202 lines
9.8 KiB
Plaintext
202 lines
9.8 KiB
Plaintext
package com.cmeim.stock.service;
|
|
|
|
import com.cmeim.basic.api.dto.MaterialDto;
|
|
import com.cmeim.biz.po.MmInputBill;
|
|
import com.cmeim.biz.po.MmMaterialBar;
|
|
import com.cmeim.biz.po.MmOtherInputBill;
|
|
import com.cmeim.biz.repository.MmInputBillRepository;
|
|
import com.cmeim.biz.repository.MmMaterialBarRepository;
|
|
import com.cmeim.biz.repository.MmOtherInputBillRepository;
|
|
import com.cmeim.biz.service.api.CurrencyService;
|
|
import com.cmeim.common.core.exception.ServiceException;
|
|
import com.cmeim.common.core.web.controller.GenericController;
|
|
import com.cmeim.common.core.web.domain.Respond;
|
|
import com.cmeim.common.core.web.domain.RespondEnum;
|
|
import com.cmeim.stock.po.BaLocation;
|
|
import com.cmeim.stock.po.BaWarehouse;
|
|
import com.cmeim.stock.po.MmStock;
|
|
import com.cmeim.stock.repository.BaWareHouseRepository;
|
|
import com.cmeim.stock.repository.BalocationRepository;
|
|
import com.cmeim.stock.repository.MmStockAreaRepository;
|
|
import com.cmeim.stock.repository.MmStockBizRepository;
|
|
import com.cmeim.stock.repository.MmStockRepository;
|
|
import com.cmeim.stock.service.api.MaterialBarService;
|
|
import com.cmeim.stock.service.api.StockService;
|
|
import com.cmeim.stock.vo.stock.CreateBar;
|
|
import com.cmeim.stock.vo.stock.StockInVo;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
@Service
|
|
@Slf4j
|
|
@Transactional(rollbackFor = {ServiceException.class, RuntimeException.class, Exception.class})
|
|
public class BarSplitService extends GenericController {
|
|
@Autowired
|
|
private MmStockRepository mmStockRepository;
|
|
@Autowired
|
|
private MmStockAreaRepository mmStockAreaRepository;
|
|
@Autowired
|
|
private MmStockBizRepository mmStockBizRepository;
|
|
@Autowired
|
|
private RemoteService remoteService;
|
|
@Autowired
|
|
private MmMaterialBarRepository materialBarRepository;
|
|
@Autowired
|
|
private MaterialBarService materialBarService;
|
|
@Autowired
|
|
private CurrencyService currencyService;
|
|
|
|
@Autowired
|
|
private BalocationRepository balocationRepository;
|
|
@Autowired
|
|
private BaWareHouseRepository baWareHouseRepository;
|
|
@Autowired
|
|
private StockService stockService;
|
|
@Autowired
|
|
private MmInputBillRepository mmInputBillRepository;
|
|
@Autowired
|
|
private MmOtherInputBillRepository mmOtherInputBillRepository;
|
|
|
|
@Transactional
|
|
public Respond BarSplit(String materialBar, BigDecimal qty) {
|
|
|
|
MmMaterialBar byMaterialBar1 = materialBarRepository.findByMaterialBar(materialBar);
|
|
if (byMaterialBar1 == null) {
|
|
throw new ServiceException(RespondEnum.FAILURE,"条码不存在");
|
|
}
|
|
if (byMaterialBar1.getMaterialQty().compareTo(qty) <= 0) {
|
|
throw new ServiceException(
|
|
RespondEnum.FAILURE, String.format(
|
|
"拆分数量【%s】大于等于条码数量,无法进行物料拆分",qty,byMaterialBar1.getMaterialQty()));
|
|
}
|
|
List<MmMaterialBar> bar = new ArrayList<>();
|
|
Integer integer = currencyService.selectStockSaveType(
|
|
byMaterialBar1.getMaterialCode(),null, byMaterialBar1.getWarehouseCode());
|
|
if (integer == 2) {
|
|
throw new ServiceException(RespondEnum.FAILURE,"请维护管理模式再进行拆分");
|
|
}
|
|
if (integer == 1) {
|
|
MmMaterialBar byMaterialBar = materialBarRepository.findByMaterialBar(materialBar);
|
|
CreateBar createBar = new CreateBar();
|
|
createBar.setMaterialBar(materialBar);
|
|
createBar.setNewQty(qty);
|
|
createBar.setOldQty(byMaterialBar.getMaterialQty());
|
|
createBar.setPrefix("1");
|
|
createBar.setBarDictType(37);
|
|
MmMaterialBar mmMaterialBar = materialBarService.splitMaterialBar(createBar);
|
|
|
|
if (com.cmeim.common.core.utils.StringUtils.isNotBlank(byMaterialBar.getInputBillNumber())) {
|
|
getMaterialBarSplit(byMaterialBar);
|
|
}
|
|
|
|
if (com.cmeim.common.core.utils.StringUtils.isNotBlank(byMaterialBar.getWarehouseCode())) {
|
|
BaWarehouse baWarehouse2 = baWareHouseRepository.findByWarehouseCode(byMaterialBar.getWarehouseCode());
|
|
if (com.cmeim.common.core.utils.StringUtils.isNotBlank(baWarehouse2.getCustomerAbbreviation())) {
|
|
byMaterialBar.setCustomerAbbreviation(baWarehouse2.getCustomerAbbreviation());
|
|
}
|
|
}
|
|
if (com.cmeim.common.core.utils.StringUtils.isNotBlank(mmMaterialBar.getInputBillNumber())) {
|
|
getMaterialBarSplit(mmMaterialBar);
|
|
}
|
|
|
|
if (com.cmeim.common.core.utils.StringUtils.isNotBlank(mmMaterialBar.getWarehouseCode())) {
|
|
BaWarehouse baWarehouse3 = baWareHouseRepository.findByWarehouseCode(mmMaterialBar.getWarehouseCode());
|
|
if (com.cmeim.common.core.utils.StringUtils.isNotBlank(baWarehouse3.getCustomerAbbreviation())) {
|
|
mmMaterialBar.setCustomerAbbreviation(baWarehouse3.getCustomerAbbreviation());
|
|
}
|
|
}
|
|
bar.add(byMaterialBar);
|
|
bar.add(mmMaterialBar);
|
|
return buildSuccess(bar);
|
|
}
|
|
if (integer == 0) {
|
|
MmStock mmStock = mmStockRepository.findByMaterialBar(materialBar);
|
|
if (mmStock == null) {
|
|
return buildFailure("该条码在库存中不存在");
|
|
}
|
|
if (mmStock.getQty().compareTo(qty) != 1) {
|
|
return buildFailure("拆分数量大于条码数量,无法拆分");
|
|
}
|
|
MmMaterialBar byMaterialBar = materialBarRepository.findByMaterialBar(materialBar);
|
|
CreateBar createBar = new CreateBar();
|
|
createBar.setMaterialBar(materialBar);
|
|
createBar.setNewQty(qty);
|
|
createBar.setOldQty(byMaterialBar.getMaterialQty());
|
|
createBar.setPrefix("1");
|
|
createBar.setBarDictType(37);
|
|
MmMaterialBar mmMaterialBar = materialBarService.splitMaterialBar(createBar);
|
|
|
|
StockInVo stockInVo = new StockInVo();
|
|
stockInVo.setMaterialBar(materialBar);
|
|
MaterialDto materialDto = remoteService.findByMaterialCode(mmStock.getMaterialCode());
|
|
stockInVo.setMaterialDto(materialDto);
|
|
stockInVo.setBatchNo(mmStock.getBatchNo());
|
|
stockInVo.setQty(mmStock.getQty());
|
|
BaLocation baLocation = balocationRepository.findByLocationCode(mmStock.getLocationCode());
|
|
stockInVo.setTargetBaLocation(baLocation);
|
|
stockInVo.setFromBaLocation(baLocation);
|
|
BaWarehouse baWarehouse = baWareHouseRepository.findByWarehouseCode(mmStock.getWarehouseCode());
|
|
stockInVo.setTargetBaWarehouse(baWarehouse);
|
|
BaWarehouse baWarehouse1 = baWareHouseRepository.findByWarehouseCode(mmStock.getWarehouseCode());
|
|
stockInVo.setFromBaWarehouse(baWarehouse1);
|
|
stockInVo.setDictBizType(37); //:物料拆分
|
|
stockService.stockTransformation(stockInVo);
|
|
if (com.cmeim.common.core.utils.StringUtils.isNotBlank(byMaterialBar.getInputBillNumber())) {
|
|
getMaterialBarSplit(byMaterialBar);
|
|
}
|
|
|
|
if (com.cmeim.common.core.utils.StringUtils.isNotBlank(byMaterialBar.getWarehouseCode())) {
|
|
BaWarehouse baWarehouse2 = baWareHouseRepository.findByWarehouseCode(byMaterialBar.getWarehouseCode());
|
|
if (com.cmeim.common.core.utils.StringUtils.isNotBlank(baWarehouse2.getCustomerAbbreviation())) {
|
|
byMaterialBar.setCustomerAbbreviation(baWarehouse2.getCustomerAbbreviation());
|
|
}
|
|
}
|
|
|
|
if (com.cmeim.common.core.utils.StringUtils.isNotBlank(mmMaterialBar.getInputBillNumber())) {
|
|
getMaterialBarSplit(mmMaterialBar);
|
|
}
|
|
|
|
if (com.cmeim.common.core.utils.StringUtils.isNotBlank(mmMaterialBar.getWarehouseCode())) {
|
|
BaWarehouse baWarehouse3 = baWareHouseRepository.findByWarehouseCode(mmMaterialBar.getWarehouseCode());
|
|
if (com.cmeim.common.core.utils.StringUtils.isNotBlank(baWarehouse3.getCustomerAbbreviation())) {
|
|
mmMaterialBar.setCustomerAbbreviation(baWarehouse3.getCustomerAbbreviation());
|
|
}
|
|
}
|
|
bar.add(byMaterialBar);
|
|
bar.add(mmMaterialBar);
|
|
return buildSuccess(bar);
|
|
}
|
|
return buildSuccess();
|
|
}
|
|
|
|
public MmMaterialBar getMaterialBarSplit(MmMaterialBar mmMaterialBar) {
|
|
if("Q".equals(mmMaterialBar.getInputBillNumber().substring(0,1))) {
|
|
MmOtherInputBill byInputBillNumber = mmOtherInputBillRepository.findByInputBillNumber(
|
|
mmMaterialBar.getInputBillNumber());
|
|
if (byInputBillNumber != null) {
|
|
BaWarehouse baWarehouse = baWareHouseRepository.findByWarehouseCode(byInputBillNumber.getWarehouseCode());
|
|
if (com.cmeim.common.core.utils.StringUtils.isNotBlank(baWarehouse.getCustomerAbbreviation())) {
|
|
mmMaterialBar.setCustomerAbbreviation(baWarehouse.getCustomerAbbreviation());
|
|
}
|
|
}
|
|
}
|
|
if("C".equals(mmMaterialBar.getInputBillNumber().substring(0,1))) {
|
|
MmInputBill byInputBillNumber = mmInputBillRepository.findByInputBillNumber(
|
|
mmMaterialBar.getInputBillNumber());
|
|
if (byInputBillNumber != null) {
|
|
BaWarehouse baWarehouse = baWareHouseRepository.findByWarehouseCode(byInputBillNumber.getWarehouseCode());
|
|
if (com.cmeim.common.core.utils.StringUtils.isNotBlank(baWarehouse.getCustomerAbbreviation())) {
|
|
mmMaterialBar.setCustomerAbbreviation(baWarehouse.getCustomerAbbreviation());
|
|
}
|
|
}
|
|
}
|
|
return mmMaterialBar;
|
|
}
|
|
}
|