|
|
@@ -13,40 +13,42 @@ import (
|
|
|
"mtp2_if/mtpcache"
|
|
|
"mtp2_if/pb"
|
|
|
"mtp2_if/rediscli"
|
|
|
+ "mtp2_if/utils"
|
|
|
)
|
|
|
|
|
|
// ErmcpRealExposureModel 实时敞口
|
|
|
type ErmcpRealExposureModel struct {
|
|
|
- MiddleGoodsID uint32 // 套保品种
|
|
|
- AreaUserID uint32 // 所属机构
|
|
|
- OriBuyPlanQty float64 // 期初采购计划数量
|
|
|
- OriBuyPricedQty float64 // 期初采购合同已定价数量
|
|
|
- OriSellPlanQty float64 // 期初销售计划数量
|
|
|
- OriSellPricedQty float64 // 期初销售合同已定价数量
|
|
|
- OriBuyFutureQty float64 // 期初买入期货数量
|
|
|
- OriSellFutureQty float64 // 期初卖出期货数量
|
|
|
- BuyPlanQty float64 // 采购计划数量
|
|
|
- BuyPricedQty float64 // 采购合同已定价数量
|
|
|
- SellPlanQty float64 // 销售计划数量
|
|
|
- SellPricedQty float64 // 销售合同已定价数量
|
|
|
- BuyFutureQty float64 // 买入期货数量
|
|
|
- SellFutureQty float64 // 卖出期货数量
|
|
|
- TotalSpotQty float64 // 现货数量
|
|
|
- TotalFutureQty float64 // 期货数量
|
|
|
- TotalExposure float64 // 总敞口
|
|
|
- TotalHedgeRatio float64 // 敞口比例
|
|
|
- TotalNeedHedgeQty float64 // 期货应套保量
|
|
|
- NeedHedgeExposoure float64 // 应套保敞口
|
|
|
- NeedHedgeRatio float64 // 应套保敞口比例
|
|
|
-
|
|
|
- MiddleGoodsName string // 套保品种名称
|
|
|
- MiddleGoodsCode string // 套保品种代码
|
|
|
- MiddleGoodsHedgeRatio float64 // 应套保比例
|
|
|
- OriTotalSpotQty float64 // 期初现货数量=(期初销售计划数量-期初销售合同已定价数量)-(期初采购计划数量-期初采购合同已定价数量)
|
|
|
- OriTotalFutuQty float64 // 期初期货数量=期初买入期货数量-期初卖出期货数量
|
|
|
- DiffSpotQty float64 // 今日变动量(现货) = 现货数量 - 期初现货数量
|
|
|
- DiffFutuQty float64 // 今日变动量(期货) = (买入 - 买入期初) - (卖出 - 卖出期初)
|
|
|
- ENUMDICNAME string // 单位名称
|
|
|
+ MiddleGoodsID uint32 `json:"MiddleGoodsID" xorm:"'MiddleGoodsID'"` // 套保品种
|
|
|
+ AreaUserID uint32 `json:"AreaUserID" xorm:"'AreaUserID'"` // 所属机构
|
|
|
+ OriBuyPlanQty float64 `json:"OriBuyPlanQty" xorm:"'OriBuyPlanQty'"` // 期初采购计划数量
|
|
|
+ OriBuyPricedQty float64 `json:"OriBuyPricedQty" xorm:"'OriBuyPricedQty'"` // 期初采购合同已定价数量
|
|
|
+ OriSellPlanQty float64 `json:"OriSellPlanQty" xorm:"'OriSellPlanQty'"` // 期初销售计划数量
|
|
|
+ OriSellPricedQty float64 `json:"OriSellPricedQty" xorm:"'OriSellPricedQty'"` // 期初销售合同已定价数量
|
|
|
+ OriBuyFutureQty float64 `json:"OriBuyFutureQty" xorm:"'OriBuyFutureQty'"` // 期初买入期货数量
|
|
|
+ OriSellFutureQty float64 `json:"OriSellFutureQty" xorm:"'OriSellFutureQty'"` // 期初卖出期货数量
|
|
|
+ BuyPlanQty float64 `json:"BuyPlanQty" xorm:"'BuyPlanQty'"` // 采购计划数量
|
|
|
+ BuyPricedQty float64 `json:"BuyPricedQty" xorm:"'BuyPricedQty'"` // 采购合同已定价数量
|
|
|
+ SellPlanQty float64 `json:"SellPlanQty" xorm:"'SellPlanQty'"` // 销售计划数量
|
|
|
+ SellPricedQty float64 `json:"SellPricedQty" xorm:"'SellPricedQty'"` // 销售合同已定价数量
|
|
|
+ BuyFutureQty float64 `json:"BuyFutureQty" xorm:"'BuyFutureQty'"` // 买入期货数量
|
|
|
+ SellFutureQty float64 `json:"SellFutureQty" xorm:"'SellFutureQty'"` // 卖出期货数量
|
|
|
+ TotalSpotQty float64 `json:"TotalSpotQty" xorm:"'TotalSpotQty'"` // 现货数量
|
|
|
+ TotalFutureQty float64 `json:"TotalFutureQty" xorm:"'TotalFutureQty'"` // 期货数量
|
|
|
+ TotalExposure float64 `json:"TotalExposure" xorm:"'TotalExposure'"` // 总敞口
|
|
|
+ TotalHedgeRatio float64 `json:"TotalHedgeRatio" xorm:"'TotalHedgeRatio'"` // 敞口比例
|
|
|
+ TotalNeedHedgeQty float64 `json:"TotalNeedHedgeQty" xorm:"'TotalNeedHedgeQty'"` // 期货应套保量
|
|
|
+ NeedHedgeExposoure float64 `json:"NeedHedgeExposoure" xorm:"'NeedHedgeExposoure'"` // 应套保敞口
|
|
|
+ NeedHedgeRatio float64 `json:"NeedHedgeRatio" xorm:"'NeedHedgeRatio'"` // 应套保敞口比例
|
|
|
+ GOODSUNITID int32 `json:"-" xorm:"'GOODSUNITID'"` // 品种单位ID
|
|
|
+ MiddleGoodsName string `json:"MiddleGoodsName" xorm:"'MiddleGoodsName'"` // 套保品种名称
|
|
|
+ MiddleGoodsCode string `json:"MiddleGoodsCode" xorm:"'MiddleGoodsCode'"` // 套保品种代码
|
|
|
+ MiddleGoodsHedgeRatio float64 `json:"MiddleGoodsHedgeRatio" xorm:"'needhedgeratio'"` // 应套保比例
|
|
|
+
|
|
|
+ OriTotalSpotQty float64 // 期初现货数量=(期初销售计划数量-期初销售合同已定价数量)-(期初采购计划数量-期初采购合同已定价数量)
|
|
|
+ OriTotalFutuQty float64 // 期初期货数量=期初买入期货数量-期初卖出期货数量
|
|
|
+ DiffSpotQty float64 // 今日变动量(现货) = 现货数量 - 期初现货数量
|
|
|
+ DiffFutuQty float64 // 今日变动量(期货) = (买入 - 买入期初) - (卖出 - 卖出期初)
|
|
|
+ ENUMDICNAME string // 单位名称
|
|
|
}
|
|
|
|
|
|
// calc 计算相关字段
|
|
|
@@ -55,6 +57,42 @@ func (r *ErmcpRealExposureModel) calc() {
|
|
|
r.OriTotalFutuQty = r.OriBuyFutureQty - r.OriSellFutureQty
|
|
|
r.DiffSpotQty = r.TotalSpotQty - r.OriTotalSpotQty
|
|
|
r.DiffFutuQty = (r.BuyFutureQty - r.OriBuyFutureQty) - (r.SellFutureQty - r.OriSellFutureQty)
|
|
|
+ if r.ENUMDICNAME == "" {
|
|
|
+ r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.GOODSUNITID)
|
|
|
+ }
|
|
|
+}
|
|
|
+func (r *ErmcpRealExposureModel) buildSql() string {
|
|
|
+ var sqlId utils.SQLVal = "select t.MiddleGoodsID," +
|
|
|
+ " t.AreaUserID," +
|
|
|
+ " t.OriBuyPlanQty," +
|
|
|
+ " t.OriBuyPricedQty," +
|
|
|
+ " t.OriSellPlanQty," +
|
|
|
+ " t.OriSellPricedQty," +
|
|
|
+ " t.OriBuyFutureQty," +
|
|
|
+ " t.OriSellFutureQty," +
|
|
|
+ " t.BuyPlanQty," +
|
|
|
+ " t.BuyPricedQty," +
|
|
|
+ " t.SellPlanQty," +
|
|
|
+ " t.SellPricedQty," +
|
|
|
+ " t.BuyFutureQty," +
|
|
|
+ " t.SellFutureQty," +
|
|
|
+ " t.TotalSpotQty," +
|
|
|
+ " t.TotalFutureQty," +
|
|
|
+ " t.TotalExposure," +
|
|
|
+ " t.TotalHedgeRatio," +
|
|
|
+ " t.TotalNeedHedgeQty," +
|
|
|
+ " t.NeedHedgeExposoure," +
|
|
|
+ " t.NeedHedgeRatio," +
|
|
|
+ " g.middlegoodsname," +
|
|
|
+ " g.middlegoodscode," +
|
|
|
+ " g.goodsunitid," +
|
|
|
+ " g.needhedgeratio" +
|
|
|
+ " from ermcp_areaexposure t" +
|
|
|
+ " left join erms_middlegoods g" +
|
|
|
+ " on t.middlegoodsid = g.middlegoodsid" +
|
|
|
+ " where 1 = 1"
|
|
|
+ sqlId.And("t.AreaUserID", r.AreaUserID)
|
|
|
+ return sqlId.String()
|
|
|
}
|
|
|
|
|
|
// ParseFromProto 从协议中获取数据
|
|
|
@@ -112,6 +150,16 @@ func (r *ErmcpRealExposureModel) GetData() ([]ErmcpRealExposureModel, error) {
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
+// GetDataEx 从数据库中查询实时敞口
|
|
|
+func (r *ErmcpRealExposureModel) GetDataEx() (interface{}, error) {
|
|
|
+ sData := make([]ErmcpRealExposureModel, 0)
|
|
|
+ err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
|
|
|
+ for i := range sData {
|
|
|
+ sData[i].calc()
|
|
|
+ }
|
|
|
+ return sData, err
|
|
|
+}
|
|
|
+
|
|
|
/*************敞口明细**************/
|
|
|
|
|
|
// ErmcpExposureDetailModel 敞口现货明细结构
|
|
|
@@ -326,7 +374,7 @@ func (r *ErmcpAreaSpotDetailModel) buildSql() string {
|
|
|
" t.LogType," +
|
|
|
" tmp.contracttype," +
|
|
|
" t.RealQty qty," +
|
|
|
- " to_char(t.createtime, 'yyyy-mm-dd hh:mi:ss') createtime," +
|
|
|
+ " to_char(t.createtime, 'yyyy-mm-dd hh24:mi:ss') createtime," +
|
|
|
" w.wrstandardname," +
|
|
|
" w.wrstandardcode," +
|
|
|
" w.unitid" +
|