增加java枚举注解;

增加深度解析注解;
beetlsql3-dev
Mlxa0324 3 years ago
parent 6132346d5c
commit ef4cfb9ee0

@ -0,0 +1,38 @@
package com.ibeetl.admin.core.annotation;
import org.springframework.core.annotation.AliasFor;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* <p>
* Java
* </p>
*
* @author mlx
* @date 2022/9/21
* @modified
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface DictEnum {
/**
*
* @return
*/
String value() default "text";
@AliasFor("value")
String type() default "text";
/**
*
*
* @return
*/
String suffix() default "Text";
}

@ -0,0 +1,27 @@
package com.ibeetl.admin.core.conf;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.annotation.PostConstruct;
/**
* 使null
* @author lx
*/
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Autowired
private ObjectMapper objectMapper;
@PostConstruct
public void myObjectMapper() {
// 解决enum不匹配问题 默认值为false
objectMapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);
}
}

@ -1,6 +1,12 @@
package com.ibeetl.admin.core.service;
import cn.hutool.core.exceptions.UtilException;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import com.ibeetl.admin.core.annotation.Dict;
import com.ibeetl.admin.core.annotation.DictDeep;
import com.ibeetl.admin.core.annotation.DictEnum;
import com.ibeetl.admin.core.entity.CoreDict;
import com.ibeetl.admin.core.util.PlatformException;
import com.ibeetl.admin.core.util.enums.DelFlagEnum;
@ -9,6 +15,7 @@ import org.beetl.sql.core.TailBean;
import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.HashMap;
@ -26,75 +33,80 @@ public class CoreBaseService<T> {
protected CoreDictService dictUtil;
@Resource
protected SQLManager sqlManager;
/**
* idID
*
* @param id
* @return
*/
public T queryById(Object id) {
T t = sqlManager.single(getCurrentEntityClassz(), id);
queryEntityAfter((Object) t);
queryEntityAfter((Object) t);
return t;
}
/**
* List
*
* @param paras
* @return
*/
public <T> List<T> queryObjectList(Object paras) {
if(!(paras instanceof TailBean)){
throw new PlatformException("指定的pojo"+paras.getClass()+" 不能获取数据字典需要继承TailBean");
if (!(paras instanceof TailBean)) {
throw new PlatformException("指定的pojo" + paras.getClass() + " 不能获取数据字典需要继承TailBean");
}
return (List<T>) sqlManager.template(paras);
}
/**
* List
*
* @param paras
* @return
*/
public <T> List<T> queryByObject(Object paras,String orderBy) {
if(!(paras instanceof TailBean)){
throw new PlatformException("指定的pojo"+paras.getClass()+" 不能获取数据字典需要继承TailBean");
public <T> List<T> queryByObject(Object paras, String orderBy) {
if (!(paras instanceof TailBean)) {
throw new PlatformException("指定的pojo" + paras.getClass() + " 不能获取数据字典需要继承TailBean");
}
TailBean ext = (TailBean)paras;
TailBean ext = (TailBean) paras;
Class c = ext.getClass();
return (List<T>) sqlManager.template(c);
}
/**
* List
*
* @param paras
* @return
*/
public <T> T queryObject(T paras) {
if(!(paras instanceof TailBean)){
throw new PlatformException("指定的pojo"+paras.getClass()+" 不能获取数据字典需要继承TailBean");
if (!(paras instanceof TailBean)) {
throw new PlatformException("指定的pojo" + paras.getClass() + " 不能获取数据字典需要继承TailBean");
}
List<T> list = (List<T>) sqlManager.template(paras);
T t = null;
if(list.size() > 0) {
t = list.get(0);
if (list.size() > 0) {
t = list.get(0);
}
return t;
}
/**
* mapList
*
* @param paras
* @return
*/
public <T> List<T> queryByObject(Class c,Object paras,String orderBy) {
public <T> List<T> queryByObject(Class c, Object paras, String orderBy) {
return (List<T>) sqlManager.template(c);
}
/**
* id
*
* @param classz
* @param id id
* @return
@ -107,6 +119,7 @@ public class CoreBaseService<T> {
/**
*
*
* @param model
* @return
*/
@ -116,21 +129,23 @@ public class CoreBaseService<T> {
/**
* ID
*
* @param model
* @return
*/
public boolean insert(T model) {
return sqlManager.insert(model)> 0;
return sqlManager.insert(model) > 0;
}
/**
*
*
* @param list
* @return
*/
public boolean saveBatch(List<T> list){
if(list.size()>0) {
return sqlManager.insertBatch(list.get(0).getClass(),list).length > 0;
public boolean saveBatch(List<T> list) {
if (list.size() > 0) {
return sqlManager.insertBatch(list.get(0).getClass(), list).length > 0;
} else {
return false;
}
@ -138,20 +153,23 @@ public class CoreBaseService<T> {
/**
* ID
*
* @param list
* @return
*/
public boolean insertBatch(List<T> list){
public boolean insertBatch(List<T> list) {
return insertBatch(list, true);
}
/**
* ID
*
* @param list
* @return
*/
public boolean insertBatch(List<T> list, Boolean autoDbAssignKey){
if(list.size()>0) {
return sqlManager.insertBatch(list.get(0).getClass(),list).length > 0;
public boolean insertBatch(List<T> list, Boolean autoDbAssignKey) {
if (list.size() > 0) {
return sqlManager.insertBatch(list.get(0).getClass(), list).length > 0;
} else {
return false;
}
@ -159,6 +177,7 @@ public class CoreBaseService<T> {
/**
* del_flag1
*
* @param ids
* @return
*/
@ -188,20 +207,22 @@ public class CoreBaseService<T> {
map.put("id", id);
map.put("delFlag", DelFlagEnum.DELETED.getValue());
int ret = sqlManager.updateTemplateById(getCurrentEntityClassz(), map);
return ret==1;
return ret == 1;
}
public boolean deleteById(Long id) {
Map map = new HashMap();
// always id,delFlag for pojo
map.put("id", id);
map.put("delFlag", DelFlagEnum.DELETED.getValue());
int ret = sqlManager.updateTemplateById(getCurrentEntityClassz(), map);
return ret==1;
Map map = new HashMap();
// always id,delFlag for pojo
map.put("id", id);
map.put("delFlag", DelFlagEnum.DELETED.getValue());
int ret = sqlManager.updateTemplateById(getCurrentEntityClassz(), map);
return ret == 1;
}
/**
* id
*
* @param id
* @return
*/
@ -211,6 +232,7 @@ public class CoreBaseService<T> {
/**
* id
*
* @param id
* @return
*/
@ -220,29 +242,32 @@ public class CoreBaseService<T> {
/**
*
*
* @param model
* @return
*/
public boolean updateTemplate(T model) {
return sqlManager.updateTemplateById(model)>0;
return sqlManager.updateTemplateById(model) > 0;
}
/**
*
*
* @param model
* @return
*/
public boolean update(T model) {
return sqlManager.updateById(model) > 0;
return sqlManager.updateById(model) > 0;
}
/**
*
*
* @param list
* @return
*/
public boolean updateBatch(List<T> list) {
if(list.size()>0) {
if (list.size() > 0) {
return sqlManager.updateByIdBatch(list).length > 0;
} else {
return false;
@ -251,21 +276,22 @@ public class CoreBaseService<T> {
/**
*
*
* @param list
* @return
*/
public boolean updateBatchTemplate(List<T> list) {
if(list.size()>0) {
return sqlManager.updateBatchTemplateById(list.get(0).getClass(),list).length > 0;
if (list.size() > 0) {
return sqlManager.updateBatchTemplateById(list.get(0).getClass(), list).length > 0;
} else {
return false;
}
}
/**
* T
*
* @return
*/
@SuppressWarnings("unchecked")
@ -280,16 +306,16 @@ public class CoreBaseService<T> {
}
}
public void queryEntityAfter(Object bean) {
public void queryEntityAfter(Object bean) {
if (bean == null) {
return;
}
if(!(bean instanceof TailBean)){
throw new PlatformException("指定的pojo"+bean.getClass()+" 不能获取数据字典需要继承TailBean");
if (!(bean instanceof TailBean)) {
throw new PlatformException("指定的pojo" + bean.getClass() + " 不能获取数据字典需要继承TailBean");
}
TailBean ext = (TailBean)bean;
TailBean ext = (TailBean) bean;
Class c = ext.getClass();
do {
Field[] fields = c.getDeclaredFields();
@ -297,26 +323,65 @@ public class CoreBaseService<T> {
if (field.isAnnotationPresent(Dict.class)) {
field.setAccessible(true);
Dict dict = field.getAnnotation(Dict.class);
try {
String display = "";
Object fieldValue = field.get(ext);
if (fieldValue != null) {
CoreDict dbDict = dict.type().contains(".")?dictUtil.findCoreDictByTable(dict.type(),fieldValue.toString()):dictUtil.findCoreDict(dict.type(),fieldValue.toString());
display = dbDict!=null?dbDict.getName():null;
CoreDict dbDict = dict.type().contains(".") ? dictUtil.findCoreDictByTable(dict.type(), fieldValue.toString()) : dictUtil.findCoreDict(dict.type(), fieldValue.toString());
display = dbDict != null ? dbDict.getName() : null;
}
ext.set(field.getName() + dict.suffix(), display);
} catch (Exception e) {
e.printStackTrace();
} finally {
field.setAccessible(false);
}
}
}
c = c.getSuperclass();
}while(c!=TailBean.class);
}
// 深度解析注解
if (field.isAnnotationPresent(DictDeep.class)) {
field.setAccessible(true);
try {
Object res = field.get(ext);
if (res instanceof List) {
queryListAfter((List) res);
} else {
queryEntityAfter(res);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
field.setAccessible(false);
}
}
// 枚举自动转换中文
if (field.isAnnotationPresent(DictEnum.class)) {
field.setAccessible(true);
DictEnum dict = field.getAnnotation(DictEnum.class);
try {
String display = "";
Method methodByName = ReflectUtil.getMethodByName(field.getType(), "get" + StrUtil.upperFirst(dict.value()));
Object enumValue = ReflectUtil.invoke(field.get(ext), methodByName);
if (ObjectUtil.isNotEmpty(enumValue)) {
display = String.valueOf(enumValue);
}
ext.set(field.getName() + dict.suffix(), display);
} catch (UtilException e) {
throw new RuntimeException(field.getName() + " 缺少getter方法");
} catch (Exception e) {
e.printStackTrace();
} finally {
field.setAccessible(false);
}
}
}
c = c.getSuperclass();
} while (c != TailBean.class);
}
}

@ -1,6 +1,7 @@
package com.ibeetl.jlw.entity;
import com.ibeetl.admin.core.annotation.Dict;
import com.ibeetl.admin.core.annotation.DictDeep;
import com.ibeetl.admin.core.entity.BaseEntity;
import com.ibeetl.admin.core.util.ValidateConfig;
import lombok.Data;
@ -70,6 +71,7 @@ public class TeacherOpenCourseScheduleSession extends BaseEntity{
private Long userId ;
@DictDeep
@FetchSql("select * from teacher_open_course_schedule_session_snap where teacher_open_course_schedule_session_snap_status = 1" +
" and teacher_open_course_id = #teacherOpenCourseId#")
private List<TeacherOpenCourseScheduleSessionSnap> sessionTagList;

@ -4,13 +4,13 @@ import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.ibeetl.admin.core.annotation.Dict;
import com.ibeetl.admin.core.annotation.DictEnum;
import com.ibeetl.admin.core.entity.BaseEntity;
import com.ibeetl.admin.core.util.ValidateConfig;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.beetl.sql.annotation.entity.AssignID;
import org.beetl.sql.annotation.entity.EnumValue;
import javax.validation.constraints.NotNull;
import java.util.Date;
@ -37,18 +37,19 @@ public class TeacherOpenCourseScheduleSessionSnap extends BaseEntity{
private Long teacherOpenCourseScheduleSessionId ;
//关联开课ID
@Dict(type = "teacher_open_course.teacher_open_course_title.teacher_open_course_status=1")
private Long teacherOpenCourseId ;
//状态1正常 2删除
@Dict(type="global_stataus")
@Dict(type="global_status")
private Integer teacherOpenCourseScheduleSessionSnapStatus ;
@DictEnum
//开始状态
@EnumValue
private TeacherOpenCourseScheduleSessionTagStartStatusEnum teacherOpenCourseScheduleSessionTagStartStatus;
//课次名称
private String teacherOpenCourseScheduleSessionTagName ;
@ -145,7 +146,7 @@ public class TeacherOpenCourseScheduleSessionSnap extends BaseEntity{
* END
* READY
*/
protected enum TeacherOpenCourseScheduleSessionTagStartStatusEnum {
public enum TeacherOpenCourseScheduleSessionTagStartStatusEnum {
// 进行中
ING("进行中"),
// 已结束
@ -154,10 +155,12 @@ public class TeacherOpenCourseScheduleSessionSnap extends BaseEntity{
READY("未开始");
@Getter
@Setter
private String teacherOpenCourseScheduleSessionTagStartStatusStr;
// 可以转换成中文
// @JsonValue
private String text;
TeacherOpenCourseScheduleSessionTagStartStatusEnum(String teacherOpenCourseScheduleSessionTagStartStatusStr) {
this.teacherOpenCourseScheduleSessionTagStartStatusStr = teacherOpenCourseScheduleSessionTagStartStatusStr;
TeacherOpenCourseScheduleSessionTagStartStatusEnum(String text) {
this.text = text;
}
}

@ -8,6 +8,8 @@ import com.ibeetl.jlw.entity.TeacherOpenCourseScheduleSessionSnap;
import javax.validation.constraints.NotNull;
import java.util.Date;
import static com.ibeetl.admin.core.annotation.Query.TYPE_DICT;
/**
*
*/
@ -17,9 +19,9 @@ public class TeacherOpenCourseScheduleSessionSnapQuery extends PageParam {
private Long teacherOpenCourseScheduleSessionSnapId;
@Query(name = "关联排课ID", display = false)
private Long teacherOpenCourseScheduleSessionId;
@Query(name = "关联开课ID", display = false)
@Query(name = "关联开课ID", display = true, type = TYPE_DICT, dict="teacher_open_course.teacher_open_course_title.teacher_open_course_status=1")
private Long teacherOpenCourseId;
@Query(name = "状态1正常 2删除", display = true,type=Query.TYPE_DICT,dict="global_stataus")
@Query(name = "状态1正常 2删除", display = true,type= TYPE_DICT,dict="global_status")
private Integer teacherOpenCourseScheduleSessionSnapStatus;
@Query(name = "课次名称", display = false)
private String teacherOpenCourseScheduleSessionTagName;
@ -43,6 +45,7 @@ public class TeacherOpenCourseScheduleSessionSnapQuery extends PageParam {
private String teacherOpenCourseScheduleSessionSnapIdPlural;
private String teacherOpenCourseScheduleSessionIdPlural;
private String teacherOpenCourseScheduleSessionSnapStatusPlural;
private String teacherOpenCourseIdPlural;
private String orgIdPlural;
private String userIdPlural;
@ -176,6 +179,15 @@ public class TeacherOpenCourseScheduleSessionSnapQuery extends PageParam {
public void setTeacherOpenCourseScheduleSessionSnapJsonStr(String teacherOpenCourseScheduleSessionSnapJsonStr ){
this.teacherOpenCourseScheduleSessionSnapJsonStr = teacherOpenCourseScheduleSessionSnapJsonStr;
}
public String getTeacherOpenCourseIdPlural() {
return teacherOpenCourseIdPlural;
}
public void setTeacherOpenCourseIdPlural(String teacherOpenCourseIdPlural) {
this.teacherOpenCourseIdPlural = teacherOpenCourseIdPlural;
}
public String get_given() {
return _given;
}

@ -38,6 +38,12 @@ server.tomcat.accesslog.suffix=.log
server.tomcat.max-http-post-size=-1
server.tomcat.max-threads=100
#=====================jackson配置==============================
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
spring.jackson.serialization.write_enums_using_to_string=true
#html\u89C6\u56FE\u4EA4\u7ED9beetl\u6E32\u67D3
beetl.suffix=html
app.name=jlw

@ -69,8 +69,12 @@ queryByCondition
@if(!isEmpty(userIdPlural)){
and find_in_set(t.user_id,#userIdPlural#)
@}
queryByConditionQuery
===
queryByConditionQuery
===
* 根据不为空的参数进行分页查询(无权限)
select
@pageTag(){
@ -138,19 +142,27 @@ queryByCondition
@if(!isEmpty(userIdPlural)){
and find_in_set(t.user_id,#userIdPlural#)
@}
deleteTeacherOpenCourseScheduleSessionSnapByIds
===
*
deleteTeacherOpenCourseScheduleSessionSnapByIds
===
* 批量删除(假删除)
update teacher_open_course_schedule_session_snap set teacher_open_course_schedule_session_snap_status = 2 where find_in_set(teacher_open_course_schedule_session_snap_id,#ids#)
deleteByIds
===
deleteByIds
===
* 批量删除(真删除)
delete from teacher_open_course_schedule_session_snap where find_in_set(teacher_open_course_schedule_session_snap_id,#ids#)
getByIds
===
getByIds
===
select * from teacher_open_course_schedule_session_snap where find_in_set(teacher_open_course_schedule_session_snap_id,#ids#)
updateGivenByIds
===
updateGivenByIds
===
* 批量更新指定字段,无论此字段是否有值
update teacher_open_course_schedule_session_snap
set
@ -240,8 +252,11 @@ queryByCondition
@}
teacher_open_course_schedule_session_snap_id = teacher_open_course_schedule_session_snap_id
where find_in_set(teacher_open_course_schedule_session_snap_id,#teacherOpenCourseScheduleSessionSnapIdPlural#)
getTeacherOpenCourseScheduleSessionSnapValues
===
getTeacherOpenCourseScheduleSessionSnapValues
===
* 根据不为空的参数进行查询
select t.*
from teacher_open_course_schedule_session_snap t
@ -287,8 +302,11 @@ queryByCondition
@if(!isEmpty(userId)){
and t.user_id =#userId#
@}
getValuesByQuery
===
getValuesByQuery
===
* 根据不为空的参数进行查询
select t.*
from teacher_open_course_schedule_session_snap t

@ -141,13 +141,6 @@ layui.define([ 'form', 'laydate', 'table' ], function(exports) {
hideField :false,
hide:$.isEmpty(sx_['teacherOpenCourseScheduleSessionTagEndTime'])?false:sx_['teacherOpenCourseScheduleSessionTagEndTime'],
}
,{
field : 'operation_',title : '操作',align:"center", templet: function (d) {
var htm = '<button type="button" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</button>';
htm += '<button type="button" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button>';
return htm;
}
}
] ]

@ -49,7 +49,7 @@ layui.define([ 'form', 'laydate', 'table' ], function(exports) {
hide:$.isEmpty(sx_['teacherOpenCourseScheduleSessionId'])?false:sx_['teacherOpenCourseScheduleSessionId'],
},
{
field : 'teacherOpenCourseScheduleSessionSnapStatusText', //数据字典类型为 global_stataus
field : 'teacherOpenCourseScheduleSessionSnapStatusText', //数据字典类型为 global_status
title : '状态1正常 2删除',
align:"center",
hideField :false,
@ -103,20 +103,6 @@ layui.define([ 'form', 'laydate', 'table' ], function(exports) {
align:"center",
hideField :false,
hide:$.isEmpty(sx_['teacherOpenCourseScheduleSessionSnapAddTime'])?false:sx_['teacherOpenCourseScheduleSessionSnapAddTime'],
},
{
field : 'orgId',
title : '组织ID',
align:"center",
hideField :false,
hide:$.isEmpty(sx_['orgId'])?false:sx_['orgId'],
},
{
field : 'userId',
title : '用户ID',
align:"center",
hideField :false,
hide:$.isEmpty(sx_['userId'])?false:sx_['userId'],
}
,{
field : 'operation_',title : '操作',align:"center", templet: function (d) {

@ -12,7 +12,7 @@
<div class="layui-inline">
<label class="layui-form-label">状态1正常 2删除</label>
<div class="layui-input-inline">
<layui:simpleDictSelect style='layui-input-inline' type="global_stataus"
<layui:simpleDictSelect style='layui-input-inline' type="global_status"
id="teacherOpenCourseScheduleSessionSnapStatus" name="teacherOpenCourseScheduleSessionSnapStatus" value="${teacherOpenCourseScheduleSessionSnap.teacherOpenCourseScheduleSessionSnapStatus}" layVerify="" />
</div>
</div>

@ -12,7 +12,7 @@
<div class="layui-inline">
<label class="layui-form-label">状态1正常 2删除</label>
<div class="layui-input-inline">
<layui:simpleDictSelect style='layui-input-inline' type="global_stataus"
<layui:simpleDictSelect style='layui-input-inline' type="global_status"
id="teacherOpenCourseScheduleSessionSnapStatus" name="teacherOpenCourseScheduleSessionSnapStatus" value="${teacherOpenCourseScheduleSessionSnap.teacherOpenCourseScheduleSessionSnapStatus}" layVerify="" />
</div>
</div>

Loading…
Cancel
Save