修改
This commit is contained in:
@@ -26,6 +26,11 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.8.16</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.jcraft</groupId>
|
||||
|
||||
@@ -119,7 +119,6 @@ public class hostJob {
|
||||
bizDeviceInfo.setDevice(diskInfo.getDevice());
|
||||
bizDeviceInfo.setMountPoint(diskInfo.getMountPoint());
|
||||
List<BizDeviceInfo> deviceInfoList = deviceInfoService.findList(bizDeviceInfo);
|
||||
|
||||
BizDeviceInfo deviceInfo = deviceInfoList.isEmpty() ? new BizDeviceInfo() : deviceInfoList.get(0);
|
||||
deviceInfo.setHostId(host.getHostId());
|
||||
deviceInfo.setDevice(diskInfo.getDevice());
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.jeesite.modules.app.dao;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class ExecResult implements Serializable {
|
||||
|
||||
private String code;
|
||||
|
||||
private String fileName;
|
||||
|
||||
public ExecResult() {
|
||||
}
|
||||
|
||||
public ExecResult(String code, String fileName) {
|
||||
this.code = code;
|
||||
this.fileName = fileName;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
package com.jeesite.modules.app.utils;
|
||||
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.poi.excel.BigExcelWriter;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import com.jeesite.modules.app.dao.TableTree;
|
||||
import com.jeesite.modules.app.dao.ExecResult;
|
||||
import com.jeesite.modules.biz.entity.BizDbConfig;
|
||||
import com.jeesite.modules.biz.entity.BizTableField;
|
||||
import com.jeesite.modules.biz.entity.BizTableInfo;
|
||||
@@ -18,6 +22,10 @@ public class MysqlUtils {
|
||||
|
||||
private static final LoggerUtils logger = LoggerUtils.getInstance();
|
||||
|
||||
private static final String filePath = "/ogsapp/resultList/";
|
||||
|
||||
private static String EXEC_CODE = "0";
|
||||
|
||||
// 需要排除的系统数据库
|
||||
private static final List<String> SYSTEM_DATABASES = Arrays.asList(
|
||||
"information_schema", "mysql", "performance_schema", "sys", "test"
|
||||
@@ -202,4 +210,42 @@ public class MysqlUtils {
|
||||
}
|
||||
return tableTrees;
|
||||
}
|
||||
|
||||
|
||||
public static ExecResult getExecResult(BizDbConfig dbConfig, String sql) {
|
||||
String fileName = filePath + vId.getCid() + "_data.xlsx";
|
||||
try {
|
||||
Connection conn = getConnection(dbConfig.getDbIp(), dbConfig.getDbPort(), dbConfig.getDbUsername(), dbConfig.getDbPassword());
|
||||
Statement statement = conn.createStatement();
|
||||
boolean isQuery = sql.trim().toUpperCase().startsWith("SELECT");
|
||||
if (isQuery) {
|
||||
ResultSet rs = statement.executeQuery(sql);
|
||||
List<Map<String, Object>> resultList = new ArrayList<>();
|
||||
ResultSetMetaData metaData = rs.getMetaData();
|
||||
int columnCount = metaData.getColumnCount();
|
||||
while (rs.next()) {
|
||||
Map<String, Object> rowMap = new LinkedHashMap<>();
|
||||
for (int i = 1; i <= columnCount; i++) {
|
||||
String columnName = metaData.getColumnName(i);
|
||||
Object value = rs.getObject(i);
|
||||
rowMap.put(columnName, value);
|
||||
}
|
||||
resultList.add(rowMap);
|
||||
}
|
||||
List<Map<String, Object>> mapList = CollUtil.newArrayList(resultList);
|
||||
BigExcelWriter writer = ExcelUtil.getBigWriter(fileName);
|
||||
writer.write(mapList);
|
||||
writer.close();
|
||||
logger.info(sql, "执行成功,影响行数:", resultList.size(), "执行结果:", fileName);
|
||||
} else {
|
||||
int affectedRows = statement.executeUpdate(sql);
|
||||
logger.info(sql, "执行成功,影响行数:", affectedRows);
|
||||
}
|
||||
EXEC_CODE = "1";
|
||||
} catch (Exception e) {
|
||||
EXEC_CODE = "0";
|
||||
logger.error(e.getMessage());
|
||||
}
|
||||
return new ExecResult(EXEC_CODE, fileName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.jeesite.modules.biz.dao;
|
||||
|
||||
import com.jeesite.common.dao.CrudDao;
|
||||
import com.jeesite.common.mybatis.annotation.MyBatisDao;
|
||||
import com.jeesite.modules.biz.entity.BizSqlStorage;
|
||||
|
||||
/**
|
||||
* 数据开发DAO接口
|
||||
* @author gaoxq
|
||||
* @version 2025-12-03
|
||||
*/
|
||||
@MyBatisDao(dataSourceName="work")
|
||||
public interface BizSqlStorageDao extends CrudDao<BizSqlStorage> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package com.jeesite.modules.biz.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import com.jeesite.common.mybatis.annotation.JoinTable;
|
||||
import com.jeesite.common.mybatis.annotation.JoinTable.Type;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
import com.jeesite.common.entity.DataEntity;
|
||||
import com.jeesite.common.mybatis.annotation.Column;
|
||||
import com.jeesite.common.mybatis.annotation.Table;
|
||||
import com.jeesite.common.mybatis.mapper.query.QueryType;
|
||||
import com.jeesite.common.utils.excel.annotation.ExcelField;
|
||||
import com.jeesite.common.utils.excel.annotation.ExcelField.Align;
|
||||
import com.jeesite.common.utils.excel.annotation.ExcelFields;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 数据开发Entity
|
||||
*
|
||||
* @author gaoxq
|
||||
* @version 2025-12-03
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Table(name = "biz_sql_storage", alias = "a", label = "数据开发信息", columns = {
|
||||
@Column(name = "create_time", attrName = "createTime", label = "创建时间", isUpdate = false, isUpdateForce = true),
|
||||
@Column(name = "id", attrName = "id", label = "主键ID", isPK = true),
|
||||
@Column(name = "sql_name", attrName = "sqlName", label = "SQL名称", queryType = QueryType.LIKE),
|
||||
@Column(name = "sql_content", attrName = "sqlContent", label = "SQL语句", isQuery = false),
|
||||
@Column(name = "sql_type", attrName = "sqlType", label = "SQL类型"),
|
||||
@Column(name = "sql_desc", attrName = "sqlDesc", label = "SQL描述", isQuery = false),
|
||||
@Column(name = "update_time", attrName = "updateTime", label = "更新时间"),
|
||||
@Column(name = "ustatus", attrName = "ustatus", label = "状态"),
|
||||
@Column(name = "execute_file", attrName = "executeFile", label = "文件名称", isQuery = false),
|
||||
@Column(name = "execute_time", attrName = "executeTime", label = "执行时间"),
|
||||
@Column(name = "execute_result", attrName = "executeResult", label = "执行结果"),
|
||||
@Column(name = "db_id", attrName = "dbId", label = "连接标识"),
|
||||
}, joinTable = {
|
||||
@JoinTable(type = Type.LEFT_JOIN, entity = BizDbConfig.class, attrName = "this", alias = "b",
|
||||
on = "a.db_id = b.id",
|
||||
columns = {
|
||||
@Column(name = "db_type", attrName = "dbType", label = "数据库类型"),
|
||||
@Column(name = "db_name", attrName = "dbName", label = "数据库名称"),
|
||||
@Column(name = "db_ip", attrName = "dbIp", label = "数据库IP"),
|
||||
}),
|
||||
}, orderBy = "a.create_time DESC"
|
||||
)
|
||||
@Data
|
||||
public class BizSqlStorage extends DataEntity<BizSqlStorage> implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Date createTime; // 创建时间
|
||||
private String sqlName; // SQL名称
|
||||
private String sqlContent; // SQL语句
|
||||
private String sqlType; // SQL类型
|
||||
private String sqlDesc; // SQL描述
|
||||
private Date updateTime; // 更新时间
|
||||
private String ustatus; // 状态
|
||||
private String executeFile; // 文件名称
|
||||
private Date executeTime; // 执行时间
|
||||
private String executeResult; // 执行结果
|
||||
private String dbId; // 连接标识
|
||||
|
||||
private String dbType;
|
||||
private String dbName;
|
||||
private String dbIp;
|
||||
|
||||
@ExcelFields({
|
||||
@ExcelField(title = "创建时间", attrName = "createTime", align = Align.CENTER, sort = 10, dataFormat = "yyyy-MM-dd hh:mm"),
|
||||
@ExcelField(title = "主键ID", attrName = "id", align = Align.CENTER, sort = 20),
|
||||
@ExcelField(title = "SQL名称", attrName = "sqlName", align = Align.CENTER, sort = 30),
|
||||
@ExcelField(title = "SQL语句", attrName = "sqlContent", align = Align.CENTER, sort = 40),
|
||||
@ExcelField(title = "SQL类型", attrName = "sqlType", align = Align.CENTER, sort = 50),
|
||||
@ExcelField(title = "SQL描述", attrName = "sqlDesc", align = Align.CENTER, sort = 60),
|
||||
@ExcelField(title = "更新时间", attrName = "updateTime", align = Align.CENTER, sort = 70, dataFormat = "yyyy-MM-dd hh:mm"),
|
||||
@ExcelField(title = "状态", attrName = "ustatus", dictType = "ustatus", align = Align.CENTER, sort = 80),
|
||||
@ExcelField(title = "文件名称", attrName = "executeFile", align = Align.CENTER, sort = 90),
|
||||
@ExcelField(title = "执行时间", attrName = "executeTime", align = Align.CENTER, sort = 100, dataFormat = "yyyy-MM-dd hh:mm"),
|
||||
@ExcelField(title = "执行结果", attrName = "executeResult", dictType = "execute_result", align = Align.CENTER, sort = 110),
|
||||
@ExcelField(title = "数据库名称", attrName = "dbName", align = Align.CENTER, sort = 120),
|
||||
@ExcelField(title = "数据库IP", attrName = "dbIp", align = Align.CENTER, sort = 120),
|
||||
})
|
||||
public BizSqlStorage() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public BizSqlStorage(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public Date getCreateTime_gte() {
|
||||
return sqlMap.getWhere().getValue("create_time", QueryType.GTE);
|
||||
}
|
||||
|
||||
public void setCreateTime_gte(Date createTime) {
|
||||
sqlMap.getWhere().and("create_time", QueryType.GTE, createTime);
|
||||
}
|
||||
|
||||
public Date getCreateTime_lte() {
|
||||
return sqlMap.getWhere().getValue("create_time", QueryType.LTE);
|
||||
}
|
||||
|
||||
public void setCreateTime_lte(Date createTime) {
|
||||
sqlMap.getWhere().and("create_time", QueryType.LTE, createTime);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package com.jeesite.modules.biz.service;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.jeesite.common.entity.Page;
|
||||
import com.jeesite.common.service.CrudService;
|
||||
import com.jeesite.modules.biz.entity.BizSqlStorage;
|
||||
import com.jeesite.modules.biz.dao.BizSqlStorageDao;
|
||||
import com.jeesite.common.service.ServiceException;
|
||||
import com.jeesite.common.config.Global;
|
||||
import com.jeesite.common.validator.ValidatorUtils;
|
||||
import com.jeesite.common.utils.excel.ExcelImport;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import jakarta.validation.ConstraintViolation;
|
||||
import jakarta.validation.ConstraintViolationException;
|
||||
|
||||
/**
|
||||
* 数据开发Service
|
||||
* @author gaoxq
|
||||
* @version 2025-12-03
|
||||
*/
|
||||
@Service
|
||||
public class BizSqlStorageService extends CrudService<BizSqlStorageDao, BizSqlStorage> {
|
||||
|
||||
/**
|
||||
* 获取单条数据
|
||||
* @param bizSqlStorage 主键
|
||||
*/
|
||||
@Override
|
||||
public BizSqlStorage get(BizSqlStorage bizSqlStorage) {
|
||||
return super.get(bizSqlStorage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询分页数据
|
||||
* @param bizSqlStorage 查询条件
|
||||
* @param bizSqlStorage page 分页对象
|
||||
*/
|
||||
@Override
|
||||
public Page<BizSqlStorage> findPage(BizSqlStorage bizSqlStorage) {
|
||||
return super.findPage(bizSqlStorage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询列表数据
|
||||
* @param bizSqlStorage 查询条件
|
||||
*/
|
||||
@Override
|
||||
public List<BizSqlStorage> findList(BizSqlStorage bizSqlStorage) {
|
||||
return super.findList(bizSqlStorage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据(插入或更新)
|
||||
* @param bizSqlStorage 数据对象
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void save(BizSqlStorage bizSqlStorage) {
|
||||
super.save(bizSqlStorage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入数据
|
||||
* @param file 导入的数据文件
|
||||
*/
|
||||
@Transactional
|
||||
public String importData(MultipartFile file) {
|
||||
if (file == null){
|
||||
throw new ServiceException(text("请选择导入的数据文件!"));
|
||||
}
|
||||
int successNum = 0; int failureNum = 0;
|
||||
StringBuilder successMsg = new StringBuilder();
|
||||
StringBuilder failureMsg = new StringBuilder();
|
||||
try(ExcelImport ei = new ExcelImport(file, 2, 0)){
|
||||
List<BizSqlStorage> list = ei.getDataList(BizSqlStorage.class);
|
||||
for (BizSqlStorage bizSqlStorage : list) {
|
||||
try{
|
||||
ValidatorUtils.validateWithException(bizSqlStorage);
|
||||
this.save(bizSqlStorage);
|
||||
successNum++;
|
||||
successMsg.append("<br/>" + successNum + "、编号 " + bizSqlStorage.getId() + " 导入成功");
|
||||
} catch (Exception e) {
|
||||
failureNum++;
|
||||
String msg = "<br/>" + failureNum + "、编号 " + bizSqlStorage.getId() + " 导入失败:";
|
||||
if (e instanceof ConstraintViolationException){
|
||||
ConstraintViolationException cve = (ConstraintViolationException)e;
|
||||
for (ConstraintViolation<?> violation : cve.getConstraintViolations()) {
|
||||
msg += Global.getText(violation.getMessage()) + " ("+violation.getPropertyPath()+")";
|
||||
}
|
||||
}else{
|
||||
msg += e.getMessage();
|
||||
}
|
||||
failureMsg.append(msg);
|
||||
logger.error(msg, e);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
failureMsg.append(e.getMessage());
|
||||
return failureMsg.toString();
|
||||
}
|
||||
if (failureNum > 0) {
|
||||
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
|
||||
throw new ServiceException(failureMsg.toString());
|
||||
}else{
|
||||
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
|
||||
}
|
||||
return successMsg.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新状态
|
||||
* @param bizSqlStorage 数据对象
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void updateStatus(BizSqlStorage bizSqlStorage) {
|
||||
super.updateStatus(bizSqlStorage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param bizSqlStorage 数据对象
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void delete(BizSqlStorage bizSqlStorage) {
|
||||
super.delete(bizSqlStorage);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
package com.jeesite.modules.biz.web;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.jeesite.modules.app.dao.ExecResult;
|
||||
import com.jeesite.modules.app.utils.MysqlUtils;
|
||||
import com.jeesite.modules.app.utils.vDate;
|
||||
import com.jeesite.modules.biz.entity.BizDbConfig;
|
||||
import com.jeesite.modules.biz.service.BizDbConfigService;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.jeesite.common.config.Global;
|
||||
import com.jeesite.common.collect.ListUtils;
|
||||
import com.jeesite.common.entity.Page;
|
||||
import com.jeesite.common.lang.DateUtils;
|
||||
import com.jeesite.common.utils.excel.ExcelExport;
|
||||
import com.jeesite.common.utils.excel.annotation.ExcelField.Type;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.jeesite.common.web.BaseController;
|
||||
import com.jeesite.modules.biz.entity.BizSqlStorage;
|
||||
import com.jeesite.modules.biz.service.BizSqlStorageService;
|
||||
|
||||
/**
|
||||
* 数据开发Controller
|
||||
*
|
||||
* @author gaoxq
|
||||
* @version 2025-12-03
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping(value = "${adminPath}/biz/sqlStorage")
|
||||
public class BizSqlStorageController extends BaseController {
|
||||
|
||||
@Resource
|
||||
private BizDbConfigService dbConfigService;
|
||||
|
||||
private final BizSqlStorageService bizSqlStorageService;
|
||||
|
||||
public BizSqlStorageController(BizSqlStorageService bizSqlStorageService) {
|
||||
this.bizSqlStorageService = bizSqlStorageService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据
|
||||
*/
|
||||
@ModelAttribute
|
||||
public BizSqlStorage get(String id, boolean isNewRecord) {
|
||||
return bizSqlStorageService.get(id, isNewRecord);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询列表
|
||||
*/
|
||||
@RequiresPermissions("biz:sqlStorage:view")
|
||||
@RequestMapping(value = {"list", ""})
|
||||
public String list(BizSqlStorage bizSqlStorage, Model model) {
|
||||
model.addAttribute("bizSqlStorage", bizSqlStorage);
|
||||
return "modules/biz/bizSqlStorageList";
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询列表数据
|
||||
*/
|
||||
@RequiresPermissions("biz:sqlStorage:view")
|
||||
@RequestMapping(value = "listData")
|
||||
@ResponseBody
|
||||
public Page<BizSqlStorage> listData(BizSqlStorage bizSqlStorage, HttpServletRequest request, HttpServletResponse response) {
|
||||
bizSqlStorage.setPage(new Page<>(request, response));
|
||||
Page<BizSqlStorage> page = bizSqlStorageService.findPage(bizSqlStorage);
|
||||
return page;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看编辑表单
|
||||
*/
|
||||
@RequiresPermissions("biz:sqlStorage:view")
|
||||
@RequestMapping(value = "form")
|
||||
public String form(BizSqlStorage bizSqlStorage, Model model) {
|
||||
model.addAttribute("bizSqlStorage", bizSqlStorage);
|
||||
return "modules/biz/bizSqlStorageForm";
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据
|
||||
*/
|
||||
@RequiresPermissions("biz:sqlStorage:edit")
|
||||
@PostMapping(value = "save")
|
||||
@ResponseBody
|
||||
public String save(@Validated BizSqlStorage bizSqlStorage) {
|
||||
bizSqlStorage.setUpdateTime(vDate.getUpdateTime(bizSqlStorage.getIsNewRecord()));
|
||||
bizSqlStorageService.save(bizSqlStorage);
|
||||
return renderResult(Global.TRUE, text("保存数据开发成功!"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
*/
|
||||
@RequiresPermissions("biz:sqlStorage:view")
|
||||
@RequestMapping(value = "exportData")
|
||||
public void exportData(BizSqlStorage bizSqlStorage, HttpServletResponse response) {
|
||||
List<BizSqlStorage> list = bizSqlStorageService.findList(bizSqlStorage);
|
||||
String fileName = "数据开发" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
|
||||
try (ExcelExport ee = new ExcelExport("数据开发", BizSqlStorage.class)) {
|
||||
ee.setDataList(list).write(response, fileName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载模板
|
||||
*/
|
||||
@RequiresPermissions("biz:sqlStorage:view")
|
||||
@RequestMapping(value = "importTemplate")
|
||||
public void importTemplate(HttpServletResponse response) {
|
||||
BizSqlStorage bizSqlStorage = new BizSqlStorage();
|
||||
List<BizSqlStorage> list = ListUtils.newArrayList(bizSqlStorage);
|
||||
String fileName = "数据开发模板.xlsx";
|
||||
try (ExcelExport ee = new ExcelExport("数据开发", BizSqlStorage.class, Type.IMPORT)) {
|
||||
ee.setDataList(list).write(response, fileName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入数据
|
||||
*/
|
||||
@ResponseBody
|
||||
@RequiresPermissions("biz:sqlStorage:edit")
|
||||
@PostMapping(value = "importData")
|
||||
public String importData(MultipartFile file) {
|
||||
try {
|
||||
String message = bizSqlStorageService.importData(file);
|
||||
return renderResult(Global.TRUE, "posfull:" + message);
|
||||
} catch (Exception ex) {
|
||||
return renderResult(Global.FALSE, "posfull:" + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
*/
|
||||
@RequiresPermissions("biz:sqlStorage:edit")
|
||||
@RequestMapping(value = "delete")
|
||||
@ResponseBody
|
||||
public String delete(BizSqlStorage bizSqlStorage) {
|
||||
bizSqlStorageService.delete(bizSqlStorage);
|
||||
return renderResult(Global.TRUE, text("删除数据开发成功!"));
|
||||
}
|
||||
|
||||
@RequiresPermissions("biz:sqlStorage:edit")
|
||||
@RequestMapping(value = "execute")
|
||||
@ResponseBody
|
||||
public String execute(BizSqlStorage bizSqlStorage) {
|
||||
BizSqlStorage sqlStorage = bizSqlStorageService.get(bizSqlStorage);
|
||||
BizDbConfig config = dbConfigService.get(sqlStorage.getDbId());
|
||||
ExecResult result = MysqlUtils.getExecResult(config, sqlStorage.getSqlContent());
|
||||
sqlStorage.setExecuteResult(result.getCode());
|
||||
sqlStorage.setExecuteFile(result.getFileName());
|
||||
sqlStorage.setExecuteTime(new Date());
|
||||
bizSqlStorageService.save(sqlStorage);
|
||||
return renderResult(Global.TRUE, text("执行数据脚本成功!"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?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.jeesite.modules.biz.dao.BizSqlStorageDao">
|
||||
|
||||
<!-- 查询数据
|
||||
<select id="findList" resultType="BizSqlStorage">
|
||||
SELECT ${sqlMap.column.toSql()}
|
||||
FROM ${sqlMap.table.toSql()}
|
||||
<where>
|
||||
${sqlMap.where.toSql()}
|
||||
</where>
|
||||
ORDER BY ${sqlMap.order.toSql()}
|
||||
</select> -->
|
||||
|
||||
</mapper>
|
||||
57
web-vue/packages/biz/api/biz/sqlStorage.ts
Normal file
57
web-vue/packages/biz/api/biz/sqlStorage.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||
* No deletion without permission, or be held responsible to law.
|
||||
* @author gaoxq
|
||||
*/
|
||||
import { defHttp } from '@jeesite/core/utils/http/axios';
|
||||
import { useGlobSetting } from '@jeesite/core/hooks/setting';
|
||||
import { BasicModel, Page } from '@jeesite/core/api/model/baseModel';
|
||||
import { UploadApiResult } from '@jeesite/core/api/sys/upload';
|
||||
import { UploadFileParams } from '@jeesite/types/axios';
|
||||
import { AxiosProgressEvent } from 'axios';
|
||||
|
||||
const { ctxPath, adminPath } = useGlobSetting();
|
||||
|
||||
export interface BizSqlStorage extends BasicModel<BizSqlStorage> {
|
||||
createTime?: string; // 创建时间
|
||||
sqlName: string; // SQL名称
|
||||
sqlContent: string; // SQL语句
|
||||
sqlType: string; // SQL类型
|
||||
sqlDesc?: string; // SQL描述
|
||||
updateTime?: string; // 更新时间
|
||||
ustatus: string; // 状态
|
||||
executeFile?: string; // 文件名称
|
||||
executeTime?: string; // 执行时间
|
||||
executeResult?: string; // 执行结果
|
||||
dbId: string; // 连接标识
|
||||
}
|
||||
|
||||
export const bizSqlStorageList = (params?: BizSqlStorage | any) =>
|
||||
defHttp.get<BizSqlStorage>({ url: adminPath + '/biz/sqlStorage/list', params });
|
||||
|
||||
export const bizSqlStorageListData = (params?: BizSqlStorage | any) =>
|
||||
defHttp.post<Page<BizSqlStorage>>({ url: adminPath + '/biz/sqlStorage/listData', params });
|
||||
|
||||
export const bizSqlStorageForm = (params?: BizSqlStorage | any) =>
|
||||
defHttp.get<BizSqlStorage>({ url: adminPath + '/biz/sqlStorage/form', params });
|
||||
|
||||
export const bizSqlStorageSave = (params?: any, data?: BizSqlStorage | any) =>
|
||||
defHttp.postJson<BizSqlStorage>({ url: adminPath + '/biz/sqlStorage/save', params, data });
|
||||
|
||||
export const bizSqlStorageImportData = (
|
||||
params: UploadFileParams,
|
||||
onUploadProgress: (progressEvent: AxiosProgressEvent) => void,
|
||||
) =>
|
||||
defHttp.uploadFile<UploadApiResult>(
|
||||
{
|
||||
url: ctxPath + adminPath + '/biz/sqlStorage/importData',
|
||||
onUploadProgress,
|
||||
},
|
||||
params,
|
||||
);
|
||||
|
||||
export const bizSqlStorageDelete = (params?: BizSqlStorage | any) =>
|
||||
defHttp.get<BizSqlStorage>({ url: adminPath + '/biz/sqlStorage/delete', params });
|
||||
|
||||
export const bizSqlStorageExecute = (params?: BizSqlStorage | any) =>
|
||||
defHttp.get<BizSqlStorage>({ url: adminPath + '/biz/sqlStorage/execute', params });
|
||||
140
web-vue/packages/biz/views/biz/sqlStorage/form.vue
Normal file
140
web-vue/packages/biz/views/biz/sqlStorage/form.vue
Normal file
@@ -0,0 +1,140 @@
|
||||
<!--
|
||||
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||
* No deletion without permission, or be held responsible to law.
|
||||
* @author gaoxq
|
||||
-->
|
||||
<template>
|
||||
<BasicDrawer
|
||||
v-bind="$attrs"
|
||||
:showFooter="true"
|
||||
:okAuth="'biz:sqlStorage:edit'"
|
||||
@register="registerDrawer"
|
||||
@ok="handleSubmit"
|
||||
width="70%"
|
||||
>
|
||||
<template #title>
|
||||
<Icon :icon="getTitle.icon" class="m-1 pr-1" />
|
||||
<span> {{ getTitle.value }} </span>
|
||||
</template>
|
||||
<BasicForm @register="registerForm" />
|
||||
</BasicDrawer>
|
||||
</template>
|
||||
<script lang="ts" setup name="ViewsBizSqlStorageForm">
|
||||
import { ref, unref, computed } from 'vue';
|
||||
import { useI18n } from '@jeesite/core/hooks/web/useI18n';
|
||||
import { useMessage } from '@jeesite/core/hooks/web/useMessage';
|
||||
import { router } from '@jeesite/core/router';
|
||||
import { Icon } from '@jeesite/core/components/Icon';
|
||||
import { BasicForm, FormSchema, useForm } from '@jeesite/core/components/Form';
|
||||
import { BasicDrawer, useDrawerInner } from '@jeesite/core/components/Drawer';
|
||||
import { BizSqlStorage, bizSqlStorageSave, bizSqlStorageForm } from '@jeesite/biz/api/biz/sqlStorage';
|
||||
|
||||
const emit = defineEmits(['success', 'register']);
|
||||
|
||||
const { t } = useI18n('biz.sqlStorage');
|
||||
const { showMessage } = useMessage();
|
||||
const { meta } = unref(router.currentRoute);
|
||||
const record = ref<BizSqlStorage>({} as BizSqlStorage);
|
||||
|
||||
const getTitle = computed(() => ({
|
||||
icon: meta.icon || 'i-ant-design:book-outlined',
|
||||
value: record.value.isNewRecord ? t('新增数据开发') : t('编辑数据开发'),
|
||||
}));
|
||||
|
||||
const inputFormSchemas: FormSchema<BizSqlStorage>[] = [
|
||||
{
|
||||
label: t('SQL名称'),
|
||||
field: 'sqlName',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
maxlength: 128,
|
||||
},
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
label: t('SQL类型'),
|
||||
field: 'sqlType',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
dictType: 'sql_type',
|
||||
allowClear: true,
|
||||
},
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
label: t('SQL语句'),
|
||||
field: 'sqlContent',
|
||||
component: 'InputTextArea',
|
||||
required: true,
|
||||
colProps: { md: 24, lg: 24 },
|
||||
},
|
||||
{
|
||||
label: t('SQL描述'),
|
||||
field: 'sqlDesc',
|
||||
component: 'InputTextArea',
|
||||
componentProps: {
|
||||
maxlength: 225,
|
||||
},
|
||||
colProps: { md: 24, lg: 24 },
|
||||
},
|
||||
{
|
||||
label: t('数据库名称'),
|
||||
field: 'dbId',
|
||||
fieldLabel: 'dbName',
|
||||
component: 'ListSelect',
|
||||
componentProps: {
|
||||
selectType: 'bizDbSelect',
|
||||
},
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
label: t('状态'),
|
||||
field: 'ustatus',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
dictType: 'ustatus',
|
||||
allowClear: true,
|
||||
},
|
||||
required: true,
|
||||
},
|
||||
];
|
||||
|
||||
const [registerForm, { resetFields, setFieldsValue, validate }] = useForm<BizSqlStorage>({
|
||||
labelWidth: 120,
|
||||
schemas: inputFormSchemas,
|
||||
baseColProps: { md: 24, lg: 12 },
|
||||
});
|
||||
|
||||
const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
|
||||
setDrawerProps({ loading: true });
|
||||
await resetFields();
|
||||
const res = await bizSqlStorageForm(data);
|
||||
record.value = (res.bizSqlStorage || {}) as BizSqlStorage;
|
||||
record.value.__t = new Date().getTime();
|
||||
await setFieldsValue(record.value);
|
||||
setDrawerProps({ loading: false });
|
||||
});
|
||||
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
const data = await validate();
|
||||
setDrawerProps({ confirmLoading: true });
|
||||
const params: any = {
|
||||
isNewRecord: record.value.isNewRecord,
|
||||
id: record.value.id || data.id,
|
||||
};
|
||||
// console.log('submit', params, data, record);
|
||||
const res = await bizSqlStorageSave(params, data);
|
||||
showMessage(res.message);
|
||||
setTimeout(closeDrawer);
|
||||
emit('success', data);
|
||||
} catch (error: any) {
|
||||
if (error && error.errorFields) {
|
||||
showMessage(error.message || t('common.validateError'));
|
||||
}
|
||||
console.log('error', error);
|
||||
} finally {
|
||||
setDrawerProps({ confirmLoading: false });
|
||||
}
|
||||
}
|
||||
</script>
|
||||
103
web-vue/packages/biz/views/biz/sqlStorage/formImport.vue
Normal file
103
web-vue/packages/biz/views/biz/sqlStorage/formImport.vue
Normal file
@@ -0,0 +1,103 @@
|
||||
<!--
|
||||
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||
* No deletion without permission, or be held responsible to law.
|
||||
* @author gaoxq
|
||||
-->
|
||||
<template>
|
||||
<BasicModal
|
||||
v-bind="$attrs"
|
||||
:title="t('导入数据开发')"
|
||||
:okText="t('导入')"
|
||||
@register="registerModal"
|
||||
@ok="handleSubmit"
|
||||
:minHeight="120"
|
||||
:width="400"
|
||||
>
|
||||
<Upload accept=".xls,.xlsx" :file-list="fileList" :before-upload="beforeUpload" @remove="handleRemove">
|
||||
<a-button> <Icon icon="ant-design:upload-outlined" /> {{ t('选择文件') }} </a-button>
|
||||
<span class="ml-4">{{ uploadInfo }}</span>
|
||||
</Upload>
|
||||
<div class="ml-4 mt-4">
|
||||
{{ t('提示:仅允许导入“xls”或“xlsx”格式文件!') }}
|
||||
</div>
|
||||
<div class="mt-4">
|
||||
<a-button @click="handleDownloadTemplate()" type="text">
|
||||
<Icon icon="i-fa:file-excel-o" />
|
||||
{{ t('下载模板') }}
|
||||
</a-button>
|
||||
</div>
|
||||
</BasicModal>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { ref } from 'vue';
|
||||
import { Upload } from 'ant-design-vue';
|
||||
import { useI18n } from '@jeesite/core/hooks/web/useI18n';
|
||||
import { useMessage } from '@jeesite/core/hooks/web/useMessage';
|
||||
import { useGlobSetting } from '@jeesite/core/hooks/setting';
|
||||
import { downloadByUrl } from '@jeesite/core/utils/file/download';
|
||||
import { Icon } from '@jeesite/core/components/Icon';
|
||||
import { BasicModal, useModalInner } from '@jeesite/core/components/Modal';
|
||||
import { bizSqlStorageImportData } from '@jeesite/biz/api/biz/sqlStorage';
|
||||
import { FileType } from 'ant-design-vue/es/upload/interface';
|
||||
import { AxiosProgressEvent } from 'axios';
|
||||
|
||||
const emit = defineEmits(['success', 'register']);
|
||||
|
||||
const { t } = useI18n('biz.sqlStorage');
|
||||
const { showMessage, showMessageModal } = useMessage();
|
||||
|
||||
const fileList = ref<FileType[]>([]);
|
||||
const uploadInfo = ref('');
|
||||
|
||||
const beforeUpload = (file: FileType) => {
|
||||
fileList.value = [file];
|
||||
return false;
|
||||
};
|
||||
|
||||
const handleRemove = () => {
|
||||
fileList.value = [];
|
||||
};
|
||||
|
||||
const [registerModal, { setModalProps, closeModal }] = useModalInner(() => {
|
||||
fileList.value = [];
|
||||
uploadInfo.value = '';
|
||||
});
|
||||
|
||||
async function handleDownloadTemplate() {
|
||||
const { ctxAdminPath } = useGlobSetting();
|
||||
downloadByUrl({ url: ctxAdminPath + '/biz/sqlStorage/importTemplate' });
|
||||
}
|
||||
|
||||
function onUploadProgress(progressEvent: AxiosProgressEvent) {
|
||||
const complete = ((progressEvent.loaded / (progressEvent.total || 1)) * 100) | 0;
|
||||
if (complete != 100) {
|
||||
uploadInfo.value = t('正在导入,请稍候') + ' ' + complete + '%...';
|
||||
} else {
|
||||
uploadInfo.value = '';
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
if (fileList.value.length == 0) {
|
||||
showMessage(t('请选择要导入的数据文件'));
|
||||
return;
|
||||
}
|
||||
setModalProps({ confirmLoading: true });
|
||||
const params = {
|
||||
file: fileList.value[0],
|
||||
};
|
||||
const { data } = await bizSqlStorageImportData(params, onUploadProgress);
|
||||
showMessageModal({ content: data.message });
|
||||
setTimeout(closeModal);
|
||||
emit('success');
|
||||
} catch (error: any) {
|
||||
if (error && error.errorFields) {
|
||||
showMessage(error.message || t('common.validateError'));
|
||||
}
|
||||
console.log('error', error);
|
||||
} finally {
|
||||
setModalProps({ confirmLoading: false });
|
||||
}
|
||||
}
|
||||
</script>
|
||||
313
web-vue/packages/biz/views/biz/sqlStorage/list.vue
Normal file
313
web-vue/packages/biz/views/biz/sqlStorage/list.vue
Normal file
@@ -0,0 +1,313 @@
|
||||
<!--
|
||||
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||
* No deletion without permission, or be held responsible to law.
|
||||
* @author gaoxq
|
||||
-->
|
||||
<template>
|
||||
<div>
|
||||
<BasicTable @register="registerTable">
|
||||
<template #tableTitle>
|
||||
<Icon :icon="getTitle.icon" class="m-1 pr-1" />
|
||||
<span> {{ getTitle.value }} </span>
|
||||
</template>
|
||||
<template #toolbar>
|
||||
<a-button type="default" :loading="loading" @click="handleExport()">
|
||||
<Icon icon="i-ant-design:download-outlined" /> {{ t('导出') }}
|
||||
</a-button>
|
||||
<a-button type="primary" @click="handleForm({})" v-auth="'biz:sqlStorage:edit'">
|
||||
<Icon icon="i-fluent:add-12-filled" /> {{ t('新增') }}
|
||||
</a-button>
|
||||
</template>
|
||||
<template #slotBizKey="{ record }">
|
||||
<a @click="handleForm({ id: record.id })" :title="record.sqlName">
|
||||
{{ record.sqlName }}
|
||||
</a>
|
||||
</template>
|
||||
</BasicTable>
|
||||
<InputForm @register="registerDrawer" @success="handleSuccess" />
|
||||
<FormImport @register="registerImportModal" @success="handleSuccess" />
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup name="ViewsBizSqlStorageList">
|
||||
import { onMounted, ref, unref } from 'vue';
|
||||
import { useI18n } from '@jeesite/core/hooks/web/useI18n';
|
||||
import { useMessage } from '@jeesite/core/hooks/web/useMessage';
|
||||
import { useGlobSetting } from '@jeesite/core/hooks/setting';
|
||||
import { downloadByUrl } from '@jeesite/core/utils/file/download';
|
||||
import { router } from '@jeesite/core/router';
|
||||
import { Icon } from '@jeesite/core/components/Icon';
|
||||
import { BasicTable, BasicColumn, useTable } from '@jeesite/core/components/Table';
|
||||
import { BizSqlStorage, bizSqlStorageList } from '@jeesite/biz/api/biz/sqlStorage';
|
||||
import { bizSqlStorageDelete, bizSqlStorageExecute, bizSqlStorageListData } from '@jeesite/biz/api/biz/sqlStorage';
|
||||
import { useDrawer } from '@jeesite/core/components/Drawer';
|
||||
import { useModal } from '@jeesite/core/components/Modal';
|
||||
import { FormProps } from '@jeesite/core/components/Form';
|
||||
import InputForm from './form.vue';
|
||||
import FormImport from './formImport.vue';
|
||||
|
||||
const { t } = useI18n('biz.sqlStorage');
|
||||
const { showMessage } = useMessage();
|
||||
const { meta } = unref(router.currentRoute);
|
||||
const record = ref<BizSqlStorage>({} as BizSqlStorage);
|
||||
|
||||
const getTitle = {
|
||||
icon: meta.icon || 'i-ant-design:book-outlined',
|
||||
value: meta.title || t('数据开发管理'),
|
||||
};
|
||||
const loading = ref(false);
|
||||
|
||||
const searchForm: FormProps<BizSqlStorage> = {
|
||||
baseColProps: { md: 8, lg: 6 },
|
||||
labelWidth: 90,
|
||||
schemas: [
|
||||
{
|
||||
label: t('记录时间起'),
|
||||
field: 'createTime_gte',
|
||||
component: 'DatePicker',
|
||||
componentProps: {
|
||||
format: 'YYYY-MM-DD HH:mm',
|
||||
showTime: { format: 'HH:mm' },
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t('记录时间止'),
|
||||
field: 'createTime_lte',
|
||||
component: 'DatePicker',
|
||||
componentProps: {
|
||||
format: 'YYYY-MM-DD HH:mm',
|
||||
showTime: { format: 'HH:mm' },
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t('SQL名称'),
|
||||
field: 'sqlName',
|
||||
component: 'Input',
|
||||
},
|
||||
{
|
||||
label: t('SQL类型'),
|
||||
field: 'sqlType',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
dictType: 'sql_type',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t('数据库名称'),
|
||||
field: 'dbId',
|
||||
fieldLabel: 'dbName',
|
||||
component: 'ListSelect',
|
||||
componentProps: {
|
||||
selectType: 'bizDbSelect',
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t('执行结果'),
|
||||
field: 'executeResult',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
dictType: 'execute_result',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t('状态'),
|
||||
field: 'ustatus',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
dictType: 'ustatus',
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const tableColumns: BasicColumn<BizSqlStorage>[] = [
|
||||
{
|
||||
title: t('记录时间'),
|
||||
dataIndex: 'createTime',
|
||||
key: 'a.create_time',
|
||||
sorter: true,
|
||||
width: 180,
|
||||
align: 'left',
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
title: t('数据库名称'),
|
||||
dataIndex: 'dbName',
|
||||
key: 'b.db_name',
|
||||
sorter: true,
|
||||
width: 130,
|
||||
align: 'left',
|
||||
},
|
||||
{
|
||||
title: t('数据库IP'),
|
||||
dataIndex: 'dbIp',
|
||||
key: 'b.db_ip',
|
||||
sorter: true,
|
||||
width: 130,
|
||||
align: 'left',
|
||||
},
|
||||
{
|
||||
title: t('SQL名称'),
|
||||
dataIndex: 'sqlName',
|
||||
key: 'a.sql_name',
|
||||
sorter: true,
|
||||
width: 130,
|
||||
align: 'left',
|
||||
slot: 'slotBizKey',
|
||||
},
|
||||
{
|
||||
title: t('SQL类型'),
|
||||
dataIndex: 'sqlType',
|
||||
key: 'a.sql_type',
|
||||
sorter: true,
|
||||
width: 130,
|
||||
align: 'left',
|
||||
},
|
||||
{
|
||||
title: t('SQL描述'),
|
||||
dataIndex: 'sqlDesc',
|
||||
key: 'a.sql_desc',
|
||||
sorter: true,
|
||||
width: 130,
|
||||
align: 'left',
|
||||
},
|
||||
{
|
||||
title: t('更新时间'),
|
||||
dataIndex: 'updateTime',
|
||||
key: 'a.update_time',
|
||||
sorter: true,
|
||||
width: 180,
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
title: t('状态'),
|
||||
dataIndex: 'ustatus',
|
||||
key: 'a.ustatus',
|
||||
sorter: true,
|
||||
width: 130,
|
||||
align: 'left',
|
||||
dictType: 'ustatus',
|
||||
},
|
||||
{
|
||||
title: t('文件名称'),
|
||||
dataIndex: 'executeFile',
|
||||
key: 'a.execute_file',
|
||||
sorter: true,
|
||||
width: 130,
|
||||
align: 'left',
|
||||
},
|
||||
{
|
||||
title: t('执行时间'),
|
||||
dataIndex: 'executeTime',
|
||||
key: 'a.execute_time',
|
||||
sorter: true,
|
||||
width: 180,
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
title: t('执行结果'),
|
||||
dataIndex: 'executeResult',
|
||||
key: 'a.execute_result',
|
||||
sorter: true,
|
||||
width: 130,
|
||||
align: 'left',
|
||||
dictType: 'execute_result',
|
||||
},
|
||||
];
|
||||
|
||||
const actionColumn: BasicColumn<BizSqlStorage> = {
|
||||
width: 160,
|
||||
align: 'center',
|
||||
actions: (record: BizSqlStorage) => [
|
||||
{
|
||||
icon: 'i-clarity:note-edit-line',
|
||||
title: t('编辑'),
|
||||
onClick: handleForm.bind(this, { id: record.id }),
|
||||
auth: 'biz:sqlStorage:edit',
|
||||
},
|
||||
{
|
||||
icon: 'i-ant-design:delete-outlined',
|
||||
color: 'error',
|
||||
title: t('删除'),
|
||||
popConfirm: {
|
||||
title: t('是否确认删除脚本?'),
|
||||
confirm: handleDelete.bind(this, record),
|
||||
},
|
||||
auth: 'biz:sqlStorage:edit',
|
||||
ifShow: record.ustatus == '0'
|
||||
},
|
||||
{
|
||||
icon: 'simple-line-icons:check',
|
||||
color: 'success',
|
||||
title: t('运行'),
|
||||
popConfirm: {
|
||||
title: t('是否确认运行脚本?'),
|
||||
confirm: handleExecute.bind(this, record),
|
||||
},
|
||||
auth: 'biz:sqlStorage:edit',
|
||||
ifShow: record.ustatus == '1'
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const [registerTable, { reload, getForm }] = useTable<BizSqlStorage>({
|
||||
api: bizSqlStorageListData,
|
||||
beforeFetch: (params) => {
|
||||
return params;
|
||||
},
|
||||
columns: tableColumns,
|
||||
actionColumn: actionColumn,
|
||||
formConfig: searchForm,
|
||||
showTableSetting: true,
|
||||
useSearchForm: true,
|
||||
canResize: true,
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
const res = await bizSqlStorageList();
|
||||
record.value = (res.bizSqlStorage || {}) as BizSqlStorage;
|
||||
await getForm().setFieldsValue(record.value);
|
||||
});
|
||||
|
||||
const [registerDrawer, { openDrawer }] = useDrawer();
|
||||
|
||||
function handleForm(record: Recordable) {
|
||||
openDrawer(true, record);
|
||||
}
|
||||
|
||||
async function handleExport() {
|
||||
loading.value = true;
|
||||
const { ctxAdminPath } = useGlobSetting();
|
||||
await downloadByUrl({
|
||||
url: ctxAdminPath + '/biz/sqlStorage/exportData',
|
||||
params: getForm().getFieldsValue(),
|
||||
});
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
const [registerImportModal, { openModal: importModal }] = useModal();
|
||||
|
||||
function handleImport() {
|
||||
importModal(true, {});
|
||||
}
|
||||
|
||||
async function handleDelete(record: Recordable) {
|
||||
const params = { id: record.id };
|
||||
const res = await bizSqlStorageDelete(params);
|
||||
showMessage(res.message);
|
||||
await handleSuccess(record);
|
||||
}
|
||||
|
||||
async function handleExecute(record: Recordable) {
|
||||
const params = { id: record.id };
|
||||
const res = await bizSqlStorageExecute(params);
|
||||
showMessage(res.message);
|
||||
await handleSuccess(record);
|
||||
}
|
||||
|
||||
async function handleSuccess(record: Recordable) {
|
||||
await reload({ record });
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user