package com.ruoyi.inspect.service.impl; import cn.hutool.core.util.NumberUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.framework.exception.ErrorException; import com.ruoyi.inspect.dto.InsProductDto; import com.ruoyi.inspect.mapper.InsOrderMapper; import com.ruoyi.inspect.mapper.InsOrderStateMapper; import com.ruoyi.inspect.mapper.InsProductMapper; import com.ruoyi.inspect.mapper.InsSampleMapper; import com.ruoyi.inspect.pojo.InsOrder; import com.ruoyi.inspect.pojo.InsOrderState; import com.ruoyi.inspect.pojo.InsProduct; import com.ruoyi.inspect.pojo.InsSample; import com.ruoyi.inspect.service.InsProductService; import lombok.AllArgsConstructor; import org.apache.logging.log4j.util.Strings; import org.springframework.stereotype.Service; import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; @Service @AllArgsConstructor public class InsProductServiceImpl extends ServiceImpl implements InsProductService { private InsProductMapper insProductMapper; private InsOrderMapper insOrderMapper; private InsOrderStateMapper insOrderStateMapper; private InsSampleMapper insSampleMapper; @Override public int selectOrderManDay(Integer orderId) { return insProductMapper.selectOrderManDay(orderId); } @Override public int updateInspected(Integer id, String ids) { InsOrder insOrder = new InsOrder(); insOrder.setId(id); insOrder.setIsRevocation(1);//需要审核 insOrder.setRevocationInsProductIds(ids); return insOrderMapper.updateById(insOrder); } @Override public boolean write(InsProductDto insProductDto) { // List insProducts = baseMapper.selectBatchIds(insProductDto.getIds()); // for (InsProduct insProduct : insProducts) { // insProduct.setTemperature(insProductDto.getTemperature()); // insProduct.setHumidity(insProductDto.getHumidity()); // } List insSamples = insSampleMapper.selectList(Wrappers.lambdaQuery() .eq(InsSample::getInsOrderId, insProductDto.getInsOrderId()) .select(InsSample::getId)) .stream() .map(InsSample::getId) .collect(Collectors.toList()); // Integer insSampleId = baseMapper.selectById(insProductDto.getIds().get(0)).getInsSampleId(); return baseMapper.update(null, new LambdaUpdateWrapper().in(InsProduct::getInsSampleId, insSamples) .set(Strings.isNotBlank(insProductDto.getTemperature()),InsProduct::getTemperature, insProductDto.getTemperature()) .set(Strings.isNotBlank(insProductDto.getHumidity()),InsProduct::getHumidity, insProductDto.getHumidity()))>0; } //查询待检项目 @Override public Map selectNoProducts(Page page, InsProduct insProduct, Integer orderId, String ids) { Map map = new HashMap<>(); // map.put("head", PrintChina.printChina(InsProduct.class)); IPage insProductIPage = baseMapper.selectNoProducts(page, orderId); if (ObjectUtils.isNotEmpty(ids)) { List collect = Arrays.asList(ids.split(",")).stream() .map(Integer::parseInt) .collect(Collectors.toList()); List products = insProductIPage.getRecords().stream().filter(record -> collect.contains(record.getId())).collect(Collectors.toList()); insProductIPage.setRecords(products); } map.put("body", insProductIPage); return map; } // 查询撤销项目 public List> selectRevocation(Integer orderId) { // 查询撤销状态的样品 以及 检验项 String revocationInsProductIds = insOrderMapper.selectById(orderId).getRevocationInsProductIds(); List productIds = new ArrayList<>(); List sampleIds = new ArrayList<>(); // 如果是新的数据 会存在sample的id 以及product的id 以@分隔 if(StringUtils.isNotEmpty(revocationInsProductIds)) { if(revocationInsProductIds.contains("@")) { List> collect = Arrays.stream(revocationInsProductIds.split("@")).map(item -> { List list = JSONArray.parseArray(item, Integer.class); return list; }).collect(Collectors.toList()); sampleIds = collect.get(0); productIds = collect.get(1); }else { // 以前的数据则是productId,以 ,分隔 productIds = Arrays.stream(revocationInsProductIds.split(",")).map(Integer::parseInt).collect(Collectors.toList()); } } return Arrays.asList(sampleIds,productIds); } @Override public List> selectSampleByOrderId(Integer orderId) { List> collect = selectRevocation(orderId); List sampleIds = collect.get(0); List productIds = collect.get(1); List> list = new ArrayList<>(); List insSamples = insSampleMapper.selectList(new LambdaQueryWrapper() .eq(InsSample::getInsOrderId, orderId) .notIn(CollectionUtils.isNotEmpty(sampleIds), InsSample::getId,sampleIds)); for(InsSample insSample : insSamples) { List productList = insProductMapper.selectList(new LambdaQueryWrapper() .eq(InsProduct::getInsSampleId, insSample.getId()) .eq(InsProduct::getState, 1) .notIn(CollectionUtils.isNotEmpty(productIds), InsProduct::getId,productIds)); if(CollectionUtils.isNotEmpty(productList)) { HashMap map = new HashMap<>(); map.put("sampleCode", insSample.getSampleCode()); // 样品编号 map.put("sampleId", insSample.getId()); // 前端需要 map.put("id", insSample.getId()); map.put("hasChildren", true); // 是否有子项 list.add(map); } } return list; } @Override public List> selectProductsBySampleId(Integer sampleId,Integer orderId) { List> collect1 = selectRevocation(orderId); List sampleIds = collect1.get(0); List productIds = collect1.get(1); List> list = new ArrayList<>(); if(!sampleIds.contains(sampleId)) { InsSample insSample = insSampleMapper.selectById(sampleId); List productList = insProductMapper.selectList(new LambdaQueryWrapper() .eq(InsProduct::getInsSampleId, insSample.getId()) .eq(InsProduct::getState,1) .notIn(CollectionUtils.isNotEmpty(productIds), InsProduct::getId,productIds)); for (InsProduct insProduct : productList) { // 区分温度循环 和 普通项目 if(Objects.isNull(insProduct.getSpecialItemParentId()) || !NumberUtil.isInteger(insProduct.getInspectionItem())) { Map map = new HashMap<>(); // 如果是温度循环就还得在多嵌套几层 if(insProduct.getInspectionItem().equals("温度循环")) { map.put("sampleCode", insSample.getSampleCode()); // 样品编号 map.put("inspectionItem",insProduct.getInspectionItem()); // 检验项目 map.put("sampleId", insSample.getId()); // 样品id map.put("hasChildren",true); // 温度循环特殊标识 map.put("temperature",true); map.put("id",insProduct.getId()); }else { map.put("sampleId", insSample.getId()); // 样品id map.put("sampleCode", insSample.getSampleCode()); // 样品编号 map.put("inspectionItem",insProduct.getInspectionItem()); // 检验项目 map.put("inspectionItemSubclass",insProduct.getInspectionItemSubclass()); // 检验子项 map.put("sampleType",insProduct.getSampleType()); // 样品分类 map.put("sample",insProduct.getSample()); // 样品 map.put("model",insProduct.getModel()); // 型号 map.put("sonLaboratory",insProduct.getSonLaboratory()); // 子实验室 map.put("tell",insProduct.getTell()); // 要求值 map.put("id",insProduct.getId()); } list.add(map); } } } return list; } @Override public List> selectTemperatureByProductId(Integer productId) { List> list = new ArrayList<>(); List productList = null; // 已经到撤销页面的就不在查出来 InsProduct insProduct = insProductMapper.selectById(productId); InsSample insSample = insSampleMapper.selectById(insProduct.getInsSampleId()); InsOrder insOrder = insOrderMapper.selectById(insSample.getInsOrderId()); List> lists = selectRevocation(insOrder.getId()); List productIds = lists.get(1); productList = insProductMapper.selectList(new LambdaQueryWrapper() .eq(InsProduct::getState, 1) .eq(InsProduct::getSpecialItemParentId, productId) .notIn(CollectionUtils.isNotEmpty(productIds),InsProduct::getId,productIds)); if(CollectionUtils.isNotEmpty(productList)) { Map> collect = productList.stream().collect(Collectors.groupingBy(InsProduct::getInspectionItem)); // 拿到循环次数 Iterator>> iterator = collect.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry> next = iterator.next(); Map map = new HashMap<>(); map.put("hasChildren",true); // 温度循环特殊标识 循环次数 map.put("temperatureNumber",true); map.put("sampleId", next.getValue().get(0).getInsSampleId()); // 样品id map.put("inspectionItem",next.getKey() + " (循环次数)"); // 检验项目 map.put("inspectionItemTwo",next.getKey()); // 方便查看具体次数 (传值需要) map.put("parentId",productId); // 父id map.put("ids",next.getValue().stream().map(InsProduct::getId).collect(Collectors.toList())); map.put("sampleCode", next.getValue().get(0).getSampleCode()); // 样品编号 map.put("id",productId + Integer.parseInt(next.getKey())); list.add(map); } } return list; } @Override public List> selectTemperatureNumberByProductId(Integer parentId, String inspectionItem) { List> list = new ArrayList<>(); // 已经到撤销页面的就不在查出来 InsProduct ip = insProductMapper.selectById(parentId); InsSample insSample = insSampleMapper.selectById(ip.getInsSampleId()); InsOrder insOrder = insOrderMapper.selectById(insSample.getInsOrderId()); List> lists = selectRevocation(insOrder.getId()); List sampleIds = lists.get(0); List productIds = lists.get(1); List productList = insProductMapper.selectList(new LambdaQueryWrapper() .eq(InsProduct::getState, 1) .eq(InsProduct::getSpecialItemParentId, parentId) .eq(InsProduct::getInspectionItem, inspectionItem) .notIn(CollectionUtils.isNotEmpty(productIds),InsProduct::getId,productIds)); // 根据检验子项得到温度点 Map> collect = productList.stream().collect(Collectors.groupingBy(InsProduct::getInspectionItemSubclass)); Iterator>> iterator = collect.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry> next = iterator.next(); InsProduct insProduct = next.getValue().get(0); Map map = new HashMap<>(); map.put("sampleId", next.getValue().get(0).getInsSampleId()); // 样品id map.put("inspectionItem",""); // 检验项目 map.put("inspectionItemSubclass",next.getKey()); // 检验子项 map.put("sampleType",insProduct.getSampleType()); // 样品分类 map.put("sample",insProduct.getSample()); // 样品 map.put("model",insProduct.getModel()); // 型号 map.put("sonLaboratory",insProduct.getSonLaboratory()); // 子实验室 map.put("sampleCode", next.getValue().get(0).getSampleCode()); // 样品编号 map.put("tell",insProduct.getTell()); // 要求值 map.put("number",inspectionItem); // 循环次数 map.put("parentId",parentId); // 父id map.put("ids",next.getValue().stream().map(InsProduct::getId).collect(Collectors.toList())); // 该温度点所有的id map.put("id",Math.random()); list.add(map); } return list; } @Override public void revoke(Map data) { List> lists = selectRevocation(Integer.parseInt(data.get("orderId").toString())); // 更新order的状态 以及添加需要撤销的项目 Integer orderId = Integer.parseInt(data.get("orderId").toString()); InsOrder insOrder = insOrderMapper.selectById(orderId); insOrder.setIsRevocation(1); List sampleIds = new ArrayList<>(); List productIds = new ArrayList<>(); if(data.containsKey("sampleIds")) { sampleIds = JSONArray.parseArray(data.get("sampleIds").toString(), Integer.class); } if(data.containsKey("productIds")) { productIds = JSONArray.parseArray(data.get("productIds").toString(), Integer.class); } sampleIds.addAll(lists.get(0)); productIds.addAll(lists.get(1)); String SampleJsonString = JSON.toJSONString(sampleIds); String ProductJsonString = JSON.toJSONString(productIds); insOrder.setRevocationInsProductIds(SampleJsonString + "@" + ProductJsonString); insOrderMapper.updateById(insOrder); } @Override public List> revokeReviewSample(Integer orderId) { List> list = new ArrayList<>(); List> lists = selectRevocation(orderId); List sampleIds = lists.get(0); List productIds = lists.get(1); List newSampleIds = new ArrayList<>(); // 根据项目来获取样品 if(CollectionUtils.isNotEmpty(productIds)) { newSampleIds = insProductMapper.selectBatchIds(productIds).stream().map(InsProduct::getInsSampleId).distinct().collect(Collectors.toList()); } // 查询需要撤销的样品 if(CollectionUtils.isNotEmpty(newSampleIds)) { List insSamples = insSampleMapper.selectList(new LambdaQueryWrapper() .in(InsSample::getId, newSampleIds)); for (InsSample insSample : insSamples) { List productList = insProductMapper.selectList(new LambdaQueryWrapper() .eq(InsProduct::getInsSampleId, insSample.getId()) .eq(InsProduct::getState, 1) .in(CollectionUtils.isNotEmpty(productIds), InsProduct::getId, productIds)); if(CollectionUtils.isNotEmpty(productList)) { HashMap map = new HashMap<>(); map.put("sampleCode", insSample.getSampleCode()); // 样品编号 map.put("sampleId", insSample.getId()); // 前端需要 map.put("id", insSample.getId()); map.put("hasChildren", true); // 是否有子项 list.add(map); } } } if(CollectionUtils.isNotEmpty(sampleIds)) { List insSamples2 = insSampleMapper.selectList(new LambdaQueryWrapper() .in(InsSample::getId, sampleIds)); for (InsSample insSample : insSamples2) { List productList = insProductMapper.selectList(new LambdaQueryWrapper() .eq(InsProduct::getInsSampleId, insSample.getId()) .eq(InsProduct::getState, 1)); if(CollectionUtils.isNotEmpty(productList)) { HashMap map = new HashMap<>(); map.put("sampleCode", insSample.getSampleCode()); // 样品编号 map.put("sampleId", insSample.getId()); // 前端需要 map.put("id", insSample.getId()); map.put("hasChildren", true); // 是否有子项 list.add(map); } } } list = list.stream().sorted(Comparator.comparing(map -> Integer.parseInt(map.get("id")+""))).collect(Collectors.toList()); return list; } @Override public List> revokeReviewProduct(Integer orderId, Integer sampleId) { String sampleCode = insSampleMapper.selectById(sampleId).getSampleCode(); List> list = new ArrayList<>(); List> lists = selectRevocation(orderId); List sampleIds = lists.get(0); List productIds = lists.get(1); List productList = new ArrayList<>(); // 如果是一整个样品撤销 if(sampleIds.contains(sampleId)) { // 过滤出温度循环次数的数据 productList = insProductMapper.selectList(new LambdaQueryWrapper() .eq(InsProduct::getInsSampleId, sampleId).eq(InsProduct::getState,1)); productList = productList.stream().filter(item -> !NumberUtil.isNumber(item.getInspectionItem()) && Objects.isNull(item.getSpecialItemParentId())).collect(Collectors.toList()); }else { // 如果是单个项目撤销 productList = insProductMapper.selectList(new LambdaQueryWrapper() .eq(InsProduct::getInsSampleId, sampleId) .eq(InsProduct::getState,1) .in(InsProduct::getId, productIds)); // 判断是否是温度循环下面的温度点 // 1.过滤出不是温度点的数据 List collect = productList.stream().filter(item -> Objects.isNull(item.getSpecialItemParentId()) || !NumberUtil.isInteger(item.getInspectionItem())).collect(Collectors.toList()); if(productList.size() != collect.size()) { // 2.返回温度循环数据即可 List collect1 = productList.stream().filter(item -> Objects.nonNull(item.getSpecialItemParentId()) && NumberUtil.isInteger(item.getInspectionItem())).collect(Collectors.toList()); InsProduct insProduct = insProductMapper.selectById(collect1.get(0).getSpecialItemParentId()); collect.add(insProduct); productList =collect.stream().distinct().collect(Collectors.toList()); } } for (InsProduct insProduct : productList) { Map map = new HashMap<>(); if(insProduct.getInspectionItem().equals("温度循环")) { map.put("sampleCode", sampleCode); // 样品编号 map.put("inspectionItem",insProduct.getInspectionItem()); // 检验项目 map.put("sampleId", sampleId); // 样品id map.put("hasChildren",true); // 温度循环特殊标识 map.put("temperature",true); map.put("id",insProduct.getId()); }else { map.put("sampleId", sampleId); // 样品id map.put("sampleCode", sampleCode); // 样品编号 map.put("inspectionItem",insProduct.getInspectionItem()); // 检验项目 map.put("inspectionItemSubclass",insProduct.getInspectionItemSubclass()); // 检验子项 map.put("sampleType",insProduct.getSampleType()); // 样品分类 map.put("sample",insProduct.getSample()); // 样品 map.put("model",insProduct.getModel()); // 型号 map.put("sonLaboratory",insProduct.getSonLaboratory()); // 子实验室 map.put("tell",insProduct.getTell()); // 要求值 map.put("id",insProduct.getId()); } list.add(map); } return list; } @Override public List> revokeReviewTemperatureByProductId(Integer productId) { // 根据温度循环id 查找order 以及 sample List> list = new ArrayList<>(); InsProduct insProduct = insProductMapper.selectById(productId); InsSample insSample = insSampleMapper.selectById(insProduct.getInsSampleId()); InsOrder insOrder = insOrderMapper.selectById(insSample.getInsOrderId()); List> lists = selectRevocation(insOrder.getId()); List sampleIds = lists.get(0); List productIds = lists.get(1); // 如果当前样品是整个撤销 if(sampleIds.contains(insSample.getId())) { list = selectTemperatureByProductId(productId); }else { // 撤销的是检验项 List productList = insProductMapper.selectList(new LambdaQueryWrapper() .eq(InsProduct::getState, 1) .eq(InsProduct::getSpecialItemParentId,productId) .in(InsProduct::getId, productIds)); Map> collect = productList.stream().collect(Collectors.groupingBy(InsProduct::getInspectionItem)); // 拿到循环次数 Iterator>> iterator = collect.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry> next = iterator.next(); Map map = new HashMap<>(); map.put("hasChildren",true); // 温度循环特殊标识 循环次数 map.put("temperatureNumber",true); map.put("sampleId", next.getValue().get(0).getInsSampleId()); // 样品id map.put("inspectionItem",next.getKey() + " (循环次数)"); // 检验项目 map.put("inspectionItemTwo",next.getKey()); // 方便查看具体次数 (传值需要) map.put("parentId",productId); // 父id map.put("ids",next.getValue().stream().map(InsProduct::getId).collect(Collectors.toList())); map.put("sampleCode", next.getValue().get(0).getSampleCode()); // 样品编号 map.put("id",productId + Integer.parseInt(next.getKey())); list.add(map); } } return list; } @Override public List> revokeReviewConsistentByProductId(Integer parentId, String inspectionItem) { List> list = new ArrayList<>(); InsProduct insProduct = insProductMapper.selectById(parentId); InsSample insSample = insSampleMapper.selectById(insProduct.getInsSampleId()); InsOrder insOrder = insOrderMapper.selectById(insSample.getInsOrderId()); List> lists = selectRevocation(insOrder.getId()); List sampleIds = lists.get(0); List productIds = lists.get(1); // 如果是当前样品撤销 查询所有 if(sampleIds.contains(insSample.getId())) { list = selectTemperatureNumberByProductId(parentId, inspectionItem); }else { // 查询撤销的温度点 List productList = insProductMapper.selectList(new LambdaQueryWrapper() .eq(InsProduct::getState, 1) .eq(InsProduct::getSpecialItemParentId, parentId) .eq(InsProduct::getInspectionItem, inspectionItem) .in(InsProduct::getId, productIds)); // 根据检验子项得到温度点 Map> collect = productList.stream().collect(Collectors.groupingBy(InsProduct::getInspectionItemSubclass)); Iterator>> iterator = collect.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry> next = iterator.next(); InsProduct ip = next.getValue().get(0); Map map = new HashMap<>(); map.put("sampleId", next.getValue().get(0).getInsSampleId()); // 样品id map.put("inspectionItem",""); // 检验项目 map.put("inspectionItemParent",inspectionItem + " (循环次数)"); // 检验父项目 map.put("inspectionItemSubclass",next.getKey()); // 检验子项 map.put("sampleType",ip.getSampleType()); // 样品分类 map.put("sample",ip.getSample()); // 样品 map.put("model",ip.getModel()); // 型号 map.put("sonLaboratory",ip.getSonLaboratory()); // 子实验室 map.put("sampleCode", next.getValue().get(0).getSampleCode()); // 样品编号 map.put("tell",ip.getTell()); // 要求值 map.put("parentId",parentId); // 父id map.put("ids",next.getValue().stream().map(InsProduct::getId).collect(Collectors.toList())); // 该温度点所有的id map.put("id",Math.random()); list.add(map); } } return list; } @Override public void revocationPassed(Integer id) { List> lists = selectRevocation(id); List sampleIds = lists.get(0); List productIds = lists.get(1); if(CollectionUtils.isNotEmpty(sampleIds)) { insProductMapper.update(null,new LambdaUpdateWrapper() .set(InsProduct::getState,0) .in(InsProduct::getInsSampleId,sampleIds)); } if(CollectionUtils.isNotEmpty(productIds)) { insProductMapper.update(null,new LambdaUpdateWrapper() .set(InsProduct::getState,0) .in(InsProduct::getId,productIds)); // 拿到的productId List productList = insProductMapper.selectList(new LambdaQueryWrapper() .in(InsProduct::getId, productIds)); if(CollectionUtils.isNotEmpty(productList)) { // 得判断一下 是否含有温度循环项目 List collect2 = productList.stream().filter(item -> Objects.nonNull(item.getSpecialItemParentId()) && NumberUtil.isInteger(item.getInspectionItem())).collect(Collectors.toList()); if(CollectionUtils.isNotEmpty(collect2)) { // 就是有温度循环的 Map> collect = productList.stream().collect(Collectors.groupingBy(InsProduct::getSpecialItemParentId)); // 获取温度循环的id for(Map.Entry> entry1 : collect.entrySet()) { String number = ""; Integer parentId = entry1.getKey(); // 查询该温度循环 得到循环次数 List productList2 = insProductMapper.selectList(new LambdaQueryWrapper() .eq(InsProduct::getSpecialItemParentId, parentId) .eq(InsProduct::getState, 1)); if(CollectionUtils.isNotEmpty(productList2)) { Map> group = productList2.stream().collect(Collectors.groupingBy(InsProduct::getInspectionItem)); number = group.size() + ""; } // 撤销的温度循环各个温度点 List productList1 = insProductMapper.selectList(new LambdaQueryWrapper() .eq(InsProduct::getState, 0) .eq(InsProduct::getSpecialItemParentId, parentId) .in(InsProduct::getId, productIds)); // 根据温度点进行分组 Map> collect1 = productList1.stream().collect(Collectors.groupingBy(InsProduct::getInspectionItemSubclass)); Iterator>> iterator = collect1.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry> entry = iterator.next(); String key = entry.getKey(); // 拿到温度循环的ask InsProduct insProduct = insProductMapper.selectById(parentId); String ask = insProduct.getAsk(); String newAsk = ""; String[] split = ask.split(";"); // 只有循环的次数 都不包含该温度点才需要更改 List productList3 = insProductMapper.selectList(new LambdaQueryWrapper() .eq(InsProduct::getSpecialItemParentId, parentId) .eq(InsProduct::getInspectionItemSubclass, key) .eq(InsProduct::getState, 1)); if(CollectionUtils.isEmpty(productList3)) { if(key.equals("20℃")) { newAsk = Arrays.stream(split).filter(item -> (!item.contains(key) || item.contains("20℃(常温)")) && !NumberUtil.isInteger(item.trim())).collect(Collectors.joining(";")) + ";" + number; }else { newAsk = Arrays.stream(split).filter(item -> !item.contains(key) && !NumberUtil.isInteger(item)).collect(Collectors.joining(";")) + ";" + number; } }else { newAsk = Arrays.stream(split).filter(item -> !NumberUtil.isInteger(item)).collect(Collectors.joining(";")) + ";" + number; } insProductMapper.update(null, new LambdaUpdateWrapper() .set(InsProduct::getAsk, newAsk) .eq(InsProduct::getId, parentId)); } } } } } insOrderMapper.update(null,new LambdaUpdateWrapper().set(InsOrder::getIsRevocation,0).eq(InsOrder::getId,id)); // 如果检验项目全部撤销则需要撤销检验单 InsOrder insOrder = insOrderMapper.selectById(id); insOrder.setRevocationTime(LocalDateTime.now()); //查询该委托单下发的试验室 List insOrderStates = insOrderStateMapper.selectList(Wrappers.lambdaQuery().eq(InsOrderState::getInsOrderId, id)); List insSamples = insSampleMapper.selectList(new LambdaQueryWrapper().eq(InsSample::getInsOrderId, id)); List collect = insSamples.stream().map(InsSample::getId).collect(Collectors.toList()); List insProducts = insProductMapper.selectList(new LambdaQueryWrapper().eq(InsProduct::getState, 1).in(InsProduct::getInsSampleId, collect)); if(CollectionUtils.isEmpty(insProducts)) { insOrder.setState(3); insOrderMapper.updateById(insOrder); }else{ //遍历各试验室,如果试验室下的项目为空,则删除该试验室下的订单 insOrderStates.forEach(insOrderState -> { //过滤试验室下的项目 long productCount = insProducts.stream().filter(insProduct -> insProduct.getSonLaboratory().equals(insOrderState.getLaboratory())).count(); if(productCount == 0){ insOrderStateMapper.delete(new LambdaUpdateWrapper().eq(InsOrderState::getId, insOrderState.getId())); } }); } } @Override public void revocationCancel(Integer orderId) { InsOrder insOrder = insOrderMapper.selectById(orderId); insOrder.setIsRevocation(0); insOrder.setRevocationInsProductIds(""); insOrderMapper.updateById(insOrder); } // public List> selectProductsByOrderId(Integer orderId) { // List> list = new ArrayList<>(); // List insSamples = insSampleMapper.selectList(new LambdaQueryWrapper().eq(InsSample::getInsOrderId, orderId)); // if(CollectionUtils.isNotEmpty(insSamples)) { // for (InsSample insSample : insSamples) { // List> lists = new ArrayList<>(); // List insProducts = insProductMapper.selectList(new LambdaQueryWrapper().eq(InsProduct::getInsSampleId, insSample.getId())); // Map map = new HashMap<>(); // map.put("label", insSample.getSampleCode()); // map.put("value", insSample.getId()); // if(CollectionUtils.isNotEmpty(insProducts)) { // Map> collect = insProducts.stream().collect(Collectors.groupingBy(InsProduct::getInspectionItem)); // Iterator>> iterator = collect.entrySet().iterator(); // while (iterator.hasNext()) { // Map.Entry> entry = iterator.next(); // lists.add(getInspectionItem(entry.getKey(), entry.getValue())); // } // map.put("children", lists); // } // list.add(map); // } // } // return list; // } public Map getInspectionItem(String inspectionItem, List insProducts) { List ids = new ArrayList<>(); List> list = new ArrayList<>(); Map map = new HashMap<>(); map.put("label", inspectionItem); for (InsProduct insProduct : insProducts) { ids.add(insProduct.getId()); list.add(getProductsSubclass(insProduct)); } map.put("value", ids); map.put("children", list); return map; } public Map getProductsSubclass(InsProduct insProduct) { Map map = new HashMap<>(); if(StringUtils.isNotEmpty(insProduct.getInspectionItemSubclass())) { map.put("label",insProduct.getInspectionItemSubclass()); }else { map.put("label",insProduct.getInspectionItem()); } map.put("value",insProduct.getId()); return map; } //审核待检撤销 @Override public void checkUpdate(Integer orderId, Integer state) { InsOrder insOrder = insOrderMapper.selectById(orderId); if (state == 1) { List list = new ArrayList<>(); try { list = Arrays.asList(insOrder.getRevocationInsProductIds().split(",")); } catch (Exception e) { throw new ErrorException("还没有选择应该要撤销的检验项目"); } List ids = list.stream() .map(Integer::parseInt) .collect(Collectors.toList()); List insSamples = insSampleMapper.selectList(Wrappers.lambdaQuery().eq(InsSample::getInsOrderId, orderId)); List collect = insSamples.stream().map(InsSample::getId).collect(Collectors.toList()); List insProducts = insProductMapper.selectList(Wrappers.lambdaQuery().eq(InsProduct::getState, 1).in(InsProduct::getInsSampleId, collect)); if (insProducts.stream().map(InsProduct::getId).collect(Collectors.toList()).equals(ids)) { //如果该检验单下的所有项目全部都撤销,那么这个单子也需要撤销 insOrder.setState(3); } else { List products = insProductMapper.selectBatchIds(ids); //首先根据选择的项目id进行撤销项目 updateBatchById(products.stream().map(insProduct -> { insProduct.setState(0); return insProduct; }).collect(Collectors.toList())); } //insProductMapper.updateInspected(id); } //不通过 insOrder.setIsRevocation(0); insOrderMapper.updateById(insOrder); } @Override public int write2(Integer id, String elasticityModulus) { InsProduct insProduct = new InsProduct(); insProduct.setId(id); insProduct.setElasticityModulus(elasticityModulus); insProductMapper.updateById(insProduct); return 0; } }