Преглед изворни кода

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

esb пре 8 година
родитељ
комит
5ac821d371

+ 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;
    }

+ 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;
    }
}

+ 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);
}

+ 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;
        }
    }
}

+ 7 - 5
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();

+ 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,"查询失败");

+ 20 - 84
src/main/java/com/yihu/wlyy/web/patient/consult/ConsultController.java

@ -136,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,"查询失败!");
		}
	}
    /**
     * 医生是否在工作
     *
@ -230,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,"查询失败");
		}
	}
	/**
	 * 获取未完成咨询
	 *