Prechádzať zdrojové kódy

定时九点提醒待接种疫苗的居民

zd_123 6 rokov pred
rodič
commit
00c9c45ac4

+ 9 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/event/ApplicationEvent.java

@ -292,6 +292,15 @@ public class ApplicationEvent implements ApplicationListener<ContextRefreshedEve
                logger.info("child_immune_vaccin_job  job exist");
            }
            //获取儿童可预约疫苗,每天凌晨1点执行一次
            if (!quartzHelper.isExistJob("alert_child_immune_vaccin_job")) {
                String trigger = SystemConf.getInstance().getSystemProperties().getProperty("alert_child_immune_vaccin_job");
                quartzHelper.addJob(AlertChildImmuneVaccinJob.class, trigger, "alert_child_immune_vaccin_job", new HashMap<String, Object>());
                logger.info("alert_child_immune_vaccin_job  job success");
            } else {
                logger.info("alert_child_immune_vaccin_job  job exist");
            }
        } catch (Exception e) {
            logger.info("sign end job start failed");
        }

+ 28 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/job/AlertChildImmuneVaccinJob.java

@ -0,0 +1,28 @@
package com.yihu.wlyy.job;
import com.yihu.wlyy.service.imm.ChildVaccinImmuneService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
public class AlertChildImmuneVaccinJob implements Job {
    private static final Logger logger = LoggerFactory.getLogger(AlertChildImmuneVaccinJob.class);
    @Autowired
    private ChildVaccinImmuneService childVaccinImmuneService;
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        logger.info("START========每天九点提醒居民待接种JOB========");
        try {
            childVaccinImmuneService.alertBefore();
            logger.info("END========每天九点提醒居民待接种JOB========");
        }catch (Exception e){
            e.printStackTrace();
            logger.info("END===ERROE===每天九点提醒居民待接种JOB,message:"+e.getMessage());
        }
    }
}

+ 170 - 3
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/service/imm/ChildVaccinImmuneService.java

@ -1,16 +1,28 @@
package com.yihu.wlyy.service.imm;
import com.yihu.es.entity.PatientRemindRecordESDO;
import com.yihu.wlyy.config.es.ElasticFactory;
import com.yihu.wlyy.config.es.ElastricSearchSave;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.imm.ChildFamilyImmune;
import com.yihu.wlyy.entity.imm.ChildImmuneVaccin;
import com.yihu.wlyy.entity.imm.ChildInfo;
import com.yihu.wlyy.entity.wechat.WechatTemplateConfig;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.imm.ChildImmuneVaccinDao;
import com.yihu.wlyy.repository.wechat.WechatTemplateConfigDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.third.jw.ImmuneService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import io.searchbox.client.JestClient;
import org.apache.commons.lang.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -24,21 +36,38 @@ import java.util.*;
 */
@Service
public class ChildVaccinImmuneService extends BaseService {
	
	private static org.slf4j.Logger logger = LoggerFactory.getLogger(ChildVaccinImmuneService.class);
	@Autowired
	private JdbcTemplate jdbcTemplate;
	@Autowired
	private ChildImmuneVaccinDao childImmuneVaccinDao;
	@Autowired
	private ImmuneService immuneService;
	@Autowired
	private DoctorDao doctorDao;
	@Value("${es.type.patientRemindRecord}")
	private String esType;
	@Value("${es.index.patientRemindRecord}")
	private String esIndex;
	@Autowired
	private WechatTemplateConfigDao templateConfigDao;
	@Autowired
	private PushMsgTask pushMsgTask;
	@Autowired
	private WeiXinAccessTokenUtils weiXinAccessTokenUtils;
	@Autowired
	private ElasticFactory elasticFactory;
	@Autowired
	private ElastricSearchSave elastricSearchSave;
	
