更新代码
parent
847e150cbc
commit
24c219c145
|
@ -49,7 +49,7 @@ public class SecurityUtils {
|
|||
* 获取登录企业ID
|
||||
*/
|
||||
public static Long getEnterpriseId(){
|
||||
Long enterpriseId = getLoginUser().getEnterpriseId();
|
||||
Long enterpriseId = getLoginUser().getDeptId();
|
||||
Assert.notNull(enterpriseId, "该用户未绑定负责企业");
|
||||
return enterpriseId;
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ public class LoginUser implements Serializable {
|
|||
/**
|
||||
* 企业ID
|
||||
*/
|
||||
private Long enterpriseId;
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
|
|
|
@ -6,12 +6,18 @@ 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 lombok.extern.java.Log;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@FeignClient(contextId = "remoteFileService" ,
|
||||
@FeignClient(contextId = "remoteDeptService" ,
|
||||
value = ServiceNameConstants.SYSTEM_SERVICE,
|
||||
fallbackFactory = RemoteDeptFallbackFactory.class,
|
||||
path = "/dept"
|
||||
|
@ -28,9 +34,13 @@ public interface RemoteDeptService {
|
|||
|
||||
/**
|
||||
* 根据企业ID获取企业下部门
|
||||
* @param enterpriseId 企业ID
|
||||
* @param deptId 企业ID
|
||||
* @return 企业信息,内含有部门
|
||||
*/
|
||||
@GetMapping("/getSysDeptByEnterpriseId/{enterpriseId}")
|
||||
public Result<SysDept> getSysDeptByEnterpriseId(@PathVariable(value = "enterpriseId") Long enterpriseId);
|
||||
@GetMapping("/getSysDeptByDeptId/{deptId}")
|
||||
public Result<List<SysDept>> getSysDeptByDeptId(@PathVariable(value = "deptId") Long deptId);
|
||||
|
||||
|
||||
@PostMapping
|
||||
public Result add (@Validated @RequestBody SysDept dept);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ import com.couplet.common.system.remote.RemoteDeptService;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fufanrui
|
||||
* @version 1.0
|
||||
|
@ -20,24 +22,31 @@ public class RemoteDeptFallbackFactory implements FallbackFactory<RemoteDeptServ
|
|||
@Override
|
||||
public RemoteDeptService create(Throwable cause) {
|
||||
log.error("sys服务调用失败:{}", cause.getMessage());
|
||||
|
||||
return new RemoteDeptService() {
|
||||
|
||||
@Override
|
||||
public Result list(SysDept dept) {
|
||||
return Result.error("调用失败..."+cause.getMessage());
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据企业ID获取企业下部门
|
||||
*
|
||||
* @param enterpriseId 企业ID
|
||||
* @param deptId 企业ID
|
||||
*
|
||||
* @return 企业信息,内含有部门
|
||||
*/
|
||||
@Override
|
||||
public Result<SysDept> getSysDeptByEnterpriseId (Long enterpriseId) {
|
||||
return Result.error("调用失败..."+cause.getMessage());
|
||||
public Result<List<SysDept>> getSysDeptByDeptId(Long deptId) {
|
||||
return Result.error("调用失败...."+cause.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result add(SysDept dept) {
|
||||
return Result.error("调用失败...."+cause.getMessage());
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +1,50 @@
|
|||
package com.couplet.server.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.couplet.common.core.domain.Result;
|
||||
import com.couplet.common.system.domain.SysDept;
|
||||
import com.couplet.server.service.ManageServer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fufanrui
|
||||
* @version 1.0
|
||||
* @description: TODO
|
||||
* @date 2024/3/27 15:33
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/manage")
|
||||
public class ManageController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private ManageServer manageServer;
|
||||
|
||||
|
||||
/*
|
||||
* @param sysDept:
|
||||
* @return Result
|
||||
* @author 付凡芮
|
||||
* @description 登入后获取到企业下的所有部门
|
||||
* @date
|
||||
*/
|
||||
@PostMapping("manageList")
|
||||
public Result manageList(@RequestBody SysDept sysDept) {
|
||||
List<SysDept> sysDepts = manageServer.selectDeptList(sysDept);
|
||||
return Result.success(sysDepts);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @param sysDept:
|
||||
* @return Result
|
||||
* @author 付凡芮
|
||||
* @description 添加企业中的部门
|
||||
* @date
|
||||
*/
|
||||
@PostMapping("manageInsert")
|
||||
public Result manageInsert(@RequestBody SysDept sysDept) {
|
||||
|
||||
return manageServer.insertDept(sysDept);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,15 @@
|
|||
package com.couplet.server.service;
|
||||
|
||||
import com.couplet.remote.DeptServiceFegin;
|
||||
import com.couplet.common.core.domain.Result;
|
||||
import com.couplet.common.system.domain.SysDept;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ManageServer {
|
||||
|
||||
|
||||
List<SysDept> selectDeptList(SysDept sysDept);
|
||||
|
||||
Result insertDept(SysDept sysDept);
|
||||
}
|
||||
|
|
|
@ -1,32 +1,43 @@
|
|||
package com.couplet.server.service.impl;
|
||||
|
||||
import com.couplet.common.core.constant.SecurityConstants;
|
||||
import com.couplet.common.core.domain.Result;
|
||||
import com.couplet.common.core.utils.StringUtils;
|
||||
import com.couplet.common.security.utils.SecurityUtils;
|
||||
import com.couplet.common.system.domain.LoginUser;
|
||||
import com.couplet.common.system.domain.SysDept;
|
||||
import com.couplet.common.system.remote.RemoteDeptService;
|
||||
import com.couplet.common.system.remote.RemoteUserService;
|
||||
import com.couplet.server.service.ManageServer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fufanrui
|
||||
* @version 1.0
|
||||
* @description: TODO
|
||||
* @description: 管理企业业务层
|
||||
* @date 2024/3/27 15:34
|
||||
*/
|
||||
@Service
|
||||
public class ManageServiceImpl implements ManageServer {
|
||||
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();
|
||||
}
|
||||
@Autowired
|
||||
private RemoteUserService remoteUserService;
|
||||
@Override
|
||||
public List<SysDept> selectDeptList(SysDept sysDept) {
|
||||
Result<LoginUser> userInfo = remoteUserService.getUserInfo(SecurityUtils.getUsername(), SecurityConstants.FROM_SOURCE);
|
||||
LoginUser loginUser = userInfo.getData();
|
||||
Long deptId = loginUser.getDeptId();
|
||||
return remoteDeptService.getSysDeptByDeptId(deptId).getData();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Result insertDept(SysDept sysDept) {
|
||||
return remoteDeptService.add(sysDept);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,12 +110,14 @@ public class SysDeptController extends BaseController {
|
|||
|
||||
/**
|
||||
* 根据企业ID获取企业下部门
|
||||
* @param enterpriseId 企业ID
|
||||
* @param deptId 企业ID
|
||||
* @return 企业信息,内含有部门
|
||||
*/
|
||||
@GetMapping("/getSysDeptByEnterpriseId/{enterpriseId}")
|
||||
public Result<SysDept> getSysDeptByEnterpriseId(@PathVariable(value = "enterpriseId") Long enterpriseId){
|
||||
SysDept sysDept = deptService.getSysDeptByEnterpriseId(enterpriseId);
|
||||
return Result.success(sysDept);
|
||||
@GetMapping("/getSysDeptByDeptId/{deptId}")
|
||||
|
||||
public Result<List<SysDept>> getSysDeptByDeptId(@PathVariable(value = "deptId") Long deptId){
|
||||
List<SysDept> sysDept = deptService.getSysDeptByDeptId(deptId);
|
||||
Result<List<SysDept>> success = Result.success(sysDept);
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ public class SysUserController extends BaseController {
|
|||
sysUserVo.setSysUser(sysUser);
|
||||
sysUserVo.setRoles(roles);
|
||||
sysUserVo.setPermissions(permissions);
|
||||
sysUserVo.setEnterpriseId(deptId);
|
||||
sysUserVo.setDeptId(deptId);
|
||||
return Result.success(sysUserVo);
|
||||
}
|
||||
|
||||
|
|
|
@ -128,4 +128,9 @@ public interface SysDeptMapper extends BaseMapper<SysDept> {
|
|||
* @return 结果
|
||||
*/
|
||||
public int deleteDeptById (Long deptId);
|
||||
|
||||
SysDept selectDeptIdByLeader(String userName);
|
||||
|
||||
List<SysDept> getSysDeptByDeptId(Long deptId);
|
||||
|
||||
}
|
||||
|
|
|
@ -138,15 +138,15 @@ public interface SysDeptService extends IService<SysDept> {
|
|||
|
||||
/**
|
||||
* 通过负责人查询企业ID
|
||||
* @param leader 负责人
|
||||
* @param userName 负责人
|
||||
* @return 企业ID
|
||||
*/
|
||||
Long selectDeptIdByLeader (String leader);
|
||||
Long selectDeptIdByLeader (String userName);
|
||||
|
||||
/**
|
||||
* 根据企业ID获取企业下部门
|
||||
* @param enterpriseId 企业ID
|
||||
* @param deptId 企业ID
|
||||
* @return 企业信息,内含有部门
|
||||
*/
|
||||
SysDept getSysDeptByEnterpriseId (Long enterpriseId);
|
||||
List<SysDept> getSysDeptByDeptId(Long deptId);
|
||||
}
|
||||
|
|
|
@ -1,6 +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;
|
||||
|
@ -285,31 +285,33 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|||
/**
|
||||
* 通过负责人查询企业ID
|
||||
*
|
||||
* @param leader 负责人
|
||||
* @param userName 负责人
|
||||
*
|
||||
* @return 企业ID
|
||||
*/
|
||||
@Override
|
||||
public Long selectDeptIdByLeader (String leader) {
|
||||
SysDept sysDept = getOne(new LambdaQueryWrapper<>() {{
|
||||
eq(SysDept::getLeader, leader);
|
||||
}});
|
||||
public Long selectDeptIdByLeader (String userName) {
|
||||
|
||||
SysDept sysDept = deptMapper.selectDeptIdByLeader(userName);
|
||||
|
||||
return sysDept == null ? null : sysDept.getDeptId();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 根据企业ID获取企业下部门
|
||||
*
|
||||
* @param enterpriseId 企业ID
|
||||
* @param deptId 企业ID
|
||||
*
|
||||
* @return 企业信息,内含有部门
|
||||
*/
|
||||
@Override
|
||||
public SysDept getSysDeptByEnterpriseId (Long enterpriseId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysDept> getSysDeptByDeptId(Long deptId) {
|
||||
|
||||
return deptMapper.getSysDeptByDeptId(deptId);
|
||||
}
|
||||
/**
|
||||
* 递归列表
|
||||
*/
|
||||
|
|
|
@ -108,6 +108,12 @@
|
|||
<include refid="selectDeptVo"/>
|
||||
where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
|
||||
</select>
|
||||
<select id="selectDeptIdByLeader" resultType="com.couplet.common.system.domain.SysDept">
|
||||
SELECT * FROM sys_dept d LEFT JOIN sys_user u on d.dept_id = u.dept_id WHERE u.user_name = #{userName}
|
||||
</select>
|
||||
<select id="getSysDeptByDeptId" resultType="com.couplet.common.system.domain.SysDept">
|
||||
SELECT * FROM sys_dept WHERE parent_id = #{deptId}
|
||||
</select>
|
||||
|
||||
<insert id="insertDept" parameterType="com.couplet.common.system.domain.SysDept">
|
||||
insert into sys_dept(
|
||||
|
|
Loading…
Reference in New Issue