|
|
@ -1,14 +1,43 @@ |
|
|
|
package com.win.module.wms.service.issueRequest; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import cn.hutool.core.exceptions.UtilException; |
|
|
|
import cn.hutool.json.JSONObject; |
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
import com.win.framework.common.pojo.CustomConditions; |
|
|
|
import com.win.module.wms.controller.issueRequest.vo.IssueRequestMainCreateReqVO; |
|
|
|
import com.win.module.wms.controller.issueRequest.vo.IssueRequestMainExportReqVO; |
|
|
|
import com.win.module.wms.controller.issueRequest.vo.IssueRequestMainPageReqVO; |
|
|
|
import com.win.module.wms.controller.issueRequest.vo.IssueRequestMainUpdateReqVO; |
|
|
|
import com.win.framework.common.util.validation.ValidationUtils; |
|
|
|
import com.win.framework.dict.core.util.DictFrameworkUtils; |
|
|
|
import com.win.module.system.api.serialnumber.SerialNumberApi; |
|
|
|
import com.win.module.system.enums.serialNumber.RuleCodeEnum; |
|
|
|
import com.win.module.wms.controller.issueRequest.vo.*; |
|
|
|
import com.win.module.wms.controller.rule.vo.RuleRespVO; |
|
|
|
import com.win.module.wms.convert.issueRequest.IssueRequestDetailConvert; |
|
|
|
import com.win.module.wms.dal.dataobject.businesstype.BusinesstypeDO; |
|
|
|
import com.win.module.wms.dal.dataobject.issueRequest.IssueRequestDetailDO; |
|
|
|
import com.win.module.wms.dal.dataobject.itembasic.ItembasicDO; |
|
|
|
import com.win.module.wms.dal.dataobject.productionline.ProductionlineDO; |
|
|
|
import com.win.module.wms.dal.dataobject.requestsetting.RequestsettingDO; |
|
|
|
import com.win.module.wms.dal.dataobject.workstation.WorkstationDO; |
|
|
|
import com.win.module.wms.dal.mysql.issueRequest.IssueRequestDetailMapper; |
|
|
|
import com.win.module.wms.enums.DictTypeConstants; |
|
|
|
import com.win.module.wms.service.itembasic.ItembasicService; |
|
|
|
import com.win.module.wms.service.productionline.ProductionlineService; |
|
|
|
import com.win.module.wms.service.productionlineitem.ProductionlineitemService; |
|
|
|
import com.win.module.wms.service.requestsetting.RequestsettingService; |
|
|
|
import com.win.module.wms.service.rule.RuleService; |
|
|
|
import com.win.module.wms.service.workshop.WorkshopService; |
|
|
|
import com.win.module.wms.service.workstation.WorkstationService; |
|
|
|
import com.win.module.wms.util.JobUtils; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.validation.Validator; |
|
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport; |
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import com.win.module.wms.dal.dataobject.issueRequest.IssueRequestMainDO; |
|
|
@ -31,6 +60,28 @@ public class IssueRequestMainServiceImpl implements IssueRequestMainService { |
|
|
|
|
|
|
|
@Resource |
|
|
|
private IssueRequestMainMapper issueRequestMainMapper; |
|
|
|
@Resource |
|
|
|
private IssueRequestDetailMapper issueRequestDetailMapper; |
|
|
|
@Resource |
|
|
|
private Validator validator; |
|
|
|
@Resource |
|
|
|
private SerialNumberApi serialNumberApi; |
|
|
|
@Resource |
|
|
|
private ItembasicService itembasicService; |
|
|
|
@Resource |
|
|
|
private WorkshopService workshopService; |
|
|
|
@Resource |
|
|
|
private ProductionlineitemService productionlineitemService; |
|
|
|
@Resource |
|
|
|
private ProductionlineService productionlineService; |
|
|
|
@Resource |
|
|
|
private WorkstationService workstationService; |
|
|
|
@Resource |
|
|
|
private JobUtils jobUtils; |
|
|
|
@Resource |
|
|
|
private RuleService ruleService; |
|
|
|
@Resource |
|
|
|
private RequestsettingService requestsettingService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public Long createIssueRequestMain(IssueRequestMainCreateReqVO createReqVO) { |
|
|
@ -60,6 +111,8 @@ public class IssueRequestMainServiceImpl implements IssueRequestMainService { |
|
|
|
|
|
|
|
private void validateIssueRequestMainExists(Long id) { |
|
|
|
if (issueRequestMainMapper.selectById(id) == null) { |
|
|
|
return; |
|
|
|
} else { |
|
|
|
throw exception(ISSUE_REQUEST_MAIN_NOT_EXISTS); |
|
|
|
} |
|
|
|
} |
|
|
@ -78,6 +131,7 @@ public class IssueRequestMainServiceImpl implements IssueRequestMainService { |
|
|
|
public PageResult<IssueRequestMainDO> getIssueRequestMainPage(IssueRequestMainPageReqVO pageReqVO) { |
|
|
|
return issueRequestMainMapper.selectPage(pageReqVO); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageResult<IssueRequestMainDO> getIssueRequestMainSenior(CustomConditions conditions) { |
|
|
|
return issueRequestMainMapper.selectSenior(conditions); |
|
|
@ -88,4 +142,160 @@ public class IssueRequestMainServiceImpl implements IssueRequestMainService { |
|
|
|
return issueRequestMainMapper.selectList(exportReqVO); |
|
|
|
} |
|
|
|
|
|
|
|
private void ifUomSuccess(String itemUom, String uom) { |
|
|
|
if (!itemUom.equals(uom)) { |
|
|
|
throw new UtilException("提示单位" + uom + "错误,应该是" + itemUom); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private Boolean ifLocationCodeInRule(String itemCode, String locationCode, String ruleLocationCode) { |
|
|
|
String[] ruleLocationCodes = ruleLocationCode.split(","); |
|
|
|
Boolean request = false; |
|
|
|
for (String code : ruleLocationCodes) { |
|
|
|
if (code.equals(locationCode)) { |
|
|
|
request = true; |
|
|
|
} else { |
|
|
|
throw new UtilException("未查找到零件" + itemCode + "与库位" + locationCode + "对应的上架策略"); |
|
|
|
} |
|
|
|
} |
|
|
|
return request; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public List<IssueRequestImportErrorVO> importIssueRequestList(List<IssueRequestMainCreateReqVO> datas, Integer mode, boolean updatePart) { |
|
|
|
if (CollUtil.isEmpty(datas)) { |
|
|
|
throw exception(PREPARETOISSUE_REQUEST_IMPORT_LIST_IS_EMPTY); |
|
|
|
} |
|
|
|
List<IssueRequestImportErrorVO> errorList = new ArrayList<>(); |
|
|
|
datas.forEach(createReqVO -> { |
|
|
|
String messageMain = ""; |
|
|
|
BusinesstypeDO businesstypeDO = null; |
|
|
|
//主表校验方法
|
|
|
|
try { |
|
|
|
validateIssueRequestMainExists(null); |
|
|
|
} catch (Exception ex) { |
|
|
|
messageMain += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
try { |
|
|
|
workshopService.selectWorkshopExist(createReqVO.getWorkshopCode()); |
|
|
|
} catch (Exception ex) { |
|
|
|
messageMain += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
createReqVO.setStatus(DictFrameworkUtils.parseDictDataValue(DictTypeConstants.REQUEST_STATUS, "新增")); |
|
|
|
createReqVO.setRequestTime(LocalDateTime.now()); |
|
|
|
try { |
|
|
|
RequestsettingDO requestsettingDO = requestsettingService.selectRequestsettingExist("IssueRequest"); |
|
|
|
if (requestsettingDO != null) { |
|
|
|
createReqVO.setAutoAgree(requestsettingDO.getAutoAgree()); |
|
|
|
createReqVO.setAutoCommit(requestsettingDO.getAutoCommit()); |
|
|
|
createReqVO.setAutoExecute(requestsettingDO.getAutoExecute()); |
|
|
|
createReqVO.setDirectCreateRecord(requestsettingDO.getDirectCreateRecord()); |
|
|
|
} |
|
|
|
} catch (Exception ex) { |
|
|
|
messageMain += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
try { |
|
|
|
businesstypeDO = jobUtils.selectDocumentSettingFromBusinessType("IssueRequest"); |
|
|
|
createReqVO.setBusinessType(businesstypeDO.getCode()); |
|
|
|
createReqVO.setFromLocationTypes(businesstypeDO.getOutLocationTypes()); |
|
|
|
createReqVO.setToLocationTypes(businesstypeDO.getInLocationTypes()); |
|
|
|
createReqVO.setFromAreaCodes(businesstypeDO.getOutAreaCodes()); |
|
|
|
createReqVO.setToAreaCodes(businesstypeDO.getInAreaCodes()); |
|
|
|
} catch (Exception ex) { |
|
|
|
messageMain += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
try { |
|
|
|
ValidationUtils.validate(validator, createReqVO); |
|
|
|
} catch (Exception ex) { |
|
|
|
messageMain += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
String number = serialNumberApi.generateCode(RuleCodeEnum.PURCHASE_RETURN_REQUEST.getCode()); |
|
|
|
createReqVO.setNumber(number); |
|
|
|
List<IssueRequestDetailCreateReqVO> subList = createReqVO.getSubList(); |
|
|
|
List<IssueRequestDetailDO> subDOList = IssueRequestDetailConvert.INSTANCE.convertList03(subList); |
|
|
|
for (IssueRequestDetailDO detailDO : subDOList) { |
|
|
|
String messageDetail = ""; |
|
|
|
// 校验,判断是否有不符合的原因,并加入errorList,同主表,只把有错误的子表加入errorList
|
|
|
|
//子表校验方法
|
|
|
|
try { |
|
|
|
ItembasicDO itembasicDO = itembasicService.selectItembasic(detailDO.getItemCode()); |
|
|
|
detailDO.setItemDesc1(itembasicDO.getDesc1()); |
|
|
|
detailDO.setItemDesc2(itembasicDO.getDesc2()); |
|
|
|
detailDO.setItemName(itembasicDO.getName()); |
|
|
|
detailDO.setProjectCode(itembasicDO.getProject()); |
|
|
|
try { |
|
|
|
jobUtils.ifInType(itembasicDO.getType(), businesstypeDO); |
|
|
|
} catch (Exception ex) { |
|
|
|
messageMain += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
try { |
|
|
|
ifUomSuccess(itembasicDO.getUom(), detailDO.getUom()); |
|
|
|
} catch (Exception ex) { |
|
|
|
messageDetail += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
} catch (Exception ex) { |
|
|
|
messageDetail += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
try { |
|
|
|
ProductionlineDO productionlineDO = productionlineService.productionLineCodeExist(detailDO.getProductionLineCode()); |
|
|
|
detailDO.setToLocationCode(productionlineDO.getRawLocationCode()); |
|
|
|
} catch (Exception ex) { |
|
|
|
messageMain += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
try { |
|
|
|
if (detailDO.getWorkStationCode() != "") { |
|
|
|
WorkstationDO workstationDO = workstationService.selectWorkstationExist(detailDO.getWorkStationCode(), createReqVO.getWorkshopCode(), detailDO.getProductionLineCode()); |
|
|
|
detailDO.setToLocationCode(workstationDO.getRawLocationCode()); |
|
|
|
} |
|
|
|
} catch (Exception ex) { |
|
|
|
messageMain += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
try { |
|
|
|
productionlineitemService.productionLineCodeAndpItemCodeExist(detailDO.getProductionLineCode(), detailDO.getItemCode()); |
|
|
|
} catch (Exception ex) { |
|
|
|
messageMain += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
try { |
|
|
|
RuleRespVO grounding = ruleService.grounding(null, null, null, null, null, null, detailDO.getItemCode(), null, null, null, null, null, null); |
|
|
|
JSONObject json = JSONUtil.parseObj(grounding); |
|
|
|
String locationCode = json.get("LocationCode").toString(); |
|
|
|
try { |
|
|
|
ifLocationCodeInRule(detailDO.getItemCode(), detailDO.getToLocationCode(), locationCode); |
|
|
|
} catch (Exception ex) { |
|
|
|
messageDetail += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
} catch (Exception ex) { |
|
|
|
messageDetail += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
IssueRequestDetailCreateReqVO purchaseturnRequestDetailCreateReqVO = IssueRequestDetailConvert.INSTANCE.convert1(detailDO); |
|
|
|
IssueRequestImportErrorVO importVO = IssueRequestDetailConvert.INSTANCE.convert(createReqVO, purchaseturnRequestDetailCreateReqVO); |
|
|
|
if (!messageMain.equals("") || !messageDetail.equals("")) { |
|
|
|
importVO.setImportStatus("失败"); |
|
|
|
messageMain = messageMain + messageDetail; |
|
|
|
importVO.setImportRemark(messageMain.substring(0, messageMain.length() - 1)); |
|
|
|
errorList.add(importVO); |
|
|
|
} else { |
|
|
|
detailDO.setNumber(createReqVO.getNumber()); |
|
|
|
detailDO.setMasterId(createReqVO.getId()); |
|
|
|
} |
|
|
|
} |
|
|
|
IssueRequestMainDO createobj = IssueRequestMainConvert.INSTANCE.convert(createReqVO); |
|
|
|
if (errorList.isEmpty()) { |
|
|
|
IssueRequestMainDO existIssueRequestMainDO = issueRequestMainMapper.selectWorkShopCodeAndUseOnTheWayLocation(createReqVO.getWorkshopCode(), createobj.getUseOnTheWayLocation()); |
|
|
|
if (existIssueRequestMainDO == null && mode != 3) { |
|
|
|
issueRequestMainMapper.insert(createobj); |
|
|
|
issueRequestDetailMapper.insertBatch(subDOList); |
|
|
|
} else if (existIssueRequestMainDO != null && mode != 2) { |
|
|
|
issueRequestMainMapper.updateById(createobj); |
|
|
|
issueRequestDetailMapper.updateBatch(subDOList); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
//错误不为空并非部分更新,手工回滚
|
|
|
|
if (!errorList.isEmpty() && !updatePart) { |
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
} |
|
|
|
return errorList; |
|
|
|
} |
|
|
|
} |
|
|
|