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.GoodsSkuStore;
import com.yiqi.core.service.IGoodsSkuStoreService;
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-09-05
 */
@Api(tags = "管理后台 - 商品物料门店关联")
@RestController
@RequestMapping(UrlConstants.managerApi + "/goods/goodsSkuStore")
public class GoodsSkuStoreController extends BaseController {
    @Autowired
    private IGoodsSkuStoreService goodsSkuStoreService;

    /**
     * 查询商品物料门店关联列表
     */
//    @PreAuthorize("@ss.hasPermi('goods:goodsSkuStore:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询商品物料门店关联列表")
    public TableDataInfo list(GoodsSkuStore goodsSkuStore) {
        startPage();
        List<GoodsSkuStore> list = goodsSkuStoreService.selectGoodsSkuStoreList(goodsSkuStore);
        return getDataTable(list);
    }

    /**
     * 导出商品物料门店关联列表
     */
//    @PreAuthorize("@ss.hasPermi('goods:goodsSkuStore:export')")
    @Log(title = "商品物料门店关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出商品物料门店关联列表")
    public void export(HttpServletResponse response, GoodsSkuStore goodsSkuStore) {
        List<GoodsSkuStore> list = goodsSkuStoreService.selectGoodsSkuStoreList(goodsSkuStore);
        ExcelUtil<GoodsSkuStore> util = new ExcelUtil<GoodsSkuStore>(GoodsSkuStore.class);
        util.exportExcel(response, list, "商品物料门店关联数据");
    }

    /**
     * 获取商品物料门店关联详细信息
     */
//    @PreAuthorize("@ss.hasPermi('goods:goodsSkuStore:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取商品物料门店关联详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(goodsSkuStoreService.selectGoodsSkuStoreById(id));
    }

    /**
     * 新增商品物料门店关联
     */
//    @PreAuthorize("@ss.hasPermi('goods:goodsSkuStore:add')")
    @Log(title = "商品物料门店关联", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增商品物料门店关联")
    public AjaxResult add(@RequestBody GoodsSkuStore goodsSkuStore) {
        goodsSkuStore.setCreateById(getUserId());
        goodsSkuStore.setCreateBy(getUsername());
        return toAjax(goodsSkuStoreService.insertGoodsSkuStore(goodsSkuStore));
    }

    /**
     * 修改商品物料门店关联
     */
//    @PreAuthorize("@ss.hasPermi('goods:goodsSkuStore:edit')")
    @Log(title = "商品物料门店关联", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改商品物料门店关联")
    public AjaxResult edit(@RequestBody GoodsSkuStore goodsSkuStore) {
        goodsSkuStore.setUpdateById(getUserId());
        goodsSkuStore.setUpdateBy(getUsername());
        return toAjax(goodsSkuStoreService.updateGoodsSkuStore(goodsSkuStore));
    }

    /**
     * 删除商品物料门店关联
     */
//    @PreAuthorize("@ss.hasPermi('goods:goodsSkuStore:remove')")
    @Log(title = "商品物料门店关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除商品物料门店关联")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(goodsSkuStoreService.deleteGoodsSkuStoreByIds(ids));
    }

    /**
     * 修改商品物料门店关联状态
     */
//    @PreAuthorize("@ss.hasPermi('goods:goodsSkuStore:edit')")
    @Log(title = "商品物料门店关联", businessType = BusinessType.UPDATE)
    @PostMapping(value = "updateStatus")
    @ApiOperation(value = "修改商品物料门店关联状态")
    public AjaxResult updateGoodsSkuStoreStatus(@RequestBody GoodsSkuStore goodsSkuStore) {
        return toAjax(goodsSkuStoreService.updateGoodsSkuStoreStatus(goodsSkuStore));
    }
}
