Sfoglia il codice sorgente

联调问题修改、增加查询套保计划接口

zou.yingbin 4 anni fa
parent
commit
eb7cc86c9b
7 ha cambiato i file con 464 aggiunte e 3 eliminazioni
  1. 32 0
      controllers/ermcp3/qryErmcp3.go
  2. 130 0
      docs/docs.go
  3. 130 0
      docs/swagger.json
  4. 91 0
      docs/swagger.yaml
  5. 79 2
      models/ermcp3.go
  6. 1 1
      mtpcache/username.go
  7. 1 0
      routers/router.go

+ 32 - 0
controllers/ermcp3/qryErmcp3.go

@@ -10,6 +10,7 @@ import (
 	"github.com/gin-gonic/gin"
 	"mtp2_if/global/app"
 	"mtp2_if/global/e"
+	"mtp2_if/logger"
 	"mtp2_if/models"
 	"net/http"
 )
@@ -445,3 +446,34 @@ func QuerySpotGoodsPriceLog(c *gin.Context) {
 	m := models.Ermcp3SpotGoodsPriceLog{AREAUSERID: req.UserId, DELIVERYGOODSID: req.DELIVERYGOODSID}
 	a.DoGetDataI(&m)
 }
+
+// QueryHedgePlan 查询套保计划
+// @Summary 查询套保计划
+// @Produce json
+// @Security ApiKeyAuth
+// @Param userid query int true "用户ID"
+// @Param hedgeplanstatus query string true "套保计划状态(允许多个,逗号隔开) - 0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回"
+// @Success 200 {array} models.Ermcp3HedgePlan
+// @Failure 500 {object} app.Response
+// @Router /Ermcp3/QueryHedgePlan [get]
+// @Tags 企业风险管理v3(app)
+func QueryHedgePlan(c *gin.Context) {
+	appG := app.Gin{C: c}
+	req := struct {
+		UserId          int64  `form:"userid" binding:"required"`          // 用户id
+		HedgePlanStatus string `form:"hedgeplanstatus" binding:"required"` // 状态
+	}{}
+	if err := c.ShouldBind(&req); err != nil {
+		logger.GetLogger().Errorf("query hedgeplanReq,%v", err)
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	var m = models.Ermcp3HedgePlan{Areauserid: req.UserId}
+	if d, err := m.GetData(req.HedgePlanStatus); err == nil {
+		appG.Response(http.StatusOK, e.SUCCESS, d)
+	} else {
+		logger.GetLogger().Errorf("query fail, %v", err)
+		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+	}
+}

+ 130 - 0
docs/docs.go

@@ -5127,6 +5127,55 @@ var doc = `{
                 }
             }
         },
+        "/Ermcp3/QueryHedgePlan": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "企业风险管理v3(app)"
+                ],
+                "summary": "查询套保计划",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户ID",
+                        "name": "userid",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "string",
+                        "description": "套保计划状态(允许多个,逗号隔开) - 0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回",
+                        "name": "hedgeplanstatus",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "type": "array",
+                            "items": {
+                                "$ref": "#/definitions/models.Ermcp3HedgePlan"
+                            }
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Ermcp3/QuerySpotContract": {
             "get": {
                 "security": [
@@ -13824,6 +13873,87 @@ var doc = `{
                 }
             }
         },
+        "models.Ermcp3HedgePlan": {
+            "type": "object",
+            "properties": {
+                "areauserid": {
+                    "description": "用户ID",
+                    "type": "integer"
+                },
+                "audittime": {
+                    "description": "审核时间",
+                    "type": "string"
+                },
+                "contracttype": {
+                    "description": "计划类型 - 1:采购 -1:销售",
+                    "type": "integer"
+                },
+                "convertfactor": {
+                    "description": "标仓系数",
+                    "type": "number"
+                },
+                "createtime": {
+                    "description": "创建时间",
+                    "type": "string"
+                },
+                "deliverygoodscode": {
+                    "description": "现货品种代码",
+                    "type": "string"
+                },
+                "deliverygoodsid": {
+                    "description": "现货品种ID",
+                    "type": "integer"
+                },
+                "deliverygoodsname": {
+                    "description": "现货品种名称",
+                    "type": "string"
+                },
+                "enumdicname": {
+                    "description": "单位名称",
+                    "type": "string"
+                },
+                "hedgeplanid": {
+                    "description": "套保计划ID(601+Unix秒时间戳(10位)+xxxxxx)",
+                    "type": "string"
+                },
+                "hedgeplanno": {
+                    "description": "套保计划编号(名称)",
+                    "type": "string"
+                },
+                "hedgeplanstatus": {
+                    "description": "套保计划状态 -  0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回",
+                    "type": "integer"
+                },
+                "planqty": {
+                    "description": "计划数量",
+                    "type": "number"
+                },
+                "plantime": {
+                    "description": "计划时间",
+                    "type": "string"
+                },
+                "producttype": {
+                    "description": "产品类型 - 1:标准仓单 2:等标 3:非标",
+                    "type": "integer"
+                },
+                "remark": {
+                    "description": "备注",
+                    "type": "string"
+                },
+                "spotgoodsdesc": {
+                    "description": "商品型号",
+                    "type": "string"
+                },
+                "unitid": {
+                    "description": "单位id",
+                    "type": "integer"
+                },
+                "updatetime": {
+                    "description": "更新时间",
+                    "type": "string"
+                }
+            }
+        },
         "models.Ermcp3ReportAreaSpotPL": {
             "type": "object",
             "properties": {

+ 130 - 0
docs/swagger.json

@@ -5111,6 +5111,55 @@
                 }
             }
         },
