فهرست منبع

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

chenweida 7 سال پیش
والد
کامیت
29d53bd9c0

+ 70 - 4
patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/controller/QueryController.java

@ -6,6 +6,7 @@ import com.alibaba.druid.sql.parser.ParserException;
import com.alibaba.druid.sql.parser.SQLExprParser;
import com.alibaba.druid.sql.parser.Token;
import com.google.gson.JsonObject;
import com.yihu.wlyy.statistics.etl.cache.Cache;
import com.yihu.wlyy.statistics.etl.save.es.ElasticFactory;
import com.yihu.wlyy.statistics.util.DateUtil;
import com.yihu.wlyy.statistics.util.ElasticsearchUtil;
@ -38,10 +39,9 @@ import org.nlpcn.es4sql.query.AggregationQueryAction;
import org.nlpcn.es4sql.query.DefaultQueryAction;
import org.nlpcn.es4sql.query.SqlElasticSearchRequestBuilder;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * Created by chenweida on 2017/7/1.
@ -176,6 +176,72 @@ public class QueryController {
        return deleteData(DateUtil.strToDate(date, "yyyy-MM-dd"), null).toString();
    }
    @ApiOperation(value = "删除某一天到某一天的数据")
    @RequestMapping(value = "/deleteQuotaDateToDate", method = RequestMethod.DELETE)
    public String deleteQuotaDateToDate(
            @ApiParam(name = "start", value = "时间(yyyy-MM-dd)", required = true) @RequestParam(value = "start", required = true) String start,
            @ApiParam(name = "end", value = "时间(yyyy-MM-dd)", required = true) @RequestParam(value = "end", required = true) String end) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date startDate = sdf.parse(start);
            Date endDate = endDate = sdf.parse(end);
            int day = daysBetween(startDate, endDate);
            for (int i = 0; i < day; i++) {
                Cache.cleanCache();//清空缓存
                deleteData(DateUtil.strToDate(getYesterday(i, startDate), "yyyy-MM-dd"), null).toString();
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "删除成功";
    }
    @ApiOperation(value = "删除某一天到某一天的数据")
    @RequestMapping(value = "/deleteQuotaDateToDateWithId", method = RequestMethod.DELETE)
    public String deleteQuotaDateToDateWithId(
            @ApiParam(name = "id", value = "指标id", required = true) @RequestParam(value = "id", required = true) String id,
            @ApiParam(name = "start", value = "时间(yyyy-MM-dd)", required = true) @RequestParam(value = "start", required = true) String start,
            @ApiParam(name = "end", value = "时间(yyyy-MM-dd)", required = true) @RequestParam(value = "end", required = true) String end) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date startDate = sdf.parse(start);
            Date endDate = endDate = sdf.parse(end);
            int day = daysBetween(startDate, endDate);
            for (int i = 0; i < day; i++) {
                Cache.cleanCache();//清空缓存
                deleteData(DateUtil.strToDate(getYesterday(i, startDate), "yyyy-MM-dd"), id).toString();
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "删除成功";
    }
    public static String getYesterday(Integer day, Date startDate) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(startDate);
        cal.add(Calendar.DAY_OF_MONTH, day);
        String yesterday = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
        return yesterday;
    }
    public static int daysBetween(Date smdate, Date bdate) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        smdate = sdf.parse(sdf.format(smdate));
        bdate = sdf.parse(sdf.format(bdate));
        Calendar cal = Calendar.getInstance();
        cal.setTime(smdate);
        long time1 = cal.getTimeInMillis();
        cal.setTime(bdate);
        long time2 = cal.getTimeInMillis();
        long between_days = (time2 - time1) / (1000 * 3600 * 24);
        return Integer.parseInt(String.valueOf(between_days));
    }
    /**
     * 删除 某个指标某一天的某个timelevel的数据
     *

+ 17 - 16
patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/etl/convert/wlyy/PrescriptionStatusConvert.java

@ -19,36 +19,37 @@ import java.util.Map;
 * Created by zhangdan on 2017/10/26.
 */
