diff --git a/zc-business/src/main/java/com/zc/business/controller/DcWarningController.java b/zc-business/src/main/java/com/zc/business/controller/DcWarningController.java index 3c9f6cc5..029931fa 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcWarningController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcWarningController.java @@ -160,7 +160,7 @@ public class DcWarningController extends BaseController return dcWarningService.batchConvert(dcWarningBatchConvert); } - //指挥调度 + //1,指挥调度,查看是否存在记录和资源信息,存在即返回 @PostMapping("/commandAndDispatch") public AjaxResult commandAndDispatch(@RequestBody DcWarning dcWarning){ if (StringUtils.isBlank(dcWarning.getStakeMark())||StringUtils.isBlank(dcWarning.getId())){ @@ -168,6 +168,22 @@ public class DcWarningController extends BaseController } return (dcWarningService.commandAndDispatch(dcWarning)); } + //2,指挥调度,当调度信息为空的时候调用智能分配资源 + @PostMapping("/intelligentSource") + public AjaxResult intelligentSource(@RequestBody DcWarning dcWarning){ + if (StringUtils.isBlank(dcWarning.getStakeMark())){ + return AjaxResult.error("参数错误"); + } + return (dcWarningService.intelligentSource(dcWarning)); + } + //3.指挥调度,新增调度记录信息 + @PostMapping("/insertDispatch") + public AjaxResult insertDispatch(@RequestBody HashMap map){ + if (map == null || !map.containsKey("eventId")||StringUtils.isBlank(map.get("eventId").toString())){ + return AjaxResult.error("参数错误"); + } + return (dcWarningService.insertDispatch(map)); + } //指挥调度记录修改 @PostMapping("/updateDispatch") public AjaxResult insertDispatch(@RequestBody DcDispatch dcDispatch){ @@ -176,12 +192,9 @@ public class DcWarningController extends BaseController } return toAjax(dcWarningService.insertDispatch(dcDispatch)); } - //指挥调度资源新增 + //4.指挥调度资源新增(用户修改弹窗的提交) @PostMapping("/updateSource") public AjaxResult insertDispatchSource(@RequestBody HashMap map){ - if (map==null||!map.containsKey("dispatchId")){ - return AjaxResult.error("参数错误"); - } return toAjax(dcWarningService.insertDispatchSource(map)); } //感知事件误报 diff --git a/zc-business/src/main/java/com/zc/business/mapper/DcWarningMapper.java b/zc-business/src/main/java/com/zc/business/mapper/DcWarningMapper.java index aa7a8af8..95df0a5b 100644 --- a/zc-business/src/main/java/com/zc/business/mapper/DcWarningMapper.java +++ b/zc-business/src/main/java/com/zc/business/mapper/DcWarningMapper.java @@ -99,6 +99,7 @@ public interface DcWarningMapper public Integer updateEndSection(@Param("dcWarningList") List dcWarningList); //查询当天全部可以结束的事件 public List selectEndSection(); + //依据桩号返回驻点id public Long selectSectionId(@Param("stakeMark")String stakeMark,@Param("direction")String direction); //依据桩号获取最近距离的驻点 @@ -130,6 +131,8 @@ public interface DcWarningMapper public HashMap selectOrganization(); //选中的人员信息 public List> selectEmployeesChoice(@Param("dispatchId")Long dispatchId); + //查询最近的交警人员和电话 + public List> selectTrafficPolice(@Param("organizationId")Long organizationId); //选中的车辆信息 public List> selectVehiclesChoice(@Param("dispatchId")Long dispatchId); public Integer deleteDispatchResource(@Param("dispatchId")Long dispatchId); @@ -137,4 +140,12 @@ public interface DcWarningMapper DcDispatch selectDcDispatchById(@Param("id") Long id); //误报解除 public Integer falseAlarmResolution(DcWarning dcWarning); + //依据人员id查询人员名称 + public String employeesName(Long id); + //依据车辆id查询车辆信息,前提车辆可用 + public String vehiclesName(Long id); + //依据车辆id查询车辆信息,前提车辆可用 + public String vehiclesType(Long id); + //依据机构id查询机构名称 + public String organizationName(Long id); } diff --git a/zc-business/src/main/java/com/zc/business/service/IDcWarningService.java b/zc-business/src/main/java/com/zc/business/service/IDcWarningService.java index c33cacb8..095c3f74 100644 --- a/zc-business/src/main/java/com/zc/business/service/IDcWarningService.java +++ b/zc-business/src/main/java/com/zc/business/service/IDcWarningService.java @@ -91,8 +91,12 @@ public interface IDcWarningService //定时结束部分事件 Integer updateEndSection(); - //指挥调度 + //1.指挥调度 AjaxResult commandAndDispatch(DcWarning dcWarning); + //2.指挥调度,当调度信息为空的时候调用智能分配资源 + AjaxResult intelligentSource(DcWarning dcWarning); + //3.指挥调度新增资源 + AjaxResult insertDispatch(HashMap map); //修改指挥调度资源记录 public Integer insertDispatch(DcDispatch dcDispatch); //新增指挥调度资源记录 diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java index fb839689..7216ea41 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java @@ -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> mapList = dcWarningMapper.selectRecentlySection();//全部机构的桩号和名称 - for (HashMap 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> sortedHashMaps = hashMaps.stream().sorted(Comparator.comparing(map -> { - return (Double) map.get("difference"); })).collect(Collectors.toList()); - HashMap hashMap = dcWarningMapper.selectDcDispatch(dcWarning.getId());//查询事件是否已经有转的调度记录 - if (!sortedHashMaps.isEmpty()&&hashMap==null) { - HashMap 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> employeesMap = dcWarningMapper.selectOrganizationEmployees(id);//人员map - if (employeesMap != null&&employeesMap.size()>0) { - // 生成一个随机索引,范围在0到列表长度减1之间 - int randomIndex = ThreadLocalRandom.current().nextInt(employeesMap.size()); - HashMap 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> vehiclesMap = dcWarningMapper.selectVehicles(id);//车辆map - if (vehiclesMap != null&&vehiclesMap.size()>0) { - // 生成一个随机索引,范围在0到列表长度减1之间 - int randomIndex = ThreadLocalRandom.current().nextInt(vehiclesMap.size()); - HashMap 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 mapAll = new HashMap<>(); + HashMap dcDispatch = dcWarningMapper.selectDcDispatch(dcWarning.getId());//查询是否存在调度记录 //逻辑,调用全部的机构信息,计算传入的桩号与机构桩号的距离作为排序使用,使用机构的id调出车辆,人员,值班等信息 List> mapList = dcWarningMapper.selectRecentlySection();//全部机构的桩号和名称 ArrayList> hashMaps = new ArrayList<>(); - Map mapAll = new HashMap<>(); + for (HashMap 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> employeesMap = dcWarningMapper.selectEmployeesDispatch(id,dcWarning.getId());//人员map List> vehiclesMap = dcWarningMapper.selectVehiclesDispatch(id,dcWarning.getId());//车辆map map.put("employeesMap",employeesMap); @@ -692,20 +637,31 @@ public class DcWarningServiceImpl implements IDcWarningService hashMaps.add(map); } List> sortedHashMaps = hashMaps.stream().sorted(Comparator.comparing(map -> { - return (Double) map.get("difference"); })).collect(Collectors.toList()); + return (Double) map.get("difference"); })).collect(Collectors.toList()); mapAll.put("listData",sortedHashMaps); + if (!sortedHashMaps.isEmpty()) { + HashMap map = sortedHashMaps.get(0); + Long id = Long.parseLong(map.get("id").toString());//取出最近的机构id + List> trafficPolice = dcWarningMapper.selectTrafficPolice(id);//交警人员信息 + mapAll.put("trafficPolice",trafficPolice); + } + if (dcDispatch==null){ + mapAll.put("existence",0); + return AjaxResult.success(mapAll); + } + mapAll.put("existence",1); HashMap map = dcWarningMapper.selectDcDispatch(dcWarning.getId());//获取机构id与资源id if (map!=null){ HashMap 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> shifts = dcWarningMapper.selectShiftsEmployees();//值班为空把全部的人员信息作为值班人员信息 + //List> shifts = dcWarningMapper.selectShiftsEmployees();//值班为空把全部的人员信息作为值班人员信息 List> resource = dcWarningMapper.selectDispatchResource(id);//全部资源信息 List> employeesChoice = dcWarningMapper.selectEmployeesChoice(id);//选中人员信息 List> 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> hashMaps = new ArrayList<>(); + Map mapAll = new HashMap<>(); + List> mapList = dcWarningMapper.selectRecentlySection();//全部机构的桩号和名称 + for (HashMap map:mapList){ + HashMap 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> employeesMap = dcWarningMapper.selectEmployeesDispatch(id,dcWarning.getId());//人员map + List> 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> sortedHashMaps = hashMaps.stream().sorted(Comparator.comparing(map -> { + return (Double) map.get("difference"); })).collect(Collectors.toList()); + if (!sortedHashMaps.isEmpty()) { + HashMap map = sortedHashMaps.get(0); + Long id = Long.parseLong(map.get("organizationId").toString());//取出最近的机构id + if (id != null) { + List> employeesMap = dcWarningMapper.selectOrganizationEmployees(id);//人员map + if (employeesMap != null&&employeesMap.size()>0) { + HashMap employeesHashMap = new HashMap<>(); + // 生成一个随机索引,范围在0到列表长度减1之间 + int randomIndex = ThreadLocalRandom.current().nextInt(employeesMap.size()); + HashMap 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> vehiclesMap = dcWarningMapper.selectVehicles(id);//车辆map + if (vehiclesMap != null&&vehiclesMap.size()>0) { + HashMap vehiclesHashMap = new HashMap<>(); + // 生成一个随机索引,范围在0到列表长度减1之间 + int randomIndex = ThreadLocalRandom.current().nextInt(vehiclesMap.size()); + HashMap 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> employeesArray = (ArrayList>) 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); diff --git a/zc-business/src/main/resources/mapper/business/DcWarningMapper.xml b/zc-business/src/main/resources/mapper/business/DcWarningMapper.xml index 3486169b..c3986369 100644 --- a/zc-business/src/main/resources/mapper/business/DcWarningMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcWarningMapper.xml @@ -255,6 +255,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where id = #{id} + delete from dc_warning where id = #{id} @@ -278,6 +279,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" delete from dc_dispatch_resource where dispatch_id=#{dispatchId} + @@ -317,7 +319,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where parent_id!=0 SELECT DISTINCT dc_employees.id, dc_employees.name, - dc_employees.contact_number AS contactNumber, - CASE - WHEN t.id IS NOT NULL THEN 1 -- 连接成立 - ELSE 0 -- 连接不成立 - END AS state + dc_employees.contact_number AS contactNumber from dc_employees LEFT JOIN( select employees.id id, employees.name, employees.contact_number contactNumber @@ -380,19 +378,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" left JOIN dc_dispatch_resource as respurce on respurce.resource_id = employees.id LEFT JOIN dc_dispatch as path on path.id = respurce.dispatch_id where employees.organization_id = #{organizationId} - and employees.employees_type = 2 and respurce.dispatch_type = 1 and path.event_id = #{eventId}) as t on t.id = dc_employees.id - where organization_id = #{organizationId} + where organization_id = #{organizationId} and dc_employees.employees_type=1 select * from dc_dispatch where id = #{id} + + + + +