Browse Source

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

chenweida 8 years ago
parent
commit
23b8bdfad2

+ 5 - 0
patient-co-statistics/pom.xml

@ -362,6 +362,11 @@
                <artifactId>spring-boot-starter-test</artifactId>
                <version>${version.spring-boot}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-mail</artifactId>
                <version>${version.spring-boot}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>

+ 38 - 1
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/controller/JobController.java

@ -364,5 +364,42 @@ public class JobController extends BaseController {
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
    }
    /**
     * 生成过去某一天的健康消息
     *
     * @param day
     * @return
     */
    @ApiOperation(value = "生成过去某一天的健康消息")
    @RequestMapping(value = "productHealthDataByOneDay", method = RequestMethod.GET)
    public String productHealthDataByOneDay( @ApiParam(name = "day", value = "yyyy-MM-dd")
                                           @RequestParam(value = "day", required = true)String day) {
        try {
            jobService.productHealthDataByOneDay(day);
            return success("启动成功!");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
    }
    /**
     * 生成过去某一天到某一天的某个指标的数据
     *
     * @param start
     * @param end
     * @return
     */
    @ApiOperation(value = "生成过去某一天到某一天的健康消息(包含头尾)")
    @RequestMapping(value = "productHealthDataByDayToDay", method = RequestMethod.GET)
    public String productHealthDataByDayToDay( @ApiParam(name = "start", value = "yyyy-MM-dd")@RequestParam(value = "start", required = true)String start,
                                              @ApiParam(name = "end", value = "yyyy-MM-dd")@RequestParam(value = "end", required = true)String end
                                             ) {
        try {
            jobService.productHealthDataByDayToDay(start,end);
            return success("启动成功!");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
    }
}

+ 117 - 0
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/etl/dataFilter/SignDataFilter.java

@ -460,7 +460,122 @@ public class SignDataFilter {
            return Constant.level_age_6;
        }
    }
    public FilterModel filterNoTeam(List<SignFamily> signFamilies ,String level2Key,String level3Key, String sql, String filterDate) {
        //查找出系统全部的机构
        List<Hospital> hospitals = hospitalDao.findHospital2();
        Map<String, Hospital> hospitalsMap = new HashMap<String, Hospital>();
        for (Hospital hospital : hospitals) {
            hospitalsMap.put(hospital.getCode(), hospital);
        }
        //查找出厦门市全部的区
        List<Town> towns = townDao.findByCityCode(Constant.city);
        Map<String, Town> townsMap = new HashMap<String, Town>();
        for (Town town : towns) {
            townsMap.put(town.getCode(), town);
        }
        List<ETLModel> etlModelList=new ArrayList<>();//返回的ETL數據
        Long cityCount = new Long(0L); //统计到市的数目
        Long townCount = new Long(0L); //统计到所有区的数目
        Long orgCount =new Long(0L);//统计到所有机构的数目
        Long adminCount = new Long(0L);//统计到所有团队的数目
        Long errorCount=new Long(0L);//脏数据
        Boolean isAll=true;//是否统计失败
        LogModel logModel=new LogModel();
        errorModels=new ArrayList<ErrorModel>();
        for (int i=0;i<signFamilies.size();i++){
            SignFamily signFamily=signFamilies.get(i);
            String orgCode = signFamily.getHospital();
            if(StringUtils.isEmpty(orgCode)) {
                errorModels.add(ErrorModel.newEM(signFamily.getCode(),ErrorModel.sign_hospital_null));
                isAll=false;
                errorCount++;
                continue;
            }
            if(orgCode.length()!=10) {
                errorModels.add(ErrorModel.newEM(signFamily.getCode(),ErrorModel.sign_hospital_isTest));
                isAll=false;
                errorCount++;
                continue;
            }
            String orgCodeTemp="";
            if(!"00".equals(orgCode.substring(orgCode.length()-2,orgCode.length()))){
                //站
                orgCodeTemp=orgCode.substring(0,orgCode.length()-2)+"00";
            }else{
                //社区
                orgCodeTemp=orgCode;
            }
            //判断社区有没有值
            Hospital hospital=hospitalsMap.get(orgCodeTemp);
            if(hospital == null) {
                errorModels.add(ErrorModel.newEM(signFamily.getCode(),ErrorModel.sign_hospital_noExist));
                isAll=false;
                errorCount++;
                continue;
            }
            String town =hospital.getTown();
            if(StringUtils.isEmpty(town)) {
                errorModels.add(ErrorModel.newEM(signFamily.getCode(),ErrorModel.sign_town_null));
                isAll=false;
                errorCount++;
                continue;
            }
            Town townObj =townsMap.get(town);
            if(townObj==null) {
                errorModels.add(ErrorModel.newEM(signFamily.getCode(),ErrorModel.sign_town_noExist));
                isAll=false;
                errorCount++;
                continue;
            }
            String idCard=signFamily.getIdcard();
            if(idCard == null||((idCard.length()!=18&&idCard.length()!=15))) {
                errorModels.add(ErrorModel.newEM(signFamily.getCode(),ErrorModel.sign_idcard_error));
                isAll=false;
                errorCount++;
                continue;
            }
            //设置二级维度的Key
            String returnLevel2Key=getLevel2Key(level2Key,signFamily);
            String returnLevel3Key=getLevel3Key(level3Key,signFamily);
            if(StringUtils.isEmpty(returnLevel2Key)){
                //没有二级维度
                ETLModel etlModel=new ETLModel();
                etlModel.setHospital(orgCodeTemp);
                etlModel.setTown(hospital.getTown());
                etlModel.setCity(Constant.city);
                etlModelList.add(etlModel);
            }else{
                String[] level2Keys=returnLevel2Key.split(",");
                for(int j=0;j<level2Keys.length;j++){
                    ETLModel etlModel=new ETLModel();
                    etlModel.setLevel2Key(level2Keys[j]);
                    etlModel.setLevel3Key(returnLevel3Key);
                    etlModel.setHospital(orgCodeTemp);
                    etlModel.setTown(hospital.getTown());
                    etlModel.setCity(Constant.city);
                    etlModelList.add(etlModel);
                }
            }
            //统计数目+1
            cityCount++;
            townCount++;
            orgCount++;
            adminCount++;
        }
        logModel.setDate(filterDate);
        logModel.setEndTime(new Date());
        logModel.setExcuteSql(sql);
        logModel.setSuccess(isAll);
        logModel.setAllNum(signFamilies.size());
        logModel.setSuccessNum(adminCount.intValue());
        logModel.setModelList(errorModels);
        logModel.setErrorNum(errorCount.intValue());
        //String message=saveContent(signFamilies.size(),adminCount,orgCount,townCount,cityCount,isAll,errorContent,errorCount,sql,filterDate);
        return FilterModel.getFiltrerMode(logModel,etlModelList,isAll);
    }
    /**
     * 根据年龄得到对应的code
     *
@ -474,4 +589,6 @@ public class SignDataFilter {
            return Constant.level_age2_2;
        }
    }
}

+ 22 - 0
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/etl/role/Level1Role.java

@ -66,4 +66,26 @@ public class Level1Role {
            eltMap.put(key,etlModels);
        }
    }
    public List<Map<String,List<ETLModel>>> eltNoTeam(List<ETLModel> models) {
        List<Map<String, List<ETLModel>>> returnMapsList=new ArrayList<Map<String, List<ETLModel>>>();
        Map<String, List<ETLModel>> tjCityMap = new HashMap<String, List<ETLModel>>();//市级的统计map key 是区行政区划350200
        Map<String, List<ETLModel>> tjTownMap = new HashMap<String, List<ETLModel>>();//区级的统计map key 是区行政区划350206
        Map<String, List<ETLModel>> tjOrgMap = new HashMap<String, List<ETLModel>>();//机构的统计map key 是机构的code
        for(ETLModel etlModel:models){
            //统计市市
            compute(tjCityMap, etlModel.getCity(),etlModel);
            //统计市区
            compute(tjTownMap, etlModel.getTown(),etlModel);
            //统计市机构
            compute(tjOrgMap, etlModel.getHospital(),etlModel);
        }
        returnMapsList.add(1,tjOrgMap);
        returnMapsList.add(2,tjTownMap);
        returnMapsList.add(3,tjCityMap);
        return returnMapsList;
    }
}

+ 30 - 0
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/etl/storage/DBStorage.java

@ -846,4 +846,34 @@ public class DBStorage   {
            return statementCreator;
        });
    }
    public void saveByLevel1NoTeam(List<Map<String, List<ETLModel>>> data, String date, WlyyQuotaVO wlyyQuota) throws Exception{
        this.wlyyQuota=wlyyQuota;
        List<AdminTeam> adminTeams=doctorAdminTeamDao.findAllTeam();
        for (AdminTeam adminTeam : adminTeams) {
            adminTeamMap.put(adminTeam.getId()+"", adminTeam);
        }
        //查找出系统全部的机构
        List<Hospital> hospitals = hospitalDao.findHospitalzxFWZ();
        for (Hospital hospital : hospitals) {
            hospitalsMap.put(hospital.getCode(), hospital);
        }
        //查找出厦门市全部的区
        List<Town> towns = townDao.findByCityCode(Constant.city);
        for (Town town : towns) {
            townsMap.put(town.getCode(), town);
        }
        //全部的市
        Map<String, City> cityMap = new HashMap<String, City>();
        City city=new City();
        city.setCode(Constant.city);
        city.setName(Constant.cityName);
        cityMap.put(Constant.city,city);
        //保存机构
        saveAll(saveHospitalTeamDataLevel1(data.get(1),date,hospitalsMap));
        //保存区
        saveAll(saveTownTeamDataLevel1(data.get(2),date,townsMap));
        //保存市
        saveAll(saveCityTeamDataLevel1(data.get(3),date,cityMap));
    }
}

+ 3 - 3
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/WaitSignJob.java

@ -92,11 +92,11 @@ public class WaitSignJob implements Job {
            //抽取數據
            List<SignFamily> signFamilies= dbExtract.extract(SignFamily.class,sql);
            //清洗數據
            FilterModel etlModels= signDataFilter.filter(signFamilies,sql,yesterday);
            FilterModel etlModels= signDataFilter.filterNoTeam(signFamilies,null,null,sql,yesterday);
            //统计数据
            List<Map<String, List<ETLModel>>>  returnDatas= levelRole.elt(etlModels.getEtlModelList());
            List<Map<String, List<ETLModel>>>  returnDatas= levelRole.eltNoTeam(etlModels.getEtlModelList());
            //保存数据
            dbStorage.saveByLevel1(returnDatas,yesterday,wlyyQuota);
            dbStorage.saveByLevel1NoTeam(returnDatas,yesterday,wlyyQuota);
            //保存日志
            quartzJobLog.setJobEndTime(new Date());
            quartzJobLog.setJobContent(JsonUtil.objToStr(etlModels.getLogModel()));

+ 26 - 192
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/check/CheckSignJob.java

@ -1,27 +1,20 @@
package com.yihu.wlyy.statistics.job.check;
import com.yihu.wlyy.statistics.dao.*;
import com.yihu.wlyy.statistics.job.business.QuartzHelper;
import com.yihu.wlyy.statistics.job.business.SignAgeGroupDiseaseJob;
import com.yihu.wlyy.statistics.job.business.SignJob;
import com.yihu.wlyy.statistics.model.job.QuartzJobConfig;
import com.yihu.wlyy.statistics.model.job.WlyyQuota;
import com.yihu.wlyy.statistics.model.job.WlyyQuotaResult;
import com.yihu.wlyy.statistics.model.signfamily.SignFamily;
import com.yihu.wlyy.statistics.util.DateUtil;
import com.yihu.wlyy.statistics.vo.WlyyJobConfigVO;
import com.yihu.wlyy.statistics.vo.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.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
import java.util.*;
import java.util.Date;
/**
 * Created by Administrator on 2016.10.11.
@ -30,201 +23,42 @@ import java.util.*;
@Component
@Scope("prototype")
public class CheckSignJob implements Job{
    public static String jobKey="CHECK_SIGN_JOB";
    public static String cron="0 0 12 * * ?";
    public static String cron="0 */5 * * * ?";
    @Autowired
    private WlyyQuotaResultDao wlyyQuotaResultDao;
    @Autowired
    private SignFamilyDao signFamilyDao;
    @Autowired
    private QuartzHelper quartzHelper;
    private StringRedisTemplate redisTemplate;
    @Autowired
    private QuartzJobConfigDao wlyyJobConfigDao;
    @Autowired
    private QuotaDao quotaDao;
    private JavaMailSender javaMailSender;
    @Value("${spring.mail.from}")
    private String from;;
    @Value("${spring.mail.to}")
    private String to;;
    @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){
            //如果出錯立即重新執行
            JobExecutionException e2 =new JobExecutionException(e);
            e2.setRefireImmediately(true);
        }
    }
    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 daybefore=getNextDate(wlyyQuotaResult.getQuotaDate());
                String yesterday=wlyyQuotaResult.getQuotaDate();
                //往quartz框架添加任务
                params.put("daybefore", daybefore);
                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,daybefore);
                    startJob("7",yesterday,daybefore);
                    startJob("8",yesterday,daybefore);
                    startJob("12",yesterday,daybefore);
                }
            }
        }
    }
    private void startJob(String id, String yesterday, String daybefore) 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("daybefore", daybefore);
        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 SignAgeGroupDiseaseJob.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);
            String timeKey=redisTemplate.opsForValue().get("quota:timeKey");
            if(!redisTemplate.hasKey("quota:16:4:350200:"+timeKey)){
                //发送邮件给管理员
                sendEmail();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        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);
    }
    private void sendEmail() throws Exception {
    /**
     * 得到需要检验的统计
     * @return
     */
    private List<WlyyQuotaResult> getNeedCheckData() {
        List<WlyyQuotaResult> wlyyQuotaResults=wlyyQuotaResultDao.findByLevel1TypeAndQkdoctorJobName("4","1");
        return wlyyQuotaResults;
        SimpleMailMessage message=new SimpleMailMessage();
        message.setFrom(from);//发送者.
        message.setSubject("实时统计失败");//邮件主题.
        message.setText("实时统计失败,redis数据生成失败 時間:"+ DateUtil.dateToStrLong(new Date()));//邮件内容.
        message.setTo(to);
        javaMailSender.send(message);
    }
    /**
     * 获取当前时间所在的凌晨时间
     *  凌晨
     * @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();
    }
}

+ 19 - 6
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/message/HealthMessageJob.java

@ -12,6 +12,7 @@ import org.springframework.context.annotation.Scope;
import org.springframework.jdbc.core.JdbcTemplate;
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.text.SimpleDateFormat;
@ -36,14 +37,26 @@ public class HealthMessageJob implements Job {
    @Transactional
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
            try{
        try{
            SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
            String yesterday=jobExecutionContext.getMergedJobDataMap().getString("yesterday");
            String now=jobExecutionContext.getMergedJobDataMap().getString("yesterday");
            if(StringUtils.isEmpty(yesterday)){
                yesterday=getYesterday(-1,new Date());
            }
            if(StringUtils.isEmpty(now)){
                now=getYesterday(0,new Date());
            }
            //删除原来的数据
            String deleteSql="delete from wlyy_message where type=3 and czrq >= '"+yesterday+"17:00:00'and czqr <= '"+now+" 17:00:00'";
            jdbcTemplate.execute(deleteSql);
            //生成新的数据
            String sql="select doctor,doctor_name from wlyy_sign_family " +
                    " where  status >0 and type='2' and expenses_status='1'  " +
                    " and expenses_time >='"+getYesterday(-1,new Date())+" 17:00:00' and expenses_time<'"+getYesterday(0,new Date())+" 17:00:00' and  (doctor_health is null or doctor_health = '')" ;
                    " and expenses_time >='"+yesterday+" 17:00:00' and expenses_time<'"+now+" 17:00:00' and  (doctor_health is null or doctor_health = '')" ;
            String countSql="select count(id) from wlyy_sign_family " +
                    " where  status >0 and type='2' and expenses_status='1'  " +
                    " and expenses_time >='"+getYesterday(-1,new Date())+" 17:00:00' and expenses_time<'"+getYesterday(0,new Date())+" 17:00:00' and  (doctor_health is null or doctor_health = '')" ;
                    " and expenses_time >='"+yesterday+" 17:00:00' and expenses_time<'"+now+" 17:00:00' and  (doctor_health is null or doctor_health = '')" ;
            List<SignFamily> signFamilyList=dbExtract.extractByPage(SignFamily.class,sql,countSql,true);
            Map<String,List<SignFamily>> signFamilyMap=new HashMap<String,List<SignFamily>>();
            for(int i=0;i<signFamilyList.size();i++){
@ -59,7 +72,7 @@ public class HealthMessageJob implements Job {
            for(Map.Entry<String,List<SignFamily>> entry:signFamilyMap.entrySet()){
                 countSql="select count(id) from wlyy_sign_family " +
                        " where  status >0 and type='2' and expenses_status='1'  " +
                        "  and expenses_time<'"+getYesterday(0,new Date())+" 17:00:00' and  (doctor_health is null or doctor_health = '') and doctor='"+entry.getKey()+"'" ;
                        "  and expenses_time<'"+now+" 17:00:00' and  (doctor_health is null or doctor_health = '') and doctor='"+entry.getKey()+"'" ;
                Integer allCount=jdbcTemplate.queryForObject(countSql,Integer.class);
                Message message=new Message();
@ -68,12 +81,12 @@ public class HealthMessageJob implements Job {
                message.setOver("0");
                message.setDel("1");
                message.setSender("system");
                message.setCzrq(new Date());
                message.setCzrq(new SimpleDateFormat("yyyy-MM-dd").parse(now));
                message.setState(1);
                message.setTitle("新增系统消息");
                SimpleDateFormat dateFormat=new SimpleDateFormat("MM月dd日");
                String date=  dateFormat.format(new Date());
                message.setContent(date+",新增"+entry.getValue().size()+"个签约居民待分配健管师,目前共"+allCount+"人待处理");
                message.setContent(date+"新增"+entry.getValue().size()+"个签约居民待分配健管师,目前共"+allCount+"人待处理");
                message.setCode(UUID.randomUUID().toString());
                message.setReceiver(entry.getKey());
                messageDao.save(message);

+ 41 - 0
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/service/JobService.java

@ -351,12 +351,16 @@ public class JobService {
    public void startCleanCacheJob() throws  Exception {
        if(!quartzHelper.isExistJob(CacheCleanJob.jobKey)){
            quartzHelper.addJob(CacheCleanJob.class,CacheCleanJob.cron,CacheCleanJob.jobKey,new HashMap<>());
        }else{
            throw new Exception("已经启动");
        }
    }
    public void stopCleanCacheJob()throws  Exception  {
        if(quartzHelper.isExistJob(CacheCleanJob.jobKey)){
            quartzHelper.removeJob(CacheCleanJob.jobKey);
        }else{
            throw new Exception("已经停止");
        }
    }
@ -382,12 +386,49 @@ public class JobService {
    public void startHealthMessageJob() throws Exception {
        if(!quartzHelper.isExistJob(HealthMessageJob.jobKey)){
            quartzHelper.addJob(HealthMessageJob.class,HealthMessageJob.cron,HealthMessageJob.jobKey,new HashMap<>());
        }else{
            throw new Exception("已经启动");
        }
    }
    public void stopHealthMessageJob()throws Exception  {
        if(quartzHelper.isExistJob(HealthMessageJob.jobKey)){
            quartzHelper.removeJob(HealthMessageJob.jobKey);
        }else{
            throw new Exception("已经停止");
        }
    }
    public void productHealthDataByOneDay(String day)throws Exception {
        SimpleDateFormat dataSimple = new SimpleDateFormat("yyyy-MM-dd");
        Date date = dataSimple.parse(day);
        if (date == null) {
            throw new Exception("时间格式错误");
        }
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(calendar.DATE, -1);//把日期往后增加一天.整数往后推,负数往前移动
        Date nowDate = calendar.getTime();   //这个时间就是日期往后推一天的结果
        String yesterday = new SimpleDateFormat("yyyy-MM-dd").format(nowDate.getTime());
        Map<String, Object> params = new HashMap<String, Object>();
        //往quartz框架添加任务
        params.put("now", day);
        params.put("yesterday", yesterday);
        quartzHelper.startNow(HealthMessageJob.class, HealthMessageJob.jobKey + UUID.randomUUID().toString().replace("-",""), params);
        Thread.sleep(20000L);
    }
    public void productHealthDataByDayToDay(String start, String end) 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("日期参数错误");
        }
        int day=daysBetween(startDate,endDate);
        for(int i=0;i<day;i++){
            productHealthDataByOneDay(getYesterday(i,startDate));
        }
    }
}

+ 16 - 1
patient-co-statistics/src/main/resources/application.yml

@ -53,7 +53,22 @@ spring:
      max-wait: -1 # Maximum amount of time (in milliseconds) a connection allocation should block before throwing an exception when the pool is exhausted. Use a negative value to block indefinitely.
      min-idle: 1 # Target for the minimum number of idle connections to maintain in the pool. This setting only has an effect if it is positive.
  mail:
    default-encoding: utf8
    protocol: smtp
    host: smtp.qq.com
    port: 465
    username: 1501877145
    from: 1501877145@qq.com
    to: 494679975@qq.com #接受者
    password: pnubhfagxeophfej
    properties:
      mail:
        transport:
        smtp:
          auth: true #是否开始权限验证
          ssl:
            enable: true #使用sslmail.transport.protocol
multipart:
  max-file-size: 100MB