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
<?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.TbResDykeMapper">
    <!--namespace根据自己需要创建的的mapper的路径和名称填写-->
    <select id="getPage" resultType="cn.gistack.sm.sjztmd.vo.TbResDykeVO">
 
        SELECT
            trd.*,
            aab."p_ad_code" as pAdCode,
            aab."p_ad_name" as pAdName
        FROM SJZT_MD."tb_res_dyke" trd
        LEFT JOIN YWXT."att_ad_base" aab ON aab."guid" = trd."ad_code"
        <where>
            <if test="vo.adCode != null and vo.adCode !=''">
                and trd."ad_code" LIKE #{vo.adCode}
            </if>
            <if test="vo.name != null and vo.name !=''">
                and trd."name" LIKE CONCAT('%',#{vo.name},'%')
            </if>
            <if test="vo.startLocation != null and vo.startLocation !=''">
                and trd."start_location" LIKE CONCAT('%',#{vo.startLocation},'%')
            </if>
            <if test="vo.startStakeMark != null and vo.startStakeMark !=''">
                and trd."start_stake_mark" LIKE CONCAT('%',#{vo.startStakeMark},'%')
            </if>
            <if test="vo.endLocation != null and vo.endLocation !=''">
                and trd."end_location" LIKE CONCAT('%',#{vo.endLocation},'%')
            </if>
            <if test="vo.endStakeMark != null and vo.endStakeMark !=''">
                and trd."end_stake_mark" LIKE CONCAT('%',#{vo.endStakeMark},'%')
            </if>
            <if test="vo.rvName != null and vo.rvName !=''">
                and trd."rv_name" LIKE CONCAT('%',#{vo.rvName},'%')
            </if>
            <if test="vo.shoreType != null and vo.shoreType !=''">
                and trd."shore_type" = #{vo.shoreType}
            </if>
            <if test="vo.dykeType != null and vo.dykeType != ''">
                and  trd."dyke_type" = #{vo.dykeType}
            </if>
            <if test="vo.dykeLevel != null and vo.dykeLevel !=''">
                and trd."dyke_level" = #{vo.dykeLevel}
            </if>
            <if test="vo.mgrUnitName != null and vo.mgrUnitName !=''">
                and trd."mgr_unit_name" LIKE CONCAT('%',#{vo.mgrUnitName},'%')
            </if>
        </where>
 
    </select>
    <select id="getDetail" resultType="cn.gistack.sm.sjztmd.vo.TbResDykeVO">
 
        SELECT
        trd.*,
        aab."p_ad_code" as pAdCode,
        aab."p_ad_name" as pAdName
        FROM SJZT_MD."tb_res_dyke" trd
        LEFT JOIN YWXT."att_ad_base" aab ON aab."guid" = trd."ad_code"
        where trd."guid" = #{vo.guid}
    </select>
 
    <!--  堤防普查列表  -->
    <select id="findTbResDykePcBy"
            resultType="cn.gistack.sm.sjztmd.vo.TbResDykeVO">
SELECT base.* from (
        select
        trd.*,
        tdis."check_state" AS tb_state,
        tdis."guid" as tbStateId,
        aa."p_ad_code" as pAdCode,
        aa."p_ad_name" as pAdName,
        (CASE WHEN tmp.totalDangerNum>0 THEN 1 ELSE 2 END) as hasDanger,
        tmp.totalDangerNum,
        tmp.termiteNum,
        tmp.otherNum,
        tmp.totalDangerLength,
        ifnull(tmp.totalDanger,0) totalDanger,
        ifnull(tmp.totalDangerSr,0) totalDangerSr,
        ifnull(tmp.totalDangerCb,0) totalDangerCb,
        ifnull(tmp.totalDangerDw,0) totalDangerDw
 
        from sjzt_md."tb_res_dyke" trd
        left join "SJZT_MD"."tb_dyke_investigation_state" tdis on trd."guid" = tdis."dyke_guid"
        left join YWXT."att_ad_base" aa on aa."guid" = trd."ad_code"
        left join
        (
        select
        temp2."tb_state_id",
        temp2."dyke_guid",
        sum(temp2.totalDangerNum) as totalDangerNum,
        sum(temp2.termiteNum) as termiteNum,
        sum(temp2.otherNum) as otherNum,
        SUM(CASE WHEN temp2.dangerLength THEN temp2.dangerLength ELSE 0 END) AS totalDangerLength,
        sum(temp2.totalDanger) as totalDanger,
        sum(temp2.totalDangerSr) as totalDangerSr,
        sum(temp2.totalDangerCb) as totalDangerCb,
        sum(temp2.totalDangerDw) as totalDangerDw
        from(
        SELECT
        TEMP1.*,
        TEMP1.dangerLength/temp1.num
        FROM (
        SELECT tdi."tb_state_id",tdi."dyke_guid",tdi."unit",
        count(*) as num,
        SUM(CASE WHEN (tdi."danger_length") THEN tdi."danger_length" ELSE 0 END) AS dangerLength,
        SUM(CASE WHEN (tdi."hazard_rating" != '无危害') THEN 1 ELSE 0 END) AS totalDangerNum,
        SUM(CASE WHEN (tdi."investigation_variety" = '白蚁' and tdi."hazard_rating" != '无危害') THEN 1 ELSE 0 END) AS termiteNum,
        SUM(CASE WHEN (tdi."investigation_variety" != '白蚁' and tdi."hazard_rating" != '无危害') THEN 1 ELSE 0 END) AS otherNum,
        SUM(CASE WHEN (tdi."is_danger" != '否') THEN 1 ELSE 0 END) AS totalDanger,
        SUM(CASE WHEN (json_value(tdi."danger_info", '$.sr') != '') THEN json_value(tdi."danger_info", '$.sr') ELSE 0 END) AS totalDangerSr,
        SUM(CASE WHEN (json_value(tdi."danger_info", '$.cb') != '') THEN json_value(tdi."danger_info", '$.cb') ELSE 0 END) AS totalDangerCb,
        SUM(CASE WHEN (json_value(tdi."danger_info", '$.dw') != '') THEN json_value(tdi."danger_info", '$.dw') ELSE 0 END) AS totalDangerDw
        from sjzt_md."tb_dyke_investigation" tdi
        where 1=1
        <if test="vo.tbYear !=null and vo.tbYear !=''">
            AND tdi."tb_year" = #{vo.tbYear}
        </if>
        group by tdi."tb_state_id",tdi."dyke_guid",tdi."unit"
        )TEMP1
        )temp2 group by
        temp2."tb_state_id",
        temp2."dyke_guid"
        ) tmp on tmp."tb_state_id" = tdis."guid"
        where 1 = 1
        <if test="vo.name !=null and vo.name !=''">
            AND trd."name" LIKE CONCAT('%',#{vo.name},'%')
        </if>
        <if test="vo.tbState != null and vo.tbState !=''">
            AND (
            <if test="vo.tbState == -1">
                tdis."check_state" IS NULL OR
            </if>
            tdis."check_state" = #{vo.tbState}
            )
        </if>
        <if test="vo.adCode != null and vo.adCode != '' ">
            and trd."ad_code" LIKE #{vo.adCode}
        </if>
) base where 1=1
        <if test="vo.hasDanger != null and vo.hasDanger != '' ">
            and base.hasDanger = #{vo.hasDanger}
        </if>
    </select>
</mapper>