This commit is contained in:
richboo111
2023-05-12 15:47:50 +08:00
parent fdef98fb4b
commit 59d62adb3f
3 changed files with 55 additions and 53 deletions

View File

@@ -3,6 +3,9 @@ package auto_delivery
import (
"crypto/rand"
"encoding/json"
"math/big"
"strings"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/defsch"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
@@ -10,8 +13,6 @@ import (
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/business/partner"
"git.rosy.net.cn/jx-callback/globals"
"math/big"
"strings"
)
var riderListInfo = make(map[string][]map[string]string, 0)
@@ -129,6 +130,8 @@ func AutoSettingFakeDelivery() {
return
}
}
globals.SugarLogger.Debug("==========%s,%d", riderKey, len(riderListInfo[riderKey]))
globals.SugarLogger.Debug("==========%s", utils.Format4Output(riderListInfo[riderKey], false))
randNumber, _ := rand.Int(rand.Reader, big.NewInt(int64(len(riderListInfo[riderKey]))))
randTime := randNumber.Int64()
if randTime < 0 {

View File

@@ -137,44 +137,44 @@ func MtInit() {
}, url.ClientIDMain)
//副连接
//if url.UrlSub != "" {
// jxutils.CallMsgHandlerAsync(func() {
// connSub, respSub, errSub := websocket.DefaultDialer.Dial(url.UrlSub, nil)
// if errSub != nil || respSub.StatusCode != 101 {
// fmt.Printf("连接失败:%v http响应不成功", errSub)
// }
//
// //关闭
// defer func(conn *websocket.Conn) {
// err := conn.Close()
// if err != nil {
// return
// }
// }(connSub)
//
// //client连接事件
// client := NewClient(url.ClientIDSub, connSub, ClientTypeMt)
// Manager.Connect <- client
//
// errSub = connSub.WriteMessage(websocket.TextMessage, data)
// if errSub != nil {
// fmt.Println(errSub)
// }
//
// for {
// _, msg, err := connSub.ReadMessage()
// temp := string(msg)
// res := JsonCommon(HeartCheckSuccess)
// if err != nil || temp == res {
// break
// } else {
// ReadMsgFromVendor(VendorIDMT, "", msg)
// }
// fmt.Printf("MtInit %s connSub:receive: %s\n", connSub.RemoteAddr(), string(msg))
// }
//
// }, url.ClientIDSub)
//}
if url.UrlSub != "" {
jxutils.CallMsgHandlerAsync(func() {
connSub, respSub, errSub := websocket.DefaultDialer.Dial(url.UrlSub, nil)
if errSub != nil || respSub.StatusCode != 101 {
fmt.Printf("连接失败:%v http响应不成功", errSub)
}
//关闭
defer func(conn *websocket.Conn) {
err := conn.Close()
if err != nil {
return
}
}(connSub)
//client连接事件
client := NewClient(url.ClientIDSub, connSub, ClientTypeMt)
Manager.Connect <- client
errSub = connSub.WriteMessage(websocket.TextMessage, data)
if errSub != nil {
fmt.Println(errSub)
}
for {
_, msg, err := connSub.ReadMessage()
temp := string(msg)
res := JsonCommon(HeartCheckSuccess)
if err != nil || temp == res {
break
} else {
ReadMsgFromVendor(VendorIDMT, "", msg)
}
fmt.Printf("MtInit %s connSub:receive: %s\n", connSub.RemoteAddr(), string(msg))
}
}, url.ClientIDSub)
}
}
@@ -213,7 +213,7 @@ func ReadMsgFromClient(vendorID int, elmAppID string, msg interface{}) {
MsgContent: ElmData,
}
userList = &UserMessageList{
VendorID: VendorIDMT,
VendorID: VendorIDELM,
UserID: ElmData.PayLoad.GroupID,
LatestMsg: ElmData.PayLoad.Content,
LatestTime: int(ElmData.PayLoad.CreateTime),
@@ -266,7 +266,7 @@ func ReadMsgFromVendor(vendorID int, elmAppID string, msg []byte) {
MsgContent: ElmData,
}
userList = &UserMessageList{
VendorID: VendorIDMT,
VendorID: VendorIDELM,
UserID: ElmData.PayLoad.GroupID,
LatestMsg: ElmData.PayLoad.Content,
LatestTime: int(ElmData.PayLoad.CreateTime),
@@ -286,7 +286,11 @@ func ReadMsgFromVendor(vendorID int, elmAppID string, msg []byte) {
//3 cid推送新消息
err = PushMsgByCid(vendorStoreID, vendorID)
//4 长链接通知给客户端
ToClientChan <- clientInfo{Code: SuccessCode, Msg: fmt.Sprintf("%v", err), Data: jxMsg}
if err != nil {
ToClientChan <- clientInfo{Code: SuccessCode, Msg: fmt.Sprintf("%v", err), Data: jxMsg}
} else {
ToClientChan <- clientInfo{Code: SuccessCode, Msg: SuccessMsg, Data: jxMsg}
}
return
}
@@ -365,11 +369,11 @@ func GetNewAndTrim(key string, flag string) (cnt int, err error) {
func GenMsgDetailID(jxMsg *JXMsg, vendorID int, elmAppID string) (msgID string) {
if vendorID == VendorIDMT {
var d1 = jxMsg.MsgContent.(mtwmapi.SingleChat)
msgID = utils.Int2Str(d1.AppID) + ":" + d1.AppPoiCode + ":10:" + utils.Int2Str(d1.OpenUserID)
msgID = utils.Int2Str(d1.AppID) + ":" + d1.AppPoiCode + ":1:" + utils.Int2Str(d1.OpenUserID)
}
if vendorID == VendorIDELM {
var d2 = jxMsg.MsgContent.(ebaiapi.ImMessageSend)
msgID = elmAppID + ":" + d2.PlatformShopID + ":11:" + d2.PayLoad.GroupID
msgID = elmAppID + ":" + d2.PlatformShopID + ":3:" + d2.PayLoad.GroupID
}
return msgID
}
@@ -378,11 +382,11 @@ func GenMsgDetailID(jxMsg *JXMsg, vendorID int, elmAppID string) (msgID string)
func GenMsgListID(jxMsg *JXMsg, vendorID int, elmAppID string) (msgID string) {
if vendorID == VendorIDMT {
var d1 = jxMsg.MsgContent.(mtwmapi.SingleChat)
msgID = utils.Int2Str(d1.AppID) + ":" + d1.AppPoiCode + ":10"
msgID = utils.Int2Str(d1.AppID) + ":" + d1.AppPoiCode + ":1"
}
if vendorID == VendorIDELM {
var d2 = jxMsg.MsgContent.(ebaiapi.ImMessageSend)
msgID = elmAppID + ":" + d2.PlatformShopID + ":11"
msgID = elmAppID + ":" + d2.PlatformShopID + ":3"
}
return msgID
}

View File

@@ -82,13 +82,8 @@ type commonConf struct {
// SendData 客户端写入参数
type SendData struct {
//ClientId string `json:"clientId" validate:"required"` //链接ID
VendorID int `json:"vendorID"` //消息来源平台ID 10-美团 11-饿了么
VendorID int `json:"vendorID"` //消息来源平台ID 1-美团 3-饿了么
Data interface{} `json:"data"` //发送给平台 美团/饿了么消息结构体
//返回值
//Code int `json:"code"`
//Msg string `json:"msg"`
//SendUserId string `json:"sendUserId"`
}
// JXMsg 京西消息结构体