Переглянути джерело

增加查履约模板接口

zou.yingbin 4 роки тому
батько
коміт
69d8951d2b
6 змінених файлів з 416 додано та 2 видалено
  1. 20 0
      controllers/wrTrade2/qryWrTrade.go
  2. 104 0
      docs/docs.go
  3. 104 0
      docs/swagger.json
  4. 72 0
      docs/swagger.yaml
  5. 115 2
      models/wrTrade2.go
  6. 1 0
      routers/router.go

+ 20 - 0
controllers/wrTrade2/qryWrTrade.go

@@ -176,6 +176,7 @@ func QueryWrTradeDetail(c *gin.Context) {
 // @Param marketid query int false "仓单贸易市场id"
 // @Param haswr query int true "0:仓单预售 1:仓单贸易"
 // @Param wrfactortypeid query int true "仓单要素id"
+// @Param tmplateid query int false "履约模板id(如果指定了履约模板id,履约信息将按模板id查, 否则去市场配置表中找模板)"
 // @Success 200 {array} models.WrGoodsInfo
 // @Failure 500 {object} app.Response
 // @Router /WrTrade2/QueryWrGoodsInfo [get]
@@ -557,3 +558,22 @@ func QueryWrFriendApply(c *gin.Context) {
 	a.DoBindReq(&m)
 	a.DoGetDataI(&m)
 }
+
+// QueryPermancePlanTmp
+// @Summary 查询履约模板
+// @Description 返回指定用户的模板和公共模板(用户id为空)
+// @Produce json
+// @Security ApiKeyAuth
+// @Param userid query int false "用户id"
+// @Param tmptype query string false "模板类型(逗号隔开), 0:通用 1:交割 2:仓单贸易 3:预售集采 7:竞拍-竞价式 8:竞拍-大宗式 9:荷兰式--失效枚举:4:竞拍-降价式 (无仓单) 5:挂牌期权  6:竞拍-降价式"
+// @Param includepub query int false "是否包含公共模板(用户id为空的) 1-包含"
+// @Success 200 {array} models.WrPerformanceTemplateEx
+// @Failure 500 {object} app.Response
+// @Router /WrTrade2/QueryPermancePlanTmp [get]
+// @Tags 仓单贸易v2
+func QueryPermancePlanTmp(c *gin.Context) {
+	a := app.GinUtils{Gin: app.Gin{C: c}}
+	m := models.WrPerformanceTemplateEx{}
+	a.DoBindReq(&m)
+	a.DoGetDataI(&m)
+}

+ 104 - 0
docs/docs.go

@@ -11437,6 +11437,60 @@ var doc = `{
                 }
             }
         },
+        "/WrTrade2/QueryPermancePlanTmp": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "description": "返回指定用户的模板和公共模板(用户id为空)",
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "仓单贸易v2"
+                ],
+                "summary": "查询履约模板",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户id",
+                        "name": "userid",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "模板类型(逗号隔开), 0:通用 1:交割 2:仓单贸易 3:预售集采 7:竞拍-竞价式 8:竞拍-大宗式 9:荷兰式--失效枚举:4:竞拍-降价式 (无仓单) 5:挂牌期权  6:竞拍-降价式",
+                        "name": "tmptype",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "是否包含公共模板(用户id为空的) 1-包含",
+                        "name": "includepub",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "type": "array",
+                            "items": {
+                                "$ref": "#/definitions/models.WrPerformanceTemplateEx"
+                            }
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/WrTrade2/QueryWrAverageTradePrice": {
             "get": {
                 "security": [
@@ -11882,6 +11936,12 @@ var doc = `{
                         "name": "wrfactortypeid",
                         "in": "query",
                         "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "履约模板id(如果指定了履约模板id,履约信息将按模板id查, 否则去市场配置表中找模板)",
+                        "name": "tmplateid",
+                        "in": "query"
                     }
                 ],
                 "responses": {
@@ -32320,6 +32380,50 @@ var doc = `{
                 }
             }
         },
+        "models.WrPerformanceTemplateEx": {
+            "type": "object",
+            "properties": {
+                "autoid": {
+                    "description": "AutoID 模板id",
+                    "type": "integer"
+                },
+                "createtime": {
+                    "description": "创建时间",
+                    "type": "string"
+                },
+                "creatorid": {
+                    "description": "创建人",
+                    "type": "integer"
+                },
+                "lstStep": {
+                    "description": "步骤信息列表",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/models.WrGoodsPerformanceStep"
+                    }
+                },
+                "paymenttype": {
+                    "description": "支付方式 - 1:冻结 2:扣款",
+                    "type": "integer"
+                },
+                "takemode": {
+                    "description": "提货方式 - 1:无 2:买方自提 3:卖方发货",
+                    "type": "integer"
+                },
+                "templatename": {
+                    "description": "模板名称",
+                    "type": "string"
+                },
+                "templatetype": {
+                    "description": "模板类型 - 0:通用 1:交割 2:仓单贸易 3:预售集采 7:竞拍-竞价式 8:竞拍-大宗式 9:荷兰式--失效枚举:4:竞拍-降价式 (无仓单) 5:挂牌期权  6:竞拍-降价式",
+                    "type": "integer"
+                },
+                "userid": {
+                    "description": "所属用户",
+                    "type": "integer"
+                }
+            }
+        },
         "models.WrPosition": {
             "type": "object",
             "properties": {

+ 104 - 0
docs/swagger.json

@@ -11421,6 +11421,60 @@
                 }
             }
         },
+        "/WrTrade2/QueryPermancePlanTmp": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "description": "返回指定用户的模板和公共模板(用户id为空)",
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "仓单贸易v2"
+                ],
+                "summary": "查询履约模板",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户id",
+                        "name": "userid",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "模板类型(逗号隔开), 0:通用 1:交割 2:仓单贸易 3:预售集采 7:竞拍-竞价式 8:竞拍-大宗式 9:荷兰式--失效枚举:4:竞拍-降价式 (无仓单) 5:挂牌期权  6:竞拍-降价式",
+                        "name": "tmptype",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "是否包含公共模板(用户id为空的) 1-包含",
+                        "name": "includepub",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "type": "array",
+                            "items": {
+                                "$ref": "#/definitions/models.WrPerformanceTemplateEx"
+                            }
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/WrTrade2/QueryWrAverageTradePrice": {
             "get": {
                 "security": [
@@ -11866,6 +11920,12 @@
                         "name": "wrfactortypeid",
                         "in": "query",
                         "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "履约模板id(如果指定了履约模板id,履约信息将按模板id查, 否则去市场配置表中找模板)",
+                        "name": "tmplateid",
+                        "in": "query"
                     }
                 ],
                 "responses": {
@@ -32304,6 +32364,50 @@
                 }
             }
         },
+        "models.WrPerformanceTemplateEx": {
+            "type": "object",
+            "properties": {
+                "autoid": {
+                    "description": "AutoID 模板id",
+                    "type": "integer"
+                },
+                "createtime": {
+                    "description": "创建时间",
+                    "type": "string"
+                },
+                "creatorid": {
+                    "description": "创建人",
+                    "type": "integer"
+                },
+                "lstStep": {
+                    "description": "步骤信息列表",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/models.WrGoodsPerformanceStep"
+                    }
+                },
+                "paymenttype": {
+                    "description": "支付方式 - 1:冻结 2:扣款",
+                    "type": "integer"
+                },
+                "takemode": {
+                    "description": "提货方式 - 1:无 2:买方自提 3:卖方发货",
+                    "type": "integer"
+                },
+                "templatename": {
+                    "description": "模板名称",
+                    "type": "string"
+                },
+                "templatetype": {
+                    "description": "模板类型 - 0:通用 1:交割 2:仓单贸易 3:预售集采 7:竞拍-竞价式 8:竞拍-大宗式 9:荷兰式--失效枚举:4:竞拍-降价式 (无仓单) 5:挂牌期权  6:竞拍-降价式",
+                    "type": "integer"
+                },
+                "userid": {
+                    "description": "所属用户",
+                    "type": "integer"
+                }
+            }
+        },
         "models.WrPosition": {
             "type": "object",
             "properties": {

+ 72 - 0
docs/swagger.yaml

@@ -14732,6 +14732,39 @@ definitions:
         description: 商品
         type: string
     type: object
+  models.WrPerformanceTemplateEx:
+    properties:
+      autoid:
+        description: AutoID 模板id
+        type: integer
+      createtime:
+        description: 创建时间
+        type: string
+      creatorid:
+        description: 创建人
+        type: integer
+      lstStep:
+        description: 步骤信息列表
+        items:
+          $ref: '#/definitions/models.WrGoodsPerformanceStep'
+        type: array
+      paymenttype:
+        description: 支付方式 - 1:冻结 2:扣款
+        type: integer
+      takemode:
+        description: 提货方式 - 1:无 2:买方自提 3:卖方发货
+        type: integer
+      templatename:
+        description: 模板名称
+        type: string
+      templatetype:
+        description: 模板类型 - 0:通用 1:交割 2:仓单贸易 3:预售集采 7:竞拍-竞价式 8:竞拍-大宗式 9:荷兰式--失效枚举:4:竞拍-降价式
+          (无仓单) 5:挂牌期权  6:竞拍-降价式
+        type: integer
+      userid:
+        description: 所属用户
+        type: integer
+    type: object
   models.WrPosition:
     properties:
       accountid:
@@ -24551,6 +24584,41 @@ paths:
       summary: 查询履约信息
       tags:
       - 仓单贸易v2
+  /WrTrade2/QueryPermancePlanTmp:
+    get:
+      description: 返回指定用户的模板和公共模板(用户id为空)
+      parameters:
+      - description: 用户id
+        in: query
+        name: userid
+        type: integer
+      - description: 模板类型(逗号隔开), 0:通用 1:交割 2:仓单贸易 3:预售集采 7:竞拍-竞价式 8:竞拍-大宗式 9:荷兰式--失效枚举:4:竞拍-降价式
+          (无仓单) 5:挂牌期权  6:竞拍-降价式
+        in: query
+        name: tmptype
+        type: string
+      - description: 是否包含公共模板(用户id为空的) 1-包含
+        in: query
+        name: includepub
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            items:
+              $ref: '#/definitions/models.WrPerformanceTemplateEx'
+            type: array
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 查询履约模板
+      tags:
+      - 仓单贸易v2
   /WrTrade2/QueryWrAverageTradePrice:
     get:
       parameters:
@@ -24825,6 +24893,10 @@ paths:
         name: wrfactortypeid
         required: true
         type: integer
+      - description: 履约模板id(如果指定了履约模板id,履约信息将按模板id查, 否则去市场配置表中找模板)
+        in: query
+        name: tmplateid
+        type: integer
       produces:
       - application/json
       responses:

+ 115 - 2
models/wrTrade2.go

@@ -1045,6 +1045,8 @@ func (r *WrGoodsPerformanceStep) calc() {
 	switch r.STEPTYPEID {
 	case 1, 2, 98:
 		r.STEPINFO = fmt.Sprintf("%v %v%%", r.STEPTYPENAME, r.STEPVALUE*100)
+	case 92:
+		r.STEPINFO = r.STEPTYPENAME
 	default:
 		if r.STEPVALUE == 0 {
 			r.STEPINFO = r.STEPTYPENAME
@@ -1085,11 +1087,24 @@ func (r WrGoodsPerformanceStep) buildSqlByTmpId() string {
 	return sqlId.String()
 }
 
+func (r WrGoodsPerformanceStep) buildSqlAll() string {
+	var sqlId utils.SQLVal = "select t.*, s.steptypename" +
+		"  from PerformanceStepTemplate t" +
+		" inner join PerformanceStepType s" +
+		"    on t.steptypeid = s.steptypeid" +
+		" where 1=1" +
+		" order by t.templateid, t.stepindex"
+	return sqlId.String()
+}
+
 func (r *WrGoodsPerformanceStep) buildSql() string {
 	if r.TEMPLATEID != 0 {
 		return r.buildSqlByTmpId()
+	} else if r.WRSTANDARDID > 0 {
+		return r.buildSqlByWrstandard()
+	} else {
+		return r.buildSqlAll()
 	}
-	return r.buildSqlByWrstandard()
 }
 
 // GetDataEx 获取商品履约步骤
@@ -1117,6 +1132,7 @@ type WrGoodsInfo struct {
 	HASWR          int32                    `json:"haswr" form:"haswr"`       // 0:仓单预售 1:仓单贸易
 	LstItem        []WrTypeItem             `json:"lstitem"`                  // 商品信息项
 	LstStep        []WrGoodsPerformanceStep `json:"lststep"`                  // 履约规则
+	TMPLATEID      int64                    `json:"-" form:"tmplateid"`       // 履约模板id
 }
 
 // GetDataEx 获取仓单商品信息(仓单要素列展开+履约计划步骤)
@@ -1131,7 +1147,12 @@ func (r *WrGoodsInfo) GetDataEx() (interface{}, error) {
 			a := sType[0]
 
 			// 获取履约规则
-			mStep := WrGoodsPerformanceStep{MARKETID: r.MARKETID, WRSTANDARDID: a.WRSTANDARDID, HASWR: r.HASWR}
+			mStep := WrGoodsPerformanceStep{}
+			if r.TMPLATEID > 0 {
+				mStep.TEMPLATEID = r.TMPLATEID
+			} else {
+				mStep.MARKETID, mStep.WRSTANDARDID, mStep.HASWR = r.MARKETID, a.WRSTANDARDID, r.HASWR
+			}
 			if sStep, err := mStep.GetData(); err == nil && len(sStep) > 0 {
 				v.LstStep = append(v.LstStep, sStep...)
 			}
@@ -3090,3 +3111,95 @@ func (r *WrFriendApply) GetDataEx() (interface{}, error) {
 	}
 	return sData, err
 }
+
+// WrPerformanceTemplate 履约模板
+type WrPerformanceTemplate struct {
+	AUTOID       int64  `json:"autoid"  xorm:"AUTOID" form:"autoid"`          // AutoID 模板id
+	USERID       int64  `json:"userid"  xorm:"USERID" form:"userid"`          // 所属用户
+	TEMPLATENAME string `json:"templatename"  xorm:"TEMPLATENAME"`            // 模板名称
+	PAYMENTTYPE  int32  `json:"paymenttype"  xorm:"PAYMENTTYPE"`              // 支付方式 - 1:冻结 2:扣款
+	CREATETIME   string `json:"createtime"  xorm:"CREATETIME"`                // 创建时间
+	CREATORID    int64  `json:"creatorid"  xorm:"CREATORID" form:"creatorid"` // 创建人
+	TEMPLATETYPE int32  `json:"templatetype"  xorm:"TEMPLATETYPE"`            // 模板类型 - 0:通用 1:交割 2:仓单贸易 3:预售集采 7:竞拍-竞价式 8:竞拍-大宗式 9:荷兰式--失效枚举:4:竞拍-降价式 (无仓单) 5:挂牌期权  6:竞拍-降价式
+	TAKEMODE     int32  `json:"takemode"  xorm:"TAKEMODE"`                    // 提货方式 - 1:无 2:买方自提 3:卖方发货
+
+	FTTMPTYPE  string `json:"-" form:"tmptype"`    // 模板类型筛选
+	INCLUDEPUB int32  `json:"-" form:"includepub"` // 是否包含公共模板
+}
+
+func (r *WrPerformanceTemplate) calc() {
+
+}
+
+func (r *WrPerformanceTemplate) buildSql() string {
+	var sqlId utils.SQLVal = "SELECT t.USERID," +
+		"       t.AUTOID," +
+		"       t.TEMPLATENAME," +
+		"       t.PAYMENTTYPE," +
+		"       to_char(t.CREATETIME, 'yyyy-mm-dd hh24:mi:ss') CREATETIME," +
+		"       t.CREATORID," +
+		"       t.TEMPLATETYPE," +
+		"       t.TAKEMODE" +
+		"  FROM PERFORMANCEPLANTEMPLATE t" +
+		" WHERE 1 = 1"
+	if r.USERID > 0 {
+		if r.INCLUDEPUB == 1 {
+			// t.userid is null 意思是查公共模板
+			sqlId.JoinFormat(" and (t.userid is null or t.userid = %v)", r.USERID)
+		} else {
+			sqlId.And("t.userid", r.USERID)
+		}
+	}
+	sqlId.AndEx("t.autoid", r.AUTOID, r.AUTOID > 0)
+	if r.FTTMPTYPE != "" {
+		sqlId.JoinFormat(" and t.TEMPLATETYPE in(%v)", r.FTTMPTYPE)
+	}
+	sqlId.Join(" order by t.AUTOID")
+	return sqlId.String()
+}
+
+// GetDataEx 获取履约模板
+func (r *WrPerformanceTemplate) GetDataEx() (interface{}, error) {
+	sData := make([]WrPerformanceTemplate, 0)
+	err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
+	for i := range sData {
+		sData[i].calc()
+	}
+	return sData, err
+}
+
+// WrPerformanceTemplateEx 履约模板(含步骤信息)
+type WrPerformanceTemplateEx struct {
+	WrPerformanceTemplate `form:"extends"`
+	LstStep               []WrGoodsPerformanceStep // 步骤信息列表
+}
+
+func (r *WrPerformanceTemplateEx) addStep(lst []WrGoodsPerformanceStep) {
+	for i := range lst {
+		if lst[i].TEMPLATEID == r.AUTOID {
+			r.LstStep = append(r.LstStep, lst[i])
+		}
+	}
+}
+
+func (r *WrPerformanceTemplateEx) GetDataEx() (interface{}, error) {
+	sData := make([]WrPerformanceTemplateEx, 0)
+	if d, err := r.WrPerformanceTemplate.GetDataEx(); err == nil {
+		if sTmplate, ok := d.([]WrPerformanceTemplate); ok {
+			if len(sTmplate) > 0 {
+				// 查履约步骤
+				ms := WrGoodsPerformanceStep{}
+				if d2, err := ms.GetData(); err == nil {
+					for i := range sTmplate {
+						val := WrPerformanceTemplateEx{}
+						val.WrPerformanceTemplate = sTmplate[i]
+						val.LstStep = make([]WrGoodsPerformanceStep, 0)
+						val.addStep(d2)
+						sData = append(sData, val)
+					}
+				}
+			}
+		}
+	}
+	return sData, nil
+}

+ 1 - 0
routers/router.go

@@ -548,6 +548,7 @@ func InitRouter() *gin.Engine {
 		wrTrade2R.GET("QueryWrDeliveryAvalidHoldLB", wrTrade2.QueryWrDeliveryAvalidHoldLB)
 		wrTrade2R.GET("QueryWrUserFriend", wrTrade2.QueryWrUserFriend)
 		wrTrade2R.GET("QueryWrFriendApply", wrTrade2.QueryWrFriendApply)
+		wrTrade2R.GET("QueryPermancePlanTmp", wrTrade2.QueryPermancePlanTmp)
 	}
 
 	return r