zhanghua
2023-12-12 bc2da7908a227c09e5cc7b6d8dab3e9c94b784a1
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
package com.ycl.service.apidata.impl;
 
import com.ycl.mapper.apidata.ApiDataMapper;
import com.ycl.service.apidata.IApiDataService;
import com.ycl.vo.cockpit.aiIot.EfficiencyVO;
import com.ycl.vo.cockpit.statisticsEvents.StatisticsEventsVO;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;
 
@Service
public class IApiDataServiceImpl implements IApiDataService {
 
    @Resource
    private ApiDataMapper apiDataMapper;
 
    @Override
    public List<StatisticsEventsVO.Top10VO> listTop10(String beginTime, String endTime) {
 
        return apiDataMapper.listTop10(beginTime, endTime);
    }
 
    @Override
    public List<StatisticsEventsVO.ArithmeticVO> arithmeticEvent(Integer streetId, String beginTime, String endTime) {
        List<StatisticsEventsVO.ArithmeticVO> list = apiDataMapper.arithmeticEvent(streetId, beginTime, endTime);
        List<String> dic = Arrays.asList("无照经营游商", "占道经营", "店外经营", "非机动车乱停放", "违规撑伞", "沿街晾挂", "机动车乱停放", "群发性事件");
        while (list.size() < 8) {
            for (int i = 0; i < dic.size(); i++) {
                int finalI = i;
                long count = list.stream().filter(o -> o.getName().equals(dic.get(finalI))).count();
                if (count == 0) {
                    list.add(new StatisticsEventsVO.ArithmeticVO(dic.get(finalI), 0, 0.0));
                    break;
                }
            }
        }
        // list.add(new StatisticsEventsVO.ArithmeticVO("店外经营", 0, 0.0));
        // list.add(new StatisticsEventsVO.ArithmeticVO("沿街晾晒", 0, 0.0));
        // list.add(new StatisticsEventsVO.ArithmeticVO("无照经营游商", 0, 0.0));
        // list.add(new StatisticsEventsVO.ArithmeticVO("违规撑伞", 0, 0.0));
        Integer all = list.stream().flatMapToInt(o -> IntStream.of(o.getCount())).sum();
        list.stream().forEach(o -> {
            o.setRatio(new BigDecimal(((double) o.getCount() / (double) all)).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue());
        });
        return list;
    }
 
    @Override
    public List<StatisticsEventsVO.LotVO> listLot(Integer streetId, String beginTime, String endTime) {
        return apiDataMapper.listLot(streetId, beginTime, endTime);
    }
}