ICSITEMLotService.java
4.87 KB
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
package com.huaheng.pc.srm.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.api.srm.domain.SRMResult;
import com.huaheng.common.exception.RunFailException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.pc.srm.domain.ICSASN;
import com.huaheng.pc.srm.domain.ICSITEMLot;
import com.huaheng.pc.srm.mapper.ICSITEMlotMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class ICSITEMLotService extends ServiceImpl<ICSITEMlotMapper, ICSITEMLot> {
    @Resource
    RunFailException runFailException;
    @Resource
    private MaterialService materialService;
    public List<ICSITEMLot> selectList(ICSITEMLot icsitemLot){
        LambdaQueryWrapper<ICSITEMLot> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(StringUtils.isNotEmpty(icsitemLot.getLotNO()),ICSITEMLot::getLotNO,icsitemLot.getLotNO());
        return this.list(queryWrapper);
    }
    public ICSITEMLot selectFirstModel(ICSITEMLot icsitemLot){
        LambdaQueryWrapper<ICSITEMLot> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(StringUtils.isNotEmpty(icsitemLot.getLotNO()),ICSITEMLot::getLotNO,icsitemLot.getLotNO());
        queryWrapper.eq(StringUtils.isNotEmpty(icsitemLot.getWarehouseCode()),ICSITEMLot::getWarehouseCode,icsitemLot.getWarehouseCode());
        queryWrapper.last("limit 1");
        return this.getOne(queryWrapper);
    }
    /**
     * 获取物料条码
     *
     * @param icsitemLotList
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public SRMResult saveICSItemLotList(List<ICSITEMLot> icsitemLotList) {
        SRMResult srmResult = new SRMResult();
        ICSITEMLot queryIcsitemLot = new ICSITEMLot();
        for (ICSITEMLot icsitemLot : icsitemLotList) {
            if(StringUtils.isEmpty(icsitemLot.getItemCode())){
                return srmResult.error("物料不存在");
            }
            if(StringUtils.isEmpty(icsitemLot.getWarehouseCode())){
                return srmResult.error("仓库code不存在");
            }
            Material material = materialService.getMaterialByCode(icsitemLot.getItemCode(),icsitemLot.getWarehouseCode());
            if(material == null){
                runFailException.sendException("ID为:"+icsitemLot.getID()+"的物料条码在wms不存在");
                return srmResult.error("ID为:"+icsitemLot.getID()+"的物料条码在wms不存在");
            }
            queryIcsitemLot.setLotNO(icsitemLot.getLotNO());
                if (this.selectList(queryIcsitemLot).size()!=0){
                    if(!this.updateById(icsitemLot)){
                        runFailException.sendException("ID为:"+icsitemLot.getID()+"的物料条码更新失败");
                        return srmResult.error("ID为:"+icsitemLot.getID()+"的物料条码更新失败");
                    }
                }else {
                    if (!this.save(icsitemLot)){
                        runFailException.sendException("ID为:"+icsitemLot.getID()+"的物料条码插入失败");
                        return srmResult.error("ID为:"+icsitemLot.getID()+"的物料条码插入失败");
                    }
                }
        }
        return srmResult.success("物料条码列表插入成功");
    }
    public SRMResult delICSItemLotList(List<ICSITEMLot> icsitemLotList) {
        SRMResult srmResult = new SRMResult();
        if (icsitemLotList.isEmpty()){
            return srmResult.error("请勿提交空数据!");
        }
        if (icsitemLotList.size() == 0){
            return srmResult.error("条码数据不能为空!");
        }
        List<String> warehouseCodes = icsitemLotList.stream().map(ICSITEMLot::getWarehouseCode).collect(Collectors.toList());
        if (warehouseCodes.size() == 0){
            return srmResult.error("仓库code不能为空值!");
        }
        try {
            deleteByLOTNOs(icsitemLotList.stream().map(ICSITEMLot::getLotNO).collect(Collectors.toList()));
        }catch (Exception e){
            return srmResult.error(e.getMessage());
        }
        return srmResult.success("条码删除成功!");
    }
    public void deleteByLOTNOs(List<String> list) {
        if(list!=null&&list.size()>0){
            String[] split=list.toArray(new String[0]);
            LambdaQueryWrapper<ICSITEMLot> queryWrapper = Wrappers.lambdaQuery();
            queryWrapper.in(ICSITEMLot::getLotNO,split);
            this.remove(queryWrapper);
        }
    }
}