zss
2023-08-23 36488ef509030773381ea67de9d1aa00ce25caf6
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
package com.yuanchu.limslaboratory.service.impl;
 
import com.yuanchu.limslaboratory.mapper.InspectionMapper;
import com.yuanchu.limslaboratory.mapper.InspectionProductMapper;
import com.yuanchu.limslaboratory.pojo.LineChartVO;
import com.yuanchu.limslaboratory.pojo.LineSeriesVO;
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.time.DayOfWeek;
import java.time.LocalDate;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
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;
    }
 
    //统计
    @Override
    @Transactional(rollbackFor = Exception.class)
    public LineChartVO turno(Integer type) {
        LineChartVO lineChartVO = new LineChartVO();
        List<LineSeriesVO> series = new ArrayList<>();
        //构建第一个lineSeriesVO1(原材料检验数量)
        LineSeriesVO lineSeriesVO1 = new LineSeriesVO();
        lineSeriesVO1.setName("原材料检验数量");
        //构建第二个lineSeriesVO2(成品检验数量)
        LineSeriesVO lineSeriesVO2 = new LineSeriesVO();
        lineSeriesVO2.setName("成品检验数量");
        //构建第三个lineSeriesVO3(原材料合格率)
        LineSeriesVO lineSeriesVO3 = new LineSeriesVO();
        lineSeriesVO3.setName("原材料合格率");
        //构建第四个lineSeriesVO4(成品合格率)
        LineSeriesVO lineSeriesVO4 = new LineSeriesVO();
        lineSeriesVO4.setName("成品合格率");
        List<Object> list1 = new ArrayList<>();
        List<Object> list2 = new ArrayList<>();
        List<Object> list3 = new ArrayList<>();
        List<Object> list4 = new ArrayList<>();
        switch (type) {
            /*本周*/
            case 1:
                List<String> dayofWeeks = getDayofWeeks();
                lineChartVO.setXAxis(dayofWeeks);
                for (String dayofWeek : dayofWeeks) {
                    //查询该日期的原材料检验数量
                    Integer allMaterByDay = inspectionMapper.getMaterByDay(dayofWeek);
                    list1.add(allMaterByDay);
                    //查询该日期的成品检验数量
                    Integer allFinByDay = inspectionMapper.getFinByDay(dayofWeek);
                    list2.add(allFinByDay);
                    //查询该日期的原材料合格率
                    Long okMaterByDay = inspectionMapper.getOkMaterByDay(dayofWeek);
                    list3.add(getRadio(allMaterByDay, okMaterByDay));
                    //查询该日期的成品合格率
                    Long okFinByDay = inspectionMapper.getOkFinByDay(dayofWeek);
                    list4.add(getRadio(allFinByDay, okFinByDay));
                }
                break;
            /*本月*/
            case 2:
                List<String> dayofMonths = getDayofMonth();
                lineChartVO.setXAxis(dayofMonths);
                for (String dayofMonth : dayofMonths) {
                    //查询该日期的原材料检验数量
                    Integer allMaterByDay = inspectionMapper.getMaterByDay(dayofMonth);
                    list1.add(allMaterByDay);
                    //查询该日期的成品检验数量
                    Integer allFinByDay = inspectionMapper.getFinByDay(dayofMonth);
                    list2.add(allFinByDay);
                    //查询该日期的原材料合格率
                    Long okMaterByDay = inspectionMapper.getOkMaterByDay(dayofMonth);
                    list3.add(getRadio(allMaterByDay, okMaterByDay));
                    //查询该日期的成品合格率
                    Long okFinByDay = inspectionMapper.getOkFinByDay(dayofMonth);
                    list4.add(getRadio(allFinByDay, okFinByDay));
                }
                break;
            /*本年*/
            case 3:
                List<String> monthofYears = getMonthofYear();
                lineChartVO.setXAxis(monthofYears);
                for (String monthofYear : monthofYears) {
                    //查询该日期范围内的原材料检验数量
                    Integer allMaterByDay = inspectionMapper.getMaterByMonth(monthofYear);
                    list1.add(allMaterByDay);
                    //查询该日期的成品检验数量
                    Integer allFinByDay = inspectionMapper.getFinByMonth(monthofYear);
                    list2.add(allFinByDay);
                    //查询该日期的原材料合格率
                    Long okMaterByDay = inspectionMapper.getOkMaterByMonth(monthofYear);
                    list3.add(getRadio(allMaterByDay, okMaterByDay));
                    //查询该日期的成品合格率
                    Long okFinByDay = inspectionMapper.getOkFinByMonth(monthofYear);
                    list4.add(getRadio(allFinByDay, okFinByDay));
                }
                break;
        }
        lineSeriesVO1.setData(list1);
        lineSeriesVO2.setData(list2);
        lineSeriesVO3.setData(list3);
        lineSeriesVO4.setData(list4);
        series.add(lineSeriesVO1);
        series.add(lineSeriesVO2);
        series.add(lineSeriesVO3);
        series.add(lineSeriesVO4);
        lineChartVO.setSeries(series);
        return lineChartVO;
    }
 
    /*计算百分比*/
    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));
    }
 
    /*获取本年月份list集合*/
    private List<String> getMonthofYear() {
        // 获取当前年份
        int year = YearMonth.now().getYear();
        // 创建月份列表
        List<String> months = new ArrayList<>();
        // 添加月份到列表
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
        for (int i = 1; i <= 12; i++) {
            YearMonth month = YearMonth.of(year, i);
            String monthString = month.format(formatter);
            months.add(monthString);
        }
        return months;
    }
 
    /*获取本月日份list集合*/
    private List<String> getDayofMonth() {
        // 获取当前日期
        LocalDate now = LocalDate.now();
        // 获取当前月份
        YearMonth currentMonth = YearMonth.from(now);
        // 获取该月的天数
        int daysInMonth = currentMonth.lengthOfMonth();
        // 创建日期列表
        List<String> dates = new ArrayList<>();
        // 添加日期到列表
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        for (int i = 1; i <= daysInMonth; i++) {
            LocalDate date = currentMonth.atDay(i);
            String dateString = date.format(formatter);
            dates.add(dateString);
        }
        return dates;
    }
 
    /*获取本周日份list集合*/
    private List<String> getDayofWeeks() {
        // 获取当前日期
        LocalDate now = LocalDate.now();
        // 获取本周的第一天和最后一天
        LocalDate startOfWeek = now.with(DayOfWeek.MONDAY);
        LocalDate endOfWeek = now.with(DayOfWeek.SUNDAY);
        // 创建日期列表
        List<String> dates = new ArrayList<>();
        // 添加日期到列表
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        while (!startOfWeek.isAfter(endOfWeek)) {
            String dateString = startOfWeek.format(formatter);
            dates.add(dateString);
            startOfWeek = startOfWeek.plusDays(1);
        }
        return dates;
    }
 
 
 
}