Bläddra i källkod

Merge branch 'master' of 192.168.30.132:MTP2.0/MTP20_IF

zhou.xiaoning 4 år sedan
förälder
incheckning
8d193ec25e
11 ändrade filer med 3026 tillägg och 268 borttagningar
  1. 115 0
      controllers/ermcp3/qryErmcp3.go
  2. 777 81
      docs/docs.go
  3. 777 81
      docs/swagger.json
  4. 647 38
      docs/swagger.yaml
  5. 593 0
      models/ermcp3.go
  6. 22 22
      models/ermcpAccMgr.go
  7. 34 26
      models/ermcpOPApply.go
  8. 20 12
      models/ermcpWrstandard.go
  9. 21 0
      models/wrTrade.go
  10. 11 8
      routers/router.go
  11. 9 0
      utils/sqlUtils.go

+ 115 - 0
controllers/ermcp3/qryErmcp3.go

@@ -0,0 +1,115 @@
+/**
+* @Author: zou.yingbin
+* @Create  : 2021/4/15 10:35
+* @Modify  : 2021/4/15 10:35
+ */
+
+package ermcp3
+
+import (
+	"github.com/gin-gonic/gin"
+	"mtp2_if/global/app"
+	"mtp2_if/models"
+)
+
+// QueryDeliveryGoods
+// @Summary 查询现货商品
+// @Produce json
+// @Security ApiKeyAuth
+// @Param areauserid query int true "所属机构id"
+// @Param excludecfg query int false "排除已配置的现货商品 1-排除"
+// @Success 200 {array} models.ErmcpDeliveryGoods
+// @Failure 500 {object} app.Response
+// @Router /Ermcp3/QueryDeliveryGoods [get]
+// @Tags 企业风险管理v3(app)
+func QueryDeliveryGoods(c *gin.Context) {
+	a := app.GinUtils{Gin: app.Gin{C: c}}
+	req := struct {
+		AreaUserId int64 `form:"areauserid" binding:"required"` // 所属机构id
+		ExcludeCfg int32 `form:"excludecfg"`                    // 排除已配置的商品
+	}{}
+	a.DoBindReq(&req)
+	m := models.ErmcpDeliveryGoods{AREAUSERID: req.AreaUserId, ExcludeCfg: req.ExcludeCfg}
+	a.DoGetDataI(&m)
+}
+
+// QueryDeliveryGoodsDetail
+// @Summary 查询现货商品详情
+// @Produce json
+// @Security ApiKeyAuth
+// @Param areauserid query int true "所属机构id"
+// @Param deliverygoodsid query int false "现货商品id"
+// @Param qrytradegoods query int false "是否查询关联交易商品 1-查询"
+// @Success 200 {array} models.ErmcpDeliveryGoodsDetail
+// @Failure 500 {object} app.Response
+// @Router /Ermcp3/QueryDeliveryGoodsDetail [get]
+// @Tags 企业风险管理v3(app)
+func QueryDeliveryGoodsDetail(c *gin.Context) {
+	a := app.GinUtils{Gin: app.Gin{C: c}}
+	req := struct {
+		AreaUserId      int64 `form:"areauserid" binding:"required"` // 所属机构id
+		DeliveryGoodsId int32 `form:"deliverygoodsid"`               // 排除已配置的商品
+		QryTradeGoods   int32 `form:"qrytradegoods"`                 // 查询关联交易商品
+	}{}
+	a.DoBindReq(&req)
+	m := models.ErmcpDeliveryGoodsDetail{
+		Data:          models.ErmcpDeliveryGoods{AREAUSERID: req.AreaUserId, DELIVERYGOODSID: req.DeliveryGoodsId},
+		QryTradeGoods: req.QryTradeGoods}
+	a.DoGetDataI(&m)
+}
+
+// QryContractReq 查询合同请求
+type QryContractReq struct {
+	AreadUserId  int64  `form:"areauserid" binding:"required"`   // 所属机构Id
+	CONTRACTTYPE int32  `form:"contracttype" binding:"required"` // 合同类型 1-采购, -1-销售
+	QUERYTYPE    int64  `form:"querytype" binding:"required"`    // 查询类型 1-全部 2-待点价 3-履约结算 4-已完成
+	USERID       int64  `form:"userid"`                          // 用户Id
+	USERTYPE     int32  `form:"usertype"`                        // 用户类型
+	CONTRACTID   string `form:"contractid"`                      // 合同ID(SpotContractId)
+}
+
+// QuerySpotContract
+// @Summary 查询现货合同
+// @Produce json
+// @Security ApiKeyAuth
+// @Param areauserid query int true "所属机构ID"
+// @Param contracttype query int true "合同类型 1-采购, -1-销售"
+// @Param querytype query int true "查询类型 1-全部 2-待点价 3-履约结算 4-已完成"
+// @Param userid query int false "用户ID"
+// @Param usertype query int false "用户类型 2-机构 7-企业成员"
+// @Param contractid query string false "合同ID(SpotContractId)"
+// @Success 200 {array} models.Ermcp3Contract
+// @Failure 500 {object} app.Response
+// @Router /Ermcp3/QuerySpotContract [get]
+// @Tags 企业风险管理v3(app)
+func QuerySpotContract(c *gin.Context) {
+	a := app.GinUtils{Gin: app.Gin{C: c}}
+	req := QryContractReq{}
+	a.DoBindReq(&req)
+	m := models.Ermcp3Contract{USERID: req.AreadUserId, CONTRACTTYPE: req.CONTRACTTYPE,
+		OwnUserId: req.USERID, UserType: req.USERTYPE, SPOTCONTRACTID: req.CONTRACTID}
+	a.DoGetDataI(&m)
+}
+
+// QuerySpotContractBS
+// @Summary 查询合同(采购/销售)
+// @Produce json
+// @Security ApiKeyAuth
+// @Param areauserid query int true "所属机构ID"
+// @Param contracttype query int true "合同类型 1-采购, -1-销售"
+// @Param querytype query int true "查询类型 1-全部 2-待点价 3-履约结算 4-已完成"
+// @Param userid query int false "用户ID"
+// @Param usertype query int false "用户类型 2-机构 7-企业成员"
+// @Param contractid query string false "合同ID(SpotContractId)"
+// @Success 200 {array} models.Ermcp3SellBuyContract
+// @Failure 500 {object} app.Response
+// @Router /Ermcp3/QuerySpotContractBS [get]
+// @Tags 企业风险管理v3(app)
+func QuerySpotContractBS(c *gin.Context) {
+	a := app.GinUtils{Gin: app.Gin{C: c}}
+	req := QryContractReq{}
+	a.DoBindReq(&req)
+	m := models.Ermcp3SellBuyContract{UserID: req.AreadUserId, Contracttype: req.CONTRACTTYPE,
+		OwnUserId: req.USERID, UserType: req.USERTYPE, SpotContractId: req.CONTRACTID}
+	a.DoGetDataI(&m)
+}

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 777 - 81
docs/docs.go


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 777 - 81
docs/swagger.json


+ 647 - 38
docs/swagger.yaml

@@ -1361,6 +1361,15 @@ definitions:
       contracttype:
         description: 现货合同类型 - 1:采购 -1:销售
         type: integer
+      deliverygoodscode:
+        description: 现货品种代码
+        type: string
+      deliverygoodsid:
+        description: 现货商品ID
+        type: integer
+      deliverygoodsname:
+        description: 现货品种名称
+        type: string
       enumdicname:
         description: 单位名称
         type: string
@@ -1398,13 +1407,13 @@ definitions:
         description: 用户ID
         type: integer
       wrstandardcode:
-        description: 现货商品代码
+        description: 品代码
         type: string
       wrstandardid:
-        description: 现货商品id
+        description: 品id
         type: integer
       wrstandardname:
-        description: 现货商品名称
+        description: 品名称
         type: string
     type: object
   ermcp.QryBussinessFpRsp:
@@ -1445,6 +1454,15 @@ definitions:
       contracttype:
         description: 现货合同类型 - 1:采购 -1:销售
         type: integer
+      deliverygoodscode:
+        description: 现货品种代码
+        type: string
+      deliverygoodsid:
+        description: 现货商品ID
+        type: integer
+      deliverygoodsname:
+        description: 现货品种名称
+        type: string
       enumdicname:
         description: 单位名称
         type: string
@@ -1479,13 +1497,13 @@ definitions:
         description: 用户ID
         type: integer
       wrstandardcode:
-        description: 现货商品代码
+        description: 品代码
         type: string
       wrstandardid:
-        description: 现货商品id
+        description: 品id
         type: integer
       wrstandardname:
-        description: 现货商品名称
+        description: 品名称
         type: string
     type: object
   ermcp.QryBussinessJsExRsp:
@@ -1526,6 +1544,15 @@ definitions:
       contracttype:
         description: 现货合同类型 - 1:采购 -1:销售
         type: integer
+      deliverygoodscode:
+        description: 现货品种代码
+        type: string
+      deliverygoodsid:
+        description: 现货商品ID
+        type: integer
+      deliverygoodsname:
+        description: 现货品种名称
+        type: string
       enumdicname:
         description: 单位名称
         type: string
@@ -1563,13 +1590,13 @@ definitions:
         description: 用户ID
         type: integer
       wrstandardcode:
-        description: 现货商品代码
+        description: 品代码
         type: string
       wrstandardid:
-        description: 现货商品id
+        description: 品id
         type: integer
       wrstandardname:
-        description: 现货商品名称
+        description: 品名称
         type: string
     type: object
   ermcp.QryBussinessJsRsp:
@@ -1616,6 +1643,15 @@ definitions:
       decmargin:
         description: 减少保证金(非必填)
         type: number
+      deliverygoodscode:
+        description: 现货品种代码
+        type: string
+      deliverygoodsid:
+        description: 现货商品ID
+        type: integer
+      deliverygoodsname:
+        description: 现货品种名称
+        type: string
       enumdicname:
         description: 单位名称
         type: string
@@ -1659,13 +1695,13 @@ definitions:
         description: 用户ID
         type: integer
       wrstandardcode:
-        description: 现货商品代码
+        description: 品代码
         type: string
       wrstandardid:
-        description: 现货商品id
+        description: 品id
         type: integer
       wrstandardname:
-        description: 现货商品名称
+        description: 品名称
         type: string
     type: object
   ermcp.QryBussinessKxRsp:
@@ -1709,6 +1745,15 @@ definitions:
       deductamount:
         description: 退款(非必填)
         type: number
+      deliverygoodscode:
+        description: 现货品种代码
+        type: string
+      deliverygoodsid:
+        description: 现货商品ID
+        type: integer
+      deliverygoodsname:
+        description: 现货品种名称
+        type: string
       enumdicname:
         description: 单位名称
         type: string
@@ -1746,13 +1791,13 @@ definitions:
         description: 用户ID
         type: integer
       wrstandardcode:
-        description: 现货商品代码
+        description: 品代码
         type: string
       wrstandardid:
-        description: 现货商品id
+        description: 品id
         type: integer
       wrstandardname:
-        description: 现货商品名称
+        description: 品名称
         type: string
     type: object
   ermcp.QryErmcpRsp:
@@ -4654,23 +4699,311 @@ definitions:
       enumitemstatus:
         description: 枚举项状态 - 1.启用 2.不启用
         type: integer
-      enumitemvalue:
-        description: 通用值 - [币种通用简写]
-        type: string
-      param1:
-        description: 参数1[币种:币种小数位]
-        type: string
-      param2:
-        description: 参数1[币种:币种显示单位]
+      enumitemvalue:
+        description: 通用值 - [币种通用简写]
+        type: string
+      param1:
+        description: 参数1[币种:币种小数位]
+        type: string
+      param2:
+        description: 参数1[币种:币种显示单位]
+        type: string
+      remark:
+        description: 备注
+        type: string
+    required:
+    - autoid
+    - enumdiccode
+    - enumdicid
+    - enumitemname
+    type: object
+  models.Ermcp3Contract:
+    properties:
+      amount:
+        description: 金额 [1:一口价、3:暂定价]
+        type: number
+      attachment:
+        description: 附件
+        type: string
+      auditremark:
+        description: 审核意见
+        type: string
+      audittime:
+        description: 审核时间
+        type: string
+      brandname:
+        description: 品牌名称
+        type: string
+      buyuserid:
+        description: 采购方ID
+        type: integer
+      buyusername:
+        description: 采购方名称
+        type: string
+      contracctstatus:
+        description: 合同状态 - 0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回
+        type: integer
+      contractmargin:
+        description: 合同保证金
+        type: number
+      contractno:
+        description: 现货合同编号
+        type: string
+      contracttype:
+        description: 现货合同类型 - 1:采购 -1:销售
+        type: integer
+      convertfactor:
+        description: 标仓系数(品类)
+        type: number
+      createtime:
+        description: 创建时间
+        type: string
+      deliveryenddate:
+        description: 交收期(结束)
+        type: string
+      deliverygoodscode:
+        description: 现货品种代码
+        type: string
+      deliverygoodsid:
+        description: 现货品种ID
+        type: integer
+      deliverygoodsname:
+        description: 现货品种名称
+        type: string
+      deliverystartdate:
+        description: 交收期(开始)
+        type: string
+      enddate:
+        description: 点价结束日期 [2:点价 3:暂定价]
+        type: string
+      enumdicname:
+        description: 单位名称
+        type: string
+      goodscode:
+        description: 点价合约代码
+        type: string
+      goodsid:
+        description: 点价合约ID - 0:为现货,其它为期货商品合约ID [2:点价 3:暂定价]
+        type: integer
+      goodsname:
+        description: 点价商品名称
+        type: string
+      margin:
+        description: 当前保证金
+        type: number
+      price:
+        description: 价格\暂定价 [1:一口价、3:暂定价]
+        type: number
+      pricemove:
+        description: 升贴水 [2:点价 3:暂定价]
+        type: number
+      pricetype:
+        description: 定价类型 - 1:一口价 2:点价 3:暂定价
+        type: integer
+      producttype:
+        description: 产品类型 - 1:标准仓单 2:等标 3:非标
+        type: integer
+      qty:
+        description: 数量
+        type: number
+      remark:
+        description: 备注
+        type: string
+      selluserid:
+        description: 销售方ID
+        type: integer
+      sellusername:
+        description: 销售方名称
+        type: string
+      spotcontractid:
+        description: 现货合同ID(602+Unix秒时间戳(10位)+xxxxxx)
+        type: string
+      spotgoodsbrandid:
+        description: 现货品牌ID(DGFactoryItem表的ID)
+        type: integer
+      spotgoodsdesc:
+        description: 商品型号
+        type: string
+      startdate:
+        description: 点价开始日期 [2:点价 3:暂定价]
+        type: string
+      unitid:
+        description: 单位id(取品类上的单位id)
+        type: integer
+      updatetime:
+        description: 更新时间
+        type: string
+      userid:
+        description: 所属机构ID
+        type: integer
+      wrstandardcode:
+        description: 品类代码
+        type: string
+      wrstandardid:
+        description: 品类ID
+        type: integer
+      wrstandardname:
+        description: 品类名称
+        type: string
+    type: object
+  models.Ermcp3SellBuyContract:
+    properties:
+      accountname:
+        description: 账户名称
+        type: string
+      attachment:
+        description: 附件
+        type: string
+      audittime:
+        description: 审核时间
+        type: string
+      brandname:
+        description: 品牌名称
+        type: string
+      contracctstatus:
+        description: 合同状态- 0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回
+        type: integer
+      contractmargin:
+        description: 合同保证金
+        type: number
+      contractno:
+        description: 合同编号
+        type: string
+      contracttype:
+        description: 合同类型 1-采购, -1-销售
+        type: integer
+      convertfactor:
+        description: 标仓系数(品类)
+        type: number
+      createtime:
+        description: 创建时间
+        type: string
+      daikaiamount:
+        description: 应收(开)票额
+        type: number
+      deliveryenddate:
+        description: 交割结束日
+        type: string
+      deliverygoodscode:
+        description: 现货品种代码
+        type: string
+      deliverygoodsid:
+        description: 现货商品ID
+        type: integer
+      deliverygoodsname:
+        description: 现货品种名称
+        type: string
+      deliverystartdate:
+        description: 交割开始日
+        type: string
+      enddate:
+        description: 点价结束日
+        type: string
+      enumdicname:
+        description: 单位名称
+        type: string
+      goodscode:
+        description: 点价商品代码
+        type: string
+      goodsid:
+        description: 点价商品ID
+        type: integer
+      goodsname:
+        description: 点价商品名称
+        type: string
+      invoiceamount:
+        description: 已开票额
+        type: number
+      loanamount:
+        description: 贷款总额=已定价额+调整金额
+        type: number
+      margin:
+        description: 保证金
+        type: number
+      payamount:
+        description: 已收付额(收款或付款)
+        type: number
+      preinvoiceamount:
+        description: 预收(开)票额
+        type: number
+      prepayamount:
+        description: 预收付额
+        type: number
+      price:
+        description: 价格
+        type: number
+      pricedamount:
+        description: 已定价额
+        type: number
+      pricedavg:
+        description: 已点均价
+        type: number
+      pricedqty:
+        description: 已定价量
+        type: number
+      pricemove:
+        description: 升贴水
+        type: number
+      pricetype:
+        description: 定价类型 - 1:一口价 2:点价 3:暂定价
+        type: integer
+      producttype:
+        description: 产品类型 - 1:标准仓单 2:等标 3:非标
+        type: integer
+      qty:
+        description: 合同量
+        type: number
+      reckonadjustamount:
+        description: 调整金额
+        type: number
+      reckonedamount:
+        description: 实际已收付额(已确定额,已收付总额-已退款总额)
+        type: number
+      reckonotheramount:
+        description: 其它费用
+        type: number
+      reckonrealqty:
+        description: 已确定量
+        type: number
+      remark:
+        description: 备注
+        type: string
+      spotcontractid:
+        description: 合同ID
+        type: string
+      spotgoodsbrandid:
+        description: 现货品牌ID(DGFactoryItem表的ID)
+        type: integer
+      spotgoodsdesc:
+        description: 商品型号(商品规格)
+        type: string
+      startdate:
+        description: 点价开始日
+        type: string
+      totalamount:
+        description: 合计总额
+        type: number
+      unpayamount:
+        description: 应收付款额(应支付或应收款)
+        type: number
+      unpricedqty:
+        description: 未定价量
+        type: number
+      unsureqty:
+        description: 未确定量
+        type: number
+      userid:
+        description: 机构ID
+        type: integer
+      wrstandardcode:
+        description: 品类代码
         type: string
-      remark:
-        description: 备注
+      wrstandardid:
+        description: 品类ID
+        type: integer
+      wrstandardname:
+        description: 品类名称
         type: string
-    required:
-    - autoid
-    - enumdiccode
-    - enumdicid
-    - enumitemname
     type: object
   models.ErmcpAreaStock:
     properties:
@@ -4950,7 +5283,7 @@ definitions:
         description: 业务类型 1-套保 2-套利
         type: integer
       wrlist:
-        description: 现货商品表
+        description: 现货商品表
         items:
           $ref: '#/definitions/models.ErmcpBizGroupSpotGoods'
         type: array
@@ -4966,18 +5299,18 @@ definitions:
       biztype:
         description: 业务类型 1-套保 2-套利
         type: integer
-      unitid:
-        description: 现货商品单位id
-        type: integer
-      wrstandardcode:
+      deliverygoodscode:
         description: 现货商品代码
         type: string
-      wrstandardid:
+      deliverygoodsid:
         description: 现货商品id
         type: integer
-      wrstandardname:
+      deliverygoodsname:
         description: 现货商品名称
         type: string
+      unitid:
+        description: 现货商品单位id
+        type: integer
     type: object
   models.ErmcpBizGroupTaAccount:
     properties:
@@ -4997,6 +5330,92 @@ definitions:
         description: 是否主账号 1-是 0-否
         type: integer
     type: object
+  models.ErmcpBrand:
+    properties:
+      brandid:
+        description: 品牌id
+        type: integer
+      brandname:
+        description: 品牌名称
+        type: string
+      deliverygoodsid:
+        description: 品种ID
+        type: integer
+    type: object
+  models.ErmcpDeliveryGoods:
+    properties:
+      agreeunit:
+        description: 合约单位[散货时默认为1, 整装时默认为标准数量]
+        type: integer
+      areauserid:
+        description: 所属机构
+        type: integer
+      auditflag:
+        description: 交割是否需要审核 - 0:不需要 1:需要审核   默认为0
+        type: integer
+      categoryid:
+        description: 类别ID(SEQ_WRCATEGORY)
+        type: integer
+      deliverygoodscode:
+        description: 现货品种代码
+        type: string
+      deliverygoodsid:
+        description: 现货品种ID(SEQ_DELIVERYGOODS)
+        type: integer
+      deliverygoodsname:
+        description: 现货品种名称
+        type: string
+      deliverygoodstype:
+        description: '现货品种类型: 1-整装不拆分 2-散装记录明细 3:整装拆分 4:散装不记录明细'
+        type: integer
+      dgstatus:
+        description: 品种状态 - 作废 - 0:未激活 1:正常
+        type: integer
+      enumdicname:
+        description: 现货品种单位名称
+        type: string
+      goodsunitid:
+        description: 现货品种单位ID
+        type: integer
+      isvalid:
+        description: 是否有效 - 0:无效 1:有效
+        type: integer
+      qtydecimalplace:
+        description: 成交量小数位
+        type: integer
+      standardqty:
+        description: 标准数量(库位数量) [标准品特有]
+        type: integer
+      standardqtyrange:
+        description: 标准数量偏差范围 [标准品特有]
+        type: integer
+    type: object
+  models.ErmcpDeliveryGoodsDetail:
+    properties:
+      data:
+        $ref: '#/definitions/models.ErmcpDeliveryGoods'
+        description: 现货商品基本信息(交割品种)
+      gblist:
+        description: 品牌列表
+        items:
+          $ref: '#/definitions/models.ErmcpBrand'
+        type: array
+      gmlist:
+        description: 品类列表(仓单标准)
+        items:
+          $ref: '#/definitions/models.ErmcpWrstandard'
+        type: array
+      goodslist:
+        description: 关联交易商品列表
+        items:
+          $ref: '#/definitions/models.ErmcpRelatedGoods'
+        type: array
+      wrslist:
+        description: 套保信息列表
+        items:
+          $ref: '#/definitions/models.WRSConverTDetail'
+        type: array
+    type: object
   models.ErmcpFuturesCompany:
     properties:
       brokerid:
