Merge remote-tracking branch 'origin/master'

This commit is contained in:
YunaiV
2019-09-02 19:13:13 +08:00
34 changed files with 1283 additions and 224 deletions

View File

@@ -5,8 +5,10 @@ import cn.iocoder.common.framework.util.CollectionUtil;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.admin.api.AdminService;
import cn.iocoder.mall.admin.api.DeptmentService;
import cn.iocoder.mall.admin.api.ResourceService;
import cn.iocoder.mall.admin.api.RoleService;
import cn.iocoder.mall.admin.api.bo.deptment.DeptmentBO;
import cn.iocoder.mall.admin.api.bo.resource.ResourceBO;
import cn.iocoder.mall.admin.api.bo.role.RoleBO;
import cn.iocoder.mall.admin.api.bo.admin.AdminBO;
@@ -23,6 +25,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.*;
@@ -44,6 +47,9 @@ public class AdminController {
@Reference(validation = "true", version = "${dubbo.provider.RoleService.version}")
private RoleService roleService;
@Autowired
private DeptmentService deptmentService;
// =========== 当前管理员相关的资源 API ===========
// TODO 功能:当前管理员
@@ -85,7 +91,7 @@ public class AdminController {
}
// =========== 管理员管理 API ===========
//TODO 目前需要增加搜索所有子部门的用户
@GetMapping("/page")
@RequiresPermissions("system.admin.page")
@ApiOperation(value = "管理员分页")
@@ -97,7 +103,17 @@ public class AdminController {
// 查询角色数组
Map<Integer, Collection<RoleBO>> roleMap = adminService.getAdminRolesMap(CollectionUtil.convertList(resultPage.getList(), AdminBO::getId));
resultPage.getList().forEach(admin -> admin.setRoles(AdminConvert.INSTANCE.convertAdminVORoleList(roleMap.get(admin.getId()))));
// 查询对应部门
List<DeptmentBO> deptmentBOS = deptmentService.getAllDeptments();
Map<Integer, String> deptNameMap = deptmentBOS.stream().collect(Collectors.toMap(d->d.getId(), d->d.getName()));
//管理员所在部门被删后,变成未分配状态
deptNameMap.put(0, "未分配");
resultPage.getList().forEach(admin->{
admin.setDeptment(new AdminVO.Deptment(admin.getDeptmentId(), deptNameMap.get(admin.getDeptmentId())));
});
}
return success(resultPage);
}

View File

