czt
2025-06-12 930d29f39d115fe76c305af4320c2acbcb30c445
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
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
package com.ld.igds.inout.service.impl;
 
import com.bstek.dorado.data.entity.EntityUtils;
import com.ld.igds.constant.Constant;
import com.ld.igds.constant.RedisConst;
import com.ld.igds.data.CommonData;
import com.ld.igds.data.Page;
import com.ld.igds.inout.InoutConstant;
import com.ld.igds.inout.dto.InoutCheckData;
import com.ld.igds.inout.dto.InoutCheckParam;
import com.ld.igds.inout.dto.InoutData;
import com.ld.igds.inout.dto.InoutParam;
import com.ld.igds.inout.mapper.InoutCheckMapper;
import com.ld.igds.inout.mapper.InoutRecordMapper;
import com.ld.igds.inout.service.InoutService;
import com.ld.igds.models.InoutLossOver;
import com.ld.igds.models.InoutPrice;
import com.ld.igds.util.ContextUtil;
import com.ld.igds.util.DateUtil;
import com.ld.igds.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.*;
 
@Slf4j
@Component
public class InoutServiceImpl implements InoutService {
 
    @Resource
    private InoutRecordMapper inoutMapper;
    @Resource
    private InoutCheckMapper inoutCheckMapper;
    @Resource
    private RedisUtil redisUtil;
 
    @Override
    public InoutData inoutProgressQuery(InoutParam param) throws Exception {
        if (StringUtils.isEmpty(param.getCompanyId())) {
            param.setCompanyId(ContextUtil.getCompanyId());
        }
 
        // 首先从缓存中获取,如果没有则从数据库获取
        InoutData result = this.getFromInoutCache(param);
        if (null != result) {
            return result;
        }
        List<InoutData> list = inoutMapper.inoutProgressQuery(param);
        if (null == list || list.size() == 0)
            return null;
        if (list.size() == 1) {
            return list.get(0);
        } else {
            throw new Exception("当前条件下存在多个满足条件的数据,请核查!!");
        }
    }
 
    @Override
    public InoutData inoutQueryById(InoutParam param) {
        if (StringUtils.isEmpty(param.getCompanyId())) {
            param.setCompanyId(ContextUtil.getCompanyId());
        }
        if (null == param.getId())
            return null;
 
        // 首先从缓存中获取,如果没有则从数据库获取
        InoutData result = this.getFromInoutCache(param);
 
        if (null != result) {
            return result;
        }
 
        result = inoutMapper.inoutQueryById(param);
 
        return result;
    }
 
    @Override
    public String deleteData(InoutParam param) throws Exception {
        if (StringUtils.isEmpty(param.getCompanyId())) {
            param.setCompanyId(ContextUtil.getCompanyId());
        }
        if (StringUtils.isEmpty(param.getId())) {
            return "没有获取到被删除数据的ID,无法删除!";
        }
 
        inoutMapper.deleteData(param);
 
        delFromCache(param.getDeptId(), param.getType(), param.getId());
 
        return null;
    }
 
    @Override
    public String inoutStop(InoutParam param) throws Exception {
        if (StringUtils.isEmpty(param.getCompanyId())) {
            param.setCompanyId(ContextUtil.getDefaultCompanyId());
        }
 
 
        param.setProgress(InoutConstant.PROGRESS_RECORD);
        param.setRecordStatus(InoutConstant.RECORD_STATUS_DEL);
 
 
        // 缓存中删除
        delFromCache(param.getDeptId(), param.getType(), param.getId());
 
        inoutMapper.inoutStop(param);
 
        return null;
    }
 