	@Transactional(rollbackFor = Exception.class)
	public int getChildImmuneVaccinEveryDay()throws Exception{
		int result = 0;
		try {
			String sql ="SELECT" +
			/*String sql ="SELECT" +
					" DISTINCT ci.`code`," +
					" ci.idcard," +
					" ci.`name`," +
@ -48,7 +77,9 @@ public class ChildVaccinImmuneService extends BaseService {
					" wlyy_child_family_immune fi" +
					" LEFT JOIN wlyy_child_info ci ON fi.child_code = ci.`code`" +
					" WHERE" +
					" fi.del = 0";
					" fi.del = 0";*/
            String sql ="SELECT `code`,`name`,idcard,ssc FROM wlyy_child_info WHERE del=0";
			List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
			for (Map<String,Object> map : list){
				String barcode = String.valueOf(map.get("barcode"));
@ -165,4 +196,140 @@ public class ChildVaccinImmuneService extends BaseService {
		}
		return result;
	}
	public int alertBefore()throws Exception{
		JSONArray jsonArray =  new JSONArray();
		String sql ="SELECT" +
				" v.*, i.birthday" +
				" FROM" +
				" wlyy_child_immune_vaccin v" +
				" LEFT JOIN wlyy_child_info i ON v.child_info_code = i.`code`" +
				" WHERE" +
				" v.del = 0" +
				" AND ymkc = 'true'";
		List<Map<String,Object>> mapList = jdbcTemplate.queryForList(sql);
		String nowDate = DateUtil.dateToStrShort(new Date());
		for (Map<String,Object> map : mapList){
			Calendar calendar=Calendar.getInstance();
			String birthDayStr = String.valueOf(map.get("birthday"));
			if (StringUtils.isNotBlank(birthDayStr)){
				String[] biStr = birthDayStr.split("-");
				int birthdayDate = Integer.valueOf(biStr[biStr.length-1]);
				int nowDayDate = calendar.get(GregorianCalendar.DAY_OF_MONTH);
				int nowMonthDate = calendar.get(GregorianCalendar.MONTH)+1;
				int nowYearDate = calendar.get(GregorianCalendar.YEAR);
				//如果生日在今天的日期之前,则取下个月生日的日期的15天的是否是今天
				if (birthdayDate<nowDayDate){
					calendar.set(nowYearDate,nowMonthDate+1,birthdayDate);
				}else {
					//如果生日在今天之前后,则看生日的15天之前是否是今天
					calendar.set(nowYearDate,nowMonthDate,birthdayDate);
				}
				String needAlertDate = DateUtil.dateToStrShort(DateUtil.getPreDays(calendar.getTime(),-15));
				if (needAlertDate.equals(nowDate)){
					JSONObject jsonObject = new JSONObject();
					jsonObject.put("vaccinCode",map.get("code"));//待接种疫苗记录code
					jsonObject.put("childName", map.get("name"));//儿童姓名
					jsonObject.put("childCode", map.get("child_info_code"));//儿童code
					jsonObject.put("vaccinName", map.get("ymmc"));//疫苗名称
					jsonArray.put(jsonObject);
				}
			}
		}
		return alertImmVacclinByChildInfoCodes(jsonArray.toString());
	}
	public int alertImmVacclinByChildInfoCodes(String alertDataJsonStr)throws Exception{
		if (StringUtils.isEmpty(alertDataJsonStr)){
			return -1;
		}
		List<PatientRemindRecordESDO> patientRemindRecordESDOList = new ArrayList<>();
		JSONArray jsonArray = new JSONArray(alertDataJsonStr);
		for (int i=0;i<jsonArray.length();i++){
			JSONObject jsonObject = jsonArray.getJSONObject(i);
			String childCode = jsonObject.getString("childCode");
			String childName = jsonObject.getString("childName");
			String vaccinName = jsonObject.getString("vaccinName");
			String vaccinCode = jsonObject.getString("vaccinCode");
			String sql ="SELECT" +
					" cfi.relation," +
					" p.`code`," +
					" p.`name`," +
					" p.openid" +
					" FROM" +
					" wlyy_child_family_immune cfi" +
					" LEFT JOIN wlyy_patient p ON cfi.family_code = p.`code`" +
					" WHERE" +
					" cfi.child_code = '"+childCode+"'" +
					" AND cfi.del = 0 and (p.openid is not null or p.openid !='')";
			List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
			if (list.size()==0){
				return -10000;
			}
			List<String> openIdList = new ArrayList<>();
			for (Map<String,Object> map : list){
				//如果父母亲都在就都发
				if (!openIdList.contains(String.valueOf(map.get("openid")))){
					if (("1".equals(String.valueOf(map.get("relation"))) || "2".equals(String.valueOf(map.get("relation")))) && StringUtils.isNotBlank(String.valueOf(map.get("openid")))){
						boolean flag =true;
						try {
							WechatTemplateConfig temp = templateConfigDao.findByScene("template_deal_with_job", "dsymjztx");
							JSONObject json = new JSONObject();
							json.put("toUser",String.valueOf(map.get("code")));
							json.put("keyword1", temp.getKeyword1().replace("key1",DateUtil.dateToStr(new Date(), "yyyy-MM-dd")));
							json.put("keyword2", temp.getKeyword2().replace("key1", vaccinName));
							json.put("remark", temp.getRemark());
							json.put("first", temp.getFirst().replace("key1", childName));
							logger.info("weiTempJOSN:"+json.toString());
							pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 24,String.valueOf(map.get("openid")) , String.valueOf(map.get("name")), json);
						}catch (Exception e){
							e.printStackTrace();
							flag = false;
						}
						//发送微信消息并且插入一条es提醒数据
						PatientRemindRecordESDO patientRemindRecordESDO =  new PatientRemindRecordESDO();
						patientRemindRecordESDO.setCode(getCode());
						patientRemindRecordESDO.setPatient(String.valueOf(map.get("code")));
						patientRemindRecordESDO.setPatientName(String.valueOf(map.get("name")));
						patientRemindRecordESDO.setDoctor("admin");
						patientRemindRecordESDO.setDoctorName("admin");
						patientRemindRecordESDO.setCreateDate(new Date());
						patientRemindRecordESDO.setRemindType(1);
						if (flag) {
							patientRemindRecordESDO.setStatus(1);
							String update="UPDATE wlyy_child_immune_vaccin SET alert_tag=1,alert_time='"+DateUtil.dateToStr(new Date(),DateUtil.YYYY_MM_DD_HH_MM_SS)+"' where `code`='"+vaccinCode+"'";
							jdbcTemplate.update(update);
						}else {
							patientRemindRecordESDO.setStatus(0);
						}
						patientRemindRecordESDOList.add(patientRemindRecordESDO);
					}
				}
			}
		}
		//保存到es的提醒日志表中
		esSavePatientRemindRecord(patientRemindRecordESDOList);
		return 200;
	}
	public boolean esSavePatientRemindRecord(List<PatientRemindRecordESDO> patientRemindRecordESDOList)throws Exception{
		JestClient jestClient = null;
		boolean flag = true;
		try {
			jestClient = elasticFactory.getJestClient();
			if(patientRemindRecordESDOList != null && patientRemindRecordESDOList.size()>0){
				flag = elastricSearchSave.save(patientRemindRecordESDOList, esIndex, esType);
			}
		}catch (Exception e){
			e.printStackTrace();
			flag = false;
		} finally{
			if (jestClient != null) {
				jestClient.shutdownClient();
			}
		}
		return  flag;
	}
}

+ 2 - 0
patient-co/patient-co-wlyy-job/src/main/resources/application-dev.yml

@ -125,10 +125,12 @@ es:
    HealthEduArticlePatient: health_edu_article_patient_dev
    Statistics: wlyy_quota_test
    FollowUp: wlyy_followup
    patientRemindRecord: wlyy_patient_remind_record
  type:
    HealthEduArticlePatient: health_edu_article_patient_dev
    Statistics: wlyy_quota_test
    FollowUpContent: wlyy_followup_content
    patientRemindRecord: wlyy_patient_remind_record
  host:  http://172.19.103.68:9200
  tHost: 172.19.103.68:9300
  clusterName: jkzl

+ 2 - 0
patient-co/patient-co-wlyy-job/src/main/resources/application-devtest.yml

@ -118,10 +118,12 @@ es:
    HealthEduArticlePatient: wlyy_quota_test
    FollowUp: wlyy_followup
    Statistics: wlyy_quota_test
    patientRemindRecord: wlyy_patient_remind_record
  type:
    HealthEduArticlePatient: wlyy_quota_test
    Statistics: wlyy_quota_test
    FollowUpContent: wlyy_followup_content
    patientRemindRecord: wlyy_patient_remind_record
  host:  http://172.19.103.68:9200
  tHost: 172.19.103.68:9300
  clusterName: jkzl

+ 2 - 0
patient-co/patient-co-wlyy-job/src/main/resources/application-test.yml

@ -124,10 +124,12 @@ es:
    HealthEduArticlePatient: health_edu_article_patient_test
    FollowUp: wlyy_followup
    Statistics: wlyy_quota_test
    patientRemindRecord: wlyy_patient_remind_record
  type:
    HealthEduArticlePatient: health_edu_article_patient_test
    FollowUpContent: wlyy_followup_content
    Statistics: wlyy_quota_test
    patientRemindRecord: wlyy_patient_remind_record
  host:  http://172.19.103.68:9200
  tHost: 172.19.103.68:9300
  clusterName: jkzl

+ 3 - 0
patient-co/patient-co-wlyy-job/src/main/resources/system.properties

@ -140,6 +140,9 @@ patient_medicare_number_job=0 0 6 * * ?
# 获取儿童可预约疫苗,每天凌晨1点执行一次
child_immune_vaccin_job=0 0 1 * * ?
# 提醒具名儿童可预约疫苗,每天9点执行一次
alert_child_immune_vaccin_job=0 0 9 * * ?
#统一支付平台支付成功后页面跳转地址
return_url={server}/wx/html/qygl/html/pay_result.html
#统一支付平台支付接口地址