Browse Source

Merge branch 'dev' of http://192.168.1.220:10080/Amoy/patient-co-management into dev

zhenglingfeng 8 years ago
parent
commit
8c5d8c12cc
21 changed files with 2124 additions and 219 deletions
  1. 317 85
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/etl/storage/RedisStorage.java
  2. 54 97
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/CurrentDayAllQuotaJob.java
  3. 2 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/consult/ConsultTeamLogDao.java
  4. 9 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/PatientFamilyMemberDao.java
  5. 16 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/account/DoctorInfoService.java
  6. 16 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/account/PatientInfoService.java
  7. 5 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/consult/ConsultTeamService.java
  8. 16 2
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/family/FamilyMemberService.java
  9. 3 2
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/family/FamilyService.java
  10. 1 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java
  11. 1556 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statistics/StatisticsAllService.java
  12. 23 10
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statistics/StatisticsService.java
  13. 1 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/common/account/PatientService.java
  14. 30 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/util/IdCardUtil.java
  15. 1 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/common/account/WechatController.java
  16. 24 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/account/DoctorController.java
  17. 8 8
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/sign/DoctorFamilyContractController.java
  18. 23 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/account/PatientController.java
  19. 5 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/family/FamilyMemberController.java
  20. 1 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/quota/JobController.java
  21. 13 10
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/statistic/StatisticsController.java

+ 317 - 85
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,18 +231,22 @@ 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++){
                JSONArray jrlevel2=new JSONArray();
                //得到每个团队的三级维度
                Map<String, List<ETLModel>> threeETLMap=null;
                if(twoETLMap!=null){
                    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 +256,27 @@ 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);
                    jrlevel2.put(jo);
                }
                StringBuffer sb=new StringBuffer("quota:"+wlyyQuotaId+":"+level1+":"+adminTeamObj.getId()+":"+timeKey);
                keys.add(sb.toString());
                redisTemplate.opsForValue().set(sb.toString(), jrlevel2.toString());
            }
            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 +329,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,18 +338,24 @@ 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++){
                JSONArray jrlevel2=new JSONArray();
                //得到每个团队的三级维度
                Map<String, List<ETLModel>> threeETLMap= new HashMap<String, List<ETLModel>>();
                if(twoETLMap!=null){
                    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 +365,25 @@ 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);
                    jrlevel2.put(jo);
                }
                StringBuffer sb=new StringBuffer("quota:"+wlyyQuotaId+":"+level1+":"+hospital.getCode()+":"+i+":"+timeKey);
                keys.add(sb.toString());
                redisTemplate.opsForValue().set(sb.toString(), jrlevel2.toString());
            }
            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 +425,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 +472,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,19 +482,22 @@ 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++){
                JSONArray jrlevel2=new JSONArray();
                //得到每个团队的三级维度
                Map<String, List<ETLModel>> threeETLMap= new HashMap<String, List<ETLModel>>();
                if(twoETLMap!=null){
                    threeETLMap=twoETLMap.get(i+"");
                }
                for(int j=start3;j<=foreachNum3;j++){
                    String level1="3";
                    String level2=i+"";
                    String level3=j+"";
                    int num=0;
@ -472,35 +507,49 @@ 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);
                    jrlevel2.put(jo);
                }
                StringBuffer sb=new StringBuffer("quota:"+wlyyQuotaId+":"+level1+":"+town.getCode()+":"+i+":"+timeKey);
                keys.add(sb.toString());
                redisTemplate.opsForValue().set(sb.toString(), jrlevel2.toString());
            }
            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++){
                //得到每个团队的三级维度
                JSONArray jrLevel2=new JSONArray();
                Map<String, List<ETLModel>> threeETLMap= new HashMap<String, List<ETLModel>>();
                if(twoETLMap!=null){
                    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 +559,26 @@ 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());
                    jrLevel2.put(jo);
                    jr.put(jo);
                }
                StringBuffer sb=new StringBuffer("quota:"+wlyyQuotaId+":"+level1+":"+cityObj.getCode()+":"+i+":"+timeKey);
                keys.add(sb.toString());
                redisTemplate.opsForValue().set(sb.toString(), jrLevel2.toString());
            }
            StringBuffer sb=new StringBuffer("quota:"+wlyyQuotaId+":"+level1+":"+cityObj.getCode()+":"+timeKey);
            keys.add(sb.toString());
            redisTemplate.opsForValue().set(sb.toString(), jr.toString());
        }
    }
@ -554,7 +612,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 +656,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 +666,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 +680,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 +719,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 +729,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 +741,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 +775,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 +812,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 +842,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 +854,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 +866,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 +895,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:"+Constant.city+":1:"+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:"+entry.getKey()+":1:"+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:"+entry.getKey()+":1:"+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 +949,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 +968,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:"+Constant.city+":2:"+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:"+entry.getKey()+":2:"+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 +1069,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 +1092,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());
            jo.put("name", entry.getValue().getName());
            jo.put("code", entry.getValue().getCode());
            redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":3:"+entry.getKey()).toString(), 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 +1108,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+":"+entry.getKey()+":3:"+timeKey);
            keys.add(key.toString());
            redisTemplate.opsForValue().set(key.toString(), jo.toString());
        }
        //保存市下面全部的区
        StringBuffer key=new StringBuffer("quota:"+wlyyQuotaId+":4:"+Constant.city+":3:"+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,8 +1136,8 @@ 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());
            jo.put("name", entry.getValue().getName());
            jo.put("code", entry.getValue().getCode());
            redisTemplate.opsForValue().set(new StringBuffer("quota:"+wlyyQuotaId+":4:"+entry.getKey()).toString(), jo.toString());
        }
    }
@ -937,9 +1151,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 +1172,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);

+ 2 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/consult/ConsultTeamLogDao.java

@ -11,5 +11,6 @@ import org.springframework.data.repository.PagingAndSortingRepository;
import com.yihu.wlyy.entity.consult.ConsultTeamLog;
public interface ConsultTeamLogDao extends PagingAndSortingRepository<ConsultTeamLog, Long>, JpaSpecificationExecutor<ConsultTeamLog> {
	
    int countByConsult(String consult);
}

+ 9 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/PatientFamilyMemberDao.java

@ -24,6 +24,15 @@ public interface PatientFamilyMemberDao extends PagingAndSortingRepository<Patie
     */
    PatientFamilyMember findByPatientAndFamilyMember(String patient,String member);
    /**
     * 查询居民的某个关系成员
     *
     * @param patient 居民
     * @param familyRelation 关系
     * @return
     */
    List<PatientFamilyMember> findByPatientAndFamilyRelation(String patient,Integer familyRelation);
    /**
     * 查找某个居民的家庭成员
     *

+ 16 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/account/DoctorInfoService.java

@ -756,4 +756,20 @@ public class DoctorInfoService extends BaseService {
        return bo;
    }
    /**
     * 手机号是否注册
     *
     * @param mobile
     * @return
     */
    public int isMobileRegister(String mobile) {
        Doctor doc = doctorDao.findByMobile(mobile);
        if (doc != null) {
            return 1;
        } else {
            return 0;
        }
    }
}

+ 16 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/account/PatientInfoService.java

