Commit 6c290ab6 by lijingjing

查询优化:父级分类一次性查询;

parent d26d8ca8
...@@ -8,7 +8,6 @@ import com.baomidou.mybatisplus.toolkit.IdWorker; ...@@ -8,7 +8,6 @@ import com.baomidou.mybatisplus.toolkit.IdWorker;
import com.patzn.cloud.commons.api.RestAssert; import com.patzn.cloud.commons.api.RestAssert;
import com.patzn.cloud.commons.controller.Account; import com.patzn.cloud.commons.controller.Account;
import com.patzn.cloud.commons.controller.LoginHelper; import com.patzn.cloud.commons.controller.LoginHelper;
import com.patzn.cloud.commons.exception.PatznException;
import com.patzn.cloud.commons.service.impl.BaseServiceImpl; import com.patzn.cloud.commons.service.impl.BaseServiceImpl;
import com.patzn.cloud.commons.toolkit.*; import com.patzn.cloud.commons.toolkit.*;
import com.patzn.cloud.feign.base.client.SysOrgClient; import com.patzn.cloud.feign.base.client.SysOrgClient;
...@@ -203,20 +202,23 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> ...@@ -203,20 +202,23 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
* *
* @param sample * @param sample
*/ */
private void sampleCodeHandler(EntrustSample sample) { private void fillCodeAfterHandle(EntrustSample sample) {
String code = sample.getCode(), firstCode = sample.getFirstCode(), String code = sample.getCode(),
secondCode = sample.getSecondCode(), thirdCode = sample.getThirdCode(); firstCode = sample.getFirstCode(),
secondCode = sample.getSecondCode(),
thirdCode = sample.getThirdCode();
if (StringUtils.isNotBlank(code)) { if (StringUtils.isNotBlank(code)) {
sample.setCode(code.trim().toUpperCase()); sample.setCode(StringHandleUtils.toUpper(code));
} }
if (StringUtils.isNotBlank(firstCode)) { if (StringUtils.isNotBlank(firstCode)) {
sample.setFirstCode(firstCode.trim().toUpperCase()); sample.setFirstCode(StringHandleUtils.toUpper(firstCode));
} }
if (StringUtils.isNotBlank(secondCode)) { if (StringUtils.isNotBlank(secondCode)) {
sample.setFirstCode(secondCode.trim().toUpperCase()); sample.setFirstCode(StringHandleUtils.toUpper(secondCode));
} }
if (StringUtils.isNotBlank(thirdCode)) { if (StringUtils.isNotBlank(thirdCode)) {
sample.setFirstCode(thirdCode.trim().toUpperCase()); sample.setFirstCode(StringHandleUtils.toUpper(thirdCode));
} }
} }
...@@ -230,7 +232,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> ...@@ -230,7 +232,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
sample.setSlotNo(slotNo.trim()); sample.setSlotNo(slotNo.trim());
} }
public void initSampleCode(Entrust entrust, EntrustSample sample) { public void initSampleCode(Entrust entrust, EntrustSample sample, Map<String, LmsChemicalCategory> categoryMap) {
// 如果合同编号不为空,样品编号不为空,一级编号不为空,则不进行编号生成 // 如果合同编号不为空,样品编号不为空,一级编号不为空,则不进行编号生成
if (null != sample.getContractSampleId() && StringUtils.isNotBlank(sample.getCode()) && StringUtils.isNotBlank(sample.getFirstCode())) { if (null != sample.getContractSampleId() && StringUtils.isNotBlank(sample.getCode()) && StringUtils.isNotBlank(sample.getFirstCode())) {
return; return;
...@@ -240,7 +242,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> ...@@ -240,7 +242,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
RestAssert.fail(StringUtils.isBlank(category), "样品类型不能为空"); RestAssert.fail(StringUtils.isBlank(category), "样品类型不能为空");
String parentCategory = ""; String parentCategory = "";
if (StringUtils.isNotBlank(category)) { if (StringUtils.isNotBlank(category)) {
LmsChemicalCategory chemicalCategory = lmsChemicalCategoryClient.getTopCategory(category).getData(); LmsChemicalCategory chemicalCategory = categoryMap.get(category);
RestAssert.fail(null == chemicalCategory, "样品(物资)类型不能为空"); RestAssert.fail(null == chemicalCategory, "样品(物资)类型不能为空");
parentCategory = chemicalCategory.getName(); parentCategory = chemicalCategory.getName();
} }
...@@ -398,11 +400,13 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> ...@@ -398,11 +400,13 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
/** /**
* 样品编号处理 * 样品编号处理
*/ */
private void handleSampleCode(Entrust entrust, EntrustSample sample) { private void handleSampleCode(Entrust entrust, EntrustSample sample, Map<String, LmsChemicalCategory> categoryMap) {
String sampleCode = sample.getCode(), secondCode = sample.getSecondCode(), thirdCode = sample.getThirdCode(); String
if (isExistSampleCode(sample) && StringUtils.isBlank(sampleCode)) { sampleCode = sample.getCode(),
throw new PatznException("样品编号为空"); secondCode = sample.getSecondCode(),
} thirdCode = sample.getThirdCode();
// 若为【已有编码物质】,且编号为空的情况下,提示【编号为空】
RestAssert.fail(isExistSampleCode(sample) && StringUtils.isBlank(sampleCode), "样品编号为空");
// 非已有编码物质为空时,需要生成样品编号 // 非已有编码物质为空时,需要生成样品编号
// 若有采样ID,样品编号自动获取 // 若有采样ID,样品编号自动获取
Long samplingId = sample.getSamplingId(); Long samplingId = sample.getSamplingId();
...@@ -418,7 +422,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> ...@@ -418,7 +422,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
} }
sample.setThirdCode(thirdCode); sample.setThirdCode(thirdCode);
} else { } else {
initSampleCode(entrust, sample); initSampleCode(entrust, sample, categoryMap);
if (StringUtils.isNotBlank(sampleCode)) { if (StringUtils.isNotBlank(sampleCode)) {
sample.setCode(sampleCode); sample.setCode(sampleCode);
sample.setFirstCode(sampleCode); sample.setFirstCode(sampleCode);
...@@ -488,19 +492,10 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> ...@@ -488,19 +492,10 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
// 保存并提交委托时使用 // 保存并提交委托时使用
dto.setId(entrust.getId()); dto.setId(entrust.getId());
// == // ==
// 先对样品进行处理 List<?> dataList = verifyAndPrepareSampleData(sampleDTOList, isSubmit);
Set<String> sampleNames = new HashSet<>(), sampleCodes = new HashSet<>(), sampleSlots = new HashSet<>(); String sampleName = dataList.get(0).toString();
entrust.setSampleName(sampleName);
for (EntrustSampleDTO sampleDTO : sampleDTOList) { Map<String, LmsChemicalCategory> categoryMap = (Map<String, LmsChemicalCategory>) dataList.get(1);
String sname = sampleDTO.getName(), scode = sampleDTO.getCode(), slotNo = sampleDTO.getSlotNo();
RestAssert.fail(StringUtils.isNotBlank(scode) && sampleCodes.contains(scode), String.format("样品编号【%s】重复!", scode));
RestAssert.fail(StringUtils.isNotBlank(slotNo) && sampleSlots.contains(slotNo), String.format("样品槽号【%s】重复!", scode));
sampleNames.add(sname);
sampleCodes.add(scode);
sampleSlots.add(slotNo);
}
RestAssert.fail(sampleNames.size() > 1, "一个委托只能下同一种样品!");
List<EntrustSample> saveSampleList = new ArrayList<>(); List<EntrustSample> saveSampleList = new ArrayList<>();
List<EntrustSampleItem> saveEntrustSampleItemList = new ArrayList<>(); List<EntrustSampleItem> saveEntrustSampleItemList = new ArrayList<>();
...@@ -510,16 +505,17 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> ...@@ -510,16 +505,17 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
if (null != sampleDTO.getContractSampleId()) { if (null != sampleDTO.getContractSampleId()) {
contractSampleIds.add(sampleDTO.getContractSampleId()); contractSampleIds.add(sampleDTO.getContractSampleId());
} }
EntrustSample sample = sampleDTO.convert(EntrustSample.class); EntrustSample sample = sampleDTO.convert(EntrustSample.class);
sample.setEntrustId(entrust.getId()); initSampleJudgeNew(entrust.getId(), incNum, sample);
sampleSlotNoHandler(sample);
// 只有在提交时,才初始化样品编号 // 只有在提交时,才初始化样品编号
if (isSubmit) { if (isSubmit) {
// 判断是否样品为空时,需要考虑是否进场物资 // 判断是否样品为空时,需要考虑是否进场物资
// 若为进场物资,需要考虑是否为采样样品 // 若为进场物资,需要考虑是否为采样样品
// 若为采样样品,需要赋值采样样品编号 // 若为采样样品,需要赋值采样样品编号
if (StringUtils.isBlank(sample.getCode()) || Objects.nonNull(sample.getSamplingId())) { if (StringUtils.isBlank(sample.getCode()) || Objects.nonNull(sample.getSamplingId())) {
handleSampleCode(entrust, sample); handleSampleCode(entrust, sample, categoryMap);
} }
if (StringUtils.isNotBlank(sample.getCode())) { if (StringUtils.isNotBlank(sample.getCode())) {
sample.setCode(sample.getCode().trim().toUpperCase()); sample.setCode(sample.getCode().trim().toUpperCase());
...@@ -528,33 +524,29 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> ...@@ -528,33 +524,29 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
} }
} }
// 处理下编号 // 处理下编号
sampleCodeHandler(sample); fillCodeAfterHandle(sample);
judgeSampleFields(sample, isSubmit); judgeSampleFields(sample, isSubmit);
sample.setId(IdWorker.getId());
sample.setOrderBy(incNum);
saveSampleList.add(sample); saveSampleList.add(sample);
logger.error("添加了编号为【{}】的【{}】样品。", sample.getCode(), sample.getName());
// 样品的顺序号,为了插入标样方便设置 // 样品的顺序号,为了插入标样方便设置
incNum += 10; incNum += 10;
List<EntrustSampleItem> experiments = sampleDTO.getItemList(); List<EntrustSampleItem> itemList = sampleDTO.getItemList();
if (CollectionUtils.isEmpty(experiments)) { if (CollectionUtils.isEmpty(itemList)) {
logger.error("✦✦✦✦ EntrustServiceImpl ✦✦✦✦ saveEntrustDTO ✦✦✦✈ 【{},{}】检测项目数据为空!", sample.getId(), sample.getCode());
continue; continue;
} }
for (EntrustSampleItem sampleItem : experiments) { for (EntrustSampleItem sampleItem : itemList) {
if (null != sampleItem.getPrice()) { if (null != sampleItem.getPrice()) {
totalFee = totalFee.add(sampleItem.getPrice()); totalFee = totalFee.add(sampleItem.getPrice());
} }
sampleItem.setEntrustSampleId(sample.getId()); sampleItem.setEntrustSampleId(sample.getId());
sampleItem.setEntrustId(entrust.getId()); sampleItem.setEntrustId(entrust.getId());
saveEntrustSampleItemList.add(sampleItem); saveEntrustSampleItemList.add(sampleItem);
} }
} }
//计算费用 //计算费用
entrust.setTotalFee(totalFee); entrust.setTotalFee(totalFee);
//保存样品名称
entrust.setSampleName(sampleDTOList.get(0).getName());
saveEntrust(entrust); saveEntrust(entrust);
if (CollectionUtils.isNotEmpty(saveSampleList)) { if (CollectionUtils.isNotEmpty(saveSampleList)) {
entrustSampleService.saveBatch(saveSampleList); entrustSampleService.saveBatch(saveSampleList);
...@@ -570,8 +562,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> ...@@ -570,8 +562,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
private void retakeSourceCodeHandle(EntrustSample sample) { private void retakeSourceCodeHandle(EntrustSample sample) {
// 判定是否原铝重取 // 判定是否原铝重取
String name = sample.getName(); if (!Objects.equals("原铝重取", sample.getName())) {
if (!"原铝重取".equals(name)) {
return; return;
} }
String code = sample.getCode(); String code = sample.getCode();
...@@ -729,28 +720,20 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> ...@@ -729,28 +720,20 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public boolean editEntrust(EntrustDTO entrustDTO, boolean isSubmit, Account account) { public boolean editEntrust(EntrustDTO dto, boolean isSubmit, Account account) {
final Long entrustId = entrustDTO.getId(); final Long entrustId = dto.getId();
// ==
RestAssert.fail(Objects.isNull(entrustId), "委托编号为空"); RestAssert.fail(Objects.isNull(entrustId), "委托编号为空");
List<EntrustSampleDTO> sampleList = entrustDTO.getSampleDTOList(); // ==
RestAssert.fail(CollectionUtils.isEmpty(sampleList), "委托样品为空"); List<EntrustSampleDTO> sampleList = dto.getSampleDTOList();
RestAssert.fail(sampleList.stream().map(EntrustSampleDTO::getName).distinct().count() > 1, "一个委托只能下同一种样品!"); // == 验证 ==> 样品信息
Set<String> sampleNames = new HashSet<>(), sampleCodes = new HashSet<>(), sampleSlots = new HashSet<>(); List<?> dataList = verifyAndPrepareSampleData(sampleList, isSubmit);
for (EntrustSampleDTO sampleDTO : sampleList) {
String sname = sampleDTO.getName(), scode = sampleDTO.getCode(), slotNo = sampleDTO.getSlotNo();
RestAssert.fail(StringUtils.isBlank(sname), "样品名称不能为空");
RestAssert.fail(StringUtils.isNotBlank(scode) && sampleCodes.contains(scode), String.format("样品编号【%s】重复!", scode));
RestAssert.fail(StringUtils.isNotBlank(slotNo) && sampleSlots.contains(slotNo), String.format("样品槽号【%s】重复!", slotNo));
sampleNames.add(sname);
sampleCodes.add(scode);
sampleSlots.add(slotNo);
}
RestAssert.fail(sampleNames.size() > 1, "一个委托只能下同一种样品!");
Entrust entrust = entrustDTO.convert(Entrust.class); Entrust entrust = dto.convert(Entrust.class);
// 保存样品名字至委托备用 // 强制获取数据 样品名称
entrust.setSampleName(sampleList.get(0).getName()); entrust.setSampleName(dataList.get(0).toString());
// 强制获取数据 分类列表
Map<String, LmsChemicalCategory> categoryMap = (Map<String, LmsChemicalCategory>) dataList.get(1);
if (updateById(entrust)) { if (updateById(entrust)) {
List<EntrustSample> updateSampleList = new ArrayList<>(); List<EntrustSample> updateSampleList = new ArrayList<>();
...@@ -758,37 +741,28 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> ...@@ -758,37 +741,28 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
List<EntrustSampleItem> saveItemList = new ArrayList<>(); List<EntrustSampleItem> saveItemList = new ArrayList<>();
int incNum = 10; int incNum = 10;
for (EntrustSampleDTO dto : sampleList) { for (EntrustSampleDTO sto : sampleList) {
EntrustSample sample = dto.convert(EntrustSample.class); EntrustSample sample = sto.convert(EntrustSample.class);
sample.setEntrustId(entrustId); boolean isInsert = initSampleJudgeNew(entrustId, incNum, sample);
sample.setOrderBy(incNum);
sampleSlotNoHandler(sample);
incNum += 10; incNum += 10;
boolean isInsert = false;
// 如果室新增的样品
if (null == sample.getId()) {
isInsert = true;
sample.setId(IdWorker.getId());
}
if (isSubmit) { if (isSubmit) {
// 样品编号为空,或者采样ID不为空
if (StringUtils.isBlank(sample.getCode()) || Objects.nonNull(sample.getSamplingId())) { if (StringUtils.isBlank(sample.getCode()) || Objects.nonNull(sample.getSamplingId())) {
handleSampleCode(entrust, sample); handleSampleCode(entrust, sample, categoryMap);
} }
if (StringUtils.isNotBlank(sample.getCode())) { if (StringUtils.isNotBlank(sample.getCode())) {
sample.setCode(sample.getCode().trim().toUpperCase()); sample.setCode(StringHandleUtils.toUpper(sample.getCode()));
retakeSourceCodeHandle(sample); retakeSourceCodeHandle(sample);
RestAssert.fail(entrustSampleService.isRepeatSampleCode(sample), String.format("样品编号【%s】重复!", sample.getCode())); // RestAssert.fail(entrustSampleService.isRepeatSampleCode(sample), String.format("样品编号【%s】重复!", sample.getCode()));
} }
} }
// 对样品编号处理 // 对样品编号处理
sampleCodeHandler(sample); fillCodeAfterHandle(sample);
if (isInsert) { if (isInsert) {
saveSampleList.add(sample); saveSampleList.add(sample);
logger.error("添加了编号为【{}】的【{}】样品", sample.getCode(), sample.getName());
} else { } else {
updateSampleList.add(sample); updateSampleList.add(sample);
logger.error("修改了编号为【{}】的【{}】样品", sample.getCode(), sample.getName());
} }
if (StringUtils.isNotBlank(sample.getCode())) { if (StringUtils.isNotBlank(sample.getCode())) {
...@@ -797,9 +771,9 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> ...@@ -797,9 +771,9 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
judgeSampleFields(sample, isSubmit); judgeSampleFields(sample, isSubmit);
List<EntrustSampleItem> viewItemList = dto.getItemList(); List<EntrustSampleItem> itemList = sto.getItemList();
if (CollectionUtils.isNotEmpty(viewItemList)) { if (CollectionUtils.isNotEmpty(itemList)) {
for (EntrustSampleItem item : viewItemList) { for (EntrustSampleItem item : itemList) {
if (null == item.getId()) { if (null == item.getId()) {
item.setId(IdWorker.getId()); item.setId(IdWorker.getId());
item.setEntrustSampleId(sample.getId()); item.setEntrustSampleId(sample.getId());
...@@ -809,6 +783,8 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> ...@@ -809,6 +783,8 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
saveItemList.add(item); saveItemList.add(item);
} }
} }
} else {
logger.error("✦✦✦✦ EntrustServiceImpl ✦✦✦✦ editEntrust ✦✦✦✈ 【{},{}】检测项目数据为空!", sample.getId(), sample.getCode());
} }
} }
...@@ -835,6 +811,50 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> ...@@ -835,6 +811,50 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
return true; return true;
} }
private static boolean initSampleJudgeNew(Long entrustId, int incNum, EntrustSample sample) {
sample.setEntrustId(entrustId);
sample.setOrderBy(incNum);
sample.setSlotNo(StringHandleUtils.nvlBlank(sample.getSlotNo()));
if (Objects.isNull(sample.getId())) {
sample.setId(IdWorker.getId());
return true;
}
return false;
}
private List<?> verifyAndPrepareSampleData(List<EntrustSampleDTO> sampleList, boolean isSubmit) {
RestAssert.fail(CollectionUtils.isEmpty(sampleList), "委托样品为空");
List<Object> dataList = new ArrayList<>();
// == 变量声明
Set<String>
sampleNameSet = new HashSet<>(),
sampleCodeSet = new HashSet<>(),
sampleSlotSet = new HashSet<>(),
categoriesSet = new HashSet<>();
for (EntrustSampleDTO s : sampleList) {
String sname = s.getName(), scode = s.getCode(), slotNo = s.getSlotNo();
RestAssert.fail(StringUtils.isBlank(sname), "样品名称不能为空");
RestAssert.fail(StringUtils.isNotBlank(scode) && sampleCodeSet.contains(scode), String.format("样品编号【%s】重复!", scode));
RestAssert.fail(StringUtils.isNotBlank(slotNo) && sampleSlotSet.contains(slotNo), String.format("样品槽号【%s】重复!", slotNo));
sampleNameSet.add(sname);
sampleCodeSet.add(scode);
sampleSlotSet.add(slotNo);
categoriesSet.add(s.getCategory());
}
RestAssert.fail(sampleNameSet.size() > 1, "一个委托只能下同一种样品!");
// 0:样品名称
dataList.add(sampleNameSet.iterator().next());
Map<String, LmsChemicalCategory> categoryMap = new HashMap<>();
if (isSubmit) {
categoryMap = lmsChemicalCategoryClient.getTopCategoryMap(new ArrayList<>(categoriesSet)).getData();
RestAssert.fail(MapUtils.isEmpty(categoryMap), "物料父级分类为空!");
}
// 1:分类Map
dataList.add(categoryMap);
return dataList;
}
public void calTotalFee(Long id) { public void calTotalFee(Long id) {
//计算委托费用 //计算委托费用
...@@ -1221,6 +1241,12 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> ...@@ -1221,6 +1241,12 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
// 保存委托信息 // 保存委托信息
saveEntrust(entrust); saveEntrust(entrust);
entrustIdList.add(entrust.getId()); entrustIdList.add(entrust.getId());
// 单独查询分类信息
List<String> categoryList = sampleList.stream().map(EntrustSample::getCategory).distinct().collect(Collectors.toList());
Map<String, LmsChemicalCategory> categoryMap = lmsChemicalCategoryClient.getTopCategoryMap(categoryList).getData();
if (MapUtils.isEmpty(categoryMap)) {
categoryMap = new HashMap<>(4);
}
int sampleIndex = 0; int sampleIndex = 0;
for (EntrustSample sample : sampleList) { for (EntrustSample sample : sampleList) {
Long oldSampleId = sample.getId(); Long oldSampleId = sample.getId();
...@@ -1229,7 +1255,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> ...@@ -1229,7 +1255,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
sample.setId(IdWorker.getId()); sample.setId(IdWorker.getId());
sample.setCode(null).setFirstCode(null).setSecondCode(null).setThirdCode(null); sample.setCode(null).setFirstCode(null).setSecondCode(null).setThirdCode(null);
//生成样品编号,可能存在为空的情况 //生成样品编号,可能存在为空的情况
initSampleCode(entrust, sample); initSampleCode(entrust, sample, categoryMap);
// 样品编号问题,手填的样品编号不清空 // 样品编号问题,手填的样品编号不清空
if (StringUtils.isBlank(sample.getCode())) { if (StringUtils.isBlank(sample.getCode())) {
sample.setCode(sampleCode); sample.setCode(sampleCode);
...@@ -1245,6 +1271,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> ...@@ -1245,6 +1271,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
// //
List<EntrustSampleItem> itemList = entrustSampleItemService.list(Condition.create().eq("entrust_sample_id", oldSampleId).eq("deleted", 0)); List<EntrustSampleItem> itemList = entrustSampleItemService.list(Condition.create().eq("entrust_sample_id", oldSampleId).eq("deleted", 0));
if (CollectionUtils.isEmpty(itemList)) { if (CollectionUtils.isEmpty(itemList)) {
logger.error("✦✦✦✦ EntrustServiceImpl ✦✦✦✦ cloneEntrust ✦✦✦✈ 【{},{}】检测项目数据为空!", sample.getId(), sample.getCode());
continue; continue;
} }
...@@ -1704,23 +1731,40 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> ...@@ -1704,23 +1731,40 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
normalIds = new ArrayList<>(); normalIds = new ArrayList<>();
List<Long> sendUserIdList = new ArrayList<>(); List<Long> sendUserIdList = new ArrayList<>();
List<EntrustSample> samples = entrustSampleService.listByEntrustIds(Arrays.asList(ids)); List<EntrustSample> samples = entrustSampleService.listByEntrustIds(Arrays.asList(ids));
RestAssert.fail(CollectionUtils.isEmpty(samples), "提交的样品信息为空!");
Map<Long, List<EntrustSample>> entrustSampleMap = new HashMap<>(8); Map<Long, List<EntrustSample>> entrustSampleMap = new HashMap<>(8);
Optional.ofNullable(samples).ifPresent(dl -> dl.forEach(d -> MapMergeUtils.getorCreateMapArrayList(d.getEntrustId(), entrustSampleMap, d))); List<String> categoryList = new ArrayList<>();
List<Long> sampleIds = new ArrayList<>();
samples.forEach(s -> {
sampleIds.add(s.getId());
MapMergeUtils.getorCreateMapArrayList(s.getEntrustId(), entrustSampleMap, s);
String category = s.getCategory();
if (StringUtils.isNotBlank(category) && !categoryList.contains(category)) {
categoryList.add(category);
}
});
Map<String, LmsChemicalCategory> categoryMap = lmsChemicalCategoryClient.getTopCategoryMap(categoryList).getData();
List<EntrustSampleItem> itemList = entrustSampleItemService.list(Condition.<EntrustSampleItem>wrapper().in("entrust_sample_id", sampleIds));
RestAssert.fail(CollectionUtils.isEmpty(itemList), "提交的检测项目数据为空!");
Map<Long, List<EntrustSampleItem>> sampleItemMap = new HashMap<>();
itemList.forEach(it -> MapMergeUtils.getorCreateMapArrayList(it.getEntrustSampleId(), sampleItemMap, it));
for (Entrust entrust : entrustList) { for (Entrust entrust : entrustList) {
RestAssert.fail(!Objects.equals(entrust.getFlowStatus(), EntrustFlowEnum.DRAFT.name()), "只能提交草稿状态的委托!"); RestAssert.fail(!Objects.equals(entrust.getFlowStatus(), EntrustFlowEnum.DRAFT.name()), "只能提交草稿状态的委托!");
List<EntrustSample> sampleList = entrustSampleMap.get(entrust.getId()); List<EntrustSample> sampleList = entrustSampleMap.get(entrust.getId());
RestAssert.fail(CollectionUtils.isEmpty(sampleList), String.format("委托编号为的【%s】样品为空!", entrust.getCode())); RestAssert.fail(CollectionUtils.isEmpty(sampleList), String.format("委托编号为的【%s】样品为空!", entrust.getCode()));
// 若存在任何一个样品的编号为空,那么需要自动生成其编号 // 若存在任何一个样品的编号为空,那么需要自动生成其编号
for (EntrustSample sample : sampleList) { for (EntrustSample sample : sampleList) {
sampleSlotNoHandler(sample); sample.setSlotNo(StringHandleUtils.nvlBlank(sample.getSlotNo()));
if (StringUtils.isBlank(sample.getCode()) || Objects.nonNull(sample.getSamplingId())) { if (StringUtils.isBlank(sample.getCode()) || Objects.nonNull(sample.getSamplingId())) {
handleSampleCode(entrust, sample); handleSampleCode(entrust, sample, categoryMap);
} }
// 额外处理样品编号空格,大写 // 额外处理样品编号空格,大写
sampleCodeHandler(sample); fillCodeAfterHandle(sample);
// 处理重取原编号 // 处理重取原编号
retakeSourceCodeHandle(sample); retakeSourceCodeHandle(sample);
RestAssert.fail(entrustSampleService.isRepeatSampleCode(sample), String.format("样品编号【%s】重复!", sample.getCode())); RestAssert.fail(entrustSampleService.isRepeatSampleCode(sample), String.format("样品编号【%s】重复!", sample.getCode()));
RestAssert.fail(CollectionUtils.isEmpty(sampleItemMap.get(sample.getId())), String.format("【%s】样品对应的检测项目为空!", sample.getCode()));
} }
entrustSampleService.updateBatchById(sampleList); entrustSampleService.updateBatchById(sampleList);
...@@ -1740,6 +1784,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> ...@@ -1740,6 +1784,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
} }
} }
// 更新委托,发送消息 // 更新委托,发送消息
Entrust updateModel = new Entrust(); Entrust updateModel = new Entrust();
if (CollectionUtils.isNotEmpty(specialIds)) { if (CollectionUtils.isNotEmpty(specialIds)) {
...@@ -1809,6 +1854,9 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> ...@@ -1809,6 +1854,9 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
List<EntrustSample> sampleList = new ArrayList<>(); List<EntrustSample> sampleList = new ArrayList<>();
List<EntrustSampleItem> itemList = new ArrayList<>(); List<EntrustSampleItem> itemList = new ArrayList<>();
List<String> categoryList = sampleDTOList.stream().map(EntrustSampleDTO::getCategory).distinct().collect(Collectors.toList());
Map<String, LmsChemicalCategory> categoryMap = lmsChemicalCategoryClient.getTopCategoryMap(categoryList).getData();
for (EntrustSampleDTO dto : sampleDTOList) { for (EntrustSampleDTO dto : sampleDTOList) {
EntrustSample sample = dto.convert(EntrustSample.class); EntrustSample sample = dto.convert(EntrustSample.class);
sample.setEntrustId(entrustId).setFirstCode(null).setSecondCode(null).setThirdCode(null) sample.setEntrustId(entrustId).setFirstCode(null).setSecondCode(null).setThirdCode(null)
...@@ -1816,7 +1864,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> ...@@ -1816,7 +1864,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
.setSampleGrading(null).setLtime(new Date()).setLid(account.getUserId()).setCtime(new Date()) .setSampleGrading(null).setLtime(new Date()).setLid(account.getUserId()).setCtime(new Date())
.setJudgeStatus(0).setJudgeTime(null).setJudgeCheckTime(null).setJudgeCheckerId(null).setJudger(null) .setJudgeStatus(0).setJudgeTime(null).setJudgeCheckTime(null).setJudgeCheckerId(null).setJudger(null)
.setJudgeProgress(null).setOkJudge(null).setConclusion(null); .setJudgeProgress(null).setOkJudge(null).setConclusion(null);
initSampleCode(entrust, sample); initSampleCode(entrust, sample, categoryMap);
// 重置三级编码 // 重置三级编码
sample.setThirdCode(getSampleThirdCode(sample)); sample.setThirdCode(getSampleThirdCode(sample));
sample.setOrderBy(incNum).setId(IdWorker.getId()); sample.setOrderBy(incNum).setId(IdWorker.getId());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment