1.修复采购报表(按商品)查询商品数量不准确的问题;

This commit is contained in:
chenlin 2024-08-01 16:11:40 +08:00
parent c64de0727b
commit 0c3fc88c8d
2 changed files with 39 additions and 12 deletions

View File

@ -814,7 +814,7 @@ func ErpPurchaseReportByCommodity(c *gin.Context) {
app.Error(c, http.StatusInternalServerError, err, "查询失败:"+err.Error())
return
}
fmt.Println(resp)
//fmt.Println(resp)
app.OK(c, resp, "查询成功")
return

View File

@ -4122,8 +4122,9 @@ func getReportByCommodityFromCommon(req *ErpPurchaseReportByCommodityReq, c *gin
return nil, err
}
tempDataMap := make(map[uint32][]TempData)
//var wg sync.WaitGroup
//ch := make(chan TempData, len(orders)*len(commodityAndOrderIdMap))
//
//// 补充所有采购订单的商品信息和采购执行数量
//for _, v := range orders {
// commodityIds := findCommodityIDsByOrderID(v.ID, commodityAndOrderIdMap)
@ -4141,7 +4142,12 @@ func getReportByCommodityFromCommon(req *ErpPurchaseReportByCommodityReq, c *gin
// tempDataMap[commodityId] = append(tempDataMap[commodityId], tempData)
// }
//}
//wg.Wait()
//close(ch)
// 并发查询的限制
const maxConcurrency = 15
sem := make(chan struct{}, maxConcurrency)
var wg sync.WaitGroup
ch := make(chan TempData, len(orders)*len(commodityAndOrderIdMap))
@ -4150,13 +4156,30 @@ func getReportByCommodityFromCommon(req *ErpPurchaseReportByCommodityReq, c *gin
commodityIds := findCommodityIDsByOrderID(v.ID, commodityAndOrderIdMap)
for _, commodityID := range commodityIds {
wg.Add(1)
go getPurchaseOrderAndCommodityDataAsync(v.ID, commodityID, ch, &wg)
sem <- struct{}{}
go func(orderID, commodityID uint32) {
defer wg.Done()
defer func() { <-sem }()
purchaseOrderData, commodityData, err := getPurchaseOrderAndCommodityData(orderID, commodityID)
if err != nil {
logger.Errorf("getPurchaseOrderAndCommodityData err:", err)
return
}
tempData := TempData{
CommodityData: commodityData,
ErpCommodityPurchaseOrderData: purchaseOrderData,
}
ch <- tempData
}(v.ID, commodityID)
}
}
wg.Wait()
close(ch)
go func() {
wg.Wait()
close(ch)
}()
tempDataMap := make(map[uint32][]TempData)
for data := range ch {
tempDataMap[data.ErpCommodityId] = append(tempDataMap[data.ErpCommodityId], data)
}
@ -4275,14 +4298,18 @@ func getReportByCommodityFromCommon(req *ErpPurchaseReportByCommodityReq, c *gin
sortByCommodityIDDesc(dataList)
resp.Total = len(dataList)
// 计算分页所需的切片索引
startIndex := page * req.PageSize
endIndex := (page + 1) * req.PageSize
if endIndex > len(dataList) {
endIndex = len(dataList)
if req.IsExport == 1 {
resp.List = dataList
} else {
// 计算分页所需的切片索引
startIndex := page * req.PageSize
endIndex := (page + 1) * req.PageSize
if endIndex > len(dataList) {
endIndex = len(dataList)
}
resp.List = dataList[startIndex:endIndex]
}
resp.List = dataList[startIndex:endIndex]
resp.PlanCount = totalData.PlanCount
resp.PlanAmount = totalData.PlanAmount
resp.Amount = totalData.Amount