Prechádzať zdrojové kódy

1.实时敞口改为从数据库查(之前从redis查)
2. fix bug: #94381 #93892

zou.yingbin 4 rokov pred
rodič
commit
6203eea4ba

+ 1 - 1
controllers/ermcp/qryExposure.go

@@ -45,7 +45,7 @@ func QueryRealtimeExposure(c *gin.Context) {
 	}
 
 	m := models.ErmcpRealExposureModel{AreaUserID: req.AreaUserID}
-	if d, err := m.GetData(); err == nil {
+	if d, err := m.GetDataEx(); err == nil {
 		appG.Response(http.StatusOK, e.SUCCESS, d)
 	} else {
 		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)

+ 44 - 44
docs/docs.go

@@ -12473,121 +12473,121 @@ var doc = `{
         "models.ErmcpRealExposureModel": {
             "type": "object",
             "properties": {
-                "areaUserID": {
+                "AreaUserID": {
                     "description": "所属机构",
                     "type": "integer"
                 },
-                "buyFutureQty": {
+                "BuyFutureQty": {
                     "description": "买入期货数量",
                     "type": "number"
                 },
-                "buyPlanQty": {
+                "BuyPlanQty": {
                     "description": "采购计划数量",
                     "type": "number"
                 },
-                "buyPricedQty": {
+                "BuyPricedQty": {
                     "description": "采购合同已定价数量",
                     "type": "number"
                 },
-                "diffFutuQty": {
-                    "description": "今日变动量(期货) = (买入 - 买入期初) - (卖出 - 卖出期初)",
-                    "type": "number"
-                },
-                "diffSpotQty": {
-                    "description": "今日变动量(现货) = 现货数量 - 期初现货数量",
-                    "type": "number"
-                },
-                "enumdicname": {
-                    "description": "单位名称",
-                    "type": "string"
-                },
-                "middleGoodsCode": {
+                "MiddleGoodsCode": {
                     "description": "套保品种代码",
                     "type": "string"
                 },
-                "middleGoodsHedgeRatio": {
+                "MiddleGoodsHedgeRatio": {
                     "description": "应套保比例",
                     "type": "number"
                 },
-                "middleGoodsID": {
+                "MiddleGoodsID": {
                     "description": "套保品种",
                     "type": "integer"
                 },
-                "middleGoodsName": {
+                "MiddleGoodsName": {
                     "description": "套保品种名称",
                     "type": "string"
                 },
-                "needHedgeExposoure": {
+                "NeedHedgeExposoure": {
                     "description": "应套保敞口",
                     "type": "number"
                 },
-                "needHedgeRatio": {
+                "NeedHedgeRatio": {
                     "description": "应套保敞口比例",
                     "type": "number"
                 },
-                "oriBuyFutureQty": {
+                "OriBuyFutureQty": {
                     "description": "期初买入期货数量",
                     "type": "number"
                 },
-                "oriBuyPlanQty": {
+                "OriBuyPlanQty": {
                     "description": "期初采购计划数量",
                     "type": "number"
                 },
-                "oriBuyPricedQty": {
+                "OriBuyPricedQty": {
                     "description": "期初采购合同已定价数量",
                     "type": "number"
                 },
-                "oriSellFutureQty": {
+                "OriSellFutureQty": {
                     "description": "期初卖出期货数量",
                     "type": "number"
                 },
-                "oriSellPlanQty": {
+                "OriSellPlanQty": {
                     "description": "期初销售计划数量",
                     "type": "number"
                 },
-                "oriSellPricedQty": {
+                "OriSellPricedQty": {
                     "description": "期初销售合同已定价数量",
                     "type": "number"
                 },
-                "oriTotalFutuQty": {
-                    "description": "期初期货数量=期初买入期货数量-期初卖出期货数量",
-                    "type": "number"
-                },
-                "oriTotalSpotQty": {
-                    "description": "期初现货数量=(期初销售计划数量-期初销售合同已定价数量)-(期初采购计划数量-期初采购合同已定价数量)",
-                    "type": "number"
-                },
-                "sellFutureQty": {
+                "SellFutureQty": {
                     "description": "卖出期货数量",
                     "type": "number"
                 },
-                "sellPlanQty": {
+                "SellPlanQty": {
                     "description": "销售计划数量",
                     "type": "number"
                 },
-                "sellPricedQty": {
+                "SellPricedQty": {
                     "description": "销售合同已定价数量",
                     "type": "number"
                 },
-                "totalExposure": {
+                "TotalExposure": {
                     "description": "总敞口",
                     "type": "number"
                 },
-                "totalFutureQty": {
+                "TotalFutureQty": {
                     "description": "期货数量",
                     "type": "number"
                 },
-                "totalHedgeRatio": {
+                "TotalHedgeRatio": {
                     "description": "敞口比例",
                     "type": "number"
                 },
-                "totalNeedHedgeQty": {
+                "TotalNeedHedgeQty": {
                     "description": "期货应套保量",
                     "type": "number"
                 },
-                "totalSpotQty": {
+                "TotalSpotQty": {
                     "description": "现货数量",
                     "type": "number"
+                },
+                "diffFutuQty": {
+                    "description": "今日变动量(期货) = (买入 - 买入期初) - (卖出 - 卖出期初)",
+                    "type": "number"
+                },
+                "diffSpotQty": {
+                    "description": "今日变动量(现货) = 现货数量 - 期初现货数量",
+                    "type": "number"
+                },
+                "enumdicname": {
+                    "description": "单位名称",
+                    "type": "string"
+                },
+                "oriTotalFutuQty": {
+                    "description": "期初期货数量=期初买入期货数量-期初卖出期货数量",
+                    "type": "number"
+                },
+                "oriTotalSpotQty": {
+                    "description": "期初现货数量=(期初销售计划数量-期初销售合同已定价数量)-(期初采购计划数量-期初采购合同已定价数量)",
+                    "type": "number"
                 }
             }
         },

+ 44 - 44
docs/swagger.json

@@ -12457,121 +12457,121 @@
         "models.ErmcpRealExposureModel": {
             "type": "object",
             "properties": {
-                "areaUserID": {
+                "AreaUserID": {
                     "description": "所属机构",
                     "type": "integer"
                 },
-                "buyFutureQty": {
+                "BuyFutureQty": {
                     "description": "买入期货数量",
                     "type": "number"
                 },
-                "buyPlanQty": {
+                "BuyPlanQty": {
                     "description": "采购计划数量",
                     "type": "number"
                 },
-                "buyPricedQty": {
+                "BuyPricedQty": {
                     "description": "采购合同已定价数量",
                     "type": "number"
                 },
-                "diffFutuQty": {
-                    "description": "今日变动量(期货) = (买入 - 买入期初) - (卖出 - 卖出期初)",
-                    "type": "number"
-                },
-                "diffSpotQty": {
-                    "description": "今日变动量(现货) = 现货数量 - 期初现货数量",
-                    "type": "number"
-                },
-                "enumdicname": {
-                    "description": "单位名称",
-                    "type": "string"
-                },
-                "middleGoodsCode": {
+                "MiddleGoodsCode": {
                     "description": "套保品种代码",
                     "type": "string"
                 },
-                "middleGoodsHedgeRatio": {
+                "MiddleGoodsHedgeRatio": {
                     "description": "应套保比例",
                     "type": "number"
                 },
-                "middleGoodsID": {
+                "MiddleGoodsID": {
                     "description": "套保品种",
                     "type": "integer"
                 },
-                "middleGoodsName": {
+                "MiddleGoodsName": {
                     "description": "套保品种名称",
                     "type": "string"
                 },
-                "needHedgeExposoure": {
+                "NeedHedgeExposoure": {
                     "description": "应套保敞口",
                     "type": "number"
                 },
-                "needHedgeRatio": {
+                "NeedHedgeRatio": {
                     "description": "应套保敞口比例",
                     "type": "number"
                 },
-                "oriBuyFutureQty": {
+                "OriBuyFutureQty": {
                     "description": "期初买入期货数量",
                     "type": "number"
                 },
-                "oriBuyPlanQty": {
+                "OriBuyPlanQty": {
                     "description": "期初采购计划数量",
                     "type": "number"
                 },
-                "oriBuyPricedQty": {
+                "OriBuyPricedQty": {
                     "description": "期初采购合同已定价数量",
                     "type": "number"
                 },
-                "oriSellFutureQty": {
+                "OriSellFutureQty": {
                     "description": "期初卖出期货数量",
                     "type": "number"
                 },
-                "oriSellPlanQty": {
+                "OriSellPlanQty": {
                     "description": "期初销售计划数量",
                     "type": "number"
                 },
-                "oriSellPricedQty": {
+                "OriSellPricedQty": {
                     "description": "期初销售合同已定价数量",
                     "type": "number"
                 },
-                "oriTotalFutuQty": {
-                    "description": "期初期货数量=期初买入期货数量-期初卖出期货数量",
-                    "type": "number"
-                },
-                "oriTotalSpotQty": {
-                    "description": "期初现货数量=(期初销售计划数量-期初销售合同已定价数量)-(期初采购计划数量-期初采购合同已定价数量)",
-                    "type": "number"
-                },
-                "sellFutureQty": {
+                "SellFutureQty": {
                     "description": "卖出期货数量",
                     "type": "number"
                 },
-                "sellPlanQty": {
+                "SellPlanQty": {
                     "description": "销售计划数量",
                     "type": "number"
                 },
-                "sellPricedQty": {
+                "SellPricedQty": {
                     "description": "销售合同已定价数量",
                     "type": "number"
                 },
-                "totalExposure": {
+                "TotalExposure": {
                     "description": "总敞口",
                     "type": "number"
                 },
-                "totalFutureQty": {
+                "TotalFutureQty": {
                     "description": "期货数量",
                     "type": "number"
                 },
-                "totalHedgeRatio": {
+                "TotalHedgeRatio": {
                     "description": "敞口比例",
                     "type": "number"
                 },
-                "totalNeedHedgeQty": {
+                "TotalNeedHedgeQty": {
                     "description": "期货应套保量",
                     "type": "number"
                 },
-                "totalSpotQty": {
+                "TotalSpotQty": {
                     "description": "现货数量",
                     "type": "number"
+                },
+                "diffFutuQty": {
+                    "description": "今日变动量(期货) = (买入 - 买入期初) - (卖出 - 卖出期初)",
+                    "type": "number"
+                },
+                "diffSpotQty": {
+                    "description": "今日变动量(现货) = 现货数量 - 期初现货数量",
+                    "type": "number"
+                },
+                "enumdicname": {
+                    "description": "单位名称",
+                    "type": "string"
+                },
+                "oriTotalFutuQty": {
+                    "description": "期初期货数量=期初买入期货数量-期初卖出期货数量",
+                    "type": "number"
+                },
+                "oriTotalSpotQty": {
+                    "description": "期初现货数量=(期初销售计划数量-期初销售合同已定价数量)-(期初采购计划数量-期初采购合同已定价数量)",
+                    "type": "number"
                 }
             }
         },

+ 39 - 39
docs/swagger.yaml

@@ -4073,93 +4073,93 @@ definitions:
     type: object
   models.ErmcpRealExposureModel:
     properties:
-      areaUserID:
+      AreaUserID:
         description: 所属机构
         type: integer
-      buyFutureQty:
+      BuyFutureQty:
         description: 买入期货数量
         type: number
-      buyPlanQty:
+      BuyPlanQty:
         description: 采购计划数量
         type: number
-      buyPricedQty:
+      BuyPricedQty:
         description: 采购合同已定价数量
         type: number
-      diffFutuQty:
-        description: 今日变动量(期货) = (买入 - 买入期初) - (卖出 - 卖出期初)
-        type: number
-      diffSpotQty:
-        description: 今日变动量(现货) = 现货数量 - 期初现货数量
-        type: number
-      enumdicname:
-        description: 单位名称
-        type: string
-      middleGoodsCode:
+      MiddleGoodsCode:
         description: 套保品种代码
         type: string
-      middleGoodsHedgeRatio:
+      MiddleGoodsHedgeRatio:
         description: 应套保比例
         type: number
-      middleGoodsID:
+      MiddleGoodsID:
         description: 套保品种
         type: integer
-      middleGoodsName:
+      MiddleGoodsName:
         description: 套保品种名称
         type: string
-      needHedgeExposoure:
+      NeedHedgeExposoure:
         description: 应套保敞口
         type: number
-      needHedgeRatio:
+      NeedHedgeRatio:
         description: 应套保敞口比例
         type: number
-      oriBuyFutureQty:
+      OriBuyFutureQty:
         description: 期初买入期货数量
         type: number
-      oriBuyPlanQty:
+      OriBuyPlanQty:
         description: 期初采购计划数量
         type: number
-      oriBuyPricedQty:
+      OriBuyPricedQty:
         description: 期初采购合同已定价数量
         type: number
-      oriSellFutureQty:
+      OriSellFutureQty:
         description: 期初卖出期货数量
         type: number
-      oriSellPlanQty:
+      OriSellPlanQty:
         description: 期初销售计划数量
         type: number
-      oriSellPricedQty:
+      OriSellPricedQty:
         description: 期初销售合同已定价数量
         type: number
-      oriTotalFutuQty:
-        description: 期初期货数量=期初买入期货数量-期初卖出期货数量
-        type: number
-      oriTotalSpotQty:
-        description: 期初现货数量=(期初销售计划数量-期初销售合同已定价数量)-(期初采购计划数量-期初采购合同已定价数量)
-        type: number
-      sellFutureQty:
+      SellFutureQty:
         description: 卖出期货数量
         type: number
-      sellPlanQty:
+      SellPlanQty:
         description: 销售计划数量
         type: number
-      sellPricedQty:
+      SellPricedQty:
         description: 销售合同已定价数量
         type: number
-      totalExposure:
+      TotalExposure:
         description: 总敞口
         type: number
-      totalFutureQty:
+      TotalFutureQty:
         description: 期货数量
         type: number
-      totalHedgeRatio:
+      TotalHedgeRatio:
         description: 敞口比例
         type: number
-      totalNeedHedgeQty:
+      TotalNeedHedgeQty:
         description: 期货应套保量
         type: number
-      totalSpotQty:
+      TotalSpotQty:
         description: 现货数量
         type: number
+      diffFutuQty:
+        description: 今日变动量(期货) = (买入 - 买入期初) - (卖出 - 卖出期初)
+        type: number
+      diffSpotQty:
+        description: 今日变动量(现货) = 现货数量 - 期初现货数量
+        type: number
+      enumdicname:
+        description: 单位名称
+        type: string
+      oriTotalFutuQty:
+        description: 期初期货数量=期初买入期货数量-期初卖出期货数量
+        type: number
+      oriTotalSpotQty:
+        description: 期初现货数量=(期初销售计划数量-期初销售合同已定价数量)-(期初采购计划数量-期初采购合同已定价数量)
+        type: number
     type: object
   models.ErmcpReportDayExposure:
     properties:

+ 79 - 31
models/ermcpExposure.go

@@ -13,40 +13,42 @@ import (
 	"mtp2_if/mtpcache"
 	"mtp2_if/pb"
 	"mtp2_if/rediscli"
+	"mtp2_if/utils"
 )
 
 // ErmcpRealExposureModel 实时敞口
 type ErmcpRealExposureModel struct {
-	MiddleGoodsID      uint32  // 套保品种
-	AreaUserID         uint32  // 所属机构
-	OriBuyPlanQty      float64 // 期初采购计划数量
-	OriBuyPricedQty    float64 // 期初采购合同已定价数量
-	OriSellPlanQty     float64 // 期初销售计划数量
-	OriSellPricedQty   float64 // 期初销售合同已定价数量
-	OriBuyFutureQty    float64 // 期初买入期货数量
-	OriSellFutureQty   float64 // 期初卖出期货数量
-	BuyPlanQty         float64 // 采购计划数量
-	BuyPricedQty       float64 // 采购合同已定价数量
-	SellPlanQty        float64 // 销售计划数量
-	SellPricedQty      float64 // 销售合同已定价数量
-	BuyFutureQty       float64 // 买入期货数量
-	SellFutureQty      float64 // 卖出期货数量
-	TotalSpotQty       float64 // 现货数量
-	TotalFutureQty     float64 // 期货数量
-	TotalExposure      float64 // 总敞口
-	TotalHedgeRatio    float64 // 敞口比例
-	TotalNeedHedgeQty  float64 // 期货应套保量
-	NeedHedgeExposoure float64 // 应套保敞口
-	NeedHedgeRatio     float64 // 应套保敞口比例
-
-	MiddleGoodsName       string  // 套保品种名称
-	MiddleGoodsCode       string  // 套保品种代码
-	MiddleGoodsHedgeRatio float64 // 应套保比例
-	OriTotalSpotQty       float64 // 期初现货数量=(期初销售计划数量-期初销售合同已定价数量)-(期初采购计划数量-期初采购合同已定价数量)
-	OriTotalFutuQty       float64 // 期初期货数量=期初买入期货数量-期初卖出期货数量
-	DiffSpotQty           float64 // 今日变动量(现货) = 现货数量 - 期初现货数量
-	DiffFutuQty           float64 // 今日变动量(期货) = (买入 - 买入期初) - (卖出 - 卖出期初)
-	ENUMDICNAME           string  // 单位名称
+	MiddleGoodsID         uint32  `json:"MiddleGoodsID"  xorm:"'MiddleGoodsID'"`           // 套保品种
+	AreaUserID            uint32  `json:"AreaUserID"  xorm:"'AreaUserID'"`                 // 所属机构
+	OriBuyPlanQty         float64 `json:"OriBuyPlanQty"  xorm:"'OriBuyPlanQty'"`           // 期初采购计划数量
+	OriBuyPricedQty       float64 `json:"OriBuyPricedQty"  xorm:"'OriBuyPricedQty'"`       // 期初采购合同已定价数量
+	OriSellPlanQty        float64 `json:"OriSellPlanQty"  xorm:"'OriSellPlanQty'"`         // 期初销售计划数量
+	OriSellPricedQty      float64 `json:"OriSellPricedQty"  xorm:"'OriSellPricedQty'"`     // 期初销售合同已定价数量
+	OriBuyFutureQty       float64 `json:"OriBuyFutureQty"  xorm:"'OriBuyFutureQty'"`       // 期初买入期货数量
+	OriSellFutureQty      float64 `json:"OriSellFutureQty"  xorm:"'OriSellFutureQty'"`     // 期初卖出期货数量
+	BuyPlanQty            float64 `json:"BuyPlanQty"  xorm:"'BuyPlanQty'"`                 // 采购计划数量
+	BuyPricedQty          float64 `json:"BuyPricedQty"  xorm:"'BuyPricedQty'"`             // 采购合同已定价数量
+	SellPlanQty           float64 `json:"SellPlanQty"  xorm:"'SellPlanQty'"`               // 销售计划数量
+	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'"`         // 期货数量
+	TotalExposure         float64 `json:"TotalExposure"  xorm:"'TotalExposure'"`           // 总敞口
+	TotalHedgeRatio       float64 `json:"TotalHedgeRatio"  xorm:"'TotalHedgeRatio'"`       // 敞口比例
+	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'"`  // 应套保比例
+
+	OriTotalSpotQty float64 // 期初现货数量=(期初销售计划数量-期初销售合同已定价数量)-(期初采购计划数量-期初采购合同已定价数量)
+	OriTotalFutuQty float64 // 期初期货数量=期初买入期货数量-期初卖出期货数量
+	DiffSpotQty     float64 // 今日变动量(现货) = 现货数量 - 期初现货数量
+	DiffFutuQty     float64 // 今日变动量(期货) = (买入 - 买入期初) - (卖出 - 卖出期初)
+	ENUMDICNAME     string  // 单位名称
 }
 
 // calc 计算相关字段
