BarCodeApiService.java 10.1 KB
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;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.spring.SpringUtils;
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;
import java.math.BigDecimal;
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;

    @Transactional(rollbackFor = Exception.class)
    public AjaxResult checkBarCode(BarCodeDomain barCodeDomain) {
        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");
//            }

            BigDecimal qty = barCodeDetail.getQty();
            if(qty == null){
                return AjaxResult.error("数量不存在 qty");
            }

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

        }
        return AjaxResult.success();
    }



    @Transactional(rollbackFor = Exception.class)
    public AjaxResult addBarCodeApi(BarCodeDomain barCodeDomain){
        AjaxResult ajaxResult = checkBarCode(barCodeDomain);
        if(ajaxResult.getCode()!=200){
            return AjaxResult.error(ajaxResult.getMsg());
        }
        BarCodeHeader barCodeHeader = barCodeDomain.getBarCodeHeader();
        barCodeHeader.setReceiptType("BZXXRK");
        if(StringUtils.isNotEmpty(barCodeHeader.getReceiptNote())){
            barCodeHeader.setReceiptNote(barCodeHeader.getReceiptNote());
        }
        barCodeHeader.setBarCodeHeaderCode(barCodeHeader.getCode());
        //获得入库单据
        String code = barCodeHeaderService.createCode("BZXXRK");
        //重新覆盖值
        barCodeHeader.setCode(code);
        barCodeHeader.setWarehouseCode("CS0001");
        barCodeHeader.setCompanyCode("BHF");
        barCodeHeader.setFbillno(barCodeDomain.getBarCodeHeader().getFbillno());
        boolean savebarCodeHeader = barCodeHeaderService.save(barCodeHeader);
        if(!savebarCodeHeader){
            return AjaxResult.error("包装头信息插入失败");
        }
        List<BarCodeDetail> barCodeDetailList = barCodeDomain.getBarCodeDetails();
        for (BarCodeDetail barCodeDetail : barCodeDetailList) {
            barCodeDetail.setWarehouseCode("CS0001");
            barCodeDetail.setCompanyCode("BHF");
            barCodeDetail.setReceiptId(barCodeHeader.getId());
            barCodeDetail.setCode(barCodeDetail.getCode());
            barCodeDetail.setReceiptCode(barCodeHeader.getCode());
//            barCodeDetail.setMaterialCode(barCodeDetail.getMaterialCode());
            if(barCodeDetail.getMaterialName() == null){
                LambdaQueryWrapper<Material> materialLambdaQueryWrapper = Wrappers.lambdaQuery();
                materialLambdaQueryWrapper.eq(Material::getCode,barCodeDetail.getMaterialCode())
                .eq(Material::getUnit,barCodeDetail.getMaterialUnit());
                Material materialServiceOne = materialService.getOne(materialLambdaQueryWrapper);
                if(materialServiceOne == null){
                    return AjaxResult.error("没改物料编码:"+barCodeDetail.getMaterialCode());
                }
                String materialName = materialServiceOne.getName();
                barCodeDetail.setMaterialName(materialName);
            }
//            barCodeDetail.setMaterialName(barCodeDetail.getMaterialName());
            if(StringUtils.isNotEmpty(barCodeDetail.getMaterialUnit())){
                barCodeDetail.setMaterialUnit(barCodeDetail.getMaterialUnit());
            }
            boolean savebarCodeDetail = barCodeDetailService.save(barCodeDetail);
            if(!savebarCodeDetail){
                return AjaxResult.error("包装子信息插入失败");
            }

//
//            LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper2 = Wrappers.lambdaQuery();
//            taskHeaderLambdaQueryWrapper2.eq(TaskHeader::getPort, barCodeDomain.getPort())
//                    .eq(TaskHeader::getArea, barCodeDomain.getArea())
//                    .in(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT,
//                            QuantityConstant.TASK_TYPE_WHOLERECEIPT)
//                    .eq(TaskHeader::getMaterialCode, barCodeDetail.getMaterialCode())
////                    .eq(TaskHeader::getBack, 0)
//                    .lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
//            TaskHeader taskHeader = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper2);
//            if(taskHeader != null) {
//                LambdaQueryWrapper<TaskDetail> taskDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
//                taskDetailLambdaQueryWrapper.eq(TaskDetail::getTaskId, taskHeader.getId());
//                List<TaskDetail> taskDetailList = taskDetailService.list(taskDetailLambdaQueryWrapper);
//                if (taskDetailList != null && taskDetailList.size() >= 0) {
//                    int size = taskDetailList.size();
//                    if (size == 0) {
//                        return AjaxResult.error("不要重复请求入库");
//                    }
//                    taskHeaderService.updateById(taskHeader);
//                }
//            } else {
//                LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper3 = Wrappers.lambdaQuery();
//                taskHeaderLambdaQueryWrapper3.eq(TaskHeader::getPort, barCodeDomain.getPort())
//                                            .eq(TaskHeader::getArea, barCodeDomain.getArea())
//                                            .in(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT,
//                                                    QuantityConstant.TASK_TYPE_WHOLERECEIPT)
//                                            .eq(TaskHeader::getMaterialCode, barCodeDetail.getMaterialCode())
//                    //                    .eq(TaskHeader::getBack, 0)
//                                            .lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
//                List<TaskHeader> taskHeaderList = taskHeaderService.list(taskHeaderLambdaQueryWrapper3);
//                if(taskHeaderList.size() > 1) {
//                    taskHeader = taskHeaderList.get(0);
//                    if (taskHeader != null) {
//                        taskHeaderService.updateById(taskHeader);
//                    }
//                } else {
//                    taskHeader = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper3);
//                    if (taskHeader != null) {
//                        taskHeaderService.updateById(taskHeader);
//                    }
//                }
//            }
        }


//        String stationCode = barCodeDomain.getPort();
//
////        String containerCode = taskInfoService.getStationPallet(stationCode, area);
//        String containerCode = barCodeDomain.getContainerCode();
//        if(containerCode != null){
//            return receiptTaskService.createWholeReceiptTask(containerCode,
//                    "2022202240001", "CS0001", stationCode, barCodeDomain.getArea(),barCodeDetailList);
//        }
        return AjaxResult.success();
    }



}