mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 20:49:00 +08:00
✨ 添加新特性:: 租户管理功能
This commit is contained in:
1 parent
c38a8cbbc8
commit
a841d13c74
40 files changed
+824
-133
No files matched your search
@@ -68,6 +68,11 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
<!-- druid 连接池 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!--freemarker-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@@ -115,13 +115,13 @@ public class PigxTokenEndpoint {
|
||||
@DeleteMapping("/logout")
|
||||
public R logout(@RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false) String authHeader) {
|
||||
if (StrUtil.isBlank(authHeader)) {
|
||||
return R.failed(Boolean.FALSE, "退出失败,token 为空");
|
||||
return R.ok(Boolean.FALSE, "退出失败,token 为空");
|
||||
}
|
||||
|
||||
String tokenValue = authHeader.replace(OAuth2AccessToken.BEARER_TYPE, StrUtil.EMPTY).trim();
|
||||
OAuth2AccessToken accessToken = tokenStore.readAccessToken(tokenValue);
|
||||
if (accessToken == null || StrUtil.isBlank(accessToken.getValue())) {
|
||||
return R.failed(Boolean.FALSE, "退出失败,token 无效");
|
||||
return R.ok(Boolean.TRUE, "退出失败,token 无效");
|
||||
}
|
||||
|
||||
OAuth2Authentication auth2Authentication = tokenStore.readAuthentication(accessToken);
|
||||
@@ -133,7 +133,7 @@ public class PigxTokenEndpoint {
|
||||
tokenStore.removeAccessToken(accessToken);
|
||||
|
||||
// 清空 refresh token
|
||||
OAuth2RefreshToken refreshToken = tokenStore.readRefreshToken(tokenValue);
|
||||
OAuth2RefreshToken refreshToken = accessToken.getRefreshToken();
|
||||
tokenStore.removeRefreshToken(refreshToken);
|
||||
return R.ok(Boolean.TRUE);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
<properties>
|
||||
<pigx.version>3.0.0</pigx.version>
|
||||
<mybatis-plus.version>3.1.0</mybatis-plus.version>
|
||||
<mysql.connector.version>8.0.15</mysql.connector.version>
|
||||
<druid.version>1.1.16</druid.version>
|
||||
<mysql.connector.version>8.0.16</mysql.connector.version>
|
||||
<swagger.core.version>1.5.22</swagger.core.version>
|
||||
<mp.weixin.version>3.3.0</mp.weixin.version>
|
||||
</properties>
|
||||
@@ -88,6 +89,12 @@
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
</dependency>
|
||||
<!-- druid 连接池 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>${druid.version}</version>
|
||||
</dependency>
|
||||
<!--mysql 驱动-->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
|
||||
+5
@@ -44,4 +44,9 @@ public interface CacheConstants {
|
||||
* 参数缓存
|
||||
*/
|
||||
String PARAMS_DETAILS = "params_details";
|
||||
|
||||
/**
|
||||
* 租户缓存
|
||||
*/
|
||||
String TENANT_DETAILS = "tenant_details";
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package com.pig4cloud.pigx.common.core.constant.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2019-05-16
|
||||
* <p>
|
||||
* 字典类型
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum DictTypeEnum {
|
||||
/**
|
||||
* 字典类型-系统内置(不可修改)
|
||||
*/
|
||||
SYSTEM("1", "系统内置"),
|
||||
|
||||
/**
|
||||
* 字典类型-业务类型
|
||||
*/
|
||||
BIZ("0", "业务类");
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
private String type;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
}
|
||||
@@ -77,6 +77,10 @@ public class R<T> implements Serializable {
|
||||
return restResult(null, CommonConstants.FAIL, msg);
|
||||
}
|
||||
|
||||
public static <T> R<T> failed(T data) {
|
||||
return restResult(data, CommonConstants.FAIL, null);
|
||||
}
|
||||
|
||||
public static <T> R<T> failed(T data, String msg) {
|
||||
return restResult(data, CommonConstants.FAIL, msg);
|
||||
}
|
||||
|
||||
+2
@@ -37,6 +37,8 @@ public class PigxTenantHandler implements TenantHandler {
|
||||
|
||||
/**
|
||||
* 获取租户值
|
||||
* <p>
|
||||
* TODO 校验租户状态
|
||||
*
|
||||
* @return 租户值
|
||||
*/
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ public class TenantContextHolder {
|
||||
*
|
||||
* @param tenantId
|
||||
*/
|
||||
void setTenantId(Integer tenantId) {
|
||||
public void setTenantId(Integer tenantId) {
|
||||
THREAD_LOCAL_TENANT.set(tenantId);
|
||||
}
|
||||
|
||||
|
||||
+39
-36
@@ -18,7 +18,6 @@ package com.pig4cloud.pigx.admin.api.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@@ -34,41 +33,45 @@ import java.time.LocalDateTime;
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SysDict extends Model<SysDict> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
@TableId
|
||||
private Integer id;
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
private String type;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* 备注信息
|
||||
*/
|
||||
private String remarks;
|
||||
/**
|
||||
* 删除标记
|
||||
*/
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
@TableId
|
||||
private Integer id;
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
private String type;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* 是否是系统内置
|
||||
*/
|
||||
private String system;
|
||||
/**
|
||||
* 备注信息
|
||||
*/
|
||||
private String remarks;
|
||||
/**
|
||||
* 删除标记
|
||||
*/
|
||||
@TableLogic
|
||||
private String delFlag;
|
||||
/**
|
||||
* 所属租户
|
||||
*/
|
||||
private Integer tenantId;
|
||||
|
||||
private String delFlag;
|
||||
/**
|
||||
* 所属租户
|
||||
*/
|
||||
private Integer tenantId;
|
||||
|
||||
}
|
||||
+6
@@ -88,6 +88,11 @@ public class SysPublicParam extends Model<SysPublicParam> {
|
||||
@ApiModelProperty(value = "创建时间", example = "2019-03-21 12:28:48")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 是否是系统内置
|
||||
*/
|
||||
private String system;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@@ -100,4 +105,5 @@ public class SysPublicParam extends Model<SysPublicParam> {
|
||||
@ApiModelProperty(value = "类型[1-检索;2-原文...]", example = "1")
|
||||
private String publicType;
|
||||
|
||||
|
||||
}
|
||||
@@ -82,6 +82,11 @@
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- druid 连接池 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!--数据库-->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
|
||||
+4
-6
@@ -114,7 +114,7 @@ public class DictController {
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("@pms.hasPermission('sys_dict_del')")
|
||||
public R removeById(@PathVariable Integer id) {
|
||||
return R.ok(sysDictService.removeDict(id));
|
||||
return sysDictService.removeDict(id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,7 +127,7 @@ public class DictController {
|
||||
@SysLog("修改字典")
|
||||
@PreAuthorize("@pms.hasPermission('sys_dict_edit')")
|
||||
public R updateById(@Valid @RequestBody SysDict sysDict) {
|
||||
return R.ok(sysDictService.updateById(sysDict));
|
||||
return sysDictService.updateDict(sysDict);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -175,9 +175,8 @@ public class DictController {
|
||||
*/
|
||||
@SysLog("修改字典项")
|
||||
@PutMapping("/item")
|
||||
@CacheEvict(value = CacheConstants.DICT_DETAILS, allEntries = true)
|
||||
public R updateById(@RequestBody SysDictItem sysDictItem) {
|
||||
return R.ok(sysDictItemService.updateById(sysDictItem));
|
||||
return sysDictItemService.updateDictItem(sysDictItem);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -188,8 +187,7 @@ public class DictController {
|
||||
*/
|
||||
@SysLog("删除字典项")
|
||||
@DeleteMapping("/item/{id}")
|
||||
@CacheEvict(value = CacheConstants.DICT_DETAILS, allEntries = true)
|
||||
public R removeDictItemById(@PathVariable Integer id) {
|
||||
return R.ok(sysDictItemService.removeById(id));
|
||||
return sysDictItemService.removeDictItem(id);
|
||||
}
|
||||
}
|
||||
+2
-4
@@ -108,10 +108,9 @@ public class SysPublicParamController {
|
||||
*/
|
||||
@SysLog("修改公共参数")
|
||||
@PutMapping
|
||||
@CacheEvict(value = CacheConstants.PARAMS_DETAILS, key = "#sysPublicParam.publicKey")
|
||||
@PreAuthorize("@pms.hasPermission('admin_syspublicparam_edit')")
|
||||
public R updateById(@RequestBody SysPublicParam sysPublicParam) {
|
||||
return R.ok(sysPublicParamService.updateById(sysPublicParam));
|
||||
return sysPublicParamService.updateParam(sysPublicParam);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,10 +121,9 @@ public class SysPublicParamController {
|
||||
*/
|
||||
@SysLog("删除公共参数")
|
||||
@DeleteMapping("/{publicId}")
|
||||
@CacheEvict(value = CacheConstants.PARAMS_DETAILS, allEntries = true)
|
||||
@PreAuthorize("@pms.hasPermission('admin_syspublicparam_del')")
|
||||
public R removeById(@PathVariable Long publicId) {
|
||||
return R.ok(sysPublicParamService.removeById(publicId));
|
||||
return sysPublicParamService.removeParam(publicId);
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+124
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2025, lengleng 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 pig4cloud.com 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: lengleng (wangiegie@gmail.com)
|
||||
*/
|
||||
|
||||
package com.pig4cloud.pigx.admin.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.pig4cloud.pigx.admin.entity.SysTenant;
|
||||
import com.pig4cloud.pigx.admin.service.SysTenantService;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.log.annotation.SysLog;
|
||||
import com.pig4cloud.pigx.common.security.annotation.Inner;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
|
||||
/**
|
||||
* 租户管理
|
||||
*
|
||||
* @author lengleng
|
||||
* @date 2019-05-15 15:55:41
|
||||
*/
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping("/tenant")
|
||||
@Api(value = "tenant", tags = "租户管理")
|
||||
public class SysTenantController {
|
||||
|
||||
private final SysTenantService sysTenantService;
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param sysTenant 租户
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
public R getSysTenantPage(Page page, SysTenant sysTenant) {
|
||||
return R.ok(sysTenantService.page(page, Wrappers.query(sysTenant)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过id查询租户
|
||||
*
|
||||
* @param id id
|
||||
* @return R
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public R getById(@PathVariable("id") Integer id) {
|
||||
return R.ok(sysTenantService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增租户
|
||||
*
|
||||
* @param sysTenant 租户
|
||||
* @return R
|
||||
*/
|
||||
@SysLog("新增租户")
|
||||
@PostMapping
|
||||
@PreAuthorize("@pms.hasPermission('admin_systenant_add')")
|
||||
public R save(@RequestBody SysTenant sysTenant) {
|
||||
return R.ok(sysTenantService.saveTenant(sysTenant));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改租户
|
||||
*
|
||||
* @param sysTenant 租户
|
||||
* @return R
|
||||
*/
|
||||
@SysLog("修改租户")
|
||||
@PutMapping
|
||||
@PreAuthorize("@pms.hasPermission('admin_systenant_edit')")
|
||||
public R updateById(@RequestBody SysTenant sysTenant) {
|
||||
return R.ok(sysTenantService.updateById(sysTenant));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除租户
|
||||
*
|
||||
* @param id id
|
||||
* @return R
|
||||
*/
|
||||
@SysLog("删除租户")
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("@pms.hasPermission('admin_systenant_del')")
|
||||
public R removeById(@PathVariable Integer id) {
|
||||
return R.ok(sysTenantService.removeById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询全部有效的租户
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@SysLog("查询全部有效的租户")
|
||||
@Inner(value = false)
|
||||
@GetMapping("/list")
|
||||
public R list() {
|
||||
return R.ok(sysTenantService.getNormal());
|
||||
}
|
||||
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2025, lengleng 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 pig4cloud.com 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: lengleng (wangiegie@gmail.com)
|
||||
*/
|
||||
|
||||
package com.pig4cloud.pigx.admin.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 租户
|
||||
*
|
||||
* @author lengleng
|
||||
* @date 2019-05-15 15:55:41
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_tenant")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel(description = "租户")
|
||||
public class SysTenant extends Model<SysTenant> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 租户id
|
||||
*/
|
||||
@TableId
|
||||
private Integer id;
|
||||
/**
|
||||
* 租户名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 租户编号
|
||||
*/
|
||||
private String code;
|
||||
/**
|
||||
* 开始时间
|
||||
*/
|
||||
private LocalDate startTime;
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
private LocalDate endTime;
|
||||
/**
|
||||
* 0正常 9-冻结
|
||||
*/
|
||||
private String status;
|
||||
/**
|
||||
* 删除标记
|
||||
*/
|
||||
@TableLogic
|
||||
private String delFlag;
|
||||
/**
|
||||
* 创建
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
}
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2025, lengleng 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 pig4cloud.com 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: lengleng (wangiegie@gmail.com)
|
||||
*/
|
||||
|
||||
package com.pig4cloud.pigx.admin.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.pig4cloud.pigx.admin.entity.SysTenant;
|
||||
|
||||
/**
|
||||
* 租户
|
||||
*
|
||||
* @author lengleng
|
||||
* @date 2019-05-15 15:55:41
|
||||
*/
|
||||
public interface SysTenantMapper extends BaseMapper<SysTenant> {
|
||||
|
||||
}
|
||||
+16
@@ -18,6 +18,7 @@ package com.pig4cloud.pigx.admin.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysDictItem;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
|
||||
/**
|
||||
* 字典项
|
||||
@@ -27,4 +28,19 @@ import com.pig4cloud.pigx.admin.api.entity.SysDictItem;
|
||||
*/
|
||||
public interface SysDictItemService extends IService<SysDictItem> {
|
||||
|
||||
/**
|
||||
* 删除字典项
|
||||
*
|
||||
* @param id 字典项ID
|
||||
* @return
|
||||
*/
|
||||
R removeDictItem(Integer id);
|
||||
|
||||
/**
|
||||
* 更新字典项
|
||||
*
|
||||
* @param item 字典项
|
||||
* @return
|
||||
*/
|
||||
R updateDictItem(SysDictItem item);
|
||||
}
|
||||
+10
-1
@@ -18,6 +18,7 @@ package com.pig4cloud.pigx.admin.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysDict;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
|
||||
/**
|
||||
* 字典表
|
||||
@@ -33,5 +34,13 @@ public interface SysDictService extends IService<SysDict> {
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
Boolean removeDict(Integer id);
|
||||
R removeDict(Integer id);
|
||||
|
||||
/**
|
||||
* 更新字典
|
||||
*
|
||||
* @param sysDict 字典
|
||||
* @return
|
||||
*/
|
||||
R updateDict(SysDict sysDict);
|
||||
}
|
||||
+18
@@ -19,6 +19,7 @@ package com.pig4cloud.pigx.admin.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysPublicParam;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
|
||||
/**
|
||||
* 公共参数配置
|
||||
@@ -30,8 +31,25 @@ public interface SysPublicParamService extends IService<SysPublicParam> {
|
||||
|
||||
/**
|
||||
* 通过key查询公共参数指定值
|
||||
*
|
||||
* @param publicKey
|
||||
* @return
|
||||
*/
|
||||
String getSysPublicParamKeyToValue(String publicKey);
|
||||
|
||||
/**
|
||||
* 更新参数
|
||||
*
|
||||
* @param sysPublicParam
|
||||
* @return
|
||||
*/
|
||||
R updateParam(SysPublicParam sysPublicParam);
|
||||
|
||||
/**
|
||||
* 删除参数
|
||||
*
|
||||
* @param publicId
|
||||
* @return
|
||||
*/
|
||||
R removeParam(Long publicId);
|
||||
}
|
||||
Executable
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2025, lengleng 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 pig4cloud.com 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: lengleng (wangiegie@gmail.com)
|
||||
*/
|
||||
|
||||
package com.pig4cloud.pigx.admin.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.pig4cloud.pigx.admin.entity.SysTenant;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 租户管理
|
||||
*
|
||||
* @author lengleng
|
||||
* @date 2019-05-15 15:55:41
|
||||
*/
|
||||
public interface SysTenantService extends IService<SysTenant> {
|
||||
|
||||
/**
|
||||
* 获取正常的租户
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<SysTenant> getNormal();
|
||||
|
||||
/**
|
||||
* 保存租户
|
||||
*
|
||||
* @param sysTenant
|
||||
* @return
|
||||
*/
|
||||
Boolean saveTenant(SysTenant sysTenant);
|
||||
}
|
||||
+2
@@ -34,6 +34,7 @@ import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -132,6 +133,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
private List<DeptTree> getDeptTree(List<SysDept> depts) {
|
||||
List<DeptTree> treeList = depts.stream()
|
||||
.filter(dept -> !dept.getDeptId().equals(dept.getParentId()))
|
||||
.sorted(Comparator.comparingInt(SysDept::getSort))
|
||||
.map(dept -> {
|
||||
DeptTree node = new DeptTree();
|
||||
node.setId(dept.getDeptId());
|
||||
|
||||
+45
@@ -17,9 +17,16 @@
|
||||
package com.pig4cloud.pigx.admin.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysDict;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysDictItem;
|
||||
import com.pig4cloud.pigx.admin.mapper.SysDictItemMapper;
|
||||
import com.pig4cloud.pigx.admin.service.SysDictItemService;
|
||||
import com.pig4cloud.pigx.admin.service.SysDictService;
|
||||
import com.pig4cloud.pigx.common.core.constant.CacheConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.enums.DictTypeEnum;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
@@ -29,6 +36,44 @@ import org.springframework.stereotype.Service;
|
||||
* @date 2019/03/19
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class SysDictItemServiceImpl extends ServiceImpl<SysDictItemMapper, SysDictItem> implements SysDictItemService {
|
||||
private final SysDictService dictService;
|
||||
|
||||
/**
|
||||
* 删除字典项
|
||||
*
|
||||
* @param id 字典项ID
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = CacheConstants.DICT_DETAILS, allEntries = true)
|
||||
public R removeDictItem(Integer id) {
|
||||
//根据ID查询字典ID
|
||||
SysDictItem dictItem = this.getById(id);
|
||||
SysDict dict = dictService.getById(dictItem.getDictId());
|
||||
// 系统内置
|
||||
if (DictTypeEnum.SYSTEM.getType().equals(dict.getSystem())) {
|
||||
return R.failed("系统内置字典项目不能删除");
|
||||
}
|
||||
return R.ok(this.removeById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新字典项
|
||||
*
|
||||
* @param item 字典项
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = CacheConstants.DICT_DETAILS, allEntries = true)
|
||||
public R updateDictItem(SysDictItem item) {
|
||||
//查询字典
|
||||
SysDict dict = dictService.getById(item.getDictId());
|
||||
// 系统内置
|
||||
if (DictTypeEnum.SYSTEM.getType().equals(dict.getSystem())) {
|
||||
return R.failed("系统内置字典项目不能删除");
|
||||
}
|
||||
return R.ok(this.updateById(item));
|
||||
}
|
||||
}
|
||||
+27
-4
@@ -24,6 +24,8 @@ import com.pig4cloud.pigx.admin.mapper.SysDictItemMapper;
|
||||
import com.pig4cloud.pigx.admin.mapper.SysDictMapper;
|
||||
import com.pig4cloud.pigx.admin.service.SysDictService;
|
||||
import com.pig4cloud.pigx.common.core.constant.CacheConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.enums.DictTypeEnum;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -43,17 +45,38 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
|
||||
/**
|
||||
* 根据ID 删除字典
|
||||
*
|
||||
* @param id
|
||||
* @param id 字典ID
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = CacheConstants.DICT_DETAILS, allEntries = true)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean removeDict(Integer id) {
|
||||
baseMapper.deleteById(id);
|
||||
public R removeDict(Integer id) {
|
||||
SysDict dict = this.getById(id);
|
||||
// 系统内置
|
||||
if (DictTypeEnum.SYSTEM.getType().equals(dict.getSystem())) {
|
||||
return R.failed("系统内置字典不能删除");
|
||||
}
|
||||
|
||||
baseMapper.deleteById(id);
|
||||
dictItemMapper.delete(Wrappers.<SysDictItem>lambdaQuery()
|
||||
.eq(SysDictItem::getDictId, id));
|
||||
return Boolean.TRUE;
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新字典
|
||||
*
|
||||
* @param dict 字典
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public R updateDict(SysDict dict) {
|
||||
SysDict sysDict = this.getById(dict.getId());
|
||||
// 系统内置
|
||||
if (DictTypeEnum.SYSTEM.getType().equals(sysDict.getSystem())) {
|
||||
return R.failed("系统内置字典不能修改");
|
||||
}
|
||||
return R.ok(this.updateById(dict));
|
||||
}
|
||||
}
|
||||
+37
@@ -23,7 +23,10 @@ import com.pig4cloud.pigx.admin.api.entity.SysPublicParam;
|
||||
import com.pig4cloud.pigx.admin.mapper.SysPublicParamMapper;
|
||||
import com.pig4cloud.pigx.admin.service.SysPublicParamService;
|
||||
import com.pig4cloud.pigx.common.core.constant.CacheConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.enums.DictTypeEnum;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -49,4 +52,38 @@ public class SysPublicParamServiceImpl extends ServiceImpl<SysPublicParamMapper,
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新参数
|
||||
*
|
||||
* @param sysPublicParam
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = CacheConstants.PARAMS_DETAILS, key = "#sysPublicParam.publicKey")
|
||||
public R updateParam(SysPublicParam sysPublicParam) {
|
||||
SysPublicParam param = this.getById(sysPublicParam.getPublicId());
|
||||
// 系统内置
|
||||
if (DictTypeEnum.SYSTEM.getType().equals(param.getSystem())) {
|
||||
return R.failed("系统内置参数不能删除");
|
||||
}
|
||||
return R.ok(this.updateById(sysPublicParam));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除参数
|
||||
*
|
||||
* @param publicId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = CacheConstants.PARAMS_DETAILS, allEntries = true)
|
||||
public R removeParam(Long publicId) {
|
||||
SysPublicParam param = this.getById(publicId);
|
||||
// 系统内置
|
||||
if (DictTypeEnum.SYSTEM.getType().equals(param.getSystem())) {
|
||||
return R.failed("系统内置参数不能删除");
|
||||
}
|
||||
return R.ok(this.removeById(publicId));
|
||||
}
|
||||
}
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2025, lengleng 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 pig4cloud.com 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: lengleng (wangiegie@gmail.com)
|
||||
*/
|
||||
package com.pig4cloud.pigx.admin.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.pig4cloud.pigx.admin.api.entity.*;
|
||||
import com.pig4cloud.pigx.admin.entity.SysTenant;
|
||||
import com.pig4cloud.pigx.admin.mapper.SysTenantMapper;
|
||||
import com.pig4cloud.pigx.admin.service.*;
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.enums.DictTypeEnum;
|
||||
import com.pig4cloud.pigx.common.core.exception.CheckedException;
|
||||
import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.apache.commons.configuration.Configuration;
|
||||
import org.apache.commons.configuration.ConfigurationException;
|
||||
import org.apache.commons.configuration.PropertiesConfiguration;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 租户
|
||||
*
|
||||
* @author lengleng
|
||||
* @date 2019-05-15 15:55:41
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class SysTenantServiceImpl extends ServiceImpl<SysTenantMapper, SysTenant> implements SysTenantService {
|
||||
private static final PasswordEncoder ENCODER = new BCryptPasswordEncoder();
|
||||
private final SysDeptRelationService deptRelationService;
|
||||
private final SysUserRoleService userRoleService;
|
||||
private final SysRoleMenuService roleMenuService;
|
||||
private final SysDictItemService dictItemService;
|
||||
private final SysUserService userService;
|
||||
private final SysRoleService roleService;
|
||||
private final SysMenuService menuService;
|
||||
private final SysDeptService deptService;
|
||||
private final SysDictService dictService;
|
||||
|
||||
/**
|
||||
* 获取正常状态租户
|
||||
* <p>
|
||||
* 1. 状态正常
|
||||
* 2. 开始时间小于等于当前时间
|
||||
* 3. 结束时间大于等于当前时间
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<SysTenant> getNormal() {
|
||||
return list(Wrappers.<SysTenant>lambdaQuery()
|
||||
.eq(SysTenant::getStatus, CommonConstants.STATUS_NORMAL)
|
||||
.le(SysTenant::getStartTime, LocalDate.now())
|
||||
.ge(SysTenant::getEndTime, LocalDate.now()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存租户
|
||||
* <p>
|
||||
* 1. 保存租户
|
||||
* 2. 初始化权限相关表
|
||||
* - sys_user
|
||||
* - sys_role
|
||||
* - sys_user_role
|
||||
* - sys_role_menu
|
||||
* - sys_dict
|
||||
* - sys_dict_item
|
||||
*
|
||||
* @param sysTenant 租户实体
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean saveTenant(SysTenant sysTenant) {
|
||||
this.save(sysTenant);
|
||||
|
||||
// 查询系统内置字典
|
||||
List<SysDict> dictList = dictService.list(Wrappers.<SysDict>lambdaQuery()
|
||||
.eq(SysDict::getSystem, DictTypeEnum.SYSTEM.getType()))
|
||||
.stream().map(dict -> {
|
||||
SysDict sysDict = new SysDict();
|
||||
BeanUtils.copyProperties(dict, sysDict, "tenantId");
|
||||
return sysDict;
|
||||
}).collect(Collectors.toList());
|
||||
// 查询系统内置字典项目
|
||||
List<Integer> dictIdList = dictList.stream().map(SysDict::getId)
|
||||
.collect(Collectors.toList());
|
||||
List<SysDictItem> dictItemList = dictItemService.list(Wrappers.<SysDictItem>lambdaQuery()
|
||||
.in(SysDictItem::getDictId, dictIdList))
|
||||
.stream().map(item -> {
|
||||
SysDictItem sysDictItem = new SysDictItem();
|
||||
BeanUtils.copyProperties(item, sysDictItem, "tenantId");
|
||||
return sysDictItem;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
// 保证插入租户为新的租户
|
||||
TenantContextHolder.setTenantId(sysTenant.getId());
|
||||
Configuration config = getConfig();
|
||||
|
||||
// 插入部门
|
||||
SysDept dept = new SysDept();
|
||||
dept.setName(config.getString("defaultDeptName"));
|
||||
dept.setParentId(0);
|
||||
deptService.save(dept);
|
||||
//维护部门关系
|
||||
deptRelationService.insertDeptRelation(dept);
|
||||
// 构造初始化用户
|
||||
SysUser user = new SysUser();
|
||||
user.setUsername(config.getString("defaultUsername"));
|
||||
user.setPassword(ENCODER.encode(config.getString("defaultPassword")));
|
||||
user.setDeptId(dept.getDeptId());
|
||||
userService.save(user);
|
||||
// 构造新角色
|
||||
SysRole role = new SysRole();
|
||||
role.setRoleCode(config.getString("defaultRoleCode"));
|
||||
role.setRoleName(config.getString("defaultRoleName"));
|
||||
roleService.save(role);
|
||||
// 用户角色关系
|
||||
SysUserRole userRole = new SysUserRole();
|
||||
userRole.setUserId(user.getUserId());
|
||||
userRole.setRoleId(role.getRoleId());
|
||||
userRoleService.save(userRole);
|
||||
// 查询全部菜单,构造角色菜单关系
|
||||
List<SysRoleMenu> collect = menuService.list()
|
||||
.stream().map(menu -> {
|
||||
SysRoleMenu roleMenu = new SysRoleMenu();
|
||||
roleMenu.setRoleId(role.getRoleId());
|
||||
roleMenu.setMenuId(menu.getMenuId());
|
||||
return roleMenu;
|
||||
}).collect(Collectors.toList());
|
||||
roleMenuService.saveBatch(collect);
|
||||
// 插入系统字典和字典项
|
||||
dictService.saveBatch(dictList);
|
||||
return dictItemService.saveBatch(dictItemList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置信息
|
||||
*/
|
||||
private Configuration getConfig() {
|
||||
try {
|
||||
return new PropertiesConfiguration("tenant/tenant.properties");
|
||||
} catch (ConfigurationException e) {
|
||||
throw new CheckedException("获取配置文件失败,", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
~
|
||||
~ Copyright (c) 2018-2025, lengleng 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 pig4cloud.com 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: lengleng (wangiegie@gmail.com)
|
||||
~
|
||||
-->
|
||||
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.pig4cloud.pigx.admin.mapper.SysTenantMapper">
|
||||
|
||||
<resultMap id="sysTenantMap" type="com.pig4cloud.pigx.admin.entity.SysTenant">
|
||||
<id property="id" column="id"/>
|
||||
<result property="name" column="name"/>
|
||||
<result property="code" column="code"/>
|
||||
<result property="startTime" column="start_time"/>
|
||||
<result property="endTime" column="end_time"/>
|
||||
<result property="status" column="status"/>
|
||||
<result property="delFlag" column="del_flag"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="updateTime" column="update_time"/>
|
||||
</resultMap>
|
||||
</mapper>
|
||||
@@ -0,0 +1,6 @@
|
||||
# \u79DF\u6237\u521D\u59CB\u5316\u9ED8\u8BA4\u914D\u7F6E
|
||||
defaultUsername=admin
|
||||
defaultPassword=123456
|
||||
defaultRoleCode=ROLE_admin
|
||||
defaultRoleName=\u79DF\u6237\u9ED8\u8BA4\u89D2\u8272
|
||||
defaultDeptName=\u79DF\u6237\u9ED8\u8BA4\u90E8\u95E8
|
||||
@@ -61,6 +61,11 @@
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- druid 连接池 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!--websocket-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@@ -39,6 +39,11 @@
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<!-- druid 连接池 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!--common-->
|
||||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.pig4cloud.pigx.codegen.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2019-05-14
|
||||
* <p>
|
||||
* 参考DruidDataSourceWrapper
|
||||
*/
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties("spring.datasource.druid")
|
||||
public class DruidDataSourceProperties {
|
||||
private String username;
|
||||
private String password;
|
||||
private String url;
|
||||
private String driverClassName;
|
||||
}
|
||||
+6
-7
@@ -1,12 +1,11 @@
|
||||
package com.pig4cloud.pigx.codegen.config;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.mysql.cj.jdbc.Driver;
|
||||
import com.pig4cloud.pigx.codegen.util.DataSourceConstants;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jasypt.encryption.StringEncryptor;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
@@ -32,14 +31,14 @@ import java.util.Optional;
|
||||
@AllArgsConstructor
|
||||
public class DynamicDataSourceConfig implements TransactionManagementConfigurer {
|
||||
private final Map<Object, Object> dataSourceMap = new HashMap<>(8);
|
||||
private final DataSourceProperties dataSourceProperties;
|
||||
private final DruidDataSourceProperties dataSourceProperties;
|
||||
private final StringEncryptor stringEncryptor;
|
||||
|
||||
@Bean("dynamicDataSource")
|
||||
public DynamicDataSource dataSource() {
|
||||
DynamicDataSource ds = new DynamicDataSource();
|
||||
HikariDataSource cads = new HikariDataSource();
|
||||
cads.setJdbcUrl(dataSourceProperties.getUrl());
|
||||
DruidDataSource cads = new DruidDataSource();
|
||||
cads.setUrl(dataSourceProperties.getUrl());
|
||||
cads.setDriverClassName(dataSourceProperties.getDriverClassName());
|
||||
cads.setUsername(dataSourceProperties.getUsername());
|
||||
cads.setPassword(dataSourceProperties.getPassword());
|
||||
@@ -64,8 +63,8 @@ public class DynamicDataSourceConfig implements TransactionManagementConfigurer
|
||||
log.info("开始 -> 初始化动态数据源");
|
||||
Optional.of(dbList).ifPresent(list -> list.forEach(db -> {
|
||||
log.info("数据源:{}", db.get(DataSourceConstants.DS_NAME));
|
||||
HikariDataSource ds = new HikariDataSource();
|
||||
ds.setJdbcUrl(String.valueOf(db.get(DataSourceConstants.DS_JDBC_URL)));
|
||||
DruidDataSource ds = new DruidDataSource();
|
||||
ds.setUrl(String.valueOf(db.get(DataSourceConstants.DS_JDBC_URL)));
|
||||
ds.setDriverClassName(Driver.class.getName());
|
||||
ds.setUsername((String) db.get(DataSourceConstants.DS_USER_NAME));
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@
|
||||
this.page.total = response.data.data.total
|
||||
this.tableLoading = false
|
||||
}).catch(() => {
|
||||
this.listLoading=false
|
||||
this.tableLoading=false
|
||||
})
|
||||
},
|
||||
rowDel: function (row, index) {
|
||||
|
||||
@@ -65,6 +65,11 @@
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<!-- druid 连接池 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!--ZK 依赖-->
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
|
||||
@@ -44,6 +44,11 @@
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<!-- druid 连接池 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!--swagger-->
|
||||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
|
||||
-11
@@ -28,15 +28,4 @@ public class RedisController {
|
||||
public R memory() {
|
||||
return R.ok(redisService.getInfo());
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行用户输入命令
|
||||
*
|
||||
* @param command 命令
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/exec")
|
||||
public R exec(String command) {
|
||||
return redisService.exec(command);
|
||||
}
|
||||
}
|
||||
-10
@@ -1,7 +1,5 @@
|
||||
package com.pig4cloud.pigx.monitor.service;
|
||||
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -17,12 +15,4 @@ public interface RedisService {
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> getInfo();
|
||||
|
||||
/**
|
||||
* 执行运行命令
|
||||
*
|
||||
* @param command
|
||||
* @return
|
||||
*/
|
||||
R exec(String command);
|
||||
}
|
||||
-32
@@ -2,10 +2,7 @@ package com.pig4cloud.pigx.monitor.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.monitor.service.RedisService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -52,33 +49,4 @@ public class RedisServiceImpl implements RedisService {
|
||||
result.put("commandStats", pieList);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行运行命令
|
||||
*
|
||||
* @param input 用户输入
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public R exec(String input) {
|
||||
try {
|
||||
Object result = redisTemplate.execute((RedisCallback) connection -> {
|
||||
String[] arrs = input.split(StrUtil.SPACE);
|
||||
if (arrs.length == 1) {
|
||||
return connection.execute(arrs[0]);
|
||||
}
|
||||
|
||||
String[] args = ArrayUtil.sub(arrs, 1, arrs.length);
|
||||
byte[][] bytes = new byte[args.length][];
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
bytes[i] = StrUtil.bytes(args[i], CharsetUtil.UTF_8);
|
||||
}
|
||||
return connection.execute(arrs[0], bytes);
|
||||
});
|
||||
return R.ok(StrUtil.str(result, CharsetUtil.UTF_8), "success");
|
||||
} catch (Exception e) {
|
||||
log.error("REDIS 命令执行失败", e);
|
||||
return R.failed("error");
|
||||
}
|
||||
}
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
package com.pig4cloud.pigx.monitor.service.impl;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2019-05-09
|
||||
*/
|
||||
public class RedisServiceImplTest {
|
||||
|
||||
@Test
|
||||
public void exec() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,11 @@
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<!-- druid 连接池 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!--common-->
|
||||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
</developers>
|
||||
|
||||
<properties>
|
||||
<spring-boot.version>2.1.4.RELEASE</spring-boot.version>
|
||||
<spring-boot.version>2.1.5.RELEASE</spring-boot.version>
|
||||
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
|
||||
<spring-platform.version>Cairo-SR8</spring-platform.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
Reference in new issue
Block a user