esb 8 years ago
parent
commit
e1fc3009e0

+ 298 - 87
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/etl/storage/RedisStorage.java

@ -11,12 +11,14 @@ import com.yihu.wlyy.statistics.model.system.City;
import com.yihu.wlyy.statistics.model.system.Town;
import com.yihu.wlyy.statistics.model.team.AdminTeam;
import com.yihu.wlyy.statistics.util.DateUtil;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import springfox.documentation.spring.web.json.Json;
import java.util.*;
@ -27,6 +29,9 @@ import java.util.*;
@Component
@Scope("prototype")
public class RedisStorage {
    public static String timeKey="";
    public static List<String> keys=new ArrayList<String>();//全部的key
    private Map<String, AdminTeam> adminTeamMap = new HashMap<String, AdminTeam>();
    private Map<String, Hospital> hospitalsMap = new HashMap<String, Hospital>();
@ -46,6 +51,7 @@ public class RedisStorage {
     * @throws Exception
     */
    public void saveByLevel1(List<Map<String, List<ETLModel>>> data,List<Map<String, List<ETLModel>>> deleteData, String wlyyQuotaId) throws Exception {
        List<AdminTeam> adminTeams=doctorAdminTeamDao.findAllTeam();
        Map<String, AdminTeam> adminTeamMap = new HashMap<String, AdminTeam>();
        for (AdminTeam adminTeam : adminTeams) {
@ -74,7 +80,6 @@ public class RedisStorage {
        Map<String, List<ETLModel>> orgTeam=data.get(1);//机构的数据
        Map<String, List<ETLModel>> townTeam=data.get(2);//区的数据
        Map<String, List<ETLModel>> cityTeam=data.get(3);//市的数据
        redisTemplate.opsForValue().set("quota:date",DateUtil.dateToStrLong(new Date()));
        if(deleteData==null){
            //保存市
            saveLevel1City(wlyyQuotaId, cityMap, cityTeam);
@ -168,7 +173,6 @@ public class RedisStorage {
            //保存市
            saveCityTeamDataLevel3(data.get(3),deleteData.get(3),wlyyQuotaId,cityMap,foreachNum2,foreachNum3,type2,type3,start2,start3);
        }else{
            //保存团队
            saveAdminTeamDataLevel3(data.get(0),wlyyQuotaId,adminTeamMap,foreachNum2,foreachNum3,type2,type3,start2,start3);
            //保存机构
@ -218,8 +222,8 @@ public class RedisStorage {
                    JSONObject jo=new JSONObject();
                    jo.put("date", DateUtil.dateToStrLong(new Date()));
                    jo.put("num", num);
                    jo.put("teamName", adminTeamObj.getName());
                    jo.put("teamId", adminTeamObj.getId());
                    jo.put("name", adminTeamObj.getName());
                    jo.put("code", adminTeamObj.getId());
                    jo.put("name", getLevel3Name(level3,type3));
                    redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":"+level1+":"+level2+":"+level3+":"+adminTeamObj.getId()).toString(), jo.toString());
                }
@ -227,8 +231,12 @@ public class RedisStorage {
        }
    }
    private void saveAdminTeamDataLevel3(Map<String, Map<String, Map<String, List<ETLModel>>>> etlModelMap, String wlyyQuotaId,Map<String, AdminTeam> adminTeamMap, Integer foreachNum2, Integer foreachNum3, Integer type2, Integer type3, Integer start2, Integer start3) {
        //遍历团队的Map
        for(Map.Entry<String,AdminTeam> oneAdminTeam:adminTeamMap.entrySet()){
            JSONArray level2Jr=new JSONArray();
            AdminTeam adminTeamObj = adminTeamMap.get(oneAdminTeam.getKey());//团队
            String level1="1";
            //得到每个团队的2级维度
            Map<String, Map<String, List<ETLModel>>> twoETLMap= etlModelMap.get(oneAdminTeam.getKey());
            for(int i=start2;i<=foreachNum2;i++){
@ -238,7 +246,6 @@ public class RedisStorage {
                    threeETLMap=twoETLMap.get(i+"");
                }
                for(int j=start3;j<=foreachNum3;j++){
                    String level1="1";
                    String level2=i+"";
                    String level3=j+"";
                    int num=0;
@ -248,17 +255,23 @@ public class RedisStorage {
                            num=etlModelList.size();
                        }
                    }
                    AdminTeam adminTeamObj = adminTeamMap.get(oneAdminTeam.getKey());//团队
                    if(adminTeamObj==null)continue;
                    JSONObject jo=new JSONObject();
                    jo.put("date", DateUtil.dateToStrLong(new Date()));
                    jo.put("num", num);
                    jo.put("teamName", adminTeamObj.getName());
                    jo.put("teamId", adminTeamObj.getId());
                    jo.put("name", getLevel3Name(level3,type3));
                    redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":"+level1+":"+level2+":"+level3+":"+adminTeamObj.getId()).toString(), jo.toString());
                    jo.put("name", level3);
                    jo.put("code", getLevel3Name(level3,type3));
                    StringBuffer sb=new StringBuffer("quota:"+wlyyQuotaId+":"+level1+":"+adminTeamObj.getId()+":"+level2+":"+":"+level3+":"+timeKey);
                    keys.add(sb.toString());
                    redisTemplate.opsForValue().set(sb.toString(), jo.toString());
                    level2Jr.put(jo);
                }
            }
            StringBuffer sb=new StringBuffer("quota:"+wlyyQuotaId+":"+level1+":"+adminTeamObj.getId()+":"+timeKey);
            keys.add(sb.toString());
            redisTemplate.opsForValue().set(sb.toString(), level2Jr.toString());
        }
    }
    private String getLevel3Name(String j, Integer type) {
@ -311,8 +324,8 @@ public class RedisStorage {
                    JSONObject jo=new JSONObject();
                    jo.put("date", DateUtil.dateToStrLong(new Date()));
                    jo.put("num", num);
                    jo.put("orgName", hospital.getName());
                    jo.put("orgCode", hospital.getCode());
                    jo.put("name", hospital.getName());
                    jo.put("code", hospital.getCode());
                    jo.put("name", getLevel3Name(level3,type3));
                    redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":"+level1+":"+level2+":"+level3+":"+hospital.getCode()).toString(), jo.toString());
                }
@ -320,8 +333,14 @@ public class RedisStorage {
        }
    }
    private void saveHospitalTeamDataLevel3(Map<String, Map<String, Map<String, List<ETLModel>>>> etlModelMap,String wlyyQuotaId, Map<String, Hospital> hospitalMap, Integer foreachNum2, Integer foreachNum3, Integer type2, Integer type3, Integer start2, Integer start3) {
        Map<String,Map<String,JSONArray>> cityJr=new HashMap<String,Map<String,JSONArray>>();
        //遍历团队的Map
        for(Map.Entry<String,Hospital> oneHospital:hospitalMap.entrySet()){
            Hospital hospital = hospitalsMap.get(oneHospital.getKey());
            if(hospital==null)continue;
            JSONArray jr=new JSONArray();
            String level1="2";
            //得到每个团队的2级维度
            Map<String, Map<String, List<ETLModel>>> twoETLMap= etlModelMap.get(oneHospital.getKey());
            for(int i=start2;i<=foreachNum2;i++){
@ -331,7 +350,6 @@ public class RedisStorage {
                    threeETLMap=twoETLMap.get(i+"");
                }
                for(int j=start3;j<=foreachNum3;j++){
                    String level1="2";
                    String level2=i+"";
                    String level3=j+"";
                    int num=0;
@ -341,17 +359,21 @@ public class RedisStorage {
                            num=etlModelList.size();
                        }
                    }
                    Hospital hospital = hospitalsMap.get(oneHospital.getKey());
                    if(hospital==null)continue;
                    JSONObject jo=new JSONObject();
                    jo.put("date", DateUtil.dateToStrLong(new Date()));
                    jo.put("num", num);
                    jo.put("orgName", hospital.getName());
                    jo.put("orgCode", hospital.getCode());
                    jo.put("name", getLevel3Name(level3,type3));
                    redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":"+level1+":"+level2+":"+level3+":"+hospital.getCode()).toString(), jo.toString());
                    jo.put("name", level3);
                    jo.put("code", getLevel3Name(level3,type3));
                    StringBuffer sb=new StringBuffer("quota:"+wlyyQuotaId+":"+level1+":"+":"+hospital.getCode()+":"+level2+":"+level3+":"+timeKey);
                    keys.add(sb.toString());
                    redisTemplate.opsForValue().set(sb.toString(), jo.toString());
                    jr.put(jo);
                }
            }
            StringBuffer sb=new StringBuffer("quota:"+wlyyQuotaId+":"+level1+":"+hospital.getCode()+":"+timeKey);
            keys.add(sb.toString());
            redisTemplate.opsForValue().set(sb.toString(), jr.toString());
        }
    }
    private void saveTownTeamDataLevel3(Map<String, Map<String, Map<String, List<ETLModel>>>> etlModelMap,Map<String, Map<String, Map<String, List<ETLModel>>>> deleteEtlModelMap,String wlyyQuotaId, Map<String, Town> townsMap, Integer foreachNum2, Integer foreachNum3, Integer type2, Integer type3, Integer start2, Integer start3) {
@ -393,8 +415,8 @@ public class RedisStorage {
                    JSONObject jo=new JSONObject();
                    jo.put("date", DateUtil.dateToStrLong(new Date()));
                    jo.put("num", num);
                    jo.put("townName", town.getName());
                    jo.put("townCode", town.getCode());
                    jo.put("name", town.getName());
                    jo.put("code", town.getCode());
                    jo.put("name", getLevel3Name(level3,type3));
                    redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":"+level1+":"+level2+":"+level3+":"+town.getCode()).toString(), jo.toString());
                }
@ -440,8 +462,8 @@ public class RedisStorage {
                    JSONObject jo=new JSONObject();
                    jo.put("date", DateUtil.dateToStrLong(new Date()));
                    jo.put("num", num);
                    jo.put("cityName", cityObj.getName());
                    jo.put("cityCode", cityObj.getCode());
                    jo.put("name", cityObj.getName());
                    jo.put("code", cityObj.getCode());
                    jo.put("name", getLevel3Name(level3,type3));
                    redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":"+level1+":"+level2+":"+level3+":"+cityObj.getCode()).toString(), jo.toString());
@ -450,9 +472,12 @@ public class RedisStorage {
        }
    }
    private void saveTownTeamDataLevel3(Map<String, Map<String, Map<String, List<ETLModel>>>> etlModelMap,String wlyyQuotaId, Map<String, Town> townsMap, Integer foreachNum2, Integer foreachNum3, Integer type2, Integer type3, Integer start2, Integer start3) {
        List<WlyyQuotaResult> wlyyQuotaResults=new ArrayList<WlyyQuotaResult>();
        //遍历团队的Map
        for(Map.Entry<String,Town> oneTownTeam:townsMap.entrySet()){
            Town town=townsMap.get(oneTownTeam.getKey());
            JSONArray jr=new JSONArray();
            String level1="3";
            //得到每个团队的2级维度
            Map<String, Map<String, List<ETLModel>>> twoETLMap= etlModelMap.get(oneTownTeam.getKey());
            for(int i=start2;i<=foreachNum2;i++){
@ -462,7 +487,6 @@ public class RedisStorage {
                    threeETLMap=twoETLMap.get(i+"");
                }
                for(int j=start3;j<=foreachNum3;j++){
                    String level1="3";
                    String level2=i+"";
                    String level3=j+"";
                    int num=0;
@ -472,24 +496,34 @@ public class RedisStorage {
                            num=etlModelList.size();
                        }
                    }
                    Town town=townsMap.get(oneTownTeam.getKey());
                    if(town==null)continue;
                    JSONObject jo=new JSONObject();
                    jo.put("date", DateUtil.dateToStrLong(new Date()));
                    jo.put("num", num);
                    jo.put("townName", town.getName());
                    jo.put("townCode", town.getCode());
                    jo.put("name", getLevel3Name(level3,type3));
                    redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":"+level1+":"+level2+":"+level3+":"+town.getCode()).toString(), jo.toString());
                    //jo.put("name", town.getName());
                    //jo.put("code", town.getCode());
                    jo.put("level2code", level2);
                    jo.put("level2name", getLevel2Name(level2,type2));
                    jo.put("name", level3);
                    jo.put("code", getLevel3Name(level3,type3));
                    StringBuffer sb=new StringBuffer("quota:"+wlyyQuotaId+":"+level1+":"+town.getCode()+":"+level2+":"+level3+":"+timeKey);
                    keys.add(sb.toString());
                    redisTemplate.opsForValue().set(sb.toString(), jo.toString());
                    jr.put(jo);
                }
            }
            StringBuffer sb=new StringBuffer("quota:"+wlyyQuotaId+":"+level1+":"+town.getCode()+":"+timeKey);
            keys.add(sb.toString());
            redisTemplate.opsForValue().set(sb.toString(), jr.toString());
        }
    }
    private void saveCityTeamDataLevel3(Map<String, Map<String, Map<String, List<ETLModel>>>> etlModelMap,String wlyyQuotaId, Map<String, City> cityMap, Integer foreachNum2, Integer foreachNum3, Integer type2, Integer type3, Integer start2, Integer start3) {
        List<WlyyQuotaResult> wlyyQuotaResults=new ArrayList<WlyyQuotaResult>();
        //遍历团队的Map
        for(Map.Entry<String,City> oneCityTeam:cityMap.entrySet()){
            City cityObj=oneCityTeam.getValue();
            JSONArray jr=new JSONArray();
            String level1="4";
            //得到每个团队的2级维度
            Map<String, Map<String, List<ETLModel>>> twoETLMap= etlModelMap.get(oneCityTeam.getKey());
            for(int i=start2;i<=foreachNum2;i++){
@ -499,8 +533,6 @@ public class RedisStorage {
                    threeETLMap=twoETLMap.get(i+"");
                }
                for(int j=start3;j<=foreachNum3;j++){
                    String level1="4";
                    String level2=i+"";
                    String level3=j+"";
                    int num=0;
@ -510,17 +542,22 @@ public class RedisStorage {
                            num=etlModelList.size();
                        }
                    }
                    City cityObj=oneCityTeam.getValue();
                    JSONObject jo=new JSONObject();
                    jo.put("date", DateUtil.dateToStrLong(new Date()));
                    jo.put("num", num);
                    jo.put("cityName", cityObj.getName());
                    jo.put("cityCode", cityObj.getCode());
                    jo.put("name", getLevel3Name(level3,type3));
                    redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":"+level1+":"+level2+":"+level3+":"+cityObj.getCode()).toString(), jo.toString());
                    jo.put("name", level3);
                    jo.put("code", getLevel3Name(level3,type3));
                    StringBuffer sb=new StringBuffer("quota:"+wlyyQuotaId+":"+level1+":"+cityObj.getCode()+":"+level2+":"+level3+":"+timeKey);
                    keys.add(sb.toString());
                    redisTemplate.opsForValue().set(sb.toString(), jo.toString());
                    jr.put(jo);
                }
            }
            StringBuffer sb=new StringBuffer("quota:"+wlyyQuotaId+":"+level1+":"+cityObj.getCode()+":"+timeKey);
            keys.add(sb.toString());
            redisTemplate.opsForValue().set(sb.toString(), jr.toString());
        }
    }
@ -554,7 +591,6 @@ public class RedisStorage {
        Map<String, Map<String, List<ETLModel>>> townTeam=data.get(2);//区的数据
        Map<String, Map<String, List<ETLModel>>> cityTeam=data.get(3);//市的数据
        redisTemplate.opsForValue().set("quota:date",DateUtil.dateToStrLong(new Date()));
        if(deleteData!=null){
            //保存市
            saveLevel2City(wlyyQuotaId, cityMap, cityTeam,deleteData.get(3),foreachNum,type,start);
@ -599,10 +635,9 @@ public class RedisStorage {
                }
                jo.put("date", DateUtil.dateToStrLong(new Date()));
                jo.put("num", num);
                jo.put("teamName", adminTeamObj.getName());
                jo.put("teamId", adminTeamObj.getId());
                jo.put("name", adminTeamObj.getName());
                jo.put("code", adminTeamObj.getId());
                String key=i+"";
                jo.put("name", getLevel2Name(key,type));
                redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":1:"+key+":"+adminTeam.getKey()).toString(), jo.toString());
            }
        }
@ -610,6 +645,7 @@ public class RedisStorage {
    private void saveLevel2Team(String wlyyQuotaId, Map<String, AdminTeam> adminTeamMap, Map<String, Map<String, List<ETLModel>>> eltModel,  Integer foreachNum, Integer type,Integer start) {
        for(Map.Entry<String,AdminTeam> adminTeam:adminTeamMap.entrySet()){
            Map<String, List<ETLModel>> oneELTMap= eltModel.get(adminTeam.getKey());
            JSONArray level2=new JSONArray();
            for(int i=start;i<=foreachNum;i++){
                AdminTeam adminTeamObj=adminTeam.getValue();
                if(adminTeamObj==null)continue;
@ -623,12 +659,20 @@ public class RedisStorage {
                }
                jo.put("date", DateUtil.dateToStrLong(new Date()));
                jo.put("num", num);
                jo.put("teamName", adminTeamObj.getName());
                jo.put("teamId", adminTeamObj.getId());
                String key=i+"";
                jo.put("name", getLevel2Name(key,type));
                redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":1:"+key+":"+adminTeam.getKey()).toString(), jo.toString());
                jo.put("name", key);
                jo.put("code",  Constant.getLevelSexName(key));
                StringBuffer sb=new StringBuffer("quota:"+wlyyQuotaId+":1:"+adminTeam.getKey().toString()+":"+key+":"+timeKey);
                keys.add(sb.toString());
                redisTemplate.opsForValue().set(sb.toString(), jo.toString());
                level2.put(jo);
            }
            StringBuffer sb=new StringBuffer("quota:"+wlyyQuotaId+":1:"+adminTeam.getKey().toString()+":"+timeKey);
            keys.add(sb.toString());
            redisTemplate.opsForValue().set(sb.toString(), level2.toString());
        }
    }
    private void saveLevel2Org(String wlyyQuotaId, Map<String, Hospital> hospitalsMap, Map<String, Map<String, List<ETLModel>>> eltModel, Map<String, Map<String, List<ETLModel>>> deleteEltModel, Integer foreachNum, Integer type,Integer start) {
@ -654,10 +698,9 @@ public class RedisStorage {
                }
                jo.put("date", DateUtil.dateToStrLong(new Date()));
                jo.put("num", num);
                jo.put("orgName", hospitalObj.getName());
                jo.put("orgCode", hospitalObj.getCode());
                jo.put("name", hospitalObj.getName());
                jo.put("code", hospitalObj.getCode());
                String key=i+"";
                jo.put("name", getLevel2Name(key,type));
                redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":2:"+key+":"+hospital.getKey()).toString(), jo.toString());
            }
        }
@ -665,6 +708,7 @@ public class RedisStorage {
    private void saveLevel2Town(String wlyyQuotaId, Map<String, Town> townsMap, Map<String, Map<String, List<ETLModel>>> eltModel,  Integer foreachNum, Integer type,Integer start) {
        for(Map.Entry<String,Town> town:townsMap.entrySet()){
            Map<String, List<ETLModel>> oneELTMap= eltModel.get(town.getKey());
            JSONArray level2=new JSONArray();
            for(int i=1;i<=foreachNum;i++){
                JSONObject jo=new JSONObject();
                int num=0;
@ -676,17 +720,27 @@ public class RedisStorage {
                }
                jo.put("date", DateUtil.dateToStrLong(new Date()));
                jo.put("num", num);
                jo.put("townName", town.getValue().getName());
                jo.put("townCode", town.getValue().getCode());
                String key=i+"";
                jo.put("name", getLevel2Name(key,type));
                redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":3:"+key+":"+town.getKey()).toString(), jo.toString());
                jo.put("name", key);
                jo.put("code", Constant.getLevelSexName(key));
                StringBuffer sb=new StringBuffer("quota:"+wlyyQuotaId+":3:"+town.getKey()+":"+key+":"+timeKey);
                keys.add(sb.toString());
                redisTemplate.opsForValue().set(sb.toString(), jo.toString());
                level2.put(jo);
            }
            StringBuffer sb=new StringBuffer("quota:"+wlyyQuotaId+":3:"+town.getKey()+":"+timeKey);
            keys.add(sb.toString());
            redisTemplate.opsForValue().set(sb.toString(), level2.toString());
        }
    }
    private void saveLevel2Org(String wlyyQuotaId, Map<String, Hospital> hospitalsMap, Map<String, Map<String, List<ETLModel>>> eltModel,Integer foreachNum, Integer type,Integer start) {
        Map<String,Map<String,JSONArray>> townjr=new HashMap<String,Map<String,JSONArray>>();
        for(Map.Entry<String,Hospital> hospital:hospitalsMap.entrySet()){
            Map<String, List<ETLModel>> oneELTMap= eltModel.get(hospital.getKey());
            JSONArray level2=new JSONArray();
            for(int i=start;i<=foreachNum;i++){
                Hospital hospitalObj=hospital.getValue();
                if(hospitalObj==null)continue;
@ -700,12 +754,20 @@ public class RedisStorage {
                }
                jo.put("date", DateUtil.dateToStrLong(new Date()));
                jo.put("num", num);
                jo.put("orgName", hospitalObj.getName());
                jo.put("orgCode", hospitalObj.getCode());
                String key=i+"";
                jo.put("name", getLevel2Name(key,type));
                redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":2:"+key+":"+hospital.getKey()).toString(), jo.toString());
                jo.put("name", key);
                jo.put("code", Constant.getLevelSexName(key));
                addJOLeval2(townjr,hospitalObj.getTown(),key,jo);
                StringBuffer sb=new StringBuffer("quota:"+wlyyQuotaId+":2:"+hospital.getKey().toString()+":"+key+":"+timeKey);
                keys.add(sb.toString());
                redisTemplate.opsForValue().set(sb.toString(), level2.toString());
            }
            StringBuffer sb=new StringBuffer("quota:"+wlyyQuotaId+":2:"+hospital.getKey().toString()+":"+timeKey);
            keys.add(sb.toString());
            redisTemplate.opsForValue().set(sb.toString(), level2.toString());
        }
    }
    private void saveLevel2Town(String wlyyQuotaId, Map<String, Town> townsMap, Map<String, Map<String, List<ETLModel>>> eltModel, Map<String, Map<String, List<ETLModel>>> deleteEltModel, Integer foreachNum, Integer type,Integer start) {
@ -729,8 +791,8 @@ public class RedisStorage {
                }
                jo.put("date", DateUtil.dateToStrLong(new Date()));
                jo.put("num", num);
                jo.put("townName", town.getValue().getName());
                jo.put("townCode", town.getValue().getCode());
                jo.put("name", town.getValue().getName());
                jo.put("code", town.getValue().getCode());
                String key=i+"";
                jo.put("name", getLevel2Name(key,type));
                redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":3:"+key+":"+town.getKey()).toString(), jo.toString());
@ -759,10 +821,11 @@ public class RedisStorage {
                }
                jo.put("date", DateUtil.dateToStrLong(new Date()));
                jo.put("num", num);
                jo.put("cityName", city.getValue().getName());
                jo.put("cityCode", city.getValue().getCode());
                jo.put("name", city.getValue().getName());
                jo.put("code", city.getValue().getCode());
                String key=i+"";
                jo.put("name", getLevel2Name(key,type));
                jo.put("name", getLevel2Name(key,type));
                redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":4:"+key+":"+city.getKey()).toString(), jo.toString());
            }
        }
