Sfoglia il codice sorgente

1.增加 查财务报表明细报表
2.增加 查损益汇总明细报表
3.实时敞口增加字段(#95031)
4.现货合同明细增加品牌名称、现货品名称

zou.yingbin 4 anni fa
parent
commit
898b0591b7

+ 32 - 8
controllers/ermcp3/qryErmcp3Report.go

@@ -81,7 +81,7 @@ func (r *CycleTypeCheck) Check() bool {
 
 // QryReportReq 查报表请求
 // @Param userid query int true "用户ID"
-// @Param querytype query int true "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日])"
+// @Param querytype query int true "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日]) 4-日报表明细"
 // @Param tradedate query string false "交易日(格式yyyymmdd)"
 // @Param cycletype query int false "周期类型 - 1:月 2:季 3:年 4:周 5:全报表【原值】"
 // @Param cycletime query string false "周期时间 月(YYYYMM)  季(YYYYQ) 年(YYYY) 周(YYYYIW) 全(0)【原值】"
@@ -101,13 +101,15 @@ type QryReportReq struct {
 func (r *QryReportReq) Check() bool {
 	// 参数检查
 	switch r.QUERYTYPE {
-	case 1:
+	case 1, 4:
 		return QueryDate(r.TRADEDATE).IsNumberic(1)
 	case 2:
 		switch r.CYCLETYPE {
-		case 1, 2, 3, 4, 5:
+		case 1, 2, 3, 5:
 			p := CycleTypeCheck{CYCLETYPE: r.CYCLETYPE, CYCLETIME: r.CYCLETIME}
 			return p.Check()
+		case 4:
+			return QueryDate(r.CYCLETIME).IsNumberic(1)
 		default:
 			return false
 		}
@@ -199,7 +201,7 @@ func QryReportMonthSpotDetail(c *gin.Context) {
 // @Produce json
 // @Security ApiKeyAuth
 // @Param userid query int true "用户ID"
-// @Param querytype query int true "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日])"
+// @Param querytype query int true "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日]) 4-日报表明细"
 // @Param tradedate query string false "交易日(格式yyyymmdd)"
 // @Param cycletype query int false "周期类型 - 1:月 2:季 3:年 4:周 5:全报表【原值】"
 // @Param cycletime query string false "周期时间 月(YYYYMM)  季(YYYYQ) 年(YYYY) 周(YYYYIW) 全(0)【原值】"
@@ -297,12 +299,13 @@ func QryAreaSpotplReport(c *gin.Context) {
 // @Produce json
 // @Security ApiKeyAuth
 // @Param userid query int true "用户ID"
-// @Param querytype query int true "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日])"
+// @Param querytype query int true "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日]) 4-日报表明细"
 // @Param tradedate query string false "交易日(格式yyyymmdd)"
 // @Param cycletype query int false "周期类型 - 1:月 2:季 3:年 4:周 5:全报表【原值】"
 // @Param cycletime query string false "周期时间 月(YYYYMM)  季(YYYYQ) 年(YYYY) 周(YYYYIW) 全(0)【原值】"
 // @Param begindate query string false "开始交易日(格式yyyymmdd)"
 // @Param enddate query string false "结束交易日(格式yyyymmdd)"
+// @Param currencyid query int false "币种id(日报表明细)"
 // @Success 200 {array} models.Ermcp3FinanceReport
 // @Failure 500 {object} app.Response
 // @Router /Ermcp3/QryFinanceReport [get]
@@ -312,8 +315,18 @@ func QryFinanceReport(c *gin.Context) {
 	req := QryReportReq{}
 	a.DoBindReq(&req)
 	a.CheckParam(&req)
+	req2 := struct {
+		CURRENCYID int32 `form:"currencyid"` // 币种id
+	}{}
+	a.DoBindReq(&req2)
+	a.CheckParamF(func() bool {
+		if req.QUERYTYPE == 4 {
+			return req2.CURRENCYID > 0
+		}
+		return true
+	})
 	m := models.Ermcp3FinanceReport{AREAUSERID: req.USERID, QueryType: req.QUERYTYPE, RECKONDATE: req.TRADEDATE,
-		CYCLETYPE: req.CYCLETYPE, CYCLETIME: req.CYCLETIME, BeginDate: req.BEGINDATE, EndDate: req.ENDDATE}
+		CYCLETYPE: req.CYCLETYPE, CYCLETIME: req.CYCLETIME, BeginDate: req.BEGINDATE, EndDate: req.ENDDATE, CURRENCYID: req2.CURRENCYID}
 	a.DoGetDataI(&m)
 }
 
@@ -399,12 +412,13 @@ func QueryAreaStockReportDetail(c *gin.Context) {
 // @Produce json
 // @Security ApiKeyAuth
 // @Param userid query int true "用户ID"
-// @Param querytype query int true "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日])"
+// @Param querytype query int true "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日]) 4-日报表明细"
 // @Param tradedate query string false "交易日(格式yyyymmdd)"
 // @Param cycletype query int false "周期类型 - 1:月 2:季 3:年 4:周 5:全报表【原值】"
 // @Param cycletime query string false "周期时间 月(YYYYMM)  季(YYYYQ) 年(YYYY) 周(YYYYIW) 全(0)【原值】"
 // @Param begindate query string false "开始交易日(格式yyyymmdd)"
 // @Param enddate query string false "结束交易日(格式yyyymmdd)"
+// @Param currencyid query int false "币种id(日报表明细)"
 // @Success 200 {array} models.Ermcp3ArealSumPL
 // @Failure 500 {object} app.Response
 // @Router /Ermcp3/QryAreaSumPL [get]
@@ -414,7 +428,17 @@ func QryAreaSumPL(c *gin.Context) {
 	req := QryReportReq{}
 	a.DoBindReq(&req)
 	a.CheckParam(&req)
+	req2 := struct {
+		CURRENCYID int32 `form:"currencyid"` // 币种id
+	}{}
+	a.DoBindReq(&req2)
+	a.CheckParamF(func() bool {
+		if req.QUERYTYPE == 4 {
+			return req2.CURRENCYID > 0
+		}
+		return true
+	})
 	m := models.Ermcp3ArealSumPL{AREAUSERID: req.USERID, QueryType: req.QUERYTYPE, RECKONDATE: req.TRADEDATE,
-		CYCLETYPE: req.CYCLETYPE, CYCLETIME: req.CYCLETIME, BeginDate: req.BEGINDATE, EndDate: req.ENDDATE}
+		CYCLETYPE: req.CYCLETYPE, CYCLETIME: req.CYCLETIME, BeginDate: req.BEGINDATE, EndDate: req.ENDDATE, CURRENCYID: req2.CURRENCYID}
 	a.DoGetDataI(&m)
 }

+ 98 - 14
docs/docs.go

@@ -2717,7 +2717,7 @@ var doc = `{
                     },
                     {
                         "type": "integer",
-                        "description": "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日])",
+                        "description": "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日]) 4-日报表明细",
                         "name": "querytype",
                         "in": "query",
                         "required": true
@@ -2796,7 +2796,7 @@ var doc = `{
                     },
                     {
                         "type": "integer",
-                        "description": "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日])",
+                        "description": "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日]) 4-日报表明细",
                         "name": "querytype",
                         "in": "query",
                         "required": true
@@ -2875,7 +2875,7 @@ var doc = `{
                     },
                     {
                         "type": "integer",
-                        "description": "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日])",
+                        "description": "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日]) 4-日报表明细",
                         "name": "querytype",
                         "in": "query",
                         "required": true
@@ -2978,7 +2978,7 @@ var doc = `{
                     },
                     {
                         "type": "integer",
-                        "description": "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日])",
+                        "description": "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日]) 4-日报表明细",
                         "name": "querytype",
                         "in": "query",
                         "required": true
@@ -3012,6 +3012,12 @@ var doc = `{
                         "description": "结束交易日(格式yyyymmdd)",
                         "name": "enddate",
                         "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "币种id(日报表明细)",
+                        "name": "currencyid",
+                        "in": "query"
                     }
                 ],
                 "responses": {
@@ -3057,7 +3063,7 @@ var doc = `{
                     },
                     {
                         "type": "integer",
-                        "description": "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日])",
+                        "description": "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日]) 4-日报表明细",
                         "name": "querytype",
                         "in": "query",
                         "required": true
@@ -3091,6 +3097,12 @@ var doc = `{
                         "description": "结束交易日(格式yyyymmdd)",
                         "name": "enddate",
                         "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "币种id(日报表明细)",
+                        "name": "currencyid",
+                        "in": "query"
                     }
                 ],
                 "responses": {
@@ -12365,6 +12377,10 @@ var doc = `{
                     "description": "业务类型 1-套保 2-套利",
                     "type": "integer"
                 },
+                "brandname": {
+                    "description": "品牌名称",
+                    "type": "string"
+                },
                 "buyuserid": {
                     "description": "采购方id",
                     "type": "integer"
@@ -12389,10 +12405,18 @@ var doc = `{
                     "description": "今定价量",
                     "type": "number"
                 },
+                "deliverygoodscode": {
+                    "description": "现货商品代码",
+                    "type": "string"
+                },
                 "deliverygoodsid": {
                     "description": "现货商品id",
                     "type": "integer"
                 },
+                "deliverygoodsname": {
+                    "description": "现货商品名称",
+                    "type": "string"
+                },
                 "diffqty": {
                     "description": "套保品种今变动量",
                     "type": "number"
@@ -12556,7 +12580,7 @@ var doc = `{
                     "type": "number"
                 },
                 "contracttype": {
-                    "description": "现货合同类型 - 1:采购 -1:销售",
+                    "description": "计划类型 - 1:采购 -1:销售",
                     "type": "integer"
                 },
                 "convertratio": {
@@ -12583,6 +12607,10 @@ var doc = `{
                     "description": "套保计划编号",
                     "type": "string"
                 },
+                "hedgeplanstatus": {
+                    "description": "套保计划状态 -  0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回",
+                    "type": "integer"
+                },
                 "mgunitidname": {
                     "description": "单位名称(套保商品)",
                     "type": "string"
@@ -12724,7 +12752,7 @@ var doc = `{
                     "description": "套保品种ID",
                     "type": "integer"
                 },
-                "middlegoodsnam": {
+                "middlegoodsname": {
                     "description": "套保商品名称",
                     "type": "string"
                 },
@@ -12913,6 +12941,10 @@ var doc = `{
                     "description": "周期类型 - 1:月 2:季 3:年 4:周 5:全报表【原值】",
                     "type": "integer"
                 },
+                "deliverygoodsid": {
+                    "description": "现货品种ID",
+                    "type": "integer"
+                },
                 "reckondate": {
                     "description": "日照时期(yyyyMMdd)",
                     "type": "string"
@@ -12945,6 +12977,10 @@ var doc = `{
                     "description": "销售应收款额(应收货款额)",
                     "type": "number"
                 },
+                "spotgoodsbrandid": {
+                    "description": "现货品牌ID",
+                    "type": "integer"
+                },
                 "todaypaysum": {
                     "description": "今付款合计",
                     "type": "number"
@@ -12956,6 +12992,14 @@ var doc = `{
                 "updatetime": {
                     "description": "更新时间",
                     "type": "string"
+                },
+                "wrfactortypeid": {
+                    "description": "仓单要素类型ID(212+Unix秒时间戳(10位)+xxxxxx)",
+                    "type": "integer"
+                },
+                "wrstandardid": {
+                    "description": "现货商品ID",
+                    "type": "integer"
                 }
             }
         },
@@ -15068,7 +15112,7 @@ var doc = `{
                     "type": "string"
                 },
                 "MiddleGoodsHedgeRatio": {
-                    "description": "套保比例",
+                    "description": "套保比例",
                     "type": "number"
                 },
                 "MiddleGoodsID": {
@@ -15080,7 +15124,7 @@ var doc = `{
                     "type": "string"
                 },
                 "NeedHedgeExposoure": {
-                    "description": "应套保敞口",
+                    "description": "应套保敞口(套保敞口)",
                     "type": "number"
                 },
                 "NeedHedgeRatio": {
@@ -15128,7 +15172,7 @@ var doc = `{
                     "type": "number"
                 },
                 "TotalFutureQty": {
-                    "description": "期货量",
+                    "description": "期货量",
                     "type": "number"
                 },
                 "TotalHedgeRatio": {
@@ -15136,23 +15180,39 @@ var doc = `{
                     "type": "number"
                 },
                 "TotalNeedHedgeQty": {
-                    "description": "期货应套保量",
+                    "description": "应套保总量(现货应套保总量)",
                     "type": "number"
                 },
                 "TotalSpotQty": {
-                    "description": "现货量",
+                    "description": "现货量",
                     "type": "number"
                 },
                 "arbitrageqty": {
                     "description": "套利量",
                     "type": "number"
                 },
+                "diffArbitrageQty": {
+                    "description": "套利变动量",
+                    "type": "number"
+                },
+                "diffExposoureQty": {
+                    "description": "变动量(套保敞口)",
+                    "type": "number"
+                },
                 "diffFutuQty": {
-                    "description": "今日变动量(期货) = (买入 - 买入期初) - (卖出 - 卖出期初)",
+                    "description": "变动量(期货总量)",
+                    "type": "number"
+                },
+                "diffHedgeQty": {
+                    "description": "套保变动量",
+                    "type": "number"
+                },
+                "diffSpotHedgeQty": {
+                    "description": "变动量(现货应套保总量)",
                     "type": "number"
                 },
                 "diffSpotQty": {
-                    "description": "今日变动量(现货) = 现货数量 - 期初现货数量",
+                    "description": "变动量(现货总量) = 现货数量 - 期初现货数量",
                     "type": "number"
                 },
                 "enumdicname": {
@@ -15182,6 +15242,30 @@ var doc = `{
                 "oriTotalSpotQty": {
                     "description": "期初现货数量=(期初销售计划数量-期初销售合同已定价数量)-(期初采购计划数量-期初采购合同已定价数量)",
                     "type": "number"
+                },
+                "oriarbitrageqty": {
+                    "description": "期初套利量",
+                    "type": "number"
+                },
+                "orihedgeqty": {
+                    "description": "期初套保量",
+                    "type": "number"
+                },
+                "orineedhedgeexposoure": {
+                    "description": "期初套保敞口",
+                    "type": "number"
+                },
+                "oritotalexposure": {
+                    "description": "期初总敞口",
+                    "type": "number"
+                },
+                "oritotalfutureqty": {
+                    "description": "期初期货总量",
+                    "type": "number"
+                },
+                "oritotalneedhedgeqty": {
+                    "description": "期初现货应套保量",
+                    "type": "number"
                 }
             }
         },

+ 98 - 14
docs/swagger.json

@@ -2701,7 +2701,7 @@
                     },
                     {
                         "type": "integer",
-                        "description": "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日])",
+                        "description": "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日]) 4-日报表明细",
                         "name": "querytype",
                         "in": "query",
                         "required": true
@@ -2780,7 +2780,7 @@
                     },
                     {
                         "type": "integer",
-                        "description": "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日])",
+                        "description": "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日]) 4-日报表明细",
                         "name": "querytype",
                         "in": "query",
                         "required": true
@@ -2859,7 +2859,7 @@
                     },
                     {
                         "type": "integer",
-                        "description": "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日])",
+                        "description": "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日]) 4-日报表明细",
                         "name": "querytype",
                         "in": "query",
                         "required": true
@@ -2962,7 +2962,7 @@
                     },
                     {
                         "type": "integer",
-                        "description": "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日])",
+                        "description": "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日]) 4-日报表明细",
                         "name": "querytype",
                         "in": "query",
                         "required": true
@@ -2996,6 +2996,12 @@
                         "description": "结束交易日(格式yyyymmdd)",
                         "name": "enddate",
                         "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "币种id(日报表明细)",
+                        "name": "currencyid",
+                        "in": "query"
                     }
                 ],
                 "responses": {
@@ -3041,7 +3047,7 @@
                     },
                     {
                         "type": "integer",
-                        "description": "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日])",
+                        "description": "查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日]) 4-日报表明细",
                         "name": "querytype",
                         "in": "query",
                         "required": true
@@ -3075,6 +3081,12 @@
                         "description": "结束交易日(格式yyyymmdd)",
                         "name": "enddate",
                         "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "币种id(日报表明细)",
+                        "name": "currencyid",
+                        "in": "query"
                     }
                 ],
                 "responses": {
@@ -12349,6 +12361,10 @@
                     "description": "业务类型 1-套保 2-套利",
                     "type": "integer"
                 },
+                "brandname": {
+                    "description": "品牌名称",
+                    "type": "string"
+                },
                 "buyuserid": {
                     "description": "采购方id",
                     "type": "integer"
@@ -12373,10 +12389,18 @@
                     "description": "今定价量",
                     "type": "number"
                 },
+                "deliverygoodscode": {
+                    "description": "现货商品代码",
+                    "type": "string"
+                },
                 "deliverygoodsid": {
                     "description": "现货商品id",
                     "type": "integer"
                 },
+                "deliverygoodsname": {
+                    "description": "现货商品名称",
+                    "type": "string"
+                },
                 "diffqty": {
                     "description": "套保品种今变动量",
                     "type": "number"
@@ -12540,7 +12564,7 @@
                     "type": "number"
                 },
                 "contracttype": {
-                    "description": "现货合同类型 - 1:采购 -1:销售",
+                    "description": "计划类型 - 1:采购 -1:销售",
                     "type": "integer"
                 },
                 "convertratio": {
@@ -12567,6 +12591,10 @@
                     "description": "套保计划编号",
                     "type": "string"
                 },
+                "hedgeplanstatus": {
+                    "description": "套保计划状态 -  0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回",
+                    "type": "integer"
+                },
                 "mgunitidname": {
                     "description": "单位名称(套保商品)",
                     "type": "string"
@@ -12708,7 +12736,7 @@
                     "description": "套保品种ID",
                     "type": "integer"
                 },
-                "middlegoodsnam": {
+                "middlegoodsname": {
                     "description": "套保商品名称",
                     "type": "string"
                 },
@@ -12897,6 +12925,10 @@
                     "description": "周期类型 - 1:月 2:季 3:年 4:周 5:全报表【原值】",
                     "type": "integer"
                 },
+                "deliverygoodsid": {
+                    "description": "现货品种ID",
+                    "type": "integer"
+                },
                 "reckondate": {
                     "description": "日照时期(yyyyMMdd)",
                     "type": "string"
@@ -12929,6 +12961,10 @@
                     "description": "销售应收款额(应收货款额)",
                     "type": "number"
                 },
+                "spotgoodsbrandid": {
+                    "description": "现货品牌ID",
+                    "type": "integer"
+                },
                 "todaypaysum": {
                     "description": "今付款合计",
                     "type": "number"
@@ -12940,6 +12976,14 @@
                 "updatetime": {
                     "description": "更新时间",
                     "type": "string"
+                },
+                "wrfactortypeid": {
+                    "description": "仓单要素类型ID(212+Unix秒时间戳(10位)+xxxxxx)",
+                    "type": "integer"
+                },
+                "wrstandardid": {
+                    "description": "现货商品ID",
+                    "type": "integer"
                 }
             }
         },
@@ -15052,7 +15096,7 @@
                     "type": "string"
                 },
                 "MiddleGoodsHedgeRatio": {
-                    "description": "套保比例",
+                    "description": "套保比例",
                     "type": "number"
                 },
                 "MiddleGoodsID": {
@@ -15064,7 +15108,7 @@
                     "type": "string"
                 },
                 "NeedHedgeExposoure": {
-                    "description": "应套保敞口",
+                    "description": "应套保敞口(套保敞口)",
                     "type": "number"
                 },
                 "NeedHedgeRatio": {
@@ -15112,7 +15156,7 @@
                     "type": "number"
                 },
                 "TotalFutureQty": {
-                    "description": "期货量",
+                    "description": "期货量",
                     "type": "number"
                 },
                 "TotalHedgeRatio": {
@@ -15120,23 +15164,39 @@
                     "type": "number"
                 },
                 "TotalNeedHedgeQty": {
-                    "description": "期货应套保量",
+                    "description": "应套保总量(现货应套保总量)",
                     "type": "number"
                 },
                 "TotalSpotQty": {
-                    "description": "现货量",
+                    "description": "现货量",
                     "type": "number"
                 },
                 "arbitrageqty": {
                     "description": "套利量",
                     "type": "number"
                 },
+                "diffArbitrageQty": {
+                    "description": "套利变动量",
+                    "type": "number"
+                },
+                "diffExposoureQty": {
+                    "description": "变动量(套保敞口)",
+                    "type": "number"
+                },
                 "diffFutuQty": {
-                    "description": "今日变动量(期货) = (买入 - 买入期初) - (卖出 - 卖出期初)",
+                    "description": "变动量(期货总量)",
+                    "type": "number"
+                },
+                "diffHedgeQty": {
+                    "description": "套保变动量",
+                    "type": "number"
+                },
+                "diffSpotHedgeQty": {
+                    "description": "变动量(现货应套保总量)",
                     "type": "number"
                 },
                 "diffSpotQty": {
-                    "description": "今日变动量(现货) = 现货数量 - 期初现货数量",
+                    "description": "变动量(现货总量) = 现货数量 - 期初现货数量",
                     "type": "number"
                 },
                 "enumdicname": {
@@ -15166,6 +15226,30 @@
                 "oriTotalSpotQty": {
                     "description": "期初现货数量=(期初销售计划数量-期初销售合同已定价数量)-(期初采购计划数量-期初采购合同已定价数量)",
                     "type": "number"
+                },
+                "oriarbitrageqty": {
+                    "description": "期初套利量",
+                    "type": "number"
+                },
+                "orihedgeqty": {
+                    "description": "期初套保量",
+                    "type": "number"
+                },
+                "orineedhedgeexposoure": {
+                    "description": "期初套保敞口",
+                    "type": "number"
+                },
+                "oritotalexposure": {
+                    "description": "期初总敞口",
+                    "type": "number"
+                },
+                "oritotalfutureqty": {
+                    "description": "期初期货总量",
+                    "type": "number"
+                },
+                "oritotalneedhedgeqty": {
+                    "description": "期初现货应套保量",
+                    "type": "number"
                 }
             }
         },

+ 76 - 14
docs/swagger.yaml

@@ -3408,6 +3408,9 @@ definitions:
       biztype:
         description: 业务类型 1-套保 2-套利
         type: integer
+      brandname:
+        description: 品牌名称
+        type: string
       buyuserid:
         description: 采购方id
         type: integer
@@ -3426,9 +3429,15 @@ definitions:
       curqty:
         description: 今定价量
         type: number
+      deliverygoodscode:
+        description: 现货商品代码
+        type: string
       deliverygoodsid:
         description: 现货商品id
         type: integer
+      deliverygoodsname:
+        description: 现货商品名称
+        type: string
       diffqty:
         description: 套保品种今变动量
         type: number
@@ -3550,7 +3559,7 @@ definitions:
         description: 应套保总量变化量
         type: number
       contracttype:
-        description: 现货合同类型 - 1:采购 -1:销售
+        description: 计划类型 - 1:采购 -1:销售
         type: integer
       convertratio:
         description: 折算系数(套保品种)
@@ -3570,6 +3579,9 @@ definitions:
       hedgeplanno:
         description: 套保计划编号
         type: string
+      hedgeplanstatus:
+        description: 套保计划状态 -  0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回
+        type: integer
       mgunitidname:
         description: 单位名称(套保商品)
         type: string
@@ -3675,7 +3687,7 @@ definitions:
       middlegoodsid:
         description: 套保品种ID
         type: integer
-      middlegoodsnam:
+      middlegoodsname:
         description: 套保商品名称
         type: string
       middlgoodscode:
@@ -3816,6 +3828,9 @@ definitions:
       cycletype:
         description: 周期类型 - 1:月 2:季 3:年 4:周 5:全报表【原值】
         type: integer
+      deliverygoodsid:
+        description: 现货品种ID
+        type: integer
       reckondate:
         description: 日照时期(yyyyMMdd)
         type: string
@@ -3840,6 +3855,9 @@ definitions:
       sellunpaidamount:
         description: 销售应收款额(应收货款额)
         type: number
+      spotgoodsbrandid:
+        description: 现货品牌ID
+        type: integer
       todaypaysum:
         description: 今付款合计
         type: number
@@ -3849,6 +3867,12 @@ definitions:
       updatetime:
         description: 更新时间
         type: string
+      wrfactortypeid:
+        description: 仓单要素类型ID(212+Unix秒时间戳(10位)+xxxxxx)
+        type: integer
+      wrstandardid:
+        description: 现货商品ID
+        type: integer
     type: object
   models.Ermcp3Goods:
     properties:
@@ -5401,7 +5425,7 @@ definitions:
         description: 套保品种代码
         type: string
       MiddleGoodsHedgeRatio:
-        description: 套保比例
+        description: 套保比例
         type: number
       MiddleGoodsID:
         description: 套保品种
@@ -5410,7 +5434,7 @@ definitions:
         description: 套保品种名称
         type: string
       NeedHedgeExposoure:
-        description: 应套保敞口
+        description: 应套保敞口(套保敞口)
         type: number
       NeedHedgeRatio:
         description: 应套保敞口比例
@@ -5446,25 +5470,37 @@ definitions:
         description: 总敞口
         type: number
       TotalFutureQty:
-        description: 期货
+        description: 期货
         type: number
       TotalHedgeRatio:
         description: 敞口比例
         type: number
       TotalNeedHedgeQty:
-        description: 期货应套保量
+        description: 应套保总量(现货应套保总量)
         type: number
       TotalSpotQty:
-        description: 现货
+        description: 现货
         type: number
       arbitrageqty:
         description: 套利量
         type: number
+      diffArbitrageQty:
+        description: 套利变动量
+        type: number
+      diffExposoureQty:
+        description: 变动量(套保敞口)
+        type: number
       diffFutuQty:
-        description: 今日变动量(期货) = (买入 - 买入期初) - (卖出 - 卖出期初)
+        description: 变动量(期货总量)
+        type: number
+      diffHedgeQty:
+        description: 套保变动量
+        type: number
+      diffSpotHedgeQty:
+        description: 变动量(现货应套保总量)
         type: number
       diffSpotQty:
-        description: 今日变动量(现货) = 现货数量 - 期初现货数量
+        description: 变动量(现货总量) = 现货数量 - 期初现货数量
         type: number
       enumdicname:
         description: 单位名称
@@ -5487,6 +5523,24 @@ definitions:
       oriTotalSpotQty:
         description: 期初现货数量=(期初销售计划数量-期初销售合同已定价数量)-(期初采购计划数量-期初采购合同已定价数量)
         type: number
+      oriarbitrageqty:
+        description: 期初套利量
+        type: number
+      orihedgeqty:
+        description: 期初套保量
+        type: number
+      orineedhedgeexposoure:
+        description: 期初套保敞口
+        type: number
+      oritotalexposure:
+        description: 期初总敞口
+        type: number
+      oritotalfutureqty:
+        description: 期初期货总量
+        type: number
+      oritotalneedhedgeqty:
+        description: 期初现货应套保量
+        type: number
     type: object
   models.ErmcpRole:
     properties:
@@ -12651,7 +12705,7 @@ paths:
         name: userid
         required: true
         type: integer
-      - description: 查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日])
+      - description: 查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日]) 4-日报表明细
         in: query
         name: querytype
         required: true
@@ -12702,7 +12756,7 @@ paths:
         name: userid
         required: true
         type: integer
-      - description: 查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日])
+      - description: 查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日]) 4-日报表明细
         in: query
         name: querytype
         required: true
