Просмотр исходного кода

1.更新菜单mobile_munu.json
2.查提货单和提货地址返回行政区名称
3.财务报表明细拆分 #95409
4.fix bug #95406 #95429 #95412

zou.yingbin 4 лет назад
Родитель
Сommit
5ba3e2ce35

+ 6 - 6
config/mobile_menu.json

@@ -272,7 +272,7 @@
                         "sort": 1,
                         "type": 1,
                         "rulekey": "client_report_exposure_parmateradjust",
-                        "isshow": true,
+                        "isshow": false,
                         "remark": "报表查询-敞口报表-参数调整明细",
                         "children": [] 
                     },
@@ -282,14 +282,14 @@
                         "sort": 2,
                         "type": 1,
                         "rulekey": "client_report_exposure_futures",
-                        "isshow": true,
+                        "isshow": false,
                         "remark": "报表查询-敞口报表-期货明细",
                         "children": [] 
                     },
                     {
                         "code": "client_report_exposure_hedgeplan",
                         "title": "套保计划明细",
-                        "sort": 2,
+                        "sort": 3,
                         "type": 1,
                         "rulekey": "client_report_exposure_hedgeplan",
                         "isshow": true,
@@ -299,7 +299,7 @@
                     {
                         "code": "client_report_exposure_spotcontract",
                         "title": "现货合同明细",
-                        "sort": 2,
+                        "sort": 4,
                         "type": 1,
                         "rulekey": "client_report_exposure_spotcontract",
                         "isshow": true,
@@ -314,7 +314,7 @@
                 "sort": 2,
                 "type": 1,
                 "rulekey": "client_report_futures",
-                "isshow": true,
+                "isshow": false,
                 "remark": "报表查询-期货报表",
                 "children": [
                     {
@@ -323,7 +323,7 @@
                         "sort": 1,
                         "type": 1,
                         "rulekey": "client_report_futures_account",
-                        "isshow": true,
+                        "isshow": false,
                         "remark": "报表查询-期货报表-账户明细",
                         "children": [] 
                     }

+ 32 - 6
controllers/ermcp/qryExposure.go

@@ -11,6 +11,7 @@ import (
 	"mtp2_if/global/e"
 	"mtp2_if/logger"
 	"mtp2_if/models"
+	"mtp2_if/mtpcache"
 	"net/http"
 
 	"github.com/gin-gonic/gin"
@@ -190,7 +191,7 @@ func QueryHisExposure(c *gin.Context) {
 
 // 实时敞口/期货明细 请求
 type RealtimeExposurePositionReq struct {
-	AreaUserId    int32 `form:"userid" json:"areaUserId"`           // 所属机构ID
+	AreaUserId    int64 `form:"userid" json:"areaUserId"`           // 所属机构ID
 	MiddleGoodsId int32 `form:"middleGoodsId" json:"middlegoodsid"` // 套保商品
 }
 
@@ -216,7 +217,7 @@ func QueryRealtimeExposurePosition(c *gin.Context) {
 
 // 敞口/期货头寸 请求
 type ExposureHedgePositionReq struct {
-	AreaUserId int32 `form:"userid" json:"areaUserId"` // 用户ID
+	AreaUserId int64 `form:"userid" json:"areaUserId"` // 用户ID
 }
 
 // 敞口/期货头寸 应答
@@ -237,11 +238,36 @@ func QueryExposureHedgePosition(c *gin.Context) {
 		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
 		return
 	}
-	var m = models.ErmcpHedgePosition{RELATEDUSERID: req.AreaUserId}
-	if d, err := m.GetData(); err == nil {
-		appG.Response(http.StatusOK, e.SUCCESS, d)
+	if mtpcache.IsAreaUserId(req.AreaUserId) {
+		var m = models.ErmcpHedgePosition{RELATEDUSERID: req.AreaUserId}
+		if d, err := m.GetData(); err == nil {
+			appG.Response(http.StatusOK, e.SUCCESS, d)
+		} else {
+			appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+		}
 	} else {
-		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+		var m = models.ErmcpTradePosition{USERID: req.AreaUserId}
+		if d, err := m.GetData(); err == nil {
+			if len(d) > 0 {
+				hedgePos := models.ErmcpHedgePosition{
+					RELATEDUSERID:   d[0].USERID,
+					YDBUYPOSITION:   int32(d[0].BUYPOSITIONQTY),
+					CURBUYPOSITION:  int32(d[0].BUYCURPOSITIONQTY),
+					YDSELLPOSITION:  int32(d[0].SELLPOSITIONQTY),
+					CURSELLPOSITION: int32(d[0].SELLCURPOSITIONQTY),
+					HEDGEGOODSID:    d[0].GOODSID,
+					GOODSID:         d[0].GOODSID,
+					GOODSCODE:       d[0].GOODSCODE,
+					GOODSNAME:       d[0].GOODSNAME,
+				}
+				sData := []models.ErmcpHedgePosition{hedgePos}
+				appG.Response(http.StatusOK, e.SUCCESS, sData)
+			} else {
+				appG.Response(http.StatusOK, e.SUCCESS, d)
+			}
+		} else {
+			appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+		}
 	}
 }
 

+ 15 - 3
controllers/ermcp3/qryErmcp3Report.go

@@ -352,7 +352,8 @@ func QryAreaSpotplReport(c *gin.Context) {
 // @Param querytype query int true "查询类型 1-报表 2-报表明细"
 // @Param cycletype query int true "周期类型 - 0:日 1:月 2:季 3:年 4:周 5:全报表【原值】"
 // @Param cycletime query string true "周期时间 日(YYYYMMDD) 月(YYYYMM)  季(YYYYQ) 年(YYYY) 周(YYYYMMDD周内任意一天) 全(0)【原值】"
-// @Param currencyid query int false "币种id(日报表明细)"
+// @Param currencyid query int false "币种id(报表明细必填)"
+// @Param sumfields query string false "汇总维度(逗号隔开) 1-品种 2-品类 3-品牌"
 // @Success 200 {array} models.Ermcp3FinanceReport
 // @Failure 500 {object} app.Response
 // @Router /Ermcp3/QryFinanceReport [get]
@@ -363,17 +364,28 @@ func QryFinanceReport(c *gin.Context) {
 	a.DoBindReq(&req)
 	a.CheckParam(&req)
 	req2 := struct {
-		CURRENCYID int32 `form:"currencyid"` // 币种id
+		CURRENCYID int32  `form:"currencyid"` // 币种id
+		SUMFIELDS  string `form:"sumfields"`  // 汇总维度
 	}{}
 	a.DoBindReq(&req2)
 	a.CheckParamF(func() bool {
 		if req.QUERYTYPE == 2 {
 			return req2.CURRENCYID > 0
 		}
+		tmp := req2.SUMFIELDS
+		req2.SUMFIELDS = strings.TrimSpace(req2.SUMFIELDS)
+		for _, v := range req2.SUMFIELDS {
+			if v != ',' {
+				if v < '1' || v > '3' {
+					logger.GetLogger().Errorf("QryFinanceReport sumfield[%v] check fail", tmp)
+					return false
+				}
+			}
+		}
 		return true
 	})
 	req.CovertRequest()
-	m := models.Ermcp3FinanceReport{AREAUSERID: req.USERID, QueryType: req.QUERYTYPE, RECKONDATE: req.TRADEDATE,
+	m := models.Ermcp3FinanceReport{AREAUSERID: req.USERID, QueryType: req.QUERYTYPE, RECKONDATE: req.TRADEDATE, SumFields: req2.SUMFIELDS,
 		CYCLETYPE: req.CYCLETYPE, CYCLETIME: req.CYCLETIME, BeginDate: req.BEGINDATE, EndDate: req.ENDDATE, CURRENCYID: req2.CURRENCYID}
 	a.DoGetDataI(&m)
 }

+ 47 - 1
docs/docs.go

@@ -3364,9 +3364,15 @@ var doc = `{
                     },
                     {
                         "type": "integer",
-                        "description": "币种id(报表明细)",
+                        "description": "币种id(报表明细必填)",
                         "name": "currencyid",
                         "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "汇总维度(逗号隔开) 1-品种 2-品类 3-品牌",
+                        "name": "sumfields",
+                        "in": "query"
                     }
                 ],
                 "responses": {
@@ -20554,14 +20560,26 @@ var doc = `{
                     "description": "市",
                     "type": "integer"
                 },
+                "cityname": {
+                    "description": "城市名称",
+                    "type": "string"
+                },
                 "countryid": {
                     "description": "国家",
                     "type": "integer"
                 },
+                "countryname": {
+                    "description": "国家名称",
+                    "type": "string"
+                },
                 "districtid": {
                     "description": "地区",
                     "type": "integer"
                 },
+                "districtname": {
+                    "description": "地区名称",
+                    "type": "string"
+                },
                 "enumdicname": {
                     "description": "单位名称(提货商品)",
                     "type": "string"
@@ -20578,10 +20596,18 @@ var doc = `{
                     "description": "交易商品乘数",
                     "type": "number"
                 },
+                "goodscode": {
+                    "description": "商品代码",
+                    "type": "string"
+                },
                 "goodsid": {
                     "description": "商品ID",
                     "type": "integer"
                 },
+                "goodsname": {
+                    "description": "商品名称",
+                    "type": "string"
+                },
                 "goodsqty": {
                     "description": "交易商品手数(69模式按成交量小数位放大取整)",
                     "type": "number"
@@ -20630,6 +20656,10 @@ var doc = `{
                     "description": "省",
                     "type": "integer"
                 },
+                "provincename": {
+                    "description": "省名称",
+                    "type": "string"
+                },
                 "qty": {
                     "description": "交易商品总手数(交易商品 - 69模式按成交量放大) - 明细表的交易商品手数汇总",
                     "type": "number"
@@ -21525,14 +21555,26 @@ var doc = `{
                     "description": "市",
                     "type": "integer"
                 },
+                "cityname": {
+                    "description": "城市名称",
+                    "type": "string"
+                },
                 "countryid": {
                     "description": "国家",
                     "type": "integer"
                 },
+                "countryname": {
+                    "description": "国家名称",
+                    "type": "string"
+                },
                 "districtid": {
                     "description": "地区",
                     "type": "integer"
                 },
+                "districtname": {
+                    "description": "地区名称",
+                    "type": "string"
+                },
                 "hasencrypt": {
                     "description": "数据是否已加密 - 0:未加密 1:已加密",
                     "type": "integer"
@@ -21549,6 +21591,10 @@ var doc = `{
                     "description": "省",
                     "type": "integer"
                 },
+                "provincename": {
+                    "description": "省名称",
+                    "type": "string"
+                },
                 "receivername": {
                     "description": "提货人姓名",
                     "type": "string"

+ 47 - 1
docs/swagger.json

@@ -3348,9 +3348,15 @@
                     },
                     {
                         "type": "integer",
-                        "description": "币种id(报表明细)",
+                        "description": "币种id(报表明细必填)",
                         "name": "currencyid",
                         "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "汇总维度(逗号隔开) 1-品种 2-品类 3-品牌",
+                        "name": "sumfields",
+                        "in": "query"
                     }
                 ],
                 "responses": {
@@ -20538,14 +20544,26 @@
                     "description": "市",
                     "type": "integer"
                 },
+                "cityname": {
+                    "description": "城市名称",
+                    "type": "string"
+                },
                 "countryid": {
                     "description": "国家",
                     "type": "integer"
                 },
+                "countryname": {
+                    "description": "国家名称",
+                    "type": "string"
+                },
                 "districtid": {
                     "description": "地区",
                     "type": "integer"
                 },
+                "districtname": {
+                    "description": "地区名称",
+                    "type": "string"
+                },
                 "enumdicname": {
                     "description": "单位名称(提货商品)",
                     "type": "string"
@@ -20562,10 +20580,18 @@
                     "description": "交易商品乘数",
                     "type": "number"
                 },
+                "goodscode": {
+                    "description": "商品代码",
+                    "type": "string"
+                },
                 "goodsid": {
                     "description": "商品ID",
                     "type": "integer"
                 },
+                "goodsname": {
+                    "description": "商品名称",
+                    "type": "string"
+                },
                 "goodsqty": {
                     "description": "交易商品手数(69模式按成交量小数位放大取整)",
                     "type": "number"
@@ -20614,6 +20640,10 @@
                     "description": "省",
                     "type": "integer"
                 },
+                "provincename": {
+                    "description": "省名称",
+                    "type": "string"
+                },
                 "qty": {
                     "description": "交易商品总手数(交易商品 - 69模式按成交量放大) - 明细表的交易商品手数汇总",
                     "type": "number"
@@ -21509,14 +21539,26 @@
                     "description": "市",
                     "type": "integer"
                 },
+                "cityname": {
+                    "description": "城市名称",
+                    "type": "string"
+                },
                 "countryid": {
                     "description": "国家",
                     "type": "integer"
                 },
+                "countryname": {
+                    "description": "国家名称",
+                    "type": "string"
+                },
                 "districtid": {
                     "description": "地区",
                     "type": "integer"
                 },
+                "districtname": {
+                    "description": "地区名称",
+                    "type": "string"
+                },
                 "hasencrypt": {
                     "description": "数据是否已加密 - 0:未加密 1:已加密",
                     "type": "integer"
@@ -21533,6 +21575,10 @@
                     "description": "省",
                     "type": "integer"
                 },
+                "provincename": {
+                    "description": "省名称",
+                    "type": "string"
+                },
                 "receivername": {
                     "description": "提货人姓名",
                     "type": "string"

+ 35 - 1
docs/swagger.yaml

@@ -9040,12 +9040,21 @@ definitions:
       cityid:
         description: 市
         type: integer
+      cityname:
+        description: 城市名称
+        type: string
       countryid:
         description: 国家
         type: integer
+      countryname:
+        description: 国家名称
+        type: string
       districtid:
         description: 地区
         type: integer
+      districtname:
+        description: 地区名称
+        type: string
       enumdicname:
         description: 单位名称(提货商品)
         type: string
@@ -9058,9 +9067,15 @@ definitions:
       goodsagreeunit:
         description: 交易商品乘数
         type: number
+      goodscode:
+        description: 商品代码
+        type: string
       goodsid:
         description: 商品ID
         type: integer
+      goodsname:
+        description: 商品名称
+        type: string
       goodsqty:
         description: 交易商品手数(69模式按成交量小数位放大取整)
         type: number
@@ -9097,6 +9112,9 @@ definitions:
       provinceid:
         description: 省
         type: integer
+      provincename:
+        description: 省名称
+        type: string
       qty:
         description: 交易商品总手数(交易商品 - 69模式按成交量放大) - 明细表的交易商品手数汇总
         type: number
@@ -9762,12 +9780,21 @@ definitions:
       cityid:
         description: 市
         type: integer
+      cityname:
+        description: 城市名称
+        type: string
       countryid:
         description: 国家
         type: integer
+      countryname:
+        description: 国家名称
+        type: string
       districtid:
         description: 地区
         type: integer
+      districtname:
+        description: 地区名称
+        type: string
       hasencrypt:
         description: 数据是否已加密 - 0:未加密 1:已加密
         type: integer
@@ -9780,6 +9807,9 @@ definitions:
       provinceid:
         description: 省
         type: integer
+      provincename:
+        description: 省名称
+        type: string
       receivername:
         description: 提货人姓名
         type: string
@@ -14194,10 +14224,14 @@ paths:
         name: cycletime
         required: true
         type: string
-      - description: 币种id(报表明细)
+      - description: 币种id(报表明细必填)
         in: query
         name: currencyid
         type: integer
+      - description: 汇总维度(逗号隔开) 1-品种 2-品类 3-品牌
+        in: query
+        name: sumfields
+        type: string
       produces:
       - application/json
       responses:

+ 254 - 163
models/ermcp3Report.go

@@ -938,7 +938,6 @@ func (r *Ermcp3AreaSpotPLReport) buildSqlDay() string {
 		"               t.AREAUSERID," +
 		"               t.CURRENCYID," +
 		"               t.DELIVERYGOODSID," +
-		"               t.WRSTANDARDID," +
 		"               sum(t.ORIBUYQTY) ORIBUYQTY," +
 		"               sum(t.ORIBUYAMOUNT) ORIBUYAMOUNT," +
 		"               sum(t.ORISELLQTY) ORISELLQTY," +
@@ -970,8 +969,7 @@ func (r *Ermcp3AreaSpotPLReport) buildSqlDay() string {
 		"         GROUP BY t.RECKONDATE," +
 		"                  t.AREAUSERID," +
 		"                  t.CURRENCYID," +
-		"                  t.DELIVERYGOODSID," +
-		"                  t.WRSTANDARDID) a" +
+		"                  t.DELIVERYGOODSID) a" +
 		"  LEFT JOIN DELIVERYGOODS g" +
 		"    on a.deliverygoodsid = g.deliverygoodsid" +
 		"  LEFT JOIN WRSTANDARD w" +
@@ -988,42 +986,7 @@ func (r *Ermcp3AreaSpotPLReport) buildSqlDay() string {
 }
 
 func (r *Ermcp3AreaSpotPLReport) buildSqlDayDetail() string {
-	var sqlId utils.SQLVal = "SELECT t.RECKONDATE," +
-		"       t.AREAUSERID," +
-		"       t.ACCOUNTID," +
-		"       t.WRFACTORTYPEID," +
-		"       t.CURRENCYID," +
-		"       t.BIZTYPE," +
-		"       t.DELIVERYGOODSID," +
-		"       t.WRSTANDARDID," +
-		"       t.SPOTGOODSBRANDID," +
-		"       t.ORIBUYQTY," +
-		"       t.ORIBUYAMOUNT," +
-		"       t.ORISELLQTY," +
-		"       t.ORISELLAMOUNT," +
-		"       t.ORIQTY," +
-		"       t.ORIAVERAGEPRICE," +
-		"       t.ORIAMOUNT," +
-		"       t.TODAYBUYQTY," +
-		"       t.TODAYBUYAMOUNT," +
-		"       t.TODAYBUYAVERAGEPRICE," +
-		"       t.TODAYSELLQTY," +
-		"       t.TODAYSELLAMOUNT," +
-		"       t.TODAYSELLAVERAGEPRICE," +
-		"       t.CURBUYQTY," +
-		"       t.CURBUYAMOUNT," +
-		"       t.CURSELLQTY," +
-		"       t.CURSELLAMOUNT," +
-		"       t.CURQTY," +
-		"       t.CURAVERAGEPRICE," +
-		"       t.CURAMOUNT," +
-		"       t.CURSPOTPRICE," +
-		"       t.CURMARKETVALUE," +
-		"       t.ACTUALPL," +
-		"       t.FLOATPL," +
-		"       to_char(t.UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME," +
-		"       t.TODAYINQTY," +
-		"       t.TODAYOUTQTY," +
+	var sqlId utils.SQLVal = "select a.*," +
 		"       g.deliverygoodscode," +
 		"       g.deliverygoodsname," +
 		"       g.goodsunitid," +
@@ -1031,20 +994,62 @@ func (r *Ermcp3AreaSpotPLReport) buildSqlDayDetail() string {
 		"       w.wrstandardname," +
 		"       w.unitid," +
 		"       dg.dgfactoryitemvalue brandName" +
-		"  FROM RECKON_ERMCP_AREASPOTPL t" +
-		"  LEFT JOIN DELIVERYGOODS g on t.deliverygoodsid=g.deliverygoodsid" +
-		"  LEFT JOIN WRSTANDARD w on t.wrstandardid = w.wrstandardid" +
-		"  LEFT JOIN DGFACTORYITEM dg on t.spotgoodsbrandid=dg.dgfactoryitemid" +
-		" WHERE 1 = 1"
-	sqlId.And("t.AREAUSERID", r.AREAUSERID)
-	sqlId.AndEx("t.RECKONDATE", r.RECKONDATE, len(r.RECKONDATE) > 0)
+		"  from (SELECT t.RECKONDATE," +
+		"               t.AREAUSERID," +
+		"               t.CURRENCYID," +
+		"               t.DELIVERYGOODSID," +
+		"               t.WRSTANDARDID," +
+		"               t.SPOTGOODSBRANDID," +
+		"               sum(t.ORIBUYQTY) ORIBUYQTY," +
+		"               sum(t.ORIBUYAMOUNT) ORIBUYAMOUNT," +
+		"               sum(t.ORISELLQTY) ORISELLQTY," +
+		"               sum(t.ORISELLAMOUNT) ORISELLAMOUNT," +
+		"               sum(t.ORIQTY) ORIQTY," +
+		"               sum(t.ORIAVERAGEPRICE) ORIAVERAGEPRICE," +
+		"               sum(t.ORIAMOUNT) ORIAMOUNT," +
+		"               sum(t.TODAYBUYQTY) TODAYBUYQTY," +
+		"               sum(t.TODAYBUYAMOUNT) TODAYBUYAMOUNT," +
+		"               sum(t.TODAYBUYAVERAGEPRICE) TODAYBUYAVERAGEPRICE," +
+		"               sum(t.TODAYSELLQTY) TODAYSELLQTY," +
+		"               sum(t.TODAYSELLAMOUNT) TODAYSELLAMOUNT," +
+		"               sum(t.TODAYSELLAVERAGEPRICE) TODAYSELLAVERAGEPRICE," +
+		"               sum(t.CURBUYQTY) CURBUYQTY," +
+		"               sum(t.CURBUYAMOUNT) CURBUYAMOUNT," +
+		"               sum(t.CURSELLQTY) CURSELLQTY," +
+		"               sum(t.CURSELLAMOUNT) CURSELLAMOUNT," +
+		"               sum(t.CURQTY) CURQTY," +
+		"               sum(t.CURAVERAGEPRICE) CURAVERAGEPRICE," +
+		"               sum(t.CURAMOUNT) CURAMOUNT," +
+		"               sum(t.CURSPOTPRICE) CURSPOTPRICE," +
+		"               sum(t.CURMARKETVALUE) CURMARKETVALUE," +
+		"               sum(t.ACTUALPL) ACTUALPL," +
+		"               sum(t.FLOATPL) FLOATPL," +
+		"               sum(t.TODAYINQTY) TODAYINQTY," +
+		"               sum(t.TODAYOUTQTY) TODAYOUTQTY" +
+		"          FROM RECKON_ERMCP_AREASPOTPL t" +
+		"         WHERE 1 = 1 %v" +
+		"         GROUP BY t.RECKONDATE," +
+		"                  t.AREAUSERID," +
+		"                  t.CURRENCYID," +
+		"                  t.DELIVERYGOODSID," +
+		"                  t.WRSTANDARDID," +
+		"                  t.SPOTGOODSBRANDID) a" +
+		"  LEFT JOIN DELIVERYGOODS g" +
+		"    on a.deliverygoodsid = g.deliverygoodsid" +
+		"  LEFT JOIN WRSTANDARD w" +
+		"    on a.wrstandardid = w.wrstandardid" +
+		"  LEFT JOIN DGFACTORYITEM dg" +
+		"    on a.spotgoodsbrandid = dg.dgfactoryitemid"
+	var sqlParam utils.SQLVal
+	sqlParam.And("t.AREAUSERID", r.AREAUSERID)
+	sqlParam.AndEx("t.RECKONDATE", r.RECKONDATE, len(r.RECKONDATE) > 0)
 	if len(r.BeginDate) > 0 && len(r.EndDate) > 0 {
-		sqlId.Join(fmt.Sprintf(" and t.RECKONDATE >= '%v' and t.RECKONDATE <= '%v' ", r.BeginDate, r.EndDate))
+		sqlParam.Join(fmt.Sprintf(" and t.RECKONDATE >= '%v' and t.RECKONDATE <= '%v' ", r.BeginDate, r.EndDate))
 	}
-	sqlId.And("t.CURRENCYID", r.CURRENCYID)
-	sqlId.And("t.DELIVERYGOODSID", r.DELIVERYGOODSID)
-	sqlId.And("t.WRSTANDARDID", r.WRSTANDARDID)
-
+	sqlParam.And("t.CURRENCYID", r.CURRENCYID)
+	sqlParam.And("t.DELIVERYGOODSID", r.DELIVERYGOODSID)
+	sqlParam.And("t.WRSTANDARDID", r.WRSTANDARDID)
+	sqlId.FormatParam(sqlParam.String())
 	return sqlId.String()
 }
 
@@ -1062,7 +1067,6 @@ func (r *Ermcp3AreaSpotPLReport) buildSqlCycle() string {
 		"               t.AREAUSERID," +
 		"               t.CURRENCYID," +
 		"               t.DELIVERYGOODSID," +
-		"               t.WRSTANDARDID," +
 		"               sum(t.ORIBUYQTY) ORIBUYQTY," +
 		"               sum(t.ORIBUYAMOUNT) ORIBUYAMOUNT," +
 		"               sum(t.ORISELLQTY) ORISELLQTY," +
@@ -1095,8 +1099,7 @@ func (r *Ermcp3AreaSpotPLReport) buildSqlCycle() string {
 		"                  t.cycletype," +
 		"                  t.cycletime," +
 		"                  t.CURRENCYID," +
-		"                  t.DELIVERYGOODSID," +
-		"                  t.WRSTANDARDID) a" +
+		"                  t.DELIVERYGOODSID) a" +
 		"  LEFT JOIN DELIVERYGOODS g" +
 		"    on a.deliverygoodsid = g.deliverygoodsid" +
 		"  LEFT JOIN WRSTANDARD w" +
@@ -1161,6 +1164,8 @@ type Ermcp3FinanceReport struct {
 	QueryType    int32  `json:"-"`            // 查询类型 1-报表 2-报表明细
 	BeginDate    string `json:"begindate"`    // 开始交易日
 	EndDate      string `json:"enddate"`      // 结束交易日
+
+	SumFields string `json:"-"` // 维度字段
 }
 
 func (r *Ermcp3FinanceReport) calc() {
@@ -1168,127 +1173,213 @@ func (r *Ermcp3FinanceReport) calc() {
 	r.ACCOUNTNAME = mtpcache.GetUserNameByUserId(r.AREAUSERID)
 }
 
-func (r *Ermcp3FinanceReport) buildSql() string {
-	// 日报表
-	if r.QueryType == 1 && r.CYCLETYPE == 0 {
-		return r.buildSqlDay()
+// getSumField 获取汇总维度字段
+func (r *Ermcp3FinanceReport) getSumField() (fields []string) {
+	fields = append(fields, "areauserid")
+	fields = append(fields, "currencyid")
+	if r.CYCLETYPE == 0 {
+		// 日报表
+		fields = append(fields, "reckondate")
+	} else {
+		// 周期报表
+		fields = append(fields, "cycletype")
+		fields = append(fields, "cycletime")
 	}
-	// 日报表明细
-	if r.QueryType == 2 && r.CYCLETYPE == 0 {
-		return r.buildSqlDayDetail()
+	baseField := map[string]string{
+		"1": "deliverygoodsid",
+		"2": "wrstandardid",
+		"3": "spotgoodsbrandid",
 	}
-	return r.buildSqlCycle()
+	param := []string{}
+	if len(r.SumFields) > 0 {
+		param = strings.Split(r.SumFields, ",")
+	}
+	for k, v := range baseField {
+		for _, p := range param {
+			if k == p {
+				fields = append(fields, v)
+			}
+		}
+	}
+	return
 }
 
-// buildSqlDay 财务日报表查询语句
-func (r *Ermcp3FinanceReport) buildSqlDay() string {
-	var sqlId utils.SQLVal = "SELECT t.SELLPREINVOICEDAMOUNT," +
-		"       t.SELLUNINVOICEDAMOUNT," +
-		"       t.TODAYRECEIVESUM," +
-		"       t.TODAYPAYSUM," +
-		"       to_char(t.UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME," +
-		"       t.RECKONDATE," +
-		"       t.AREAUSERID," +
-		"       t.CURRENCYID," +
-		"       t.BIZTYPE," +
-		"       t.BUYTODAYSETTLEAMOUNT," +
-		"       t.BUYTODAYREFUNDAMOUNT," +
-		"       t.BUYPREPAIDAMOUNT," +
-		"       t.BUYUNPAIDAMOUNT," +
-		"       t.BUYTODAYINVOICEAMOUNT," +
-		"       t.BUYPREINVOICEDAMOUNT," +
-		"       t.BUYUNINVOICEDAMOUNT," +
-		"       t.SELLTODAYSETTLEAMOUNT," +
-		"       t.SELLTODAYREFUNDAMOUNT," +
-		"       t.SELLPREPAIDAMOUNT," +
-		"       t.SELLUNPAIDAMOUNT," +
-		"       t.SELLTODAYINVOICEAMOUNT" +
-		"  FROM RECKON_ERMCP_AREAFINANCE t" +
-		" WHERE 1 = 1"
-	sqlId.And("t.AREAUSERID", r.AREAUSERID)
-	if r.QueryType == 1 {
-		sqlId.And("t.RECKONDATE", r.RECKONDATE)
-	} else if r.QueryType == 2 {
-		sqlId.Join(fmt.Sprintf(" and t.RECKONDATE >= '%v' and t.RECKONDATE <= '%v' ", r.BeginDate, r.EndDate))
+func (r *Ermcp3FinanceReport) getExFieldInfo() (strFiled string, strleftJoin string) {
+	if len(r.SumFields) > 0 {
+		param := strings.Split(r.SumFields, ",")
+		fHas := func(v string) bool {
+			for i := range param {
+				if param[i] == v {
+					return true
+				}
+			}
+			return false
+		}
+		if fHas("1") {
+			if len(strFiled) > 0 {
+				strFiled += ","
+			}
+			strFiled += "g.deliverygoodscode, g.deliverygoodsname, g.goodsunitid"
+			strleftJoin += " LEFT JOIN deliverygoods g on a.deliverygoodsid = g.deliverygoodsid"
+		}
+		if fHas("2") {
+			if len(strFiled) > 0 {
+				strFiled += ","
+			}
+			strFiled += "w.wrstandardname, w.wrstandardcode, w.unitid"
+			strleftJoin += " LEFT JOIN WRSTANDARD w on a.wrstandardid = w.wrstandardid"
+		}
+		if fHas("3") {
+			if len(strFiled) > 0 {
+				strFiled += ","
+			}
+			strFiled += "gb.dgfactoryitemvalue brandname"
+			strleftJoin += " LEFT JOIN dgfactoryitem gb on a.spotgoodsbrandid = gb.dgfactoryitemid"
+		}
 	}
-	return sqlId.String()
+	return
 }
 
-// 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," +
-		"       g.deliverygoodscode," +
-		"       g.deliverygoodsname," +
-		"       w.wrstandardcode," +
-		"       w.wrstandardname," +
-		"       dg.dgfactoryitemvalue brandName" +
-		"  FROM RECKON_ERMCP_AFINANCESUB t" +
-		"  LEFT JOIN DELIVERYGOODS g on t.deliverygoodsid=g.deliverygoodsid" +
-		"  LEFT JOIN WRSTANDARD w on t.wrstandardid=w.wrstandardid" +
-		"  LEFT JOIN DGFACTORYITEM dg on t.spotgoodsbrandid=dg.dgfactoryitemid" +
-		" WHERE 1 = 1"
-	sqlId.And("t.AREAUSERID", r.AREAUSERID)
-	sqlId.AndEx("t.RECKONDATE", r.RECKONDATE, len(r.RECKONDATE) > 0)
+func (r *Ermcp3FinanceReport) buildSql() string {
+	fields := r.getSumField()
+	if r.CYCLETYPE == 0 {
+		// 查日照报
+		return r.buildSqlReckon(fields)
+	} else {
+		// 查报表表
+		return r.buildSqlReport(fields)
+	}
+}
+
+func (r *Ermcp3FinanceReport) buildSqlReckon(fields []string) string {
+	var sqlId, sqlParam utils.SQLVal
+	var strFileds string
+	for _, v := range fields {
+		if len(strFileds) > 0 {
+			strFileds += ","
+		}
+		strFileds += "t." + v
+	}
+	sqlParam.And("t.AREAUSERID", r.AREAUSERID)
+	sqlParam.AndEx("t.RECKONDATE", r.RECKONDATE, len(r.RECKONDATE) > 0)
 	if len(r.BeginDate) > 0 && len(r.EndDate) > 0 {
-		sqlId.Join(fmt.Sprintf(" and t.RECKONDATE >= '%v' and t.RECKONDATE <= '%v' ", r.BeginDate, r.EndDate))
+		sqlParam.Join(fmt.Sprintf(" and t.RECKONDATE >= '%v' and t.RECKONDATE <= '%v' ", r.BeginDate, r.EndDate))
+	}
+	sqlParam.AndEx("t.CURRENCYID", r.CURRENCYID, r.CURRENCYID > 0)
+
+	exFileds, strleftJoin := r.getExFieldInfo()
+	if len(exFileds) > 0 {
+		// 有左联查额外信息(RECKON_ERMCP_AFINANCESUB明细表, 注意是不同的表)
+		sqlId = "select a.*, %v" +
+			"  from (SELECT %v," +
+			"               sum(t.BUYTODAYSETTLEAMOUNT) BUYTODAYSETTLEAMOUNT," +
+			"               sum(t.BUYTODAYREFUNDAMOUNT) BUYTODAYREFUNDAMOUNT," +
+			"               sum(t.BUYPREPAIDAMOUNT) BUYPREPAIDAMOUNT," +
+			"               sum(t.BUYUNPAIDAMOUNT) BUYUNPAIDAMOUNT," +
+			"               sum(t.BUYTODAYINVOICEAMOUNT) BUYTODAYINVOICEAMOUNT," +
+			"               sum(t.BUYPREINVOICEDAMOUNT) BUYPREINVOICEDAMOUNT," +
+			"               sum(t.BUYUNINVOICEDAMOUNT) BUYUNINVOICEDAMOUNT," +
+			"               sum(t.SELLTODAYSETTLEAMOUNT) SELLTODAYSETTLEAMOUNT," +
+			"               sum(t.SELLTODAYREFUNDAMOUNT) SELLTODAYREFUNDAMOUNT," +
+			"               sum(t.SELLPREPAIDAMOUNT) SELLPREPAIDAMOUNT," +
+			"               sum(t.SELLUNPAIDAMOUNT) SELLUNPAIDAMOUNT," +
+			"               sum(t.SELLTODAYINVOICEAMOUNT) SELLTODAYINVOICEAMOUNT," +
+			"               sum(t.SELLPREINVOICEDAMOUNT) SELLPREINVOICEDAMOUNT," +
+			"               sum(t.SELLUNINVOICEDAMOUNT) SELLUNINVOICEDAMOUNT," +
+			"               sum(t.TODAYRECEIVESUM) TODAYRECEIVESUM," +
+			"               sum(t.TODAYPAYSUM) TODAYPAYSUM" +
+			"          FROM RECKON_ERMCP_AFINANCESUB t" +
+			"         WHERE 1 = 1 %v" +
+			"         GROUP BY %v) a %v"
+		sqlId.FormatParam(exFileds, strFileds, sqlParam.String(), strFileds, strleftJoin)
+	} else {
+		sqlId = "SELECT %v," +
+			"       sum(t.BUYTODAYSETTLEAMOUNT) BUYTODAYSETTLEAMOUNT," +
+			"       sum(t.BUYTODAYREFUNDAMOUNT) BUYTODAYREFUNDAMOUNT," +
+			"       sum(t.BUYPREPAIDAMOUNT) BUYPREPAIDAMOUNT," +
+			"       sum(t.BUYUNPAIDAMOUNT) BUYUNPAIDAMOUNT," +
+			"       sum(t.BUYTODAYINVOICEAMOUNT) BUYTODAYINVOICEAMOUNT," +
+			"       sum(t.BUYPREINVOICEDAMOUNT) BUYPREINVOICEDAMOUNT," +
+			"       sum(t.BUYUNINVOICEDAMOUNT) BUYUNINVOICEDAMOUNT," +
+			"       sum(t.SELLTODAYSETTLEAMOUNT) SELLTODAYSETTLEAMOUNT," +
+			"       sum(t.SELLTODAYREFUNDAMOUNT) SELLTODAYREFUNDAMOUNT," +
+			"       sum(t.SELLPREPAIDAMOUNT) SELLPREPAIDAMOUNT," +
+			"       sum(t.SELLUNPAIDAMOUNT) SELLUNPAIDAMOUNT," +
+			"       sum(t.SELLTODAYINVOICEAMOUNT) SELLTODAYINVOICEAMOUNT," +
+			"       sum(t.SELLPREINVOICEDAMOUNT) SELLPREINVOICEDAMOUNT," +
+			"       sum(t.SELLUNINVOICEDAMOUNT) SELLUNINVOICEDAMOUNT," +
+			"       sum(t.TODAYRECEIVESUM) TODAYRECEIVESUM," +
+			"       sum(t.TODAYPAYSUM) TODAYPAYSUM" +
+			"  FROM RECKON_ERMCP_AREAFINANCE t" +
+			" WHERE 1 = 1 %v" +
+			" GROUP BY %v"
+		sqlId.FormatParam(strFileds, sqlParam.String(), strFileds)
 	}
-	sqlId.And("t.CURRENCYID", r.CURRENCYID)
 	return sqlId.String()
 }
 
-// buildSqlCycle 财务周期报表查询语句
-func (r *Ermcp3FinanceReport) buildSqlCycle() string {
-	var sqlId utils.SQLVal = "SELECT t.SELLPREINVOICEDAMOUNT," +
-		"       t.SELLUNINVOICEDAMOUNT," +
-		"       t.TODAYRECEIVESUM," +
-		"       t.TODAYPAYSUM," +
-		"       to_char(t.UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME," +
-		"       t.CYCLETIME," +
-		"       t.CYCLETYPE," +
-		"       t.AREAUSERID," +
-		"       t.CURRENCYID," +
-		"       t.BIZTYPE," +
-		"       t.BUYTODAYSETTLEAMOUNT," +
-		"       t.BUYTODAYREFUNDAMOUNT," +
-		"       t.BUYPREPAIDAMOUNT," +
-		"       t.BUYUNPAIDAMOUNT," +
-		"       t.BUYTODAYINVOICEAMOUNT," +
-		"       t.BUYPREINVOICEDAMOUNT," +
-		"       t.BUYUNINVOICEDAMOUNT," +
-		"       t.SELLTODAYSETTLEAMOUNT," +
-		"       t.SELLTODAYREFUNDAMOUNT," +
-		"       t.SELLPREPAIDAMOUNT," +
-		"       t.SELLUNPAIDAMOUNT," +
-		"       t.SELLTODAYINVOICEAMOUNT" +
-		"  FROM REPORT_ERMCP_AREAFINANCE t" +
-		" WHERE 1 = 1"
-	sqlId.And("t.AREAUSERID", r.AREAUSERID)
-	sqlId.And("t.CYCLETYPE", r.CYCLETYPE)
-	sqlId.And("t.CYCLETIME", r.CYCLETIME)
+func (r *Ermcp3FinanceReport) buildSqlReport(fields []string) string {
+	var sqlId, sqlParam utils.SQLVal
+	var strFileds string
+	for _, v := range fields {
+		if len(strFileds) > 0 {
+			strFileds += ","
+		}
+		strFileds += "t." + v
+	}
+	sqlParam.And("t.AREAUSERID", r.AREAUSERID)
+	sqlParam.And("t.CYCLETYPE", r.CYCLETYPE)
+	sqlParam.And("t.CYCLETIME", r.CYCLETIME)
+	sqlParam.AndEx("t.CURRENCYID", r.CURRENCYID, r.CURRENCYID > 0)
+
+	exFileds, strleftJoin := r.getExFieldInfo()
+	if len(exFileds) > 0 {
+		// 有左联查额外信息(REPORT_ERMCP_AFINANCESUB注意表名不同)
+		sqlId = "select a.*, %v" +
+			"  from (SELECT %v," +
+			"               sum(t.BUYTODAYSETTLEAMOUNT) BUYTODAYSETTLEAMOUNT," +
+			"               sum(t.BUYTODAYREFUNDAMOUNT) BUYTODAYREFUNDAMOUNT," +
+			"               sum(t.BUYPREPAIDAMOUNT) BUYPREPAIDAMOUNT," +
+			"               sum(t.BUYUNPAIDAMOUNT) BUYUNPAIDAMOUNT," +
+			"               sum(t.BUYTODAYINVOICEAMOUNT) BUYTODAYINVOICEAMOUNT," +
+			"               sum(t.BUYPREINVOICEDAMOUNT) BUYPREINVOICEDAMOUNT," +
+			"               sum(t.BUYUNINVOICEDAMOUNT) BUYUNINVOICEDAMOUNT," +
+			"               sum(t.SELLTODAYSETTLEAMOUNT) SELLTODAYSETTLEAMOUNT," +
+			"               sum(t.SELLTODAYREFUNDAMOUNT) SELLTODAYREFUNDAMOUNT," +
+			"               sum(t.SELLPREPAIDAMOUNT) SELLPREPAIDAMOUNT," +
+			"               sum(t.SELLUNPAIDAMOUNT) SELLUNPAIDAMOUNT," +
+			"               sum(t.SELLTODAYINVOICEAMOUNT) SELLTODAYINVOICEAMOUNT," +
+			"               sum(t.SELLPREINVOICEDAMOUNT) SELLPREINVOICEDAMOUNT," +
+			"               sum(t.SELLUNINVOICEDAMOUNT) SELLUNINVOICEDAMOUNT," +
+			"               sum(t.TODAYRECEIVESUM) TODAYRECEIVESUM," +
+			"               sum(t.TODAYPAYSUM) TODAYPAYSUM" +
+			"          FROM REPORT_ERMCP_AFINANCESUB t" +
+			"         WHERE 1 = 1 %v" +
+			"         GROUP BY %v) a %v"
+		sqlId.FormatParam(exFileds, strFileds, sqlParam.String(), strFileds, strleftJoin)
+	} else {
+		sqlId = "SELECT %v," +
+			"       sum(t.BUYTODAYSETTLEAMOUNT) BUYTODAYSETTLEAMOUNT," +
+			"       sum(t.BUYTODAYREFUNDAMOUNT) BUYTODAYREFUNDAMOUNT," +
+			"       sum(t.BUYPREPAIDAMOUNT) BUYPREPAIDAMOUNT," +
+			"       sum(t.BUYUNPAIDAMOUNT) BUYUNPAIDAMOUNT," +
+			"       sum(t.BUYTODAYINVOICEAMOUNT) BUYTODAYINVOICEAMOUNT," +
+			"       sum(t.BUYPREINVOICEDAMOUNT) BUYPREINVOICEDAMOUNT," +
+			"       sum(t.BUYUNINVOICEDAMOUNT) BUYUNINVOICEDAMOUNT," +
+			"       sum(t.SELLTODAYSETTLEAMOUNT) SELLTODAYSETTLEAMOUNT," +
+			"       sum(t.SELLTODAYREFUNDAMOUNT) SELLTODAYREFUNDAMOUNT," +
+			"       sum(t.SELLPREPAIDAMOUNT) SELLPREPAIDAMOUNT," +
+			"       sum(t.SELLUNPAIDAMOUNT) SELLUNPAIDAMOUNT," +
+			"       sum(t.SELLTODAYINVOICEAMOUNT) SELLTODAYINVOICEAMOUNT," +
+			"       sum(t.SELLPREINVOICEDAMOUNT) SELLPREINVOICEDAMOUNT," +
+			"       sum(t.SELLUNINVOICEDAMOUNT) SELLUNINVOICEDAMOUNT," +
+			"       sum(t.TODAYRECEIVESUM) TODAYRECEIVESUM," +
+			"       sum(t.TODAYPAYSUM) TODAYPAYSUM" +
+			"  FROM REPORT_ERMCP_AREAFINANCE t" +
+			" WHERE 1 = 1 %v" +
+			" GROUP BY %v"
+		sqlId.FormatParam(strFileds, sqlParam.String(), strFileds)
+	}
 	return sqlId.String()
 }
 

+ 87 - 43
models/ermcpExposure.go

@@ -581,7 +581,7 @@ type ErmcpTradeGoods struct {
 	GOODSNAME        string  `json:"goodsname"  xorm:"'GOODSNAME'"`               // 商品名称
 	GOODSGROUPID     int32   `json:"goodsgroupid"  xorm:"'GOODSGROUPID'"`         // 商品组id
 	GOODSUNITID      int32   `json:"goodsunitid"  xorm:"'GOODSUNITID'"`           // 套保品种单位id
-	AREAUSERID       int32   `json:"areauserid"  xorm:"'AREAUSERID'"`             // 所属机构id
+	AREAUSERID       int64   `json:"areauserid"  xorm:"'AREAUSERID'"`             // 所属机构id
 	AGREEUNIT        float64 `json:"agreeunit"  xorm:"'agreeunit'"`               // 合约单位
 }
 
@@ -619,28 +619,32 @@ func (r *ErmcpTradeGoods) GetData() (map[int32]*ErmcpTradeGoods, error) {
 
 // ErmcpTradePosition 获取用户头寸(子账户)
 type ErmcpTradePosition struct {
-	USERID             int32 `json:"userid"  xorm:"'userid'"`                         // 用户id
-	GOODSID            int32 `json:"goodsid"  xorm:"'goodsid'"`                       // 商品id
-	BUYPOSITIONQTY     int64 `json:"buypositionqty"  xorm:"'Buypositionqty'"`         // 买期初持仓
-	BUYCURPOSITIONQTY  int64 `json:"buycurpositionqty"  xorm:"'Buycurpositionqty'"`   // 买当前持仓
-	SELLPOSITIONQTY    int64 `json:"sellpositionqty"  xorm:"'Sellpositionqty'"`       // 卖期初持仓
-	SELLCURPOSITIONQTY int64 `json:"sellcurpositionqty"  xorm:"'Sellcurpositionqty'"` // 卖当前持仓
+	USERID             int64  `json:"userid"  xorm:"'userid'"`                         // 用户id
+	GOODSID            int32  `json:"goodsid"  xorm:"'goodsid'"`                       // 商品id
+	BUYPOSITIONQTY     int64  `json:"buypositionqty"  xorm:"'Buypositionqty'"`         // 买期初持仓
+	BUYCURPOSITIONQTY  int64  `json:"buycurpositionqty"  xorm:"'Buycurpositionqty'"`   // 买当前持仓
+	SELLPOSITIONQTY    int64  `json:"sellpositionqty"  xorm:"'Sellpositionqty'"`       // 卖期初持仓
+	SELLCURPOSITIONQTY int64  `json:"sellcurpositionqty"  xorm:"'Sellcurpositionqty'"` // 卖当前持仓
+	GOODSCODE          string `json:"goodscode"  xorm:"'GOODSCODE'"`                   // 商品代码
+	GOODSNAME          string `json:"goodsname"  xorm:"'GOODSNAME'"`                   // 商品名称
 }
 
 func (r *ErmcpTradePosition) buildSql() string {
-	sqlId := "select a.relateduserid userid," +
+	sqlId := "select b.*, g.goodscode,g.goodsname from (" +
+		"select a.userid," +
 		"       a.goodsid," +
 		"       sum(a.buypositionqty) buypositionqty," +
 		"       sum(a.buycurpositionqty) buycurpositionqty," +
 		"       sum(a.sellpositionqty) sellpositionqty," +
 		"       sum(a.sellcurpositionqty) sellcurpositionqty" +
-		"  from (select ta.userid, t.*" +
+		"  from (select ta.relateduserid userid, t.*" +
 		"          from tradeposition t" +
 		"         inner join taaccount ta" +
 		"            on t.accountid = ta.accountid" +
-		"         where ta.relateduserid = %v and ismain=0" +
-		"           ) a" +
-		" group by a.userid, a.goodsid"
+		"         where ta.relateduserid = %v" +
+		"           and ismain = 0) a" +
+		" group by a.userid, a.goodsid" +
+		" ) b left join goods g on b.goodsid=g.goodsid"
 	sqlId = fmt.Sprintf(sqlId, r.USERID)
 	return sqlId
 }
@@ -654,7 +658,7 @@ func (r *ErmcpTradePosition) GetData() ([]ErmcpTradePosition, error) {
 
 // ErmcpHedgePosition 用户头寸(母账户)
 type ErmcpHedgePosition struct {
-	RELATEDUSERID     int32  `json:"relateduserid"  xorm:"'RELATEDUSERID'"`         // 关联用户id
+	RELATEDUSERID     int64  `json:"relateduserid"  xorm:"'RELATEDUSERID'"`         // 关联用户id
 	ACCOUNTID         int64  `json:"accountid"  xorm:"'ACCOUNTID'"`                 // 资金账号[外部母账户]
 	HEDGEGOODSID      int32  `json:"hedgegoodsid"  xorm:"'HEDGEGOODSID'"`           // 对冲合约ID
 	HEDGEACCOUNTCODE  string `json:"hedgeaccountcode"  xorm:"'HEDGEACCOUNTCODE'"`   // 对冲账号
@@ -735,7 +739,7 @@ func (r *ErmcpHedgePosition) GetData() ([]ErmcpHedgePosition, error) {
 
 // ErmcpExposurePostion 实时敞口\期货明细(头寸)
 type ErmcpExposurePostion struct {
-	AREAUSERID    int32   `json:"areauserid"  xorm:"'AREAUSERID'"`       // 所属机构id
+	AREAUSERID    int64   `json:"areauserid"  xorm:"'AREAUSERID'"`       // 所属机构id
 	MIDDLEGOODSID int32   `json:"middlegoodsid"  xorm:"'MIDDLEGOODSID'"` // 套保商品id
 	GOODSID       int32   `json:"goodsid"  xorm:"'GOODSID'"`             // 商品id
 	GOODSCODE     string  `json:"goodscode"  xorm:"'GOODSCODE'"`         // 商品代码
@@ -752,7 +756,7 @@ type ErmcpExposurePostion struct {
 func (r *ErmcpExposurePostion) ParseFromPos(val *ErmcpTradeGoods, data *ErmcpTradePosition) {
 	r.AREAUSERID = val.AREAUSERID
 	r.MIDDLEGOODSID = val.MIDDLEGOODSID
-	r.GOODSID = val.MIDDLEGOODSID
+	r.GOODSID = val.GOODSID
 	r.GOODSCODE = val.GOODSCODE
 	r.GOODSNAME = val.GOODSNAME
 	//相关计算
@@ -770,7 +774,7 @@ func (r *ErmcpExposurePostion) ParseFromPos(val *ErmcpTradeGoods, data *ErmcpTra
 func (r *ErmcpExposurePostion) ParseFromHedgePos(val *ErmcpTradeGoods, data *ErmcpHedgePosition) {
 	r.AREAUSERID = val.AREAUSERID
 	r.MIDDLEGOODSID = val.MIDDLEGOODSID
-	r.GOODSID = val.MIDDLEGOODSID
+	r.GOODSID = val.GOODSID
 	r.GOODSCODE = val.GOODSCODE
 	r.GOODSNAME = val.GOODSNAME
 	//相关计算
@@ -794,21 +798,39 @@ func (r *ErmcpExposurePostion) GetDataEx() (interface{}, error) {
 		return sData, err
 	}
 
-	// 查询头寸(母账号)
-	mp := ErmcpHedgePosition{RELATEDUSERID: r.AREAUSERID}
-	sPostion, err1 := mp.GetData()
-	if err1 != nil || sPostion == nil || len(sPostion) == 0 {
-		return sData, err1
-	}
+	if mtpcache.IsAreaUserId(r.AREAUSERID) {
+		// 查询头寸(母账号)
+		mp := ErmcpHedgePosition{RELATEDUSERID: r.AREAUSERID}
+		sPostion, err1 := mp.GetData()
+		if err1 != nil || sPostion == nil || len(sPostion) == 0 {
+			return sData, err1
+		}
 
-	// 合并处理
-	for i := range sPostion {
-		if val, ok := sGoods[sPostion[i].HEDGEGOODSID]; ok {
-			d := ErmcpExposurePostion{}
-			d.ParseFromHedgePos(val, &sPostion[i])
-			sData = append(sData, d)
+		// 合并处理
+		for i := range sPostion {
+			if val, ok := sGoods[sPostion[i].HEDGEGOODSID]; ok {
+				d := ErmcpExposurePostion{}
+				d.ParseFromHedgePos(val, &sPostion[i])
+				sData = append(sData, d)
+			}
+		}
+	} else {
+		// 查询头寸(子账号)
+		mp := ErmcpTradePosition{USERID: r.AREAUSERID}
+		sPostion, err1 := mp.GetData()
+		if err1 != nil || sPostion == nil || len(sPostion) == 0 {
+			return sData, err1
+		}
+		// 合并处理
+		for i := range sPostion {
+			if val, ok := sGoods[sPostion[i].GOODSID]; ok {
+				d := ErmcpExposurePostion{}
+				d.ParseFromPos(val, &sPostion[i])
+				sData = append(sData, d)
+			}
 		}
 	}
+
 	return sData, nil
 }
 
@@ -832,21 +854,43 @@ func (r *ErmcpHedgePositionDetail) Calc() {
 }
 
 func (r *ErmcpHedgePositionDetail) buildSql() string {
-	sqlId := "select t.hedgegoodsid," +
-		"       t.buyorsell," +
-		"       tradeqty," +
-		"       t.channelbuildtype," +
-		"       to_char(t.tradetime, 'yyyy-mm-dd hh24:mi:ss') tradetime," +
-		"       g.goodscode," +
-		"       g.goodsname" +
-		"  from hedge_outtradedetail t" +
-		" inner join taaccount ta" +
-		"    on t.accountid = ta.accountid" +
-		"   and ta.ismain = 1" +
-		"   and ta.relateduserid = %v" +
-		"  left join goods g" +
-		"    on t.hedgegoodsid = g.goodsid" +
-		" where t.hedgegoodsid = %v"
+	var sqlId string
+	if mtpcache.IsAreaUserId(int64(r.AREAUSERID)) {
+		// 机构查外部表
+		sqlId = "select t.hedgegoodsid," +
+			"       t.buyorsell," +
+			"       tradeqty," +
+			"       t.channelbuildtype," +
+			"       to_char(t.tradetime, 'yyyy-mm-dd hh24:mi:ss') tradetime," +
+			"       g.goodscode," +
+			"       g.goodsname" +
+			"  from hedge_outtradedetail t" +
+			" inner join taaccount ta" +
+			"    on t.accountid = ta.accountid" +
+			"   and ta.ismain = 1" +
+			"   and ta.relateduserid = %v" +
+			"  left join goods g" +
+			"    on t.hedgegoodsid = g.goodsid" +
+			" where t.hedgegoodsid = %v"
+	} else {
+		// 交易员查内部表
+		sqlId = "select t.goodsid hedgegoodsid," +
+			"       t.buyorsell," +
+			"       tradeqty," +
+			"       t.channelbuildtype," +
+			"       to_char(t.tradetime, 'yyyy-mm-dd hh24:mi:ss') tradetime," +
+			"       g.goodscode," +
+			"       g.goodsname" +
+			"  from hedge_innertradedetail t" +
+			" inner join taaccount ta" +
+			"    on t.accountid = ta.accountid" +
+			"   and ta.ismain = 1" +
+			"   and ta.relateduserid = %v" +
+			"  left join goods g" +
+			"    on t.goodsid = g.goodsid" +
+			" where t.goodsid = %v"
+	}
+
 	sqlId = fmt.Sprintf(sqlId, r.AREAUSERID, r.HEDGEGOODSID)
 	return sqlId
 }

+ 26 - 3
models/qhj.go

@@ -308,6 +308,10 @@ type UserReceiveInfo struct {
 	DISTRICTID   int32  `json:"districtid"  xorm:"DISTRICTID"`     // 地区
 	ISDEFAULT    int32  `json:"isdefault"  xorm:"ISDEFAULT"`       // 是否默认地址 - 0:否 1:是
 	HASENCRYPT   int32  `json:"hasencrypt"  xorm:"HASENCRYPT"`     // 数据是否已加密 - 0:未加密 1:已加密
+	COUNTRYNAME  string `json:"countryname"`                       // 国家名称
+	CITYNAME     string `json:"cityname"`                          // 城市名称
+	PROVINCENAME string `json:"provincename"`                      // 省名称
+	DISTRICTNAME string `json:"districtname"`                      // 地区名称
 }
 
 func (r *UserReceiveInfo) calc() {
@@ -318,6 +322,10 @@ func (r *UserReceiveInfo) calc() {
 	if len(r.PHONENUM) > 16 {
 		r.PHONENUM = DecryptField(r.PHONENUM)
 	}
+	r.COUNTRYNAME = mtpcache.GetDivisionName(r.COUNTRYID)
+	r.CITYNAME = mtpcache.GetDivisionName(r.CITYID)
+	r.PROVINCENAME = mtpcache.GetDivisionName(r.PROVINCEID)
+	r.DISTRICTNAME = mtpcache.GetDivisionName(r.DISTRICTID)
 }
 
 func (r *UserReceiveInfo) buildSql() string {
@@ -438,16 +446,26 @@ type QhjTradeGoodsPickup struct {
 	PREPAREDAYS          int32   `json:"preparedays"  xorm:"PREPAREDAYS"`                   // 备货期(天)-提货单明细表
 	PICKUPGOODSNAME      string  `json:"pickupgoodsname"  xorm:"PICKUPGOODSNAME"`           // 提货商品名称
 	PICKUPGOODSUNITID    int32   `json:"pickupgoodsunitid"  xorm:"PICKUPGOODSUNITID"`       // 单位ID(提货商品)
+	GOODSNAME            string  `json:"goodsname"  xorm:"'GOODSNAME'"`                     // 商品名称
+	GOODSCODE            string  `json:"goodscode"  xorm:"'GOODSCODE'"`                     // 商品代码
 
 	ENUMDICNAME   string `json:"enumdicname"`   // 单位名称(提货商品)
 	USERNAME      string `json:"username"`      // 用户名称
 	STOREUSERNAME string `json:"storeusername"` // 门店用户名称
+	COUNTRYNAME   string `json:"countryname"`   // 国家名称
+	CITYNAME      string `json:"cityname"`      // 城市名称
+	PROVINCENAME  string `json:"provincename"`  // 省名称
+	DISTRICTNAME  string `json:"districtname"`  // 地区名称
 }
 
 func (r *QhjTradeGoodsPickup) calc() {
 	r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.PICKUPGOODSUNITID)
 	r.STOREUSERNAME = mtpcache.GetUserNameByUserId(r.STOREUSERID)
 	r.USERNAME = mtpcache.GetUserNameByUserId(r.USERID)
+	r.COUNTRYNAME = mtpcache.GetDivisionName(r.COUNTRYID)
+	r.CITYNAME = mtpcache.GetDivisionName(r.CITYID)
+	r.PROVINCENAME = mtpcache.GetDivisionName(r.PROVINCEID)
+	r.DISTRICTNAME = mtpcache.GetDivisionName(r.DISTRICTID)
 }
 
 func (r *QhjTradeGoodsPickup) buildSql() string {
@@ -491,10 +509,15 @@ func (r *QhjTradeGoodsPickup) buildSql() string {
 		"       k.GOODSQTY," +
 		"       k.PREPAREDAYS," +
 		"       g.PICKUPGOODSNAME," +
-		"       g.PICKUPGOODSUNITID" +
+		"       g.PICKUPGOODSUNITID," +
+		"       g2.goodsname," +
+		"       g2.goodscode" +
 		"  FROM TRADE_GOODSPICKUP t" +
-		"  LEFT JOIN TRADE_GOODSPICKUPDETAIL k on t.takeorderid = k.takeorderid" +
-		"  LEFT JOIN PICKUPGOODS g on k.pickupgoodsid=g.pickupgoodsid" +
+		"  LEFT JOIN TRADE_GOODSPICKUPDETAIL k" +
+		"    on t.takeorderid = k.takeorderid" +
+		"  LEFT JOIN PICKUPGOODS g" +
+		"    on k.pickupgoodsid = g.pickupgoodsid" +
+		"  LEFT JOIN GOODS g2 on t.goodsid=g2.goodsid" +
 		" WHERE 1 = 1"
 	sqlId.And("t.USERID", r.USERID)
 	return sqlId.String()

+ 87 - 0
mtpcache/division.go

@@ -0,0 +1,87 @@
+/**
+* @Author: zou.yingbin
+* @Create  : 2021/6/3 15:14
+* @Modify  : 2021/6/3 15:14
+ */
+
+package mtpcache
+
+import (
+	"mtp2_if/db"
+	"sync"
+	"time"
+)
+
+var vDivisionMgr DivisionMgr
+
+// DivisionMgr 行政区域缓存
+type DivisionMgr struct {
+	mtx  sync.RWMutex
+	data map[int64]Division
+	last time.Time
+}
+
+// Division 行政区域表
+type Division struct {
+	Autoid        int64     `json:"autoid"  xorm:"'AUTOID'" binding:"required"`             // 自增ID
+	Divisioncode  string    `json:"divisioncode"  xorm:"'DIVISIONCODE'" binding:"required"` // 行政代码
+	Shortcode     string    `json:"shortcode"  xorm:"'SHORTCODE'"`                          // 地区简码
+	Parentcode    string    `json:"parentcode"  xorm:"'PARENTCODE'"`                        // 上级行政代码
+	Divisionlevel string    `json:"divisionlevel"  xorm:"'DIVISIONLEVEL'"`                  // 行政级别
+	Divisionname  string    `json:"divisionname"  xorm:"'DIVISIONNAME'"`                    // 行政名称
+	Pathname      string    `json:"pathname"  xorm:"'PATHNAME'"`                            // 路径名称
+	Separablename string    `json:"separablename"  xorm:"'SEPARABLENAME'"`                  // 可拆分的全称
+	Postcode      string    `json:"postcode"  xorm:"'POSTCODE'"`                            // 邮政编码
+	Modifytime    time.Time `json:"modifytime"  xorm:"'MODIFYTIME'"`                        // 修改时间
+	Modifierid    int64     `json:"modifierid"  xorm:"'MODIFIERID'"`                        // 修改人
+}
+
+// TableName is DIVISION
+func (Division) TableName() string {
+	return "DIVISION"
+}
+
+func init() {
+	go func() {
+		time.Sleep(time.Second * 2)
+		vDivisionMgr.load()
+	}()
+}
+
+func (r *DivisionMgr) load() {
+	now := time.Now()
+	// 间隔3秒以上才重新加载
+	if d := now.Sub(r.last); d.Seconds() < 3 {
+		return
+	}
+	r.mtx.Lock()
+	defer r.mtx.Unlock()
+	engine := db.GetEngine()
+
+	divisions := make([]Division, 0)
+	if err := engine.Find(&divisions); err == nil {
+		r.data = map[int64]Division{}
+		for i := range divisions {
+			r.data[divisions[i].Autoid] = divisions[i]
+		}
+	}
+}
+
+// Name 获取行政区名称
+func (r *DivisionMgr) Name(Id int64) string {
+	r.mtx.RLock()
+	defer r.mtx.RUnlock()
+	if d, ok := r.data[Id]; ok {
+		return d.Divisionname
+	}
+	return ""
+}
+
+// 获取行政区名称
+func GetDivisionName(Id int32) string {
+	if strName := vDivisionMgr.Name(int64(Id)); strName != "" {
+		return strName
+	}
+	vDivisionMgr.load()
+	return vDivisionMgr.Name(int64(Id))
+}

+ 6 - 0
mtpcache/useraccount.go

@@ -191,3 +191,9 @@ func GetAreaUserId(userId int64, userType int32) (areaUserId int64) {
 	}
 	return
 }
+
+// IsAreaUserId 是否是机构id
+func IsAreaUserId(userId int64) bool {
+	areaUserId := GetAreaUserId(userId, 0)
+	return areaUserId == userId
+}