WEB甘特图(机器运行状态图)
程序员文章站
2023-08-18 18:12:40
请勿见怪!以下添加标签代码重复过多,有兴趣耐心看,没兴趣略过!HTML 1
3
请勿见怪!以下添加标签代码重复过多,有兴趣耐心看,没兴趣略过!
html
1 <div id="container" 2 style="width: 1608px; height: 901px; border: 1px dashed #a4a4a4; margin-top: 9px;"> 3 <div class="carnum"> 4 <div 5 style="background: #d3dfed; height: 40px; text-align: center;"> 6 <font size="4" color="#5d7cb2"><label 7 style="position: relative; top: 5px;">机器型号</label></font> 8 </div> 9 <hr 10 style="width: 1605px; border-top: 1px; border: 1px dashed #a4a4a4; margin-top: -1px;" /> 11 <div style="height: 9px;">b3-1</div> 12 <div id="b3-1" 13 style="position: absolute; margin-left: 1540px; margin-top: -10px;"> </div> 14 <hr 15 style="width: 1605px; border-top: 1px; border: 1px dashed #a4a4a4;" /> 16 <div style="height: 9px;">b3-2</div> 17 <div id="b3-2" 18 style="position: absolute; margin-left: 1540px; margin-top: -10px;"> </div> 19 <hr 20 style="width: 1605px; border-top: 1px; border: 1px dashed #a4a4a4;" /> 21 <div style="height: 9px;">b3-3</div> 22 <div id="b3-3" 23 style="position: absolute; margin-left: 1540px; margin-top: -10px;"> </div> 24 <hr 25 style="width: 1605px; border-top: 1px; border: 1px dashed #a4a4a4;" /> 26 <div style="height: 9px;">b3-15</div> 27 <div id="b3-15" 28 style="position: absolute; margin-left: 1540px; margin-top: -10px;"> </div> 29 <hr 30 style="width: 1605px; border-top: 1px; border: 1px dashed #a4a4a4;" /> 31 <div style="height: 9px;">b3-kq</div> 32 <div id="b3-kq" 33 style="position: absolute; margin-left: 1540px; margin-top: -10px;"> </div> 34 <hr 35 style="width: 1605px; border-top: 1px; border: 1px dashed #a4a4a4;" /> 36 <div style="height: 9px;">be-01</div> 37 <div id="be-01" 38 style="position: absolute; margin-left: 1540px; margin-top: -10px;"> </div> 39 <hr 40 style="width: 1605px; border-top: 1px; border: 1px dashed #a4a4a4;" /> 41 <div style="height: 9px;">be-02</div> 42 <div id="be-02" 43 style="position: absolute; margin-left: 1540px; margin-top: -10px;"> </div> 44 <hr 45 style="width: 1605px; border-top: 1px; border: 1px dashed #a4a4a4;" /> 46 <div style="height: 9px;">be-03</div> 47 <div id="be-03" 48 style="position: absolute; margin-left: 1540px; margin-top: -10px;"> </div> 49 <hr 50 style="width: 1605px; border-top: 1px; border: 1px dashed #a4a4a4;" /> 51 <div style="height: 9px;">be-04</div> 52 <div id="be-04" 53 style="position: absolute; margin-left: 1540px; margin-top: -10px;"> </div> 54 <hr 55 style="width: 1605px; border-top: 1px; border: 1px dashed #a4a4a4;" /> 56 <div style="height: 9px;">be-05</div> 57 <div id="be-05" 58 style="position: absolute; margin-left: 1540px; margin-top: -10px;"> </div> 59 <hr 60 style="width: 1605px; border-top: 1px; border: 1px dashed #a4a4a4;" /> 61 <div style="height: 9px;">be-06</div> 62 <div id="be-06" 63 style="position: absolute; margin-left: 1540px; margin-top: -10px;"> </div> 64 <hr 65 style="width: 1605px; border-top: 1px; border: 1px dashed #a4a4a4;" /> 66 <div style="height: 9px;">be-08</div> 67 <div id="be-08" 68 style="position: absolute; margin-left: 1540px; margin-top: -10px;"> </div> 69 <hr 70 style="width: 1605px; border-top: 1px; border: 1px dashed #a4a4a4;" /> 71 <div style="height: 9px;">be-09</div> 72 <div id="be-09" 73 style="position: absolute; margin-left: 1540px; margin-top: -10px;"> </div> 74 <hr 75 style="width: 1605px; border-top: 1px; border: 1px dashed #a4a4a4;" /> 76 <div style="height: 9px;">be-37</div> 77 <div id="be-37" 78 style="position: absolute; margin-left: 1540px; margin-top: -10px;"> </div> 79 <hr 80 style="width: 1605px; border-top: 1px; border: 1px dashed #a4a4a4;" /> 81 <div style="height: 9px;">be-39</div> 82 <div id="be-39" 83 style="position: absolute; margin-left: 1540px; margin-top: -10px;"> </div> 84 <hr 85 style="width: 1605px; border-top: 1px; border: 1px dashed #a4a4a4;" /> 86 <div style="height: 9px;">be-40</div> 87 <div id="be-40" 88 style="position: absolute; margin-left: 1540px; margin-top: -10px;"> </div> 89 <hr 90 style="width: 1605px; border-top: 1px; border: 1px dashed #a4a4a4;" /> 91 <div style="height: 9px;">be-41</div> 92 <div id="be-41" 93 style="position: absolute; margin-left: 1540px; margin-top: -10px;"> </div> 94 <hr 95 style="width: 1605px; border-top: 1px; border: 1px dashed #a4a4a4;" /> 96 <div style="height: 9px;">be-42</div> 97 <div id="be-42" 98 style="position: absolute; margin-left: 1540px; margin-top: -10px;"> </div> 99 <hr 100 style="width: 1605px; border-top: 1px; border: 1px dashed #a4a4a4;" /> 101 <div style="height: 9px;">be-43</div> 102 <div id="be-43" 103 style="position: absolute; margin-left: 1540px; margin-top: -10px;"> </div> 104 <hr 105 style="width: 1605px; border-top: 1px; border: 1px dashed #a4a4a4;" /> 106 <div style="height: 9px;">be-51</div> 107 <div id="be-51" 108 style="position: absolute; margin-left: 1540px; margin-top: -10px;"> </div> 109 110 111 </div> 112 <div id="hour" style="position: absolute; margin-left: 100px;"> 113 <div style="height: 40px;"> 114 <font size="4">08</font> 115 </div> 116 <div style="height: 40px;"> 117 <font size="4">09</font> 118 </div> 119 <div style="height: 40px;"> 120 <font size="4">10</font> 121 </div> 122 <div style="height: 40px;"> 123 <font size="4">11</font> 124 </div> 125 <div style="height: 40px;"> 126 <font size="4">12</font> 127 </div> 128 <div style="height: 40px;"> 129 <font size="4">13</font> 130 </div> 131 <div style="height: 40px;"> 132 <font size="4">14</font> 133 </div> 134 <div style="height: 40px;"> 135 <font size="4">15</font> 136 </div> 137 <div style="height: 40px;"> 138 <font size="4">16</font> 139 </div> 140 <div style="height: 40px;"> 141 <font size="4">17</font> 142 </div> 143 <div style="height: 40px;"> 144 <font size="4">18</font> 145 </div> 146 <div style="height: 40px;"> 147 <font size="4">19</font> 148 </div> 149 <div style="height: 40px;"> 150 <font size="4">20</font> 151 </div> 152 <div style="height: 40px;"> 153 <font size="4">21</font> 154 </div> 155 <div style="height: 40px;"> 156 <font size="4">22</font> 157 </div> 158 <div style="height: 40px;"> 159 <font size="4">23</font> 160 </div> 161 <div style="height: 40px;"> 162 <font size="4">00</font> 163 </div> 164 <div style="height: 40px;"> 165 <font size="4">01</font> 166 </div> 167 <div style="height: 40px;"> 168 <font size="4">02</font> 169 </div> 170 <div style="height: 40px;"> 171 <font size="4">03</font> 172 </div> 173 <div style="height: 40px;"> 174 <font size="4">04</font> 175 </div> 176 <div style="height: 40px;"> 177 <font size="4">05</font> 178 </div> 179 <div style="height: 40px;"> 180 <font size="4">06</font> 181 </div> 182 <div style="height: 40px;"> 183 <font size="4">07</font> 184 </div> 185 <div style="height: 40px; width: 70px;"> 186 <font size="3"><sup>时长</sup>/<sub>分</sub></font> 187 </div> 188 </div> 189 190 191 </div> 192 193 194 195 </center> 196 197 </div> 198 199 <div id="addbox" class="addbox"> 200 <a href="javascript:;" 201 onclick="jquery('.addbox').hide();jquery('.shadow').hide();" 202 class="close"></a> 203 </div> 204 <!--遮罩层--> 205 <div class="shadow" id="progress"> 206 <div class="container"> 207 <div class="warning"> 208 <img style="margin-top: 400px; margin-left: 500px;" 209 src="${pagecontext.request.contextpath}/images/2.gif"> 210 </div> 211 </div> 212 </div>
javascript
1 javascript 2 <script type="text/javascript"> 3 $(function() { 4 //日期插件 datapicker 5 $("input[name='txtbegindate']").daterangepicker( 6 { 7 singledatepicker : true,//设置为单个的datepicker,而不是有区间的datepicker 默认false 8 showdropdowns : true,//当设置值为true的时候,允许年份和月份通过下拉框的形式选择 默认false 9 autoupdateinput : false,//1.当设置为false的时候,不给与默认值(当前时间)2.选择时间时,失去鼠标焦点,不会给与默认值 默认true 10 timepicker24hour : true,//设置小时为24小时制 默认false 11 timepicker : false,//可选中时分 默认false 12 locale : { 13 format : "yyyy-mm-dd", 14 separator : " - ", 15 daysofweek : [ "日", "一", "二", "三", "四", "五", "六" ], 16 monthnames : [ "一月", "二月", "三月", "四月", "五月", "六月", 17 "七月", "八月", "九月", "十月", "十一月", "十二月" ] 18 } 19 }).on('cancel.daterangepicker', function(ev, picker) { 20 $("#submitdate").val(""); 21 }).on('apply.daterangepicker', function(ev, picker) { 22 $("#submitdate").val(picker.startdate.format('yyyy-mm-dd')); 23 $("#txtbegindate").val(picker.startdate.format('yyyy-mm-dd')); 24 }); 25 }); 26 // 记录添加机器状态条的次数 27 var removetimes = 0; 28 // 初始化 29 function init() { 30 this.createhours(); 31 this.createdata(); 32 } 33 // 页面初始化数据准备 34 function createdata() { 35 var ml = null; // 为了解决ie和火狐机器状态条相对左边位置不同问题 故只能设置变量进行解决 36 39 // 日期文本框中显示出昨天日期 40 var date = new date(); 37 var seperator1 = "-"; 38 var year = date.getfullyear(); 39 var month = date.getmonth() + 1; 40 var strdate = date.getdate() - 1; 41 if (month >= 1 && month <= 9) { 42 month = "0" + month; 43 } 44 if (strdate >= 0 && strdate <= 9) { 45 strdate = "0" + strdate; 46 } 47 var today = date.getdate() - 1; // 今天的日期 48 if (today == 0) { 49 if (month == 1 || month == 3 || month == 5 || month == 8 50 || month == 10 || month == 11) { 51 month -= 1; 52 strdate = 31; 53 } else { 54 month -= 1; 55 strdate = 30; 56 } 57 } 58 var currentdate = "" + year + seperator1 + month + seperator1+ strdate; // 拼接日期显示在文本框中 59 $(function() { 60 $ .ajax({ 61 type : "post", 62 url : "${pagecontext.request.contextpath}/data", 63 datatype : "json", 64 data : { 65 itdate : currentdate, 66 mtype : "alltype", 67 tcolor : "all" 68 }, 69 success : function(data) { 70 document.getelementbyid("txtbegindate").value = currentdate;// 为日期文本框赋值 71 $('.addbox').show();// 控制遮盖层的显示 72 if (null == data || "" == data) { 73 $('.addbox').hide(); 74 }// 返回数据为空时立即隐藏遮盖层 75 if (!!window.activexobject 76 || "activexobject" in window) { 77 ml = 100; 78 } else { 79 ml = -698; 80 }// 判断用户所使用的浏览器,然后根据估计增加或减少机器进度条margin-left的大小,目的是为了让时刻与顶部时间栏对应 81 var demodata = new array(), list = null, html = null, allleft = null; 82 t = null;// 统一创建变量避免占用资源,提高效率 83 for (var key = 0; key < data.length; key++) { //第一层循环取到大集合中的各个list 84 list = data[key]; 85 html = '', allleft = 0, t = 1; 86 var len = list.length; 87 for (var i = 0; i < len; i++) { //第二层循环取到list中的对象 88 // 根据时间计算机器状态条的长度,1分钟1px,此具体计算方法借鉴而来 89 var start = new date(list[2]), end = new date( list[3]), start_d = start.getdate(), end_d = end.getdate(), start_h = start 90 .gethours(), start_m = start.getminutes(), end_h = end.gethours(), end_m = end.getminutes(), 91 left_offset = 0, bgcolor = list[4], _left_offset = 0, width = ''; 92 if (start_d === (today + 1)) { 93 left_offset = ((23 - 8) * 60)+ ((start_h + 1) * 60)+ start_m; 94 _left_offset = left_offset - allleft; 95 width = (((23 + (end_h + 1)) - 8) * 60 + end_m) - left_offset; 96 } else if (end_d === (today + 1)) { 97 left_offset = ((start_h - 8) * 60)+ start_m; 98 _left_offset = left_offset- allleft; 99 width = (((24 + end_h) - 8) * 60 + end_m)- left_offset; 100 } else { 101 left_offset = (start_h - 8) * 60 + start_m; 102 _left_offset = left_offset- allleft; 103 width = ((end_h - 8) * 60 + end_m)- left_offset; 104 } 105 allleft = left_offset + width; 106 // 具体为什么循环1次本人也不是很清楚,我是临时想的方法解决进度条重复出现的问题,如兄台研究出了可否告知在下,在下一定感激不尽。135 if (t == 1) { 107 html = html 108 + "<span class='content' style=' background:" 109 + bgcolor 110 + ";position:absolute; width:" 111 + width 112 + "px;margin-left:" 113 + (left_offset + ml) 114 + "px;margin-top:" 115 + list[5] 116 + "px;' data-content='" 117 + list[1] 118 + ":" 119 + list[2].substring(parseint(list[2].lastindexof("/")) + 3,parseint(list[2].length)) 120 + " 至" 121 + list[3].substring(parseint(list[3].lastindexof("/")) + 3,parseint(list[3].length)) 122 + " "+ "["+ math.floor((end.gettime() - start.gettime()) / 60000) 123 + "s" + "]" + "'>"+ "</span>"; 124 t = 0; 125 break; 126 } 127 } 128 if (data[key][6] != null&& "" != data[key][6]) { 129 document.getelementbyid(data[key][0]).innerhtml = " "+ data[key][6] + ""; 130 } 131 document.getelementbyid('container').innerhtml += "<div id='lblstate' class='gantt-item' >"+ html + "</div>"; 132 removetimes += 1; 133 } 134 $('.addbox').hide(); 135 } 136 }); 137 }); 138 } 139 this.init(); 140 // 此函数是为条件查询服务的,同页面初始化显示数据同理,只是多了一些标签删除操作 141 $(function() { 142 $("#btfind") 143 .click( 144 function() { 145 var ml = null; 146 // 防止最后一栏时长标签多次添加出现追加操作,故赋值前要清空 147 document.getelementbyid("b3-1").innerhtml = " "; 148 document.getelementbyid("be-39").innerhtml = " "; 149 document.getelementbyid("be-43").innerhtml = " "; 150 document.getelementbyid("be-41").innerhtml = " "; 151 document.getelementbyid("be-04").innerhtml = " "; 152 document.getelementbyid("be-05").innerhtml = " "; 153 document.getelementbyid("be-03").innerhtml = " "; 154 document.getelementbyid("be-37").innerhtml = " "; 155 document.getelementbyid("b3-2").innerhtml = " "; 156 document.getelementbyid("be-08").innerhtml = " "; 157 document.getelementbyid("be-09").innerhtml = " "; 158 document.getelementbyid("be-51").innerhtml = " "; 159 document.getelementbyid("be-06").innerhtml = " "; 160 document.getelementbyid("b3-3").innerhtml = " "; 161 document.getelementbyid("be-01").innerhtml = " "; 162 document.getelementbyid("be-02").innerhtml = " "; 163 document.getelementbyid("be-42").innerhtml = " "; 164 document.getelementbyid("b3-15").innerhtml = " "; 165 document.getelementbyid("b3-kq").innerhtml = " "; 166 document.getelementbyid("be-40").innerhtml = " "; 167 168 if (!!window.activexobject || "activexobject" in window) { 169 ml=100; 170 for (var i = 0; i < removetimes; i++) { 171 var temp = document 172 .getelementbyid("lblstate"); 173 if (temp != null && "" != temp) { 174 document.getelementbyid("lblstate") 175 .removenode(true);//ie删除标签操作 176 } 177 } 178 }else{ 179 ml=-698; 180 for (var i = 0; i < removetimes; i++) { 181 var temp = document 182 .getelementbyid("lblstate"); 183 if (temp != null && "" != temp) { 184 document.getelementbyid("lblstate") 185 .remove();// 除ie外标签删除操作 186 } 187 } 188 } 189 // 显示遮罩层 190 $(".shadow").css({ 191 'display' : 'block' 192 }); 193 $('.addbox').show(); 194 var strdate = $("#txtbegindate").val();// 获得用户选择日期 195 var stcolor = $("#stcolor option:selected")// 获得用户选择运行状态 196 .val(); 197 var datearr = strdate.split("-");//截取日期到数组中 198 var year = parseint(datearr[0]); 199 var month; 200 //处理月份为04这样的情况 201 var datetemp = datearr[1] 202 if (datetemp.indexof("0") == 0) { 203 month = parseint(datetemp.substring(1)); 204 } else { 205 month = parseint(datetemp); 206 } 207 var day = parseint(datearr[2]); 208 if (day == 31) { 209 day = 0; 210 }// 判断日期31号时次日应1号故day为0下文使用时会对其+1变成1号而非0号 211 $.ajax({ 212 url : "${pagecontext.request.contextpath}/result", 213 type : "post", 214 data : { 215 itdate : strdate, // 日期 216 statecolor : stcolor,// 状态 217 mtype : "alltype"// 机器种类(全部或三课或eins) 218 }, 219 success : function(data) { 220 if (null == data || "" == data) { 221 alert("未查询到对应数据"); 222 $('.addbox').hide(); 223 } 224 var list = null, html = null, allleft = null, t = null, demodata = new array(), innerht; 225 for (var key = 0; key < data.length; key++) { //第一层循环取到各个list 226 list = data[key], 227 html = '', 228 allleft = 0, t = 1; 229 var len = list.length; 230 for (var i = 0; i < len; i++) { //第二层循环取list中的对象 231 var start = new date( 232 list[2]), end = new date( 233 list[3]), start_d = start.getdate(), end_d = end.getdate(), start_h = start .gethours(); 234 start_m = start.getminutes(), 235 start_s = start.getseconds(), 236 end_h = end.gethours(), 237 end_m = end.getminutes(), 238 end_s = end.getseconds(), 239 left_offset = 0, 240 bgcolor = list[4], 241 _left_offset = 0, 242 width = ''; 243 /* alert(list[0]+":"+(math.abs(end.gettime()-start.gettime()))/(1000*60)); */ 244 if (start_d === (day + 1)) { 245 left_offset = ((23 - 8) * 60)+ ((start_h + 1) * 60)+ start_m+ start_s/ 60; 246 _left_offset = left_offset- allleft; 247 width = (((23 + (end_h + 1)) - 8)* 60+ end_m + end_s / 60)- left_offset; 248 } else if (end_d === (day + 1)) { 249 left_offset = ((start_h - 8) * 60)+ start_m+ start_s/ 60; 250 _left_offset = left_offset- allleft; 251 width = (((24 + end_h) - 8)* 60+ end_m + end_s / 60)- left_offset; 252 } else { 253 left_offset = (start_h - 8)* 60+ start_m+ start_s/ 60; 254 _left_offset = left_offset- allleft; 255 width = ((end_h - 8)* 60 + end_m + end_s / 60)- left_offset; 256 } 257 allleft = left_offset+ width; 258 if (t == 1) { 259 html = html+ "<span class='content' style=' background:" + bgcolor+ ";position:absolute; width:"+ width+ "px;margin-left:"+ (left_offset + ml) + "px;margin-top:" 260 + list[5] + "px;' data-content='"+ list[1]+ ":"+ list[2].substring( parseint(list[2].lastindexof("/")) + 3,parseint(list[2].length))+ " 至" 261 + list[3].substring(parseint(list[3].lastindexof("/")) + 3,parseint(list[3].length))+ " "+ "["+ ((end.gettime() - start.gettime()) / 60000).tofixed(2)+ "m" + "]" 262 + "'>" 263 + "</span>"; 264 t = 0; 265 break; 266 } 267 break; 268 } 269 if (data[key][6] != null 270 && "" != data[key][6]) { 271 document .getelementbyid(data[key][0]).innerhtml = " "+ data[key][6] + ""; 272 } 273 innerht += "<div id='lblstate' class='gantt-item' >" + html + "</div>"; 274 removetimes += 1; 275 } 276 document .getelementbyid('container').innerhtml += innerht; 277 $('.addbox').hide(); 278 $(".shadow").css({ 279 'display' : 'none' 280 }); 281 } 282 }); 283 }); 284 }); 285 </script>
以上为显示层
控制层(handler):
1 @requestmapping(value = "/data", method = requestmethod.post) 2 @responsebody 3 public arraylist<arraylist<string>> getdata(string itdate, string mtype, string tcolor) { 4 return gs.searchdata(mtype, itdate, tcolor); 5 }// 页面初始数据查询 6 7 //多条件数据查询 8 @requestmapping(value = "/result", method = requestmethod.post) 9 @responsebody 10 public arraylist<arraylist<string>> finddata(string itdate, string statecolor, string mtype) { 11 return gs.searchdata(mtype, itdate, statecolor); 12 }
...不罗嗦直接进入持久层(dao):
1 @repository("machinestatedao") 2 public class machinestatedaoimp implements machinestatedao { 3 4 /** 5 * 6 * @title: finddata @description: todo(查询指定条件下的机床运行情况) @param mtemp 机床种类 @param 7 * itdate 日期 @param statecolor 运行状态 @return arraylist<arraylist<string>> 8 * 指定日期下指定类型中机床指定状态的运行状态 @throws 9 */ 10 public arraylist<arraylist<string>> finddata(string mtemp, string itdate, string statecolor) { 11 /** 12 * 年月日+时分秒 13 */ 14 itdate += " 08:00:00"; 15 /** 16 * 日期格式化 17 */ 18 simpledateformat simdate = new simpledateformat("yyyy-mm-dd hh:mm:ss"); 19 /** 20 * 创建开始日期 21 */ 22 date begintime = null; 23 if (itdate != null && !"".equals(itdate)) { 24 try { 25 begintime = simdate.parse(itdate); 26 } catch (parseexception e) { 27 e.printstacktrace(); 28 } 29 } 30 /** 31 * 当前日期设置为结束日期 32 */ 33 calendar calendar = calendar.getinstance(); 34 calendar.settime(begintime); 35 calendar.set(calendar.get(calendar.year), calendar.get(calendar.month), calendar.get(calendar.date) + 1); 36 string endtime = simdate.format(calendar.gettime()); 37 /** 38 * 多条件查询(日期、机器种类),以及必须根据机器种类在前和日期在后排序 39 */ 40 string sql = "select * from [demo191128].[dbo].[t_zj_machine_state_eins] where 1=1"; 41 if (itdate != null && !"".equals(itdate)) { 42 sql += " and fdate>='" + itdate + "' and fdate<='" + endtime + "'"; 43 } 44 if (mtemp.equals("eins")) { 45 sql += " and fmachine like 'ce%'"; 46 } 47 if (mtemp.equals("third")) { 48 sql += " and fmachine like 'b%'"; 49 } 50 sql += " order by fmachine,fdate"; 51 /** 52 * 数据库连接 此处使用preparedstatement防止sql注入 53 */ 54 connection conn = jdbctools.getconnection(); 55 preparedstatement ps = null; 56 resultset rs = null; 57 list<machinestate> list = new arraylist<machinestate>(); 58 try { 59 ps = conn.preparestatement(sql); 60 rs = ps.executequery(); 61 while (rs.next()) { 62 machinestate ms = new machinestate(); 63 ms.setfno(rs.getint("fno")); 64 stringbuilder temp = new stringbuilder(rs.getstring("fmachine")); 65 /** 66 * 此处由于数据库存储的都是ce开头的机器型号,但是有所变动故将ce开头的机器型号用be代替 67 */ 68 if ((rs.getstring("fmachine").contains("ce"))) { 69 temp.replace(0, 2, "be"); 70 } 71 /** 72 * 将数据库中的数据转换为对象 73 */ 74 ms.setfmachine(new string(temp)); 75 ms.setfstatecode(rs.getstring("fstatecode")); 76 ms.setfstateinfo(rs.getstring("fstateinfo")); 77 ms.setfdate(rs.gettimestamp("fdate")); 78 if (!ms.getfstateinfo().equals("关机") && !ms.getfstateinfo().equals("开机")) { 79 list.add(ms); 80 } 81 } 82 } catch (sqlexception e) { 83 e.printstacktrace(); 84 } finally { 85 try { 86 conn.close(); 87 ps.close(); 88 } catch (sqlexception e) { 89 e.printstacktrace(); 90 } 91 } 92 arraylist<arraylist<string>> list = new arraylist<arraylist<string>>(); 93 /** 94 * 状态持续时间 95 */ 96 int alltime = 0; 97 for (int i = 0; i < list.size() - 1; i++) { 98 arraylist<string> liststr = new arraylist<string>(); 99 if (list.get(i).getfmachine().equals(list.get(i + 1).getfmachine())) { 100 simpledateformat formatter = new simpledateformat("yyyy/mm/dd hh:mm:ss"); 101 liststr.add(list.get(i).getfmachine()); 102 liststr.add(list.get(i).getfstateinfo()); 103 liststr.add("" + formatter.format(list.get(i).getfdate())); 104 liststr.add("" + formatter.format(list.get(i + 1).getfdate())); 105 /** 106 * 根据机器种类条件给机器对象添加状态颜色和该机器运行时长 107 */ 108 if (!statecolor.equals("all")) { 109 if (liststr.get(1).equals("待机")) { 110 liststr.add("orange"); 111 if (liststr.get(4).equals(statecolor)) { 112 if (mtemp.equals("alltype")) { 113 methodall(list, i, liststr); 114 } 115 if (mtemp.equals("eins")) { 116 methodeins(list, i, liststr); 117 } 118 if (mtemp.equals("third")) { 119 methodthird(list, i, liststr); 120 } 121 alltime += ((list.get(i + 1).getfdate().gettime() - list.get(i).getfdate().gettime()) / 1000 122 / 60); 123 liststr.add(alltime + ""); 124 list.add(liststr); 125 } 126 } else if (liststr.get(1).equals("运行")) { 127 liststr.add("green"); 128 if (liststr.get(4).equals(statecolor)) { 129 if (mtemp.equals("alltype")) { 130 methodall(list, i, liststr); 131 } 132 if (mtemp.equals("eins")) { 133 methodeins(list, i, liststr); 134 } 135 if (mtemp.equals("third")) { 136 methodthird(list, i, liststr); 137 } 138 // liststr.add(((list.get(i + 1).getfdate().gettime() - list.get(i).getfdate().gettime()) / 1000 / 60)+"" ); 139 alltime += ((list.get(i + 1).getfdate().gettime() - list.get(i).getfdate().gettime()) / 1000 140 / 60); 141 liststr.add(alltime + ""); 142 143 list.add(liststr); 144 } 145 } else if (liststr.get(1).equals("停机")) { 146 liststr.add("red"); 147 if (liststr.get(4).equals(statecolor)) { 148 if (mtemp.equals("alltype")) { 149 methodall(list, i, liststr); 150 } 151 if (mtemp.equals("eins")) { 152 methodeins(list, i, liststr); 153 } 154 if (mtemp.equals("third")) { 155 methodthird(list, i, liststr); 156 } 157 alltime += ((list.get(i + 1).getfdate().gettime() - list.get(i).getfdate().gettime()) / 1000 158 / 60); 159 liststr.add(alltime + ""); 160 list.add(liststr); 161 } 162 } 163 } else { 164 if (liststr.get(1).equals("待机")) { 165 liststr.add("orange"); 166 167 } else if (liststr.get(1).equals("运行")) { 168 liststr.add("green"); 169 170 } else if (liststr.get(1).equals("停机")) { 171 liststr.add("red"); 172 } 173 if (mtemp.equals("alltype")) { 174 methodall(list, i, liststr); 175 } 176 if (mtemp.equals("eins")) { 177 methodeins(list, i, liststr); 178 } 179 if (mtemp.equals("third")) { 180 methodthird(list, i, liststr); 181 } 182 alltime += ((list.get(i + 1).getfdate().gettime() - list.get(i).getfdate().gettime()) / 1000 / 60); 183 liststr.add(alltime + ""); 184 list.add(liststr); 185 } 186 187 } else { 188 alltime = 0; 189 } 190 191 } 192 return list; 193 } 194 195 /** 196 * 197 * @title: methodall @description: todo(根据浏览器显示的机器名称位置设置将要显示机器状态条距顶部的距离) @param 198 * list 机器对象 @param i 集合下标 @param liststr 字符串集合 @return 无 @throws 199 */ 200 public void methodall(list<machinestate> list, int i, list<string> liststr) { 201 if (list.get(i).getfmachine().equals("b3-1")) { 202 liststr.add("32");// * 203 } else if (list.get(i).getfmachine().equals("b3-2")) { 204 liststr.add("75");// * 205 } else if (list.get(i).getfmachine().equals("b3-3")) { 206 liststr.add("117");// * 207 } else if (list.get(i).getfmachine().equals("b3-15")) { 208 liststr.add("162");// * 209 } else if (list.get(i).getfmachine().equals("b3-kq")) { 210 liststr.add("205");// * 211 } else if (list.get(i).getfmachine().equals("be-01")) { 212 liststr.add("247");// * 213 } else if (list.get(i).getfmachine().equals("be-02")) { 214 liststr.add("290");// * 215 } else if (list.get(i).getfmachine().equals("be-03")) { 216 liststr.add("333");// * 217 } else if (list.get(i).getfmachine().equals("be-04")) { 218 liststr.add("376");// * 219 } else if (list.get(i).getfmachine().equals("be-05")) { 220 liststr.add("420");// * 221 } else if (list.get(i).getfmachine().equals("be-06")) { 222 liststr.add("463");// * 223 } else if (list.get(i).getfmachine().equals("be-08")) { 224 liststr.add("506");// * 225 } else if (list.get(i).getfmachine().equals("be-09")) { 226 liststr.add("547");// * 227 } else if (list.get(i).getfmachine().equals("be-37")) { 228 liststr.add("592");// * 229 } else if (list.get(i).getfmachine().equals("be-39")) { 230 liststr.add("634");// * 231 } else if (list.get(i).getfmachine().equals("be-40")) { 232 liststr.add("676");// * 233 } else if (list.get(i).getfmachine().equals("be-41")) { 234 liststr.add("720");// * 235 } else if (list.get(i).getfmachine().equals("be-42")) { 236 liststr.add("763");// * 237 } else if (list.get(i).getfmachine().equals("be-43")) { 238 liststr.add("804");// * 239 } else if (list.get(i).getfmachine().equals("be-51")) { 240 liststr.add("848");// * 241 } 242 } 243 244 /** 245 * 246 * @title: methodeins @description: todo(根据浏览器显示的机器名称位置设置将要显示机器状态条距顶部的距离) @param 247 * list 机器对象 @param i 集合下标 @param liststr 字符串集合 @return 无 @throws 248 */ 249 public void methodeins(list<machinestate> list, int i, list<string> liststr) { 250 if (list.get(i).getfmachine().equals("be-01")) { 251 liststr.add("32");// * 252 } else if (list.get(i).getfmachine().equals("be-02")) { 253 liststr.add("75");// * 254 } else if (list.get(i).getfmachine().equals("be-03")) { 255 liststr.add("117");// * 256 } else if (list.get(i).getfmachine().equals("be-04")) { 257 liststr.add("162");// * 258 } else if (list.get(i).getfmachine().equals("be-05")) { 259 liststr.add("205");// * 260 } else if (list.get(i).getfmachine().equals("be-06")) { 261 liststr.add("247");// * 262 } else if (list.get(i).getfmachine().equals("be-08")) { 263 liststr.add("290");// * 264 } else if (list.get(i).getfmachine().equals("be-09")) { 265 liststr.add("333");// * 266 } else if (list.get(i).getfmachine().equals("be-37")) { 267 liststr.add("376");// * 268 } else if (list.get(i).getfmachine().equals("be-39")) { 269 liststr.add("420");// * 270 } else if (list.get(i).getfmachine().equals("be-40")) { 271 liststr.add("463");// * 272 } else if (list.get(i).getfmachine().equals("be-41")) { 273 liststr.add("506");// * 274 } else if (list.get(i).getfmachine().equals("be-42")) { 275 liststr.add("547");// * 276 } else if (list.get(i).getfmachine().equals("be-43")) { 277 liststr.add("592");// * 278 } else if (list.get(i).getfmachine().equals("be-51")) { 279 liststr.add("634");// * 280 } 281 } 282 283 /** 284 * 285 * @title: methodthird @description: 286 * todo(根据浏览器显示的机器名称位置设置将要显示机器状态条距顶部的距离) @param list 机器对象 @param i 集合下标 @param 287 * liststr 字符串集合 @return 无 @throws 288 */ 289 public void methodthird(list<machinestate> list, int i, list<string> liststr) { 290 if (list.get(i).getfmachine().equals("b3-1")) { 291 liststr.add("32");// * 292 } else if (list.get(i).getfmachine().equals("b3-2")) { 293 liststr.add("75");// * 294 } else if (list.get(i).getfmachine().equals("b3-3")) { 295 liststr.add("117");// * 296 } else if (list.get(i).getfmachine().equals("b3-15")) { 297 liststr.add("162");// * 298 } else if (list.get(i).getfmachine().equals("b3-kq")) { 299 liststr.add("205");// * 300 } 301 }
数据库部分数据展示:
能不能看的懂,
就看兄弟你的了,
有不懂的可以留言,
有时间我会回复的!
当然了,你如果还想了解前端代码,可以去下载源代码
或者先看