From f1761fa154d448c0ee54be3f8a613fb509915f77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Thu, 4 Aug 2022 17:26:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=AD=E9=9F=B3=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/event/event_tcp_utils.go | 19 +++++++++++----- business/jxstore/event/print_test.go | 27 +---------------------- 2 files changed, 14 insertions(+), 32 deletions(-) diff --git a/business/jxstore/event/event_tcp_utils.go b/business/jxstore/event/event_tcp_utils.go index 7ad249ffa..864b9f39f 100644 --- a/business/jxstore/event/event_tcp_utils.go +++ b/business/jxstore/event/event_tcp_utils.go @@ -482,9 +482,9 @@ func replaceContent(content string, printMsg *model.PrintMsg) (result string) { result = strings.ReplaceAll(result, byteSignQrRight, hexSignQrRight+hexSignQr+hexLenqr+"00") result = strings.ReplaceAll(result, byteSignQrRightE, hexSignQrEnd) } - // 固定模板输出语音 3c736f756e643e 3634 3c2f736f756e643e + // 固定模板输出语音 if strings.Contains(result, byteSignSound) && strings.Contains(result, byteSignSoundE) { - soundStr := "" + var soundStr []string for _, v1 := range strings.Split(result, byteSignSoundE) { v1 += byteSignSoundE if sounds := regexpSound.FindStringSubmatch(v1); len(sounds) > 0 { @@ -505,10 +505,17 @@ func replaceContent(content string, printMsg *model.PrintMsg) (result string) { } } soundParam := strings.ReplaceAll(resultV1, sound, "") - soundStr += strings.ReplaceAll(soundParam, byteSignSound, voice) + soundStr = append(soundStr, strings.ReplaceAll(soundParam, byteSignSound, voice)) } } - result = soundStr + + result = strings.ReplaceAll(result, byteSignSound, "*") + result = strings.ReplaceAll(result, byteSignSoundE, "&") + for _, v := range soundStr { + start := strings.Index(result, "*") + end := strings.Index(result, "&") + result = strings.Replace(result, result[start:end+1], v, 1) + } } // 自动合成语音功能 //if strings.Contains(result, byteSignSound) && strings.Contains(result, byteSignSoundE) { @@ -566,8 +573,8 @@ func int2h8l8(i int64) (h, l string) { } begin8 := origin2[:8] end8 := origin2[8:] - r1, _ := strconv.ParseInt(begin8, 2, 64) - r2, _ := strconv.ParseInt(end8, 2, 64) + r1, _ := strconv.ParseInt(begin8, 2, 32) + r2, _ := strconv.ParseInt(end8, 2, 32) h = fmt.Sprintf("%x", r1) l = fmt.Sprintf("%x", r2) if len(h)%2 != 0 { diff --git a/business/jxstore/event/print_test.go b/business/jxstore/event/print_test.go index 372411f15..4c924a15f 100644 --- a/business/jxstore/event/print_test.go +++ b/business/jxstore/event/print_test.go @@ -6,7 +6,6 @@ import ( "git.rosy.net.cn/jx-callback/business/jxutils" "git.rosy.net.cn/jx-callback/business/model" "strconv" - "strings" "testing" "unicode/utf8" ) @@ -16,7 +15,7 @@ func TestPrintMsg(t *testing.T) { msg := &model.PrintMsg{ ModelIDCULD: model.ModelIDCULD{}, PrintNo: "20220707000002", - Content: "6162", + Content: "1,2,3
居中文字
4,5,6
居中
", OrderNo: "9999999991", // 2147483648111 Status: 0, Comment: "", @@ -25,7 +24,6 @@ func TestPrintMsg(t *testing.T) { data, err := buildMsg(msg) - fmt.Println("data=", fmt.Sprintf("%s", string(data...))) fmt.Println("data=", string(data)) fmt.Println("err=", err) } @@ -63,28 +61,5 @@ func TestCheckSum(t *testing.T) { } func TestTen216(t *testing.T) { - fmt.Println(toHex(16)) -} -func toHex(ten int) string { - m := 0 - hex := make([]int, 0) - for { - m = ten % 16 - ten = ten / 16 - if ten == 0 { - hex = append(hex, m) - break - } - hex = append(hex, m) - } - hexStr := []string{} - for i := len(hex) - 1; i >= 0; i-- { - if hex[i] >= 10 { - hexStr = append(hexStr, fmt.Sprintf("%c", 'A'+hex[i]-10)) - } else { - hexStr = append(hexStr, fmt.Sprintf("%d", hex[i])) - } - } - return strings.Join(hexStr, "") }