|
|
@ -1,6 +1,7 @@
|
|
|
|
package cn.iocoder.yudao.module.product.service.harvestinfo;
|
|
|
|
package cn.iocoder.yudao.module.product.service.harvestinfo;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
import cn.iocoder.yudao.framework.common.enums.BlockStateEnum;
|
|
|
|
import cn.iocoder.yudao.framework.common.enums.BlockStateEnum;
|
|
|
|
import cn.iocoder.yudao.framework.common.enums.CodeEnum;
|
|
|
|
import cn.iocoder.yudao.framework.common.enums.CodeEnum;
|
|
|
|
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
|
|
|
|
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
|
|
|
@ -20,6 +21,8 @@ import cn.iocoder.yudao.module.chain.enums.ChainStatusEnum;
|
|
|
|
import cn.iocoder.yudao.module.chain.enums.OperateTypeEnum;
|
|
|
|
import cn.iocoder.yudao.module.chain.enums.OperateTypeEnum;
|
|
|
|
import cn.iocoder.yudao.module.configure.api.uniTemplate.UniTemplateApi;
|
|
|
|
import cn.iocoder.yudao.module.configure.api.uniTemplate.UniTemplateApi;
|
|
|
|
import cn.iocoder.yudao.module.configure.api.uniTemplate.dto.UniTemplateDTO;
|
|
|
|
import cn.iocoder.yudao.module.configure.api.uniTemplate.dto.UniTemplateDTO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.identity.api.generaterecord.GenerateRecordApi;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.identity.api.generaterecord.dto.GenerateRecordDTO;
|
|
|
|
import cn.iocoder.yudao.module.product.controller.admin.harvestbatch.vo.HarvestBatchBaseVO;
|
|
|
|
import cn.iocoder.yudao.module.product.controller.admin.harvestbatch.vo.HarvestBatchBaseVO;
|
|
|
|
import cn.iocoder.yudao.module.product.controller.admin.harvestbatch.vo.HarvestBatchRespVO;
|
|
|
|
import cn.iocoder.yudao.module.product.controller.admin.harvestbatch.vo.HarvestBatchRespVO;
|
|
|
|
import cn.iocoder.yudao.module.product.controller.admin.harvestbatch.vo.HarvestBatchSaveReqVO;
|
|
|
|
import cn.iocoder.yudao.module.product.controller.admin.harvestbatch.vo.HarvestBatchSaveReqVO;
|
|
|
@ -77,6 +80,9 @@ public class HarvestInfoServiceImpl implements HarvestInfoService {
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private LanguageTypeApi languageTypeApi;
|
|
|
|
private LanguageTypeApi languageTypeApi;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private GenerateRecordApi generateRecordApi;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public Long createHarvestInfo(HarvestInfoCreateReqVO createReqVO) {
|
|
|
|
public Long createHarvestInfo(HarvestInfoCreateReqVO createReqVO) {
|
|
|
@ -150,14 +156,18 @@ public class HarvestInfoServiceImpl implements HarvestInfoService {
|
|
|
|
throw ServiceExceptionUtil.exception(ErrorCodeConstants.ONLY_NOT_ON_CHAIN_HARVEST_INFO_CAN_BE_EDIT);
|
|
|
|
throw ServiceExceptionUtil.exception(ErrorCodeConstants.ONLY_NOT_ON_CHAIN_HARVEST_INFO_CAN_BE_EDIT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<HarvestBatchDO> DBHarvestBatchList = harvestBatchMapper.selectList(new LambdaQueryWrapperX<HarvestBatchDO>()
|
|
|
|
|
|
|
|
.eq(HarvestBatchDO::getHarvestId, harvestInfo.getHarverstId()));
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, GoodsInfoRespDTO> goodsInfoMap = new HashMap<>();
|
|
|
|
Map<String, GoodsInfoRespDTO> goodsInfoMap = new HashMap<>();
|
|
|
|
List<Long> willUpdateIds = new ArrayList<>();// 将要更新的投入品批次主键id
|
|
|
|
List<Long> willUpdateIds = new ArrayList<>();// 将要更新的投入品批次主键id
|
|
|
|
this.verifiGoodsInfos(updateReqVO.getHarvestBatchs(), goodsInfoMap, willUpdateIds, harvestInfo.getBelongBusinessId());
|
|
|
|
this.verifiGoodsInfos(updateReqVO.getHarvestBatchs(), goodsInfoMap, willUpdateIds, harvestInfo.getBelongBusinessId());
|
|
|
|
|
|
|
|
List<Long> DBBatchIds = DBHarvestBatchList.stream().map(HarvestBatchDO::getId).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
// 验证将要更新的批次
|
|
|
|
// 验证将要更新的批次
|
|
|
|
Map<Long, HarvestBatchDO> harvestBatchMaps = new HashMap<>();// 采收批次键值对
|
|
|
|
Map<Long, HarvestBatchDO> harvestBatchMaps = new HashMap<>();// 采收批次键值对
|
|
|
|
// 验证将要更新的批次
|
|
|
|
// 验证将要更新的批次
|
|
|
|
if(willUpdateIds.size() > 0) {
|
|
|
|
if (!willUpdateIds.isEmpty()) {
|
|
|
|
List<HarvestBatchDO> harvestBatchDOs = harvestBatchMapper.selectList(new LambdaQueryWrapperX<HarvestBatchDO>()
|
|
|
|
List<HarvestBatchDO> harvestBatchDOs = harvestBatchMapper.selectList(new LambdaQueryWrapperX<HarvestBatchDO>()
|
|
|
|
.in(HarvestBatchDO::getId, willUpdateIds)
|
|
|
|
.in(HarvestBatchDO::getId, willUpdateIds)
|
|
|
|
.eq(HarvestBatchDO::getHarvestId, harvestInfo.getHarverstId()));
|
|
|
|
.eq(HarvestBatchDO::getHarvestId, harvestInfo.getHarverstId()));
|
|
|
@ -170,6 +180,7 @@ public class HarvestInfoServiceImpl implements HarvestInfoService {
|
|
|
|
|
|
|
|
|
|
|
|
List<HarvestBatchDO> addList = new ArrayList<>(); // 需要新增的批次集合
|
|
|
|
List<HarvestBatchDO> addList = new ArrayList<>(); // 需要新增的批次集合
|
|
|
|
List<HarvestBatchDO> updateList = new ArrayList<>(); // 需要新增的批次集合
|
|
|
|
List<HarvestBatchDO> updateList = new ArrayList<>(); // 需要新增的批次集合
|
|
|
|
|
|
|
|
Collection<Long> deleteIds = CollUtil.subtract(DBBatchIds, willUpdateIds);// 需要删除的批次集合
|
|
|
|
for (HarvestBatchSaveReqVO item: updateReqVO.getHarvestBatchs()) {
|
|
|
|
for (HarvestBatchSaveReqVO item: updateReqVO.getHarvestBatchs()) {
|
|
|
|
if (item.getId() != null) {
|
|
|
|
if (item.getId() != null) {
|
|
|
|
// 更新流程
|
|
|
|
// 更新流程
|
|
|
@ -200,13 +211,17 @@ public class HarvestInfoServiceImpl implements HarvestInfoService {
|
|
|
|
|
|
|
|
|
|
|
|
harvestInfoMapper.updateById(harvestInfoDO);
|
|
|
|
harvestInfoMapper.updateById(harvestInfoDO);
|
|
|
|
|
|
|
|
|
|
|
|
if(updateList.size() > 0) {
|
|
|
|
if (!updateList.isEmpty()) {
|
|
|
|
harvestBatchMapper.updateBatch(updateList, Integer.MAX_VALUE);
|
|
|
|
harvestBatchMapper.updateBatch(updateList, Integer.MAX_VALUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(addList.size() > 0) {
|
|
|
|
if (!addList.isEmpty()) {
|
|
|
|
harvestBatchMapper.insertBatch(addList);
|
|
|
|
harvestBatchMapper.insertBatch(addList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!deleteIds.isEmpty()) {
|
|
|
|
|
|
|
|
harvestBatchMapper.deleteBatchIds(deleteIds);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void verifiGoodsInfos(List<HarvestBatchSaveReqVO> harvestBatchs, Map<String, GoodsInfoRespDTO> goodsInfoMap, List<Long> willUpdateIds, Long businessInfoId) {
|
|
|
|
private void verifiGoodsInfos(List<HarvestBatchSaveReqVO> harvestBatchs, Map<String, GoodsInfoRespDTO> goodsInfoMap, List<Long> willUpdateIds, Long businessInfoId) {
|
|
|
@ -245,17 +260,33 @@ public class HarvestInfoServiceImpl implements HarvestInfoService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
public void deleteHarvestInfo(Long id) {
|
|
|
|
public void deleteHarvestInfo(Long id) {
|
|
|
|
// 校验存在
|
|
|
|
// 校验存在
|
|
|
|
validateHarvestInfoExists(id);
|
|
|
|
HarvestInfoDO harvestInfo = validateHarvestInfoExists(id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HarvestBatchDO harvestBatch = harvestBatchMapper.selectOne(new LambdaQueryWrapperX<HarvestBatchDO>().eq(HarvestBatchDO::getHarvestId, harvestInfo.getHarverstId()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (harvestBatch != null) {
|
|
|
|
|
|
|
|
// 校验是否已生成码包
|
|
|
|
|
|
|
|
GenerateRecordDTO generateRecord = generateRecordApi.getByBatchId(harvestBatch.getHarvestBatchId()).getData();
|
|
|
|
|
|
|
|
if (generateRecord != null) {
|
|
|
|
|
|
|
|
throw ServiceExceptionUtil.exception(ErrorCodeConstants.CAN_NOT_DELETE_BECAUSE_EXIST_GENERATE_RECORD);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
harvestBatchMapper.deleteById(harvestBatch.getId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 删除
|
|
|
|
// 删除
|
|
|
|
harvestInfoMapper.deleteById(id);
|
|
|
|
harvestInfoMapper.deleteById(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void validateHarvestInfoExists(Long id) {
|
|
|
|
private HarvestInfoDO validateHarvestInfoExists(Long id) {
|
|
|
|
if (harvestInfoMapper.selectById(id) == null) {
|
|
|
|
HarvestInfoDO harvestInfo = harvestInfoMapper.selectById(id);
|
|
|
|
|
|
|
|
if (harvestInfo == null) {
|
|
|
|
throw ServiceExceptionUtil.exception(ErrorCodeConstants.HARVEST_INFO_NOT_EXISTS);
|
|
|
|
throw ServiceExceptionUtil.exception(ErrorCodeConstants.HARVEST_INFO_NOT_EXISTS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return harvestInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -270,7 +301,7 @@ public class HarvestInfoServiceImpl implements HarvestInfoService {
|
|
|
|
List<HarvestBatchRespVO> harvestBatchResps = HarvestBatchConvert.INSTANCE.convertList(list);
|
|
|
|
List<HarvestBatchRespVO> harvestBatchResps = HarvestBatchConvert.INSTANCE.convertList(list);
|
|
|
|
List<String> goodsIds = harvestBatchResps.stream().map(HarvestBatchBaseVO::getGoodsId).collect(Collectors.toList());
|
|
|
|
List<String> goodsIds = harvestBatchResps.stream().map(HarvestBatchBaseVO::getGoodsId).collect(Collectors.toList());
|
|
|
|
List<GoodsInfoRespDTO> goodsInfos = goodsInfoApi.getGoodsInfoListByGoodsIds(goodsIds, harvestInfo.getBelongBusinessId()).getData();
|
|
|
|
List<GoodsInfoRespDTO> goodsInfos = goodsInfoApi.getGoodsInfoListByGoodsIds(goodsIds, harvestInfo.getBelongBusinessId()).getData();
|
|
|
|
if(goodsInfos != null && !goodsInfos.isEmpty() || Objects.requireNonNull(goodsInfos).size() != goodsIds.size()) {
|
|
|
|
if(goodsInfos != null && !goodsInfos.isEmpty()) {
|
|
|
|
Map<String, GoodsInfoRespDTO> goodsInfoMap = new HashMap<>();
|
|
|
|
Map<String, GoodsInfoRespDTO> goodsInfoMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
goodsInfos.forEach(item -> goodsInfoMap.put(item.getGoodsId(), item));
|
|
|
|
goodsInfos.forEach(item -> goodsInfoMap.put(item.getGoodsId(), item));
|
|
|
|