表结构的增删改查

master
冷调 2024-08-24 19:48:42 +08:00
parent ddaa24276b
commit b40b52a5c7
4 changed files with 163 additions and 9 deletions

View File

@ -1,6 +1,5 @@
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;
@ -10,7 +9,6 @@ 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.DataSource;
import com.muyu.source.domain.req.DataSourceQueryReq;
import com.muyu.source.service.DataSourceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -18,7 +16,6 @@ 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.HttpRequestHandler;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;

View File

@ -2,17 +2,23 @@ package com.muyu.source.controller;
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.TableData;
import com.muyu.source.service.TableDataService;
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.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
/**
* @author Lenovo
* @ ToolIntelliJ IDEA
@ -25,7 +31,7 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/tableData")
@Tag(name = "表结构控制层", description = "进行表结构管理,查看等相关操作")
public class TableDataController {
public class TableDataController extends BaseController{
public TableDataController() {
log.info("forest扫描路径:{}", ForestScannerRegister.getBasePackages());
}
@ -42,7 +48,81 @@ public class TableDataController {
@GetMapping("/selectTableData/{id}")
@Operation(summary = "根据id查询表结构", description = "可以根据根据id查询表结构")
public Result<TableData> selectTableData(@PathVariable("id") Integer id) {
return Result.success(tableDataService.getById(id));
return success(tableDataService.getById(id));
}
/**
*
*/
@RequiresPermissions("tableData:data:list")
@GetMapping("/list")
public Result<TableDataInfo<TableData>> list(TableData tableData)
{
startPage();
List<TableData> list = tableDataService.selectTableDataList(tableData);
return getDataTable(list);
}
/**
*
*/
@RequiresPermissions("tableData:data:export")
@PostMapping("/export")
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("tableData:data:query")
@GetMapping(value = "/{id}")
public Result<List<TableData>> getInfo(@PathVariable("id") Long id)
{
return success(tableDataService.selectTableDataById(id));
}
/**
*
*/
@RequiresPermissions("tableData:data:add")
@PostMapping
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("tableData:data:edit")
@PutMapping
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("tableData:data:remove")
@DeleteMapping("/{ids}")
public Result<Integer> remove(@PathVariable("ids") Long[] ids)
{
tableDataService.removeBatchByIds(Arrays.asList(ids));
return success();
}
/**

View File

@ -1,11 +1,16 @@
package com.muyu.source.service.Impl;
import cn.hutool.core.lang.Assert;
import com.alibaba.cloud.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.source.domain.TableData;
import com.muyu.source.mapper.TableDataMapper;
import com.muyu.source.service.TableDataService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author Lenovo
* @ ToolIntelliJ IDEA
@ -16,5 +21,52 @@ import org.springframework.stereotype.Service;
*/
@Service
public class TableDataServiceImpl extends ServiceImpl<TableDataMapper, TableData> implements TableDataService {
/**
*
*
* @param id
* @return
*/
@Override
public TableData selectTableDataById(Long id)
{
LambdaQueryWrapper<TableData> queryWrapper = new LambdaQueryWrapper<>();
Assert.notNull(id, "id不可为空");
queryWrapper.eq(TableData::getId, id);
return this.getOne(queryWrapper);
}
/**
*
*
* @param tableData
* @return
*/
@Override
public List<TableData> selectTableDataList(TableData tableData)
{
LambdaQueryWrapper<TableData> queryWrapper = new LambdaQueryWrapper<>();
if (StringUtils.isNotEmpty(tableData.getName())){
queryWrapper.like(TableData::getName, tableData.getName());
}
if (StringUtils.isNotEmpty(tableData.getType())){
queryWrapper.eq(TableData::getType, tableData.getType());
}
return this.list(queryWrapper);
}
/**
*
* @param tableData
* @return
*/
@Override
public Boolean checkIdUnique(TableData tableData) {
LambdaQueryWrapper<TableData> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(TableData::getId, tableData.getId());
return this.count(queryWrapper) > 0;
}
}

View File

@ -3,6 +3,8 @@ package com.muyu.source.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.source.domain.TableData;
import java.util.List;
/**
* @author Lenovo
* @ ToolIntelliJ IDEA
@ -12,4 +14,27 @@ import com.muyu.source.domain.TableData;
* @ Description
*/
public interface TableDataService extends IService<TableData> {
/**
*
*
* @param id
* @return
*/
public TableData selectTableDataById(Long id);
/**
*
*
* @param tableData
* @return
*/
public List<TableData> selectTableDataList(TableData tableData);
/**
* id
* @param tableData
* @return
*/
Boolean checkIdUnique(TableData tableData);
}