This commit is contained in:
suyl
2021-07-30 17:22:51 +08:00
parent d1c0a06730
commit 14de70f911
2 changed files with 66 additions and 21 deletions

View File

@@ -25,9 +25,9 @@ func ListenTcp() {
return
}
globals.SugarLogger.Debugf("begin listenTcp port 8000......")
go HandleTcpMessages()
go t.HandleTcpMessages()
go t.HandleCheckTcpHeart()
go t.doPrint2(printMsgChan)
//go t.doPrint2()
//go t.doPrint(printMsgChanFail)
for {
c, err := l.Accept()
@@ -95,9 +95,11 @@ func (t *TcpClient) handleConn(c net.Conn) {
//t.Unlock()
t.addConn(c, printNo, status)
t.buildCallBackMap(printNo)
t.buildMsgMap(printNo)
go t.doPrint2(printNo)
changePrinterStatus(printNo, status)
if status == printerStatusOnline {
printFail()
t.printFail()
}
//} else {
//改变打印机状态
@@ -118,9 +120,7 @@ func (t *TcpClient) handleConn(c net.Conn) {
} else if strings.Contains(data, printText) {
globals.SugarLogger.Debugf("handleConn print callback: %v", data)
_, printNo = getCallbackMsgInfo(data)
t.RLock()
t.CallBackMap[printNo] <- data
t.RUnlock()
t.addCallbackChan(printNo, data)
//printMsgCallbackChan <- printMsgCallbackMap
//changePrintMsg(data)
}
@@ -153,14 +153,14 @@ func changePrinterStatus(printNo string, status int) {
}
}
func printFail() (err error) {
func (t *TcpClient) printFail() (err error) {
//新开机的打印失败和错误的
var (
db = dao.GetDB()
)
prints, _ := dao.GetPrintMsgs(db, []int{printMsgFail, printMsgErr, printMsgAlreadyLoad, printMsgAlreadySend}, time.Now().Add(-time.Hour*3), time.Now(), 0, 999)
for _, printMsg := range prints {
printMsgChan <- printMsg
t.addMsgChan(printMsg)
}
return err
}
@@ -217,7 +217,7 @@ func (t *TcpClient) changePrintMsg(data string, orderNo int64, printNo string) (
return err
}
func HandleTcpMessages() {
func (t *TcpClient) HandleTcpMessages() {
var (
db = dao.GetDB()
offset, pageSize = 0, 1
@@ -226,20 +226,20 @@ func HandleTcpMessages() {
//一直读?
prints, _ := dao.GetPrintMsgs(db, []int{printMsgWait}, time.Now().Add(-time.Hour*3), time.Now(), offset, pageSize)
for _, printMsg := range prints {
printMsgChan <- printMsg
t.addMsgChan(printMsg)
printMsg.Status = printMsgAlreadyLoad
dao.UpdateEntity(db, printMsg, "Status")
}
}
}
func (t *TcpClient) doPrint2(printMsgChan chan *model.PrintMsg) (err error) {
func (t *TcpClient) doPrint2(key string) (err error) {
var (
db = dao.GetDB()
)
for {
select {
case printMsg := <-printMsgChan:
case printMsg := <-t.MsgMap[key]:
var (
data []byte
c net.Conn