|
|
|
|
@ -10,15 +10,23 @@ import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.dromara.mes.domain.bo.ProdRecipeInfoBo;
|
|
|
|
|
import org.dromara.mes.domain.bo.ProdRecipeWeightBo;
|
|
|
|
|
import org.dromara.mes.domain.bo.ProdRecipeMixingBo;
|
|
|
|
|
import org.dromara.mes.domain.bo.RecipeDetailSaveBo;
|
|
|
|
|
import org.dromara.mes.domain.vo.ProdRecipeInfoVo;
|
|
|
|
|
import org.dromara.mes.domain.ProdRecipeInfo;
|
|
|
|
|
import org.dromara.mes.mapper.ProdRecipeInfoMapper;
|
|
|
|
|
import org.dromara.mes.service.IProdRecipeInfoService;
|
|
|
|
|
import org.dromara.mes.service.IProdRecipeWeightService;
|
|
|
|
|
import org.dromara.mes.service.IProdRecipeMixingService;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 配方-基础信息Service业务层处理
|
|
|
|
|
@ -31,6 +39,8 @@ import java.util.Collection;
|
|
|
|
|
public class ProdRecipeInfoServiceImpl implements IProdRecipeInfoService {
|
|
|
|
|
|
|
|
|
|
private final ProdRecipeInfoMapper baseMapper;
|
|
|
|
|
private final IProdRecipeWeightService prodRecipeWeightService;
|
|
|
|
|
private final IProdRecipeMixingService prodRecipeMixingService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询配方-基础信息
|
|
|
|
|
@ -75,7 +85,7 @@ public class ProdRecipeInfoServiceImpl implements IProdRecipeInfoService {
|
|
|
|
|
.selectAll(ProdRecipeInfo.class)
|
|
|
|
|
.eq(bo.getRecipeId() != null, ProdRecipeInfo::getRecipeId, bo.getRecipeId())
|
|
|
|
|
.eq(bo.getMachineId() != null, ProdRecipeInfo::getMachineId, bo.getMachineId())
|
|
|
|
|
.eq(StringUtils.isNotBlank(bo.getMaterialId()), ProdRecipeInfo::getMaterialId, bo.getMaterialId())
|
|
|
|
|
.eq(bo.getMaterialId() != null, ProdRecipeInfo::getMaterialId, bo.getMaterialId())
|
|
|
|
|
.eq(bo.getEdtCode() != null, ProdRecipeInfo::getEdtCode, bo.getEdtCode())
|
|
|
|
|
.eq(bo.getRecipeType() != null, ProdRecipeInfo::getRecipeType, bo.getRecipeType())
|
|
|
|
|
.eq(StringUtils.isNotBlank(bo.getUserEdtCode()), ProdRecipeInfo::getUserEdtCode, bo.getUserEdtCode())
|
|
|
|
|
@ -189,4 +199,96 @@ public class ProdRecipeInfoServiceImpl implements IProdRecipeInfoService {
|
|
|
|
|
}
|
|
|
|
|
return baseMapper.deleteByIds(ids) > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Boolean saveDetail(RecipeDetailSaveBo bo) {
|
|
|
|
|
ProdRecipeInfoBo recipeInfo = bo.getRecipeInfo();
|
|
|
|
|
if (recipeInfo == null || recipeInfo.getRecipeId() == null) {
|
|
|
|
|
throw new IllegalArgumentException("配方ID不能为空");
|
|
|
|
|
}
|
|
|
|
|
Long recipeId = recipeInfo.getRecipeId();
|
|
|
|
|
// 1. 更新配方基本信息
|
|
|
|
|
updateByBo(recipeInfo);
|
|
|
|
|
|
|
|
|
|
// 2. 称量信息:有主键则更新,无主键则插入;删除提交列表中已不存在的原记录
|
|
|
|
|
List<ProdRecipeWeightBo> weightList = bo.getWeightList() != null ? bo.getWeightList() : new ArrayList<>();
|
|
|
|
|
List<Long> submittedWeightIds = weightList.stream()
|
|
|
|
|
.map(ProdRecipeWeightBo::getWeightId)
|
|
|
|
|
.filter(id -> id != null)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
ProdRecipeWeightBo weightQuery = new ProdRecipeWeightBo();
|
|
|
|
|
weightQuery.setRecipeId(recipeId);
|
|
|
|
|
List<Long> existingWeightIds = prodRecipeWeightService.queryList(weightQuery).stream()
|
|
|
|
|
.map(vo -> vo.getWeightId())
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
List<Long> weightIdsToDelete = existingWeightIds.stream()
|
|
|
|
|
.filter(id -> !submittedWeightIds.contains(id))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
if (!weightIdsToDelete.isEmpty()) {
|
|
|
|
|
prodRecipeWeightService.deleteWithValidByIds(weightIdsToDelete, false);
|
|
|
|
|
}
|
|
|
|
|
int weightSeq = 0;
|
|
|
|
|
for (ProdRecipeWeightBo w : weightList) {
|
|
|
|
|
if (w.getSetWeight() == null && StringUtils.isBlank(w.getActCode()) && StringUtils.isNull(w.getChildCode())) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
weightSeq++;
|
|
|
|
|
w.setRecipeId(recipeId);
|
|
|
|
|
if (w.getMachineId() == null) {
|
|
|
|
|
w.setMachineId(recipeInfo.getMachineId());
|
|
|
|
|
}
|
|
|
|
|
if (w.getEdtCode() == null) {
|
|
|
|
|
w.setEdtCode(recipeInfo.getEdtCode());
|
|
|
|
|
}
|
|
|
|
|
w.setWeightSeq((long) weightSeq);
|
|
|
|
|
if (w.getWeightId() != null) {
|
|
|
|
|
prodRecipeWeightService.updateByBo(w);
|
|
|
|
|
} else {
|
|
|
|
|
w.setWeightId(null);
|
|
|
|
|
prodRecipeWeightService.insertByBo(w);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 3. 混炼信息:有主键则更新,无主键则插入;删除提交列表中已不存在的原记录
|
|
|
|
|
List<ProdRecipeMixingBo> mixingList = bo.getMixingList() != null ? bo.getMixingList() : new ArrayList<>();
|
|
|
|
|
List<Long> submittedMixingIds = mixingList.stream()
|
|
|
|
|
.map(ProdRecipeMixingBo::getMixingId)
|
|
|
|
|
.filter(id -> id != null)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
ProdRecipeMixingBo mixingQuery = new ProdRecipeMixingBo();
|
|
|
|
|
mixingQuery.setRecipeId(recipeId);
|
|
|
|
|
List<Long> existingMixingIds = prodRecipeMixingService.queryList(mixingQuery).stream()
|
|
|
|
|
.map(vo -> vo.getMixingId())
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
List<Long> mixingIdsToDelete = existingMixingIds.stream()
|
|
|
|
|
.filter(id -> !submittedMixingIds.contains(id))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
if (!mixingIdsToDelete.isEmpty()) {
|
|
|
|
|
prodRecipeMixingService.deleteWithValidByIds(mixingIdsToDelete, false);
|
|
|
|
|
}
|
|
|
|
|
int mixSeq = 0;
|
|
|
|
|
for (ProdRecipeMixingBo m : mixingList) {
|
|
|
|
|
if (StringUtils.isBlank(m.getActCode()) && m.getSetTime() == null && m.getSetTemp() == null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
mixSeq++;
|
|
|
|
|
m.setRecipeId(recipeId);
|
|
|
|
|
if (m.getMachineId() == null) {
|
|
|
|
|
m.setMachineId(recipeInfo.getMachineId());
|
|
|
|
|
}
|
|
|
|
|
if (m.getEdtCode() == null) {
|
|
|
|
|
m.setEdtCode(recipeInfo.getEdtCode());
|
|
|
|
|
}
|
|
|
|
|
m.setMixId((long) mixSeq);
|
|
|
|
|
if (m.getMixingId() != null) {
|
|
|
|
|
prodRecipeMixingService.updateByBo(m);
|
|
|
|
|
} else {
|
|
|
|
|
m.setMixingId(null);
|
|
|
|
|
prodRecipeMixingService.insertByBo(m);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|