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
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
package com.ycl.smoke.task;
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ycl.smoke.dto.EventAddParamDto;
import com.ycl.smoke.dto.EventAddResponseDto;
import com.ycl.smoke.dto.ResultResponseDto;
import com.ycl.smoke.entity.BaseCase;
import com.ycl.smoke.entity.VideoAlarmReport;
import com.ycl.smoke.entity.Violations;
import com.ycl.smoke.mapper.BaseCaseMapper;
import com.ycl.smoke.mapper.VideoAlarmReportMapper;
import com.ycl.smoke.mapper.ViolationsMapper;
import com.ycl.smoke.service.CityPlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.List;
 
@Component
public class CityUploadTask {
 
    @Resource
    BaseCaseMapper baseCaseMapper;
 
    @Resource
    ViolationsMapper violationsMapper;
 
 
    @Resource
    VideoAlarmReportMapper videoAlarmReportMapper;
 
    @Autowired
    CityPlatformService cityPlatformService;
 
 
    @Scheduled(cron = "0 */5 * * * ?")   // 每5分钟执行
    public void upload() {
        QueryWrapper<BaseCase> wrapperWc = new QueryWrapper<>();
        wrapperWc.lambda().eq(BaseCase::getState, 10);
        List<BaseCase> baseCases = baseCaseMapper.selectList(wrapperWc);
 
        baseCases.forEach(o -> {
 
            Violations violations = violationsMapper.selectById(o.getId());
            String medias = "";
            String eventDesc = "";
            if (violations != null) {
                eventDesc = violations.getDescription();
                VideoAlarmReport videoAlarmReport = videoAlarmReportMapper.selectById(violations.getVideoAlarmReportId());
                if (videoAlarmReport != null) {
                    StringBuilder stringBuilder = new StringBuilder().append("[{'mediaURL':'").append(videoAlarmReport.getPicData()).append(videoAlarmReport.getPicData()).append("'}]");
                    medias = stringBuilder.toString();
                }
            }
            EventAddParamDto dto = EventAddParamDto.builder().y84(o.getLatitude() != null ? o.getLatitude().toString() : "")
                    .x84(o.getLongitude() != null ? o.getLongitude().toString() : "")
                    .source(11).address(o.getSite()).eventDesc(eventDesc).eventSign(o.getCode())
                    .medias(medias).build();
            String msg = cityPlatformService.addEvent(dto);
            ResultResponseDto result = JSONObject.parseObject(msg, ResultResponseDto.class);
            System.out.println("--" + result.toString());
            if (result.getCode() == 0) {
                try {
 
                    // EventAddResponseDto responseDto = JSONObject.parseObject(result.getResult(), EventAddResponseDto.class);
                    // o.setTaskCode(responseDto.getTaskcode());
                    o.setTaskCode(result.getResult());
                    o.setState(2);
                    baseCaseMapper.updateById(o);
//                    System.out.println("--更新成功");
 
                } catch (Exception ex) {
 
                    System.out.println("--" + ex.getMessage());
                }
            }
 
        });
    }
}