Bladeren bron

设置超过15未登录,把用户账户停用

Administrator 2 jaren geleden
bovenliggende
commit
112b17fb50

+ 8 - 0
boman-api/boman-api-system/src/main/java/com/boman/system/api/RemoteUserService.java

@@ -70,4 +70,12 @@ public interface RemoteUserService
 
     @PostMapping("user/packInfo")
     LoginUser packInfo(@RequestBody SysUser sysUser);
+
+    /**
+     * 超过15天未登录,设置状态停用
+     * @param sysUser
+     * @return
+     */
+    @PostMapping("user/updateStatus")
+    void updateStatus(@RequestBody SysUser sysUser);
 }

+ 10 - 2
boman-api/boman-api-wechat/src/main/java/com/boman/wechat/api/RemoteWechatService.java

@@ -4,8 +4,7 @@ import com.boman.domain.constant.ServiceNameConstants;
 import com.boman.domain.dto.AjaxResult;
 import com.boman.domain.form.LoginBody;
 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.*;
 
 @FeignClient(contextId = "remoteObjService", value = ServiceNameConstants.WECHAT_SERVICE)
 public interface RemoteWechatService {
@@ -19,6 +18,15 @@ public interface RemoteWechatService {
     @PostMapping("/wechat/p/c/wechatInfo")
     AjaxResult getWechatInfo(@RequestBody LoginBody loginBody);
 
+
+    /**
+     * 判断该用户名最后登录时间是否超过15天,返回值 大于0 则15天内登录过
+     * @param userName
+     * @return
+     */
+    @GetMapping("/logininfor/getLastLogininfor/{userName}")
+    Integer getLastLogininfor(@PathVariable("userName") String userName);
+
     /**
      * 发送消息
      *

+ 21 - 1
boman-auth/src/main/java/com/boman/auth/service/SysLoginService.java

@@ -3,6 +3,7 @@ package com.boman.auth.service;
 import com.boman.common.redis.service.RedisService;
 import com.boman.domain.dto.AjaxResult;
 import com.boman.domain.form.LoginBody;
+import com.boman.wechat.api.RemoteWechatService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
@@ -18,6 +19,8 @@ import com.boman.system.api.RemoteUserService;
 import com.boman.domain.SysUser;
 import com.boman.system.api.model.LoginUser;
 
+import javax.annotation.Resource;
+
 import static com.boman.domain.constant.Constants.SUCCESS;
 
 /**
@@ -35,6 +38,8 @@ public class SysLoginService {
 
     @Autowired
     private RedisService redisService;
+    @Resource
+    private RemoteWechatService remoteWechatService;
 
     @Value("${upkeep}")
     private Boolean upKeep;
@@ -82,6 +87,14 @@ public class SysLoginService {
             throw new BaseException("对不起,您的账号:" + username + " 已被删除");
         }
 
+        //判断15天内是否登录过 大于0 登录过
+        Integer lastLogininforCount = remoteWechatService.getLastLogininfor(username);
+        if (lastLogininforCount < 1){
+            //设置用户停用
+            remoteUserService.updateStatus(user);
+            remoteLogService.saveLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
+            throw new BaseException("对不起,您的账号:" + username + "超过15天未登录 已停用,请联系管理员");
+        }
         if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
             remoteLogService.saveLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
             throw new BaseException("对不起,您的账号:" + username + " 已停用");
@@ -120,7 +133,14 @@ public class SysLoginService {
             remoteLogService.saveLogininfor(userName, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
             throw new BaseException("对不起,您的账号:" + userName + " 已被删除");
         }
-
+        //判断15天内是否登录过 大于0 登录过
+        Integer lastLogininforCount = remoteWechatService.getLastLogininfor(userName);
+        if (lastLogininforCount < 1){
+            //设置用户停用
+            remoteUserService.updateStatus(user);
+            remoteLogService.saveLogininfor(userName, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
+            throw new BaseException("对不起,您的账号:" + userName + "超过15天未登录 已停用,请联系管理员");
+        }
         if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
             remoteLogService.saveLogininfor(userName, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
             throw new BaseException("对不起,您的账号:" + userName + " 已停用");

+ 10 - 0
boman-modules/boman-system/src/main/java/com/boman/system/controller/SysLogininforController.java

@@ -94,4 +94,14 @@ public class SysLogininforController extends BaseController
         }
         return toAjax(logininforService.insertLogininfor(logininfor));
     }
+
+    /**
+     * 判断该用户名最后一次登录时间是否小于 15天
+     * @return
+     */
+    @GetMapping("/getLastLogininfor/{userName}")
+    public int getLastLogininfor (@PathVariable("userName") String userName)
+    {
+        return logininforService.getLastLogininfor(userName);
+    }
 }

+ 7 - 0
boman-modules/boman-system/src/main/java/com/boman/system/controller/SysUserController.java

@@ -362,4 +362,11 @@ public class SysUserController extends BaseController {
         LOGGER.info("getByPhone: 请求结果:{}", JSON.toJSONString(sysUser));
         return ObjectUtils.requireNonNull(sysUser, String.format("手机号 [%s] 对应的用户不存在", phone));
     }
+
+    @PostMapping("/updateStatus")
+    public void updateStatus(@RequestBody SysUser sysUser ) {
+        userService.checkUserAllowed(sysUser);
+        sysUser.setUpdateBy("admin");
+        userService.updateStatus(sysUser);
+    }
 }

