package com.yem.tws.common1;

//import json.JSONArray;
//import json.JSONObject;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * json工具类
 */
public class JsonUtils {

    /**
     * 根据关务单据注册将json报文转换为业务对象
     *
     * @param json       json报文
     * @param entityName 业务对象标识
     * @return
     */
    public static DynamicObject jsonToData(String json, String entityName, DynamicObject[] yem_ca_billlogon_s, String entryId, JSONObject preDecHeadVo) {
        DynamicObject bill = null;
        try {
            JSONObject data = JSONObject.parseObject(json);
//            JSONObject jsonObj = JSONObject.parseObject(json);
//            String code = jsonObj.getString("code");
//            JSONObject result = jsonObj.getJSONObject("result");
//            boolean ok = result.getBoolean("ok");
//            if (!ok) {
//                return null;
//            }
//            JSONObject data = result.getJSONObject("data");
//            JSONObject preDecHeadVo = data.getJSONObject("preDecHeadVo");
//            boolean needEdit = data.getBoolean("needEdit");

            bill = BusinessDataServiceHelper.newDynamicObject(entityName);
            if (null != yem_ca_billlogon_s && yem_ca_billlogon_s.length > 0) {
                DynamicObject yem_ca_billlogon = yem_ca_billlogon_s[0];
                yem_ca_billlogon = BusinessDataServiceHelper.loadSingle(yem_ca_billlogon.getPkValue(), "yem_ca_billlogon");
                DynamicObjectCollection yem_entitycontainer_s = yem_ca_billlogon.getDynamicObjectCollection("yem_entitycontainer");
                if (null != yem_entitycontainer_s && yem_entitycontainer_s.size() > 0) {
                    //判断billno是否已在系统存在
                    for (int i = 0; i < yem_entitycontainer_s.size(); i++) {
                        DynamicObject yem_entitycontainer = yem_entitycontainer_s.get(i);
                        String yem_entitytype = yem_entitycontainer.getString("yem_entitytype");//实体类型
                        String yem_jsonformid = yem_entitycontainer.getString("yem_jsonformid");//json标识
                        if ("A".equals(yem_entitytype)) {
//                            JSONObject headData = data.getJSONObject(yem_jsonformid);
                            JSONObject headData = JSONObject.parseObject(data.getString(yem_jsonformid));
                            if (headData.containsKey("billno")) {
                                String billno = headData.getString("billno");
                                QFilter qFilter1 = new QFilter("yem_formid.number", QCP.equals, entityName);
                                DynamicObject[] bill_s = BusinessDataServiceHelper.load(entityName,
                                        "id,billno,billstatus", new QFilter[]{qFilter1}, null);
                                if (null != bill_s && bill_s.length > 0) {
                                    bill = bill_s[0];
                                    bill = BusinessDataServiceHelper.loadSingle(bill.getPkValue(), bill.getDynamicObjectType().getName());
                                }
                            }
                        }
                    }

                    Map entry_map = new HashMap();
                    for (int i = 0; i < yem_entitycontainer_s.size(); i++) {
                        DynamicObject yem_entitycontainer = yem_entitycontainer_s.get(i);
                        String yem_entitytype = yem_entitycontainer.getString("yem_entitytype");//实体类型
                        String yem_entityformid = yem_entitycontainer.getString("yem_entityformid");//容器标识
                        String yem_parentcontainer = yem_entitycontainer.getString("yem_parentcontainer");//父级容器
                        String yem_jsonformid = yem_entitycontainer.getString("yem_jsonformid");//json标识
                        boolean yem_issubentry = yem_entitycontainer.getBoolean("yem_issubentry");//是否子分录
                        String yem_entryformid = yem_entitycontainer.getString("yem_entryformid");//分录标识
                        DynamicObjectCollection yem_entityfieldcol_s = yem_entitycontainer.getDynamicObjectCollection("yem_entityfieldcol");
                        if (null != yem_entityfieldcol_s && yem_entityfieldcol_s.size() > 0) {
                            if ("A".equals(yem_entitytype)) {//判断实体类型为单据头还是单据体  其中单据头为【A】，单据体为【B】
//                                JSONObject headData = data.getJSONObject(yem_jsonformid);
                                JSONObject headData = JSONObject.parseObject(data.getString(yem_jsonformid));
                                for (int j = 0; j < yem_entityfieldcol_s.size(); j++) {
                                    DynamicObject yem_entityfieldcol = yem_entityfieldcol_s.get(j);
                                    String yem_erpfiledformid = yem_entityfieldcol.getString("yem_erpfiledformid");//ERP字段标识
                                    String yem_filedtype = yem_entityfieldcol.getString("yem_filedtype");//字段类型
                                    String yem_jsonfieldid = yem_entityfieldcol.getString("yem_jsonfieldid");//json字段标识
                                    String yem_defaultvalue = yem_entityfieldcol.getString("yem_defaultvalue");//默认值
                                    String yem_modledefaultvalue = yem_entityfieldcol.getString("yem_modledefaultvalue");//动态默认
                                    String yem_identifierbasic = yem_entityfieldcol.getString("yem_identifierbasic");//定义基础数据唯一标识
                                    String yem_filedtypename = yem_entityfieldcol.getString("yem_filedtypename");//字段类型名称
                                    String val = "";
                                    //优先判断是否有默认值，有默认值的情况不需要配置json字段标识
                                    if (StringUtils.isNotEmpty(yem_defaultvalue)) {//判断配置的默认值是否为空
                                        val = yem_defaultvalue;
                                    } else {
                                        if (headData.containsKey(yem_jsonfieldid)) {//判断jsom中之后包含配置的json标识
                                            //配置中默认值为空并且动态默认也为空 则 根据字段类型赋值，类型有（基础资料、日期、文本、下拉列表、数值，单据类型，）
                                            val = headData.getString(yem_jsonfieldid);
                                        } else {
                                            //json报文不存在标识，记录ERP日志
//                                            if (StringUtils.isNotEmpty(yem_jsonfieldid)) {
//                                                String description = "当前Json中不存在" + yem_jsonfieldid + "标识，请修改后重试！";
//                                                CusLog(false, description, entryId, headData);
////                                                bill = null;
//                                            }
                                        }
                                    }
                                    if ("basedata".equals(yem_filedtype)) {
                                        bill.set(yem_erpfiledformid, getObjDynamicObject(yem_filedtypename, yem_identifierbasic, val));
                                    } else if ("datetime".equals(yem_filedtype) || "date".equals(yem_filedtype)) {
                                        if (StringUtils.isNotEmpty(val) && val.indexOf("-") != -1) {
                                            bill.set(yem_erpfiledformid, DateUtils.formatDate(val, "yyyy-MM-dd"));
                                        } else if (StringUtils.isNotEmpty(val) && val.indexOf("-") == -1 && !val.contains("AM") && !val.contains("PM")) {
                                            bill.set(yem_erpfiledformid, DateUtils.formatDate(val, "yyyyMMdd"));
                                        } else if (StringUtils.isNotEmpty(val) && CheckFormat(val)) {
                                            bill.set(yem_erpfiledformid, DateUtils.formatDate(val, "yyyy-MM-dd HH:mm:ss"));
                                        } else if (StringUtils.isNotEmpty(val) && val.indexOf(",") != -1 && (val.contains("AM") || val.contains("PM"))) {
                                            bill.set(yem_erpfiledformid, DateUtils.formatDateLocale(val, "MMM dd, yyyy hh:mm:ss"));
                                        }
                                    } else if ("number".equals(yem_filedtype)) {
                                        bill.set(yem_erpfiledformid, BigDecimalUtils.toBigDecimal(val));
                                    } else {
                                        bill.set(yem_erpfiledformid, val);
                                    }
                                    //暂时写死
                                    if ("auditor".equals(yem_erpfiledformid)) {
                                        bill.set(yem_erpfiledformid, CommonUtils.getCurrentUser());
                                    }
                                    if ("auditdate".equals(yem_erpfiledformid)) {
                                        bill.set(yem_erpfiledformid, new Date());
                                    }
                                    if ("modifier".equals(yem_erpfiledformid)) {
                                        bill.set(yem_erpfiledformid, CommonUtils.getCurrentUser());
                                    }
                                    if ("creator".equals(yem_erpfiledformid)) {
                                        bill.set(yem_erpfiledformid, CommonUtils.getCurrentUser());
                                    }
                                }
                            } else {
                                if (StringUtils.isNotEmpty(yem_parentcontainer)) {//父级容器
                                    String yem_entityformid_p = "";
                                    String yem_jsonformid_p = "";
                                    for (int k = 0; k < yem_entitycontainer_s.size(); k++) {//循环实体容器
                                        DynamicObject yem_entitycontainer_l = yem_entitycontainer_s.get(k);
                                        String yem_entityformid_l = yem_entitycontainer_l.getString("yem_entityformid");//容器标识
                                        String yem_jsonformid_l = yem_entitycontainer_l.getString("yem_jsonformid");//json标识
                                        if (StringUtils.isNotEmpty(yem_parentcontainer) && StringUtils.isNotEmpty(yem_entityformid_l) && yem_parentcontainer.equals(yem_entityformid_l)) {
                                            yem_entityformid_p = yem_entityformid_l;
                                            yem_jsonformid_p = yem_jsonformid_l;
                                        }
                                    }

                                    DynamicObjectCollection entry_s = bill.getDynamicObjectCollection(yem_entityformid_p);
                                    if (entry_map.containsKey(yem_entityformid_p)) {
                                        List index_s = (List) entry_map.get(yem_entityformid_p);
                                        for (int k = 0; k < index_s.size(); k++) {
                                            int index = new Integer(index_s.get(k).toString());
                                            DynamicObject entry = entry_s.get(index);
                                            DynamicObjectCollection detail_s = entry.getDynamicObjectCollection(yem_entityformid);
                                            JSONArray detailData_s = null;
                                            if (yem_issubentry) {//是否子分录
                                                JSONArray entryData_s = data.getJSONArray(yem_jsonformid_p);
                                                JSONObject entryData = entryData_s.getJSONObject(k);
                                                detailData_s = entryData.getJSONArray(yem_jsonformid);
                                            } else {
                                                detailData_s = data.getJSONArray(yem_jsonformid);
                                            }
                                            for (int m = 0; m < detailData_s.size(); m++) {
                                                JSONObject detailData = detailData_s.getJSONObject(m);
                                                DynamicObject detail = detail_s.addNew();
                                                for (int j = 0; j < yem_entityfieldcol_s.size(); j++) {
                                                    DynamicObject yem_entityfieldcol = yem_entityfieldcol_s.get(j);
                                                    String yem_erpfiledformid = yem_entityfieldcol.getString("yem_erpfiledformid");//ERP字段标识
                                                    String yem_filedtype = yem_entityfieldcol.getString("yem_filedtype");//字段类型
                                                    String yem_jsonfieldid = yem_entityfieldcol.getString("yem_jsonfieldid");//json字段标识
                                                    String yem_defaultvalue = yem_entityfieldcol.getString("yem_defaultvalue");//默认值
                                                    String yem_modledefaultvalue = yem_entityfieldcol.getString("yem_modledefaultvalue");//动态默认
                                                    String yem_identifierbasic = yem_entityfieldcol.getString("yem_identifierbasic");//定义基础数据唯一标识
                                                    String yem_filedtypename = yem_entityfieldcol.getString("yem_filedtypename");//字段类型名称

                                                    String val = "";
                                                    //优先判断是否有默认值，有默认值的情况不需要配置json字段标识
                                                    if (StringUtils.isNotEmpty(yem_defaultvalue)) {//判断配置的默认值是否为空
                                                        val = yem_defaultvalue;
                                                    } else {
                                                        if (detailData.containsKey(yem_jsonfieldid)) {//判断jsom中之后包含配置的json标识
                                                            //配置中默认值为空并且动态默认也为空 则 根据字段类型赋值，类型有（基础资料、日期、文本、下拉列表、数值，单据类型，）
                                                            val = detailData.getString(yem_jsonfieldid);
                                                        } else {
                                                            //json报文不存在标识，记录ERP日志
//                                                            if (StringUtils.isNotEmpty(yem_jsonfieldid)) {
//                                                                String description = "当前Json中不存在" + yem_jsonfieldid + "标识，请修改后重试！";
//                                                                CusLog(false, description, entryId, detailData);
////                                                                bill = null;
//                                                            }
                                                        }
                                                    }
                                                    if ("basedata".equals(yem_filedtype)) {
                                                        detail.set(yem_erpfiledformid, getObjDynamicObject(yem_filedtypename, yem_identifierbasic, val));
                                                    } else if ("datetime".equals(yem_filedtype) || "date".equals(yem_filedtype)) {
                                                        if (StringUtils.isNotEmpty(val) && val.indexOf("-") != -1) {
                                                            bill.set(yem_erpfiledformid, DateUtils.formatDate(val, "yyyy-MM-dd"));
                                                        } else if (StringUtils.isNotEmpty(val) && val.indexOf("-") == -1 && !val.contains("AM") && !val.contains("PM")) {
                                                            bill.set(yem_erpfiledformid, DateUtils.formatDate(val, "yyyyMMdd"));
                                                        } else if (StringUtils.isNotEmpty(val) && CheckFormat(val)) {
                                                            bill.set(yem_erpfiledformid, DateUtils.formatDate(val, "yyyy-MM-dd HH:mm:ss"));
                                                        } else if (StringUtils.isNotEmpty(val) && val.indexOf(",") != -1 && (val.contains("AM") || val.contains("PM"))) {
                                                            bill.set(yem_erpfiledformid, DateUtils.formatDateLocale(val, "MMM dd, yyyy hh:mm:ss"));
                                                        }
                                                    } else if ("number".equals(yem_filedtype)) {
                                                        detail.set(yem_erpfiledformid, BigDecimalUtils.toBigDecimal(val));
                                                    } else {
                                                        detail.set(yem_erpfiledformid, val);
                                                    }

                                                }
                                            }
                                        }
                                    }
                                } else {
                                    DynamicObjectCollection entry_s = bill.getDynamicObjectCollection(yem_entityformid);
//                                JSONArray entryData_s = data.getJSONArray(yem_jsonformid);
                                    //20230506 zhouc Modify
                                    JSONArray entryData_s = null;
                                    if (yem_entryformid.length() > 0) {
                                        JSONObject jsonObject = JSONObject.parseObject(preDecHeadVo.getString(yem_entryformid));
                                        if (jsonObject != null) {
                                            if (jsonObject.get(yem_jsonformid) instanceof JSONObject) {
                                                JSONArray jsonArray =  new JSONArray();
                                                jsonArray.add(jsonObject.getJSONObject(yem_jsonformid));
                                                entryData_s = jsonArray;
                                            } else {
                                                entryData_s = JSONObject.parseArray(jsonObject.getString(yem_jsonformid));
                                            }
                                        }
                                    } else {
                                        entryData_s = JSONObject.parseArray(preDecHeadVo.getString(yem_jsonformid));
                                    }
                                    if (entryData_s != null) {
                                        for (int k = 0; k < entryData_s.size(); k++) {
                                            JSONObject entryData = entryData_s.getJSONObject(k);
                                            DynamicObject entry = entry_s.addNew();
                                            for (int j = 0; j < yem_entityfieldcol_s.size(); j++) {
                                                DynamicObject yem_entityfieldcol = yem_entityfieldcol_s.get(j);
                                                String yem_erpfiledformid = yem_entityfieldcol.getString("yem_erpfiledformid");//ERP字段标识
                                                String yem_filedtype = yem_entityfieldcol.getString("yem_filedtype");//字段类型
                                                String yem_jsonfieldid = yem_entityfieldcol.getString("yem_jsonfieldid");//json字段标识
                                                String yem_defaultvalue = yem_entityfieldcol.getString("yem_defaultvalue");//默认值
                                                String yem_modledefaultvalue = yem_entityfieldcol.getString("yem_modledefaultvalue");//动态默认
                                                String yem_identifierbasic = yem_entityfieldcol.getString("yem_identifierbasic");//定义基础数据唯一标识
                                                String yem_filedtypename = yem_entityfieldcol.getString("yem_filedtypename");//字段类型名称

                                                String val = "";

                                                //优先判断是否有默认值，有默认值的情况不需要配置json字段标识
                                                if (StringUtils.isNotEmpty(yem_defaultvalue)) {//判断配置的默认值是否为空
                                                    val = yem_defaultvalue;
                                                } else {
                                                    if (entryData.containsKey(yem_jsonfieldid)) {//判断jsom中之后包含配置的json标识
                                                        //配置中默认值为空并且动态默认也为空 则 根据字段类型赋值，类型有（基础资料、日期、文本、下拉列表、数值，单据类型，）
                                                        val = entryData.getString(yem_jsonfieldid);
                                                    } else {
                                                        //json报文不存在标识，记录ERP日志
//                                                        if (StringUtils.isNotEmpty(yem_jsonfieldid)) {
//                                                            String description = "当前Json中不存在" + yem_jsonfieldid + "标识，请修改后重试！";
//                                                            CusLog(false, description, entryId, entryData);
////                                                            bill = null;
//                                                        }
                                                    }
                                                }
                                                if (val.length() > 0) {
                                                    if ("basedata".equals(yem_filedtype)) {
                                                        entry.set(yem_erpfiledformid, getObjDynamicObject(yem_filedtypename, yem_identifierbasic, val));
                                                    } else if ("datetime".equals(yem_filedtype) || "date".equals(yem_filedtype)) {
                                                        if (StringUtils.isNotEmpty(val) && val.indexOf("-") != -1) {
                                                            bill.set(yem_erpfiledformid, DateUtils.formatDate(val, "yyyy-MM-dd"));
                                                        } else if (StringUtils.isNotEmpty(val) && val.indexOf("-") == -1 && !val.contains("AM") && !val.contains("PM")) {
                                                            bill.set(yem_erpfiledformid, DateUtils.formatDate(val, "yyyyMMdd"));
                                                        } else if (StringUtils.isNotEmpty(val) && CheckFormat(val)) {
                                                            bill.set(yem_erpfiledformid, DateUtils.formatDate(val, "yyyy-MM-dd HH:mm:ss"));
                                                        } else if (StringUtils.isNotEmpty(val) && val.indexOf(",") != -1 && (val.contains("AM") || val.contains("PM"))) {
                                                            bill.set(yem_erpfiledformid, DateUtils.formatDateLocale(val, "MMM dd, yyyy hh:mm:ss"));
                                                        }
                                                    } else if ("number".equals(yem_filedtype)) {
                                                        entry.set(yem_erpfiledformid, BigDecimalUtils.toBigDecimal(val));
                                                    } else {
                                                        entry.set(yem_erpfiledformid, val);
                                                    }
                                                }
                                                if (entry_map.containsKey(yem_entityformid)) {
                                                    List index_s = (List) entry_map.get(yem_entityformid);
                                                    index_s.add(entry_s.size() - 1);
                                                    entry_map.put(yem_entityformid, index_s);
                                                } else {
                                                    List index_s = new ArrayList();
                                                    index_s.add(entry_s.size() - 1);
                                                    entry_map.put(yem_entityformid, index_s);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    //最后统一处理动态默认字段逻辑
                    for (int i = 0; i < yem_entitycontainer_s.size(); i++) {
                        DynamicObject yem_entitycontainer = yem_entitycontainer_s.get(i);
                        DynamicObjectCollection yem_entityfieldcol_s = yem_entitycontainer.getDynamicObjectCollection("yem_entityfieldcol");
                        String yem_entitytype = yem_entitycontainer.getString("yem_entitytype");//实体类型
                        String yem_entityformid = yem_entitycontainer.getString("yem_entityformid");//容器标识
                        if (null != yem_entityfieldcol_s && yem_entityfieldcol_s.size() > 0) {
                            if ("A".equals(yem_entitytype)) {//判断实体类型为单据头还是单据体  其中单据头为【A】，单据体为【B】
                                for (int j = 0; j < yem_entityfieldcol_s.size(); j++) {
                                    DynamicObject yem_entityfieldcol = yem_entityfieldcol_s.get(j);
                                    String yem_erpfiledformid = yem_entityfieldcol.getString("yem_erpfiledformid");//ERP字段标识
                                    String yem_jsonfieldid = yem_entityfieldcol.getString("yem_jsonfieldid");//json字段标识
                                    String yem_modledefaultvalue = yem_entityfieldcol.getString("yem_modledefaultvalue");//动态默认
                                    if (StringUtils.isNotEmpty(yem_modledefaultvalue)) {//判断配置动态默认是否为空
                                        bill.set(yem_erpfiledformid, DyDataUtils.getDyData(bill, yem_modledefaultvalue, yem_jsonfieldid));
                                    }
                                }
                            } else {
                                String yem_parentcontainer = yem_entitycontainer.getString("yem_parentcontainer");//父级容器
                                if (StringUtils.isNotEmpty(yem_parentcontainer)) {//父级容器
                                    String yem_entityformid_p = "";
                                    for (int k = 0; k < yem_entitycontainer_s.size(); k++) {//循环实体容器
                                        DynamicObject yem_entitycontainer_l = yem_entitycontainer_s.get(k);
                                        String yem_entityformid_l = yem_entitycontainer_l.getString("yem_entityformid");//容器标识
                                        if (StringUtils.isNotEmpty(yem_parentcontainer) && StringUtils.isNotEmpty(yem_entityformid_l) && yem_parentcontainer.equals(yem_entityformid_l)) {
                                            yem_entityformid_p = yem_entityformid_l;
                                        }
                                    }
                                    DynamicObjectCollection entry_s = bill.getDynamicObjectCollection(yem_entityformid_p);
                                    for (int n = 0; n < entry_s.size(); n++) {
                                        DynamicObject entry = entry_s.get(n);
                                        DynamicObjectCollection detail_s = entry.getDynamicObjectCollection(yem_entityformid);
                                        for (int m = 0; m < detail_s.size(); m++) {
                                            DynamicObject detail = detail_s.get(m);
                                            for (int j = 0; j < yem_entityfieldcol_s.size(); j++) {
                                                DynamicObject yem_entityfieldcol = yem_entityfieldcol_s.get(j);
                                                String yem_erpfiledformid = yem_entityfieldcol.getString("yem_erpfiledformid");//ERP字段标识
                                                String yem_jsonfieldid = yem_entityfieldcol.getString("yem_jsonfieldid");//json字段标识
                                                String yem_modledefaultvalue = yem_entityfieldcol.getString("yem_modledefaultvalue");//动态默认
                                                String yem_filedtypename = yem_entityfieldcol.getString("yem_filedtypename");//字段类型
                                                if (StringUtils.isNotEmpty(yem_modledefaultvalue)) {//判断配置动态默认是否为空
                                                    detail.set(yem_erpfiledformid, DyDataUtils.getDyDataEntry(detail, yem_modledefaultvalue, yem_jsonfieldid, yem_filedtypename));
                                                }
                                            }
                                        }
                                    }
                                } else {
                                    DynamicObjectCollection entry_s = bill.getDynamicObjectCollection(yem_entityformid);
                                    for (int m = 0; m < entry_s.size(); m++) {
                                        DynamicObject entry = entry_s.get(m);
                                        for (int j = 0; j < yem_entityfieldcol_s.size(); j++) {
                                            DynamicObject yem_entityfieldcol = yem_entityfieldcol_s.get(j);
                                            String yem_erpfiledformid = yem_entityfieldcol.getString("yem_erpfiledformid");//ERP字段标识
                                            String yem_jsonfieldid = yem_entityfieldcol.getString("yem_jsonfieldid");//json字段标识
                                            String yem_modledefaultvalue = yem_entityfieldcol.getString("yem_modledefaultvalue");//动态默认
                                            String yem_filedtypename = yem_entityfieldcol.getString("yem_filedtypename");//字段类型名称
                                            if (StringUtils.isNotEmpty(yem_modledefaultvalue)) {//判断配置动态默认是否为空
                                                entry.set(yem_erpfiledformid, DyDataUtils.getDyDataEntry(entry, yem_modledefaultvalue, yem_jsonfieldid, yem_filedtypename));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            //获取到错误，记录错误日志
            String description = e.getMessage();
            CusLog(false, description, entryId, JSONObject.parseObject(json));
            bill = null;
        }
        return bill;
    }

    /**
     * 根据编码/名称查询基础资料
     *
     * @param yem_filedtypename
     * @param yem_identifierbasic
     * @param filterVal
     * @return obj
     */
    public static DynamicObject getObjDynamicObject(String yem_filedtypename, String yem_identifierbasic, String filterVal) {
        DynamicObject obj = null;
        if (StringUtils.isNotEmpty(yem_filedtypename) && StringUtils.isNotEmpty(filterVal)) {
            QFilter filter = new QFilter(yem_identifierbasic, QCP.equals, filterVal);
            obj = BusinessDataServiceHelper.loadSingle(yem_filedtypename, "id,name,number", new QFilter[]{filter});
        }
        return obj;
    }

    public static void CusLog(Boolean BollISSucces, String description, String billno, JSONObject jsonObj) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        resultMap.put("description", description);
        resultMap.put("result", BollISSucces);
        resultMap.put("billno", billno);
        String opdesc = "将中国国际贸易单一窗口同步至单一窗口报关单";
        ApilogUtils.Createlog(resultMap, billno, "单一窗口报关单", opdesc, "AddCusDec", jsonObj);
    }

    public static boolean CheckFormat(String str) {
        boolean falg = false;
        DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date date = formatter.parse(str);
            falg = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return falg;
    }


}
