package com.yem.wm.im.transferorder.op;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yem.wm.utils.RequestEAS;
import com.yem.wm.utils.YunzhijiaUtils;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.ExtendedDataEntity;
import kd.bos.entity.operate.result.OperationResult;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.PreparePropertysEventArgs;
import kd.bos.entity.plugin.args.AfterOperationArgs;
import kd.bos.entity.plugin.args.BeforeOperationArgs;
import kd.bos.entity.plugin.args.EndOperationTransactionArgs;
import kd.bos.entity.validate.ErrorLevel;
import kd.bos.entity.validate.ValidationErrorInfo;
import kd.bos.exception.KDBizException;
import kd.bos.exception.KDException;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.QueryServiceHelper;
import kd.bos.servicehelper.operation.OperationServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.fi.ai.util.BigdecimalUtil;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

public class TransFerOrderAuditOp extends AbstractOperationServicePlugIn {
    @Override
    public void onPreparePropertys(PreparePropertysEventArgs e) {
        e.getFieldKeys().add("billno");
        e.getFieldKeys().add("yem_bizdate");
        e.getFieldKeys().add("yem_supfinorg.number");
        e.getFieldKeys().add("yem_supstockorg.number");
        e.getFieldKeys().add("yem_cusfinorg.number");
        e.getFieldKeys().add("yem_cusstockorg.number");
        e.getFieldKeys().add("yem_currency.number");
        e.getFieldKeys().add("yem_exrate");
        e.getFieldKeys().add("yem_includingtax");
        e.getFieldKeys().add("yem_amount");
        e.getFieldKeys().add("yem_amountbase");
        e.getFieldKeys().add("yem_businessdirection");
        e.getFieldKeys().add("yem_es_materialinfo.yem_pricetax");
        e.getFieldKeys().add("yem_es_materialinfo.yem_price");
        e.getFieldKeys().add("yem_es_materialinfo.yem_amttax");
        e.getFieldKeys().add("yem_es_materialinfo.yem_amt");
        e.getFieldKeys().add("yem_es_materialinfo.yem_amounttax");
        e.getFieldKeys().add("yem_es_materialinfo.yem_realityprice");
        e.getFieldKeys().add("yem_es_materialinfo.yem_realitypricetax");
        e.getFieldKeys().add("yem_es_materialinfo.yem_locamt");
        e.getFieldKeys().add("yem_es_materialinfo.yem_amountfield1");
        e.getFieldKeys().add("yem_es_materialinfo.yem_baseamttax");
        e.getFieldKeys().add("yem_es_materialinfo.yem_taxrate");
        e.getFieldKeys().add("yem_es_materialinfo.yem_qty");
        e.getFieldKeys().add("yem_es_materialinfo.yem_impactprice");
        e.getFieldKeys().add("yem_es_materialinfo");
        e.getFieldKeys().add("yem_es_materialinfo.yem_gift");
        e.getFieldKeys().add("yem_gift");
        e.getFieldKeys().add("yem_isextprice");
        e.getFieldKeys().add("yem_businesssort");
        super.onPreparePropertys(e);
    }

    @Override
    public void endOperationTransaction(EndOperationTransactionArgs e) {
        super.endOperationTransaction(e);
    }

    @Override
    public void afterExecuteOperationTransaction(AfterOperationArgs e) {
        super.afterExecuteOperationTransaction(e);
    }

    @Override
    public void beforeExecuteOperationTransaction(BeforeOperationArgs e) {
        super.beforeExecuteOperationTransaction(e);

    }
//    }

    private static void addErrMessage(OperationResult operationResult, ExtendedDataEntity dataEntity, String errMsg) {

        Object pkId = dataEntity.getDataEntity().getPkValue();
        int dataIndex = dataEntity.getDataEntityIndex();
        int rowIndex = 0;
        ErrorLevel errorLevel = ErrorLevel.Info;

        ValidationErrorInfo errInfo = new ValidationErrorInfo("",
                pkId, dataIndex, rowIndex,
                "BeforeExecuteOperationTransactionSample",
                "获取调拨价格失败",
                errMsg,
                errorLevel);

        operationResult.addErrorInfo(errInfo);
    }

    private JSONObject setJson(String key, String value) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put(key, value);
        return jsonObject;
    }
}
