package cn.estsh.i3plus.pojo.softswitch.sqlpack;

import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import cn.estsh.i3plus.pojo.base.tool.HqlPack;
import cn.estsh.i3plus.pojo.softswitch.bean.*;

/**
 * @Description :
 * @Reference :
 * @Author : Adair Peng
 * @CreateDate : 2019-02-28 16:05
 * @Modify:
 **/
public class SoftSwitchHqlPack {

    /**
     * In 参数封装
     * @param columnName
     * @return
     */
    public static String packHqlIds(String columnName,String[] params){
        StringBuffer result =  new StringBuffer();

        // 参数数组 [1,2,3] -> "1,2,3"
        HqlPack.getInPack(String.join(",",params),columnName,result);
        return result.toString();
    }

    /**
     * 目录查询封装
     * @param testDataBase
     * @return
     */
    public static String packHqlTestDataBase(TestDataBase testDataBase){
        StringBuffer result = new StringBuffer();

        // 查询参数封装
//        HqlPack.getStringLikerPack(testDataBase.getName(),"name",result);

        return result.toString();
    }

    /**
     * 适配套件参数条件封装
     * @param bsSuitCaseParam 查询条件
     * @return
     */
    public static DdlPackBean packHqlBsSuitCaseParam(BsSuitCaseParam bsSuitCaseParam){
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();

        DdlPreparedPack.getStringLikerPack(bsSuitCaseParam.getParamName(),"paramName",ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsSuitCaseParam.getParamTypeId(), "paramTypeId", ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsSuitCaseParam.getSuitCaseId(), "suitCaseId", ddlPackBean);
        DdlPreparedPack.getStringEqualPack(bsSuitCaseParam.getSuitCaseCodeRdd(),"suitCaseCodeRdd",ddlPackBean);

        ddlPackBean.setOrderByStr(bsSuitCaseParam.orderBy());

        return ddlPackBean;
    }

    /**
     * 适配套件参数唯一校验
     * @param bsSuitCaseParam 适配套件参数信息
     * @return
     */
    public static DdlPackBean packHqlCheckBsSuitCaseParamOnly(BsSuitCaseParam bsSuitCaseParam){
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();

        DdlPreparedPack.getNumNOEqualPack(bsSuitCaseParam.getId(),"id",ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsSuitCaseParam.getSuitCaseId(), "suitCaseId", ddlPackBean);
        DdlPreparedPack.getStringEqualPack(bsSuitCaseParam.getParamName(),"paramName",ddlPackBean);

        return ddlPackBean;
    }

    /**
     * 适配套件条件封装
     * @param bsSuitCase 查询条件
     * @return
     */
    public static DdlPackBean packHqlBsSuitCase(BsSuitCase bsSuitCase){
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();

        DdlPreparedPack.getStringLikerPack(bsSuitCase.getSuitCaseName(),"suitCaseName",ddlPackBean);
        DdlPreparedPack.getStringLikerPack(bsSuitCase.getSuitCaseCode(),"suitCaseCode",ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsSuitCase.getSuitTypeId(), "suitTypeId", ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsSuitCase.getCaseTypeId(), "caseTypeId", ddlPackBean);

        ddlPackBean.setOrderByStr(bsSuitCase.orderBy());

        return ddlPackBean;
    }

    /**
     * 适配套件唯一校验
     * @param bsSuitCase 适配套件信息
     * @return
     */
    public static DdlPackBean packHqlCheckBsSuitCaseOnly(BsSuitCase bsSuitCase){
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();

        DdlPreparedPack.getNumNOEqualPack(bsSuitCase.getId(),"id",ddlPackBean);
        DdlPreparedPack.getStringEqualPack(bsSuitCase.getSuitCaseCode(), "suitCaseCode", ddlPackBean);

        return ddlPackBean;
    }

