zss
2023-09-05 b9e2c1619cf61bcd5f24b858fff738244d20566e
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
package com.yuanchu.mom.service.impl;
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yuanchu.mom.mapper.FinishedInspectMapper;
import com.yuanchu.mom.mapper.RawInspectMapper;
import com.yuanchu.mom.pojo.ProReport;
import com.yuanchu.mom.pojo.RawInspect;
import com.yuanchu.mom.pojo.StatisticsData;
import com.yuanchu.mom.service.ResportService;
import lombok.Data;
import org.apache.tomcat.util.buf.StringUtils;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
 
 
@Service
public class ResportServiceImpl implements ResportService {
 
    @Resource
    RawInspectMapper rawInspectMapper;
 
    @Resource
    FinishedInspectMapper finishedInspectMapper;
 
    //计算合格与不合格数量
    @Override
    public StatisticsData turno(String begin, String end) {
        StatisticsData statisticsData = new StatisticsData();
        //原材料合格
        Integer material = rawInspectMapper.selCountRaw(begin, end, 1);
        statisticsData.setMaterial(material);
        //原材料不合格
        Integer unmaterial = rawInspectMapper.selCountRaw(begin, end, 0);
        statisticsData.setUnmaterial(unmaterial);
        //过程合格数
        Integer process = finishedInspectMapper.selCountFin(begin, end, 1, 1);
        statisticsData.setProcess(process);
        //过程不合格
        Integer unprocess = finishedInspectMapper.selCountFin(begin, end, 1, 0);
        statisticsData.setUnprocess(unprocess);
        //成品合格数
        Integer finished = finishedInspectMapper.selCountFin(begin, end, 0, 1);
        statisticsData.setFinished(finished);
        //成品不合格
        Integer unfinished = finishedInspectMapper.selCountFin(begin, end, 0, 0);
        statisticsData.setUnfinished(unfinished);
        return statisticsData;
    }
 
    //计算产品总量
    @Override
    public ProReport allNum() {
        // 获取当前日期的前两个月的日期
        ArrayList<String> dateList = new ArrayList<>();
        LocalDate now = LocalDate.now();
        LocalDate oneAgo = now.minusMonths(1);
        LocalDate twoAgo = now.minusMonths(2);
        // 格式化日期对象
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
        dateList.add(twoAgo.format(formatter));
        dateList.add(oneAgo.format(formatter));
        dateList.add(now.format(formatter));
        //获取原材料月产量
        Long cLong = rawInspectMapper.seAllCount(now.withDayOfMonth(1).toString(), now.plusMonths(1).withDayOfMonth(1).minusDays(1).toString());
        Long bLong = rawInspectMapper.seAllCount(oneAgo.withDayOfMonth(1).toString(), oneAgo.plusMonths(1).withDayOfMonth(1).minusDays(1).toString());
        Long aLong = rawInspectMapper.seAllCount(twoAgo.withDayOfMonth(1).toString(), twoAgo.plusMonths(1).withDayOfMonth(1).minusDays(1).toString());
        ArrayList<String> materialList = new ArrayList<>();
        materialList.add(aLong.toString());
        materialList.add(bLong.toString());
        materialList.add(cLong.toString());
        //获取过程月产量
        Long c1Long = finishedInspectMapper.seAllCount(now.withDayOfMonth(1).toString(), now.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 1);
        Long b1Long = finishedInspectMapper.seAllCount(oneAgo.withDayOfMonth(1).toString(), oneAgo.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 1);
        Long a1Long = finishedInspectMapper.seAllCount(twoAgo.withDayOfMonth(1).toString(), twoAgo.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 1);
        ArrayList<String> processList = new ArrayList<>();
        processList.add(a1Long.toString());
        processList.add(b1Long.toString());
        processList.add(c1Long.toString());
        //获取成品月产量
        Long c2Long = finishedInspectMapper.seAllCount(now.withDayOfMonth(1).toString(), now.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 0);
        Long b2Long = finishedInspectMapper.seAllCount(oneAgo.withDayOfMonth(1).toString(), oneAgo.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 0);
        Long a2Long = finishedInspectMapper.seAllCount(twoAgo.withDayOfMonth(1).toString(), twoAgo.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 0);
        ArrayList<String> finishedList = new ArrayList<>();
        finishedList.add(a2Long.toString());
        finishedList.add(b2Long.toString());
        finishedList.add(c2Long.toString());
        return ProReport.builder()
                .dateList(StringUtils.join(dateList, ','))
                .materialList(StringUtils.join(materialList, ','))
                .processList(StringUtils.join(processList, ','))
                .finishedList(StringUtils.join(finishedList, ','))
                .build();
    }
 
    //计算达标总量
    @Override
    public ProReport statisNum() {
        // 获取当前日期的前两个月的日期
        ArrayList<String> dateList = new ArrayList<>();
        LocalDate now = LocalDate.now();
        LocalDate oneAgo = now.minusMonths(1);
        LocalDate twoAgo = now.minusMonths(2);
        // 格式化日期对象
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
        dateList.add(twoAgo.format(formatter));
        dateList.add(oneAgo.format(formatter));
        dateList.add(now.format(formatter));
        //获取原材料月达标产量
        Integer c = rawInspectMapper.selCountRaw(now.withDayOfMonth(1).toString(), now.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 1);
        Integer b = rawInspectMapper.selCountRaw(oneAgo.withDayOfMonth(1).toString(), oneAgo.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 1);
        Integer a = rawInspectMapper.selCountRaw(twoAgo.withDayOfMonth(1).toString(), twoAgo.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 1);
        ArrayList<String> materialList = new ArrayList<>();
        materialList.add(a.toString());
        materialList.add(b.toString());
        materialList.add(c.toString());
        //获取过程月达标产量
        Integer c1 = finishedInspectMapper.selCountFin(now.withDayOfMonth(1).toString(), now.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 1, 1);
        Integer b1 = finishedInspectMapper.selCountFin(oneAgo.withDayOfMonth(1).toString(), oneAgo.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 1, 1);
        Integer a1 = finishedInspectMapper.selCountFin(twoAgo.withDayOfMonth(1).toString(), twoAgo.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 1, 1);
        ArrayList<String> processList = new ArrayList<>();
        processList.add(a1.toString());
        processList.add(b1.toString());
        processList.add(c1.toString());
        //获取成品月达标产量
        Integer c2 = finishedInspectMapper.selCountFin(now.withDayOfMonth(1).toString(), now.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 0, 1);
        Integer b2 = finishedInspectMapper.selCountFin(oneAgo.withDayOfMonth(1).toString(), oneAgo.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 0, 1);
        Integer a2 = finishedInspectMapper.selCountFin(twoAgo.withDayOfMonth(1).toString(), twoAgo.plusMonths(1).withDayOfMonth(1).minusDays(1).toString(), 0, 1);
        ArrayList<String> finishedList = new ArrayList<>();
        finishedList.add(a2.toString());
        finishedList.add(b2.toString());
        finishedList.add(c2.toString());
        return ProReport.builder()
                .dateList(StringUtils.join(dateList, ','))
                .materialList(StringUtils.join(materialList, ','))
                .processList(StringUtils.join(processList, ','))
                .finishedList(StringUtils.join(finishedList, ','))
                .build();
    }
 
 
    /*计算百分比*/
    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));
    }
}