package com.ag.test;

import com.ag.account.service.FeeController;
import com.ag.entity.fee.face.ICondition;
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.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yangxh on 2019/8/24.
 */
public class LocalTestByShip {

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

    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring/dubbo-provider.xml");
        FeeController fee = context.getBean(FeeController.class);
        ReqSource reqSource = new ReqSource();
        LocalTestByShip.generateData(reqSource);

        //String req = "{\"accountPointCode\":\"02\",\"contractId\":\"67e28d2715684d6e8db0eb77f86cc567\",\"operMan\":\"王楠\",\"sourceProperties\":[{\"bizId\":\"72372405-69ff-47a3-af0e-541e4d062427\",\"bizTime\":\"2019-08-29 10:19:44\",\"bizType\":\"02\",\"property\":{\"BILL_CALC\":\"1\",\"I_E_ID\":\"0\"},\"spare\":{}},{\"bizId\":\"72372405-69ff-47a3-af0e-541e4d062427\",\"bizTime\":\"2019-08-29 10:19:44\",\"bizType\":\"02\",\"property\":{\"MAIN_CNTR\":\"1\",\"quantity\":\"2\",\"I_E_ID\":\"0\",\"V_V_C_SIZE_DATA_FEE_FEE\":\"20\"},\"spare\":{}}],\"tenancyId\":\"01\"}";
        //String str = fee.callback(req);
        String str = fee.callback(JSON.toJSONString(reqSource));
        System.out.println(str);

        //fee.call(JSON.toJSONString(reqSource));
    }

    /**
     * 箱,票,拼箱比例费用计算(类舱单费)
     * @param reqSource
     */
    public 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("V_C_TYPE_DATA_FEE", "FR");
        cntrMap.put("V_C_SIZE_DATA_FEE", "20");
        cntrMap.put("CARGO_KIND_CODE", "E");
        cntrMap.put("I_E_ID", "I");
        cntrMap.put("BILL_TYPE", "C");
        cntrMap.put("MAIN_CNTR", "1");
        cntrMap.put("TRANS_TYPE", "11");
        cntrMap.put("TRADE_ID", "2");
        cntrMap.put("TYPE", "2");
        cntrMap.put(ICondition.LIN_ID, "营运人CODE");
        cntrMap.put(ICondition.CAR_AGE, "车队code");
        cntr.setProperty(cntrMap);
        String json =
                "{\"contractId\":\"38d0362f69824db8b9c9853e72dec930\",\"itemId\":\"001\",\"operMan\":\"admin\",\"sourceProperties\":[{\"property\":{\"C_CARGO_NAM\":\"HB\",\"TRADE_ID\":\"1\"},\"spare\":{}}]}";
        //箱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(ICondition.weight, 800);
        cntrMap2.put("CARGO_CODE", "HB");
        cntrMap2.put("TRADE_ID", "2");
        cntr2.setProperty(cntrMap2);

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


}
