Sfoglia il codice sorgente

Merge branch 'dev' of chenweida/patient-co-management into dev

chenweida 8 anni fa
parent
commit
550c6a823b

+ 3 - 3
src/main/java/com/yihu/wlyy/entity/statistics/WlyyQuotaResult.java

@ -32,9 +32,9 @@ public class WlyyQuotaResult implements java.io.Serializable {
    private String townName;//区级名称
    private String orgCode;//机构code
    private String orgName;//机构名称
    private String qkdoctorName;//全科医生名称
    private String qkdoctorJobName;//全科医生职称
    private String qkdoctorCode;//全科医生code
    private String qkdoctorName;//全科医生名称 --现在是团队名称
    private String qkdoctorCode;//全科医生code --现在是团队code
    private String qkdoctorJobName;//全科医生职称   用于检验统计线程判断指标是否需要重新生成  等于 1 的时候是不需要
    private Date createTime;//创建时间
    @Id

+ 1 - 1
src/main/java/com/yihu/wlyy/job/AllSignExpenseStatusJob.java

@ -77,7 +77,7 @@ public class AllSignExpenseStatusJob implements Job{
     */
    @Transactional
    private void computequota() {
        jdbcTemplate.execute("delete from wlyy_quota_result where quota_date='" + date + "' and quato_code='" + 13 + "'");
        jdbcTemplate.execute("delete from wlyy_quota_result where quota_date='" + date + "' and quato_code='" + 14 + "'");
        //新建任务日志对象
        QuartzJobLog quartzJobLog = new QuartzJobLog();
        quartzJobLog.setJobStartTime(new Date());

+ 229 - 0
src/main/java/com/yihu/wlyy/job/check/CheckSignJob.java

@ -0,0 +1,229 @@
package com.yihu.wlyy.job.check;
import com.yihu.wlyy.entity.job.QuartzJobConfig;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.entity.statistics.WlyyQuota;
import com.yihu.wlyy.entity.statistics.WlyyQuotaResult;
import com.yihu.wlyy.job.QuartzHelper;
import com.yihu.wlyy.job.SignJob;
import com.yihu.wlyy.repository.job.QuartzJobConfigDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.repository.statistics.QuotaDao;
import com.yihu.wlyy.repository.statistics.WlyyQuotaResultDao;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.web.quota.WlyyJobConfigVO;
import com.yihu.wlyy.web.quota.WlyyQuotaVO;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
import java.util.*;
/**
 * Created by Administrator on 2016.10.11.
 * 判断签约的数据对不对 不对的话 添加任务重新生成签约数据
 */
@Component
public class CheckSignJob implements Job{
    public static String jobKey="CHECK_SIGN_JOB";
    public static String cron="0 0 12 * * ?";
    @Autowired
    private WlyyQuotaResultDao wlyyQuotaResultDao;
    @Autowired
    private SignFamilyDao signFamilyDao;
    @Autowired
    private QuartzHelper quartzHelper;
    @Autowired
    private QuartzJobConfigDao wlyyJobConfigDao;
    @Autowired
    private QuotaDao quotaDao;
    @Transactional
    public void execute(JobExecutionContext context) throws JobExecutionException {
        try{
        SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
        //得到需要检验的统计
        List<WlyyQuotaResult> wlyyQuotaResults=getNeedCheckData();
        //检验统计数据和签约数据是否一致  key:yes 是需要 no:是不需要
        Map<String,List<WlyyQuotaResult>> wlyyQuotaResultsMap=checkWlyyQuotaResult(wlyyQuotaResults);
        //更新不需要下一次统计的任务
        upDataNoNeedCheckQuato(wlyyQuotaResultsMap.get("no"));
        //添加需要重新统计的指标
        addNeedCheckQuato(wlyyQuotaResultsMap.get("yes"));
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    private void addNeedCheckQuato(List<WlyyQuotaResult> yes)throws Exception {
        if(yes.size()>0){
            for(WlyyQuotaResult wlyyQuotaResult:yes){
                QuartzJobConfig quartzJobConfig = wlyyJobConfigDao.findById(wlyyQuotaResult.getId());
                if (quartzJobConfig == null) {
                    throw new Exception("id不存在");
                }
                WlyyQuota wlyyQuota = quotaDao.findOne(quartzJobConfig.getQuotaId());
                WlyyQuotaVO wlyyQuotaVO = new WlyyQuotaVO();
                WlyyJobConfigVO wlyyJobConfigVO = new WlyyJobConfigVO();
                BeanUtils.copyProperties(wlyyQuota, wlyyQuotaVO);
                BeanUtils.copyProperties(quartzJobConfig, wlyyJobConfigVO);
                Map<String, Object> params = new HashMap<String, Object>();
                params.put("quota", wlyyQuotaVO);
                params.put("jobConfig", wlyyJobConfigVO);
                String now=getNextDate(wlyyQuotaResult.getQuotaDate());
                String yesterday=wlyyQuotaResult.getQuotaDate();
                //往quartz框架添加任务
                params.put("now", now);
                params.put("yesterday", yesterday);
                String jobKey="checkSignQuartz:"+wlyyQuotaResult.getQuotaDate()+":"+wlyyQuotaResult.getQuatoCode();
                if(!quartzHelper.isExistJob(jobKey)){
                    quartzHelper.startAt(weeHours(new Date(),1),SignJob.class,jobKey,params);
                    //重新生成性别 疾病 扣费 和 年龄的统计
                    startJob("6",yesterday,now);
                    startJob("7",yesterday,now);
                    startJob("8",yesterday,now);
                    startJob("12",yesterday,now);
                }
            }
        }
    }
    private void startJob(String id, String yesterday, String now) throws Exception{
        QuartzJobConfig quartzJobConfig = wlyyJobConfigDao.findById(id);
        if (quartzJobConfig == null) {
            throw new Exception("id不存在");
        }
        WlyyQuota wlyyQuota = quotaDao.findOne(quartzJobConfig.getQuotaId());
        WlyyQuotaVO wlyyQuotaVO = new WlyyQuotaVO();
        WlyyJobConfigVO wlyyJobConfigVO = new WlyyJobConfigVO();
        BeanUtils.copyProperties(wlyyQuota, wlyyQuotaVO);
        BeanUtils.copyProperties(quartzJobConfig, wlyyJobConfigVO);
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("quota", wlyyQuotaVO);
        params.put("jobConfig", wlyyJobConfigVO);
        //往quartz框架添加任务
        params.put("now", now);
        params.put("yesterday", yesterday);
        String jobKey="checkSignQuartz:"+yesterday+":"+wlyyQuota.getId();
        if(!quartzHelper.isExistJob(jobKey)){
            quartzHelper.startAt(weeHours(new Date(),1),getClassById(id),jobKey,params);
        }
    }
    private Class getClassById(String id) {
        switch (id){
            case "6":{
                return SignJob.class;
            }
            case "7":{
                return SignJob.class;
            }
            case "8":{
                return SignJob.class;
            }
            case "12":{
                return SignJob.class;
            }
        }
        return null;
    }
    /**
     * 更新不需要下一次统计的任务   更新qkdoctorJobName字段为1
     * @param noNeedCheckQuatos
     */
    private void upDataNoNeedCheckQuato(List<WlyyQuotaResult> noNeedCheckQuatos) {
        if(noNeedCheckQuatos.size()>0){
            for(WlyyQuotaResult wlyyQuotaResult:noNeedCheckQuatos){
                wlyyQuotaResult.setQkdoctorJobName("1");
            }
            wlyyQuotaResultDao.save(noNeedCheckQuatos);
        }
    }
    /**
     * 检验统计数据和签约数据是否一致  key:yes 是需要 no:是不需要
     * @param wlyyQuotaResults
     * @return
     */
    private Map<String,List<WlyyQuotaResult>> checkWlyyQuotaResult(List<WlyyQuotaResult> wlyyQuotaResults) {
        Map<String,List<WlyyQuotaResult>> returnMap=new HashMap<String,List<WlyyQuotaResult>>();
        List<WlyyQuotaResult> yes=new ArrayList<WlyyQuotaResult>();//需要重新统计的
        List<WlyyQuotaResult> no=new ArrayList<WlyyQuotaResult>();//不需要重新统计
        for(WlyyQuotaResult wlyyQuotaResult:wlyyQuotaResults){
            String date=  wlyyQuotaResult.getQuotaDate();//格式  2016-10-20
            String nextDate=getNextDate(date);
            List<SignFamily> signFamilys = signFamilyDao.findByJiatingSignYesterdayExpensesStatus(date, nextDate);
            if(signFamilys.size()!=Integer.valueOf(wlyyQuotaResult.getResult())){
                //如果数目不相等 说明需要重新统计
                yes.add(wlyyQuotaResult);
            }else{
                //如果数目相等 说明需要不需要重新统计
                no.add(wlyyQuotaResult);
            }
        }
        returnMap.put("yes",yes);
        returnMap.put("no",no);
        return returnMap;
    }
    private String getNextDate(String date) {
        Date dateTime=  DateUtil.strToDateShort(date);
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(dateTime);
        calendar.add(calendar.DATE,1);//把日期往后增加一天.整数往后推,负数往前移动
        Date nextDateTime=calendar.getTime();
        return DateUtil.dateToStrShort(nextDateTime);
    }
    /**
     * 得到需要检验的统计
     * @return
     */
    private List<WlyyQuotaResult> getNeedCheckData() {
        List<WlyyQuotaResult> wlyyQuotaResults=wlyyQuotaResultDao.findByLevel1TypeAndQkdoctorJobName("4","1");
        return wlyyQuotaResults;
    }
    /**
     * 获取当前时间所在的凌晨时间
     *  凌晨
     * @param date
     * @flag 0 返回yyyy-MM-dd 00:00:00日期<br>
     *       1 返回yyyy-MM-dd 23:59:59日期
     * @return
     */
    private  Date weeHours(Date date, int flag) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        int minute = cal.get(Calendar.MINUTE);
        int second = cal.get(Calendar.SECOND);
        //时分秒(毫秒数)
        long millisecond = hour*60*60*1000 + minute*60*1000 + second*1000;
        //凌晨00:00:00
        cal.setTimeInMillis(cal.getTimeInMillis()-millisecond);
        if (flag == 0) {
            return cal.getTime();
        } else if (flag == 1) {
            //凌晨23:59:59
            cal.setTimeInMillis(cal.getTimeInMillis()+23*60*60*1000 + 59*60*1000 + 59*1000);
        }
        return cal.getTime();
    }
}

+ 1 - 1
src/main/java/com/yihu/wlyy/repository/job/QuartzJobConfigDao.java

@ -18,7 +18,7 @@ public interface QuartzJobConfigDao extends PagingAndSortingRepository<QuartzJob
    @Query(" FROM QuartzJobConfig a WHERE a.status=?1 and a.del='1'")
    List<QuartzJobConfig> findByAll(String s);
    @Query(" FROM QuartzJobConfig a WHERE a.id in (1,2,3,4,5,6,7,8,9,10,12,13)  and a.del='1' ")
    @Query(" FROM QuartzJobConfig a WHERE a.id in (1,2,3,4,5,6,7,8,9,10,12,13,14)  and a.del='1' ")
    List<QuartzJobConfig> findByIds();
    @Query(" FROM QuartzJobConfig a WHERE a.id=?1 and a.del='1'")

+ 3 - 0
src/main/java/com/yihu/wlyy/repository/statistics/WlyyQuotaResultDao.java

@ -18,4 +18,7 @@ public interface WlyyQuotaResultDao extends PagingAndSortingRepository<WlyyQuota
    @Modifying
    @Query(" delete FROM WlyyQuotaResult a WHERE a.quotaDate =?1 and a.quatoCode=?2")
    void deleteByDateAndCode(String yesterday, String quatoCode);
    @Query(" FROM WlyyQuotaResult a WHERE a.level1Type =?1 and a.qkdoctorJobName != ?2 and a.quatoCode=1")
    List<WlyyQuotaResult> findByLevel1TypeAndQkdoctorJobName(String level1Type, String qkdoctorJobName);
}

+ 13 - 0
src/main/java/com/yihu/wlyy/service/quota/JobService.java

@ -4,6 +4,7 @@ import com.yihu.wlyy.entity.doctor.team.sign.DoctorPatientGroupInfo;
import com.yihu.wlyy.entity.job.QuartzJobConfig;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.entity.statistics.WlyyQuota;
import com.yihu.wlyy.job.check.CheckSignJob;
import com.yihu.wlyy.job.QuartzHelper;
import com.yihu.wlyy.repository.doctor.DoctorPatientGroupInfoDao;
import com.yihu.wlyy.repository.job.QuartzJobConfigDao;
@ -297,4 +298,16 @@ public class JobService {
                }
            }
    }
    public void startCheckSignJob() throws  Exception{
        if(!quartzHelper.isExistJob(CheckSignJob.jobKey)){
            quartzHelper.addJob(CheckSignJob.class,CheckSignJob.cron,CheckSignJob.jobKey,new HashMap<>());
        }
    }
    public void stopCheckSignJob()throws  Exception {
        if(quartzHelper.isExistJob(CheckSignJob.jobKey)){
            quartzHelper.removeJob(CheckSignJob.jobKey);
        }
    }
}

+ 30 - 1
src/main/java/com/yihu/wlyy/web/quota/JobController.java

@ -182,7 +182,36 @@ public class JobController extends BaseController {
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
    }
    /**
     * 启动判断的任务
     *
     * @return
     */
    @RequestMapping(value = "startCheckSignJob", method = RequestMethod.GET)
    public String startCheckSignJob() {
        try {
            jobService.startCheckSignJob();
            return success("启动成功!");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
    }
    /**
     * 停止判断的任务
     *
     * @return
     */
    @RequestMapping(value = "stopCheckSignJob", method = RequestMethod.GET)
    public String stopCheckSignJob() {
        try {
            jobService.stopCheckSignJob();
            return success("停止成功!");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
    }
    /**
     * 启动所有任务
     *