|
|
@@ -111,7 +111,7 @@ func (r *ErmcpRealExposureModel) GetData() ([]ErmcpRealExposureModel, error) {
|
|
|
|
|
|
/*************敞口明细**************/
|
|
|
|
|
|
-//敞口明细结构
|
|
|
+//敞口现货明细结构
|
|
|
type ErmcpExposureDetailModel struct {
|
|
|
Createtime string `json:"createtime" xorm:"'createtime'"` // 时间
|
|
|
Areauserid uint32 `json:"areauserid" xorm:"'areauserid'"` // 机构ID
|
|
|
@@ -136,10 +136,11 @@ func (r *ErmcpExposureDetailModel) buildSql() string {
|
|
|
str := "with tmp as" +
|
|
|
" (select 2 as LogType," +
|
|
|
" s.spotcontractid as relatedid," +
|
|
|
- " s.contractno as relateNo" +
|
|
|
+ " s.contractno as relateNo," +
|
|
|
+ " s.qty " +
|
|
|
" from ermcp_spotcontract s" +
|
|
|
" union all" +
|
|
|
- " select 1, t.hedgeplanid as relateid, t.hedgeplanno as relateNo" +
|
|
|
+ " select 1, t.hedgeplanid as relateid, t.hedgeplanno as relateNo, t.planqty as qty " +
|
|
|
" from ermcp_hedgeplan t)" +
|
|
|
"select to_char(t.createtime, 'yyyy-mm-dd hh24:mi:ss') createtime," +
|
|
|
" t.middlegoodsid," +
|
|
|
@@ -147,10 +148,10 @@ func (r *ErmcpExposureDetailModel) buildSql() string {
|
|
|
" t.logtype," +
|
|
|
" t.contracttype," +
|
|
|
" wc.wrstandardid," +
|
|
|
- " t.qty," +
|
|
|
+ " tmp.qty," +
|
|
|
" t.convertfactor," +
|
|
|
" t.convertratio," +
|
|
|
- " t.qty * t.convertfactor * t.convertratio as changeQty," +
|
|
|
+ " t.qty changeQty," +
|
|
|
" tmp.relateNo," +
|
|
|
" m.middlegoodsname," +
|
|
|
" m.middlegoodscode," +
|
|
|
@@ -177,6 +178,21 @@ func (r *ErmcpExposureDetailModel) buildSql() string {
|
|
|
return fmt.Sprintf(str, r.MiddlegoodsId, r.Areauserid)
|
|
|
}
|
|
|
|
|
|
+// 处理数据
|
|
|
+func (r *ErmcpExposureDetailModel) Calc() {
|
|
|
+ // 销售合同转换为负数
|
|
|
+ if r.Logtype == 2 && r.Contracttype == -1 {
|
|
|
+ r.ChangeQty *= -1
|
|
|
+ r.Qty *= -1
|
|
|
+ }
|
|
|
+
|
|
|
+ // 采购计划 转换为负数
|
|
|
+ if r.Logtype == 1 && r.Contracttype == 1 {
|
|
|
+ r.ChangeQty *= -1
|
|
|
+ r.Qty *= -1
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
// 查询敞口现货明细
|
|
|
func (r *ErmcpExposureDetailModel) GetData() ([]ErmcpExposureDetailModel, error) {
|
|
|
e := db.GetEngine()
|
|
|
@@ -185,6 +201,9 @@ func (r *ErmcpExposureDetailModel) GetData() ([]ErmcpExposureDetailModel, error)
|
|
|
if err := s.Find(&sData); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
+ for i := range sData {
|
|
|
+ sData[i].Calc()
|
|
|
+ }
|
|
|
return sData, nil
|
|
|
}
|
|
|
|
|
|
@@ -273,37 +292,41 @@ type ErmcpAreaSpotDetailModel struct {
|
|
|
|
|
|
// 组建查询SQL
|
|
|
func (r *ErmcpAreaSpotDetailModel) buildSql() string {
|
|
|
- str := "select to_char(t.hedgeplanid) relatedid," +
|
|
|
- " t.hedgeplanno relatedno," +
|
|
|
- " 1 as logType," +
|
|
|
- " t.contracttype," +
|
|
|
- " w.wrstandardname," +
|
|
|
- " w.wrstandardcode," +
|
|
|
- " t.planqty qty," +
|
|
|
- " w.unitid," +
|
|
|
- " to_char(t.createtime, 'yyyy-mm-dd hh:mi:ss') createtime" +
|
|
|
- " from ermcp_hedgeplan t" +
|
|
|
- " left join wrstandard w" +
|
|
|
- " on t.wrstandardid = w.wrstandardid" +
|
|
|
- " where t.hedgeplanstatus in (2, 3, 5)" +
|
|
|
- " and t.areauserid = %v and t.wrstandardid = %v" +
|
|
|
- " union all " +
|
|
|
- "select to_char(t.spotcontractid)," +
|
|
|
- " t.contractno," +
|
|
|
- " 1 as logType," +
|
|
|
- " t.contracttype," +
|
|
|
+ str := "with tmp as" +
|
|
|
+ " (select to_char(t.hedgeplanid) relatedid," +
|
|
|
+ " t.hedgeplanno relatedno," +
|
|
|
+ " 1 as logType," +
|
|
|
+ " t.contracttype" +
|
|
|
+ " from ermcp_hedgeplan t" +
|
|
|
+ " where t.areauserid = %v" +
|
|
|
+ " and t.wrstandardid = %v" +
|
|
|
+ " union all " +
|
|
|
+ " select to_char(t.spotcontractid)," +
|
|
|
+ " t.contractno," +
|
|
|
+ " 2 as logType," +
|
|
|
+ " t.contracttype" +
|
|
|
+ " from ermcp_spotcontract t" +
|
|
|
+ " where t.userid = %v" +
|
|
|
+ " and t.wrstandardid = %v)" +
|
|
|
+ "select t.relatedid," +
|
|
|
+ " tmp.relatedno," +
|
|
|
+ " t.LogType," +
|
|
|
+ " tmp.contracttype," +
|
|
|
+ " t.RealQty qty," +
|
|
|
+ " to_char(t.createtime, 'yyyy-mm-dd hh:mi:ss') createtime," +
|
|
|
" w.wrstandardname," +
|
|
|
" w.wrstandardcode," +
|
|
|
- " t.qty," +
|
|
|
- " w.unitid," +
|
|
|
- " to_char(t.createtime, 'yyyy-mm-dd hh:mi:ss') createtime" +
|
|
|
- " from ermcp_spotcontract t" +
|
|
|
+ " w.unitid" +
|
|
|
+ " from ermcp_spotlog t" +
|
|
|
+ " inner join tmp" +
|
|
|
+ " on t.LogType = tmp.logType" +
|
|
|
+ " and t.relatedid = tmp.relatedid" +
|
|
|
+ " and t.areauserid = %v" +
|
|
|
+ " and t.wrstandardid = %v" +
|
|
|
" left join wrstandard w" +
|
|
|
- " on t.wrstandardid = w.wrstandardid" +
|
|
|
- " where t.contractstatus in (2, 3, 5)" +
|
|
|
- " and t.userid = %v and t.wrstandardid = %v"
|
|
|
+ " on t.wrstandardid = w.wrstandardid"
|
|
|
|
|
|
- return fmt.Sprintf(str, r.UserId, r.WrstandardId, r.UserId, r.WrstandardId)
|
|
|
+ return fmt.Sprintf(str, r.UserId, r.WrstandardId, r.UserId, r.WrstandardId, r.UserId, r.WrstandardId)
|
|
|
}
|
|
|
|
|
|
// 现货头寸-明细:数据加工处理
|
|
|
@@ -319,8 +342,18 @@ func (r *ErmcpAreaSpotDetailModel) Calc() {
|
|
|
contractTypeName = "采购"
|
|
|
} else {
|
|
|
contractTypeName = "销售"
|
|
|
+ }
|
|
|
+
|
|
|
+ // 销售合同 数量转为负数
|
|
|
+ if r.LogType == 2 && r.Contracttype == -1 {
|
|
|
+ if r.Qty > 0 {
|
|
|
+ r.Qty = r.Qty * -1
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 采购计划 数量转为负数
|
|
|
+ if r.LogType == 1 && r.Contracttype == 1 {
|
|
|
if r.Qty > 0 {
|
|
|
- // 销售的数量转为负数
|
|
|
r.Qty = r.Qty * -1
|
|
|
}
|
|
|
}
|
|
|
@@ -561,6 +594,9 @@ func (r *ErmcpHedgePosition) buildSql() string {
|
|
|
func (r *ErmcpHedgePosition) GetData() ([]ErmcpHedgePosition, error) {
|
|
|
sData := make([]ErmcpHedgePosition, 0)
|
|
|
err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
|
|
|
+ for i := range sData {
|
|
|
+ sData[i].Calc()
|
|
|
+ }
|
|
|
return sData, err
|
|
|
}
|
|
|
|
|
|
@@ -592,7 +628,7 @@ func (r *ErmcpExposurePostion) ParseFromPos(val *ErmcpTradeGoods, data *ErmcpTra
|
|
|
r.DiffQty = r.CurQty - r.YdQty
|
|
|
r.DiffHedgeQty = float64(r.DiffQty) * float64(val.AGREEUNIT) * val.CONVERTRATIO
|
|
|
r.CONVERTRATIO = val.CONVERTRATIO
|
|
|
- if strName := mtpcache.GetEnumDicitemName(val.GOODSUNITID); len(strName) > 0{
|
|
|
+ if strName := mtpcache.GetEnumDicitemName(val.GOODSUNITID); len(strName) > 0 {
|
|
|
r.AGREEUNIT = fmt.Sprintf("%v%v/手", val.AGREEUNIT, strName)
|
|
|
}
|
|
|
}
|
|
|
@@ -610,7 +646,7 @@ func (r *ErmcpExposurePostion) ParseFromHedgePos(val *ErmcpTradeGoods, data *Erm
|
|
|
r.DiffQty = r.CurQty - r.YdQty
|
|
|
r.DiffHedgeQty = float64(r.DiffQty) * float64(val.AGREEUNIT) * val.CONVERTRATIO
|
|
|
r.CONVERTRATIO = val.CONVERTRATIO
|
|
|
- if strName := mtpcache.GetEnumDicitemName(val.GOODSUNITID); len(strName) > 0{
|
|
|
+ if strName := mtpcache.GetEnumDicitemName(val.GOODSUNITID); len(strName) > 0 {
|
|
|
r.AGREEUNIT = fmt.Sprintf("%v%v/手", val.AGREEUNIT, strName)
|
|
|
}
|
|
|
}
|