Pārlūkot izejas kodu

增加登陆校验

lilt085163@126.com 3 gadi atpakaļ
vecāks
revīzija
2358fb0b20
24 mainītis faili ar 1642 papildinājumiem un 11 dzēšanām
  1. 17 2
      pom.xml
  2. 2 0
      src/main/java/com/care/CareSpringStart.java
  3. 81 0
      src/main/java/com/care/app/bms/controller/LoginController.java
  4. 25 0
      src/main/java/com/care/app/bms/params/UserLoginParams.java
  5. 10 7
      src/main/java/com/care/bigscreen/controller/CommonController.java
  6. 28 0
      src/main/java/com/care/common/annotation/LogModule.java
  7. 20 0
      src/main/java/com/care/common/annotation/LoginedUser.java
  8. 28 0
      src/main/java/com/care/common/annotation/Permission.java
  9. 29 0
      src/main/java/com/care/common/cache/RedisKeyConstant.java
  10. 549 0
      src/main/java/com/care/common/cache/RedisUtil.java
  11. 19 0
      src/main/java/com/care/common/constant/Constants.java
  12. 59 0
      src/main/java/com/care/common/vo/UserLogindConvertVO.java
  13. 78 0
      src/main/java/com/care/common/vo/sysuser/CareSysUserVO.java
  14. 75 0
      src/main/java/com/care/interceptor/AuthorizationInterceptor.java
  15. 45 0
      src/main/java/com/care/interceptor/AuthorizationInterceptorConf.java
  16. 310 0
      src/main/java/com/care/interceptor/ControllerInterceptor.java
  17. 2 1
      src/main/java/com/care/service/CareSysUserService.java
  18. 38 0
      src/main/java/com/care/service/impl/CareSysUserServiceImpl.java
  19. 0 1
      src/main/java/com/care/util/JsonUtil.java
  20. 84 0
      src/main/java/com/care/util/JwtUtils.java
  21. 4 0
      src/main/java/com/care/util/ResultCode.java
  22. 124 0
      src/main/java/com/care/util/WebPageUtils.java
  23. 8 0
      src/main/resources/application.properties
  24. 7 0
      src/main/resources/common.properties

+ 17 - 2
pom.xml

@@ -31,6 +31,7 @@
         <admin.version>2.2.2</admin.version>
         <io.springfox.version>2.5.0</io.springfox.version>
         <easyexcel.version>2.2.8</easyexcel.version>
+        <jwt.version>0.9.0</jwt.version>
     </properties>
 
     <!--环境依赖-->
@@ -48,6 +49,14 @@
             <artifactId>spring-boot-starter-web</artifactId>
             <version>${spring-web.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-aop</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-websocket</artifactId>
+        </dependency>
         <!--junit5 单元测试-->
         <dependency>
             <groupId>org.springframework.boot</groupId>
@@ -194,6 +203,11 @@
 		    <artifactId>itext-asian</artifactId>
 		    <version>5.2.0</version>
 		</dependency>
+        <dependency>
+            <groupId>io.jsonwebtoken</groupId>
+            <artifactId>jjwt</artifactId>
+            <version>${jwt.version}</version>
+        </dependency>
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-test</artifactId>
@@ -204,7 +218,7 @@
             <version>1.3.5</version>
         </dependency>
         <!-- 引入redis及相关组件 -->
-        <!--<dependency>
+        <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-data-redis</artifactId>
             <exclusions>
@@ -218,8 +232,9 @@
             <groupId>redis.clients</groupId>
             <artifactId>jedis</artifactId>
             <version>3.3.0</version>
-        </dependency>-->
+        </dependency>
          <!-- 引入redis及相关组件 结束 -->
+
     </dependencies>
 
     <build>

+ 2 - 0
src/main/java/com/care/CareSpringStart.java

@@ -20,9 +20,11 @@ public class CareSpringStart {
     public static void main(String[] args) {
         SpringApplication.run(CareSpringStart.class, args);
     }
+
     @Bean
     RestTemplate createTemplate(){
         return new RestTemplate();
     }
+
 }
 

+ 81 - 0
src/main/java/com/care/app/bms/controller/LoginController.java

@@ -0,0 +1,81 @@
+package com.care.app.bms.controller;
+
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.json.JSONUtil;
+import com.care.app.bms.params.UserLoginParams;
+import com.care.common.constant.Constants;
+import com.care.common.entity.CareSysUser;
+import com.care.common.exception.BDException;
+import com.care.common.vo.UserLogindConvertVO;
+import com.care.service.CareSysUserService;
+import com.care.util.JwtUtils;
+import com.care.util.Result;
+import com.care.util.ResultCode;
+import io.jsonwebtoken.Claims;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.codec.digest.DigestUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Created by y on 2017/10/20.
+ * @author y
+ */
+@RestController
+@Api(value = "LoginController", tags = { "登录相关接口" })
+@Slf4j
+@RequestMapping("/bms")
+public class LoginController {
+
+    @Autowired
+    CareSysUserService careSysUserService;
+
+    @Autowired
+    JwtUtils jwtUtils;
+
+    @PostMapping(value = "/login", produces = MediaType.APPLICATION_JSON_VALUE)
+    @ApiOperation(value = "登陆", notes = "登陆")
+    public Result<Object> login(HttpServletRequest request, @RequestBody UserLoginParams userLoginParams) {
+        try {
+            //验证用户名密码
+            UserLogindConvertVO loginUser = careSysUserService.getLoginUser(userLoginParams.getOrgCode(),userLoginParams.getPhone(),userLoginParams.getPassword());
+            if (loginUser == null) {
+                return Result.error("未找到相关用户");
+            }
+
+            Map<String,Object> dataMap = new HashMap<>(2);
+            dataMap.put("token",jwtUtils.generalToken(loginUser));
+            dataMap.put("user",loginUser);
+            return Result.success("登陆成功",dataMap);
+
+        }catch (BDException ex) {
+            return Result.error(ex.getMessage());
+        } catch (Exception ex) {
+            return new Result(ResultCode.NO_LOGINED,"登陆失败",ex.getMessage());
+        }
+    }
+
+    @GetMapping(value = "/parseToken", produces = MediaType.APPLICATION_JSON_VALUE)
+    @ApiOperation(value = "解析token", notes = "解析token")
+    public Result<Object> tokenParse(HttpServletRequest request) {
+
+        String commonJwt = request.getHeader(Constants.LOGIN_TOKEN_KEY);
+        Claims claims = jwtUtils.tokenParse(commonJwt);
+        if (claims != null) {
+            UserLogindConvertVO vo = JSONUtil.toBean(claims.getSubject(), UserLogindConvertVO.class);
+            if (vo != null) {
+               return Result.success("解析成功",vo);
+            }else{
+                return Result.error("解析失败");
+            }
+        }
+        return Result.error("解析失败");
+    }
+}

+ 25 - 0
src/main/java/com/care/app/bms/params/UserLoginParams.java

@@ -0,0 +1,25 @@
+package com.care.app.bms.params;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class UserLoginParams {
+
+    private String orgCode;
+
+    /**
+     * 用户名
+     */
+    @ApiModelProperty("用户名")
+    private String phone;
+
+    /**
+     * 密码
+     */
+    @ApiModelProperty("密码")
+    private String password;
+
+}

+ 10 - 7
src/main/java/com/care/bigscreen/controller/CommonController.java

@@ -1,13 +1,15 @@
 package com.care.bigscreen.controller;
 
+import com.care.common.annotation.Permission;
+import com.care.common.vo.UserLogindConvertVO;
 import com.care.service.CommonService;
 import com.care.util.Result;
+import com.care.util.WebPageUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
 
 
 /**
@@ -31,10 +33,11 @@ public class CommonController {
      * @return 返回0表示字段没有重复,非零表示有重复
      */
     @GetMapping("/convertedCodeName")
-    public Result<Object> convertedCodeName(@RequestParam("typeCode") String typeCode,@RequestParam("value") String value) {
+    @Permission
+    public Result<Object> convertedCodeName(@RequestHeader("token") String token, @RequestParam("typeCode") String typeCode, @RequestParam("value") String value, HttpServletRequest request) {
         try {
-            String name = commonService.convertedCodeName(typeCode,value);
-                return Result.success("成功",name);
+            UserLogindConvertVO user = WebPageUtils.getCurrentLoginedUser(request);
+                return Result.success("成功",user);
         } catch (Exception e) {
             return Result.error("系统错误,查询失败");
         }

+ 28 - 0
src/main/java/com/care/common/annotation/LogModule.java

@@ -0,0 +1,28 @@
+package com.care.common.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * 日志 -> 功能模块名称定义
+ * Created by y on 2017/11/16.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.METHOD, ElementType.TYPE})
+public @interface LogModule {
+
+    /**
+     * 主模块名称
+     * @return
+     */
+    String masterModule() default "";
+
+    /**
+     * 子模块名称
+     * @return
+     */
+    String childModule() default "";
+
+}

+ 20 - 0
src/main/java/com/care/common/annotation/LoginedUser.java

@@ -0,0 +1,20 @@
+package com.care.common.annotation;
+
+import springfox.documentation.annotations.ApiIgnore;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * 描述: 注入当前访问用户
+ *
+ * @author y
+ * @create 2018-10-18 14:10
+ */
+@Target(ElementType.PARAMETER)
+@Retention(RetentionPolicy.RUNTIME)
+@ApiIgnore
+public @interface LoginedUser {
+}

+ 28 - 0
src/main/java/com/care/common/annotation/Permission.java

@@ -0,0 +1,28 @@
+package com.care.common.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * 权限控制
+ * Created by y on 2017/11/16.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.METHOD, ElementType.TYPE})
+public @interface Permission {
+
+    /**
+     * 是否需要登录,缺省为需要
+     * @return
+     */
+    boolean loginReqired() default true;
+
+    /**
+     * 需要的权限,缺省值为不需要任何权限
+     * @return
+     */
+    //Privilege privilege() default Privilege.ANY;
+
+}

+ 29 - 0
src/main/java/com/care/common/cache/RedisKeyConstant.java

@@ -0,0 +1,29 @@
+package com.care.common.cache;
+
+import lombok.Data;
+
+/**
+ * 描述:
+ *
+ * @autho:wenskys
+ * @create 2020/5/11 0:55
+ **/
+@Data
+public class RedisKeyConstant {
+
+    // 微信access_token 2h
+    public static final String WX_ACCESS_TOKEN = "WX:TOKEN";
+    public static final int WX_ACCESS_TOKEN_TIME = (3600 - 2) * 2;
+
+    // 会员登录信息 2days
+    public static final String LOGIN_INFO = "LOGIN";
+    public static final int LOGIN_INFO_TIME = 3600 * 24 * 2;
+
+    // 后台登录信息 2days
+    public static final String BACK_LOGIN_INFO = "BACK:LOGIN";
+    public static final int BACK_LOGIN_INFO_TIME = 3600 * 24 * 2;
+
+    // 绑定手机号短信验证码 5min
+    public static final String V_CODE_BIND_MSG = "V_CODE:MSG";
+    public static final int V_CODE_BIND_MSG_TIME = 60 * 5;
+}

+ 549 - 0
src/main/java/com/care/common/cache/RedisUtil.java

@@ -0,0 +1,549 @@
+package com.care.common.cache;
+
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.util.CollectionUtils;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * redis工具
+ */
+public class RedisUtil {
+
+    private RedisTemplate<String, Object> redisTemplate;
+
+    public void setRedisTemplate(RedisTemplate<String, Object> redisTemplate) {
+        this.redisTemplate = redisTemplate;  
+    }
+
+    //=============================common============================  
+    /** 
+     * 指定缓存失效时间 
+     * @param key 键 
+     * @param time 时间(秒) 
+     * @return 
+     */  
+    public boolean expire(String key,long time){  
+        try {  
+            if(time>0){  
+                redisTemplate.expire(key, time, TimeUnit.SECONDS);
+            }  
+            return true;  
+        } catch (Exception e) {  
+            e.printStackTrace();  
+            return false;  
+        }  
+    }  
+
+    /** 
+     * 根据key 获取过期时间 
+     * @param key 键 不能为null 
+     * @return 时间(秒) 返回0代表为永久有效 
+     */  
+    public long getExpire(String key){  
+        return redisTemplate.getExpire(key,TimeUnit.SECONDS);  
+    }  
+
+    /** 
+     * 判断key是否存在 
+     * @param key 键 
+     * @return true 存在 false不存在 
+     */  
+    public boolean hasKey(String key){  
+        try {  
+            return redisTemplate.hasKey(key);  
+        } catch (Exception e) {  
+            e.printStackTrace();  
+            return false;  
+        }  
+    }  
+
+    /** 
+     * 删除缓存 
+     * @param key 可以传一个值 或多个 
+     */  
+    @SuppressWarnings("unchecked")  
+    public void del(String ... key){  
+        if(key!=null&&key.length>0){  
+            if(key.length==1){  
+                redisTemplate.delete(key[0]);  
+            }else{  
+                redisTemplate.delete(CollectionUtils.arrayToList(key));
+            }  
+        }  
+    }  
+
+    //============================String=============================  
+    /** 
+     * 普通缓存获取 
+     * @param key 键 
+     * @return 值 
+     */  
+    public Object get(String key){  
+        return key==null?null:redisTemplate.opsForValue().get(key);  
+    }
+    /**
+     * 普通缓存获取并刷新过期时间
+     * @param key 键
+     * @return 值
+     */
+    public Object getAndRefresh(String key,Long seconds){
+
+        Object object = key==null?null:redisTemplate.opsForValue().get(key);
+        try {
+            redisTemplate.opsForValue().set(key, object,seconds,TimeUnit.SECONDS);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return object;
+    }
+
+    /** 
+     * 普通缓存放入 
+     * @param key 键 
+     * @param value 值 
+     * @return true成功 false失败 
+     */  
+    public boolean set(String key,Object value) {  
+        try {
+            redisTemplate.opsForValue().set(key, value);  
+            return true;  
+        } catch (Exception e) {  
+            e.printStackTrace();  
+            return false;  
+        }  
+
+    }  
+
+    /** 
+     * 普通缓存放入并设置时间 
+     * @param key 键 
+     * @param value 值 
+     * @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期 
+     * @return true成功 false 失败 
+     */  
+    public boolean set(String key,Object value,long time){  
+        try {  
+            if(time>0){  
+                redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);  
+            }else{  
+                set(key, value);  
+            }  
+            return true;  
+        } catch (Exception e) {  
+            e.printStackTrace();  
+            return false;  
+        }  
+    }  
+
+    /** 
+     * 递增 
+     * @param key 键 
+     * @param delta 要增加几(大于0)
+     * @return 
+     */  
+    public long incr(String key, long delta){    
+        if(delta<0){  
+            throw new RuntimeException("递增因子必须大于0");  
+        }  
+        return redisTemplate.opsForValue().increment(key, delta);  
+    }  
+
+    /** 
+     * 递减 
+     * @param key 键 
+     * @param delta 要减少几(小于0)
+     * @return 
+     */  
+    public long decr(String key, long delta){    
+        if(delta<0){  
+            throw new RuntimeException("递减因子必须大于0");  
+        }  
+        return redisTemplate.opsForValue().increment(key, -delta);    
+    }    
+
+    //================================Map=================================  
+    /** 
+     * HashGet 
+     * @param key 键 不能为null 
+     * @param item 项 不能为null 
+     * @return 值 
+     */  
+    public Object hget(String key,String item){  
+        return redisTemplate.opsForHash().get(key, item);  
+    }  
+
+    /** 
+     * 获取hashKey对应的所有键值 
+     * @param key 键 
+     * @return 对应的多个键值 
+     */  
+    public Map<Object,Object> hmget(String key){
+        return redisTemplate.opsForHash().entries(key);  
+    }  
+
+    /**
+     *
+     *
+     * HashSet 
+     * @param key 键 
+     * @param map 对应多个键值 
+     * @return true 成功 false 失败 
+     */  
+    public boolean hmset(String key, Map<String,Object> map){    
+        try {  
+            redisTemplate.opsForHash().putAll(key, map);  
+            return true;  
+        } catch (Exception e) {  
+            e.printStackTrace();  
+            return false;  
+        }  
+    }  
+
+    /** 
+     * HashSet 并设置时间 
+     * @param key 键 
+     * @param map 对应多个键值 
+     * @param time 时间(秒) 
+     * @return true成功 false失败 
+     */  
+    public boolean hmset(String key, Map<String,Object> map, long time){    
+        try {  
+            redisTemplate.opsForHash().putAll(key, map);  
+            if(time>0){  
+                expire(key, time);  
+            }  
+            return true;  
+        } catch (Exception e) {  
+            e.printStackTrace();  
+            return false;  
+        }  
+    }  
+
+    /** 
+     * 向一张hash表中放入数据,如果不存在将创建 
+     * @param key 键 
+     * @param item 项 
+     * @param value 值 
+     * @return true 成功 false失败 
+     */  
+    public boolean hset(String key,String item,Object value) {  
+         try {  
+            redisTemplate.opsForHash().put(key, item, value);  
+            return true;  
+        } catch (Exception e) {  
+            e.printStackTrace();  
+            return false;  
+        }  
+    }  
+
+    /** 
+     * 向一张hash表中放入数据,如果不存在将创建 
+     * @param key 键 
+     * @param item 项 
+     * @param value 值 
+     * @param time 时间(秒)  注意:如果已存在的hash表有时间,这里将会替换原有的时间 
+     * @return true 成功 false失败 
+     */  
+    public boolean hset(String key,String item,Object value,long time) {  
+         try {  
+            redisTemplate.opsForHash().put(key, item, value);  
+            if(time>0){  
+                expire(key, time);  
+            }  
+            return true;  
+        } catch (Exception e) {  
+            e.printStackTrace();  
+            return false;  
+        }  
+    }  
+
+    /** 
+     * 删除hash表中的值 
+     * @param key 键 不能为null 
+     * @param item 项 可以使多个 不能为null 
+     */  
+    public void hdel(String key, Object... item){    
+        redisTemplate.opsForHash().delete(key,item);  
+    }   
+
+    /** 
+     * 判断hash表中是否有该项的值 
+     * @param key 键 不能为null 
+     * @param item 项 不能为null 
+     * @return true 存在 false不存在 
+     */  
+    public boolean hHasKey(String key, String item){  
+        return redisTemplate.opsForHash().hasKey(key, item);  
+    }   
+
+    /** 
+     * hash递增 如果不存在,就会创建一个 并把新增后的值返回 
+     * @param key 键 
+     * @param item 项 
+     * @param by 要增加几(大于0) 
+     * @return 
+     */  
+    public double hincr(String key, String item,double by){    
+        return redisTemplate.opsForHash().increment(key, item, by);  
+    }  
+
+    /** 
+     * hash递减 
+     * @param key 键 
+     * @param item 项 
+     * @param by 要减少记(小于0) 
+     * @return 
+     */  
+    public double hdecr(String key, String item,double by){    
+        return redisTemplate.opsForHash().increment(key, item,-by);    
+    }    
+
+    //============================set=============================  
+    /** 
+     * 根据key获取Set中的所有值 
+     * @param key 键 
+     * @return 
+     */  
+    public Set<Object> sGet(String key){
+        try {  
+            return redisTemplate.opsForSet().members(key);  
+        } catch (Exception e) {  
+            e.printStackTrace();  
+            return null;  
+        }  
+    }  
+
+    /** 
+     * 根据value从一个set中查询,是否存在 
+     * @param key 键 
+     * @param value 值 
+     * @return true 存在 false不存在 
+     */  
+    public boolean sHasKey(String key,Object value){  
+        try {  
+            return redisTemplate.opsForSet().isMember(key, value);  
+        } catch (Exception e) {  
+            e.printStackTrace();  
+            return false;  
+        }  
+    }  
+
+    /** 
+     * 将数据放入set缓存 
+     * @param key 键 
+     * @param values 值 可以是多个 
+     * @return 成功个数 
+     */  
+    public long sSet(String key, Object...values) {  
+        try {  
+            return redisTemplate.opsForSet().add(key, values);  
+        } catch (Exception e) {  
+            e.printStackTrace();  
+            return 0;  
+        }  
+    }  
+
+    /** 
+     * 将set数据放入缓存 
+     * @param key 键 
+     * @param time 时间(秒) 
+     * @param values 值 可以是多个 
+     * @return 成功个数 
+     */  
+    public long sSetAndTime(String key,long time,Object...values) {  
+        try {  
+            Long count = redisTemplate.opsForSet().add(key, values);  
+            if(time>0) expire(key, time);  
+            return count;  
+        } catch (Exception e) {  
+            e.printStackTrace();  
+            return 0;  
+        }  
+    }  
+
+    /** 
+     * 获取set缓存的长度 
+     * @param key 键 
+     * @return 
+     */  
+    public long sGetSetSize(String key){  
+        try {  
+            return redisTemplate.opsForSet().size(key);  
+        } catch (Exception e) {  
+            e.printStackTrace();  
+            return 0;  
+        }  
+    }  
+
+    /** 
+     * 移除值为value的 
+     * @param key 键 
+     * @param values 值 可以是多个 
+     * @return 移除的个数 
+     */  
+    public long setRemove(String key, Object ...values) {  
+        try {  
+            Long count = redisTemplate.opsForSet().remove(key, values);  
+            return count;  
+        } catch (Exception e) {  
+            e.printStackTrace();  
+            return 0;  
+        }  
+    }  
+    //===============================list=================================  
+
+    /** 
+     * 获取list缓存的内容 
+     * @param key 键 
+     * @param start 开始 
+     * @param end 结束  0 到 -1代表所有值 
+     * @return 
+     */  
+    public List<Object> lGet(String key, long start, long end){
+        try {  
+            return redisTemplate.opsForList().range(key, start, end);  
+        } catch (Exception e) {  
+            e.printStackTrace();  
+            return null;  
+        }  
+    }  
+
+    /** 
+     * 获取list缓存的长度 
+     * @param key 键 
+     * @return 
+     */  
+    public long lGetListSize(String key){  
+        try {  
+            return redisTemplate.opsForList().size(key);  
+        } catch (Exception e) {  
+            e.printStackTrace();  
+            return 0;  
+        }  
+    }  
+
+    /** 
+     * 通过索引 获取list中的值 
+     * @param key 键 
+     * @param index 索引  index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推 
+     * @return 
+     */  
+    public Object lGetIndex(String key,long index){  
+        try {  
+            return redisTemplate.opsForList().index(key, index);  
+        } catch (Exception e) {  
+            e.printStackTrace();  
+            return null;  
+        }  
+    }  
+
+    /** 
+     * 将list放入缓存 
+     * @param key 键 
+     * @param value 值
+     * @return 
+     */  
+    public boolean lSet(String key, Object value) {  
+        try {  
+            redisTemplate.opsForList().rightPush(key, value);  
+            return true;  
+        } catch (Exception e) {  
+            e.printStackTrace();  
+            return false;  
+        }  
+    }  
+
+    /** 
+     * 将list放入缓存 
+     * @param key 键 
+     * @param value 值 
+     * @param time 时间(秒) 
+     * @return 
+     */  
+    public boolean lSet(String key, Object value, long time) {  
+        try {  
+            redisTemplate.opsForList().rightPush(key, value);  
+            if (time > 0){
+                expire(key, time);
+            }
+            return true;  
+        } catch (Exception e) {  
+            e.printStackTrace();  
+            return false;  
+        }  
+    }  
+
+    /** 
+     * 将list放入缓存 
+     * @param key 键 
+     * @param value 值
+     * @return 
+     */  
+    public boolean lSet(String key, List<Object> value) {  
+        try {  
+            redisTemplate.opsForList().rightPushAll(key, value);  
+            return true;  
+        } catch (Exception e) {  
+            e.printStackTrace();  
+            return false;  
+        }  
+    }  
+
+    /** 
+     * 将list放入缓存 
+     * @param key 键 
+     * @param value 值 
+     * @param time 时间(秒) 
+     * @return 
+     */  
+    public boolean lSet(String key, List<Object> value, long time) {  
+        try {  
+            redisTemplate.opsForList().rightPushAll(key, value);  
+            if (time > 0){
+                expire(key, time);
+            }
+            return true;  
+        } catch (Exception e) {  
+            e.printStackTrace();  
+            return false;  
+        }  
+    }  
+
+    /** 
+     * 根据索引修改list中的某条数据 
+     * @param key 键 
+     * @param index 索引 
+     * @param value 值 
+     * @return 
+     */  
+    public boolean lUpdateIndex(String key, long index,Object value) {  
+        try {  
+            redisTemplate.opsForList().set(key, index, value);  
+            return true;  
+        } catch (Exception e) {  
+            e.printStackTrace();  
+            return false;  
+        }  
+    }   
+
+    /** 
+     * 移除N个值为value  
+     * @param key 键 
+     * @param count 移除多少个 
+     * @param value 值 
+     * @return 移除的个数 
+     */  
+    public long lRemove(String key,long count,Object value) {  
+        try {  
+            Long remove = redisTemplate.opsForList().remove(key, count, value);  
+            return remove;  
+        } catch (Exception e) {  
+            e.printStackTrace();  
+            return 0;  
+        }  
+    }  
+}

