Forráskód Böngészése

增加查询待审核合同接口

zou.yingbin 5 éve
szülő
commit
486fb97fd2
10 módosított fájl, 811 hozzáadás és 1 törlés
  1. 1 0
      .gitignore
  2. 304 0
      controllers/erms3/qryContract.go
  3. 137 0
      docs/docs.go
  4. 137 0
      docs/swagger.json
  5. 97 0
      docs/swagger.yaml
  6. 1 1
      go.mod
  7. 2 0
      go.sum
  8. 114 0
      models/contractModel.go
  9. 16 0
      models/delivery.go
  10. 2 0
      routers/router.go

+ 1 - 0
.gitignore

@@ -7,3 +7,4 @@ mtp2_if
 QueryService
 go.sum
 mtp2_if.exe
+/.idea

+ 304 - 0
controllers/erms3/qryContract.go

@@ -0,0 +1,304 @@
+/**
+* @Author: zou.yingbin
+* @Create  : 2020/12/2 9:18
+* @Modify  : 2020/12/2 9:18
+ */
+
+package erms3
+
+import (
+	"encoding/json"
+	"github.com/gin-gonic/gin"
+	"mtp2_if/global/app"
+	"mtp2_if/global/e"
+	"mtp2_if/logger"
+	"mtp2_if/models"
+	"net/http"
+	"strconv"
+)
+
+// 去除多余的冒号
+func tripColon(str string) string {
+	if len(str) >= 3 && str[0] == '"' {
+		return str[1 : len(str)-1]
+	}
+
+	return str
+}
+
+type sFloat64 float64
+
+func (r *sFloat64) UnmarshalJSON(buf []byte) error {
+	str := tripColon(string(buf))
+	if d, err := strconv.ParseFloat(str, 64); err == nil {
+		*r = sFloat64(d)
+	} else {
+		return err
+	}
+
+	return nil
+}
+
+type sInt32 int32
+
+func (r *sInt32) UnmarshalJSON(buf []byte) error {
+	str := tripColon(string(buf))
+	if d, err := strconv.ParseInt(str, 10, 64); err == nil {
+		*r = sInt32(d)
+	} else {
+		return err
+	}
+	return nil
+}
+
+type sInt64 int64
+
+func (r *sInt64) UnmarshalJSON(buf []byte) error {
+	str := tripColon(string(buf))
+	if d, err := strconv.ParseInt(str, 10, 64); err == nil {
+		*r = sInt64(d)
+	} else {
+		return err
+	}
+	return nil
+}
+
+// 解析定价明细Json字段
+type SpotPriceJson struct {
+	Price  sFloat64
+	Qty    sFloat64
+	Amount sFloat64
+}
+
+// 解析点价明细Json字段
+type SpotPointJson struct {
+	GoodsID   sInt32
+	GoodsName string
+	Qty       sFloat64
+	Basic     sFloat64
+	StartDate string
+	EndDate   string
+}
+
+// 解析合同申请表Json字段
+type DetailJSON struct {
+	WrStandardID         sInt64
+	WrStandardName       string
+	ProductType          sInt32
+	ProductTypeName      string
+	DeliveryGoodsID      sInt32
+	DeliveryGoodsName    string
+	DeliveryGoodsDesc    string
+	WarehouseID          sInt32
+	WarehouseName        string
+	UnitName             string
+	PointDesc            string
+	SpotPriceOrderList   []SpotPriceJson
+	SpotPointOrderVoList []SpotPointJson
+}
+
+// 查询待审核合同请求
+type QryAuditContractReq struct {
+	AccountId    uint64 `form:"accountid" binding:"required"`    // 请求账号ID
+	ContractType int32  `form:"contracttype" binding:"required"` // 合同类型
+	ContractMode uint32 `form:"contractmode" binding:"required"` // 合同模式
+}
+
+// 查询待审核合同应答
+type QryAuditContractRsp struct {
+	SpotContractId    string  `json:"spotcontractid"  xorm:"'SPOTCONTRACTID'" binding:"required"`       // 合同ID
+	MatchCustomerName string  `json:"matchcustomername"  xorm:"'MATCHCUSTOMERNAME'" binding:"required"` // 销售方ID
+	MatchAccountId    string  `json:"matchaccountid"  xorm:"'MATCHACCOUNTID'"`                          // 业务员ID
+	AccountId         string  `json:"accountid"  xorm:"'ACCOUNTID'"`                                    // 交易员ID
+	CustomerName      string  `json:"customername"  xorm:"'CUSTOMERNAME'"`                              // 采购方ID
+	WrstandardName    string  `json:"wrstandardname"  xorm:"'WRSTANDARDNAME'"`                          // 商品名称
+	Wrstandardcode    string  `json:"wrstandardcode"  xorm:"'WRSTANDARDCODE'"`                          // 商品代码
+	PricedQty         float64 `json:"pricedqty"  xorm:"'PRICEDQTY'"`                                    // 定价量
+	UnpricedQty       float64 `json:"unpricedqty"  xorm:"'UNPRICEDQTY'"`                                // 未定价量
+	TotaldQty         float64 `json:"totaldqty"  xorm:"'TOTALDQTY'"`                                    // 合同量
+	DeliveryQty       uint64  `json:"deliveryqty"  xorm:"'DELIVERYQTY'"`                                // 交收量
+	CurDeliveryQty    uint64  `json:"curdeliveryqty"  xorm:"'CURDELIVERYQTY'"`                          // 未交收量
+	DeliveryGoodsName string  `json:"deliverygoodsname"  xorm:"'DELIVERYGOODSNAME'"`                    // 品种名称
+	DeliveryGoodscode string  `json:"deliverygoodscode"  xorm:"'DELIVERYGOODSCODE'"`                    // 品种代码
+	ApplyStatus       uint32  `json:"applystatus"  xorm:"'APPLYSTATUS'"`                                // 状态
+	EnumdicName       string  `json:"enumdicname"  xorm:"'ENUMDICNAME'"`                                // 单位名称
+	SignDate          string  `json:"signdate"  xorm:"'SIGNDATE'"`                                      // 签订日期
+
+	deliverGoods map[int32]models.Deliverygoods // 不参与json编码,作为id转code缓存
+	wrStandards  map[int64]models.Wrstandard    // 不参与json编码,作为id转code缓存
+}
+
+// 转换交割商品ID为商品代码
+func (r *QryAuditContractRsp) DeliverGoodsId2Code(id int32) string {
+
+	// init
+	if r.deliverGoods == nil || len(r.deliverGoods) == 0 {
+		r.deliverGoods = make(map[int32]models.Deliverygoods)
+		if dg, err := models.GetDeliverGoods(); err == nil {
+			for _, v := range dg {
+				r.deliverGoods[v.Deliverygoodsid] = v
+			}
+		}
+	}
+
+	if v, ok := r.deliverGoods[id]; ok {
+		return v.Deliverygoodscode
+	}
+
+	return ""
+}
+
+// 转换仓单商品ID为代code
+func (r *QryAuditContractRsp) WrStandardID2Code(id int64) string {
+
+	// init
+	if r.wrStandards == nil || len(r.wrStandards) == 0 {
+		r.wrStandards = make(map[int64]models.Wrstandard)
+		if wg, err := models.GetWrstandards(); err == nil {
+			for _, v := range wg {
+				r.wrStandards[v.Wrstandardid] = v
+			}
+		}
+	}
+
+	if v, ok := r.wrStandards[id]; ok {
+		return v.Wrstandardcode
+	}
+
+	return ""
+}
+
+// 构建响应数据
+func (r *QryAuditContractRsp) ParseFromModel(val models.AuditContractModel) error {
+	r.SpotContractId = val.SpotContractId
+	r.MatchAccountId = val.MatchAccountId
+	r.MatchCustomerName = val.MatchCustomerName
+	r.AccountId = val.AccountId
+	r.CustomerName = val.CustomerName
+	r.ApplyStatus = val.ApplyStatus
+
+	// 解析DetailJSON字段
+	details := make([]DetailJSON, 0)
+	if err := json.Unmarshal([]byte(val.DetailJSON), &details); err != nil {
+		logger.GetLogger().Errorf("parse detailJson field fail:%v", err)
+		return err
+	}
+
+	// 现在合同只有一张单
+	detail := details[0]
+
+	r.WrstandardName = detail.WrStandardName
+	r.DeliveryGoodsName = detail.DeliveryGoodsName
+	r.EnumdicName = detail.UnitName
+
+	// 汇总未定价量
+	r.UnpricedQty = 0
+	for _, v := range detail.SpotPointOrderVoList {
+		r.UnpricedQty += float64(v.Qty)
+	}
+
+	// 汇总定价量
+	r.PricedQty = 0
+	for _, v := range detail.SpotPriceOrderList {
+		r.PricedQty += float64(v.Qty)
+	}
+
+	// 总量
+	r.TotaldQty = r.UnpricedQty + r.PricedQty
+
+	// 转换仓单商品ID为代code
+	r.Wrstandardcode = r.WrStandardID2Code(int64(detail.WrStandardID))
+
+	// 转换交割商品ID为商品代码
+	r.DeliveryGoodscode = r.DeliverGoodsId2Code(int32(detail.DeliveryGoodsID))
+
+	return nil
+}
+
+// 构建响应数据
+func (r *QryAuditContractRsp) ParseFromHGModel(val models.AutditContractHGModel) error {
+	r.SpotContractId = val.SpotContractId
+	r.MatchCustomerName = val.MatchCustomerName
+	r.AccountId = val.AccountId
+	r.CustomerName = val.CustomerName
+	r.EnumdicName = val.EnumdicName
+	r.WrstandardName = val.WrstandardName
+	r.Wrstandardcode = val.Wrstandardcode
+	r.ApplyStatus = val.ApplyStatus
+	r.SignDate = val.SignDate
+	r.MatchAccountId = val.MatchAccountId
+	r.TotaldQty = val.ContractQty
+
+	return nil
+}
+
+// QueryPendingAuditContract  查询待审核合同
+// @Summary 查询待审核合同
+// @Produce json
+// @Security ApiKeyAuth
+// @Param accountid query int true "账号ID"
+// @Param contracttype query int true "合同类型 1-采购 -1-销售"
+// @Param contractmode query int true "合同模式 1-普通 2-回购"
+// @Success 200 {array} QryAuditContractRsp
+// @Failure 500 {object} app.Response
+// @Router /Erms3/QueryPendingAuditContract [get]
+// @Tags 风险管理v3
+func QueryPendingAuditContract(c *gin.Context) {
+	appG := app.Gin{C: c}
+	var req QryAuditContractReq
+	if err := c.ShouldBind(&req); err != nil {
+		logger.GetLogger().Errorf("parse query pending audit contract, %v", err)
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	// 参数检查
+	if req.ContractMode != 1 && req.ContractMode != 2 {
+		logger.GetLogger().Errorf("ContractMode not in(1, 2)")
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	if req.ContractMode == 1 {
+		if req.ContractType != 1 && req.ContractType != -1 {
+			logger.GetLogger().Errorf("ContractType not in(1, -1) when ContractMode=1")
+			appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+			return
+		}
+	}
+
+	switch req.ContractMode {
+	case 1: // 普通合同
+		var m models.AuditContractModel
+		if d, err := m.GetData(req.AccountId, req.ContractType); err == nil {
+			rsp := make([]QryAuditContractRsp, 0)
+			for _, v := range d {
+				var rv QryAuditContractRsp
+				if err := rv.ParseFromModel(v); err == nil {
+					rsp = append(rsp, rv)
+				} else {
+					appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+					return
+				}
+			}
+			appG.Response(http.StatusOK, e.SUCCESS, rsp)
+		}
+	case 2: // 回购合同
+		var m models.AutditContractHGModel
+		if d, err := m.GetData(req.AccountId); err == nil {
+			rsp := make([]QryAuditContractRsp, 0)
+			for _, v := range d {
+				var rv QryAuditContractRsp
+				if err := rv.ParseFromHGModel(v); err == nil {
+					rsp = append(rsp, rv)
+				} else {
+					appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+					return
+				}
+			}
+			appG.Response(http.StatusOK, e.SUCCESS, rsp)
+		}
+	default:
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+	}
+}

+ 137 - 0
docs/docs.go

@@ -20,6 +20,7 @@ var doc = `{
         "title": "{{.Title}}",
         "termsOfService": "http://muchinfo.cn",
         "contact": {},
+        "license": {},
         "version": "{{.Version}}"
     },
     "host": "{{.Host}}",
@@ -830,6 +831,62 @@ var doc = `{
                 }
             }
         },
