|
|
@@ -479,7 +479,7 @@ func (r *Ermcp2hedgeditemspotDetail) GetDataEx() (interface{}, error) {
|
|
|
// Ermcppatradelinkdetail 期货成交单关联明细表
|
|
|
type Ermcppatradelinkdetail struct {
|
|
|
LINKDETAILID string `json:"linkdetailid" xorm:"LINKDETAILID"` // 期货明细ID(614+Unix秒时间戳(10位)+xxxxxx)
|
|
|
- TRADEID int64 `json:"tradeid" xorm:"TRADEID"` // 内部成交单ID
|
|
|
+ TRADEID string `json:"tradeid" xorm:"TRADEID"` // [成交单号]内部成交单ID
|
|
|
BUYORSELL int32 `json:"buyorsell" xorm:"BUYORSELL"` // 方向 - 0:买 1:卖
|
|
|
HEDGEFLAG int32 `json:"hedgeflag" xorm:"HEDGEFLAG"` // 投机套保标志 - 0:无 1:投机 2:套保 3:套利 4:套期保值(平安\合同) 5:单边(平安) 6:移仓(平安) 7:错单处理(平安) 8:跨期套利(平安) 9:套期保值(计划) 10:套利(合同) 11:换月(合同) 12:交割(金瑞) 13:被套期项目
|
|
|
SPOTCONTRACTID int64 `json:"hedgeditemid" xorm:"SPOTCONTRACTID" form:"hedgeditemid" binding:"required"` // 现货ID[套期项目ID] [13 - 被套期项目ID] [4,10,11 - 现货合同ID] [9 - 套保计划ID]
|
|
|
@@ -525,7 +525,7 @@ func (r *Ermcppatradelinkdetail) buildSql() string {
|
|
|
t.TRADEPRICE,
|
|
|
t.RELATEDLOT,
|
|
|
(t.RelatedLot * t.TradePrice * t.AgreeUnit) AMOUNT,
|
|
|
- t.TRADEID,
|
|
|
+ to_char(t.TRADEID) TRADEID,
|
|
|
(u.ACCOUNTNAME || '/' || to_char(t.ACCOUNTID)) NAME
|
|
|
FROM ERMCP_PA_TradeLinkDetail t
|
|
|
LEFT JOIN ERMCP_PA_TradeLink p ON p.TradeID = t.TradeID AND p.BuyorSell = t.BuyorSell
|
|
|
@@ -552,3 +552,109 @@ func (r *Ermcppatradelinkdetail) GetDataEx() (interface{}, error) {
|
|
|
}
|
|
|
return sData, nil
|
|
|
}
|
|
|
+
|
|
|
+// InternalUncorrelatedTradeDetail 内部未关联成交单
|
|
|
+type InternalUncorrelatedTradeDetail struct {
|
|
|
+ LINKDETAILID string `json:"linkdetailid" xorm:"LINKDETAILID"` // 期货明细ID(614+Unix秒时间戳(10位)+xxxxxx)
|
|
|
+ TRADEID string `json:"tradeid" xorm:"TRADEID" form:"tradeid"` // 成交单号
|
|
|
+ BUYORSELL int32 `json:"buyorsell" xorm:"BUYORSELL" form:"buyorsell"` // 方向 - 0:买 1:卖
|
|
|
+ HEDGEFLAG int32 `json:"hedgeflag" xorm:"HEDGEFLAG"` // 投机套保标志 - 0:无 1:投机 2:套保 3:套利 4:套期保值(平安\合同) 5:单边(平安) 6:移仓(平安) 7:错单处理(平安) 8:跨期套利(平安) 9:套期保值(计划) 10:套利(合同) 11:换月(合同) 12:交割(金瑞) 13:被套期项目
|
|
|
+ SPOTCONTRACTID int64 `json:"hedgeditemid" xorm:"SPOTCONTRACTID"` // 现货ID[套期项目ID] [13 - 被套期项目ID] [4,10,11 - 现货合同ID] [9 - 套保计划ID]
|
|
|
+ RELATEDLOT float64 `json:"relatedlot" xorm:"RELATEDLOT"` // [数量]关联手数
|
|
|
+ GOODSID int32 `json:"goodsid" xorm:"GOODSID"` // 商品ID
|
|
|
+ GOODSGROUPID int32 `json:"goodsgroupid" xorm:"GOODSGROUPID"` // 对冲品种ID[期货合约商品组ID]
|
|
|
+ MIDDLEGOODSID int64 `json:"middlegoodsid" xorm:"MIDDLEGOODSID"` // 套保品种ID
|
|
|
+ RELATEDQTY float64 `json:"relatedqty" xorm:"RELATEDQTY"` // [套期商品数量]关联数量 = RelatedLot * AgreeUnit * ConvertRatio
|
|
|
+ TRADEDATE string `json:"tradedate" xorm:"TRADEDATE"` // 关联交易日(yyyyMMdd)
|
|
|
+ RELATEDMODE int32 `json:"relatedmode" xorm:"RELATEDMODE"` // 关联方式 - 1:自动关联 2:手动关联 3:解绑关联
|
|
|
+ TRADETRADEDATE string `json:"tradetradedate" xorm:"TRADETRADEDATE"` // 成交交易日(yyyyMMdd)
|
|
|
+ TRADEPRICE float64 `json:"tradeprice" xorm:"TRADEPRICE"` // 成交价
|
|
|
+ TRADELOT int64 `json:"tradelot" xorm:"TRADELOT"` // 成交手数
|
|
|
+ SALEUSERID int64 `json:"saleuserid" xorm:"SALEUSERID"` // 业务员ID
|
|
|
+ BIZSUBJECTID int64 `json:"bizsubjectid" xorm:"BIZSUBJECTID"` // 归属业务部门ID - SubjectID
|
|
|
+ AGREEUNIT float64 `json:"agreeunit" xorm:"AGREEUNIT"` // 合约乘数
|
|
|
+ CONVERTRATIO float64 `json:"convertratio" xorm:"CONVERTRATIO"` // 品种系数
|
|
|
+ AREAUSERID int64 `json:"areauserid" xorm:"AREAUSERID"` // 所属机构
|
|
|
+ CREATORSRC int32 `json:"creatorsrc" xorm:"CREATORSRC"` // 创建人来源 - 1:管理端 2:终端 3:交易
|
|
|
+ CREATORID int64 `json:"creatorid" xorm:"CREATORID"` // 创建人ID
|
|
|
+ CREATETIME time.Time `json:"createtime" xorm:"CREATETIME"` // 创建时间
|
|
|
+ LINKSTATUS int32 `json:"linkstatus" xorm:"LINKSTATUS"` // 关联状态 - 1:成功 2:失败 3:解绑
|
|
|
+ RETCODE int32 `json:"retcode" xorm:"RETCODE"` // 返回码
|
|
|
+
|
|
|
+ TRADETIME time.Time `json:"tradetime" xorm:"TRADETIME"` // 成交时间
|
|
|
+ ACCOUNTNAME string `json:"accountname" xorm:"ACCOUNTNAME" form:"accountname"` // 套期主体
|
|
|
+ ENABLEQTY float64 `json:"enableqty" xorm:"ENABLEQTY"` // 项目可关联手数 = 成交手数 - 关联数量
|
|
|
+
|
|
|
+ USERID int64 `form:"userid" binding:"required"` // 用户编号
|
|
|
+ BEGINDATE string `json:"-" form:"begindate"` // 起始日期, 格式:yyyymmdd
|
|
|
+ ENDDATE string `json:"-" form:"enddate"` // 终止日期, 格式:yyyymmdd
|
|
|
+ GOODSCODE string `json:"goodscode" form:"goodscode"` // 合约代码
|
|
|
+ GOODSNAME string `json:"goodsname" form:"goodsname"` // 合约名称
|
|
|
+}
|
|
|
+
|
|
|
+func (r *InternalUncorrelatedTradeDetail) calc() {
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+func (r *InternalUncorrelatedTradeDetail) buildSql() string {
|
|
|
+ var sqlId utils.SQLVal = `
|
|
|
+ SELECT
|
|
|
+ ept.TRADETIME,
|
|
|
+ ept.GOODSID,
|
|
|
+ g.GOODSCODE,
|
|
|
+ g.GOODSNAME,
|
|
|
+ ept.BUYORSELL,
|
|
|
+ ept.TRADEPRICE,
|
|
|
+ ept.TRADELOT,
|
|
|
+ ept.RELATEDQTY,
|
|
|
+ ept.RELATEDLOT,
|
|
|
+ ept.MIDDLEGOODSQTY,
|
|
|
+ e.ENUMDICNAME,
|
|
|
+ to_char(ept.TRADEID) TRADEID,
|
|
|
+ ua.ACCOUNTNAME,
|
|
|
+ ta.accountname TAACCOUNTNAME,
|
|
|
+ ept.ACCOUNTID,
|
|
|
+ (ept.TRADELOT - ept.RELATEDQTY) ENABLEQTY
|
|
|
+ FROM ERMCP_PA_TRADELINK ept
|
|
|
+ LEFT JOIN goods g ON ept.goodsid = g.goodsid
|
|
|
+ LEFT JOIN taaccount ta ON ta.accountid = ept.accountid
|
|
|
+ LEFT JOIN useraccount ua ON ta.userid = ua.userid
|
|
|
+ LEFT JOIN enumdicitem e ON e.enumitemname = g.goodunitid AND e.enumdiccode = 'goodsunit'
|
|
|
+ WHERE ept.tradelot > ept.relatedlot
|
|
|
+ and ept.areauserid in
|
|
|
+ (select u1.userid
|
|
|
+ FROM useraccount u1
|
|
|
+ start with u1.userid = %v
|
|
|
+ connect by prior u1.userid = u1.parentuserid)
|
|
|
+ `
|
|
|
+
|
|
|
+ sqlId.FormatParam(r.USERID)
|
|
|
+ if r.BEGINDATE != "" {
|
|
|
+ sqlId.JoinFormat(" and to_char(ept.tradetime, 'yyyymmdd') >= '%v'", r.BEGINDATE)
|
|
|
+ }
|
|
|
+ if r.ENDDATE != "" {
|
|
|
+ sqlId.JoinFormat(" and to_char(ept.tradetime, 'yyyymmdd') <= '%v'", r.ENDDATE)
|
|
|
+ }
|
|
|
+ sqlId.AndLike("g.goodscode", r.GOODSCODE)
|
|
|
+ sqlId.AndLike("g.goodsname", r.GOODSNAME)
|
|
|
+ sqlId.AndEx("ept.TRADEID", r.TRADEID, r.TRADEID != "")
|
|
|
+ sqlId.And("ept.BUYORSELL", r.BUYORSELL)
|
|
|
+ sqlId.AndLikes2("ta.accountname", "ta.accountid", r.ACCOUNTNAME)
|
|
|
+ sqlId.OrderByDesc("ept.tradetime")
|
|
|
+
|
|
|
+ return sqlId.String()
|
|
|
+}
|
|
|
+
|
|
|
+// GetDataEx 从数据库中查询数据
|
|
|
+func (r *InternalUncorrelatedTradeDetail) GetDataEx() (interface{}, error) {
|
|
|
+ e := db.GetEngine()
|
|
|
+ s := e.SQL(r.buildSql())
|
|
|
+ sData := make([]InternalUncorrelatedTradeDetail, 0)
|
|
|
+ if err := s.Find(&sData); err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ for i := range sData {
|
|
|
+ sData[i].calc()
|
|
|
+ }
|
|
|
+ return sData, nil
|
|
|
+}
|