|
|
|
package com.zc.business.controller;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
|
import com.zc.business.domain.DcEventProcess;
|
|
|
|
import com.zc.business.domain.DcWarning;
|
|
|
|
import com.zc.business.enums.UniversalEnum;
|
|
|
|
import com.zc.business.mapper.DcEventProcessMapper;
|
|
|
|
import com.zc.business.service.IDcWarningService;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.text.ParseException;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* License
|
|
|
|
*
|
|
|
|
* @author Athena-zhaoxianglong
|
|
|
|
*/
|
|
|
|
@Api(tags = "扫码报警")
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("/codeScanningAlarm")
|
|
|
|
public class CodeScanningAlarmController extends BaseController {
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
private IDcWarningService dcWarningService;
|
|
|
|
@Resource
|
|
|
|
private DcEventProcessMapper dcEventProcessMapper;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 扫码报警事件回调函数
|
|
|
|
*
|
|
|
|
* @param returnParameters 事件回参
|
|
|
|
* @return 结果
|
|
|
|
*/
|
|
|
|
@PostMapping(value = "/event")
|
|
|
|
public AjaxResult codeScanningAlarmControllerEvent(@RequestBody Map<String, Object> returnParameters) {
|
|
|
|
String id = String.valueOf(returnParameters.get("id"));
|
|
|
|
DcWarning dcWarning = new DcWarning();
|
|
|
|
dcWarning.setId(id);
|
|
|
|
dcWarning.setOtherConfig(String.valueOf(JSONObject.parseObject(JSONObject.toJSONString(returnParameters))));
|
|
|
|
|
|
|
|
HashMap<String, Object> oldData = dcWarningService.selectAlarmById(id);
|
|
|
|
if (oldData == null) {
|
|
|
|
dcWarning.setStakeMark(String.valueOf(returnParameters.get("stakeNum")));
|
|
|
|
String roadCode = String.valueOf(returnParameters.get("roadCode"));
|
|
|
|
dcWarning.setDirection(Objects.equals(roadCode, UniversalEnum.ONE.getValue()) ? UniversalEnum.THREE.getValue() : UniversalEnum.ONE.getValue());
|
|
|
|
String createTime = String.valueOf(returnParameters.get("createTime"));
|
|
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mmXXX");
|
|
|
|
try {
|
|
|
|
dcWarning.setWarningTime(format.parse(createTime));
|
|
|
|
} catch (ParseException e) {
|
|
|
|
dcWarning.setWarningTime(new Date());
|
|
|
|
}
|
|
|
|
dcWarning.setCreateTime(new Date());
|
|
|
|
String accidentType = String.valueOf(returnParameters.get("accidentType"));
|
|
|
|
switch (accidentType) {
|
|
|
|
case "1"://车辆炸胎(无备胎)
|
|
|
|
dcWarning.setWarningType(UniversalEnum.ELEVEN.getNumber());
|
|
|
|
dcWarning.setWarningSubclass(UniversalEnum.ELEVEN_THREE.getValue());
|
|
|
|
break;
|
|
|
|
case "2"://车辆炸胎(有备胎)
|
|
|
|
dcWarning.setWarningType(UniversalEnum.ELEVEN.getNumber());
|
|
|
|
dcWarning.setWarningSubclass(UniversalEnum.ELEVEN_TWO.getValue());
|
|
|
|
break;
|
|
|
|
case "3"://车辆抛锚
|
|
|
|
dcWarning.setWarningType(UniversalEnum.ELEVEN.getNumber());
|
|
|
|
dcWarning.setWarningSubclass(UniversalEnum.ELEVEN_ONE.getValue());
|
|
|
|
break;
|
|
|
|
case "4"://单车事故
|
|
|
|
dcWarning.setWarningType(UniversalEnum.TEN.getNumber());
|
|
|
|
dcWarning.setWarningSubclass(UniversalEnum.TEN_TWO.getValue());
|
|
|
|
break;
|
|
|
|
case "5"://多车事故
|
|
|
|
dcWarning.setWarningType(UniversalEnum.TEN.getNumber());
|
|
|
|
dcWarning.setWarningSubclass(UniversalEnum.TEN_THREE.getValue());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(UniversalEnum.CHINESE_CHARACTER_TIME_FORMAT.getValue());
|
|
|
|
|
|
|
|
String warningTitle = dcWarning.getStakeMark() + UniversalEnum.BLANK_SPACE.getValue() + (Objects.equals(roadCode, UniversalEnum.ONE.getValue()) ? UniversalEnum.DIRECTION_OF_JINAN.getValue() : UniversalEnum.DIRECTION_OF_HEZE.getValue()) + UniversalEnum.BLANK_SPACE.getValue() + "发生" + (Integer.parseInt(accidentType) >= 4 ? UniversalEnum.TRAFFIC_ACCIDENT_EVENT.getValue() : UniversalEnum.VEHICLE_BREAKDOWN_EVENT.getValue());
|
|
|
|
dcWarning.setWarningTitle(warningTitle);
|
|
|
|
dcWarning.setRemark(simpleDateFormat.format(dcWarning.getWarningTime()) + warningTitle);
|
|
|
|
dcWarning.setWarningSource(UniversalEnum.FIVE.getNumber());
|
|
|
|
dcWarning.setWarningState(UniversalEnum.ONE.getNumber());
|
|
|
|
return AjaxResult.success(dcWarningService.insertDcWarning(dcWarning));
|
|
|
|
} else {
|
|
|
|
dcWarning.setId(oldData.get("id").toString());
|
|
|
|
|
|
|
|
return AjaxResult.success(dcWarningService.updateDcWarning(dcWarning));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@PostMapping(value = "/updateAlarm")
|
|
|
|
public AjaxResult updateAlarm(@RequestBody Map<String, Object> params) {
|
|
|
|
if (!params.containsKey("id") || !params.containsKey("type") || !params.containsKey("url")){
|
|
|
|
return AjaxResult.error("参数错误");
|
|
|
|
}
|
|
|
|
String id = String.valueOf(params.get("id"));
|
|
|
|
String type = String.valueOf(params.get("type"));
|
|
|
|
String url = String.valueOf(params.get("url"));
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(id) || StringUtils.isEmpty(type) || StringUtils.isEmpty(url)){
|
|
|
|
return AjaxResult.error("参数错误");
|
|
|
|
}
|
|
|
|
|
|
|
|
HashMap<String, Object> oldData = dcWarningService.selectAlarmById(id);
|
|
|
|
if (oldData == null){
|
|
|
|
return AjaxResult.error("无此事件");
|
|
|
|
}
|
|
|
|
JSONObject otherConfig = JSONObject.parseObject(oldData.get("otherConfig").toString());
|
|
|
|
if (type.equals("video")){
|
|
|
|
JSONArray videoUrl = new JSONArray();
|
|
|
|
if (otherConfig.containsKey("videoUrl")){
|
|
|
|
videoUrl = otherConfig.getJSONArray("videoUrl");
|
|
|
|
}
|
|
|
|
videoUrl.add(url);
|
|
|
|
otherConfig.put("videoUrl",videoUrl);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
JSONArray imgUrl = new JSONArray();
|
|
|
|
if (otherConfig.containsKey("imgUrl")){
|
|
|
|
imgUrl = otherConfig.getJSONArray("imgUrl");
|
|
|
|
}
|
|
|
|
imgUrl.add(url);
|
|
|
|
otherConfig.put("imgUrl",imgUrl);
|
|
|
|
}
|
|
|
|
DcWarning dcWarning = new DcWarning();
|
|
|
|
dcWarning.setId(oldData.get("id").toString());
|
|
|
|
dcWarning.setOtherConfig(String.valueOf(JSONObject.parseObject(JSONObject.toJSONString(otherConfig))));
|
|
|
|
dcWarningService.updateDcWarning(dcWarning);
|
|
|
|
|
|
|
|
DcEventProcess dcEventProcess = new DcEventProcess();
|
|
|
|
dcEventProcess.setEventId(oldData.get("id").toString());
|
|
|
|
dcEventProcess.setSource(2);
|
|
|
|
if (type.equals("video")){
|
|
|
|
dcEventProcess.setType("mp4");
|
|
|
|
} else {
|
|
|
|
dcEventProcess.setType("png");
|
|
|
|
}
|
|
|
|
dcEventProcess.setContext(url);
|
|
|
|
dcEventProcess.setOperatorName("上报人");
|
|
|
|
dcEventProcess.setOperationTime(new Date());
|
|
|
|
dcEventProcessMapper.insertDcEventProcess(dcEventProcess);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return AjaxResult.success("添加成功");
|
|
|
|
}
|
|
|
|
}
|