Pārlūkot izejas kodu

Merge branch 'fms_2.8' into debug

# Conflicts:
#	controller/census/invoice_payment.go
ziwen 1 gadu atpakaļ
vecāks
revīzija
df0956402e
1 mainītis faili ar 191 papildinājumiem un 131 dzēšanām
  1. 191 131
      controller/census/invoice_payment.go

+ 191 - 131
controller/census/invoice_payment.go

@@ -1005,11 +1005,12 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 	//if redisErr != nil {
 
 	//获取最新的开票到款日期
-	invoiceItem,err := fms.GetLatestIncome()
+	invoiceItem, err := fms.GetLatestIncome()
 	if err != nil {
 		err = fmt.Errorf("获取最新的开票或到款日期, Err: %s", err.Error())
 		return
 	}
+	invoiceItem.InvoiceDate = invoiceItem.InvoiceDate.AddDate(0,0,-invoiceItem.InvoiceDate.Day()+1)
 
 	var dateSlice []string
 	var totalMoneySlice, prevTotalMoneySlice []float64
@@ -1021,7 +1022,7 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 	if req.StartDate != "" && req.EndDate != "" {
 		st := fmt.Sprint(req.StartDate, "-01 00:00:00")
 		ed := fmt.Sprint(req.EndDate, "-01 23:59:59")
-		reqStartDate, _ = time.Parse(utils.FormatDateTime,st)
+		reqStartDate, _ = time.Parse(utils.FormatDateTime, st)
 		reqEndDate, _ = time.Parse(utils.FormatDateTime, ed)
 		if reqEndDate.After(invoiceItem.InvoiceDate) {
 			yearNum = invoiceItem.InvoiceDate.Year() - reqStartDate.Year()
@@ -1046,9 +1047,12 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 	// 累计值
 	var accumulate float64
 	var historyAccumulate float64
-	fmt.Println("numMonth:",numMonth)
-	fmt.Println("InvoiceDate:",invoiceItem.InvoiceDate)
+	//dataList := make([]*fms.IncomeSummaryItem, 0)
+	//historydataList := make([]*fms.IncomeSummaryItem, 0)
+	fmt.Println("numMonth:", numMonth)
+	fmt.Println("InvoiceDate:", invoiceItem.InvoiceDate)
 
+	var j int
 	for i := 0; i <= numMonth; i++ {
 		//timeNow, _ := time.Parse("2006-01", time.Now().Format("2006-01"))
 
@@ -1084,9 +1088,6 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 		endDate = endDateTime.Format(utils.FormatDate)
 		prevEndDate = prevEndDateTime.Format(utils.FormatDate)
 
-
-		dateSlice = append(dateSlice, startDateTime.Format("06/01"))
-
 		cond := `1 = 1`
 		histrtyCond := `1 = 1`
 		pars := make([]interface{}, 0)
@@ -1150,6 +1151,7 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 						err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
 						return
 					}
+					//dataList = append(dataList, results...)
 					var amountSum float64
 					for _, result := range results {
 						incomeChart.DataList = append(incomeChart.DataList, result)
@@ -1158,13 +1160,14 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 					amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
 					accumulate += amountTotal
 				}
-				if req.ListParam == "4" {
-					totalMoneySlice = append(totalMoneySlice, accumulate)
-				} else {
-					totalMoneySlice = append(totalMoneySlice, amountTotal)
+				if i == j {
+					if req.ListParam == "4" {
+						totalMoneySlice = append(totalMoneySlice, accumulate)
+					} else {
+						totalMoneySlice = append(totalMoneySlice, amountTotal)
+					}
 				}
 			} else if endDateTime.Before(historyTime) || endDateTime.Equal(historyTime) {
-
 				//全部走旧查询
 				//fmt.Println("旧查询")
 				histrtyCond += ` AND (invoice_time BETWEEN ? AND ? )`
@@ -1177,6 +1180,7 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 					return
 				}
 				var amountSum float64
+				//dataList = append(dataList, results...)
 				for _, result := range results {
 					incomeChart.DataList = append(incomeChart.DataList, result)
 					amountSum += result.Amount
@@ -1184,64 +1188,67 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 				amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
 				accumulate += amountTotal
 
-				if req.ListParam == "4" {
-					totalMoneySlice = append(totalMoneySlice, accumulate)
-				} else {
-					totalMoneySlice = append(totalMoneySlice, amountTotal)
-				}
-			} else {
-				//刚好跨过20230301的,各查一部分
-				//fmt.Println("查询3")
-				var historyAmountTotal float64
-				histrtyCond += ` AND (invoice_time BETWEEN ? AND '2023-03-01 23:59:59' ) `
-				historyPars = append(historyPars, st)
-				//// 开票到款金额合计(换算后)
-				var amountTotal float64
-				results, e := fms.GetIncomeHistory(histrtyCond, historyPars)
-				if e != nil {
-					err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
-					return
-				}
-				var amountSum float64
-				for _, result := range results {
-					incomeChart.DataList = append(incomeChart.DataList, result)
-					amountSum += result.Amount
-				}
-				amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
-				accumulate += amountTotal
-				historyAmountTotal = amountTotal
-
-				cond += ` AND ((c.invoice_time BETWEEN '2023-03-02 00:00:00' AND ?) or (d.invoice_time BETWEEN '2023-03-02 00:00:00' AND ?))`
-				pars = append(pars, ed, ed)
-				summaryIds, e := fms.GetInvoicePaymentCensusSummaryDataIds(cond, pars)
-				if e != nil {
-					return
-				}
-
-				if len(summaryIds) > 0 {
-					amountCond := `a.id IN ? AND (a.invoice_id <> 0 OR (a.payment_id <> 0 AND a.invoice_id =0))`
-					amountPars := make([]interface{}, 0)
-					amountPars = append(amountPars, summaryIds)
-					results, e := fms.GetContractSummaryIncomeAmount(amountCond, amountPars)
-					if e != nil {
-						err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
-						return
-					}
-					var amountSum float64
-					for _, result := range results {
-						incomeChart.DataList = append(incomeChart.DataList, result)
-						amountSum += result.Amount
+				if i == j {
+					if req.ListParam == "4" {
+						totalMoneySlice = append(totalMoneySlice, accumulate)
+					} else {
+						totalMoneySlice = append(totalMoneySlice, amountTotal)
 					}
-					amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
-					accumulate += amountTotal
 				}
-				if req.ListParam == "4" {
-					totalMoneySlice = append(totalMoneySlice, accumulate)
-				} else {
-					totalMoneySlice = append(totalMoneySlice, amountTotal+historyAmountTotal)
-				}
-
 			}
+			//else {
+			//	//刚好跨过20230301的,各查一部分
+			//	//fmt.Println("查询3")
+			//	var historyAmountTotal float64
+			//	histrtyCond += ` AND (invoice_time BETWEEN ? AND '2023-03-01 23:59:59' ) `
+			//	historyPars = append(historyPars, st)
+			//	//// 开票到款金额合计(换算后)
+			//	var amountTotal float64
+			//	results, e := fms.GetIncomeHistory(histrtyCond, historyPars)
+			//	if e != nil {
+			//		err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
+			//		return
+			//	}
+			//	var amountSum float64
+			//	for _, result := range results {
+			//		incomeChart.DataList = append(incomeChart.DataList, result)
+			//		amountSum += result.Amount
+			//	}
+			//	amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
+			//	accumulate += amountTotal
+			//	historyAmountTotal = amountTotal
+			//
+			//	cond += ` AND ((c.invoice_time BETWEEN '2023-03-02 00:00:00' AND ?) or (d.invoice_time BETWEEN '2023-03-02 00:00:00' AND ?))`
+			//	pars = append(pars, ed, ed)
+			//	summaryIds, e := fms.GetInvoicePaymentCensusSummaryDataIds(cond, pars)
+			//	if e != nil {
+			//		return
+			//	}
+			//
+			//	if len(summaryIds) > 0 {
+			//		amountCond := `a.id IN ? AND (a.invoice_id <> 0 OR (a.payment_id <> 0 AND a.invoice_id =0))`
+			//		amountPars := make([]interface{}, 0)
+			//		amountPars = append(amountPars, summaryIds)
+			//		results, e := fms.GetContractSummaryIncomeAmount(amountCond, amountPars)
+			//		if e != nil {
+			//			err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
+			//			return
+			//		}
+			//		var amountSum float64
+			//		for _, result := range results {
+			//			incomeChart.DataList = append(incomeChart.DataList, result)
+			//			amountSum += result.Amount
+			//		}
+			//		amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
+			//		accumulate += amountTotal
+			//	}
+			//	if req.ListParam == "4" {
+			//		totalMoneySlice = append(totalMoneySlice, accumulate)
+			//	} else {
+			//		totalMoneySlice = append(totalMoneySlice, amountTotal+historyAmountTotal)
+			//	}
+			//
+			//}
 
 		}
 
@@ -1274,13 +1281,21 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 						return
 					}
 					var amountSum float64
+					//historydataList = append(historydataList, results...)
 					for _, result := range results {
+
 						amountSum += result.Amount
 					}
 					prevAmountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
 					historyAccumulate += prevAmountTotal
 				}
-				prevTotalMoneySlice = append(prevTotalMoneySlice, prevAmountTotal)
+				if i == j {
+					if req.ListParam == "4" {
+						prevTotalMoneySlice = append(prevTotalMoneySlice, historyAccumulate)
+					} else {
+						prevTotalMoneySlice = append(prevTotalMoneySlice, prevAmountTotal)
+					}
+				}
 			} else if prevEndDateTime.Before(historyTime) || prevEndDateTime.Equal(historyTime) {
 				//全部走旧查询
 				prevHistoryCond += ` AND (invoice_time BETWEEN ? AND ?)`
@@ -1292,6 +1307,7 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 					err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
 					return
 				}
