Browse Source

增加“未关联合同查询”接口

zhou.xiaoning 3 years ago
parent
commit
a2e699dba9
7 changed files with 1105 additions and 50 deletions
  1. 33 0
      controllers/ermcp8/qryErmcp8.go
  2. 291 0
      docs/docs.go
  3. 291 0
      docs/swagger.json
  4. 210 0
      docs/swagger.yaml
  5. 4 22
      models/ermcp.go
  6. 275 28
      models/ermcp8.go
  7. 1 0
      routers/router.go

+ 33 - 0
controllers/ermcp8/qryErmcp8.go

@@ -2,7 +2,10 @@ package ermcp8
 
 import (
 	"mtp2_if/global/app"
+	"mtp2_if/global/e"
+	"mtp2_if/logger"
 	"mtp2_if/models"
+	"net/http"
 
 	"github.com/gin-gonic/gin"
 )
@@ -151,3 +154,33 @@ func QueryErmcp8HedgeditemReport(c *gin.Context) {
 	a.DoBindReq(&m)
 	a.DoGetDataI(&m)
 }
+
+// QueryUnLinkSpotContract
+// @Summary 未关联合同查询
+// @Produce json
+// @Security ApiKeyAuth
+// @Param userid query int true "用户ID"
+// @Param pricetype query int false "定价类型 - 1:一口价 2:点价 3:暂定价"
+// @Param contractno query string false "合同编号, 模拟查询"
+// @Param customername query string false "对手方, 模拟查询"
+// @Param contracttype query int false "项合同类型 - 1:采购 -1:销售"
+// @Success 200 {array} models.ErmcpSpotContractModelEx
+// @Failure 500 {object} app.Response
+// @Router /Ermcp8/QueryUnLinkSpotContract [get]
+// @Tags 企业风险管理v8
+func QueryUnLinkSpotContract(c *gin.Context) {
+	appG := app.Gin{C: c}
+	var req models.QrySpotContractExReq
+	if err := c.ShouldBind(&req); err != nil {
+		logger.GetLogger().Errorf("parse query req: %v", err)
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	var m = models.ErmcpSpotContractModelEx{}
+	if d, err := m.GetData(req); err == nil {
+		appG.Response(http.StatusOK, e.SUCCESS, d)
+	} else {
+		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+	}
+}

+ 291 - 0
docs/docs.go

@@ -6020,6 +6020,72 @@ var doc = `{
                 }
             }
         },
+        "/Ermcp8/QueryUnLinkSpotContract": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "企业风险管理v8"
+                ],
+                "summary": "未关联合同查询",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户ID",
+                        "name": "userid",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "定价类型 - 1:一口价 2:点价 3:暂定价",
+                        "name": "pricetype",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "合同编号, 模拟查询",
+                        "name": "contractno",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "对手方, 模拟查询",
+                        "name": "customername",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "项合同类型 - 1:采购 -1:销售",
+                        "name": "contracttype",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "type": "array",
+                            "items": {
+                                "$ref": "#/definitions/models.ErmcpSpotContractModelEx"
+                            }
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Erms2/QueryArbitrageStrategy": {
             "get": {
                 "security": [
@@ -26524,6 +26590,231 @@ var doc = `{
                 }
             }
         },
+        "models.ErmcpSpotContractModelEx": {
+            "type": "object",
+            "properties": {
+                "accountName": {
+                    "description": "套期主体",
+                    "type": "string"
+                },
+                "amount": {
+                    "description": "金额 [1:一口价、3:暂定价]",
+                    "type": "number"
+                },
+                "attachment": {
+                    "description": "附件",
+                    "type": "string"
+                },
+                "auditremark": {
+                    "description": "审核意见",
+                    "type": "string"
+                },
+                "audittime": {
+                    "description": "审核时间",
+                    "type": "string"
+                },
+                "avgprice": {
+                    "description": "定价均价 = 已定价金额 / 已定价量",
+                    "type": "number"
+                },
+                "brandname": {
+                    "description": "品牌名称",
+                    "type": "string"
+                },
+                "buyuserid": {
+                    "description": "采购方ID",
+                    "type": "integer"
+                },
+                "buyusername": {
+                    "description": "采购方名称",
+                    "type": "string"
+                },
+                "contracctstatus": {
+                    "description": "合同状态 - 0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回",
+                    "type": "integer"
+                },
+                "contractmargin": {
+                    "description": "合同保证金",
+                    "type": "number"
+                },
+                "contractno": {
+                    "description": "[合同编号]现货合同编号",
+                    "type": "string"
+                },
+                "contracttype": {
+                    "description": "[合同类型]现货合同类型 - 1:采购 -1:销售",
+                    "type": "integer"
+                },
+                "convertfactor": {
+                    "description": "标仓系数",
+                    "type": "number"
+                },
+                "createtime": {
+                    "description": "创建时间",
+                    "type": "string"
+                },
+                "customername": {
+                    "description": "对手方",
+                    "type": "string"
+                },
+                "customeruserid": {
+                    "description": "客户ID",
+                    "type": "integer"
+                },
+                "deliveryenddate": {
+                    "description": "交收期(结束)",
+                    "type": "string"
+                },
+                "deliverygoodscode": {
+                    "description": "现货品种代码",
+                    "type": "string"
+                },
+                "deliverygoodsid": {
+                    "description": "现货品种ID",
+                    "type": "integer"
+                },
+                "deliverygoodsname": {
+                    "description": "现货品种名称",
+                    "type": "string"
+                },
+                "deliverystartdate": {
+                    "description": "交收期(开始)",
+                    "type": "string"
+                },
+                "enddate": {
+                    "description": "点价结束日期 [2:点价 3:暂定价]",
+                    "type": "string"
+                },
+                "enumdicname": {
+                    "description": "单位名称",
+                    "type": "string"
+                },
+                "goodscode": {
+                    "description": "点价合约代码",
+                    "type": "string"
+                },
+                "goodsid": {
+                    "description": "点价合约ID - 0:为现货,其它为期货商品合约ID [2:点价 3:暂定价]",
+                    "type": "integer"
+                },
+                "goodsname": {
+                    "description": "点价商品名称",
+                    "type": "string"
+                },
+                "isrelated": {
+                    "description": "是否已关联计划项目 - 0:否 1:是",
+                    "type": "integer"
+                },
+                "isrelated2": {
+                    "description": "是否已关联现货项目 - 0:否 1:是",
+                    "type": "integer"
+                },
+                "margin": {
+                    "description": "当前保证金",
+                    "type": "number"
+                },
+                "modelname": {
+                    "description": "型号名称",
+                    "type": "string"
+                },
+                "price": {
+                    "description": "价格\\暂定价 [1:一口价、3:暂定价]",
+                    "type": "number"
+                },
+                "pricedamount": {
+                    "description": "已定价金额 = (点价价格+升贴水) * 数量",
+                    "type": "number"
+                },
+                "pricedqty": {
+                    "description": "已定价量",
+                    "type": "number"
+                },
+                "pricemove": {
+                    "description": "升贴水 [2:点价 3:暂定价]",
+                    "type": "number"
+                },
+                "pricetype": {
+                    "description": "定价类型 - 1:一口价 2:点价 3:暂定价",
+                    "type": "integer"
+                },
+                "producttype": {
+                    "description": "产品类型 - 1:标准仓单 2:等标 3:非标",
+                    "type": "integer"
+                },
+                "qty": {
+                    "description": "[合同数量]数量",
+                    "type": "number"
+                },
+                "remark": {
+                    "description": "备注",
+                    "type": "string"
+                },
+                "selluserid": {
+                    "description": "销售方ID",
+                    "type": "integer"
+                },
+                "sellusername": {
+                    "description": "销售方名称",
+                    "type": "string"
+                },
+                "spotamount": {
+                    "description": "合同现货金额 [不含升贴水]",
+                    "type": "number"
+                },
+                "spotavgprice": {
+                    "description": "现货均价 = 合同现货金额 / 已定价量",
+                    "type": "number"
+                },
+                "spotcontractid": {
+                    "description": "现货合同ID(602+Unix秒时间戳(10位)+xxxxxx)",
+                    "type": "string"
+                },
+                "spotgoodsbrandid": {
+                    "description": "现货品牌ID",
+                    "type": "integer"
+                },
+                "spotgoodsdesc": {
+                    "description": "商品型号",
+                    "type": "string"
+                },
+                "spotgoodsmodelid": {
+                    "description": "现货型号ID",
+                    "type": "integer"
+                },
+                "startdate": {
+                    "description": "点价开始日期 [2:点价 3:暂定价]",
+                    "type": "string"
+                },
+                "tradeuserid": {
+                    "description": "交易用户ID",
+                    "type": "integer"
+                },
+                "unpricedqty": {
+                    "description": "未定价量 = 合同数量 - 已定价量",
+                    "type": "number"
+                },
+                "updatetime": {
+                    "description": "更新时间",
+                    "type": "string"
+                },
+                "userid": {
+                    "description": "机构ID",
+                    "type": "integer"
+                },
+                "wrstandardcode": {
+                    "description": "现货商品代码",
+                    "type": "string"
+                },
+                "wrstandardid": {
+                    "description": "现货商品ID",
+                    "type": "integer"
+                },
+                "wrstandardname": {
+                    "description": "[现货商品]现货商品名称",
+                    "type": "string"
+                }
+            }
+        },
         "models.ErmcpTaAccount": {
             "type": "object",
             "properties": {

+ 291 - 0
docs/swagger.json

@@ -6004,6 +6004,72 @@
                 }
             }
         },
+        "/Ermcp8/QueryUnLinkSpotContract": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "企业风险管理v8"
+                ],
+                "summary": "未关联合同查询",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户ID",
+                        "name": "userid",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "定价类型 - 1:一口价 2:点价 3:暂定价",
+                        "name": "pricetype",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "合同编号, 模拟查询",
+                        "name": "contractno",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "对手方, 模拟查询",
+                        "name": "customername",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "项合同类型 - 1:采购 -1:销售",
+                        "name": "contracttype",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "type": "array",
+                            "items": {
+                                "$ref": "#/definitions/models.ErmcpSpotContractModelEx"
+                            }
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Erms2/QueryArbitrageStrategy": {
             "get": {
                 "security": [
@@ -26508,6 +26574,231 @@
                 }
             }
         },
+        "models.ErmcpSpotContractModelEx": {
+            "type": "object",
+            "properties": {
+                "accountName": {
+                    "description": "套期主体",
+                    "type": "string"
+                },
+                "amount": {
+                    "description": "金额 [1:一口价、3:暂定价]",
+                    "type": "number"
+                },
+                "attachment": {
+                    "description": "附件",
+                    "type": "string"
+                },
+                "auditremark": {
+                    "description": "审核意见",
+                    "type": "string"
+                },
+                "audittime": {
+                    "description": "审核时间",
+                    "type": "string"
+                },
+                "avgprice": {
+                    "description": "定价均价 = 已定价金额 / 已定价量",
+                    "type": "number"
+                },
+                "brandname": {
+                    "description": "品牌名称",
+                    "type": "string"
+                },
+                "buyuserid": {
+                    "description": "采购方ID",
+                    "type": "integer"
+                },
+                "buyusername": {
+                    "description": "采购方名称",
+                    "type": "string"
+                },
+                "contracctstatus": {
+                    "description": "合同状态 - 0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回",
+                    "type": "integer"
+                },
+                "contractmargin": {
+                    "description": "合同保证金",
+                    "type": "number"
+                },
+                "contractno": {
+                    "description": "[合同编号]现货合同编号",
+                    "type": "string"
+                },
+                "contracttype": {
+                    "description": "[合同类型]现货合同类型 - 1:采购 -1:销售",
+                    "type": "integer"
+                },
+                "convertfactor": {
+                    "description": "标仓系数",
+                    "type": "number"
+                },
+                "createtime": {
+                    "description": "创建时间",
+                    "type": "string"
+                },
+                "customername": {
+                    "description": "对手方",
+                    "type": "string"
+                },
+                "customeruserid": {
+                    "description": "客户ID",
+                    "type": "integer"
+                },
+                "deliveryenddate": {
+                    "description": "交收期(结束)",
+                    "type": "string"
+                },
+                "deliverygoodscode": {
+                    "description": "现货品种代码",
+                    "type": "string"
+                },
+                "deliverygoodsid": {
+                    "description": "现货品种ID",
+                    "type": "integer"
+                },
+                "deliverygoodsname": {
+                    "description": "现货品种名称",
+                    "type": "string"
+                },
+                "deliverystartdate": {
+                    "description": "交收期(开始)",
+                    "type": "string"
+                },
+                "enddate": {
+                    "description": "点价结束日期 [2:点价 3:暂定价]",
+                    "type": "string"
+                },
+                "enumdicname": {
+                    "description": "单位名称",
+                    "type": "string"
+                },
+                "goodscode": {
+                    "description": "点价合约代码",
+                    "type": "string"
+                },
+                "goodsid": {
+                    "description": "点价合约ID - 0:为现货,其它为期货商品合约ID [2:点价 3:暂定价]",
+                    "type": "integer"
+                },
+                "goodsname": {
+                    "description": "点价商品名称",
+                    "type": "string"
+                },
+                "isrelated": {
+                    "description": "是否已关联计划项目 - 0:否 1:是",
+                    "type": "integer"
+                },
+                "isrelated2": {
+                    "description": "是否已关联现货项目 - 0:否 1:是",
+                    "type": "integer"
+                },
+                "margin": {
+                    "description": "当前保证金",
+                    "type": "number"
+                },
+                "modelname": {
+                    "description": "型号名称",
+                    "type": "string"
+                },
+                "price": {
+                    "description": "价格\\暂定价 [1:一口价、3:暂定价]",
+                    "type": "number"
+                },
+                "pricedamount": {
+                    "description": "已定价金额 = (点价价格+升贴水) * 数量",
+                    "type": "number"
+                },
+                "pricedqty": {
+                    "description": "已定价量",
+                    "type": "number"
+                },
+                "pricemove": {
+                    "description": "升贴水 [2:点价 3:暂定价]",
+                    "type": "number"
+                },
+                "pricetype": {
+                    "description": "定价类型 - 1:一口价 2:点价 3:暂定价",
+                    "type": "integer"
+                },
+                "producttype": {
+                    "description": "产品类型 - 1:标准仓单 2:等标 3:非标",
+                    "type": "integer"
+                },
+                "qty": {
+                    "description": "[合同数量]数量",
+                    "type": "number"
+                },
+                "remark": {
+                    "description": "备注",
+                    "type": "string"
+                },
+                "selluserid": {
+                    "description": "销售方ID",
+                    "type": "integer"
+                },
+                "sellusername": {
+                    "description": "销售方名称",
+                    "type": "string"
+                },
+                "spotamount": {
+                    "description": "合同现货金额 [不含升贴水]",
+                    "type": "number"
+                },
+                "spotavgprice": {
+                    "description": "现货均价 = 合同现货金额 / 已定价量",
+                    "type": "number"
+                },
+                "spotcontractid": {
+                    "description": "现货合同ID(602+Unix秒时间戳(10位)+xxxxxx)",
+                    "type": "string"
+                },
+                "spotgoodsbrandid": {
+                    "description": "现货品牌ID",
+                    "type": "integer"
+                },
+                "spotgoodsdesc": {
+                    "description": "商品型号",
+                    "type": "string"
+                },
+                "spotgoodsmodelid": {
+                    "description": "现货型号ID",
+                    "type": "integer"
+                },
+                "startdate": {
+                    "description": "点价开始日期 [2:点价 3:暂定价]",
+                    "type": "string"
+                },
+                "tradeuserid": {
+                    "description": "交易用户ID",
+                    "type": "integer"
+                },
+                "unpricedqty": {
+                    "description": "未定价量 = 合同数量 - 已定价量",
+                    "type": "number"
+                },
+                "updatetime": {
+                    "description": "更新时间",
+                    "type": "string"
+                },
+                "userid": {
+                    "description": "机构ID",
+                    "type": "integer"
+                },
+                "wrstandardcode": {
+                    "description": "现货商品代码",
+                    "type": "string"
+                },
+                "wrstandardid": {
+                    "description": "现货商品ID",
+                    "type": "integer"
+                },
+                "wrstandardname": {
+                    "description": "[现货商品]现货商品名称",
+                    "type": "string"
+                }
+            }
+        },
         "models.ErmcpTaAccount": {
             "type": "object",
             "properties": {

+ 210 - 0
docs/swagger.yaml

@@ -8399,6 +8399,174 @@ definitions:
           $ref: '#/definitions/models.ErmcpRoleMenuEx'
         type: array
     type: object
+  models.ErmcpSpotContractModelEx:
+    properties:
+      accountName:
+        description: 套期主体
+        type: string
+      amount:
+        description: 金额 [1:一口价、3:暂定价]
+        type: number
+      attachment:
+        description: 附件
+        type: string
+      auditremark:
+        description: 审核意见
+        type: string
+      audittime:
+        description: 审核时间
+        type: string
+      avgprice:
+        description: 定价均价 = 已定价金额 / 已定价量
+        type: number
+      brandname:
+        description: 品牌名称
+        type: string
+      buyuserid:
+        description: 采购方ID
+        type: integer
+      buyusername:
+        description: 采购方名称
+        type: string
+      contracctstatus:
+        description: 合同状态 - 0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回
+        type: integer
+      contractmargin:
+        description: 合同保证金
+        type: number
+      contractno:
+        description: '[合同编号]现货合同编号'
+        type: string
+      contracttype:
+        description: '[合同类型]现货合同类型 - 1:采购 -1:销售'
+        type: integer
+      convertfactor:
+        description: 标仓系数
+        type: number
+      createtime:
+        description: 创建时间
+        type: string
+      customername:
+        description: 对手方
+        type: string
+      customeruserid:
+        description: 客户ID
+        type: integer
+      deliveryenddate:
+        description: 交收期(结束)
+        type: string
+      deliverygoodscode:
+        description: 现货品种代码
+        type: string
+      deliverygoodsid:
+        description: 现货品种ID
+        type: integer
+      deliverygoodsname:
+        description: 现货品种名称
+        type: string
+      deliverystartdate:
+        description: 交收期(开始)
+        type: string
+      enddate:
+        description: 点价结束日期 [2:点价 3:暂定价]
+        type: string
+      enumdicname:
+        description: 单位名称
+        type: string
+      goodscode:
+        description: 点价合约代码
+        type: string
+      goodsid:
+        description: 点价合约ID - 0:为现货,其它为期货商品合约ID [2:点价 3:暂定价]
+        type: integer
+      goodsname:
+        description: 点价商品名称
+        type: string
+      isrelated:
+        description: 是否已关联计划项目 - 0:否 1:是
+        type: integer
+      isrelated2:
+        description: 是否已关联现货项目 - 0:否 1:是
+        type: integer
+      margin:
+        description: 当前保证金
+        type: number
+      modelname:
+        description: 型号名称
+        type: string
+      price:
+        description: 价格\暂定价 [1:一口价、3:暂定价]
+        type: number
+      pricedamount:
+        description: 已定价金额 = (点价价格+升贴水) * 数量
+        type: number
+      pricedqty:
+        description: 已定价量
+        type: number
+      pricemove:
+        description: 升贴水 [2:点价 3:暂定价]
+        type: number
+      pricetype:
+        description: 定价类型 - 1:一口价 2:点价 3:暂定价
+        type: integer
+      producttype:
+        description: 产品类型 - 1:标准仓单 2:等标 3:非标
+        type: integer
+      qty:
+        description: '[合同数量]数量'
+        type: number
+      remark:
+        description: 备注
+        type: string
+      selluserid:
+        description: 销售方ID
+        type: integer
+      sellusername:
+        description: 销售方名称
+        type: string
+      spotamount:
+        description: 合同现货金额 [不含升贴水]
+        type: number
+      spotavgprice:
+        description: 现货均价 = 合同现货金额 / 已定价量
+        type: number
+      spotcontractid:
+        description: 现货合同ID(602+Unix秒时间戳(10位)+xxxxxx)
+        type: string
+      spotgoodsbrandid:
+        description: 现货品牌ID
+        type: integer
+      spotgoodsdesc:
+        description: 商品型号
+        type: string
+      spotgoodsmodelid:
+        description: 现货型号ID
+        type: integer
+      startdate:
+        description: 点价开始日期 [2:点价 3:暂定价]
+        type: string
+      tradeuserid:
+        description: 交易用户ID
+        type: integer
+      unpricedqty:
+        description: 未定价量 = 合同数量 - 已定价量
+        type: number
+      updatetime:
+        description: 更新时间
+        type: string
+      userid:
+        description: 机构ID
+        type: integer
+      wrstandardcode:
+        description: 现货商品代码
+        type: string
+      wrstandardid:
+        description: 现货商品ID
+        type: integer
+      wrstandardname:
+        description: '[现货商品]现货商品名称'
+        type: string
+    type: object
   models.ErmcpTaAccount:
     properties:
       accountid:
@@ -24662,6 +24830,48 @@ paths:
       summary: 内部未关联成交单查询
       tags:
       - 企业风险管理v8
+  /Ermcp8/QueryUnLinkSpotContract:
+    get:
+      parameters:
+      - description: 用户ID
+        in: query
+        name: userid
+        required: true
+        type: integer
+      - description: 定价类型 - 1:一口价 2:点价 3:暂定价
+        in: query
+        name: pricetype
+        type: integer
+      - description: 合同编号, 模拟查询
+        in: query
+        name: contractno
+        type: string
+      - description: 对手方, 模拟查询
+        in: query
+        name: customername
+        type: string
+      - description: 项合同类型 - 1:采购 -1:销售
+        in: query
+        name: contracttype
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            items:
+              $ref: '#/definitions/models.ErmcpSpotContractModelEx'
+            type: array
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 未关联合同查询
+      tags:
+      - 企业风险管理v8
   /Erms2/QueryArbitrageStrategy:
     get:
       parameters:

+ 4 - 22
models/ermcp.go

@@ -18,8 +18,8 @@ import (
 // ErmcpSpotContractModel 现货合同结构(对应现货合同菜单)
 type ErmcpSpotContractModel struct {
 	SPOTCONTRACTID    string  `json:"spotcontractid"  xorm:"'SPOTCONTRACTID'"`       // 现货合同ID(602+Unix秒时间戳(10位)+xxxxxx)
-	CONTRACTNO        string  `json:"contractno"  xorm:"'CONTRACTNO'"`               // [合同编号]现货合同编号
-	CONTRACTTYPE      int32   `json:"contracttype"  xorm:"'CONTRACTTYPE'"`           // [合同类型]现货合同类型 - 1:采购 -1:销售
+	CONTRACTNO        string  `json:"contractno"  xorm:"'CONTRACTNO'"`               // 现货合同编号
+	CONTRACTTYPE      int32   `json:"contracttype"  xorm:"'CONTRACTTYPE'"`           // 现货合同类型 - 1:采购 -1:销售
 	USERID            int64   `json:"userid"  xorm:"'USERID'"`                       // 机构ID
 	BUYUSERID         int64   `json:"buyuserid"  xorm:"'BUYUSERID'"`                 // 采购方ID
 	BUYUSERName       string  `json:"buyusername"  xorm:"'BUYUSERName'"`             // 采购方名称
@@ -27,7 +27,7 @@ type ErmcpSpotContractModel struct {
 	SELLUSERNAME      string  `json:"sellusername"  xorm:"'SELLUSERNAME'"`           // 销售方名称
 	DELIVERYGOODSID   int32   `json:"deliverygoodsid"  xorm:"'DELIVERYGOODSID'"`     // 现货品种ID
 	WRSTANDARDID      int32   `json:"wrstandardid"  xorm:"'wrstandardid'"`           // 现货商品ID
-	WRSTANDARDNAME    string  `json:"wrstandardname"  xorm:"'WRSTANDARDNAME'"`       // [现货商品]现货商品名称
+	WRSTANDARDNAME    string  `json:"wrstandardname"  xorm:"'WRSTANDARDNAME'"`       // 现货商品名称
 	WRSTANDARDCODE    string  `json:"wrstandardcode"  xorm:"'WRSTANDARDCODE'"`       // 现货商品代码
 	DELIVERYGOODSCODE string  `json:"deliverygoodscode"  xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码
 	DELIVERYGOODSNAME string  `json:"deliverygoodsname"  xorm:"'DELIVERYGOODSNAME'"` // 现货品种名称
@@ -35,7 +35,7 @@ type ErmcpSpotContractModel struct {
 	CONVERTFACTOR     float64 `json:"convertfactor"  xorm:"'CONVERTFACTOR'"`         // 标仓系数
 	SPOTGOODSDESC     string  `json:"spotgoodsdesc"  xorm:"'SPOTGOODSDESC'"`         // 商品型号
 	PRICETYPE         int32   `json:"pricetype"  xorm:"'PRICETYPE'"`                 // 定价类型 - 1:一口价 2:点价 3:暂定价
-	QTY               float64 `json:"qty"  xorm:"'QTY'"`                             // [合同数量]数量
+	QTY               float64 `json:"qty"  xorm:"'QTY'"`                             // 数量
 	PRICE             float64 `json:"price"  xorm:"'PRICE'"`                         // 价格\暂定价 [1:一口价、3:暂定价]
 	AMOUNT            float64 `json:"amount"  xorm:"'AMOUNT'"`                       // 金额 [1:一口价、3:暂定价]
 	DELIVERYSTARTDATE string  `json:"deliverystartdate"  xorm:"'DELIVERYSTARTDATE'"` // 交收期(开始)
@@ -60,18 +60,6 @@ type ErmcpSpotContractModel struct {
 	BRANDNAME         string  `json:"brandname"  xorm:"'brandname'"`                 // 品牌名称
 	MODELNAME         string  `json:"modelname"  xorm:"'modelname'"`                 // 型号名称
 	ATTACHMENT        string  `json:"attachment"  xorm:"'ATTACHMENT'"`               // 附件
-	PRICEDQTY         float64 `json:"pricedqty"  xorm:"PRICEDQTY"`                   // 已定价量
-	PRICEDAMOUNT      float64 `json:"pricedamount"  xorm:"PRICEDAMOUNT"`             // 已定价金额 = (点价价格+升贴水) * 数量
-	SPOTAMOUNT        float64 `json:"spotamount"  xorm:"SPOTAMOUNT"`                 // 合同现货金额 [不含升贴水]
-	TRADEUSERID       int64   `json:"tradeuserid"  xorm:"TRADEUSERID"`               // 交易用户ID
-	ISRELATED         int32   `json:"isrelated"  xorm:"ISRELATED"`                   // 是否已关联计划项目 - 0:否 1:是
-	ISRELATED2        int32   `json:"isrelated2"  xorm:"ISRELATED2"`                 // 是否已关联现货项目 - 0:否 1:是
-
-	AccountName string `json:"accountName" xorm:"ACCOUNTNAME"` // 套期主体
-
-	UNPRICEDQTY  float64 `json:"unpricedqty" xorm:"UNPRICEDQTY"`   // 未定价量 = 合同数量 - 已定价量
-	AVGPRICE     float64 `json:"avgprice" xorm:"AVGPRICE"`         // 定价均价 = 已定价金额 / 已定价量
-	SPOTAVGPRICE float64 `json:"spotavgprice" xorm:"SPOTAVGPRICE"` // 现货均价 = 合同现货金额 / 已定价量
 }
 
 func (r *ErmcpSpotContractModel) buildSql(nQueryType int32) string {
@@ -118,10 +106,6 @@ func (r *ErmcpSpotContractModel) buildSql(nQueryType int32) string {
 		"       e.Enumdicname," +
 		"       w.wrstandardname," +
 		"       w.wrstandardcode" +
-		"       (t.QTY - t.PRICEDQTY) UNPRICEDQTY" +
-		"       DECODE(t.PRICEDQTY, 0, 0, t.PRICEDAMOUNT/t.PRICEDQTY) AVGPRICE" +
-		"       DECODE(t.PRICEDQTY, 0, 0, t.SPOTAMOUNT/t.PRICEDQTY) SPOTAVGPRICE" +
-		"       ua.ACCOUNTNAME," +
 		"  FROM ERMCP_SPOTCONTRACT t" +
 		"  left join useraccount u1" +
 		"    on t.buyuserid = u1.userid" +
@@ -138,8 +122,6 @@ func (r *ErmcpSpotContractModel) buildSql(nQueryType int32) string {
 		"  left join enumdicitem e" +
 		"    on w.unitid = e.enumitemname" +
 		"   and e.enumdiccode = 'goodsunit'" +
-		"  left join useraccount ua" +
-		"    on ua.userid = t.tradeuserid" +
 		" where t.contractstatus in (%v)" +
 		"   and t.userid = %v"
 

+ 275 - 28
models/ermcp8.go

@@ -1,7 +1,9 @@
 package models
 
 import (
+	"fmt"
 	"mtp2_if/db"
+	"mtp2_if/logger"
 	"mtp2_if/utils"
 	"time"
 )
@@ -279,9 +281,9 @@ type Ermcp2hedgeditem struct {
 	FutureHedgePLChange float64 `json:"futurehedgeplchange" xorm:"FUTUREHEDGEPLCHANGE"` // 期货实际损益变动
 	FuturePLChange      float64 `json:"futureplchange" xorm:"FUTUREPLCHANGE"`           // 期货套期损益变动
 
-	Wrstandardname string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 商品名称
-	EnumdicName    string `json:"enumdicname"  xorm:"'ENUMDICNAME'"`      // 单位
-	AccountName    string `json:"accountName" xorm:"ACCOUNTNAME"`         // 套期主体
+	Wrstandardname string `json:"wrstandardname" xorm:"WRSTANDARDNAME"` // 商品名称
+	EnumdicName    string `json:"enumdicname"  xorm:"ENUMDICNAME"`      // 单位
+	AccountName    string `json:"accountName" xorm:"ACCOUNTNAME"`       // 套期主体
 
 	MiddleGoodsList []Ermcp2himiddlegoods `json:"middlegoodslist"` // 套期商品列表
 
@@ -417,8 +419,8 @@ type Ermcp2himiddlegoods struct {
 	CREATETIME       time.Time `json:"-"  xorm:"CREATETIME"`                                   // 创建时间
 	UPDATETIME       time.Time `json:"-"  xorm:"UPDATETIME"`                                   // 更新时间
 
-	Middlegoodsname string `json:"middlegoodsname"  xorm:"'MIDDLEGOODSNAME'"` // 套保商品名称
-	Middlegoodscode string `json:"middlegoodscode"  xorm:"'MIDDLEGOODSCODE'"` // 套保商品代码
+	Middlegoodsname string `json:"middlegoodsname"  xorm:"MIDDLEGOODSNAME"` // 套保商品名称
+	Middlegoodscode string `json:"middlegoodscode"  xorm:"MIDDLEGOODSCODE"` // 套保商品代码
 }
 
 // TableName is ERMCP2_HIMIDDLEGOODS
@@ -484,9 +486,9 @@ type Ermcpjrlinkpos struct {
 	TODAYFUTURECLOSEPL  float64   `json:"todayfutureclosepl"  xorm:"TODAYFUTURECLOSEPL"`                                // 今日平仓盈亏
 	RECKONPL            float64   `json:"reckonpl"  xorm:"RECKONPL"`                                                    // 总盈亏(平仓盈亏 + 结算盈亏 - 手续费)
 
-	Middlegoodsname string  `json:"middlegoodsname" xorm:"'MIDDLEGOODSNAME'"` // 套保商品名称
-	Middlegoodscode string  `json:"middlegoodscode" xorm:"'MIDDLEGOODSCODE'"` // 套保商品代码
-	FUTUREHEDGEQTY  float64 `json:"futurehedgeqty" xorm:"FUTUREHEDGEQTY"`     // 期货套期量
+	Middlegoodsname string  `json:"middlegoodsname" xorm:"MIDDLEGOODSNAME"` // 套保商品名称
+	Middlegoodscode string  `json:"middlegoodscode" xorm:"MIDDLEGOODSCODE"` // 套保商品代码
+	FUTUREHEDGEQTY  float64 `json:"futurehedgeqty" xorm:"FUTUREHEDGEQTY"`   // 期货套期量
 
 	AVERAGEPRICE float64 `json:"averageprice" xorm:"AVERAGEPRICE"` // 持仓均价 (TotalBuyHoldAmount - TotalSellHoldAmount) / NetQty
 }
@@ -560,9 +562,9 @@ type Ermcp2hedgeditemspot struct {
 	TRADEUSERID           int64     `json:"tradeuserid"  xorm:"TRADEUSERID"`                                          // 交易用户ID
 	AREAUSERID            int64     `json:"areauserid"  xorm:"AREAUSERID"`                                            // 企业ID
 
-	Wrstandardname string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 现货商品
-	EnumdicName    string `json:"enumdicname"  xorm:"'ENUMDICNAME'"`      // 单位
-	Hedgeplanno    string `json:"hedgeplanno"  xorm:"'HEDGEPLANNO'"`      // 计划编号
+	Wrstandardname string `json:"wrstandardname" xorm:"WRSTANDARDNAME"` // 现货商品
+	EnumdicName    string `json:"enumdicname"  xorm:"ENUMDICNAME"`      // 单位
+	Hedgeplanno    string `json:"hedgeplanno"  xorm:"HEDGEPLANNO"`      // 计划编号
 }
 
 // TableName is ERMCP2_HEDGEDITEMSPOT
@@ -633,11 +635,11 @@ type Ermcp2hedgeditemspotDetail struct {
 	TRADEUSERID           int64     `json:"tradeuserid"  xorm:"TRADEUSERID"`                                          // 交易用户ID
 	AREAUSERID            int64     `json:"areauserid"  xorm:"AREAUSERID"`                                            // 企业ID
 
-	Wrstandardname string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 现货商品
-	EnumdicName    string `json:"enumdicname"  xorm:"'ENUMDICNAME'"`      // 单位
-	AccountName    string `json:"accountName" xorm:"ACCOUNTNAME"`         // 对手方
-	BRANDNAME      string `json:"brandname"  xorm:"'BRANDNAME'"`          // 品牌
-	CONTRACTNO     string `json:"contractno"  xorm:"'CONTRACTNO'"`        // 合同编号
+	Wrstandardname string `json:"wrstandardname" xorm:"WRSTANDARDNAME"` // 现货商品
+	EnumdicName    string `json:"enumdicname"  xorm:"ENUMDICNAME"`      // 单位
+	AccountName    string `json:"accountName" xorm:"ACCOUNTNAME"`       // 对手方
+	BRANDNAME      string `json:"brandname"  xorm:"BRANDNAME"`          // 品牌
+	CONTRACTNO     string `json:"contractno"  xorm:"CONTRACTNO"`        // 合同编号
 }
 
 func (r *Ermcp2hedgeditemspotDetail) calc() {
@@ -845,10 +847,10 @@ func (r *InternalUncorrelatedTradeDetail) buildSql() string {
 
 	sqlId.FormatParam(r.USERID)
 	if r.BEGINDATE != "" {
-		sqlId.JoinFormat(" and to_char(ept.tradetime, 'yyyymmdd') >= '%v'", 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.JoinFormat(" and to_char(ept.tradetime, 'yyyymmdd') <= '%v", r.ENDDATE)
 	}
 	sqlId.AndLike("g.goodscode", r.GOODSCODE)
 	sqlId.AndLike("g.goodsname", r.GOODSNAME)
@@ -877,12 +879,12 @@ func (r *InternalUncorrelatedTradeDetail) GetDataEx() (interface{}, error) {
 // InternalEnableTradeDetail 内部成交单可关联项目
 type InternalEnableTradeDetail struct {
 	HEDGEDITEMNUM     string  `json:"hedgeditemnum"  xorm:"HEDGEDITEMNUM"`                                // 项目编号
-	Deliverygoodsid   int32   `json:"deliverygoodsid"  xorm:"'DELIVERYGOODSID'"`                          // 现货品种ID(SEQ_DELIVERYGOODS)
-	Deliverygoodscode string  `json:"deliverygoodscode"  xorm:"'DELIVERYGOODSCODE'"`                      // 现货品种代码
-	Deliverygoodsname string  `json:"deliverygoodsname"  xorm:"'DELIVERYGOODSNAME'"`                      // 现货品种名称
-	Wrstandardid      int64   `json:"wrstandardid"  xorm:"'WRSTANDARDID'"`                                // 现货品类ID(SEQ_WRSTANDARD)
-	Wrstandardcode    string  `json:"wrstandardcode"  xorm:"'WRSTANDARDCODE'"`                            // 现货品类代码
-	Wrstandardname    string  `json:"wrstandardname"  xorm:"'WRSTANDARDNAME'"`                            // 现货品类名称
+	Deliverygoodsid   int32   `json:"deliverygoodsid"  xorm:"DELIVERYGOODSID"`                            // 现货品种ID(SEQ_DELIVERYGOODS)
+	Deliverygoodscode string  `json:"deliverygoodscode"  xorm:"DELIVERYGOODSCODE"`                        // 现货品种代码
+	Deliverygoodsname string  `json:"deliverygoodsname"  xorm:"DELIVERYGOODSNAME"`                        // 现货品种名称
+	Wrstandardid      int64   `json:"wrstandardid"  xorm:"WRSTANDARDID"`                                  // 现货品类ID(SEQ_WRSTANDARD)
+	Wrstandardcode    string  `json:"wrstandardcode"  xorm:"WRSTANDARDCODE"`                              // 现货品类代码
+	Wrstandardname    string  `json:"wrstandardname"  xorm:"WRSTANDARDNAME"`                              // 现货品类名称
 	UNEXESPOTQTY      float64 `json:"unexespotqty"  xorm:"UNEXESPOTQTY"`                                  // 未执行现货量
 	UNEXEHEDGEQTY     float64 `json:"unexehedgeqty"  xorm:"UNEXEHEDGEQTY"`                                // 未执行套期量 = 未执行现货量*折算系数* (1/(1+增值税)) * 套期比例(项目上)
 	FUTUREHEDGEQTY    float64 `json:"futurehedgeqty"  xorm:"FUTUREHEDGEQTY"`                              // [已关联数量]期货持仓套期量
@@ -945,8 +947,8 @@ type Ermcp8HedgeditemReport struct {
 	HEDGEDITEMSTATUS    int32     `json:"hedgeditemstatus"  xorm:"HEDGEDITEMSTATUS" form:"hedgeditemstatus"` // 项目状态 - 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回
 	HEDGEDITEMNUM       string    `json:"hedgeditemnum"  xorm:"HEDGEDITEMNUM" form:"hedgeditemnum"`          // 项目编号,模糊查询
 	WRSTANDARDID        int64     `json:"wrstandardid"  xorm:"WRSTANDARDID" form:"wrstandardid"`             // 现货商品ID
-	Wrstandardcode      string    `json:"wrstandardcode"  xorm:"'WRSTANDARDCODE'"`                           // 现货品类代码
-	Wrstandardname      string    `json:"wrstandardname"  xorm:"'WRSTANDARDNAME'"`                           // [现货商品]现货品类名称
+	Wrstandardcode      string    `json:"wrstandardcode"  xorm:"WRSTANDARDCODE"`                             // 现货品类代码
+	Wrstandardname      string    `json:"wrstandardname"  xorm:"WRSTANDARDNAME"`                             // [现货商品]现货品类名称
 	HEDGEQTY            float64   `json:"hedgeqty"  xorm:"HEDGEQTY"`                                         // [套期数量]套期现货量
 	ORIAVGPRICE         float64   `json:"oriavgprice"  xorm:"ORIAVGPRICE"`                                   // [期初价]期初市场均价 = 套期市价总额 / 套期现货量
 	HEDGEAMOUNT         float64   `json:"hedgeamount"  xorm:"HEDGEAMOUNT"`                                   // [套期现货金额]套期市价总额
@@ -970,8 +972,8 @@ type Ermcp8HedgeditemReport struct {
 	ORISPOTPL           float64   `json:"orispotpl"  xorm:"ORISPOTPL"`                                       // 期初现货套期损益
 	ORIFUTUREPL         float64   `json:"orifuturepl"  xorm:"ORIFUTUREPL"`                                   // 期初期货套期损益
 
-	EnumdicName string `json:"enumdicname"  xorm:"'ENUMDICNAME'"` // 单位
-	AccountName string `json:"accountName" xorm:"ACCOUNTNAME"`    // 套期主体
+	EnumdicName string `json:"enumdicname"  xorm:"ENUMDICNAME"` // 单位
+	AccountName string `json:"accountName" xorm:"ACCOUNTNAME"`  // 套期主体
 
 	USERID    int64  `form:"userid" binding:"required"`    // 用户ID
 	CYCLETYPE int32  `form:"cycletype"`                    // 周期类型 - 0:日 1:月 2:季 3:年 4:周 5:全报表【原值】
@@ -1101,3 +1103,248 @@ func (r *Ermcp8HedgeditemReport) GetDataEx() (interface{}, error) {
 	}
 	return sData, nil
 }
+
+// 查询现货合同
+type QrySpotContractExReq struct {
+	USERID       int64  `form:"userid" binding:"required"` // 用户ID
+	PRICETYPE    int32  `form:"pricetype"`                 // 定价类型 - 1:一口价 2:点价 3:暂定价
+	CONTRACTNO   string `form:"contractno"`                // 合同编号, 模拟查询
+	CUSTOMERNAME string `form:"customername"`              // 对手方, 模拟查询
+	CONTRACTTYPE int32  `form:"contracttype"`              // 合同类型 - 1:采购 -1:销售
+}
+
+// ErmcpSpotContractModelEx 现货合同结构(对应现货合同菜单)
+type ErmcpSpotContractModelEx struct {
+	SPOTCONTRACTID    string  `json:"spotcontractid"  xorm:"SPOTCONTRACTID"`       // 现货合同ID(602+Unix秒时间戳(10位)+xxxxxx)
+	CONTRACTNO        string  `json:"contractno"  xorm:"CONTRACTNO"`               // [合同编号]现货合同编号
+	CONTRACTTYPE      int32   `json:"contracttype"  xorm:"CONTRACTTYPE"`           // [合同类型]现货合同类型 - 1:采购 -1:销售
+	USERID            int64   `json:"userid"  xorm:"USERID"`                       // 机构ID
+	BUYUSERID         int64   `json:"buyuserid"  xorm:"BUYUSERID"`                 // 采购方ID
+	BUYUSERName       string  `json:"buyusername"  xorm:"BUYUSERName"`             // 采购方名称
+	SELLUSERID        int64   `json:"selluserid"  xorm:"SELLUSERID"`               // 销售方ID
+	SELLUSERNAME      string  `json:"sellusername"  xorm:"SELLUSERNAME"`           // 销售方名称
+	DELIVERYGOODSID   int32   `json:"deliverygoodsid"  xorm:"DELIVERYGOODSID"`     // 现货品种ID
+	WRSTANDARDID      int32   `json:"wrstandardid"  xorm:"wrstandardid"`           // 现货商品ID
+	WRSTANDARDNAME    string  `json:"wrstandardname"  xorm:"WRSTANDARDNAME"`       // [现货商品]现货商品名称
+	WRSTANDARDCODE    string  `json:"wrstandardcode"  xorm:"WRSTANDARDCODE"`       // 现货商品代码
+	DELIVERYGOODSCODE string  `json:"deliverygoodscode"  xorm:"DELIVERYGOODSCODE"` // 现货品种代码
+	DELIVERYGOODSNAME string  `json:"deliverygoodsname"  xorm:"DELIVERYGOODSNAME"` // 现货品种名称
+	PRODUCTTYPE       int32   `json:"producttype"  xorm:"PRODUCTTYPE"`             // 产品类型 - 1:标准仓单 2:等标 3:非标
+	CONVERTFACTOR     float64 `json:"convertfactor"  xorm:"CONVERTFACTOR"`         // 标仓系数
+	SPOTGOODSDESC     string  `json:"spotgoodsdesc"  xorm:"SPOTGOODSDESC"`         // 商品型号
+	PRICETYPE         int32   `json:"pricetype"  xorm:"PRICETYPE"`                 // 定价类型 - 1:一口价 2:点价 3:暂定价
+	QTY               float64 `json:"qty"  xorm:"QTY"`                             // [合同数量]数量
+	PRICE             float64 `json:"price"  xorm:"PRICE"`                         // 价格\暂定价 [1:一口价、3:暂定价]
+	AMOUNT            float64 `json:"amount"  xorm:"AMOUNT"`                       // 金额 [1:一口价、3:暂定价]
+	DELIVERYSTARTDATE string  `json:"deliverystartdate"  xorm:"DELIVERYSTARTDATE"` // 交收期(开始)
+	DELIVERYENDDATE   string  `json:"deliveryenddate"  xorm:"DELIVERYENDDATE"`     // 交收期(结束)
+	GOODSID           int32   `json:"goodsid"  xorm:"GOODSID"`                     // 点价合约ID - 0:为现货,其它为期货商品合约ID [2:点价 3:暂定价]
+	GOODSCODE         string  `json:"goodscode"  xorm:"GOODSCODE"`                 // 点价合约代码
+	GOODSNAME         string  `json:"goodsname"  xorm:"GOODSNAME"`                 // 点价商品名称
+	PRICEMOVE         float64 `json:"pricemove"  xorm:"PRICEMOVE"`                 // 升贴水 [2:点价 3:暂定价]
+	STARTDATE         string  `json:"startdate"  xorm:"STARTDATE"`                 // 点价开始日期 [2:点价 3:暂定价]
+	ENDDATE           string  `json:"enddate"  xorm:"ENDDATE"`                     // 点价结束日期 [2:点价 3:暂定价]
+	MARGIN            float64 `json:"margin"  xorm:"MARGIN"`                       // 当前保证金
+	CONTRACTMARGIN    float64 `json:"contractmargin"  xorm:"CONTRACTMARGIN"`       // 合同保证金
+	EnumdicName       string  `json:"enumdicname"  xorm:"ENUMDICNAME"`             // 单位名称
+	CONTRACCTSTATUS   int32   `json:"contracctstatus"  xorm:"CONTRACTSTATUS"`      // 合同状态 - 0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回
+	Remark            string  `json:"remark"  xorm:"Remark"`                       // 备注
+	AUDITREMARK       string  `json:"auditremark"  xorm:"AUDITREMARK"`             // 审核意见
+	AUDITTIME         string  `json:"audittime"  xorm:"AUDITTIME"`                 // 审核时间
+	CREATETIME        string  `json:"createtime"  xorm:"CREATETIME"`               // 创建时间
+	UPDATETIME        string  `json:"updatetime"  xorm:"UPDATETIME"`               // 更新时间
+	SPOTGOODSMODELID  int32   `json:"spotgoodsmodelid"  xorm:"SPOTGOODSMODELID"`   // 现货型号ID
+	SPOTGOODSBRANDID  int32   `json:"spotgoodsbrandid"  xorm:"SPOTGOODSBRANDID"`   // 现货品牌ID
+	BRANDNAME         string  `json:"brandname"  xorm:"brandname"`                 // 品牌名称
+	MODELNAME         string  `json:"modelname"  xorm:"modelname"`                 // 型号名称
+	ATTACHMENT        string  `json:"attachment"  xorm:"ATTACHMENT"`               // 附件
+	PRICEDQTY         float64 `json:"pricedqty"  xorm:"PRICEDQTY"`                 // 已定价量
+	PRICEDAMOUNT      float64 `json:"pricedamount"  xorm:"PRICEDAMOUNT"`           // 已定价金额 = (点价价格+升贴水) * 数量
+	SPOTAMOUNT        float64 `json:"spotamount"  xorm:"SPOTAMOUNT"`               // 合同现货金额 [不含升贴水]
+	TRADEUSERID       int64   `json:"tradeuserid"  xorm:"TRADEUSERID"`             // 交易用户ID
+	CUSTOMERUSERID    int64   `json:"customeruserid"  xorm:"CUSTOMERUSERID"`       // 客户ID
+	ISRELATED         int32   `json:"isrelated"  xorm:"ISRELATED"`                 // 是否已关联计划项目 - 0:否 1:是
+	ISRELATED2        int32   `json:"isrelated2"  xorm:"ISRELATED2"`               // 是否已关联现货项目 - 0:否 1:是
+
+	ACCOUNTNAME  string `json:"accountName" xorm:"ACCOUNTNAME"`   // 套期主体
+	CUSTOMERNAME string `json:"customername" xorm:"CUSTOMERNAME"` // 对手方
+
+	UNPRICEDQTY  float64 `json:"unpricedqty" xorm:"UNPRICEDQTY"`   // 未定价量 = 合同数量 - 已定价量
+	AVGPRICE     float64 `json:"avgprice" xorm:"AVGPRICE"`         // 定价均价 = 已定价金额 / 已定价量
+	SPOTAVGPRICE float64 `json:"spotavgprice" xorm:"SPOTAVGPRICE"` // 现货均价 = 合同现货金额 / 已定价量
+}
+
+func (r *ErmcpSpotContractModelEx) buildSql(req QrySpotContractExReq) string {
+	str := `
+	SELECT to_char(t.SPOTCONTRACTID) SPOTCONTRACTID,
+		t.CONTRACTNO,
+		t.CONTRACTTYPE,
+		t.USERID,
+		t.BUYUSERID,
+		t.SELLUSERID,
+		t.DELIVERYGOODSID,
+		t.wrstandardid,
+		t.PRODUCTTYPE,
+		w.CONVERTFACTOR,
+		t.SPOTGOODSDESC,
+		t.PRICETYPE,
+		t.QTY,
+		t.PRICE,
+		t.AMOUNT,
+		to_char(t.DELIVERYSTARTDATE, 'yyyy-mm-dd hh24:mi:ss') DELIVERYSTARTDATE,
+		to_char(t.DELIVERYENDDATE, 'yyyy-mm-dd hh24:mi:ss') DELIVERYENDDATE,
+		t.GOODSID,
+		t.PRICEMOVE,
+		to_char(t.STARTDATE, 'yyyy-mm-dd hh24:mi:ss') STARTDATE,
+		to_char(t.ENDDATE, 'yyyy-mm-dd hh24:mi:ss') ENDDATE,
+		t.MARGIN,
+		t.contractmargin,
+		t.remark,
+		t.pointdesc,
+		t.auditremark,
+		to_char(t.contractattachment) attachment,
+		t.contractstatus,
+		t.SPOTGOODSBRANDID,
+		to_char(t.audittime, 'yyyy-mm-dd hh24:mi:ss') audittime,
+		to_char(t.createtime, 'yyyy-mm-dd hh24:mi:ss') createtime,
+		to_char(t.updatetime, 'yyyy-mm-dd hh24:mi:ss') updatetime,
+		g.deliverygoodscode,
+		g.deliverygoodsname,
+		g2.goodscode,
+		g2.goodsname,
+		gb.dgfactoryitemvalue brandname,
+		w.wrstandardname,
+		w.wrstandardcode,
+		w.vatrate,
+		w.unitid,
+		t.tradeuserid,
+		t.saleuserid,
+		t.meruserid,
+		t.currencyid,
+		to_char(t.accountid) accountid,
+		t.biztype,
+		to_char(t.subjectid) subjectid,
+		b.subjectname,
+		(t.QTY - t.PRICEDQTY) UNPRICEDQTY,
+		DECODE(t.PRICEDQTY, 0, 0, t.PRICEDAMOUNT/t.PRICEDQTY) AVGPRICE,
+		DECODE(t.PRICEDQTY, 0, 0, t.SPOTAMOUNT/t.PRICEDQTY) SPOTAVGPRICE,
+		ua.ACCOUNTNAME,
+		uc.ACCOUNTNAME CUSTOMERNAME
+	FROM ERMCP_SPOTCONTRACT t
+	left join ermcp_pa_areasubject b on t.subjectid=b.subjectid
+	left join deliverygoods g
+	on t.deliverygoodsid = g.deliverygoodsid
+	left join goods g2
+	on t.goodsid = g2.goodsid
+	left join DGFACTORYITEM gb
+	on t.spotgoodsbrandid = gb.dgfactoryitemid
+	left join wrstandard w
+	on t.wrstandardid = w.wrstandardid
+	left join loginaccount l
+	on t.applyid = l.loginid
+	left join useraccount ua
+		on ua.userid = t.tradeuserid
+	left join useraccount uc
+		on uc.userid = t.CUSTOMERUSERID
+	where t.contractstatus = 2 and t.ISRELATED = 0 and t.ISRELATED2 = 0
+		and (t.userid = %v or t.tradeuserid = %v)
+	`
+
+	// "SELECT to_char(t.SPOTCONTRACTID) SPOTCONTRACTID," +
+	// 	"       t.CONTRACTNO," +
+	// 	"       t.CONTRACTTYPE," +
+	// 	"       t.USERID," +
+	// 	"       t.BUYUSERID," +
+	// 	"       t.SELLUSERID," +
+	// 	"       t.DELIVERYGOODSID," +
+	// 	"       t.wrstandardid," +
+	// 	"       t.PRODUCTTYPE," +
+	// 	"       t.CONVERTFACTOR," +
+	// 	"       t.SPOTGOODSDESC," +
+	// 	"       t.PRICETYPE," +
+	// 	"       t.QTY," +
+	// 	"       t.PRICE," +
+	// 	"       t.AMOUNT," +
+	// 	"       to_char(t.DELIVERYSTARTDATE, 'yyyy-mm-dd hh24:mi:ss') DELIVERYSTARTDATE," +
+	// 	"       to_char(t.DELIVERYENDDATE, 'yyyy-mm-dd hh24:mi:ss') DELIVERYENDDATE," +
+	// 	"       t.GOODSID," +
+	// 	"       t.PRICEMOVE," +
+	// 	"       to_char(t.STARTDATE, 'yyyy-mm-dd hh24:mi:ss') STARTDATE," +
+	// 	"       to_char(t.ENDDATE, 'yyyy-mm-dd hh24:mi:ss') ENDDATE," +
+	// 	"       t.MARGIN," +
+	// 	"       t.contractmargin," +
+	// 	"       t.remark," +
+	// 	"       t.auditremark," +
+	// 	"       to_char(t.contractattachment) attachment," +
+	// 	"       t.contractstatus," +
+	// 	"       t.SPOTGOODSMODELID," +
+	// 	"       t.SPOTGOODSBRANDID," +
+	// 	"       to_char(t.audittime, 'yyyy-mm-dd hh24:mi:ss') audittime," +
+	// 	"       to_char(t.createtime, 'yyyy-mm-dd hh24:mi:ss') createtime," +
+	// 	"       to_char(t.updatetime, 'yyyy-mm-dd hh24:mi:ss') updatetime," +
+	// 	"       u1.accountname BuyUserName," +
+	// 	"       u2.accountname SellUserName," +
+	// 	"       g.deliverygoodscode," +
+	// 	"       g.deliverygoodsname," +
+	// 	"       g2.goodscode," +
+	// 	"       g2.goodsname," +
+	// 	"       gb.brandname," +
+	// 	"       gm.modelname," +
+	// 	"       e.Enumdicname," +
+	// 	"       w.wrstandardname," +
+	// 	"       w.wrstandardcode," +
+	// 	"       (t.QTY - t.PRICEDQTY) UNPRICEDQTY," +
+	// 	"       DECODE(t.PRICEDQTY, 0, 0, t.PRICEDAMOUNT/t.PRICEDQTY) AVGPRICE," +
+	// 	"       DECODE(t.PRICEDQTY, 0, 0, t.SPOTAMOUNT/t.PRICEDQTY) SPOTAVGPRICE," +
+	// 	"       ua.ACCOUNTNAME," +
+	// 	"       uc.ACCOUNTNAME CUSTOMERNAME" +
+	// 	"  FROM ERMCP_SPOTCONTRACT t" +
+	// 	"  left join useraccount u1" +
+	// 	"    on t.buyuserid = u1.userid" +
+	// 	"  left join useraccount u2" +
+	// 	"    on t.selluserid = u2.userid" +
+	// 	"  left join deliverygoods g" +
+	// 	"    on t.deliverygoodsid = g.deliverygoodsid" +
+	// 	"  left join goods g2" +
+	// 	"    on t.goodsid = g2.goodsid" +
+	// 	"    left join spotgoodsbrand gb on t.spotgoodsbrandid=gb.brandid" +
+	// 	"    left join spotgoodsmodel gm on t.spotgoodsmodelid=gm.modelid" +
+	// 	"  left join wrstandard w" +
+	// 	"    on t.wrstandardid = w.wrstandardid" +
+	// 	"  left join enumdicitem e" +
+	// 	"    on w.unitid = e.enumitemname" +
+	// 	"   and e.enumdiccode = 'goodsunit'" +
+
+	str = fmt.Sprintf(str, req.USERID, req.USERID)
+	if req.PRICETYPE > 0 {
+		str += " and t.PRICETYPE = %v"
+		str = fmt.Sprintf(str, req.PRICETYPE)
+	}
+	if len(req.CONTRACTNO) > 0 {
+		str += " and t.CONTRACTNO like '%%%s%%'"
+		str = fmt.Sprintf(str, req.CONTRACTNO)
+	}
+	if len(req.CUSTOMERNAME) > 0 {
+		str += " and uc.ACCOUNTNAME like '%%%s%%'"
+		str = fmt.Sprintf(str, req.CUSTOMERNAME)
+	}
+	if req.CONTRACTTYPE > 0 {
+		str += " and t.CONTRACTTYPE = %v"
+		str = fmt.Sprintf(str, req.CONTRACTTYPE)
+	}
+	str += " order by t.audittime desc"
+
+	return str
+}
+
+// GetData 从数据库中查询现货合同
+func (r *ErmcpSpotContractModelEx) GetData(req QrySpotContractExReq) ([]ErmcpSpotContractModelEx, error) {
+	sData := make([]ErmcpSpotContractModelEx, 0)
+	e := db.GetEngine()
+	s := e.SQL(r.buildSql(req))
+	if err := s.Find(&sData); err != nil {
+		logger.GetLogger().Errorf("ermcp query fail:%v", err)
+		return sData, err
+	}
+	return sData, nil
+}

+ 1 - 0
routers/router.go

@@ -495,6 +495,7 @@ func InitRouter() *gin.Engine {
 		ermcp8R.GET("/QueryInternalUncorrelatedTradeDetail", ermcp8.QueryInternalUncorrelatedTradeDetail)
 		ermcp8R.GET("/QueryInternalEnableTradeDetail", ermcp8.QueryInternalEnableTradeDetail)
 		ermcp8R.GET("/QueryErmcp8HedgeditemReport", ermcp8.QueryErmcp8HedgeditemReport)
+		ermcp8R.GET("/QueryUnLinkSpotContract", ermcp8.QueryUnLinkSpotContract)
 	}
 
 	// ****************************大连千海金******************************