public boolean addOrUpdate(Map
//父级信息
_Map
Map
Department department = new Department();
ConvertUtils._register
try {
//把map转成department对象
_BeanUtils._populate(department, mm);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
_//判断前端有没有传父级过来<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){
this.save(department);<br /> }else{
this.updateById(department);<br /> Integer did = department.getId();<br /> QueryWrapper<Department> queryWrapper= new QueryWrapper<>();<br /> queryWrapper.eq("id", did);
List<Department> list = this.list(queryWrapper);<br /> for (Department depart:list) {<br /> depart.setSupior(department.getName());<br /> this.updateById(depart);<br /> }<br /> }
return true;<br /> }