Browse Source

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

linzhuo 8 years ago
parent
commit
6cb6f0fdff

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

@ -81,7 +81,7 @@ public class SignDataFilter {
     *
     * @param signFamilies 签约列表
     * @param level2Key    二级维度的key
     *                       1:性别 2:年龄 3:分组 4:费用 5:健康服务分布 6:年龄 7:年龄疾病
     *                     1:性别 2:年龄 3:分组 4:费用 5:健康服务分布 6:年龄 7:年龄疾病
     * @param filterDate   过滤的是哪天的数据 yyyy-MM-dd
     * @return
     */
@ -94,9 +94,9 @@ public class SignDataFilter {
     *
     * @param signFamilies 签约列表
     * @param level2Key    二级维度的key
     *                       1:性别 2:年龄 3:分组 4:费用 5:健康服务分布 6:年龄 7:年龄疾病
     *                     1:性别 2:年龄 3:分组 4:费用 5:健康服务分布 6:年龄 7:年龄疾病
     * @param level3Key    三级维度的key
     *                      1.疾病
     *                     1.疾病
     * @param filterDate   过滤的是哪天的数据 yyyy-MM-dd
     * @return
     */
@ -109,9 +109,9 @@ public class SignDataFilter {
     *
     * @param signFamilies 签约列表
     * @param level2Key    二级维度的key
     *                       1:性别 2:年龄 3:分组 4:费用 5:健康服务分布 6:年龄 7:年龄疾病
     *                     1:性别 2:年龄 3:分组 4:费用 5:健康服务分布 6:年龄 7:年龄疾病
     * @param level3Key    三级维度的key
     *                      1.疾病
     *                     1.疾病
     * @param filterDate   过滤的是哪天的数据 yyyy-MM-dd
     * @return
     */
@ -300,7 +300,8 @@ public class SignDataFilter {
    /**
     * 得到二级维度的key
     *1:性别 2:年龄 3:分组 4:费用 5:健康服务分布 6:年龄 7:年龄疾病
     * 1:性别 2:年龄 3:分组 4:费用 5:健康服务分布 6:年龄 7:年龄疾病
     *
     * @param level2Key
     * @return
     */
@ -588,34 +589,34 @@ public class SignDataFilter {
                errorCount++;
                continue;
            }
            Long adminId=signFamily.getAdminTeamCode();
            Long adminId = signFamily.getAdminTeamCode();
            //医生团队列表
            List<Long> adminTeamList=new ArrayList<>();
            if(adminId == null||adminId<=0) {
            List<Long> adminTeamList = new ArrayList<>();
            if (adminId == null || adminId <= 0) {
                //如果团队是空 把数目给待签约的医生 可能是健康管理师也可以能是全科
                if(!StringUtils.isEmpty(signFamily.getDoctor())) {
                if (!StringUtils.isEmpty(signFamily.getDoctor())) {
                    //找出全科医生所在的团队
                    String sqlD="select DISTINCT team_id from wlyy_admin_team_member w where w.doctor_code='"+signFamily.getDoctor()+"'";
                    adminTeamList= jdbcTemplate.queryForList(sqlD,Long.class);
                    if(adminTeamList==null&&adminTeamList.size()==0){
                        errorModels.add(ErrorModel.newEM(signFamily.getCode(),ErrorModel.sign_adminTeam_null));
                        isAll=false;
                    String sqlD = "select DISTINCT team_id from wlyy_admin_team_member w where w.doctor_code='" + signFamily.getDoctor() + "'";
                    adminTeamList = jdbcTemplate.queryForList(sqlD, Long.class);
                    if (adminTeamList == null && adminTeamList.size() == 0) {
                        errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.sign_adminTeam_null));
                        isAll = false;
                        errorCount++;
                        continue;
                    }
                }else if(!StringUtils.isEmpty(signFamily.getDoctorHealth())){
                } else if (!StringUtils.isEmpty(signFamily.getDoctorHealth())) {
                    //找出健康管理师所在的团队
                    String sqlD="select DISTINCT team_id from wlyy_admin_team_member w where w.doctor_code='"+signFamily.getDoctorHealth()+"'  ";
                    adminTeamList= jdbcTemplate.queryForList(sqlD,Long.class);
                    if(adminTeamList==null&&adminTeamList.size()==0){
                        errorModels.add(ErrorModel.newEM(signFamily.getCode(),ErrorModel.sign_adminTeam_null));
                        isAll=false;
                    String sqlD = "select DISTINCT team_id from wlyy_admin_team_member w where w.doctor_code='" + signFamily.getDoctorHealth() + "'  ";
                    adminTeamList = jdbcTemplate.queryForList(sqlD, Long.class);
                    if (adminTeamList == null && adminTeamList.size() == 0) {
                        errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.sign_adminTeam_null));
                        isAll = false;
                        errorCount++;
                        continue;
                    }
                }else{
                    errorModels.add(ErrorModel.newEM(signFamily.getCode(),ErrorModel.sign_adminTeam_null));
                    isAll=false;
                } else {
                    errorModels.add(ErrorModel.newEM(signFamily.getCode(), ErrorModel.sign_adminTeam_null));
                    isAll = false;
                    errorCount++;
                    continue;
                }
@ -625,18 +626,18 @@ public class SignDataFilter {
            String returnLevel3Key = getLevel3Key(level3Key, signFamily);
            if (StringUtils.isEmpty(returnLevel2Key)) {
                //没有二级维度
                for(int teamNum=0;teamNum<adminTeamList.size();teamNum++){
                for (int teamNum = 0; teamNum < adminTeamList.size(); teamNum++) {
                    ETLModel etlModel = new ETLModel();
                    etlModel.setHospital(orgCodeTemp);
                    etlModel.setTown(hospital.getTown());
                    etlModel.setCity(Constant.city);
                    etlModel.setAdminTeam(adminTeamList.get(teamNum)+"");
                    etlModel.setAdminTeam(adminTeamList.get(teamNum) + "");
                    etlModelList.add(etlModel);
                }
            } else {
                String[] level2Keys = returnLevel2Key.split(",");
                for (int j = 0; j < level2Keys.length; j++) {
                    for(int teamNum=0;teamNum<adminTeamList.size();teamNum++) {
                    for (int teamNum = 0; teamNum < adminTeamList.size(); teamNum++) {
                        ETLModel etlModel = new ETLModel();
                        etlModel.setLevel2Key(level2Keys[j]);
                        etlModel.setLevel3Key(returnLevel3Key);

+ 4 - 4
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/etl/model/FilterModel.java

@ -21,14 +21,14 @@ public class FilterModel {
        this.etlModelList = etlModelList;
    }
    public static FilterModel getFiltrerMode(LogModel logModel, List<ETLModel> etlModelList,Boolean isError){
        return new FilterModel(logModel,etlModelList,isError);
    }
    public LogModel getLogModel() {
        return logModel;
    }
    public static FilterModel getFiltrerMode(LogModel logModel, List<ETLModel> etlModelList,Boolean isError){
        return new FilterModel(logModel,etlModelList,isError);
    }
    public void setLogModel(LogModel logModel) {
        this.logModel = logModel;
    }

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

@ -37,6 +37,7 @@ import org.springframework.context.annotation.Scope;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.nativejdbc.OracleJdbc4NativeJdbcExtractor;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
@ -158,30 +159,31 @@ public class CurrentDayAllQuotaJob implements Job {
        //抽取數據
        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,null); //统计今天的签约患者性别
        computequota_7(sql,signFamilies,null);//统计今天的签约患者分组
        computequota_8(sql,signFamilies,null);//统计今天的签约患者年龄
        computequota_9();//统计今天的待签约
        computequota_10();//统计今天的改签
        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
        computequota_17(sql,signFamilies,null);//统计今天的年龄疾病
        computequota_20();//统计今天的已经签约患者绑定设备
        computequota_21();//统计今天的已经签约微信关注人数
        computequota_22();//未回复的咨询量
        computequota_23();//及时回复的咨询量
        computequota_24();//及时回复的咨询量时间分布
        computequota_25();//统计质询量总数
        computequota_26();//统计未缴费签约总数
        computequota_27();//统计代预约量
//        computequota_1(sql,signFamilies,null); //统计今天的签约
//        computequota_2(); //统计今天的解约
//        computequota_3(); //统计今天的健康咨询量
//        computequota_4(); //统计今天的随访量
//        computequota_5(); //统计今天的健康指导
//        computequota_6(sql,signFamilies,null); //统计今天的签约患者性别
//        computequota_7(sql,signFamilies,null);//统计今天的签约患者分组
//        computequota_8(sql,signFamilies,null);//统计今天的签约患者年龄
//        computequota_9();//统计今天的待签约
//        computequota_10();//统计今天的改签
//        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
//        computequota_17(sql,signFamilies,null);//统计今天的年龄疾病
//        computequota_20();//统计今天的已经签约患者绑定设备
//        computequota_21();//统计今天的已经签约微信关注人数
//        computequota_22();//未回复的咨询量
//        computequota_23();//及时回复的咨询量
//        computequota_24();//及时回复的咨询量时间分布
//        computequota_25();//统计质询量总数
//        computequota_26();//统计未缴费签约总数
//        computequota_27();//统计代预约量
        computequota_28();//统计平均值
        quartzJobLog.setJobContent(allContent.toString());
        quartzJobLog.setJobName("实时统计");
@ -965,6 +967,120 @@ public class CurrentDayAllQuotaJob implements Job {
        allContent.append("-----------27----------");
    }
    /**
     * SQL统计平均值存储redis
     * 统计市,区,机构,团队医生满意度
     */
    private void  computequota_28(){
        //获取市,区统计结果
        List<Map<String,Object>> m1 = getCityTowms();
        JSONObject json1 = new JSONObject();
        json1.put("data",m1);
        redisTemplate.opsForValue().set("quota:28:4:"+Constant.city+":3:"+RedisStorage.timeKey,json1.toString());
        //获取市,机构统计结果
        List<Map<String,Object>> m2 = getCityHoss();
        JSONObject json2 = new JSONObject();
        json2.put("data",m2);
        redisTemplate.opsForValue().set("quota:28:4:"+Constant.city+":2:"+RedisStorage.timeKey,json2.toString());
        //统计区级低下所有机构
        if(m1!=null&&m1.size()>0){
            for(Map<String,Object> m:m1){
                String town =(String)m.get("code");
                List<Map<String,Object>> m3 = getTownHoss(town);
                JSONObject json3 = new JSONObject();
                json3.put("data",m3);
                redisTemplate.opsForValue().set("quota:28:3:"+town+":2:"+RedisStorage.timeKey,json3.toString());
            }
        }
        //得到所有机构
        List<Map<String,Object>> allHs = getAllHoss();
        //得到所有团队统计结果
        List<Map<String,Object>> allTs =getAllHosTeams();
        //将团队按机构分组,分别存储
        if(allHs!=null&&allHs.size()>0){
            for(Map<String,Object> h : allHs){
                String code = (String)h.get("code");
                List<Map<String,Object>> hosTeams = new ArrayList<>();
                Iterator<Map<String,Object>> it = allTs.iterator();
                while(it.hasNext()){
                    Map<String,Object> x = it.next();
                    String hospital = (String)x.get("hospital");
                    if(code.equals(hospital)){
                        hosTeams.add(x);
                        it.remove();
                    }
                }
                JSONObject json = new JSONObject();
                json.put("data",hosTeams);
                redisTemplate.opsForValue().set("quota:28:2:"+code+":1:"+RedisStorage.timeKey,json.toString());
            }
        }
    }
    public List<Map<String,Object>> getCityTowms(){
        List<Map<String,Object>> map = jdbcTemplate.queryForList(getAvgSqlByCode("city_town_SQL"));
        return map;
    }
    public List<Map<String,Object>> getCityHoss(){
        List<Map<String,Object>> map = jdbcTemplate.queryForList(getAvgSqlByCode("city_hos_SQL"));
        return map;
    }
    public List<Map<String,Object>> getTownHoss(String townCode){
        List<Map<String,Object>> map = jdbcTemplate.queryForList(getAvgSqlByCode("town_hos_SQL"),new Object[]{townCode});
        return map;
    }
    public List<Map<String,Object>> getAllHosTeams(){
        List<Map<String,Object>> map = jdbcTemplate.queryForList(getAvgSqlByCode("team_SQL"));
        return map;
    }
    public List<Map<String,Object>> getAllHoss(){
        List<Map<String,Object>> map = jdbcTemplate.queryForList(getAvgSqlByCode("All_hos_SQL"));
        return map;
    }
    public String getAvgSqlByCode(String code){
        if("city_town_SQL".equals(code)){
            //统计市级各区
            String city_town_SQL ="SELECT t.code,t.`name` ,ifnull(ROUND(AVG(s.score),1),0) as avgCount " +
                    " FROM wlyy_doctor d " +
                    " RIGHT JOIN dm_town t on t.code=d.town " +
                    " LEFT JOIN wlyy_evaluate_score s ON d.code = s.doctor " +
                    " WHERE t.city='"+Constant.city+"' GROUP BY d.town order by avgCount DESC ";
            return city_town_SQL;
        }else if("city_hos_SQL".equals(code)){
            //统计市级各社区
            String city_hos_SQL ="SELECT  t.code,t.`name`,ifnull(ROUND(AVG(s.score),1),0) as avgCount " +
                    " FROM wlyy_doctor d " +
                    " RIGHT JOIN dm_hospital t on t.code = d.hospital " +
                    " LEFT JOIN wlyy_evaluate_score s ON d.code = s.doctor " +
                    " WHERE t.city='"+Constant.city+"' GROUP BY d.hospital order by avgCount DESC ";
            return city_hos_SQL;
        }else if("town_hos_SQL".equals(code)){
            //统计区级各社区
            String town_hos_SQL ="SELECT  t.code,t.`name`,ifnull(ROUND(AVG(s.score),1),0) as avgCount " +
                    " FROM wlyy_doctor d " +
                    " RIGHT JOIN dm_hospital t on t.code = d.hospital " +
                    " LEFT JOIN wlyy_evaluate_score s ON d.code = s.doctor " +
                    " WHERE t.town= ? GROUP BY d.hospital order by avgCount DESC ";
            return town_hos_SQL;
        }else if("team_SQL".equals(code)){
            //查找所有团队
            String team_SQL ="SELECT  t.id,t.`name` ,d.hospital,ifnull(ROUND(AVG(s.score),1),0) as avgCount " +
                    " FROM wlyy_doctor d " +
                    " RIGHT JOIN wlyy_admin_team t on t.leader_code = d.code " +
                    " LEFT JOIN wlyy_evaluate_score s ON d.code = s.doctor " +
                    " GROUP BY t.id order by avgCount DESC ";
            return team_SQL;
        }else if("All_hos_SQL".equals(code)){
            //查找所有机构
            String All_hos_SQL = "SELECT t.code FROM dm_hospital t where t.city ='"+Constant.city+"'";
            return All_hos_SQL;
        }
    return "";
    }
    public static String getDayString(Integer size) {
        Date date = new Date();//取时间

+ 10 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/label/SignPatientLabelInfoService.java

@ -9,6 +9,7 @@ import com.yihu.wlyy.entity.doctor.team.sign.SignPatientLabelInfo;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.PatientDisease;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.entity.patient.SignFamilyRenew;
import com.yihu.wlyy.logs.BusinessLogs;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.doctor.DoctorPatientGroupInfoDao;
@ -17,6 +18,7 @@ import com.yihu.wlyy.repository.doctor.SignPatientLabelInfoDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.PatientDiseaseDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.repository.patient.SignFamilyRenewDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.app.team.AdminTeamService;
import com.yihu.wlyy.util.DateUtil;
@ -74,6 +76,8 @@ public class SignPatientLabelInfoService extends BaseService {
    AdminTeamService adminTeamService;
    @Autowired
    SignPatientLabelDao labelDao;
    @Autowired
    SignFamilyRenewDao signFamilyRenewDao;
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
@ -209,7 +213,12 @@ public class SignPatientLabelInfoService extends BaseService {
        }else{
            json.put("isRemainRenew","0");
        }
        String sql = "SELECT t.czrq FROM wlyy_sign_family_renew t WHERE t.status>=0 AND t.is_valid =0";
        List<Map<String,Object>> renews =  jdbcTemplate.queryForList(sql);
        if(renews!=null&&renews.size()>0){
            Map<String,Object> renew = renews.get(0);
            json.put("renewTime",renew.get("czrq"));
        }
        return json;
    }

+ 36 - 8
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/SignWebService.java

@ -404,7 +404,7 @@ public class SignWebService extends BaseService {
            jsonObject.put("applyDate",renew.getApplyDate());
            jsonObject.put("createTime",renew.getCzrq());
            jsonObject.put("type",renew.getType());
            jsonObject.put("typeName",renew.getType()==1?"三师签约":"家庭签约");
            jsonObject.put("typeName",renew.getType()==1?"三师签约":"家庭签约续签");
            String statusName = "";
            switch (jsonObject.getInt("status")){
                case -4 : statusName = "已到期";break;
@ -748,8 +748,9 @@ public class SignWebService extends BaseService {
                "    ,b.street_name as streetName" +
                "    ,b.sex" +
                "    ,b.openid" +
                "    ,a.czrq" +
                " from " +
                " ( select code,patient,doctor,status,id,apply_date,patient_apply_date,expenses_time,reason,begin from wlyy_sign_family_renew where (doctor = ? or doctor_health = ?) and status = ? and type = 2" +
                " ( select czrq,code,patient,doctor,status,id,apply_date,patient_apply_date,expenses_time,reason,begin from wlyy_sign_family_renew where (doctor = ? or doctor_health = ?) and status = ? and type = 2" +
                " order by begin desc ) a " +
                " ,wlyy_patient b " +
                " where a.patient = b.code  order by a.begin desc limit " + page * pageSize + "," + pageSize;
@ -773,10 +774,37 @@ public class SignWebService extends BaseService {
                "    ,b.street_name as streetName" +
                "    ,b.sex" +
                "    ,b.openid" +
                "    ,a.czrq" +
                " from " +
                " ( select code,patient,doctor,status,id,apply_date,reason,begin,expenses_status,LENGTH(trim(ifnull(expenses_status,''))) len from wlyy_sign_family_renew where (doctor = ? or doctor_health = ?) and status > ? and type = 2 order by begin desc ) a " +
                " ( select czrq,code,patient,doctor,status,id,apply_date,reason,begin,expenses_status,LENGTH(trim(ifnull(expenses_status,''))) len from wlyy_sign_family_renew where (doctor = ? or doctor_health = ?) and status > ? and type = 2 order by begin desc ) a " +
                " ,wlyy_patient b " +
                " where a.patient = b.code and (a.expenses_status = '0' or a.len < 1) order by a.begin desc limit " + page * pageSize + "," + pageSize;
                " where a.patient = b.code and a.expenses_status = '0' order by a.begin desc limit " + page * pageSize + "," + pageSize;
        // 已签约
        String signedSql = "select " +
                "    a.code " +
                "    ,a.doctor " +
                "    ,b.code  as  patient" +
                "    ,b.idcard " +
                "    ,b.name " +
                "    ,b.province_name  as provinceName" +
                "    ,b.city_name  as cityName" +
                "    ,b.town_name  as townName" +
                "    ,b.address " +
                "    ,b.photo " +
                "    ,a.status " +
                "    ,a.id " +
                (status == 1 ? "    ,a.patient_apply_date as applyDate " : "    ,a.expenses_time as applyDate ") +
                "    ,a.reason " +
                "    ,b.street_name as streetName" +
                "    ,b.sex" +
                "    ,b.openid" +
                "    ,a.czrq" +
                " from " +
                " ( select expenses_status,czrq,code,patient,doctor,status,id,apply_date,patient_apply_date,expenses_time,reason,begin from wlyy_sign_family_renew where (doctor = ? or doctor_health = ?) and status = ? and type = 2" +
                " order by begin desc ) a " +
                " ,wlyy_patient b " +
                " where a.patient = b.code and a.expenses_status = '1' order by a.begin desc limit " + page * pageSize + "," + pageSize;
        //1:待签约 2, 待缴费 3 已签约
@ -787,10 +815,10 @@ public class SignWebService extends BaseService {
                patients = jdbcTemplate.queryForList(sql, new Object[]{doctor, doctor, 0});
                break;
            case 2:// 待缴费
                patients = jdbcTemplate.queryForList(sqlExpenses, new Object[]{doctor, doctor, 1});
                patients = jdbcTemplate.queryForList(sqlExpenses, new Object[]{doctor, doctor, 0});
                break;
            case 3:// 已签约
                patients = jdbcTemplate.queryForList(sql, new Object[]{doctor, doctor, 1});
                patients = jdbcTemplate.queryForList(signedSql, new Object[]{doctor, doctor, 1});
                break;
        }
@ -934,9 +962,9 @@ public class SignWebService extends BaseService {
     * 获取年度列表
     * @return
     */
    public JSONObject getRenewYearCount(String doctorCode){
    public JSONObject getRenewYearCount(Long teamCode){
        StringBuffer sql = new StringBuffer("SELECT t.sign_year labelCode,COUNT(1) amount " +
                "FROM  wlyy_sign_family t WHERE t.doctor ='"+doctorCode+"' AND t.end <=NOW() AND t.status=-4 AND sign_year IS NOT NULL GROUP BY t.sign_year DESC");
                "FROM  wlyy_sign_family t WHERE t.admin_team_code ='"+teamCode+"' AND t.end <=NOW() AND t.status=-4 AND sign_year IS NOT NULL GROUP BY t.sign_year DESC");
        List<Map<String,Object>> rs = jdbcTemplate.queryForList(sql.toString());
        JSONObject json = new JSONObject();
        json.put("result",rs);

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

@ -2518,4 +2518,5 @@ public class StatisticsAllService extends BaseService {
        return 0L;
    }
}

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

@ -17,6 +17,7 @@ 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.jdbc.support.nativejdbc.OracleJdbc4NativeJdbcExtractor;
import org.springframework.stereotype.Service;
import org.apache.commons.lang3.StringUtils;
@ -1597,4 +1598,111 @@ public class StatisticsService extends BaseService {
        }
        return result;
    }
    public JSONObject getAVGSocre(String level,String area){
        String sql = "SELECT ROUND(AVG(s.score),1) avgCount FROM wlyy_evaluate_score s ,wlyy_doctor d WHERE s.doctor = d.code ";
        //市级
        if("4".equals(level)){
            sql +=" AND d.city = ? ";
        //区级
        }else if("3".equals(level)){
            sql +=" AND d.town = ? ";
        //机构
        }else if("2".equals(level)){
            sql +=" AND d.hospital = ? ";
        }
        Map<String,Object> rs = jdbcTemplate.queryForMap(sql,new Object[]{area});
        JSONObject json = new JSONObject();
        json.put("rs",rs);
        return json;
    }
    public JSONObject getAVGSocreByMonth(String level ,String area,String statDate,String endDate)throws  Exception{
        List<String> times =  getMonthBetween(statDate,endDate);
        if(times==null||times.size()==0){
            throw new Exception("时间区间错误");
        }
        String sql = "SELECT DATE_FORMAT(t.czrq,'%Y-%m') mt,ifnull(ROUND(AVG(s.score),1),0)  as avgCount " +
                " FROM  wlyy_consult_team t " +
                "  LEFT JOIN wlyy_doctor d ON d.code = t.doctor" +
                "  LEFT JOIN wlyy_evaluate_score s ON s.doctor = t.doctor" +
                " WHERE t.czrq >=? AND t.czrq <=?";
        //市级
        if("4".equals(level)){
            sql +=" AND d.city = ? ";
            //区级
        }else if("3".equals(level)){
            sql +=" AND d.town = ? ";
            //机构
        }else if("2".equals(level)){
            sql +=" AND d.hospital = ? ";
        }
        sql +=" GROUP BY mt order by mt DESC ";
        List<Map<String,Object>> rs = jdbcTemplate.queryForList(sql,new Object[]{statDate,endDate,area});
        Map<String,Object> map = new HashMap<>();
        if(rs!=null&&rs.size()>0){
            //降低循环层级
            for(Map<String,Object> m : rs){
                map.put((String)m.get("mt"),m);
            }
        }
        Map<String,Object> rsMap = new HashMap<>();
        for(String time : times){
            rsMap.put(time,map.get(time)==null?0:((Map<String,Object>)map.get(time)).get("avgCount"));
        }
        JSONObject data = new JSONObject();
        data.put("data",rsMap);
        return data;
    }
    private  List<String> getMonthBetween(String minDate, String maxDate) throws Exception {
        ArrayList<String> result = new ArrayList<String>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");//格式化为年月
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");//格式化为年月
        Calendar min = Calendar.getInstance();
        Calendar max = Calendar.getInstance();
        min.setTime(sdf2.parse(minDate));
        min.set(min.get(Calendar.YEAR), min.get(Calendar.MONTH), 1);
        max.setTime(sdf2.parse(maxDate));
        max.set(max.get(Calendar.YEAR), max.get(Calendar.MONTH), 2);
        Calendar curr = min;
        while (curr.before(max)) {
            result.add(sdf.format(curr.getTime()));
            curr.add(Calendar.MONTH, 1);
        }
        return result;
    }
    public String getAvgAllInfo(int level ,String area,String lowLevel){
        String timeKey = redisTemplate.opsForValue().get("quota:timeKey");
        String rs = "";
        //市级
        if(level==4){
            if(StringUtils.isNotBlank(lowLevel)){
                rs = redisTemplate.opsForValue().get("quota:28:"+level+":"+area+":3:"+timeKey);
            }else{
                rs = redisTemplate.opsForValue().get("quota:28:"+level+":"+area+":2:"+timeKey);
            }
        } else if(level ==3){
            rs = redisTemplate.opsForValue().get("quota:28:"+level+":"+area+":2:"+timeKey);
        }else if(level ==2){
            rs = redisTemplate.opsForValue().get("quota:28:"+level+":"+area+":1:"+timeKey);
        }
        return rs;
    }
}

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

@ -38,6 +38,7 @@ import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * 患者基本信息类.
@ -390,12 +391,13 @@ public class PatientService extends TokenService {
        //判断时间是否在6月30之前
        if (month < 7) {
            //判断是否有签约记录
            List<SignFamily> signFamilys1 = jdbcTemplate.queryForList(sql, SignFamily.class);
            List<Map<String,Object>> signFamilys1 = jdbcTemplate.queryForList(sql);
            if (signFamilys1 != null && signFamilys1.size() > 0) {
                //如果有记录则判断其年份是否为当前年份,如果为当前年份,不允许续签
                SignFamily sign = signFamilys1.get(0);
                if (StringUtils.isNotBlank(sign.getSignYear())) {
                    int y = Integer.parseInt(sign.getSignYear());
                Map<String,Object> sign = signFamilys1.get(0);
                if (StringUtils.isNotBlank((String)sign.get("signYear"))){
                    int y = Integer.parseInt((String)sign.get("signYear"));
                    if (y == year) {
                        rs.put("mes", "当前年度已经签约");
                        rs.put("code", "-2");
@ -444,7 +446,7 @@ public class PatientService extends TokenService {
            rs.put("code", "-3");
            return rs;
        } else {
            rs.put("mes", ",可以续签(未到期)");
            rs.put("mes", "可以续签(未到期)");
            rs.put("code", "1");
            return rs;
        }

+ 1 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/patient/SignPatientLabelInfoController.java

@ -246,7 +246,7 @@ public class SignPatientLabelInfoController extends BaseController {
            //计算年度数目
            if(labelType.equals("9")){
                JSONObject r= signWebService.getRenewYearCount(getUID());
                JSONObject r= signWebService.getRenewYearCount(teamCode);
                return write(200, "查询成功", "data", r);
            }

+ 12 - 11
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/sign/DoctorSignController.java

@ -382,6 +382,7 @@ public class DoctorSignController extends WeixinBaseController {
                    json.put("photo", temp.get("photo"));
                    json.put("status", temp.get("status"));
                    json.put("openid", temp.get("openid"));
                    json.put("renewTime", temp.get("czrq"));
                    String statusName = "";
                    switch (Integer.parseInt(temp.get("status").toString())) {
                        case 0:
@ -484,17 +485,17 @@ public class DoctorSignController extends WeixinBaseController {
     * 获取去医生下年度分组列表
     * @return
     */
    @RequestMapping("/getRenewYearCount")
    @ApiOperation(value = "获取年度分组")
    public String getRenewYearCount(){
        try{
            JSONObject rs =signWebService.getRenewYearCount(getUID());
            //JSONObject rs =signWebService.getRenewYearCount("64de930c-5b15-11e6-8344-fa163e8aee56");
            return write(200, "操作成功!", "data", rs);
        }catch (Exception e){
            return error(-1, "请求失败");
        }
    }
//    @RequestMapping("/getRenewYearCount")
//    @ApiOperation(value = "获取年度分组")
//    public String getRenewYearCount(){
//        try{
//            JSONObject rs =signWebService.getRenewYearCount(getUID());
//            //JSONObject rs =signWebService.getRenewYearCount("64de930c-5b15-11e6-8344-fa163e8aee56");
//            return write(200, "操作成功!", "data", rs);
//        }catch (Exception e){
//            return error(-1, "请求失败");
//        }
//    }
    /**
     *

+ 40 - 2
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/statistic/StatisticsController.java

@ -440,7 +440,8 @@ public class StatisticsController extends BaseController {
                                            @RequestParam(required = true) String index,
                                            @RequestParam(required = true) int sort,
                                            @RequestParam(required = false) String lowLevel,
                                            @RequestParam(required = false) String lowCode) {
                                            @RequestParam(required = false) String lowCode,
                                            @RequestParam(required = false) String startDate) {
        try {
            String[] indexes = index.split(",");
            JSONObject result = new JSONObject();
@ -455,7 +456,9 @@ public class StatisticsController extends BaseController {
                        result.put("index_" + idx, statisticsAllService.getLowLevelTotalSpecial(date, area, level, idx, sort, lowLevel));
                    } else if (idx.equals("1") || index.equals("21")) {
                        result.put("index_" + idx, statisticsAllService.getLowLevelTotal2(date, area, level, idx, sort, lowLevel));
                    } else {
                    } else if (idx.equals("28")){
                        result.put("index_" + idx, statisticsService.getAvgAllInfo(level,area,lowLevel));
                    } else{
                        result.put("index_" + idx, statisticsAllService.getLowLevelTotal(date, area, level, idx, sort, lowLevel));
                    }
                }
@ -663,4 +666,39 @@ public class StatisticsController extends BaseController {
            return error(-1, "查询失败");
        }
    }
    /**
     * 获取得分平均数
     * @param level
     * @param area
     * @return
     */
    @RequestMapping("/getAVGSocre")
    @ResponseBody
    public String getAVGSocre(@RequestParam(required = true) String level, @RequestParam(required = true) String area) {
        try {
            return write(200, "查询成功", "data", statisticsService.getAVGSocre(level,area));
        } catch (Exception e) {
            return error(-1, "查询失败");
        }
    }
    /**
     * 获取得分平均数按月份
     * @return
     */
    @RequestMapping("/getAVGSocreByMonth")
    @ResponseBody
    public String getAVGSocreByMonth(@RequestParam(required = true)String level ,
                                     @RequestParam(required = true)String area,
                                     @RequestParam(required = true)String statDate,
                                     @RequestParam(required = true)String endDate){
        try {
            return write(200, "查询成功", "data", statisticsService.getAVGSocreByMonth(level,area,statDate,endDate));
        } catch (Exception e) {
            return error(-1, "查询失败");
        }
    }
}