package com.xingxi.web.controller.master.product.controller;

import com.xingxi.common.annotation.Log;
import com.xingxi.common.core.controller.BaseController;
import com.xingxi.common.core.domain.AjaxResult;
import com.xingxi.common.enums.BusinessType;
import com.xingxi.common.enums.ERoleKey;
import com.xingxi.master.product.domain.ProdAttrPrice;
import com.xingxi.web.controller.master.product.domain.ProdAttrPriceVo;
import com.xingxi.web.controller.master.product.service.IProdAttrPriceVoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 商品属性价格Controller
 *
 * @author ruoyi
 * @date 2025-03-09
 */
@Controller
@RequestMapping("/master/product/prodAttrPrice")
public class ProdAttrPriceController extends BaseController {
    private final String prefix = "master/product/prodAttrprice";

    @Resource
    private IProdAttrPriceVoService prodAttrPriceVoService;

    @RequiresPermissions("master:product:prodAttrPrice:viewPrice")
    @GetMapping()
    public String price(@RequestParam("prodId") Long prodId,@RequestParam("prodAttrId") Long prodAttrId, ModelMap mMap) {
        ProdAttrPriceVo cond = new ProdAttrPriceVo();
        cond.setProdId(prodId);
        cond.setProdAttrId(prodAttrId);
        ProdAttrPriceVo prodAttrPriceVo = prodAttrPriceVoService.selectProdAttrPriceVo(cond);
        if (prodAttrPriceVo == null) {
            prodAttrPriceVo = new ProdAttrPriceVo();
            prodAttrPriceVo.setProdId(prodId);
            prodAttrPriceVo.setProdAttrId(prodAttrId);
        }
        prodAttrPriceVo.setSellerId(0L);
        prodAttrPriceVo.setSellerName("用户");
        prodAttrPriceVo.setSellerRoleKey(ERoleKey.PLATFORM.getCode());
        prodAttrPriceVo.setSellerRoleName(ERoleKey.PLATFORM.getDesc());
        prodAttrPriceVo.setBuyerId(100L);
        prodAttrPriceVo.setBuyerName("平台");
        prodAttrPriceVo.setBuyerRoleKey(ERoleKey.CUSTOMER.getCode());
        prodAttrPriceVo.setBuyerRoleName(ERoleKey.CUSTOMER.getDesc());
        mMap.put("prodAttrPriceVo", prodAttrPriceVo);
        return prefix + "/prodAttrPrice";
    }

    /**
     * 修改保存商品
     */
    @RequiresPermissions("master:product:prodAttrPrice:editPrice")
    @Log(title = "商品", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestBody ProdAttrPrice prodAttrPrice) {
        return toAjax(prodAttrPriceVoService.updateProdAttrPrice(prodAttrPrice));
    }
}
