济菏高速数据中心代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
4.8 KiB

package com.zc.business.controller;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.zc.business.domain.DcWarning;
import com.zc.business.enums.UniversalEnum;
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;
/**
* 扫码报警事件回调函数
*
* @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));
}
}
}