+				//historydataList = append(historydataList, results...)
 				var amountSum float64
 				for _, result := range results {
 					amountSum += result.Amount
@@ -1299,73 +1315,117 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 				amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
 				historyAccumulate += amountTotal
 
-				if req.ListParam == "4" {
-					prevTotalMoneySlice = append(prevTotalMoneySlice, historyAccumulate)
-				} else {
-					prevTotalMoneySlice = append(prevTotalMoneySlice, amountTotal)
-				}
-			} else {
-				//刚好跨过20230301的,各查一部分
-				var historyAmountTotal float64
-				prevHistoryCond += ` AND (invoice_time BETWEEN ? AND '2023-03-01 23:59:59' ) `
-				prevHistoryPars = append(prevHistoryPars, prevSt)
-				// 开票到款金额合计(换算后)
-				var amountTotal float64
-				results, e := fms.GetIncomeHistory(prevHistoryCond, prevHistoryPars)
-				if e != nil {
-					err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
-					return
-				}
-				var amountSum float64
-				for _, result := range results {
-					amountSum += result.Amount
-				}
-				amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
-				historyAccumulate += amountTotal
-
-
-				prevCond += ` AND ((c.invoice_time BETWEEN '2023-03-02 00:00:00' AND ?) or (d.invoice_time BETWEEN '2023-03-02 00:00:00' AND ?))`
-				prevPars = append(prevPars, prevEd, prevEd)
-				prevSummaryIds, e := fms.GetInvoicePaymentCensusSummaryDataIds(prevCond, prevPars)
-				if e != nil {
-					return
-				}
-
-				// 开票到款金额合计(换算后)
-				var prevAmountTotal float64
-
-				if len(prevSummaryIds) > 0 {
-					amountCond := `a.id IN ? AND (a.invoice_id <> 0 OR (a.payment_id <> 0 AND a.invoice_id =0))`
-					amountPars := make([]interface{}, 0)
-					amountPars = append(amountPars, prevSummaryIds)
-					results, e := fms.GetContractSummaryIncomeAmount(amountCond, amountPars)
-					if e != nil {
-						err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
-						return
+				if i == j {
+					if req.ListParam == "4" {
+						prevTotalMoneySlice = append(prevTotalMoneySlice, historyAccumulate)
+					} else {
+						prevTotalMoneySlice = append(prevTotalMoneySlice, amountTotal)
 					}
-					var amountSum float64
-					for _, result := range results {
-						amountSum += result.Amount
-					}
-					prevAmountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
-					historyAccumulate += prevAmountTotal
-				}
-				if req.ListParam == "4" {
-					prevTotalMoneySlice = append(prevTotalMoneySlice, historyAccumulate)
-				} else {
-					prevTotalMoneySlice = append(prevTotalMoneySlice, prevAmountTotal+historyAmountTotal)
 				}
 			}
-
-		}
-		if req.ListParam == "1" {
-			i = i + 2
-		} else if req.ListParam == "2" {
-			i = i + 5
-		} else if req.ListParam == "3" {
-			i = i + 11
+			//else {
+			//	//刚好跨过20230301的,各查一部分
+			//	var historyAmountTotal float64
+			//	prevHistoryCond += ` AND (invoice_time BETWEEN ? AND '2023-03-01 23:59:59' ) `
+			//	prevHistoryPars = append(prevHistoryPars, prevSt)
+			//	// 开票到款金额合计(换算后)
+			//	var amountTotal float64
+			//	results, e := fms.GetIncomeHistory(prevHistoryCond, prevHistoryPars)
+			//	if e != nil {
+			//		err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
+			//		return
+			//	}
+			//	var amountSum float64
+			//	for _, result := range results {
+			//		amountSum += result.Amount
+			//	}
+			//	amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
+			//	historyAccumulate += amountTotal
+			//
+			//
+			//	prevCond += ` AND ((c.invoice_time BETWEEN '2023-03-02 00:00:00' AND ?) or (d.invoice_time BETWEEN '2023-03-02 00:00:00' AND ?))`
+			//	prevPars = append(prevPars, prevEd, prevEd)
+			//	prevSummaryIds, e := fms.GetInvoicePaymentCensusSummaryDataIds(prevCond, prevPars)
+			//	if e != nil {
+			//		return
+			//	}
+			//
+			//	// 开票到款金额合计(换算后)
+			//	var prevAmountTotal float64
+			//
+			//	if len(prevSummaryIds) > 0 {
+			//		amountCond := `a.id IN ? AND (a.invoice_id <> 0 OR (a.payment_id <> 0 AND a.invoice_id =0))`
+			//		amountPars := make([]interface{}, 0)
+			//		amountPars = append(amountPars, prevSummaryIds)
+			//		results, e := fms.GetContractSummaryIncomeAmount(amountCond, amountPars)
+			//		if e != nil {
+			//			err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
+			//			return
+			//		}
+			//		var amountSum float64
+			//		for _, result := range results {
+			//			amountSum += result.Amount
+			//		}
+			//		prevAmountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
+			//		historyAccumulate += prevAmountTotal
+			//	}
+			//	if req.ListParam == "4" {
+			//		prevTotalMoneySlice = append(prevTotalMoneySlice, historyAccumulate)
+			//	} else {
+			//		prevTotalMoneySlice = append(prevTotalMoneySlice, prevAmountTotal+historyAmountTotal)
+			//	}
+			//}
+			if req.ListParam == "1" && i == j {
+				dateSlice = append(dateSlice, startDateTime.AddDate(0, 2, 0).Format("06/01"))
+				j = j + 2
+			} else if req.ListParam == "2" && i == j {
+				j = j + 5
+				dateSlice = append(dateSlice, startDateTime.AddDate(0, 5, 0).Format("06/01"))
+			} else if req.ListParam == "3" && i == j {
+				j = j + 11
+				dateSlice = append(dateSlice, startDateTime.AddDate(0, 11, 0).Format("06/01"))
+			} else if i == j {
+				dateSlice = append(dateSlice, startDateTime.Format("06/01"))
+				j++
+			}
 		}
 	}
