From 8f4433bf7907b3832f36fdccdd97a7d5f8af4856 Mon Sep 17 00:00:00 2001 From: chixiao Date: Sat, 15 Jun 2019 23:11:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=B0=E5=A2=9E=E9=83=A8?= =?UTF-8?q?=E9=97=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admins/DeptmentController.java | 39 ++++++++++++++++ .../application/vo/deptment/DeptmentVO.java | 14 ++++++ .../mall/admin/api/DeptmentService.java | 16 +++++++ .../admin/api/bo/deptment/DeptmentBO.java | 44 +++++++++++++++++++ .../api/constant/AdminErrorCodeEnum.java | 5 +++ .../api/dto/depetment/DeptmentAddDTO.java | 33 ++++++++++++++ .../mall/admin/convert/DeptmentConvert.java | 28 ++++++++++++ .../mall/admin/dao/DeptmentMapper.java | 27 ++++++++++++ .../mall/admin/dao/DeptmentRoleMapper.java | 15 +++++++ .../mall/admin/dataobject/DeptmentDO.java | 37 ++++++++++++++++ .../mall/admin/dataobject/DeptmentRoleDO.java | 29 ++++++++++++ .../mall/admin/service/AdminServiceImpl.java | 2 +- .../admin/service/DeptmentServiceImpl.java | 41 +++++++++++++++++ 13 files changed, 329 insertions(+), 1 deletion(-) create mode 100644 system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DeptmentController.java create mode 100644 system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/deptment/DeptmentVO.java create mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/DeptmentService.java create mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/deptment/DeptmentBO.java create mode 100644 system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/depetment/DeptmentAddDTO.java create mode 100644 system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/DeptmentConvert.java create mode 100644 system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DeptmentMapper.java create mode 100644 system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DeptmentRoleMapper.java create mode 100644 system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/DeptmentDO.java create mode 100644 system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/DeptmentRoleDO.java create mode 100644 system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/DeptmentServiceImpl.java diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DeptmentController.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DeptmentController.java new file mode 100644 index 000000000..8a77b27cd --- /dev/null +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/DeptmentController.java @@ -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 add(@RequestBody DeptmentAddDTO deptmentAddDTO){ + return success(deptmentService.addDeptment( + AdminSecurityContextHolder.getContext().getAdminId(), deptmentAddDTO)); + + } +} diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/deptment/DeptmentVO.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/deptment/DeptmentVO.java new file mode 100644 index 000000000..929d5e153 --- /dev/null +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/deptment/DeptmentVO.java @@ -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 { + +} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/DeptmentService.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/DeptmentService.java new file mode 100644 index 000000000..e6b9f53e2 --- /dev/null +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/DeptmentService.java @@ -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); +} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/deptment/DeptmentBO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/deptment/DeptmentBO.java new file mode 100644 index 000000000..37d8d874d --- /dev/null +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/deptment/DeptmentBO.java @@ -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; + + +} diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/AdminErrorCodeEnum.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/AdminErrorCodeEnum.java index df9949f48..48786700a 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/AdminErrorCodeEnum.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/constant/AdminErrorCodeEnum.java @@ -57,6 +57,11 @@ public enum AdminErrorCodeEnum { SMS_TEMPLATE_NOT_EXISTENT(1002006020, "短信签名不存在"), SMS_TEMPLATE_IS_EXISTENT(1002006021, "短信签名不存在"), SMS_NOT_SEND_CLIENT(1002006030, "短信没有发送的client"), + + // ========== 部门模块 1002007000 ========== + DEPT_SAME_LEVEL_NAME_EXITS(1002007001,"当前级别部门名字已存在"), + DEPT_PARENT_NOT_EXITS(1002007002,"父级部门不存在") + ; private final int code; diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/depetment/DeptmentAddDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/depetment/DeptmentAddDTO.java new file mode 100644 index 000000000..f440aa140 --- /dev/null +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/depetment/DeptmentAddDTO.java @@ -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; +} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/DeptmentConvert.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/DeptmentConvert.java new file mode 100644 index 000000000..ac3cfd31c --- /dev/null +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/convert/DeptmentConvert.java @@ -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); + +} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DeptmentMapper.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DeptmentMapper.java new file mode 100644 index 000000000..99b6fa76c --- /dev/null +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DeptmentMapper.java @@ -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 { + + default DeptmentDO findDeptByNameAndPid(String name, Integer pid){ + return selectOne(new QueryWrapper() + .eq("name", name) + .eq("pid", pid) + .eq("deleted", false) + ); + } + + +} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DeptmentRoleMapper.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DeptmentRoleMapper.java new file mode 100644 index 000000000..e062a607b --- /dev/null +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/DeptmentRoleMapper.java @@ -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 { + +} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/DeptmentDO.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/DeptmentDO.java new file mode 100644 index 000000000..63bcd8ef2 --- /dev/null +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/DeptmentDO.java @@ -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; + +} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/DeptmentRoleDO.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/DeptmentRoleDO.java new file mode 100644 index 000000000..f10f76d22 --- /dev/null +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/DeptmentRoleDO.java @@ -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; +} diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java index b0fccf80a..0137ade70 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java @@ -56,7 +56,7 @@ public class AdminServiceImpl implements AdminService { throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.ADMIN_USERNAME_NOT_REGISTERED.getCode()); } // 密码不正确 - if (encodePassword(adminAuthenticationDTO.getPassword()).equals(admin.getPassword())) { + if (!encodePassword(adminAuthenticationDTO.getPassword()).equals(admin.getPassword())) { throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.ADMIN_PASSWORD_ERROR.getCode()); } // 账号被禁用 diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/DeptmentServiceImpl.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/DeptmentServiceImpl.java new file mode 100644 index 000000000..067a83446 --- /dev/null +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/DeptmentServiceImpl.java @@ -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); + } +}