@@ -55,6 +57,42 @@ func (r *ErmcpRealExposureModel) calc() {
 	r.OriTotalFutuQty = r.OriBuyFutureQty - r.OriSellFutureQty
 	r.DiffSpotQty = r.TotalSpotQty - r.OriTotalSpotQty
 	r.DiffFutuQty = (r.BuyFutureQty - r.OriBuyFutureQty) - (r.SellFutureQty - r.OriSellFutureQty)
+	if r.ENUMDICNAME == "" {
+		r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.GOODSUNITID)
+	}
+}
+func (r *ErmcpRealExposureModel) buildSql() string {
+	var sqlId utils.SQLVal = "select t.MiddleGoodsID," +
+		"       t.AreaUserID," +
+		"       t.OriBuyPlanQty," +
+		"       t.OriBuyPricedQty," +
+		"       t.OriSellPlanQty," +
+		"       t.OriSellPricedQty," +
+		"       t.OriBuyFutureQty," +
+		"       t.OriSellFutureQty," +
+		"       t.BuyPlanQty," +
+		"       t.BuyPricedQty," +
+		"       t.SellPlanQty," +
+		"       t.SellPricedQty," +
+		"       t.BuyFutureQty," +
+		"       t.SellFutureQty," +
+		"       t.TotalSpotQty," +
+		"       t.TotalFutureQty," +
+		"       t.TotalExposure," +
+		"       t.TotalHedgeRatio," +
+		"       t.TotalNeedHedgeQty," +
+		"       t.NeedHedgeExposoure," +
+		"       t.NeedHedgeRatio," +
+		"       g.middlegoodsname," +
+		"       g.middlegoodscode," +
+		"       g.goodsunitid," +
+		"       g.needhedgeratio" +
+		"  from ermcp_areaexposure t" +
+		"  left join erms_middlegoods g" +
+		"    on t.middlegoodsid = g.middlegoodsid" +
+		" where 1 = 1"
+	sqlId.And("t.AreaUserID", r.AreaUserID)
+	return sqlId.String()
 }
 
 // ParseFromProto 从协议中获取数据
@@ -112,6 +150,16 @@ func (r *ErmcpRealExposureModel) GetData() ([]ErmcpRealExposureModel, error) {
 	return nil, nil
 }
 
+// GetDataEx 从数据库中查询实时敞口
+func (r *ErmcpRealExposureModel) GetDataEx() (interface{}, error) {
+	sData := make([]ErmcpRealExposureModel, 0)
+	err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
+	for i := range sData {
+		sData[i].calc()
+	}
+	return sData, err
+}
+
 /*************敞口明细**************/
 
 // ErmcpExposureDetailModel 敞口现货明细结构
@@ -326,7 +374,7 @@ func (r *ErmcpAreaSpotDetailModel) buildSql() string {
 		"       t.LogType," +
 		"       tmp.contracttype," +
 		"       t.RealQty qty," +
-		"       to_char(t.createtime, 'yyyy-mm-dd hh:mi:ss') createtime," +
+		"       to_char(t.createtime, 'yyyy-mm-dd hh24:mi:ss') createtime," +
 		"       w.wrstandardname," +
 		"       w.wrstandardcode," +
 		"       w.unitid" +

+ 2 - 2
models/ermcpPendingAuditInfo.go

@@ -46,8 +46,8 @@ func (r *ErmcpPendingAudit) buildSql() string {
 		" union all " +
 		"select 7, count(1) BusinessFpQty from ermcp_contractoperateapply t where t.userid = %v and t.applystatus = 1 and t.operateapplytype=4" +
 		" union all " +
-		"select 8, count(1) AreaStockQty from ermcp_areainoutstockapply t where t.ApplyStatus = 1"
-	sqlId = fmt.Sprintf(sqlId, r.UserId, r.UserId, r.UserId, r.UserId, r.UserId, r.UserId, r.UserId)
+		"select 8, count(1) AreaStockQty from ermcp_areainoutstockapply t where t.userid = %v and t.ApplyStatus = 1"
+	sqlId = fmt.Sprintf(sqlId, r.UserId, r.UserId, r.UserId, r.UserId, r.UserId, r.UserId, r.UserId, r.UserId)
 	return sqlId
 }