+ 19 - 0
src/main/java/com/care/common/constant/Constants.java

@@ -0,0 +1,19 @@
+package com.care.common.constant;
+
+/**
+ * Created by y on 2017/11/23.
+ * @author y
+ */
+public interface Constants {
+
+    /**
+     * 储存用户登录信息KEY
+     */
+    String CURRENT_LOGINED_USER_KEY = "currentLoginedUserKey";
+
+    /**
+     * 请求中传输TOKEN键
+     */
+    String LOGIN_TOKEN_KEY = "token";
+
+}

+ 59 - 0
src/main/java/com/care/common/vo/UserLogindConvertVO.java

@@ -0,0 +1,59 @@
+package com.care.common.vo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Date;
+
+@Getter
+@Setter
+public class UserLogindConvertVO {
+
+    @TableId(value = "ID", type = IdType.AUTO)
+    private Long id;
+
+
+    @ApiModelProperty("机构ID")
+    private Long orgId;
+    @ApiModelProperty("机构名称")
+    private String orgName;
+
+
+    @ApiModelProperty("服务站ID,角色未坐席时,该字段可能未空")
+    private Long stationId;
+    @ApiModelProperty("机构名称")
+    private String stationName;
+
+    @ApiModelProperty("姓名")
+    private String name;
+
+
+    @ApiModelProperty("电话")
+    private String phone;
+
+
+    @ApiModelProperty("姓名:M:男 W:女")
+    private String gender;
+
+
+    @ApiModelProperty("状态:1正常;2:休假")
+    private String status;
+
+
+    @ApiModelProperty("经度")
+    private Double longitude;
+
+
+    @ApiModelProperty("纬度")
+    private Double latitude;
+
+    @ApiModelProperty("1:坐席 2:管家")
+    private String role;
+
+
+}

