czt
9 天以前 db67639449287bcec461916a7dca6003ee5dd03c
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
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
package com.fzzy.sys.manager.inout;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fzzy.igds.constant.Constant;
import com.fzzy.igds.constant.RespCodeEnum;
import com.fzzy.igds.data.*;
import com.fzzy.igds.domain.*;
import com.fzzy.igds.service.*;
import com.fzzy.igds.utils.ContextUtil;
import com.fzzy.igds.utils.SystemUtil;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.redis.RedisCache;
import lombok.extern.slf4j.Slf4j;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
 
/**
 * @Description 出入库业务处理
 * @Author CZT
 * @Date 2025/11/29 11:02
 */
@Slf4j
@Component
public class InoutManager {
 
    @Resource
    private RedisCache redisCache;
    @Resource
    private InoutConfService inoutConfService;
    @Resource
    private FileService fileService;
    @Resource
    private InoutRecordService inoutRecordService;
    @Resource
    private DicAreaService dicAreaService;
    @Resource
    private InoutNoticeService inoutNoticeService;
 
    /**
     * 根据用户请求信息,根据当前客户电脑IP,获取出入库称重上次选择的地磅
     *
     * @param httpRequest
     * @return
     */
    public String getInoutWeightByClient(HttpServletRequest httpRequest) {
        String userIp = SystemUtil.getIP(httpRequest);
        log.debug("----------------根据用户IP获取选择-地磅----{}", userIp);
 
        String key = "INOUT:WEIGHT:" + userIp;
        String sort = (String) redisCache.getCacheObject(key);
        if (com.ruoyi.common.utils.StringUtils.isEmpty(sort)) sort = "1";
        return sort;
    }
 
    /**
     * 获取出入库的整个流程信息
     *
     * @param companyId
     * @param deptId
     * @param inoutType
     * @return
     */
    public String getInoutProgressConf(String companyId, String deptId, String inoutType) {
        // 从缓存中获取出入库系统配置信息
        InoutSysConf inoutSysConf = inoutConfService.getCacheInoutSysConf(companyId, deptId);
        String progressConf = null;
        if (inoutSysConf != null) {
            if (Constant.TYPE_IN.equals(inoutType)) {
                progressConf = inoutSysConf.getProgressIn();
            }
            if (Constant.TYPE_OUT.equals(inoutType)) {
                progressConf = inoutSysConf.getProgressOut();
            }
        }
        return progressConf;
    }
 
    /**
     * 获取出入库设备配置信息
     *
     * @param companyId
     * @param deptId
     * @return
     */
    public List<InoutConf> getListInoutConf(String companyId, String deptId) {
        return inoutConfService.getCacheInoutConf(companyId, deptId);
    }
 
    /**
     * 根据配置获取出入库的配置参数
     *
     * @param listInoutConf 配置列表
     * @param sort          方案序号
     * @param type          设备类型
     * @param inoutProgress 出入库流程
     * @return 车牌设备配置,没有则返回NULL
     */
    public InoutConf getInoutConf(List<InoutConf> listInoutConf, String sort, String type, String inoutProgress, int inOrder) {
        if (null == listInoutConf) {
            return new InoutConf(sort);
        }
        if (StringUtils.isEmpty(sort)) sort = "1";
 
        InoutConf result = null;
        for (InoutConf conf : listInoutConf) {
            if (sort.equals(conf.getSort()) && type.equals(conf.getType()) && inoutProgress.equals(conf.getInoutProgress())) {
                if (conf.getInOrder() == inOrder) {
                    result = conf;
                    break;
                }
            }
        }
 
        if (null == result) return new InoutConf(sort);
 
        return result;
    }
 
    /**
     * 根据配置获取出入库的配置参数
     *
     * @param listInoutConf
     * @param type
     * @return
     */
    public List<InoutConf> getInoutConf(List<InoutConf> listInoutConf, String type) {
        List<InoutConf> result = new ArrayList<>();
        if (null == listInoutConf) return result;
        for (InoutConf conf : listInoutConf) {
            if (type.equals(conf.getType())) {
                result.add(conf);
            }
        }
        return result;
    }
 
    /**
     * 根据配置获取出入库的配置参数
     *
     * @param listInoutConf
     * @param sort
     * @param type
     * @return
     */
    public InoutConf getInoutConf(List<InoutConf> listInoutConf, String sort, String type) {
        if (null == listInoutConf) return new InoutConf(sort);
        if (StringUtils.isEmpty(sort)) sort = "1";
 
        for (InoutConf conf : listInoutConf) {
            if (sort.equals(conf.getSort()) && type.equals(conf.getType())) {
                return conf;
            }
        }
        return new InoutConf(sort);
    }
 
    /**
     * 获取地磅重量编辑标签
     *
     * @param companyId
     * @param deptId
     * @return
     */
    public String getWeightEditTag(String companyId, String deptId) {
        // 从缓存中获取出入库系统配置信息
        InoutSysConf inoutSysConf = inoutConfService.getCacheInoutSysConf(companyId, deptId);
        String weightEditTag = Constant.YN_N;
        if (inoutSysConf != null) {
            weightEditTag = inoutSysConf.getWeightEditTag();
        }
        if (null == weightEditTag) weightEditTag = Constant.YN_N;
 
        return weightEditTag;
    }
 
    /**
     * 出入库注册数据提交,出入库登记使用同一个方法,包含称重时直接登记
     *
     * @param data
     * @return
     */
    public PageResponse<InoutData> submitRegister(InoutData data) {
        if (StringUtils.isEmpty(data.getCompanyId())) {
            data.setCompanyId(ContextUtil.getCompanyId());
        }
        if (StringUtils.isEmpty(data.getDeptId())) {
            data.setDeptId(ContextUtil.subDeptId(null));
        }
 
        int num = inoutRecordService.checkExist(data.getCompanyId(), data.getPlateNum());
        if (num > 0) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), "当前车牌号正在执行流程未结束,请核查车牌或联系管理员", data);
        }
 
        // 获取系统参数配置
        InoutSysConf inoutSysConf = inoutConfService.getCacheInoutSysConf(data.getCompanyId(), data.getDeptId());
        if (null == inoutSysConf) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), "提示:当前库区未配置出入库流程信息,请联系管理员", data);
        }
 
        // 获取下一个流程状态
        String curProgress = data.getProgress();
        String nextProgress = getNextProgress(curProgress, data.getType(), inoutSysConf);
        data.setProgress(nextProgress);
 
        //去除身份证号中的空格
        if (StringUtils.isNotEmpty(data.getUserId())) {
            data.setUserId(data.getUserId().trim());
        }
        //去除姓名中的空格
        if (StringUtils.isNotEmpty(data.getUserName())) {
            data.setUserName(data.getUserName().trim());
        }
        //登记人及登记时间
        data.setRegisterUser(ContextUtil.getLoginUserName());
        data.setRegisterTime(new Date());
 
        num = inoutRecordService.addInoutRecord(data);
 
        if (num == 0) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), "登记失败!", data);
        }
 
        //附件处理
        fileService.saveInoutFiles(data.getFiles(), data.getId(), curProgress, "INOUT");
 
        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "登记成功!", data);
    }
 
    /**
     * 化验信息提交
     *
     * @param data
     * @return
     */
    public PageResponse<InoutData> submitCheck(InoutData data) {
        SysUser user = ContextUtil.getLoginUser();
        if (StringUtils.isEmpty(data.getCompanyId())) {
            data.setCompanyId(user.getCompanyId());
        }
        if (StringUtils.isEmpty(data.getDeptId())) {
            data.setDeptId(ContextUtil.subDeptId(user));
        }
 
        //化验人及时间
        data.setCheckUser(user.getUserName());
        data.setCheckTime(new Date());
        data.setCheckStatus(Constant.STATUS_CHECK);
 
        int num = inoutRecordService.updateInoutRecord(data);
 
        if (num == 0) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), "提交失败!", data);
        }
 
        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "提交成功!", data);
    }
 
    /**
     * 称重提交,包含称重登记提交及单独称重提交
     *
     * @param data
     * @return
     */
    public PageResponse<InoutData> submitWeight(InoutData data) {
        if (Constant.PROGRESS_WEIGHT_EMPTY.equals(data.getProgress())) {
            data.setEmptyWeightTime(new Date());
            data.setEmptyWeightUser(ContextUtil.getLoginUserName());
        }
        if (Constant.PROGRESS_WEIGHT_FULL.equals(data.getProgress())) {
            data.setFullWeightTime(new Date());
            data.setFullWeightUser(ContextUtil.getLoginUserName());
        }
        if (StringUtils.isBlank(data.getId())) {
            //表示称重时直接登记
            return submitRegister(data);
        }
 
        //获取系统参数配置
        InoutSysConf inoutSysConf = inoutConfService.getCacheInoutSysConf(data.getCompanyId(), data.getDeptId());
        if (null == inoutSysConf) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), "提示:当前系统中流程配置异常,请联系管理员", data);
        }
 
        // 获取下一个流程状态
        String curProgress = data.getProgress();
        String nextProgress = getNextProgress(curProgress, data.getType(), inoutSysConf);
        data.setProgress(nextProgress);
 
        if(Constant.PROGRESS_RECORD.equals(nextProgress)){
            //流程结束时,设置完成时间和完成人
            data.setCompleteTime(new Date());
            data.setCompleteUser(ContextUtil.getLoginUserName());
        }
        //称重数据更新
        int num = inoutRecordService.updateInoutRecord(data);
 
        if (num == 0) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), "提交失败!", data);
        }
 
        //附件处理
        fileService.saveInoutFiles(data.getFiles(), data.getId(), curProgress, "INOUT");
 
        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "执行成功", data);
    }
 
    /**
     * 值仓信息提交
     *
     * @param data
     * @return
     */
    public PageResponse<InoutData> submitHandle(InoutData data) {
 
        // 获取系统参数配置
        InoutSysConf inoutSysConf = inoutConfService.getCacheInoutSysConf(data.getCompanyId(), data.getDeptId());
        if (null == inoutSysConf) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), "提示:当前系统中流程配置异常,请联系管理员", data);
        }
 
        // 获取下一个流程状态
        String curProgress = data.getProgress();
        String nextProgress = getNextProgress(curProgress, data.getType(), inoutSysConf);
        data.setProgress(nextProgress);
 
        data.setHandleEnd(new Date());
        data.setHandleUser(ContextUtil.getLoginUserName());
        // 执行数据更新
        int num = inoutRecordService.updateInoutRecord(data);
 
        if (num == 0) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), "提交失败!", data);
        }
 
        //附件处理
        fileService.saveInoutFiles(data.getFiles(), data.getId(), curProgress, "INOUT");
 
        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "提交成功", data);
    }
 
    /**
     * 获取下一流程
     *
     * @param curProgress
     * @param type
     * @param sysConf
     * @return
     */
    private String getNextProgress(String curProgress, String type, InoutSysConf sysConf) {
        String nextProgress = null;
        List<String> list = null;
        if (Constant.TYPE_IN.equals(type)) {
            list = Arrays.asList(sysConf.getProgressIn().split("-"));
        }
        if (Constant.TYPE_OUT.equals(type)) {
            list = Arrays.asList(sysConf.getProgressOut().split("-"));
        }
        if (list != null) {
            for (int i = 0; i < list.size() - 1; i++) {
                if (curProgress.equals(list.get(i))) {
                    nextProgress = list.get(i + 1);
                    break;
                }
            }
        }
        return nextProgress;
    }
 
    /**
     * 分页查询数据
     *
     * @param param
     * @return
     */
    public PageResponse<Page<InoutRecord>> pageInoutData(InoutParam param) {
        if (StringUtils.isEmpty(param.getCompanyId())) {
            param.setCompanyId(ContextUtil.getCompanyId());
        }
        if (StringUtils.isEmpty(param.getDeptId())) {
            param.setDeptId(ContextUtil.subDeptId(null));
        }
 
        param.setProgressTag(Constant.PROGRESS_RECORD);
 
        Page<InoutRecord> corePage = new Page<>(param.getPage(), param.getLimit());
        inoutRecordService.listPageInout(corePage, param);
 
        if (null == corePage.getRecords() || corePage.getRecords().isEmpty()) {
            return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(), "获取到数据信息为空");
        }
 
        return new PageResponse<>(RespCodeEnum.CODE_0000, corePage);
    }
 
    /**
     * 查询待称重的数据
     *
     * @param param
     * @return
     */
    public PageResponse<List<InoutRecord>> listWeightData(InoutParam param) {
        if (StringUtils.isEmpty(param.getCompanyId())) {
            param.setCompanyId(ContextUtil.getCompanyId());
        }
        if (StringUtils.isEmpty(param.getDeptId())) {
            param.setDeptId(ContextUtil.subDeptId(null));
        }
 
        //设置称重流程标记
        param.setWeightTag("WEIGHT");
 
        List<InoutRecord> inoutRecords = inoutRecordService.listInout(param);
 
        if (null == inoutRecords || inoutRecords.isEmpty()) {
            return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(), "获取到数据信息为空");
        }
 
        return new PageResponse<>(RespCodeEnum.CODE_0000, inoutRecords);
    }
 
    /**
     * 查询待值仓的数据
     *
     * @param param
     * @return
     */
    public PageResponse<List<InoutRecord>> listHandleData(InoutParam param) {
        if (StringUtils.isEmpty(param.getCompanyId())) {
            param.setCompanyId(ContextUtil.getCompanyId());
        }
        if (StringUtils.isEmpty(param.getDeptId())) {
            param.setDeptId(ContextUtil.subDeptId(null));
        }
 
        List<InoutRecord> inoutRecords = inoutRecordService.listInout(param);
 
        if (null == inoutRecords || inoutRecords.isEmpty()) {
            return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(), "获取到数据信息为空");
        }
 
        return new PageResponse<>(RespCodeEnum.CODE_0000, inoutRecords);
    }
 
    /**
     * 查询数据
     *
     * @param param
     * @return
     */
    public PageResponse<InoutRecord> inoutQuery(InoutParam param) {
 
        if (StringUtils.isEmpty(param.getId()) && StringUtils.isEmpty(param.getPlateNum())) {
            return new PageResponse<>(RespCodeEnum.CODE_1007.getCode(), "查询参数不完整,查询失败!");
        }
        if (StringUtils.isEmpty(param.getCompanyId())) {
            param.setCompanyId(ContextUtil.getCompanyId());
        }
        if (StringUtils.isEmpty(param.getDeptId())) {
            param.setDeptId(ContextUtil.subDeptId(null));
        }
 
        if(Constant.PROGRESS_WEIGHT_EMPTY.equals(param.getProgress()) || Constant.PROGRESS_WEIGHT_FULL.equals(param.getProgress())){
            //设置查询待称重的
            param.setProgress(null);
            //设置称重流程标记
            param.setWeightTag("WEIGHT");
        }
 
        InoutRecord result = inoutRecordService.selectOne(param);
        if (null == result) {
            return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(),
                    "系统未查询到执行中的单据信息", null);
        }
        return new PageResponse<>(RespCodeEnum.CODE_0000, result);
    }
 
    /**
     * 分页获取区划信息
     *
     * @param param
     * @return
     */
    public PageResponse<Page<DicArea>> pageDicArea(IgdsBaseParam param) {
 
        Page<DicArea> corePage = new Page<>(param.getPage(), param.getLimit());
 
        dicAreaService.listPageData(corePage, param.getKey());
 
        if (null == corePage.getRecords() || corePage.getRecords().isEmpty()) {
            return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(), "获取到数据信息为空");
        }
        return new PageResponse<>(RespCodeEnum.CODE_0000, corePage);
    }
 
    /**
     * @param param
     * @return
     */
    public PageResponse<List<InoutNoticeIn>> listNoticeIn(NoticeParam param) {
 
        SysUser user = ContextUtil.getLoginUser();
        if (org.apache.commons.lang3.StringUtils.isEmpty(param.getCompanyId())) {
            param.setCompanyId(user.getCompanyId());
        }
        param.setDeptId(ContextUtil.subDeptId(user));
        param.setCompleteStatus(Constant.COMPLETE_STATUS_NONE);
        List<InoutNoticeIn> list = inoutNoticeService.getNoticeIn(param);
 
        if (null == list || list.isEmpty()) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), "查询结果为空!");
        }
 
        return new PageResponse<>(RespCodeEnum.CODE_0000, list);
    }
 
    /**
     * @param param
     * @return
     */
    public PageResponse<List<InoutNoticeOut>> listNoticeOut(NoticeParam param) {
        SysUser user = ContextUtil.getLoginUser();
        if (org.apache.commons.lang3.StringUtils.isEmpty(param.getCompanyId())) {
            param.setCompanyId(user.getCompanyId());
        }
        param.setDeptId(ContextUtil.subDeptId(user));
        param.setCompleteStatus(Constant.COMPLETE_STATUS_NONE);
        List<InoutNoticeOut> list = inoutNoticeService.getNoticeOut(param);
 
        if (null == list || list.isEmpty()) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), "查询结果为空!");
        }
 
        return new PageResponse<>(RespCodeEnum.CODE_0000, list);
    }
}