@@ -12753,7 +12807,7 @@ paths:
         name: userid
         required: true
         type: integer
-      - description: 查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日])
+      - description: 查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日]) 4-日报表明细
         in: query
         name: querytype
         required: true
@@ -12820,7 +12874,7 @@ paths:
         name: userid
         required: true
         type: integer
-      - description: 查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日])
+      - description: 查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日]) 4-日报表明细
         in: query
         name: querytype
         required: true
@@ -12845,6 +12899,10 @@ paths:
         in: query
         name: enddate
         type: string
+      - description: 币种id(日报表明细)
+        in: query
+        name: currencyid
+        type: integer
       produces:
       - application/json
       responses:
@@ -12871,7 +12929,7 @@ paths:
         name: userid
         required: true
         type: integer
-      - description: 查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日])
+      - description: 查询类型 1-日报表 2-周期报表 3-日报表(指定时间段[开始交易日,结束交易日]) 4-日报表明细
         in: query
         name: querytype
         required: true
@@ -12896,6 +12954,10 @@ paths:
         in: query
         name: enddate
         type: string
+      - description: 币种id(日报表明细)
+        in: query
+        name: currencyid
+        type: integer
       produces:
       - application/json
       responses:

+ 9 - 0
global/app/ginUtils.go

@@ -42,6 +42,9 @@ type GinUtils struct {
 
 // DoBindReq 处理参数绑定
 func (r *GinUtils) DoBindReq(req interface{}) {
+	if r.err != nil {
+		return
+	}
 	if r.err = r.C.ShouldBind(req); r.err != nil {
 		r.Gin.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
 	}
@@ -106,6 +109,9 @@ func (r *GinUtils) DoGetDataI(iObj IGetDataEx) {
 
 // CheckParam 参数检查
 func (r *GinUtils) CheckParam(iObj ICheck) {
+	if r.err != nil {
+		return
+	}
 	if iObj.Check() == false {
 		r.err = fmt.Errorf("check param err")
 		r.Gin.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
@@ -114,6 +120,9 @@ func (r *GinUtils) CheckParam(iObj ICheck) {
 
 // CheckParamF 参数检查
 func (r *GinUtils) CheckParamF(f func() bool) {
+	if r.err != nil {
+		return
+	}
 	if f() == false {
 		r.err = fmt.Errorf("check param err")
 		r.Gin.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)

+ 94 - 18
models/ermcp3Report.go

@@ -473,7 +473,7 @@ type Ermcp3ExpourseReport struct {
 	ARBITRAGEQTY          float64 `json:"arbitrageqty"  xorm:"'ARBITRAGEQTY'"`                   // 套利量
 	NEEDHEDGEQTY          float64 `json:"needhedgeqty"  xorm:"'NEEDHEDGEQTY'"`                   // 应套保量
 	NEEDARBITRAGEQTY      float64 `json:"needarbitrageqty"  xorm:"'NEEDARBITRAGEQTY'"`           // 应套利量
-	MIDDLEGOODSNAME       string  `json:"middlegoodsnam"  xorm:"'MIDDLEGOODSNAME'"`              // 套保商品名称
+	MIDDLEGOODSNAME       string  `json:"middlegoodsname"  xorm:"'MIDDLEGOODSNAME'"`             // 套保商品名称
 	MIDDLEGOODSCODE       string  `json:"middlgoodscode"  xorm:"'MIDDLEGOODSCODE'"`              // 套保商品代码
 	UNITID                int32   `json:"unitid"  xorm:"'UNITID'"`                               // 单位id
 	MGNEEDHEDGERATIO      float64 `json:"mgneedhedgeratio"  xorm:"'MGNEEDHEDGERATIO'"`           // 套保比例(套保品的)
@@ -663,6 +663,9 @@ type Ermcp3ExposureContractDetail struct {
 	TRADEDATE          string  `json:"tradedate"  xorm:"'tradedate'"`                   // 交易日
 	NEEDHEDGERATIO     float64 `json:"needhedgeratio"  xorm:"'NEEDHEDGERATIO'"`         // 应套保比例
 	NEEDARBITRAGERATIO float64 `json:"needarbitrageratio"  xorm:"'NEEDARBITRAGERATIO'"` // 应套利比例
+	BRANDNAME          string  `json:"brandname"  xorm:"'BRANDNAME'"`                   // 品牌名称
+	DELIVERYGOODSCODE  string  `json:"deliverygoodscode"  xorm:"'DELIVERYGOODSCODE'"`   // 现货商品代码
+	DELIVERYGOODSNAME  string  `json:"deliverygoodsname"  xorm:"'DELIVERYGOODSNAME'"`   // 现货商品名称
 
 	EnumdicName  string  `json:"enumdicname"`  // 单位名称
 	BUYUSERNAME  string  `json:"buyusername"`  // 采购方名称
@@ -703,7 +706,9 @@ func (r *Ermcp3ExposureContractDetail) buildSql() string {
 		"       mg.needhedgeratio," +
 		"       mg.needarbitrageratio," +
 		"       dg.dgfactoryitemid brandid," +
-		"       dg.dgfactoryitemvalue brandName" +
+		"       dg.dgfactoryitemvalue brandName," +
+		"       g.deliverygoodscode," +
+		"       g.deliverygoodsname" +
 		"  from erms2_wrsconvertdetail t" +
 		" inner join ermcp_spotcontract s" +
 		"    on t.deliverygoodsid = s.deliverygoodsid" +
@@ -711,8 +716,11 @@ func (r *Ermcp3ExposureContractDetail) buildSql() string {
 		"    on t.middlegoodsid = mg.middlegoodsid" +
 		"  left join wrstandard w" +
 		"    on s.wrstandardid = w.wrstandardid" +
-		"  left join dgfactoryitem dg on s.spotgoodsbrandid=dg.dgfactoryitemid" +
-		" where t.wrstandardid = 0 and s.contractstatus in(2,3)"
+		"  left join dgfactoryitem dg" +
+		"    on s.spotgoodsbrandid = dg.dgfactoryitemid" +
+		"  left join deliverygoods g on s.deliverygoodsid=g.deliverygoodsid" +
+		" where t.wrstandardid = 0" +
+		"   and s.contractstatus in (2, 3)"
 	sqlId.And("s.audittradedate", r.TRADEDATE)
 	sqlId.And("t.middlegoodsid", r.MIDDLEGOODSID)
 	sqlId.Join(fmt.Sprintf(" and %v in(s.userid, s.tradeuserid)", r.USERID))
@@ -737,7 +745,6 @@ type Ermcp3ExposureHedgeplanDetail struct {
 	USERID             int64   `json:"userid"  xorm:"'USERID'"`                         // 机构id
 	HEDGEPLANID        string  `json:"hedgeplanid"  xorm:"'HEDGEPLANID'"`               // 套保计划id
 	HEDGEPLANNO        string  `json:"hedgeplanno"  xorm:"'HEDGEPLANNO'"`               // 套保计划编号
-	CONTRACTTYPE       int32   `json:"contracttype"  xorm:"'CONTRACTTYPE'"`             // 现货合同类型 - 1:采购 -1:销售
 	BIZTYPE            int32   `json:"biztype"  xorm:"'BIZTYPE'"`                       // 业务类型 1-套保 2-套利
 	QTY                float64 `json:"qty"  xorm:"'QTY'"`                               // 合同量
 	PRICEDQTY          float64 `json:"pricedqty"  xorm:"'PRICEDQTY'"`                   // 已定价量
@@ -751,6 +758,8 @@ type Ermcp3ExposureHedgeplanDetail struct {
 	TRADEDATE          string  `json:"tradedate"  xorm:"'tradedate'"`                   // 交易日(登记日)
 	NEEDHEDGERATIO     float64 `json:"needhedgeratio"  xorm:"'NEEDHEDGERATIO'"`         // 应套保比例
 	NEEDARBITRAGERATIO float64 `json:"needarbitrageratio"  xorm:"'NEEDARBITRAGERATIO'"` // 应套利比例
+	CONTRACTTYPE       int32   `json:"contracttype"  xorm:"'CONTRACTTYPE'"`             // 计划类型 - 1:采购 -1:销售
+	HEDGEPLANSTATUS    int32   `json:"hedgeplanstatus"  xorm:"'HEDGEPLANSTATUS'"`       // 套保计划状态 -  0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回
 
 	EnumdicName  string  `json:"enumdicname"`  // 单位名称(品类)
 	MGUNITIDNAME string  `json:"mgunitidname"` // 单位名称(套保商品)
@@ -779,6 +788,7 @@ func (r *Ermcp3ExposureHedgeplanDetail) buildSql() string {
 		"       s.planqty qty," +
 		"       s.wrstandardid," +
 		"       s.audittradedate tradedate," +
+		"       s.hedgeplanstatus," +
 		"       w.wrstandardname," +
 		"       w.wrstandardcode," +
 		"       w.unitid," +
@@ -1034,6 +1044,10 @@ type Ermcp3FinanceReport struct {
 	BUYUNINVOICEDAMOUNT    float64 `json:"buyuninvoicedamount"  xorm:"BUYUNINVOICEDAMOUNT"`       // 采购应收票额(应收票额)
 	SELLPREPAIDAMOUNT      float64 `json:"sellprepaidamount"  xorm:"SELLPREPAIDAMOUNT"`           // 销售预收款额(预收货款额)
 	SELLUNPAIDAMOUNT       float64 `json:"sellunpaidamount"  xorm:"SELLUNPAIDAMOUNT"`             // 销售应收款额(应收货款额)
+	WRFACTORTYPEID         int64   `json:"wrfactortypeid"  xorm:"WRFACTORTYPEID"`                 // 仓单要素类型ID(212+Unix秒时间戳(10位)+xxxxxx)
+	DELIVERYGOODSID        int64   `json:"deliverygoodsid"  xorm:"DELIVERYGOODSID"`               // 现货品种ID
+	WRSTANDARDID           int64   `json:"wrstandardid"  xorm:"WRSTANDARDID"`                     // 现货商品ID
+	SPOTGOODSBRANDID       int32   `json:"spotgoodsbrandid"  xorm:"SPOTGOODSBRANDID"`             // 现货品牌ID
 
 	CURRENCYNAME string `json:"currencyname"` // 币种名称
 	QueryType    int32  `json:"-"`            // 查询类型 1-日报表 2-周期报表 3-日报表(范围,[开始日期,结束日期])
@@ -1048,11 +1062,13 @@ func (r *Ermcp3FinanceReport) calc() {
 func (r *Ermcp3FinanceReport) buildSql() string {
 	if r.QueryType == 1 || r.QueryType == 3 {
 		return r.buildSqlDay()
+	} else if r.QueryType == 4 {
+		return r.buildSqlDayDetail()
 	}
 	return r.buildSqlCycle()
 }
 
-// 日报表查询语句
+// buildSqlDay 财务日报表查询语句
 func (r *Ermcp3FinanceReport) buildSqlDay() string {
 	var sqlId utils.SQLVal = "SELECT t.SELLPREINVOICEDAMOUNT," +
 		"       t.SELLUNINVOICEDAMOUNT," +
@@ -1086,7 +1102,42 @@ func (r *Ermcp3FinanceReport) buildSqlDay() string {
 	return sqlId.String()
 }
 
-// 周期报表查询语句
+// buildSqlDayDetail 财务日报表明细查询语句
+func (r *Ermcp3FinanceReport) buildSqlDayDetail() string {
+	var sqlId utils.SQLVal = "SELECT t.RECKONDATE," +
+		"       t.AREAUSERID," +
+		"       t.CURRENCYID," +
+		"       t.BIZTYPE," +
+		"       t.WRFACTORTYPEID," +
+		"       t.DELIVERYGOODSID," +
+		"       t.WRSTANDARDID," +
+		"       t.SPOTGOODSBRANDID," +
+		"       t.BUYTODAYSETTLEAMOUNT," +
+		"       t.BUYTODAYREFUNDAMOUNT," +
+		"       t.BUYPREPAIDAMOUNT," +
+		"       t.BUYUNPAIDAMOUNT," +
+		"       t.BUYTODAYINVOICEAMOUNT," +
+		"       t.BUYPREINVOICEDAMOUNT," +
+		"       t.BUYUNINVOICEDAMOUNT," +
+		"       t.SELLTODAYSETTLEAMOUNT," +
+		"       t.SELLTODAYREFUNDAMOUNT," +
+		"       t.SELLPREPAIDAMOUNT," +
+		"       t.SELLUNPAIDAMOUNT," +
+		"       t.SELLTODAYINVOICEAMOUNT," +
+		"       t.SELLPREINVOICEDAMOUNT," +
+		"       t.SELLUNINVOICEDAMOUNT," +
+		"       t.TODAYRECEIVESUM," +
+		"       t.TODAYPAYSUM," +
+		"       to_char(t.UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME" +
+		"  FROM RECKON_ERMCP_AFINANCESUB t" +
+		" WHERE 1 = 1"
+	sqlId.And("t.AREAUSERID", r.AREAUSERID)
+	sqlId.And("t.RECKONDATE", r.RECKONDATE)
+	sqlId.And("t.CURRENCYID", r.CURRENCYID)
+	return sqlId.String()
+}
+
+// buildSqlCycle 财务周期报表查询语句
 func (r *Ermcp3FinanceReport) buildSqlCycle() string {
 	var sqlId utils.SQLVal = "SELECT t.SELLPREINVOICEDAMOUNT," +
 		"       t.SELLUNINVOICEDAMOUNT," +
@@ -1323,35 +1374,38 @@ func (r *Ermcp3ArealSumPL) calc() {
 func (r *Ermcp3ArealSumPL) buildSql() string {
 	if r.QueryType == 1 || r.QueryType == 3 {
 		return r.buildSqlDay()
+	} else if r.QueryType == 4 {
+		return r.buildSqlDayDetail()
 	}
 	return r.buildSqlCycle()
 }
 
+// buildSqlDay 损益汇总日报表(需要汇总维度)
 func (r *Ermcp3ArealSumPL) buildSqlDay() string {
 	var sqlId utils.SQLVal = "SELECT t.RECKONDATE," +
 		"       t.AREAUSERID," +
-		"       t.MIDDLEGOODSID," +
 		"       t.CURRENCYID," +
-		"       t.SPOTACTUALPL," +
-		"       t.SPOTFLOATPL," +
-		"       t.FUTUREACTUALPL," +
-		"       t.FUTUREFLOATPL," +
-		"       t.SUMACTUALPL," +
-		"       to_char(t.UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME" +
+		"       sum(t.SPOTACTUALPL) SPOTACTUALPL," +
+		"       sum(t.SPOTFLOATPL) SPOTFLOATPL," +
+		"       sum(t.FUTUREACTUALPL) FUTUREACTUALPL," +
+		"       sum(t.FUTUREFLOATPL) FUTUREFLOATPL," +
+		"       sum(t.SUMACTUALPL) SUMACTUALPL," +
+		"       sum(t.SUMPL) SUMPL" +
 		"  FROM RECKON_ERMCP_AREASUMPL t" +
 		" WHERE 1 = 1"
+	sqlId.And("t.AREAUSERID", r.AREAUSERID)
 	if r.QueryType == 1 {
 		sqlId.And("t.RECKONDATE", r.RECKONDATE)
 	} else if r.QueryType == 3 {
 		sqlId.Join(fmt.Sprintf(" and t.RECKONDATE >= '%v' and t.RECKONDATE <= '%v' ", r.BeginDate, r.EndDate))
 	}
+	sqlId.Join(" GROUP BY t.RECKONDATE, t.AREAUSERID, t.CURRENCYID")
 	return sqlId.String()
 }
 
-func (r *Ermcp3ArealSumPL) buildSqlCycle() string {
-	var sqlId utils.SQLVal = "SELECT t.AREAUSERID," +
-		"       t.CYCLETIME," +
-		"       t.CYCLETYPE," +
+func (r *Ermcp3ArealSumPL) buildSqlDayDetail() string {
+	var sqlId utils.SQLVal = "SELECT t.RECKONDATE," +
+		"       t.AREAUSERID," +
 		"       t.MIDDLEGOODSID," +
 		"       t.CURRENCYID," +
 		"       t.SPOTACTUALPL," +
@@ -1359,11 +1413,33 @@ func (r *Ermcp3ArealSumPL) buildSqlCycle() string {
 		"       t.FUTUREACTUALPL," +
 		"       t.FUTUREFLOATPL," +
 		"       t.SUMACTUALPL," +
+		"       t.SUMPL," +
 		"       to_char(t.UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME" +
+		"  FROM RECKON_ERMCP_AREASUMPL t" +
+		" WHERE 1 = 1"
+	sqlId.And("t.AREAUSERID", r.AREAUSERID)
+	sqlId.And("t.RECKONDATE", r.RECKONDATE)
+	sqlId.And("t.CURRENCYID", r.CURRENCYID)
+	return sqlId.String()
+}
+
+func (r *Ermcp3ArealSumPL) buildSqlCycle() string {
+	var sqlId utils.SQLVal = "SELECT t.AREAUSERID," +
+		"       t.CYCLETIME," +
+		"       t.CYCLETYPE," +
+		"       t.CURRENCYID," +
+		"       sum(t.SPOTACTUALPL) SPOTACTUALPL," +
+		"       sum(t.SPOTFLOATPL) SPOTFLOATPL," +
+		"       sum(t.FUTUREACTUALPL) FUTUREACTUALPL," +
+		"       sum(t.FUTUREFLOATPL) FUTUREFLOATPL," +
+		"       sum(t.SUMACTUALPL) SUMACTUALPL," +
+		"       sum(t.SUMPL) SUMPL" +
 		"  FROM REPORT_ERMCP_AREASUMPL t" +
 		" WHERE 1 = 1"
+	sqlId.And("t.AREAUSERID", r.AREAUSERID)
 	sqlId.And("t.cycletype", r.CYCLETYPE)
 	sqlId.And("t.cycletime", r.CYCLETIME)
+	sqlId.Join(" GROUP BY t.AREAUSERID, t.CURRENCYID, t.CYCLETIME, t.CYCLETYPE")
 	return sqlId.String()
 }
 

+ 33 - 9
models/ermcpExposure.go

@@ -32,28 +32,41 @@ type ErmcpRealExposureModel struct {
 	SellPricedQty         float64 `json:"SellPricedQty"  xorm:"'SellPricedQty'"`           // 销售合同已定价数量
 	BuyFutureQty          float64 `json:"BuyFutureQty"  xorm:"'BuyFutureQty'"`             // 买入期货数量
 	SellFutureQty         float64 `json:"SellFutureQty"  xorm:"'SellFutureQty'"`           // 卖出期货数量
-	TotalSpotQty          float64 `json:"TotalSpotQty"  xorm:"'TotalSpotQty'"`             // 现货
-	TotalFutureQty        float64 `json:"TotalFutureQty"  xorm:"'TotalFutureQty'"`         // 期货
+	TotalSpotQty          float64 `json:"TotalSpotQty"  xorm:"'TotalSpotQty'"`             // 现货
+	TotalFutureQty        float64 `json:"TotalFutureQty"  xorm:"'TotalFutureQty'"`         // 期货
 	TotalExposure         float64 `json:"TotalExposure"  xorm:"'TotalExposure'"`           // 总敞口
 	TotalHedgeRatio       float64 `json:"TotalHedgeRatio"  xorm:"'TotalHedgeRatio'"`       // 敞口比例
-	TotalNeedHedgeQty     float64 `json:"TotalNeedHedgeQty"  xorm:"'TotalNeedHedgeQty'"`   // 期货应套保量
-	NeedHedgeExposoure    float64 `json:"NeedHedgeExposoure"  xorm:"'NeedHedgeExposoure'"` // 应套保敞口
+	TotalNeedHedgeQty     float64 `json:"TotalNeedHedgeQty"  xorm:"'TotalNeedHedgeQty'"`   // 应套保总量(现货应套保总量)
+	NeedHedgeExposoure    float64 `json:"NeedHedgeExposoure"  xorm:"'NeedHedgeExposoure'"` // 应套保敞口(套保敞口)
 	NeedHedgeRatio        float64 `json:"NeedHedgeRatio"  xorm:"'NeedHedgeRatio'"`         // 应套保敞口比例
 	GOODSUNITID           int32   `json:"-"  xorm:"'GOODSUNITID'"`                         // 品种单位ID
 	MiddleGoodsName       string  `json:"MiddleGoodsName"  xorm:"'MiddleGoodsName'"`       // 套保品种名称
 	MiddleGoodsCode       string  `json:"MiddleGoodsCode"  xorm:"'MiddleGoodsCode'"`       // 套保品种代码
-	MiddleGoodsHedgeRatio float64 `json:"MiddleGoodsHedgeRatio"  xorm:"'needhedgeratio'"`  // 套保比例
+	MiddleGoodsHedgeRatio float64 `json:"MiddleGoodsHedgeRatio"  xorm:"'needhedgeratio'"`  // 套保比例
 	NEEDARBITRAGEQTY      float64 `json:"needarbitrageqty"  xorm:"'NEEDARBITRAGEQTY'"`     // 应套利量
 	NEEDHEDGEQTY          float64 `json:"needhedgeqty"  xorm:"'NEEDHEDGEQTY'"`             // 应套保量
 	HEDGEQTY              float64 `json:"hedgeqty"  xorm:"'hedgeqty'"`                     // 套保量
 	ARBITRAGEQTY          float64 `json:"arbitrageqty"  xorm:"'arbitrageqty'"`             // 套利量
 	NEEDARBITRAGERATIO    float64 `json:"needarbitrageratio"  xorm:"'needarbitrageratio'"` // 套利比例
 
+	ORIHEDGEQTY           float64 `json:"orihedgeqty"  xorm:"'ORIHEDGEQTY'"`                     // 期初套保量
+	ORIARBITRAGEQTY       float64 `json:"oriarbitrageqty"  xorm:"'ORIARBITRAGEQTY'"`             // 期初套利量
+	ORITOTALNEEDHEDGEQTY  float64 `json:"oritotalneedhedgeqty"  xorm:"'ORITOTALNEEDHEDGEQTY'"`   // 期初现货应套保量
+	ORITOTALFUTUREQTY     float64 `json:"oritotalfutureqty"  xorm:"'ORITOTALFUTUREQTY'"`         // 期初期货总量
+	ORINEEDHEDGEEXPOSOURE float64 `json:"orineedhedgeexposoure"  xorm:"'ORINEEDHEDGEEXPOSOURE'"` // 期初套保敞口
+	ORITOTALEXPOSURE      float64 `json:"oritotalexposure"  xorm:"'ORITOTALEXPOSURE'"`           // 期初总敞口
+
+	ENUMDICNAME     string  // 单位名称
 	OriTotalSpotQty float64 // 期初现货数量=(期初销售计划数量-期初销售合同已定价数量)-(期初采购计划数量-期初采购合同已定价数量)
 	OriTotalFutuQty float64 // 期初期货数量=期初买入期货数量-期初卖出期货数量
-	DiffSpotQty     float64 // 今日变动量(现货) = 现货数量 - 期初现货数量
-	DiffFutuQty     float64 // 今日变动量(期货) = (买入 - 买入期初) - (卖出 - 卖出期初)
-	ENUMDICNAME     string  // 单位名称
+	DiffSpotQty     float64 // 变动量(现货总量) = 现货数量 - 期初现货数量
+	DiffFutuQty     float64 // 变动量(期货总量)
+
+	DiffHedgeQty     float64 // 套保变动量
+	DiffArbitrageQty float64 // 套利变动量
+	DiffSpotHedgeQty float64 // 变动量(现货应套保总量)
+	DiffExposoureQty float64 // 变动量(套保敞口)
+
 }
 
 // calc 计算相关字段
@@ -61,7 +74,12 @@ func (r *ErmcpRealExposureModel) calc() {
 	r.OriTotalSpotQty = (r.OriSellPlanQty - r.OriSellPricedQty) - (r.OriBuyPlanQty - r.OriBuyPricedQty)
 	r.OriTotalFutuQty = r.OriBuyFutureQty - r.OriSellFutureQty
 	r.DiffSpotQty = r.TotalSpotQty - r.OriTotalSpotQty
-	r.DiffFutuQty = (r.BuyFutureQty - r.OriBuyFutureQty) - (r.SellFutureQty - r.OriSellFutureQty)
+	r.DiffFutuQty = r.TotalFutureQty - r.ORITOTALFUTUREQTY
+	r.DiffHedgeQty = r.HEDGEQTY - r.ORIHEDGEQTY
+	r.DiffArbitrageQty = r.ARBITRAGEQTY - r.ORIHEDGEQTY
+	r.DiffSpotHedgeQty = r.TotalNeedHedgeQty - r.ORITOTALNEEDHEDGEQTY
+	r.DiffExposoureQty = r.NeedHedgeExposoure - r.ORINEEDHEDGEEXPOSOURE
+
 	if r.ENUMDICNAME == "" {
 		r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.GOODSUNITID)
 	}
@@ -97,6 +115,12 @@ func (r *ErmcpRealExposureModel) buildSql() string {
 		"       t.needhedgeqty," +
 		"       t.hedgeqty," +
 		"       t.arbitrageqty," +
+		"       t.orihedgeqty," +
+		"       t.oriarbitrageqty," +
+		"       t.oritotalneedhedgeqty," +
+		"       t.oritotalfutureqty," +
+		"       t.orineedhedgeexposoure," +
+		"       t.oritotalexposure," +
 		"       g.needarbitrageratio" +
 		"  from ermcp_areaexposure t" +
 		"  left join erms_middlegoods g" +