    /**
     * 数据适配转换规则查询条件封装
     * @param bsParamAdapter 数据适配转换规则
     * @return
     */
    public static DdlPackBean packHqlBsParamAdapter(BsParamAdapter bsParamAdapter){
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();

        DdlPreparedPack.getNumEqualPack(bsParamAdapter.getSuitCaseId(),"suitCaseId",ddlPackBean);
        DdlPreparedPack.getStringEqualPack(bsParamAdapter.getSuitCaseCode(),"suitCaseCode",ddlPackBean);
        DdlPreparedPack.getStringLikerPack(bsParamAdapter.getSuitParamNameRdd(), "suitParamNameRdd", ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsParamAdapter.getSuitParamTypeId(), "suitParamTypeId", ddlPackBean);

        ddlPackBean.setOrderByStr(bsParamAdapter.orderBy());

        return ddlPackBean;
    }

    /**
     * 数据适配装换规则唯一校验
     * @param bsParamAdapter 数据适配转换规则
     * @return
     */
    public static DdlPackBean packHqlCheckBsParamAdapterOnly(BsParamAdapter bsParamAdapter){
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();

        DdlPreparedPack.getNumEqualPack(bsParamAdapter.getId(), "id", ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsParamAdapter.getSuitCaseId(), "suitCaseId", ddlPackBean);
        DdlPreparedPack.getStringEqualPack(bsParamAdapter.getSuitCaseCode(), "suitCaseCode", ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsParamAdapter.getSuitParamId(), "suitParamId", ddlPackBean);

        return ddlPackBean;
    }

    /**
     * 定时适配任务查询条件封装
     * @param bsSuitSchedule 查询条件
     * @return
     */
    public static DdlPackBean packHqlBsSuitSchedule(BsSuitSchedule bsSuitSchedule){
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();

        DdlPreparedPack.getStringLikerPack(bsSuitSchedule.getScheduleName(),"scheduleName",ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsSuitSchedule.getSuitCaseId(),"suitCaseId",ddlPackBean);
        DdlPreparedPack.getStringLikerPack(bsSuitSchedule.getSuitCaseNameRdd(),"suitCaseNameRdd",ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsSuitSchedule.getTaskCycleId(),"taskCycleId",ddlPackBean);

        ddlPackBean.setOrderByStr(bsSuitSchedule.orderBy());

        return ddlPackBean;
    }

    /**
     * 定时适配任务唯一校验
     * @param bsSuitSchedule
     * @return
     */
    public static DdlPackBean packHqlCheckBsSuitScheduleOnly(BsSuitSchedule bsSuitSchedule){
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();

        DdlPreparedPack.getNumNOEqualPack(bsSuitSchedule.getId(),"id",ddlPackBean);
        DdlPreparedPack.getStringEqualPack(bsSuitSchedule.getScheduleName(),"scheduleName",ddlPackBean);
        DdlPreparedPack.getStringEqualPack(bsSuitSchedule.getScheduleGroupName(),"scheduleGroupName",ddlPackBean);

        return ddlPackBean;
    }

    /**
     * 适配认证查询条件分页
     * @param bsSslKey 查询条件
     * @return
     */
    public static DdlPackBean packHqlBsSslKey(BsSslKey bsSslKey){
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();

        DdlPreparedPack.getStringEqualPack(bsSslKey.getKeyName(),"keyName",ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsSslKey.getKeyTypeId(),"keyTypeId",ddlPackBean);

        ddlPackBean.setOrderByStr(bsSslKey.orderBy());

        return ddlPackBean;
    }

    /**
     * 适配认证唯一校验
     * @param bsSslKey
     * @return
     */
    public static DdlPackBean packHqlCheckBsSslKeyOnly(BsSslKey bsSslKey){
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();

        DdlPreparedPack.getNumEqualPack(bsSslKey.getId(),"id",ddlPackBean);
        DdlPreparedPack.getStringEqualPack(bsSslKey.getKeyName(), "keyName", ddlPackBean);

        return ddlPackBean;
    }

    /**
     * 适配认证参数按条件查询
     * @param bsSslKeyParam 查询条件
     * @return
     */
    public static DdlPackBean packHqlBsSslKeyParam(BsSslKeyParam bsSslKeyParam){
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();

        DdlPreparedPack.getNumEqualPack(bsSslKeyParam.getSslKeyId(), "sslKeyId", ddlPackBean);
        DdlPreparedPack.getStringLikerPack(bsSslKeyParam.getParamName(), "paramName", ddlPackBean);

        ddlPackBean.setOrderByStr(bsSslKeyParam.orderBy());

        return ddlPackBean;
    }

    /**
     * 适配认证参数唯一校验
     * @param bsSslKeyParam
     * @return
     */
    public static DdlPackBean packHqlCheckBsSslKeyParamOnly(BsSslKeyParam bsSslKeyParam){
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();

        DdlPreparedPack.getNumEqualPack(bsSslKeyParam.getSslKeyId(), "sslKeyId", ddlPackBean);
        DdlPreparedPack.getStringEqualPack(bsSslKeyParam.getParamName(), "paramName", ddlPackBean);

        return ddlPackBean;
    }

    /**
     * 数据源查询条件封装
     * @param bsDataSource
     * @return
     */
    public static DdlPackBean packHqlBsDataSource(BsDataSource bsDataSource){
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();

        DdlPreparedPack.getStringLikerPack(bsDataSource.getDataSourceName(), "dataSourceName", ddlPackBean);
        DdlPreparedPack.getStringLikerPack(bsDataSource.getDataSourceCode(), "dataSourceCode", ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsDataSource.getDataSourceTypeId(), "dataSourceTypeId", ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsDataSource.getDataSourceStatus(), "dataSourceStatus", ddlPackBean);

        ddlPackBean.setOrderByStr(bsDataSource.orderBy());

        return ddlPackBean;
    }

    /**
     * 数据源唯一校验
     * @param bsDataSource
     * @return
     */
    public static DdlPackBean packHqlCheckBsDataSourceOnly(BsDataSource bsDataSource){
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();

        DdlPreparedPack.getNumEqualPack(bsDataSource.getId(), "id", ddlPackBean);
        DdlPreparedPack.getStringEqualPack(bsDataSource.getDataSourceCode(), "dataSourceCode", ddlPackBean);

        return ddlPackBean;
    }

    /**
     * 数据源适配操作查询条件封装
     * @param bsSuitCaseDataSourceTable
     * @return
     */
    public static DdlPackBean packHqlBsSuitCaseDataSourceTable(BsSuitCaseDataSourceTable bsSuitCaseDataSourceTable){
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();

        DdlPreparedPack.getNumEqualPack(bsSuitCaseDataSourceTable.getSuitCaseId(),"suitCaseId",ddlPackBean);
        DdlPreparedPack.getStringLikerPack(bsSuitCaseDataSourceTable.getOperateName(),"operateName",ddlPackBean);

        bsSuitCaseDataSourceTable.setOrderByParam("operateSort");
        bsSuitCaseDataSourceTable.setAscOrDesc(CommonEnumUtil.ASC_OR_DESC.DESC.getValue());
        ddlPackBean.setOrderByStr(bsSuitCaseDataSourceTable.orderBy());

        return ddlPackBean;
    }

    /**
     * 数据适配操作操作唯一校验
     * @param bsSuitCaseDataSourceTable
     * @return
     */
    public static DdlPackBean packHqlCheckBsSuitCaseDataSourceTableOnly(BsSuitCaseDataSourceTable bsSuitCaseDataSourceTable){
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();

        DdlPreparedPack.getNumNOEqualPack(bsSuitCaseDataSourceTable.getId(), "id", ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsSuitCaseDataSourceTable.getSuitCaseId(), "suitCaseId", ddlPackBean);
        DdlPreparedPack.getStringEqualPack(bsSuitCaseDataSourceTable.getOperateName(), "operateName", ddlPackBean);

        return ddlPackBean;
    }

    /**
     * WebService 唯一校验
     * @param webService
     * @return
     */
    public static DdlPackBean packHqlCheckWebService(BsSuitCaseWebService webService){
        DdlPackBean result = DdlPackBean.getDdlPackBean();

        return result;
    }

