|
|
@@ -7,6 +7,7 @@
|
|
|
package models
|
|
|
|
|
|
import (
|
|
|
+ "fmt"
|
|
|
"mtp2_if/db"
|
|
|
"mtp2_if/utils"
|
|
|
)
|
|
|
@@ -308,3 +309,173 @@ func (r *WrOrderQuoteDetail) GetDataEx() (interface{}, error) {
|
|
|
}
|
|
|
return sData, err
|
|
|
}
|
|
|
+
|
|
|
+// Wr2FactorType 仓单要素类型
|
|
|
+type Wr2FactorType struct {
|
|
|
+ WRFACTORTYPEID int64 `json:"wrfactortypeid" xorm:"WRFACTORTYPEID" form:"wrfactortypeid"` // 仓单要素类型ID(212+Unix秒时间戳(10位)+xxxxxx)
|
|
|
+ WRFACTORTYPENAME string `json:"wrfactortypename" xorm:"WRFACTORTYPENAME" form:"wrfactortypename"` // 仓单要素类型名称(选择项要素的名称合并显示,逗号分隔)
|
|
|
+ DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"DELIVERYGOODSID" form:"deliverygoodsid"` // 品种ID
|
|
|
+ WAREHOUSEID int64 `json:"warehouseid" xorm:"WAREHOUSEID" form:"warehouseid"` // 仓库ID
|
|
|
+ WRSTANDARDID int64 `json:"wrstandardid" xorm:"WRSTANDARDID" form:"wrstandardid"` // 现货商品ID
|
|
|
+ WRSTANDARDCODE string `json:"wrstandardcode" xorm:"WRSTANDARDCODE" form:"wrstandardcode"` // 现货商品代码
|
|
|
+ OPTIONCOMPARE string `json:"optioncompare" xorm:"OPTIONCOMPARE" form:"optioncompare"` // 选择项比较串【{选择项ID}+{冒号}+选择项值 } ,逗号分隔,头尾加逗号】-- 所有选择项拼接,用于比较
|
|
|
+
|
|
|
+ WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 商品名称
|
|
|
+ DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 品种代码
|
|
|
+ DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 品种名称
|
|
|
+ ENUMDICNAME string `json:"enumdicname"` // 单位名称
|
|
|
+ WAREHOUSENAME string `json:"warehousename" xorm:"'WAREHOUSENAME'"` // 仓库名称
|
|
|
+
|
|
|
+ WRTYPENAME string `json:"wrtypename"` // 商品
|
|
|
+}
|
|
|
+
|
|
|
+func (r *Wr2FactorType) Calc() {
|
|
|
+ r.WRTYPENAME = r.WRSTANDARDNAME + "-" + r.WRFACTORTYPENAME
|
|
|
+}
|
|
|
+
|
|
|
+// WrPosition 仓单贸易持仓汇总
|
|
|
+type WrPosition struct {
|
|
|
+ WRPOSITIONID int64 `json:"wrpositionid" xorm:"WRPOSITIONID" form:"wrpositionid"` // 仓单头寸ID(201+Unix秒时间戳(10位)+xxxxxx)
|
|
|
+ WRUSERID int64 `json:"wruserid" xorm:"WRUSERID" form:"userid"` // 持有人ID
|
|
|
+ TOTALQTY float64 `json:"totalqty" xorm:"TOTALQTY" form:"totalqty"` // 总数量(库存数量)
|
|
|
+ INCREASEQTY float64 `json:"-" xorm:"INCREASEQTY" form:"increaseqty"` // 今日增加数量
|
|
|
+ DECREASEQTY float64 `json:"-" xorm:"DECREASEQTY" form:"decreaseqty"` // 今日减少数量
|
|
|
+ FREEZEQTY float64 `json:"freezeqty" xorm:"FREEZEQTY" form:"freezeqty"` // 总冻结数量
|
|
|
+ RELATEDQTY float64 `json:"-" xorm:"RELATEDQTY" form:"relatedqty"` // 关联数量
|
|
|
+ MODIFYTIME string `json:"modifytime" xorm:"MODIFYTIME" form:"modifytime"` // 修改时间(过户时间)
|
|
|
+ MODIFIERID int64 `json:"-" xorm:"MODIFIERID" form:"modifierid"` // 修改人
|
|
|
+ TRADEWRQTY float64 `json:"-" xorm:"TRADEWRQTY" form:"tradewrqty"` // 订单仓单头寸总数量
|
|
|
+ ACCOUNTID int64 `json:"accountid" xorm:"ACCOUNTID" form:"accountid"` // 帐户ID
|
|
|
+ CREDITTOTALQTY float64 `json:"credittotalqty" xorm:"CREDITTOTALQTY" form:"credittotalqty"` // 授信总数量(预售仓单:预售总量)
|
|
|
+ CREDITCURQTY float64 `json:"creditcurqty" xorm:"CREDITCURQTY" form:"creditcurqty"` // 授信当前数量(预售仓单:预售当前量)
|
|
|
+ CREDITFREEZEQTY float64 `json:"creditfreezeqty" xorm:"CREDITFREEZEQTY" form:"creditfreezeqty"` // 授信冻结数量(预售仓单: 当前数量)
|
|
|
+ CREDITTRADEQTY float64 `json:"credittradeqty" xorm:"CREDITTRADEQTY" form:"credittradeqty"` // 授信成交数量(预售仓单:成交总量)
|
|
|
+ Wr2FactorType `xorm:"extends"`
|
|
|
+
|
|
|
+ ENALBEQTY float64 `json:"enalbeqty" xorm:"'ENALBEQTY'"` // 可用数量
|
|
|
+ CREDITENABLEQTY float64 `json:"creditenableqty" xorm:"'CREDITENABLEQTY'"` // 授信可用数量(预售仓单: 可用数量)
|
|
|
+ PLEDGEQTY float64 `json:"pledgeqty" xorm:"'-'"` // 质押数量
|
|
|
+ BUYEXCUTEQTY float64 `json:"buyexcuteqty"` // 采购履约中数量
|
|
|
+ SELLEXCUTEQTY float64 `json:"sellexcuteqty"` // 销售履约中数量
|
|
|
+ WRPOSITIONNO string `json:"wrpositionno"` // 仓单编号
|
|
|
+
|
|
|
+ QueryType int32 `json:"querytype" form:"querytype"` // 查询类型 1-现货汇总 2-库存汇总(订单汇总) 3-现货明细
|
|
|
+}
|
|
|
+
|
|
|
+func (r *WrPosition) calc() {
|
|
|
+ r.ENALBEQTY = r.TOTALQTY - r.FREEZEQTY
|
|
|
+ r.CREDITENABLEQTY = r.CREDITCURQTY - r.CREDITFREEZEQTY
|
|
|
+ r.WRPOSITIONNO = fmt.Sprintf("%v", r.WRFACTORTYPEID)
|
|
|
+ r.Wr2FactorType.Calc()
|
|
|
+}
|
|
|
+
|
|
|
+func (r *WrPosition) buildSql() string {
|
|
|
+ if r.QueryType == 1 {
|
|
|
+ // 现货汇总 品种 + 品类 + 其它要素, 根据品种汇总
|
|
|
+ return r.buildSql1()
|
|
|
+ } else if r.QueryType == 2 {
|
|
|
+ // 库存汇总 品种 + 仓库 + 品类 + 其它要素, 即全维度
|
|
|
+ return r.buildSql2()
|
|
|
+ } else {
|
|
|
+ // 现货明细 仓单编号 + 品种 + 仓库 + 仓单要素 即全维度 跟库存汇总一样
|
|
|
+ return r.buildSql3()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func (r *WrPosition) buildSql1() string {
|
|
|
+ var sqlId utils.SQLVal = "with tmp as" +
|
|
|
+ " (select t.*," +
|
|
|
+ " w.wrstandardid," +
|
|
|
+ " w.warehouseid," +
|
|
|
+ " wd.wrstandardname," +
|
|
|
+ " wd.wrstandardname || '-' ||w.wrfactortypename as wrtypename" +
|
|
|
+ " from WRPOSITION t" +
|
|
|
+ " left join WRFACTORTYPE w" +
|
|
|
+ " on t.wrfactortypeid = w.wrfactortypeid" +
|
|
|
+ " left join wrstandard wd" +
|
|
|
+ " on w.wrstandardid = wd.wrstandardid" +
|
|
|
+ " where t.wruserid = %v)," +
|
|
|
+ "hld as" +
|
|
|
+ " (select k.deliverygoodsid," +
|
|
|
+ " k.wrtypename," +
|
|
|
+ " sum(k.TOTALQTY) TOTALQTY," +
|
|
|
+ " sum(k.INCREASEQTY) INCREASEQTY," +
|
|
|
+ " sum(k.DECREASEQTY) DECREASEQTY," +
|
|
|
+ " sum(k.FREEZEQTY) FREEZEQTY," +
|
|
|
+ " sum(k.RELATEDQTY) RELATEDQTY," +
|
|
|
+ " sum(k.TRADEWRQTY) TRADEWRQTY," +
|
|
|
+ " sum(k.CREDITTOTALQTY) CREDITTOTALQTY," +
|
|
|
+ " sum(k.CREDITCURQTY) CREDITCURQTY," +
|
|
|
+ " sum(k.CREDITFREEZEQTY) CREDITFREEZEQTY," +
|
|
|
+ " sum(k.CREDITTRADEQTY) CREDITTRADEQTY" +
|
|
|
+ " from tmp k" +
|
|
|
+ " where 1 = 1" +
|
|
|
+ " group by k.deliverygoodsid, k.wrstandardname, k.wrtypename)" +
|
|
|
+ "select h.*, g.deliverygoodsname, g.deliverygoodscode, e.enumdicname" +
|
|
|
+ " from hld h" +
|
|
|
+ " left join deliverygoods g" +
|
|
|
+ " on h.deliverygoodsid = g.deliverygoodsid" +
|
|
|
+ " left join enumdicitem e" +
|
|
|
+ " on e.enumitemname = g.goodsunitid" +
|
|
|
+ " and e.enumdiccode = 'goodsunit'"
|
|
|
+ sqlId.FormatParam(r.WRUSERID)
|
|
|
+ return sqlId.String()
|
|
|
+}
|
|
|
+
|
|
|
+func (r *WrPosition) buildSql2() string {
|
|
|
+ return r.buildSql3()
|
|
|
+}
|
|
|
+
|
|
|
+func (r *WrPosition) buildSql3() string {
|
|
|
+ var sqlId utils.SQLVal = "SELECT t.WRPOSITIONID," +
|
|
|
+ " t.WRUSERID," +
|
|
|
+ " t.TOTALQTY," +
|
|
|
+ " t.INCREASEQTY," +
|
|
|
+ " t.DECREASEQTY," +
|
|
|
+ " t.FREEZEQTY," +
|
|
|
+ " t.RELATEDQTY," +
|
|
|
+ " to_char(t.MODIFYTIME, 'yyyy-mm-dd hh24:mi:ss') MODIFYTIME," +
|
|
|
+ " t.MODIFIERID," +
|
|
|
+ " t.TRADEWRQTY," +
|
|
|
+ " t.ACCOUNTID," +
|
|
|
+ " t.CREDITTOTALQTY," +
|
|
|
+ " t.CREDITCURQTY," +
|
|
|
+ " t.CREDITFREEZEQTY," +
|
|
|
+ " t.CREDITTRADEQTY," +
|
|
|
+ " w.WRFACTORTYPEID," +
|
|
|
+ " w.WRFACTORTYPENAME," +
|
|
|
+ " w.DELIVERYGOODSID," +
|
|
|
+ " w.WAREHOUSEID," +
|
|
|
+ " w.WRSTANDARDID," +
|
|
|
+ " w.WRSTANDARDCODE," +
|
|
|
+ " w.OPTIONCOMPARE," +
|
|
|
+ " dg.deliverygoodscode," +
|
|
|
+ " dg.deliverygoodsname," +
|
|
|
+ " wd.wrstandardcode," +
|
|
|
+ " wd.wrstandardname," +
|
|
|
+ " e.enumdicname" +
|
|
|
+ " FROM WRPOSITION t" +
|
|
|
+ " LEFT JOIN WRFACTORTYPE w" +
|
|
|
+ " on t.wrfactortypeid = w.wrfactortypeid" +
|
|
|
+ " LEFT JOIN DELIVERYGOODS dg" +
|
|
|
+ " on t.deliverygoodsid = dg.deliverygoodsid" +
|
|
|
+ " LEFT JOIN WRSTANDARD wd" +
|
|
|
+ " on w.wrstandardid = wd.wrstandardid" +
|
|
|
+ " left join enumdicitem e" +
|
|
|
+ " on e.enumitemname = dg.goodsunitid" +
|
|
|
+ " and e.enumdiccode = 'goodsunit'" +
|
|
|
+ " WHERE 1 = 1"
|
|
|
+ sqlId.And("t.WRUSERID", r.WRUSERID)
|
|
|
+ return sqlId.String()
|
|
|
+}
|
|
|
+
|
|
|
+// GetDataEx 获取仓单贸易持仓汇总
|
|
|
+func (r *WrPosition) GetDataEx() (interface{}, error) {
|
|
|
+ sData := make([]WrPosition, 0)
|
|
|
+ err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
|
|
|
+ for i := range sData {
|
|
|
+ sData[i].calc()
|
|
|
+ sData[i].QueryType = r.QueryType
|
|
|
+ }
|
|
|
+ return sData, err
|
|
|
+}
|