|
@@ -81,15 +81,9 @@ public class IotOperationPlanJob implements JobHandler {
|
|
|
@Override
|
|
|
public String execute(String param) throws Exception {
|
|
|
TenantContextHolder.setIgnore(true);
|
|
|
-
|
|
|
-
|
|
|
//1、查询开启,非删除状态运行计划
|
|
|
List<IotOperationPlanDO> planList = planMapper.getPlanList();
|
|
|
-
|
|
|
if(planList.size()>0){
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
for (IotOperationPlanDO planDO:planList) {
|
|
|
if (planDO.getLastCreateTime()==null&& Objects.nonNull(planDO.getBeginCreateTime())) {
|
|
|
//当首次执行时间大于当前时间
|
|
@@ -98,97 +92,48 @@ public class IotOperationPlanJob implements JobHandler {
|
|
|
planDO.getBeginCreateTime().atZone(ZoneId.systemDefault()) // 使用系统默认时区
|
|
|
.toInstant() // 转为 Instant(时间戳)
|
|
|
);
|
|
|
-
|
|
|
-
|
|
|
- Set<Long> idList = new HashSet<>();
|
|
|
- if(Objects.nonNull(planDO.getDeptId())){
|
|
|
- idList = deptService.getChildDeptIdListFromCache(planDO.getDeptId());
|
|
|
- idList.add(planDO.getDeptId());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- //2、根据计划获取设备ID
|
|
|
- List<IotDeviceRespVO> devList = iotOpeationFillMapper.getFillDevices2(idList);
|
|
|
-
|
|
|
- if(devList.size()>0){
|
|
|
- List<Long> devIdList= devList.stream().map(IotDeviceRespVO::getId).collect(Collectors.toList());
|
|
|
- //3、根据设备ID生成主表数据
|
|
|
- List<IotOpeationFillOrderDO> orderList = new ArrayList<>();
|
|
|
- List<IotOpeationFillDO> pdList = iotOpeationFillMapper.pdList(devIdList);
|
|
|
-
|
|
|
- for (IotOpeationFillDO pd:pdList) {
|
|
|
-
|
|
|
- IotOpeationFillOrderDO fillDO = new IotOpeationFillOrderDO();
|
|
|
-
|
|
|
- fillDO.setOrderName(pd.getOrgName()+"/"+LocalDate.now()+"运行记录填报");
|
|
|
- fillDO.setDeptId(pd.getDeptId());
|
|
|
- fillDO.setOrderStatus(0);
|
|
|
- fillDO.setCreateTime(LocalDateTime.now());
|
|
|
- fillDO.setUserName(pd.getUserName());
|
|
|
- fillDO.setUserId(pd.getUserId());
|
|
|
- fillDO.setMobile(pd.getMobile());
|
|
|
- orderList.add(fillDO);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- deal(planDO, date,devIdList,orderList);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
+ extractedOrder(planDO, date);
|
|
|
}
|
|
|
} else {
|
|
|
Date lastdate = Date.from(
|
|
|
planDO.getLastCreateTime().atZone(ZoneId.systemDefault()) // 使用系统默认时区
|
|
|
.toInstant() // 转为 Instant(时间戳)
|
|
|
);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- Set<Long> idList = new HashSet<>();
|
|
|
- if(Objects.nonNull(planDO.getDeptId())){
|
|
|
- idList = deptService.getChildDeptIdListFromCache(planDO.getDeptId());
|
|
|
- idList.add(planDO.getDeptId());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- //2、根据计划获取设备ID
|
|
|
- List<IotDeviceRespVO> devList = iotOpeationFillMapper.getFillDevices2(idList);
|
|
|
- if(devList.size()>0){
|
|
|
- List<Long> devIdList= devList.stream().map(IotDeviceRespVO::getId).collect(Collectors.toList());
|
|
|
- //3、根据设备ID生成主表数据
|
|
|
- List<IotOpeationFillOrderDO> orderList = new ArrayList<>();
|
|
|
- List<IotOpeationFillDO> pdList = iotOpeationFillMapper.pdList(devIdList);
|
|
|
-
|
|
|
- for (IotOpeationFillDO pd:pdList) {
|
|
|
-
|
|
|
- IotOpeationFillOrderDO fillDO = new IotOpeationFillOrderDO();
|
|
|
-
|
|
|
- fillDO.setOrderName(pd.getOrgName()+"/"+LocalDate.now()+"运行记录填报");
|
|
|
- fillDO.setDeptId(pd.getDeptId());
|
|
|
- fillDO.setOrderStatus(0);
|
|
|
- fillDO.setCreateTime(LocalDateTime.now());
|
|
|
- fillDO.setUserName(pd.getUserName());
|
|
|
- fillDO.setUserId(pd.getUserId());
|
|
|
- fillDO.setMobile(pd.getMobile());
|
|
|
- orderList.add(fillDO);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- deal(planDO, lastdate,devIdList,orderList);
|
|
|
- }
|
|
|
-
|
|
|
+ extractedOrder(planDO, lastdate);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
return "创建成功";
|
|
|
}
|
|
|
|
|
|
+ private void extractedOrder(IotOperationPlanDO planDO, Date date) {
|
|
|
+ Set<Long> idList = new HashSet<>();
|
|
|
+ if(Objects.nonNull(planDO.getDeptId())){
|
|
|
+ idList = deptService.getChildDeptIdListFromCache(planDO.getDeptId());
|
|
|
+ idList.add(planDO.getDeptId());
|
|
|
+ }
|
|
|
+ //2、根据计划获取设备ID
|
|
|
+ List<IotDeviceRespVO> devList = iotOpeationFillMapper.getFillDevices2(idList);
|
|
|
+ if(devList.size()>0){
|
|
|
+ List<Long> devIdList= devList.stream().map(IotDeviceRespVO::getId).collect(Collectors.toList());
|
|
|
+ //3、根据设备ID生成主表数据
|
|
|
+ List<IotOpeationFillOrderDO> orderList = new ArrayList<>();
|
|
|
+ List<IotOpeationFillDO> pdList = iotOpeationFillMapper.pdList(devIdList);
|
|
|
+ for (IotOpeationFillDO pd:pdList) {
|
|
|
+ IotOpeationFillOrderDO fillDO = new IotOpeationFillOrderDO();
|
|
|
+ fillDO.setOrderName(pd.getOrgName()+"/"+ LocalDate.now()+"运行记录填报");
|
|
|
+ fillDO.setDeptId(pd.getDeptId());
|
|
|
+ fillDO.setOrderStatus(0);
|
|
|
+ fillDO.setCreateTime(LocalDateTime.now());
|
|
|
+ fillDO.setUserName(pd.getUserName());
|
|
|
+ fillDO.setUserId(pd.getUserId());
|
|
|
+ fillDO.setMobile(pd.getMobile());
|
|
|
+ orderList.add(fillDO);
|
|
|
+ }
|
|
|
+ deal(planDO, date,devIdList,orderList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
private void deal(IotOperationPlanDO plan, Date date,List<Long> devIdList, List<IotOpeationFillOrderDO> orderList) {
|
|
|
Date date1 = new Date();
|
|
@@ -196,19 +141,16 @@ public class IotOperationPlanJob implements JobHandler {
|
|
|
DateTime dateTime = DateUtil.offsetHour(date, Integer.parseInt(StringUtils.substringBeforeLast(String.valueOf(plan.getPlanCycle()),".")));
|
|
|
if (date1.compareTo(dateTime) > 0){
|
|
|
extracted(devIdList, orderList,plan);
|
|
|
-
|
|
|
}
|
|
|
} else if ("day".equals(plan.getPlanUnit())){
|
|
|
DateTime dateTime = DateUtil.offsetDay(date, Integer.parseInt(StringUtils.substringBeforeLast(String.valueOf(plan.getPlanCycle()),".")));
|
|
|
if (date1.compareTo(dateTime) > 0){
|
|
|
extracted(devIdList, orderList,plan);
|
|
|
-
|
|
|
}
|
|
|
} else if ("month".equals(plan.getPlanUnit())){
|
|
|
DateTime dateTime = DateUtil.offsetMonth(date, Integer.parseInt(StringUtils.substringBeforeLast(String.valueOf(plan.getPlanCycle()),".")));
|
|
|
if (date1.compareTo(dateTime) > 0){
|
|
|
extracted(devIdList, orderList,plan);
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -219,44 +161,27 @@ public class IotOperationPlanJob implements JobHandler {
|
|
|
LocalDateTime localDateTime = DateUtils.contactTime(plan.getBeginCreateTime());
|
|
|
plan.setLastCreateTime(localDateTime);
|
|
|
planMapper.updateById(plan);
|
|
|
-
|
|
|
//4、根据设备ID生成子表数据
|
|
|
List<IotOpeationFillDO> deviceList = iotOpeationFillMapper.getFillDevices(devIdList);
|
|
|
-
|
|
|
List<Integer> idList = deviceList.stream().map(IotOpeationFillDO::getUserId).collect(Collectors.toList());
|
|
|
-
|
|
|
-
|
|
|
List<IotOpeationFillOrderDO> orderList1 = orderList.stream()
|
|
|
.filter(obj -> idList.contains(obj.getUserId()))
|
|
|
.collect(Collectors.toList());
|
|
|
-
|
|
|
-
|
|
|
//插入工单主表
|
|
|
iotOpeationFillOrderMapper.insertBatch(orderList1);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
Set<Long> rdIdList = new HashSet<>();
|
|
|
rdIdList = deptService.getChildDeptIdListFromCache(163L);
|
|
|
rdIdList.add(163L);
|
|
|
-
|
|
|
Set<Long> rhIdList = new HashSet<>();
|
|
|
rhIdList = deptService.getChildDeptIdListFromCache(157L);
|
|
|
rhIdList.add(157L);
|
|
|
-
|
|
|
-
|
|
|
boolean exist = rdIdList.contains(plan.getDeptId());
|
|
|
-
|
|
|
if(!exist){
|
|
|
-
|
|
|
-
|
|
|
//瑞鹰SCP项目部50010队伍临时创建
|
|
|
if(plan.getDeptId()==292){
|
|
|
//筛选日报工单
|
|
|
List<IotOpeationFillOrderDO> virOrderList = new ArrayList<>();
|
|
|
-
|
|
|
IotOpeationFillOrderDO fillDO = new IotOpeationFillOrderDO();
|
|
|
-
|
|
|
fillDO.setOrderName("40006队"+"/"+LocalDate.now()+"运行记录填报");
|
|
|
fillDO.setDeptId(322L);
|
|
|
fillDO.setOrderStatus(0);
|
|
@@ -265,112 +190,111 @@ public class IotOperationPlanJob implements JobHandler {
|
|
|
fillDO.setUserId(486);
|
|
|
fillDO.setMobile(String.valueOf(17723897643L));
|
|
|
virOrderList.add(fillDO);
|
|
|
-
|
|
|
orderList1.addAll(virOrderList);
|
|
|
iotOpeationFillOrderMapper.insertBatch(virOrderList);
|
|
|
//创建日报设备
|
|
|
List <IotOpeationFillDO> devList = opeationFillService.reportMethod(virOrderList);
|
|
|
//插入日报设备
|
|
|
iotOpeationFillMapper.insertFill(devList);
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
boolean rhContain = rhIdList.contains(plan.getDeptId());
|
|
|
-
|
|
|
- if(rhContain){
|
|
|
-
|
|
|
- //创建日报设备
|
|
|
- List <IotOpeationFillDO> devList = opeationFillService.reportMethod(orderList1);
|
|
|
- //插入日报设备
|
|
|
- iotOpeationFillMapper.insertFill(devList);
|
|
|
-
|
|
|
- //2、瑞恒无指定队伍全部队伍插入日报设备
|
|
|
- //筛选正常工单部门id
|
|
|
- List<Long> deptIdList = orderList1.stream().map(IotOpeationFillOrderDO::getDeptId).collect(Collectors.toList());
|
|
|
- //查询瑞恒所有责任人数据
|
|
|
- Set<Long> pIdList = new HashSet<>();
|
|
|
- pIdList = deptService.getChildDeptIdListFromCache(plan.getDeptId());
|
|
|
- pIdList.add(plan.getDeptId());
|
|
|
- List<IotOpeationFillDO> rhPdList = iotOpeationFillMapper.pdListRh(pIdList);
|
|
|
- //筛选与正常工单不同部门的责任人数据
|
|
|
- List<IotOpeationFillDO> verRPList = rhPdList.stream().filter(e->!deptIdList.contains(e.getDeptId())).collect(Collectors.toList());
|
|
|
- //筛选小队责任人数据
|
|
|
- // 使用迭代器遍历集合
|
|
|
- Iterator<IotOpeationFillDO> iterator = verRPList.iterator();
|
|
|
- while (iterator.hasNext()) {
|
|
|
- IotOpeationFillDO rp = iterator.next();
|
|
|
- IotOpeationFillOrderDO rpOrder = new IotOpeationFillOrderDO();
|
|
|
- rpOrder.setDeptId(rp.getDeptId());
|
|
|
- List<IotOpeationFillOrderDO> childList = iotOpeationFillMapper.childList(rpOrder);
|
|
|
-
|
|
|
- // 当childList有元素时,通过迭代器删除当前元素
|
|
|
- if (childList.size() > 0) {
|
|
|
- iterator.remove(); // 使用迭代器的remove方法安全删除
|
|
|
- }
|
|
|
- }
|
|
|
- //创建虚拟工单
|
|
|
- if(verRPList.size()>0){
|
|
|
- for (IotOpeationFillDO vir:verRPList) {
|
|
|
- IotRhDailyReportSaveReqVO saveReqVO = new IotRhDailyReportSaveReqVO();
|
|
|
- //查询队伍增压机状态
|
|
|
- IotDeviceDO virDev = new IotDeviceDO();
|
|
|
- virDev.setDeptId(vir.getDeptId());
|
|
|
- IotDeviceDO devStatus = iotOpeationFillMapper.devStatus(virDev);
|
|
|
- //不为空则为日报赋值
|
|
|
- if(devStatus!=null){
|
|
|
- saveReqVO.setConstructionStatus(devStatus.getDeviceStatus());
|
|
|
- }
|
|
|
- //当日注气量
|
|
|
- saveReqVO.setDailyGasInjection(BigDecimal.valueOf(0.00));
|
|
|
- //当日注水量
|
|
|
- saveReqVO.setDailyWaterInjection(BigDecimal.valueOf(0.00));
|
|
|
- //当日注气时间
|
|
|
- saveReqVO.setDailyInjectGasTime(BigDecimal.valueOf(0.00));
|
|
|
- //当日注水时间
|
|
|
- saveReqVO.setDailyInjectWaterTime(BigDecimal.valueOf(0.00));
|
|
|
- //当日用电量
|
|
|
- saveReqVO.setDailyPowerUsage(BigDecimal.valueOf(0.00));
|
|
|
- //非生产时间
|
|
|
- saveReqVO.setNonProductionTime(BigDecimal.valueOf(0.00));
|
|
|
- saveReqVO.setDeptId(vir.getDeptId());
|
|
|
- saveReqVO.setFillOrderCreateTime(LocalDateTime.now());
|
|
|
- iotRhDailyReportService.createIotRhDailyReport(saveReqVO);
|
|
|
- }
|
|
|
+ //瑞恒日报插入
|
|
|
+ rhReportInsert(plan, orderList1, rhContain);
|
|
|
+ }
|
|
|
+ //发送钉钉消息
|
|
|
+ sendDingMessage(orderList1);
|
|
|
+ //正常工单设备
|
|
|
+ for (IotOpeationFillDO device:deviceList) {
|
|
|
+ for (IotOpeationFillOrderDO order:orderList1) {
|
|
|
+ if(device.getUserId().intValue()==order.getUserId().intValue()){
|
|
|
+ device.setOrderId(order.getId());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ //插入子表
|
|
|
+ for (IotOpeationFillDO re:deviceList) {
|
|
|
+ re.setDeviceId(re.getId());
|
|
|
+ }
|
|
|
+ iotOpeationFillMapper.insertFill(deviceList);
|
|
|
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+ private void sendDingMessage(List<IotOpeationFillOrderDO> orderList1) {
|
|
|
//发送钉钉通知
|
|
|
pmsThreadPoolTaskExecutor.execute(()->{
|
|
|
try{
|
|
|
- for (IotOpeationFillOrderDO order:orderList1) {
|
|
|
+ for (IotOpeationFillOrderDO order: orderList1) {
|
|
|
pmsMessage.sendMessage(order.getId(), order.getOrderName(), PmsConstants.GENERATE_OPERATION, (long)order.getUserId(), order.getMobile());
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
});
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- //正常工单设备
|
|
|
- for (IotOpeationFillDO device:deviceList) {
|
|
|
- for (IotOpeationFillOrderDO order:orderList1) {
|
|
|
- if(device.getUserId().intValue()==order.getUserId().intValue()){
|
|
|
- device.setOrderId(order.getId());
|
|
|
+ private void rhReportInsert(IotOperationPlanDO plan, List<IotOpeationFillOrderDO> orderList1, boolean rhContain) {
|
|
|
+ if(rhContain){
|
|
|
+
|
|
|
+ //创建日报设备
|
|
|
+ List <IotOpeationFillDO> devList = opeationFillService.reportMethod(orderList1);
|
|
|
+ //插入日报设备
|
|
|
+ iotOpeationFillMapper.insertFill(devList);
|
|
|
+
|
|
|
+ //2、瑞恒无指定队伍全部队伍插入日报设备
|
|
|
+ //筛选正常工单部门id
|
|
|
+ List<Long> deptIdList = orderList1.stream().map(IotOpeationFillOrderDO::getDeptId).collect(Collectors.toList());
|
|
|
+ //查询瑞恒所有责任人数据
|
|
|
+ Set<Long> pIdList = new HashSet<>();
|
|
|
+ pIdList = deptService.getChildDeptIdListFromCache(plan.getDeptId());
|
|
|
+ pIdList.add(plan.getDeptId());
|
|
|
+ List<IotOpeationFillDO> rhPdList = iotOpeationFillMapper.pdListRh(pIdList);
|
|
|
+ //筛选与正常工单不同部门的责任人数据
|
|
|
+ List<IotOpeationFillDO> verRPList = rhPdList.stream().filter(e->!deptIdList.contains(e.getDeptId())).collect(Collectors.toList());
|
|
|
+ //筛选小队责任人数据
|
|
|
+ // 使用迭代器遍历集合
|
|
|
+ Iterator<IotOpeationFillDO> iterator = verRPList.iterator();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ IotOpeationFillDO rp = iterator.next();
|
|
|
+ IotOpeationFillOrderDO rpOrder = new IotOpeationFillOrderDO();
|
|
|
+ rpOrder.setDeptId(rp.getDeptId());
|
|
|
+ List<IotOpeationFillOrderDO> childList = iotOpeationFillMapper.childList(rpOrder);
|
|
|
+
|
|
|
+ // 当childList有元素时,通过迭代器删除当前元素
|
|
|
+ if (childList.size() > 0) {
|
|
|
+ iterator.remove(); // 使用迭代器的remove方法安全删除
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //创建虚拟工单
|
|
|
+ if(verRPList.size()>0){
|
|
|
+ for (IotOpeationFillDO vir:verRPList) {
|
|
|
+ IotRhDailyReportSaveReqVO saveReqVO = new IotRhDailyReportSaveReqVO();
|
|
|
+ //查询队伍增压机状态
|
|
|
+ IotDeviceDO virDev = new IotDeviceDO();
|
|
|
+ virDev.setDeptId(vir.getDeptId());
|
|
|
+ IotDeviceDO devStatus = iotOpeationFillMapper.devStatus(virDev);
|
|
|
+ //不为空则为日报赋值
|
|
|
+ if(devStatus!=null){
|
|
|
+ saveReqVO.setConstructionStatus(devStatus.getDeviceStatus());
|
|
|
+ }
|
|
|
+ //当日注气量
|
|
|
+ saveReqVO.setDailyGasInjection(BigDecimal.valueOf(0.00));
|
|
|
+ //当日注水量
|
|
|
+ saveReqVO.setDailyWaterInjection(BigDecimal.valueOf(0.00));
|
|
|
+ //当日注气时间
|
|
|
+ saveReqVO.setDailyInjectGasTime(BigDecimal.valueOf(0.00));
|
|
|
+ //当日注水时间
|
|
|
+ saveReqVO.setDailyInjectWaterTime(BigDecimal.valueOf(0.00));
|
|
|
+ //当日用电量
|
|
|
+ saveReqVO.setDailyPowerUsage(BigDecimal.valueOf(0.00));
|
|
|
+ //非生产时间
|
|
|
+ saveReqVO.setNonProductionTime(BigDecimal.valueOf(0.00));
|
|
|
+ saveReqVO.setDeptId(vir.getDeptId());
|
|
|
+ saveReqVO.setFillOrderCreateTime(LocalDateTime.now());
|
|
|
+ iotRhDailyReportService.createIotRhDailyReport(saveReqVO);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- //插入子表
|
|
|
- for (IotOpeationFillDO re:deviceList) {
|
|
|
- re.setDeviceId(re.getId());
|
|
|
- }
|
|
|
- iotOpeationFillMapper.insertFill(deviceList);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
}
|