DepotNodeController.java 4.57 KB
package com.ruoyi.service.controller;

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.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.service.domain.DepotNode;
import com.ruoyi.service.service.DepotNodeService;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 库房维护 控制层
 * 
 * @author ym
 * @date 2022-08-19
 */
@RestController
@RequestMapping("/service/depotNode")
public class DepotNodeController extends BaseController
{
    @Autowired
    private DepotNodeService depotNodeService;

    /**
     * 查询库房列表
     */
    @PreAuthorize("@ss.hasPermi('service:depotNode:list')")
    @GetMapping("/list")
    public AjaxResult list(DepotNode depotNode)
    {
        startPage();
        List<DepotNode> list = depotNodeService.selectDepotNodeList(depotNode);
        return AjaxResult.success(list);
    }

    /**
     * 导出库房列表
     */
    @PreAuthorize("@ss.hasPermi('service:depotNode:export')")
    @Log(title = "库房", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DepotNode depotNode)
    {
        List<DepotNode> list = depotNodeService.selectDepotNodeList(depotNode);
        ExcelUtil<DepotNode> util = new ExcelUtil<DepotNode>(DepotNode.class);
        util.exportExcel(response, list, "库房数据");
    }

    /**
     * 获取库房详细信息
     */
    @PreAuthorize("@ss.hasPermi('service:depotNode:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        DepotNode serviceDept=depotNodeService.selectDepotNodeById(id);
        System.out.println(serviceDept);
        return AjaxResult.success(depotNodeService.selectDepotNodeById(id));
    }

    /**
     * 新增库房
     */
    @PreAuthorize("@ss.hasPermi('service:depotNode:add')")
    @Log(title = "库房", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DepotNode depotNode)
    {
        return toAjax(depotNodeService.insertDepotNode(depotNode));
    }

    /**
     * 修改库房
     */
    @PreAuthorize("@ss.hasPermi('service:depotNode:edit')")
    @Log(title = "库房", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DepotNode depotNode)
    {
        if(depotNodeService.selectCountBox(depotNode.getId())>0 && ("1".equals(depotNode.getStatus()) || "2".equals(depotNode.getNodeFlag()))){
            return AjaxResult.error("档案架存在文件不可修改");
        }
        return toAjax(depotNodeService.updateDepotNode(depotNode));
    }

    /**
     * 删除库房
     */
    @PreAuthorize("@ss.hasPermi('service:depotNode:remove')")
    @Log(title = "库房", businessType = BusinessType.DELETE)
	@DeleteMapping("/{depotNodeIds}")
    public AjaxResult remove(@PathVariable Long[] depotNodeIds)
    {
        if(depotNodeService.selectCountBox(depotNodeIds[0])>0){
            return AjaxResult.error("档案架存在文件不可删除");
        }
        return toAjax(depotNodeService.deleteDepotNodeByIds(depotNodeIds));
    }
    
    @GetMapping("/treeselect")
    public AjaxResult treeselect(DepotNode depotNode)
    {
        depotNode.setStatus("0");
        List<DepotNode> depotNodes = depotNodeService.selectDepotNodeList(depotNode);
        return AjaxResult.success(depotNodeService.buildDepotNodeTreeSelect(depotNodes));
    }


    /**
     * 查询库房列表(排除节点)
     */
    @PreAuthorize("@ss.hasPermi('system:depotNode:list')")
    @GetMapping("/list/exclude/{depotNodeId}")
    public AjaxResult excludeChild(@PathVariable(value = "depotNodeId", required = false) Long depotNodeId)
    {
        List<DepotNode> depotNodes = depotNodeService.selectDepotNodeList(new DepotNode());
        Iterator<DepotNode> it = depotNodes.iterator();
        while (it.hasNext())
        {
            DepotNode d = (DepotNode) it.next();
            if (d.getId().intValue() == depotNodeId
                    || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), depotNodeId + ""))
            {
                it.remove();
            }
        }
        return AjaxResult.success(depotNodes);
    }

}