diff --git a/common/Utils.go b/common/Utils.go index 95f0141..64fbf2a 100644 --- a/common/Utils.go +++ b/common/Utils.go @@ -1,7 +1,6 @@ package common import ( - "LAPP_PRN_Service/db" "container/list" "errors" "fmt" @@ -359,12 +358,16 @@ func SendFileToPrinter(filePath string, ip string, port int) error { return nil } +type ByteFile struct { + ByteLine []byte +} + // 发送到打印机 -func SendFileBySerial(bytesFile []db.ByteFile, SerialName string, SerialPort int) error { +func SendFileBySerial(bytesFile []ByteFile, SerialName string, SerialPort int) error { var ( err error - bytesRow db.ByteFile + bytesRow ByteFile ) c := &serial.Config{Name: SerialName, Baud: SerialPort} diff --git a/db/PrintTask.go b/db/PrintTask.go index 530a27d..1390ddd 100644 --- a/db/PrintTask.go +++ b/db/PrintTask.go @@ -23,12 +23,8 @@ type PrintTask struct { PrintDetailList []PrintDetail } -type ByteFile struct { - ByteLine []byte -} - // 基于模板将打印任务转换成字节码输出 -func (t *PrintTask) GenBytesFile(conf *conf.EnvConfig) ([]ByteFile, error) { +func (t *PrintTask) GenBytesFile(conf *conf.EnvConfig) ([]common.ByteFile, error) { TemplatePath := common.EnsureDir(conf.TemplatePath) templatefile := filepath.Join(TemplatePath, t.PrintHead.TemplateFile) f, err := os.Open(templatefile) @@ -39,7 +35,7 @@ func (t *PrintTask) GenBytesFile(conf *conf.EnvConfig) ([]ByteFile, error) { return nil, err } - var results []ByteFile + var results []common.ByteFile scanner := bufio.NewScanner(f) for scanner.Scan() { linetext := scanner.Text() @@ -47,7 +43,7 @@ func (t *PrintTask) GenBytesFile(conf *conf.EnvConfig) ([]ByteFile, error) { // -1 替换所有; 1 替换第一个; 5 替换前5个 linetext = strings.Replace(linetext, pd.VarName, pd.VarValue, -1) } - var r ByteFile + var r common.ByteFile r.ByteLine = []byte(linetext) results = append(results, r) } diff --git a/engine/printer.go b/engine/printer.go index 8684593..6f99271 100644 --- a/engine/printer.go +++ b/engine/printer.go @@ -44,10 +44,10 @@ func (p *Printer) Create(printertab db.Printer) { // 输出打印任务到端口 // 打印任务是以ByteArray数组类型的文件行 -func (p *Printer) printTaskBytesFile(bytesFile []db.ByteFile) error { +func (p *Printer) printTaskBytesFile(bytesFile []common.ByteFile) error { var ( err error - bytesRow db.ByteFile + bytesRow common.ByteFile ) for _, bytesRow = range bytesFile { if _, err = p.conn.Write(bytesRow.ByteLine); err != nil { @@ -88,7 +88,7 @@ func (p *Printer) printBySocket(conf *conf.EnvConfig, saveChan chan db.PrintTask var ( t db.PrintTask err error - bytesFile []db.ByteFile + bytesFile []common.ByteFile ) // 从缓存队列的头部取出一个任务并输出打印 @@ -196,7 +196,7 @@ func (p *Printer) printBySerial(conf *conf.EnvConfig, saveChan chan db.PrintTask var ( t db.PrintTask err error - bytesFile []db.ByteFile + bytesFile []common.ByteFile ) for {