|
|
@ -1,15 +1,41 @@ |
|
|
|
package com.win.module.wms.service.repleinshJob; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.win.framework.common.exception.ServiceException; |
|
|
|
import com.win.framework.common.pojo.CustomConditions; |
|
|
|
import com.win.module.wms.controller.repleinshJob.vo.RepleinshJobMainCreateReqVO; |
|
|
|
import com.win.module.wms.controller.repleinshJob.vo.RepleinshJobMainExportReqVO; |
|
|
|
import com.win.module.wms.controller.repleinshJob.vo.RepleinshJobMainPageReqVO; |
|
|
|
import com.win.module.wms.controller.repleinshJob.vo.RepleinshJobMainUpdateReqVO; |
|
|
|
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.api.user.AdminUserApi; |
|
|
|
import com.win.module.system.api.user.dto.AdminUserRespDTO; |
|
|
|
import com.win.module.system.enums.serialNumber.RuleCodeEnum; |
|
|
|
import com.win.module.wms.controller.repleinshJob.vo.*; |
|
|
|
import com.win.module.wms.controller.transaction.vo.TransactionCreateReqVO; |
|
|
|
import com.win.module.wms.dal.dataobject.businesstype.BusinesstypeDO; |
|
|
|
import com.win.module.wms.dal.dataobject.location.LocationDO; |
|
|
|
import com.win.module.wms.dal.dataobject.repleinshJob.RepleinshJobDetailDO; |
|
|
|
import com.win.module.wms.dal.dataobject.repleinshRecord.RepleinshRecordDetailDO; |
|
|
|
import com.win.module.wms.dal.dataobject.repleinshRecord.RepleinshRecordMainDO; |
|
|
|
import com.win.module.wms.dal.dataobject.transactiontype.TransactiontypeDO; |
|
|
|
import com.win.module.wms.dal.mysql.repleinshRecord.RepleinshRecordDetailMapper; |
|
|
|
import com.win.module.wms.dal.mysql.repleinshRecord.RepleinshRecordMainMapper; |
|
|
|
import com.win.module.wms.enums.DictTypeConstants; |
|
|
|
import com.win.module.wms.enums.job.JobStatusState; |
|
|
|
import com.win.module.wms.service.expectin.ExpectinService; |
|
|
|
import com.win.module.wms.service.expectout.ExpectoutService; |
|
|
|
import com.win.module.wms.service.location.LocationService; |
|
|
|
import com.win.module.wms.service.recordsetting.RecordsettingService; |
|
|
|
import com.win.module.wms.service.transaction.TransactionService; |
|
|
|
import com.win.module.wms.util.JobUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import javax.annotation.Resource; |
|
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import com.win.module.wms.dal.dataobject.repleinshJob.RepleinshJobMainDO; |
|
|
@ -19,6 +45,7 @@ import com.win.module.wms.convert.repleinshJob.RepleinshJobMainConvert; |
|
|
|
import com.win.module.wms.dal.mysql.repleinshJob.RepleinshJobMainMapper; |
|
|
|
|
|
|
|
import static com.win.framework.common.exception.util.ServiceExceptionUtil.exception; |
|
|
|
import static com.win.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
|
|
|
import static com.win.module.wms.enums.ErrorCodeConstants.*; |
|
|
|
|
|
|
|
/** |
|
|
@ -30,6 +57,30 @@ import static com.win.module.wms.enums.ErrorCodeConstants.*; |
|
|
|
@Validated |
|
|
|
public class RepleinshJobMainServiceImpl implements RepleinshJobMainService { |
|
|
|
|
|
|
|
@Resource |
|
|
|
private ExpectinService expectinService; |
|
|
|
@Resource |
|
|
|
private ExpectoutService expectoutService; |
|
|
|
@Resource |
|
|
|
private TransactionService transactionService; |
|
|
|
@Resource |
|
|
|
private RepleinshRecordDetailMapper repleinshRecordDetailMapper; |
|
|
|
@Resource |
|
|
|
private LocationService locationService; |
|
|
|
@Resource |
|
|
|
private RecordsettingService recordsettingService; |
|
|
|
@Resource |
|
|
|
private RepleinshRecordMainMapper repleinshRecordMainMapper; |
|
|
|
@Resource |
|
|
|
private JobUtils jobUtils; |
|
|
|
@Resource |
|
|
|
private SerialNumberApi serialNumberApi; |
|
|
|
@Resource |
|
|
|
private RepleinshJobDetailService repleinshJobDetailService; |
|
|
|
@Resource |
|
|
|
private TrendsApi trendsApi; |
|
|
|
@Resource |
|
|
|
private AdminUserApi userApi; |
|
|
|
@Resource |
|
|
|
private RepleinshJobMainMapper repleinshJobMainMapper; |
|
|
|
|
|
|
@ -59,10 +110,12 @@ public class RepleinshJobMainServiceImpl implements RepleinshJobMainService { |
|
|
|
repleinshJobMainMapper.deleteById(id); |
|
|
|
} |
|
|
|
|
|
|
|
private void validateRepleinshJobMainExists(Long id) { |
|
|
|
if (repleinshJobMainMapper.selectById(id) == null) { |
|
|
|
private RepleinshJobMainDO validateRepleinshJobMainExists(Long id) { |
|
|
|
RepleinshJobMainDO repleinshJobMainDO = repleinshJobMainMapper.selectById(id); |
|
|
|
if (repleinshJobMainDO == null) { |
|
|
|
throw exception(REPLEINSH_JOB_MAIN_NOT_EXISTS); |
|
|
|
} |
|
|
|
return repleinshJobMainDO; |
|
|
|
} |
|
|
|
@Override |
|
|
|
public PageResult<RepleinshJobMainDO> getRepleinshJobMainSenior(CustomConditions conditions) { |
|
|
@ -109,4 +162,175 @@ public class RepleinshJobMainServiceImpl implements RepleinshJobMainService { |
|
|
|
map.put("count", l.intValue()); |
|
|
|
return map; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<RepleinshJobMainDO> getRepleinshJobMainList(CustomConditions conditions) { |
|
|
|
return repleinshJobMainMapper.selectSeniorList(conditions); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public Integer acceptRepleinshJobMain(Long id) { |
|
|
|
RepleinshJobMainDO repleinshJobMainDO = this.validateRepleinshJobMainExists(id); |
|
|
|
JobStatusState jobStatusState = new JobStatusState(repleinshJobMainDO.getStatus()); |
|
|
|
if(!jobStatusState.accept()) { |
|
|
|
throw exception(REPLEINSH_JOB_MAIN_STATUS_ERROR); |
|
|
|
} |
|
|
|
Long userId = getLoginUserId(); |
|
|
|
AdminUserRespDTO userRespDTO = userApi.getUser(userId); |
|
|
|
repleinshJobMainDO.setStatus(jobStatusState.getState().getCode()); |
|
|
|
repleinshJobMainDO.setAcceptUserId(String.valueOf(userId)); |
|
|
|
repleinshJobMainDO.setAcceptUserName(userRespDTO.getNickname()); |
|
|
|
repleinshJobMainDO.setAcceptTime(LocalDateTime.now()); |
|
|
|
trendsApi.createTrends(id, "repleinshJob", "承接了补料任务", TrendsTypeEnum.UPDATE); |
|
|
|
return repleinshJobMainMapper.updateById(repleinshJobMainDO); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public Integer abandonRepleinshJobMain(Long id) { |
|
|
|
RepleinshJobMainDO repleinshJobMainDO = this.validateRepleinshJobMainExists(id); |
|
|
|
JobStatusState jobStatusState = new JobStatusState(repleinshJobMainDO.getStatus()); |
|
|
|
if(!jobStatusState.cancelAccept()) { |
|
|
|
throw exception(REPLEINSH_JOB_MAIN_STATUS_ERROR); |
|
|
|
} |
|
|
|
repleinshJobMainDO.setStatus(jobStatusState.getState().getCode()); |
|
|
|
repleinshJobMainDO.setAcceptUserId(null); |
|
|
|
repleinshJobMainDO.setAcceptUserName(null); |
|
|
|
repleinshJobMainDO.setAcceptTime(null); |
|
|
|
trendsApi.createTrends(id, "repleinshJob", "取消了补料任务", TrendsTypeEnum.UPDATE); |
|
|
|
return repleinshJobMainMapper.updateById(repleinshJobMainDO); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public Integer closeRepleinshJobMain(Long id) { |
|
|
|
RepleinshJobMainDO repleinshJobMainDO = this.validateRepleinshJobMainExists(id); |
|
|
|
JobStatusState jobStatusState = new JobStatusState(repleinshJobMainDO.getStatus()); |
|
|
|
if(!jobStatusState.close()) { |
|
|
|
throw exception(REPLEINSH_JOB_MAIN_STATUS_ERROR); |
|
|
|
} |
|
|
|
repleinshJobMainDO.setStatus(jobStatusState.getState().getCode()); |
|
|
|
trendsApi.createTrends(id, "repleinshJob", "关闭了补料任务", TrendsTypeEnum.UPDATE); |
|
|
|
return repleinshJobMainMapper.updateById(repleinshJobMainDO); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public Integer executeRepleinshJobMain(RepleinshJobMainUpdateReqVO repleinshJobMainUpdateReqVO) { |
|
|
|
//查询数据
|
|
|
|
RepleinshJobMainDO repleinshJobMainDO = this.validateRepleinshJobMainExists(repleinshJobMainUpdateReqVO.getId()); |
|
|
|
List<RepleinshJobDetailDO> subList = repleinshJobDetailService.selectList(repleinshJobMainDO.getId()); |
|
|
|
JobStatusState jobStatusState = new JobStatusState(repleinshJobMainDO.getStatus()); |
|
|
|
boolean flag = jobStatusState.execute(); |
|
|
|
if(!flag) { |
|
|
|
throw new ServiceException(REPLEINSH_JOB_MAIN_STATUS_ERROR); |
|
|
|
} |
|
|
|
//更新完成信息
|
|
|
|
Long userId = getLoginUserId(); |
|
|
|
AdminUserRespDTO userRespDTO = userApi.getUser(userId); |
|
|
|
repleinshJobMainDO.setStatus(jobStatusState.getState().getCode()); |
|
|
|
repleinshJobMainDO.setCompleteTime(LocalDateTime.now()); |
|
|
|
repleinshJobMainDO.setCompleteUserId(String.valueOf(userRespDTO.getId())); |
|
|
|
repleinshJobMainDO.setCompleteUserName(userRespDTO.getNickname()); |
|
|
|
//更新任务表状态
|
|
|
|
int result = repleinshJobMainMapper.updateById(repleinshJobMainDO); |
|
|
|
//创建 发料记录 主表
|
|
|
|
RepleinshRecordMainDO repleinshRecordMainDO = new RepleinshRecordMainDO(); |
|
|
|
BeanUtils.copyProperties(repleinshJobMainDO, repleinshRecordMainDO); |
|
|
|
String number = serialNumberApi.generateCode(RuleCodeEnum.REPLEINMENT_RECORD.getCode()); |
|
|
|
repleinshRecordMainDO.setNumber(number); |
|
|
|
repleinshRecordMainDO.setJobNumber(repleinshJobMainDO.getNumber()); |
|
|
|
repleinshRecordMainDO.setExecuteTime(LocalDateTime.now()); |
|
|
|
repleinshRecordMainDO.setActiveDate(LocalDateTime.now()); |
|
|
|
repleinshRecordMainDO.setAvailable("TRUE"); |
|
|
|
repleinshRecordMainDO.setDueTime(repleinshJobMainDO.getRequestDueTime()); |
|
|
|
repleinshRecordMainDO.setId(null); |
|
|
|
repleinshRecordMainDO.setCreator(null); |
|
|
|
repleinshRecordMainDO.setCreateTime(null); |
|
|
|
repleinshRecordMainDO.setUpdater(null); |
|
|
|
repleinshRecordMainDO.setUpdateTime(null); |
|
|
|
// 接口类型
|
|
|
|
repleinshRecordMainDO.setInterfaceType(recordsettingService.selectRecordsettingExist("RepleinmentRecord").getInterfaceType()); |
|
|
|
//增加业务类型
|
|
|
|
BusinesstypeDO businesstypeDO = jobUtils.selectDocumentSettingFromBusinessType("RepleinmentRecord"); |
|
|
|
repleinshRecordMainDO.setOutTransactionType(businesstypeDO.getOutTransactionType()); |
|
|
|
repleinshRecordMainDO.setInTransactionType(businesstypeDO.getInTransactionType()); |
|
|
|
repleinshRecordMainDO.setBusinessType(businesstypeDO.getCode()); |
|
|
|
repleinshRecordMainMapper.insert(repleinshRecordMainDO); |
|
|
|
// 获取参数中的sublist
|
|
|
|
List<RepleinshJobDetailUpdateReqVO> repleinshJobDetailUpdateReqVOList = repleinshJobMainUpdateReqVO.getSubList(); |
|
|
|
//发料记录子
|
|
|
|
List<RepleinshRecordDetailDO> repleinshRecordDetailDOList = new ArrayList<>(); |
|
|
|
//库存事务
|
|
|
|
List<TransactionCreateReqVO> transactionCreateReqVOList = new ArrayList<>(); |
|
|
|
subList.forEach(subListItem -> { |
|
|
|
// 获取参数中recordLst
|
|
|
|
repleinshJobDetailUpdateReqVOList.forEach(DetailUpdateItem -> { |
|
|
|
// 匹配任务子表与参数中子表
|
|
|
|
if (DetailUpdateItem.getId().equals(subListItem.getId())) { |
|
|
|
List<Map<String,Object>> recordLst = DetailUpdateItem.getRecordLst(); |
|
|
|
recordLst.forEach(recordLstItem -> { |
|
|
|
RepleinshRecordDetailDO repleinshRecordDetailDO = new RepleinshRecordDetailDO(); |
|
|
|
BeanUtils.copyProperties(subListItem, repleinshRecordDetailDO); |
|
|
|
repleinshRecordDetailDO.setId(null); |
|
|
|
repleinshRecordDetailDO.setNumber(number); |
|
|
|
repleinshRecordDetailDO.setMasterId(repleinshRecordMainDO.getId()); |
|
|
|
repleinshRecordDetailDO.setCreator(null); |
|
|
|
repleinshRecordDetailDO.setCreateTime(null); |
|
|
|
repleinshRecordDetailDO.setUpdater(null); |
|
|
|
repleinshRecordDetailDO.setUpdateTime(null); |
|
|
|
// 根据recordLst 进行赋值子表部分数据
|
|
|
|
repleinshRecordDetailDO.setQty(new BigDecimal(recordLstItem.get("handleQty").toString())); |
|
|
|
repleinshRecordDetailDO.setToPackingNumber(recordLstItem.get("toPackingNumber").toString()); |
|
|
|
repleinshRecordDetailDO.setToContainerNumber(recordLstItem.get("toContainerNumber").toString()); |
|
|
|
repleinshRecordDetailDO.setToBatch(recordLstItem.get("toBatch").toString()); |
|
|
|
repleinshRecordDetailDO.setToLocationCode(recordLstItem.get("toLocationCode").toString()); |
|
|
|
repleinshRecordDetailDO.setInventoryStatus(recordLstItem.get("toInventoryStatus").toString()); |
|
|
|
repleinshRecordDetailDO.setSupplierCode(recordLstItem.get("supplierCode").toString()); |
|
|
|
// 根据 to库位 查询 库位组 库区
|
|
|
|
LocationDO locationDO = locationService.selectLocation(recordLstItem.get("toLocationCode").toString()); |
|
|
|
repleinshRecordDetailDO.setToLocationGroupCode(locationDO.getLocationGroupCode()); |
|
|
|
repleinshRecordDetailDO.setToAreaCode(locationDO.getAreaCode()); |
|
|
|
// 根据 from库位 查询 库位组 库区
|
|
|
|
LocationDO locationDOFrom = locationService.selectLocation(subListItem.getFromLocationCode()); |
|
|
|
repleinshRecordDetailDO.setFromLocationGroupCode(locationDOFrom.getLocationGroupCode()); |
|
|
|
repleinshRecordDetailDO.setFromAreaCode(locationDOFrom.getAreaCode()); |
|
|
|
repleinshRecordDetailDOList.add(repleinshRecordDetailDO); |
|
|
|
//添加库存事务list
|
|
|
|
TransactionCreateReqVO transactionCreateReqVO = new TransactionCreateReqVO(); |
|
|
|
BeanUtils.copyProperties(repleinshRecordDetailDO, transactionCreateReqVO); |
|
|
|
TransactiontypeDO transactiontypeDO = jobUtils.selectDocumentFromTransactionType(businesstypeDO.getInTransactionType()); |
|
|
|
transactionCreateReqVO.setWorker(String.valueOf(userApi.getUser(getLoginUserId()).getId())); |
|
|
|
transactionCreateReqVO.setInventoryAction(transactiontypeDO.getInventoryAction()); |
|
|
|
transactionCreateReqVO.setTransactionType(transactiontypeDO.getCode()); |
|
|
|
transactionCreateReqVO.setBusinessType(repleinshRecordMainDO.getBusinessType()); |
|
|
|
transactionCreateReqVO.setOwnerCode(repleinshRecordDetailDO.getFromOwnerCode()); |
|
|
|
transactionCreateReqVO.setRecordNumber(number); |
|
|
|
transactionCreateReqVO.setId(null); |
|
|
|
transactionCreateReqVO.setPackingNumber(repleinshRecordDetailDO.getToPackingNumber()); |
|
|
|
transactionCreateReqVO.setBatch(repleinshRecordDetailDO.getToBatch()); |
|
|
|
transactionCreateReqVO.setContainerNumber(repleinshRecordDetailDO.getToContainerNumber()); |
|
|
|
transactionCreateReqVO.setAmount(BigDecimal.ZERO); |
|
|
|
transactionCreateReqVO.setLocationCode(recordLstItem.get("toLocationCode").toString()); |
|
|
|
transactionCreateReqVOList.add(transactionCreateReqVO); |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
if(!repleinshRecordDetailDOList.isEmpty()) { |
|
|
|
repleinshRecordDetailMapper.insertBatch(repleinshRecordDetailDOList); |
|
|
|
} |
|
|
|
//增加库存事务
|
|
|
|
transactionService.createTransaction(transactionCreateReqVOList); |
|
|
|
//移除预计入
|
|
|
|
expectinService.deleteExpectinByJobNumber(repleinshRecordMainDO.getNumber()); |
|
|
|
//移除预计出
|
|
|
|
expectoutService.deleteExpectoutByJobNumber(repleinshRecordMainDO.getNumber()); |
|
|
|
//变更记录
|
|
|
|
trendsApi.createTrends(repleinshRecordMainDO.getId(), "repleinshJob", "执行了补料任务", TrendsTypeEnum.UPDATE); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|