Browse Source

查套保/现货商品详情增加层级

zou.yingbin 4 years ago
parent
commit
3f2d8daac6
4 changed files with 210 additions and 59 deletions
  1. 45 17
      docs/docs.go
  2. 45 17
      docs/swagger.json
  3. 35 15
      docs/swagger.yaml
  4. 85 10
      models/ermcp3.go

+ 45 - 17
docs/docs.go

@@ -14148,11 +14148,11 @@ var doc = `{
                 }
             }
         },
-        "models.Ermcp3GoodsEx": {
+        "models.Ermcp3Goods": {
             "type": "object",
             "properties": {
-                "convertratio": {
-                    "description": "折算系数(品种系数)",
+                "agreeunit": {
+                    "description": "合约单位(合约乘数)",
                     "type": "number"
                 },
                 "enumdicname": {
@@ -14174,14 +14174,6 @@ var doc = `{
                 "goodsname": {
                     "description": "期货商品名称",
                     "type": "string"
-                },
-                "goodunitid": {
-                    "description": "期货商品单位id",
-                    "type": "integer"
-                },
-                "middlegoodsid": {
-                    "description": "套保商品id",
-                    "type": "integer"
                 }
             }
         },
@@ -14289,6 +14281,42 @@ var doc = `{
                 }
             }
         },
+        "models.Ermcp3GoodsGroupEx": {
+            "type": "object",
+            "properties": {
+                "convertratio": {
+                    "description": "折算系数(品种系数)",
+                    "type": "number"
+                },
+                "enumdicname": {
+                    "description": "单位名称",
+                    "type": "string"
+                },
+                "exexchangecode": {
+                    "description": "交易所代码",
+                    "type": "string"
+                },
+                "glist": {
+                    "description": "合约列表",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/models.Ermcp3Goods"
+                    }
+                },
+                "goodsgroupid": {
+                    "description": "商品组id",
+                    "type": "integer"
+                },
+                "goodsgroupname": {
+                    "description": "商品组名称",
+                    "type": "string"
+                },
+                "middlegoodsid": {
+                    "description": "套保商品id",
+                    "type": "integer"
+                }
+            }
+        },
         "models.Ermcp3HedgePlan": {
             "type": "object",
             "properties": {
@@ -14373,11 +14401,11 @@ var doc = `{
         "models.Ermcp3MiddleGoodsDetail": {
             "type": "object",
             "properties": {
-                "glist": {
-                    "description": "关联商品列表",
+                "gplist": {
+                    "description": "关联商品列表",
                     "type": "array",
                     "items": {
-                        "$ref": "#/definitions/models.Ermcp3GoodsEx"
+                        "$ref": "#/definitions/models.Ermcp3GoodsGroupEx"
                     }
                 },
                 "mg": {
@@ -14397,11 +14425,11 @@ var doc = `{
                         "$ref": "#/definitions/models.ErmcpDeliveryGoodsDetail"
                     }
                 },
-                "glist": {
-                    "description": "关联商品列表",
+                "gplist": {
+                    "description": "关联商品列表",
                     "type": "array",
                     "items": {
-                        "$ref": "#/definitions/models.Ermcp3GoodsEx"
+                        "$ref": "#/definitions/models.Ermcp3GoodsGroupEx"
                     }
                 },
                 "mg": {

+ 45 - 17
docs/swagger.json

@@ -14132,11 +14132,11 @@
                 }
             }
         },
-        "models.Ermcp3GoodsEx": {
+        "models.Ermcp3Goods": {
             "type": "object",
             "properties": {
-                "convertratio": {
-                    "description": "折算系数(品种系数)",
+                "agreeunit": {
+                    "description": "合约单位(合约乘数)",
                     "type": "number"
                 },
                 "enumdicname": {
@@ -14158,14 +14158,6 @@
                 "goodsname": {
                     "description": "期货商品名称",
                     "type": "string"
-                },
-                "goodunitid": {
-                    "description": "期货商品单位id",
-                    "type": "integer"
-                },
-                "middlegoodsid": {
-                    "description": "套保商品id",
-                    "type": "integer"
                 }
             }
         },
@@ -14273,6 +14265,42 @@
                 }
             }
         },
+        "models.Ermcp3GoodsGroupEx": {
+            "type": "object",
+            "properties": {
+                "convertratio": {
+                    "description": "折算系数(品种系数)",
+                    "type": "number"
+                },
+                "enumdicname": {
+                    "description": "单位名称",
+                    "type": "string"
+                },
+                "exexchangecode": {
+                    "description": "交易所代码",
+                    "type": "string"
+                },
+                "glist": {
+                    "description": "合约列表",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/models.Ermcp3Goods"
+                    }
+                },
+                "goodsgroupid": {
+                    "description": "商品组id",
+                    "type": "integer"
+                },
+                "goodsgroupname": {
+                    "description": "商品组名称",
+                    "type": "string"
+                },
+                "middlegoodsid": {
+                    "description": "套保商品id",
+                    "type": "integer"
+                }
+            }
+        },
         "models.Ermcp3HedgePlan": {
             "type": "object",
             "properties": {
@@ -14357,11 +14385,11 @@
         "models.Ermcp3MiddleGoodsDetail": {
             "type": "object",
             "properties": {
-                "glist": {
-                    "description": "关联商品列表",
+                "gplist": {
+                    "description": "关联商品列表",
                     "type": "array",
                     "items": {
-                        "$ref": "#/definitions/models.Ermcp3GoodsEx"
+                        "$ref": "#/definitions/models.Ermcp3GoodsGroupEx"
                     }
                 },
                 "mg": {
@@ -14381,11 +14409,11 @@
                         "$ref": "#/definitions/models.ErmcpDeliveryGoodsDetail"
                     }
                 },
-                "glist": {
-                    "description": "关联商品列表",
+                "gplist": {
+                    "description": "关联商品列表",
                     "type": "array",
                     "items": {
-                        "$ref": "#/definitions/models.Ermcp3GoodsEx"
+                        "$ref": "#/definitions/models.Ermcp3GoodsGroupEx"
                     }
                 },
                 "mg": {

+ 35 - 15
docs/swagger.yaml

@@ -3668,10 +3668,10 @@ definitions:
         description: 现货合同/套保计划编号
         type: string
     type: object
-  models.Ermcp3GoodsEx:
+  models.Ermcp3Goods:
     properties:
-      convertratio:
-        description: 折算系数(品种系数)
+      agreeunit:
+        description: 合约单位(合约乘数)
         type: number
       enumdicname:
         description: 单位名称
@@ -3688,12 +3688,6 @@ definitions:
       goodsname:
         description: 期货商品名称
         type: string
-      goodunitid:
-        description: 期货商品单位id
-        type: integer
-      middlegoodsid:
-        description: 套保商品id
-        type: integer
     type: object
   models.Ermcp3GoodsGroup:
     properties:
@@ -3772,6 +3766,32 @@ definitions:
     required:
     - areauserid
     type: object
+  models.Ermcp3GoodsGroupEx:
+    properties:
+      convertratio:
+        description: 折算系数(品种系数)
+        type: number
+      enumdicname:
+        description: 单位名称
+        type: string
+      exexchangecode:
+        description: 交易所代码
+        type: string
+      glist:
+        description: 合约列表
+        items:
+          $ref: '#/definitions/models.Ermcp3Goods'
+        type: array
+      goodsgroupid:
+        description: 商品组id
+        type: integer
+      goodsgroupname:
+        description: 商品组名称
+        type: string
+      middlegoodsid:
+        description: 套保商品id
+        type: integer
+    type: object
   models.Ermcp3HedgePlan:
     properties:
       areauserid:
@@ -3834,10 +3854,10 @@ definitions:
     type: object
   models.Ermcp3MiddleGoodsDetail:
     properties:
-      glist:
-        description: 关联商品列表
+      gplist:
+        description: 关联商品列表
         items:
-          $ref: '#/definitions/models.Ermcp3GoodsEx'
+          $ref: '#/definitions/models.Ermcp3GoodsGroupEx'
         type: array
       mg:
         $ref: '#/definitions/models.ErmcpMiddleGoodsModel'
@@ -3851,10 +3871,10 @@ definitions:
         items:
           $ref: '#/definitions/models.ErmcpDeliveryGoodsDetail'
         type: array
-      glist:
-        description: 关联商品列表
+      gplist:
+        description: 关联商品列表
         items:
-          $ref: '#/definitions/models.Ermcp3GoodsEx'
+          $ref: '#/definitions/models.Ermcp3GoodsGroupEx'
         type: array
       mg:
         $ref: '#/definitions/models.ErmcpMiddleGoodsModel'

+ 85 - 10
models/ermcp3.go

@@ -310,8 +310,8 @@ func (r *ErmcpDeliveryGoodsDetailEx) addMgList(lst []Ermcp3MiddleGoodsDetail, wc
 
 // Ermcp3MiddleGoodsDetail 套保品种详情
 type Ermcp3MiddleGoodsDetail struct {
-	Mg    ErmcpMiddleGoodsModel `json:"mg"`    // 套保商品信息
-	GList []Ermcp3GoodsEx       `json:"glist"` // 关联商品列表
+	Mg     ErmcpMiddleGoodsModel `json:"mg"`     // 套保商品信息
+	GPList []Ermcp3GoodsGroupEx  `json:"gplist"` // 关联商品列表
 }
 
 // GetData 获取套保品种详情(不含现货列表)
@@ -321,7 +321,7 @@ func (r *Ermcp3MiddleGoodsDetail) GetData() ([]Ermcp3MiddleGoodsDetail, error) {
 	mMg := ErmcpMiddleGoodsModel{AREAUSERID: r.Mg.AREAUSERID, MIDDLEGOODSID: r.Mg.MIDDLEGOODSID, ISVALID: 1}
 	if mgLst, err := mMg.GetData2(); err == nil {
 		for i := range mgLst {
-			sData = append(sData, Ermcp3MiddleGoodsDetail{Mg: mgLst[i], GList: make([]Ermcp3GoodsEx, 0)})
+			sData = append(sData, Ermcp3MiddleGoodsDetail{Mg: mgLst[i], GPList: make([]Ermcp3GoodsGroupEx, 0)})
 		}
 	}
 	if len(sData) == 0 {
@@ -330,14 +330,58 @@ func (r *Ermcp3MiddleGoodsDetail) GetData() ([]Ermcp3MiddleGoodsDetail, error) {
 	mGoods := Ermcp3GoodsEx{AREAUSERID: r.Mg.AREAUSERID}
 	if gLst, err := mGoods.GetData(); err == nil {
 		for i := range sData {
-			for _, ex := range gLst {
-				if sData[i].Mg.MIDDLEGOODSID == ex.MIDDLEGOODSID {
-					sData[i].GList = append(sData[i].GList, ex)
+			sData[i].addGoodsGroup(gLst)
+		}
+		for i := range sData {
+			sData[i].addGoods(gLst)
+		}
+	}
+	return sData, nil
+}
+
+func (r *Ermcp3MiddleGoodsDetail) addGoodsGroup(gpLst []Ermcp3GoodsEx) {
+	for i := range gpLst {
+		if gpLst[i].MIDDLEGOODSID == r.Mg.MIDDLEGOODSID {
+			bExist := false
+			for _, v := range r.GPList {
+				if v.GOODSGROUPID == gpLst[i].GOODSGROUPID {
+					bExist = true
+					break
+				}
+			}
+			if !bExist {
+				val := Ermcp3GoodsGroupEx{
+					GOODSGROUPID:   gpLst[i].GOODSGROUPID,
+					MIDDLEGOODSID:  gpLst[i].MIDDLEGOODSID,
+					CONVERTRATIO:   gpLst[i].CONVERTRATIO,
+					EXEXCHANGECODE: gpLst[i].EXEXCHANGECODE,
+					GOODSGROUPNAME: gpLst[i].GOODSGROUPNAME,
+					ENUMDICNAME:    gpLst[i].ENUMDICNAME,
+					GList:          make([]Ermcp3Goods, 0),
+				}
+				r.GPList = append(r.GPList, val)
+			}
+		}
+	}
+}
+
+func (r *Ermcp3MiddleGoodsDetail) addGoods(gpLst []Ermcp3GoodsEx) {
+	for i := range gpLst {
+		if gpLst[i].MIDDLEGOODSID == r.Mg.MIDDLEGOODSID {
+			for k := range r.GPList {
+				if r.GPList[k].GOODSGROUPID == gpLst[i].GOODSGROUPID {
+					r.GPList[k].GList = append(r.GPList[k].GList, Ermcp3Goods{
+						GOODSID:        gpLst[i].GOODSID,
+						GOODSNAME:      gpLst[i].GOODSNAME,
+						GOODSCODE:      gpLst[i].GOODSCODE,
+						AGREEUNIT:      gpLst[i].AGREEUNIT,
+						EXEXCHANGECODE: gpLst[i].EXEXCHANGECODE,
+						ENUMDICNAME:    gpLst[i].ENUMDICNAME,
+					})
 				}
 			}
 		}
 	}
-	return sData, nil
 }
 
 // Ermcp3MiddleGoodsDetailEx 套保品种详情(含现货列表)
@@ -384,6 +428,27 @@ func (r *Ermcp3MiddleGoodsDetailEx) GetDataEx() (interface{}, error) {
 	return sData, nil
 }
 
+// Ermcp3GoodsGroupEx 商品组(含商品列表)
+type Ermcp3GoodsGroupEx struct {
+	MIDDLEGOODSID  uint32        `json:"middlegoodsid"  xorm:"'middlegoodsid'"`   // 套保商品id
+	GOODSGROUPID   int32         `json:"goodsgroupid"  xorm:"'goodsgroupid'"`     // 商品组id
+	CONVERTRATIO   float64       `json:"convertratio"  xorm:"'convertratio'"`     // 折算系数(品种系数)
+	EXEXCHANGECODE string        `json:"exexchangecode"  xorm:"'exexchangecode'"` // 交易所代码
+	GOODSGROUPNAME string        `json:"goodsgroupname"  xorm:"'goodsgroupname'"` // 商品组名称
+	ENUMDICNAME    string        `json:"enumdicname"`                             // 单位名称
+	GList          []Ermcp3Goods `json:"glist"`                                   // 合约列表
+}
+
+// Ermcp3Goods 商品信息
+type Ermcp3Goods struct {
+	GOODSID        int32   `json:"goodsid"  xorm:"'goodsid'"`               // 期货商品id
+	GOODSCODE      string  `json:"goodscode"  xorm:"'goodscode'"`           // 期货商品代码
+	GOODSNAME      string  `json:"goodsname"  xorm:"'goodsname'"`           // 期货商品名称
+	AGREEUNIT      float32 `json:"agreeunit"  xorm:"'agreeunit'"`           // 合约单位(合约乘数)
+	EXEXCHANGECODE string  `json:"exexchangecode"  xorm:"'exexchangecode'"` // 交易所代码
+	ENUMDICNAME    string  `json:"enumdicname"`                             // 单位名称
+}
+
 // Ermcp3GoodsEx 套保品关联的期货商品(少量字段)
 type Ermcp3GoodsEx struct {
 	MIDDLEGOODSID  uint32  `json:"middlegoodsid"  xorm:"'middlegoodsid'"`   // 套保商品id
@@ -392,14 +457,20 @@ type Ermcp3GoodsEx struct {
 	GOODSNAME      string  `json:"goodsname"  xorm:"'goodsname'"`           // 期货商品名称
 	GOODUNITID     int32   `json:"goodunitid"  xorm:"'goodunitid'"`         // 期货商品单位id
 	CONVERTRATIO   float64 `json:"convertratio"  xorm:"'convertratio'"`     // 折算系数(品种系数)
+	GOODSGROUPID   int32   `json:"goodsgroupid"  xorm:"'goodsgroupid'"`     // 商品组id
 	EXEXCHANGECODE string  `json:"exexchangecode"  xorm:"'exexchangecode'"` // 交易所代码
+	GOODSGROUPNAME string  `json:"goodsgroupname"  xorm:"'goodsgroupname'"` // 商品组名称
+	GPUNITID       int32   `json:"gpunitid"  xorm:"'gpunitid'"`             // 商品组单位id
+	AGREEUNIT      float32 `json:"agreeunit"  xorm:"'agreeunit'"`           // 合约单位(合约乘数)
 
-	ENUMDICNAME string `json:"enumdicname"` // 单位名称
-	AREAUSERID  int64  `json:"-"`           // 所属机构id
+	ENUMDICNAME   string `json:"enumdicname"` // 单位名称
+	GPENUMDICNAME string `json:"enumdicname"` // 商品组单位名称
+	AREAUSERID    int64  `json:"-"`           // 所属机构id
 }
 
 func (r *Ermcp3GoodsEx) calc() {
 	r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.GOODUNITID)
+	r.GPENUMDICNAME = mtpcache.GetEnumDicitemName(r.GPUNITID)
 }
 
 func (r *Ermcp3GoodsEx) buildSql() string {
@@ -409,8 +480,12 @@ func (r *Ermcp3GoodsEx) buildSql() string {
 		"       g.goodscode," +
 		"       g.goodsname," +
 		"       g.goodunitid," +
+		"       g.goodsgroupid," +
+		"       g.agreeunit," +
 		"       gc.convertratio," +
-		"       ex.exexchangecode" +
+		"       ex.exexchangecode," +
+		"       gp.goodsgroupname," +
+		"       gp.goodunitid gpunitid" +
 		"  from erms_middlegoods mg" +
 		" inner join ERMCP_GGConvertConfig gc" +
 		"    on mg.goodsgroupid = gc.destgoodsgroupid" +