Procházet zdrojové kódy

增加“内部未关联成交单查询”接口

zhou.xiaoning před 3 roky
rodič
revize
fb16bfded4
6 změnil soubory, kde provedl 739 přidání a 8 odebrání
  1. 23 0
      controllers/ermcp8/qryErmcp8.go
  2. 219 2
      docs/docs.go
  3. 219 2
      docs/swagger.json
  4. 156 2
      docs/swagger.yaml
  5. 108 2
      models/ermcp8.go
  6. 14 0
      utils/sqlUtils.go

+ 23 - 0
controllers/ermcp8/qryErmcp8.go

@@ -89,3 +89,26 @@ func QueryERMCPPatradeLinkDetail(c *gin.Context) {
 	a.DoBindReq(&m)
 	a.DoGetDataI(&m)
 }
+
+// QueryInternalUncorrelatedTradeDetail
+// @Summary 内部未关联成交单查询
+// @Produce json
+// @Security ApiKeyAuth
+// @Param userid query int true "用户编号"
+// @Param begindate query string false "起始日期(格式yyyymmdd)"
+// @Param enddate query string false "终止日期(格式yyyymmdd)"
+// @Param goodscode query string false "合约代码"
+// @Param goodsname query string false "合约名称"
+// @Param tradeid query int false "成交单号"
+// @Param buyorsell query int false "方向 - 0:买 1:卖"
+// @Param accountname query string true "套期主体"
+// @Success 200 {array} models.InternalUncorrelatedTradeDetail
+// @Failure 500 {object} app.Response
+// @Router /Ermcp8/QueryInternalUncorrelatedTradeDetail [get]
+// @Tags 企业风险管理v8
+func QueryInternalUncorrelatedTradeDetail(c *gin.Context) {
+	a := app.GinUtils{Gin: app.Gin{C: c}}
+	m := models.InternalUncorrelatedTradeDetail{}
+	a.DoBindReq(&m)
+	a.DoGetDataI(&m)
+}

+ 219 - 2
docs/docs.go

