Kaynağa Gözat

1、处理Token校验恢复登录状态的问题;
2、支持 HdWROrderReq 和 WROutApplyReq 总线请求。

zhou.xiaoning 2 yıl önce
ebeveyn
işleme
0c7e2369be

+ 17 - 0
api/v1/account/login.go

@@ -1,9 +1,11 @@
 package account
 
 import (
+	"errors"
 	"mtp20access/global"
 	"mtp20access/model/account/request"
 	accountRsp "mtp20access/model/account/response"
+	commonRequest "mtp20access/model/common/request"
 	"mtp20access/model/common/response"
 	accountService "mtp20access/service/account"
 	"mtp20access/utils"
@@ -47,5 +49,20 @@ func Login(c *gin.Context) {
 // @Router   /Account/TokenCheck [get]
 // @Tags    账户服务
 func TokenCheck(c *gin.Context) {
+	// 获取请求账号信息
+	s, exists := c.Get("claims")
+	if !exists {
+		err := errors.New("获取请求账号信息异常")
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	claims := s.(*commonRequest.CustomClaims)
+
+	token := c.Request.Header.Get("x-token")
+	if err := accountService.RestoreLoginWithToken(claims.LoginID, claims.Group, token); err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+
 	response.Ok(c)
 }

+ 4 - 4
config.yaml

@@ -20,7 +20,7 @@ jwt:
 # redis configuration
 redis:
   db: 0
-  addr: '192.168.31.139:5007'
+  addr: '192.168.31.204:5007'
   password: ''
 
 # system configuration
@@ -28,7 +28,7 @@ system:
   env: 'develop'  # "develop" & "public", Change to "develop" to skip authentication for development mode
   addr: 8888
   need-quote-publish: true # 是否需要连接行情发布服务
-  quote-publish-addr: '192.168.31.139:5004' # 行情发布服务地址
+  quote-publish-addr: '192.168.31.204:5004' # 行情发布服务地址
 
 # local configuration
 local:
@@ -41,14 +41,14 @@ oracle:
   address: '192.168.31.88'
   name: 'orcl'
   port: '1521'
-  user: 'mtp2_test139'
+  user: 'mtp2_test204'
   pwd: 'muchinfo'
   max-idle-conns: 10
   max-open-conns: 100
 
 # rabbitmq configuration
 rabbitmq:
-  url: 'amqp://guest:guest@192.168.31.139:5020/test'
+  url: 'amqp://guest:guest@192.168.31.204:5020/test'
   exchange: 'entry'
 
 # 跨域配置

+ 6 - 0
global/funcode.go

@@ -78,6 +78,12 @@ var (
 	GZCenterPurchaseOrderRsp = 1441892 // 广钻集采认购下单响应
 	BSWMSReckonPayReq        = 1114135 // WMS结算单支付接口请求
 	BSWMSReckonPayRsp        = 1114136 // WMS结算单支付接口响应
+
+	HdWROrderReq  = 1441807 // 持仓单挂牌请求
+	HdWROrderRsp  = 1441808 // 持仓单挂牌应答
+	WROutApplyReq = 1900657 // 仓单出库申请
+	WROutApplyRsp = 1900658 // 仓单出库申请响应
+
 )
 
 // 通过请求功能码获取对应主题的方法

+ 28 - 0
initialize/rabbitmq.go

@@ -385,6 +385,32 @@ func (t *MQProc) getRspProtobuf(msg *[]byte) (funcode uint32, sessionId uint32,
 			bytes = &bs
 			serialNumber = p.GetHeader().GetRequestID()
 		}
+	case global.HdWROrderRsp:
+		var p pb.HdWROrderRsp
+		if err = proto.Unmarshal(b, &p); err != nil {
+			global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
+			return
+		}
+		if bs, e := protojson.Marshal(&p); e != nil {
+			global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
+			return
+		} else {
+			bytes = &bs
+			serialNumber = p.GetHeader().GetRequestID()
+		}
+	case global.WROutApplyRsp:
+		var p pb.WROutApplyRsp
+		if err = proto.Unmarshal(b, &p); err != nil {
+			global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
+			return
+		}
+		if bs, e := protojson.Marshal(&p); e != nil {
+			global.M2A_LOG.Error("总线回复数据反序列化失败", zap.Error(err))
+			return
+		} else {
+			bytes = &bs
+			serialNumber = p.GetHeader().GetRequestID()
+		}
 	case global.ReceiptZSOutApplyRsp: // 钻石出库申请接口响应
 		var p pb.ReceiptZSOutApplyRsp
 		if err = proto.Unmarshal(b, &p); err != nil {
@@ -631,6 +657,8 @@ func InitFuncodeTopic() {
 	}
 	global.M2A_FuncodeTopic[global.TOPIC_REQ_WAREHOUSE_TRADE] = []int{
 		global.WRListingCancelOrderReq,
+		global.HdWROrderReq,
+		global.WROutApplyReq,
 	}
 	global.M2A_FuncodeTopic[global.TOPIC_REQ_WAREHOUSE_TRADE_GZ] = []int{
 		global.GoodsFavoriteOperateReq,

+ 36 - 0
model/mq/request/mq.go

@@ -478,6 +478,42 @@ func (r *MQBodyReq) GetProtoBytes(serialNumber *uint32) (bytes *[]byte, err erro
 		} else {
 			bytes = &b
 		}
+	case global.HdWROrderReq:
+		m := pb.HdWROrderReq{}
+		if err = r.reflect(data, &m); err != nil {
+			return
+		}
+		if m.Header != nil {
+			m.Header.RequestID = serialNumber
+		} else {
+			err = errors.New("请求信息序列化失败")
+			return
+		}
+		if b, e := proto.Marshal(&m); e != nil {
+			global.M2A_LOG.Error(e.Error(), zap.Error(e))
+			err = errors.New("请求信息序列化失败")
+			return
+		} else {
+			bytes = &b
+		}
+	case global.WROutApplyReq:
+		m := pb.WROutApplyReq{}
+		if err = r.reflect(data, &m); err != nil {
+			return
+		}
+		if m.Header != nil {
+			m.Header.RequestID = serialNumber
+		} else {
+			err = errors.New("请求信息序列化失败")
+			return
+		}
+		if b, e := proto.Marshal(&m); e != nil {
+			global.M2A_LOG.Error(e.Error(), zap.Error(e))
+			err = errors.New("请求信息序列化失败")
+			return
+		} else {
+			bytes = &b
+		}
 	case global.ReceiptZSOutApplyReq:
 		m := pb.ReceiptZSOutApplyReq{}
 		if err = r.reflect(data, &m); err != nil {

Dosya farkı çok büyük olduğundan ihmal edildi
+ 1170 - 1
res/pb/mtp2.pb.go


+ 110 - 0
res/pb/mtp2.proto

@@ -1037,4 +1037,114 @@ message BSWMSReckonPayRsp {
 		optional uint32 UserID = 4; // 用户ID
 		optional uint64 OrderID = 5; // 单据ID
 			optional string ClientSerialNo = 6; // 客户端流水号
+}
+
+// 仓单贸易浮动价商品配置信息
+message WRGoodsInfo {
+		optional uint32 GoodsID = 1; // 配置商品ID
+		optional string GoodsCode = 2; // 配置商品代码
+		optional double PriceFactor = 3; // 商品价格系数
+		optional double PriceMove = 4; // 商品升贴水值
+		optional double WeightRatio = 5; // 商品重量系数
+}
+// 要素类型明细
+message DGFactoryItems {
+		optional uint64 DGFactoryItemTypeID = 1; // 要素项类型ID
+		optional uint64 DGFactoryItemID = 2; // 预约要素项类型值
+		optional uint32 ItemTypeMode = 3; // 要素项类型模式
+}
+// 持仓单挂牌请求
+message HdWROrderReq {
+	optional MessageHead Header = 1;
+		optional uint64 LadingBillId = 2; // 提单id(wrholdlb的LadingBillId字段),卖的时候填写
+		required string TradeDate = 3; // 交易日
+		optional uint64 SubNum = 4; // 提单子单号(wrholdlb的SubNum字段),卖的时候填写
+		optional uint64 WRFactorTypeId = 5; // 仓单要素ID(wrholdlb的WRFactorTypeId字段),卖的时候填写
+		required uint32 UserID = 6; // 用户ID
+		required uint64 AccountID = 7; // 资金账号
+		optional uint32 IsSpecified = 8; // 是否指定对手
+		repeated uint64 MatchAccIDs = 9; // 仓单贸易对手用户ID集合(指定对手时填写)
+		required uint64 OrderQty = 10; // 委托数量(可挂部分数据量)
+		required uint32 DeliveryGoodsID = 11; // 交割商品商品ID
+		optional uint32 WRPriceType = 12; // 价格方式
+		optional double FixedPrice = 13; // 固定价格
+		repeated WRGoodsInfo WRTradeGoods = 14; // 仓单贸易商品配置集合(浮动价时填写)
+		optional double PriceFactor = 15; // 价格系数(浮动价时填写)-[挂牌]
+		optional double PriceMove = 16; // 升贴水(浮动价时填写)
+		optional uint32 TimevalidType = 17; // 时间有效类型
+		optional string ValidTime = 18; // 有效期限
+		optional double FirstRatio = 19; // 首付比例
+		optional int64 PerformanceTemplateID = 20; // 履约计划模板ID
+		optional uint32 OrderSrc = 21; // 委托来源
+		optional string ClientSerialNo = 22; // 客户端流水号
+		optional string ClientOrderTime = 23; // 客户端委托时间
+		optional uint32 ClientType = 24; // 终端类型
+		optional uint64 OperatorID = 25; // 操作员账号ID
+		optional uint32 BuyOrSell = 26; // 买卖方向
+		optional uint32 PriceDisplayMode = 27; // 浮动价显示方式
+		optional uint32 CanBargain = 28; // 挂牌是否可议价0:不可1:可-摘牌是否议价
+		optional string Attachment1 = 29; // 附件1
+		optional string Attachment2 = 30; // 附件2
+		optional string Remark = 31; // 备注
+		optional uint64 ApplyID = 32; // 申请ID
+		optional uint32 CanPart = 33; // 是否允许部份摘牌0:不允许;1:允许
+		repeated string MatchAccIDsString = 34; // 仓单贸易对手用户ID集合(指定对手时填写)
+		optional string DeliveryMonth = 35; // 交收月
+		optional uint32 HasWr = 36; // 是否有仓单-0:没有仓单1:有仓单
+		optional uint32 WRStandardID = 37; // 现货品种ID
+		repeated DGFactoryItems FactoryItems = 38; // 要素类型明细集合(没有仓单要素ID填写)
+		optional uint64 DelistMinQty = 39; // 起摘数量
+		optional uint32 MarginFlag = 40; // 挂牌是否指定保证金0:否1:是
+		optional uint32 MarginAlgorithm = 41; // 指定保证金方式1:比率2:固定
+		optional double MarginValue = 42; // 指定保证金设置值
+		optional uint32 AllFriendsFlag = 43; // 是否全好友可见0:否1:是
+}
+// 持仓单挂牌应答
+message HdWROrderRsp {
+	optional MessageHead Header = 1; // 消息头
+	optional int32 RetCode = 2; // 返回码
+	optional string RetDesc = 3; // 描述信息
+		optional uint32 UserID = 4; // 用户ID
+		optional uint64 AccountID = 5; // 资金账号
+		optional uint64 WRTradeOrderID = 6; // 仓单贸易委托单ID
+		optional uint64 FreezeQty = 7; // 冻结数量
+		optional string OrderTime = 8; // 接收委托交易的时间
+		optional string ClientSerialNo = 9; // 客户端流水号
+}
+
+// 仓单出库提单明细数据
+message WROutInDetail {
+			optional string LadingBillID = 1; // 提单ID
+			optional uint64 SubNum = 2; // 提单子单号
+			optional uint64 Qty = 3; // 子提单总数量
+			optional uint64 OutQty = 4; // 预约数量
+}
+// 仓单出库申请
+message WROutApplyReq {
+	optional MessageHead Header = 1;
+		optional uint64 ClientSerialID = 2; // 客户端唯一ID
+		optional uint64 WRStandardID = 3; // 仓单标准ID
+		optional uint64 WarehouseID = 4; // 仓库ID
+		optional uint64 UserID = 5; // 申请人ID
+		optional uint64 AccountID = 6; // 申请人账户ID
+		optional string Mobile = 7; // 申请人手机号
+		optional string AppointmentDate = 8; // 预约出库时间(格式:20200101)
+		optional uint32 AppointmentModel = 9; // 预约方式:1-物流,2-自送,3-自提
+			optional uint64 CountryID = 10; // 国家
+			optional uint64 ProvinceID = 11; // 省
+			optional uint64 DistrictID = 12; // 区
+			optional uint64 CityID = 13; // 市
+			optional string Address = 14; // 详细地址
+			optional string ContactName = 15; // 收货人提货人
+			optional string ContactNum = 16; // 收货人提货人手机
+			optional string AppointmentRemark = 17; // 预约备注
+		optional uint64 CreatorID = 18; // 创建人ID
+		repeated WROutInDetail WROutInDetails = 19; // 仓单出库提单明细数据
+}
+// 仓单出库申请响应
+message WROutApplyRsp {
+	optional MessageHead Header = 1; // 消息头
+	optional int32 RetCode = 2; // 返回码
+	optional string RetDesc = 3; // 描述信息
+		optional uint64 ClientSerialID = 4; // 客户端唯一ID
 }

+ 39 - 0
service/account/login.go

@@ -174,3 +174,42 @@ func buildRedisLoginInfo(loginaccount accountModel.Loginaccount, addr string, gr
 
 	return
 }
+
+// RestoreLoginWithToken 通过Token检验恢复登录状态失败
+func RestoreLoginWithToken(loginID int, group int, token string) (err error) {
+	// 从Redis获取登录信息
+	j := utils.NewJWT()
+	loginMap, err := j.GetRedisLogin(loginID, group)
+	if err != nil {
+		global.M2A_LOG.Error("Token检验恢复登录状态失败", zap.Error(err))
+		return
+	}
+	loginId := loginMap["loginId"]
+	userId := loginMap["userId"]
+	sessionId := loginMap["sessionId"]
+	addr := loginMap["addr"]
+	loginLogin := client.LoginRedis{
+		LoginID:   loginId,
+		UserID:    userId,
+		SessionID: sessionId,
+		Token:     token,
+		Group:     strconv.Itoa(group),
+		Addr:      addr,
+	}
+
+	// 记录用户信息
+	mtx.Lock()
+	defer mtx.Unlock()
+	if client.Clients == nil {
+		client.Clients = make(map[int]*client.Client, 0)
+	}
+	s, err := strconv.Atoi(sessionId)
+	if err != nil {
+		global.M2A_LOG.Error("Token检验恢复登录状态失败", zap.Error(err))
+		return
+	}
+	delete(client.Clients, s)
+	client.Clients[s] = &client.Client{LoginRedis: loginLogin}
+
+	return
+}

Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor