package org.jeecg.modules.mdc.job; import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.util.DateUtils; import org.jeecg.modules.mdc.service.IEquipmentService; import org.jeecg.modules.mdc.util.CxfClientUtil; import org.jeecg.modules.mdc.util.ThrowableUtil; import org.jeecg.modules.mdc.vo.WsEquipmentStatus; 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 javax.annotation.Resource; import java.util.Date; import java.util.List; /** * @author Lius * @date 2024/6/11 11:27 */ @PersistJobDataAfterExecution @DisallowConcurrentExecution @Slf4j public class WebServiceStatusJob implements Job { /** * url */ @Value("${webservice.url}") private String url; /** * namespace */ @Value("${webservice.namespace}") private String namespace; /** * method */ @Value("${webservice.statusMethod}") private String method; @Resource private IQuartzJobService quartzJobService; @Resource private ISysQuartzLogService sysQuartzLogService; @Resource private IEquipmentService equipmentService; @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上报设备状态任务 WebServiceStatusJob start! 时间:" + DateUtils.now()); long startTime = System.currentTimeMillis(); try { List equipmentStatusList = equipmentService.selectEquipmentStatus(); if (equipmentStatusList != null && !equipmentStatusList.isEmpty()) { for (WsEquipmentStatus wsEquipmentStatus : equipmentStatusList) { String s = JSONObject.toJSONString(wsEquipmentStatus); log.info("上报状态数据 ===== " + s); String result = CxfClientUtil.invokeService(url, s, namespace, method); log.info("上报状态结果 ===== " + result); } } 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); } }