@ -78,7 +78,7 @@ public class PatientInfoService extends BaseService {
		Patient pMobile = patientDao.findByMobile(mobile);
		if (pMobile == null && !p.getCode().equals(patient)) {
		if (pMobile != null && !pMobile.getCode().equals(patient)) {
			return -2;
		}
@ -95,6 +95,21 @@ public class PatientInfoService extends BaseService {
		return 1;
	}
	/**
	 * 手机号是否注册
	 *
	 * @param mobile
	 * @return
	 */
	public int isMobileRegister(String mobile) {
		Patient p = patientDao.findByMobile(mobile);
		if (p != null) {
			return 1;
		} else {
			return 0;
		}
	}
	/**
	 * 根据患者标识查询患者信息

+ 5 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/consult/ConsultTeamService.java

@ -771,6 +771,11 @@ public class ConsultTeamService extends ConsultService {
    public void transfer(String from, String to, String consult) {
        // 检查是否存在
        if (consultTeamDoctorDao.isExist(consult, to) == 0) {
            ConsultTeam ct = consultTeamDao.findByConsult(consult);
            int count = consultTeamLogDao.countByConsult(consult);
            // 设置未读消息数
            ct.setDoctorRead(count);
            consultTeamDao.save(ct);
            // 查询医生信息
            Doctor d = doctorDao.findByCode(from);
            // 再保存

+ 16 - 2
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/family/FamilyMemberService.java

@ -83,9 +83,23 @@ public class FamilyMemberService extends BaseService {
        if (m == null) {
            return -2;
        }
        if(relation < 5) {
            List<PatientFamilyMember> familyMembers = memberDao.findByPatientAndFamilyRelation(patient, relation);
            if (familyMembers != null && familyMembers.size() > 0) {
                return -5;
            }
        }
        // 验证码验证
        if (StringUtils.isNotEmpty(captcha) && smsService.check(m.getMobile(), 10, captcha) != 1) {
            return -3;
        if (StringUtils.isNotEmpty(captcha)) {
            int checkStatus = smsService.check(m.getMobile(), 10, captcha);
            if(checkStatus == -2){
                return -6;  // 验证码过期
            } else if(checkStatus == -1){
                return -3; // 验证码错误
            }
        }
        if (StringUtils.isNotEmpty(password)) {
            String loginPassword = MD5.GetMD5Code(password + m.getSalt());

+ 3 - 2
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/family/FamilyService.java

@ -188,11 +188,12 @@ public class FamilyService {
                    if (!StringUtils.isEmpty(jo.get("name"))) {
                        patientTemp.setName(jo.get("name").toString());
                    }
                    String password=idcard.substring(idcard.length()-6);
                    String idCardTemp=jo.get("idcard").toString();
                    String password=idCardTemp.substring(idCardTemp.length()-6);
                    String salt= UUID.randomUUID().toString().replace("-","");
                    patientTemp.setSalt(salt);
                    patientTemp.setPassword(MD5.GetMD5Code(password+salt));
                    patientTemp.setSex(Integer.valueOf(IdCardUtil.getSexForIdcard(jo.get("idcard").toString())));
                    patientTemp.setSex(Integer.valueOf(IdCardUtil.getSexForIdcard_new(jo.get("idcard").toString())));
                    patientTemp.setBirthday(IdCardUtil.getBirthdayForIdcard(jo.get("idcard").toString()));
                    SocialSecurityInfo socialSecurityInfo = socialSecurityInfoDao.findBySfzh18Max(jo.get("idcard").toString());
                    //设置医保卡号

+ 1 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java

@ -714,6 +714,7 @@ public class FamilyContractService extends BaseService {
            patient.setName(name);
            patient.setIdcard(idcard);
            patient.setSsc(sscD);
            patient.setMobile(mobile);
            patient.setBirthday(ie.getBirthday());
            patient.setSex(ie.getGender());
            String password=idcard.substring(idcard.length()-6);

+ 1556 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statistics/StatisticsAllService.java

@ -0,0 +1,1556 @@
package com.yihu.wlyy.service.app.statistics;
import com.yihu.wlyy.entity.address.Town;
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
import com.yihu.wlyy.entity.organization.Hospital;
import com.yihu.wlyy.entity.statistics.PopulationBase;
import com.yihu.wlyy.repository.address.CityDao;
import com.yihu.wlyy.repository.address.TownDao;
import com.yihu.wlyy.repository.doctor.DoctorAdminTeamDao;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.organization.HospitalDao;
import com.yihu.wlyy.repository.statistics.PopulationBaseDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.util.DateUtil;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * Created by lyr-pc on 2016/10/21.
 */
@Service
public class StatisticsAllService extends BaseService {
    @Autowired
    CityDao cityDao;
    @Autowired
    TownDao townDao;
    @Autowired
    DoctorDao doctorDao;
    @Autowired
    HospitalDao hospitalDao;
    @Autowired
    DoctorAdminTeamDao adminTeamDao;
    @Autowired
    JdbcTemplate jdbcTemplate;
    @Autowired
    PopulationBaseDao peopleNumDao;
    @Autowired
    private StringRedisTemplate redisTemplate;
    /**
     * 获取时间戳
     *
     * @return
     */
    public String getQuotaTimeStamp() {
        return redisTemplate.opsForValue().get("quota:timeKey");
    }
    /**
     * 获取一级指标达到量
     *
     * @param endDate 截止日期
     * @param area    区域
     * @param index   指标
     * @param level   级别
     * @return
     */
    public long getIndexTotal(String endDate, String area, int level, String index) {
        long total = 0;
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        if (endDate.compareTo(dateFormat.format(new Date())) >= 0) {
            String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area + ":" + getQuotaTimeStamp());
            if (!StringUtils.isEmpty(val)) {
                JSONObject valJson = new JSONObject(val);
                if (valJson.has("num")) {
                    total = valJson.getInt("num");
                }
            }
        } else {
            // 查询语句
            String sql = " select " +
                    "     ifnull(result,'0') amount" +
                    " from  " +
                    "     wlyy_quota_result " +
                    " where " +
                    "     quato_code = ? " +
                    "   and level1_type = ? and del = '1'" +
                    "   and quota_date = ? ";
            if (level == 4) {
                // 市级别
                sql += " and city = ? ";
            } else if (level == 3) {
                // 区、城镇级别
                sql += " and town = ? ";
            } else if (level == 2) {
                // 机构级别
                sql += " and org_code = ? ";
            } else if (level == 1) {
                sql += " and qkdoctor_code = ?";
            }
            List<Map<String, Object>> result = jdbcTemplate.queryForList(sql, new Object[]{index, level, endDate, area});
            if (result != null && result.size() > 0) {
                total = (result.get(0).get("amount") != null ? Long.valueOf(result.get(0).get("amount").toString()) : 0L);
            }
        }
        return total;
    }
    /**
     * 获取缴费
     *
     * @param endDate 截止日期
     * @param area    区域
     * @param level   级别
     * @return
     */
    public long getWeiJiaoFei(String endDate, String area, int level) {
        long total = 0;
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        if (endDate.compareTo(dateFormat.format(new Date())) >= 0) {
            String val = redisTemplate.opsForValue().get("quota:16:" + level + ":"+ area + ":0:" + getQuotaTimeStamp());
            if (!StringUtils.isEmpty(val)) {
                JSONObject valJson = new JSONObject(val);
                if (valJson.has("num")) {
                    total = valJson.getInt("num");
                }
            }
        } else {
            // 查询语句
            String sql = " select " +
                    "     ifnull(result,'0') amount" +
                    " from  " +
                    "     wlyy_quota_result " +
                    " where " +
                    "     quato_code = '16' " +
                    "   and level1_type = ? and del = '1'" +
                    "   and level2_type = '0' " +
                    "   and quota_date = ? ";
            if (level == 4) {
                // 市级别
                sql += " and city = ? ";
            } else if (level == 3) {
                // 区、城镇级别
                sql += " and town = ? ";
            } else if (level == 2) {
                // 机构级别
                sql += " and org_code = ? ";
            } else if (level == 1) {
                sql += " and qkdoctor_code = ?";
            }
            List<Map<String, Object>> result = jdbcTemplate.queryForList(sql, new Object[]{level, endDate, area});
            if (result != null && result.size() > 0) {
                total = (result.get(0).get("amount") != null ? Long.valueOf(result.get(0).get("amount").toString()) : 0L);
            }
        }
        return total;
    }
    /**
     * 查询截止某个日期累计签约率
     *
     * @param endDate 截止日期
     * @param area    区域或机构代码
     * @param level   级别
     * @return
     */
    public JSONObject getSignRate(String endDate, String area, int level) throws Exception {
        JSONObject json = new JSONObject();
        long signAmount = getIndexTotal(endDate, area, level, "13");
        PopulationBase peopleNum = peopleNumDao.findByCodeAndYear(area, Calendar.getInstance().get(Calendar.YEAR));
        DecimalFormat df = new DecimalFormat("0.0000");
        if (peopleNum != null && peopleNum.getNum() > 0) {
            json.put("rate", df.format((signAmount * 1.0000) / peopleNum.getNum() * 100));
            json.put("sign", signAmount);
            json.put("people", peopleNum.getNum());
        } else {
            json.put("rate", "0.0000");
            json.put("sign", signAmount);
            json.put("people", 0);
        }
        return json;
    }
    /**
     * 查询截止某个日期签约完成率
     *
     * @param endDate 截止日期
     * @param area    区域或机构代码
     * @param level   级别
     * @return
     */
    public JSONObject getSignTaskRate(String endDate, String area, int level) throws Exception {
        JSONObject json = new JSONObject();
        long signAmount = getIndexTotal(endDate, area, level, "13");
        PopulationBase peopleNum = peopleNumDao.findByCodeAndYear(area, Calendar.getInstance().get(Calendar.YEAR));
        DecimalFormat df = new DecimalFormat("0.0000");
        if (peopleNum != null && peopleNum.getTaskNum() > 0) {
            json.put("rate", df.format((signAmount * 1.0000) / peopleNum.getTaskNum() * 100));
            json.put("sign", signAmount);
            json.put("people", peopleNum.getTaskNum());
        } else {
            json.put("rate", "0.0000");
            json.put("sign", signAmount);
            json.put("people", 0);
        }
        return json;
    }
    /**
     * 查询某个级别的某个指标到达量
     *
     * @param date
     * @param area
     * @param level
     * @param index
     * @param sort
     * @param lowLevel
     * @return
     * @throws Exception
     */
    public JSONArray getLowLevelTotal(String date, String area, int level, String index, int sort, String lowLevel) throws Exception {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String low_level = String.valueOf(StringUtils.isEmpty(lowLevel) ? (level - 1) : lowLevel);
        List<Map<String, Object>> resultList = new ArrayList<>();
        if (date.compareTo(dateFormat.format(new Date())) >= 0) {
            resultList = getTodayLowLevelTotal(date, area, level, index, lowLevel);
        } else {
            resultList = getTodayBeforeLowLevelTotal(date, area, level, index, sort, lowLevel);
        }
        // 结果为空时,自建结果集
        if (resultList == null || resultList.size() < 1) {
            resultList = getLowLevelMapKey(level, low_level, area);
        }
        if (resultList != null) {
            DecimalFormat df = new DecimalFormat("0.0000");
            for (Map<String, Object> map : resultList) {
                map.put("amount", map.get("amount") != null ? Long.valueOf(map.get("amount").toString()) : 0L);
                if (!low_level.equals("1")) {
                    String redisNum = redisTemplate.opsForValue().get("people:num:" + map.get("code").toString());
                    if (StringUtils.isEmpty(redisNum)) {
                        PopulationBase peopleNum = peopleNumDao.findByCodeAndYear(map.get("code").toString(), Calendar.getInstance().get(Calendar.YEAR));
                        if (peopleNum != null) {
                            map.put("rate", df.format(((long) map.get("amount") * 1.0000) / peopleNum.getNum() * 100));
                            map.put("taskRate", df.format(((long) map.get("amount") * 1.0000) / peopleNum.getTaskNum() * 100));
                            map.put("targetRate", df.format(peopleNum.getTaskNum() * 1.0000 / peopleNum.getNum() * 100));
                            map.put("num", peopleNum.getNum());
                            map.put("task", peopleNum.getTaskNum());
                        }
                    } else {
                        JSONObject peopleNum = new JSONObject(redisNum);
                        if (peopleNum != null) {
                            map.put("rate", df.format(((long) map.get("amount") * 1.0000) / peopleNum.getInt("num") * 100));
                            map.put("taskRate", df.format(((long) map.get("amount") * 1.0000) / peopleNum.getInt("taskNum") * 100));
                            map.put("targetRate", df.format(peopleNum.getInt("taskNum") * 1.0000 / peopleNum.getInt("num") * 100));
                            map.put("num", peopleNum.getInt("num"));
                            map.put("task", peopleNum.getInt("taskNum"));
                        }
                    }
                }
            }
            Collections.sort(resultList, new Comparator<Map<String, Object>>() {
                public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                    long map1value = (long) o1.get("amount");
                    long map2value = (long) o2.get("amount");
                    if (map1value - map2value > 0) {
                        return sort == 1 ? -1 : 1;
                    } else if (map1value - map2value < 0) {
                        return sort == 1 ? 1 : -1;
                    } else {
                        return 0;
                    }
                }
            });
            return new JSONArray(resultList);
        } else {
            return new JSONArray();
        }
    }
    /**
     * 获取过去某个日期某个区域一级指标的下级统计
     *
     * @param date
     * @param area
     * @param level
     * @param index
     * @param lowLevel
     * @return
     */
    public List<Map<String, Object>> getTodayBeforeLowLevelTotal(String date, String area, int level, String index, int sort, String lowLevel) throws Exception {
        List<Map<String, Object>> resultList = new ArrayList<>();
        String low_level = String.valueOf(StringUtils.isEmpty(lowLevel) ? (level - 1) : lowLevel);
        String areaField = "";
        String lowLevelField = "";
        String lowLevelName = "";
        if (level == 4) {
            // 市级别
            areaField = "city";
        } else if (level == 3) {
            // 区、城镇级别
            areaField = "town";
        } else if (level == 2) {
            // 机构级别
            areaField = "org_code";
        } else if (level == 1) {
            throw new Exception("param level error");
        }
        if (low_level.equals("3")) {
            lowLevelField = "town";
            lowLevelName = "town_name";
        } else if (low_level.equals("2")) {
            lowLevelField = "org_code";
            lowLevelName = "org_name";
        } else if (low_level.equals("1")) {
            lowLevelField = "qkdoctor_code";
            lowLevelName = "qkdoctor_name";
        } else {
            throw new Exception("param lowLevel error");
        }
        // 查询语句
        String sql = " select " +
                "     ifnull(" + lowLevelField + ",'') code " +
                "     ,ifnull(" + lowLevelName + ",'') 'name' " +
                "     ,ifnull(result,'0') amount" +
                " from  " +
                "     wlyy_quota_result " +
                " where " +
                "     quato_code = '" + index + "' " +
                "   and level1_type = ? and del = '1'" +
                "   and quota_date = ? " +
                "   and " + areaField + " = ? ";
        if (sort == 1) {
            sql += " order by amount desc";
        } else {
            sql += " order by amount asc ";
        }
        resultList = jdbcTemplate.queryForList(sql, new Object[]{low_level, date, area});
        return resultList;
    }
    /**
     * 获取今天某个区域一级指标的下级统计
     *
     * @param date
     * @param area
     * @param level
     * @param index
     * @param lowLevel
     * @return
     */
    public List<Map<String, Object>> getTodayLowLevelTotal(String date, String area, int level, String index, String lowLevel) {
        List<Map<String, Object>> resultList = new ArrayList<>();
        String low_level = String.valueOf(StringUtils.isEmpty(lowLevel) ? (level - 1) : lowLevel);
        String redisData = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area + ":" + low_level + ":" + getQuotaTimeStamp());
        if (!StringUtils.isEmpty(redisData)) {
            JSONArray jsonArray = new JSONArray(redisData);
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject json = jsonArray.getJSONObject(i);
                Map<String, Object> data = new HashMap<>();
                data.put("code", json.getString("code"));
                data.put("name", json.getString("name"));
                data.put("amount", Long.valueOf(String.valueOf(json.get("num"))));
                resultList.add(data);
            }
        }
        if (resultList.size() < 1) {
            resultList = getLowLevelMapKey(level, low_level, area);
        }
        return resultList;
    }
    /**
     * 获取下级统计key
     *
     * @param level
     * @param lowLevel
     * @param area
     * @return
     */
    public List<Map<String, Object>> getLowLevelMapKey(int level, String lowLevel, String area) {
        List<Map<String, Object>> resultList = new ArrayList<>();
        if (lowLevel.equals("3")) {
            List<Town> towns = townDao.findByCityCode(area);
            if (towns != null) {
                for (Town town : towns) {
                    Map<String, Object> obj = new HashMap<>();
                    obj.put("code", town.getCode());
                    obj.put("name", town.getName());
                    obj.put("amount", "0");
                    resultList.add(obj);
                }
            }
        } else if (lowLevel.equals("2")) {
            List<Town> towns = new ArrayList<>();
            if (level == 4) {
                towns = townDao.findByCityCode(area);
            } else if (level == 3) {
                Town town = townDao.findByCode(area);
                towns.add(town);
            }
            if (towns != null && towns.size() > 0) {
                for (Town town : towns) {
                    List<Hospital> hospitals = hospitalDao.findByTownCode(town.getCode());
                    for (Hospital hos : hospitals) {
                        if (hos.getCode().length() > 10) {
                            continue;
                        }
                        Map<String, Object> obj = new HashMap<>();
                        obj.put("code", hos.getCode());
                        obj.put("name", hos.getName());
                        obj.put("amount", "0");
                        resultList.add(obj);
                    }
                }
            }
        } else if (lowLevel.equals("1")) {
            List<Hospital> hospitals = new ArrayList<>();
            if (level == 4) {
                hospitals = hospitalDao.findByCity(area);
            } else if (level == 3) {
                hospitals = hospitalDao.findByTownCode(area);
            } else {
                Hospital hos = hospitalDao.findByCode(area);
                if (hos != null) {
                    hospitals.add(hos);
                }
            }
            if (hospitals != null && hospitals.size() > 0) {
                for (Hospital hos : hospitals) {
                    if (hos.getCode().length() > 10) {
                        continue;
                    }
                    List<AdminTeam> teams = adminTeamDao.findByOrgCode(hos.getCode());
                    for (AdminTeam team : teams) {
                        Map<String, Object> obj = new HashMap<>();
                        obj.put("code", String.valueOf(team.getId()));
                        obj.put("name", team.getName());
                        obj.put("amount", "0");
                        resultList.add(obj);
                    }
                }
            }
        }
        return resultList;
    }
    /**
     * 获取二级指标的到达量
     *
     * @param endDate
     * @param area
     * @param level
     * @param index
     * @return
     */
    public JSONArray getIndexLevelTwototal(String endDate, String area, int level, String index) {
        String areaField = "";
        SimpleDateFormat datef = new SimpleDateFormat("yyyy-MM-dd");
        List<Map<String, Object>> resultList = new ArrayList<>();
        if (endDate.compareTo(datef.format(new Date())) >= 0) {
            resultList = getTodayLevelTwoTotal(area, level, index);
        } else {
            resultList = getTodyBeforeLevelTwototal(endDate, area, level, index);
        }
        if (resultList != null) {
            long total = 0;
            for (Map<String, Object> map : resultList) {
                map.put("amount", map.get("amount") == null ? 0 : Math.round(Double.valueOf(map.get("amount").toString())));
                // 当天数据统计
                if (endDate.compareTo(new SimpleDateFormat("yyyy-MM-dd").format(new Date())) == 0) {
                    String code = map.get("code") != null ? String.valueOf(map.get("code")) : "";
                    String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + code + ":" + area + ":" + getQuotaTimeStamp());
                    if (!StringUtils.isEmpty(val)) {
                        JSONObject valJson = new JSONObject(val);
                        if (valJson.has("num")) {
                            map.put("amount", (long) map.get("amount") + valJson.getInt("num"));
                        }
                    }
                }
                if (index.equals("7")) {
                    // 分组指标总数算法
                    String code = map.get("code") != null ? String.valueOf(map.get("code")) : "";
                    if (code.equals("0") || code.equals("1") || code.equals("2") || code.equals("3") || code.equals("7")) {
                        total += (long) map.get("amount");
                    }
                } else if (index.equals("16")) {
                    String code = map.get("code") != null ? String.valueOf(map.get("code")) : "";
                    if (!code.equals("2")) {
                        total += (long) map.get("amount");
                    }
                } else {
                    total += (long) map.get("amount");
                }
            }
            if (!index.equals("8")) {
                DecimalFormat df = new DecimalFormat("0.0000");
                for (Map<String, Object> map : resultList) {
                    double rateG = (total > 0 ? ((long) map.get("amount")) * 1.0000 / total * 100 : 0);
                    map.put("rate", df.format(rateG));
                }
            }
            if (index.equals("6") && resultList.size() > 0) {
                int i = 0;
                boolean flag = false;
                for (; i < resultList.size(); i++) {
                    if (resultList.get(i).get("code") != null && String.valueOf(resultList.get(i).get("code")).equals("3")
                            && String.valueOf(resultList.get(i).get("amount")).equals("0")) {
                        flag = true;
                        break;
                    }
                }
                if (flag) {
                    resultList.remove(i);
                }
            }
            return new JSONArray(resultList);
        } else {
            return new JSONArray();
        }
    }
    /**
     * 获取二级指标的到达量
     *
     * @param endDate
     * @param area
     * @param level
     * @param index
     * @return
     */
    public List<Map<String, Object>> getTodyBeforeLevelTwototal(String endDate, String area, int level, String index) {
        String areaField = "";
        SimpleDateFormat datef = new SimpleDateFormat("yyyy-MM-dd");
        if (level == 4) {
            // 市级别
            areaField = "city";
        } else if (level == 3) {
            // 区、城镇级别
            areaField = "town";
        } else if (level == 2) {
            // 机构级别
            areaField = "org_code";
        } else if (level == 1) {
            // 团队
            areaField = "qkdoctor_code";
        }
        // 查询语句
        String sql = " select " +
                "     ifnull(level2_type,'') code " +
                "     ,ifnull(level2_type_name,'') 'name' " +
                "     ,ifnull(result,0.0) amount" +
                " from  " +
                "     wlyy_quota_result " +
                " where " +
                "     quato_code = '" + index + "' " +
                "   and level1_type = ? and del = '1'";
        sql += "   and quota_date = ? " +
                "   and " + areaField + " = ? " +
                " group by level2_type,level2_type_name";
        List<Map<String, Object>> resultList = new ArrayList<>();
        resultList = jdbcTemplate.queryForList(sql, new Object[]{level, endDate, area});
        if (resultList == null || resultList.size() < 1) {
            getLevelTwoMapKey(index);
        }
        return resultList;
    }
    /**
     * 查询某个指标的二级维度
     *
     * @param area
     * @param level
     * @param index
     * @return
     */
    public List<Map<String, Object>> getTodayLevelTwoTotal(String area, int level, String index) {
        List<Map<String, Object>> resultList = new ArrayList<>();
        String redisData = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area + ":" + getQuotaTimeStamp());
        if (!StringUtils.isEmpty(redisData)) {
            JSONArray jsonArray = new JSONArray(redisData);
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject json = jsonArray.getJSONObject(i);
                Map<String, Object> data = new HashMap<>();
                data.put("code", json.getString("code"));
                data.put("name", json.getString("name"));
                data.put("amount", Long.valueOf(String.valueOf(json.get("num"))));
                resultList.add(data);
            }
        }
        if (resultList.size() < 1) {
            resultList = getLevelTwoMapKey(index);
        }
        return resultList;
    }
    /**
     * 获取某个二级指标的统计key
     *
     * @param index
     * @return
     */
    public List<Map<String, Object>> getLevelTwoMapKey(String index) {
        List<Map<String, Object>> resultList = new ArrayList<>();
        if (index.equals("6")) {
            Map<String, Object> women = new HashMap<>();
            women.put("code", "1");
            women.put("name", "女");
            women.put("amount", Double.valueOf("0.0"));
            resultList.add(women);
            Map<String, Object> man = new HashMap<>();
            man.put("code", "2");
            man.put("name", "男");
            man.put("amount", Double.valueOf("0.0"));
            resultList.add(man);
            Map<String, Object> unknown = new HashMap<>();
            unknown.put("code", "3");
            unknown.put("name", "未知");
            unknown.put("amount", Double.valueOf("0.0"));
            resultList.add(unknown);
        } else if (index.equals("7")) {
            Map<String, Object> nogroup = new HashMap<>();
            nogroup.put("code", "0");
            nogroup.put("name", "未分组");
            nogroup.put("amount", Double.valueOf("0.0"));
            resultList.add(nogroup);
            Map<String, Object> normal = new HashMap<>();
            normal.put("code", "1");
            normal.put("name", "普通人群");
            normal.put("amount", Double.valueOf("0.0"));
            resultList.add(normal);
            Map<String, Object> manbing = new HashMap<>();
            manbing.put("code", "2");
            manbing.put("name", "慢病人群65岁以下");
            manbing.put("amount", Double.valueOf("0.0"));
            resultList.add(manbing);
            Map<String, Object> upsixfive = new HashMap<>();
            upsixfive.put("code", "3");
            upsixfive.put("name", "65岁以上人群");
            upsixfive.put("amount", Double.valueOf("0.0"));
            resultList.add(upsixfive);
            Map<String, Object> gxy = new HashMap<>();
            gxy.put("code", "4");
            gxy.put("name", "高血压");
            gxy.put("amount", Double.valueOf("0.0"));
            resultList.add(gxy);
            Map<String, Object> tnb = new HashMap<>();
            tnb.put("code", "5");
            tnb.put("name", "糖尿病");
            tnb.put("amount", Double.valueOf("0.0"));
            resultList.add(tnb);
            Map<String, Object> tnbGxy = new HashMap<>();
            tnbGxy.put("code", "6");
            tnbGxy.put("name", "高血压和糖尿病");
            tnbGxy.put("amount", Double.valueOf("0.0"));
            resultList.add(tnb);
            Map<String, Object> mb65UpGxy = new HashMap<>();
            mb65UpGxy.put("code", "7");
            mb65UpGxy.put("name", "慢病人群65岁以上");
            mb65UpGxy.put("amount", Double.valueOf("0.0"));
            resultList.add(mb65UpGxy);
        } else if (index.equals("8")) {
            Map<String, Object> map1 = new HashMap<>();
            map1.put("code", "1");
            map1.put("name", "0~6");
            map1.put("amount", Double.valueOf("0.0"));
            resultList.add(map1);
            Map<String, Object> map2 = new HashMap<>();
            map2.put("code", "2");
            map2.put("name", "7~18");
            map2.put("amount", Double.valueOf("0.0"));
            resultList.add(map2);
            Map<String, Object> map3 = new HashMap<>();
            map3.put("code", "3");
            map3.put("name", "18~30");
            map3.put("amount", Double.valueOf("0.0"));
            resultList.add(map3);
            Map<String, Object> map4 = new HashMap<>();
            map4.put("code", "4");
            map4.put("name", "30~50");
            map4.put("amount", Double.valueOf("0.0"));
            resultList.add(map4);
            Map<String, Object> map5 = new HashMap<>();
            map5.put("code", "5");
            map5.put("name", "50~65");
            map5.put("amount", Double.valueOf("0.0"));
            resultList.add(map5);
            Map<String, Object> map6 = new HashMap<>();
            map6.put("code", "6");
            map6.put("name", "50~65");
            map6.put("amount", Double.valueOf("0.0"));
            resultList.add(map6);
        } else if (index.equals("16")) {
            Map<String, Object> map1 = new HashMap<>();
            map1.put("code", "0");
            map1.put("name", "未缴费人数");
            map1.put("amount", Double.valueOf("0.0"));
            resultList.add(map1);
            Map<String, Object> map2 = new HashMap<>();
            map2.put("code", "1");
            map2.put("name", "已缴费人数");
            map2.put("amount", Double.valueOf("0.0"));
            resultList.add(map2);
            Map<String, Object> map3 = new HashMap<>();
            map3.put("code", "2");
            map3.put("name", "已退费人数");
            map3.put("amount", Double.valueOf("0.0"));
            resultList.add(map3);
        } else if (index.equals("15")) {
            Map<String, Object> map1 = new HashMap<>();
            map1.put("code", "0");
            map1.put("name", "未标注");
            map1.put("amount", Double.valueOf("0.0"));
            resultList.add(map1);
            Map<String, Object> map2 = new HashMap<>();
            map2.put("code", "1");
            map2.put("name", "健康人群");
            map2.put("amount", Double.valueOf("0.0"));
            resultList.add(map2);
            Map<String, Object> map3 = new HashMap<>();
            map3.put("code", "2");
            map3.put("name", "患病人群");
            map3.put("amount", Double.valueOf("0.0"));
            resultList.add(map3);
            Map<String, Object> map4 = new HashMap<>();
            map4.put("code", "3");
            map4.put("name", "高危人群");
            map4.put("amount", Double.valueOf("0.0"));
            resultList.add(map4);
            Map<String, Object> map5 = new HashMap<>();
            map5.put("code", "4");
            map5.put("name", "恢复期人群");
            map5.put("amount", Double.valueOf("0.0"));
            resultList.add(map5);
        }
        return resultList;
    }
    /**
     * 统计65以上人群数据
     *
     * @param endDate
     * @param area
     * @param level
     * @return
     */
    public JSONArray getSixFiveStatistics(String endDate, String area, int level) {
        String areaField = "";
        SimpleDateFormat datef = new SimpleDateFormat("yyyy-MM-dd");
        List<Map<String, Object>> resultList = new ArrayList<>();
        if (endDate.compareTo(datef.format(new Date())) >= 0) {
            String redisData = redisTemplate.opsForValue().get("quota:12:" + level + ":" + area + ":6:" + getQuotaTimeStamp());
            if (!StringUtils.isEmpty(redisData)) {
                JSONArray jsonArray = new JSONArray(redisData);
                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject json = jsonArray.getJSONObject(i);
                    Map<String, Object> data = new HashMap<>();
                    data.put("code", json.getString("code"));
                    data.put("name", json.getString("name"));
                    data.put("amount", Long.valueOf(String.valueOf(json.get("num"))));
                    resultList.add(data);
                }
            }
        } else {
            if (level == 4) {
                // 市级别
                areaField = "city";
            } else if (level == 3) {
                // 区、城镇级别
                areaField = "town";
            } else if (level == 2) {
                // 机构级别
                areaField = "org_code";
            } else if (level == 1) {
                // 团队
                areaField = "qkdoctor_code";
            }
            // 查询语句
            String sql = " select " +
                    "     ifnull(level3_type,'') code " +
                    "     ,ifnull(level3_type_name,'') 'name' " +
                    "     ,ifnull(result,0.0) amount" +
                    " from  " +
                    "     wlyy_quota_result " +
                    " where " +
                    "     quato_code = '12' " +
                    "   and level2_type = '6' " +
                    "   and level1_type = ? and del = '1'";
            sql += "   and quota_date = ? " +
                    "   and " + areaField + " = ? " +
                    " group by level3_type,level3_type_name";
            resultList = jdbcTemplate.queryForList(sql, new Object[]{level, endDate, area});
        }
        if (resultList == null || resultList.size() < 1) {
            resultList = new ArrayList<>();
            Map<String, Object> gxy = new HashMap<>();
            gxy.put("code", "1");
            gxy.put("name", "高血压");
            gxy.put("amount", Double.valueOf("0.0"));
            resultList.add(gxy);
            Map<String, Object> tnb = new HashMap<>();
            tnb.put("code", "2");
            tnb.put("name", "糖尿病");
            tnb.put("amount", Double.valueOf("0.0"));
            resultList.add(tnb);
            Map<String, Object> gxyTnb = new HashMap<>();
            gxyTnb.put("code", "3");
            gxyTnb.put("name", "高血压+糖尿病");
            gxyTnb.put("amount", Double.valueOf("0.0"));
            resultList.add(gxyTnb);
            Map<String, Object> jk = new HashMap<>();
            jk.put("code", "4");
            jk.put("name", "健康人群");
            jk.put("amount", Double.valueOf("0.0"));
            resultList.add(jk);
        }
        if (resultList != null) {
            for (Map<String, Object> map : resultList) {
                map.put("amount", map.get("amount") == null ? 0 : Math.round(Double.valueOf(map.get("amount").toString())));
            }
            // 65岁以上人群总数统计
            long sixFiveTotal = getSixFiveTotal(endDate, area, level);
            Map<String, Object> sixFive = new HashMap<>();
            sixFive.put("code", "0");
            sixFive.put("name", "总数");
            sixFive.put("amount", sixFiveTotal);
            resultList.add(sixFive);
            return new JSONArray(resultList);
        } else {
            return new JSONArray();
        }
    }
    /**
     * 获取65岁以上人群总数
     *
     * @param endDate
     * @param area
     * @param level
     * @return
     */
    public long getSixFiveTotal(String endDate, String area, int level) {
        String areaField = "";
        long total = 0;
        SimpleDateFormat datef = new SimpleDateFormat("yyyy-MM-dd");
        if (endDate.compareTo(datef.format(new Date())) >= 0) {
            String code = "6";
            String val = redisTemplate.opsForValue().get("quota:8:" + level + ":" + area + ":" + code + ":" + getQuotaTimeStamp());
            if (!StringUtils.isEmpty(val)) {
                JSONObject valJson = new JSONObject(val);
                if (valJson.has("num")) {
                    total = valJson.getInt("num");
                }
            }
        } else {
            if (level == 4) {
                // 市级别
                areaField = "city";
            } else if (level == 3) {
                // 区、城镇级别
                areaField = "town";
            } else if (level == 2) {
                // 机构级别
                areaField = "org_code";
            } else if (level == 1) {
                // 团队
                areaField = "qkdoctor_code";
            }
            // 查询语句
            String sql = " select " +
                    "     ifnull(result,0.0) amount" +
                    " from  " +
                    "     wlyy_quota_result " +
                    " where " +
                    "     quato_code = '8' " +
                    "   and level2_type = '6' " +
                    "   and level1_type = ? and del = '1'";
            sql += "   and quota_date = ? " +
                    "   and " + areaField + " = ? ";
            List<Map<String, Object>> result = null;
            result = jdbcTemplate.queryForList(sql, new Object[]{level, endDate, area});
            if (result != null && result.size() > 0) {
                total = (result.get(0).get("amount") == null ? 0 : Math.round(Double.valueOf(result.get(0).get("amount").toString())));
            }
        }
        return total;
    }
    /**
     * 查询某个日期范围内的某个指标每天到达量
     *
     * @param startDate
     * @param endDate
     * @param interval
     * @param area
     * @param level
     * @param index
     * @return
     */
    public JSONObject getDateTotal(String startDate, String endDate, int interval, String area, int level, String index) throws Exception {
        int taskNum = 0;
        JSONObject json = new JSONObject();
        if (level > 1) {
            String redisNum = redisTemplate.opsForValue().get("people:num:" + area);
            if (StringUtils.isEmpty(redisNum)) {
                PopulationBase peopleNum = peopleNumDao.findByCodeAndYear(area, Calendar.getInstance().get(Calendar.YEAR));
                if (peopleNum != null) {
                    taskNum = peopleNum.getTaskNum();
                }
            } else {
                JSONObject peopleNum = new JSONObject(redisNum);
                if (peopleNum != null) {
                    taskNum = peopleNum.getInt("taskNum");
                }
            }
        }
        json.put("taskNum", taskNum);
        if (interval == 1) {
            JSONArray jsonArray = dateTotalStatistics(startDate, endDate, area, level, index);
            json.put("data", jsonArray);
            return json;
        } else if (interval == 2) {
            JSONArray jsonArray = weekTotalStatistics(startDate, endDate, area, level, index);
            json.put("data", jsonArray);
            return json;
        } else if (interval == 3) {
            JSONArray jsonArray = monthTotalStatistics(startDate, endDate, area, level, index);
            json.put("data", jsonArray);
            return json;
        }
        return json;
    }
    /**
     * @param startDate
     * @param endDate
     * @param area
     * @param level
     * @param index
     * @return
     */
    public JSONArray dateTotalStatistics(String startDate, String endDate, String area, int level, String index) throws ParseException {
        String areaField = "";
        String sql = "";
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String dateCon = endDate;
        if (endDate.compareTo(df.format(new Date())) == 0) {
            Calendar calendar = Calendar.getInstance();
            calendar.add(Calendar.DATE, -1);
            dateCon = df.format(calendar.getTime());
        }
        if (level == 4) {
            // 市级别
            areaField = "city";
        } else if (level == 3) {
            // 区、城镇级别
            areaField = "town";
        } else if (level == 2) {
            // 机构级别
            areaField = "org_code";
        } else if (level == 1) {
            // 机构级别
            areaField = "qkdoctor_code";
        }
        // 起始日期
        Calendar start = Calendar.getInstance();
        start.setTime(DateUtil.strToDate(startDate, DateUtil.YYYY_MM_DD));
        //结束日期
        Calendar end = Calendar.getInstance();
        end.setTime(DateUtil.strToDate(endDate, DateUtil.YYYY_MM_DD));
        // 日期集合
        List<Calendar> days = new ArrayList<>();
        days.add(start);
        boolean flag = true;
        if (startDate.compareTo(endDate) == 0) {
            flag = false;
        }
        // 计算统计日期
        while (flag) {
            Calendar next = Calendar.getInstance();
            next.setTime(days.get(days.size() - 1).getTime());
            next.add(Calendar.DATE, 1);
            if (df.format(next.getTime()).compareTo(endDate) < 0) {
                days.add(next);
            } else {
                days.add(end);
                flag = false;
            }
        }
        Map<String, JSONObject> countResult = new HashMap<>();
        // 统计预计构建
        for (int i = 0; i < days.size(); i++) {
            String startStr = "";
            long amount = 0;
            startStr = df.format(days.get(i).getTime());
            // 当前范围包含当天,则需添加当天的统计数据
            if (startStr.compareTo(df.format(new Date())) == 0) {
                String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area + ":" + getQuotaTimeStamp());
                if (!StringUtils.isEmpty(val)) {
                    JSONObject valJson = new JSONObject(val);
                    if (valJson.has("num")) {
                        amount = (long) valJson.getInt("num");
                    }
                }
            }
            JSONObject range = new JSONObject();
            range.put("range", startStr);
            range.put("amount", amount);
            countResult.put(startStr, range);
        }
        if (startDate.equals(df.format(new Date()))) {
            Calendar preDate = Calendar.getInstance();
            preDate.setTime(df.parse(endDate));
            preDate.add(Calendar.DATE, -1);
            startDate = df.format(preDate.getTime());
        }
        sql = " select " +
                "     ifnull(quota_date,'') as 'range' " +
                "     ,ifnull(result,'0') amount " +
                " from  " +
                "     wlyy_quota_result " +
                " where " +
                "     quato_code = '" + index + "' " +
                "   and level1_type = '" + level + "' and del = '1' " +
                "   and quota_date >= '" + startDate + "' " +
                "   and quota_date <= '" + dateCon + "' " +
                "   and " + areaField + " = '" + area + "' ";
        List<Map<String, Object>> resultList = jdbcTemplate.queryForList(sql);
        if (resultList != null) {
            for (Map<String, Object> map : resultList) {
                if (countResult.containsKey(map.get("range").toString())) {
                    JSONObject range = (JSONObject) countResult.get(map.get("range").toString());
                    long amount = range.getLong("amount");
                    long resultAmount = map.get("amount") != null ? Long.valueOf(map.get("amount").toString()) : 0L;
                    range.put("amount", amount + resultAmount);
                }
            }
            List<JSONObject> result = new ArrayList<>(countResult.values());
            result.sort(new Comparator<JSONObject>() {
                @Override
                public int compare(JSONObject o1, JSONObject o2) {
                    if (o1.getString("range").compareTo(o2.getString("range")) > 0) {
                        return 1;
                    } else if (o1.getString("range").compareTo(o2.getString("range")) < 0) {
                        return -1;
                    } else {
                        return 0;
                    }
                }
            });
            return new JSONArray(result);
        } else {
            return new JSONArray();
        }
    }
    /**
     * 按周统计
     *
     * @param startDate
     * @param endDate
     * @param area
     * @param level
     * @param index
     * @return
     */
    private JSONArray weekTotalStatistics(String startDate, String endDate, String area, int level, String index) throws Exception {
        String areaField = "";
        String sql = "";
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String dateCon = endDate;
        if (endDate.compareTo(df.format(new Date())) == 0) {
            Calendar calendar = Calendar.getInstance();
            calendar.add(Calendar.DATE, -1);
            dateCon = df.format(calendar.getTime());
        }
        if (level == 4) {
            // 市级别
            areaField = "city";
        } else if (level == 3) {
            // 区、城镇级别
            areaField = "town";
        } else if (level == 2) {
            // 机构级别
            areaField = "org_code";
        } else if (level == 1) {
            // 机构级别
            areaField = "qkdoctor_code";
        }
        // 起始日期
        Calendar start = Calendar.getInstance();
        start.setTime(DateUtil.strToDate(startDate, DateUtil.YYYY_MM_DD));
        // 第一个统计周期结束日期
        String firstEnd = "";
        // 结束日期
        Calendar end = Calendar.getInstance();
        end.setTime(DateUtil.strToDate(endDate, DateUtil.YYYY_MM_DD));
        // 起始日期为周几
        int week = start.get(Calendar.DAY_OF_WEEK);
        int incre = 7 - week + 1;
        // 日期集合
        List<Calendar> days = new ArrayList<>();
        days.add(start);
        boolean flag = true;
        int i = 0;
        if (startDate.compareTo(endDate) == 0) {
            flag = false;
            days.add(end);
            firstEnd = df.format(end.getTime());
        }
        // 计算统计日期
        while (flag) {
            Calendar next = Calendar.getInstance();
            next.setTime(days.get(days.size() - 1).getTime());
            if (i == 0) {
                if (incre != 7) {
                    next.add(Calendar.DATE, incre);
                }
            } else {
                next.add(Calendar.DATE, 7);
            }
            if (df.format(next.getTime()).compareTo(df.format(end.getTime())) < 0) {
                days.add(next);
                if (i == 0) {
                    firstEnd = df.format(next.getTime());
                }
            } else {
                days.add(end);
                flag = false;
                if (i == 0) {
                    firstEnd = df.format(end.getTime());
                }
            }
            i++;
        }
        // 结果集
        Map<String, JSONObject> countResult = new HashMap<>();
        // 算出每个查询周期
        for (int j = 0; j < days.size() - 1; j++) {
            String startStr = "";
            String endStr = df.format(days.get(j + 1).getTime());
            long amount = 0;
            // 起始、截止日期
            if (j == 0) {
                startStr = df.format(days.get(j).getTime());
            } else {
                Calendar cal = Calendar.getInstance();
                cal.setTime(days.get(j).getTime());
                cal.add(Calendar.DATE, 1);
                startStr = df.format(cal.getTime());
            }
            // 当前范围包含当天,则需添加当天的统计数据
            if (startStr.compareTo(df.format(new Date())) <= 0 && endStr.compareTo(df.format(new Date())) >= 0) {
                String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area + ":" + getQuotaTimeStamp());
                if (!StringUtils.isEmpty(val)) {
                    JSONObject valJson = new JSONObject(val);
                    if (valJson.has("num")) {
                        amount = valJson.getInt("num");
                    }
                }
            }
            JSONObject range = new JSONObject();
            range.put("range", endStr);
            range.put("amount", amount);
            countResult.put(endStr, range);
        }
        if (startDate.equals(df.format(new Date()))) {
            Calendar preDate = Calendar.getInstance();
            preDate.setTime(df.parse(endDate));
            preDate.add(Calendar.DATE, -1);
            startDate = df.format(preDate.getTime());
        }
        // 查询时间范围内所有记录
        sql = " select " +
                "     ifnull(quota_date,'') as 'range' " +
                "     ,ifnull(result,'0') amount " +
                " from  " +
                "     wlyy_quota_result " +
                " where " +
                "     quato_code = '" + index + "' " +
                "   and level1_type = '" + level + "' and del = '1' " +
                "   and quota_date >= '" + startDate + "' " +
                "   and quota_date <= '" + dateCon + "' " +
                "   and " + areaField + " = '" + area + "' ";
        List<Map<String, Object>> resultList = jdbcTemplate.queryForList(sql);
        if (resultList != null) {
            // 计算结果
            for (Map<String, Object> map : resultList) {
                String range = map.get("range").toString();
                JSONObject json = countResult.get(range);
                if (json != null) {
                    long amount = map.get("amount") == null ? 0L : Long.valueOf(map.get("amount").toString());
                    json.put("amount", amount);
                }
            }
            List<JSONObject> result = new ArrayList<>(countResult.values());
            // 排序
            result.sort(new Comparator<JSONObject>() {
                @Override
                public int compare(JSONObject o1, JSONObject o2) {
                    if (o1.getString("range").compareTo(o2.getString("range")) > 0) {
                        return 1;
                    } else if (o1.getString("range").compareTo(o2.getString("range")) < 0) {
                        return -1;
                    } else {
                        return 0;
                    }
                }
            });
            return new JSONArray(result);
        } else {
            return new JSONArray();
        }
    }
    /**
     * 按月统计
     *
     * @param startDate
     * @param endDate
     * @param area
     * @param level
     * @param index
     * @return
     * @throws Exception
     */
    private JSONArray monthTotalStatistics(String startDate, String endDate, String area, int level, String index) throws Exception {
        String areaField = "";
        String sql = "";
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String dateCon = endDate;
        if (endDate.compareTo(df.format(new Date())) == 0) {
            Calendar calendar = Calendar.getInstance();
            calendar.add(Calendar.DATE, -1);
            dateCon = df.format(calendar.getTime());
        }
        if (level == 4) {
            // 市级别
            areaField = "city";
        } else if (level == 3) {
            // 区、城镇级别
            areaField = "town";
        } else if (level == 2) {
            // 机构级别
            areaField = "org_code";
        } else if (level == 1) {
            // 机构级别
            areaField = "qkdoctor_code";
        }
        // 起始日期
        Calendar start = Calendar.getInstance();
        start.setTime(DateUtil.strToDate(startDate, DateUtil.YYYY_MM_DD));
        // 结束日期
        Calendar end = Calendar.getInstance();
        end.setTime(DateUtil.strToDate(endDate, DateUtil.YYYY_MM_DD));
        // 第一个结束日期
        String firstEnd = "";
        // 日期集合
        List<Calendar> days = new ArrayList<>();
        days.add(start);
        boolean flag = true;
        int k = 0;
        if (startDate.compareTo(endDate) == 0) {
            flag = false;
            days.add(end);
        }
        // 统计日期计算
        while (flag) {
            Calendar next = Calendar.getInstance();
            next.setTime(days.get(days.size() - 1).getTime());
            if (k == 0) {
                next.add(Calendar.MONTH, 1);
            } else {
                next.add(Calendar.MONTH, 2);
            }
            next.set(Calendar.DAY_OF_MONTH, 1);
            next.add(Calendar.DAY_OF_MONTH, -1);
            if (df.format(next.getTime()).compareTo(df.format(end.getTime())) < 0) {
                days.add(next);
            } else {
                days.add(end);
                flag = false;
            }
            k++;
        }
        // 统计结果
        Map<String, JSONObject> countResult = new HashMap<>();
        for (int i = 0; i < days.size() - 1; i++) {
            String startStr = "";
            String endStr = df.format(days.get(i + 1).getTime());
            int amount = 0;
            // 起始时间计算
            if (i == 0) {
                startStr = df.format(days.get(i).getTime());
            } else {
                Calendar cal = Calendar.getInstance();
                cal.setTime(days.get(i).getTime());
                cal.add(Calendar.DATE, 1);
                startStr = df.format(cal.getTime());
            }
            // 当天数据计算
            if (startStr.compareTo(df.format(new Date())) <= 0 && endStr.compareTo(df.format(new Date())) >= 0) {
                String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area + ":" + getQuotaTimeStamp());
                if (!StringUtils.isEmpty(val)) {
                    JSONObject valJson = new JSONObject(val);
                    if (valJson.has("num")) {
                        amount = valJson.getInt("num");
                    }
                }
            }
            JSONObject range = new JSONObject();
            range.put("range", endStr);
            range.put("amount", amount);
            countResult.put(endStr, range);
        }
        if (startDate.equals(df.format(new Date()))) {
            Calendar preDate = Calendar.getInstance();
            preDate.setTime(df.parse(endDate));
            preDate.add(Calendar.DATE, -1);
            startDate = df.format(preDate.getTime());
        }
        // 查询时间范围内所有记录
        sql = " select " +
                "     ifnull(quota_date,'') as 'range' " +
                "     ,ifnull(result,'0') amount " +
                " from  " +
                "     wlyy_quota_result " +
                " where " +
                "     quato_code = '" + index + "' " +
                "   and level1_type = '" + level + "' and del = '1' " +
                "   and quota_date >= '" + startDate + "' " +
                "   and quota_date <= '" + dateCon + "' " +
                "   and " + areaField + " = '" + area + "' ";
        List<Map<String, Object>> resultList = jdbcTemplate.queryForList(sql);
        if (resultList != null) {
            String pre = "";
            if (endDate.equals(df.format(new Date()))) {
                Calendar preDate = Calendar.getInstance();
                preDate.setTime(df.parse(endDate));
                preDate.add(Calendar.DATE, -1);
                pre = df.format(preDate.getTime());
            }
            // 计算结果
            for (Map<String, Object> map : resultList) {
                String range = map.get("range").toString();
                JSONObject json = countResult.get(range);
                if (json != null) {
                    long amount = map.get("amount") == null ? 0L : Long.valueOf(map.get("amount").toString());
                    json.put("amount", amount);
                }
            }
            List<JSONObject> result = new ArrayList<>(countResult.values());
            // 排序
            result.sort(new Comparator<JSONObject>() {
                @Override
                public int compare(JSONObject o1, JSONObject o2) {
                    if (o1.getString("range").compareTo(o2.getString("range")) > 0) {
                        return 1;
                    } else if (o1.getString("range").compareTo(o2.getString("range")) < 0) {
                        return -1;
                    } else {
                        return 0;
                    }
                }
            });
            return new JSONArray(result);
        } else {
            return new JSONArray();
        }
    }
}

