Kaynağa Gözat

Merge branch 'dev' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into dev

Trick 6 yıl önce
ebeveyn
işleme
36d03d09ea
27 değiştirilmiş dosya ile 794 ekleme ve 741 silme
  1. 2 5
      business/base-service/src/main/java/com/yihu/jw/message/service/MessageService.java
  2. 3 3
      business/base-service/src/main/java/com/yihu/jw/patient/dao/BasePatientDao.java
  3. 2 0
      business/base-service/src/main/java/com/yihu/jw/patient/dao/BasePatientMedicareCardDao.java
  4. 8 0
      business/base-service/src/main/java/com/yihu/jw/patient/service/BasePatientMedicardCardService.java
  5. 22 0
      business/base-service/src/main/java/com/yihu/jw/wechat/service/WeChatQrcodeService.java
  6. 51 0
      business/base-service/src/main/java/com/yihu/jw/wechat/service/WechatService.java
  7. 0 27
      common/common-entity/src/main/java/com/yihu/jw/entity/base/message/BaseMessageDO.java
  8. 122 254
      common/common-entity/src/main/java/com/yihu/jw/entity/base/patient/BasePatientDO.java
  9. 3 0
      common/common-request-mapping/src/main/java/com/yihu/jw/rm/patient/PatientRequestMapping.java
  10. 2 1
      server/svr-authentication/src/main/java/com/yihu/jw/security/core/userdetails/SaltUser.java
  11. 18 4
      server/svr-authentication/src/main/java/com/yihu/jw/security/core/userdetails/jdbc/WlyyUserDetailsService.java
  12. 2 2
      server/svr-authentication/src/main/java/com/yihu/jw/security/oauth2/provider/WlyyTokenGranter.java
  13. 103 2
      server/svr-authentication/src/main/java/com/yihu/jw/security/oauth2/provider/endpoint/WlyyLoginEndpoint.java
  14. 6 6
      svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/service/user/LoginService.java
  15. 13 2
      svr/svr-patient/sql/sql
  16. 4 1
      svr/svr-patient/src/main/java/com/yihu/jw/patient/dao/myFamily/PatientApplyLogDao.java
  17. 1 1
      svr/svr-patient/src/main/java/com/yihu/jw/patient/dao/myFamily/PatientFamilyMemberDao.java
  18. 0 11
      svr/svr-patient/src/main/java/com/yihu/jw/patient/dao/personal_info/PatientDao.java
  19. 60 15
      svr/svr-patient/src/main/java/com/yihu/jw/patient/endpoint/myFamily/MyFamilyEndpoint.java
  20. 18 46
      svr/svr-patient/src/main/java/com/yihu/jw/patient/endpoint/personal_info/PatientEndpoint.java
  21. 19 1
      svr/svr-patient/src/main/java/com/yihu/jw/patient/endpoint/wechat/WechatEndPoint.java
  22. 182 100
      svr/svr-patient/src/main/java/com/yihu/jw/patient/service/myFamily/MyFamilyService.java
  23. 4 0
      svr/svr-patient/src/main/java/com/yihu/jw/patient/service/myFamily/PatientApplyLogService.java
  24. 0 3
      svr/svr-patient/src/main/java/com/yihu/jw/patient/service/personal_Info/PatientMedicareCardService.java
  25. 139 68
      svr/svr-patient/src/main/java/com/yihu/jw/patient/service/personal_Info/PatientService.java
  26. 0 182
      svr/svr-patient/src/main/java/com/yihu/jw/patient/util/RSAService.java
  27. 10 7
      svr/svr-patient/src/main/resources/application.yml

+ 2 - 5
business/base-service/src/main/java/com/yihu/jw/message/service/MessageService.java

@ -2,7 +2,6 @@ package com.yihu.jw.message.service;
import com.yihu.jw.entity.base.message.BaseMessageDO;
import com.yihu.jw.message.dao.MessageDao;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
@ -10,7 +9,6 @@ import org.springframework.data.domain.Sort;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@ -104,9 +102,8 @@ public class MessageService extends BaseJpaService<BaseMessageDO, MessageDao> {
    }
    public List<Map<String, Object>> applyMessageList(String patient, Date failureTime, String msgTypeCode){
        String failureTimeStr = DateUtil.dateToStr(failureTime,"yyyy-MM-dd HH:mm:ss");
        String sql = "select m.* from base_message m join patient_apply_for_log l on m.relation_data=l.id where m.failure_Time>='"+failureTimeStr+"' and m.msgTypeCode='"+msgTypeCode+"'";
    public List<Map<String, Object>> applyMessageList(String patient, String msgTypeCode){
        String sql = "select m.* from base_message m join patient_apply_for_log l on m.relation_data=l.id where  m.msg_type_code='"+msgTypeCode+"' and m.receiver='"+patient+"'";
        return jdbcTemplate.queryForList(sql);
//        return messageDao.applyMessageList(patient,failureTime,msgTypeCode);
    }

+ 3 - 3
business/base-service/src/main/java/com/yihu/jw/patient/dao/BasePatientDao.java

@ -17,13 +17,13 @@ public interface BasePatientDao extends PagingAndSortingRepository<BasePatientDO
    BasePatientDO findByIdAndDel(String id, String del);
    @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")
    @Query("select id as id,idcard as idcard,name as name,case sex when 1 then '男' when 2 then '女' else '未知' end as sex,mobile 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")
    @Query("select id as id,idcard as idcard,name as name,case sex when 1 then '男' when 2 then '女' else '未知' end as sex,mobile 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")
    @Query("select id as id,idcard as idcard,name as name,case sex when 1 then '男' when 2 then '女' else '未知' end as sex,mobile as phone,committeeName as committeeName,concat(provinceName,cityName,townName,streetName) as address from BasePatientDO")
    List<Map<String,Object>> findBaseInfo(Pageable pageable);
    boolean existsByIdcardAndIdNot(String idcard,String id);

+ 2 - 0
business/base-service/src/main/java/com/yihu/jw/patient/dao/BasePatientMedicareCardDao.java

@ -19,4 +19,6 @@ public interface BasePatientMedicareCardDao extends PagingAndSortingRepository<P
    Set<Object> findIdListByPatientCode(String patientCode);
    PatientMedicareCardDO findByCode(String code);
    PatientMedicareCardDO findByTypeAndPatientCodeAndDel(String Type,String patientCode,String del);
}

+ 8 - 0
business/base-service/src/main/java/com/yihu/jw/patient/service/BasePatientMedicardCardService.java

@ -70,4 +70,12 @@ public class BasePatientMedicardCardService<T, R extends CrudRepository> extends
        return patientMedicareCard;
    }
    public PatientMedicareCardDO findByTypeAndPatientCodeAndDel(String Type,String patientCode,String del)throws Exception{
        PatientMedicareCardDO patientMedicareCardDO = basePatientMedicareCardDao.findByTypeAndPatientCodeAndDel(Type,patientCode,del);
        if(patientMedicareCardDO==null){
            throw new Exception("no PatientMedicareCard entity");
        }
        return patientMedicareCardDO;
    }
}

+ 22 - 0
business/base-service/src/main/java/com/yihu/jw/wechat/service/WeChatQrcodeService.java

@ -95,6 +95,28 @@ public class WeChatQrcodeService {
        return "";
    }
    public String getQrcode( String wechatId, String scene) throws Exception{
        String token_url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + wxAccessTokenService.getWxAccessTokenById(wechatId).getAccessToken();
        String params = "{\"action_name\": \"QR_LIMIT_STR_SCENE\", \"action_info\": {\"scene\": {\"scene_str\": \"" + scene + "\"}}}";
        //服务号必须是通过腾讯认证,每年是300元,如果没有认证而导致的错误提示,那就去认证
        //微信登录提示48001,{"errcode":48001,"errmsg":"api unauthorized, hints: [ req_id: 1QoCla0699ns81 ]"}
        String result = HttpUtil.sendPost(token_url, params);
        if (!StringUtils.isEmpty(result)) {
            JSONObject json = new JSONObject(result);
            if (json.has("ticket")) {
                // 请求输入流
                InputStream inputStream = null;
                // 下载二维码图片
                String  urlGet = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket="
                        + URLEncoder.encode(json.get("ticket").toString(), "UTF-8");
                return urlGet;
            }
        }
        return "";
    }
//    public void write(InputStream inputStream)throws Exception{
//        String file = "D:\\workspace\\file\\test.png";
//        // 保存文件

+ 51 - 0
business/base-service/src/main/java/com/yihu/jw/wechat/service/WechatService.java

@ -0,0 +1,51 @@
package com.yihu.jw.wechat.service;
import com.yihu.jw.entity.base.wx.WxWechatDO;
import com.yihu.jw.util.wechat.wxhttp.HttpUtil;
import com.yihu.jw.wechat.dao.WechatDao;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class WechatService {
    @Autowired
    private WechatDao wechatDao;
    /**
     * 通过code获取判断openid
     *
     * @param code
     * @return
     */
    public String getOpenidByCode(String code,String appId,String appSecret) {
        try {
            String token_url = "https://api.weixin.qq.com/sns/oauth2/access_token";
            String params = "appid=" + appId + "&secret=" +appSecret+ "&code=" + code + "&grant_type=authorization_code";
            String result = HttpUtil.sendGet(token_url, params);
            System.out.println("getOpenidByCode:"+result);
            JSONObject json = new JSONObject(result);
            if (json.has("openid")) {
                return json.get("openid").toString();
            } else {
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
     * 通过code获取判断openid
     *
     * @param code
     * @return
     */
    public String getOpenidByCode(String code,String wxId) {
        //通过wxId获取appId和appSecret
        WxWechatDO wxWechatDO = wechatDao.findById(wxId);
        return getOpenidByCode(code,wxWechatDO.getAppId(),wxWechatDO.getAppSecret());
    }
}

+ 0 - 27
common/common-entity/src/main/java/com/yihu/jw/entity/base/message/BaseMessageDO.java

@ -113,16 +113,6 @@ public class BaseMessageDO extends IntegerIdentityEntity {
     */
    private String relationData;
    /**
     * 消息存续类型(1、时效性,2、非时效性)
     */
    private Integer type;
    /**
     * 消息失效时间
     */
    private Date failureTime;
    @Column(name = "receiver")
    public String getReceiver() {
        return receiver;
@ -294,21 +284,4 @@ public class BaseMessageDO extends IntegerIdentityEntity {
        this.relationData = relationData;
    }
    @Column(name = "type")
    public Integer getType() {
        return type;
    }
    public void setType(Integer type) {
        this.type = type;
    }
    @Column(name = "failure_time")
    public Date getFailureTime() {
        return failureTime;
    }
    public void setFailureTime(Date failureTime) {
        this.failureTime = failureTime;
    }
}

+ 122 - 254
common/common-entity/src/main/java/com/yihu/jw/entity/base/patient/BasePatientDO.java

@ -2,81 +2,77 @@ package com.yihu.jw.entity.base.patient;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.Range;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;
/**
* 居民信息(居民就是患者)实体
*
* @author Administrator on  2018年09月05日
*
*/
 * 居民信息(居民就是患者)实体
 *
 * @author Administrator on  2018年09月05日
 *
 */
@Entity
@Table(name = "base_patient")
public class BasePatientDO extends UuidIdentityEntityWithOperator {
    /**
	 * saas配置id
	 */
     * saas配置id
     */
//    @NotNull(message = "saasid不可为空")
	private String saasId;
    private String saasId;
    /**
	 * 身份证号
	 */
     * 身份证号
     */
//    @NotNull(message = "身份证号不可为空")
	private String idcard;
    private String idcard;
    /**
	 * 登录密码
	 */
	private String password;
     * 登录密码
     */
    private String password;
    /**
	 *
	 */
	private String salt;
     *
     */
    private String salt;
    /**
	 * 姓名
	 */
	private String name;
     * 姓名
     */
    private String name;
    /**
	 * 生日
	 */
     * 生日
     */
//	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	private Date birthday;
    private Date birthday;
    /**
	 * 性别,1男,2女
	 */
     * 性别,1男,2女
     */
//    @Range(min = 1, max = 2, message = "1-男,2-女")
	private Integer sex;
    private Integer sex;
    /**
	 * 手机号
	 */
     * 手机号
     */
//    @Length(min = 11,max = 11,message = "手机号长度为11位")
	private String mobile;
    private String mobile;
    /**
	 * 联系电话
	 */
	private String phone;
    /**
     * 社保卡号
     */
	private String ssc;
    /**
	 * 头像http地址
	 */
	private String photo;
     * 头像http地址
     */
    private String photo;
    /**
     * 省代码
@ -117,31 +113,62 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
     * 街道名称
     */
    private String streetName;
    /**
     * 居住居委会代码
     * 地址
     */
    private String committeeCode;
    private String address;
    /**
     * 居住居委会名称
     * 居住省代码
     */
    private String committeeName;
    private String liveProvinceCode;
    /**
     * 地址
     * 居住省名称
     */
    private String address;
    private String liveProvinceName;
    /**
     * 居住市代码
     */
    private String liveCityCode;
    /**
     * 居住市名称
     */
    private String liveCityName;
    /**
     * 居住区县代码
     */
    private String liveTownCode;
    /**
     * 居住区县名称
     */
    private String liveTownName;
    /**
     * 疾病类型,0健康,1高血压,2糖尿病,3高血压+糖尿病
     * 居住街道代码
     */
    private String liveStreetCode;
    /**
     * 居住街道名称
     */
    private String disease;
    private String liveStreetName;
    /**
     * 病情:0绿标,1黄标,2红标,3重点关注
     * 居住居委会代码
     */
    private String diseaseCondition;
    private String committeeCode;
    /**
     * 居住居委会名称
     */
    private String committeeName;
    /**
     * 总积分
@ -179,37 +206,11 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
     */
    private String principalCode;
    /**
     * 是否绑定电子社保卡 (0否 1是)
     */
    private String sicardStatus;
    /**
     * 电子社保卡绑定时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    private Date sicardTime;
    /**
     * 是否分配过微信标签
     */
    private Integer isWxtag;
    /**
     * 微信tagId
     */
    private String wxtagid;
    /**
     * 居民预警状态:0为标准,1为预警状态
     */
    private Integer standardStatus;
    /**
     * 医疗保险号
     */
    private String medicareNumber;
    /**
     * unionId 开发平台唯一标识
     */
@ -220,82 +221,38 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
     */
    private String del;
    /**
     * 登录时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    private Date loginDate;
    /**
     * 锁定时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    private Date lockedDate;
    /**
     * 是否被锁定;1为锁定,0为可用
     */
    private Integer locked;
    /**
     * 是否可用
     */
    private Integer enabled;
    /**
     * 备注
     */
    private String remark;
    /**
     * 登录失败次数
     */
    private Integer loginFailureCount;
    /**
     * 居住区县代码
     * 账号是否被锁定
     */
    private String liveTownCode;
    private int locked;
    /**
     * 居住区县名称
     * 是否可以登录
     */
    private String liveTownName;
    private int enabled;
    /**
     * 居住市代码
     */
    private String liveCityCode;
    /**
     * 居住市名称
     * 登录失败次数
     */
    private String liveCityName;
    private int loginFailureCount;
    /**
     * 居住省代码
     * 锁定日期
     */
    private String liveProvinceCode;
    /**
     * 居住省名称
     */
    private String liveProvinceName;
    private Date lockedDate;
    /**
     * 居住街道代码
     * 登录日期
     */
    private String liveStreetCode;
    /**
     * 居住街道名称
     */
    private String liveStreetName;
    private Date loginDate;
	@Column(name = "saas_id")
    @Column(name = "saas_id")
    public String getSaasId() {
        return saasId;
    }
@ -303,7 +260,7 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
        this.saasId = saasId;
    }
	@Column(name = "idcard")
    @Column(name = "idcard")
    public String getIdcard() {
        return idcard;
    }
@ -311,7 +268,7 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
        this.idcard = idcard;
    }
	@Column(name = "password")
    @Column(name = "password")
    public String getPassword() {
        return password;
    }
@ -319,7 +276,7 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
        this.password = password;
    }
	@Column(name = "salt")
    @Column(name = "salt")
    public String getSalt() {
        return salt;
    }
@ -327,7 +284,7 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
        this.salt = salt;
    }
	@Column(name = "name")
    @Column(name = "name")
    public String getName() {
        return name;
    }
@ -335,7 +292,7 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
        this.name = name;
    }
	@Column(name = "birthday")
    @Column(name = "birthday")
    public Date getBirthday() {
        return birthday;
    }
@ -343,7 +300,7 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
        this.birthday = birthday;
    }
	@Column(name = "sex")
    @Column(name = "sex")
    public Integer getSex() {
        return sex;
    }
@ -351,7 +308,7 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
        this.sex = sex;
    }
	@Column(name = "mobile")
    @Column(name = "mobile")
    public String getMobile() {
        return mobile;
    }
@ -359,15 +316,7 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
        this.mobile = mobile;
    }
	@Column(name = "phone")
    public String getPhone() {
        return phone;
    }
    public void setPhone(String phone) {
        this.phone = phone;
    }
	@Column(name = "photo")
    @Column(name = "photo")
    public String getPhoto() {
        return photo;
    }
@ -474,7 +423,7 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
        this.points = points;
    }
	@Column(name = "record_amount")
    @Column(name = "record_amount")
    public String getRecordAmount() {
        return recordAmount;
    }
@ -482,7 +431,7 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
        this.recordAmount = recordAmount;
    }
	@Column(name = "openid")
    @Column(name = "openid")
    public String getOpenid() {
        return openid;
    }
@ -490,7 +439,7 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
        this.openid = openid;
    }
	@Column(name = "patient_status")
    @Column(name = "patient_status")
    public String getPatientStatus() {
        return patientStatus;
    }
@ -498,7 +447,7 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
        this.patientStatus = patientStatus;
    }
	@Column(name = "mobile_remarks")
    @Column(name = "mobile_remarks")
    public String getMobileRemarks() {
        return mobileRemarks;
    }
@ -506,7 +455,7 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
        this.mobileRemarks = mobileRemarks;
    }
	@Column(name = "openid_time")
    @Column(name = "openid_time")
    public Date getOpenidTime() {
        return openidTime;
    }
@ -514,7 +463,7 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
        this.openidTime = openidTime;
    }
	@Column(name = "principal_code")
    @Column(name = "principal_code")
    public String getPrincipalCode() {
        return principalCode;
    }
@ -522,39 +471,7 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
        this.principalCode = principalCode;
    }
	@Column(name = "sicard_status")
    public String getSicardStatus() {
        return sicardStatus;
    }
    public void setSicardStatus(String sicardStatus) {
        this.sicardStatus = sicardStatus;
    }
	@Column(name = "sicard_time")
    public Date getSicardTime() {
        return sicardTime;
    }
    public void setSicardTime(Date sicardTime) {
        this.sicardTime = sicardTime;
    }
	@Column(name = "is_wxtag")
    public Integer getIsWxtag() {
        return isWxtag;
    }
    public void setIsWxtag(Integer isWxtag) {
        this.isWxtag = isWxtag;
    }
	@Column(name = "wxtagid")
    public String getWxtagid() {
        return wxtagid;
    }
    public void setWxtagid(String wxtagid) {
        this.wxtagid = wxtagid;
    }
	@Column(name = "standard_status")
    @Column(name = "standard_status")
    public Integer getStandardStatus() {
        return standardStatus;
    }
@ -562,7 +479,7 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
        this.standardStatus = standardStatus;
    }
	@Column(name = "unionid")
    @Column(name = "unionid")
    public String getUnionid() {
        return unionid;
    }
@ -570,7 +487,7 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
        this.unionid = unionid;
    }
	@Column(name = "del")
    @Column(name = "del")
    public String getDel() {
        return del;
    }
@ -578,16 +495,14 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
        this.del = del;
    }
    @Column(name = "remark")
    public String getRemark() {
        return remark;
    }
    @Column(name = "remark")
    public void setRemark(String remark) {
        this.remark = remark;
    }
    @Column(name = "live_province_code")
    public String getLiveProvinceCode() {
        return liveProvinceCode;
    }
@ -596,7 +511,6 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
        this.liveProvinceCode = liveProvinceCode;
    }
    @Column(name = "live_province_name")
    public String getLiveProvinceName() {
        return liveProvinceName;
    }
@ -605,7 +519,6 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
        this.liveProvinceName = liveProvinceName;
    }
    @Column(name = "live_city_code")
    public String getLiveCityCode() {
        return liveCityCode;
    }
@ -614,7 +527,6 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
        this.liveCityCode = liveCityCode;
    }
    @Column(name = "live_city_name")
    public String getLiveCityName() {
        return liveCityName;
    }
@ -623,7 +535,6 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
        this.liveCityName = liveCityName;
    }
    @Column(name = "live_town_code")
    public String getLiveTownCode() {
        return liveTownCode;
    }
@ -632,7 +543,6 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
        this.liveTownCode = liveTownCode;
    }
    @Column(name = "live_town_name")
    public String getLiveTownName() {
        return liveTownName;
    }
