public boolean addOrUpdate(Map map) {
    //父级信息
    _Map aSuper = (Map) map.get(“super”);
    //获取需要修改、添加的部门信息
    Map mm = (Map) map.get(“department”);
    Department department = new Department();
    ConvertUtils._register
    (new DateLocaleConverter(), Date.class);
    try {
    //把map转成department对象
    _BeanUtils._populate
    (department, mm);
    } catch (IllegalAccessException | InvocationTargetException e) {
    e.printStackTrace();
    }

    1. _//判断前端有没有传父级过来<br /> _if (aSuper != null) {<br /> _/* 获取父级的id,用于子级的super_id<br /> 等级比父级低,所以在父级基础上+1<br /> 获取父级的名字,并设置在supior */<br /> _department.setSuperId((Integer) aSuper.get("id"));<br /> department.setLevel((Integer) aSuper.get("level") + 1);<br /> department.setSupior(((String) aSuper.get("name")));<br /> } else {<br /> _/*如果没有父级,那么自己等级最高*/<br /> _department.setSuperId(0);<br /> department.setLevel(1);<br /> department.setSupior("");<br /> }<br /> _//新增或修改<br />// this.saveOrUpdate(department);<br /> //如果部门的id不存在,新增部门<br /> _if(department.getId()==null){
    2. this.save(department);<br /> }else{
    3. this.updateById(department);<br /> Integer did = department.getId();<br /> QueryWrapper<Department> queryWrapper= new QueryWrapper<>();<br /> queryWrapper.eq("id", did);
    4. List<Department> list = this.list(queryWrapper);<br /> for (Department depart:list) {<br /> depart.setSupior(department.getName());<br /> this.updateById(depart);<br /> }<br /> }
    5. return true;<br /> }