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.DateUtils; 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.IMdcEquipmentService; import org.jeecg.modules.mdc.util.CxfClientUtil; import org.jeecg.modules.mdc.util.ThrowableUtil; import org.jeecg.modules.mdc.vo.WsEquipmentEndWork; 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 WebServiceCompletedJob implements Job { /** * url */ @Value("${webservice2.url}") private String url; /** * namespace */ @Value("${webservice2.namespace}") private String namespace; /** * method */ @Value("${webservice2.endWorkMethod}") private String method; @Resource private IQuartzJobService quartzJobService; @Resource private ISysQuartzLogService sysQuartzLogService; @Resource @Lazy private RedisUtil redisUtil; @Resource private IMdcEquipmentService mdcEquipmentService; @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上报完工任务 WebServiceCompletedJob start! 时间:" + DateUtils.now()); 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 = (MdcEquipmentDaySchedule) redisUtil.get("work:" + mdcEquipment.getEquipmentId()); String productName = mdcEquipmentDaySchedule.getProductName(); Map dataProductName = equipmentWorkLineService.getDataProductName(mdcEquipment.getSaveTableName()); if (dataProductName != null && !dataProductName.isEmpty()) { if (dataProductName.containsKey("productname")) { String proName = dataProductName.get("productname") == null ? "" : dataProductName.get("productname").toString(); if (!productName.equals(proName)) { //完工 WsEquipmentEndWork wsEquipmentEndWork = new WsEquipmentEndWork(); wsEquipmentEndWork.setMesId(mdcEquipmentDaySchedule.getMesId()); wsEquipmentEndWork.setWorkshop(mdcEquipmentDaySchedule.getWorkshop()); wsEquipmentEndWork.setProcessProgress("100"); wsEquipmentEndWork.setTaskCode(mdcEquipmentDaySchedule.getTaskCode()); wsEquipmentEndWork.setOpreationSeqNo(mdcEquipmentDaySchedule.getOpreationSeqNo()); wsEquipmentEndWork.setMdsItemCode(mdcEquipmentDaySchedule.getMdsItemCode()); wsEquipmentEndWork.setEquipmentId(mdcEquipment.getEquipmentId()); wsEquipmentEndWork.setProcessNumber(mdcEquipmentDaySchedule.getBatchNum()); Date date = dataProductName.get("collecttime") == null ? null : (Date) dataProductName.get("collecttime"); wsEquipmentEndWork.setEndProcessTime(date); String s = JSONObject.toJSONString(wsEquipmentEndWork); log.info("上报完工数据 ===== " + s); String result = CxfClientUtil.invokeService(url, s, namespace, method); log.info("上报完工结果 ===== " + result); if (result.contains("成功")) { // mdcEquipmentDaySchedule.setProductName(productName); //开工设备删除redis redisUtil.del("work:" + mdcEquipment.getEquipmentId()); } } } } } } } 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); } }