package com.ruoyi.web.controller.quote;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.framework.web.domain.server.Sys;
import com.ruoyi.quote.domain.CalculateRBParamDto;
import com.ruoyi.quote.domain.MaterialDto;
import com.ruoyi.quote.service.QuoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.ruoyi.common.utils.PageUtils.startPage;

/**
 * @ClassName QuoteController
 * @Description TODO
 * @Author JIAL
 * @Date 2024/3/5 12:57
 * @Version 1.0
 */
@RestController
@RequestMapping("/quote")

public class QuoteController extends BaseController {

    @Autowired
    QuoteService quoteService;

    /**
     * @title queryMaterialListByParam
     * @description 获取物料列表
     * @author JIAL
     * @param: precMaterialName
     * @param: vagueMaterialName
     * @param: vagueModel
     * @updateTime 2024/3/11 10:56
     * @return: com.ruoyi.common.core.page.TableDataInfo
     */
    @DataSource(DataSourceType.QUOT)
    @PostMapping("/materialList")
    public TableDataInfo queryMaterialListByParam(@RequestParam("precMaterialName") String precMaterialName,
                                                  @RequestParam("vagueMaterialName") String vagueMaterialName,
                                                  @RequestParam("vagueModel") String vagueModel) {
        startPage();
        logger.info(precMaterialName + vagueMaterialName + vagueModel);
        List<MaterialDto> materialDtos = quoteService.queryMaterialListByParam(precMaterialName,
                vagueMaterialName, vagueModel);

        System.out.println("打通接口");
        return getDataTable(materialDtos);
    }

    /**
     * @title queryRedBookPriceByParam
     * @description 计算物料红本价格
     * @author JIAL
     * @param: params
     * @updateTime 2024/3/11 10:56
     */
    @DataSource(DataSourceType.QUOT)
    @PostMapping("/redBCost")
    public AjaxResult queryRedBCostByParams(@RequestBody List<CalculateRBParamDto> params) {
        List<CalculateRBParamDto> calculateRBParamDtoList = quoteService.queryRedBCostByParams(params);
        logger.info("查询结果： {}", calculateRBParamDtoList);
        return success(calculateRBParamDtoList);
    }

    /**
     * @title queryRedBPriceByParams
     * @description 获取红本价格
     * @author JIAL
     * @param: params
     * @updateTime 2024/3/12 10:33
     * @return: com.ruoyi.common.core.domain.AjaxResult
     */
    @DataSource(DataSourceType.QUOT)
    @PostMapping("/redBPrice")
    public AjaxResult queryRedBPriceByParams(@RequestBody List<CalculateRBParamDto> params) {
        List<CalculateRBParamDto> calculateRBParamDtoList = quoteService.queryRedBPriceByParams(params);
        logger.info("查询结果： {}", calculateRBParamDtoList);
        return success(calculateRBParamDtoList);
    }

    /**
     * @title queryRedBookVersion
     * @description 获取红本版本号
     * @author JIAL
     * @updateTime 2024/3/11 11:24
     * @return: com.ruoyi.common.core.domain.AjaxResult
     */
    @DataSource(DataSourceType.REDBOOK)
    @PostMapping("/redBookVer")
    public AjaxResult queryRedBookVersion() {
        return success(quoteService.queryRedBookVer());
    }

    /**
     * @title queryRedBookLocalVersion
     * @description 获取本地红本版本号
     * @author JIAL
     * @updateTime 2024/3/13 12:54
     * @return: com.ruoyi.common.core.domain.AjaxResult
     */
    @DataSource(DataSourceType.QUOT)
    @PostMapping("/redBookLocalVer")
    public AjaxResult queryRedBookLocalVersion() {
        return success(quoteService.queryRedBookLocalVer());
    }


}
