package com.ruoyi.web.controller.doubleDefense;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.doubledefense.domain.BasicSafetyCategory;
import com.ruoyi.doubledefense.service.IBasicSafetyCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * 【安全基础文档控制层】Controller
 *
 * @author ruoyi
 * @date 2023-08-03
 */
@RestController
@Api(tags = "安全基础文档分类接口")
@RequestMapping("/system/category")
public class BasicSafetyCategoryController extends BaseController
{
    @Autowired
    private IBasicSafetyCategoryService basicSafetyCategoryService;

    /**
     * 查询【安全基础文档分类】列表
     */
    //TODO 20230920PreAuthorize("@ss.hasPermi('system:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasicSafetyCategory basicSafetyCategory)
    {
        startPage();
        List<BasicSafetyCategory> list = basicSafetyCategoryService.selectBasicSafetyCategoryList(basicSafetyCategory);
        return getDataTable(list);
    }

    /**
     * 导出【安全基础文档分类】列表
     */
    //TODO 20230920PreAuthorize("@ss.hasPermi('system:category:export')")
    @Log(title = "【安全基础文档分类】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasicSafetyCategory basicSafetyCategory)
    {
        List<BasicSafetyCategory> list = basicSafetyCategoryService.selectBasicSafetyCategoryList(basicSafetyCategory);
        ExcelUtil<BasicSafetyCategory> util = new ExcelUtil<BasicSafetyCategory>(BasicSafetyCategory.class);
        util.exportExcel(response, list, "【安全基础文档分类】数据");
    }

    /**
     * 获取【安全基础文档分类】详细信息
     */
//    //TODO 20230920PreAuthorize("@ss.hasPermi('system:category:getInfo')")
    @Anonymous
    @ApiOperation("获取分类详情")
    @GetMapping(value = "getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(basicSafetyCategoryService.getById(id));
    }

    /**
     * 编辑【安全基础文档分类】
     */
//    //TODO 20230920PreAuthorize("@ss.hasPermi('system:category:add')")
    @Log(title = "【安全基础文档分类】", businessType = BusinessType.INSERT)
    @ApiOperation("编辑安全基础文档分类")
    @PostMapping("add")
    @Anonymous
    public AjaxResult add(@RequestBody BasicSafetyCategory basicSafetyCategory)
    {
        return toAjax(basicSafetyCategoryService.saveOrUpdate(basicSafetyCategory));
    }


    /**
     * 删除【安全基础文档分类】
     */
//    //TODO 20230920PreAuthorize("@ss.hasPermi('system:category:remove')")
    @Log(title = "【安全基础文档分类】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(basicSafetyCategoryService.deleteBasicSafetyCategoryByIds(ids));
    }

//    //TODO 20230920PreAuthorize("@ss.hasPermi('system:category:getCategoryTree')")
    @Anonymous
    @ApiOperation("获取分类树")
    @GetMapping(value = "getCategoryTree/{parentId}")
    public AjaxResult getCategoryTree(@PathVariable("parentId") String parentId)
    {
        return success(basicSafetyCategoryService.getCategoryTree(parentId));
    }





}
