refactor: Update 'Content' field in HasuraRepository.CreateNew method
This commit is contained in:
+12
-12
@@ -92,26 +92,26 @@ type ParsedMessage struct {
|
||||
DateTime string `json:"dateTime"` // 日期时间: The date and time of the message (e.g., '150631').
|
||||
PriorityIndicator string `json:"priorityIndicator"` // 优先级标识: The priority level of the message (e.g., 'FF').
|
||||
PrimaryAddress string `json:"primaryAddress"` // 主要地址: The primary recipient address (e.g., 'ZBTJZPZX').
|
||||
SecondaryAddresses []string `json:"secondaryAddresses,omitempty"` // 次要地址: Additional recipient addresses (e.g., ['150630', 'ZBACZQZX']).
|
||||
SecondaryAddresses string `json:"secondaryAddresses,omitempty"` // 次要地址: Additional recipient addresses (e.g., ['150630', 'ZBACZQZX']).
|
||||
Originator string `json:"originator,omitempty"` // 发件人: The sender of the message.
|
||||
OriginatorDateTime string `json:"originatorDateTime,omitempty"` // 发件日期时间: The date and time when the originator sent the message.
|
||||
Category string `json:"category,omitempty"` // 类别: The category of the message.
|
||||
Text string `json:"bodyAndFooter,omitempty"` // 正文和页脚: The body and footer of the message (e.g., 'CALLSIGN/ABC123\nFPL/AB1234-AB\n...').
|
||||
Body string `json:"body,omitempty"` // 正文: The body of the message.
|
||||
BodyData interface{} `json:"bodyData,omitempty"` // 正文数据: Parsed body data.
|
||||
ReceivedAt time.Time `json:"receivedAt"` // 接收时间: The time when the message was received.
|
||||
ParsedAt time.Time `json:"parsedAt,omitempty"` // 解析时间: The time when the message was parsed.
|
||||
DispatchedAt time.Time `json:"dispatchedAt,omitempty"` // 分发时间: The time when the message was dispatched.
|
||||
NeedDispatch bool `json:"needDispatch"` // 需要分发: Indicates if the message needs to be dispatched.
|
||||
Parsed bool `json:"parsed"` // 解析: Indicates if the message has been parsed.
|
||||
Comments string `json:"comments,omitempty"` // 备注: Additional comments.
|
||||
Body string // 正文和页脚: The body and footer of the message (e.g., 'CALLSIGN/ABC123\nFPL/AB1234-AB\n...').
|
||||
Content string `json:"content,omitempty"` // 正文: The body of the message.
|
||||
BodyData interface{} `json:"bodyData,omitempty"` // 正文数据: Parsed body data.
|
||||
ReceivedAt time.Time `json:"receivedAt"` // 接收时间: The time when the message was received.
|
||||
ParsedAt time.Time `json:"parsedAt,omitempty"` // 解析时间: The time when the message was parsed.
|
||||
DispatchedAt time.Time `json:"dispatchedAt,omitempty"` // 分发时间: The time when the message was dispatched.
|
||||
NeedDispatch bool `json:"needDispatch"` // 需要分发: Indicates if the message needs to be dispatched.
|
||||
Parsed bool `json:"parsed"` // 解析: Indicates if the message has been parsed.
|
||||
Comments string `json:"comments,omitempty"` // 备注: Additional comments.
|
||||
|
||||
}
|
||||
|
||||
// NewParsedMessage initializes a ParsedMessage with default values
|
||||
func NewParsedMessage() *ParsedMessage {
|
||||
return &ParsedMessage{
|
||||
SecondaryAddresses: []string{},
|
||||
Parsed: false,
|
||||
// SecondaryAddresses: []string{},
|
||||
Parsed: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,9 +28,9 @@ func New(config *config.Config) *MessageHandler {
|
||||
}
|
||||
}
|
||||
|
||||
func (n *MessageHandler) HandleMessage(msg *message.Message) error {
|
||||
n.mu.Lock()
|
||||
defer n.mu.Unlock()
|
||||
func (handler *MessageHandler) HandleMessage(msg *message.Message) error {
|
||||
handler.mu.Lock()
|
||||
defer handler.mu.Unlock()
|
||||
log := utils.GetSugaredLogger()
|
||||
if msg.Payload == nil {
|
||||
log.Error("empty message")
|
||||
@@ -43,7 +43,7 @@ func (n *MessageHandler) HandleMessage(msg *message.Message) error {
|
||||
} else {
|
||||
log.Infof("parsed [%s]: %v\n", msg.UUID, parsed)
|
||||
}
|
||||
n.SaveMessage(parsed, msg.UUID)
|
||||
handler.SaveMessage(parsed, msg.UUID)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -196,7 +196,7 @@ func Parse(rawText string) *domain.ParsedMessage {
|
||||
message, err := ParseHeader(rawText)
|
||||
if err != nil {
|
||||
msg := domain.NewParsedMessage()
|
||||
msg.Text = rawText
|
||||
msg.Content = rawText
|
||||
return msg
|
||||
}
|
||||
|
||||
@@ -234,12 +234,12 @@ func ParseHeader(fullMessage string) (domain.ParsedMessage, error) {
|
||||
|
||||
if len(lines) < 3 {
|
||||
log.Warnf("invalid message format: %s", fullMessage)
|
||||
return domain.ParsedMessage{Text: fullMessage}, fmt.Errorf("invalid message format: %s", fullMessage)
|
||||
return domain.ParsedMessage{Content: fullMessage}, fmt.Errorf("invalid message format: %s", fullMessage)
|
||||
}
|
||||
|
||||
_, messageID, dateTime, err := parseStartIndicator(lines[0])
|
||||
if err != nil {
|
||||
return domain.ParsedMessage{Text: fullMessage}, err
|
||||
return domain.ParsedMessage{Content: fullMessage}, err
|
||||
}
|
||||
|
||||
priorityIndicator, primaryAddress := parsePriorityAndPrimary(lines[1])
|
||||
@@ -253,7 +253,7 @@ func ParseHeader(fullMessage string) (domain.ParsedMessage, error) {
|
||||
SecondaryAddresses: secondaryAddresses,
|
||||
Originator: originator,
|
||||
OriginatorDateTime: originatorDateTime,
|
||||
Text: fullMessage,
|
||||
Content: fullMessage,
|
||||
Body: body,
|
||||
ReceivedAt: time.Now(),
|
||||
}, nil
|
||||
@@ -277,9 +277,9 @@ func parsePriorityAndPrimary(line string) (string, string) {
|
||||
return "", ""
|
||||
}
|
||||
|
||||
func parseRemainingLines(lines []string) ([]string, string, string, string) {
|
||||
func parseRemainingLines(lines []string) (string, string, string, string) {
|
||||
var (
|
||||
secondaryAddresses []string
|
||||
secondaryAddresses string
|
||||
originator string
|
||||
originatorDateTime string
|
||||
bodyAndFooter strings.Builder
|
||||
@@ -311,7 +311,7 @@ func parseRemainingLines(lines []string) ([]string, string, string, string) {
|
||||
originatorDateTime = o1
|
||||
originator = o2
|
||||
} else {
|
||||
secondaryAddresses = append(secondaryAddresses, line)
|
||||
secondaryAddresses = secondaryAddresses + " " + line
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ NNNN`
|
||||
Expect(parsedHeader.DateTime).To(Equal("160530"))
|
||||
Expect(parsedHeader.PriorityIndicator).To(Equal("QU"))
|
||||
Expect(parsedHeader.PrimaryAddress).To(Equal("TSNZPCA"))
|
||||
Expect(parsedHeader.SecondaryAddresses).To(Equal([]string{"QU PEKUDCA TSNUOCA TSNZPCA TSNUFCA"}))
|
||||
Expect(parsedHeader.SecondaryAddresses).To(Equal(" QU PEKUDCA TSNUOCA TSNZPCA TSNUFCA"))
|
||||
})
|
||||
|
||||
It("should parse the header correctly with originator information", func() {
|
||||
@@ -92,7 +92,7 @@ NNNN`
|
||||
Expect(parsedHeader.DateTime).To(Equal("171000"))
|
||||
Expect(parsedHeader.PriorityIndicator).To(Equal("QU"))
|
||||
Expect(parsedHeader.PrimaryAddress).To(Equal("TSNZPCA"))
|
||||
Expect(parsedHeader.SecondaryAddresses).To(Equal([]string{"QU PEKUDCA TSNUOCA TSNZPCA TSNUFCA"}))
|
||||
Expect(parsedHeader.SecondaryAddresses).To(Equal(" QU PEKUDCA TSNUOCA TSNZPCA TSNUFCA"))
|
||||
Expect(parsedHeader.Originator).To(Equal("SELOZKE"))
|
||||
Expect(parsedHeader.OriginatorDateTime).To(Equal("170999"))
|
||||
})
|
||||
@@ -288,7 +288,7 @@ NNNN
|
||||
Expect(parsedMessage.MessageID).To(Equal("TMQ2526"))
|
||||
Expect(parsedMessage.DateTime).To(Equal("141605"))
|
||||
Expect(parsedMessage.PrimaryAddress).To(Equal("ZBTJZPZX"))
|
||||
Expect(parsedMessage.SecondaryAddresses).To(BeNil())
|
||||
Expect(parsedMessage.SecondaryAddresses).To(Equal(""))
|
||||
Expect(parsedMessage.PriorityIndicator).To(Equal("FF"))
|
||||
Expect(parsedMessage.OriginatorDateTime).To(Equal("141604"))
|
||||
Expect(parsedMessage.Originator).To(Equal("ZBACZQZX"))
|
||||
@@ -339,7 +339,7 @@ NNNN
|
||||
Expect(parsedMessage.MessageID).To(Equal("TMQ2617"))
|
||||
Expect(parsedMessage.DateTime).To(Equal("142150"))
|
||||
Expect(parsedMessage.PrimaryAddress).To(Equal("ZBTJZPZX"))
|
||||
Expect(parsedMessage.SecondaryAddresses).To(BeNil())
|
||||
Expect(parsedMessage.SecondaryAddresses).To(Equal(""))
|
||||
Expect(parsedMessage.PriorityIndicator).To(Equal("GG"))
|
||||
Expect(parsedMessage.OriginatorDateTime).To(Equal("150551"))
|
||||
Expect(parsedMessage.Originator).To(Equal("ZBTJUOBK"))
|
||||
@@ -409,7 +409,7 @@ NNNN`
|
||||
It("should parse remaining lines correctly", func() {
|
||||
lines := []string{"QU PEKUDCA TSNUOCA TSNZPCA TSNUFCA", ".SELOZKE 170999", "BEGIN PART 01"}
|
||||
secondaryAddresses, originator, originatorDateTime, bodyAndFooter := parseRemainingLines(lines)
|
||||
Expect(secondaryAddresses).To(Equal([]string{"QU PEKUDCA TSNUOCA TSNZPCA TSNUFCA"}))
|
||||
Expect(secondaryAddresses).To(Equal(" QU PEKUDCA TSNUOCA TSNZPCA TSNUFCA"))
|
||||
Expect(originator).To(Equal("SELOZKE"))
|
||||
Expect(originatorDateTime).To(Equal("170999"))
|
||||
Expect(bodyAndFooter).To(Equal("BEGIN PART 01\n"))
|
||||
|
||||
@@ -38,7 +38,7 @@ func (hr *HasuraRepository) CreateNew(pm *domain.ParsedMessage) error {
|
||||
Priority_indicator: pm.PriorityIndicator,
|
||||
Primary_address: pm.PrimaryAddress,
|
||||
Secondary_addresses: string(secondAddress),
|
||||
Content: pm.Text,
|
||||
Content: pm.Content,
|
||||
Body_data: bodyString,
|
||||
Category: pm.Category,
|
||||
Date_time: pm.DateTime,
|
||||
|
||||
Reference in New Issue
Block a user