    @Override
    public String insertData(InoutData data) {
        try {
            data.setUpdateTime(new Date());
 
            if (null == data.getDeptId()) {
                data.setDeptId(ContextUtil.subDeptId(null));
            }
 
            String id = this.createId(data.getRegisterTime(), data.getCompanyId());
            if (StringUtils.isEmpty(data.getId())) {
                if (InoutConstant.TYPE_IN.equals(data.getType())) {
                    data.setId("R_" + id);
                } else if (InoutConstant.TYPE_OUT.equals(data.getType())) {
                    data.setId("C_" + id);
                } else if (Constant.LOSS_OVER_OVER.equals(data.getType())) {
                    data.setId("R_" + id);
                } else if (Constant.LOSS_OVER_LOSS.equals(data.getType())) {
                    data.setId("C_" + id);
                } else {
                    data.setId("M_" + id);
                }
            }
            if (StringUtils.isEmpty(data.getCheckId())) {
                data.setCheckId(id);
            }
 
            if (null == data.getUserName()) {
                data.setUserName("");
            }
 
            InoutData newData;
            if (EntityUtils.isEntity(data)) {
                newData = new InoutData();
                BeanUtils.copyProperties(data, newData, new String[]{"checkItems", "files"});
            } else {
                newData = data;
            }
 
            inoutMapper.insertData(newData);
 
 
            updateInoutCache(newData);
 
        } catch (Exception e) {
            log.error("------------出入库执行保存出错---{}", e);
            return "后台异常:" + e.getMessage();
        }
 
        return null;
    }
 
 
    @Override
    public String updateData(InoutData data) throws Exception {
 
        data.setUpdateTime(new Date());
        if (StringUtils.isEmpty(data.getCompanyId())) {
            data.setCompanyId(ContextUtil.getCompanyId());
        }
        InoutData newData;
        if (EntityUtils.isEntity(data)) {
            newData = new InoutData();
            BeanUtils.copyProperties(data, newData, new String[]{"checkItems", "files"});
        } else {
            newData = data;
        }
 
        inoutMapper.updateData(newData);
 
        //更新缓存
        updateInoutCache(newData);
 
        return null;
    }
 
    @Override
    public String updateDataByHandle(InoutData data) {
        data.setUpdateTime(new Date());
 
        if (StringUtils.isEmpty(data.getCompanyId())) {
            data.setCompanyId(ContextUtil.getCompanyId());
        }
        InoutData newData;
        if (EntityUtils.isEntity(data)) {
            newData = new InoutData();
            BeanUtils.copyProperties(data, newData, new String[]{"checkItems", "files"});
        } else {
            newData = data;
        }
 
        inoutMapper.updateDataByHandle(newData);
        InoutParam param = new InoutParam();
        param.setId(newData.getId());
 
        //更新缓存
        updateInoutCache(inoutMapper.inoutQueryById(param));
 
        return null;
    }
 
    @Override
    public Page<InoutData> pageRecordData(InoutParam param) {
 
        if (StringUtils.isEmpty(param.getCompanyId())) {
            param.setCompanyId(ContextUtil.getCompanyId());
        }
        Page<InoutData> page = new Page<>(param.getPage(), param.getLimit());
        page.setSearchCount(true);
 
        if (null != param.getStart()) {
            param.setStart(DateUtil.getCurZero(param.getStart()));
        }
 
        if (null != param.getEnd()) {
            param.setEnd(DateUtil.getNextZero(param.getEnd()));
        }
 
        // 设置车牌的模糊查询条件
        if (null != param.getPlateNum()) {
            param.setPlateNum("%" + param.getPlateNum() + "%");
        }
 
        // 设置身份证号的模糊查询条件
        if (null != param.getUserId()) {
            param.setUserId("%" + param.getUserId() + "%");
        }
 
        if (null != param.getRecordStatus() && InoutConstant.RECORD_STATUS_NORMAL.equals(param.getRecordStatus())) {
            param.setRecordStatus(null);
        }
 
        List<InoutData> records = inoutMapper.pageRecordData(page, param);
        //判断入库重量是否为空,为空则赋值结算重量
        if (records != null) {
            for (InoutData record : records) {
                if (record.getRecordWeight() == null || record.getRecordWeight() == 0.0) {
                    record.setRecordWeight(record.getSettleWeight());
                }
            }
        }
        page.setRecords(records);
 
        return page;
    }
 
    @Override
    public List<InoutData> listRecordData(InoutParam param) {
        if (StringUtils.isEmpty(param.getCompanyId())) {
            param.setCompanyId(ContextUtil.getCompanyId());
        }
        List<InoutData> records = inoutMapper.listRecordData(param);
 
        return records;
    }
 
    @Override
    public String validate(String intelCard, String plateNum) {
        InoutParam param = new InoutParam();
        param.setCompanyId(ContextUtil.getCompanyId());
        param.setIntelCard(intelCard);
        param.setPlateNum(plateNum);
 
        int i = inoutMapper.validateInoutData(param);
 
        if (i > 0) {
            return "当前卡或者车辆出入库未完成!";
        }
        return null;
    }
 
    @Override
    public String toComplete(InoutParam param) throws Exception {
 
        param.setUpdateTime(new Date());
 
        if (null == param.getCompanyId()) {
            param.setCompanyId(ContextUtil.getDefaultCompanyId());
        }
 
        // 清除缓存
//        this.delFromCache(param.getDeptId(), param.getType(), param.getId());
 
 
        inoutMapper.toComplete(param);
 
        return null;
    }
 
    @Override
    public String quickComplete(InoutData data) throws Exception {
        if (null == data.getCompanyId()) {
            data.setCompanyId(ContextUtil.getDefaultCompanyId());
        }
        if (null == data.getCompleteTime()) {
            data.setCompleteTime(new Date());
        }
        if (null == data.getCompleteTime()) {
            data.setCompleteTime(new Date());
        }
        if (null == data.getEmptyWeightTime()) {
            data.setEmptyWeightTime(new Date());
        }
        if (null == data.getFullWeightTime()) {
            data.setFullWeightTime(new Date());
        }
 
        //调整时间差
        if (InoutConstant.TYPE_IN.equals(data.getType())) {
 
            if (data.getFullWeightTime().after(data.getEmptyWeightTime()))
                data.setFullWeightTime(DateUtil.getNewByMinute(data.getEmptyWeightTime(), -50));
 
            if (data.getCompleteTime().before(data.getEmptyWeightTime()))
                data.setCompleteTime(DateUtil.getNewByMinute(data.getEmptyWeightTime(), 5));
        }
 
        //调整时间差
        if (InoutConstant.TYPE_OUT.equals(data.getType())) {
 
            if (data.getEmptyWeightTime().after(data.getFullWeightTime()))
                data.setEmptyWeightTime(DateUtil.getNewByMinute(data.getFullWeightTime(), -50));
 
            if (data.getCompleteTime().before(data.getFullWeightTime()))
                data.setCompleteTime(DateUtil.getNewByMinute(data.getFullWeightTime(), 10));
        }
 
 
        if (InoutConstant.STATUS_NONE.equals(data.getCheckStatus())) {
            data.setCheckStatus(InoutConstant.STATUS_PASS);
        }
        // 设置流程结束
        data.setProgress(InoutConstant.PROGRESS_RECORD);
 
        //执行更新
        inoutMapper.updateData(data);
 
        //更新缓存
        updateInoutCache(data);
 
        return null;
    }
 
    @Override
    public void updateInoutCache(InoutData data) {
 
        data.setFiles(null);
        data.setCheckItems(null);
 
        if (InoutConstant.PROGRESS_RECORD.equals(data.getProgress())) {
 
            delFromCache(data.getDeptId(), data.getType(), data.getId());
 
            setCompleteInoutCache(data.getDeptId(), data);
 
        } else {
            setInoutCache(data.getDeptId(), data);
        }
    }
 
 
    public void delFromCache(String deptId, String type, String id) {
        if (StringUtils.isEmpty(deptId)) {
            return;
        }
        if (StringUtils.isEmpty(type)) {
            return;
        }
        if (StringUtils.isEmpty(id)) {
            return;
        }
        //从未完成列表中删除
        String key = this.buildInoutKey(deptId, InoutConstant.KEY_INOUT_LIST, type, id);
        redisUtil.del(key);
    }
 
