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.GoodsStore;
import com.yiqi.core.service.IGoodsStoreService;
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-21
 */
@Api(tags = "管理后台 - 商品门店")
@RestController
@RequestMapping(UrlConstants.managerApi + "/core/store")
public class GoodsStoreController extends BaseController {
    @Autowired
    private IGoodsStoreService goodsStoreService;

    /**
     * 查询商品门店列表
     */
//    @PreAuthorize("@ss.hasPermi('goods:store:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询商品门店列表")
    public TableDataInfo list(GoodsStore goodsStore) {
        startPage();
        List<GoodsStore> list = goodsStoreService.selectGoodsStoreList(goodsStore);
        return getDataTable(list);
    }

    /**
     * 导出商品门店列表
     */
//    @PreAuthorize("@ss.hasPermi('goods:store:export')")
    @Log(title = "商品门店", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出商品门店列表")
    public void export(HttpServletResponse response, GoodsStore goodsStore) {
        List<GoodsStore> list = goodsStoreService.selectGoodsStoreList(goodsStore);
        ExcelUtil<GoodsStore> util = new ExcelUtil<GoodsStore>(GoodsStore.class);
        util.exportExcel(response, list, "商品门店数据");
    }

    /**
     * 获取商品门店详细信息
     */
//    @PreAuthorize("@ss.hasPermi('goods:store:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取商品门店详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(goodsStoreService.selectGoodsStoreById(id));
    }

    /**
     * 新增商品门店
     */
//    @PreAuthorize("@ss.hasPermi('goods:store:add')")
    @Log(title = "商品门店", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增商品门店")
    public AjaxResult add(@RequestBody GoodsStore goodsStore) {
        goodsStore.setCreateById(getUserId());
        goodsStore.setCreateBy(getUsername());
        return toAjax(goodsStoreService.insertGoodsStore(goodsStore));
    }

    /**
     * 修改商品门店
     */
//    @PreAuthorize("@ss.hasPermi('goods:store:edit')")
    @Log(title = "商品门店", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改商品门店")
    public AjaxResult edit(@RequestBody GoodsStore goodsStore) {
        goodsStore.setUpdateById(getUserId());
        goodsStore.setUpdateBy(getUsername());
        return toAjax(goodsStoreService.updateGoodsStore(goodsStore));
    }

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

    /**
     * 修改商品门店状态
     */
//    @PreAuthorize("@ss.hasPermi('goods:store:edit')")
    @Log(title = "商品门店", businessType = BusinessType.UPDATE)
    @PostMapping(value = "updateStatus")
    @ApiOperation(value = "修改商品门店状态")
    public AjaxResult updateGoodsStoreStatus(@RequestBody GoodsStore goodsStore) {
        return toAjax(goodsStoreService.updateGoodsStoreStatus(goodsStore));
    }
}
