打印机状态尝试改变
This commit is contained in:
@@ -29,6 +29,9 @@ const (
|
||||
|
||||
heartErrWithoutPaper = "04" //心跳错,缺纸
|
||||
heartErrHot = "08" //过热
|
||||
|
||||
printerStatusOnline = 1 //在线
|
||||
printerStatusOffline = -1 //离线
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -99,7 +102,7 @@ func handleConn(c net.Conn) {
|
||||
tcpClient.Clients[printNo] = c
|
||||
} else {
|
||||
//改变打印机状态
|
||||
|
||||
changePrinterStatus(db, printNo, printerStatusOnline)
|
||||
}
|
||||
} else if strings.Contains(data, printText) {
|
||||
changePrintMsg(db, data)
|
||||
@@ -159,7 +162,7 @@ func handleTcpMessages() {
|
||||
c = tcpClient.Clients[printMsg.PrintNo]
|
||||
data, err = buildMsg(printMsg)
|
||||
} else {
|
||||
err = fmt.Errorf("打印机已掉线!")
|
||||
changePrinterStatus(db, printMsg.PrintNo, printerStatusOffline)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -169,16 +172,34 @@ func handleTcpMessages() {
|
||||
printMsg.Status = printMsgErr
|
||||
printMsg.Comment = err.Error()
|
||||
dao.UpdateEntity(db, printMsg, "Status", "Comment")
|
||||
delete(tcpClient.Clients, printMsg.PrintNo)
|
||||
} else {
|
||||
if _, err = c.Write(data); err != nil {
|
||||
globals.SugarLogger.Debugf("handleTcpMessages err [%v]", err)
|
||||
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) {
|
||||
var (
|
||||
content = printMsg.Content
|
||||
|
||||
@@ -9,3 +9,13 @@ type PrintMsg struct {
|
||||
Status int `json:"status"` //打印状态
|
||||
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