package com.ld.igds.timer; import com.ld.igds.constant.Constant; import com.ld.igds.gas.dto.GasParam; import com.ld.igds.gas.manager.GasManager; import com.ld.igds.io.constant.OrderRespEnum; import com.ld.igds.io.response.GasResponse; import com.ld.igds.models.Depot; import com.ld.igds.models.TimingDepot; import com.ld.igds.timer.service.ITimerService; import com.ld.igds.view.service.HDepotService; import lombok.extern.slf4j.Slf4j; import org.quartz.Job; import org.quartz.JobExecutionContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 气体定时检测 */ @Slf4j @Service(Constant.JOB_BEAN_GAS) public class JobGasService implements Job { @Autowired private ITimerService timerService; @Autowired private HDepotService depotService; @Autowired private GasManager gasManager; @Override public void execute(JobExecutionContext context) { log.info("=======================开始执行定时气体检测============================="); try { // 获取JOB的ID String key = context.getTrigger().getKey().getName(); String jobId = key.substring(7); //根据当前JOB获取设备列表 List list = timerService.getDepotByTimerId(jobId); if (null == list || list.isEmpty()) { log.info(context.getJobDetail().getDescription() + "该方案下没有配置需要执行的仓库,定时检测失败……"); return; } // 获取到需要操作的仓库列表 List depots = depotService.getDepotByTimer(list); if (null == depots || depots.isEmpty()) { log.info(context.getJobDetail().getDescription() + "该方案下没有获取到仓库信息,定时检测失败……"); return; } GasParam param; GasResponse tempResp; Map mapError = new HashMap(); for (Depot depot : depots) { param = new GasParam(); param.setCompanyId(depot.getCompanyId()); param.setDepotId(depot.getId()); tempResp = gasManager.checkGas(param); if (!OrderRespEnum.ORDER_SUCCESS.getCode().equals( tempResp.getCode())) { mapError.put(depot.getName(), tempResp.getMsg()); } Thread.sleep(3 * 1000); } if (mapError.isEmpty()) { log.info("气体定时检测命令发送成功,请等待终端响应……"); } else { String errorMsg = ""; for (String str : mapError.keySet()) { errorMsg = "仓库:" + str + "采集失败,异常:" + mapError.get(str); log.error("气体定时检测-" + errorMsg); } } } catch (Exception e) { log.error("定时气体采集异常:{}", e); } } }