baizonghao
2023-02-24 e16e9a3ef7eb82daeb139fd9252213579e2bed25
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
package com.ycl.service.unlawful.impl;
 
import com.ycl.dto.statistics.CategoryDto;
import com.ycl.dto.statistics.StatusDto;
import com.ycl.dto.statistics.TimeDto;
import com.ycl.dto.statistics.UnlawfulDto;
import com.ycl.mapper.unlawful.UnlawfulMapper;
import com.ycl.service.unlawful.UnlawfulService;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.math.RoundingMode;
import java.text.NumberFormat;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
 
@Service
public class UnlawfulServiceImpl implements UnlawfulService {
 
    @Resource
    private UnlawfulMapper unlawfuldao;
 
 
    /**
     * 按类型
     */
    @Override
    public List<UnlawfulDto> getUnlawfulByType(Integer currentPage, Integer pageSize, String startTime, String endTime) {
        List<UnlawfulDto> res = new ArrayList<>();
        Double total = unlawfuldao.getTotal().doubleValue();
        List<CategoryDto> data = unlawfuldao.getDataByType(currentPage, pageSize, startTime, endTime);
        data.forEach(categoryDto -> {
            StatusDto statusData = unlawfuldao.getStatusDataByType(startTime, endTime, categoryDto.getId());
            format(res, total, categoryDto, statusData);
        });
        return res;
    }
    @Override
    public List<UnlawfulDto> getUnlawfulByTypeExport() {
        List<UnlawfulDto> res = new ArrayList<>();
        Double total = unlawfuldao.getTotal().doubleValue();
        List<CategoryDto> data = unlawfuldao.getDataByTypeExp();
        data.forEach(categoryDto -> {
            StatusDto statusData = unlawfuldao.getStatusDataByType(null, null, categoryDto.getId());
            format(res, total, categoryDto, statusData);
        });
        return res;
    }
 
    @Override
    public Integer getTotalByType(String startTime, String endTime) {
        return unlawfuldao.getTotalByType(startTime, endTime);
    }
 
    /**
     * 按区域
     */
    @Override
    public List<UnlawfulDto> getUnlawfulByStreet(Integer currentPage, Integer pageSize, String startTime, String endTime) {
        List<UnlawfulDto> res = new ArrayList<>();
        Double total = unlawfuldao.getTotal().doubleValue();
        List<CategoryDto> data = unlawfuldao.getDataByStreet(currentPage, pageSize, startTime, endTime);
        data.forEach(categoryDto -> {
            StatusDto statusData = unlawfuldao.getStatusDataByStreet(startTime, endTime, categoryDto.getId());
            format(res, total, categoryDto, statusData);
        });
        return res;
    }
    @Override
    public List<UnlawfulDto> getUnlawfulByStreetExport() {
        List<UnlawfulDto> res = new ArrayList<>();
        Double total = unlawfuldao.getTotal().doubleValue();
        List<CategoryDto> data = unlawfuldao.getDataByStreetExp();
        data.forEach(categoryDto -> {
            StatusDto statusData = unlawfuldao.getStatusDataByStreet(null, null, categoryDto.getId());
            format(res, total, categoryDto, statusData);
        });
        return res;
    }
 
    @Override
    public Integer getTotalByStreet(String startTime, String endTime) {
        return unlawfuldao.getTotalByStreet(startTime, endTime);
    }
 
    /**
     * 按报警点位
     */
    @Override
    public List<UnlawfulDto> getUnlawfulBySite(Integer currentPage, Integer pageSize, String startTime, String endTime) {
        List<UnlawfulDto> res = new ArrayList<>();
        Double total = unlawfuldao.getTotal().doubleValue();
        List<String> data = unlawfuldao.getDataBySite(currentPage, pageSize, startTime, endTime);
        data.forEach(site -> {
            StatusDto statusData = unlawfuldao.getStatusDataBySite(startTime, endTime, site);
            format1(res, total, site, statusData);
        });
        return res;
    }
    @Override
    public List<UnlawfulDto> getUnlawfulBySiteExport() {
        List<UnlawfulDto> res = new ArrayList<>();
        Double total = unlawfuldao.getTotal().doubleValue();
        List<String> data = unlawfuldao.getDataBySiteExp();
        data.forEach(site -> {
            StatusDto statusData = unlawfuldao.getStatusDataBySite(null, null, site);
            format1(res, total, site, statusData);
        });
        return res;
    }
 
