Browse Source

策略自动结束,人员分配类型

develop
wangsixiang 8 months ago
parent
commit
c5e01958fc
  1. 5
      zc-business/src/main/java/com/zc/business/controller/DcWarningController.java
  2. 22
      zc-business/src/main/java/com/zc/business/domain/DcEmployees.java
  3. 2
      zc-business/src/main/java/com/zc/business/domain/DcWarning.java
  4. 8
      zc-business/src/main/java/com/zc/business/mapper/DcWarningMapper.java
  5. 3
      zc-business/src/main/java/com/zc/business/service/IDcWarningService.java
  6. 355
      zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java
  7. 13
      zc-business/src/main/resources/mapper/business/DcEmployeesMapper.xml
  8. 16
      zc-business/src/main/resources/mapper/business/DcWarningMapper.xml

5
zc-business/src/main/java/com/zc/business/controller/DcWarningController.java

@ -136,4 +136,9 @@ public class DcWarningController extends BaseController
return dcWarningService.batchConvert(dcWarningBatchConvert); return dcWarningService.batchConvert(dcWarningBatchConvert);
} }
//定时任务,定时结束部分事件
@PostMapping("/endSection")
public AjaxResult updateEndSection(){
return toAjax(dcWarningService.updateEndSection());
}
} }

22
zc-business/src/main/java/com/zc/business/domain/DcEmployees.java

@ -49,6 +49,27 @@ public class DcEmployees extends BaseEntity
private String organizationName; private String organizationName;
private Long parentId; private Long parentId;
//人员类型1为路管人员2为应急人员
@Excel(name = "人员类型 1-路管人员 2-应急人员")
private Long employeesType;
//类型参数
private String type;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Long getEmployeesType() {
return employeesType;
}
public void setEmployeesType(Long employeesType) {
this.employeesType = employeesType;
}
public Long getParentId() { public Long getParentId() {
return parentId; return parentId;
@ -130,6 +151,7 @@ public class DcEmployees extends BaseEntity
.append("contactNumber", getContactNumber()) .append("contactNumber", getContactNumber())
.append("createTime", getCreateTime()) .append("createTime", getCreateTime())
.append("updateTime", getUpdateTime()) .append("updateTime", getUpdateTime())
.append("employeesType", getEmployeesType())
.toString(); .toString();
} }
} }

2
zc-business/src/main/java/com/zc/business/domain/DcWarning.java

@ -98,7 +98,7 @@ public class DcWarning extends BaseEntity
//事件原因 //事件原因
private String eventCause; private String eventCause;
//完结时间 //完结时间
@JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
private Date endTime; private Date endTime;
//操作员 //操作员
private String userName; private String userName;

8
zc-business/src/main/java/com/zc/business/mapper/DcWarningMapper.java

@ -1,5 +1,6 @@
package com.zc.business.mapper; package com.zc.business.mapper;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -83,5 +84,10 @@ public interface DcWarningMapper
public List<DcWaringStrategy> selectDcWaringStrategyList(@Param("warningSource")String warningSource,@Param public List<DcWaringStrategy> selectDcWaringStrategyList(@Param("warningSource")String warningSource,@Param
("warningType")String warningType,@Param("warningSubclass")String warningSubclass,@Param("strategy")Integer strategy); ("warningType")String warningType,@Param("warningSubclass")String warningSubclass,@Param("strategy")Integer strategy);
//修改配置 //修改配置
public Integer updateOtherConfig(@Param("id")String id,@Param("otherConfig")String otherConfig); public Integer updateOtherConfig(@Param("id")String id,@Param("otherConfig")String otherConfig,@Param("endTime") Date endTime );
//定时结束部分事件
public Integer updateEndSection(@Param("dcWarningList") List<DcWarning> dcWarningList);
//查询当天全部可以结束的事件
public List<DcWarning> selectEndSection();
} }

3
zc-business/src/main/java/com/zc/business/service/IDcWarningService.java

@ -6,6 +6,7 @@ import java.util.List;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.zc.business.domain.DcWarning; import com.zc.business.domain.DcWarning;
import com.zc.business.domain.DcWarningBatchConvert; import com.zc.business.domain.DcWarningBatchConvert;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
/** /**
@ -81,4 +82,6 @@ public interface IDcWarningService
*/ */
AjaxResult batchConvert(DcWarningBatchConvert dcWarningBatchConvert); AjaxResult batchConvert(DcWarningBatchConvert dcWarningBatchConvert);
//定时结束部分事件
Integer updateEndSection();
} }

355
zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java

@ -120,7 +120,8 @@ public class DcWarningServiceImpl implements IDcWarningService
HashMap redisValueTwo = redisWarningStrategy.get(redisKye+"2");//查看传入的事件类型是否配置策略2(延迟策略) HashMap redisValueTwo = redisWarningStrategy.get(redisKye+"2");//查看传入的事件类型是否配置策略2(延迟策略)
if (redisValueTwo!=null){ //执行策略2, if (redisValueTwo!=null){ //执行策略2,
String strategyTime = redisValueTwo.get("strategyTime").toString();//策略时长 String strategyTime = redisValueTwo.get("strategyTime").toString();//策略时长
if (dataId==null){//如果不存在直接加入数据库,加入缓存,配置对应的过期时间 dcWarning.setEndTime(DateUtils.getObtainDateAfter(Integer.parseInt(strategyTime)));//注入过期时间
if (dataId==null){//如果不存在直接加入数据库,加入缓存,配置对应的缓存过期时间以及数据库过期时间
int insertDcWarning = dcWarningMapper.insertDcWarning(dcWarning);//加入数据库 int insertDcWarning = dcWarningMapper.insertDcWarning(dcWarning);//加入数据库
if (insertDcWarning==0){ if (insertDcWarning==0){
return 0; return 0;
@ -131,7 +132,7 @@ public class DcWarningServiceImpl implements IDcWarningService
} }
//redis存在数据,取出redis的id找对对应事件的配置,合成事件配置,重新定义延迟时间 //redis存在数据,取出redis的id找对对应事件的配置,合成事件配置,重新定义延迟时间
HashMap<String, Object> map = dcWarningMapper.selectDcWarningById(dataId); HashMap<String, Object> map = dcWarningMapper.selectDcWarningById(dataId);
if (map==null||(map.get("warningState")!=null&&!map.get("warningState").toString().equals("1"))){//redis中有id但是数据库中没有这条数据,或则数据库中有数据但是状态不为上报,那就删除这条redis数据,新数据加入到数据库,并加入到redis if (map==null||(map.get("warningState")!=null&&map.get("warningState").toString().equals("4"))){//redis中有id但是数据库中没有这条数据,或则数据库中有数据但是状态不为结束,那就删除这条redis数据,新数据加入到数据库,并加入到redis
redisCache.deleteObject(WARNINGDATA+key); redisCache.deleteObject(WARNINGDATA+key);
String id = dcWarning.getId(); String id = dcWarning.getId();
redisCache.setCacheObject(WARNINGDATA+key,id,Integer.parseInt(strategyTime),TimeUnit.MINUTES); redisCache.setCacheObject(WARNINGDATA+key,id,Integer.parseInt(strategyTime),TimeUnit.MINUTES);
@ -156,185 +157,185 @@ public class DcWarningServiceImpl implements IDcWarningService
jsonObjectOne.put("videoList",videoList); jsonObjectOne.put("videoList",videoList);
} }
redisCache.setCacheObject(WARNINGDATA+key,dataId,Integer.parseInt(strategyTime),TimeUnit.MINUTES);//重新设置延迟时间 redisCache.setCacheObject(WARNINGDATA+key,dataId,Integer.parseInt(strategyTime),TimeUnit.MINUTES);//重新设置延迟时间
return dcWarningMapper.updateOtherConfig(dataId,jsonObjectOne.toString());//修改数据库配置 return dcWarningMapper.updateOtherConfig(dataId,jsonObjectOne.toString(),dcWarning.getEndTime());//修改数据库配置
} }
DcWarningServiceImpl dcWarningService = new DcWarningServiceImpl();//合成工具类 DcWarningServiceImpl dcWarningService = new DcWarningServiceImpl();//合成工具类
JSONObject jsonObject = dcWarningService.mergeJsonObjects(jsonObjectOne, jsonObjectTwo); JSONObject jsonObject = dcWarningService.mergeJsonObjects(jsonObjectOne, jsonObjectTwo);
redisCache.setCacheObject(WARNINGDATA+key,dataId,Integer.parseInt(strategyTime),TimeUnit.MINUTES);//重新设置延迟时间 redisCache.setCacheObject(WARNINGDATA+key,dataId,Integer.parseInt(strategyTime),TimeUnit.MINUTES);//重新设置延迟时间
return dcWarningMapper.updateOtherConfig(dataId, jsonObject.toString());//修改数据库配置 return dcWarningMapper.updateOtherConfig(dataId, jsonObject.toString(),dcWarning.getEndTime());//修改数据库配置
} }
return dcWarningMapper.insertDcWarning(dcWarning);//如果没有配置策略直接加入数据库; return dcWarningMapper.insertDcWarning(dcWarning);//如果没有配置策略直接加入数据库;
} }
//优先级策略(还差优先级策略需要配置) //优先级策略(还差优先级策略需要配置)
public int priority(DcWarning dcWarning){ // public int priority(DcWarning dcWarning){
dcWarning.setCreateTime(DateUtils.getNowDate()); // dcWarning.setCreateTime(DateUtils.getNowDate());
//设置事件Id UUID无下划线格式32 // //设置事件Id UUID无下划线格式32
String uuid = IdUtils.fastSimpleUUID(); // String uuid = IdUtils.fastSimpleUUID();
dcWarning.setId(uuid); // dcWarning.setId(uuid);
if (StringUtils.isBlank(dcWarning.getStakeMark())||dcWarning.getWarningSource()==null||dcWarning.getWarningType()==null|| // if (StringUtils.isBlank(dcWarning.getStakeMark())||dcWarning.getWarningSource()==null||dcWarning.getWarningType()==null||
StringUtils.isBlank(dcWarning.getWarningSubclass())||StringUtils.isBlank(dcWarning.getDirection())){ // StringUtils.isBlank(dcWarning.getWarningSubclass())||StringUtils.isBlank(dcWarning.getDirection())){
return 0; // return 0;
} // }
String redisKye=dcWarning.getWarningSource().toString()+dcWarning.getWarningType().toString()+dcWarning.getWarningSubclass();//配置数据的key 事件源+事件类型+策略 // String redisKye=dcWarning.getWarningSource().toString()+dcWarning.getWarningType().toString()+dcWarning.getWarningSubclass();//配置数据的key 事件源+事件类型+策略
Map<String, HashMap> redisWarningStrategy = redisCache.getCacheMap(WARNINGSTRATEGY);//获取缓存全部的配置数据 // Map<String, HashMap> redisWarningStrategy = redisCache.getCacheMap(WARNINGSTRATEGY);//获取缓存全部的配置数据
if (redisWarningStrategy==null||redisWarningStrategy.size()==0){//如果缓存为空,查询数据重新加入缓存 // if (redisWarningStrategy==null||redisWarningStrategy.size()==0){//如果缓存为空,查询数据重新加入缓存
Map<String, JSONObject> redisMap = new HashMap<>(); // Map<String, JSONObject> redisMap = new HashMap<>();
List<DcWaringStrategy> dcWaringStrategies = dcWarningMapper.selectDcWaringStrategyList();//数据库全部配置数据 // List<DcWaringStrategy> dcWaringStrategies = dcWarningMapper.selectDcWaringStrategyList();//数据库全部配置数据
for (DcWaringStrategy waringStrategy : dcWaringStrategies) { // for (DcWaringStrategy waringStrategy : dcWaringStrategies) {
String key = waringStrategy.getWarningSource().toString() + waringStrategy.getWarningType().toString() // String key = waringStrategy.getWarningSource().toString() + waringStrategy.getWarningType().toString()
+ waringStrategy.getWarningSubclass()+waringStrategy.getStrategy().toString();//redis配置数据key // + waringStrategy.getWarningSubclass()+waringStrategy.getStrategy().toString();//redis配置数据key
JSONObject jsonObject = new JSONObject(); // JSONObject jsonObject = new JSONObject();
jsonObject.put("strategy", waringStrategy.getStrategy());//策略模式 // jsonObject.put("strategy", waringStrategy.getStrategy());//策略模式
jsonObject.put("strategyTime", waringStrategy.getStrategyTime());//模式时长,单位为分钟 // jsonObject.put("strategyTime", waringStrategy.getStrategyTime());//模式时长,单位为分钟
jsonObject.put("priority", waringStrategy.getPriority());//优先级 // jsonObject.put("priority", waringStrategy.getPriority());//优先级
redisMap.put(key, jsonObject); // redisMap.put(key, jsonObject);
} // }
redisCache.setCacheMap(WARNINGSTRATEGY, redisMap);//数据库配置数据加入缓存中 // redisCache.setCacheMap(WARNINGSTRATEGY, redisMap);//数据库配置数据加入缓存中
redisWarningStrategy = redisCache.getCacheMap(WARNINGSTRATEGY);//缓存数据为空重新加入到缓存在取出缓存的配置 // redisWarningStrategy = redisCache.getCacheMap(WARNINGSTRATEGY);//缓存数据为空重新加入到缓存在取出缓存的配置
} // }
String key=dcWarning.getStakeMark()+dcWarning.getDirection()+dcWarning.getWarningSource(). // String key=dcWarning.getStakeMark()+dcWarning.getDirection()+dcWarning.getWarningSource().
toString()+dcWarning.getWarningType().toString()+dcWarning.getWarningSubclass();//key,redis存储事件的key(桩号+方向+事件源+类型) // toString()+dcWarning.getWarningType().toString()+dcWarning.getWarningSubclass();//key,redis存储事件的key(桩号+方向+事件源+类型)
String dataId = redisCache.getCacheObject(WARNINGDATA + key);//查看redis是否存在数据(id的值) // String dataId = redisCache.getCacheObject(WARNINGDATA + key);//查看redis是否存在数据(id的值)
HashMap redisValueOne = redisWarningStrategy.get(redisKye+"1");//查看传入的事件类型是否配置策略1(优先级策略) // HashMap redisValueOne = redisWarningStrategy.get(redisKye+"1");//查看传入的事件类型是否配置策略1(优先级策略)
if(redisValueOne!=null){//执行策略1(暂时未定义,定义后开发) // if(redisValueOne!=null){//执行策略1(暂时未定义,定义后开发)
String priority = redisValueOne.get("priority").toString();//全部的优先等级 // String priority = redisValueOne.get("priority").toString();//全部的优先等级
String[] split = priority.split(","); // String[] split = priority.split(",");
for (int i = 0; i < split.length; i++){ // for (int i = 0; i < split.length; i++){
String priorityValue=split[i];//取出当前循环的优先级类型 // String priorityValue=split[i];//取出当前循环的优先级类型
String keys=dcWarning.getStakeMark()+dcWarning.getDirection()+dcWarning.getWarningSource(). // String keys=dcWarning.getStakeMark()+dcWarning.getDirection()+dcWarning.getWarningSource().
toString()+dcWarning.getWarningType().toString()+priorityValue;//redis存储事件的key // toString()+dcWarning.getWarningType().toString()+priorityValue;//redis存储事件的key
String dataIds = redisCache.getCacheObject(WARNINGDATA + keys);//查看redis是否存在数据(id的值) // String dataIds = redisCache.getCacheObject(WARNINGDATA + keys);//查看redis是否存在数据(id的值)
if (dataIds==null){ //没有对应的优先级类型的id值,结束当前循环 // if (dataIds==null){ //没有对应的优先级类型的id值,结束当前循环
continue; // continue;
} // }
//redis存在数据,取出redis的id找对对应事件的配置,合成事件配置 // //redis存在数据,取出redis的id找对对应事件的配置,合成事件配置
HashMap<String, Object> map = dcWarningMapper.selectDcWarningById(dataId); // HashMap<String, Object> map = dcWarningMapper.selectDcWarningById(dataId);
if (map==null){//redis中有id但是数据库中没有这条数据,那就直接新增这个事件 // if (map==null){//redis中有id但是数据库中没有这条数据,那就直接新增这个事件
return dcWarningMapper.insertDcWarning(dcWarning); // return dcWarningMapper.insertDcWarning(dcWarning);
} // }
String warningState = map.get("warningState").toString();//事件上报状态 // String warningState = map.get("warningState").toString();//事件上报状态
if ("1".equals(warningState)==false){ //状态不为上报,不用合成事件,删除之前的redis数据 // if ("1".equals(warningState)==false){ //状态不为上报,不用合成事件,删除之前的redis数据
redisCache.deleteObject(WARNINGDATA+keys); // redisCache.deleteObject(WARNINGDATA+keys);
continue; // continue;
} // }
String otherConfig=""; // String otherConfig="";
if (map.get("otherConfig")!=null){ // if (map.get("otherConfig")!=null){
otherConfig = map.get("otherConfig").toString(); //取出原id的配置信息 // otherConfig = map.get("otherConfig").toString(); //取出原id的配置信息
} // }
String otherConfigString = dcWarning.getOtherConfig();//新增的配置信息 // String otherConfigString = dcWarning.getOtherConfig();//新增的配置信息
JSONObject jsonObjectOne = new JSONObject(otherConfig); // JSONObject jsonObjectOne = new JSONObject(otherConfig);
JSONObject jsonObjectTwo = new JSONObject(otherConfigString); // JSONObject jsonObjectTwo = new JSONObject(otherConfigString);
DcWarningServiceImpl dcWarningService = new DcWarningServiceImpl();//合成新的json // DcWarningServiceImpl dcWarningService = new DcWarningServiceImpl();//合成新的json
JSONObject jsonObject = dcWarningService.mergeJsonObjects(jsonObjectOne, jsonObjectTwo); // JSONObject jsonObject = dcWarningService.mergeJsonObjects(jsonObjectOne, jsonObjectTwo);
return dcWarningMapper.updateOtherConfig(dataId, jsonObject.toString());//修改数据库配置 // return dcWarningMapper.updateOtherConfig(dataId, jsonObject.toString());//修改数据库配置
} // }
} // }
HashMap redisValueTwo = redisWarningStrategy.get(redisKye+"2");//查看传入的事件类型是否配置策略2(延迟策略) // HashMap redisValueTwo = redisWarningStrategy.get(redisKye+"2");//查看传入的事件类型是否配置策略2(延迟策略)
if (redisValueTwo!=null){ //执行策略2,执行到这里说明1不存在或者1未满足过滤条件 // if (redisValueTwo!=null){ //执行策略2,执行到这里说明1不存在或者1未满足过滤条件
String strategyTime = redisValueTwo.get("strategyTime").toString();//策略时长 // String strategyTime = redisValueTwo.get("strategyTime").toString();//策略时长
if (dataId==null){//如果不存在直接加入数据库,加入缓存,配置对应的过期时间 // if (dataId==null){//如果不存在直接加入数据库,加入缓存,配置对应的过期时间
int insertDcWarning = dcWarningMapper.insertDcWarning(dcWarning);//加入数据库 // int insertDcWarning = dcWarningMapper.insertDcWarning(dcWarning);//加入数据库
if (insertDcWarning==0){ // if (insertDcWarning==0){
return 0; // return 0;
} // }
String id = dcWarning.getId();//取出加入后的id作为value // String id = dcWarning.getId();//取出加入后的id作为value
redisCache.setCacheObject(WARNINGDATA+key,id,Integer.parseInt(strategyTime),TimeUnit.MINUTES);//加入缓存并设置延迟时间(单位分钟) // redisCache.setCacheObject(WARNINGDATA+key,id,Integer.parseInt(strategyTime),TimeUnit.MINUTES);//加入缓存并设置延迟时间(单位分钟)
return 1;//结束 // return 1;//结束
} // }
//redis存在数据,取出redis的id找对对应事件的配置,合成事件配置,重新定义延迟时间 // //redis存在数据,取出redis的id找对对应事件的配置,合成事件配置,重新定义延迟时间
HashMap<String, Object> map = dcWarningMapper.selectDcWarningById(dataId); // HashMap<String, Object> map = dcWarningMapper.selectDcWarningById(dataId);
if (map==null){//redis中有id但是数据库中没有这条数据,那就删除这条redis数据,新数据加入到数据库,并加入到redis // if (map==null){//redis中有id但是数据库中没有这条数据,那就删除这条redis数据,新数据加入到数据库,并加入到redis
redisCache.deleteObject(WARNINGDATA+key); // redisCache.deleteObject(WARNINGDATA+key);
dcWarningMapper.insertDcWarning(dcWarning); // dcWarningMapper.insertDcWarning(dcWarning);
String id = dcWarning.getId(); // String id = dcWarning.getId();
redisCache.setCacheObject(WARNINGDATA+key,id,Integer.parseInt(strategyTime),TimeUnit.MINUTES); // redisCache.setCacheObject(WARNINGDATA+key,id,Integer.parseInt(strategyTime),TimeUnit.MINUTES);
return 1; // return 1;
} // }
String otherConfig=""; // String otherConfig="";
if (map.get("otherConfig")!=null){ // if (map.get("otherConfig")!=null){
otherConfig = map.get("otherConfig").toString(); //取出原id的配置信息 // otherConfig = map.get("otherConfig").toString(); //取出原id的配置信息
} // }
String otherConfigString = dcWarning.getOtherConfig();//新增的配置信息 // String otherConfigString = dcWarning.getOtherConfig();//新增的配置信息
JSONObject jsonObjectOne = new JSONObject(otherConfig); // JSONObject jsonObjectOne = new JSONObject(otherConfig);
JSONObject jsonObjectTwo = new JSONObject(otherConfigString); // JSONObject jsonObjectTwo = new JSONObject(otherConfigString);
DcWarningServiceImpl dcWarningService = new DcWarningServiceImpl();//合成新的json // DcWarningServiceImpl dcWarningService = new DcWarningServiceImpl();//合成新的json
JSONObject jsonObject = dcWarningService.mergeJsonObjects(jsonObjectOne, jsonObjectTwo); // JSONObject jsonObject = dcWarningService.mergeJsonObjects(jsonObjectOne, jsonObjectTwo);
Integer integer = dcWarningMapper.updateOtherConfig(dataId, jsonObject.toString());//修改数据库配置 // Integer integer = dcWarningMapper.updateOtherConfig(dataId, jsonObject.toString());//修改数据库配置
redisCache.setCacheObject(WARNINGDATA+key,dataId,Integer.parseInt(strategyTime),TimeUnit.MINUTES);//重新设置延迟时间 // redisCache.setCacheObject(WARNINGDATA+key,dataId,Integer.parseInt(strategyTime),TimeUnit.MINUTES);//重新设置延迟时间
if (integer==0){ // if (integer==0){
return 0; // return 0;
} // }
return 1; // return 1;
} // }
HashMap redisValueThree = redisWarningStrategy.get(redisKye+"3");//查看传入的事件类型是否配置策略3(时间窗口策略) // HashMap redisValueThree = redisWarningStrategy.get(redisKye+"3");//查看传入的事件类型是否配置策略3(时间窗口策略)
if (redisValueTwo==null&&redisValueThree!=null){ //执行策略3,执行到这里说明1不存在或者2不存在或者1未满足过滤条件 // if (redisValueTwo==null&&redisValueThree!=null){ //执行策略3,执行到这里说明1不存在或者2不存在或者1未满足过滤条件
String strategyTime = redisValueThree.get("strategyTime").toString();//策略时长 // String strategyTime = redisValueThree.get("strategyTime").toString();//策略时长
if (dataId==null){//如果不存在直接加入数据库,加入缓存,配置对应的过期时间 // if (dataId==null){//如果不存在直接加入数据库,加入缓存,配置对应的过期时间
int insertDcWarning = dcWarningMapper.insertDcWarning(dcWarning);//加入数据库 // int insertDcWarning = dcWarningMapper.insertDcWarning(dcWarning);//加入数据库
if (insertDcWarning==0){ // if (insertDcWarning==0){
return 0; // return 0;
} // }
String id = dcWarning.getId();//取出加入后的id作为value // String id = dcWarning.getId();//取出加入后的id作为value
redisCache.setCacheObject(WARNINGDATA+key,id,Integer.parseInt(strategyTime),TimeUnit.MINUTES);//加入缓存并设置延迟时间(单位分钟) // redisCache.setCacheObject(WARNINGDATA+key,id,Integer.parseInt(strategyTime),TimeUnit.MINUTES);//加入缓存并设置延迟时间(单位分钟)
return 1;//结束 // return 1;//结束
} // }
//redis存在数据,取出redis的id找对对应事件的配置,合成事件配置 // //redis存在数据,取出redis的id找对对应事件的配置,合成事件配置
HashMap<String, Object> map = dcWarningMapper.selectDcWarningById(dataId); // HashMap<String, Object> map = dcWarningMapper.selectDcWarningById(dataId);
if (map==null){//redis中有id但是数据库中没有这条数据,那就删除这条redis数据,新数据加入到数据库,并加入到redis // if (map==null){//redis中有id但是数据库中没有这条数据,那就删除这条redis数据,新数据加入到数据库,并加入到redis
redisCache.deleteObject(WARNINGDATA+key); // redisCache.deleteObject(WARNINGDATA+key);
dcWarningMapper.insertDcWarning(dcWarning); // dcWarningMapper.insertDcWarning(dcWarning);
String id = dcWarning.getId(); // String id = dcWarning.getId();
redisCache.setCacheObject(WARNINGDATA+key,id,Integer.parseInt(strategyTime),TimeUnit.MINUTES); // redisCache.setCacheObject(WARNINGDATA+key,id,Integer.parseInt(strategyTime),TimeUnit.MINUTES);
return 1; // return 1;
} // }
String otherConfig=""; // String otherConfig="";
otherConfig = map.get("otherConfig").toString();//取出原id的配置信息 // otherConfig = map.get("otherConfig").toString();//取出原id的配置信息
String otherConfigString = dcWarning.getOtherConfig();//新增的配置信息 // String otherConfigString = dcWarning.getOtherConfig();//新增的配置信息
JSONObject jsonObjectOne = new JSONObject(otherConfig); // JSONObject jsonObjectOne = new JSONObject(otherConfig);
JSONObject jsonObjectTwo = new JSONObject(otherConfigString); // JSONObject jsonObjectTwo = new JSONObject(otherConfigString);
JSONObject jsonObject = new DcWarningServiceImpl().mergeJsonObjects(jsonObjectOne, jsonObjectTwo);//合成新的json // JSONObject jsonObject = new DcWarningServiceImpl().mergeJsonObjects(jsonObjectOne, jsonObjectTwo);//合成新的json
Integer integer = dcWarningMapper.updateOtherConfig(dataId, jsonObject.toString());//修改数据库配置 // Integer integer = dcWarningMapper.updateOtherConfig(dataId, jsonObject.toString());//修改数据库配置
if (integer==0){ // if (integer==0){
return 0; // return 0;
} // }
return 1; // return 1;
} // }
HashMap redisValueFour = redisWarningStrategy.get(redisKye+"4");//查看传入的事件类型是否配置策略3(自动结束策略) // HashMap redisValueFour = redisWarningStrategy.get(redisKye+"4");//查看传入的事件类型是否配置策略3(自动结束策略)
if (redisValueTwo==null&&redisValueThree==null&&redisValueFour!=null){ //执行策略4,执行到这里说明1不存在或者2、3不存在或者1未满足过滤条件 // if (redisValueTwo==null&&redisValueThree==null&&redisValueFour!=null){ //执行策略4,执行到这里说明1不存在或者2、3不存在或者1未满足过滤条件
if (dataId==null){//如果不存在直接加入数据库,加入缓存 // if (dataId==null){//如果不存在直接加入数据库,加入缓存
int insertDcWarning = dcWarningMapper.insertDcWarning(dcWarning);//加入数据库 // int insertDcWarning = dcWarningMapper.insertDcWarning(dcWarning);//加入数据库
if (insertDcWarning==0){ // if (insertDcWarning==0){
return 0; // return 0;
} // }
String id = dcWarning.getId();//取出加入后的id作为value // String id = dcWarning.getId();//取出加入后的id作为value
redisCache.setCacheObject(WARNINGDATA+key,id,24,TimeUnit.HOURS);//加入缓存,防止redis数据累计,这里也要设置过期时间,设置为24小时 // redisCache.setCacheObject(WARNINGDATA+key,id,24,TimeUnit.HOURS);//加入缓存,防止redis数据累计,这里也要设置过期时间,设置为24小时
return 1;//结束 // return 1;//结束
} // }
//redis存在数据,取出redis的id找对对应事件的配置,合成事件配置 // //redis存在数据,取出redis的id找对对应事件的配置,合成事件配置
HashMap<String, Object> map = dcWarningMapper.selectDcWarningById(dataId); // HashMap<String, Object> map = dcWarningMapper.selectDcWarningById(dataId);
if (map==null){//redis中有id但是数据库中没有这条数据,那就删除这条redis数据,新数据加入到数据库,并加入到redis // if (map==null){//redis中有id但是数据库中没有这条数据,那就删除这条redis数据,新数据加入到数据库,并加入到redis
redisCache.deleteObject(WARNINGDATA+key); // redisCache.deleteObject(WARNINGDATA+key);
dcWarningMapper.insertDcWarning(dcWarning); // dcWarningMapper.insertDcWarning(dcWarning);
String id = dcWarning.getId(); // String id = dcWarning.getId();
redisCache.setCacheObject(WARNINGDATA+key,id); // redisCache.setCacheObject(WARNINGDATA+key,id);
return 1; // return 1;
} // }
String otherConfig=""; // String otherConfig="";
otherConfig = map.get("otherConfig").toString();//取出原id的配置信息 // otherConfig = map.get("otherConfig").toString();//取出原id的配置信息
String otherConfigString = dcWarning.getOtherConfig();//新增的配置信息 // String otherConfigString = dcWarning.getOtherConfig();//新增的配置信息
JSONObject jsonObjectOne = new JSONObject(otherConfig); // JSONObject jsonObjectOne = new JSONObject(otherConfig);
JSONObject jsonObjectTwo = new JSONObject(otherConfigString); // JSONObject jsonObjectTwo = new JSONObject(otherConfigString);
JSONObject jsonObject = new DcWarningServiceImpl().mergeJsonObjects(jsonObjectOne, jsonObjectTwo);//合成新的json // JSONObject jsonObject = new DcWarningServiceImpl().mergeJsonObjects(jsonObjectOne, jsonObjectTwo);//合成新的json
Integer integer = dcWarningMapper.updateOtherConfig(dataId, jsonObject.toString());//修改数据库配置 // Integer integer = dcWarningMapper.updateOtherConfig(dataId, jsonObject.toString());//修改数据库配置
redisCache.deleteObject(WARNINGDATA + key);//删除redis存储的数据 // redisCache.deleteObject(WARNINGDATA + key);//删除redis存储的数据
if (integer==0){ // if (integer==0){
return 0; // return 0;
} // }
return 1; // return 1;
} // }
return dcWarningMapper.insertDcWarning(dcWarning);//如果没有配置策略直接加入数据库; // return dcWarningMapper.insertDcWarning(dcWarning);//如果没有配置策略直接加入数据库;
} // }
private JSONObject mergeJsonObjects(JSONObject jsonObjectOne, JSONObject jsonObjectTwo){ private JSONObject mergeJsonObjects(JSONObject jsonObjectOne, JSONObject jsonObjectTwo){
// 合并videoList // 合并videoList
if (jsonObjectTwo.has("videoList")) { if (jsonObjectTwo.has("videoList")) {
@ -532,4 +533,14 @@ public class DcWarningServiceImpl implements IDcWarningService
return AjaxResult.success("批量操作成功"); return AjaxResult.success("批量操作成功");
} }
//定时结束部分事件
@Override
public Integer updateEndSection() {
List<DcWarning> dcWarnings = dcWarningMapper.selectEndSection();//全部应该结束事件的id
if (dcWarnings.size()==0){
return 1;
}
return dcWarningMapper.updateEndSection(dcWarnings);
}
} }

