package com.ag.account.feeUtil;

import com.ag.entity.account.FeeDetail;
import com.ag.entity.fee.ItemProperties;
import com.ag.entity.fee.TariffRitem;
import com.ag.entity.fee.face.ICondition;
import com.ag.entity.fee.face.IRuleCondition;
import com.ag.entity.fee.face.SourceProperty;
import com.ag.entity.fee.vo.ContractItemVO;
import com.ag.entity.fee.vo.TariffVO;
import com.ag.util.StrUtil;
import com.alibaba.fastjson.JSONObject;

import java.util.List;

/**
 * Created by Administrator on 2017-12-01.
 */
public class NotesUtil {

    /*public static String setDataProperty(IProperty property){
        String msg = "";
        if (!StrUtil.isEmpty(property.getTradeId())){
            msg = StrUtil.join(msg, "内外贸=",property.getTradeId());
        }
        if (!StrUtil.isEmpty(property.getiEId())){
            msg = StrUtil.join(msg, ",进出口标记=",property.getiEId());
        }
        if (!StrUtil.isEmpty(property.getCntrSize())){
            msg = StrUtil.join(msg, ",箱尺寸=",property.getCntrSize());
        }
        if (!StrUtil.isEmpty(property.geteFId())){
            msg = StrUtil.join(msg, ",空重标记=",property.geteFId());
        }
        if (!StrUtil.isEmpty(property.getCntrType())){
            msg = StrUtil.join(msg, ",货物属性=",property.getCntrType());
        }
        if (!StrUtil.isEmpty(property.getWorkWay())){
            msg = StrUtil.join(msg, ",作业类型=",property.getWorkWay());
        }
        if (!StrUtil.isEmpty(property.getFeiAddress())){
            msg = StrUtil.join(msg, ",计费区域=",property.getFeiAddress());
        }
        if (!StrUtil.isEmpty(property.getCarProperty())){
            msg = StrUtil.join(msg, ",车辆性质=",property.getCarProperty());
        }
        if (!StrUtil.isEmpty(property.getPol())){
            msg = StrUtil.join(msg, ",装货港=",property.getPol());
        }
        if (!StrUtil.isEmpty(property.getPod())){
            msg = StrUtil.join(msg, ",卸货港=",property.getPod());
        }
        if (!StrUtil.isEmpty(property.getService())){
            msg = StrUtil.join(msg, ",进口航线=", property.getService());
        }
        if (!StrUtil.isEmpty(property.getOservice())){
            msg = StrUtil.join(msg, ",出口航线=", property.getOservice());
        }
        if (!StrUtil.isEmpty(property.getCntrOperatorCod())){
            msg = StrUtil.join(msg, ",驳船公司=", property.getCntrOperatorCod());
        }
        if (!StrUtil.isEmpty(property.getsAdress())){
            msg = StrUtil.join(msg, ",送货地址=", property.getsAdress());
        }
        if (!StrUtil.isEmpty(property.getColineCod())){
            msg = StrUtil.join(msg, ",合作船公司=", property.getColineCod());
        }
        if (!StrUtil.isEmpty(property.getSettelType())){
            msg = StrUtil.join(msg, ",货主结算类型=", property.getSettelType());
        }
        if (!StrUtil.isEmpty(property.getTransit())){
            msg = StrUtil.join(msg, ",贸易方式=", property.getTransit());
        }
        if (!StrUtil.isEmpty(property.getShipConsignCod())){
            msg = StrUtil.join(msg, ",货主=", property.getShipConsignCod());
        }
        if (!StrUtil.isEmpty(property.getGoodsNotes())){
            msg = StrUtil.join(msg, ",货物名称=", property.getGoodsNotes());
        }
        if (!StrUtil.isEmpty(property.getiEICustomer())){
            msg = StrUtil.join(msg, ",进口货主=", property.getiEICustomer());
        }
        if (!StrUtil.isEmpty(property.getVainRun())){
            msg = StrUtil.join(msg, ",是否空跑=", property.getVainRun());
        }
        if (!StrUtil.isEmpty(property.getPtType())){
            msg = StrUtil.join(msg, ",派车方式=", property.getPtType());
        }
        if(!StrUtil.isEmpty(property.getIsJk())){
            msg = StrUtil.join(msg, ",是否借靠=", property.getIsJk());
        }
        if (property.getMainFlag() != null){
            msg = StrUtil.join(msg, ",主单标志=", property.getMainFlag());
        }
        if (property.getSplitId() != null){
            msg = StrUtil.join(msg, ",是否夹柜=", property.getSplitId());
        }

        return msg;
    }*/


    public static void setFeeByTariffScription(FeeDetail detail, SourceProperty source) {
        TariffVO tariffVO = source.getTariffVO();
        List<TariffRitem> ritemList = tariffVO.getRitemList();
        List<ItemProperties> properties = ((ContractItemVO) source.getContractItem()).getItemProperties();
        JSONObject property = source.getProperty();
        String description = "";
        for (ItemProperties itemProp : properties){
            for (IRuleCondition ritem : ritemList) {
                if (ICondition.RATE.equals(ritem.getKeyName())) {
                    continue;
                }
                if (itemProp.getPropertyCode().equals(ritem.getKeyName())){
                    description = StrUtil.join(description, getProperyDescription(ritem.getKeyName(), property));
//                    description = StrUtil.join(description, property.getString(ritem.getKeyName()), ",");
                    break;
                }
            }
        }
        detail.setTariffDescription(description);
    }

    private static String getProperyDescription(String keyName, JSONObject property){
        if (StrUtil.isEmpty(property.getString(keyName))){
            return "";
        }
        if ("V_C_SIZE_DATA_FEE".equals(keyName)){
            return property.getString(keyName)+"'";
        }
        if ("E_F_IDCODE".equals(keyName)){
            return property.getString(keyName);
        }
        if ("TRANS_FLAG_FEE".equals(keyName)){
            return property.getString(keyName);
        }
        if ("TAKEOVER_PROXY_FEE".equals(keyName)){
            return property.getString(keyName);
        }

        return property.getString(keyName)+",";
    }
}
