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

dict 本地化

上级 361bb9ce
package cn.ibizlab.core.dict.extensions.aspect;
import cn.ibizlab.core.dict.domain.DictCatalog;
import cn.ibizlab.core.dict.extensions.service.DictCoreService;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
@Aspect
@Order(0)
@Component
public class CacheRefreshAspect
{
@Autowired
@Lazy
private DictCoreService dictCoreService;
@Before(value = "execution(* cn.ibizlab.core.dict.service.IDictCatalogService.update(..))")
public void BeforeUpdateEmp(JoinPoint point) throws Exception {
refreshDictCache(point);
}
@Before(value = "execution(* cn.ibizlab.core.dict.service.IDictCatalogService.save(..))")
public void BeforeSaveEmp(JoinPoint point) throws Exception {
refreshDictCache(point);
}
private void refreshDictCache(JoinPoint point)
{
Object[] args = point.getArgs();
if (args.length > 0)
{
Object obj = args[0];
if(obj instanceof DictCatalog)
{
String code=((DictCatalog) obj).getCode();
if(!StringUtils.isEmpty(code)) {
dictCoreService.resetDictCatalog(code);
dictCoreService.resetCodeListCatalog(code);
}
}
}
}
}
package cn.ibizlab.core.dict.extensions.service;
import cn.ibizlab.core.dict.domain.DictCatalog;
import cn.ibizlab.core.dict.domain.DictOption;
import cn.ibizlab.core.dict.filter.DictOptionSearchContext;
import cn.ibizlab.core.dict.service.IDictCatalogService;
import cn.ibizlab.core.dict.service.IDictOptionService;
import cn.ibizlab.util.dict.Catalog;
import cn.ibizlab.util.dict.CodeItem;
import cn.ibizlab.util.dict.CodeList;
import cn.ibizlab.util.dict.Option;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
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;
@Slf4j
@Service
public class DictCoreService
{
@Autowired
private IDictCatalogService dictCatalogService;
@Autowired
private IDictOptionService optionService;
@Cacheable( value="dictcatalog",key = "'dict:'+#p0")
public Catalog getDictCatalog(String code){
return getDictCatalog(code,new DictOptionSearchContext());
}
public Catalog getDictCatalog(String code, DictOptionSearchContext context)
{
Catalog catalog = new Catalog();
if(code.equalsIgnoreCase("dictcatalog"))
{
catalog.setCode("DictCatalog");
catalog.setName("字典目录");
List<Option> list = new ArrayList<>();
LambdaQueryWrapper<DictCatalog> wrapper=Wrappers.lambdaQuery();
if(!StringUtils.isEmpty(context.getN_val_like()))
wrapper.like(DictCatalog::getCode,context.getN_val_like());
if(!StringUtils.isEmpty(context.getN_val_in()))
wrapper.in(DictCatalog::getCode,context.getN_val_in());
if(!StringUtils.isEmpty(context.getN_val_leftlike()))
wrapper.likeRight(DictCatalog::getCode,context.getN_val_leftlike());
if(!StringUtils.isEmpty(context.getN_val_notin()))
wrapper.notIn(DictCatalog::getCode,context.getN_val_notin());
if(!StringUtils.isEmpty(context.getN_label_like()))
wrapper.notIn(DictCatalog::getName,context.getN_label_like());
if(!StringUtils.isEmpty(context.getN_vfilter_like()))
wrapper.like(DictCatalog::getGroup,context.getN_vfilter_like());
if(!StringUtils.isEmpty(context.getN_vfilter_in()))
wrapper.in(DictCatalog::getGroup,context.getN_vfilter_in());
if(!StringUtils.isEmpty(context.getN_vfilter_leftlike()))
wrapper.likeRight(DictCatalog::getGroup,context.getN_vfilter_leftlike());
if(!StringUtils.isEmpty(context.getN_vfilter_eq()))
wrapper.eq(DictCatalog::getGroup,context.getN_vfilter_eq());
wrapper.orderByAsc(DictCatalog::getGroup, DictCatalog::getCode);
dictCatalogService.list(wrapper).forEach(item->{
list.add(new Option().setValue(item.getCode()).setId(item.getCode())
.setDisabled(false)
.setFilter(item.getGroup()).setLabel(item.getName())
);
});
catalog.setOptions(list);
}
else
{
DictCatalog dictCatalog = dictCatalogService.getOne(Wrappers.<DictCatalog>query().eq("ccode",code));
catalog.setCode(dictCatalog.getCode()).setName(dictCatalog.getName());
List<Option> list = new ArrayList<>();
optionService.list(context.getSelectCond().eq("cid",dictCatalog.getId()).orderByAsc("showorder")).forEach(item->{
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)
);
});
List<Option> codeItemTreeList = new ArrayList<Option>();
codeItemTreeList = loop(list, "");
catalog.setOptions(codeItemTreeList);
}
return catalog;
}
@CacheEvict(value="dictcatalog",key = "'dict:'+#p0")
public void resetDictCatalog(String code)
{
}
@Cacheable( value="dictcatalog",key = "'codelist:'+#p0")
public CodeList getCodeListCatalog(String code){
return getCodeListCatalog(code,new DictOptionSearchContext());
}
public CodeList getCodeListCatalog(String code, DictOptionSearchContext context)
{
CodeList catalog = new CodeList();
if(code.equalsIgnoreCase("dictcatalog"))
{
catalog.setCode("DictCatalog");
catalog.setName("字典目录");
List<CodeItem> list = new ArrayList<>();
LambdaQueryWrapper<DictCatalog> wrapper=Wrappers.lambdaQuery();
if(!StringUtils.isEmpty(context.getN_val_like()))
wrapper.like(DictCatalog::getCode,context.getN_val_like());
if(!StringUtils.isEmpty(context.getN_val_in()))
wrapper.in(DictCatalog::getCode,context.getN_val_in());
if(!StringUtils.isEmpty(context.getN_val_leftlike()))
wrapper.likeRight(DictCatalog::getCode,context.getN_val_leftlike());
if(!StringUtils.isEmpty(context.getN_val_notin()))
wrapper.notIn(DictCatalog::getCode,context.getN_val_notin());
if(!StringUtils.isEmpty(context.getN_label_like()))
wrapper.notIn(DictCatalog::getName,context.getN_label_like());
if(!StringUtils.isEmpty(context.getN_vfilter_like()))
wrapper.like(DictCatalog::getGroup,context.getN_vfilter_like());
if(!StringUtils.isEmpty(context.getN_vfilter_in()))
wrapper.in(DictCatalog::getGroup,context.getN_vfilter_in());
if(!StringUtils.isEmpty(context.getN_vfilter_leftlike()))
wrapper.likeRight(DictCatalog::getGroup,context.getN_vfilter_leftlike());
if(!StringUtils.isEmpty(context.getN_vfilter_eq()))
wrapper.eq(DictCatalog::getGroup,context.getN_vfilter_eq());
wrapper.orderByAsc(DictCatalog::getGroup, DictCatalog::getCode);
dictCatalogService.list(wrapper).forEach(item->{
list.add(new CodeItem().setValue(item.getCode()).setId(item.getCode())
.setDisabled(false)
.setFilter(item.getGroup()).setLabel(item.getName())
);
});
catalog.setOptions(list);
}
else {
DictCatalog dictCatalog = dictCatalogService.getOne(Wrappers.<DictCatalog>query().eq("ccode",code));
catalog.setCode(dictCatalog.getCode()).setName(dictCatalog.getName());
List<CodeItem> list = new ArrayList<>();
optionService.list(context.getSelectCond().eq("cid",dictCatalog.getId()).orderByAsc("showorder")).forEach(item->{
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);
}
return catalog;
}
@CacheEvict(value="dictcatalog",key = "'codelist:'+#p0")
public void resetCodeListCatalog(String code)
{
}
public List<Option> loop(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)) {
List<Option> childCodeItem = loop(listCodeItem, codeItem.getValue());
if (childCodeItem.size() > 0) {
codeItem.setChildren(childCodeItem);
}
trees.add(codeItem);
}
}
return trees;
}
public List<CodeItem> loopCodeItem(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 (childCodeItem.size() > 0) {
codeItem.setChildren(childCodeItem);
}
trees.add(codeItem);
}
}
return trees;
}
}
......@@ -2,6 +2,7 @@ package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.analysis.domain.DADimension;
import cn.ibizlab.core.analysis.service.IDABuildService;
import cn.ibizlab.core.dict.extensions.service.DictCoreService;
import cn.ibizlab.core.extensions.cql.ExecResult;
import cn.ibizlab.core.extensions.domain.BaseRequest;
import cn.ibizlab.core.extensions.domain.ResultsMQMsg;
......@@ -41,7 +42,7 @@ public class AnalyseEntityServiceImpl extends BaseEntityServiceImpl {
@Autowired
@Lazy
private cn.ibizlab.util.client.IBZDictFeignClient ibzDictFeignClient;
private DictCoreService dictCoreService;
@Override
public void saveResult(ModelObj param, String RULEID,String RULECODE, String RULENAME, String RU_EXECRESULTNAME, FieldObj BUSINESSCAT,
......@@ -123,7 +124,7 @@ public class AnalyseEntityServiceImpl extends BaseEntityServiceImpl {
//维度指定代码表时,向上同时为每一个父节点添加一条数据
while(true)
{
CodeItem code=ibzDictFeignClient.getCodeList(dictname).findCodeItem(val);
CodeItem code=dictCoreService.getCodeListCatalog(dictname).findCodeItem(val);
if(code!=null)
{
ExecResult result2 = new ExecResult();
......
......@@ -4,6 +4,7 @@ import cn.ibizlab.core.analysis.domain.DAMetric;
import cn.ibizlab.core.analysis.domain.DAReport;
import cn.ibizlab.core.analysis.filter.DAMetricSearchContext;
import cn.ibizlab.core.analysis.service.impl.DAReportServiceImpl;
import cn.ibizlab.core.dict.extensions.service.DictCoreService;
import cn.ibizlab.core.extensions.cql.ExecResult;
import cn.ibizlab.core.extensions.cql.ExecResultRepository;
import cn.ibizlab.core.extensions.domain.FetchMetricDatasParam;
......@@ -52,7 +53,7 @@ public class DACoreService {
@Autowired
@Lazy
private cn.ibizlab.util.client.IBZDictFeignClient ibzDictFeignClient;
private DictCoreService dictCoreService;
@Autowired
@Lazy
......@@ -278,7 +279,7 @@ public class DACoreService {
Hashtable<String,HashMap<String,Object>> dimsSet = new Hashtable<>();
// CodeItem code=CodeListBase.getCodeList(dimcodelist).getCodeList().getCodeItemModelMap().get(dimval);
CodeItem code=ibzDictFeignClient.getCodeList(dimcodelist).findChildren(dimval);
CodeItem code=dictCoreService.getCodeListCatalog(dimcodelist).findChildren(dimval);
if(code==null)
return null;
int no=1;
......
package cn.ibizlab.api.rest.extensions;
import cn.ibizlab.core.dict.extensions.service.DictCoreService;
import cn.ibizlab.core.lite.domain.DstSystem;
import cn.ibizlab.core.lite.domain.MetaField;
import cn.ibizlab.core.lite.extensions.domain.*;
......@@ -124,7 +125,7 @@ public class DstCoreResource {
}
@Autowired
private IBZDictFeignClient dictFeignClient;
private DictCoreService dictCoreService;
@RequestMapping(method = RequestMethod.GET, value = {"/dst/datamodels/{modelid}/{propertyname}.{fieldname}/dict"})
public ResponseEntity<List<CodeItem>> getDataModelFieldDict(@PathVariable(name="modelid",required = false) String modelid,
......@@ -141,7 +142,7 @@ public class DstCoreResource {
String dict = field.getDict();
if(!StringUtils.isEmpty(dict))
{
CodeList codeList=dictFeignClient.getCodeList(dict);
CodeList codeList=dictCoreService.getCodeListCatalog(dict);
if(codeList!=null)
list=codeList.getOptions();
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册