zhongrj
2023-11-13 7eee9e04b31e1d8fdcbce8bc48bc839aa975441f
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
<?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.AttResBaseMapper">
 
 
    <select id="selectAttResBasePage" resultType="cn.gistack.sm.sjztmd.entity.AttResBase">
        SELECT * FROM "SJZT_MD"."att_res_base"
        WHERE "is_deleted"=0
        <if test="attResBase.name !=null and attResBase.name !=''">
            AND "name" LIKE CONCAT('%',#{attResBase.name},'%')
        </if>
    </select>
    <select id="getListByRegion" resultType="cn.gistack.sm.sjztmd.entity.AttResBase">
        SELECT arb."guid",arb."code",arb."name",arb."ad_guid",arb."eng_scal",arb."res_loc" FROM "att_res_base" arb
        left join "att_ad_base" aab on aab."guid" = arb."interior_ad_guid"
        left join "att_ad_base" aa on aab."p_ad_code" = aa."ad_code"
        left join "att_ad_base" ab on aa."p_ad_code" = ab."ad_code"
        left join "att_ad_base" ac on ab."p_ad_code" = ac."ad_code"
        WHERE arb."is_deleted"=0
        <if test="obj.code != null and obj.code != '' ">
            and (aab."ad_code" = #{obj.code} or aa."ad_code" = #{obj.code} or ab."ad_code" = #{obj.code} or ac."ad_code" = #{obj.code})
        </if>
         <if test="obj.name !=null and obj.name !=''">
             AND "name" LIKE CONCAT('%',#{obj.name},'%')
         </if>
 
    </select>
    <select id="getDetailByCode" resultType="cn.gistack.sm.sjztmd.entity.AttResBase">
        SELECT * FROM "att_res_base"
        WHERE "is_deleted"=0 and "code" = #{code}
    </select>
 
    <!--获取水库对应责任人分页数据-->
    <select id="getAttResBaseUserPage" resultType="cn.gistack.sm.sjztmd.dto.AttResBaseUserDTO">
        select
        arb."guid", arb."name", arb."res_loc" as place, arb."res_reg_code" as resRegCode, arb."eng_scal" as engScal,
        REGEXP_SUBSTR (arb."res_loc",'[^-]+',1,2) as cityName,
        REGEXP_SUBSTR (arb."res_loc",'[^-]+',1,3) as countyName,
        REGEXP_SUBSTR (arb."res_loc",'[^-]+',1,4) as townName,
        aab."ad_name" as adName,
        trmp1."user_unit" areaUnitName,trmp1."user_name" areaUsername,trmp1."user_phone" areaPhone,trmp1."position" areaPosition,trmp1."guid" areaUserGuid,
        trmp2."user_unit" customsUnitName,trmp2."user_name" customsUsername,trmp2."user_phone" customsPhone,trmp2."position" customsPosition,trmp2."guid" customsUserGuid,
        trmp3."user_unit" manageUnitUnitName,trmp3."user_name" manageUnitUsername,trmp3."user_phone" manageUnitPhone,trmp3."position" manageUnitPosition,trmp3."guid" manageUnitUserGuid,
        trmp4."user_unit" technologyUnitName,trmp4."user_name" technologyUsername,trmp4."user_phone" technologyPhone,trmp4."position" technologyPosition,trmp4."guid" technologyUserGuid,
        trmp5."user_unit" patrolUnitName,trmp5."user_name" patrolUsername,trmp5."user_phone" patrolPhone,trmp5."position" patrolPosition,trmp5."guid" patrolUserGuid
        from SJZT_MD."att_res_base" arb
        left join "SJZT_MD"."att_ad_base" aab on aab."guid" = arb."interior_ad_guid"
        left join "SJZT_MD"."att_ad_base" aa on aab."p_ad_code" = aa."ad_code"
        left join "SJZT_MD"."att_ad_base" ab on aa."p_ad_code" = ab."ad_code"
        left join "SJZT_MD"."att_ad_base" ac on ab."p_ad_code" = ac."ad_code"
        left join (
        select "res_guid",WM_Concat("guid") "guid",WM_Concat("user_unit") "user_unit",WM_Concat("user_name") "user_name",WM_Concat("user_phone") "user_phone",WM_Concat("position") "position"
        from "SJZT_MD"."att_res_manage_person" where  "type"=1 GROUP BY "res_guid"
        ) trmp1 on arb."guid" = trmp1."res_guid"
 
        left join (
        select "res_guid",WM_Concat("guid") "guid",WM_Concat("user_unit") "user_unit",WM_Concat("user_name") "user_name",WM_Concat("user_phone") "user_phone",WM_Concat("position") "position"
        from "SJZT_MD"."att_res_manage_person" where  "type"=2 GROUP BY "res_guid"
        ) trmp2 on arb."guid" = trmp2."res_guid"
 
        left join (
        select "res_guid",WM_Concat("guid") "guid",WM_Concat("user_unit") "user_unit",WM_Concat("user_name") "user_name",WM_Concat("user_phone") "user_phone",WM_Concat("position") "position"
        from "SJZT_MD"."att_res_manage_person" where  "type"=3 GROUP BY "res_guid"
        ) trmp3 on arb."guid" = trmp3."res_guid"
 
        left join (
        select "res_guid",WM_Concat("guid") "guid",WM_Concat("user_unit") "user_unit",WM_Concat("user_name") "user_name",WM_Concat("user_phone") "user_phone",WM_Concat("position") "position"
        from "SJZT_MD"."att_res_manage_person" where  "type"=4 GROUP BY "res_guid"
        ) trmp4 on arb."guid" = trmp4."res_guid"
 
        left join (
        select "res_guid",WM_Concat("guid") "guid",WM_Concat("user_unit") "user_unit",WM_Concat("user_name") "user_name",WM_Concat("user_phone") "user_phone",WM_Concat("position") "position"
        from "SJZT_MD"."att_res_manage_person" where  "type"=5 GROUP BY "res_guid"
        ) trmp5 on arb."guid" = trmp5."res_guid"
        where 1=1
        <if test="params.name !=null and params.name !=''">
            AND arb."name" LIKE CONCAT('%',#{params.name},'%')
        </if>
        <if test="params.resRegCode !=null and params.resRegCode !=''">
            AND arb."res_reg_code" LIKE CONCAT('%',#{params.resRegCode},'%')
        </if>
        <if test="params.engScal !=null and params.engScal !=''">
            AND arb."eng_scal" LIKE CONCAT('%',#{params.engScal},'%')
        </if>
        <if test="params.isWorkable==1">
            AND (
                (
                (arb."eng_scal" = '大(1)型' or arb."eng_scal" = '大(2)型' or arb."eng_scal" = '中型')
                and
                trmp1."user_unit" is not null and trmp2."user_unit" is not null and trmp3."user_unit" is not null
                )
                or
                (
                (arb."eng_scal" = '小(1)型' or arb."eng_scal" = '小(2)型')
                and
                trmp1."user_unit" is not null and trmp2."user_unit" is not null and trmp3."user_unit" is not null and trmp4."user_unit" is not null and trmp5."user_unit" is not null
                )
            )
        </if>
        <if test="params.isWorkable==2">
            AND (
                (arb."eng_scal" = '大(1)型' or arb."eng_scal" = '大(2)型' or arb."eng_scal" = '中型')
                and
                (trmp1."user_unit" is null or trmp2."user_unit" is null or trmp3."user_unit" is null)
                or
                (
                (arb."eng_scal" = '小(1)型' or arb."eng_scal" = '小(2)型')
                and
                (trmp1."user_unit" is null or trmp2."user_unit" is null or trmp3."user_unit" is null or trmp4."user_unit" is null or trmp5."user_unit" is null)
                )
            )
        </if>
 
        <if test="params.adCode != null and params.adCode != '' ">
            and (aab."ad_code" = #{params.adCode} or aa."ad_code" = #{params.adCode} or ab."ad_code" = #{params.adCode} or ac."ad_code" = #{params.adCode})
        </if>
    </select>
 
    <!--查询各类型责任人-->
    <select id="getUserByResBaseGuid" resultType="cn.gistack.sm.sjztmd.vo.ManagePersonVO">
        select
        trmp."type",
        trmp."user_name" as username,
        trmp."user_unit" as unitName,
        trmp."position",
        trmp."user_phone" as phone
        from "SJZT_MD"."att_res_manage_person" trmp
        where trmp."res_guid" = #{guid}
    </select>
 
    <update id="updateResBaseByGuid">
        UPDATE "att_res_base" SET
        <if test="attResBase.interiorAdGuid !=null and attResBase.interiorAdGuid != ''">
            "interior_ad_guid" = #{attResBase.interiorAdGuid},
        </if>
        <if test="attResBase.label !=null and attResBase.label != ''">
            "label" = #{attResBase.label},
        </if>
        <if test="attResBase.label ==null or attResBase.label == ''">
            "label" = '',
        </if>
            "is_gate" = #{attResBase.isGate},
        "update_time" = #{attResBase.updateTime}
        WHERE "guid" = #{attResBase.guid}
    </update>
 
    <!--查询当前水库对应的市级编号和县区编号-->
    <select id="getCityCountyCodeByResGuid" resultType="cn.gistack.sm.sjztmd.vo.AttResBaseVO">
        SELECT
            case when b."ad_grad" = 3 THEN b."ad_code"
                 when c."ad_grad" = 3 THEN c."ad_code" END AS countyCode,
            case when b."ad_grad" = 2 THEN b."ad_code"
                 when c."ad_grad" = 2 THEN c."ad_code"
                 ELSE d."ad_code" END AS cityCode
        FROM sjzt_md."att_res_base" a
        LEFT JOIN sjzt_md."att_ad_base" b ON a."interior_ad_guid" = b."guid"
        LEFT JOIN sjzt_md."att_ad_base" c ON b."p_ad_code" = c."guid"
        LEFT JOIN sjzt_md."att_ad_base" d ON c."p_ad_code" = d."guid"
        where a."guid" = #{guid}
    </select>
 
    <!--查询当前水库对应的市级编号和县区编号-->
    <select id="getWaterRegionInfoByResGuid" resultType="cn.gistack.sm.sjztmd.vo.AttResAdVO">
        SELECT
            a."guid" as resGuid,
            case when b."ad_grad" = 4 THEN b."ad_code" ELSE NULL END AS townCode,
            case when b."ad_grad" = 4 THEN b."ad_name" ELSE NULL END AS townName,
            case when b."ad_grad" = 3 THEN b."ad_code"
                 when c."ad_grad" = 3 THEN c."ad_code" END AS countyCode,
            case when b."ad_grad" = 3 THEN b."ad_name"
                 when c."ad_grad" = 3 THEN C."ad_name" END AS countyName,
            case when b."ad_grad" = 2 THEN b."ad_code"
                 when c."ad_grad" = 2 THEN c."ad_code"
                 ELSE d."ad_code" END AS cityCode,
            case when b."ad_grad" = 2 THEN b."ad_name"
                 when c."ad_grad" = 2 THEN c."ad_name"
                 ELSE d."ad_name" END AS cityName
        FROM sjzt_md."att_res_base" a
        LEFT JOIN sjzt_md."att_ad_base" b ON a."interior_ad_guid" = b."guid"
        LEFT JOIN sjzt_md."att_ad_base" c ON b."p_ad_code" = c."guid"
        LEFT JOIN sjzt_md."att_ad_base" d ON c."p_ad_code" = d."guid"
        where a."guid" = #{guid}
    </select>
 
</mapper>