From e29f147aab5b0b0b794d611b522b67b94423e3cf Mon Sep 17 00:00:00 2001 From: Fixiaobai <fixiaobai@163.com> Date: 星期四, 07 九月 2023 17:56:57 +0800 Subject: [PATCH] 修改bug --- inspection-server/src/main/java/com/yuanchu/limslaboratory/service/impl/PlanServiceImpl.java | 191 +++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 183 insertions(+), 8 deletions(-) diff --git a/inspection-server/src/main/java/com/yuanchu/limslaboratory/service/impl/PlanServiceImpl.java b/inspection-server/src/main/java/com/yuanchu/limslaboratory/service/impl/PlanServiceImpl.java index 8eb52e3..4d23c99 100644 --- a/inspection-server/src/main/java/com/yuanchu/limslaboratory/service/impl/PlanServiceImpl.java +++ b/inspection-server/src/main/java/com/yuanchu/limslaboratory/service/impl/PlanServiceImpl.java @@ -1,18 +1,29 @@ package com.yuanchu.limslaboratory.service.impl; -import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; + +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.yuanchu.limslaboratory.mapper.*; -import com.yuanchu.limslaboratory.pojo.InspectionProduct; -import com.yuanchu.limslaboratory.pojo.Instrument; -import com.yuanchu.limslaboratory.pojo.User; -import com.yuanchu.limslaboratory.service.InstrumentService; +import com.yuanchu.limslaboratory.pojo.*; import com.yuanchu.limslaboratory.service.PlanService; +import com.yuanchu.limslaboratory.utils.MyUtil; +import com.yuanchu.limslaboratory.utils.RedisUtil; +import com.yuanchu.limslaboratory.utils.ServletUtils; +import org.apache.commons.lang3.time.DateUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.ObjectUtils; import javax.annotation.Resource; +import java.time.LocalDateTime; +import java.util.Arrays; +import java.util.Date; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * <p> @@ -37,10 +48,31 @@ @Resource InstrumentMapper instrumentMapper; + @Resource + ReportMapper reportMapper; + + @Resource + InspectionMapper inspectionMapper; + + @Resource + InspectionMaterialMapper inspectionMaterialMapper; + + @Resource + LinkDetectionMapper linkDetectionMapper; + + @Resource + private NonConformanceReviewMapper nonConformanceReviewMapper; + //鏌ヨ妫�楠岃鍒� @Override - public List<Map<String,Object>> selectAllPlan(String code , String beginTime, String endTime,Integer status) { - return planMapper.selectAllPlan(code,beginTime,endTime,status); + public List<Map<String, Object>> selectAllPlan(String code, String beginTime, String endTime, Integer status,Boolean isLookMe) { + Object obj = RedisUtil.get(ServletUtils.getRequest().getHeader("X-Token")); + Integer id=null; + if(isLookMe&&!ObjectUtils.isEmpty(obj)){ + Map loginUser = (Map) obj; + id=Integer.parseInt(String.valueOf(loginUser.get("id"))); + } + return planMapper.selectAllPlan(code, beginTime, endTime, status,isLookMe,id); } //鍒嗛厤-->閫夋嫨妫�楠屼汉 @@ -52,7 +84,7 @@ //鍒嗛厤-->閫夋嫨璁惧 @Override public List<Map<String, Object>> chooseinstum() { - return null; + return instrumentMapper.chooseinstum(); } //鍒嗛厤浜哄憳涓庤澶� @@ -60,9 +92,152 @@ public String distribution(Integer id, Integer userId, Integer instrumentId) { InspectionProduct inspectionProduct = new InspectionProduct(); inspectionProduct.setId(id); + //鎵ц浜� inspectionProduct.setUserId(userId); inspectionProduct.setInstrumentId(instrumentId); inspectionProductMapper.updateById(inspectionProduct); return "鍒嗛厤瀹屾垚!"; } + + //妫�楠� + @Override + @Transactional(rollbackFor = Exception.class) + public Integer check(Integer id, String value) { + InspectionProduct inspectionProduct = inspectionProductMapper.selectById(id); + //鍒ゆ柇妫�娴嬪�兼槸鍚︽弧瓒虫爣鍑嗗�煎拰鍐呮帶鍊肩殑瑕佹眰,濡傛灉涓嶆弧瓒冲垯妫�楠岀粨璁轰负涓嶅悎鏍�0 + String required = inspectionProduct.getRequired();//鏍囧噯鍊� + String internal = inspectionProduct.getInternal();//鍐呮帶鍊� + inspectionProduct.setTestValue(value); + List<Integer> list = Arrays.stream(value.split(",")).map(s -> { + int values = checkValues(required, internal, s); + return values; + }).collect(Collectors.toList()); + if (list.contains(0)) { + //濡傛灉鍏朵腑涓�涓楠屽�间笉鍚堟牸鍒欒椤圭洰妫�楠屼笉鍚堟牸 + inspectionProduct.setTestState(0); + }else { + inspectionProduct.setTestState(1); + } + inspectionProductMapper.updateById(inspectionProduct); + return inspectionProduct.getTestState(); + } + + //涓婃姤 + @Override + @Transactional(rollbackFor = Exception.class) + public String reported(Integer id) { + /*鏇存柊妫�楠屽崟閲岄潰鐨勬楠岀粨璁�*/ + //鍏堝垽鏂楠岀粨鏋� + List<Integer> results = inspectionProductMapper.getresult(id); + int count = 0; + for (Integer result : results) { + if (result != null && result == 1) { + count++; + } + } + //濡傛灉妫�楠岄」鐩腑鐨勭粨璁哄寘鍚笉鍚堟牸鍒欐楠屽崟涓嶅悎鏍� + if (results.contains(0)) { + Inspection inspection = new Inspection(); + inspection.setId(id); + inspection.setInspectionStatus(0); + //鏇存柊妫�楠屽崟 + inspectionMapper.updateById(inspection); + //娣诲姞涓嶅悎鏍间俊鎭埌璇勫 + Map<String, Object> map = inspectionMapper.selectImAndUserName(id); + NonConformanceReview nonConformanceReview = new NonConformanceReview(); + LocalDateTime localDateTime = DateUtil.toLocalDateTime(DateUtil.date()); + nonConformanceReview.setCreatedTime(localDateTime); + nonConformanceReview.setUpdatedTime(localDateTime); + nonConformanceReview.setMaterialCode(String.valueOf(map.get("code"))); + nonConformanceReview.setInspectionCode(String.valueOf(map.get("iCode"))); + nonConformanceReview.setMaterialName(String.valueOf(map.get("name"))); + nonConformanceReview.setSpecifications(String.valueOf(map.get("specifications"))); + nonConformanceReview.setSpecificationsId(Integer.valueOf(String.valueOf(map.get("specificationsId")))); + nonConformanceReview.setState(1); + Date iCreateTime = DateUtil.parse(String.valueOf(map.get("iCreateTime"))); + nonConformanceReview.setCreateTime(iCreateTime); + nonConformanceReview.setTestManager(String.valueOf(map.get("uName"))); + Object obj = RedisUtil.get(ServletUtils.getRequest().getHeader("X-Token")); + if (!ObjectUtils.isEmpty(obj)) { + Map loginUser = (Map) obj; + nonConformanceReview.setCreatedUser(String.valueOf(loginUser.get("id"))); + } + int insert = nonConformanceReviewMapper.insert(nonConformanceReview); + if(insert<1){ + return "涓婃姤澶辫触"; + } + } else if (count == results.size()) { + Inspection inspection = new Inspection(); + inspection.setId(id); + inspection.setInspectionStatus(1); + inspectionMapper.updateById(inspection); + } else return "椤圭洰鏈楠屽畬!"; + //鐢熸垚鎶ュ憡鍗� + Report report = new Report(); + //鐢熸垚鎶ュ憡鍗曞彿 + String recode = MyUtil.getTimeSixNumberCode("BG", "BG"); + //鑾峰彇妫�楠岀粨璁� + String conclusion = ""; + Inspection inspection = inspectionMapper.selectById(id); + if (inspection.getInspectionStatus().equals(1)) { + conclusion = "鍚堟牸"; + } else { + conclusion = "涓嶅悎鏍�"; + } + report.setCode(recode); + report.setStatus(0); + report.setConclusion(conclusion); + report.setInspectionId(id); + //鏂板妫�楠屾姤鍛� + reportMapper.insert(report); + return "涓婃姤鎴愬姛!"; + } + + + /*鍒ゆ柇妫�娴嬪�兼槸鍚︽弧瓒虫爣鍑嗗�煎拰鍐呮帶鍊肩殑瑕佹眰,濡傛灉涓嶆弧瓒冲垯妫�楠岀粨璁轰负涓嶅悎鏍�*/ + private int checkValues(String standardValueStr, String controlValueStr, String detectionValueStr) { + boolean isStandardValueSatisfied = isValueSatisfied(standardValueStr, detectionValueStr); + boolean isControlValueSatisfied = isValueSatisfied(controlValueStr, detectionValueStr); + + if (isStandardValueSatisfied && isControlValueSatisfied) { + return 1; + } else { + return 0; + } + } + + private boolean isValueSatisfied(String valueStr, String detectionValueStr) { + String substring = valueStr.substring(1, 2); + if (substring.equals("=")) { + String operator = valueStr.substring(0, 2); + Double standardValue = Double.parseDouble(valueStr.substring(2)); + Double detectionValue = Double.parseDouble(detectionValueStr); + switch (operator) { + case ">=": + return detectionValue >= standardValue; + case "<=": + return detectionValue <= standardValue; + default: + return false; + } + } else { + String operator = valueStr.substring(0, 1); + Double standardValue = Double.parseDouble(valueStr.substring(1)); + Double detectionValue = Double.parseDouble(detectionValueStr); + switch (operator) { + case ">": + return detectionValue > standardValue; + case "鈮�": + return detectionValue >= standardValue; + case "鈮�": + return detectionValue <= standardValue; + case "<": + return detectionValue < standardValue; + case "=": + return detectionValue.equals(standardValue); + default: + return false; + } + } + } } -- Gitblit v1.9.3