package com.ag.demo;

import com.ag.dynamicmodule.main.HotApplicationContext;
import com.ag.entity.fee.face.ICondition;
import com.ag.entity.fee.face.IFeeBase;
import com.ag.entity.fee.face.ReqSource;
import com.ag.entity.fee.face.SourceProperty;
import com.ag.util.TimeUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by yangxh on 2022/1/5.
 */
@Service
public class AutoCalcTest {

    private static final String bizType = "MACH";
    private static final String itemIds = "001";
    private static final String contractId = "ccb1deff1086449d87106a6478f34ca4";

    public void execute(org.json.JSONObject param, HttpServletResponse response, HttpServletRequest request){
        IFeeBase feeBase = (IFeeBase) HotApplicationContext.getBean("feeController");
        ReqSource reqSource = new ReqSource();
        generateData(reqSource);
        System.out.println(JSON.toJSONString(reqSource));
        String res = feeBase.callback(JSON.toJSONString(reqSource));
        System.out.println(res);
    }

    /**
     * 箱,票,拼箱比例费用计算(类舱单费)
     * @param reqSource
     */
    private static void generateData(ReqSource reqSource){

        List<SourceProperty> sources = new ArrayList<>();
        //票
        String mainId  = "8f548bf59afa4440b86636c10ba";
        SourceProperty bill = new SourceProperty();
        sources.add(bill);
        bill.setBizId(mainId);
        bill.setBizTime(TimeUtil.getDateTime());
        bill.setBizType(bizType);
        JSONObject billMap = new JSONObject();
        billMap.put("BILL_CALC", "1");
        billMap.put(ICondition.LIN_ID, "营运人code");
        billMap.put(ICondition.CAR_AGE, "车队code");
        bill.setProperty(billMap);

        //箱1
        String bizId = "8f548bf59afa4440b86636c10ba31547";
        SourceProperty cntr = new SourceProperty();
        sources.add(cntr);
        cntr.setBizId(bizId);
        cntr.setBizTime(TimeUtil.getDateTime());
        cntr.setBizType(bizType);
        JSONObject cntrMap = new JSONObject();
        cntrMap.put("TRADE_ID", "1");
        cntrMap.put("CNTR_SIZE", "40");
        cntrMap.put("I_E_ID", "I");
        cntrMap.put("TYPE", "1");
        cntr.setProperty(cntrMap);
        //箱2
        String bizId2 = "8f548bf59afa4440b86636c10ba31";
        SourceProperty cntr2 = new SourceProperty();
        sources.add(cntr2);
        cntr2.setBizId(bizId2);
        cntr2.setBizTime(TimeUtil.getDateTime());
        cntr2.setBizType(bizType);
        JSONObject cntrMap2 = new JSONObject();
        cntrMap2.put("TRADE_ID", "1");
        cntrMap2.put("CNTR_SIZE", "40");
        cntrMap2.put("I_E_ID", "I");
        cntrMap2.put("TYPE", "2");
        cntr2.setProperty(cntrMap2);

        reqSource.setSourceProperties(sources);
        reqSource.setTenancyId("default");
        reqSource.setOperMan("yxh");
        reqSource.setContractId(contractId);
//        reqSource.setItemId(itemIds);
        reqSource.setAccountPointCode(bizType);
    }
}
