czt
2025-11-29 867f65fe7558c1fb1e2b11d23b625cc95dbe88d8
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
487
488
489
package com.fzzy.igds;
 
 
import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.annotation.Expose;
import com.bstek.dorado.data.provider.Page;
import com.fzzy.igds.constant.Constant;
import com.fzzy.igds.data.NoticeDto;
import com.fzzy.igds.service.InoutNoticeService;
import com.fzzy.igds.domain.InoutNoticeIn;
import com.fzzy.igds.domain.InoutNoticeOut;
import com.fzzy.igds.service.SysDeptService;
import com.fzzy.igds.utils.ContextUtil;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.*;
 
/**
 * @Description 通知单管理
 * @Author CZT
 * @Date 2024/12/16 10:10
 */
@Component
public class InoutNoticePR {
 
    @Resource
    private InoutNoticeService inoutNoticeService;
    @Resource
    private SysDeptService sysDeptService;
 
    /**
     * inoutNoticePR#getTitle 根据报表类型,获取默认查询信息,比如表头信息等
     *
     * @param
     * @return
     */
    @DataProvider
    public Map<String, Object> getTitle(Map<String, Object> param) {
        Map<String, Object> result = new HashMap<String, Object>();
        //获取参数中报表类型
        String type = (String)param.get("type");
 
        //获取分库编码对应的分库名称
        String deptName = "";
        SysDept subDept = sysDeptService.getCacheDept(null, ContextUtil.subDeptId(null));
        if (null != subDept) {
            deptName = subDept.getDeptName();
        }
        if ("NOTICE_IN".equals(type)) {
            result.put("title", "入库通知单");
            if (StringUtils.isNotEmpty(deptName)) {
                result.put("title", deptName + "入库通知单");
            }
        }
        if ("NOTICE_OUT".equals(type)) {
            result.put("title", "出库通知单");
            if (StringUtils.isNotEmpty(deptName)) {
                result.put("title", deptName + "出库通知单");
            }
        }
        return result;
    }
 
    /**
     * inoutNoticePR#getYearQuery 默认年份
     *
     * @param
     * @return
     */
    @DataProvider
    public Map<String, Object> getYearQuery(Map<String, Object> param) {
        Map<String, Object> result = new HashMap<String, Object>();
        //获取参数中分库编码
        String deptId = (String)param.get("deptId");
 
        result.put("year", DateFormatUtils.format(new Date(), "yyyy"));
        result.put("deptId", deptId);
        return result;
    }
 
    /**
     * inoutNoticePR#queryNoticeByKey  根据参数查询出入库通知单,用于手动补单时,选择通知单
     *
     * @param
     * @return
     */
    @DataProvider
    public List<NoticeDto> queryNoticeByKey(Map<String, Object> param) {
        if (param == null) {
            return null;
        }
        String type = (String) param.get("type");
        if (StringUtils.isEmpty(type)) {
            return null;
        }
        List<NoticeDto> list = new ArrayList<>();
        NoticeDto dto;
        if (Constant.TYPE_IN.equals(type)) {
            List<InoutNoticeIn> listIn = this.queryNoticeIn(param);
            if (null != listIn && listIn.size() > 0) {
                for (InoutNoticeIn inoutNoticeIn : listIn) {
                    dto = new NoticeDto();
                    BeanUtils.copyProperties(inoutNoticeIn, dto);
                    list.add(dto);
                }
            }
        }
        if (Constant.TYPE_OUT.equals(type)) {
            List<InoutNoticeOut> listOut = this.queryNoticeOut(param);
            if (null != listOut && listOut.size() > 0) {
                for (InoutNoticeOut inoutNoticeOut : listOut) {
                    dto = new NoticeDto();
                    BeanUtils.copyProperties(inoutNoticeOut, dto);
                    list.add(dto);
                }
            }
        }
        return list;
    }
 
 
    /*==================== 入库通知单相关业务 ====================*/
 
    /**
     * inoutNoticePR#initAddIn 入库通知单新增初始化
     *
     * @return
     */
    @Expose
    public InoutNoticeIn initAddIn() {
        SysUser user = ContextUtil.getLoginUser();
        InoutNoticeIn data = new InoutNoticeIn();
        data.setId("RKTZD_" + ContextUtil.generateId());
        data.setName("入库通知单");
        data.setCompanyId(user.getCompanyId());
        data.setDeptId(ContextUtil.subDeptId(user));
        data.setTag(Constant.YN_Y);
        return data;
    }
 
