Browse Source

重构字典值@Dict注解切面

syh 5 năm trước cách đây
mục cha
commit
fdac2a245e

+ 4 - 0
jeecg-boot-base-common/src/main/java/org/jeecg/common/aspect/annotation/Dict.java

@@ -39,4 +39,8 @@ public @interface Dict {
      * @return 返回类型: String
      */
     String dictTable() default "";
+
+    String extendsKey() default "";
+
+    String extendsValue() default "";
 }

+ 6 - 4
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/aspect/DictAspect.java

@@ -102,9 +102,11 @@ public class DictAspect {
                             String code = field.getAnnotation(Dict.class).dicCode();
                             String text = field.getAnnotation(Dict.class).dicText();
                             String table = field.getAnnotation(Dict.class).dictTable();
+                            String extendsKey = field.getAnnotation(Dict.class).extendsKey();
+                            String extendsValue = field.getAnnotation(Dict.class).extendsValue();
                             String key = String.valueOf(item.get(field.getName()));
                             //翻译字典值对应的txt
-                            String textValue = translateDictValue(code, text, table, key);
+                            String textValue = translateDictValue(code, text, table, key,extendsKey,extendsValue);
 
                             log.debug(" 字典Val : "+ textValue);
                             log.debug(" __翻译字典字段__ "+field.getName() + CommonConstant.DICT_TEXT_SUFFIX+": "+ textValue);
@@ -132,7 +134,7 @@ public class DictAspect {
      * @param key
      * @return
      */
-    private String translateDictValue(String code, String text, String table, String key) {
+    private String translateDictValue(String code, String text, String table, String key,String extendsKey,String extendsValue) {
     	if(oConvertUtils.isEmpty(key)) {
     		return null;
     	}
@@ -145,9 +147,9 @@ public class DictAspect {
                 continue; //跳过循环
             }
             if (!StringUtils.isEmpty(table)){
-                tmpValue= dictService.queryTableDictTextByKey(table,text,code,k.trim());
+                tmpValue= dictService.queryTableDictTextByKey(table,text,code,k.trim(),extendsKey,extendsValue);
             }else {
-                tmpValue = dictService.queryDictTextByKey(code, k.trim());
+                tmpValue = dictService.queryDictTextByKey(code, k.trim(),extendsKey,extendsValue);
             }
 
             if (tmpValue != null) {

+ 2 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/SysDictController.java

@@ -167,7 +167,7 @@ public class SysDictController {
 		Result<String> result = new Result<String>();
 		String text = null;
 		try {
-			text = sysDictService.queryDictTextByKey(dictCode, key);
+			text = sysDictService.queryDictTextByKey(dictCode, key,null,null);
 			 result.setSuccess(true);
 			 result.setResult(text);
 		} catch (Exception e) {
@@ -380,7 +380,7 @@ public class SysDictController {
 					result.error500("字典Code格式不正确!");
 					return result;
 				}
-				String text = sysDictService.queryTableDictTextByKey(params[0], params[1], params[2], key);
+				String text = sysDictService.queryTableDictTextByKey(params[0], params[1], params[2], key,null,null);
 				result.setSuccess(true);
 				result.setResult(text);
 				log.info(result.toString());

+ 10 - 10
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/mapper/SysDictMapper.java

@@ -1,13 +1,13 @@
 package org.jeecg.modules.system.mapper;
 
-import java.util.List;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Param;
 import org.jeecg.common.system.vo.DictModel;
 import org.jeecg.modules.system.entity.SysDict;
 import org.jeecg.modules.system.model.DuplicateCheckVo;
 import org.jeecg.modules.system.model.TreeSelectModel;
 
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import java.util.List;
 
 /**
  * <p>
@@ -18,36 +18,36 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  * @since 2018-12-28
  */
 public interface SysDictMapper extends BaseMapper<SysDict> {
-	
+
 	/**
 	  *  重复检查SQL
 	 * @return
 	 */
 	public Long duplicateCheckCountSql(DuplicateCheckVo duplicateCheckVo);
 	public Long duplicateCheckCountSqlNoDataId(DuplicateCheckVo duplicateCheckVo);
-	
+
 	public List<DictModel> queryDictItemsByCode(@Param("code") String code);
 	public List<DictModel> queryTableDictItemsByCode(@Param("table") String table,@Param("text") String text,@Param("code") String code);
 	public List<DictModel> queryTableDictItemsByCodeAndFilter(@Param("table") String table,@Param("text") String text,@Param("code") String code,@Param("filterSql") String filterSql);
 
 
-	public String queryDictTextByKey(@Param("code") String code,@Param("key") String key);
+	String queryDictTextByKey(@Param("code") String code,@Param("key") String key,@Param(value = "extendsKey") String extendsKey,@Param(value = "extendsValue") String extendsValue);
+
+	String queryTableDictTextByKey(@Param("table") String table,@Param("text") String text,@Param("code") String code,@Param("key") String key,@Param(value = "extendsKey") String extendsKey,@Param(value = "extendsValue") String extendsValue);
 
-	public String queryTableDictTextByKey(@Param("table") String table,@Param("text") String text,@Param("code") String code,@Param("key") String key);
 
-	
 	/**
 	 * 查询所有部门 作为字典信息 id -->value,departName -->text
 	 * @return
 	 */
 	public List<DictModel> queryAllDepartBackDictModel();
-	
+
 	/**
 	 * 查询所有用户  作为字典信息 username -->value,realname -->text
 	 * @return
 	 */
 	public List<DictModel> queryAllUserBackDictModel();
-	
+
 	/**
 	 * 通过关键字查询出字典表
 	 * @param table
@@ -56,7 +56,7 @@ public interface SysDictMapper extends BaseMapper<SysDict> {
 	 * @param keyword
 	 * @return
 	 */
-	public List<DictModel> queryTableDictItems(@Param("table") String table,@Param("text") String text,@Param("code") String code,@Param("keyword") String keyword); 
+	public List<DictModel> queryTableDictItems(@Param("table") String table,@Param("text") String text,@Param("code") String code,@Param("keyword") String keyword);
 
 	/**
 	  * 根据表名、显示字段名、存储字段名 查询树

+ 7 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/mapper/xml/SysDictMapper.xml

@@ -12,9 +12,12 @@
 
     <!-- 通过字典code获取字典数据 -->
     <select id="queryDictTextByKey" parameterType="String" resultType="String">
-		   select s.item_text from sys_dict_item s 
+		   select s.item_text from sys_dict_item s
 		   where s.dict_id = (select id from sys_dict where dict_code = #{code})
 		   and s.item_value = #{key}
+		   <if test="extendsKey!=null and extendsValue!=null">
+			   and s.${extendsKey} = #{extendsValue}
+		   </if>
 	</select>
 
 
@@ -33,6 +36,9 @@
     <!--通过查询指定table的 text code key 获取字典值-->
     <select id="queryTableDictTextByKey" parameterType="String" resultType="String">
 		   select ${text} as 'text' from ${table} where ${code}= #{key}
+		   <if test="extendsKey != null and extendsValue != null">
+			   and ${extendsKey} = #{extendsValue}
+		   </if>
 	</select>
 
     <!-- 重复校验 sql语句 -->

+ 11 - 12
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/ISysDictService.java

@@ -1,14 +1,13 @@
 package org.jeecg.modules.system.service;
 
-import java.util.List;
-import java.util.Map;
-
+import com.baomidou.mybatisplus.extension.service.IService;
 import org.jeecg.common.system.vo.DictModel;
 import org.jeecg.modules.system.entity.SysDict;
-import com.baomidou.mybatisplus.extension.service.IService;
 import org.jeecg.modules.system.entity.SysDictItem;
 import org.jeecg.modules.system.model.TreeSelectModel;
 
+import java.util.List;
+
 /**
  * <p>
  * 字典表 服务类
@@ -19,14 +18,14 @@ import org.jeecg.modules.system.model.TreeSelectModel;
  */
 public interface ISysDictService extends IService<SysDict> {
 
-    public List<DictModel> queryDictItemsByCode(String code);
+    List<DictModel> queryDictItemsByCode(String code);
 
     List<DictModel> queryTableDictItemsByCode(String table, String text, String code);
 
-	public List<DictModel> queryTableDictItemsByCodeAndFilter(String table, String text, String code, String filterSql);
-    public String queryDictTextByKey(String code, String key);
+	List<DictModel> queryTableDictItemsByCodeAndFilter(String table, String text, String code, String filterSql);
+    String queryDictTextByKey(String code, String key,String extendsKey,String extendsValue);
 
-    String queryTableDictTextByKey(String table, String text, String code, String key);
+    String queryTableDictTextByKey(String table, String text, String code, String key,String extendsKey,String extendsValue);
 
     /**
      * 根据字典类型删除关联表中其对应的数据
@@ -40,19 +39,19 @@ public interface ISysDictService extends IService<SysDict> {
      * 添加一对多
      */
     public void saveMain(SysDict sysDict, List<SysDictItem> sysDictItemList);
-    
+
     /**
 	 * 查询所有部门 作为字典信息 id -->value,departName -->text
 	 * @return
 	 */
 	public List<DictModel> queryAllDepartBackDictModel();
-	
+
 	/**
 	 * 查询所有用户  作为字典信息 username -->value,realname -->text
 	 * @return
 	 */
 	public List<DictModel> queryAllUserBackDictModel();
-	
+
 	/**
 	 * 通过关键字查询字典表
 	 * @param table
@@ -62,7 +61,7 @@ public interface ISysDictService extends IService<SysDict> {
 	 * @return
 	 */
 	public List<DictModel> queryTableDictItems(String table, String text, String code,String keyword);
-	
+
 	/**
 	  * 根据表名、显示字段名、存储字段名 查询树
 	 * @param table

+ 20 - 12
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/SysDictServiceImpl.java

@@ -1,8 +1,7 @@
 package org.jeecg.modules.system.service.impl;
 
-import java.util.List;
-
-
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.constant.CacheConstant;
 import org.jeecg.common.constant.CommonConstant;
 import org.jeecg.common.system.vo.DictModel;
@@ -10,7 +9,6 @@ import org.jeecg.modules.system.entity.SysDict;
 import org.jeecg.modules.system.entity.SysDictItem;
 import org.jeecg.modules.system.mapper.SysDictItemMapper;
 import org.jeecg.modules.system.mapper.SysDictMapper;
-
 import org.jeecg.modules.system.model.TreeSelectModel;
 import org.jeecg.modules.system.service.ISysDictService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -18,9 +16,7 @@ import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-
-import lombok.extern.slf4j.Slf4j;
+import java.util.List;
 
 /**
  * <p>
@@ -60,9 +56,15 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
 
 	@Override
 	@Cacheable(value = CacheConstant.DICT_CACHE)
-	public String queryDictTextByKey(String code, String key) {
+	public String queryDictTextByKey(String code, String key,String extendsKey,String extendsValue) {
 		log.info("无缓存dictText的时候调用这里!");
-		return sysDictMapper.queryDictTextByKey(code, key);
+		if(null == extendsKey||extendsKey.trim().equals("")){
+			extendsKey = null;
+		}
+		if(null == extendsValue||extendsValue.trim().equals("")){
+			extendsValue = null;
+		}
+		return sysDictMapper.queryDictTextByKey(code, key,extendsKey,extendsValue);
 	}
 
 	/**
@@ -96,9 +98,15 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
 	 */
 	@Override
 	@Cacheable(value = "dictTableCache")
-	public String queryTableDictTextByKey(String table,String text,String code, String key) {
+	public String queryTableDictTextByKey(String table,String text,String code, String key,String extendsKey,String extendsValue) {
 		log.info("无缓存dictTable的时候调用这里!");
-		return sysDictMapper.queryTableDictTextByKey(table,text,code,key);
+		if(null == extendsKey||extendsKey.trim().equals("")){
+			extendsKey = null;
+		}
+		if(null == extendsValue||extendsValue.trim().equals("")){
+			extendsValue = null;
+		}
+		return sysDictMapper.queryTableDictTextByKey(table,text,code,key,extendsKey,extendsValue);
 	}
 
     /**
@@ -132,7 +140,7 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
 	public List<DictModel> queryAllUserBackDictModel() {
 		return baseMapper.queryAllUserBackDictModel();
 	}
-	
+
 	@Override
 	public List<DictModel> queryTableDictItems(String table, String text, String code, String keyword) {
 		return baseMapper.queryTableDictItems(table, text, code, "%"+keyword+"%");

+ 10 - 2
jeecg-boot-module-system/src/main/resources/application-wps.yml

@@ -56,7 +56,11 @@ spring:
   autoconfigure:
     exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
   datasource:
-    url: jdbc:mysql://139.186.27.96:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false
+#    url: jdbc:mysql://139.186.27.96:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false
+#    username: hcst
+#    password: test@20190531
+#    driver-class-name: com.mysql.jdbc.Driver
+    url: jdbc:mysql://39.106.184.70:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false
     username: hcst
     password: test@20190531
     driver-class-name: com.mysql.jdbc.Driver
@@ -95,7 +99,11 @@ spring:
         connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
       datasource:
         master:
-          url: jdbc:mysql://139.186.27.96:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false
+#          url: jdbc:mysql://139.186.27.96:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false
+#          username: hcst
+#          password: test@20190531
+#          driver-class-name: com.mysql.jdbc.Driver、
+          url: jdbc:mysql://39.106.184.70:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false
           username: hcst
           password: test@20190531
           driver-class-name: com.mysql.jdbc.Driver

+ 1 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/controller/ByteDanceCampaignController.java

@@ -50,6 +50,7 @@ public class ByteDanceCampaignController {
                                                           HttpServletRequest req) {
         Result<IPage<ByteDanceCampaign>> result = new Result<>();
         QueryWrapper<ByteDanceCampaign> queryWrapper = QueryGenerator.initQueryWrapper(byteDanceCampaign, req.getParameterMap());
+        queryWrapper.orderByDesc("campaign_create_time");
         Page<ByteDanceCampaign> page = new Page<>(pageNo, pageSize);
         IPage<ByteDanceCampaign> pageList = byteDanceCampaignService.page(page, queryWrapper);
         result.setSuccess(true);

+ 6 - 5
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/entity/ByteDanceCampaign.java

@@ -9,6 +9,7 @@ import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
 import cn.com.ctop.common.module.entity.CtopOauthToken;
+import org.jeecg.common.aspect.annotation.Dict;
 import org.jeecgframework.poi.excel.annotation.Excel;
 
 import java.math.BigDecimal;
@@ -34,7 +35,6 @@ public class ByteDanceCampaign {
     @TableId
     @ApiModelProperty(value = "今日头条广告组id")
     private Long id;
-
     private Long accountId;
     /**
      * 广告组名称
@@ -51,14 +51,15 @@ public class ByteDanceCampaign {
     /**
      * 广告组预算类型
      */
-    @Excel(name = "广告组预算类型", width = 15)
-    @ApiModelProperty(value = "广告组预算类型")
+    @Dict(dicCode = "item_value", dictTable = "sys_dict_item", dicText = "item_text",extendsKey = "dict_id",extendsValue = "6512a5e70b99f6499dc3164b95e06395")
     private String budgetMode;
     /**
      * 广告组推广目的
      */
-    @Excel(name = "广告组推广目的", width = 15)
-    @ApiModelProperty(value = "广告组推广目的")
+    /**
+     * extendsValue在此处为固定值,切忌胡乱修改
+     */
+    @Dict(dicCode = "item_value", dictTable = "sys_dict_item", dicText = "item_text",extendsKey = "dict_id",extendsValue = "181afbae847dd3bc7e27795d89538c9c")
     private String landingType;
     /**
      * 广告组时间戳,用于更新时提交,服务端判断是否基于最新信息修改