package com.ruoyi.project.monitor.controller;

import com.ruoyi.framework.aspectj.lang.annotation.Anonymous;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.system.domain.Product;
import com.ruoyi.project.system.domain.vo.FrontProductDetailVo;
import com.ruoyi.project.system.domain.vo.FrontProductVo;
import com.ruoyi.project.system.domain.vo.ProductVo;
import com.ruoyi.project.system.enums.DelFlagEnum;
import com.ruoyi.project.system.service.IProductCraftCateService;
import com.ruoyi.project.system.service.IProductMaterialService;
import com.ruoyi.project.system.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 产品价格
 * * @author zhu
 * * @date 2023-10-28
 */
@RestController
@RequestMapping("/monitor/product")
public class MonitorProductPriceController extends BaseController {
    @Autowired
    private IProductService productService;
    @Autowired
    private IProductMaterialService productMaterialService;

    @Autowired
    private IProductCraftCateService productCraftCateService;

    /**
     * 获取全部商品
     */
    @GetMapping("/index")
    public AjaxResult getList() {
        return AjaxResult.success(productService.selectFrontProductList(new Product().setDelFlag(DelFlagEnum.NORMAL.getCode()).setIsShow(true)));
    }

    /**
     * 查询产品材料列表
     */
    @GetMapping("/{id}")
    public AjaxResult list(@PathVariable("id") Long id) {
        ProductVo product = productService.selectProductById(id);
        FrontProductDetailVo productDetail = productCraftCateService.selectProductDetailById(product);
        return AjaxResult.success(productDetail);
    }

    /**
     * 计算价格
     *
     * @param frontProductVo
     * @return
     */
    @Anonymous
    @PostMapping("/compute")
    public AjaxResult compute(@RequestBody FrontProductVo frontProductVo) {
        return AjaxResult.success(productService.compute(frontProductVo));
    }
}
