Browse Source

add getCompanyName func

animeic 2 years ago
parent
commit
516e4ffae8
4 changed files with 26 additions and 22 deletions
  1. 2 5
      boxcost/api/bill.go
  2. 3 6
      boxcost/api/plan.go
  3. 4 11
      boxcost/api/report.go
  4. 17 0
      boxcost/api/utils.go

+ 2 - 5
boxcost/api/bill.go

@@ -230,11 +230,8 @@ func DownLoadBills(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 	}
 	billExcel.Content = &bill
-	info := model.Setting{}
-	repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
-		CollectName: "infos",
-	}, &info)
-	billExcel.Title = fmt.Sprintf("%s原材料采购单", info.CompanyName)
+	companyName := getCompanyName(apictx)
+	billExcel.Title = fmt.Sprintf("%s原材料采购单", companyName)
 
 	//设置对应的数据
 	billExcel.Draws()

+ 3 - 6
boxcost/api/plan.go

@@ -130,10 +130,7 @@ func DownLoadPlan(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	f.SetActiveSheet(index)
 	f.SetDefaultFont("宋体")
 
-	info := model.Setting{}
-	repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
-		CollectName: "infos",
-	}, &info)
+	companyName := getCompanyName(apictx)
 
 	offset := 0
 	for _, mat := range curComp.Mats {
@@ -149,7 +146,7 @@ func DownLoadPlan(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 			if found {
 				purchaseExcel := NewPurchaseBill(f)
 				purchaseExcel.Content = &purchase
-				purchaseExcel.Title = fmt.Sprintf("%s原材料采购单", info.CompanyName)
+				purchaseExcel.Title = fmt.Sprintf("%s原材料采购单", companyName)
 				//设置对应的数据
 				purchaseExcel.Offset = offset
 				purchaseExcel.Draws()
@@ -171,7 +168,7 @@ func DownLoadPlan(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 					if found {
 						produceExcel := NewProduceBill(f)
 						produceExcel.Content = &produce
-						produceExcel.Title = fmt.Sprintf("%s加工单", info.CompanyName)
+						produceExcel.Title = fmt.Sprintf("%s加工单", companyName)
 						//设置对应的数据
 						produceExcel.Offset = offset
 						produceExcel.Draws()

+ 4 - 11
boxcost/api/report.go

@@ -74,10 +74,7 @@ func ReportProduceDownload(c *gin.Context, apictx *ApiSession) (interface{}, err
 		Border:    border,
 	})
 	offset := 0
-	info := model.Setting{}
-	repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
-		CollectName: "infos",
-	}, &info)
+	companyName := getCompanyName(apictx)
 
 	var budgetCount float64 = 0
 	var realCount float64 = 0
@@ -87,7 +84,7 @@ func ReportProduceDownload(c *gin.Context, apictx *ApiSession) (interface{}, err
 		produceExcel := NewReportProduceExcel(f)
 		produceExcel.Content = &produce
 
-		produceExcel.Title = fmt.Sprintf("%s加工单", info.CompanyName)
+		produceExcel.Title = fmt.Sprintf("%s加工单", companyName)
 		//设置对应的数据
 		produceExcel.Offset = offset
 		produceExcel.Draws()
@@ -163,11 +160,7 @@ func ReportPurchaseDownload(c *gin.Context, apictx *ApiSession) (interface{}, er
 		Border:    border,
 	})
 	offset := 0
-	info := model.Setting{}
-	repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
-		CollectName: "infos",
-	}, &info)
-
+	companyName := getCompanyName(apictx)
 	var budgetCount float64 = 0
 	var realCount float64 = 0
 	var row int = 0
@@ -175,7 +168,7 @@ func ReportPurchaseDownload(c *gin.Context, apictx *ApiSession) (interface{}, er
 	for _, purchase := range purchases {
 		purchaseExcel := NewReportPurchaseExcel(f)
 		purchaseExcel.Content = &purchase
-		purchaseExcel.Title = fmt.Sprintf("%s原材料采购单", info.CompanyName)
+		purchaseExcel.Title = fmt.Sprintf("%s原材料采购单", companyName)
 		//设置对应的数据
 		purchaseExcel.Offset = offset
 		purchaseExcel.Draws()

+ 17 - 0
boxcost/api/utils.go

@@ -125,6 +125,7 @@ func getTimeRange(startDate, endDate string) (start, end time.Time) {
 	return
 }
 
+// 处理报表query条件
 func handleReportQuery(query map[string]interface{}) map[string]interface{} {
 	// 条件处理
 	query["status"] = "complete"
@@ -162,3 +163,19 @@ func handleReportQuery(query map[string]interface{}) map[string]interface{} {
 	return query
 
 }
+
+// 获取公司名字
+func getCompanyName(apictx *ApiSession) string {
+	companyName := "中鱼互动"
+	info := model.Setting{}
+	found, _ := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+		CollectName: "infos",
+	}, &info)
+
+	if found {
+		if info.CompanyName != "" {
+			companyName = info.CompanyName
+		}
+	}
+	return companyName
+}