|
|
@@ -1,23 +1,25 @@
|
|
|
package cn.iocoder.yudao.module.pms.service.inspect;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
-import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.inspect.plan.vo.IotInspectPlanPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.inspect.plan.vo.IotInspectPlanSaveReqVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.inspect.route.vo.IotInspectRouteRespVO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.inspect.IotInspectPlanDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.inspect.IotInspectPlanMapper;
|
|
|
+import cn.iocoder.yudao.module.pms.service.IotDeviceService;
|
|
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
|
|
-import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
|
|
import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
@@ -38,6 +40,9 @@ public class IotInspectPlanServiceImpl implements IotInspectPlanService {
|
|
|
private AdminUserApi adminUserApi;
|
|
|
@Resource
|
|
|
private DeptService deptService;
|
|
|
+ @Autowired
|
|
|
+ private IotDeviceService iotDeviceService;
|
|
|
+
|
|
|
@Override
|
|
|
public void updateInspectPlanStatus(Long id, Integer status) {
|
|
|
IotInspectPlanDO iotInspectPlanDO = iotInspectPlanMapper.selectById(id).setStatus(status);
|
|
|
@@ -103,4 +108,43 @@ public class IotInspectPlanServiceImpl implements IotInspectPlanService {
|
|
|
return iotInspectPlanMapper.selectPage(pageReqVO, ids);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 设备调拨后修改巡检计划
|
|
|
+ * @param deviceIds 多个设备
|
|
|
+ * @param deptId 调拨后部门id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void syncInspectPlanData(List<Long> deviceIds, Long deptId) {
|
|
|
+ deviceIds.forEach(e ->{
|
|
|
+ //设备为瑞恒的话进行该调整
|
|
|
+ String deviceCompany = iotDeviceService.getDeviceCompany(e);
|
|
|
+ if ("rh".equals(deviceCompany)) {
|
|
|
+ String device = "\"deviceId\":"+e;
|
|
|
+ List<IotInspectPlanDO> listByJsonDeviceId = iotInspectPlanMapper.getListByJsonDeviceId(device);
|
|
|
+ //遍历巡检计划
|
|
|
+ AtomicReference<IotInspectRouteRespVO> iotInspectRouteDO = new AtomicReference<>(new IotInspectRouteRespVO());
|
|
|
+ listByJsonDeviceId.forEach(f ->{
|
|
|
+ List<IotInspectRouteRespVO> routeDOS = JSON.parseArray(f.getDeviceIds(), IotInspectRouteRespVO.class);
|
|
|
+ List<IotInspectRouteRespVO> collect = routeDOS.stream().filter(g -> !e.equals(g.getDeviceId())).collect(Collectors.toList());
|
|
|
+ routeDOS.stream().filter(g -> e.equals(g.getDeviceId())).findFirst().ifPresent(iotInspectRouteDO::set);
|
|
|
+ //更新巡检计划的巡检明细
|
|
|
+ f.setDeviceIds(JSON.toJSONString(collect));
|
|
|
+ iotInspectPlanMapper.updateById(f);
|
|
|
+ });
|
|
|
+ //往新的队伍中添加该设备
|
|
|
+ List<IotInspectPlanDO> targetPlan = iotInspectPlanMapper.selectList("dept_id", deptId);
|
|
|
+ if (CollUtil.isNotEmpty(targetPlan)) {
|
|
|
+ IotInspectPlanDO iotInspectPlanDO = targetPlan.get(0);
|
|
|
+ List<IotInspectRouteRespVO> routeDOS = JSON.parseArray(iotInspectPlanDO.getDeviceIds(), IotInspectRouteRespVO.class);
|
|
|
+ if (Objects.nonNull(iotInspectRouteDO.get())){
|
|
|
+ routeDOS.add(iotInspectRouteDO.get());
|
|
|
+ }
|
|
|
+ //更新巡检计划的巡检明细
|
|
|
+ iotInspectPlanDO.setDeviceIds(JSON.toJSONString(routeDOS));
|
|
|
+ iotInspectPlanMapper.updateById(iotInspectPlanDO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
}
|