chenyongxing 6 年 前
コミット
15e5a0f716

+ 16 - 1
business/base-service/src/main/java/com/yihu/jw/patient/service/BasePatientService.java

@ -10,6 +10,7 @@ import com.yihu.jw.patient.util.ConstantUtils;
import com.yihu.mysql.query.BaseJpaService;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.CrudRepository;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Transactional;
@ -34,7 +35,7 @@ import java.util.Set;
 * @since 1.
 * @since 1.
 */
 */
@Service
@Service
public class BasePatientService extends BaseJpaService<BasePatientDO, BasePatientDao> {
public class BasePatientService<T, R extends CrudRepository> extends BaseJpaService<BasePatientDO, BasePatientDao> {
    @Autowired
    @Autowired
    private BasePatientDao basePatientDao;
    private BasePatientDao basePatientDao;
@ -161,4 +162,18 @@ public class BasePatientService extends BaseJpaService<BasePatientDO, BasePatien
        }
        }
        return ConstantUtils.SUCCESS;
        return ConstantUtils.SUCCESS;
    }
    }
    /**
     * 根据patient的id获取居民信息
     * @param patient
     * @return
     */
    public BasePatientDO findByIdAndDel(String patient) throws Exception{
        BasePatientDO basePatientDO = basePatientDao.findByIdAndDel(patient,"1");
        if(basePatientDO==null){
            throw new Exception("not patient");
        }
        return basePatientDO;
    }
}
}

+ 22 - 1
common/common-util/src/main/java/com/yihu/jw/util/common/RSAUtils.java

@ -15,6 +15,15 @@ public class RSAUtils {
//    private static final KeyPair keyPair = initKey();
//    private static final KeyPair keyPair = initKey();
    /**
     * 算法名称
     */
    private static final String ALGORITHOM = "RSA";
    /**
     * 默认的安全服务提供者
     */
    private static final Provider DEFAULT_PROVIDER = new BouncyCastleProvider();
    public static KeyPair initKey(){
    public static KeyPair initKey(){
        try {
        try {
            Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
            Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
@ -51,7 +60,7 @@ public class RSAUtils {
        return new String(decrypt(Base64.decodeBase64(string),keyPair));
        return new String(decrypt(Base64.decodeBase64(string),keyPair));
    }
    }
    private static byte[] decrypt(byte[] string,KeyPair keyPair) {
    public static byte[] decrypt(byte[] string,KeyPair keyPair) {
        try {
        try {
            Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
            Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
            Cipher cipher = Cipher.getInstance("RSA/None/PKCS1Padding", "BC");
            Cipher cipher = Cipher.getInstance("RSA/None/PKCS1Padding", "BC");
@ -106,6 +115,18 @@ public class RSAUtils {
        return data != null ? Base64.encodeBase64String(data) : null;
        return data != null ? Base64.encodeBase64String(data) : null;
    }
    }
    /**
     * 使用指定的私钥解密数据。
     *
     * @param privateKey 给定的私钥。
     * @param data       要解密的数据。
     * @return 原数据。
     */
    public static byte[] decrypt(PrivateKey privateKey, byte[] data) throws Exception {
        Cipher ci = Cipher.getInstance(ALGORITHOM, DEFAULT_PROVIDER);
        ci.init(Cipher.DECRYPT_MODE, privateKey);
        return ci.doFinal(data);
    }
    public static void main(String[] args) {
    public static void main(String[] args) {

+ 0 - 31
svr/svr-patient/src/main/java/com/yihu/jw/patient/dao/patient/BasePatientDao.java

@ -1,31 +0,0 @@
//package com.yihu.jw.patient.dao.patient;
//
//import com.yihu.jw.entity.base.patient.BasePatientDO;
//import org.springframework.data.domain.Pageable;
//import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
//import org.springframework.data.jpa.repository.Query;
//import org.springframework.data.repository.PagingAndSortingRepository;
//
//import java.util.List;
//import java.util.Map;
//
///**
// * Created by Trick on 2018/8/31.
// */
//public interface BasePatientDao extends PagingAndSortingRepository<BasePatientDO, String>, JpaSpecificationExecutor<BasePatientDO> {
//
//    BasePatientDO findByIdAndDel(String id, String del);
//
//    @Query("from BasePatientDO where mobile = ?1")
//    List<BasePatientDO> findByMobile(String mobile);
//
//    @Query("select id as id,idcard as idcard,name as name,case sex when 1 then '男' when 2 then '女' else '未知' end as sex,phone as phone,committeeName as committeeName,concat(provinceName,cityName,townName,streetName) as address from BasePatientDO where idcard like ?1")
//    List<Map<String,Object>> findByIdcard(String idcard, Pageable pageable);
//
//    @Query("select id as id,idcard as idcard,name as name,case sex when 1 then '男' when 2 then '女' else '未知' end as sex,phone as phone,committeeName as committeeName,concat(provinceName,cityName,townName,streetName) as address from BasePatientDO where name like ?1")
//    List<Map<String,Object>> findByName(String name, Pageable pageable);
//
//    @Query("select id as id,idcard as idcard,name as name,case sex when 1 then '男' when 2 then '女' else '未知' end as sex,phone as phone,committeeName as committeeName,concat(provinceName,cityName,townName,streetName) as address from BasePatientDO")
//    List<Map<String,Object>> findBaseInfo(Pageable pageable);
//
//}

+ 6 - 0
svr/svr-patient/src/main/java/com/yihu/jw/patient/dao/personal_info/PatientDao.java

@ -26,4 +26,10 @@ public interface PatientDao extends PagingAndSortingRepository<BasePatientDO, St
    @Query("select id as id,idcard as idcard,name as name,case sex when 1 then '男' when 2 then '女' else '未知' end as sex,phone as phone,committeeName as committeeName,concat(provinceName,cityName,townName,streetName) as address from BasePatientDO")
    @Query("select id as id,idcard as idcard,name as name,case sex when 1 then '男' when 2 then '女' else '未知' end as sex,phone as phone,committeeName as committeeName,concat(provinceName,cityName,townName,streetName) as address from BasePatientDO")
    List<Map<String,Object>> findBaseInfo(Pageable pageable);
    List<Map<String,Object>> findBaseInfo(Pageable pageable);
    @Query("from BasePatientDO where mobile = ?1")
    List<BasePatientDO> findByMobile(String mobile);
    @Query("from BasePatientDO p where p.mobile = ?1 and p.del=?2")
    List<BasePatientDO> findByMobileAndDel(String mobile,String del);
}
}

+ 138 - 124
svr/svr-patient/src/main/java/com/yihu/jw/patient/endpoint/patient/PatientInfoEndpint.java

@ -1,22 +1,22 @@
package com.yihu.jw.patient.endpoint.patient;
package com.yihu.jw.patient.endpoint.patient;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.patient.dao.BasePatientDao;
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.patient.util.RSAService;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.patient.PatientRequestMapping;
import com.yihu.jw.rm.patient.PatientRequestMapping;
import com.yihu.jw.util.common.RSAUtils;
import com.yihu.jw.util.security.MD5;
import com.yihu.jw.util.security.MD5;
import io.swagger.annotations.Api;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.*;
@RestController
@RestController
@ -25,7 +25,9 @@ import java.util.*;
public class PatientInfoEndpint extends EnvelopRestEndpoint {
public class PatientInfoEndpint extends EnvelopRestEndpoint {
    @Autowired
    @Autowired
    private BasePatientDao patientDao;
    private PatientDao patientDao;
    @Autowired
    private PatientService patientService;
    @Autowired
    @Autowired
    private RSAService rsaService;
    private RSAService rsaService;
@ -41,10 +43,10 @@ public class PatientInfoEndpint extends EnvelopRestEndpoint {
        String modulus = rsaService.getModulus();
        String modulus = rsaService.getModulus();
        String exponent = rsaService.getExponent();
        String exponent = rsaService.getExponent();
        JSONObject json = new JSONObject();
        json.put("modulus", modulus); //加密指数
        json.put("exponent", exponent);//加密系数
        return success(json);
        Map<String, String> map = new HashMap<>();
        map.put("modulus", modulus); //加密指数
        map.put("exponent", exponent);//加密系数
        return success(map);
    }
    }
@ -54,18 +56,24 @@ public class PatientInfoEndpint extends EnvelopRestEndpoint {
    public Envelop regist(@ApiParam(value = "手机号", name = "mobile") @RequestParam(required = true)String mobile ,
    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 = "验证码", name = "captcha") @RequestParam(value = "captcha", required = true) String captcha,
                         @ApiParam(value = "微信openId", name = "openid") @RequestParam(value = "openid", required = false) String openid,
                         @ApiParam(value = "微信openId", name = "openid") @RequestParam(value = "openid", required = false) String openid,
                         @ApiParam(value = "密码", name = "password") @RequestParam(value = "password", required = true) String password) {
        try {
            Envelop envelop = new Envelop();
                         @ApiParam(value = "密码", name = "password") @RequestParam(value = "password", required = false) String password) {
        Envelop envelop = new Envelop();
            //验证手机是否被注册
            List<BasePatientDO> list =  patientDao.findByMobile(mobile);
            if(list!=null && list.size()>0){
                envelop.setMessage("该手机号已经注册!");
                envelop.setStatus(-1);
                return envelop;
            }
            // 对验证码进行校验 todo cyx
        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);
//            int res = smsService.check(mobile, 1, captcha);
//            switch (res) {
//            switch (res) {
//                case -2:
//                case -2:
@ -76,135 +84,140 @@ public class PatientInfoEndpint extends EnvelopRestEndpoint {
//                    return error(-1, "验证码无效!");
//                    return error(-1, "验证码无效!");
//            }
//            }
            BasePatientDO patient = new BasePatientDO();
            patient.setMobile(mobile);
        BasePatientDO patient = new BasePatientDO();
        patient.setMobile(mobile);
        if(StringUtils.isNotBlank(password)){
            //增加密码
            //增加密码
            String salt = UUID.randomUUID().toString().replace("-", "");
            String salt = UUID.randomUUID().toString().replace("-", "");
            patient.setSalt(salt);
            patient.setSalt(salt);
            password = RSAUtils.decryptString(password);
            password = rsaService.decryptString(password);
            password = StringUtils.reverse(password);
            password = StringUtils.reverse(password);
            patient.setPassword(MD5.GetMD5Code(password + salt));
            if(!"undefined".equals(openid) && StringUtils.isNotBlank(openid)){
                patient.setOpenid(openid);
                patient.setOpenidTime(new Date());
            if(password.length()<6 || password.length()>20){
                envelop.setMessage("密码长度需为6-20位");
                envelop.setStatus(-1);
                return envelop;
            }
            }
//            JSONObject json = patientService.register(mobile, MD5.GetMD5Code(password + salt)
//                    ,salt,openid,3);
        } catch (Exception e) {
//            error(e);
////            return error(-1, "注册失败!");
            patient.setPassword(MD5.GetMD5Code(password + salt));
        }
        if(!"undefined".equals(openid) && StringUtils.isNotBlank(openid)){
            patient.setOpenid(openid);
            patient.setOpenidTime(new Date());
        }
        }
        return null;
        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 String login(
//            @RequestParam(required = false) String mobile,
//            @RequestParam(required = false) String captcha,
//            @RequestParam(required = false) String password,
//            String openid) {
//        String errorMessage;
//        LoginLog loginLog = new LoginLog();
//        loginLog.setCreateTime(new Date());
//        loginLog.setPhone(mobile);
//        loginLog.setType("2");
//        loginLog.setUserType("1");
    /**
     * 患者微信登录接口
     *
     * @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 {
//        try {
//            //账号登录 mobile可能是电话号也可能是身份证
//            //账号登录 mobile可能是电话号也可能是身份证
//            if (StringUtils.isNoneEmpty(mobile) && StringUtils.isNoneEmpty(password)) {
//            if (StringUtils.isNoneEmpty(mobile) && StringUtils.isNoneEmpty(password)) {
//                Patient p = patientService.findByIdcard(mobile);
//                if (p == null) {
//                    List<Patient> patients = patientService.findByMobile(mobile);
//                    if (patients.size() > 1) {
//                        return error(-1, "此手机号码存在多个用户,请用身份证进行登录!");
//                    } else if (patients.size() == 1) {
//                        p = patients.get(0);
//                    }
//                }
//                loginLog.setLoginType("2");
//                if (p == null) {
//                    if (mobile.length() == 11) {
//                        errorMessage = "该手机号暂未注册账号,请确认后重新输入!";
//                    } else {
//                        errorMessage = "该身份证号暂未注册账号,请确认后重新输入!";
//                    }
//                    loginLog.setErrorMessage(errorMessage);
//                    loginLogService.saveLog(loginLog);
//                    return error(-1, errorMessage);
//                } else 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());
//                //解密
//                rsaUtils.setBaseService(patientService);
//                password = rsaUtils.decryptString(password);
//                password = StringUtils.reverse(password);
//                BasePatientDO p = patientService.findByMobile(mobile);
//                //生成MD5
//                //生成MD5
//                String loginPassword = MD5.GetMD5Code(password + p.getSalt());
//                String loginPassword = MD5.GetMD5Code(password + p.getSalt());
//                //判断d登录密码是否正确
//                //判断d登录密码是否正确
//                if (loginPassword.equals(p.getPassword())) {
//                if (loginPassword.equals(p.getPassword())) {
//                    // 绑定用户手机号和openid
//                    // 绑定用户手机号和openid
//                    if (StringUtils.isNotBlank(openid) && !"undefined".equals(openid)) {//undefined不更新数据库
//                        //patient.setOpenid(openid);
//                    if (StringUtils.isNotBlank(openId) && !"undefined".equals(openId)) {//undefined不更新数据库
//                        //patient.setOpenid(openId);
//                        //1.判斷居民OPenid是不是空
//                        //1.判斷居民OPenid是不是空
//                        if(StringUtils.isNotBlank(p.getOpenid())){
//                        if(StringUtils.isNotBlank(p.getOpenid())){
//                            //如果OPenid与原来用户不相等,则判断登录的openids是否被大于10人登录
//                            //如果OPenid与原来用户不相等,则判断登录的openids是否被大于10人登录
//                            if(!p.getOpenid().equals(openid)){
//                            if(!p.getOpenid().equals(openId)){
//                                //判断登录的openids是否被大于10人登录
//                                //判断登录的openids是否被大于10人登录
////                                if(!patientService.checkOpenidCount(openid)){
////                                if(!patientService.checkOpenidCount(openId)){
////                                    errorMessage ="您已超过系统允许登录的最大居民账号数量,当前不再允许使用该微信登录新的居民账号,请使用其他微信号进行登录";
////                                    errorMessage ="您已超过系统允许登录的最大居民账号数量,当前不再允许使用该微信登录新的居民账号,请使用其他微信号进行登录";
////                                    return error(-2, errorMessage);
////                                    return error(-2, errorMessage);
////                                }
////                                }
//                            }
//                            }
//                            patientService.updatePatient(p, openid);
//                            patientService.updatePatient(p, openId);
//                        }else{
//                        }else{
//                            // 判断登录的openids是否被大于10人登录
//                            // 判断登录的openids是否被大于10人登录
//                            if(!patientService.checkOpenidCount(openid)){
//                            if(!patientService.checkOpenidCount(openId)){
////                                errorMessage ="您已超过系统允许登录的最大居民账号数量,当前不再允许使用该微信登录新的居民账号,请使用其他微信号进行登录";
////                                errorMessage ="您已超过系统允许登录的最大居民账号数量,当前不再允许使用该微信登录新的居民账号,请使用其他微信号进行登录";
////                                return error(-2, errorMessage);
////                                return error(-2, errorMessage);
//                            }else{
//                            }else{
//                                //未达到上限更新用户openid
//                                //未达到上限更新用户openid
//                                patientService.updatePatient(p, openid);
//                                patientService.updatePatient(p, openId);
//                            }
//                            }
//                        }
//                        }
//                    }
//                    }
//
//
//                    // 用户校验通过,生成token
//                    // 用户校验通过,生成token
//                    Token token = tokenService.newTxToken(p.getCode(), openid);
//                    Token token = tokenService.newTxToken(p.getCode(), openId);
//                    Map<Object, Object> map = new HashMap<Object, Object>();
//                    Map<Object, Object> map = new HashMap<Object, Object>();
//                    map.put("id", p.getId());
//                    map.put("id", p.getId());
//                    map.put("uid", p.getCode());
//                    map.put("uid", p.getCode());
//                    map.put("name", p.getName());
//                    map.put("name", p.getName());
//                    map.put("token", token.getToken());
//                    map.put("token", token.getToken());
//                    map.put("photo", p.getPhoto());
//                    map.put("photo", p.getPhoto());
//                    if (StringUtils.isNoneEmpty(openid)) {
//                    if (StringUtils.isNoneEmpty(openId)) {
//                        //发送微信模板
//                        //发送微信模板
//                        familyService.sendWXMessage(p);
//                        familyService.sendWXMessage(p);
//                    }
//                    }
@ -217,7 +230,7 @@ public class PatientInfoEndpint extends EnvelopRestEndpoint {
//                    //清空患者的微信标签
//                    //清空患者的微信标签
//                    weiXinTagUtil.deleteTagWithOpenid(p.getOpenid());
//                    weiXinTagUtil.deleteTagWithOpenid(p.getOpenid());
//                    //给患者打微信标签
//                    //给患者打微信标签
//                    weiXinTagUtil.addTagWithOpenid(openid, p.getCode(), p.getName());
//                    weiXinTagUtil.addTagWithOpenid(openId, p.getCode(), p.getName());
//                    //}
//                    //}
//                    return write(200, "登录成功", "data", map);
//                    return write(200, "登录成功", "data", map);
//                } else {
//                } else {
@ -285,7 +298,7 @@ public class PatientInfoEndpint extends EnvelopRestEndpoint {
//                        loginLog.setErrorMessage(errorMessage);
//                        loginLog.setErrorMessage(errorMessage);
//                        loginLogService.saveLog(loginLog);
//                        loginLogService.saveLog(loginLog);
//                        return error(-1, errorMessage);
//                        return error(-1, errorMessage);
//                    } else if (StringUtils.isEmpty(openid)) {
//                    } else if (StringUtils.isEmpty(openId)) {
//                        errorMessage = "无效的OpenID!";
//                        errorMessage = "无效的OpenID!";
//                        loginLog.setErrorMessage(errorMessage);
//                        loginLog.setErrorMessage(errorMessage);
//                        loginLogService.saveLog(loginLog);
//                        loginLogService.saveLog(loginLog);
@ -293,44 +306,44 @@ public class PatientInfoEndpint extends EnvelopRestEndpoint {
//                    }
//                    }
//                    loginLog.setUserCode(p.getCode());
//                    loginLog.setUserCode(p.getCode());
//                    // 绑定用户手机号和openid
//                    // 绑定用户手机号和openid
////                    if (!StringUtils.equals(p.getOpenid(), openid) && !"undefined".equals(openid)) {//undefined不更新数据库
////                        //patient.setOpenid(openid);
////                        patientService.updatePatient(p, 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);
//                    if (StringUtils.isNotBlank(openId) && !"undefined".equals(openId)) {//undefined不更新数据库
//                        //patient.setOpenid(openId);
//                        //1.判斷居民OPenid是不是空
//                        //1.判斷居民OPenid是不是空
//                        if(StringUtils.isNotBlank(p.getOpenid())){
//                        if(StringUtils.isNotBlank(p.getOpenid())){
//                            //如果OPenid与原来用户不相等,则判断登录的openids是否被大于10人登录
//                            //如果OPenid与原来用户不相等,则判断登录的openids是否被大于10人登录
//                            if(!p.getOpenid().equals(openid)){
//                            if(!p.getOpenid().equals(openId)){
//                                //判断登录的openids是否被大于10人登录
//                                //判断登录的openids是否被大于10人登录
//                                if(!patientService.checkOpenidCount(openid)){
//                                if(!patientService.checkOpenidCount(openId)){
////                                    errorMessage ="您已超过系统允许登录的最大居民账号数量,当前不再允许使用该微信登录新的居民账号,请使用其他微信号进行登录";
////                                    errorMessage ="您已超过系统允许登录的最大居民账号数量,当前不再允许使用该微信登录新的居民账号,请使用其他微信号进行登录";
////                                    return error(-2, errorMessage);
////                                    return error(-2, errorMessage);
//                                }
//                                }
//                            }
//                            }
//                            patientService.updatePatient(p, openid);
//                            patientService.updatePatient(p, openId);
//                        }else{
//                        }else{
//                            // 判断登录的openids是否被大于10人登录
//                            // 判断登录的openids是否被大于10人登录
//                            if(!patientService.checkOpenidCount(openid)){
//                            if(!patientService.checkOpenidCount(openId)){
////                                errorMessage ="您已超过系统允许登录的最大居民账号数量,当前不再允许使用该微信登录新的居民账号,请使用其他微信号进行登录";
////                                errorMessage ="您已超过系统允许登录的最大居民账号数量,当前不再允许使用该微信登录新的居民账号,请使用其他微信号进行登录";
////                                return error(-2, errorMessage);
////                                return error(-2, errorMessage);
//                            }else{
//                            }else{
//                                //未达到上限更新用户openid
//                                //未达到上限更新用户openid
//                                patientService.updatePatient(p, openid);
//                                patientService.updatePatient(p, openId);
//                            }
//                            }
//                        }
//                        }
//                    }
//                    }
//
//
//                    // 用户校验通过,生成token
//                    // 用户校验通过,生成token
//                    Token token = tokenService.newTxToken(p.getCode(), openid);
//                    Token token = tokenService.newTxToken(p.getCode(), openId);
//                    Map<Object, Object> map = new HashMap<Object, Object>();
//                    Map<Object, Object> map = new HashMap<Object, Object>();
//                    map.put("id", p.getId());
//                    map.put("id", p.getId());
//                    map.put("uid", p.getCode());
//                    map.put("uid", p.getCode());
//                    map.put("name", p.getName());
//                    map.put("name", p.getName());
//                    map.put("token", token.getToken());
//                    map.put("token", token.getToken());
//                    map.put("photo", p.getPhoto());
//                    map.put("photo", p.getPhoto());
//                    if (StringUtils.isNoneEmpty(openid)) {
//                    if (StringUtils.isNoneEmpty(openId)) {
//                        //发送微信模板
//                        //发送微信模板
//                        familyService.sendWXMessage(p);
//                        familyService.sendWXMessage(p);
//                    }
//                    }
@ -341,7 +354,7 @@ public class PatientInfoEndpint extends EnvelopRestEndpoint {
//                    //清空患者的微信标签
//                    //清空患者的微信标签
//                    weiXinTagUtil.deleteTagWithOpenid(p.getOpenid());
//                    weiXinTagUtil.deleteTagWithOpenid(p.getOpenid());
//                    //给患者打微信标签
//                    //给患者打微信标签
//                    weiXinTagUtil.addTagWithOpenid(openid, p.getCode(), p.getName());
//                    weiXinTagUtil.addTagWithOpenid(openId, p.getCode(), p.getName());
//                    //}
//                    //}
//                    return write(200, "登录成功", "data", map);
//                    return write(200, "登录成功", "data", map);
//                }
//                }
@ -355,7 +368,8 @@ public class PatientInfoEndpint extends EnvelopRestEndpoint {
//            error(e);
//            error(e);
//            return error(-1, "系统异常,登录失败");
//            return error(-1, "系统异常,登录失败");
//        }
//        }
//    }
            return null;
    }
}
}

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

@ -4,7 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.base.sms.SmsDO;
import com.yihu.jw.entity.base.sms.SmsDO;
import com.yihu.jw.entity.base.sms.SmsTemplateDO;
import com.yihu.jw.entity.base.sms.SmsTemplateDO;
import com.yihu.jw.patient.service.personal_Info.PatientService;
import com.yihu.jw.patient.service.BasePatientService;
import com.yihu.jw.patient.util.ConstantUtils;
import com.yihu.jw.patient.util.ConstantUtils;
import com.yihu.jw.restmodel.base.patient.BasePatientVO;
import com.yihu.jw.restmodel.base.patient.BasePatientVO;
import com.yihu.jw.restmodel.base.sms.SmsVO;
import com.yihu.jw.restmodel.base.sms.SmsVO;
@ -42,7 +42,7 @@ import java.util.Map;
public class PatientEndpoint extends EnvelopRestEndpoint {
public class PatientEndpoint extends EnvelopRestEndpoint {
    @Autowired
    @Autowired
    private PatientService patientService;
    private BasePatientService patientService;
    @Value("sms.clientId")
    @Value("sms.clientId")
    private String clientId;
    private String clientId;

+ 2 - 2
svr/svr-patient/src/main/java/com/yihu/jw/patient/service/myFamily/MyFamilyService.java

@ -6,7 +6,7 @@ import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.base.patient.BasePatientFamilyMemberDO;
import com.yihu.jw.entity.base.patient.BasePatientFamilyMemberDO;
import com.yihu.jw.entity.myFamily.PatientApplyLog;
import com.yihu.jw.entity.myFamily.PatientApplyLog;
import com.yihu.jw.message.service.MessageService;
import com.yihu.jw.message.service.MessageService;
import com.yihu.jw.patient.service.personal_Info.PatientService;
import com.yihu.jw.patient.service.BasePatientService;
import com.yihu.jw.wechat.service.WeChatQrcodeService;
import com.yihu.jw.wechat.service.WeChatQrcodeService;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.StringUtils;
@ -27,7 +27,7 @@ public class MyFamilyService {
    @Autowired
    @Autowired
    private PatientFamilyMemberService patientFamilyMemberService;
    private PatientFamilyMemberService patientFamilyMemberService;
    @Autowired
    @Autowired
    private PatientService patientService;
    private BasePatientService patientService;
    @Autowired
    @Autowired
    private MessageService messageService;
    private MessageService messageService;
    @Value("${myFamily.qrCodeFailurTime}")
    @Value("${myFamily.qrCodeFailurTime}")

+ 10 - 18
svr/svr-patient/src/main/java/com/yihu/jw/patient/service/personal_Info/PatientService.java

@ -5,6 +5,7 @@ import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.exception.business.patient.CapthcaInvalidException;
import com.yihu.jw.exception.business.patient.CapthcaInvalidException;
import com.yihu.jw.exception.business.patient.NotFoundPatientException;
import com.yihu.jw.exception.business.patient.NotFoundPatientException;
import com.yihu.jw.file_upload.FileUploadService;
import com.yihu.jw.file_upload.FileUploadService;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.patient.dao.personal_info.PatientDao;
import com.yihu.jw.patient.dao.personal_info.PatientDao;
import com.yihu.jw.patient.service.BasePatientService;
import com.yihu.jw.patient.service.BasePatientService;
import com.yihu.jw.patient.util.ConstantUtils;
import com.yihu.jw.patient.util.ConstantUtils;
@ -15,12 +16,14 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Transactional;
import java.util.UUID;
/**
/**
 * 居民信息服务
 * 居民信息服务
 * @author litaohong on  2018年11月28日
 * @author litaohong on  2018年11月28日
 */
 */
@Service
@Service
public class PatientService extends BasePatientService {
public class PatientService extends BasePatientService<BasePatientDO, BasePatientDao> {
    @Autowired
    @Autowired
    private PatientDao patientDao;
    private PatientDao patientDao;
@ -28,9 +31,6 @@ public class PatientService extends BasePatientService {
    @Autowired
    @Autowired
    private BaseSmsService baseSmsService;
    private BaseSmsService baseSmsService;
    @Autowired
    private FileUploadService fileUploadService;
    /**
    /**
     * 设置登录密码
     * 设置登录密码
     * @param id
     * @param id
@ -43,9 +43,10 @@ public class PatientService extends BasePatientService {
        if(null == patient){
        if(null == patient){
            throw new NotFoundPatientException("当前居民不存在:【 " + id + "】");
            throw new NotFoundPatientException("当前居民不存在:【 " + id + "】");
        }
        }
        patient.setSalt(randomString(5));
        String salt = UUID.randomUUID().toString().replace("-", "");
        patient.setSalt(salt);
        password = patient.getIdcard().substring(0, 5);
        password = patient.getIdcard().substring(0, 5);
        patient.setPassword(MD5.md5Hex(password + "{" + patient.getSalt() + "}"));
        patient.setPassword(MD5.md5Hex(password + patient.getSalt()));
        return ConstantUtils.SUCCESS;
        return ConstantUtils.SUCCESS;
    }
    }
@ -65,7 +66,7 @@ public class PatientService extends BasePatientService {
            throw new NotFoundPatientException("当前居民不存在:【 " + id + "】");
            throw new NotFoundPatientException("当前居民不存在:【 " + id + "】");
        }
        }
        patient.setSalt(randomString(5));
        patient.setSalt(randomString(5));
        patient.setPassword(MD5.md5Hex(newPassword + "{" + patient.getSalt() + "}"));
        patient.setPassword(MD5.md5Hex(newPassword + patient.getSalt() ));
        return ConstantUtils.SUCCESS;
        return ConstantUtils.SUCCESS;
    }
    }
@ -100,17 +101,8 @@ public class PatientService extends BasePatientService {
        return patientDO;
        return patientDO;
    }
    }
    /**
     * 根据patient的id获取居民信息
     * @param patient
     * @return
     */
    public BasePatientDO findByIdAndDel(String patient) throws Exception{
        BasePatientDO basePatientDO = patientDao.findByIdAndDel(patient,"1");
        if(basePatientDO==null){
            throw new Exception("not patient");
        }
        return basePatientDO;
    public void updateOpenId(String openId){
    }
    }
}
}

+ 20 - 0
svr/svr-patient/src/main/java/com/yihu/jw/patient/util/CommonUtils.java

@ -0,0 +1,20 @@
package com.yihu.jw.patient.util;
import org.apache.commons.lang3.StringUtils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CommonUtils {
    public static boolean isMobile(String str) {
        boolean b = false;
        String s2="^[1](([3][0-9])|([4][5,7,9])|([5][^4,6,9])|([6][6])|([7][3,5,6,7,8])|([8][0-9])|([9][8,9]))[0-9]{8}$";// 验证手机号
        if(StringUtils.isNotBlank(str)){
            Pattern p = Pattern.compile(s2);
            Matcher m = p.matcher(str);
            b = m.matches();
        }
        return b;
    }
}

+ 32 - 2
svr/svr-patient/src/main/java/com/yihu/jw/patient/util/RSAService.java

@ -2,6 +2,7 @@ package com.yihu.jw.patient.util;
import java.io.*;
import java.io.*;
import java.security.*;
import java.security.*;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.interfaces.RSAPublicKey;
import java.util.Iterator;
import java.util.Iterator;
@ -10,10 +11,11 @@ import com.yihu.jw.entity.base.security.RSA;
import com.yihu.jw.patient.dao.security.RSADao;
import com.yihu.jw.patient.dao.security.RSADao;
import com.yihu.jw.util.common.RSAUtils;
import com.yihu.jw.util.common.RSAUtils;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
@Component
@Service
public class RSAService {
public class RSAService {
    @Autowired
    @Autowired
@ -149,4 +151,32 @@ public class RSAService {
        return obj;
        return obj;
    }
    }
    /**
     * 使用默认的私钥解密给定的字符串。
     * <p>
     * 若{@code encrypttext} 为 {@code null}或空字符串则返回 {@code null}。
     * 私钥不匹配时,返回 {@code null}。
     *
     * @param encrypttext 密文。
     * @return 原文字符串。
     */
    public String decryptString(String encrypttext) {
        if (StringUtils.isBlank(encrypttext)) {
            return null;
        }
        try {
            byte[] en_data = Hex.decodeHex(encrypttext.toCharArray());
            byte[] data =   RSAUtils.decrypt((RSAPrivateKey) getKeyPair().getPrivate(), en_data);
            return new String(data);
        } catch (NullPointerException ex) {
            ex.printStackTrace();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }
}
}