java 多表连接查询模板实现类的实例

java 多表连接查询模板实现类的实例,第1张

public List listAccuDtlData(List accountingUnitIDs, List mtrlIDs, List energyNodeTypeIDs,
                                         List inOutPutIDs, CalendarType reportTypeId, Date beginTime, Date endTime) {

    if (CollectionUtil.isEmpty(mtrlIDs)) {
        return new ArrayList<>();
    }
    Boolean energyNodeTypeIDsIsNotEmpty = CollectionUtil.isNotEmpty(energyNodeTypeIDs);
    Boolean inOutPutIDsIsNotEmpty = CollectionUtil.isNotEmpty(inOutPutIDs);

    String hql = "select data from AccuDtlData data"
            + " where data.accuUnit.accuId in ( :accountingUnitIDs )"
            + " and data.mtrl.id in ( :mtrlIDs )"
            + " and data.begTime=:beginTime"
            + " and data.endTime=:endTime";
    if (energyNodeTypeIDsIsNotEmpty) {
        hql += " and data.energyNodeType.id in ( :energyNodeTypeIDs )";
    }
    if (inOutPutIDsIsNotEmpty) {
        hql += " and data.eoInOutTypeInfo.id in ( :inOutPutIDs )";
    }

    List> sqlParams = new ArrayList<>();
    List sqlParam = new ArrayList<>();
    sqlParams.add(new SqlParams("accountingUnitIDs", accountingUnitIDs));
    sqlParams.add(new SqlParams("mtrlIDs", mtrlIDs));

    sqlParam.add(new Condition("beginTime", beginTime));
    sqlParam.add(new Condition("endTime", endTime));

    if (energyNodeTypeIDsIsNotEmpty) {
        sqlParams.add(new SqlParams("energyNodeTypeIDs", energyNodeTypeIDs));
    }
    if (inOutPutIDsIsNotEmpty) {
        sqlParams.add(new SqlParams("inOutPutIDs", inOutPutIDs));

    }

    List resultList = factoryService.selectFactoryHql(hql, sqlParams, sqlParam, AccuDtlData.class);
    List accuDtlDatas = new ArrayList<>();
    if (CollUtil.isNotEmpty(resultList)) {
        JSONArray jsonArray = new JSONArray();
        jsonArray.addAll(resultList);
        accuDtlDatas = jsonArray.toJavaList(AccuDtlData.class);
    }
    return accuDtlDatas;

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/876449.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-13
下一篇 2022-05-13

发表评论

登录后才能评论

评论列表(0条)

保存