@@ -5194,6 +5613,12 @@ definitions:
       createtime:
         description: 创建时间
         type: string
+      logincode:
+        description: 登录代码
+        type: string
+      loginid:
+        description: 登录id(LOGINID)
+        type: integer
       loginstatus:
         description: 登录账户状态 - 1:正常 2:冻结 3:无效
         type: integer
@@ -5221,6 +5646,9 @@ definitions:
     type: object
   models.ErmcpLoginUserEx:
     properties:
+      roleid:
+        description: 角色id
+        type: integer
       rolename:
         description: 角色名称
         type: string
@@ -5281,6 +5709,21 @@ definitions:
         description: 备注
         type: string
     type: object
+  models.ErmcpRelatedGoods:
+    properties:
+      deliverygoodsid:
+        description: 品种ID
+        type: integer
+      goodscode:
+        description: 商品代码
+        type: string
+      goodsid:
+        description: 商品id
+        type: integer
+      goodsname:
+        description: 商品名称
+        type: string
+    type: object
   models.ErmcpReportAreaSpotPL:
     properties:
       actualpl:
@@ -8846,9 +9289,15 @@ definitions:
       convertratio:
         description: 套保系数
         type: number
+      deliverygoodscode:
+        description: 现货商品代码
+        type: string
       deliverygoodsid:
         description: 现货品种ID
         type: integer
+      deliverygoodsname:
+        description: 现货商品名称
+        type: string
       enumdicname:
         description: 单位名称
         type: string
@@ -8868,7 +9317,7 @@ definitions:
         description: 修改时间
         type: string
       wrstandardid:
-        description: 现货商品ID
+        description: 品ID
         type: integer
     type: object
   models.WRStandardInfo:
@@ -13391,6 +13840,166 @@ paths:
       summary: 查询现货商品详情(菜单:现货品种/现货品种详情)
       tags:
       - 企业风险管理(app)
+  /Ermcp3/QueryDeliveryGoods:
+    get:
+      parameters:
+      - description: 所属机构id
+        in: query
+        name: areauserid
+        required: true
+        type: integer
+      - description: 排除已配置的现货商品 1-排除
+        in: query
+        name: excludecfg
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            items:
+              $ref: '#/definitions/models.ErmcpDeliveryGoods'
+            type: array
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 查询现货商品
+      tags:
+      - 企业风险管理v3(app)
+  /Ermcp3/QueryDeliveryGoodsDetail:
+    get:
+      parameters:
+      - description: 所属机构id
+        in: query
+        name: areauserid
+        required: true
+        type: integer
+      - description: 现货商品id
+        in: query
+        name: deliverygoodsid
+        type: integer
+      - description: 是否查询关联交易商品 1-查询
+        in: query
+        name: qrytradegoods
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            items:
+              $ref: '#/definitions/models.ErmcpDeliveryGoodsDetail'
+            type: array
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 查询现货商品详情
+      tags:
+      - 企业风险管理v3(app)
+  /Ermcp3/QuerySpotContract:
+    get:
+      parameters:
+      - description: 所属机构ID
+        in: query
+        name: areauserid
+        required: true
+        type: integer
+      - description: 合同类型 1-采购, -1-销售
+        in: query
+        name: contracttype
+        required: true
+        type: integer
+      - description: 查询类型 1-全部 2-待点价 3-履约结算 4-已完成
+        in: query
+        name: querytype
+        required: true
+        type: integer
+      - description: 用户ID
+        in: query
+        name: userid
+        type: integer
+      - description: 用户类型 2-机构 7-企业成员
+        in: query
+        name: usertype
+        type: integer
+      - description: 合同ID(SpotContractId)
+        in: query
+        name: contractid
+        type: string
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            items:
+              $ref: '#/definitions/models.Ermcp3Contract'
+            type: array
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 查询现货合同
+      tags:
+      - 企业风险管理v3(app)
+  /Ermcp3/QuerySpotContractBS:
+    get:
+      parameters:
+      - description: 所属机构ID
+        in: query
+        name: areauserid
+        required: true
+        type: integer
+      - description: 合同类型 1-采购, -1-销售
+        in: query
+        name: contracttype
+        required: true
+        type: integer
+      - description: 查询类型 1-全部 2-待点价 3-履约结算 4-已完成
+        in: query
+        name: querytype
+        required: true
+        type: integer
+      - description: 用户ID
+        in: query
+        name: userid
+        type: integer
+      - description: 用户类型 2-机构 7-企业成员
+        in: query
+        name: usertype
+        type: integer
+      - description: 合同ID(SpotContractId)
+        in: query
+        name: contractid
+        type: string
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            items:
+              $ref: '#/definitions/models.Ermcp3SellBuyContract'
+            type: array
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 查询合同(采购/销售)
+      tags:
+      - 企业风险管理v3(app)
   /Erms2/QueryArbitrageStrategy:
     get:
       parameters:

+ 593 - 0
models/ermcp3.go

