feat(文章操作基于代码仓库实现): 创建专区项目
新增接口:查询专区对应项目列表 1、部门相关Fegin操作提取成单独类 2、部门服务提供通过id列表查询部门列表接口 关联Issue:https://www.gitlink.org.cn/Gitlink/forgeplus/issues/2696
This commit is contained in:
parent
228c910a75
commit
c19edb2f77
|
|
@ -0,0 +1,41 @@
|
|||
package com.ruoyi.system.api;
|
||||
|
||||
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||
import com.ruoyi.common.core.constant.ServiceNameConstants;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.system.api.domain.SysDept;
|
||||
import com.ruoyi.system.api.factory.RemoteDeptFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 部门服务
|
||||
*
|
||||
* @author otto
|
||||
*/
|
||||
@FeignClient(contextId = "remoteDeptService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteDeptFallbackFactory.class)
|
||||
public interface RemoteDeptService {
|
||||
/**
|
||||
* 通过部门Id列表查询部门列表
|
||||
*
|
||||
* @param ids 部门Id列表
|
||||
* @param source 请求来源
|
||||
* @return 结果
|
||||
*/
|
||||
@GetMapping("/dept/listInIds/{ids}")
|
||||
public R<List<SysDept>> getDeptInDeptIds(@PathVariable("ids") List<Long> ids, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
/**
|
||||
* 通过部门Id查询部门信息
|
||||
*
|
||||
* @param deptId 部门Id
|
||||
* @return 结果
|
||||
*/
|
||||
@GetMapping("/dept/getDeptByDeptId/{deptId}")
|
||||
public R<SysDept> getDeptByDeptId(@PathVariable("deptId") Long deptId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
}
|
||||
|
|
@ -3,7 +3,6 @@ package com.ruoyi.system.api;
|
|||
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||
import com.ruoyi.common.core.constant.ServiceNameConstants;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.system.api.domain.SysDept;
|
||||
import com.ruoyi.system.api.domain.SysUser;
|
||||
import com.ruoyi.system.api.factory.RemoteUserFallbackFactory;
|
||||
import com.ruoyi.system.api.model.LoginUser;
|
||||
|
|
@ -46,14 +45,6 @@ public interface RemoteUserService
|
|||
@GetMapping("/user/getSysUserByUserId/{userId}")
|
||||
public R<SysUser> getSysUserByUserId(@PathVariable("userId") Long userId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
/**
|
||||
* 通过部门Id查询部门信息
|
||||
*
|
||||
* @param deptId 部门Id
|
||||
* @return 结果
|
||||
*/
|
||||
@GetMapping("/dept/getDeptByDeptId/{deptId}")
|
||||
public R<SysDept> getDeptByDeptId(@PathVariable("deptId") Long deptId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
/**
|
||||
* 注册用户信息
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
package com.ruoyi.system.api.factory;
|
||||
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.system.api.RemoteDeptService;
|
||||
import com.ruoyi.system.api.domain.SysDept;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 部门服务降级处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
public class RemoteDeptFallbackFactory implements FallbackFactory<RemoteDeptService> {
|
||||
private static final Logger log = LoggerFactory.getLogger(RemoteDeptFallbackFactory.class);
|
||||
|
||||
@Override
|
||||
public RemoteDeptService create(Throwable throwable) {
|
||||
log.error("部门服务调用失败:{}", throwable.getMessage());
|
||||
return new RemoteDeptService() {
|
||||
@Override
|
||||
public R<List<SysDept>> getDeptInDeptIds(List<Long> ids, String source) {
|
||||
return R.fail("获取部门列表失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<SysDept> getDeptByDeptId(Long deptId, String source) {
|
||||
return R.fail("获取部门失败:" + throwable.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,6 @@ package com.ruoyi.system.api.factory;
|
|||
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.system.api.RemoteUserService;
|
||||
import com.ruoyi.system.api.domain.SysDept;
|
||||
import com.ruoyi.system.api.domain.SysUser;
|
||||
import com.ruoyi.system.api.model.LoginUser;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -42,11 +41,6 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
|
|||
return R.fail("获取用户失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<SysDept> getDeptByDeptId(Long deptId, String source) {
|
||||
return R.fail("获取部门失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<Boolean> registerUserInfo(SysUser sysUser, String source) {
|
||||
return R.fail("注册用户失败:" + throwable.getMessage());
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
com.ruoyi.system.api.factory.RemoteUserFallbackFactory
|
||||
com.ruoyi.system.api.factory.RemoteDeptFallbackFactory
|
||||
com.ruoyi.system.api.factory.RemoteLogFallbackFactory
|
||||
com.ruoyi.system.api.factory.RemoteFileFallbackFactory
|
||||
com.ruoyi.system.api.factory.RemoteCmsFallbackFactory
|
||||
|
|
|
|||
|
|
@ -1,17 +1,23 @@
|
|||
package com.ruoyi.cms.project.controller;
|
||||
|
||||
import com.ruoyi.cms.project.domain.CmsProject;
|
||||
import com.ruoyi.cms.project.service.ICmsProjectService;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.web.controller.BaseController;
|
||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.web.page.TableDataInfo;
|
||||
import com.ruoyi.common.log.annotation.Log;
|
||||
import com.ruoyi.common.log.enums.BusinessType;
|
||||
import com.ruoyi.common.security.annotation.InnerAuth;
|
||||
import com.ruoyi.system.api.domain.SysDept;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 专区对应项目Controller
|
||||
|
|
@ -38,47 +44,17 @@ public class CmsProjectController extends BaseController {
|
|||
Boolean changeRoleResult = cmsProjectService.changeUserRole(userId, oldDeptId, newDeptId);
|
||||
return R.ok(changeRoleResult);
|
||||
}
|
||||
// /**
|
||||
// * 查询专区对应项目列表
|
||||
// */
|
||||
// @RequiresPermissions("cms:project:list")
|
||||
// @GetMapping("/list")
|
||||
// public TableDataInfo list(CmsProject cmsProject) {
|
||||
// startPage();
|
||||
// List<CmsProject> list = cmsProjectService.selectCmsProjectList(cmsProject);
|
||||
// return getDataTable(list);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 导出专区对应项目列表
|
||||
// */
|
||||
// @RequiresPermissions("cms:project:export")
|
||||
// @Log(title = "专区对应项目", businessType = BusinessType.EXPORT)
|
||||
// @PostMapping("/export")
|
||||
// public void export(HttpServletResponse response, CmsProject cmsProject) {
|
||||
// List<CmsProject> list = cmsProjectService.selectCmsProjectList(cmsProject);
|
||||
// ExcelUtil<CmsProject> util = new ExcelUtil<CmsProject>(CmsProject.class);
|
||||
// util.exportExcel(response, list, "专区对应项目数据");
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 获取专区对应项目详细信息
|
||||
// */
|
||||
// @RequiresPermissions("cms:project:query")
|
||||
// @GetMapping(value = "/{id}")
|
||||
// public AjaxResult getInfo(@PathVariable("id") Long id) {
|
||||
// return success(cmsProjectService.selectCmsProjectById(id));
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * 新增专区对应项目
|
||||
// */
|
||||
// @RequiresPermissions("cms:project:add")
|
||||
// @Log(title = "专区对应项目", businessType = BusinessType.INSERT)
|
||||
// @PostMapping
|
||||
// public AjaxResult add(@RequestBody CmsProject cmsProject) {
|
||||
// return toAjax(cmsProjectService.insertCmsProject(cmsProject));
|
||||
// }
|
||||
/**
|
||||
* 查询专区对应项目列表
|
||||
*/
|
||||
// @RequiresPermissions("cms:project:list")
|
||||
@ApiOperation("查询专区对应项目列表")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(@ApiIgnore CmsProject cmsProject) {
|
||||
List<SysDept> list = cmsProjectService.selectCmsProjectList(cmsProject);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过组织id新增专区对应项目
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.ruoyi.cms.project.service;
|
|||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.cms.project.domain.CmsProject;
|
||||
import com.ruoyi.system.api.domain.SysDept;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -26,7 +27,7 @@ public interface ICmsProjectService {
|
|||
* @param cmsProject 专区对应项目
|
||||
* @return 专区对应项目集合
|
||||
*/
|
||||
public List<CmsProject> selectCmsProjectList(CmsProject cmsProject);
|
||||
public List<SysDept> selectCmsProjectList(CmsProject cmsProject);
|
||||
|
||||
/**
|
||||
* 新增专区对应项目
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import com.ruoyi.cms.utils.httpclient.GitLinkRequestUrl;
|
|||
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||
import com.ruoyi.common.core.exception.ServiceException;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.system.api.RemoteDeptService;
|
||||
import com.ruoyi.system.api.RemoteUserService;
|
||||
import com.ruoyi.system.api.domain.SysDept;
|
||||
import com.ruoyi.system.api.domain.SysUser;
|
||||
|
|
@ -19,7 +20,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 专区对应项目Service业务层处理
|
||||
|
|
@ -34,6 +37,8 @@ public class CmsProjectServiceImpl implements ICmsProjectService {
|
|||
@Autowired
|
||||
private RemoteUserService remoteUserService;
|
||||
@Autowired
|
||||
private RemoteDeptService remoteDeptService;
|
||||
@Autowired
|
||||
private ISysUserService sysUserService;
|
||||
@Autowired
|
||||
private GitLinkRequestHelper gitLinkRequestHelper;
|
||||
|
|
@ -61,8 +66,15 @@ public class CmsProjectServiceImpl implements ICmsProjectService {
|
|||
* @return 专区对应项目
|
||||
*/
|
||||
@Override
|
||||
public List<CmsProject> selectCmsProjectList(CmsProject cmsProject) {
|
||||
return cmsProjectMapper.selectCmsProjectList(cmsProject);
|
||||
public List<SysDept> selectCmsProjectList(CmsProject cmsProject) {
|
||||
List<SysDept> deptList = new ArrayList<>();
|
||||
List<CmsProject> cmsProjectList = cmsProjectMapper.selectCmsProjectList(cmsProject);
|
||||
if (cmsProject == null) {
|
||||
return deptList;
|
||||
}
|
||||
List<Long> deptIdList = cmsProjectList.stream().map(x -> x.getDepId()).collect(Collectors.toList());
|
||||
deptList = FeginUtils.getReturnData(remoteDeptService.getDeptInDeptIds(deptIdList, SecurityConstants.INNER));
|
||||
return deptList;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -135,7 +147,7 @@ public class CmsProjectServiceImpl implements ICmsProjectService {
|
|||
throw new ServiceException("该组织已创建项目(组织id[" + deptId + "])");
|
||||
}
|
||||
//通过Fegin获取部门信息
|
||||
SysDept sysDept = FeginUtils.getReturnData(remoteUserService.getDeptByDeptId(deptId, SecurityConstants.INNER));
|
||||
SysDept sysDept = FeginUtils.getReturnData(remoteDeptService.getDeptByDeptId(deptId, SecurityConstants.INNER));
|
||||
if (sysDept == null) {
|
||||
throw new ServiceException("该组织不存在(组织id[" + deptId + "])");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,13 +47,25 @@ public class SysDeptController extends BaseController
|
|||
*/
|
||||
@RequiresPermissions("system:dept:list")
|
||||
@GetMapping("/list/exclude/{deptId}")
|
||||
public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId)
|
||||
{
|
||||
public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId) {
|
||||
List<SysDept> depts = deptService.selectDeptList(new SysDept());
|
||||
depts.removeIf(d -> d.getDeptId().intValue() == deptId || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + ""));
|
||||
return success(depts);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过部门Id列表查询部门列表
|
||||
*/
|
||||
@InnerAuth
|
||||
@GetMapping("/listInIds/{ids}")
|
||||
public R<List<SysDept>> getDeptInDeptIds(@PathVariable("ids") List<Long> ids) {
|
||||
List<SysDept> sysDeptList = deptService.selectDeptListInIds(ids);
|
||||
if (StringUtils.isNull(sysDeptList)) {
|
||||
return R.fail("部门不存在(部门id列表[" + ids + "])");
|
||||
}
|
||||
return R.ok(sysDeptList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据部门编号获取详细信息
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package com.ruoyi.system.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.ruoyi.system.api.domain.SysDept;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 部门管理 数据层
|
||||
|
|
@ -110,9 +111,17 @@ public interface SysDeptMapper
|
|||
|
||||
/**
|
||||
* 删除部门管理信息
|
||||
*
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDeptById(Long deptId);
|
||||
|
||||
/**
|
||||
* 通过部门Id列表查询部门列表
|
||||
*
|
||||
* @param ids 部门Id列表
|
||||
* @return
|
||||
*/
|
||||
List<SysDept> selectDeptListInIds(@Param("ids") List<Long> ids);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
package com.ruoyi.system.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.system.api.domain.SysDept;
|
||||
import com.ruoyi.system.domain.vo.TreeSelect;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 部门管理 服务层
|
||||
*
|
||||
|
|
@ -116,9 +117,17 @@ public interface ISysDeptService
|
|||
|
||||
/**
|
||||
* 删除部门管理信息
|
||||
*
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDeptById(Long deptId);
|
||||
|
||||
/**
|
||||
* 通过部门Id列表查询部门列表
|
||||
*
|
||||
* @param ids 部门Id列表
|
||||
* @return
|
||||
*/
|
||||
List<SysDept> selectDeptListInIds(List<Long> ids);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,5 @@
|
|||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.common.core.constant.UserConstants;
|
||||
import com.ruoyi.common.core.exception.ServiceException;
|
||||
import com.ruoyi.common.core.text.Convert;
|
||||
|
|
@ -20,6 +14,13 @@ import com.ruoyi.system.domain.vo.TreeSelect;
|
|||
import com.ruoyi.system.mapper.SysDeptMapper;
|
||||
import com.ruoyi.system.mapper.SysRoleMapper;
|
||||
import com.ruoyi.system.service.ISysDeptService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 部门管理 服务实现
|
||||
|
|
@ -283,21 +284,25 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|||
|
||||
/**
|
||||
* 删除部门管理信息
|
||||
*
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteDeptById(Long deptId)
|
||||
{
|
||||
public int deleteDeptById(Long deptId) {
|
||||
return deptMapper.deleteDeptById(deptId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysDept> selectDeptListInIds(List<Long> ids) {
|
||||
List<SysDept> deptList = deptMapper.selectDeptListInIds(ids);
|
||||
return deptList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归列表
|
||||
*/
|
||||
private void recursionFn(List<SysDept> list, SysDept t)
|
||||
{
|
||||
private void recursionFn(List<SysDept> list, SysDept t) {
|
||||
// 得到子节点列表
|
||||
List<SysDept> childList = getChildList(list, t);
|
||||
t.setChildren(childList);
|
||||
|
|
|
|||
|
|
@ -75,25 +75,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<select id="selectChildrenDeptById" parameterType="Long" resultMap="SysDeptResult">
|
||||
select * from sys_dept where find_in_set(#{deptId}, ancestors)
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int">
|
||||
select count(*) from sys_dept where status = 0 and del_flag = '0' and find_in_set(#{deptId}, ancestors)
|
||||
select count(*)
|
||||
from sys_dept
|
||||
where status = 0
|
||||
and del_flag = '0'
|
||||
and find_in_set(#{deptId}, ancestors)
|
||||
</select>
|
||||
|
||||
|
||||
<select id="checkDeptNameUnique" resultMap="SysDeptResult">
|
||||
<include refid="selectDeptVo"/>
|
||||
<include refid="selectDeptVo"/>
|
||||
where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
|
||||
</select>
|
||||
|
||||
<insert id="insertDept" parameterType="SysDept">
|
||||
insert into sys_dept(
|
||||
<if test="deptId != null and deptId != 0">dept_id,</if>
|
||||
<if test="parentId != null and parentId != 0">parent_id,</if>
|
||||
<if test="deptName != null and deptName != ''">dept_name,</if>
|
||||
<if test="ancestors != null and ancestors != ''">ancestors,</if>
|
||||
<if test="orderNum != null">order_num,</if>
|
||||
<if test="leader != null and leader != ''">leader,</if>
|
||||
<if test="phone != null and phone != ''">phone,</if>
|
||||
<select id="selectDeptListInIds" resultMap="SysDeptResult">
|
||||
<include refid="selectDeptVo"/>
|
||||
where d.del_flag = '0'
|
||||
and d.dept_id in
|
||||
<foreach collection="ids" item="deptId" open="(" separator="," close=")">
|
||||
#{deptId}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<insert id="insertDept" parameterType="SysDept">
|
||||
insert into sys_dept(
|
||||
<if test="deptId != null and deptId != 0">dept_id,</if>
|
||||
<if test="parentId != null and parentId != 0">parent_id,</if>
|
||||
<if test="deptName != null and deptName != ''">dept_name,</if>
|
||||
<if test="ancestors != null and ancestors != ''">ancestors,</if>
|
||||
<if test="orderNum != null">order_num,</if>
|
||||
<if test="leader != null and leader != ''">leader,</if>
|
||||
<if test="phone != null and phone != ''">phone,</if>
|
||||
<if test="email != null and email != ''">email,</if>
|
||||
<if test="status != null">status,</if>
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
|
|
|
|||
Loading…
Reference in New Issue