package com.zy.asrs.task; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.core.common.Cools; import com.zy.asrs.entity.LocMast; import com.zy.asrs.entity.WrkMast; import com.zy.asrs.service.LocMastService; import com.zy.asrs.service.WrkMastService; import com.zy.asrs.task.core.ReturnT; import com.zy.asrs.task.handler.AutoEmptyOutHandler; import com.zy.system.entity.Config; import com.zy.system.service.ConfigService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @Slf4j @Component public class AutoEmptyOutScheduler { @Autowired private ConfigService configService; @Autowired private AutoEmptyOutHandler autoEmptyOutHandler; @Autowired private WrkMastService wrkMastService; @Autowired private LocMastService locMastService; //定时空库位预留,空轴出库 @Scheduled(cron = "0/3 * * * * ? ") public void autoEmptyOut() { Config config = configService.selectConfigByCode("AutoEmptyOut"); if (Cools.isEmpty(config) || config.getValue().equals("false")) { return; } ReturnT result = autoEmptyOutHandler.start(); if (!result.isSuccess()) { log.error("自动出空轴失败{}", result.getMsg()); } } @Scheduled(cron = "0/30 * * * * ? ") public void autoLocMove() { Config config = configService.selectConfigByCode("AutoLocMoveToOther"); if (Cools.isEmpty(config) || config.getValue().equals("false")) { return; } Config configMax = configService.selectConfigByCode("moveMax"); Integer max; if (Cools.isEmpty(configMax)) { max = 4; }else{ max = Integer.valueOf(config.getValue()); } try { Integer existCount = wrkMastService.selectCount(new EntityWrapper() .eq("io_type", 101) .eq("log_mk", "Y") .eq("ove_mk", "N")); int allow = max - (existCount == null ? 0 : existCount); if (allow <= 0) { return; } int created = 0; for (int crnNo = 1; crnNo < 5 && created < allow; crnNo++) { Integer emptyLocCount = locMastService.selectCount(new EntityWrapper() .eq("crn_no", crnNo) .eq("loc_sts", "O") .eq("frozen", 0) .eq("deleted", 0) .eq("whs_type", 1)); if (emptyLocCount == null || emptyLocCount >= 50) { continue; } String result = autoEmptyOutHandler.moveMostMatnrInventoryInner(crnNo, 1L); if (!Cools.isEmpty(result)) { created++; log.info("自动移库生成任务: {}", result); } } } catch (Exception e) { log.error("自动移库失败", e); } } }