gigibox
2023-06-15 ff3cadba4a63cd1b63cd0e36358f49ccedb88bef
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
package report
 
import (
    "encoding/json"
 
    "kingdee-dbapi/cache"
    "kingdee-dbapi/config"
    "kingdee-dbapi/kingdee"
    "kingdee-dbapi/models"
    "kingdee-dbapi/nsqclient"
)
 
func SendOrder() {
    var completedOrderNo = make(map[string]struct{})
    list := kingdee.SeOrderList()
 
    for i := 0; i < len(list); i++ {
        if cache.Exists(list[i].FBillNo) {
            list = append(list[:i], list[i+1:]...)
        } else {
            completedOrderNo[list[i].FBillNo] = struct{}{}
        }
    }
 
    b, _ := json.Marshal(list)
 
    ok := nsqclient.HttpPost(config.Options.OrderTopic, b)
    if ok {
        // 写入数据库, 标记已经上报过了,避免重复上报
        for orderNo, _ := range completedOrderNo {
            cursor := models.Order{
                OrderNo: orderNo,
            }
 
            cursor.Insert()
            cache.WriteCache(orderNo)
        }
    }
 
    // 逐条发送
    //for idx, _ := range list {
    //    // 已经推送过的订单
    //    if cache.Exists(list[idx].FBillNo) {
    //        continue
    //    }
    //
    //    b, _ := json.Marshal(list[idx])
    //
    //    ok := nsqclient.HttpPost(config.Options.OrderTopic, b)
    //    if ok {
    //        completedOrderNo[list[idx].FBillNo] = struct{}{}
    //    }
    //}
}
 
func SendInventory() {
    list := kingdee.ICInventory()
 
    // 每次发 300 条
    for i := 0; i < len(list); i += 300 {
        end := i + 300
        if end > len(list) {
            end = len(list)
        }
 
        b, _ := json.Marshal(list[i:end])
 
        nsqclient.HttpPost(config.Options.InventoryTopic, b)
    }
}