zhongrj
2023-07-06 3ce737b52fca082ac3a2ecda4a848e2e4abcd0ee
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?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="cn.gistack.sm.sjztmd.mapper.AttResManagePersonMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="baseResultMap" type="cn.gistack.sm.sjztmd.entity.AttResManagePerson">
        <id column="guid" property="guid"/>
        <result column="user_name" property="userName"/>
        <result column="type" property="type"/>
        <result column="user_phone" property="userPhone"/>
        <result column="user_unit" property="userUnit"/>
        <result column="postion" property="position"/>
        <result column="res_guid" property="resGuid"/>
    </resultMap>
 
    <!--    <select id="attResManagePersonListByResId" resultMap="baseResultMap">-->
    <select id="attResManagePersonListByResId" resultMap="baseResultMap">
        select DISTINCT
        "guid","user_name","type","user_phone","user_unit","position","res_guid","user_guid"
        from "att_res_manage_person" where "type" = 5 AND "res_guid" IN
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>
 
    <select id="getPatrolResponsiblePersonAll" resultType="cn.gistack.sm.sjztmd.entity.PatrolResponsiblePerson">
        select DISTINCT a."res_guid", c."name", b.id as user_id
        from "SJZT_MD"."att_res_manage_person" a,
             "BLADE_USER" b,
             "SJZT_MD"."att_res_base" c
        WHERE a."user_phone" = b.PHONE
          and a."res_guid" = c."guid"
          and a."type" = 5
    </select>
 
    <update id="updateResManagePersonByGuid">
        update "att_res_manage_person"
        SET
        <if test="attResManagePerson.userName !=null  and attResManagePerson.userName != '' ">
            "user_name" = #{attResManagePerson.userName},
        </if>
        <if test="attResManagePerson.userPhone !=null  and attResManagePerson.userPhone != '' ">
            "user_phone" = #{attResManagePerson.userPhone},
        </if>
        <if test="attResManagePerson.userUnit !=null  and attResManagePerson.userUnit != '' ">
            "user_unit" = #{attResManagePerson.userUnit},
        </if>
        <if test="attResManagePerson.position !=null  and attResManagePerson.position != '' ">
            "position" = #{attResManagePerson.position},
        </if>
        <if test="attResManagePerson.resGuid !=null  and attResManagePerson.resGuid != '' ">
            "res_guid" = #{attResManagePerson.resGuid},
        </if>
        <if test="attResManagePerson.type !=null  and attResManagePerson.type != '' ">
            "type" = #{attResManagePerson.type},
        </if>
        <if test="attResManagePerson.sysResource !=null  and attResManagePerson.sysResource != '' ">
            "sys_resource" = #{attResManagePerson.sysResource},
        </if>
        "update_time" = #{attResManagePerson.updateTime}
        where "guid" = #{attResManagePerson.guid}
    </update>
 
    <insert id="insertResManagePersion">
        insert into "att_res_manage_person"("guid", "user_name", "type", "user_phone", "user_unit", "position",
                                            "res_guid", "sys_resource")
        values (rawtohex(sys_guid()),
                #{attResManagePerson.userName},
                #{attResManagePerson.type},
                #{attResManagePerson.userPhone},
                #{attResManagePerson.userUnit},
                #{attResManagePerson.position},
                #{attResManagePerson.resGuid},
                #{attResManagePerson.sysResource})
    </insert>
 
    <!--根据水库编号及责任人类型查询相关责任人信息-->
    <select id="getPersonListByResGuid" resultType="cn.gistack.sm.sjztmd.vo.PersonVO">
        select "user_name" as name,"user_phone" as phone,"type" as type
        from "SJZT_MD"."att_res_manage_person"
        where "res_guid" = #{res_cd}
        <choose>
            <when test="list!=null and list.size()>0">
                and "type" in
                <foreach collection="list" item="type" separator="," open="(" close=")">
                    #{type}
                </foreach>
            </when>
            <otherwise>
                and "type" in ('')
            </otherwise>
        </choose>
    </select>
 
    <select id="getPersonByUserNotExists" resultType="cn.gistack.sm.sjztmd.vo.UserPersonVO">
        select distinct a.*,
               to_char((select wm_concat(
                                   distinct CASE  tmp."type" WHEN '1' THEN '1648252341572902914'  WHEN '2' THEN '1648252441107931137' WHEN '3' THEN '1648252563300589570' WHEN '4' THEN '1648252509110181890' WHEN '5' THEN '1642713427301355522' ELSE '' END
               )
                        from "SJZT_MD"."att_res_manage_person" tmp
                        where tmp."user_phone" = a."user_phone")) as role_id
        from (select *
              from (select distinct a."user_name", a."user_phone", concat(b."ad_guid", '000000') as "ad_code"
                    from "SJZT_MD"."att_res_manage_person" a
                             left join "SJZT_MD"."att_res_base" b on a."res_guid" = b."guid"
                    where "user_phone" is not null
                      and "user_name" not like '%、'
                      and length(a."user_phone") = 11
                    order by "user_phone") a
              where not exists(select * from "YWXT"."BLADE_USER" where a."user_phone" = "PHONE")) a
    </select>
 
    <select id="getPersonByUser" resultType="cn.gistack.sm.sjztmd.vo.UserPersonVO">
        select distinct a."user_name",
                        a."user_phone",
                        a."ad_code",
                        to_char((select wm_concat(
                                            distinct CASE  tmp."type" WHEN '1' THEN '1648252341572902914'  WHEN '2' THEN '1648252441107931137' WHEN '3' THEN '1648252563300589570' WHEN '4' THEN '1648252509110181890' WHEN '5' THEN '1642713427301355522' ELSE '' END
                        )
                                 from "SJZT_MD"."att_res_manage_person" tmp
                                 where tmp."user_phone" = a."user_phone")) as role_id
        from (select *
              from (select distinct a."user_name", a."user_phone", concat(b."ad_guid", '000000') as "ad_code"
                    from "SJZT_MD"."att_res_manage_person" a
                             left join "SJZT_MD"."att_res_base" b on a."res_guid" = b."guid"
                    where "user_phone" is not null
                      and "user_name" not like '%、'
                      and length(a."user_phone") = 11
                    order by "user_phone") a) a
    </select>
 
    <update id="updateUserByPerson">
 
        UPDATE YWXT.BLADE_USER a, (
            select distinct a."user_name",
            a."user_phone",
            a."ad_code",
            to_char((select wm_concat(
            distinct CASE  tmp."type" WHEN '1' THEN '1648252341572902914'  WHEN '2' THEN '1648252441107931137' WHEN '3' THEN '1648252563300589570' WHEN '4' THEN '1648252509110181890' WHEN '5' THEN '1642713427301355522' ELSE '' END
            )
            from "SJZT_MD"."att_res_manage_person" tmp
            where tmp."user_phone" = a."user_phone")) as role_id
            from (select *
            from (select distinct a."user_name", a."user_phone", concat(b."ad_guid", '000000') as "ad_code"
            from "SJZT_MD"."att_res_manage_person" a
            left join "SJZT_MD"."att_res_base" b on a."res_guid" = b."guid"
            where "user_phone" is not null
            and "user_name" not like '%、'
            and length(a."user_phone") = 11
            order by "user_phone") a) a
            ) b
        set
            a.role_id = b.role_id
        where a.phone = b."user_phone" and a.role_id &lt;&gt; b.role_id
    </update>
 
    <!--通过水库代码获取巡查责任人及技术责任人手机号-->
    <select id="getPersonListByWaterCodeList" resultType="java.lang.String">
        SELECT b."user_phone" FROM SJZT_MD."att_res_base"  a
        LEFT JOIN SJZT_MD."att_res_manage_person" b ON a."guid" = b."res_guid"
        where 1=1
        and (b."type" = 4 or b."type" = 5)
        <choose>
            <when test="list!=null and list.size()>0">
                and "sk_code" in
                <foreach collection="list" item="id" open="(" close=")" separator=",">
                   #{id}
                </foreach>
            </when>
            <otherwise>
                and "sk_code" in ('')
            </otherwise>
        </choose>
        group by b."user_phone"
    </select>
 
    <!--根据水库编号查询市县水利部人员姓名及联系方式-->
    <select id="getCityCountyPersonListByResGuid" resultType="cn.gistack.sm.sjztmd.vo.PersonVO">
        select real_name as name,phone,#{type} as type from YWXT.blade_user bu
        left join YWXT.blade_dept bd on locate(bd.id,bu.dept_id)>0 and bd.is_deleted = 0
        left join YWXT.blade_role br on locate(br.id,bu.role_id)>0 and br.is_deleted = 0
        where bu.is_deleted = 0
        and br.role_alias = #{roleAlias}
        and bd.ad_code = #{adCode}
    </select>
 
</mapper>