管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2022-10-11 9c5c93a36294b3f14536689d548928196c367de8
src/main/java/com/lf/server/controller/sys/BlacklistController.java
@@ -4,7 +4,9 @@
import com.lf.server.controller.all.BaseController;
import com.lf.server.entity.all.ResponseMsg;
import com.lf.server.entity.sys.BlacklistEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.service.sys.BlacklistService;
import com.lf.server.service.sys.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
@@ -12,6 +14,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
@@ -25,15 +28,19 @@
    @Autowired
    BlacklistService blacklistService;
    @Autowired
    TokenService tokenService;
    @SysLog()
    @ApiOperation(value = "查询记录数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ip", value = "IP地址", dataType = "String", paramType = "query", required = false, example = "")
            @ApiImplicitParam(name = "ip", value = "IP地址", dataType = "String", paramType = "query", required = false, example = "192."),
            @ApiImplicitParam(name = "type", value = "类别", dataType = "Integer", paramType = "query", example = "1")
    })
    @GetMapping({"/selectCount"})
    public ResponseMsg<Integer> selectCount(String ip) {
    public ResponseMsg<Integer> selectCount(String ip, Integer type) {
        try {
            int count = blacklistService.selectCount(ip);
            int count = blacklistService.selectCount(ip, type);
            return success(count);
        } catch (Exception ex) {
@@ -44,18 +51,19 @@
    @SysLog()
    @ApiOperation(value = "分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ip", value = "IP地址", dataType = "String", paramType = "query", example = ""),
            @ApiImplicitParam(name = "ip", value = "IP地址", dataType = "String", paramType = "query", example = "192."),
            @ApiImplicitParam(name = "type", value = "类别", 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 = "/selectByPage")
    public ResponseMsg<List<BlacklistEntity>> selectByPage(String ip, Integer pageSize, Integer pageIndex) {
    public ResponseMsg<List<BlacklistEntity>> selectByPage(String ip, Integer type, Integer pageSize, Integer pageIndex) {
        try {
            if (pageSize < 1 || pageIndex < 1) {
                return fail("每页页数或分页数小于1", null);
            }
            List<BlacklistEntity> rs = blacklistService.selectByPage(ip, pageSize, pageSize * (pageIndex - 1));
            List<BlacklistEntity> rs = blacklistService.selectByPage(ip, type, pageSize, pageSize * (pageIndex - 1));
            return success(rs);
        } catch (Exception ex) {
@@ -66,21 +74,22 @@
    @SysLog()
    @ApiOperation(value = "分页查询并返回记录数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ip", value = "IP地址", dataType = "String", paramType = "query", example = ""),
            @ApiImplicitParam(name = "ip", value = "IP地址", dataType = "String", paramType = "query", required = false, example = "192."),
            @ApiImplicitParam(name = "type", value = "类别", 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 = "/selectByPageAndCount")
    public ResponseMsg<List<BlacklistEntity>> selectByPageAndCount(String ip, Integer pageSize, Integer pageIndex) {
    public ResponseMsg<List<BlacklistEntity>> selectByPageAndCount(String ip, Integer type, Integer pageSize, Integer pageIndex) {
        try {
            if (pageSize < 1 || pageIndex < 1) {
                return fail("每页页数或分页数小于1", null);
            }
            int count = blacklistService.selectCount(ip);
            int count = blacklistService.selectCount(ip, type);
            if (count == 0) {
                return success(0, null);
            }
            List<BlacklistEntity> rs = blacklistService.selectByPage(ip, pageSize, pageSize * (pageIndex - 1));
            List<BlacklistEntity> rs = blacklistService.selectByPage(ip, type, pageSize, pageSize * (pageIndex - 1));
            return success(count, rs);
        } catch (Exception ex) {
@@ -123,8 +132,13 @@
            @ApiImplicitParam(name = "entity", value = "实体类", dataType = "BlacklistEntity", paramType = "body")
    })
    @PostMapping(value = "/insert", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> insert(@RequestBody BlacklistEntity entity) {
    public ResponseMsg<Integer> insert(@RequestBody BlacklistEntity entity, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                entity.setCreateUser(ue.getId());
            }
            int count = blacklistService.insert(entity);
            return success(count);
@@ -139,8 +153,15 @@
            @ApiImplicitParam(name = "list", value = "实体类集合", dataType = "BlacklistEntity", paramType = "body")
    })
    @PostMapping(value = "/inserts", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> inserts(@RequestBody List<BlacklistEntity> list) {
    public ResponseMsg<Integer> inserts(@RequestBody List<BlacklistEntity> list, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                for (BlacklistEntity entity : list) {
                    entity.setCreateUser(ue.getId());
                }
            }
            int count = blacklistService.inserts(list);
            return success(count);
@@ -192,8 +213,13 @@
    })
    @ResponseBody
    @PostMapping(value = "/update", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> update(@RequestBody BlacklistEntity entity) {
    public ResponseMsg<Integer> update(@RequestBody BlacklistEntity entity, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                entity.setUpdateUser(ue.getId());
            }
            int count = blacklistService.update(entity);
            return success(count);
@@ -209,8 +235,15 @@
    })
    @ResponseBody
    @PostMapping(value = "/updates", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> updates(@RequestBody List<BlacklistEntity> list) {
    public ResponseMsg<Integer> updates(@RequestBody List<BlacklistEntity> list, HttpServletRequest req) {
        try {
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                for (BlacklistEntity entity : list) {
                    entity.setUpdateUser(ue.getId());
                }
            }
            int count = blacklistService.updates(list);
            return success(count);