|
|
|
|
@ -44,6 +44,7 @@ import org.springblade.desk.dashboard.pojo.vo.DsProcessSynthesisVO; |
|
|
|
|
import org.springblade.desk.dashboard.service.*; |
|
|
|
|
import org.springblade.desk.order.pojo.entity.YieldOrder; |
|
|
|
|
import org.springblade.desk.order.service.IYieldOrderService; |
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.context.annotation.Lazy; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
@ -385,4 +386,136 @@ public class DsCraftServiceImpl extends BaseServiceImpl<DsCraftMapper, DsCraftEn |
|
|
|
|
public List<DsCraftEntity> getPartCraft(Long partId, String rank) { |
|
|
|
|
return craftMapper.selectDsCraftByPartIdAndRank(partId,rank); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean craftBatchCopy(DsCraftVO craftVO) { |
|
|
|
|
String partCode = craftVO.getPartCode(); |
|
|
|
|
Long craftId = Long.valueOf(craftVO.getCraftId()); |
|
|
|
|
|
|
|
|
|
// 1. 查询原工艺
|
|
|
|
|
DsCraftEntity oldCraft = this.getById(craftId); |
|
|
|
|
if (oldCraft == null) { |
|
|
|
|
throw new ServiceException("工艺信息不存在"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 2. 查询目标零件
|
|
|
|
|
DsPartEntity part = partService.selectDsPartByPatCodeAndVersion(partCode, null); |
|
|
|
|
if (part == null) { |
|
|
|
|
throw new ServiceException("零件信息不存在"); |
|
|
|
|
} |
|
|
|
|
// 2.1查询版本号
|
|
|
|
|
DsPartVersionEntity partVersion = partVersionService.selectByPartId(part.getId()); |
|
|
|
|
if(partVersion == null){ |
|
|
|
|
throw new ServiceException("零件版本号信息不存在"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 3. 复制工艺(创建新工艺)
|
|
|
|
|
DsCraftEntity newCraft = new DsCraftEntity(); |
|
|
|
|
BeanUtils.copyProperties(oldCraft, newCraft, "id", "createTime", "updateTime"); |
|
|
|
|
newCraft.setId(null); |
|
|
|
|
newCraft.setPartId(part.getId()); |
|
|
|
|
newCraft.setPartCode(part.getPartCode()); |
|
|
|
|
newCraft.setRoamNo(null); |
|
|
|
|
newCraft.setPartVersions(partVersion.getPartVersion()); |
|
|
|
|
this.save(newCraft); |
|
|
|
|
|
|
|
|
|
// 4. 查询原工艺下的所有工序
|
|
|
|
|
List<DsProcessEntity> oldProcessEntities = processService.selectDsProcessByCraftId(craftId); |
|
|
|
|
if (oldProcessEntities.isEmpty()) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 5. 获取原工序ID列表,用于查询关联数据
|
|
|
|
|
List<Long> oldProcessIdList = oldProcessEntities.stream() |
|
|
|
|
.map(DsProcessEntity::getId) |
|
|
|
|
.filter(Objects::nonNull) |
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
// 6. 批量查询原工序的关联数据
|
|
|
|
|
List<Object> allResults = batchQueryAssociations(oldProcessIdList); |
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
|
List<DsProcessProjectEntity> oldProcessProjectEntities = (List<DsProcessProjectEntity>) allResults.get(0); |
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
|
List<DsProcessMeasuringToolEntity> oldProcessMeasuringToolEntities = (List<DsProcessMeasuringToolEntity>) allResults.get(1); |
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
|
List<DsProcessMoldToolEntity> oldProcessMoldToolEntities = (List<DsProcessMoldToolEntity>) allResults.get(2); |
|
|
|
|
|
|
|
|
|
// 7. 创建旧工序ID -> 新工序ID 的映射关系
|
|
|
|
|
Map<Long, Long> processIdMapping = new HashMap<>(); |
|
|
|
|
List<DsProcessEntity> newProcessEntities = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
for (DsProcessEntity oldProcess : oldProcessEntities) { |
|
|
|
|
DsProcessEntity newProcess = new DsProcessEntity(); |
|
|
|
|
BeanUtils.copyProperties(oldProcess, newProcess, "id", "createTime", "updateTime"); |
|
|
|
|
newProcess.setId(null); |
|
|
|
|
newProcess.setCraftId(newCraft.getId()); |
|
|
|
|
newProcessEntities.add(newProcess); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 8. 批量保存新工序
|
|
|
|
|
processService.saveBatch(newProcessEntities); |
|
|
|
|
|
|
|
|
|
// 9. 建立新旧工序ID映射关系(保存后新工序会生成ID)
|
|
|
|
|
for (int i = 0; i < oldProcessEntities.size(); i++) { |
|
|
|
|
processIdMapping.put(oldProcessEntities.get(i).getId(), newProcessEntities.get(i).getId()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 10. 复制工序项目(尺寸)数据
|
|
|
|
|
if (CollectionUtils.isNotEmpty(oldProcessProjectEntities)) { |
|
|
|
|
List<DsProcessProjectEntity> newProcessProjectEntities = new ArrayList<>(); |
|
|
|
|
for (DsProcessProjectEntity oldEntity : oldProcessProjectEntities) { |
|
|
|
|
DsProcessProjectEntity newEntity = new DsProcessProjectEntity(); |
|
|
|
|
BeanUtils.copyProperties(oldEntity, newEntity, "id", "createTime", "updateTime"); |
|
|
|
|
newEntity.setId(null); |
|
|
|
|
// 关键:将旧的processId映射为新的processId
|
|
|
|
|
Long newProcessId = processIdMapping.get(oldEntity.getProcessId()); |
|
|
|
|
if (newProcessId != null) { |
|
|
|
|
newEntity.setProcessId(newProcessId); |
|
|
|
|
newProcessProjectEntities.add(newEntity); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (CollectionUtils.isNotEmpty(newProcessProjectEntities)) { |
|
|
|
|
processProjectService.saveBatch(newProcessProjectEntities); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 11. 复制工序量具数据
|
|
|
|
|
if (CollectionUtils.isNotEmpty(oldProcessMeasuringToolEntities)) { |
|
|
|
|
List<DsProcessMeasuringToolEntity> newProcessMeasuringToolEntities = new ArrayList<>(); |
|
|
|
|
for (DsProcessMeasuringToolEntity oldEntity : oldProcessMeasuringToolEntities) { |
|
|
|
|
DsProcessMeasuringToolEntity newEntity = new DsProcessMeasuringToolEntity(); |
|
|
|
|
BeanUtils.copyProperties(oldEntity, newEntity, "id", "createTime", "updateTime"); |
|
|
|
|
newEntity.setId(null); |
|
|
|
|
Long newProcessId = processIdMapping.get(oldEntity.getProcessId()); |
|
|
|
|
if (newProcessId != null) { |
|
|
|
|
newEntity.setProcessId(newProcessId); |
|
|
|
|
newProcessMeasuringToolEntities.add(newEntity); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (CollectionUtils.isNotEmpty(newProcessMeasuringToolEntities)) { |
|
|
|
|
processMeasuringToolService.saveBatch(newProcessMeasuringToolEntities); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 12. 复制工序工装模具数据
|
|
|
|
|
if (CollectionUtils.isNotEmpty(oldProcessMoldToolEntities)) { |
|
|
|
|
List<DsProcessMoldToolEntity> newProcessMoldToolEntities = new ArrayList<>(); |
|
|
|
|
for (DsProcessMoldToolEntity oldEntity : oldProcessMoldToolEntities) { |
|
|
|
|
DsProcessMoldToolEntity newEntity = new DsProcessMoldToolEntity(); |
|
|
|
|
BeanUtils.copyProperties(oldEntity, newEntity, "id", "createTime", "updateTime"); |
|
|
|
|
newEntity.setId(null); |
|
|
|
|
Long newProcessId = processIdMapping.get(oldEntity.getProcessId()); |
|
|
|
|
if (newProcessId != null) { |
|
|
|
|
newEntity.setProcessId(newProcessId); |
|
|
|
|
newProcessMoldToolEntities.add(newEntity); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (CollectionUtils.isNotEmpty(newProcessMoldToolEntities)) { |
|
|
|
|
processMoldToolService.saveBatch(newProcessMoldToolEntities); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|