|
|
|
package com.glxp.api.task;
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
import cn.hutool.core.thread.ThreadUtil;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
import com.glxp.api.dao.basic.SysWorkplaceDocumentDao;
|
|
|
|
import com.glxp.api.dao.schedule.ScheduledDao;
|
|
|
|
import com.glxp.api.entity.collect.IoCollectSet;
|
|
|
|
import com.glxp.api.entity.inv.InvProductRationEntity;
|
|
|
|
import com.glxp.api.entity.system.ScheduledEntity;
|
|
|
|
import com.glxp.api.entity.system.SystemParamConfigEntity;
|
|
|
|
import com.glxp.api.req.basic.WorkBindBusTypeRequest;
|
|
|
|
import com.glxp.api.req.collect.CollectOrderRequest;
|
|
|
|
import com.glxp.api.req.system.ScheduledRequest;
|
|
|
|
import com.glxp.api.req.system.SysParamConfigSaveRequest;
|
|
|
|
import com.glxp.api.res.basic.SysWorkplaceDocumentResponse;
|
|
|
|
import com.glxp.api.service.collect.IoCollectOriginService;
|
|
|
|
import com.glxp.api.service.collect.IoCollectSetService;
|
|
|
|
import com.glxp.api.service.inv.InvProductRationService;
|
|
|
|
import com.glxp.api.service.system.SystemParamConfigService;
|
|
|
|
import com.glxp.api.util.MsDateUtil;
|
|
|
|
import com.glxp.api.util.StringUtils;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
|
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
|
|
|
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
|
|
|
import org.springframework.scheduling.support.CronTrigger;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
@Component
|
|
|
|
@EnableScheduling
|
|
|
|
public class AsyncIoCollectOrderDownloadTask implements SchedulingConfigurer {
|
|
|
|
|
|
|
|
final Logger logger = LoggerFactory.getLogger(AsyncIoCollectOrderDownloadTask.class);
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
private ScheduledDao scheduledDao;
|
|
|
|
@Resource
|
|
|
|
SysWorkplaceDocumentDao sysWorkplaceDocumentDao;
|
|
|
|
@Resource
|
|
|
|
IoCollectOriginService collectOriginService;
|
|
|
|
@Resource
|
|
|
|
IoCollectSetService collectSetService;
|
|
|
|
@Override
|
|
|
|
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
|
|
|
|
scheduledTaskRegistrar.addTriggerTask(() -> process(),
|
|
|
|
triggerContext -> {
|
|
|
|
ScheduledRequest scheduledRequest = new ScheduledRequest();
|
|
|
|
scheduledRequest.setCronName("ioCollectOrderDownloadTask");
|
|
|
|
ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest);
|
|
|
|
String cron = scheduledEntity != null ? scheduledEntity.getCron() : "0 */10 * * * ?";
|
|
|
|
if (cron.isEmpty()) {
|
|
|
|
logger.error("cron is null");
|
|
|
|
}
|
|
|
|
return new CronTrigger(cron).nextExecutionTime(triggerContext);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void process() {
|
|
|
|
ThreadUtil.execAsync(() -> {
|
|
|
|
//获取下载的起始时间
|
|
|
|
IoCollectSet ioCollectSet = collectSetService.getSet();
|
|
|
|
Date startDownloadTime = ioCollectSet.getStartDownloadTime();
|
|
|
|
String startDownloadTimes = MsDateUtil.formatDateTime(startDownloadTime);
|
|
|
|
Boolean autoDownload = ioCollectSet.getAutoDownload();
|
|
|
|
|
|
|
|
if (StrUtil.isNotBlank(startDownloadTimes) && autoDownload){
|
|
|
|
//获取当前时间
|
|
|
|
String paramValue = startDownloadTimes;
|
|
|
|
String nowTime = MsDateUtil.getDateTime();
|
|
|
|
CollectOrderRequest collectOrderRequest = new CollectOrderRequest();
|
|
|
|
|
|
|
|
collectOrderRequest.setStartTime(paramValue);
|
|
|
|
collectOrderRequest.setEndTime(nowTime);
|
|
|
|
|
|
|
|
WorkBindBusTypeRequest workBindBusTypeRequest = new WorkBindBusTypeRequest();
|
|
|
|
List<SysWorkplaceDocumentResponse> sysWorkplaceDocumentResponses = sysWorkplaceDocumentDao.filterList(workBindBusTypeRequest);
|
|
|
|
if (CollUtil.isNotEmpty(sysWorkplaceDocumentResponses)) {
|
|
|
|
for (SysWorkplaceDocumentResponse sysWorkplaceDocumentResponse : sysWorkplaceDocumentResponses) {
|
|
|
|
String documentTypeCode = sysWorkplaceDocumentResponse.getDocumentTypeCode();
|
|
|
|
collectOrderRequest.setBusType(documentTypeCode);
|
|
|
|
collectOriginService.downloadOrderV2(collectOrderRequest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ioCollectSet.setStartDownloadTime(MsDateUtil.parseDate(nowTime));
|
|
|
|
collectSetService.updateById(ioCollectSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|