+ 78 - 0
src/main/java/com/care/common/vo/sysuser/CareSysUserVO.java

@@ -0,0 +1,78 @@
+package com.care.common.vo.sysuser;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 安全管家表(CareSysUser)实体类
+ *
+ * @author makejava
+ * @since 2021-05-21 00:08:37
+ */
+
+@Data
+public class CareSysUserVO implements Serializable {
+    private static final long serialVersionUID = -32919685706503729L;
+
+    private Long id;
+
+
+    @ApiModelProperty("机构ID")
+    private Long orgId;
+
+
+    @ApiModelProperty("服务站ID,角色未坐席时,该字段可能未空")
+    private Long stationId;
+
+
+    @ApiModelProperty("姓名")
+    private String name;
+
+
+    @ApiModelProperty("电话")
+    private String phone;
+
+
+    @ApiModelProperty("password")
+    private String password;
+
+
+    @ApiModelProperty("姓名:M:男 W:女")
+    private String gender;
+
+
+    @ApiModelProperty("状态:1正常;2:休假")
+    private String status;
+
+
+    @ApiModelProperty("经度")
+    private Double longitude;
+
+
+    @ApiModelProperty("纬度")
+    private Double latitude;
+
+
+    @ApiModelProperty("createTime")
+    private Date createTime;
+
+
+    @ApiModelProperty("modifyTime")
+    private Date modifyTime;
+
+
+    @ApiModelProperty("1:坐席 2:管家")
+    private String role;
+
+
+}