+	//for i, v := range dataList {
+	//	amountTotal, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", v.Amount), 64)
+	//	accumulate += amountTotal
+	//
+	//	if req.ListParam == "4" {
+	//		totalMoneySlice = append(totalMoneySlice, accumulate)
+	//	} else {
+	//		totalMoneySlice = append(totalMoneySlice, amountTotal)
+	//	}
+	//	if req.ListParam == "1" {
+	//		i = i + 2
+	//	} else if req.ListParam == "2" {
+	//		i = i + 5
+	//	} else if req.ListParam == "3" {
+	//		i = i + 11
+	//	}
+	//}
+	//
+	//for i, v := range historydataList {
+	//	historyAmountTotal, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", v.Amount), 64)
+	//	historyAccumulate += historyAmountTotal
+	//
+	//	if req.ListParam == "4" {
+	//		prevTotalMoneySlice = append(prevTotalMoneySlice, historyAccumulate)
+	//	} else {
+	//		prevTotalMoneySlice = append(prevTotalMoneySlice, historyAmountTotal)
+	//	}
+	//	if req.ListParam == "1" {
+	//		i = i + 2
+	//	} else if req.ListParam == "2" {
+	//		i = i + 5
+	//	} else if req.ListParam == "3" {
+	//		i = i + 11
+	//	}
+	//}
+
 	fmt.Println("prevTotalMoneySlice:", len(prevTotalMoneySlice))
 	fmt.Println("totalMoneySlice:", len(totalMoneySlice))
 
@@ -1376,7 +1436,7 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 		//fmt.Println("1:", prevTotalMoneySlice[i])
 		//fmt.Println("2:", totalMoneySlice[i])
 		//fmt.Println("3:", totalMoneySlice[i]-prevTotalMoneySlice[i])
-		if prevTotalMoneySlice[i] != 0 && totalMoneySlice[i] != 0{
+		if prevTotalMoneySlice[i] != 0 && totalMoneySlice[i] != 0 {
 			yoy = (totalMoneySlice[i] - prevTotalMoneySlice[i]) / prevTotalMoneySlice[i]
 			yoyStr = fmt.Sprintf("%.4f", yoy)
 		}