|
@ -1,375 +0,0 @@
|
|
|
package com.yihu.jw.patient.endpoint.patient;
|
|
|
|
|
|
import com.yihu.jw.entity.base.patient.BasePatientDO;
|
|
|
import com.yihu.jw.patient.dao.personal_info.PatientDao;
|
|
|
import com.yihu.jw.patient.service.personal_Info.PatientService;
|
|
|
import com.yihu.jw.patient.util.CommonUtils;
|
|
|
import com.yihu.jw.patient.util.RSAService;
|
|
|
import com.yihu.jw.restmodel.web.Envelop;
|
|
|
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
|
|
|
import com.yihu.jw.rm.patient.PatientRequestMapping;
|
|
|
import com.yihu.jw.util.security.MD5;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping(PatientRequestMapping.PatientInfo.PREFIX)
|
|
|
@Api(value = "患者注册,登陆等", description = "患者注册,登陆等", tags = {"居民端 - 患者注册,登陆等"})
|
|
|
public class PatientInfoEndpint extends EnvelopRestEndpoint {
|
|
|
|
|
|
@Autowired
|
|
|
private PatientDao patientDao;
|
|
|
@Autowired
|
|
|
private PatientService patientService;
|
|
|
|
|
|
@Autowired
|
|
|
private RSAService rsaService;
|
|
|
|
|
|
/**
|
|
|
* 公钥生成并返回接口
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "getKey", method = RequestMethod.GET)
|
|
|
@ApiOperation("获取公钥")
|
|
|
public Envelop publicKey() {
|
|
|
|
|
|
String modulus = rsaService.getModulus();
|
|
|
String exponent = rsaService.getExponent();
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
map.put("modulus", modulus); //加密指数
|
|
|
map.put("exponent", exponent);//加密系数
|
|
|
return success(map);
|
|
|
}
|
|
|
|
|
|
|
|
|
@ApiOperation("居民注册接口")
|
|
|
@RequestMapping(value = "regist", method = RequestMethod.POST)
|
|
|
@ResponseBody
|
|
|
public Envelop regist(@ApiParam(value = "手机号", name = "mobile") @RequestParam(required = true)String mobile ,
|
|
|
@ApiParam(value = "验证码", name = "captcha") @RequestParam(value = "captcha", required = true) String captcha,
|
|
|
@ApiParam(value = "微信openId", name = "openid") @RequestParam(value = "openid", required = false) String openid,
|
|
|
@ApiParam(value = "密码", name = "password") @RequestParam(value = "password", required = false) String password) {
|
|
|
Envelop envelop = new Envelop();
|
|
|
|
|
|
boolean b = CommonUtils.isMobile(mobile);
|
|
|
if(!b){
|
|
|
envelop.setMessage("手机号码格式不正确");
|
|
|
envelop.setStatus(-1);
|
|
|
return envelop;
|
|
|
}
|
|
|
|
|
|
//验证手机是否被注册
|
|
|
List<BasePatientDO> list = patientDao.findByMobileAndDel(mobile,"1");
|
|
|
if(list!=null && list.size()> 0){
|
|
|
envelop.setMessage("该手机号已经注册!");
|
|
|
envelop.setStatus(-1);
|
|
|
return envelop;
|
|
|
}
|
|
|
// 对验证码进行校验 todo cyx
|
|
|
// int res = smsService.check(mobile, 1, captcha);
|
|
|
// switch (res) {
|
|
|
// case -2:
|
|
|
// return error(-1, "验证码已过期!");
|
|
|
// case -1:
|
|
|
// return error(-1, "请输入正确的验证码!");
|
|
|
// case 0:
|
|
|
// return error(-1, "验证码无效!");
|
|
|
// }
|
|
|
|
|
|
BasePatientDO patient = new BasePatientDO();
|
|
|
patient.setMobile(mobile);
|
|
|
|
|
|
if(StringUtils.isNotBlank(password)){
|
|
|
//增加密码
|
|
|
String salt = UUID.randomUUID().toString().replace("-", "");
|
|
|
patient.setSalt(salt);
|
|
|
password = rsaService.decryptString(password);
|
|
|
password = StringUtils.reverse(password);
|
|
|
if(password.length()<6 || password.length()>20){
|
|
|
envelop.setMessage("密码长度需为6-20位");
|
|
|
envelop.setStatus(-1);
|
|
|
return envelop;
|
|
|
}
|
|
|
patient.setPassword(MD5.GetMD5Code(password + salt));
|
|
|
}
|
|
|
if(!"undefined".equals(openid) && StringUtils.isNotBlank(openid)){
|
|
|
patient.setOpenid(openid);
|
|
|
patient.setOpenidTime(new Date());
|
|
|
}
|
|
|
patient.setDel("1");
|
|
|
patient.setPatientStatus("1");
|
|
|
patientService.save(patient);
|
|
|
envelop.setMessage("注册成功");
|
|
|
envelop.setStatus(200);
|
|
|
return envelop;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 患者微信登录接口
|
|
|
*
|
|
|
* @param captcha 短信号
|
|
|
* @param mobile 电话号码
|
|
|
* @param password 登录密码
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "login", method = RequestMethod.POST)
|
|
|
@ResponseBody
|
|
|
public Envelop login(
|
|
|
@RequestParam(required = true) String mobile,
|
|
|
@RequestParam(required = false) String captcha,
|
|
|
@RequestParam(required = false) String password,
|
|
|
@RequestParam(required = false) String openId) {
|
|
|
Envelop envelop = new Envelop();
|
|
|
|
|
|
boolean b = CommonUtils.isMobile(mobile);
|
|
|
if(!b){
|
|
|
envelop.setMessage("手机号码格式不正确");
|
|
|
envelop.setStatus(-1);
|
|
|
return envelop;
|
|
|
}
|
|
|
|
|
|
//验证手机是否被注册
|
|
|
List<BasePatientDO> list = patientDao.findByMobileAndDel(mobile,"1");
|
|
|
if(CollectionUtils.isEmpty(list)){
|
|
|
envelop.setMessage("该手机未注册");
|
|
|
envelop.setStatus(-1);
|
|
|
return envelop;
|
|
|
}
|
|
|
|
|
|
if(list.size()> 1){
|
|
|
envelop.setMessage("该手机号存在多个账号,请联系管理员");
|
|
|
envelop.setStatus(-1);
|
|
|
return envelop;
|
|
|
}
|
|
|
BasePatientDO p = list.get(0);
|
|
|
//用于判断是否登陆成功,若登陆成功,且openId不为空,则更新openId
|
|
|
boolean isLogin = false;
|
|
|
if(StringUtils.isNotBlank(password)){
|
|
|
password = rsaService.decryptString(password);
|
|
|
password = StringUtils.reverse(password);
|
|
|
//生成MD5
|
|
|
String loginPassword = MD5.GetMD5Code(password + p.getSalt());
|
|
|
if (loginPassword.equals(p.getPassword())) {
|
|
|
//使用密码登录成功
|
|
|
}else{
|
|
|
//使用密码登录失败
|
|
|
|
|
|
}
|
|
|
} else {
|
|
|
//验证码登陆
|
|
|
|
|
|
}
|
|
|
if(isLogin && StringUtils.isNotBlank(openId) && !"undefined".equals(openId)){
|
|
|
//更新openId
|
|
|
if(!openId.equals(p.getOpenid())){
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// String errorMessage;
|
|
|
// try {
|
|
|
// //账号登录 mobile可能是电话号也可能是身份证
|
|
|
// if (StringUtils.isNoneEmpty(mobile) && StringUtils.isNoneEmpty(password)) {
|
|
|
// BasePatientDO p = patientService.findByMobile(mobile);
|
|
|
// //生成MD5
|
|
|
// String loginPassword = MD5.GetMD5Code(password + p.getSalt());
|
|
|
// //判断d登录密码是否正确
|
|
|
// if (loginPassword.equals(p.getPassword())) {
|
|
|
// // 绑定用户手机号和openid
|
|
|
// if (StringUtils.isNotBlank(openId) && !"undefined".equals(openId)) {//undefined不更新数据库
|
|
|
// //patient.setOpenid(openId);
|
|
|
// //1.判斷居民OPenid是不是空
|
|
|
// if(StringUtils.isNotBlank(p.getOpenid())){
|
|
|
// //如果OPenid与原来用户不相等,则判断登录的openids是否被大于10人登录
|
|
|
// if(!p.getOpenid().equals(openId)){
|
|
|
// //判断登录的openids是否被大于10人登录
|
|
|
//// if(!patientService.checkOpenidCount(openId)){
|
|
|
//// errorMessage ="您已超过系统允许登录的最大居民账号数量,当前不再允许使用该微信登录新的居民账号,请使用其他微信号进行登录";
|
|
|
//// return error(-2, errorMessage);
|
|
|
//// }
|
|
|
// }
|
|
|
// patientService.updatePatient(p, openId);
|
|
|
// }else{
|
|
|
// // 判断登录的openids是否被大于10人登录
|
|
|
// if(!patientService.checkOpenidCount(openId)){
|
|
|
//// errorMessage ="您已超过系统允许登录的最大居民账号数量,当前不再允许使用该微信登录新的居民账号,请使用其他微信号进行登录";
|
|
|
//// return error(-2, errorMessage);
|
|
|
// }else{
|
|
|
// //未达到上限更新用户openid
|
|
|
// patientService.updatePatient(p, openId);
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
// // 用户校验通过,生成token
|
|
|
// Token token = tokenService.newTxToken(p.getCode(), openId);
|
|
|
// Map<Object, Object> map = new HashMap<Object, Object>();
|
|
|
// map.put("id", p.getId());
|
|
|
// map.put("uid", p.getCode());
|
|
|
// map.put("name", p.getName());
|
|
|
// map.put("token", token.getToken());
|
|
|
// map.put("photo", p.getPhoto());
|
|
|
// if (StringUtils.isNoneEmpty(openId)) {
|
|
|
// //发送微信模板
|
|
|
// familyService.sendWXMessage(p);
|
|
|
// }
|
|
|
//
|
|
|
// loginLog.setLoginType("1");
|
|
|
// loginLogService.saveLog(loginLog);
|
|
|
// //判断是否打过标签
|
|
|
// //if (!(Patient.isWchatTage.yes.getValue() == p.getIsWxtag())) {
|
|
|
//
|
|
|
// //清空患者的微信标签
|
|
|
// weiXinTagUtil.deleteTagWithOpenid(p.getOpenid());
|
|
|
// //给患者打微信标签
|
|
|
// weiXinTagUtil.addTagWithOpenid(openId, p.getCode(), p.getName());
|
|
|
// //}
|
|
|
// return write(200, "登录成功", "data", map);
|
|
|
// } else {
|
|
|
// errorMessage = "密码错误,登录失败";
|
|
|
// loginLog.setErrorMessage(errorMessage);
|
|
|
// loginLogService.saveLog(loginLog);
|
|
|
// return error(-1, errorMessage);
|
|
|
// }
|
|
|
// }
|
|
|
// //短信登录
|
|
|
// if (StringUtils.isNoneEmpty(mobile) && StringUtils.isNoneEmpty(captcha)) {
|
|
|
// List<Patient> patients = patientService.findByMobile(mobile);
|
|
|
// if (patients.size() > 1) {
|
|
|
// return error(-1, "此手机存在多个用户,请用身份证和密码登录!");
|
|
|
// }
|
|
|
// // 对验证码进行校验
|
|
|
// int res = smsService.check(mobile, 4, captcha);
|
|
|
// switch (res) {
|
|
|
// case -2: {
|
|
|
// errorMessage = "验证码已过期!";
|
|
|
// loginLog.setErrorMessage(errorMessage);
|
|
|
// loginLogService.saveLog(loginLog);
|
|
|
// return error(-1, errorMessage);
|
|
|
// }
|
|
|
// case -1: {
|
|
|
// errorMessage = "请输入正确的验证码!";
|
|
|
// loginLog.setErrorMessage(errorMessage);
|
|
|
// loginLogService.saveLog(loginLog);
|
|
|
// return error(-1, errorMessage);
|
|
|
// }
|
|
|
// case 0: {
|
|
|
// errorMessage = "验证码无效!";
|
|
|
// loginLog.setErrorMessage(errorMessage);
|
|
|
// loginLogService.saveLog(loginLog);
|
|
|
// return error(-1, errorMessage);
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
// loginLog.setLoginType("1");
|
|
|
// if (patients == null || patients.size() == 0) {
|
|
|
// if (mobile.length() == 11) {
|
|
|
// errorMessage = "该手机号暂未注册账号,请确认后重新输入!";
|
|
|
// } else {
|
|
|
// errorMessage = "该身份证号暂未注册账号,请确认后重新输入!";
|
|
|
// }
|
|
|
// loginLog.setErrorMessage(errorMessage);
|
|
|
// loginLogService.saveLog(loginLog);
|
|
|
// return error(-1, errorMessage);
|
|
|
// } else {
|
|
|
// Patient p = null;
|
|
|
// if (patients.size() == 1) {
|
|
|
// p = patients.get(0);
|
|
|
// }
|
|
|
// if (p.getStatus() == 0) {
|
|
|
// if (mobile.length() == 11) {
|
|
|
// errorMessage = "该手机号已被禁止使用!";
|
|
|
// } else {
|
|
|
// errorMessage = "该身份证号已被禁止使用!";
|
|
|
// }
|
|
|
// loginLog.setErrorMessage(errorMessage);
|
|
|
// loginLogService.saveLog(loginLog);
|
|
|
// return error(-1, errorMessage);
|
|
|
// } else if (p.getStatus() == 2) {
|
|
|
// errorMessage = "该账号正在审核中,请确认审核通过后再登录,“如有疑问,拨打400-6677-400转2人工客服”";
|
|
|
// loginLog.setErrorMessage(errorMessage);
|
|
|
// loginLogService.saveLog(loginLog);
|
|
|
// return error(-1, errorMessage);
|
|
|
// } else if (StringUtils.isEmpty(openId)) {
|
|
|
// errorMessage = "无效的OpenID!";
|
|
|
// loginLog.setErrorMessage(errorMessage);
|
|
|
// loginLogService.saveLog(loginLog);
|
|
|
// return error(-1, errorMessage);
|
|
|
// }
|
|
|
// loginLog.setUserCode(p.getCode());
|
|
|
// // 绑定用户手机号和openid
|
|
|
//// if (!StringUtils.equals(p.getOpenid(), openId) && !"undefined".equals(openId)) {//undefined不更新数据库
|
|
|
//// //patient.setOpenid(openId);
|
|
|
//// patientService.updatePatient(p, openId);
|
|
|
//// }
|
|
|
// if (StringUtils.isNotBlank(openId) && !"undefined".equals(openId)) {//undefined不更新数据库
|
|
|
// //patient.setOpenid(openId);
|
|
|
// //1.判斷居民OPenid是不是空
|
|
|
// if(StringUtils.isNotBlank(p.getOpenid())){
|
|
|
// //如果OPenid与原来用户不相等,则判断登录的openids是否被大于10人登录
|
|
|
// if(!p.getOpenid().equals(openId)){
|
|
|
// //判断登录的openids是否被大于10人登录
|
|
|
// if(!patientService.checkOpenidCount(openId)){
|
|
|
//// errorMessage ="您已超过系统允许登录的最大居民账号数量,当前不再允许使用该微信登录新的居民账号,请使用其他微信号进行登录";
|
|
|
//// return error(-2, errorMessage);
|
|
|
// }
|
|
|
// }
|
|
|
// patientService.updatePatient(p, openId);
|
|
|
// }else{
|
|
|
// // 判断登录的openids是否被大于10人登录
|
|
|
// if(!patientService.checkOpenidCount(openId)){
|
|
|
//// errorMessage ="您已超过系统允许登录的最大居民账号数量,当前不再允许使用该微信登录新的居民账号,请使用其他微信号进行登录";
|
|
|
//// return error(-2, errorMessage);
|
|
|
// }else{
|
|
|
// //未达到上限更新用户openid
|
|
|
// patientService.updatePatient(p, openId);
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
// // 用户校验通过,生成token
|
|
|
// Token token = tokenService.newTxToken(p.getCode(), openId);
|
|
|
// Map<Object, Object> map = new HashMap<Object, Object>();
|
|
|
// map.put("id", p.getId());
|
|
|
// map.put("uid", p.getCode());
|
|
|
// map.put("name", p.getName());
|
|
|
// map.put("token", token.getToken());
|
|
|
// map.put("photo", p.getPhoto());
|
|
|
// if (StringUtils.isNoneEmpty(openId)) {
|
|
|
// //发送微信模板
|
|
|
// familyService.sendWXMessage(p);
|
|
|
// }
|
|
|
// loginLog.setType("1");
|
|
|
// loginLogService.saveLog(loginLog);
|
|
|
// //判断是否打过标签
|
|
|
// //if (!(Patient.isWchatTage.yes.getValue() == p.getIsWxtag())) {
|
|
|
// //清空患者的微信标签
|
|
|
// weiXinTagUtil.deleteTagWithOpenid(p.getOpenid());
|
|
|
// //给患者打微信标签
|
|
|
// weiXinTagUtil.addTagWithOpenid(openId, p.getCode(), p.getName());
|
|
|
// //}
|
|
|
// return write(200, "登录成功", "data", map);
|
|
|
// }
|
|
|
// }
|
|
|
// return error(-1, "登录失败");
|
|
|
// } catch (Exception e) {
|
|
|
//
|
|
|
// errorMessage = "系统异常,登录失败";
|
|
|
// loginLog.setErrorMessage(errorMessage);
|
|
|
// loginLogService.saveLog(loginLog);
|
|
|
// error(e);
|
|
|
// return error(-1, "系统异常,登录失败");
|
|
|
// }
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|