浏览代码

:heavy_plus_sign: 添加参数统一获取类

smallchill 6 年之前
父节点
当前提交
221ccf2e9b

+ 62 - 0
src/main/java/org/springblade/common/cache/ParamCache.java

@@ -0,0 +1,62 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.common.cache;
+
+import org.springblade.core.cache.utils.CacheUtil;
+import org.springblade.core.tool.utils.SpringUtil;
+import org.springblade.modules.system.entity.Param;
+import org.springblade.modules.system.service.IParamService;
+
+import static org.springblade.core.cache.constant.CacheConstant.PARAM_CACHE;
+
+/**
+ * 参数缓存工具类
+ *
+ * @author Chill
+ */
+public class ParamCache {
+
+	private static final String PARAM_ID = "param:id:";
+	private static final String PARAM_VALUE = "param:value:";
+
+	private static IParamService paramService;
+
+	static {
+		paramService = SpringUtil.getBean(IParamService.class);
+	}
+
+	/**
+	 * 获取参数实体
+	 *
+	 * @param id 主键
+	 * @return Param
+	 */
+	public static Param getById(Long id) {
+		return CacheUtil.get(PARAM_CACHE, PARAM_ID, id, () -> paramService.getById(id));
+	}
+
+	/**
+	 * 获取参数配置
+	 *
+	 * @param paramKey 参数值
+	 * @return String
+	 */
+	public static String getValue(String paramKey) {
+		return CacheUtil.get(PARAM_CACHE, PARAM_VALUE, paramKey, () -> paramService.getValue(paramKey));
+	}
+
+}

+ 0 - 13
src/main/java/org/springblade/modules/system/mapper/ParamMapper.java

@@ -17,11 +17,7 @@
 package org.springblade.modules.system.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.springblade.modules.system.entity.Param;
-import org.springblade.modules.system.vo.ParamVO;
-
-import java.util.List;
 
 /**
  * Mapper 接口
@@ -30,13 +26,4 @@ import java.util.List;
  */
 public interface ParamMapper extends BaseMapper<Param> {
 
-	/**
-	 * 自定义分页
-	 *
-	 * @param page
-	 * @param param
-	 * @return
-	 */
-	List<ParamVO> selectParamPage(IPage page, ParamVO param);
-
 }

+ 0 - 17
src/main/java/org/springblade/modules/system/mapper/ParamMapper.xml

@@ -17,21 +17,4 @@
         <result column="remark" property="remark"/>
     </resultMap>
 
-    <!-- 通用查询结果列 -->
-    <sql id="baseColumnList">
-        select
-        id,
-        create_user AS createUser,
-        create_time AS createTime,
-        update_user AS updateUser,
-        update_time AS updateTime,
-        status,
-        is_deleted AS isDeleted,
-        param_name, param_key, param_value, remark
-    </sql>
-
-    <select id="selectParamPage" resultMap="paramResultMap">
-        select * from blade_param where is_deleted = 0
-    </select>
-
 </mapper>

+ 6 - 8
src/main/java/org/springblade/modules/system/service/IParamService.java

@@ -16,10 +16,8 @@
  */
 package org.springblade.modules.system.service;
 
-import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.springblade.core.mp.base.BaseService;
 import org.springblade.modules.system.entity.Param;
-import org.springblade.modules.system.vo.ParamVO;
 
 /**
  * 服务类
@@ -28,12 +26,12 @@ import org.springblade.modules.system.vo.ParamVO;
  */
 public interface IParamService extends BaseService<Param> {
 
-	/***
-	 * 自定义分页
-	 * @param page
-	 * @param param
-	 * @return
+	/**
+	 * 获取参数值
+	 *
+	 * @param paramKey 参数key
+	 * @return String
 	 */
-	IPage<ParamVO> selectParamPage(IPage<ParamVO> page, ParamVO param);
+	String getValue(String paramKey);
 
 }

+ 4 - 4
src/main/java/org/springblade/modules/system/service/impl/ParamServiceImpl.java

@@ -16,12 +16,11 @@
  */
 package org.springblade.modules.system.service.impl;
 
-import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import org.springblade.core.mp.base.BaseServiceImpl;
 import org.springblade.modules.system.entity.Param;
 import org.springblade.modules.system.mapper.ParamMapper;
 import org.springblade.modules.system.service.IParamService;
-import org.springblade.modules.system.vo.ParamVO;
 import org.springframework.stereotype.Service;
 
 /**
@@ -33,8 +32,9 @@ import org.springframework.stereotype.Service;
 public class ParamServiceImpl extends BaseServiceImpl<ParamMapper, Param> implements IParamService {
 
 	@Override
-	public IPage<ParamVO> selectParamPage(IPage<ParamVO> page, ParamVO param) {
-		return page.setRecords(baseMapper.selectParamPage(page, param));
+	public String getValue(String paramKey) {
+		Param param = this.getOne(Wrappers.<Param>query().lambda().eq(Param::getParamKey, paramKey));
+		return param.getParamValue();
 	}
 
 }