Jelajahi Sumber

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

huangwenjie 7 tahun lalu
induk
melakukan
def312d4d4

+ 121 - 8
patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/service/JobService.java

@ -143,28 +143,25 @@ public class JobService {
    private boolean breakPoint(WlyyJobConfigVO wlyyJobConfigVO, int i) {
        //如果为空或者等3说明纪要生成到达量也要生成增量
        if (StringUtils.isEmpty(wlyyJobConfigVO.getTimeLevel()) || Integer.valueOf(wlyyJobConfigVO.getTimeLevel()) == 3) {
            return false;
            return true;
        }
        //如果不为空 并且是1或者2 说明只要增量或者只要到达量
        if (!(StringUtils.isEmpty(wlyyJobConfigVO.getTimeLevel())) && Integer.valueOf(wlyyJobConfigVO.getTimeLevel()) == i) {
            return false;
        }
        if(wlyyJobConfigVO.getIncrementInterval()!=1){
            return true;
        }
        return true;
        return false;
    }
    private boolean breakPoint(QuartzJobConfig wlyyJobConfigVO, int i) {
        //如果为空或者等3说明纪要生成到达量也要生成增量
        if (StringUtils.isEmpty(wlyyJobConfigVO.getTimeLevel()) || Integer.valueOf(wlyyJobConfigVO.getTimeLevel()) == 3) {
            return false;
            return true;
        }
        //如果不为空 并且是1或者2 说明只要增量或者只要到达量
        if (!(StringUtils.isEmpty(wlyyJobConfigVO.getTimeLevel())) && Integer.valueOf(wlyyJobConfigVO.getTimeLevel()) == i) {
            return false;
            return true;
        }
        return true;
        return false;
    }
    public void productDataByDay(Integer day) throws Exception {
@ -467,4 +464,120 @@ public class JobService {
            throw new Exception("已经停止");
        }
    }
    /**************************************按周或按月****************************************/
    public void productWeekByDayToDay(String start, String end,String id) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date startDate = sdf.parse(start);
        Date endDate = sdf.parse(end);
        if (startDate.after(endDate)) {
            throw new Exception("日期参数错误");
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(startDate);
        int a = calendar.get(Calendar.YEAR);
        calendar.clear();
        calendar.setTime(endDate);
        int b = calendar.get(Calendar.YEAR);
        int startWeek = DateUtil.week(startDate);
        if(a!=b){
            Date lastDate = DateUtil.getYearLast(a);
            int lastWeek = DateUtil.week(lastDate);
            for(int i=startWeek;i<=lastWeek;i++){
                start = getDate(startDate ,i,2);
                end = getDate(startDate ,i+1,1);
                productDataByOneDay2(start,end,2,id);
            }
            startDate =lastDate;
        }
        startWeek = DateUtil.week(startDate);
        int endWeek = DateUtil.week(endDate);
        for(int i=startWeek;i<=endWeek;i++){
            start = getDate(startDate ,i,2);
            end = getDate(startDate ,i+1,1);
            productDataByOneDay2(start,end,2,id);
        }
    }
    public void productMonthByDayToDay(String start, String end,String id) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date startDate = sdf.parse(start);
        Date endDate = sdf.parse(end);
        if (startDate.after(endDate)) {
            throw new Exception("日期参数错误");
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(startDate);
        int a = calendar.get(Calendar.YEAR);
        int a1 = calendar.get(Calendar.MONTH);
        calendar.clear();
        calendar.setTime(endDate);
        int b = calendar.get(Calendar.YEAR);
        int b1 = calendar.get(Calendar.MONTH);
        if(a!=b){
            for(int i=a1;i<=12;i++){
//            start = getDate(startDate ,i,1)+" 00:00:00";
//            end = getDate(startDate ,i,7)+" 59:59:59";
                start = DateUtil.getFristDayOfMonth(startDate);
                end = DateUtil.getLastDayOfMonth(startDate);
                productDataByOneDay2(start,end,3,id);
            }
            a1=1;
            calendar.clear();
            calendar.set(Calendar.YEAR, b);
            startDate = calendar.getTime();
        }
        for(int i=a1;i<=b1;i++){
            start = DateUtil.getFristDayOfMonth(startDate);
            end = DateUtil.getLastDayOfMonth(startDate);
            productDataByOneDay2(start,end,3,id);
        }
    }
    public void productDataByOneDay2(String start, String end,Integer incrementInterval,String id) throws Exception {
        String condition = "";
        if(!StringUtils.isEmpty(id)){
            condition+=" and a.id in ("+id+") ";
        }
        if(incrementInterval!=null){
            condition +=" and a.increment_interval ="+incrementInterval.intValue();
        }
        String sql = "select * from wlyy_job_config_new a where  a.del='1' and a.id !=11 "+condition+" order by a.id asc";
        List<QuartzJobConfig> quartzJobConfigs = jdbcTemplate.query(sql, new BeanPropertyRowMapper(QuartzJobConfig.class));
        for (QuartzJobConfig quartzJobConfig : quartzJobConfigs) {
            WlyyJobConfigVO wlyyJobConfigVO = new WlyyJobConfigVO();
            BeanUtils.copyProperties(quartzJobConfig, wlyyJobConfigVO);
            Map<String, String> params = new HashMap<String, String>();
            params.put("jobConfig", wlyyJobConfigVO.getId());
            //往quartz框架添加任务
            params.put("startTime", start);
            params.put("endTime", end);
            for (int j = 1; j <= 2; j++) {
//                if (Integer.valueOf(wlyyJobConfigVO.getId()) > 86 && j == 2) continue;
                params.put("timeLevel", j + "");
                if (!StringUtils.isEmpty(quartzJobConfig.getJobClass())) {
                    quartzHelper.startNow(getRightClass(quartzJobConfig), quartzJobConfig.getId() + UUID.randomUUID().toString().replace("-", ""), params);
                    Thread.sleep(sleepTime);
                }
            }
        }
    }
    public String getDate(Date date ,int weekNum,int day){
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(Calendar.WEEK_OF_YEAR, weekNum); // 设置为2016年的第10周
        cal.set(Calendar.DAY_OF_WEEK, day); // 1表示周日,2表示周一,7表示周六
        return sf.format(cal.getTime());
    }
}