13
zc-business/src/main/resources/mapper/business/DcEmployeesMapper.xml

@ -14,13 +14,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="updateTime" column="update_time" /> <result property="updateTime" column="update_time" />
<result property="postName" column="post_name" /> <result property="postName" column="post_name" />
<result property="organizationName" column="organization_name" /> <result property="organizationName" column="organization_name" />
<result property="employeesType" column="employees_type" />
</resultMap> </resultMap>
<sql id="selectDcEmployeesVo"> <sql id="selectDcEmployeesVo">
select employees.id, employees.post_id, employees.organization_id, select employees.employees_type,employees.id, employees.post_id, employees.organization_id,
organization.organization_name,post.post_name, organization.organization_name,post.post_name,
employees.name, employees.contact_number, employees.name, employees.contact_number,
employees.create_time, employees.update_time from dc_employees as employees employees.create_time, employees.update_time,
CASE
WHEN employees.employees_type = 1 THEN '路管人员'
WHEN employees.employees_type = 2 THEN '应急人员'
END AS type
from dc_employees as employees
left join dc_organization as organization on organization.id=employees.organization_id left join dc_organization as organization on organization.id=employees.organization_id
left join sys_post as post on post.post_id=employees.post_id left join sys_post as post on post.post_id=employees.post_id
</sql> </sql>
@ -50,6 +56,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="contactNumber != null and contactNumber != ''">contact_number,</if> <if test="contactNumber != null and contactNumber != ''">contact_number,</if>
<if test="createTime != null">create_time,</if> <if test="createTime != null">create_time,</if>
<if test="updateTime != null">update_time,</if> <if test="updateTime != null">update_time,</if>
<if test="employeesType != null">employees_type,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if> <if test="id != null">#{id},</if>
@ -59,6 +66,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="contactNumber != null and contactNumber != ''">#{contactNumber},</if> <if test="contactNumber != null and contactNumber != ''">#{contactNumber},</if>
<if test="createTime != null">#{createTime},</if> <if test="createTime != null">#{createTime},</if>
<if test="updateTime != null">#{updateTime},</if> <if test="updateTime != null">#{updateTime},</if>
<if test="employeesType != null">#{employeesType},</if>
</trim> </trim>
</insert> </insert>
@ -71,6 +79,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="contactNumber != null and contactNumber != ''">contact_number = #{contactNumber},</if> <if test="contactNumber != null and contactNumber != ''">contact_number = #{contactNumber},</if>
<if test="createTime != null">create_time = #{createTime},</if> <if test="createTime != null">create_time = #{createTime},</if>
<if test="updateTime != null">update_time = #{updateTime},</if> <if test="updateTime != null">update_time = #{updateTime},</if>
<if test="employeesType != null">employees_type = #{employeesType},</if>
</trim> </trim>
where id = #{id} where id = #{id}
</update> </update>

