Browse Source

Merge branch 'dev/one' into debug

zhoutg 6 years ago
parent
commit
93036d1369
22 changed files with 455 additions and 105 deletions
  1. 2 1
      common/src/main/java/com/diagbot/exception/CommonErrorCode.java
  2. 17 2
      common/src/main/java/com/diagbot/util/JwtUtil.java
  3. 1 0
      config-server/src/main/resources/shared/user-service-dev.yml
  4. 1 0
      config-server/src/main/resources/shared/user-service-local.yml
  5. 1 0
      config-server/src/main/resources/shared/user-service-test.yml
  6. 4 1
      diagbotman-service/src/main/java/com/diagbot/facade/LantoneProductFacade.java
  7. 1 1
      diagbotman-service/src/main/java/com/diagbot/facade/OrderDetailsFacade.java
  8. 12 1
      diagbotman-service/src/main/java/com/diagbot/facade/ProductOrderFacade.java
  9. 4 0
      gateway-service/src/main/java/com/diagbot/client/UserServiceClient.java
  10. 7 0
      gateway-service/src/main/java/com/diagbot/client/hystrix/UserServiceHystrix.java
  11. 21 0
      gateway-service/src/main/java/com/diagbot/entity/Token.java
  12. 20 0
      gateway-service/src/main/java/com/diagbot/filter/GlobalGatewayFilter.java
  13. 13 0
      user-service/src/main/java/com/diagbot/config/RedisConfigurer.java
  14. 1 0
      user-service/src/main/java/com/diagbot/config/ResourceServerConfigurer.java
  15. 1 0
      user-service/src/main/java/com/diagbot/config/security/UrlAccessDecisionManager.java
  16. 16 0
      user-service/src/main/java/com/diagbot/entity/JwtStore.java
  17. 21 0
      user-service/src/main/java/com/diagbot/entity/Token.java
  18. 13 0
      user-service/src/main/java/com/diagbot/facade/TokenFacade.java
  19. 125 99
      user-service/src/main/java/com/diagbot/facade/UserFacade.java
  20. 29 0
      user-service/src/main/java/com/diagbot/service/TokenService.java
  21. 128 0
      user-service/src/main/java/com/diagbot/service/impl/TokenServiceImpl.java
  22. 17 0
      user-service/src/main/java/com/diagbot/web/UserController.java

+ 2 - 1
common/src/main/java/com/diagbot/exception/CommonErrorCode.java

