Fixiaobai
2023-09-07 e29f147aab5b0b0b794d611b522b67b94423e3cf
inspection-server/src/main/java/com/yuanchu/limslaboratory/service/impl/PlanServiceImpl.java
@@ -1,17 +1,29 @@
package com.yuanchu.limslaboratory.service.impl;
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.*;
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>
@@ -42,10 +54,25 @@
    @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);
    }
    //分配-->选择检验人
@@ -75,21 +102,24 @@
    //检验
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String check(Integer id, String value) {
        //如果检验值不为空
        if (StringUtils.isNotBlank(value)) {
            InspectionProduct inspectionProduct = inspectionProductMapper.selectById(id);
            //判断检测值是否满足标准值和内控值的要求,如果不满足则检验结论为不合格0
            String required = inspectionProduct.getRequired();//标准值
            String internal = inspectionProduct.getInternal();//内控值
            inspectionProduct.setTestValue(value);
            inspectionProduct.setTestState(checkValues(required, internal, value));
            inspectionProductMapper.updateById(inspectionProduct);
        } else {
            //如果检验值为空,将原有的检验结论覆盖为null
            inspectionProductMapper.upda(id);
    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);
        }
        return "提交成功!";
        inspectionProductMapper.updateById(inspectionProduct);
        return inspectionProduct.getTestState();
    }
    //上报
@@ -101,7 +131,7 @@
        List<Integer> results = inspectionProductMapper.getresult(id);
        int count = 0;
        for (Integer result : results) {
            if (result != null && result==1) {
            if (result != null && result == 1) {
                count++;
            }
        }
@@ -110,7 +140,32 @@
            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);
@@ -133,6 +188,7 @@
        report.setStatus(0);
        report.setConclusion(conclusion);
        report.setInspectionId(id);
        //新增检验报告
        reportMapper.insert(report);
        return "上报成功!";
    }