16
zc-business/src/main/resources/mapper/business/DcWarningMapper.xml

@ -122,6 +122,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="otherConfig != null">other_config,</if> <if test="otherConfig != null">other_config,</if>
<if test="lane != null">lane,</if> <if test="lane != null">lane,</if>
<if test="vehicleType != null">vehicle_type,</if> <if test="vehicleType != null">vehicle_type,</if>
<if test="endTime != null">end_time,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if> <if test="id != null">#{id},</if>
@ -142,6 +143,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="otherConfig != null">#{otherConfig},</if> <if test="otherConfig != null">#{otherConfig},</if>
<if test="lane != null">#{lane},</if> <if test="lane != null">#{lane},</if>
<if test="vehicleType != null">#{vehicleType},</if> <if test="vehicleType != null">#{vehicleType},</if>
<if test="endTime != null">#{endTime},</if>
</trim> </trim>
</insert> </insert>
@ -182,9 +184,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update> </update>
<update id="updateOtherConfig"> <update id="updateOtherConfig">
update dc_warning set other_config=#{otherConfig},update_time=now() where id=#{id} update dc_warning set other_config=#{otherConfig},update_time=now(),end_time=#{endTime} where id=#{id}
</update>
<update id="updateEndSection">
update dc_warning set warning_state = 4
where id in
<foreach collection="dcWarningList" item="item" index="index"
separator="," open="(" close=")">
#{item.id}
</foreach>
</update> </update>
<delete id="deleteDcWarningById" parameterType="Integer"> <delete id="deleteDcWarningById" parameterType="Integer">
delete from dc_warning where id = #{id} delete from dc_warning where id = #{id}
</delete> </delete>
@ -233,5 +242,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="strategy != null "> and strategy = #{strategy}</if> <if test="strategy != null "> and strategy = #{strategy}</if>
</where> </where>
</select> </select>
<select id="selectEndSection" resultType="com.zc.business.domain.DcWarning">
select id from dc_warning where YEAR(end_time) = YEAR(CURDATE()) and warning_state!=4 and now()>end_time
</select>
</mapper> </mapper>

Loading…
Cancel
Save