package com.yem.wm.syn.eas.submit.utils;

import com.yem.wm.utils.RequestEAS;
import com.yem.wm.utils.YEM;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;

import java.util.List;
import java.util.Map;
import java.util.Objects;

public class FilterUtils {

    /**
     * 客户财务信息查询
     *
     * @param org      组织
     * @param customer 客户
     * @return
     */
    public static Boolean setCustomer(DynamicObject org, DynamicObject customer) {

        if (YEM.isNotEmpty(org) && YEM.isNotEmpty(customer)) {
            QFilter qFilter1 = new QFilter("createorg.id", QCP.equals, org.getPkValue());
            QFilter qFilter2 = new QFilter("yem_customer.id", QCP.equals, customer.getPkValue());
            qFilter1.and(qFilter2);
            QFilter[] qFilters = new QFilter[]{qFilter1};
            DynamicObject customercompany = BusinessDataServiceHelper.loadSingle("yem_customercompanyinfo", qFilters);
            if (Objects.isNull(customercompany)) {
                return true;
            }
        }
        return false;
    }

    public static Boolean setMaterial(DynamicObject org, DynamicObject material) {

        QFilter qFilter1 = new QFilter("createorg.id", QCP.equals, org.getPkValue());
        QFilter qFilter2 = new QFilter("yem_material.id", QCP.equals, material.getPkValue());
        qFilter1.and(qFilter2);
        QFilter[] qFilters = new QFilter[]{qFilter1};
        DynamicObject materialCompany = BusinessDataServiceHelper.loadSingle("yem_materialcompanyinfo", qFilters);
        if (Objects.isNull(materialCompany)) {
            return true;
        }
        return false;
    }

    public static String getUserNumber(String number) {
        String sql = "SELECT count(1) FROM T_PM_USER where fnumber = '" + number + "'; ";
        List<Map<String, Object>> list = RequestEAS.exeSql(sql);
        if (Integer.parseInt(list.get(0).get("count(1)").toString())!=0) {
            list.get(0).get("count(1)");
            return number;
        } else {
            return "COSMIC";
        }
    }
}
