Explorar o código

fix bug: 现货汇总/订单汇总 履约中的数量不正确

zou.yingbin %!s(int64=3) %!d(string=hai) anos
pai
achega
a19e9150a4
Modificáronse 1 ficheiros con 110 adicións e 95 borrados
  1. 110 95
      models/wrTrade2.go

+ 110 - 95
models/wrTrade2.go

@@ -1944,107 +1944,122 @@ func (r *WrPerformanPlanSum) calc() {
 
 // 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"
+	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)
 	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)
+	// 跟buildSql_XHHZ()相比, group by 多了warehouseid字段
+	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)
 	return sqlId.String()
 }