WEB甘特图(机器运行状态图)

六月ゝ 毕业季﹏ 提交于 2019-12-18 15:49:55

  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;">&nbsp;</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;">&nbsp;</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;">&nbsp;</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;">&nbsp;</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;">&nbsp;</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;">&nbsp;</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;">&nbsp;</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;">&nbsp;</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;">&nbsp;</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;">&nbsp;</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;">&nbsp;</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;">&nbsp;</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;">&nbsp;</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;">&nbsp;</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;">&nbsp;</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;">&nbsp;</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;">&nbsp;</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;">&nbsp;</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;">&nbsp;</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;">&nbsp;</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         
200         
201 
202         <!-- Control Sidebar -->
203         <aside class="control-sidebar control-sidebar-dark">
204             <!-- Control sidebar content goes here -->
205         </aside>
206         <!-- /.control-sidebar -->
207     </div>
208 
209     <div id="addBox" class="addBox">
210         <a href="javascript:;"
211             onclick="jQuery('.addBox').hide();jQuery('.shadow').hide();"
212             class="close"></a>
213     </div>
214     <!--遮罩层-->
215     <div class="shadow" id="progress">
216         <div class="container">
217             <div class="warning">
218   <!-- 等待页面加载为一张gif的Loading图片 -->
219                 <img style="margin-top: 400px; margin-left: 500px;"
220                     src="${pageContext.request.contextPath}/images/2.gif">
221             </div>
222         </div>
223     </div>
  1 <script type="text/javascript">
  2         $(function() {
  3        //日期插件 datapicker
  4             
  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 
 20                     }).on('cancel.daterangepicker', function(ev, picker) {
 21                 $("#submitDate").val("");
 22             }).on('apply.daterangepicker', function(ev, picker) {
 23                 $("#submitDate").val(picker.startDate.format('YYYY-MM-DD'));
 24                 $("#txtBeginDate").val(picker.startDate.format('YYYY-MM-DD'));
 25             });
 26         });
 27      // 记录添加机器状态条的次数
 28         var removetimes = 0;
 29         // 初始化
 30         function init() {
 31             
 32             this.createHours();
 33             this.createData();
 34         }
 35       //  页面初始化数据准备
 36         function createData() {
 37             var ml = null; // 为了解决IE和火狐机器状态条相对左边位置不同问题 故只能设置变量进行解决
 38              39             // 日期文本框中显示出昨天日期 40             var date = new Date();
 41             var seperator1 = "-";
 42             var year = date.getFullYear();
 43             var month = date.getMonth() + 1;
 44             var strDate = date.getDate() - 1;
 45             if (month >= 1 && month <= 9) {
 46                 month = "0" + month;
 47             }
 48             if (strDate >= 0 && strDate <= 9) {
 49                 strDate = "0" + strDate;
 50             }
 51 
 52             var today = date.getDate() - 1; // 今天的日期
 53 
 54             if (today == 0) {
 55                 if (month == 1 || month == 3 || month == 5 || month == 8
 56                         || month == 10 || month == 11) {
 57 
 58                     month -= 1;
 59                     strDate = 31;
 60                 } else {
 61 
 62                     month -= 1;
 63                     strDate = 30;
 64                 }
 65             }
 66             var currentdate = "" + year + seperator1 + month + seperator1
 67                     + strDate;  // 拼接日期显示在文本框中
 68              69             $(function() {
 70                 $
 71                         .ajax({
 72                             type : "post",
 73                             url : "${pageContext.request.contextPath}/data",
 74                             dataType : "json",
 75                             data : {
 76                                 itdate : currentdate,
 77                                 mtype : "alltype",
 78                                 tcolor : "all"
 79                             },
 80                             success : function(data) {
 81                                 document.getElementById("txtBeginDate").value = currentdate;// 为日期文本框赋值
 82                                 $('.addBox').show();// 控制遮盖层的显示
 83                                 if (null == data || "" == data) {
 84                                     $('.addBox').hide();
 85                                 }// 返回数据为空时立即隐藏遮盖层
 86                                 if (!!window.ActiveXobject
 87                                         || "ActiveXObject" in window) {
 88                                     ml = 100;
 89                                 } else {
 90                                     ml = -698;
 91                                 }// 判断用户所使用的浏览器,然后根据估计增加或减少机器进度条margin-left的大小,目的是为了让时刻与顶部时间栏对应
 92                                 var demoData = new Array(), List = null, html = null, allLeft = null;
 93                                 t = null;// 统一创建变量避免占用资源,提高效率
 94                                 for (var key = 0; key < data.length; key++) { //第一层循环取到大集合中的各个list
 95                                     List = data[key];
 96                                     html = '', allLeft = 0, t = 1;
 97                                     var len = List.length;
 98                                     for (var i = 0; i < len; i++) { //第二层循环取到list中的对象
 99                         // 根据时间计算机器状态条的长度,1分钟1px,此具体计算方法借鉴而来
100                                         var start = new Date(List[2]), end = new Date(
101                                                 List[3]), start_d = start
102                                                 .getDate(), end_d = end
103                                                 .getDate(), start_h = start
104                                                 .getHours(), start_m = start
105                                                 .getMinutes(), end_h = end
106                                                 .getHours(), end_m = end
107                                                 .getMinutes(), left_offset = 0, bgcolor = List[4], _left_offset = 0, width = '';
108                                         if (start_d === (today + 1)) {
109                                             left_offset = ((23 - 8) * 60)
110                                                     + ((start_h + 1) * 60)
111                                                     + start_m;
112                                             _left_offset = left_offset
113                                                     - allLeft;
114                                             width = (((23 + (end_h + 1)) - 8) * 60 + end_m)
115                                                     - left_offset;
116 
117                                         } else if (end_d === (today + 1)) {
118                                             left_offset = ((start_h - 8) * 60)
119                                                     + start_m;
120                                             _left_offset = left_offset
121                                                     - allLeft;
122                                             width = (((24 + end_h) - 8) * 60 + end_m)
123                                                     - left_offset;
124                                         } else {
125                                             left_offset = (start_h - 8) * 60
126                                                     + start_m;
127                                             _left_offset = left_offset
128                                                     - allLeft;
129                                             width = ((end_h - 8) * 60 + end_m)
130                                                     - left_offset;
131 
132                                         }
133                                         allLeft = left_offset + width;
134                                        // 具体为什么循环1次本人也不是很清楚,我是临时想的方法解决进度条重复出现的问题,如兄台研究出了可否告知在下,在下一定感激不尽。135                                             if (t == 1) {
136                                                 html = html
137                                                         + "<span class='content' style=' background:"
138                                                         + bgcolor
139                                                         + ";position:absolute; width:"
140                                                         + width
141                                                         + "px;margin-left:"
142                                                         + (left_offset + ml)
143                                                         + "px;margin-top:"
144                                                         + List[5]
145                                                         + "px;' data-content='"
146                                                         + List[1]
147                                                         + ":"
148                                                         + List[2]
149                                                                 .substring(
150                                                                         parseInt(List[2]
151                                                                                 .lastIndexOf("/")) + 3,
152                                                                         parseInt(List[2].length))
153                                                         + " 至"
154                                                         + List[3]
155                                                                 .substring(
156                                                                         parseInt(List[3]
157                                                                                 .lastIndexOf("/")) + 3,
158                                                                         parseInt(List[3].length))
159                                                         + "&nbsp;"
160                                                         + "["
161                                                         + Math
162                                                                 .floor((end
163                                                                         .getTime() - start
164                                                                         .getTime()) / 60000)
165                                                         + "s" + "]" + "'>"
166                                                         + "</span>";
167                                                 t = 0;
168                                                 break;
169                                             }
170 171 
172                                     }
173                                     if (data[key][6] != null
174                                             && "" != data[key][6]) {
175                                         document.getElementById(data[key][0]).innerHTML = "&nbsp;"
176                                                 + data[key][6] + "";
177                                     }
178                                     document.getElementById('container').innerHTML += "<div id='lblstate' class='gantt-item' >"
179                                             + html + "</div>";
180                                     removetimes += 1;
181                                 }
182                                 $('.addBox').hide();
183                             }
184                         });
185 
186             });
187 
188         }
189         this.init();
190      // 此函数是为条件查询服务的,同页面初始化显示数据同理,只是多了一些标签删除操作
191         $(function() {
192             $("#btfind")
193                     .click(
194                             function() {
195                                 var ml = null;
196                    // 防止最后一栏时长标签多次添加出现追加操作,故赋值前要清空
197                                 document.getElementById("B3-1").innerHTML = "&nbsp;";
198                                 document.getElementById("BE-39").innerHTML = "&nbsp;";
199                                 document.getElementById("BE-43").innerHTML = "&nbsp;";
200                                 document.getElementById("BE-41").innerHTML = "&nbsp;";
201                                 document.getElementById("BE-04").innerHTML = "&nbsp;";
202                                 document.getElementById("BE-05").innerHTML = "&nbsp;";
203                                 document.getElementById("BE-03").innerHTML = "&nbsp;";
204                                 document.getElementById("BE-37").innerHTML = "&nbsp;";
205                                 document.getElementById("B3-2").innerHTML = "&nbsp;";
206                                 document.getElementById("BE-08").innerHTML = "&nbsp;";
207                                 document.getElementById("BE-09").innerHTML = "&nbsp;";
208                                 document.getElementById("BE-51").innerHTML = "&nbsp;";
209                                 document.getElementById("BE-06").innerHTML = "&nbsp;";
210                                 document.getElementById("B3-3").innerHTML = "&nbsp;";
211                                 document.getElementById("BE-01").innerHTML = "&nbsp;";
212                                 document.getElementById("BE-02").innerHTML = "&nbsp;";
213                                 document.getElementById("BE-42").innerHTML = "&nbsp;";
214                                 document.getElementById("B3-15").innerHTML = "&nbsp;";
215                                 document.getElementById("B3-KQ").innerHTML = "&nbsp;";
216                                 document.getElementById("BE-40").innerHTML = "&nbsp;";
217 
218                                 if (!!window.ActiveXobject || "ActiveXObject" in window) {
219                                     ml=100;
220                                     for (var i = 0; i < removetimes; i++) {
221                                         var temp = document
222                                                 .getElementById("lblstate");
223                                         if (temp != null && "" != temp) {
224                                             document.getElementById("lblstate")
225                                             .removeNode(true);//IE删除标签操作
226                                         }
227                                     }
228                                 }else{
229                                     ml=-698;
230                                     for (var i = 0; i < removetimes; i++) {
231                                         var temp = document
232                                                 .getElementById("lblstate");
233                                         if (temp != null && "" != temp) {
234                                             document.getElementById("lblstate")
235                                                     .remove();// 除IE外标签删除操作
236                                         }
237                                     }
238                                 }
239                    // 显示遮罩层
240                                 $(".shadow").css({
241                                     'display' : 'block'
242                                 });
243                                 $('.addBox').show();
244                                 var strdate = $("#txtBeginDate").val();// 获得用户选择日期
245                                 var stColor = $("#stcolor option:selected")// 获得用户选择运行状态
246                                         .val();
247                                 var dateArr = strdate.split("-");//截取日期到数组中
248                                 var year = parseInt(dateArr[0]);
249                                 var month;
250                                 //处理月份为04这样的情况                
251                                 var dateTemp = dateArr[1]
252                                 if (dateTemp.indexOf("0") == 0) {
253                                     month = parseInt(dateTemp.substring(1));
254                                 } else {
255                                     month = parseInt(dateTemp);
256                                 }
257                                 var day = parseInt(dateArr[2]);
258                                 if (day == 31) {
259                                     day = 0;
260                                 }// 判断日期31号时次日应1号故day为0下文使用时会对其+1变成1号而非0号
261                                 $
262                                         .ajax({
263                                             url : "${pageContext.request.contextPath}/result",
264                                             type : "post",
265                                             data : {
266                                                 itdate : strdate,  // 日期
267                                                 stateColor : stColor,// 状态
268                                                 mtype : "alltype"// 机器种类(全部或三课或eins)
269                                             },
270 
271                                             success : function(data) {
272 
273                                                 if (null == data || "" == data) {
274 
275                                                     alert("未查询到对应数据");
276                                                     $('.addBox').hide();
277 
278                                                 }
279 
280                                                 var List = null, html = null, allLeft = null, t = null, demoData = new Array(), innerht;
281 
282                                                 for (var key = 0; key < data.length; key++) { //第一层循环取到各个list
283 
284                                                     List = data[key],
285                                                             html = '',
286                                                             allLeft = 0, t = 1;
287                                                     var len = List.length;
288                                                     for (var i = 0; i < len; i++) { //第二层循环取list中的对象
289                                                         var start = new Date(
290                                                                 List[2]), end = new Date(
291                                                                 List[3]), start_d = start
292                                                                 .getDate(), end_d = end
293                                                                 .getDate(), start_h = start
294                                                                 .getHours();
295                                                                 start_m = start
296                                                                         .getMinutes(),
297                                                                 start_s = start
298                                                                         .getSeconds(),
299                                                                 end_h = end
300                                                                         .getHours(),
301                                                                 end_m = end
302                                                                         .getMinutes(),
303                                                                 end_s = end
304                                                                         .getSeconds(),
305                                                                 left_offset = 0,
306                                                                 bgcolor = List[4],
307                                                                 _left_offset = 0,
308                                                                 width = '';
309                                                         /* alert(List[0]+":"+(Math.abs(end.getTime()-start.getTime()))/(1000*60)); */
310                                                         if (start_d === (day + 1)) {
311                                                             left_offset = ((23 - 8) * 60)
312                                                                     + ((start_h + 1) * 60)
313                                                                     + start_m
314                                                                     + start_s
315                                                                     / 60;
316                                                             _left_offset = left_offset
317                                                                     - allLeft;
318                                                             width = (((23 + (end_h + 1)) - 8)
319                                                                     * 60
320                                                                     + end_m + end_s / 60)
321                                                                     - left_offset;
322 
323                                                         } else if (end_d === (day + 1)) {
324                                                             left_offset = ((start_h - 8) * 60)
325                                                                     + start_m
326                                                                     + start_s
327                                                                     / 60;
328                                                             _left_offset = left_offset
329                                                                     - allLeft;
330                                                             width = (((24 + end_h) - 8)
331                                                                     * 60
332                                                                     + end_m + end_s / 60)
333                                                                     - left_offset;
334                                                         } else {
335                                                             left_offset = (start_h - 8)
336                                                                     * 60
337                                                                     + start_m
338                                                                     + start_s
339                                                                     / 60;
340                                                             _left_offset = left_offset
341                                                                     - allLeft;
342                                                             width = ((end_h - 8)
343                                                                     * 60
344                                                                     + end_m + end_s / 60)
345                                                                     - left_offset;
346 
347                                                         }
348                                                         allLeft = left_offset
349                                                                 + width;
350                                                         if (t == 1) {
351                                                             html = html
352                                                                     + "<span class='content' style=' background:"
353                                                                     + bgcolor
354                                                                     + ";position:absolute; width:"
355                                                                     + width
356                                                                     + "px;margin-left:"
357                                                                     + (left_offset + ml)
358                                                                     + "px;margin-top:"
359                                                                     + List[5]
360                                                                     + "px;' data-content='"
361                                                                     + List[1]
362                                                                     + ":"
363                                                                     + List[2]
364                                                                             .substring(
365                                                                                     parseInt(List[2]
366                                                                                             .lastIndexOf("/")) + 3,
367                                                                                     parseInt(List[2].length))
368                                                                     + " 至"
369                                                                     + List[3]
370                                                                             .substring(
371                                                                                     parseInt(List[3]
372                                                                                             .lastIndexOf("/")) + 3,
373                                                                                     parseInt(List[3].length))
374                                                                     + "&nbsp;"
375                                                                     + "["
376                                                                     + ((end
377                                                                             .getTime() - start
378                                                                             .getTime()) / 60000)
379                                                                             .toFixed(2)
380                                                                     + "m" + "]"
381                                                                     + "'>"
382                                                                     + "</span>";
383                                                             t = 0;
384                                                             break;
385                                                         }
386                                                         break;
387                                                     }
388                                                     if (data[key][6] != null
389                                                             && "" != data[key][6]) {
390                                                         document
391                                                                 .getElementById(data[key][0]).innerHTML = "&nbsp;&nbsp;"
392                                                                 + data[key][6]
393                                                                 + "";
394                                                     }
395                                                     innerht += "<div id='lblstate' class='gantt-item' >"
396                                                             + html + "</div>";
397 
398                                                     removetimes += 1;
399                                                 }
400                                                 document
401                                                         .getElementById('container').innerHTML += innerht;
402                                                 $('.addBox').hide();
403                                                 $(".shadow").css({
404                                                     'display' : 'none'
405                                                 });
406                                             }
407                                         });
408 
409                             });
410 
411         });
412     </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     }

数据库部分数据展示:

能不能看的懂,

就看兄弟你的了,

有不懂的可以留言,

有时间我会回复的!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!