|
|
@@ -1,50 +1,151 @@
|
|
|
-// Package models 40.a交割服务
|
|
|
package models
|
|
|
|
|
|
import (
|
|
|
- "fmt"
|
|
|
"mtp2_if/db"
|
|
|
+ "mtp2_if/utils"
|
|
|
)
|
|
|
|
|
|
-// Deliveryrelation 商品交割关系表
|
|
|
-type Deliveryrelation struct {
|
|
|
- Goodsid int64 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 交易合约ID
|
|
|
- Deliverymode int64 `json:"deliverymode" xorm:"'DELIVERYMODE'"` // 交割方式 - 1:点选式 2:申报式
|
|
|
- Wrstandardid int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 仓单标准ID
|
|
|
- Deliverygoodsid int64 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 交割商品
|
|
|
- Mindeliveryqty int64 `json:"mindeliveryqty" xorm:"'MINDELIVERYQTY'" binding:"required"` // 最小交割系数(K)
|
|
|
- Rratio1 int64 `json:"rratio1" xorm:"'RRATIO1'"` // 兑换系数(交易合约)(R1)
|
|
|
- Rratio2 int64 `json:"rratio2" xorm:"'RRATIO2'"` // 兑换系数(仓单标准)(R2)
|
|
|
- Deliverypricerule int64 `json:"deliverypricerule" xorm:"'DELIVERYPRICERULE'"` // 交割价规则- 1:行情价 2:建仓价
|
|
|
- Begindate string `json:"begindate" xorm:"'BEGINDATE'" binding:"required"` // 起始日期(yyyyMMdd)
|
|
|
- Enddate string `json:"enddate" xorm:"'ENDDATE'" binding:"required"` // 结束日期(yyyyMMdd)
|
|
|
- Buytemplateid int64 `json:"buytemplateid" xorm:"'BUYTEMPLATEID'"` // 买履约计划模板ID
|
|
|
- Selltemplateid int64 `json:"selltemplateid" xorm:"'SELLTEMPLATEID'"` // 卖履约计划模板ID
|
|
|
- Deliverytype int64 `json:"deliverytype" xorm:"'DELIVERYTYPE'"` // 交割模式 - 1:X交割 2:X+P交割 3:X+C交割 4:X+P+C交割
|
|
|
- Xdeliveryratio int64 `json:"xdeliveryratio" xorm:"'XDELIVERYRATIO'" binding:"required"` // 交易合约系数(m)
|
|
|
- Ppricemode int64 `json:"ppricemode" xorm:"'PPRICEMODE'"` // P合约价格方式 - 1:商品价 2:固定值
|
|
|
- Pdeliveryprice float64 `json:"pdeliveryprice" xorm:"'PDELIVERYPRICE'"` // P合约价格(商品价时填写0,固定值时填写固定值)
|
|
|
- Pdeliveryratio int64 `json:"pdeliveryratio" xorm:"'PDELIVERYRATIO'"` // P合约系数(n)
|
|
|
- Pgoodsid int64 `json:"pgoodsid" xorm:"'PGOODSID'"` // P合约ID
|
|
|
- P2pricemode int64 `json:"p2pricemode" xorm:"'P2PRICEMODE'"` // P2合约价格方式 - 1:商品价 2:固定值
|
|
|
- P2deliveryprice float64 `json:"p2deliveryprice" xorm:"'P2DELIVERYPRICE'"` // P2合约价格(商品价时填写0,固定值时填写固定值)
|
|
|
- P2deliveryratio int64 `json:"p2deliveryratio" xorm:"'P2DELIVERYRATIO'"` // P2合约系数(p)
|
|
|
- P2goodsid int64 `json:"p2goodsid" xorm:"'P2GOODSID'"` // P2合约ID
|
|
|
- Rratio int64 `json:"rratio" xorm:"'RRATIO'"` // 兑换系数(R)
|
|
|
-}
|
|
|
-
|
|
|
-// TableName is DELIVERYRELATION
|
|
|
-func (Deliveryrelation) TableName() string {
|
|
|
- return "DELIVERYRELATION"
|
|
|
-}
|
|
|
-
|
|
|
-// GetDeliverGoods 获取交割商品
|
|
|
-func GetDeliverGoods() ([]Deliverygoods, error) {
|
|
|
- engine := db.GetEngine()
|
|
|
- d := make([]Deliverygoods, 0)
|
|
|
- if err := engine.Where("IsValid=1").And("categoryid<>0").Find(&d); err != nil {
|
|
|
- return nil, fmt.Errorf("query deleiverygoods fail")
|
|
|
+// DeliveryRelation 交割关系
|
|
|
+type DeliveryRelation struct {
|
|
|
+ GOODSID int32 `json:"goodsid" xorm:"GOODSID" form:"goodsid"` // 交易合约ID
|
|
|
+ DELIVERYMODE int32 `json:"deliverymode" xorm:"DELIVERYMODE"` // 交割方式 - 1:点选式 2:申报式
|
|
|
+ WRSTANDARDID int32 `json:"wrstandardid" xorm:"WRSTANDARDID" form:"wrstandardid"` // 现货商品ID
|
|
|
+ DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"DELIVERYGOODSID" form:"deliverygoodsid"` // 现货品种ID
|
|
|
+ MINDELIVERYQTY float64 `json:"mindeliveryqty" xorm:"MINDELIVERYQTY"` // 最小交割系数(K)
|
|
|
+ RRATIO1 int32 `json:"rratio1" xorm:"RRATIO1"` // 兑换系数(交易合约)(R1)
|
|
|
+ RRATIO2 int32 `json:"rratio2" xorm:"RRATIO2"` // 兑换系数(现货商品)(R2)
|
|
|
+ DELIVERYPRICERULE int32 `json:"deliverypricerule" xorm:"DELIVERYPRICERULE"` // 交割价规则- 1:行情价 2:建仓价
|
|
|
+ BEGINDATE string `json:"begindate" xorm:"BEGINDATE" form:"begindate"` // 起始日期(yyyyMMdd)
|
|
|
+ ENDDATE string `json:"enddate" xorm:"ENDDATE" form:"enddate"` // 结束日期(yyyyMMdd)
|
|
|
+ BUYTEMPLATEID int64 `json:"buytemplateid" xorm:"BUYTEMPLATEID" form:"buytemplateid"` // 买履约计划模板ID
|
|
|
+ SELLTEMPLATEID int64 `json:"selltemplateid" xorm:"SELLTEMPLATEID" form:"selltemplateid"` // 卖履约计划模板ID
|
|
|
+ DELIVERYTYPE int32 `json:"deliverytype" xorm:"DELIVERYTYPE"` // 交割模式 - 1:X交割 2:X+P交割 3:X+C交割 4:X+P+C交割
|
|
|
+ XDELIVERYRATIO int32 `json:"xdeliveryratio" xorm:"XDELIVERYRATIO"` // 交易合约系数(m)
|
|
|
+ PPRICEMODE int32 `json:"ppricemode" xorm:"PPRICEMODE"` // P合约价格方式 - 1:商品价 2:固定值
|
|
|
+ PDELIVERYPRICE float64 `json:"pdeliveryprice" xorm:"PDELIVERYPRICE"` // P合约价格(商品价时填写0,固定值时填写固定值)
|
|
|
+ PDELIVERYRATIO int32 `json:"pdeliveryratio" xorm:"PDELIVERYRATIO"` // P合约系数(n)
|
|
|
+ PGOODSID int32 `json:"pgoodsid" xorm:"PGOODSID" form:"pgoodsid"` // P合约ID
|
|
|
+ P2PRICEMODE int32 `json:"p2pricemode" xorm:"P2PRICEMODE"` // P2合约价格方式 - 1:商品价 2:固定值
|
|
|
+ P2DELIVERYPRICE float64 `json:"p2deliveryprice" xorm:"P2DELIVERYPRICE"` // P2合约价格(商品价时填写0,固定值时填写固定值)
|
|
|
+ P2DELIVERYRATIO int32 `json:"p2deliveryratio" xorm:"P2DELIVERYRATIO"` // P2合约系数(p)
|
|
|
+ P2GOODSID int32 `json:"p2goodsid" xorm:"P2GOODSID" form:"p2goodsid"` // P2合约ID
|
|
|
+ RRATIO int32 `json:"rratio" xorm:"RRATIO"` // 兑换系数(R)
|
|
|
+
|
|
|
+ GOODSCODE string `json:"goodscode" xorm:"'GOODSCODE'"` // 商品代码
|
|
|
+ GOODSNAME string `json:"goodsname" xorm:"'GOODSNAME'"` // 商品名称
|
|
|
+ DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 品种代码
|
|
|
+ DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 品种名称
|
|
|
+ WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 品类代码
|
|
|
+ WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 品类名称
|
|
|
+ BUYTMPNAME string `json:"buytmpname" xorm:"'BUYTMPNAME'"` // 买履约模板名称
|
|
|
+ SELLTMPNAME string `json:"selltmpname" xorm:"'SELLTMPNAME'"` // 卖履约模板名称
|
|
|
+}
|
|
|
+
|
|
|
+func (r *DeliveryRelation) calc() {
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+func (r *DeliveryRelation) buildSql() string {
|
|
|
+ var sqlId utils.SQLVal = "select t.goodsid," +
|
|
|
+ " t.deliverymode," +
|
|
|
+ " t.wrstandardid," +
|
|
|
+ " t.deliverygoodsid," +
|
|
|
+ " t.mindeliveryqty," +
|
|
|
+ " t.rratio1," +
|
|
|
+ " t.rratio2," +
|
|
|
+ " t.deliverypricerule," +
|
|
|
+ " t.begindate," +
|
|
|
+ " t.enddate," +
|
|
|
+ " t.buytemplateid," +
|
|
|
+ " t.selltemplateid," +
|
|
|
+ " t.deliverytype," +
|
|
|
+ " t.xdeliveryratio," +
|
|
|
+ " t.ppricemode," +
|
|
|
+ " t.pdeliveryprice," +
|
|
|
+ " t.pdeliveryratio," +
|
|
|
+ " t.pgoodsid," +
|
|
|
+ " t.p2pricemode," +
|
|
|
+ " t.p2deliveryprice," +
|
|
|
+ " t.p2deliveryratio," +
|
|
|
+ " t.p2goodsid," +
|
|
|
+ " t.rratio," +
|
|
|
+ " g.goodscode," +
|
|
|
+ " g.goodsname," +
|
|
|
+ " dg.deliverygoodscode," +
|
|
|
+ " dg.deliverygoodsname," +
|
|
|
+ " w.wrstandardcode," +
|
|
|
+ " w.wrstandardname," +
|
|
|
+ " k1.templatename buytmpname," +
|
|
|
+ " k2.templatename selltmpname" +
|
|
|
+ " from deliveryrelation t" +
|
|
|
+ " left join goods g" +
|
|
|
+ " on t.goodsid = g.goodsid" +
|
|
|
+ " left join deliverygoods dg" +
|
|
|
+ " on t.deliverygoodsid = dg.deliverygoodsid" +
|
|
|
+ " left join wrstandard w" +
|
|
|
+ " on t.wrstandardid = w.wrstandardid" +
|
|
|
+ " left join performanceplantemplate k1" +
|
|
|
+ " on t.buytemplateid = k1.autoid" +
|
|
|
+ " left join performanceplantemplate k2" +
|
|
|
+ " on t.selltemplateid = k2.autoid" +
|
|
|
+ " where 1=1"
|
|
|
+ sqlId.AndEx("t.GOODSID", r.GOODSID, r.GOODSID > 0)
|
|
|
+ sqlId.AndEx("t.wrstandardid", r.WRSTANDARDID, r.WRSTANDARDID > 0)
|
|
|
+ return sqlId.String()
|
|
|
+}
|
|
|
+
|
|
|
+// GetDataEx 获取交割关系
|
|
|
+func (r *DeliveryRelation) GetDataEx() (interface{}, error) {
|
|
|
+ sData := make([]DeliveryRelation, 0)
|
|
|
+ err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
|
|
|
+ for i := range sData {
|
|
|
+ sData[i].calc()
|
|
|
}
|
|
|
+ return sData, err
|
|
|
+}
|
|
|
+
|
|
|
+// DeliveryRelationDetail 交割关系明细
|
|
|
+type DeliveryRelationDetail struct {
|
|
|
+ GOODSID int32 `json:"goodsid" xorm:"GOODSID" form:"goodsid"` // 交易合约ID
|
|
|
+ DGFACTORYITEMID int64 `json:"dgfactoryitemid" xorm:"DGFACTORYITEMID"` // 选择项ID
|
|
|
+ DGFACTORYITEMTYPEID int64 `json:"dgfactoryitemtypeid" xorm:"DGFACTORYITEMTYPEID"` // 要素项类型ID
|
|
|
+ PREMIUMVALUE float64 `json:"premiumvalue" xorm:"PREMIUMVALUE"` // 升贴水值
|
|
|
|
|
|
- return d, nil
|
|
|
+ ITEMTYPENAME string `json:"itemtypename" xorm:"'ITEMTYPENAME'"` // 要素项名称
|
|
|
+ DGFACTORYITEMVALUE string `json:"dgfactoryitemvalue" xorm:"'DGFACTORYITEMVALUE'"` // 要素项值
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+func (r *DeliveryRelationDetail) calc() {
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+func (r *DeliveryRelationDetail) buildSql() string {
|
|
|
+ var sqlId utils.SQLVal = "select t.goodsid," +
|
|
|
+ " t.dgfactoryitemid," +
|
|
|
+ " t.dgfactoryitemtypeid," +
|
|
|
+ " t.premiumvalue," +
|
|
|
+ " dt.itemtypename," +
|
|
|
+ " di.dgfactoryitemvalue" +
|
|
|
+ " from deliveryrelationdetail t" +
|
|
|
+ " left join deliveryrelation s" +
|
|
|
+ " on t.goodsid = s.goodsid" +
|
|
|
+ " left join dgfactoryitem di" +
|
|
|
+ " on t.dgfactoryitemid = di.dgfactoryitemid" +
|
|
|
+ " left join dgfactoryitemtype dt" +
|
|
|
+ " on t.dgfactoryitemtypeid = dt.dgfactoryitemtypeid" +
|
|
|
+ " and dt.deliverygoodsid = s.deliverygoodsid" +
|
|
|
+ " where 1 = 1"
|
|
|
+ sqlId.AndEx("t.GOODSID", r.GOODSID, r.GOODSID > 0)
|
|
|
+ return sqlId.String()
|
|
|
+}
|
|
|
+
|
|
|
+// GetDataEx 获取交割关系明细
|
|
|
+func (r *DeliveryRelationDetail) GetDataEx() (interface{}, error) {
|
|
|
+ sData := make([]DeliveryRelationDetail, 0)
|
|
|
+ err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
|
|
|
+ for i := range sData {
|
|
|
+ sData[i].calc()
|
|
|
+ }
|
|
|
+ return sData, err
|
|
|
}
|