public class PrescriptionStatusConvert implements Convert {
    public List<DataModel> convert(JdbcTemplate jdbcTemplate, List<DataModel> oneList, String slaveLevel, WlyyDimensionQuota temp ) {
        for(DataModel one:oneList){
    public List<DataModel> convert(JdbcTemplate jdbcTemplate, List<DataModel> oneList, String slaveLevel, WlyyDimensionQuota temp) {
        for (DataModel one : oneList) {
            try {
//                Object value = DataModel.class.getMethod("get" + temp.getKey()).invoke(one);
                //获取到prescriptionCode,求长处方状态
                String sql ="SELECT status FROM wlyy_prescription WHERE code=?";
                String sql = "SELECT status FROM wlyy_prescription WHERE code=?";
                //int status = jdbcTemplate.queryForObject(sql, Integer.class);
                Object[] args = {one.getPrescriptionCode()};
                int status=jdbcTemplate.queryForObject(sql,args,Integer.class);
                int status = jdbcTemplate.queryForObject(sql, args, Integer.class);
                String key = getStatusCode(status);
                DataModel.class.getMethod("setSlaveKey" + slaveLevel, String.class).invoke(one, key);
            } catch (Exception e) {
                e.printStackTrace();
            }
        };
        }
        ;
        return oneList;
    }
    public String getStatusCode(Integer status) {
        if (status >= 0 && status < 100) {
            return Contant.prescriptionStatus.status_1;
        } else if (status==100) {
            return Contant.prescriptionStatus.status_2;
        } else if (status==-2) {
            return Contant.prescriptionStatus.status_3;
        } else if (status==-1) {
            return Contant.prescriptionStatus.status_4;
        } else if (status==-3||status==-4||status==-5) {
            return Contant.prescriptionStatus.status_5;
        } else{
        if (status == 100) {
            return Contant.prescriptionStatus.status_1; //已完成
        } else if (status == -2) {
            return Contant.prescriptionStatus.status_2; //已取消
        } else if (status == -1) {
            return Contant.prescriptionStatus.status_3;//审核不通过
        } else if (status >= 0 && status < 100) {
            return Contant.prescriptionStatus.status_4; //进行中
        } else if (status == -3 || status == -4 || status == -5) {
            return Contant.prescriptionStatus.status_5;//其他原因取消
        } else {
            return "0";
        }
    }

+ 7 - 10
patient-co/patient-co-statistics-es/src/main/java/com/yihu/wlyy/statistics/util/Contant.java

@ -141,11 +141,13 @@ public class Contant {
    }
    public static class prescriptionStatus{
        public static String status_1="1";
        public static String status_2="2";
        public static String status_3="3";
        public static String status_4="4";
        public static String status_5="5";
        public static String status_1="1";//已完成
        public static String status_2="2";//已取消
        public static String status_3="3";//审核不通过
        public static String status_4="4";//进行中
        public static String status_5="5";//其他原因取消
//        public static String status_6="6";
//        public static String status_7="7";
//        public static String status_8="8";
@ -170,11 +172,6 @@ public class Contant {
//        public static String status_12_name="已完成";
//        public static String status_13_name="进行中";
        public static String status_1_name="进行中";//大于0小于100
        public static String status_2_name="已完成";//100
        public static String status_3_name="已取消";//患者取消,-2
        public static String status_4_name="审核不通过";//-1;
        public static String status_5_name="其他原因取消";//支付超时,-3;
    }
}

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

@ -27,7 +27,7 @@ spring:
    poolPreparedStatements: true # 打开PSCache,并且指定每个连接上PSCache的大小
    maxPoolPreparedStatementPerConnectionSize: 50
    removeAbandoned: true #超过时间限制是否回收
    removeAbandonedTimeout: 180 #超时时间;单位为秒。180秒=3分钟
    removeAbandonedTimeout: 7200 #超时时间;单位为秒。180秒=3分钟
    logAbandoned: false #关闭abanded连接时输出错误日志
    # REDIS
  redis:

+ 127 - 89
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statisticsES/StatisticsESService.java

@ -521,7 +521,11 @@ public class StatisticsESService {
    public long getWeiJiaoFei(String endDate, String area, int level) throws Exception {
        SaveModel saveModel = elasticsearchUtil.findOneDateQuotaLevel1(endDate, area, level, "16", "2", "0");
        return saveModel.getResult2().longValue();
        if (saveModel != null) {
            return saveModel.getResult2().longValue();
        } else {
            return 0;
        }
    }
@ -1330,11 +1334,12 @@ public class StatisticsESService {
        }
        return rs;
    }
    public List translateTeamLeaderNameListMap(List<Map<String,Object>> rs) {
    public List translateTeamLeaderNameListMap(List<Map<String, Object>> rs) {
        Map<Integer, Map<String, Object>> leaders = getAllTeamLeaders();
        if (rs != null) {
            for (int i = 0; i < rs.size(); i++) {
                Map<String,Object> r = rs.get(i);
                Map<String, Object> r = rs.get(i);
                Integer id = Integer.valueOf(r.get("code").toString());
                String name = getTeamLeaderNameByTeamCode(leaders, id);
                if (org.apache.commons.lang3.StringUtils.isNotBlank(name)) {
@ -1344,6 +1349,7 @@ public class StatisticsESService {
        }
        return rs;
    }
    public JSONArray translateTeamLeaderNameByCode(JSONArray rs) {
        Map<Integer, Map<String, Object>> leaders = getAllTeamLeaders();
        if (rs != null) {
@ -2420,7 +2426,7 @@ public class StatisticsESService {
     * @return
     */
    private JSONArray getLevel2JsonObjectForRedis(String index, String level, String code, String timeKey) throws Exception {
        List<SaveModel> list = elasticsearchUtil.findDateAllQuotaLevel1(timeKey, timeKey,code, Integer.parseInt(level), index, SaveModel.timeLevel_DDL,"","");
        List<SaveModel> list = elasticsearchUtil.findDateAllQuotaLevel1(timeKey, timeKey, code, Integer.parseInt(level), index, SaveModel.timeLevel_DDL, "", "");
//        JSONObject jo = new JSONObject();
        JSONArray switchJo = new JSONArray();
        list.stream().forEach(one -> {
@ -2736,7 +2742,7 @@ public class StatisticsESService {
//        Map<String, Object> map = jdbcTemplate.queryForMap(sql, startDate, endDate,admin.getId());
        SaveModel saveModel21 = elasticsearchUtil.findOneDateQuotaLevel0(startDate, endDate, admin.getId() + "", Integer.parseInt(SaveModel.teamLevel), "3", SaveModel.timeLevel_ZL);
        Double avgCout = 0.0;
        if (saveModel21.getResult2().intValue()!=0){
        if (saveModel21.getResult2().intValue() != 0) {
            avgCout = saveModel2.getResult1() / saveModel21.getResult2();
        }
        Map<String, Object> avgScore = new HashMap<>();
@ -2791,7 +2797,7 @@ public class StatisticsESService {
            throw new RuntimeException("未找到团队信息");
        }
        Long id = admin.getId();
        List<SaveModel> list = elasticsearchUtil.findLineChartDateQuotaLevel0(startDate,endDate,id+"",Integer.valueOf(SaveModel.teamLevel),"1",SaveModel.timeLevel_ZL,String.valueOf(Integer.valueOf(type)+1));
        List<SaveModel> list = elasticsearchUtil.findLineChartDateQuotaLevel0(startDate, endDate, id + "", Integer.valueOf(SaveModel.teamLevel), "1", SaveModel.timeLevel_ZL, String.valueOf(Integer.valueOf(type) + 1));
        List<Map<String, Object>> rs = new ArrayList<>();
        for (SaveModel saveModel : list) {
@ -2889,12 +2895,12 @@ public class StatisticsESService {
            String quotaDate = dateFormat.format(one.getQuotaDate());
            saveModel = elasticsearchUtil.findOneDateQuotaLevel0(quotaDate, id + "", Integer.parseInt(SaveModel.teamLevel), "59", SaveModel.timeLevel_ZL);
            //如果曾量为0,则说明没有数据。直接返回
            if(one.getResult2()!=0 && saveModel.getResult2().intValue()!=0){
            if (one.getResult2() != 0 && saveModel.getResult2().intValue() != 0) {
                avgCount = one.getResult2() / saveModel.getResult2();
            }else if (one.getResult2()!=0 && saveModel.getResult2().intValue()==0){
            } else if (one.getResult2() != 0 && saveModel.getResult2().intValue() == 0) {
                avgCount = 80.0;
            }else if (one.getResult2()==0){
                avgCount=0.0;
            } else if (one.getResult2() == 0) {
                avgCount = 0.0;
            }
            map = new HashMap<>();
            if ("0".equals(type)) {
@ -3029,7 +3035,7 @@ public class StatisticsESService {
        String index = "64";
        Map<String, Object> rs = new HashedMap();
        //总数
        SaveModel total = elasticsearchUtil.findOneDateQuotaLevel1NoSlaveKey1(startDate,endDate, String.valueOf(adminTeamId), Integer.valueOf(SaveModel.teamLevel), index, SaveModel.timeLevel_ZL);
        SaveModel total = elasticsearchUtil.findOneDateQuotaLevel1NoSlaveKey1(startDate, endDate, String.valueOf(adminTeamId), Integer.valueOf(SaveModel.teamLevel), index, SaveModel.timeLevel_ZL);
        //进行中
        SaveModel processing = elasticsearchUtil.findOneDateQuotaLevel1(startDate, endDate, String.valueOf(adminTeamId), Integer.valueOf(SaveModel.teamLevel), index, SaveModel.timeLevel_ZL, "1");
        //已完成
@ -3101,27 +3107,27 @@ public class StatisticsESService {
        }
        //进行中
        if (StringUtils.isNotBlank(disease)) {
            processing = elasticsearchUtil.findOneDateQuotaLevel2(quotaDate, area, level, index58, SaveModel.timeLevel_DDL, disease, "1").get(0);
            processing = elasticsearchUtil.findOneDateQuotaLevel2(quotaDate, area, level, index58, SaveModel.timeLevel_DDL, disease, "4").get(0);
        } else {
            processing = elasticsearchUtil.findOneDateQuotaLevel1(quotaDate, area, level, index64, SaveModel.timeLevel_DDL, "1");
            processing = elasticsearchUtil.findOneDateQuotaLevel1(quotaDate, area, level, index64, SaveModel.timeLevel_DDL, "4");
        }
        //已完成
        if (StringUtils.isNotBlank(disease)) {
            finished = elasticsearchUtil.findOneDateQuotaLevel2(quotaDate, area, level, index58, SaveModel.timeLevel_DDL, disease, "2").get(0);
            finished = elasticsearchUtil.findOneDateQuotaLevel2(quotaDate, area, level, index58, SaveModel.timeLevel_DDL, disease, "1").get(0);
        } else {
            finished = elasticsearchUtil.findOneDateQuotaLevel1(quotaDate, area, level, index64, SaveModel.timeLevel_DDL, "2");
            finished = elasticsearchUtil.findOneDateQuotaLevel1(quotaDate, area, level, index64, SaveModel.timeLevel_DDL, "1");
        }
        //已经取消
        if (StringUtils.isNotBlank(disease)) {
            canceled = elasticsearchUtil.findOneDateQuotaLevel2(quotaDate, area, level, index58, SaveModel.timeLevel_DDL, disease, "3").get(0);
            canceled = elasticsearchUtil.findOneDateQuotaLevel2(quotaDate, area, level, index58, SaveModel.timeLevel_DDL, disease, "2").get(0);
        } else {
            canceled = elasticsearchUtil.findOneDateQuotaLevel1(quotaDate, area, level, index64, SaveModel.timeLevel_DDL, "3");
            canceled = elasticsearchUtil.findOneDateQuotaLevel1(quotaDate, area, level, index64, SaveModel.timeLevel_DDL, "2");
        }
        //审核不通过
        if (StringUtils.isNotBlank(disease)) {
            unPass = elasticsearchUtil.findOneDateQuotaLevel2(quotaDate, area, level, index58, SaveModel.timeLevel_DDL, disease, "4").get(0);
            unPass = elasticsearchUtil.findOneDateQuotaLevel2(quotaDate, area, level, index58, SaveModel.timeLevel_DDL, disease, "3").get(0);
        } else {
            unPass = elasticsearchUtil.findOneDateQuotaLevel1(quotaDate, area, level, index64, SaveModel.timeLevel_DDL, "4");
            unPass = elasticsearchUtil.findOneDateQuotaLevel1(quotaDate, area, level, index64, SaveModel.timeLevel_DDL, "3");
        }
        //其他原因取消
        if (StringUtils.isNotBlank(disease)) {
@ -3258,12 +3264,15 @@ public class StatisticsESService {
            for (SaveModel one : list) {
                map = new HashMap<>();
                if (SaveModel.townLevel.equals(lowlevel)) {
                    map = new HashMap<>();
                    map.put("code", one.getTown());
                    map.put("name", one.getTownName());
                } else if (SaveModel.OrgLevel.equals(lowlevel)) {
                    map = new HashMap<>();
                    map.put("code", one.getHospital());
                    map.put("name", one.getHospitalName());
                } else if (SaveModel.teamLevel.equals(lowlevel)) {
                    map = new HashMap<>();
                    map.put("code", one.getTeam());
                    map.put("name", one.getTeamName());
                }
@ -3281,13 +3290,13 @@ public class StatisticsESService {
                adminTeams = findAllTeam();
            } else if (SaveModel.townLevel.equals(level)) {
                hospitalList = hospitalDao.findByTownCode(area);
//                adminTeams = adminTeamDao.findByTownCode(area);
                adminTeams = findAllTeam();
            } else if (SaveModel.OrgLevel.equals(level)) {
                adminTeams = adminTeamDao.findByOrgCode(area);
            }
            if (SaveModel.townLevel.equals(lowlevel)) {
                for (Town one : townList) {
                    map = new HashMap<>();
                    map.put("code", one.getCode());
                    map.put("name", one.getName());
                    map.put("val", 0);
@ -3295,6 +3304,7 @@ public class StatisticsESService {
                }
            } else if (SaveModel.OrgLevel.equals(lowlevel)) {
                for (Hospital one : hospitalList) {
                    map = new HashMap<>();
                    map.put("code", one.getCode());
                    map.put("name", one.getName());
                    map.put("val", 0);
@ -3302,6 +3312,7 @@ public class StatisticsESService {
                }
            } else if (SaveModel.teamLevel.equals(lowlevel)) {
                for (AdminTeam one : adminTeams) {
                    map = new HashMap<>();
                    map.put("code", one.getLeaderCode());
                    map.put("name", one.getName());
                    map.put("val", 0);
@ -3309,6 +3320,11 @@ public class StatisticsESService {
                }
            }
        }
        if (SaveModel.teamLevel.equals(lowlevel)) {
            translateTeamLeaderName(rs);
        }
        Collections.sort(rs, new Comparator<Map<String, Object>>() {
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                Integer map1value = Integer.valueOf(String.valueOf(o1.get("val")));
@ -3356,25 +3372,25 @@ public class StatisticsESService {
        String index60 = "60";  //统计长处方总数年龄和疾病维度
        String index65 = "65";  //统计长处方总数年龄维度
        List<SaveModel> chufanglist =null;
        List<SaveModel> numList =null;
        Map<String,SaveModel> numListMap =new HashMap<>();
        List<SaveModel> chufanglist = null;
        List<SaveModel> numList = null;
        Map<String, SaveModel> numListMap = new HashMap<>();
        String quotaDate = elasticsearchUtil.getQuotaTime();
        //统计处方年龄分布
        if(org.springframework.util.StringUtils.isEmpty(disease)){
        if (org.springframework.util.StringUtils.isEmpty(disease)) {
            numList = elasticsearchUtil.findOneDateQuotaLevel1(quotaDate, area, Integer.parseInt(level), index68, SaveModel.timeLevel_DDL);
        }else{
            numList = elasticsearchUtil.findOneDateQuotaLevel2(quotaDate, area, Integer.parseInt(level), index63,  SaveModel.timeLevel_DDL,null,disease);
        } else {
            numList = elasticsearchUtil.findOneDateQuotaLevel2(quotaDate, area, Integer.parseInt(level), index63, SaveModel.timeLevel_DDL, null, disease);
        }
        //统计处方患者年龄分布
        if(org.springframework.util.StringUtils.isEmpty(disease)){
        if (org.springframework.util.StringUtils.isEmpty(disease)) {
            chufanglist = elasticsearchUtil.findOneDateQuotaLevel1(quotaDate, area, Integer.parseInt(level), index65, SaveModel.timeLevel_DDL);
        }else{
            chufanglist = elasticsearchUtil.findOneDateQuotaLevel2(quotaDate, area, Integer.parseInt(level), index60,  SaveModel.timeLevel_DDL,null,disease);
        } else {
            chufanglist = elasticsearchUtil.findOneDateQuotaLevel2(quotaDate, area, Integer.parseInt(level), index60, SaveModel.timeLevel_DDL, null, disease);
        }
        for(int i=0;i<numList.size();i++){
            SaveModel saveModel=numList.get(i);
            numListMap.put(saveModel.getSlaveKey1(),saveModel);
        for (int i = 0; i < numList.size(); i++) {
            SaveModel saveModel = numList.get(i);
            numListMap.put(saveModel.getSlaveKey1(), saveModel);
        }
        Map<String, Object> map = new HashMap<>();
        if (numList.size() == 0) {
@ -3385,41 +3401,41 @@ public class StatisticsESService {
            map.put("65ageRate", 0.0);
        } else {
            DecimalFormat decimalFormat = new DecimalFormat("0.00");//构造方法的字符格式这里如果小数不足2位,会以0补足.
            if(numListMap.get(chufanglist.get(0).getSlaveKey1()).getResult2()!=0.0D){
                Double ageRate = chufanglist.get(0).getResult2() /numListMap.get(chufanglist.get(0).getSlaveKey1()).getResult2() ;
            if (numListMap.get(chufanglist.get(0).getSlaveKey1()).getResult2() != 0.0D) {
                Double ageRate = chufanglist.get(0).getResult2() / numListMap.get(chufanglist.get(0).getSlaveKey1()).getResult2();
                map.put("0ageRate", decimalFormat.format(ageRate));
            }else{
                map.put("0ageRate",chufanglist.get(0).getResult2() );
            } else {
                map.put("0ageRate", chufanglist.get(0).getResult2());
            }
            if(numListMap.get(chufanglist.get(1).getSlaveKey1()).getResult2()!=0.0D){
                Double ageRate = chufanglist.get(1).getResult2() /numListMap.get(chufanglist.get(1).getSlaveKey1()).getResult2() ;
            if (numListMap.get(chufanglist.get(1).getSlaveKey1()).getResult2() != 0.0D) {
                Double ageRate = chufanglist.get(1).getResult2() / numListMap.get(chufanglist.get(1).getSlaveKey1()).getResult2();
                map.put("7ageRate", decimalFormat.format(ageRate));
            }else{
                map.put("7ageRate", chufanglist.get(1).getResult2() );
            } else {
                map.put("7ageRate", chufanglist.get(1).getResult2());
            }
            if(numListMap.get(chufanglist.get(2).getSlaveKey1()).getResult2()!=0.0D){
                Double ageRate = chufanglist.get(2).getResult2() /numListMap.get(chufanglist.get(2).getSlaveKey1()).getResult2() ;
            if (numListMap.get(chufanglist.get(2).getSlaveKey1()).getResult2() != 0.0D) {
                Double ageRate = chufanglist.get(2).getResult2() / numListMap.get(chufanglist.get(2).getSlaveKey1()).getResult2();
                map.put("19ageRate", decimalFormat.format(ageRate));
            }else{
                map.put("19ageRate", chufanglist.get(2).getResult2() );
            } else {
                map.put("19ageRate", chufanglist.get(2).getResult2());
            }
            if(numListMap.get(chufanglist.get(3).getSlaveKey1()).getResult2()!=0.0D){
                Double ageRate = chufanglist.get(3).getResult2() /numListMap.get(chufanglist.get(3).getSlaveKey1()).getResult2() ;
            if (numListMap.get(chufanglist.get(3).getSlaveKey1()).getResult2() != 0.0D) {
                Double ageRate = chufanglist.get(3).getResult2() / numListMap.get(chufanglist.get(3).getSlaveKey1()).getResult2();
                map.put("31ageRate", decimalFormat.format(ageRate));
            }else{
                map.put("31ageRate",chufanglist.get(3).getResult2() );
            } else {
                map.put("31ageRate", chufanglist.get(3).getResult2());
            }
            if(numListMap.get(chufanglist.get(4).getSlaveKey1()).getResult2()!=0.0D){
                Double ageRate = chufanglist.get(4).getResult2() /numListMap.get(chufanglist.get(4).getSlaveKey1()).getResult2() ;
            if (numListMap.get(chufanglist.get(4).getSlaveKey1()).getResult2() != 0.0D) {
                Double ageRate = chufanglist.get(4).getResult2() / numListMap.get(chufanglist.get(4).getSlaveKey1()).getResult2();
                map.put("51ageRate", decimalFormat.format(ageRate));
            }else{
                map.put("51ageRate",chufanglist.get(4).getResult2() );
            } else {
                map.put("51ageRate", chufanglist.get(4).getResult2());
            }
            if(numListMap.get(chufanglist.get(5).getSlaveKey1()).getResult2()!=0.0D){
                Double ageRate = chufanglist.get(5).getResult2() /numListMap.get(chufanglist.get(5).getSlaveKey1()).getResult2() ;
            if (numListMap.get(chufanglist.get(5).getSlaveKey1()).getResult2() != 0.0D) {
                Double ageRate = chufanglist.get(5).getResult2() / numListMap.get(chufanglist.get(5).getSlaveKey1()).getResult2();
                map.put("65ageRate", decimalFormat.format(ageRate));
            }else{
                map.put("65ageRate", chufanglist.get(5).getResult2() );
            } else {
                map.put("65ageRate", chufanglist.get(5).getResult2());
            }
        }
        return map;
@ -3429,10 +3445,11 @@ public class StatisticsESService {
     * @param level   等级
     * @param area    等级编码
     * @param disease 疾病编码
     * @param type    类型0.总量,1.进行中,2.已完成,3.居民取消,4.审核不通过,5.其他原因取消
     * @return
     */
    public List<Map<String, Object>> getPrescriptionTotalHistogram(int level, String area, String disease, String type) throws Exception {
        //转换type 前端type和ES生成的数据字典对不上
        type = changeType(type);
        //因为一个处方可能有多个疾病状态 所以分开2个指标
        String index58 = "58";//统计长处方总数疾病和状态维度
        String index64 = "64";//统计长处方总数状态维度
@ -3455,19 +3472,19 @@ public class StatisticsESService {
        String endTime = DateUtil.dateToStr(new Date(), "YYYY-MM-dd HH:mm:ss");
        List<SaveModel> resultList = new ArrayList<>();
        if (StringUtils.isNotBlank(disease)) {
            //类型0.总量,1.进行中,2.已完成,3.居民取消,4.审核不通过,5.其他原因取消
            if ("0".equals(type)) {
            //类型1.总量,2.已完成,3.居民取消,4.审核不通过,5.进行中,6.其他原因取消
            if ("1".equals(type)) {
                //总数
                resultList = elasticsearchUtil.findLineChartDateQuotaLevel2NoSlaveKey2(startTime, endTime, area, level, index58, "1", "3", disease);
                resultList = elasticsearchUtil.findLineChartDateQuotaLevel2NoSlaveKey2(startTime, endTime, area, level, index58, SaveModel.timeLevel_ZL, SaveModel.interval_month, disease);
            } else {
                resultList = elasticsearchUtil.findLineChartDateQuotaLevel2(startTime, endTime, area, level, index58, "1", "3", disease, type);
                resultList = elasticsearchUtil.findLineChartDateQuotaLevel2(startTime, endTime, area, level, index58, SaveModel.timeLevel_ZL,  SaveModel.interval_month, disease, String.valueOf(Integer.valueOf(type) - 1));
            }
        } else {
            if ("0".equals(type)) {
            if ("1".equals(type)) {
                //总数
                resultList = elasticsearchUtil.findLineChartDateQuotaLevel1NoSlaveKey1(startTime, endTime, area, level, index64, "1", "3");
                resultList = elasticsearchUtil.findLineChartDateQuotaLevel1NoSlaveKey1(startTime, endTime, area, level, index64, SaveModel.timeLevel_ZL,  SaveModel.interval_month);
            } else {
                resultList = elasticsearchUtil.findLineChartDateQuotaLevel1(startTime, endTime, area, level, index64, "1", "3", type);
                resultList = elasticsearchUtil.findLineChartDateQuotaLevel1(startTime, endTime, area, level, index64, SaveModel.timeLevel_ZL,  SaveModel.interval_month,String.valueOf(Integer.valueOf(type) - 1));
            }
        }
        //把数据设置到初始化的Map里面去
@ -3475,6 +3492,8 @@ public class StatisticsESService {
            String monthKeyEs = "";
            if (saveModel.getQuotaDate() != null) {
                monthKeyEs = DateUtil.changeQuotaDate(saveModel.getQuotaDate());
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
                monthKeyEs = sdf.format(saveModel.getQuotaDate());
            }
            if (StringUtils.isNotBlank(monthKeyEs) && rs.containsKey(monthKeyEs)) {
                Map<String, Object> oneMc = rs.get(monthKeyEs);
@ -3485,6 +3504,29 @@ public class StatisticsESService {
        return new ArrayList<>(rs.values());
    }
    /**
     * @param type 1.总量,2.进行中,3.已完成,4.居民取消,5.审核不通过,6.其他原因取消
     * @return  1.总量,2.已完成,3.居民取消,4.审核不通过,5.进行中,6.其他原因取消
     */
    private String changeType(String type) {
        if ("2".equals(type)) {
            return "5";
        }
        if ("3".equals(type)) {
            return "2";
        }
        if ("4".equals(type)) {
            return "3";
        }
        if ("5".equals(type)) {
            return "4";
        }
        if ("6".equals(type)) {
            return "6";
        }
        return type;
    }
    /**
     * @param level    等级 1 省 2 市 3 区县 4 机构 5团队
     * @param lowlevel 等级 1 省 2 市 3 区县 4 机构 5团队
@ -3495,6 +3537,8 @@ public class StatisticsESService {
     * @return
     */
    public List<Map<String, Object>> getPrescriptionTotalLowLevel(int level, String lowlevel, String area, String disease, String type) throws Exception {
        //转换type 前端type和ES生成的数据字典对不上
        type = changeType(type);
        String quotaDate = elasticsearchUtil.getQuotaTime();
        //因为一个处方可能有多个疾病状态 所以分开2个指标
        String index58 = "58";//统计长处方总数疾病和状态维度
@ -3507,22 +3551,15 @@ public class StatisticsESService {
            if ("1".equals(type)) {
                //总数
                saveModels = elasticsearchUtil.findListDateQuotaLevel1NoSlaveKey1(quotaDate, area, level, index64, SaveModel.timeLevel_DDL, lowlevel);
            } else if ("2".equals(type) || "3".equals(type) || "4".equals(type)) {
                saveModels = elasticsearchUtil.findListDateQuotaLevel1(quotaDate, area, level, index64, SaveModel.timeLevel_DDL, lowlevel, type);
            } else if ("5".equals(type)) {
                saveModels = elasticsearchUtil.findListDateQuotaLevel1(quotaDate, area, level, index64, SaveModel.timeLevel_DDL, lowlevel, "1");
            } else if ("6".equals(type)) {
                saveModels = elasticsearchUtil.findListDateQuotaLevel1(quotaDate, area, level, index64, SaveModel.timeLevel_DDL, lowlevel, "5");
            } else {
                saveModels = elasticsearchUtil.findListDateQuotaLevel1(quotaDate, area, level, index64, SaveModel.timeLevel_DDL, lowlevel, String.valueOf(Integer.valueOf(type) - 1));
            }
        } else {
            if ("1".equals(type)) {
                saveModels = elasticsearchUtil.findListDateQuotaLevel2NoSlaveKey2(quotaDate, area, level, index58, SaveModel.timeLevel_DDL, lowlevel, disease);
            } else if ("2".equals(type) || "3".equals(type) || "4".equals(type)) {
                saveModels = elasticsearchUtil.findListDateQuotaLevel2(quotaDate, area, level, index58, SaveModel.timeLevel_DDL, lowlevel, disease, type);
            } else if ("5".equals(type)) {
                saveModels = elasticsearchUtil.findListDateQuotaLevel2(quotaDate, area, level, index58, SaveModel.timeLevel_DDL, lowlevel, disease, "1");
            } else if ("6".equals(type)) {
                saveModels = elasticsearchUtil.findListDateQuotaLevel2(quotaDate, area, level, index58, SaveModel.timeLevel_DDL, lowlevel, disease, "5");
            }
            {
                saveModels = elasticsearchUtil.findListDateQuotaLevel2(quotaDate, area, level, index58, SaveModel.timeLevel_DDL, lowlevel, disease, String.valueOf(Integer.valueOf(type) - 1));
            }
        }
        if ("5".equals(lowlevel)) {
@ -3752,7 +3789,7 @@ public class StatisticsESService {
        List<SaveModel> resultList = new ArrayList<>();
        if (StringUtils.isNotBlank(disease)) {
            resultList = elasticsearchUtil.findLineChartDateQuotaLevel2(startTime, endTime, area, level, index62, SaveModel.timeLevel_ZL, SaveModel.interval_month, type,disease);
            resultList = elasticsearchUtil.findLineChartDateQuotaLevel2(startTime, endTime, area, level, index62, SaveModel.timeLevel_ZL, SaveModel.interval_month, type, disease);
        } else {
            resultList = elasticsearchUtil.findLineChartDateQuotaLevel1(startTime, endTime, area, level, index67, SaveModel.timeLevel_ZL, SaveModel.interval_month, type);
        }
@ -3805,7 +3842,7 @@ public class StatisticsESService {
        List<Map<String, Object>> rs = new ArrayList<>();
        if (StringUtils.isNotBlank(disease)) {
            //类型 1.自取,2.快递配送,3.健管师配送
            saveModels = elasticsearchUtil.findListDateQuotaLevel2(quotaDate, area, level, index62, SaveModel.timeLevel_DDL, lowlevel, type,disease);
            saveModels = elasticsearchUtil.findListDateQuotaLevel2(quotaDate, area, level, index62, SaveModel.timeLevel_DDL, lowlevel, type, disease);
        } else {
            saveModels = elasticsearchUtil.findListDateQuotaLevel1(quotaDate, area, level, index67, SaveModel.timeLevel_DDL, lowlevel, type);
        }
@ -3937,30 +3974,31 @@ public class StatisticsESService {
                if (SaveModel.townLevel.equals(lowlevel)) {
                    map.put("code", one.getTown());
                    map.put("name", one.getTownName());
                    if (one != null&&one.getResult2()>0) {
                        avg = decimalFormat.format(one.getResult1() / (one.getResult2()*100));
                    if (one != null && one.getResult2() > 0) {
                        avg = decimalFormat.format(one.getResult1() / (one.getResult2() * 100));
                    }
                    map.put("val", avg);
                } else if (SaveModel.OrgLevel.equals(lowlevel)) {
                    map.put("code", one.getHospital());
                    map.put("name", one.getHospitalName());
                    if (one != null&&one.getResult2()>0) {
                        avg = decimalFormat.format(one.getResult1() / (one.getResult2()*100));
                    if (one != null && one.getResult2() > 0) {
                        avg = decimalFormat.format(one.getResult1() / (one.getResult2() * 100));
                    }
                    map.put("val", avg);
                } else if (SaveModel.teamLevel.equals(lowlevel)) {
                    map.put("code", one.getTeam());
                    map.put("name", one.getTeamName());
                    if (one != null&&one.getResult2()>0) {
                        avg = decimalFormat.format(one.getResult1() / (one.getResult2()*100));
                    if (one != null && one.getResult2() > 0) {
                        avg = decimalFormat.format(one.getResult1() / (one.getResult2() * 100));
                    }
                    map.put("val", avg);
                }
                countList.add(map);
            }
        }
        if(SaveModel.teamLevel.equals(lowlevel)){
            translateTeamLeaderNameListMap(countList);;
        if (SaveModel.teamLevel.equals(lowlevel)) {
            translateTeamLeaderNameListMap(countList);
            ;
        }
        Collections.sort(countList, new Comparator<Map<String, Object>>() {
@ -4018,10 +4056,10 @@ public class StatisticsESService {
                key = DateUtil.getMonth(dateFormat.format(one.getQuotaDate()));
            }
            String avg = "0.0";
            if (one.getResult2()!=0) {
                avg = decimalFormat.format(one.getResult1() / (one.getResult2()*100));
            if (one.getResult2() != 0) {
                avg = decimalFormat.format(one.getResult1() / (one.getResult2() * 100));
            }
            map.put("avg",avg);
            map.put("avg", avg);
            map.put("date", key);
            countList.add(map);

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

@ -32,7 +32,7 @@ import java.util.TreeMap;
 * Created by chenweida on 2017/10/13.
 */
@Controller
@RequestMapping(value = "/esstatistics", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, method = {RequestMethod.GET, RequestMethod.POST})
@RequestMapping(value = "/statistics", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, method = {RequestMethod.GET, RequestMethod.POST})
@Api(description = "ES统计查询")
public class EsStatisticsController extends BaseController {
@ -1709,7 +1709,7 @@ public class EsStatisticsController extends BaseController {
    public String getPrescriptionTotalHistogram(@ApiParam(name="level", value="级别") @RequestParam(required = true)String level,
                                                @ApiParam(name="area", value="级别对应编码") @RequestParam(required = true)String area,
                                                @ApiParam(name="disease", value="疾病类型") @RequestParam(required = false)String disease,
                                                @ApiParam(name="type", value="类型0.总量,1.进行中,2.已完成,3.居民取消,4.审核不通过,5.其他原因取消") @RequestParam(required = true)String type){
                                                @ApiParam(name="type", value="类型1.总量,2.已完成,3.居民取消,4.审核不通过,5.进行中,6.其他原因取消") @RequestParam(required = true)String type){
        try{
            return write(200, "查询成功", "data", statisticsESService.getPrescriptionTotalHistogram(elasticsearchUtil.changeLevel(Integer.valueOf(level)),area,disease,type));
        } catch (Exception e) {

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

@ -29,7 +29,7 @@ import java.util.*;
 * Created by lyr on 2016/08/16.
 */
@Controller
@RequestMapping(value = "/statistics", produces = MediaType.APPLICATION_JSON_UTF8_VALUE,method = {RequestMethod.GET,RequestMethod.POST})
@RequestMapping(value = "/oldstatistics", produces = MediaType.APPLICATION_JSON_UTF8_VALUE,method = {RequestMethod.GET,RequestMethod.POST})
@Api(description = "统计")
public class StatisticsController extends BaseController {

+ 103 - 73
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/service/GcEduArticleService.java

@ -1,10 +1,13 @@
package com.yihu.wlyy.web.third.gateway.service;
//import com.yihu.es.entity.ArticleTest;
import com.alibaba.fastjson.JSONObject;
import com.yihu.es.entity.HealthEduArticlePatient;
import com.yihu.wlyy.config.es.ElastricSearchSave;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.education.HealthEduArticlePatientDao;
import com.yihu.wlyy.repository.patient.PatientDao;
@ -13,10 +16,12 @@ import com.yihu.wlyy.service.app.health.HealthEduArticleOpHistoryService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.service.third.fzzb.HealthEducationArticleService;
import com.yihu.wlyy.util.ElasticsearchUtil;
import com.yihu.wlyy.web.third.gateway.vo.DictModel;
import com.yihu.wlyy.web.third.gateway.vo.HealthEduArticlePatientModel;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -74,17 +79,17 @@ public class GcEduArticleService {
        //1 服务类型  2 健康情况 3 疾病类型 4 自定义标签
        if (!org.springframework.util.StringUtils.isEmpty(labelType)) {
            switch (labelType) {
                case "1":{
                case "1": {
                    sb.append(" select w.code FROM wlyy_sign_family w  left join wlyy_sign_family_server s on w.code=s.sign_code " +
                            " left join wlyy_patient p on p.code=w.patient "+
                            " left join wlyy_patient p on p.code=w.patient " +
                            "where w.`status` > 0 and s.server_type=? ");
                    params.add(labelCode);
                }
                case "2":
                case "3":
                case "4":{
                case "4": {
                    sb.append(" SELECT w.code FROM wlyy_sign_family w left join wlyy_sign_patient_label_info l on w.patient = l.patient " +
                            " left join wlyy_patient p on p.code=w.patient "+
                            " left join wlyy_patient p on p.code=w.patient " +
                            "where w.`status` > 0 and l.label_type = ? AND l.label = ? and l.status=1 ");
                    params.add(labelType);
                    params.add(labelCode);
@ -100,7 +105,7 @@ public class GcEduArticleService {
        }
        if (patients != null && patients.length > 0) {
            List<String> arrPatient = java.util.Arrays.asList(patients);
            for(String str:arrPatient){
            for (String str : arrPatient) {
                patientSet.add(str);
            }
        }
@ -192,21 +197,21 @@ public class GcEduArticleService {
    /**
     * 保存发送信息
     *
     * @param patientSet   患者set集和
     * @param sendCode     发送人code、
     * @param sendName     发送人名称
     * @param sendMessage  发送人携带的信息
     * @param teamId       发送人所属团队
     * @param articleId    文章列表
     * @param patientSet  患者set集和
     * @param sendCode    发送人code、
     * @param sendName    发送人名称
     * @param sendMessage 发送人携带的信息
     * @param teamId      发送人所属团队
     * @param articleId   文章列表
     */
    @Transactional
    public HealthEduArticlePatient getSaveArticle(Set<String> patientSet,
                                                        String sendCode,
                                                        String sendName,
                                                        Integer sendType,
                                                        String sendMessage,
                                                        Long teamId,
                                                        String articleId) throws Exception{
                                                  String sendCode,
                                                  String sendName,
                                                  Integer sendType,
                                                  String sendMessage,
                                                  Long teamId,
                                                  String articleId) throws Exception {
        String batchNo = UUID.randomUUID().toString();
@ -219,13 +224,13 @@ public class GcEduArticleService {
        //1、医生,2、卫计委
        //如果是卫计委得区别角色
        Doctor doctor = null;
        if(sendType==2){
        if (sendType == 2) {
            String sql = "select r.code as roleCode from wlyy_user_role u " +
                    "left join wlyy_role r on r.`code`=u.role where u.user='"+sendCode+"'";
            Map<String,Object> result = jdbcTemplate.queryForMap(sql);
                    "left join wlyy_role r on r.`code`=u.role where u.user='" + sendCode + "'";
            Map<String, Object> result = jdbcTemplate.queryForMap(sql);
            //角色的code值
            healthEduArticlePatient.setSendCode(result.get("roleCode")+"");
        }else{
            healthEduArticlePatient.setSendCode(result.get("roleCode") + "");
        } else {
            doctor = doctorDao.findByCode(sendCode);
            healthEduArticlePatient.setSendCode(sendCode);
        }
@ -237,9 +242,9 @@ public class GcEduArticleService {
            healthEduArticlePatient.setHospitalName(doctor.getHospitalName());
            healthEduArticlePatient.setTown(doctor.getTown());
            healthEduArticlePatient.setTownName(doctor.getTownName());
            healthEduArticlePatient.setSendLevel(doctor.getLevel()!=null?String.valueOf(doctor.getLevel()):"");
            healthEduArticlePatient.setSendLevel(doctor.getLevel() != null ? String.valueOf(doctor.getLevel()) : "");
            healthEduArticlePatient.setSendPic(doctor.getPhoto());
            healthEduArticlePatient.setSendSex(doctor.getSex()!=null?String.valueOf(doctor.getSex()):"");
            healthEduArticlePatient.setSendSex(doctor.getSex() != null ? String.valueOf(doctor.getSex()) : "");
        }
        healthEduArticlePatient.setBatchNo(batchNo);
        healthEduArticlePatient.setCreateTime(new Date());
@ -247,15 +252,15 @@ public class GcEduArticleService {
        //通过文章id 获取文章详情
        JSONObject article = healthEducationArticleService.getArticalById(articleId);
        healthEduArticlePatient.setArticleId(article.get("articleId")+"");
        healthEduArticlePatient.setAttachedTitle(article.get("articleTitle")+"");
        healthEduArticlePatient.setAttachedPic(article.get("articleCover")+"");
        healthEduArticlePatient.setAttachedContent(article.get("articleContent")+"");
        healthEduArticlePatient.setArticleId(article.get("articleId") + "");
        healthEduArticlePatient.setAttachedTitle(article.get("articleTitle") + "");
        healthEduArticlePatient.setAttachedPic(article.get("articleCover") + "");
        healthEduArticlePatient.setAttachedContent(article.get("articleContent") + "");
        healthEduArticlePatient.setAttachedMessage(sendMessage);
        healthEduArticlePatient.setArticleType(article.get("articleType")+"");
        healthEduArticlePatient.setLevel(article.get("articlelevel")+"");
        healthEduArticlePatient.setLevel1Type(article.get("firstLevelCategoryId")+"");
        healthEduArticlePatient.setLevel2Type(article.get("secondLevelCategoryId")+"");
        healthEduArticlePatient.setArticleType(article.get("articleType") + "");
        healthEduArticlePatient.setLevel(article.get("articlelevel") + "");
        healthEduArticlePatient.setLevel1Type(article.get("firstLevelCategoryId") + "");
        healthEduArticlePatient.setLevel2Type(article.get("secondLevelCategoryId") + "");
        healthEduArticlePatient.setType("1");//文章
        healthEduArticlePatient.setArticleUrl("");
        healthEduArticlePatient.setPatients(patientList);
@ -269,7 +274,7 @@ public class GcEduArticleService {
        pagesize = page * pagesize;
        page = (page - 1) * pagesize;
        StringBuffer sql = new StringBuffer("select *,count(articleId) allCount from   " +esType+
        StringBuffer sql = new StringBuffer("select *,count(articleId) allCount from   " + esType +
                " where  sendCode='" + sendCode + "' ");
        if (!StringUtils.isEmpty(articleType)) {
            sql.append(" and  articleType='" + articleType + "'  ");
@ -309,7 +314,7 @@ public class GcEduArticleService {
    }
    private com.yihu.es.entity.HealthEduArticlePatient findOne(String articleId) {
        String sql = "select level,level2Type,level1Type,attachedContent,attachedTitle,articleId,createTime,articleType,sendCode,sendName from "+esType+" where articleId='" + articleId + "' order by createTime desc limit 0,1";
        String sql = "select level,level2Type,level1Type,attachedContent,attachedTitle,articleId,createTime,articleType,sendCode,sendName from " + esType + " where articleId='" + articleId + "' order by createTime desc limit 0,1";
        com.yihu.es.entity.HealthEduArticlePatient esList = (com.yihu.es.entity.HealthEduArticlePatient) elasticsearchUtil.excuteOneObject(sql, com.yihu.es.entity.HealthEduArticlePatient.class, esIndex, esType);
        return esList;
    }
@ -382,38 +387,64 @@ public class GcEduArticleService {
//        patientSet.addAll(groupPatient);
//    }
    public void initPatient(Set<String> patientSet,String labelUnit,String labelSex,String labelServe,String labelDisease,String labelHealth){
    public void initPatient(Set<String> patientSet, String labelUnit, String labelSex, String labelServe, String labelDisease, String labelHealth) {
        //全选的时候前端传0,后台要去数据库再查询一次
        if ("0".equals(labelUnit)) {
            //查找全部的下属单位
            String sql = "select Group_concat(code) code  from dm_hospital  where level=2 and town = '350211'" ;
            labelUnit = jdbcTemplate.queryForObject(sql,String.class);
        }
        if ("0".equals(labelSex)) {
            //查找全部的性别
            labelSex="1,2";
        }
        if ("0".equals(labelServe)) {
            //查找全部的服务类型
            String sql="select Group_concat(s.code) from wlyy_sign_dict s where s.year='2017' order by s.sort asc";
            labelServe = jdbcTemplate.queryForObject(sql,String.class);
        }
        if ("0".equals(labelDisease)) {
            //查找全部的疾病标签
            String sql="select Group_concat(s.label_code)  from wlyy_sign_patient_label s where s.label_type=3 and status=1";
            labelDisease = jdbcTemplate.queryForObject(sql,String.class);
        }
        if ("0".equals(labelHealth)) {
            //查找全部的健康情况
            String sql="select Group_concat(s.label_code)  from wlyy_sign_patient_label s where s.label_type=2 and status=1";
            labelHealth = jdbcTemplate.queryForObject(sql,String.class);
        }
        String tableSql = " select p.code from wlyy_sign_family w ";
        String whereSql = " where w.status>0 and p.town='350211' ";
        if(!StringUtils.isEmpty(labelServe)){
        if (!StringUtils.isEmpty(labelServe)) {
            tableSql += " left join wlyy_sign_family_server s on w.code= s.sign_code ";
            whereSql += " and s.server_type in ("+labelServe+" ) ";
            whereSql += " and s.server_type in (" + labelServe + " ) ";
        }
        if(!StringUtils.isEmpty(labelHealth)||!StringUtils.isEmpty(labelDisease)){
        if (!StringUtils.isEmpty(labelHealth) || !StringUtils.isEmpty(labelDisease)) {
            tableSql += " left join wlyy_sign_patient_label_info l on w.patient=l.patient ";
            whereSql += " and l.status=1 ";
            whereSql += " and ( ";
        }
        if(!StringUtils.isEmpty(labelHealth)){
            whereSql += " (l.label_type = 2 AND l.label in ("+labelHealth+")) ";
        if (!StringUtils.isEmpty(labelHealth)) {
            whereSql += " (l.label_type = 2 AND l.label in (" + labelHealth + ")) ";
        }
        if(!StringUtils.isEmpty(labelDisease)){
            if(!whereSql.endsWith(" and ( ")) {
                whereSql += " or (l.label_type = 3 AND l.label in ("+labelDisease+"))) ";
            }else{
                whereSql += " (l.label_type = 1 AND l.label in ("+labelDisease+"))) ";
        if (!StringUtils.isEmpty(labelDisease)) {
            if (!whereSql.endsWith(" and ( ")) {
                whereSql += " or (l.label_type = 3 AND l.label in (" + labelDisease + "))) ";
            } else {
                whereSql += " (l.label_type = 1 AND l.label in (" + labelDisease + "))) ";
            }
        }
        tableSql += " left join wlyy_patient p on p.code=w.patient ";
        if(!StringUtils.isEmpty(labelSex)){
            whereSql += " and p.sex in ("+labelSex+") ";
        if (!StringUtils.isEmpty(labelSex)) {
            whereSql += " and p.sex in (" + labelSex + ") ";
        }
        if(!StringUtils.isEmpty(labelUnit)){
            whereSql += " and w.hospital in ("+labelUnit+") ";
        if (!StringUtils.isEmpty(labelUnit)) {
            whereSql += " and w.hospital in (" + labelUnit + ") ";
        }
        List<String> groupPatient = jdbcTemplate.queryForList(tableSql+whereSql, String.class);
        List<String> groupPatient = jdbcTemplate.queryForList(tableSql + whereSql, String.class);
        patientSet.addAll(groupPatient);
    }
@ -457,25 +488,22 @@ public class GcEduArticleService {
//    }
    public List<HealthEduArticlePatientModel> pushArticleLogs(int page, int pagesize,String sendCode) throws Exception{
    public List<HealthEduArticlePatientModel> pushArticleLogs(int page, int pagesize, String sendCode) throws Exception {
        pagesize = page * pagesize;
        page = (page - 1) * pagesize;
        String sql = "select r.code as roleCode from wlyy_user_role u " +
                "left join wlyy_role r on r.`code`=u.role where u.user='"+sendCode+"'";
                "left join wlyy_role r on r.`code`=u.role where u.user='" + sendCode + "'";
        Map<String,Object> resultMap = jdbcTemplate.queryForMap(sql);
        Map<String, Object> resultMap = jdbcTemplate.queryForMap(sql);
        sendCode = resultMap.get("roleCode").toString();
        StringBuffer sql2 = new StringBuffer("select *  from   " +esType+
        StringBuffer sql2 = new StringBuffer("select *  from   " + esType +
                " where  sendCode='" + sendCode + "' ");
        sql2.append("  order by createTime limit " + page + "," + pagesize);
        List<com.yihu.es.entity.HealthEduArticlePatient> esList = elasticsearchUtil.excute(sql2.toString(), com.yihu.es.entity.HealthEduArticlePatient.class, esIndex, esType);
        List<HealthEduArticlePatientModel> returnList = new ArrayList<>();
        Map<String,HealthEduArticlePatientModel> result = new HashMap<>();
        Map<String, HealthEduArticlePatientModel> result = new HashMap<>();
        HealthEduArticlePatientModel heapm = null;
        com.alibaba.fastjson.JSONObject article = null;
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXX");
        for(HealthEduArticlePatient one :esList){
        for (HealthEduArticlePatient one : esList) {
            article = healthEducationArticleService.getArticalById(one.getArticleId());
//            com.yihu.es.entity.HealthEduArticlePatient p = findOne(one.getArticleId());
//            if (p != null) {
@ -484,10 +512,10 @@ public class GcEduArticleService {
//                BeanUtils.copyProperties(p, heapm);
//                returnList.add(heapm);
//            }
            if(result.get(one.getArticleId())!=null){
            if (result.get(one.getArticleId()) != null) {
                heapm = result.get(one.getArticleId());
            }else{
            } else {
                heapm = new HealthEduArticlePatientModel();
            }
            heapm.setSendName(one.getSendName());
@ -500,13 +528,15 @@ public class GcEduArticleService {
            heapm.setLevel1Type(article.getString("firstLevelCategoryId"));
            heapm.setLevel2Type(article.getString("secondLevelCategoryId"));
            heapm.setLevel(article.getString("articlelevel"));
            heapm.setAllCount(heapm.getAllCount()+one.getPatients().size());
            heapm.setBrowseNumbere(article.getInteger("browseNumber"));
            heapm.setCommentNumber(article.getInteger("commentNumber"));
            result.put(one.getArticleId(),heapm);
        };
        List< HealthEduArticlePatientModel > resultList = new ArrayList<>();
        for (Map.Entry< String, HealthEduArticlePatientModel > entry : result.entrySet()) {
            heapm.setAllCount(heapm.getAllCount() + one.getPatients().size());
            heapm.setBrowseNumbere(Integer.valueOf(article.getString("browseNumber")));//文章浏览数
            heapm.setCommentNumber(Integer.valueOf(article.getString("commentNumber")));//文章评论数
            heapm.setPointNumber(Integer.valueOf(article.getString("pointNumber")));//文章点赞数
            result.put(one.getArticleId(), heapm);
        }
        ;
        List<HealthEduArticlePatientModel> resultList = new ArrayList<>();
        for (Map.Entry<String, HealthEduArticlePatientModel> entry : result.entrySet()) {
            resultList.add(entry.getValue());
        }
        return resultList;
@ -514,20 +544,20 @@ public class GcEduArticleService {
    public Long pushArticleLogsCount(String sendCode) {
        StringBuffer sql = new StringBuffer("select count(distinct articleId) count  from   " +esType+
        StringBuffer sql = new StringBuffer("select count(distinct articleId) count  from   " + esType +
                " where  sendCode='" + sendCode + "' ");
        return elasticsearchUtil.excuteForLong(sql.toString(), esIndex, esType);
    }
    public JSONObject pushArticleConfirm(String articleId, String labelUnit,String labelSex,String labelServe,String labelDisease,String labelHealth) throws Exception{
    public JSONObject pushArticleConfirm(String articleId, String labelUnit, String labelSex, String labelServe, String labelDisease, String labelHealth) throws Exception {
        JSONObject article = healthEducationArticleService.getArticalById(articleId);
        Set<String> patientSet = new HashSet<>();
        initPatient(patientSet,labelUnit,labelSex,labelServe,labelDisease,labelHealth);
        initPatient(patientSet, labelUnit, labelSex, labelServe, labelDisease, labelHealth);
        long num = patientSet.size();
        JSONObject result = new JSONObject();
        result.put("num",num);
        result.put("articleTitle",article.getString("articleTitle"));
        result.put("num", num);
        result.put("articleTitle", article.getString("articleTitle"));
        return result;
    }
}

+ 20 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/vo/HealthEduArticlePatientModel.java

@ -41,6 +41,10 @@ public class HealthEduArticlePatientModel {
    private Integer browseNumbere=0;//文章浏览数
    @ApiModelProperty(value = "文章评论数", required = false, access = "response")
    private Integer commentNumber=0;//文章评论数
    @ApiModelProperty(value = "文章点赞数", required = false, access = "response")
    private Integer pointNumber=0;//文章点赞数
    @ApiModelProperty(value = "封面图", required = false, access = "response")
    private String articleCover;//封面图
    public String getSendCode() {
        return sendCode;
@ -145,4 +149,20 @@ public class HealthEduArticlePatientModel {
    public void setCommentNumber(Integer commentNumber) {
        this.commentNumber = commentNumber;
    }
    public Integer getPointNumber() {
        return pointNumber;
    }
    public void setPointNumber(Integer pointNumber) {
        this.pointNumber = pointNumber;
    }
    public String getArticleCover() {
        return articleCover;
    }
    public void setArticleCover(String articleCover) {
        this.articleCover = articleCover;
    }
}

+ 1 - 1
patient-co/patient-co-wlyy/src/main/resources/application-prod.yml

@ -118,5 +118,5 @@ activemq:
##如果是外网项目就是flase 内网是true
neiwang:
  enable: false
  enable: true
  wlyy: http://59.61.92.90:8072/wlyy