zenglf
2023-08-18 499d6294b4b7881c5797a59a183c5fc0105599dd
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
package org.jeecg.modules.spare.service.impl;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.spare.entity.*;
import org.jeecg.modules.spare.mapper.SparePartOutboundDetailMapper;
import org.jeecg.modules.spare.service.ISparePartOutboundDetailService;
import org.jeecg.modules.spare.service.ISparePartOutboundService;
import org.jeecg.modules.spare.service.ISparePartService;
import org.jeecg.modules.spare.service.ISparesPartInventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
 
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
 
/**
 * @Description: mom_eam_spare_part_outbound_deatil
 * @Author: jeecg-boot
 * @Date:   2023-06-30
 * @Version: V1.0
 */
@Service
public class SparePartOutboundDetailServiceImpl extends ServiceImpl<SparePartOutboundDetailMapper, SparePartOutboundDetail> implements ISparePartOutboundDetailService {
 
    @Autowired
    @Lazy
    private ISparesPartInventoryService sparesPartInventoryService;
 
    @Autowired
    @Lazy
    private ISparePartService sparePartService;
 
    @Autowired
    @Lazy
    private ISparePartOutboundService sparePartOutboundService;
 
    @Override
    public List<Map<String, Object>> getSparePartOutboundDeatilList(String sparePartOutboundId) {
        return this.baseMapper.getSparePartOutboundDeatilList(sparePartOutboundId);
    }
 
    @Override
    public IPage<Map<String, Object>> getSparePartOutboundDetailsById(Integer pageNo, Integer pageSize, Map<String, Object> params) {
        IPage<Map> pageData = new Page<Map>(pageNo, pageSize);
        return super.getBaseMapper().getSparePartOutboundDetailsById(pageData,params);
    }
 
 
    @Override
    @Transactional(rollbackFor = { Exception.class })
    public boolean sparePartOutbound(SparePartOutboundDetail sparePartOutboundDetail) {
        //1.获取库存信息及库存总数量
        String sparePartOutboundId = sparePartOutboundDetail.getSparePartOutboundId();
        SparePartOutbound sparePartOutbound = sparePartOutboundService.getById(sparePartOutboundId);
        String sparesPartInventoryId = sparePartOutboundDetail.getSparesPartInventoryId();
        SparesPartInventory sparesPartInventory = sparesPartInventoryService.getById(sparesPartInventoryId);
 
        //2.获取出库数量
        Double outboundMainQuantity = sparePartOutboundDetail.getOutboundMainQuantity();
        BigDecimal outboundMainQuantityB = new BigDecimal(outboundMainQuantity);
        String sparePartId = sparePartOutboundDetail.getSparePartId();
 
        //3.获取主 辅单位转换比例
        SparePart sparePart = sparePartService.getById(sparePartId);
        String conversionRatio = sparePart.getConversionRatio();
        double conversionRatioD = 0;
        if(StringUtils.isBlank(conversionRatio)){
             conversionRatioD = Double.parseDouble("0");
        }else{
             conversionRatioD = Double.parseDouble(conversionRatio);
        }
        BigDecimal conversionRatioB = new BigDecimal(conversionRatioD);
 
        //4.计算出库数量更新库存数量(库存)
        Double mainQuantity = sparesPartInventory.getMainQuantity();
        BigDecimal mainQuantityB = new BigDecimal(mainQuantity);
        Double auxiliaryQuantity = sparesPartInventory.getAuxiliaryQuantity();
        BigDecimal auxiliaryQuantityB = new BigDecimal(auxiliaryQuantity);
 
        BigDecimal mainQuantitySubtract = mainQuantityB.subtract(outboundMainQuantityB);//减完后的库存主数量
        BigDecimal outboundAuxiliaryQuantity = outboundMainQuantityB.multiply(conversionRatioB);//出库辅数量
        BigDecimal auxiliaryQuantitySubtract = auxiliaryQuantityB.subtract(outboundAuxiliaryQuantity);//减完后的库存辅数量
 
        sparesPartInventory.setMainQuantity(mainQuantitySubtract.doubleValue());
        sparesPartInventory.setAuxiliaryQuantity(auxiliaryQuantitySubtract.doubleValue());
        boolean b = sparesPartInventoryService.updateById(sparesPartInventory);
        if(!b){
            return b;
        }
 
        sparePartOutboundDetail.setStatus("1");
        super.updateById(sparePartOutboundDetail);
 
        //5.更新出库单状态
        List<SparePartOutboundDetail> sparePartOutboundDetails = super.lambdaQuery()
                .eq(SparePartOutboundDetail::getSparePartOutboundId, sparePartOutboundId)
                .eq(SparePartOutboundDetail::getStatus, "0")
                .eq(SparePartOutboundDetail::getDelFlag, "0").list();
        if(sparePartOutboundDetails.size()==0){
            sparePartOutbound.setStatus("4");
            sparePartOutboundService.updateById(sparePartOutbound);
        }
        return true;
    }
 
 
}