package com.yiqi.admin.controller.core;

import com.yiqi.common.annotation.Log;
import com.yiqi.common.constant.UrlConstants;
import com.yiqi.common.core.controller.BaseController;
import com.yiqi.common.core.domain.AjaxResult;
import com.yiqi.common.core.page.TableDataInfo;
import com.yiqi.common.enums.BusinessType;
import com.yiqi.common.utils.poi.ExcelUtil;
import com.yiqi.core.domain.GoodsSkuSpec;
import com.yiqi.core.service.IGoodsSkuSpecService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 商品规格Controller
 *
 * @author ruoyi
 * @date 2023-08-30
 */
@Api(tags = "管理后台 - 商品规格")
@RestController
@RequestMapping(UrlConstants.managerApi + "/goods/goodsSkuSpec")
public class GoodsSkuSpecController extends BaseController {
    @Autowired
    private IGoodsSkuSpecService goodsSkuSpecService;

    /**
     * 查询商品规格列表
     */
//    @PreAuthorize("@ss.hasPermi('goods:goodsSkuSpec:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询商品规格列表")
    public TableDataInfo list(GoodsSkuSpec goodsSkuSpec) {
        startPage();
        List<GoodsSkuSpec> list = goodsSkuSpecService.selectGoodsSkuSpecList(goodsSkuSpec);
        return getDataTable(list);
    }

    /**
     * 导出商品规格列表
     */
//    @PreAuthorize("@ss.hasPermi('goods:goodsSkuSpec:export')")
    @Log(title = "商品规格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出商品规格列表")
    public void export(HttpServletResponse response, GoodsSkuSpec goodsSkuSpec) {
        List<GoodsSkuSpec> list = goodsSkuSpecService.selectGoodsSkuSpecList(goodsSkuSpec);
        ExcelUtil<GoodsSkuSpec> util = new ExcelUtil<GoodsSkuSpec>(GoodsSkuSpec.class);
        util.exportExcel(response, list, "商品规格数据");
    }

    /**
     * 获取商品规格详细信息
     */
//    @PreAuthorize("@ss.hasPermi('goods:goodsSkuSpec:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取商品规格详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(goodsSkuSpecService.selectGoodsSkuSpecById(id));
    }

    /**
     * 新增商品规格
     */
//    @PreAuthorize("@ss.hasPermi('goods:goodsSkuSpec:add')")
    @Log(title = "商品规格", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增商品规格")
    public AjaxResult add(@RequestBody GoodsSkuSpec goodsSkuSpec) {
        goodsSkuSpec.setCreateById(getUserId());
        goodsSkuSpec.setCreateBy(getUsername());
        return toAjax(goodsSkuSpecService.insertGoodsSkuSpec(goodsSkuSpec));
    }

    /**
     * 修改商品规格
     */
//    @PreAuthorize("@ss.hasPermi('goods:goodsSkuSpec:edit')")
    @Log(title = "商品规格", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改商品规格")
    public AjaxResult edit(@RequestBody GoodsSkuSpec goodsSkuSpec) {
        goodsSkuSpec.setUpdateById(getUserId());
        goodsSkuSpec.setUpdateBy(getUsername());
        return toAjax(goodsSkuSpecService.updateGoodsSkuSpec(goodsSkuSpec));
    }

    /**
     * 删除商品规格
     */
//    @PreAuthorize("@ss.hasPermi('goods:goodsSkuSpec:remove')")
    @Log(title = "商品规格", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除商品规格")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(goodsSkuSpecService.deleteGoodsSkuSpecByIds(ids));
    }

}
