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()) app.Error(c, http.StatusInternalServerError, err, "查询失败:"+err.Error())
return return
} }
fmt.Println(resp) //fmt.Println(resp)
app.OK(c, resp, "查询成功") app.OK(c, resp, "查询成功")
return return

View File

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