package com.gxwebsoft.shop.controller;

import com.gxwebsoft.common.core.annotation.OperationLog;
import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.shop.dto.ShopGoodsProfitUpdateDto;
import com.gxwebsoft.shop.service.ShopGoodsProfitService;
import com.gxwebsoft.shop.vo.ShopGoodsProfitVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商品分润设定控制器
 *
 * @author xm
 * @since 2026-05-20 14:33:00
 */
@Tag(name = "商品分润设定管理")
@RestController
@RequestMapping("/api/shop/shop-goods-profit")
public class ShopGoodsProfitController extends BaseController {
    @Resource
    private ShopGoodsProfitService shopGoodsProfitService;

//    @PreAuthorize("hasAuthority('shop:shopGoodsProfit:list')")
    @Operation(summary = "通过商品、类型查询分润信息")
    @GetMapping("/getByGoodsId")
    @Parameters({
            @Parameter(name = "goodsId", description = "商品ID", required = true, example = "10086"),
            @Parameter(name = "type", description = "类型 1-分红 2-其他", required = true, example = "1")
    })
    public ApiResult<List<ShopGoodsProfitVO>> getByGoodsId(@RequestParam("goodsId") Integer goodsId, @Param("type") Integer type) {
        return success(shopGoodsProfitService.getByGoodsId(goodsId, type));
    }

//    @PreAuthorize("hasAuthority('shop:shopGoodsProfit:update')")
    @OperationLog
    @Operation(summary = "根据商品ID修改商品分润设定")
    @PutMapping("/updateByGoodsId")
    public ApiResult<Boolean> update(@RequestBody ShopGoodsProfitUpdateDto updateDto) {
        return success(shopGoodsProfitService.updateByGoodsId(updateDto));
    }

}
