|
@@ -0,0 +1,211 @@
|
|
|
+package cn.iocoder.yudao.module.pms.job;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
|
|
+import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
|
|
|
+import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
|
|
|
+import cn.iocoder.yudao.module.pms.constant.PmsConstants;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.inspect.IotInspectPlanDO;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillOrderDO;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotoperationplan.IotOperationPlanDO;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotoperationplandev.IotOperationPlanDevDO;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.iotopeationfill.IotOpeationFillMapper;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.iotopeationfill.IotOpeationFillOrderMapper;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.iotoperationplan.IotOperationPlanMapper;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.iotoperationplandev.IotOperationPlanDevMapper;
|
|
|
+import cn.iocoder.yudao.module.pms.message.PmsMessage;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import static cn.iocoder.yudao.module.pms.framework.config.MultiThreadConfiguration.PMS_THREAD_POOL_TASK_EXECUTOR;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author yc
|
|
|
+ * @version 1.0
|
|
|
+ * @className IotOperationFillTask
|
|
|
+ * @date 2025/5/11 10:26
|
|
|
+ * @description
|
|
|
+ */
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class IotOperationPlanJob implements JobHandler {
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IotOpeationFillMapper iotOpeationFillMapper;
|
|
|
+ @Autowired
|
|
|
+ private IotOpeationFillOrderMapper iotOpeationFillOrderMapper;
|
|
|
+ @Resource
|
|
|
+ private PmsMessage pmsMessage;
|
|
|
+ @Resource(name = PMS_THREAD_POOL_TASK_EXECUTOR)
|
|
|
+ private ThreadPoolTaskExecutor pmsThreadPoolTaskExecutor;
|
|
|
+ @Resource
|
|
|
+ private IotOperationPlanMapper planMapper;
|
|
|
+ @Resource
|
|
|
+ private IotOperationPlanDevMapper planDevMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 1、查询开启状态运行计划
|
|
|
+ * 2、根据计划获取设备
|
|
|
+ * 3、根据设备ID查询设备责任人表,获取user_id
|
|
|
+ * 4、根据user_id生成工单主表数据
|
|
|
+ * 5、生成设备子表数据
|
|
|
+ * 6、根据计划周期确认工单生成时间
|
|
|
+ */
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String execute(String param) throws Exception {
|
|
|
+ TenantContextHolder.setIgnore(true);
|
|
|
+ System.out.println("***********创建运行记录填报工单开始执行*********8");
|
|
|
+
|
|
|
+
|
|
|
+ //1、查询开启,非删除状态运行计划
|
|
|
+ List<IotOperationPlanDO> planList = planMapper.getPlanList();
|
|
|
+
|
|
|
+ if(planList.size()>0){
|
|
|
+ List<Long> planIds= planList.stream().map(IotOperationPlanDO::getId).collect(Collectors.toList());
|
|
|
+ //2、根据计划获取设备ID
|
|
|
+ List<IotOperationPlanDevDO> devList = planDevMapper.devIdList(planIds);
|
|
|
+ List<Long> devIdList= devList.stream().map(IotOperationPlanDevDO::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);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for (IotOperationPlanDO planDO:planList) {
|
|
|
+ if (planDO.getLastCreateTime()==null&& Objects.nonNull(planDO.getBeginCreateTime())) {
|
|
|
+ //当首次执行时间大于当前时间
|
|
|
+ if (planDO.getBeginCreateTime().isBefore(LocalDateTime.now())) {
|
|
|
+ Date date = Date.from(
|
|
|
+ planDO.getBeginCreateTime().atZone(ZoneId.systemDefault()) // 使用系统默认时区
|
|
|
+ .toInstant() // 转为 Instant(时间戳)
|
|
|
+ );
|
|
|
+ deal(planDO, date,devIdList,orderList);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Date lastdate = Date.from(
|
|
|
+ planDO.getLastCreateTime().atZone(ZoneId.systemDefault()) // 使用系统默认时区
|
|
|
+ .toInstant() // 转为 Instant(时间戳)
|
|
|
+ );
|
|
|
+ deal(planDO, lastdate,devIdList,orderList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return "创建成功";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void deal(IotOperationPlanDO plan, Date date,List<Long> devIdList, List<IotOpeationFillOrderDO> orderList) {
|
|
|
+ Date date1 = new Date();
|
|
|
+ if ("hour".equals(plan.getPlanUnit())){
|
|
|
+ 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);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void extracted(List<Long> devIdList, List<IotOpeationFillOrderDO> orderList,IotOperationPlanDO plan) {
|
|
|
+ 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);
|
|
|
+
|
|
|
+
|
|
|
+ /*//发送钉钉通知
|
|
|
+ pmsThreadPoolTaskExecutor.execute(()->{
|
|
|
+ try{
|
|
|
+ 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) {
|
|
|
+ System.out.println("deviceUser"+device.getUserId());
|
|
|
+ for (IotOpeationFillOrderDO order:orderList1) {
|
|
|
+ System.out.println("orderId"+order.getUserId());
|
|
|
+ if(device.getUserId().intValue()==order.getUserId().intValue()){
|
|
|
+ System.out.println("-----相等-------");
|
|
|
+ device.setOrderId(order.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ System.out.println("***********创建运行记录填报工单执行结束*********8");
|
|
|
+
|
|
|
+
|
|
|
+ System.out.println("*****************插入运行记录设备表***********************");
|
|
|
+
|
|
|
+ for (IotOpeationFillDO re:deviceList) {
|
|
|
+ re.setDeviceId(re.getId());
|
|
|
+ }
|
|
|
+ iotOpeationFillMapper.insertFill(deviceList);
|
|
|
+
|
|
|
+
|
|
|
+ System.out.println("*****************插入运行记录设备表完成***********************");
|
|
|
+ }
|
|
|
+
|
|
|
+}
|