Browse Source

联调问题修改:买卖大厅单号、汇总的履约数量等

zou.yingbin 4 years ago
parent
commit
2bd50ad03e
1 changed files with 176 additions and 3 deletions
  1. 176 3
      models/wrTrade2.go

+ 176 - 3
models/wrTrade2.go

@@ -267,7 +267,7 @@ func (r *WrOrderQuoteDetail) calc() {
 }
 
 func (r *WrOrderQuoteDetail) buildSql() string {
-	var sqlId utils.SQLVal = "select t.wrtradeorderid," +
+	var sqlId utils.SQLVal = "select to_char(t.wrtradeorderid) wrtradeorderid," +
 		"       to_char(t.wrfactortypeid) wrfactortypeid," +
 		"       t.userid," +
 		"       t.orderqty - t.tradeqty as qty," +
@@ -341,6 +341,7 @@ type Wr2FactorType struct {
 	WRTYPENAME string `json:"wrtypename" xorm:"'WRTYPENAME'"` // 商品
 }
 
+// Calc
 func (r *Wr2FactorType) Calc() {
 	if r.WRTYPENAME == "" {
 		if len(r.WRFACTORTYPENAME) > 0 {
@@ -378,7 +379,7 @@ type WrPosition struct {
 	SELLEXCUTEQTY   float64 `json:"sellexcuteqty"`                             // 销售履约中数量
 	WRPOSITIONNO    string  `json:"wrpositionno"`                              // 仓单编号
 
-	QueryType int32 `json:"querytype" form:"querytype"` // 查询类型  1-现货汇总 2-库存汇总(订单汇总) 3-现货明细
+	QueryType int32 `json:"querytype" form:"querytype"` // 查询类型  1-现货汇总 2-库存汇总(订单汇总)
 }
 
 func (r *WrPosition) calc() {
@@ -388,6 +389,21 @@ func (r *WrPosition) calc() {
 	r.Wr2FactorType.Calc()
 }
 
+// 添加履约中数量
+func (r *WrPosition) addPerformancePlanQty(sum WrPerformanPlanSum) {
+	if r.DELIVERYGOODSID == sum.DELIVERYGOODSID &&
+		r.WRSTANDARDID == sum.WRSTANDARDID &&
+		r.WRTYPENAME == sum.WRTYPENAME {
+		if r.QueryType == 1 || (r.QueryType == 2 && r.WAREHOUSEID == sum.WAREHOUSEID) {
+			if sum.BUYORSELL == 0 {
+				r.BUYEXCUTEQTY = sum.QTY
+			} else {
+				r.SELLEXCUTEQTY = sum.QTY
+			}
+		}
+	}
+}
+
 func (r *WrPosition) buildSql() string {
 	if r.QueryType == 1 {
 		// 现货汇总 品种 + 品类 + 其它要素, 根据品种汇总
@@ -499,6 +515,20 @@ func (r *WrPosition) GetDataEx() (interface{}, error) {
 		sData[i].calc()
 		sData[i].QueryType = r.QueryType
 	}
+	// 查履约中的数量
+	if len(sData) > 0 {
+		if r.QueryType == 1 || r.QueryType == 2 {
+			m := WrPerformanPlanSum{QueryType: r.QueryType, USERID: r.WRUSERID}
+			if d, err := m.GetData(); err == nil {
+				for i := range sData {
+					for _, sum := range d {
+						sData[i].addPerformancePlanQty(sum)
+					}
+				}
+			}
+		}
+	}
+
 	return sData, err
 }
 
@@ -1020,7 +1050,7 @@ func (r *WrPerformancePlan) calc() {
 
 func (r *WrPerformancePlan) buildSql() string {
 	var sqlId utils.SQLVal = "with tmp as" +
-		" (select t.wrfactortypeid," +
+		" (select to_char(t.wrfactortypeid) wrfactortypeid," +
 		"         t.wrfactortypename," +
 		"         t.wrstandardid," +
 		"         t.deliverygoodsid," +
@@ -1253,3 +1283,146 @@ func (r *WrFilterItem) GetDataEx() (interface{}, error) {
 	}
 	return sData, err
 }
+
+// WrPerformanPlanSum 履约中数量
+type WrPerformanPlanSum struct {
+	USERID          int64   `json:"userid"  xorm:"'USERID'"`                   // 用户id
+	BUYORSELL       int32   `json:"buyorsell"  xorm:"'BUYORSELL'"`             // 买卖方向
+	QTY             float64 `json:"qty"  xorm:"'QTY'"`                         // 履约中的数量
+	DELIVERYGOODSID int32   `json:"deliverygoodsid"  xorm:"'DELIVERYGOODSID'"` // 品种id
+	WRSTANDARDID    int64   `json:"wrstandardid"  xorm:"'WRSTANDARDID'"`       // 品类id
+	WAREHOUSEID     int64   `json:"warehouseid"  xorm:"'WAREHOUSEID'"`         // 仓库id
+	WRTYPENAME      string  `json:"wrtypename"  xorm:"'WRTYPENAME'"`           // 商品
+
+	QueryType int32 `json:"querytype" form:"querytype"` // 查询类型  1-现货汇总 2-库存汇总
+}
+
+func (r *WrPerformanPlanSum) calc() {
+	if len(r.WRTYPENAME) > 0 {
+		r.WRTYPENAME = strings.ReplaceAll(r.WRTYPENAME, ",", "-")
+	}
+}
+
+// buildSql_XHHZ 现货汇总 履约中的数量
+func (r *WrPerformanPlanSum) buildSql_XHHZ() string {
+	var sqlId utils.SQLVal = "with tmp as" +
+		" (select t.buyaccountid," +
+		"         t.sellaccountid," +
+		"         t.qty," +
+		"         w.wrfactortypeid," +
+		"         w.deliverygoodsid," +
+		"         w.wrstandardid," +
+		"         w.warehouseid," +
+		"         wd.wrstandardname || w.wrfactortypename2 wrtypename," +
+		"         u1.userid buyuserid," +
+		"         u2.userid selluserid" +
+		"    from performanceplan t" +
+		"    left join performanceplanwr p" +
+		"      on t.performanceplanid = p.performanceplanid" +
+		"    left join warehousereciept f" +
+		"      on p.wrid = f.wrid" +
+		"    left join wrfactortype w" +
+		"      on f.wrfactortypeid = w.wrfactortypeid" +
+		"    left join wrstandard wd" +
+		"      on w.wrstandardid = wd.wrstandardid" +
+		"    left join taaccount ta1" +
+		"      on t.buyaccountid = ta1.accountid" +
+		"    left join useraccount u1" +
+		"      on ta1.userid = u1.userid" +
+		"    left join taaccount ta2" +
+		"      on t.sellaccountid = ta2.accountid" +
+		"    left join useraccount u2" +
+		"      on ta2.userid = u2.userid" +
+		"   where t.performancestatus in (2) and %v in(u1.userid, u2.userid))" +
+		"select k.buyuserid userid," +
+		"       0 as buyorsell," +
+		"       k.deliverygoodsid," +
+		"       k.wrstandardid," +
+		"       k.wrtypename," +
+		"       sum(k.qty) qty" +
+		"  from tmp k" +
+		" group by k.buyuserid, k.deliverygoodsid, k.wrstandardid, k.wrtypename" +
+		"union all" +
+		"select k.selluserid userid," +
+		"       1 as buyorsell," +
+		"       k.deliverygoodsid," +
+		"       k.wrstandardid," +
+		"       k.wrtypename," +
+		"       sum(k.qty) qty" +
+		"  from tmp k" +
+		" group by k.selluserid, k.deliverygoodsid, k.wrstandardid, k.wrtypename"
+	sqlId.FormatParam(r.USERID, r.USERID)
+	return sqlId.String()
+}
+
+// buildSql_KCHZ 库存汇总 履约中的数量
+func (r *WrPerformanPlanSum) buildSql_KCHZ() string {
+	var sqlId utils.SQLVal = "with tmp as" +
+		" (select t.buyaccountid," +
+		"         t.sellaccountid," +
+		"         t.qty," +
+		"         w.wrfactortypeid," +
+		"         w.deliverygoodsid," +
+		"         w.wrstandardid," +
+		"         w.warehouseid," +
+		"         wd.wrstandardname || w.wrfactortypename2 wrtypename," +
+		"         u1.userid buyuserid," +
+		"         u2.userid selluserid" +
+		"    from performanceplan t" +
+		"    left join performanceplanwr p" +
+		"      on t.performanceplanid = p.performanceplanid" +
+		"    left join warehousereciept f" +
+		"      on p.wrid = f.wrid" +
+		"    left join wrfactortype w" +
+		"      on f.wrfactortypeid = w.wrfactortypeid" +
+		"    left join wrstandard wd" +
+		"      on w.wrstandardid = wd.wrstandardid" +
+		"    left join taaccount ta1" +
+		"      on t.buyaccountid = ta1.accountid" +
+		"    left join useraccount u1" +
+		"      on ta1.userid = u1.userid" +
+		"    left join taaccount ta2" +
+		"      on t.sellaccountid = ta2.accountid" +
+		"    left join useraccount u2" +
+		"      on ta2.userid = u2.userid" +
+		"   where t.performancestatus in (2) and %v in(u1.userid, u2.userid)" +
+		"select k.buyuserid userid," +
+		"       0 as buyorsell," +
+		"       k.deliverygoodsid," +
+		"       k.wrstandardid," +
+		"       k.warehouseid," +
+		"       k.wrtypename," +
+		"       sum(k.qty) qty" +
+		"  from tmp k" +
+		" group by k.buyuserid, k.deliverygoodsid, k.wrstandardid, k.warehouseid, k.wrtypename" +
+		"union all" +
+		"select k.selluserid userid," +
+		"       1 as buyorsell," +
+		"       k.deliverygoodsid," +
+		"       k.wrstandardid," +
+		"       k.warehouseid," +
+		"       k.wrtypename," +
+		"       sum(k.qty) qty" +
+		"  from tmp k" +
+		" group by k.selluserid, k.deliverygoodsid, k.wrstandardid, k.warehouseid, k.wrtypename"
+	sqlId.FormatParam(r.USERID, r.USERID)
+	return sqlId.String()
+}
+
+func (r *WrPerformanPlanSum) buildSql() string {
+	if r.QueryType == 1 {
+		return r.buildSql_XHHZ()
+	} else {
+		return r.buildSql_KCHZ()
+	}
+}
+
+// GetData 获取履约中数量
+func (r *WrPerformanPlanSum) GetData() ([]WrPerformanPlanSum, error) {
+	sData := make([]WrPerformanPlanSum, 0)
+	err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
+	for i := range sData {
+		sData[i].calc()
+	}
+	return sData, err
+}