电力项目六--运行监控设计

运行监控的分析设计

需求:业务人员在当天,按照每个时间段,录入设备和站点管理的分公司的设备和站点运行情况。

数据库的设计方案:

方案一:

方案二:

 数据库表结构

创建表后,建立映射文件:

CREATE TABLE Elec_CommonMsg(
    comID VARCHAR(50) NOT NULL PRIMARY KEY COMMENT '主键ID',
    stationRun VARCHAR(5000) NULL COMMENT '站点运行情况',
    devRun VARCHAR(5000) NULL COMMENT '设备运行情况',
    createDate DATETIME NULL COMMENT'创建日期'
);

 然后写对应的Elec_CommonMsg.java和ElecCommonMsg.hbm.xml和hibernate.cfg.xml文件

 ElecCommonMsg.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC 
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="com.elec.domain.ElecCommonMsg" table="elec_commonmsg">
        <id name="comID" type="string" column="comID">
                <generator class="uuid"></generator>            
        </id>
        <property name="stationRun" type="string" column="stationRun"></property>
        <property name="devRun" type="string" column="devRun"></property>
        <property name="createDate" type="string" column="createDate"></property>
    </class>
</hibernate-mapping>

 然后写对应的Dao层,service层的代码,这就不写了

在action层,ElecCommonMsgAction.java  先显示出运行监控页面来,然后将运行监控表中的数据回显到也上来

package com.elec.web.action;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.elec.domain.ElecCommonMsg;
import com.elec.service.IElecCommonMsgService;
import com.elec.service.IElecTextService;
import com.elec.web.utils.ValueUtils;
import com.opensymphony.xwork2.ModelDriven;

/**
 * @author kj
 *
 */

@SuppressWarnings("serial")
@Controller("elecCommonMsgAction")
@Scope(value="prototype")
public class ElecCommonMsgAction extends BaseAction<ElecCommonMsg> implements ModelDriven<ElecCommonMsg>{
    
    ElecCommonMsg elecCommonMsg = this.getModel();
    
    @Resource(name=IElecCommonMsgService.SERVICE_NAME)
    IElecCommonMsgService elecCommonMsgService;
    /**
     * @Name
     * @Description: 运行监控的首页
     * @author kj
     * @version:
     * @create Date:
     * @return String 跳转到actingIndex.jsp
     */
    public String home(){
//        1.查询数据库运行监控表的数据,返回唯一的ElecCommonMsg 
        ElecCommonMsg ecm = elecCommonMsgService.findCommonMsg();
//            2.将ElecCommonMsg对象压入栈顶,支持表单回显    
//        ServletActionContext.getContext().getValueStack().push(ecm);   //  后边有复用,写到公用方法中去
        ValueUtils.putValueStack(ecm);
        return "home";
    }
}

 对应的ElecCommonMsgServiceImpl.java中 findCommonMsg()方法

/**    @Name  findCommonMsg
     * @Description: 查询运行监控表的数据
     * @author kj
     * @version: V1.00
     * @create Date: 2017-05-19
     * @return String 
     */
    @Override
    public ElecCommonMsg findCommonMsg() {
        List<ElecCommonMsg> list = elecCommonMsgDao.findCollectionByConditionNoPage("", null, null); //返回list结果集
        ElecCommonMsg elecCommonMsg =  null;
        if(list.size() > 0 && list != null){
            elecCommonMsg = list.get(0);
        }
        return elecCommonMsg;
    }

 同时把对象压入栈顶的方法抽取出到方法类中:此处使用Object类

public class ValueUtils {

    //将对象压入栈顶
    public static void putValueStack(Object object) {
        // TODO Auto-generated method stub
        ServletActionContext.getContext().getValueStack().push(object);
    }

}

 对应的struts.xml文件中

<!-- 运行监控 -->
<action name="elecCommonMsgAction_*" class="elecCommonMsgAction" method="{1}">
<result name="home">/WEB-INF/page/system/actingIndex.jsp</result>
</action>

对应的

页面中需要引入taglib标签: <%@ tablig uri="/struts-tags" prefix="s" %>

<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>

