zhanghua
2023-04-03 c8688c4239077b123165f3e86a380a41b40f39db
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
package com.ycl.controller.cockpit.aiIot;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ycl.api.CommonResult;
import com.ycl.dto.allot.EfficiencyDto;
import com.ycl.entity.video.VideoPoint;
import com.ycl.service.allot.IEfficiencyService;
import com.ycl.service.carManage.ICarSlagcarService;
import com.ycl.service.equipment.IHandheldTerminalService;
import com.ycl.service.equipment.ILoudspeakerService;
import com.ycl.service.video.impl.IVideoPointService;
import com.ycl.util.CheckApiUtil;
import com.ycl.util.VideoUtil;
import com.ycl.vo.cockpit.CockpitVO;
import com.ycl.vo.cockpit.aiIot.AIIotStatisticsVO;
import com.ycl.vo.cockpit.aiIot.AIIotVO;
import com.ycl.vo.cockpit.aiIot.EfficiencyVO;
import com.ycl.vo.cockpit.aiIot.VideoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.function.ToIntFunction;
import java.util.stream.Collectors;
 
/**
 * @author Lyq
 * @version 1.0
 * @date 2022/10/26
 */
@Api(tags = "驾驶舱数据接口-AI物联")
@RestController
@RequestMapping("/api/lot")
public class AIIotController {
 
    @Resource
    private CheckApiUtil checkApiUtil;
 
    @Autowired
    private IVideoPointService iVideoPointService;
    @Autowired
    private VideoUtil videoUtil;
    @Autowired
    IHandheldTerminalService iHandheldTerminalService;
    @Autowired
    ILoudspeakerService loudspeakerService;
    @Autowired
    ICarSlagcarService iCarSlagcarService;
    @Autowired
    IEfficiencyService iEfficiencyService;
 
 
    @ApiOperation(value = "监测数据")
    @GetMapping("/detection")
    public CommonResult<AIIotVO.DetectionVO> detection(@Validated CockpitVO params) {
        checkApiUtil.cockpit(params);
        AIIotVO.DetectionVO detectionVO = new AIIotVO.DetectionVO();
        detectionVO.setVideo(iVideoPointService.count());
        detectionVO.setIndividual(iHandheldTerminalService.count());
        detectionVO.setLampblack(iEfficiencyService.getSmokeCustomer());
 
        detectionVO.setLoudspeaker(34L);
        detectionVO.setSlagCar(iCarSlagcarService.count());
        return CommonResult.success(detectionVO);
    }
 
    @ApiOperation(value = "实时视频监控")
    @GetMapping("/video")
    public CommonResult video(@Validated CockpitVO params) {
        checkApiUtil.cockpit(params);
        /// TODO: 2022/12/13  视频点位设备为空 没数据
        List<VideoPoint> list = iVideoPointService.list(new LambdaQueryWrapper<VideoPoint>()
                .eq(params.getStreetId() != null, VideoPoint::getStreetId, params.getStreetId())
                .isNotNull(VideoPoint::getPlatResourceId).orderByDesc(VideoPoint::getId));
 
        List<VideoVO> vos = list.stream().map(item -> {
            VideoVO videoVO = new VideoVO();
            videoVO.setName(item.getName());
            videoVO.setBrand(item.getEquipmentBrand());
            videoVO.setModel(item.getEquipmentModel());
            videoVO.setIp(item.getEquipmentIp());
            videoVO.setLatitude(item.getLatitude() != null ? item.getLatitude().toString() : "");
            videoVO.setLongitude(item.getLongitude() != null ? item.getLongitude().toString() : "");
            videoVO.setResourceId(item.getPlatResourceId());
            videoVO.setCode(item.getCode());
            return videoVO;
        }).collect(Collectors.toList());
 
        return CommonResult.success(vos);
 
    }
 
    @ApiOperation(value = "AI算法效能")
    @GetMapping("/efficiency")
    public CommonResult efficiency(@Validated CockpitVO params) {
        checkApiUtil.cockpit(params);
        List<EfficiencyDto> list = iEfficiencyService.list();
        List<EfficiencyVO> efficiencyVOS = list.stream().map((Function<EfficiencyDto, EfficiencyVO>) efficiencyDto -> {
            EfficiencyVO a = new EfficiencyVO();
            a.setType(efficiencyDto.getName());
            a.setCount(efficiencyDto.getNumber());
            a.setRatio(1.0 - ((double) efficiencyDto.getErrorNumber() / (double) efficiencyDto.getNumber()));
            return a;
        }).collect(Collectors.toList());
        efficiencyVOS.add(new EfficiencyVO("店外经营", 0, 0.0));
        efficiencyVOS.add(new EfficiencyVO("沿街晾晒", 0, 0.0));
        efficiencyVOS.add(new EfficiencyVO("无照经营游商", 0, 0.0));
        efficiencyVOS.add(new EfficiencyVO("违规撑伞", 0, 0.0));
        return CommonResult.success(efficiencyVOS);
    }
 
    @ApiOperation(value = "渣土联动")
    @GetMapping("/slag_car")
    public CommonResult<AIIotVO.SlagCarVO> slagCar(@Validated CockpitVO params) {
        checkApiUtil.cockpit(params);
 
        AIIotVO.SlagCarVO slagCarVO = new AIIotVO.SlagCarVO();
        slagCarVO.setCar(iCarSlagcarService.count());
        slagCarVO.setTeam(0L);
 
        return CommonResult.success(slagCarVO);
    }
 
    @ApiOperation(value = "AI事件统计")
    @GetMapping("/event_statistics")
    public CommonResult<List<AIIotStatisticsVO>> statistics(@Validated CockpitVO params) {
        checkApiUtil.cockpit(params);
 
        List<AIIotStatisticsVO> list = iEfficiencyService.aiMonthList(params.getBeginTime(), params.getEndTime());
        return CommonResult.success(list);
    }
 
 
}