package com.ruoyi.mall.controller;

import java.util.List;
import javax.annotation.Resource;
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.*;
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.mall.domain.MallMajorClass;
import com.ruoyi.mall.service.IMallMajorClassService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 专业分类Controller
 *
 * @author LCL
 * @date 2023-10-18
 */
@RestController
@RequestMapping("/mall/mallMajorClass")
public class MallMajorClassController extends BaseController
{
    @Resource
    private IMallMajorClassService mallMajorClassService;

    /**
     * 查询专业分类列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallMajorClass:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallMajorClass mallMajorClass)
    {
        startPage();
        List<MallMajorClass> list = mallMajorClassService.selectMallMajorClassList(mallMajorClass);
        return getDataTable(list);
    }

    /**
     * 导出专业分类列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallMajorClass:export')")
    @Log(title = "专业分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallMajorClass mallMajorClass)
    {
        List<MallMajorClass> list = mallMajorClassService.selectMallMajorClassList(mallMajorClass);
        ExcelUtil<MallMajorClass> util = new ExcelUtil<MallMajorClass>(MallMajorClass.class);
        util.exportExcel(response, list, "专业分类数据");
    }

    /**
     * 获取专业分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:mallMajorClass:query')")
    @GetMapping(value = "/{majorId}")
    public AjaxResult getInfo(@PathVariable("majorId") Long majorId)
    {
        return AjaxResult.success(mallMajorClassService.selectMallMajorClassByMajorId(majorId));
    }

    /**
     * 新增专业分类
     */
    @PreAuthorize("@ss.hasPermi('mall:mallMajorClass:add')")
    @Log(title = "专业分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallMajorClass mallMajorClass)
    {
        return toAjax(mallMajorClassService.insertMallMajorClass(mallMajorClass));
    }

    /**
     * 修改专业分类
     */
    @PreAuthorize("@ss.hasPermi('mall:mallMajorClass:edit')")
    @Log(title = "专业分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallMajorClass mallMajorClass)
    {
        return toAjax(mallMajorClassService.updateMallMajorClass(mallMajorClass));
    }

    /**
     * 删除专业分类
     */
    @PreAuthorize("@ss.hasPermi('mall:mallMajorClass:remove')")
    @Log(title = "专业分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{majorIds}")
    public AjaxResult remove(@PathVariable Long[] majorIds)
    {
        return toAjax(mallMajorClassService.deleteMallMajorClassByMajorIds(majorIds));
    }

    /**
     * 查询商品类型树列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallGoodsClass:list')")
    @GetMapping("/treeList")
    public AjaxResult treeList(MallMajorClass mallMajorClass)
    {
        List<MallMajorClass> list = mallMajorClassService.selectMallMajorClassList(mallMajorClass);
        return AjaxResult.success(list);
    }

    /**
     * 根据父级id查询专业分类
     * @param pid 父级id
     * @return 结果
     */
    @GetMapping("/selectMajorListByPid")
    public AjaxResult selectMajorListByPid(@RequestParam Long pid){
        return AjaxResult.success(mallMajorClassService.selectMajorListByPid(pid));
    }

    /**
     * 所有二级专业分类
     * @return 结果
     */
    @GetMapping("/selectMajorListByLowLevel")
    public AjaxResult selectMajorListByLowLevel(){
        return AjaxResult.success(mallMajorClassService.selectMajorListByLevel2());
    }

    /**
     * 专业级联列表
     * @return
     */
    @GetMapping("/getMajorList")
    public AjaxResult getMajorList(){
        return AjaxResult.success(mallMajorClassService.getMajorList());
    }

}
