From 0d755d2266d0bd67ff420918a2577756fb804662 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期四, 02 二月 2023 22:41:24 +0800 Subject: [PATCH] update 优化 转换注解 支持映射属性功能 --- ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysDictTypeBo.java | 13 +-- ruoyi-common/ruoyi-common-translation/src/main/java/com/ruoyi/common/translation/annotation/Translation.java | 7 ++ ruoyi-common/ruoyi-common-translation/src/main/java/com/ruoyi/common/translation/core/handler/TranslationHandler.java | 19 +++--- ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysDeptBo.java | 5 + ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysNoticeBo.java | 13 ++- ruoyi-ui/src/views/system/notice/index.vue | 11 ++- ruoyi-common/ruoyi-common-translation/src/main/java/com/ruoyi/common/translation/config/TranslationConfig.java | 6 ++ ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysNoticeVo.java | 11 ++- ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysDictDataBo.java | 8 +- ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysOssConfigBo.java | 7 +- ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysPostBo.java | 9 +- ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysNoticeServiceImpl.java | 10 ++ ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysMenuBo.java | 8 +- 13 files changed, 73 insertions(+), 54 deletions(-) diff --git a/ruoyi-common/ruoyi-common-translation/src/main/java/com/ruoyi/common/translation/annotation/Translation.java b/ruoyi-common/ruoyi-common-translation/src/main/java/com/ruoyi/common/translation/annotation/Translation.java index 302ef93..dbb469d 100644 --- a/ruoyi-common/ruoyi-common-translation/src/main/java/com/ruoyi/common/translation/annotation/Translation.java +++ b/ruoyi-common/ruoyi-common-translation/src/main/java/com/ruoyi/common/translation/annotation/Translation.java @@ -21,10 +21,17 @@ /** * 绫诲瀷 (闇�涓庡疄鐜扮被涓婄殑 {@link com.ruoyi.common.translation.annotation.TranslationType} 娉ㄨВtype瀵瑰簲) + * <p> + * 榛樿鍙栧綋鍓嶅瓧娈电殑鍊� 濡傛灉璁剧疆浜� @{@link Translation#mapper()} 鍒欏彇鏄犲皠瀛楁鐨勫�� */ String type(); /** + * 鏄犲皠瀛楁 (濡傛灉涓嶄负绌哄垯鍙栨瀛楁鐨勫��) + */ + String mapper() default ""; + + /** * 鍏朵粬鏉′欢 渚嬪: 瀛楀吀type(sys_user_sex) */ String other() default ""; diff --git a/ruoyi-common/ruoyi-common-translation/src/main/java/com/ruoyi/common/translation/config/TranslationConfig.java b/ruoyi-common/ruoyi-common-translation/src/main/java/com/ruoyi/common/translation/config/TranslationConfig.java index d589fdd..bc833d1 100644 --- a/ruoyi-common/ruoyi-common-translation/src/main/java/com/ruoyi/common/translation/config/TranslationConfig.java +++ b/ruoyi-common/ruoyi-common-translation/src/main/java/com/ruoyi/common/translation/config/TranslationConfig.java @@ -1,5 +1,6 @@ package com.ruoyi.common.translation.config; +import com.fasterxml.jackson.databind.ObjectMapper; import com.ruoyi.common.translation.annotation.TranslationType; import com.ruoyi.common.translation.core.TranslationInterface; import com.ruoyi.common.translation.core.handler.TranslationHandler; @@ -24,6 +25,9 @@ @Autowired private List<TranslationInterface> list; + @Autowired + private ObjectMapper objectMapper; + @PostConstruct public void init() { Map<String, TranslationInterface> map = new HashMap<>(list.size()); @@ -36,6 +40,8 @@ } } TranslationHandler.TRANSLATION_MAPPER.putAll(map); + // todo null鍊煎鐞� +// objectMapper.getSerializerProvider().setNullValueSerializer(); } } diff --git a/ruoyi-common/ruoyi-common-translation/src/main/java/com/ruoyi/common/translation/core/handler/TranslationHandler.java b/ruoyi-common/ruoyi-common-translation/src/main/java/com/ruoyi/common/translation/core/handler/TranslationHandler.java index 922757e..0a8f1b3 100644 --- a/ruoyi-common/ruoyi-common-translation/src/main/java/com/ruoyi/common/translation/core/handler/TranslationHandler.java +++ b/ruoyi-common/ruoyi-common-translation/src/main/java/com/ruoyi/common/translation/core/handler/TranslationHandler.java @@ -8,10 +8,10 @@ import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.ser.ContextualSerializer; import com.ruoyi.common.core.utils.StringUtils; +import com.ruoyi.common.core.utils.reflect.ReflectUtils; import com.ruoyi.common.translation.annotation.Translation; import com.ruoyi.common.translation.core.TranslationInterface; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.BeansException; import java.io.IOException; import java.util.Map; @@ -35,16 +35,15 @@ @Override public void serialize(Object value, JsonGenerator gen, SerializerProvider serializers) throws IOException { - try { - TranslationInterface trans = TRANSLATION_MAPPER.get(translation.type()); - if (ObjectUtil.isNotNull(trans)) { - String result = trans.translation(value, translation.other()); - gen.writeString(StringUtils.isNotBlank(result) ? result : value.toString()); - } else { - gen.writeString(value.toString()); + TranslationInterface trans = TRANSLATION_MAPPER.get(translation.type()); + if (ObjectUtil.isNotNull(trans)) { + // 濡傛灉鏄犲皠瀛楁涓嶄负绌� 鍒欏彇鏄犲皠瀛楁鐨勫�� + if (StringUtils.isNotBlank(translation.mapper())) { + value = ReflectUtils.invokeGetter(gen.getCurrentValue(), translation.mapper()); } - } catch (BeansException e) { - log.error("鏁版嵁鏈煡鍒�, 閲囩敤榛樿澶勭悊 => {}", e.getMessage()); + String result = trans.translation(value, translation.other()); + gen.writeString(StringUtils.isNotBlank(result) ? result : value.toString()); + } else { gen.writeString(value.toString()); } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysDeptBo.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysDeptBo.java index 94bfbab..f7163d6 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysDeptBo.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysDeptBo.java @@ -3,9 +3,12 @@ import com.ruoyi.common.core.validate.AddGroup; import com.ruoyi.common.core.validate.EditGroup; import com.ruoyi.common.mybatis.core.domain.TreeEntity; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import lombok.Data; import lombok.EqualsAndHashCode; -import jakarta.validation.constraints.*; /** * 閮ㄩ棬涓氬姟瀵硅薄 sys_dept diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysDictDataBo.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysDictDataBo.java index 5d4f786..1e2d2cd 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysDictDataBo.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysDictDataBo.java @@ -2,11 +2,12 @@ import com.ruoyi.common.core.validate.AddGroup; import com.ruoyi.common.core.validate.EditGroup; +import com.ruoyi.common.mybatis.core.domain.BaseEntity; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import lombok.Data; import lombok.EqualsAndHashCode; -import jakarta.validation.constraints.*; - -import com.ruoyi.common.mybatis.core.domain.BaseEntity; /** * 瀛楀吀鏁版嵁涓氬姟瀵硅薄 sys_dict_data @@ -81,6 +82,5 @@ * 澶囨敞 */ private String remark; - } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysDictTypeBo.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysDictTypeBo.java index bf69a68..9f83e78 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysDictTypeBo.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysDictTypeBo.java @@ -2,11 +2,13 @@ import com.ruoyi.common.core.validate.AddGroup; import com.ruoyi.common.core.validate.EditGroup; +import com.ruoyi.common.mybatis.core.domain.BaseEntity; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Pattern; +import jakarta.validation.constraints.Size; import lombok.Data; import lombok.EqualsAndHashCode; -import jakarta.validation.constraints.*; - -import com.ruoyi.common.mybatis.core.domain.BaseEntity; /** * 瀛楀吀绫诲瀷涓氬姟瀵硅薄 sys_dict_type @@ -44,11 +46,6 @@ * 鐘舵�侊紙0姝e父 1鍋滅敤锛� */ private String status; - - /** - * 鍒涘缓閮ㄩ棬 - */ - private Long createDept; /** * 澶囨敞 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysMenuBo.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysMenuBo.java index 4770d9d..4c9babb 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysMenuBo.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysMenuBo.java @@ -4,13 +4,11 @@ import com.ruoyi.common.core.validate.AddGroup; import com.ruoyi.common.core.validate.EditGroup; import com.ruoyi.common.mybatis.core.domain.TreeEntity; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import lombok.Data; import lombok.EqualsAndHashCode; -import jakarta.validation.constraints.*; - -import java.util.Date; - -import com.ruoyi.common.mybatis.core.domain.BaseEntity; /** * 鑿滃崟鏉冮檺涓氬姟瀵硅薄 sys_menu diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysNoticeBo.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysNoticeBo.java index b185031..4b67a57 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysNoticeBo.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysNoticeBo.java @@ -3,13 +3,12 @@ import com.ruoyi.common.core.validate.AddGroup; import com.ruoyi.common.core.validate.EditGroup; import com.ruoyi.common.core.xss.Xss; +import com.ruoyi.common.mybatis.core.domain.BaseEntity; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import lombok.Data; import lombok.EqualsAndHashCode; -import jakarta.validation.constraints.*; - -import java.util.Date; - -import com.ruoyi.common.mybatis.core.domain.BaseEntity; /** * 閫氱煡鍏憡涓氬姟瀵硅薄 sys_notice @@ -56,5 +55,9 @@ */ private String remark; + /** + * 鍒涘缓浜哄悕绉� + */ + private String createByName; } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysOssConfigBo.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysOssConfigBo.java index 4e772cc..50886f3 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysOssConfigBo.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysOssConfigBo.java @@ -1,14 +1,13 @@ package com.ruoyi.system.domain.bo; -import com.ruoyi.common.mybatis.core.domain.BaseEntity; import com.ruoyi.common.core.validate.AddGroup; import com.ruoyi.common.core.validate.EditGroup; -import lombok.Data; -import lombok.EqualsAndHashCode; - +import com.ruoyi.common.mybatis.core.domain.BaseEntity; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; /** * 瀵硅薄瀛樺偍閰嶇疆涓氬姟瀵硅薄 sys_oss_config diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysPostBo.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysPostBo.java index 4eca2e7..119db0f 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysPostBo.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysPostBo.java @@ -2,13 +2,12 @@ import com.ruoyi.common.core.validate.AddGroup; import com.ruoyi.common.core.validate.EditGroup; +import com.ruoyi.common.mybatis.core.domain.BaseEntity; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import lombok.Data; import lombok.EqualsAndHashCode; -import jakarta.validation.constraints.*; - -import java.util.Date; - -import com.ruoyi.common.mybatis.core.domain.BaseEntity; /** * 宀椾綅淇℃伅涓氬姟瀵硅薄 sys_post diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysNoticeVo.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysNoticeVo.java index 231f728..06dfbb4 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysNoticeVo.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysNoticeVo.java @@ -1,9 +1,5 @@ package com.ruoyi.system.domain.vo; -import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; -import com.alibaba.excel.annotation.ExcelProperty; -import com.ruoyi.common.excel.annotation.ExcelDictFormat; -import com.ruoyi.common.excel.convert.ExcelDictConvert; import com.ruoyi.common.translation.annotation.Translation; import com.ruoyi.common.translation.constant.TransConstant; import lombok.Data; @@ -59,10 +55,15 @@ /** * 鍒涘缓鑰� */ - @Translation(type = TransConstant.USER_ID_TO_NAME) private Long createBy; /** + * 鍒涘缓浜哄悕绉� + */ + @Translation(type = TransConstant.USER_ID_TO_NAME, mapper = "createBy") + private String createByName = ""; + + /** * 鍒涘缓鏃堕棿 */ private Date createTime; diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysNoticeServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysNoticeServiceImpl.java index 17d9f04..36f6748 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysNoticeServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysNoticeServiceImpl.java @@ -5,13 +5,15 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.mybatis.core.page.PageQuery; import com.ruoyi.common.mybatis.core.page.TableDataInfo; -import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.system.domain.SysNotice; +import com.ruoyi.system.domain.SysUser; import com.ruoyi.system.domain.bo.SysNoticeBo; import com.ruoyi.system.domain.vo.SysNoticeVo; import com.ruoyi.system.mapper.SysNoticeMapper; +import com.ruoyi.system.mapper.SysUserMapper; import com.ruoyi.system.service.ISysNoticeService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -29,6 +31,7 @@ public class SysNoticeServiceImpl implements ISysNoticeService { private final SysNoticeMapper baseMapper; + private final SysUserMapper userMapper; @Override public TableDataInfo<SysNoticeVo> selectPageNoticeList(SysNoticeBo notice, PageQuery pageQuery) { @@ -64,7 +67,10 @@ LambdaQueryWrapper<SysNotice> lqw = Wrappers.lambdaQuery(); lqw.like(StringUtils.isNotBlank(bo.getNoticeTitle()), SysNotice::getNoticeTitle, bo.getNoticeTitle()); lqw.eq(StringUtils.isNotBlank(bo.getNoticeType()), SysNotice::getNoticeType, bo.getNoticeType()); - lqw.eq(ObjectUtil.isNotNull(bo.getCreateBy()), SysNotice::getCreateBy, bo.getCreateBy()); + if (StringUtils.isNotBlank(bo.getCreateByName())) { + SysUser sysUser = userMapper.selectUserByUserName(bo.getCreateByName()); + lqw.eq(SysNotice::getCreateBy, ObjectUtil.isNotNull(sysUser) ? sysUser.getUserId() : null); + } return lqw; } diff --git a/ruoyi-ui/src/views/system/notice/index.vue b/ruoyi-ui/src/views/system/notice/index.vue index 19e25a0..daf5c46 100644 --- a/ruoyi-ui/src/views/system/notice/index.vue +++ b/ruoyi-ui/src/views/system/notice/index.vue @@ -9,9 +9,9 @@ @keyup.enter.native="handleQuery" /> </el-form-item> - <el-form-item label="鎿嶄綔浜哄憳" prop="createBy"> + <el-form-item label="鎿嶄綔浜哄憳" prop="createByName"> <el-input - v-model="queryParams.createBy" + v-model="queryParams.createByName" placeholder="璇疯緭鍏ユ搷浣滀汉鍛�" clearable @keyup.enter.native="handleQuery" @@ -88,7 +88,7 @@ <dict-tag :options="dict.type.sys_notice_status" :value="scope.row.status"/> </template> </el-table-column> - <el-table-column label="鍒涘缓鑰�" align="center" prop="createBy" width="100" /> + <el-table-column label="鍒涘缓鑰�" align="center" prop="createByName" width="100" /> <el-table-column label="鍒涘缓鏃堕棿" align="center" prop="createTime" width="100"> <template slot-scope="scope"> <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span> @@ -200,7 +200,7 @@ pageNum: 1, pageSize: 10, noticeTitle: undefined, - createBy: undefined, + createByName: undefined, status: undefined }, // 琛ㄥ崟鍙傛暟 @@ -282,6 +282,7 @@ this.$refs["form"].validate(valid => { if (valid) { if (this.form.noticeId != undefined) { + console.log(this.$refs['form']) updateNotice(this.form).then(response => { this.$modal.msgSuccess("淇敼鎴愬姛"); this.open = false; @@ -309,4 +310,4 @@ } } }; -</script> \ No newline at end of file +</script> -- Gitblit v1.9.3