|
|
|
@ -1,11 +1,16 @@
|
|
|
|
|
package com.ibeetl.admin.core.service;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import com.ibeetl.admin.core.annotation.Dict;
|
|
|
|
|
import com.ibeetl.admin.core.annotation.Query;
|
|
|
|
|
import com.ibeetl.admin.core.dao.CoreDictDao;
|
|
|
|
|
import com.ibeetl.admin.core.entity.CoreDict;
|
|
|
|
|
import com.ibeetl.admin.core.entity.CoreUser;
|
|
|
|
|
import com.ibeetl.admin.core.util.BeetlSqlKit;
|
|
|
|
|
import com.ibeetl.admin.core.util.enums.DelFlagEnum;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.beetl.core.BeetlKit;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
@ -17,6 +22,8 @@ import java.util.*;
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
import static com.ibeetl.admin.core.util.user.CacheUserUtil.getUser;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 描述: 字典 service,包含常规字典和级联字典的操作。
|
|
|
|
|
* @author : TLT
|
|
|
|
@ -51,10 +58,15 @@ public class CoreDictService extends CoreBaseService<CoreDict> {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据表和行名获取字典集合 表名.存中文的那一行.参数 参数按照 参数名 条件,参数名 条件...的格式 采用英文逗号
|
|
|
|
|
* {@link Query} 的最终实现方法
|
|
|
|
|
* {@link Dict} 的最终实现方法
|
|
|
|
|
* @return List
|
|
|
|
|
*/
|
|
|
|
|
@Cacheable(value = CorePlatformService.DICT_CACHE_TYPE, key="#type")
|
|
|
|
|
public List<CoreDict> findAllByTable(String type) {
|
|
|
|
|
|
|
|
|
|
type = renderStringTemplate(type, null);
|
|
|
|
|
|
|
|
|
|
String[] str = type.split("\\.");
|
|
|
|
|
String tableName = null,filedName = null,params = null;
|
|
|
|
|
if(str.length>0)
|
|
|
|
@ -98,7 +110,50 @@ public class CoreDictService extends CoreBaseService<CoreDict> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Cacheable(value = "core.coreDict.findCoreDictByTable", key="#type+\"_\"+#value")
|
|
|
|
|
/**
|
|
|
|
|
* 全局的变量
|
|
|
|
|
*/
|
|
|
|
|
static Map<String, String> GLOBAL_PARAMS = MapUtil.<String, String>builder()
|
|
|
|
|
// 通过身份判断,只查询我自己的机构
|
|
|
|
|
.put("seeMyOrgByRole", "${user.isAdmin ? '1=1' : 'find_in_set(org_id,' + user.orgId +')'}")
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 走beetl的渲染
|
|
|
|
|
* @param script
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private String renderStringTemplate(String script, Map<String, Object> params) {
|
|
|
|
|
try {
|
|
|
|
|
// 获取当前登录人的用户信息。通过request的header中获取
|
|
|
|
|
CoreUser loginUser = getUser();
|
|
|
|
|
// 有使用到beetl模块
|
|
|
|
|
if (script.indexOf("${") >= 0) {
|
|
|
|
|
if (params == null) {
|
|
|
|
|
params = new HashMap<>();
|
|
|
|
|
params.putAll(GLOBAL_PARAMS);
|
|
|
|
|
}
|
|
|
|
|
if (loginUser != null && !params.containsKey("user")) {
|
|
|
|
|
params.put("user", loginUser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String resultScript = BeetlKit.render(script, params);
|
|
|
|
|
|
|
|
|
|
if (resultScript.indexOf("${") >= 0) {
|
|
|
|
|
return renderStringTemplate(resultScript, params);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resultScript;
|
|
|
|
|
}
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
System.out.println(e.getMessage());
|
|
|
|
|
return script;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return script;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Cacheable(value = "core.coreDict.findCoreDictByTable", key="#type+\"_\"+#value")
|
|
|
|
|
public CoreDict findCoreDictByTable(String type,String value) {
|
|
|
|
|
List<CoreDict> list = findAllByTable(type);
|
|
|
|
|
if(list==null) {
|
|
|
|
|