¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.yuanchu.mom.utils; |
| | | |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.context.AnalysisContext; |
| | | import com.alibaba.excel.event.AnalysisEventListener; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.yuanchu.mom.excel.HuTiaoData; |
| | | import com.yuanchu.mom.mapper.InsOrderStateMapper; |
| | | import com.yuanchu.mom.mapper.InsProductMapper; |
| | | import com.yuanchu.mom.mapper.InsProductResult2Mapper; |
| | | import com.yuanchu.mom.mapper.InsSampleMapper; |
| | | import com.yuanchu.mom.pojo.*; |
| | | import com.yuanchu.mom.service.InsOrderPlanService; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Component |
| | | public class DianLuUtils { |
| | | |
| | | @Value("${wordUrl}") |
| | | private String wordUrl; |
| | | |
| | | @Resource |
| | | private InsProductMapper insProductMapper; |
| | | |
| | | @Resource |
| | | private InsSampleMapper insSampleMapper; |
| | | |
| | | @Resource |
| | | private InsProductResult2Mapper insProductResult2Mapper; |
| | | |
| | | @Resource |
| | | private InsOrderStateMapper insOrderStateMapper; |
| | | |
| | | //读åäºè°çæä»¶ |
| | | public void readDianLuFile1(Integer sampleId,InsOrderFile insOrderFile) { |
| | | String excelFilePath = wordUrl + "/" + insOrderFile.getFileUrl(); // æ´æ°ä¸ºä½ çæä»¶è·¯å¾ |
| | | List<HuTiaoData> huTiaoData = readExcelData(excelFilePath); |
| | | //æ¥è¯¢è¯¥æ ·åçäºè°é¡¹ç®id |
| | | List<InsProduct> products = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getState, 1) |
| | | .eq(InsProduct::getInsSampleId, sampleId) |
| | | .eq(InsProduct::getInspectionItemSubclass, "äºè°")); |
| | | //æ¥è¯¢æ£éªä»»å¡id |
| | | List<InsOrderState> orderStates = insOrderStateMapper.selectList(Wrappers.<InsOrderState>lambdaQuery() |
| | | .eq(InsOrderState::getInsSampleId, sampleId) |
| | | .eq(InsOrderState::getLaboratory, "çµè·¯è¯éª")); |
| | | //æ¥è¯¢åææ£éªæ°æ® |
| | | List<InsProduct> productList = getInsProduct(sampleId, "çµè·¯è¯éª"); |
| | | //æ ¹æ®é¢ç¹åç±» |
| | | Map<String, List<HuTiaoData>> collect = huTiaoData.stream().collect(Collectors.groupingBy(HuTiaoData::getOften,LinkedHashMap::new, Collectors.toList())); |
| | | for (Map.Entry<String, List<HuTiaoData>> stringListEntry : collect.entrySet()) { |
| | | InsProductResult2 insProductResult2 = new InsProductResult2(); |
| | | insProductResult2.setOften(stringListEntry.getKey()+"(M)");//é¢ç¹ |
| | | //æ ¹æ®ä¸å¾è§è¿è¡åç±» |
| | | Map<String, List<HuTiaoData>> collect1 = stringListEntry.getValue().stream().collect(Collectors.groupingBy(HuTiaoData::getAngle,LinkedHashMap::new, Collectors.toList())); |
| | | String angles = collect1.entrySet().stream().map(stringListEntry1 -> stringListEntry1.getKey() + "°").collect(Collectors.joining(",")); |
| | | insProductResult2.setAngle(angles); //ä¸å¾è§ |
| | | //æ ¹æ®ç«¯å£å·è¿è¡åç±» |
| | | Map<String, List<HuTiaoData>> collect2 = stringListEntry.getValue().stream().collect(Collectors.groupingBy(HuTiaoData::getPort,LinkedHashMap::new, Collectors.toList())); |
| | | String ports = collect2.entrySet().stream().map(Map.Entry::getKey).collect(Collectors.joining(",")); |
| | | insProductResult2.setPort(ports); //端å£å· |
| | | //éè¿åä¸ç«¯å£å·åä¸ä¸å¾è§è·åæå¤§æ£éªå¼ |
| | | List<String> string = new ArrayList<>(); |
| | | for (Map.Entry<String, List<HuTiaoData>> listEntry : collect1.entrySet()) { |
| | | Map<String, List<HuTiaoData>> collect3 = listEntry.getValue().stream().collect(Collectors.groupingBy(HuTiaoData::getPort,LinkedHashMap::new, Collectors.toList())); |
| | | List<String> stringList = new ArrayList<>(); |
| | | for (Map.Entry<String, List<HuTiaoData>> entry : collect3.entrySet()) { |
| | | OptionalDouble max = entry.getValue().stream().mapToDouble(value -> Double.parseDouble(value.getValue())).max(); |
| | | stringList.add(String.valueOf(max.getAsDouble())); |
| | | } |
| | | string.add("[" + stringList.stream().collect(Collectors.joining(",")) + "]"); |
| | | } |
| | | String value = "[" + string.stream().collect(Collectors.joining(",")) + "]"; |
| | | insProductResult2.setValue(value); |
| | | insProductResult2.setInsProductId(products.get(0).getId()); |
| | | //æ¬¡æ° |
| | | insProductResult2.setNum(orderStates.get(0).getNum()); |
| | | //颿®µ(å
夿忿°æ®æ¯å¦æ) |
| | | if (ObjectUtils.isNotEmpty(productList.get(0).getInsProductResult2())) { |
| | | insProductResult2.setFrequency(productList.get(0).getInsProductResult2().get(0).getFrequency()); |
| | | } |
| | | insProductResult2Mapper.insert(insProductResult2); |
| | | } |
| | | } |
| | | |
| | | |
| | | public static List<HuTiaoData> readExcelData(String filePath) { |
| | | List<HuTiaoData> dataList = new ArrayList<>(); |
| | | |
| | | // åå§åçå¬å¨ |
| | | AnalysisEventListener<HuTiaoData> listener = new AnalysisEventListener<HuTiaoData>() { |
| | | @Override |
| | | public void invoke(HuTiaoData data, AnalysisContext context) { |
| | | // å¤çæ¯è¡æ°æ®ï¼è¿éç®åå°æ·»å å°æ°æ®åè¡¨ä¸ |
| | | dataList.add(data); |
| | | } |
| | | |
| | | @Override |
| | | public void doAfterAllAnalysed(AnalysisContext context) { |
| | | // æææ°æ®è§£æå®æåçæä½ï¼è¿éæä¸å®ç° |
| | | } |
| | | }; |
| | | |
| | | // 读åExcelæä»¶ |
| | | EasyExcel.read(filePath, HuTiaoData.class, listener).sheet().doRead(); |
| | | |
| | | return dataList; |
| | | } |
| | | |
| | | public List<InsProduct> getInsProduct(Integer id, String laboratory) { |
| | | List<InsProduct> insProducts = new ArrayList<>(); |
| | | //æ ·å |
| | | insProducts = insSampleMapper.getInsProduct1(id, laboratory); |
| | | if (insProducts.size() == 0) { |
| | | insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getInsSampleId, id) |
| | | .eq(InsProduct::getState, 1) |
| | | .eq(InsProduct::getSonLaboratory, laboratory)); |
| | | for (InsProduct insProduct : insProducts) { |
| | | List<InsProductResult2> insProductResult2List = insProductResult2Mapper.selectList(Wrappers.<InsProductResult2>lambdaQuery() |
| | | .eq(InsProductResult2::getInsProductId, insProduct.getId()).isNull(InsProductResult2::getNum)); |
| | | insProduct.setInsProductResult2(insProductResult2List); |
| | | } |
| | | } |
| | | return insProducts; |
| | | } |
| | | } |