소스 검색

病患者定标情况同步JOB

DESKTOP-G6NQ3SI\dante 7 년 전
부모
커밋
4106292593

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

@ -116,6 +116,16 @@ public class ApplicationEvent implements ApplicationListener<ContextRefreshedEve
                logger.info("doctor_feldsher_template_job reorder job job exist");
                logger.info("doctor_feldsher_template_job reorder job job exist");
            }
            }
            //慢病患者定标情况同步,每天凌晨2点执行一次
            if (!quartzHelper.isExistJob("patient_disease_contion_syn_job")) {
                String trigger = SystemConf.getInstance().getSystemProperties().getProperty("patient_disease_contion_syn_job");
                quartzHelper.addJob(PatientDiseaseConditionSynJob.class, trigger, "patient_disease_contion_syn_job", new HashMap<String, Object>());
                logger.info("patient_disease_contion_syn_job  job success");
            } else {
                logger.info("patient_disease_contion_syn_job  job exist");
            }
            // 启动redis 消息队列线程
            // 启动redis 消息队列线程
            logger.info("redis message start");
            logger.info("redis message start");

+ 41 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/job/PatientDiseaseConditionSynJob.java

@ -0,0 +1,41 @@
package com.yihu.wlyy.job;
import com.yihu.wlyy.service.third.jw.JwPrescriptionService;
import com.yihu.wlyy.util.DateUtil;
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;
/**
 * 慢病患者定标情况同步JOB
 * @author huangwenjie
 * @date 2017/9/17 21:28
 */
public class PatientDiseaseConditionSynJob implements Job {
    private static final Logger logger = LoggerFactory.getLogger(PatientDiseaseConditionSynJob.class);
    @Autowired
    private JwPrescriptionService jwPrescriptionService;
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        logger.info("START=====开始更新慢病患者定标情况的JOB");
        try {
            String startdate = DateUtil.getStringDateShort() + " 00:00:00";
            String enddate = DateUtil.getStringDateShort() + " 23:59:59";
            //根据起止时间查询家签慢病患者定标情况,并同步到本地数据库
            jwPrescriptionService.getPatientDiseaseContentMapByTime(startdate,enddate);
            logger.info("END========开始更新慢病患者定标情况成功JOB");
        }catch (Exception e){
            e.printStackTrace();
            logger.info("END===ERROE===开始更新慢病患者定标情况JOB,message:"+e.getMessage());
        }
    }
}

+ 5 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/patient/PatientDao.java

@ -64,4 +64,9 @@ public interface PatientDao extends PagingAndSortingRepository<Patient, Long> {
    //获取所有的openid并排重
    //获取所有的openid并排重
    @Query("select distinct p.openid from Patient p where p.openid is not null and p.openid <> '' ")
    @Query("select distinct p.openid from Patient p where p.openid is not null and p.openid <> '' ")
    List<String> findOpenids();
    List<String> findOpenids();
    //根据患者身份证号更新患者颜色定标情况
    @Modifying
    @Query("update Patient p set p.diseaseCondition = ?2 where p.idcard = ?1")
    void updatePatientDiseascontionByIdcard(String idcard, Integer diseaseCondition);
}
}

+ 40 - 3
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/service/common/account/PatientService.java

@ -24,7 +24,8 @@ import com.yihu.wlyy.util.EncodesUtil;
import com.yihu.wlyy.util.IdcardInfoExtractor;
import com.yihu.wlyy.util.IdcardInfoExtractor;
import com.yihu.wlyy.util.SystemData;
import com.yihu.wlyy.util.SystemData;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.json.JSONArray;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
@ -32,12 +33,14 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Component;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springside.modules.utils.Clock;
import org.springside.modules.utils.Clock;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.*;
/**
/**
@ -49,6 +52,8 @@ import java.util.*;
@Transactional(rollbackFor = Exception.class)
@Transactional(rollbackFor = Exception.class)
public class PatientService extends TokenService {
public class PatientService extends TokenService {
    private static final Logger logger = LoggerFactory.getLogger(PatientService.class);
    @Autowired
    @Autowired
    private SignFamilyDao signFamilyDao;
    private SignFamilyDao signFamilyDao;
    @Autowired
    @Autowired
@ -64,6 +69,9 @@ public class PatientService extends TokenService {
    @Autowired
    @Autowired
    JdbcTemplate jdbcTemplate;
    JdbcTemplate jdbcTemplate;
    @Autowired
    private JpaTransactionManager transactionManager;
    private Clock clock = Clock.DEFAULT;
    private Clock clock = Clock.DEFAULT;
    //可续签月份
    //可续签月份
    private int[] canRenewMonth = {4, 5, 6, 7};
    private int[] canRenewMonth = {4, 5, 6, 7};
@ -982,4 +990,33 @@ public class PatientService extends TokenService {
    public void save(Patient patient) {
    public void save(Patient patient) {
        patientDao.save(patient);
        patientDao.save(patient);
    }
    }
    /**
     * 根据患者身份证号更新患者颜色定标情况
     * @param idcard_diseasecontion_map
     */
    @Transactional
    public void updatePatientDiseascontionByIdcard(HashMap<String, Integer> idcard_diseasecontion_map){
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); // 事物隔离级别,开启新事务
        TransactionStatus status = transactionManager.getTransaction(def); // 获得事务状态
        try {
            for (String idcard : idcard_diseasecontion_map.keySet()) {
                patientDao.updatePatientDiseascontionByIdcard(idcard,idcard_diseasecontion_map.get(idcard));
            }
            //事务提交
            transactionManager.commit(status);
        } catch (Exception ex) {
            logger.info("更新患者颜色定标情况出错,从基卫获取的患者数据为:START");
            for (String idcard : idcard_diseasecontion_map.keySet()) {
                logger.info("idcard:"+idcard);
                logger.info("idcard:"+idcard_diseasecontion_map.get(idcard));
            }
            logger.info("更新患者颜色定标情况出错,从基卫获取的患者数据为:END");
            //报错事务回滚
            transactionManager.rollback(status);
        }
    }
}
}

+ 58 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/service/third/jw/JwPrescriptionService.java

@ -1,9 +1,11 @@
package com.yihu.wlyy.service.third.jw;
package com.yihu.wlyy.service.third.jw;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.entity.patient.prescription.Prescription;
import com.yihu.wlyy.entity.patient.prescription.Prescription;
import com.yihu.wlyy.repository.prescription.PrescriptionDao;
import com.yihu.wlyy.repository.prescription.PrescriptionDao;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.util.HttpClientUtil;
import com.yihu.wlyy.util.HttpClientUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.NameValuePair;
@ -16,6 +18,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.List;
import java.util.Map;
import java.util.Map;
@ -36,6 +39,8 @@ public class JwPrescriptionService {
    private JdbcTemplate jdbcTemplate;
    private JdbcTemplate jdbcTemplate;
    @Autowired
    @Autowired
    private PrescriptionDao prescriptionDao;
    private PrescriptionDao prescriptionDao;
    @Autowired
    private PatientService patientService;
    /**
    /**
     * 获取字典列表
     * 获取字典列表
@ -228,4 +233,57 @@ public class JwPrescriptionService {
        return response;
        return response;
    }
    }
    /**
     * 根据起止时间查询家签慢病患者定标情况,并同步到本地数据库
     * @param startdate
     * @param enddate
     * @return
     */
    public void getPatientDiseaseContentMapByTime(String startdate, String enddate)throws Exception {
        logger.info("查询家签慢病患者定标情况,开始时间"+startdate+",结束时间:"+enddate);
        String url = jwUrl + "/third/sign/getSickFamilyDoctorSpecialistControl";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("TIME_START", startdate));//开始时间
        params.add(new BasicNameValuePair("TIME_END", enddate));//结束时间
        String response = httpClientUtil.post(url, params, "UTF-8");
        HashMap<String, Integer> idcard_diseasecontion_map = new HashMap<>();
        if(StringUtils.isNotBlank(response)){
            JSONObject reobj =  JSON.parseObject(response);
            Integer status = reobj.getInteger("status");
            String errmsg = reobj.getString("msg");
            if(200 == status){
                JSONObject jwData = reobj.getJSONObject("data");
                Integer jwCode = jwData.getInteger("CODE");
                if(1 == jwCode){
                    JSONArray dataArray = jwData.getJSONArray("DATA");
                    for (int i = 0; i < dataArray.size(); i++) {
                        JSONObject json = dataArray.getJSONObject(i);
                        String idcard = json.getString("IDENTITY_CARD_NO");//身份证号码
                        Integer diseaseCondition = json.getInteger("SPECIALIST_CONTROL");//定标情况【 0 绿标 1 黄标 2 红标】
                        idcard_diseasecontion_map.put(idcard,diseaseCondition);
                    }
                    if(idcard_diseasecontion_map != null && !idcard_diseasecontion_map.keySet().isEmpty()){
                        logger.info("从基卫接口获取需要更新定标情况的慢病患者个数为"+idcard_diseasecontion_map.keySet().size());
                        patientService.updatePatientDiseascontionByIdcard(idcard_diseasecontion_map);
                    }else{
                        logger.info("从基卫接口获取需要更新定标情况的慢病患者个数为"+idcard_diseasecontion_map.keySet().size());
                    }
                }else{
                    String jwMessage = jwData.getString("MESSAGE");
                    throw new Exception("获取慢病患者定标情况,请求基卫接口失败:"+jwMessage);
                }
            }else{
                throw new Exception("获取慢病患者定标情况请求失败,"+errmsg);
            }
        }else{
            throw new Exception("获取慢病患者定标情况请求失败,无数据返回!");
        }
    }
}
}

+ 59 - 1
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/web/quota/JobController.java