@@ -5808,6 +5808,91 @@ var doc = `{
                 }
             }
         },
+        "/Ermcp8/QueryInternalUncorrelatedTradeDetail": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "企业风险管理v8"
+                ],
+                "summary": "内部未关联成交单查询",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户编号",
+                        "name": "userid",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "string",
+                        "description": "起始日期(格式yyyymmdd)",
+                        "name": "begindate",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "终止日期(格式yyyymmdd)",
+                        "name": "enddate",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "合约代码",
+                        "name": "goodscode",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "合约名称",
+                        "name": "goodsname",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "成交单号",
+                        "name": "tradeid",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "方向 - 0:买 1:卖",
+                        "name": "buyorsell",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "套期主体",
+                        "name": "accountname",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "type": "array",
+                            "items": {
+                                "$ref": "#/definitions/models.InternalUncorrelatedTradeDetail"
+                            }
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Erms2/QueryArbitrageStrategy": {
             "get": {
                 "security": [
@@ -26742,8 +26827,8 @@ var doc = `{
                     "type": "string"
                 },
                 "tradeid": {
-                    "description": "内部成交单ID",
-                    "type": "integer"
+                    "description": "[成交单号]内部成交单ID",
+                    "type": "string"
                 },
                 "tradelot": {
                     "description": "成交手数",
@@ -28861,6 +28946,138 @@ var doc = `{
                 }
             }
         },
+        "models.InternalUncorrelatedTradeDetail": {
+            "type": "object",
+            "required": [
+                "userid"
+            ],
+            "properties": {
+                "accountname": {
+                    "description": "套期主体",
+                    "type": "string"
+                },
+                "agreeunit": {
+                    "description": "合约乘数",
+                    "type": "number"
+                },
+                "areauserid": {
+                    "description": "所属机构",
+                    "type": "integer"
+                },
+                "bizsubjectid": {
+                    "description": "归属业务部门ID - SubjectID",
+                    "type": "integer"
+                },
+                "buyorsell": {
+                    "description": "方向 - 0:买 1:卖",
+                    "type": "integer"
+                },
+                "convertratio": {
+                    "description": "品种系数",
+                    "type": "number"
+                },
+                "createtime": {
+                    "description": "创建时间",
+                    "type": "string"
+                },
+                "creatorid": {
+                    "description": "创建人ID",
+                    "type": "integer"
+                },
+                "creatorsrc": {
+                    "description": "创建人来源 - 1:管理端 2:终端 3:交易",
+                    "type": "integer"
+                },
+                "enableqty": {
+                    "description": "项目可关联手数 = 成交手数 - 关联数量",
+                    "type": "number"
+                },
+                "goodscode": {
+                    "description": "合约代码",
+                    "type": "string"
+                },
+                "goodsgroupid": {
+                    "description": "对冲品种ID[期货合约商品组ID]",
+                    "type": "integer"
+                },
+                "goodsid": {
+                    "description": "商品ID",
+                    "type": "integer"
+                },
+                "goodsname": {
+                    "description": "合约名称",
+                    "type": "string"
+                },
+                "hedgeditemid": {
+                    "description": "现货ID[套期项目ID] [13 - 被套期项目ID] [4,10,11 - 现货合同ID]  [9 - 套保计划ID]",
+                    "type": "integer"
+                },
+                "hedgeflag": {
+                    "description": "投机套保标志 - 0:无 1:投机 2:套保 3:套利 4:套期保值(平安\\合同) 5:单边(平安) 6:移仓(平安) 7:错单处理(平安) 8:跨期套利(平安) 9:套期保值(计划) 10:套利(合同)  11:换月(合同)  12:交割(金瑞) 13:被套期项目",
+                    "type": "integer"
+                },
+                "linkdetailid": {
+                    "description": "期货明细ID(614+Unix秒时间戳(10位)+xxxxxx)",
+                    "type": "string"
+                },
+                "linkstatus": {
+                    "description": "关联状态 - 1:成功 2:失败 3:解绑",
+                    "type": "integer"
+                },
+                "middlegoodsid": {
+                    "description": "套保品种ID",
+                    "type": "integer"
+                },
+                "relatedlot": {
+                    "description": "[数量]关联手数",
+                    "type": "number"
+                },
+                "relatedmode": {
+                    "description": "关联方式 - 1:自动关联 2:手动关联 3:解绑关联",
+                    "type": "integer"
+                },
+                "relatedqty": {
+                    "description": "[套期商品数量]关联数量 = RelatedLot * AgreeUnit * ConvertRatio",
+                    "type": "number"
+                },
+                "retcode": {
+                    "description": "返回码",
+                    "type": "integer"
+                },
+                "saleuserid": {
+                    "description": "业务员ID",
+                    "type": "integer"
+                },
+                "tradedate": {
+                    "description": "关联交易日(yyyyMMdd)",
+                    "type": "string"
+                },
+                "tradeid": {
+                    "description": "成交单号",
+                    "type": "string"
+                },
+                "tradelot": {
+                    "description": "成交手数",
+                    "type": "integer"
+                },
+                "tradeprice": {
+                    "description": "成交价",
+                    "type": "number"
+                },
+                "tradetime": {
+                    "description": "成交时间",
+                    "type": "string"
+                },
+                "tradetradedate": {
+                    "description": "成交交易日(yyyyMMdd)",
+                    "type": "string"
+                },
+                "userid": {
+                    "description": "用户编号",
+                    "type": "integer"
+                }
+            }
+        },
         "models.Loginaccount": {
             "type": "object",
             "required": [

+ 219 - 2
docs/swagger.json

@@ -5792,6 +5792,91 @@
                 }
             }
         },
+        "/Ermcp8/QueryInternalUncorrelatedTradeDetail": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "企业风险管理v8"
+                ],
+                "summary": "内部未关联成交单查询",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户编号",
+                        "name": "userid",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "string",
+                        "description": "起始日期(格式yyyymmdd)",
+                        "name": "begindate",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "终止日期(格式yyyymmdd)",
+                        "name": "enddate",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "合约代码",
+                        "name": "goodscode",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "合约名称",
+                        "name": "goodsname",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "成交单号",
+                        "name": "tradeid",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "方向 - 0:买 1:卖",
+                        "name": "buyorsell",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "套期主体",
+                        "name": "accountname",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "type": "array",
+                            "items": {
+                                "$ref": "#/definitions/models.InternalUncorrelatedTradeDetail"
+                            }
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Erms2/QueryArbitrageStrategy": {
             "get": {
                 "security": [
@@ -26726,8 +26811,8 @@
                     "type": "string"
                 },
                 "tradeid": {
-                    "description": "内部成交单ID",
-                    "type": "integer"
+                    "description": "[成交单号]内部成交单ID",
+                    "type": "string"
                 },
                 "tradelot": {
                     "description": "成交手数",
@@ -28845,6 +28930,138 @@
                 }
             }
         },
+        "models.InternalUncorrelatedTradeDetail": {
+            "type": "object",
+            "required": [
+                "userid"
+            ],
+            "properties": {
+                "accountname": {
+                    "description": "套期主体",
+                    "type": "string"
+                },
+                "agreeunit": {
+                    "description": "合约乘数",
+                    "type": "number"
+                },
+                "areauserid": {
+                    "description": "所属机构",
+                    "type": "integer"
+                },
+                "bizsubjectid": {
+                    "description": "归属业务部门ID - SubjectID",
+                    "type": "integer"
+                },
+                "buyorsell": {
+                    "description": "方向 - 0:买 1:卖",
+                    "type": "integer"
+                },
+                "convertratio": {
+                    "description": "品种系数",
+                    "type": "number"
+                },
+                "createtime": {
+                    "description": "创建时间",
+                    "type": "string"
+                },
+                "creatorid": {
+                    "description": "创建人ID",
+                    "type": "integer"
+                },
+                "creatorsrc": {
+                    "description": "创建人来源 - 1:管理端 2:终端 3:交易",
+                    "type": "integer"
+                },
+                "enableqty": {
+                    "description": "项目可关联手数 = 成交手数 - 关联数量",
+                    "type": "number"
+                },
+                "goodscode": {
+                    "description": "合约代码",
+                    "type": "string"
+                },
+                "goodsgroupid": {
+                    "description": "对冲品种ID[期货合约商品组ID]",
+                    "type": "integer"
+                },
+                "goodsid": {
+                    "description": "商品ID",
+                    "type": "integer"
+                },
+                "goodsname": {
+                    "description": "合约名称",
+                    "type": "string"
+                },
+                "hedgeditemid": {
+                    "description": "现货ID[套期项目ID] [13 - 被套期项目ID] [4,10,11 - 现货合同ID]  [9 - 套保计划ID]",
+                    "type": "integer"
+                },
+                "hedgeflag": {
+                    "description": "投机套保标志 - 0:无 1:投机 2:套保 3:套利 4:套期保值(平安\\合同) 5:单边(平安) 6:移仓(平安) 7:错单处理(平安) 8:跨期套利(平安) 9:套期保值(计划) 10:套利(合同)  11:换月(合同)  12:交割(金瑞) 13:被套期项目",
+                    "type": "integer"
+                },
+                "linkdetailid": {
+                    "description": "期货明细ID(614+Unix秒时间戳(10位)+xxxxxx)",
+                    "type": "string"
+                },
+                "linkstatus": {
+                    "description": "关联状态 - 1:成功 2:失败 3:解绑",
+                    "type": "integer"
+                },
+                "middlegoodsid": {
+                    "description": "套保品种ID",
+                    "type": "integer"
+                },
+                "relatedlot": {
+                    "description": "[数量]关联手数",
+                    "type": "number"
+                },
+                "relatedmode": {
+                    "description": "关联方式 - 1:自动关联 2:手动关联 3:解绑关联",
+                    "type": "integer"
+                },
+                "relatedqty": {
+                    "description": "[套期商品数量]关联数量 = RelatedLot * AgreeUnit * ConvertRatio",
+                    "type": "number"
+                },
+                "retcode": {
+                    "description": "返回码",
+                    "type": "integer"
+                },
+                "saleuserid": {
+                    "description": "业务员ID",
+                    "type": "integer"
+                },
+                "tradedate": {
+                    "description": "关联交易日(yyyyMMdd)",
+                    "type": "string"
+                },
+                "tradeid": {
+                    "description": "成交单号",
+                    "type": "string"
+                },
+                "tradelot": {
+                    "description": "成交手数",
+                    "type": "integer"
+                },
+                "tradeprice": {
+                    "description": "成交价",
+                    "type": "number"
+                },
+                "tradetime": {
+                    "description": "成交时间",
+                    "type": "string"
+                },
+                "tradetradedate": {
+                    "description": "成交交易日(yyyyMMdd)",
+                    "type": "string"
+                },
+                "userid": {
+                    "description": "用户编号",
+                    "type": "integer"
+                }
+            }
+        },
         "models.Loginaccount": {
             "type": "object",
             "required": [

+ 156 - 2
docs/swagger.yaml

@@ -8715,8 +8715,8 @@ definitions:
         description: 关联交易日(yyyyMMdd)
         type: string
       tradeid:
-        description: 内部成交单ID
-        type: integer
+        description: '[成交单号]内部成交单ID'
+        type: string
       tradelot:
         description: 成交手数
         type: integer
@@ -10325,6 +10325,105 @@ definitions:
     - ordertime
     - trademode
     type: object
+  models.InternalUncorrelatedTradeDetail:
+    properties:
+      accountname:
+        description: 套期主体
+        type: string
+      agreeunit:
+        description: 合约乘数
+        type: number
+      areauserid:
+        description: 所属机构
+        type: integer
+      bizsubjectid:
+        description: 归属业务部门ID - SubjectID
+        type: integer
+      buyorsell:
+        description: 方向 - 0:买 1:卖
+        type: integer
+      convertratio:
+        description: 品种系数
+        type: number
+      createtime:
+        description: 创建时间
+        type: string
+      creatorid:
+        description: 创建人ID
+        type: integer
+      creatorsrc:
+        description: 创建人来源 - 1:管理端 2:终端 3:交易
+        type: integer
+      enableqty:
+        description: 项目可关联手数 = 成交手数 - 关联数量
+        type: number
+      goodscode:
+        description: 合约代码
+        type: string
+      goodsgroupid:
+        description: 对冲品种ID[期货合约商品组ID]
+        type: integer
+      goodsid:
+        description: 商品ID
+        type: integer
+      goodsname:
+        description: 合约名称
+        type: string
+      hedgeditemid:
+        description: 现货ID[套期项目ID] [13 - 被套期项目ID] [4,10,11 - 现货合同ID]  [9 - 套保计划ID]
+        type: integer
+      hedgeflag:
+        description: 投机套保标志 - 0:无 1:投机 2:套保 3:套利 4:套期保值(平安\合同) 5:单边(平安) 6:移仓(平安) 7:错单处理(平安)
+          8:跨期套利(平安) 9:套期保值(计划) 10:套利(合同)  11:换月(合同)  12:交割(金瑞) 13:被套期项目
+        type: integer
+      linkdetailid:
+        description: 期货明细ID(614+Unix秒时间戳(10位)+xxxxxx)
+        type: string
+      linkstatus:
+        description: 关联状态 - 1:成功 2:失败 3:解绑
+        type: integer
+      middlegoodsid:
+        description: 套保品种ID
+        type: integer
+      relatedlot:
+        description: '[数量]关联手数'
+        type: number
+      relatedmode:
+        description: 关联方式 - 1:自动关联 2:手动关联 3:解绑关联
+        type: integer
+      relatedqty:
+        description: '[套期商品数量]关联数量 = RelatedLot * AgreeUnit * ConvertRatio'
+        type: number
+      retcode:
+        description: 返回码
+        type: integer
+      saleuserid:
+        description: 业务员ID
+        type: integer
+      tradedate:
+        description: 关联交易日(yyyyMMdd)
+        type: string
+      tradeid:
+        description: 成交单号
+        type: string
+      tradelot:
+        description: 成交手数
+        type: integer
+      tradeprice:
+        description: 成交价
+        type: number
+      tradetime:
+        description: 成交时间
+        type: string
+      tradetradedate:
+        description: 成交交易日(yyyyMMdd)
+        type: string
+      userid:
+        description: 用户编号
+        type: integer
+    required:
+    - userid
+    type: object
   models.Loginaccount:
     properties:
       accountname:
@@ -24271,6 +24370,61 @@ paths:
       summary: 查询被套期项目信息
       tags:
       - 企业风险管理v8
+  /Ermcp8/QueryInternalUncorrelatedTradeDetail:
+    get:
+      parameters:
+      - description: 用户编号
+        in: query
+        name: userid
+        required: true
+        type: integer
+      - description: 起始日期(格式yyyymmdd)
+        in: query
+        name: begindate
+        type: string
+      - description: 终止日期(格式yyyymmdd)
+        in: query
+        name: enddate
+        type: string
+      - description: 合约代码
+        in: query
+        name: goodscode
+        type: string
+      - description: 合约名称
+        in: query
+        name: goodsname
+        type: string
+      - description: 成交单号
+        in: query
+        name: tradeid
+        type: integer
+      - description: 方向 - 0:买 1:卖
+        in: query
+        name: buyorsell
+        type: integer
+      - description: 套期主体
+        in: query
+        name: accountname
+        required: true
+        type: string
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            items:
+              $ref: '#/definitions/models.InternalUncorrelatedTradeDetail'
+            type: array
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 内部未关联成交单查询
+      tags:
+      - 企业风险管理v8
   /Erms2/QueryArbitrageStrategy:
     get:
       parameters:

+ 108 - 2
models/ermcp8.go

@@ -479,7 +479,7 @@ func (r *Ermcp2hedgeditemspotDetail) GetDataEx() (interface{}, error) {
 // Ermcppatradelinkdetail 期货成交单关联明细表
 type Ermcppatradelinkdetail struct {
 	LINKDETAILID   string    `json:"linkdetailid"  xorm:"LINKDETAILID"`                                          // 期货明细ID(614+Unix秒时间戳(10位)+xxxxxx)
-	TRADEID        int64     `json:"tradeid"  xorm:"TRADEID"`                                                    // 内部成交单ID
+	TRADEID        string    `json:"tradeid"  xorm:"TRADEID"`                                                    // [成交单号]内部成交单ID
 	BUYORSELL      int32     `json:"buyorsell"  xorm:"BUYORSELL"`                                                // 方向 - 0:买 1:卖
 	HEDGEFLAG      int32     `json:"hedgeflag"  xorm:"HEDGEFLAG"`                                                // 投机套保标志 - 0:无 1:投机 2:套保 3:套利 4:套期保值(平安\合同) 5:单边(平安) 6:移仓(平安) 7:错单处理(平安) 8:跨期套利(平安) 9:套期保值(计划) 10:套利(合同)  11:换月(合同)  12:交割(金瑞) 13:被套期项目
 	SPOTCONTRACTID int64     `json:"hedgeditemid"  xorm:"SPOTCONTRACTID" form:"hedgeditemid" binding:"required"` // 现货ID[套期项目ID] [13 - 被套期项目ID] [4,10,11 - 现货合同ID]  [9 - 套保计划ID]
@@ -525,7 +525,7 @@ func (r *Ermcppatradelinkdetail) buildSql() string {
 		t.TRADEPRICE,
 		t.RELATEDLOT,
 		(t.RelatedLot * t.TradePrice * t.AgreeUnit) AMOUNT,
-		t.TRADEID,
+		to_char(t.TRADEID) TRADEID,
 		(u.ACCOUNTNAME || '/' || to_char(t.ACCOUNTID)) NAME
 	FROM ERMCP_PA_TradeLinkDetail t
 	LEFT JOIN ERMCP_PA_TradeLink p ON p.TradeID = t.TradeID AND p.BuyorSell = t.BuyorSell
@@ -552,3 +552,109 @@ func (r *Ermcppatradelinkdetail) GetDataEx() (interface{}, error) {
 	}
 	return sData, nil
 }
+
+// InternalUncorrelatedTradeDetail 内部未关联成交单
+type InternalUncorrelatedTradeDetail struct {
+	LINKDETAILID   string    `json:"linkdetailid"  xorm:"LINKDETAILID"`            // 期货明细ID(614+Unix秒时间戳(10位)+xxxxxx)
+	TRADEID        string    `json:"tradeid"  xorm:"TRADEID" form:"tradeid"`       // 成交单号
+	BUYORSELL      int32     `json:"buyorsell"  xorm:"BUYORSELL" form:"buyorsell"` // 方向 - 0:买 1:卖
+	HEDGEFLAG      int32     `json:"hedgeflag"  xorm:"HEDGEFLAG"`                  // 投机套保标志 - 0:无 1:投机 2:套保 3:套利 4:套期保值(平安\合同) 5:单边(平安) 6:移仓(平安) 7:错单处理(平安) 8:跨期套利(平安) 9:套期保值(计划) 10:套利(合同)  11:换月(合同)  12:交割(金瑞) 13:被套期项目
+	SPOTCONTRACTID int64     `json:"hedgeditemid"  xorm:"SPOTCONTRACTID"`          // 现货ID[套期项目ID] [13 - 被套期项目ID] [4,10,11 - 现货合同ID]  [9 - 套保计划ID]
+	RELATEDLOT     float64   `json:"relatedlot"  xorm:"RELATEDLOT"`                // [数量]关联手数
+	GOODSID        int32     `json:"goodsid"  xorm:"GOODSID"`                      // 商品ID
+	GOODSGROUPID   int32     `json:"goodsgroupid"  xorm:"GOODSGROUPID"`            // 对冲品种ID[期货合约商品组ID]
+	MIDDLEGOODSID  int64     `json:"middlegoodsid"  xorm:"MIDDLEGOODSID"`          // 套保品种ID
+	RELATEDQTY     float64   `json:"relatedqty"  xorm:"RELATEDQTY"`                // [套期商品数量]关联数量 = RelatedLot * AgreeUnit * ConvertRatio
+	TRADEDATE      string    `json:"tradedate"  xorm:"TRADEDATE"`                  // 关联交易日(yyyyMMdd)
+	RELATEDMODE    int32     `json:"relatedmode"  xorm:"RELATEDMODE"`              // 关联方式 - 1:自动关联 2:手动关联 3:解绑关联
+	TRADETRADEDATE string    `json:"tradetradedate"  xorm:"TRADETRADEDATE"`        // 成交交易日(yyyyMMdd)
+	TRADEPRICE     float64   `json:"tradeprice"  xorm:"TRADEPRICE"`                // 成交价
+	TRADELOT       int64     `json:"tradelot"  xorm:"TRADELOT"`                    // 成交手数
+	SALEUSERID     int64     `json:"saleuserid"  xorm:"SALEUSERID"`                // 业务员ID
+	BIZSUBJECTID   int64     `json:"bizsubjectid"  xorm:"BIZSUBJECTID"`            // 归属业务部门ID - SubjectID
+	AGREEUNIT      float64   `json:"agreeunit"  xorm:"AGREEUNIT"`                  // 合约乘数
+	CONVERTRATIO   float64   `json:"convertratio"  xorm:"CONVERTRATIO"`            // 品种系数
+	AREAUSERID     int64     `json:"areauserid"  xorm:"AREAUSERID"`                // 所属机构
+	CREATORSRC     int32     `json:"creatorsrc"  xorm:"CREATORSRC"`                // 创建人来源 - 1:管理端 2:终端 3:交易
+	CREATORID      int64     `json:"creatorid"  xorm:"CREATORID"`                  // 创建人ID
+	CREATETIME     time.Time `json:"createtime"  xorm:"CREATETIME"`                // 创建时间
+	LINKSTATUS     int32     `json:"linkstatus"  xorm:"LINKSTATUS"`                // 关联状态 - 1:成功 2:失败 3:解绑
+	RETCODE        int32     `json:"retcode"  xorm:"RETCODE"`                      // 返回码
+
+	TRADETIME   time.Time `json:"tradetime"  xorm:"TRADETIME"`                       // 成交时间
+	ACCOUNTNAME string    `json:"accountname" xorm:"ACCOUNTNAME" form:"accountname"` // 套期主体
+	ENABLEQTY   float64   `json:"enableqty" xorm:"ENABLEQTY"`                        // 项目可关联手数 = 成交手数 - 关联数量
+
+	USERID    int64  `form:"userid" binding:"required"`  // 用户编号
+	BEGINDATE string `json:"-" form:"begindate"`         // 起始日期, 格式:yyyymmdd
+	ENDDATE   string `json:"-" form:"enddate"`           // 终止日期, 格式:yyyymmdd
+	GOODSCODE string `json:"goodscode" form:"goodscode"` // 合约代码
+	GOODSNAME string `json:"goodsname" form:"goodsname"` // 合约名称
+}
+
+func (r *InternalUncorrelatedTradeDetail) calc() {
+
+}
+
+func (r *InternalUncorrelatedTradeDetail) buildSql() string {
+	var sqlId utils.SQLVal = `
+	SELECT 
+		ept.TRADETIME,
+		ept.GOODSID,
+		g.GOODSCODE,
+		g.GOODSNAME,
+		ept.BUYORSELL,
+		ept.TRADEPRICE,
+		ept.TRADELOT,
+		ept.RELATEDQTY,
+		ept.RELATEDLOT,
+		ept.MIDDLEGOODSQTY,
+		e.ENUMDICNAME,
+		to_char(ept.TRADEID) TRADEID,
+		ua.ACCOUNTNAME,
+		ta.accountname TAACCOUNTNAME,
+		ept.ACCOUNTID,
+		(ept.TRADELOT - ept.RELATEDQTY) ENABLEQTY
+	FROM ERMCP_PA_TRADELINK ept
+	LEFT JOIN goods g ON ept.goodsid = g.goodsid
+	LEFT JOIN taaccount ta ON ta.accountid = ept.accountid
+	LEFT JOIN useraccount ua ON ta.userid = ua.userid
+	LEFT JOIN enumdicitem e ON e.enumitemname = g.goodunitid AND e.enumdiccode = 'goodsunit'
+	WHERE ept.tradelot > ept.relatedlot
+	and ept.areauserid in
+		(select u1.userid
+			FROM useraccount u1
+			start with u1.userid = %v
+			connect by prior u1.userid = u1.parentuserid)
+	`
+
+	sqlId.FormatParam(r.USERID)
+	if r.BEGINDATE != "" {
+		sqlId.JoinFormat(" and to_char(ept.tradetime, 'yyyymmdd') >= '%v'", r.BEGINDATE)
+	}
+	if r.ENDDATE != "" {
+		sqlId.JoinFormat(" and to_char(ept.tradetime, 'yyyymmdd') <= '%v'", r.ENDDATE)
+	}
+	sqlId.AndLike("g.goodscode", r.GOODSCODE)
+	sqlId.AndLike("g.goodsname", r.GOODSNAME)
+	sqlId.AndEx("ept.TRADEID", r.TRADEID, r.TRADEID != "")
+	sqlId.And("ept.BUYORSELL", r.BUYORSELL)
+	sqlId.AndLikes2("ta.accountname", "ta.accountid", r.ACCOUNTNAME)
+	sqlId.OrderByDesc("ept.tradetime")
+
+	return sqlId.String()
+}
+
+// GetDataEx 从数据库中查询数据
+func (r *InternalUncorrelatedTradeDetail) GetDataEx() (interface{}, error) {
+	e := db.GetEngine()
+	s := e.SQL(r.buildSql())
+	sData := make([]InternalUncorrelatedTradeDetail, 0)
+	if err := s.Find(&sData); err != nil {
+		return nil, err
+	}
+	for i := range sData {
+		sData[i].calc()
+	}
+	return sData, nil
+}

+ 14 - 0
utils/sqlUtils.go

@@ -108,6 +108,20 @@ func (r *SQLVal) AndLikes2(fieldName string, fieldName2 string, param ...string)
 	}
 }
 
+// OrderBy 排序
+func (r *SQLVal) OrderBy(fieldName ...string) {
+	if len(fieldName) > 0 {
+		*r += SQLVal(fmt.Sprintf(" ORDER BY %v", fieldName))
+	}
+}
+
+// OrderByDesc 反向排序
+func (r *SQLVal) OrderByDesc(fieldName ...string) {
+	if len(fieldName) > 0 {
+		*r += SQLVal(fmt.Sprintf(" ORDER BY %v DESC", fieldName))
+	}
+}
+
 // Page 分页查询 pageNum-页码 第几页, pageSize-每页大小
 func (r *SQLVal) Page(pageNum int, pageSize int) {
 	if pageNum <= 0 || pageSize <= 0 {