erms2.go 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. // Package models 211.2风险管理系统2020_期现套利
  2. package models
  3. import (
  4. "fmt"
  5. "mtp2_if/db"
  6. "time"
  7. )
  8. // Erms2astradedetails 期现套利期货成交单关联表
  9. type Erms2astradedetails struct {
  10. Asapplyid int64 `json:"asapplyid" xorm:"'ASAPPLYID'" binding:"required"` // 策略申请ID
  11. Outtradeid int64 `json:"outtradeid" xorm:"'OUTTRADEID'" binding:"required"` // 外部成交单ID(114+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
  12. Biztype int64 `json:"biztype" xorm:"'BIZTYPE'"` // 策略业务类型 - 1:正向套利 2:反向套利
  13. Detailtype int64 `json:"detailtype" xorm:"'DETAILTYPE'"` // 明细类型 - 1:套利对冲 2:期货换月 3:期货仓位调整
  14. Spotcontractid int64 `json:"spotcontractid" xorm:"'SPOTCONTRACTID'"` // 现货合同ID [1:套利对冲 为合同ID,2:期货换月\3:期货仓位调整时为0]
  15. Contracttype int64 `json:"contracttype" xorm:"'CONTRACTTYPE'"` // 现货合同类型 - 1:采购合同 -1:销售合同
  16. Hedgegoodsid int64 `json:"hedgegoodsid" xorm:"'HEDGEGOODSID'"` // 对冲合约ID
  17. Buyorsell int64 `json:"buyorsell" xorm:"'BUYORSELL'"` // 买卖方向 - 0:买 1:卖 [成交单方向]
  18. Buildtype int64 `json:"buildtype" xorm:"'BUILDTYPE'"` // 开平标志- 0:无 1:开仓 2:平仓 [根据成交单方向及策略业务类型确定]正向套利 成交单:卖 开 成交单:买 平反向套利 成交单:买 开 成交单:卖 平
  19. Goodsgroupid int64 `json:"goodsgroupid" xorm:"'GOODSGROUPID'"` // 对冲品种ID[期货合约商品组ID]
  20. Tradedate string `json:"tradedate" xorm:"'TRADEDATE'"` // 成交交易日(yyyyMMdd)
  21. Tradeprice float64 `json:"tradeprice" xorm:"'TRADEPRICE'"` // 成交价
  22. Tradelot float64 `json:"tradelot" xorm:"'TRADELOT'"` // 成交手数
  23. Agreeunit float64 `json:"agreeunit" xorm:"'AGREEUNIT'"` // 合约单位
  24. Tradeamount float64 `json:"tradeamount" xorm:"'TRADEAMOUNT'"` // 成交金额 = 成交价*成交手数*合约单位
  25. Tradecharge float64 `json:"tradecharge" xorm:"'TRADECHARGE'"` // 交易手续费
  26. Basisflag int64 `json:"basisflag" xorm:"'BASISFLAG'"` // 是否计入基差损益 - 0:不计入 1:计入 [明细类型:1\2为1,3:期货仓位调整是为0]
  27. Remark string `json:"remark" xorm:"'REMARK'"` // 备注
  28. Updatetime time.Time `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间
  29. }
  30. // TableName is ERMS2_ASTRADEDETAILS
  31. func (Erms2astradedetails) TableName() string {
  32. return "ERMS2_ASTRADEDETAILS"
  33. }
  34. // Erms2Wrrcontract 仓单回购业务表
  35. type Erms2Wrrcontract struct {
  36. Wrrcontractid string `json:"wrrcontractid" xorm:"WRRCONTRACTID"` // 回购业务ID(343+Unix秒时间戳(10位)+xxxxxx)
  37. Wrrcontractno string `json:"wrrcontractno" xorm:"WRRCONTRACTNO"` // 回购业务编号
  38. Wrrcontractname string `json:"wrrcontractname" xorm:"WRRCONTRACTNAME"` // 回购名称
  39. Areauserid int64 `json:"areauserid" xorm:"AREAUSERID"` // 所属机构
  40. Deliverygoodsid int64 `json:"deliverygoodsid" xorm:"DELIVERYGOODSID"` // 现货品种ID
  41. Wrstandardid int64 `json:"wrstandardid" xorm:"WRSTANDARDID"` // 仓单标准ID
  42. Wrfactortypeid int64 `json:"wrfactortypeid" xorm:"WRFACTORTYPEID"` // 仓单要素类型ID
  43. Accountid int64 `json:"accountid" xorm:"ACCOUNTID"` // 现货账户
  44. Contractqtychar string `json:"contractqtychar" xorm:"CONTRACTQTYCHAR"` // 合同数量(显示)
  45. Contractqty float64 `json:"contractqty" xorm:"CONTRACTQTY"` // 合同数量
  46. Contractprice float64 `json:"contractprice" xorm:"CONTRACTPRICE"` // 合同价格
  47. Contractamount float64 `json:"contractamount" xorm:"CONTRACTAMOUNT"` // 合同金额
  48. Interestratemode int32 `json:"interestratemode" xorm:"INTERESTRATEMODE"` // 利率方式 - 1:年利率 2:日利率
  49. Interestrate float64 `json:"interestrate" xorm:"INTERESTRATE"` // 利率
  50. Interestmindays int64 `json:"interestmindays" xorm:"INTERESTMINDAYS"` // 最小计息天数
  51. Contractinterest float64 `json:"contractinterest" xorm:"CONTRACTINTEREST"` // 合同利息
  52. Orimargin float64 `json:"orimargin" xorm:"ORIMARGIN"` // 初始保证金
  53. Marginrate float64 `json:"marginrate" xorm:"MARGINRATE"` // 保证金率
  54. Begindate time.Time `json:"begindate" xorm:"BEGINDATE"` // 开始日期
  55. Enddate time.Time `json:"enddate" xorm:"ENDDATE"` // 结束日期
  56. Warningline float64 `json:"warningline" xorm:"WARNINGLINE"` // 预警线
  57. Closeline float64 `json:"closeline" xorm:"CLOSELINE"` // 强平线
  58. Customeruserid int64 `json:"customeruserid" xorm:"CUSTOMERUSERID"` // 回购客户ID
  59. Customeraccountid int64 `json:"customeraccountid" xorm:"CUSTOMERACCOUNTID"` // 客户资金账户ID
  60. Curqty float64 `json:"curqty" xorm:"CURQTY"` // 当前数量
  61. Curamount float64 `json:"curamount" xorm:"CURAMOUNT"` // 当前金额
  62. Curinterest float64 `json:"curinterest" xorm:"CURINTEREST"` // 当前利息
  63. Curmargin float64 `json:"curmargin" xorm:"CURMARGIN"` // 当前保证金
  64. Addedmargin float64 `json:"addedmargin" xorm:"ADDEDMARGIN"` // 已追加保证金
  65. Curenddate time.Time `json:"curenddate" xorm:"CURENDDATE"` // 最新结束日期(默认为结束日期)
  66. Remark string `json:"remark" xorm:"REMARK"` // 备注
  67. Marketid int64 `json:"marketid" xorm:"MARKETID"` // 市场ID
  68. Tradedate string `json:"tradedate" xorm:"TRADEDATE"` // 交易日(yyyyMMdd)
  69. Updatetime time.Time `json:"updatetime" xorm:"UPDATETIME"` // 更新时间
  70. Relatedspotcontractid int64 `json:"relatedspotcontractid" xorm:"RELATEDSPOTCONTRACTID"` // 关联销售合同ID
  71. Handlestatus int32 `json:"handlestatus" xorm:"HANDLESTATUS"` // 处理状态
  72. Contractstatus int32 `json:"contractstatus" xorm:"CONTRACTSTATUS"` // 合同状态 - 0:未结束 1:已结束
  73. Closetradedate string `json:"closetradedate" xorm:"CLOSETRADEDATE"` // 完结交易日(yyyyMMdd)
  74. }
  75. // TableName is ERMS2_WRRCONTRACT
  76. func (Erms2Wrrcontract) TableName() string {
  77. return "ERMS2_WRRCONTRACT"
  78. }
  79. // Erms2WrrcontractInfo 仓单回购业务详细信息.
  80. type Erms2WrrcontractInfo struct {
  81. Wrrcontractid string `json:"wrrcontractid" xorm:"WRRCONTRACTID"` // 回购业务ID(343+Unix秒时间戳(10位)+xxxxxx)
  82. Deliverygoodsid int64 `json:"deliverygoodsid" xorm:"DELIVERYGOODSID"` // 现货品种ID
  83. Contractqty float64 `json:"contractqty" xorm:"CONTRACTQTY"` // 合同数量
  84. Contractstatus int32 `json:"contractstatus" xorm:"CONTRACTSTATUS"` // 合同状态 - 0:未结束 1:已结束
  85. Buyqty float64 `json:"buyqty" xorm:"BUYQTY"` // 采购量.
  86. Buyamount float64 `json:"buyamount" xorm:"BUYAMOUNT"` // 采购额.
  87. Sellqty float64 `json:"sellqty" xorm:"SELLQTY"` // 销售量.
  88. Sellamount float64 `json:"sellamount" xorm:"SELLAMOUNT"` // 销售额.
  89. }
  90. // Erms2Spottradebiz 现货贸易业务表
  91. type Erms2Spottradebiz struct {
  92. Spottradeid string `json:"spottradeid" xorm:"SPOTTRADEID"` // 业务ID(341+Unix秒时间戳(10位)+xxxxxx)
  93. Spottradeno string `json:"spottradeno" xorm:"SPOTTRADENO"` // 业务编号
  94. Spottradename string `json:"spottradename" xorm:"SPOTTRADENAME"` // 业务名称
  95. Areauserid int64 `json:"areauserid" xorm:"AREAUSERID"` // 所属机构
  96. Deliverygoodsid int64 `json:"deliverygoodsid" xorm:"DELIVERYGOODSID"` // 现货品种ID
  97. Wrstandardid int64 `json:"wrstandardid" xorm:"WRSTANDARDID"` // 仓单标准ID
  98. Goodsgroupid int64 `json:"goodsgroupid" xorm:"GOODSGROUPID"` // 期货品种
  99. Spotaccountid int64 `json:"spotaccountid" xorm:"SPOTACCOUNTID"` // 现货资金账户
  100. Futureaccountid int64 `json:"futureaccountid" xorm:"FUTUREACCOUNTID"` // 期货资金账户
  101. Remark string `json:"remark" xorm:"REMARK"` // 备注
  102. Marketid int64 `json:"marketid" xorm:"MARKETID"` // 市场ID
  103. Tradedate string `json:"tradedate" xorm:"TRADEDATE"` // 交易日(yyyyMMdd)
  104. Buyqty float64 `json:"buyqty" xorm:"BUYQTY"` // 采购总量
  105. Buyamount float64 `json:"buyamount" xorm:"BUYAMOUNT"` // 采购总金额
  106. Buydeliveryqty float64 `json:"buydeliveryqty" xorm:"BUYDELIVERYQTY"` // 采购已交收数量
  107. Buydeliveryamount float64 `json:"buydeliveryamount" xorm:"BUYDELIVERYAMOUNT"` // 采购已交收金额
  108. Sellqty float64 `json:"sellqty" xorm:"SELLQTY"` // 销售总量
  109. Sellamount float64 `json:"sellamount" xorm:"SELLAMOUNT"` // 销售总金额
  110. Selldeliveryqty float64 `json:"selldeliveryqty" xorm:"SELLDELIVERYQTY"` // 销售已交收数量
  111. Selldeliveryamount float64 `json:"selldeliveryamount" xorm:"SELLDELIVERYAMOUNT"` // 销售已交收金额
  112. Futurelot float64 `json:"futurelot" xorm:"FUTURELOT"` // 期货手数
  113. Closestatus int32 `json:"closestatus" xorm:"CLOSESTATUS"` // 完结状态 - 0:未完结 1:已完结
  114. Closetradedate string `json:"closetradedate" xorm:"CLOSETRADEDATE"` // 完结交易日(yyyyMMdd)
  115. }
  116. // TableName is ERMS2_SPOTTRADEBIZ
  117. func (Erms2Spottradebiz) TableName() string {
  118. return "ERMS2_SPOTTRADEBIZ"
  119. }
  120. // Erms2SpottradebizInfo 现货贸易详细信息.
  121. type Erms2SpottradebizInfo struct {
  122. Spottradeid string `json:"spottradeid" xorm:"SPOTTRADEID"` // 业务ID(341+Unix秒时间戳(10位)+xxxxxx)
  123. Deliverygoodsid int64 `json:"deliverygoodsid" xorm:"DELIVERYGOODSID"` // 现货品种ID
  124. Buyqty float64 `json:"buyqty" xorm:"BUYQTY"` // 采购总量
  125. Sellqty float64 `json:"sellqty" xorm:"SELLQTY"` // 销售总量
  126. Closestatus int32 `json:"closestatus" xorm:"CLOSESTATUS"` // 完结状态 - 0:未完结 1:已完结
  127. TradeBuyqty float64 `json:"tradebuyqty" xorm:"TRADEBUYQTY"` // 采购量.
  128. TradeBuyamount float64 `json:"tradebuyamount" xorm:"TRADEBUYAMOUNT"` // 采购额.
  129. TradeSellqty float64 `json:"tradesellqty" xorm:"TRADESELLQTY"` // 销售量.
  130. TradeSellamount float64 `json:"tradesellamount" xorm:"TRADESELLAMOUNT"` // 销售额.
  131. }
  132. // Erms2Arbitragestrategy 期现套利业务表
  133. type Erms2Arbitragestrategy struct {
  134. Asapplyid string `json:"asapplyid" xorm:"ASAPPLYID"` // 策略申请ID(342+Unix秒时间戳(10位)+xxxxxx)
  135. Asno string `json:"asno" xorm:"ASNO"` // 策略编号
  136. Asname string `json:"asname" xorm:"ASNAME"` // 策略名称
  137. Biztype int32 `json:"biztype" xorm:"BIZTYPE"` // 业务类型 - 1:正向套利 -1:反向套利
  138. Userid int64 `json:"userid" xorm:"USERID"` // 所属机构
  139. Deliverygoodsid int64 `json:"deliverygoodsid" xorm:"DELIVERYGOODSID"` // 现货品种ID
  140. Goodsgroupid int64 `json:"goodsgroupid" xorm:"GOODSGROUPID"` // 期货品种ID
  141. Spotquota float64 `json:"spotquota" xorm:"SPOTQUOTA"` // 现货额度
  142. Futurequote float64 `json:"futurequote" xorm:"FUTUREQUOTE"` // 期货额度
  143. Applybasis float64 `json:"applybasis" xorm:"APPLYBASIS"` // 申请基差
  144. Strategystatus int32 `json:"strategystatus" xorm:"STRATEGYSTATUS"` // 策略状态 - 0:未结束 1:已结束
  145. Remark string `json:"remark" xorm:"REMARK"` // 备注
  146. Marketid int64 `json:"marketid" xorm:"MARKETID"` // 市场ID
  147. Tradedate string `json:"tradedate" xorm:"TRADEDATE"` // 交易日(yyyyMMdd)
  148. Closetradedate string `json:"closetradedate" xorm:"CLOSETRADEDATE"` // 完结交易日(yyyyMMdd)
  149. Usedquota float64 `json:"usedquota" xorm:"USEDQUOTA"` // 期货已占用资金[结算更新]
  150. Futureqty float64 `json:"futureqty" xorm:"FUTUREQTY"` // 期货持仓数量
  151. Futureavgprice float64 `json:"futureavgprice" xorm:"FUTUREAVGPRICE"` // 期货建仓均价
  152. Futurepl float64 `json:"futurepl" xorm:"FUTUREPL"` // 期货总盈亏[结算更新]
  153. Pricedspotqty float64 `json:"pricedspotqty" xorm:"PRICEDSPOTQTY"` // 已定价现货数量
  154. Pricedspotqtynotax float64 `json:"pricedspotqtynotax" xorm:"PRICEDSPOTQTYNOTAX"` // 已定价现货不含税数量
  155. Spotavgprice float64 `json:"spotavgprice" xorm:"SPOTAVGPRICE"` // 现货均价
  156. Spotpl float64 `json:"spotpl" xorm:"SPOTPL"` // 现货总盈亏[结算更新]
  157. Netexposure float64 `json:"netexposure" xorm:"NETEXPOSURE"` // 单笔业务头寸净敞口 = 期货持仓数量 + 已定价现货不含税数量
  158. Netexposurerate float64 `json:"netexposurerate" xorm:"NETEXPOSURERATE"` // 净敞口比例 - 0:未结束 = (NetExposure/PriceSpotQtyNoTax) ; 已结束为0
  159. Totalpl float64 `json:"totalpl" xorm:"TOTALPL"` // 业务合计损益 = FuturePL + SpotPL [结算更新]
  160. Openbasis float64 `json:"openbasis" xorm:"OPENBASIS"` // 建仓基差
  161. Curbasis float64 `json:"curbasis" xorm:"CURBASIS"` // 当前基差[结算更新]
  162. Basischangepl float64 `json:"basischangepl" xorm:"BASISCHANGEPL"` // 基差变动损益[结算更新]
  163. Netexposurepl float64 `json:"netexposurepl" xorm:"NETEXPOSUREPL"` // 净敞口损益 = TotalPL - BasisChangePL[结算更新]
  164. Spotusedquota float64 `json:"spotusedquota" xorm:"SPOTUSEDQUOTA"` // 现货占用资金
  165. Futureopenqty float64 `json:"futureopenqty" xorm:"FUTUREOPENQTY"` // 期货开仓数量
  166. Futureopenamount float64 `json:"futureopenamount" xorm:"FUTUREOPENAMOUNT"` // 期货开仓金额
  167. Futurecloseqty float64 `json:"futurecloseqty" xorm:"FUTURECLOSEQTY"` // 期货平仓数量
  168. Futurecloseamount float64 `json:"futurecloseamount" xorm:"FUTURECLOSEAMOUNT"` // 期货平仓金额
  169. Spotbuyamount float64 `json:"spotbuyamount" xorm:"SPOTBUYAMOUNT"` // 现货采购金额
  170. Spotbuyqty float64 `json:"spotbuyqty" xorm:"SPOTBUYQTY"` // 现货采购数量
  171. Spotsellamount float64 `json:"spotsellamount" xorm:"SPOTSELLAMOUNT"` // 现货销售金额
  172. Spotsellqty float64 `json:"spotsellqty" xorm:"SPOTSELLQTY"` // 现货销售数量
  173. Updatetime time.Time `json:"updatetime" xorm:"UPDATETIME"` // 更新时间
  174. }
  175. // TableName is ERMS2_ARBITRAGESTRATEGY
  176. func (Erms2Arbitragestrategy) TableName() string {
  177. return "ERMS2_ARBITRAGESTRATEGY"
  178. }
  179. // 期现套利详细信息.
  180. type Erms2AribitrageInfo struct {
  181. Asapplyid string `json:"asapplyid" xorm:"ASAPPLYID"` // 策略申请ID(342+Unix秒时间戳(10位)+xxxxxx)
  182. Deliverygoodsid int64 `json:"deliverygoodsid" xorm:"DELIVERYGOODSID"` // 现货品种ID
  183. Pricedspotqty float64 `json:"pricedspotqty" xorm:"PRICEDSPOTQTY"` // 已定价现货数量
  184. Futureqty float64 `json:"futureqty" xorm:"FUTUREQTY"` // 期货持仓数量
  185. Strategystatus int32 `json:"strategystatus" xorm:"STRATEGYSTATUS"` // 策略状态 - 0:未结束 1:已结束
  186. Buyqty float64 `json:"buyqty" xorm:"BUYQTY"` // 采购量.
  187. Buyamount float64 `json:"buyamount" xorm:"BUYAMOUNT"` // 采购额.
  188. Sellqty float64 `json:"sellqty" xorm:"SELLQTY"` // 销售量.
  189. Sellamount float64 `json:"sellamount" xorm:"SELLAMOUNT"` // 销售额.
  190. }
  191. // Erms2spotcontract 现货合同表
  192. type Erms2spotcontract struct {
  193. Spotcontractid int64 `json:"spotcontractid" xorm:"'SPOTCONTRACTID'" binding:"required"` // 现货合同ID(701+Unix秒时间戳(10位)+xxxxxx)
  194. Tradedate string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd)
  195. Contractno string `json:"contractno" xorm:"'CONTRACTNO'"` // 现货合同编号
  196. Contracttype int64 `json:"contracttype" xorm:"'CONTRACTTYPE'"` // 现货合同类型 - 1:采购合同 -1:销售合同
  197. Areauserid int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构
  198. Userid int64 `json:"userid" xorm:"'USERID'"` // 业务员用户ID
  199. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'"` // 资金账户ID
  200. Customeruserid int64 `json:"customeruserid" xorm:"'CUSTOMERUSERID'"` // 客户ID
  201. Customeraccountid int64 `json:"customeraccountid" xorm:"'CUSTOMERACCOUNTID'"` // 客户资金账户ID
  202. Signdate time.Time `json:"signdate" xorm:"'SIGNDATE'"` // 签订日期
  203. Lastdate time.Time `json:"lastdate" xorm:"'LASTDATE'"` // 交货时间
  204. Contractattachment string `json:"contractattachment" xorm:"'CONTRACTATTACHMENT'"` // 合同附件
  205. Producttype int64 `json:"producttype" xorm:"'PRODUCTTYPE'"` // 产品类型 - 1:标准仓单 2:等标 3:非标
  206. Deliverygoodsid int64 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种ID
  207. Deliverygoodsdesc string `json:"deliverygoodsdesc" xorm:"'DELIVERYGOODSDESC'"` // 品种说明
  208. Warehouseid int64 `json:"warehouseid" xorm:"'WAREHOUSEID'"` // 仓库ID
  209. Wrfactortypeid int64 `json:"wrfactortypeid" xorm:"'WRFACTORTYPEID'"` // 仓单要素类型ID
  210. Contractqtychar string `json:"contractqtychar" xorm:"'CONTRACTQTYCHAR'"` // 合同数量\已订价数量 (用于显示)
  211. Spotprice float64 `json:"spotprice" xorm:"'SPOTPRICE'"` // 价格
  212. Contractamount float64 `json:"contractamount" xorm:"'CONTRACTAMOUNT'"` // 合同金额
  213. Marketid int64 `json:"marketid" xorm:"'MARKETID'"` // 市场ID
  214. Remark string `json:"remark" xorm:"'REMARK'"` // 备注
  215. Handlestatus int64 `json:"handlestatus" xorm:"'HANDLESTATUS'"` // 处理状态
  216. Contractqty float64 `json:"contractqty" xorm:"'CONTRACTQTY'"` // 合同数量(数值) (用于计算)
  217. Positionqty int64 `json:"positionqty" xorm:"'POSITIONQTY'"` // 头寸数量 - 合同数量去小数部分
  218. Paystatus int64 `json:"paystatus" xorm:"'PAYSTATUS'"` // 收付款状态 - 0:未支付 1:已收款 2:已付款
  219. Payremark string `json:"payremark" xorm:"'PAYREMARK'"` // 收付款备注
  220. Paydatetime time.Time `json:"paydatetime" xorm:"'PAYDATETIME'"` // 收付款更新时间
  221. Invoicestatus int64 `json:"invoicestatus" xorm:"'INVOICESTATUS'"` // 开收票状态 - 0:未开票 1:已开票
  222. Invoiceremark string `json:"invoiceremark" xorm:"'INVOICEREMARK'"` // 发票备注
  223. Invoiceatt string `json:"invoiceatt" xorm:"'INVOICEATT'"` // 发票附件
  224. Invoicedatetime time.Time `json:"invoicedatetime" xorm:"'INVOICEDATETIME'"` // 开收票更新时间
  225. Spotstatus int64 `json:"spotstatus" xorm:"'SPOTSTATUS'"` // 收发货状态 - 0:未交收 1:已发货 2:已发货
  226. Spotremark string `json:"spotremark" xorm:"'SPOTREMARK'"` // 收发货备注
  227. Spotdatetime time.Time `json:"spotdatetime" xorm:"'SPOTDATETIME'"` // 收发货更新时间
  228. Relatedqty float64 `json:"relatedqty" xorm:"'RELATEDQTY'"` // 已关联数量
  229. Contractstatus int64 `json:"contractstatus" xorm:"'CONTRACTSTATUS'"` // 合同状态 - 0:未结束 1:已结束
  230. Closeremark string `json:"closeremark" xorm:"'CLOSEREMARK'"` // 结束备注
  231. Closetradedate string `json:"closetradedate" xorm:"'CLOSETRADEDATE'"` // 完结交易日(yyyyMMdd)
  232. Relatedstatus int64 `json:"relatedstatus" xorm:"'RELATEDSTATUS'"` // 关联完结状态 - 0:未结束 1:已结束
  233. Wrstandardid int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 仓单标准ID(SEQ_WRSTANDARD)
  234. Invoiceopentime time.Time `json:"invoiceopentime" xorm:"'INVOICEOPENTIME'"` // 开票时间
  235. Closetype int64 `json:"closetype" xorm:"'CLOSETYPE'"` // 终止类型 - 1:违约 2:提前终止
  236. Closedate time.Time `json:"closedate" xorm:"'CLOSEDATE'"` // 终止日期
  237. }
  238. // TableName is ERMS2_SPOTCONTRACT
  239. func (Erms2spotcontract) TableName() string {
  240. return "ERMS2_SPOTCONTRACT"
  241. }
  242. // Erms2asaccount 期现套利资金账户表
  243. type Erms2asaccount struct {
  244. Asapplyid int64 `json:"asapplyid" xorm:"'ASAPPLYID'" binding:"required"` // 策略申请ID(702+Unix秒时间戳(10位)+xxxxxx)
  245. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'" binding:"required"` // 资金账户
  246. Taaccounttype int64 `json:"taaccounttype" xorm:"'TAACCOUNTTYPE'"` // 账户类型 - 1:外部账号 2:内部账号 3:内部做市自营账号 4:内部做市接单账号
  247. Taaccountbiztype int64 `json:"taaccountbiztype" xorm:"'TAACCOUNTBIZTYPE'"` // 账户业务类型 - 1:现货 2:期货
  248. }
  249. // TableName is ERMS2_ASACCOUNT
  250. func (Erms2asaccount) TableName() string {
  251. return "ERMS2_ASACCOUNT"
  252. }
  253. // Erms2asspotdetail 期现套利现货明细表 - 导历史
  254. type Erms2asspotdetail struct {
  255. Asapplyid int64 `json:"asapplyid" xorm:"'ASAPPLYID'" binding:"required"` // 策略申请ID
  256. Spotcontractid int64 `json:"spotcontractid" xorm:"'SPOTCONTRACTID'" binding:"required"` // 现货合同ID
  257. Contracttype int64 `json:"contracttype" xorm:"'CONTRACTTYPE'"` // 现货合同类型 - 1:采购合同 -1:销售合同
  258. Pricedspotqty float64 `json:"pricedspotqty" xorm:"'PRICEDSPOTQTY'"` // 已定价数量(合同数量 * 合同类型)
  259. Pricedspotqtynotax float64 `json:"pricedspotqtynotax" xorm:"'PRICEDSPOTQTYNOTAX'"` // 已定价不含税数量( 已定价数量 /(1+对冲税率))
  260. Vatrate float64 `json:"vatrate" xorm:"'VATRATE'"` // 税率
  261. Spotprice float64 `json:"spotprice" xorm:"'SPOTPRICE'"` // 价格
  262. Spotamount float64 `json:"spotamount" xorm:"'SPOTAMOUNT'"` // 收付款资金(合同金额 * 合同类型)
  263. Detailstatus int64 `json:"detailstatus" xorm:"'DETAILSTATUS'"` // 明细状态 - 0:未结束 1:已结束
  264. Futureqty float64 `json:"futureqty" xorm:"'FUTUREQTY'"` // 期货已对冲数量
  265. Futureamount float64 `json:"futureamount" xorm:"'FUTUREAMOUNT'"` // 期货成交金额
  266. Closetradedate string `json:"closetradedate" xorm:"'CLOSETRADEDATE'"` // 完结交易日(yyyyMMdd)
  267. Remark string `json:"remark" xorm:"'REMARK'"` // 备注
  268. Updatetime time.Time `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间
  269. }
  270. // TableName is ERMS2_ASSPOTDETAIL
  271. func (Erms2asspotdetail) TableName() string {
  272. return "ERMS2_ASSPOTDETAIL"
  273. }
  274. // QueryASAccountInfoByAccountID 根据资金账号ID查询.
  275. func QueryASAccountInfoByAccountID(accountids []int64) ([]Erms2asaccount, error) {
  276. engine := db.GetEngine()
  277. data := make([]Erms2asaccount, 0)
  278. err := engine.In("ACCOUNTID", accountids).Find(&data)
  279. return data, err
  280. }
  281. // QueryASApplyIDSByAccountID 根据资金账号ID查询业务ID集合.
  282. func QueryASApplyIDSByAccountID(accountids []int64) ([]int64, error) {
  283. data, err := QueryASAccountInfoByAccountID(accountids)
  284. if err != nil {
  285. return nil, err
  286. }
  287. distinctID := make(map[int64]struct{})
  288. applyids := make([]int64, 0, len(data))
  289. for i := range data {
  290. if _, ok := distinctID[data[i].Asapplyid]; ok {
  291. continue
  292. }
  293. applyids = append(applyids, data[i].Asapplyid)
  294. distinctID[data[i].Asapplyid] = struct{}{}
  295. }
  296. return applyids, nil
  297. }
  298. // buildSQL 构建sql.
  299. func (asa Erms2Arbitragestrategy) buildSQL(accountids string, status int32) string {
  300. statement := `select to_char(asa.asapplyid) asapplyid,
  301. asa.deliverygoodsid, asa.pricedspotqty, asa.futureqty, asa.strategystatus,
  302. d.buyqty,
  303. d.buyamount,
  304. d.sellqty,
  305. d.sellamount
  306. from erms2_arbitragestrategy asa
  307. left join (select bt.relatedbizid,
  308. sum(case bt.contracttype
  309. when 1 then
  310. bt.relatedqty - bt.cancelledqty
  311. else
  312. 0
  313. end) buyqty,
  314. sum(case bt.contracttype
  315. when 1 then
  316. bt.relatedamount - bt.cancelledamount
  317. else
  318. 0
  319. end) buyamount,
  320. sum(case bt.contracttype
  321. when -1 then
  322. bt.relatedqty - bt.cancelledqty
  323. else
  324. 0
  325. end) sellqty,
  326. sum(case bt.contracttype
  327. when -1 then
  328. bt.relatedamount - bt.cancelledamount
  329. else
  330. 0
  331. end) sellamount
  332. from erms3_biztradedetail bt
  333. left join erms2_asaccount ea
  334. on bt.relatedbizid = ea.asapplyid
  335. where ea.accountid in (%v)
  336. group by bt.relatedbizid) d
  337. on asa.asapplyid = d.relatedbizid
  338. where asa.strategystatus = %v`
  339. return fmt.Sprintf(statement, accountids, status)
  340. }
  341. // GetByAccountIDSAndStatus 根据账号和状态获取期现套利详细信息.
  342. func (asa Erms2Arbitragestrategy) GetByAccountIDSAndStatus(accountids string, status int32) ([]Erms2AribitrageInfo, error) {
  343. engine := db.GetEngine()
  344. data := make([]Erms2AribitrageInfo, 0)
  345. err := engine.SQL(asa.buildSQL(accountids, status)).Find(&data)
  346. return data, err
  347. }
  348. func (Erms2Wrrcontract) buildSQL(accountids string, status int32) string {
  349. statement := `select to_char(wr.wrrcontractid) wrrcontractid,
  350. wr.deliverygoodsid,
  351. wr.contractqty,
  352. wr.contractstatus,
  353. sum(case bt.contracttype
  354. when 1 then
  355. bt.relatedqty - bt.cancelledqty
  356. else
  357. 0
  358. end) buyqty,
  359. sum(case bt.contracttype
  360. when 1 then
  361. bt.relatedamount - bt.cancelledamount
  362. else
  363. 0
  364. end) buyamount,
  365. sum(case bt.contracttype
  366. when -1 then
  367. bt.relatedqty - bt.cancelledqty
  368. else
  369. 0
  370. end) sellqty,
  371. sum(case bt.contracttype
  372. when -1 then
  373. bt.relatedamount - bt.cancelledamount
  374. else
  375. 0
  376. end) sellamount
  377. from erms3_biztradedetail bt
  378. left join erms2_wrrcontract wr
  379. on wr.wrrcontractid = bt.relatedbizid
  380. where wr.accountid in (%v)
  381. and wr.contractstatus = %v
  382. group by wr.wrrcontractid,
  383. wr.deliverygoodsid,
  384. wr.contractqty,
  385. wr.contractstatus`
  386. return fmt.Sprintf(statement, accountids, status)
  387. }
  388. // GetByAccountIDSAndStatus 根据账号和状态获取仓单回购业务.
  389. func (wr Erms2Wrrcontract) GetByAccountIDSAndStatus(accountids string, status int32) ([]Erms2WrrcontractInfo, error) {
  390. engine := db.GetEngine()
  391. data := make([]Erms2WrrcontractInfo, 0)
  392. err := engine.SQL(wr.buildSQL(accountids, status)).Find(&data)
  393. return data, err
  394. }
  395. // buildSQL 构建sql.
  396. func (Erms2Spottradebiz) buildSQL(accountids string, status int32) string {
  397. statement := `select to_char(sbt.spottradeid) spottradeid,
  398. sbt.deliverygoodsid,
  399. sbt.buyqty,
  400. sbt.sellqty,
  401. sbt.closestatus,
  402. sum(case bt.contracttype
  403. when 1 then
  404. bt.relatedqty - bt.cancelledqty
  405. else
  406. 0
  407. end) tradebuyqty,
  408. sum(case bt.contracttype
  409. when 1 then
  410. bt.relatedamount - bt.cancelledamount
  411. else
  412. 0
  413. end) tradebuyamount,
  414. sum(case bt.contracttype
  415. when -1 then
  416. bt.relatedqty - bt.cancelledqty
  417. else
  418. 0
  419. end) tradesellqty,
  420. sum(case bt.contracttype
  421. when -1 then
  422. bt.relatedamount - bt.cancelledamount
  423. else
  424. 0
  425. end) tradesellamount
  426. from erms3_biztradedetail bt
  427. left join erms2_spottradebiz sbt
  428. on sbt.spottradeid = bt.relatedbizid
  429. where sbt.spotaccountid in (%v)
  430. and sbt.closestatus = %v
  431. group by sbt.spottradeid,
  432. sbt.deliverygoodsid,
  433. sbt.buyqty,
  434. sbt.sellqty,
  435. sbt.closestatus`
  436. return fmt.Sprintf(statement, accountids, status)
  437. }
  438. // GetByAccountIDSAndStatus 根据账号和状态获取现货贸易业务.
  439. func (stb Erms2Spottradebiz) GetByAccountIDSAndStatus(accountids string, status int32) ([]Erms2SpottradebizInfo, error) {
  440. engine := db.GetEngine()
  441. data := make([]Erms2SpottradebizInfo, 0)
  442. err := engine.SQL(stb.buildSQL(accountids, status)).Find(&data)
  443. return data, err
  444. }