parent
d564cedfb5
commit
bdea7fe82f
10 changed files with 219 additions and 24 deletions
@ -0,0 +1,136 @@ |
|||||||
|
|
||||||
|
package org.springblade.plugin.operation.database.controller; |
||||||
|
|
||||||
|
import com.alibaba.nacos.common.utils.CollectionUtils; |
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import io.swagger.annotations.ApiParam; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import org.springblade.core.boot.ctrl.BladeController; |
||||||
|
import org.springblade.core.cache.utils.CacheUtil; |
||||||
|
import org.springblade.core.excel.util.ExcelUtil; |
||||||
|
import org.springblade.core.mp.support.Condition; |
||||||
|
import org.springblade.core.mp.support.Query; |
||||||
|
import org.springblade.core.tenant.annotation.NonDS; |
||||||
|
import org.springblade.core.tool.api.R; |
||||||
|
import org.springblade.core.tool.utils.BeanUtil; |
||||||
|
import org.springblade.core.tool.utils.DateUtil; |
||||||
|
import org.springblade.core.tool.utils.Func; |
||||||
|
import org.springblade.plugin.operation.database.entity.DataBase; |
||||||
|
import org.springblade.plugin.operation.database.excel.DatabaseExcel; |
||||||
|
import org.springblade.plugin.operation.database.service.IDataBaseService; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
import org.springframework.web.multipart.MultipartFile; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import javax.validation.Valid; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE; |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* |
||||||
|
*/ |
||||||
|
@NonDS |
||||||
|
@RestController |
||||||
|
@AllArgsConstructor |
||||||
|
@RequestMapping("/database") |
||||||
|
@Api(value = "接口权限", tags = "接口权限") |
||||||
|
public class DataBaseController extends BladeController { |
||||||
|
|
||||||
|
private final IDataBaseService dataBaseService; |
||||||
|
|
||||||
|
/** |
||||||
|
* 详情 |
||||||
|
*/ |
||||||
|
@GetMapping("/detail") |
||||||
|
@ApiOperationSupport(order = 1) |
||||||
|
@ApiOperation(value = "详情", notes = "传入dataScope") |
||||||
|
public R<DataBase> detail(DataBase dataBase) { |
||||||
|
DataBase detail = dataBaseService.getOne(Condition.getQueryWrapper(dataBase)); |
||||||
|
return R.data(detail); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 分页 |
||||||
|
*/ |
||||||
|
@GetMapping("/list") |
||||||
|
@ApiOperationSupport(order = 2) |
||||||
|
@ApiOperation(value = "分页", notes = "传入dataScope") |
||||||
|
public R<IPage<DataBase>> list(DataBase dataBase, Query query) { |
||||||
|
IPage<DataBase> pages = dataBaseService.page(Condition.getPage(query), Condition.getQueryWrapper(dataBase)); |
||||||
|
return R.data(pages); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 新增 |
||||||
|
*/ |
||||||
|
@PostMapping("/save") |
||||||
|
@ApiOperationSupport(order = 3) |
||||||
|
@ApiOperation(value = "新增", notes = "传入dataScope") |
||||||
|
public R save(@Valid @RequestBody DataBase dataBase) { |
||||||
|
return R.status(dataBaseService.save(dataBase)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 修改 |
||||||
|
*/ |
||||||
|
@PostMapping("/update") |
||||||
|
@ApiOperationSupport(order = 4) |
||||||
|
@ApiOperation(value = "修改", notes = "传入dataScope") |
||||||
|
public R update(@Valid @RequestBody DataBase dataBase) { |
||||||
|
return R.status(dataBaseService.updateById(dataBase)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 新增或修改 |
||||||
|
*/ |
||||||
|
@PostMapping("/submit") |
||||||
|
@ApiOperationSupport(order = 5) |
||||||
|
@ApiOperation(value = "新增或修改", notes = "传入dataScope") |
||||||
|
public R submit(@Valid @RequestBody DataBase dataBase) { |
||||||
|
return R.status(dataBaseService.saveOrUpdate(dataBase)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 删除 |
||||||
|
*/ |
||||||
|
@PostMapping("/remove") |
||||||
|
@ApiOperationSupport(order = 6) |
||||||
|
@ApiOperation(value = "逻辑删除", notes = "传入ids") |
||||||
|
public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) { |
||||||
|
return R.status(dataBaseService.deleteLogic(Func.toLongList(ids))); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* excel导入 |
||||||
|
*/ |
||||||
|
@PostMapping("dataImport") |
||||||
|
public R importUser(MultipartFile file) { |
||||||
|
List<DatabaseExcel> excelList = ExcelUtil.read(file, DatabaseExcel.class); |
||||||
|
if (CollectionUtils.isNotEmpty(excelList)) { |
||||||
|
List<DataBase> dataBaseList = new ArrayList<>(); |
||||||
|
excelList.forEach(item->{ |
||||||
|
DataBase dataBase = BeanUtil.copy(item, DataBase.class); |
||||||
|
dataBaseList.add(dataBase); |
||||||
|
}); |
||||||
|
dataBaseService.saveBatch(dataBaseList); |
||||||
|
} |
||||||
|
return R.success("操作成功"); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* excel导出模板 |
||||||
|
*/ |
||||||
|
@GetMapping("exportTemplate") |
||||||
|
public void exportUser(HttpServletResponse response) { |
||||||
|
List<DatabaseExcel> excels = new ArrayList<>(); |
||||||
|
ExcelUtil.export(response, "数据库数据" + DateUtil.time(), "数据库数据", excels, DatabaseExcel.class); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,14 @@ |
|||||||
|
|
||||||
|
package org.springblade.plugin.operation.database.mapper; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import org.springblade.plugin.operation.database.entity.DataBase; |
||||||
|
|
||||||
|
/** |
||||||
|
* Mapper 接口 |
||||||
|
* |
||||||
|
* @author BladeX |
||||||
|
*/ |
||||||
|
public interface DataBaseMapper extends BaseMapper<DataBase> { |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,5 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||||
|
<mapper namespace="org.springblade.plugin.operation.database.mapper.DataBaseMapper"> |
||||||
|
|
||||||
|
</mapper> |
||||||
@ -0,0 +1,14 @@ |
|||||||
|
|
||||||
|
package org.springblade.plugin.operation.database.service; |
||||||
|
|
||||||
|
import org.springblade.core.mp.base.BaseService; |
||||||
|
import org.springblade.plugin.operation.database.entity.DataBase; |
||||||
|
|
||||||
|
/** |
||||||
|
* 服务类 |
||||||
|
* |
||||||
|
* @author BladeX |
||||||
|
*/ |
||||||
|
public interface IDataBaseService extends BaseService<DataBase> { |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,18 @@ |
|||||||
|
|
||||||
|
package org.springblade.plugin.operation.database.service.impl; |
||||||
|
|
||||||
|
import org.springblade.core.mp.base.BaseServiceImpl; |
||||||
|
import org.springblade.plugin.operation.database.entity.DataBase; |
||||||
|
import org.springblade.plugin.operation.database.mapper.DataBaseMapper; |
||||||
|
import org.springblade.plugin.operation.database.service.IDataBaseService; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
/** |
||||||
|
* 服务实现类 |
||||||
|
* |
||||||
|
* @author BladeX |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
public class DataBaseServiceImpl extends BaseServiceImpl<DataBaseMapper, DataBase> implements IDataBaseService { |
||||||
|
|
||||||
|
} |
||||||
Loading…
Reference in new issue