很快的,拿到了第二个需求。哇,需求文档好坑爹啊,感觉就是把客户的要求整理一下,然后就发过来了,对我这种菜鸟而言,完全不知道这个需求想要什么,更别谈怎么实现了。没办法,问我们万能的组长吧。
然后我们组长就啪啪啪啪啪的说了一通,告诉我这是个什么什么玩意,我听完之后恍然大悟,啊咧,听起来还满简单的。开始呗。
我坐回工位时发现,哎我去,没页面啊,赶紧腆着脸又找组长大人要了一个。有了页面以后,突然感觉可以着手了。干活吧。
第一,我需要建一个表,我们有灰常流逼的代码生成器,字段往里面一填,点个确定,什么sql啊,JAVA类啊,竟然还生成了JSP页面!好吧,好厉害。当我打开生成的JSP页面后,顿时泪流满面啊,这特么都是啥啊,封装的太严重了,我那熟悉的form,input啥啥的都哪里去了。面对着JSP里面形形色色的标签我就蒙圈了,行了先这样吧。
第二,围绕这个表做增删改查的功能,先说说增吧,最重要的就是表单验证了
<script type="text/javascript"> Ext.onReady(function() { v = new eoms.form.Validation({form:'timeLimitForm'}); } );//这个是特么啥啊!!有啥用啊,放着吧,不删了 var isNum = false;//标识是否为数字 var isEqual = false;//标识T1T2T3相加是否与handling相等 var isFill = false; //标识是否填值 //校验非空 function validate0(){ var af = false; var bf = false; var cf = false; var df = false; var ef = false; var ff = false; var gf = false; var hf = false; var message ='请填写'; var areaType = document.getElementById('area_type'); var netType = document.getElementById('network_level_one').value; var alarmLevel = document.getElementById('alarm_level').value; var accept = document.getElementById('sheet_accept_time_limit').value; var handling = document.getElementById('sheet_handling_time_limit').value; var t1 = document.getElementById('t1_time_limit').value; var t2 = document.getElementById('t2_time_limit').value; var t3 = document.getElementById('t3_time_limit').value; var index = areaType.selectedIndex; var value = areaType.options[index].value; if(netType!=''){ af = true; }else{ af = false; message = message+' 网络一级分类'; } if(value!=0){ bf = true; }else{ bf = false; message = message+' 地区'; } if(alarmLevel!=''){ cf = true; }else{ cf = false; message = message+' 故障处理响应级别'; } if(accept!=''){ df = true; }else{ df = false; message = message+' 故障受理时限'; } if(handling!=''){ ef = true; }else{ ef = false; message = message+' 故障处理时限'; } if(t1!=''){ ff = true; }else{ ff =false; message = message+' T1处理时限'; } if(t2!=''){ gf = true; }else{ gf = false; message = message+' T2处理时限'; } if(t3!=''){ hf = true; }else{ hf = false; message = message+' T3处理时限'; } if(af&&bf&&cf&&df&&ef&&ff&&gf&&hf){ isFill = true; }else{ isFill = false; alert(message); } } //校验输入是否是数字 function validate1(){ var reg = new RegExp("^([1-9][0-9]*)$"); var accept = document.getElementById('sheet_accept_time_limit').value; var handling = document.getElementById('sheet_handling_time_limit').value; var t1 = document.getElementById('t1_time_limit').value; var t2 = document.getElementById('t2_time_limit').value; var t3 = document.getElementById('t3_time_limit').value; if(!((reg.test(accept))&&(reg.test(handling))&&(reg.test(t1))&&(reg.test(t2))&&(reg.test(t3)))){ isNum = false; alert("请输入非0开头数字!"); }else{ isNum = true; } } //校验处理时限是否等于T1,T2,T3之和 function validate2(){ var t1 = parseInt(document.getElementById("t1_time_limit").value); var t2 = parseInt(document.getElementById("t2_time_limit").value); var t3 = parseInt(document.getElementById("t3_time_limit").value); var handlingTime = parseInt(document.getElementById("sheet_handling_time_limit").value); var t=t1+t2+t3; if(handlingTime==t){ isEqual = true; }else{ isEqual = false; alert('工单处理时限必须为T1处理时限,T2处理时限,T3处理时限之和'); } } //校验规则是否已有 function validate3(){ var areaType = document.getElementById('area_type').value; var netType = document.getElementById('network_level_one').value; var alarmLevel = document.getElementById('alarm_level').value; if((areaType!=0)&&(netType!='')&&(alarmLevel!='')){ Ext.Ajax.request({ params:{ areaType:areaType,netType:netType,alarmLevel:alarmLevel }, method:"post", url: "${app}/sheet/centralcommonfaulttimelimit/timeLimit.do?method=validate", success: function(x){ var data = eoms.JSONDecode(x.responseText); if(null != data){ var form = document.getElementById("form"); form.submit(); } else{ alert('已有相同规则存在,不可重复添加'); } } }); } } //表单提交 function submitForm(){ validate0(); if(isFill){ validate1(); } if(isNum){ validate2(); } if(isEqual&&isFill&&isNum){ validate3(); } } </script>
增加完了吧,增加完就得展示了吧。哈哈哈,按照之前的想法,增加完就直接跳到列表页面,显示内容呗。就把显示列表的页面称为list.jsp吧,我勒个去,这个list.jsp是系统生成的用的是无敌的display标签库!!!
这个标签库啊,可以分页,可以以某列为标准进行排序,可以把表格到处成pdf,excel啥啥的,有木有高端大气上档次的感觉呢?详细了解可以百度。但是,就是这个流逼的标签害的我好惨啊,谁让咱菜呢。首先这个标签库里有个requestURI属性,我不知道这是个什么玩意,好不留情的删掉了,于是,分页不好使了,啥都不好使了。后来发现问题所在又加上了。
这个标签库的分页十分的厉害,你是通过action里面的什么方法进入后台继而经过一些个什么什么操作展示出的页面,它中间过程统统不记,只记住第一个方法。好吧,这样导致了一个问题。例如,我是通过save方法进入后台的,然后由save方法跳到showlist方法展示出页面,那么这个标签只记得save方法,当你一点击下一页时它就执行save方法,呼呼的往数据库里插数据啊。我以为在那个requestURI里面把方法写死了,就OK了,事实证明这是痴心妄想啊。它只是通过requestURI知道它需要访问哪个action类,点击下一页什么的具体要执行什么方法只跟我前面说的机制有关。咋整啊!后来,问我的隔壁,他告诉我,你只要增加成功然后弹出一个success页面就可以了,不要直接跳list.jsp,同理,那些个删除什么的也要这样。好吧,还真是一个好主意呢。把那个页面贴上。
对了对了,说一下页面乱码的问题,在JSP最上面要写<%page pageEncoding 什么什么的。每个JSP都要写,如果你认为<%include xxxxx.jsp里面已经写了这句话了,就不用再写了,那你就错了
<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8" contentType="text/html;charset=utf-8" %> <%@ include file="/common/taglibs.jsp"%> <%@ include file="/common/header_eoms_ext.jsp"%> <script type="text/javascript"> function onRemove(id){ var flag = confirm('确定要删除吗?'); if(flag){ window.location.href="${app}/sheet/centralcommonfaulttimelimit/timeLimit.do?method=remove&id="+id; } } </script> <jsp:include page="/WEB-INF/pages/wfworksheet/centralcommonfault/timelimit/timeLimitQuery.jsp"/> <br/> <fmt:bundle basename="config/applicationResource-timelimit"> <content tag="heading"> 故障工单处理时限规则列表 </content> <display:table name="timeLimitList" cellspacing="0" cellpadding="0" id="timeLimitList" pagesize="${pageSize}" class="table timeLimitList" export="false" sort="list" partialList="true" size="resultSize" requestURI="${app}/sheet/centralcommonfaulttimelimit/timeLimit.do?method=showList"> <display:column property="network_level_one" sortable="false" headerClass="sortable" title="网络一级分类" paramId="id" paramProperty="id"/> <display:column property="area_type" sortable="false" headerClass="sortable" title="地区" paramId="id" paramProperty="id"/> <display:column property="alarm_level" sortable="false" headerClass="sortable" title="故障处理响应级别" paramId="id" paramProperty="id"/> <display:column property="sheet_accept_time_limit" sortable="false" headerClass="sortable" title="故障工单受理时限(分钟)" paramId="id" paramProperty="id"/> <display:column property="sheet_handling_time_limit" sortable="false" headerClass="sortable" title="故障工单处理时限(分钟)" paramId="id" paramProperty="id"/> <display:column property="t1_time_limit" sortable="false" headerClass="sortable" title="T1处理时限(分钟)" paramId="id" paramProperty="id"/> <display:column property="t2_time_limit" sortable="false" headerClass="sortable" title="T2处理时限(分钟)" paramId="id" paramProperty="id"/> <display:column property="t3_time_limit" sortable="false" headerClass="sortable" title="T3处理时限(分钟)" paramId="id" paramProperty="id"/> <display:column sortable="false" headerClass="sortable" title="编辑" media="html"> <a href='${app}/sheet/centralcommonfaulttimelimit/timeLimit.do?method=edit&id=${timeLimitList.id}' > <img src="${app }/images/icons/edit.gif" /> </a> </display:column> <display:column sortable="false" headerClass="sortable" title="删除" media="html"> <a href="javascript:onRemove('${timeLimitList.id}')"> <img src="${app }/images/icons/nodetype/empty.gif" > </a> </display:column> <display:setProperty name="paging.banner.item_name" value="timeLimit" /> <display:setProperty name="paging.banner.items_name" value="timeLimits" /> </display:table> <br/> <input type="button" value="新增" onclick="window.location.href='${app}/sheet/centralcommonfaulttimelimit/timeLimit.do?method=showForm'"/> <c:out value="${buttons}" escapeXml="false" /> </fmt:bundle> <%@ include file="/common/footer_eoms.jsp"%>
查询的页面做的很有意思,就是timeLimitQuery.jsp这个,需要查询的时候一点就弹出来了,不需要的时候就自己隐藏在那里。
<%@ page language="java" pageEncoding="UTF-8" %> <%@ include file="/common/taglibs.jsp"%> <%String mainfaultresponselevels = (String)request.getAttribute("mainfaultresponselevels"); %> <script type="text/javascript"> Ext.onReady(function(){ //viewer var areaViewer = new Ext.JsonView("areaview", '<div class="viewlistitem-{nodeType}">{name}</div>', { emptyText : '<div>没有选择项目</div>' } ); var data = "[{id:'${toDeptId}',name:'<eoms:id2nameDB id='${toDeptId}' beanId='tawSystemAreaDao'/>',nodeType:'area'}]"; areaViewer.jsonData = eoms.JSONDecode(data); areaViewer.refresh(); //area tree var deptTreeAction='${app}/xtree.do?method=areaTree'; deptetree = new xbox({ btnId:'${sheetPageName}showDept',dlgId:'dlg3', treeDataUrl:deptTreeAction,treeRootId:'-1',treeRootText:'地市',treeChkMode:'single',treeChkType:'area', showChkFldId:'${sheetPageName}showDept',saveChkFldId:'${sheetPageName}toDeptId',viewer:areaViewer }); var levelparam = document.getElementsByName("mainfaultresponselevel"); var mainfaultresponselevel = document.getElementById("level").value; if(mainfaultresponselevel!=''){ var array = mainfaultresponselevel.split(","); if(array!=null&&array.length>0){ for(var i=0;i<array.length;i++){ var level = array[i]; for(var j=0;j<levelparam.length;j++){ var param = levelparam[j].value; if(level==param){ levelparam[j].checked=true; } } } } } }); function openQuery(handler){ var el = Ext.get('listQueryObject'); if(el.isVisible()){ el.slideOut('t',{useDisplay:true}); handler.innerHTML = "打开快速查询"; } else{ el.slideIn(); handler.innerHTML = "关闭快速查询"; } } function onsubmitCheck(){ return true; } </script> <div style="border:1px solid #98c0f4;padding:5px;width:98%;" class="x-layout-panel-hd"> 工具栏: <img src="${app}/images/icons/search.gif" align="absmiddle" style="cursor:pointer"/> <span id="openQuery" style="cursor:pointer" onclick="openQuery(this);">打开快速查询</span> </div> <div id="listQueryObject" style="display:none;border:1px solid #98c0f4;border-top:0;padding:5px;background-color:#eff6ff;width:98%"> <form name="queryform" method="post" action="${app}/sheet/centralcommonfaulttimelimit/timeLimit.do?method=showList" onsubmit="return onsubmitCheck();" > <table width="100%" class="formTable"> <tr> <td class="label"> 网络一级分类 </td> <td> <input type="hidden" name="level" id="level" value="<%=mainfaultresponselevels %>" /> <eoms:comboBox name="network_level_one" id="network_level_one" initDicId="1010104" defaultValue="" /> </td> <td class="label"> 地区 </td> <td> <select id="area_type" name="area_type"> <option value="0" selected="selected">请选择</option> <option value="1">城区</option> <option value="2">县城</option> <option value="3">乡镇</option> </select> </td> </tr> <tr> <td class="label"> 故障响应级别 </td> <td> <eoms:comboBox name="alarm_level" id="alarm_level" defaultValue="" initDicId="1010304"/> </td> <td colspan="2"> <input type="submit" value="查询" class="submit"/> <input type="reset" value="重置" class="button"/> </td> </tr> </table> </form> </div>
也就没啥了,想知道时间的加减怎么算么?这么算
JS里面
//根据网络三级分类+故障响应级别选择时限,这块沿用已有故障流程的配置 function selectLimit(value){ var city = document.getElementById('mainFaultGenerantCityName').value;//获取地市 var county = document.getElementById('mainFaultGenerantCountyName').value;//获取县城 //获取乡镇var town = document.getElementById('').value; var mainNetSortOne = document.getElementById('mainNetSortOne').value;//网络一级分类 var mainFaultResponseLevel=document.getElementById('mainFaultResponseLevel').value;//告警响应级别 var areaType = '0'; if(city!=""&&county==""){ areaType = '1'; }else{ areaType = '2'; } if(areaType!="0"&&mainNetSortOne!=""&&mainFaultResponseLevel!=""){ Ext.Ajax.request({ method:"get", url: "${app}/sheet/centralcommonfaulttimelimit/timeLimit.do?method=showTimeLimit&areaType="+areaType+"&netType="+mainNetSortOne+"&alarmLevel="+mainFaultResponseLevel, success: function(x){ var o = eoms.JSONDecode(x.responseText); if(o==null){ alert('o==null'); $("sheetAcceptLimit").value = ""; $('sheetCompleteLimit').value =""; $("mainCompleteLimitT1").value = ""; $('mainCompleteLimitT2').value = ""; $('mainCompleteLimitT3').value = ""; }else{ var times=<%=localTimes%>; //工单时限 var acceptdt = new Date(times).add(Date.MINUTE,parseInt(o.timeLimit.sheet_accept_time_limit,10)); var replydt = acceptdt.add(Date.MINUTE,parseInt(o.timeLimit.sheet_handling_time_limit,10)); $("sheetAcceptLimit").value = acceptdt.format('Y-m-d H:i:s'); $('sheetCompleteLimit').value = replydt.format('Y-m-d H:i:s'); //环节时限 var dt1 = acceptdt.add(Date.MINUTE,parseInt(o.timeLimit.t1_time_limit,10)); var dt2 = dt1.add(Date.MINUTE,parseInt(o.timeLimit.t2_time_limit,10)); var dt3 = dt2.add(Date.MINUTE,parseInt(o.timeLimit.t3_time_limit,10)); dt3=dt3.add(Date.SECOND,-1); $("mainCompleteLimitT1").value = dt1.format('Y-m-d H:i:s'); $('mainCompleteLimitT2').value = dt2.format('Y-m-d H:i:s'); $('mainCompleteLimitT3').value = dt3.format('Y-m-d H:i:s'); } } }); } /* if($("mainIsGroupCustomSheet").value=="1030101" && value=='2'){//是集客故障工单时获取工单时限 var customLevel=$("mainGroupCustomLevel").value; if(customLevel == null ||customLevel ==""){ alert("请先选择业务保障级别"); return false; } if(customLevel != null && customLevel !=""){ Ext.Ajax.request({ method:"get", url: "centralcommonfaultLimit.do?method=showDealLimit&customLevel="+customLevel, success: function(x){ var o = eoms.JSONDecode(x.responseText); if(o.acceptLimit == null || o.acceptLimit == ""){ $("sheetAcceptLimit").value = ""; $('sheetCompleteLimit').value =""; }else{ var times=<%=localTimes%>; //工单时限 var acceptdt = new Date(times).add(Date.MINUTE,parseInt(o.acceptLimit,10)); var replydt = new Date(times).add(Date.MINUTE,parseInt(o.replyLimit,10)); $("sheetAcceptLimit").value = acceptdt.format('Y-m-d H:i:s'); $('sheetCompleteLimit').value = replydt.format('Y-m-d H:i:s'); //环节时限 var dt1 = new Date(times).add(Date.MINUTE,parseInt(o.t1Limit,10)); var dt2 = dt1.add(Date.MINUTE,parseInt(o.t2Limit,10)); var dt3 = dt2.add(Date.MINUTE,parseInt(o.t3Limit,10)); dt3=dt3.add(Date.SECOND,-1); $("mainCompleteLimitT1").value = dt1.format('Y-m-d H:i:s'); $('mainCompleteLimitT2').value = dt2.format('Y-m-d H:i:s'); $('mainCompleteLimitT3').value = dt3.format('Y-m-d H:i:s'); } } }); } }else{ if($("mainNetSortOne").value == null ||$("mainNetSortOne").value ==""){ return false; } if($("mainFaultResponseLevel").value == null ||$("mainFaultResponseLevel").value ==""){ return false; } var netSortOne=$("mainNetSortOne").value; var faultResponseLevel=$("mainFaultResponseLevel").value; var netSortTwo=$("mainNetSortTwo").value; var netSortThree=$("mainNetSortThree").value; if($("mainFaultResponseLevel").value != null && $("mainFaultResponseLevel").value !=""){ Ext.Ajax.request({ method:"get", url: "centralcommonfault.do?method=showDealLimit&faultResponseLevel="+faultResponseLevel, success: function(x){ var o = eoms.JSONDecode(x.responseText); if(o.acceptLimit == null || o.acceptLimit == ""){ $("sheetAcceptLimit").value = ""; $('sheetCompleteLimit').value =""; }else{ var times=<%=localTimes%>; //工单时限 var acceptdt = new Date(times).add(Date.MINUTE,parseInt(o.acceptLimit,10)); var replydt = new Date(times).add(Date.MINUTE,parseInt(o.replyLimit,10)); $("sheetAcceptLimit").value = acceptdt.format('Y-m-d H:i:s'); $('sheetCompleteLimit').value = replydt.format('Y-m-d H:i:s'); } } }); } Ext.Ajax.request({ method:"get", url: "centralcommonfault.do?method=showLimit&netSortOne="+netSortOne+"&netSortTwo="+netSortTwo+"&netSortThree="+netSortThree+"&faultResponseLevel="+faultResponseLevel, success: function(x){ var o = eoms.JSONDecode(x.responseText); if((o.t1Limit == null || o.t1Limit == "")&&(o.t2Limit == null || o.t2Limit == "")){ $("mainCompleteLimitT1").value = ""; $('mainCompleteLimitT2').value = ""; $('mainCompleteLimitT3').value = ""; //alert("您选择的故障专业类型和故障处理响应级别没有配置工单时长!"); }else{ var times=<%=localTimes%>; var dt1 = new Date(times).add(Date.MINUTE,parseInt(o.t1Limit,10)); var dt2 = dt1.add(Date.MINUTE,parseInt(o.t2Limit,10)); var dt3 = dt2.add(Date.MINUTE,parseInt(o.t3Limit,10)); dt3=dt3.add(Date.SECOND,-1); $("mainCompleteLimitT1").value = dt1.format('Y-m-d H:i:s'); $('mainCompleteLimitT2').value = dt2.format('Y-m-d H:i:s'); $('mainCompleteLimitT3').value = dt3.format('Y-m-d H:i:s'); } } }); } */ }
后台这么写的
private static String addMinute(Date date, int minute) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); GregorianCalendar c = new GregorianCalendar(); c.setTime(date); c.add(12, minute); String datestr = dateFormat.format(c.getTime()); return datestr; }
不写了,烦了