    @Override
    public List<InoutData> getListInoutCache(String deptId) {
 
        String pattern = RedisConst.buildKey(deptId, InoutConstant.KEY_INOUT_LIST);
        Set<String> keys = redisUtil.keys(pattern);
        if (null == keys || keys.isEmpty()) {
            return null;
        }
        List<InoutData> list = new ArrayList<>();
        for (String key : keys) {
            list.add((InoutData) redisUtil.get(key));
        }
        return list;
    }
 
    @Override
    public List<InoutData> getCompleteListInoutCache(String deptId) {
        String pattern = RedisConst.buildKey(deptId, InoutConstant.KEY_INOUT_COMPLETE_LIST);
        Set<String> keys = redisUtil.keys(pattern);
 
        if (null == keys || keys.isEmpty()) {
            return null;
        }
        List<InoutData> list = new ArrayList<>();
        for (String key : keys) {
            list.add((InoutData) redisUtil.get(key));
        }
        return list;
    }
 
    @Override
    public InoutData getFromInoutCache(InoutParam param) {
        if (StringUtils.isEmpty(param.getDeptId())) {
            param.setDeptId(ContextUtil.subDeptId(null));
        }
 
        List<InoutData> list = getListInoutCache(param.getDeptId());
        if (null == list || list.isEmpty())
            return null;
 
        String intelCard = param.getIntelCard(), plateNum = param.getPlateNum(),
                id = param.getId(), userId = param.getUserId();
 
        for (InoutData data : list) {
 
            if (StringUtils.isNotEmpty(id) && data.getId().equals(id)) {
                return data;
            }
            if (StringUtils.isNotEmpty(intelCard) && data.getIntelCard().equals(intelCard)) {
                return data;
            }
            if (StringUtils.isNotEmpty(plateNum) && data.getPlateNum().equals(plateNum)) {
                return data;
            }
            if (StringUtils.isNotEmpty(userId) && data.getUserId().equals(userId)) {
                return data;
            }
        }
        return null;
    }
 
    @Override
    public Page<InoutData> pageUnCompleteData(InoutParam param) {
 
        if (StringUtils.isEmpty(param.getCompanyId())) {
            param.setCompanyId(ContextUtil.getCompanyId());
        }
        Page<InoutData> page = new Page<InoutData>(param.getPage(), param.getLimit());
        page.setSearchCount(true);
 
        if (null != param.getStart()) {
            param.setStart(DateUtil.getCurZero(param.getStart()));
        }
 
        if (null != param.getEnd()) {
            param.setEnd(DateUtil.getNextZero(param.getEnd()));
        }
        // 设置单据号模糊查询
        if (null != param.getId()) {
            param.setId("%" + param.getId() + "%");
        }
 
        // 设置往来单位名称的模糊查询条件
        if (StringUtils.isNotEmpty(param.getCustomerName())) {
            param.setCustomerName("%" + param.getCustomerName() + "%");
        }
 
        List<InoutData> records = inoutMapper.pageUnCompleteData(page, param);
        page.setRecords(records);
 
        return page;
    }
 
    @Override
    public InoutData getLastRecord(InoutParam param) {
        return inoutMapper.getLastRecord(param);
    }
 
