package org.jeecg.modules.mdc.job; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.util.RedisUtil; import org.jeecg.modules.mdc.entity.MdcEquipment; import org.jeecg.modules.mdc.entity.MdcEquipmentDaySchedule; import org.jeecg.modules.mdc.service.IEquipmentWorkLineService; import org.jeecg.modules.mdc.service.IMdcEquipmentDayScheduleService; import org.jeecg.modules.mdc.service.IMdcEquipmentService; import org.jeecg.modules.mdc.util.CxfClientUtil; import org.jeecg.modules.mdc.util.DateUtils; import org.jeecg.modules.mdc.util.ThrowableUtil; import org.jeecg.modules.mdc.vo.WsEquipmentStartWork; import org.jeecg.modules.quartz.entity.QuartzJob; import org.jeecg.modules.quartz.entity.SysQuartzLog; import org.jeecg.modules.quartz.service.IQuartzJobService; import org.jeecg.modules.quartz.service.ISysQuartzLogService; import org.quartz.*; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Lazy; import javax.annotation.Resource; import java.util.Date; import java.util.List; import java.util.Map; /** * @Author: Lius * @CreateTime: 2025-04-29 * @Description: 开工任务 */ @PersistJobDataAfterExecution @DisallowConcurrentExecution @Slf4j public class WebServiceStartWorkJob implements Job { /** * url */ @Value("${webservice2.url}") private String url; /** * namespace */ @Value("${webservice2.namespace}") private String namespace; /** * method */ @Value("${webservice2.startWorkMethod}") private String method; @Resource private IQuartzJobService quartzJobService; @Resource private ISysQuartzLogService sysQuartzLogService; @Resource private IMdcEquipmentDayScheduleService mdcEquipmentDayScheduleService; @Resource private IMdcEquipmentService mdcEquipmentService; @Resource @Lazy private RedisUtil redisUtil; @Resource private IEquipmentWorkLineService equipmentWorkLineService; @Override public void execute(JobExecutionContext context) throws JobExecutionException { SysQuartzLog quartzLog = new SysQuartzLog(); quartzLog.setCreateTime(new Date()); List byJobClassName = this.quartzJobService.findByJobClassName(this.getClass().getName()); if (byJobClassName != null && !byJobClassName.isEmpty()) { quartzLog.setJobId(byJobClassName.get(0).getId()); } log.info("WebService上报开工任务 WebServiceStartWorkJob start! 时间:" + DateUtils.getNow()); long startTime = System.currentTimeMillis(); try { List mdcEquipmentList = mdcEquipmentService.list(new LambdaQueryWrapper().eq(MdcEquipment::getDriveType, "FANUC")); if (mdcEquipmentList != null && !mdcEquipmentList.isEmpty()) { for (MdcEquipment mdcEquipment : mdcEquipmentList) { if (!redisUtil.hasKey("work:" + mdcEquipment.getEquipmentId())) { MdcEquipmentDaySchedule mdcEquipmentDaySchedule = mdcEquipmentDayScheduleService.selectLast(mdcEquipment.getEquipmentId()); if (mdcEquipmentDaySchedule != null) { //查询设备单表零件号 Map dataList = equipmentWorkLineService.getDataProductName(mdcEquipment.getSaveTableName()); if (dataList != null) { if (dataList.containsKey("productname")) { String productName = dataList.get("productname") == null ? "" : dataList.get("productname").toString(); if (productName.contains(mdcEquipmentDaySchedule.getMdsItemCode())) { log.info("验证自动开工开始,设备编号为 ====== " + mdcEquipment.getEquipmentId()); WsEquipmentStartWork wsEquipmentStartWork = new WsEquipmentStartWork(); wsEquipmentStartWork.setMesId(mdcEquipmentDaySchedule.getMesId()); wsEquipmentStartWork.setEquipmentId(mdcEquipmentDaySchedule.getEquipmentId()); wsEquipmentStartWork.setWorkshop(mdcEquipmentDaySchedule.getWorkshop()); wsEquipmentStartWork.setTaskCode(mdcEquipmentDaySchedule.getTaskCode()); wsEquipmentStartWork.setOpreationSeqNo(mdcEquipmentDaySchedule.getOpreationSeqNo()); //获取开工时间 Date date = dataList.get("collecttime") == null ? null : (Date) dataList.get("collecttime"); wsEquipmentStartWork.setStartProcessTime(date); String s = JSONObject.toJSONString(wsEquipmentStartWork); log.info("上报开工数据 ===== " + s); String result = CxfClientUtil.invokeService(url, s, namespace, method); log.info("上报开工结果 ===== " + result); if (result.contains("成功")) { mdcEquipmentDaySchedule.setProductName(productName); //开工设备存入redis redisUtil.set("work:" + mdcEquipment.getEquipmentId(), mdcEquipmentDaySchedule); } return; } } } } } } } quartzLog.setIsSuccess(0); } catch (Exception e) { quartzLog.setIsSuccess(-1); quartzLog.setExceptionDetail(ThrowableUtil.getStackTrace(e)); } long endTime = System.currentTimeMillis(); quartzLog.setExecutionTime(Integer.parseInt(String.valueOf(endTime - startTime))); sysQuartzLogService.save(quartzLog); } }