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