Browse Source

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

LiTaohong 6 years ago
parent
commit
1af6d93b5b
16 changed files with 213 additions and 80 deletions
  1. 2 2
      business/sms-service/src/main/java/com/yihu/jw/sms/dao/BaseSmsDao.java
  2. 3 3
      business/sms-service/src/main/java/com/yihu/jw/sms/service/BaseSmsService.java
  3. 26 0
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/ResultStatus.java
  4. 7 8
      gateway/ag-basic/src/main/java/com/yihu/jw/gateway/filter/BasicZuulFilter.java
  5. 17 13
      server/svr-authentication/src/main/java/com/yihu/jw/security/oauth2/provider/endpoint/WlyyLoginEndpoint.java
  6. 8 3
      server/svr-authentication/src/main/java/com/yihu/jw/security/oauth2/provider/error/WlyyOAuth2ExceptionTranslator.java
  7. 2 0
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/role/RoleDao.java
  8. 5 2
      svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/role/RoleEndpoint.java
  9. 12 4
      svr/svr-base/src/main/java/com/yihu/jw/base/service/role/RoleService.java
  10. 4 0
      svr/svr-patient/src/main/java/com/yihu/jw/patient/dao/myFamily/PatientFamilyMemberDao.java
  11. 6 3
      svr/svr-patient/src/main/java/com/yihu/jw/patient/endpoint/myFamily/MyFamilyEndpoint.java
  12. 14 11
      svr/svr-patient/src/main/java/com/yihu/jw/patient/endpoint/servicepackage/PackageServiceEndpoint.java
  13. 16 1
      svr/svr-patient/src/main/java/com/yihu/jw/patient/endpoint/wechat/WechatInfoEndPoint.java
  14. 54 20
      svr/svr-patient/src/main/java/com/yihu/jw/patient/service/myFamily/MyFamilyService.java
  15. 2 2
      svr/svr-patient/src/main/java/com/yihu/jw/patient/service/myFamily/PatientFamilyMemberService.java
  16. 35 8
      svr/svr-patient/src/main/java/com/yihu/jw/patient/service/servicepackage/PackageService.java

+ 2 - 2
business/sms-service/src/main/java/com/yihu/jw/sms/dao/BaseSmsDao.java

@ -18,6 +18,6 @@ public interface BaseSmsDao extends PagingAndSortingRepository<SmsDO, String>, J
    boolean existsByCaptchaAndDeadlineAfter(String captcha, Date now);
    @Query("select a from SmsDO a where a.mobile = ?1 and a.captcha = ?2 and a.type = ?3")
    Page<SmsDO> findByCaptcha(String mobile, String captcha, SmsTemplateDO.Type type, Pageable pageRequest);
    @Query("select a from SmsDO a where a.mobile = ?1  and a.type = ?2")
    Page<SmsDO> findByCaptcha(String mobile, SmsTemplateDO.Type type, Pageable pageRequest);
}

+ 3 - 3
business/sms-service/src/main/java/com/yihu/jw/sms/service/BaseSmsService.java

