zhanghua
2022-09-29 94e964d96cdacef8bf255c09cb90c0366a074c68
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
package com.ycl.service.caseHandler.impl;
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ycl.bo.casePool.CasePoolIllegalBuildingDO;
import com.ycl.bo.casePool.CasePoolViolationDO;
import com.ycl.dto.casePool.IllegalBuildingParam;
import com.ycl.dto.casePool.ViolationParam;
import com.ycl.entity.caseHandler.BaseCase;
import com.ycl.entity.caseHandler.IllegalBuilding;
import com.ycl.entity.caseHandler.Violations;
import com.ycl.entity.video.VideoAlarmReport;
import com.ycl.mapper.caseHandler.BaseCaseMapper;
import com.ycl.mapper.caseHandler.IllegalBuildingMapper;
import com.ycl.mapper.caseHandler.ViolationsMapper;
import com.ycl.mapper.dict.DataDictionaryMapper;
import com.ycl.remote.dto.*;
import com.ycl.remote.service.CityPlatformService;
import com.ycl.service.caseHandler.IBaseCaseService;
import com.ycl.service.caseHandler.IViolationsService;
import com.ycl.service.video.IVideoAlarmReportService;
import com.ycl.vo.casePool.CasePoolIllegalBuildingVO;
import com.ycl.vo.casePool.CasePoolViolationVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 案件基本信息 服务实现类
 * </p>
 *
 * @author wl
 * @since 2022-09-24
 */
@Service
public class BaseCaseServiceImpl extends ServiceImpl<BaseCaseMapper, BaseCase> implements IBaseCaseService {
 
    private CityPlatformService cityPlatformService;
    private IViolationsService violationsService;
    private IVideoAlarmReportService videoAlarmReportService;
 
    @Value("${fdfs.fileUrl}")
    private String fileUrl;
 
    @Autowired
    public void setCityPlatformService(CityPlatformService cityPlatformService) {
        this.cityPlatformService = cityPlatformService;
    }
 
    @Autowired
    public void setViolationsService(IViolationsService violationsService) {
        this.violationsService = violationsService;
    }
 
    @Autowired
    public void setVideoAlarmReportService(IVideoAlarmReportService videoAlarmReportService) {
        this.videoAlarmReportService = videoAlarmReportService;
    }
 
    @Resource
    BaseCaseMapper baseCaseMapper;
    @Resource
    DataDictionaryMapper dataDictionaryMapper;
    @Resource
    ViolationsMapper violationsMapper;
    @Resource
    IllegalBuildingMapper illegalBuildingMapper;
 
    @Override
    public String uploadEvent(Integer caseId) {
        BaseCase baseCase = this.getById(caseId);
        Violations violations = violationsService.getById(caseId);
        String medias = "";
        String eventDesc = "";
        if (violations != null) {
            eventDesc = violations.getDescription();
            VideoAlarmReport videoAlarmReport = videoAlarmReportService.getById(violations.getVideoAlarmReportId());
            if (videoAlarmReport != null) {
                StringBuilder stringBuilder = new StringBuilder().append("[{'mediaURL':'").append(fileUrl).append(videoAlarmReport.getPicData()).append("'}]");
                medias = stringBuilder.toString();
            }
        }
        EventAddParamDto dto = EventAddParamDto.builder().y84(baseCase.getLatitude() != null ? baseCase.getLatitude().toString() : "")
                .x84(baseCase.getLongitude() != null ? baseCase.getLongitude().toString() : "")
                .source(11).address(baseCase.getSite()).eventDesc(eventDesc).eventSign(baseCase.getCode()).medias(medias).build();
        String msg = cityPlatformService.addEvent(dto);
        ResultResponseDto result = JSONObject.parseObject(msg, ResultResponseDto.class);
        if (result.getCode() == 0) {
            EventAddResponseDto responseDto = JSONObject.parseObject(result.getResult(), EventAddResponseDto.class);
            baseCase.setTaskCode(responseDto.getTaskcode());
            this.updateById(baseCase);
            return null;
        } else {
            return result.getMsg();
        }
    }
 
    @Override
    public String processEvent(Integer caseId) {
        BaseCase baseCase = this.getById(caseId);
        EventProcessParamDto paramDto = EventProcessParamDto.builder().eventSign(baseCase.getCode()).taskcode(baseCase.getTaskCode()).build();
        String msg = cityPlatformService.getEventProcess(paramDto);
        ResultResponseDto responseDto = JSONObject.parseObject(msg, ResultResponseDto.class);
        if (responseDto.getCode() == 0) {
            EventProcessResponseDto eventProcessResponseDto = JSONObject.parseObject(responseDto.getResult(), EventProcessResponseDto.class);
            /*********** 未处理市平台返回数据 ***************/
            return null;
        } else {
            return responseDto.getMsg();
        }
    }
 
