2021与蓝度共同重构项目,服务端
liuhaonan
2022-09-14 aebf1df56a02c71a5e6b4a9da395c12ed66edb1b
ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightTaskService.java
@@ -105,18 +105,24 @@
            throw new BusinessException("保存路灯任务失败");
        }
        List<String> poleCodeList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(param.getPoleIdList())) {
            List<Pole> poleList = SpringContextHolder.getBean(PoleService.class).listByIds(param.getPoleIdList());
        //传入的灯杆id集合
        List<Long> poleIdList = new ArrayList<>();
        //去重
        for (Long item : param.getPoleIdList()) {
            if (!poleIdList.contains(item)) {
                poleIdList.add(item);
            }
        }
        if (CollectionUtil.isNotEmpty(poleIdList)) {
            List<Pole> poleList = SpringContextHolder.getBean(PoleService.class).listByIds(poleIdList);
            if (CollectionUtil.isNotEmpty(poleList)) {
                poleCodeList = poleList.stream().map(Pole::getDeviceCode).collect(Collectors.toList());
            }
        }
        String content = "{任务ID:" + newLightTask.getTaskId() + ", 任务名:" + newLightTask.getTaskName() + "},{内帧指令" + newLightTask.getFramePayload() + ", 灯杆ID:" + param.getPoleIdList().toString() + ", 控制的灯头地址:" + param.getLightAddress() + " }";
        String content = "{任务ID:" + newLightTask.getTaskId() + ", 任务名:" + newLightTask.getTaskName() + "},{内帧指令" + newLightTask.getFramePayload() + ", 灯杆ID:" + poleIdList.toString() + ", 控制的灯头地址:" + param.getLightAddress() + " }";
        StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "新增路灯任务", content);
        //传入的灯杆id集合
        List<Long> poleIdList = param.getPoleIdList();
        //记录这些灯杆原先的任务
        List<LightTaskPoleRelation> oldLightTaskStatusAndPoles;
        if ("FFFF".equals(param.getLightAddress())) {
@@ -156,7 +162,7 @@
         * 下发路灯任务日志记录开始
         */
        String content1 = "{任务ID:" + newLightTask.getTaskId() + ", 任务名:" + newLightTask.getTaskName() + "}," + " 灯杆ID:" + param.getPoleIdList().toString() + " }";
        String content1 = "{任务ID:" + newLightTask.getTaskId() + ", 任务名:" + newLightTask.getTaskName() + "}," + " 灯杆ID:" + poleIdList.toString() + " }";
        StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "下发路灯任务", content1);
        /**
         * 下发路灯任务日志记录结束
@@ -172,7 +178,7 @@
            lightTaskPoleRelationService.saveBatch(all);
        }
        if (!param.getPoleIdList().isEmpty() && num == newPoleMap.size()) {
        if (!poleIdList.isEmpty() && num == newPoleMap.size()) {
            //所有灯杆都下发失败 新增的任务不保留
            removeById(newLightTask);
            throw new BusinessException("指令下发失败,请检查灯杆状态后重新新增任务");
@@ -217,7 +223,13 @@
        //编辑后灯杆ID集合
        List<Long> poleIdList = param.getPoleIdList();
        List<Long> poleIdList = new ArrayList<>();
        //去重
        for (Long item : param.getPoleIdList()) {
            if (!poleIdList.contains(item)) {
                poleIdList.add(item);
            }
        }
        if (poleIdList.isEmpty()) {
            throw new BusinessException("编辑任务时请选择灯杆");
        }
@@ -225,12 +237,12 @@
        List<LightTaskStatusAndPole> oldLightTaskStatusAndPoles = lightTaskPoleRelationService.listPoleAndStatusIdByTaskId(taskId);
        List<Long> oldList = oldLightTaskStatusAndPoles.stream().map(LightTaskStatusAndPole::getId).collect(Collectors.toList());
        //判断param.getPoleIdList()中是否有旧的灯杆ID    (直接下发)
        List<Long> newPoleIdList = param.getPoleIdList().stream().filter(poleId -> !oldList.contains(poleId)).collect(Collectors.toList());
        //判断param.getPoleIdList()中是否有新的灯杆ID    (覆盖操作)
        List<Long> oldPoleIdList = param.getPoleIdList().stream().filter(poleId -> oldList.contains(poleId)).collect(Collectors.toList());
        //oldList中有的灯杆ID,但是param.getPoleIdList()中没有 (关灯操作)
        List<Long> closeLight = oldList.stream().filter(poleId -> !param.getPoleIdList().contains(poleId)).collect(Collectors.toList());
        //判断poleIdList中是否有旧的灯杆ID    (直接下发)
        List<Long> newPoleIdList = poleIdList.stream().filter(poleId -> !oldList.contains(poleId)).collect(Collectors.toList());
        //判断poleIdList中是否有新的灯杆ID    (覆盖操作)
        List<Long> oldPoleIdList = poleIdList.stream().filter(poleId -> oldList.contains(poleId)).collect(Collectors.toList());
        //oldList中有的灯杆ID,但是poleIdList中没有 (关灯操作)
        List<Long> closeLight = oldList.stream().filter(poleId -> !poleIdList.contains(poleId)).collect(Collectors.toList());
        //取出覆盖操作的关系信息
@@ -317,13 +329,13 @@
         * 编辑路灯任务日志记录开始
         */
        List<String> poleCodeList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(param.getPoleIdList())) {
            List<Pole> poleList = SpringContextHolder.getBean(PoleService.class).listByIds(param.getPoleIdList());
        if (CollectionUtil.isNotEmpty(poleIdList)) {
            List<Pole> poleList = SpringContextHolder.getBean(PoleService.class).listByIds(poleIdList);
            if (CollectionUtil.isNotEmpty(poleList)) {
                poleCodeList = poleList.stream().map(Pole::getDeviceCode).collect(Collectors.toList());
            }
        }
        String content = "{任务ID:" + newLightTask.getTaskId() + ", 任务名:" + newLightTask.getTaskName() + "},{内帧指令" + newLightTask.getFramePayload() + ", 灯杆ID:" + param.getPoleIdList().toString() + ", 控制的灯头地址:" + param.getLightAddress() + " }";
        String content = "{任务ID:" + newLightTask.getTaskId() + ", 任务名:" + newLightTask.getTaskName() + "},{内帧指令" + newLightTask.getFramePayload() + ", 灯杆ID:" + poleIdList.toString() + ", 控制的灯头地址:" + param.getLightAddress() + " }";
        StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "编辑路灯任务", content);
        /**
         * 编辑路灯任务日志记录结束
@@ -348,7 +360,8 @@
        List<LightTaskPoleRelation> all = new ArrayList<>();
        all.addAll(newPoleSuccess);
        all.addAll(oldPoleFail);
        all.addAll(oldPoleSuccess);
//        all.addAll(oldPoleFail);
//        all.addAll(closePoleFail);
@@ -376,7 +389,7 @@
        /**
         * 下发路灯任务日志记录开始
         */
        String content1 = "{任务ID:" + newLightTask.getTaskId() + ", 任务名:" + newLightTask.getTaskName() + "}," + " 灯杆ID:" + param.getPoleIdList().toString() + " }";
        String content1 = "{任务ID:" + newLightTask.getTaskId() + ", 任务名:" + newLightTask.getTaskName() + "}," + " 灯杆ID:" + poleCodeList.toString() + " }";
        StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "下发路灯任务", content1);
        /**
         * 下发路灯任务日志记录结束
@@ -388,7 +401,7 @@
            throw new BusinessException("编辑失败,请检查原有设备和编辑后的设备是否在线!");
        } else if (!closePoleFail.isEmpty() && !newPoleSuccess.isEmpty() && !oldPoleFail.isEmpty()) {
            return "原任务中存在下发异常,原任务保留,创建新任务进行保存";
        } else if (!newPoleFail.isEmpty() && !newPoleSuccess.isEmpty()) {
        } else if (!newPoleFail.isEmpty()) {
            return "新任务中存在下发异常,忽略异常操作的灯杆";
        } else {
            return "操作异常";
@@ -900,4 +913,12 @@
        }
    }
    public boolean clearLightTask(List<Long> poleIds) {
        Map<String, List<LightTaskPoleRelation>> ffff = sendControllerFrame(poleIds, "", "FFFF");
        ffff.get("success").forEach(lightTaskPoleRelation -> {
            lightTaskPoleRelationService.remove(Wrappers.lambdaUpdate(LightTaskPoleRelation.class).eq(LightTaskPoleRelation::getPoleId, lightTaskPoleRelation.getPoleId()).eq(LightTaskPoleRelation::getTaskId, lightTaskPoleRelation.getTaskId()));
        });
        return true;
    }
}