提交 f33f3e42 编写于 作者: sq3536's avatar sq3536

dict调整

上级 00c35f15
......@@ -20,10 +20,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Slf4j
@Service
......@@ -80,23 +77,57 @@ public class DictDstService
}
else
{
DictCatalog dictCatalog = dictCatalogService.getOne(Wrappers.<DictCatalog>query().eq("ccode",code));
catalog.setCode(dictCatalog.getCode()).setName(dictCatalog.getName());
String codeName=code;
String filter="";
String subCode="";
if(codeName.indexOf(".")>0)
{
String[] arg= codeName.split("[.]");
codeName=arg[0];
subCode=arg[1];
}
if(codeName.indexOf("-")>0)
{
String[] arg= codeName.split("-");
codeName=arg[0];
filter=arg[1];
}
DictCatalog dictCatalog = dictCatalogService.getOne(Wrappers.<DictCatalog>query().eq("ccode",codeName));
catalog.setCode(code).setName(dictCatalog.getName());
List<Option> list = new ArrayList<>();
optionService.list(context.getSelectCond().eq("cid",dictCatalog.getId()).orderByAsc("showorder")).forEach(item->{
Map<String,List<Option>> map = new LinkedHashMap<>();
Option subOption=null;
for(DictOption item:optionService.list(context.getSelectCond().eq("cid",dictCatalog.getId()).orderByAsc("showorder")))
{
Map<String,Object> extension = new HashMap<>();
if(!StringUtils.isEmpty(item.getExtension()))
extension = JSONObject.parseObject(item.getExtension(),Map.class);
list.add(new Option().setValue(item.getValue()).setId(item.getValue())
.setDisabled(((item.getDisabled()!=null && item.getDisabled()==1)||(item.getExpired()!=null && item.getExpired()==1))?true:false)
.setFilter(item.getFilter()).setIconClass(item.getIconClass()).setLabel(item.getLabel()).setParent(item.getParent()).setExtension(extension)
);
});
String pid=StringUtils.isEmpty(item.getParent())?"_root":item.getParent();
List<Option> list=null;
if(!map.containsKey(pid))
{
list=new ArrayList<>();
map.put(pid,list);
}
else
list=map.get(pid);
List<Option> codeItemTreeList = new ArrayList<Option>();
codeItemTreeList = loop(list, "");
Option option=new Option().setValue(item.getValue()).setId(item.getValue())
.setDisabled(((item.getDisabled()!=null && item.getDisabled()==1)||(item.getExpired()!=null && item.getExpired()==1))?true:false)
.setFilter(item.getFilter()).setIconClass(item.getIconClass()).setLabel(item.getLabel()).setParent(item.getParent()).setExtension(extension);
if(option.getValue().equals(subCode))
subOption=option;
if(StringUtils.isEmpty(filter)||option.getFilterSet().contains(filter))
list.add(option);
}
List<Option> codeItemTreeList = loop(map, (StringUtils.isEmpty(subCode))?"_root":subCode);
if(subOption!=null)
{
subOption.setChildren(codeItemTreeList).setParent("");
catalog.getOptions().add(subOption);
}
else
catalog.setOptions(codeItemTreeList);
}
return catalog;
......@@ -152,25 +183,67 @@ public class DictDstService
catalog.setOptions(list);
}
else {
DictCatalog dictCatalog = dictCatalogService.getOne(Wrappers.<DictCatalog>query().eq("ccode",code));
catalog.setCode(dictCatalog.getCode()).setName(dictCatalog.getName());
String codeName=code;
String filter="";
String subCode="";
if(codeName.indexOf(".")>0)
{
String[] arg= codeName.split("[.]");
codeName=arg[0];
subCode=arg[1];
}
if(codeName.indexOf("-")>0)
{
String[] arg= codeName.split("-");
codeName=arg[0];
filter=arg[1];
}
List<CodeItem> list = new ArrayList<>();
optionService.list(context.getSelectCond().eq("cid",dictCatalog.getId()).orderByAsc("showorder")).forEach(item->{
DictCatalog dictCatalog = dictCatalogService.getOne(Wrappers.<DictCatalog>query().eq("ccode",codeName));
catalog.setCode(code).setName(dictCatalog.getName());
Map<String,List<CodeItem>> map = new LinkedHashMap<>();
List<CodeItem> alllist = new ArrayList<>();
CodeItem subOption=null;
for(DictOption item:optionService.list(context.getSelectCond().eq("cid",dictCatalog.getId()).orderByAsc("showorder"))){
Map<String,Object> extension = new HashMap<>();
if(!StringUtils.isEmpty(item.getExtension()))
extension = JSONObject.parseObject(item.getExtension(),Map.class);
list.add(new CodeItem().setValue(item.getValue()).setId(item.getValue())
.setDisabled(((item.getDisabled()!=null && item.getDisabled()==1)||(item.getExpired()!=null && item.getExpired()==1))?true:false)
.setFilter(item.getFilter()).setIconClass(item.getIconClass()).setLabel(item.getLabel()).setParent(item.getParent()).setExtension(extension)
);
});
catalog.setOptions(list);
String pid=StringUtils.isEmpty(item.getParent())?"_root":item.getParent();
List<CodeItem> list=null;
if(!map.containsKey(pid))
{
list=new ArrayList<>();
map.put(pid,list);
}
else
list=map.get(pid);
CodeItem option=new CodeItem().setValue(item.getValue()).setId(item.getValue())
.setDisabled(((item.getDisabled()!=null && item.getDisabled()==1)||(item.getExpired()!=null && item.getExpired()==1))?true:false)
.setFilter(item.getFilter()).setIconClass(item.getIconClass()).setLabel(item.getLabel()).setParent(item.getParent()).setExtension(extension);
if(option.getValue().equals(subCode))
subOption=option;
if(StringUtils.isEmpty(filter)||option.getFilterSet().contains(filter))
{
alllist.add(option);
list.add(option);
}
}
if(subOption!=null)
{
List<CodeItem> codeItemTreeList = loopItem(map, subCode);
codeItemTreeList.add(0,subOption);
catalog.setOptions(codeItemTreeList);
}
else
catalog.setOptions(alllist);
}
return catalog;
}
......@@ -181,14 +254,10 @@ public class DictDstService
}
public List<Option> loop(List<Option> listCodeItem, Object parentValue) {
public List<Option> loop(Map<String,List<Option>> listCodeItem, Object parentValue) {
List<Option> trees = new ArrayList<Option>();
for (Option codeItem : listCodeItem) {
String codeItemParentValue = codeItem.getParent();
if (StringUtils.isEmpty(codeItemParentValue)) {
codeItemParentValue = "";
}
if (parentValue.equals(codeItemParentValue)) {
if(listCodeItem.containsKey(parentValue)) {
for (Option codeItem : listCodeItem.get(parentValue)) {
List<Option> childCodeItem = loop(listCodeItem, codeItem.getValue());
if (childCodeItem.size() > 0) {
codeItem.setChildren(childCodeItem);
......@@ -199,19 +268,15 @@ public class DictDstService
return trees;
}
public List<CodeItem> loopCodeItem(List<CodeItem> listCodeItem, Object parentValue) {
public List<CodeItem> loopItem(Map<String,List<CodeItem>> listCodeItem, Object parentValue) {
List<CodeItem> trees = new ArrayList<CodeItem>();
for (CodeItem codeItem : listCodeItem) {
String codeItemParentValue = codeItem.getParent();
if (StringUtils.isEmpty(codeItemParentValue)) {
codeItemParentValue = "";
}
if (parentValue.equals(codeItemParentValue)) {
List<CodeItem> childCodeItem = loopCodeItem(listCodeItem, codeItem.getValue());
if(listCodeItem.containsKey(parentValue)) {
for (CodeItem codeItem : listCodeItem.get(parentValue)) {
trees.add(codeItem);
List<CodeItem> childCodeItem = loopItem(listCodeItem, codeItem.getValue());
if (childCodeItem.size() > 0) {
codeItem.setChildren(childCodeItem);
trees.addAll(childCodeItem);
}
trees.add(codeItem);
}
}
return trees;
......
......@@ -720,7 +720,55 @@ public class BuildResultService {
@Cacheable( value="dataAnalyse",key="'rows:cg:'+#p0.getId()")
public FetchResult getReportConfig(FetchParam fetchParam)
{
prepareFetchParam(fetchParam);
String vmConfig="";
if(!StringUtils.isEmpty(fetchParam.getReportId()))
{
DAReport daReport = daReportService.getById(fetchParam.getReportId());
if(daReport != null) {
vmConfig = daReport.getConfig();
if(!StringUtils.isEmpty(daReport.getDict()))
fetchParam.setDimDict(daReport.getDict());
else
fetchParam.setDimDict("CL_DST_REGION");
if(!StringUtils.isEmpty(daReport.getGroup()))
fetchParam.setGroup(daReport.getGroup());
fetchParam.setTitle(daReport.getReportName());
}
}
else if(!StringUtils.isEmpty(fetchParam.getChartId()))
{
DAChart daChart = daChartService.getById(fetchParam.getChartId());
if(daChart != null) {
vmConfig = daChart.getConfig();
if(!StringUtils.isEmpty(daChart.getDict()))
fetchParam.setDimDict(daChart.getDict());
else
fetchParam.setDimDict("CL_DST_REGION");
if(!StringUtils.isEmpty(daChart.getGroup()))
fetchParam.setGroup(daChart.getGroup());
fetchParam.setTitle(daChart.getChartName());
}
}
if(!StringUtils.isEmpty(vmConfig)) {
fetchParam.setVmConfigs(JSONArray.parseArray(vmConfig,VMConfig.class));
}
if(!StringUtils.isEmpty(fetchParam.getDimDict())) {
Catalog dict = dictDstService.getDictCatalog(fetchParam.getDimDict());
if (StringUtils.isEmpty(fetchParam.getGroup()))
fetchParam.setGroup(dict.getName());
Assert.notNull(dict, "未找到数据字典" + fetchParam.getDimDict());
Assert.notEmpty(dict.getOptions(), "未找到数据字典" + fetchParam.getDimDict());
fetchParam.setDict(dict);
Option dimItem = null;
if (StringUtils.isEmpty(fetchParam.getDimValue())) {
dimItem = dict.getOptions().get(0);
fetchParam.setDimValue(dimItem.getValue().toString());
}
}
return FetchResult.from(fetchParam);
}
......
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-3.9.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.9.xsd">
<changeSet author="mac (generated)" id="1631273658303-1">
<preConditions onFail="MARK_RAN" >
<not>
<columnExists tableName="IBZDICTCATALOG" columnName="EXTPARAMS" />
</not>
</preConditions>
<addColumn tableName="IBZDICTCATALOG">
<column name="EXTPARAMS" type="CLOB(2147483647)"/>
</addColumn>
</changeSet>
</databaseChangeLog>
......@@ -4,14 +4,17 @@ package cn.ibizlab.util.dict;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import liquibase.util.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@Getter
@Setter
......@@ -40,4 +43,15 @@ public class CodeItem
{
return label;
}
@JsonIgnore
@JSONField(serialize = false)
public Set<String> getFilterSet()
{
Set<String> set=new HashSet<>();
if(!StringUtils.isEmpty(filter))
for(String str:filter.split(";|,"))
set.add(str);
return set;
}
}
......@@ -4,13 +4,17 @@ package cn.ibizlab.util.dict;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import liquibase.util.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@Getter
@Setter
......@@ -31,4 +35,14 @@ public class Option
private String parent;
private Map<String,Object> extension;
@JsonIgnore
@JSONField(serialize = false)
public Set<String> getFilterSet()
{
Set<String> set=new HashSet<>();
if(!StringUtils.isEmpty(filter))
for(String str:filter.split(";|,"))
set.add(str);
return set;
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册