打印机状态尝试改变
This commit is contained in:
@@ -29,6 +29,9 @@ const (
|
|||||||
|
|
||||||
heartErrWithoutPaper = "04" //心跳错,缺纸
|
heartErrWithoutPaper = "04" //心跳错,缺纸
|
||||||
heartErrHot = "08" //过热
|
heartErrHot = "08" //过热
|
||||||
|
|
||||||
|
printerStatusOnline = 1 //在线
|
||||||
|
printerStatusOffline = -1 //离线
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -99,7 +102,7 @@ func handleConn(c net.Conn) {
|
|||||||
tcpClient.Clients[printNo] = c
|
tcpClient.Clients[printNo] = c
|
||||||
} else {
|
} else {
|
||||||
//改变打印机状态
|
//改变打印机状态
|
||||||
|
changePrinterStatus(db, printNo, printerStatusOnline)
|
||||||
}
|
}
|
||||||
} else if strings.Contains(data, printText) {
|
} else if strings.Contains(data, printText) {
|
||||||
changePrintMsg(db, data)
|
changePrintMsg(db, data)
|
||||||
@@ -159,7 +162,7 @@ func handleTcpMessages() {
|
|||||||
c = tcpClient.Clients[printMsg.PrintNo]
|
c = tcpClient.Clients[printMsg.PrintNo]
|
||||||
data, err = buildMsg(printMsg)
|
data, err = buildMsg(printMsg)
|
||||||
} else {
|
} else {
|
||||||
err = fmt.Errorf("打印机已掉线!")
|
changePrinterStatus(db, printMsg.PrintNo, printerStatusOffline)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -169,16 +172,34 @@ func handleTcpMessages() {
|
|||||||
printMsg.Status = printMsgErr
|
printMsg.Status = printMsgErr
|
||||||
printMsg.Comment = err.Error()
|
printMsg.Comment = err.Error()
|
||||||
dao.UpdateEntity(db, printMsg, "Status", "Comment")
|
dao.UpdateEntity(db, printMsg, "Status", "Comment")
|
||||||
|
delete(tcpClient.Clients, printMsg.PrintNo)
|
||||||
} else {
|
} else {
|
||||||
if _, err = c.Write(data); err != nil {
|
if _, err = c.Write(data); err != nil {
|
||||||
globals.SugarLogger.Debugf("handleTcpMessages err [%v]", err)
|
globals.SugarLogger.Debugf("handleTcpMessages err [%v]", err)
|
||||||
c.Close()
|
c.Close()
|
||||||
|
delete(tcpClient.Clients, printMsg.PrintNo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func changePrinterStatus(db *dao.DaoDB, printNo string, status int) (err error) {
|
||||||
|
var (
|
||||||
|
printer = &model.Printer{
|
||||||
|
PrintNo: printNo,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if err = dao.GetEntity(db, printer, "PrintNo"); err == nil {
|
||||||
|
if printer.ID != 0 {
|
||||||
|
if printer.Status != status {
|
||||||
|
dao.UpdateEntity(db, printer, "Status")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func buildMsg(printMsg *model.PrintMsg) (data []byte, err error) {
|
func buildMsg(printMsg *model.PrintMsg) (data []byte, err error) {
|
||||||
var (
|
var (
|
||||||
content = printMsg.Content
|
content = printMsg.Content
|
||||||
|
|||||||
@@ -9,3 +9,13 @@ type PrintMsg struct {
|
|||||||
Status int `json:"status"` //打印状态
|
Status int `json:"status"` //打印状态
|
||||||
Comment string `json:"comment"` //失败原因
|
Comment string `json:"comment"` //失败原因
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Printer struct {
|
||||||
|
ModelIDCULD
|
||||||
|
|
||||||
|
AppID int `orm:"column(app_id)" json:"app_id"` //应用编号
|
||||||
|
PrintNo string `json:"print_no"` //打印机编号
|
||||||
|
PrintKey string `json:"print_key"` //打印机识别码
|
||||||
|
Name string `json:"name"` //打印机备注名
|
||||||
|
Status int `json:"status"` //打印机状态
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user