表结构的增删改查
parent
ddaa24276b
commit
b40b52a5c7
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
* @ Tool:IntelliJ 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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
* @ Tool:IntelliJ 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
* @ Tool:IntelliJ 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);
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue