package com.ruoyi.web.controller.dxp.system.integration;

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.dxp.domain.Catalogue;
import com.ruoyi.dxp.service.ICatalogueService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 目录Controller
 * 
 * @author jy
 * @date 2022-11-11
 */
@RestController
@RequestMapping("/system/integration/catalogue")
public class CatalogueController extends BaseController
{
    @Autowired
    private ICatalogueService catalogueService;

    /**
     * 查询目录列表
     */
    @PreAuthorize("@ss.hasPermi('system/integration:catalogue:list')")
    @GetMapping("/list")
    public TableDataInfo list(Catalogue catalogue)
    {
        startPage();
        List<Catalogue> list = catalogueService.selectCatalogueList(catalogue);
        return getDataTable(list);
    }

    /**
     * 导出目录列表
     */
    @PreAuthorize("@ss.hasPermi('system/integration:catalogue:export')")
    @Log(title = "目录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Catalogue catalogue)
    {
        List<Catalogue> list = catalogueService.selectCatalogueList(catalogue);
        ExcelUtil<Catalogue> util = new ExcelUtil<Catalogue>(Catalogue.class);
        util.exportExcel(response, list, "目录数据");
    }

    /**
     * 获取目录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system/integration:catalogue:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(catalogueService.selectCatalogueById(id));
    }

    /**
     * 新增目录
     */
    @PreAuthorize("@ss.hasPermi('system/integration:catalogue:add')")
    @Log(title = "目录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Catalogue catalogue)
    {
        return toAjax(catalogueService.insertCatalogue(catalogue));
    }

    /**
     * 修改目录
     */
    @PreAuthorize("@ss.hasPermi('system/integration:catalogue:edit')")
    @Log(title = "目录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Catalogue catalogue)
    {
        return toAjax(catalogueService.updateCatalogue(catalogue));
    }

    /**
     * 删除目录
     */
    @PreAuthorize("@ss.hasPermi('system/integration:catalogue:remove')")
    @Log(title = "目录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(catalogueService.deleteCatalogueByIds(ids));
    }
}