+ 7 - 0
boman-modules/boman-system/src/main/java/com/boman/system/mapper/SysLogininforMapper.java

@@ -2,6 +2,7 @@ package com.boman.system.mapper;
 
 import java.util.List;
 import com.boman.system.domain.SysLogininfor;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * 系统访问日志情况信息 数据层
@@ -39,4 +40,10 @@ public interface SysLogininforMapper
      * @return 结果
      */
     public int cleanLogininfor();
+
+    /**
+     * 判断该用户名最后一次登录时间是否小于 15天
+     * @return
+     */
+    public int getLastLogininfor(@Param("userName") String userName);
 }

+ 1 - 0
boman-modules/boman-system/src/main/java/com/boman/system/mapper/SysUserMapper.java

@@ -133,4 +133,5 @@ public interface SysUserMapper
     SysUser queryByOpenId(String openId);
 
     SysUser getByPhone(String phone);
+    SysUser updateStatus(SysUser sysUser);
 }

+ 6 - 0
boman-modules/boman-system/src/main/java/com/boman/system/service/ISysLogininforService.java

@@ -37,4 +37,10 @@ public interface ISysLogininforService
      * 清空系统登录日志
      */
     public void cleanLogininfor();
+
+    /**
+     * 判断该用户名最后一次登录时间是否小于 15天
+     * @return
+     */
+    public int getLastLogininfor(String userName);
 }

+ 2 - 0
boman-modules/boman-system/src/main/java/com/boman/system/service/ISysUserService.java

@@ -221,4 +221,6 @@ public interface ISysUserService
      * @return com.boman.domain.SysUser
      */
     SysUser getByPhone(String phone);
+
+    void updateStatus(SysUser sysUser);
 }

+ 9 - 0
boman-modules/boman-system/src/main/java/com/boman/system/service/impl/SysLogininforServiceImpl.java

@@ -62,4 +62,13 @@ public class SysLogininforServiceImpl implements ISysLogininforService
     {
         logininforMapper.cleanLogininfor();
     }
+
+    /**
+     * 判断该用户名最后一次登录时间是否小于 15天
+     * @return
+     */
+    @Override
+    public int getLastLogininfor(String userName) {
+        return logininforMapper.getLastLogininfor(userName);
+    }
 }

+ 5 - 0
boman-modules/boman-system/src/main/java/com/boman/system/service/impl/SysUserServiceImpl.java

@@ -560,4 +560,9 @@ public class SysUserServiceImpl implements ISysUserService
     public SysUser getByPhone(String phone) {
         return userMapper.getByPhone(phone);
     }
+
+    @Override
+    public void updateStatus(SysUser sysUser) {
+        userMapper.updateStatus(sysUser);
+    }
 }

+ 9 - 5
boman-modules/boman-system/src/main/resources/mapper/system/SysLogininforMapper.xml

@@ -4,7 +4,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.boman.system.mapper.SysLogininforMapper">
 
