zss
2023-08-30 af9457d7ce94c7684a9439d46b0025bd6e66d8af
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package com.yuanchu.mom.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanchu.mom.mapper.RawInsProductMapper;
import com.yuanchu.mom.pojo.RawInsProduct;
import com.yuanchu.mom.service.RawInsProductService;
import com.yuanchu.mom.utils.MyUtil;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
 
/**
 * 原材料申请单中的项目列表(RawInsProduct)表服务实现类
 *
 * @author zss
 * @since 2023-08-01 13:52:31
 */
@Service
public class RawInsProductServiceImpl extends ServiceImpl<RawInsProductMapper, RawInsProduct> implements RawInsProductService {
 
    @Resource
    RawInsProductMapper rawInsProductMapper;
 
    //更新检验项目
    @Override
    public void updaterawInsProduct(int userId, RawInsProduct rawInsProduct) {
        //赋值检验员id
        rawInsProduct.setUserId(userId);
        //判断检测值是否满足标准值和内控值的要求,如果不满足则检验结论为不合格0
        String testValue = rawInsProduct.getTestValue();//检验值
        String required = rawInsProduct.getRequired();//标准值
        String internal = rawInsProduct.getInternal();//内控值
        rawInsProduct.setTestState(checkValues(required, internal, testValue));
        //根据检验项目名和关联的检验单id来查询检验项目的数据
        LambdaUpdateWrapper<RawInsProduct> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(RawInsProduct::getRawInspectId, rawInsProduct.getRawInspectId())
                .eq(RawInsProduct::getName, rawInsProduct.getName());
        rawInsProductMapper.update(rawInsProduct, updateWrapper);
    }
 
    /*判断检测值是否满足标准值和内控值的要求,如果不满足则检验结论为不合格*/
    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;
            }
        }
    }
}