查询指定时间段内的所有数据的金额总数和对应的数据列表

 
  
  //这是查询时间段内的所有数据的金额总数
  public
JSONArray statistics(Date stateTime,Date endTime) throws CRUDException, ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); if(stateTime==null){ //判断是否给出指定时间段 Cath tempCath = cathMapper.findMin();   //查询数据库中第一条处理的数据 stateTime = tempCath.getDateTime(); //如果没给开始时间,就将数据库中最开始那一条数据的处理时间赋值给开始时间 } if(endTime==null){ endTime = new Date(); //如果没给截止时间,就将当前时间赋值给截止时间 } String sTime = sdf.format(stateTime); String eTime = sdf.format(endTime); CashierType cashierType = new CashierType(); List<CashierType> typeList = cashierTypeMapper.findAll(cashierType); JSONArray jsonArray = new JSONArray(); //简单的json,没什么好说的 for(CashierType temp : typeList){ JSONObject tempObj = new JSONObject(); tempObj.put("payId", temp.getId()); tempObj.put("stateTime", sTime); tempObj.put("endTime", eTime); tempObj.put("payType", temp.getName()); tempObj.put("sumTotal", cathMapper.statistics(temp.getId(),sTime,eTime)); //统计时间段内所有数据的金额总数 jsonArray.add(tempObj); } return jsonArray; }
 
  
  //这是查询对应的数据列表
  public
List<Cath> findDetails(String stateTime,String endTime,Cath cath) throws CRUDException{ try{ List<Cath> cList = cathMapper.findList(cath); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); Date staTime = sdf.parse(stateTime); Date enTime = sdf.parse(endTime); int sTime = Integer.parseInt(sdf.format(staTime)); int eTime = Integer.parseInt(sdf.format(enTime)); if(sTime>eTime){ //比较传进来的两个时间大小 int temp = 0; temp = sTime; sTime = eTime; eTime = temp; } List<Cath> delList = new ArrayList<Cath>(); //这是clist.removeAll(delList)中移除的list for(Cath temp : cList){ int cathTime = Integer.parseInt(sdf.format(temp.getDateTime())); if(cathTime<sTime||cathTime>eTime){ //数据中的处理时间不在传进来的两个时间之间,就把这条数据放在移除的list中 delList.add(temp); } } cList.removeAll(delList); //将cList中和delList数据一样的移除出cList ,这样得到的cList就是我们需要的list集合了 return cList; }catch(Exception e){ e.printStackTrace(); return null; } }

一开始查找的结果:

点击详情查看对应的数据:

输出时间段然后查找的结果:

同样的查看他的对应数据:

 

附上对应的sql:

  <!-- 数据统计 -->
    <select id="statistics" resultType="Integer">
        select COALESCE(sum(t.money),0) from T_CATH t
        <where>
            t.DATE_TIME between to_date(#{param2},'yyyy-mm-dd') and to_date(#{param3},'yyyy-mm-dd') //在之前已经给两个时间赋值,所以可以不用判断是否为空
            <if test="param1 != null and param1 != ''">
            AND t.PAYMENT_TYPE = #{param1,jdbcType=VARCHAR}
            </if>
        </where>
    </select>
    
    <!-- 查询第一个处理的数据 -->
    <select id="findMin" resultType="com.seeyoui.kensite.elder.finance.cath.domain.Cath">
        select <include refid="tableColumns"/>
        from T_CATH T where T.DATE_TIME = (select min(c.date_time) from t_cath c )
    </select>
    
    <!-- 查询数据集合 -->
    <select id="findList" resultType="com.seeyoui.kensite.elder.finance.cath.domain.Cath">
        select * from(select T.*,rownum rn from(
            SELECT
            <include refid="tableColumns"/>
            FROM T_CATH T
            <include refid="whereStr"/>
            <include refid="orderBy"/>
        ) T WHERE rownum &lt; = #{page}*#{rows}) where rn &gt; (#{page}-1)*#{rows}
    </select>

 

转载于:https://www.cnblogs.com/dnf1612/p/7099802.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值