From 9d50f64b00f1129eea0030b8fd99623fbac78daa Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期三, 05 七月 2023 17:55:31 +0800 Subject: [PATCH] 开发资源表和资源日志表的操作接口 --- src/main/resources/mapper/sys/ResLogMapper.xml | 72 +++++++ /dev/null | 82 -------- src/main/java/com/moon/server/entity/sys/ResLogEntity.java | 85 ++++++++ src/main/java/com/moon/server/mapper/sys/ResLogMapper.java | 96 +++++++++ src/main/java/com/moon/server/service/sys/ResLogService.java | 69 ++++++ src/main/java/com/moon/server/controller/sys/ResLogController.java | 150 +++++++++++++++ 6 files changed, 472 insertions(+), 82 deletions(-) diff --git a/src/main/java/com/moon/server/controller/sys/ResLogController.java b/src/main/java/com/moon/server/controller/sys/ResLogController.java new file mode 100644 index 0000000..8997a26 --- /dev/null +++ b/src/main/java/com/moon/server/controller/sys/ResLogController.java @@ -0,0 +1,150 @@ +package com.moon.server.controller.sys; + +import com.moon.server.annotation.SysLog; +import com.moon.server.controller.all.BaseController; +import com.moon.server.entity.all.ResponseMsg; +import com.moon.server.entity.sys.ResLogEntity; +import com.moon.server.entity.sys.UserEntity; +import com.moon.server.service.sys.ResLogService; +import com.moon.server.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; + +/** + * 璧勬簮鏃ュ織 + * @author WWW + */ +@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/src/main/java/com/moon/server/entity/sys/ResLogEntity.java b/src/main/java/com/moon/server/entity/sys/ResLogEntity.java new file mode 100644 index 0000000..785017f --- /dev/null +++ b/src/main/java/com/moon/server/entity/sys/ResLogEntity.java @@ -0,0 +1,85 @@ +package com.moon.server.entity.sys; + +import java.io.Serializable; +import java.sql.Timestamp; + +/** + * 璧勬簮鏃ュ織 + * @author WWW + */ +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/src/main/java/com/moon/server/entity/sys/ResOpEntity.java b/src/main/java/com/moon/server/entity/sys/ResOpEntity.java deleted file mode 100644 index 5971972..0000000 --- a/src/main/java/com/moon/server/entity/sys/ResOpEntity.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.moon.server.entity.sys; - -import java.io.Serializable; -import java.sql.Timestamp; - -/** - * 璧勬簮鎿嶄綔 - * @author sws - * @date 2022-09-28 - */ - -public class ResOpEntity implements Serializable { - private static final long serialVersionUID = -7322438248126715583L; - - private int id; - - private String uname; - - private String name; - - private int resid; - - private int type; - - private String ip; - - private int userid; - - private Timestamp optime; - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getUname() { - return uname; - } - - public void setUname(String uname) { - this.uname = uname; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - 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 int getUserid() { - return userid; - } - - public void setUserid(int userid) { - this.userid = userid; - } - - public Timestamp getOptime() { - return optime; - } - - public void setOptime(Timestamp optime) { - this.optime = optime; - } -} diff --git a/src/main/java/com/moon/server/mapper/sys/ResLogMapper.java b/src/main/java/com/moon/server/mapper/sys/ResLogMapper.java new file mode 100644 index 0000000..aa841ed --- /dev/null +++ b/src/main/java/com/moon/server/mapper/sys/ResLogMapper.java @@ -0,0 +1,96 @@ +package com.moon.server.mapper.sys; + +import com.moon.server.entity.sys.ResLogEntity; +import org.apache.ibatis.annotations.Mapper; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * 璧勬簮鏃ュ織 + * @author WWW + */ +@Mapper +@Repository +public interface ResLogMapper { + /** + * 鏌ヨ璁板綍鏁� + * + * @param resid 璧勬簮ID + * @return 璁板綍鏁� + */ + public Integer selectCount(Integer resid); + + /** + * 鍒嗛〉鏌ヨ + * + * @param resid 璧勬簮ID + * @param limit 璁板綍鏁� + * @param offset 鍋忕Щ閲� + * @return 鍒楄〃 + */ + public List<ResLogEntity> selectByPage(Integer resid, Integer limit, Integer offset); + + /** + * 鏌ヨ鎵�鏈� + * + * @return + */ + public List<ResLogEntity> selectAll(); + + /** + * 鏍规嵁ID鏌ヨ + * + * @param id + * @return + */ + public ResLogEntity selectById(int id); + + /** + * 鎻掑叆涓�鏉� + * + * @param entity + * @return + */ + public Integer insert(ResLogEntity entity); + + /** + * 鎻掑叆澶氭潯 + * + * @param list + * @return + */ + public Integer inserts(List<ResLogEntity> list); + + /** + * 鍒犻櫎涓�鏉� + * + * @param id + * @return + */ + public Integer delete(int id); + + /** + * 鍒犻櫎澶氭潯 + * + * @param ids + * @return + */ + public Integer deletes(List<Integer> ids); + + /** + * 鏇存柊涓�鏉� + * + * @param entity + * @return + */ + public Integer update(ResLogEntity entity); + + /** + * 鏇存柊澶氭潯 + * + * @param list + * @return + */ + public Integer updates(List<ResLogEntity> list); +} diff --git a/src/main/java/com/moon/server/mapper/sys/ResOpMapper.java b/src/main/java/com/moon/server/mapper/sys/ResOpMapper.java deleted file mode 100644 index af94f0a..0000000 --- a/src/main/java/com/moon/server/mapper/sys/ResOpMapper.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.moon.server.mapper.sys; - -import com.moon.server.entity.sys.ResOpEntity; -import org.apache.ibatis.annotations.Mapper; -import org.springframework.web.bind.annotation.ResponseBody; - -import java.sql.Timestamp; -import java.util.List; - -/** - * 璧勬簮鎿嶄綔 - * @author sws - * @date 2022-09-28 - */ -@Mapper -@ResponseBody -public interface ResOpMapper { - /** - * 鏌ヨ璁板綍鏁� - * - * @param name - * @param type - * @param start - * @param end - * @return - */ - public Integer selectCount(String name, Integer type, Timestamp start, Timestamp end); - - /** - * 鍒嗛〉鏌ヨ - * - * @param name - * @param type - * @param start - * @param end - * @param limit - * @param offset - * @return - */ - public List<ResOpEntity> selectByPage(String name, Integer type, Timestamp start, Timestamp end, Integer limit, Integer offset); - - /** - * 鎻掑叆涓�鏉� - * - * @param resOpEntity - * @return - */ - public Integer insertResOp(ResOpEntity resOpEntity); - - /** - * 鎻掑叆澶氭潯 - * - * @param list - * @return - */ - public Integer insertResOps(List<ResOpEntity> list); - - /** - * 鍒犻櫎涓�鏉� - * - * @param id - * @return - */ - public Integer deleteResOp(int id); - - /** - * 鍒犻櫎澶氭潯 - * - * @param ids - * @return - */ - public Integer deleteResOps(List<Integer> ids); - - /** - * 鏇存柊涓�鏉� - * - * @param resOpEntity - * @return - */ - public Integer updateResOp(ResOpEntity resOpEntity); - - /** - * 鏌ヨ鍗曟潯鏁版嵁 - * - * @param id - * @return - */ - public ResOpEntity selectResOp(int id); - - /** - * 鏌ヨ鎵�鏈� - * - * @return - */ - public List<ResOpEntity> selectResOpAll(); -} diff --git a/src/main/java/com/moon/server/service/sys/ResLogService.java b/src/main/java/com/moon/server/service/sys/ResLogService.java new file mode 100644 index 0000000..fec97c3 --- /dev/null +++ b/src/main/java/com/moon/server/service/sys/ResLogService.java @@ -0,0 +1,69 @@ +package com.moon.server.service.sys; + +import com.moon.server.entity.sys.ResLogEntity; +import com.moon.server.helper.StringHelper; +import com.moon.server.mapper.sys.ResLogMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 璧勬簮鏃ュ織 + * @author WWW + */ +@Service +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/src/main/java/com/moon/server/service/sys/ResOpService.java b/src/main/java/com/moon/server/service/sys/ResOpService.java deleted file mode 100644 index 2ec8c0c..0000000 --- a/src/main/java/com/moon/server/service/sys/ResOpService.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.moon.server.service.sys; - -import com.moon.server.entity.sys.ResOpEntity; -import com.moon.server.helper.StringHelper; -import com.moon.server.mapper.sys.ResOpMapper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.sql.Timestamp; -import java.util.List; - -/** - * 璧勬簮鎿嶄綔琛� - * @author sws - * @date 2022-09-28 - */ -@Service -public class ResOpService implements ResOpMapper { - @Autowired - ResOpMapper resOpMapper; - - @Override - public Integer selectCount(String name, Integer type, Timestamp start, Timestamp end) { - name = StringHelper.getLikeUpperStr(name); - - return resOpMapper.selectCount(name, type, start, end); - } - - @Override - public List<ResOpEntity> selectByPage(String name, Integer type, Timestamp start, Timestamp end, Integer limit, Integer offset) { - name = StringHelper.getLikeUpperStr(name); - - return resOpMapper.selectByPage(name, type, start, end, limit, offset); - } - - @Override - public Integer insertResOp(ResOpEntity resOpEntity) { - return resOpMapper.insertResOp(resOpEntity); - } - - @Override - public Integer insertResOps(List<ResOpEntity> resOpEntity) { - return resOpMapper.insertResOps(resOpEntity); - } - - @Override - public Integer deleteResOp(int id) { - return resOpMapper.deleteResOp(id); - } - - @Override - public Integer deleteResOps(List<Integer> ids) { - return resOpMapper.deleteResOps(ids); - } - - @Override - public Integer updateResOp(ResOpEntity resOpEntity) { - return resOpMapper.updateResOp(resOpEntity); - } - - @Override - public ResOpEntity selectResOp(int id) { - return resOpMapper.selectResOp(id); - } - - @Override - public List<ResOpEntity> selectResOpAll() { - return resOpMapper.selectResOpAll(); - } -} diff --git a/src/main/resources/mapper/sys/ResLogMapper.xml b/src/main/resources/mapper/sys/ResLogMapper.xml new file mode 100644 index 0000000..9c67b0e --- /dev/null +++ b/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.moon.server.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.moon.server.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.moon.server.entity.sys.ResLogEntity"> + select * from lf.sys_res_log order by id desc; + </select> + + <select id="selectById" resultType="com.moon.server.entity.sys.ResLogEntity"> + select * from lf.sys_res_log where id = #{id} + </select> + + <insert id="insert" parameterType="com.moon.server.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/src/main/resources/mapper/sys/ResOpMapper.xml b/src/main/resources/mapper/sys/ResOpMapper.xml deleted file mode 100644 index 797065b..0000000 --- a/src/main/resources/mapper/sys/ResOpMapper.xml +++ /dev/null @@ -1,82 +0,0 @@ -<?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.moon.server.mapper.sys.ResOpMapper"> - <select id="selectCount" resultType="java.lang.Integer"> - select count(*) 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} - </if> - <if test="type != null"> - and a.type = #{type} - </if> - <if test="start != null"> - and a.optime >= #{start} - </if> - <if test="end != null"> - and a.optime <= #{end} - </if> - </where> - </select> - - <select id="selectByPage" resultType="com.moon.server.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 - <where> - 1 = 1 - <if test="name != null"> - and upper(c.name) like #{name} - </if> - <if test="type != null"> - and a.type = #{type} - </if> - <if test="start != null"> - and a.optime >= #{start} - </if> - <if test="end != null"> - and a.optime <= #{end} - </if> - </where> - order by a.id desc - limit #{limit} offset #{offset} - </select> - - <select id="selectResOpAll" resultType="com.moon.server.entity.sys.ResOpEntity"> - select * from lf.sys_res_op order by id desc; - </select> - - <select id="selectResOp" resultType="com.moon.server.entity.sys.ResOpEntity"> - select * from lf.sys_res_op where id = #{id} - </select> - - <insert id="insertResOp" parameterType="com.moon.server.entity.sys.ResOpEntity"> - insert into lf.sys_res_op - (resid,type,ip,userid,optime) - values - (#{resid},#{type},#{ip},#{userid},now()); - </insert> - - <insert id="insertResOps"> - insert into lf.sys_res_op - (resid,type,ip,userid,optime) - values - <foreach collection="list" item="item" index="index" separator="," > - (#{item.resid},#{item.type},#{item.ip},#{item.userid},now()); - </foreach> - </insert> - - <delete id="deleteResOp"> - delete from lf.sys_res_op where id = #{id} - </delete> - - <delete id="deleteResOps"> - delete from lf.sys_res_op where id in - <foreach item="id" collection="ids" index="index" open="(" separator="," close=")"> - #{id} - </foreach> - </delete> - - <update id="updateResOp"> - update lf.sys_res_op set resid=#{resid},type=#{type},ip=#{ip},userid=#{userid},optime=now() where id=#{id} - </update> -</mapper> \ No newline at end of file -- Gitblit v1.9.3