add ng_report and offline_report
This commit is contained in:
parent
5832992701
commit
b90685e2f8
BIN
APIServer.exe
BIN
APIServer.exe
Binary file not shown.
BIN
APIServer.exe~
BIN
APIServer.exe~
Binary file not shown.
144
APIServer.go
144
APIServer.go
@ -180,8 +180,10 @@ func startSvc() {
|
||||
http.HandleFunc("/", handleIndex)
|
||||
http.HandleFunc("/request/", handleRequest)
|
||||
http.HandleFunc("/fileinfo/", handleFileInfo)
|
||||
http.HandleFunc("/getuutinfo/", handleGetUutInfo)
|
||||
http.HandleFunc("/setuutinfo/", handleSetUutInfo)
|
||||
http.HandleFunc("/getuutinfo/", handleGetUutInfo)
|
||||
http.HandleFunc("/getdefectinfo/", handleGetDefectInfo)
|
||||
http.HandleFunc("/getofflineinfo/", handleGetOfflineInfo)
|
||||
logger.Printf("[MSG] Starting HTTP Server On Port: %s\r\n", cfg.Settings.ListenPort)
|
||||
err := http.ListenAndServe(":"+cfg.Settings.ListenPort, nil)
|
||||
if err != nil {
|
||||
@ -339,41 +341,6 @@ func handleFileInfo(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "%s", string(jsonObj))
|
||||
}
|
||||
|
||||
func handleGetUutInfo(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
if r.RequestURI == "/favicon.ico" {
|
||||
return
|
||||
}
|
||||
host := strings.Split(r.Host, ":")[0]
|
||||
addr := strings.Split(r.RemoteAddr, ":")[0]
|
||||
uri := r.RequestURI
|
||||
rst := map[string]string{"RESULT": ""}
|
||||
|
||||
if err := r.ParseForm(); err != nil {
|
||||
logger.Printf("[ERR] %s; %s; %s\r\n", r.RemoteAddr, r.RequestURI, err.Error())
|
||||
rst["RESULT"] = "NG"
|
||||
rst["ErrMsg"] = err.Error()
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
fmt.Fprintf(w, "%v", strings.ReplaceAll(fmt.Sprintf("%#v", rst), "map[string]string", ""))
|
||||
return
|
||||
}
|
||||
|
||||
params := make(map[string]string, 0)
|
||||
if len(r.Form) > 0 {
|
||||
for k, v := range r.Form {
|
||||
params[strings.ToUpper(strings.TrimSpace(k))] = strings.TrimSpace(v[0])
|
||||
}
|
||||
}
|
||||
ews := new(ews.EWS)
|
||||
rst = ews.GetUutInfo(cfg, logger, host, addr, uri, params)
|
||||
if rst["RESULT"] != "OK" {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
} else {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
fmt.Fprintf(w, "%v", rst["ErrMsg"])
|
||||
}
|
||||
|
||||
func handleSetUutInfo(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
if r.RequestURI == "/favicon.ico" {
|
||||
@ -413,6 +380,111 @@ func handleSetUutInfo(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "%v", strings.ReplaceAll(fmt.Sprintf("%#v", rst), "map[string]string", ""))
|
||||
}
|
||||
|
||||
func handleGetUutInfo(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
if r.RequestURI == "/favicon.ico" {
|
||||
return
|
||||
}
|
||||
host := strings.Split(r.Host, ":")[0]
|
||||
addr := strings.Split(r.RemoteAddr, ":")[0]
|
||||
uri := r.RequestURI
|
||||
rst := map[string]string{"RESULT": ""}
|
||||
|
||||
if err := r.ParseForm(); err != nil {
|
||||
logger.Printf("[ERR] %s; %s; %s\r\n", r.RemoteAddr, r.RequestURI, err.Error())
|
||||
rst["RESULT"] = "NG"
|
||||
rst["ErrMsg"] = err.Error()
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
fmt.Fprintf(w, "%v", strings.ReplaceAll(fmt.Sprintf("%#v", rst), "map[string]string", ""))
|
||||
return
|
||||
}
|
||||
|
||||
params := make(map[string]string, 0)
|
||||
if len(r.Form) > 0 {
|
||||
for k, v := range r.Form {
|
||||
params[strings.ToUpper(strings.TrimSpace(k))] = strings.TrimSpace(v[0])
|
||||
}
|
||||
}
|
||||
ews := new(ews.EWS)
|
||||
rst = ews.GetUutInfo(cfg, logger, host, addr, uri, params)
|
||||
if rst["RESULT"] != "OK" {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
} else {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
fmt.Fprintf(w, "%v", rst["ErrMsg"])
|
||||
}
|
||||
|
||||
func handleGetDefectInfo(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
if r.RequestURI == "/favicon.ico" {
|
||||
return
|
||||
}
|
||||
host := strings.Split(r.Host, ":")[0]
|
||||
addr := strings.Split(r.RemoteAddr, ":")[0]
|
||||
uri := r.RequestURI
|
||||
rst := map[string]string{"RESULT": ""}
|
||||
|
||||
if err := r.ParseForm(); err != nil {
|
||||
logger.Printf("[ERR] %s; %s; %s\r\n", r.RemoteAddr, r.RequestURI, err.Error())
|
||||
rst["RESULT"] = "NG"
|
||||
rst["ErrMsg"] = err.Error()
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
fmt.Fprintf(w, "%v", strings.ReplaceAll(fmt.Sprintf("%#v", rst), "map[string]string", ""))
|
||||
return
|
||||
}
|
||||
|
||||
params := make(map[string]string, 0)
|
||||
if len(r.Form) > 0 {
|
||||
for k, v := range r.Form {
|
||||
params[strings.ToUpper(strings.TrimSpace(k))] = strings.TrimSpace(v[0])
|
||||
}
|
||||
}
|
||||
ews := new(ews.EWS)
|
||||
rst = ews.GetDefectUuts(cfg, logger, host, addr, uri, params)
|
||||
if rst["RESULT"] != "OK" {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
} else {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
fmt.Fprintf(w, "%v", rst["ErrMsg"])
|
||||
}
|
||||
|
||||
func handleGetOfflineInfo(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
if r.RequestURI == "/favicon.ico" {
|
||||
return
|
||||
}
|
||||
host := strings.Split(r.Host, ":")[0]
|
||||
addr := strings.Split(r.RemoteAddr, ":")[0]
|
||||
uri := r.RequestURI
|
||||
rst := map[string]string{"RESULT": ""}
|
||||
|
||||
if err := r.ParseForm(); err != nil {
|
||||
logger.Printf("[ERR] %s; %s; %s\r\n", r.RemoteAddr, r.RequestURI, err.Error())
|
||||
rst["RESULT"] = "NG"
|
||||
rst["ErrMsg"] = err.Error()
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
fmt.Fprintf(w, "%v", strings.ReplaceAll(fmt.Sprintf("%#v", rst), "map[string]string", ""))
|
||||
return
|
||||
}
|
||||
|
||||
params := make(map[string]string, 0)
|
||||
if len(r.Form) > 0 {
|
||||
for k, v := range r.Form {
|
||||
params[strings.ToUpper(strings.TrimSpace(k))] = strings.TrimSpace(v[0])
|
||||
}
|
||||
}
|
||||
ews := new(ews.EWS)
|
||||
rst = ews.GetOfflineUuts(cfg, logger, host, addr, uri, params)
|
||||
if rst["RESULT"] != "OK" {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
} else {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
fmt.Fprintf(w, "%v", rst["ErrMsg"])
|
||||
}
|
||||
|
||||
func parseReqParams(r *http.Request) (map[string]string, error) {
|
||||
params := make(map[string]string, 0)
|
||||
if err := r.ParseForm(); err != nil {
|
||||
|
15
Index.html
15
Index.html
@ -5,9 +5,11 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />
|
||||
<title>API Server</title>
|
||||
<style type="text/css">
|
||||
form {margin: 0px; display: inline;}
|
||||
ul,li {margin: 0px; padding: 0px; list-style-type: none;}
|
||||
label {font-family: Consolas; font-size: 16px;}
|
||||
input {width: 250px; height: 20px; font-family: monospace; font-size: 14px;}
|
||||
input {width: 200px; height: 20px; font-family: monospace; font-size: 14px;}
|
||||
select {width: 150px; height: 25px; font-size: 14px;}
|
||||
iframe {word-wrap: break-word; position: static; border: 0; top: 0px; left: 0px; width: 100%;}
|
||||
</style>
|
||||
<script>
|
||||
@ -20,6 +22,16 @@
|
||||
</head>
|
||||
<body leftmargin="10px" >
|
||||
<h4>机台测试记录查询</h4>
|
||||
|
||||
<form name="getdefectinfo" action="/getdefectinfo/" method="POST" target="result">
|
||||
<input type="submit" name="Query" value="实时异常报表" style="width:120px; height:25px;">
|
||||
</form>
|
||||
|
||||
<form name="getofflineinfo" action="/getofflineinfo/" method="POST" target="result">
|
||||
<input type="submit" name="Query" value="实时离线报表" style="width:120px; height:25px;">
|
||||
</form>
|
||||
<br/><br/>
|
||||
|
||||
<form name="getuutinfo" action="/getuutinfo/" method="POST" target="result">
|
||||
<ul>
|
||||
<li>
|
||||
@ -27,6 +39,7 @@
|
||||
<input type="text" name="USN" id="USN" />
|
||||
|
||||
<input type="submit" name="Query" value="Query" style="width:75px; height:25px;" />
|
||||
<!--input type="submit" style="width:75px; height:25px;" /-->
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
|
239
ews/ews.go
239
ews/ews.go
@ -30,6 +30,21 @@ type UutInfo struct {
|
||||
LastTrn string
|
||||
}
|
||||
|
||||
type DefectInfo struct {
|
||||
USN string
|
||||
PartNO string
|
||||
SKU string
|
||||
Line string
|
||||
Location string
|
||||
Item string
|
||||
Status string
|
||||
Message string
|
||||
FirstAck string
|
||||
LastAck string
|
||||
LastChg string
|
||||
DiffMins string
|
||||
}
|
||||
|
||||
func (e *EWS) SetUutInfo(cfg cnf.Cfg, logger *log.Logger, host string, addr string, uri string, params map[string]string) map[string]string {
|
||||
if cfg.Settings.LogRequest {
|
||||
logger.Printf("[MSG] %s; %s; Request: %#v\r\n", addr, uri, params)
|
||||
@ -407,9 +422,161 @@ func (e *EWS) GetUutInfo(cfg cnf.Cfg, logger *log.Logger, host string, addr stri
|
||||
partNO, mfgMO, mfgSKU, fstAck, lstAck)
|
||||
|
||||
rst["RESULT"] = "OK"
|
||||
rst["ErrMsg"] = e.TemplateHTML(loc, locTime, misc, last, bkup)
|
||||
rst["ErrMsg"] = e.TemplateUutInfo(loc, locTime, misc, last, bkup)
|
||||
if cfg.Settings.LogResponse {
|
||||
logger.Printf("[MSG] %s; %s; Response: Length=%s\r\n", addr, uri, rst["RESULT"])
|
||||
logger.Printf("[MSG] %s; %s; Response: Length=%d\r\n", addr, uri, len(rst["ErrMsg"]))
|
||||
}
|
||||
return rst
|
||||
}
|
||||
|
||||
func (e *EWS) GetDefectUuts(cfg cnf.Cfg, logger *log.Logger, host string, addr string, uri string, params map[string]string) map[string]string {
|
||||
if cfg.Settings.LogRequest {
|
||||
logger.Printf("[MSG] %s; %s; Request: %#v\r\n", addr, uri, params)
|
||||
}
|
||||
rst := map[string]string{"RESULT": ""}
|
||||
|
||||
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s",
|
||||
cfg.MySQL.User,
|
||||
cfg.MySQL.Password,
|
||||
cfg.MySQL.Server,
|
||||
cfg.MySQL.Port,
|
||||
cfg.MySQL.Database,
|
||||
)
|
||||
dbo, err := sql.Open("mysql", dsn)
|
||||
if err != nil {
|
||||
logger.Printf("[ERR] %s; %s; %#v; %s\r\n", addr, uri, params, err.Error())
|
||||
rst["RESULT"] = "NG"
|
||||
rst["ErrMsg"] = e.SimpleMsgHTML("red", err.Error())
|
||||
return rst
|
||||
}
|
||||
defer dbo.Close()
|
||||
err = dbo.Ping()
|
||||
if err != nil {
|
||||
logger.Printf("[ERR] %s; %s; %#v; %s\r\n", addr, uri, params, err.Error())
|
||||
rst["RESULT"] = "NG"
|
||||
rst["ErrMsg"] = e.SimpleMsgHTML("red", err.Error())
|
||||
return rst
|
||||
}
|
||||
|
||||
di := new(DefectInfo)
|
||||
defect := ""
|
||||
rows, err := dbo.Query(
|
||||
`SELECT usn,partno,sku,line,location,item,status,message,first_ack,last_ack,last_change,diffmins
|
||||
FROM v_ngreport
|
||||
ORDER BY diffmins ASC;`)
|
||||
if err != nil {
|
||||
logger.Printf("[ERR] %s; %s; %#v; %s\r\n", addr, uri, params, err.Error())
|
||||
rst["RESULT"] = "NG"
|
||||
rst["ErrMsg"] = e.SimpleMsgHTML("red", err.Error())
|
||||
return rst
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
num := 1
|
||||
for rows.Next() {
|
||||
err := rows.Scan(
|
||||
&di.USN,
|
||||
&di.PartNO,
|
||||
&di.SKU,
|
||||
&di.Line,
|
||||
&di.Location,
|
||||
&di.Item,
|
||||
&di.Status,
|
||||
&di.Message,
|
||||
&di.FirstAck,
|
||||
&di.LastAck,
|
||||
&di.LastChg,
|
||||
&di.DiffMins,
|
||||
)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
temp := fmt.Sprintf(`<tr><td>%d</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>%s`,
|
||||
num, di.USN, di.PartNO, di.SKU, di.Line, di.Location, di.Item, di.Status, di.Message, di.FirstAck, di.LastAck, di.LastChg, di.DiffMins, "\r\n")
|
||||
defect = defect + temp
|
||||
num += 1
|
||||
}
|
||||
|
||||
rst["RESULT"] = "OK"
|
||||
rst["ErrMsg"] = e.TemplateDefectInfo(defect)
|
||||
if cfg.Settings.LogResponse {
|
||||
logger.Printf("[MSG] %s; %s; Response: Length=%d\r\n", addr, uri, len(rst["ErrMsg"]))
|
||||
}
|
||||
return rst
|
||||
}
|
||||
|
||||
func (e *EWS) GetOfflineUuts(cfg cnf.Cfg, logger *log.Logger, host string, addr string, uri string, params map[string]string) map[string]string {
|
||||
if cfg.Settings.LogRequest {
|
||||
logger.Printf("[MSG] %s; %s; Request: %#v\r\n", addr, uri, params)
|
||||
}
|
||||
rst := map[string]string{"RESULT": ""}
|
||||
|
||||
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s",
|
||||
cfg.MySQL.User,
|
||||
cfg.MySQL.Password,
|
||||
cfg.MySQL.Server,
|
||||
cfg.MySQL.Port,
|
||||
cfg.MySQL.Database,
|
||||
)
|
||||
dbo, err := sql.Open("mysql", dsn)
|
||||
if err != nil {
|
||||
logger.Printf("[ERR] %s; %s; %#v; %s\r\n", addr, uri, params, err.Error())
|
||||
rst["RESULT"] = "NG"
|
||||
rst["ErrMsg"] = e.SimpleMsgHTML("red", err.Error())
|
||||
return rst
|
||||
}
|
||||
defer dbo.Close()
|
||||
err = dbo.Ping()
|
||||
if err != nil {
|
||||
logger.Printf("[ERR] %s; %s; %#v; %s\r\n", addr, uri, params, err.Error())
|
||||
rst["RESULT"] = "NG"
|
||||
rst["ErrMsg"] = e.SimpleMsgHTML("red", err.Error())
|
||||
return rst
|
||||
}
|
||||
|
||||
di := new(DefectInfo)
|
||||
offline := ""
|
||||
rows, err := dbo.Query(
|
||||
`SELECT usn,partno,sku,line,location,item,status,message,first_ack,last_ack,last_change,diffmins
|
||||
FROM v_offline
|
||||
ORDER BY diffmins DESC;`)
|
||||
if err != nil {
|
||||
logger.Printf("[ERR] %s; %s; %#v; %s\r\n", addr, uri, params, err.Error())
|
||||
rst["RESULT"] = "NG"
|
||||
rst["ErrMsg"] = e.SimpleMsgHTML("red", err.Error())
|
||||
return rst
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
num := 1
|
||||
for rows.Next() {
|
||||
err := rows.Scan(
|
||||
&di.USN,
|
||||
&di.PartNO,
|
||||
&di.SKU,
|
||||
&di.Line,
|
||||
&di.Location,
|
||||
&di.Item,
|
||||
&di.Status,
|
||||
&di.Message,
|
||||
&di.FirstAck,
|
||||
&di.LastAck,
|
||||
&di.LastChg,
|
||||
&di.DiffMins,
|
||||
)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
temp := fmt.Sprintf(`<tr><td>%d</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>%s`,
|
||||
num, di.USN, di.PartNO, di.SKU, di.Line, di.Location, di.Item, di.Status, di.Message, di.FirstAck, di.LastAck, di.LastChg, di.DiffMins, "\r\n")
|
||||
offline = offline + temp
|
||||
num += 1
|
||||
}
|
||||
|
||||
rst["RESULT"] = "OK"
|
||||
rst["ErrMsg"] = e.TemplateDefectInfo(offline)
|
||||
if cfg.Settings.LogResponse {
|
||||
logger.Printf("[MSG] %s; %s; Response: Length=%d\r\n", addr, uri, len(rst["ErrMsg"]))
|
||||
}
|
||||
return rst
|
||||
}
|
||||
@ -429,7 +596,7 @@ func (e *EWS) SimpleMsgHTML(clr, msg string) string {
|
||||
return resp
|
||||
}
|
||||
|
||||
func (e *EWS) TemplateHTML(loc, locTime, misc, last, bkup string) string {
|
||||
func (e *EWS) TemplateUutInfo(loc, locTime, misc, last, bkup string) string {
|
||||
if loc == "" {
|
||||
loc = `<span style="color: red; font-size: 14px; font-family: Consolas;">Unknown</span>`
|
||||
}
|
||||
@ -458,7 +625,7 @@ func (e *EWS) TemplateHTML(loc, locTime, misc, last, bkup string) string {
|
||||
color: #fff;
|
||||
border: 1px solid rgb(81, 130, 187);
|
||||
padding: 5px 10px;
|
||||
font-size: 14px;
|
||||
font-size: 12px;
|
||||
font-family: Verdana;
|
||||
font-weight: bold;
|
||||
}
|
||||
@ -468,7 +635,7 @@ func (e *EWS) TemplateHTML(loc, locTime, misc, last, bkup string) string {
|
||||
td {
|
||||
color: #000;
|
||||
padding: 5px 10px;
|
||||
font-size: 14px;
|
||||
font-size: 12px;
|
||||
font-family: Consolas;
|
||||
}
|
||||
span {
|
||||
@ -524,3 +691,65 @@ func (e *EWS) TemplateHTML(loc, locTime, misc, last, bkup string) string {
|
||||
</html>`, loc, locTime, misc, bkup, last)
|
||||
return resp
|
||||
}
|
||||
|
||||
func (e *EWS) TemplateDefectInfo(src string) string {
|
||||
if src == "" {
|
||||
src = `<span style="color: red;">NO Records !</span>`
|
||||
}
|
||||
resp := fmt.Sprintf(`<!DOCTYPE html>
|
||||
<html>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>Test Records</title>
|
||||
<style type="text/css">
|
||||
table {
|
||||
border: 1px solid rgb(81, 130, 187);
|
||||
border-collapse: separate;
|
||||
border-spacing: 1px;
|
||||
position: static;
|
||||
}
|
||||
th {
|
||||
background-color: rgb(81, 130, 187);
|
||||
color: #fff;
|
||||
border: 1px solid rgb(81, 130, 187);
|
||||
padding: 5px 10px;
|
||||
font-size: 12px;
|
||||
font-family: Verdana;
|
||||
font-weight: bold;
|
||||
}
|
||||
tr {
|
||||
border: 1px solid rgb(81, 130, 187);
|
||||
}
|
||||
td {
|
||||
color: #000;
|
||||
padding: 5px 10px;
|
||||
font-size: 12px;
|
||||
font-family: Consolas;
|
||||
}
|
||||
span {
|
||||
font-size: 14px;
|
||||
font-family: Consolas;
|
||||
}
|
||||
</style>
|
||||
<body>
|
||||
<table>
|
||||
<tr>
|
||||
<th>NO.</th>
|
||||
<th>USN</th>
|
||||
<th>Part NO.</th>
|
||||
<th>SKU</th>
|
||||
<th>Line</th>
|
||||
<th>Location</th>
|
||||
<th>Item</th>
|
||||
<th>Status</th>
|
||||
<th>Message</th>
|
||||
<th>First Ack</th>
|
||||
<th>Last Ack</th>
|
||||
<th>Last Change</th>
|
||||
<th>Differ Time (Min)</th>
|
||||
</tr>
|
||||
%s
|
||||
</table>
|
||||
</body>
|
||||
</html>`, src)
|
||||
return resp
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user