1134 lines
56 KiB
Plaintext
1134 lines
56 KiB
Plaintext
package com.cmeim.biz.service;
|
||
|
||
import com.alibaba.fastjson.JSONObject;
|
||
import com.cmeim.activiti6.api.RemoteActiviti6Service;
|
||
import com.cmeim.activiti6.api.dto.StartParamsDto;
|
||
import com.cmeim.activiti6.api.enums.BizKey;
|
||
import com.cmeim.basic.api.RemoteCustomerService;
|
||
import com.cmeim.basic.api.RemoteLocationService;
|
||
import com.cmeim.basic.api.RemoteMaterialService;
|
||
import com.cmeim.basic.api.dto.CustomerDto;
|
||
import com.cmeim.basic.api.dto.MaterialDto;
|
||
import com.cmeim.basic.api.dto.SupplierDto;
|
||
import com.cmeim.basic.api.enums.BaNumberRuleCode;
|
||
import com.cmeim.biz.dto.MaterialBarDto;
|
||
import com.cmeim.biz.enums.WfStatus;
|
||
import com.cmeim.biz.po.*;
|
||
import com.cmeim.biz.repository.*;
|
||
import com.cmeim.biz.vo.ArriveBillAddMaterialBar;
|
||
import com.cmeim.biz.vo.ArriveBillDetailVo;
|
||
import com.cmeim.biz.vo.MaterialBarVo;
|
||
import com.cmeim.biz.vo.OtherInAddMaterialBar;
|
||
import com.cmeim.biz.vo.ProdInAddMaterialBar;
|
||
import com.cmeim.biz.vo.app.InputStockInMaterialBarVo;
|
||
import com.cmeim.biz.vo.app.InputStockInVo;
|
||
import com.cmeim.common.core.domain.R;
|
||
import com.cmeim.common.core.exception.ServiceException;
|
||
import com.cmeim.common.core.utils.BeanUtil;
|
||
import com.cmeim.common.core.utils.DateUtil;
|
||
import com.cmeim.common.core.utils.DateUtils;
|
||
import com.cmeim.common.core.utils.SecurityUtils;
|
||
import com.cmeim.common.core.utils.StringUtils;
|
||
import com.cmeim.common.core.web.domain.RespondEnum;
|
||
import com.cmeim.stock.dto.MmStockDto;
|
||
import com.cmeim.stock.dto.StockBizDto;
|
||
import com.cmeim.stock.po.BaLocation;
|
||
import com.cmeim.stock.po.BaLocationRecommend;
|
||
import com.cmeim.stock.po.BaWarehouse;
|
||
import com.cmeim.stock.po.MmStockBiz;
|
||
import com.cmeim.stock.repository.BaWareHouseRepository;
|
||
import com.cmeim.stock.repository.BalocationRecommendRepository;
|
||
import com.cmeim.stock.repository.BalocationRepository;
|
||
import com.cmeim.stock.repository.MmStockBizRepository;
|
||
import com.cmeim.stock.repository.MmStockRepository;
|
||
import com.cmeim.stock.service.api.StockService;
|
||
import com.cmeim.stock.vo.stock.StockInVo;
|
||
import com.cmeim.system.api.RemoteConfigService;
|
||
import com.cmeim.wms.api.dto.InputStockInDto;
|
||
import com.cmeim.wms.api.dto.InputStockInMaterialBarDto;
|
||
import lombok.extern.slf4j.Slf4j;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.kafka.core.KafkaTemplate;
|
||
import org.springframework.stereotype.Service;
|
||
import org.springframework.transaction.annotation.Transactional;
|
||
|
||
import java.math.BigDecimal;
|
||
import java.util.ArrayList;
|
||
import java.util.List;
|
||
import java.util.Optional;
|
||
import java.util.stream.Collectors;
|
||
|
||
@Slf4j
|
||
@Service
|
||
public class InputMaterialBarService {
|
||
|
||
@Autowired
|
||
private MmOtherInputDetailRepository otherInputDetailRepository;
|
||
@Autowired
|
||
private MmArriveBillRepository arriveBillRepository;
|
||
@Autowired
|
||
private MmArriveBillDetailRepository arriveBillDetailRepository;
|
||
@Autowired
|
||
private MmMaterialBarRepository materialBarRepository;
|
||
@Autowired
|
||
private InputRemoteService remoteService;
|
||
@Autowired
|
||
private RemoteMaterialService remoteMaterialService;
|
||
@Autowired
|
||
private MmInputBillRepository mmInputBillRepository;
|
||
@Autowired
|
||
private RemoteActiviti6Service activiti6Service;
|
||
@Autowired
|
||
private InputBillService inputBillService;
|
||
@Autowired
|
||
private MmOtherInputBillRepository otherInputBillRepository;
|
||
@Autowired
|
||
private MmInspectBillDetailRepository inspectBillDetailRepository;
|
||
@Autowired
|
||
private MmInspectBillItemRepository inspectBillItemRepository;
|
||
@Autowired
|
||
private MmInspectBillRepository inspectBillRepository;
|
||
@Autowired
|
||
private StockService stockService;
|
||
@Autowired
|
||
private BalocationRepository balocationRepository;
|
||
@Autowired
|
||
private MmStockBizRepository mmStockBizRepository;
|
||
@Autowired
|
||
private BaWareHouseRepository baWareHouseRepository;
|
||
@Autowired
|
||
private MmProdInBillRepository prodInBillRepository;
|
||
@Autowired
|
||
private MmProdInBillDetailRepository prodInBillDetailRepository;
|
||
@Autowired
|
||
private BalocationRecommendRepository balocationRecommendRepository;
|
||
@Autowired
|
||
private KafKaService kafKaService;
|
||
@Autowired
|
||
private MmInputBillDetailRepository mmInputBillDetailRepository;
|
||
|
||
/**
|
||
* 打印条码
|
||
*
|
||
* @param vo 条码集合
|
||
* @return 返回值
|
||
*/
|
||
@Transactional(rollbackFor = {ServiceException.class, RuntimeException.class, Exception.class})
|
||
public List<MaterialBarVo> printBars(MaterialBarVo vo) {
|
||
if (vo.getPlanQty() == null) {
|
||
ServiceException exception = new ServiceException(RespondEnum.FAILURE);
|
||
exception.setErrorMessage("计划入库数量不能为空!");
|
||
throw exception;
|
||
}
|
||
if (vo.getPackageSize() == null) {
|
||
ServiceException exception = new ServiceException(RespondEnum.FAILURE);
|
||
exception.setErrorMessage("包装数量不能为空!");
|
||
throw exception;
|
||
}
|
||
|
||
if (vo.getPackageSize().compareTo(new BigDecimal(0)) == 0) {
|
||
ServiceException exception = new ServiceException(RespondEnum.FAILURE);
|
||
exception.setErrorMessage("包装数量不能为0!");
|
||
throw exception;
|
||
}
|
||
|
||
if (vo.getInputBillId() == null) {
|
||
ServiceException exception = new ServiceException(RespondEnum.FAILURE);
|
||
exception.setErrorMessage("入库单明细ID不能为空!");
|
||
throw exception;
|
||
}
|
||
|
||
MaterialDto materialDto = remoteService.findMaterialById(vo.getMaterialId());
|
||
String supplierCode = materialDto.getProviderCode();
|
||
String supplierName = materialDto.getProviderName();
|
||
|
||
List<MaterialBarVo> voList = new ArrayList<>();
|
||
|
||
//List<MmMaterialBar> barList = materialBarRepository.findAllByBillDetailIdAndDictType(vo.getBillDetailId(),
|
||
List<MmMaterialBar> barList = materialBarRepository.findAllByInputBillIdAndDictType(vo.getInputBillId(),
|
||
vo.getDictType());
|
||
if (barList != null && barList.size() != 0) {
|
||
for (MmMaterialBar bar : barList) {
|
||
MaterialBarVo materialBarVo = new MaterialBarVo();
|
||
|
||
materialBarVo.setInputBillNumber(bar.getInputBillNumber());
|
||
materialBarVo.setMaterialCode(materialDto.getMaterialCode());
|
||
materialBarVo.setMaterialName(materialDto.getMaterialName());
|
||
materialBarVo.setBatchNo(bar.getBatchNo());
|
||
materialBarVo.setSupplierCode(supplierCode);
|
||
materialBarVo.setSupplierName(supplierName);
|
||
materialBarVo.setMaterialQty(bar.getMaterialQty());
|
||
materialBarVo.setMaterialBar(bar.getMaterialBar());
|
||
|
||
voList.add(materialBarVo);
|
||
}
|
||
|
||
return voList;
|
||
}
|
||
|
||
BigDecimal[] c = vo.getPlanQty().divideAndRemainder(vo.getPackageSize());
|
||
|
||
int count = c[0].intValue();
|
||
List<MmMaterialBar> materialBarList = new ArrayList<>();
|
||
|
||
|
||
for (int i = 0; i < count; i++) {
|
||
final MaterialBarVo materialBarVo = new MaterialBarVo();
|
||
MmMaterialBar materialBar = new MmMaterialBar();
|
||
|
||
materialBar.setBoxBar(null);
|
||
materialBar.setLocationCode(null);
|
||
|
||
materialBar.setMaterialBar(remoteService.getByCode(BaNumberRuleCode.MATERIAL_PKG));
|
||
materialBar.setCreatedDt(DateUtil.getCurrentDate());
|
||
materialBar.setMaterialQty(vo.getPackageSize());
|
||
//materialBar.setBillDetailId(vo.getBillDetailId());
|
||
materialBar.setDictType(vo.getDictType());
|
||
materialBar.setCreatedBy(vo.getCreatedBy());
|
||
materialBar.setMaterialId(vo.getMaterialId());
|
||
materialBar.setInputBillId(vo.getInputBillId());
|
||
materialBar.setInputBillNumber(vo.getInputBillNumber());
|
||
materialBar.setBatchNo(vo.getBatchNo());
|
||
materialBarList.add(materialBar);
|
||
|
||
materialBarVo.setInputBillNumber(vo.getInputBillNumber());
|
||
materialBarVo.setMaterialCode(materialDto.getMaterialCode());
|
||
materialBarVo.setMaterialName(materialDto.getMaterialName());
|
||
materialBarVo.setBatchNo(vo.getBatchNo());
|
||
materialBarVo.setSupplierCode(supplierCode);
|
||
materialBarVo.setSupplierName(supplierName);
|
||
materialBarVo.setMaterialQty(materialBar.getMaterialQty());
|
||
materialBarVo.setMaterialBar(materialBar.getMaterialBar());
|
||
|
||
voList.add(materialBarVo);
|
||
}
|
||
|
||
if (c[1].compareTo(new BigDecimal(0)) > 0) {
|
||
final MaterialBarVo materialBarVo = new MaterialBarVo();
|
||
MmMaterialBar materialBar = new MmMaterialBar();
|
||
|
||
materialBar.setLocationCode(null);
|
||
materialBar.setBoxBar(null);
|
||
|
||
materialBar.setMaterialBar(remoteService.getByCode(BaNumberRuleCode.MATERIAL_PKG));
|
||
|
||
materialBar.setCreatedDt(DateUtil.getCurrentDate());
|
||
materialBar.setMaterialQty(c[1]);
|
||
//materialBar.setBillDetailId(vo.getBillDetailId());
|
||
materialBar.setDictType(vo.getDictType());
|
||
materialBar.setCreatedBy(vo.getCreatedBy());
|
||
materialBar.setMaterialId(vo.getMaterialId());
|
||
materialBar.setInputBillId(vo.getInputBillId());
|
||
materialBar.setInputBillNumber(vo.getInputBillNumber());
|
||
materialBar.setBatchNo(vo.getBatchNo());
|
||
materialBarList.add(materialBar);
|
||
materialBarVo.setInputBillNumber(vo.getInputBillNumber());
|
||
materialBarVo.setMaterialCode(materialDto.getMaterialCode());
|
||
materialBarVo.setMaterialName(materialDto.getMaterialName());
|
||
materialBarVo.setBatchNo(vo.getBatchNo());
|
||
materialBarVo.setSupplierCode(supplierCode);
|
||
materialBarVo.setSupplierName(supplierName);
|
||
materialBarVo.setMaterialQty(materialBar.getMaterialQty());
|
||
materialBarVo.setMaterialBar(materialBar.getMaterialBar());
|
||
|
||
voList.add(materialBarVo);
|
||
}
|
||
|
||
materialBarRepository.saveAll(materialBarList);
|
||
return voList;
|
||
}
|
||
|
||
|
||
public MaterialBarVo getDetailByBar(String bar) {
|
||
log.info("获取条码明细调用开始:" + bar);
|
||
MmMaterialBar materialBar = materialBarRepository.findByMaterialBar(bar);
|
||
MaterialBarVo materialBarVo = new MaterialBarVo();
|
||
if (materialBar != null) {
|
||
/* materialBarVo.setLocationId(materialBar.getLocationId());
|
||
materialBarVo.setLocationCode(materialBar.getLocationCode());*/
|
||
if (StringUtils.isNotBlank(materialBar.getWarehouseCode())) {
|
||
BaWarehouse baWarehouse = baWareHouseRepository.findByWarehouseCode(materialBar.getWarehouseCode());
|
||
if (StringUtils.isNotBlank(baWarehouse.getCustomerAbbreviation())) {
|
||
materialBarVo.setCustomerAbbreviation(baWarehouse.getCustomerAbbreviation());
|
||
}
|
||
}
|
||
}
|
||
if (materialBar == null) {
|
||
if (bar != null && (bar.length() == 44 || bar.length() == 54)) {
|
||
String materialCode = bar.substring(0, 9);
|
||
|
||
String bacthNo = bar.length() == 44 ? DateUtils.dateTime() : bar.substring(9, 19);
|
||
bacthNo = bacthNo.replaceAll("^(0+)", "");
|
||
|
||
BigDecimal materialQty = new BigDecimal(bar.length() == 44 ? bar.substring(35, 44) : bar.substring(45, 54));
|
||
materialBarVo.setMaterialBar(bar);
|
||
materialBarVo.setMaterialCode(materialCode);
|
||
if (StringUtils.isEmpty(bacthNo)) {
|
||
bacthNo = DateUtils.dateTime();
|
||
}
|
||
materialBarVo.setBatchNo(bacthNo);
|
||
|
||
materialBarVo.setMaterialQty(materialQty);
|
||
|
||
R<MaterialDto> materialDtoR = remoteMaterialService.findByMaterialCode(materialCode);
|
||
if (materialDtoR.getCode() == 200) {
|
||
MaterialDto materialDto = materialDtoR.getData();
|
||
if (materialDto != null) {
|
||
materialBarVo.setMaterialId(materialDto.getId());
|
||
materialBarVo.setMaterialName(materialDto.getMaterialName());
|
||
materialBarVo.setMaterialSpec(materialDto.getMaterialSpec());
|
||
}
|
||
}
|
||
materialBarVo.setIsHikBar(true);
|
||
log.info("获取条码明细调用结束:" + bar);
|
||
return materialBarVo;
|
||
} else {
|
||
log.info("获取条码明细调用结束:" + bar);
|
||
throw new ServiceException(RespondEnum.FAILURE, String.format("条码【%s】不存在", bar));
|
||
}
|
||
}
|
||
|
||
materialBarVo = BeanUtil.copyProperties(materialBar, MaterialBarVo.class);
|
||
if (materialBarVo != null) {
|
||
R<MaterialDto> materialDtoR = remoteMaterialService.get(materialBar.getMaterialId());
|
||
if (materialDtoR.getCode() == 200 && materialDtoR.getData() != null) {
|
||
MaterialDto materialDto = materialDtoR.getData();
|
||
materialBarVo.setSupplierCode(materialDto.getProviderCode());
|
||
materialBarVo.setMaterialId(materialDto.getId());
|
||
materialBarVo.setMaterialCode(materialDto.getMaterialCode());
|
||
materialBarVo.setMaterialName(materialDto.getMaterialName());
|
||
materialBarVo.setMaterialSpec(materialDto.getMaterialSpec());
|
||
}
|
||
materialBarVo.setIsHikBar(false);
|
||
return materialBarVo;
|
||
} else {
|
||
throw new RuntimeException("该条码不存在");
|
||
}
|
||
}
|
||
|
||
|
||
public List<MaterialBarVo> getDetailByBoxBar(String bar) {
|
||
List<MmMaterialBar> materialBarList = materialBarRepository.findAllByBoxBar(bar);
|
||
List<MaterialBarVo> voList = new ArrayList<>();
|
||
for (MmMaterialBar materialBar : materialBarList) {
|
||
MaterialBarVo vo = getDetailByBar(materialBar.getMaterialBar());
|
||
voList.add(vo);
|
||
}
|
||
return voList;
|
||
}
|
||
|
||
/**
|
||
* 入库上架
|
||
*
|
||
* @param vo 入库参数
|
||
*/
|
||
@Transactional(rollbackFor = {ServiceException.class, RuntimeException.class, Exception.class})
|
||
public void inputStockIn(InputStockInVo vo) {
|
||
//查询入单是否存在
|
||
MmInputBill inputBill = mmInputBillRepository.findByInputBillNumber(vo.getInputBillNumber());
|
||
log.info("入库上架入库单数据:" + JSONObject.toJSONString(vo));
|
||
if (inputBill == null) {
|
||
throw new ServiceException(RespondEnum.FAILURE, "查询相关入库单失败");
|
||
}
|
||
if (inputBill.getWarehouseCode() == null || "".equals(inputBill.getWarehouseCode())) {
|
||
throw new ServiceException(RespondEnum.FAILURE, String.format("请先维护入库单【%s】的入库库区", vo.getInputBillNumber()));
|
||
}
|
||
String currtime = DateUtil.getCurrentDate();
|
||
String username = SecurityUtils.getUsername();
|
||
String nickName = remoteService.getNickName(username);
|
||
//根据仓库获取对应库位
|
||
List<BaLocationRecommend> byWarehouseCode = balocationRecommendRepository.findByWarehouseCode(inputBill.getWarehouseCode());
|
||
if (byWarehouseCode.size() <= 0) {
|
||
throw new ServiceException(RespondEnum.FAILURE, String.format("根据仓库编码【%s】未找到库位",inputBill.getWarehouseCode()));
|
||
}
|
||
String locationCode = byWarehouseCode.get(0).getLocationCode();
|
||
|
||
//通过循环进行入库上架
|
||
for (InputStockInMaterialBarVo arrVo : vo.getMaterialBarArr()) {
|
||
//获取条码基本信息
|
||
MaterialBarVo materialBarVo = getDetailByBar(arrVo.getMaterialBar());
|
||
|
||
log.info("条码/IsHikBar是否为海康条码/条码库位"+arrVo.getMaterialBar()+
|
||
"/"+materialBarVo.getIsHikBar()+
|
||
"/"+materialBarVo.getLocationCode());
|
||
if (!materialBarVo.getIsHikBar() && materialBarVo.getLocationCode() != null) {
|
||
throw new ServiceException(RespondEnum.FAILURE, String.format("上架失败,条码【%s】已上架",
|
||
arrVo.getMaterialBar()));
|
||
}
|
||
MaterialBarVo bar = getDetailByBar(arrVo.getMaterialBar());
|
||
//添加库存信息
|
||
if (null == bar) {
|
||
return;
|
||
}
|
||
bar.setLocationCode(locationCode);
|
||
List<BaLocation> baLocation = balocationRepository.findAllByLocationCode(locationCode);
|
||
if (baLocation != null) {
|
||
bar.setLocationId(baLocation.get(0).getId());
|
||
}
|
||
bar.setDictStatus(30);
|
||
bar.setUpdatedBy(username);
|
||
bar.setUpdatedDt(currtime);
|
||
bar.setInputBillId(inputBill.getId());
|
||
bar.setInputBillNumber(inputBill.getInputBillNumber());
|
||
//materialBarRepository.save(BeanUtil.copyProperties(bar, MmMaterialBar.class));
|
||
MmInputBillDetail mmInputBillDetail = mmInputBillDetailRepository.findByInputBillNumberAndMaterialCodeAndBatchNo(
|
||
inputBill.getInputBillNumber(), bar.getMaterialCode(), bar.getBatchNo());
|
||
if (mmInputBillDetail == null) {
|
||
throw new ServiceException(RespondEnum.FAILURE, String.format("通过单据号【%s】物料【%s】批次【%s】未查询到明细",
|
||
inputBill.getInputBillNumber(),bar.getMaterialCode(),bar.getBatchNo()));
|
||
}
|
||
// 判断该数据是否已上架完毕
|
||
if (mmInputBillDetail.getPlanQty().compareTo(mmInputBillDetail.getRealQty()) <= 0) {
|
||
throw new ServiceException(RespondEnum.FAILURE, "该物料已上架完,请检验当前数据");
|
||
}
|
||
// 判断是否入库数量是否溢出
|
||
BigDecimal subtract = mmInputBillDetail.getPlanQty().subtract(mmInputBillDetail.getRealQty());
|
||
if (arrVo.getMaterialQty().compareTo(subtract) > 0) {
|
||
throw new ServiceException(RespondEnum.FAILURE, String.format("入库数量【%s】超过剩余待入库数量【%s】",
|
||
arrVo.getMaterialQty().toString(), subtract.toString()));
|
||
}
|
||
mmInputBillDetail.setRealQty(mmInputBillDetail.getRealQty().add(arrVo.getMaterialQty()));
|
||
if (mmInputBillDetail.getPlanQty().compareTo(mmInputBillDetail.getRealQty()) > 0) {
|
||
mmInputBillDetail.setDictStatus(2);
|
||
} else {
|
||
mmInputBillDetail.setDictStatus(3);
|
||
}
|
||
mmInputBillDetail.setUpdatedBy(username);
|
||
mmInputBillDetail.setUpdatedDt(currtime);
|
||
mmInputBillDetail.setModifier(nickName);
|
||
|
||
//添加入库人 入库时间
|
||
if (org.apache.commons.lang3.StringUtils.isNotBlank(mmInputBillDetail.getInputBy())) {
|
||
int data = 0;
|
||
String[] split = mmInputBillDetail.getInputBy().split(",");
|
||
for (int i = 0; i < split.length ; i++) {
|
||
if (split[i].equals(username)) {
|
||
data = 1;
|
||
}
|
||
}
|
||
if (data == 0 && username != null) {
|
||
mmInputBillDetail.setInputBy(mmInputBillDetail.getInputBy()+","+username);
|
||
mmInputBillDetail.setInputDt(currtime);
|
||
}
|
||
} else {
|
||
mmInputBillDetail.setInputBy(username);
|
||
mmInputBillDetail.setInputDt(currtime);
|
||
}
|
||
log.info("入库单明细:"+mmInputBillDetail);
|
||
//修改入库单据明细
|
||
mmInputBillDetailRepository.save(mmInputBillDetail);
|
||
|
||
// 更新到货单入库信息
|
||
MmArriveBillDetail arriveBillDetail = new MmArriveBillDetail();
|
||
Optional<MmArriveBillDetail> byId = arriveBillDetailRepository.findById(mmInputBillDetail.getArriveBillDetailId());
|
||
if (byId.isPresent()) {
|
||
arriveBillDetail = byId.get();
|
||
}
|
||
arriveBillDetail.setInputQty(arriveBillDetail.getInputQty().add(arrVo.getMaterialQty()));
|
||
if (arriveBillDetail.getPlanQty().compareTo(arriveBillDetail.getInputQty()) > 0) {
|
||
arriveBillDetail.setDictStatus(20);
|
||
} else {
|
||
arriveBillDetail.setDictStatus(35);
|
||
}
|
||
arriveBillDetail.setUpdatedDt(currtime);
|
||
arriveBillDetail.setUpdatedBy(username);
|
||
arriveBillDetail.setModifier(nickName);
|
||
arriveBillDetailRepository.save(arriveBillDetail);
|
||
|
||
// 更新库存信息
|
||
R<MaterialDto> materialDtoR = remoteMaterialService.findByMaterialCode(bar.getMaterialCode());
|
||
MaterialDto materialDto = new MaterialDto();
|
||
if (materialDtoR.getCode() == 200) {
|
||
materialDto = materialDtoR.getData();
|
||
}
|
||
MmArriveBill arriveBill = arriveBillRepository.findByArriveBillNumber(bar.getArriveBillNumber());
|
||
SupplierDto supplierDto = new SupplierDto();
|
||
supplierDto.setId(arriveBill.getSupplierId());
|
||
supplierDto.setSupplierCode(arriveBill.getSupplierCode());
|
||
supplierDto.setSupplierName(arriveBill.getSupplierName());
|
||
|
||
CustomerDto customerDto = new CustomerDto();
|
||
customerDto.setCustomerCode(inputBill.getCustomerCode());
|
||
List<CustomerDto> customerDtoList = remoteService.findCustomer(customerDto);
|
||
|
||
StockInVo stockInVo = new StockInVo();
|
||
stockInVo.setMaterialBar(bar.getMaterialBar());
|
||
stockInVo.setBatchNo(bar.getBatchNo());
|
||
stockInVo.setQty(arrVo.getMaterialQty());
|
||
stockInVo.setBillId(inputBill.getId());
|
||
stockInVo.setBillNumber(inputBill.getInputBillNumber());
|
||
stockInVo.setMaterialDto(materialDto);
|
||
stockInVo.setSupplierDto(supplierDto);
|
||
stockInVo.setDictBizType(7);
|
||
stockInVo.setInspectBillNumber(bar.getInspectBillNumber());
|
||
stockInVo.setTargetWarehouseType(10);
|
||
stockInVo.setTargetBaWarehouse(baWareHouseRepository.findByWarehouseCode(inputBill.getWarehouseCode()));
|
||
stockInVo.setFromWarehouseType(10);
|
||
stockInVo.setFromBaWarehouse(baWareHouseRepository.findByWarehouseCode(inputBill.getWarehouseCode()));
|
||
stockInVo.setTargetBaLocation(baLocation.get(0));
|
||
/* stockInVo.setFromBaLocation(baLocation.get(0));*/
|
||
stockInVo.setDictBilltype(30);//单据类型:入库单
|
||
stockInVo.setUserName(username);
|
||
if (customerDtoList.size() > 0) {
|
||
stockInVo.setCustomerDto(customerDtoList.get(0));
|
||
}
|
||
stockService.stockIn(stockInVo, false,false);
|
||
}
|
||
log.warn("上架完成");
|
||
|
||
//查询最新的入库单数据
|
||
MmInputBill mmInputBill = mmInputBillRepository.findByInputBillNumber(vo.getInputBillNumber());
|
||
// 判断入库单是否全部完成
|
||
List<MmInputBillDetail> filter =
|
||
mmInputBill.getItems().stream().filter(detail -> detail.getDictStatus() == 3).collect(Collectors.toList());
|
||
if (filter.size() == mmInputBill.getItems().size()) {
|
||
mmInputBill.setDictStatus(3);
|
||
} else {
|
||
mmInputBill.setDictStatus(2);
|
||
}
|
||
log.warn("审批完成");
|
||
mmInputBill.setUpdatedBy(username);
|
||
mmInputBill.setUpdatedDt(currtime);
|
||
mmInputBill.setModifier(nickName);
|
||
log.warn("入库单完成");
|
||
// 更新入库单状态
|
||
inputBillService.updateBillStatus(mmInputBill);
|
||
}
|
||
|
||
/**
|
||
* 其他入库
|
||
*
|
||
* @param vo 入库数据
|
||
*/
|
||
@Transactional(rollbackFor = {ServiceException.class, RuntimeException.class, Exception.class})
|
||
public void otherInputStockIn(InputStockInVo vo) {
|
||
MmOtherInputBill inputBill = otherInputBillRepository.findByInputBillNumber(vo.getInputBillNumber());
|
||
if (inputBill == null) {
|
||
throw new ServiceException(RespondEnum.FAILURE, "查询相关入库单失败");
|
||
}
|
||
if (inputBill.getWarehouseCode() == null || "".equals(inputBill.getWarehouseCode())) {
|
||
throw new ServiceException(RespondEnum.FAILURE, String.format("请先维护入库单【%s】的入库库区", vo.getInputBillNumber()));
|
||
}
|
||
|
||
String currtime = DateUtil.getCurrentDate();
|
||
String locationCode = vo.getLocationCode();
|
||
List<MmStockDto> stockDtoList = new ArrayList<>();
|
||
|
||
for (InputStockInMaterialBarVo arrVo : vo.getMaterialBarArr()) {
|
||
MaterialBarVo materialBarVo = getDetailByBar(arrVo.getMaterialBar());
|
||
if (!materialBarVo.getIsHikBar() && materialBarVo.getLocationCode() != null) {
|
||
throw new ServiceException(RespondEnum.FAILURE, String.format("上架失败,条码【%s】已上架",
|
||
arrVo.getMaterialBar()));
|
||
}
|
||
|
||
MaterialBarVo bar = getDetailByBar(arrVo.getMaterialBar());
|
||
//添加库存信息
|
||
if (null == bar) {
|
||
return;
|
||
}
|
||
bar.setLocationCode(locationCode);
|
||
BaLocation baLocation = balocationRepository.findByLocationCode(locationCode);
|
||
if (baLocation != null) {
|
||
bar.setLocationId(baLocation.getId());
|
||
}
|
||
bar.setDictStatus(30);
|
||
bar.setUpdatedBy(SecurityUtils.getUsername());
|
||
bar.setUpdatedDt(currtime);
|
||
bar.setInputBillId(inputBill.getId());
|
||
bar.setInputBillNumber(inputBill.getInputBillNumber());
|
||
//materialBarRepository.save(BeanUtil.copyProperties(bar, MmMaterialBar.class));
|
||
|
||
for (MmOtherInputBillDetail item : inputBill.getItems()) {
|
||
if (item.getMaterialCode().equals(bar.getMaterialCode()) && item.getBatchNo().equals(bar.getBatchNo())) {
|
||
if (item.getDictStatus() == 3) {
|
||
throw new ServiceException(RespondEnum.FAILURE, "该物料已上架完,请检验当前数据");
|
||
}
|
||
item.setRealQty(item.getRealQty().add(arrVo.getMaterialQty()));
|
||
if (item.getRealQty().compareTo(item.getPlanQty()) > 0 || item.getRealQty().compareTo(item.getPlanQty()) == 0) {
|
||
item.setDictStatus(3);
|
||
} else {
|
||
item.setDictStatus(2);
|
||
}
|
||
item.setUpdatedBy(SecurityUtils.getUsername());
|
||
item.setUpdatedDt(currtime);
|
||
}
|
||
}
|
||
|
||
// 更新库存信息
|
||
R<MaterialDto> materialDtoR = remoteMaterialService.findByMaterialCode(bar.getMaterialCode());
|
||
MaterialDto materialDto = new MaterialDto();
|
||
if (materialDtoR.getCode() == 200) {
|
||
materialDto = materialDtoR.getData();
|
||
}
|
||
MmArriveBill arriveBill = arriveBillRepository.findByArriveBillNumber(bar.getArriveBillNumber());
|
||
BaWarehouse baWarehouse = new BaWarehouse();
|
||
baWarehouse.setWorkCenterId(inputBill.getWarehouseId());
|
||
baWarehouse.setWarehouseCode(inputBill.getWarehouseCode());
|
||
baWarehouse.setWarehouseName(inputBill.getWarehouseName());
|
||
BaWarehouse baWarehouse2 = new BaWarehouse();
|
||
baWarehouse2.setWarehouseCode("在途");
|
||
baWarehouse2.setWarehouseName("在途");
|
||
BaLocation baLocation2 = new BaLocation();
|
||
baLocation2.setWarehouseCode("在途");
|
||
baLocation2.setWarehouseName("在途");
|
||
|
||
StockInVo stockInVo = new StockInVo();
|
||
stockInVo.setMaterialBar(bar.getMaterialBar());
|
||
stockInVo.setBatchNo(bar.getBatchNo());
|
||
stockInVo.setQty(arrVo.getMaterialQty());
|
||
stockInVo.setBillId(inputBill.getId());
|
||
stockInVo.setBillNumber(inputBill.getInputBillNumber());
|
||
stockInVo.setMaterialDto(materialDto);
|
||
SupplierDto supplierDto = new SupplierDto();
|
||
if (arriveBill != null) {
|
||
supplierDto.setId(arriveBill.getSupplierId());
|
||
supplierDto.setSupplierCode(arriveBill.getSupplierCode());
|
||
supplierDto.setSupplierName(arriveBill.getSupplierName());
|
||
|
||
}
|
||
stockInVo.setSupplierDto(supplierDto);
|
||
stockInVo.setDictBizType(16);
|
||
stockInVo.setInspectBillNumber(bar.getInspectBillNumber());
|
||
stockInVo.setTargetWarehouseType(10);
|
||
stockInVo.setTargetBaWarehouse(baWarehouse);
|
||
stockInVo.setFromBaWarehouse(baWareHouseRepository.findByWarehouseCode("在途"));
|
||
stockInVo.setTargetBaLocation(baLocation);
|
||
stockInVo.setFromBaLocation(balocationRepository.findByLocationCode("在途"));
|
||
stockInVo.setUserName(SecurityUtils.getUsername());
|
||
stockService.stockIn(stockInVo, false,false);
|
||
}
|
||
// 判断入库单是否全部完成
|
||
List<MmOtherInputBillDetail> filter =
|
||
inputBill.getItems().stream().filter(detail -> detail.getDictStatus() == 3).collect(Collectors.toList());
|
||
if (filter.size() == inputBill.getItems().size()) {
|
||
inputBill.setDictStatus(3);
|
||
// 发起审批流程 创建流程实例id
|
||
StartParamsDto startParamsDto = new StartParamsDto();
|
||
startParamsDto.setBizKey(BizKey.CGRK_INSTRUCTION.getKey());
|
||
startParamsDto.setPrimaryKey(inputBill.getId().toString());
|
||
R<String> launchR = activiti6Service.start(startParamsDto);
|
||
if (launchR.getCode() != 200 || launchR.getData() == null || "".equals(launchR.getData())) {
|
||
log.error("创建入库审批流程失败,入库单号{}", inputBill.getInputBillNumber());
|
||
} else {
|
||
String processInstanceId = launchR.getData();
|
||
inputBill.setProcessInstanceId(processInstanceId);
|
||
inputBill.setDictApprovalStatus(WfStatus.WORKING.getValue());
|
||
log.info("创建入库审批流程成功,入库单号{},流程实例ID{}", inputBill.getInputBillNumber(), processInstanceId);
|
||
}
|
||
} else {
|
||
inputBill.setDictStatus(2);
|
||
}
|
||
inputBill.setUpdatedBy(SecurityUtils.getUsername());
|
||
inputBill.setUpdatedDt(currtime);
|
||
otherInputBillRepository.save(inputBill);
|
||
}
|
||
|
||
@Transactional(rollbackFor = {ServiceException.class, RuntimeException.class, Exception.class})
|
||
public List<MaterialBarDto> createExcessPickBar(MaterialBarDto materialBarDto) {
|
||
final List<MaterialBarDto> result = new ArrayList<>();
|
||
MmMaterialBar raw = BeanUtil.copyProperties(materialBarDto, MmMaterialBar.class);
|
||
raw.setMaterialQty(raw.getMaterialQty().subtract(materialBarDto.getExcessQty()));
|
||
materialBarRepository.save(raw);
|
||
|
||
// 新建新条码
|
||
MmMaterialBar newBar = BeanUtil.copyProperties(materialBarDto, MmMaterialBar.class);
|
||
newBar.setId(null);
|
||
newBar.setMaterialBar(newBar.getMaterialBar() + "-1");
|
||
newBar.setMaterialQty(materialBarDto.getExcessQty());
|
||
materialBarRepository.save(newBar);
|
||
|
||
// 创建物料拆分事务
|
||
StockBizDto splitBiz = new StockBizDto();
|
||
splitBiz.setMaterialBar(raw.getMaterialBar());
|
||
splitBiz.setMaterialId(raw.getMaterialId());
|
||
splitBiz.setMaterialCode(raw.getMaterialCode());
|
||
splitBiz.setMaterialName(raw.getMaterialName());
|
||
splitBiz.setMaterialSpec(raw.getMaterialSpec());
|
||
splitBiz.setUnitOfMeasure(raw.getUnitOfMeasure());
|
||
splitBiz.setBatchNo(raw.getBatchNo());
|
||
splitBiz.setQty(raw.getMaterialQty().subtract(materialBarDto.getMaterialQty()));
|
||
splitBiz.setBeforeQty(materialBarDto.getMaterialQty());
|
||
splitBiz.setAfterQty(raw.getMaterialQty());
|
||
splitBiz.setTargetLocationCode(raw.getLocationCode());
|
||
splitBiz.setDictBiztype(37);
|
||
splitBiz.setDictBilltype(40);
|
||
splitBiz.setBillId(materialBarDto.getPickBillId());
|
||
splitBiz.setBillNumber(materialBarDto.getPickBillNumber());
|
||
|
||
// 创建领料退回事务
|
||
StockBizDto pickReturnBiz = new StockBizDto();
|
||
pickReturnBiz.setMaterialBar(newBar.getMaterialBar());
|
||
pickReturnBiz.setMaterialId(newBar.getMaterialId());
|
||
pickReturnBiz.setMaterialCode(newBar.getMaterialCode());
|
||
pickReturnBiz.setMaterialName(newBar.getMaterialName());
|
||
pickReturnBiz.setMaterialSpec(newBar.getMaterialSpec());
|
||
pickReturnBiz.setUnitOfMeasure(newBar.getUnitOfMeasure());
|
||
pickReturnBiz.setBatchNo(raw.getBatchNo());
|
||
pickReturnBiz.setQty(newBar.getMaterialQty());
|
||
pickReturnBiz.setBeforeQty(BigDecimal.ZERO);
|
||
pickReturnBiz.setAfterQty(newBar.getMaterialQty());
|
||
pickReturnBiz.setTargetLocationCode(raw.getLocationCode());
|
||
pickReturnBiz.setDictBiztype(12);
|
||
pickReturnBiz.setDictBilltype(40);
|
||
pickReturnBiz.setBillId(materialBarDto.getPickBillId());
|
||
pickReturnBiz.setBillNumber(materialBarDto.getPickBillNumber());
|
||
|
||
BaLocation baLocation = balocationRepository.findByLocationCode(raw.getLocationCode());
|
||
if (baLocation != null) {
|
||
splitBiz.setTargetLocationId(baLocation.getId());
|
||
splitBiz.setTargetLocationName(baLocation.getLocationName());
|
||
splitBiz.setTargetWarehouseId(baLocation.getWarehouseId());
|
||
splitBiz.setTargetWarehouseCode(baLocation.getWarehouseCode());
|
||
splitBiz.setTargetWarehouseName(baLocation.getWarehouseName());
|
||
pickReturnBiz.setTargetLocationId(baLocation.getId());
|
||
pickReturnBiz.setTargetLocationName(baLocation.getLocationName());
|
||
pickReturnBiz.setTargetWarehouseId(baLocation.getWarehouseId());
|
||
pickReturnBiz.setTargetWarehouseCode(baLocation.getWarehouseCode());
|
||
pickReturnBiz.setTargetWarehouseName(baLocation.getWarehouseName());
|
||
}
|
||
|
||
mmStockBizRepository.save(BeanUtil.copyProperties(splitBiz, MmStockBiz.class));
|
||
mmStockBizRepository.save(BeanUtil.copyProperties(pickReturnBiz, MmStockBiz.class));
|
||
result.add(BeanUtil.copyProperties(raw, MaterialBarDto.class));
|
||
result.add(BeanUtil.copyProperties(newBar, MaterialBarDto.class));
|
||
return result;
|
||
}
|
||
|
||
@Transactional(rollbackFor = {ServiceException.class, RuntimeException.class, Exception.class})
|
||
public List<String> createMaterialBar(ArriveBillAddMaterialBar vo) {
|
||
List<String> existsBarList = new ArrayList<>();
|
||
|
||
String currentDate = DateUtil.getCurrentDate();
|
||
String user = SecurityUtils.getUsername();
|
||
|
||
List<String> materialBarList = vo.getMaterialBarList();
|
||
|
||
if (vo.getBarNo() != materialBarList.size()) {
|
||
throw new ServiceException(RespondEnum.FAILURE, "新增条码数目与传入条码数目不一致");
|
||
}
|
||
Optional<MmArriveBillDetail> optional = arriveBillDetailRepository.findById(vo.getArriveBillDetailId());
|
||
if (!optional.isPresent()) {
|
||
throw new ServiceException(RespondEnum.FAILURE, "查询到货单明细失败");
|
||
}
|
||
MmArriveBillDetail detail = optional.get();
|
||
|
||
List<MmMaterialBar> materialBars = materialBarRepository.findAllByArriveBillDetailId(detail.getId());
|
||
// 已生成数量
|
||
BigDecimal createdQty = BigDecimal.ZERO;
|
||
if (materialBars.size() > 0) {
|
||
createdQty = materialBars.stream().map(MmMaterialBar::getMaterialQty).reduce(BigDecimal.ZERO,
|
||
BigDecimal::add);
|
||
}
|
||
// 欠缺数量
|
||
BigDecimal lackQty = detail.getPlanQty().subtract(createdQty);
|
||
// 生产条码总数
|
||
BigDecimal createdTotalQty = vo.getQty().multiply(new BigDecimal(vo.getBarNo()));
|
||
|
||
if (lackQty.compareTo(createdTotalQty) < 0) {
|
||
throw new ServiceException(RespondEnum.FAILURE, String.format("物料【%s】生成总数【%s】不能超过欠缺数量【%s】",
|
||
detail.getMaterialCode(), createdTotalQty.toString(), lackQty.toString()));
|
||
}
|
||
|
||
Optional<MmArriveBill> billOptional = arriveBillRepository.findById(detail.getArriveBillId());
|
||
if (!billOptional.isPresent()) {
|
||
throw new ServiceException(RespondEnum.FAILURE, "查询到货单失败");
|
||
}
|
||
MmArriveBill arriveBill = billOptional.get();
|
||
|
||
List<MmMaterialBar> barList = new ArrayList<>();
|
||
for (String materialBar : materialBarList) {
|
||
MmMaterialBar existsBar = materialBarRepository.findByMaterialBar(materialBar);
|
||
if (null != existsBar) {
|
||
existsBarList.add("【" + materialBar + "】");
|
||
continue;
|
||
}
|
||
|
||
MmMaterialBar bar = new MmMaterialBar();
|
||
bar.setMaterialBar(materialBar);
|
||
bar.setArriveBillDetailId(detail.getId());
|
||
bar.setArriveBillNumber(detail.getArriveBillNumber());
|
||
bar.setMaterialId(detail.getMaterialId());
|
||
bar.setMaterialCode(detail.getMaterialCode());
|
||
bar.setMaterialName(detail.getMaterialName());
|
||
bar.setMaterialSpec(detail.getMaterialSpec());
|
||
bar.setUnitOfMeasure(detail.getUnitOfMeasure());
|
||
bar.setMaterialQty(vo.getQty());
|
||
bar.setBatchNo(vo.getBatchNo());
|
||
bar.setDictStatus(5);
|
||
bar.setInspectQty(BigDecimal.ZERO);
|
||
bar.setNoGoodQty(BigDecimal.ZERO);
|
||
bar.setIsThereLead(arriveBill.getIsThereLead());
|
||
bar.setCreatedBy(user);
|
||
bar.setCreatedDt(currentDate);
|
||
barList.add(bar);
|
||
}
|
||
if (existsBarList.size() == 0) {
|
||
materialBarRepository.saveAll(barList);
|
||
} else {
|
||
throw new ServiceException(RespondEnum.FAILURE, "条码" + String.join("、", existsBarList) + "已存在,请加大流水码起始");
|
||
}
|
||
return existsBarList;
|
||
}
|
||
|
||
@Transactional(rollbackFor = {ServiceException.class, RuntimeException.class, Exception.class})
|
||
public List<String> createMaterialBarOtherIn(OtherInAddMaterialBar vo) {
|
||
List<String> existsBarList = new ArrayList<>();
|
||
|
||
String currentDate = DateUtil.getCurrentDate();
|
||
String user = SecurityUtils.getUsername();
|
||
|
||
List<String> materialBarList = vo.getMaterialBarList();
|
||
|
||
if (vo.getBarNo() != materialBarList.size()) {
|
||
throw new ServiceException(RespondEnum.FAILURE, "新增条码数目与传入条码数目不一致");
|
||
}
|
||
Optional<MmOtherInputBillDetail> optional = otherInputDetailRepository.findById(vo.getOtherInDtlId());
|
||
if (!optional.isPresent()) {
|
||
throw new ServiceException(RespondEnum.FAILURE, "查询到货单明细失败");
|
||
}
|
||
MmOtherInputBillDetail detail = optional.get();
|
||
detail = otherInputDetailRepository.findByInputBillNumberAndMaterialCode(detail.getInputBillNumber(),
|
||
vo.getMaterialCode());
|
||
if (detail == null) {
|
||
throw new ServiceException(RespondEnum.FAILURE, "明细为空");
|
||
}
|
||
|
||
List<MmMaterialBar> materialBars =
|
||
materialBarRepository.findAllByInputBillNumberAndMaterialCode(detail.getInputBillNumber(),
|
||
detail.getMaterialCode());
|
||
// 已生成数量
|
||
BigDecimal createdQty = BigDecimal.ZERO;
|
||
if (materialBars.size() > 0) {
|
||
createdQty = materialBars.stream().map(MmMaterialBar::getMaterialQty).reduce(BigDecimal.ZERO,
|
||
BigDecimal::add);
|
||
}
|
||
// 欠缺数量
|
||
BigDecimal lackQty = detail.getPlanQty().subtract(createdQty);
|
||
// 生产条码总数
|
||
BigDecimal createdTotalQty = vo.getQty().multiply(new BigDecimal(vo.getBarNo()));
|
||
if (lackQty.compareTo(createdTotalQty) < 0) {
|
||
throw new ServiceException(RespondEnum.FAILURE, String.format("物料【%s】生成总数【%s】不能超过欠缺数量【%s】",
|
||
detail.getMaterialCode(), createdTotalQty.toString(), lackQty.toString()));
|
||
}
|
||
List<MmMaterialBar> barList = new ArrayList<>();
|
||
for (String materialBar : materialBarList) {
|
||
MmMaterialBar existsBar = materialBarRepository.findByMaterialBar(materialBar);
|
||
if (null != existsBar) {
|
||
existsBarList.add("【" + materialBar + "】");
|
||
continue;
|
||
}
|
||
MmMaterialBar bar = new MmMaterialBar();
|
||
bar.setMaterialBar(materialBar);
|
||
bar.setInputBillId(detail.getInputBillId());
|
||
bar.setInputBillNumber(detail.getInputBillNumber());
|
||
bar.setMaterialId(detail.getMaterialId());
|
||
bar.setMaterialCode(detail.getMaterialCode());
|
||
bar.setMaterialName(detail.getMaterialName());
|
||
bar.setMaterialSpec(detail.getMaterialSpec());
|
||
bar.setUnitOfMeasure(detail.getUnitOfMeasure());
|
||
bar.setMaterialQty(vo.getQty());
|
||
bar.setBatchNo(vo.getBatchNo());
|
||
bar.setDictStatus(25);
|
||
bar.setInspectQty(BigDecimal.ZERO);
|
||
bar.setNoGoodQty(BigDecimal.ZERO);
|
||
bar.setCreatedBy(user);
|
||
bar.setCreatedDt(currentDate);
|
||
barList.add(bar);
|
||
}
|
||
if (existsBarList.size() == 0) {
|
||
materialBarRepository.saveAll(barList);
|
||
} else {
|
||
throw new ServiceException(RespondEnum.FAILURE, "条码" + String.join("、", existsBarList) + "已存在,请加大流水码起始");
|
||
}
|
||
return existsBarList;
|
||
}
|
||
|
||
public List<MmMaterialBar> getNoInspectMaterialBarByInspectBillId(Long inspectBillId, Long inspectBillDetailId) {
|
||
List<MmMaterialBar> list = new ArrayList<>();
|
||
|
||
Optional<MmInspectBill> optional = inspectBillRepository.findById(inspectBillId);
|
||
if (!optional.isPresent()) {
|
||
return list;
|
||
}
|
||
|
||
List<MmInspectBillItem> itemList =
|
||
inspectBillItemRepository.findByInspectBillNumber(optional.get().getInspectBillNumber());
|
||
|
||
|
||
List<String> materialBarList = new ArrayList<String>();
|
||
for (MmInspectBillItem mmInspectBillItem : itemList) {
|
||
if (StringUtils.isNotEmpty(mmInspectBillItem.getMaterialBar())) {
|
||
materialBarList.add(mmInspectBillItem.getMaterialBar());
|
||
}
|
||
}
|
||
|
||
Optional<MmInspectBillDetail> optionalDetail = inspectBillDetailRepository.findById(inspectBillDetailId);
|
||
if (!optionalDetail.isPresent()) {
|
||
return list;
|
||
}
|
||
|
||
MmInspectBillDetail inspectBillDetail = optionalDetail.get();
|
||
Long arriveBillDetailId = inspectBillDetail.getArriveBillDetailId();
|
||
String batchNo = inspectBillDetail.getBatchNo();
|
||
if (materialBarList.size() > 0) {
|
||
list = materialBarRepository.findAllByInspectBillIdAndArriveBillDetailIdAndBatchNoAndMaterialBarNotIn(
|
||
inspectBillId, arriveBillDetailId, batchNo, materialBarList);
|
||
} else {
|
||
list = materialBarRepository.findAllByInspectBillIdAndArriveBillDetailIdAndBatchNo(
|
||
inspectBillId, arriveBillDetailId, batchNo);
|
||
}
|
||
return list;
|
||
}
|
||
|
||
@Transactional(rollbackFor = {ServiceException.class, RuntimeException.class, Exception.class})
|
||
public List<String> createMaterialBarProdIn(ProdInAddMaterialBar vo) {
|
||
List<String> existsBarList = new ArrayList<>();
|
||
|
||
String currentDate = DateUtil.getCurrentDate();
|
||
String user = SecurityUtils.getUsername();
|
||
|
||
List<String> materialBarList = vo.getMaterialBarList();
|
||
|
||
if (vo.getBarNo() != materialBarList.size()) {
|
||
throw new ServiceException(RespondEnum.FAILURE, "新增条码数目与传入条码数目不一致");
|
||
}
|
||
Optional<MmProdInBill> byId = prodInBillRepository.findById(vo.getProdInDtlId());
|
||
if (!byId.isPresent()) {
|
||
throw new ServiceException(RespondEnum.FAILURE, "查询到成品入库失败");
|
||
}
|
||
|
||
MmProdInBill mmProdInBill = byId.get();
|
||
List<MmMaterialBar> materialBars =
|
||
materialBarRepository.findAllByInputBillIdAndMaterialCode(vo.getProdInDtlId(),
|
||
vo.getMaterialCode());
|
||
// 已生成数量
|
||
BigDecimal createdQty = BigDecimal.ZERO;
|
||
if (materialBars.size() > 0) {
|
||
createdQty = materialBars.stream().map(MmMaterialBar::getMaterialQty).reduce(BigDecimal.ZERO,
|
||
BigDecimal::add);
|
||
}
|
||
// 欠缺数量
|
||
BigDecimal lackQty = mmProdInBill.getInStockQty().subtract(createdQty);
|
||
// 生产条码总数
|
||
BigDecimal createdTotalQty = vo.getQty().multiply(new BigDecimal(vo.getBarNo()));
|
||
if (lackQty.compareTo(createdTotalQty) < 0) {
|
||
throw new ServiceException(RespondEnum.FAILURE, String.format("物料【%s】生成总数【%s】不能超过欠缺数量【%s】",
|
||
mmProdInBill.getMaterialCode(), createdTotalQty.toString(), lackQty.toString()));
|
||
}
|
||
List<MmMaterialBar> barList = new ArrayList<>();
|
||
for (String materialBar : materialBarList) {
|
||
MmMaterialBar existsBar = materialBarRepository.findByMaterialBar(materialBar);
|
||
if (null != existsBar) {
|
||
existsBarList.add("【" + materialBar + "】");
|
||
continue;
|
||
}
|
||
MmMaterialBar bar = new MmMaterialBar();
|
||
bar.setMaterialBar(materialBar);
|
||
bar.setInputBillId(vo.getProdInDtlId());
|
||
bar.setInputBillNumber(mmProdInBill.getProdInBillNumber());
|
||
bar.setMaterialId(mmProdInBill.getMaterialId());
|
||
bar.setMaterialCode(mmProdInBill.getMaterialCode());
|
||
bar.setMaterialName(mmProdInBill.getMaterialName());
|
||
bar.setMaterialSpec(mmProdInBill.getMaterialSpec());
|
||
bar.setMaterialQty(vo.getQty());
|
||
bar.setBatchNo(vo.getBatchNo());
|
||
bar.setDictStatus(25);
|
||
bar.setInspectQty(BigDecimal.ZERO);
|
||
bar.setNoGoodQty(BigDecimal.ZERO);
|
||
bar.setCreatedBy(user);
|
||
bar.setCreatedDt(currentDate);
|
||
barList.add(bar);
|
||
}
|
||
if (existsBarList.size() == 0) {
|
||
materialBarRepository.saveAll(barList);
|
||
} else {
|
||
throw new ServiceException(RespondEnum.FAILURE, "条码" + String.join("、", existsBarList) + "已存在,请加大流水码起始");
|
||
}
|
||
return existsBarList;
|
||
}
|
||
|
||
@Transactional(rollbackFor = {ServiceException.class, RuntimeException.class, Exception.class})
|
||
public MmInputBill inputStockInSync(InputStockInDto vo) {
|
||
MmInputBill inputBill = mmInputBillRepository.findByInputBillNumber(vo.getInputBillNumber());
|
||
log.info("立体库入库上架入库单数据:" + JSONObject.toJSONString(vo));
|
||
if (inputBill == null) {
|
||
throw new ServiceException(RespondEnum.FAILURE, "查询相关入库单失败");
|
||
}
|
||
if (inputBill.getWarehouseCode() == null || "".equals(inputBill.getWarehouseCode())) {
|
||
throw new ServiceException(RespondEnum.FAILURE, String.format("请先维护入库单【%s】的入库库区", vo.getInputBillNumber()));
|
||
}
|
||
String currtime = DateUtil.getCurrentDate();
|
||
String username = SecurityUtils.getUsername();
|
||
String nickName = remoteService.getNickName(username);
|
||
List<BaLocationRecommend> byWarehouseCode = balocationRecommendRepository.findByWarehouseCode(inputBill.getWarehouseCode());
|
||
if (byWarehouseCode.size() <= 0) {
|
||
throw new ServiceException(RespondEnum.FAILURE, String.format("根据仓库编码【%s】未找到库位",inputBill.getWarehouseCode()));
|
||
}
|
||
String locationCode = byWarehouseCode.get(0).getLocationCode();
|
||
for (InputStockInMaterialBarDto arrVo : vo.getMaterialBarArr()) {
|
||
MaterialBarVo materialBarVo = getDetailByBar(arrVo.getMaterialBar());
|
||
if (!materialBarVo.getIsHikBar() && materialBarVo.getLocationCode() != null) {
|
||
throw new ServiceException(RespondEnum.FAILURE, String.format("上架失败,条码【%s】已上架",
|
||
arrVo.getMaterialBar()));
|
||
}
|
||
MaterialBarVo bar = getDetailByBar(arrVo.getMaterialBar());
|
||
//添加库存信息
|
||
if (null == bar) {
|
||
return null;
|
||
}
|
||
bar.setLocationCode(locationCode);
|
||
List<BaLocation> baLocation = balocationRepository.findAllByLocationCode(locationCode);
|
||
if (baLocation != null) {
|
||
bar.setLocationId(baLocation.get(0).getId());
|
||
}
|
||
bar.setDictStatus(30);
|
||
bar.setUpdatedBy(username);
|
||
bar.setUpdatedDt(currtime);
|
||
bar.setInputBillId(inputBill.getId());
|
||
bar.setInputBillNumber(inputBill.getInputBillNumber());
|
||
//materialBarRepository.save(BeanUtil.copyProperties(bar, MmMaterialBar.class));
|
||
for (MmInputBillDetail item : inputBill.getItems()) {
|
||
if (item.getMaterialCode().equals(bar.getMaterialCode())
|
||
&& item.getBatchNo().equals(bar.getBatchNo())) {
|
||
// 判断该数据是否已上架完毕
|
||
if (item.getPlanQty().compareTo(item.getRealQty()) <= 0) {
|
||
throw new ServiceException(RespondEnum.FAILURE, "该物料已上架完,请检验当前数据");
|
||
}
|
||
// 判断是否入库数量是否溢出
|
||
BigDecimal subtract = item.getPlanQty().subtract(item.getRealQty());
|
||
if (arrVo.getMaterialQty().compareTo(subtract) > 0) {
|
||
throw new ServiceException(RespondEnum.FAILURE, String.format("入库数量【%s】超过剩余待入库数量【%s】",
|
||
arrVo.getMaterialQty().toString(), subtract.toString()));
|
||
}
|
||
item.setRealQty(item.getRealQty().add(arrVo.getMaterialQty()));
|
||
if (item.getPlanQty().compareTo(item.getRealQty()) > 0) {
|
||
item.setDictStatus(2);
|
||
} else {
|
||
item.setDictStatus(3);
|
||
}
|
||
item.setUpdatedBy(username);
|
||
item.setUpdatedDt(currtime);
|
||
item.setModifier(nickName);
|
||
|
||
//添加入库人 入库时间
|
||
if (org.apache.commons.lang3.StringUtils.isNotBlank(item.getInputBy())) {
|
||
int data = 0;
|
||
String[] split = item.getInputBy().split(",");
|
||
for (int i = 0; i < split.length ; i++) {
|
||
if (split[i].equals(username)) {
|
||
data = 1;
|
||
}
|
||
}
|
||
if (data == 0 && username != null) {
|
||
item.setInputBy(item.getInputBy()+","+username);
|
||
item.setInputDt(currtime);
|
||
}
|
||
} else {
|
||
item.setInputBy(username);
|
||
item.setInputDt(currtime);
|
||
}
|
||
|
||
// 更新到货单入库信息
|
||
MmArriveBillDetail arriveBillDetail = new MmArriveBillDetail();
|
||
Optional<MmArriveBillDetail> byId = arriveBillDetailRepository.findById(item.getArriveBillDetailId());
|
||
if (byId.isPresent()) {
|
||
arriveBillDetail = byId.get();
|
||
}
|
||
arriveBillDetail.setInputQty(arriveBillDetail.getInputQty().add(arrVo.getMaterialQty()));
|
||
if (arriveBillDetail.getPlanQty().compareTo(arriveBillDetail.getInputQty()) > 0) {
|
||
arriveBillDetail.setDictStatus(20);
|
||
} else {
|
||
arriveBillDetail.setDictStatus(35);
|
||
}
|
||
arriveBillDetail.setUpdatedDt(currtime);
|
||
arriveBillDetail.setUpdatedBy(username);
|
||
arriveBillDetail.setModifier(nickName);
|
||
arriveBillDetailRepository.save(arriveBillDetail);
|
||
break;
|
||
}
|
||
}
|
||
// 更新库存信息
|
||
R<MaterialDto> materialDtoR = remoteMaterialService.findByMaterialCode(bar.getMaterialCode());
|
||
MaterialDto materialDto = new MaterialDto();
|
||
if (materialDtoR.getCode() == 200) {
|
||
materialDto = materialDtoR.getData();
|
||
}
|
||
MmArriveBill arriveBill = arriveBillRepository.findByArriveBillNumber(bar.getArriveBillNumber());
|
||
SupplierDto supplierDto = new SupplierDto();
|
||
supplierDto.setId(arriveBill.getSupplierId());
|
||
supplierDto.setSupplierCode(arriveBill.getSupplierCode());
|
||
supplierDto.setSupplierName(arriveBill.getSupplierName());
|
||
BaWarehouse baWarehouse2 = new BaWarehouse();
|
||
baWarehouse2.setWarehouseCode("虚拟");
|
||
baWarehouse2.setWarehouseName("虚拟");
|
||
BaLocation baLocation2 = new BaLocation();
|
||
baLocation2.setWarehouseCode("虚拟");
|
||
baLocation2.setWarehouseName("虚拟");
|
||
|
||
CustomerDto customerDto = new CustomerDto();
|
||
customerDto.setCustomerCode(inputBill.getCustomerCode());
|
||
List<CustomerDto> customerDtoList = remoteService.findCustomer(customerDto);
|
||
|
||
StockInVo stockInVo = new StockInVo();
|
||
stockInVo.setMaterialBar(bar.getMaterialBar());
|
||
stockInVo.setBatchNo(bar.getBatchNo());
|
||
stockInVo.setQty(arrVo.getMaterialQty());
|
||
stockInVo.setBillId(inputBill.getId());
|
||
stockInVo.setBillNumber(inputBill.getInputBillNumber());
|
||
stockInVo.setMaterialDto(materialDto);
|
||
stockInVo.setSupplierDto(supplierDto);
|
||
stockInVo.setDictBizType(7);
|
||
stockInVo.setInspectBillNumber(bar.getInspectBillNumber());
|
||
stockInVo.setTargetWarehouseType(10);
|
||
stockInVo.setTargetBaWarehouse(baWareHouseRepository.findByWarehouseCode(inputBill.getWarehouseCode()));
|
||
stockInVo.setFromWarehouseType(10);
|
||
stockInVo.setFromBaWarehouse(baWarehouse2);
|
||
stockInVo.setTargetBaLocation(baLocation.get(0));
|
||
stockInVo.setFromBaLocation(baLocation2);
|
||
if (customerDtoList.size() > 0) {
|
||
stockInVo.setCustomerDto(customerDtoList.get(0));
|
||
}
|
||
stockService.stockIn(stockInVo, false,true);
|
||
}
|
||
log.warn("立体库上架完成");
|
||
// 判断入库单是否全部完成
|
||
List<MmInputBillDetail> filter =
|
||
inputBill.getItems().stream().filter(detail -> detail.getDictStatus() == 3).collect(Collectors.toList());
|
||
if (filter.size() == inputBill.getItems().size()) {
|
||
inputBill.setDictStatus(3);
|
||
/* // 发起审批流程 创建流程实例id
|
||
StartParamsDto startParamsDto = new StartParamsDto();
|
||
startParamsDto.setBizKey(BizKey.CGRK_INSTRUCTION.getKey());
|
||
startParamsDto.setPrimaryKey(inputBill.getId().toString());
|
||
R<String> launchR = activiti6Service.start(startParamsDto);
|
||
if (launchR.getCode() != 200 || launchR.getData() == null || "".equals(launchR.getData())) {
|
||
log.error("创建入库审批流程失败,入库单号{}", inputBill.getInputBillNumber());
|
||
} else {
|
||
String processInstanceId = launchR.getData();
|
||
inputBill.setProcessInstanceId(processInstanceId);
|
||
inputBill.setDictApprovalStatus(WfStatus.WORKING.getValue());
|
||
log.info("创建入库审批流程成功,入库单号{},流程实例ID{}", inputBill.getInputBillNumber(), processInstanceId);
|
||
}*/
|
||
|
||
R<Integer> integerR = remoteService.compareTimeApi(inputBill.getCreatedDt());
|
||
Integer data = integerR.getData();
|
||
if (data != -1) {
|
||
//入库单完成,发起ERP
|
||
kafKaService.sendInputToERP(inputBill,SecurityUtils.getUsername());
|
||
}
|
||
} else {
|
||
inputBill.setDictStatus(2);
|
||
}
|
||
log.warn("立体库审批完成");
|
||
inputBill.setInputMode("立体库入库");
|
||
inputBill.setUpdatedBy(username);
|
||
inputBill.setUpdatedDt(currtime);
|
||
inputBill.setModifier(nickName);
|
||
|
||
mmInputBillRepository.save(inputBill);
|
||
log.warn("立体库入库单完成");
|
||
// 更新入库单状态
|
||
return inputBillService.updateBillStatus(inputBill);
|
||
}
|
||
}
|