mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-08 02:04:04 +08:00
管理员日志查询
This commit is contained in:
parent
c65013f266
commit
67c3578609
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (C) 2023 杭州白书科技有限公司
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package xyz.playedu.api.controller.backend;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
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 xyz.playedu.api.BCtx;
|
||||
import xyz.playedu.api.annotation.Log;
|
||||
import xyz.playedu.api.bus.BackendBus;
|
||||
import xyz.playedu.api.constant.BusinessType;
|
||||
import xyz.playedu.api.domain.*;
|
||||
import xyz.playedu.api.service.AdminLogService;
|
||||
import xyz.playedu.api.service.AdminUserService;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
import xyz.playedu.api.types.paginate.AdminLogPaginateFiler;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequestMapping("/backend/v1/admin/log")
|
||||
public class AdminLogController {
|
||||
|
||||
@Autowired private AdminLogService adminLogService;
|
||||
|
||||
@Autowired private AdminUserService adminUserService;
|
||||
|
||||
@Autowired private BackendBus backendBus;
|
||||
|
||||
@GetMapping("/index")
|
||||
@Log(title = "管理员日志-列表", businessType = BusinessType.GET)
|
||||
public JsonResponse index(@RequestParam HashMap<String, Object> params) {
|
||||
Integer page = MapUtils.getInteger(params, "page", 1);
|
||||
Integer size = MapUtils.getInteger(params, "size", 10);
|
||||
String sortField = MapUtils.getString(params, "sort_field");
|
||||
String sortAlgo = MapUtils.getString(params, "sort_algo");
|
||||
|
||||
Integer adminId = MapUtils.getInteger(params, "admin_id");
|
||||
String module = MapUtils.getString(params, "module");
|
||||
String title = MapUtils.getString(params, "title");
|
||||
Integer opt = MapUtils.getInteger(params, "opt");
|
||||
|
||||
AdminLogPaginateFiler filter = new AdminLogPaginateFiler();
|
||||
if(backendBus.isSuperAdmin()){
|
||||
filter.setAdminId(adminId);
|
||||
}else {
|
||||
filter.setAdminId(BCtx.getId());
|
||||
}
|
||||
filter.setModule(module);
|
||||
filter.setTitle(title);
|
||||
filter.setOpt(opt);
|
||||
filter.setSortField(sortField);
|
||||
filter.setSortAlgo(sortAlgo);
|
||||
|
||||
PaginationResult<AdminLog> result = adminLogService.paginate(page, size, filter);
|
||||
|
||||
Map<Integer, String> adminUserMap = adminUserService.chunks(result.getData().stream().map(AdminLog::getAdminId).toList())
|
||||
.stream().collect(Collectors.toMap(AdminUser::getId, AdminUser::getName));
|
||||
|
||||
result.getData().forEach(adminLog -> {
|
||||
adminLog.setAdminName(adminUserMap.get(adminLog.getAdminId()));
|
||||
});
|
||||
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("data", result.getData());
|
||||
data.put("total", result.getTotal());
|
||||
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
}
|
@ -40,6 +40,9 @@ public class AdminLog implements Serializable {
|
||||
@JsonProperty("admin_id")
|
||||
private Integer adminId;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String adminName;
|
||||
|
||||
/** 模块 */
|
||||
private String module;
|
||||
|
||||
|
@ -20,6 +20,9 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import xyz.playedu.api.domain.AdminLog;
|
||||
import xyz.playedu.api.types.paginate.AdminLogPaginateFiler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
@ -27,4 +30,8 @@ import xyz.playedu.api.domain.AdminLog;
|
||||
* @createDate 2023-02-17 15:40:31 @Entity xyz.playedu.api.domain.AdminLog
|
||||
*/
|
||||
@Mapper
|
||||
public interface AdminLogMapper extends BaseMapper<AdminLog> {}
|
||||
public interface AdminLogMapper extends BaseMapper<AdminLog> {
|
||||
List<AdminLog> paginate(AdminLogPaginateFiler filer);
|
||||
|
||||
Long paginateCount(AdminLogPaginateFiler filer);
|
||||
}
|
||||
|
@ -20,6 +20,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import xyz.playedu.api.domain.AdminLog;
|
||||
import xyz.playedu.api.types.paginate.AdminLogPaginateFiler;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
@ -27,4 +29,6 @@ import xyz.playedu.api.domain.AdminLog;
|
||||
* @createDate 2023-02-17 15:40:31
|
||||
*/
|
||||
@Service
|
||||
public interface AdminLogService extends IService<AdminLog> {}
|
||||
public interface AdminLogService extends IService<AdminLog> {
|
||||
PaginationResult<AdminLog> paginate(int page, int size, AdminLogPaginateFiler filter);
|
||||
}
|
||||
|
@ -22,6 +22,8 @@ import org.springframework.stereotype.Service;
|
||||
import xyz.playedu.api.domain.AdminLog;
|
||||
import xyz.playedu.api.mapper.AdminLogMapper;
|
||||
import xyz.playedu.api.service.AdminLogService;
|
||||
import xyz.playedu.api.types.paginate.AdminLogPaginateFiler;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
@ -30,4 +32,16 @@ import xyz.playedu.api.service.AdminLogService;
|
||||
*/
|
||||
@Service
|
||||
public class AdminLogServiceImpl extends ServiceImpl<AdminLogMapper, AdminLog>
|
||||
implements AdminLogService {}
|
||||
implements AdminLogService {
|
||||
@Override
|
||||
public PaginationResult<AdminLog> paginate(int page, int size, AdminLogPaginateFiler filter) {
|
||||
filter.setPageStart((page - 1) * size);
|
||||
filter.setPageSize(size);
|
||||
|
||||
PaginationResult<AdminLog> pageResult = new PaginationResult<>();
|
||||
pageResult.setData(getBaseMapper().paginate(filter));
|
||||
pageResult.setTotal(getBaseMapper().paginateCount(filter));
|
||||
|
||||
return pageResult;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) 2023 杭州白书科技有限公司
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package xyz.playedu.api.types.paginate;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class AdminLogPaginateFiler {
|
||||
|
||||
private Integer adminId;
|
||||
|
||||
private String module;
|
||||
|
||||
private String title;
|
||||
|
||||
private Integer opt;
|
||||
|
||||
private String sortField;
|
||||
|
||||
private String sortAlgo;
|
||||
|
||||
private Integer pageStart;
|
||||
|
||||
private Integer pageSize;
|
||||
}
|
@ -26,4 +26,64 @@
|
||||
opt,method,request_method,url,param,result,
|
||||
ip,ip_area,error_msg,created_at
|
||||
</sql>
|
||||
|
||||
<select id="paginate" resultType="xyz.playedu.api.domain.AdminLog">
|
||||
SELECT `admin_logs`.*
|
||||
FROM `admin_logs`
|
||||
<where>
|
||||
<if test="adminId != null">
|
||||
AND `admin_logs`.`admin_id` = #{adminId}
|
||||
</if>
|
||||
<if test="module != null and module != ''">
|
||||
AND `admin_logs`.`module` LIKE concat('%',#{module},'%')
|
||||
</if>
|
||||
<if test="title != null and title != ''">
|
||||
AND `admin_logs`.`title` LIKE concat('%',#{title},'%')
|
||||
</if>
|
||||
<if test="opt != null">
|
||||
AND `admin_logs`.`opt` = #{opt}
|
||||
</if>
|
||||
</where>
|
||||
|
||||
<if test="sortAlgo == 'asc'">
|
||||
<choose>
|
||||
<when test="sortField == 'created_at'">
|
||||
ORDER BY `admin_logs`.`created_at` ASC
|
||||
</when>
|
||||
<otherwise>
|
||||
ORDER BY `admin_logs`.`id` ASC
|
||||
</otherwise>
|
||||
</choose>
|
||||
</if>
|
||||
<if test="sortAlgo != 'asc'">
|
||||
<choose>
|
||||
<when test="sortField == 'created_at'">
|
||||
ORDER BY `admin_logs`.`created_at` DESC
|
||||
</when>
|
||||
<otherwise>
|
||||
ORDER BY `admin_logs`.`id` DESC
|
||||
</otherwise>
|
||||
</choose>
|
||||
</if>
|
||||
LIMIT #{pageStart}, #{pageSize};
|
||||
</select>
|
||||
|
||||
<select id="paginateCount" resultType="java.lang.Long">
|
||||
SELECT count(1)
|
||||
FROM `admin_logs`
|
||||
<where>
|
||||
<if test="adminId != null">
|
||||
AND `admin_logs`.`admin_id` = #{adminId}
|
||||
</if>
|
||||
<if test="module != null and module != ''">
|
||||
AND `admin_logs`.`module` LIKE concat('%',#{module},'%')
|
||||
</if>
|
||||
<if test="title != null and title != ''">
|
||||
AND `admin_logs`.`title` LIKE concat('%',#{title},'%')
|
||||
</if>
|
||||
<if test="opt != null">
|
||||
AND `admin_logs`.`opt` = #{opt}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
||||
|
Loading…
x
Reference in New Issue
Block a user