package cn.stylefeng.guns.sys.modular.rest.service; import cn.stylefeng.guns.base.pojo.node.TreeviewNode; import cn.stylefeng.guns.base.pojo.node.ZTreeNode; import cn.stylefeng.guns.sys.core.exception.enums.BizExceptionEnum; import cn.stylefeng.guns.sys.modular.rest.entity.RestDept; import cn.stylefeng.guns.sys.modular.rest.mapper.RestDeptMapper; import cn.stylefeng.roses.core.util.ToolUtil; import cn.stylefeng.roses.kernel.model.exception.ServiceException; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.List; import java.util.Map; /** *

* 部门表 服务实现类 *

* * @author stylefeng * @since 2018-12-07 */ @Service public class RestDeptService extends ServiceImpl { @Resource private RestDeptMapper restDeptMapper; /** * 新增部门 * * @author fengshuonan * @Date 2018/12/23 5:00 PM */ @Transactional(rollbackFor = Exception.class) public void addDept(RestDept dept) { if (ToolUtil.isOneEmpty(dept, dept.getSimpleName(), dept.getFullName(), dept.getPid(), dept.getDescription())) { throw new ServiceException(BizExceptionEnum.REQUEST_NULL); } //完善pids,根据pid拿到pid的pids this.deptSetPids(dept); this.save(dept); } /** * 修改部门 * * @author fengshuonan * @Date 2018/12/23 5:00 PM */ @Transactional(rollbackFor = Exception.class) public void editDept(RestDept dept) { if (ToolUtil.isOneEmpty(dept, dept.getDeptId(), dept.getSimpleName(), dept.getFullName(), dept.getPid(), dept.getDescription())) { throw new ServiceException(BizExceptionEnum.REQUEST_NULL); } //完善pids,根据pid拿到pid的pids this.deptSetPids(dept); this.updateById(dept); } /** * 删除部门 * * @author fengshuonan * @Date 2018/12/23 5:16 PM */ @Transactional public void deleteDept(Long deptId) { RestDept dept = restDeptMapper.selectById(deptId); //根据like查询删除所有级联的部门 List subDepts = restDeptMapper.likePids(dept.getDeptId()); for (RestDept temp : subDepts) { this.removeById(temp.getDeptId()); } this.removeById(dept.getDeptId()); } /** * 获取ztree的节点列表 * * @author fengshuonan * @Date 2018/12/23 5:16 PM */ public List tree() { return this.baseMapper.tree(); } /** * 获取ztree的节点列表 * * @author fengshuonan * @Date 2018/12/23 5:16 PM */ public List treeviewNodes() { return this.baseMapper.treeviewNodes(); } /** * 获取所有部门列表 * * @author fengshuonan * @Date 2018/12/23 5:16 PM */ public List> list(String condition, Long deptId) { return this.baseMapper.listNotPage(condition, deptId); } /** * 设置部门的父级ids * * @author fengshuonan * @Date 2018/12/23 4:58 PM */ private void deptSetPids(RestDept dept) { if (ToolUtil.isEmpty(dept.getPid()) || dept.getPid().equals(0L)) { dept.setPid(0L); dept.setPids("[0],"); } else { Long pid = dept.getPid(); RestDept temp = this.getById(pid); String pids = temp.getPids(); dept.setPid(pid); dept.setPids(pids + "[" + pid + "],"); } } }