package com.bawei.mall.product.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bawei.common.log.annotation.Log;
import com.bawei.common.log.enums.BusinessType;
import com.bawei.common.security.annotation.RequiresPermissions;
import com.bawei.mall.product.domain.MallProductTypeInfo;
import com.bawei.mall.product.service.IMallProductTypeInfoService;
import com.bawei.common.core.web.controller.BaseController;
import com.bawei.common.core.web.domain.AjaxResult;
import com.bawei.common.core.utils.poi.ExcelUtil;

/**
 * 商品类型Controller
 *
 * @author DongZeLiang
 * @date 2022-09-16
 */
@RestController
@RequestMapping("/type")
public class MallProductTypeInfoController extends BaseController
{
    @Autowired
    private IMallProductTypeInfoService mallProductTypeInfoService;

    /**
     * 查询商品类型列表
     */
    @RequiresPermissions("product:type:list")
    @GetMapping("/list")
    public AjaxResult list(MallProductTypeInfo mallProductTypeInfo)
    {
        List<MallProductTypeInfo> list = mallProductTypeInfoService.selectMallProductTypeInfoList(mallProductTypeInfo);
        return AjaxResult.success(list);
    }
    @RequiresPermissions("product:type:list")
    @GetMapping("/tree")
    public AjaxResult tree()
    {
        MallProductTypeInfo mallProductTypeInfo = new MallProductTypeInfo();
        mallProductTypeInfo.setParentId(0L);
        List<MallProductTypeInfo> list = mallProductTypeInfoService.selectMallProductTypeInfoList(mallProductTypeInfo);
        return AjaxResult.success(list);
    }



    /**
     * 导出商品类型列表
     */
    @RequiresPermissions("product:type:export")
    @Log(title = "商品类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallProductTypeInfo mallProductTypeInfo)
    {
        List<MallProductTypeInfo> list = mallProductTypeInfoService.selectMallProductTypeInfoList(mallProductTypeInfo);
        ExcelUtil<MallProductTypeInfo> util = new ExcelUtil<MallProductTypeInfo>(MallProductTypeInfo.class);
        util.exportExcel(response, list, "商品类型数据");
    }

    /**
     * 获取商品类型详细信息
     */
    @RequiresPermissions("product:type:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mallProductTypeInfoService.selectMallProductTypeInfoById(id));
    }

    /**
     * 新增商品类型
     */
    @RequiresPermissions("product:type:add")
    @Log(title = "商品类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallProductTypeInfo mallProductTypeInfo)
    {
        return toAjax(mallProductTypeInfoService.insertMallProductTypeInfo(mallProductTypeInfo));
    }

    /**
     * 修改商品类型
     */
    @RequiresPermissions("product:type:edit")
    @Log(title = "商品类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallProductTypeInfo mallProductTypeInfo)
    {
        return toAjax(mallProductTypeInfoService.updateMallProductTypeInfo(mallProductTypeInfo));
    }

    /**
     * 删除商品类型
     */
    @RequiresPermissions("product:type:remove")
    @Log(title = "商品类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mallProductTypeInfoService.deleteMallProductTypeInfoByIds(ids));
    }
}
