Pārlūkot izejas kodu

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

sand 8 gadi atpakaļ
vecāks
revīzija
d8a53824c9
23 mainītis faili ar 1272 papildinājumiem un 188 dzēšanām
  1. 9 0
      src/main/java/com/yihu/wlyy/entity/WlyyDoctorWorkTime.java
  2. 8 0
      src/main/java/com/yihu/wlyy/entity/WlyyQuota.java
  3. 20 0
      src/main/java/com/yihu/wlyy/entity/WlyyQuotaResult.java
  4. 8 0
      src/main/java/com/yihu/wlyy/entity/WlyySignFamilyCode.java
  5. 1 1
      src/main/java/com/yihu/wlyy/entity/consult/ConsultTeam.java
  6. 44 0
      src/main/java/com/yihu/wlyy/entity/doctor/DoctorFamousConsultTimesRemain.java
  7. 48 0
      src/main/java/com/yihu/wlyy/job/Constant.java
  8. 189 0
      src/main/java/com/yihu/wlyy/job/CurrentDayAllQuotaJob.java
  9. 335 0
      src/main/java/com/yihu/wlyy/job/SignAgeGroupDiseaseJob.java
  10. 9 1
      src/main/java/com/yihu/wlyy/repository/ConsultDao.java
  11. 25 0
      src/main/java/com/yihu/wlyy/repository/ConsultTeamDao.java
  12. 21 0
      src/main/java/com/yihu/wlyy/repository/FamousDoctorTimesRemainDao.java
  13. 3 0
      src/main/java/com/yihu/wlyy/repository/WlyySignFamilyCodeDao.java
  14. 15 5
      src/main/java/com/yihu/wlyy/service/app/consult/ConsultService.java
  15. 60 11
      src/main/java/com/yihu/wlyy/service/app/consult/ConsultTeamService.java
  16. 3 0
      src/main/java/com/yihu/wlyy/service/app/family/FamilyService.java
  17. 174 54
      src/main/java/com/yihu/wlyy/service/app/scheduling/DoctorWorkTimeService.java
  18. 10 7
      src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java
  19. 37 0
      src/main/java/com/yihu/wlyy/service/common/account/DoctorService.java
  20. 3 3
      src/main/java/com/yihu/wlyy/web/doctor/consult/DoctorConsultController.java
  21. 33 1
      src/main/java/com/yihu/wlyy/web/doctor/device/DoctorDeviceController.java
  22. 73 13
      src/main/java/com/yihu/wlyy/web/doctor/scheduling/DoctorWorkTimeController.java
  23. 144 92
      src/main/java/com/yihu/wlyy/web/patient/consult/ConsultController.java

+ 9 - 0
src/main/java/com/yihu/wlyy/entity/WlyyDoctorWorkTime.java