@ -770,6 +833,7 @@ public class RedisStorage {
    private void saveLevel2City(String wlyyQuotaId, Map<String, City> cityMap, Map<String, Map<String, List<ETLModel>>> eltModel,  Integer foreachNum, Integer type,Integer start) {
        for(Map.Entry<String,City> city:cityMap.entrySet()){
            Map<String, List<ETLModel>> oneELTMap= eltModel.get(city.getKey());
            JSONArray level2=new JSONArray();
            for(int i=start;i<=foreachNum;i++){
                JSONObject jo=new JSONObject();
                int num=0;
@ -781,15 +845,24 @@ public class RedisStorage {
                }
                jo.put("date", DateUtil.dateToStrLong(new Date()));
                jo.put("num", num);
                jo.put("cityName", city.getValue().getName());
                jo.put("cityCode", city.getValue().getCode());
                String key=i+"";
                jo.put("code", key);
                jo.put("name", getLevel2Name(key,type));
                redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":4:"+key+":"+city.getKey()).toString(), jo.toString());
                StringBuffer sb=new StringBuffer("quota:"+wlyyQuotaId+":4:"+city.getKey()+":"+key+":"+timeKey);
                keys.add(sb.toString());
                redisTemplate.opsForValue().set(sb.toString(), jo.toString());
                level2.put(jo);
            }
            StringBuffer sb=new StringBuffer("quota:"+wlyyQuotaId+":4:"+city.getKey()+":"+timeKey);
            keys.add(sb.toString());
            redisTemplate.opsForValue().set(sb.toString(), level2.toString());
        }
    }
    private void saveLevel1Team(String wlyyQuotaId, Map<String, AdminTeam> adminTeamMap, Map<String, List<ETLModel>> adminTeam) {
        JSONArray cityjr=new JSONArray();
        Map<String,JSONArray> townjr=new HashMap<String,JSONArray>();//key是town
        Map<String,JSONArray> orgjr=new HashMap<String,JSONArray>();//key是机构
        for(Map.Entry<String,AdminTeam> entry:adminTeamMap.entrySet()){
            JSONObject jo=new JSONObject();
            Integer num=0;
@ -801,10 +874,41 @@ public class RedisStorage {
            }
            jo.put("date", DateUtil.dateToStrLong(new Date()));
            jo.put("num", num);
            jo.put("teamName", adminTeamObj.getName());
            jo.put("teamId", adminTeamObj.getId());
            redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":1:"+entry.getKey()).toString(), jo.toString());
            jo.put("name", adminTeamObj.getName());
            jo.put("code", adminTeamObj.getId());
            String orgKey=adminTeamObj.getOrgCode();
            Hospital hospital=hospitalsMap.get(orgKey);
            if(hospital==null)continue;
            String townKey=hospital.getTown();
            cityjr.put(jo);
            addJO(townjr,townKey,jo);
            addJO(orgjr,orgKey,jo);
            StringBuffer key=new StringBuffer("quota:"+wlyyQuotaId+":1:"+entry.getKey()+":"+timeKey);
            keys.add(key.toString());
            redisTemplate.opsForValue().set(key.toString(), jo.toString());
        }
        //保存市下面全部的团队
        StringBuffer key=new StringBuffer("quota:"+wlyyQuotaId+":4:1:"+Constant.city+":"+timeKey);
        keys.add(key.toString());
        redisTemplate.opsForValue().set(key.toString(), cityjr.toString());
        //保存区下面全部的团队
        for(Map.Entry<String,JSONArray> entry:townjr.entrySet()){
            key=new StringBuffer("quota:"+wlyyQuotaId+":3:1:"+entry.getKey()+":"+timeKey);
            keys.add(key.toString());
            redisTemplate.opsForValue().set(key.toString(), entry.getValue().toString());
        }
        townjr.clear();
        //保存机构下面全部的团队
        for(Map.Entry<String,JSONArray> entry:orgjr.entrySet()){
            key=new StringBuffer("quota:"+wlyyQuotaId+":2:1:"+entry.getKey()+":"+timeKey);
            keys.add(key.toString());
            redisTemplate.opsForValue().set(key.toString(), entry.getValue().toString());
        }
        orgjr.clear();
    }
    private void saveLevel1Team(String wlyyQuotaId, Map<String, AdminTeam> adminTeamMap, Map<String, List<ETLModel>> adminTeam, Map<String, List<ETLModel>> deleteAdminTeam) {
        for(Map.Entry<String,AdminTeam> entry:adminTeamMap.entrySet()){
@ -824,12 +928,14 @@ public class RedisStorage {
            }
            jo.put("date", DateUtil.dateToStrLong(new Date()));
            jo.put("num", num);
            jo.put("teamName", adminTeamObj.getName());
            jo.put("teamId", adminTeamObj.getId());
            redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":1:"+entry.getKey()).toString(), jo.toString());
            jo.put("name", adminTeamObj.getName());
            jo.put("code", adminTeamObj.getId());
            redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":1:"+entry.getKey()).toString()+":0", jo.toString());
        }
    }
    private void saveLevel1Org(String wlyyQuotaId, Map<String, Hospital> hospitalsMap, Map<String, List<ETLModel>> orgTeam) {
        JSONArray cityjr=new JSONArray();
        Map<String,JSONArray> townjr=new HashMap<String,JSONArray>();
        for(Map.Entry<String,Hospital> entry:hospitalsMap.entrySet()){
            Hospital hospital=entry.getValue();
            if(hospital==null)continue;
@ -841,11 +947,89 @@ public class RedisStorage {
            }
            jo.put("date", DateUtil.dateToStrLong(new Date()));
            jo.put("num", num);
            jo.put("orgName", hospital.getName());
            jo.put("orgCode", hospital.getCode());
            redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":2:"+entry.getKey()).toString(), jo.toString());
            jo.put("name", hospital.getName());
            jo.put("code", hospital.getCode());
            cityjr.put(jo);
            String townKey=hospital.getTown();
            addJO(townjr, townKey, jo);
            StringBuffer key=new StringBuffer("quota:"+wlyyQuotaId+":2:"+entry.getKey()+":"+timeKey);
            keys.add(key.toString());
            redisTemplate.opsForValue().set(key.toString(), jo.toString());
        }
        //保存市下面全部的机构
        StringBuffer key=new StringBuffer("quota:"+wlyyQuotaId+":4:2:"+Constant.city+":"+timeKey);
        keys.add(key.toString());
        redisTemplate.opsForValue().set(key.toString(), cityjr.toString());
        //保存区下面全部的机构
        for(Map.Entry<String,JSONArray> entry:townjr.entrySet()){
            key=new StringBuffer("quota:"+wlyyQuotaId+":3:2:"+entry.getKey()+":"+timeKey);
            keys.add(key.toString());
            redisTemplate.opsForValue().set(key.toString(), entry.getValue().toString());
        }
        townjr.clear();
    }
    private void addJO(Map<String, JSONArray> townjr,String key, JSONObject jo) {
        if(townjr.containsKey(key)){
            townjr.get(key).put(jo);
        }else{
            JSONArray townjrList=new JSONArray();
            townjrList.put(jo);
            townjr.put(key,townjrList);
        }
    }
    private void addJOLeval2(Map<String,Map<String, JSONArray>> townjr,String key1,String key2, JSONObject jo) {
        if(townjr.containsKey(key1)){
            Map<String, JSONArray> level2=townjr.get(key1);
            if(level2.containsKey(key2)){
                JSONArray jr=level2.get(key2);
                jr.put(jo);
            }else{
                JSONArray jr=new JSONArray();
                jr.put(jo);
                level2.put(key2,jr);
            }
        }else{
            Map<String, JSONArray> level2=new HashMap<>();
            JSONArray jr=new JSONArray();
            jr.put(jo);
            level2.put(key2,jr);
            townjr.put(key1,level2);
        }
    }
    private void addJOLeval3(Map<String,Map<String, Map<String, JSONArray>>> townjr,String key1,String key2,String key3, JSONObject jo) {
        if(townjr.containsKey(key1)){
            Map<String, Map<String, JSONArray>> level1= townjr.get(key1);
            if(level1.containsKey(key2)){
                Map<String, JSONArray> level2=level1.get(key2);
                if(level2.containsKey(key3)){
                    JSONArray jr=level2.get(key3);
                    jr.put(jo);
                }else{
                    JSONArray jr=new JSONArray();
                    jr.put(jo);
                    level2.put(key3,jr);
                }
            }else{
                Map<String, JSONArray> level2=new HashMap<>();
                JSONArray jr=new JSONArray();
                jr.put(jo);
                level2.put(key3,jr);
                level1.put(key2,level2);
            }
        }else{
            Map<String, Map<String, JSONArray>> level1=new HashMap<>();
            Map<String, JSONArray> level2=new HashMap<>();
            JSONArray level3=new JSONArray();
            level3.put(jo);
        }
    }
    private void saveLevel1Org(String wlyyQuotaId, Map<String, Hospital> hospitalsMap, Map<String, List<ETLModel>> orgTeam, Map<String, List<ETLModel>> deleteOrgTeam) {
        for(Map.Entry<String,Hospital> entry:hospitalsMap.entrySet()){
            Hospital hospital=entry.getValue();
@ -864,13 +1048,14 @@ public class RedisStorage {
            }
            jo.put("date", DateUtil.dateToStrLong(new Date()));
            jo.put("num", num);
            jo.put("orgName", hospital.getName());
            jo.put("orgCode", hospital.getCode());
            redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":2:"+entry.getKey()).toString(), jo.toString());
            jo.put("name", hospital.getName());
            jo.put("code", hospital.getCode());
            redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":2:"+entry.getKey()).toString()+":0", jo.toString());
        }
    }
    private void saveLevel1Town(String wlyyQuotaId, Map<String, Town> townsMap, Map<String, List<ETLModel>> townTeam, Map<String, List<ETLModel>> deleteTownTeam) {
        for(Map.Entry<String,Town> entry:townsMap.entrySet()){
            JSONObject jo=new JSONObject();
            Integer num=0;
@ -886,12 +1071,13 @@ public class RedisStorage {
            }
            jo.put("date", DateUtil.dateToStrLong(new Date()));
            jo.put("num", num);
            jo.put("townName", entry.getValue().getName());
            jo.put("townCode", entry.getValue().getCode());
            redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":3:"+entry.getKey()).toString(), jo.toString());
            jo.put("name", entry.getValue().getName());
            jo.put("code", entry.getValue().getCode());
            redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":3:"+entry.getKey()).toString()+":0", jo.toString());
        }
    }
    private void saveLevel1Town(String wlyyQuotaId, Map<String, Town> townsMap, Map<String, List<ETLModel>> townTeam) {
        JSONArray jr=new JSONArray();
        for(Map.Entry<String,Town> entry:townsMap.entrySet()){
            JSONObject jo=new JSONObject();
            Integer num=0;
@ -901,10 +1087,17 @@ public class RedisStorage {
            }
            jo.put("date", DateUtil.dateToStrLong(new Date()));
            jo.put("num", num);
            jo.put("townName", entry.getValue().getName());
            jo.put("townCode", entry.getValue().getCode());
            redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":3:"+entry.getKey()).toString(), jo.toString());
            jo.put("name", entry.getValue().getName());
            jo.put("code", entry.getValue().getCode());
            jr.put(jo);
            StringBuffer key=new StringBuffer("quota:"+wlyyQuotaId+":3:"+entry.getKey()+":"+timeKey);
            keys.add(key.toString());
            redisTemplate.opsForValue().set(key.toString(), jo.toString());
        }
        //保存市下面全部的区
        StringBuffer key=new StringBuffer("quota:"+wlyyQuotaId+":4:3:"+Constant.city+":"+timeKey);
        keys.add(key.toString());
        redisTemplate.opsForValue().set(key.toString(), jr.toString());
    }
    private void saveLevel1City(String wlyyQuotaId, Map<String, City> cityMap, Map<String, List<ETLModel>> cityTeam, Map<String, List<ETLModel>> deleteCityTeam) {
        for(Map.Entry<String,City> entry:cityMap.entrySet()){
@ -922,9 +1115,9 @@ public class RedisStorage {
            }
            jo.put("date", DateUtil.dateToStrLong(new Date()));
            jo.put("num", num);
            jo.put("cityName", entry.getValue().getName());
            jo.put("cityCode", entry.getValue().getCode());
            redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":4:"+entry.getKey()).toString(), jo.toString());
            jo.put("name", entry.getValue().getName());
            jo.put("code", entry.getValue().getCode());
            redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":4:"+entry.getKey()).toString()+":0", jo.toString());
        }
    }
    private void saveLevel1City(String wlyyQuotaId, Map<String, City> cityMap, Map<String, List<ETLModel>> cityTeam) {
@ -937,9 +1130,11 @@ public class RedisStorage {
            }
            jo.put("date", DateUtil.dateToStrLong(new Date()));
            jo.put("num", num);
            jo.put("cityName", entry.getValue().getName());
            jo.put("cityCode", entry.getValue().getCode());
            redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":4:"+entry.getKey()).toString(), jo.toString());
            jo.put("name", entry.getValue().getName());
            jo.put("code", entry.getValue().getCode());
            StringBuffer key=new StringBuffer("quota:"+wlyyQuotaId+":4:"+entry.getKey()+":"+timeKey);
            keys.add(key.toString());
            redisTemplate.opsForValue().set(key.toString(), jo.toString());
        }
    }
    private String getLevel2Name(String i, Integer type) {
@ -956,9 +1151,25 @@ public class RedisStorage {
                //用户分组
                return Constant.getLevelGroupName(i);
            }
            case  4:{
                //疾病
                return Constant.getLevelDiseaseName(i);
            }
            case  5:{
                //疾病
                return Constant.getLevelExpenseName(i);
            }
            default:{
                return "";
            }
        }
    }
    private String getOrg(String org){
        //if(!"00".equals(org.substring(org.length()-2,org.length()))){
        if(org.length() == 10 && !org.endsWith("00")){
            return org.substring(0,org.length()-2)+"00";
        }else{
            return org;
        }
    }
}

+ 54 - 97
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/CurrentDayAllQuotaJob.java

@ -43,6 +43,7 @@ import org.springframework.web.context.support.SpringBeanAutowiringSupport;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
 * 实时统计今天的数据
@ -79,9 +80,13 @@ public class CurrentDayAllQuotaJob implements Job {
    private String now = getDayString(-1)+ Constant.quota_date_last;
    private String tomorrow = getDayString(1);
    private String tomorrow = DateUtil.dateToStrLong(new Date());
    private StringBuffer allContent=new StringBuffer();//日志内容
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Value("${fv.jdbc.driver}")
    String fv_jdbc_driver;
    @Value("${fv.jdbc.url}")
@ -127,32 +132,36 @@ public class CurrentDayAllQuotaJob implements Job {
    //统计
    private void computequota() throws Exception {
        //更新统计时间
        redisTemplate.opsForValue().set("quota:date",DateUtil.dateToStrLong(new Date()));
        //更新时间key
        RedisStorage.timeKey=new Date().getTime()+"";
        redisTemplate.opsForValue().set("quota:timeKey",RedisStorage.timeKey);
        QuartzJobLog quartzJobLog =new QuartzJobLog();
        quartzJobLog.setJobStartTime(new Date());
        allContent=new StringBuffer();
        //找出今天的签约信息 yesterday,now
        String sql=" select id,code,idcard,hospital,admin_team_code,expenses_status,patient from wlyy_sign_family a where  a.type =2 and status in (1,2) and  a.expenses_time>= '"+now+"' and  a.expenses_time< '"+tomorrow+"' and a.expenses_status=1 ";
        //抽取數據
        List<SignFamily> signFamilies= SpringUtil.getBean(DBExtract.class).extract(SignFamily.class,sql);
        //找出需要扣除的数据
        String deleteDql=" select id,code,idcard,hospital,admin_team_code,expenses_status,patient from wlyy_sign_family a where  a.type =2 and  a.czrq>= '"+now+"' and  a.czrq< '"+tomorrow+"' and a.expenses_status=3 ";
        String sql=" select id,code,idcard,hospital,admin_team_code,expenses_status,patient from wlyy_sign_family a where  a.type =2 and status in (1,2) and  a.expenses_time< '"+tomorrow+"' and a.expenses_status=1 ";
        String sqlCount=" select count(id) from wlyy_sign_family a where  a.type =2 and status in (1,2) and  a.expenses_time< '"+tomorrow+"' and a.expenses_status=1 ";
        //抽取數據
        List<SignFamily> deleteSignFamilies= SpringUtil.getBean(DBExtract.class).extract(SignFamily.class,deleteDql);
        computequota_1(sql,signFamilies,deleteSignFamilies); //统计今天的签约
        List<SignFamily> signFamilies= SpringUtil.getBean(DBExtract.class).extractByPage(SignFamily.class,sql,sqlCount,true);
        computequota_1(sql,signFamilies,null); //统计今天的签约
        computequota_2(); //统计今天的解约
        computequota_3(); //统计今天的健康咨询量
        computequota_4(); //统计今天的随访量
        computequota_5(); //统计今天的健康指导
        computequota_6(sql,signFamilies,deleteSignFamilies); //统计今天的签约患者性别
        computequota_7(sql,signFamilies,deleteSignFamilies);//统计今天的签约患者分组
        computequota_8(sql,signFamilies,deleteSignFamilies);//统计今天的签约患者年龄
        computequota_6(sql,signFamilies,null); //统计今天的签约患者性别
        computequota_7(sql,signFamilies,null);//统计今天的签约患者分组
        computequota_8(sql,signFamilies,null);//统计今天的签约患者年龄
        computequota_9();//统计今天的待签约
        computequota_10();//统计今天的改签
        computequota_12(sql,signFamilies,deleteSignFamilies);//统计今天的签约下按年龄分组后再
        computequota_13(sql,signFamilies,deleteSignFamilies);//统计今天的签约量
        computequota_16_1(sql,signFamilies,deleteSignFamilies);//统计今天的签约数的扣费钱 1
        computequota_15(sql,signFamilies,deleteSignFamilies);//统计今天的健康分布统计
        computequota_16_0(sql,signFamilies,deleteSignFamilies);//统计今天的签约数的未扣费 0
        computequota_12(sql,signFamilies,null);//统计今天的签约下按年龄分组后再
        computequota_13(sql,signFamilies,null);//统计今天的签约量
        computequota_16_1(sql,signFamilies,null);//统计今天的签约数的扣费钱 1
        computequota_15(sql,signFamilies,null);//统计今天的健康分布统计
        //computequota_16_0(sql,signFamilies,null);//统计今天的签约数的未扣费 0
        quartzJobLog.setJobContent(allContent.toString());
        quartzJobLog.setJobName("实时统计");
@ -160,27 +169,27 @@ public class CurrentDayAllQuotaJob implements Job {
        quartzJobLog.setJobType("1");
        quartzJobLog.setJobEndTime(new Date());
        quartzJobLogDao.save(quartzJobLog);
        for (String key :RedisStorage.keys){
            redisTemplate.expire(key, 1, TimeUnit.HOURS);//1小时过期
        }
        RedisStorage.keys.clear();//清空Key
    }
    private void computequota_16_1(String sql,List<SignFamily> signFamilies_1,List<SignFamily> deleteSignFamilies) {
        String quotaId="16";
        try{
            for(SignFamily signFamily:deleteSignFamilies){
                signFamily.setExpensesStatus("1");
            }
            sql=" select id,code,idcard,hospital,admin_team_code,expenses_status from wlyy_sign_family a where  a.type =2 and (expenses_status =0 or expenses_status is null) and    a.apply_date< '"+tomorrow+"' ";
            String sqlCount=" select count(id) from wlyy_sign_family a where  a.type =2 and (expenses_status =0 or expenses_status is null)  and  a.apply_date< '"+tomorrow+"' ";
            List<SignFamily> signFamilies_2= SpringUtil.getBean(DBExtract.class).extractByPage(SignFamily.class,sql,sqlCount,true);
            signFamilies_2.addAll(signFamilies_1);
            //清洗數據
            FilterModel etlModels= SpringUtil.getBean(SignDataFilter.class).filter(signFamilies_1, SignDataFilter.level2Expenses,sql,null);
            FilterModel etlModels= SpringUtil.getBean(SignDataFilter.class).filter(signFamilies_2, SignDataFilter.level2Expenses,sql,null);
            //统计数据 一级维度
            List<Map<String, List<ETLModel>>>  returnDatas= SpringUtil.getBean(Level1Role.class).elt(etlModels.getEtlModelList());
            //统计数据 二级维度
            List<Map<String, Map<String, List<ETLModel>>>> level2Data= SpringUtil.getBean(Level2Role.class).elt(returnDatas);
            //清洗數據
            FilterModel deleteEtlModels= SpringUtil.getBean(SignDataFilter.class).filter(deleteSignFamilies,SignDataFilter.level2Expenses,sql,"now");
            //统计数据
            List<Map<String, List<ETLModel>>>  deleteReturnDatas= SpringUtil.getBean(Level1Role.class).elt(deleteEtlModels.getEtlModelList());
            //统计数据 二级维度
            List<Map<String, Map<String, List<ETLModel>>>>  deleteLevel2Data= SpringUtil.getBean(Level2Role.class).elt(deleteReturnDatas);;
            SpringUtil.getBean(RedisStorage.class).saveByLevel2(level2Data,deleteLevel2Data,quotaId,1,4,1);
            //保存redis
            SpringUtil.getBean(RedisStorage.class).saveByLevel2(level2Data,null,quotaId,2,5,0);
            allContent.append(JsonUtil.objToStr(etlModels.getLogModel()));
        }catch (Exception e){
            e.printStackTrace();
@ -198,12 +207,8 @@ public class CurrentDayAllQuotaJob implements Job {
           FilterModel etlModels= SpringUtil.getBean(SignDataFilter.class).filter(signFamilies,sql,null);
           //统计数据
           List<Map<String, List<ETLModel>>>  returnData= SpringUtil.getBean(Level1Role.class).elt(etlModels.getEtlModelList());
            //清洗數據
            FilterModel deleteEtlModels= SpringUtil.getBean(SignDataFilter.class).filter(deleteSignFamilies,sql,"now");
            //统计数据
            List<Map<String, List<ETLModel>>>  deleteReturnDatas= SpringUtil.getBean(Level1Role.class).elt(deleteEtlModels.getEtlModelList());
            //保存数据
             SpringUtil.getBean(RedisStorage.class).saveByLevel1(returnData,deleteReturnDatas,"13");
             SpringUtil.getBean(RedisStorage.class).saveByLevel1(returnData,null,"13");
            allContent.append(JsonUtil.objToStr(etlModels.getLogModel()));
        }catch (Exception e){
            e.printStackTrace();
@ -217,8 +222,8 @@ public class CurrentDayAllQuotaJob implements Job {
        //找出今天的签约信息
        try{
            //抽取第二种条件的语句 找出未缴费的
            sql=" select id,code,idcard,hospital,admin_team_code,expenses_status from wlyy_sign_family a where  a.type =2 and (expenses_status =0 or expenses_status is null) and  a.apply_date>= '"+now+"' and  a.apply_date< '"+tomorrow+"' ";
            String sqlCount=" select count(id) from wlyy_sign_family a where  a.type =2 and (expenses_status =0 or expenses_status is null) and  a.apply_date>= '"+now+"' and  a.apply_date< '"+tomorrow+"' ";
            sql=" select id,code,idcard,hospital,admin_team_code,expenses_status from wlyy_sign_family a where  a.type =2 and (expenses_status =0 or expenses_status is null) and    a.apply_date< '"+tomorrow+"' ";
            String sqlCount=" select count(id) from wlyy_sign_family a where  a.type =2 and (expenses_status =0 or expenses_status is null)  and  a.apply_date< '"+tomorrow+"' ";
            List<SignFamily> signFamilies_2= SpringUtil.getBean(DBExtract.class).extractByPage(SignFamily.class,sql,sqlCount,true);
             //清洗數據
            FilterModel etlModels= SpringUtil.getBean(SignDataFilter.class).filter(signFamilies_2, SignDataFilter.level2Expenses,sql,null);
@ -227,14 +232,9 @@ public class CurrentDayAllQuotaJob implements Job {
            List<Map<String, List<ETLModel>>>  returnDatas= SpringUtil.getBean(Level1Role.class).elt(etlModels.getEtlModelList());
            //统计数据 二级维度
            List<Map<String, Map<String, List<ETLModel>>>> level2Data= SpringUtil.getBean(Level2Role.class).elt(returnDatas);
            //清洗數據
            FilterModel deleteEtlModels= SpringUtil.getBean(SignDataFilter.class).filter(deleteSignFamilies,SignDataFilter.level2Expenses,sql,null);
            //统计数据
            List<Map<String, List<ETLModel>>>  deleteReturnDatas= SpringUtil.getBean(Level1Role.class).elt(deleteEtlModels.getEtlModelList());
            //统计数据 二级维度
            List<Map<String, Map<String, List<ETLModel>>>>  deleteLevel2Data= SpringUtil.getBean(Level2Role.class).elt(deleteReturnDatas);;
            //保存数据
            SpringUtil.getBean(RedisStorage.class).saveByLevel2(level2Data,deleteLevel2Data,quotaId,0,4,0);
            SpringUtil.getBean(RedisStorage.class).saveByLevel2(level2Data,null,quotaId,0,4,0);
            allContent.append(JsonUtil.objToStr(etlModels.getLogModel()));
        }catch (Exception e){
            e.printStackTrace();
@ -256,14 +256,8 @@ public class CurrentDayAllQuotaJob implements Job {
           List<Map<String, List<ETLModel>>>  returnDatas= SpringUtil.getBean(Level1Role.class).elt(etlModels.getEtlModelList());
           //统计数据 二级维度
           List<Map<String, Map<String, List<ETLModel>>>> patientSexRoleData= SpringUtil.getBean(Level2Role.class).elt(returnDatas);
           //清洗數據
           FilterModel deleteEtlModels= SpringUtil.getBean(SignDataFilter.class).filter(deleteSignFamilies,SignDataFilter.level2Health,sql,"now");
           //统计数据
           List<Map<String, List<ETLModel>>>  deleteReturnDatas= SpringUtil.getBean(Level1Role.class).elt(deleteEtlModels.getEtlModelList());
           //统计数据 二级维度
           List<Map<String, Map<String, List<ETLModel>>>>  deleteLevel2Data= SpringUtil.getBean(Level2Role.class).elt(deleteReturnDatas);;
            //保存数据
             SpringUtil.getBean(RedisStorage.class).saveByLevel2(patientSexRoleData,deleteLevel2Data,quotaId,4,5,0);
             SpringUtil.getBean(RedisStorage.class).saveByLevel2(patientSexRoleData,null,quotaId,4,5,0);
           allContent.append(JsonUtil.objToStr(etlModels.getLogModel()));
        }catch (Exception e){
            e.printStackTrace();
@ -289,16 +283,8 @@ public class CurrentDayAllQuotaJob implements Job {
            List<Map<String, Map<String, List<ETLModel>>>> patientSexRoleData= SpringUtil.getBean(Level2Role.class).elt(returnDatas);
            //统计数据 三级维度
            List<Map<String, Map<String, Map<String, List<ETLModel>>>>> returnD= SpringUtil.getBean(Level3Role.class).elt(patientSexRoleData);
            //清洗數據
            FilterModel deleteEtlModels= SpringUtil.getBean(SignDataFilter.class).filter(deleteSignFamilies,SignDataFilter.level2Age,SignDataFilter.level3Disease,sql,null);
            //统计数据 一级维度
            List<Map<String, List<ETLModel>>>  deleteReturnDatas= SpringUtil.getBean(Level1Role.class).elt(deleteEtlModels.getEtlModelList());
            //统计数据 二级维度
            List<Map<String, Map<String, List<ETLModel>>>> deletePatientSexRoleData= SpringUtil.getBean(Level2Role.class).elt(deleteReturnDatas);
            //统计数据 三级维度
            List<Map<String, Map<String, Map<String, List<ETLModel>>>>> deleteReturnD=SpringUtil.getBean(Level3Role.class).elt(deletePatientSexRoleData);
            //保存数据
             SpringUtil.getBean(RedisStorage.class).saveByLevel3(returnD,deleteReturnD,quotaId,6,4,2,1,1,1);
             SpringUtil.getBean(RedisStorage.class).saveByLevel3(returnD,null,quotaId,6,4,2,1,1,1);
        }catch (Exception e){
        }
@ -339,12 +325,8 @@ public class CurrentDayAllQuotaJob implements Job {
            FilterModel etlModels= SpringUtil.getBean(SignDataFilter.class).filter(signFamilies,sql,"now");
            //统计数据
            List<Map<String, List<ETLModel>>>  returnDatas= SpringUtil.getBean(Level1Role.class).elt(etlModels.getEtlModelList());
            //清洗數據
            FilterModel deleteEtlModels= SpringUtil.getBean(SignDataFilter.class).filter(deleteSignFamilies,sql,"now");
            //统计数据
            List<Map<String, List<ETLModel>>>  deleteReturnDatas= SpringUtil.getBean(Level1Role.class).elt(deleteEtlModels.getEtlModelList());
            //保存数据
             SpringUtil.getBean(RedisStorage.class).saveByLevel1(returnDatas,deleteReturnDatas,"1");
             SpringUtil.getBean(RedisStorage.class).saveByLevel1(returnDatas,null,"1");
            allContent.append(JsonUtil.objToStr(etlModels.getLogModel()));
        }catch (Exception e){
            e.printStackTrace();
@ -358,7 +340,7 @@ public class CurrentDayAllQuotaJob implements Job {
        String quotaId="2";
        try{
            //找出今天的解约信息
            String sql=" select id,code,idcard,hospital,admin_team_code,expenses_status from wlyy_sign_family a where  a.type =2 and  a.apply_unsign_date>= '"+now+"' and  a.apply_unsign_date< '"+tomorrow+"' and a.expenses_status=1 ";
            String sql=" select id,code,idcard,hospital,admin_team_code,expenses_status from wlyy_sign_family a where  a.type =2  and  a.apply_unsign_date< '"+tomorrow+"' and a.expenses_status=1 ";
            //抽取數據
            List<SignFamily> signFamilies= SpringUtil.getBean(DBExtract.class).extract(SignFamily.class,sql);
            //清洗數據
@ -379,7 +361,7 @@ public class CurrentDayAllQuotaJob implements Job {
        String quotaId="3";
        try{
            //找出今天的咨询信息
            String sql=" select * from wlyy_consult_team a where a.type=2 and a.czrq>='"+now+"' and a.czrq< '"+tomorrow+"'";
            String sql=" select * from wlyy_consult_team a where a.type=2  and a.czrq>= '"+now+"'and a.czrq< '"+tomorrow+"'";
            //抽取數據
            List<ConsultTeam> consultTeams= SpringUtil.getBean(DBExtract.class).extract(ConsultTeam.class,sql);
            //過濾數據
@ -400,7 +382,7 @@ public class CurrentDayAllQuotaJob implements Job {
        String quotaId="4";
        try{
            //找出今天的随访信息
            String sql=" select * from fv_plan a where unix_timestamp(a.update_time)>=unix_timestamp('"+now+"') and unix_timestamp(a.update_time)< unix_timestamp('"+tomorrow+"')  ";
            String sql=" select * from fv_plan a where  a.update_time< '"+tomorrow+"' and a.update_time>= '"+now+"' ";
            //找出今天的随访信息
            List<Map<String, Object>> plans = fv_jdbcTemplate.queryForList(sql);
@ -420,7 +402,7 @@ public class CurrentDayAllQuotaJob implements Job {
    private void computequota_5() {
        String quotaId="5";
        String sql="SELECT * FROM wlyy_patient_health_guidance a WHERE a.czrq>='"+now+"' and a.czrq< '"+tomorrow+"'";
        String sql="SELECT * FROM wlyy_patient_health_guidance a WHERE a.czrq< '"+tomorrow+"' and a.czrq>= '"+now+"'";
        try{
            //抽取數據
            List<PatientHealthGuidance> consultTeams= SpringUtil.getBean(DBExtract.class).extract(PatientHealthGuidance.class,sql);
@ -451,14 +433,8 @@ public class CurrentDayAllQuotaJob implements Job {
           List<Map<String, List<ETLModel>>>  returnDatas= SpringUtil.getBean(Level1Role.class).elt(etlModels.getEtlModelList());
           //统计数据 二级维度
           List<Map<String, Map<String, List<ETLModel>>>>  level2Data= SpringUtil.getBean(Level2Role.class).elt(returnDatas);;
           //清洗數據
           FilterModel deleteEtlModels= SpringUtil.getBean(SignDataFilter.class).filter(deleteSignFamilies,SignDataFilter.level2Sex,sql,"now");
           //统计数据
           List<Map<String, List<ETLModel>>>  deleteReturnDatas= SpringUtil.getBean(Level1Role.class).elt(deleteEtlModels.getEtlModelList());
           //统计数据 二级维度
           List<Map<String, Map<String, List<ETLModel>>>>  deleteLevel2Data= SpringUtil.getBean(Level2Role.class).elt(deleteReturnDatas);;
            //保存数据
            SpringUtil.getBean(RedisStorage.class).saveByLevel2(level2Data,deleteLevel2Data,quotaId,3,1);
            SpringUtil.getBean(RedisStorage.class).saveByLevel2(level2Data,null,quotaId,3,1);
           allContent.append(JsonUtil.objToStr(etlModels.getLogModel()));
        }catch (Exception e){
            e.printStackTrace();
@ -479,14 +455,8 @@ public class CurrentDayAllQuotaJob implements Job {
            List<Map<String, List<ETLModel>>>  returnDatas= SpringUtil.getBean(Level1Role.class).elt(etlModels.getEtlModelList());
            //统计数据 二级维度
            List<Map<String, Map<String, List<ETLModel>>>>  level2Data= SpringUtil.getBean(Level2Role.class).elt(returnDatas);
            //清洗數據
            FilterModel deleteEtlModels= SpringUtil.getBean(SignDataFilter.class).filter(deleteSignFamilies,SignDataFilter.level2Group,sql,"now");
            //统计数据
            List<Map<String, List<ETLModel>>>  deleteReturnDatas= SpringUtil.getBean(Level1Role.class).elt(deleteEtlModels.getEtlModelList());
            //统计数据 二级维度
            List<Map<String, Map<String, List<ETLModel>>>>  deleteLevel2Data= SpringUtil.getBean(Level2Role.class).elt(deleteReturnDatas);;
            //保存数据 1 表示:从1开始循环 6表示:循环6次 3表示 2级维度是 3
             SpringUtil.getBean(RedisStorage.class).saveByLevel2(level2Data,deleteLevel2Data,quotaId,7,3,-1);
             SpringUtil.getBean(RedisStorage.class).saveByLevel2(level2Data,null,quotaId,7,3,-1);
            allContent.append(JsonUtil.objToStr(etlModels.getLogModel()));
        }catch (Exception e){
            e.printStackTrace();
@ -508,14 +478,8 @@ public class CurrentDayAllQuotaJob implements Job {
            List<Map<String, List<ETLModel>>>  returnDatas= SpringUtil.getBean(Level1Role.class).elt(etlModels.getEtlModelList());
            //统计数据 二级维度
            List<Map<String, Map<String, List<ETLModel>>>>  level2Data= SpringUtil.getBean(Level2Role.class).elt(returnDatas);;
            //清洗數據
            FilterModel deleteEtlModels= SpringUtil.getBean(SignDataFilter.class).filter(deleteSignFamilies,SignDataFilter.level2Age,sql,"now");
            //统计数据
            List<Map<String, List<ETLModel>>>  deleteReturnDatas= SpringUtil.getBean(Level1Role.class).elt(deleteEtlModels.getEtlModelList());
            //统计数据 二级维度
            List<Map<String, Map<String, List<ETLModel>>>>  deleteLevel2Data= SpringUtil.getBean(Level2Role.class).elt(deleteReturnDatas);;
            //保存数据
             SpringUtil.getBean(RedisStorage.class).saveByLevel2(level2Data,deleteLevel2Data,quotaId,6,2);
             SpringUtil.getBean(RedisStorage.class).saveByLevel2(level2Data,null,quotaId,6,2);
            allContent.append(JsonUtil.objToStr(etlModels.getLogModel()));
        }catch (Exception e){
            e.printStackTrace();
@ -527,7 +491,7 @@ public class CurrentDayAllQuotaJob implements Job {
    private void computequota_9() {
        String quotaId="9";
        //找出今天的待签约信息
        String sql=" select id,code,idcard,hospital,admin_team_code from wlyy_sign_family a where  a.type =2   and  a.patient_apply_date>= '"+now+"' and  a.patient_apply_date< '"+tomorrow+"' and a.expenses_status=1 ";
        String sql=" select id,code,idcard,hospital,admin_team_code from wlyy_sign_family a where  a.type =2   and   a.patient_apply_date< '"+tomorrow+"' and a.expenses_status=1 ";
        try{
            //抽取數據
            List<SignFamily> signFamilies= SpringUtil.getBean(DBExtract.class).extract(SignFamily.class,sql);
@ -549,7 +513,7 @@ public class CurrentDayAllQuotaJob implements Job {
        String quotaId="10";
       try{
            //找出今天的已改簽信息
            String sql=" select id,code,idcard,hospital,admin_team_code from wlyy_sign_family a where  a.type =2 and a.status =100 and  a.patient_apply_date>= '"+now+"' and  a.patient_apply_date< '"+tomorrow+"' and a.expenses_status=1 ";
            String sql=" select id,code,idcard,hospital,admin_team_code from wlyy_sign_family a where  a.type =2 and a.status =100 and   a.patient_apply_date< '"+tomorrow+"' and a.expenses_status=1 ";
            //抽取數據
            List<SignFamily> signFamilies= SpringUtil.getBean(DBExtract.class).extract(SignFamily.class,sql);
            //清洗數據
@ -599,14 +563,7 @@ public class CurrentDayAllQuotaJob implements Job {
            return Constant.level_age_6;
        }
    }
    private String getOrg(String org){
        //if(!"00".equals(org.substring(org.length()-2,org.length()))){
        if(org.length() == 10 && !org.endsWith("00")){
            return org.substring(0,org.length()-2)+"00";
        }else{
            return org;
        }
    }
    private String saveContent(String id,Integer size, Long qkCount, Long orgCount, Long townCount, Long cityCount, boolean isAll, StringBuffer errorContent,Long errorCount) {
        StringBuffer string=new StringBuffer("统计 quotaid:"+id+" 的数据完成 ,数据库查询到签约数目:"+size);
        string.append(",过滤的脏数据数目:"+errorCount);