zhou.yingan il y a 5 ans
Parent
commit
4118d72961
6 fichiers modifiés avec 305 ajouts et 233 suppressions
  1. 48 81
      controllers/erms3/business.go
  2. 27 34
      docs/docs.go
  3. 27 34
      docs/swagger.json
  4. 20 26
      docs/swagger.yaml
  5. 183 17
      models/erms2.go
  6. 0 41
      models/erms3.go

+ 48 - 81
controllers/erms3/business.go

@@ -64,18 +64,6 @@ func QueryBusinessInfo(c *gin.Context) {
 		return
 	}
 
-	strids := strings.Split(strings.TrimSpace(req.Accountids), ",")
-	accountids := make([]int64, len(strids))
-	for i := range strids {
-		accountids[i], err = strconv.ParseInt(strids[i], 10, 64)
-		if err != nil {
-			logger.GetLogger().Errorf("ParseInt failed: %s", err.Error())
-			appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
-
-			return
-		}
-	}
-
 	// 获取商品信息.
 	goods, err := models.GetDeliverGoods()
 	if err != nil {
@@ -106,27 +94,11 @@ func QueryBusinessInfo(c *gin.Context) {
 		id2enum[enuminfo[i].Enumitemname] = enuminfo[i]
 	}
 
-	// 查询期现套利业务,首先查询业务ID集合.
-	applyid, err := models.QueryASApplyIDSByAccountID(accountids)
-	if err != nil {
-		logger.GetLogger().Errorf("query applyid failed: %s", err.Error())
-		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
-
-		return
-	}
-
-	// 查询业务对应单据详细信息.
-	tradeinfo, err := models.QueryBizTradeInfo(applyid)
-	if err != nil {
-		logger.GetLogger().Errorf("query biztradedetail failed: %s", err.Error())
-		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
-
-		return
-	}
-
-	asainfo, err := models.QueryArbitragestrategy(applyid, req.Status)
+	// 查询期现套利业务.
+	var asa models.Erms2Arbitragestrategy
+	asainfo, err := asa.GetByAccountIDSAndStatus(req.Accountids, req.Status)
 	if err != nil {
-		logger.GetLogger().Errorf("query arbitragestrategy failed: %s", err.Error())
+		logger.GetLogger().Errorf("query asainfo failed: %s", err.Error())
 		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
 
 		return
@@ -136,7 +108,7 @@ func QueryBusinessInfo(c *gin.Context) {
 	preKey := "Erms2_ArbitrageStrategy:"
 	rsp := make([]QueryBusinessInfoRsp, 0, len(asainfo))
 	for i := range asainfo {
-		key := preKey + strconv.FormatInt(asainfo[i].Asapplyid, 10)
+		key := preKey + asainfo[i].Asapplyid
 		redisMsg := pb.Erms2ArbitrageStrategy{}
 		redisRsp, err := redisClient.Get(key).Result()
 		if err != nil {
@@ -150,15 +122,22 @@ func QueryBusinessInfo(c *gin.Context) {
 
 		goodsinfo := id2goods[int32(asainfo[i].Deliverygoodsid)]
 		goodsunit := id2enum[int64(goodsinfo.Goodsunitid)]
-		detail := tradeinfo[asainfo[i].Asapplyid]
+		businessid, err := strconv.ParseInt(asainfo[i].Asapplyid, 10, 64)
+		if err != nil {
+			logger.GetLogger().Errorf("parse string[%s] to int failed: %s", asainfo[i].Asapplyid, err.Error())
+			appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+
+			return
+		}
+
 		business := QueryBusinessInfoRsp{
-			BusinessID:      asainfo[i].Asapplyid,
+			BusinessID:      businessid,
 			Type:            1,
 			GoodsID:         strings.Join([]string{goodsinfo.Deliverygoodsname, goodsinfo.Deliverygoodscode}, "/"),
-			Buyqty:          strconv.FormatFloat(detail.Buyqty, 'f', 2, 64) + goodsunit.Enumdicname,
-			BuyAmount:       detail.Buyamount,
-			Sellqty:         strconv.FormatFloat(detail.Sellqty, 'f', 2, 64) + goodsunit.Enumdicname,
-			SellAmount:      detail.Sellamount,
+			Buyqty:          strconv.FormatFloat(asainfo[i].Buyqty, 'f', 2, 64) + goodsunit.Enumdicname,
+			BuyAmount:       asainfo[i].Buyamount,
+			Sellqty:         strconv.FormatFloat(asainfo[i].Sellqty, 'f', 2, 64) + goodsunit.Enumdicname,
+			SellAmount:      asainfo[i].Sellamount,
 			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,
@@ -174,7 +153,8 @@ func QueryBusinessInfo(c *gin.Context) {
 	}
 
 	// 查询仓单回购业务.
-	wrrcontracts, err := models.QueryWRRContract(accountids, req.Status)
+	var wr models.Erms2Wrrcontract
+	wrrcontracts, err := wr.GetByAccountIDSAndStatus(req.Accountids, req.Status)
 	if err != nil {
 		logger.GetLogger().Errorf("query wrrcontract failed: %s", err.Error())
 		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
@@ -182,32 +162,25 @@ func QueryBusinessInfo(c *gin.Context) {
 		return
 	}
 
-	wrrids := make([]int64, 0, len(wrrcontracts))
-	for i := range wrrcontracts {
-		wrrids = append(wrrids, wrrcontracts[i].Wrrcontractid)
-	}
-
-	// 查询业务对应单据详细信息.
-	wrtradeinfo, err := models.QueryBizTradeInfo(wrrids)
-	if err != nil {
-		logger.GetLogger().Errorf("query biztradedetail failed: %s", err.Error())
-		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
-
-		return
-	}
-
 	for i := range wrrcontracts {
 		goodsinfo := id2goods[int32(wrrcontracts[i].Deliverygoodsid)]
 		goodsunit := id2enum[int64(goodsinfo.Goodsunitid)]
-		detail := wrtradeinfo[wrrcontracts[i].Wrrcontractid]
+		businessid, err := strconv.ParseInt(wrrcontracts[i].Wrrcontractid, 10, 64)
+		if err != nil {
+			logger.GetLogger().Errorf("parse string[%s] to int failed: %s", asainfo[i].Asapplyid, err.Error())
+			appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+
+			return
+		}
+
 		business := QueryBusinessInfoRsp{
-			BusinessID:      wrrcontracts[i].Wrrcontractid,
+			BusinessID:      businessid,
 			Type:            2,
 			GoodsID:         strings.Join([]string{goodsinfo.Deliverygoodsname, goodsinfo.Deliverygoodscode}, "/"),
-			Buyqty:          strconv.FormatFloat(detail.Buyqty, 'f', 2, 64) + goodsunit.Enumdicname,
-			BuyAmount:       detail.Buyamount,
-			Sellqty:         strconv.FormatFloat(detail.Sellqty, 'f', 2, 64) + goodsunit.Enumdicname,
-			SellAmount:      detail.Sellamount,
+			Buyqty:          strconv.FormatFloat(wrrcontracts[i].Buyqty, 'f', 2, 64) + goodsunit.Enumdicname,
+			BuyAmount:       wrrcontracts[i].Buyamount,
+			Sellqty:         strconv.FormatFloat(wrrcontracts[i].Sellqty, 'f', 2, 64) + goodsunit.Enumdicname,
+			SellAmount:      wrrcontracts[i].Sellamount,
 			Spotqty:         strconv.FormatFloat(wrrcontracts[i].Contractqty, 'f', 2, 64) + goodsunit.Enumdicname,
 			SpotMarketValue: 0,
 			Hedgingqty:      "-",
@@ -223,7 +196,8 @@ func QueryBusinessInfo(c *gin.Context) {
 	}
 
 	// 查询现货贸易业务.
-	spotTradeBiz, err := models.QuerySpotTradeBiz(accountids, req.Status)
+	var sbt models.Erms2Spottradebiz
+	spotTradeBiz, err := sbt.GetByAccountIDSAndStatus(req.Accountids, req.Status)
 	if err != nil {
 		logger.GetLogger().Errorf("query spottradebiz failed: %s", err.Error())
 		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
@@ -231,32 +205,25 @@ func QueryBusinessInfo(c *gin.Context) {
 		return
 	}
 
-	spotids := make([]int64, 0, len(spotTradeBiz))
-	for i := range spotTradeBiz {
-		spotids = append(spotids, spotTradeBiz[i].Spottradeid)
-	}
-
-	// 查询业务对应单据详细信息.
-	spottradeinfo, err := models.QueryBizTradeInfo(spotids)
-	if err != nil {
-		logger.GetLogger().Errorf("query spottradedetail failed: %s", err.Error())
-		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
-
-		return
-	}
-
 	for i := range spotTradeBiz {
 		goodsinfo := id2goods[int32(spotTradeBiz[i].Deliverygoodsid)]
 		goodsunit := id2enum[int64(goodsinfo.Goodsunitid)]
-		detail := spottradeinfo[spotTradeBiz[i].Spottradeid]
+		businessid, err := strconv.ParseInt(spotTradeBiz[i].Spottradeid, 10, 64)
+		if err != nil {
+			logger.GetLogger().Errorf("parse string[%s] to int failed: %s", asainfo[i].Asapplyid, err.Error())
+			appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+
+			return
+		}
+
 		business := QueryBusinessInfoRsp{
-			BusinessID:      spotTradeBiz[i].Spottradeid,
+			BusinessID:      businessid,
 			Type:            3,
 			GoodsID:         strings.Join([]string{goodsinfo.Deliverygoodsname, goodsinfo.Deliverygoodscode}, "/"),
-			Buyqty:          strconv.FormatFloat(detail.Buyqty, 'f', 2, 64) + goodsunit.Enumdicname,
-			BuyAmount:       detail.Buyamount,
-			Sellqty:         strconv.FormatFloat(detail.Sellqty, 'f', 2, 64) + goodsunit.Enumdicname,
-			SellAmount:      detail.Sellamount,
+			Buyqty:          strconv.FormatFloat(spotTradeBiz[i].TradeBuyqty, 'f', 2, 64) + goodsunit.Enumdicname,
+			BuyAmount:       spotTradeBiz[i].TradeBuyamount,
+			Sellqty:         strconv.FormatFloat(spotTradeBiz[i].TradeSellqty, 'f', 2, 64) + goodsunit.Enumdicname,
+			SellAmount:      spotTradeBiz[i].TradeSellamount,
 			Spotqty:         strconv.FormatFloat(spotTradeBiz[i].Buyqty+spotTradeBiz[i].Sellqty, 'f', 2, 64) + goodsunit.Enumdicname,
 			SpotMarketValue: 0,
 			Hedgingqty:      "-",

+ 27 - 34
docs/docs.go

@@ -20,7 +20,6 @@ var doc = `{
         "title": "{{.Title}}",
         "termsOfService": "http://muchinfo.cn",
         "contact": {},
-        "license": {},
         "version": "{{.Version}}"
     },
     "host": "{{.Host}}",
@@ -3332,7 +3331,6 @@ var doc = `{
                 },
                 "province": {
                     "description": "省",
-                    "type": "object",
                     "$ref": "#/definitions/models.Division"
                 }
             }
@@ -5302,7 +5300,33 @@ var doc = `{
             }
         },
         "erms3.QryPendingBizRsp": {
-            "$ref": "#/definitions/models.PendingAuditBizModel"
+            "type": "object",
+            "properties": {
+                "accountid": {
+                    "description": "现货账户",
+                    "type": "string"
+                },
+                "areaname": {
+                    "description": "所属部门",
+                    "type": "string"
+                },
+                "bizid": {
+                    "description": "业务ID",
+                    "type": "string"
+                },
+                "bizname": {
+                    "description": "业务名称",
+                    "type": "string"
+                },
+                "status": {
+                    "description": "状态,0:待审核 1:审核通过 2:审核中 3:审核失败 4已撤销 5:审核拒绝",
+                    "type": "integer"
+                },
+                "type": {
+                    "description": "业务类型,1-期现套利,2-仓单回购,3-现货贸易",
+                    "type": "integer"
+                }
+            }
         },
         "erms3.QueryBusinessInfoRsp": {
             "type": "object",
@@ -5392,7 +5416,6 @@ var doc = `{
                 },
                 "ouruser": {
                     "description": "我方账号",
-                    "type": "object",
                     "$ref": "#/definitions/erms3.CustomerInfo"
                 },
                 "warehouseinfos": {
@@ -5720,7 +5743,6 @@ var doc = `{
                 },
                 "province": {
                     "description": "省",
-                    "type": "object",
                     "$ref": "#/definitions/models.Division"
                 }
             }
@@ -6867,35 +6889,6 @@ var doc = `{
                 }
             }
         },
-        "models.PendingAuditBizModel": {
-            "type": "object",
-            "properties": {
-                "accountid": {
-                    "description": "现货账户",
-                    "type": "string"
-                },
-                "areaname": {
-                    "description": "所属部门",
-                    "type": "string"
-                },
-                "businessid": {
-                    "description": "业务ID",
-                    "type": "string"
-                },
-                "businessname": {
-                    "description": "业务名称",
-                    "type": "string"
-                },
-                "statu": {
-                    "description": "状态,0:待审核 1:审核通过 2:审核中 3:审核失败 4已撤销 5:审核拒绝",
-                    "type": "integer"
-                },
-                "type": {
-                    "description": "业务类型,1-期现套利,2-仓单回购,3-现货贸易",
-                    "type": "integer"
-                }
-            }
-        },
         "models.QuotePrimaryMenu": {
             "type": "object",
             "properties": {

+ 27 - 34
docs/swagger.json

@@ -5,7 +5,6 @@
         "title": "MTP2.0 查询服务 API",
         "termsOfService": "http://muchinfo.cn",
         "contact": {},
-        "license": {},
         "version": "1.0"
     },
     "basePath": "/api",
@@ -3316,7 +3315,6 @@
                 },
                 "province": {
                     "description": "省",
-                    "type": "object",
                     "$ref": "#/definitions/models.Division"
                 }
             }
@@ -5286,7 +5284,33 @@
             }
         },
         "erms3.QryPendingBizRsp": {
-            "$ref": "#/definitions/models.PendingAuditBizModel"
+            "type": "object",
+            "properties": {
+                "accountid": {
+                    "description": "现货账户",
+                    "type": "string"
+                },
+                "areaname": {
+                    "description": "所属部门",
+                    "type": "string"
+                },
+                "bizid": {
+                    "description": "业务ID",
+                    "type": "string"
+                },
+                "bizname": {
+                    "description": "业务名称",
+                    "type": "string"
+                },
+                "status": {
+                    "description": "状态,0:待审核 1:审核通过 2:审核中 3:审核失败 4已撤销 5:审核拒绝",
+                    "type": "integer"
+                },
+                "type": {
+                    "description": "业务类型,1-期现套利,2-仓单回购,3-现货贸易",
+                    "type": "integer"
+                }
+            }
         },
         "erms3.QueryBusinessInfoRsp": {
             "type": "object",
@@ -5376,7 +5400,6 @@
                 },
                 "ouruser": {
                     "description": "我方账号",
-                    "type": "object",
                     "$ref": "#/definitions/erms3.CustomerInfo"
                 },
                 "warehouseinfos": {
@@ -5704,7 +5727,6 @@
                 },
                 "province": {
                     "description": "省",
-                    "type": "object",
                     "$ref": "#/definitions/models.Division"
                 }
             }
@@ -6851,35 +6873,6 @@
                 }
             }
         },
-        "models.PendingAuditBizModel": {
-            "type": "object",
-            "properties": {
-                "accountid": {
-                    "description": "现货账户",
-                    "type": "string"
-                },
-                "areaname": {
-                    "description": "所属部门",
-                    "type": "string"
-                },
-                "businessid": {
-                    "description": "业务ID",
-                    "type": "string"
-                },
-                "businessname": {
-                    "description": "业务名称",
-                    "type": "string"
-                },
-                "statu": {
-                    "description": "状态,0:待审核 1:审核通过 2:审核中 3:审核失败 4已撤销 5:审核拒绝",
-                    "type": "integer"
-                },
-                "type": {
-                    "description": "业务类型,1-期现套利,2-仓单回购,3-现货贸易",
-                    "type": "integer"
-                }
-            }
-        },
         "models.QuotePrimaryMenu": {
             "type": "object",
             "properties": {

+ 20 - 26
docs/swagger.yaml

@@ -87,7 +87,6 @@ definitions:
       province:
         $ref: '#/definitions/models.Division'
         description: 省
-        type: object
     type: object
   common.QueryTableDefineRsp:
     properties:
@@ -1562,7 +1561,26 @@ definitions:
     - spotcontractid
     type: object
   erms3.QryPendingBizRsp:
-    $ref: '#/definitions/models.PendingAuditBizModel'
+    properties:
+      accountid:
+        description: 现货账户
+        type: string
+      areaname:
+        description: 所属部门
+        type: string
+      bizid:
+        description: 业务ID
+        type: string
+      bizname:
+        description: 业务名称
+        type: string
+      status:
+        description: 状态,0:待审核 1:审核通过 2:审核中 3:审核失败 4已撤销 5:审核拒绝
+        type: integer
+      type:
+        description: 业务类型,1-期现套利,2-仓单回购,3-现货贸易
+        type: integer
+    type: object
   erms3.QueryBusinessInfoRsp:
     properties:
       businessid:
@@ -1629,7 +1647,6 @@ definitions:
       ouruser:
         $ref: '#/definitions/erms3.CustomerInfo'
         description: 我方账号
-        type: object
       warehouseinfos:
         description: 仓库信息列表
         items:
@@ -1869,7 +1886,6 @@ definitions:
       province:
         $ref: '#/definitions/models.Division'
         description: 省
-        type: object
     type: object
   models.Division:
     properties:
@@ -2734,27 +2750,6 @@ definitions:
         description: 菜单标题
         type: string
     type: object
-  models.PendingAuditBizModel:
-    properties:
-      accountid:
-        description: 现货账户
-        type: string
-      areaname:
-        description: 所属部门
-        type: string
-      businessid:
-        description: 业务ID
-        type: string
-      businessname:
-        description: 业务名称
-        type: string
-      statu:
-        description: 状态,0:待审核 1:审核通过 2:审核中 3:审核失败 4已撤销 5:审核拒绝
-        type: integer
-      type:
-        description: 业务类型,1-期现套利,2-仓单回购,3-现货贸易
-        type: integer
-    type: object
   models.QuotePrimaryMenu:
     properties:
       Index:
@@ -4675,7 +4670,6 @@ definitions:
 info:
   contact: {}
   description: 新的查询服务,替代原通用查询服务。
-  license: {}
   termsOfService: http://muchinfo.cn
   title: MTP2.0 查询服务 API
   version: "1.0"

+ 183 - 17
models/erms2.go

@@ -2,6 +2,7 @@
 package models
 
 import (
+	"fmt"
 	"mtp2_if/db"
 	"time"
 )
@@ -87,7 +88,7 @@ func (Erms2astradedetails) TableName() string {
 
 // Erms2Wrrcontract 仓单回购业务表
 type Erms2Wrrcontract struct {
-	Wrrcontractid         int64     `json:"wrrcontractid" xorm:"WRRCONTRACTID"`                 // 回购业务ID(343+Unix秒时间戳(10位)+xxxxxx)
+	Wrrcontractid         string    `json:"wrrcontractid" xorm:"WRRCONTRACTID"`                 // 回购业务ID(343+Unix秒时间戳(10位)+xxxxxx)
 	Wrrcontractno         string    `json:"wrrcontractno" xorm:"WRRCONTRACTNO"`                 // 回购业务编号
 	Wrrcontractname       string    `json:"wrrcontractname" xorm:"WRRCONTRACTNAME"`             // 回购名称
 	Areauserid            int64     `json:"areauserid" xorm:"AREAUSERID"`                       // 所属机构
@@ -132,9 +133,21 @@ func (Erms2Wrrcontract) TableName() string {
 	return "ERMS2_WRRCONTRACT"
 }
 
+// Erms2WrrcontractInfo 仓单回购业务详细信息.
+type Erms2WrrcontractInfo struct {
+	Wrrcontractid   string  `json:"wrrcontractid" xorm:"WRRCONTRACTID"`     // 回购业务ID(343+Unix秒时间戳(10位)+xxxxxx)
+	Deliverygoodsid int64   `json:"deliverygoodsid" xorm:"DELIVERYGOODSID"` // 现货品种ID
+	Contractqty     float64 `json:"contractqty" xorm:"CONTRACTQTY"`         // 合同数量
+	Contractstatus  int32   `json:"contractstatus" xorm:"CONTRACTSTATUS"`   // 合同状态 -  0:未结束 1:已结束
+	Buyqty          float64 `json:"buyqty" xorm:"BUYQTY"`                   // 采购量.
+	Buyamount       float64 `json:"buyamount" xorm:"BUYAMOUNT"`             // 采购额.
+	Sellqty         float64 `json:"sellqty" xorm:"SELLQTY"`                 // 销售量.
+	Sellamount      float64 `json:"sellamount" xorm:"SELLAMOUNT"`           // 销售额.
+}
+
 // Erms2Spottradebiz 现货贸易业务表
 type Erms2Spottradebiz struct {
-	Spottradeid        int64   `json:"spottradeid" xorm:"SPOTTRADEID"`               // 业务ID(341+Unix秒时间戳(10位)+xxxxxx)
+	Spottradeid        string  `json:"spottradeid" xorm:"SPOTTRADEID"`               // 业务ID(341+Unix秒时间戳(10位)+xxxxxx)
 	Spottradeno        string  `json:"spottradeno" xorm:"SPOTTRADENO"`               // 业务编号
 	Spottradename      string  `json:"spottradename" xorm:"SPOTTRADENAME"`           // 业务名称
 	Areauserid         int64   `json:"areauserid" xorm:"AREAUSERID"`                 // 所属机构
@@ -164,9 +177,22 @@ func (Erms2Spottradebiz) TableName() string {
 	return "ERMS2_SPOTTRADEBIZ"
 }
 
+// Erms2SpottradebizInfo 现货贸易详细信息.
+type Erms2SpottradebizInfo struct {
+	Spottradeid     string  `json:"spottradeid" xorm:"SPOTTRADEID"`         // 业务ID(341+Unix秒时间戳(10位)+xxxxxx)
+	Deliverygoodsid int64   `json:"deliverygoodsid" xorm:"DELIVERYGOODSID"` // 现货品种ID
+	Buyqty          float64 `json:"buyqty" xorm:"BUYQTY"`                   // 采购总量
+	Sellqty         float64 `json:"sellqty" xorm:"SELLQTY"`                 // 销售总量
+	Closestatus     int32   `json:"closestatus" xorm:"CLOSESTATUS"`         // 完结状态 - 0:未完结 1:已完结
+	TradeBuyqty     float64 `json:"tradebuyqty" xorm:"TRADEBUYQTY"`         // 采购量.
+	TradeBuyamount  float64 `json:"tradebuyamount" xorm:"TRADEBUYAMOUNT"`   // 采购额.
+	TradeSellqty    float64 `json:"tradesellqty" xorm:"TRADESELLQTY"`       // 销售量.
+	TradeSellamount float64 `json:"tradesellamount" xorm:"TRADESELLAMOUNT"` // 销售额.
+}
+
 // Erms2Arbitragestrategy 期现套利业务表
 type Erms2Arbitragestrategy struct {
-	Asapplyid          int64     `json:"asapplyid" xorm:"ASAPPLYID"`                   // 策略申请ID(342+Unix秒时间戳(10位)+xxxxxx)
+	Asapplyid          string    `json:"asapplyid" xorm:"ASAPPLYID"`                   // 策略申请ID(342+Unix秒时间戳(10位)+xxxxxx)
 	Asno               string    `json:"asno" xorm:"ASNO"`                             // 策略编号
 	Asname             string    `json:"asname" xorm:"ASNAME"`                         // 策略名称
 	Biztype            int32     `json:"biztype" xorm:"BIZTYPE"`                       // 业务类型 - 1:正向套利 -1:反向套利
@@ -213,6 +239,19 @@ func (Erms2Arbitragestrategy) TableName() string {
 	return "ERMS2_ARBITRAGESTRATEGY"
 }
 
+// 期现套利详细信息.
+type Erms2AribitrageInfo struct {
+	Asapplyid       string  `json:"asapplyid" xorm:"ASAPPLYID"`             // 策略申请ID(342+Unix秒时间戳(10位)+xxxxxx)
+	Deliverygoodsid int64   `json:"deliverygoodsid" xorm:"DELIVERYGOODSID"` // 现货品种ID
+	Pricedspotqty   float64 `json:"pricedspotqty" xorm:"PRICEDSPOTQTY"`     // 已定价现货数量
+	Futureqty       float64 `json:"futureqty" xorm:"FUTUREQTY"`             // 期货持仓数量
+	Strategystatus  int32   `json:"strategystatus" xorm:"STRATEGYSTATUS"`   // 策略状态 - 0:未结束 1:已结束
+	Buyqty          float64 `json:"buyqty" xorm:"BUYQTY"`                   // 采购量.
+	Buyamount       float64 `json:"buyamount" xorm:"BUYAMOUNT"`             // 采购额.
+	Sellqty         float64 `json:"sellqty" xorm:"SELLQTY"`                 // 销售量.
+	Sellamount      float64 `json:"sellamount" xorm:"SELLAMOUNT"`           // 销售额.
+}
+
 // Erms2spotcontract 现货合同表
 type Erms2spotcontract struct {
 	Spotcontractid     int64     `json:"spotcontractid"  xorm:"'SPOTCONTRACTID'" binding:"required"` // 现货合同ID(701+Unix秒时间戳(10位)+xxxxxx)
@@ -332,29 +371,156 @@ func QueryASApplyIDSByAccountID(accountids []int64) ([]int64, error) {
 	return applyids, nil
 }
 
-// QueryArbitragestrategy 根据业务ID和状态查询.
-func QueryArbitragestrategy(applyid []int64, status int32) ([]Erms2Arbitragestrategy, error) {
+// buildSQL 构建sql.
+func (asa Erms2Arbitragestrategy) buildSQL(accountids string, status int32) string {
+	statement := `select to_char(asa.asapplyid) asapplyid,
+       asa.deliverygoodsid, asa.pricedspotqty, asa.futureqty, asa.strategystatus,
+       d.buyqty,
+       d.buyamount,
+       d.sellqty,
+       d.sellamount
+  from erms2_arbitragestrategy asa
+  left join (select bt.relatedbizid,
+                    sum(case bt.contracttype
+                          when 1 then
+                           bt.relatedqty - bt.cancelledqty
+                          else
+                           0
+                        end) buyqty,
+                    sum(case bt.contracttype
+                          when 1 then
+                           bt.relatedamount - bt.cancelledamount
+                          else
+                           0
+                        end) buyamount,
+                    sum(case bt.contracttype
+                          when -1 then
+                           bt.relatedqty - bt.cancelledqty
+                          else
+                           0
+                        end) sellqty,
+                    sum(case bt.contracttype
+                          when -1 then
+                           bt.relatedamount - bt.cancelledamount
+                          else
+                           0
+                        end) sellamount
+               from erms3_biztradedetail bt
+               left join erms2_asaccount ea
+                 on bt.relatedbizid = ea.asapplyid
+              where ea.accountid in (%v)
+              group by bt.relatedbizid) d
+    on asa.asapplyid = d.relatedbizid
+ where asa.strategystatus = %v`
+	return fmt.Sprintf(statement, accountids, status)
+}
+
+// GetByAccountIDSAndStatus 根据账号和状态获取期现套利详细信息.
+func (asa Erms2Arbitragestrategy) GetByAccountIDSAndStatus(accountids string, status int32) ([]Erms2AribitrageInfo, error) {
 	engine := db.GetEngine()
-	data := make([]Erms2Arbitragestrategy, 0)
-	err := engine.In("ASAPPLYID", applyid).Where("STRATEGYSTATUS = ?", status).Find(&data)
+	data := make([]Erms2AribitrageInfo, 0)
+	err := engine.SQL(asa.buildSQL(accountids, status)).Find(&data)
 
 	return data, err
 }
 
-// QueryWRRContract 根据资金账号ID和状态查询.
-func QueryWRRContract(accountids []int64, status int32) ([]Erms2Wrrcontract, error) {
-	engine := db.GetEngine()
-	data := make([]Erms2Wrrcontract, 0)
-	err := engine.In("ACCOUNTID", accountids).Where("CONTRACTSTATUS = ?", status).Find(&data)
+func (Erms2Wrrcontract) buildSQL(accountids string, status int32) string {
+	statement := `select to_char(wr.wrrcontractid) wrrcontractid,
+       wr.deliverygoodsid,
+       wr.contractqty,
+       wr.contractstatus,
+       sum(case bt.contracttype
+             when 1 then
+              bt.relatedqty - bt.cancelledqty
+             else
+              0
+           end) buyqty,
+       sum(case bt.contracttype
+             when 1 then
+              bt.relatedamount - bt.cancelledamount
+             else
+              0
+           end) buyamount,
+       sum(case bt.contracttype
+             when -1 then
+              bt.relatedqty - bt.cancelledqty
+             else
+              0
+           end) sellqty,
+       sum(case bt.contracttype
+             when -1 then
+              bt.relatedamount - bt.cancelledamount
+             else
+              0
+           end) sellamount
+  from erms3_biztradedetail bt
+  left join erms2_wrrcontract wr
+    on wr.wrrcontractid = bt.relatedbizid
+ where wr.accountid in (%v)
+   and wr.contractstatus = %v
+ group by wr.wrrcontractid,
+          wr.deliverygoodsid,
+          wr.contractqty,
+          wr.contractstatus`
+	return fmt.Sprintf(statement, accountids, status)
+}
 
+// GetByAccountIDSAndStatus 根据账号和状态获取仓单回购业务.
+func (wr Erms2Wrrcontract) GetByAccountIDSAndStatus(accountids string, status int32) ([]Erms2WrrcontractInfo, error) {
+	engine := db.GetEngine()
+	data := make([]Erms2WrrcontractInfo, 0)
+	err := engine.SQL(wr.buildSQL(accountids, status)).Find(&data)
 	return data, err
 }
 
-// QuerySpotTradeBiz 根据现货资金账号ID和状态查询现货贸易业务.
-func QuerySpotTradeBiz(accountids []int64, status int32) ([]Erms2Spottradebiz, error) {
-	engine := db.GetEngine()
-	data := make([]Erms2Spottradebiz, 0)
-	err := engine.In("SPOTACCOUNTID", accountids).Where("CLOSESTATUS = ?", status).Find(&data)
+// buildSQL 构建sql.
+func (Erms2Spottradebiz) buildSQL(accountids string, status int32) string {
+	statement := `select to_char(sbt.spottradeid) spottradeid,
+       sbt.deliverygoodsid,
+       sbt.buyqty,
+       sbt.sellqty,
+       sbt.closestatus,
+       sum(case bt.contracttype
+             when 1 then
+              bt.relatedqty - bt.cancelledqty
+             else
+              0
+           end) tradebuyqty,
+       sum(case bt.contracttype
+             when 1 then
+              bt.relatedamount - bt.cancelledamount
+             else
+              0
+           end) tradebuyamount,
+       sum(case bt.contracttype
+             when -1 then
+              bt.relatedqty - bt.cancelledqty
+             else
+              0
+           end) tradesellqty,
+       sum(case bt.contracttype
+             when -1 then
+              bt.relatedamount - bt.cancelledamount
+             else
+              0
+           end) tradesellamount
+  from erms3_biztradedetail bt
+  left join erms2_spottradebiz sbt
+    on sbt.spottradeid = bt.relatedbizid
+ where sbt.spotaccountid in (%v)
+   and sbt.closestatus = %v
+ group by sbt.spottradeid,
+          sbt.deliverygoodsid,
+          sbt.buyqty,
+          sbt.sellqty,
+          sbt.closestatus`
+	return fmt.Sprintf(statement, accountids, status)
+}
 
+// GetByAccountIDSAndStatus 根据账号和状态获取现货贸易业务.
+func (stb Erms2Spottradebiz) GetByAccountIDSAndStatus(accountids string, status int32) ([]Erms2SpottradebizInfo, error) {
+	engine := db.GetEngine()
+	data := make([]Erms2SpottradebizInfo, 0)
+	err := engine.SQL(stb.buildSQL(accountids, status)).Find(&data)
 	return data, err
 }

+ 0 - 41
models/erms3.go

@@ -214,44 +214,3 @@ to_char(ERMS3_BIZTRADEDETAIL.RELATEDBIZID) RELATEDBIZID, ENUMDICITEM.ENUMDICNAME
 	err := s.Find(&datas)
 	return datas, err
 }
-
-// QueryBizTradeDetailByBizID 根据关联业务ID查询.
-func QueryBizTradeDetailByBizID(relatedbizid []int64) ([]Erms3Biztradedetail, error) {
-	data := make([]Erms3Biztradedetail, 0)
-	engine := db.GetEngine()
-	err := engine.In("RELATEDBIZID", relatedbizid).Find(&data)
-	return data, err
-}
-
-// Erms3BizTradeInfo 汇总数据.
-type Erms3BizTradeInfo struct {
-	Relatedbizid int64   // 关联业务ID
-	Buyqty       float64 // 采购量.
-	Buyamount    float64 // 采购额.
-	Sellqty      float64 // 销售量.
-	Sellamount   float64 // 销售额.
-}
-
-// QueryBizTradeInfo 根据关联业务ID查询汇总信息.
-func QueryBizTradeInfo(relatedbizid []int64) (map[int64]Erms3BizTradeInfo, error) {
-	data, err := QueryBizTradeDetailByBizID(relatedbizid)
-	if err != nil {
-		return nil, err
-	}
-
-	infos := make(map[int64]Erms3BizTradeInfo)
-	for i := range data {
-		info := infos[data[i].Relatedbizid]
-		if 1 == data[i].Contracttype {
-			info.Buyqty += data[i].Relatedqty - data[i].Cancelledqty
-			info.Buyamount += data[i].Relatedamount - data[i].Cancelledamount
-		} else if -1 == data[i].Contracttype {
-			info.Sellqty += data[i].Relatedqty - data[i].Cancelledqty
-			info.Sellamount += data[i].Relatedamount - data[i].Cancelledamount
-		}
-
-		infos[data[i].Relatedbizid] = info
-	}
-
-	return infos, nil
-}