Commit 674eb84e authored by suhuiguang's avatar suhuiguang

refeat(96333): 警情报送

1.警情重复问题处理,,一个工单号有多个警情,数据一样,增加校验,数据库已有数据时不再插入而是更新
parent f4b258a3
......@@ -57,6 +57,7 @@ import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
......@@ -162,20 +163,18 @@ public class AlertCalledController extends BaseController {
jsonObject.put("alertId",String.valueOf(alertCalledObjsDto.getAlertCalledDto().getSequenceNbr()));
JSONObject jsonObject1 = new JSONObject();
jsonObject.put("alertId",String.valueOf(alertCalledObjsDto.getAlertCalledDto().getSequenceNbr()));
jsonObject1.put("alertId",String.valueOf(alertCalledObjsDto.getAlertCalledDto().getSequenceNbr()));
try {
emqKeeper.getMqttClient().publish(alertReportpushTopic, jsonObject.toString().getBytes("UTF-8"), 1, false);
emqKeeper.getMqttClient().publish(alertReportpushTopic, jsonObject.toString().getBytes(StandardCharsets.UTF_8), 1, false);
// 跑马灯消息提醒
if(null != alertCalledObjsDto.getAlertCalledDto().getFatherAlert()) {
emqKeeper.getMqttClient().publish(alertInfopushTopic, jsonObject1.toString().getBytes("UTF-8"), 1, false);
emqKeeper.getMqttClient().publish(alertInfopushTopic, jsonObject1.toString().getBytes(StandardCharsets.UTF_8), 1, false);
}
} catch (MqttException e) {
logger.error("mqtt发送失败" +jsonObject );
} catch (UnsupportedEncodingException e) {
logger.error("mqtt发送失败" +jsonObject );
logger.error("mqtt发送失败:{}", jsonObject );
}
return ResponseHelper.buildResponse(alertCalledObjsDto.getAlertCalledDto());
return ResponseHelper.buildResponse(alertCalledObjsDto.getAlertCalledDto());
}
private void saveAlertCallRecord(AlertCalledObjsDto alertCalledObjsDto) {
......
......@@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.core.toolkit.SystemClock;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Maps;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.boot.biz.common.entity.BaseEntity;
import com.yeejoin.amos.boot.biz.common.service.impl.DataDictionaryServiceImpl;
import com.yeejoin.amos.boot.biz.common.utils.DateUtils;
import com.yeejoin.amos.boot.biz.common.utils.RedisKey;
......@@ -57,6 +58,7 @@ import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import static com.alibaba.fastjson.JSON.parseArray;
......@@ -155,6 +157,9 @@ public class AlertCalledServiceImpl extends BaseService<AlertCalledDto,AlertCall
@Value("classpath:/json/repairFollow.json")
private Resource repairFollowJson;
@Value("${global-config.worker-id:1}")
private int workId;
public AlertCalledServiceImpl(RedissonClient client){
this.redissonClient = client;
......@@ -567,11 +572,16 @@ public class AlertCalledServiceImpl extends BaseService<AlertCalledDto,AlertCall
AlertCalled alertCalled = BeanDtoVoUtils.convert(alertCalledObjsDto.getAlertCalledDto(),AlertCalled.class);
alertCalled.setEquipmentClassification(alertCalledObjsDto.getAlertCalledDto().getEquipment());
Map<String, String> getCode = EquipmentClassifityEnum.getCode;
String code= getCode.get(alertCalledObjsDto.getAlertCalledDto().getEquipment().toString());
String code= getCode.get(alertCalledObjsDto.getAlertCalledDto().getEquipment());
alertCalled.setEquipmentClassificationCode(code);
alertCalled.setCallTime(DateUtils.longStr2Date(alertCalled.getCallTimeStr()));
String groupCode = ctiService.getSkillGroup(user.getUserId());
alertCalled.setSkillGroup(groupCode);
// 重复填报使用覆盖原有最新(按照主键倒叙排列)且非删除状态的警情,工单号唯一,正常不会出现一个工单号有两条数据
AlertCalled existAlertCalled = this.getOne(new LambdaQueryWrapper<AlertCalled>().eq(AlertCalled::getWorkOrderNumber, alertCalled.getWorkOrderNumber()).eq(BaseEntity::getIsDelete, false).orderByDesc(AlertCalled::getSequenceNbr).last("limit 1"));
if(existAlertCalled != null){
alertCalled.setSequenceNbr(existAlertCalled.getSequenceNbr());
}
// 判断是否归并警情
if (alertCalled.getFatherAlert() != null) {
// 警情归并,设置当前警情状态为结束。
......@@ -580,17 +590,16 @@ public class AlertCalledServiceImpl extends BaseService<AlertCalledDto,AlertCall
alertCalled.setAlertStageCode(DispatchPaperEnums.receivedAlert.getId());
alertCalled.setType(AlertStageEnums.JQGB.getValue());
alertCalled.setTypeCode(AlertStageEnums.JQGB.getId());
this.save(alertCalled);
this.saveOrUpdate(alertCalled);
// 动态表单
List<AlertFormValue> alertFormValuelist = alertCalledObjsDto.getAlertFormValue();
// 填充警情主键
alertFormValuelist.stream().forEach(alertFormValue -> {
alertFormValuelist.forEach(alertFormValue -> {
alertFormValue.setAlertCalledId(alertCalled.getSequenceNbr());
alertFormValue.setAlertTypeCode(alertCalled.getAlarmTypeCode());
});
// 保存动态表单数据
iAlertFormValueService.saveBatch(alertFormValuelist);
// 返回父警情基本信息和自身alertID
AlertCalled alertCalledFather = this.getById(alertCalled.getFatherAlert());
AlertCalledDto alertCalledDto = BeanDtoVoUtils.convert(alertCalledFather, AlertCalledDto.class);
......@@ -615,14 +624,11 @@ public class AlertCalledServiceImpl extends BaseService<AlertCalledDto,AlertCall
alertCalled.setRegionCode(map.get("regionCode").toString());
alertCalled.setBizOrgCode(map.get("orgCode") + "");
}
this.save(alertCalled);
this.saveOrUpdate(alertCalled);
// 动态表单
List<AlertFormValue> alertFormValuelist = alertCalledObjsDto.getAlertFormValue();
// 填充警情主键
alertFormValuelist.stream().forEach(alertFormValue -> {
alertFormValuelist.forEach(alertFormValue -> {
alertFormValue.setAlertCalledId(alertCalled.getSequenceNbr());
alertFormValue.setAlertTypeCode(alertCalled.getAlarmTypeCode());
});
......@@ -630,7 +636,6 @@ public class AlertCalledServiceImpl extends BaseService<AlertCalledDto,AlertCall
//困人救援创建警情时创建救援过程信息
rescueProcessServiceImpl.getProcessByAlertId(alertCalled.getSequenceNbr());
}
// 保存动态表单数据
iAlertFormValueService.saveBatch(alertFormValuelist);
alertCalledObjsDto.setAlertCalledDto(BeanDtoVoUtils.convert(alertCalled,AlertCalledDto.class));
......@@ -640,7 +645,6 @@ public class AlertCalledServiceImpl extends BaseService<AlertCalledDto,AlertCall
//同步保存ES
eSAlertCalledService.saveAlertCalledToES(alertCalled);
}
return alertCalledObjsDto;
} catch (Exception e) {
logger.error("报送失败",e);
......@@ -853,9 +857,11 @@ public class AlertCalledServiceImpl extends BaseService<AlertCalledDto,AlertCall
if (remainTimeToLive <= 0) {
resetCounterAndExpire();
}
long seq = rAtomicLong.incrementAndGet();
long seq = rAtomicLong.addAndGetAsync(1).get();
String number = DateUtils.stampToDate(SystemClock.now(), "yyyyMMddHHmmss");
workOrderNumber = number + seq;
workOrderNumber = number + workId + seq;
} catch (ExecutionException | InterruptedException e) {
throw new RuntimeException(e);
} finally {
if (lock.isHeldByCurrentThread()) {
lock.unlock();
......@@ -948,7 +954,7 @@ public class AlertCalledServiceImpl extends BaseService<AlertCalledDto,AlertCall
private long calculateExpirationTime() {
LocalDateTime now = LocalDateTime.now();
LocalDateTime nextDay = now.plus(1, ChronoUnit.DAYS).withHour(0).withMinute(0).withSecond(0).withNano(0);
LocalDateTime nextDay = now.plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
return nextDay.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
}
......
......@@ -162,4 +162,6 @@ tzs.auth.user.photo=/public/common/userPic.png
tzs.WxApp.appId=wx48a1b1915b10d14b
tzs.WxApp.secret=ac4f4a9d3c97676badb70c19a2f37b16
tzs.WxApp.grant-type=authorization_code
\ No newline at end of file
tzs.WxApp.grant-type=authorization_code
global-config.worker-id=2
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment