erms3.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // Package models 211.3 风险管理系统2020_现货合同
  2. package models
  3. import (
  4. "mtp2_if/db"
  5. "time"
  6. )
  7. // Erms3Spotcontractdetail 合同标的明细表
  8. type Erms3Spotcontractdetail struct {
  9. Spotdetailid string `json:"spotdetailid" xorm:"SPOTDETAILID"` // 标的明细ID(346+Unix秒时间戳(10位)+xxxxxx)
  10. Spotcontractid string `json:"spotcontractid" xorm:"SPOTCONTRACTID"` // 现货合同ID
  11. Wrstandardid int64 `json:"wrstandardid" xorm:"WRSTANDARDID"` // 仓单标准ID
  12. Deliverygoodsid int64 `json:"deliverygoodsid" xorm:"DELIVERYGOODSID"` // 现货品种ID
  13. Tradedate string `json:"tradedate" xorm:"TRADEDATE"` // 交易日(yyyyMMdd)
  14. Contracttype int32 `json:"contracttype" xorm:"CONTRACTTYPE"` // 现货合同类型 - 1:采购 -1:销售
  15. Accountid int64 `json:"accountid" xorm:"ACCOUNTID"` // 资金账户ID
  16. Customeraccountid int64 `json:"customeraccountid" xorm:"CUSTOMERACCOUNTID"` // 客户资金账户ID
  17. Producttype int32 `json:"producttype" xorm:"PRODUCTTYPE"` // 产品类型 - 1:标准仓单 2:等标 3:非标
  18. Deliverygoodsdesc string `json:"deliverygoodsdesc" xorm:"DELIVERYGOODSDESC"` // 产品规格 - 根据此字段生成仓单标准、仓单要素类型
  19. Warehouseid int64 `json:"warehouseid" xorm:"WAREHOUSEID"` // 仓库ID
  20. Pointdesc string `json:"pointdesc" xorm:"POINTDESC"` // 点价描述
  21. Priceqty float64 `json:"priceqty" xorm:"PRICEQTY"` // 指定价类总量
  22. Pointqty float64 `json:"pointqty" xorm:"POINTQTY"` // 点价类总量
  23. Unpricedqty float64 `json:"unpricedqty" xorm:"UNPRICEDQTY"` // 未确定量
  24. Unpricedrelatedqty float64 `json:"unpricedrelatedqty" xorm:"UNPRICEDRELATEDQTY"` // 未确定量关联量
  25. Unpricedavaliableqty float64 `json:"unpricedavaliableqty" xorm:"UNPRICEDAVALIABLEQTY"` // 未确定量可关联量
  26. Unpricedcancelledqty float64 `json:"unpricedcancelledqty" xorm:"UNPRICEDCANCELLEDQTY"` // 未确定量撤销量(非业务)
  27. Pricedqty float64 `json:"pricedqty" xorm:"PRICEDQTY"` // 确定量
  28. Pricedamount float64 `json:"pricedamount" xorm:"PRICEDAMOUNT"` // 确定金额
  29. Pricedrelatedqty float64 `json:"pricedrelatedqty" xorm:"PRICEDRELATEDQTY"` // 确定量关联量
  30. Pricedavaliableqty float64 `json:"pricedavaliableqty" xorm:"PRICEDAVALIABLEQTY"` // 确定量可关联量
  31. Pricedcancelledqty float64 `json:"pricedcancelledqty" xorm:"PRICEDCANCELLEDQTY"` // 确定量撤销量(非业务)
  32. Pricedcancelledamount float64 `json:"pricedcancelledamount" xorm:"PRICEDCANCELLEDAMOUNT"` // 确定量撤销金额(非业务)
  33. Deliveryqty float64 `json:"deliveryqty" xorm:"DELIVERYQTY"` // 交收数量(非业务)
  34. Deliveryamount float64 `json:"deliveryamount" xorm:"DELIVERYAMOUNT"` // 交收金额(非业务)
  35. Deliveryovershortqty float64 `json:"deliveryovershortqty" xorm:"DELIVERYOVERSHORTQTY"` // 交收溢短数量(非业务)
  36. Deliveryactualamount float64 `json:"deliveryactualamount" xorm:"DELIVERYACTUALAMOUNT"` // 交收实际金额(非业务)
  37. Deliveryotheramount float64 `json:"deliveryotheramount" xorm:"DELIVERYOTHERAMOUNT"` // 交收其它费用(非业务)
  38. Curdeliveryqty float64 `json:"curdeliveryqty" xorm:"CURDELIVERYQTY"` // 剩余交收数量
  39. Curdeliveryamount float64 `json:"curdeliveryamount" xorm:"CURDELIVERYAMOUNT"` // 剩余交收金额
  40. Remark string `json:"remark" xorm:"REMARK"` // 备注
  41. Marketid int64 `json:"marketid" xorm:"MARKETID"` // 市场ID
  42. Handlestatus int32 `json:"handlestatus" xorm:"HANDLESTATUS"` // 处理状态
  43. Updatetime time.Time `json:"updatetime" xorm:"UPDATETIME"` // 更新时间
  44. Reckonedamount float64 `json:"reckonedamount" xorm:"RECKONEDAMOUNT"` // 已结金额
  45. Invoicedamount float64 `json:"invoicedamount" xorm:"INVOICEDAMOUNT"` // 已开票金额
  46. }
  47. // TableName is ERMS3_SPOTCONTRACTDETAIL
  48. func (Erms3Spotcontractdetail) TableName() string {
  49. return "ERMS3_SPOTCONTRACTDETAIL"
  50. }
  51. // Erms3SpotContractInfo 合同明细.
  52. type Erms3SpotContractInfo struct {
  53. Erms3Spotcontractdetail `xorm:"extends"`
  54. Areauserid int64 `json:"areauserid" xorm:"AREAUSERID"` // 所属机构
  55. Accountid int64 `json:"accountid" xorm:"ACCOUNTID"` // 资金账户ID
  56. Customeruserid int64 `json:"customeruserid" xorm:"CUSTOMERUSERID"` // 客户ID
  57. Customeraccountid int64 `json:"customeraccountid" xorm:"CUSTOMERACCOUNTID"` // 客户资金账户ID
  58. Signdate time.Time `json:"signdate" xorm:"SIGNDATE"` // 签订日期
  59. Closestatus int32 `json:"closestatus" xorm:"CLOSESTATUS"` // 完结状态 - 0:未完结 1:已完结
  60. Relatedbizid string `json:"relatedbizid" xorm:"RELATEDBIZID"` // 关联业务ID
  61. Goodunit string `json:"goodunit" xorm:"'GOODUNIT'"` // 报价单位
  62. Wrstandardcode string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 仓单标准代码
  63. Wrstandardname string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 仓单标准名称
  64. Deliverygoodscode string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 交割商品代码
  65. Deliverygoodsname string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 交割商品名称
  66. }
  67. // Erms3SpotContractApply 现货合同申请表
  68. type Erms3SpotContractApply struct {
  69. SpotContractID int64 `json:"spotcontractid" xorm:"'SPOTCONTRACTID'" binging:"required"` // 现货合同ID(345+Unix秒时间戳(10位)+xxxxxx)
  70. TradeDate string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd)
  71. ContractNo string `json:"contractno" xorm:"'CONTRACTNO'"` // 现货合同编号
  72. ContractType int32 `json:"contracttype" xorm:"'CONTRACTTYPE'"` // 现货合同类型 - 1:采购 -1:销售
  73. AreaUserID int32 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构
  74. AccountID int64 `json:"accountid" xorm:"'ACCOUNTID'"` // 资金账户ID
  75. CustomerUserID int32 `json:"customeruserid" xorm:"'CUSTOMERUSERID'"` // 客户ID
  76. CustomerAccountID int64 `json:"customeraccountid" xorm:"'CUSTOMERACCOUNTID'"` // 客户资金账户ID
  77. SignDate time.Time `json:"signdate" xorm:"'SIGNDATE'"` // 签订日期
  78. LastDate time.Time `json:"lastdate" xorm:"'LASTDATE'"` // 交货时间
  79. ContractAttachment string `json:"contractattachment" xorm:"'CONTRACTATTACHMENT'"` // 合同附件
  80. OriMarginPayer int32 `json:"orimarginpayer" xorm:"'ORIMARGINPAYER'"` // 初始保证金支付方 -1:买方 2:卖方
  81. OriMargin float64 `json:"orimargin" xorm:"'ORIMARGIN'"` // 初始保证金
  82. Remark string `json:"remark" xorm:"'REMARK'"` // 备注
  83. DetailJSON string `json:"detailjson" xorm:"'DETAILJSON'"` // 明细JSON
  84. ApplyStatus int32 `json:"applystatus" xorm:"'APPLYSTATUS'"` // 申请状态 - 0:未审核 1:审核通过 2:审核中 3:审核失败 4已撤销 5:审核拒绝
  85. ApplySrc int32 `json:"applysrc" xorm:"'APPLYSRC'"` // 申请来源 - 1:管理端 2:终端
  86. MarketID int32 `json:"marketid" xorm:"'MARKETID'"` // 市场ID
  87. CreatorID int32 `json:"creatorid" xorm:"'CREATORID'"` // 申请人
  88. CreateTime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 申请时间
  89. AuditID int32 `json:"auditid" xorm:"'AUDITID'"` // 审核人
  90. AuditTime time.Time `json:"audittime" xorm:"'AUDITTIME'"` // 审核时间
  91. AuditRemark string `json:"auditremark" xorm:"'AUDITREMARK'"` // 审核备注
  92. }
  93. // TableName is ERMS3_SPOTCONTRACTAPPLY
  94. func (Erms3SpotContractApply) TableName() string {
  95. return "ERMS3_SPOTCONTRACTAPPLY"
  96. }
  97. // AddSpotContractApply 插入现货合同记录
  98. func AddSpotContractApply(spotContractApply Erms3SpotContractApply) error {
  99. engine := db.GetEngine()
  100. // 组织sql,插入现货合同申请信息
  101. sql := `INSERT INTO ERMS3_SPOTCONTRACTAPPLY(SPOTCONTRACTID,
  102. TRADEDATE,
  103. CONTRACTNO,
  104. CONTRACTTYPE,
  105. AREAUSERID,
  106. ACCOUNTID,
  107. CUSTOMERUSERID,
  108. CUSTOMERACCOUNTID,
  109. SIGNDATE,
  110. LASTDATE,
  111. CONTRACTATTACHMENT,
  112. ORIMARGINPAYER,
  113. ORIMARGIN,
  114. REMARK,
  115. DETAILJSON,
  116. APPLYSTATUS,
  117. APPLYSRC,
  118. MARKETID,
  119. CREATORID,
  120. CREATETIME)
  121. VALUES(?,
  122. ?,
  123. ?,
  124. ?,
  125. ?,
  126. ?,
  127. ?,
  128. ?,
  129. to_date(?, 'YYYY-MM-DD HH24:MI:SS'),
  130. to_date(?, 'YYYY-MM-DD HH24:MI:SS'),
  131. ?,
  132. ?,
  133. ?,
  134. ?,
  135. ?,
  136. ?,
  137. ?,
  138. ?,
  139. ?,
  140. sysdate)`
  141. _, err := engine.Exec(sql,
  142. spotContractApply.SpotContractID,
  143. spotContractApply.TradeDate,
  144. spotContractApply.ContractNo,
  145. spotContractApply.ContractType,
  146. spotContractApply.AreaUserID,
  147. spotContractApply.AccountID,
  148. spotContractApply.CustomerUserID,
  149. spotContractApply.CustomerAccountID,
  150. spotContractApply.SignDate,
  151. spotContractApply.LastDate,
  152. spotContractApply.ContractAttachment,
  153. spotContractApply.OriMarginPayer,
  154. spotContractApply.OriMargin,
  155. spotContractApply.Remark,
  156. spotContractApply.DetailJSON,
  157. spotContractApply.ApplyStatus,
  158. spotContractApply.ApplySrc,
  159. spotContractApply.MarketID,
  160. spotContractApply.CreatorID)
  161. return err
  162. }
  163. func QueryErms3SpotContractInfo(accountids []int64, contracttype, contractmode, status int32) ([]Erms3SpotContractInfo, error) {
  164. datas := make([]Erms3SpotContractInfo, 0)
  165. engine := db.GetEngine()
  166. s := engine.Table("ERMS3_SPOTCONTRACTDETAIL").
  167. Join("LEFT", "ERMS3_SPOTCONTRACT", "ERMS3_SPOTCONTRACTDETAIL.SPOTCONTRACTID = ERMS3_SPOTCONTRACT.SPOTCONTRACTID").
  168. Join("LEFT", "ERMS3_BIZTRADEDETAIL", "ERMS3_BIZTRADEDETAIL.SPOTDETAILID = ERMS3_SPOTCONTRACTDETAIL.SPOTDETAILID").
  169. Join("LEFT", "WRSTANDARD", "WRSTANDARD.WRSTANDARDID = ERMS3_SPOTCONTRACTDETAIL.WRSTANDARDID").
  170. Join("LEFT", "DELIVERYGOODS", "DELIVERYGOODS.DELIVERYGOODSID = WRSTANDARD.DELIVERYGOODSID").
  171. Join("LEFT", "ENUMDICITEM", "WRSTANDARD.UNITID = ENUMDICITEM.ENUMITEMNAME AND ENUMDICITEM.ENUMDICCODE = 'goodsunit'").
  172. Select(`to_char(ERMS3_SPOTCONTRACTDETAIL.SPOTCONTRACTID) SPOTCONTRACTID, ERMS3_SPOTCONTRACT.AREAUSERID, ERMS3_SPOTCONTRACT.ACCOUNTID, ERMS3_SPOTCONTRACT.CUSTOMERUSERID,
  173. ERMS3_SPOTCONTRACT.CUSTOMERACCOUNTID, ERMS3_SPOTCONTRACT.CLOSESTATUS, ERMS3_SPOTCONTRACT.SIGNDATE, ERMS3_SPOTCONTRACTDETAIL.*, WRSTANDARD.WRSTANDARDNAME, WRSTANDARD.WRSTANDARDCODE, DELIVERYGOODS.DELIVERYGOODSNAME, DELIVERYGOODS.DELIVERYGOODSCODE,
  174. to_char(ERMS3_BIZTRADEDETAIL.RELATEDBIZID) RELATEDBIZID, ENUMDICITEM.ENUMDICNAME GOODUNIT`).
  175. Where("ERMS3_SPOTCONTRACT.CONTRACTTYPE = ? AND ERMS3_SPOTCONTRACT.CONTRACTMODE = ? AND ERMS3_SPOTCONTRACT.CLOSESTATUS = ?", contracttype, contractmode, status).
  176. In("ERMS3_SPOTCONTRACT.ACCOUNTID", accountids).
  177. Desc("ERMS3_SPOTCONTRACTDETAIL.SPOTCONTRACTID")
  178. err := s.Find(&datas)
  179. return datas, err
  180. }