ke
2024-05-13 659d3e60c6fe5e5bcd8c4cbb3dd8077e29f13a38
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<?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.TbProjectMapper">
    <!--namespace根据自己需要创建的的mapper的路径和名称填写-->
    <sql id="selectResByRegion">
        SELECT arb."code",
               arb."name",
               arb."eng_scal",
               case when town."ad_grad" = 4 THEN town."ad_code" ELSE NULL END AS townCode,
               case when town."ad_grad" = 4 THEN town."ad_name" ELSE NULL END AS townName,
               case
                   when town."ad_grad" = 3 THEN town."ad_code"
                   when county."ad_grad" = 3 THEN county."ad_code" END        AS countyCode,
               case
                   when town."ad_grad" = 3 THEN town."ad_name"
                   when county."ad_grad" = 3 THEN county."ad_name" END        AS countyName,
               case
                   when town."ad_grad" = 2 THEN town."ad_code"
                   when county."ad_grad" = 2 THEN county."ad_code"
                   ELSE city."ad_code" END                                    AS cityCode,
               case
                   when town."ad_grad" = 2 THEN town."ad_name"
                   when county."ad_grad" = 2 THEN county."ad_name"
                   ELSE city."ad_name" END                                    AS cityName,
               case
                   when town."ad_grad" = 1 THEN town."ad_code"
                   when county."ad_grad" = 1 THEN county."ad_code"
                   when city."ad_grad" = 1 THEN city."ad_code"
                   ELSE province."ad_code" END                                AS provinceCode,
               case
                   when town."ad_grad" = 1 THEN town."ad_name"
                   when county."ad_grad" = 1 THEN county."ad_name"
                   when city."ad_grad" = 1 THEN city."ad_name"
                   ELSE province."ad_name" END                                AS provinceName
        FROM sjzt_MD."att_res_base" ARB
                 LEFT JOIN YWXT."att_ad_base" town ON town."ad_code" = arb."interior_ad_guid"
                 LEFT JOIN YWXT."att_ad_base" county ON county."ad_code" = town."p_ad_code"
                 LEFT JOIN YWXT."att_ad_base" city ON city."ad_code" = county."p_ad_code"
                 LEFT JOIN YWXT."att_ad_base" province ON province."ad_code" = city."p_ad_code"
    </sql>
 
    <select id="getList" resultType="cn.gistack.sm.sjztmd.vo.TbProjectVO">
 
        SELECT
            *
        FROM SJZT_MD."tb_project" tb
        where
            tb."is_deleted" = 0
        <if test="vo.cityCode != null and vo.cityCode != ''">
            and tb."city_code" = #{vo.cityCode}
        </if>
        <if test="vo.countyCode != null and vo.countyCode != ''">
            and tb."county_code" = #{vo.countyCode}
        </if>
        <if test="vo.isEstablishPlan != null and vo.isEstablishPlan !=''">
            and tb."is_establish_plan" = #{vo.isEstablishPlan}
        </if>
        <if test="vo.isGovPurchase != null and vo.isGovPurchase != ''">
            and tb."is_gov_purchase" = #{vo.isGovPurchase}
        </if>
        <if test="vo.contractDate != null and vo.contractDate != ''">
            and tb."contract_date" = #{vo.contractDate}
        </if>
        <if test="vo.startTime!=null and vo.startTime!=''">
            and tb."check_date">= #{vo.startTime}
        </if>
        <if test="vo.endTime!=null and vo.endTime!=''">
            and tb."check_date" &lt;= #{vo.endTime}
        </if>
        order by city_code,county_code asc
    </select>
 
    <resultMap id="dto" type="cn.gistack.sm.sjztmd.dto.TbProjectDTO">
        <id property="guid" column="guid"/>
        <result property="tbYear" column="tb_year"/>
        <result property="cityCode" column="city_code"/>
        <result property="cityName" column="city_name"/>
        <result property="countyCode" column="county_code"/>
        <result property="countyName" column="county_name"/>
 
        <result property="centerFund" column="center_fund"/>
        <result property="localFund" column="local_fund"/>
        <result property="isEstablishPlan" column="is_establish_plan"/>
        <result property="planUrl" column="plan_url"/>
        <result property="planFeedBackUrl" column="plan_feed_back_url"/>
        <result property="isGovPurchase" column="is_gov_purchase"/>
        <result property="purchaseWay" column="purchase_way"/>
        <result property="govUrl" column="gov_url"/>
        <result property="contractDate" column="contract_date"/>
        <result property="contractUrl" column="contract_url"/>
        <result property="checkDate" column="check_date"/>
        <result property="planCheckDate" column="plan_check_date"/>
 
        <result property="isCheck" column="is_check"/>
        <result property="checkUrl" column="check_url"/>
 
 
        <result column="create_user" property="createUser"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="update_user" property="updateUser"/>
 
        <collection property="tbProjectScheduleList" ofType="cn.gistack.sm.sjztmd.entity.TbProjectSchedule">
            <id property="guid" column="scheduleId"/>
            <result property="year" column="year"/>
            <result property="month" column="month"/>
            <result property="actualFund" column="actual_fund"/>
        </collection>
    </resultMap>
 
 
 
 
    <select id="getDetail" resultMap="dto">
        SELECT
            tb.*,
            TPS."guid" as scheduleId,
            TPS."year",
            TPS."month",
            TPS."actual_fund"
        from sjzt_md."tb_project" tb
        LEFT JOIN SJZT_MD."tb_project_schedule" TPS ON TPS."tb_project_id" = tb."guid"
        where
            tb."is_deleted" = 0
            AND tb."guid" = #{id}
    </select>
 
 
 
    <select id="getStatisticsTable" resultType="cn.gistack.sm.sjztmd.statisticsVO.StatisticsTableProject">
        SELECT
            aab."guid" adCode,
            aab."ad_name" adName,
            paab."guid" padCode,
            paab."ad_name" padName,
 
            tps.curMonthActualFund,
            project.totalActualFund,
 
            ifNull(resNum,0) resNum,
            ifNull(bigNum,0) bigNum,
            ifNull(midNum,0) midNum,
            ifNull(smallOneNum,0) smallOneNum,
            ifNull(smallTwoNum,0) smallTwoNum,
 
            dykeLength,
            levelOneLength,
            levelTwoLength,
            levelThreeLength,
            levelFourLength,
            levelFiveLength
        FROM YWXT."att_ad_base" aab
        left join (
            SELECT
                aab."guid",
                aab."ad_name",
                SUM(CASE WHEN arb."code" is not null then 1 else 0 end) as resNum ,
                SUM(CASE WHEN (arb."eng_scal" = '大(1)型' or arb."eng_scal" = '大(2)型') then 1 else 0 end) as bigNum ,
                SUM(CASE WHEN (arb."eng_scal" = '中型') then 1 else 0 end) as midNum ,
                SUM(CASE WHEN (arb."eng_scal" = '小(1)型') then 1 else 0 end) as smallOneNum ,
                SUM(CASE WHEN (arb."eng_scal" = '小(2)型') then 1 else 0 end) as smallTwoNum
            FROM YWXT."att_ad_base" aab
             LEFT JOIN
             (
                 <include refid="selectResByRegion"/>
             ) arb ON ((arb.townCode = aab."guid")or(arb.countyCode = aab."guid") or (arb.cityCode = aab."guid") or (arb.provinceCode = aab."guid") )
            right join sjzt_md."tb_res_general_investigation_state" trgis on trgis."res_guid" = arb."code"
                    <!--统计待审核和已审核的-->
                and (trgis."check_state" = 1 or trgis."check_state" = 2)
                <if test="params.tbYear != null and params.tbYear != ''">
                    and trgis."tb_year" = #{params.tbYear}
                </if>
            group by aab."guid",aab."ad_name"
        )res on res."guid" = aab."guid"
        left join (
            SELECT
                aab."guid",
                aab."ad_name",
 
                SUM(CASE WHEN trd."dyke_guid" is not null then trd.dangerLength else 0 END) as dykeLength,
                SUM(CASE WHEN trd."dyke_level" = '1级' THEN trd.dangerLength ELSE 0 END) AS levelOneLength,
                SUM(CASE WHEN trd."dyke_level" = '2级' THEN trd.dangerLength ELSE 0 END) AS levelTwoLength,
                SUM(CASE WHEN trd."dyke_level" = '3级' THEN trd.dangerLength ELSE 0 END)AS levelThreeLength,
                SUM(CASE WHEN trd."dyke_level" = '4级' THEN trd.dangerLength ELSE 0 END) AS levelFourLength,
                SUM(CASE WHEN trd."dyke_level" = '5级' THEN trd.dangerLength ELSE 0 END) AS levelFiveLength
            FROM YWXT."att_ad_base" aab
            LEFT JOIN (
                SELECT
                    trd."guid",
                    trd."dyke_length",
                    trd."dyke_level",
                    trd."dyke_guid",
                    trd.dangerLength,
                    county."guid" as countyCode,
                    city."guid" as cityCode,
                    province."guid" as provinceCode
                FROM (
                    SELECT
                        tdis."guid",
                        tdis."dyke_guid",
                        trd."ad_code",
                        trd."dyke_level",
                        trd."dyke_length",
                        tdi.dangerLength
                    FROM SJZT_MD."tb_dyke_investigation_state" tdis
                    LEFT JOIN SJZT_MD."tb_res_dyke" trd on trd."guid" = tdis."dyke_guid"
                    LEFT JOIN (
                        SELECT
                            TEMP1."tb_state_id",
                            TEMP1."unit",
                            TEMP1.dangerLength/temp1.num as dangerLength
                        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
                            from sjzt_md."tb_dyke_investigation" tdi
                            where 1=1
 
 
                             <if test="params.tbYear != null and params.tbYear != ''">
                                 AND  tdi."tb_year" = #{params.tbYear}
                            </if>
                            group by tdi."tb_state_id",tdi."dyke_guid",tdi."unit"
                        )TEMP1
                    ) tdi on tdi."tb_state_id" = tdis."guid"
                    <!--统计待审核和已审核的-->
                    where (tdis."check_state" = 1 or tdis."check_state" = 2)
                ) trd
                LEFT JOIN YWXT."att_ad_base" county ON county."ad_code" = trd."ad_code"
                LEFT JOIN YWXT."att_ad_base" city ON city."ad_code" = county."p_ad_code"
                LEFT JOIN YWXT."att_ad_base" province ON province."ad_code" = city."p_ad_code"
            )trd on ((trd.countyCode = aab."guid") or (trd.cityCode = aab."guid") or (trd.provinceCode = aab."guid"))
            group by aab."guid",aab."ad_name"
        )dyke on dyke."guid" = aab."guid"
 
        left join (
            SELECT
                aab."guid",
                aab."ad_name",
                SUM(CASE WHEN tb."actual_fund" then tb."actual_fund" else 0 end) as totalActualFund
            FROM YWXT."att_ad_base" aab
            LEFT JOIN (
                select
                tb."city_code" cityCode,
                tb."county_code" countyCode,
                province."guid" provinceCode,
                tps."actual_fund"
 
                from sjzt_md."tb_project" tb
                LEFT JOIN SJZT_MD."tb_project_schedule" tps on tps."tb_project_id" = tb."guid"
                LEFT JOIN YWXT."att_ad_base" province ON province."ad_code" = tb."city_code"
            )tb on ((tb.countyCode = aab."guid") or (tb.cityCode = aab."guid") or (tb.provinceCode = aab."guid"))
            group by aab."guid",aab."ad_name"
        ) project on project."guid" = aab."guid"
 
        left join (
            SELECT
            aab."guid",
            aab."ad_name",
            tb."actual_fund" curMonthActualFund
 
            FROM YWXT."att_ad_base" aab
            LEFT JOIN (
                select
                tb."city_code" cityCode,
                tb."county_code" countyCode,
                province."guid" provinceCode,
                tps."actual_fund"
 
                from sjzt_md."tb_project" tb
                LEFT JOIN SJZT_MD."tb_project_schedule" tps on tps."tb_project_id" = tb."guid"
                LEFT JOIN YWXT."att_ad_base" province ON province."ad_code" = tb."city_code"
                where
                    1=1
                    <if test="params.tbYear != null and params.tbYear !=''">
                    AND tps."year" = #{params.tbYear}
                    </if>
                  <if test="params.tbMonth != null and params.tbMonth != ''">
                      and tps."month" = #{params.tbMonth}
                  </if>
            )tb on ((tb.countyCode = aab."guid") or (tb.cityCode = aab."guid") or (tb.provinceCode = aab."guid"))
        ) tps on tps."guid" = aab."guid"
 
        left join ywxt."att_ad_base" paab on paab."guid" = aab."p_ad_code"
        where
            1=1
            <if test="params.adCode != null and params.adCode !=''">
            AND aab."p_ad_code" = #{params.adCode}
            </if>
    </select>
    <select id="getTbProjectInfo" resultType="cn.gistack.sm.sjztmd.entity.TbProject">
        SELECT
            *
        FROM SJZT_MD."tb_project"
        where 1=1
        <if test="params.cityCode != null and params.cityCode !=''">
            and "city_code"  = #{params.cityCode}
        </if>
        <if test="params.countyCode != null and params.countyCode !=''">
            and "county_code"  = #{params.countyCode}
        </if>
        <if test="params.tbYear != null and params.tbYear !=''">
            and "tb_year" = #{params.tbYear}
        </if>
    </select>
</mapper>