增加新增部门接口

This commit is contained in:
chixiao
2019-06-15 23:11:09 +08:00
parent e7c9464804
commit 8f4433bf79
13 changed files with 329 additions and 1 deletions

View File

@@ -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);
}

View File

@@ -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)
);
}
}

View File

@@ -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> {
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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());
}
// 账号被禁用

View File

@@ -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);
}
}