diff --git a/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictBaseTag.java b/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictBaseTag.java index a5daaf5f..04dd7354 100644 --- a/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictBaseTag.java +++ b/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictBaseTag.java @@ -3,11 +3,16 @@ package cn.stylefeng.guns.core.beetl.tag; import cn.hutool.core.util.ObjectUtil; import cn.hutool.extra.spring.SpringUtil; import cn.stylefeng.guns.core.beetl.consts.DictTagConstants; +import cn.stylefeng.roses.kernel.dict.modular.entity.SysDict; +import cn.stylefeng.roses.kernel.dict.modular.entity.SysDictType; import cn.stylefeng.roses.kernel.dict.modular.service.DictService; import cn.stylefeng.roses.kernel.dict.modular.service.DictTypeService; +import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.Data; import org.beetl.core.tag.GeneralVarTagBinding; +import java.util.List; import java.util.Map; /** @@ -73,6 +78,12 @@ public class SysDictBaseTag extends GeneralVarTagBinding { */ public String itemName; + /** + * 初始化绑定属性 + * + * @author liuhanqing + * @date 2021/1/16 23:49 + */ public void initAttr() { Map attrs = this.getAttributes(); if (attrs.size() > 0) { @@ -122,4 +133,33 @@ public class SysDictBaseTag extends GeneralVarTagBinding { public void render() { } + + /** + * 获取字典类型 + * @return 字典类型 + * @author liuhanqing + * @date 2021/1/16 23:46 + */ + public SysDictType getDictType(){ + // 根据字典类型编码去查询字典类型 + LambdaQueryWrapper dictTypeQueryWrapper = new LambdaQueryWrapper<>(); + dictTypeQueryWrapper.eq(SysDictType::getDictTypeCode, this.getDictTypeCode()); + dictTypeQueryWrapper.ne(SysDictType::getDelFlag, YesOrNotEnum.Y.getCode()); + return dictTypeService.getOne(dictTypeQueryWrapper); + } + /** + * + * + * @return 根据字典类型返回字典集合 + * @author liuhanqing + * @date 2021/1/16 23:46 + */ + public List getDictList(){ + // 查询字典列表 + LambdaQueryWrapper dictQueryWrapper = new LambdaQueryWrapper<>(); + dictQueryWrapper.eq(SysDict::getDictTypeCode, this.getDictTypeCode()); + dictQueryWrapper.ne(SysDict::getDelFlag, YesOrNotEnum.Y.getCode()); + dictQueryWrapper.orderByAsc(SysDict::getDictSort); + return dictService.list(dictQueryWrapper); + } } diff --git a/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictCheckBoxTag.java b/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictCheckBoxTag.java index 19fbed07..45482975 100644 --- a/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictCheckBoxTag.java +++ b/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictCheckBoxTag.java @@ -27,18 +27,10 @@ public class SysDictCheckBoxTag extends SysDictBaseTag { // 当字典类型编码不为空 if (StrUtil.isNotBlank(this.getDictTypeCode())) { // 根据字典类型编码去查询字典类型 - LambdaQueryWrapper dictTypeQueryWrapper = new LambdaQueryWrapper<>(); - dictTypeQueryWrapper.eq(SysDictType::getDictTypeCode, this.getDictTypeCode()); - dictTypeQueryWrapper.ne(SysDictType::getDelFlag, YesOrNotEnum.Y.getCode()); - SysDictType dictType = dictTypeService.getOne(dictTypeQueryWrapper); + SysDictType dictType = getDictType(); // 判断字典类型不为空 if (dictType != null) { - // 查询字典列表 - LambdaQueryWrapper dictQueryWrapper = new LambdaQueryWrapper<>(); - dictQueryWrapper.eq(SysDict::getDictTypeCode, dictType.getDictTypeCode()); - dictQueryWrapper.ne(SysDict::getDelFlag, YesOrNotEnum.Y.getCode()); - dictQueryWrapper.orderByAsc(SysDict::getDictSort); - List lst = dictService.list(dictQueryWrapper); + List lst = getDictList(); // 默认选中值 String defaultValue = this.getDefaultValue(); // 循环字典列表 diff --git a/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictRadioTag.java b/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictRadioTag.java index d6fa9aba..3b1f75e7 100644 --- a/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictRadioTag.java +++ b/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictRadioTag.java @@ -26,18 +26,10 @@ public class SysDictRadioTag extends SysDictBaseTag { // 当字典类型编码不为空 if (StrUtil.isNotBlank(this.getDictTypeCode())) { // 根据字典类型编码去查询字典类型 - LambdaQueryWrapper dictTypeQueryWrapper = new LambdaQueryWrapper<>(); - dictTypeQueryWrapper.eq(SysDictType::getDictTypeCode, this.getDictTypeCode()); - dictTypeQueryWrapper.ne(SysDictType::getDelFlag, YesOrNotEnum.Y.getCode()); - SysDictType dictType = dictTypeService.getOne(dictTypeQueryWrapper); + SysDictType dictType = getDictType(); // 判断字典类型不为空 if (dictType != null) { - // 查询字典列表 - LambdaQueryWrapper dictQueryWrapper = new LambdaQueryWrapper<>(); - dictQueryWrapper.eq(SysDict::getDictTypeCode, dictType.getDictTypeCode()); - dictQueryWrapper.ne(SysDict::getDelFlag, YesOrNotEnum.Y.getCode()); - dictQueryWrapper.orderByAsc(SysDict::getDictSort); - List lst = dictService.list(dictQueryWrapper); + List lst = getDictList(); // 默认选中值 String defaultValue = this.getDefaultValue(); int index = 0; diff --git a/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictSelectTag.java b/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictSelectTag.java index 2eca74c7..cb10795e 100644 --- a/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictSelectTag.java +++ b/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictSelectTag.java @@ -64,17 +64,10 @@ public class SysDictSelectTag extends SysDictBaseTag { } } // 根据字典类型编码去查询字典类型 - LambdaQueryWrapper dictTypeQueryWrapper = new LambdaQueryWrapper<>(); - dictTypeQueryWrapper.eq(SysDictType::getDictTypeCode, this.getDictTypeCode()); - dictTypeQueryWrapper.ne(SysDictType::getDelFlag, YesOrNotEnum.Y.getCode()); - SysDictType dictType = dictTypeService.getOne(dictTypeQueryWrapper); + SysDictType dictType = getDictType(); + // 判断字典类型不为空 if (dictType != null) { - // 查询字典列表 - LambdaQueryWrapper dictQueryWrapper = new LambdaQueryWrapper<>(); - dictQueryWrapper.eq(SysDict::getDictTypeCode, dictType.getDictTypeCode()); - dictQueryWrapper.ne(SysDict::getDelFlag, YesOrNotEnum.Y.getCode()); - dictQueryWrapper.orderByAsc(SysDict::getDictSort); - List lst = dictService.list(dictQueryWrapper); + List lst = getDictList(); // 默认选中值 String defaultValue = this.getDefaultValue(); // 循环字典列表,添加下拉选项