|
|
@ -1,23 +1,46 @@ |
|
|
|
package com.win.module.wms.service.preparetoissue; |
|
|
|
|
|
|
|
import com.win.framework.common.exception.ServiceException; |
|
|
|
import com.win.framework.common.pojo.CustomConditions; |
|
|
|
import com.win.framework.common.pojo.PageResult; |
|
|
|
import com.win.module.wms.controller.preparetoissue.vo.PreparetoissueMainCreateReqVO; |
|
|
|
import com.win.module.wms.controller.preparetoissue.vo.PreparetoissueMainExportReqVO; |
|
|
|
import com.win.module.wms.controller.preparetoissue.vo.PreparetoissueMainPageReqVO; |
|
|
|
import com.win.module.wms.controller.preparetoissue.vo.PreparetoissueMainUpdateReqVO; |
|
|
|
import com.win.module.infra.api.trends.TrendsApi; |
|
|
|
import com.win.module.infra.enums.TrendsTypeEnum; |
|
|
|
import com.win.module.system.api.dict.DictDataApi; |
|
|
|
import com.win.module.system.api.serialnumber.SerialNumberApi; |
|
|
|
import com.win.module.system.enums.serialNumber.RuleCodeEnum; |
|
|
|
import com.win.module.wms.controller.bom.vo.BomExportReqVO; |
|
|
|
import com.win.module.wms.controller.preparetoissue.vo.*; |
|
|
|
import com.win.module.wms.convert.preparetoissue.PreparetoissueDetailConvert; |
|
|
|
import com.win.module.wms.convert.preparetoissue.PreparetoissueMainConvert; |
|
|
|
import com.win.module.wms.convert.production.ProductionDetailConvert; |
|
|
|
import com.win.module.wms.convert.production.ProductionMainConvert; |
|
|
|
import com.win.module.wms.dal.dataobject.bom.BomDO; |
|
|
|
import com.win.module.wms.dal.dataobject.itembasic.ItembasicDO; |
|
|
|
import com.win.module.wms.dal.dataobject.preparetoissue.PreparetoissueDetailDO; |
|
|
|
import com.win.module.wms.dal.dataobject.preparetoissue.PreparetoissueMainDO; |
|
|
|
import com.win.module.wms.dal.dataobject.production.ProductionDetailDO; |
|
|
|
import com.win.module.wms.dal.dataobject.production.ProductionMainDO; |
|
|
|
import com.win.module.wms.dal.mysql.preparetoissue.PreparetoissueDetailMapper; |
|
|
|
import com.win.module.wms.dal.mysql.preparetoissue.PreparetoissueMainMapper; |
|
|
|
import com.win.module.wms.enums.plan.PlanStatusState; |
|
|
|
import com.win.module.wms.service.bom.BomService; |
|
|
|
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.shift.ShiftService; |
|
|
|
import com.win.module.wms.service.team.TeamService; |
|
|
|
import com.win.module.wms.service.workshop.WorkshopService; |
|
|
|
import com.win.module.wms.service.workstation.WorkstationService; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.List; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import static com.win.framework.common.exception.util.ServiceExceptionUtil.exception; |
|
|
|
import static com.win.module.wms.enums.ErrorCodeConstants.PREPARETOISSUE_MAIN_NOT_EXISTS; |
|
|
|
import static com.win.module.wms.enums.ErrorCodeConstants.*; |
|
|
|
|
|
|
|
/** |
|
|
|
* 备料计划主 Service 实现类 |
|
|
@ -27,26 +50,68 @@ import static com.win.module.wms.enums.ErrorCodeConstants.PREPARETOISSUE_MAIN_NO |
|
|
|
@Service |
|
|
|
@Validated |
|
|
|
public class PreparetoissueMainServiceImpl implements PreparetoissueMainService { |
|
|
|
|
|
|
|
@Resource |
|
|
|
private BomService bomService; |
|
|
|
@Resource |
|
|
|
private WorkstationService workstationService; |
|
|
|
@Resource |
|
|
|
private DictDataApi dictDataApi; |
|
|
|
@Resource |
|
|
|
private ItembasicService itembasicService; |
|
|
|
@Resource |
|
|
|
private ProductionlineitemService productionlineitemService; |
|
|
|
@Resource |
|
|
|
private ShiftService shiftService; |
|
|
|
@Resource |
|
|
|
private TeamService teamService; |
|
|
|
@Resource |
|
|
|
private ProductionlineService productionlineService; |
|
|
|
@Resource |
|
|
|
private WorkshopService workshopService; |
|
|
|
@Resource |
|
|
|
private PreparetoissueMainMapper preparetoissueMainMapper; |
|
|
|
@Resource |
|
|
|
private PreparetoissueDetailMapper preparetoissueDetailMapper; |
|
|
|
@Resource |
|
|
|
private TrendsApi trendsApi; |
|
|
|
@Resource |
|
|
|
private SerialNumberApi serialNumberApi; |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public Long createPreparetoissueMain(PreparetoissueMainCreateReqVO createReqVO) { |
|
|
|
// 插入
|
|
|
|
PreparetoissueMainDO preparetoissueMain = PreparetoissueMainConvert.INSTANCE.convert(createReqVO); |
|
|
|
preparetoissueMainMapper.insert(preparetoissueMain); |
|
|
|
PreparetoissueMainDO mainDO = PreparetoissueMainConvert.INSTANCE.convert(createReqVO); |
|
|
|
List<PreparetoissueDetailDO> subDOList = PreparetoissueDetailConvert.INSTANCE.convertList03(createReqVO.getSubList()); |
|
|
|
for (PreparetoissueDetailDO detailDO : subDOList) { |
|
|
|
this.validatePreparetoissueDetailCreate(mainDO, detailDO); |
|
|
|
} |
|
|
|
String number = serialNumberApi.generateCode(RuleCodeEnum.MATERIAL_PREPARE_PLAN.getCode()); |
|
|
|
mainDO.setNumber(number); |
|
|
|
mainDO.setBusinessType("Issue"); // 业务类型:发料
|
|
|
|
preparetoissueMainMapper.insert(mainDO); |
|
|
|
for (PreparetoissueDetailDO detailDO : subDOList) { |
|
|
|
detailDO.setMasterId(mainDO.getId()); |
|
|
|
detailDO.setNumber(number); |
|
|
|
} |
|
|
|
preparetoissueDetailMapper.insertBatch(subDOList); |
|
|
|
//增加操作记录
|
|
|
|
trendsApi.createTrends(mainDO.getId(), "preparetoissueMain", "增加了备料计划", TrendsTypeEnum.CREATE); |
|
|
|
// 返回
|
|
|
|
return preparetoissueMain.getId(); |
|
|
|
return mainDO.getId(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void updatePreparetoissueMain(PreparetoissueMainUpdateReqVO updateReqVO) { |
|
|
|
@Transactional |
|
|
|
public Integer updatePreparetoissueMain(PreparetoissueMainUpdateReqVO updateReqVO) { |
|
|
|
// 校验存在
|
|
|
|
validatePreparetoissueMainExists(updateReqVO.getId()); |
|
|
|
// 更新
|
|
|
|
PreparetoissueMainDO updateObj = PreparetoissueMainConvert.INSTANCE.convert(updateReqVO); |
|
|
|
preparetoissueMainMapper.updateById(updateObj); |
|
|
|
this.validatePreparetoissueMainUpdate(updateObj); |
|
|
|
//增加操作记录
|
|
|
|
trendsApi.createTrends(updateObj.getId(), "preparetoissueMain", "更新了备料计划", TrendsTypeEnum.UPDATE); |
|
|
|
return preparetoissueMainMapper.updateById(updateObj); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -57,10 +122,12 @@ public class PreparetoissueMainServiceImpl implements PreparetoissueMainService |
|
|
|
preparetoissueMainMapper.deleteById(id); |
|
|
|
} |
|
|
|
|
|
|
|
private void validatePreparetoissueMainExists(Long id) { |
|
|
|
if (preparetoissueMainMapper.selectById(id) == null) { |
|
|
|
private PreparetoissueMainDO validatePreparetoissueMainExists(Long id) { |
|
|
|
PreparetoissueMainDO existPreparetoissueMainDO = preparetoissueMainMapper.selectById(id); |
|
|
|
if (existPreparetoissueMainDO == null) { |
|
|
|
throw exception(PREPARETOISSUE_MAIN_NOT_EXISTS); |
|
|
|
} |
|
|
|
return existPreparetoissueMainDO; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -73,6 +140,11 @@ public class PreparetoissueMainServiceImpl implements PreparetoissueMainService |
|
|
|
return preparetoissueMainMapper.selectBatchIds(ids); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<PreparetoissueMainDO> getPreparetoissueMainList(CustomConditions conditions) { |
|
|
|
return preparetoissueMainMapper.selectSeniorList(conditions); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageResult<PreparetoissueMainDO> getPreparetoissueMainPage(PreparetoissueMainPageReqVO pageReqVO) { |
|
|
|
return preparetoissueMainMapper.selectPage(pageReqVO); |
|
|
@ -88,4 +160,206 @@ public class PreparetoissueMainServiceImpl implements PreparetoissueMainService |
|
|
|
return preparetoissueMainMapper.selectList(exportReqVO); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public Integer closeProductionMain(Long id) { |
|
|
|
// 校验存在存在下级单据
|
|
|
|
PreparetoissueMainDO mainDO = validatePreparetoissueMainExists(id); |
|
|
|
PlanStatusState planStatusState = new PlanStatusState(mainDO.getStatus()); |
|
|
|
boolean flag = planStatusState.close(); |
|
|
|
if(!flag) { |
|
|
|
throw new ServiceException(PREPARETOISSUE_MAIN_CANNOT_CLOSE); |
|
|
|
} |
|
|
|
mainDO.setStatus(planStatusState.getState().getCode()); |
|
|
|
//增加操作记录
|
|
|
|
trendsApi.createTrends(id, "preparetoissueMain", "关闭了备料计划", TrendsTypeEnum.UPDATE); |
|
|
|
return preparetoissueMainMapper.updateById(mainDO); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public Integer submitProductionMain(Long id) { |
|
|
|
PreparetoissueMainDO mainDO = validatePreparetoissueMainExists(id); |
|
|
|
PlanStatusState planStatusState = new PlanStatusState(mainDO.getStatus()); |
|
|
|
boolean flag = planStatusState.submit(); |
|
|
|
if(!flag) { |
|
|
|
throw new ServiceException(PREPARETOISSUE_MAIN_CANNOT_SUBMIT); |
|
|
|
} |
|
|
|
mainDO.setStatus(planStatusState.getState().getCode()); |
|
|
|
//增加操作记录
|
|
|
|
trendsApi.createTrends(id, "preparetoissueMain", "提交了备料计划", TrendsTypeEnum.UPDATE); |
|
|
|
return preparetoissueMainMapper.updateById(mainDO); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public Integer openProductionMain(Long id) { |
|
|
|
PreparetoissueMainDO mainDO = validatePreparetoissueMainExists(id); |
|
|
|
PlanStatusState planStatusState = new PlanStatusState(mainDO.getStatus()); |
|
|
|
boolean flag = planStatusState.open(); |
|
|
|
if(!flag) { |
|
|
|
throw new ServiceException(PREPARETOISSUE_MAIN_CANNOT_OPEN); |
|
|
|
} |
|
|
|
mainDO.setStatus(planStatusState.getState().getCode()); |
|
|
|
//增加操作记录
|
|
|
|
trendsApi.createTrends(id, "preparetoissueMain", "打开了备料计划", TrendsTypeEnum.UPDATE); |
|
|
|
return preparetoissueMainMapper.updateById(mainDO); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public Integer rejectProductionMain(Long id) { |
|
|
|
PreparetoissueMainDO mainDO = validatePreparetoissueMainExists(id); |
|
|
|
PlanStatusState planStatusState = new PlanStatusState(mainDO.getStatus()); |
|
|
|
boolean flag = planStatusState.reject(); |
|
|
|
if(!flag) { |
|
|
|
throw new ServiceException(PREPARETOISSUE_MAIN_CANNOT_REJECT); |
|
|
|
} |
|
|
|
mainDO.setStatus(planStatusState.getState().getCode()); |
|
|
|
//增加操作记录
|
|
|
|
trendsApi.createTrends(id, "preparetoissueMain", "驳回了备料计划", TrendsTypeEnum.UPDATE); |
|
|
|
return preparetoissueMainMapper.updateById(mainDO); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public Integer agreeProductionMain(Long id) { |
|
|
|
PreparetoissueMainDO mainDO = validatePreparetoissueMainExists(id); |
|
|
|
PlanStatusState planStatusState = new PlanStatusState(mainDO.getStatus()); |
|
|
|
boolean flag = planStatusState.agree(); |
|
|
|
if(!flag) { |
|
|
|
throw new ServiceException(PREPARETOISSUE_MAIN_CANNOT_AGREE); |
|
|
|
} |
|
|
|
mainDO.setStatus(planStatusState.getState().getCode()); |
|
|
|
//增加操作记录
|
|
|
|
trendsApi.createTrends(id, "preparetoissueMain", "审批通过了备料计划", TrendsTypeEnum.UPDATE); |
|
|
|
return preparetoissueMainMapper.updateById(mainDO); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public Integer publishProductionMain(Long id) { |
|
|
|
PreparetoissueMainDO mainDO = validatePreparetoissueMainExists(id); |
|
|
|
PlanStatusState planStatusState = new PlanStatusState(mainDO.getStatus()); |
|
|
|
boolean flag = planStatusState.publish(); |
|
|
|
if(!flag) { |
|
|
|
throw new ServiceException(PREPARETOISSUE_MAIN_CANNOT_PUBLISH); |
|
|
|
} |
|
|
|
mainDO.setStatus(planStatusState.getState().getCode()); |
|
|
|
// 生成申请单据
|
|
|
|
// this.generateRequest(mainDO, productionDetailMapper.selectList(mainDO.getId()));
|
|
|
|
//增加操作记录
|
|
|
|
trendsApi.createTrends(id, "preparetoissueMain", "发布了备料计划", TrendsTypeEnum.UPDATE); |
|
|
|
return preparetoissueMainMapper.updateById(mainDO); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public Integer resettingProductionMain(Long id) { |
|
|
|
PreparetoissueMainDO mainDO = validatePreparetoissueMainExists(id); |
|
|
|
PlanStatusState planStatusState = new PlanStatusState(mainDO.getStatus()); |
|
|
|
boolean flag = planStatusState.resetting(); |
|
|
|
if(!flag) { |
|
|
|
throw new ServiceException(PREPARETOISSUE_MAIN_CANNOT_RESETTING); |
|
|
|
} |
|
|
|
mainDO.setStatus(planStatusState.getState().getCode()); |
|
|
|
//增加操作记录
|
|
|
|
trendsApi.createTrends(id, "preparetoissueMain", "重置了备料计划", TrendsTypeEnum.UPDATE); |
|
|
|
return preparetoissueMainMapper.updateById(mainDO); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 新增校验 |
|
|
|
* @param detailDo |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private void validatePreparetoissueDetailCreate(PreparetoissueMainDO mainDo, PreparetoissueDetailDO detailDo) { |
|
|
|
// 校验物品代码
|
|
|
|
ItembasicDO itembasicDO = itembasicService.selectItembasic(detailDo.getItemCode()); |
|
|
|
if (!itembasicDO.getUom().equals(detailDo.getUom())) { |
|
|
|
throw exception(ITEMBASIC_UOM_EXCEPTION, dictDataApi.selectDictValue(detailDo.getUom()).getLabel(), dictDataApi.selectDictValue(itembasicDO.getUom()).getLabel()); |
|
|
|
} |
|
|
|
// 校验车间 基础信息
|
|
|
|
workshopService.selectWorkshopExist(mainDo.getWorkshop()); |
|
|
|
// 校验生产线基础信息
|
|
|
|
productionlineService.productionLineCodeExist(mainDo.getProdLine()); |
|
|
|
// 校验班组基础信息
|
|
|
|
teamService.selectTeamExist(mainDo.getTeam()); |
|
|
|
// 校验班次基础信息
|
|
|
|
shiftService.selectShiftExist(mainDo.getShift()); |
|
|
|
// 校验工位基础信息
|
|
|
|
if (detailDo.getWorkStation() != null) { |
|
|
|
workstationService.selectWorkstationExist(detailDo.getWorkStation(),mainDo.getWorkshop(),mainDo.getProdLine()); |
|
|
|
} |
|
|
|
// 校验生产线和物品关系
|
|
|
|
// productionlineitemService.productionLineCodeAndpItemCodeExist(mainDo.getProdLine(), detailDo.getItemCode());
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 编辑校验 |
|
|
|
* @param mainDo |
|
|
|
*/ |
|
|
|
public void validatePreparetoissueMainUpdate(PreparetoissueMainDO mainDo) { |
|
|
|
// 校验车间 基础信息
|
|
|
|
workshopService.selectWorkshopExist(mainDo.getWorkshop()); |
|
|
|
// 校验生产线基础信息
|
|
|
|
productionlineService.productionLineCodeExist(mainDo.getProdLine()); |
|
|
|
// 校验班组基础信息
|
|
|
|
teamService.selectTeamExist(mainDo.getTeam()); |
|
|
|
// 校验班次基础信息
|
|
|
|
shiftService.selectShiftExist(mainDo.getShift()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* bom拆解 |
|
|
|
* @param mainDO |
|
|
|
* @param detailDOList |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<PreparetoissueDetailCreateReqVO> BomDisassemble(ProductionMainDO mainDO, List<ProductionDetailDO> detailDOList ) { |
|
|
|
List<PreparetoissueDetailCreateReqVO> subList = new ArrayList<>(); |
|
|
|
detailDOList.forEach(item -> { |
|
|
|
List<Map<String,Object>> list = new ArrayList<>(); |
|
|
|
this.BomRecursion(item.getItemCode(), list); |
|
|
|
list.forEach(itemBom -> { |
|
|
|
PreparetoissueDetailCreateReqVO preparetoissueDetailCreateReqVO = new PreparetoissueDetailCreateReqVO(); |
|
|
|
preparetoissueDetailCreateReqVO.setAvailable(item.getAvailable()); |
|
|
|
preparetoissueDetailCreateReqVO.setToLocationCode(productionlineitemService.productionLineCodeAndpItemCodeExist(mainDO.getProductionLine(), item.getItemCode()).getRawLocationCode()); |
|
|
|
preparetoissueDetailCreateReqVO.setMasterId(item.getMasterId()); |
|
|
|
preparetoissueDetailCreateReqVO.setItemCode(itemBom.get("itemCode").toString()); |
|
|
|
preparetoissueDetailCreateReqVO.setPlanQty(new BigDecimal(itemBom.get("qty").toString()).multiply(item.getPlanQty())); |
|
|
|
preparetoissueDetailCreateReqVO.setUom(itemBom.get("uom").toString()); |
|
|
|
subList.add(preparetoissueDetailCreateReqVO); |
|
|
|
}); |
|
|
|
}); |
|
|
|
return subList; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* bom解析递归 |
|
|
|
* @param itemCode |
|
|
|
* @param list |
|
|
|
*/ |
|
|
|
private void BomRecursion (String itemCode,List<Map<String,Object>> list) { |
|
|
|
BomExportReqVO bomExportReqVO = new BomExportReqVO(); |
|
|
|
bomExportReqVO.setProductItemCode(itemCode); |
|
|
|
bomExportReqVO.setAvailable("TRUE"); |
|
|
|
List<BomDO> bomDOList = bomService.getBomList(bomExportReqVO); |
|
|
|
bomDOList.forEach(item -> { |
|
|
|
// 判断物品是否是虚零件
|
|
|
|
if (itembasicService.selectItembasic(item.getComponentItemCode()).getIsPhantom().equals("TRUE")) { |
|
|
|
this.BomRecursion(item.getComponentItemCode(),list); |
|
|
|
} else { |
|
|
|
Map<String,Object> map = new HashMap<>(); |
|
|
|
map.put("itemCode",item.getComponentItemCode()); |
|
|
|
map.put("uom",item.getComponentUom()); |
|
|
|
map.put("qty",item.getComponentQty()); |
|
|
|
list.add(map); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|