wip
This commit is contained in:
parent
2e40882329
commit
130dfb682a
@ -31,7 +31,7 @@ func init() {
|
|||||||
sapCmd.Flags().String("db-name", "falcon", "database user password")
|
sapCmd.Flags().String("db-name", "falcon", "database user password")
|
||||||
sapCmd.Flags().String("nats-host", "nats", "nats.io broker host address")
|
sapCmd.Flags().String("nats-host", "nats", "nats.io broker host address")
|
||||||
sapCmd.Flags().Int("nats-port", 4222, "nats.io broker tcp port")
|
sapCmd.Flags().Int("nats-port", 4222, "nats.io broker tcp port")
|
||||||
sapCmd.Flags().String("nsq-host", "nats", "NSQ queue system host address")
|
sapCmd.Flags().String("nsq-host", "10.1.152.13", "NSQ queue system host address")
|
||||||
sapCmd.Flags().Int("nsq-port", 4222, "NSQ queue system tcp port")
|
sapCmd.Flags().Int("nsq-port", 4150, "NSQ queue system tcp port")
|
||||||
sapCmd.Flags().String("log-level", "debug", "log level trace")
|
sapCmd.Flags().String("log-level", "debug", "log level trace")
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
type Storager interface {
|
type Storager interface {
|
||||||
StoreBarcode(ctx context.Context, in *types.Barcode) error
|
StoreBarcode(ctx context.Context, in *types.Barcode) error
|
||||||
StoreProductionOrder(ctx context.Context, in *types.ProductionOrder) error
|
StoreProductionOrder(ctx context.Context, in *types.ProductionOrder) error
|
||||||
|
StoreCustomerOrder(ctx context.Context, in *types.CustomerOrder) error
|
||||||
ConfirmBundle(ctx context.Context, barcode string) error
|
ConfirmBundle(ctx context.Context, barcode string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,6 +28,11 @@ type DBConfig struct {
|
|||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StoreCustomerOrder implements Storager.
|
||||||
|
func (s *storage) StoreCustomerOrder(ctx context.Context, in *types.CustomerOrder) error {
|
||||||
|
return s.db.Save(in).Error
|
||||||
|
}
|
||||||
|
|
||||||
// StoreProductionOrder implements Storager.
|
// StoreProductionOrder implements Storager.
|
||||||
func (s *storage) StoreProductionOrder(ctx context.Context, in *types.ProductionOrder) error {
|
func (s *storage) StoreProductionOrder(ctx context.Context, in *types.ProductionOrder) error {
|
||||||
return s.db.Save(in).Error
|
return s.db.Save(in).Error
|
||||||
@ -64,6 +70,7 @@ func Automigrate(db *gorm.DB) error {
|
|||||||
&types.Barcode{},
|
&types.Barcode{},
|
||||||
&types.BundleData{},
|
&types.BundleData{},
|
||||||
&types.ProductionOrder{},
|
&types.ProductionOrder{},
|
||||||
|
&types.CustomerOrder{},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
87
internal/types/customer_order.go
Normal file
87
internal/types/customer_order.go
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CustomerOrder struct {
|
||||||
|
Inst string `json:"INST"`
|
||||||
|
DateTime string `json:"DATE_TIME"`
|
||||||
|
COrderNo int `json:"C_ORDER_NO" gorm:"primaryKey"`
|
||||||
|
POrderNo int `json:"P_ORDER_NO"`
|
||||||
|
SchedulNo int `json:"SCHEDUL_NO"`
|
||||||
|
OrdWeight string `json:"ORD_WEIGHT"`
|
||||||
|
OrdLen string `json:"ORD_LEN"`
|
||||||
|
OrLenTU string `json:"OR_LEN_T_U"`
|
||||||
|
OrLenTL string `json:"OR_LEN_T_L"`
|
||||||
|
PackType int `json:"PACK_TYPE"`
|
||||||
|
SectLayer int `json:"SECT_LAYER"`
|
||||||
|
LayerPack int `json:"LAYER_PACK"`
|
||||||
|
SecLastL int `json:"SEC_LAST_L"`
|
||||||
|
TotalSect int `json:"TOTAL_SECT"`
|
||||||
|
PackWidth int `json:"PACK_WIDTH"`
|
||||||
|
PackHigh int `json:"PACK_HIGH"`
|
||||||
|
OutpTolU int `json:"OUTP_TOL_U"`
|
||||||
|
OutpTolD int `json:"OUTP_TOL_D"`
|
||||||
|
LogoCode int `json:"LOGO_CODE"`
|
||||||
|
SecondLab string `json:"SECOND_LAB"`
|
||||||
|
PaintText string `json:"PAINT_TEXT"`
|
||||||
|
AddLabel1 string `json:"ADD_LABEL1"`
|
||||||
|
AddLabel2 string `json:"ADD_LABEL2"`
|
||||||
|
AddLabel3 string `json:"ADD_LABEL3"`
|
||||||
|
MaterCode string `json:"MATER_CODE"`
|
||||||
|
ProduDate int `json:"PRODU_DATE"`
|
||||||
|
LangLabel string `json:"LANG_LABEL"`
|
||||||
|
Warehouse string `json:"WAREHOUSE"`
|
||||||
|
Location string `json:"LOCATION"`
|
||||||
|
Marking string `json:"MARKING"`
|
||||||
|
DisForwar string `json:"DIS_FORWAR"`
|
||||||
|
NumTies int `json:"NUM_TIES"`
|
||||||
|
DisTies string `json:"DIS_TIES"`
|
||||||
|
DisMachin string `json:"DIS_MACHIN"`
|
||||||
|
Vbeln string `json:"VBELN"`
|
||||||
|
Posnr string `json:"POSNR"`
|
||||||
|
CoType string `json:"CO_TYPE"`
|
||||||
|
LoadBed int `json:"LOAD_BED"`
|
||||||
|
SecNum int `json:"SEC_NUM"`
|
||||||
|
Numpal int `json:"NUMPAL"`
|
||||||
|
Numbul string `json:"NUMBUL"`
|
||||||
|
Marfab int `json:"MARFAB"`
|
||||||
|
Sortb string `json:"SORTB"`
|
||||||
|
Strol1 int `json:"STROL1"`
|
||||||
|
Strol2 string `json:"STROL2"`
|
||||||
|
Strol3 int `json:"STROL3"`
|
||||||
|
Strol4 int `json:"STROL4"`
|
||||||
|
Strol5 int `json:"STROL5"`
|
||||||
|
Strol6 int `json:"STROL6"`
|
||||||
|
Strol7 int `json:"STROL7"`
|
||||||
|
Strol8 int `json:"STROL8"`
|
||||||
|
Strol9 int `json:"STROL9"`
|
||||||
|
Strol10 int `json:"STROL10"`
|
||||||
|
Strol11 int `json:"STROL11"`
|
||||||
|
Strol12 int `json:"STROL12"`
|
||||||
|
Strol13 int `json:"STROL13"`
|
||||||
|
Strol14 int `json:"STROL14"`
|
||||||
|
Strol15 int `json:"STROL15"`
|
||||||
|
Strol16 string `json:"STROL16"`
|
||||||
|
Strol17 string `json:"STROL17"`
|
||||||
|
Strol18 string `json:"STROL18"`
|
||||||
|
Strol19 string `json:"STROL19"`
|
||||||
|
Strol20 string `json:"STROL20"`
|
||||||
|
Strol21 string `json:"STROL21"`
|
||||||
|
Strol22 string `json:"STROL22"`
|
||||||
|
Strol23 string `json:"STROL23"`
|
||||||
|
Strol24 string `json:"STROL24"`
|
||||||
|
Strol25 string `json:"STROL25"`
|
||||||
|
Strol26 string `json:"STROL26"`
|
||||||
|
Strol27 string `json:"STROL27"`
|
||||||
|
CreatedAt time.Time `gorm:"->;<-:create" json:"createdat,omitempty"`
|
||||||
|
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||||
|
DeletedAt gorm.DeletedAt `gorm:"index"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (CustomerOrder) TableName() string {
|
||||||
|
return "sap_co"
|
||||||
|
}
|
@ -65,7 +65,7 @@ func Run(cmd *cobra.Command, args []string) {
|
|||||||
NSQAddress: nsqHost,
|
NSQAddress: nsqHost,
|
||||||
NSQPort: nsqPort,
|
NSQPort: nsqPort,
|
||||||
Unmarshaler: cml04eventer.JSONMarshaler{},
|
Unmarshaler: cml04eventer.JSONMarshaler{},
|
||||||
Channel: "cml04-falcon-system",
|
Channel: "CML04-FALCON",
|
||||||
}, log)
|
}, log)
|
||||||
// handle error
|
// handle error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -77,7 +77,7 @@ func Run(cmd *cobra.Command, args []string) {
|
|||||||
// create context with cancel
|
// create context with cancel
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
eventChan, err := subscriber.SubscribeEvent(ctx, "FALCON-IN")
|
eventChan, err := subscriber.SubscribeEvent(ctx, "SAP-IN")
|
||||||
// handle error
|
// handle error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("nsq subscription failed", err, logFields)
|
log.Error("nsq subscription failed", err, logFields)
|
||||||
@ -85,8 +85,6 @@ func Run(cmd *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
for event := range eventChan {
|
for event := range eventChan {
|
||||||
// log info banner
|
|
||||||
log.Info("received new SAP event", logFields.Add(logger.LogFields{"event_id": event.EventID}))
|
|
||||||
// create buffer
|
// create buffer
|
||||||
buffer := bytes.NewBuffer(event.EventData)
|
buffer := bytes.NewBuffer(event.EventData)
|
||||||
// get event message subject
|
// get event message subject
|
||||||
@ -101,11 +99,17 @@ func Run(cmd *cobra.Command, args []string) {
|
|||||||
log.Error("decode event message data failed", err, logFields)
|
log.Error("decode event message data failed", err, logFields)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
// log info banner
|
||||||
|
log.Info("received new production data from SAP event", logFields.Add(
|
||||||
|
logger.LogFields{
|
||||||
|
"event_id": event.EventID,
|
||||||
|
"production_order": po.POrderNo,
|
||||||
|
}))
|
||||||
if err := storage.StoreProductionOrder(ctx, po); err != nil {
|
if err := storage.StoreProductionOrder(ctx, po); err != nil {
|
||||||
log.Error("store production order data failed", err, logFields)
|
log.Error("store production order data failed", err, logFields)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
case "sap.in.telegramas.z_sms-10002":
|
||||||
default:
|
default:
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user