|
|
@ -9,6 +9,8 @@ import com.win.framework.common.pojo.PageResult; |
|
|
|
import com.win.framework.dict.core.util.DictFrameworkUtils; |
|
|
|
import com.win.module.infra.api.trends.TrendsApi; |
|
|
|
import com.win.module.infra.enums.TrendsTypeEnum; |
|
|
|
import com.win.module.system.api.serialnumber.SerialNumberApi; |
|
|
|
import com.win.module.system.enums.serialNumber.RuleCodeEnum; |
|
|
|
import com.win.module.wms.controller.purchasePlan.vo.*; |
|
|
|
import com.win.module.wms.convert.purchasePlan.PurchasePlanDetailConvert; |
|
|
|
import com.win.module.wms.convert.purchasePlan.PurchasePlanMainConvert; |
|
|
@ -16,21 +18,24 @@ import com.win.module.wms.dal.dataobject.businesstype.BusinesstypeDO; |
|
|
|
import com.win.module.wms.dal.dataobject.itembasic.ItembasicDO; |
|
|
|
import com.win.module.wms.dal.dataobject.purchasePlan.PurchasePlanDetailDO; |
|
|
|
import com.win.module.wms.dal.dataobject.purchasePlan.PurchasePlanMainDO; |
|
|
|
import com.win.module.wms.dal.dataobject.requestsetting.RequestsettingDO; |
|
|
|
import com.win.module.wms.dal.dataobject.shift.ShiftDO; |
|
|
|
import com.win.module.wms.dal.dataobject.supplier.SupplierDO; |
|
|
|
import com.win.module.wms.dal.dataobject.supplieritem.SupplieritemDO; |
|
|
|
import com.win.module.wms.dal.mysql.purchasePlan.PurchasePlanDetailMapper; |
|
|
|
import com.win.module.wms.dal.mysql.purchasePlan.PurchasePlanMainMapper; |
|
|
|
import com.win.module.wms.enums.DictTypeConstants; |
|
|
|
import com.win.module.wms.enums.plan.PlanStatusEnum; |
|
|
|
import com.win.module.wms.enums.plan.PurchasePlanStatusEnum; |
|
|
|
import com.win.module.wms.enums.request.RequestStatusEnum; |
|
|
|
import com.win.module.wms.service.itembasic.ItembasicService; |
|
|
|
import com.win.module.wms.service.requestsetting.RequestsettingService; |
|
|
|
import com.win.module.wms.service.shift.ShiftService; |
|
|
|
import com.win.module.wms.service.supplier.SupplierService; |
|
|
|
import com.win.module.wms.service.supplieritem.SupplieritemService; |
|
|
|
import com.win.module.wms.util.JobUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport; |
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
@ -66,24 +71,42 @@ public class PurchasePlanMainServiceImpl implements PurchasePlanMainService { |
|
|
|
private JobUtils jobUtils; |
|
|
|
@Resource |
|
|
|
private TrendsApi trendsApi; |
|
|
|
@Resource |
|
|
|
private SerialNumberApi serialNumberApi; |
|
|
|
@Resource |
|
|
|
private SupplierService supplierService; |
|
|
|
@Resource |
|
|
|
private RequestsettingService requestsettingService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public Long createPurchasePlanMain(PurchasePlanMainCreateReqVO createReqVO) { |
|
|
|
// 插入
|
|
|
|
PurchasePlanMainDO purchasePlanMain = PurchasePlanMainConvert.INSTANCE.convert(createReqVO); |
|
|
|
purchasePlanMain.setCreateTime(LocalDateTime.now()); |
|
|
|
purchasePlanMainMapper.insert(purchasePlanMain); |
|
|
|
// 返回
|
|
|
|
return purchasePlanMain.getId(); |
|
|
|
// 插入主表
|
|
|
|
BusinesstypeDO businesstypeDO = jobUtils.selectDocumentSettingFromBusinessType("PurchasePlan"); |
|
|
|
createReqVO.setBusinessType(businesstypeDO.getCode()); |
|
|
|
String number = serialNumberApi.generateCode(RuleCodeEnum.PURCHASE_PLAN.getCode()); |
|
|
|
createReqVO.setNumber(number); |
|
|
|
createReqVO.setCreateTime(LocalDateTime.now()); |
|
|
|
PurchasePlanMainDO purchasePlanMainDO = validatorToCreate(createReqVO); |
|
|
|
//调用自动执行方法
|
|
|
|
if (RequestStatusEnum.HANDLING.getCode().equals(purchasePlanMainDO.getStatus())) { |
|
|
|
} |
|
|
|
trendsApi.createTrends(purchasePlanMainDO.getId(), "PurchaseOrder", "增加了采购订单", TrendsTypeEnum.CREATE); |
|
|
|
return purchasePlanMainDO.getId(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void updatePurchasePlanMain(PurchasePlanMainUpdateReqVO updateReqVO) { |
|
|
|
// 校验存在
|
|
|
|
public Long updatePurchasePlanMain(PurchasePlanMainUpdateReqVO updateReqVO) { |
|
|
|
RequestsettingDO requestsettingDO = requestsettingDO = requestsettingService.selectRequestsettingExist("PurchasePlan"); |
|
|
|
// 校验存在,如子表需要也再此校验
|
|
|
|
validatePurchasePlanMainExists(updateReqVO.getId()); |
|
|
|
// 更新
|
|
|
|
PurchasePlanMainDO updateObj = PurchasePlanMainConvert.INSTANCE.convert(updateReqVO); |
|
|
|
purchasePlanMainMapper.updateById(updateObj); |
|
|
|
// 更新主表
|
|
|
|
PurchasePlanMainDO purchasePlanMainDO = validatorToUpdate(updateReqVO); |
|
|
|
if (RequestStatusEnum.HANDLING.getCode().equals(purchasePlanMainDO.getStatus())) { |
|
|
|
} |
|
|
|
trendsApi.createTrends(requestsettingDO.getId(), "PurchaseclaimRequest", "增加了采购索赔申请", TrendsTypeEnum.CREATE); |
|
|
|
return purchasePlanMainDO.getId(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -154,89 +177,153 @@ public class PurchasePlanMainServiceImpl implements PurchasePlanMainService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//主表校验 校验供应商基础信息
|
|
|
|
private SupplierDO validatorShiftExist(String supplierCode) { |
|
|
|
return supplierService.selectSupplier(supplierCode); |
|
|
|
} |
|
|
|
|
|
|
|
//子表校验 校验供应商基础信息
|
|
|
|
private void validatorItembasic(String itemCode) { |
|
|
|
itembasicService.selectItembasic(itemCode); |
|
|
|
} |
|
|
|
|
|
|
|
//子表校验 校验供应商物品
|
|
|
|
private SupplieritemDO validatorSupplierItemExist(String supplierCode, String itemCode) { |
|
|
|
return supplieritemService.selectSupplierItemExist(supplierCode, itemCode); |
|
|
|
} |
|
|
|
|
|
|
|
//校验主表公共方法(适用于新增/修改)
|
|
|
|
private PurchasePlanMainDO validatorMainMethod(PurchasePlanMainBaseVO baseVO) { |
|
|
|
PurchasePlanMainDO mainDo = PurchasePlanMainConvert.INSTANCE.convert(baseVO); |
|
|
|
SupplierDO supplierDO = this.validatorShiftExist(mainDo.getSupplierCode()); |
|
|
|
if (supplierDO == null) { |
|
|
|
throw exception(STDCOSTPRICE_SUPPLIER_CODE_NOT_EXISTS); |
|
|
|
} |
|
|
|
mainDo.setStatus(DictFrameworkUtils.parseDictDataValue(DictTypeConstants.REQUEST_STATUS, "新增")); |
|
|
|
return mainDo; |
|
|
|
} |
|
|
|
|
|
|
|
//校验子表公共方法(适用于新增/修改)
|
|
|
|
private void validatorDetailMethod(PurchasePlanDetailDO detailDo, PurchasePlanMainDO mainDo) { |
|
|
|
this.validatorItembasic(detailDo.getItemCode()); |
|
|
|
this.validatorSupplierItemExist(mainDo.getSupplierCode(),detailDo.getItemCode()); |
|
|
|
} |
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public List<PurchasePlanMainImportErrorVO> importPurchasePlanMainList(List<PurchasePlanMainCreateReqVO> datas, Integer mode, boolean updatePart) { |
|
|
|
if (CollUtil.isEmpty(datas)) { |
|
|
|
throw exception(PURCHASECLAIM_REQUEST_IMPORT_LIST_IS_EMPTY); |
|
|
|
} |
|
|
|
List<PurchasePlanMainImportErrorVO> errorList = new ArrayList<>(); |
|
|
|
datas.forEach(createReqVO -> { |
|
|
|
// 校验,判断是否有不符合的原因,并加入errorList,如果主表则所有子表都加入errorList
|
|
|
|
String messageMain = ""; |
|
|
|
//主表的验证
|
|
|
|
//校验供应商基础信息
|
|
|
|
try { |
|
|
|
ShiftDO shiftDO = shiftService.selectShiftExist(createReqVO.getSupplierCode()); |
|
|
|
BeanUtils.copyProperties(createReqVO, shiftDO); |
|
|
|
} catch (ServiceException ex) { |
|
|
|
messageMain += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
//子表的验证
|
|
|
|
for (PurchasePlanMainCreateReqVO createReqVO : datas) { |
|
|
|
PurchasePlanMainDO mainDo = PurchasePlanMainConvert.INSTANCE.convert(createReqVO); |
|
|
|
String messageMain = validatorPurchasePlanMainImport(mainDo); |
|
|
|
List<PurchasePlanDetailCreateReqVO> subList = createReqVO.getSubList(); |
|
|
|
List<PurchasePlanDetailDO> subDOList = PurchasePlanDetailConvert.INSTANCE.convertList03(subList); |
|
|
|
for (PurchasePlanDetailDO purchasePlanDetailDO : subDOList) { |
|
|
|
String messageDetail = ""; |
|
|
|
// 校验物品基础信息
|
|
|
|
try { |
|
|
|
ItembasicDO itembasicDO = itembasicService.selectItembasic(purchasePlanDetailDO.getItemCode()); |
|
|
|
if (itembasicDO.getUom() != purchasePlanDetailDO.getUom()) { |
|
|
|
messageDetail += "计量单位" + itembasicDO.getUom() + "错误,应该是" + purchasePlanDetailDO.getUom() + ","; |
|
|
|
} |
|
|
|
// purchasePlanDetailDO.setProjectCode(itembasicDO.getCode());
|
|
|
|
} catch (ServiceException ex) { |
|
|
|
messageDetail += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
// 校验供应商物品
|
|
|
|
try { |
|
|
|
SupplieritemDO supplieritemDO = supplieritemService.selectSupplierItemExist(createReqVO.getSupplierCode(), purchasePlanDetailDO.getItemCode()); |
|
|
|
} catch (ServiceException ex) { |
|
|
|
messageDetail += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
|
|
|
|
PurchasePlanDetailCreateReqVO purchasePlanDetailCreateReqVO = PurchasePlanDetailConvert.INSTANCE.convert1(purchasePlanDetailDO); |
|
|
|
PurchasePlanMainImportErrorVO importVO = PurchasePlanDetailConvert.INSTANCE.convert(createReqVO, purchasePlanDetailCreateReqVO); |
|
|
|
//进行子表的错误统计
|
|
|
|
//主表没有错误 写入库里
|
|
|
|
if (!messageMain.equals("") || !messageDetail.equals("")) { |
|
|
|
importVO.setImportStatus("失败"); |
|
|
|
// 是否有错误数据
|
|
|
|
boolean flag = true; |
|
|
|
for (PurchasePlanDetailDO detailDO : subDOList) { |
|
|
|
String messageDetail = validatorPurchasePlanDetailImport(detailDO, mainDo); |
|
|
|
if (!messageMain.isEmpty() || messageDetail.isEmpty()) { |
|
|
|
PurchasePlanMainImportErrorVO importErrorVO = PurchasePlanDetailConvert.INSTANCE.convert(createReqVO, detailDO); |
|
|
|
importErrorVO.setImportStatus("失败"); |
|
|
|
messageMain = messageMain + messageDetail; |
|
|
|
importVO.setImportRemark(messageMain.substring(0, messageMain.length() - 1)); |
|
|
|
errorList.add(importVO); |
|
|
|
} else { |
|
|
|
purchasePlanDetailDO.setNumber(createReqVO.getNumber()); |
|
|
|
importErrorVO.setImportRemark(messageMain.substring(0, messageMain.length() - 1)); |
|
|
|
errorList.add(importErrorVO); |
|
|
|
flag = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (errorList.isEmpty()) { |
|
|
|
// 判断如果不存在,在进行插入
|
|
|
|
PurchasePlanMainDO existPurchaseclaimRequestMainDO = purchasePlanMainMapper.selectByNumber(createReqVO.getNumber()); |
|
|
|
if (existPurchaseclaimRequestMainDO == null && mode != 3) { |
|
|
|
createReqVO.setStatus(DictFrameworkUtils.parseDictDataValue(DictTypeConstants.REQUEST_STATUS, "新增")); |
|
|
|
BusinesstypeDO businesstypeDO = jobUtils.selectDocumentSettingFromBusinessType("PurchasePlan"); |
|
|
|
if (businesstypeDO != null) { |
|
|
|
createReqVO.setBusinessType(businesstypeDO.getCode()); |
|
|
|
} |
|
|
|
PurchasePlanMainDO createObj = PurchasePlanMainConvert.INSTANCE.convert(createReqVO); |
|
|
|
purchasePlanMainMapper.insert(createObj); |
|
|
|
purchasePlanDetailMapper.insertBatch(subDOList); |
|
|
|
} else if (existPurchaseclaimRequestMainDO != null && mode != 2) { |
|
|
|
createReqVO.setStatus(DictFrameworkUtils.parseDictDataValue(DictTypeConstants.REQUEST_STATUS, "新增")); |
|
|
|
BusinesstypeDO businesstypeDO = jobUtils.selectDocumentSettingFromBusinessType("PurchaseOrder"); |
|
|
|
if (businesstypeDO != null) { |
|
|
|
createReqVO.setBusinessType(businesstypeDO.getCode()); |
|
|
|
} |
|
|
|
PurchasePlanMainDO createObj = PurchasePlanMainConvert.INSTANCE.convert(createReqVO); |
|
|
|
purchasePlanMainMapper.updateById(createObj); |
|
|
|
purchasePlanDetailMapper.updateBatch(subDOList); |
|
|
|
//写入数据
|
|
|
|
if (flag) { |
|
|
|
mainDo.setStatus(DictFrameworkUtils.parseDictDataValue(DictTypeConstants.REQUEST_STATUS, "新增")); |
|
|
|
// mainDo.setOrderDate(LocalDateTime.now());
|
|
|
|
// mainDo.setTaxRate(BigDecimal.ZERO);
|
|
|
|
BusinesstypeDO businesstypeDO = jobUtils.selectDocumentSettingFromBusinessType("PurchaseOrder"); |
|
|
|
mainDo.setBusinessType(businesstypeDO.getCode()); |
|
|
|
mainDo.setAvailable("TRUE"); |
|
|
|
purchasePlanMainMapper.insert(mainDo); |
|
|
|
for (PurchasePlanDetailDO detailDO : subDOList) { |
|
|
|
detailDO.setMasterId(mainDo.getId()); |
|
|
|
detailDO.setNumber(mainDo.getNumber()); |
|
|
|
detailDO.setShippedQty(BigDecimal.ZERO); |
|
|
|
detailDO.setAvailable("TRUE"); |
|
|
|
} |
|
|
|
purchasePlanDetailMapper.insertBatch(subDOList); |
|
|
|
} |
|
|
|
}); |
|
|
|
//错误不为空并非部分更新,手工回滚
|
|
|
|
if (!errorList.isEmpty() && !updatePart) { |
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
} |
|
|
|
return errorList; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 校验主表导入,并赋值一些参数 |
|
|
|
* |
|
|
|
* @param mainDo |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private String validatorPurchasePlanMainImport(PurchasePlanMainDO mainDo) { |
|
|
|
String messageMain = ""; |
|
|
|
//主表的验证
|
|
|
|
//校验供应商基础信息
|
|
|
|
try { |
|
|
|
ShiftDO shiftDO = shiftService.selectShiftExist(mainDo.getSupplierCode()); |
|
|
|
} catch (ServiceException ex) { |
|
|
|
messageMain += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
return messageMain; |
|
|
|
} |
|
|
|
|
|
|
|
private String validatorPurchasePlanDetailImport(PurchasePlanDetailDO detailDo, PurchasePlanMainDO mainDo) { |
|
|
|
String messageDetail = ""; |
|
|
|
// 校验物品基础信息
|
|
|
|
try { |
|
|
|
ItembasicDO itembasicDO = itembasicService.selectItembasic(detailDo.getItemCode()); |
|
|
|
if (itembasicDO.getUom() != detailDo.getUom()) { |
|
|
|
messageDetail += "计量单位" + itembasicDO.getUom() + "错误,应该是" + detailDo.getUom() + ","; |
|
|
|
} |
|
|
|
// purchasePlanDetailDO.setProjectCode(itembasicDO.getCode());
|
|
|
|
} catch (ServiceException ex) { |
|
|
|
messageDetail += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
// 校验供应商物品
|
|
|
|
try { |
|
|
|
SupplieritemDO supplieritemDO = supplieritemService.selectSupplierItemExist(mainDo.getSupplierCode(), detailDo.getItemCode()); |
|
|
|
} catch (ServiceException ex) { |
|
|
|
messageDetail += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
return messageDetail; |
|
|
|
} |
|
|
|
//新增校验
|
|
|
|
private PurchasePlanMainDO validatorToCreate(PurchasePlanMainCreateReqVO createReqVO) { |
|
|
|
PurchasePlanMainDO purchasePlanMainDO = validatorMainMethod(createReqVO); |
|
|
|
//子表校验
|
|
|
|
List<PurchasePlanDetailCreateReqVO> subList = createReqVO.getSubList(); |
|
|
|
List<PurchasePlanDetailDO> subDOList = PurchasePlanDetailConvert.INSTANCE.convertList03(subList); |
|
|
|
purchasePlanMainMapper.insert(purchasePlanMainDO); |
|
|
|
for (PurchasePlanDetailDO purchasePlanDetailDO : subDOList) { |
|
|
|
validatorDetailMethod(purchasePlanDetailDO, purchasePlanMainDO); |
|
|
|
purchasePlanDetailDO.setMasterId(purchasePlanMainDO.getId()); |
|
|
|
purchasePlanDetailDO.setNumber(purchasePlanMainDO.getNumber()); |
|
|
|
purchasePlanDetailDO.setShippedQty(BigDecimal.ZERO); |
|
|
|
purchasePlanDetailDO.setAvailable("TRUE"); |
|
|
|
} |
|
|
|
purchasePlanDetailMapper.insertBatch(subDOList); |
|
|
|
return purchasePlanMainDO; |
|
|
|
} |
|
|
|
|
|
|
|
//修改校验
|
|
|
|
private PurchasePlanMainDO validatorToUpdate(PurchasePlanMainUpdateReqVO updateReqVO) { |
|
|
|
PurchasePlanMainDO purchasePlanMainDO = validatorMainMethod(updateReqVO); |
|
|
|
//子表校验
|
|
|
|
List<PurchasePlanDetailUpdateReqVO> subList = updateReqVO.getSubList(); |
|
|
|
List<PurchasePlanDetailDO> subDOList = PurchasePlanDetailConvert.INSTANCE.convertList05(subList); |
|
|
|
for (PurchasePlanDetailDO purchasePlanDetailDO : subDOList) { |
|
|
|
validatorDetailMethod(purchasePlanDetailDO, purchasePlanMainDO); |
|
|
|
} |
|
|
|
purchasePlanMainMapper.updateById(purchasePlanMainDO); |
|
|
|
purchasePlanDetailMapper.updateBatch(subDOList); |
|
|
|
return purchasePlanMainDO; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public Integer closePurchasePlanMain(Long id) { |
|
|
|