package com.ruoyi.generator.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.generator.domain.SysProjectStructure;
import com.ruoyi.generator.service.ISysProjectStructureService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目结构节点Controller
 * 
 * @author ruoyi
 * @date 2025-05-14
 */
@RestController
@RequestMapping("/generator/structure")
public class SysProjectStructureController extends BaseController
{
    @Autowired
    private ISysProjectStructureService sysProjectStructureService;

    /**
     * 查询项目结构节点列表
     */
    @PreAuthorize("@ss.hasPermi('generator:structure:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysProjectStructure sysProjectStructure)
    {
        startPage();
        List<SysProjectStructure> list = sysProjectStructureService.selectSysProjectStructureList(sysProjectStructure);
        return getDataTable(list);
    }

    /**
     * 查询项目结构节点列表
     */
    @PreAuthorize("@ss.hasPermi('generator:structure:list')")
    @GetMapping("/listAll")
    public AjaxResult listAll(SysProjectStructure sysProjectStructure)
    {
        List<SysProjectStructure> list = sysProjectStructureService.selectSysProjectStructureList(sysProjectStructure);
        return success(list);
    }

    /**
     * 导出项目结构节点列表
     */
    @PreAuthorize("@ss.hasPermi('generator:structure:export')")
    @Log(title = "项目结构节点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysProjectStructure sysProjectStructure)
    {
        List<SysProjectStructure> list = sysProjectStructureService.selectSysProjectStructureList(sysProjectStructure);
        ExcelUtil<SysProjectStructure> util = new ExcelUtil<SysProjectStructure>(SysProjectStructure.class);
        util.exportExcel(response, list, "项目结构节点数据");
    }

    /**
     * 获取项目结构节点详细信息
     */
    @PreAuthorize("@ss.hasPermi('generator:structure:query')")
    @GetMapping(value = "/{nodeId}")
    public AjaxResult getInfo(@PathVariable("nodeId") Long nodeId)
    {
        return success(sysProjectStructureService.selectSysProjectStructureByNodeId(nodeId));
    }

    /**
     * 新增项目结构节点
     */
    @PreAuthorize("@ss.hasPermi('generator:structure:add')")
    @Log(title = "项目结构节点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysProjectStructure sysProjectStructure)
    {
        return toAjax(sysProjectStructureService.insertSysProjectStructure(sysProjectStructure));
    }

    /**
     * 修改项目结构节点
     */
    @PreAuthorize("@ss.hasPermi('generator:structure:edit')")
    @Log(title = "项目结构节点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysProjectStructure sysProjectStructure)
    {
        return toAjax(sysProjectStructureService.updateSysProjectStructure(sysProjectStructure));
    }

    /**
     * 删除项目结构节点
     */
    @PreAuthorize("@ss.hasPermi('generator:structure:remove')")
    @Log(title = "项目结构节点", businessType = BusinessType.DELETE)
    @DeleteMapping("/{nodeIds}")
    public AjaxResult remove(@PathVariable Long[] nodeIds)
    {
        return toAjax(sysProjectStructureService.deleteSysProjectStructureByNodeIds(nodeIds));
    }
}
