wang-hao-jie
2022-03-10 ae32c3a7d77e2ed114555623c70e3fbd1d6aba59
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
package cn.exrick.xboot.your.controller.pc;
 
import cn.exrick.xboot.core.common.redis.RedisTemplateHelper;
import cn.exrick.xboot.core.common.utils.PageUtil;
import cn.exrick.xboot.core.common.utils.ResultUtil;
import cn.exrick.xboot.core.common.vo.PageVo;
import cn.exrick.xboot.core.common.vo.Result;
import cn.exrick.xboot.your.entity.*;
import cn.exrick.xboot.your.service.*;
import cn.exrick.xboot.your.util.HaiKangPost;
import cn.exrick.xboot.your.vo.AlarmVo;
import cn.exrick.xboot.your.vo.PreviewURLsVo;
import cn.exrick.xboot.your.vo.TalkURLsVo;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
 
import java.util.*;
 
/**
 * @author whj
 */
@Slf4j
@RestController
@Api(tags = "大屏统计接口")
@RequestMapping("/xboot/pcStatistic")
@Transactional
public class StatisticController {
 
    @Autowired
    private RedisTemplateHelper redisTemplateHelper;
 
    @Autowired
    private IOrderTaskService iOrderTaskService;
 
    @Autowired
    private IEventLogService iEventLogService;
 
    @Autowired
    private ICarService iCarService;
 
    @Autowired
    private HaiKangPost haiKangPost;
 
    @Autowired
    private IAreaService iAreaService;
 
    @Autowired
    private IAreaSectionService iAreaSectionService;
 
    @Autowired
    private IEquipmentService iEquipmentService;
 
    @Autowired
    private IAlarmService iAlarmService;
 
    @Autowired
    private ICustomerService iCustomerService;
 
    @RequestMapping(value = "/getIndex1", method = RequestMethod.GET)
    @ApiOperation(value = "获取首页数据")
    public Result<Object> getIndex1() {
        Map<String,Object> map = new HashMap<>();
        Set<String> scan = redisTemplateHelper.scan("*statistic1::*");
        for (String str : scan) {
            map.put(str.substring(12),redisTemplateHelper.get(str));
        }
        QueryWrapper<Customer> wrapper = new QueryWrapper<>();
        wrapper.eq("kstatus",0);
        map.put("taKan",iCustomerService.count(wrapper));
        return new ResultUtil<Object>().setData(map);
    }
 
    @RequestMapping(value = "/getTaKanList", method = RequestMethod.GET)
    @ApiOperation(value = "获取踏勘商户列表")
    public Result<Object> getTaKanList() {
        QueryWrapper<Customer> wrapper = new QueryWrapper<>();
        wrapper.eq("kstatus",0);
        return new ResultUtil<Object>().setData(iCustomerService.list(wrapper));
    }
 
    @RequestMapping(value = "/getTodayTask", method = RequestMethod.GET)
    @ApiOperation(value = "获取今日配送任务")
    public Result<Object> getTodayTask() {
        QueryWrapper<OrderTask> wrapper2 = new QueryWrapper<OrderTask>();
        String format = DateUtil.format(new Date(), "yyyy-MM-dd");
        wrapper2.eq("a.send_date",format);
        //wrapper2.orderByAsc("a.seq");
        List<OrderTask> list = iOrderTaskService.list3(format);
        return new ResultUtil<Object>().setData(list);
    }
 
    @RequestMapping(value = "/getEventLog", method = RequestMethod.GET)
    @ApiOperation(value = "获取事件日志")
    public Result<Object> getEventLog() {
        QueryWrapper<EventLog> wrapper2 = new QueryWrapper<EventLog>();
        PageVo page = new PageVo();
        page.setPageNumber(1);
        page.setPageSize(20);
        page.setOrder("desc");
        page.setSort("createTime");
        IPage<EventLog> data = iEventLogService.page(PageUtil.initMpPage(page),wrapper2);
        return new ResultUtil<Object>().setData(data.getRecords());
    }
 
    @RequestMapping(value = "/getCars", method = RequestMethod.GET)
    @ApiOperation(value = "获取车辆定位信息")
    public Result<Object> getCars() {
        List<Car> list = iCarService.list();
        List<String> list2 = new ArrayList<>();
 
        for(int i=0;i<list.size();i++){
            if(!StrUtil.isEmpty(list.get(i).getCode())){
                list2.add(list.get(i).getCode());
            }
        }
 
        String codes[] = new String[list2.size()];
        for(int i=0;i<list2.size();i++){
            codes[i] = list2.get(i);
        }
        String latestGps = haiKangPost.findLatestGps(codes);
        return new ResultUtil<Object>().setData(JSONUtil.parseObj(latestGps));
    }
 
    @RequestMapping(value = "/getAnalysis", method = RequestMethod.GET)
    @ApiOperation(value = "获取配送分析")
    public Result<Object> getAnalysis() {
        List<Area> list = iAreaService.list2();
        for(Area area:list){
            double sum = 0;
            int flag = 0;
            for(AreaSection areaSection: area.getChildren()){
                sum+=areaSection.getStability();
                flag++;
            }
            if(flag>0){
                double v = sum / flag;
                area.setVariance(trans2(v));
            }
        }
        return new ResultUtil<Object>().setData(list);
    }
 
    @RequestMapping(value = "/getAnalysisDetail", method = RequestMethod.GET)
    @ApiOperation(value = "获取配送分析详情")
    public Result<Object> getAnalysisDetail(String areaName,String selectName) {
        QueryWrapper<Area> wrapper = new QueryWrapper<Area>();
        wrapper.eq("name",areaName);
        Area one = iAreaService.getOne(wrapper);
 
        QueryWrapper<AreaSection> wrapper2 = new QueryWrapper<AreaSection>();
        wrapper2.eq("area_id",one.getId());
        wrapper2.eq("name",selectName);
        AreaSection one1 = iAreaSectionService.getOne(wrapper2);
 
        List<OrderTask> list = iOrderTaskService.groupByTime(one.getId(),one1.getId());
 
        List<String> list1 = new ArrayList<>();
        List<Integer> list2 = new ArrayList<>();
        List<Integer> list3 = new ArrayList<>();
        List<Integer> list4 = new ArrayList<>();
 
        for(OrderTask obj:list){
            list1.add(obj.getCustomerName());
            list2.add(Integer.valueOf(obj.getTime()/60000));
            list3.add(Integer.valueOf(obj.getNum()/60000));
            list4.add(Integer.valueOf(obj.getLevel()/60000));
        }
        Map<String,Object> map = new HashMap<>();
        map.put("name",list1);
        map.put("avg",list2);
        map.put("min",list3);
        map.put("max",list4);
 
        return new ResultUtil<Object>().setData(map);
    }
 
    @RequestMapping(value = "/getOrderStatus", method = RequestMethod.GET)
    @ApiOperation(value = "获取某辆车的配送情况")
    public Result<Object> getOrderStatus(String carNo) {
 
        QueryWrapper<Car> wrapper = new QueryWrapper<>();
        wrapper.eq("car_no",carNo);
        Car car = iCarService.getOne(wrapper);
 
        if(car==null){
           return ResultUtil.error("车辆不存在,请先添加车辆信息");
        }
 
        QueryWrapper<OrderTask> wrapper2 = new QueryWrapper<OrderTask>();
        String format = DateUtil.format(new Date(), "yyyy-MM-dd");
        wrapper2.eq("a.send_date",format);
        wrapper2.eq("a.car_id",car.getId());
        List<OrderTask> list = iOrderTaskService.list4(wrapper2);
 
        return new ResultUtil<Object>().setData(list);
    }
 
