zss
2023-08-22 c427ed3db05c772cec3658949e19bcf1b6c0d2a7
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
package com.yuanchu.limslaboratory.service.impl;
 
import com.yuanchu.limslaboratory.mapper.InspectionMapper;
import com.yuanchu.limslaboratory.mapper.InspectionProductMapper;
import com.yuanchu.limslaboratory.pojo.vo.ProjectNumVo;
import com.yuanchu.limslaboratory.pojo.vo.StatisticsDataVo;
import com.yuanchu.limslaboratory.service.HomeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
 
 
@Service
public class HomeServiceImpl implements HomeService {
 
    @Resource
    InspectionMapper inspectionMapper;
 
    @Resource
    InspectionProductMapper inspectionProductMapper;
 
 
    //计算检验与未检验的单子与项目的数量接口
    @Override
    public ProjectNumVo checkProjectNum() {
        ProjectNumVo projectNumVo = new ProjectNumVo();
        //已检验的检验单数量
        projectNumVo.setInsNum(inspectionMapper.seleCountIns());
        //未检验的检验单数量
        projectNumVo.setInsUnNum(inspectionMapper.seleCountUnIns());
        //已检验的检验项目数量
        projectNumVo.setInsproNum(inspectionProductMapper.seleCountInspro());
        //未检验的检验项目数量
        projectNumVo.setInsproUnNum(inspectionProductMapper.seleCountUnInspro());
        return projectNumVo;
    }
 
    //已检验top3
    @Override
    public List<Map<String, Object>> checktop3() {
        //获取检验单总数
        Integer allIns = inspectionMapper.getcount();
        //检验结论,检验数量
        List<Map<String, Object>> mapList = inspectionMapper.getResultNum();
        for (Map<String, Object> map : mapList) {
            //遍历获取数量
            Long num = (Long) map.get("num");
            //计算百分比并存入map中
            map.put("chact", getRadio(allIns, num));
        }
        return mapList;
    }
 
    //未检验tpo4
    @Override
    public List<Map<String, Object>> unchecktop4() {
        //检验项目,设备,检验开始时间,执行人,检验结束时间
        List<Map<String, Object>> mapList = inspectionProductMapper.getResultNum();
        return mapList;
    }
 
    //计算原材料与成品的合格率
    @Override
    @Transactional(rollbackFor = Exception.class)
    public StatisticsDataVo qualified() {
        StatisticsDataVo statisticsDataVo = new StatisticsDataVo();
        //原材料检验单总数
        Integer allmater = inspectionMapper.getallmater();
        //原材料合格率
        Long mater = inspectionMapper.qualified(1);
        statisticsDataVo.setMaterial(getRadio(allmater, mater));
        //原材料不合格率
        Long unmater = inspectionMapper.qualified(0);
        statisticsDataVo.setUnmaterial(getRadio(allmater, unmater));
        //原材料未检验率
        Long notmater = inspectionMapper.qualified(null);
        statisticsDataVo.setNotmaterial(getRadio(allmater, notmater));
 
        //成品检验单总数
        Integer allfin = inspectionMapper.getallfin();
        //成品合格率
        Long finished = inspectionMapper.qualifiedfin(1);
        statisticsDataVo.setFinished(getRadio(allfin, finished));
        //成品不合格率
        Long unfinished = inspectionMapper.qualifiedfin(0);
        statisticsDataVo.setUnfinished(getRadio(allfin, unfinished));
        //成品未检验率
        Long notfinished = inspectionMapper.qualifiedfin(null);
        statisticsDataVo.setNotfinished(getRadio(allfin, notfinished));
 
        return statisticsDataVo;
    }
 
    /*计算百分比*/
    private BigDecimal getRadio(Integer all, Long num) {
        if (all.intValue() == 0) {
            return new BigDecimal(0);
        }
        BigDecimal numBigDecimal = new BigDecimal(num);
        BigDecimal allBigDecimal = new BigDecimal(all);
        BigDecimal divide = numBigDecimal.divide(allBigDecimal, 4, BigDecimal.ROUND_HALF_UP);
        return divide.multiply(new BigDecimal(100));
    }
}