Skip to content

Commit

Permalink
modify code:
Browse files Browse the repository at this point in the history
1.增加分页查询登录登出日志信息
2.数据库连接池staff服务初始化
  • Loading branch information
ZhiQinIsZhen committed Dec 2, 2024
1 parent 35f6bf0 commit 1961294
Show file tree
Hide file tree
Showing 21 changed files with 192 additions and 49 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@

这是一个基于Jdk21,框架是SpringCloud + Springboot3 + Mybatis-plus的脚手架。

- 主框架基于:Spring Cloud、Spring Boot、Mybatis-plus
- 主框架基于:Spring Cloud、Spring Boot
- 数据ORM基于:Mybatis-plus
- 注册中心基于:Eureka
- 监控中心基于:Spring Admin
- 登陆安全基于:Spring Security、jjwt、redisson
- 接口文档基于:Swagger-knife4j
- 限流基于:Google-guava
- 分布式定时任务基于:Elastic-job
- 推送聊天基于:Netty
- 登陆安全基于:Spring Security、jjwt
- 接口文档基于:knife4j
- 分库分表读写分离基于:Sharding-jdbc


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* @version 1.0.0
* @date 2024/5/9 15:10
*/
@Tag(name = "员工信息")
@Tag(name = "鉴权相关")
@ApiResponses(value = {
@ApiResponse(responseCode = "0", description = "成功"),
@ApiResponse(responseCode = "1", description = "失败")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package com.liyz.cloud.api.staff.controller.staff;

import com.liyz.cloud.api.staff.vo.staff.StaffInfoVO;
import com.liyz.cloud.api.staff.vo.staff.StaffInfoApiVO;
import com.liyz.cloud.common.api.context.AuthContext;
import com.liyz.cloud.common.base.util.BeanUtil;
import com.liyz.cloud.common.exception.CommonExceptionCodeEnum;
import com.liyz.cloud.common.feign.bo.RemotePage;
import com.liyz.cloud.common.feign.bo.auth.AuthUserBO;
import com.liyz.cloud.common.feign.dto.PageDTO;
import com.liyz.cloud.common.feign.result.PageResult;
import com.liyz.cloud.common.feign.result.Result;
import com.liyz.cloud.service.staff.bo.info.StaffInfoBO;
import com.liyz.cloud.service.staff.dto.log.StaffLogPageDTO;
import com.liyz.cloud.service.staff.feign.StaffInfoFeignService;
import com.liyz.cloud.service.staff.vo.info.StaffInfoVO;
import com.liyz.cloud.service.staff.vo.log.StaffLoginLogVO;
import com.liyz.cloud.service.staff.vo.log.StaffLogoutLogVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down Expand Up @@ -43,19 +46,36 @@ public class StaffInfoController {

@Operation(summary = "查询当前登录员工信息")
@GetMapping("/current")
public Result<StaffInfoVO> userInfo() {
public Result<StaffInfoApiVO> userInfo() {
AuthUserBO authUser = AuthContext.getAuthUser();
Result<StaffInfoBO> result = staffInfoFeignService.getByStaffId(authUser.getAuthId());
return Result.success(BeanUtil.copyProperties(result.getData(), StaffInfoVO::new));
Result<StaffInfoVO> result = staffInfoFeignService.getByStaffId(authUser.getAuthId());
return Result.result(result, BeanUtil.copyProperties(result.getData(), StaffInfoApiVO::new));
}

@Operation(summary = "分页查询员工信息")
@GetMapping("/page")
public PageResult<StaffInfoVO> page(PageDTO page) {
Result<RemotePage<StaffInfoBO>> pageResult = staffInfoFeignService.page(page);
if (CommonExceptionCodeEnum.SUCCESS.getCode().equals(pageResult.getCode())) {
return PageResult.success(BeanUtil.copyRemotePage(pageResult.getData(), StaffInfoVO::new));
}
return PageResult.error(pageResult.getCode(), pageResult.getMessage());
public PageResult<StaffInfoApiVO> page(PageDTO page) {
Result<RemotePage<StaffInfoVO>> pageResult = staffInfoFeignService.page(page);
return PageResult.result(pageResult, BeanUtil.copyRemotePage(pageResult.getData(), StaffInfoApiVO::new));
}

@Operation(summary = "分页查询员工登录信息")
@GetMapping("/login/page")
public PageResult<StaffLoginLogVO> loginPage(@Valid PageDTO page) {
StaffLogPageDTO pageDTO = BeanUtil.copyProperties(page, StaffLogPageDTO::new, (s, t) -> {
t.setStaffId(AuthContext.getAuthUser().getAuthId());
});
Result<RemotePage<StaffLoginLogVO>> pageResult = staffInfoFeignService.loginPage(pageDTO);
return PageResult.result(pageResult, pageResult.getData());
}

@Operation(summary = "分页查询员工登出信息")
@GetMapping("/logout/page")
public PageResult<StaffLogoutLogVO> logoutPage(@Valid PageDTO page) {
StaffLogPageDTO pageDTO = BeanUtil.copyProperties(page, StaffLogPageDTO::new, (s, t) -> {
t.setStaffId(AuthContext.getAuthUser().getAuthId());
});
Result<RemotePage<StaffLogoutLogVO>> pageResult = staffInfoFeignService.logoutPage(pageDTO);
return PageResult.result(pageResult, pageResult.getData());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
@Getter
@Setter
public class StaffInfoVO implements Serializable {
public class StaffInfoApiVO implements Serializable {
@Serial
private static final long serialVersionUID = 3401036150852744531L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
@Getter
@Setter
public class StaffLoginLogVO implements Serializable {
public class StaffLoginLogApiVO implements Serializable {
@Serial
private static final long serialVersionUID = 378737454967076747L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
@Getter
@Setter
public class StaffLogoutLogVO implements Serializable {
public class StaffLogoutLogApiVO implements Serializable {
@Serial
private static final long serialVersionUID = 787994069214271291L;

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @version 1.0.0
* @date 2023/11/13 10:30
*/
@Getter
public class RemotePage<T> implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
Expand All @@ -29,21 +30,17 @@ public RemotePage(List<T> list, long total, long pageNum, long pageSize) {
this.pageSize = pageSize;
}

@Getter
@Setter
@Schema(description = "结果集")
private List<T> list;

@Getter
@Setter
@Schema(description = "总记录数")
private long total;

@Getter
@Schema(description = "当前页")
private long pageNum;

@Getter
@Schema(description = "每页的数量")
private long pageSize;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ public static <T> PageResult<T> error(IExceptionService codeEnum) {
return new PageResult<>(codeEnum);
}

public static <T, E> PageResult<T> result(Result<RemotePage<E>> result, RemotePage<T> data) {
if (CommonExceptionCodeEnum.SUCCESS.getCode().equals(result.getCode())) {
return success(data);
}
return error(result.getCode(), result.getMessage());
}

public void setPageNum(long pageNum) {
this.pageNum = Math.max(1L, pageNum);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,11 @@ public static <E> Result<E> error(IExceptionService codeEnum) {
public static <E> Result<E> error(String code, String message) {
return new Result<>(code, message);
}

public static <E, T> Result<E> result(Result<T> result, E data) {
if (CommonExceptionCodeEnum.SUCCESS.getCode().equals(result.getCode())) {
return success(data);
}
return error(result.getCode(), result.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.liyz.cloud.service.staff.runner;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.liyz.cloud.service.staff.model.StaffLoginLogDO;
import com.liyz.cloud.service.staff.service.StaffLoginLogService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
* Desc:数据库连接池初始化
*
* @author lyz
* @version 1.0.0
* @date 2023/3/14 9:19
*/
@Slf4j
@Component
public class HikariPoolInitRunner implements ApplicationRunner {

@Resource
private StaffLoginLogService staffLoginLogService;

@Override
public void run(ApplicationArguments args) throws Exception {
StaffLoginLogDO staffLoginLogDO = staffLoginLogService.getOne(
Wrappers.lambdaQuery(StaffLoginLogDO.builder().staffId(1L).build()), false);
log.info("hikari pool init success");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.liyz.cloud.service.staff.dto.log;

import com.liyz.cloud.common.feign.dto.PageDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
* Desc:
*
* @author lyz
* @version 1.0.0
* @date 2024/10/30 15:23
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class StaffLogPageDTO extends PageDTO {

@Schema(description = "用户ID")
@NotNull(message = "用户ID不能为空")
private Long staffId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import com.liyz.cloud.common.feign.bo.RemotePage;
import com.liyz.cloud.common.feign.dto.PageDTO;
import com.liyz.cloud.common.feign.result.Result;
import com.liyz.cloud.service.staff.bo.info.StaffInfoBO;
import com.liyz.cloud.service.staff.constants.StaffConstants;
import com.liyz.cloud.service.staff.dto.log.StaffLogPageDTO;
import com.liyz.cloud.service.staff.vo.info.StaffInfoVO;
import com.liyz.cloud.service.staff.vo.log.StaffLoginLogVO;
import com.liyz.cloud.service.staff.vo.log.StaffLogoutLogVO;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -25,9 +29,17 @@ public interface StaffInfoFeignService {

@Operation(summary = "根据staffId获取用户信息")
@GetMapping( "/getByStaffId")
Result<StaffInfoBO> getByStaffId(@RequestParam("staffId") Long staffId);
Result<StaffInfoVO> getByStaffId(@RequestParam("staffId") Long staffId);

@Operation(summary = "分页查询员工信息")
@PostMapping("/page")
Result<RemotePage<StaffInfoBO>> page(@RequestBody PageDTO pageDTO);
Result<RemotePage<StaffInfoVO>> page(@RequestBody PageDTO pageDTO);

@Operation(summary = "分页查询员工登录信息")
@PostMapping("/login/page")
Result<RemotePage<StaffLoginLogVO>> loginPage(@Valid @RequestBody StaffLogPageDTO pageDTO);

@Operation(summary = "分页查询员工登出信息")
@PostMapping("/logout/page")
Result<RemotePage<StaffLogoutLogVO>> logoutPage(@Valid @RequestBody StaffLogPageDTO pageDTO);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.liyz.cloud.service.staff.bo.info;
package com.liyz.cloud.service.staff.vo.info;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
Expand All @@ -18,7 +18,7 @@
*/
@Getter
@Setter
public class StaffInfoBO implements Serializable {
public class StaffInfoVO implements Serializable {
@Serial
private static final long serialVersionUID = 477985923412638468L;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.liyz.cloud.service.staff.bo.log;
package com.liyz.cloud.service.staff.vo.log;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -17,7 +18,7 @@
*/
@Getter
@Setter
public class StaffLoginLogBO implements Serializable {
public class StaffLoginLogVO implements Serializable {
@Serial
private static final long serialVersionUID = -8978119199629210583L;

Expand All @@ -30,6 +31,7 @@ public class StaffLoginLogBO implements Serializable {
@Schema(description = "用户设备")
private Integer device;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@Schema(description = "用户登录时间")
private Date loginTime;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.liyz.cloud.service.staff.bo.log;
package com.liyz.cloud.service.staff.vo.log;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -17,7 +18,7 @@
*/
@Getter
@Setter
public class StaffLogoutLogBO implements Serializable {
public class StaffLogoutLogVO implements Serializable {
@Serial
private static final long serialVersionUID = 3070437801653890936L;

Expand All @@ -30,6 +31,7 @@ public class StaffLogoutLogBO implements Serializable {
@Schema(description = "用户设备")
private Integer device;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@Schema(description = "用户登录时间")
private Date logoutTime;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.liyz.cloud.service.staff.bo.role;
package com.liyz.cloud.service.staff.vo.role;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
Expand All @@ -16,7 +16,7 @@
*/
@Getter
@Setter
public class StaffRoleBO implements Serializable {
public class StaffRoleVO implements Serializable {
@Serial
private static final long serialVersionUID = -5019855188001537438L;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.liyz.cloud.service.staff.bo.role;
package com.liyz.cloud.service.staff.vo.role;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
Expand All @@ -16,7 +16,7 @@
*/
@Getter
@Setter
public class SystemAuthorityBO implements Serializable {
public class SystemAuthorityVO implements Serializable {
@Serial
private static final long serialVersionUID = -6116744036977982899L;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.liyz.cloud.service.staff.bo.role;
package com.liyz.cloud.service.staff.vo.role;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
Expand All @@ -16,7 +16,7 @@
*/
@Getter
@Setter
public class SystemRoleAuthorityBO implements Serializable {
public class SystemRoleAuthorityVO implements Serializable {
@Serial
private static final long serialVersionUID = 8328113920009535585L;

Expand Down
Loading

0 comments on commit 1961294

Please sign in to comment.