    /**
     * inoutNoticePR#pageQueryIn 获取入库通知单
     *
     * @param param
     * @return
     */
    @DataProvider
    public void pageQueryIn(Page<InoutNoticeIn> page, Map<String, Object> param) {
        if (null == param) {
            param = new HashMap<>();
        }
        Map<String, Object> finalParam = param;
 
        //多参数分页查询
        Pageable pageable = PageRequest.of(0, 10000, Sort.Direction.ASC, InoutNoticeIn.SORT_PROP);
        Specification<InoutNoticeIn> specification = new Specification<InoutNoticeIn>() {
            private static final long serialVersionUID = 1L;
 
            public Predicate toPredicate(Root<InoutNoticeIn> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                List<Predicate> predicates = new ArrayList<Predicate>(); //所有的断言
 
                Predicate predicate1 = cb.equal(root.get("companyId"), ContextUtil.getCompanyId());
                predicates.add(predicate1);
                Predicate predicate2 = cb.equal(root.get("deptId"), ContextUtil.subDeptId(null));
                predicates.add(predicate2);
 
                String key = String.valueOf(finalParam.get("year"));
                if (StringUtils.isBlank(key)) {
                    Predicate predicate3 = cb.equal(root.get("year"), key);
                    predicates.add(predicate3);
                }
                key = (String) finalParam.get("id");
                if (StringUtils.isBlank(key)) {
                    Predicate predicate4 = cb.equal(root.get("id"),  key);
                    predicates.add(predicate4);
                }
                key = (String) finalParam.get("customerName");
                if (StringUtils.isBlank(key)) {
                    Predicate predicate5 = cb.like(root.get("customerName"), "%" + key + "%");
                    predicates.add(predicate5);
                }
                key = (String) finalParam.get("completeStatus");
                if (StringUtils.isBlank(key)) {
                    Predicate predicate6 = cb.equal(root.get("completeStatus"), key);
                    predicates.add(predicate6);
                }
                key = (String) finalParam.get("foodVariety");
                if (StringUtils.isBlank(key)) {
                    Predicate predicate7 = cb.equal(root.get("foodVariety"), key);
                    predicates.add(predicate7);
                }
                return cb.and(predicates.toArray(new Predicate[0]));
            }
        };
        org.springframework.data.domain.Page<InoutNoticeIn> japPage = inoutNoticeService.queryAllNoticeIn(specification, pageable);
        page.setEntityCount((int) japPage.getTotalElements());
        page.setEntities(japPage.getContent());
    }
 
    /**
     * inoutNoticePR#saveIn 更新入库通知单
     */
    @Expose
    public String saveIn(InoutNoticeIn data) {
        InoutNoticeIn inoutNoticeIn = new InoutNoticeIn();
        BeanUtils.copyProperties(data, inoutNoticeIn);
        return inoutNoticeService.saveOrUpdateIn(inoutNoticeIn);
    }
 
    /**
     * inoutNoticePR#delDataIn
     */
    @Expose
    public String delDataIn(InoutNoticeIn data) {
        InoutNoticeIn inoutNoticeIn = new InoutNoticeIn();
        BeanUtils.copyProperties(data, inoutNoticeIn);
        return inoutNoticeService.delDataIn(inoutNoticeIn);
    }
 