    @Override
    public String addInoutDataByLossOver(InoutData data) {
 
        // 获取上一车的流水数据
        //    InoutData inoutData = this.getLastRecord(data.getCompanyId(), data.getDepotId());
 
//        // 设置流水的库存
//        if (InoutConstant.TYPE_IN.equals(inoutData.getType())) {
//            data.setCurStorage(inoutData.getCurStorage()
//                    + inoutData.getSettleWeight());
//        } else if (InoutConstant.TYPE_OUT.equals(inoutData.getType())) {
//            data.setCurStorage(inoutData.getCurStorage()
//                    - inoutData.getSettleWeight());
//        }
 
        // 添加补单数据
        this.insertData(data);
 
        return data.getId();
    }
 
    @Override
    public void delInoutDataByLossOver(InoutParam param) {
        inoutMapper.deleteData(param);
    }
 
    /**
     * 出入库流程ID创建 202001030001 202001030001
     *
     * @param registerTime 登记时间,和组织编码
     * @return
     */
    @Override
    public String createId(Date registerTime, String companyId) {
 
        // 时间戳标签
        String timeKey = DateFormatUtils.format(registerTime, "yyyyMMdd");
 
        // 从缓存中获取已有的组织编码
        String cacheKey = RedisConst.buildKey(companyId,
                InoutConstant.CACHE_RECORD_ID);
 
        String cacheId = (String) redisUtil.get(cacheKey);
 
        if (null != cacheId && cacheId.indexOf(timeKey) >= 0) {
            String temp = cacheId.substring(cacheId.length() - 4);
            Integer i = Integer.valueOf(temp);
            i++;
            temp = String.valueOf(i);
            if (temp.length() == 1) {
                cacheId = timeKey + "000" + temp;
            }
            if (temp.length() == 2) {
                cacheId = timeKey + "00" + temp;
            }
            if (temp.length() == 3) {
                cacheId = timeKey + "0" + temp;
            }
            if (temp.length() == 4) {
                cacheId = timeKey + temp;
            }
        } else {
            Map<String, Object> result = inoutMapper.getMaxId("%_" + timeKey
                    + "%", companyId);
 
            if (null == result) {
                cacheId = timeKey + "0001";
            } else {
                String temp = (String) result.get("maxId");
                // 获取最后四位
                int i = Integer.valueOf(temp.substring(temp.length() - 4));
                i++;
                temp = String.valueOf(i);
                if (temp.length() == 1) {
                    cacheId = timeKey + "000" + temp;
                }
                if (temp.length() == 2) {
                    cacheId = timeKey + "00" + temp;
                }
                if (temp.length() == 3) {
                    cacheId = timeKey + "0" + temp;
                }
                if (temp.length() == 4) {
                    cacheId = timeKey + temp;
                }
            }
        }
 
        // 更新缓存
        redisUtil.set(cacheKey, cacheId);
 
        return cacheId;
    }
 
    @Override
    public double sumRecordWeight(InoutParam param) {
        CommonData result = inoutMapper.sumRecordWeight(param);
        return result.getNumValue1();
    }
 
    @Override
    public int checkExist(InoutParam param) {
        return inoutMapper.checkExist(param);
    }
 
    /**
     * 未完成流程存入缓存
     *
     * @param deptId
     * @param data
     */
    private void setInoutCache(String deptId, InoutData data) {
        String key = this.buildInoutKey(deptId, InoutConstant.KEY_INOUT_LIST, data.getType(), data.getId());
        redisUtil.set(key, data, InoutConstant.KEY_INOUT_LIST_TIME);
    }
 
    /**
     * 设置完成的流水存入缓存
     *
     * @param deptId
     * @param data
     */
    private void setCompleteInoutCache(String deptId, InoutData data) {
        String key = this.buildInoutKey(deptId, InoutConstant.KEY_INOUT_COMPLETE_LIST, data.getType(), data.getId());
        //设置缓存到第二天凌晨(计算当前时间到第二天凌晨的时间差秒数)
        redisUtil.set(key, data, DateUtil.getNowToNextDaySeconds());
    }
 