@ -8,14 +8,18 @@ import com.yihu.wlyy.service.app.disease.PatientDiseaseService;
import com.yihu.wlyy.service.app.scheduling.DoctorWorkTimeService;
import com.yihu.wlyy.service.app.scheduling.DoctorWorkTimeService;
import com.yihu.wlyy.service.app.statistics.StatisticsService;
import com.yihu.wlyy.service.app.statistics.StatisticsService;
import com.yihu.wlyy.service.quota.JobService;
import com.yihu.wlyy.service.quota.JobService;
import com.yihu.wlyy.service.third.jw.JwPrescriptionService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.web.BaseController;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.MediaType;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestController;
import java.text.SimpleDateFormat;
import java.text.SimpleDateFormat;
@ -40,15 +44,17 @@ public class JobController extends BaseController {
    private final QuartzHelper quartzHelper;
    private final QuartzHelper quartzHelper;
    private final DoctorWorkTimeService workTimeService;
    private final DoctorWorkTimeService workTimeService;
    private final StatisticsService statisticsService;
    private final StatisticsService statisticsService;
    private final JwPrescriptionService jwPrescriptionService;
    @Autowired
    @Autowired
    public JobController(StatisticsService statisticsService, JobService jobService, StringRedisTemplate redisTemplate, DoctorWorkTimeService workTimeService, PatientDiseaseService diseaseService, QuartzHelper quartzHelper) {
    public JobController(StatisticsService statisticsService, JobService jobService, StringRedisTemplate redisTemplate, DoctorWorkTimeService workTimeService, PatientDiseaseService diseaseService, QuartzHelper quartzHelper,JwPrescriptionService jwPrescriptionService) {
        this.statisticsService = statisticsService;
        this.statisticsService = statisticsService;
        this.jobService = jobService;
        this.jobService = jobService;
        this.redisTemplate = redisTemplate;
        this.redisTemplate = redisTemplate;
        this.workTimeService = workTimeService;
        this.workTimeService = workTimeService;
        this.diseaseService = diseaseService;
        this.diseaseService = diseaseService;
        this.quartzHelper = quartzHelper;
        this.quartzHelper = quartzHelper;
        this.jwPrescriptionService = jwPrescriptionService;
    }
    }
    /**
    /**
@ -463,4 +469,56 @@ public class JobController extends BaseController {
            return error(-1, e.getMessage());
            return error(-1, e.getMessage());
        }
        }
    }
    }
    /**
     *立即执行当天的慢病患者定标情况同步
     *@author huangwenjie
     *@date 2017/9/17 14:16
     */
    @RequestMapping(value = "/executePatientDiseaseConditionSynJob", method = RequestMethod.POST)
    @ApiOperation("立即执行当天的慢病患者定标情况同步")
    public String executePatientDiseaseConditionSynJob() {
        try {
            quartzHelper.startNow(PatientDiseaseConditionSynJob.class, "PATIENT-DISEASE-CONDITION-SYN", null);
            return write(200, "启动成功");
        } catch (Exception e) {
            error(e);
            return error(-1, e.getMessage());
        }
    }
    /**
     *根据时间范围执行慢病患者定标情况同步
     *@author huangwenjie
     *@date 2017/9/17 14:16
     */
    @RequestMapping(value = "/executePatientDiseaseConditionSynJobByTime", method = RequestMethod.POST)
    @ApiOperation("根据时间范围执行慢病患者定标情况同步")
    public String executePatientDiseaseConditionSynJobByTime(
            @ApiParam(name="startdate", value="开始时间:yyyy-mm-dd")
            @RequestParam(value = "startdate",required = true) String startdate,
            @ApiParam(name="enddate", value="结束时间:yyyy-mm-dd")
            @RequestParam(value = "enddate",required = true) String enddate) {
        try {
            String start = "";
            String end = "";
            do{
                start = startdate + " 00:00:00";
                end = startdate + " 23:59:59";
                //根据起止时间查询家签慢病患者定标情况,并同步到本地数据库
                jwPrescriptionService.getPatientDiseaseContentMapByTime(start,end);
                startdate = DateUtil.getNextDay(startdate,1);
            }while (!startdate.equals(enddate));
            return write(200, "执行成功");
        } catch (Exception e) {
            error(e);
            return error(-1, e.getMessage());
        }
    }
}
}

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

@ -98,6 +98,9 @@ finish_consult_job=* 59 * * * ?
#提醒有监测方案的居民上传数据,每29分钟执行一次
#提醒有监测方案的居民上传数据,每29分钟执行一次
doctor_feldsher_template_job=0 0/29 * * * ?
doctor_feldsher_template_job=0 0/29 * * * ?
# 病患者定标情况同步JOB (每天2点一次)
patient_disease_contion_syn_job=0 0 2 * * ?
#统一支付平台支付成功后页面跳转地址
#统一支付平台支付成功后页面跳转地址
return_url={server}/wx/html/qygl/html/pay_result.html
return_url={server}/wx/html/qygl/html/pay_result.html