All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.base4j.mvc.sys.controller.SysDeptController Maven / Gradle / Ivy

The newest version!
package com.base4j.mvc.sys.controller;

import com.base4j.mvc.base.controller.BaseController;
import com.base4j.mvc.sys.entity.SysDept;
import com.base4j.mvc.sys.service.SysDeptService;
import com.base4j.mvc.util.ILoginUserTool;
import com.base4j.mvc.util.Res;
import com.base4j.mybatis.base.QueryParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("sys/dept")
public class SysDeptController extends BaseController {

    @Autowired
    private SysDeptService sysDeptService;

    @Autowired
    private ILoginUserTool loginUserTool;

    /**
     * 根据父级部门id查找其下级部门
     * @param parentId 父级部门id
     * @return
     */
    @RequestMapping("/selectListByParentId")
    public Res selectListByParentId(long parentId) {
        List subDepts = sysDeptService.selectChildNumListByParentId(parentId);
        return Res.ok(subDepts);
    }

    /**
     * 查询本组织下的所有部门
     * @return
     */
    @RequestMapping("/selectOwnOrgDeptList")
    public Res selectOwnOrgDeptList() {
        QueryParams queryParams = new QueryParams(SysDept.class);
        QueryParams.Criteria criteria = queryParams.createCriteria();
        criteria.andEqualTo("sysOrgId", loginUserTool.getLoginUser().getSysOrgId());
        List sysDepts = sysDeptService.selectListByParams(queryParams);
        return Res.ok(sysDepts);
    }


    @RequestMapping("selectOrgTree")
    public List selectOrgTree() {
        return sysDeptService.selectOrgTree();
    }

    @RequestMapping("/loadData")
    public SysDept loadData(long id) {
        return sysDeptService.selectByPrimaryKey(id);
    }

    /** 删除当前部门及期子部门
     * @param id
     * @return
     */
    @RequestMapping("deleteAllSubDeptById/{id}")
    public Res deleteAllSubDeptById(@PathVariable Long id) {
        QueryParams queryParams = new QueryParams(SysDept.class);
        QueryParams.Criteria criteria = queryParams.createCriteria();
        criteria.andEqualTo("id", id);
        QueryParams.Criteria or = queryParams.or();
        or.andEqualTo("parentId", id);
        sysDeptService.deleteByParams(queryParams);
        return Res.ok();
    }


    @RequestMapping("/deleteOrg")
    public Res deleteOrg(long id) {
        QueryParams params = new QueryParams(SysDept.class);
        QueryParams.Criteria criteria = params.createCriteria();
        criteria.andEqualTo("parentId", id);
        int count = sysDeptService.selectCountByParams(params);
        if (count > 0) {
            return Res.error("当前机构有下属机构,无法删除");
        }
        sysDeptService.deleteByPrimaryKey(id);
        return Res.ok();
    }

}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy