张磊磊
2023-12-11 62b8f41aced0c0772f4d4eb1aba9d9697c0f8f61
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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<?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.screen.modules.biz.bigscreen.mapper.BigScreenMapper">
 
    <select id="queryAllProject" resultType="com.thhy.screen.modules.biz.bigscreen.entity.PipeYearCount">
        select pro_id as proId,pro_name as proName,plan_output as planOutput from sys_project where is_use = 1 and company_id=#{companyId}
    </select>
 
    <select id="pipePlanActual" resultType="com.thhy.screen.modules.biz.bigscreen.entity.PipePlanActual">
        select e.planProduct,d.ringCount,ROUND((d.ringCount*100/e.planProduct),3) as completeRate from
        (
        select sum(plan_product) as planProduct,1 as wl
        from t_pipe_plan tpp
        left join sys_project sp on sp.pro_id = tpp.pro_id
        where sp.company_id = #{companyId} and tpp.pro_id = #{proId} and tpp.plan_year = YEAR(SYSDATE())
        ) e
        left join (
 
        select count(a.ringNum) as ringCount,1 as wl
        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
        left join sys_project sp1 on sp1.pro_id = tpi.pro_id
        where tpi.check_result = 1 and tpi.pro_id = #{proId} and YEAR(tpi.check_time) = YEAR(SYSDATE()) and sp1.company_id = #{companyId}
        GROUP BY tpi.ring_num,tpi.pro_id) a where a.ringBlocks = a.proBlocks
        ) d on e.wl = d.wl
    </select>
 
    <select id="pipeMonthPlanActual" resultType="com.thhy.screen.modules.biz.bigscreen.entity.PipeMonthPlanActual">
        select CONCAT(e.`month`,'月') as `month`,e.planProduct,case when d.actualProduct is null then 0 else d.actualProduct end as actualProduct
        from
        (
        select ppm.`month`,sum(ppm.plan_product) as planProduct
        from t_pipe_plan_month ppm
        left join t_pipe_plan pp on pp.plan_id = ppm.pipe_plan_id
        left join sys_project sp on pp.pro_id = sp.pro_id
        where pp.plan_year = YEAR(SYSDATE()) and sp.company_id = #{companyId}
        group by ppm.`month`
        ) e
        left join
        (
        select a.lastMonth,count(a.ringNum) as actualProduct
        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,MONTH(max(tpi.check_time)) as lastMonth
        from t_pipe_info tpi
        left join sys_dict sd on sd.dict_id = tpi.block_num
        left join sys_project sp1 on tpi.pro_id = sp1.pro_id
        where tpi.check_result = 1 and YEAR(tpi.check_time) = YEAR(SYSDATE()) and sp1.company_id = #{companyId}
 
        GROUP BY tpi.ring_num,tpi.pro_id) a where a.ringBlocks = a.proBlocks
        group by a.lastMonth
        ) d on e.`month` = d.lastMonth
    </select>
 
    <select id="materialWeekAndMonth" resultType="com.thhy.screen.modules.biz.bigscreen.entity.MaterialWeekAndMonth">
        select a.dict_name as materialName,case when b.materialValue is null then 0 else b.materialValue end as weekValue,
               case when c.materialValue is null then 0 else c.materialValue end as monthValue
        from
            (
                select dict_id,dict_name
                from sys_dict sd
                where sd.dict_type = 'pipe_materials'
                order by sd.dict_value
            ) a
                left join
            (
                select mmi.material_name as materialName,SUM(mmi.material_value) as materialValue
                from t_mix_material_info mmi
                         left join t_mix_material mm on mmi.mix_material_id = mm.id
                where mm.company_id = #{companyId} and YEARWEEK(mm.create_time,1) = YEARWEEK(SYSDATE(),1)
                group by mmi.material_name
            ) b on a.dict_id = b.materialName
                left join
            (
                select mmi.material_name as materialName,SUM(mmi.material_value) as materialValue
                from t_mix_material_info mmi
                         left join t_mix_material mm on mmi.mix_material_id = mm.id
                where mm.company_id = #{companyId} and YEAR(SYSDATE()) = YEAR(mm.create_time) and MONTH(SYSDATE()) = MONTH(mm.create_time)
        group by mmi.material_name
            ) c on a.dict_id = c.materialName
    </select>
 
    <!--新版-->
    <select id="materialWeekMonth" resultType="com.thhy.screen.modules.biz.bigscreen.entity.MaterialWeekAndMonth">
        select a.dict_id,a.dict_name as materialName,case when b.monthValue is NULL then 0 else b.monthValue end as monthValue,
               case when c.weekValue is NULL then 0 else c.weekValue end as weekValue
        from
            (
                select dict_id,dict_name
                from sys_dict sd
                where sd.dict_type = 'pipe_materials'
                order by sd.dict_value
            ) a
                left join
            (
                select msr.material_name,sum(msr.material_value) as monthValue
                from t_material_stock_record msr
                where msr.type = 2 and msr.company_id = #{companyId} and  DATE_FORMAT(SYSDATE(),'%Y-%m') = DATE_FORMAT(msr.create_date,'%Y-%m')
                group by msr.material_name
            ) b on a.dict_id = b.material_name
                left join
            (
                select msr.material_name,sum(msr.material_value) as weekValue
                from t_material_stock_record msr
                where msr.type = 2 and msr.company_id = #{companyId} and YEARWEEK(SYSDATE(),1) = YEARWEEK(msr.create_date,1)
                group by msr.material_name
            ) c on a.dict_id = c.material_name
    </select>
 
    <select id="WaterCulInfo" resultType="com.thhy.screen.modules.biz.bigscreen.entity.WaterCulInfo">
        SELECT wc1.water_cultivated_name as waterCultivatedName,wc1.max_size as maxSize,m.ph_value as ph,m.temperature as tem,
               (select count(id) from t_pipe_cultivated where out_water = 1 and water_cultivated_id = wc1.water_cultivated_id) as waterCount
        from t_water_cultivated wc1
        left join
             (
                 select a.water_cultivated_id,a.maxReleaseTime,wcdd1.ph_value,wcdd1.temperature from t_water_cultivated_device_data wcdd1
                 left join
                 (
                     select wc.water_cultivated_id,max(wcdd.release_time) as maxReleaseTime
                     from t_water_cultivated_device_data wcdd
                              left join t_water_cultivated_device wcd on wcd.device_id = wcdd.device_id
                              left join t_water_cultivated wc on wc.water_cultivated_id = wcd.water_cultivated_id
                     group by wc.water_cultivated_id
                 ) a on wcdd1.release_time = a.maxReleaseTime
             ) m on wc1.water_cultivated_id = m.water_cultivated_id
        where wc1.is_use = 1 and wc1.company_id = #{companyId}
    </select>
 
    <select id="repoInfo" resultType="com.thhy.screen.modules.biz.bigscreen.entity.RepoInfo">
        select r.repo_id as repoId,r.repo_name as repoName,r.max_size as maxSize,
               case when a.ringCount is null then 0 else a.ringCount end as ringCount,
               case when a.pipeCount is null then 0 else a.pipeCount end as pipeCount,
               (select count(id) from t_repo_record_pipe where repo_id = r.repo_id and out_repo = 0 and DATE_ADD(create_time,INTERVAL r.save_time DAY) > sysdate()) as intime
        from t_repo r
             left join
             (
                 select rrp.repo_id,count(DISTINCT rrp.ring_num) as ringCount,count(DISTINCT rrp.pipe_num) as pipeCount
                 from
                     t_repo_record_pipe rrp
                 where rrp.out_repo = 0
                 group by rrp.repo_id
             ) a on r.repo_id = a.repo_id
        where r.company_id = #{companyId}
    </select>
 
    <select id="sendInfo" resultType="com.thhy.screen.modules.biz.bigscreen.entity.SendInfo">
        select DATE_FORMAT(a.ymd,'%Y-%m') as ym,case when b.pipeCount is null then 0 else b.pipeCount end as pipeCount
        from
            (
                select @s:=DATE_ADD(@s,INTERVAL -1 MONTH) as ymd from mysql.help_topic,(select @s:=DATE_ADD(SYSDATE(),INTERVAL 1 MONTH)) temp where @s > DATE_ADD(SYSDATE(),INTERVAL -4 MONTH)
            ) a
                left join
            (
                select DATE_FORMAT(po.create_time,'%Y-%m') as ym,count(pop.pipe_id) as pipeCount
                from t_pipe_out_pipe pop
                         left join t_pipe_out po on po.pipe_out_id = pop.pipe_out_id
                         left join t_pipe_info tpi on tpi.pipe_id = pop.pipe_id
                         left join sys_project sp on tpi.pro_id = sp.pro_id
                where po.is_use = 1 and sp.company_id = #{companyId}
                group by DATE_FORMAT(po.create_time,'%Y-%m')
            ) b on DATE_FORMAT(a.ymd,'%Y-%m') = b.ym
    </select>
 
    <select id="displayText" resultType="hashmap">
        select dis_en_text as disEnText,dis_cn_text as disCnText
        from t_screen_display
        where is_use = 1 order by create_time desc limit 1
    </select>
 
    <select id="monthRingNumByPro" resultType="hashmap">
        select DATE_FORMAT(m.`month`,'%Y-%m') as `month`,
        case when n.ringCount is NULL then 0 else n.ringCount end as ringCount,
        case when x.planProduct is NULL then 0 else x.planProduct end as planProduct
        from
        (SELECT @s := DATE_ADD(@s,INTERVAL 1 MONTH) as `month` FROM mysql.help_topic,(SELECT @s := DATE_ADD(DATE_FORMAT(SYSDATE(),'%Y-01-01'),INTERVAL -1 MONTH)) temp WHERE @s &lt; DATE_FORMAT(SYSDATE(),'%Y-12-01')) m
 
        left join
        (
        select b.lastMonth,count(b.ringNum) as ringCount from
        (
        select *
        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
        left join sys_project sp on sp.pro_id = tpi.pro_id
        where tpi.check_result = 1 and sp.company_id = #{companyId} and tpi.pro_id = #{proId} and YEAR(check_time) = YEAR(SYSDATE())
        GROUP BY tpi.ring_num,tpi.pro_id) a where a.ringBlocks = a.proBlocks
        ) b group by b.lastMonth
 
        ) n on DATE_FORMAT(m.`month`,'%Y-%m') = n.lastMonth
 
        left join
        (
        select DATE_FORMAT(DATE(CONCAT(pp.plan_year,'-',ppm.`month`,'-01')),'%Y-%m') as `month`,sum(ppm.plan_product) as planProduct
        from t_pipe_plan_month ppm
        left join t_pipe_plan pp on ppm.pipe_plan_id = pp.plan_id
        left join sys_project sp on sp.pro_id = pp.pro_id
        where sp.company_id = #{companyId} AND sp.pro_id = #{proId} AND pp.plan_year = YEAR(SYSDATE()) group by DATE_FORMAT(DATE(CONCAT(pp.plan_year,'-',ppm.`month`,'-01')),'%Y-%m')
        ) x on x.`month` = DATE_FORMAT(m.`month`,'%Y-%m')
    </select>
 
    <insert id="insertAudioGroup">
        INSERT INTO t_audio_group
        <trim suffix=")" prefix="(" suffixOverrides=",">
            <if test="id != null and id !=null">
                id,
            </if>
            <if test="groupId != null">
                group_id,
            </if>
            <if test="groupName != null and groupName !=null">
                group_name,
            </if>
        </trim>
        <trim suffix=")" prefix=" values(" suffixOverrides=",">
            <if test="id != null and id !=null">
                #{id},
            </if>
            <if test="groupId != null">
                #{groupId},
            </if>
            <if test="groupName != null and groupName !=null">
                #{groupName},
            </if>
        </trim>
    </insert>
 
    <select id="queryGroups" resultType="com.thhy.screen.modules.biz.audio.entity.AudioGroup">
        select id,group_id as groupId,group_name as groupName from t_audio_group
        <where>
            <if test="groupId != null and groupId !=''">
                id = #{groupId}
            </if>
        </where>
    </select>
 
    <!--钢筋总消耗,周消耗,月消耗-->
    <select id="querySteelMake" resultType="hashmap">
        select steel.steel_id,CONCAT(steel.steel_name,'-',steel_model) as steelName,
               case when a.totalStock is NULL then 0 else a.totalStock end as totalStock,
               case when b.weekStock is NULL then 0 else b.weekStock end as weekStock,
               case when c.monthStock is NULL then 0 else c.monthStock end as monthStock
        from sys_steel steel
                 left join
             (
                 select ssr.steel_id,sum(ssr.change_stock) as totalStock from sys_steel_record ssr
                 where ssr.stock_type = 2
                 group by ssr.steel_id
             ) a on steel.steel_id = a.steel_id
 
                 left join
             (
                 select ssr.steel_id,sum(ssr.change_stock) as weekStock from sys_steel_record ssr
                 where ssr.stock_type = 2 and YEAR(SYSDATE()) = YEAR(ssr.create_time) and WEEK(sysdate(),1) = WEEK(ssr.create_time,1)
        group by ssr.steel_id
            ) b on steel.steel_id = b.steel_id
 
            left join
            (
            select ssr.steel_id,sum(ssr.change_stock) as monthStock from sys_steel_record ssr
            where ssr.stock_type = 2 and YEAR(SYSDATE()) = YEAR(ssr.create_time) and MONTH(SYSDATE()) = MONTH(ssr.create_time)
            group by ssr.steel_id
            ) c on steel.steel_id = c.steel_id
            ORDER BY c.monthStock desc
    </select>
 
    <!--获取静养区-->
    <select id="queryRestInfo" resultType="hashmap">
        select sd.device_id as deviceId,sd.device_name as deviceName,(select tem from t_rest_data trd where trd.device_id = sd.device_id order by check_time desc limit 1) as tem
        from sys_device sd where sd.produce_order = '静养'
    </select>
 
    <insert id="insertAudioFile">
        insert into  t_audio_group_file
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id !=null and id !=''">
                id,
            </if>
            <if test="name !=null and name !=''">
                name,
            </if>
            <if test="groupId !=null and groupId !=''">
                group_id,
            </if>
            <if test="audioFile !=null and audioFile !=''">
                audio_file,
            </if>
            <if test="defaults !=null">
                `defaults`,
            </if>
        </trim>
        <trim prefix=" values (" suffix=")" suffixOverrides=",">
            <if test="id !=null and id !=''">
                #{id},
            </if>
            <if test="name !=null and name !=''">
                #{name},
            </if>
            <if test="groupId !=null and groupId !=''">
                #{groupId},
            </if>
            <if test="audioFile !=null and audioFile !=''">
                #{audioFile},
            </if>
            <if test="defaults !=null">
                #{defaults},
            </if>
        </trim>
    </insert>
 
    <update id="updateAudioFile">
        UPDATE  t_audio_group_file
        <set>
            <trim suffixOverrides=",">
                <if test="groupId !=null and groupId !=''">
                    group_id = #{groupId},
                </if>
                <if test="audioFile !=null and audioFile !=''">
                    audio_file = #{groupFile},
                </if>
                <if test="defaults !=null">
                    `defaults` = #{defaults},
                </if>
            </trim>
        </set>
        where id = #{id}
    </update>
 
    <delete id="deleteAudioFile">
        delete from t_audio_group_file where group_id = #{groupId}
    </delete>
 
    <select id="queryGroupInfo" resultType="com.thhy.screen.modules.biz.audio.entity.GroupInfoVo">
        select id,group_name as groupName
            from t_audio_group where id = #{id}
    </select>
 
    <select id="queryFileByGroup" resultType="com.thhy.screen.modules.biz.audio.entity.AudioFile">
        select id,group_id as groupId,audio_file as audioFile,`defaults` from t_audio_group_file where group_id = #{groupId}
    </select>
</mapper>