chenlu
2025-11-24 943e4b59e43ce34d5b0967c8b73fef76eefe68bb
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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
<?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.example.erp.mapper.pp.PatchLogMapper">
 
 
 
    <!--获取补片数据-->
    <select id="SelectReplenish"  >
        select
        r.id,
        r.review_status,
        r.reporting_work_id,
        r.patch_id,
        r.process_id,
        r.order_id,
        r.order_sort,
        o.project,
        o.batch,
        od.building_number,
        od.product_name,
        r.technology_number,
        ogd.glass_address,
        ogd.glass_child,
        r.patch_num,
        ogd.child_width as width,
        ogd.child_height as height,
        od.shape,
        r.patch_type,
        r.patch_reason,
        r.responsible_team,
        r.responsible_personnel,
        r.responsible_equipment,
        r.patch_area,
        r.quality_inspector,
        r.patch_processes,
        r.reviewer,
        r.create_time as create_time,
        date(r.update_time) as update_time,
        JSON_UNQUOTE( JSON_EXTRACT( od.other_columns, '$.S01' )) AS glassNumber
        from pp.patch_log r left join sd.order_detail od on r.order_id=od.order_id and r.order_sort=od.order_number
        left join sd.`order` o on r.order_id = o.order_id
        left join (select * from sd.order_glass_detail group by order_id,order_number,technology_number) as ogd
        on r.order_id = ogd.order_id and r.order_sort = ogd.order_number and r.technology_number=ogd.technology_number
        <where>
            date(r.create_time)>=#{startDate} and date(r.create_time) &lt;= #{endDate}
            and o.create_order>0
            <if test="patchLog.patchId != null and patchLog.patchId != ''">
                and r.patch_id regexp #{patchLog.patchId}
            </if>
            <if test="patchLog.orderId != null and patchLog.orderId != ''">
                and r.order_id regexp #{patchLog.orderId}
            </if>
            <if test="patchLog.reportingWorkId != null and patchLog.reportingWorkId != ''">
                and r.reporting_work_id regexp #{patchLog.reportingWorkId}
            </if>
            <if test="patchLog.processId != null and patchLog.processId != ''">
                and r.process_id regexp #{patchLog.processId}
            </if>
            <if test="patchLog.project != null and patchLog.project != ''">
                and o.project regexp #{patchLog.project}
            </if>
            <if test="patchLog.batch != null and patchLog.batch != ''">
                and o.batch regexp #{patchLog.batch}
            </if>
            <if test="patchLog.orderSort != null and patchLog.orderSort != ''">
                and r.order_sort regexp #{patchLog.orderSort}
            </if>
            <if test="patchLog.buildingNumber != null and patchLog.buildingNumber != ''">
                and od.building_number regexp #{patchLog.buildingNumber}
            </if>
            <if test="patchLog.productName != null and patchLog.productName != ''">
                and od.product_name regexp #{patchLog.productName}
            </if>
            <if test="patchLog.technologyNumber != null and patchLog.technologyNumber != ''">
                and r.technology_number regexp #{patchLog.technologyNumber}
            </if>
            <if test="patchLog.qualityInspector != null and patchLog.qualityInspector != ''">
                and r.quality_inspector regexp #{patchLog.qualityInspector}
            </if>
            <if test="patchLog.width != null and patchLog.width != ''">
                and ogd.child_width regexp REGEXP_REPLACE(#{patchLog.width},'\\.0+$','')
            </if>
            <if test="patchLog.height != null and patchLog.height != ''">
                and ogd.child_height regexp REGEXP_REPLACE(#{patchLog.height},'\\.0+$','')
            </if>
            <if test="patchLog.shape != null and patchLog.shape != ''">
                and od.shape regexp #{patchLog.shape}
            </if>
            <if test="patchLog.patchNum != null and patchLog.patchNum != ''">
                and r.patch_num regexp #{patchLog.patchNum}
            </if>
            <if test="patchLog.glassAddress != null and patchLog.glassAddress != ''">
                and ogd.glass_address regexp #{patchLog.glassAddress}
            </if>
            <if test="patchLog.glassChild != null and patchLog.glassChild != ''">
                and ogd.glass_child regexp #{patchLog.glassChild}
            </if>
            <if test="patchLog.responsibleTeam != null and patchLog.responsibleTeam != ''">
                and r.responsible_team regexp #{patchLog.responsibleTeam}
            </if>
            <if test="patchLog.responsibleEquipment != null and patchLog.responsibleEquipment != ''">
                and r.responsible_equipment regexp #{patchLog.responsibleEquipment}
            </if>
            <if test="patchLog.responsiblePersonnel != null and patchLog.responsiblePersonnel != ''">
                and r.responsible_personnel regexp #{patchLog.responsiblePersonnel}
            </if>
            <if test="patchLog.patchType != null and patchLog.patchType != ''">
                and r.patch_type regexp #{patchLog.patchType}
            </if>
            <if test="patchLog.patchReason != null and patchLog.patchReason != ''">
                and r.patch_reason regexp #{patchLog.patchReason}
            </if>
            <if test="patchLog.patchArea != null and patchLog.patchArea != ''">
                and r.patch_area regexp #{patchLog.patchArea}
            </if>
            <if test="patchLog.qualityInspector != null and patchLog.qualityInspector != ''">
                and r.quality_inspector regexp #{patchLog.qualityInspector}
            </if>
            <if test="patchLog.patchProcesses != null and patchLog.patchProcesses != ''">
                and r.patch_processes regexp #{patchLog.patchProcesses}
            </if>
            <if test="patchLog.reviewer != null and patchLog.reviewer != ''">
                and r.reviewer regexp #{patchLog.reviewer}
            </if>
        </where>
         order by r.review_status,r.id desc
        limit #{offset},#{pageSize};
    </select>
 
    <select id="SelectReplenishPageTotal" >
        select CEILING(count(zu.id)/#{pageSize}) as 'pageTotal',
        count(zu.id) as 'total'
        from (select r.id as id
        from pp.patch_log r left join sd.order_detail od on r.order_id=od.order_id and r.order_sort=od.order_number
        left join sd.`order` o on r.order_id = o.order_id
        left join (select * from sd.order_glass_detail group by order_id,order_number,technology_number) as ogd
        on r.order_id = ogd.order_id and r.order_sort = ogd.order_number and r.technology_number=ogd.technology_number
        <where>
            date(r.create_time)>=#{startDate} and date(r.create_time) &lt;= #{endDate}
            <if test="patchLog.patchId != null and patchLog.patchId != ''">
                and r.patch_id regexp #{patchLog.patchId}
            </if>
            <if test="patchLog.orderId != null and patchLog.orderId != ''">
                and r.order_id regexp #{patchLog.orderId}
            </if>
            <if test="patchLog.reportingWorkId != null and patchLog.reportingWorkId != ''">
                and r.reporting_work_id regexp #{patchLog.reportingWorkId}
            </if>
            <if test="patchLog.processId != null and patchLog.processId != ''">
                and r.process_id regexp #{patchLog.processId}
            </if>
            <if test="patchLog.project != null and patchLog.project != ''">
                and o.project regexp #{patchLog.project}
            </if>
            <if test="patchLog.batch != null and patchLog.batch != ''">
                and o.batch regexp #{patchLog.batch}
            </if>
            <if test="patchLog.orderSort != null and patchLog.orderSort != ''">
                and r.order_sort regexp #{patchLog.orderSort}
            </if>
            <if test="patchLog.buildingNumber != null and patchLog.buildingNumber != ''">
                and od.building_number regexp #{patchLog.buildingNumber}
            </if>
            <if test="patchLog.productName != null and patchLog.productName != ''">
                and od.product_name regexp #{patchLog.productName}
            </if>
            <if test="patchLog.technologyNumber != null and patchLog.technologyNumber != ''">
                and r.technology_number regexp #{patchLog.technologyNumber}
            </if>
            <if test="patchLog.qualityInspector != null and patchLog.qualityInspector != ''">
                and r.quality_inspector regexp #{patchLog.qualityInspector}
            </if>
            <if test="patchLog.width != null and patchLog.width != ''">
                and ogd.child_width regexp REGEXP_REPLACE(#{patchLog.width},'\\.0+$','')
            </if>
            <if test="patchLog.height != null and patchLog.height != ''">
                and ogd.child_height regexp REGEXP_REPLACE(#{patchLog.height},'\\.0+$','')
            </if>
            <if test="patchLog.shape != null and patchLog.shape != ''">
                and od.shape regexp #{patchLog.shape}
            </if>
            <if test="patchLog.patchNum != null and patchLog.patchNum != ''">
                and r.patch_num regexp #{patchLog.patchNum}
            </if>
            <if test="patchLog.glassAddress != null and patchLog.glassAddress != ''">
                and ogd.glass_address regexp #{patchLog.glassAddress}
            </if>
            <if test="patchLog.glassChild != null and patchLog.glassChild != ''">
                and ogd.glass_child regexp #{patchLog.glassChild}
            </if>
            <if test="patchLog.responsibleTeam != null and patchLog.responsibleTeam != ''">
                and r.responsible_team regexp #{patchLog.responsibleTeam}
            </if>
            <if test="patchLog.responsibleEquipment != null and patchLog.responsibleEquipment != ''">
                and r.responsible_equipment regexp #{patchLog.responsibleEquipment}
            </if>
            <if test="patchLog.responsiblePersonnel != null and patchLog.responsiblePersonnel != ''">
                and r.responsible_personnel regexp #{patchLog.responsiblePersonnel}
            </if>
            <if test="patchLog.patchType != null and patchLog.patchType != ''">
                and r.patch_type regexp #{patchLog.patchType}
            </if>
            <if test="patchLog.patchReason != null and patchLog.patchReason != ''">
                and r.patch_reason regexp #{patchLog.patchReason}
            </if>
            <if test="patchLog.patchArea != null and patchLog.patchArea != ''">
                and r.patch_area regexp #{patchLog.patchArea}
            </if>
            <if test="patchLog.qualityInspector != null and patchLog.qualityInspector != ''">
                and r.quality_inspector regexp #{patchLog.qualityInspector}
            </if>
            <if test="patchLog.patchProcesses != null and patchLog.patchProcesses != ''">
                and r.patch_processes regexp #{patchLog.patchProcesses}
            </if>
            <if test="patchLog.reviewer != null and patchLog.reviewer != ''">
                and r.reviewer regexp #{patchLog.reviewer}
            </if>
        </where>
        ) as zu
    </select>
 
 
 
 
    <select id="getMaximum" >
        SELECT IFNULL(patch_id,'00')
        FROM patch_log
        WHERE DATE(create_time) = CURDATE()
        ORDER BY create_time DESC
            LIMIT 1;
    </select>
 
 
    <insert id="insertReplenish"  useGeneratedKeys="true" >
        insert into pp.patch_log(patch_id,reporting_work_id,process_id,order_id, order_sort, technology_number, responsible_team,
                              responsible_personnel, patch_type, patch_reason, patch_processes, patch_num,
                                 patch_area,responsible_equipment,quality_inspector, reviewer, review_status, create_time)
        values (
                   #{oddNumber}, #{patchLog.reportingWorkId},#{patchLog.processId},#{patchLog.orderId},#{patchLog.orderSort},#{patchLog.technologyNumber},
                #{patchLog.responsibleTeam},#{patchLog.responsiblePersonnel},#{patchLog.patchType},#{patchLog.patchReason},
                #{patchLog.patchProcesses},#{patchLog.patchNum},#{patchLog.patchArea},#{patchLog.responsibleEquipment},#{patchLog.qualityInspector},"",0,now()
               )
    </insert>
 
    <update id="updateReplenish"  >
        update pp.patch_log set reviewer=#{userName},review_status=1,update_time=now() where id=#{patchLog.id}
    </update>
 
 
    <update id="updateOrderProcessDetail"  >
        update sd.order_process_detail
        set reporting_work_num=reporting_work_num - #{patchLog.patchNum}
        where order_id = #{patchLog.orderId}
          and process_id = #{patchLog.processId}
          and order_number = #{patchLog.orderSort}
          and technology_number = #{patchLog.technologyNumber}
          and id <![CDATA[<]]> (select a.opdid
                       from (select id as opdid
                             from sd.order_process_detail opd
                             where opd.order_id = #{patchLog.orderId}
                               and opd.process_id = #{patchLog.processId}
                               and opd.order_number = #{patchLog.orderSort}
                               and opd.technology_number = #{patchLog.technologyNumber}
                               and process = #{reportingWork.thisProcess}) as a)
    </update>
 
    <update id="updateDamageDetails"  >
        update pp.damage_details set quantity=quantity+#{patchLog.patchNum},patch_status=1 where id=#{patchLog.reviewer}
    </update>
 
    <update id="updateReportingWorkDetail"  >
        update pp.reporting_work_detail set patch_status=1 where reporting_work_id=#{reportingWorkId}
                                          and order_number=#{orderSort} and technology_number=#{technologyNumber}
    </update>
 
 
    <select id="getSelectReplenish">
        select date(rw.reporting_work_time) as reportingWorkTime,
               o.order_id as orderId,
               dd.reporting_work_id as reportingWorkId,
               rw.production_id as productionId,
               rw.process_id as processId,
               o.project,
               o.batch,
               dd.id as reviewer,
               od.building_number as buildingNumber,
               dd.order_number as orderSort,
               od.product_name as productName,
               dd.technology_number as technologyNumber,
               ogd.glass_address as glassAddress,
               dd.breakage_quantity-dd.quantity as patchNum,
                ogd.child_width as width,
                ogd.child_height as height,
               od.shape,
               dd.responsible_process as responsibleProcess,
               rw.this_process as patchProcesses,
               dd.breakage_quantity-dd.quantity as breakageQuantity,
               dd.return_process as patchProcesses,
               dd.breakage_reason as patchReason,
               dd.breakage_type as patchType,
               dd.responsible_personnel as responsiblePersonnel,
               dd.responsible_equipment as responsibleEquipment,
               dd.responsible_team as responsibleTeam,
               ROUND((dd.breakage_quantity-dd.quantity) * od.width * od.height / 1000000, 2) as patchArea,
               rw.quality_inspector as qualityInspector,
               ogd.glass_child as glassChild,
               if(dd.responsible_process=rw.this_process,2,dd.quality_ins_status) as qualityInsStatus,
               if(dd.quality_ins_status=1,1,2) as orderBy,
               dd.responsible_personnel as responsiblePersonnel
        from pp.damage_details dd
                 left join    pp.reporting_work_detail rwd on dd.reporting_work_id = rwd.reporting_work_id and dd.order_number=rwd.order_number  and dd.technology_number=rwd.technology_number
                 left join pp.reporting_work rw on dd.reporting_work_id = rw.reporting_work_id
 
                 left join sd.`order` o on rw.order_id = o.order_id
                 left join sd.order_detail od on rw.order_id = od.order_id and dd.order_number = od.order_number
                 left join (select * from sd.order_glass_detail group by order_id,order_number,technology_number) as ogd
                           on rw.order_id = ogd.order_id and dd.order_number = ogd.order_number and rwd.technology_number=ogd.technology_number
 
        <where>  dd.breakage_quantity-dd.quantity>0 and dd.available=0 and rw.reviewed_state!=-1 /*(dd.responsible_process=rw.this_process or (dd.quality_ins_status!=1)) and */
                and o.create_order>0 and dd.patch_status=0
            <if test="patchLogAddDTO.orderId != null and patchLogAddDTO.orderId != ''">
                and o.order_id regexp #{patchLogAddDTO.orderId}
            </if>
            <if test="patchLogAddDTO.reportingWorkId != null and patchLogAddDTO.reportingWorkId != ''">
                and dd.reporting_work_id regexp #{patchLogAddDTO.reportingWorkId}
            </if>
            <if test="patchLogAddDTO.productionId != null and patchLogAddDTO.productionId != ''">
                and rw.production_id regexp #{patchLogAddDTO.productionId}
            </if>
            <if test="patchLogAddDTO.processId != null and patchLogAddDTO.processId != ''">
                and rw.process_id regexp #{patchLogAddDTO.processId}
            </if>
            <if test="patchLogAddDTO.project != null and patchLogAddDTO.project != ''">
                and o.project regexp #{patchLogAddDTO.project}
            </if>
            <if test="patchLogAddDTO.batch != null and patchLogAddDTO.batch != ''">
                and o.batch regexp #{patchLogAddDTO.batch}
            </if>
            <if test="patchLogAddDTO.orderSort != null and patchLogAddDTO.orderSort != ''">
                and dd.order_number regexp #{patchLogAddDTO.orderSort}
            </if>
            <if test="patchLogAddDTO.productName != null and patchLogAddDTO.productName != ''">
                and od.product_name regexp #{patchLogAddDTO.productName}
            </if>
            <if test="patchLogAddDTO.technologyNumber != null and patchLogAddDTO.technologyNumber != ''">
                and dd.technology_number regexp #{patchLogAddDTO.technologyNumber}
            </if>
            <if test="patchLogAddDTO.qualityInspector != null and patchLogAddDTO.qualityInspector != ''">
                and rw.quality_inspector regexp #{patchLogAddDTO.qualityInspector}
            </if>
            <if test="patchLogAddDTO.width != null and patchLogAddDTO.width != ''">
                and ogd.child_width regexp REGEXP_REPLACE(#{patchLogAddDTO.width},'\\.0+$','')
            </if>
            <if test="patchLogAddDTO.height != null and patchLogAddDTO.height != ''">
                and ogd.child_height regexp REGEXP_REPLACE(#{patchLogAddDTO.height},'\\.0+$','')
            </if>
            <if test="patchLogAddDTO.shape != null and patchLogAddDTO.shape != ''">
                and od.shape regexp #{patchLogAddDTO.shape}
            </if>
            <if test="patchLogAddDTO.glassAddress != null and patchLogAddDTO.glassAddress != ''">
                and ogd.glass_address regexp #{patchLogAddDTO.glassAddress}
            </if>
            <if test="patchLogAddDTO.glassChild != null and patchLogAddDTO.glassChild != ''">
                and ogd.glass_child regexp #{patchLogAddDTO.glassChild}
            </if>
            <if test="patchLogAddDTO.responsibleTeam != null and patchLogAddDTO.responsibleTeam != ''">
                and dd.responsible_team regexp #{patchLogAddDTO.responsibleTeam}
            </if>
            <if test="patchLogAddDTO.responsibleEquipment != null and patchLogAddDTO.responsibleEquipment != ''">
                and dd.responsible_equipment regexp #{patchLogAddDTO.responsibleEquipment}
            </if>
            <if test="patchLogAddDTO.responsibleProcess != null and patchLogAddDTO.responsibleProcess != ''">
                and dd.responsible_process regexp #{patchLogAddDTO.responsibleProcess}
            </if>
            <if test="patchLogAddDTO.patchProcesses != null and patchLogAddDTO.patchProcesses != ''">
                and rw.this_process regexp #{patchLogAddDTO.patchProcesses}
            </if>
            <if test="patchLogAddDTO.patchType != null and patchLogAddDTO.patchType != ''">
                and dd.breakage_type regexp #{patchLogAddDTO.patchType}
            </if>
            <if test="patchLogAddDTO.patchReason != null and patchLogAddDTO.patchReason != ''">
                and dd.breakage_reason regexp #{patchLogAddDTO.patchReason}
            </if>
        </where>
        order by orderBy desc,dd.id desc
    </select>
 
    <delete id="deleteReplenishMp">
        delete from pp.patch_log where id=#{id}
    </delete>
 
    <delete id="updatePatchDdMp">
        delete from pp.damage_details
     where reporting_work_id=#{reportingWorkId} and order_number=#{orderSort} and technology_number=#{technologyNumber}
        and breakage_reason=#{patchReason}
    </delete>
 
    <update id="updatePatchBgMp">
        update pp.reporting_work_detail set patch_status=0
        where reporting_work_id=#{reportingWorkId} and order_number=#{orderSort} and technology_number=#{technologyNumber}
    </update>
 
    <update id="updateOrderProcessDetailCancel">
        update sd.order_process_detail
        set reporting_work_num=reporting_work_num + #{patchLog.patchNum}
        where order_id = #{patchLog.orderId}
          and process_id = #{patchLog.processId}
          and order_number = #{patchLog.orderSort}
          and technology_number = #{patchLog.technologyNumber}
          and id <![CDATA[<]]> (select a.opdid
                                from (select id as opdid
                                      from sd.order_process_detail opd
                                      where opd.order_id = #{patchLog.orderId}
                                        and opd.process_id = #{patchLog.processId}
                                        and opd.order_number = #{patchLog.orderSort}
                                        and opd.technology_number = #{patchLog.technologyNumber}
                                        and process = #{reportingWork.thisProcess}) as a)
    </update>
 
    <update id="updateReplenishCancel">
        update pp.patch_log set reviewer=null,review_status=0,update_time=now() where id=#{patchLog.id}
    </update>
 
    <select id="selectProjectCount">
        SELECT COUNT(*)
        FROM patch_log
        WHERE process_id= #{processId} and patch_id=#{patchId} and technology_number = #{technologyNumber}
          and project_no IS not NULL;
    </select>
 
</mapper>