package com.dgtly.goods.controller;

import java.util.List;
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.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.dgtly.common.annotation.Log;
import com.dgtly.common.enums.BusinessType;
import com.dgtly.goods.domain.GoodsTypeAttribute;
import com.dgtly.goods.service.IGoodsTypeAttributeService;
import com.dgtly.common.core.controller.BaseController;
import com.dgtly.common.core.domain.AjaxResult;
import com.dgtly.common.utils.poi.ExcelUtil;
import com.dgtly.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author dgtly
 * @date 2020-02-13
 */
@Controller
@RequestMapping("/system/attribute")
public class GoodsTypeAttributeController extends BaseController
{
    private String prefix = "goods/attribute";

    @Autowired
    private IGoodsTypeAttributeService goodsTypeAttributeService;

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

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("system:attribute:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GoodsTypeAttribute goodsTypeAttribute)
    {
        startPage();
        List<GoodsTypeAttribute> list = goodsTypeAttributeService.selectGoodsTypeAttributeList(goodsTypeAttribute);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("system:attribute:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GoodsTypeAttribute goodsTypeAttribute)
    {
        List<GoodsTypeAttribute> list = goodsTypeAttributeService.selectGoodsTypeAttributeList(goodsTypeAttribute);
        ExcelUtil<GoodsTypeAttribute> util = new ExcelUtil<GoodsTypeAttribute>(GoodsTypeAttribute.class);
        return util.exportExcel(list, "attribute");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("system:attribute:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GoodsTypeAttribute goodsTypeAttribute)
    {
        return toAjax(goodsTypeAttributeService.insertGoodsTypeAttribute(goodsTypeAttribute));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        GoodsTypeAttribute goodsTypeAttribute = goodsTypeAttributeService.selectGoodsTypeAttributeById(id);
        mmap.put("goodsTypeAttribute", goodsTypeAttribute);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("system:attribute:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GoodsTypeAttribute goodsTypeAttribute)
    {
        return toAjax(goodsTypeAttributeService.updateGoodsTypeAttribute(goodsTypeAttribute));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("system:attribute:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(goodsTypeAttributeService.deleteGoodsTypeAttributeByIds(ids));
    }
}
