package com.qryord.project.master.modelKind.controller;

import com.qryord.common.utils.poi.ExcelUtil;
import com.qryord.framework.aspectj.lang.annotation.Log;
import com.qryord.framework.aspectj.lang.enums.BusinessType;
import com.qryord.framework.web.controller.BaseController;
import com.qryord.framework.web.domain.AjaxResult;
import com.qryord.framework.web.page.TableDataInfo;
import com.qryord.project.master.modelKind.domain.ModelKind;
import com.qryord.project.master.modelKind.service.IModelKindService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品型号分类Controller
 * 
 * @author ruoyi
 * @date 2022-09-30
 */
@Controller
@RequestMapping("/master/modelKind")
public class ModelKindController extends BaseController
{
    private String prefix = "master/modelKind";

    @Autowired
    private IModelKindService mModelKindService;

    @RequiresPermissions("master:modelKind:view")
    @GetMapping()
    public String modelKind()
    {
        return prefix + "/modelKind";
    }

    /**
     * 查询商品型号分类列表
     */
    @RequiresPermissions("master:modelKind:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ModelKind mModelKind)
    {
        startPage();
        List<ModelKind> list = mModelKindService.selectModelKindList(mModelKind);
        return getDataTable(list);
    }

    /**
     * 导出商品型号分类列表
     */
    @RequiresPermissions("master:modelKind:export")
    @Log(title = "商品型号分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ModelKind mModelKind)
    {
        List<ModelKind> list = mModelKindService.selectModelKindList(mModelKind);
        ExcelUtil<ModelKind> util = new ExcelUtil<ModelKind>(ModelKind.class);
        return util.exportExcel(list, "商品型号分类数据");
    }

    /**
     * 新增商品型号分类
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商品型号分类
     */
    @RequiresPermissions("master:modelKind:add")
    @Log(title = "商品型号分类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ModelKind mModelKind)
    {
        return toAjax(mModelKindService.insertModelKind(mModelKind));
    }

    /**
     * 修改商品型号分类
     */
    @RequiresPermissions("master:modelKind:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ModelKind mModelKind = mModelKindService.selectModelKindById(id);
        mmap.put("mModelKind", mModelKind);
        return prefix + "/edit";
    }

    /**
     * 修改保存商品型号分类
     */
    @RequiresPermissions("master:modelKind:edit")
    @Log(title = "商品型号分类", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ModelKind mModelKind)
    {
        return toAjax(mModelKindService.updateModelKind(mModelKind));
    }

    /**
     * 删除商品型号分类
     */
    @RequiresPermissions("master:modelKind:remove")
    @Log(title = "商品型号分类", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mModelKindService.deleteModelKindByIds(ids));
    }
}
