ArchivesDeptController.java 4.57 KB
package com.ruoyi.controller;

import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.domain.ArchivesDept;
import com.ruoyi.service.IArchivesDeptService;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 部门Controller
 * 
 * @author li
 * @date 2022-08-01
 */
@RestController
@RequestMapping("/archives/dept")
public class ArchivesDeptController extends BaseController
{
    @Autowired
    private IArchivesDeptService archivesDeptService;

    /**
     * 查询部门列表
     */
    @PreAuthorize("@ss.hasPermi('archives:dept:list')")
    @GetMapping("/list")
    public AjaxResult list(ArchivesDept archivesDept)
    {
        startPage();
        List<ArchivesDept> list = archivesDeptService.selectArchivesDeptList(archivesDept);
        return AjaxResult.success(list);
    }

    /**
     * 导出部门列表
     */
    @PreAuthorize("@ss.hasPermi('archives:dept:export')")
    @Log(title = "部门", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArchivesDept archivesDept)
    {
        List<ArchivesDept> list = archivesDeptService.selectArchivesDeptList(archivesDept);
        ExcelUtil<ArchivesDept> util = new ExcelUtil<ArchivesDept>(ArchivesDept.class);
        util.exportExcel(response, list, "部门数据");
    }

    /**
     * 获取部门详细信息
     */
    @PreAuthorize("@ss.hasPermi('archives:dept:query')")
    @GetMapping(value = "/{deptId}")
    public AjaxResult getInfo(@PathVariable("deptId") Long deptId)
    {
        return AjaxResult.success(archivesDeptService.selectArchivesDeptByDeptId(deptId));
    }

    /**
     * 新增部门
     */
    @PreAuthorize("@ss.hasPermi('archives:dept:add')")
    @Log(title = "部门", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArchivesDept archivesDept)
    {
        return toAjax(archivesDeptService.insertArchivesDept(archivesDept));
    }

    /**
     * 修改部门
     */
    @PreAuthorize("@ss.hasPermi('archives:dept:edit')")
    @Log(title = "部门", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArchivesDept archivesDept)
    {
        return toAjax(archivesDeptService.updateArchivesDept(archivesDept));
    }

    /**
     * 删除部门
     */
    @PreAuthorize("@ss.hasPermi('archives:dept:remove')")
    @Log(title = "部门", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deptIds}")
    public AjaxResult remove(@PathVariable Long[] deptIds)
    {
        return toAjax(archivesDeptService.deleteArchivesDeptByDeptIds(deptIds));
    }
    
    @GetMapping("/treeselect")
    public AjaxResult treeselect(ArchivesDept archivesDept)
    {
        List<ArchivesDept> depts = archivesDeptService.selectArchivesDeptList(archivesDept);
        return AjaxResult.success(archivesDeptService.buildDeptTreeSelect(depts));
    }


    /**
     * 查询部门列表(排除节点)
     */
    @PreAuthorize("@ss.hasPermi('system:dept:list')")
    @GetMapping("/list/exclude/{deptId}")
    public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId)
    {
        List<ArchivesDept> depts = archivesDeptService.selectArchivesDeptList(new ArchivesDept());
        Iterator<ArchivesDept> it = depts.iterator();
        while (it.hasNext())
        {
            ArchivesDept d = (ArchivesDept) it.next();
            if (d.getDeptId().intValue() == deptId
                    || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + ""))
            {
                it.remove();
            }
        }
        return AjaxResult.success(depts);
    }

}