双重预防项目-国泰新华二开定制版
SZH
2022-08-20 f9f0687195e0fe349185437d22c495d74c8d4a20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.project.system.post.mapper.PostMapper">
 
    <resultMap type="Post" id="PostResult">
        <id     property="postId"        column="post_id"       />
        <result property="companyId"      column="company_id"   />
        <result property="postCode"      column="post_code"     />
        <result property="postName"      column="post_name"     />
        <result property="postSort"      column="post_sort"     />
        <result property="status"        column="status"        />
        <result property="createBy"      column="create_by"     />
        <result property="createTime"    column="create_time"   />
        <result property="updateBy"      column="update_by"     />
        <result property="updateTime"    column="update_time"   />
        <result property="remark"        column="remark"        />
        <association property="company"    column="company_id" javaType="Company" resultMap="CompanyResult" />
    </resultMap>
 
    <resultMap id="CompanyResult" type="Company">
        <id     property="companyId"   column="company_id"     />
        <result property="companyName"    column="company_name"    />
        <result property="companyPrincipal"    column="company_principal"    />
        <result property="companyAddress"    column="company_address"    />
        <result property="companyPhone"    column="company_phone"    />
    </resultMap>
    
    <sql id="selectPostVo">
        select p.post_id, p.company_id, p.post_code, p.post_name, p.post_sort, p.status, p.create_by, p.create_time, p.remark,
        c.company_id,c.company_name
        from sys_post AS p
        LEFT JOIN sys_company c ON p.company_id = c.company_id
    </sql>
 
 
    
    <select id="selectPostList" parameterType="Post" resultMap="PostResult">
        <include refid="selectPostVo"/>
        <where>
            <if test="postCode != null and postCode != ''">
                AND post_code like concat('%', #{postCode}, '%')
            </if>
            <if test="status != null and status != ''">
                AND status = #{status}
            </if>
            <if test="postName != null and postName != ''">
                AND post_name like concat('%', #{postName}, '%')
            </if>
            <if test="companyId != null and companyId != 0">
                AND c.company_id = #{companyId}
            </if>
        </where>
    </select>
    
    <select id="selectPostAll" resultMap="PostResult">
        <include refid="selectPostVo"/>
    </select>
    
    <select id="selectPostsByUserId" parameterType="Long" resultMap="PostResult">
        SELECT p.post_id, p.post_name, p.post_code
        FROM sys_user u
             LEFT JOIN sys_user_post up ON u.user_id = up.user_id
             LEFT JOIN sys_post p ON up.post_id = p.post_id
        WHERE up.user_id = #{userId}
    </select>
    
    <select id="selectPostById" parameterType="Long" resultMap="PostResult">
        <include refid="selectPostVo"/>
        where post_id = #{postId}
    </select>
    
    <select id="checkPostNameUnique" resultMap="PostResult">
        <include refid="selectPostVo"/>
         where post_name=#{postName}
        <if test="companyId != null and companyId != 0">
            AND c.company_id = #{companyId}
        </if>
        <if test="postId != null and postId != 0">
            AND p.post_id != #{postId}
        </if>
    </select>
    
    <select id="checkPostCodeUnique"  resultMap="PostResult">
        <include refid="selectPostVo"/>
         where post_code=#{postCode}
        <if test="companyId != null and companyId != 0">
            AND c.company_id = #{companyId}
        </if>
        <if test="postId != null and postId != 0">
            AND p.post_id != #{postId}
        </if>
    </select>
    
     <delete id="deletePostByIds" parameterType="Long">
         delete from sys_post where post_id in
         <foreach collection="array" item="postId" open="(" separator="," close=")">
             #{postId}
        </foreach> 
     </delete>
     
     <update id="updatePost" parameterType="Post">
         update sys_post
         <set>
             <if test="postCode != null and postCode != ''">post_code = #{postCode},</if>
            <if test="companyId != null and companyId != ''">company_id = #{companyId},</if>
             <if test="postName != null and postName != ''">post_name = #{postName},</if>
             <if test="postSort != null and postSort != ''">post_sort = #{postSort},</if>
             <if test="status != null and status != ''">status = #{status},</if>
             <if test="remark != null">remark = #{remark},</if>
             <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
             update_time = sysdate()
         </set>
         where post_id = #{postId}
    </update>
     
     <insert id="insertPost" parameterType="Post" useGeneratedKeys="true" keyProperty="postId">
         insert into sys_post(
             <if test="postId != null and postId != 0">post_id,</if>
            <if test="companyId != null and companyId != 0">company_id,</if>
             <if test="postCode != null and postCode != ''">post_code,</if>
             <if test="postName != null and postName != ''">post_name,</if>
             <if test="postSort != null and postSort != ''">post_sort,</if>
             <if test="status != null and status != ''">status,</if>
             <if test="remark != null and remark != ''">remark,</if>
             <if test="createBy != null and createBy != ''">create_by,</if>
             create_time
         )values(
             <if test="postId != null and postId != 0">#{postId},</if>
            <if test="companyId != null and companyId != 0">#{companyId},</if>
             <if test="postCode != null and postCode != ''">#{postCode},</if>
             <if test="postName != null and postName != ''">#{postName},</if>
             <if test="postSort != null and postSort != ''">#{postSort},</if>
             <if test="status != null and status != ''">#{status},</if>
             <if test="remark != null and remark != ''">#{remark},</if>
             <if test="createBy != null and createBy != ''">#{createBy},</if>
             sysdate()
         )
    </insert>
 
</mapper>