zhangqian
2023-12-19 c688f083caf965cd13f640098ad204d8fd8c9e69
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package test
 
import (
    "apsClient/model/common"
    "apsClient/nsq"
    "encoding/json"
    "fmt"
    "github.com/shopspring/decimal"
    "log"
    "testing"
    "time"
)
 
func TestHandleMessage(t *testing.T) {
    Init()
    var tasks = make([]*common.DeliverScheduleTask, 0)
    startTime, _ := time.ParseInLocation("2006-01-02 15:04", "2023-08-22 08:00", time.Local)
    endTime, _ := time.ParseInLocation("2006-01-02 15:04", "2023-08-23 12:00", time.Local)
    fmt.Println(startTime)
    fmt.Println(startTime.Unix())
    startTime1, _ := time.ParseInLocation("2006-01-02 15:04", "2023-08-22 08:00", time.Local)
    endTime1, _ := time.ParseInLocation("2006-01-02 15:04", "2023-08-22 18:00", time.Local)
 
    startTime2, _ := time.ParseInLocation("2006-01-02 15:04", "2023-08-22 18:00", time.Local)
    endTime2, _ := time.ParseInLocation("2006-01-02 15:04", "2023-08-23 06:00", time.Local)
 
    inputMaterials := []*common.ProcedureMaterial{{
        MaterialID:   "MaterialID 1",
        MaterialName: "这是一个输入物料名",
        Amount:       decimal.NewFromFloat(100),
        Unit:         "件",
    }}
    outputMaterials := []*common.ProcedureMaterial{{
        MaterialID:   "MaterialID",
        MaterialName: "这是一个输出物料名",
        Amount:       decimal.NewFromFloat(20),
        Unit:         "件",
    }}
    workers := []*common.ProcedureWorker{{
        WorkerID:   "WorkerID 1",
        WorkerName: "张三",
        PhoneNum:   "18800000000",
        StartTime:  startTime1.Unix(),
        EndTime:    endTime1.Unix(),
    },
        {
            WorkerID:   "WorkerID 2",
            WorkerName: "李四",
            PhoneNum:   "19900000000",
            StartTime:  startTime2.Unix(),
            EndTime:    endTime2.Unix(),
        }}
 
    task1 := common.DeliverScheduleTask{
        WorkOrder: common.WorkOrder{
            WorkOrderID: "WorkOrderID 1",
            OrderID:     "OrderID 1",
            ProductID:   "ProductID 1",
            ProductName: "ProductName 1",
            Parameter:   "Parameter 1",
            Customer:    "Customer 1",
            DeliverDate: "2023-08-19",
            OrderAttr:   "OrderAttr",
            Amount:      decimal.NewFromFloat(4),
            Unit:        "件",
            StartTime:   startTime.Unix(),
            EndTime:     endTime.Unix(),
        },
        Procedures: []*common.ProductProcedure{{
            ProcedureID:     "ProcedureID 1",
            ProcedureName:   "ProcedureName 1",
            DeviceID:        "DeviceID1",
            DeviceName:      "DeviceName 1",
            StartTime:       startTime.Unix(),
            EndTime:         endTime.Unix(),
            WorkHours:       decimal.NewFromFloat(4),
            InputMaterials:  inputMaterials,
            OutputMaterials: outputMaterials,
            Workers:         workers,
        }, {ProcedureID: "ProcedureID 2",
            ProcedureName:   "ProcedureName 2",
            DeviceID:        "DeviceID2",
            DeviceName:      "DeviceName 1",
            StartTime:       startTime.Unix(),
            EndTime:         endTime.Unix(),
            WorkHours:       decimal.NewFromFloat(4),
            InputMaterials:  inputMaterials,
            OutputMaterials: outputMaterials,
            Workers:         workers,
        }},
    }
    task2 := common.DeliverScheduleTask{
        WorkOrder: common.WorkOrder{
            WorkOrderID: "WorkOrderID 2",
            OrderID:     "OrderID 2",
            ProductID:   "ProductID 2",
            ProductName: "ProductName 2",
            Parameter:   "Parameter 2",
            Customer:    "Customer 2",
            DeliverDate: "2023-08-19",
            OrderAttr:   "OrderAttr",
            Amount:      decimal.NewFromFloat(4),
            Unit:        "件",
            StartTime:   startTime.Unix(),
            EndTime:     endTime.Unix(),
        },
        Procedures: []*common.ProductProcedure{{
            ProcedureID:     "ProcedureID 3",
            ProcedureName:   "ProcedureName 3",
            DeviceID:        "DeviceID1",
            DeviceName:      "DeviceName 1",
            StartTime:       startTime.Unix(),
            EndTime:         endTime.Unix(),
            WorkHours:       decimal.NewFromFloat(4),
            InputMaterials:  inputMaterials,
            OutputMaterials: outputMaterials,
            Workers:         workers,
        }, {
            ProcedureID:     "ProcedureID 4",
            ProcedureName:   "ProcedureName 4",
            DeviceID:        "DeviceID2",
            DeviceName:      "DeviceName 1",
            StartTime:       startTime.Unix(),
            EndTime:         endTime.Unix(),
            WorkHours:       decimal.NewFromFloat(4),
            InputMaterials:  inputMaterials,
            OutputMaterials: outputMaterials,
            Workers:         workers,
        },
        },
    }
    tasks = append(tasks, &task1, &task2)
    data, _ := json.Marshal(&tasks)
    handler := nsq.ScheduleTask{}
    err := handler.HandleMessage(data)
    if err != nil {
        log.Fatal(err)
    }
}