|
|
@@ -15,7 +15,7 @@ import (
|
|
|
"mtp2_if/rediscli"
|
|
|
)
|
|
|
|
|
|
-//实时敞口
|
|
|
+// ErmcpRealExposureModel 实时敞口
|
|
|
type ErmcpRealExposureModel struct {
|
|
|
MiddleGoodsID uint32 // 套保品种
|
|
|
AreaUserID uint32 // 所属机构
|
|
|
@@ -49,7 +49,7 @@ type ErmcpRealExposureModel struct {
|
|
|
ENUMDICNAME string // 单位名称
|
|
|
}
|
|
|
|
|
|
-// 计算相关字段
|
|
|
+// calc 计算相关字段
|
|
|
func (r *ErmcpRealExposureModel) calc() {
|
|
|
r.OriTotalSpotQty = (r.OriSellPlanQty - r.OriSellPricedQty) - (r.OriBuyPlanQty - r.OriBuyPricedQty)
|
|
|
r.OriTotalFutuQty = r.OriBuyFutureQty - r.OriSellFutureQty
|
|
|
@@ -57,6 +57,7 @@ func (r *ErmcpRealExposureModel) calc() {
|
|
|
r.DiffFutuQty = (r.BuyFutureQty - r.OriBuyFutureQty) - (r.SellFutureQty - r.OriSellFutureQty)
|
|
|
}
|
|
|
|
|
|
+// ParseFromProto 从协议中获取数据
|
|
|
func (r *ErmcpRealExposureModel) ParseFromProto(v *pb.ErmcpAreaExposure) {
|
|
|
r.MiddleGoodsID = *v.MiddleGoodsID
|
|
|
r.AreaUserID = *v.AreaUserID
|
|
|
@@ -83,7 +84,7 @@ func (r *ErmcpRealExposureModel) ParseFromProto(v *pb.ErmcpAreaExposure) {
|
|
|
r.calc()
|
|
|
}
|
|
|
|
|
|
-// 实时敞口数据: Redis数据 + 套保品种信息表
|
|
|
+// GetData 实时敞口数据: Redis数据 + 套保品种信息表
|
|
|
func (r *ErmcpRealExposureModel) GetData() ([]ErmcpRealExposureModel, error) {
|
|
|
// 获取关联的套路商品
|
|
|
if sGoods, err := mtpcache.GetMiddleGoodsByUserID(r.AreaUserID); err == nil {
|
|
|
@@ -113,7 +114,7 @@ func (r *ErmcpRealExposureModel) GetData() ([]ErmcpRealExposureModel, error) {
|
|
|
|
|
|
/*************敞口明细**************/
|
|
|
|
|
|
-//敞口现货明细结构
|
|
|
+// ErmcpExposureDetailModel 敞口现货明细结构
|
|
|
type ErmcpExposureDetailModel struct {
|
|
|
Createtime string `json:"createtime" xorm:"'createtime'"` // 时间
|
|
|
Areauserid uint32 `json:"areauserid" xorm:"'areauserid'"` // 机构ID
|
|
|
@@ -180,7 +181,7 @@ func (r *ErmcpExposureDetailModel) buildSql() string {
|
|
|
return fmt.Sprintf(str, r.MiddlegoodsId, r.Areauserid)
|
|
|
}
|
|
|
|
|
|
-// 处理数据
|
|
|
+// Calc 处理数据
|
|
|
func (r *ErmcpExposureDetailModel) Calc() {
|
|
|
// 销售合同转换为负数
|
|
|
if r.Logtype == 2 && r.Contracttype == -1 {
|
|
|
@@ -195,7 +196,7 @@ func (r *ErmcpExposureDetailModel) Calc() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// 查询敞口现货明细
|
|
|
+// GetData 查询敞口现货明细
|
|
|
func (r *ErmcpExposureDetailModel) GetData() ([]ErmcpExposureDetailModel, error) {
|
|
|
e := db.GetEngine()
|
|
|
s := e.SQL(r.buildSql())
|
|
|
@@ -211,7 +212,7 @@ func (r *ErmcpExposureDetailModel) GetData() ([]ErmcpExposureDetailModel, error)
|
|
|
|
|
|
/// 现货头寸
|
|
|
|
|
|
-// 现货头寸数据
|
|
|
+// AreaSpotModel 现货头寸数据
|
|
|
type AreaSpotModel struct {
|
|
|
WRSTANDARDID int32 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 现货商品ID
|
|
|
WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 现货品种
|
|
|
@@ -232,7 +233,7 @@ type AreaSpotModel struct {
|
|
|
UPDATETIME string `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间
|
|
|
}
|
|
|
|
|
|
-// 进行相关字段的值计算
|
|
|
+// calc 进行相关字段的值计算
|
|
|
func (r *AreaSpotModel) calc() {
|
|
|
r.IncreaseQty = r.SELLPLANQTY + r.BUYPRICEDQTY
|
|
|
r.DecreaseQty = (r.SELLPRICEDQTY + r.BUYPLANQTY) * -1
|
|
|
@@ -261,7 +262,7 @@ func (r *AreaSpotModel) buildSql() string {
|
|
|
return fmt.Sprintf(str, r.AREAUSERID)
|
|
|
}
|
|
|
|
|
|
-// 从数据库中查询现货头寸
|
|
|
+// GetData 从数据库中查询现货头寸
|
|
|
func (r *AreaSpotModel) GetData() ([]AreaSpotModel, error) {
|
|
|
e := db.GetEngine()
|
|
|
sData := make([]AreaSpotModel, 0)
|
|
|
@@ -274,7 +275,7 @@ func (r *AreaSpotModel) GetData() ([]AreaSpotModel, error) {
|
|
|
return sData, nil
|
|
|
}
|
|
|
|
|
|
-// 现货头寸-现货明细
|
|
|
+// ErmcpAreaSpotDetailModel 现货头寸-现货明细
|
|
|
type ErmcpAreaSpotDetailModel struct {
|
|
|
Relatedid string `json:"relatedid" xorm:"'relatedid'"` // 套保计划ID/现货合同ID
|
|
|
Relatedno string `json:"relatedno" xorm:"'relatedno'"` // 编号
|
|
|
@@ -292,7 +293,7 @@ type ErmcpAreaSpotDetailModel struct {
|
|
|
WrstandardId int32 `json:"-"` // 现货商品ID
|
|
|
}
|
|
|
|
|
|
-// 组建查询SQL
|
|
|
+// buildSql 组建查询SQL
|
|
|
func (r *ErmcpAreaSpotDetailModel) buildSql() string {
|
|
|
str := "with tmp as" +
|
|
|
" (select to_char(t.hedgeplanid) relatedid," +
|
|
|
@@ -331,7 +332,7 @@ func (r *ErmcpAreaSpotDetailModel) buildSql() string {
|
|
|
return fmt.Sprintf(str, r.UserId, r.WrstandardId, r.UserId, r.WrstandardId, r.UserId, r.WrstandardId)
|
|
|
}
|
|
|
|
|
|
-// 现货头寸-明细:数据加工处理
|
|
|
+// Calc 现货头寸-明细:数据加工处理
|
|
|
func (r *ErmcpAreaSpotDetailModel) Calc() {
|
|
|
var logTypeName, contractTypeName string
|
|
|
if r.LogType == 1 {
|
|
|
@@ -364,7 +365,7 @@ func (r *ErmcpAreaSpotDetailModel) Calc() {
|
|
|
r.Enumdicname = mtpcache.GetEnumDicitemName(r.Unitid)
|
|
|
}
|
|
|
|
|
|
-// 现货头寸-明细:从数据库中查询敞口现货头寸明细数据
|
|
|
+// GetData 现货头寸-明细:从数据库中查询敞口现货头寸明细数据
|
|
|
func (r *ErmcpAreaSpotDetailModel) GetData() ([]interface{}, error) {
|
|
|
sData := make([]ErmcpAreaSpotDetailModel, 0)
|
|
|
err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
|
|
|
@@ -378,7 +379,7 @@ func (r *ErmcpAreaSpotDetailModel) GetData() ([]interface{}, error) {
|
|
|
|
|
|
///////////////////////////
|
|
|
|
|
|
-/*历史/历史敞口*/
|
|
|
+// ErmcpHisExposure 历史/历史敞口
|
|
|
type ErmcpHisExposure struct {
|
|
|
RECKONDATE string `json:"reckondate" xorm:"'RECKONDATE'"` // 日照时期(yyyyMMdd)
|
|
|
MIDDLEGOODSID int32 `json:"-" xorm:"'MIDDLEGOODSID'"` // 套保品种ID
|
|
|
@@ -392,7 +393,7 @@ type ErmcpHisExposure struct {
|
|
|
LastNum int32 `json:"-"` // 查询条数
|
|
|
}
|
|
|
|
|
|
-// 历史分品种嵌套结构
|
|
|
+// ErmcpHisExposureS 历史分品种嵌套结构
|
|
|
type ErmcpHisExposureS struct {
|
|
|
MIDDLEGOODSID int32 `json:"middlegoodsid"` // 套保品种ID
|
|
|
MIDDLEGOODSNAME string `json:"middlegoodsname"` // 套保品种名称
|
|
|
@@ -427,7 +428,7 @@ func (r *ErmcpHisExposure) buildSql() string {
|
|
|
return fmt.Sprintf(str, r.AREAUSERID, r.LastNum)
|
|
|
}
|
|
|
|
|
|
-// 获取历史敞口
|
|
|
+// GetData 获取历史敞口
|
|
|
func (r *ErmcpHisExposure) GetData() ([]ErmcpHisExposureS, error) {
|
|
|
e := db.GetEngine()
|
|
|
sData := make([]ErmcpHisExposure, 0)
|
|
|
@@ -471,7 +472,7 @@ func (r *ErmcpHisExposure) GetData() ([]ErmcpHisExposureS, error) {
|
|
|
return lst, nil
|
|
|
}
|
|
|
|
|
|
-// 套保品种关联交易商品
|
|
|
+// ErmcpTradeGoods 套保品种关联交易商品
|
|
|
type ErmcpTradeGoods struct {
|
|
|
MIDDLEGOODSID int32 `json:"middlegoodsid" xorm:"'MIDDLEGOODSID'"` // 套保商品id
|
|
|
MIDDLEGOODSNAME string `json:"middlegoodsname" xorm:"'MIDDLEGOODSNAME'"` // 套保商品名称
|
|
|
@@ -513,14 +514,14 @@ func (r *ErmcpTradeGoods) buildSq() string {
|
|
|
return sqlId
|
|
|
}
|
|
|
|
|
|
-// 获取套保商品关联的交易商品
|
|
|
+// GetData 获取套保商品关联的交易商品
|
|
|
func (r *ErmcpTradeGoods) GetData() (map[int32]*ErmcpTradeGoods, error) {
|
|
|
mData := make(map[int32]*ErmcpTradeGoods, 0)
|
|
|
err := db.GetEngine().SQL(r.buildSq()).Find(&mData)
|
|
|
return mData, err
|
|
|
}
|
|
|
|
|
|
-// 获取用户头寸(子账户)
|
|
|
+// ErmcpTradePosition 获取用户头寸(子账户)
|
|
|
type ErmcpTradePosition struct {
|
|
|
USERID int32 `json:"userid" xorm:"'userid'"` // 用户id
|
|
|
GOODSID int32 `json:"goodsid" xorm:"'goodsid'"` // 商品id
|
|
|
@@ -548,14 +549,14 @@ func (r *ErmcpTradePosition) buildSql() string {
|
|
|
return sqlId
|
|
|
}
|
|
|
|
|
|
-// 获取用户持仓头寸(子账户)
|
|
|
+// GetData 获取用户持仓头寸(子账户)
|
|
|
func (r *ErmcpTradePosition) GetData() ([]ErmcpTradePosition, error) {
|
|
|
sData := make([]ErmcpTradePosition, 0)
|
|
|
err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
|
|
|
return sData, err
|
|
|
}
|
|
|
|
|
|
-// 用户头寸(母账户)
|
|
|
+// ErmcpHedgePosition 用户头寸(母账户)
|
|
|
type ErmcpHedgePosition struct {
|
|
|
RELATEDUSERID int32 `json:"relateduserid" xorm:"'RELATEDUSERID'"` // 关联用户id
|
|
|
ACCOUNTID int64 `json:"accountid" xorm:"'ACCOUNTID'"` // 资金账号[外部母账户]
|
|
|
@@ -585,6 +586,7 @@ type ErmcpHedgePosition struct {
|
|
|
DecreaseQty int32 `json:"decreaseqty"` // 减少数量 = (期末卖头寸 - 期初卖头寸)*-1
|
|
|
}
|
|
|
|
|
|
+// Calc 计算母账号头寸相关数据
|
|
|
func (r *ErmcpHedgePosition) Calc() {
|
|
|
r.TotalYdQty = r.YDBUYPOSITION - r.YDSELLPOSITION
|
|
|
r.TotalCurQty = r.CURBUYPOSITION - r.CURSELLPOSITION
|
|
|
@@ -625,7 +627,7 @@ func (r *ErmcpHedgePosition) buildSql() string {
|
|
|
return sqlId
|
|
|
}
|
|
|
|
|
|
-// 获取对冲头寸(母账号头寸)
|
|
|
+// GetData 获取对冲头寸(母账号头寸)
|
|
|
func (r *ErmcpHedgePosition) GetData() ([]ErmcpHedgePosition, error) {
|
|
|
sData := make([]ErmcpHedgePosition, 0)
|
|
|
err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
|
|
|
@@ -635,7 +637,7 @@ func (r *ErmcpHedgePosition) GetData() ([]ErmcpHedgePosition, error) {
|
|
|
return sData, err
|
|
|
}
|
|
|
|
|
|
-// 实时敞口\期货明细(头寸)
|
|
|
+// ErmcpExposurePostion 实时敞口\期货明细(头寸)
|
|
|
type ErmcpExposurePostion struct {
|
|
|
AREAUSERID int32 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构id
|
|
|
MIDDLEGOODSID int32 `json:"middlegoodsid" xorm:"'MIDDLEGOODSID'"` // 套保商品id
|
|
|
@@ -650,7 +652,7 @@ type ErmcpExposurePostion struct {
|
|
|
CONVERTRATIO float64 `json:"convertratio"` // 期货品种系数(折算系数)
|
|
|
}
|
|
|
|
|
|
-// 子账户相关计算(不一定用得到,现在说都是查母账号的)
|
|
|
+// ParseFromPos 子账户相关计算(不一定用得到,现在说都是查母账号的)
|
|
|
func (r *ErmcpExposurePostion) ParseFromPos(val *ErmcpTradeGoods, data *ErmcpTradePosition) {
|
|
|
r.AREAUSERID = val.AREAUSERID
|
|
|
r.MIDDLEGOODSID = val.MIDDLEGOODSID
|
|
|
@@ -668,7 +670,7 @@ func (r *ErmcpExposurePostion) ParseFromPos(val *ErmcpTradeGoods, data *ErmcpTra
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// 母账户相关计算
|
|
|
+// ParseFromHedgePos 母账户相关计算
|
|
|
func (r *ErmcpExposurePostion) ParseFromHedgePos(val *ErmcpTradeGoods, data *ErmcpHedgePosition) {
|
|
|
r.AREAUSERID = val.AREAUSERID
|
|
|
r.MIDDLEGOODSID = val.MIDDLEGOODSID
|
|
|
@@ -686,7 +688,7 @@ func (r *ErmcpExposurePostion) ParseFromHedgePos(val *ErmcpTradeGoods, data *Erm
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// 获取敞口明细期货头寸
|
|
|
+// GetDataEx 获取敞口明细期货头寸
|
|
|
func (r *ErmcpExposurePostion) GetDataEx() (interface{}, error) {
|
|
|
sData := make([]ErmcpExposurePostion, 0)
|
|
|
// 查询交易商品
|
|
|
@@ -714,7 +716,7 @@ func (r *ErmcpExposurePostion) GetDataEx() (interface{}, error) {
|
|
|
return sData, nil
|
|
|
}
|
|
|
|
|
|
-// 敞口/期货头寸/期货明细
|
|
|
+// ErmcpHedgePositionDetail 敞口/期货头寸/期货明细
|
|
|
type ErmcpHedgePositionDetail struct {
|
|
|
HEDGEGOODSID int32 `json:"hedgegoodsid" xorm:"'HEDGEGOODSID'"` // 商品id
|
|
|
BUYORSELL int32 `json:"buyorsell" xorm:"'BUYORSELL'"` // 买卖方向 0-买 1-卖
|
|
|
@@ -726,6 +728,7 @@ type ErmcpHedgePositionDetail struct {
|
|
|
AREAUSERID int32 `json:"-"` // 所属机构id
|
|
|
}
|
|
|
|
|
|
+// Calc 计算期货明细相关数据
|
|
|
func (r *ErmcpHedgePositionDetail) Calc() {
|
|
|
if r.BUYORSELL == 1 && r.TRADEQTY > 0 {
|
|
|
r.TRADEQTY = r.TRADEQTY * -1
|
|
|
@@ -769,7 +772,7 @@ func (r *ErmcpHedgePositionDetail) buildSql() string {
|
|
|
return sqlId
|
|
|
}
|
|
|
|
|
|
-// 获取持仓头寸明细(成交记录)
|
|
|
+// GetDataEx 获取持仓头寸明细(成交记录)
|
|
|
func (r *ErmcpHedgePositionDetail) GetDataEx() (interface{}, error) {
|
|
|
sData := make([]ErmcpHedgePositionDetail, 0)
|
|
|
err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
|