+        "/Ermcp3/QueryHedgePlan": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "企业风险管理v3(app)"
+                ],
+                "summary": "查询套保计划",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户ID",
+                        "name": "userid",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "string",
+                        "description": "套保计划状态(允许多个,逗号隔开) - 0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回",
+                        "name": "hedgeplanstatus",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "type": "array",
+                            "items": {
+                                "$ref": "#/definitions/models.Ermcp3HedgePlan"
+                            }
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Ermcp3/QuerySpotContract": {
             "get": {
                 "security": [
@@ -13808,6 +13857,87 @@
                 }
             }
         },
+        "models.Ermcp3HedgePlan": {
+            "type": "object",
+            "properties": {
+                "areauserid": {
+                    "description": "用户ID",
+                    "type": "integer"
+                },
+                "audittime": {
+                    "description": "审核时间",
+                    "type": "string"
+                },
+                "contracttype": {
+                    "description": "计划类型 - 1:采购 -1:销售",
+                    "type": "integer"
+                },
+                "convertfactor": {
+                    "description": "标仓系数",
+                    "type": "number"
+                },
+                "createtime": {
+                    "description": "创建时间",
+                    "type": "string"
+                },
+                "deliverygoodscode": {
+                    "description": "现货品种代码",
+                    "type": "string"
+                },
+                "deliverygoodsid": {
+                    "description": "现货品种ID",
+                    "type": "integer"
+                },
+                "deliverygoodsname": {
+                    "description": "现货品种名称",
+                    "type": "string"
+                },
+                "enumdicname": {
+                    "description": "单位名称",
+                    "type": "string"
+                },
+                "hedgeplanid": {
+                    "description": "套保计划ID(601+Unix秒时间戳(10位)+xxxxxx)",
+                    "type": "string"
+                },
+                "hedgeplanno": {
+                    "description": "套保计划编号(名称)",
+                    "type": "string"
+                },
+                "hedgeplanstatus": {
+                    "description": "套保计划状态 -  0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回",
+                    "type": "integer"
+                },
+                "planqty": {
+                    "description": "计划数量",
+                    "type": "number"
+                },
+                "plantime": {
+                    "description": "计划时间",
+                    "type": "string"
+                },
+                "producttype": {
+                    "description": "产品类型 - 1:标准仓单 2:等标 3:非标",
+                    "type": "integer"
+                },
+                "remark": {
+                    "description": "备注",
+                    "type": "string"
+                },
+                "spotgoodsdesc": {
+                    "description": "商品型号",
+                    "type": "string"
+                },
+                "unitid": {
+                    "description": "单位id",
+                    "type": "integer"
+                },
+                "updatetime": {
+                    "description": "更新时间",
+                    "type": "string"
+                }
+            }
+        },
         "models.Ermcp3ReportAreaSpotPL": {
             "type": "object",
             "properties": {

+ 91 - 0
docs/swagger.yaml

@@ -3591,6 +3591,66 @@ definitions:
         description: 现货合同/套保计划编号
         type: string
     type: object
+  models.Ermcp3HedgePlan:
+    properties:
+      areauserid:
+        description: 用户ID
+        type: integer
+      audittime:
+        description: 审核时间
+        type: string
+      contracttype:
+        description: 计划类型 - 1:采购 -1:销售
+        type: integer
+      convertfactor:
+        description: 标仓系数
+        type: number
+      createtime:
+        description: 创建时间
+        type: string
+      deliverygoodscode:
+        description: 现货品种代码
+        type: string
+      deliverygoodsid:
+        description: 现货品种ID
+        type: integer
+      deliverygoodsname:
+        description: 现货品种名称
+        type: string
+      enumdicname:
+        description: 单位名称
+        type: string
+      hedgeplanid:
+        description: 套保计划ID(601+Unix秒时间戳(10位)+xxxxxx)
+        type: string
+      hedgeplanno:
+        description: 套保计划编号(名称)
+        type: string
+      hedgeplanstatus:
+        description: 套保计划状态 -  0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回
+        type: integer
+      planqty:
+        description: 计划数量
+        type: number
+      plantime:
+        description: 计划时间
+        type: string
+      producttype:
+        description: 产品类型 - 1:标准仓单 2:等标 3:非标
+        type: integer
+      remark:
+        description: 备注
+        type: string
+      spotgoodsdesc:
+        description: 商品型号
+        type: string
+      unitid:
+        description: 单位id
+        type: integer
+      updatetime:
+        description: 更新时间
+        type: string
+    type: object
   models.Ermcp3ReportAreaSpotPL:
     properties:
       actualpl:
@@ -15149,6 +15209,37 @@ paths:
       summary: 查询商品品牌
       tags:
       - 企业风险管理v3(app)
+  /Ermcp3/QueryHedgePlan:
+    get:
+      parameters:
+      - description: 用户ID
+        in: query
+        name: userid
+        required: true
+        type: integer
+      - description: 套保计划状态(允许多个,逗号隔开) - 0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回
+        in: query
+        name: hedgeplanstatus
+        required: true
+        type: string
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            items:
+              $ref: '#/definitions/models.Ermcp3HedgePlan'
+            type: array
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 查询套保计划
+      tags:
+      - 企业风险管理v3(app)
   /Ermcp3/QuerySpotContract:
     get:
       parameters:

+ 79 - 2
models/ermcp3.go

@@ -9,6 +9,7 @@ package models
 import (
 	"fmt"
 	"mtp2_if/db"
+	"mtp2_if/logger"
 	"mtp2_if/mtpcache"
 	"mtp2_if/utils"
 )
@@ -552,7 +553,7 @@ func (r *Ermcp3SellBuyContract) buildSql() string {
 		"       to_char(t.enddate, 'yyyy-mm-dd hh24:mi:ss') enddate," +
 		"       to_char(t.deliverystartdate, 'yyyy-mm-dd hh24:mi:ss') deliverystartdate," +
 		"       to_char(t.deliveryenddate, 'yyyy-mm-dd hh24:mi:ss') deliveryenddate," +
-		"       w.convertfactor," +
+		"       wr.convertfactor," +
 		"       t.contractstatus," +
 		"       t.pricetype," +
 		"       t.producttype," +
@@ -1545,7 +1546,7 @@ func (r *Ermcp3SpotGoodsPriceLog) buildSql() string {
 
 // GetDataEx 获取现货市价信息日志
 func (r *Ermcp3SpotGoodsPriceLog) GetDataEx() (interface{}, error) {
-	sData := make([]Ermcp3SpotGoodsPrice, 0)
+	sData := make([]Ermcp3SpotGoodsPriceLog, 0)
 	err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
 	if err == nil {
 		for i := range sData {
@@ -1554,3 +1555,79 @@ func (r *Ermcp3SpotGoodsPriceLog) GetDataEx() (interface{}, error) {
 	}
 	return sData, err
 }
+
+// Ermcp3HedgePlan 套保计划表结构
+type Ermcp3HedgePlan struct {
+	Areauserid        int64   `json:"areauserid"  xorm:"'Areauserid'"`               // 用户ID
+	Hedgeplanid       string  `json:"hedgeplanid"  xorm:"'Hedgeplanid'"`             // 套保计划ID(601+Unix秒时间戳(10位)+xxxxxx)
+	Hedgeplanno       string  `json:"hedgeplanno"  xorm:"'Hedgeplanno'"`             // 套保计划编号(名称)
+	Contracttype      int     `json:"contracttype"  xorm:"'Contracttype'"`           // 计划类型 - 1:采购 -1:销售
+	Deliverygoodsid   int     `json:"deliverygoodsid"  xorm:"'Deliverygoodsid'"`     // 现货品种ID
+	Deliverygoodsname string  `json:"deliverygoodsname"  xorm:"'Deliverygoodsname'"` // 现货品种名称
+	DELIVERYGOODSCODE string  `json:"deliverygoodscode"  xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码
+	Producttype       int     `json:"producttype"  xorm:"'Producttype'"`             // 产品类型 - 1:标准仓单 2:等标 3:非标
+	Spotgoodsdesc     string  `json:"spotgoodsdesc"  xorm:"'Spotgoodsdesc'"`         // 商品型号
+	Planqty           float64 `json:"planqty"  xorm:"'Planqty'"`                     // 计划数量
+	Convertfactor     float64 `json:"convertfactor"  xorm:"'Convertfactor'"`         // 标仓系数
+	Plantime          string  `json:"plantime"  xorm:"'Plantime'"`                   // 计划时间
+	Hedgeplanstatus   int     `json:"hedgeplanstatus"  xorm:"'Hedgeplanstatus'"`     // 套保计划状态 -  0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回
+	Remark            string  `json:"remark"  xorm:"'Remark'"`                       // 备注
+	CREATETIME        string  `json:"createtime"  xorm:"'CREATETIME'"`               // 创建时间
+	UPDATETIME        string  `json:"updatetime"  xorm:"'UPDATETIME'"`               // 更新时间
+	AUDITTIME         string  `json:"audittime"  xorm:"'AUDITTIME'"`                 // 审核时间
+	UNITID            int32   `json:"unitid"  xorm:"'UNITID'"`                       // 单位id
+	ENUMDICNAME       string  `json:"enumdicname"`                                   // 单位名称
+}
+
+func (r *Ermcp3HedgePlan) calc() {
+	r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.UNITID)
+}
+
+func (r *Ermcp3HedgePlan) buildSql(status string) string {
+	str := "select to_char(t.Hedgeplanid) Hedgeplanid," +
+		"       t.Hedgeplanno," +
+		"       t.Contracttype," +
+		"       t.Deliverygoodsid," +
+		"       g.Deliverygoodsname," +
+		"       g.deliverygoodscode," +
+		"       g.goodsunitid unitid," +
+		"       t.Producttype," +
+		"       t.Spotgoodsdesc," +
+		"       t.Planqty," +
+		"       t.Convertfactor," +
+		"       to_char(t.Plantime, 'yyyy-mm-dd hh24:mi:ss') Plantime," +
+		"       to_char(t.createtime, 'yyyy-mm-dd hh24:mi:ss') createtime," +
+		"       to_char(t.updatetime, 'yyyy-mm-dd hh24:mi:ss') updatetime," +
+		"       to_char(t.audittime, 'yyyy-mm-dd hh24:mi:ss') audittime," +
+		"       t.Hedgeplanstatus," +
+		"       t.Remark" +
+		"  from ermcp_hedgeplan t" +
+		"  left join deliverygoods g" +
+		"    on t.deliverygoodsid = g.deliverygoodsid" +
+		" where t.hedgeplanstatus in (%v)" +
+		"   and t.areauserid = %v"
+
+	if status == "2" {
+		// 执行中状态,按审核时间倒序
+		str += " order by t.audittime desc"
+	} else {
+		str += " order by t.updatetime desc"
+	}
+
+	return fmt.Sprintf(str, status, r.Areauserid)
+}
+
+// GetData 从数据库中查询套保计划数据
+func (r *Ermcp3HedgePlan) GetData(status string) ([]Ermcp3HedgePlan, error) {
+	e := db.GetEngine()
+	sData := make([]Ermcp3HedgePlan, 0)
+	if err := e.SQL(r.buildSql(status)).Find(&sData); err != nil {
+		logger.GetLogger().Errorf("query hedgeplan:%v", err)
+		return sData, err
+	}
+	for i := range sData {
+		sData[i].calc()
+	}
+
+	return sData, nil
+}

+ 1 - 1
mtpcache/username.go

@@ -50,7 +50,7 @@ func (r *userName) load() {
 		" where 1 = 1"
 
 	sData := make([]userData, 0)
-	s := e.SQL(sqlId)
+	s := e.SQL(sqlId.String())
 	if err := s.Find(&sData); err != nil {
 		logger.GetLogger().Errorf("cache load usrname, %v", err)
 	} else {

+ 1 - 0
routers/router.go

@@ -429,6 +429,7 @@ func InitRouter() *gin.Engine {
 		ermcp3R.GET("/QueryAreaStockReportDetail", ermcp3.QueryAreaStockReportDetail)
 		ermcp3R.GET("/QuerySpotGoodsPrice", ermcp3.QuerySpotGoodsPrice)
 		ermcp3R.GET("/QuerySpotGoodsPriceLog", ermcp3.QuerySpotGoodsPriceLog)
+		ermcp3R.GET("/QueryHedgePlan", ermcp3.QueryHedgePlan)
 	}
 
 	return r