算出租率报表:涉及时间的判断(jsp页面)
业务:新增出租率统计功能,仅适用于大厦7楼至31楼,每个月有一个出租率(出租面积/7至31楼的总面积),年终统计一个平均出租率(即每个月的出租率/12个月)
<%@page import="com.velcro.convert.util.DateUtils"%> <%@ page contentType="text/html; charset=UTF-8"%> <%@ include file="/vbase/init.jsp"%> <%@ page import="com.velcro.base.BaseContext" %> <%@ page import="java.net.URLDecoder"%> <%@ page import="java.util.Map"%> <%@ page import="java.util.regex.*"%> <%@ page import="java.math.BigDecimal"%> <%@ page import="com.velcro.base.util.StringHelper"%> <%@ page import="com.velcro.base.DataService"%> <%@ page import="com.velcro.km.util.*"%> <%@ page import="com.velcro.base.util.NumberHelper"%> <%@ page import="com.ctc.wstx.util.DataUtil" %> <%@ page import="cn.hutool.core.date.DateUtil" %> <%@ page import="cn.hutool.core.util.NumberUtil" %> <%@ page import="com.navi.utils.NumberUtils" %> <%@ page import="com.navi.dao.jdbc.IDataService" %> <%@ page import="org.apache.ecs.html.S" %> <%@ page import="com.velcro.convert.util.StringUtil" %> <%@ page import="com.sun.star.bridge.oleautomation.Decimal" %> <%@ page import="cn.hutool.core.collection.CollectionUtil" %> <%@ page import="com.navi.utils.StringUtils" %> <%@ page import="java.text.DecimalFormat" %> <% DataService dataService = (DataService) BaseContext.getBean(getServletContext(), "dataService"); String selectYear = StringHelper.null2String(request.getParameter("objnames1"));//获取选择年份 //年份的查询 %> <%--2022.3.10--%> <% IDataService dataServices=BaseContext.getBean("mobileDataService"); //获取出租数据的最早的年 String minYearSql=" select top 1 SUBSTRING(extdatefield1,0,5) from assets where objno like 'GDB%' and extdatefield1 is not null order by extdatefield1 asc"; String minYear=dataServices.getValue(minYearSql); //获取当前年 String nowYear = DateUtil.format(new Date(), "yyyy"); //把年份转化为int类型 int minYears = NumberUtils.objToInt(minYear, 2018); int maxYears = NumberUtils.objToInt(nowYear, 2022); //获取1-12个月 ListmonthLists=new ArrayList (); monthLists.add("01"); monthLists.add("02"); monthLists.add("03"); monthLists.add("04"); monthLists.add("05"); monthLists.add("06"); monthLists.add("07"); monthLists.add("08"); monthLists.add("09"); monthLists.add("10"); monthLists.add("11"); monthLists.add("12"); double sum=0; //粤财大厦7楼至31楼的总面积 String ycdsSql="select sum(extnumfield0) from assets where objno like 'GDB%' and extintfield0>=7 and extintfield0<=31 and isdelete=0"; String area =dataService.getValue(ycdsSql); double totalarea = NumberUtils.objToDouble(area, 0); //最早年到当前年 //年份 List int selectYears=0; if (StringUtils.isEmpty(selectYear)){ for ( int i=minYears ; i<=maxYears ;i++){ //月份 Map mapMonthData=new HashMap ();//每个月的出租率 List > newMonthRate=new ArrayList >();//每个月的出租率按月份进行重新排序 Double totalRate=0.0;//年总的出租率 for (String month:monthLists){ double czmj=0;//月份的面积总数 String czSql="select id,objname,extintfield0,extselectitemfield2,extnumfield0,extdatefield1,extdatefield2 from assets " + "where objno like 'GDB%' and extselectitemfield2='40288110301fdb1601301fedb6080096' and extintfield0>=7 and extintfield0<=31 and isdelete=0 \n" + "and extdatefield1<='"+i+"-"+month+"-31' and extdatefield2>='"+i+"-"+month+"-01' "; List > mapList = dataServices.getMapList(czSql); if (CollectionUtil.isEmpty(mapList)){ mapMonthData.put(StringUtil.obj2String(month),0); }else { //月数据不为空,面积相加 for (int j = 0; j < mapList.size(); j++) { Map map1 = (Map) mapList.get(j); String extnumfield0=StringHelper.null2String(map1.get("extnumfield0")); double mianji = Double.valueOf(extnumfield0); czmj=czmj+mianji; } } //这年每月的出租率:每个月有一个出租率(出租面积/7至31楼的总面积) Double rentalRate=0.0;//每月的出租率 //每个月的出租率换成百分比形式并且保留二位小数 rentalRate=(czmj/totalarea) * 100; DecimalFormat df = new DecimalFormat("#0.00"); String rateTow =df.format(rentalRate)+"%"; mapMonthData.put(StringUtil.obj2String(month),rateTow); totalRate +=rentalRate; //System.out.println(month+"月已出租的总面积:"+"======================"+czmj); } //年终统计一个平均出租率(即每个月的出租率/12个月) Double avgRate=totalRate/12;//平均出租率 DecimalFormat df = new DecimalFormat("#0.00"); String rateTow =df.format(avgRate)+"%"; mapMonthData.put(StringUtil.obj2String(13),rateTow); //进行重新按月份排序 List > list = new ArrayList >(mapMonthData.entrySet()); Collections.sort(list, new Comparator >() { public int compare(Map.Entry o1, Map.Entry o2) { return NumberHelper.string2Int(o1.getKey(),0) - NumberHelper.string2Int(o2.getKey(),0); } }); for(Map.Entry m: list){ Map MonthData=new HashMap ();//每个月的出租率 //newMonthRate.add(NumberHelper.string2Double(mapMonthData.get(m.getKey()),0)); MonthData.put("month",m.getKey()); MonthData.put("monthValue",m.getValue()); newMonthRate.add(MonthData); } //每年的数据 Map everyYear=new HashMap(); everyYear.put("year",i); everyYear.put("avgRate",avgRate); everyYear.put("newMonthRate",newMonthRate); RateYearData.add(everyYear); } }else { //传进年份 // int selectYears = NumberUtils.objToInt(selectYear, 2022); selectYears = NumberUtils.objToInt(selectYear, 2022); for ( int i=selectYears ; i<=selectYears ;i++){ //月份 Map mapMonthData=new HashMap ();//每个月的出租率 List > newMonthRate=new ArrayList >();//每个月的出租率按月份进行重新排序 Double totalRate=0.0;//年总的出租率 for (String month:monthLists){ double czmj=0;//月份的面积总数 String czSql="select id,objname,extintfield0,extselectitemfield2,extnumfield0,extdatefield1,extdatefield2 from assets " + "where objno like 'GDB%' and extselectitemfield2='40288110301fdb1601301fedb6080096' and extintfield0>=7 and extintfield0<=31 and isdelete=0 \n" + "and extdatefield1<='"+i+"-"+month+"-31' and extdatefield2>='"+i+"-"+month+"-01' "; List > mapList = dataServices.getMapList(czSql); if (CollectionUtil.isEmpty(mapList)){ mapMonthData.put(StringUtil.obj2String(month),0); }else { //月数据不为空,面积相加 for (int j = 0; j < mapList.size(); j++) { Map map1 = (Map) mapList.get(j); String extnumfield0=StringHelper.null2String(map1.get("extnumfield0")); double mianji = Double.valueOf(extnumfield0); czmj=czmj+mianji; } } //这年每月的出租率:每个月有一个出租率(出租面积/7至31楼的总面积) Double rentalRate=0.0;//每月的出租率 //每个月的出租率换成百分比形式并且保留二位小数 rentalRate=(czmj/totalarea) * 100; DecimalFormat df = new DecimalFormat("#0.00"); String rateTow =df.format(rentalRate)+"%"; // mapMonthData.put(StringUtil.obj2String(month),rentalRate); mapMonthData.put(StringUtil.obj2String(month),rateTow); totalRate +=rentalRate; // System.out.println(month+"月已出租的总面积:"+"======================"+czmj); } //年终统计一个平均出租率(即每个月的出租率/12个月) Double avgRate=totalRate/12;//平均出租率 DecimalFormat df = new DecimalFormat("#0.00"); String rateTow =df.format(avgRate)+"%"; mapMonthData.put(StringUtil.obj2String(13),rateTow); //进行重新按月份排序 List > list = new ArrayList >(mapMonthData.entrySet()); Collections.sort(list, new Comparator >() { public int compare(Map.Entry o1, Map.Entry o2) { return NumberHelper.string2Int(o1.getKey(),0) - NumberHelper.string2Int(o2.getKey(),0); } }); for(Map.Entry m: list){ Map MonthData=new HashMap ();//每个月的出租率 //newMonthRate.add(NumberHelper.string2Double(mapMonthData.get(m.getKey()),0)); MonthData.put("month",m.getKey()); MonthData.put("monthValue",m.getValue()); newMonthRate.add(MonthData); } //每年的数据 Map everyYear=new HashMap(); everyYear.put("year",i); everyYear.put("avgRate",avgRate); everyYear.put("newMonthRate",newMonthRate); RateYearData.add(everyYear); } } %> 会议
说明:其中有按钮的提交事件,下拉选择,时间的判断,年份的查询用form表单(jsp)