const system = require("../../../system");
const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings");

class NeedinfoService extends ServiceBase {
    constructor() {
        super("aggregation", ServiceBase.getDaoName(NeedinfoService));
        this.execClient = system.getObject("util.execClient");
    }
    //推送聚合页需求至蜂擎
    async pushAggregationNeedInfo2fq(ab){
        if(!ab || !ab.id){
            return ;
        }
        var needinfo = await this.dao.model.findOne({
            where:{
                id:ab.id,
                push_status:0
            },
            raw:true
        });
        if(!needinfo || !needinfo.id || !needinfo.business_id || !needinfo.contact_mobile){
            return ;
        }
        var pobj={
                "customer_name": needinfo.contact_name || "未知",
                "customer_phone": needinfo.contact_mobile,
                "customer_region": "全国",
                "demand_list": [{
                    "product_id": needinfo.business_id,
                    "region": "全国"
                }],
                "remark": needinfo.original_need,
                "source_keyword":needinfo.channel_name,
                "source": "媒体聚合页"
        };
        console.log(pobj,"pobj###########################2");
        var pushRes = await this.fqUtilsSve.pushMediaNeedInfo2Fq(pobj);
        console.log(pushRes,"pushRes############################3");
        if(pushRes && pushRes.data && pushRes.code && pushRes.code=="200" && pushRes.success ){//推送成功
            await this.dao.update({id:needinfo.id,push_status:1});
        }else{
            await this.dao.update({id:needinfo.id,push_status:2});
        }
    }
    
}

module.exports = NeedinfoService;