张磊磊
2023-11-08 2b2d292c1a274aa95aab8c2ac20530e54a503923
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="com.thhy.materials.modules.biz.pipeplan.mapper.PipePlanMapper">
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        t.plan_id as planId,
        t.pro_id as proId,
        t.plan_year as planYear,
        t.plan_product as planProduct,
        t.size as size,
        t.create_time as createTime,
        t.create_user as createUser,
        t.update_time as updateTime,
        t.update_user as updateUser
    </sql>
 
    <sql id="condition_query">
        <where>
            <trim suffixOverrides=" AND ">
                t.is_use = 1 AND
                <if test="proId!=null and proId!=''">
                    t.pro_id = #{proId} AND
                </if>
                <if test="planYear!=null">
                    t.plan_year = #{planYear} AND
                </if>
                <if test="planProduct!=null">
                    t.plan_product = #{planProduct} AND
                </if>
                <if test="size!=null and size!=''">
                    t.size = #{size} AND
                </if>
                <if test="createTime!=null">
                    t.create_time = #{createTime} AND
                </if>
                <if test="createUser!=null and createUser!=''">
                    t.create_user = #{createUser} AND
                </if>
                <if test="updateTime!=null">
                    t.update_time = #{updateTime} AND
                </if>
                <if test="updateUser!=null and updateUser!=''">
                    t.update_user = #{updateUser} AND
                </if>
            </trim>
        </where>
    </sql>
 
    <select id="queryById" resultType="com.thhy.materials.modules.biz.pipeplan.entity.PipePlan">
        select <include refid="Base_Column_List" />
        from t_pipe_plan t
        where t.plan_id=#{planId}
    </select>
 
    <select id="queryVersionById" resultType="integer">
        select version from t_pipe_plan
        where plan_id=#{planId}
    </select>
 
    <!--查询列表-->
    <select id="findList" resultType="com.thhy.materials.modules.biz.pipeplan.entity.PipePlanListVo">
        SELECT
        t.plan_id as planId,
        t.pro_id as proId,
        t.plan_year as planYear,
        t.plan_product as planProduct,
        t.size as size,
        sp.pro_name as proName,
        sd.dict_name as sizeName
        from t_pipe_plan t
        left join sys_project sp on sp.pro_id = t.pro_id
        left join sys_dict sd on sd.dict_id = t.size
        <include refid="condition_query" />
        AND sp.company_id = #{companyId}
        order by t.create_time desc
    </select>
 
    <!--查询列表-->
    <select id="findAll" resultType="com.thhy.materials.modules.biz.pipeplan.entity.PipePlan">
        SELECT
        <include refid="Base_Column_List" />
        from t_pipe_plan t
    </select>
 
    <!--插入操作-->
    <insert id="insert">
        insert into t_pipe_plan
        <trim prefix="(" suffix=")" suffixOverrides="," >
            <if test="planId != null">
                plan_id,
            </if>
            <if test="proId != null">
                pro_id,
            </if>
            <if test="planYear != null">
                plan_year,
            </if>
            <if test="planProduct != null">
                plan_product,
            </if>
            <if test="size != null">
                size,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="createUser != null">
                create_user,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="updateUser != null">
                update_user,
            </if>
        </trim>
 
        <trim prefix="values (" suffix=")" suffixOverrides="," >
            <if test="planId != null">
                #{planId},
            </if>
            <if test="proId != null">
                #{proId},
            </if>
            <if test="planYear != null">
                #{planYear},
            </if>
            <if test="planProduct != null">
                #{planProduct},
            </if>
            <if test="size != null">
                #{size},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="createUser != null">
                #{createUser},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
            <if test="updateUser != null">
                #{updateUser},
            </if>
        </trim>
    </insert>
 
 
    <!--更新操作-->
    <update id="update">
        update t_pipe_plan
        <set>
            <if test="proId != null">
                pro_id=#{proId},
            </if>
            <if test="planYear != null">
                plan_year=#{planYear},
            </if>
            <if test="planProduct != null">
                plan_product=#{planProduct},
            </if>
            <if test="size != null">
                size=#{size},
            </if>
            <if test="createTime != null">
                create_time=#{createTime},
            </if>
            <if test="createUser != null">
                create_user=#{createUser},
            </if>
            <if test="updateTime != null">
                update_time=#{updateTime},
            </if>
            <if test="updateUser != null">
                update_user=#{updateUser},
            </if>
        </set>
        where plan_id=#{planId}
    </update>
 
    <!--逻辑删除-->
    <update id="deletelogic">
        update t_pipe_plan
        SET is_use = 0
        where plan_id=#{planId}
    </update>
 
    <!--根据ID删除-->
    <delete id="deleteById">
        delete from t_pipe_plan
        where plan_id=#{planId}
    </delete>
 
    <select id="queryMonthList" resultType="com.thhy.materials.modules.biz.pipeplanmonth.entity.PipePlanMonth">
        select c.month,case when c.planProduct is null then 0 else c.planProduct end as planProduct from (select a.`index` as month,b.plan_product as planProduct from (SELECT @s :=@s + 1 as `index` FROM mysql.help_topic,(SELECT @s := 0) temp WHERE @s &lt; 12) a
        left join
        (select `month`,plan_product from t_pipe_plan_month where
        <if test="pipePlanId!=null and pipePlanId !=''">
            pipe_plan_id = #{pipePlanId}
        </if>
        <if test="pipePlanId==null or pipePlanId ==''">
            pipe_plan_id = -1
        </if>
 
        ) b on a.index=b.month) c
    </select>
 
    <select id="sumProduct" resultType="double">
        select sum(plan_product) from t_pipe_plan_month where pipe_plan_id = #{pipePlanId}
    </select>
 
    <select id="queryPlanProductByPlan" resultType="com.thhy.materials.modules.biz.pipeplan.entity.PlanMonthCal">
        SELECT GROUP_CONCAT(c.planProduct order by c.MONTH) as resultStr,sum(c.planProduct) as resultSum FROM
        (
        SELECT
        1 as wl,
        a.`index` AS MONTH,
        case when b.plan_product is NULL then '0' else b.plan_product end
        AS planProduct
        FROM
        (
        SELECT
        @s := @s + 1 AS `index`
        FROM
        mysql.help_topic,(
        SELECT
        @s := 0
        ) temp
        WHERE
        @s &lt; 13
        ) a
        LEFT JOIN ( SELECT `month`, plan_product FROM t_pipe_plan_month WHERE pipe_plan_id = #{planId} ) b ON a.INDEX = b.MONTH
        ) c group by c.wl
    </select>
 
    <select id="queryProductedByPlan" resultType="com.thhy.materials.modules.biz.pipeplan.entity.PlanMonthCal">
        select sum(e.resultSum) as resultSum,GROUP_CONCAT(e.resultSum order by e.resultStr) as resultStr  from (select d.ym as resultStr,1 as wl,case when b.resultSum is null then 0 else b.resultSum end as resultSum
        from (select DATE_FORMAT(CONCAT(#{planYear},'-',c.`month`,'-01'),'%Y-%m') as ym
        from (SELECT @s := @s + 1 AS `month` FROM mysql.help_topic,(SELECT @s := 0) temp WHERE @s &lt; 12) c) d
        left join
        (
        select a.lastMonth,count(a.ringNum) as resultSum
        from
        (select tpi.ring_num as ringNum,tpi.pro_id,GROUP_CONCAT(sd.dict_name order by sd.dict_value) as ringBlocks,
 
        (select GROUP_CONCAT(sd1.dict_name order by sd1.dict_value) from sys_pro_blok pb left join sys_dict sd1 on sd1.dict_id = pb.block_num where pb.pro_id = tpi.pro_id group by pb.pro_id) as proBlocks,DATE_FORMAT(max(tpi.check_time),'%Y-%m') as lastMonth
        from t_pipe_info tpi
        left join sys_dict sd on sd.dict_id = tpi.block_num
        where tpi.check_result = 1 and tpi.check_time &gt; DATE(CONCAT(#{planYear},'-01-01 00:00:00'))
        and tpi.check_time &lt; DATE(CONCAT(#{planYear},'-12-31 23:59:59')) and tpi.pro_id = #{proId} and tpi.size = #{size}
        GROUP BY tpi.ring_num,tpi.pro_id) a where a.ringBlocks = a.proBlocks
        GROUP BY a.lastMonth
        ) b on d.ym = b.lastMonth) e
        group by e.wl
    </select>
 
    <select id="countByPYS" resultType="int">
        select count(plan_id) from t_pipe_plan where pro_id = #{proId} and size = #{size} and plan_year = #{planYear} and is_use = 1
    </select>
 
    <select id="queryByPYS" resultType="String">
        select plan_id from t_pipe_plan where pro_id = #{proId} and size = #{size} and plan_year = #{planYear} and is_use = 1
    </select>
 
</mapper>