算出租率报表:涉及时间的判断(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个月 List<String> monthLists=new ArrayList<String>(); 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<Map<String,Object>> RateYearData=new ArrayList<Map<String,Object>>();//每年的出租率 int selectYears=0; if (StringUtils.isEmpty(selectYear)){ for ( int i=minYears ; i<=maxYears ;i++){ //月份 Map<String,Object> mapMonthData=new HashMap<String,Object>();//每个月的出租率 List<Map<String,Object>> newMonthRate=new ArrayList<Map<String,Object>>();//每个月的出租率按月份进行重新排序 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<Map<String, Object>> 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<Map.Entry<String,Object>> list = new ArrayList<Map.Entry<String,Object>>(mapMonthData.entrySet()); Collections.sort(list, new Comparator<Map.Entry<String, Object>>() { public int compare(Map.Entry<String, Object> o1, Map.Entry<String, Object> o2) { return NumberHelper.string2Int(o1.getKey(),0) - NumberHelper.string2Int(o2.getKey(),0); } }); for(Map.Entry<String,Object> m: list){ Map<String,Object> MonthData=new HashMap<String,Object>();//每个月的出租率 //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<String,Object> mapMonthData=new HashMap<String,Object>();//每个月的出租率 List<Map<String,Object>> newMonthRate=new ArrayList<Map<String,Object>>();//每个月的出租率按月份进行重新排序 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<Map<String, Object>> 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<Map.Entry<String,Object>> list = new ArrayList<Map.Entry<String,Object>>(mapMonthData.entrySet()); Collections.sort(list, new Comparator<Map.Entry<String, Object>>() { public int compare(Map.Entry<String, Object> o1, Map.Entry<String, Object> o2) { return NumberHelper.string2Int(o1.getKey(),0) - NumberHelper.string2Int(o2.getKey(),0); } }); for(Map.Entry<String,Object> m: list){ Map<String,Object> MonthData=new HashMap<String,Object>();//每个月的出租率 //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); } } %> <html> <head> <link rel="stylesheet" type="text/css" href="../report/tables.css"> <title>会议</title> </head> <body> <form action="/vproduct/view/report/wuyechuzulv.jsp" name="VelcroForm" method="post"> <!--搜索条件 --> <% pagemenustr += "{S,查询,javascript:onSearch()}"; %> <div class="bBac"> <div class="fLef icoP iPSub" onclick="ShowHide.shByIco(this,'#searchTable')"></div> <div class="fMid" id="pagemenubar"></div> </div> <%@ include file="/vbase/pagemenu.jsp"%> <div class="sTab"> <div style="display: none"> <tr> <th>年份</th> <td><input name="objnames1" id="name1" style="width: 144px;" type="text" size="15" value=""/> </td> </tr> </div> <tr> <th>年份</th> <select id="selectyear"> <option value =""></option> <% for ( int i=minYears ; i<=maxYears ;i++){ String checkYear = StringUtil.obj2String(selectYears); String syear=StringUtil.obj2String(i); //String selected=checkYear.equals(syear) ? "selected" : "";//判断是否有有选中年份 %> <%--<option value ="<%=i%>" <%=selected%> ><%=i%></option>--%> <option value ="<%=i%>" ><%=i%></option> <% } %> </select> </tr> </div> <!--搜索条件 --> <div align="left"> <table id="eTab" cellspacing="0"> <tr> <th width="4%">年份</th> <th width="8%">一月</th> <th width="8%">二月</th> <th width="8%">三月</th> <th width="8%">四月</th> <th width="8%">五月</th> <th width="8%">六月</th> <th width="8%">七月</th> <th width="8%">八月</th> <th width="8%">九月</th> <th width="8%">十月</th> <th width="8%">十一月</th> <th width="8%">十二月</th> <th width="8%">年终出租率</th> </tr> <br> <% for (int i = 0; i < RateYearData.size(); i++) { Map<String, Object> map = RateYearData.get(i); String year=StringHelper.null2String(map.get("year")); // String avgRate=StringHelper.null2String(map.get("avgRate")); List<Map<String,Object>> v=(List<Map<String,Object>>)map.get("newMonthRate"); %> <tr> <td><%=year%></td> <% for (int j = 0; j < v.size(); j++) { Map<String, Object> temp = v.get(j); String monthValue=StringHelper.null2String(temp.get("monthValue")); %> <td class="row"><%=monthValue%></td> <% } %> </tr> <% } %> </table> </div> </form> <script type="text/javascript" src="/js/bootstrap.min.js"></script> </body> </html> <script type=text/javascript> function onSearch() { var select=$('#selectyear option:selected') .val();//选中的值 $("#name1").attr("value",select); document.VelcroForm.submit(); } </script>
说明:其中有按钮的提交事件,下拉选择,时间的判断,年份的查询用form表单(jsp)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
· AI 智能体引爆开源社区「GitHub 热点速览」