package com.xinelu.manage.controller.subdivisioncategory;

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.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.subdivisioncategory.SubdivisionCategory;
import com.xinelu.manage.service.subdivisioncategory.ISubdivisionCategoryService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 细分类别信息Controller
 *
 * @author xinelu
 * @date 2024-02-28
 */
@RestController
@RequestMapping("/system/subdivision")
public class SubdivisionCategoryController extends BaseController {
    @Resource
    private ISubdivisionCategoryService subdivisionCategoryService;

    /**
     * 查询细分类别信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:subdivision:list')")
    @GetMapping("/list")
    public TableDataInfo list(SubdivisionCategory subdivisionCategory) {
        startPage();
        List<SubdivisionCategory> list = subdivisionCategoryService.selectSubdivisionCategoryList(subdivisionCategory);
        return getDataTable(list);
    }

    /**
     * 导出细分类别信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:subdivision:export')")
    @Log(title = "细分类别信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SubdivisionCategory subdivisionCategory) {
        List<SubdivisionCategory> list = subdivisionCategoryService.selectSubdivisionCategoryList(subdivisionCategory);
        ExcelUtil<SubdivisionCategory> util = new ExcelUtil<SubdivisionCategory>(SubdivisionCategory.class);
        util.exportExcel(response, list, "细分类别信息数据");
    }

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

    /**
     * 新增细分类别信息
     */
    @PreAuthorize("@ss.hasPermi('system:subdivision:add')")
    @Log(title = "细分类别信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SubdivisionCategory subdivisionCategory) {
        return toAjax(subdivisionCategoryService.insertSubdivisionCategory(subdivisionCategory));
    }

    /**
     * 修改细分类别信息
     */
    @PreAuthorize("@ss.hasPermi('system:subdivision:edit')")
    @Log(title = "细分类别信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SubdivisionCategory subdivisionCategory) {
        return toAjax(subdivisionCategoryService.updateSubdivisionCategory(subdivisionCategory));
    }

    /**
     * 删除细分类别信息
     */
    @PreAuthorize("@ss.hasPermi('system:subdivision:remove')")
    @Log(title = "细分类别信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(subdivisionCategoryService.deleteSubdivisionCategoryByIds(ids));
    }
}
