package com.lyms.talkonlineweb.task;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.lyms.talkonlineweb.domain.LymsArticle;
import com.lyms.talkonlineweb.domain.LymsDict;
import com.lyms.talkonlineweb.domain.LymsPushedart;
import com.lyms.talkonlineweb.domain.PatientInfo;
import com.lyms.talkonlineweb.service.LymsArticleService;
import com.lyms.talkonlineweb.service.LymsDictService;
import com.lyms.talkonlineweb.service.LymsPushedartService;
import com.lyms.talkonlineweb.service.PatientInfoService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 推送文章任务
*/
@Component
@Log4j2
public class PushArticleTask {
@Autowired
private LymsArticleService lymsArticleService;
@Autowired
private PatientInfoService patientInfoService;
@Autowired
private LymsPushedartService lymsPushedartService;//推送的历史记录
@Autowired
private LymsDictService lymsDictService;
// @Scheduled(initialDelay=10000, fixedRate=60000*10)
@Scheduled(initialDelay=10000, fixedRate=10000)
public void pushArtcle(){
Map<String,Object> param=new HashMap<>();
param.put("vtype",999);
List<LymsDict> dcLst=lymsDictService.listByMap(param);
if (dcLst.size()>0 && dcLst.get(0).getCode()==1){
log.debug("开始给患者推送文章>>>>>>");
List<LymsArticle> aLst=lymsArticleService.sltNeedPush();//获取待推送文章
aLst.forEach(e->{
PatientInfo patientInfo=new PatientInfo();
patientInfo.setIid(e.getIid());//针对特定疾病人群推送文章
List<PatientInfo> pLst=patientInfoService.list(Wrappers.query(patientInfo));
pLst.forEach(p->{
LymsPushedart pushedart=new LymsPushedart();
pushedart.setPid(p.getId());
pushedart.setAid(e.getAid());
pushedart.setCreatedtime(new Date());
pushedart.setIsread((byte) 0);
lymsPushedartService.save(pushedart);//插入到提送记录
});
});
}
}
}