@ -658,53 +568,30 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
        this.liveStreetName = liveStreetName;
    }
    @Column(name = "ssc")
    public String getSsc() {
        return ssc;
    }
    public void setSsc(String ssc) {
        this.ssc = ssc;
    }
    @Column(name = "disease")
    public String getDisease() {
        return disease;
    }
    public void setDisease(String disease) {
        this.disease = disease;
    }
    @Column(name = "disease_condition")
    public String getDiseaseCondition() {
        return diseaseCondition;
    public int getLocked() {
        return locked;
    }
    public void setDiseaseCondition(String diseaseCondition) {
        this.diseaseCondition = diseaseCondition;
    public void setLocked(int locked) {
        this.locked = locked;
    }
    @Column(name = "medicare_number")
    public String getMedicareNumber() {
        return medicareNumber;
    public int getEnabled() {
        return enabled;
    }
    public void setMedicareNumber(String medicareNumber) {
        this.medicareNumber = medicareNumber;
    public void setEnabled(int enabled) {
        this.enabled = enabled;
    }
    @Column(name = "login_date")
    public Date getLoginDate() {
        return loginDate;
    public int getLoginFailureCount() {
        return loginFailureCount;
    }
    public void setLoginDate(Date loginDate) {
        this.loginDate = loginDate;
    public void setLoginFailureCount(int loginFailureCount) {
        this.loginFailureCount = loginFailureCount;
    }
    @Column(name = "locked_date")
    public Date getLockedDate() {
        return lockedDate;
    }
@ -713,30 +600,11 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
        this.lockedDate = lockedDate;
    }
    @Column(name = "locked")
    public Integer getLocked() {
        return locked;
    }
    public void setLocked(Integer locked) {
        this.locked = locked;
    }
    @Column(name = "enabled")
    public Integer getEnabled() {
        return enabled;
    }
    public void setEnabled(Integer enabled) {
        this.enabled = enabled;
    }
    @Column(name = "login_failure_count")
    public Integer getLoginFailureCount() {
        return loginFailureCount;
    public Date getLoginDate() {
        return loginDate;
    }
    public void setLoginFailureCount(Integer loginFailureCount) {
        this.loginFailureCount = loginFailureCount;
    public void setLoginDate(Date loginDate) {
        this.loginDate = loginDate;
    }
}

+ 3 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/patient/PatientRequestMapping.java

@ -54,10 +54,13 @@ public class PatientRequestMapping {
        public static final String bindingMyFamily  = "/bindingMyFamily";
        public static final String createFamilyQrCode  = "/createFamilyQrCode";
        public static final String remindMyFamily  = "/remindMyFamily";
        public static final String scanQRcodeConfirmApply  = "/scanQRcodeConfirmApply";
        public static final String confirmApply  = "/confirmApply";
        public static final String applyMessageList  = "/applyMessageList";
        public static final String cancelApply  = "/cancelApply";
        public static final String myFamilyBindList  = "/myFamilyBindList";
        public static final String scanQRcode  = "/scanQRcode";
        public static final String messageToBinding  = "/messageToBinding";
    }

+ 2 - 1
server/svr-authentication/src/main/java/com/yihu/jw/security/core/userdetails/SaltUser.java

@ -36,7 +36,8 @@ public class SaltUser implements UserDetails, CredentialsContainer {
    }
    public SaltUser(String username, String password, String salt, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities) {
        if(username != null && !"".equals(username) && password != null) {
        //居民使用验证码注册,密码没有默认值, 可能为空 password != null
        if(username != null && !"".equals(username)) {
            this.username = username;
            this.password = password;
            this.salt = salt;

+ 18 - 4
server/svr-authentication/src/main/java/com/yihu/jw/security/core/userdetails/jdbc/WlyyUserDetailsService.java

@ -5,6 +5,7 @@ import com.yihu.jw.security.model.WlyyUserDetails;
import com.yihu.jw.security.model.WlyyUserSimple;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
@ -19,10 +20,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
@ -37,6 +35,10 @@ public class WlyyUserDetailsService extends JdbcDaoSupport implements UserDetail
    private static final String DEFAULT_PATIENT_DETAILS_STATEMENT = "SELECT * FROM base_patient p WHERE p.mobile = ? OR p.idcard = ?";
    private static final String BespeakRegist = "bespeakRegist:";
    @Autowired
    private StringRedisTemplate redisTemplate;
    public WlyyUserDetailsService(DataSource dataSource) {
        this.setDataSource(dataSource);
@ -102,6 +104,14 @@ public class WlyyUserDetailsService extends JdbcDaoSupport implements UserDetail
            users = this.getJdbcTemplate().query(DEFAULT_DOCTOR_DETAILS_STATEMENT, new BeanPropertyRowMapper(WlyyUserDetails.class), username, username);
            //3.患者登录
        }else if("3".equals(loginType)){
            //查找是否存在预注册 用户
            String userName = redisTemplate.opsForValue().get(BespeakRegist + username);
            if(StringUtils.isNotBlank(userName)){
                //保存到数据库
                this.getJdbcTemplate().execute("update base_patient set del=1 where mobile='"+username+"'");
                redisTemplate.opsForValue().get(BespeakRegist + username);
                redisTemplate.delete(BespeakRegist+username);
            }
            users = this.getJdbcTemplate().query(DEFAULT_PATIENT_DETAILS_STATEMENT, new BeanPropertyRowMapper(WlyyUserDetails.class), username, username);
        }//..
        return users;
@ -260,4 +270,8 @@ public class WlyyUserDetailsService extends JdbcDaoSupport implements UserDetail
        }
        return true;
    }
    public void updateOpenId(String openid,String userId){
        this.getJdbcTemplate().update("update base_patient p set p.openid = ? where p.id= ?",openid ,userId);
    }
}

+ 2 - 2
server/svr-authentication/src/main/java/com/yihu/jw/security/oauth2/provider/WlyyTokenGranter.java

@ -315,9 +315,9 @@ public class WlyyTokenGranter implements TokenGranter {
            String username = parameters.get("username");
            String captcha = parameters.get("captcha");
            if (!wlyyRedisVerifyCodeService.verification(client_id, username, captcha)){
           /* if (!wlyyRedisVerifyCodeService.verification(client_id, username, captcha)){
                throw new InvalidGrantException("Invalid captcha");
            }
            }*/
            SaltUser userDetails = (SaltUser)userDetailsService.loadUserByUsername(username);
            if (!userDetails.isEnabled()) {

+ 103 - 2
server/svr-authentication/src/main/java/com/yihu/jw/security/oauth2/provider/endpoint/WlyyLoginEndpoint.java

@ -166,9 +166,12 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
        wlyyUserSimple.setState(parameters.get("state"));
        String loginType = parameters.get("login_type");
        String openid = parameters.get("openid");
        //更新患者openId
        if(!StringUtils.isEmpty(openid) && !"undefined".equalsIgnoreCase(openid) && "3".equalsIgnoreCase(loginType)){
            userDetailsService.updateOpenId(openid,wlyyUserSimple.getId());
        }
        userDetailsService.setRolePhth(loginType,token,wlyyUserSimple.getId(),redisTemplate);
        return getResponse(wlyyUserSimple);
    }
@ -372,6 +375,95 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
        return new ResponseEntity<>(oauth2Envelop, headers, HttpStatus.OK);
    }
    /**
     * 登陆
     * @param parameters
     * 不定入参:
     * login_type 用户类型 1或默认为user,2:医生登录,3:患者登录
     * mobile:手机号
     * captcha:验证码
     * clientId:
     * login_type 用户类型 1或默认为user,2:医生登录,3:患者登录
     * @param httpSession
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/oauth/registAndLogin", method = RequestMethod.POST)
    public ResponseEntity<Oauth2Envelop<WlyyUserSimple>> registAndLogin(@RequestParam Map<String, String> parameters, HttpSession httpSession) throws Exception {
        //用于标记是否注册成功
        boolean registFlag = false;
        String client_id = parameters.get("client_id");
        if (StringUtils.isEmpty(client_id)) {
            throw new InvalidRequestException("client_id is null");
        }
        String type = parameters.get("login_type");
        if (StringUtils.isEmpty(type)) {
            throw new InvalidRequestException("regist type is null");
        }
        //type :1居民  2:医生
        if("3".equals(type)){
            String mobile = parameters.get("mobile");
            String captcha = parameters.get("captcha");
            HttpHeaders reqHeaders = new HttpHeaders();
            MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
            params.add("mobile", mobile);
            params.add("captcha", captcha);
            params.add("openid", parameters.get("openid"));
            HttpEntity<MultiValueMap<String, String>> httpEntity = new HttpEntity<>(params, reqHeaders);
            Map<String, Object> result = restTemplate.postForObject("http://svr-patient-111:10021/basePatient/regist", httpEntity, HashMap.class);//svr-patient
            Map<String,Object> obj = (Map<String, Object>) result.get("obj");
            if("1".equals(obj.get("code"))){
                registFlag = true;
                parameters.put("username",mobile);
                wlyyRedisVerifyCodeService.store(client_id, mobile, captcha, 120);
            }else{
                return getFailedResponse(obj.get("message").toString(),-1,null);
            }
        }else{
            return getFailedResponse("暂不提供其他类型人员注册",-1,null);
        }
        if(registFlag){
            parameters.put("grant_type", "captcha");
            ClientDetails authenticatedClient = clientDetailsService.loadClientByClientId(client_id);
            TokenRequest tokenRequest = oAuth2RequestFactory.createTokenRequest(parameters, authenticatedClient);
            if (authenticatedClient != null) {
                oAuth2RequestValidator.validateScope(tokenRequest, authenticatedClient);
            }
            OAuth2AccessToken token = getTokenGranter().grant(tokenRequest.getGrantType(), tokenRequest);
            if (token == null) {
                throw new UnsupportedGrantTypeException("Unsupported grant type: " + tokenRequest.getGrantType());
            }
            /*如果是移动端登陆则移除之前的token,
            在网关处通过HTTP状态码告知前端是过期(402)还是账号在别处登陆(403),
            实现同一账号只能在一处登陆*/
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            if (request.getHeader("login-device") != null && request.getHeader("login-device").equals("mobile")) {
                tokenStore.removeAccessToken(token.getValue());
                tokenStore.removeRefreshToken(token.getRefreshToken().getValue());
                token = getTokenGranter().grant(tokenRequest.getGrantType(), tokenRequest);
            }
            if (token == null) {
                throw new UnsupportedGrantTypeException("Unsupported grant type: " + tokenRequest.getGrantType());
            }
            WlyyUserSimple wlyyUserSimple = userDetailsService.authSuccess(parameters.get("username"));
            wlyyUserSimple.setAccessToken(token.getValue());
            wlyyUserSimple.setTokenType(token.getTokenType());
            wlyyUserSimple.setExpiresIn(token.getExpiresIn());
            wlyyUserSimple.setRefreshToken(token.getRefreshToken().getValue());
            wlyyUserSimple.setUser(parameters.get("username"));
            wlyyUserSimple.setState(parameters.get("state"));
            String loginType = parameters.get("login_type");
            userDetailsService.setRolePhth(loginType,token,wlyyUserSimple.getId(),redisTemplate);
            return getResponse(wlyyUserSimple);
        }
        return null;
    }
    @Override
    protected TokenGranter getTokenGranter() {
        return this.tokenGranter;
@ -392,6 +484,15 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
        return new ResponseEntity<>(oauth2Envelop, headers, HttpStatus.OK);
    }
    private ResponseEntity<Oauth2Envelop<WlyyUserSimple>> getFailedResponse(String message ,int status,WlyyUserSimple ehrUserSimple) {
        HttpHeaders headers = new HttpHeaders();
        headers.set("Cache-Control", "no-store");
        headers.set("Pragma", "no-cache");
        Oauth2Envelop<WlyyUserSimple> oauth2Envelop = new Oauth2Envelop<>(message, status, ehrUserSimple);
        return new ResponseEntity<>(oauth2Envelop, headers, HttpStatus.OK);
    }
    @Override
    protected WebResponseExceptionTranslator getExceptionTranslator() {
        return wlyyOAuth2ExceptionTranslator;

+ 6 - 6
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/service/user/LoginService.java

@ -250,12 +250,12 @@ public class LoginService  extends BaseJpaService {
        ObjectMapper objectMapper = new ObjectMapper();
        HashMap<String, Object> result = objectMapper.readValue(resultStr,HashMap.class);
            Long expire = 600L;
            wlyyRedisVerifyCodeService.store(clientId, phone, captcha, expire.intValue());
            HttpHeaders headers = new HttpHeaders();
            headers.set("Cache-Control", "no-store");
            headers.set("Pragma", "no-cache");
            return new ResponseEntity<>(result, headers, HttpStatus.OK);
        Long expire = 600L;
        wlyyRedisVerifyCodeService.store(clientId, phone, captcha, expire.intValue());
        HttpHeaders headers = new HttpHeaders();
        headers.set("Cache-Control", "no-store");
        headers.set("Pragma", "no-cache");
        return new ResponseEntity<>(result, headers, HttpStatus.OK);
    }

+ 13 - 2
svr/svr-patient/sql/sql

@ -40,7 +40,6 @@ create table `feedback`
  `id` int(11) NOT NULL AUTO_INCREMENT  COMMENT '表id,自增长',
  `type` varchar(1) DEFAULT NULL COMMENT '问题类型(功能异常-无法使用功能,功能优化-不好用、界面难看,新功能建议-你希望有什么功能,其他-其他任何问题)',
  `feedback_content` varchar(100) not null COMMENT '反馈内容,问题和建议',
  `answer` varchar(500) not null COMMENT '问题回答',
  `img` varchar(1000) not null COMMENT '图片,存图片地址,逗号分割',
  `mobile` varchar(11) not null COMMENT '联系手机号码',
  primary key (id)
@ -97,4 +96,16 @@ CREATE TABLE `base_patient_family_member` (
  `create_user_name` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fmaily_member_patient` (`patient`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='居民家庭成员表';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='居民家庭成员表';
-- 居民表多余字段删除
alter table base_patient drop column ssc;
alter table base_patient drop column disease;
alter table base_patient drop column disease_condition;
alter table base_patient drop column principal_code;
alter table base_patient drop column sicard_status;
alter table base_patient drop column sicard_time;
alter table base_patient drop column is_wxtag;
alter table base_patient drop column wxtagid;
alter table base_patient drop column medicare_number;

+ 4 - 1
svr/svr-patient/src/main/java/com/yihu/jw/patient/dao/myFamily/PatientApplyLogDao.java

@ -1,12 +1,13 @@
package com.yihu.jw.patient.dao.myFamily;
import com.sun.tools.javac.util.List;
import com.yihu.jw.entity.myFamily.PatientApplyLog;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.Date;
/**
 * @author liuwenbin on 2018/11/30.
 */
@ -22,4 +23,6 @@ public interface PatientApplyLogDao extends PagingAndSortingRepository<PatientAp
    @Query("update PatientApplyLog t set t.status = ?1 where t.id=?2 ")
    int updateStatusById(Integer status,Integer id);
    @Query("select l from PatientApplyLog l where l.createUser=?1 and l.familyMemberCode=?2 and l.del=1 and l.status in(1,2) and l.failureTime<?3 and l.familyBindRole=?4")
    PatientApplyLog findValidOne(String createUser,String familyMemberCode,Date failureTime,Integer familyBindRole);
}

+ 1 - 1
svr/svr-patient/src/main/java/com/yihu/jw/patient/dao/myFamily/PatientFamilyMemberDao.java

@ -27,6 +27,6 @@ public interface PatientFamilyMemberDao extends PagingAndSortingRepository<BaseP
    @Query("select m from BasePatientFamilyMemberDO m where m.del=1 and m.familyMember=?1 and m.familyRelation in (?2,?3)")
    List<BasePatientFamilyMemberDO> getByFamilyMemberAndFamilyRelation(String familyMember,Integer familyRelation1,Integer familyRelation2);
    @Query("select m from BasePatientFamilyMemberDO m where m.del=1 and (m.familyMember=?1 or m.patient=?1)")
    @Query("select m from BasePatientFamilyMemberDO m where m.del=1 and m.patient=?1")
    List<BasePatientFamilyMemberDO> getByPatientAndFamilyMember(String patient);
}

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

@ -16,15 +16,4 @@ import java.util.Map;
public interface PatientDao extends PagingAndSortingRepository<BasePatientDO, String>, JpaSpecificationExecutor<BasePatientDO> {
    BasePatientDO findByIdAndDel(String id, String del);
    @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);
}

+ 60 - 15
svr/svr-patient/src/main/java/com/yihu/jw/patient/endpoint/myFamily/MyFamilyEndpoint.java

@ -1,7 +1,5 @@
package com.yihu.jw.patient.endpoint.myFamily;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.myFamily.PatientApplyLog;
import com.yihu.jw.patient.service.myFamily.MyFamilyService;
import com.yihu.jw.patient.service.personal_Info.PatientService;
import com.yihu.jw.restmodel.web.Envelop;
@ -13,7 +11,6 @@ import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@ -65,14 +62,12 @@ public class MyFamilyEndpoint extends EnvelopRestEndpoint {
    public Envelop bindingMyFamily(
            @ApiParam(name = "patient", value = "居民code", required = false)
            @RequestParam(value = "patient",required = false) String patient,
            @ApiParam(name = "wechatId", value = "wechatId", required = true)
            @RequestParam(value = "wechatId",required = true) String wechatId,
            @ApiParam(name = "familyMobile", value = "家人的手机号码", required = true)
            @RequestParam(value = "familyMobile",required = true) String familyMobile,
            @ApiParam(name = "familyBindRole", value = "家庭关系关系 1配偶 2父亲 3母亲 4公公 5婆婆 6岳父 7岳母 8子女", required = true)
            @RequestParam(value = "familyBindRole",required = true) Integer familyBindRole,HttpServletRequest request) throws Exception {
            @RequestParam(value = "familyBindRole",required = true) Integer familyBindRole) throws Exception {
        try{
            PatientApplyLog patientApplyLog = myFamilyService.bindingMyFamily(request,wechatId, getUID(patient), familyMobile, 1,familyBindRole);
            Map<String,Object> patientApplyLog = myFamilyService.bindingMyFamily( getUID(patient), familyMobile, 1,familyBindRole);
            return success(patientApplyLog);
        }catch (Exception e){
            e.printStackTrace();
@ -85,16 +80,13 @@ public class MyFamilyEndpoint extends EnvelopRestEndpoint {
    public Envelop createFamilyQrCode(
            @ApiParam(name = "patient", value = "居民code", required = false)
            @RequestParam(value = "patient",required = false) String patient,
            @ApiParam(name = "familyMobile", value = "家人的手机号码", required = true)
            @RequestParam(value = "familyMobile",required = true) String familyMobile,
            @ApiParam(name = "wechatId", value = "wechatId", required = true)
            @RequestParam(value = "wechatId",required = true) String wechatId,
            @ApiParam(name = "familyBindRole", value = "家庭关系关系 1配偶 2父亲 3母亲 4公公 5婆婆 6岳父 7岳母 8子女", required = true)
            @RequestParam(value = "familyBindRole",required = true) Integer familyBindRole,HttpServletRequest request) throws Exception {
            @RequestParam(value = "familyBindRole",required = true) Integer familyBindRole) throws Exception {
        try{
            BasePatientDO familyPatient = patientService.findByMobileAndDel(familyMobile);
            PatientApplyLog patientApplyLog = myFamilyService.createFamilyQrCode(request,familyPatient,wechatId, getUID(patient),familyBindRole);
            return success(patientApplyLog.getQrCode());
            Map<String,Object> resultMap = myFamilyService.createFamilyQrCode(wechatId, getUID(patient),familyBindRole);
            return success(resultMap);
        }catch (Exception e){
            e.printStackTrace();
            return failed(e.getMessage());
@ -118,7 +110,7 @@ public class MyFamilyEndpoint extends EnvelopRestEndpoint {
    }
    @GetMapping(value = PatientRequestMapping.MyFamily.applyMessageList)
    @ApiOperation(value = "有效的申请绑定消息")
    @ApiOperation(value = "家人登录后,弹出绑定邀请窗口")
    public Envelop applyMessageList(
            @ApiParam(name = "patient", value = "居民code", required = false)
            @RequestParam(value = "patient",required = false) String patient) throws Exception {
@ -141,7 +133,28 @@ public class MyFamilyEndpoint extends EnvelopRestEndpoint {
            @ApiParam(name = "isAuthorize", value = "0:未授权,1:已授权", required = true)
            @RequestParam(value = "isAuthorize",required = true) Integer isAuthorize) throws Exception {
        try{
            myFamilyService.confirmApply(patientApplyLogId,status,isAuthorize);
            return success(myFamilyService.confirmApply(patientApplyLogId,status,isAuthorize));
        }catch (Exception e){
            e.printStackTrace();
            return failed(e.getMessage());
        }
    }
    @PostMapping(value = PatientRequestMapping.MyFamily.scanQRcodeConfirmApply)
    @ApiOperation(value = "扫码绑定确认")
    public Envelop scanQRcodeConfirmApply(
            @ApiParam(name = "applyPatient", value = "申请人code", required = true)
            @RequestParam(value = "applyPatient",required = true) String applyPatient,
            @ApiParam(name = "applyPatient", value = "家人code", required = false)
            @RequestParam(value = "familyPatient",required = false) String familyPatient,
            @ApiParam(name = "familyBindRole", value = "家庭关系关系 1配偶 2父亲 3母亲 4公公 5婆婆 6岳父 7岳母 8子女", required = true)
            @RequestParam(value = "familyBindRole",required = true) Integer familyBindRole,
            @ApiParam(name = "isAuthorize", value = "0:未授权,1:已授权", required = true)
            @RequestParam(value = "isAuthorize",required = true) Integer isAuthorize,
            @ApiParam(name = "status", value = "3、通过,4、拒绝", required = true)
            @RequestParam(value = "status",required = true) Integer status) throws Exception {
        try{
            myFamilyService.scanQRcodeConfirmApply(status,applyPatient,getUID(familyPatient),familyBindRole,isAuthorize);
            return success();
        }catch (Exception e){
            e.printStackTrace();
@ -176,4 +189,36 @@ public class MyFamilyEndpoint extends EnvelopRestEndpoint {
        }
    }
    @GetMapping(value = PatientRequestMapping.MyFamily.scanQRcode)
    @ApiOperation(value = "扫码到确认绑定页面")
    public Envelop scanQRcode(
            @ApiParam(name = "applyPatient", value = "申请人code", required = true)
            @RequestParam(value = "applyPatient",required = true) String applyPatient,
            @ApiParam(name = "familyPatient", value = "家人code", required = false)
            @RequestParam(value = "familyPatient",required = false) String familyPatient,
            @ApiParam(name = "familyBindRole", value = "家庭关系关系 1配偶 2父亲 3母亲 4公公 5婆婆 6岳父 7岳母 8子女", required = true)
            @RequestParam(value = "familyBindRole",required = true) Integer familyBindRole) throws Exception {
        try{
            Map<String,Object> resultMap = myFamilyService.scanQRcode(applyPatient,getUID(familyPatient),familyBindRole);
            return success(resultMap);
        }catch (Exception e){
            e.printStackTrace();
            return failed(e.getMessage());
        }
    }
    @GetMapping(value = PatientRequestMapping.MyFamily.messageToBinding)
    @ApiOperation(value = "消息到确认绑定页面")
    public Envelop messageToBinding(
            @ApiParam(name = "messageId", value = "消息的id", required = true)
            @RequestParam(value = "messageId",required = true) Integer messageId) throws Exception {
        try{
            Map<String,Object> resultMap = myFamilyService.messageToBinding(messageId);
            return success(resultMap);
        }catch (Exception e){
            e.printStackTrace();
            return failed(e.getMessage());
        }
    }
}

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

@ -1,14 +1,10 @@
package com.yihu.jw.patient.endpoint.personal_info;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.base.security.Token;
import com.yihu.jw.entity.base.sms.SmsDO;
import com.yihu.jw.entity.base.sms.SmsTemplateDO;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.patient.service.personal_Info.PatientService;
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.restmodel.base.patient.BasePatientVO;
import com.yihu.jw.restmodel.base.sms.SmsVO;
import com.yihu.jw.restmodel.web.Envelop;
@ -17,17 +13,13 @@ import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.PageEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.base.BaseRequestMapping;
import com.yihu.jw.security.service.TokenService;
import com.yihu.jw.sms.service.BaseSmsGatewayService;
import com.yihu.jw.sms.service.BaseSmsService;
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.beans.factory.annotation.Value;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@ -57,52 +49,17 @@ public class PatientEndpoint extends EnvelopRestEndpoint {
    @Autowired
    private BaseSmsGatewayService baseSmsGatewayService;
    @Autowired
    private BasePatientDao basePatientDao;
    @Autowired
    private RSAService rsaService;
    @Autowired
    private TokenService tokenService;
    @Autowired
    private BaseSmsService baseSmsService;
    /**
     * 公钥生成并返回接口
     *
     * @return
     */
    @RequestMapping(value = BaseRequestMapping.BasePatient.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 = BaseRequestMapping.BasePatient.Regist, method = RequestMethod.POST)
    @ResponseBody
    public Envelop regist(@ApiParam(value = "手机号", name = "mobile") @RequestParam(required = true) String mobile,
    public ObjEnvelop 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();
        ObjEnvelop envelop = new ObjEnvelop();
        Map<String, Object> result = patientService.regist(mobile, captcha, password, openid);
        if ("-1".equals(result.get("code"))) {
            envelop.setStatus(-1);
            envelop.setMessage(result.get("message") + "");
        } else {
            envelop.setStatus(200);
            envelop.setMessage(result.get("message") + "");
        }
        envelop.setObj(result);
        return envelop;
    }
@ -234,4 +191,19 @@ public class PatientEndpoint extends EnvelopRestEndpoint {
        return success(smsDO, SmsVO.class);
    }
    @GetMapping(value = "bespeakRegist")
    @ApiOperation(value = "预注册测试接口")
    public Envelop bespeakRegist(
            @ApiParam(name = "mobile", value = "手机号")
            @RequestParam(value = "mobile", required = true) String mobile) throws Exception {
        Map<String, Object> map = patientService.bespeakRegist(mobile, 2L);
        Envelop envelop = new Envelop();
        String code = map.get("code").toString();
        String message = map.get("message").toString();
        System.out.println("code====>>"+code);
        System.out.println("message====>>"+message);
        return envelop;
    }
}

+ 19 - 1
svr/svr-patient/src/main/java/com/yihu/jw/patient/endpoint/wechat/WechatEndPoint.java

@ -3,16 +3,17 @@ package com.yihu.jw.patient.endpoint.wechat;
import com.yihu.jw.entity.base.wx.JsApiTicket;
import com.yihu.jw.entity.base.wx.WxWechatDO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.patient.PatientRequestMapping;
import com.yihu.jw.util.wechat.wxhttp.HttpUtil;
import com.yihu.jw.wechat.service.WechatService;
import com.yihu.jw.wechat.service.WxAccessTokenService;
import io.swagger.annotations.Api;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@ -35,6 +36,10 @@ public class WechatEndPoint extends EnvelopRestEndpoint {
    @Autowired
    private WxAccessTokenService wxAccessTokenService;
    @Autowired
    private WechatService wechatService;
    @Value("${wechat.id}")
    private String wxId;
    /**
     * 获取签名signature
     *
@ -64,6 +69,19 @@ public class WechatEndPoint extends EnvelopRestEndpoint {
        return failed(PatientRequestMapping.Wechat.api_error);
    }
    /**
     * 获取微信openid
     *
     * @param code
     * @return
     */
    @RequestMapping(value = "getOpenidByCode", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public String getOpenidByCode(String code) {
        return wechatService.getOpenidByCode(code,wxId);
    }
    /**
     * 获取微信的jsapi_ticket
     *

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

@ -9,6 +9,7 @@ import com.yihu.jw.message.service.MessageService;
import com.yihu.jw.patient.service.BasePatientMedicardCardService;
import com.yihu.jw.patient.service.personal_Info.PatientService;
import com.yihu.jw.patient.service.servicepackage.PackageService;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.wechat.service.WeChatQrcodeService;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.collections.map.LinkedMap;
@ -18,7 +19,6 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
/**
@ -34,7 +34,7 @@ public class MyFamilyService {
    @Autowired
    private MessageService messageService;
    @Value("${myFamily.qrCodeFailurTime}")
    private String qrCodeFailurTime;
    private String qrCodeFailurTime;//单位天
    @Autowired
    private WeChatQrcodeService weChatQrcodeService;
    @Autowired
@ -91,61 +91,85 @@ public class MyFamilyService {
    /**
     * 一键绑定
     * @param request
     * @param wechatId
     * @param patient
     * @param familyMobile
     * @param platform
     * @throws Exception
     */
    @Transactional(rollbackFor = Exception.class)
    public PatientApplyLog bindingMyFamily(HttpServletRequest request,String wechatId, String patient, String familyMobile, Integer platform,Integer familyBindRole) throws Exception{
    public Map<String,Object> bindingMyFamily( String patient, String familyMobile, Integer platform,Integer familyBindRole) throws Exception{
        BasePatientDO patientDO = patientService.findByIdAndDel(patient);
        //1、检验手机号码是否有存在账号,
        BasePatientDO familyPatient = patientService.findByMobileAndDel(familyMobile);
        if(familyPatient==null){
            //2、没有存在账号的,预注册一个账号,调用预注册接口
        }
        //3、生成申请绑定的记录
        PatientApplyLog patientApplyLog = patientApplyLogService.findValidOne(patient,familyPatient.getId(),new Date(),familyBindRole);
        if(patientApplyLog==null){
            patientApplyLog = new PatientApplyLog();
            patientApplyLog.setFamilyMemberName(familyPatient.getName());
            patientApplyLog.setFamilyMemberCode(familyPatient.getId());
            patientApplyLog.setDel(1);
            patientApplyLog.setCreateTime(new Date());
            patientApplyLog.setCreateUser(familyPatient.getId());
            patientApplyLog.setCreateUserName(patientDO.getName());
            patientApplyLog.setFamilyBindRole(familyBindRole);
            //4、发送绑定家人的系统消息
            BaseMessageDO messageDO = new BaseMessageDO();
            messageDO.setReceiver(familyPatient.getId());
            messageDO.setReceiverName(familyPatient.getName());
            messageDO.setSender(patient);
            messageDO.setSenderName(patientDO.getName());
            messageDO.setSenderPhoto(patientDO.getPhoto());
            messageDO.setTitle("家人绑定");
            messageDO.setMsgDigest("");
            messageDO.setMsgContent("");
            messageDO.setMsgTypeCode("010801");
            messageDO.setMsgTypeName("");
            messageDO.setPlatform(platform);
            messageDO.setReadState(0);
            messageDO.setReadonly(0);
            messageDO.setDel("1");
            messageDO.setCreateTime(new Date());
            messageService.save(messageDO);
        }
        Long time = 1000*60*60*Long.valueOf(qrCodeFailurTime);
        Long failurTime = System.currentTimeMillis()+time;
        patientApplyLog.setFailureTime(new Date(failurTime));
        patientApplyLog = patientApplyLogService.save(patientApplyLog);
//        PatientApplyLog patientApplyLog = createFamilyQrCode(request,familyPatient,wechatId,patient,familyBindRole);
        //2、没有存在账号的,预注册一个账号,调用预注册接口
        BasePatientDO familyPatient = null;
        //3、生成申请绑定的记录,申请绑定二维码
        PatientApplyLog patientApplyLog = createFamilyQrCode(request,familyPatient,wechatId,patient,familyBindRole);
        //4、发送绑定家人的系统消息
        BaseMessageDO messageDO = new BaseMessageDO();
        messageDO.setReceiver(familyPatient.getId());
        messageDO.setReceiverName(familyPatient.getName());
        messageDO.setSender(patient);
        messageDO.setType(1);
        messageDO.setFailureTime(patientApplyLog.getFailureTime());
        messageDO.setSenderName(patientDO.getName());
        messageDO.setSenderPhoto(patientDO.getPhoto());
        messageDO.setTitle("家人绑定");
        messageDO.setMsgDigest("");
        messageDO.setMsgContent("");
        messageDO.setMsgTypeCode("010801");
        messageDO.setMsgTypeName("");
        messageDO.setPlatform(platform);
        messageDO.setReadState(0);
        messageDO.setReadonly(0);
        messageDO.setDel("1");
        messageDO.setCreateTime(new Date());
        messageService.save(messageDO);
        return patientApplyLog;
        Map<String,Object> map = new HashedMap();
        map.put("patientApplyLogId",patientApplyLog.getId());//
        map.put("familyMemberName",patientApplyLog.getFamilyMemberName());//家人的名称
        map.put("familyMemberCode",patientApplyLog.getFamilyMemberCode());//家人的code
        map.put("familyMemberPhoto",familyPatient.getPhoto());//家人的头像
        map.put("failureTime", DateUtil.dateToStr(patientApplyLog.getFailureTime(),"yyyy-MM-dd HH:mm:ss"));//失效时间
        map.put("status",patientApplyLog.getStatus());//状态
        map.put("createTime",DateUtil.dateToStr(patientApplyLog.getCreateTime(),"yyyy-MM-dd HH:mm:ss"));//创建时间
        map.put("createUser",patientApplyLog.getCreateUser());//申请人
        map.put("createUserName",patientApplyLog.getCreateUserName());//申请人姓名
        map.put("createUserPhoto",patientDO.getPhoto());//申请人头像
        map.put("familyBindRole",patientApplyLog.getFamilyBindRole());//角色 1"配偶",2"父亲",3"母亲",4"公公",5"婆婆",6"岳父",7"岳母",8"女婿",9"儿媳",10"子女"
        map.put("familyMobile",familyMobile);//家人手机号码
        return map;
    }
    /**
     * 签约绑定家人
     * @param request
     * @param wechatId
     * @param patient
     * @param familyMobile
     * @param platform
     * @param patient 申请绑定的居民code
     * @param familyMobile 家人的手机号码
     * @param platform  消息平台,1微信端/患者端,2医生APP端
     * @param familyBindRole 1"配偶",2"父亲",3"母亲",4"公公",5"婆婆",6"岳父",7"岳母",8"女婿",9"儿媳",10"子女"
     * @param isAdult 0未成年人 1成年人
     */
    public PatientApplyLog signBindFamily(HttpServletRequest request,String wechatId, String patient, String familyMobile, Integer platform,Integer familyBindRole,Integer isAdult) throws Exception{
    public Map<String,Object> signBindFamily( String patient, String familyMobile, Integer platform,Integer familyBindRole,Integer isAdult) throws Exception{
        if(isAdult==1){
            PatientApplyLog p = bindingMyFamily(request,wechatId,patient, familyMobile, platform,familyBindRole);
            Map<String,Object> p = bindingMyFamily(patient, familyMobile, platform,familyBindRole);
            return p;
        }else if(isAdult==0){
            //注册一个没有手机号码的用户信息
@ -164,35 +188,24 @@ public class MyFamilyService {
    /**
     * 生成绑定家人的二维码
     * @param request
     * @param familyPatient
     * @param wechatId
     * @param patient
     * @return
     * @throws Exception
     */
    @Transactional(rollbackFor = Exception.class)
    public PatientApplyLog createFamilyQrCode(HttpServletRequest request,BasePatientDO familyPatient,String wechatId, String patient,Integer familyBindRole) throws Exception{
        BasePatientDO patientDO = patientService.findByIdAndDel(patient);
        PatientApplyLog patientApplyLog = new PatientApplyLog();
        patientApplyLog.setFamilyMemberName(familyPatient.getName());
        patientApplyLog.setFamilyMemberCode(familyPatient.getId());
        String scene ="family_"+familyPatient.getId()+"_"+familyPatient.getId();
        String qrCode = weChatQrcodeService.getQrcode(request,wechatId, scene);
    public Map<String,Object> createFamilyQrCode(String wechatId, String patient,Integer familyBindRole) throws Exception{
        Map<String,Object> map = new HashedMap();
        String scene ="family_"+patient+"_"+familyBindRole;
        String qrCode = weChatQrcodeService.getQrcode(wechatId, scene);
        if(StringUtils.isEmpty(qrCode)){
            throw new Exception("qrCode is null");
        }
        patientApplyLog.setQrCode(qrCode);
        Long time = 1000*60*60*Long.valueOf(qrCodeFailurTime);
        Long failurTime = (new Date()).getTime()+time;
        patientApplyLog.setFailureTime(new Date(failurTime));
        patientApplyLog.setDel(1);
        patientApplyLog.setCreateTime(new Date());
        patientApplyLog.setCreateUser(familyPatient.getId());
        patientApplyLog.setCreateUserName(patientDO.getName());
        patientApplyLog.setFamilyBindRole(familyBindRole);
        patientApplyLogService.save(patientApplyLog);
        return patientApplyLog;
        map.put("qrCode",qrCode);
        map.put("familyBindRole",familyBindRole);
        map.put("myFamilyBindingRole",getMyFamilyBindingRole(patient));
        return map;
    }
@ -216,10 +229,20 @@ public class MyFamilyService {
     * @param status 1、添加家人(默认),2、邀请登录,3、通过,4、拒绝
     */
    @Transactional(rollbackFor = Exception.class)
    public void confirmApply(Integer patientApplyLogId,Integer status,Integer isAuthorize){
    public Map<String,Object> confirmApply(Integer patientApplyLogId,Integer status,Integer isAuthorize)throws Exception{
        Map<String,Object> map = new HashedMap();
        PatientApplyLog patientApplyLog = patientApplyLogService.findById(patientApplyLogId);
        BasePatientDO apply = patientService.findByIdAndDel(patientApplyLog.getCreateUser());
        BasePatientDO family = patientService.findByIdAndDel(patientApplyLog.getFamilyMemberCode());
        Integer converRole = familyRelationTrans(patientApplyLog.getFamilyBindRole(),apply.getSex());
        if(patientApplyLog.getFailureTime().getTime()<System.currentTimeMillis()){
            map.put("key","0");
            map.put("keyName","绑定过期");
            map.put("applyPhoto",apply.getPhoto());
            map.put("familyPhoto",family.getPhoto());
            map.put("explain","您的"+role.get(converRole-1)+apply.getName()+"向您发起的绑定邀请已过期,您可以点下下方邀请绑定按钮,重新邀请绑定家人。");
            return map;
        }
        patientApplyLog.setStatus(status);
        patientApplyLog.setConfirmTime(new Date());
        patientApplyLogService.save(patientApplyLog);
@ -229,11 +252,82 @@ public class MyFamilyService {
            patientFamilyMember.setPatient(patientApplyLog.getCreateUser());
            patientFamilyMember.setFamilyMember(patientApplyLog.getFamilyMemberCode());
            patientFamilyMember.setFamilyRelation(patientApplyLog.getFamilyBindRole());
            patientFamilyMember.setIsAuthorize(isAuthorize);
            patientFamilyMember.setIsAuthorize(0);
            patientFamilyMember.setDel(1);
            patientFamilyMemberService.save(patientFamilyMember);
            BasePatientFamilyMemberDO patientFamilyMember2 = new BasePatientFamilyMemberDO();
            patientFamilyMember2.setPatient(patientApplyLog.getFamilyMemberCode());
            patientFamilyMember2.setFamilyMember(patientApplyLog.getCreateUser());
            BasePatientDO createUser = patientService.findByIdAndDel(patientApplyLog.getCreateUser());
            patientFamilyMember2.setFamilyRelation(familyRelationTrans(patientApplyLog.getFamilyBindRole(),createUser.getSex()));
            patientFamilyMember2.setIsAuthorize(isAuthorize);
            patientFamilyMember2.setDel(1);
            patientFamilyMemberService.save(patientFamilyMember2);
        }
        map.put("key","1");
        map.put("keyName","绑定成功");
        return map;
    }
    /**
     * 扫码绑定确认
     * @param status
     * @param applyPatient
     * @param familyPatient
     * @param familyBindRole
     * @param isAuthorize
     * @throws Exception
     */
    public void scanQRcodeConfirmApply(Integer status,String applyPatient,String familyPatient,Integer familyBindRole,Integer isAuthorize)throws Exception{
        if(status==3){
            BasePatientFamilyMemberDO patientFamilyMember = new BasePatientFamilyMemberDO();
            patientFamilyMember.setPatient(applyPatient);
            patientFamilyMember.setFamilyMember(familyPatient);
            patientFamilyMember.setFamilyRelation(familyBindRole);
            patientFamilyMember.setIsAuthorize(0);
            patientFamilyMember.setDel(1);
            patientFamilyMemberService.save(patientFamilyMember);
            BasePatientFamilyMemberDO patientFamilyMember2 = new BasePatientFamilyMemberDO();
            patientFamilyMember2.setPatient(familyPatient);
            patientFamilyMember2.setFamilyMember(applyPatient);
            BasePatientDO createUser = patientService.findByIdAndDel(applyPatient);
            patientFamilyMember2.setFamilyRelation(familyRelationTrans(familyBindRole,createUser.getSex()));
            patientFamilyMember2.setIsAuthorize(isAuthorize);
            patientFamilyMember2.setDel(1);
            patientFamilyMemberService.save(patientFamilyMember2);
        }
    }
    /**
     * 扫码到确认绑定页面
     * @param applyPatient
     * @param familyPatient
     * @param familyBindRole
     * @throws Exception
     */
    public Map<String,Object> scanQRcode(String applyPatient,String familyPatient,Integer familyBindRole) throws Exception{
        Map<String,Object> map = new HashedMap();
        BasePatientDO apply = patientService.findByIdAndDel(applyPatient);
        BasePatientDO family = patientService.findByIdAndDel(familyPatient);
        Integer converRole = familyRelationTrans(familyBindRole,apply.getSex());
        map.put("applyPhoto",apply.getPhoto());
        map.put("familyPhoto",family.getPhoto());
        map.put("explain","您的"+role.get(converRole-1)+apply.getName()+"邀请您绑定家人账号");
        return map;
    }
    /**
     * 消息到确认绑定页面
     * @param messageId
     * @return
     * @throws Exception
     */
    public Map<String,Object> messageToBinding(Integer messageId)throws Exception{
        BaseMessageDO messageDO = messageService.findById(messageId);
        PatientApplyLog patientApplyLog = patientApplyLogService.findById(Integer.valueOf(messageDO.getRelationData()+""));
        Map<String,Object> map = scanQRcode(patientApplyLog.getCreateUser(),patientApplyLog.getFamilyMemberCode(),patientApplyLog.getFamilyBindRole());
        map.put("patientApplyLogId",patientApplyLog.getId());
        return map;
    }
    /**
@ -245,7 +339,6 @@ public class MyFamilyService {
    public List<Map<String,Object>> getBindingList(String patient,String packageId) throws Exception{
        List<Map<String,Object>> resultList = new LinkedList<>();
        List<BasePatientFamilyMemberDO> list = patientFamilyMemberService.getByPatientAndFamilyMember(patient);
        String patientTemp = null;
        //自己
        BasePatientDO basePatientDO = patientService.findByIdAndDel(patient);
        Map<String,Object> map = new HashedMap();
@ -254,10 +347,10 @@ public class MyFamilyService {
        map.put("name",basePatientDO.getName());//姓名
        map.put("cardTypeName","身份证");
        map.put("idcard",basePatientDO.getIdcard());//身份证
        if(!StringUtils.isEmpty(basePatientDO.getPrincipalCode())){
        PatientMedicareCardDO patientMedicareCardDO = patientMedicareCardService.findByTypeAndPatientCodeAndDel(PatientMedicareCardDO.Type.SocialSecurityCard.getType(),patient,"1");
        if(patientMedicareCardDO!=null){
            PatientMedicareCardDO patientMedicareCard = patientMedicareCardService.findByCode(basePatientDO.getPrincipalCode());
            map.put("principalNum",patientMedicareCard.getCode());//社保卡号
            map.put("principalNum",patientMedicareCardDO.getCode());//社保卡号
        }else{
            map.put("principalNum","");//社保卡号
        }
@ -274,20 +367,15 @@ public class MyFamilyService {
        //家人
        for(BasePatientFamilyMemberDO one:list){
            Map<String,Object> map2 = new HashedMap();
            if(patient.equals(one.getPatient())){
                patientTemp = one.getPatient();
            }else{
                patientTemp = one.getFamilyMember();
            }
            basePatientDO = patientService.findByIdAndDel(patientTemp);
            basePatientDO = patientService.findByIdAndDel(one.getPatient());
            map2.put("appellation",basePatientDO.getName());//别称
            map2.put("patientCode",patientTemp);//居民code
            map2.put("patientCode",basePatientDO.getId());//居民code
            map2.put("name",basePatientDO.getName());//姓名
            map2.put("cardTypeName","身份证");
            map2.put("idcard",basePatientDO.getIdcard());//身份证
            if(!StringUtils.isEmpty(basePatientDO.getPrincipalCode())){
            PatientMedicareCardDO patientMedicareCard = patientMedicareCardService.findByTypeAndPatientCodeAndDel(PatientMedicareCardDO.Type.SocialSecurityCard.getType(),patient,"1");
            if(patientMedicareCardDO!=null){
                PatientMedicareCardDO patientMedicareCard = patientMedicareCardService.findByCode(basePatientDO.getPrincipalCode());
                map2.put("principalNum",patientMedicareCard.getCode());//社保卡号
            }else{
                map2.put("principalNum","");//社保卡号
@ -313,28 +401,15 @@ public class MyFamilyService {
        BasePatientDO patientDO = patientService.findByIdAndDel(patient);//绑定人
        for(BasePatientFamilyMemberDO one:bindList){
            Map<String,Object> map = new HashedMap();
            if(patient.equals(one.getPatient())){
                BasePatientDO familyMember = patientService.findByIdAndDel(one.getFamilyMember());
                map.put("photo",familyMember.getPhoto());//头像
                map.put("name",familyMember.getName());//姓名
                map.put("roleName",role.get(one.getFamilyRelation()+1));//角色名称
                map.put("mobile",familyMember.getMobile());//手机号码
                map.put("isAuthorize",one.getIsAuthorize());//0:未授权,1:已授权
                map.put("familyMemberId",one.getId());
                map.put("patientId",familyMember.getId());
                map.put("type",1);
            }else{
                Integer familyRelation = familyRelationTrans(one.getFamilyRelation(),patientDO.getSex());
                BasePatientDO familyMember = patientService.findByIdAndDel(one.getPatient());
                map.put("photo",familyMember.getPhoto());//头像
                map.put("name",familyMember.getName());//姓名
                map.put("roleName",role.get(familyRelation+1));//角色名称
                map.put("mobile",familyMember.getMobile());//手机号码
                map.put("isAuthorize",one.getIsAuthorize());//0:未授权,1:已授权
                map.put("familyMemberId",one.getId());
                map.put("patientId",familyMember.getId());
                map.put("type",1);
            }
            BasePatientDO familyMember = patientService.findByIdAndDel(one.getFamilyMember());
            map.put("photo",familyMember.getPhoto());//头像
            map.put("name",familyMember.getName());//姓名
            map.put("roleName",role.get(one.getFamilyRelation()+1));//角色名称
            map.put("mobile",familyMember.getMobile());//手机号码
            map.put("isAuthorize",one.getIsAuthorize());//0:未授权,1:已授权
            map.put("familyMemberId",one.getId());
            map.put("patientId",familyMember.getId());
            map.put("type",1);
            resultList.add(map);
        }
        //已邀请的
@ -385,13 +460,20 @@ public class MyFamilyService {
     */
    @Transactional(rollbackFor = Exception.class)
    public List<Map<String,Object>> applyMessageList(String patient) throws Exception{
        List<Map<String, Object>> msgList = messageService.applyMessageList(patient, new Date(), "010801");
        List<Map<String, Object>> msgList = messageService.applyMessageList(patient, "010801");
        List<Map<String,Object>> result = new ArrayList<>();
        PatientApplyLog patientApplyLog = null;
        for(Map<String, Object> one:msgList){
            Map<String,Object> map = new HashedMap();
            String relationData = one.get("relation_data")+"";
            patientApplyLog = patientApplyLogService.findById(Integer.valueOf(relationData));
            if(patientApplyLog.getFailureTime().getTime()<System.currentTimeMillis()){
                BaseMessageDO msg = messageService.findById(Integer.valueOf(one.get("id")+""));
                msg.setReadonly(1);
                msg.setReadTime(new Date());
                messageService.save(msg);
               continue;
            }
            Integer bindRole = patientApplyLog.getFamilyBindRole();
            String createUser = patientApplyLog.getCreateUser();//申请人code
@ -429,7 +511,7 @@ public class MyFamilyService {
    /**
     * 家庭关系转换
     * @param familyRelation
     * @param sex 1男,2女
     * @param sex 申请人的性别 1男,2女
     */
    public Integer familyRelationTrans(Integer familyRelation,Integer sex){
        //1"配偶",2"父亲",3"母亲",4"公公",5"婆婆",6"岳父",7"岳母",8"女婿",9"儿媳",10"子女"

+ 4 - 0
svr/svr-patient/src/main/java/com/yihu/jw/patient/service/myFamily/PatientApplyLogService.java

@ -57,4 +57,8 @@ public class PatientApplyLogService extends BaseJpaService<PatientApplyLog, Pati
        String sql = "select l.* from patient_apply_for_log l where l.create_user='"+patient+"' and l.del=1 and (l.status in (4,5) or (l.failure_time>='"+ DateUtil.dateToStr(new Date(),"yyyy-MM-dd HH:mm:ss")+"' and l.status in (1,2))) limit0,10";
        return jdbcTemplate.queryForList(sql);
    }
    public PatientApplyLog findValidOne(String createUser,String familyMemberCode,Date failureTime,Integer familyBindRole){
        return  patientApplyLogDao.findValidOne(createUser,familyMemberCode,failureTime,familyBindRole);
    }
}

+ 0 - 3
svr/svr-patient/src/main/java/com/yihu/jw/patient/service/personal_Info/PatientMedicareCardService.java

@ -1,12 +1,9 @@
package com.yihu.jw.patient.service.personal_Info;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.base.patient.PatientMedicareCardDO;
import com.yihu.jw.exception.business.patient.PatientCardNotFoundException;
import com.yihu.jw.exception.business.patient.PatientNotFoundException;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.patient.dao.BasePatientMedicareCardDao;
import com.yihu.jw.patient.dao.personal_info.PatientMedicareCardDao;
import com.yihu.jw.patient.service.BasePatientMedicardCardService;
import com.yihu.jw.util.security.MD5;
import org.springframework.beans.factory.annotation.Autowired;

+ 139 - 68
svr/svr-patient/src/main/java/com/yihu/jw/patient/service/personal_Info/PatientService.java

@ -7,30 +7,32 @@ import com.yihu.jw.exception.business.patient.CapthcaInvalidException;
import com.yihu.jw.exception.business.patient.PatientNotFoundException;
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.service.BasePatientService;
import com.yihu.jw.patient.util.CommonUtils;
import com.yihu.jw.patient.util.ConstantUtils;
import com.yihu.jw.restmodel.iot.common.UploadVO;
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;
import org.csource.common.MyException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
 * 居民信息服务
 *
 * @author litaohong on  2018年11月28日
 */
@Service
@ -45,88 +47,133 @@ public class PatientService extends BasePatientService<BasePatientDO, BasePatien
    @Autowired
    private FileUploadService fileUploadService;
    @Autowired
    private StringRedisTemplate redisTemplate;
    private static final String BespeakRegist = "bespeakRegist:";
    @Value("${fastDFS.fastdfs_file_url}")
    private String fastdfsUrl;
    public Map<String,Object> regist(String mobile, String captcha, String password, String openid){
    public Map<String, Object> regist(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","手机号码格式不正确");
        if (!b) {
            map.put("code", -1);
            map.put("message", "手机号码格式不正确");
            return map;
        }
        //验证手机是否被注册
        List<BasePatientDO> list = basePatientDao.findByMobileAndDel(mobile,"1");
        if(list!=null && list.size()> 0){
            map.put("code",-1);
            map.put("message","该手机号已经注册!");
        List<BasePatientDO> list = basePatientDao.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","验证码已过期!");
        if (-2 == res) {
            map.put("code", -1);
            map.put("message", "验证码已过期!");
            return map;
        }else if(-1 == res){
            map.put("code",-1);
            map.put("message","请输入正确的验证码!");
        } else if (-1 == res) {
            map.put("code", -1);
            map.put("message", "请输入正确的验证码!");
            return map;
        }else if(0 == res){
            map.put("code",-1);
            map.put("message","验证码无效!");
        } else if (0 == res) {
            map.put("code", -1);
            map.put("message", "验证码无效!");
            return map;
        } else{
        } else {
            BasePatientDO patient = new BasePatientDO();
            if(StringUtils.isNotBlank(password)){
            if (StringUtils.isNotBlank(password)) {
                //增加密码
                if(password.length()<6 || password.length()>20){
                    map.put("code",-1);
                    map.put("message","密码长度需为6-20位");
                if (password.length() < 6 || password.length() > 20) {
                    map.put("code", -1);
                    map.put("message", "密码长度需为6-20位");
                    return map;
                }
                patient.setSalt(randomString(5));
                patient.setPassword(MD5.md5Hex(password + "{" + patient.getSalt() + "}"));
            }
            if(!"undefined".equals(openid) && StringUtils.isNotBlank(openid)){
            if (!"undefined".equals(openid) && StringUtils.isNotBlank(openid)) {
                patient.setOpenid(openid);
                patient.setOpenidTime(new Date());
            }
            patient.setMobile(mobile);
            patient.setLocked(0);
            patient.setEnabled(0);
            patient.setEnabled(1);
            patient.setDel("1");
            patient.setLoginFailureCount(0);
            patient.setPatientStatus("1");
            this.save(patient);
            map.put("code",1);
            map.put("message","注册成功");
            map.put("code", 1);
            map.put("message", "注册成功");
            return map;
        }
    }
    /**
     * 预注册功能接口
     * @param phone
     * @param mobile
     * @param time 预注册过期时间 例如: 2 , 则2分钟过期
     * @return
     */
//    public Map<String,Object> bespeakRegist(String phone){
//
//    }
    public Map<String,Object> bespeakRegist(String mobile,long time){
        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 = basePatientDao.findByMobileAndDel(mobile,"1");
        if(list!=null && list.size()> 0){
            map.put("code",-1);
            map.put("message","该手机号已经注册!");
            return map;
        }
        //将预注册信息存到redis中
        redisTemplate.opsForValue().set(BespeakRegist+mobile , mobile, time, TimeUnit.MINUTES);
        //判断是否存在del=0的数据
        list = basePatientDao.findByMobileAndDel(mobile,"0");
        BasePatientDO patient = null;
        if(CollectionUtils.isEmpty(list)){
            patient = new BasePatientDO();
            patient.setMobile(mobile);
            patient.setLocked(0);
            patient.setEnabled(1);
            patient.setDel("0");
            patient.setLoginFailureCount(0);
            patient.setPatientStatus("1");
            patient = this.save(patient);
        }else{
            patient = list.get(0);
        }
        map.put("code",1);
        map.put("message","预注册成功");
        map.put("patient",patient);
        return map;
    }
    /**
     * 设置登录密码/修改密码
     *
     * @param id
     * @param newPassword
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public String resetPassword(String id,String newPassword){
    public String resetPassword(String id, String newPassword) {
        Preconditions.checkNotNull(id);
        Preconditions.checkNotNull(newPassword);
        BasePatientDO patient = basePatientDao.findOne(id);
        if(null == patient){
        if (null == patient) {
            throw new PatientNotFoundException("当前居民不存在:【 " + id + "】");
        }
        patient.setSalt(randomString(5));
@ -136,28 +183,29 @@ public class PatientService extends BasePatientService<BasePatientDO, BasePatien
    /**
     * 修改手机号
     *
     * @param id
     * @param newMobile
     * @param captcha
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public BasePatientDO updateMobile(@NotNull String id, @NotNull String newMobile, @NotNull String captcha){
    public BasePatientDO updateMobile(@NotNull String id, @NotNull String newMobile, @NotNull String captcha) {
        Preconditions.checkNotNull(id,"id不可为空");
        Preconditions.checkNotNull(newMobile,"手机号不可为空");
        Preconditions.checkNotNull(captcha,"验证码不可为空");
        Preconditions.checkNotNull(id, "id不可为空");
        Preconditions.checkNotNull(newMobile, "手机号不可为空");
        Preconditions.checkNotNull(captcha, "验证码不可为空");
        BasePatientDO patient = basePatientDao.findOne(id);
        if(null == patient){
        if (null == patient) {
            throw new PatientNotFoundException("当前居民不存在:【 " + id + "】");
        }
        if(StringUtils.endsWithIgnoreCase(patient.getMobile(),newMobile)){
        if (StringUtils.endsWithIgnoreCase(patient.getMobile(), newMobile)) {
            return patient;
        }
        if(baseSmsService.verifyCaptcha(captcha)){
        if (baseSmsService.verifyCaptcha(captcha)) {
            patient.setMobile(newMobile);
            this.save(patient);
        }else{
        } else {
            throw new CapthcaInvalidException("验证码不正确或过期!");
        }
        return patient;
@ -165,24 +213,30 @@ public class PatientService extends BasePatientService<BasePatientDO, BasePatien
    /**
     * 完善居民基本信息
     *
     * @param headPortrait 头像
     * @param json
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public BasePatientDO completePatientDetails(MultipartFile headPortrait, String json){
        BasePatientDO patientDetail = JSONObject.parseObject(json,BasePatientDO.class);
    public BasePatientDO completePatientDetails(MultipartFile headPortrait, String json) {
        BasePatientDO patientDetail = JSONObject.parseObject(json, BasePatientDO.class);
        Assert.notNull(patientDetail.getName(), "姓名不可为空!");
        Assert.notNull(patientDetail.getSex(), "性别不可为空!");
        Assert.notNull(patientDetail.getIdcard(), "身份证不可为空!");
        Assert.notNull(patientDetail.getCommitteeCode(), "居委会不可为空!");
        Assert.notNull(patientDetail.getCommitteeName(), "居委会不可为空!");
        BasePatientDO patientBrief = basePatientDao.findOne(patientDetail.getId());
        if(null == patientBrief){
        if (null == patientBrief) {
            throw new PatientNotFoundException("未找到该居民!");
        }
        //如果未上传头像,使用默认头像,默认头像由客户端来处理,后台默认存null
        if(null == headPortrait && !StringUtils.isEmpty(patientBrief.getPhoto())){
            patientDetail.setPhoto(patientBrief.getPhoto());
        }else{
        if (null != headPortrait) {
            UploadVO uploadedFile = null;
            try {
                uploadedFile = fileUploadService.uploadImg(headPortrait.getInputStream(),headPortrait.getOriginalFilename(),headPortrait.getSize(),fastdfsUrl);
                uploadedFile = fileUploadService.uploadImg(headPortrait.getInputStream(), headPortrait.getOriginalFilename(), headPortrait.getSize(), fastdfsUrl);
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            } catch (IOException e) {
@ -190,33 +244,48 @@ public class PatientService extends BasePatientService<BasePatientDO, BasePatien
            } catch (MyException e) {
                e.printStackTrace();
            }
            patientDetail.setPhoto(uploadedFile.getFullUrl());
            patientBrief.setPhoto(uploadedFile.getFullUrl());
        }
        patientDetail.setMobile(patientBrief.getMobile());
        Assert.notNull(patientDetail.getName(),"姓名不可为空!");
        Assert.notNull(patientDetail.getSex(),"性别不可为空!");
        Assert.notNull(patientDetail.getIdcard(),"身份证不可为空!");
        Assert.notNull(patientDetail.getCommitteeCode(),"居委会不可为空!");
        Assert.notNull(patientDetail.getCommitteeName(),"居委会不可为空!");
        this.save(patientDetail);
        patientBrief.setName(patientDetail.getName());
        patientBrief.setSex(patientDetail.getSex());
        patientBrief.setIdcard(patientDetail.getIdcard());
        patientBrief.setProvinceCode(patientDetail.getProvinceCode());
        patientBrief.setProvinceName(patientDetail.getProvinceName());
        patientBrief.setCityCode(patientDetail.getCityCode());
        patientBrief.setCityName(patientDetail.getCityName());
        patientBrief.setTownCode(patientDetail.getTownCode());
        patientBrief.setTownName(patientDetail.getTownName());
        patientBrief.setLiveProvinceCode(patientDetail.getLiveProvinceCode());
        patientBrief.setLiveProvinceName(patientDetail.getLiveProvinceName());
        patientBrief.setLiveCityCode(patientDetail.getLiveCityCode());
        patientBrief.setLiveCityName(patientDetail.getLiveCityName());
        patientBrief.setLiveTownCode(patientDetail.getLiveTownName());
        patientBrief.setLiveStreetCode(patientDetail.getLiveStreetCode());
        patientBrief.setLiveStreetName(patientDetail.getLiveStreetName());
        patientBrief.setAddress(patientDetail.getAddress());
        patientBrief.setCommitteeCode(patientDetail.getCommitteeCode());
        patientBrief.setCommitteeName(patientDetail.getCommitteeName());
        this.save(patientBrief);
        return patientDetail;
    }
    /**
     * 验证身份证是否存在,剔除当前用户自身id
     *
     * @param idcard
     * @param id
     * @return
     */
    public boolean existsByIdcard(String idcard,String id) {
    public boolean existsByIdcard(String idcard, String id) {
        Preconditions.checkNotNull(idcard, "身份证不可为空");
        Preconditions.checkNotNull(id, "id不可为空");
        return basePatientDao.existsByIdcardAndIdNot(idcard,id);
        return basePatientDao.existsByIdcardAndIdNot(idcard, id);
    }
    /**
     * 验证身份证是否存在
     *
     * @param idcard
     * @return
     */
@ -227,33 +296,35 @@ public class PatientService extends BasePatientService<BasePatientDO, BasePatien
    @Transactional(rollbackFor = Exception.class)
    public int updateOpenId(String id, String openId){
        return basePatientDao.updateOpenId(id,openId);
    public int updateOpenId(String id, String openId) {
        return basePatientDao.updateOpenId(id, openId);
    }
    /**
     *  判断是否需要完善信息,身份证未填则需要完善
     * 判断是否需要完善信息,身份证未填则需要完善
     *
     * @param id
     * @return
     */
    public boolean isCompleted(String id) {
        Assert.notNull(id,"id不可为空");
        Assert.notNull(id, "id不可为空");
        BasePatientDO patient = basePatientDao.findOne(id);
        if(null == patient){
        if (null == patient) {
            throw new PatientNotFoundException("居民不存在!");
        }
       return !StringUtils.isEmpty(patient.getIdcard());
        return !StringUtils.isEmpty(patient.getIdcard());
    }
    /**
     * 查询居民完善后的基本信息
     *
     * @return
     */
    public BasePatientDO getCompletedDetails(String id){
        Assert.notNull(id,"居民id不可为空!");
    public BasePatientDO getCompletedDetails(String id) {
        Assert.notNull(id, "居民id不可为空!");
        BasePatientDO patient = basePatientDao.findOne(id);
        if(null == patient){
        if (null == patient) {
            throw new PatientNotFoundException("居民不存在!");
        }
        return patient;

+ 0 - 182
svr/svr-patient/src/main/java/com/yihu/jw/patient/util/RSAService.java

@ -1,182 +0,0 @@
package com.yihu.jw.patient.util;
import java.io.*;
import java.security.*;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.util.Iterator;
import com.yihu.jw.entity.base.security.RSA;
import com.yihu.jw.patient.dao.security.RSADao;
import com.yihu.jw.util.common.RSAUtils;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class RSAService {
    @Autowired
    private RSADao rsaDao;
    /**
     * 缓存的密钥对。
     */
    private KeyPair oneKeyPair = null;
    /**
     * 读取RSA加密信息
     * @return
     */
    public RSA loadRSA() {
        Iterable<RSA> iterable = rsaDao.findAll();
        if (iterable != null) {
            Iterator<RSA> it = iterable.iterator();
            if (it != null && it.hasNext()) {
                return it.next();
            }
        }
        return null;
    }
    public KeyPair getKeyPair() {
        if (oneKeyPair == null) {
            // 从数据库加载
            RSA rsa = loadRSA();
            if (rsa == null) {
                // 生成密钥
                generateKeyPair();
            } else {
                // 由数据库取出来
                Object obj = toObject(rsa.getData());
                oneKeyPair = (KeyPair) obj;
            }
        }
        return oneKeyPair;
    }
    /**
     * 生成并返回RSA密钥对。
     */
    private synchronized KeyPair generateKeyPair() {
        try {
            oneKeyPair = RSAUtils.initKey();
            // 保存到数据库
            saveRSA(oneKeyPair);
            return oneKeyPair;
        } catch (InvalidParameterException ex) {
            ex.printStackTrace();
        } catch (NullPointerException ex) {
            ex.printStackTrace();
        }
        return null;
    }
    /**
     * 保存RSA加密信息
     * @return
     */
    public RSA saveRSA(KeyPair keyPair) {
        RSA rsa = new RSA();
        rsa.setData(toByteArray(keyPair));
        // 先清空
        rsaDao.deleteAll();
        // 再添加
        return rsaDao.save(rsa);
    }
    /**
     * 返回已初始化的默认的公钥。
     */
    public RSAPublicKey getDefaultPublicKey() {
        KeyPair keyPair = getKeyPair();
        if (keyPair != null) {
            return (RSAPublicKey) keyPair.getPublic();
        }
        return null;
    }
    public String getModulus() {
        return new String(Hex.encodeHex(getDefaultPublicKey().getModulus().toByteArray()));
    }
    public String getExponent() {
        return new String(Hex.encodeHex(getDefaultPublicKey().getPublicExponent().toByteArray()));
    }
    /**
     * 对象转数组
     *
     * @param obj
     * @return
     */
    public byte[] toByteArray(Object obj) {
        byte[] bytes = null;
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        try {
            ObjectOutputStream oos = new ObjectOutputStream(bos);
            oos.writeObject(obj);
            oos.flush();
            bytes = bos.toByteArray();
            oos.close();
            bos.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return bytes;
    }
    /**
     * 数组转对象
     *
     * @param bytes
     * @return
     */
    public Object toObject(byte[] bytes) {
        Object obj = null;
        try {
            ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
            ObjectInputStream ois = new ObjectInputStream(bis);
            obj = ois.readObject();
            ois.close();
            bis.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }
        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;
    }
}

+ 10 - 7
svr/svr-patient/src/main/resources/application.yml

@ -107,8 +107,9 @@ fastDFS:
jw:
  smsUrl: http://svr-base:10020/sms_gateway/send
myFamily:
  qrCodeFailurTime: 2
  qrCodeFailurTime: 7
wechat:
  id: d24d1367-7f4f-43af-910e-a0a43799e040  # base库中,wx_wechat 的id字段
# 短信验证码发送的客户端标识,居民端
sms:
  clientId: EwC0iRSrcP
@ -139,12 +140,13 @@ spring:
    port: 6379 # Redis server port.
fastDFS:
  fastdfs_file_url: http://172.19.103.54:80/
wechat:
  id: d24d1367-7f4f-43af-910e-a0a43799e040  # base库中,wx_wechat 的id字段
# 短信验证码发送的客户端标识,居民端
sms:
  clientId: EwC0iRSrcP
myFamily:
  qrCodeFailurTime: 2
  qrCodeFailurTime: 7
---
spring:
  profiles: prod
@ -169,9 +171,10 @@ spring:
    port: 6379 # Redis server port.
fastDFS:
  fastdfs_file_url: http://172.19.103.54:80/
wechat:
  id: d24d1367-7f4f-43af-910e-a0a43799e040  # base库中,wx_wechat 的id字段  # todo 待配置
# 短信验证码发送的客户端标识,居民端
sms:
  clientId: EwC0iRSrcP
  clientId: EwC0iRSrcP #todo 待配置
myFamily:
  qrCodeFailurTime: 2
  qrCodeFailurTime: 7