@ -17,6 +17,8 @@ public class WlyyDoctorWorkTime extends IdEntity{
    private String doctorName;
    // 接收咨询 0不接受 1接受
    private String receiveConsult;
    // 名医咨询次数
    private Integer famousConsultTimes;
    // 上午开始时间
    private String morningBegin;
    // 上午结束时间
@ -53,6 +55,13 @@ public class WlyyDoctorWorkTime extends IdEntity{
        this.receiveConsult = receiveConsult;
    }
    public Integer getFamousConsultTimes() {
        return famousConsultTimes;
    }
    public void setFamousConsultTimes(Integer famousConsultTimes) {
        this.famousConsultTimes = famousConsultTimes;
    }
    public String getMorningBegin() {
        return morningBegin;
    }

+ 8 - 0
src/main/java/com/yihu/wlyy/entity/WlyyQuota.java

@ -22,6 +22,7 @@ public class WlyyQuota implements java.io.Serializable {
	private String name;//指标名称
	private String level1;//指标维度(1:机构维度)
	private String level2;//2级维度 (1:患者性别 2:患者分组 3:患者年龄)
	private String level3;//3级维度 (1:患者疾病)
	private String cycle;//统计周期( 1:天 )
	private String type;//尺度(1 新增 2是累计)
	private Date createTime;//创建时间
@ -122,5 +123,12 @@ public class WlyyQuota implements java.io.Serializable {
		this.del = del;
	}
	@Column(name = "level_3", length = 2)
	public String getLevel3() {
		return level3;
	}
	public void setLevel3(String level3) {
		this.level3 = level3;
	}
}

+ 20 - 0
src/main/java/com/yihu/wlyy/entity/WlyyQuotaResult.java

@ -27,6 +27,8 @@ public class WlyyQuotaResult implements java.io.Serializable {
    private String level1Type;//等级 1:团队 2社区机构 3区级 4市级
    private String level2Type;//如果有二级维度那么这个存的是二级维度的code 例如二级维度是性别 那么这个存 1
    private String level2TypeName;//如果有二级维度那么这个存的是二级维度的code 例如二级维度是性别 那么这个存 男
    private String level3Type;//如果有三级维度那么这个存的是三级维度的code 例如三级维度是疾病 那么这个存 1
    private String level3TypeName;//如果有三级维度那么这个存的是三级维度的code 例如三级维度是疾病 那么这个存 高血压
    private String city;//市
    private String cityName;//市级名称
    private String town;//区级
@ -222,4 +224,22 @@ public class WlyyQuotaResult implements java.io.Serializable {
    public void setLevel2TypeName(String level2TypeName) {
        this.level2TypeName = level2TypeName;
    }
    @Column(name = "level3_type", length = 50)
    public String getLevel3Type() {
        return level3Type;
    }
    public void setLevel3Type(String level3Type) {
        this.level3Type = level3Type;
    }
    @Column(name = "level3_type_name", length = 50)
    public String getLevel3TypeName() {
        return level3TypeName;
    }
    public void setLevel3TypeName(String level3TypeName) {
        this.level3TypeName = level3TypeName;
    }
}

+ 8 - 0
src/main/java/com/yihu/wlyy/entity/WlyySignFamilyCode.java

@ -23,6 +23,7 @@ public class WlyySignFamilyCode implements java.io.Serializable {
	private String orgName;
	private Integer sequence;
	private Date modifyTime;
	private String year;
	// Constructors
@ -93,5 +94,12 @@ public class WlyySignFamilyCode implements java.io.Serializable {
		this.modifyTime = modifyTime;
	}
	@Column(name = "year" , length = 10)
	public String getYear() {
		return year;
	}
	public void setYear(String year) {
		this.year = year;
	}
}

+ 1 - 1
src/main/java/com/yihu/wlyy/entity/consult/ConsultTeam.java

@ -30,7 +30,7 @@ public class ConsultTeam extends IdEntity {
	private String doctor;
	// 三师团队标识
	private String team;
	//三师咨询,2家庭医生咨询 3.名医咨询
	//1 三师咨询,2家庭医生咨询 6.名医咨询
	private Integer type;
	// 提问者标识
	private String patient;

+ 44 - 0
src/main/java/com/yihu/wlyy/entity/doctor/DoctorFamousConsultTimesRemain.java

@ -0,0 +1,44 @@
package com.yihu.wlyy.entity.doctor;
import com.yihu.wlyy.entity.IdEntity;
import org.springframework.data.repository.cdi.Eager;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * Created by JKZL-A on 2016/9/19.
 */
@Entity
@Table(name = "wlyy_doctor_famous_consult_times_remain")
public class DoctorFamousConsultTimesRemain extends IdEntity {
    // 医生代码
    private String doctor;
    // 咨询日期
    private String consultDate;
    // 剩余次数
    private Integer timesRemain;
    public String getDoctor() {
        return doctor;
    }
    public void setDoctor(String doctor) {
        this.doctor = doctor;
    }
    public String getConsultDate() {
        return consultDate;
    }
    public void setConsultDate(String consultDate) {
        this.consultDate = consultDate;
    }
    public Integer getTimesRemain() {
        return timesRemain;
    }
    public void setTimesRemain(Integer timesRemain) {
        this.timesRemain = timesRemain;
    }
}

+ 48 - 0
src/main/java/com/yihu/wlyy/job/Constant.java

@ -43,4 +43,52 @@ public class Constant {
    public static String level_group_4_name="高血压";
    public static String level_group_5_name="糖尿病";
    public static String level_group_100_name="糖尿病和高血压";
    //三级维度的疾病
    public static String level_disease_1="1";
    public static String level_disease_2="2";
    public static String level_disease_3="3";
    public static String level_disease_1_name="高血压";
    public static String level_disease_2_name="糖尿病";
    public static String level_disease_3_name="糖尿病和高血压";
    public static String getLevelAgeName(String key){
        switch (key){
            case "1":{
                return level_age_1_name;
            }
            case "2":{
                return level_age_2_name;
            }
            case "3":{
                return level_age_3_name;
            }
            case "4":{
                return level_age_4_name;
            }
            case "5":{
                return level_age_5_name;
            }
            case "6":{
                return level_age_6_name;
            }
        }
        return "";
    }
    public static String getLevelDiseaseName(String key){
        switch (key){
            case "1":{
                return level_disease_1_name;
            }
            case "2":{
                return level_disease_2_name;
            }
            case "3":{
                return level_disease_3_name;
            }
        }
        return "";
    }
}

+ 189 - 0
src/main/java/com/yihu/wlyy/job/CurrentDayAllQuotaJob.java

@ -120,13 +120,202 @@ public class CurrentDayAllQuotaJob implements Job {
        computequota_8();//统计今天的签约患者年龄
        computequota_9();//统计今天的待签约
        computequota_10();//统计今天的改签
        computequota_12();//统计今天的签约下按年龄分组后再按疾病统计
        wlyyJobLog.setJobContent("开始实时统计查询");
        wlyyJobLog.setJobName("实时统计");
        wlyyJobLog.setJobId("11");
        wlyyJobLog.setJobType("1");
        wlyyJobLog.setJobEndTime(new Date());
        wlyyJobLogDao.save(wlyyJobLog);
    }
    private void computequota_12() throws Exception{
        String now = getDayString(0);
        String tomorrow = getDayString(1);
        //找出今天的签约信息 yesterday,now
        //查找出系统全部的机构
        List<Hospital> hospitals = hospitalDao.findHospital2();
        Map<String, Hospital> hospitalsMap = new HashMap<String, Hospital>();
        for (Hospital hospital : hospitals) {
            hospitalsMap.put(hospital.getCode(), hospital);
        }
        //查找出厦门市全部的区
        List<Town> towns = townDao.findByCityCode(Constant.city);
        Map<String, Town> townsMap = new HashMap<String, Town>();
        for (Town town : towns) {
            townsMap.put(town.getCode(), town);
        }
        //找出今天的签约信息
        List<SignFamily> signFamilys = signFamilyDao.findByJiatingSignYesterday(now, tomorrow);
        //数组里面第一个是健康人群 第二个是慢病人群 第三个是65岁以上人群
        Map<String, Map<String, Map>> cityAgeMap = new HashMap<String, Map<String, Map>>();//key是市行政代码 目前只有厦门市
        Map<String,Map> temp =new HashMap<String,Map>();
        cityAgeMap.put(Constant.city, temp);
        Map<String, Map<String, Map>> townAgeMap = new HashMap<String, Map<String, Map>>();//key是区行政代码
        Map<String, Map<String, Map>> orgAgeMap = new HashMap<String, Map<String, Map>>();//key是机构代码
        //统计有签约的
        for (SignFamily signFamily : signFamilys) {
            Hospital hospital = hospitalsMap.get(signFamily.getHospital());//得到患者签约的机构
            String town = hospital.getTown();
            int age = IdCardUtil.getAgeForIdcard(signFamily.getIdcard());//根据card解析年龄
            String ageCode = getAgeCode(age);//得到年龄的code
            boolean hasGXY = false;//有高血压
            boolean hasTNB = false;//有糖尿病
            //如果是慢病的 统计高血压的 糖尿病  1高血压,2糖尿病  糖尿病和高血压是100
            String diseaseType="";
            String jsonString = redisTemplate.opsForValue().get("disease:" + signFamily.getPatient());
            if (StringUtils.isEmpty(jsonString)) {
                continue;
            }
            //排除数据 只留下高血压和糖尿病
            List<JSONObject> jsonObjects = new ArrayList<JSONObject>();
            JSONArray redisValues = new JSONArray(jsonString);
            for (Object obj : redisValues) {
                JSONObject redisValue = new JSONObject(obj);
                //排除掉三师签约
                if ("1".equals(redisValue.get("signType").toString())) {
                    continue;
                }
                String disease = redisValue.get("disease").toString();
                if (Integer.valueOf(disease).equals("1")) {
                    jsonObjects.add(redisValue);
                    hasGXY = true;//设置有高血压
                    diseaseType="1";
                }
                if (Integer.valueOf(disease).equals("2")) {
                    jsonObjects.add(redisValue);
                    hasTNB = true;//设置有糖尿病
                    diseaseType="2";
                }
            }
            if(hasGXY&&hasTNB){
                diseaseType="100";
            }
            //统计市
            compute(cityAgeMap, Constant.city, ageCode, diseaseType);
            //统计区
            compute(townAgeMap, town, ageCode, diseaseType);
            //统计机构
            //统计站
            if (!"00".equals(hospital.getCode().substring(8))) {
                String orgCodeTemp = hospital.getCode().substring(0, 8) + "00";
                //统计机构
                compute(orgAgeMap, orgCodeTemp, ageCode, diseaseType);
            } else {
                compute(orgAgeMap, hospital.getCode(), ageCode, diseaseType);
            }
        }
        //保存市级数据
        for (Map.Entry<String, Map<String, Map>> entry : cityAgeMap.entrySet()) {
            Map<String, Map> oneAgeMap = entry.getValue();
            for(int i=1;i<7;i++){
                for(int j=1;j<4;j++){
                    String key_2=i+"";
                    String key_3=j+"";
                    String name=Constant.cityName;
                    JSONObject jsonObject=new JSONObject();
                    if (oneAgeMap != null && oneAgeMap.containsKey(key_2)) {
                        Map<String,Long> key3Map=oneAgeMap.get(key_2);
                        if(key3Map!=null&&key3Map.containsKey(key_3)){
                            jsonObject.put("num",entry.getValue().get((key3Map.get(key_3) + "")));
                        }else{
                            jsonObject.put("num",0);
                        }
                    } else {
                        jsonObject.put("num",0);
                    }
                    jsonObject.put("name",name);
                    jsonObject.put("date", DateUtil.dateToStrLong(new Date()));
                    redisTemplate.opsForValue().set(new StringBuffer("quota:12:4:"+i+":"+j+":"+entry.getKey()).toString(),jsonObject.toString());
                }
            }
        }
        //保存区级
        for (Map.Entry<String, Town> entry : townsMap.entrySet()) {
            //判断该区是否有统计数据
            Map<String, Map> oneAgeMap = townAgeMap.get(entry.getKey());//得到当个区的统计数据
            Town townObj = entry.getValue();//得到区级信息
            for(int i=1;i<7;i++){
                for(int j=1;j<4;j++){
                    String key_2=i+"";
                    String key_3=j+"";
                    String name=townObj.getName();
                    JSONObject jsonObject=new JSONObject();
                    if (oneAgeMap != null && oneAgeMap.containsKey(key_2)) {
                        Map<String,Long> key3Map=oneAgeMap.get(key_2);
                        if(key3Map!=null&&key3Map.containsKey(key_3)){
                            jsonObject.put("num",(key3Map.get(key_3) + ""));
                        }else{
                            jsonObject.put("num",0);
                        }
                    } else {
                        jsonObject.put("num",0);
                    }
                    jsonObject.put("name",townObj.getName());
                    jsonObject.put("date", DateUtil.dateToStrLong(new Date()));//quota:12:2:6:1:350200
                    redisTemplate.opsForValue().set(new StringBuffer("quota:12:3:"+i+":"+j+":"+entry.getKey()).toString(),jsonObject.toString());
                }
            }
        }
        //保存机构级
        for (Map.Entry<String, Hospital> entry : hospitalsMap.entrySet()) {
            //判断该机构是否有统计数据
            Map<String, Map> oneAgeMap = orgAgeMap.get(entry.getKey());//得到当个机构的统计数据
            Hospital hospital = entry.getValue();//得到机构信息
            for(int i=1;i<7;i++){
                for(int j=1;j<4;j++){
                    String key_2=i+"";
                    String key_3=j+"";
                    String name=hospital.getName();
                    JSONObject jsonObject=new JSONObject();
                    if (oneAgeMap != null && oneAgeMap.containsKey(key_2)) {
                        Map<String,Long> key3Map=oneAgeMap.get(key_2);
                        if(key3Map!=null&&key3Map.containsKey(key_3)){
                            jsonObject.put("num",(key3Map.get(key_3) + ""));
                        }else{
                            jsonObject.put("num",0);
                        }
                    } else {
                        jsonObject.put("num",0);
                    }
                    jsonObject.put("name",name);
                    jsonObject.put("date", DateUtil.dateToStrLong(new Date()));
                    redisTemplate.opsForValue().set(new StringBuffer("quota:12:2:"+i+":"+j+":"+entry.getKey()).toString(),jsonObject.toString());
                }
            }
        }
    }
    private void compute(Map<String, Map<String, Map>> rootMap, String rootKey, String ageCode, String diseaseType) {
        if (rootMap.containsKey(rootKey)) {
            //得到市下面的所有的年龄map
            Map<String, Map> groupMapTemp = rootMap.get(rootKey);
            if(groupMapTemp.containsKey(ageCode)){
                //得到这个年龄下的患者map
                Map<String,Long> mape= groupMapTemp.get(ageCode);
                if(mape.containsKey(diseaseType)){
                    mape.put(diseaseType,mape.get(diseaseType)+1L);
                }else{
                    mape.put(diseaseType,1L);
                }
            }else{
                //新增疾病的统计map
                Map<String, Long> groupMapTemp1 = new HashMap<String, Long>();
                groupMapTemp1.put(diseaseType, 1L);
                groupMapTemp.put(ageCode,groupMapTemp1);
            }
        } else {
            //没有就新建统计数据  新增疾病的统计map
            Map<String, Long> groupMapTemp = new HashMap<String, Long>();
            groupMapTemp.put(diseaseType, 1L);
            //把统计疾病的map放入对应的年龄组map中
            Map<String, Map> groupMapTemp2 = new HashMap<String, Map>();
            groupMapTemp2.put(ageCode,groupMapTemp);
            //把年龄组map放入市的map里面
            rootMap.put(rootKey, groupMapTemp2);
        }
    }
    private void computequota_1() {
        //签约需要的统计map
        Map<String, JSONObject> tjCityMap = new HashMap<>();//区级的统计map key 是区行政区划350200

+ 335 - 0
src/main/java/com/yihu/wlyy/job/SignAgeGroupDiseaseJob.java

@ -0,0 +1,335 @@
package com.yihu.wlyy.job;
import com.yihu.wlyy.entity.SignFamily;
import com.yihu.wlyy.entity.WlyyJobLog;
import com.yihu.wlyy.entity.WlyyQuotaResult;
import com.yihu.wlyy.entity.address.Hospital;
import com.yihu.wlyy.entity.address.Town;
import com.yihu.wlyy.repository.*;
import com.yihu.wlyy.util.IdCardUtil;
import com.yihu.wlyy.web.quota.WlyyJobConfigVO;
import com.yihu.wlyy.web.quota.WlyyQuotaVO;
import org.json.JSONArray;
import org.json.JSONObject;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * 签约下按年龄分组后再按疾病统计
 */
@Component
public class SignAgeGroupDiseaseJob implements Job {
    private WlyyQuotaVO wlyyQuota;//指标对象
    private WlyyJobConfigVO wlyyJobConfig;//配置对象
    @Autowired
    private WlyyQuotaResultDao wlyyQuotaResultDao;//指标结果Dao
    @Autowired
    private WlyyJobLogDao wlyyJobLogDao;//执行日志Dao
    @Autowired
    private SignFamilyDao signFamilyDao;
    @Autowired
    private DoctorDao doctorDao;
    @Autowired
    private HospitalDao hospitalDao;
    @Autowired
    private TownDao townDao;
    @Autowired
    private DoctorPatientGroupInfoDao doctorPatientGroupInfoDao;
    @Autowired
    private PatientDao patientDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private StringRedisTemplate redisTemplate;
    String yesterday;
    String now;
    @Override
    public void execute(JobExecutionContext context)
            throws JobExecutionException {
        SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
        //初始化参数
        JobDataMap map = context.getJobDetail().getJobDataMap();
        wlyyQuota = (WlyyQuotaVO) map.get("quota");
        wlyyJobConfig = (WlyyJobConfigVO) map.get("jobConfig");
        now = StringUtils.isEmpty(map.get("now")) ? SignAgeGroupDiseaseJob.getDayString(0) : map.get("now").toString();
        yesterday = StringUtils.isEmpty(map.get("yesterday")) ? SignAgeGroupDiseaseJob.getDayString(-1) : map.get("yesterday").toString();
        computequotaByPatientAge();
    }
    /**
     * 机构维度患者年龄维度计算指标
     */
    @Transactional
    private void computequotaByPatientAge() {
        try {
            jdbcTemplate.execute("delete from wlyy_quota_result where quota_date='"+yesterday+"' and quato_code='"+12+"'");
            //新建任务日志对象
            WlyyJobLog wlyyJobLog = new WlyyJobLog();
            wlyyJobLog.setJobStartTime(new Date());
            wlyyJobLog.setJobId(wlyyJobConfig.getId());
            wlyyJobLog.setJobName(wlyyJobConfig.getJobName());
            //查找出系统全部的机构
            List<Hospital> hospitals = hospitalDao.findHospital2();
            Map<String, Hospital> hospitalsMap = new HashMap<String, Hospital>();
            for (Hospital hospital : hospitals) {
                hospitalsMap.put(hospital.getCode(), hospital);
            }
            //查找出厦门市全部的区
            List<Town> towns = townDao.findByCityCode(Constant.city);
            Map<String, Town> townsMap = new HashMap<String, Town>();
            for (Town town : towns) {
                townsMap.put(town.getCode(), town);
            }
            //找出今天的签约信息
            List<SignFamily> signFamilys = signFamilyDao.findByJiatingSignYesterday(yesterday, now);
            //数组里面第一个是健康人群 第二个是慢病人群 第三个是65岁以上人群
            Map<String, Map<String, Map>> cityAgeMap = new HashMap<String, Map<String, Map>>();//key是市行政代码 目前只有厦门市
            Map<String,Map> temp =new HashMap<String,Map>();
            cityAgeMap.put(Constant.city, temp);
            Map<String, Map<String, Map>> townAgeMap = new HashMap<String, Map<String, Map>>();//key是区行政代码
            Map<String, Map<String, Map>> orgAgeMap = new HashMap<String, Map<String, Map>>();//key是机构代码
            //统计有签约的
            for (SignFamily signFamily : signFamilys) {
                Hospital hospital = hospitalsMap.get(signFamily.getHospital());//得到患者签约的机构
                String town = hospital.getTown();
                int age = IdCardUtil.getAgeForIdcard(signFamily.getIdcard());//根据card解析年龄
                String ageCode = getAgeCode(age);//得到年龄的code
                boolean hasGXY = false;//有高血压
                boolean hasTNB = false;//有糖尿病
                //如果是慢病的 统计高血压的 糖尿病  1高血压,2糖尿病  3 糖尿病和高血压 4健康人群数
                String diseaseType="";
                String jsonString = redisTemplate.opsForValue().get("disease:" + signFamily.getPatient());
                if (StringUtils.isEmpty(jsonString)) {
                    diseaseType="4";//健康人群
                }else{
                    //排除数据 只留下高血压和糖尿病
                    List<JSONObject> jsonObjects = new ArrayList<JSONObject>();
                    JSONArray redisValues = new JSONArray(jsonString);
                    if(redisValues.length()>0){
                        for (Object obj : redisValues) {
                            JSONObject redisValue = new JSONObject(obj);
                            //排除掉三师签约
                            if ("1".equals(redisValue.get("signType").toString())) {
                                continue;
                            }
                            String disease = redisValue.get("disease").toString();
                            if (Integer.valueOf(disease).equals("1")) {
                                jsonObjects.add(redisValue);
                                hasGXY = true;//设置有高血压
                                diseaseType="1";
                            }
                            if (Integer.valueOf(disease).equals("2")) {
                                jsonObjects.add(redisValue);
                                hasTNB = true;//设置有糖尿病
                                diseaseType="2";
                            }
                        }
                        if(hasGXY&&hasTNB){
                            diseaseType="3";
                        }
                    }else{
                        diseaseType="4";
                    }
                }
                //统计市
                compute(cityAgeMap, Constant.city, ageCode, diseaseType);
                //统计区
                compute(townAgeMap, town, ageCode, diseaseType);
                //统计机构
                //统计站
                if (!"00".equals(hospital.getCode().substring(8))) {
                    String orgCodeTemp = hospital.getCode().substring(0, 8) + "00";
                    //统计机构
                    compute(orgAgeMap, orgCodeTemp, ageCode, diseaseType);
                } else {
                    compute(orgAgeMap, hospital.getCode(), ageCode, diseaseType);
                }
            }
            //保存统计数据
            // 保存市的统计数据
            for (Map.Entry<String, Map<String, Map>> entry : cityAgeMap.entrySet()) {
               Map<String, Map> oneAgeMap = entry.getValue();
               for(int i=1;i<7;i++){
                   for(int j=1;j<4;j++){
                       String key_2=i+"";
                       String key_3=j+"";
                       String city=Constant.city;
                       String cityName=Constant.cityName;
                       String town="";
                       String townName="";
                       String org="";
                       String orgName="";
                       save(oneAgeMap, key_2, key_3, city, cityName, town, townName, org, orgName,"4");
                   }
               }
            }
            //保存区级
            for (Map.Entry<String, Town> entry : townsMap.entrySet()) {
                //判断该区是否有统计数据
                Map<String, Map> oneAgeMap = townAgeMap.get(entry.getKey());//得到当个区的统计数据
                Town townObj = entry.getValue();//得到区级信息
                for(int i=1;i<7;i++){
                    for(int j=1;j<4;j++){
                        String key_2=i+"";
                        String key_3=j+"";
                        String city=Constant.city;
                        String cityName=Constant.cityName;
                        String town=townObj.getCode();
                        String townName=townObj.getName();
                        String org="";
                        String orgName="";
                        save(oneAgeMap, key_2, key_3, city, cityName, town, townName, org, orgName,"3");
                    }
                }
            }
            for (Map.Entry<String, Hospital> entry : hospitalsMap.entrySet()) {
                //判断该机构是否有统计数据
                Map<String, Map> oneAgeMap = orgAgeMap.get(entry.getKey());//得到当个机构的统计数据
                Hospital hospital = entry.getValue();//得到机构信息
                for(int i=1;i<7;i++){
                    for(int j=1;j<4;j++){
                        String key_2=i+"";
                        String key_3=j+"";
                        String city=Constant.city;
                        String cityName=Constant.cityName;
                        String town=hospital.getTown();
                        String townName=hospital.getTownName();
                        String org=hospital.getCode();
                        String orgName=hospital.getName();
                        save(oneAgeMap, key_2, key_3, city, cityName, town, townName, org, orgName,"2");
                    }
                }
            }
            wlyyJobLog.setJobEndTime(new Date());
            wlyyJobLog.setJobContent("统计" + getYesterday() + " 的签约患者年龄数据完成 ");
            wlyyJobLog.setJobType("1");
            wlyyJobLogDao.save(wlyyJobLog);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    private void save(Map<String, Map> oneAgeMap, String key_2, String key_3, String city, String cityName, String town, String townName, String org, String orgName,String level) {
        WlyyQuotaResult wlyyQuotaResult = new WlyyQuotaResult();
        wlyyQuotaResult.setDel("1");
        wlyyQuotaResult.setCity(city);
        wlyyQuotaResult.setCityName(cityName);
        wlyyQuotaResult.setTown(town);
        wlyyQuotaResult.setTownName(townName);
        wlyyQuotaResult.setOrgCode(org);
        wlyyQuotaResult.setOrgName(orgName);
        wlyyQuotaResult.setQuatoCode(wlyyQuota.getId());
        wlyyQuotaResult.setQuatoName(wlyyQuota.getName());
        wlyyQuotaResult.setQuotaDate(getYesterday());
        wlyyQuotaResult.setCreateTime(new Date());
        wlyyQuotaResult.setLevel1Type(level);//等级
        wlyyQuotaResult.setLevel2Type(key_2);
        wlyyQuotaResult.setLevel2TypeName(Constant.getLevelAgeName(key_2));
        wlyyQuotaResult.setLevel3Type(key_3);
        wlyyQuotaResult.setLevel3TypeName(Constant.getLevelDiseaseName(key_3));
        if (oneAgeMap != null && oneAgeMap.containsKey(key_2)) {
            Map<String,Long> key3Map=oneAgeMap.get(key_2);
            if(key3Map!=null&&key3Map.containsKey(key_3)){
                wlyyQuotaResult.setResult(key3Map.get(key_3) + "");
            }else{
                wlyyQuotaResult.setResult("0");
            }
        } else {
            wlyyQuotaResult.setResult("0");
        }
        wlyyQuotaResultDao.save(wlyyQuotaResult);
    }
    private void compute(Map<String, Map<String, Map>> rootMap, String rootKey, String ageCode, String diseaseType) {
        if (rootMap.containsKey(rootKey)) {
            //得到市下面的所有的年龄map
            Map<String, Map> groupMapTemp = rootMap.get(rootKey);
            if(groupMapTemp.containsKey(ageCode)){
                //得到这个年龄下的患者map
                Map<String,Long> mape= groupMapTemp.get(ageCode);
                if(mape.containsKey(diseaseType)){
                    mape.put(diseaseType,mape.get(diseaseType)+1L);
                }else{
                    mape.put(diseaseType,1L);
                }
            }else{
                //新增疾病的统计map
                Map<String, Long> groupMapTemp1 = new HashMap<String, Long>();
                groupMapTemp1.put(diseaseType, 1L);
                groupMapTemp.put(ageCode,groupMapTemp1);
            }
        } else {
            //没有就新建统计数据  新增疾病的统计map
            Map<String, Long> groupMapTemp = new HashMap<String, Long>();
            groupMapTemp.put(diseaseType, 1L);
            //把统计疾病的map放入对应的年龄组map中
            Map<String, Map> groupMapTemp2 = new HashMap<String, Map>();
            groupMapTemp2.put(ageCode,groupMapTemp);
            //把年龄组map放入市的map里面
            rootMap.put(rootKey, groupMapTemp2);
        }
    }
    /*
    得到昨天的日期字符串  yyyy-MM-dd
     */
    public String getYesterday() {
        return yesterday;
    }
    /**
     * 根据年龄得到对应的code
     *
     * @param age
     * @return
     */
    public String getAgeCode(int age) {
        if (age < 7) {
            return Constant.level_age_1;
        } else if (age >= 7 && age < 18) {
            return Constant.level_age_2;
        } else if (age >= 18 && age < 30) {
            return Constant.level_age_3;
        } else if (age >= 30 && age < 50) {
            return Constant.level_age_4;
        } else if (age >= 50 && age < 65) {
            return Constant.level_age_5;
        } else {
            return Constant.level_age_6;
        }
    }
    public static String getDayString(Integer size) {
        Date date = new Date();//取时间
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(calendar.DATE, size);//把日期往后增加一天.整数往后推,负数往前移动
        date = calendar.getTime(); //这个时间就是日期往后推一天的结果
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String dateString = formatter.format(date);
        return dateString;
    }
    public static void main(String[] args) {
        getDayString(0);
    }
}

+ 9 - 1
src/main/java/com/yihu/wlyy/repository/ConsultDao.java

@ -12,12 +12,20 @@ public interface ConsultDao extends PagingAndSortingRepository<Consult, Long>, J
	
	Consult findByCode(String code);
	// 查询患者咨询记录
	@Query("select a.id,a.type,a.code,a.title,a.symptoms,a.czrq,b.status from Consult a,ConsultTeam b where a.code = b.consult and a.patient = ?1 and a.del = '1' and a.symptoms like ?2 order by a.czrq desc")
	Page<Object> findByPatient(String patient,String title, Pageable pageRequest);
	// 查询患者咨询记录
	@Query("select a.id,a.type,a.code,a.title,a.symptoms,a.czrq,b.status from Consult a,ConsultTeam b where a.code = b.consult and a.patient = ?1 and a.id < ?3 and a.del = '1'and a.symptoms like ?2 order by a.czrq desc")
	Page<Object> findByPatient(String patient,String title, long id, Pageable pageRequest);
	// 查询患者咨询记录
	@Query("select a.id,a.type,a.code,a.title,a.symptoms,a.czrq,b.status from Consult a,ConsultTeam b where a.code = b.consult and a.patient = ?1 and a.del = '1' order by a.czrq desc")
	Page<Object> findByPatient(String patient, Pageable pageRequest);
	// 查询患者咨询记录
	@Query("select a.id,a.type,a.code,a.title,a.symptoms,a.czrq,b.status from Consult a,ConsultTeam b where a.code = b.consult and a.patient = ?1 and a.id < ?2 and a.del = '1' order by a.czrq desc")
	@Query("select a.id,a.type,a.code,a.title,a.symptoms,a.czrq,b.status from Consult a,ConsultTeam b where a.code = b.consult and a.patient = ?1 and a.id < ?2 and a.del = '1'order by a.czrq desc")
	Page<Object> findByPatient(String patient, long id, Pageable pageRequest);
	@Query("select count(a) from Consult a,ConsultTeamDoctor b  where a.code = b.consult and a.patient=?1 and b.to=?2 ")

+ 25 - 0
src/main/java/com/yihu/wlyy/repository/ConsultTeamDao.java

@ -6,6 +6,7 @@
package com.yihu.wlyy.repository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
@ -144,4 +145,28 @@ public interface ConsultTeamDao extends PagingAndSortingRepository<ConsultTeam,
	//查找
	@Query("SELECT a FROM ConsultTeam a WHERE a.patient=?1 and a.status=0 and a.del=1")
	ConsultTeam findFamousConsultByPatient(String uid);
	//名医咨询 -全部
	@Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.id < ?2 and a.del = '1' and b.del = '1'")
	Page<ConsultTeam> findFamousDoctorAllList(String uid, long id, Pageable pageRequest);
	//名医咨询 -全部
	@Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1  and a.del = '1' and b.del = '1'")
	Page<ConsultTeam> findFamousDoctorAllList(String uid, Pageable pageRequest);
	//名医咨询 -全部 带symptoms
	@Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.id < ?2 and a.symptoms like ?3 and a.del = '1' and b.del = '1'")
	Page<ConsultTeam> findFamousDoctorAllList(String uid, long id,String title, Pageable pageRequest);
	//名医咨询 -全部 带symptoms
	@Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.symptoms like ?2  and a.del = '1' and b.del = '1'")
	Page<ConsultTeam> findFamousDoctorAllList(String uid,String title, Pageable pageRequest);
	//名医咨询 -根据status
	@Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.id < ?2 and a.status = ?3 and a.del = '1' and b.del = '1'")
	Page<ConsultTeam> findFamousDoctorDoingList(String uid, long id,Integer type, Pageable pageRequest);
	//名医咨询 -根据status
	@Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.status = ?2  and a.del = '1' and b.del = '1'")
	Page<ConsultTeam> findFamousDoctorDoingList(String uid,Integer type, Pageable pageRequest);
	//名医咨询 -根据status 带symptoms
	@Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.id < ?2 and a.symptoms like ?3 and a.status = ?4 and a.del = '1' and b.del = '1'")
	Page<ConsultTeam> findFamousDoctorDoingList(String uid, long id,String title,Integer type, Pageable pageRequest);
	//名医咨询 -根据status 带symptoms
	@Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.symptoms like ?2 and a.status = ?3 and a.del = '1' and b.del = '1'")
	Page<ConsultTeam> findFamousDoctorDoingList(String uid,String title,Integer type, Pageable pageRequest);
}

+ 21 - 0
src/main/java/com/yihu/wlyy/repository/FamousDoctorTimesRemainDao.java

@ -0,0 +1,21 @@
package com.yihu.wlyy.repository;
import com.yihu.wlyy.entity.doctor.DoctorFamousConsultTimesRemain;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by JKZL-A on 2016/9/19.
 */
public interface FamousDoctorTimesRemainDao extends PagingAndSortingRepository<DoctorFamousConsultTimesRemain, Long>,
        JpaSpecificationExecutor<DoctorFamousConsultTimesRemain> {
    /**
     * 查询医生剩余咨询次数
     *
     * @param doctor 医生
     * @param consultDate 咨询日期
     * @return
     */
    DoctorFamousConsultTimesRemain findByDoctorAndConsultDate(String doctor,String consultDate);
}

+ 3 - 0
src/main/java/com/yihu/wlyy/repository/WlyySignFamilyCodeDao.java

@ -14,4 +14,7 @@ import org.springframework.data.repository.PagingAndSortingRepository;
public interface WlyySignFamilyCodeDao  extends PagingAndSortingRepository<WlyySignFamilyCode, String>, JpaSpecificationExecutor<WlyySignFamilyCode> {
    @Query(" FROM WlyySignFamilyCode a WHERE a.orgCode =?1 ")
    WlyySignFamilyCode findByOrgCode(String hospital);
    @Query(" FROM WlyySignFamilyCode a WHERE a.orgCode =?1 and a.year=?2 ")
    WlyySignFamilyCode findByOrgCodeAndYear(String hospital, String year);
}

+ 15 - 5
src/main/java/com/yihu/wlyy/service/app/consult/ConsultService.java

@ -19,6 +19,7 @@ import com.yihu.wlyy.repository.ConsultTeamDao;
import com.yihu.wlyy.repository.DoctorDao;
import com.yihu.wlyy.repository.PatientDao;
import com.yihu.wlyy.service.BaseService;
import org.springframework.util.StringUtils;
public class ConsultService extends BaseService {
@ -68,7 +69,7 @@ public class ConsultService extends BaseService {
	 * @param pagesize 分页大小
	 * @return
	 */
	public Page<Object> findConsultRecordByPatient(String patient, long id, int pagesize) {
	public Page<Object> findConsultRecordByPatient(String patient, long id, int pagesize,String title) {
		if (id < 0) {
			id = 0;
		}
@ -79,10 +80,19 @@ public class ConsultService extends BaseService {
		Sort sort = new Sort(Direction.DESC, "id");
		// 分页信息
		PageRequest pageRequest = new PageRequest(0, pagesize, sort);
		if (id > 0) {
			return consultDao.findByPatient(patient, id, pageRequest);
		} else {
			return consultDao.findByPatient(patient, pageRequest);
		if(!StringUtils.isEmpty(title)){
			title="%"+title+"%";
			if (id > 0) {
				return consultDao.findByPatient(patient,title, id, pageRequest);
			} else {
				return consultDao.findByPatient(patient,title, pageRequest);
			}
		}else{
			if (id > 0) {
				return consultDao.findByPatient(patient, id, pageRequest);
			} else {
				return consultDao.findByPatient(patient, pageRequest);
			}
		}
	}

+ 60 - 11
src/main/java/com/yihu/wlyy/service/app/consult/ConsultTeamService.java

@ -76,12 +76,12 @@ public class ConsultTeamService extends ConsultService {
	/**
	 * 查詢醫生網絡諮詢列表
	 * @param type 咨询类型:1、咨询我的,2、公共的, 3、参与过的,4、已结束的
	 * @param type 咨询类型:1、咨询我的,2、公共的, 3、参与过的,4、已结束的 5 名医咨询 全部  6 名医咨询 进行中 7 名医咨询 已结束
	 * @param id
	 * @param pagesize 每页显示数,默认为10
	 * @return
	 */
	public Page<ConsultTeam> findByDoctor(String uid, int type, long id, int pagesize) {
	public Page<ConsultTeam> findByDoctor(String uid, int type, long id, int pagesize,String title) {
		if (id < 0) {
			id = 0;
		}
@ -104,10 +104,59 @@ public class ConsultTeamService extends ConsultService {
		case 4:
			// 已完成的
			return findByDoctorType4(uid, id, pagesize);
		case 5:
			// 5 名医咨询 全部
			return findByDoctorType5(uid, id, pagesize,title);
		case 6:
			//6 名医咨询 进行中
			return findByDoctorType6(uid, 0, id, pagesize,title);
		case 7:
			//7 名医咨询 已结束
			return findByDoctorType6(uid, 1, id, pagesize,title);
		}
		return null;
	}
	private Page<ConsultTeam> findByDoctorType5(String uid,  long id, int pagesize,String title) {
		Sort sort = new Sort(Direction.DESC, "id");
		// 分页信息
		PageRequest pageRequest = new PageRequest(0, pagesize, sort);
		if(StringUtils.isNoneEmpty(title)){
			title="%"+title+"%";
			if (id > 0) {
				return consultTeamDao.findFamousDoctorAllList(uid, id,title, pageRequest);
			} else {
				return consultTeamDao.findFamousDoctorAllList(uid,title, pageRequest);
			}
		}else{
			if (id > 0) {
				return consultTeamDao.findFamousDoctorAllList(uid, id, pageRequest);
			} else {
				return consultTeamDao.findFamousDoctorAllList(uid, pageRequest);
			}
		}
	}
	private Page<ConsultTeam> findByDoctorType6(String uid, int type, long id, int pagesize,String title) {
		// 排序
		Sort sort = new Sort(Direction.DESC, "id");
		// 分页信息
		PageRequest pageRequest = new PageRequest(0, pagesize, sort);
		if(StringUtils.isNoneEmpty(title)){
			title="%"+title+"%";
			if (id > 0) {
				return consultTeamDao.findFamousDoctorDoingList(uid, id,title,type, pageRequest);
			} else {
				return consultTeamDao.findFamousDoctorDoingList(uid, title,type,pageRequest);
			}
		}else{
			if (id > 0) {
				return consultTeamDao.findFamousDoctorDoingList(uid, id,type, pageRequest);
			} else {
				return consultTeamDao.findFamousDoctorDoingList(uid,type, pageRequest);
			}
		}
	}
	/**
	 * 查询全部咨询记录
	 * @param uid
@ -652,6 +701,15 @@ public class ConsultTeamService extends ConsultService {
		return consultTeamLogDao.findOne(logId);
	}
	public boolean isExistFamousConsult(String uid) {
		ConsultTeam consultTeam= consultTeamDao.findFamousConsultByPatient(uid);
		if(consultTeam!=null){
			return true;
		}else{
			return false;
		}
	}
	public void addFamousTeamConsult(ConsultTeam ct, String uid) throws Exception{
		// 设置患者信息
		ct.setPatient(uid);
@ -691,13 +749,4 @@ public class ConsultTeamService extends ConsultService {
		// 添加医生咨询日志
		addLogs(ct);
	}
	public boolean isExistFamousConsult(String uid) {
		ConsultTeam consultTeam= consultTeamDao.findFamousConsultByPatient(uid);
		if(consultTeam!=null){
			return true;
		}else{
			return false;
		}
	}
}

+ 3 - 0
src/main/java/com/yihu/wlyy/service/app/family/FamilyService.java

@ -204,6 +204,9 @@ public class FamilyService {
                    patientTemp.setPoints(0);
                    patientTemp.setRecordAmount(0);
                    patientDao.save(patientTemp);
                    jo.put("code",patientTemp.getCode());
                }else{
                    jo.put("code",patient.getCode());
                }
            }
        }

+ 174 - 54
src/main/java/com/yihu/wlyy/service/app/scheduling/DoctorWorkTimeService.java

@ -3,9 +3,11 @@ package com.yihu.wlyy.service.app.scheduling;
import com.yihu.wlyy.entity.doctor.Doctor;
import com.yihu.wlyy.entity.WlyyDoctorWorkTime;
import com.yihu.wlyy.entity.WlyyDoctorWorkWeek;
import com.yihu.wlyy.entity.doctor.DoctorFamousConsultTimesRemain;
import com.yihu.wlyy.repository.DoctorDao;
import com.yihu.wlyy.repository.DoctorWorkTimeDao;
import com.yihu.wlyy.repository.DoctorWorkWeekDao;
import com.yihu.wlyy.repository.FamousDoctorTimesRemainDao;
import com.yihu.wlyy.service.BaseService;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
@ -14,11 +16,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * 医生工作排班
 *
 * <p>
 * Created by lyr on 2016/08/19.
 */
@Service
@ -31,6 +34,8 @@ public class DoctorWorkTimeService extends BaseService {
    private DoctorWorkWeekDao doctorWorkWeekDao;
    @Autowired
    private DoctorDao doctorDao;
    @Autowired
    private FamousDoctorTimesRemainDao timesRemainDao;
    /**
     * 查询医生工作时间列表
@ -38,13 +43,13 @@ public class DoctorWorkTimeService extends BaseService {
     * @param doctor 医生标识
     * @return
     */
    public JSONObject findDoctorWorkTime(String doctor){
    public JSONObject findDoctorWorkTime(String doctor) throws Exception {
        JSONObject result = new JSONObject();
        WlyyDoctorWorkTime workTime = doctorWorkTimeDao.findDoctorWorkTime(doctor);
        List<WlyyDoctorWorkWeek> workWeekList = doctorWorkWeekDao.findDoctorWorkWeeks(doctor);
        result.put("workTime",workTime != null ? new JSONObject(workTime): "");
        result.put("workWeeks",workWeekList != null ? new JSONArray(workWeekList): "");
        result.put("workTime", workTime != null ? new JSONObject(workTime) : "");
        result.put("workWeeks", workWeekList != null ? new JSONArray(workWeekList) : "");
        return result;
    }
@ -53,16 +58,16 @@ public class DoctorWorkTimeService extends BaseService {
     * 查询医生某天工作时间
     *
     * @param doctor 医生标识
     * @param week 某天
     * @param week   某天
     * @return
     */
    public JSONObject findDoctorWeekWorkTime(String doctor,String week){
    public JSONObject findDoctorWeekWorkTime(String doctor, String week) throws Exception {
        JSONObject result = new JSONObject();
        WlyyDoctorWorkTime workTime = doctorWorkTimeDao.findDoctorWorkTime(doctor);
        WlyyDoctorWorkWeek workWeek = doctorWorkWeekDao.findDoctorWorkWeek(doctor,week);
        WlyyDoctorWorkWeek workWeek = doctorWorkWeekDao.findDoctorWorkWeek(doctor, week);
        result.put("workTime",workTime != null ? new JSONObject(workTime): "");
        result.put("workWeek",workWeek != null ? new JSONObject(workWeek) : "");
        result.put("workTime", workTime != null ? new JSONObject(workTime) : "");
        result.put("workWeek", workWeek != null ? new JSONObject(workWeek) : "");
        return result;
    }
@ -71,16 +76,31 @@ public class DoctorWorkTimeService extends BaseService {
     * 查询医生某天工作时间
     *
     * @param doctor 医生标识
     * @param week 某天
     * @param week   某天
     * @return
     */
    public Map<String,Object> findDoctorWeekWork(String doctor,String week){
        Map<String,Object> map = new HashMap<>();
    public Map<String, Object> findDoctorWeekWork(String doctor, String week) throws Exception {
        Map<String, Object> map = new HashMap<>();
        Doctor doc = doctorDao.findByCode(doctor);
        if (doc == null) {
            throw new Exception("doctor-worktime-error:doctor not exist");
        }
        WlyyDoctorWorkTime workTime = doctorWorkTimeDao.findDoctorWorkTime(doctor);
        WlyyDoctorWorkWeek workWeek = doctorWorkWeekDao.findDoctorWorkWeek(doctor,week);
        WlyyDoctorWorkWeek workWeek = doctorWorkWeekDao.findDoctorWorkWeek(doctor, week);
        map.put("workTime", workTime);
        map.put("workWeek", workWeek);
        if (doc.getIsFamous() == 1) {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            DoctorFamousConsultTimesRemain timesRemain = timesRemainDao.findByDoctorAndConsultDate(doctor, df.format(new Date()));
        map.put("workTime",workTime);
        map.put("workWeek",workWeek);
            if (timesRemain == null) {
                map.put("famousDoctorTimesRemain",workTime.getFamousConsultTimes());
            } else {
                map.put("famousDoctorTimesRemain",timesRemain.getTimesRemain());
            }
        }
        return map;
    }
@ -88,11 +108,11 @@ public class DoctorWorkTimeService extends BaseService {
    /**
     * 保存医生工作排班
     *
     * @param doctor 医生
     * @param doctor         医生
     * @param workScheduling 排班配置
     * @return
     */
    public boolean saveDoctorWorkTime(String doctor,JSONObject workScheduling) throws Exception {
    public boolean saveDoctorWorkTime(String doctor, JSONObject workScheduling) throws Exception {
        JSONObject workTime = workScheduling.has("workTime") ? workScheduling.getJSONObject("workTime") : null;
        JSONArray workTWeeks = workScheduling.has("workWeeks") ? workScheduling.getJSONArray("workWeeks") : null;
@ -100,16 +120,17 @@ public class DoctorWorkTimeService extends BaseService {
        WlyyDoctorWorkTime doctorWorkTime = doctorWorkTimeDao.findDoctorWorkTime(doctor);
        Doctor doc = doctorDao.findByCode(doctor);
        if(StringUtils.isEmpty(doctor) || doc == null){
        if (StringUtils.isEmpty(doctor) || doc == null) {
            throw new Exception("找不到对应医生!");
        }
        if(workTime == null){
        if (workTime == null) {
            throw new Exception("工作时间段不能为空!");
        }
        if(doctorWorkTime == null){
        if (doctorWorkTime == null) {
            doctorWorkTime = new WlyyDoctorWorkTime();
            doctorWorkTime.setReceiveConsult("1");
            doctorWorkTime.setFamousConsultTimes(0);
        }
        // 医生
@ -135,10 +156,10 @@ public class DoctorWorkTimeService extends BaseService {
        doctorWorkWeekDao.deleteByDoctor(doctor);
        // 排班保存
        if(workTWeeks != null){
        if (workTWeeks != null) {
            List<WlyyDoctorWorkWeek> weeks = new ArrayList<>();
            for(int i = 0; i < workTWeeks.length(); i++){
            for (int i = 0; i < workTWeeks.length(); i++) {
                JSONObject object = workTWeeks.getJSONObject(i);
                WlyyDoctorWorkWeek week = new WlyyDoctorWorkWeek();
@ -162,11 +183,11 @@ public class DoctorWorkTimeService extends BaseService {
    /**
     * 医生设置是否接受咨询
     *
     * @param doctor 医生
     * @param doctor         医生
     * @param receiveConsult 是否接受咨询
     * @return
     */
    public boolean setDoctorReceiveConsult(String doctor,String receiveConsult) throws Exception {
    public boolean setDoctorReceiveConsult(String doctor, String receiveConsult) throws Exception {
        try {
            WlyyDoctorWorkTime workTime = doctorWorkTimeDao.findDoctorWorkTime(doctor);
@ -187,7 +208,7 @@ public class DoctorWorkTimeService extends BaseService {
            doctorWorkTimeDao.save(workTime);
            return true;
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
@ -196,33 +217,33 @@ public class DoctorWorkTimeService extends BaseService {
    /**
     * 医生是否在工作
     *
     * @param doctor
     * @param doctor 医生
     * @return
     */
    public JSONObject isDoctorWorking(String doctor){
    public JSONObject isDoctorWorking(String doctor) throws Exception {
        JSONObject json = new JSONObject();
        Calendar calendar = Calendar.getInstance();
        int week =  calendar.get(Calendar.DAY_OF_WEEK) - 1;
        int week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        if(week == 0){
        if (week == 0) {
            week = 7;
        }
        // 医生工作时间设置
        Map<String,Object> result = findDoctorWeekWork(doctor,String.valueOf(week));
        Map<String, Object> result = findDoctorWeekWork(doctor, String.valueOf(week));
        if(result.get("workTime") == null){
        if (result.get("workTime") == null) {
            // 医生未设置时,默认7*24小时工作
            json.put("status","1");
            json.put("msg","医生当前接受咨询");
        }else{
            WlyyDoctorWorkTime doctorWorkTime = (WlyyDoctorWorkTime)result.get("workTime");
            json.put("status", "1");
            json.put("msg", "医生当前接受咨询");
        } else {
            WlyyDoctorWorkTime doctorWorkTime = (WlyyDoctorWorkTime) result.get("workTime");
            if(doctorWorkTime.getReceiveConsult().equals("0")){
            if (doctorWorkTime.getReceiveConsult().equals("0")) {
                // 医生设置不接受咨询
                json.put("status","0");
                json.put("msg","医生不接受咨询");
            }else {
                json.put("status", "0");
                json.put("msg", "医生不接受咨询");
            } else {
                if (result.get("workWeek") != null) {
                    // 当前工作日已设置工作时间
                    int flag = 0;
@ -236,10 +257,10 @@ public class DoctorWorkTimeService extends BaseService {
                    if (workWeek.getMorning().equals("1")) {
                        String currentStart = workTime.getMorningBegin();
                        String currentEnd = workTime.getMorningEnd();
                        if(currentStart.length() == 4){
                        if (currentStart.length() == 4) {
                            currentStart = "0" + currentStart;
                        }
                        if(currentEnd.length() == 4){
                        if (currentEnd.length() == 4) {
                            currentEnd = "0" + currentEnd;
                        }
                        if (current.compareTo(currentStart) >= 0 &&
@ -251,10 +272,10 @@ public class DoctorWorkTimeService extends BaseService {
                    if (workWeek.getAfternoon().equals("1")) {
                        String currentStart = workTime.getAfternoonBegin();
                        String currentEnd = workTime.getAfternoonEnd();
                        if(currentStart.length() == 4){
                        if (currentStart.length() == 4) {
                            currentStart = "0" + currentStart;
                        }
                        if(currentEnd.length() == 4){
                        if (currentEnd.length() == 4) {
                            currentEnd = "0" + currentEnd;
                        }
                        if (current.compareTo(currentStart) >= 0 &&
@ -266,10 +287,10 @@ public class DoctorWorkTimeService extends BaseService {
                    if (workWeek.getNight().equals("1")) {
                        String currentStart = workTime.getNightBegin();
                        String currentEnd = workTime.getNightEnd();
                        if(currentStart.length() == 4){
                        if (currentStart.length() == 4) {
                            currentStart = "0" + currentStart;
                        }
                        if(currentEnd.length() == 4){
                        if (currentEnd.length() == 4) {
                            currentEnd = "0" + currentEnd;
                        }
                        if (current.compareTo(currentStart) >= 0 &&
@ -278,20 +299,119 @@ public class DoctorWorkTimeService extends BaseService {
                        }
                    }
                    if(flag == 1){
                        json.put("status","1");
                        json.put("msg","医生当前接受咨询");
                    }else{
                        json.put("status","2");
                        json.put("msg","医生当前不在工作时间");
                    if (flag == 1) {
                        json.put("status", "1");
                        json.put("msg", "医生当前接受咨询");
                    } else {
                        json.put("status", "2");
                        json.put("msg", "医生当前不在工作时间");
                    }
                }else{
                    json.put("status","2");
                    json.put("msg","医生当前不在工作时间");
                } else {
                    json.put("status", "2");
                    json.put("msg", "医生当前不在工作时间");
                }
            }
        }
        return json;
    }
    /**
     * 设置名医咨询次数
     *
     * @param doctor 医生
     * @return
     */
    public boolean setFamousDoctorConsultTimes(String doctor, int consultTimes) {
        try {
            WlyyDoctorWorkTime workTime = doctorWorkTimeDao.findDoctorWorkTime(doctor);
            // 未有设置,则新建医生设置
            if (workTime == null) {
                Doctor doc = doctorDao.findByCode(doctor);
                if (doc == null) {
                    throw new Exception("doctor can not find");
                }
                workTime = new WlyyDoctorWorkTime();
                workTime.setDoctor(doctor);
                workTime.setDoctorName(doc.getName());
            }
            // 设置名医咨询次数
            workTime.setFamousConsultTimes(consultTimes);
            workTime.setCzrq(new Date());
            doctorWorkTimeDao.save(workTime);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    /**
     * 名医咨询当前剩余次数查询
     *
     * @param doctor 医生
     * @return
     */
    public int getDoctorConsultTimesRemain(String doctor) {
        int result = 0;
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        DoctorFamousConsultTimesRemain timesRemain = timesRemainDao.findByDoctorAndConsultDate(doctor, df.format(new Date()));
        if (timesRemain != null) {
            result = timesRemain.getTimesRemain();
        } else {
            WlyyDoctorWorkTime workTime = doctorWorkTimeDao.findDoctorWorkTime(doctor);
            if (workTime != null) {
                result = workTime.getFamousConsultTimes();
            }
        }
        return result;
    }
    /**
     * 名医咨询当前剩余次数减一
     *
     * @param doctor 医生
     * @return
     */
    public boolean setDoctorCurrentConsultTimesRemain(String doctor) {
        try {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            DoctorFamousConsultTimesRemain timesRemain = timesRemainDao.findByDoctorAndConsultDate(doctor, df.format(new Date()));
            if (timesRemain != null) {
                int times = timesRemain.getTimesRemain();
                if (times < 1) {
                    throw new Exception("consult-times-error:doctor does not have not consult times remain");
                }
                timesRemain.setTimesRemain(times - 1);
                timesRemainDao.save(timesRemain);
            } else {
                DoctorFamousConsultTimesRemain timesRemainNew = new DoctorFamousConsultTimesRemain();
                WlyyDoctorWorkTime workTime = doctorWorkTimeDao.findDoctorWorkTime(doctor);
                if (workTime == null || workTime.getFamousConsultTimes() < 1) {
                    throw new Exception("consult-times-error:doctor does not have consult times setting");
                }
                timesRemainNew.setDoctor(doctor);
                timesRemainNew.setConsultDate(df.format(new Date()));
                timesRemainNew.setTimesRemain(workTime.getFamousConsultTimes() - 1);
                timesRemainDao.save(timesRemainNew);
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}

+ 10 - 7
src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java

@ -898,7 +898,7 @@ public class FamilyContractService extends BaseService {
            json.put("doctorName", sf.getDoctorName());
            json.put("date", DateUtil.dateToStrShort(sf.getBegin()));
            json.put("content", content);
            json.put("remark", "您好,您成功签约家庭医生");
            json.put("remark", ""); //您好,您成功签约家庭医生
            // 添加到发送队列
            PushMsgTask.getInstance().putWxMsg(access_token, 1, sf.getOpenid(), sf.getName(), json);
        }
@ -1179,7 +1179,7 @@ public class FamilyContractService extends BaseService {
            json.put("doctorName", sf.getDoctorName());
            json.put("date", DateUtil.dateToStrShort(sf.getBegin()));
            json.put("content", content);
            json.put("remark", "您好,您成功签约家庭医生");
            json.put("remark", ""); //您好,您成功签约家庭医生
            // 添加到发送队列
            PushMsgTask.getInstance().putWxMsg(access_token, 1, sf.getOpenid(), sf.getName(), json);
        } else if (type == 2) {
@ -1206,7 +1206,7 @@ public class FamilyContractService extends BaseService {
     * @param reason  解约原因
     * @return
     */
    public int handleSurrender(String access_token, long msgid, String patient, int type, String reason) {
    public int handleSurrender(String access_token, long msgid, String patient, int type, String reason) throws Exception {
        if (type != 1 && type != 2) {
            return -1;
        }
@ -1221,6 +1221,10 @@ public class FamilyContractService extends BaseService {
            message.setOver("0");
        }
        if (type == 1) {
            // 设置家庭签约疾病无效
            if(!patientDiseaseService.updatePatientDisease(patient,"")){
                throw new Exception("patient's disease update failed");
            }
            // 将签约状态改为已解约
            sf.setReason(reason);
            sf.setStatus(-3);
@ -1234,8 +1238,6 @@ public class FamilyContractService extends BaseService {
            doctorPatientGroupInfoDao.deleteByPatient(patient);
            //结束患者家庭签约咨询
            consultTeamDao.updateStatusByPatient(patient);
            // 设置家庭签约疾病无效
            patientDiseaseService.updatePatientDisease(patient,"");
            // 推送消息消息给微信端
            JSONObject json = new JSONObject();
@ -1338,7 +1340,7 @@ public class FamilyContractService extends BaseService {
        String year = DateUtil.getStringDate(DateUtil.YY);
        Hospital hospital1 = hospitalDao.findByCode(hospital);
        Integer amount=0;
        WlyySignFamilyCode wlyySignFamilyCode = wlyySignFamilyCodeDao.findByOrgCode(hospital);
        WlyySignFamilyCode wlyySignFamilyCode = wlyySignFamilyCodeDao.findByOrgCodeAndYear(hospital,year);
        if(wlyySignFamilyCode!=null){
            amount=wlyySignFamilyCode.getSequence()+1;
            wlyySignFamilyCode.setSequence(amount);
@ -1350,10 +1352,11 @@ public class FamilyContractService extends BaseService {
            wlyySignFamilyCodeTemp.setModifyTime(new Date());
            wlyySignFamilyCodeTemp.setOrgCode(hospital1.getCode());
            wlyySignFamilyCodeTemp.setOrgName(hospital1.getName());
            wlyySignFamilyCodeTemp.setYear(year);
            wlyySignFamilyCodeTemp.setSequence(1);
            wlyySignFamilyCodeDao.save(wlyySignFamilyCodeTemp);
        }
        return year + hospital1.getRoadCode() + hospital1.getCenterSite() + StringUtils.leftPad(String.valueOf(amount + 1), 6, "0");
        return year + hospital1.getRoadCode() + hospital1.getCenterSite() + "Y"+StringUtils.leftPad(String.valueOf(amount + 1), 5, "0");
    }
    public int countAmountSigned2(String uid) {

+ 37 - 0
src/main/java/com/yihu/wlyy/service/common/account/DoctorService.java

@ -5,10 +5,17 @@
 *******************************************************************************/
package com.yihu.wlyy.service.common.account;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.persistence.DynamicSpecifications;
import org.springside.modules.persistence.SearchFilter;
import org.springside.modules.utils.Clock;
import com.yihu.wlyy.entity.doctor.Doctor;
@ -16,6 +23,10 @@ import com.yihu.wlyy.entity.Token;
import com.yihu.wlyy.repository.DoctorDao;
import com.yihu.wlyy.util.EncodesUtil;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 医生基本信息类.
 *
@ -66,5 +77,31 @@ public class DoctorService extends TokenService {
	}
	public Page<Doctor> famousDoctorList(String name, long id, int pagesize) {
		if (pagesize <= 0) {
			pagesize = 10;
		}
		// 排序
		Sort sort = new Sort(Sort.Direction.ASC, "id");
		// 分页信息
		PageRequest pageRequest = new PageRequest(0, pagesize, sort);
		// 设置查询条件
		Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
		if (StringUtils.isNoneEmpty(name)) {
			filters.put("name", new SearchFilter("name", SearchFilter.Operator.LIKE, "%"+name+"%"));
		}
		if (id > 0) {
			filters.put("id", new SearchFilter("id", SearchFilter.Operator.GT, id));
		}
		//设置过滤条件是名医
		//filters.put("level", new SearchFilter("level", SearchFilter.Operator.EQ, level));
		//设置过滤条件是次数大于零
		//filters.put("level", new SearchFilter("level", SearchFilter.Operator.EQ, level));
		// 未作废
		filters.put("status", new SearchFilter("status", SearchFilter.Operator.EQ, 1));
		Specification<Doctor> spec = DynamicSpecifications.bySearchFilter(filters.values(), Doctor.class);
		return doctorDao.findAll(spec, pageRequest);
	}
}

+ 3 - 3
src/main/java/com/yihu/wlyy/web/doctor/consult/DoctorConsultController.java

@ -46,16 +46,16 @@ public class DoctorConsultController extends WeixinBaseController {
	/**
	 * 三师咨询列表查询
	 * @param type 咨询类型:0、全部,1、咨询我的,2、公共的, 3、参与过的,4、已结束的
	 * @param type 咨询类型:0、全部,1、咨询我的,2、公共的, 3、参与过的,4、已结束的  5 名医咨询 全部  6 名医咨询 进行中 7 名医咨询 已结束
	 * @param id
	 * @param pagesize 每页显示数,默认为10
	 * @return
	 */
	@RequestMapping(value = "list")
	@ResponseBody
	public String list(int type, int id, int pagesize, @RequestParam(required = false) String patient) {
	public String list(int type, int id, int pagesize, @RequestParam(required = false) String patient, @RequestParam(required = false) String title) {
		try {
			Page<ConsultTeam> list = consultTeamService.findByDoctor(getUID(), type, id, pagesize);
			Page<ConsultTeam> list = consultTeamService.findByDoctor(getUID(), type, id, pagesize,title);
			JSONArray jsonArray = new JSONArray();
			for (ConsultTeam consult : list) {
				if (consult == null) {

+ 33 - 1
src/main/java/com/yihu/wlyy/web/doctor/device/DoctorDeviceController.java

@ -79,7 +79,7 @@ public class DoctorDeviceController extends BaseController {
	@RequestMapping(value = "DeletePatientDevice",method = RequestMethod.DELETE)
	@ResponseBody
	public String delete(@ApiParam(name="id",value="删除设备关联ID")
						  @RequestParam(value="id",required = true) String id) {
						 @RequestParam(value="id",required = true) String id) {
		try {
			PatientDevice pd = patientDeviceService.findById(id);
			if(pd!=null)
@ -98,4 +98,36 @@ public class DoctorDeviceController extends BaseController {
			return invalidUserException(ex, -1,ex.getMessage());
		}
	}
	@ApiOperation("获取患者设备信息")
	@RequestMapping(value = "PatientDeviceInfo",method = RequestMethod.GET)
	@ResponseBody
	public String getPatientDeviceInfo(@ApiParam(name="id",value="患者设备ID",defaultValue = "34")
									   @RequestParam(value="id",required = true) String id) {
		try {
			PatientDevice device = patientDeviceService.findById(id);
			return write(200, "查询成功", "data", device);
		} catch (Exception ex) {
			return invalidUserException(ex, -1, ex.getMessage());
		}
	}
	@ApiOperation("通过sn码获取设备绑定情况")
	@RequestMapping(value = "PatientDeviceIdcard",method = RequestMethod.GET)
	@ResponseBody
	public String getDeviceUser(
			@ApiParam(name="patient",value="患者code",defaultValue = "915cca0a-5b1d-11e6-8344-fa163e8aee56")
			@RequestParam(value="patient",required = true) String patient,
			@ApiParam(name="type",value="设备类型",defaultValue = "1")
			@RequestParam(value="type",required = true) String type,
			@ApiParam(name="device_sn",value="设备SN码",defaultValue = "15L000002")
			@RequestParam(value="device_sn",required = true) String deviceSn) {
		try {
			List<Map<String,String>> list = patientDeviceService.getDeviceUser(patient,deviceSn,type);
			return write(200, "获取设备绑定信息成功!", "data",list);
		} catch (Exception ex) {
			return invalidUserException(ex, -1, ex.getMessage());
		}
	}
}

+ 73 - 13
src/main/java/com/yihu/wlyy/web/doctor/scheduling/DoctorWorkTimeController.java

@ -1,6 +1,8 @@
package com.yihu.wlyy.web.doctor.scheduling;
import com.yihu.wlyy.entity.WlyyDoctorWorkTime;
import com.yihu.wlyy.entity.doctor.Doctor;
import com.yihu.wlyy.service.app.account.DoctorInfoService;
import com.yihu.wlyy.service.app.scheduling.DoctorWorkTimeService;
import com.yihu.wlyy.web.BaseController;
import org.apache.commons.lang3.StringUtils;
@ -11,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import java.util.Calendar;
import java.util.List;
@ -22,6 +25,8 @@ import java.util.List;
@RequestMapping(value = "/doctor/work_scheduling")
public class DoctorWorkTimeController extends BaseController {
    @Autowired
    private DoctorInfoService doctorInfoService;
    @Autowired
    private DoctorWorkTimeService doctorWorkTimeService;
@ -125,8 +130,8 @@ public class DoctorWorkTimeController extends BaseController {
    @ResponseBody
    public String setDoctorReceiveConsult(String receiveConsult) {
        try {
            if(StringUtils.isEmpty(receiveConsult)){
                return error(-1,"是否接受咨询参数不能为空");
            if (StringUtils.isEmpty(receiveConsult)) {
                return error(-1, "是否接受咨询参数不能为空");
            }
            if (doctorWorkTimeService.setDoctorReceiveConsult(getUID(), receiveConsult)) {
                return error(200, "设置成功");
@ -139,6 +144,36 @@ public class DoctorWorkTimeController extends BaseController {
        }
    }
    /**
     * 设置名医咨询次数
     *
     * @param consultTimes 名医咨询次数
     * @return
     */
    @RequestMapping(value = "/consult_times_setting")
    @ResponseBody
    public String setFamousDoctorConsultTime(int consultTimes) {
        try {
            Doctor doc = doctorInfoService.findDoctorByCode(getUID());
            if (doc == null) {
                return error(-1,"医生不存在");
            }
            if (doc.getIsFamous() != 1) {
                return error(-1,"医生不是名医,无法设置名医咨询次数");
            }
            if (doctorWorkTimeService.setFamousDoctorConsultTimes(getUID(), consultTimes)) {
                return error(200, "设置成功");
            } else {
                return error(-1, "设置失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "设置失败");
        }
    }
    /**
     * 查询某个医生是否在工作时间
     *
@ -149,8 +184,8 @@ public class DoctorWorkTimeController extends BaseController {
    @ResponseBody
    public String isDoctorWorking(String doctor) {
        try {
            if(StringUtils.isEmpty(doctor)){
                return error(-1,"参数不能为空");
            if (StringUtils.isEmpty(doctor)) {
                return error(-1, "参数不能为空");
            }
            JSONObject result = doctorWorkTimeService.isDoctorWorking(doctor);
            return write(200, "查询成功", "data", result);
@ -168,13 +203,13 @@ public class DoctorWorkTimeController extends BaseController {
     */
    @RequestMapping(value = "/doctor_worktime")
    @ResponseBody
    public String getDoctorWorkTime(String doctor){
        try{
    public String getDoctorWorkTime(String doctor) {
        try {
            JSONObject json = doctorWorkTimeService.findDoctorWorkTime(doctor);
            return write(200,"查询成功","data",json);
        }catch(Exception e){
            return write(200, "查询成功", "data", json);
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1,"查询失败");
            return error(-1, "查询失败");
        }
    }
@ -182,15 +217,40 @@ public class DoctorWorkTimeController extends BaseController {
     * 查询某个医生某天的工作时间
     *
     * @param doctor 医生
     * @param week 周几
     * @param week   周几
     * @return
     */
    @RequestMapping(value = "/doctor_week_worktime")
    @ResponseBody
    public String getDoctorWeekWorkTime(String doctor,String week){
    public String getDoctorWeekWorkTime(String doctor, String week) {
        try {
            JSONObject json = doctorWorkTimeService.findDoctorWeekWorkTime(doctor, week);
            return write(200, "查询成功", "data", json);
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "查询失败");
        }
    }
    /**
     * 名医咨询剩余次数查询
     *
     * @return
     */
    @RequestMapping(value = "/consult_times_remain")
    @ResponseBody
    public String famousDoctorTimesRemain(){
        try{
            JSONObject json = doctorWorkTimeService.findDoctorWeekWorkTime(doctor,week);
            return write(200,"查询成功","data",json);
            Doctor doc = doctorInfoService.findDoctorByCode(getUID());
            if (doc == null) {
                return error(-1,"医生不存在");
            }
            if (doc.getIsFamous() != 1) {
                return error(-1,"医生不是名医,没有名医咨询次数");
            }
            int result = doctorWorkTimeService.getDoctorConsultTimesRemain(getUID());
            return write(200,"查询成功","data",result);
        }catch (Exception e){
            e.printStackTrace();
            return error(-1,"查询失败");

+ 144 - 92
src/main/java/com/yihu/wlyy/web/patient/consult/ConsultController.java

@ -53,16 +53,20 @@ public class ConsultController extends WeixinBaseController {
	/**
	 * 患者咨询记录查询
	 * @param title 咨询标题
	 * @param id
	 * @param pagesize 分页大小
	 * @return
	 */
	@RequestMapping(value = "records")
	@ResponseBody
	public String consultRecords(long id, int pagesize) {
	public String consultRecords(
			@RequestParam(required = false) String  title,
			long id,
			int pagesize) {
		try {
			JSONArray array = new JSONArray();
			Page<Object> data = consultTeamService.findConsultRecordByPatient(getUID(), id, pagesize);
			Page<Object> data = consultTeamService.findConsultRecordByPatient(getUID(), id, pagesize,title);
			if (data != null) {
				for (Object consult : data.getContent()) {
					if (consult == null) {
@ -132,89 +136,6 @@ public class ConsultController extends WeixinBaseController {
		}
	}
	/**
	 * 验证医生是否在工作时间
	 *
	 * @param doctor
	 * @return
	 */
	@RequestMapping(value = "/doctor_isworking")
	@ResponseBody
    public String isDoctorWorking(@RequestParam(required = true)String doctor){
    	try{
    		int flag = 0;
			Calendar calendar = Calendar.getInstance();
            int week =  calendar.get(Calendar.DAY_OF_WEEK) - 1;
            if(week == 0){
            	week = 7;
			}
			Map<String,Object> result = doctorWorkTimeService.findDoctorWeekWork(doctor,String.valueOf(week));
			if(result.get("workTime") == null){
				flag = 1; // 未设置时间段则默认为7*24小时
			}else{
				if(result.get("workWeek") != null){
					WlyyDoctorWorkTime workTime = (WlyyDoctorWorkTime)result.get("workTime");
					WlyyDoctorWorkWeek workWeek = (WlyyDoctorWorkWeek)result.get("workWeek");
					int hour = calendar.get(Calendar.HOUR_OF_DAY);
					int minute = calendar.get(Calendar.MINUTE);
					String current = (hour < 10?("0" + hour):hour) + ":" + (hour < 10?("0" + minute):minute);
                    // 早上
                    if (workWeek.getMorning().equals("1")) {
                        String currentStart = workTime.getMorningBegin();
                        String currentEnd = workTime.getMorningEnd();
                        if(currentStart.length() == 4){
                            currentStart = "0" + currentStart;
                        }
                        if(currentEnd.length() == 4){
                            currentEnd = "0" + currentEnd;
                        }
                        if (current.compareTo(currentStart) >= 0 &&
                                current.compareTo(currentEnd) < 0) {
                            flag = 1;
                        }
                    }
                    // 下午
                    if (workWeek.getAfternoon().equals("1")) {
                        String currentStart = workTime.getAfternoonBegin();
                        String currentEnd = workTime.getAfternoonEnd();
                        if(currentStart.length() == 4){
                            currentStart = "0" + currentStart;
                        }
                        if(currentEnd.length() == 4){
                            currentEnd = "0" + currentEnd;
                        }
                        if (current.compareTo(currentStart) >= 0 &&
                                current.compareTo(currentEnd) < 0) {
                            flag = 1;
                        }
                    }
                    // 晚上
                    if (workWeek.getNight().equals("1")) {
                        String currentStart = workTime.getNightBegin();
                        String currentEnd = workTime.getNightEnd();
                        if(currentStart.length() == 4){
                            currentStart = "0" + currentStart;
                        }
                        if(currentEnd.length() == 4){
                            currentEnd = "0" + currentEnd;
                        }
                        if (current.compareTo(currentStart) >= 0 &&
                                current.compareTo(currentEnd) < 0) {
                            flag = 1;
                        }
                    }
				}
			}
    		return write(200,"查询成功","data",flag);
		}catch (Exception e){
			e.printStackTrace();
			return error(-1,"查询失败!");
		}
	}
    /**
     * 医生是否在工作
     *
@ -226,13 +147,32 @@ public class ConsultController extends WeixinBaseController {
	public String isDoctorAtWorking(String doctor){
		try{
            JSONObject result = doctorWorkTimeService.isDoctorWorking(doctor);
            return write(200,"查询成功","data",result);
            return write(200,result.getString("msg"),"data",result.getString("status"));
		}catch (Exception e){
            e.printStackTrace();
			return error(-1,"查询失败");
		}
	}
	/**
	 * 名医咨询剩余次数查询
	 *
	 * @param doctor
	 * @return
	 */
	@RequestMapping(value = "/consult_times_remain")
	@ResponseBody
	public String famousDoctorTimesRemain(String doctor){
		try{
			int result = doctorWorkTimeService.getDoctorConsultTimesRemain(doctor);
			return write(200,"查询成功","data",result);
		}catch (Exception e){
			e.printStackTrace();
			return error(-1,"查询失败");
		}
	}
	/**
	 * 获取未完成咨询
	 *
@ -291,7 +231,7 @@ public class ConsultController extends WeixinBaseController {
				voice = CommonUtil.copyTempVoice(voice);
			}
			ConsultTeam consult = new ConsultTeam();
			// 设置咨询类型:1三师咨询,2家庭医生咨询
			// 设置咨询类型:1三师咨询,2家庭医生咨询  6.名医咨询
			consult.setType(type);
			// 设置发病时间
			consult.setWhen(when);
@ -319,7 +259,12 @@ public class ConsultController extends WeixinBaseController {
				DoctorStatisticsTask.getInstance(doctorStatisticsService).put(consult.getDoctor(), 1, 1, 0);
			}
			// 推送消息给医生
			PushMsgTask.getInstance().put(consult.getDoctor(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM.D_CT_01.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM.指定咨询.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM.您有新的指定咨询.name(), consult.getConsult());
			if(type==6){
				// 推送消息给医生
				PushMsgTask.getInstance().put(consult.getDoctor(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_FAMOUS_CONSULT_TEAM.D_CT_01.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_FAMOUS_CONSULT_TEAM.名医咨询.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_FAMOUS_CONSULT_TEAM.您有新的名医咨询.name(), consult.getConsult());
			}else{
				PushMsgTask.getInstance().put(consult.getDoctor(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM.D_CT_01.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM.指定咨询.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM.您有新的指定咨询.name(), consult.getConsult());
			}
			return success("提交成功");
		} catch (Exception ex) {
			error(ex);
@ -345,6 +290,16 @@ public class ConsultController extends WeixinBaseController {
					  @RequestParam(required = false) String images,
					  @RequestParam(required = false) String voice) {
		try {
			//判断医生是否是在工作时间
			JSONObject jo=doctorWorkTimeService.isDoctorWorking(doctorCode);
			if(!jo.get("status").equals("1")){
				return error(-1, jo.get("msg").toString());
			}
			//判断医生是否剩下咨询次数
			int result = doctorWorkTimeService.getDoctorConsultTimesRemain(doctorCode);
			if(result==0){
				return error(-1, "没有次数");
			}
			if (StringUtils.isEmpty(images)) {
				images = fetchWxImages();
			}
@ -363,8 +318,8 @@ public class ConsultController extends WeixinBaseController {
				return error(-1, "已经存在名医咨询!");
			}
			ConsultTeam consult = new ConsultTeam();
			// 设置咨询类型:1三师咨询,2家庭医生咨询 3.名医咨询
			consult.setType(3);
			// 设置咨询类型:1三师咨询,2家庭医生咨询 6.名医咨询
			consult.setType(6);
			// 设置发病时间
			consult.setWhen(when);
			// 设置主要症状
@ -376,7 +331,8 @@ public class ConsultController extends WeixinBaseController {
			consult.setDoctor(doctorCode);//设置专科医生
			// 保存到数据库
			consultTeamService.addFamousTeamConsult(consult, getUID());
			//名医咨询次数减一
			doctorWorkTimeService.setDoctorCurrentConsultTimesRemain(doctorCode);
			// 推送消息给医生
			PushMsgTask.getInstance().put(consult.getDoctor(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_FAMOUS_CONSULT_TEAM.D_CT_01.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_FAMOUS_CONSULT_TEAM.名医咨询.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_FAMOUS_CONSULT_TEAM.您有新的名医咨询.name(), consult.getConsult());
			return success("提交成功");
@ -386,7 +342,104 @@ public class ConsultController extends WeixinBaseController {
		}
	}
	/**
	 * 名医列表
	 * @return
     */
	@RequestMapping(value = "famousDoctorList")
	@ResponseBody
	public String famousDoctorList(
									@RequestParam(required = false) String name,
									long id,
									int pagesize) {
		try {
			JSONArray array = new JSONArray();
			Page<Doctor>list = doctorService.famousDoctorList(name, id, pagesize);
			if (list != null) {
				for (Doctor doctor : list) {
					if (doctor == null) {
						continue;
					}
					JSONObject json = new JSONObject();
					json.put("id", doctor.getId());
					// 医生标识
					json.put("code", doctor.getCode());
					// 医生姓名
					json.put("name", doctor.getName());
					// 所在医院名称
					json.put("hospital", doctor.getHospital());
					// 所在医院名称
					json.put("hospital_name", doctor.getHosptialName());
					// 科室名称
					json.put("dept_name", (doctor.getDeptName() == null ||
							StringUtils.isEmpty(doctor.getDeptName().toString())) ? " " : doctor.getDeptName());
					// 职称名称
					json.put("job_name", (doctor.getJobName() == null ||
							StringUtils.isEmpty(doctor.getJobName().toString())) ? " " : doctor.getJobName());
					// 头像
					json.put("photo", doctor.getPhoto());
					// 简介
					json.put("introduce", doctor.getIntroduce());
					// 专长
					json.put("expertise", doctor.getExpertise());
					// 剩余咨询次数
					json.put("num", doctorWorkTimeService.getDoctorConsultTimesRemain(doctor.getCode()));
					array.put(json);
				}
			}
			return write(200, "获取医院医生列表成功!", "list", array);
		} catch (Exception e) {
			error(e);
			return error(-1, "获取医院医生列表失败!");
		}
	}
	/**
	 * 名医主页
	 * @return
	 */
	@RequestMapping(value = "famousDoctorPage")
	@ResponseBody
	public String famousDoctorPage(
			 String doctorCode) {
		try {
			Doctor temp = doctorService.findDoctorByCode(doctorCode);
			if (temp != null) {
				JSONObject json = new JSONObject();
				// 设置医生手机号码
				json.put("mobile", temp.getMobile());
				// 设置医生标识
				json.put("code", temp.getCode());
				// 设置医生姓名
				json.put("name", temp.getName());
				// 设置医生头像
				json.put("photo", CommonUtil.getPhoneUrl(temp.getPhoto()));
				// 设置医生性别
				json.put("sex", temp.getSex());
				// 设置省名称
				json.put("provinceName", temp.getProvinceName());
				// 设置城市名称
				json.put("cityName", temp.getCityName());
				// 设置医院名称
				json.put("hospitalName", temp.getHosptialName());
				// 设置部门名称
				json.put("deptName", StringUtils.isNotEmpty(temp.getDeptName()) ? temp.getDeptName() : "");
				// 设置职称
				json.put("jobName", StringUtils.isNotEmpty(temp.getJobName()) ? temp.getJobName() : "");
				// 设置医生专长
				json.put("expertise", StringUtils.isNotEmpty(temp.getExpertise()) ? temp.getExpertise() : "");
				// 设置医生简介
				json.put("introduce", StringUtils.isNotEmpty(temp.getIntroduce()) ? temp.getIntroduce() : "");
				//doctorWorkTimeService.findDoctorWeekWorkTime()
				return write(200, "医生信息查询成功!", "data", json);
			} else {
				return error(-1, "医生信息查询失败!");
			}
		} catch (Exception e) {
			error(e);
			return invalidUserException(e, -1, "医生信息查询失败!");
		}
	}
	@RequestMapping(value = "status")
	@ResponseBody
@ -545,7 +598,6 @@ public class ConsultController extends WeixinBaseController {
	/**
	 * 网络咨询咨询日志查询
	 * @param consult 咨询标识
	 * @param patient 患者标识
	 * @param pagesize 每页显示数,默认为10
	 * @return
	 */