+ 75 - 0
src/main/java/com/care/interceptor/AuthorizationInterceptor.java

@@ -0,0 +1,75 @@
+package com.care.interceptor;
+
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONUtil;
+import com.care.common.constant.Constants;
+import com.care.common.vo.UserLogindConvertVO;
+import com.care.util.JwtUtils;
+import io.jsonwebtoken.Claims;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * 描述:
+ *
+ * @author y
+ * @create 2018-10-18 15:11
+ */
+@Component
+public class AuthorizationInterceptor extends HandlerInterceptorAdapter {
+
+    @Autowired
+    JwtUtils jwtUtils;
+
+    /**
+     * 解析请求
+     */
+    @Override
+    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+        /**
+         * 获取登录用户
+         */
+        Claims claims = parseToken(request);
+        if (claims != null) {
+            UserLogindConvertVO dto = JSONUtil.toBean(claims.getSubject(), UserLogindConvertVO.class);
+            if (dto != null) {
+                /**
+                 * 设置登录用户到请求 Request 中.
+                 */
+                request.setAttribute(Constants.CURRENT_LOGINED_USER_KEY, dto);
+            }
+        }
+        return super.preHandle(request, response, handler);
+    }
+
+    /**
+     * 获取登录用户
+     * @param request
+     * @return
+     */
+    private Claims parseToken(HttpServletRequest request) {
+        /**
+         * 获取Header中携带TOKEN
+         */
+        String commonJwt = request.getHeader(Constants.LOGIN_TOKEN_KEY);
+        if (StrUtil.isBlank(commonJwt)) {
+            /**
+             * 获取参数中携带TOKEN
+             */
+            commonJwt = request.getParameter(Constants.LOGIN_TOKEN_KEY);
+            if (StrUtil.isBlank(commonJwt)) {
+                return null;
+            }
+        }
+        Claims claims = jwtUtils.tokenParse(commonJwt);
+        if(claims != null){
+            return claims;
+        }
+        return null;
+    }
+
+}

+ 45 - 0
src/main/java/com/care/interceptor/AuthorizationInterceptorConf.java

@@ -0,0 +1,45 @@
+package com.care.interceptor;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+
+/**
+ * @author stw
+ * @version 1.0.0 创建于 2018/1/18
+ **/
+@Configuration
+public class AuthorizationInterceptorConf extends WebMvcConfigurerAdapter implements WebMvcConfigurer {
+
+    @Autowired
+    AuthorizationInterceptor authorizationInterceptor;
+    /**
+     * 不通过拦截器
+     */
+    private static final String[] EXCLUDE_RRI = {
+            //不拦截公共资源
+            "/webjars/**",
+            "/error",
+            "/v2/api-docs",
+            "/swagger-resources/configuration/security",
+            "/swagger-resources/configuration/ui",
+            "/swagger-resources",
+            "/swagger-ui.html",
+            "/static/**",
+
+            //不拦截登录接口
+            "/bms/login",
+
+
+    };
+
+
+    @Override
+    public void addInterceptors(InterceptorRegistry registry) {
+        registry.addInterceptor(authorizationInterceptor)
+                .addPathPatterns("/**")
+                .excludePathPatterns(EXCLUDE_RRI);
+    }
+}

+ 310 - 0
src/main/java/com/care/interceptor/ControllerInterceptor.java

@@ -0,0 +1,310 @@
+package com.care.interceptor;
+
+import cn.hutool.core.util.StrUtil;
+import com.care.common.annotation.LogModule;
+import com.care.common.annotation.LoginedUser;
+import com.care.common.annotation.Permission;
+import com.care.common.constant.Constants;
+import com.care.common.vo.UserLogindConvertVO;
+import com.care.util.JwtUtils;
+import com.care.util.Result;
+import com.care.util.ResultCode;
+import com.care.util.WebPageUtils;
+import io.swagger.annotations.ApiOperation;
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Pointcut;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.annotation.AnnotationUtils;
+import org.springframework.stereotype.Component;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Created by y on 2017/11/16.
+ * @author y
+ */
+@Component
+@Aspect
+public class ControllerInterceptor {
+
+    private static final Logger logger = LoggerFactory.getLogger(ControllerInterceptor.class);
+
+    @Autowired
+    JwtUtils jwtUtils;
+
+//    @Autowired
+//    SysLogService sysLogService;
+
+    /**
+     * 定义拦截规则:拦截com.bj106.zhyc.app.controller包下面的所有类中,有@RequestMapping注解的方法。
+     */
+    @Pointcut("execution(public * com.care..*.controller..*(..))")
+    public void controllerMethodPointcut(){}
+
+    /**
+     * 拦截器具体实现<br/>
+     * 指定拦截器规则;也可以直接把“execution(* com.bj106.zhyc.........)”写进这里
+     * @param pjp
+     * @return JsonResult(被拦截方法的执行结果,或需要登录的错误提示。)
+     */
+    @Around("controllerMethodPointcut()")
+    public Object interceptor(ProceedingJoinPoint pjp){
+
+        long beginTime = System.currentTimeMillis();
+        MethodSignature signature = (MethodSignature)pjp.getSignature();
+
+//        SysLogDO sysLogDO = new SysLogDO();
+
+        /**
+         * 获取被拦截的方法
+         */
+        Method method = signature.getMethod();
+        /**
+         * 获取被拦截的方法名
+         */
+        String methodName = method.getName();
+//        sysLogDO.setMethod(methodName);
+        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
+
+//        sysLogDO.setUrl(request.getRequestURI().toString());
+
+        /**
+         * 保存所有请求参数,用于输出到日志中
+         */
+        Set<Object> allParams = new LinkedHashSet<>();
+        Object result = null;
+        logger.debug("请求开始,方法:{}", (pjp.getTarget().getClass().getName() + "." + pjp.getSignature().getName() + "()"));
+        try {
+            String description = getControllerMethodDescription(pjp);
+            if (StrUtil.isNotBlank(description)) {
+                logger.debug("方法描述: " + description);
+//                sysLogDO.setDescription(description);
+            }
+
+            String[] moduleNames = getControllerModule(pjp);
+            if (moduleNames.length > 0) {
+//                sysLogDO.setModuleName(moduleNames[0]);
+                if (moduleNames.length == 2) {
+//                    sysLogDO.setChildModuleName(moduleNames[1]);
+                }
+            }
+
+            String ip = WebPageUtils.getIpAddr(request);
+            logger.debug("请求IP: " + ip);
+//            sysLogDO.setIp(ip);
+            UserLogindConvertVO dto = (UserLogindConvertVO)request.getAttribute(Constants.CURRENT_LOGINED_USER_KEY);
+            if (dto != null) {
+//                UserDO userDO = new UserDO();
+//                userDO.setId(dto.getId());
+//                sysLogDO.setOperUserDO(userDO);
+//                logger.debug("请求人: " + dto.getRealName());
+            } else {
+                if (isLoginRequired(pjp.getTarget().getClass(), method)) {
+                    logger.debug("请求异常: 该接口需要登录后进行操作. 请先登录", methodName, System.currentTimeMillis() - beginTime);
+                    logger.debug("请求结束,方法:{} -> 耗时:{}ms", methodName, System.currentTimeMillis() - beginTime);
+                    return new Result(ResultCode.NO_LOGINED, "该操作需要登录.",null);
+                }
+            }
+            /**
+             * 请求参数
+             */
+            Object[] args = pjp.getArgs();
+            for (Object arg : args) {
+                if (arg instanceof Map<?, ?>) {
+                    /**
+                     * 提取方法中的MAP参数,用于记录进日志中
+                     */
+                    @SuppressWarnings("unchecked")
+                    Map<String, Object> map = (Map<String, Object>)arg;
+                    allParams.add(map);
+                } else if (arg instanceof HttpServletRequest) {
+                    HttpServletRequest argRequest = (HttpServletRequest)arg;
+                    //获取query string 或 posted form data参数
+                    Map<String, String[]> paramMap = argRequest.getParameterMap();
+                    if (paramMap!=null && paramMap.size() > 0) {
+                        allParams.add(paramMap);
+                    }
+                } else if (arg instanceof HttpServletResponse) {
+                    //do nothing...
+                } else {
+                    allParams.add(arg);
+                }
+            }
+
+            if (!"true".equalsIgnoreCase(request.getParameter("interval"))) {
+//                sysLogService.saveOrUpdate(sysLogDO);
+            }
+        } catch (Exception e) {
+            logger.error("异常信息:{}", e.getMessage());
+        }
+        try {
+            if(result == null) {
+                /**
+                 * 一切正常的情况下,继续执行被拦截的方法
+                 */
+                result = pjp.proceed();
+            }
+        } catch (Throwable e) {
+            logger.error("exception: ", e);
+            result = new Result(ResultCode.UNKNOWN, StrUtil.isNotBlank(e.getMessage()) ? e.getMessage() : "请求服务器出现异常, 请稍后重试.",null);
+        }
+        if (result instanceof Result) {
+            logger.debug("请求结束,方法:{} -> 耗时:{}ms", methodName, System.currentTimeMillis() - beginTime);
+        }
+        return result;
+    }
+
+
+    /**
+     * 判断一个方法是否需要登录
+     * @param method
+     * @return
+     */
+    private boolean isLoginRequired(Class<?> clazz, Method method){
+//        if(!env.equals("prod")){ //只有生产环境才需要登录
+//            return false;
+//        }
+
+        boolean result = false;
+
+        /**
+         * 首先校验方法是否存在 登录 注解, 并根据此来进行是否需要验证拦截
+         */
+        if(method.isAnnotationPresent(Permission.class)){
+            result = method.getAnnotation(Permission.class).loginReqired();
+        }
+        /**
+         * 如方法无注解, 则根据类是否添加 登录 注解, 并根据此来进行是否需要验证拦截
+         */
+        else if (clazz.isAnnotationPresent(Permission.class)) {
+            result = clazz.getAnnotation(Permission.class).loginReqired();
+        } else {
+            Annotation[][] annotations = method.getParameterAnnotations();
+            for (Annotation[] childAnnotations : annotations) {
+                for (Annotation childAnnotation : childAnnotations) {
+                    /**
+                     * 如果方法参数中存在 LoginedUser 属性获取注解, 则也认定为需要 登录 验证
+                     */
+                    if (childAnnotation.annotationType() == LoginedUser.class) {
+                        return true;
+                    }
+                }
+            }
+        }
+        return result;
+    }
+
+    /**
+     * 获取注解中对类的描述信息 用于Controller层注解
+     *
+     * @param joinPoint 切点
+     * @return 类描述
+     * @throws Exception
+     */
+//    public  static String getControllerDescription(JoinPoint joinPoint)  throws Exception {
+//        String targetName = joinPoint.getTarget().getClass().getName();
+//        String methodName = joinPoint.getSignature().getName();
+//        Object[] arguments = joinPoint.getArgs();
+//        Class targetClass = Class.forName(targetName);
+//        Method[] methods = targetClass.getMethods();
+//        String description = "";
+//        for (Method method : methods) {
+//            if (method.getName().equals(methodName)) {
+//                Class[] clazzs = method.getParameterTypes();
+//                if (clazzs.length == arguments.length) {
+//                    Api api = (Api)targetClass.getAnnotation(Api.class);
+//                    if (api != null) {
+//                        description = api.description();
+//                    }
+//                    break;
+//                }
+//            }
+//        }
+//        return description;
+//    }
+
+    /**
+     * 获取注解中对方法的描述信息 用于Controller层 Method 注解
+     *
+     * @param joinPoint 切点
+     * @return 方法描述
+     * @throws Exception
+     */
+    public  static String getControllerMethodDescription(JoinPoint joinPoint)  throws Exception {
+        String targetName = joinPoint.getTarget().getClass().getName();
+        String methodName = joinPoint.getSignature().getName();
+        Object[] arguments = joinPoint.getArgs();
+        Class targetClass = Class.forName(targetName);
+        Method[] methods = targetClass.getMethods();
+        String description = "";
+        for (Method method : methods) {
+            if (method.getName().equals(methodName)) {
+                Class[] clazzs = method.getParameterTypes();
+                if (clazzs.length == arguments.length) {
+                    ApiOperation apiOperation = method.getAnnotation(ApiOperation.class);
+                    if (apiOperation != null) {
+                        description = apiOperation.value();
+                        if (StrUtil.isBlank(description)) {
+                            description = apiOperation.notes();
+                        }
+                    }
+                    break;
+                }
+            }
+        }
+        return description;
+    }
+
+    /**
+     * 获取注解中对方法的描述信息 用于Controller层 Method 注解
+     *
+     * @param joinPoint 切点
+     * @return 方法描述
+     * @throws Exception
+     */
+    public static String[] getControllerModule(JoinPoint joinPoint)  throws Exception {
+        String targetName = joinPoint.getTarget().getClass().getName();
+        String methodName = joinPoint.getSignature().getName();
+        Object[] arguments = joinPoint.getArgs();
+        Class targetClass = Class.forName(targetName);
+        Method[] methods = targetClass.getMethods();
+        for (Method method : methods) {
+            if (method.getName().equals(methodName)) {
+                Class[] clazzs = method.getParameterTypes();
+                if (clazzs.length == arguments.length) {
+                    LogModule logModule = method.getAnnotation(LogModule.class);
+                    if (logModule != null) {
+                        if (StrUtil.isNotBlank(logModule.childModule())) {
+                            return new String[] { logModule.masterModule(), logModule.childModule() };
+                        }
+                        return new String[] { logModule.masterModule() };
+                    }
+                    break;
+                }
+            }
+        }
+        LogModule logControllerAnnotation = AnnotationUtils.findAnnotation(targetClass, LogModule.class);
+        if (logControllerAnnotation != null) {
+            if (StrUtil.isNotBlank(logControllerAnnotation.childModule())) {
+                return new String[] { logControllerAnnotation.masterModule(), logControllerAnnotation.childModule() };
+            }
+            return new String[] { logControllerAnnotation.masterModule() };
+        }
+        return new String[0];
+    }
+
+}

