|
|
@@ -9,6 +9,7 @@ package models
|
|
|
import (
|
|
|
"fmt"
|
|
|
"mtp2_if/db"
|
|
|
+ "mtp2_if/logger"
|
|
|
"mtp2_if/mtpcache"
|
|
|
"mtp2_if/utils"
|
|
|
)
|
|
|
@@ -552,7 +553,7 @@ func (r *Ermcp3SellBuyContract) buildSql() string {
|
|
|
" to_char(t.enddate, 'yyyy-mm-dd hh24:mi:ss') enddate," +
|
|
|
" to_char(t.deliverystartdate, 'yyyy-mm-dd hh24:mi:ss') deliverystartdate," +
|
|
|
" to_char(t.deliveryenddate, 'yyyy-mm-dd hh24:mi:ss') deliveryenddate," +
|
|
|
- " w.convertfactor," +
|
|
|
+ " wr.convertfactor," +
|
|
|
" t.contractstatus," +
|
|
|
" t.pricetype," +
|
|
|
" t.producttype," +
|
|
|
@@ -1545,7 +1546,7 @@ func (r *Ermcp3SpotGoodsPriceLog) buildSql() string {
|
|
|
|
|
|
// GetDataEx 获取现货市价信息日志
|
|
|
func (r *Ermcp3SpotGoodsPriceLog) GetDataEx() (interface{}, error) {
|
|
|
- sData := make([]Ermcp3SpotGoodsPrice, 0)
|
|
|
+ sData := make([]Ermcp3SpotGoodsPriceLog, 0)
|
|
|
err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
|
|
|
if err == nil {
|
|
|
for i := range sData {
|
|
|
@@ -1554,3 +1555,79 @@ func (r *Ermcp3SpotGoodsPriceLog) GetDataEx() (interface{}, error) {
|
|
|
}
|
|
|
return sData, err
|
|
|
}
|
|
|
+
|
|
|
+// Ermcp3HedgePlan 套保计划表结构
|
|
|
+type Ermcp3HedgePlan struct {
|
|
|
+ Areauserid int64 `json:"areauserid" xorm:"'Areauserid'"` // 用户ID
|
|
|
+ Hedgeplanid string `json:"hedgeplanid" xorm:"'Hedgeplanid'"` // 套保计划ID(601+Unix秒时间戳(10位)+xxxxxx)
|
|
|
+ Hedgeplanno string `json:"hedgeplanno" xorm:"'Hedgeplanno'"` // 套保计划编号(名称)
|
|
|
+ Contracttype int `json:"contracttype" xorm:"'Contracttype'"` // 计划类型 - 1:采购 -1:销售
|
|
|
+ Deliverygoodsid int `json:"deliverygoodsid" xorm:"'Deliverygoodsid'"` // 现货品种ID
|
|
|
+ Deliverygoodsname string `json:"deliverygoodsname" xorm:"'Deliverygoodsname'"` // 现货品种名称
|
|
|
+ DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码
|
|
|
+ Producttype int `json:"producttype" xorm:"'Producttype'"` // 产品类型 - 1:标准仓单 2:等标 3:非标
|
|
|
+ Spotgoodsdesc string `json:"spotgoodsdesc" xorm:"'Spotgoodsdesc'"` // 商品型号
|
|
|
+ Planqty float64 `json:"planqty" xorm:"'Planqty'"` // 计划数量
|
|
|
+ Convertfactor float64 `json:"convertfactor" xorm:"'Convertfactor'"` // 标仓系数
|
|
|
+ Plantime string `json:"plantime" xorm:"'Plantime'"` // 计划时间
|
|
|
+ Hedgeplanstatus int `json:"hedgeplanstatus" xorm:"'Hedgeplanstatus'"` // 套保计划状态 - 0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤回
|
|
|
+ Remark string `json:"remark" xorm:"'Remark'"` // 备注
|
|
|
+ CREATETIME string `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
|
|
|
+ UPDATETIME string `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间
|
|
|
+ AUDITTIME string `json:"audittime" xorm:"'AUDITTIME'"` // 审核时间
|
|
|
+ UNITID int32 `json:"unitid" xorm:"'UNITID'"` // 单位id
|
|
|
+ ENUMDICNAME string `json:"enumdicname"` // 单位名称
|
|
|
+}
|
|
|
+
|
|
|
+func (r *Ermcp3HedgePlan) calc() {
|
|
|
+ r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.UNITID)
|
|
|
+}
|
|
|
+
|
|
|
+func (r *Ermcp3HedgePlan) buildSql(status string) string {
|
|
|
+ str := "select to_char(t.Hedgeplanid) Hedgeplanid," +
|
|
|
+ " t.Hedgeplanno," +
|
|
|
+ " t.Contracttype," +
|
|
|
+ " t.Deliverygoodsid," +
|
|
|
+ " g.Deliverygoodsname," +
|
|
|
+ " g.deliverygoodscode," +
|
|
|
+ " g.goodsunitid unitid," +
|
|
|
+ " t.Producttype," +
|
|
|
+ " t.Spotgoodsdesc," +
|
|
|
+ " t.Planqty," +
|
|
|
+ " t.Convertfactor," +
|
|
|
+ " to_char(t.Plantime, 'yyyy-mm-dd hh24:mi:ss') Plantime," +
|
|
|
+ " to_char(t.createtime, 'yyyy-mm-dd hh24:mi:ss') createtime," +
|
|
|
+ " to_char(t.updatetime, 'yyyy-mm-dd hh24:mi:ss') updatetime," +
|
|
|
+ " to_char(t.audittime, 'yyyy-mm-dd hh24:mi:ss') audittime," +
|
|
|
+ " t.Hedgeplanstatus," +
|
|
|
+ " t.Remark" +
|
|
|
+ " from ermcp_hedgeplan t" +
|
|
|
+ " left join deliverygoods g" +
|
|
|
+ " on t.deliverygoodsid = g.deliverygoodsid" +
|
|
|
+ " where t.hedgeplanstatus in (%v)" +
|
|
|
+ " and t.areauserid = %v"
|
|
|
+
|
|
|
+ if status == "2" {
|
|
|
+ // 执行中状态,按审核时间倒序
|
|
|
+ str += " order by t.audittime desc"
|
|
|
+ } else {
|
|
|
+ str += " order by t.updatetime desc"
|
|
|
+ }
|
|
|
+
|
|
|
+ return fmt.Sprintf(str, status, r.Areauserid)
|
|
|
+}
|
|
|
+
|
|
|
+// GetData 从数据库中查询套保计划数据
|
|
|
+func (r *Ermcp3HedgePlan) GetData(status string) ([]Ermcp3HedgePlan, error) {
|
|
|
+ e := db.GetEngine()
|
|
|
+ sData := make([]Ermcp3HedgePlan, 0)
|
|
|
+ if err := e.SQL(r.buildSql(status)).Find(&sData); err != nil {
|
|
|
+ logger.GetLogger().Errorf("query hedgeplan:%v", err)
|
|
|
+ return sData, err
|
|
|
+ }
|
|
|
+ for i := range sData {
|
|
|
+ sData[i].calc()
|
|
|
+ }
|
|
|
+
|
|
|
+ return sData, nil
|
|
|
+}
|