    @RequestMapping(value = "/getVideoByCarId", method = RequestMethod.GET)
    @ApiOperation(value = "获取视频信息 1:前置 4:车内")
    public Result<Object> getVideoByCarId(String carCode,int type) {
        QueryWrapper<Car> wrapper = new QueryWrapper<Car>();
        wrapper.eq("code",carCode);
        Car car = iCarService.getOne(wrapper);
        if(car==null){
            return ResultUtil.error("车辆编号错误");
        }
 
        QueryWrapper<Equipment> wrapper1 = new QueryWrapper<>();
        wrapper1.eq("car_id",car.getId());
        wrapper1.eq("type",type);
        Equipment one = iEquipmentService.getOne(wrapper1);
        if(one==null){
            return ResultUtil.error("设备未找到");
        }
 
        PreviewURLsVo previewURLsVo = new PreviewURLsVo();
        previewURLsVo.setCameraIndexCode(one.getCode());
        String s = haiKangPost.previewURLs(previewURLsVo);
        return new ResultUtil<Object>().setData(JSONUtil.parseObj(s));
    }
 
    @RequestMapping(value = "/getYuYinByCarId", method = RequestMethod.GET)
    @ApiOperation(value = "获取对讲信息")
    public Result<Object> getYuYinByCarId(String carCode,int type,int transmode) {
        QueryWrapper<Car> wrapper = new QueryWrapper<Car>();
        wrapper.eq("code",carCode);
        Car car = iCarService.getOne(wrapper);
        if(car==null){
            return ResultUtil.error("车辆编号错误");
        }
 
        QueryWrapper<Equipment> wrapper1 = new QueryWrapper<>();
        wrapper1.eq("car_id",car.getId());
        wrapper1.eq("type",type);
        Equipment one = iEquipmentService.getOne(wrapper1);
        if(one==null){
            return ResultUtil.error("设备未找到");
        }
 
        TalkURLsVo talkURLsVo =new TalkURLsVo();
        talkURLsVo.setCameraIndexCode(one.getCode());
        talkURLsVo.setTransmode(transmode);
        String s = haiKangPost.talkURLs(talkURLsVo);
        return new ResultUtil<Object>().setData(JSONUtil.parseObj(s));
    }
 
    @RequestMapping(value = "/getAlarmByCarId", method = RequestMethod.GET)
    @ApiOperation(value = "获取报警图片")
    public Result<Object> getAlarmByCarId(String alarmId) {
        QueryWrapper<Alarm> wrapper = new QueryWrapper<Alarm>();
        wrapper.eq("alarm_id",alarmId);
        Alarm alarm = iAlarmService.getOne(wrapper);
        if(alarm==null){
            return ResultUtil.error("报警id错误");
        }
 
        AlarmVo alarmVo = new AlarmVo();
        alarmVo.setAlarmId(alarm.getAlarmId());
        String[] s1 = alarm.getAlarmTime().split(" ");
        alarmVo.setAlarmTime(s1[0]+"T"+s1[1]+".000+08:00");
        String s = haiKangPost.findPicturesByAlarmId(alarmVo);
        return new ResultUtil<Object>().setData(JSONUtil.parseObj(s));
    }
 
    public double trans2(double v2){
        return (double) Math.round(v2 * 100) / 100;
    }
 
 
    @RequestMapping(value = "/getYiHuDuoZheng", method = RequestMethod.GET)
    @ApiOperation(value = "获取配送分析详情")
    public Result<Object> getYiHuDuoZheng() {
 
        List<Customer> list = iCustomerService.getYiHuDuoZheng();
        Map<String,Object> map = new HashMap<>();
        map.put("name","一户多证");
        List<Object> childrens = new ArrayList<>();
        for(Customer c:list){
            Map<String,Object> map2 = new HashMap<>();
            map2.put("name",c.getName());
 
            List<Object> names = new ArrayList<>();
            Map<String,Object> map3 = new HashMap<>();
            map3.put("name",c.getCode());
            names.add(map3);
 
            map2.put("children",names);
 
            childrens.add(map2);
        }
        map.put("children",childrens);
 
        return new ResultUtil<Object>().setData(map);
    }
}