• 关于hibernate子查询参数的问题


    private Map<String, Object> createWblHqlContext(boolean needGroup, String startDate, String endDate) {
            Map<String, Object> context = new HashMap<String, Object>();
            // 构建hql
            StringBuilder hql = new StringBuilder();
            hql.append(this.createVaInfoWblDaySelectPart(startDate, endDate)).append(" ");

            hql.append("from WfjWbl t where 1=1 ");
            List<Object> params = new ArrayList<Object>();
            if (startDate.length() > 0) {
                hql.append(" and t.settlementDate >= ?");
                params.add(startDate);
            }
            if (endDate.length() > 0) {
                hql.append(" and t.settlementDate <= ?");
                params.add(endDate);
            }
            if (needGroup)
                hql.append(" ").append(this.createVaInfoWblDayGroupByPart());
            context.put("hql", hql.toString());
            context.put("params", params);
            return context;
        }

        // 构造select字段
        private String createVaInfoWblDaySelectPart(String startDate,String endDate) {
            StringBuilder sb = new StringBuilder();
            sb.append("select t.settlementDate,");// 清算日期
            sb.append("sum(t.amount)/100 ,"); // 清算交易金额
            sb.append("sum(t.amount)/100 ,"); // 交易笔数
            sb.append("sum(t.shopfee)/100 ,"); // 商户手续费
            sb.append("((sum(t.sdsy)/100-sum(t.advancefee)/100)) ,"); // 王府井入账金额
            sb.append("sum(t.sdsy)/100, "); // 收单收入
            sb.append("sum(t.wangsy)/100,"); // 王府井收入
            sb.append("sum(t.cjfsy)/100, "); // 插件方收入
            sb.append("sum(t.wangsh)/100, "); // 王府井损失
            sb.append("sum(t.cjfsh)/100 "); // 插件方损失
            sb.append("( ").append(this.createNoCardPayQueryThirdsySelectByPart())
            .append(this.createNoCardPayQueryThirdsyFromByPart(startDate, endDate))
            .append(" and t.mernum = '898110248990216'").append(this.createVaInfoWblDayGroupByPart()).append(") ");//代垫手续费(国美)
            

            return sb.toString();
        }

        // 构造group by字段
        private String createVaInfoWblDayGroupByPart() {
            StringBuilder sb = new StringBuilder();
            sb.append("group by t.settlementDate ");
            return sb.toString();
        }
        
        //构造sql查询代垫手续费,
        private String createNoCardPayQueryThirdsySelectByPart() {
            StringBuilder sb = new StringBuilder();
            sb.append("select sum(t.thirdsy)/100 ");
            return sb.toString();
        }

        //构造sql查询代垫手续费的from部分
        private String createNoCardPayQueryThirdsyFromByPart(String startDate, String endDate) {
            StringBuilder sb = new StringBuilder();
            sb.append("from WfjWbl t where 1=1 ");
            List<Object> params = new ArrayList<Object>();
            if (startDate.length() > 0) {
                sb.append(" and t.settlementDate >= ?");
                params.add(startDate);
            }
            if (endDate.length() > 0) {
                sb.append(" and t.settlementDate <= ?");
                params.add(endDate);
            }
            return sb.toString();
        }

    当添加红色部分内容时,页面就报org.springframework.orm.hibernate3.HibernateQueryException: unexpected token: ( near line 1, column 215 [select t.settlementDate,sum(t.amount)/100 ,sum(t.amount)/100 ,sum(t.shopfee)/100 ,((sum(t.sdsy)/100-sum(t.advancefee)/100)) ,sum(t.sdsy)/100, sum(t.wangsy)/100,sum(t.cjfsy)/100, sum(t.wangsh)/100, sum(t.cjfsh)/100 ( select sum(t.thirdsy)/100 from cn.net.wangfujing.model.WfjWbl t where 1=1 and t.settlementDate >= ? and t.settlementDate <= ? and t.mernum = '898110248990216'group by t.settlementDate ) from cn.net.wangfujing.model.WfjWbl t where 1=1 and t.settlementDate >= ? and t.settlementDate <= ? group by t.settlementDate

    求助!!!

  • 相关阅读:
    Android底层开发之红外遥控驱动移植
    OC的动态继承编译机制
    Android 的Recovery机制
    JStorm中的并行( parallelismction )介绍
    windows编译ffmpeg出现gcc is unable to create an executable file 的普通情况
    Yii2高速构建RESTful Web服务功能简单介绍
    APK防反编译技术
    Partition(hdu4651)2013 Multi-University Training Contest 5----(整数拆分一)
    JSP简单练习-上传文件
    ios+openflow 问题
  • 原文地址:https://www.cnblogs.com/lius1/p/4311160.html
Copyright © 2020-2023  润新知