zss
2023-09-25 d1ea726be5628c46fb6be700a0197002d55d39f1
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package com.yuanchu.mom.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yuanchu.mom.mapper.InspectionItemMapper;
import com.yuanchu.mom.mapper.TechniqueMapper;
import com.yuanchu.mom.pojo.InspectionItem;
import com.yuanchu.mom.pojo.RawInsProduct;
import com.yuanchu.mom.pojo.dto.InspectionItemDto;
import com.yuanchu.mom.pojo.dto.UpdateInspectionItemDto;
import com.yuanchu.mom.service.DeviceService;
import com.yuanchu.mom.service.InspectionItemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 江苏鵷雏网络科技有限公司
 * @since 2023-08-01
 */
@Service
public class InspectionItemServiceImpl extends ServiceImpl<InspectionItemMapper, InspectionItem> implements InspectionItemService {
 
    @Resource
    private InspectionItemMapper inspectionItemMapper;
 
 
 
 
    //新增按钮-->2、查询所有检验项目
    @Override
    public List<InspectionItemDto> selectInspectionItem(Integer id, Integer type) {
        return inspectionItemMapper.selectInspectionItem(id,type);
    }
 
    //更改设备
    @Override
    public void updateDevByInsId(Integer id, Integer type, Integer devId) {
        LambdaUpdateWrapper<InspectionItem> updateWrapper = Wrappers.<InspectionItem>lambdaUpdate()
                .eq(InspectionItem::getId, id)
                .eq(InspectionItem::getType, type)
                .set(InspectionItem::getDeviceId, devId)
                .set(InspectionItem::getInspectionValue, null)
                .set(InspectionItem::getResult, null);
        inspectionItemMapper.update(new InspectionItem(), updateWrapper);
    }
 
    //新增按钮-->2、检验项目-->失去焦点发起该请求
    @Override
    public Integer addProcessInspectionSheet(String username, UpdateInspectionItemDto updateInspectionItemDto) {
        //查询内控值和标准值
        InspectionItem inspectionItem = inspectionItemMapper.selectById(updateInspectionItemDto.getInspectionItemId());
        inspectionItem.setInspectionValue(updateInspectionItemDto.getInspectionValue());
        inspectionItem.setDeviceId(updateInspectionItemDto.getDeviceId());
        if (updateInspectionItemDto.getInspectionValue().equals("过")){
            inspectionItem.setResult(1);
        }else if (updateInspectionItemDto.getInspectionValue().equals("不过")){
            inspectionItem.setResult(0);
        }else {
            char req = inspectionItem.getRequired().charAt(0);
            List<Integer> list = Arrays.stream(updateInspectionItemDto.getInspectionValue().split(",")).map(s -> {
                int values=2;
                if (req == '>' || req == '<' || req == '=') {
                    values = checkValues(inspectionItem.getRequired(),  inspectionItem.getInternal(), s);
                }else {
                    values = conValues(inspectionItem.getRequired(),  inspectionItem.getInternal(), s);
                }
                return values;
            }).collect(Collectors.toList());
            if (list.contains(0)) {
                //如果其中一个检验值不合格则该项目检验不合格
                inspectionItem.setResult(0);
            } else {
                inspectionItem.setResult(1);
            }
        }
        inspectionItem.setUsername(username);
        inspectionItemMapper.updateById(inspectionItem);
        //返回检验项目的结论
        return inspectionItem.getResult();
    }
 
 
    /*判断检测值是否满足标准值和内控值的要求,如果不满足则检验结论为不合格*/
    //如果是±的操作
    private int conValues(String standardValueStr, String controlValueStr, String detectionValueStr) {
        double standVar = Double.parseDouble(standardValueStr);
        double controlVar = Double.parseDouble(controlValueStr);
        double detecVar = Double.parseDouble(detectionValueStr);
        double a = standVar + controlVar;
        double b = standVar - controlVar;
        if (detecVar >= b && detecVar <= a) {
            return 1;
        }
        return 0;
    }
    //如果是> , < ,=的操作
    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.equals(standardValue);
                case "≥":
                    return detectionValue >= standardValue;
                case "≤":
                    return detectionValue <= standardValue;
                default:
                    return false;
            }
        }
    }
}