Blame view

src/main/java/com/huaheng/api/general/service/BarCodeApiService.java 8.72 KB
lihailong authored
1
2
3
4
5
6
7
8
package com.huaheng.api.general.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.api.general.domain.BarCodeDomain;
import com.huaheng.api.wcs.service.taskInfo.TaskInfoService;
import com.huaheng.common.constant.QuantityConstant;
9
import com.huaheng.common.exception.BusinessException;
lihailong authored
10
import com.huaheng.common.exception.service.ServiceException;
11
import com.huaheng.common.utils.spring.SpringUtils;
lihailong authored
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.barcode.barcodeDetail.domain.BarCodeDetail;
import com.huaheng.pc.barcode.barcodeDetail.service.BarCodeDetailService;
import com.huaheng.pc.barcode.barcodeHeader.domain.BarCodeHeader;
import com.huaheng.pc.barcode.barcodeHeader.service.BarCodeHeaderService;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.pc.config.station.domain.Station;
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.ReceiptTaskService;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
lihailong authored
29
import java.math.BigDecimal;
lihailong authored
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.List;

@Component
@Transactional
public class BarCodeApiService {
    @Resource
    private BarCodeHeaderService barCodeHeaderService;
    @Resource
    private MaterialService materialService;
    @Resource
    private BarCodeDetailService barCodeDetailService;
    @Resource
    private TaskHeaderService taskHeaderService;
    @Resource
    private TaskDetailService taskDetailService;
    @Resource
    private TaskInfoService taskInfoService;
    @Resource
    private ReceiptTaskService receiptTaskService;
50
51
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult checkBarCode(BarCodeDomain barCodeDomain) {
lihailong authored
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
        BarCodeHeader barCodeHeader = barCodeDomain.getBarCodeHeader();
        String barCodeHeaderCode = barCodeHeader.getCode();
        if(barCodeHeaderCode == null){
            return AjaxResult.error("主码不存在 code");
        }

        barCodeHeader.setBarCodeHeaderCode(barCodeHeaderCode);

        LambdaQueryWrapper<BarCodeHeader> barCodeHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
        barCodeHeaderLambdaQueryWrapper.eq(BarCodeHeader::getBarCodeHeaderCode,barCodeHeader.getBarCodeHeaderCode());
        List<BarCodeHeader> barCodeHeaderList = barCodeHeaderService.list(barCodeHeaderLambdaQueryWrapper);
        if(barCodeHeaderList.size()>0){
            return AjaxResult.error("主码重复 code");
        }

        List<BarCodeDetail> barCodeDetailList = barCodeDomain.getBarCodeDetails();
        for (BarCodeDetail barCodeDetail : barCodeDetailList) {

            String barCodeDetailReceiptCode = barCodeDetail.getCode();
            if(barCodeDetailReceiptCode == null){
                return AjaxResult.error("子条码不存在 code");
            }
            barCodeDetail.setReceiptCode(barCodeDetailReceiptCode);
            String materialCode = barCodeDetail.getMaterialCode();
            if(materialCode == null){
                return AjaxResult.error("物料编码不存在 materialCode");
            }

//            String materialUnit = barCodeDetail.getMaterialUnit();
//            if(materialUnit == null){
//                return AjaxResult.error("物料单位不存在 materialUnit");
//            }
lihailong authored
85
            BigDecimal qty = barCodeDetail.getQty();
lihailong authored
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
            if(qty == null){
                return AjaxResult.error("数量不存在 qty");
            }

            String sn = barCodeDetail.getSn();
            if(sn == null){
                return AjaxResult.error("序列号不存在 sn");
            }

        }
        return AjaxResult.success();
    }
101
    @Transactional(rollbackFor = Exception.class)
lihailong authored
102
    public AjaxResult addBarCodeApi(BarCodeDomain barCodeDomain){
103
104
        boolean result = false;
        BarCodeHeader header = barCodeDomain.getBarCodeHeader();
105
106
107
108
109
        //原料批次
        String materialBatch = header.getMaterialBatch();
        if(materialBatch ==null){
            return AjaxResult.error("包装信息头错误:原料批次不存在");
        }
110
111
112
113
        String barCodeHeaderCode = header.getCode();
        String fbillno = header.getFbillno();
        if(barCodeHeaderCode == null || "".equals(barCodeHeaderCode)){
            return AjaxResult.error("主码不存在 code");
lihailong authored
114
115
        }
        String code = barCodeHeaderService.createCode("BZXXRK");
116
117
118
119

        BarCodeHeader barCodeHeader = barCodeHeaderService.getOne(new LambdaQueryWrapper<BarCodeHeader>()
                .eq(BarCodeHeader::getBarCodeHeaderCode,barCodeHeaderCode)
                .eq(BarCodeHeader::getFbillno,fbillno));
120
121
122
123
124
        if(barCodeHeader != null){
            return AjaxResult.error("包装信息头错误:主条码重复【"+barCodeHeaderCode+"】。");
        }
        barCodeHeader = new BarCodeHeader();
        barCodeHeader.setCode(code);
125
        barCodeHeader.setMaterialBatch(materialBatch);
126
127
128
129
130
131
132
133
134
135
136
137
138
        barCodeHeader.setReceiptType("BZXXRK");
        barCodeHeader.setWarehouseCode(QuantityConstant.DEFAULT_WAREHOUSE);
        barCodeHeader.setCompanyCode(QuantityConstant.DEFAULT_COMPANYCODE);
        barCodeHeader.setFbillno(fbillno);
        barCodeHeader.setCreatedBy(QuantityConstant.PLATFORM_MES);
        barCodeHeader.setBarCodeHeaderCode(barCodeHeaderCode);
        barCodeHeader.setReceiptNote(header.getReceiptNote());
        barCodeHeader.setTotalQty(BigDecimal.ZERO);
        barCodeHeader.setTotalLines(0);
        barCodeHeader.setTotalWeight(BigDecimal.ZERO);
        result = barCodeHeaderService.save(barCodeHeader);
        if(!result){
            throw new ServiceException("保存 包装头信息插入失败");
lihailong authored
139
        }
140
141
142
143
144
145
146
147
148
        List<BarCodeDetail> barCodeDetails = barCodeDomain.getBarCodeDetails();
        BigDecimal totalQty = BigDecimal.ZERO;
        BigDecimal totalWeight = BigDecimal.ZERO;
        int totalLines = barCodeDetails.size();

        for (BarCodeDetail detail : barCodeDetails) {
            BarCodeDetail barCodeDetail = new BarCodeDetail();
            barCodeDetail.setWarehouseCode(QuantityConstant.DEFAULT_WAREHOUSE);
            barCodeDetail.setCompanyCode(QuantityConstant.DEFAULT_COMPANYCODE);
lihailong authored
149
            barCodeDetail.setReceiptId(barCodeHeader.getId());
150
151
            barCodeDetail.setCode(detail.getCode());
            barCodeDetail.setPower(detail.getPower());
lihailong authored
152
            barCodeDetail.setReceiptCode(barCodeHeader.getCode());
153
154
155
156

            String materialCode = detail.getMaterialCode();
            String materialUnit = detail.getMaterialUnit();
            BigDecimal qty = detail.getQty();
tongzhonghao authored
157
            BigDecimal weight = detail.getWeight();
tongzhonghao authored
158
159
            if(weight == null){
                return AjaxResult.error("包装信息入库子明细,重量不能为空");
tongzhonghao authored
160
161
            }
            if(qty == null || qty.compareTo(BigDecimal.ZERO) <= 0){
162
                return AjaxResult.error("数量不存在 qty");
lihailong authored
163
            }
tongzhonghao authored
164
165
166
167
168
            String sn = detail.getSn();
            totalQty.add(qty);
            totalWeight.add(weight);
169
170
171
172
173
174
175
176
177
178
179
            LambdaQueryWrapper<Material> queryWrapper1 = Wrappers.lambdaQuery();
            queryWrapper1.eq(Material::getCode,materialCode)
                    .eq(Material::getUnit,materialUnit);
            Material material = materialService.getOne(queryWrapper1);
            if(material == null){
                return AjaxResult.error("没改物料编码:"+barCodeDetail.getMaterialCode());
            }
            barCodeDetail.setMaterialCode(material.getCode());
            barCodeDetail.setMaterialName(material.getName());
            barCodeDetail.setMaterialSpec(material.getSpec());
            barCodeDetail.setMaterialUnit(material.getUnit());
tongzhonghao authored
180
            barCodeDetail.setQty(BigDecimal.ONE);
181
            barCodeDetail.setSn(sn);
tongzhonghao authored
182
            barCodeDetail.setWeight(weight);
183
184
185
            result = barCodeDetailService.save(barCodeDetail);
            if(!result){
                throw new ServiceException("包装子信息插入失败");
lihailong authored
186
187
            }
        }
188
189
190
191
192
193
194
        barCodeHeader.setTotalQty(barCodeHeader.getTotalQty().add(totalQty));
        barCodeHeader.setTotalWeight(barCodeHeader.getTotalWeight().add(totalWeight));
        barCodeHeader.setTotalLines(totalLines);
        result = barCodeHeaderService.updateById(barCodeHeader);
        if(!result){
            throw new ServiceException("更新包装入库头信息失败。");
        }
lihailong authored
195
196
197
198
        return AjaxResult.success();
    }

}