@@ -0,0 +1,593 @@
+/**
+* @Author: zou.yingbin
+* @Create  : 2021/4/14 11:11
+* @Modify  : 2021/4/14 11:11
+ */
+
+package models
+
+import (
+	"fmt"
+	"mtp2_if/db"
+	"mtp2_if/mtpcache"
+	"mtp2_if/utils"
+)
+
+// ErmcpDeliveryGoods 现货品种(交割品种)
+type ErmcpDeliveryGoods struct {
+	DELIVERYGOODSID   int32  `json:"deliverygoodsid"  xorm:"'DELIVERYGOODSID'"`     // 现货品种ID(SEQ_DELIVERYGOODS)
+	DELIVERYGOODSCODE string `json:"deliverygoodscode"  xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码
+	DELIVERYGOODSNAME string `json:"deliverygoodsname"  xorm:"'DELIVERYGOODSNAME'"` // 现货品种名称
+	GOODSUNITID       int32  `json:"goodsunitid"  xorm:"'GOODSUNITID'"`             // 现货品种单位ID
+	DELIVERYGOODSTYPE int32  `json:"deliverygoodstype"  xorm:"'DELIVERYGOODSTYPE'"` // 现货品种类型: 1-整装不拆分 2-散装记录明细 3:整装拆分 4:散装不记录明细
+	STANDARDQTY       int32  `json:"standardqty"  xorm:"'STANDARDQTY'"`             // 标准数量(库位数量) [标准品特有]
+	STANDARDQTYRANGE  int32  `json:"standardqtyrange"  xorm:"'STANDARDQTYRANGE'"`   // 标准数量偏差范围 [标准品特有]
+	AUDITFLAG         int32  `json:"auditflag"  xorm:"'AUDITFLAG'"`                 // 交割是否需要审核 - 0:不需要 1:需要审核   默认为0
+	ISVALID           int32  `json:"isvalid"  xorm:"'ISVALID'"`                     // 是否有效 - 0:无效 1:有效
+	AGREEUNIT         int32  `json:"agreeunit"  xorm:"'AGREEUNIT'"`                 // 合约单位[散货时默认为1, 整装时默认为标准数量]
+	QTYDECIMALPLACE   int32  `json:"qtydecimalplace"  xorm:"'QTYDECIMALPLACE'"`     // 成交量小数位
+	CATEGORYID        int32  `json:"categoryid"  xorm:"'CATEGORYID'"`               // 类别ID(SEQ_WRCATEGORY)
+	DGSTATUS          int32  `json:"dgstatus"  xorm:"'DGSTATUS'"`                   // 品种状态 - 作废 - 0:未激活 1:正常
+	AREAUSERID        int64  `json:"areauserid"  xorm:"'AREAUSERID'"`               // 所属机构
+
+	EnumdicName string `json:"enumdicname"` // 现货品种单位名称
+	ExcludeCfg  int32  `json:"-"`           // 排除已配置项 1-排除
+}
+
+func (r *ErmcpDeliveryGoods) calc() {
+	r.EnumdicName = mtpcache.GetEnumDicitemName(r.GOODSUNITID)
+}
+
+func (r *ErmcpDeliveryGoods) buildSql() string {
+	var sqlId utils.SQLVal = "SELECT t.DELIVERYGOODSID," +
+		"       t.DELIVERYGOODSCODE," +
+		"       t.DELIVERYGOODSNAME," +
+		"       t.GOODSUNITID," +
+		"       t.DELIVERYGOODSTYPE," +
+		"       t.STANDARDQTY," +
+		"       t.STANDARDQTYRANGE," +
+		"       t.AUDITFLAG," +
+		"       t.ISVALID," +
+		"       t.ISSPLIT," +
+		"       t.AGREEUNIT," +
+		"       t.QTYDECIMALPLACE," +
+		"       t.CATEGORYID," +
+		"       t.DGSTATUS," +
+		"       t.AREAUSERID" +
+		"  FROM DELIVERYGOODS t" +
+		" WHERE 1 = 1"
+	sqlId.AndEx("t.AREAUSERID", r.AREAUSERID, r.AREAUSERID > 0)
+	sqlId.AndEx("t.DELIVERYGOODSID", r.DELIVERYGOODSID, r.DELIVERYGOODSID > 0)
+	if r.ExcludeCfg == 1 {
+		sqlId.Join(" and t.deliverygoodsid not in(select distinct deliverygoodsid from ermcp_bizgroupspotgoods)")
+	}
+	return sqlId.String()
+}
+
+// GetDataEx 获取现货商品(交割商品)
+func (r *ErmcpDeliveryGoods) GetDataEx() (interface{}, error) {
+	return r.GetData()
+}
+
+// GetData
+func (r *ErmcpDeliveryGoods) GetData() ([]ErmcpDeliveryGoods, error) {
+	sData := make([]ErmcpDeliveryGoods, 0)
+	err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
+	for i := range sData {
+		sData[i].calc()
+	}
+	return sData, err
+}
+
+// ErmcpDGFactoryItem 品种选择项定义表
+type ErmcpDGFactoryItem struct {
+	DGFACTORYITEMID     int64  // 选择项ID(SEQ_DGFACTORYITEM)
+	DELIVERYGOODSID     int32  // 品种ID
+	DGFACTORYITEMTYPEID int64  // 要素项类型
+	DGFACTORYITEMVALUE  string // 要素项值(类型为仓库时填写仓库名称)
+	WAREHOUSEID         int64  // 仓库ID(类型为仓库时填写)
+	ISVALID             int32  // 是否有效 - 0:无效 1:有效
+	ORDERINDEX          int32  // 顺序
+}
+
+func (r *ErmcpDGFactoryItem) buildSql() string {
+	var sqlId utils.SQLVal = "SELECT DGFACTORYITEMID," +
+		"       t.DELIVERYGOODSID," +
+		"       to_char(t.DGFACTORYITEMTYPEID) DGFACTORYITEMTYPEID," +
+		"       t.DGFACTORYITEMVALUE," +
+		"       to_char(t.WAREHOUSEID) WAREHOUSEID," +
+		"       t.ISVALID," +
+		"       t.ORDERINDEX" +
+		"  FROM DGFACTORYITEM t" +
+		" WHERE ISVALID = 1"
+	sqlId.AndEx("t.DGFACTORYITEMID", r.DGFACTORYITEMID, r.DGFACTORYITEMID > 0)
+	sqlId.AndEx("t.DELIVERYGOODSID", r.DELIVERYGOODSID, r.DELIVERYGOODSID > 0)
+	sqlId.AndEx("t.DGFACTORYITEMTYPEID", r.DGFACTORYITEMTYPEID, r.DGFACTORYITEMTYPEID > 0)
+	sqlId.AndEx("t.ORDERINDEX", r.ORDERINDEX, r.ORDERINDEX > 0)
+
+	return sqlId.String()
+}
+
+// GetDataEx 获取品种选择项定义
+func (r *ErmcpDGFactoryItem) GetDataEx() (interface{}, error) {
+	return r.GetData()
+}
+
+// GetData
+func (r *ErmcpDGFactoryItem) GetData() (interface{}, error) {
+	sData := make([]ErmcpDGFactoryItem, 0)
+	err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
+	return sData, err
+}
+
+// ErmcpBrand 品牌(从品种选择项定义表中查)
+type ErmcpBrand struct {
+	BRANDID         int64  `json:"brandid"`         // 品牌id
+	BRANDNAME       string `json:"brandname"`       // 品牌名称
+	DELIVERYGOODSID int32  `json:"deliverygoodsid"` // 品种ID
+}
+
+// 获取品牌数据
+func (r *ErmcpBrand) GetData() ([]ErmcpBrand, error) {
+	m := ErmcpDGFactoryItem{
+		DELIVERYGOODSID:     r.DELIVERYGOODSID,
+		DGFACTORYITEMTYPEID: 2,
+		ORDERINDEX:          1,
+	}
+	sData := make([]ErmcpBrand, 0)
+	if d, err := m.GetDataEx(); err == nil {
+		if dgLst, ok := d.([]ErmcpDGFactoryItem); ok {
+			for _, val := range dgLst {
+				sData = append(sData, ErmcpBrand{BRANDID: val.DGFACTORYITEMID,
+					BRANDNAME: val.DGFACTORYITEMVALUE, DELIVERYGOODSID: val.DELIVERYGOODSID})
+			}
+		}
+	}
+	return sData, nil
+}
+
+// ErmcpRelatedGoods 现货品种的关联交易商品
+type ErmcpRelatedGoods struct {
+	GoodsId         int    `json:"goodsid"  xorm:"'GoodsId'"`                 // 商品id
+	GoodsCode       string `json:"goodscode"  xorm:"'GoodsCode'"`             // 商品代码
+	GoodsName       string `json:"goodsname"  xorm:"'GoodsName'"`             // 商品名称
+	DELIVERYGOODSID int32  `json:"deliverygoodsid"  xorm:"'DELIVERYGOODSID'"` // 品种ID
+
+	AREAUSERID int64 `json:"-"` // 所属机构
+}
+
+func (r *ErmcpRelatedGoods) buildSql() string {
+	var sqlId utils.SQLVal = "select distinct t.deliverygoodsid, g.goodsid, g.goodscode, g.goodsname" +
+		"  from deliverygoods t" +
+		" inner join ERMS2_WRSConvertDetail w" +
+		"    on t.deliverygoodsid = w.deliverygoodsid" +
+		" inner join erms_middlegoods m" +
+		"    on w.middlegoodsid = m.middlegoodsid" +
+		" inner join ERMCP_GGConvertConfig gc" +
+		"    on m.goodsgroupid = gc.destgoodsgroupid" +
+		" inner join goods g" +
+		"    on gc.srcgoodsgroupid = g.goodsgroupid" +
+		" where 1 = 1"
+	sqlId.AndEx("t.AREAUSERID", r.AREAUSERID, r.AREAUSERID > 0)
+	sqlId.AndEx("t.DELIVERYGOODSID", r.DELIVERYGOODSID, r.DELIVERYGOODSID > 0)
+	return sqlId.String()
+}
+
+// GetDataEx 获取现货关联交易商品
+func (r *ErmcpRelatedGoods) GetDataEx() (interface{}, error) {
+	return r.GetData()
+}
+
+// GetData 获取现货关联交易商品
+func (r *ErmcpRelatedGoods) GetData() ([]ErmcpRelatedGoods, error) {
+	sData := make([]ErmcpRelatedGoods, 0)
+	err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
+	return sData, err
+}
+
+// ErmcpDeliveryGoodsDetail 现货商品详情
+type ErmcpDeliveryGoodsDetail struct {
+	Data      ErmcpDeliveryGoods  `json:"data"`      // 现货商品基本信息(交割品种)
+	GmList    []ErmcpWrstandard   `json:"gmlist"`    // 品类列表(仓单标准)
+	GbList    []ErmcpBrand        `json:"gblist"`    // 品牌列表
+	WrsList   []WRSConverTDetail  `json:"wrslist"`   // 套保信息列表
+	GoodsList []ErmcpRelatedGoods `json:"goodslist"` // 关联交易商品列表
+
+	QryTradeGoods int32 `json:"-"` // 是否查询关联交易商品 1-查询
+}
+
+func (r *ErmcpDeliveryGoodsDetail) addGmList(lst []ErmcpWrstandard) {
+	for i := range lst {
+		if lst[i].DELIVERYGOODSID == r.Data.DELIVERYGOODSID {
+			r.GmList = append(r.GmList, lst[i])
+		}
+	}
+}
+
+func (r *ErmcpDeliveryGoodsDetail) addGbList(lst []ErmcpBrand) {
+	for i := range lst {
+		if lst[i].DELIVERYGOODSID == r.Data.DELIVERYGOODSID {
+			r.GbList = append(r.GbList, lst[i])
+		}
+	}
+}
+
+func (r *ErmcpDeliveryGoodsDetail) addWrsList(lst []WRSConverTDetail) {
+	for i := range lst {
+		if lst[i].DELIVERYGOODSID == r.Data.DELIVERYGOODSID {
+			r.WrsList = append(r.WrsList, lst[i])
+		}
+	}
+}
+
+func (r *ErmcpDeliveryGoodsDetail) addGoodsList(lst []ErmcpRelatedGoods) {
+	for i := range lst {
+		if lst[i].DELIVERYGOODSID == r.Data.DELIVERYGOODSID {
+			r.GoodsList = append(r.GoodsList, lst[i])
+		}
+	}
+}
+
+// GetDataEx
+func (r *ErmcpDeliveryGoodsDetail) GetDataEx() (interface{}, error) {
+	sData := make([]ErmcpDeliveryGoodsDetail, 0)
+	m := ErmcpDeliveryGoods{AREAUSERID: r.Data.AREAUSERID, DELIVERYGOODSID: r.Data.DELIVERYGOODSID}
+	data, err := m.GetData()
+	if err != nil {
+		return sData, err
+	}
+	if data == nil || len(data) == 0 {
+		return sData, nil
+	}
+	// 基本信息
+	for i := range data {
+		val := ErmcpDeliveryGoodsDetail{Data: data[i],
+			GmList: make([]ErmcpWrstandard, 0), GbList: make([]ErmcpBrand, 0),
+			WrsList: make([]WRSConverTDetail, 0), GoodsList: make([]ErmcpRelatedGoods, 0),
+		}
+		sData = append(sData, val)
+	}
+	//品类/品牌/套保信息
+	gm := ErmcpWrstandard{AREAUSERID: int(r.Data.AREAUSERID), DELIVERYGOODSID: r.Data.DELIVERYGOODSID, ISVALID: 1}
+	gb := ErmcpBrand{DELIVERYGOODSID: r.Data.DELIVERYGOODSID}
+	WrsC := WRSConverTDetail{DELIVERYGOODSID: r.Data.DELIVERYGOODSID}
+	gmLst, _ := gm.GetData()
+	gbLst, _ := gb.GetData()
+	wrsLst, _ := WrsC.GetData()
+	var goodLst []ErmcpRelatedGoods
+	if r.QryTradeGoods == 1 {
+		goodsM := ErmcpRelatedGoods{AREAUSERID: r.Data.AREAUSERID, DELIVERYGOODSID: r.Data.DELIVERYGOODSID}
+		goodLst, _ = goodsM.GetData()
+	}
+
+	for i := range sData {
+		sData[i].addGmList(gmLst)
+		sData[i].addGbList(gbLst)
+		sData[i].addWrsList(wrsLst)
+		sData[i].addGoodsList(goodLst)
+	}
+
+	return sData, nil
+}
+
+// Ermcp3Contract 现货合同
+type Ermcp3Contract struct {
+	SPOTCONTRACTID    string  `json:"spotcontractid"  xorm:"'SPOTCONTRACTID'"`       // 现货合同ID(602+Unix秒时间戳(10位)+xxxxxx)
+	CONTRACTNO        string  `json:"contractno"  xorm:"'CONTRACTNO'"`               // 现货合同编号
+	CONTRACTTYPE      int32   `json:"contracttype"  xorm:"'CONTRACTTYPE'"`           // 现货合同类型 - 1:采购 -1:销售
+	USERID            int64   `json:"userid"  xorm:"'USERID'"`                       // 所属机构ID
+	BUYUSERID         int64   `json:"buyuserid"  xorm:"'BUYUSERID'"`                 // 采购方ID
+	BUYUSERName       string  `json:"buyusername"  xorm:"'BUYUSERName'"`             // 采购方名称
+	SELLUSERID        int64   `json:"selluserid"  xorm:"'SELLUSERID'"`               // 销售方ID
+	SELLUSERNAME      string  `json:"sellusername"  xorm:"'SELLUSERNAME'"`           // 销售方名称
+	DELIVERYGOODSID   int32   `json:"deliverygoodsid"  xorm:"'DELIVERYGOODSID'"`     // 现货品种ID
+	WRSTANDARDID      int32   `json:"wrstandardid"  xorm:"'wrstandardid'"`           // 品类ID
+	WRSTANDARDNAME    string  `json:"wrstandardname"  xorm:"'WRSTANDARDNAME'"`       // 品类名称
+	WRSTANDARDCODE    string  `json:"wrstandardcode"  xorm:"'WRSTANDARDCODE'"`       // 品类代码
+	DELIVERYGOODSCODE string  `json:"deliverygoodscode"  xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码
+	DELIVERYGOODSNAME string  `json:"deliverygoodsname"  xorm:"'DELIVERYGOODSNAME'"` // 现货品种名称
+	PRODUCTTYPE       int32   `json:"producttype"  xorm:"'PRODUCTTYPE'"`             // 产品类型 - 1:标准仓单 2:等标 3:非标
+	CONVERTFACTOR     float64 `json:"convertfactor"  xorm:"'CONVERTFACTOR'"`         // 标仓系数(品类)
+	SPOTGOODSDESC     string  `json:"spotgoodsdesc"  xorm:"'SPOTGOODSDESC'"`         // 商品型号
+	PRICETYPE         int32   `json:"pricetype"  xorm:"'PRICETYPE'"`                 // 定价类型 - 1:一口价 2:点价 3:暂定价
+	QTY               float64 `json:"qty"  xorm:"'QTY'"`                             // 数量
+	PRICE             float64 `json:"price"  xorm:"'PRICE'"`                         // 价格\暂定价 [1:一口价、3:暂定价]
+	AMOUNT            float64 `json:"amount"  xorm:"'AMOUNT'"`                       // 金额 [1:一口价、3:暂定价]
+	DELIVERYSTARTDATE string  `json:"deliverystartdate"  xorm:"'DELIVERYSTARTDATE'"` // 交收期(开始)
+	DELIVERYENDDATE   string  `json:"deliveryenddate"  xorm:"'DELIVERYENDDATE'"`     // 交收期(结束)
+	GOODSID           int32   `json:"goodsid"  xorm:"'GOODSID'"`                     // 点价合约ID - 0:为现货,其它为期货商品合约ID [2:点价 3:暂定价]
+	GOODSCODE         string  `json:"goodscode"  xorm:"'GOODSCODE'"`                 // 点价合约代码
+	GOODSNAME         string  `json:"goodsname"  xorm:"'GOODSNAME'"`                 // 点价商品名称
+	PRICEMOVE         float64 `json:"pricemove"  xorm:"'PRICEMOVE'"`                 // 升贴水 [2:点价 3:暂定价]
+	STARTDATE         string  `json:"startdate"  xorm:"'STARTDATE'"`                 // 点价开始日期 [2:点价 3:暂定价]
+	ENDDATE           string  `json:"enddate"  xorm:"'ENDDATE'"`                     // 点价结束日期 [2:点价 3:暂定价]
+	MARGIN            float64 `json:"margin"  xorm:"'MARGIN'"`                       // 当前保证金
+	CONTRACTMARGIN    float64 `json:"contractmargin"  xorm:"'CONTRACTMARGIN'"`       // 合同保证金
+	EnumdicName       string  `json:"enumdicname"  xorm:"'ENUMDICNAME'"`             // 单位名称
+	CONTRACCTSTATUS   int32   `json:"contracctstatus"  xorm:"'CONTRACTSTATUS'"`      // 合同状态 - 0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回
+	Remark            string  `json:"remark"  xorm:"'Remark'"`                       // 备注
+	AUDITREMARK       string  `json:"auditremark"  xorm:"'AUDITREMARK'"`             // 审核意见
+	AUDITTIME         string  `json:"audittime"  xorm:"'AUDITTIME'"`                 // 审核时间
+	CREATETIME        string  `json:"createtime"  xorm:"'CREATETIME'"`               // 创建时间
+	UPDATETIME        string  `json:"updatetime"  xorm:"'UPDATETIME'"`               // 更新时间
+	SPOTGOODSBRANDID  int32   `json:"spotgoodsbrandid"  xorm:"'SPOTGOODSBRANDID'"`   // 现货品牌ID(DGFactoryItem表的ID)
+	BRANDNAME         string  `json:"brandname"  xorm:"'brandname'"`                 // 品牌名称
+	ATTACHMENT        string  `json:"attachment"  xorm:"'ATTACHMENT'"`               // 附件
+	UNITID            int32   `json:"unitid"  xorm:"'UNITID'"`                       // 单位id(取品类上的单位id)
+
+	// 筛选条件
+	QryType   int32 `json:"-"` // 查询类型 1-未提交 2-待审核 3-履约中 4-已完成
+	UserType  int32 `json:"-"` // 用户类型  2-管理员 7-企业成员
+	OwnUserId int64 `json:"-"` // 登录用户id
+}
+
+func (r *Ermcp3Contract) getQryTypeStatus() string {
+	var status string
+	switch r.QryType {
+	case 1: // 未提交
+		status = "0,4,6"
+	case 2: // 待审核
+		status = "1"
+	case 3: // 履约中
+		status = "2"
+	case 4: // 已完成
+		status = "3,5"
+	}
+	return status
+}
+
+func (r *Ermcp3Contract) calc() {
+	r.BUYUSERName = mtpcache.GetUserNameByUserId(r.BUYUSERID)
+	r.SELLUSERNAME = mtpcache.GetUserNameByUserId(r.SELLUSERID)
+	r.EnumdicName = mtpcache.GetEnumDicitemName(r.UNITID)
+}
+
+func (r *Ermcp3Contract) buildSql() string {
+	var sqlId utils.SQLVal = "SELECT to_char(t.SPOTCONTRACTID) SPOTCONTRACTID," +
+		"       t.CONTRACTNO," +
+		"       t.CONTRACTTYPE," +
+		"       t.USERID," +
+		"       t.BUYUSERID," +
+		"       t.SELLUSERID," +
+		"       t.DELIVERYGOODSID," +
+		"       t.wrstandardid," +
+		"       t.PRODUCTTYPE," +
+		"       w.CONVERTFACTOR," +
+		"       t.SPOTGOODSDESC," +
+		"       t.PRICETYPE," +
+		"       t.QTY," +
+		"       t.PRICE," +
+		"       t.AMOUNT," +
+		"       to_char(t.DELIVERYSTARTDATE, 'yyyy-mm-dd hh24:mi:ss') DELIVERYSTARTDATE," +
+		"       to_char(t.DELIVERYENDDATE, 'yyyy-mm-dd hh24:mi:ss') DELIVERYENDDATE," +
+		"       t.GOODSID," +
+		"       t.PRICEMOVE," +
+		"       to_char(t.STARTDATE, 'yyyy-mm-dd hh24:mi:ss') STARTDATE," +
+		"       to_char(t.ENDDATE, 'yyyy-mm-dd hh24:mi:ss') ENDDATE," +
+		"       t.MARGIN," +
+		"       t.contractmargin," +
+		"       t.remark," +
+		"       t.auditremark," +
+		"       to_char(t.contractattachment) attachment," +
+		"       t.contractstatus," +
+		"       t.SPOTGOODSBRANDID," +
+		"       to_char(t.audittime, 'yyyy-mm-dd hh24:mi:ss') audittime," +
+		"       to_char(t.createtime, 'yyyy-mm-dd hh24:mi:ss') createtime," +
+		"       to_char(t.updatetime, 'yyyy-mm-dd hh24:mi:ss') updatetime," +
+		"       g.deliverygoodscode," +
+		"       g.deliverygoodsname," +
+		"       g2.goodscode," +
+		"       g2.goodsname," +
+		"       gb.dgfactoryitemvalue brandname," +
+		"       w.wrstandardname," +
+		"       w.wrstandardcode," +
+		"       w.unitid" +
+		"  FROM ERMCP_SPOTCONTRACT t" +
+		"  left join deliverygoods g" +
+		"    on t.deliverygoodsid = g.deliverygoodsid" +
+		"  left join goods g2" +
+		"    on t.goodsid = g2.goodsid" +
+		"  left join DGFACTORYITEM gb" +
+		"    on t.spotgoodsbrandid = gb.dgfactoryitemid" +
+		"  left join wrstandard w" +
+		"    on t.wrstandardid = w.wrstandardid" +
+		" where 1 = 1"
+	sqlId.AndEx("t.userid", r.USERID, r.USERID > 0)
+	sqlId.AndEx("t.SPOTCONTRACTID", r.SPOTCONTRACTID, len(r.SPOTCONTRACTID) > 0)
+	if r.UserType == 7 {
+		// 企业成员
+		sqlId.Join(fmt.Sprintf(" and %v in(t.saleuserid, t.tradeuserid, t.meruserid)", r.OwnUserId))
+	}
+	status := r.getQryTypeStatus()
+	if len(status) > 0 {
+		sqlId.Join(fmt.Sprintf(" and t.contractstatus in (%v)", status))
+	}
+
+	return sqlId.String()
+}
+
+// GetDataEx
+func (r *Ermcp3Contract) GetDataEx() (interface{}, error) {
+	sData := make([]Ermcp3Contract, 0)
+	err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
+	for i := range sData {
+		sData[i].calc()
+	}
+	return sData, err
+}
+
+// Ermcp3SellBuyContract 采购/销售合同
+type Ermcp3SellBuyContract struct {
+	UserID             int64   `json:"userid"  xorm:"'UserID'"`                         // 机构ID
+	SpotContractId     string  `json:"spotcontractid"  xorm:"'SPOTCONTRACTID'"`         // 合同ID
+	AccountName        string  `json:"accountname"  xorm:"'ACCOUNTNAME'"`               // 账户名称
+	DeliveryGoodsId    int     `json:"deliverygoodsid"  xorm:"'DELIVERYGOODSID'"`       // 现货商品ID
+	DeliveryGoodsCode  string  `json:"deliverygoodscode"  xorm:"'DELIVERYGOODSCODE'"`   // 现货品种代码
+	DeliveryGoodsName  string  `json:"deliverygoodsname"  xorm:"'DELIVERYGOODSNAME'"`   // 现货品种名称
+	SpotGoodsdesc      string  `json:"spotgoodsdesc"  xorm:"'SPOTGOODSDESC'"`           // 商品型号(商品规格)
+	GoodsId            int     `json:"goodsid"  xorm:"'GOODSID'"`                       // 点价商品ID
+	GOODSNAME          string  `json:"goodsname"  xorm:"'GOODSNAME'"`                   // 点价商品名称
+	Goodscode          string  `json:"goodscode"  xorm:"'GOODSCODE'"`                   // 点价商品代码
+	Pricemove          float64 `json:"pricemove"  xorm:"'PRICEMOVE'"`                   // 升贴水
+	Qty                float64 `json:"qty"  xorm:"'QTY'"`                               // 合同量
+	UnpricedQty        float64 `json:"unpricedqty"  xorm:"'UNPRICEDQTY'"`               // 未定价量
+	PricedQty          float64 `json:"pricedqty"  xorm:"'PRICEDQTY'"`                   // 已定价量
+	UnsureQty          float64 `json:"unsureqty"  xorm:"'UNSUREQTY'"`                   // 未确定量
+	PayAmount          float64 `json:"payamount"  xorm:"'PAYAMOUNT'"`                   // 已收付额(收款或付款)
+	UnpayAmount        float64 `json:"unpayamount"`                                     // 应收付款额(应支付或应收款)
+	PrePayAmount       float64 `json:"prepayamount"`                                    // 预收付额
+	InvoiceAmount      float64 `json:"invoiceamount"  xorm:"'INVOICEAMOUNT'"`           // 已开票额
+	DaikaiAmount       float64 `json:"daikaiamount"  xorm:"'DAIKAIAMOUNT'"`             // 应收(开)票额
+	PreInvoiceAmount   float64 `json:"preinvoiceamount"`                                // 预收(开)票额
+	StartDate          string  `json:"startdate"  xorm:"'STARTDATE'"`                   // 点价开始日
+	EndDate            string  `json:"enddate"  xorm:"'ENDDATE'"`                       // 点价结束日
+	DeliveryStartDate  string  `json:"deliverystartdate"  xorm:"'DELIVERYSTARTDATE'"`   // 交割开始日
+	DeliveryendDate    string  `json:"deliveryenddate"  xorm:"'DELIVERYENDDATE'"`       // 交割结束日
+	Convertfactor      float64 `json:"convertfactor"  xorm:"'CONVERTFACTOR'"`           // 标仓系数(品类)
+	EnumdicName        string  `json:"enumdicname"  xorm:"'ENUMDICNAME'"`               // 单位名称
+	Contracctstatus    uint    `json:"contracctstatus"  xorm:"'CONTRACTSTATUS'"`        // 合同状态- 0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回
+	PriceType          int     `json:"pricetype"  xorm:"'PRICETYPE'"`                   // 定价类型 - 1:一口价 2:点价 3:暂定价
+	ProductType        int     `json:"producttype"  xorm:"'PRODUCTTYPE'"`               // 产品类型 - 1:标准仓单 2:等标 3:非标
+	Contracttype       int32   `json:"contracttype"  xorm:"'CONTRACTTYPE'"`             // 合同类型 1-采购, -1-销售
+	Pricedamount       float64 `json:"pricedamount"  xorm:"'PRICEDAMOUNT'"`             // 已定价额
+	PricedAvg          float64 `json:"pricedavg"  xorm:"'PRICEDAVG'"`                   // 已点均价
+	Margin             float64 `json:"margin"  xorm:"'MARGIN'"`                         // 保证金
+	CONTRACTMARGIN     float64 `json:"contractmargin"  xorm:"'CONTRACTMARGIN'"`         // 合同保证金
+	Remark             string  `json:"remark"  xorm:"'Remark'"`                         // 备注
+	ATTACHMENT         string  `json:"attachment"  xorm:"'ATTACHMENT'"`                 // 附件
+	ReckonRealQty      float64 `json:"reckonrealqty"  xorm:"'ReckonRealQty'"`           // 已确定量
+	ReckonOtherAmount  float64 `json:"reckonotheramount"  xorm:"'ReckonOtherAmount'"`   // 其它费用
+	ReckonAdjustAmount float64 `json:"reckonadjustamount"  xorm:"'ReckonAdjustAmount'"` // 调整金额
+	Price              float64 `json:"price"  xorm:"'Price'"`                           // 价格
+	LoanAmount         float64 `json:"loanamount"  xorm:"'LoanAmount'"`                 // 贷款总额=已定价额+调整金额
+	Contractno         string  `json:"contractno"  xorm:"'Contractno'"`                 // 合同编号
+	TotalAmount        float64 `json:"totalamount"  xorm:"'-'"`                         // 合计总额
+	ReckonedAmount     float64 `json:"reckonedamount"  xorm:"'ReckonedAmount'"`         // 实际已收付额(已确定额,已收付总额-已退款总额)
+	BUYUSERID          int64   `json:"-"  xorm:"'BUYUSERID'"`                           // 采购方ID
+	SELLUSERID         int64   `json:"-"  xorm:"'SELLUSERID'"`                          // 销售方ID
+	AUDITTIME          string  `json:"audittime"  xorm:"'AUDITTIME'"`                   // 审核时间
+	CREATETIME         string  `json:"createtime"  xorm:"'CREATETIME'"`                 // 创建时间
+	SPOTGOODSBRANDID   int32   `json:"spotgoodsbrandid"  xorm:"'SPOTGOODSBRANDID'"`     // 现货品牌ID(DGFactoryItem表的ID)
+	BRANDNAME          string  `json:"brandname"  xorm:"'brandname'"`                   // 品牌名称
+	WRSTANDARDID       int64   `json:"wrstandardid"  xorm:"'WRSTANDARDID'"`             // 品类ID
+	WRSTANDARDNAME     string  `json:"wrstandardname"  xorm:"'WRSTANDARDNAME'"`         // 品类名称
+	WRSTANDARDCODE     string  `json:"wrstandardcode"  xorm:"'WRSTANDARDCODE'"`         // 品类代码
+
+	// 筛选条件
+	QryType   int32 `json:"-"` // 查询类型 1-未提交 2-待审核 3-履约中 4-已完成
+	UserType  int32 `json:"-"` // 用户类型  2-管理员 7-企业成员
+	OwnUserId int64 `json:"-"` // 登录用户id
+}
+
+func (r *Ermcp3SellBuyContract) calc() {
+	r.TotalAmount = r.LoanAmount + r.ReckonOtherAmount
+	r.UnpayAmount = r.TotalAmount - r.ReckonedAmount
+	r.PrePayAmount = r.ReckonedAmount - r.TotalAmount
+	r.PreInvoiceAmount = r.InvoiceAmount - r.TotalAmount
+	if r.Contracttype == 1 {
+		//采购合同, 取销售方名称
+		r.AccountName = mtpcache.GetUserNameByUserId(r.SELLUSERID)
+	} else {
+		//销售合同, 取采购方名称
+		r.AccountName = mtpcache.GetUserNameByUserId(r.BUYUSERID)
+	}
+}
+
+func (r *Ermcp3SellBuyContract) buildSql() string {
+	var sqlId utils.SQLVal = "select t.contractno," +
+		"       to_char(t.SpotContractId) SpotContractId," +
+		"       t.deliverygoodsid," +
+		"       t.spotgoodsdesc," +
+		"       t.goodsid," +
+		"       t.pricemove," +
+		"       t.userid," +
+		"       t.BUYUSERID," +
+		"       t.SELLUSERID," +
+		"       t.qty," +
+		"       t.qty - t.pricedqty unpricedqty," +
+		"       t.pricedqty," +
+		"       (case" +
+		"         when t.pricetype = 3 then" +
+		"          t.qty - t.RECKONREALQTY" +
+		"         else" +
+		"          t.pricedqty - t.ReckonRealQty" +
+		"       end) unsureqty," +
+		"       t.reckonedamount PayAmount," +
+		"       t.invoiceamount," +
+		"       (t.pricedamount + t.RECKONADJUSTAMOUNT + t.RECKONOTHERAMOUNT -" +
+		"       t.invoiceamount) as daikaiAmount," +
+		"       to_char(t.startdate, 'yyyy-mm-dd hh24:mi:ss') startdate," +
+		"       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," +
+		"       t.contractstatus," +
+		"       t.pricetype," +
+		"       t.producttype," +
+		"       t.contracttype," +
+		"       t.remark," +
+		"       to_char(t.contractattachment) attachment," +
+		"       t.margin," +
+		"       t.contractmargin," +
+		"       t.SPOTGOODSBRANDID," +
+		"       g.deliverygoodscode," +
+		"       g.deliverygoodsname," +
+		"       wr.wrstandardid," +
+		"       wr.wrstandardname," +
+		"       wr.wrstandardcode," +
+		"       g2.goodscode," +
+		"       g2.goodsname," +
+		"       e.enumdicname," +
+		"       t.contracttype," +
+		"       t.pricedamount," +
+		"       case" +
+		"         when t.pricedqty > 0 then" +
+		"          (t.pricedamount) / t.pricedqty" +
+		"         else" +
+		"          0" +
+		"       end pricedAvg," +
+		"       t.ReckonRealQty," +
+		"       t.ReckonOtherAmount," +
+		"       t.ReckonAdjustAmount," +
+		"       t.Price," +
+		"       t.ReckonedAmount," +
+		"       to_char(t.audittime, 'yyyy-mm-dd hh24:mi:ss') audittime," +
+		"       to_char(t.createtime, 'yyyy-mm-dd hh24:mi:ss') createtime," +
+		"       t.pricedamount + t.ReckonAdjustAmount as LoanAmount," +
+		"       gb.dgfactoryitemvalue BRANDNAME" +
+		"  from ermcp_spotcontract t" +
+		"  left join deliverygoods g" +
+		"    on t.deliverygoodsid = g.deliverygoodsid" +
+		"  left join goods g2" +
+		"    on t.goodsid = g2.goodsid" +
+		"  left join wrstandard wr" +
+		"    on t.wrstandardid = wr.wrstandardid" +
+		"  left join DGFactoryItem gb" +
+		"    on t.spotgoodsbrandid = gb.dgfactoryitemid" +
+		"  left join enumdicitem e" +
+		"    on wr.unitid = e.enumitemname" +
+		"   and e.enumdiccode = 'goodsunit'" +
+		" where 1 = 1"
+	sqlId.AndEx("t.userid", r.UserID, r.UserID > 0)
+	sqlId.AndEx("t.SpotContractId", r.SpotContractId, len(r.SpotContractId) > 0)
+	if r.UserType == 7 {
+		// 企业成员
+		sqlId.Join(fmt.Sprintf(" and %v in(t.saleuserid, t.tradeuserid, t.meruserid)", r.OwnUserId))
+	}
+	var tmp = Ermcp3Contract{QryType: r.QryType}
+	status := tmp.getQryTypeStatus()
+	if len(status) > 0 {
+		sqlId.Join(fmt.Sprintf(" and t.contractstatus in (%v)", status))
+	}
+	return sqlId.String()
+}
+
+// GetDataEx
+func (r *Ermcp3SellBuyContract) GetDataEx() (interface{}, error) {
+	sData := make([]Ermcp3SellBuyContract, 0)
+	err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
+	for i := range sData {
+		sData[i].calc()
+	}
+	return sData, err
+}

+ 22 - 22
models/ermcpAccMgr.go

@@ -20,7 +20,7 @@ type ErmcpLoginUserEx struct {
 	ROLENAME string           `json:"rolename"` // 角色名称
 	USERTYPE int32            `json:"usertype"` // 用户类型 2-机构 7-企业成员(云平台)
 	UserList []ErmcpLoginUser `json:"userlist"` // 用户列表
-	RoleId   int32            `json:"-"`        // 角色id
+	RoleId   int32            `json:"roleid"`   // 角色id
 }
 
 // ErmcpLoginUser 查询登录账户
@@ -36,6 +36,8 @@ type ErmcpLoginUser struct {
 	CLIENTROLEID int32  `json:"clientroleid"  xorm:"'CLIENTROLEID'"` // 角色id(usertype=2)
 	ROLENAME     string `json:"rolename"  xorm:"'ROLENAME'"`         // 角色名称
 	ROLESTATUS   int32  `json:"rolestatus"  xorm:"'ROLESTATUS'"`     // 角色状态 1-启用 2-停用
+	LOGINCODE    string `json:"logincode"  xorm:"'LOGINCODE'"`       // 登录代码
+	LOGINID      int64  `json:"loginid"  xorm:"'LOGINID'"`           // 登录id(LOGINID)
 }
 
 func (r *ErmcpLoginUser) calc() {
@@ -56,7 +58,7 @@ func (r *ErmcpLoginUser) buildSql() string {
 		"       l.logincode," +
 		"       l.loginid," +
 		"       l.clientroleid," +
-		"       'name(22,23,24)' rolename," +
+		"       '企业成员' rolename," +
 		"       l.loginstatus" +
 		"  from useraccount t" +
 		"  left join loginaccount l" +
@@ -414,13 +416,13 @@ func (r *ErmcpRoleMenu) GetDataEx() (interface{}, error) {
 
 // ErmcpBizGroupSpotGoods 业务类型分组商品表
 type ErmcpBizGroupSpotGoods struct {
-	BIZTYPE        int32  `json:"biztype"  xorm:"'BIZTYPE'"`               // 业务类型 1-套保 2-套利
-	BIZGROUPID     int64  `json:"bizgroupid"  xorm:"'BIZGROUPID'"`         // 分组id
-	WRSTANDARDID   int32  `json:"wrstandardid"  xorm:"'WRSTANDARDID'"`     // 现货商品id
-	WRSTANDARDCODE string `json:"wrstandardcode"  xorm:"'WRSTANDARDCODE'"` // 现货商品代码
-	WRSTANDARDNAME string `json:"wrstandardname"  xorm:"'WRSTANDARDNAME'"` // 现货商品名称
-	UNITID         int32  `json:"unitid"  xorm:"'UNITID'"`                 // 现货商品单位id
-	AREAUSERID     int64  `json:"areauserid"  xorm:"'AREAUSERID'"`         // 所属机构id
+	BIZTYPE           int32  `json:"biztype"  xorm:"'BIZTYPE'"`                     // 业务类型 1-套保 2-套利
+	BIZGROUPID        int64  `json:"bizgroupid"  xorm:"'BIZGROUPID'"`               // 分组id
+	DELIVERYGOODSID   int32  `json:"deliverygoodsid"  xorm:"'DELIVERYGOODSID'"`     // 现货商品id
+	DELIVERYGOODSCODE string `json:"deliverygoodscode"  xorm:"'DELIVERYGOODSCODE'"` // 现货商品代码
+	DELIVERYGOODSNAME string `json:"deliverygoodsname"  xorm:"'DELIVERYGOODSNAME'"` // 现货商品名称
+	GOODSUNITID       int32  `json:"unitid"  xorm:"'UNITID'"`                       // 现货商品单位id
+	AREAUSERID        int64  `json:"areauserid"  xorm:"'AREAUSERID'"`               // 所属机构id
 }
 
 func (r *ErmcpBizGroupSpotGoods) calc() {
@@ -429,18 +431,16 @@ func (r *ErmcpBizGroupSpotGoods) calc() {
 func (r *ErmcpBizGroupSpotGoods) buildSql() string {
 	var sqlId utils.SQLVal = "select t.biztype," +
 		"       t.bizgroupid," +
-		"       t.wrstandardid," +
-		"       w.wrstandardcode," +
-		"       w.wrstandardname," +
-		"       w.unitid," +
-		"       w.areauserid" +
-		"  from ermcp_bizgroupspotgoods t" +
-		"  left join wrstandard w" +
-		"    on t.wrstandardid = w.wrstandardid" +
-		" where 1 = 1"
-	if r.AREAUSERID > 0 {
-		sqlId.And("w.AREAUSERID", r.AREAUSERID)
-	}
+		"       t.deliverygoodsid," +
+		"       g.deliverygoodsname," +
+		"       g.deliverygoodscode," +
+		"       g.goodsunitid," +
+		"       g.areauserid" +
+		"  from ERMCP_BizGroupSpotGoods t" +
+		"  left join deliverygoods g" +
+		"    on t.deliverygoodsid = g.deliverygoodsid" +
+		"  where 1=1"
+	sqlId.AndEx("g.areauserid", r.AREAUSERID, r.AREAUSERID > 0)
 	return sqlId.String()
 }
 
@@ -498,7 +498,7 @@ type ErmcpBizGroupEx struct {
 	BIZGROUPID int64 `json:"bizgroupid"  xorm:"'BIZGROUPID'"` // 业务分组id
 
 	AccList []ErmcpBizGroupTaAccount `json:"acclist"` // 账号列表
-	WrList  []ErmcpBizGroupSpotGoods `json:"wrlist"`  // 现货商品表
+	WrList  []ErmcpBizGroupSpotGoods `json:"wrlist"`  // 现货商品表
 
 	AREAUSERID int64 `json:"-"` // 所属机构
 }

+ 34 - 26
models/ermcpOPApply.go

@@ -16,32 +16,35 @@ import (
 
 // ErmcpOPApplyModel 现货合同操作数据
 type ErmcpOPApplyModel struct {
-	USERID           int64   `json:"userid"  xorm:"'USERID'"`                     // 用户ID
-	OPERATEAPPLYID   string  `json:"operateapplyid"  xorm:"'OPERATEAPPLYID'"`     // 操作申请ID(603+Unix秒时间戳(10位)+xxxxxx)
-	OPERATEAPPLYTYPE int32   `json:"operateapplytype"  xorm:"'OPERATEAPPLYTYPE'"` // 操作申请类型 - 1:点价 2:结算登记 3:款项登记 4:发票登记
-	RELATEDID        string  `json:"relatedid"  xorm:"'RELATEDID'"`               // 现货合同ID
-	DETAILJSON       string  `json:"-"  xorm:"'DETAILJSON'"`                      // 明细JSON
-	APPLYID          string  `json:"applyid"  xorm:"'APPLYID'"`                   // 申请人
-	APPLYTIME        string  `json:"applytime"  xorm:"'APPLYTIME'"`               // 申请时间
-	APPLYSTATUS      int32   `json:"applystatus"  xorm:"'APPLYSTATUS'"`           // 申请状态 - 1:待审核 2:审核通过 3:审核拒绝 4:处理失败 5:已撤回
-	AUDITTIME        string  `json:"audittime"  xorm:"'AUDITTIME'"`               // 审核时间
-	CONTRACTTYPE     int32   `json:"contracttype"  xorm:"'CONTRACTTYPE'"`         // 现货合同类型 - 1:采购 -1:销售
-	CONTRACTNO       string  `json:"contractno"  xorm:"'CONTRACTNO'"`             // 合同编号
-	PRICETYPE        int32   `json:"pricetype"  xorm:"'PRICETYPE'"`               // 定价类型 - 1:一口价 2:点价 3:暂定价
-	PRICEMOVE        float64 `json:"pricemove"  xorm:"'PRICEMOVE'"`               // 升贴水
-	GOODSNAME        string  `json:"goodsname"  xorm:"'GOODSNAME'"`               // 商品名称
-	GOODSCODE        string  `json:"goodscode"  xorm:"'GOODSCODE'"`               // 点价合约
-	EnumdicName      string  `json:"enumdicname"  xorm:"'ENUMDICNAME'"`           // 单位名称
-	BUYUSERNAME      string  `json:"buyusername"  xorm:"'BUYUSERNAME'"`           // 采购方名称
-	SELLUSERNAME     string  `json:"sellusername"  xorm:"'SELLUSERNAME'"`         // 销售方名字
-	AUDITID          string  `json:"auditid"  xorm:"'AUDITID'"`                   // 审核人ID
-	APPLYNAME        string  `json:"applyname"  xorm:"'APPLYNAME'"`               // 申请人名称
-	AUDITNAME        string  `json:"auditname"  xorm:"'AUDITNAME'"`               // 审核人名称
-	CONTRACTSTATUS   int32   `json:"contractstatus"  xorm:"'CONTRACTSTATUS'"`     // 合同状态- 0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回
-	ATTACHURL        string  `json:"attachurl"  xorm:"'ATTACHURL'"`               // 附件
-	WRSTANDARDNAME   string  `json:"wrstandardname"  xorm:"'WRSTANDARDNAME'"`     // 现货商品名称
-	WRSTANDARDCODE   string  `json:"wrstandardcode"  xorm:"'WRSTANDARDCODE'"`     // 现货商品代码
-	WRSTANDARDID     int     `json:"wrstandardid"  xorm:"'WRSTANDARDID'"`         // 现货商品id
+	USERID            int64   `json:"userid"  xorm:"'USERID'"`                       // 用户ID
+	OPERATEAPPLYID    string  `json:"operateapplyid"  xorm:"'OPERATEAPPLYID'"`       // 操作申请ID(603+Unix秒时间戳(10位)+xxxxxx)
+	OPERATEAPPLYTYPE  int32   `json:"operateapplytype"  xorm:"'OPERATEAPPLYTYPE'"`   // 操作申请类型 - 1:点价 2:结算登记 3:款项登记 4:发票登记
+	RELATEDID         string  `json:"relatedid"  xorm:"'RELATEDID'"`                 // 现货合同ID
+	DETAILJSON        string  `json:"-"  xorm:"'DETAILJSON'"`                        // 明细JSON
+	APPLYID           string  `json:"applyid"  xorm:"'APPLYID'"`                     // 申请人
+	APPLYTIME         string  `json:"applytime"  xorm:"'APPLYTIME'"`                 // 申请时间
+	APPLYSTATUS       int32   `json:"applystatus"  xorm:"'APPLYSTATUS'"`             // 申请状态 - 1:待审核 2:审核通过 3:审核拒绝 4:处理失败 5:已撤回
+	AUDITTIME         string  `json:"audittime"  xorm:"'AUDITTIME'"`                 // 审核时间
+	CONTRACTTYPE      int32   `json:"contracttype"  xorm:"'CONTRACTTYPE'"`           // 现货合同类型 - 1:采购 -1:销售
+	CONTRACTNO        string  `json:"contractno"  xorm:"'CONTRACTNO'"`               // 合同编号
+	PRICETYPE         int32   `json:"pricetype"  xorm:"'PRICETYPE'"`                 // 定价类型 - 1:一口价 2:点价 3:暂定价
+	PRICEMOVE         float64 `json:"pricemove"  xorm:"'PRICEMOVE'"`                 // 升贴水
+	GOODSNAME         string  `json:"goodsname"  xorm:"'GOODSNAME'"`                 // 商品名称
+	GOODSCODE         string  `json:"goodscode"  xorm:"'GOODSCODE'"`                 // 点价合约
+	EnumdicName       string  `json:"enumdicname"  xorm:"'ENUMDICNAME'"`             // 单位名称
+	BUYUSERNAME       string  `json:"buyusername"  xorm:"'BUYUSERNAME'"`             // 采购方名称
+	SELLUSERNAME      string  `json:"sellusername"  xorm:"'SELLUSERNAME'"`           // 销售方名字
+	AUDITID           string  `json:"auditid"  xorm:"'AUDITID'"`                     // 审核人ID
+	APPLYNAME         string  `json:"applyname"  xorm:"'APPLYNAME'"`                 // 申请人名称
+	AUDITNAME         string  `json:"auditname"  xorm:"'AUDITNAME'"`                 // 审核人名称
+	CONTRACTSTATUS    int32   `json:"contractstatus"  xorm:"'CONTRACTSTATUS'"`       // 合同状态- 0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回
+	ATTACHURL         string  `json:"attachurl"  xorm:"'ATTACHURL'"`                 // 附件
+	WRSTANDARDNAME    string  `json:"wrstandardname"  xorm:"'WRSTANDARDNAME'"`       // 品类名称
+	WRSTANDARDCODE    string  `json:"wrstandardcode"  xorm:"'WRSTANDARDCODE'"`       // 品类代码
+	WRSTANDARDID      int     `json:"wrstandardid"  xorm:"'WRSTANDARDID'"`           // 品类id
+	DELIVERYGOODSID   int     `json:"deliverygoodsid"  xorm:"'DELIVERYGOODSID'"`     // 现货商品ID
+	DELIVERYGOODSCODE string  `json:"deliverygoodscode"  xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码
+	DELIVERYGOODSNAME string  `json:"deliverygoodsname"  xorm:"'DELIVERYGOODSNAME'"` // 现货品种名称
 
 	FilterAppStatus string `json:"-"` // 状态过滤条件
 }
@@ -78,6 +81,9 @@ func (r *ErmcpOPApplyModel) buildSql(opType int32) string {
 		"       s.pricemove," +
 		"       s.userid," +
 		"       s.contractstatus," +
+		"       dg.deliverygoodsid," +
+		"       dg.deliverygoodscode," +
+		"       dg.deliverygoodsname," +
 		"       w.wrstandardname," +
 		"       w.wrstandardcode," +
 		"       w.wrstandardid," +
@@ -103,6 +109,8 @@ func (r *ErmcpOPApplyModel) buildSql(opType int32) string {
 		"    on s.buyuserid = u1.userid" +
 		"  left join useraccount u2" +
 		"    on s.selluserid = u2.userid" +
+		"  left join deliverygoods dg" +
+		"    on t.deliverygoodsid = dg.deliverygoodsid" +
 		"  left join enumdicitem e" +
 		"    on e.enumitemname = w.unitid" +
 		"   and e.enumdiccode = 'goodsunit'" +

+ 20 - 12
models/ermcpWrstandard.go

@@ -165,16 +165,17 @@ func (r *GoodsBrand) GetData() ([]GoodsBrand, error) {
 
 // WRSConverTDetail 现货商品折算配置明细表
 type WRSConverTDetail struct {
-	WRSTANDARDID    int64   `json:"wrstandardid"  xorm:"'WRSTANDARDID'"`       // 现货商品ID
-	DELIVERYGOODSID int32   `json:"deliverygoodsid"  xorm:"'DELIVERYGOODSID'"` // 现货品种ID
-	MIDDLEGOODSID   int64   `json:"middlegoodsid"  xorm:"'MIDDLEGOODSID'"`     // 套保品种ID
-	CONVERTRATIO    float64 `json:"convertratio"  xorm:"'CONVERTRATIO'"`       // 套保系数
-	MODIFYTIME      string  `json:"modifytime"  xorm:"'MODIFYTIME'"`           // 修改时间
-	MIDDLEGOODSNAME string  `json:"middlegoodsname"  xorm:"'middlegoodsname'"` // 套保品种名称
-	MIDDLEGOODSCODE string  `json:"middlegoodscode"  xorm:"'middlegoodscode'"` // 套保品种代码
-	GOODSUNITID     int32   `json:"goodsunitid"  xorm:"'GOODSUNITID'"`         // 套保品种单位id
-
-	ENUMDICNAME string `json:"enumdicname"` // 单位名称
+	WRSTANDARDID      int64   `json:"wrstandardid"  xorm:"'WRSTANDARDID'"`           // 品类ID
+	DELIVERYGOODSID   int32   `json:"deliverygoodsid"  xorm:"'DELIVERYGOODSID'"`     // 现货品种ID
+	MIDDLEGOODSID     int64   `json:"middlegoodsid"  xorm:"'MIDDLEGOODSID'"`         // 套保品种ID
+	CONVERTRATIO      float64 `json:"convertratio"  xorm:"'CONVERTRATIO'"`           // 套保系数
+	MODIFYTIME        string  `json:"modifytime"  xorm:"'MODIFYTIME'"`               // 修改时间
+	MIDDLEGOODSNAME   string  `json:"middlegoodsname"  xorm:"'middlegoodsname'"`     // 套保品种名称
+	MIDDLEGOODSCODE   string  `json:"middlegoodscode"  xorm:"'middlegoodscode'"`     // 套保品种代码
+	GOODSUNITID       int32   `json:"goodsunitid"  xorm:"'GOODSUNITID'"`             // 套保品种单位id
+	DELIVERYGOODSCODE string  `json:"deliverygoodscode"  xorm:"'DELIVERYGOODSCODE'"` // 现货商品代码
+	DELIVERYGOODSNAME string  `json:"deliverygoodsname"  xorm:"'DELIVERYGOODSNAME'"` // 现货商品名称
+	ENUMDICNAME       string  `json:"enumdicname"`                                   // 单位名称
 }
 
 func (r *WRSConverTDetail) calc() {
@@ -189,14 +190,21 @@ func (r *WRSConverTDetail) buildSql() string {
 		"       to_char(t.MODIFYTIME, 'yyyy-mm-dd hh24:mi:ss') MODIFYTIME," +
 		"       m.middlegoodsname," +
 		"       m.middlegoodscode," +
-		"       m.goodsunitid" +
+		"       m.goodsunitid," +
+		"       g.deliverygoodscode," +
+		"       g.deliverygoodsname" +
 		"  from Erms2_Wrsconvertdetail t" +
 		"  left join erms_middlegoods m" +
 		"    on t.middlegoodsid = m.middlegoodsid" +
-		"    where 1=1"
+		"  left join deliverygoods g" +
+		"    on t.deliverygoodsid = g.deliverygoodsid" +
+		" where 1 = 1"
 	if r.WRSTANDARDID > 0 {
 		sqlId = sqlId + fmt.Sprintf(" and t.wrstandardid=%v", r.WRSTANDARDID)
 	}
+	if r.DELIVERYGOODSID > 0 {
+		sqlId += fmt.Sprintf(" and t.DELIVERYGOODSID=%v", r.DELIVERYGOODSID)
+	}
 	return sqlId
 }
 

+ 21 - 0
models/wrTrade.go

@@ -172,6 +172,27 @@ func (Warehouseinfo) TableName() string {
 	return "WAREHOUSEINFO"
 }
 
+// Wrcategory 现货分类表
+type Wrcategory struct {
+	Categoryid       int32     `json:"categoryid"  xorm:"'CATEGORYID'" binding:"required"` // 类别ID(SEQ_WRCATEGORY)
+	Categoryname     string    `json:"categoryname"  xorm:"'CATEGORYNAME'"`                // 类别名称
+	Parentcategoryid int32     `json:"parentcategoryid"  xorm:"'PARENTCATEGORYID'"`        // 父类别ID
+	Categorydesc     string    `json:"categorydesc"  xorm:"'CATEGORYDESC'"`                // 类别描述
+	Isvalid          int32     `json:"isvalid"  xorm:"'ISVALID'"`                          // 是否有效 - 0:无效 1:有效
+	Iconurl          string    `json:"iconurl"  xorm:"'ICONURL'"`                          // 图标地址
+	Creatorid        int64     `json:"creatorid"  xorm:"'CREATORID'"`                      // 创建人
+	Createtime       time.Time `json:"createtime"  xorm:"'CREATETIME'"`                    // 创建时间
+	Updatorid        int64     `json:"updatorid"  xorm:"'UPDATORID'"`                      // 更新人
+	Updatetime       time.Time `json:"updatetime"  xorm:"'UPDATETIME'"`                    // 更新时间
+	Orderindex       int32     `json:"orderindex"  xorm:"'ORDERINDEX'"`                    // 顺序
+	Areauserid       int64     `json:"areauserid"  xorm:"'AREAUSERID'"`                    // 所属机构
+}
+
+// TableName is WRCATEGORY
+func (Wrcategory) TableName() string {
+	return "WRCATEGORY"
+}
+
 // WRStandardInfo 仓库信息
 type WRStandardInfo struct {
 	Wrstandard `xorm:"extends"`

+ 11 - 8
routers/router.go

@@ -7,6 +7,7 @@ import (
 	"mtp2_if/controllers/cptrade"
 	"mtp2_if/controllers/delivery"
 	"mtp2_if/controllers/ermcp"
+	"mtp2_if/controllers/ermcp3"
 	"mtp2_if/controllers/erms2"
 	"mtp2_if/controllers/erms3"
 	"mtp2_if/controllers/hsby"
@@ -18,7 +19,6 @@ import (
 	"mtp2_if/controllers/taaccount"
 	"mtp2_if/controllers/trade"
 	"mtp2_if/controllers/user"
-	"mtp2_if/controllers/wr"
 	"mtp2_if/controllers/wrtrade"
 	"mtp2_if/logger"
 	"mtp2_if/token"
@@ -198,13 +198,6 @@ func InitRouter() *gin.Engine {
 		// 查询产能预售委托单信息
 		cpTradeR.GET("/QueryCPTradeOrderDetail", cptrade.QueryCPTradeOrderDetail)
 	}
-	// ************************ 仓单服务 ************************
-	wrR := apiR.Group("WR")
-	wrR.Use()
-	{
-		// 获取现货分类信息
-		wrR.GET("/GetWRCategoryInfo", wr.GetWRCategoryInfo)
-	}
 	// ************************ 交割服务 ************************
 	deliveryR := apiR.Group("Delivery")
 	deliveryR.Use(token.Auth())
@@ -407,6 +400,16 @@ func InitRouter() *gin.Engine {
 		ermcpR.GET("/GetErmcpRoleFuncMenuLists", ermcp.GetErmcpRoleFuncMenuLists)
 	}
 
+	// ***************************** 企业风险管理v3(app)***************************
+	ermcp3R := apiR.Group("Ermcp3")
+	ermcp3R.Use(token.Auth())
+	{
+		ermcp3R.GET("/QueryDeliveryGoods", ermcp3.QueryDeliveryGoods)
+		ermcp3R.GET("/QueryDeliveryGoodsDetail", ermcp3.QueryDeliveryGoodsDetail)
+		ermcp3R.GET("/QuerySpotContract", ermcp3.QuerySpotContract)
+		ermcp3R.GET("/QuerySpotContractBS", ermcp3.QuerySpotContractBS)
+	}
+
 	return r
 }
 

+ 9 - 0
utils/sqlUtils.go

@@ -27,6 +27,15 @@ func (r *SQLVal) And(fieldName string, val interface{}) {
 	*r = *r + SQLVal(fmt.Sprintf(" and %v = %v", fieldName, val))
 }
 
+// And 增加and 条件, bAdd参数省了在外层写if语句
+// 例如:  sqlId.AndEx("t.areauserid", r.areauserid, r.areauserid > 0)
+// 如果没有bAdd参数,外层就得写if r.areauserid > 0 {...}
+func (r *SQLVal) AndEx(fieldName string, val interface{}, bAdd bool) {
+	if bAdd {
+		*r = *r + SQLVal(fmt.Sprintf(" and %v = %v", fieldName, val))
+	}
+}
+
 // Bigger 大于
 func (r *SQLVal) Bigger(fieldName string, val interface{}) {
 	*r = *r + SQLVal(fmt.Sprintf(" and %v > %v", fieldName, val))

Vissa filer visades inte eftersom för många filer har ändrats