+        "/Erms3/QueryPendingAuditContract": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "风险管理v3"
+                ],
+                "summary": "查询待审核合同",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "账号ID",
+                        "name": "accountid",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "合同类型 1-采购 -1-销售",
+                        "name": "contracttype",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "合同模式 1-普通 2-回购",
+                        "name": "contractmode",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "type": "array",
+                            "items": {
+                                "$ref": "#/definitions/erms3.QryAuditContractRsp"
+                            }
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Erms3/QuerySpotContractAppleForm": {
             "get": {
                 "security": [
@@ -2911,6 +2968,7 @@ var doc = `{
                 },
                 "province": {
                     "description": "省",
+                    "type": "object",
                     "$ref": "#/definitions/models.Division"
                 }
             }
@@ -4525,6 +4583,83 @@ var doc = `{
                 }
             }
         },
+        "erms3.QryAuditContractRsp": {
+            "type": "object",
+            "required": [
+                "matchcustomername",
+                "spotcontractid"
+            ],
+            "properties": {
+                "accountid": {
+                    "description": "交易员ID",
+                    "type": "string"
+                },
+                "applystatus": {
+                    "description": "状态",
+                    "type": "integer"
+                },
+                "curdeliveryqty": {
+                    "description": "未交收量",
+                    "type": "integer"
+                },
+                "customername": {
+                    "description": "采购方ID",
+                    "type": "string"
+                },
+                "deliverygoodscode": {
+                    "description": "品种代码",
+                    "type": "string"
+                },
+                "deliverygoodsname": {
+                    "description": "品种名称",
+                    "type": "string"
+                },
+                "deliveryqty": {
+                    "description": "交收量",
+                    "type": "integer"
+                },
+                "enumdicname": {
+                    "description": "单位名称",
+                    "type": "string"
+                },
+                "matchaccountid": {
+                    "description": "业务员ID",
+                    "type": "string"
+                },
+                "matchcustomername": {
+                    "description": "销售方ID",
+                    "type": "string"
+                },
+                "pricedqty": {
+                    "description": "定价量",
+                    "type": "number"
+                },
+                "signdate": {
+                    "description": "签订日期",
+                    "type": "string"
+                },
+                "spotcontractid": {
+                    "description": "合同ID",
+                    "type": "string"
+                },
+                "totaldqty": {
+                    "description": "合同量",
+                    "type": "number"
+                },
+                "unpricedqty": {
+                    "description": "未定价量",
+                    "type": "number"
+                },
+                "wrstandardcode": {
+                    "description": "商品代码",
+                    "type": "string"
+                },
+                "wrstandardname": {
+                    "description": "商品名称",
+                    "type": "string"
+                }
+            }
+        },
         "erms3.QuerySpotContractAppleFormRsp": {
             "type": "object",
             "properties": {
@@ -4544,6 +4679,7 @@ var doc = `{
                 },
                 "ouruser": {
                     "description": "我方账号",
+                    "type": "object",
                     "$ref": "#/definitions/erms3.CustomerInfo"
                 },
                 "warehouseinfos": {
@@ -4724,6 +4860,7 @@ var doc = `{
                 },
                 "province": {
                     "description": "省",
+                    "type": "object",
                     "$ref": "#/definitions/models.Division"
                 }
             }

+ 137 - 0
docs/swagger.json

@@ -5,6 +5,7 @@
         "title": "MTP2.0 查询服务 API",
         "termsOfService": "http://muchinfo.cn",
         "contact": {},
+        "license": {},
         "version": "1.0"
     },
     "basePath": "/api",
@@ -814,6 +815,62 @@
                 }
             }
         },
+        "/Erms3/QueryPendingAuditContract": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "风险管理v3"
+                ],
+                "summary": "查询待审核合同",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "账号ID",
+                        "name": "accountid",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "合同类型 1-采购 -1-销售",
+                        "name": "contracttype",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "合同模式 1-普通 2-回购",
+                        "name": "contractmode",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "type": "array",
+                            "items": {
+                                "$ref": "#/definitions/erms3.QryAuditContractRsp"
+                            }
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Erms3/QuerySpotContractAppleForm": {
             "get": {
                 "security": [
@@ -2895,6 +2952,7 @@
                 },
                 "province": {
                     "description": "省",
+                    "type": "object",
                     "$ref": "#/definitions/models.Division"
                 }
             }
@@ -4509,6 +4567,83 @@
                 }
             }
         },
+        "erms3.QryAuditContractRsp": {
+            "type": "object",
+            "required": [
+                "matchcustomername",
+                "spotcontractid"
+            ],
+            "properties": {
+                "accountid": {
+                    "description": "交易员ID",
+                    "type": "string"
+                },
+                "applystatus": {
+                    "description": "状态",
+                    "type": "integer"
+                },
+                "curdeliveryqty": {
+                    "description": "未交收量",
+                    "type": "integer"
+                },
+                "customername": {
+                    "description": "采购方ID",
+                    "type": "string"
+                },
+                "deliverygoodscode": {
+                    "description": "品种代码",
+                    "type": "string"
+                },
+                "deliverygoodsname": {
+                    "description": "品种名称",
+                    "type": "string"
+                },
+                "deliveryqty": {
+                    "description": "交收量",
+                    "type": "integer"
+                },
+                "enumdicname": {
+                    "description": "单位名称",
+                    "type": "string"
+                },
+                "matchaccountid": {
+                    "description": "业务员ID",
+                    "type": "string"
+                },
+                "matchcustomername": {
+                    "description": "销售方ID",
+                    "type": "string"
+                },
+                "pricedqty": {
+                    "description": "定价量",
+                    "type": "number"
+                },
+                "signdate": {
+                    "description": "签订日期",
+                    "type": "string"
+                },
+                "spotcontractid": {
+                    "description": "合同ID",
+                    "type": "string"
+                },
+                "totaldqty": {
+                    "description": "合同量",
+                    "type": "number"
+                },
+                "unpricedqty": {
+                    "description": "未定价量",
+                    "type": "number"
+                },
+                "wrstandardcode": {
+                    "description": "商品代码",
+                    "type": "string"
+                },
+                "wrstandardname": {
+                    "description": "商品名称",
+                    "type": "string"
+                }
+            }
+        },
         "erms3.QuerySpotContractAppleFormRsp": {
             "type": "object",
             "properties": {
@@ -4528,6 +4663,7 @@
                 },
                 "ouruser": {
                     "description": "我方账号",
+                    "type": "object",
                     "$ref": "#/definitions/erms3.CustomerInfo"
                 },
                 "warehouseinfos": {
@@ -4708,6 +4844,7 @@
                 },
                 "province": {
                     "description": "省",
+                    "type": "object",
                     "$ref": "#/definitions/models.Division"
                 }
             }

