CZT
2023-11-27 c206acfaedc69c390fb67daa81bc686f58a212ef
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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
<?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.ld.igds.m.mapper.InoutCommonMapper">
 
 
    <!-- 根据组织编码查询出入库设备配置信息 -->
    <select id="listInoutConf" parameterType="java.lang.String" resultType="com.ld.igds.models.InoutConf">
        select
        ID_ as id,
        COMPANY_ID_ as companyId,
        DEPT_ID_ as deptId,
        SORT_ as sort,
        IN_ORDER_ as inOrder,
        INTOU_PROGRESS_ as inoutProgress,
        NAME_ as name,
        SN_ as sn,
        IP_ as ip,
        PORT_ as port,
        LOGIN_ID_ as loginId,
        PWD_ as pwd,
        CHAN_NUM_ as chanNum,
        PORT_CTRL_ as portCtrl,
        TYPE_ as type,
        STATUS_ as status,
        PROTOCOL_ as protocol,
        PLAY_TYPE_ as playType,
        SNAP_TYPE_ as snapType,
        MEDIA_ADDR_ as mediaAddr,
        REMARK_ as remark
        from
        D_INOUT_CONF
 
        <where>
            <if test="companyId != null ">AND COMPANY_ID_ = #{companyId}</if>
            <if test="deptId != null and deptId != ''">AND DEPT_ID_ = #{deptId}</if>
        </where>
 
    </select>
 
    <!-- 根据ip和端口更新出入库设备状态 -->
    <update id="updateInoutConfStatus">
        update D_INOUT_CONF
        set STATUS_ = #{status}
        where IP_ = #{ip}
          and PORT_ = #{port}
    </update>
 
    <!-- 根据参数获取往来单位 -->
    <select id="listCustomer" parameterType="com.ld.igds.inout.dto.InoutParam"
            resultType="com.ld.igds.models.InoutCustomer">
        select
        ID_ as id,
        COMPANY_ID_ as companyId,
        DEPT_ID_ as deptId,
        NAME_ as name,
        TYPE_ as type,
        CARD_ID_ as cardId,
        ADDRESS_ as address,
        CONTACT_USER_ as contactUser,
        PHONE_ as phone,
        BANK_ as bank,
        BANK_NUM_ as bankNum,
        FOOD_AREA_ as foodArea
        from
        D_INOUT_CUSTOMER
        <where>
            <if test="param.companyId != null and param.companyId != ''">AND COMPANY_ID_ = #{param.companyId}</if>
            <if test="param.deptId != null and param.deptId != ''">AND DEPT_ID_ = #{param.deptId}</if>
            <if test="param.type != null and param.type != ''">AND TYPE_ = #{param.type}</if>
            <if test="param.key != null and param.key !='' ">AND ( ID_ like #{param.key} OR NAME_ like #{param.key} )
            </if>
        </where>
        GROUP BY NAME_
        order by CONVERT(NAME_ USING GBK)
    </select>
 
    <!-- 从入库通知单中获取往来单位
    <select id="listCustomerByNoticeIn" parameterType="com.ld.igds.inout.dto.InoutParam"
            resultType="com.ld.igds.models.InoutCustomer">
        select
        CUSTOMER_ID_ as id,
        CUSTOMER_NAME_ as name,
        ID_ as noticeId
        from
        D_INOUT_NOTICE_IN
        <where>
            <if test="param.companyId != null and param.companyId !='' ">AND COMPANY_ID_ = #{param.companyId}</if>
            <if test="param.deptId != null and param.deptId != ''">AND DEPT_ID_ = #{param.deptId}</if>
            <if test="param.year != null and param.year !='' ">AND YEAR_ = #{param.year}</if>
            <if test="param.type != null and param.type !='' ">AND COMPLETE_STATUS_ = #{param.type}</if>
            <if test="param.key != null and param.key !='' ">AND ( CUSTOMER_ID_ like #{param.key} OR CUSTOMER_NAME_ like
                #{param.key} )
            </if>
        </where>
        GROUP BY CUSTOMER_NAME_
        order by CONVERT(CUSTOMER_NAME_ USING GBK)
    </select>
     -->
 
 
    <!-- 从出库通知单中获取客户列表
    <select id="listCustomerByNoticeOut" parameterType="com.ld.igds.inout.dto.InoutParam"
            resultType="com.ld.igds.models.InoutCustomer">
        select
        CUSTOMER_ID_ as id,
        CUSTOMER_NAME_ as name,
        ID_ as noticeId
        from
        D_INOUT_NOTICE_OUT
        <where>
            <if test="param.companyId != null and param.companyId !='' ">AND COMPANY_ID_ = #{param.companyId}</if>
            <if test="param.deptId != null and param.deptId != ''">AND DEPT_ID_ = #{param.deptId}</if>
            <if test="param.year != null and param.year !='' ">AND YEAR_ = #{param.year}</if>
            <if test="param.type != null and param.type !='' ">AND COMPLETE_STATUS_ = #{param.type}</if>
            <if test="param.key != null and param.key !='' ">AND ( CUSTOMER_ID_ like #{param.key} OR CUSTOMER_NAME_ like
                #{param.key} )
            </if>
        </where>
        GROUP BY CUSTOMER_NAME_
        order by CONVERT(CUSTOMER_NAME_ USING GBK)
    </select>
    -->
 
    <!--更新往来单位信息-->
    <update id="updateCustomer" parameterType="com.ld.igds.m.dto.NoticeInData">
        update D_INOUT_CUSTOMER
        <set>
            <if test="data.address != null and data.address != '' ">ADDRESS_ = #{data.address},</if>
            <if test="data.phone != null and data.phone != '' ">PHONE_ = #{data.phone},</if>
            <if test="data.cardId != null and data.cardId != '' ">CARD_ID_ = #{data.cardId},</if>
            <if test="data.bankNum != null and data.bankNum != '' ">BANK_NUM_ = #{data.bankNum}</if>
        </set>
        <where>
            <if test="data.customerId != null and data.customerId != '' ">AND ID_ = #{data.customerId}</if>
            <if test="data.customerName != null and data.customerName != '' ">AND NAME_ = #{data.customerName}</if>
        </where>
    </update>
 
    <!-- 获取编码最大的单位 -->
    <select id="getMaxCustomerId" parameterType="java.lang.String"
            resultType="java.lang.String">
        select ID_
        from D_INOUT_CUSTOMER
        where COMPANY_ID_ = #{companyId}
        order by ID_ DESC limit 1
    </select>
 
    <!-- 获取入库通知单信息 -->
    <select id="listNoticeIn" parameterType="com.ld.igds.m.dto.NoticeParam"
            resultType="com.ld.igds.models.InoutNoticeIn">
        select
        ID_ as id,
        COMPANY_ID_ as companyId,
        DEPT_ID_ as deptId,
        PLAN_ID_ as planId,
        CONTRACT_ID_ as contractId,
        CONTRACT_NAME_ as contractName,
        NAME_ as name,
        CUSTOMER_ID_ as customerId,
        CUSTOMER_NAME_ as customerName,
        UNIT_NAME_ as unitName,
        FOOD_VARIETY_ as foodVariety,
        YEAR_ as year,
        TARGET_NUMBER_ as targetNumber,
        COMPLETE_NUMBER_ as completeNumber,
        AUDIT_STATUS_ as auditStatus,
        AUDIT_USER_ as auditUser,
        COMPLETE_STATUS_ as completeStatus,
        CREATE_TIME_ as createTime,
        CREATE_USER_ as createUser,
        COMPLETE_TIME_ as completeTime,
        DEPOT_ID_ as depotId,
        REMARK_ as remark
        from
        D_INOUT_NOTICE_IN
        where
        COMPANY_ID_ = #{param.companyId}
        <if test="param.customerId != null and param.customerId != ''">
            and CUSTOMER_ID_ = #{param.customerId}
        </if>
        <if test="param.foodVariety != null and param.foodVariety != ''">
            and FOOD_VARIETY_ = #{param.foodVariety}
        </if>
        <if test="param.id != null and param.id != ''">
            and ID_ = #{param.id}
        </if>
        <if test="param.year != null and param.year != ''">
            and YEAR_ = #{param.year}
        </if>
        <if test="param.completeStatus != null and param.completeStatus != ''">
            and COMPLETE_STATUS_ = #{param.completeStatus}
        </if>
        order by CREATE_TIME_ DESC
    </select>
 
    <!-- 新增入库通知单 -->
    <insert id="addNoticeIn" parameterType="com.ld.igds.models.InoutNoticeIn">
        insert into D_INOUT_NOTICE_IN (ID_,
                                       COMPANY_ID_,
                                       DEPT_ID_,
                                       PLAN_ID_,
                                       CONTRACT_ID_,
                                       NAME_,
                                       CUSTOMER_ID_,
                                       CUSTOMER_NAME_,
                                       UNIT_NAME_,
                                       FOOD_VARIETY_,
                                       YEAR_,
                                       TARGET_NUMBER_,
                                       COMPLETE_NUMBER_,
                                       AUDIT_STATUS_,
                                       AUDIT_USER_,
                                       COMPLETE_STATUS_,
                                       CREATE_TIME_,
                                       CREATE_USER_,
                                       UPDATE_TIME_,
                                       REMARK_)
        values (#{param.id},
                #{param.companyId},
                #{param.deptId},
                #{param.planId},
                #{param.contractId},
                #{param.name},
                #{param.customerId},
                #{param.customerName},
                #{param.unitName},
                #{param.foodVariety},
                #{param.year},
                #{param.targetNumber},
                #{param.completeNumber},
                #{param.auditStatus},
                #{param.auditUser},
                #{param.completeStatus},
                #{param.createTime},
                #{param.createUser},
                #{param.updateTime},
                #{param.remark})
    </insert>
 
    <!--更新入库通知单-->
    <update id="updateNoticeIn" parameterType="com.ld.igds.m.dto.NoticeInData">
        update D_INOUT_NOTICE_IN
        <set>
            <if test="data.customerName != null and data.customerName != '' ">CUSTOMER_NAME_ = #{data.customerName},
            </if>
            <if test="data.targetNumber != null and data.targetNumber != '' ">TARGET_NUMBER_ = #{data.targetNumber},
            </if>
            <if test="data.completeNumber != null and data.completeNumber != '' ">COMPLETE_NUMBER_ =
                #{data.completeNumber},
            </if>
            <if test="data.companyId != null and data.companyId != '' ">COMPANY_ID_ = #{data.companyId},</if>
            <if test="data.updateTime != null">UPDATE_TIME_ = #{data.updateTime},</if>
        </set>
        <where>
            <if test="data.foodVariety != null and data.foodVariety != '' ">AND FOOD_VARIETY_ = #{data.foodVariety}</if>
            <if test="data.customerId != null and data.customerId != '' ">AND CUSTOMER_ID_ = #{data.customerId}</if>
            <if test="data.year != null and data.year != '' ">AND YEAR_ = #{data.year}</if>
        </where>
    </update>
 
    <!-- 获取所有未完成状态入库通知单 -->
    <select id="getUnComNoticeIn" resultType="com.ld.igds.models.InoutNoticeIn">
        select ID_            as id,
               COMPANY_ID_    as companyId,
               DEPT_ID_       as deptId,
               PLAN_ID_       as planId,
               CONTRACT_ID_   as contractId,
               NAME_          as name,
               CUSTOMER_ID_   as customerId,
               CUSTOMER_NAME_ as customerName,
               UNIT_NAME_     as unitName,
               FOOD_VARIETY_  as foodVariety,
               YEAR_ as year,
        TARGET_NUMBER_ as targetNumber,
        COMPLETE_NUMBER_ as completeNumber,
        AUDIT_STATUS_ as auditStatus,
        AUDIT_USER_ as auditUser,
        COMPLETE_STATUS_ as completeStatus,
        CREATE_TIME_ as createTime,
        CREATE_USER_ as createUser,
        COMPLETE_TIME_ as completeTime,
        REMARK_ as remark
        from
            D_INOUT_NOTICE_IN
        where
            COMPLETE_STATUS_ = 'NONE'
          and COMPANY_ID_ = #{companyId}
    </select>
 
    <!-- 重新计算入库通知单完成量 -->
    <update id="reSumNoticeInComplete" parameterType="com.ld.igds.m.dto.NoticeParam">
        update D_INOUT_NOTICE_IN t,(
            SELECT
            r.FOOD_VARIETY_,
            r.NOTICE_ID_,
            sum(r.RECORD_WEIGHT_) as COMPLETE_NUMBER_
            from d_inout_record r
            where r.COMPANY_ID_ = #{param.companyId}
            and r.DEPT_ID_ = #{param.deptId}
            and r.FOOD_VARIETY_ = #{param.foodVariety}
            and r.NOTICE_ID_ = #{param.id}
            and r.RECORD_STATUS_ != 'DEL'
            and r.RECORD_STATUS_ != 'ERROR'
            GROUP BY r.FOOD_VARIETY_
            ) b
        SET t.COMPLETE_NUMBER_ = b.COMPLETE_NUMBER_
        WHERE
          t.FOOD_VARIETY_ = b.FOOD_VARIETY_
          AND t.ID_ = b.NOTICE_ID_
    </update>
 
    <!-- 根据参数查询出库通知单 -->
    <select id="queryNoticeOut" resultType="int" parameterType="com.ld.igds.m.dto.NoticeParam">
        select COUNT(*)
        from D_INOUT_NOTICE_OUT
        <where>
            COMPANY_ID_ = #{param.companyId}
            AND DEPT_ID_ = #{param.deptId}
            <if test="param.customerId != null and param.customerId != ''">
                AND CUSTOMER_ID_ = #{param.customerId}
            </if>
            <if test="param.depotId != null and param.depotId != ''">
                AND DEPOT_ID_ = #{param.depotId}
            </if>
            <if test="param.year != null and param.year != ''">
                AND YEAR_ = #{param.year}
            </if>
            <if test="param.foodVariety != null and param.foodVariety != ''">
                AND FOOD_VARIETY_ = #{param.foodVariety}
            </if>
            <if test="param.completeStatus != null and param.completeStatus != ''">
                AND COMPLETE_STATUS_ = #{param.completeStatus}
            </if>
            <if test="param.contractId != null and param.contractId != ''">
                AND CONTRACT_ID_ = #{param.contractId}
            </if>
            <if test="param.planId != null and param.planId != ''">
                AND PLAN_ID_ = #{param.planId}
            </if>
        </where>
    </select>
 
 
    <!-- 根据参数查询ru库通知单 -->
    <select id="queryNoticeIn" resultType="int" parameterType="com.ld.igds.m.dto.NoticeParam">
        select COUNT(*)
        from D_INOUT_NOTICE_IN
        <where>
            COMPANY_ID_ = #{param.companyId}
            AND DEPT_ID_ = #{param.deptId}
            <if test="param.customerId != null and param.customerId != ''">
                AND CUSTOMER_ID_ = #{param.customerId}
            </if>
            <if test="param.year != null and param.year != ''">
                AND YEAR_ = #{param.year}
            </if>
            <if test="param.foodVariety != null and param.foodVariety != ''">
                AND FOOD_VARIETY_ = #{param.foodVariety}
            </if>
            <if test="param.completeStatus != null and param.completeStatus != ''">
                AND COMPLETE_STATUS_ = #{param.completeStatus}
            </if>
            <if test="param.contractId != null and param.contractId != ''">
                AND CONTRACT_ID_ = #{param.contractId}
            </if>
            <if test="param.planId != null and param.planId != ''">
                AND PLAN_ID_ = #{param.planId}
            </if>
        </where>
    </select>
 
    <!-- 获取出库通知单 -->
    <select id="listNoticeOut" parameterType="com.ld.igds.m.dto.NoticeParam"
            resultType="com.ld.igds.models.InoutNoticeOut">
        select
        ID_ as id,
        COMPANY_ID_ as companyId,
        DEPT_ID_ as deptId,
        PLAN_ID_ as planId,
        CONTRACT_ID_ as contractId,
        CONTRACT_NAME_ as contractName,
        NAME_ as name,
        DEPOT_ID_ as depotId,
        CUSTOMER_ID_ as customerId,
        CUSTOMER_NAME_ as customerName,
        UNIT_NAME_ as unitName,
        FOOD_VARIETY_ as foodVariety,
        FOOD_TYPE_ as foodType,
        FOOD_LEVEL_ as foodLevel,
        YEAR_ as year,
        STORAGE_REAL_ as storageReal,
        TARGET_NUMBER_ as targetNumber,
        COMPLETE_NUMBER_ as completeNumber,
        AUDIT_STATUS_ as auditStatus,
        AUDIT_USER_ as auditUser,
        COMPLETE_STATUS_ as completeStatus,
        CREATE_TIME_ as createTime,
        CREATE_USER_ as createUser,
        COMPLETE_TIME_ as completeTime,
        REMARK_ as remark
        from
        D_INOUT_NOTICE_OUT
        where
        COMPANY_ID_ = #{param.companyId}
        <if test="param.customerId != null and param.customerId != ''">
            and CUSTOMER_ID_ = #{param.customerId}
        </if>
        <if test="param.deptId != null and param.deptId != ''">
            and DEPT_ID_ = #{param.deptId}
        </if>
        <if test="param.id != null and param.id != ''">
            AND ID_ = #{param.id}
        </if>
        <if test="param.depotId != null and param.depotId != ''">
            and DEPOT_ID_ = #{param.depotId}
        </if>
        <if test="param.year != null and param.year != ''">
            and YEAR_ = #{param.year}
        </if>
        <if test="param.completeStatus != null and param.completeStatus != ''">
            and COMPLETE_STATUS_ = #{param.completeStatus}
        </if>
 
        order by CREATE_TIME_ DESC
    </select>
 
    <!-- 获取所有未完成状态出库通知单 -->
    <select id="getUnComNoticeOut" resultType="com.ld.igds.models.InoutNoticeOut">
        select ID_            as id,
               COMPANY_ID_    as companyId,
               DEPT_ID_       as deptId,
               PLAN_ID_       as planId,
               CONTRACT_ID_   as contractId,
               NAME_          as name,
               DEPOT_ID_      as depotId,
               CUSTOMER_ID_   as customerId,
               CUSTOMER_NAME_ as customerName,
               UNIT_NAME_     as unitName,
               FOOD_VARIETY_  as foodVariety,
               FOOD_TYPE_     as foodType,
               FOOD_LEVEL_    as foodLevel,
               YEAR_ as year,
        STORAGE_REAL_ as storageReal,
        TARGET_NUMBER_ as targetNumber,
        COMPLETE_NUMBER_ as completeNumber,
        AUDIT_STATUS_ as auditStatus,
        AUDIT_USER_ as auditUser,
        COMPLETE_STATUS_ as completeStatus,
        CREATE_TIME_ as createTime,
        CREATE_USER_ as createUser,
        COMPLETE_TIME_ as completeTime,
        REMARK_ as remark
        from
            D_INOUT_NOTICE_OUT
        where
            COMPLETE_STATUS_ = 'NONE'
          and COMPANY_ID_ = #{companyId}
    </select>
 
    <!-- 重新计算出库通知单完成量,只根据客户更新 -->
    <update id="reSumNoticeOutComplete" parameterType="com.ld.igds.m.dto.NoticeParam">
        update D_INOUT_NOTICE_OUT t,(
            SELECT
            r.FOOD_VARIETY_,
            r.DEPOT_ID_,
            r.NOTICE_ID_,
            sum(r.RECORD_WEIGHT_) as COMPLETE_NUMBER_
            from d_inout_record r
            where r.COMPANY_ID_ = #{param.companyId}
            AND r.DEPT_ID_ = #{param.deptId}
            and r.DEPOT_ID_ = #{param.depotId}
            and r.FOOD_VARIETY_ = #{param.foodVariety}
            and r.RECORD_STATUS_ != 'DEL'
            and r.RECORD_STATUS_ != 'ERROR'
            GROUP BY r.DEPOT_ID_
            ) b
        SET t.COMPLETE_NUMBER_ = b.COMPLETE_NUMBER_
        WHERE  t.FOOD_VARIETY_ = b.FOOD_VARIETY_
          AND t.DEPOT_ID_ = b.DEPOT_ID_
          AND t.ID_ = b.NOTICE_ID_
    </update>
 
</mapper>