Ver Fonte

修改"查询合同申请表单数据"接口BUG

zhou.xiaoning há 5 anos atrás
pai
commit
2e0a3857a5

+ 3 - 3
config/config.xml

@@ -21,7 +21,7 @@
     </DbSetting>
 
     <RedisSetting>
-        <Address   value="192.168.30.182"/>
+        <Address   value="192.168.31.104"/>
         <Port      value="5007"/>
         <Timeout   value="3"/>
         <ConnNum   value="1"/>
@@ -30,12 +30,12 @@
     </RedisSetting>
 
     <MqSetting>
-        <Url       value="amqp://guest:guest@192.168.30.182:5020/test"/>
+        <Url       value="amqp://guest:guest@192.168.31.104:5020/test"/>
         <Exchange  value="entry"/>
     </MqSetting>
 
     <MongoDBSetting>
-        <HostName   value="192.168.30.182"/>
+        <HostName   value="192.168.31.104"/>
         <Port       value="5025"/>
         <DBName     value="HistoryQuote"/>
         <Username   value="quote_test01"/>

+ 33 - 32
controllers/erms3/business.go

@@ -1,8 +1,6 @@
 package erms3
 
 import (
-	"github.com/gin-gonic/gin"
-	"github.com/golang/protobuf/proto"
 	"mtp2_if/global/app"
 	"mtp2_if/global/e"
 	"mtp2_if/logger"
@@ -12,32 +10,35 @@ import (
 	"net/http"
 	"strconv"
 	"strings"
+
+	"github.com/gin-gonic/gin"
+	"github.com/golang/protobuf/proto"
 )
 
 // QueryBusinessInfoReq 查询业务请求.
 type QueryBusinessInfoReq struct {
-	Accountids   string `form:"accountids" binding:"required"`   // 资金账号ID列表,逗号分隔.
-	Status       int32  `form:"status"`                          // 合同状态,0-未结束 1-已结束.
+	Accountids string `form:"accountids" binding:"required"` // 资金账号ID列表,逗号分隔.
+	Status     int32  `form:"status"`                        // 合同状态,0-未结束 1-已结束.
 }
 
 // QueryBusinessInfoRsp 查询业务响应.
 type QueryBusinessInfoRsp struct {
-	BusinessID int64 `json:"businessid"` // 业务ID.
-	Type int32 `json:"type"` // 业务类型,1-期现套利,2-仓单回购,3-现货贸易.
-	GoodsID string `json:"goodsid"` // 商品名称/商品代码.
-	Buyqty string `json:"buyqty"` // 采购量.
-	BuyAmount float64 `json:"buyamount"` // 采购额.
-	Sellqty string `json:"sellqty"` // 销售量.
-	SellAmount float64 `json:"sellamount"` // 销售额.
-	Spotqty string `json:"spotqty"` // 现货量.
+	BusinessID      int64   `json:"businessid"`      // 业务ID.
+	Type            int32   `json:"type"`            // 业务类型,1-期现套利,2-仓单回购,3-现货贸易.
+	GoodsID         string  `json:"goodsid"`         // 商品名称/商品代码.
+	Buyqty          string  `json:"buyqty"`          // 采购量.
+	BuyAmount       float64 `json:"buyamount"`       // 采购额.
+	Sellqty         string  `json:"sellqty"`         // 销售量.
+	SellAmount      float64 `json:"sellamount"`      // 销售额.
+	Spotqty         string  `json:"spotqty"`         // 现货量.
 	SpotMarketValue float64 `json:"spotmarketvalue"` // 现货市值.
-	Hedgingqty string `json:"hedgingqty"` // 套保量.
-	Spotpl float64 `json:"spotpl"` // 浮动权益.
-	Futureqty string `json:"futureqty"` // 期货敞口.
-	Futurepl float64 `json:"futurepl"` // 期货盈亏.
-	Totalqty string `json:"totalqty"` // 总敞口.
-	Totalpl float64 `json:"totalpl"` // 总盈亏.
-	Status int32 `json:"statu"` // 状态,0-未结束 1-已结束.
+	Hedgingqty      string  `json:"hedgingqty"`      // 套保量.
+	Spotpl          float64 `json:"spotpl"`          // 浮动权益.
+	Futureqty       string  `json:"futureqty"`       // 期货敞口.
+	Futurepl        float64 `json:"futurepl"`        // 期货盈亏.
+	Totalqty        string  `json:"totalqty"`        // 总敞口.
+	Totalpl         float64 `json:"totalpl"`         // 总盈亏.
+	Status          int32   `json:"statu"`           // 状态,0-未结束 1-已结束.
 }
 
 // QueryBusinessInfo 查询业务数据
@@ -154,17 +155,17 @@ func QueryBusinessInfo(c *gin.Context) {
 			BusinessID:      asainfo[i].Asapplyid,
 			Type:            1,
 			GoodsID:         strings.Join([]string{goodsinfo.Deliverygoodsname, goodsinfo.Deliverygoodscode}, "/"),
-			Buyqty:          strconv.FormatFloat(detail.Buyqty, 'f', 2, 64)+goodsunit.Enumdicname,
+			Buyqty:          strconv.FormatFloat(detail.Buyqty, 'f', 2, 64) + goodsunit.Enumdicname,
 			BuyAmount:       detail.Buyamount,
-			Sellqty:         strconv.FormatFloat(detail.Sellqty, 'f', 2, 64)+goodsunit.Enumdicname,
+			Sellqty:         strconv.FormatFloat(detail.Sellqty, 'f', 2, 64) + goodsunit.Enumdicname,
 			SellAmount:      detail.Sellamount,
-			Spotqty:         strconv.FormatFloat(asainfo[i].Pricedspotqty, 'f', 2, 64)+goodsunit.Enumdicname,
+			Spotqty:         strconv.FormatFloat(asainfo[i].Pricedspotqty, 'f', 2, 64) + goodsunit.Enumdicname,
 			SpotMarketValue: 0.0,
-			Hedgingqty:      strconv.FormatFloat(asainfo[i].Futureqty, 'f', 2, 64)+goodsunit.Enumdicname,
+			Hedgingqty:      strconv.FormatFloat(asainfo[i].Futureqty, 'f', 2, 64) + goodsunit.Enumdicname,
 			Spotpl:          redisMsg.GetSpotPL(),
-			Futureqty:       strconv.FormatFloat(asainfo[i].Futureqty, 'f', 2, 64)+goodsunit.Enumdicname,
+			Futureqty:       strconv.FormatFloat(asainfo[i].Futureqty, 'f', 2, 64) + goodsunit.Enumdicname,
 			Futurepl:        redisMsg.GetFuturePL(),
-			Totalqty:        strconv.FormatFloat(asainfo[i].Pricedspotqty - asainfo[i].Futureqty, 'f', 2, 64)+goodsunit.Enumdicname,
+			Totalqty:        strconv.FormatFloat(asainfo[i].Pricedspotqty-asainfo[i].Futureqty, 'f', 2, 64) + goodsunit.Enumdicname,
 			Totalpl:         redisMsg.GetTotalPL(),
 			Status:          asainfo[i].Strategystatus,
 		}
@@ -203,11 +204,11 @@ func QueryBusinessInfo(c *gin.Context) {
 			BusinessID:      wrrcontracts[i].Wrrcontractid,
 			Type:            2,
 			GoodsID:         strings.Join([]string{goodsinfo.Deliverygoodsname, goodsinfo.Deliverygoodscode}, "/"),
-			Buyqty:          strconv.FormatFloat(detail.Buyqty, 'f', 2, 64)+goodsunit.Enumdicname,
+			Buyqty:          strconv.FormatFloat(detail.Buyqty, 'f', 2, 64) + goodsunit.Enumdicname,
 			BuyAmount:       detail.Buyamount,
-			Sellqty:         strconv.FormatFloat(detail.Sellqty, 'f', 2, 64)+goodsunit.Enumdicname,
+			Sellqty:         strconv.FormatFloat(detail.Sellqty, 'f', 2, 64) + goodsunit.Enumdicname,
 			SellAmount:      detail.Sellamount,
-			Spotqty:         strconv.FormatFloat(wrrcontracts[i].Contractqty, 'f', 2, 64)+goodsunit.Enumdicname,
+			Spotqty:         strconv.FormatFloat(wrrcontracts[i].Contractqty, 'f', 2, 64) + goodsunit.Enumdicname,
 			SpotMarketValue: 0,
 			Hedgingqty:      "-",
 			Spotpl:          0,
@@ -243,7 +244,7 @@ func QueryBusinessInfo(c *gin.Context) {
 
 		return
 	}
-	
+
 	for i := range spotTradeBiz {
 		goodsinfo := id2goods[int32(spotTradeBiz[i].Deliverygoodsid)]
 		goodsunit := id2enum[uint64(goodsinfo.Goodsunitid)]
@@ -252,11 +253,11 @@ func QueryBusinessInfo(c *gin.Context) {
 			BusinessID:      spotTradeBiz[i].Spottradeid,
 			Type:            3,
 			GoodsID:         strings.Join([]string{goodsinfo.Deliverygoodsname, goodsinfo.Deliverygoodscode}, "/"),
-			Buyqty:          strconv.FormatFloat(detail.Buyqty, 'f', 2, 64)+goodsunit.Enumdicname,
+			Buyqty:          strconv.FormatFloat(detail.Buyqty, 'f', 2, 64) + goodsunit.Enumdicname,
 			BuyAmount:       detail.Buyamount,
-			Sellqty:         strconv.FormatFloat(detail.Sellqty, 'f', 2, 64)+goodsunit.Enumdicname,
+			Sellqty:         strconv.FormatFloat(detail.Sellqty, 'f', 2, 64) + goodsunit.Enumdicname,
 			SellAmount:      detail.Sellamount,
-			Spotqty:         strconv.FormatFloat(spotTradeBiz[i].Buyqty+spotTradeBiz[i].Sellqty, 'f', 2, 64)+goodsunit.Enumdicname,
+			Spotqty:         strconv.FormatFloat(spotTradeBiz[i].Buyqty+spotTradeBiz[i].Sellqty, 'f', 2, 64) + goodsunit.Enumdicname,
 			SpotMarketValue: 0,
 			Hedgingqty:      "-",
 			Spotpl:          0,

+ 6 - 6
controllers/erms3/spotContract.go

@@ -275,7 +275,7 @@ func BuildDetailJSON(details []SoptContractDetail) (string, error) {
 
 // QuerySpotContractAppleFormReq 查询合同申请表单数据请求参数
 type QuerySpotContractAppleFormReq struct {
-	UserID int `form:"userID" binding:"required"`
+	LoginID int `form:"loginID" binding:"required"`
 }
 
 // CustomerInfo 申请单账号信息
@@ -299,7 +299,7 @@ type QuerySpotContractAppleFormRsp struct {
 // @Summary 查询合同申请表单数据
 // @Produce json
 // @Security ApiKeyAuth
-// @Param userID query int true "用户ID"
+// @Param loginID query int true "登录账号"
 // @Success 200 {object} QuerySpotContractAppleFormRsp
 // @Failure 500 {object} app.Response
 // @Router /Erms3/QuerySpotContractAppleForm [get]
@@ -318,7 +318,7 @@ func QuerySpotContractAppleForm(c *gin.Context) {
 
 	rsp := QuerySpotContractAppleFormRsp{}
 	// 获取我方用户信息
-	ourUser, err := models.GetUserInfo(req.UserID)
+	ourUser, err := models.GetUserInfoByLoginID(req.LoginID)
 	if err != nil {
 		// 查询失败
 		logger.GetLogger().Errorf("QuerySpotContractAppleForm failed: %s", err.Error())
@@ -336,7 +336,7 @@ func QuerySpotContractAppleForm(c *gin.Context) {
 			}
 		}
 	}
-	taAccounts, err := models.GetTaAccountsByType(req.UserID, 3) // 获取内部资金账户,现货都使用内部资金账户
+	taAccounts, err := models.GetTaAccountsByLoginID(req.LoginID, 2) // 获取内部资金账户,现货都使用内部资金账户
 	if err != nil {
 		// 查询失败
 		logger.GetLogger().Errorf("QuerySpotContractAppleForm failed: %s", err.Error())
@@ -359,7 +359,7 @@ func QuerySpotContractAppleForm(c *gin.Context) {
 	rsp.OppositeUsers = make([]CustomerInfo, 0)
 	for _, v := range oppositeUsers {
 		// 把自己过滤掉
-		if int(v.Userid) == req.UserID {
+		if v.Userid == rsp.OurUser.Userid {
 			continue
 		}
 
@@ -375,7 +375,7 @@ func QuerySpotContractAppleForm(c *gin.Context) {
 			}
 		}
 		// 获取客户的资金账户列表
-		opposTaAccounts, err := models.GetTaAccountsByType(int(v.Userid), 3) // 获取内部资金账户,现货都使用内部资金账户
+		opposTaAccounts, err := models.GetTaAccountsByType(int(v.Userid), 2) // 获取内部资金账户,现货都使用内部资金账户
 		if err != nil {
 			// 查询失败
 			logger.GetLogger().Errorf("QuerySpotContractAppleForm failed: %s", err.Error())

+ 2 - 2
docs/docs.go

@@ -993,8 +993,8 @@ var doc = `{
                 "parameters": [
                     {
                         "type": "integer",
-                        "description": "用户ID",
-                        "name": "userID",
+                        "description": "登录账号",
+                        "name": "loginID",
                         "in": "query",
                         "required": true
                     }

+ 2 - 2
docs/swagger.json

@@ -977,8 +977,8 @@
                 "parameters": [
                     {
                         "type": "integer",
-                        "description": "用户ID",
-                        "name": "userID",
+                        "description": "登录账号",
+                        "name": "loginID",
                         "in": "query",
                         "required": true
                     }

+ 2 - 2
docs/swagger.yaml

@@ -5217,9 +5217,9 @@ paths:
   /Erms3/QuerySpotContractAppleForm:
     get:
       parameters:
-      - description: 用户ID
+      - description: 登录账号
         in: query
-        name: userID
+        name: loginID
         required: true
         type: integer
       produces:

+ 67 - 1
models/account.go

@@ -513,6 +513,20 @@ func GetUserInfo(userID int) (*Userinfo, error) {
 	return &userInfo, nil
 }
 
+// GetUserInfoByLoginID 通过登录账号获取用户信息的方法
+func GetUserInfoByLoginID(loginID int) (*Userinfo, error) {
+	engine := db.GetEngine()
+
+	var userInfo Userinfo
+	_, err := engine.Table("USERINFO U").Join("INNER", "LOGINACCOUNT L", "L.USERID = U.USERID").Where("L.LOGINID = ?", loginID).Get(&userInfo)
+	if err != nil {
+		// 查询失败
+		return nil, err
+	}
+
+	return &userInfo, nil
+}
+
 // GetUserInfoByIDS 批量获取用户信息.
 func GetUserInfoByIDS(userids []int64) ([]Userinfo, error) {
 	engine := db.GetEngine()
@@ -626,9 +640,61 @@ func GetTaAccountsByType(userID, taAccountType int) ([]Taaccount, error) {
 	engine := db.GetEngine()
 
 	taAccounts := make([]Taaccount, 0)
-	if err := engine.Where("RELATEDUSERID = ?", userID).Find(&taAccounts); err != nil {
+
+	session := engine.Where("RELATEDUSERID = ?", userID)
+	if taAccountType != 0 {
+		session = session.And("TAACCOUNTTYPE = ?", taAccountType)
+	}
+	if err := session.Find(&taAccounts); err != nil {
+		return nil, err
+	}
+
+	return taAccounts, nil
+}
+
+// GetTaAccountsByLoginID 通过登录账号获取对应资金账户列表的方法,一般用于获取自己的资金账号时使用
+// 输入 loginID int 登录账号
+// 输入 taAccountType int 账号类型 - 1:外部账号 2:内部账号 3:内部做市自营账号 4:内部做市接单账号
+func GetTaAccountsByLoginID(loginID, taAccountType int) ([]Taaccount, error) {
+	engine := db.GetEngine()
+
+	taAccounts := make([]Taaccount, 0)
+
+	// 注意:获取自身的资金账号列表,先要从LoginTAAccount表中判断是否有关联关系,如没配置关系则直接从TaAccount表中获取
+	loginTaAccounts := make([]Logintaaccount, 0)
+	if err := engine.Where("LOGINID = ?", loginID).Find(&loginTaAccounts); err != nil {
 		return nil, err
 	}
+	if len(loginTaAccounts) > 0 {
+		// 获取资金账号ID列表
+		accountIDs := ""
+		for _, v := range loginTaAccounts {
+			if len(accountIDs) == 0 {
+				accountIDs = strconv.Itoa(int(v.Accountid))
+			} else {
+				accountIDs += "," + strconv.Itoa(int(v.Accountid))
+			}
+		}
+		// 获取资金账号列表
+		session := engine.Where(fmt.Sprintf("ACCOUNTID in (%s)", accountIDs))
+		if taAccountType != 0 {
+			session = session.And("TAACCOUNTTYPE = ?", taAccountType)
+		}
+		if err := session.Find(&taAccounts); err != nil {
+			return nil, err
+		}
+	} else {
+		// 直接从TaAccount表中获取
+		session := engine.Table("TAACCOUNT").
+			Join("INNER", "LOGINACCOUNT L", "L.USERID = TAACCOUNT.RELATEDUSERID").
+			Where("L.LOGINID = ?", loginID)
+		if taAccountType != 0 {
+			session = session.And("TAACCOUNT.TAACCOUNTTYPE = ?", taAccountType)
+		}
+		if err := session.Find(&taAccounts); err != nil {
+			return nil, err
+		}
+	}
 
 	return taAccounts, nil
 }