package com.hai.config;

import com.alibaba.fastjson.JSONObject;
import com.hai.entity.BsProductConfig;
import com.hai.entity.BsProductDiscount;
import com.hai.service.ApiProductService;
import com.hai.service.BsConfigService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;

/**
 * @author hurui
 * @version 1.0
 * @ClassName ThirdProductConfig
 * @description: 第三方接口配置文件
 * @date 2021/7/5 14:18
 */
@Component
public class ThirdProductConfig {

    @Resource
    private BsConfigService bsConfigService;

    @Resource
    private ApiProductService apiProductService;

    // 产品折扣比例
    public BigDecimal getProductConfigNum(Integer productType , Long companyId) {

        Map<String, Object> listMap = new HashMap<>();
        listMap.put("productType", productType);
        listMap.put("companyId", companyId);

        List<BsProductConfig> productConfigs = apiProductService.getProductConfig(listMap);

        if (productConfigs.size() > 0 ) {
            return productConfigs.get(0).getDiscount();
        }
        return  null;
    }

    // 产品折扣比例
    public BsProductConfig getProductConfig(Integer productType , Long companyId) {

        Map<String, Object> listMap = new HashMap<>();
        listMap.put("productType", productType);
        listMap.put("companyId", companyId);

        List<BsProductConfig> productConfigs = apiProductService.getProductConfig(listMap);

        if (productConfigs.size() > 0 ) {
            return productConfigs.get(0);
        }
        return  null;
    }

    public JSONObject getThirdPartyByDetail(Integer platformId , Integer productType , Long companyId) {
        BsProductConfig productConfig = getProductConfig(productType, companyId);

        JSONObject object = new JSONObject();

        Map<String, Object> listMap = new HashMap<>();
        listMap.put("productType", "5");
        listMap.put("returnType", 1);
        listMap.put("sourceId", productConfig.getId());
        listMap.put("platformId", platformId);

        object.put("integralDiscount" , bsConfigService.getProductDiscountByMap(listMap).getDiscount());
        object.put("priceDiscount" , productConfig.getDiscount());
        object.put("productPayType" , bsConfigService.getProductPayTypeByMap(listMap));
        object.put("productPlatform" , bsConfigService.getProductPlatformByMap(listMap));

        return object;
    }


}
