refactor(chart): 优化图表模板和记录功能

This commit is contained in:
曾文豪
2025-06-03 09:28:46 +08:00
parent 9363d08308
commit 94f93f8a80
5 changed files with 64 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
package com.tiesheng.role.controller; package com.tiesheng.role.controller;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.style.row.SimpleRowHeightStyleStrategy; import com.alibaba.excel.write.style.row.SimpleRowHeightStyleStrategy;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
@@ -56,6 +57,10 @@ public class ChartRecordController {
dto.getTableXField(), dto.getWhere(), dto.getTableXField(), dto.getWhere(),
dto.getTemplate().getSField(), dto.getTemplate().getSField(),
dto.getTableGroupBy()); dto.getTableGroupBy());
chartRecordVOS.forEach(it -> {
it.put("xField", StrUtil.emptyToDefault(it.getString("xField"), "未分类"));
});
return ApiResp.respOK(TsTableVO.of(dto.getTemplate(), chartRecordVOS)); return ApiResp.respOK(TsTableVO.of(dto.getTemplate(), chartRecordVOS));
} catch (Exception e) { } catch (Exception e) {
throw new ApiException("表或字段配置有误,请检查"); throw new ApiException("表或字段配置有误,请检查");
@@ -81,6 +86,7 @@ public class ChartRecordController {
} }
List<List<String>> contents = new ArrayList<>(); List<List<String>> contents = new ArrayList<>();
for (JSONObject obj : tsTableVO.getDataSource()) { for (JSONObject obj : tsTableVO.getDataSource()) {
List<String> data = new ArrayList<>(); List<String> data = new ArrayList<>();

View File

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tiesheng.annotation.role.RoleAuthority; import com.tiesheng.annotation.role.RoleAuthority;
import com.tiesheng.annotation.token.TokenIgnore;
import com.tiesheng.role.pojos.dao.CoreChartTable; import com.tiesheng.role.pojos.dao.CoreChartTable;
import com.tiesheng.role.pojos.dao.CoreChartTemplate; import com.tiesheng.role.pojos.dao.CoreChartTemplate;
import com.tiesheng.role.pojos.dto.ChartTableEditDTO; import com.tiesheng.role.pojos.dto.ChartTableEditDTO;
@@ -143,4 +144,19 @@ public class ChartTemplateController {
return ApiResp.respOK(""); return ApiResp.respOK("");
} }
/**
* 获取table详情
*
* @return
*/
@GetMapping("/table/info")
@TokenIgnore
public ApiResp<CoreChartTable> getTableInfo(String tableName) {
return ApiResp.respOK(chartService.getCoreChartTableMapper().selectOne(new QueryWrapper<CoreChartTable>()
.eq("is_deleted", 0)
.eq("table_name", tableName)
.last("limit 1")
));
}
} }

View File

@@ -1,5 +1,6 @@
package com.tiesheng.role.pojos.dto; package com.tiesheng.role.pojos.dto;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
@@ -16,12 +17,15 @@ public class ChartTemplateCheck {
private String templateId; private String templateId;
private CoreChartTemplate template; private CoreChartTemplate template;
private String xFormat;
private List<ChartTemplateEditDTO.TemplateExt> exts;
@JSONField(serialize = false) @JSONField(serialize = false)
public String getTableXField() { public String getTableXField() {
if (StrUtil.isNotEmpty(template.getXFormat())) { String tmpXFormat = StrUtil.emptyToDefault(getXFormat(), getTemplate().getXFormat());
return StrUtil.format("DATE_FORMAT({},'{}')", getTemplate().getXField(), getTemplate().getXFormat()); if (StrUtil.isNotEmpty(tmpXFormat)) {
return StrUtil.format("DATE_FORMAT({},'{}')", getTemplate().getXField(), tmpXFormat);
} }
return getTemplate().getXField(); return getTemplate().getXField();
} }
@@ -44,13 +48,19 @@ public class ChartTemplateCheck {
@JSONField(serialize = false) @JSONField(serialize = false)
public String getWhere() { public String getWhere() {
List<ChartTemplateEditDTO.TemplateExt> templateExts = JSON.parseArray(getTemplate().getExts(), ChartTemplateEditDTO.TemplateExt.class); if (CollUtil.isEmpty(getExts())) {
if (templateExts == null || templateExts.isEmpty()) { setExts(JSON.parseArray(getTemplate().getExts(), ChartTemplateEditDTO.TemplateExt.class));
}
if (CollUtil.isEmpty(getExts())) {
return ""; return "";
} }
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
for (ChartTemplateEditDTO.TemplateExt templateExt : templateExts) { for (ChartTemplateEditDTO.TemplateExt templateExt : getExts()) {
if (templateExt.isErrorExt()) {
continue;
}
if (Objects.equals(templateExt.getAction(), "eq")) { if (Objects.equals(templateExt.getAction(), "eq")) {
list.add(StrUtil.format("{} = '{}'", templateExt.getKey(), templateExt.getValue())); list.add(StrUtil.format("{} = '{}'", templateExt.getKey(), templateExt.getValue()));
} else if (Objects.equals(templateExt.getAction(), "ne")) { } else if (Objects.equals(templateExt.getAction(), "ne")) {

View File

@@ -1,5 +1,7 @@
package com.tiesheng.role.pojos.dto; package com.tiesheng.role.pojos.dto;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
@@ -35,6 +37,18 @@ public class ChartTemplateEditDTO {
private String key; private String key;
private String action; private String action;
private String value; private String value;
/**
* 该数据是否有效
*
* @return
*/
@JSONField(serialize = false)
public boolean isErrorExt() {
return StrUtil.isEmpty(getKey()) || StrUtil.isEmpty(getAction()) || StrUtil.isEmpty(getValue());
}
} }
} }

View File

@@ -6,9 +6,21 @@ public class IdName {
private String name; private String name;
private String extra; private String extra;
public IdName(String id, String name) {
this.id = id;
this.name = name;
}
public IdName(String id, String name, String extra) {
this.id = id;
this.name = name;
this.extra = extra;
}
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// setter\getter // setter\getter
///////////////////////////////////////////////////////////////////////////
/// ////////////////////////////////////////////////////////////////////////
public String getId() { public String getId() {
return id; return id;