165 lines
5.7 KiB
Java
165 lines
5.7 KiB
Java
package com.muyu.source.controller;
|
||
|
||
|
||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||
import com.dtflys.forest.springboot.annotation.ForestScannerRegister;
|
||
import com.muyu.common.core.domain.Result;
|
||
import com.muyu.common.core.utils.poi.ExcelUtil;
|
||
import com.muyu.common.core.web.controller.BaseController;
|
||
import com.muyu.common.core.web.page.TableDataInfo;
|
||
import com.muyu.common.security.annotation.RequiresPermissions;
|
||
import com.muyu.common.security.utils.SecurityUtils;
|
||
import com.muyu.source.domain.Structure;
|
||
import com.muyu.source.domain.TableData;
|
||
import com.muyu.source.domain.TableInfo;
|
||
import com.muyu.source.service.StructureService;
|
||
import com.muyu.source.service.TableDataService;
|
||
import com.muyu.source.service.TableInfoService;
|
||
import io.swagger.v3.oas.annotations.Operation;
|
||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||
import jakarta.servlet.http.HttpServletResponse;
|
||
import lombok.extern.log4j.Log4j2;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.validation.annotation.Validated;
|
||
import org.springframework.web.bind.annotation.*;
|
||
|
||
import java.util.Arrays;
|
||
import java.util.List;
|
||
|
||
/**
|
||
* @author Lenovo
|
||
* @ Tool:IntelliJ IDEA
|
||
* @ Author:CHX
|
||
* @ Date:2024-08-21-19:51
|
||
* @ Version:1.0
|
||
* @ Description:表结构控制层
|
||
*/
|
||
@Log4j2
|
||
@RestController
|
||
@RequestMapping("/data")
|
||
@Tag(name = "表结构控制层", description = "进行表结构管理,查看等相关操作")
|
||
public class TableDataController extends BaseController {
|
||
public TableDataController() {
|
||
log.info("forest扫描路径:{}", ForestScannerRegister.getBasePackages());
|
||
}
|
||
|
||
@Autowired
|
||
private TableDataService tableDataService;
|
||
@Autowired
|
||
private TableInfoService tableInfoService;
|
||
@Autowired
|
||
private StructureService structureService;
|
||
/**
|
||
* 根据childrenId查询表结构
|
||
*
|
||
* @param id id
|
||
* @return 表结构
|
||
*/
|
||
@GetMapping("/selectTableData/{id}")
|
||
@Operation(summary = "根据id查询表结构", description = "可以根据根据id查询表结构")
|
||
public Result<TableData> selectTableData(@PathVariable("id") Integer id) {
|
||
return success(tableDataService.getById(id));
|
||
}
|
||
|
||
/**
|
||
* 根据表的id查询表结构
|
||
* @param id id
|
||
* @return tableInfo
|
||
*/
|
||
@GetMapping("/selectStructureById/{id}")
|
||
public Result<List<Structure>> selectStructureById(@PathVariable("id") Integer id) {
|
||
List<Structure> structureList =tableInfoService.selectTableInfoById(id);
|
||
return success(structureList);
|
||
}
|
||
|
||
/**
|
||
* 查询结构列表
|
||
*/
|
||
@RequiresPermissions("data:data:list")
|
||
@GetMapping("/list")
|
||
@Operation(summary = "查询结构列表", description = "查询结构列表")
|
||
public Result<TableDataInfo<TableData>> list(TableData tableData) {
|
||
startPage();
|
||
List<TableData> list = tableDataService.selectTableDataList(tableData);
|
||
return getDataTable(list);
|
||
}
|
||
|
||
/**
|
||
* 导出结构列表
|
||
*/
|
||
@RequiresPermissions("data:data:export")
|
||
@PostMapping("/export")
|
||
@Operation(summary = "导出结构列表", description = "导出结构列表")
|
||
public void export(HttpServletResponse response, TableData tableData) {
|
||
List<TableData> list = tableDataService.selectTableDataList(tableData);
|
||
ExcelUtil<TableData> util = new ExcelUtil<TableData>(TableData.class);
|
||
util.exportExcel(response, list, "结构数据");
|
||
}
|
||
|
||
/**
|
||
* 获取结构详细信息
|
||
*/
|
||
@RequiresPermissions("data:data:query")
|
||
@GetMapping(value = "/{id}")
|
||
@Operation(summary = "获取结构详细信息", description = "获取结构详细信息")
|
||
public Result<List<TableData>> getInfo(@PathVariable("id") Long id) {
|
||
return success(tableDataService.selectTableDataById(id));
|
||
}
|
||
|
||
/**
|
||
* 新增结构
|
||
*/
|
||
@RequiresPermissions("data:data:add")
|
||
@PostMapping
|
||
@Operation(summary = "新增结构", description = "新增结构")
|
||
public Result<Integer> add(
|
||
@Validated @RequestBody TableData tableData) {
|
||
if (tableDataService.checkIdUnique(tableData)) {
|
||
return error("新增 结构 '" + tableData + "'失败,结构已存在");
|
||
}
|
||
tableData.setCreateBy(SecurityUtils.getUsername());
|
||
return toAjax(tableDataService.save(tableData));
|
||
}
|
||
|
||
/**
|
||
* 修改结构
|
||
*/
|
||
@RequiresPermissions("data:data:edit")
|
||
@PutMapping
|
||
@Operation(summary = "修改结构", description = "修改结构")
|
||
public Result<Integer> edit(
|
||
@Validated @RequestBody TableData tableData) {
|
||
if (!tableDataService.checkIdUnique(tableData)) {
|
||
return error("修改 结构 '" + tableData + "'失败,结构不存在");
|
||
}
|
||
tableData.setUpdateBy(SecurityUtils.getUsername());
|
||
return toAjax(tableDataService.updateById(tableData));
|
||
}
|
||
|
||
/**
|
||
* 删除结构
|
||
*/
|
||
@RequiresPermissions("data:data:remove")
|
||
@DeleteMapping("/{ids}")
|
||
@Operation(summary = "删除结构", description = "删除结构")
|
||
public Result<Integer> remove(@PathVariable("ids") Long[] ids) {
|
||
tableDataService.removeBatchByIds(Arrays.asList(ids));
|
||
return success();
|
||
}
|
||
|
||
/**
|
||
* 修改字段类型是否为字典类型
|
||
*
|
||
* @param tableData tableData
|
||
* @return Result
|
||
*/
|
||
@PutMapping("/updIsDict")
|
||
@Operation(summary = "修改字段类型是否为字典类型", description = "修改字段类型是否为字典类型")
|
||
public Result updIsDict(@RequestBody TableData tableData) {
|
||
return toAjax(tableDataService.updateById(tableData));
|
||
}
|
||
|
||
|
||
}
|