<html>
<head>
<title>运行监控模块编辑</title>
<link href="${pageContext.request.contextPath }/css/Style.css" type="text/css" rel="stylesheet">
<link href="${pageContext.request.contextPath }/css/showText.css" type="text/css" rel="stylesheet">
<script language="javascript" src="${pageContext.request.contextPath }/script/function.js"></script>
<script language="javascript" src="${pageContext.request.contextPath }/script/limitedTextarea.js"></script>
<script language="javascript" src="${pageContext.request.contextPath }/script/showText.js"></script>
  <script language="javascript"> 
  function checkchar(){
  
          if(document.Form2.stationRun.value.length>2500){
      
             alert("站点运行情况字数不能超过2500字");
             return;
          }
          if(document.Form2.devRun.value.length>2500){
      
             alert("设备运行情况字数不能超过2500字");
             return;
          }
          document.Form2.action="savePending.do";
          document.Form2.submit();
          alert(" 待办事宜保存成功!");
  }
  function addEnter(element){
           document.getElementById(element).value = document.getElementById(element).value+"<br>";
   
  }
  function checkTextAreaLen(){
          var stationRun = new Bs_LimitedTextarea('stationRun', 2500); 
        stationRun.infolineCssStyle = "font-family:arial; font-size:11px; color:gray;";
        stationRun.draw();    
      
        var devRun = new Bs_LimitedTextarea('devRun', 2500); 
        devRun.infolineCssStyle = "font-family:arial; font-size:11px; color:gray;";
        devRun.draw();    
  }
  window.onload=function(){
        checkTextAreaLen();
  }
  
  </script>


</head>

<body>
<form name="Form1" id="Form1" method="post">
    <table cellSpacing="1" cellPadding="0" width="90%" align="center" bgColor="#f5fafe" border="0">
        <TBODY>
            <TR height=10><td></td></TR>            
            <tr>
                  <td>
                    <TABLE style="WIDTH: 105px; HEIGHT: 20px" border="0">
                                    <TR>
                                        <TD align="center" background="${pageContext.request.contextPath }/images/cotNavGround.gif"><img src="${pageContext.request.contextPath }/images/yin.gif" width="15"></TD>
                                        <TD class="DropShadow" background="${pageContext.request.contextPath }/images/cotNavGround.gif">运行监控列表</TD>
                                    </TR>
                     </TABLE>
                  </td>
            </tr>
            <tr>
                <td class="ta_01" align="center" bgColor="#f5fafe" colspan=3>            
                        <table cellspacing="0" cellpadding="1" rules="all" bordercolor="gray" border="1" id="DataGrid1"
                            style="BORDER-RIGHT:gray 1px solid; BORDER-TOP:gray 1px solid; BORDER-LEFT:gray 1px solid; WIDTH:100%; WORD-BREAK:break-all; BORDER-BOTTOM:gray 1px solid; BORDER-COLLAPSE:collapse; BACKGROUND-COLOR:#f5fafe; WORD-WRAP:break-word">
                            <tr style="FONT-WEIGHT:bold;FONT-SIZE:12pt;HEIGHT:25px;BACKGROUND-COLOR:#afd1f3">
                            
                                <td align="center" width="40%" height=22 background="${pageContext.request.contextPath }/images/tablehead.jpg">站点运行情况</td>
                                <td align="center" width="40%" height=22 background="${pageContext.request.contextPath }/images/tablehead.jpg">设备运行情况</td>
                                <td align="center" width="20%" height=22 background="${pageContext.request.contextPath }/images/tablehead.jpg">创建日期</td>
                            </tr>
                            <div id="showInfomation" style="visibility: hidden"></div>
                            <tr onmouseover="this.style.backgroundColor = 'white'" onmouseout="this.style.backgroundColor = '#F5FAFE';">
                                <td style="HEIGHT:22px" align="center" width="40%">
                                    <div class="scrollStyle" align="left" onmouseover="showInfoWithPanel(this)" onmouseout="hiddenInfoPanel(this)" style="table-layout:fixed;">
                                    <!-- 站点运行情况 -->
                                        <s:property value="stationRun"/>
                                    </div>
                                </td>
                                <td style="HEIGHT:22px" align="center" width="40%">
                                    <div class="scrollStyle" align="left" onmouseover="showInfoWithPanel(this)" onmouseout="hiddenInfoPanel(this)" style="table-layout:fixed;">
                                    <!-- 设备运行情况 -->
                                        <s:property value="devRun"/>
                                    </div>
                                </td>
                                <td style="HEIGHT:22px" align="center" width="20%">
                                    <!-- 创建时间 --><!-- 此处应该使用s:date格式 -->
                                    <%--     <s:property value="createDate"/> --%>
                                    <s:date name="createDate"     format="yyyy-MM-dd HH:mm:ss" />
                                </td>
                            </tr>
                            
                        </table>
                        
                    </td>
                </tr>    
                
        </TBODY>
    </table>
