微服务版后端初始化
This commit is contained in:
@ -0,0 +1,31 @@
|
||||
package com.xjrsoft.tenant.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: tzx
|
||||
* @Date: 2023/8/14 14:37
|
||||
*/
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties("xjrsoft.tenant")
|
||||
public class TenantConfig {
|
||||
|
||||
private Boolean enabled;
|
||||
|
||||
private String adminTenantCode;
|
||||
|
||||
private String tenantField;
|
||||
|
||||
private Boolean isUseDefaultTenant;
|
||||
|
||||
private String defaultTenantCode;
|
||||
|
||||
private List<Long> hiddenSubMenuIds;
|
||||
|
||||
private List<String> ignoreTable;
|
||||
}
|
||||
@ -0,0 +1,95 @@
|
||||
package com.xjrsoft.tenant.entity;
|
||||
|
||||
import com.xjrsoft.common.core.domain.base.AuditEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 机构
|
||||
* </p>
|
||||
*
|
||||
* @author tzx
|
||||
* @since 2022-03-02
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class Department extends AuditEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private Long parentId;
|
||||
|
||||
private String code;
|
||||
|
||||
private String mobile;
|
||||
|
||||
private String email;
|
||||
|
||||
private String website;
|
||||
|
||||
private String address;
|
||||
|
||||
private Integer sortCode;
|
||||
|
||||
private String remark;
|
||||
|
||||
private String hierarchy;
|
||||
|
||||
private Integer departmentType;
|
||||
|
||||
private Long tenantId;
|
||||
|
||||
private String shortName;
|
||||
|
||||
private Long departmentNature;
|
||||
|
||||
private LocalDateTime establishedTime;
|
||||
|
||||
private Long custodian;
|
||||
|
||||
private String facsimile;
|
||||
|
||||
private Long administrativeLeader;
|
||||
|
||||
private Long partyCommitteeLeader;
|
||||
|
||||
private String departmentLeaders;
|
||||
|
||||
private String chargeOfLeaders;
|
||||
|
||||
private String departmentLabel;
|
||||
|
||||
private String extensionNumber;
|
||||
|
||||
private Long industry;
|
||||
|
||||
private String corporateLegalPerson;
|
||||
|
||||
private String phoneNumber;
|
||||
|
||||
private String contactNumber;
|
||||
|
||||
private String depositBank;
|
||||
|
||||
private String bankAccount;
|
||||
|
||||
private String businessScope;
|
||||
|
||||
private Long wechatDeptId;
|
||||
|
||||
private Long dingtalkDeptId;
|
||||
|
||||
private String dingAgentId;
|
||||
|
||||
private String dingAppKey;
|
||||
|
||||
private String dingAppSecret;
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
package com.xjrsoft.tenant.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 岗位
|
||||
* </p>
|
||||
*
|
||||
* @author tzx
|
||||
* @since 2022-03-02
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class Post implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String code;
|
||||
|
||||
private Long parentId;
|
||||
|
||||
private Integer sortCode;
|
||||
|
||||
private String remark;
|
||||
|
||||
private Long deptId;
|
||||
|
||||
private Long tenantId;
|
||||
}
|
||||
|
||||
@ -0,0 +1,40 @@
|
||||
package com.xjrsoft.tenant.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.xjrsoft.common.core.domain.base.AuditEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author tzx
|
||||
* @since 2023-08-14
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("xjr_tenant")
|
||||
public class Tenant extends AuditEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long id;
|
||||
|
||||
private String code;
|
||||
|
||||
private String name;
|
||||
|
||||
private LocalDateTime startTime;
|
||||
|
||||
private LocalDateTime endTime;
|
||||
|
||||
private String remark;
|
||||
|
||||
private Integer sortCode;
|
||||
|
||||
}
|
||||
@ -0,0 +1,91 @@
|
||||
package com.xjrsoft.tenant.entity;
|
||||
|
||||
import com.xjrsoft.common.core.domain.base.AuditEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户
|
||||
* </p>
|
||||
*
|
||||
* @author tzx
|
||||
* @since 2022-03-02
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class User extends AuditEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long id;
|
||||
|
||||
private String userName;
|
||||
|
||||
private String name;
|
||||
|
||||
private String code;
|
||||
|
||||
private String nickName;
|
||||
|
||||
private String password;
|
||||
|
||||
private Integer gender;
|
||||
|
||||
private String mobile;
|
||||
|
||||
private Long postId;
|
||||
|
||||
private String avatar;
|
||||
|
||||
private String email;
|
||||
|
||||
private String address;
|
||||
|
||||
private Double longitude;
|
||||
|
||||
private Double latitude;
|
||||
|
||||
private Integer sortCode;
|
||||
|
||||
private String remark;
|
||||
|
||||
private Long departmentId;
|
||||
|
||||
private String wechatNumber;
|
||||
|
||||
private String qqNumber;
|
||||
|
||||
private LocalDateTime birthDate;
|
||||
|
||||
private Long tenantId;
|
||||
|
||||
private String tenantCode;
|
||||
|
||||
private Integer passwordAuthentication;
|
||||
|
||||
private String phoneNumber;
|
||||
|
||||
private String identityCardNumber;
|
||||
|
||||
private Long politicsStatus;
|
||||
|
||||
private Long administrativePost;
|
||||
|
||||
private Long administrativeRank;
|
||||
|
||||
private Long secretLevel;
|
||||
|
||||
private Long professionalTitleGrade;
|
||||
|
||||
private Long technicalPosition;
|
||||
|
||||
private Long managerialPosition;
|
||||
|
||||
private Long vocationalSkill;
|
||||
|
||||
private String bindIp;
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package com.xjrsoft.tenant.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xjrsoft.tenant.entity.Tenant;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author tzx
|
||||
* @since 2023-08-14
|
||||
*/
|
||||
@Mapper()
|
||||
public interface CommonTenantMapper extends BaseMapper<Tenant> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,142 @@
|
||||
package com.xjrsoft.tenant.util;
|
||||
|
||||
import cn.dev33.satoken.session.SaSession;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.xjrsoft.common.core.constant.GlobalConstant;
|
||||
import com.xjrsoft.organization.entity.Post;
|
||||
import com.xjrsoft.organization.entity.User;
|
||||
import com.xjrsoft.tenant.entity.Department;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: tzx
|
||||
* @Date: 2023/8/18 15:31
|
||||
*/
|
||||
public class SecureUtil {
|
||||
|
||||
/**
|
||||
* 本地线程中存当前登录用户,用于无请求的情况(定时任务等)
|
||||
* 需自行调用setCurrentUser和removeCurrentUser,注意线程溢出
|
||||
*/
|
||||
private static final ThreadLocal<User>userThreadLocal=new ThreadLocal<>();
|
||||
public static void setCurrentUser(User user){
|
||||
userThreadLocal.set(user);
|
||||
}
|
||||
public static void removeCurrentUser(){
|
||||
userThreadLocal.remove();
|
||||
}
|
||||
private static final ThreadLocal<Department>deptThreadLocal=new ThreadLocal<>();
|
||||
public static void setCurrentDept(Department dept){
|
||||
deptThreadLocal.set(dept);
|
||||
}
|
||||
public static void removeCurrentDept(){
|
||||
deptThreadLocal.remove();
|
||||
}
|
||||
private static final ThreadLocal<Post>postThreadLocal=new ThreadLocal<>();
|
||||
public static void setCurrentPost(Post post){
|
||||
postThreadLocal.set(post);
|
||||
}
|
||||
public static void removeCurrentPost(){
|
||||
postThreadLocal.remove();
|
||||
}
|
||||
private static final ThreadLocal<Long>userIdThreadLocal=new ThreadLocal<>();
|
||||
public static void setCurrentUserId(Long userId){
|
||||
userIdThreadLocal.set(userId);
|
||||
}
|
||||
public static void removeCurrentUserId(){
|
||||
userIdThreadLocal.remove();
|
||||
}
|
||||
|
||||
public static User getCurrentUser(){
|
||||
//先从本地线程取
|
||||
if(userThreadLocal.get()!=null){
|
||||
return userThreadLocal.get();
|
||||
}
|
||||
SaSession tokenSession = StpUtil.getTokenSession();
|
||||
return tokenSession.get(GlobalConstant.LOGIN_USER_INFO_KEY, new User());
|
||||
}
|
||||
public static Long getCurrentUserId(){
|
||||
//先从本地线程取
|
||||
if(userIdThreadLocal.get()!=null){
|
||||
return userIdThreadLocal.get();
|
||||
}
|
||||
return StpUtil.getLoginIdAsLong();
|
||||
}
|
||||
|
||||
public static Department getCurrentDept(){
|
||||
//先从本地线程取
|
||||
if(deptThreadLocal.get()!=null){
|
||||
return deptThreadLocal.get();
|
||||
}
|
||||
SaSession tokenSession = StpUtil.getTokenSession();
|
||||
return tokenSession.get(GlobalConstant.LOGIN_USER_DEPT_INFO_KEY, new Department());
|
||||
}
|
||||
public static Long getCurrentDeptId(){
|
||||
Department currentDept=getCurrentDept();
|
||||
return currentDept!=null?currentDept.getId():null;
|
||||
}
|
||||
|
||||
public static Post getCurrentPost(){
|
||||
//先从本地线程取
|
||||
if(postThreadLocal.get()!=null){
|
||||
return postThreadLocal.get();
|
||||
}
|
||||
SaSession tokenSession = StpUtil.getTokenSession();
|
||||
return tokenSession.get(GlobalConstant.LOGIN_USER_POST_INFO_KEY, new Post());
|
||||
}
|
||||
public static Long getCurrentPostId(){
|
||||
Post currentPost=getCurrentPost();
|
||||
return currentPost!=null?currentPost.getId():null;
|
||||
}
|
||||
|
||||
public static Boolean hasRole(String roleCode){
|
||||
SaSession tokenSession = StpUtil.getTokenSession();
|
||||
List<String> roleCodeList=tokenSession.get(GlobalConstant.LOGIN_USER_ROLE_CODE_KEY,new ArrayList<>());
|
||||
return roleCodeList!=null&&roleCodeList.contains(roleCode);
|
||||
}
|
||||
public static Boolean hasAnyRole(String[] roleCodes){
|
||||
SaSession tokenSession = StpUtil.getTokenSession();
|
||||
List<String> roleCodeList=tokenSession.get(GlobalConstant.LOGIN_USER_ROLE_CODE_KEY,new ArrayList<>());
|
||||
return roleCodeList!=null&& Arrays.stream(roleCodes).anyMatch(s->roleCodeList.contains(s));
|
||||
}
|
||||
public static Boolean hasAllRoles(String[] roleCodes){
|
||||
SaSession tokenSession = StpUtil.getTokenSession();
|
||||
List<String> roleCodeList=tokenSession.get(GlobalConstant.LOGIN_USER_ROLE_CODE_KEY,new ArrayList<>());
|
||||
return roleCodeList!=null&& roleCodeList.containsAll(Arrays.asList(roleCodes));
|
||||
}
|
||||
|
||||
public static List<Department>getCompanyOfCurrentUser(){
|
||||
SaSession tokenSession = StpUtil.getTokenSession();
|
||||
return tokenSession.get(GlobalConstant.LOGIN_USER_COMPANY_LIST_KEY,new ArrayList());
|
||||
}
|
||||
public static List<Department>getSubCompanyOfCurrentUser(){
|
||||
SaSession tokenSession = StpUtil.getTokenSession();
|
||||
return tokenSession.get(GlobalConstant.LOGIN_USER_SUBCOMPANY_LIST_KEY,new ArrayList());
|
||||
}
|
||||
public static List<Department>getSuperCompanyOfCurrentUser(){
|
||||
SaSession tokenSession = StpUtil.getTokenSession();
|
||||
return tokenSession.get(GlobalConstant.LOGIN_USER_SUPERCOMPANY_LIST_KEY,new ArrayList());
|
||||
}
|
||||
public static List<Department>getCompanyWithSubOfCurrentUser(){
|
||||
SaSession tokenSession = StpUtil.getTokenSession();
|
||||
List<Department>result=new ArrayList<>();
|
||||
result.addAll(tokenSession.get(GlobalConstant.LOGIN_USER_COMPANY_LIST_KEY,new ArrayList()));
|
||||
result.addAll(tokenSession.get(GlobalConstant.LOGIN_USER_SUBCOMPANY_LIST_KEY,new ArrayList()));
|
||||
return result;
|
||||
}
|
||||
public static List<Department>getCompanyWithSuperAndSubOfCurrentUser(){
|
||||
SaSession tokenSession = StpUtil.getTokenSession();
|
||||
List<Department>result=new ArrayList<>();
|
||||
result.addAll(tokenSession.get(GlobalConstant.LOGIN_USER_SUPERCOMPANY_LIST_KEY,new ArrayList()));
|
||||
result.addAll(tokenSession.get(GlobalConstant.LOGIN_USER_COMPANY_LIST_KEY,new ArrayList()));
|
||||
result.addAll(tokenSession.get(GlobalConstant.LOGIN_USER_SUBCOMPANY_LIST_KEY,new ArrayList()));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Boolean isAdmin(List<Long>roleIdList){
|
||||
return roleIdList.contains(GlobalConstant.SUPER_ADMIN_ROLE_ID);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
package com.xjrsoft.tenant.util;
|
||||
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
|
||||
/**
|
||||
* @Author: tzx
|
||||
* @Date: 2023/8/15 15:15
|
||||
*/
|
||||
public class TenantUtil {
|
||||
|
||||
private static final ThreadLocal<LinkedBlockingDeque<Boolean>> TENANT_CONTEXT_THREAD_LOCAL = new ThreadLocal() {
|
||||
@Override
|
||||
protected LinkedBlockingDeque<Boolean> initialValue() {
|
||||
return new LinkedBlockingDeque<>();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 该方法必须配合clear方法使用
|
||||
* @param isNoTenant
|
||||
*/
|
||||
public static void ignore(Boolean isNoTenant){
|
||||
TENANT_CONTEXT_THREAD_LOCAL.get().addFirst(isNoTenant);
|
||||
}
|
||||
|
||||
public static Boolean get() {
|
||||
LinkedBlockingDeque<Boolean> deque = TENANT_CONTEXT_THREAD_LOCAL.get();
|
||||
return deque.isEmpty() ? null : deque.getFirst();
|
||||
}
|
||||
|
||||
public static void clear(){
|
||||
LinkedBlockingDeque<Boolean> deque = TENANT_CONTEXT_THREAD_LOCAL.get();
|
||||
if (deque.isEmpty()) {
|
||||
TENANT_CONTEXT_THREAD_LOCAL.remove();
|
||||
} else {
|
||||
deque.pollFirst();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isNoTenant(){
|
||||
Boolean isNoTenant = get();
|
||||
if (isNoTenant == null) return false;
|
||||
|
||||
return isNoTenant;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user