+ 97 - 0
docs/swagger.yaml

@@ -87,6 +87,7 @@ definitions:
       province:
         $ref: '#/definitions/models.Division'
         description: 省
+        type: object
     type: object
   common.QueryTableDefineRsp:
     properties:
@@ -1296,6 +1297,63 @@ definitions:
     required:
     - userid
     type: object
+  erms3.QryAuditContractRsp:
+    properties:
+      accountid:
+        description: 交易员ID
+        type: string
+      applystatus:
+        description: 状态
+        type: integer
+      curdeliveryqty:
+        description: 未交收量
+        type: integer
+      customername:
+        description: 采购方ID
+        type: string
+      deliverygoodscode:
+        description: 品种代码
+        type: string
+      deliverygoodsname:
+        description: 品种名称
+        type: string
+      deliveryqty:
+        description: 交收量
+        type: integer
+      enumdicname:
+        description: 单位名称
+        type: string
+      matchaccountid:
+        description: 业务员ID
+        type: string
+      matchcustomername:
+        description: 销售方ID
+        type: string
+      pricedqty:
+        description: 定价量
+        type: number
+      signdate:
+        description: 签订日期
+        type: string
+      spotcontractid:
+        description: 合同ID
+        type: string
+      totaldqty:
+        description: 合同量
+        type: number
+      unpricedqty:
+        description: 未定价量
+        type: number
+      wrstandardcode:
+        description: 商品代码
+        type: string
+      wrstandardname:
+        description: 商品名称
+        type: string
+    required:
+    - matchcustomername
+    - spotcontractid
+    type: object
   erms3.QuerySpotContractAppleFormRsp:
     properties:
       goodses:
@@ -1311,6 +1369,7 @@ definitions:
       ouruser:
         $ref: '#/definitions/erms3.CustomerInfo'
         description: 我方账号
+        type: object
       warehouseinfos:
         description: 仓库信息列表
         items:
@@ -1443,6 +1502,7 @@ definitions:
       province:
         $ref: '#/definitions/models.Division'
         description: 省
+        type: object
     type: object
   models.Division:
     properties:
@@ -4097,6 +4157,7 @@ definitions:
 info:
   contact: {}
   description: 新的查询服务,替代原通用查询服务。
+  license: {}
   termsOfService: http://muchinfo.cn
   title: MTP2.0 查询服务 API
   version: "1.0"
@@ -4605,6 +4666,42 @@ paths:
       summary: 新增现货合同申请
       tags:
       - 风险管理v3
+  /Erms3/QueryPendingAuditContract:
+    get:
+      parameters:
+      - description: 账号ID
+        in: query
+        name: accountid
+        required: true
+        type: integer
+      - description: 合同类型 1-采购 -1-销售
+        in: query
+        name: contracttype
+        required: true
+        type: integer
+      - description: 合同模式 1-普通 2-回购
+        in: query
+        name: contractmode
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            items:
+              $ref: '#/definitions/erms3.QryAuditContractRsp'
+            type: array
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 查询待审核合同
+      tags:
+      - 风险管理v3
   /Erms3/QuerySpotContractAppleForm:
     get:
       parameters:

