Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yudao-cloud
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
hblj
yudao-cloud
Commits
07d1e317
提交
07d1e317
authored
6月 26, 2019
作者:
zhenxianyimeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
部门管理更细和删除接口
上级
b9047e49
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
133 行增加
和
4 行删除
+133
-4
DeptmentController.java
...min/application/controller/admins/DeptmentController.java
+20
-2
DeptmentService.java
.../main/java/cn/iocoder/mall/admin/api/DeptmentService.java
+5
-0
AdminErrorCodeEnum.java
...n/iocoder/mall/admin/api/constant/AdminErrorCodeEnum.java
+4
-2
DeptmentUpdateDTO.java
...coder/mall/admin/api/dto/depetment/DeptmentUpdateDTO.java
+39
-0
DeptmentConvert.java
...n/java/cn/iocoder/mall/admin/convert/DeptmentConvert.java
+4
-0
DeptmentRoleMapper.java
...in/java/cn/iocoder/mall/admin/dao/DeptmentRoleMapper.java
+9
-0
DeptmentServiceImpl.java
...va/cn/iocoder/mall/admin/service/DeptmentServiceImpl.java
+52
-0
没有找到文件。
system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DeptmentController.java
浏览文件 @
07d1e317
...
...
@@ -7,17 +7,18 @@ import cn.iocoder.mall.admin.api.bo.deptment.DeptmentBO;
import
cn.iocoder.mall.admin.api.constant.ResourceConstants
;
import
cn.iocoder.mall.admin.api.dto.depetment.DeptmentAddDTO
;
import
cn.iocoder.mall.admin.api.dto.depetment.DeptmentPageDTO
;
import
cn.iocoder.mall.admin.api.dto.depetment.DeptmentUpdateDTO
;
import
cn.iocoder.mall.admin.application.convert.DeptmentConvert
;
import
cn.iocoder.mall.admin.application.vo.deptment.DeptmentVO
;
import
cn.iocoder.mall.admin.
application.vo.resource.ResourceTreeNodeVO
;
import
cn.iocoder.mall.admin.
sdk.context.AdminSecurityContext
;
import
cn.iocoder.mall.admin.sdk.context.AdminSecurityContextHolder
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
...
...
@@ -74,6 +75,23 @@ public class DeptmentController {
}
@PostMapping
(
"delete"
)
@ApiOperation
(
value
=
"删除部门"
)
@ApiImplicitParam
(
name
=
"id"
,
value
=
"部门id"
,
required
=
true
,
example
=
"1"
)
public
CommonResult
<
Boolean
>
delete
(
@RequestParam
(
"id"
)
Integer
id
){
return
success
(
deptmentService
.
deleteDeptment
(
AdminSecurityContextHolder
.
getContext
().
getAdminId
(),
id
));
}
@PostMapping
(
"update"
)
@ApiOperation
(
value
=
"更新部门"
)
public
CommonResult
<
Boolean
>
update
(
@RequestBody
DeptmentUpdateDTO
deptmentUpdateDTO
){
return
success
(
deptmentService
.
updateDeptment
(
AdminSecurityContextHolder
.
getContext
().
getAdminId
(),
deptmentUpdateDTO
));
}
}
system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/DeptmentService.java
浏览文件 @
07d1e317
...
...
@@ -4,6 +4,7 @@ import cn.iocoder.common.framework.vo.PageResult;
import
cn.iocoder.mall.admin.api.bo.deptment.DeptmentBO
;
import
cn.iocoder.mall.admin.api.dto.depetment.DeptmentAddDTO
;
import
cn.iocoder.mall.admin.api.dto.depetment.DeptmentPageDTO
;
import
cn.iocoder.mall.admin.api.dto.depetment.DeptmentUpdateDTO
;
import
java.util.List
;
...
...
@@ -18,6 +19,10 @@ public interface DeptmentService {
DeptmentBO
addDeptment
(
Integer
adminId
,
DeptmentAddDTO
deptmentAddDTO
);
Boolean
deleteDeptment
(
Integer
adminId
,
Integer
deptmentId
);
Boolean
updateDeptment
(
Integer
adminId
,
DeptmentUpdateDTO
deptmentUpdateDTO
);
PageResult
<
DeptmentBO
>
getPageRootDeptment
(
DeptmentPageDTO
deptmentPageDTO
);
List
<
DeptmentBO
>
getAllDeptments
();
...
...
system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/AdminErrorCodeEnum.java
浏览文件 @
07d1e317
...
...
@@ -60,8 +60,10 @@ public enum AdminErrorCodeEnum {
// ========== 部门模块 1002007000 ==========
DEPT_SAME_LEVEL_NAME_EXITS
(
1002007001
,
"当前级别部门名字已存在"
),
DEPT_PARENT_NOT_EXITS
(
1002007002
,
"父级部门不存在"
)
DEPT_PARENT_NOT_EXITS
(
1002007002
,
"父级部门不存在"
),
DEPT_NOT_EXITS
(
1002007003
,
"当前部门不存在"
),
DEPT_EXITS_CHILDREN
(
1002007004
,
"当前部门存在子部门"
),
DEPT_PARENT_NOT_LEGAL
(
1002007005
,
"父级部门不合法"
),
;
private
final
int
code
;
...
...
system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/depetment/DeptmentUpdateDTO.java
0 → 100644
浏览文件 @
07d1e317
package
cn
.
iocoder
.
mall
.
admin
.
api
.
dto
.
depetment
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
javax.validation.constraints.NotEmpty
;
import
javax.validation.constraints.NotNull
;
import
java.io.Serializable
;
/**
* Description:
*
* @author: zhenxianyimeng
* @date: 2019-06-26
* @time: 22:37
*/
@ApiModel
(
"部门更新DTO"
)
@Data
public
class
DeptmentUpdateDTO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
8905970407110374395L
;
@ApiModelProperty
(
value
=
"部门id"
,
required
=
true
,
example
=
"1"
)
@NotNull
(
message
=
"部门id不能为空"
)
private
Integer
id
;
@ApiModelProperty
(
value
=
"部门名字"
,
required
=
true
,
example
=
"销售部"
)
@NotEmpty
(
message
=
"部门名字不为空"
)
private
String
name
;
@ApiModelProperty
(
value
=
"部门排序"
,
required
=
true
,
example
=
"1"
)
@NotNull
(
message
=
"部门排序不为空"
)
private
Integer
sort
;
@ApiModelProperty
(
value
=
"父级部门id"
,
required
=
true
,
example
=
"1"
)
private
Integer
pid
;
}
system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/DeptmentConvert.java
浏览文件 @
07d1e317
...
...
@@ -3,6 +3,7 @@ package cn.iocoder.mall.admin.convert;
import
cn.iocoder.common.framework.vo.PageResult
;
import
cn.iocoder.mall.admin.api.bo.deptment.DeptmentBO
;
import
cn.iocoder.mall.admin.api.dto.depetment.DeptmentAddDTO
;
import
cn.iocoder.mall.admin.api.dto.depetment.DeptmentUpdateDTO
;
import
cn.iocoder.mall.admin.dataobject.DeptmentDO
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
org.mapstruct.Mapper
;
...
...
@@ -35,4 +36,7 @@ public interface DeptmentConvert {
@Mappings
({})
List
<
DeptmentBO
>
convert
(
List
<
DeptmentDO
>
list
);
@Mappings
({})
DeptmentDO
convert
(
DeptmentUpdateDTO
deptmentUpdateDTO
);
}
system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DeptmentRoleMapper.java
浏览文件 @
07d1e317
package
cn
.
iocoder
.
mall
.
admin
.
dao
;
import
cn.iocoder.mall.admin.dataobject.DeptmentRoleDO
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
/**
...
...
@@ -12,4 +13,12 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
*/
public
interface
DeptmentRoleMapper
extends
BaseMapper
<
DeptmentRoleDO
>
{
default
int
deleteByDeptmentId
(
Integer
deptmentId
){
return
delete
(
new
QueryWrapper
<
DeptmentRoleDO
>().
eq
(
"deptment_id"
,
deptmentId
));
}
default
int
deleteByRoleId
(
Integer
roleId
){
return
delete
(
new
QueryWrapper
<
DeptmentRoleDO
>().
eq
(
"role_id"
,
roleId
));
}
}
system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/DeptmentServiceImpl.java
浏览文件 @
07d1e317
package
cn
.
iocoder
.
mall
.
admin
.
service
;
import
cn.iocoder.common.framework.util.ExceptionUtil
;
import
cn.iocoder.common.framework.util.ServiceExceptionUtil
;
import
cn.iocoder.common.framework.vo.PageResult
;
import
cn.iocoder.mall.admin.api.DeptmentService
;
...
...
@@ -8,12 +9,17 @@ import cn.iocoder.mall.admin.api.constant.AdminErrorCodeEnum;
import
cn.iocoder.mall.admin.api.constant.DeptmentConstants
;
import
cn.iocoder.mall.admin.api.dto.depetment.DeptmentAddDTO
;
import
cn.iocoder.mall.admin.api.dto.depetment.DeptmentPageDTO
;
import
cn.iocoder.mall.admin.api.dto.depetment.DeptmentUpdateDTO
;
import
cn.iocoder.mall.admin.convert.DeptmentConvert
;
import
cn.iocoder.mall.admin.dao.DeptmentMapper
;
import
cn.iocoder.mall.admin.dao.DeptmentRoleMapper
;
import
cn.iocoder.mall.admin.dataobject.DeptmentDO
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.kafka.KafkaProperties
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.CollectionUtils
;
import
java.util.List
;
...
...
@@ -30,6 +36,9 @@ public class DeptmentServiceImpl implements DeptmentService {
@Autowired
private
DeptmentMapper
deptmentMapper
;
@Autowired
private
DeptmentRoleMapper
deptmentRoleMapper
;
@Override
public
DeptmentBO
addDeptment
(
Integer
adminId
,
DeptmentAddDTO
deptmentAddDTO
)
{
if
(
deptmentAddDTO
.
getPid
()
!=
0
&&
...
...
@@ -45,6 +54,49 @@ public class DeptmentServiceImpl implements DeptmentService {
return
DeptmentConvert
.
INSTANCE
.
convert
(
deptmentDO
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
Boolean
deleteDeptment
(
Integer
adminId
,
Integer
deptmentId
)
{
if
(
deptmentMapper
.
selectById
(
deptmentId
)
==
null
){
throw
ServiceExceptionUtil
.
exception
(
AdminErrorCodeEnum
.
DEPT_NOT_EXITS
.
getCode
());
}
if
(!
CollectionUtils
.
isEmpty
(
deptmentMapper
.
getDeptByPid
(
deptmentId
))){
throw
ServiceExceptionUtil
.
exception
(
AdminErrorCodeEnum
.
DEPT_EXITS_CHILDREN
.
getCode
());
}
deptmentMapper
.
deleteById
(
deptmentId
);
deptmentRoleMapper
.
deleteByDeptmentId
(
deptmentId
);
return
true
;
}
@Override
@Transactional
public
Boolean
updateDeptment
(
Integer
adminId
,
DeptmentUpdateDTO
deptmentUpdateDTO
)
{
//判断需要更新的部门是否存在
if
(
deptmentMapper
.
selectById
(
deptmentUpdateDTO
.
getId
())
==
null
){
throw
ServiceExceptionUtil
.
exception
(
AdminErrorCodeEnum
.
DEPT_NOT_EXITS
.
getCode
());
}
//不能选择当前部门作为自己的父级部门
if
(
deptmentUpdateDTO
.
getId
().
equals
(
deptmentUpdateDTO
.
getPid
())){
throw
ServiceExceptionUtil
.
exception
(
AdminErrorCodeEnum
.
DEPT_PARENT_NOT_LEGAL
.
getCode
());
}
if
(
deptmentUpdateDTO
.
getPid
()!=
null
&&
!
DeptmentConstants
.
PID_ROOT
.
equals
(
deptmentUpdateDTO
.
getPid
())
&&
deptmentMapper
.
selectById
(
deptmentUpdateDTO
.
getPid
())==
null
){
throw
ServiceExceptionUtil
.
exception
(
AdminErrorCodeEnum
.
DEPT_PARENT_NOT_EXITS
.
getCode
());
}
DeptmentDO
deptmentDO
=
DeptmentConvert
.
INSTANCE
.
convert
(
deptmentUpdateDTO
);
deptmentMapper
.
updateById
(
deptmentDO
);
return
true
;
}
@Override
public
PageResult
<
DeptmentBO
>
getPageRootDeptment
(
DeptmentPageDTO
deptmentPageDTO
)
{
IPage
<
DeptmentDO
>
page
=
deptmentMapper
.
selectDeptPage
(
deptmentPageDTO
,
DeptmentConstants
.
PID_ROOT
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论