-	<resultMap type="SysLogininfor" id="SysLogininforResult">
+	<resultMap type="com.boman.system.domain.SysLogininfor" id="SysLogininforResult">
 		<id     property="id"        column="id"           />
 		<result property="userName"      column="user_name"         />
 		<result property="status"        column="status"            />
@@ -13,12 +13,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<result property="accessTime"    column="access_time"       />
 	</resultMap>
 
-	<insert id="insertLogininfor" parameterType="SysLogininfor">
+	<insert id="insertLogininfor" parameterType="com.boman.system.domain.SysLogininfor">
 		insert into sys_logininfor (user_name, status, ipaddr, msg, access_time)
 		values (#{userName}, #{status}, #{ipaddr}, #{msg}, sysdate())
 	</insert>
 	
-	<select id="selectLogininforList" parameterType="SysLogininfor" resultMap="SysLogininforResult">
+	<select id="selectLogininforList" parameterType="com.boman.system.domain.SysLogininfor" resultMap="SysLogininforResult">
 		select id, user_name, ipaddr, status, msg, access_time from sys_logininfor
 		<where>
 			<if test="ipaddr != null and ipaddr != ''">
@@ -39,8 +39,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		</where>
 		order by id desc
 	</select>
-	
-	<delete id="deleteLogininforByIds" parameterType="Long">
+
+    <select id="getLastLogininfor"  resultType="java.lang.Integer">
+	SELECT ifnull(count(1),0) FROM `sys_logininfor` where user_name = #{userName} and date_format(access_time,'%Y-%m-%d') >= DATE_FORMAT(DATE_SUB(now(),INTERVAL 15 DAY),'%Y-%m-%d') and `status` = '0' and msg = '登录成功';
+	</select>
+
+    <delete id="deleteLogininforByIds" parameterType="Long">
  		delete from sys_logininfor where id in
  		<foreach collection="array" item="id" open="(" separator="," close=")">
  			#{id}

+ 3 - 0
boman-modules/boman-system/src/main/resources/mapper/system/SysUserMapper.xml

@@ -213,6 +213,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	<update id="updateUnionId" parameterType="com.boman.domain.SysUser">
 		update sys_user set open_id = #{openId} where id = #{id}
 	</update>
+	<update id="updateStatus" parameterType="com.boman.domain.SysUser">
+		update sys_user set status = '1' where user_name = #{userName}
+	</update>
 
 	<select id="queryByOpenId" resultMap="SysUserResult">
 		select * from sys_user where open_id = #{openId} limit 1;

+ 13 - 0
boman-wechat/src/main/java/com/boman/wechat/controller/AppletLoginController.java

@@ -22,9 +22,11 @@ import com.boman.system.api.RemoteDeptService;
 import com.boman.system.api.RemoteLogService;
 import com.boman.system.api.RemoteUserService;
 import com.boman.system.api.model.LoginUser;
+import com.boman.wechat.api.RemoteWechatService;
 import com.boman.wechat.utils.WxCodeSessionUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -64,6 +66,8 @@ public class AppletLoginController {
     private RemoteLogService remoteLogService;
     @Resource
     private RemoteDeptService remoteDeptService;
+    @Resource
+    private RemoteWechatService remoteWechatService;
 
     @Value("${upkeep}")
     private Boolean upKeep;
@@ -79,10 +83,19 @@ public class AppletLoginController {
             throw new BaseException("对不起,未获取到手机号");
         }
         SysUser user = remoteUserService.getByPhone(dto.getPhoneNumber());
+
         if (user == null){
             throw new BaseException("对不起,未获取到相关信息");
         }
         String userName = user.getUserName();
+        //判断15天内是否登录过 大于0 登录过
+        Integer lastLogininforCount = remoteWechatService.getLastLogininfor(userName);
+        if (lastLogininforCount < 1){
+            //设置用户停用
+            remoteUserService.updateStatus(user);
+            remoteLogService.saveLogininfor(userName, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
+            throw new BaseException("对不起,您的账号:" + userName + "超过15天未登录 已停用,请联系管理员");
+        }
         if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
             remoteLogService.saveLogininfor(userName, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
             throw new BaseException("对不起,您的账号:" + userName + " 已被删除");