diff --git a/demo/pom.xml b/demo/pom.xml index 633bff6..8a1ce5f 100644 --- a/demo/pom.xml +++ b/demo/pom.xml @@ -25,4 +25,24 @@ + + + kepai-repo + http://git.kepai365.com/zeng_wenhao/kepai-repo/raw/master + + true + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/pom.xml b/pom.xml index df9d717..672ec69 100644 --- a/pom.xml +++ b/pom.xml @@ -35,6 +35,7 @@ 8 8 UTF-8 + 3.5.1 diff --git a/tiesheng-db-migration/src/main/java/com/tiesheng/migration/config/DbMigrationConfig.java b/tiesheng-db-migration/src/main/java/com/tiesheng/migration/config/DbMigrationConfig.java index bc41879..21face5 100644 --- a/tiesheng-db-migration/src/main/java/com/tiesheng/migration/config/DbMigrationConfig.java +++ b/tiesheng-db-migration/src/main/java/com/tiesheng/migration/config/DbMigrationConfig.java @@ -20,7 +20,7 @@ import java.util.List; public class DbMigrationConfig { private String table = "core_db_migration"; - private List locations = CollUtil.newArrayList("classpath:db/migration/*.sql"); + private List locations = CollUtil.newArrayList("classpath*:db/migration/*.sql"); private String ignoreSqls = "drop,delete"; /** diff --git a/tiesheng-login/pom.xml b/tiesheng-login/pom.xml index 41cc97b..8dc530f 100644 --- a/tiesheng-login/pom.xml +++ b/tiesheng-login/pom.xml @@ -18,6 +18,14 @@ + + + + org.springframework.boot + spring-boot-starter-aop + compile + + com.tiesheng tiesheng-ding @@ -30,6 +38,14 @@ ${project.parent.version} + + + com.baomidou + mybatis-plus-boot-starter + ${mybatis-plus.version} + compile + + diff --git a/tiesheng-login/src/main/java/com/tiesheng/login/LoginAutoImportSelector.java b/tiesheng-login/src/main/java/com/tiesheng/login/LoginAutoImportSelector.java new file mode 100644 index 0000000..900b29e --- /dev/null +++ b/tiesheng-login/src/main/java/com/tiesheng/login/LoginAutoImportSelector.java @@ -0,0 +1,15 @@ +package com.tiesheng.login; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.context.annotation.ComponentScan; + +/** + * @author hao + */ + +@ComponentScan({ + "com.tiesheng.login.**.*", +}) +@MapperScan("com.tiesheng.login.mapper") +public class LoginAutoImportSelector { +} diff --git a/tiesheng-web/src/main/java/com/tiesheng/core/config/token/TokenValidAspect.java b/tiesheng-login/src/main/java/com/tiesheng/login/config/token/TsTokenAspect.java similarity index 84% rename from tiesheng-web/src/main/java/com/tiesheng/core/config/token/TokenValidAspect.java rename to tiesheng-login/src/main/java/com/tiesheng/login/config/token/TsTokenAspect.java index 4516ce7..cd6b44b 100644 --- a/tiesheng-web/src/main/java/com/tiesheng/core/config/token/TokenValidAspect.java +++ b/tiesheng-login/src/main/java/com/tiesheng/login/config/token/TsTokenAspect.java @@ -1,4 +1,4 @@ -package com.tiesheng.core.config.token; +package com.tiesheng.login.config.token; import com.tiesheng.annotation.token.TokenIgnore; import org.aspectj.lang.JoinPoint; @@ -6,6 +6,7 @@ import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.reflect.MethodSignature; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.lang.reflect.Method; @@ -22,7 +23,10 @@ import java.lang.reflect.Method; */ @Aspect @Component -public class TokenValidAspect { +public class TsTokenAspect { + + @Autowired + TsTokenConfig tsTokenConfig; /** @@ -51,7 +55,8 @@ public class TokenValidAspect { } // token验证 - TokenParse.get(); + tsTokenConfig.validToken(true); + } diff --git a/tiesheng-login/src/main/java/com/tiesheng/login/config/token/TsTokenConfig.java b/tiesheng-login/src/main/java/com/tiesheng/login/config/token/TsTokenConfig.java new file mode 100644 index 0000000..f8a76be --- /dev/null +++ b/tiesheng-login/src/main/java/com/tiesheng/login/config/token/TsTokenConfig.java @@ -0,0 +1,146 @@ +package com.tiesheng.login.config.token; + + +import cn.hutool.core.map.MapUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.extra.servlet.ServletUtil; +import cn.hutool.extra.spring.SpringUtil; +import cn.hutool.jwt.JWT; +import com.tiesheng.login.config.token.bean.TokenBean; +import com.tiesheng.util.ServletKit; +import com.tiesheng.util.exception.ApiException; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import java.util.Map; + + +/** + * @author hao + */ +@Configuration +@ConfigurationProperties("tiesheng.token") +public class TsTokenConfig { + + private Map ignores = MapUtil.newHashMap(); + private String encryptKey = "%kIp9frQCu"; + private Integer expireHours = 48; + + + /** + * 获取当前登录的token + * + * @return + */ + public static TokenBean get() { + TsTokenConfig tokenConfig = SpringUtil.getBean(TsTokenConfig.class); + return tokenConfig.validToken(true); + } + + + /** + * 获取当前登录的token + * + * @return + */ + public static TokenBean getWithoutThr() { + TsTokenConfig tokenConfig = SpringUtil.getBean(TsTokenConfig.class); + return tokenConfig.validToken(false); + } + + + /** + * 验证token + * + * @param token + * @return + */ + public TokenBean isIgnored(String token) { + if (ignores == null) { + return null; + } + return ignores.get(token); + } + + /** + * 设置token + */ + public String toToken(String id, String environmentType, String service, String extra) { + return JWT.create() + .setPayload("id", id) + .setPayload("environmentType", environmentType) + .setPayload("service", service) + .setPayload("extra", extra) + .setPayload("time", System.currentTimeMillis() + expireHours * 1000 * 60 * 60) + .setKey(getEncryptKey().getBytes()) + .sign(); + } + + /** + * 验证token + * + * @return + */ + public TokenBean validToken(boolean thrExp) { + String token = ServletUtil.getHeader(ServletKit.getRequest(), "token", "utf-8"); + TokenBean tokenBean = isIgnored(token); + if (tokenBean != null) { + return tokenBean; + } + + try { + JWT decode = JWT.of(token); + String id = decode.getPayload("id").toString(); + String environmentType = decode.getPayload("environmentType").toString(); + String service = decode.getPayload("service").toString(); + String extra = decode.getPayload("extra").toString(); + Long expireTime = decode.getPayloads().getLong("time"); + if (expireTime != null && expireTime < System.currentTimeMillis()) { + throw new ApiException("登录过期,请重新登陆"); + } + + tokenBean = new TokenBean(id, environmentType, service); + tokenBean.setExtra(extra); + } catch (Exception ignored) { + } + + if (tokenBean == null && thrExp) { + throw new ApiException(StrUtil.isEmpty(token) ? "请先登录" : "登录过期,请重新登陆"); + } + + if (tokenBean == null) { + tokenBean = new TokenBean(); + tokenBean.setId(""); + } + + return tokenBean; + } + + /////////////////////////////////////////////////////////////////////////// + // setter\getter + /////////////////////////////////////////////////////////////////////////// + + public Map getIgnores() { + return ignores; + } + + public void setIgnores(Map ignores) { + this.ignores = ignores; + } + + public String getEncryptKey() { + return encryptKey; + } + + public void setEncryptKey(String encryptKey) { + this.encryptKey = encryptKey; + } + + public Integer getExpireHours() { + return expireHours; + } + + public void setExpireHours(Integer expireHours) { + this.expireHours = expireHours; + } +} diff --git a/tiesheng-web/src/main/java/com/tiesheng/core/config/token/bean/TokenBean.java b/tiesheng-login/src/main/java/com/tiesheng/login/config/token/bean/TokenBean.java similarity index 68% rename from tiesheng-web/src/main/java/com/tiesheng/core/config/token/bean/TokenBean.java rename to tiesheng-login/src/main/java/com/tiesheng/login/config/token/bean/TokenBean.java index 0670ed9..59ada0e 100644 --- a/tiesheng-web/src/main/java/com/tiesheng/core/config/token/bean/TokenBean.java +++ b/tiesheng-login/src/main/java/com/tiesheng/login/config/token/bean/TokenBean.java @@ -1,7 +1,8 @@ -package com.tiesheng.core.config.token.bean; - -import cn.hutool.jwt.JWT; +package com.tiesheng.login.config.token.bean; +/** + * @author hao + */ public class TokenBean { private String id; @@ -19,21 +20,6 @@ public class TokenBean { this.extra = ""; } - /** - * 设置token - */ - public String toToken() { - byte[] key = "%kIp9frQCu".getBytes(); - return JWT.create() - .setPayload("id", id) - .setPayload("environmentType", environmentType) - .setPayload("service", service) - .setPayload("extra", extra) - .setPayload("time", System.currentTimeMillis()) - .setKey(key) - .sign(); - } - /////////////////////////////////////////////////////////////////////////// // setter\getter /////////////////////////////////////////////////////////////////////////// diff --git a/tiesheng-login/src/main/java/com/tiesheng/login/controller/LoginUserController.java b/tiesheng-login/src/main/java/com/tiesheng/login/controller/LoginUserController.java new file mode 100644 index 0000000..842bf00 --- /dev/null +++ b/tiesheng-login/src/main/java/com/tiesheng/login/controller/LoginUserController.java @@ -0,0 +1,12 @@ +package com.tiesheng.login.controller; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author hao + */ +@RestController +@RequestMapping("/login/user") +public class LoginUserController { +} diff --git a/tiesheng-login/src/main/java/com/tiesheng/login/mapper/CoreLogLoginMapper.java b/tiesheng-login/src/main/java/com/tiesheng/login/mapper/CoreLogLoginMapper.java new file mode 100644 index 0000000..decbb40 --- /dev/null +++ b/tiesheng-login/src/main/java/com/tiesheng/login/mapper/CoreLogLoginMapper.java @@ -0,0 +1,7 @@ +package com.tiesheng.login.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.tiesheng.login.pojos.dao.CoreLogLogin; + +public interface CoreLogLoginMapper extends BaseMapper { +} \ No newline at end of file diff --git a/tiesheng-login/src/main/java/com/tiesheng/login/pojos/dao/CoreLogLogin.java b/tiesheng-login/src/main/java/com/tiesheng/login/pojos/dao/CoreLogLogin.java new file mode 100644 index 0000000..5215090 --- /dev/null +++ b/tiesheng-login/src/main/java/com/tiesheng/login/pojos/dao/CoreLogLogin.java @@ -0,0 +1,156 @@ +package com.tiesheng.login.pojos.dao; + +import com.baomidou.mybatisplus.annotation.*; + +import java.util.Date; + +/** + * 日志-登录 + */ +@TableName(value = "core_log_login") +public class CoreLogLogin { + + @TableId(value = "id", type = IdType.ASSIGN_ID) + private String id; + + @TableField(value = "create_time", fill = FieldFill.INSERT) + private Date createTime; + + @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE) + private Date updateTime; + + @TableField(value = "is_deleted") + private Integer isDeleted; + + /** + * 用户id + */ + @TableField(value = "user_id") + private String userId; + + /** + * 用户id + */ + @TableField(value = "user_name") + private String userName; + + /** + * ip + */ + @TableField(value = "platform") + private String platform; + + /** + * ip + */ + @TableField(value = "ip") + private String ip; + + /** + * ip地址 + */ + @TableField(value = "address") + private String address; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + public Integer getIsDeleted() { + return isDeleted; + } + + public void setIsDeleted(Integer isDeleted) { + this.isDeleted = isDeleted; + } + + /** + * 获取用户id + * + * @return user_id - 用户id + */ + public String getUserId() { + return userId; + } + + /** + * 设置用户id + * + * @param userId 用户id + */ + public void setUserId(String userId) { + this.userId = userId; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getPlatform() { + return platform; + } + + public void setPlatform(String platform) { + this.platform = platform; + } + + /** + * 获取ip + * + * @return ip - ip + */ + public String getIp() { + return ip; + } + + /** + * 设置ip + * + * @param ip ip + */ + public void setIp(String ip) { + this.ip = ip; + } + + /** + * 获取ip地址 + * + * @return address - ip地址 + */ + public String getAddress() { + return address; + } + + /** + * 设置ip地址 + * + * @param address ip地址 + */ + public void setAddress(String address) { + this.address = address; + } +} diff --git a/tiesheng-login/src/main/java/com/tiesheng/login/service/LoginLogService.java b/tiesheng-login/src/main/java/com/tiesheng/login/service/LoginLogService.java new file mode 100644 index 0000000..6aca26d --- /dev/null +++ b/tiesheng-login/src/main/java/com/tiesheng/login/service/LoginLogService.java @@ -0,0 +1,42 @@ +package com.tiesheng.login.service; + +import cn.hutool.extra.servlet.ServletUtil; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.tiesheng.login.mapper.CoreLogLoginMapper; +import com.tiesheng.login.pojos.dao.CoreLogLogin; +import com.tiesheng.util.ServletKit; +import com.tiesheng.util.ip2region.DataBlock; +import com.tiesheng.util.ip2region.Ip2Region; +import org.springframework.stereotype.Service; + +import javax.servlet.http.HttpServletRequest; + +/** + * @author hao + */ +@Service +public class LoginLogService extends ServiceImpl { + + + /** + * 获取 + * + * @param userId + */ + public void addLog(String userId, String platform) { + + HttpServletRequest request = ServletKit.getRequest(); + String ip = ServletUtil.getClientIP(request); + + CoreLogLogin login = new CoreLogLogin(); + login.setUserId(userId); + login.setPlatform(platform); + + login.setIp(ip); + DataBlock dataBlock = Ip2Region.getInstance().btreeSearch(ip); + login.setAddress(dataBlock.getRegion()); + save(login); + } + + +} diff --git a/tiesheng-login/src/main/resources/db/migration/tiesheng_login_log.sql b/tiesheng-login/src/main/resources/db/migration/tiesheng_login_log.sql new file mode 100644 index 0000000..ccf8bfe --- /dev/null +++ b/tiesheng-login/src/main/resources/db/migration/tiesheng_login_log.sql @@ -0,0 +1,22 @@ +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for core_log_login +-- ---------------------------- +CREATE TABLE `core_log_login` +( + `id` varchar(50) NOT NULL, + `create_time` datetime NOT NULL, + `update_time` datetime NOT NULL, + `is_deleted` int(6) NOT NULL DEFAULT '0', + `user_id` varchar(50) DEFAULT NULL COMMENT '用户id', + `user_name` varchar(255) DEFAULT NULL COMMENT '用户姓名', + `platform` varchar(50) DEFAULT NULL COMMENT '登录方式', + `ip` varchar(100) DEFAULT NULL COMMENT 'ip', + `address` varchar(255) DEFAULT NULL COMMENT 'ip地址', + PRIMARY KEY (`id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 COMMENT ='日志-登录'; + +SET FOREIGN_KEY_CHECKS = 1; diff --git a/tiesheng-login/src/main/resources/mapper/CoreLogLoginMapper.xml b/tiesheng-login/src/main/resources/mapper/CoreLogLoginMapper.xml new file mode 100644 index 0000000..9aeaf93 --- /dev/null +++ b/tiesheng-login/src/main/resources/mapper/CoreLogLoginMapper.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + id, create_time, update_time, is_deleted, user_id, user_name, platform, ip, address + + \ No newline at end of file diff --git a/tiesheng-util/pom.xml b/tiesheng-util/pom.xml index 337f672..7589245 100644 --- a/tiesheng-util/pom.xml +++ b/tiesheng-util/pom.xml @@ -18,6 +18,13 @@ + + + org.springframework.boot + spring-boot-starter-web + compile + + cn.hutool hutool-all diff --git a/tiesheng-web/src/main/java/com/tiesheng/core/util/servlet/ServletKit.java b/tiesheng-util/src/main/java/com/tiesheng/util/ServletKit.java similarity index 93% rename from tiesheng-web/src/main/java/com/tiesheng/core/util/servlet/ServletKit.java rename to tiesheng-util/src/main/java/com/tiesheng/util/ServletKit.java index 2b7418d..13d7801 100644 --- a/tiesheng-web/src/main/java/com/tiesheng/core/util/servlet/ServletKit.java +++ b/tiesheng-util/src/main/java/com/tiesheng/util/ServletKit.java @@ -1,4 +1,4 @@ -package com.tiesheng.core.util.servlet; +package com.tiesheng.util; import cn.hutool.extra.servlet.ServletUtil; import org.springframework.web.context.request.RequestContextHolder; diff --git a/tiesheng-web/pom.xml b/tiesheng-web/pom.xml index 4439e32..f2bbaa6 100644 --- a/tiesheng-web/pom.xml +++ b/tiesheng-web/pom.xml @@ -48,14 +48,14 @@ mysql mysql-connector-java - 8.0.12 + 8.0.30 com.baomidou mybatis-plus-boot-starter - 3.5.1 + ${mybatis-plus.version} diff --git a/tiesheng-web/src/main/java/com/tiesheng/core/EnableTieshengWeb.java b/tiesheng-web/src/main/java/com/tiesheng/core/EnableTieshengWeb.java index b456747..5b1e753 100644 --- a/tiesheng-web/src/main/java/com/tiesheng/core/EnableTieshengWeb.java +++ b/tiesheng-web/src/main/java/com/tiesheng/core/EnableTieshengWeb.java @@ -1,6 +1,8 @@ package com.tiesheng.core; +import com.tiesheng.login.LoginAutoImportSelector; import com.tiesheng.migration.MigrationAutoImportSelector; +import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Import; import java.lang.annotation.*; @@ -13,7 +15,9 @@ import java.lang.annotation.*; @Documented @Import({ CoreAutoImportSelector.class, + LoginAutoImportSelector.class, MigrationAutoImportSelector.class }) +@ComponentScan("cn.hutool.extra.spring") public @interface EnableTieshengWeb { } diff --git a/tiesheng-web/src/main/java/com/tiesheng/core/config/operation/OperationAspect.java b/tiesheng-web/src/main/java/com/tiesheng/core/config/operation/OperationAspect.java index 82c0c84..6eaca63 100644 --- a/tiesheng-web/src/main/java/com/tiesheng/core/config/operation/OperationAspect.java +++ b/tiesheng-web/src/main/java/com/tiesheng/core/config/operation/OperationAspect.java @@ -4,8 +4,6 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.StrUtil; import com.tiesheng.annotation.operation.OperationLog; -import com.tiesheng.core.config.token.TokenParse; -import com.tiesheng.core.config.token.bean.TokenBean; import com.tiesheng.core.service.CoreLogService; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; diff --git a/tiesheng-web/src/main/java/com/tiesheng/core/config/token/TokenParse.java b/tiesheng-web/src/main/java/com/tiesheng/core/config/token/TokenParse.java deleted file mode 100644 index 4355011..0000000 --- a/tiesheng-web/src/main/java/com/tiesheng/core/config/token/TokenParse.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.tiesheng.core.config.token; - -import cn.hutool.extra.servlet.ServletUtil; -import cn.hutool.extra.spring.SpringUtil; -import cn.hutool.jwt.JWT; -import com.tiesheng.core.config.token.bean.TokenBean; -import com.tiesheng.core.util.servlet.ServletKit; -import com.tiesheng.util.exception.ApiException; -import com.tiesheng.util.pojos.ApiResp; - -/** - * @author hao - */ -public class TokenParse { - - - /** - * 获取登陆信息 - * - * @param token - * @return - */ - public static TokenBean get(String token) { - try { - - TokenValidConfig tokenValidConfig = SpringUtil.getBean(TokenValidConfig.class); - TokenBean tokenBean = tokenValidConfig.getTokenBean(token); - if (tokenBean == null) { - JWT decode = JWT.of(token); - String id = decode.getPayload("id").toString(); - String environmentType = decode.getPayload("environmentType").toString(); - String service = decode.getPayload("service").toString(); - String extra = decode.getPayload("extra").toString(); - tokenBean = new TokenBean(id, environmentType, service); - tokenBean.setExtra(extra); - } - return tokenBean; - } catch (Exception e) { - throw new ApiException(ApiResp.respNeedLogin("请重新登录")); - } - } - - /** - * 获取登录信息 - * - * @return - */ - public static TokenBean get() { - String headerToken = ServletUtil.getHeader(ServletKit.getRequest(), "token", "utf-8"); - return get(headerToken); - } - - /** - * 获取用户id - * - * @return - */ - public static TokenBean getWithoutThr() { - TokenBean tokenBean = null; - try { - tokenBean = get(); - } catch (Exception ignored) { - } - return tokenBean; - } - -} diff --git a/tiesheng-web/src/main/java/com/tiesheng/core/config/token/TokenValidConfig.java b/tiesheng-web/src/main/java/com/tiesheng/core/config/token/TokenValidConfig.java deleted file mode 100644 index 4d36684..0000000 --- a/tiesheng-web/src/main/java/com/tiesheng/core/config/token/TokenValidConfig.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.tiesheng.core.config.token; - - -import cn.hutool.core.map.MapUtil; -import com.tiesheng.core.config.token.bean.TokenBean; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -import java.util.Map; - - -/** - * @author hao - */ -@Configuration -@ConfigurationProperties("tiesheng.token") -public class TokenValidConfig { - - private Map ignores = MapUtil.newHashMap(); - - - /** - * 验证token - * - * @param token - * @return - */ - public TokenBean getTokenBean(String token) { - if (ignores == null) { - return null; - } - return ignores.get(token); - } - - /////////////////////////////////////////////////////////////////////////// - // setter\getter - /////////////////////////////////////////////////////////////////////////// - - public Map getIgnores() { - return ignores; - } - - public void setIgnores(Map ignores) { - this.ignores = ignores; - } -} diff --git a/tiesheng-web/src/main/java/com/tiesheng/core/config/web/TieshengWebConfigurer.java b/tiesheng-web/src/main/java/com/tiesheng/core/config/web/TieshengWebConfigurer.java index 85716e4..17ad62a 100644 --- a/tiesheng-web/src/main/java/com/tiesheng/core/config/web/TieshengWebConfigurer.java +++ b/tiesheng-web/src/main/java/com/tiesheng/core/config/web/TieshengWebConfigurer.java @@ -1,7 +1,7 @@ package com.tiesheng.core.config.web; import cn.hutool.log.LogFactory; -import com.tiesheng.core.config.token.TokenParse; +import com.tiesheng.login.config.token.TsTokenConfig; import com.tiesheng.core.config.web.bean.CurrentWebUser; import com.tiesheng.util.exception.ApiRespEnum; import com.tiesheng.util.pojos.ApiResp; @@ -23,7 +23,7 @@ public interface TieshengWebConfigurer { */ default CurrentWebUser getCurrentUserName() { CurrentWebUser webUser = new CurrentWebUser(); - webUser.setId(TokenParse.getWithoutThr().getId()); + webUser.setId(TsTokenConfig.getWithoutThr().getId()); return webUser; } diff --git a/tiesheng-web/src/main/java/com/tiesheng/core/controller/log/ManagerLogController.java b/tiesheng-web/src/main/java/com/tiesheng/core/controller/log/ManagerLogController.java index d917b94..5143244 100644 --- a/tiesheng-web/src/main/java/com/tiesheng/core/controller/log/ManagerLogController.java +++ b/tiesheng-web/src/main/java/com/tiesheng/core/controller/log/ManagerLogController.java @@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.tiesheng.core.pojos.dao.CoreLogOperation; import com.tiesheng.core.pojos.dto.PageDTO; import com.tiesheng.core.service.CoreLogService; +import com.tiesheng.login.pojos.dao.CoreLogLogin; +import com.tiesheng.login.service.LoginLogService; import com.tiesheng.util.pojos.ApiResp; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -23,6 +25,8 @@ public class ManagerLogController { @Autowired CoreLogService coreLogService; + @Autowired(required = false) + LoginLogService loginLogService; /** @@ -31,7 +35,7 @@ public class ManagerLogController { * @return */ @GetMapping("/operation/page") - public ApiResp> operationList(@Valid PageDTO dto) { + public ApiResp> operationPage(@Valid PageDTO dto) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("is_deleted", 0); @@ -44,4 +48,25 @@ public class ManagerLogController { return ApiResp.respOK(page.getRecords(), page.getTotal()); } + + /** + * 登录日志列表 + * + * @return + */ + @GetMapping("/login/page") + public ApiResp> loginPage(@Valid PageDTO dto) { + + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("is_deleted", 0); + dto.likeColumns(queryWrapper, "user_name", "ip", "address"); + queryWrapper.orderByDesc("create_time"); + + Page page = dto.pageObj(); + if (loginLogService != null) { + loginLogService.page(page, queryWrapper); + } + return ApiResp.respOK(page.getRecords(), page.getTotal()); + } + } diff --git a/tiesheng-web/src/main/java/com/tiesheng/core/service/CoreLogService.java b/tiesheng-web/src/main/java/com/tiesheng/core/service/CoreLogService.java index 888cdb3..9794b40 100644 --- a/tiesheng-web/src/main/java/com/tiesheng/core/service/CoreLogService.java +++ b/tiesheng-web/src/main/java/com/tiesheng/core/service/CoreLogService.java @@ -1,7 +1,7 @@ package com.tiesheng.core.service; import cn.hutool.json.JSONUtil; -import com.tiesheng.core.config.token.TokenParse; +import com.tiesheng.login.config.token.TsTokenConfig; import com.tiesheng.core.config.web.TieshengWebConfigurer; import com.tiesheng.core.config.web.bean.CurrentWebUser; import com.tiesheng.core.mapper.CoreLogOperationMapper; @@ -33,7 +33,7 @@ public class CoreLogService extends TsServiceBase