增加Query和Dict的Beetl模块支持。

beetlsql3-dev
Mlxa0324
parent a6c4bf298e
commit 31c892d32a

@ -79,6 +79,8 @@ public class CoreBaseAnnotationParser {
do {
List<Field> fields = Arrays.asList(c.getDeclaredFields());
for (Field field : fields) {
// 字典查询,也可以查询普通表
if (field.isAnnotationPresent(Dict.class)) {
field.setAccessible(true);
Dict dict = field.getAnnotation(Dict.class);
@ -107,6 +109,7 @@ public class CoreBaseAnnotationParser {
}
}
// 深度解析注解
if (field.isAnnotationPresent(DictDeep.class)) {
field.setAccessible(true);

@ -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) {

@ -26,7 +26,7 @@ public class TeacherOpenCourseQuery extends PageParam {
// @Query(name = "封面列表JSON格式: {封面URLis默认封面}", display = false)
@Query(name = "封面列表", display = false)
private String teacherOpenCourseCover;
@Query(name = "上课教师", display = true, type = Query.TYPE_DICT, dict = "teacher.teacher_name.teacher_status=1")
@Query(name = "上课教师", display = true, type = Query.TYPE_DICT, dict = "teacher.teacher_name.teacher_status=1,${seeMyOrgByRole}")
private Long teacherId;
// @Query(name = "开课状态1启用 2禁用", display = true,type=Query.TYPE_DICT,dict=GLOBAL_OPEN_STATUS)
@Query(name = "开课状态", display = true, type = Query.TYPE_DICT, dict = GLOBAL_OPEN_STATUS)

@ -79,6 +79,7 @@ queryAllAuthCourseInfoByCondition
t.use_end_time,
t.second_level_name,
t.second_level_logo,
tb.universities_colleges_name,
ta.`course_info_id`,
ta.`course_info_full_id`,
ta.`course_info_name`,
@ -99,7 +100,6 @@ queryAllAuthCourseInfoByCondition
ta.`add_time`,
ta.org_id,
ta.user_id,
tb.universities_colleges_name,
tc.course_label_type,
tc.course_label_name
from course_info ta

Loading…
Cancel
Save