@ -46,7 +46,7 @@ public class BaseSmsService extends BaseJpaService<SmsDO, BaseSmsDao>{
        // 分页信息
        PageRequest pageRequest = new PageRequest(0, 1, sort);
        SmsTemplateDO.Type value = SmsTemplateDO.valueOf(type);
        Page<SmsDO> page = baseSmsDao.findByCaptcha(mobile, captcha, value, pageRequest);
        Page<SmsDO> page = baseSmsDao.findByCaptcha(mobile, value, pageRequest);
        SmsDO sms = null;
        for (SmsDO temp : page) {
            if (temp != null) {
@ -58,8 +58,8 @@ public class BaseSmsService extends BaseJpaService<SmsDO, BaseSmsDao>{
        if (sms == null) {
            // 验证码错误
            return -1;
        } else if (type != sms.getType().ordinal()){
            // 验证码无效,也视为错误
        } else if (!sms.getCaptcha().equalsIgnoreCase(captcha)){
            // 验证码错误
            return -1;
        } else if (sms.getDeadline().before(new Date())) {
            // 验证码过期

+ 26 - 0
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/ResultStatus.java

@ -0,0 +1,26 @@
package com.yihu.jw.restmodel;
public class ResultStatus {
    /**
     *   1000多错误码 用户,应用相关的
     */
    public static final Integer USER_NO_EXIST = 1000;//用户不存在
    public static final Integer APP_NO_EXIST = 1001;//应用不存在
    /**
     * 1100多错误码 与授权相关的
     */
    public static final Integer ERROR_TOKEN = 1100; //token有误,错误的token  或者 过期的token
    public static final Integer NULL_TOKEN = 1101;// token为空
    public static final Integer INVALID_GRANT = 1102; //授权失败,看具体报错信息,如验证码错误,密码错误等
    public static final Integer NO_PERMI = 1103; //无权限访问
    /**
     *  1200多错误码
     */
    public static final Integer ERROR_PARA = 1200;//错误参数等
    public static final Integer FAILED_RESP = 1201;//返回出错
}

+ 7 - 8
gateway/ag-basic/src/main/java/com/yihu/jw/gateway/filter/BasicZuulFilter.java

@ -3,6 +3,7 @@ package com.yihu.jw.gateway.filter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.yihu.jw.restmodel.ResultStatus;
import com.yihu.jw.restmodel.web.Envelop;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -11,7 +12,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.TokenStore;
@ -21,7 +21,6 @@ import org.springframework.util.StringUtils;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Set;
/**
 * Created by progr1mmer on 2017/12/27
@ -85,14 +84,14 @@ public class BasicZuulFilter extends ZuulFilter {
    private Object authenticate(RequestContext ctx, HttpServletRequest request, String path) {
        String accessToken = this.extractToken(request);
        if (null == accessToken) {
            return this.forbidden(ctx, HttpStatus.FORBIDDEN.value(), "token can not be null");
            return this.forbidden(ctx, ResultStatus.NULL_TOKEN, "token can not be null");
        }
        OAuth2AccessToken oAuth2AccessToken = tokenStore.readAccessToken(accessToken);
        if (null == oAuth2AccessToken) {
            return this.forbidden(ctx, HttpStatus.FORBIDDEN.value(), "invalid token");
            return this.forbidden(ctx, ResultStatus.ERROR_TOKEN, "invalid token");
        }
        if (oAuth2AccessToken.isExpired()) {
            return this.forbidden(ctx, HttpStatus.PAYMENT_REQUIRED.value(), "expired token"); //返回402 登陆过期
            return this.forbidden(ctx, ResultStatus.ERROR_TOKEN, "expired token");
        }
        //将token的认证信息附加到请求中,转发给下游微服务
        OAuth2Authentication auth = tokenStore.readAuthentication(accessToken);
@ -101,7 +100,7 @@ public class BasicZuulFilter extends ZuulFilter {
//        Set<String> resourceIds = auth.getOAuth2Request().getResourceIds();
        String urls = redisTemplate.opsForValue().get("wlyy2:auth:token:"+accessToken);
        if(StringUtils.isEmpty(urls)){
           return this.forbidden(ctx, HttpStatus.FORBIDDEN.value(), "invalid token does not contain request resource " + path);
           return this.forbidden(ctx, ResultStatus.NO_PERMI, "invalid token does not contain request resource " + path);
        }
        //获取所有token资源
        String resourceIds[] = urls.split(",");
@ -119,7 +118,7 @@ public class BasicZuulFilter extends ZuulFilter {
                return true;
            }
        }
        return this.forbidden(ctx, HttpStatus.FORBIDDEN.value(), "invalid token does not contain request resource " + path);
        return this.forbidden(ctx, ResultStatus.NO_PERMI, "invalid token does not contain request resource " + path);
    }
    private String extractToken(HttpServletRequest request) {
@ -139,7 +138,7 @@ public class BasicZuulFilter extends ZuulFilter {
            //requestContext.setResponseStatusCode(status);
            requestContext.getResponse().getWriter().write(objectMapper.writeValueAsString(envelop));
        } catch (IOException e) {
            requestContext.setResponseStatusCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
            requestContext.setResponseStatusCode(ResultStatus.FAILED_RESP);
            logger.error(e.getMessage());
        }
        return false;

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

@ -2,6 +2,7 @@ package com.yihu.jw.security.oauth2.provider.endpoint;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.entity.base.login.BaseLoginLogDO;
import com.yihu.jw.restmodel.ResultStatus;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.security.core.userdetails.jdbc.WlyyUserDetailsService;
import com.yihu.jw.security.login.service.BaseLoginLogService;
@ -147,11 +148,11 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
        在网关处通过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 (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());
        }
@ -240,8 +241,11 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
        }
        String userAgent = loginLog.getUserAgent();
        WlyyUserSimple wlyyUserSimple = JSONObject.parseObject(userAgent, WlyyUserSimple.class);
//        String accessToken = wlyyUserSimple.getAccessToken();
//        OAuth2AccessToken oAuth2AccessToken = tokenStore.readAccessToken(accessToken);
        String accessToken = wlyyUserSimple.getAccessToken();
        OAuth2Authentication authentication = tokenStore.readAuthentication(accessToken);
        if (null == authentication) {
            throw new InvalidTokenException("Cant not load authentication");
        }
        return getResponse(wlyyUserSimple);
    }
@ -406,7 +410,7 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
        if (wlyyRedisVerifyCodeService.verification(client_id, username, captcha)) {
            oauth2Envelop = new Oauth2Envelop<>("验证码正确", 200, true);
        } else {
            oauth2Envelop = new Oauth2Envelop<>("验证码错误", 200, false);
            oauth2Envelop = new Oauth2Envelop<>("验证码错误", ResultStatus.INVALID_GRANT, false);
        }
        HttpHeaders headers = new HttpHeaders();
        headers.set("Cache-Control", "no-store");
@ -551,15 +555,15 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
    public ResponseEntity<Oauth2Envelop> handleException(Exception e) throws Exception {
        LOG.debug(e.getMessage(), e);
        if (e instanceof UsernameNotFoundException) {
            return handleOAuth2Exception(new Oauth2Envelop("用户不存在!", HttpStatus.UNAUTHORIZED.value()), e);
            return handleOAuth2Exception(new Oauth2Envelop("用户不存在!", ResultStatus.USER_NO_EXIST), e);
        } else if (e instanceof NoSuchClientException) {
            return handleOAuth2Exception(new Oauth2Envelop("应用未注册!", HttpStatus.UNAUTHORIZED.value()), e);
            return handleOAuth2Exception(new Oauth2Envelop("应用未注册!", ResultStatus.APP_NO_EXIST), e);
        } else if (e instanceof InvalidGrantException) {
            return handleOAuth2Exception(new Oauth2Envelop(invalidGrantMessage((InvalidGrantException)e), HttpStatus.UNAUTHORIZED.value()), e);
            return handleOAuth2Exception(new Oauth2Envelop(invalidGrantMessage((InvalidGrantException)e), ResultStatus.INVALID_GRANT), e);
        } else if (e instanceof InvalidTokenException) {
            return handleOAuth2Exception(new Oauth2Envelop("Token有误!", HttpStatus.UNAUTHORIZED.value()), e);
            return handleOAuth2Exception(new Oauth2Envelop("Token有误/过期!", ResultStatus.ERROR_TOKEN), e);
        } else if (e instanceof InvalidRequestException) {
            return handleOAuth2Exception(new Oauth2Envelop("参数" + e.getMessage() + "缺失!", HttpStatus.UNAUTHORIZED.value()), e);
            return handleOAuth2Exception(new Oauth2Envelop("参数" + e.getMessage() + "缺失!", ResultStatus.ERROR_PARA), e);
        } else if (e instanceof IllegalAccessException) {
            return handleOAuth2Exception(new Oauth2Envelop("短信请求频率过快,请稍后再试!", -1), e);
        } else if (e instanceof IllegalStateException) {

+ 8 - 3
server/svr-authentication/src/main/java/com/yihu/jw/security/oauth2/provider/error/WlyyOAuth2ExceptionTranslator.java

@ -1,5 +1,6 @@
package com.yihu.jw.security.oauth2.provider.error;
import com.yihu.jw.restmodel.ResultStatus;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ -63,12 +64,16 @@ public class WlyyOAuth2ExceptionTranslator implements WebResponseExceptionTransl
        HttpHeaders headers = new HttpHeaders();
        headers.set("Cache-Control", "no-store");
        headers.set("Pragma", "no-cache");
        if (status == HttpStatus.UNAUTHORIZED.value() || (e instanceof InsufficientScopeException)) {
        if (status == ResultStatus.USER_NO_EXIST
                || status == ResultStatus.APP_NO_EXIST
                || status == ResultStatus.ERROR_TOKEN
                || status == ResultStatus.NULL_TOKEN
                || status == ResultStatus.INVALID_GRANT
                || e instanceof InsufficientScopeException) {
            headers.set("WWW-Authenticate", String.format("%s %s", OAuth2AccessToken.BEARER_TYPE, e.getSummary()));
        }
        ResponseEntity<OAuth2Exception> response = new ResponseEntity<>(e, headers,
                HttpStatus.valueOf(status));
                HttpStatus.OK);
        return response;

+ 2 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/dao/role/RoleDao.java

@ -15,4 +15,6 @@ public interface RoleDao extends PagingAndSortingRepository<RoleDO, String>, Jpa
    RoleDO findByCode(String code);
    List<RoleDO> findByNameAndStatus(String name,Integer status);
    List<RoleDO> findByNameAndSaasIdAndStatus(String name,String saasId,Integer status);
}

+ 5 - 2
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/role/RoleEndpoint.java

@ -134,7 +134,10 @@ public class RoleEndpoint extends EnvelopRestEndpoint {
    @GetMapping(value = BaseRequestMapping.Role.findRoleNameExist)
    @ApiOperation(value = "判断角色是否存在")
    public ObjEnvelop<Boolean> findRoleNameExist(@ApiParam(name = "name", value = "角色名称")
                                     @RequestParam(value = "name", required = false)String name) {
        return success(BaseRequestMapping.Role.api_success,roleService.findRoleNameExist(name));
                                                 @RequestParam(value = "name", required = true)String name,
                                                 @ApiParam(name = "saasId", value = "租户id")
                                                 @RequestParam(value = "saasId", required = false)String saasId) {
        return success(BaseRequestMapping.Role.api_success,roleService.findRoleNameExist(name,saasId));
    }
}

+ 12 - 4
svr/svr-base/src/main/java/com/yihu/jw/base/service/role/RoleService.java

@ -7,6 +7,7 @@ import com.yihu.jw.entity.base.role.RoleMenuDO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.rm.base.BaseRequestMapping;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -43,10 +44,17 @@ public class RoleService extends BaseJpaService<RoleDO, RoleDao> {
        return Envelop.getSuccess(BaseRequestMapping.Role.api_success);
    }
    public Boolean findRoleNameExist(String name){
        List<RoleDO> list = roleDao.findByNameAndStatus(name,1);
        if(list!=null&&list.size()>0){
            return true;
    public Boolean findRoleNameExist(String name,String saasId){
        if(StringUtils.isNotBlank(saasId)){
            List<RoleDO> list = roleDao.findByNameAndSaasIdAndStatus(name,saasId,1);
            if(list!=null&&list.size()>0){
                return true;
            }
        }else{
            List<RoleDO> list = roleDao.findByNameAndStatus(name,1);
            if(list!=null&&list.size()>0){
                return true;
            }
        }
        return false;
    }

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

@ -39,5 +39,9 @@ public interface PatientFamilyMemberDao extends PagingAndSortingRepository<BaseP
    @Query("update BasePatientFamilyMemberDO m set m.del = ?1 where m.id=?2 ")
    int updateDelById(Integer del,String id);
    @Modifying
    @Query("update BasePatientFamilyMemberDO m set m.del = ?1 where m.patient=?2 and m.familyMember=?3 ")
    int updateDelByPatientAndFamilyMember(Integer del,String patient,String familyPatientId);
    BasePatientFamilyMemberDO findByPatientAndFamilyMemberAndDel(String patient,String familyMember,Integer del);
}

+ 6 - 3
svr/svr-patient/src/main/java/com/yihu/jw/patient/endpoint/myFamily/MyFamilyEndpoint.java

@ -228,10 +228,13 @@ public class MyFamilyEndpoint extends EnvelopRestEndpoint {
    @PostMapping(value = PatientRequestMapping.MyFamily.cancelBindFamily)
    @ApiOperation(value = "解除绑定家人")
    public Envelop cancelBindFamily(
            @ApiParam(name = "familyMemberId", value = "familyMemberId", required = true)
            @RequestParam(value = "familyMemberId",required = true) String familyMemberId) throws Exception {
            @ApiParam(name = "patientId", value = "申请人patient的Id", required = true)
            @RequestParam(value = "patientId",required = true) String patientId,
            @ApiParam(name = "familyPatientId", value = "家人patient的id", required = true)
            @RequestParam(value = "familyPatientId",required = true) String familyPatientId) throws Exception {
        try{
            myFamilyService.cancelBindFamily(familyMemberId);
            myFamilyService.cancelBindFamily(patientId,familyPatientId);
            myFamilyService.cancelBindFamily(familyPatientId,patientId);
            return success();
        }catch (Exception e){
            e.printStackTrace();

+ 14 - 11
svr/svr-patient/src/main/java/com/yihu/jw/patient/endpoint/servicepackage/PackageServiceEndpoint.java

@ -30,6 +30,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * Created by Trick on 2018/11/27.
@ -52,11 +53,13 @@ public class PackageServiceEndpoint extends EnvelopRestEndpoint {
                                         @RequestParam(value = "labelType", required = false)String labelType,
                                         @ApiParam(name = "patient", value = "居民code(判断居民是否签约,非必传)")
                                         @RequestParam(value = "patient", required = false)String patient,
                                         @ApiParam(name = "saasId", value = "租户id")
                                         @RequestParam(value = "saasId", required = false)String saasId,
                                         @ApiParam(name = "page", value = "第几页")
                                         @RequestParam(value = "page", required = true)Integer page,
                                         @ApiParam(name = "size", value = "每页大小")
                                         @RequestParam(value = "size", required = true)Integer size) {
        return packageService.findPackageService(city,labelCode,labelType,patient,page,size);
        return packageService.findPackageService(city,saasId,labelCode,labelType,patient,page,size);
    }
@ -110,26 +113,26 @@ public class PackageServiceEndpoint extends EnvelopRestEndpoint {
    @PostMapping(value = PatientRequestMapping.SignPackage.signPackageAndFamily)
    @ApiOperation(value = "绑定家人,签约服务包", notes = "绑定家人,签约服务包")
    public Envelop signPackageAndFamily(@ApiParam(name = "recordJson", value = "签约实体")
    public ObjEnvelop<Map<String,Object>> signPackageAndFamily(@ApiParam(name = "recordJson", value = "签约实体")
                                        @RequestParam(value = "recordJson", required = true)String recordJson,
                                        @ApiParam(name = "patient", value = "申请绑定的居民code")
                                                               @ApiParam(name = "patient", value = "申请绑定的居民code")
                                        @RequestParam(value = "patient", required = true)String patient,
                                        @ApiParam(name = "familyName", value = "申请绑定的家人的名称")
                                                               @ApiParam(name = "familyName", value = "申请绑定的家人的名称")
                                        @RequestParam(value = "familyName", required = false)String familyName,
                                        @ApiParam(name = "principalNum", value = "医社保号")
                                                               @ApiParam(name = "principalNum", value = "医社保号")
                                        @RequestParam(value = "principalNum", required = false)String principalNum,
                                        @ApiParam(name = "idcard", value = "身份证号")
                                                               @ApiParam(name = "idcard", value = "身份证号")
                                        @RequestParam(value = "idcard", required = false)String idcard,
                                        @ApiParam(name = "familyMobile", value = "家人的手机号码")
                                                               @ApiParam(name = "familyMobile", value = "家人的手机号码")
                                        @RequestParam(value = "familyMobile", required = true)String familyMobile,
                                        @ApiParam(name = "platform", value = "消息平台,1微信端/患者端,2医生APP端")
                                                               @ApiParam(name = "platform", value = "消息平台,1微信端/患者端,2医生APP端")
                                        @RequestParam(value = "platform", required = true)Integer platform,
                                        @ApiParam(name = "familyBindRole", value = "1\"配偶\",2\"父亲\",3\"母亲\",4\"公公\",5\"婆婆\",6\"岳父\",7\"岳母\",8\"女婿\",9\"儿媳\",10\"子女\"")
                                                               @ApiParam(name = "familyBindRole", value = "1\"配偶\",2\"父亲\",3\"母亲\",4\"公公\",5\"婆婆\",6\"岳父\",7\"岳母\",8\"女婿\",9\"儿媳\",10\"子女\"")
                                        @RequestParam(value = "familyBindRole", required = true)Integer familyBindRole,
                                        @ApiParam(name = "isAdult", value = "0未成年人 1成年人")
                                                               @ApiParam(name = "isAdult", value = "0未成年人 1成年人")
                                        @RequestParam(value = "isAdult", required = true)Integer isAdult) throws Exception {
        ServicePackageSignRecordDO recordDO = toEntity(recordJson, ServicePackageSignRecordDO.class);
        return packageService.signPackageAndFamily(recordDO,patient,familyMobile,platform,familyBindRole,isAdult,familyName,principalNum,idcard);
        return success(PatientRequestMapping.SignPackage.api_success,packageService.signPackageAndFamily(recordDO,patient,familyMobile,platform,familyBindRole,isAdult,familyName,principalNum,idcard));
    }
    @GetMapping(value = PatientRequestMapping.SignPackage.findDoctorById)

+ 16 - 1
svr/svr-patient/src/main/java/com/yihu/jw/patient/endpoint/wechat/WechatInfoEndPoint.java

@ -13,11 +13,13 @@ import com.yihu.jw.wechat.service.WxAccessTokenService;
import com.yihu.jw.wechat.service.WxUrlConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
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.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@ -28,6 +30,7 @@ import java.security.MessageDigest;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
/**
 * Created by Trick on 2018/12/3.
@ -45,6 +48,8 @@ public class WechatInfoEndPoint extends EnvelopRestEndpoint {
    private WechatInfoService wechatInfoService;
    @Value("${wechat.id}")
    private String wxId;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private WxUrlConfigService wxUrlConfigService;
@ -96,7 +101,15 @@ public class WechatInfoEndPoint extends EnvelopRestEndpoint {
    @RequestMapping(value = "getOpenidByCode", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public Envelop getOpenidByCode(String code) throws Exception {
        String openid = wechatInfoService.getOpenidByCode(code, wxId);
        //通过redis获取openid, 获取不到,则调用微信接口去取
        String key = wxId+":code";
        String openid = redisTemplate.opsForValue().get(key);
        if(StringUtils.isNotBlank(openid)){
            return success(PatientRequestMapping.Wechat.api_success,openid);
        }
        openid = wechatInfoService.getOpenidByCode(code, wxId);
        redisTemplate.opsForValue().set(key,openid);
        redisTemplate.expire(key,10, TimeUnit.SECONDS);
        return success(PatientRequestMapping.Wechat.api_success,openid);
    }
@ -173,4 +186,6 @@ public class WechatInfoEndPoint extends EnvelopRestEndpoint {
        }
        return null;
    }
}

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

@ -107,7 +107,7 @@ public class MyFamilyService {
            }
        }
        //生成社保卡号
        if(!StringUtils.isEmpty(principalNum)){
        if(!StringUtils.isEmpty(principalNum)&&!patientMedicareCardService.existsByCodeAndDel(principalNum)){
            PatientMedicareCardDO medicareCardDO = new PatientMedicareCardDO();
            medicareCardDO.setCode(principalNum);
            medicareCardDO.setParentType(PatientMedicareCardDO.ParentType.CareCard.getType());
@ -140,7 +140,12 @@ public class MyFamilyService {
            messageDO.setSenderPhoto(patientDO.getPhoto());
            messageDO.setTitle("家人绑定");
            messageDO.setMsgDigest("");
            String msgContent = familyPatient.getName()+",您好!"+patientDO.getName()+"向您发起添加家人申请,添加成功后,对方可使用您的账号,为您处理各类健康服务。";
            String msgContent = "";
            if(familyPatient.getName()==null){
                msgContent = "您好!"+patientDO.getName()+"向您发起添加家人申请,添加成功后,对方可使用您的账号,为您处理各类健康服务。";
            }else{
                msgContent = familyPatient.getName()+",您好!"+patientDO.getName()+"向您发起添加家人申请,添加成功后,对方可使用您的账号,为您处理各类健康服务。";
            }
            messageDO.setMsgContent(msgContent);
            messageDO.setMsgTypeCode("010801");
            messageDO.setMsgTypeName("系统消息-添加家人申请");
@ -186,13 +191,28 @@ public class MyFamilyService {
     */
    public Map<String,Object> signBindFamily( String patient, String familyMobile, Integer platform,Integer familyBindRole,Integer isAdult,
                                              String familyName,String principalNum,String idcard) throws Exception{
        //判断身份证号和社保卡号重复问题
        if(patientService.existsByIdcard(idcard)){
            throw new Exception("填写身份证已存在!");
        }
        if(patientMedicareCardService.existsByCodeAndDel(principalNum)){
            throw new Exception("填写社保卡号已存在!");
        BasePatientDO familyPatient2 = patientService.findByMobileAndDel(familyMobile);
        if(familyPatient2!=null){
            if(!idcard.equals(familyPatient2.getIdcard())){
                throw new Exception("填写身份证有误!");
            }
            if(!StringUtils.isEmpty(principalNum)){
                PatientMedicareCardDO card = patientMedicareCardService.findByTypeAndPatientCodeAndDel(PatientMedicareCardDO.Type.MedicareCard.getType(),familyPatient2.getId(),"1");
                if(card!=null&&!principalNum.equals(card.getCode())){
                    throw new Exception("填写社保卡号有误!");
                }
            }
        }else{
            //判断身份证号和社保卡号重复问题
            if(patientService.existsByIdcard(idcard)){
                throw new Exception("填写身份证已存在!");
            }
            if(patientMedicareCardService.existsByCodeAndDel(principalNum)){
                throw new Exception("填写社保卡号已存在!");
            }
        }
        if(isAdult==1){
            Map<String,Object> p = bindingMyFamily(patient, familyMobile, platform,familyBindRole,familyName,principalNum,idcard);
@ -322,6 +342,9 @@ public class MyFamilyService {
     */
    @Transactional(rollbackFor = Exception.class)
    public Map<String,Object> scanQRcodeConfirmApply(Integer status,String applyPatient,String familyPatient,Integer familyBindRole,Integer isAuthorize)throws Exception{
        if(applyPatient.equals(familyPatient)){
            throw new Exception("非家人操作!");
        }
        Map<String,Object> map = new HashedMap();
        if(status==3){
            BasePatientFamilyMemberDO patientFamilyMember = new BasePatientFamilyMemberDO();
@ -375,8 +398,11 @@ public class MyFamilyService {
        }else{
            map.put("isBinding",0);
        }
        map.put("explain","您的"+role.get(converRole-1)+apply.getName()+"邀请您绑定家人账号");
        if(apply.getName()==null){
            map.put("explain","您的"+role.get(converRole-1)+"邀请您绑定家人账号");
        }else{
            map.put("explain","您的"+role.get(converRole-1)+apply.getName()+"邀请您绑定家人账号");
        }
        return map;
    }
@ -395,7 +421,11 @@ public class MyFamilyService {
        Integer converRole = familyRelationTrans(patientApplyLog.getFamilyBindRole(),apply.getSex());
        if(patientApplyLog.getFailureTime().getTime()<System.currentTimeMillis()) {
            map.put("overdue", "1");//过期
            map.put("explain", "您的" + role.get(converRole - 1) + apply.getName() + "向您发起的绑定邀请已过期");
            if(apply.getName()==null){
                map.put("explain", "您的" + role.get(converRole - 1)  + "向您发起的绑定邀请已过期");
            }else{
                map.put("explain", "您的" + role.get(converRole - 1) + apply.getName() + "向您发起的绑定邀请已过期");
            }
        }else {
            map.put("overdue", "0");
        }
@ -451,7 +481,7 @@ public class MyFamilyService {
            map2.put("cardTypeName","身份证");
            map2.put("idcard",basePatientDO.getIdcard());//身份证
            PatientMedicareCardDO patientMedicareCard = patientMedicareCardService.findByTypeAndPatientCodeAndDel(PatientMedicareCardDO.Type.MedicareCard.getType(),basePatientDO.getId(),"1");
            if(patientMedicareCardDO!=null){
            if(patientMedicareCard!=null){
                map2.put("principalNum",patientMedicareCard.getCode());//社保卡号
            }else{
@ -587,12 +617,16 @@ public class MyFamilyService {
            map.put("applySex",createPatient.getSex());
            map.put("applyPatientPhoto",createPatient.getPhoto());
            map.put("applyPatientNonage",this.nonageByIdcard(createPatient.getIdcard()));//1成年,2未成年
            map.put("explain","您的"+role.get(converRole-1)+createPatient.getName()+"邀请您绑定家人账号");
            if(createPatient.getName()==null){
                map.put("explain","您的"+role.get(converRole-1)+"邀请您绑定家人账号");
            }else{
                map.put("explain","您的"+role.get(converRole-1)+createPatient.getName()+"邀请您绑定家人账号");
            }
            result.add(map);
            BaseMessageDO msg = messageService.findById(Integer.valueOf(one.get("id")+""));
            msg.setReadState(1);
            msg.setReadTime(new Date());
            messageService.save(msg);
//            BaseMessageDO msg = messageService.findById(Integer.valueOf(one.get("id")+""));
//            msg.setReadState(1);
//            msg.setReadTime(new Date());
//            messageService.save(msg);
        }
        return result;
    }
@ -612,12 +646,12 @@ public class MyFamilyService {
    /**
     * 解除绑定
     * @param familyMemberId
     * @param patient
     * @throws Exception
     */
    @Transactional(rollbackFor = Exception.class)
    public void cancelBindFamily(String familyMemberId) throws Exception{
        int i = patientFamilyMemberService.cancelBindFamily(familyMemberId);
    public void cancelBindFamily(String patient,String familyPatientId) throws Exception{
        int i = patientFamilyMemberService.cancelBindFamily(patient,familyPatientId);
        if(i<0){
            throw new Exception("update data failur !");
        }

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

@ -52,8 +52,8 @@ public class PatientFamilyMemberService extends BaseJpaService<BasePatientFamily
        return patientFamilyMemberDao.getByPatientAndFamilyMember(patient);
    }
    public Integer cancelBindFamily(String id){
        return patientFamilyMemberDao.updateDelById(0,id);
    public Integer cancelBindFamily(String patient,String familyPatientId){
        return patientFamilyMemberDao.updateDelByPatientAndFamilyMember(0,patient,familyPatientId);
    }
    public Integer updateAuthorizeById(Integer isAuthorize,String id){

+ 35 - 8
svr/svr-patient/src/main/java/com/yihu/jw/patient/service/servicepackage/PackageService.java

@ -25,6 +25,7 @@ import com.yihu.jw.restmodel.patient.signPackage.ServicePackageVO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.rm.patient.PatientRequestMapping;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
@ -70,7 +71,7 @@ public class PackageService {
    @Autowired
    private PatientLabelDao patientLabelDao;
    public MixEnvelop findPackageService(String city,String labelCode,String labelType,String patient,Integer page,Integer size){
    public MixEnvelop findPackageService(String city,String saasId ,String labelCode,String labelType,String patient,Integer page,Integer size){
        String totalSql ="SELECT " +
                " count(1) as total " +
@ -83,9 +84,12 @@ public class PackageService {
                " p.city_code = '"+city+"' " +
                " AND p.del =1 ";
        if(StringUtils.isNotBlank(labelCode)&&StringUtils.isNotBlank(labelType)){
            totalSql += " ADN l.label_code='"+labelCode+"'" +
            totalSql += " AND l.label_code='"+labelCode+"'" +
                        " AND l.label_type='"+labelType+"' ";
        }
        if(StringUtils.isNotBlank(saasId)){
            totalSql += " AND p.saas_id = '"+saasId+"' ";
        }
        List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(totalSql);
        Long count = 0L;
@ -118,9 +122,12 @@ public class PackageService {
                " p.city_code = '"+city+"' " +
                " AND p.del =1 ";
        if(StringUtils.isNotBlank(labelCode)&&StringUtils.isNotBlank(labelType)){
            sql +=  " ADN l.label_code='"+labelCode+"'" +
            sql +=  " AND l.label_code='"+labelCode+"'" +
                    " AND l.label_type='"+labelType+"' ";
        }
        if(StringUtils.isNotBlank(saasId)){
            sql += " AND p.saas_id = '"+saasId+"' ";
        }
        sql +=  "ORDER BY p.sort ASC LIMIT " + (page - 1) * size + "," + size + "";
        List<ServicePackageVO> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(ServicePackageVO.class));
@ -252,14 +259,34 @@ public class PackageService {
        return Envelop.getSuccess(PatientRequestMapping.SignPackage.api_success);
    }
    public Envelop signPackageAndFamily(ServicePackageSignRecordDO recordDO,String patient, String familyMobile, Integer platform, Integer familyBindRole,
    public Map<String,Object> signPackageAndFamily(ServicePackageSignRecordDO recordDO,String patient, String familyMobile, Integer platform, Integer familyBindRole,
                                        Integer isAdult,String familyName,String principalNum,String idcard) throws Exception{
        //1.绑定家人
        myFamilyService.signBindFamily(patient,familyMobile,platform,familyBindRole,isAdult,familyName,principalNum,idcard);
        //2.服务签约
        servicePackageSignRecordDao.save(recordDO);
        Map<String,Object> map = myFamilyService.signBindFamily(patient,familyMobile,platform,familyBindRole,isAdult,familyName,principalNum,idcard);
        return Envelop.getSuccess(PatientRequestMapping.SignPackage.api_success);
        Map<String,Object> rs = new HashedMap();
        if(map!=null){
            //2.服务签约
            String memberPatient =  map.get("familyMemberCode").toString();
            recordDO.setPatient(memberPatient);
            if(findPatientSignExist(memberPatient,recordDO.getServicePackageId())){
                rs.put("mes","用户已存在");
                rs.put("status","-1");
                return rs;
            }
            servicePackageSignRecordDao.save(recordDO);
            rs.put("mes","签约成功");
            rs.put("status","1");
            return rs;
        }else{
            rs.put("mes","用户创建失败!");
            rs.put("status","-2");
        }
        return rs;
    }