From 2691194cb3ea13de13aa5fda4af2f7ff78daa7b3 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期二, 08 七月 2025 15:26:06 +0800 Subject: [PATCH] 添加ResLog类 --- se-system/src/main/java/com/terra/system/entity/sys/ResLogEntity.java | 82 +++++++++++ se-system/src/main/resources/mapper/sys/ResLogMapper.xml | 72 ++++++++++ se-system/src/main/java/com/terra/system/mapper/sys/ResLogMapper.java | 32 ++++ se-system/src/main/java/com/terra/system/controller/sys/ResLogController.java | 147 +++++++++++++++++++++ se-system/src/main/java/com/terra/system/service/sys/ResLogService.java | 66 +++++++++ se-system/src/main/resources/mapper/sys/ResOpMapper.xml | 8 6 files changed, 404 insertions(+), 3 deletions(-) diff --git a/se-system/src/main/java/com/terra/system/controller/sys/ResLogController.java b/se-system/src/main/java/com/terra/system/controller/sys/ResLogController.java new file mode 100644 index 0000000..6f41731 --- /dev/null +++ b/se-system/src/main/java/com/terra/system/controller/sys/ResLogController.java @@ -0,0 +1,147 @@ +package com.terra.system.controller.sys; + +import com.terra.system.annotation.SysLog; +import com.terra.system.controller.all.BaseController; +import com.terra.system.entity.all.ResponseMsg; +import com.terra.system.entity.sys.ResLogEntity; +import com.terra.system.entity.sys.UserEntity; +import com.terra.system.service.sys.ResLogService; +import com.terra.system.service.sys.TokenService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; + +@SuppressWarnings("ALL") +@Api(tags = "杩愮淮绠$悊\\璧勬簮鏃ュ織") +@RestController +@RequestMapping("/resLog") +public class ResLogController extends BaseController { + @Autowired + ResLogService resLogService; + + @Autowired + TokenService tokenService; + + @SysLog() + @ApiOperation(value = "鏌ヨ璁板綍鏁�") + @ApiImplicitParams({ + @ApiImplicitParam(name = "resid", value = "璧勬簮ID", dataType = "Integer", paramType = "query", required = false, example = "") + }) + @GetMapping({"/selectCount"}) + public ResponseMsg<Integer> selectCount(Integer resid) { + try { + int count = resLogService.selectCount(resid); + + return success(count); + } catch (Exception ex) { + return fail(ex, -1); + } + } + + @SysLog() + @ApiOperation(value = "鍒嗛〉鏌ヨ") + @ApiImplicitParams({ + @ApiImplicitParam(name = "resid", value = "璧勬簮ID", dataType = "Integer", paramType = "query", example = ""), + @ApiImplicitParam(name = "pageSize", value = "姣忛〉鏉℃暟", dataType = "Integer", paramType = "query", example = "10"), + @ApiImplicitParam(name = "pageIndex", value = "鍒嗛〉鏁帮紙浠�1寮�濮嬶級", dataType = "Integer", paramType = "query", example = "1") + }) + @GetMapping(value = "/selectByPage") + public ResponseMsg<List<ResLogEntity>> selectByPage(Integer resid, Integer pageSize, Integer pageIndex) { + try { + if (pageSize < 1 || pageIndex < 1) { + return fail("姣忛〉椤垫暟鎴栧垎椤垫暟灏忎簬1", null); + } + + List<ResLogEntity> rs = resLogService.selectByPage(resid, pageSize, pageSize * (pageIndex - 1)); + + return success(rs); + } catch (Exception ex) { + return fail(ex, null); + } + } + + @SysLog() + @ApiOperation(value = "鍒嗛〉鏌ヨ骞惰繑鍥炶褰曟暟") + @ApiImplicitParams({ + @ApiImplicitParam(name = "resid", value = "璧勬簮ID", dataType = "Integer", paramType = "query", example = ""), + @ApiImplicitParam(name = "pageSize", value = "姣忛〉鏉℃暟", dataType = "Integer", paramType = "query", example = "10"), + @ApiImplicitParam(name = "pageIndex", value = "鍒嗛〉鏁帮紙浠�1寮�濮嬶級", dataType = "Integer", paramType = "query", example = "1") + }) + @GetMapping(value = "/selectByPageAndCount") + public ResponseMsg<List<ResLogEntity>> selectByPageAndCount(Integer resid, Integer pageSize, Integer pageIndex) { + try { + if (pageSize < 1 || pageIndex < 1) { + return fail("姣忛〉椤垫暟鎴栧垎椤垫暟灏忎簬1", null); + } + + int count = resLogService.selectCount(resid); + if (count == 0) { + return success(0, null); + } + + List<ResLogEntity> rs = resLogService.selectByPage(resid, pageSize, pageSize * (pageIndex - 1)); + + return success(count, rs); + } catch (Exception ex) { + return fail(ex, null); + } + } + + @SysLog() + @ApiOperation(value = "鏍规嵁ID鏌ヨ") + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "ID", dataType = "int", paramType = "query", example = "1") + }) + @GetMapping(value = "/selectById") + public ResponseMsg<ResLogEntity> selectById(int id) { + try { + ResLogEntity entity = resLogService.selectById(id); + + return success(entity); + } catch (Exception ex) { + return fail(ex, null); + } + } + + @SysLog() + @ApiOperation(value = "鍒犻櫎涓�鏉�") + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "ID", dataType = "Integer", paramType = "query", example = "1") + }) + @GetMapping(value = "/delete") + public ResponseMsg<Integer> delete(int id) { + try { + int count = resLogService.delete(id); + + return success(count); + } catch (Exception ex) { + return fail(ex, -1); + } + } + + @SysLog() + @ApiOperation(value = "鍒犻櫎澶氭潯") + @ApiImplicitParams({ + @ApiImplicitParam(name = "ids", value = "ID鏁扮粍", dataType = "Integer", paramType = "query", example = "1,2") + }) + @GetMapping(value = "/deletes") + public ResponseMsg<Integer> deletes(@RequestParam List<Integer> ids) { + try { + if (ids == null || ids.isEmpty()) { + return fail("id鏁扮粍涓嶈兘涓虹┖", -1); + } + + int count = resLogService.deletes(ids); + + return success(count); + } catch (Exception ex) { + return fail(ex, -1); + } + } +} diff --git a/se-system/src/main/java/com/terra/system/entity/sys/ResLogEntity.java b/se-system/src/main/java/com/terra/system/entity/sys/ResLogEntity.java new file mode 100644 index 0000000..d310a2b --- /dev/null +++ b/se-system/src/main/java/com/terra/system/entity/sys/ResLogEntity.java @@ -0,0 +1,82 @@ +package com.terra.system.entity.sys; + +import java.io.Serializable; +import java.sql.Timestamp; + +@SuppressWarnings("ALL") +public class ResLogEntity implements Serializable { + private static final long serialVersionUID = -766548673513600896L; + + private long id; + + private int resid; + + private int type; + + private String ip; + + private String url; + + private int createUser; + + private Timestamp createTime; + + public ResLogEntity() { + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public int getResid() { + return resid; + } + + public void setResid(int resid) { + this.resid = resid; + } + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + public String getIp() { + return ip; + } + + public void setIp(String ip) { + this.ip = ip; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public int getCreateUser() { + return createUser; + } + + public void setCreateUser(int createUser) { + this.createUser = createUser; + } + + public Timestamp getCreateTime() { + return createTime; + } + + public void setCreateTime(Timestamp createTime) { + this.createTime = createTime; + } +} diff --git a/se-system/src/main/java/com/terra/system/mapper/sys/ResLogMapper.java b/se-system/src/main/java/com/terra/system/mapper/sys/ResLogMapper.java new file mode 100644 index 0000000..bce23e3 --- /dev/null +++ b/se-system/src/main/java/com/terra/system/mapper/sys/ResLogMapper.java @@ -0,0 +1,32 @@ +package com.terra.system.mapper.sys; + +import com.terra.system.entity.sys.ResLogEntity; +import org.apache.ibatis.annotations.Mapper; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Mapper +@Repository +@SuppressWarnings("ALL") +public interface ResLogMapper { + public Integer selectCount(Integer resid); + + public List<ResLogEntity> selectByPage(Integer resid, Integer limit, Integer offset); + + public List<ResLogEntity> selectAll(); + + public ResLogEntity selectById(int id); + + public Integer insert(ResLogEntity entity); + + public Integer inserts(List<ResLogEntity> list); + + public Integer delete(int id); + + public Integer deletes(List<Integer> ids); + + public Integer update(ResLogEntity entity); + + public Integer updates(List<ResLogEntity> list); +} diff --git a/se-system/src/main/java/com/terra/system/service/sys/ResLogService.java b/se-system/src/main/java/com/terra/system/service/sys/ResLogService.java new file mode 100644 index 0000000..ceeb51b --- /dev/null +++ b/se-system/src/main/java/com/terra/system/service/sys/ResLogService.java @@ -0,0 +1,66 @@ +package com.terra.system.service.sys; + +import com.terra.system.entity.sys.ResLogEntity; +import com.terra.system.helper.StringHelper; +import com.terra.system.mapper.sys.ResLogMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@SuppressWarnings("ALL") +public class ResLogService implements ResLogMapper { + @Autowired + ResLogMapper resLogMapper; + + @Override + public Integer selectCount(Integer resid) { + return resLogMapper.selectCount(resid); + } + + @Override + public List<ResLogEntity> selectByPage(Integer resid, Integer limit, Integer offset) { + return resLogMapper.selectByPage(resid, limit, offset); + } + + @Override + public List<ResLogEntity> selectAll() { + return resLogMapper.selectAll(); + } + + @Override + public ResLogEntity selectById(int id) { + return resLogMapper.selectById(id); + } + + @Override + public Integer insert(ResLogEntity entity) { + return resLogMapper.insert(entity); + } + + @Override + public Integer inserts(List<ResLogEntity> list) { + return resLogMapper.inserts(list); + } + + @Override + public Integer delete(int id) { + return resLogMapper.delete(id); + } + + @Override + public Integer deletes(List<Integer> ids) { + return resLogMapper.deletes(ids); + } + + @Override + public Integer update(ResLogEntity entity) { + return resLogMapper.update(entity); + } + + @Override + public Integer updates(List<ResLogEntity> list) { + return resLogMapper.updates(list); + } +} diff --git a/se-system/src/main/resources/mapper/sys/ResLogMapper.xml b/se-system/src/main/resources/mapper/sys/ResLogMapper.xml new file mode 100644 index 0000000..7e9767c --- /dev/null +++ b/se-system/src/main/resources/mapper/sys/ResLogMapper.xml @@ -0,0 +1,72 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="com.terra.system.mapper.sys.ResLogMapper"> + <select id="selectCount" resultType="java.lang.Integer"> + select count(*) from lf.sys_res_log + <where> + <if test="resid != null"> + resid = #{resid} + </if> + </where> + </select> + + <select id="selectByPage" resultType="com.terra.system.entity.sys.ResLogEntity"> + select * from lf.sys_res_log + <where> + <if test="resid != null"> + resid = #{resid} + </if> + </where> + order by id desc + limit #{limit} offset #{offset} + </select> + + <select id="selectAll" resultType="com.terra.system.entity.sys.ResLogEntity"> + select * from lf.sys_res_log order by id desc; + </select> + + <select id="selectById" resultType="com.terra.system.entity.sys.ResLogEntity"> + select * from lf.sys_res_log where id = #{id} + </select> + + <insert id="insert" parameterType="com.terra.system.entity.sys.ResLogEntity"> + insert into lf.sys_res_log + (resid,type,ip,url,create_user,create_time) + values + (#{resid},#{type},#{ip},#{url},#{createUser},now()) + </insert> + + <insert id="inserts"> + insert into lf.sys_res_log + (resid,type,ip,url,create_user,create_time) + values + <foreach collection="list" item="item" index="index" separator=","> + (#{item.resid},#{item.type},#{item.ip},#{item.url},#{item.createUser},now()) + </foreach> + </insert> + + <delete id="delete"> + delete from lf.sys_res_log where id = #{id} + </delete> + + <delete id="deletes"> + delete from lf.sys_res_log where id in + <foreach item="id" collection="ids" index="index" open="(" separator="," close=")"> + #{id} + </foreach> + </delete> + + <update id="update"> + update lf.sys_res_log + set resid=#{resid},type=#{type},ip=#{ip},url=#{url} + where id=#{id} + </update> + + <update id="updates"> + <foreach collection="list" item="item" index="index" separator=";"> + update lf.sys_res_log + set resid=#{item.resid},type=#{item.type},ip=#{item.ip},url=#{item.url} + where id = #{item.id} + </foreach> + </update> +</mapper> \ No newline at end of file diff --git a/se-system/src/main/resources/mapper/sys/ResOpMapper.xml b/se-system/src/main/resources/mapper/sys/ResOpMapper.xml index 3db0ca7..1f01420 100644 --- a/se-system/src/main/resources/mapper/sys/ResOpMapper.xml +++ b/se-system/src/main/resources/mapper/sys/ResOpMapper.xml @@ -6,7 +6,7 @@ <where> 1 = 1 <if test="name != null"> - and upper(c.name) like #{name} + and upper(c.cn_name) like #{name} </if> <if test="type != null"> and a.type = #{type} @@ -21,11 +21,13 @@ </select> <select id="selectByPage" resultType="com.terra.system.entity.sys.ResOpEntity"> - select a.*,b.uname,c.name from lf.sys_res_op a inner join lf.sys_user b on a.userid = b.id inner join lf.sys_res c on a.resid=c.id + select a.*, b.uname, c.cn_name "name" + from lf.sys_res_op a + inner join lf.sys_user b on a.userid = b.id inner join lf.sys_res c on a.resid=c.id <where> 1 = 1 <if test="name != null"> - and upper(c.name) like #{name} + and upper(c.cn_name) like #{name} </if> <if test="type != null"> and a.type = #{type} -- Gitblit v1.9.3