package com.xinelu.manage.controller.informationcategory;

import com.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.custominterface.Insert;
import com.xinelu.common.custominterface.Update;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.informationcategory.InformationCategory;
import com.xinelu.manage.dto.informationcategory.InformationCategoryDTO;
import com.xinelu.manage.service.informationcategory.IInformationCategoryService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * 资讯分类Controller
 *
 * @author xinyilu
 * @date 2023-02-14
 */
@RestController
@RequestMapping("/system/InformationCategory")
public class InformationCategoryController extends BaseController {
    @Resource
    private IInformationCategoryService informationCategoryService;

    /**
     * 查询资讯分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:InformationCategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(InformationCategory informationCategory) {
        startPage();
        List<InformationCategory> list = informationCategoryService.selectInformationCategoryList(informationCategory);
        return getDataTable(list);
    }

    /**
     * 导出资讯分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:InformationCategory:export')")
    @Log(title = "资讯分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InformationCategory informationCategory) {
        List<InformationCategory> list = informationCategoryService.selectInformationCategoryList(informationCategory);
        ExcelUtil<InformationCategory> util = new ExcelUtil<>(InformationCategory.class);
        util.exportExcel(response, list, "资讯分类数据");
    }

    /**
     * 获取资讯分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:InformationCategory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(informationCategoryService.selectInformationCategoryById(id));
    }

    /**
     * 新增资讯分类
     */
    @PreAuthorize("@ss.hasPermi('system:InformationCategory:add')")
    @Log(title = "资讯分类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody @Validated(Insert.class) InformationCategoryDTO informationCategory) {
        return informationCategoryService.insertInformationCategory(informationCategory);
    }

    /**
     * 修改资讯分类
     */
    @PreAuthorize("@ss.hasPermi('system:InformationCategory:edit')")
    @Log(title = "资讯分类", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody @Validated(Update.class) InformationCategory informationCategory) {
        return informationCategoryService.updateInformationCategory(informationCategory);
    }

    /**
     * 删除资讯分类
     */
    @PreAuthorize("@ss.hasPermi('system:InformationCategory:remove')")
    @Log(title = "资讯分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(informationCategoryService.deleteInformationCategoryByIds(ids));
    }
}
