1
13693261870
2022-09-16 762f2fb45db004618ba099aa3c0bd89dba1eb843
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?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.landtool.lanbase.modules.org.dao.OrgUserunitDao">
 
    <!-- 可根据自己的需求,是否要使用 -->
    <resultMap type="com.landtool.lanbase.modules.org.entity.OrgUserunit" id="userunitMap">
        <result property="userid" column="USERID"/>
        <result property="unitid" column="UNITID"/>
        <result property="rorder" column="RORDER"/>
        <result property="posname" column="POSNAME"/>
        <result property="workseasdate" column="WORKSEASDATE"/>
        <result property="worktype" column="WORKTYPE"/>
        <result property="workstartdate" column="WORKSTARTDATE"/>
        <result property="workenddate" column="WORKENDDATE"/>
        <result property="rcreateuser" column="RCREATEUSER"/>
        <result property="rcreatedate" column="RCREATEDATE"/>
        <result property="rlasteditdate" column="RLASTEDITDATE"/>
        <result property="deptid" column="DEPTID"/>
    </resultMap>
 
    <select id="queryObject" resultType="com.landtool.lanbase.modules.org.entity.OrgUserunit">
        select * from ORG_USERUNIT where USERID = #{value}
    </select>
    
    <select id="queryObjectByUnitid" resultType="com.landtool.lanbase.modules.org.entity.OrgUserunit" parameterType="com.landtool.lanbase.modules.org.entity.OrgUserunit">
        select * from ORG_USERUNIT ut
            left join ORG_UNIT un on ut.unitid= un.unitid
            left join ORG_USER us on ut.userid = us.userid
            <where>
                ut.USERID = #{userid} and ut.UNITID = #{unitid}
                <if test="deptid != null">
                    and ut.deptid=#{deptid}
                </if>
                <if test="deptid == null">
                    and ut.deptid is null
                </if>
            </where>
    </select>
    
    <select id="querUserunitJoinUserList" resultType="com.landtool.lanbase.modules.org.entity.OrgUserunitJoinUser">
        SELECT *
        FROM(
            SELECT ROW_NUMBER() OVER(ORDER BY B.userid) AS rownumber,B.*
            FROM (
                    select A.*,C.unitname,B.CHINESENAME as username,D.unitname as deptname from ORG_USERUNIT A
                    left join ORG_USER B on A.userid = B.userid
                    left join ORG_UNIT C on A.unitid = C.unitid
                    left join ORG_UNIT D on A.deptid = D.unitid
                    <where> 
                        <if test="userid != null and userid != ''">
                             AND A.userid = #{userid} 
                        </if>
                    </where>
                ) B
            ) A
        WHERE rownumber > #{lowerOffset} AND  <![CDATA[ rownumber <= ${upperOffset} ]]>
    
    </select>
    
     <select id="queryTotal" resultType="int">
        select count(*) from ORG_USERUNIT
        <where> 
            <if test="userid != null and userid != ''">
                    AND userid = #{userid} 
               </if>
           </where>
    </select>
     
    <insert id="saveUserunitJoinUser" parameterType="com.landtool.lanbase.modules.org.entity.OrgUserunitJoinUser">
        insert into ORG_USERUNIT
        (
            USERID,
            UNITID,
            RORDER,
            POSNAME,
            WORKSEASDATE,
            WORKTYPE,
            WORKSTARTDATE,
            WORKENDDATE,
            RCREATEUSER,
            RCREATEDATE,
            RLASTEDITDATE,
            DEPTID
        )
        values
         (    
             #{userid},
            #{unitid}, 
            #{rorder,jdbcType=VARCHAR},
            #{posname,jdbcType=VARCHAR},
            #{workseasdate,jdbcType=DATE},
            #{worktype,jdbcType=VARCHAR},
            #{workstartdate,jdbcType=DATE},
            #{workenddate,jdbcType=DATE},
            #{rcreateuser},
            #{rcreatedate},
            #{rlasteditdate},
            #{deptid,jdbcType=INTEGER}
        )
    </insert>
     
    <update id="updateUserunitJoinUser" parameterType="com.landtool.lanbase.modules.org.entity.OrgUserunitJoinUser">
        update ORG_USERUNIT
        <set>
            <if test="unitid != null">UNITID = #{unitid}, </if>
            <if test="rorder != null">RORDER = #{rorder}, </if>
            <if test="posname != null">POSNAME = #{posname}, </if>
            <if test="workseasdate != null">WORKSEASDATE = #{workseasdate}, </if>
            <if test="workseasdate == null">WORKSEASDATE = null, </if>
            <if test="worktype != null">WORKTYPE = #{worktype}, </if>
            <if test="workstartdate != null">WORKSTARTDATE = #{workstartdate}, </if>
            <if test="workstartdate == null">WORKSTARTDATE = null, </if>
            <if test="workenddate != null">WORKENDDATE = #{workenddate}, </if>
            <if test="workenddate == null">WORKENDDATE = null, </if>
            <if test="rcreateuser != null">RCREATEUSER = #{rcreateuser}, </if>
            <if test="rcreatedate != null">RCREATEDATE = #{rcreatedate}, </if>
            <if test="rlasteditdate != null">RLASTEDITDATE = #{rlasteditdate},</if>
            <if test="deptid != null">DEPTID = #{deptid}</if>
        </set>
        where USERID = #{userid} and UNITID = #{oldunitid}
        <if test="olddeptid != null">
            and deptid=#{olddeptid}
        </if>
        <if test="olddeptid == null">
            and deptid is null
        </if>
    </update>
    
    <delete id="delete" parameterType="com.landtool.lanbase.modules.org.entity.OrgUserunit">
        delete from ORG_USERUNIT where USERID = #{userid} and unitid = #{unitid}
        <if test="deptid != null">
            and deptid=#{deptid}
        </if>
        <if test="deptid == null">
            and deptid is null
        </if>
    </delete>
    
    <delete id="deleteBatch">
        delete from ORG_USERUNIT where USERID in
        <foreach item="userid" collection="array" open="(" separator="," close=")">
            #{userid}
        </foreach>
    </delete>
    
    <delete id="deleteBatchByUserIdAndUnitIds">
        DELETE FROM ORG_USERUNIT
        WHERE 1=1
        AND userid = #{userid}
        AND unitid in
        <foreach item="unitid" collection="unitids" open="(" separator="," close=")">
            #{unitid}
        </foreach>
    </delete>
 
    <select id="isExitUserunit" resultType="int" parameterType="com.landtool.lanbase.modules.org.entity.OrgUserunitJoinUser">
        select count(*) from ORG_USERUNIT
        <where>
            USERID = #{userid} and UNITID = #{unitid}
            <if test="deptid != null">
                and deptid=#{deptid}
            </if>
            <if test="deptid == null">
                and deptid is null
            </if>
        </where>
    </select>
 
    <select id="isWorking" resultType="com.landtool.lanbase.modules.org.entity.OrgUserunit">
        SELECT * from ORG_USERUNIT ouu where ouu.worktype = 1 and ouu.userid = #{userid}
    </select>
</mapper>