    /**
     * 创建出入库key
     *
     * @param deptId
     * @param key
     * @param type
     * @param bizId
     * @return
     */
    public String buildInoutKey(String deptId, String key, String type, String bizId) {
        return Constant.APP_NAME + ":" + deptId + ":" + key + ":" + type + ":" + bizId;
    }
 
    @Override
    public Page<InoutCheckData> pageSampleData(InoutCheckParam param) {
 
        //设置起始和截止时间
        if (null != param.getStart()) {
            param.setStart(DateUtil.getCurZero(param.getStart()));
        }
        if (null != param.getEnd()) {
            param.setEnd(DateUtil.getNextZero(param.getEnd()));
        }
 
        // 设置车牌和检验单据的模糊查询
        if (StringUtils.isNotEmpty(param.getPlateNum())) {
            param.setPlateNum("%" + param.getPlateNum() + "%");
        }
        if (StringUtils.isNotEmpty(param.getCheckId())) {
            param.setCheckId("%" + param.getCheckId() + "%");
        }
 
        Page<InoutCheckData> page = new Page<>(param.getPage(), param.getLimit());
        page.setSearchCount(true);
 
        List<InoutCheckData> records = inoutCheckMapper.pageSampleData(page, param);
        page.setRecords(records);
 
        return page;
    }
 
    @Override
    public String updateSampleData(InoutCheckData data) {
        if (StringUtils.isEmpty(data.getCompanyId())) {
            data.setCompanyId(ContextUtil.getCompanyId());
        }
        if (StringUtils.isEmpty(data.getDeptId())) {
            data.setDeptId(ContextUtil.subDeptId(null));
        }
 
        inoutCheckMapper.updateSampleData(data);
 
        return null;
    }
 
    @Override
    public Page<InoutCheckData> pageCheckData(InoutCheckParam param) {
 
        //设置起始和截止时间
        if (null != param.getStart()) {
            param.setStart(DateUtil.getCurZero(param.getStart()));
        }
        if (null != param.getEnd()) {
            param.setEnd(DateUtil.getNextZero(param.getEnd()));
        }
 
        // 设置检验单据的模糊查询
        if (StringUtils.isNotEmpty(param.getCheckId())) {
            param.setCheckId("%" + param.getCheckId() + "%");
        }
 
        Page<InoutCheckData> page = new Page<>(param.getPage(), param.getLimit());
        page.setSearchCount(true);
 
        List<InoutCheckData> records = inoutCheckMapper.pageCheckData(page, param);
        page.setRecords(records);
 
        return page;
    }
 
    @Override
    public String updateCheckData(InoutData data) {
        data.setUpdateTime(new Date());
 
        inoutCheckMapper.updateCheckData(data);
 
        //更新缓存
        updateInoutCache(data);
 
        return null;
    }
 
    @Override
    public List<InoutPrice> getPrice(InoutCheckParam param) {
        if (null == param.getStart()) {
            param.setStart(new Date());
        }
        if (null == param.getEnd()) {
            param.setEnd(new Date());
        }
        return inoutCheckMapper.getPrice(param);
    }
 
    @Override
    public InoutCheckData inoutDataByCheckId(InoutCheckParam param) throws Exception {
        List<InoutCheckData> list = inoutCheckMapper.inoutDataByCheckId(param);
        if (null == list || list.size() == 0)
            return null;
        if (list.size() == 1) {
            return list.get(0);
        } else {
            throw new Exception("当前条件下存在多个满足条件的数据,请核查!!");
        }
    }
 
    @Override
    public List<InoutLossOver> listLossOver(InoutParam param) {
        if (StringUtils.isEmpty(param.getCompanyId())) {
            param.setCompanyId(ContextUtil.getCompanyId());
        }
        List<InoutLossOver> list = inoutMapper.listLossOver(param);
 
        return list;
    }
 
    @Override
    public double sumLossOverWeight(InoutParam param) {
        CommonData result = inoutMapper.sumLossOverWeight(param);
        return result.getNumValue1();
    }
}