shenyijian
2024-06-21 f20611265f7d34fd4fbcdfdaff6cb9cccd0b25fc
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<?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
          and b.is_deleted = 0
          and c."interior_ad_guid" like '42%'
    </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", b."interior_ad_guid" 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" and is_deleted = 0)) 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="getPatrolPersonListByWaterCodeList" resultType="cn.gistack.sm.intelligentCall.entity.Scene">
        SELECT
        a."guid" as waterCode,
        a."name" as waterName,
        b."user_name" as username,
        b."user_phone" as userId,
        b."user_phone" as 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" = 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>
    </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}
        limit 3
    </select>
    <select id="getPatrolResponsiblePersonByResCdList"
            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
            and b.is_deleted = 0
        <choose>
            <when test="ids!=null and ids.size()>0">
                and "res_guid" in
                <foreach collection="ids" item="id" open="(" close=")" separator=",">
                    #{id}
                </foreach>
            </when>
            <otherwise>
                and "res_guid" in ('')
            </otherwise>
        </choose>
 
 
 
 
 
    </select>
    <select id="getCompetentDepart" resultType="java.lang.String">
        SELECT "c_unit_name" FROM SJZT_MD."att_res_mgr_sys_b" WHERE "res_guid" = #{resCd}
    </select>
    <select id="getPersonList" resultType="cn.gistack.sm.sjztmd.entity.AttResManagePerson">
        SELECT  * FROM "SJZT_MD"."att_res_manage_person" WHERE "res_guid" = #{resCd}
    </select>
    <select id="getList" resultType="cn.gistack.sm.sjztmd.entity.AttResManagePerson">
        SELECT  * FROM SJZT_MD."att_res_manage_person" where 1=1
        <if test="attResManagePerson.resGuid != null and attResManagePerson.resGuid != ''">
            AND "res_guid" = #{attResManagePerson.resGuid}
        </if>
        ORDER BY "type" ASC
    </select>
    <select id="getPersonByRoleAndAd" resultType="cn.gistack.sm.sjztmd.vo.ChargePersonVO">
        SELECT
            BU.id as userId,
            BU.real_name as userName,
            9 as type
        FROM YWXT.BLADE_USER BU
                 LEFT JOIN YWXT.BLADE_ROLE BR ON BU.ROLE_ID LIKE CONCAT('%',BR.ID,'%')
        WHERE
            bu.is_deleted = 0
            AND BU.DEPT_ID = #{adCode}
              AND BR.ROLE_ALIAS = #{roleAlias}
    </select>
 
</mapper>