database资源增删改查

This commit is contained in:
2025-02-20 09:48:42 +08:00
parent 611648240e
commit dc23ab70ac
16 changed files with 845 additions and 53 deletions

View File

@@ -0,0 +1,71 @@
package com.test.test.controller;
import java.util.List;
import com.test.test.domain.qo.IDQO;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.test.common.annotation.Log;
import com.test.common.core.controller.BaseController;
import com.test.common.core.domain.AjaxResult;
import com.test.common.enums.BusinessType;
import com.test.test.domain.TestDatasource;
import com.test.test.service.ITestDatasourceService;
/**
* 数据源Controller
*/
@RestController
@RequestMapping("/test/datasource")
public class TestDatasourceController extends BaseController {
@Resource
private ITestDatasourceService testDatasourceService;
/**
* 查询数据源列表
*/
@GetMapping("/list")
public AjaxResult list() {
List<TestDatasource> list = testDatasourceService.selectTestDatasourceList();
return success(list);
}
/**
* 获取数据源详细信息
*/
@PostMapping(value = "/detail")
public AjaxResult getInfo(@RequestBody IDQO qo) {
return success(testDatasourceService.selectTestDatasourceById(qo.getId()));
}
/**
* 新增数据源
*/
@Log(title = "数据源", businessType = BusinessType.INSERT)
@PostMapping("/add")
public AjaxResult add(@RequestBody TestDatasource testDatasource) {
return success(testDatasourceService.insertTestDatasource(testDatasource));
}
/**
* 修改数据源
*/
@Log(title = "数据源", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
public AjaxResult edit(@RequestBody TestDatasource testDatasource) {
return toAjax(testDatasourceService.updateTestDatasource(testDatasource));
}
/**
* 删除数据源
*/
@Log(title = "数据源", businessType = BusinessType.DELETE)
@PostMapping("/del")
public AjaxResult remove(@RequestBody IDQO qo) {
return toAjax(testDatasourceService.deleteTestDatasourceById(qo.getId()));
}
}

View File

@@ -15,7 +15,6 @@ import com.test.common.core.domain.AjaxResult;
import com.test.common.enums.BusinessType;
import com.test.test.domain.TestHttp;
import com.test.test.service.ITestHttpService;
import com.test.common.core.page.TableDataInfo;
/**
* http服务Controller

View File

@@ -0,0 +1,86 @@
package com.test.test.domain;
import com.test.common.core.domain.BaseEntity;
import com.test.common.annotation.Excel;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
* 数据源对象 test_datasource
*/
@Getter
@Setter
@ToString
public class TestDatasource extends BaseEntity {
/**
* 数据源id
*/
private Long id;
/**
* 数据源名称
*/
@Excel(name = "数据源名称")
private String name;
/**
* 数据源类型(Mysql1redis2Oracle3MongoDB4SQL Server5PostgreSQL6)
*/
@Excel(name = "数据源类型(Mysql1redis2Oracle3MongoDB4SQL Server5PostgreSQL6)")
private Long type;
/**
* 主机
*/
@Excel(name = "主机")
private String host;
/**
* 端口
*/
@Excel(name = "端口")
private String port;
/**
* 用户名
*/
@Excel(name = "用户名")
private String username;
/**
* 密码
*/
@Excel(name = "密码")
private String password;
/**
* 库名Oracle服务名
*/
@Excel(name = "库名", readConverterExp = "O=racle服务名")
private String dbName;
/**
* mongo认证库名
*/
@Excel(name = "mongo认证库名")
private String authDb;
/**
* redis集群模式
*/
@Excel(name = "redis集群模式")
private Integer cluster;
/**
* redis哨兵模式下输入MasterName
*/
@Excel(name = "redis哨兵模式下输入MasterName")
private String masterName;
/**
* 删除标志0代表存在 2代表删除
*/
private String delFlag;
}

View File

@@ -0,0 +1,40 @@
package com.test.test.mapper;
import java.util.List;
import com.test.test.domain.TestDatasource;
/**
* 数据源Mapper接口
*/
public interface TestDatasourceMapper {
/**
* 查询数据源
*/
TestDatasource selectTestDatasourceById(Long id);
/**
* 查询数据源列表
*/
List<TestDatasource> selectTestDatasourceList();
/**
* 新增数据源
*/
int insertTestDatasource(TestDatasource testDatasource);
/**
* 修改数据源
*/
int updateTestDatasource(TestDatasource testDatasource);
/**
* 删除数据源
*/
int deleteTestDatasourceById(Long id);
/**
* 批量删除数据源
*/
int deleteTestDatasourceByIds(Long[] ids);
}

View File

@@ -0,0 +1,40 @@
package com.test.test.service;
import java.util.List;
import com.test.test.domain.TestDatasource;
/**
* 数据源Service接口
*/
public interface ITestDatasourceService {
/**
* 查询数据源
*/
public TestDatasource selectTestDatasourceById(Long id);
/**
* 查询数据源列表
*/
List<TestDatasource> selectTestDatasourceList();
/**
* 新增数据源
*/
TestDatasource insertTestDatasource(TestDatasource testDatasource);
/**
* 修改数据源
*/
int updateTestDatasource(TestDatasource testDatasource);
/**
* 批量删除数据源
*/
int deleteTestDatasourceByIds(Long[] ids);
/**
* 删除数据源信息
*/
int deleteTestDatasourceById(Long id);
}

View File

@@ -0,0 +1,73 @@
package com.test.test.service.impl;
import java.util.List;
import com.test.common.utils.DateUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import com.test.test.mapper.TestDatasourceMapper;
import com.test.test.domain.TestDatasource;
import com.test.test.service.ITestDatasourceService;
/**
* 数据源Service业务层处理
*/
@Service
public class TestDatasourceServiceImpl implements ITestDatasourceService {
@Resource
private TestDatasourceMapper testDatasourceMapper;
/**
* 查询数据源
*
* @param id 数据源主键
* @return 数据源
*/
@Override
public TestDatasource selectTestDatasourceById(Long id) {
return testDatasourceMapper.selectTestDatasourceById(id);
}
/**
* 查询数据源列表
*/
@Override
public List<TestDatasource> selectTestDatasourceList() {
return testDatasourceMapper.selectTestDatasourceList();
}
/**
* 新增数据源
*/
@Override
public TestDatasource insertTestDatasource(TestDatasource testDatasource) {
testDatasource.setCreateTime(DateUtils.getNowDate());
testDatasourceMapper.insertTestDatasource(testDatasource);
return testDatasource;
}
/**
* 修改数据源
*/
@Override
public int updateTestDatasource(TestDatasource testDatasource) {
testDatasource.setUpdateTime(DateUtils.getNowDate());
return testDatasourceMapper.updateTestDatasource(testDatasource);
}
/**
* 批量删除数据源
*/
@Override
public int deleteTestDatasourceByIds(Long[] ids) {
return testDatasourceMapper.deleteTestDatasourceByIds(ids);
}
/**
* 删除数据源信息
*/
@Override
public int deleteTestDatasourceById(Long id) {
return testDatasourceMapper.deleteTestDatasourceById(id);
}
}

View File

@@ -0,0 +1,109 @@
<?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="com.test.test.mapper.TestDatasourceMapper">
<resultMap type="TestDatasource" id="TestDatasourceResult">
<result property="id" column="id" />
<result property="name" column="name" />
<result property="type" column="type" />
<result property="host" column="host" />
<result property="port" column="port" />
<result property="username" column="username" />
<result property="password" column="password" />
<result property="dbName" column="db_name" />
<result property="authDb" column="auth_db" />
<result property="cluster" column="cluster" />
<result property="masterName" column="master_name" />
<result property="delFlag" column="del_flag" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectTestDatasourceVo">
select id, name, type, host, port, username, password, db_name, auth_db, cluster, master_name, del_flag, create_by, create_time, update_by, update_time from test_datasource
</sql>
<select id="selectTestDatasourceList" resultMap="TestDatasourceResult">
<include refid="selectTestDatasourceVo"/>
</select>
<select id="selectTestDatasourceById" parameterType="Long" resultMap="TestDatasourceResult">
<include refid="selectTestDatasourceVo"/>
where id = #{id}
</select>
<insert id="insertTestDatasource" parameterType="TestDatasource" useGeneratedKeys="true" keyProperty="id">
insert into test_datasource
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="name != null">name,</if>
<if test="type != null">type,</if>
<if test="host != null">host,</if>
<if test="port != null">port,</if>
<if test="username != null">username,</if>
<if test="password != null">password,</if>
<if test="dbName != null">db_name,</if>
<if test="authDb != null">auth_db,</if>
<if test="cluster != null">cluster,</if>
<if test="masterName != null">master_name,</if>
<if test="delFlag != null">del_flag,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null">#{name},</if>
<if test="type != null">#{type},</if>
<if test="host != null">#{host},</if>
<if test="port != null">#{port},</if>
<if test="username != null">#{username},</if>
<if test="password != null">#{password},</if>
<if test="dbName != null">#{dbName},</if>
<if test="authDb != null">#{authDb},</if>
<if test="cluster != null">#{cluster},</if>
<if test="masterName != null">#{masterName},</if>
<if test="delFlag != null">#{delFlag},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
</insert>
<update id="updateTestDatasource" parameterType="TestDatasource">
update test_datasource
<trim prefix="SET" suffixOverrides=",">
<if test="name != null">name = #{name},</if>
<if test="type != null">type = #{type},</if>
<if test="host != null">host = #{host},</if>
<if test="port != null">port = #{port},</if>
<if test="username != null">username = #{username},</if>
<if test="password != null">password = #{password},</if>
<if test="dbName != null">db_name = #{dbName},</if>
<if test="authDb != null">auth_db = #{authDb},</if>
<if test="cluster != null">cluster = #{cluster},</if>
<if test="masterName != null">master_name = #{masterName},</if>
<if test="delFlag != null">del_flag = #{delFlag},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteTestDatasourceById" parameterType="Long">
delete from test_datasource where id = #{id}
</delete>
<delete id="deleteTestDatasourceByIds" parameterType="String">
delete from test_datasource where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>