管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2022-11-15 f19c018440a835f4871a8cb9de8334ba8dd922ca
src/main/java/com/lf/server/controller/sys/MenuAuthController.java
@@ -1,10 +1,13 @@
package com.lf.server.controller.sys;
import com.lf.server.aspect.SysLog;
import com.lf.server.annotation.SysLog;
import com.lf.server.controller.all.BaseController;
import com.lf.server.entity.all.ResponseMsg;
import com.lf.server.entity.sys.MenuAuthEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.service.all.PermsService;
import com.lf.server.service.sys.MenuAuthService;
import com.lf.server.service.sys.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
@@ -12,6 +15,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
@@ -24,6 +28,12 @@
public class MenuAuthController extends BaseController {
    @Autowired
    MenuAuthService menuAuthService;
    @Autowired
    TokenService tokenService;
    @Autowired
    PermsService permsService;
    @SysLog()
    @ApiOperation(value = "查询记录数")
@@ -89,6 +99,34 @@
    }
    @SysLog()
    @ApiOperation(value = "根据角色ID+菜单ID分页查询并返回记录数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleid", value = "角色ID", dataType = "Integer", paramType = "query", example = "1"),
            @ApiImplicitParam(name = "menuid", value = "菜单ID", dataType = "Integer", 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 = "/selectByPageForRole")
    public ResponseMsg<List<MenuAuthEntity>> selectByPageForRole(Integer roleid, Integer menuid, Integer pageSize, Integer pageIndex) {
        try {
            if (pageSize < 1 || pageIndex < 1) {
                return fail("每页页数或分页数小于1", null);
            }
            int count = menuAuthService.selectCountForRole(roleid,  menuid);
            if (count == 0) {
                return success(0, null);
            }
            List<MenuAuthEntity> rs = menuAuthService.selectByPageForRole(roleid,  menuid, pageSize, pageSize * (pageIndex - 1));
            return success(count, rs);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
    @SysLog()
    @ApiOperation(value = "查询所有")
    @GetMapping(value = "/selectAll")
    public ResponseMsg<List<MenuAuthEntity>> selectAll() {
@@ -118,14 +156,22 @@
    }
    @SysLog()
    @ApiOperation(value = "添加数据")
    @ApiOperation(value = "插入一条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "entity", value = "实体类", dataType = "MenuAuthEntity", paramType = "body")
    })
    @PostMapping(value = "/insert", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> insert(@RequestBody MenuAuthEntity entity) {
    public ResponseMsg<Integer> insert(@RequestBody MenuAuthEntity entity, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                entity.setCreateUser(ue.getId());
            }
            int count = menuAuthService.insert(entity);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -134,14 +180,24 @@
    }
    @SysLog()
    @ApiOperation(value = "批量添加")
    @ApiOperation(value = "插入多条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "list", value = "实体类集合", dataType = "MenuAuthEntity", paramType = "body")
    })
    @PostMapping(value = "/inserts", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> inserts(@RequestBody List<MenuAuthEntity> list) {
    public ResponseMsg<Integer> inserts(@RequestBody List<MenuAuthEntity> list, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                for (MenuAuthEntity entity : list) {
                    entity.setCreateUser(ue.getId());
                }
            }
            int count = menuAuthService.inserts(list);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -150,7 +206,7 @@
    }
    @SysLog()
    @ApiOperation(value = "刪除数据")
    @ApiOperation(value = "删除一条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", dataType = "Integer", paramType = "query", example = "1")
    })
@@ -158,6 +214,9 @@
    public ResponseMsg<Integer> delete(int id) {
        try {
            int count = menuAuthService.delete(id);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -166,7 +225,7 @@
    }
    @SysLog()
    @ApiOperation(value = "批量删除")
    @ApiOperation(value = "删除多条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "ID数组", dataType = "Integer", paramType = "query", example = "1,2")
    })
@@ -178,6 +237,9 @@
            }
            int count = menuAuthService.deletes(ids);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -186,15 +248,23 @@
    }
    @SysLog()
    @ApiOperation(value = "修改数据")
    @ApiOperation(value = "更新一条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "entity", value = "实体类", dataType = "MenuAuthEntity", paramType = "body")
    })
    @ResponseBody
    @PostMapping(value = "/update", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> update(@RequestBody MenuAuthEntity entity) {
    public ResponseMsg<Integer> update(@RequestBody MenuAuthEntity entity, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                entity.setUpdateUser(ue.getId());
            }
            int count = menuAuthService.update(entity);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {
@@ -203,15 +273,25 @@
    }
    @SysLog()
    @ApiOperation(value = "批量修改")
    @ApiOperation(value = "更新多条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "list", value = "实体类集合", dataType = "MenuAuthEntity", paramType = "body")
    })
    @ResponseBody
    @PostMapping(value = "/updates", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> updates(@RequestBody List<MenuAuthEntity> list) {
    public ResponseMsg<Integer> updates(@RequestBody List<MenuAuthEntity> list, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                for (MenuAuthEntity entity : list) {
                    entity.setUpdateUser(ue.getId());
                }
            }
            int count = menuAuthService.updates(list);
            if (count > 0) {
                permsService.clearPermsCache();
            }
            return success(count);
        } catch (Exception ex) {