package com.ld.igds.timer; import com.ld.igds.constant.Constant; import com.ld.igds.io.constant.OrderRespEnum; import com.ld.igds.io.response.PestResponse; import com.ld.igds.models.Depot; import com.ld.igds.models.TimingDepot; import com.ld.igds.pest.dto.PestParam; import com.ld.igds.pest.manager.PestManager; 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_PEST) public class JobPestService implements Job { @Autowired private ITimerService timerService; @Autowired private HDepotService depotService; @Autowired private PestManager pestManager; @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; } PestParam param; PestResponse tempResp; Map mapError = new HashMap(); for (Depot depot : depots) { param = new PestParam(); param.setCompanyId(depot.getCompanyId()); param.setDepotId(depot.getId()); tempResp = pestManager.checkPest(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); } } }