</form>
<form name="Form2" id="Form2"  method="post">
    <table cellspacing="1" cellpadding="5" width="90%" align="center" bgcolor="#f5fafe" style="border:1px solid #8ba7e3" border="0">

        <tr>
            <td class="ta_01" colspan=2 align="center" background="${pageContext.request.contextPath }/images/b-info.gif">
            <font face="宋体" size="2"><strong>运行监控编辑</strong></font>
            </td>
        </tr>
        <TR height=10><td></td><td></td></TR>
        
        <tr>
            <td class="ta_01" align="center" bgcolor="#f5fafe" width="15%">站点运行情况:</td>
            <td class="ta_01" bgcolor="#ffffff" style="word-break: break-all">
                <!-- 站点运行情况数据回显 -->
                <s:textarea name="stationRun" id="stationRun" cssStyle=" 500px; height: 160px; padding: 1;FONT-FAMILY: 宋体; FONT-SIZE: 9pt" onkeydown="if(event.keyCode==13)addEnter('stationRun');" />
            <!--     <textarea name="stationRun" id="stationRun"   style=" 500px; height: 160px; padding: 1;FONT-FAMILY: 宋体; FONT-SIZE: 9pt" onkeydown="if(event.keyCode==13)addEnter('stationRun');">9点站点运行正常</textarea> -->
            </td>
            
        </tr>
        <tr>
            <td class="ta_01" align="center" bgcolor="#f5fafe" width="15%">设备运行情况:</td>
            <td class="ta_01" bgcolor="#ffffff" style="word-break: break-all">
                <!-- 设备运行情况数据回显 -->
                <s:textarea name="devRun" id="devRun" cssStyle=" 500px; height: 160px; padding: 1;FONT-FAMILY: 宋体; FONT-SIZE: 9pt" onkeydown="if(event.keyCode==13)addEnter('devRun');" />
            </td>
            
        </tr>
        <tr>
            <td class="ta_01" style=" 100%" align="center" bgcolor="#f5fafe" colspan="2">
            <input type="button" name="BT_Submit" value="保存" onclick="checkchar()" id="BT_Submit" style="font-size:12px; color:black; height=20;width=50">&nbsp;&nbsp;
                <input style="font-size:12px; color:black; height=20;width=80" id="BT_Export" type="button" value="导出设置" name="BT_Export" 
                         onclick="openWindow('${pageContext.request.contextPath }/system/exportExcel.jsp?belongTo=5-3','700','400')">&nbsp;&nbsp;
            </td>
        </tr>
    </table>
</form>
</body>
</html>

 其中:

 页面上的创建时间 应该使用s:date格式 
 而不是使用<s:property value="createDate"/> --%>
 应该是 <s:date name="createDate" format="yyyy-MM-dd HH:mm:ss" />
注意:s:date标签使用时,一定要是Date类型。
 
alermStation.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s" %>

<html>
  <head>
    <title>load</title>
    <link href="${pageContext.request.contextPath }/css/Style.css" type="text/css" rel="stylesheet" />
</head>
  
  <body>
    <table width="100%" border="0"  id="table8">
    
    
                <tr>
                    <td align="left" valign="middle"  style="word-break: break-all">
                    <span class="style1">
                        <s:property value="stationRun" escapeHtml="false" /><!-- 设置解析html标签 -->
                    </span></td>
                </tr>        
    
                <tr>
                    <td align="left" valign="middle"  style="word-break: break-all">
                    <span class="style1">
                    <font color="red"><s:date name="createDate" format="yyyy-MM-dd HH:mm:ss" /></font>
                    </span></td>
                </tr>    
                
    </table>
  </body>
</html>

alermDevice.jsp

<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags"  prefix="s" %>

