src/main/java/com/lf/server/controller/data/AuthController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/lf/server/entity/data/AuthEntity.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/lf/server/mapper/data/AuthMapper.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/lf/server/service/data/AuthService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/mapper/data/AuthMapper.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/lf/server/controller/data/AuthController.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,196 @@ package com.lf.server.controller.data; import com.lf.server.controller.BaseController; import com.lf.server.entity.all.ResponseMsg; import com.lf.server.entity.data.AuthEntity; import com.lf.server.entity.data.LoginEntity; import com.lf.server.service.data.AuthService; 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 java.util.List; /** * æé表 * @author SWS * @date 2022-09.28 */ @Api(tags = "æé表") @RestController @RequestMapping("/auth") public class AuthController extends BaseController { @Autowired AuthService authService; @ApiOperation(value = "æ¥è¯¢è®°å½æ°") @ApiImplicitParams({ @ApiImplicitParam(name = "name", value = "åç§°", dataType = "String", paramType = "query", required = false, example = "sys_auth") }) @GetMapping({"/selectCount"}) public ResponseMsg<Integer> selectCount(String name) { try { int count = authService.selectCount(name); return success(count); } catch (Exception ex) { return fail(ex.getMessage(), -1); } } @ApiOperation(value = "å页æ¥è¯¢") @ApiImplicitParams({ @ApiImplicitParam(name = "name", value = "åç§°", dataType = "String", paramType = "query", example = "sys_auth"), @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<AuthEntity>> selectByPage(String name, Integer pageSize, Integer pageIndex) { try { if (pageSize < 1 || pageIndex < 1) { return fail("æ¯é¡µé¡µæ°æå页æ°å°äº1", null); } List<AuthEntity> rs = authService.selectByPage(name, pageSize, pageSize * (pageIndex - 1)); return success(rs); } catch (Exception ex) { return fail(ex.getMessage(), null); } } @ApiOperation(value = "å页æ¥è¯¢å¹¶è¿åè®°å½æ°") @ApiImplicitParams({ @ApiImplicitParam(name = "name", value = "åç§°", dataType = "String", paramType = "query", example = "1"), @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<AuthEntity>> selectByPageAndCount(String name, Integer pageSize, Integer pageIndex) { try { if (pageSize < 1 || pageIndex < 1) { return fail("æ¯é¡µé¡µæ°æå页æ°å°äº1", null); } int count = authService.selectCount(name); if (count == 0) { return success(0, null); } List<AuthEntity> rs = authService.selectByPage(name, pageSize, pageSize * (pageIndex - 1)); return success(count, rs); } catch (Exception ex) { return fail(ex.getMessage(), null); } } @ApiOperation(value = "æå ¥åå ¸") @ApiImplicitParams({ @ApiImplicitParam(name = "authEntity", value = "åå ¸å®ä½ç±»", dataType = "com.lf.server.entity.data.AuthEntity", paramType = "body", example = "") }) @PostMapping(value = "/insertAuth", produces = "application/json; charset=UTF-8") public ResponseMsg<Integer> insertAuth(AuthEntity authEntity) { try { int count = authService.insertAuth(authEntity); return success(count); } catch (Exception ex) { return fail(ex.getMessage(), -1); } } @ApiOperation(value = "æå ¥å¤æ¡åå ¸") @ApiImplicitParams({ @ApiImplicitParam(name = "authEntity", value = "åå ¸å®ä½ç±»éå", dataType = "List<AuthEntity>", paramType = "body", example = "") }) @PostMapping(value = "/insertAuths", produces = "application/json; charset=UTF-8") public ResponseMsg<Integer> insertAuths(@RequestBody List<AuthEntity> authEntity) { try { int count = authService.insertAuths(authEntity); return success(count); } catch (Exception ex) { return fail(ex.getMessage(), -1); } } @ApiOperation(value = "å é¤ä¸æ¡åå ¸") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "åå ¸ID", dataType = "Integer", paramType = "query", example = "1") }) @GetMapping(value = "/deleteAuth") public ResponseMsg<Integer> deleteAuth(int id) { try { int count = authService.deleteAuth(id); return success(count); } catch (Exception ex) { return fail(ex.getMessage(), -1); } } @ApiOperation(value = "å é¤å¤æ¡åå ¸") @ApiImplicitParams({ @ApiImplicitParam(name = "ids", value = "åå ¸IDéå", dataType = "List<Integer>", paramType = "query", example = "1,2") }) @GetMapping(value = "/deleteAuths") public ResponseMsg<Integer> deleteAuths(@RequestParam List<Integer> ids) { try { if (ids == null || ids.isEmpty()) { return fail("idæ°ç»ä¸è½ä¸ºç©º", -1); } int count = authService.deleteAuths(ids); return success(count); } catch (Exception ex) { return fail(ex.getMessage(), -1); } } @ApiOperation(value = "æ´æ°ä¸æ¡åå ¸") @ApiImplicitParams({ @ApiImplicitParam(name = "loginEntity", value = "åå ¸IDéå", dataType = "LoginEntity", paramType = "body", example = "") }) @ResponseBody @PostMapping(value = "/updateAuth", produces = "application/json; charset=UTF-8") public ResponseMsg<Integer> updateAuth(AuthEntity authEntity) { try { int count = authService.updateAuth(authEntity); return success(count); } catch (Exception ex) { return fail(ex.getMessage(), -1); } } @ApiOperation(value = "æ ¹æ®IDæ¥è¯¢åå ¸") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "åå ¸ID", dataType = "Integer", paramType = "query", example = "1") }) @GetMapping(value = "/selectAuth") public ResponseMsg<AuthEntity> selectAuth(int id) { try { AuthEntity authEntity = authService.selectAuth(id); return success(authEntity); } catch (Exception ex) { return fail(ex.getMessage(), null); } } @ApiOperation(value = "æ¥è¯¢ææåå ¸") @GetMapping(value = "/selectAuthAll") public ResponseMsg<List<AuthEntity>> selectAuthAll() { try { List<AuthEntity> list = authService.selectAuthAll(); return success(list); } catch (Exception ex) { return fail(ex.getMessage(), null); } } } src/main/java/com/lf/server/entity/data/AuthEntity.java
@@ -1,10 +1,94 @@ package com.lf.server.entity.data; import java.io.Serializable; import java.sql.Timestamp; /** * @author user * æé * @author sws * @date 2022-09-28 */ public class AuthEntity implements Serializable { private static final long serialVersionUID = 2590447372444367285L; private int id; private String name; private String tag; private int createUser; private Timestamp createTime; private int updateUser; private Timestamp updateTime; private String bak; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getTag() { return tag; } public void setTag(String tag) { this.tag = tag; } 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; } public int getUpdateUser() { return updateUser; } public void setUpdateUser(int updateUser) { this.updateUser = updateUser; } public Timestamp getUpdateTime() { return updateTime; } public void setUpdateTime(Timestamp updateTime) { this.updateTime = updateTime; } public String getBak() { return bak; } public void setBak(String bak) { this.bak = bak; } } src/main/java/com/lf/server/mapper/data/AuthMapper.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,91 @@ package com.lf.server.mapper.data; import com.lf.server.entity.data.AuthEntity; import com.lf.server.entity.data.LoginEntity; import org.apache.ibatis.annotations.Mapper; import org.springframework.web.bind.annotation.ResponseBody; import java.util.List; /** * æé表 * @author */ @Mapper @ResponseBody public interface AuthMapper { /** * æ ¹æ®è¡¨åæ¥è¯¢è®°å½æ° * * @param name åç§° * @return è®°å½æ° */ public Integer selectCount(String name); /** * æ ¹æ®è¡¨åå页æ¥è¯¢ * * @param name åç§° * @param limit è®°å½è¡¨ * @param offset åç§»é * @return å表 */ public List<AuthEntity> selectByPage(String name, Integer limit, Integer offset); /** * æ·»å æ°æ® * * @param authEntity * @return */ public Integer insertAuth(AuthEntity authEntity); /** * æ¹éæ·»å * * @param authEntity * @return */ public Integer insertAuths(List<AuthEntity> authEntity); /** * åªé¤æ°æ® * * @param id * @return */ public Integer deleteAuth(int id); /** * æ¹éå é¤ * * @param ids * @return */ public Integer deleteAuths(List<Integer> ids); /** * ä¿®æ¹æ°æ® * * @param authEntity * @return */ public Integer updateAuth(AuthEntity authEntity); /** * æ¥è¯¢åæ¡æ°æ® * * @param id * @return */ public AuthEntity selectAuth(int id); /** * æ¥è¯¢å ¨é¨æ°æ® * * @return */ public List<AuthEntity> selectAuthAll(); } src/main/java/com/lf/server/service/data/AuthService.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,66 @@ package com.lf.server.service.data; import com.lf.server.entity.data.AuthEntity; import com.lf.server.entity.data.LoginEntity; import com.lf.server.mapper.data.AuthMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; /** * æé表 * @author sws * @date 2022-09-28 */ @Service public class AuthService implements AuthMapper { @Autowired AuthMapper authMapper; @Override public Integer selectCount(String name) { return authMapper.selectCount(name); } @Override public List<AuthEntity> selectByPage(String name, Integer limit, Integer offset) { return authMapper.selectByPage(name, limit, offset); } @Override public Integer insertAuth(AuthEntity authEntity) { return authMapper.insertAuth(authEntity); } @Override public Integer insertAuths(List<AuthEntity> authEntity) { return authMapper.insertAuths(authEntity); } @Override public Integer deleteAuth(int id) { return authMapper.deleteAuth(id); } @Override public Integer deleteAuths(List<Integer> ids) { return authMapper.deleteAuths(ids); } @Override public Integer updateAuth(AuthEntity authEntity) { return authMapper.updateAuth(authEntity); } @Override public AuthEntity selectAuth(int id) { return authMapper.selectAuth(id); } @Override public List<AuthEntity> selectAuthAll() { return authMapper.selectAuthAll(); } } src/main/resources/mapper/data/AuthMapper.xml
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,67 @@ <?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.lf.server.mapper.data.AuthMapper"> <!-- ç»è®¡è¡æ° --> <select id="selectCount" resultType="java.lang.Integer" parameterType="java.lang.String"> select count(*) from lf.sys_auth <where> <if test="name != null"> name = #{name} </if> </where> </select> <!-- å页æ¥è¯¢ --> <select id="selectByPage" resultType="com.lf.server.entity.data.AuthEntity"> select * from lf.sys_auth <where> <if test="name != null"> name = #{name} </if> </where> limit #{limit} offset #{offset} </select> <select id="selectAuthAll" resultType="com.lf.server.entity.data.AuthEntity"> select * from lf.sys_auth </select> <select id="selectAuth" resultType="com.lf.server.entity.data.AuthEntity"> select * from lf.sys_auth where id = #{id} </select> <insert id="insertAuth" parameterType="com.lf.server.entity.data.AuthEntity"> insert into lf.sys_auth (name,tag,create_user,create_time,bak) values (#{name},#{tag},#{createUser},now(),#{bak}); </insert> <insert id="insertAuths" > insert into lf.sys_auth (name,tag,create_user,create_time,bak) values <foreach collection="list" item="item" index="index" separator="," > (#{item.name},#{item.tag},#{item.createUser},now(),#{item.bak}) </foreach> </insert> <delete id="deleteAuth" > delete from lf.sys_auth where id = #{id} </delete> <delete id="deleteAuths" > delete from lf.sys_auth where id in <foreach item="ids" collection="list" index="index" open="(" separator="," close=")"> #{ids} </foreach> </delete> <update id="updateAuth"> update lf.sys_auth set name=#{name},tag=#{tag},update_user=#{id},update_time=now(),bak=#{bak} where id=#{id} </update> </mapper>