diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java index 53c23e79..cd94b9d1 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java @@ -1166,65 +1166,6 @@ public class DcEventServiceImpl extends ServiceImpl impl dcEventProcess.setContext("由" + sourceName + "上报了一起" + typeName + "事件"); dcEventProcessService.insertDcEventProcess(dcEventProcess); - //插入调度默认数据 - ArrayList> hashMaps = new ArrayList<>(); - String stakeMark = dcEvent.getStakeMark();//传入桩号 - List> mapList = dcWarningMapper.selectRecentlySection();//全部机构的桩号和名称 - for (HashMap map : mapList) { - if (org.apache.commons.lang3.StringUtils.isBlank(map.get("stakeMark").toString())) { - continue; - } - Long sectionId = (Long) map.get("id");//机构的id - String stakeMarkNew = map.get("stakeMark").toString();//机构桩号 - com.zc.business.utils.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", sectionId); - hashMaps.add(map); - } - List> sortedHashMaps = hashMaps.stream().sorted(Comparator.comparing(map -> { - return (Double) map.get("difference"); - })).collect(Collectors.toList()); - HashMap hashMap = dcWarningMapper.selectDcDispatch(id);//查询事件是否已经有转的调度记录 - if (!sortedHashMaps.isEmpty() && hashMap == null) { - HashMap map = sortedHashMaps.get(0); - Long sortId = (Long) map.get("id");//取出最近的机构id - if (sortId != null) { - DcDispatch dcDispatch = new DcDispatch(); - DcDispatchResource dcDispatchResource = new DcDispatchResource(); - dcDispatch.setDeptId(SecurityUtils.getLoginUser().getDeptId()); - dcDispatch.setEventId(id); - dcDispatch.setStartTime(DateUtils.getNowDate()); - dcDispatch.setDispatchStatus(2L);//进行中状态 - dcDispatch.setRemark(dcEvent.getRemark()); - dcWarningMapper.insertDcDispatch(dcDispatch);//事件绑定信息记录 - Long dispatchId = dcDispatch.getId();//信息记录id - List> employeesMap = dcWarningMapper.selectOrganizationEmployees(sortId);//人员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(sortId);//车辆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 i; } 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 7216ea41..9cdd30aa 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 @@ -612,6 +612,7 @@ public class DcWarningServiceImpl implements IDcWarningService } @Override + @Transactional(rollbackFor = Exception.class) public AjaxResult commandAndDispatch(DcWarning dcWarning) { Map mapAll = new HashMap<>(); HashMap dcDispatch = dcWarningMapper.selectDcDispatch(dcWarning.getId());//查询是否存在调度记录 @@ -671,6 +672,7 @@ public class DcWarningServiceImpl implements IDcWarningService } //指挥调度,当调度信息为空的时候调用智能分配资源 @Override + @Transactional(rollbackFor = Exception.class) public AjaxResult intelligentSource(DcWarning dcWarning) { String stakeMark = dcWarning.getStakeMark(); ArrayList> hashMaps = new ArrayList<>(); @@ -747,7 +749,7 @@ public class DcWarningServiceImpl implements IDcWarningService employees = Long.parseLong(map.get("employeesId").toString());//人员 } Long vehicles=null; - if (map.get("vehiclesId").toString()!=null){ + if (map.get("vehiclesId")!=null){ vehicles = Long.parseLong(map.get("vehiclesId").toString());//车辆 } DcDispatch dcDispatch = new DcDispatch(); diff --git a/zc-business/src/main/resources/mapper/business/DcEventProcessMapper.xml b/zc-business/src/main/resources/mapper/business/DcEventProcessMapper.xml index e852e609..68376d4f 100644 --- a/zc-business/src/main/resources/mapper/business/DcEventProcessMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcEventProcessMapper.xml @@ -152,7 +152,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" \ No newline at end of file diff --git a/zc-business/src/main/resources/mapper/business/DcWarningMapper.xml b/zc-business/src/main/resources/mapper/business/DcWarningMapper.xml index c3986369..c4155e2a 100644 --- a/zc-business/src/main/resources/mapper/business/DcWarningMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcWarningMapper.xml @@ -319,7 +319,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where parent_id!=0