package com.yiqi.admin.controller.core;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.yiqi.common.constant.UrlConstants;
import com.yiqi.core.domain.vo.GoodsSkuStockRecordVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
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.yiqi.common.annotation.Log;
import com.yiqi.common.core.controller.BaseController;
import com.yiqi.common.core.domain.AjaxResult;
import com.yiqi.common.enums.BusinessType;
import com.yiqi.core.domain.GoodsSkuStockRecord;
import com.yiqi.core.service.IGoodsSkuStockRecordService;
import com.yiqi.common.utils.poi.ExcelUtil;
import com.yiqi.common.core.page.TableDataInfo;

/**
 * 商品库存变更记录Controller
 *
 * @author ruoyi
 * @date 2023-12-01
 */
@Api(tags = "管理后台 - 商品库存变更记录")
@RestController
@RequestMapping(UrlConstants.managerApi + "/goods/record")
public class GoodsSkuStockRecordController extends BaseController {
    @Autowired
    private IGoodsSkuStockRecordService goodsSkuStockRecordService;


    //<editor-folder desc="基础函数">
    /**
     * 查询商品库存变更记录列表
     */
//    @PreAuthorize("@ss.hasPermi('goods:record:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询商品库存变更记录列表")
    public TableDataInfo list(GoodsSkuStockRecord goodsSkuStockRecord) {
        startPage();
        List<GoodsSkuStockRecordVO> list = goodsSkuStockRecordService.selectGoodsSkuStockRecordList(goodsSkuStockRecord);
        return getDataTable(list);
    }

    /**
     * 导出商品库存变更记录列表
     */
    @PreAuthorize("@ss.hasPermi('goods:record:export')")
    @Log(title = "商品库存变更记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出商品库存变更记录列表")
    public void export(HttpServletResponse response, GoodsSkuStockRecord goodsSkuStockRecord) {
        List<GoodsSkuStockRecordVO> list = goodsSkuStockRecordService.selectGoodsSkuStockRecordList(goodsSkuStockRecord);
        ExcelUtil<GoodsSkuStockRecordVO> util = new ExcelUtil<GoodsSkuStockRecordVO>(GoodsSkuStockRecordVO. class);
        util.exportExcel(response, list, "商品库存变更记录数据");
    }

    /**
     * 获取商品库存变更记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('goods:record:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取商品库存变更记录详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(goodsSkuStockRecordService.selectGoodsSkuStockRecordById(id));
    }

    /**
     * 新增商品库存变更记录
     */
    @PreAuthorize("@ss.hasPermi('goods:record:add')")
    @Log(title = "商品库存变更记录", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增商品库存变更记录")
    public AjaxResult add(@RequestBody GoodsSkuStockRecord goodsSkuStockRecord) {
        goodsSkuStockRecord.setCreateById(getUserId());
        goodsSkuStockRecord.setCreateBy(getUsername());
        return toAjax(goodsSkuStockRecordService.insertGoodsSkuStockRecord(goodsSkuStockRecord));
    }

    /**
     * 修改商品库存变更记录
     */
    @PreAuthorize("@ss.hasPermi('goods:record:edit')")
    @Log(title = "商品库存变更记录", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改商品库存变更记录")
    public AjaxResult edit(@RequestBody GoodsSkuStockRecord goodsSkuStockRecord) {
        goodsSkuStockRecord.setUpdateById(getUserId());
        goodsSkuStockRecord.setUpdateBy(getUsername());
        return toAjax(goodsSkuStockRecordService.updateGoodsSkuStockRecord(goodsSkuStockRecord));
    }

    /**
     * 删除商品库存变更记录
     */
    @PreAuthorize("@ss.hasPermi('goods:record:remove')")
    @Log(title = "商品库存变更记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除商品库存变更记录")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(goodsSkuStockRecordService.deleteGoodsSkuStockRecordByIds(ids));
    }


    //</editor-folder>
}
