管道基础大数据平台系统开发-【后端】-Server
Surpriseplus
2022-09-29 ba0ce5710f80a0259efa949182cbcb30b829839b
权限
已添加4个文件
已修改1个文件
506 ■■■■■ 文件已修改
src/main/java/com/lf/server/controller/data/AuthController.java 196 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/entity/data/AuthEntity.java 86 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/mapper/data/AuthMapper.java 91 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/data/AuthService.java 66 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/data/AuthMapper.xml 67 ●●●●● 补丁 | 查看 | 原始文档 | 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>