|
|
@@ -924,6 +924,9 @@ type WrTradeDetail struct {
|
|
|
MATCHUSERNAME string `json:"matchusername" xorm:"'MATCHUSERNAME'"` // 对手方
|
|
|
Wr2FactorType `xorm:"extends"`
|
|
|
PageEx `xorm:"extends"`
|
|
|
+
|
|
|
+ BEGINDATE string `json:"begindate" form:"begindate"` // 开始交易日(yyyymmdd)
|
|
|
+ ENDDATE string `json:"enddate" form:"enddate"` // 结束交易日(yyyymmdd)
|
|
|
}
|
|
|
|
|
|
func (r *WrTradeDetail) calc() {
|
|
|
@@ -982,10 +985,76 @@ func (r *WrTradeDetail) buildSql() string {
|
|
|
return sqlId.String()
|
|
|
}
|
|
|
|
|
|
+func (r *WrTradeDetail) buildSqlHis() string {
|
|
|
+ var sqlId utils.SQLVal = "with tmp as" +
|
|
|
+ " (select to_char(t.wrfactortypeid) wrfactortypeid," +
|
|
|
+ " t.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 t.HASWR," +
|
|
|
+ " to_char(t.WRTRADEDETAILID) WRTRADEDETAILID," +
|
|
|
+ " t.TRADEDATE," +
|
|
|
+ " t.DELIVERYMONTH," +
|
|
|
+ " t.WRTRADETYPE," +
|
|
|
+ " t.BUYORSELL," +
|
|
|
+ " t.MARKETID," +
|
|
|
+ " t.TRADEQTY," +
|
|
|
+ " t.TRADEPRICE," +
|
|
|
+ " t.CHARGEVALUE," +
|
|
|
+ " to_char(t.TRADETIME,'yyyy-mm-dd hh24:mi:ss') TRADETIME," +
|
|
|
+ " u2.accountname matchusername," +
|
|
|
+ " ta1.userid," +
|
|
|
+ " k.*" +
|
|
|
+ " from his_wrtrade_tradedetail t" +
|
|
|
+ " left join tmp k" +
|
|
|
+ " on t.wrfactortypeid = k.wrfactortypeid" +
|
|
|
+ " left join taaccount ta1 on t.accountid=ta1.accountid" +
|
|
|
+ " left join taaccount ta2 on t.matchaccountid=ta2.accountid" +
|
|
|
+ " left join useraccount u2 on ta2.userid=u2.userid" +
|
|
|
+ " where 1=1"
|
|
|
+ sqlId.And("ta1.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.tradetime desc")
|
|
|
+ sqlId.Page(r.Page, r.PageSize)
|
|
|
+ return sqlId.String()
|
|
|
+}
|
|
|
+
|
|
|
// GetDataByPage 获取仓单贸易成交明细
|
|
|
func (r *WrTradeDetail) GetDataByPage() (interface{}, error, int, int, int) {
|
|
|
+ var sqlId string
|
|
|
+ // 如果指定了开始日期或结束日期, 刚查历史
|
|
|
+ if r.BEGINDATE != "" || r.ENDDATE != "" {
|
|
|
+ sqlId = r.buildSqlHis()
|
|
|
+ } else {
|
|
|
+ sqlId = r.buildSql()
|
|
|
+ }
|
|
|
sData := make([]WrTradeDetail, 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()
|
|
|
@@ -2646,6 +2715,9 @@ type WrOutInApply struct {
|
|
|
EXPRESSNUM string `json:"expressnum" xorm:"'EXPRESSNUM'"` // 物流单号
|
|
|
EXPRESSCOMPANY string `json:"expresscompany" xorm:"'EXPRESSCOMPANY'"` // 物流公司
|
|
|
Wr2FactorType `xorm:"extends"`
|
|
|
+
|
|
|
+ BEGINDATE string `json:"begindate" form:"begindate"` // 开始交易日(yyyymmdd)
|
|
|
+ ENDDATE string `json:"enddate" form:"enddate"` // 结束交易日(yyyymmdd)
|
|
|
}
|
|
|
|
|
|
func (r *WrOutInApply) calc() {
|
|
|
@@ -2696,6 +2768,14 @@ func (r *WrOutInApply) buildSql() string {
|
|
|
" on d.wrfactortypeid = k.wrfactortypeid" +
|
|
|
" where t.applytype in (2, 4)"
|
|
|
sqlId.AndEx("t.USERID", r.USERID, r.USERID > 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.applytime desc")
|
|
|
return sqlId.String()
|
|
|
}
|
|
|
@@ -2745,6 +2825,9 @@ type WrDeliveryDetail struct {
|
|
|
|
|
|
XGOODSAMOUNT SFLOAT64 `json:"xgoodsamount"` // 合约金额 = 货款金额(DELIVERYAMOUNT) - 点价货款(P1GOODSREMAINAMOUNT)
|
|
|
AVERAGEPRICE SFLOAT64 `json:"averageprice"` // 交割均价 = 交割金额 / 交割数量
|
|
|
+
|
|
|
+ BEGINDATE string `json:"begindate" form:"begindate"` // 开始交易日(yyyymmdd)
|
|
|
+ ENDDATE string `json:"enddate" form:"enddate"` // 结束交易日(yyyymmdd)
|
|
|
}
|
|
|
|
|
|
func (r *WrDeliveryDetail) calc() {
|
|
|
@@ -2817,10 +2900,83 @@ select t.xgoodsid,
|
|
|
return sqlId.String()
|
|
|
}
|
|
|
|
|
|
+func (r *WrDeliveryDetail) buildSqlHis() string {
|
|
|
+ var sqlId utils.SQLVal = `
|
|
|
+select t.xgoodsid,
|
|
|
+ t.buyorsell,
|
|
|
+ to_char(t.deliveryid) deliveryid,
|
|
|
+ t.deliveryqty,
|
|
|
+ t.xdeliverycloseqty,
|
|
|
+ t.pdeliverycloseqty,
|
|
|
+ t.deliveryamount,
|
|
|
+ t.pdeliveryprice,
|
|
|
+ t.p1goodsremainamount,
|
|
|
+ t.deliverypricemove,
|
|
|
+ t.deliverytotalamount,
|
|
|
+ to_char(t.deliverytime, 'yyyy-mm-dd hh24:mi:ss') deliverytime,
|
|
|
+ t.deliverystatus,
|
|
|
+ t.accountid,
|
|
|
+ t.matchaccountid,
|
|
|
+ t.tradedate,
|
|
|
+ to_char(t.wrfactortypeid) wrfactortypeid,
|
|
|
+ to_char(t.deliveryorderid) deliveryorderid,
|
|
|
+ g.goodscode xgoodscode,
|
|
|
+ g.goodsname xgoodsname,
|
|
|
+ t.pgoodsid,
|
|
|
+ g2.goodscode pgoodscode,
|
|
|
+ g2.goodsname pgoodsname,
|
|
|
+ ta.accountname taaccountname,
|
|
|
+ u.userid,
|
|
|
+ u.accountname username,
|
|
|
+ u2.accountname matchusername,
|
|
|
+ wd.wrstandardname || w.wrfactortypename2 as WRTYPENAME,
|
|
|
+ h.warehousename,
|
|
|
+ e.enumdicname
|
|
|
+ from his_deliverydetail t
|
|
|
+ left join goods g
|
|
|
+ on t.xgoodsid = g.goodsid
|
|
|
+ left join goods g2
|
|
|
+ on t.pgoodsid = g2.goodsid
|
|
|
+ left join taaccount ta
|
|
|
+ on t.accountid = ta.accountid
|
|
|
+ left join useraccount u
|
|
|
+ on ta.userid = u.userid
|
|
|
+ left join taaccount ta2
|
|
|
+ on t.accountid = ta2.accountid
|
|
|
+ left join useraccount u2
|
|
|
+ on ta2.userid = u2.userid
|
|
|
+ left join wrfactortype w
|
|
|
+ on t.wrfactortypeid = w.wrfactortypeid
|
|
|
+ left join wrstandard wd
|
|
|
+ on w.wrstandardid = wd.wrstandardid
|
|
|
+ left join warehouseinfo h on w.warehouseid=h.autoid
|
|
|
+ left join enumdicitem e on wd.unitid=e.enumitemname and e.enumdiccode='goodsunit'
|
|
|
+ where 1 = 1
|
|
|
+`
|
|
|
+ sqlId.AndEx("u.userid", r.USERID, r.USERID > 0)
|
|
|
+ sqlId.AndEx("t.accountid", r.ACCOUNTID, r.ACCOUNTID > 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)
|
|
|
+ }
|
|
|
+ return sqlId.String()
|
|
|
+}
|
|
|
+
|
|
|
// GetDataEx 获取交收
|
|
|
func (r *WrDeliveryDetail) GetDataEx() (interface{}, error) {
|
|
|
+ var sqlId string
|
|
|
+ // 如果指定了开始日期或结束日期, 刚查历史
|
|
|
+ if r.BEGINDATE != "" || r.ENDDATE != "" {
|
|
|
+ sqlId = r.buildSqlHis()
|
|
|
+ } else {
|
|
|
+ sqlId = r.buildSql()
|
|
|
+ }
|
|
|
sData := make([]WrDeliveryDetail, 0)
|
|
|
- err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
|
|
|
+ err := db.GetEngine().SQL(sqlId).Find(&sData)
|
|
|
for i := range sData {
|
|
|
sData[i].calc()
|
|
|
}
|