@@ -49,7 +49,7 @@ public class DeptmentController {
public CommonResult<List<DeptmentVO>> treeAll(){
List<DeptmentBO> list = deptmentService.getAllDeptments();
List<DeptmentVO> voList = DeptmentConvert.INSTANCE.convert(list);
Map<Integer, DeptmentVO> nodeMap = calaNodeMap(voList);
Map<Integer, DeptmentVO> nodeMap = calcNodeMap(voList);
// 获得到所有的根节点
List<DeptmentVO> rootNodes = nodeMap.values().stream()
.filter(node -> node.getPid().equals(ResourceConstants.PID_ROOT))
@@ -64,7 +64,7 @@ public class DeptmentController {
PageResult<DeptmentVO> voPageResult = DeptmentConvert.INSTANCE.convert(pageResult);
List<DeptmentBO> list = deptmentService.getAllDeptments();
List<DeptmentVO> voList = DeptmentConvert.INSTANCE.convert(list);
Map<Integer, DeptmentVO> nodeMap = calaNodeMap(voList);
Map<Integer, DeptmentVO> nodeMap = calcNodeMap(voList);
voPageResult.getList().forEach(d->{
d.setChildren(nodeMap.get(d.getId()).getChildren());
});
@@ -97,7 +97,7 @@ public class DeptmentController {
));
}
private Map<Integer, DeptmentVO> calaNodeMap(List<DeptmentVO> voList){
private Map<Integer, DeptmentVO> calcNodeMap(List<DeptmentVO> voList){
Map<Integer, DeptmentVO> nodeMap = voList.stream().collect(Collectors.toMap(e->e.getId(), e->e));
nodeMap.values().stream()

View File

@@ -3,6 +3,7 @@ package cn.iocoder.mall.admin.application.vo.admin;
import cn.iocoder.mall.admin.api.bo.admin.AdminBO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.experimental.Accessors;
@@ -15,6 +16,8 @@ public class AdminVO extends AdminBO {
private List<Role> roles;
private Deptment deptment;
@ApiModel("管理员 VO - 角色")
@Data
@Accessors(chain = true)
@@ -28,4 +31,19 @@ public class AdminVO extends AdminBO {
}
@ApiModel("管理员 VO - 部门")
@Data
@Accessors(chain = true)
@AllArgsConstructor
public static class Deptment {
@ApiModelProperty(value = "部门编号", required = true, example = "1")
private Integer id;
@ApiModelProperty(value = "部门名称", required = true, example = "研发部")
private String name;
}
}

View File

@@ -28,4 +28,7 @@ public class AdminBO implements Serializable {
@ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式")
private Date createTime;
@ApiModelProperty(value = "部门ID", required = true, example = "1")
private Integer deptmentId;
}

View File

@@ -7,6 +7,7 @@ import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
@@ -31,4 +32,8 @@ public class AdminAddDTO implements Serializable {
@Length(min = 4, max = 16, message = "密码长度为 4-16 位")
private String password;
@ApiModelProperty(value = "部门ID", required = true, example = "1")
@NotNull(message = "部门不能为空")
private Integer deptmentId;
}

View File

@@ -14,4 +14,8 @@ public class AdminPageDTO extends PageParam {
@ApiModelProperty(value = "昵称,模糊匹配", example = "小王")
private String nickname;
@ApiModelProperty(value = "所在部门ID")
private Integer deptmentId;
}

View File

@@ -35,4 +35,8 @@ public class AdminUpdateDTO implements Serializable {
@Length(min = 4, max = 16, message = "密码长度为 4-16 位")
private String password;
@ApiModelProperty(value = "部门ID", required = true, example = "1")
@NotNull(message = "部门不能为空")
private Integer deptmentId;
}

View File

@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.omg.PortableInterceptor.INACTIVE;
import org.springframework.stereotype.Repository;
@Repository
@@ -19,7 +20,14 @@ public interface AdminMapper extends BaseMapper<AdminDO> {
default IPage<AdminDO> selectPage(AdminPageDTO adminPageDTO) {
return selectPage(new Page<>(adminPageDTO.getPageNo(), adminPageDTO.getPageSize()),
new QueryWrapperX<AdminDO>().likeIfPresent("nickname", adminPageDTO.getNickname()));
new QueryWrapperX<AdminDO>().likeIfPresent("nickname", adminPageDTO.getNickname())
.eqIfPresent("deptment_id", adminPageDTO.getDeptmentId()));
}
default int updateDeptByDeptId(@Param("fromDeptId")Integer fromDeptId, @Param("toDeptId")Integer toDeptId){
QueryWrapper<AdminDO> query = new QueryWrapper<AdminDO>()
.eq("deptment_id", fromDeptId);
return update(new AdminDO().setDeptmentId(toDeptId), query);
}
}

View File

@@ -36,6 +36,12 @@ public class AdminDO extends DeletableDO {
*/
private Integer status;
/**
* 管理员部门id
*/
private Integer deptmentId;
// TODO 芋艿,最后登陆时间、最后登陆 IP
// TODO 芋艿,登陆日志

View File

@@ -11,6 +11,7 @@ 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.AdminMapper;
import cn.iocoder.mall.admin.dao.DeptmentMapper;
import cn.iocoder.mall.admin.dao.DeptmentRoleMapper;
import cn.iocoder.mall.admin.dataobject.DeptmentDO;
@@ -39,6 +40,9 @@ public class DeptmentServiceImpl implements DeptmentService {
@Autowired
private DeptmentRoleMapper deptmentRoleMapper;
@Autowired
private AdminMapper adminMapper;
@Override
public DeptmentBO addDeptment(Integer adminId, DeptmentAddDTO deptmentAddDTO) {
if (deptmentAddDTO.getPid() != 0 &&
@@ -69,6 +73,8 @@ public class DeptmentServiceImpl implements DeptmentService {
deptmentRoleMapper.deleteByDeptmentId(deptmentId);
//将改部门下所有员工的DeptmentID设置为0
adminMapper.updateDeptByDeptId(deptmentId, 0);
return true;
}