    /**
     * 适配记录查询条件封装
     * @param bsSuitRecord
     * @return
     */
    public static DdlPackBean packHqlBsSuitRecord(BsSuitRecord bsSuitRecord){
        DdlPackBean ddlPackBean = new DdlPackBean();

        DdlPreparedPack.getInPackList(bsSuitRecord.getSearchIdList(),"id",ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsSuitRecord.getSuitCaseId(),"suitCaseId",ddlPackBean);
        DdlPreparedPack.getStringLikerPack(bsSuitRecord.getSuitSid(),"suitSid",ddlPackBean);
        DdlPreparedPack.getStringLikerPack(bsSuitRecord.getSuitCaseNameRdd(),"suitCaseNameRdd",ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsSuitRecord.getSuitTypeId(),"suitTypeId",ddlPackBean);
        DdlPreparedPack.getStringLikerPack(bsSuitRecord.getSuitCaseCode(),"suitCaseCode",ddlPackBean);
        DdlPreparedPack.getStringLikerPack(bsSuitRecord.getScriptResult(),"scriptResult",ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsSuitRecord.getProcessState(),"processState",ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsSuitRecord.getSuitCaseId(),"suitCaseId",ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsSuitRecord.getCaseTypeId(),"caseTypeId",ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsSuitRecord.getSuitResult(),"suitResult",ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsSuitRecord.getProcessState(), "processState", ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsSuitRecord.getRequestSource(), "requestSource", ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsSuitRecord.getRetryRecordId(), "retryRecordId", ddlPackBean);
        DdlPreparedPack.timeBuilder(bsSuitRecord.getSuitStartTime(), "suitStartTime", ddlPackBean, false, true);
        DdlPreparedPack.timeBuilder(bsSuitRecord.getCreateDatetime(), "createDatetime", ddlPackBean, false, true);
        ddlPackBean.setOrderByStr(bsSuitRecord.orderBy());

        return ddlPackBean;
    }

    /**
     * 适配记录查询条件封装
     * @return
     */
    public static DdlPackBean packHqlBsSuitDataDetail(BsSuitDataDetail bsSuitDataDetail){
        DdlPackBean ddlPackBean = new DdlPackBean();

        DdlPreparedPack.getInPackList(bsSuitDataDetail.getSearchIdList(),"id",ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsSuitDataDetail.getSuitCaseId(),"suitCaseId",ddlPackBean);
        DdlPreparedPack.getStringLikerPack(bsSuitDataDetail.getSuitCaseCodeRdd(),"suitCaseCodeRdd",ddlPackBean);
        DdlPreparedPack.getStringLikerPack(bsSuitDataDetail.getSuitCaseNameRdd(),"suitCaseNameRdd",ddlPackBean);
        DdlPreparedPack.getStringLikerPack(bsSuitDataDetail.getSuitTypeNameRdd(),"suitTypeNameRdd",ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsSuitDataDetail.getCaseTypeId(), "caseTypeId", ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsSuitDataDetail.getProcessState(),"processState",ddlPackBean);
        DdlPreparedPack.timeBuilder(bsSuitDataDetail.getGetDateTime(), "getDateTime", ddlPackBean, false, true);
        DdlPreparedPack.timeBuilder(bsSuitDataDetail.getProcessTime(), "processTime", ddlPackBean, false, true);
        DdlPreparedPack.timeBuilder(bsSuitDataDetail.getCreateDatetime(), "createDatetime", ddlPackBean, false, true);

        ddlPackBean.setOrderByStr(bsSuitDataDetail.orderBy());

        return ddlPackBean;
    }


    /**
     * 适配记录查询条件封装
     * @return
     */
    public static DdlPackBean packHqlBsSuitRequestRecord(BsSuitRequestRecord bsSuitRequestRecord){
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean(bsSuitRequestRecord);

        DdlPreparedPack.getInPackList(bsSuitRequestRecord.getSearchIdList(),"id",ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsSuitRequestRecord.getSuitCaseId(),"suitCaseId",ddlPackBean);
        DdlPreparedPack.timeBuilder(bsSuitRequestRecord.getCreateDatetime(), "createDatetime", ddlPackBean, false, true);

        return ddlPackBean;
    }

