Browse Source

注册功能

chenyongxing 6 years ago
parent
commit
d80372a4e0

+ 6 - 54
svr/svr-patient/src/main/java/com/yihu/jw/patient/endpoint/personal_info/PatientEndpoint.java

@ -57,7 +57,6 @@ public class PatientEndpoint extends EnvelopRestEndpoint {
    private PatientDao patientDao;
    @Autowired
    private PatientService patientService;
    @Autowired
    private RSAService rsaService;
    @Autowired
@ -91,62 +90,15 @@ public class PatientEndpoint extends EnvelopRestEndpoint {
                          @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;
        }
        // 对验证码进行校验
        int res = baseSmsService.check(mobile, 0, captcha);
        if(-2 == res){
            envelop.setMessage("验证码已过期!");
            envelop.setStatus(-1);
            return envelop;
        }else if(-1 == res){
            envelop.setMessage("请输入正确的验证码!");
            envelop.setStatus(-1);
            return envelop;
        }else if(0 == res){
            envelop.setMessage("验证码无效!");
        Map<String, Object> result = patientService.regis(mobile, captcha, password, openid);
        if("-1".equals(result.get("code"))){
            envelop.setStatus(-1);
            return envelop;
        } else{
            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.setMessage(result.get("message")+"");
        }else{
            envelop.setStatus(200);
            return envelop;
            envelop.setMessage(result.get("message")+"");
        }
        return envelop;
    }
    /**

+ 67 - 1
svr/svr-patient/src/main/java/com/yihu/jw/patient/service/personal_Info/PatientService.java

@ -7,7 +7,9 @@ import com.yihu.jw.exception.business.patient.NotFoundPatientException;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.patient.dao.personal_info.PatientDao;
import com.yihu.jw.patient.service.BasePatientService;
import com.yihu.jw.patient.util.CommonUtils;
import com.yihu.jw.patient.util.ConstantUtils;
import com.yihu.jw.patient.util.RSAService;
import com.yihu.jw.sms.service.BaseSmsService;
import com.yihu.utils.security.MD5;
import org.apache.commons.lang3.StringUtils;
@ -15,7 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.UUID;
import java.util.*;
/**
 * 居民信息服务
@ -30,6 +32,70 @@ public class PatientService extends BasePatientService<BasePatientDO, BasePatien
    @Autowired
    private BaseSmsService baseSmsService;
    @Autowired
    private RSAService rsaService;
    public Map<String,Object> regis(String mobile, String captcha, String password, String openid){
        Map<String, Object> map = new HashMap<>();
        boolean b = CommonUtils.isMobile(mobile);
        if(!b){
            map.put("code",-1);
            map.put("message","手机号码格式不正确");
            return map;
        }
        //验证手机是否被注册
        List<BasePatientDO> list = patientDao.findByMobileAndDel(mobile,"1");
        if(list!=null && list.size()> 0){
            map.put("code",-1);
            map.put("message","该手机号已经注册!");
            return map;
        }
        // 对验证码进行校验
        int res = baseSmsService.check(mobile, 0, captcha);
        if(-2 == res){
            map.put("code",-1);
            map.put("message","验证码已过期!");
            return map;
        }else if(-1 == res){
            map.put("code",-1);
            map.put("message","请输入正确的验证码!");
            return map;
        }else if(0 == res){
            map.put("code",-1);
            map.put("message","验证码无效!");
            return map;
        } else{
            BasePatientDO patient = new BasePatientDO();
            patient.setMobile(mobile);
            if(org.apache.commons.lang.StringUtils.isNotBlank(password)){
                //增加密码
                String salt = UUID.randomUUID().toString().replace("-", "");
                patient.setSalt(salt);
                password = rsaService.decryptString(password);
                password = org.apache.commons.lang.StringUtils.reverse(password);
                if(password.length()<6 || password.length()>20){
                    map.put("code",-1);
                    map.put("message","密码长度需为6-20位");
                    return map;
                }
                patient.setPassword(com.yihu.jw.util.security.MD5.GetMD5Code(password + salt));
            }
            if(!"undefined".equals(openid) && org.apache.commons.lang.StringUtils.isNotBlank(openid)){
                patient.setOpenid(openid);
                patient.setOpenidTime(new Date());
            }
            patient.setDel("1");
            patient.setPatientStatus("1");
            this.save(patient);
            map.put("code",1);
            map.put("message","注册成功");
            return map;
        }
    }
    /**
     * 设置登录密码
     * @param id