From 72a9c4f2243b605296e3c86ce2b685b902531b07 Mon Sep 17 00:00:00 2001 From: smallchill Date: Tue, 31 Dec 2019 16:23:35 +0800 Subject: [PATCH] =?UTF-8?q?:heavy=5Fplus=5Fsign:=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E7=BB=9F=E4=B8=80=E8=8E=B7=E5=8F=96=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../springblade/system/cache/ParamCache.java | 72 +++++++++++++++++++ .../springblade/system/feign/ISysClient.java | 27 +++++-- .../system/feign/ISysClientFallback.java | 15 ++-- .../springblade/system/feign/SysClient.java | 27 ++++--- .../system/mapper/ParamMapper.java | 13 ---- .../springblade/system/mapper/ParamMapper.xml | 17 ----- .../system/service/IDeptService.java | 9 ++- .../system/service/IParamService.java | 14 ++-- .../system/service/impl/DeptServiceImpl.java | 5 ++ .../system/service/impl/ParamServiceImpl.java | 8 +-- 10 files changed, 145 insertions(+), 62 deletions(-) create mode 100644 blade-service-api/blade-system-api/src/main/java/org/springblade/system/cache/ParamCache.java diff --git a/blade-service-api/blade-system-api/src/main/java/org/springblade/system/cache/ParamCache.java b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/cache/ParamCache.java new file mode 100644 index 00000000..5806c011 --- /dev/null +++ b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/cache/ParamCache.java @@ -0,0 +1,72 @@ +/* + * 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.system.cache; + +import org.springblade.core.cache.utils.CacheUtil; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.SpringUtil; +import org.springblade.system.entity.Param; +import org.springblade.system.feign.ISysClient; + +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 ISysClient sysClient; + + private static ISysClient getSysClient() { + if (sysClient == null) { + sysClient = SpringUtil.getBean(ISysClient.class); + } + return sysClient; + } + + /** + * 获取参数实体 + * + * @param id 主键 + * @return Param + */ + public static Param getById(Long id) { + return CacheUtil.get(PARAM_CACHE, PARAM_ID, id, () -> { + R result = getSysClient().getParam(id); + return result.getData(); + }); + } + + /** + * 获取参数配置 + * + * @param paramKey 参数值 + * @return String + */ + public static String getValue(String paramKey) { + return CacheUtil.get(PARAM_CACHE, PARAM_VALUE, paramKey, () -> { + R result = getSysClient().getParamValue(paramKey); + return result.getData(); + }); + } + +} diff --git a/blade-service-api/blade-system-api/src/main/java/org/springblade/system/feign/ISysClient.java b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/feign/ISysClient.java index d5cd5aea..76bf0f8a 100644 --- a/blade-service-api/blade-system-api/src/main/java/org/springblade/system/feign/ISysClient.java +++ b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/feign/ISysClient.java @@ -18,10 +18,7 @@ package org.springblade.system.feign; import org.springblade.core.launch.constant.AppConstant; import org.springblade.core.tool.api.R; -import org.springblade.system.entity.Dept; -import org.springblade.system.entity.Menu; -import org.springblade.system.entity.Role; -import org.springblade.system.entity.Tenant; +import org.springblade.system.entity.*; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -51,6 +48,8 @@ public interface ISysClient { String ROLE_ALIAS = API_PREFIX + "/role-alias"; String ROLE_ALIASES = API_PREFIX + "/role-aliases"; String TENANT = API_PREFIX + "/tenant"; + String PARAM = API_PREFIX + "/param"; + String PARAM_VALUE = API_PREFIX + "/param-value"; /** * 获取菜单 @@ -146,9 +145,27 @@ public interface ISysClient { * 获取租户 * * @param id 主键 - * @return Tenant> + * @return Tenant */ @GetMapping(TENANT) R getTenant(@RequestParam("id") Long id); + /** + * 获取参数 + * + * @param id 主键 + * @return Param + */ + @GetMapping(PARAM) + R getParam(@RequestParam("id") Long id); + + /** + * 获取参数配置 + * + * @param paramKey 参数key + * @return String + */ + @GetMapping(PARAM_VALUE) + R getParamValue(@RequestParam("paramKey") String paramKey); + } diff --git a/blade-service-api/blade-system-api/src/main/java/org/springblade/system/feign/ISysClientFallback.java b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/feign/ISysClientFallback.java index 357de13d..8a117f73 100644 --- a/blade-service-api/blade-system-api/src/main/java/org/springblade/system/feign/ISysClientFallback.java +++ b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/feign/ISysClientFallback.java @@ -17,10 +17,7 @@ package org.springblade.system.feign; import org.springblade.core.tool.api.R; -import org.springblade.system.entity.Dept; -import org.springblade.system.entity.Menu; -import org.springblade.system.entity.Role; -import org.springblade.system.entity.Tenant; +import org.springblade.system.entity.*; import org.springframework.stereotype.Component; import java.util.List; @@ -87,4 +84,14 @@ public class ISysClientFallback implements ISysClient { public R getTenant(Long id) { return R.fail("获取数据失败"); } + + @Override + public R getParam(Long id) { + return R.fail("获取数据失败"); + } + + @Override + public R getParamValue(Long paramKey) { + return R.fail("获取数据失败"); + } } diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/feign/SysClient.java b/blade-service/blade-system/src/main/java/org/springblade/system/feign/SysClient.java index b7f703b6..cc20896d 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/feign/SysClient.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/feign/SysClient.java @@ -16,17 +16,10 @@ */ package org.springblade.system.feign; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; import lombok.AllArgsConstructor; import org.springblade.core.tool.api.R; -import org.springblade.system.entity.Dept; -import org.springblade.system.entity.Menu; -import org.springblade.system.entity.Role; -import org.springblade.system.entity.Tenant; -import org.springblade.system.service.IDeptService; -import org.springblade.system.service.IMenuService; -import org.springblade.system.service.IRoleService; -import org.springblade.system.service.ITenantService; +import org.springblade.system.entity.*; +import org.springblade.system.service.*; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import springfox.documentation.annotations.ApiIgnore; @@ -51,6 +44,8 @@ public class SysClient implements ISysClient { private ITenantService tenantService; + private IParamService paramService; + @Override @GetMapping(MENU) public R getMenu(Long id) { @@ -96,7 +91,7 @@ public class SysClient implements ISysClient { @Override @GetMapping(DEPT_CHILD) public R> getDeptChild(Long deptId) { - return R.data(deptService.list(Wrappers.query().lambda().like(Dept::getAncestors, deptId))); + return R.data(deptService.getDeptChild(deptId)); } @Override @@ -117,4 +112,16 @@ public class SysClient implements ISysClient { return R.data(tenantService.getById(id)); } + @Override + @GetMapping(PARAM) + public R getParam(Long id) { + return R.data(paramService.getById(id)); + } + + @Override + @GetMapping(PARAM_VALUE) + public R getParamValue(String paramKey) { + return R.data(paramService.getValue(paramKey)); + } + } diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/mapper/ParamMapper.java b/blade-service/blade-system/src/main/java/org/springblade/system/mapper/ParamMapper.java index 8638e6e7..3adf34f7 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/mapper/ParamMapper.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/mapper/ParamMapper.java @@ -17,11 +17,7 @@ package org.springblade.system.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.core.metadata.IPage; import org.springblade.system.entity.Param; -import org.springblade.system.vo.ParamVO; - -import java.util.List; /** * Mapper 接口 @@ -30,13 +26,4 @@ import java.util.List; */ public interface ParamMapper extends BaseMapper { - /** - * 自定义分页 - * - * @param page - * @param param - * @return - */ - List selectParamPage(IPage page, ParamVO param); - } diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/mapper/ParamMapper.xml b/blade-service/blade-system/src/main/java/org/springblade/system/mapper/ParamMapper.xml index cc21e4c9..e88fd76e 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/mapper/ParamMapper.xml +++ b/blade-service/blade-system/src/main/java/org/springblade/system/mapper/ParamMapper.xml @@ -17,21 +17,4 @@ - - - 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 - - - - diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/service/IDeptService.java b/blade-service/blade-system/src/main/java/org/springblade/system/service/IDeptService.java index dc3d5414..23793838 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/service/IDeptService.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/service/IDeptService.java @@ -19,7 +19,6 @@ package org.springblade.system.service; import com.baomidou.mybatisplus.extension.service.IService; import org.springblade.system.entity.Dept; import org.springblade.system.vo.DeptVO; -import org.springblade.system.vo.DeptVO; import java.util.List; import java.util.Map; @@ -66,6 +65,14 @@ public interface IDeptService extends IService { */ List getDeptNames(String deptIds); + /** + * 获取子部门 + * + * @param deptId + * @return + */ + List getDeptChild(Long deptId); + /** * 删除部门 * diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/service/IParamService.java b/blade-service/blade-system/src/main/java/org/springblade/system/service/IParamService.java index 226e0af3..ff29123b 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/service/IParamService.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/service/IParamService.java @@ -16,10 +16,8 @@ */ package org.springblade.system.service; -import com.baomidou.mybatisplus.core.metadata.IPage; import org.springblade.core.mp.base.BaseService; import org.springblade.system.entity.Param; -import org.springblade.system.vo.ParamVO; /** * 服务类 @@ -28,12 +26,12 @@ import org.springblade.system.vo.ParamVO; */ public interface IParamService extends BaseService { - /*** - * 自定义分页 - * @param page - * @param param - * @return + /** + * 获取参数值 + * + * @param paramKey 参数key + * @return String */ - IPage selectParamPage(IPage page, ParamVO param); + String getValue(String paramKey); } diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/DeptServiceImpl.java b/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/DeptServiceImpl.java index 8cb83f81..572f95e6 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/DeptServiceImpl.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/DeptServiceImpl.java @@ -80,6 +80,11 @@ public class DeptServiceImpl extends ServiceImpl implements ID return baseMapper.getDeptNames(Func.toLongArray(deptIds)); } + @Override + public List getDeptChild(Long deptId) { + return baseMapper.selectList(Wrappers.query().lambda().like(Dept::getAncestors, deptId)); + } + @Override public boolean removeDept(String ids) { Integer cnt = baseMapper.selectCount(Wrappers.query().lambda().in(Dept::getParentId, Func.toLongList(ids))); diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/ParamServiceImpl.java b/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/ParamServiceImpl.java index e2e707f0..3cd73c99 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/ParamServiceImpl.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/ParamServiceImpl.java @@ -16,12 +16,11 @@ */ package org.springblade.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.system.entity.Param; import org.springblade.system.mapper.ParamMapper; import org.springblade.system.service.IParamService; -import org.springblade.system.vo.ParamVO; import org.springframework.stereotype.Service; /** @@ -33,8 +32,9 @@ import org.springframework.stereotype.Service; public class ParamServiceImpl extends BaseServiceImpl implements IParamService { @Override - public IPage selectParamPage(IPage page, ParamVO param) { - return page.setRecords(baseMapper.selectParamPage(page, param)); + public String getValue(String paramKey) { + Param param = this.getOne(Wrappers.query().lambda().eq(Param::getParamKey, paramKey)); + return param.getParamValue(); } }