    /**
     * 适配文件条件封装
     * @param bsSuitFile 查询条件
     * @return
     */
    public static DdlPackBean packHqlBsSuitCaseFile(BsSuitFile bsSuitFile){
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();

        DdlPreparedPack.getStringLikerPack(bsSuitFile.getSuitCaseNameRdd(),"suitCaseNameRdd",ddlPackBean);
        DdlPreparedPack.getStringLikerPack(bsSuitFile.getSuitCaseCode(),"suitCaseCode",ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsSuitFile.getSuitCaseId(), "suitCaseId", ddlPackBean);
        DdlPreparedPack.getStringLikerPack(bsSuitFile.getFileName(), "fileName", ddlPackBean);
        DdlPreparedPack.getStringLikerPack(bsSuitFile.getFolderPath(), "folderPath", ddlPackBean);
        DdlPreparedPack.timeBuilder(bsSuitFile.getSuitDateTime(), "suitDateTime", ddlPackBean, false, true);

        ddlPackBean.setOrderByStr(bsSuitFile.orderBy());

        return ddlPackBean;
    }

    public static DdlPackBean packHqlSuitDataDetailBySuitCaseCodeAndProcessState(String suitCaseCode, Integer processState){
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();

        DdlPreparedPack.getStringEqualPack(suitCaseCode,"suitCaseCodeRdd",ddlPackBean);
        DdlPreparedPack.getNumEqualPack(processState,"processState",ddlPackBean);

        DdlPreparedPack.getOrderByPack(new Object[]{CommonEnumUtil.ASC_OR_DESC.DESC.getValue()},new String[]{"getDateTime"},ddlPackBean);

        return ddlPackBean;
    }


    public static DdlPackBean packHqlBsSuitRecordParam(BsSuitRecordParam bsSuitRecordParam){
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();

        DdlPreparedPack.getNumEqualPack(bsSuitRecordParam.getSuitRecordId(),"suitRecordId",ddlPackBean);

        return ddlPackBean;
    }

    public static DdlPackBean packHqlBsLongData(BsLongData bsLongData){
        DdlPackBean ddlPackBean  = DdlPackBean.getDdlPackBean(bsLongData);
        DdlPreparedPack.timeBuilder(bsLongData.getCreateDatetime(), "createDatetime", ddlPackBean, false, true);
        DdlPreparedPack.getNumEqualPack(bsLongData.getRefDataType(),"refDataType",ddlPackBean);
        DdlPreparedPack.getStringLikerPack(bsLongData.getData(),"data",ddlPackBean);
        return ddlPackBean;
    }

    public static DdlPackBean packHqlBsBusiScript(BsBusiScript bsBusiScript){
        DdlPackBean ddlPackBean  = DdlPackBean.getDdlPackBean(bsBusiScript);
        DdlPreparedPack.getStringLikerPack(bsBusiScript.getScriptName(),"scriptName",ddlPackBean);
        DdlPreparedPack.getStringLikerPack(bsBusiScript.getScriptCode(),"scriptCode",ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsBusiScript.getScriptType(),"scriptType",ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bsBusiScript.getRefId(),"refId",ddlPackBean);
        return ddlPackBean;
    }

    public static DdlPackBean packHqlCheckSuitFile(BsSuitFile bsSuitFile){
        DdlPackBean ddlPackBean  = DdlPackBean.getDdlPackBean(bsSuitFile);
        DdlPreparedPack.getNumEqualPack(bsSuitFile.getSuitCaseId(), "suitCaseId", ddlPackBean);
        DdlPreparedPack.getStringEqualPack(bsSuitFile.getFileName(),"fileName",ddlPackBean);
        DdlPreparedPack.getStringEqualPack(bsSuitFile.getFolderPath(),"folderPath",ddlPackBean);
        DdlPreparedPack.getNumNOEqualPack(bsSuitFile.getId(),"id",ddlPackBean);
        return ddlPackBean;
    }
}