    @Override
    public Page listViolationsPage(Page page, Integer state, Integer resource) {
        Integer type = 01;
        Page<CasePoolViolationDO> violationsPage = baseCaseMapper.listViolationsPage(page, state, type, resource);
        List<CasePoolViolationVO> violationVOList = violationsPage.getRecords().stream().map(item -> {
            CasePoolViolationVO casePoolViolationVO = new CasePoolViolationVO();
            BeanUtils.copyProperties(item, casePoolViolationVO);
            if (item.getCloseTime() == null) {
                long nowTime = System.currentTimeMillis();
                long alarmTime = item.getAlarmTime().toEpochSecond(ZoneOffset.ofHours(8));
                LocalDateTime continueTimes = Instant.ofEpochMilli(nowTime - alarmTime).atZone(ZoneOffset.ofHours(8)).toLocalDateTime();
                String continueTime = continueTimes.getHour() + "时" + continueTimes.getSecond() + "分钟";
                casePoolViolationVO.setContinueTime(continueTime);
            } else {
                long closeTime = item.getCloseTime().toEpochSecond(ZoneOffset.ofHours(8));
                long alarmTime = item.getAlarmTime().toEpochSecond(ZoneOffset.ofHours(8));
                LocalDateTime continueTimes = Instant.ofEpochMilli(closeTime - alarmTime).atZone(ZoneOffset.ofHours(8)).toLocalDateTime();
                String continueTime = continueTimes.getHour() + "时" + continueTimes.getSecond() + "分钟";
                casePoolViolationVO.setContinueTime(continueTime);
            }
            casePoolViolationVO.setCategory(dataDictionaryMapper.selectById(item.getCategoryId()).getName());
            casePoolViolationVO.setType(dataDictionaryMapper.selectById(item.getTypeId()).getName());
            return casePoolViolationVO;
        }).collect(Collectors.toList());
        Page<CasePoolViolationVO> casePoolViolationVOPage = new Page<>();
        BeanUtils.copyProperties(violationsPage, casePoolViolationVOPage);
        casePoolViolationVOPage.setRecords(violationVOList);
        return casePoolViolationVOPage;
    }
 
    @Override
    public Page listIllegalBuilding(Page page, Integer state, Integer resource) {
        Integer type = 02;
        Page<CasePoolIllegalBuildingDO> casePoolIllegalBuildingDTOPage = baseCaseMapper.listIllegalBuildingsPage(page, state, type, resource);
        List<CasePoolIllegalBuildingVO> casePoolIllegalBuildingVOList = casePoolIllegalBuildingDTOPage
                .getRecords()
                .stream()
                .map(
                        item -> {
                            CasePoolIllegalBuildingVO casePoolIllegalBuildingVO = new CasePoolIllegalBuildingVO();
                            BeanUtils.copyProperties(item, casePoolIllegalBuildingVO);
                            casePoolIllegalBuildingVO.setCategory(dataDictionaryMapper.selectById(item.getCategoryId()).getName());
                            return casePoolIllegalBuildingVO;
                        }
                ).collect(Collectors.toList());
        Page<CasePoolIllegalBuildingVO> casePoolViolationVOPage = new Page<>();
        BeanUtils.copyProperties(casePoolIllegalBuildingDTOPage, casePoolViolationVOPage);
        casePoolViolationVOPage.setRecords(casePoolIllegalBuildingVOList);
        return casePoolViolationVOPage;
    }
 
    @Override
    public Boolean saveViolationCase(ViolationParam violationParam, Integer id) {
        BaseCase baseCase = new BaseCase();
        Violations violations = new Violations();
        BeanUtils.copyProperties(violationParam, baseCase);
        BeanUtils.copyProperties(violationParam, violations);
        violations.setId(id);
        Integer value = 1;
        return violationsMapper.insert(violations) == value ? true : false;
    }
 
    @Override
    public Boolean saveIllegalBuildingCase(IllegalBuildingParam illegalBuildingParam, Integer id) {
        BaseCase baseCase = new BaseCase();
        IllegalBuilding illegalBuilding = new IllegalBuilding();
        BeanUtils.copyProperties(illegalBuilding, baseCase);
        BeanUtils.copyProperties(illegalBuilding, illegalBuildingParam);
        illegalBuilding.setBaseCaseId(id);
        Integer value = 1;
        return illegalBuildingMapper.insert(illegalBuilding) == value ? true : false;
    }
}