Browse Source

添加参数统一获取类

test
smallchill 5 years ago
parent
commit
72a9c4f224
  1. 72
      blade-service-api/blade-system-api/src/main/java/org/springblade/system/cache/ParamCache.java
  2. 27
      blade-service-api/blade-system-api/src/main/java/org/springblade/system/feign/ISysClient.java
  3. 15
      blade-service-api/blade-system-api/src/main/java/org/springblade/system/feign/ISysClientFallback.java
  4. 27
      blade-service/blade-system/src/main/java/org/springblade/system/feign/SysClient.java
  5. 13
      blade-service/blade-system/src/main/java/org/springblade/system/mapper/ParamMapper.java
  6. 17
      blade-service/blade-system/src/main/java/org/springblade/system/mapper/ParamMapper.xml
  7. 9
      blade-service/blade-system/src/main/java/org/springblade/system/service/IDeptService.java
  8. 14
      blade-service/blade-system/src/main/java/org/springblade/system/service/IParamService.java
  9. 5
      blade-service/blade-system/src/main/java/org/springblade/system/service/impl/DeptServiceImpl.java
  10. 8
      blade-service/blade-system/src/main/java/org/springblade/system/service/impl/ParamServiceImpl.java

72
blade-service-api/blade-system-api/src/main/java/org/springblade/system/cache/ParamCache.java vendored

@ -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<Param> 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<String> result = getSysClient().getParamValue(paramKey);
return result.getData();
});
}
}

27
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.launch.constant.AppConstant;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springblade.system.entity.Dept; import org.springblade.system.entity.*;
import org.springblade.system.entity.Menu;
import org.springblade.system.entity.Role;
import org.springblade.system.entity.Tenant;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
@ -51,6 +48,8 @@ public interface ISysClient {
String ROLE_ALIAS = API_PREFIX + "/role-alias"; String ROLE_ALIAS = API_PREFIX + "/role-alias";
String ROLE_ALIASES = API_PREFIX + "/role-aliases"; String ROLE_ALIASES = API_PREFIX + "/role-aliases";
String TENANT = API_PREFIX + "/tenant"; 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 主键 * @param id 主键
* @return Tenant> * @return Tenant
*/ */
@GetMapping(TENANT) @GetMapping(TENANT)
R<Tenant> getTenant(@RequestParam("id") Long id); R<Tenant> getTenant(@RequestParam("id") Long id);
/**
* 获取参数
*
* @param id 主键
* @return Param
*/
@GetMapping(PARAM)
R<Param> getParam(@RequestParam("id") Long id);
/**
* 获取参数配置
*
* @param paramKey 参数key
* @return String
*/
@GetMapping(PARAM_VALUE)
R<String> getParamValue(@RequestParam("paramKey") String paramKey);
} }

15
blade-service-api/blade-system-api/src/main/java/org/springblade/system/feign/ISysClientFallback.java

@ -17,10 +17,7 @@
package org.springblade.system.feign; package org.springblade.system.feign;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springblade.system.entity.Dept; import org.springblade.system.entity.*;
import org.springblade.system.entity.Menu;
import org.springblade.system.entity.Role;
import org.springblade.system.entity.Tenant;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List; import java.util.List;
@ -87,4 +84,14 @@ public class ISysClientFallback implements ISysClient {
public R<Tenant> getTenant(Long id) { public R<Tenant> getTenant(Long id) {
return R.fail("获取数据失败"); return R.fail("获取数据失败");
} }
@Override
public R<Param> getParam(Long id) {
return R.fail("获取数据失败");
}
@Override
public R<String> getParamValue(Long paramKey) {
return R.fail("获取数据失败");
}
} }

27
blade-service/blade-system/src/main/java/org/springblade/system/feign/SysClient.java

@ -16,17 +16,10 @@
*/ */
package org.springblade.system.feign; package org.springblade.system.feign;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springblade.system.entity.Dept; import org.springblade.system.entity.*;
import org.springblade.system.entity.Menu; import org.springblade.system.service.*;
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.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore; import springfox.documentation.annotations.ApiIgnore;
@ -51,6 +44,8 @@ public class SysClient implements ISysClient {
private ITenantService tenantService; private ITenantService tenantService;
private IParamService paramService;
@Override @Override
@GetMapping(MENU) @GetMapping(MENU)
public R<Menu> getMenu(Long id) { public R<Menu> getMenu(Long id) {
@ -96,7 +91,7 @@ public class SysClient implements ISysClient {
@Override @Override
@GetMapping(DEPT_CHILD) @GetMapping(DEPT_CHILD)
public R<List<Dept>> getDeptChild(Long deptId) { public R<List<Dept>> getDeptChild(Long deptId) {
return R.data(deptService.list(Wrappers.<Dept>query().lambda().like(Dept::getAncestors, deptId))); return R.data(deptService.getDeptChild(deptId));
} }
@Override @Override
@ -117,4 +112,16 @@ public class SysClient implements ISysClient {
return R.data(tenantService.getById(id)); return R.data(tenantService.getById(id));
} }
@Override
@GetMapping(PARAM)
public R<Param> getParam(Long id) {
return R.data(paramService.getById(id));
}
@Override
@GetMapping(PARAM_VALUE)
public R<String> getParamValue(String paramKey) {
return R.data(paramService.getValue(paramKey));
}
} }

13
blade-service/blade-system/src/main/java/org/springblade/system/mapper/ParamMapper.java

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

17
blade-service/blade-system/src/main/java/org/springblade/system/mapper/ParamMapper.xml

@ -17,21 +17,4 @@
<result column="remark" property="remark"/> <result column="remark" property="remark"/>
</resultMap> </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> </mapper>

9
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 com.baomidou.mybatisplus.extension.service.IService;
import org.springblade.system.entity.Dept; import org.springblade.system.entity.Dept;
import org.springblade.system.vo.DeptVO; import org.springblade.system.vo.DeptVO;
import org.springblade.system.vo.DeptVO;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -66,6 +65,14 @@ public interface IDeptService extends IService<Dept> {
*/ */
List<String> getDeptNames(String deptIds); List<String> getDeptNames(String deptIds);
/**
* 获取子部门
*
* @param deptId
* @return
*/
List<Dept> getDeptChild(Long deptId);
/** /**
* 删除部门 * 删除部门
* *

14
blade-service/blade-system/src/main/java/org/springblade/system/service/IParamService.java

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

5
blade-service/blade-system/src/main/java/org/springblade/system/service/impl/DeptServiceImpl.java

@ -80,6 +80,11 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements ID
return baseMapper.getDeptNames(Func.toLongArray(deptIds)); return baseMapper.getDeptNames(Func.toLongArray(deptIds));
} }
@Override
public List<Dept> getDeptChild(Long deptId) {
return baseMapper.selectList(Wrappers.<Dept>query().lambda().like(Dept::getAncestors, deptId));
}
@Override @Override
public boolean removeDept(String ids) { public boolean removeDept(String ids) {
Integer cnt = baseMapper.selectCount(Wrappers.<Dept>query().lambda().in(Dept::getParentId, Func.toLongList(ids))); Integer cnt = baseMapper.selectCount(Wrappers.<Dept>query().lambda().in(Dept::getParentId, Func.toLongList(ids)));

8
blade-service/blade-system/src/main/java/org/springblade/system/service/impl/ParamServiceImpl.java

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

Loading…
Cancel
Save