Browse Source

sql优化

zdm 6 years ago
parent
commit
caf095a23b

+ 12 - 5
svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/service/SpecialistService.java

@ -780,15 +780,19 @@ public class SpecialistService{
     */
    public MixEnvelop searchPatientInSpecialist(String doctorCode,String keywords,Integer page,Integer pageSize) throws Exception{
        String sql1 = " select count(1) as num ";
        String sql2 = " select p.name as name,p.idcard,p.code,p.photo ";
        String sql2 = " select p.name as name,p.idcard,p.code,p.photo,CASE WHEN wsf.status ='-4' THEN '已到期' WHEN wsf.status ='0' THEN '待签约' WHEN wsf.status ='1' THEN '已签约' WHEN wsf.status ='2' THEN '已签约' WHEN wsf.status ='3' THEN '已签约' ELSE '待签约' END  status  ";
        String whereSql ="";
        if(!StringUtils.isEmpty(keywords)){
            whereSql+=" and (p.name like '%"+keywords+"%' or p.idcard like '%"+keywords+"%' or p.mobile like '%"+keywords+"%') ";
        }
        String centerSql =" from "+basedb+".wlyy_patient p " +
                " LEFT JOIN wlyy_specialist.wlyy_specialist_patient_relation r on p.code=r.patient and sign_status='1' and doctor='"+doctorCode+"'"+
                " where r.id is not null "+whereSql;
        String sqlCount=sql1+centerSql;
        String centerSql =" from "+basedb+".wlyy_patient p LEFT JOIN  "+basedb+".wlyy_sign_family wsf ON p.code=wsf.patient AND wsf.type='1'" +
                " WHERE p.code not in (SELECT r.patient FROM  wlyy_specialist.wlyy_specialist_patient_relation r WHERE r.sign_status = '1' and doctor='"+doctorCode+"')"+" AND p.openid IS NOT NULL "+
               whereSql;
        String countCenterSql =" from "+basedb+".wlyy_patient p " +
                " WHERE p.code not in (SELECT r.patient FROM  wlyy_specialist.wlyy_specialist_patient_relation r WHERE r.sign_status = '1' and doctor='"+doctorCode+"')"+" AND p.openid IS NOT NULL "+
                whereSql;
        String sqlCount=sql1+countCenterSql;
        String sql=sql2+centerSql+" LIMIT "+(page-1)*pageSize+","+pageSize;
        List<Map<String,Object>> map = jdbcTemplate.queryForList(sql);
        List<Map<String,Object>> countMap = jdbcTemplate.queryForList(sqlCount);
@ -804,6 +808,7 @@ public class SpecialistService{
            m.put("name",one.get("name"));
            m.put("age",age);
            m.put("sex",sex);
            m.put("status",one.get("status"));
            if("1".equals(sex)){
                sexName="男";
            }else if("2".equals(sex)){
@ -816,7 +821,9 @@ public class SpecialistService{
            m.put("photo",one.get("photo"));
            resultList.add(m);
        }
        Long co=Long.parseLong("100");
        return MixEnvelop.getSuccessListWithPage(SpecialistMapping.api_success,resultList,page,pageSize,countMap.size()>0?Long.valueOf(countMap.get(0).get("num")+""):0);
//        return MixEnvelop.getSuccessListWithPage(SpecialistMapping.api_success,resultList,page,pageSize,co);
    }
    /**