From ba0ce5710f80a0259efa949182cbcb30b829839b Mon Sep 17 00:00:00 2001
From: Surpriseplus <845948745@qq.com>
Date: 星期四, 29 九月 2022 09:21:47 +0800
Subject: [PATCH] 权限

---
 src/main/java/com/lf/server/entity/data/AuthEntity.java         |   86 +++++++++
 src/main/java/com/lf/server/service/data/AuthService.java       |   66 +++++++
 src/main/java/com/lf/server/mapper/data/AuthMapper.java         |   91 ++++++++++
 src/main/java/com/lf/server/controller/data/AuthController.java |  196 +++++++++++++++++++++
 src/main/resources/mapper/data/AuthMapper.xml                   |   67 +++++++
 5 files changed, 505 insertions(+), 1 deletions(-)

diff --git a/src/main/java/com/lf/server/controller/data/AuthController.java b/src/main/java/com/lf/server/controller/data/AuthController.java
new file mode 100644
index 0000000..27a9202
--- /dev/null
+++ b/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);
+        }
+    }
+
+
+}
diff --git a/src/main/java/com/lf/server/entity/data/AuthEntity.java b/src/main/java/com/lf/server/entity/data/AuthEntity.java
index b380b2d..489f975 100644
--- a/src/main/java/com/lf/server/entity/data/AuthEntity.java
+++ b/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;
+    }
 }
diff --git a/src/main/java/com/lf/server/mapper/data/AuthMapper.java b/src/main/java/com/lf/server/mapper/data/AuthMapper.java
new file mode 100644
index 0000000..1071b43
--- /dev/null
+++ b/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();
+
+}
diff --git a/src/main/java/com/lf/server/service/data/AuthService.java b/src/main/java/com/lf/server/service/data/AuthService.java
new file mode 100644
index 0000000..93c372d
--- /dev/null
+++ b/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();
+    }
+}
diff --git a/src/main/resources/mapper/data/AuthMapper.xml b/src/main/resources/mapper/data/AuthMapper.xml
new file mode 100644
index 0000000..f669622
--- /dev/null
+++ b/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>
\ No newline at end of file

--
Gitblit v1.9.3