+ 23 - 10
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statistics/StatisticsService.java

@ -70,6 +70,11 @@ public class StatisticsService extends BaseService {
    private StringRedisTemplate redisTemplate;
    /**
     * 获取上次统计时间
     *
     * @return
     */
    public String getStatisticsTime() {
        String date = redisTemplate.opsForValue().get("quota:date");
@ -77,6 +82,15 @@ public class StatisticsService extends BaseService {
    }
    /**
     * 获取时间戳
     *
     * @return
     */
    public String getQuotaTimeStamp() {
        return redisTemplate.opsForValue().get("quota:timeKey");
    }
    /**
     * 缓存人口数据到redis
     *
@ -130,7 +144,7 @@ public class StatisticsService extends BaseService {
        // 截止日期包含当天,则从redis查询当天统计数据
        if (endDate.compareTo(new SimpleDateFormat("yyyy-MM-dd").format(new Date())) >= 0) {
            String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area);
            String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area + ":" + getQuotaTimeStamp());
            if (!StringUtils.isEmpty(val)) {
                JSONObject valJson = new JSONObject(val);
                if (valJson.has("num")) {
@ -192,7 +206,7 @@ public class StatisticsService extends BaseService {
        // 截止日期包含当天,则从redis查询当天统计数据
        if (endDate.compareTo(new SimpleDateFormat("yyyy-MM-dd").format(new Date())) >= 0) {
            String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area);
            String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area + ":" + getQuotaTimeStamp());
            if (!StringUtils.isEmpty(val)) {
                JSONObject valJson = new JSONObject(val);
                if (valJson.has("num")) {
@ -256,7 +270,7 @@ public class StatisticsService extends BaseService {
        // 截止日期包含当天,则从redis查询当天统计数据
        if (endDate.compareTo(new SimpleDateFormat("yyyy-MM-dd").format(new Date())) >= 0) {
            String val = redisTemplate.opsForValue().get("quota:16:" + level + ":0:" + area);
            String val = redisTemplate.opsForValue().get("quota:16:" + level + ":" + area + ":0:" + getQuotaTimeStamp());
            if (!StringUtils.isEmpty(val)) {
                JSONObject valJson = new JSONObject(val);
                if (valJson.has("num")) {
@ -368,7 +382,7 @@ public class StatisticsService extends BaseService {
        // 截止日期包含当天,则从redis查询当天统计数据
        if (endDate.compareTo(new SimpleDateFormat("yyyy-MM-dd").format(new Date())) >= 0) {
            String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area);
            String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area + ":" + getQuotaTimeStamp());
            if (!StringUtils.isEmpty(val)) {
                JSONObject valJson = new JSONObject(val);
                if (valJson.has("num")) {
@ -528,7 +542,7 @@ public class StatisticsService extends BaseService {
                // 截止日期包含当天,则从redis查询当天统计数据
                if (endDate.compareTo(new SimpleDateFormat("yyyy-MM-dd").format(new Date())) >= 0) {
                    String code = map.get("code") != null ? String.valueOf(map.get("code")) : "";
                    String val = redisTemplate.opsForValue().get("quota:" + index + ":" + low_level + ":" + code);
                    String val = redisTemplate.opsForValue().get("quota:" + index + ":" + low_level + ":" + code + ":" + getQuotaTimeStamp());
                    if (!StringUtils.isEmpty(val)) {
                        JSONObject valJson = new JSONObject(val);
                        if (valJson.has("num")) {
@ -721,7 +735,7 @@ public class StatisticsService extends BaseService {
                // 截止日期包含当天,则从redis查询当天统计数据
                if (endDate.compareTo(new SimpleDateFormat("yyyy-MM-dd").format(new Date())) >= 0) {
                    String code = map.get("code") != null ? String.valueOf(map.get("code")) : "";
                    String val = redisTemplate.opsForValue().get("quota:" + index + ":" + low_level + ":" + code);
                    String val = redisTemplate.opsForValue().get("quota:" + index + ":" + low_level + ":" + code + ":" + getQuotaTimeStamp());
                    if (!StringUtils.isEmpty(val)) {
                        JSONObject valJson = new JSONObject(val);
                        if (valJson.has("num")) {
@ -844,7 +858,7 @@ public class StatisticsService extends BaseService {
            // 当前范围包含当天,则需添加当天的统计数据
            if (startStr.compareTo(today) == 0) {
                String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area);
                String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area + ":" + getQuotaTimeStamp());
                if (!StringUtils.isEmpty(val)) {
                    JSONObject valJson = new JSONObject(val);
                    if (valJson.has("num")) {
@ -1008,7 +1022,7 @@ public class StatisticsService extends BaseService {
            // 当前范围包含当天,则需添加当天的统计数据
            if (startStr.compareTo(today) <= 0 && endStr.compareTo(today) >= 0) {
                String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area);
                String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area + ":" + getQuotaTimeStamp());
                if (!StringUtils.isEmpty(val)) {
                    JSONObject valJson = new JSONObject(val);
                    if (valJson.has("num")) {
@ -1204,7 +1218,7 @@ public class StatisticsService extends BaseService {
            // 当天数据计算
            if (startStr.compareTo(today) <= 0 && endStr.compareTo(today) >= 0) {
                String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area);
                String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area + ":" + getQuotaTimeStamp());
                if (!StringUtils.isEmpty(val)) {
                    JSONObject valJson = new JSONObject(val);
                    if (valJson.has("num")) {
@ -2796,7 +2810,6 @@ public class StatisticsService extends BaseService {
                        }
                    }
                }
                if (index.equals(GROUP)) {
                    // 分组指标总数算法
                    String code = map.get("code") != null ? String.valueOf(map.get("code")) : "";

+ 1 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/common/account/PatientService.java

@ -139,7 +139,7 @@ public class PatientService extends TokenService {
				json.put("token", token.getToken());
				json.put("name", temp.getName());
				json.put("photo", temp.getPhoto());
				new Thread(new SignSsGetTask(patient.getIdcard())).start();
				//new Thread(new SignSsGetTask(patient.getIdcard())).start();
				return json;
			}
		}

+ 30 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/util/IdCardUtil.java

@ -152,4 +152,34 @@ public class IdCardUtil {
        }
        return sex;
    }
    /**
     * 根据身份证的号码算出当前身份证持有者的性别
     * 1 男 2 女 3未知
     *
     * @return
     * @throws Exception
     */
    public static String getSexForIdcard_new(String CardCode)
            throws Exception {
        String sex = Constant.level_sex_3;
        if (CardCode.length() == 18) {
            if (Integer.parseInt(CardCode.substring(16).substring(0, 1)) % 2 == 0) {// 判断性别
                // modifid by lyr 2016-09-29
                 sex =  Constant.level_sex_2;
                // modifid by lyr 2016-09-29
            } else {
                // modifid by lyr 2016-09-29
                 sex =  Constant.level_sex_1;
                // modifid by lyr 2016-09-29
            }
        } else if (CardCode.length() == 15) {
            String usex = CardCode.substring(14, 15);// 用户的性别
            if (Integer.parseInt(usex) % 2 == 0) {
                 sex =  Constant.level_sex_2;
            } else {
                sex =  Constant.level_sex_1;
            }
        }
        return sex;
    }
}

+ 1 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/common/account/WechatController.java

@ -342,7 +342,7 @@ public class WechatController extends WeixinBaseController {
        loginLog.setUserType("1");
        try {
            //账号登录 mobile可能是电话号也可能是身份证
            if(StringUtils.isNoneEmpty(mobile)&&StringUtils.isNoneEmpty(password)){
            if(StringUtils.isNoneEmpty(mobile)&&StringUtils.isNoneEmpty(password)&&!org.springframework.util.StringUtils.isEmpty(mobile)){
                Patient patient = patientService.findByMobile(mobile);
                if(patient==null){
                    patient= patientService.findByIdcard(mobile);

+ 24 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/account/DoctorController.java

@ -1497,6 +1497,30 @@ public class DoctorController extends BaseController {
        }
    }
    /**
     * 手机号是否注册
     *
     * @param mobile 手机号
     * @return
     */
    @RequestMapping("/is_mobile_register")
    @ResponseBody
    public String isMobileRegister(String mobile){
        try {
            if (StringUtils.isEmpty(mobile)) {
                return error(-1, "手机号码不能为空");
            }
            int result = doctorInfoService.isMobileRegister(mobile);
            return write(200, "查询成功","data",result);
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "查询失败");
        }
    }
    /**
     * 修改密码
     *

+ 8 - 8
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/sign/DoctorFamilyContractController.java

@ -515,14 +515,14 @@ public class DoctorFamilyContractController extends WeixinBaseController {
                        }
                    }
                }
                String resultStr = HttpUtil.sendPost(checkUrl + "/third/sign/LoadSanshiSignFamily?idcard=" + idCard, "");
                if (!StringUtils.isEmpty(resultStr)) {
                    JSONObject checkJson = new JSONObject(resultStr);
                    if (checkJson.getInt("status") != 200) {
                        throw new Exception("sanshi sign get from jw failed");
                    }
                }
//                String resultStr = HttpUtil.sendPost(checkUrl + "/third/sign/LoadSanshiSignFamily?idcard=" + idCard, "");
//
//                if (!StringUtils.isEmpty(resultStr)) {
//                    JSONObject checkJson = new JSONObject(resultStr);
//                    if (checkJson.getInt("status") != 200) {
//                        throw new Exception("sanshi sign get from jw failed");
//                    }
//                }
            } catch (Exception e) {
                e.printStackTrace();
            }

+ 23 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/account/PatientController.java

@ -679,6 +679,29 @@ public class PatientController extends WeixinBaseController {
        }
    }
    /**
     * 手机号是否注册
     *
     * @param mobile 手机号
     * @return
     */
    @RequestMapping("/is_mobile_register")
    @ResponseBody
    public String isMobileRegister(String mobile){
        try {
            if (StringUtils.isEmpty(mobile)) {
                return error(-1, "手机号码不能为空");
            }
            int result = patientInfoService.isMobileRegister(mobile);
            return write(200, "查询成功","data",result);
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "查询失败");
        }
    }
    /**
     *  修改密码
     * @param newPassword1 新密码1

+ 5 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/family/FamilyMemberController.java

@ -59,9 +59,13 @@ public class FamilyMemberController extends BaseController {
            } else if (result == -2) {
                return error(-1, "该成员未注册");
            } else if (result == -3) {
                return error(-1, StringUtils.isNotEmpty(captcha) ? "验证码错误" : "密码错误");
                return error(-1, StringUtils.isNotEmpty(captcha) ? "请输入正确的验证码" : "密码错误");
            } else if (result == -4) {
                return error(-1, "该家庭成员已存在");
            } else if (result == -5) {
                return error(-1, "该家庭关系已存在成员");
            } else if (result == -6) {
                return error(-1, "验证码已过期,请重新获取验证码");
            } else if (result == 0) {
                return error(-1, "不能添加自己");
            } else {

+ 1 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/quota/JobController.java

@ -58,6 +58,7 @@ public class JobController extends BaseController {
    @RequestMapping(value = "startNowById", method = RequestMethod.GET)
    public String startNowById(String id) {
        try {
            jobService.startNowById(id);
            return success("启动成功!");
        } catch (Exception e) {

+ 13 - 10
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/statistic/StatisticsController.java

@ -1,6 +1,7 @@
package com.yihu.wlyy.web.statistic;
import com.yihu.wlyy.entity.statistics.PopulationBase;
import com.yihu.wlyy.service.app.statistics.StatisticsAllService;
import com.yihu.wlyy.service.app.statistics.StatisticsService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
@ -24,6 +25,8 @@ public class StatisticsController extends BaseController {
    @Autowired
    StatisticsService statisticsService;
    @Autowired
    StatisticsAllService statisticsAllService;
    /**
     * 获取统计时间
@ -201,7 +204,7 @@ public class StatisticsController extends BaseController {
            JSONObject result = new JSONObject();
            for (String idx : indexes) {
                result.put("index_" + idx, statisticsService.getIndexLevelTwototal(endDate, area, level, idx));
                result.put("index_" + idx, statisticsAllService.getIndexLevelTwototal(endDate, area, level, idx));
            }
            return write(200, "查询成功", "data", result);
@ -226,10 +229,10 @@ public class StatisticsController extends BaseController {
        try {
            JSONObject result = new JSONObject();
            long sign = statisticsService.getIndexTotal(endDate, area, level, "13");
            long weiJf = statisticsService.getWeiJiaoFei(endDate, area, level);
            JSONObject signRate = statisticsService.getSignRate(endDate, area, level);
            JSONObject signTaskRate = statisticsService.getSignTaskRate(endDate, area, level);
            long sign = statisticsAllService.getIndexTotal(endDate, area, level, "13");
            long weiJf = statisticsAllService.getWeiJiaoFei(endDate, area, level);
            JSONObject signRate = statisticsAllService.getSignRate(endDate, area, level);
            JSONObject signTaskRate = statisticsAllService.getSignTaskRate(endDate, area, level);
            result.put("sign", sign);
            result.put("expenses", weiJf);
@ -256,7 +259,7 @@ public class StatisticsController extends BaseController {
    @ResponseBody
    public String getSixFiveStatistics(String startDate, String endDate, String area, int level) {
        try {
            JSONArray result = statisticsService.getSixFiveStatistics(endDate, area, level);
            JSONArray result = statisticsAllService.getSixFiveStatistics(endDate, area, level);
            return write(200, "查询成功", "data", result);
        } catch (Exception e) {
@ -285,7 +288,7 @@ public class StatisticsController extends BaseController {
            if (index != null) {
                for (String idx : indexes) {
                    result.put("index_" + idx, statisticsService.getDateTotal(startDate, endDate, interval, area, level, idx));
                    result.put("index_" + idx, statisticsAllService.getDateTotal(startDate, endDate, interval, area, level, idx));
                }
            }
@ -313,7 +316,7 @@ public class StatisticsController extends BaseController {
            JSONObject result = new JSONObject();
            for (String idx : indexes) {
                result.put("index_" + idx, statisticsService.getLowLevelTotal(date, area, level, idx, sort, lowLevel));
                result.put("index_" + idx, statisticsAllService.getLowLevelTotal(date, area, level, idx, sort, lowLevel));
            }
            return write(200, "查询成功", "data", result);
@ -340,7 +343,7 @@ public class StatisticsController extends BaseController {
            JSONObject result = new JSONObject();
            for (String idx : indexes) {
                result.put("index_" + idx, statisticsService.getIndexLevelTwototal(date, area, level, idx));
                result.put("index_" + idx, statisticsAllService.getIndexLevelTwototal(date, area, level, idx));
            }
            return write(200, "查询成功", "data", result);
@ -367,7 +370,7 @@ public class StatisticsController extends BaseController {
            JSONObject result = new JSONObject();
            for (String idx : indexes) {
                result.put("index_" + idx, statisticsService.getIndexTotal(endDate, area, level, idx));
                result.put("index_" + idx, statisticsAllService.getIndexTotal(endDate, area, level, idx));
            }
            return write(200, "查询成功", "data", result);