    /**
     * 根据不同条件查询
     * @param param
     * @return
     */
    public List<InoutNoticeIn> queryNoticeIn(Map<String, Object> param) {
        if (null == param) {
            param = new HashMap<>();
        }
        Map<String, Object> finalParam = param;
 
        //多参数分页查询
        Pageable pageable = PageRequest.of(0, 10000, Sort.Direction.ASC, InoutNoticeIn.SORT_PROP);
        Specification<InoutNoticeIn> specification = new Specification<InoutNoticeIn>() {
            private static final long serialVersionUID = 1L;
 
            public Predicate toPredicate(Root<InoutNoticeIn> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                List<Predicate> predicates = new ArrayList<Predicate>(); //所有的断言
 
                Predicate predicate1 = cb.equal(root.get("companyId"), ContextUtil.getCompanyId());
                predicates.add(predicate1);
                Predicate predicate2 = cb.equal(root.get("deptId"), ContextUtil.subDeptId(null));
                predicates.add(predicate2);
                Predicate predicate3 = cb.equal(root.get("completeStatus"), "NONE");
                predicates.add(predicate3);
 
                String key = (String) finalParam.get("customerId");
                if (StringUtils.isNotEmpty(key)) {
                    Predicate predicate4 = cb.equal(root.get("customerId"), key);
                    predicates.add(predicate4);
                }
                key = (String) finalParam.get("foodVariety");
                if (StringUtils.isNotEmpty(key)) {
                    Predicate predicate5 = cb.equal(root.get("foodVariety"),  key);
                    predicates.add(predicate5);
                }
                key = (String) finalParam.get("depotId");
                if (StringUtils.isNotEmpty(key)) {
                    Predicate predicate6 = cb.equal(root.get("depotId"), key);
                    predicates.add(predicate6);
                }
                key = (String) finalParam.get("key");
                if (StringUtils.isNotEmpty(key)) {
                    Predicate predicate7 = cb.like(root.get("name"), "%" + key + "%");
                    predicates.add(predicate7);
                }
                return cb.and(predicates.toArray(new Predicate[0]));
            }
        };
        org.springframework.data.domain.Page<InoutNoticeIn> japPage = inoutNoticeService.queryAllNoticeIn(specification, pageable);
 
        return japPage.getContent();
    }
 
    /**
     * 重新核算入库通知单完成量
     *
     * inoutNoticePR#updateSumNoticeIn
     *
     * @return
     */
    @Expose
    public String updateSumNoticeIn() {
 
        //获取所有未完成状态的入库通知单
        String companyId = ContextUtil.getCompanyId();
        String deptId = ContextUtil.subDeptId(null);
 
        List<InoutNoticeIn> noticeInList = inoutNoticeService.getUnComNoticeIn(companyId);
 
        if (noticeInList != null && noticeInList.size() > 0) {
            inoutNoticeService.updateSumNoticeIn(noticeInList);
            return "success";
        }
        
        
        return "fail";
    }
 
    /*==================== 出库通知单相关业务 ====================*/
 
    /**
     * inoutNoticePR#initAddOut 出库通知单新增初始化
     *
     * @return
     */
    @Expose
    public InoutNoticeOut initAddOut() {
        SysUser user = ContextUtil.getLoginUser();
        InoutNoticeOut data = new InoutNoticeOut();
        data.setId("CKTZD_" + ContextUtil.generateId());
        data.setName("出库通知单");
        data.setCompanyId(user.getCompanyId());
        data.setDeptId(ContextUtil.subDeptId(user));
        data.setTag(Constant.YN_Y);
        return data;
    }
 
    /**
     * inoutNoticePR#pageQueryOut 获取出库通知单
     * @param page
     * @param param
     */
    @DataProvider
    public void pageQueryOut(Page<InoutNoticeOut> page, Map<String, Object> param) {
 
        if (null == param) {
            param = new HashMap<>();
        }
        Map<String, Object> finalParam = param;
 
        //多参数分页查询
        Pageable pageable = PageRequest.of(0, 10000, Sort.Direction.ASC, InoutNoticeOut.SORT_PROP);
        Specification<InoutNoticeOut> specification = new Specification<InoutNoticeOut>() {
            private static final long serialVersionUID = 1L;
 
            public Predicate toPredicate(Root<InoutNoticeOut> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                List<Predicate> predicates = new ArrayList<Predicate>(); //所有的断言
 
                Predicate predicate1 = cb.equal(root.get("companyId"), ContextUtil.getCompanyId());
                predicates.add(predicate1);
                Predicate predicate2 = cb.equal(root.get("deptId"), ContextUtil.subDeptId(null));
                predicates.add(predicate2);
 
                String key = String.valueOf(finalParam.get("year"));
                if (StringUtils.isNotEmpty(key)) {
                    Predicate predicate3 = cb.equal(root.get("year"), key);
                    predicates.add(predicate3);
                }
                key = (String) finalParam.get("id");
                if (StringUtils.isNotEmpty(key)) {
                    Predicate predicate4 = cb.equal(root.get("id"),  key);
                    predicates.add(predicate4);
                }
                key = (String) finalParam.get("customerId");
                if (StringUtils.isNotEmpty(key)) {
                    Predicate predicate5 = cb.equal(root.get("customerId"), key);
                    predicates.add(predicate5);
                }
                key = (String) finalParam.get("completeStatus");
                if (StringUtils.isNotEmpty(key)) {
                    Predicate predicate6 = cb.equal(root.get("completeStatus"), key);
                    predicates.add(predicate6);
                }
                key = (String) finalParam.get("foodVariety");
                if (StringUtils.isNotEmpty(key)) {
                    Predicate predicate7 = cb.equal(root.get("foodVariety"), key);
                    predicates.add(predicate7);
                }
                return cb.and(predicates.toArray(new Predicate[0]));
            }
        };
        org.springframework.data.domain.Page<InoutNoticeOut> japPage = inoutNoticeService.queryAllNoticeOut(specification, pageable);
        page.setEntityCount((int) japPage.getTotalElements());
        page.setEntities(japPage.getContent());
    }
 
