zou.yingbin 4 سال پیش
والد
کامیت
7bf9f9064e
1فایلهای تغییر یافته به همراه22 افزوده شده و 3 حذف شده
  1. 22 3
      models/ermcpAreaStock.go

+ 22 - 3
models/ermcpAreaStock.go

@@ -205,15 +205,34 @@ func (r *ErmcpAreaStockApplySum) buildSql() string {
 		"  from (SELECT t.INOUTTYPE," +
 		"               t.SPOTGOODSMODELID," +
 		"               t.SPOTGOODSBRANDID," +
+		"               t.SPOTCONTRACTID," +
 		"               sum(t.QTY) TOTALQTY" +
 		"          FROM ERMCP_AREAINOUTSTOCKAPPLY t" +
-		"         WHERE t.applystatus= 2 and t.inouttype = %v and t.spotcontractid = %v" +
-		"         group by t.inouttype, t.spotgoodsbrandid, t.spotgoodsmodelid) a" +
+		"         WHERE t.applystatus= 2 and t.spotcontractid = %v" +
+		"         group by t.inouttype, t.spotgoodsbrandid, t.spotgoodsmodelid, t.spotcontractid) a" +
 		"  left join spotgoodsbrand gb" +
 		"    on a.spotgoodsbrandid = gb.brandid" +
 		"  left join spotgoodsmodel gm" +
 		"    on a.spotgoodsmodelid = gm.modelid"
-	sqlId = fmt.Sprintf(sqlId, r.INOUTTYPE, r.SPOTCONTRACTID)
+	sqlId = fmt.Sprintf(sqlId, r.SPOTCONTRACTID)
+
+	// 不关联合同id
+	sqlId2 := "select a.*, gb.brandname, gm.modelname" +
+		"  from (SELECT t.INOUTTYPE," +
+		"               t.SPOTGOODSMODELID," +
+		"               t.SPOTGOODSBRANDID," +
+		"               t.SPOTCONTRACTID," +
+		"               sum(t.QTY) TOTALQTY" +
+		"          FROM ERMCP_AREAINOUTSTOCKAPPLY t" +
+		"         WHERE t.applystatus= 2" +
+		"         group by t.inouttype, t.spotgoodsbrandid, t.spotgoodsmodelid, t.SPOTCONTRACTID) a" +
+		"  left join spotgoodsbrand gb" +
+		"    on a.spotgoodsbrandid = gb.brandid" +
+		"  left join spotgoodsmodel gm" +
+		"    on a.spotgoodsmodelid = gm.modelid"
+	if len(r.SPOTCONTRACTID) == 0 {
+		return sqlId2
+	}
 	return sqlId
 }