1.show record as red when test status is NG; 2.add first_ack for issues table
This commit is contained in:
parent
e99c9fa36f
commit
59f2beee8e
BIN
APIServer.exe
BIN
APIServer.exe
Binary file not shown.
120
ews/ews.go
120
ews/ews.go
@ -46,9 +46,54 @@ type ReportInfo struct {
|
||||
DiffMins string
|
||||
}
|
||||
|
||||
func (e *EWS) RecordIssue(cfg cnf.Cfg, logger *log.Logger, host string, addr string, uri string, params map[string]string, ui *UutInfo, dbo *sql.DB) map[string]string {
|
||||
rst := map[string]string{"RESULT": ""}
|
||||
firstAck := ui.FirstAck
|
||||
if firstAck == "" {
|
||||
firstAck = time.Now().Format("2006-01-02 15:04:05")
|
||||
}
|
||||
|
||||
stmt, err := dbo.Prepare(
|
||||
fmt.Sprintf("INSERT INTO %s (usn,mac,ipaddr,relay,partno,mo,sku,line,stage,item,status,message,first_ack,last_change) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?);",
|
||||
cfg.MySQL.IssuesTable),
|
||||
)
|
||||
if err != nil {
|
||||
logger.Printf("[ERR] %s; %s; %#v; %s\r\n", addr, uri, params, err.Error())
|
||||
rst["RESULT"] = "NG"
|
||||
rst["ErrMsg"] = err.Error()
|
||||
return rst
|
||||
}
|
||||
defer stmt.Close()
|
||||
|
||||
_, err = stmt.Exec(
|
||||
params["USN"],
|
||||
params["MAC"],
|
||||
addr,
|
||||
host,
|
||||
params["PARTNO"],
|
||||
params["MO"],
|
||||
params["SKU"],
|
||||
params["LINE"],
|
||||
params["STAGE"],
|
||||
params["ITEM"],
|
||||
params["STATUS"],
|
||||
params["MESSAGE"],
|
||||
firstAck,
|
||||
time.Now().Format("2006-01-02 15:04:05"),
|
||||
)
|
||||
if err != nil {
|
||||
logger.Printf("[ERR] %s; %s; %#v; %s\r\n", addr, uri, params, err.Error())
|
||||
rst["RESULT"] = "NG"
|
||||
rst["ErrMsg"] = err.Error()
|
||||
return rst
|
||||
}
|
||||
|
||||
rst["RESULT"] = "OK"
|
||||
return rst
|
||||
}
|
||||
|
||||
func (e *EWS) SetUutInfo(cfg cnf.Cfg, logger *log.Logger, host string, addr string, uri string, params map[string]string) map[string]string {
|
||||
rst := map[string]string{"RESULT": ""}
|
||||
//if params["USN"] == "" || params["MAC"] == "" {
|
||||
if params["USN"] == "" {
|
||||
logger.Printf("[ERR] %s; %s; %#v; %s\r\n", addr, uri, params, "Missing Parameter USN.")
|
||||
rst["RESULT"] = "NG"
|
||||
@ -79,30 +124,6 @@ func (e *EWS) SetUutInfo(cfg cnf.Cfg, logger *log.Logger, host string, addr stri
|
||||
return rst
|
||||
}
|
||||
|
||||
if params["STATUS"] == "NG" {
|
||||
dmlIssue := fmt.Sprintf(`INSERT INTO %s
|
||||
(usn,mac,ipaddr,relay,partno,mo,sku,line,stage,item,status,message,last_change)
|
||||
VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s',NOW());`,
|
||||
cfg.MySQL.IssuesTable,
|
||||
params["USN"],
|
||||
params["MAC"],
|
||||
addr,
|
||||
host,
|
||||
params["PARTNO"],
|
||||
params["MO"],
|
||||
params["SKU"],
|
||||
params["LINE"],
|
||||
params["STAGE"],
|
||||
params["ITEM"],
|
||||
params["STATUS"],
|
||||
params["MESSAGE"],
|
||||
)
|
||||
_, err = dbo.Exec(dmlIssue)
|
||||
if err != nil {
|
||||
logger.Printf("[ERR] %s; %s; %#v; %s\r\n", addr, uri, params, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
rec := dbo.QueryRow(
|
||||
fmt.Sprintf(`SELECT usn,mac,ipaddr,relay,item,status,message,partno,mo,sku,line,stage,first_ack,last_ack,last_change
|
||||
FROM uutinfo
|
||||
@ -156,6 +177,12 @@ func (e *EWS) SetUutInfo(cfg cnf.Cfg, logger *log.Logger, host string, addr stri
|
||||
rst["ErrMsg"] = err.Error()
|
||||
return rst
|
||||
}
|
||||
if params["STATUS"] == "NG" {
|
||||
rst = e.RecordIssue(cfg, logger, host, addr, uri, params, ui, dbo)
|
||||
if rst["RESULT"] != "OK" {
|
||||
return rst
|
||||
}
|
||||
}
|
||||
rst["RESULT"] = "OK"
|
||||
rst["ErrMsg"] = "Inserted 1 new record."
|
||||
return rst
|
||||
@ -293,6 +320,14 @@ func (e *EWS) SetUutInfo(cfg cnf.Cfg, logger *log.Logger, host string, addr stri
|
||||
rst["ErrMsg"] = err.Error()
|
||||
return rst
|
||||
}
|
||||
|
||||
if params["STATUS"] == "NG" {
|
||||
rst = e.RecordIssue(cfg, logger, host, addr, uri, params, ui, dbo)
|
||||
if rst["RESULT"] != "OK" {
|
||||
return rst
|
||||
}
|
||||
}
|
||||
|
||||
rst["RESULT"] = "OK"
|
||||
rst["ErrMsg"] = "Updated and backed up 1 record."
|
||||
return rst
|
||||
@ -451,7 +486,20 @@ func (e *EWS) GetUutInfo(cfg cnf.Cfg, logger *log.Logger, host string, addr stri
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
last = last + fmt.Sprintf(`<tr>
|
||||
|
||||
if ul.Status == "NG" {
|
||||
last = last + fmt.Sprintf(`<tr>
|
||||
<td style="color: red; font-weight: bold;">%s</td>
|
||||
<td style="color: red; font-weight: bold;">%s</td>
|
||||
<td style="color: red; font-weight: bold;">%s</td>
|
||||
<td style="color: red; font-weight: bold;">%s</td>
|
||||
<td style="color: red; font-weight: bold;">%s</td>
|
||||
<td style="color: red; font-weight: bold;">%s</td>
|
||||
<td style="color: red; font-weight: bold;">%s</td>
|
||||
<td style="color: red; font-weight: bold;">%s</td>
|
||||
</tr>%s`, ul.USN, ul.MAC, ul.IPAddr, ul.Relay, ul.Item, ul.Status, ul.Message, ul.LastChg, "\r\n")
|
||||
} else {
|
||||
last = last + fmt.Sprintf(`<tr>
|
||||
<td style="color: blue;">%s</td>
|
||||
<td style="color: blue;">%s</td>
|
||||
<td style="color: blue;">%s</td>
|
||||
@ -461,6 +509,7 @@ func (e *EWS) GetUutInfo(cfg cnf.Cfg, logger *log.Logger, host string, addr stri
|
||||
<td style="color: blue;">%s</td>
|
||||
<td style="color: blue;">%s</td>
|
||||
</tr>%s`, ul.USN, ul.MAC, ul.IPAddr, ul.Relay, ul.Item, ul.Status, ul.Message, ul.LastChg, "\r\n")
|
||||
}
|
||||
|
||||
if ul.PartNO != "" {
|
||||
partNO = ul.PartNO
|
||||
@ -517,8 +566,23 @@ func (e *EWS) GetUutInfo(cfg cnf.Cfg, logger *log.Logger, host string, addr stri
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
bkup = bkup + fmt.Sprintf(`<tr><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`,
|
||||
uh.USN, uh.MAC, uh.IPAddr, uh.Relay, uh.Item, uh.Status, uh.Message, uh.LastChg, "\r\n")
|
||||
if uh.Status == "NG" {
|
||||
bkup = bkup + fmt.Sprintf(`<tr>
|
||||
<td style="color: red; font-weight: bold;">%s</td>
|
||||
<td style="color: red; font-weight: bold;">%s</td>
|
||||
<td style="color: red; font-weight: bold;">%s</td>
|
||||
<td style="color: red; font-weight: bold;">%s</td>
|
||||
<td style="color: red; font-weight: bold;">%s</td>
|
||||
<td style="color: red; font-weight: bold;">%s</td>
|
||||
<td style="color: red; font-weight: bold;">%s</td>
|
||||
<td style="color: red; font-weight: bold;">%s</td>
|
||||
</tr>%s`,
|
||||
uh.USN, uh.MAC, uh.IPAddr, uh.Relay, uh.Item, uh.Status, uh.Message, uh.LastChg, "\r\n")
|
||||
} else {
|
||||
bkup = bkup + fmt.Sprintf(`<tr><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`,
|
||||
uh.USN, uh.MAC, uh.IPAddr, uh.Relay, uh.Item, uh.Status, uh.Message, uh.LastChg, "\r\n")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//Get Location Information
|
||||
|
Loading…
x
Reference in New Issue
Block a user