@@ -22,7 +22,8 @@ public enum CommonErrorCode implements ErrorCode {
     SERVER_IS_ERROR("00020007", "各自业务错误!"),
     NO_PERMISSION("00020008", "无权访问!"),
     IS_EXISTS("00020009", "已存在!"),
-    ANALYZER_TOKEN_FAIL("10020010", "解析token失败");
+    ANALYZER_TOKEN_FAIL("10020010", "解析token失败"),
+    TOKEN_PAST("10020011", "token已失效,请重新登录");
 
     private String code;
     private String msg;

File diff suppressed because it is too large
+ 17 - 2
common/src/main/java/com/diagbot/util/JwtUtil.java


+ 1 - 0
config-server/src/main/resources/shared/user-service-dev.yml

@@ -70,6 +70,7 @@ spring:
       idc: 1 # 不可见ID索引
       sms: 2 # Redis短信索引
       img: 3 # Redis图片验证码索引
+      token: 4 # Token索引
     host: 192.168.2.236  #Redis服务器地址
     port: 6379 # Redis服务器连接端口
     password: lantone # Redis服务器连接密码(默认为空)

+ 1 - 0
config-server/src/main/resources/shared/user-service-local.yml

@@ -70,6 +70,7 @@ spring:
       idc: 11 # 不可见ID索引
       sms: 12 # Redis短信索引
       img: 13 # Redis图片验证码索引
+      token: 14 # Token索引
     host: 192.168.2.236  #Redis服务器地址
     port: 6379 # Redis服务器连接端口
     password: lantone # Redis服务器连接密码(默认为空)

+ 1 - 0
config-server/src/main/resources/shared/user-service-test.yml

@@ -70,6 +70,7 @@ spring:
       idc: 1 # 不可见ID索引
       sms: 2 # Redis短信索引
       img: 3 # Redis图片验证码索引
+      token: 4 # Token索引
     host: 192.168.2.241  #Redis服务器地址
     port: 6379 # Redis服务器连接端口
     password: lantone # Redis服务器连接密码(默认为空)

+ 4 - 1
diagbotman-service/src/main/java/com/diagbot/facade/LantoneProductFacade.java

@@ -91,7 +91,7 @@ public class LantoneProductFacade extends LantoneProductServiceImpl {
      */
     public Boolean updateProduct(UpdateProductVO updateProductVO) {
         LantoneProduct lantoneProductInfo = this.selectProductByName(updateProductVO.getName());
-        if(updateProductVO.getName().equals(lantoneProductInfo.getName()) && updateProductVO.getId() != lantoneProductInfo.getId()){
+        if(null != lantoneProductInfo && updateProductVO.getName().equals(lantoneProductInfo.getName()) && updateProductVO.getId() != lantoneProductInfo.getId()){
             throw new CommonException(CommonErrorCode.SERVER_IS_ERROR,
                     "产品名称重复");
         }
@@ -279,6 +279,9 @@ public class LantoneProductFacade extends LantoneProductServiceImpl {
         BeanUtil.copyProperties(oppendedProductVO, openedProductsIndex);
         if(oppendedProductVO.getOrgName()!=null&&oppendedProductVO.getOrgName()!=""){
             RespDTO<List<Long>> rlist = userServiceClient.getUserByOrgName(oppendedProductVO.getOrgName());
+            if(rlist.data.size() == 0){
+                rlist.data.add(-1L);
+            }
             openedProductsIndex.setUserId(rlist.data);
         }
         List<OpendProductDTO> list = openedProductsFacade.getByProductId(page,openedProductsIndex).getRecords();

+ 1 - 1
diagbotman-service/src/main/java/com/diagbot/facade/OrderDetailsFacade.java

@@ -92,11 +92,11 @@ public class OrderDetailsFacade extends OrderDetailsServiceImpl {
             }
             return productOrderFacade.updateProductOrderStatus(orderDetails.getOrderNum());
         }
+        orderDetails.setStatus(PaymentMethodEnum.PAY.getKey());
         if(!this.updateById(orderDetails)){
             throw new CommonException(CommonErrorCode.SERVER_IS_ERROR,
                     "审核状态修改失败");
         }
-        orderDetails.setStatus(PaymentMethodEnum.PAY.getKey());
         Long userId =Long.parseLong(UserUtils.getCurrentPrincipleID());
         OpenedProducts openedProducts =new OpenedProducts();
         openedProducts.setGmtCreate(DateUtil.now());

+ 12 - 1
diagbotman-service/src/main/java/com/diagbot/facade/ProductOrderFacade.java

@@ -234,9 +234,20 @@ public class ProductOrderFacade extends ProductOrderServiceImpl {
 		//TODO
         if(productOrderVO.getOrgName()!=null&&productOrderVO.getOrgName()!=""){
             RespDTO<List<Long>> rlist = userServiceClient.getUserByOrgName(productOrderVO.getOrgName());
+            if(rlist == null || !"0".equals(rlist.code) ) {
+                throw new CommonException(CommonErrorCode.SERVER_IS_ERROR,
+                        "获取用户和机构信息失败");
+            }
+            if(rlist.data.size() == 0){
+                rlist.data.add(-1L);
+            }
             productOrderIndex.setUserId(rlist.data);
         }else{
             RespDTO<List<User>> userInfiList = userServiceClient.getUserAllInfo();
+            if(userInfiList == null || !"0".equals(userInfiList.code) ) {
+                throw new CommonException(CommonErrorCode.SERVER_IS_ERROR,
+                        "获取用户和机构信息失败");
+            }
             List<Long> userIds =new ArrayList<>();
             for (User user:userInfiList.data) {
                 userIds.add(user.getId());
@@ -362,7 +373,7 @@ public class ProductOrderFacade extends ProductOrderServiceImpl {
         for (int i = 0; i < datas.data.getRecords().size(); i++) {
             ProductOrderWrapper userInfo = datas.data.getRecords().get(i);
             list.add(new ProductOrderExportDTO(String.valueOf(i+1),
-                    DateUtil.formatDate(userInfo.getTime()),
+                    DateUtil.formatDateTime(userInfo.getTime()),
                     userInfo.getNum(),
                     userInfo.getOrgName(),
                     userInfo.getLinkman(),

+ 4 - 0
gateway-service/src/main/java/com/diagbot/client/UserServiceClient.java

@@ -2,9 +2,11 @@ package com.diagbot.client;
 
 import com.diagbot.client.hystrix.UserServiceHystrix;
 import com.diagbot.dto.RespDTO;
+import com.diagbot.entity.Token;
 import com.diagbot.entity.User;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestParam;
 
 
@@ -19,6 +21,8 @@ public interface UserServiceClient {
     @PostMapping("/user/login")
     RespDTO<User> login(@RequestParam("username") String username, @RequestParam("password") String password);
 
+    @PostMapping("/user/verifyToken")
+    RespDTO<Boolean> verifyToken(@RequestBody Token token);
 }
 
 

+ 7 - 0
gateway-service/src/main/java/com/diagbot/client/hystrix/UserServiceHystrix.java

@@ -3,6 +3,7 @@ package com.diagbot.client.hystrix;
 
 import com.diagbot.client.UserServiceClient;
 import com.diagbot.dto.RespDTO;
+import com.diagbot.entity.Token;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
 
@@ -19,4 +20,10 @@ public class UserServiceHystrix implements UserServiceClient {
         log.error("【hystrix】调用{}异常", "login");
         return null;
     }
+
+    @Override
+    public RespDTO<Boolean> verifyToken(Token token) {
+        log.error("【hystrix】调用{}异常", "verifyToken");
+        return null;
+    }
 }

+ 21 - 0
gateway-service/src/main/java/com/diagbot/entity/Token.java

@@ -0,0 +1,21 @@
+package com.diagbot.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.io.Serializable;
+
+/**
+ * @Description: token
+ * @Author: ztg
+ * @Date: 2018/9/19 13:14
+ */
+@Getter
+@Setter
+public class Token implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    private String token;
+
+}

+ 20 - 0
gateway-service/src/main/java/com/diagbot/filter/GlobalGatewayFilter.java

@@ -4,7 +4,10 @@ import com.diagbot.client.DiagbotmanServiceClient;
 import com.diagbot.client.UserServiceClient;
 import com.diagbot.dto.RespDTO;
 import com.diagbot.entity.ServiceToken;
+import com.diagbot.entity.Token;
+import com.diagbot.exception.CommonErrorCode;
 import com.diagbot.util.GsonUtil;
+import com.diagbot.util.StringUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -70,6 +73,23 @@ public class GlobalGatewayFilter implements GlobalFilter {
         log.info("APIURL:{}", requestUri);
         log.info("SERVICENAME:{}", serviceName);
 
+        //验证token有效性
+        String tokenStr = request.getHeaders().getFirst("Authorization");
+        if(StringUtil.isNotEmpty(tokenStr)) {
+            Token token = new Token();
+            tokenStr = tokenStr.replaceFirst("Bearer ", "");
+            token.setToken(tokenStr);
+            RespDTO<Boolean> res = userServiceClient.verifyToken(token);
+            if (res == null || !RespDTO.TRUE_CODE.equals(res.code)) {
+                return getVoidMono(serverWebExchange, res);
+            }
+            if(!res.data) {
+                res.code = CommonErrorCode.TOKEN_PAST.getCode();
+                res.msg = CommonErrorCode.TOKEN_PAST.getMsg();
+                return getVoidMono(serverWebExchange, res);
+            }
+        }
+
         //        if(!IS_GENERATE) {
         //            RespDTO<List<ServiceFilter>> filter = diagbotmanServiceClient.getAll();
         //            if (filter != null){

+ 13 - 0
user-service/src/main/java/com/diagbot/config/RedisConfigurer.java

@@ -34,6 +34,8 @@ public class RedisConfigurer extends CachingConfigurerSupport {
     private String databaseSms;
     @Value("${spring.redis.database.img}")
     private String databaseImg;
+    @Value("${spring.redis.database.token}")
+    private String databaseToken;
     @Value("${spring.redis.host}")
     private String host;
     @Value("${spring.redis.password}")
@@ -171,6 +173,17 @@ public class RedisConfigurer extends CachingConfigurerSupport {
         return getRedisTemplate(factory, Integer.valueOf(databaseImg));
     }
 
+    /**
+     * Token使用的redis
+     *
+     * @param factory
+     * @return
+     */
+    @Bean(name = "redisTemplateForToken")
+    public RedisTemplate<String, Object> redisTemplateForToken(JedisConnectionFactory factory) {
+        return getRedisTemplate(factory, Integer.valueOf(databaseToken));
+    }
+
     private RedisTemplate<String, Object> getRedisTemplate(JedisConnectionFactory factory, Integer database) {
         JedisConnectionFactory factory2 = new JedisConnectionFactory();
         BeanUtil.copyProperties(factory, factory2);

+ 1 - 0
user-service/src/main/java/com/diagbot/config/ResourceServerConfigurer.java

@@ -44,6 +44,7 @@ public class ResourceServerConfigurer extends ResourceServerConfigurerAdapter {
                 .antMatchers("/user/verifyExistUsername").permitAll()
                 .antMatchers("/userAuthentication/getAuthInfoCount").permitAll()
                 .antMatchers("/user/getUserAllInfo").permitAll()
+                .antMatchers("/user/verifyToken").permitAll()
                 .antMatchers("/**").authenticated();
         //        .antMatchers("/**").permitAll();
     }

+ 1 - 0
user-service/src/main/java/com/diagbot/config/security/UrlAccessDecisionManager.java

@@ -88,6 +88,7 @@ public class UrlAccessDecisionManager implements AccessDecisionManager {
                 || matchers("/user/verifyExistUsername", request)
                 || matchers("/userAuthentication/getAuthInfoCount", request)
                 || matchers("/user/getUserAllInfo", request)
+                || matchers("/user/verifyToken", request)
                 || matchers("/", request)) {
             return true;
         }

+ 16 - 0
user-service/src/main/java/com/diagbot/entity/JwtStore.java

@@ -0,0 +1,16 @@
+package com.diagbot.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * @Description:
+ * @author: gaodm
+ * @time: 2018/10/29 14:38
+ */
+@Getter
+@Setter
+public class JwtStore {
+    private String accessToken;
+    private String refreshToken;
+}

+ 21 - 0
user-service/src/main/java/com/diagbot/entity/Token.java

@@ -0,0 +1,21 @@
+package com.diagbot.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.io.Serializable;
+
+/**
+ * @Description: token
+ * @Author: ztg
+ * @Date: 2018/9/19 13:14
+ */
+@Getter
+@Setter
+public class Token implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    private String token;
+
+}

+ 13 - 0
user-service/src/main/java/com/diagbot/facade/TokenFacade.java

@@ -0,0 +1,13 @@
+package com.diagbot.facade;
+
+import com.diagbot.service.impl.TokenServiceImpl;
+import org.springframework.stereotype.Component;
+
+/**
+ * @Description: token实现
+ * @author: gaodm
+ * @time: 2018/10/29 14:24
+ */
+@Component
+public class TokenFacade extends TokenServiceImpl {
+}

+ 125 - 99
user-service/src/main/java/com/diagbot/facade/UserFacade.java

@@ -24,6 +24,7 @@ import com.diagbot.dto.UserLoginDTO;
 import com.diagbot.dto.UserOrgDTO;
 import com.diagbot.dto.UserOrgizationProductDTO;
 import com.diagbot.entity.JWT;
+import com.diagbot.entity.JwtStore;
 import com.diagbot.entity.Organization;
 import com.diagbot.entity.User;
 import com.diagbot.entity.UserAuthentication;
@@ -107,7 +108,9 @@ public class UserFacade extends UserServiceImpl {
     DiagbotmanClient diagbotmanClient;
     @Autowired
     private VisibleIdCreater visibleIdCreater;
-	
+    @Autowired
+    private TokenFacade tokenFacade;
+
 
     /**
      * 注册
@@ -157,10 +160,10 @@ public class UserFacade extends UserServiceImpl {
      */
     public Boolean verifyNoUser(UsernameVO usernameVO) {
         String username = usernameVO.getUsername();
-        if(StringUtil.isEmpty(username)) {
+        if (StringUtil.isEmpty(username)) {
             throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "请输入手机号");
         }
-        if(!RegexValidateUtil.checkMobileNumber(username)) {
+        if (!RegexValidateUtil.checkMobileNumber(username)) {
             throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "请输入正确的手机号");
         }
         User bean = findByName(username);
@@ -171,7 +174,6 @@ public class UserFacade extends UserServiceImpl {
     }
 
 
-
     /**
      * 校验用户(手机号)已注册
      *
@@ -180,10 +182,10 @@ public class UserFacade extends UserServiceImpl {
      */
     public Boolean verifyExistUser(UsernameVO usernameVO) {
         String username = usernameVO.getUsername();
-        if(StringUtil.isEmpty(username)) {
+        if (StringUtil.isEmpty(username)) {
             throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "请输入手机号");
         }
-        if(!RegexValidateUtil.checkMobileNumber(username)) {
+        if (!RegexValidateUtil.checkMobileNumber(username)) {
             throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "请输入正确的手机号");
         }
         User bean = findByName(username);
@@ -341,7 +343,7 @@ public class UserFacade extends UserServiceImpl {
      * 修改朗通后台个人信息
      */
     public void updatePersonInfo(PersonVO personVO) {
-        if(!RegexValidateUtil.checkMobileNumber(personVO.getPhone())) {
+        if (!RegexValidateUtil.checkMobileNumber(personVO.getPhone())) {
             throw new CommonException(CommonErrorCode.SERVER_IS_ERROR,
                     "请输入正确的手机号");
         }
@@ -393,6 +395,11 @@ public class UserFacade extends UserServiceImpl {
         data.setRefreshToken(jwt.getRefresh_token());
         data.setType(user.getType());
         data.setTypeCn(ConstantEnum.getName(user.getType()));//返回中文
+        //token存入redis
+        JwtStore jwtStore = new JwtStore();
+        jwtStore.setAccessToken(jwt.getAccess_token());
+        jwtStore.setRefreshToken(jwt.getRefresh_token());
+        tokenFacade.createToken(jwtStore);
         return data;
     }
 
@@ -409,12 +416,22 @@ public class UserFacade extends UserServiceImpl {
                     "刷新令牌不能为空");
         }
 
+        //验证刷新令牌有效性
+        if (!tokenFacade.verifyToken(refreshToken, 2)) {
+            throw new CommonException(CommonErrorCode.TOKEN_PAST);
+        }
+
         JWT jwt = authServiceClient.refreshToken("Basic dWFhLXNlcnZpY2U6MTIzNDU2", "refresh_token", refreshToken);
         if (null == jwt) {
             throw new CommonException(ServiceErrorCode.GET_TOKEN_FAIL);
         }
         data.setAccessToken(jwt.getAccess_token());
         data.setRefreshToken(jwt.getRefresh_token());
+        //token存入redis
+        JwtStore jwtStore = new JwtStore();
+        jwtStore.setAccessToken(jwt.getAccess_token());
+        jwtStore.setRefreshToken(jwt.getRefresh_token());
+        tokenFacade.createToken(jwtStore);
         return data;
     }
 
@@ -543,7 +560,7 @@ public class UserFacade extends UserServiceImpl {
     /**
      * 修改密码
      *
-     * @param password     原密码
+     * @param password       原密码
      * @param modifyPassword 新密码
      * @return 修改密码是否成功
      */
@@ -556,7 +573,7 @@ public class UserFacade extends UserServiceImpl {
             throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
                     "请输入新密码");
         }
-        if(password.equals(modifyPassword)) {
+        if (password.equals(modifyPassword)) {
             throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
                     "原密码和新密码不能相同");
         }
@@ -687,16 +704,15 @@ public class UserFacade extends UserServiceImpl {
 
     /**
      * @param userExportVO
-     * @return
      * @return 导出Excel文件
      */
-    public  void export(UserExportVO userExportVO,HttpServletResponse response) {
+    public void export(UserExportVO userExportVO, HttpServletResponse response) {
         Map<String, Object> userMap = new HashMap<String, Object>();
         userMap.put("startTime", userExportVO.getStartTime());
         userMap.put("endTime", userExportVO.getEndTime());
-        userMap.put("authStatus",userExportVO.getAuthStatus());
-        userMap.put("orgName",userExportVO.getOrgName());
-        userMap.put("userName",userExportVO.getUserName());
+        userMap.put("authStatus", userExportVO.getAuthStatus());
+        userMap.put("orgName", userExportVO.getOrgName());
+        userMap.put("userName", userExportVO.getUserName());
         List<UserInfoDTO> datas = dependentuserInfoByTime(userMap);
         GsonUtil.toJson(datas);
         List<String> listName = new ArrayList<>();
@@ -761,7 +777,7 @@ public class UserFacade extends UserServiceImpl {
         RespDTO resul = ex.exportExcel("测试POI导出EXCEL文档", listName, listId, list, filePath, fileName);*/
         response.setContentType("text/html;charset=UTF-8");
         ExportBeanExcelUtil ex = new ExportBeanExcelUtil();
-        ex.exportExcelNew("用户信息详情", listName, listId, list,response);
+        ex.exportExcelNew("用户信息详情", listName, listId, list, response);
     }
 
     /**
@@ -791,27 +807,27 @@ public class UserFacade extends UserServiceImpl {
      * @param userInfoAuditVO
      * @return 审核用户信息和机构信息
      */
-    public RespDTO<Boolean> auditUserInfoAlls(UserInfoAuditVO userInfoAuditVO,int ByType) {
+    public RespDTO<Boolean> auditUserInfoAlls(UserInfoAuditVO userInfoAuditVO, int ByType) {
         Map<String, Object> auditMap = new HashMap<String, Object>();
         auditMap.put("orderNum", userInfoAuditVO.getOrderNum());
         auditMap.put("userId", userInfoAuditVO.getUserId());
         auditMap.put("modifier", UserUtils.getCurrentPrincipleID());
         auditMap.put("gmtModified", DateUtil.now());
         auditMap.put("certificationDate", DateUtil.now());
-        if(ByType == 1){
-           auditMap.put("isReject", RejectEnum.PASS.getKey());
+        if (ByType == 1) {
+            auditMap.put("isReject", RejectEnum.PASS.getKey());
         }
-        if(ByType == 2){
+        if (ByType == 2) {
             auditMap.put("isReject", RejectEnum.NO_PASS.getKey());
-         }
+        }
         auditMap.put("rejectComment", userInfoAuditVO.getRejectComment());
         auditMap.put("rejectType", userInfoAuditVO.getRejectType());
-        auditMap.put("status",AuthHandleEnum.Handled.getKey());//已处理
-        if(ByType == 1){
-        	auditMap.put("authStatus", 1);
+        auditMap.put("status", AuthHandleEnum.Handled.getKey());//已处理
+        if (ByType == 1) {
+            auditMap.put("authStatus", 1);
         }
-        if(ByType == 2){
-        	auditMap.put("authStatus", 0);
+        if (ByType == 2) {
+            auditMap.put("authStatus", 0);
         }
         // TODO 审核前先验证该用户的的认证状态
         boolean res = auditUserInfoAll(auditMap);
@@ -823,6 +839,7 @@ public class UserFacade extends UserServiceImpl {
 
     /**
      * 添加机构信息
+     *
      * @param organizationVO
      * @return
      */
@@ -853,6 +870,7 @@ public class UserFacade extends UserServiceImpl {
 
     /**
      * 添加用户信息和机构信息管理员
+     *
      * @param userAndOrganizationVO
      * @return
      */
@@ -980,69 +998,75 @@ public class UserFacade extends UserServiceImpl {
         user.setRecords(userData);
         return RespDTO.onSuc(user);
     }*/
+
     /**
      * 1.分页查询注册用户信息接口 queryUserInformation
+     *
      * @param page
      * @param userName
      * @param authStatus
      * @return
      */
-    public RespDTO<IPage<UserAllDTO>> queryUserInformations(Page page, String userName, Integer authStatus,String startTime,String endTime){
-    	CustomerDTO userInfo = new CustomerDTO();
-    	if(userName != null && userName.length() != 0){
-    		userInfo.setUserName(userName);
-    	}
-        if(authStatus!=null){
+    public RespDTO<IPage<UserAllDTO>> queryUserInformations(Page page, String userName, Integer authStatus, String startTime, String endTime) {
+        CustomerDTO userInfo = new CustomerDTO();
+        if (userName != null && userName.length() != 0) {
+            userInfo.setUserName(userName);
+        }
+        if (authStatus != null) {
             userInfo.setAuthStatus(authStatus);
         }
-        if(startTime != null && startTime.length() != 0){
-    	   userInfo.setStartTime(startTime);
+        if (startTime != null && startTime.length() != 0) {
+            userInfo.setStartTime(startTime);
         }
-        if(endTime != null && endTime.length() != 0){
-        	userInfo.setEndTime(endTime);
+        if (endTime != null && endTime.length() != 0) {
+            userInfo.setEndTime(endTime);
         }
 
-    	return RespDTO.onSuc(queryUserInformation(page, userInfo));
+        return RespDTO.onSuc(queryUserInformation(page, userInfo));
     }
+
     /**
      * 2.分页查询机构信息接口 queryMechanismInformation
+     *
      * @param page
      * @param orgName
      * @return
      */
-    public RespDTO<IPage<OrganizationDTO>> queryMechanismInformations(Page page, String orgName,String startTime,String endTime){
-    	CustomerDTO userInfo = new CustomerDTO();
-    	if(orgName != null && orgName.length() != 0){
-    		userInfo.setOrgName(orgName);
-    	}
-        if(startTime != null && startTime.length() != 0){
-    	   userInfo.setStartTime(startTime);
-        }
-        if(endTime != null && endTime.length() != 0){
-        	userInfo.setEndTime(endTime);
-        }
-    	return RespDTO.onSuc(queryMechanismInformation(page, userInfo));
+    public RespDTO<IPage<OrganizationDTO>> queryMechanismInformations(Page page, String orgName, String startTime, String endTime) {
+        CustomerDTO userInfo = new CustomerDTO();
+        if (orgName != null && orgName.length() != 0) {
+            userInfo.setOrgName(orgName);
+        }
+        if (startTime != null && startTime.length() != 0) {
+            userInfo.setStartTime(startTime);
+        }
+        if (endTime != null && endTime.length() != 0) {
+            userInfo.setEndTime(endTime);
+        }
+        return RespDTO.onSuc(queryMechanismInformation(page, userInfo));
     }
+
     /**
      * 3.分页查询已认证用户信息和机构信息及开通产品接口 queryVerifiedUserOrganizationProduct
+     *
      * @param page
      * @param orgName
      * @param userName
      * @return
      */
-    public RespDTO<IPage<UserOrgizationProductDTO>> queryVerifiedUserOrganizationProducts(Page page,String orgName,String userName,String startTime,String endTime) {
-    	CustomerDTO userInfo = new CustomerDTO();
-    	if(userName != null && userName.length() != 0){
-    		userInfo.setUserName(userName);
-    	}
-        if(orgName != null && orgName.length() != 0){
-    		userInfo.setOrgName(orgName);
-    	}
-        if(startTime != null && startTime.length() != 0){
-    	   userInfo.setStartTime(startTime);
+    public RespDTO<IPage<UserOrgizationProductDTO>> queryVerifiedUserOrganizationProducts(Page page, String orgName, String userName, String startTime, String endTime) {
+        CustomerDTO userInfo = new CustomerDTO();
+        if (userName != null && userName.length() != 0) {
+            userInfo.setUserName(userName);
+        }
+        if (orgName != null && orgName.length() != 0) {
+            userInfo.setOrgName(orgName);
+        }
+        if (startTime != null && startTime.length() != 0) {
+            userInfo.setStartTime(startTime);
         }
-        if(endTime != null && endTime.length() != 0){
-        	userInfo.setEndTime(endTime);
+        if (endTime != null && endTime.length() != 0) {
+            userInfo.setEndTime(endTime);
         }
 
         IPage<UserOrgizationProductDTO> user = queryVerifiedUserOrganizationProduct(page, userInfo);
@@ -1052,57 +1076,59 @@ public class UserFacade extends UserServiceImpl {
             Long userInfoId = userInfoDTO.getUserId();
             userIds.add(userInfoId);
         }
-        if(userIds.size()>0){
+        if (userIds.size() > 0) {
 
 
-        RespDTO<List<UserAndProdutDTO>> InformationData = diagbotmanClient.getInformationAvailableAll(userIds);
+            RespDTO<List<UserAndProdutDTO>> InformationData = diagbotmanClient.getInformationAvailableAll(userIds);
 
-        if (InformationData == null || !"0".equals(InformationData.code)) {
-            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR,
-                    "获取所有开通信息失败");
-        }
-        Map<Long, List<UserAndProdutDTO>> map = new HashMap<>();
-        //获取所有用户开通的产品信息
-        List<UserAndProdutDTO> dataList = InformationData.data;
-        map = EntityUtil.makeEntityListMap(dataList, "userId");
-        if (map.size() > 0) {
-            for (UserOrgizationProductDTO userInfoDTO : userData) {
-                List<UserAndProdutDTO> userAndProdutUDTO = map.get(userInfoDTO.getUserId());
-                if (ListUtil.isNotEmpty(userAndProdutUDTO)) {
-                    userInfoDTO.setUserAndProdutUDTO(userAndProdutUDTO);
+            if (InformationData == null || !"0".equals(InformationData.code)) {
+                throw new CommonException(CommonErrorCode.SERVER_IS_ERROR,
+                        "获取所有开通信息失败");
+            }
+            Map<Long, List<UserAndProdutDTO>> map = new HashMap<>();
+            //获取所有用户开通的产品信息
+            List<UserAndProdutDTO> dataList = InformationData.data;
+            map = EntityUtil.makeEntityListMap(dataList, "userId");
+            if (map.size() > 0) {
+                for (UserOrgizationProductDTO userInfoDTO : userData) {
+                    List<UserAndProdutDTO> userAndProdutUDTO = map.get(userInfoDTO.getUserId());
+                    if (ListUtil.isNotEmpty(userAndProdutUDTO)) {
+                        userInfoDTO.setUserAndProdutUDTO(userAndProdutUDTO);
+                    }
                 }
             }
         }
-        }
         //System.out.println("====================" + GsonUtil.toJson(userData));
         user.setRecords(userData);
         return RespDTO.onSuc(user);
-  	}
+    }
+
     /**
-     *  4.分页查询认证中的用户信息接口 queryAuthentication
+     * 4.分页查询认证中的用户信息接口 queryAuthentication
+     *
      * @param page
      * @param orgName
      * @param userName
      * @return
      */
-    public RespDTO<IPage<AuthenticationDTO>> queryAuthentications(Page page,String orgName,String userName,String startTime,String endTime) {
-    	CustomerDTO userInfo = new CustomerDTO();
-    	if(userName != null && userName.length() != 0){
-    		userInfo.setUserName(userName);
-    	}
-        if(orgName != null && orgName.length() != 0){
-    		userInfo.setOrgName(orgName);
-    	}
-        if(startTime != null && startTime.length() != 0){
-    	   userInfo.setStartTime(startTime);
-        }
-        if(endTime != null && endTime.length() != 0){
-        	userInfo.setEndTime(endTime);
+    public RespDTO<IPage<AuthenticationDTO>> queryAuthentications(Page page, String orgName, String userName, String startTime, String endTime) {
+        CustomerDTO userInfo = new CustomerDTO();
+        if (userName != null && userName.length() != 0) {
+            userInfo.setUserName(userName);
+        }
+        if (orgName != null && orgName.length() != 0) {
+            userInfo.setOrgName(orgName);
+        }
+        if (startTime != null && startTime.length() != 0) {
+            userInfo.setStartTime(startTime);
+        }
+        if (endTime != null && endTime.length() != 0) {
+            userInfo.setEndTime(endTime);
         }
         userInfo.setAuthStatus(2);//认证中。。。
         userInfo.setStatus(0);//待处理
-		return RespDTO.onSuc(queryAuthentication(page, userInfo));
-	}
+        return RespDTO.onSuc(queryAuthentication(page, userInfo));
+    }
 
     /**
      * 导出用户信息
@@ -1144,7 +1170,7 @@ public class UserFacade extends UserServiceImpl {
         List<ExportUserInfoDTO> list = new ArrayList<>();
         for (int i = 0; i < datas.size(); i++) {
             UserInfoDTO userInfo = datas.get(i);
-            list.add(new ExportUserInfoDTO(String.valueOf(i+1),
+            list.add(new ExportUserInfoDTO(String.valueOf(i + 1),
                     DateUtil.formatDateTime(userInfo.getUserGmtCreate()),
                     userInfo.getLinkman(),
                     AuthStatusEnum.getName(userInfo.getAuthStatus()),
@@ -1194,7 +1220,7 @@ public class UserFacade extends UserServiceImpl {
         for (int i = 0; i < datas.size(); i++) {
             UserInfoDTO userInfo = datas.get(i);
             list.add(new ExportOrganizationDTO(
-                    String.valueOf(i+1),
+                    String.valueOf(i + 1),
                     DateUtil.formatDateTime(userInfo.getOrgGmtCreate()),
                     userInfo.getOrgName(),
                     userInfo.getOrgPrincipal(),
@@ -1244,8 +1270,8 @@ public class UserFacade extends UserServiceImpl {
 
         List<ExportKemaDTO> list = new ArrayList<>();
         for (int i = 0; i < datas.size(); i++) {
-        	AuthenticationDTO userInfo = datas.get(i);
-            list.add(new ExportKemaDTO(String.valueOf(i+1),
+            AuthenticationDTO userInfo = datas.get(i);
+            list.add(new ExportKemaDTO(String.valueOf(i + 1),
                     DateUtil.formatDateTime(userInfo.getAutGmtCreate()),
                     userInfo.getOrderNum(),
                     userInfo.getLinkman(),
@@ -1297,7 +1323,7 @@ public class UserFacade extends UserServiceImpl {
         List<ExportVerifiedDTO> list = new ArrayList<>();
         for (int i = 0; i < datas.size(); i++) {
             UserInfoDTO userInfo = datas.get(i);
-            list.add(new ExportVerifiedDTO(String.valueOf(i+1),
+            list.add(new ExportVerifiedDTO(String.valueOf(i + 1),
                     DateUtil.formatDateTime(userInfo.getUserGmtCreate()),
                     DateUtil.formatDateTime(userInfo.getPassauthTime()),
                     userInfo.getLinkman(),
@@ -1345,7 +1371,7 @@ public class UserFacade extends UserServiceImpl {
         return RespDTO.onSuc(res);
     }
 
-    public RespDTO<User> getUserAuthStatus(Long userId){
+    public RespDTO<User> getUserAuthStatus(Long userId) {
         return RespDTO.onSuc(this.getById(userId));
     }
 

+ 29 - 0
user-service/src/main/java/com/diagbot/service/TokenService.java

@@ -0,0 +1,29 @@
+package com.diagbot.service;
+
+import com.diagbot.entity.JwtStore;
+
+/**
+ * @Description: Token验证类
+ * @author: gaodm
+ * @time: 2018/10/29 13:35
+ */
+public interface TokenService {
+
+    /**
+     * 创建token
+     *
+     * @param token 用户token
+     * @return
+     */
+    Boolean createToken(JwtStore token);
+
+    /**
+     * 验证token是否有效
+     *
+     * @param token 待验证的token
+     * @param type  1:accessToken,2:refreshToken
+     * @return
+     */
+    Boolean verifyToken(String token, Integer type);
+
+}

+ 128 - 0
user-service/src/main/java/com/diagbot/service/impl/TokenServiceImpl.java

@@ -0,0 +1,128 @@
+package com.diagbot.service.impl;
+
+import com.auth0.jwt.interfaces.Claim;
+import com.auth0.jwt.interfaces.DecodedJWT;
+import com.diagbot.entity.JwtStore;
+import com.diagbot.service.TokenService;
+import com.diagbot.util.DateUtil;
+import com.diagbot.util.JwtUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.dao.DataAccessException;
+import org.springframework.data.redis.connection.RedisConnection;
+import org.springframework.data.redis.core.RedisCallback;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.stereotype.Service;
+
+import java.util.Date;
+import java.util.Map;
+
+/**
+ * @Description: Token验证类 实现
+ * @author: gaodm
+ * @time: 2018/10/29 13:34
+ */
+@Slf4j
+@Service
+public class TokenServiceImpl implements TokenService {
+
+    @Autowired
+    @Qualifier("redisTemplateForToken")
+    RedisTemplate redisForToken;
+
+    private byte[] serializeKey(Object o) {
+        return redisForToken.getKeySerializer().serialize(o);
+    }
+
+    private byte[] serializeValue(Object o) {
+        return redisForToken.getValueSerializer().serialize(o);
+    }
+
+    private Object deserializeValue(byte[] b) {
+        return redisForToken.getValueSerializer().deserialize(b);
+    }
+
+    private byte[] getUserTokenKey(String userId) {
+        String userTokensFormat = "user_tokens_%s";
+        return serializeKey(String.format(userTokensFormat, userId));
+    }
+
+    /**
+     * 创建token
+     *
+     * @param token 用户token
+     * @return
+     */
+    @Override
+    public Boolean createToken(JwtStore token) {
+        DecodedJWT jwt = JwtUtil.decodedJWT(token.getRefreshToken());
+        Map<String, Claim> claims = jwt.getClaims();
+        String userId = claims.get("user_id").asInt().toString();
+        Date expDate = claims.get("exp").asDate();
+        final byte[] redis_key = getUserTokenKey(userId);
+        redisForToken.execute(new RedisCallback<Object>() {
+            @Override
+            public Object doInRedis(RedisConnection connection) throws DataAccessException {
+                //获取旧的
+                byte[] bytes = connection.get(redis_key);
+                //删除旧的
+                if (bytes != null) {
+                    connection.del(bytes);
+                }
+                //设置新的
+                connection.setEx(
+                        redis_key,
+                        (expDate.getTime() - DateUtil.now().getTime()) / 1000,
+                        serializeValue(token)
+                );
+                return true;
+            }
+        });
+        return true;
+    }
+
+    /**
+     * 验证token是否有效
+     *
+     * @param token 待验证的token
+     * @param type  1:accessToken,2:refreshToken
+     * @return
+     */
+    @Override
+    public Boolean verifyToken(String token, Integer type) {
+        Boolean res = false;
+        if (null == token) {
+            return false;
+        }
+        String userId = JwtUtil.getUserId(token);
+        //从redis中取出
+        final byte[] redis_key = getUserTokenKey(userId);
+        JwtStore tokenStore = (JwtStore) redisForToken.execute(new RedisCallback<JwtStore>() {
+            @Override
+            public JwtStore doInRedis(RedisConnection connection) throws DataAccessException {
+                byte[] bytes = connection.get(redis_key);
+                if (bytes == null) {
+                    return null;
+                }
+                return (JwtStore) deserializeValue(bytes);
+            }
+        });
+
+        if (null != tokenStore){
+            if (type == 1){
+                if (null != tokenStore.getAccessToken() && tokenStore.getAccessToken().equals(token)) {
+                    res = true;
+                }
+            }
+
+            if (type == 2){
+                if (null != tokenStore.getRefreshToken() && tokenStore.getRefreshToken().equals(token)) {
+                    res = true;
+                }
+            }
+        }
+
+        return res;
+    }
+}

+ 17 - 0
user-service/src/main/java/com/diagbot/web/UserController.java

@@ -9,8 +9,10 @@ import com.diagbot.dto.RespDTO;
 import com.diagbot.dto.UserLoginDTO;
 import com.diagbot.dto.UserOrgDTO;
 import com.diagbot.entity.Permission;
+import com.diagbot.entity.Token;
 import com.diagbot.entity.User;
 import com.diagbot.facade.PermissionFacade;
+import com.diagbot.facade.TokenFacade;
 import com.diagbot.facade.UserFacade;
 import com.diagbot.vo.AppkeySecretVO;
 import com.diagbot.vo.BaseIdVO;
@@ -52,6 +54,8 @@ public class UserController {
     @Autowired
     private UserFacade userFacade;
     @Autowired
+    private TokenFacade tokenFacade;
+    @Autowired
     private PermissionFacade permissionFacade;
 
 
@@ -72,6 +76,19 @@ public class UserController {
     }
 
 
+
+    @ApiOperation(value = "验证token有效性[by:zhoutg]",
+            notes = "token:token信息,必填<br>")
+    @PostMapping("/verifyToken")
+    @SysLogger("verifyToken")
+    @ApiIgnore
+    public RespDTO<Boolean> verifyToken(@RequestBody Token token) {
+        Boolean data = tokenFacade.verifyToken(token.getToken(), 1);
+        return RespDTO.onSuc(data);
+    }
+
+
+
     @ApiOperation(value = "校验用户(手机号)已注册[by:zhoutg]",
             notes = "username:用户名(手机号),必填<br>")
     @PostMapping("/verifyExistUsername")