    /**
     * inoutNoticePR#saveOut 更新出库通知单
     * @param data
     * @return
     */
    @Expose
    public String saveOut(InoutNoticeOut data) {
        InoutNoticeOut inoutNoticeOut = new InoutNoticeOut();
        BeanUtils.copyProperties(data, inoutNoticeOut);
        return inoutNoticeService.saveOrUpdateOut(inoutNoticeOut);
    }
 
    /**
     * inoutNoticePR#delDataOut
     */
    @Expose
    public String delDataOut(InoutNoticeOut data) {
        InoutNoticeOut inoutNoticeOut = new InoutNoticeOut();
        BeanUtils.copyProperties(data, inoutNoticeOut);
        return inoutNoticeService.delDataOut(inoutNoticeOut);
    }
 
    /**
     * 根据不同条件查询
     * @param param
     * @return
     */
    public List<InoutNoticeOut> queryNoticeOut(Map<String, Object> param) {
        if (null == param) {
            param = new HashMap<>();
        }
        Map<String, Object> finalParam = param;
 
        //多参数分页查询
        Pageable pageable = PageRequest.of(0, 10000, Sort.Direction.ASC, InoutNoticeOut.SORT_PROP);
        Specification<InoutNoticeOut> specification = new Specification<InoutNoticeOut>() {
            private static final long serialVersionUID = 1L;
 
            public Predicate toPredicate(Root<InoutNoticeOut> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                List<Predicate> predicates = new ArrayList<Predicate>(); //所有的断言
 
                Predicate predicate1 = cb.equal(root.get("companyId"), ContextUtil.getCompanyId());
                predicates.add(predicate1);
                Predicate predicate2 = cb.equal(root.get("deptId"), ContextUtil.subDeptId(null));
                predicates.add(predicate2);
                Predicate predicate3 = cb.equal(root.get("completeStatus"), "NONE");
                predicates.add(predicate3);
 
                String key = (String) finalParam.get("customerId");
                if (StringUtils.isNotEmpty(key)) {
                    Predicate predicate4 = cb.equal(root.get("customerId"), key);
                    predicates.add(predicate4);
                }
                key = (String) finalParam.get("foodVariety");
                if (StringUtils.isNotEmpty(key)) {
                    Predicate predicate5 = cb.equal(root.get("foodVariety"),  key);
                    predicates.add(predicate5);
                }
                key = (String) finalParam.get("depotId");
                if (StringUtils.isNotEmpty(key)) {
                    Predicate predicate6 = cb.equal(root.get("depotId"), key);
                    predicates.add(predicate6);
                }
                key = (String) finalParam.get("key");
                if (StringUtils.isNotEmpty(key)) {
                    Predicate predicate7 = cb.like(root.get("name"), "%" + key + "%");
                    predicates.add(predicate7);
                }
                return cb.and(predicates.toArray(new Predicate[0]));
            }
        };
        org.springframework.data.domain.Page<InoutNoticeOut> japPage = inoutNoticeService.queryAllNoticeOut(specification, pageable);
 
        return japPage.getContent();
    }
 
    /**
     * 重新核算出库通知单完成量
     *
     * inoutNoticePR#updateSumNoticeOut
     *
     * @return
     */
    @Expose
    public String updateSumNoticeOut() {
 
        //获取所有未完成状态的入库通知单
        String companyId = ContextUtil.getCompanyId();
        String deptId = ContextUtil.subDeptId(null);
 
        List<InoutNoticeOut> noticeOutList = inoutNoticeService.getUnComNoticeOut(companyId);
 
        if (noticeOutList != null && noticeOutList.size() > 0) {
            inoutNoticeService.updateSumNoticeOut(noticeOutList);
            return "success";
        }
        return "fail";
    }
 
}