From 658ff0617616ca1246f4f8e09a543783948f4899 Mon Sep 17 00:00:00 2001 From: peiyanni Date: Tue, 22 Jun 2021 14:08:44 +0800 Subject: [PATCH] dict --- .../dict/controller/GaeaDictController.java | 99 +++++++++++ .../controller/GaeaDictItemController.java | 41 +++++ .../dict/controller/dto/GaeaDictDTO.java | 56 +++++++ .../dict/controller/dto/GaeaDictItemDTO.java | 119 +++++++++++++ .../controller/param/GaeaDictItemParam.java | 39 +++++ .../dict/controller/param/GaeaDictParam.java | 29 ++++ .../modules/dict/dao/GaeaDictItemMapper.java | 17 ++ .../modules/dict/dao/GaeaDictMapper.java | 17 ++ .../modules/dict/dao/entity/GaeaDict.java | 56 +++++++ .../modules/dict/dao/entity/GaeaDictItem.java | 123 ++++++++++++++ .../dict/service/GaeaDictItemService.java | 23 +++ .../modules/dict/service/GaeaDictService.java | 47 ++++++ .../service/impl/GaeaDictItemServiceImpl.java | 97 +++++++++++ .../service/impl/GaeaDictServiceImpl.java | 158 ++++++++++++++++++ 14 files changed, 921 insertions(+) create mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/controller/GaeaDictController.java create mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/controller/GaeaDictItemController.java create mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/controller/dto/GaeaDictDTO.java create mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/controller/dto/GaeaDictItemDTO.java create mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/controller/param/GaeaDictItemParam.java create mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/controller/param/GaeaDictParam.java create mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/dao/GaeaDictItemMapper.java create mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/dao/GaeaDictMapper.java create mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/dao/entity/GaeaDict.java create mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/dao/entity/GaeaDictItem.java create mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/service/GaeaDictItemService.java create mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/service/GaeaDictService.java create mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/service/impl/GaeaDictItemServiceImpl.java create mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/service/impl/GaeaDictServiceImpl.java diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/controller/GaeaDictController.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/controller/GaeaDictController.java new file mode 100644 index 00000000..fdf65ce6 --- /dev/null +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/controller/GaeaDictController.java @@ -0,0 +1,99 @@ +package com.anjiplus.template.gaea.business.modules.dict.controller; + +import com.anji.plus.gaea.bean.KeyValue; +import com.anji.plus.gaea.bean.ResponseBean; +import com.anji.plus.gaea.curd.controller.GaeaBaseController; +import com.anji.plus.gaea.curd.service.GaeaBaseService; +import com.anjiplus.template.gaea.business.modules.dict.controller.dto.GaeaDictDTO; +import com.anjiplus.template.gaea.business.modules.dict.controller.param.GaeaDictParam; +import com.anjiplus.template.gaea.business.modules.dict.dao.entity.GaeaDict; +import com.anjiplus.template.gaea.business.modules.dict.service.GaeaDictItemService; +import com.anjiplus.template.gaea.business.modules.dict.service.GaeaDictService; +import io.swagger.annotations.Api; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.web.bind.annotation.*; + +import java.util.*; + +/** + * (GaeaDict)实体类 + * + * @author lr + * @since 2021-02-23 10:01:02 + */ +@RestController +@RequestMapping("/gaeaDict") +@Api(value = "/gaeaDict", tags = "") +public class GaeaDictController extends GaeaBaseController { + + @Autowired + private GaeaDictService gaeaDictService; + + @Autowired + private GaeaDictItemService gaeaDictItemService; + + @Override + public GaeaBaseService getService() { + return gaeaDictService; + } + + @Override + public GaeaDict getEntity() { + return new GaeaDict(); + } + + @Override + public GaeaDictDTO getDTO() { + return new GaeaDictDTO(); + } + + + /** + * 刷新指定字典项 + * @return + */ + @PostMapping("/freshDict") + public ResponseBean refreshDict(@RequestBody List dictCodes) { + //刷新 + gaeaDictService.refreshCache(dictCodes); + return responseSuccess(); + } + + /** + * 下拉菜单 + * @return + */ + @GetMapping("/select/{dictCode}") + public ResponseBean select(@PathVariable("dictCode") String dictName){ + Locale locale = LocaleContextHolder.getLocale(); + //语言 + String language = locale.getLanguage(); + + List keyValues = gaeaDictService.select(dictName,language); + return responseSuccessWithData(keyValues); + } + + + /** + * 指定语言的字典项 + * @return + */ + @GetMapping("/map/{dictCode}") + public ResponseBean dictItemByLang(@PathVariable("dictCode") String dictCode){ + return responseSuccessWithData(gaeaDictItemService.getItemMap(dictCode)); + } + /** + * 下拉菜单 + * @return + */ + @GetMapping("/selectAll/{project}") + public ResponseBean selectTypecodes(@PathVariable String project){ + Locale locale = LocaleContextHolder.getLocale(); + //语言 + String language = locale.getLanguage(); + + Collection keyValues = gaeaDictService.selectTypeCode(project,language); + return responseSuccessWithData(keyValues); + } +} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/controller/GaeaDictItemController.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/controller/GaeaDictItemController.java new file mode 100644 index 00000000..92a431d3 --- /dev/null +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/controller/GaeaDictItemController.java @@ -0,0 +1,41 @@ +package com.anjiplus.template.gaea.business.modules.dict.controller; + +import com.anji.plus.gaea.curd.controller.GaeaBaseController; +import com.anjiplus.template.gaea.business.modules.dict.dao.entity.GaeaDictItem; +import com.anjiplus.template.gaea.business.modules.dict.controller.dto.GaeaDictItemDTO; +import com.anjiplus.template.gaea.business.modules.dict.controller.param.GaeaDictItemParam; +import com.anjiplus.template.gaea.business.modules.dict.service.GaeaDictItemService; +import com.anji.plus.gaea.curd.service.GaeaBaseService; +import io.swagger.annotations.Api; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * 数据字典项(GaeaDictItem)实体类 + * + * @author lirui + * @since 2021-03-10 13:05:59 + */ +@RestController +@RequestMapping("/gaeaDictItem") +@Api(value = "/gaeaDictItem", tags = "数据字典项") +public class GaeaDictItemController extends GaeaBaseController { + @Autowired + private GaeaDictItemService gaeaDictItemService; + + @Override + public GaeaBaseService getService() { + return gaeaDictItemService; + } + + @Override + public GaeaDictItem getEntity() { + return new GaeaDictItem(); + } + + @Override + public GaeaDictItemDTO getDTO() { + return new GaeaDictItemDTO(); + } +} \ No newline at end of file diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/controller/dto/GaeaDictDTO.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/controller/dto/GaeaDictDTO.java new file mode 100644 index 00000000..f26f75eb --- /dev/null +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/controller/dto/GaeaDictDTO.java @@ -0,0 +1,56 @@ +package com.anjiplus.template.gaea.business.modules.dict.controller.dto; + +import com.anji.plus.gaea.curd.dto.GaeaBaseDTO; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.io.Serializable; + +/** + * (GaeaDict)实体类 + * + * @author lr + * @since 2021-02-23 10:01:02 + */ +@ApiModel(value = "") +public class GaeaDictDTO extends GaeaBaseDTO implements Serializable { + /** + * 字典名称 + */ + @ApiModelProperty(value = "字典名称") + private String dictName; + /** + * 字典编号 + */ + @ApiModelProperty(value = "字典编号") + private String dictCode; + /** + * 字典描述 + */ + @ApiModelProperty(value = "字典描述") + private String remark; + + public String getDictName() { + return dictName; + } + + public void setDictName(String dictName) { + this.dictName = dictName; + } + + public String getDictCode() { + return dictCode; + } + + public void setDictCode(String dictCode) { + this.dictCode = dictCode; + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } +} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/controller/dto/GaeaDictItemDTO.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/controller/dto/GaeaDictItemDTO.java new file mode 100644 index 00000000..3978d8f7 --- /dev/null +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/controller/dto/GaeaDictItemDTO.java @@ -0,0 +1,119 @@ +package com.anjiplus.template.gaea.business.modules.dict.controller.dto; + +import com.anji.plus.gaea.annotation.Formatter; +import com.anji.plus.gaea.curd.dto.GaeaBaseDTO; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.io.Serializable; +/** + * 数据字典项(GaeaDictItem)实体类 + * + * @author lirui + * @since 2021-03-10 13:05:59 + */ +@ApiModel(value = "数据字典项") +public class GaeaDictItemDTO extends GaeaBaseDTO implements Serializable { + /** + * 数据字典编码 + */ + @ApiModelProperty(value = "数据字典编码") + private String dictCode; + /** + * 字典项名称 + */ + @ApiModelProperty(value = "字典项名称") + private String itemName; + /** + * 字典项值 + */ + @ApiModelProperty(value = "字典项值") + private String itemValue; + + /** + * 字典项扩展 + */ + @ApiModelProperty(value = "字典项扩展") + private String itemExtend; + /** + * 语言标识 + */ + @ApiModelProperty(value = "语言标识") + @Formatter(dictCode = "LOCALE", targetField = "localeView") + private String locale; + + private String localeView; + /** + * 描述 + */ + @ApiModelProperty(value = "描述") + private String remark; + /** + * 排序 + */ + @ApiModelProperty(value = "排序") + private Integer sort; + + public String getDictCode() { + return dictCode; + } + + public void setDictCode(String dictCode) { + this.dictCode = dictCode; + } + + public String getItemName() { + return itemName; + } + + public void setItemName(String itemName) { + this.itemName = itemName; + } + + public String getItemValue() { + return itemValue; + } + + public void setItemValue(String itemValue) { + this.itemValue = itemValue; + } + + public String getLocale() { + return locale; + } + + public void setLocale(String locale) { + this.locale = locale; + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } + + public Integer getSort() { + return sort; + } + + public void setSort(Integer sort) { + this.sort = sort; + } + + public String getItemExtend() { + return itemExtend; + } + public void setItemExtend(String itemExtend) { + this.itemExtend = itemExtend; + } + + public String getLocaleView() { + return localeView; + } + + public void setLocaleView(String localeView) { + this.localeView = localeView; + } +} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/controller/param/GaeaDictItemParam.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/controller/param/GaeaDictItemParam.java new file mode 100644 index 00000000..1b148e86 --- /dev/null +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/controller/param/GaeaDictItemParam.java @@ -0,0 +1,39 @@ +package com.anjiplus.template.gaea.business.modules.dict.controller.param; + + +import com.anji.plus.gaea.annotation.Query; +import com.anji.plus.gaea.constant.QueryEnum; +import com.anji.plus.gaea.curd.params.PageParam; +import lombok.Data; + +import java.io.Serializable; + +/** + * 数据字典项(GaeaDictItem)param + * + * @author lirui + * @since 2021-03-10 13:05:59 + */ +@Data +public class GaeaDictItemParam extends PageParam implements Serializable { + + /** + * 数据字典编码 + */ + private String dictCode; + /** + * 字典项名称 + */ + @Query(QueryEnum.LIKE) + private String itemName; + + /** + * 语言标识 + */ + private String locale; + + /** + * 1:启用,0:禁用 + */ + private Integer enabled; +} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/controller/param/GaeaDictParam.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/controller/param/GaeaDictParam.java new file mode 100644 index 00000000..5e23591c --- /dev/null +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/controller/param/GaeaDictParam.java @@ -0,0 +1,29 @@ +package com.anjiplus.template.gaea.business.modules.dict.controller.param; + + +import com.anji.plus.gaea.annotation.Query; +import com.anji.plus.gaea.constant.QueryEnum; +import com.anji.plus.gaea.curd.params.PageParam; +import lombok.Data; + +import java.io.Serializable; + +/** + * (GaeaDict)param + * + * @author lr + * @since 2021-02-23 10:01:02 + */ +@Data +public class GaeaDictParam extends PageParam implements Serializable { + /** + * 字典名称 + */ + @Query(QueryEnum.LIKE) + private String dictName; + /** + * 字典编号 + */ + @Query(QueryEnum.LIKE) + private String dictCode; +} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/dao/GaeaDictItemMapper.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/dao/GaeaDictItemMapper.java new file mode 100644 index 00000000..26451825 --- /dev/null +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/dao/GaeaDictItemMapper.java @@ -0,0 +1,17 @@ +package com.anjiplus.template.gaea.business.modules.dict.dao; + +import com.anjiplus.template.gaea.business.modules.dict.dao.entity.GaeaDictItem; +import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper; +import org.apache.ibatis.annotations.Mapper; + +/** + * 数据字典项(GaeaDictItem)Mapper + * + * @author lirui + * @since 2021-03-09 15:52:41 + */ +@Mapper +public interface GaeaDictItemMapper extends GaeaBaseMapper { + + +} \ No newline at end of file diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/dao/GaeaDictMapper.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/dao/GaeaDictMapper.java new file mode 100644 index 00000000..cfd7b4a4 --- /dev/null +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/dao/GaeaDictMapper.java @@ -0,0 +1,17 @@ +package com.anjiplus.template.gaea.business.modules.dict.dao; + +import com.anjiplus.template.gaea.business.modules.dict.dao.entity.GaeaDict; +import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper; +import org.apache.ibatis.annotations.Mapper; + +/** + * (GaeaDict)Mapper + * + * @author lr + * @since 2021-02-23 10:01:02 + */ +@Mapper +public interface GaeaDictMapper extends GaeaBaseMapper { + + +} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/dao/entity/GaeaDict.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/dao/entity/GaeaDict.java new file mode 100644 index 00000000..6fb79734 --- /dev/null +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/dao/entity/GaeaDict.java @@ -0,0 +1,56 @@ +package com.anjiplus.template.gaea.business.modules.dict.dao.entity; + +import com.anji.plus.gaea.annotation.Unique; +import com.anji.plus.gaea.curd.entity.GaeaBaseEntity; +import com.anjiplus.template.gaea.common.RespCommonCode; +import com.baomidou.mybatisplus.annotation.TableName; + +import java.io.Serializable; + +/** + * (GaeaDict)实体类 + * + * @author lr + * @since 2021-02-23 10:01:02 + */ +@TableName("gaea_dict") +public class GaeaDict extends GaeaBaseEntity implements Serializable { + /** + * 字典名称 + */ + private String dictName; + /** + * 字典编码 + */ + @Unique(code = RespCommonCode.DICCODE_ISEXIST) + private String dictCode; + + /** + * 字典描述 + */ + private String remark; + + public String getDictName() { + return dictName; + } + + public void setDictName(String dictName) { + this.dictName = dictName; + } + + public String getDictCode() { + return dictCode; + } + + public void setDictCode(String dictCode) { + this.dictCode = dictCode; + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } +} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/dao/entity/GaeaDictItem.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/dao/entity/GaeaDictItem.java new file mode 100644 index 00000000..49bfa5ea --- /dev/null +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/dao/entity/GaeaDictItem.java @@ -0,0 +1,123 @@ +package com.anjiplus.template.gaea.business.modules.dict.dao.entity; + +import com.anji.plus.gaea.annotation.UnionUnique; +import com.anji.plus.gaea.annotation.UnionUniqueCode; +import com.anjiplus.template.gaea.business.code.*; +import com.anji.plus.gaea.curd.entity.GaeaBaseEntity; +import com.anjiplus.template.gaea.business.constant.BusinessConstant; +import com.baomidou.mybatisplus.annotation.TableName; + +import java.io.Serializable; + +/** + * 数据字典项(GaeaDictItem)实体类 + * + * @author lirui + * @since 2021-03-09 15:52:41 + */ +@TableName("gaea_dict_item") +@UnionUniqueCode(group = BusinessConstant.DICT_ITEM_EXIST_GROUP, code = ResponseCode.DICT_ITEM_REPEAT) +public class GaeaDictItem extends GaeaBaseEntity implements Serializable { + + /** + * 数据字典编码 + */ + @UnionUnique(group = BusinessConstant.DICT_ITEM_EXIST_GROUP) + private String dictCode; + /** + * 字典项名称 + */ + private String itemName; + /** + * 字典项值 + */ + @UnionUnique(group = BusinessConstant.DICT_ITEM_EXIST_GROUP) + private String itemValue; + + /** + * 字典项扩展 + */ + private String itemExtend; + /** + * 语言标识 + */ + @UnionUnique(group = BusinessConstant.DICT_ITEM_EXIST_GROUP) + private String locale; + + /** + * 1:启用,0:禁用 + */ + private Integer enabled; + /** + * 描述 + */ + private String remark; + /** + * 排序 + */ + private Integer sort; + + public String getDictCode() { + return dictCode; + } + + public void setDictCode(String dictCode) { + this.dictCode = dictCode; + } + + public String getItemName() { + return itemName; + } + + public void setItemName(String itemName) { + this.itemName = itemName; + } + + public String getItemValue() { + return itemValue; + } + + public void setItemValue(String itemValue) { + this.itemValue = itemValue; + } + + public String getLocale() { + return locale; + } + + public void setLocale(String locale) { + this.locale = locale; + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } + + public Integer getSort() { + return sort; + } + + public void setSort(Integer sort) { + this.sort = sort; + } + + public Integer getEnabled() { + return enabled; + } + + public void setEnabled(Integer enabled) { + this.enabled = enabled; + } + + public String getItemExtend() { + return itemExtend; + } + + public void setItemExtend(String itemExtend) { + this.itemExtend = itemExtend; + } +} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/service/GaeaDictItemService.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/service/GaeaDictItemService.java new file mode 100644 index 00000000..46291544 --- /dev/null +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/service/GaeaDictItemService.java @@ -0,0 +1,23 @@ +package com.anjiplus.template.gaea.business.modules.dict.service; + +import com.anji.plus.gaea.curd.service.GaeaBaseService; +import com.anjiplus.template.gaea.business.modules.dict.controller.param.GaeaDictItemParam; +import com.anjiplus.template.gaea.business.modules.dict.dao.entity.GaeaDictItem; + +import java.util.Map; + +/** + * 数据字典项(GaeaDictItem)Service + * + * @author lirui + * @since 2021-03-10 13:05:59 + */ +public interface GaeaDictItemService extends GaeaBaseService { + + /** + * 根据字典编码获取字典项 + * @param dictCode + * @return + */ + Map getItemMap(String dictCode); +} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/service/GaeaDictService.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/service/GaeaDictService.java new file mode 100644 index 00000000..16d74fb7 --- /dev/null +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/service/GaeaDictService.java @@ -0,0 +1,47 @@ +package com.anjiplus.template.gaea.business.modules.dict.service; + +import com.anji.plus.gaea.bean.KeyValue; +import com.anji.plus.gaea.curd.service.GaeaBaseService; +import com.anjiplus.template.gaea.business.modules.dict.controller.param.GaeaDictParam; +import com.anjiplus.template.gaea.business.modules.dict.dao.entity.GaeaDict; +import com.anjiplus.template.gaea.business.modules.dict.dao.entity.GaeaDictItem; + +import java.util.Collection; +import java.util.List; + +/** + * (GaeaDict)Service + * + * @author lr + * @since 2021-02-23 10:01:02 + */ +public interface GaeaDictService extends GaeaBaseService { + + /** + * 刷新全部缓存 + * @param dictCodes + */ + void refreshCache(List dictCodes); + + + /** + * 获取指定字典code下拉 + * @param dictCode + * @param language + * @return + */ + List select(String dictCode, String language); + + /** + * 获取所有字典项 + * @return + */ + List findItems(List dictCodes); + /** + * 获取所有 typecode + * @param system + * @param language + * @return + */ + Collection selectTypeCode(String system, String language); +} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/service/impl/GaeaDictItemServiceImpl.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/service/impl/GaeaDictItemServiceImpl.java new file mode 100644 index 00000000..3e4def12 --- /dev/null +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/service/impl/GaeaDictItemServiceImpl.java @@ -0,0 +1,97 @@ +package com.anjiplus.template.gaea.business.modules.dict.service.impl; + +import com.anji.plus.gaea.cache.CacheHelper; +import com.anji.plus.gaea.constant.BaseOperationEnum; +import com.anji.plus.gaea.constant.GaeaConstant; +import com.anji.plus.gaea.constant.GaeaKeyConstant; +import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper; +import com.anji.plus.gaea.exception.BusinessException; +import com.anjiplus.template.gaea.business.modules.dict.dao.GaeaDictItemMapper; +import com.anjiplus.template.gaea.business.modules.dict.dao.entity.GaeaDictItem; +import com.anjiplus.template.gaea.business.modules.dict.service.GaeaDictItemService; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * 数据字典项(GaeaDictItem)ServiceImpl + * + * @author lirui + * @since 2021-03-10 13:05:59 + */ +@Service +public class GaeaDictItemServiceImpl implements GaeaDictItemService { + @Autowired + private GaeaDictItemMapper gaeaDictItemMapper; + + @Autowired + private CacheHelper cacheHelper; + + @Override + public GaeaBaseMapper getMapper() { + return gaeaDictItemMapper; + } + + + @Override + public void processAfterOperation(GaeaDictItem entity, BaseOperationEnum operationEnum) throws BusinessException { + String dictCode = entity.getDictCode(); + String locale = entity.getLocale(); + + String key = GaeaKeyConstant.DICT_PREFIX + locale + GaeaConstant.REDIS_SPLIT + dictCode; + switch (operationEnum) { + case INSERT: + case UPDATE: + cacheHelper.hashSet(key, entity.getItemValue(), entity.getItemName()); + break; + case DELETE: + cacheHelper.hashDel(key, entity.getItemValue()); + default: + } + } + + @Override + public void processBatchAfterOperation(List entities, BaseOperationEnum operationEnum) throws BusinessException { + if (CollectionUtils.isEmpty(entities)) { + return; + } + + Map> dictItemMap = entities.stream() + .collect(Collectors.groupingBy(item -> item.getLocale() + GaeaConstant.REDIS_SPLIT +item.getDictCode(), + Collectors.toMap(GaeaDictItem::getItemValue, GaeaDictItem::getItemName,(v1,v2)-> v2))); + + switch (operationEnum) { + case DELETE_BATCH: + //遍历并保持到Redis中 + dictItemMap.entrySet().stream().forEach(entry -> { + String key = GaeaKeyConstant.DICT_PREFIX + entry.getKey(); + Set hashKeys = entry.getValue().keySet(); + cacheHelper.hashBatchDel(key, hashKeys); + }); + break; + default: + } + } + + @Override + public Map getItemMap(String dictCode) { + Locale locale = LocaleContextHolder.getLocale(); + + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); + wrapper.eq(GaeaDictItem::getDictCode, dictCode); + wrapper.eq(GaeaDictItem::getLocale, locale.getLanguage()); + + List list = list(wrapper); + Map data = list.stream().collect(Collectors.toMap(GaeaDictItem::getItemValue, GaeaDictItem::getItemName, (v1, v2) -> v2)); + return data; + } +} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/service/impl/GaeaDictServiceImpl.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/service/impl/GaeaDictServiceImpl.java new file mode 100644 index 00000000..640b3b59 --- /dev/null +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/service/impl/GaeaDictServiceImpl.java @@ -0,0 +1,158 @@ +package com.anjiplus.template.gaea.business.modules.dict.service.impl; + +import com.anji.plus.gaea.bean.KeyValue; +import com.anji.plus.gaea.cache.CacheHelper; +import com.anji.plus.gaea.constant.Enabled; +import com.anji.plus.gaea.constant.GaeaConstant; +import com.anji.plus.gaea.constant.GaeaKeyConstant; +import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper; +import com.anji.plus.gaea.utils.GaeaUtils; +import com.anjiplus.template.gaea.business.modules.dict.dao.GaeaDictItemMapper; +import com.anjiplus.template.gaea.business.modules.dict.dao.GaeaDictMapper; +import com.anjiplus.template.gaea.business.modules.dict.dao.entity.GaeaDict; +import com.anjiplus.template.gaea.business.modules.dict.dao.entity.GaeaDictItem; +import com.anjiplus.template.gaea.business.modules.dict.service.GaeaDictService; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * (GaeaDict)ServiceImpl + * + * @author lr + * @since 2021-02-23 10:01:02 + */ +@Service +public class GaeaDictServiceImpl implements GaeaDictService { + + @Autowired + private GaeaDictMapper gaeaDictMapper; + + @Autowired + private GaeaDictItemMapper gaeaDictItemMapper; + + @Autowired + private CacheHelper cacheHelper; + + @Override + public GaeaBaseMapper getMapper() { + return gaeaDictMapper; + } + + /** + * 刷新全部缓存 + * @param dictCodes + */ + @Override + public void refreshCache(List dictCodes) { + + //查询指定字典项 + List gaeaDictItems = findItems(dictCodes); + + //对数据字典项进行分组,分组key=语言标识:字典编码 + Map> dictItemMap = gaeaDictItems.stream() + .collect(Collectors + .groupingBy(item -> item.getLocale() + GaeaConstant.REDIS_SPLIT +item.getDictCode(), + Collectors.toMap(GaeaDictItem::getItemValue, GaeaDictItem::getItemName,(v1,v2)-> v2))); + + //遍历并保持到Redis中 + dictItemMap.entrySet().stream().forEach(entry -> { + String key = GaeaKeyConstant.DICT_PREFIX + entry.getKey(); + cacheHelper.delete(key); + cacheHelper.hashSet(key, entry.getValue()); + }); + } + + /** + * 根据国际化语言查询指定字典编码下拉列表 + * 先从Redis中获取 + * @param dictCode 字典名称 + * @param language 语言 + * @return + */ + @Override + public List select(String dictCode, String language) { + + //缓存字典Key + String dictKey = GaeaKeyConstant.DICT_PREFIX + language + GaeaConstant.REDIS_SPLIT + dictCode; + + Map dictMap = cacheHelper.hashGet(dictKey); + + //当查询的字典为空时 + if (CollectionUtils.isEmpty(dictMap)) { + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); + wrapper.eq(GaeaDictItem::getDictCode, dictCode) + .eq(GaeaDictItem::getEnabled, Enabled.YES.getValue()) + .eq(GaeaDictItem::getLocale, language) + .orderByAsc(GaeaDictItem::getSort); + + List list = gaeaDictItemMapper.selectList(wrapper); + + List keyValues = list.stream() + .map(dictItemEntity -> new KeyValue(dictItemEntity.getItemValue(), dictItemEntity.getItemName(), dictItemEntity.getItemExtend())) + .collect(Collectors.toList()); + //当缓存不存在时,刷新缓存 + List dictCodes = new ArrayList<>(); + dictCodes.add(dictCode); + refreshCache(dictCodes); + return keyValues; + } + + List keyValues = GaeaUtils.formatKeyValue(dictMap); + + //添加扩展字段 + LambdaQueryWrapper gaeaDictItemWrapper = Wrappers.lambdaQuery(); + gaeaDictItemWrapper.eq(GaeaDictItem::getDictCode, dictCode); + gaeaDictItemWrapper.isNotNull(GaeaDictItem::getItemExtend); + + Map extendMap = gaeaDictItemMapper.selectList(gaeaDictItemWrapper).stream() + .filter(gaeaDictItem -> StringUtils.isNotBlank(gaeaDictItem.getItemExtend())) + .collect(Collectors.toMap(GaeaDictItem::getItemValue, GaeaDictItem::getItemExtend, (v1, v2) -> v2)); + if (!CollectionUtils.isEmpty(extendMap)) { + keyValues.stream().forEach(keyValue -> keyValue.setExtend(extendMap.get(keyValue.getId()))); + } + return keyValues; + } + + @Override + public List findItems(List dictCodes) { + + LambdaQueryWrapper gaeaDictItemQueryWrapper = Wrappers.lambdaQuery(); + if (!CollectionUtils.isEmpty(dictCodes)) { + gaeaDictItemQueryWrapper.in(GaeaDictItem::getDictCode, dictCodes); + } + return gaeaDictItemMapper.selectList(gaeaDictItemQueryWrapper); + } + + + @Override + public Collection selectTypeCode(String system, String language) { + + //缓存字典Key + String dictKey = GaeaKeyConstant.DICT_PREFIX + language + GaeaConstant.REDIS_SPLIT + system; + + Map dictMap = cacheHelper.hashGet(dictKey); + + //当查询的字典为空时 + if (CollectionUtils.isEmpty(dictMap)) { + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); + //wrapper.eq(GaeaDict::getLocale, language).orderByAsc(GaeaDict::getSort); + + List list = getMapper().selectList(wrapper); + + Set keyValues = list.stream() + .map(dictItemEntity -> new KeyValue(dictItemEntity.getDictCode(), + dictItemEntity.getDictName())) + .collect(Collectors.toSet()); + return keyValues; + } + + return GaeaUtils.formatKeyValue(dictMap); + } +}