Browse Source

代码提交

chenweida 8 years ago
parent
commit
ca9c3b3755

+ 80 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/doctor/observer/DoctorObserver.java

@ -0,0 +1,80 @@
package com.yihu.wlyy.entity.doctor.observer;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * Created by Administrator on 2017/1/3.
 */
@Entity
@Table(name = "wlyy_doctor_observer")
public class DoctorObserver extends IdEntity {
    private String observerDoctorCode;//被观察者的医生Code
    private String observerDoctorName;//被观察者的医生name
    private String doctorCode;//观察者的医生code
    private String doctorName;//观察者的医生name
    private Date createTime;//创建时间
    private String createUser;//创建人
    private Integer status;//1有效 0无效
    public String getObserverDoctorCode() {
        return observerDoctorCode;
    }
    public void setObserverDoctorCode(String observerDoctorCode) {
        this.observerDoctorCode = observerDoctorCode;
    }
    public String getObserverDoctorName() {
        return observerDoctorName;
    }
    public void setObserverDoctorName(String observerDoctorName) {
        this.observerDoctorName = observerDoctorName;
    }
    public String getDoctorCode() {
        return doctorCode;
    }
    public void setDoctorCode(String doctorCode) {
        this.doctorCode = doctorCode;
    }
    public String getDoctorName() {
        return doctorName;
    }
    public void setDoctorName(String doctorName) {
        this.doctorName = doctorName;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public String getCreateUser() {
        return createUser;
    }
    public void setCreateUser(String createUser) {
        this.createUser = createUser;
    }
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
}

+ 68 - 64
patient-co-wlyy/src/main/java/com/yihu/wlyy/interceptors/DoctorInterceptor.java

@ -15,77 +15,81 @@ import java.util.Date;
/**
 * 医生权限校验
 * @author George
 *
 * @author George
 */
public class DoctorInterceptor extends BaseInterceptor {
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		boolean flag = true;
		try {
			response.setCharacterEncoding("UTF-8");
			JSONObject json = getAgent(request);
			if (json == null) {
				// 未登录
				response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
				return false;
			}
			String tokenStr = json.has("token") ? json.getString("token") : "";
			String uid = json.has("uid") ? json.getString("uid") : "";
			String imei = json.has("imei") ? json.getString("imei") : "";
			if (StringUtils.isEmpty(tokenStr) || StringUtils.isEmpty(imei) || StringUtils.isEmpty(uid)) {
				response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
				return false;
			}
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        boolean flag = true;
        try {
            response.setCharacterEncoding("UTF-8");
            JSONObject json = getAgent(request);
            if (json == null) {
                // 未登录
                response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
                return false;
            }
            String tokenStr = json.has("token") ? json.getString("token") : "";
            String uid = json.has("uid") ? json.getString("uid") : "";
            String imei = json.has("imei") ? json.getString("imei") : "";
            String observer = json.has("observer") ? json.getString("observer") : "";
            //如果是观察者直接返回true
            if (!org.springframework.util.StringUtils.isEmpty(observer) && observer.equals("1")) {
                return true;
            }
            if (StringUtils.isEmpty(tokenStr) || StringUtils.isEmpty(imei) || StringUtils.isEmpty(uid)) {
                response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
                return false;
            }
			Token token = SystemData.doctorTokens.get(uid);
			if (token == null) {
				token = tokenDao.findByPatient(uid, 2);
				if (token != null) {
					// 加入缓存
					SystemData.doctorTokens.put(uid, token);
				}
			}
			if (token == null || token.getPlatform() != 2) {
				// 未登录
				response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
				flag = false;
			} else {
				if (token.getTimeout().getTime() < new Date().getTime()) {
					// 登录超时
					response.getOutputStream().write(error(SystemConf.LOGIN_TIMEOUT, "登录超时,请重新登录").getBytes());
					flag = false;
				} else if (!StringUtils.equals(tokenStr, token.getToken()) || !StringUtils.equals(uid, token.getUser()) || !StringUtils.equals(imei, token.getImei())) {
					// 别处登录
					response.getOutputStream().write(error(SystemConf.LOGIN_OTHER, "帐号在别处登录,请重新登录").getBytes());
					flag = false;
				} else {
					// 一天只更新一次
					if (DateUtil.getDays(token.getCzrq(), DateUtil.getNowDateShort()) != 0) {
						// 今天未更新,则更新缓存
						token.setCzrq(new Date());
						// 更新内存
						SystemData.doctorTokens.put(uid, token);
						// 更新数据库
						tokenDao.save(token);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return flag;
	}
            Token token = SystemData.doctorTokens.get(uid);
            if (token == null) {
                token = tokenDao.findByPatient(uid, 2);
                if (token != null) {
                    // 加入缓存
                    SystemData.doctorTokens.put(uid, token);
                }
            }
            if (token == null || token.getPlatform() != 2) {
                // 未登录
                response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
                flag = false;
            } else {
                if (token.getTimeout().getTime() < new Date().getTime()) {
                    // 登录超时
                    response.getOutputStream().write(error(SystemConf.LOGIN_TIMEOUT, "登录超时,请重新登录").getBytes());
                    flag = false;
                } else if (!StringUtils.equals(tokenStr, token.getToken()) || !StringUtils.equals(uid, token.getUser()) || !StringUtils.equals(imei, token.getImei())) {
                    // 别处登录
                    response.getOutputStream().write(error(SystemConf.LOGIN_OTHER, "帐号在别处登录,请重新登录").getBytes());
                    flag = false;
                } else {
                    // 一天只更新一次
                    if (DateUtil.getDays(token.getCzrq(), DateUtil.getNowDateShort()) != 0) {
                        // 今天未更新,则更新缓存
                        token.setCzrq(new Date());
                        // 更新内存
                        SystemData.doctorTokens.put(uid, token);
                        // 更新数据库
                        tokenDao.save(token);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }
	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
	}
    }
	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
	}
    }
}

+ 18 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/doctor/DoctorObserverDao.java

@ -0,0 +1,18 @@
package com.yihu.wlyy.repository.doctor;
import com.yihu.wlyy.entity.doctor.observer.DoctorObserver;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by Administrator on 2017/1/3.
 */
public interface DoctorObserverDao extends PagingAndSortingRepository<DoctorObserver, Long>, JpaSpecificationExecutor<DoctorObserver> {
    @Query("select d from DoctorObserver a ,Doctor d where  a.observerDoctorCode=d.code and a.doctorCode=?1 and a.status=1 ")
    List<Doctor> getDoctorObserversByDoctorCode(String doctorCode);
}

+ 59 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/observer/DoctorObserverService.java

@ -0,0 +1,59 @@
package com.yihu.wlyy.service.app.observer;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.repository.doctor.DoctorObserverDao;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
 * Created by Administrator on 2017/1/3.
 */
@Service
public class DoctorObserverService {
    @Autowired
    private DoctorObserverDao doctorObserverDao;
    /**
     * 得到医生的被观察者
     *
     * @param doctorCode
     * @return
     */
    public JSONArray getDoctorObservers(String doctorCode) {
        /**  map.put("id", doctor.getId());
             map.put("uid", doctor.getCode());
             map.put("token", token.getToken());
             map.put("name", doctor.getName());
             map.put("hospital", doctor.getHospital());
             map.put("photo", doctor.getPhoto());
             // 设置医生类型:1专科医生,2全科医生,3健康管理师
             map.put("doctorType", doctor.getLevel());
             //获取医生角色和区域权限
             List<Map<String, String>> roleMap = roleService.getUserRoleAndArea(doctor.getCode());
             map.put("userRole", roleMap);
             if("10".equals(doctor.getLevel())&&roleMap.size()==0){
             errorMessage="改用户没有管理员权限";
             loginLog.setErrorMessage(errorMessage);
         */
        List<Doctor> doctors = doctorObserverDao.getDoctorObserversByDoctorCode(doctorCode);
        JSONArray jsonArray = new JSONArray();
        for (int i = 0; i < doctors.size(); i++) {
            JSONObject jo = new JSONObject();
            Doctor doctor = doctors.get(i);
            jo.put("id", doctor.getId());
            jo.put("uid", doctor.getCode());
            jo.put("name", doctor.getName());
            jo.put("hospital", doctor.getHospital());
            jo.put("HospitalName", doctor.getHospitalName());
            jo.put("photo", doctor.getPhoto());
            jo.put("doctorType", doctor.getLevel());
            jsonArray.put(jo);
        }
        return jsonArray;
    }
}

+ 8 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/account/DoctorController.java

@ -15,6 +15,7 @@ import com.yihu.wlyy.service.app.account.PatientInfoService;
import com.yihu.wlyy.service.app.consult.ConsultTeamService;
import com.yihu.wlyy.service.app.hospital.HospitalDeptService;
import com.yihu.wlyy.service.app.scheduling.DoctorWorkTimeService;
import com.yihu.wlyy.service.common.account.RoleService;
import com.yihu.wlyy.util.*;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
@ -77,6 +78,8 @@ public class DoctorController extends BaseController {
    private DoctorWorkTimeService workTimeService;
    @Autowired
    StringRedisTemplate redisTemplate;
    @Autowired
    private RoleService roleService;
    /**
     * 社区医院下医生列表查询接口 没分页
@ -593,7 +596,9 @@ public class DoctorController extends BaseController {
                json.put("isFamous", temp.getIsFamous());
                //是否医生提示 提示过是1 其他都是0
                json.put("isPasswordPrompt", StringUtils.isEmpty(temp.getIsPasswordPrompt()) ? "0" : temp.getIsPasswordPrompt());
                //获取医生角色和区域权限
                List<Map<String, String>> roleMap = roleService.getUserRoleAndArea(temp.getCode());
                json.put("userRole", roleMap);
                return write(200, "医生信息查询成功!", "data", json);
            } else {
                return error(-1, "医生信息查询失败!");
@ -1585,6 +1590,8 @@ public class DoctorController extends BaseController {
                    return error(-1, "居民不能为空");
                }
                Map<String, Integer> returnMap = doctorInfoService.updateTeamHealthDoctors(newDoctorCode, oldDoctorCode, patients, getUID());
                redisTemplate.opsForValue().set("jianguanshifenpei:" + getUID(), "0");
                redisTemplate.expire("jianguanshifenpei:" + getUID(), 10, TimeUnit.MINUTES);
                return write(200, "已成功处理" + returnMap.get("success") + "个居民," + returnMap.get("error") + "个居民因有未结束的咨询,无法处理");
            }
            redisTemplate.opsForValue().set("jianguanshifenpei:" + getUID(), "0");

+ 54 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/observer/DoctorObserverController.java

@ -0,0 +1,54 @@
package com.yihu.wlyy.web.doctor.observer;
import com.yihu.wlyy.service.app.observer.DoctorObserverService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
/**
 * Created by Administrator on 2017/1/4.
 */
@RestController
@RequestMapping(value = "/doctor/observer", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "医生端-观察者")
public class DoctorObserverController extends BaseController {
    @Autowired
    private DoctorObserverService doctorObserverService;
    @ApiOperation(value = "获取医生观察者列表")
    @RequestMapping(value = "/getAllObserver", method = RequestMethod.GET)
    public String getAllObserver(
            @ApiParam(name = "doctorCode", value = "医生code", required = false) @RequestParam(value = "doctorCode", required = false) String doctorCode) {
        try {
            if (StringUtils.isEmpty(doctorCode)) {
                //如果医生code为空从头信息获取
                doctorCode = getUID();
            }
            if (StringUtils.isEmpty(doctorCode)) {
                throw new Exception("参数错误");
            }
            //返回被观察者的医生的code
            JSONArray doctors = doctorObserverService.getDoctorObservers(doctorCode);
            return write(200, "获取成功!", "data", doctors);
        } catch (Exception e) {
            error(e);
            return error(-1, "获取失败!");
        }
    }
}