企业管理,伪代码
parent
8f9cf1a6c6
commit
847e150cbc
|
@ -7,6 +7,7 @@ import com.couplet.common.core.utils.ServletUtils;
|
|||
import com.couplet.common.core.utils.StringUtils;
|
||||
import com.couplet.common.system.domain.LoginUser;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
|
@ -44,6 +45,15 @@ public class SecurityUtils {
|
|||
return SecurityContextHolder.get(SecurityConstants.LOGIN_USER, LoginUser.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录企业ID
|
||||
*/
|
||||
public static Long getEnterpriseId(){
|
||||
Long enterpriseId = getLoginUser().getEnterpriseId();
|
||||
Assert.notNull(enterpriseId, "该用户未绑定负责企业");
|
||||
return enterpriseId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求token
|
||||
*/
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.couplet.common.system.domain;
|
||||
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -9,6 +11,10 @@ import java.util.Set;
|
|||
*
|
||||
* @author couplet
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class LoginUser implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
@ -52,80 +58,14 @@ public class LoginUser implements Serializable {
|
|||
*/
|
||||
private Set<String> roles;
|
||||
|
||||
/**
|
||||
* 企业ID
|
||||
*/
|
||||
private Long enterpriseId;
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*/
|
||||
private SysUser sysUser;
|
||||
|
||||
public String getToken () {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken (String token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public Long getUserid () {
|
||||
return userid;
|
||||
}
|
||||
|
||||
public void setUserid (Long userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public String getUsername () {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername (String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public Long getLoginTime () {
|
||||
return loginTime;
|
||||
}
|
||||
|
||||
public void setLoginTime (Long loginTime) {
|
||||
this.loginTime = loginTime;
|
||||
}
|
||||
|
||||
public Long getExpireTime () {
|
||||
return expireTime;
|
||||
}
|
||||
|
||||
public void setExpireTime (Long expireTime) {
|
||||
this.expireTime = expireTime;
|
||||
}
|
||||
|
||||
public String getIpaddr () {
|
||||
return ipaddr;
|
||||
}
|
||||
|
||||
public void setIpaddr (String ipaddr) {
|
||||
this.ipaddr = ipaddr;
|
||||
}
|
||||
|
||||
public Set<String> getPermissions () {
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public void setPermissions (Set<String> permissions) {
|
||||
this.permissions = permissions;
|
||||
}
|
||||
|
||||
public Set<String> getRoles () {
|
||||
return roles;
|
||||
}
|
||||
|
||||
public void setRoles (Set<String> roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
public SysUser getSysUser () {
|
||||
return sysUser;
|
||||
}
|
||||
|
||||
public void setSysUser (SysUser sysUser) {
|
||||
this.sysUser = sysUser;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package com.couplet.common.system.remote;
|
||||
|
||||
import com.couplet.common.core.constant.ServiceNameConstants;
|
||||
import com.couplet.common.core.domain.Result;
|
||||
import com.couplet.common.core.web.page.TableDataInfo;
|
||||
import com.couplet.common.system.domain.SysDept;
|
||||
import com.couplet.common.system.domain.SysUser;
|
||||
import com.couplet.common.system.remote.factory.RemoteDeptFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
|
||||
@FeignClient(contextId = "remoteFileService" ,
|
||||
value = ServiceNameConstants.SYSTEM_SERVICE,
|
||||
fallbackFactory = RemoteDeptFallbackFactory.class,
|
||||
path = "/dept"
|
||||
)
|
||||
public interface RemoteDeptService {
|
||||
/**
|
||||
* 查询部门管理数据
|
||||
*
|
||||
* @param dept 部门信息
|
||||
* @return 部门信息集合
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public Result list (SysDept dept);
|
||||
|
||||
/**
|
||||
* 根据企业ID获取企业下部门
|
||||
* @param enterpriseId 企业ID
|
||||
* @return 企业信息,内含有部门
|
||||
*/
|
||||
@GetMapping("/getSysDeptByEnterpriseId/{enterpriseId}")
|
||||
public Result<SysDept> getSysDeptByEnterpriseId(@PathVariable(value = "enterpriseId") Long enterpriseId);
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
package com.couplet.remote.factory;
|
||||
package com.couplet.common.system.remote.factory;
|
||||
|
||||
import com.couplet.common.core.domain.Result;
|
||||
import com.couplet.common.core.web.page.TableDataInfo;
|
||||
import com.couplet.common.system.domain.SysDept;
|
||||
import com.couplet.common.system.domain.SysUser;
|
||||
import com.couplet.remote.DeptServiceFegin;
|
||||
import com.couplet.common.system.remote.RemoteDeptService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
|
||||
|
@ -16,20 +16,28 @@ import org.springframework.cloud.openfeign.FallbackFactory;
|
|||
*/
|
||||
@Slf4j
|
||||
|
||||
public class RemoteDeptFallbackFactory implements FallbackFactory<DeptServiceFegin> {
|
||||
public class RemoteDeptFallbackFactory implements FallbackFactory<RemoteDeptService> {
|
||||
@Override
|
||||
public DeptServiceFegin create(Throwable cause) {
|
||||
public RemoteDeptService create(Throwable cause) {
|
||||
log.error("sys服务调用失败:{}", cause.getMessage());
|
||||
return new DeptServiceFegin() {
|
||||
return new RemoteDeptService() {
|
||||
@Override
|
||||
public Result list(SysDept dept) {
|
||||
return Result.error("调用失败..."+cause.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据企业ID获取企业下部门
|
||||
*
|
||||
* @param enterpriseId 企业ID
|
||||
*
|
||||
* @return 企业信息,内含有部门
|
||||
*/
|
||||
@Override
|
||||
public Result<TableDataInfo<SysUser>> list(SysUser user) {
|
||||
public Result<SysDept> getSysDeptByEnterpriseId (Long enterpriseId) {
|
||||
return Result.error("调用失败..."+cause.getMessage());
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
com.couplet.common.system.remote.factory.RemoteUserFallbackFactory
|
||||
com.couplet.common.system.remote.factory.RemoteLogFallbackFactory
|
||||
com.couplet.common.system.remote.factory.RemoteFileFallbackFactory
|
||||
com.couplet.common.system.remote.factory.RemoteDeptFallbackFactory
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
package com.couplet.remote;
|
||||
|
||||
import com.couplet.common.core.constant.ServiceNameConstants;
|
||||
import com.couplet.common.core.domain.Result;
|
||||
import com.couplet.common.core.web.page.TableDataInfo;
|
||||
import com.couplet.common.security.annotation.RequiresPermissions;
|
||||
import com.couplet.common.system.domain.SysDept;
|
||||
import com.couplet.common.system.domain.SysUser;
|
||||
import com.couplet.remote.factory.RemoteDeptFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
|
||||
@FeignClient(contextId = "remoteFileService" , value = ServiceNameConstants.SYSTEM_SERVICE,fallbackFactory = RemoteDeptFallbackFactory.class)
|
||||
public interface DeptServiceFegin {
|
||||
/**
|
||||
* 查询部门管理数据
|
||||
*
|
||||
* @param dept 部门信息
|
||||
* @return 部门信息集合
|
||||
*/
|
||||
@RequiresPermissions("system:dept:list")
|
||||
@GetMapping("/list")
|
||||
public Result list (SysDept dept);
|
||||
/*
|
||||
* @param user:
|
||||
* @return Result<TableDataInfo<SysUser>>
|
||||
* @author 付凡芮
|
||||
* @description TODO
|
||||
* @date
|
||||
* 用户信息集合
|
||||
*/
|
||||
@RequiresPermissions("system:user:list")
|
||||
@GetMapping("/list")
|
||||
public Result<TableDataInfo<SysUser>> list (SysUser user);
|
||||
}
|
|
@ -82,11 +82,6 @@
|
|||
<artifactId>couplet-common-swagger</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.couplet</groupId>
|
||||
<artifactId>couplet-enterprisemanagement-remote</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -8,9 +8,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
|
||||
/**
|
||||
* @author fufanrui
|
||||
* 启动类
|
||||
* @version 1.0
|
||||
* @description: TODO
|
||||
* @description: 启动类
|
||||
* @date 2024/3/27 14:04
|
||||
*/
|
||||
@EnableCustomConfig
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package com.couplet.server.service.impl;
|
||||
|
||||
import com.couplet.remote.DeptServiceFegin;
|
||||
import com.couplet.common.core.domain.Result;
|
||||
import com.couplet.common.security.utils.SecurityUtils;
|
||||
import com.couplet.common.system.domain.SysDept;
|
||||
import com.couplet.common.system.remote.RemoteDeptService;
|
||||
import com.couplet.server.service.ManageServer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
/**
|
||||
* @author fufanrui
|
||||
|
@ -15,8 +17,15 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|||
@Service
|
||||
public class ManageServiceImpl implements ManageServer {
|
||||
|
||||
|
||||
|
||||
@Autowired
|
||||
private RemoteDeptService remoteDeptService;
|
||||
{
|
||||
Long enterpriseId = SecurityUtils.getEnterpriseId();
|
||||
Result<SysDept> sysDeptByEnterpriseId = remoteDeptService.getSysDeptByEnterpriseId(enterpriseId);
|
||||
if (sysDeptByEnterpriseId.getCode() == 200){
|
||||
SysDept sysDept = sysDeptByEnterpriseId.getData();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -107,4 +107,15 @@ public class SysDeptController extends BaseController {
|
|||
deptService.checkDeptDataScope(deptId);
|
||||
return toAjax(deptService.deleteDeptById(deptId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据企业ID获取企业下部门
|
||||
* @param enterpriseId 企业ID
|
||||
* @return 企业信息,内含有部门
|
||||
*/
|
||||
@GetMapping("/getSysDeptByEnterpriseId/{enterpriseId}")
|
||||
public Result<SysDept> getSysDeptByEnterpriseId(@PathVariable(value = "enterpriseId") Long enterpriseId){
|
||||
SysDept sysDept = deptService.getSysDeptByEnterpriseId(enterpriseId);
|
||||
return Result.success(sysDept);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,10 +107,13 @@ public class SysUserController extends BaseController {
|
|||
Set<String> roles = permissionService.getRolePermission(sysUser);
|
||||
// 权限集合
|
||||
Set<String> permissions = permissionService.getMenuPermission(sysUser);
|
||||
// 查询企业信息
|
||||
Long deptId = deptService.selectDeptIdByLeader(sysUser.getUserName());
|
||||
LoginUser sysUserVo = new LoginUser();
|
||||
sysUserVo.setSysUser(sysUser);
|
||||
sysUserVo.setRoles(roles);
|
||||
sysUserVo.setPermissions(permissions);
|
||||
sysUserVo.setEnterpriseId(deptId);
|
||||
return Result.success(sysUserVo);
|
||||
}
|
||||
|
||||
|
|
|
@ -135,4 +135,18 @@ public interface SysDeptService extends IService<SysDept> {
|
|||
* @return 结果
|
||||
*/
|
||||
public int deleteDeptById (Long deptId);
|
||||
|
||||
/**
|
||||
* 通过负责人查询企业ID
|
||||
* @param leader 负责人
|
||||
* @return 企业ID
|
||||
*/
|
||||
Long selectDeptIdByLeader (String leader);
|
||||
|
||||
/**
|
||||
* 根据企业ID获取企业下部门
|
||||
* @param enterpriseId 企业ID
|
||||
* @return 企业信息,内含有部门
|
||||
*/
|
||||
SysDept getSysDeptByEnterpriseId (Long enterpriseId);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.couplet.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.couplet.common.core.constant.UserConstants;
|
||||
import com.couplet.common.core.exception.ServiceException;
|
||||
|
@ -17,6 +18,7 @@ import com.couplet.system.mapper.SysRoleMapper;
|
|||
import com.couplet.system.service.SysDeptService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
@ -280,6 +282,34 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|||
return deptMapper.deleteDeptById(deptId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过负责人查询企业ID
|
||||
*
|
||||
* @param leader 负责人
|
||||
*
|
||||
* @return 企业ID
|
||||
*/
|
||||
@Override
|
||||
public Long selectDeptIdByLeader (String leader) {
|
||||
SysDept sysDept = getOne(new LambdaQueryWrapper<>() {{
|
||||
eq(SysDept::getLeader, leader);
|
||||
}});
|
||||
|
||||
return sysDept == null ? null : sysDept.getDeptId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据企业ID获取企业下部门
|
||||
*
|
||||
* @param enterpriseId 企业ID
|
||||
*
|
||||
* @return 企业信息,内含有部门
|
||||
*/
|
||||
@Override
|
||||
public SysDept getSysDeptByEnterpriseId (Long enterpriseId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归列表
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue