|
|
@@ -662,6 +662,9 @@ type WrOrderDetail struct {
|
|
|
|
|
|
FUTUSHOW string `json:"futushow"` // 期货合约/升贴水
|
|
|
AMOUNT SFLOAT64 `json:"amount"` // 挂牌金额 = 委托数量 * 固定价或升贴水
|
|
|
+
|
|
|
+ BEGINDATE string `json:"begindate" form:"begindate"` // 开始交易日(yyyymmdd)
|
|
|
+ ENDDATE string `json:"enddate" form:"enddate"` // 结束交易日(yyyymmdd)
|
|
|
}
|
|
|
|
|
|
func (r *WrOrderDetail) calc() {
|
|
|
@@ -786,10 +789,113 @@ select t.HASWR,
|
|
|
return sqlId.String()
|
|
|
}
|
|
|
|
|
|
+func (r *WrOrderDetail) buildSqlHis() string {
|
|
|
+ var sqlId utils.SQLVal = `
|
|
|
+with tmp as
|
|
|
+ (select to_char(t.wrfactortypeid) wrfactortypeid,
|
|
|
+ t.wrfactortypename2 wrfactortypename,
|
|
|
+ t.wrstandardid,
|
|
|
+ t.deliverygoodsid,
|
|
|
+ g.deliverygoodscode,
|
|
|
+ g.deliverygoodsname,
|
|
|
+ w.wrstandardcode,
|
|
|
+ w.wrstandardname,
|
|
|
+ h.warehousecode,
|
|
|
+ h.warehousename,
|
|
|
+ e.enumdicname,
|
|
|
+ w.wrstandardname || t.wrfactortypename2 as wrtypename
|
|
|
+ from wrfactortype t
|
|
|
+ left join deliverygoods g
|
|
|
+ on t.deliverygoodsid = g.deliverygoodsid
|
|
|
+ left join wrstandard w
|
|
|
+ on t.wrstandardid = w.wrstandardid
|
|
|
+ left join warehouseinfo h
|
|
|
+ on t.warehouseid = h.autoid
|
|
|
+ left join enumdicitem e
|
|
|
+ on w.unitid = e.enumitemname
|
|
|
+ and e.enumdiccode = 'goodsunit'),
|
|
|
+mr as (
|
|
|
+select q.wrtradeorderid, wm_concat(u.userid||' '||u.accountname) matchusername from wrtrade_matchdetail q
|
|
|
+left join useraccount u on q.matchuserid=u.userid
|
|
|
+group by q.wrtradeorderid
|
|
|
+)
|
|
|
+select t.HASWR,
|
|
|
+ to_char(t.validtime,'yyyy-mm-dd hh24:mi:ss') validtime,
|
|
|
+ to_char(t.WRTRADEORDERID) WRTRADEORDERID,
|
|
|
+ t.TRADEDATE,
|
|
|
+ t.DELIVERYMONTH,
|
|
|
+ t.WRTRADETYPE,
|
|
|
+ t.BUYORSELL,
|
|
|
+ t.MARKETID,
|
|
|
+ t.USERID,
|
|
|
+ t.ORDERQTY,
|
|
|
+ t.TRADEQTY,
|
|
|
+ t.CANCELQTY,
|
|
|
+ t.WRPRICETYPE,
|
|
|
+ t.FIXEDPRICE,
|
|
|
+ t.PRICEMOVE,
|
|
|
+ t.TRADEPRICE,
|
|
|
+ to_char(t.ORDERTIME, 'yyyy-mm-dd hh24:mi:ss') ORDERTIME,
|
|
|
+ t.WRTRADEORDERSTATUS,
|
|
|
+ t.marginvalue,
|
|
|
+ t.freezemargin,
|
|
|
+ t.delistminqty,
|
|
|
+ t.canbargain,
|
|
|
+ t.canpart,
|
|
|
+ t.allfriendsflag,
|
|
|
+ t.isspecified,
|
|
|
+ t.accountid,
|
|
|
+ t.performancetemplateid,
|
|
|
+ c.GOODSID,
|
|
|
+ c.GOODSCODE,
|
|
|
+ c.pricemove FUTUPRICEMOVE,
|
|
|
+ g.goodsname,
|
|
|
+ mr.matchusername,
|
|
|
+ ta.accountname taname,
|
|
|
+ to_char(b.ladingbillid) ladingbillid,
|
|
|
+ b.subnum,
|
|
|
+ k.*
|
|
|
+ from his_wrtrade_orderdetail t
|
|
|
+ left join wrtrade_goodsconfig c
|
|
|
+ on t.wrtradeorderid = c.wrtradeorderid
|
|
|
+ left join wrtrade_orderdetaillb b on t.wrtradeorderid=b.wrtradeorderid
|
|
|
+ left join goods g
|
|
|
+ on c.goodsid = g.goodsid
|
|
|
+ left join tmp k
|
|
|
+ on t.wrfactortypeid = k.wrfactortypeid
|
|
|
+ left join mr
|
|
|
+ on t.wrtradeorderid = mr.wrtradeorderid
|
|
|
+ left join taaccount ta
|
|
|
+ on t.accountid = ta.accountid
|
|
|
+ where t.WRTRADETYPE = 1 and t.WRTRADEORDERSTATUS not in(2)
|
|
|
+`
|
|
|
+ sqlId.And("t.USERID", r.USERID)
|
|
|
+ sqlId.And("t.haswr", r.HASWR)
|
|
|
+ sqlId.AndEx("t.marketid", r.MARKETID, r.MARKETID > 0)
|
|
|
+ // 格式 yyyymmdd
|
|
|
+ if len(r.BEGINDATE) > 0 {
|
|
|
+ sqlId.JoinFormat(" and t.TRADEDATE >= '%v'", r.BEGINDATE)
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(r.ENDDATE) > 0 {
|
|
|
+ sqlId.JoinFormat(" and t.TRADEDATE <= '%v'", r.ENDDATE)
|
|
|
+ }
|
|
|
+ sqlId.Join(" order by t.ORDERTIME desc")
|
|
|
+ sqlId.Page(r.Page, r.PageSize)
|
|
|
+ return sqlId.String()
|
|
|
+}
|
|
|
+
|
|
|
// GetDataByPage 获取仓单贸易委托单
|
|
|
func (r *WrOrderDetail) GetDataByPage() (interface{}, error, int, int, int) {
|
|
|
+ var sqlId string
|
|
|
+ // 如果指定了开始日期或结束日期, 刚查历史
|
|
|
+ if r.BEGINDATE != "" || r.ENDDATE != "" {
|
|
|
+ sqlId = r.buildSqlHis()
|
|
|
+ } else {
|
|
|
+ sqlId = r.buildSql()
|
|
|
+ }
|
|
|
sData := make([]WrOrderDetail, 0)
|
|
|
- err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
|
|
|
+ err := db.GetEngine().SQL(sqlId).Find(&sData)
|
|
|
total := 0
|
|
|
for i := range sData {
|
|
|
sData[i].calc()
|
|
|
@@ -3422,7 +3528,9 @@ type WRTradeBargainApply struct {
|
|
|
TEMPLATENAME string `json:"templatename" xorm:"'TEMPLATENAME'"` // 履约方式(履约模板名称)
|
|
|
Wr2FactorType `xorm:"extends"`
|
|
|
|
|
|
- HASWR int32 `json:"-" form:"haswr"` // 0-仓单预售 1-仓单贸易
|
|
|
+ HASWR int32 `json:"-" form:"haswr"` // 0-仓单预售 1-仓单贸易
|
|
|
+ BEGINDATE string `json:"begindate" form:"begindate"` // 开始交易日(yyyymmdd)
|
|
|
+ ENDDATE string `json:"enddate" form:"enddate"` // 结束交易日(yyyymmdd)
|
|
|
}
|
|
|
|
|
|
func (r *WRTradeBargainApply) calc() {
|
|
|
@@ -3510,10 +3618,98 @@ SELECT to_char(t.WRBARGAINID) WRBARGAINID,
|
|
|
return sqlId.String()
|
|
|
}
|
|
|
|
|
|
+// buildSqlHis 查历史
|
|
|
+func (r *WRTradeBargainApply) buildSqlHis() string {
|
|
|
+ var sqlId utils.SQLVal = `
|
|
|
+with tmp as
|
|
|
+ (select to_char(t.wrfactortypeid) wrfactortypeid,
|
|
|
+ t.wrfactortypename2 wrfactortypename,
|
|
|
+ t.wrstandardid,
|
|
|
+ t.deliverygoodsid,
|
|
|
+ g.deliverygoodscode,
|
|
|
+ g.deliverygoodsname,
|
|
|
+ w.wrstandardcode,
|
|
|
+ w.wrstandardname,
|
|
|
+ h.warehousecode,
|
|
|
+ h.warehousename,
|
|
|
+ e.enumdicname,
|
|
|
+ w.wrstandardname || t.wrfactortypename2 as wrtypename
|
|
|
+ from wrfactortype t
|
|
|
+ left join deliverygoods g
|
|
|
+ on t.deliverygoodsid = g.deliverygoodsid
|
|
|
+ left join wrstandard w
|
|
|
+ on t.wrstandardid = w.wrstandardid
|
|
|
+ left join warehouseinfo h
|
|
|
+ on t.warehouseid = h.autoid
|
|
|
+ left join enumdicitem e
|
|
|
+ on w.unitid = e.enumitemname
|
|
|
+ and e.enumdiccode = 'goodsunit')
|
|
|
+SELECT to_char(t.WRBARGAINID) WRBARGAINID,
|
|
|
+ to_char(t.WRTRADEORDERID) WRTRADEORDERID,
|
|
|
+ t.TRADEDATE,
|
|
|
+ t.MARKETID,
|
|
|
+ t.USERID,
|
|
|
+ t.ACCOUNTID,
|
|
|
+ t.BUYORSELL,
|
|
|
+ t.APPLYQTY,
|
|
|
+ t.APPLYPRICE,
|
|
|
+ t.APPLYSTATUS,
|
|
|
+ t.HANDLESTATUS,
|
|
|
+ to_char(t.APPLYTIME, 'yyyy-mm-dd hh24:mi:ss') APPLYTIME,
|
|
|
+ t.APPLYREMARK,
|
|
|
+ t.CONFIRMUSERID,
|
|
|
+ to_char(t.CONFIRMTIME, 'yyyy-mm-dd hh24:mi:ss') CONFIRMTIME,
|
|
|
+ t.CONFIRMREMARK,
|
|
|
+ t.REFPRICE,
|
|
|
+ t.RETCODE,
|
|
|
+ t.matchuserid,
|
|
|
+ t.matchaccountid,
|
|
|
+ u.accountname USERNAME,
|
|
|
+ u2.accountname matchusername,
|
|
|
+ o.orderqty,
|
|
|
+ o.fixedprice,
|
|
|
+ o.deliverymonth,
|
|
|
+ o.marginvalue,
|
|
|
+ to_char(o.validtime, 'yyyy-mm-dd hh24:mi:ss') validtime,
|
|
|
+ p.templatename,
|
|
|
+ tmp.*
|
|
|
+ FROM HIS_WRTRADE_BARGAINAPPLY t
|
|
|
+ LEFT JOIN USERACCOUNT u on t.userid=u.userid
|
|
|
+ LEFT JOIN USERACCOUNT u2 on t.matchuserid=u2.userid
|
|
|
+ LEFT JOIN HIS_WRTRADE_ORDERDETAIL o on t.wrtradeorderid=o.wrtradeorderid
|
|
|
+ LEFT JOIN tmp on o.wrfactortypeid=tmp.wrfactortypeid
|
|
|
+ LEFT JOIN PERFORMANCEPLANTEMPLATE p on o.performancetemplateid=p.autoid
|
|
|
+ WHERE 1 = 1
|
|
|
+`
|
|
|
+ sqlId.AndEx("t.userid", r.USERID, r.USERID > 0)
|
|
|
+ sqlId.AndEx("t.matchuserid", r.MATCHUSERID, r.MATCHUSERID > 0)
|
|
|
+ sqlId.AndEx("t.WRTRADEORDERID", r.WRTRADEORDERID, r.WRTRADEORDERID != "")
|
|
|
+ sqlId.And("o.haswr", r.HASWR)
|
|
|
+
|
|
|
+ // 格式 yyyymmdd
|
|
|
+ if len(r.BEGINDATE) > 0 {
|
|
|
+ sqlId.JoinFormat(" and t.TRADEDATE >= '%v'", r.BEGINDATE)
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(r.ENDDATE) > 0 {
|
|
|
+ sqlId.JoinFormat(" and t.TRADEDATE <= '%v'", r.ENDDATE)
|
|
|
+ }
|
|
|
+
|
|
|
+ return sqlId.String()
|
|
|
+}
|
|
|
+
|
|
|
// GetDataEx 获取议价单
|
|
|
func (r *WRTradeBargainApply) GetDataEx() (interface{}, error) {
|
|
|
+ var sqlId string
|
|
|
+ // 如果指定了开始日期或结束日期, 刚查历史
|
|
|
+ if r.BEGINDATE != "" || r.ENDDATE != "" {
|
|
|
+ sqlId = r.buildSqlHis()
|
|
|
+ } else {
|
|
|
+ sqlId = r.buildSql()
|
|
|
+ }
|
|
|
+
|
|
|
sData := make([]WRTradeBargainApply, 0)
|
|
|
- err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
|
|
|
+ err := db.GetEngine().SQL(sqlId).Find(&sData)
|
|
|
for i := range sData {
|
|
|
sData[i].calc()
|
|
|
}
|