package com.glxp.udi.admin.thread; import cn.hutool.core.collection.CollUtil; import com.glxp.udi.admin.constant.ConstantStatus; import com.glxp.udi.admin.constant.SystemParamConstant; import com.glxp.udi.admin.dao.info.ScheduledDao; import com.glxp.udi.admin.entity.inout.OrderEntity; import com.glxp.udi.admin.entity.param.SystemParamConfigEntity; import com.glxp.udi.admin.req.inout.OrderFilterRequest; import com.glxp.udi.admin.service.inout.OrderService; import com.glxp.udi.admin.service.param.SystemParamConfigService; import com.glxp.udi.admin.service.param.SystemParamCustomerConfigService; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.SchedulingConfigurer; import org.springframework.scheduling.config.ScheduledTaskRegistrar; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.List; @Slf4j @Component @EnableScheduling public class TransInoutTask implements SchedulingConfigurer { @Resource private TransInoutService transInoutService; @Resource private SystemParamConfigService systemParamConfigService; @Resource private SystemParamCustomerConfigService systemParamCustomerConfigService; @Resource private OrderService orderService; @Resource protected ScheduledDao scheduledDao; @Override public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) { /* scheduledTaskRegistrar.addTriggerTask(this::process, triggerContext -> { ScheduledRequest scheduledRequest = new ScheduledRequest(); scheduledRequest.setCronName("transInout"); ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest); String cron = scheduledEntity.getCron(); if (cron.isEmpty()) { log.error("cron is null"); } return new CronTrigger(cron).nextExecutionTime(triggerContext); });*/ } private void process() { SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService.selectByParamKey(SystemParamConstant.IO_TRANSINOUT_INTERVAL); if (!"0".equals(systemParamConfigEntity.getParamValue())) { log.info("定时重码校验"); //查询待处理单据,判断此单据的用户是否开启了自动处理单据,如果已开启则自动处理,未开启跳过 OrderFilterRequest orderFilterRequest = new OrderFilterRequest(); orderFilterRequest.setStatus(ConstantStatus.ORDER_STATUS_WAIT); List list = orderService.findAll(orderFilterRequest); if (CollUtil.isNotEmpty(list)) { for (OrderEntity orderEntity : list) { SystemParamConfigEntity io_transInout_auto = systemParamCustomerConfigService.getParamByKey(SystemParamConstant.IO_TRANSINOUT_AUTO, orderEntity.getCustomerId()); if (null != io_transInout_auto && io_transInout_auto.getParamValue().equals("1")) { //此单可以自动提交 transInoutService.transInout(orderEntity); } } } } } }