+ 1 - 1
go.mod

@@ -32,7 +32,7 @@ require (
 	github.com/pkg/errors v0.9.1 // indirect
 	github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
 	github.com/sirupsen/logrus v1.4.2
-	github.com/streadway/amqp v1.0.0
+	github.com/streadway/amqp v1.0.0 // indirect
 	github.com/swaggo/gin-swagger v1.2.0
 	github.com/swaggo/swag v1.6.7
 	github.com/syndtr/goleveldb v1.0.0 // indirect

+ 2 - 0
go.sum

@@ -315,6 +315,7 @@ golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTk
 golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
 golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
 golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
+golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
 golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
 golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -396,6 +397,7 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+y
 golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
 golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
 google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=

+ 114 - 0
models/contractModel.go

@@ -0,0 +1,114 @@
+/**
+* @Author: zou.yingbin
+* @Create  : 2020/12/2 9:17
+* @Modify  : 2020/12/2 9:17
+ */
+
+// 查询待审核的合同
+package models
+
+import (
+	"fmt"
+	"mtp2_if/db"
+	"mtp2_if/logger"
+)
+
+// 待审核合同(普通合同)
+type AuditContractModel struct {
+	SpotContractId    string `json:"spotcontractid"  xorm:"'SPOTCONTRACTID'" binding:"required"`       // 合同ID
+	MatchCustomerName string `json:"matchcustomername"  xorm:"'MATCHCUSTOMERNAME'" binding:"required"` // 销售方ID
+	MatchAccountId    string `json:"matchaccountid"  xorm:"'MATCHACCOUNTID'"`                          // 业务员ID
+	AccountId         string `json:"accountid"  xorm:"'ACCOUNTID'"`                                    // 交易员ID
+	CustomerName      string `json:"customername"  xorm:"'CUSTOMERNAME'"`                              // 采购方ID
+	ApplyStatus       uint32 `json:"applystatus"  xorm:"'APPLYSTATUS'"`                                // 状态
+	EnumdicName       string `json:"enumdicname"  xorm:"'ENUMDICNAME'"`                                // 单位名称
+	DetailJSON        string `json:"detailjson"  xorm:"'DETAILJSON'"`                                  // 合同明细
+}
+
+// 组装查询普通待审核合同Sql
+func (r *AuditContractModel) buildSql(accountId uint64, contractType int32) string {
+	str := "select to_char(s.spotcontractid) spotcontractid," +
+		"       u.customername," +
+		"       s.accountid," +
+		"       u2.customername matchcustomername," +
+		"       s.customeraccountid matchaccountid," +
+		"       s.signdate," +
+		"       s.applystatus," +
+		"       to_char(s.DETAILJSON) DETAILJSON" +
+		"  from ERMS3_SpotContractApply s" +
+		"  left join userinfo u" +
+		"    on u.userid = s.areauserid" +
+		"  left join userinfo u2" +
+		"    on u2.userid = s.customeruserid" +
+		" where s.contracttype = %v" +
+		"   and s.applystatus in(0,2)" +
+		"   and s.accountid = %v"
+
+	return fmt.Sprintf(str, contractType, accountId)
+}
+
+// 获取待审核的合同
+func (r *AuditContractModel) GetData(accountId uint64, contractType int32) ([]AuditContractModel, error) {
+	sAC := make([]AuditContractModel, 0)
+	e := db.GetEngine()
+	s := e.SQL(r.buildSql(accountId, contractType))
+	if err := s.Find(&sAC); err != nil {
+		logger.GetLogger().Errorf("query pending contract fail:%v", err)
+		return sAC, err
+	}
+	return sAC, nil
+}
+
+// 待审核合同(回购)
+type AutditContractHGModel struct {
+	SpotContractId    string `json:"spotcontractid"  xorm:"'SPOTCONTRACTID'" binding:"required"`       // 合同ID
+	MatchCustomerName string `json:"matchcustomername"  xorm:"'MATCHCUSTOMERNAME'" binding:"required"` // 销售方ID
+	MatchAccountId    string `json:"matchaccountid"  xorm:"'MATCHACCOUNTID'"`                          // 业务员ID
+	AccountId         string `json:"accountid"  xorm:"'ACCOUNTID'"`                                    // 交易员ID
+	CustomerName      string `json:"customername"  xorm:"'CUSTOMERNAME'"`                              // 采购方ID
+	WrstandardName    string `json:"wrstandardname"  xorm:"'WRSTANDARDNAME'"`                          // 商品名称
+	Wrstandardcode    string `json:"wrstandardcode"  xorm:"'WRSTANDARDCODE'"`                          // 商品代码
+	ApplyStatus       uint32 `json:"applystatus"  xorm:"'APPLYSTATUS'"`                                // 状态
+	EnumdicName       string `json:"enumdicname"  xorm:"'ENUMDICNAME'"`                                // 单位名称
+	ContractQty       float64 `json:"contractqty"  xorm:"'CONTRACTQTY'"`                               // 合同量
+	SignDate          string `json:"signdate"  xorm:"'SIGNDATE'"`                                      // 签订日期
+}
+
+func (r *AutditContractHGModel) buildSql(accountId uint64) string {
+	sqlId := "select to_char(t.wrrcontractid) spotcontractid," +
+		"       t.accountid," +
+		"       t.contractqty," +
+		"       to_char(t.signdate, 'yyyy-mm-dd') signdate," +
+		"       t.applystatus," +
+		"       w.wrstandardname," +
+		"       w.wrstandardcode," +
+		"       u.accountname       customername," +
+		"       u2.accountname      matchcustomername," +
+		"       t.customeraccountid matchaccountid," +
+		"       ec.enumdicname" +
+		"  from erms2_wrrapply t" +
+		"  left join wrstandard w" +
+		"    on t.wrstandardid = w.wrstandardid" +
+		"  left join useraccount u" +
+		"    on t.areauserid = u.userid" +
+		"  left join useraccount u2" +
+		"    on t.customeruserid = u2.userid" +
+		"  left join enumdicitem ec" +
+		"    on w.unitid = ec.enumitemname" +
+		"   and ec.enumdiccode = 'goodsunit'" +
+		" where t.accountid = %v" +
+		"   and t.applystatus in (0, 2)"
+
+	return fmt.Sprintf(sqlId, accountId)
+}
+
+func (r *AutditContractHGModel) GetData(accountId uint64) ([]AutditContractHGModel, error) {
+	sAC := make([]AutditContractHGModel, 0)
+	e := db.GetEngine()
+	s := e.SQL(r.buildSql(accountId))
+	if err := s.Find(&sAC); err != nil{
+		logger.GetLogger().Errorf("query hg pending contract fail:%v", err)
+		return sAC, err
+	}
+	return sAC, nil
+}

+ 16 - 0
models/delivery.go

@@ -1,6 +1,11 @@
 // Package models 40.a交割服务
 package models
 
+import (
+	"fmt"
+	"mtp2_if/db"
+)
+
 // Deliverygoods 现货品种表
 type Deliverygoods struct {
 	Deliverygoodsid   int32   `json:"deliverygoodsid"  xorm:"'DELIVERYGOODSID'" binding:"required"`     // 交割商品ID(SEQ_DELIVERYGOODS)
@@ -55,3 +60,14 @@ type Deliveryrelation struct {
 func (Deliveryrelation) TableName() string {
 	return "DELIVERYRELATION"
 }
+
+// 获取交割商品
+func GetDeliverGoods() ([]Deliverygoods, error) {
+	engine := db.GetEngine()
+	d := make([]Deliverygoods, 0)
+	if err := engine.Where("IsValid=1").And("categoryid<>0").Find(&d); err != nil {
+		return nil, fmt.Errorf("query deleiverygoods fail")
+	}
+
+	return d, nil
+}

+ 2 - 0
routers/router.go

@@ -179,6 +179,8 @@ func InitRouter() *gin.Engine {
 		erms3R.POST("/AddSpotContractApply", erms3.AddSpotContractApply)
 		// 查询合同申请表单数据
 		erms3R.GET("/QuerySpotContractAppleForm", erms3.QuerySpotContractAppleForm)
+		// 查询待审核合同
+		erms3R.GET("/QueryPendingAuditContract", erms3.QueryPendingAuditContract)
 	}
 	// ************************ 定制【尚志大宗】 ************************
 	szdzR := apiR.Group("SZDZ")