回调
CI / changes (push) Successful in 37s
CI / ad (push) Successful in 30s
CI / admin (push) Successful in 22s
CI / bff (push) Successful in 39s
CI / chore (push) Successful in 20s
CI / equipment (push) Successful in 19s
CI / express (push) Successful in 17s
CI / product (push) Successful in 16s
CI / record (push) Successful in 17s
CI / sale (push) Successful in 16s
CI / task (push) Successful in 16s
CI / user (push) Successful in 17s
CI / wecom (push) Successful in 18s
CI / changes (push) Successful in 37s
CI / ad (push) Successful in 30s
CI / admin (push) Successful in 22s
CI / bff (push) Successful in 39s
CI / chore (push) Successful in 20s
CI / equipment (push) Successful in 19s
CI / express (push) Successful in 17s
CI / product (push) Successful in 16s
CI / record (push) Successful in 17s
CI / sale (push) Successful in 16s
CI / task (push) Successful in 16s
CI / user (push) Successful in 17s
CI / wecom (push) Successful in 18s
This commit is contained in:
@@ -2,10 +2,15 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
|
||||
"lone-services/rpc/express/pb"
|
||||
order "lone-services/rpc/order/pb"
|
||||
"lone-services/services/express/internal/dao"
|
||||
"lone-services/services/express/internal/model"
|
||||
"lone-services/services/express/internal/svc"
|
||||
"lone-services/services/express/internal/transit"
|
||||
"strconv"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
@@ -26,7 +31,181 @@ func NewExpressSfBackLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Exp
|
||||
}
|
||||
|
||||
func (l *ExpressSfBackLogic) ExpressSfBack(in *express.EmtpyRequest) (*express.SfResponse, error) {
|
||||
info := utils.GetHeaderAndBody(l.ctx)
|
||||
l.Logger.Error("ExpressSfBack", "info", string(info.Body))
|
||||
return &express.SfResponse{}, nil
|
||||
body := utils.GetBody(l.ctx)
|
||||
ret := express.SfResponse{
|
||||
ReturnCode: "1000",
|
||||
ReturnMsg: "系统异常",
|
||||
}
|
||||
if body == utils.StringEmpty {
|
||||
return &ret, nil
|
||||
}
|
||||
l.Logger.Info("SF back data:", body)
|
||||
|
||||
ok := l.Back(body)
|
||||
if ok {
|
||||
ret.ReturnCode = "000"
|
||||
ret.ReturnMsg = "成功"
|
||||
}
|
||||
|
||||
return &ret, nil
|
||||
}
|
||||
|
||||
func (l *ExpressSfBackLogic) Back(body string) bool {
|
||||
var result map[string]interface{}
|
||||
ok := utils.JsonStringToStruct(body, &result)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
bodyData, ok := result["Body"].(map[string]interface{})
|
||||
if !ok {
|
||||
l.Logger.Error("back Body interface error ")
|
||||
return false
|
||||
}
|
||||
waybillRoute, ok := bodyData["WaybillRoute"].([]interface{})
|
||||
if !ok || len(waybillRoute) < utils.NumberOne {
|
||||
l.Logger.Error("back body WaybillRoute error empty")
|
||||
return false
|
||||
}
|
||||
items := make(map[string][]dao.ExpressQueryItems)
|
||||
var orderIds []string
|
||||
end := make(map[string]bool)
|
||||
|
||||
for i := utils.NumberZero; i < len(waybillRoute); i++ {
|
||||
route := waybillRoute[i].(map[string]interface{})
|
||||
if _, ok := route["orderid"].(string); !ok {
|
||||
l.Logger.Error("back body WaybillRoute error empty")
|
||||
continue
|
||||
}
|
||||
orderId := route["orderid"].(string)
|
||||
orderIds = append(orderIds, orderId)
|
||||
tmp := dao.ExpressQueryItems{
|
||||
AcceptAddress: route["acceptAddress"].(string),
|
||||
AcceptTime: route["acceptTime"].(string),
|
||||
OpCode: route["opCode"].(string),
|
||||
Remark: route["remark"].(string),
|
||||
}
|
||||
tmp.LastMd5 = utils.MD5Encrypt(tmp.OpCode + tmp.AcceptTime + tmp.Remark)
|
||||
if _, okk := route["secondaryStatusCode"]; okk {
|
||||
tmp.SecondaryStatusCode = route["secondaryStatusCode"].(string)
|
||||
}
|
||||
if _, okk := route["secondaryStatusName"]; okk {
|
||||
tmp.SecondaryStatusName = route["secondaryStatusName"].(string)
|
||||
}
|
||||
if _, okk := route["firstStatusCode"]; okk {
|
||||
tmp.FirstStatusCode = route["firstStatusCode"].(string)
|
||||
}
|
||||
if _, okk := route["firstStatusName"]; okk {
|
||||
tmp.FirstStatusName = route["firstStatusName"].(string)
|
||||
}
|
||||
|
||||
items[orderId] = append(items[orderId], tmp)
|
||||
end[orderId] = false
|
||||
if ok := transit.SfSingedCodeMap[tmp.OpCode]; ok {
|
||||
end[orderId] = true
|
||||
}
|
||||
}
|
||||
if len(orderIds) < utils.NumberOne {
|
||||
l.Logger.Error("no ", orderIds)
|
||||
return false
|
||||
}
|
||||
orderIds = utils.UniqueStr(orderIds)
|
||||
|
||||
modelObj := model.DeliveryOrderModel{}.Init()
|
||||
|
||||
w := modelbase.Params{In: map[string][]string{
|
||||
"order_sn": orderIds,
|
||||
}}
|
||||
var info []dao.DeliveryOrderUpTransit
|
||||
err := modelObj.Items(w, &info)
|
||||
if err != nil {
|
||||
utils.Logger.Error("get deliverGoods error ", err)
|
||||
return false
|
||||
}
|
||||
if len(info) < utils.NumberOne {
|
||||
return false
|
||||
}
|
||||
modelObj.Begin()
|
||||
|
||||
for _, item := range info {
|
||||
if item.Status == dao.SendStatusOver {
|
||||
continue
|
||||
}
|
||||
if end[item.OrderSn] {
|
||||
item.Status = dao.SendStatusOver
|
||||
item.ChangeEstimatedTime = utils.StatusFail
|
||||
|
||||
w = modelbase.Params{Eq: map[string]string{"delivery_order_id": strconv.Itoa(item.Id)}}
|
||||
expEdit := dao.DeliveryExpStatus{
|
||||
Status: utils.StatusOk,
|
||||
}
|
||||
_, err = model.DeliveryOrderExpModel{}.Init().Edit(w, &expEdit)
|
||||
if err != nil {
|
||||
l.Logger.Error("back set deliver exp error ", err)
|
||||
modelObj.Rollback()
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if v, iOk := items[item.OrderSn]; iOk {
|
||||
var old []dao.ExpressQueryItems
|
||||
if utils.JsonStringToStruct(item.TransitQuery, &old) {
|
||||
l.Logger.Error("back set deliver transit error: ", item.TransitQuery)
|
||||
}
|
||||
oldMap := l.getSfMap(old)
|
||||
for i := len(v) - 1; i >= utils.NumberZero; i-- {
|
||||
if cOk := oldMap[v[i].LastMd5]; !cOk {
|
||||
old = append(old, v[i])
|
||||
}
|
||||
}
|
||||
item.TransitQuery = utils.StructToJson(old)
|
||||
w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(item.Id)}}
|
||||
if end[item.OrderSn] {
|
||||
item.SignTime = utils.Now()
|
||||
}
|
||||
_, err = modelObj.Edit(w, &item)
|
||||
if err != nil {
|
||||
l.Logger.Error("back set deliver info error ", err)
|
||||
modelObj.Rollback()
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if end[item.OrderSn] {
|
||||
if item.Type == dao.DeliveryTypeOrder {
|
||||
cli, err := svc.GetRpcClient(l.svcCtx.OrderSvcName)
|
||||
if err != nil {
|
||||
modelObj.Rollback()
|
||||
logx.Errorf("get order err: %v", err)
|
||||
return false
|
||||
}
|
||||
|
||||
client := order.NewOrderClient(cli.Conn())
|
||||
update := order.UpdateOrderDeliverStatusRequest{
|
||||
Id: item.ObjId,
|
||||
DeliverStatus: int32(item.Status),
|
||||
SignTime: utils.Now().GoString(),
|
||||
}
|
||||
_, err = client.UpdateOrderDeliverStatus(l.ctx, &update)
|
||||
if err != nil {
|
||||
modelObj.Rollback()
|
||||
logx.Errorf("get order err: %v", err)
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
modelObj.Commit()
|
||||
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
func (l *ExpressSfBackLogic) getSfMap(items []dao.ExpressQueryItems) map[string]bool {
|
||||
ret := make(map[string]bool)
|
||||
for _, item := range items {
|
||||
ret[item.LastMd5] = true
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user