erms3.go 10.0 KB

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