    @Override
    public Integer getTotalBySite(String startTime, String endTime) {
        return unlawfuldao.getTotalBySite(startTime, endTime);
    }
 
    @Override
    public List<UnlawfulDto> getUnlawfulByTime(Integer currentPage, Integer pageSize, String startTime, String endTime) {
        List<UnlawfulDto> res = new ArrayList<>();
        Double total = unlawfuldao.getTotal().doubleValue();
        List<TimeDto> data = unlawfuldao.getDataByTime(currentPage, pageSize, startTime, endTime);
        data.forEach(timeDto -> {
            StatusDto statusData = unlawfuldao.getStatusDataByTime(startTime, endTime, timeDto.getId());
            format2(res, total, timeDto, statusData);
        });
        return res;
    }
 
 
 
    @Override
    public List<UnlawfulDto> getUnlawfulByTimeExport() {
        List<UnlawfulDto> res = new ArrayList<>();
        Double total = unlawfuldao.getTotal().doubleValue();
        List<TimeDto> data = unlawfuldao.getDataByTimeExp();
        data.forEach(timeDto -> {
            StatusDto statusData = unlawfuldao.getStatusDataByTime(null, null, timeDto.getId());
            format2(res, total, timeDto, statusData);
        });
        return res;
    }
 
    @Override
    public Integer getTotalByTime(String startTime, String endTime) {
        return unlawfuldao.getTotalBySite(startTime, endTime);
    }
 
    private Double changeFormat(Double previous){
        NumberFormat numberInstance = NumberFormat.getNumberInstance();
        numberInstance.setMaximumFractionDigits(3);
        numberInstance.setRoundingMode(RoundingMode.HALF_UP);
        String format = numberInstance.format(previous);
        return Double.parseDouble(format);
    }
 
    private void format(List<UnlawfulDto> res, Double total, CategoryDto categoryDto, StatusDto statusData) {
        UnlawfulDto build = UnlawfulDto.builder().name(categoryDto.getName())     //类型名称
                .count(statusData.getTotal())   //事件总数
                .ratio(changeFormat(statusData.getTotal().doubleValue() / total))     //占比
                .register(statusData.getRegister())     //立案
                .notRegister(statusData.getNotRegister())   //暂不立案
                .closing(statusData.getClosing())   //结案
                .relearn(statusData.getRelearn())   //在学习
                .checked(statusData.getChecked())   //已审核
                .checkedRatio(changeFormat(statusData.getChecked().doubleValue() / statusData.getTotal().doubleValue()))  //审核率
                .registerRatio(changeFormat(statusData.getRegister().doubleValue() / statusData.getTotal().doubleValue()))    //立案率
                .build();
        res.add(build);
    }
 
    private void format2(List<UnlawfulDto> res, Double total, TimeDto timeDto, StatusDto statusData) {
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        UnlawfulDto build = UnlawfulDto.builder().name(timeDto.getTime().format(fmt))     //类型名称
                .count(statusData.getTotal())   //事件总数
                .ratio(changeFormat(statusData.getTotal().doubleValue() / total))     //占比
                .register(statusData.getRegister())     //立案
                .notRegister(statusData.getNotRegister())   //暂不立案
                .closing(statusData.getClosing())   //结案
                .relearn(statusData.getRelearn())   //在学习
                .checked(statusData.getChecked())   //已审核
                .checkedRatio(changeFormat(statusData.getChecked().doubleValue() / statusData.getTotal().doubleValue()))  //审核率
                .registerRatio(changeFormat(statusData.getRegister().doubleValue() / statusData.getTotal().doubleValue()))    //立案率
                .build();
        res.add(build);
    }
 
    private void format1(List<UnlawfulDto> res, Double total, String site, StatusDto statusData) {
        UnlawfulDto build = UnlawfulDto.builder().name(site)     //类型名称
                .count(statusData.getTotal())   //事件总数
                .ratio(changeFormat(statusData.getTotal().doubleValue() / total))     //占比
                .register(statusData.getRegister())     //立案
                .notRegister(statusData.getNotRegister())   //暂不立案
                .closing(statusData.getClosing())   //结案
                .relearn(statusData.getRelearn())   //在学习
                .checked(statusData.getChecked())   //已审核
                .checkedRatio(changeFormat(statusData.getChecked().doubleValue() / statusData.getTotal().doubleValue()))  //审核率
                .registerRatio(changeFormat(statusData.getRegister().doubleValue() / statusData.getTotal().doubleValue()))    //立案率
                .build();
        res.add(build);
    }
}