|
|
@@ -81,13 +81,14 @@ func (r *ErmcpDeliveryGoods) GetData() ([]ErmcpDeliveryGoods, error) {
|
|
|
|
|
|
// ErmcpDGFactoryItem 品种选择项定义表
|
|
|
type ErmcpDGFactoryItem struct {
|
|
|
- DGFACTORYITEMID int64 // 选择项ID(SEQ_DGFACTORYITEM)
|
|
|
- DELIVERYGOODSID int32 // 品种ID
|
|
|
- DGFACTORYITEMTYPEID int64 // 要素项类型
|
|
|
- DGFACTORYITEMVALUE string // 要素项值(类型为仓库时填写仓库名称)
|
|
|
- WAREHOUSEID int64 // 仓库ID(类型为仓库时填写)
|
|
|
- ISVALID int32 // 是否有效 - 0:无效 1:有效
|
|
|
- ORDERINDEX int32 // 顺序
|
|
|
+ DGFACTORYITEMID int64 `json:"dgfactoryitemid" xorm:"'DGFACTORYITEMID'"` // 选择项ID(SEQ_DGFACTORYITEM)
|
|
|
+ DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种ID
|
|
|
+ DGFACTORYITEMTYPEID int64 `json:"dgfactoryitemtypeid" xorm:"'DGFACTORYITEMTYPEID'"` // 要素项类型
|
|
|
+ DGFACTORYITEMVALUE string `json:"dgfactoryitemvalue" xorm:"'DGFACTORYITEMVALUE'"` // 要素项值(类型为仓库时填写仓库名称)
|
|
|
+ WAREHOUSEID int64 `json:"warehouseid" xorm:"'WAREHOUSEID'"` // 仓库ID(类型为仓库时填写)
|
|
|
+ ISVALID int32 `json:"isvalid" xorm:"'ISVALID'"` // 是否有效 - 0:无效 1:有效
|
|
|
+ ORDERINDEX int32 `json:"orderindex" xorm:"'ORDERINDEX'"` // 顺序
|
|
|
+ AREAUSERID int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 用户id
|
|
|
}
|
|
|
|
|
|
func (r *ErmcpDGFactoryItem) buildSql() string {
|
|
|
@@ -97,9 +98,13 @@ func (r *ErmcpDGFactoryItem) buildSql() string {
|
|
|
" t.DGFACTORYITEMVALUE," +
|
|
|
" to_char(t.WAREHOUSEID) WAREHOUSEID," +
|
|
|
" t.ISVALID," +
|
|
|
- " t.ORDERINDEX" +
|
|
|
+ " t.ORDERINDEX," +
|
|
|
+ " g.areauserid" +
|
|
|
" FROM DGFACTORYITEM t" +
|
|
|
- " WHERE ISVALID = 1"
|
|
|
+ " left join deliverygoods g" +
|
|
|
+ " on t.deliverygoodsid = g.deliverygoodsid" +
|
|
|
+ " WHERE t.ISVALID = 1"
|
|
|
+ sqlId.AndEx("g.areauserid", r.AREAUSERID, r.AREAUSERID > 0)
|
|
|
sqlId.AndEx("t.DGFACTORYITEMID", r.DGFACTORYITEMID, r.DGFACTORYITEMID > 0)
|
|
|
sqlId.AndEx("t.DELIVERYGOODSID", r.DELIVERYGOODSID, r.DELIVERYGOODSID > 0)
|
|
|
sqlId.AndEx("t.DGFACTORYITEMTYPEID", r.DGFACTORYITEMTYPEID, r.DGFACTORYITEMTYPEID > 0)
|
|
|
@@ -120,25 +125,31 @@ func (r *ErmcpDGFactoryItem) GetData() (interface{}, error) {
|
|
|
return sData, err
|
|
|
}
|
|
|
|
|
|
-// ErmcpBrand 品牌(从品种选择项定义表中查)
|
|
|
-type ErmcpBrand struct {
|
|
|
+// Ermcp3Brand 品牌(从品种选择项定义表中查)
|
|
|
+type Ermcp3Brand struct {
|
|
|
BRANDID int64 `json:"brandid"` // 品牌id
|
|
|
BRANDNAME string `json:"brandname"` // 品牌名称
|
|
|
DELIVERYGOODSID int32 `json:"deliverygoodsid"` // 品种ID
|
|
|
+ AREAUSERID int64 `json:"areauserid"` // 用户id
|
|
|
}
|
|
|
|
|
|
-// 获取品牌数据
|
|
|
-func (r *ErmcpBrand) GetData() ([]ErmcpBrand, error) {
|
|
|
+// GetDataEx
|
|
|
+func (r *Ermcp3Brand) GetDataEx() (interface{}, error) {
|
|
|
+ return r.GetData()
|
|
|
+}
|
|
|
+
|
|
|
+// GetData 获取品牌数据
|
|
|
+func (r *Ermcp3Brand) GetData() ([]Ermcp3Brand, error) {
|
|
|
m := ErmcpDGFactoryItem{
|
|
|
DELIVERYGOODSID: r.DELIVERYGOODSID,
|
|
|
DGFACTORYITEMTYPEID: 2,
|
|
|
ORDERINDEX: 1,
|
|
|
}
|
|
|
- sData := make([]ErmcpBrand, 0)
|
|
|
+ sData := make([]Ermcp3Brand, 0)
|
|
|
if d, err := m.GetDataEx(); err == nil {
|
|
|
if dgLst, ok := d.([]ErmcpDGFactoryItem); ok {
|
|
|
for _, val := range dgLst {
|
|
|
- sData = append(sData, ErmcpBrand{BRANDID: val.DGFACTORYITEMID,
|
|
|
+ sData = append(sData, Ermcp3Brand{BRANDID: val.DGFACTORYITEMID, AREAUSERID: val.AREAUSERID,
|
|
|
BRANDNAME: val.DGFACTORYITEMVALUE, DELIVERYGOODSID: val.DELIVERYGOODSID})
|
|
|
}
|
|
|
}
|
|
|
@@ -189,7 +200,7 @@ func (r *ErmcpRelatedGoods) GetData() ([]ErmcpRelatedGoods, error) {
|
|
|
type ErmcpDeliveryGoodsDetail struct {
|
|
|
Data ErmcpDeliveryGoods `json:"data"` // 现货商品基本信息(交割品种)
|
|
|
GmList []ErmcpWrstandard `json:"gmlist"` // 品类列表(仓单标准)
|
|
|
- GbList []ErmcpBrand `json:"gblist"` // 品牌列表
|
|
|
+ GbList []Ermcp3Brand `json:"gblist"` // 品牌列表
|
|
|
WrsList []WRSConverTDetail `json:"wrslist"` // 套保信息列表
|
|
|
GoodsList []ErmcpRelatedGoods `json:"goodslist"` // 关联交易商品列表
|
|
|
|
|
|
@@ -204,7 +215,7 @@ func (r *ErmcpDeliveryGoodsDetail) addGmList(lst []ErmcpWrstandard) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func (r *ErmcpDeliveryGoodsDetail) addGbList(lst []ErmcpBrand) {
|
|
|
+func (r *ErmcpDeliveryGoodsDetail) addGbList(lst []Ermcp3Brand) {
|
|
|
for i := range lst {
|
|
|
if lst[i].DELIVERYGOODSID == r.Data.DELIVERYGOODSID {
|
|
|
r.GbList = append(r.GbList, lst[i])
|
|
|
@@ -242,14 +253,14 @@ func (r *ErmcpDeliveryGoodsDetail) GetDataEx() (interface{}, error) {
|
|
|
// 基本信息
|
|
|
for i := range data {
|
|
|
val := ErmcpDeliveryGoodsDetail{Data: data[i],
|
|
|
- GmList: make([]ErmcpWrstandard, 0), GbList: make([]ErmcpBrand, 0),
|
|
|
+ GmList: make([]ErmcpWrstandard, 0), GbList: make([]Ermcp3Brand, 0),
|
|
|
WrsList: make([]WRSConverTDetail, 0), GoodsList: make([]ErmcpRelatedGoods, 0),
|
|
|
}
|
|
|
sData = append(sData, val)
|
|
|
}
|
|
|
//品类/品牌/套保信息
|
|
|
gm := ErmcpWrstandard{AREAUSERID: int(r.Data.AREAUSERID), DELIVERYGOODSID: r.Data.DELIVERYGOODSID, ISVALID: 1}
|
|
|
- gb := ErmcpBrand{DELIVERYGOODSID: r.Data.DELIVERYGOODSID}
|
|
|
+ gb := Ermcp3Brand{DELIVERYGOODSID: r.Data.DELIVERYGOODSID}
|
|
|
WrsC := WRSConverTDetail{DELIVERYGOODSID: r.Data.DELIVERYGOODSID}
|
|
|
gmLst, _ := gm.GetData()
|
|
|
gbLst, _ := gb.GetData()
|
|
|
@@ -314,6 +325,17 @@ type Ermcp3Contract struct {
|
|
|
BRANDNAME string `json:"brandname" xorm:"'brandname'"` // 品牌名称
|
|
|
ATTACHMENT string `json:"attachment" xorm:"'ATTACHMENT'"` // 附件
|
|
|
UNITID int32 `json:"unitid" xorm:"'UNITID'"` // 单位id(取品类上的单位id)
|
|
|
+ TRADEUSERID int64 `json:"tradeuserid" xorm:"'TRADEUSERID'"` // 交易员id
|
|
|
+ SALEUSERID int64 `json:"saleuserid" xorm:"'SALEUSERID'"` // 销售员id
|
|
|
+ MERUSERID int64 `json:"meruserid" xorm:"'MERUSERID'"` // 业务员id
|
|
|
+ ACCOUNTID string `json:"accountid" xorm:"'ACCOUNTID'"` // 期货账户id
|
|
|
+ BIZTYPE int32 `json:"biztype" xorm:"'BIZTYPE'"` // 业务类型 1-套保 2-套利
|
|
|
+
|
|
|
+ SELLNICKNAME string `json:"sellnickname"` // 采购方昵称
|
|
|
+ BUYNICKNAME string `json:"buynickname"` // 销售方昵称
|
|
|
+ TRADEUSERLOGINCODE string `json:"tradeuserlogincode"` // 交易员登录代码
|
|
|
+ SALEUSERLOGINCODE string `json:"saleuserlogincode"` // 销售员登录代码
|
|
|
+ MERUSERLOGINCODE string `json:"meruserlogincode"` // 业务员登录代码
|
|
|
|
|
|
// 筛选条件
|
|
|
QryType int32 `json:"-"` // 查询类型 1-未提交 2-待审核 3-履约中 4-已完成
|
|
|
@@ -337,9 +359,12 @@ func (r *Ermcp3Contract) getQryTypeStatus() string {
|
|
|
}
|
|
|
|
|
|
func (r *Ermcp3Contract) calc() {
|
|
|
- r.BUYUSERName = mtpcache.GetUserNameByUserId(r.BUYUSERID)
|
|
|
- r.SELLUSERNAME = mtpcache.GetUserNameByUserId(r.SELLUSERID)
|
|
|
+ r.BUYUSERName, r.BUYNICKNAME = mtpcache.GetUserNameAndNickName(r.BUYUSERID)
|
|
|
+ r.SELLUSERNAME, r.SELLNICKNAME = mtpcache.GetUserNameAndNickName(r.SELLUSERID)
|
|
|
r.EnumdicName = mtpcache.GetEnumDicitemName(r.UNITID)
|
|
|
+ r.TRADEUSERLOGINCODE = mtpcache.GetLoginCodeByUserId(r.TRADEUSERID)
|
|
|
+ r.SALEUSERLOGINCODE = mtpcache.GetLoginCodeByUserId(r.SALEUSERID)
|
|
|
+ r.MERUSERLOGINCODE = mtpcache.GetLoginCodeByUserId(r.MERUSERID)
|
|
|
}
|
|
|
|
|
|
func (r *Ermcp3Contract) buildSql() string {
|
|
|
@@ -381,7 +406,12 @@ func (r *Ermcp3Contract) buildSql() string {
|
|
|
" gb.dgfactoryitemvalue brandname," +
|
|
|
" w.wrstandardname," +
|
|
|
" w.wrstandardcode," +
|
|
|
- " w.unitid" +
|
|
|
+ " w.unitid," +
|
|
|
+ " t.tradeuserid," +
|
|
|
+ " t.saleuserid," +
|
|
|
+ " t.meruserid," +
|
|
|
+ " to_char(t.accountid) accountid," +
|
|
|
+ " t.biztype" +
|
|
|
" FROM ERMCP_SPOTCONTRACT t" +
|
|
|
" left join deliverygoods g" +
|
|
|
" on t.deliverygoodsid = g.deliverygoodsid" +
|
|
|
@@ -569,6 +599,7 @@ func (r *Ermcp3SellBuyContract) buildSql() string {
|
|
|
" and e.enumdiccode = 'goodsunit'" +
|
|
|
" where 1 = 1"
|
|
|
sqlId.AndEx("t.userid", r.UserID, r.UserID > 0)
|
|
|
+ sqlId.AndEx("t.contracttype", r.Contracttype, r.Contracttype != 0)
|
|
|
sqlId.AndEx("t.SpotContractId", r.SpotContractId, len(r.SpotContractId) > 0)
|
|
|
if r.UserType == 7 {
|
|
|
// 企业成员
|
|
|
@@ -591,3 +622,341 @@ func (r *Ermcp3SellBuyContract) GetDataEx() (interface{}, error) {
|
|
|
}
|
|
|
return sData, err
|
|
|
}
|
|
|
+
|
|
|
+// Ermcp3ExposureDetail 敞口现货明细
|
|
|
+type Ermcp3ExposureDetail struct {
|
|
|
+ Createtime string `json:"createtime" xorm:"'createtime'"` // 时间
|
|
|
+ Areauserid int64 `json:"areauserid" xorm:"'areauserid'"` // 机构ID
|
|
|
+ Logtype int32 `json:"logtype" xorm:"'logtype'"` // 类型 - 1:套保计划 2:现货合同
|
|
|
+ Contracttype int32 `json:"contracttype" xorm:"'contracttype'"` // 现货合同类型 - 1:采购 -1:销售
|
|
|
+ Qty float64 `json:"qty" xorm:"'qty'"` // 数量
|
|
|
+ RelateNo string `json:"relateNo" xorm:"'relateNo'"` // 现货合同/套保计划编号
|
|
|
+ Middlegoodsname string `json:"middlegoodsname" xorm:"'middlegoodsname'"` // 套保商品名称
|
|
|
+ Middlegoodscode string `json:"middlegoodscode" xorm:"'middlegoodscode'"` // 套保商品代码
|
|
|
+ MiddlegoodsId int32 `json:"middlegoodsId" xorm:"'middlegoodsId'"` // 套保商品id
|
|
|
+ Unitid int32 `json:"-" xorm:"'unitid'"` // 现货商品单位ID
|
|
|
+ Enumdicname string `json:"enumdicname" xorm:"'enumdicname'"` // 现货商品单位名称
|
|
|
+ ChangeQty float64 `json:"changeQty" xorm:"'changeQty'"` // 套保变动量
|
|
|
+ Convertfactor float64 `json:"convertfactor" xorm:"'convertfactor'"` // 标仓系数
|
|
|
+ Convertratio float64 `json:"convertratio" xorm:"'convertratio'"` // 套保系数
|
|
|
+ DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种id
|
|
|
+ DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码
|
|
|
+ DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 现货品种名称
|
|
|
+}
|
|
|
+
|
|
|
+func (r *Ermcp3ExposureDetail) 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 *Ermcp3ExposureDetail) buildSql() string {
|
|
|
+ var sqlId utils.SQLVal = "with tmp as" +
|
|
|
+ " (select 2 as LogType," +
|
|
|
+ " s.spotcontractid as relatedid," +
|
|
|
+ " s.contractno as relateNo," +
|
|
|
+ " s.qty" +
|
|
|
+ " from ermcp_spotcontract s" +
|
|
|
+ " union all" +
|
|
|
+ " 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," +
|
|
|
+ " t.areauserid," +
|
|
|
+ " t.logtype," +
|
|
|
+ " t.contracttype," +
|
|
|
+ " t.qty / t.convertfactor / t.convertratio as qty," +
|
|
|
+ " t.convertfactor," +
|
|
|
+ " t.convertratio," +
|
|
|
+ " t.qty changeQty," +
|
|
|
+ " tmp.relateNo," +
|
|
|
+ " m.middlegoodsname," +
|
|
|
+ " m.middlegoodscode," +
|
|
|
+ " g.deliverygoodsid," +
|
|
|
+ " g.deliverygoodscode," +
|
|
|
+ " g.deliverygoodsname," +
|
|
|
+ " g.goodsunitid unitid," +
|
|
|
+ " e.enumdicname" +
|
|
|
+ " from ermcp_spotexposurelog t" +
|
|
|
+ " left join erms_middlegoods m" +
|
|
|
+ " on t.middlegoodsid = m.middlegoodsid" +
|
|
|
+ " left join deliverygoods g" +
|
|
|
+ " on t.deliverygoodsid = g.deliverygoodsid" +
|
|
|
+ " left join enumdicitem e" +
|
|
|
+ " on g.goodsunitid = e.enumitemname" +
|
|
|
+ " and e.enumdiccode = 'goodsunit'" +
|
|
|
+ " left join tmp" +
|
|
|
+ " on t.logtype = tmp.LogType" +
|
|
|
+ " and t.relatedid = tmp.relatedid" +
|
|
|
+ " where 1=1 and t.tradedate=to_char(sysdate, 'yyyymmdd')"
|
|
|
+ sqlId.And("t.areauserid", r.Areauserid)
|
|
|
+ sqlId.And("t.middlegoodsid", r.MiddlegoodsId)
|
|
|
+ return sqlId.String()
|
|
|
+}
|
|
|
+
|
|
|
+// GetDataEx
|
|
|
+func (r *Ermcp3ExposureDetail) GetDataEx() (interface{}, error) {
|
|
|
+ e := db.GetEngine()
|
|
|
+ s := e.SQL(r.buildSql())
|
|
|
+ sData := make([]Ermcp3ExposureDetail, 0)
|
|
|
+ if err := s.Find(&sData); err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ for i := range sData {
|
|
|
+ sData[i].calc()
|
|
|
+ }
|
|
|
+ return sData, nil
|
|
|
+}
|
|
|
+
|
|
|
+// Ermcp3AreaSpot 敞口现货头寸
|
|
|
+type Ermcp3AreaSpot struct {
|
|
|
+ AREAUSERID int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构
|
|
|
+ ORIBUYPLANQTY float64 `json:"-" xorm:"'ORIBUYPLANQTY'"` // 期初采购计划数量
|
|
|
+ ORIBUYPRICEDQTY float64 `json:"-" xorm:"'ORIBUYPRICEDQTY'"` // 期初采购合同已定价数量
|
|
|
+ ORISELLPLANQTY float64 `json:"-" xorm:"'ORISELLPLANQTY'"` // 期初销售计划数量
|
|
|
+ ORISELLPRICEDQTY float64 `json:"-" xorm:"'ORISELLPRICEDQTY'"` // 期初销售合同已定价数量
|
|
|
+ BUYPLANQTY float64 `json:"-" xorm:"'BUYPLANQTY'"` // 采购计划数量
|
|
|
+ BUYPRICEDQTY float64 `json:"-" xorm:"'BUYPRICEDQTY'"` // 采购合同已定价数量
|
|
|
+ SELLPLANQTY float64 `json:"-" xorm:"'SELLPLANQTY'"` // 销售计划数量
|
|
|
+ SELLPRICEDQTY float64 `json:"-" xorm:"'SELLPRICEDQTY'"` // 销售合同已定价数量
|
|
|
+ TOTALSPOTQTY float64 `json:"totalspotqty" xorm:"'TOTALSPOTQTY'"` // 当前数量(现货头寸总量) = (销售计划数量 - 销售已定价数量) - (采购计划数量 - 采购已定价数量)
|
|
|
+ OriToalSpotQty float64 `json:"oritoalspotqty" xorm:"'OriToalSpotQty'"` // 昨日数量
|
|
|
+ IncreaseQty float64 `json:"increaseqty" xorm:"'IncreaseQty'"` // 增加数量=销售计划数量+采购已定价数量
|
|
|
+ DecreaseQty float64 `json:"decreaseqty" xorm:"'DecreaseQty'"` // 减少数量=-(销售已定价数量+采购计划数量)
|
|
|
+ UPDATETIME string `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间
|
|
|
+ DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种id
|
|
|
+ DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码
|
|
|
+ DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 现货品种名称
|
|
|
+}
|
|
|
+
|
|
|
+func (r *Ermcp3AreaSpot) calc() {
|
|
|
+ /*
|
|
|
+ 增加数量=今日销售计划数量+今日采购已定价数量
|
|
|
+ 减少数量=-(今日销售已定价数量+今日采购计划数量)
|
|
|
+
|
|
|
+ 其中,
|
|
|
+ 今日销售计划数量=期末销售计划数量-期初销售计划数量
|
|
|
+ 今日采购已定价数量=期末采购已定价数量-期初采购已定价数量
|
|
|
+ 今日销售已定价数量=期末销售已定价数量-期初销售已定价数量
|
|
|
+ 今日采购计划数量=期末采购计划数量-期初采购计划数量
|
|
|
+ */
|
|
|
+ r.IncreaseQty = r.SELLPLANQTY - r.ORISELLPLANQTY + r.BUYPRICEDQTY - r.ORIBUYPRICEDQTY
|
|
|
+ r.DecreaseQty = (r.SELLPRICEDQTY - r.ORISELLPRICEDQTY + r.BUYPLANQTY - r.ORIBUYPLANQTY) * -1
|
|
|
+ r.OriToalSpotQty = (r.ORISELLPLANQTY - r.ORISELLPRICEDQTY) - (r.ORIBUYPLANQTY - r.ORIBUYPRICEDQTY)
|
|
|
+}
|
|
|
+
|
|
|
+func (r *Ermcp3AreaSpot) buildSql() string {
|
|
|
+ var sqlId utils.SQLVal = "select t.AREAUSERID," +
|
|
|
+ " t.ORIBUYPLANQTY," +
|
|
|
+ " t.ORIBUYPRICEDQTY," +
|
|
|
+ " t.ORISELLPLANQTY," +
|
|
|
+ " t.ORISELLPRICEDQTY," +
|
|
|
+ " t.BUYPLANQTY," +
|
|
|
+ " t.BUYPRICEDQTY," +
|
|
|
+ " t.SELLPLANQTY," +
|
|
|
+ " t.SELLPRICEDQTY," +
|
|
|
+ " t.TOTALSPOTQTY," +
|
|
|
+ " g.deliverygoodsid," +
|
|
|
+ " g.deliverygoodscode," +
|
|
|
+ " g.deliverygoodsname," +
|
|
|
+ " to_char(t.UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME" +
|
|
|
+ " from ermcp_areaspot t" +
|
|
|
+ " left join deliverygoods g" +
|
|
|
+ " on t.deliverygoodsid = g.deliverygoodsid" +
|
|
|
+ " where 1 = 1"
|
|
|
+ sqlId.And("t.areauserid", r.AREAUSERID)
|
|
|
+ return sqlId.String()
|
|
|
+}
|
|
|
+
|
|
|
+// GetDataEx
|
|
|
+func (r *Ermcp3AreaSpot) GetDataEx() (interface{}, error) {
|
|
|
+ e := db.GetEngine()
|
|
|
+ s := e.SQL(r.buildSql())
|
|
|
+ sData := make([]Ermcp3AreaSpot, 0)
|
|
|
+ if err := s.Find(&sData); err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ for i := range sData {
|
|
|
+ sData[i].calc()
|
|
|
+ }
|
|
|
+ return sData, nil
|
|
|
+}
|
|
|
+
|
|
|
+// Ermcp3AreaSpotDetail 敞口现货头寸明细
|
|
|
+type Ermcp3AreaSpotDetail struct {
|
|
|
+ Relatedid string `json:"relatedid" xorm:"'relatedid'"` // 套保计划ID/现货合同ID
|
|
|
+ Relatedno string `json:"relatedno" xorm:"'relatedno'"` // 编号
|
|
|
+ LogType int32 `json:"logtype" xorm:"'logType'"` // 记录类型 1-套保 2-现货合同
|
|
|
+ Contracttype int32 `json:"contracttype" xorm:"'contracttype'"` // 合同类型 1-采购 -1-销售
|
|
|
+ Qty float64 `json:"qty" xorm:"'qty'"` // 数量
|
|
|
+ Strtime string `json:"strtime" xorm:"'strtime'"` // 时间
|
|
|
+ Enumdicname string `json:"enumdicname"` // 现货商品单位名称
|
|
|
+ Recordname string `json:"recordname"` // 类型名称
|
|
|
+ CREATETIME string `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
|
|
|
+ Unitid int32 `json:"-" xorm:"'UNITID'"` // 单位ID
|
|
|
+ UserId int `json:"-"` // 所属用户ID
|
|
|
+ DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种id
|
|
|
+ DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码
|
|
|
+ DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 现货品种名称
|
|
|
+}
|
|
|
+
|
|
|
+func (r *Ermcp3AreaSpotDetail) calc() {
|
|
|
+ var logTypeName, contractTypeName string
|
|
|
+ if r.LogType == 1 {
|
|
|
+ logTypeName = "计划"
|
|
|
+ } else {
|
|
|
+ logTypeName = "合同"
|
|
|
+ }
|
|
|
+
|
|
|
+ if r.Contracttype == 1 {
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ r.Recordname = contractTypeName + logTypeName
|
|
|
+ r.Enumdicname = mtpcache.GetEnumDicitemName(r.Unitid)
|
|
|
+}
|
|
|
+
|
|
|
+func (r *Ermcp3AreaSpotDetail) buildSql() string {
|
|
|
+ var sqlId utils.SQLVal = "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.deliverygoodsid = %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.deliverygoodsid = %v)" +
|
|
|
+ "select t.relatedid," +
|
|
|
+ " tmp.relatedno," +
|
|
|
+ " t.LogType," +
|
|
|
+ " tmp.contracttype," +
|
|
|
+ " t.RealQty qty," +
|
|
|
+ " to_char(t.createtime, 'yyyy-mm-dd hh24:mi:ss') createtime," +
|
|
|
+ " g.deliverygoodsid," +
|
|
|
+ " g.deliverygoodsname," +
|
|
|
+ " g.deliverygoodscode," +
|
|
|
+ " g.goodsunitid unitid" +
|
|
|
+ " from ermcp_spotlog t" +
|
|
|
+ " inner join tmp" +
|
|
|
+ " on t.LogType = tmp.logType" +
|
|
|
+ " and t.relatedid = tmp.relatedid" +
|
|
|
+ " and t.areauserid = %v" +
|
|
|
+ " and t.deliverygoodsid = %v" +
|
|
|
+ " left join deliverygoods g" +
|
|
|
+ " on t.deliverygoodsid = g.deliverygoodsid" +
|
|
|
+ " where t.tradedate = to_char(sysdate, 'yyyymmdd')"
|
|
|
+ sqlId.FormatParam(r.UserId, r.DELIVERYGOODSID, r.UserId, r.DELIVERYGOODSID, r.UserId, r.DELIVERYGOODSID)
|
|
|
+ return sqlId.String()
|
|
|
+}
|
|
|
+
|
|
|
+// GetDataEx
|
|
|
+func (r *Ermcp3AreaSpotDetail) GetDataEx() (interface{}, error) {
|
|
|
+ e := db.GetEngine()
|
|
|
+ s := e.SQL(r.buildSql())
|
|
|
+ sData := make([]Ermcp3AreaSpotDetail, 0)
|
|
|
+ if err := s.Find(&sData); err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ for i := range sData {
|
|
|
+ sData[i].calc()
|
|
|
+ }
|
|
|
+ return sData, nil
|
|
|
+}
|
|
|
+
|
|
|
+// Ermcp3Wrstandard 现货品类
|
|
|
+type Ermcp3Wrstandard struct {
|
|
|
+ WRSTANDARDID int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 品类ID(SEQ_WRSTANDARD)
|
|
|
+ WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 品类代码
|
|
|
+ DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种ID
|
|
|
+ UNITID int32 `json:"unitid" xorm:"'UNITID'"` // 品类单位ID
|
|
|
+ MINIVALUE int32 `json:"minivalue" xorm:"'MINIVALUE'"` // 最小变动值
|
|
|
+ MINIVALUEDP int32 `json:"minivaluedp" xorm:"'MINIVALUEDP'"` // 最小变动值小数位
|
|
|
+ REALMINIVALUE int32 `json:"realminivalue" xorm:"'REALMINIVALUE'"` // 实际最小变动值
|
|
|
+ REALMINIVALUEDP int32 `json:"realminivaluedp" xorm:"'REALMINIVALUEDP'"` // 实际最小变动值小数位
|
|
|
+ CREATORID int64 `json:"creatorid" xorm:"'CREATORID'"` // 创建人
|
|
|
+ CREATETIME string `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
|
|
|
+ WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 品类名称
|
|
|
+ AREAUSERID int `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构
|
|
|
+ EnumdicName string `json:"enumdicname"` // 品类单位名称
|
|
|
+ ISVALID int32 `json:"isvalid" xorm:"'ISVALID'"` // 是否有效 0-无效(停用) 1-有效(正常)
|
|
|
+ UPDATETIME string `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间
|
|
|
+ REMARK string `json:"remark" xorm:"'REMARK'"` // 备注
|
|
|
+}
|
|
|
+
|
|
|
+func (r *Ermcp3Wrstandard) calc() {
|
|
|
+ r.EnumdicName = mtpcache.GetEnumDicitemName(r.UNITID)
|
|
|
+}
|
|
|
+
|
|
|
+func (r *Ermcp3Wrstandard) buildSql() string {
|
|
|
+ str := "select WRSTANDARDID," +
|
|
|
+ " WRSTANDARDCODE," +
|
|
|
+ " DELIVERYGOODSID," +
|
|
|
+ " UNITID," +
|
|
|
+ " MINIVALUE," +
|
|
|
+ " MINIVALUEDP," +
|
|
|
+ " REALMINIVALUE," +
|
|
|
+ " REALMINIVALUEDP," +
|
|
|
+ " CREATORID," +
|
|
|
+ " to_char(CREATETIME, 'yyyy-mm-dd hh24:mi:ss') CREATETIME," +
|
|
|
+ " WRSTANDARDNAME," +
|
|
|
+ " ISVALID," +
|
|
|
+ " to_char(UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME," +
|
|
|
+ " REMARK," +
|
|
|
+ " AREAUSERID" +
|
|
|
+ " from wrstandard t" +
|
|
|
+ " where t.AREAUSERID=%v"
|
|
|
+ sqlId := fmt.Sprintf(str, r.AREAUSERID)
|
|
|
+ if r.DELIVERYGOODSID > 0 {
|
|
|
+ sqlId = sqlId + fmt.Sprintf(" and DELIVERYGOODSID=%v", r.DELIVERYGOODSID)
|
|
|
+ }
|
|
|
+ sqlId += " order by createtime desc"
|
|
|
+ return sqlId
|
|
|
+}
|
|
|
+
|
|
|
+// GetDataEx
|
|
|
+func (r *Ermcp3Wrstandard) GetDataEx() (interface{}, error) {
|
|
|
+ e := db.GetEngine()
|
|
|
+ s := e.SQL(r.buildSql())
|
|
|
+ sData := make([]Ermcp3Wrstandard, 0)
|
|
|
+ if err := s.Find(&sData); err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ for i := range sData {
|
|
|
+ sData[i].calc()
|
|
|
+ }
|
|
|
+ return sData, nil
|
|
|
+}
|