forked from YunaiV/yudao-cloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
chixiao
committed
Jun 15, 2019
1 parent
e7c9464
commit 8f4433b
Showing
13 changed files
with
329 additions
and
1 deletion.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...src/main/java/cn/iocoder/mall/admin/application/controller/admins/DeptmentController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package cn.iocoder.mall.admin.application.controller.admins; | ||
|
||
import cn.iocoder.common.framework.vo.CommonResult; | ||
import cn.iocoder.mall.admin.api.DeptmentService; | ||
import cn.iocoder.mall.admin.api.bo.deptment.DeptmentBO; | ||
import cn.iocoder.mall.admin.api.dto.depetment.DeptmentAddDTO; | ||
import cn.iocoder.mall.admin.sdk.context.AdminSecurityContextHolder; | ||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import static cn.iocoder.common.framework.vo.CommonResult.success; | ||
|
||
/** | ||
* Description: | ||
* | ||
* @author: zhenxianyimeng | ||
* @date: 2019-06-14 | ||
* @time: 19:07 | ||
*/ | ||
@RestController | ||
@RequestMapping("admins/dept") | ||
@Api("部门模块") | ||
public class DeptmentController { | ||
|
||
@Autowired | ||
private DeptmentService deptmentService; | ||
|
||
@PostMapping("add") | ||
@ApiOperation(value = "新增部门", notes = "选择部门名称,父级部门") | ||
public CommonResult<DeptmentBO> add(@RequestBody DeptmentAddDTO deptmentAddDTO){ | ||
return success(deptmentService.addDeptment( | ||
AdminSecurityContextHolder.getContext().getAdminId(), deptmentAddDTO)); | ||
|
||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...m-application/src/main/java/cn/iocoder/mall/admin/application/vo/deptment/DeptmentVO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package cn.iocoder.mall.admin.application.vo.deptment; | ||
|
||
import cn.iocoder.mall.admin.api.bo.deptment.DeptmentBO; | ||
|
||
/** | ||
* Description: | ||
* | ||
* @author: zhenxianyimeng | ||
* @date: 2019-06-15 | ||
* @time: 16:57 | ||
*/ | ||
public class DeptmentVO extends DeptmentBO { | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/DeptmentService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package cn.iocoder.mall.admin.api; | ||
|
||
import cn.iocoder.mall.admin.api.bo.deptment.DeptmentBO; | ||
import cn.iocoder.mall.admin.api.dto.depetment.DeptmentAddDTO; | ||
|
||
/** | ||
* Description: | ||
* | ||
* @author: zhenxianyimeng | ||
* @date: 2019-06-14 | ||
* @time: 19:35 | ||
*/ | ||
public interface DeptmentService { | ||
|
||
DeptmentBO addDeptment(Integer adminId, DeptmentAddDTO deptmentAddDTO); | ||
} |
44 changes: 44 additions & 0 deletions
44
...em/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/deptment/DeptmentBO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package cn.iocoder.mall.admin.api.bo.deptment; | ||
|
||
import io.swagger.annotations.ApiModel; | ||
import lombok.Data; | ||
|
||
import java.io.Serializable; | ||
import java.util.Date; | ||
|
||
/** | ||
* Description: | ||
* | ||
* @author: zhenxianyimeng | ||
* @date: 2019-06-14 | ||
* @time: 19:49 | ||
*/ | ||
@ApiModel("部门 BO") | ||
@Data | ||
public class DeptmentBO implements Serializable { | ||
|
||
private static final long serialVersionUID = 7656901281539594453L; | ||
|
||
/** | ||
* 部门编号 | ||
*/ | ||
private Integer id; | ||
/** | ||
* 部门名称 | ||
*/ | ||
private String name; | ||
/** | ||
* 部门排序字段 | ||
*/ | ||
private Integer sort; | ||
/** | ||
* 父级部门id | ||
*/ | ||
private Integer pid; | ||
|
||
private Date createTime; | ||
|
||
private Date updateTime; | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...tem-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/depetment/DeptmentAddDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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.Min; | ||
import javax.validation.constraints.NotNull; | ||
|
||
/** | ||
* Description: | ||
* | ||
* @author: zhenxianyimeng | ||
* @date: 2019-06-14 | ||
* @time: 19:55 | ||
*/ | ||
@ApiModel("添加部门 DTO") | ||
@Data | ||
public class DeptmentAddDTO { | ||
|
||
@ApiModelProperty(value = "名字", required = true, example = "销售一组") | ||
@NotNull(message = "不能为空") | ||
private String name; | ||
|
||
@ApiModelProperty(value = "排序", required = true, example = "1") | ||
@NotNull(message = "不能为空") | ||
private Integer sort; | ||
|
||
@ApiModelProperty(value = "父级id", required = true, example = "1") | ||
@NotNull(message = "可以为空,默认0,顶层") | ||
@Min(value = 0,message = "父id不能小于0") | ||
private Integer pid = 0; | ||
} |
28 changes: 28 additions & 0 deletions
28
system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/DeptmentConvert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package cn.iocoder.mall.admin.convert; | ||
|
||
import cn.iocoder.mall.admin.api.bo.deptment.DeptmentBO; | ||
import cn.iocoder.mall.admin.api.dto.depetment.DeptmentAddDTO; | ||
import cn.iocoder.mall.admin.dataobject.DeptmentDO; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mappings; | ||
import org.mapstruct.factory.Mappers; | ||
|
||
/** | ||
* Description: | ||
* | ||
* @author: zhenxianyimeng | ||
* @date: 2019-06-14 | ||
* @time: 20:06 | ||
*/ | ||
@Mapper | ||
public interface DeptmentConvert { | ||
|
||
DeptmentConvert INSTANCE = Mappers.getMapper(DeptmentConvert.class); | ||
|
||
@Mappings({}) | ||
DeptmentDO convert(DeptmentAddDTO deptmentAddDTO); | ||
|
||
@Mappings({}) | ||
DeptmentBO convert(DeptmentDO deptmentDO); | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DeptmentMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package cn.iocoder.mall.admin.dao; | ||
|
||
import cn.iocoder.mall.admin.dataobject.AdminDO; | ||
import cn.iocoder.mall.admin.dataobject.DeptmentDO; | ||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||
import org.apache.ibatis.annotations.Param; | ||
|
||
/** | ||
* Description: | ||
* | ||
* @author: zhenxianyimeng | ||
* @date: 2019-06-14 | ||
* @time: 19:26 | ||
*/ | ||
public interface DeptmentMapper extends BaseMapper<DeptmentDO> { | ||
|
||
default DeptmentDO findDeptByNameAndPid(String name, Integer pid){ | ||
return selectOne(new QueryWrapper<DeptmentDO>() | ||
.eq("name", name) | ||
.eq("pid", pid) | ||
.eq("deleted", false) | ||
); | ||
} | ||
|
||
|
||
} |
15 changes: 15 additions & 0 deletions
15
system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DeptmentRoleMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package cn.iocoder.mall.admin.dao; | ||
|
||
import cn.iocoder.mall.admin.dataobject.DeptmentRoleDO; | ||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||
|
||
/** | ||
* Description: | ||
* | ||
* @author: zhenxianyimeng | ||
* @date: 2019-06-14 | ||
* @time: 19:27 | ||
*/ | ||
public interface DeptmentRoleMapper extends BaseMapper<DeptmentRoleDO> { | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/DeptmentDO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package cn.iocoder.mall.admin.dataobject; | ||
|
||
import cn.iocoder.common.framework.dataobject.DeletableDO; | ||
import com.baomidou.mybatisplus.annotation.TableName; | ||
import lombok.Data; | ||
import lombok.experimental.Accessors; | ||
|
||
/** | ||
* Description:部门实体 | ||
* | ||
* @author: zhenxianyimeng | ||
* @date: 2019-06-14 | ||
* @time: 19:12 | ||
*/ | ||
@TableName("deptment") | ||
@Data | ||
@Accessors(chain = true) | ||
public class DeptmentDO extends DeletableDO { | ||
|
||
/** | ||
* 部门编号 | ||
*/ | ||
private Integer id; | ||
/** | ||
* 部门名称 | ||
*/ | ||
private String name; | ||
/** | ||
* 部门排序字段 | ||
*/ | ||
private Integer sort; | ||
/** | ||
* 父级部门id | ||
*/ | ||
private Integer pid; | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...em/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/DeptmentRoleDO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package cn.iocoder.mall.admin.dataobject; | ||
|
||
import cn.iocoder.common.framework.dataobject.DeletableDO; | ||
import com.baomidou.mybatisplus.annotation.TableName; | ||
import lombok.Data; | ||
|
||
/** | ||
* Description: 部门-角色映射表 | ||
* | ||
* @author: zhenxianyimeng | ||
* @date: 2019-06-14 | ||
* @time: 19:19 | ||
*/ | ||
@TableName("deptment_role") | ||
@Data | ||
public class DeptmentRoleDO extends DeletableDO { | ||
/** | ||
* 主键id | ||
*/ | ||
private Integer id; | ||
/** | ||
* 部门id | ||
*/ | ||
private Integer deptmentId; | ||
/** | ||
* 角色id | ||
*/ | ||
private Integer roleId; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
.../system-service-impl/src/main/java/cn/iocoder/mall/admin/service/DeptmentServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package cn.iocoder.mall.admin.service; | ||
|
||
import cn.iocoder.common.framework.util.ServiceExceptionUtil; | ||
import cn.iocoder.mall.admin.api.DeptmentService; | ||
import cn.iocoder.mall.admin.api.bo.deptment.DeptmentBO; | ||
import cn.iocoder.mall.admin.api.constant.AdminErrorCodeEnum; | ||
import cn.iocoder.mall.admin.api.dto.depetment.DeptmentAddDTO; | ||
import cn.iocoder.mall.admin.convert.DeptmentConvert; | ||
import cn.iocoder.mall.admin.dao.DeptmentMapper; | ||
import cn.iocoder.mall.admin.dataobject.DeptmentDO; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Description: | ||
* | ||
* @author: zhenxianyimeng | ||
* @date: 2019-06-14 | ||
* @time: 19:30 | ||
*/ | ||
@Service | ||
public class DeptmentServiceImpl implements DeptmentService { | ||
|
||
@Autowired | ||
private DeptmentMapper deptmentMapper; | ||
|
||
@Override | ||
public DeptmentBO addDeptment(Integer adminId, DeptmentAddDTO deptmentAddDTO) { | ||
if(deptmentAddDTO.getPid() != 0 && | ||
deptmentMapper.selectById(deptmentAddDTO.getPid()) == null){ | ||
throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.DEPT_PARENT_NOT_EXITS.getCode()); | ||
} | ||
//不同的大部门下好像可以小部门名字一样,验证同级别部门名字 | ||
if (null != deptmentMapper.findDeptByNameAndPid(deptmentAddDTO.getName(), deptmentAddDTO.getPid())) { | ||
throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.DEPT_SAME_LEVEL_NAME_EXITS.getCode()); | ||
} | ||
DeptmentDO deptmentDO = DeptmentConvert.INSTANCE.convert(deptmentAddDTO); | ||
deptmentMapper.insert(deptmentDO); | ||
return DeptmentConvert.INSTANCE.convert(deptmentDO); | ||
} | ||
} |