管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2022-10-08 e7b3a5e891287b1291d2ac38f7c83d5d73bc7906
src/main/java/com/lf/server/controller/data/DictController.java
@@ -1,8 +1,15 @@
package com.lf.server.controller.data;
import com.lf.server.aspect.SysLog;
import com.lf.server.controller.all.BaseController;
import com.lf.server.entity.all.ResponseMsg;
import com.lf.server.entity.data.DictEntity;
import com.lf.server.service.data.DictService;
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.*;
@@ -10,77 +17,205 @@
/**
 * 字典管理
 * @author sws
 * @author SWS + WWW
 * @date 2022-09.26
 */
@Api(tags = "数据管理\\字典管理")
@RestController
@RequestMapping("/Dict")
public class DictController {
@RequestMapping("/dict")
public class DictController extends BaseController {
    @Autowired
    DictService dictService;
    @SysLog()
    @ApiOperation(value = "查询记录数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tab", value = "表名", dataType = "String", paramType = "query", required = false, example = "sys_dict")
    })
    @GetMapping({"/selectCount"})
    public Integer selectCount(String tab) {
        return dictService.selectCount(tab);
    public ResponseMsg<Integer> selectCount(String tab) {
        try {
            int count = dictService.selectCount(tab);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @SysLog()
    @ApiOperation(value = "分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tab", value = "表名", dataType = "String", paramType = "query", example = "sys_dict"),
            @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 List<DictEntity> selectByPage(String tab, Integer pageSize, Integer pageIndex) {
        if (pageSize < 1 || pageIndex < 0) {
            return null;
        }
    public ResponseMsg<List<DictEntity>> selectByPage(String tab, Integer pageSize, Integer pageIndex) {
        try {
            if (pageSize < 1 || pageIndex < 1) {
                return fail("每页页数或分页数小于1", null);
            }
        return dictService.selectByPage(tab, pageSize, pageSize * pageIndex);
    }
            List<DictEntity> rs = dictService.selectByPage(tab, pageSize, pageSize * (pageIndex - 1));
    @RequestMapping(value = "/insertDict", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public Integer insertDict(DictEntity dictEntity) {
        return dictService.insertDict(dictEntity);
    }
    @RequestMapping(value = "/insertDicts", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public Integer insertDicts(@RequestBody List<DictEntity> dictEntity) {
        return dictService.insertDicts(dictEntity);
    }
    @ResponseBody
    @RequestMapping(value = "/deleteDict", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public Integer deleteStyle(int id) {
        return dictService.deleteDict(id);
    }
    @RequestMapping(value = "/deleteDicts", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public Integer deleteDicts(@RequestBody List<Integer> ids) {
        if (!ids.isEmpty()) {
            return dictService.deleteDicts(ids);
        } else {
            return -1;
            return success(rs);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
    @ResponseBody
    @RequestMapping(value = "/updateDict", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public Integer updateDict(DictEntity dictEntity) {
        return dictService.updateDict(dictEntity);
    @SysLog()
    @ApiOperation(value = "分页查询并返回记录数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tab", value = "表名", dataType = "String", paramType = "query", example = "sys_dict"),
            @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<DictEntity>> selectByPageAndCount(String tab, Integer pageSize, Integer pageIndex) {
        try {
            if (pageSize < 1 || pageIndex < 1) {
                return fail("每页页数或分页数小于1", null);
            }
            int count = dictService.selectCount(tab);
            if (count == 0) {
                return success(0, null);
            }
            List<DictEntity> rs = dictService.selectByPage(tab, pageSize, pageSize * (pageIndex - 1));
            return success(count, rs);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
    @SysLog()
    @ApiOperation(value = "插入字典")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dictEntity", value = "字典实体类", dataType = "com.lf.server.entity.data.DictEntity", paramType = "body", example = "")
    })
    @PostMapping(value = "/insertDict", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> insertDict(@RequestBody DictEntity dictEntity) {
        try {
            int count = dictService.insertDict(dictEntity);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @SysLog()
    @ApiOperation(value = "插入多条字典")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dictEntity", value = "字典实体类集合", dataType = "List<DictEntity>", paramType = "body", example = "")
    })
    @PostMapping(value = "/insertDicts", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> insertDicts(@RequestBody List<DictEntity> dictEntity) {
        try {
            int count = dictService.insertDicts(dictEntity);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @SysLog()
    @ApiOperation(value = "删除一条字典")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "字典ID", dataType = "Integer", paramType = "query", example = "1")
    })
    @GetMapping(value = "/deleteDict")
    public ResponseMsg<Integer> deleteDict(int id) {
        try {
            int count = dictService.deleteDict(id);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @SysLog()
    @ApiOperation(value = "删除多条字典")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "字典ID集合", dataType = "List<Integer>", paramType = "query", example = "1,2")
    })
    @GetMapping(value = "/deleteDicts")
    public ResponseMsg<Integer> deleteDicts(@RequestParam List<Integer> ids) {
        try {
            if (ids == null || ids.isEmpty()) {
                return fail("id数组不能为空", -1);
            }
            int count = dictService.deleteDicts(ids);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @SysLog()
    @ApiOperation(value = "更新一条字典")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dictEntity", value = "字典ID集合", dataType = "DictEntity", paramType = "body", example = "")
    })
    @ResponseBody
    @PostMapping(value = "/updateDict", produces = "application/json; charset=UTF-8")
    public ResponseMsg<Integer> updateDict(@RequestBody DictEntity dictEntity) {
        try {
            int count = dictService.updateDict(dictEntity);
            return success(count);
        } catch (Exception ex) {
            return fail(ex.getMessage(), -1);
        }
    }
    @SysLog()
    @ApiOperation(value = "根据ID查询字典")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "字典ID", dataType = "Integer", paramType = "query", example = "1")
    })
    @GetMapping(value = "/selectDict")
    public DictEntity selectDict(int id) {
        return dictService.selectDict(id);
    public ResponseMsg<DictEntity> selectDict(int id) {
        try {
            DictEntity de = dictService.selectDict(id);
            return success(de);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
    @SysLog()
    @ApiOperation(value = "查询所有字典")
    @GetMapping(value = "/selectDictAll")
    public List<DictEntity> selectDictAll() {
        return dictService.selectDictAll();
    public ResponseMsg<List<DictEntity>> selectDictAll() {
        try {
            List<DictEntity> list = dictService.selectDictAll();
            return success(list);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
    @SysLog()
    @ApiOperation(value = "查询字典中的所有表名")
    @GetMapping(value = "/selectDictTab")
    public List<DictEntity> selectDictTab() {
        return dictService.selectDictTab();
    public ResponseMsg<List<DictEntity>> selectDictTab() {
        try {
            List<DictEntity> list = dictService.selectDictTab();
            return success(list);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
}