<html>
  <head>
    <title>load</title>
    <link href="${pageContext.request.contextPath }/css/Style.css" type="text/css" rel="stylesheet" />
 </head>
  
  <body>
    <table width="100%" border="0" id="table8">
    
            <tr>
                    <td align="left" valign="middle"  style="word-break: break-all">
                    <span class="style1">
                        <s:property value="devRun" escapeHtml="false"/> <!-- 设置解析html标签 -->
                    </span></td>
                </tr>        
    
                <tr>
                    <td align="left" valign="middle"  style="word-break: break-all">
                    <span class="style1">
                    <font color="red"><s:date name="createDate" format="yyyy-MM-dd HH:mm:ss" /></font>
                    </span></td>
                </tr>    
              
    </table>
  </body>
</html>

ElecMenuAction.java

package com.itheima.elec.web.action;

@SuppressWarnings("serial")
@Controller("elecMenuAction")
@Scope(value="prototype")
public class ElecMenuAction extends BaseAction<MenuForm>{//需要一个Modeldriver 

    MenuForm menuForm = this.getModel();
    
    //注入运行监控Service
    @Resource(name=IElecCommonMsgService.SERVICE_NAME)
    IElecCommonMsgService elecCommonMsgService;
    
    /**
     * MenuHome系统登录的首页
     * @return
     */
    
    //执行保存
    public String menuHome(){
        System.out.println(menuForm.getName() + "--" + menuForm.getPassword());
        return "menuHome";
    }
    
    public String title(){
        return "title";
    }
    public String left(){
        return "left";
    }
    public String change(){
        return "change";
    }
    public String loading(){
        return "loading";
    }
/**
 * 重新登录
 * @return 跳转到主页面index.jsp
 */
    public String logout(){
        //清空指定名称的session
//        request.getSession().removeAttribute("arg0");
        //清空所有session
        request.getSession().invalidate();
        return "logout";
    }
    
    /**
     * 站点运行情况
     * @return
     */
    public String alermStation(){
        //1.查询线数据库运行监控表的数据,返回唯一ElecCommonMsg
        ElecCommonMsg commonMsg = elecCommonMsgService.findCommonMsg();
        //2.将ElecCommonMsg对象压入栈顶,支持表单回显
        //可能会有很多压入栈顶的操作,所以要封装,创建一个Utils类
        ValueUtils.putValueStack(commonMsg);
        //    ServletActionContext.getContext().getValueStack().push(commonMsg);
        return "alermStation";
    }
    
    /**
     * 设备运行情况
     * @return
     */
    public String alermDevice(){
        //1.查询线数据库运行监控表的数据,返回唯一ElecCommonMsg
        ElecCommonMsg commonMsg = elecCommonMsgService.findCommonMsg();
        //2.将ElecCommonMsg对象压入栈顶,支持表单回显
        //可能会有很多压入栈顶的操作,所以要封装,创建一个Utils类
        ValueUtils.putValueStack(commonMsg);
        //        ServletActionContext.getContext().getValueStack().push(commonMsg);
        return "alermDevice";
    }
    
}

 struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
    <!-- 开发模式 -->
    <constant name="struts.devMode" value="true"></constant>
    <!-- ui主题,简单主题 -->
    <constant name="struts.ui.theme" value="simple"></constant>
    <!-- 修改struts的后缀 改成do -->
    <constant name="struts.action.extension" value="do"></constant>
    
    <!-- 系统管理 -->
    <package name="system" namespace="/system" extends="struts-default">
        <!-- 测试 -->
        <action name="elecTextAction_*" class="elecTextAction" method="{1}">
                <result name="save">/system/textAdd.jsp</result>
        </action>
        <action name="elecMenuAction_*" class="elecMenuAction" method="{1}">
                <result name="menuHome">/WEB-INF/page/menu/home.jsp</result>
                <result name="title">/WEB-INF/page/menu/title.jsp</result>
                <result name="left">/WEB-INF/page/menu/left.jsp</result>
                <result name="change">/WEB-INF/page/menu/change.jsp</result>
                <result name="loading">/WEB-INF/page/menu/loading.jsp</result>
                <result name="alermStation">/WEB-INF/page/menu/alermStation.jsp</result>
                <result name="alermDevice">/WEB-INF/page/menu/alermDevice.jsp</result>
                <result name="logout" type="redirect">
                        /index.jsp
                </result>
        </action>
        <!-- 运行监控 -->
        <action name="elecCommonMsgAction_*" class="elecCommonMsgAction" method="{1}">
                <result name="home">/WEB-INF/page/system/actingIndex.jsp</result>
        </action>
    </package>
</struts>
原文地址:https://www.cnblogs.com/taiguyiba/p/6877191.html