Merge remote-tracking branch 'origin/dev_drug' into dev_drug
commit
b4586848b6
@ -0,0 +1,86 @@
|
||||
package com.glxp.api.task;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.glxp.api.dao.schedule.ScheduledDao;
|
||||
import com.glxp.api.entity.collect.RelCodeBatch;
|
||||
import com.glxp.api.entity.collect.RelCodeDetail;
|
||||
import com.glxp.api.entity.system.ScheduledEntity;
|
||||
import com.glxp.api.idc.service.IdcService;
|
||||
import com.glxp.api.req.collect.RelCodeBatchRequest;
|
||||
import com.glxp.api.req.collect.RelCodeDetailRequest;
|
||||
import com.glxp.api.req.system.ScheduledRequest;
|
||||
import com.glxp.api.service.collect.RelCodeBatchService;
|
||||
import com.glxp.api.service.collect.RelCodeDetailService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
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.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@EnableScheduling
|
||||
public class UploadDrugDataTask implements SchedulingConfigurer {
|
||||
|
||||
final Logger logger = LoggerFactory.getLogger(UploadDrugDataTask.class);
|
||||
|
||||
@Resource
|
||||
private ScheduledDao scheduledDao;
|
||||
@Resource
|
||||
private RelCodeBatchService relCodeBatchService;
|
||||
@Resource
|
||||
private RelCodeDetailService relCodeDetailService;
|
||||
|
||||
@Override
|
||||
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
|
||||
scheduledTaskRegistrar.addTriggerTask(() -> process(),
|
||||
triggerContext -> {
|
||||
ScheduledRequest scheduledRequest = new ScheduledRequest();
|
||||
scheduledRequest.setCronName("uploadDrugData");
|
||||
logger.info("uploadDrugData----------------");
|
||||
ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest);
|
||||
String cron = scheduledEntity != null ? scheduledEntity.getCron() : "0 0/5 * * * ?";
|
||||
|
||||
if (cron.isEmpty()) {
|
||||
logger.error("cron is null");
|
||||
}
|
||||
logger.info("uploadDrugData----------------");
|
||||
return new CronTrigger(cron).nextExecutionTime(triggerContext);
|
||||
});
|
||||
}
|
||||
|
||||
private void process() {
|
||||
logger.info("uploadDrugData----process------------");
|
||||
//查找扫描
|
||||
List<RelCodeBatch> list = relCodeBatchService.list(new LambdaUpdateWrapper<RelCodeBatch>().in(RelCodeBatch::getUploadFlag, 0, 2));
|
||||
if (CollUtil.isNotEmpty(list)){
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
RelCodeBatch relCodeBatch = list.get(i);
|
||||
Integer id = relCodeBatch.getId();
|
||||
List<RelCodeDetail> list1 = relCodeDetailService.list(new LambdaUpdateWrapper<RelCodeDetail>().eq(RelCodeDetail::getBatchIdFk, id));
|
||||
List<RelCodeDetailRequest> detailList = new ArrayList<>();
|
||||
if (CollUtil.isNotEmpty(list)){
|
||||
for (int i1 = 0; i1 < list1.size(); i1++) {
|
||||
RelCodeDetail relCodeDetail = list1.get(i1);
|
||||
RelCodeDetailRequest request = new RelCodeDetailRequest();
|
||||
BeanUtils.copyProperties(relCodeDetail,request);
|
||||
detailList.add(request);
|
||||
}
|
||||
}
|
||||
RelCodeBatchRequest relCodeBatchRequest = new RelCodeBatchRequest();
|
||||
BeanUtils.copyProperties(relCodeBatch,relCodeBatchRequest);
|
||||
relCodeBatchRequest.setDetailList(detailList);
|
||||
relCodeBatchService.uploadDrugDataOne(relCodeBatchRequest);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue