|
|
@ -27,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.lang.reflect.Array; |
|
|
|
import java.rmi.MarshalledObject; |
|
|
|
import java.util.Objects; |
|
|
|
import java.util.concurrent.ThreadLocalRandom; |
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.util.ArrayList; |
|
|
@ -508,68 +509,10 @@ public class DcWarningServiceImpl implements IDcWarningService |
|
|
|
dcEvent.setCreateTime(DateUtils.getNowDate());//创建时间
|
|
|
|
dcEvent.setUserId(SecurityUtils.getUserId());//处置人员
|
|
|
|
dcEvent.setRoadId(1L);//高速公路(济菏高速)
|
|
|
|
|
|
|
|
int insertDcEvent = dcEventService.insertDcEventWarning(dcEvent); |
|
|
|
|
|
|
|
if (insertDcEvent==0){ |
|
|
|
return AjaxResult.error("操作失败"); |
|
|
|
} |
|
|
|
List<HashMap<String, Object>> mapList = dcWarningMapper.selectRecentlySection();//全部机构的桩号和名称
|
|
|
|
for (HashMap<String,Object> map:mapList){ |
|
|
|
if (StringUtils.isBlank(map.get("stakeMark").toString())){ |
|
|
|
continue; |
|
|
|
} |
|
|
|
Long id = (Long) map.get("id");//机构的id
|
|
|
|
String stakeMarkNew = map.get("stakeMark").toString();//机构桩号
|
|
|
|
StakeMarkUtils stakeMarkUtils = new StakeMarkUtils(); |
|
|
|
Integer itselfStakeMark = stakeMarkUtils.stakeMarkToInt(stakeMarkNew);//机构本身的米数
|
|
|
|
Integer afferentStakeMark = stakeMarkUtils.stakeMarkToInt(stakeMark);//传入的桩号米数
|
|
|
|
Integer difference =Math.abs(afferentStakeMark-itselfStakeMark); //计算距离绝对值
|
|
|
|
map.put("difference",difference/1000.0);//米转公里加入到map
|
|
|
|
map.put("id",id); |
|
|
|
hashMaps.add(map); |
|
|
|
} |
|
|
|
List<HashMap<String, Object>> sortedHashMaps = hashMaps.stream().sorted(Comparator.comparing(map -> { |
|
|
|
return (Double) map.get("difference"); })).collect(Collectors.toList()); |
|
|
|
HashMap<String, Object> hashMap = dcWarningMapper.selectDcDispatch(dcWarning.getId());//查询事件是否已经有转的调度记录
|
|
|
|
if (!sortedHashMaps.isEmpty()&&hashMap==null) { |
|
|
|
HashMap<String, Object> map = sortedHashMaps.get(0); |
|
|
|
Long id = (Long) map.get("id");//取出最近的机构id
|
|
|
|
if (id != null) { |
|
|
|
DcDispatch dcDispatch = new DcDispatch(); |
|
|
|
DcDispatchResource dcDispatchResource = new DcDispatchResource(); |
|
|
|
dcDispatch.setDeptId(SecurityUtils.getLoginUser().getDeptId()); |
|
|
|
dcDispatch.setEventId(dcWarning.getId()); |
|
|
|
dcDispatch.setStartTime(DateUtils.getNowDate()); |
|
|
|
dcDispatch.setDispatchStatus(2L);//进行中状态
|
|
|
|
dcDispatch.setRemark(dcWarning.getRemark()); |
|
|
|
dcWarningMapper.insertDcDispatch(dcDispatch);//事件绑定信息记录
|
|
|
|
Long dispatchId = dcDispatch.getId();//信息记录id
|
|
|
|
List<HashMap<String, Object>> employeesMap = dcWarningMapper.selectOrganizationEmployees(id);//人员map
|
|
|
|
if (employeesMap != null&&employeesMap.size()>0) { |
|
|
|
// 生成一个随机索引,范围在0到列表长度减1之间
|
|
|
|
int randomIndex = ThreadLocalRandom.current().nextInt(employeesMap.size()); |
|
|
|
HashMap<String, Object> randomEmployee = employeesMap.get(randomIndex); |
|
|
|
Long employeesId = (Long) randomEmployee.get("id");//随机人员id
|
|
|
|
dcDispatchResource.setResourceId(employeesId);//资源id
|
|
|
|
dcDispatchResource.setDispatchType(1);//资源类型
|
|
|
|
dcDispatchResource.setDispatchId(dispatchId);//信息记录id
|
|
|
|
dcWarningMapper.insertDispatchResource(dcDispatchResource); |
|
|
|
} |
|
|
|
List<HashMap<String, Object>> vehiclesMap = dcWarningMapper.selectVehicles(id);//车辆map
|
|
|
|
if (vehiclesMap != null&&vehiclesMap.size()>0) { |
|
|
|
// 生成一个随机索引,范围在0到列表长度减1之间
|
|
|
|
int randomIndex = ThreadLocalRandom.current().nextInt(vehiclesMap.size()); |
|
|
|
HashMap<String, Object> randomEmployee = employeesMap.get(randomIndex); |
|
|
|
Long vehiclesId = (Long) randomEmployee.get("id");//随机车辆id
|
|
|
|
dcDispatchResource.setResourceId(vehiclesId);//资源id
|
|
|
|
dcDispatchResource.setDispatchType(2);//资源类型
|
|
|
|
dcDispatchResource.setDispatchId(dispatchId);//信息记录id
|
|
|
|
dcWarningMapper.insertDispatchResource(dcDispatchResource);//绑定车辆信息
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return AjaxResult.success("操作成功"); |
|
|
|
|
|
|
|
} |
|
|
@ -670,10 +613,12 @@ public class DcWarningServiceImpl implements IDcWarningService |
|
|
|
|
|
|
|
@Override |
|
|
|
public AjaxResult commandAndDispatch(DcWarning dcWarning) { |
|
|
|
Map<String, Object> mapAll = new HashMap<>(); |
|
|
|
HashMap<String, Object> dcDispatch = dcWarningMapper.selectDcDispatch(dcWarning.getId());//查询是否存在调度记录
|
|
|
|
//逻辑,调用全部的机构信息,计算传入的桩号与机构桩号的距离作为排序使用,使用机构的id调出车辆,人员,值班等信息
|
|
|
|
List<HashMap<String, Object>> mapList = dcWarningMapper.selectRecentlySection();//全部机构的桩号和名称
|
|
|
|
ArrayList<HashMap<String,Object>> hashMaps = new ArrayList<>(); |
|
|
|
Map<String, Object> mapAll = new HashMap<>(); |
|
|
|
|
|
|
|
for (HashMap<String,Object> map:mapList){ |
|
|
|
if (StringUtils.isBlank(map.get("stakeMark").toString())){ |
|
|
|
continue; |
|
|
@ -684,7 +629,7 @@ public class DcWarningServiceImpl implements IDcWarningService |
|
|
|
Integer afferentStakeMark = stakeMarkUtils.stakeMarkToInt(dcWarning.getStakeMark());//传入的桩号米数
|
|
|
|
Integer difference =Math.abs(afferentStakeMark-itselfStakeMark); //计算距离绝对值
|
|
|
|
map.put("difference",difference/1000.0);//米转公里加入到map
|
|
|
|
Long id = (Long) map.get("id");//机构的id,用户获取人员、值班、车辆等信息
|
|
|
|
Long id =Long.parseLong(map.get("id").toString());//机构的id,用户获取人员、值班、车辆等信息
|
|
|
|
List<HashMap<String, Object>> employeesMap = dcWarningMapper.selectEmployeesDispatch(id,dcWarning.getId());//人员map
|
|
|
|
List<HashMap<String, Object>> vehiclesMap = dcWarningMapper.selectVehiclesDispatch(id,dcWarning.getId());//车辆map
|
|
|
|
map.put("employeesMap",employeesMap); |
|
|
@ -694,18 +639,29 @@ public class DcWarningServiceImpl implements IDcWarningService |
|
|
|
List<HashMap<String, Object>> sortedHashMaps = hashMaps.stream().sorted(Comparator.comparing(map -> { |
|
|
|
return (Double) map.get("difference"); })).collect(Collectors.toList()); |
|
|
|
mapAll.put("listData",sortedHashMaps); |
|
|
|
if (!sortedHashMaps.isEmpty()) { |
|
|
|
HashMap<String, Object> map = sortedHashMaps.get(0); |
|
|
|
Long id = Long.parseLong(map.get("id").toString());//取出最近的机构id
|
|
|
|
List<HashMap<String, Object>> trafficPolice = dcWarningMapper.selectTrafficPolice(id);//交警人员信息
|
|
|
|
mapAll.put("trafficPolice",trafficPolice); |
|
|
|
} |
|
|
|
if (dcDispatch==null){ |
|
|
|
mapAll.put("existence",0); |
|
|
|
return AjaxResult.success(mapAll); |
|
|
|
} |
|
|
|
mapAll.put("existence",1); |
|
|
|
HashMap<String, Object> map = dcWarningMapper.selectDcDispatch(dcWarning.getId());//获取机构id与资源id
|
|
|
|
if (map!=null){ |
|
|
|
HashMap<Object, Object> hashMap = new HashMap<>(); |
|
|
|
Long id = (Long) map.get("id");//调度记录id
|
|
|
|
Long id =Long.parseLong(map.get("id").toString());//调度记录id
|
|
|
|
Object deptName =map.get("deptName");//部门名称
|
|
|
|
List<HashMap<String, Object>> shifts = dcWarningMapper.selectShiftsEmployees();//值班为空把全部的人员信息作为值班人员信息
|
|
|
|
//List<HashMap<String, Object>> shifts = dcWarningMapper.selectShiftsEmployees();//值班为空把全部的人员信息作为值班人员信息
|
|
|
|
List<HashMap<String, Object>> resource = dcWarningMapper.selectDispatchResource(id);//全部资源信息
|
|
|
|
List<HashMap<String, Object>> employeesChoice = dcWarningMapper.selectEmployeesChoice(id);//选中人员信息
|
|
|
|
List<HashMap<String, Object>> vehiclesChoice = dcWarningMapper.selectVehiclesChoice(id);//选中车辆信息
|
|
|
|
hashMap.put("id",id);//调度记录id
|
|
|
|
hashMap.put("deptName",deptName); |
|
|
|
hashMap.put("shifts",shifts); |
|
|
|
//hashMap.put("shifts",shifts);
|
|
|
|
hashMap.put("resource",resource); |
|
|
|
mapAll.put("resource",hashMap); |
|
|
|
mapAll.put("employeesChoice",employeesChoice); |
|
|
@ -713,6 +669,120 @@ public class DcWarningServiceImpl implements IDcWarningService |
|
|
|
} |
|
|
|
return AjaxResult.success(mapAll); |
|
|
|
} |
|
|
|
//指挥调度,当调度信息为空的时候调用智能分配资源
|
|
|
|
@Override |
|
|
|
public AjaxResult intelligentSource(DcWarning dcWarning) { |
|
|
|
String stakeMark = dcWarning.getStakeMark(); |
|
|
|
ArrayList<HashMap<String,Object>> hashMaps = new ArrayList<>(); |
|
|
|
Map<String, Object> mapAll = new HashMap<>(); |
|
|
|
List<HashMap<String, Object>> mapList = dcWarningMapper.selectRecentlySection();//全部机构的桩号和名称
|
|
|
|
for (HashMap<String,Object> map:mapList){ |
|
|
|
HashMap<String, Object> mapValue = new HashMap<>(); |
|
|
|
if (StringUtils.isBlank(map.get("stakeMark").toString())){ |
|
|
|
continue; |
|
|
|
} |
|
|
|
StakeMarkUtils stakeMarkUtils = new StakeMarkUtils(); |
|
|
|
String stakeMarkValue = map.get("stakeMark").toString(); |
|
|
|
Integer itselfStakeMark = stakeMarkUtils.stakeMarkToInt(stakeMarkValue);//桩号本身的米数
|
|
|
|
Integer afferentStakeMark = stakeMarkUtils.stakeMarkToInt(dcWarning.getStakeMark());//传入的桩号米数
|
|
|
|
Integer difference =Math.abs(afferentStakeMark-itselfStakeMark); //计算距离绝对值
|
|
|
|
|
|
|
|
mapValue.put("difference",difference/1000.0);//米转公里加入到map
|
|
|
|
Long id =Long.parseLong(map.get("id").toString());//机构的id,用户获取人员、车辆等信息
|
|
|
|
List<HashMap<String, Object>> employeesMap = dcWarningMapper.selectEmployeesDispatch(id,dcWarning.getId());//人员map
|
|
|
|
List<HashMap<String, Object>> vehiclesMap = dcWarningMapper.selectVehiclesDispatch(id,dcWarning.getId());//车辆map
|
|
|
|
String organizationName = dcWarningMapper.organizationName(id); |
|
|
|
mapValue.put("employeesMap",employeesMap); |
|
|
|
mapValue.put("vehiclesMap",vehiclesMap); |
|
|
|
mapValue.put("organizationId",id); |
|
|
|
mapValue.put("organizationName",organizationName); |
|
|
|
hashMaps.add(mapValue); |
|
|
|
} |
|
|
|
mapAll.put("selectData",hashMaps); |
|
|
|
List<HashMap<String, Object>> sortedHashMaps = hashMaps.stream().sorted(Comparator.comparing(map -> { |
|
|
|
return (Double) map.get("difference"); })).collect(Collectors.toList()); |
|
|
|
if (!sortedHashMaps.isEmpty()) { |
|
|
|
HashMap<String, Object> map = sortedHashMaps.get(0); |
|
|
|
Long id = Long.parseLong(map.get("organizationId").toString());//取出最近的机构id
|
|
|
|
if (id != null) { |
|
|
|
List<HashMap<String, Object>> employeesMap = dcWarningMapper.selectOrganizationEmployees(id);//人员map
|
|
|
|
if (employeesMap != null&&employeesMap.size()>0) { |
|
|
|
HashMap<String, Object> employeesHashMap = new HashMap<>(); |
|
|
|
// 生成一个随机索引,范围在0到列表长度减1之间
|
|
|
|
int randomIndex = ThreadLocalRandom.current().nextInt(employeesMap.size()); |
|
|
|
HashMap<String, Object> randomEmployee = employeesMap.get(randomIndex); |
|
|
|
Long employeesId = Long.parseLong(randomEmployee.get("id").toString());//随机人员id
|
|
|
|
String employeesName = dcWarningMapper.employeesName(employeesId);//随机人员姓名
|
|
|
|
employeesHashMap.put("employeesId",employeesId); |
|
|
|
employeesHashMap.put("employeesName",employeesName); |
|
|
|
mapAll.put("employees",employeesHashMap); |
|
|
|
} |
|
|
|
List<HashMap<String, Object>> vehiclesMap = dcWarningMapper.selectVehicles(id);//车辆map
|
|
|
|
if (vehiclesMap != null&&vehiclesMap.size()>0) { |
|
|
|
HashMap<String, Object> vehiclesHashMap = new HashMap<>(); |
|
|
|
// 生成一个随机索引,范围在0到列表长度减1之间
|
|
|
|
int randomIndex = ThreadLocalRandom.current().nextInt(vehiclesMap.size()); |
|
|
|
HashMap<String, Object> randomEmployee = vehiclesMap.get(randomIndex); |
|
|
|
Long vehiclesId =Long.parseLong(randomEmployee.get("id").toString());//随机车辆id
|
|
|
|
String vehiclesName = dcWarningMapper.vehiclesName(vehiclesId);//随机车辆
|
|
|
|
String vehiclesType = dcWarningMapper.vehiclesType(vehiclesId);//随机车辆
|
|
|
|
vehiclesHashMap.put("vehiclesId",vehiclesId); |
|
|
|
vehiclesHashMap.put("vehiclesName",vehiclesName); |
|
|
|
vehiclesHashMap.put("vehiclesType",vehiclesType); |
|
|
|
mapAll.put("vehicles",vehiclesHashMap); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return AjaxResult.success(mapAll); |
|
|
|
} |
|
|
|
//3.指挥调度新增资源
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public AjaxResult insertDispatch(HashMap map) { |
|
|
|
//事件id、事件备注、机构id、资源id
|
|
|
|
String eventId = map.get("eventId").toString();//事件id
|
|
|
|
String remark = Objects.toString(map.get("remark"), ""); |
|
|
|
Long employees=null; |
|
|
|
if (map.get("employeesId")!=null){ |
|
|
|
employees = Long.parseLong(map.get("employeesId").toString());//人员
|
|
|
|
} |
|
|
|
Long vehicles=null; |
|
|
|
if (map.get("vehiclesId").toString()!=null){ |
|
|
|
vehicles = Long.parseLong(map.get("vehiclesId").toString());//车辆
|
|
|
|
} |
|
|
|
DcDispatch dcDispatch = new DcDispatch(); |
|
|
|
DcDispatchResource dcDispatchResource = new DcDispatchResource(); |
|
|
|
dcDispatch.setDeptId(SecurityUtils.getLoginUser().getDeptId()); |
|
|
|
dcDispatch.setEventId(eventId); |
|
|
|
dcDispatch.setStartTime(DateUtils.getNowDate()); |
|
|
|
dcDispatch.setDispatchStatus(2L);//进行中状态
|
|
|
|
dcDispatch.setRemark(remark); |
|
|
|
Integer integer = dcWarningMapper.insertDcDispatch(dcDispatch);//事件绑定信息记录
|
|
|
|
if (integer==0){ |
|
|
|
return AjaxResult.error(); |
|
|
|
} |
|
|
|
Long dispatchId = dcDispatch.getId();//信息记录id
|
|
|
|
if (employees!=null) { |
|
|
|
dcDispatchResource.setResourceId(employees);//资源id
|
|
|
|
dcDispatchResource.setDispatchType(1);//资源类型
|
|
|
|
dcDispatchResource.setDispatchId(dispatchId);//信息记录id
|
|
|
|
Integer employeesSource = dcWarningMapper.insertDispatchResource(dcDispatchResource); |
|
|
|
if (employeesSource==0){ |
|
|
|
return AjaxResult.error("人员调度异常"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (vehicles!=null) { |
|
|
|
// 生成一个随机索引,范围在0到列表长度减1之间
|
|
|
|
dcDispatchResource.setResourceId(vehicles);//资源id
|
|
|
|
dcDispatchResource.setDispatchType(2);//资源类型
|
|
|
|
dcDispatchResource.setDispatchId(dispatchId);//信息记录id
|
|
|
|
Integer dispatchResource = dcWarningMapper.insertDispatchResource(dcDispatchResource);//绑定车辆信息
|
|
|
|
if (dispatchResource==0){ |
|
|
|
return AjaxResult.error("车辆调度异常"); |
|
|
|
} |
|
|
|
} |
|
|
|
return AjaxResult.success(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Integer insertDispatch(DcDispatch dcDispatch) { |
|
|
@ -725,12 +795,19 @@ public class DcWarningServiceImpl implements IDcWarningService |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Integer insertDispatchSource(HashMap map) { |
|
|
|
String eventId = map.get("eventId").toString();//事件id
|
|
|
|
String remark = Objects.toString(map.get("remark"), ""); |
|
|
|
DcDispatch dcDispatch = new DcDispatch(); |
|
|
|
DcDispatchResource dcDispatchResource = new DcDispatchResource(); |
|
|
|
Integer pat = (Integer) map.get("dispatchId"); |
|
|
|
long dispatchId = pat.longValue(); |
|
|
|
dcDispatch.setDeptId(SecurityUtils.getLoginUser().getDeptId()); |
|
|
|
dcDispatch.setEventId(eventId); |
|
|
|
dcDispatch.setStartTime(DateUtils.getNowDate()); |
|
|
|
dcDispatch.setDispatchStatus(2L);//进行中状态
|
|
|
|
dcDispatch.setRemark(remark); |
|
|
|
dcWarningMapper.insertDcDispatch(dcDispatch);//事件绑定信息记录
|
|
|
|
Long dispatchId = dcDispatch.getId(); |
|
|
|
dcWarningMapper.deleteDispatchResource(dispatchId);//删除全部属于该调度记录下的全部资源
|
|
|
|
ArrayList<Map<String,Object>> employeesArray = (ArrayList<Map<String,Object>>) map.get("employees");//取出人员
|
|
|
|
|
|
|
|
String context = ""; |
|
|
|
if (employeesArray!=null&&employeesArray.size()>0) { |
|
|
|
context += "路管人员"; |
|
|
@ -768,9 +845,9 @@ public class DcWarningServiceImpl implements IDcWarningService |
|
|
|
context += "参与事件救援"; |
|
|
|
} |
|
|
|
|
|
|
|
DcDispatch dcDispatch = dcWarningMapper.selectDcDispatchById(dispatchId); |
|
|
|
DcDispatch dcDispatchEventId = dcWarningMapper.selectDcDispatchById(dispatchId); |
|
|
|
DcEventProcess dcEventProcess = new DcEventProcess(); |
|
|
|
dcEventProcess.setEventId(dcDispatch.getEventId()); |
|
|
|
dcEventProcess.setEventId(dcDispatchEventId.getEventId()); |
|
|
|
dcEventProcess.setSource(1); |
|
|
|
dcEventProcess.setContext(context); |
|
|
|
dcEventProcessService.insertDcEventProcess(dcEventProcess); |
|
|
|