Browse Source

bug提交

chenweida 7 years ago
parent
commit
34a2dce2ad

+ 1 - 1
patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/dao/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.del='1' order by a.id asc")
    @Query(" FROM QuartzJobConfig a WHERE  a.del='1' and a.id !=11 order by a.id asc")
    List<QuartzJobConfig> findByIds();
    @Query(" FROM QuartzJobConfig a WHERE a.id=?1 and a.del='1'")

+ 5 - 5
patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/etl/compute/ComputeHelper.java

@ -30,18 +30,18 @@ public class ComputeHelper {
    /**
     * @param dataModels      过滤之后的数据
     * @param dimensionQuotas 指标的维度
     * @param wlyyJobConfigVO
     * @param wlyyJobCongId
     * @param endTime
     * @return
     */
    public List<SaveModel> compute(List<DataModel> dataModels, List<WlyyDimensionQuota> dimensionQuotas, WlyyJobConfigVO wlyyJobConfigVO, String endTime, String timeLevel) {
    public List<SaveModel> compute(List<DataModel> dataModels, List<WlyyDimensionQuota> dimensionQuotas, String wlyyJobCongId, String endTime, String timeLevel) {
        try {
            //得到全部团队
            List<AdminTeam> teams = findAllTeam();
            //计算数据 返回map key 根据团队和维度拼凑在map中的key   1-2-1  如果维度是长度是0返回团队id 1
            Map<String, List<DataModel>> computeMap = computeDataModel(dimensionQuotas, dataModels);
            //初始化map并且设置统计出来的数目
            List<SaveModel> savemodels = initAndSetResult(teams, dimensionQuotas, computeMap, wlyyJobConfigVO, endTime, timeLevel);
            List<SaveModel> savemodels = initAndSetResult(teams, dimensionQuotas, computeMap, wlyyJobCongId, endTime, timeLevel);
            return savemodels;
        } catch (Exception e) {
@ -127,7 +127,7 @@ public class ComputeHelper {
    /**
     * 初始化map
     */
    private List<SaveModel> initAndSetResult(List<AdminTeam> teams, List<WlyyDimensionQuota> dimensionQuotas, Map<String, List<DataModel>> countMap, WlyyJobConfigVO wlyyJobConfigVO, String endTime, String timeLevel) throws Exception {
    private List<SaveModel> initAndSetResult(List<AdminTeam> teams, List<WlyyDimensionQuota> dimensionQuotas, Map<String, List<DataModel>> countMap, String wlyyJobCongId, String endTime, String timeLevel) throws Exception {
        List<SaveModel> returnList = new ArrayList<>();
        Map<String, SaveModel> lastMaps = new HashMap<>();
@ -150,7 +150,7 @@ public class ComputeHelper {
                saveModel.setHospitalName(one.getOrgName());
                saveModel.setTeam(one.getId().toString());
                saveModel.setTeamName(one.getName());
                saveModel.setQuotaCode(wlyyJobConfigVO.getId());
                saveModel.setQuotaCode(wlyyJobCongId);
                saveModel.setCreateTime(new Date());
                saveModel.setTimeLevel(timeLevel);
                saveModel.setAreaLevel("5");//团队

+ 4 - 0
patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/etl/convert/wlyy/SimpleConvert.java

@ -6,6 +6,7 @@ import com.yihu.wlyy.statistics.model.dimension.WlyyDimensionQuota;
import com.yihu.wlyy.statistics.util.IdCardUtil;
import com.yihu.wlyy.statistics.vo.DataModel;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.util.StringUtils;
import java.util.List;
@ -23,6 +24,9 @@ public class SimpleConvert implements Convert {
        oneList.stream().forEach(one -> {
            try {
                Object value = DataModel.class.getMethod("get" + temp.getKey()).invoke(one);
                if(StringUtils.isEmpty(value)){
                    value="0";
                }
                DataModel.class.getMethod("setSlaveKey" + slaveLevel, String.class).invoke(one, value.toString());
            } catch (Exception e) {
                e.printStackTrace();

+ 6 - 1
patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/etl/extract/ExtractHelper.java

@ -1,6 +1,7 @@
package com.yihu.wlyy.statistics.etl.extract;
import com.yihu.wlyy.statistics.etl.extract.db.DBExtract;
import com.yihu.wlyy.statistics.model.job.QuartzJobConfig;
import com.yihu.wlyy.statistics.util.SpringUtil;
import com.yihu.wlyy.statistics.vo.DataModel;
import com.yihu.wlyy.statistics.vo.WlyyJobConfigVO;
@ -44,7 +45,7 @@ public class ExtractHelper {
     * @return
     * @throws Exception
     */
    public List<DataModel> extractData(WlyyJobConfigVO wlyyJobConfigVO, String startTime, String endTime, String year, String timeLevel) throws Exception {
    public List<DataModel> extractData(QuartzJobConfig wlyyJobConfigVO, String startTime, String endTime, String year, String timeLevel) throws Exception {
        try {
            this.startTime = startTime;
            this.endTime = endTime;
@ -56,6 +57,10 @@ public class ExtractHelper {
            } else {
                timeSql = wlyyJobConfigVO.getSqlDay();
            }
            //如果为null 初始化
            if(StringUtils.isEmpty(timeSql)){
                timeSql="";
            }
            //设置时间
            String sql = initSql(wlyyJobConfigVO.getSql() + "  " + timeSql, startTime, endTime, year);
            String sqlCount = initSql(wlyyJobConfigVO.getSqlCount() + "  " + timeSql, startTime, endTime, year);

+ 5 - 9
patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/job/business/CurrentMysqlToEsQuotaJob.java

@ -244,9 +244,7 @@ public class CurrentMysqlToEsQuotaJob implements Job {
     */
    private List<SaveModel> compute(List<DataModel> dataModels, List<WlyyDimensionQuota> dimensionQuotas, String timeLevel, QuartzJobConfig quartzJobConfig) {
        try {
            WlyyJobConfigVO wlyyJobConfigVO = new WlyyJobConfigVO();
            BeanUtils.copyProperties(quartzJobConfig, wlyyJobConfigVO);
            return SpringUtil.getBean(ComputeHelper.class).compute(dataModels, dimensionQuotas, wlyyJobConfigVO, endTime, timeLevel);
            return SpringUtil.getBean(ComputeHelper.class).compute(dataModels, dimensionQuotas, quartzJobConfig.getId(), endTime, timeLevel);
        } catch (Exception e) {
            logger.error("compute error:" + e.getMessage());
        }
@ -275,21 +273,19 @@ public class CurrentMysqlToEsQuotaJob implements Job {
     */
    private List<DataModel> extract(QuartzJobConfig quartzJobConfig) {
        try {
            WlyyJobConfigVO wlyyJobConfigVO = new WlyyJobConfigVO();
            BeanUtils.copyProperties(quartzJobConfig, wlyyJobConfigVO);
            List<DataModel> dataModels = null;
            //先判断指标是否支持缓存
            if (StringUtils.isEmpty(wlyyJobConfigVO.getCacheKey())) {
            if (StringUtils.isEmpty(quartzJobConfig.getCacheKey())) {
                //不支持直接去数据库拿
                dataModels = SpringUtil.getBean(ExtractHelper.class).extractData(wlyyJobConfigVO, startTime, endTime, year, timeLevel);
                dataModels = SpringUtil.getBean(ExtractHelper.class).extractData(quartzJobConfig, startTime, endTime, year, timeLevel);
            } else {
                //缓存的key 是 时间+timelevel+key
                StringBuffer bu = new StringBuffer(DateUtil.dateToStr(quotaDate, "yyyy-MM-dd") + "-" + timeLevel + wlyyJobConfigVO.getCacheKey());
                StringBuffer bu = new StringBuffer(DateUtil.dateToStr(quotaDate, "yyyy-MM-dd") + "-" + timeLevel + quartzJobConfig.getCacheKey());
                //支持的话判断缓存有没有值
                dataModels = Cache.getCache(bu.toString());
                if (dataModels == null) {
                    //如果缓存是空的那么直接数据库拿 在放入缓存
                    dataModels = SpringUtil.getBean(ExtractHelper.class).extractData(wlyyJobConfigVO, startTime, endTime, year, timeLevel);
                    dataModels = SpringUtil.getBean(ExtractHelper.class).extractData(quartzJobConfig, startTime, endTime, year, timeLevel);
                    Cache.addCache(bu.toString(), dataModels);
                }
            }

+ 20 - 15
patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/job/business/MysqlToEsQuotaJob.java

@ -1,5 +1,6 @@
package com.yihu.wlyy.statistics.job.business;
import com.yihu.wlyy.statistics.dao.QuartzJobConfigDao;
import com.yihu.wlyy.statistics.dao.QuartzJobLogDao;
import com.yihu.wlyy.statistics.dao.WlyyDimensionQuotaDao;
import com.yihu.wlyy.statistics.etl.cache.Cache;
@ -10,6 +11,7 @@ import com.yihu.wlyy.statistics.etl.filter.FilterHelper;
import com.yihu.wlyy.statistics.etl.save.SaveHelper;
import com.yihu.wlyy.statistics.etl.save.es.ElasticFactory;
import com.yihu.wlyy.statistics.model.dimension.WlyyDimensionQuota;
import com.yihu.wlyy.statistics.model.job.QuartzJobConfig;
import com.yihu.wlyy.statistics.model.job.QuartzJobLog;
import com.yihu.wlyy.statistics.util.DateUtil;
import com.yihu.wlyy.statistics.util.SpringUtil;
@ -54,7 +56,8 @@ public class MysqlToEsQuotaJob implements Job {
    private Logger logger = LoggerFactory.getLogger(MysqlToEsQuotaJob.class);
    private WlyyJobConfigVO wlyyJobConfigVO;//指标对象
    private String wlyyJobCongId;//指标对象
    private QuartzJobConfig quartzJobConfig;//指标对象
    private String endTime;//结束时间
    private String startTime;//开始时间
    private String year;//要统计的年份
@ -65,6 +68,8 @@ public class MysqlToEsQuotaJob implements Job {
    private QuartzJobLogDao quartzJobLogDao;//执行日志Dao
    @Autowired
    private WlyyDimensionQuotaDao dimensionQuotaDao;
    @Autowired
    private QuartzJobConfigDao quartzJobConfigDao;
    @Autowired
    private ElasticFactory elasticFactory;
@ -115,7 +120,7 @@ public class MysqlToEsQuotaJob implements Job {
        if ("2".equals(timeLevel)) {
            //按年度到达量
            startTime = this.year + "-06-30 17:00:00";
        }else{
        } else {
            //增量
            if (StringUtils.isEmpty(startTime)) {
                startTime = new LocalDate(new DateTime().minusDays(2)).toString("yyyy-MM-dd") + " 17:00:00"; //2017-06-01 17:00:00
@ -126,8 +131,8 @@ public class MysqlToEsQuotaJob implements Job {
        this.quotaDate = DateUtil.strToDate(endTime, "yyyy-MM-dd");
        this.wlyyJobConfigVO = (WlyyJobConfigVO) map.get("jobConfig");
        this.wlyyJobCongId = map.getString("jobConfig");
        this.quartzJobConfig=quartzJobConfigDao.findById(wlyyJobCongId);
    }
    /**
@ -135,19 +140,19 @@ public class MysqlToEsQuotaJob implements Job {
     */
    private void computequota() {
        try {
            logger.info("========================quotaCode:" + wlyyJobConfigVO.getId() + ","+DateUtil.dateToStr(quotaDate, "yyyy-MM-dd")+",timeLevel:"+timeLevel+" start========================");
            logger.info("========================quotaCode:" + wlyyJobCongId + "," + DateUtil.dateToStr(quotaDate, "yyyy-MM-dd") + ",timeLevel:" + timeLevel + " start========================");
            QuartzJobLog tjQuotaLog = new QuartzJobLog();
            tjQuotaLog.setJobId(wlyyJobConfigVO.getId());
            tjQuotaLog.setJobId(wlyyJobCongId);
            tjQuotaLog.setJobStartTime(new Date());
            // 0 删除这天的数据
            deleteData(quotaDate, wlyyJobConfigVO.getId(), timeLevel);
            deleteData(quotaDate, wlyyJobCongId, timeLevel);
            //1..抽取数据 如果是累加就是 List<DataModel>  如果是相除 Map<String,List<DataModel>>
            List<DataModel> dataModels = extract();
            //2..根据规则过滤数据
            FilterModel filterModel = filter(dataModels);
            //得到该指标的维度
            List<WlyyDimensionQuota> dimensionQuotas = dimensionQuotaDao.findDimensionQuotasByQuotaCode(wlyyJobConfigVO.getId());
            List<WlyyDimensionQuota> dimensionQuotas = dimensionQuotaDao.findDimensionQuotasByQuotaCode(wlyyJobCongId);
            //2.1.从维度的key转换
            if (dimensionQuotas != null && dimensionQuotas.size() > 0) {
                filterModel = convert(filterModel, dimensionQuotas);
@ -161,7 +166,7 @@ public class MysqlToEsQuotaJob implements Job {
            tjQuotaLog.setJobEndTime(new Date());
            tjQuotaLog.setJobContent(JSONArray.fromObject(filterModel.getErrorModels()).toString());
            saveLog(tjQuotaLog);
            logger.info("========================quotaCode:" + wlyyJobConfigVO.getId() + ","+DateUtil.dateToStr(quotaDate, "yyyy-MM-dd")+" end========================");
            logger.info("========================quotaCode:" + wlyyJobCongId + "," + DateUtil.dateToStr(quotaDate, "yyyy-MM-dd") + " end========================");
        } catch (Exception e) {
            e.printStackTrace();
        }
@ -241,7 +246,7 @@ public class MysqlToEsQuotaJob implements Job {
     */
    private List<SaveModel> compute(List<DataModel> dataModels, List<WlyyDimensionQuota> dimensionQuotas, String timeLevel) {
        try {
            return SpringUtil.getBean(ComputeHelper.class).compute(dataModels, dimensionQuotas, wlyyJobConfigVO, endTime, timeLevel);
            return SpringUtil.getBean(ComputeHelper.class).compute(dataModels, dimensionQuotas, wlyyJobCongId, endTime, timeLevel);
        } catch (Exception e) {
            logger.error("compute error:" + e.getMessage());
        }
@ -274,21 +279,21 @@ public class MysqlToEsQuotaJob implements Job {
        try {
            List<DataModel> dataModels = null;
            //先判断指标是否支持缓存
            if (StringUtils.isEmpty(wlyyJobConfigVO.getCacheKey())) {
            if (StringUtils.isEmpty(quartzJobConfig.getCacheKey())) {
                //不支持直接去数据库拿
                dataModels = SpringUtil.getBean(ExtractHelper.class).extractData(wlyyJobConfigVO, startTime, endTime, year, timeLevel);
                dataModels = SpringUtil.getBean(ExtractHelper.class).extractData(quartzJobConfig, startTime, endTime, year, timeLevel);
            } else {
                //缓存的key 是 时间+timelevel+key
                StringBuffer bu = new StringBuffer(DateUtil.dateToStr(quotaDate, "yyyy-MM-dd") + "-" + timeLevel + "-" + wlyyJobConfigVO.getCacheKey());
                StringBuffer bu = new StringBuffer(DateUtil.dateToStr(quotaDate, "yyyy-MM-dd") + "-" + timeLevel + "-" +quartzJobConfig.getCacheKey());
                //支持的话判断缓存有没有值
                dataModels = Cache.getCache(bu.toString());
                if (dataModels == null) {
                    //如果缓存是空的那么直接数据库拿 在放入缓存
                    dataModels = SpringUtil.getBean(ExtractHelper.class).extractData(wlyyJobConfigVO, startTime, endTime, year, timeLevel);
                    dataModels = SpringUtil.getBean(ExtractHelper.class).extractData(quartzJobConfig, startTime, endTime, year, timeLevel);
                    Cache.addCache(bu.toString(), dataModels);
                }
            }
            logger.info("quotaCode:" + wlyyJobConfigVO.getId() + ",size:" + dataModels.size());
            logger.info("quotaCode:" + wlyyJobCongId + ",size:" + dataModels.size());
            return dataModels;
        } catch (Exception e) {
            logger.error("extract error:" + e.getMessage());

+ 1 - 1
patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/model/job/QuartzJobConfig.java

@ -8,7 +8,7 @@ import javax.persistence.*;
 * 计划任务
 */
@Entity
@Table(name = "wlyy_job_config")
@Table(name = "wlyy_job_config_cwd")
public class QuartzJobConfig implements java.io.Serializable {
	private String id;

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

@ -118,8 +118,8 @@ public class JobService {
        WlyyJobConfigVO wlyyJobConfigVO = new WlyyJobConfigVO();
        BeanUtils.copyProperties(quartzJobConfig, wlyyJobConfigVO);
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("jobConfig", wlyyJobConfigVO);
        Map<String, String> params = new HashMap<String, String>();
        params.put("jobConfig", wlyyJobConfigVO.getId());
        for (int i = 1; i <= 2; i++) {
            params.put("timeLevel", i + "");
            //往quartz框架添加任务
@ -137,8 +137,8 @@ public class JobService {
            WlyyJobConfigVO wlyyJobConfigVO = new WlyyJobConfigVO();
            BeanUtils.copyProperties(quartzJobConfig, wlyyJobConfigVO);
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("jobConfig", wlyyJobConfigVO);
            Map<String, String> params = new HashMap<String, String>();
            params.put("jobConfig", wlyyJobConfigVO.getId());
            for (int i = 1; i <= day; i++) {
                for (int j = 1; j <= 2; j++) {
                    params.put("timeLevel", j + "");
@ -179,8 +179,8 @@ public class JobService {
            WlyyJobConfigVO wlyyJobConfigVO = new WlyyJobConfigVO();
            BeanUtils.copyProperties(quartzJobConfig, wlyyJobConfigVO);
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("jobConfig", wlyyJobConfigVO);
            Map<String, String> params = new HashMap<String, String>();
            params.put("jobConfig", wlyyJobConfigVO.getId());
            //往quartz框架添加任务
            params.put("startTime", daybefore);
            params.put("endTime", yesterday);
@ -224,8 +224,8 @@ public class JobService {
        WlyyJobConfigVO wlyyJobConfigVO = new WlyyJobConfigVO();
        BeanUtils.copyProperties(quartzJobConfig, wlyyJobConfigVO);
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("jobConfig", wlyyJobConfigVO);
        Map<String, String> params = new HashMap<String, String>();
        params.put("jobConfig", wlyyJobConfigVO.getId());
        //往quartz框架添加任务
        params.put("startTime", daybefore);
@ -254,8 +254,8 @@ public class JobService {
        WlyyJobConfigVO wlyyJobConfigVO = new WlyyJobConfigVO();
        BeanUtils.copyProperties(quartzJobConfig, wlyyJobConfigVO);
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("jobConfig", wlyyJobConfigVO);
        Map<String, String> params = new HashMap<String, String>();
        params.put("jobConfig", wlyyJobConfigVO.getId());
        for (int i = 1; i <= day; i++) {
            //往quartz框架添加任务
            params.put("startTime", getYesterday(0 - i - 1));
@ -361,7 +361,7 @@ public class JobService {
        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>();
        Map<String, String> params = new HashMap<String, String>();
        //往quartz框架添加任务
        params.put("now", yesterday);
        params.put("yesterday", day);

+ 3 - 3
patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/util/QuartzHelper.java

@ -76,7 +76,7 @@ public class QuartzHelper {
     * @param params
     * @throws Exception
     */
    public void startNow(Class jobClass, String id, Map<String, Object> params) throws Exception {
    public void startNow(Class jobClass, String id, Map<String, String> params) throws Exception {
        startAt(new Date(), jobClass, id, params);
    }
@ -89,14 +89,14 @@ public class QuartzHelper {
     * @param params
     * @throws Exception
     */
    public void startAt(Date time, Class jobClass, String id, Map<String, Object> params) throws Exception {
    public void startAt(Date time, Class jobClass, String id, Map<String, String> params) throws Exception {
        JobDetail job = JobBuilder.newJob(jobClass).
                withIdentity("job-id:" + id, "job-group:" + id)
                .build();
        JobDataMap jobDataMap = job.getJobDataMap();
        if(null != params) jobDataMap.putAll(params);
        SimpleTrigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger-id:" + id, "group-group:" + id)
        SimpleTrigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger-id:" + id, "trigger-group:" + id)
                .startAt(time)
                .withSchedule(simpleSchedule().withIntervalInSeconds(10).withRepeatCount(0).withMisfireHandlingInstructionFireNow())
                .build();

+ 2 - 1
patient-co-statistics-es/src/main/resources/quartz.properties

@ -7,7 +7,7 @@ org.quartz.scheduler.instanceName: DefaultQuartzScheduler
org.quartz.scheduler.rmi.export: false
org.quartz.scheduler.rmi.proxy: false
org.quartz.scheduler.wrapJobExecutionInUserTransaction: false
 
org.quartz.threadPool.class: org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount: 20
org.quartz.threadPool.threadPriority: 5
@ -23,6 +23,7 @@ org.quartz.jobStore.misfireThreshold: 60000
# org.quartz.jobStore.class: org.quartz.simpl.RAMJobStore
# Configure JobStore Cluster
org.quartz.jobStore.class:org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.useProperties=true
org.quartz.jobStore.driverDelegateClass:org.quartz.impl.jdbcjobstore.StdJDBCDelegate
#datasource׺
org.quartz.jobStore.tablePrefix:QRTZ_