+ 2 - 1
src/main/java/com/care/service/CareSysUserService.java

@@ -2,6 +2,7 @@ package com.care.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.care.common.entity.CareSysUser;
+import com.care.common.vo.UserLogindConvertVO;
 
 /**
  * 安全管家表(CareSysUser)表服务接口
@@ -10,5 +11,5 @@ import com.care.common.entity.CareSysUser;
  * @since 2021-05-21 00:08:38
  */
 public interface CareSysUserService extends IService<CareSysUser> {
-
+    UserLogindConvertVO getLoginUser(String orgCode, String phone,String password);
 }

+ 38 - 0
src/main/java/com/care/service/impl/CareSysUserServiceImpl.java

@@ -1,11 +1,22 @@
 package com.care.service.impl;
 
+import cn.hutool.core.bean.BeanUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.care.common.entity.CareOrganization;
 import com.care.common.entity.CareSysUser;
+import com.care.common.exception.BDException;
+import com.care.common.vo.UserLogindConvertVO;
 import com.care.mapper.CareSysUserMapper;
+import com.care.service.CareOrganizationService;
 import com.care.service.CareSysUserService;
+import com.care.util.Result;
+import org.apache.commons.codec.digest.DigestUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
+
 /**
  * 安全管家表(CareSysUser)表服务实现类
  *
@@ -15,4 +26,31 @@ import org.springframework.stereotype.Service;
 @Service
 public class CareSysUserServiceImpl extends ServiceImpl<CareSysUserMapper, CareSysUser> implements CareSysUserService {
 
+    @Resource
+    private CareOrganizationService careOrganizationService;
+
+    @Override
+    public UserLogindConvertVO getLoginUser(String orgCode, String phone,String password) {
+        UserLogindConvertVO userLogindConvertVO = null;
+        QueryWrapper<CareOrganization>  organizationQueryWrapper = new QueryWrapper<>();
+        organizationQueryWrapper.lambda().eq(CareOrganization::getOrgCode,orgCode);
+        CareOrganization org = this.careOrganizationService.getOne(organizationQueryWrapper);
+        if (org == null){
+            return null;
+        }
+        QueryWrapper<CareSysUser>  userQueryWrapper = new QueryWrapper<>();
+        userQueryWrapper.lambda().eq(CareSysUser::getOrgId,org.getId())
+                                .eq(CareSysUser::getPhone,phone);
+        CareSysUser user = this.getOne(userQueryWrapper);
+        if (user != null){
+            userLogindConvertVO = new UserLogindConvertVO();
+            BeanUtil.copyProperties(user,userLogindConvertVO);
+            userLogindConvertVO.setOrgName(org.getName());
+            String md5Password = DigestUtils.md5Hex(password);
+            if (!md5Password.equalsIgnoreCase(user.getPassword())) {
+                throw new BDException("用户名或密码错误");
+            }
+        }
+        return userLogindConvertVO;
+    }
 }

+ 0 - 1
src/main/java/com/care/util/JsonUtil.java

@@ -3,7 +3,6 @@ package com.care.util;
 import com.fasterxml.jackson.databind.ObjectMapper;
 
 /**
- * @author 许明
  * @version 1.0.0 创建于 2019/8/6
  **/
 public final class JsonUtil {

+ 84 - 0
src/main/java/com/care/util/JwtUtils.java

@@ -0,0 +1,84 @@
+package com.care.util;
+
+import cn.hutool.json.JSONUtil;
+import com.care.common.vo.UserLogindConvertVO;
+import io.jsonwebtoken.Claims;
+import io.jsonwebtoken.Jwts;
+import io.jsonwebtoken.SignatureAlgorithm;
+import org.apache.commons.codec.binary.Base64;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import javax.crypto.SecretKey;
+import javax.crypto.spec.SecretKeySpec;
+import java.security.Key;
+import java.util.Date;
+
+/**
+ * Created by y on 2017/11/16.
+ * @author y
+ */
+@Component
+@PropertySource(value = "classpath:common.properties", ignoreResourceNotFound = true)
+public class JwtUtils {
+
+    private static final Logger logger = LoggerFactory.getLogger(JwtUtils.class);
+
+    @Resource
+    private Environment env;
+
+    /**
+     * 由字符串生成加密key
+     * @return
+     */
+    public SecretKey generalKey() {
+        String stringKey = env.getProperty("auth.jwt.id") + env.getProperty("auth.jwt.secret");
+        byte[] encodedKey = Base64.decodeBase64(stringKey);
+        SecretKey key = new SecretKeySpec(encodedKey, 0, encodedKey.length, "AES");
+        return key;
+    }
+
+    public String generalToken(UserLogindConvertVO userLogindConvertDTO) {
+        String compactJws = null;
+        try {
+            long nowMillis = System.currentTimeMillis();
+            Date now = new Date(nowMillis);
+            Key key = generalKey();
+            compactJws = Jwts.builder()
+                    .setSubject(JSONUtil.toJsonStr(userLogindConvertDTO))
+                    .setIssuedAt(now)
+                    .signWith(SignatureAlgorithm.HS512, key)
+                    .setExpiration(new Date(nowMillis + env.getProperty("auth.jwt.ttl.ms", Long.class)))
+                    .compact();
+        } catch (Exception e) {
+            logger.error("生成TOKEN出现异常.", e);
+        }
+        return compactJws;
+    }
+
+    /**
+     * 解密jwt
+     * @param jwt
+     * @return
+     * @throws Exception
+     */
+    public Claims tokenParse(String jwt) {
+        SecretKey key = generalKey();
+        Claims claims = null;
+        try {
+            claims = Jwts.parser()
+                    .setSigningKey(key)
+                    .parseClaimsJws(jwt).getBody();
+        } catch (io.jsonwebtoken.ExpiredJwtException e) {
+            System.out.println("当前TOKEN已过期, 请重新登录.");
+        } catch (Exception e) {
+            System.out.println("校验TOKEN出现异常, 请重新登录.");
+        }
+        return claims;
+    }
+
+}

+ 4 - 0
src/main/java/com/care/util/ResultCode.java

@@ -13,11 +13,15 @@ public enum ResultCode {
      * 网络异常响应
      */
     WARN("00002","网络异常,请稍后重试"),
+    NO_LOGINED("00003","未登录"),
+    UNKNOWN("99999","未知异常"),
     /**
      * 异常响应
      */
     ERROR("00001","操作失败");
 
+
+
     ResultCode(String status, String message) {
         this.status = status;
         this.message = message;

+ 124 - 0
src/main/java/com/care/util/WebPageUtils.java

@@ -0,0 +1,124 @@
+package com.care.util;
+
+import com.care.common.constant.Constants;
+import com.care.common.vo.UserLogindConvertVO;
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Created by y on 2017/11/23.
+ * @author y
+ */
+public class WebPageUtils {
+
+    public static final String IS_IPV4_ADDR = "^([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5]).([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5]).([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5]).([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])$";
+
+    /**
+     * 获取当前登录用户
+     * @param request
+     * @return
+     */
+    public static UserLogindConvertVO getCurrentLoginedUser(HttpServletRequest request) {
+        if (request == null) {
+            return null;
+        }
+        Object obj = request.getAttribute(Constants.CURRENT_LOGINED_USER_KEY);
+        return obj != null ? (UserLogindConvertVO)obj : null;
+    }
+
+    /**
+     * 真实IP地址验证, 防止IP攻击,错误的IP导致安全问题
+     */
+    private static boolean isRealIPAddr(String ipAddr) throws Exception {
+        boolean b1 = false;
+        String spIP1 = "0.0.0.0";
+        String spIp2 = "255.255.255.255";
+        /**
+         * 是否正确的ip地址
+         */
+        boolean b = regexValid(ipAddr, IS_IPV4_ADDR);
+        if (b) {
+            if (!spIP1.equals(ipAddr) && !spIp2.equals(ipAddr)) {
+                b1 = true;
+            }
+        }
+        return b1;
+    }
+
+    /**
+     * 验证方法
+     * @param input
+     * @param reg
+     * @return
+     * @throws Exception
+     */
+    public static boolean regexValid(String input, String reg) throws Exception {
+        if (input == null || "".equals(input) || reg == null || "".equals(reg)) {
+            throw new Exception("参数不能为空!");
+        }
+        Pattern regex = Pattern.compile(reg);
+        Matcher matcher = regex.matcher(input);
+        return matcher.matches();
+    }
+
+    /**
+     * 获取客户端真实ip地址
+     */
+    public static String getIpAddr(HttpServletRequest request) throws Exception {
+        boolean b = false;
+        String ip = request.getHeader("x-forwarded-for");
+        String unKnown = "unknown";
+        if (StringUtils.isNotBlank(ip) && !unKnown.equalsIgnoreCase(ip)) {
+            /**
+             * 多次反向代理后会有多个ip值,第一个ip才是真实ip
+             */
+            int index = ip.indexOf(",");
+            if (index != -1) {
+                ip = ip.substring(0, index);
+                b = isRealIPAddr(ip);
+                if (!b) {
+                    ip = "";
+                }
+            }
+        }
+        if (ip == null || ip.length() == 0 || unKnown.equalsIgnoreCase(ip)) {
+            ip = request.getHeader("X-Real-IP");
+            if (StringUtils.isNotBlank(ip)) {
+                b = isRealIPAddr(ip);
+                if (!b) {
+                    ip = "";
+                }
+            }
+        }
+        if (ip == null || ip.length() == 0 || unKnown.equalsIgnoreCase(ip)) {
+            ip = request.getHeader("Proxy-Client-IP");
+            if (StringUtils.isNotBlank(ip)) {
+                b = isRealIPAddr(ip);
+                if (!b) {
+                    ip = "";
+                }
+            }
+        }
+        if (ip == null || ip.length() == 0 || unKnown.equalsIgnoreCase(ip)) {
+            ip = request.getHeader("WL-Proxy-Client-IP");
+            if (StringUtils.isNotBlank(ip)) {
+                b = isRealIPAddr(ip);
+                if (!b) {
+                    ip = "";
+                }
+            }
+        }
+        if (ip == null || ip.length() == 0 || unKnown.equalsIgnoreCase(ip)) {
+            ip = request.getRemoteAddr();
+        }
+        return ip;
+    }
+
+    public static void main(String[] args) {
+        System.out.println(DigestUtils.md5Hex("123456"));
+    }
+}

+ 8 - 0
src/main/resources/application.properties

@@ -51,3 +51,11 @@ spring.servlet.multipart.maxRequestSize=20MB
 spring.freemarker.template-loader-path=classpath:/template,classpath:/font
 #spring.freemarker.check-template-location=false
 
+#################################### 以下是redis的集群标准配置 ##################################
+spring.redis.host=114.116.250.135
+spring.redis.port=7001
+spring.redis.database=0
+spring.redis.timeout=500
+spring.redis.password=106@!en4
+#################################### 以下是redis的集群标准配置 结束 ##############################
+

+ 7 - 0
src/main/resources/common.properties

@@ -0,0 +1,7 @@
+# jwt ��ʶ
+auth.jwt.id=standard_jwt
+# jwt ��Կ
+auth.jwt.secret=hong1mu2zhi3ruan4jian5
+# jwt ����ʱ��, (2Сʱ = 7200000ms; 24Сʱ = 86400000ms; 7�� = 604800000ms)
+auth.jwt.ttl.ms=86400000
+