黎星凯
2024-04-15 62b6a7fac3f2acde70b578431147c4a01f19c182
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
package com.consum.base.service.impl;
 
import java.util.ArrayList;
import java.util.List;
 
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
 
import com.consum.base.core.type.InventoryResultType;
import com.consum.base.core.utils.IdUtil;
import com.consum.base.pojo.response.FormInventoryGoodsVO;
import com.consum.base.service.LWhFormInventoryGoodsService;
import com.consum.model.po.LWhFormInventoryGoods;
import com.walker.jdbc.service.BaseServiceImpl;
 
import lombok.extern.slf4j.Slf4j;
 
/**
 * @Description 盘点单物品
 * @Author 卢庆阳
 * @Date 2023/10/31
 */
@Slf4j
@Service
@Transactional(propagation = Propagation.REQUIRED)
public class LWhFormInventoryGoodsServiceImpl extends BaseServiceImpl implements LWhFormInventoryGoodsService {
 
    @Override
    public List<LWhFormInventoryGoods> getByInventoryId(Long id) {
        LWhFormInventoryGoods inventoryGoods = new LWhFormInventoryGoods();
        inventoryGoods.setWhFormInventoryId(id);
        return this.select(inventoryGoods);
    }
 
    @Override
    public List<FormInventoryGoodsVO> add(List<FormInventoryGoodsVO> inventoryGoodsList, Long inventoryId) {
        List<LWhFormInventoryGoods> goodsList = new ArrayList<>();
        for (FormInventoryGoodsVO inventoryGoods : inventoryGoodsList) {
            LWhFormInventoryGoods lWhFormInventoryGoods = new LWhFormInventoryGoods();
            lWhFormInventoryGoods.setId(IdUtil.generateId());
            lWhFormInventoryGoods.setWhFormInventoryId(inventoryId);
            lWhFormInventoryGoods.setBaseGoodsTemplateId(inventoryGoods.getBaseGoodsTemplateId());
            lWhFormInventoryGoods.setGoodsTemplateName(inventoryGoods.getGoodsTemplateName());
            lWhFormInventoryGoods.setUnit(inventoryGoods.getUnit());
            lWhFormInventoryGoods.setBaseGoodsModelsId(inventoryGoods.getBaseGoodsModelId());
            lWhFormInventoryGoods.setBaseGoodsModelsName(inventoryGoods.getBaseGoodsModelsName());
            lWhFormInventoryGoods.setInitCounts(inventoryGoods.getInventoryCount());
            // 保存成功后返回id,用来进行记录的更新
            inventoryGoods.setId(lWhFormInventoryGoods.getId());
            goodsList.add(lWhFormInventoryGoods);
        }
        this.insert(goodsList);
        return inventoryGoodsList;
    }
 
    @Override
    public int updateInventoryGoods(List<FormInventoryGoodsVO> inventoryGoodsList) {
        List<LWhFormInventoryGoods> goodsList = new ArrayList<>();
        for (FormInventoryGoodsVO inventoryGoods : inventoryGoodsList) {
            LWhFormInventoryGoods lWhFormInventoryGoods = new LWhFormInventoryGoods();
            lWhFormInventoryGoods.setId(inventoryGoods.getId());
            Integer inventoryCount = inventoryGoods.getInventoryCount();
            Integer realNum = inventoryGoods.getRealNum();
            if (realNum != null) {
                int errorCount = realNum - inventoryCount;
                lWhFormInventoryGoods.setInventoryCounts(realNum);
                lWhFormInventoryGoods.setErrorCounts(Math.abs(errorCount));
                // 盘点结果(1=正常;2=盘盈;3=盘亏)
                lWhFormInventoryGoods.setInventoryResult((errorCount > 0) ? InventoryResultType.SURPLUS.getValue()
                    : (errorCount < 0) ? InventoryResultType.LOSS.getValue() : InventoryResultType.NORMAL.getValue());
                goodsList.add(lWhFormInventoryGoods);
            }
 
        }
        this.updateBatch(goodsList);
        return 1;
    }
 
}