您的位置:首页 > 编程语言 > Java开发

spring boot+iview 前后端分离架构之组织管理的实现(二十九)

2019-07-09 18:56 896 查看
版权声明:署名,允许他人基于本文进行创作,且必须基于与原先许可协议相同的许可协议分发本文 (Creative Commons

spring boot 与 iview 前后端分离架构之组织管理的实现(二十九)

  • 组织管理的实现
  • 运行项目
  • 组织管理

    在前面几章我们已经完成了我们整个系统的百分70的功能了,那么到本章我们将完成我们的组织架构此块的功能。

    前文错误本章修改

    由于当时在使用mybatis生成相应的代码的时候OrgDao和OrgDao.xml不小心写成了OrgeDao和OrgeDao.xml,因此本章做一个修改将其修改为OrgDao和OrgDao.xml。

    相关工具类的实现

    在我们开始编写组织管理的时候我们首先需要实现一些相关工具类。

    OrgDto【实体转换类】

    package com.github.bg.admin.core.dto;
    
    import java.util.List;
    
    /**
    * @author linzf
    * @since 2019/5/09
    * 类描述:前端展示组织架构的dto实体
    */
    public class OrgDto {
    
    /**
    * 流水ID
    */
    private Integer orgId;
    
    /**
    * 菜单名字
    */
    private String title;
    
    /**
    * 组织编码
    */
    private String orgCode;
    
    /**
    * 父流水ID
    */
    private Integer parentOrgId;
    
    /**
    * 父组织架构名字
    */
    private String parentOrgName;
    
    /**
    * 菜单流水完整路径(1.2.3)
    */
    private String fullPath;
    
    /**
    * 默认子节点都是展开的
    */
    private boolean expand = true;
    /**
    * 默认节点是没有选中的
    */
    private boolean checked = false;
    
    /**
    * 子节点数据
    */
    private List<OrgDto> children;
    
    public String getFullPath() {
    return fullPath;
    }
    
    public void setFullPath(String fullPath) {
    this.fullPath = fullPath;
    }
    
    public Integer getOrgId() {
    return orgId;
    }
    
    public void setOrgId(Integer orgId) {
    this.orgId = orgId;
    }
    
    public String getTitle() {
    return title;
    }
    
    public void setTitle(String title) {
    this.title = title;
    }
    
    public String getOrgCode() {
    return orgCode;
    }
    
    public void setOrgCode(String orgCode) {
    this.orgCode = orgCode;
    }
    
    public Integer getParentOrgId() {
    return parentOrgId;
    }
    
    public void setParentOrgId(Integer parentOrgId) {
    this.parentOrgId = parentOrgId;
    }
    
    public String getParentOrgName() {
    return parentOrgName;
    }
    
    public void setParentOrgName(String parentOrgName) {
    this.parentOrgName = parentOrgName;
    }
    
    public boolean isExpand() {
    return expand;
    }
    
    public void setExpand(boolean expand) {
    this.expand = expand;
    }
    
    public boolean isChecked() {
    return checked;
    }
    
    public void setChecked(boolean checked) {
    this.checked = checked;
    }
    
    public List<OrgDto> getChildren() {
    return children;
    }
    
    public void setChildren(List<OrgDto> children) {
    this.children = children;
    }
    }

    OrgMapper【组织实体转换】

    package com.github.bg.admin.core.mapper;
    
    import com.github.bg.admin.core.dto.OrgDto;
    import com.github.bg.admin.core.entity.Org;
    import org.mapstruct.Mapper;
    import org.mapstruct.Mapping;
    import org.mapstruct.Mappings;
    
    import java.util.List;
    
    /**
    * @author linzf
    * @since 2019/5/9
    * 类描述: 组织架构快速转换的实现
    */
    @Mapper(componentModel = "spring")
    public interface OrgMapper {
    
    /**
    * 功能描述:实现数据的转换
    *
    * @param entity
    * @return
    */
    @Mappings({
    @Mapping(target = "title", source = "orgName"),
    @Mapping(target = "orgId", source = "orgId")
    })
    OrgDto orgToOrgDto(Org entity);
    
    /**
    * 功能描述:实现集合的数据的转换
    *
    * @param orgs
    * @return
    */
    List<OrgDto> orgsToOrgDto(List<Org> orgs);
    
    }

    OrgCascaderDto【组织下拉的实体类】

    package com.github.bg.admin.core.dto;
    
    import java.util.List;
    
    /**
    * @author linzf
    * @since 2019/5/13
    * 类描述: 级联下拉的dto
    */
    public class OrgCascaderDto {
    
    /**
    * 流水ID
    */
    private String value;
    
    /**
    * 组织架构名称
    */
    private String label;
    
    /**
    * 子节点数据
    */
    private List<OrgCascaderDto> children;
    
    public String getValue() {
    return value;
    }
    
    public void setValue(String value) {
    this.value = value;
    }
    
    public String getLabel() {
    return label;
    }
    
    public void setLabel(String label) {
    this.label = label;
    }
    
    public List<OrgCascaderDto> getChildren() {
    return children;
    }
    
    public void setChildren(List<OrgCascaderDto> children) {
    this.children = children;
    }
    }

    OrgInstall【组织组装的工具类】

    package com.github.bg.admin.core.util;
    
    import com.github.bg.admin.core.dto.OrgCascaderDto;
    import com.github.bg.admin.core.dto.OrgDto;
    import com.github.bg.admin.core.entity.Org;
    
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Map;
    
    /**
    * @author linzf
    * @since 2019-05-09
    * 类描述:实现组织架构数据的组装
    */
    public class OrgInstall {
    
    /**
    * 功能描述:实现递归组装选中的菜单节点的数据
    *
    * @param orgList 全部菜单节点的集合
    * @param orgMap  当前被选中的数据
    * @return 返回组装好的数据
    */
    public static List<OrgDto> installCheckOrg(List<OrgDto> orgList, Map<String, Object> orgMap) {
    List<OrgDto> trees = new ArrayList&
    7ff7
    lt;>();
    for (OrgDto orgDto : orgList) {
    if (0 == orgDto.getParentOrgId()) {
    orgDto.setChildren(getCheckChild(orgDto.getOrgId(), orgList, orgMap));
    // 用于防止子节点部分选中,而父节点全部选中
    if (orgDto.getChildren().size() > 0) {
    for (OrgDto checkDto : orgDto.getChildren()) {
    if (!checkDto.isChecked()) {
    orgDto.setChecked(false);
    break;
    }
    }
    }
    trees.add(orgDto);
    }
    }
    return trees;
    }
    
    /**
    * 功能描述:实现树形菜单组织架构的数据的组装
    *
    * @param orgList 需要组装的组织架构的数据
    * @return 返回组装好的数据
    */
    public static List<OrgCascaderDto> installOrgCascader(List<Org> orgList) {
    List<OrgCascaderDto> orgCascaderDtos = new ArrayList<>();
    OrgCascaderDto orgCascaderDto = null;
    for (Org org : orgList) {
    orgCascaderDto = new OrgCascaderDto();
    orgCascaderDto.setValue(org.getOrgId().toString());
    orgCascaderDto.setLabel(org.getOrgName());
    if (0 == org.getParentOrgId()) {
    orgCascaderDto.setChildren(getCascaderChild(org.getOrgId(), orgList));
    orgCascaderDtos.add(orgCascaderDto);
    }
    }
    return orgCascaderDtos;
    }
    
    /**
    * 功能描述:递归遍历组织架构节点
    *
    * @param id 父节点ID
    * @param orgList 组织架构数据
    * @return 递归组装数据
    */
    private static List<OrgCascaderDto> getCascaderChild(Integer id, List<Org> orgList) {
    List<OrgCascaderDto> childList = new ArrayList<>();
    OrgCascaderDto orgCascaderDto = null;
    for (Org org : orgList) {
    orgCascaderDto = new OrgCascaderDto();
    orgCascaderDto.setValue(org.getOrgId().toString());
    orgCascaderDto.setLabel(org.getOrgName());
    if (org.getParentOrgId().intValue() == id.intValue()) {
    orgCascaderDto.setChildren(getCascaderChild(org.getOrgId(), orgList));
    childList.add(orgCascaderDto);
    }
    }
    return childList;
    }
    
    /**
    * 功能描述:实现树形菜单组织架构的数据的组装
    *
    * @param orgDtoList 需要组装的组织架构的数据
    * @return 返回组装好的数据
    */
    public static List<OrgDto> installOrg(List<OrgDto> orgDtoList) {
    List<OrgDto> orgDtos = new ArrayList<>();
    for (OrgDto orgDto : orgDtoList) {
    if (0 == orgDto.getParentOrgId()) {
    orgDto.setChildren(getChild(orgDto.getOrgId(), orgDtoList));
    orgDtos.add(orgDto);
    }
    }
    return orgDtos;
    }
    
    /**
    * 功能描述:递归遍历菜单节点
    *
    * @param id      父节点ID
    * @param orgDtos 组织架构的集合
    * @param OrgMap  当前被选中的组织架构
    * @return 递归实现组装数据
    */
    private static List<OrgDto> getCheckChild(Integer id, List<OrgDto> orgDtos, Map<String, Object> OrgMap) {
    List<OrgDto> childList = new ArrayList<>();
    for (OrgDto orgDto : orgDtos) {
    if (orgDto.getParentOrgId().intValue() == id.intValue()) {
    orgDto.setChildren(getCheckChild(orgDto.getOrgId(), orgDtos, OrgMap));
    if (OrgMap.get(orgDto.getOrgId().toString()) != null) {
    orgDto.setChecked(true);
    } else {
    orgDto.setChecked(false);
    }
    if (orgDto.getChildren().size() > 0) {
    for (OrgDto checkOrg : orgDto.getChildren()) {
    if (!checkOrg.isChecked()) {
    orgDto.setChecked(false);
    break;
    }
    }
    }
    childList.add(orgDto);
    }
    }
    return childList;
    }
    
    /**
    * 功能描述:递归遍历组织架构节点
    *
    * @param id 父节点ID
    * @param orgDtos 组织架构数据
    * @return 递归组装数据
    */
    private static List<OrgDto> getChild(Integer id, List<OrgDto> orgDtos) {
    List<OrgDto> childList = new ArrayList<>();
    for (OrgDto orgDto : orgDtos) {
    if (orgDto.getParentOrgId().intValue() == id.intValue()) {
    orgDto.setChildren(getChild(orgDto.getOrgId(), orgDtos));
    childList.add(orgDto);
    }
    }
    return childList;
    }
    
    }

    组织管理的实现

    由于组织和用户是具有关联关系的,因此我们在删除组织的时候,同时要删除组织和用户之间的关联关系,因此我们需要实现UserOrgDao的以下的方法。

    UserOrgDao.xml的实现

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="com.github.bg.admin.core.dao.UserOrgDao">
    <resultMap id="BaseResultMap" type="com.github.bg.admin.core.entity.UserOrg">
    <id column="userOrgId" jdbcType="VARCHAR" property="userOrgId" />
    <result column="userId" jdbcType="VARCHAR" property="userId" />
    <result column="orgId" jdbcType="INTEGER" property="orgId" />
    </resultMap>
    
    <!-- 根据用户ID来删除关联关系的数据 -->
    <delete id="deleteUserOrgByUserId">
    delete from t_user_org where userId = #{userId}
    </delete>
    
    <!-- 根据组织架构ID来删除关联关系的数据 -->
    <delete id="deleteUserOrgByOrgId">
    delete from t_user_org where orgId = #{orgId}
    </delete>
    
    <!-- 根据组织架构ID来统计用户和组织架构的数量 -->
    <select id="countUserOrgByOrgId" resultType="java.lang.Integer">
    select count(*) from t_user_org where orgId = #{orgId}
    </select>
    
    </mapper>

    UserOrgDao的实现

    package com.github.bg.admin.core.dao;
    
    import com.github.bg.admin.core.entity.UserOrg;
    import org.apache.ibatis.annotations.Param;
    import tk.mybatis.mapper.common.Mapper;
    
    public interface UserOrgDao extends Mapper<UserOrg> {
    
    /**
    * 功能描述:根据用户ID来删除关联数据
    * @param userId 用户ID
    * @return 返回删除结果
    */
    int deleteUserOrgByUserId(@Param("userId") String userId);
    
    /**
    * 功能描述:根据组织架构ID来统计用户和组织架构的数量
    * @param orgId 组织架构流水ID
    * @return 返回删除结果
    */
    int countUserOrgByOrgId(@Param("orgId") Integer orgId);
    
    /**
    * 功能描述:根据组织架构ID来删除关联关系的数据
    * @param orgId 组织架构流水ID
    * @return 返回删除结果
    */
    int deleteUserOrgByOrgId(@Param("orgId") Integer orgId);
    
    }

    OrgDao.xml的实现

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="com.github.bg.admin.core.dao.OrgDao">
    <resultMap id="BaseResultMap" type="com.github.bg.admin.core.entity.Org">
    <id column="orgId" jdbcType="INTEGER" property="orgId" />
    <result column="orgName" jdbcType="VARCHAR" property="orgName" />
    <result column="orgCode" jdbcType="VARCHAR" property="orgCode" />
    <result column="parentOrgId" jdbcType="INTEGER" property="parentOrgId" />
    <result column="parentOrgName" jdbcType="VARCHAR" property="parentOrgName" />
    <result column="crtDate" jdbcType="TIMESTAMP" property="crtDate" />
    <result column="fullPath" jdbcType="VARCHAR" property="fullPath" />
    </resultMap>
    
    <!-- 根据用户ID来获取关联的组织架构的数据 -->
    <select id="getOrgByUserId" resultMap="BaseResultMap">
    select t.* from t_org t left join  t_user_org tuo on t.orgId = tuo.orgId where tuo.userId = #{userId}
    </select>
    
    <!-- 更新节点的路径 -->
    <update id="updateFullPath">
    update t_org set fullPath = #{fullPath} where  orgId = #{orgId}
    </update>
    
    <!-- 判断当前组织架构底下是否还有子节点 -->
    <select id="countOrgChildren" resultType="java.lang.Integer">
    select count(*) from t_org where parentOrgId = #{orgId}
    </select>
    
    <!-- 验证角色编码和角色名字是否重复 -->
    <select id="checkOrgNameAndCode" resultType="java.lang.Integer">
    select count(*) from t_org where 1=1
    <if test="orgName!=null and orgName !=''">
    and orgName = #{orgName}
    </if>
    <if test="orgCode!=null and orgCode !=''">
    and orgCode = #{orgCode}
    </if>
    <if test="orgId != null and orgId != ''">
    and orgId != #{orgId}
    </if>
    </select>
    
    </mapper>

    OrgDao的实现

    package com.github.bg.admin.core.dao;
    
    import com.github.bg.admin.core.entity.Org;
    import org.apache.ibatis.annotations.Param;
    import tk.mybatis.mapper.common.Mapper;
    
    public interface OrgDao extends Mapper<Org> {
    
    /**
    * 功能描述:根据用户ID来获取关联的组织架构的数据
    *
    * @param userId 用户流水ID
    * @return 返回获取的结果
    */
    Org getOrgByUserId(@Param("userId") String userId);
    
    /**
    * 功能描述:判断当前组织架构底下是否还有子节点
    *
    * @param orgId 组织架构ID
    * @return 返回统计结果
    */
    int countOrgChildren(@Param("orgId") Integer orgId);
    
    /**
    * 功能描述:更新节点的路径
    *
    * @param orgId    组织架构ID
    * @param fullPath 组织架构完整路径
    * @return 返回更新结果
    */
    int updateFullPath(@Param("orgId") Integer orgId, @Param("fullPath") String fullPath);
    
    /**
    * 功能描述:验证组织架构名字和编码是否存在
    *
    * @param orgId   组织架构ID
    * @param orgName 组织架构名称
    * @param orgCode 组织架构编码
    * @return 返回验证结果
    */
    int checkOrgNameAndCode(@Param("orgId") Integer orgId, @Param("orgName") String orgName, @Param("orgCode") String orgCode);
    
    }

    OrgService的实现

    package com.github.bg.admin.core.service;
    
    import com.github.bg.admin.core.constant.SystemStaticConst;
    import com.github.bg.admin.core.dao.OrgDao;
    import com.github.bg.admin.core.dao.UserOrgDao;
    import com.github.bg.admin.core.entity.Org;
    import com.github.bg.admin.core.entity.ReturnInfo;
    import com.github.bg.admin.core.mapper.OrgMapper;
    import com.github.bg.admin.core.util.OrgInstall;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;
    
    import java.util.Date;
    import java.util.HashMap;
    import java.util.Map;
    
    /**
    * @author linzf
    * @since 2019-05-09
    * 类描述:组织架构的service
    */
    @Service
    @Transactional(rollbackFor = {IllegalArgumentException.class})
    public class OrgService {
    
    @Autowired
    private OrgDao orgDao;
    @Autowired
    private UserOrgDao userOrgDao;
    @Autowired
    private OrgMapper orgMapper;
    
    /**
    * 功能描述:获取组织架构信息
    * @param orgId 组织架构流水ID
    * @return 返回获取结果
    */
    public ReturnInfo getOrgByOrgId(Integer orgId) {
    Org org = orgDao.selectByPrimaryKey(orgId);
    if (org == null) {
    return new ReturnInfo(SystemStaticConst.FAIL, "查无此组织架构数据,请重新刷新页面!");
    }
    return new ReturnInfo(SystemStaticConst.SUCCESS, "获取组织架构数据成功", org);
    }
    
    /**
    * 功能描述:删除组织架构
    *
    * @param orgId 组织架构流水ID
    * @return 返回删除结果
    */
    public ReturnInfo deleteOrg(Integer orgId) {
    Org org = orgDao.selectByPrimaryKey(orgId);
    if (org == null) {
    return new ReturnInfo(SystemStaticConst.FAIL, "删除组织架构数据失败,查无此组织架构数据!");
    }
    if (orgDao.countOrgChildren(orgId) > 0) {
    return new ReturnInfo(SystemStaticConst.FAIL, "删除组织架构数据失败,当前组织架构底下还有子组织,请先删除子组织!");
    }
    if (userOrgDao.countUserOrgByOrgId(orgId) > 0) {
    return new ReturnInfo(SystemStaticConst.FAIL, "删除组织架构数据失败,当前组织架构底下还有用户,请先删除该组织架构底下的用户!");
    }
    if (orgDao.deleteByPrimaryKey(orgId) > 0) {
    userOrgDao.deleteUserOrgByOrgId(orgId);
    return new ReturnInfo(SystemStaticConst.SUCCESS, "删除组织架构成功!");
    } else {
    return new ReturnInfo(SystemStaticConst.FAIL, "删除组织架构数据失败,查无此组织架构数据!");
    }
    }
    
    /**
    * 功能描述:更新组织架构的数据
    *
    * @param orgId   组织架构流水ID
    * @param orgName 组织架构名字
    * @param orgCode 组织架构编码
    * @return 返回更新结果
    */
    public ReturnInfo updateOrg(Integer orgId, String orgName, String orgCode) {
    if (orgDao.checkOrgNameAndCode(orgId, orgName, "") > 0) {
    return new ReturnInfo(SystemStaticConst.FAIL, "当前组织架构名称已经存在,请重新修改以后再提交!");
    }
    if (orgDao.checkOrgNameAndCode(orgId, "", orgCode) > 0) {
    return new ReturnInfo(SystemStaticConst.FAIL, "当前组织架构编码已经存在,请重新修改以后再提交!");
    }
    Org org = orgDao.selectByPrimaryKey(orgId);
    if (org == null) {
    return new ReturnInfo(SystemStaticConst.FAIL, "查无此组织架构数据,请重新刷新页面!");
    }
    org.setOrgName(orgName);
    org.setOrgCode(orgCode);
    if (orgDao.updateByPrimaryKey(org) > 0) {
    return new ReturnInfo(SystemStaticConst.SUCCESS, "更新组织架构数据成功");
    } else {
    return new ReturnInfo(SystemStaticConst.FAIL, "更新组织架构失败");
    }
    }
    
    /**
    * 功能描述:增加组织架构
    *
    * @param orgName     组织架构名称
    * @param orgCode     组织架构编码
    * @param parentOrgId 父节点ID
    * @return
    */
    public ReturnInfo addOrg(String orgName, String orgCode, Integer parentOrgId) {
    StringBuilder fullPath = new StringBuilder();
    Org org = new Org();
    if (parentOrgId.intValue() == 0) {
    org.setParentOrgName("");
    } else {
    Org parent = orgDao.selectByPrimaryKey(parentOrgId);
    if (parent == null) {
    return new ReturnInfo(SystemStaticConst.FAIL, "查无此父组织架构数据,请重新选择父组织架构!");
    }
    org.setParentOrgName(parent.getOrgName());
    fullPath.append(parent.getFullPath());
    }
    org.setOrgName(orgName);
    org.setOrgCode(orgCode);
    org.setCrtDate(new Date());
    org.setParentOrgId(parentOrgId);
    if (orgDao.insert(org) > 0) {
    fullPath.append(".").append(org.getOrgId());
    orgDao.updateFullPath(org.getOrgId(), fullPath.toString());
    return new ReturnInfo(SystemStaticConst.SUCCESS, "增加组织架构成功", org);
    } else {
    return new ReturnInfo(SystemStaticConst.FAIL, "增加组织架构失败");
    }
    
    }
    
    /**
    * 功能描述:验证组织架构名字和编码是否存在
    *
    * @param orgId   组织架构ID
    * @param orgName 组织架构名称
    * @param orgCode 组织架构编码
    * @return 返回验证结果
    */
    public ReturnInfo checkOrgNameAndCode(Integer orgId, String orgName, String orgCode) {
    Map<String, Object> result = new HashMap<>(1);
    try {
    if (orgDao.checkOrgNameAndCode(orgId, orgName, orgCode) > 0) {
    result.put("success", "unPass");
    } else {
    result.put("success", "pass");
    }
    } catch (Exception e) {
    return new ReturnInfo(SystemStaticConst.FAIL, "验证请求处理失败,失败原因:" + e.getMessage());
    }
    return new ReturnInfo(SystemStaticConst.SUCCESS, "验证请求处理成功", result);
    }
    
    /**
    * 功能描述:获取组织架构树目录
    *
    * @return 返回获取的结果
    */
    public ReturnInfo getOrgTree() {
    return new ReturnInfo(SystemStaticConst.SUCCESS, "加载组织架构数据成功", OrgInstall.installOrg(orgMapper.orgsToOrgDto(orgDao.selectAll())));
    }
    
    /**
    * 功能描述:获取组织架构的Cascader的数据
    * @return 返回获取结果
    */
    public ReturnInfo getOrgCascader(){
    return new ReturnInfo(SystemStaticConst.SUCCESS, "加载级联菜单的组织架构数据成功", OrgInstall.installOrgCascader(orgDao.selectAll()));
    }
    
    }

    OrgController的实现

    package com.github.bg.admin.core.controller;
    
    import com.github.bg.admin.core.entity.ReturnInfo;
    import com.github.bg.admin.core.service.OrgService;
    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.RequestMapping;
    import org.springframework.web.bind.annotation.RequestParam;
    import org.springframework.web.bind.annotation.RestController;
    
    /**
    * @author linzf
    * @since 2019-05-09
    * 类描述:组织架构的controller
    */
    @RestController
    @RequestMapping("/org")
    public class OrgController {
    
    @Autowired
    private OrgService orgService;
    
    /**
    * 功能描述:获取组织架构信息
    * @param orgId 组织架构流水ID
    * @return 返回获取结果
    */
    @ApiOperation(value = "获取组织架构信息")
    @PostMapping("getOrgByOrgId")
    public ReturnInfo getOrgByOrgId(@RequestParam(name = "orgId") Integer orgId){
    return orgService.getOrgByOrgId(orgId);
    }
    
    /**
    * 功能描述:删除组织架构
    *
    * @param orgId 组织架构流水ID
    * @return 返回删除结果
    */
    @ApiOperation(value = "删除组织架构")
    @PostMapping("deleteOrg")
    public ReturnInfo deleteOrg(@RequestParam(name = "orgId") Integer orgId) {
    return orgService.deleteOrg(orgId);
    }
    
    /**
    * 功能描述:更新组织架构的数据
    *
    * @param orgId   组织架构流水ID
    * @param orgName 组织架构名字
    * @param orgCode 组织架构编码
    * @return 返回更新结果
    */
    @ApiOperation(value = "更新组织架构的数据")
    @PostMapping("updateOrg")
    public ReturnInfo updateOrg(@RequestParam(name = "orgId") Integer orgId,
    @RequestParam(name = "orgName") String orgName,
    @RequestParam(name = "orgCode") String orgCode) {
    return orgService.updateOrg(orgId, orgName, orgCode);
    }
    
    /**
    * 功能描述:增加组织架构
    *
    * @param orgName     组织架构名称
    * @param orgCode     组织架构编码
    * @param parentOrgId 父节点ID
    * @return 返回增加组织架构的结果
    */
    @ApiOperation(value = "增加组织架构")
    @PostMapping("addOrg")
    public ReturnInfo addOrg(@RequestParam(name = "orgName") String orgName,
    @RequestParam(name = "orgCode") String orgCode,
    @RequestParam(name = "parentOrgId") Integer parentOrgId) {
    return orgService.addOrg(orgName, orgCode, parentOrgId);
    }
    
    /**
    * 功能描述:验证组织架构名字和编码是否存在
    *
    * @param orgId   组织架构ID
    * @param orgName 组织架构名称
    * @param orgCode 组织架构编码
    * @return 返回验证结果
    */
    @ApiOperation(value = "验证组织架构名字和编码是否存在")
    @PostMapping("checkOrgNameAndCode")
    public ReturnInfo checkOrgNameAndCode(@RequestParam(name = "orgId", required = false) Integer orgId,
    @RequestParam(name = "orgName", required = false) String orgName,
    @RequestParam(name = "orgCode", required = false) String orgCode) {
    return orgService.checkOrgNameAndCode(orgId, orgName, orgCode);
    }
    
    /**
    * 功能描述:获取组织架构树目录
    *
    * @return 返回获取的结果
    */
    @ApiOperation(value = "获取组织架构树目录")
    @PostMapping("getOrgTree")
    public ReturnInfo getOrgTree() {
    return orgService.getOrgTree();
    }
    
    /**
    * 功能描述:获取组织架构的Cascader的数据
    * @return 返回获取结果
    */
    @ApiOperation(value = "获取组织架构的Cascader的数据")
    @PostMapping("getOrgCascader")
    public ReturnInfo getOrgCascader(){
    return orgService.getOrgCascader();
    }
    
    }

    运行项目

    最后我们重新编译我们的项目,记得一定要重新编译,因为我们引入了mapper,不重新编译是会报错的,然后我们使用账号:admin密码:123456登录系统操作我们的用户组织模块,可以正常的对组织进行维护,但是这个时候会产生报错,这是因为用户还没有集成进去的原因,等下一章集成进去就不会有这个问题了。

    本章的代码的github地址是:https://github.com/lazyboyl/bg-admin/tree/chapter-29

    内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
    标签: 
    相关文章推荐