animeic 1 년 전
부모
커밋
40ed2b92dd
3개의 변경된 파일31개의 추가작업 그리고 33개의 파일을 삭제
  1. 17 9
      boxcost/api/plan-summary-excel.go
  2. 5 0
      boxcost/api/print.go
  3. 9 24
      boxcost/api/summary.go

+ 17 - 9
boxcost/api/plan-summary-excel.go

@@ -20,7 +20,7 @@ type PlanSummaryExcel struct {
 func (b *PlanSummaryExcel) drawTitle() error {
 	b.Row++
 	startCell := fmt.Sprintf("A%d", b.Row)
-	err := b.Excel.MergeCell(b.SheetName, startCell, fmt.Sprintf("S%d", b.Row))
+	err := b.Excel.MergeCell(b.SheetName, startCell, fmt.Sprintf("T%d", b.Row))
 	if err != nil {
 		return err
 	}
@@ -131,11 +131,12 @@ func (b *PlanSummaryExcel) drawTableTitle() error {
 	drawCol("Q", "预算金额")
 	drawCol("R", "实际金额")
 	drawCol("S", "备注")
+	drawCol("T", "送货地址")
 	return nil
 }
 
 func (b *PlanSummaryExcel) drawRow(rowIndex int, values ...string) {
-	charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S"}
+	charas := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T"}
 	for i, c := range charas {
 		v := ""
 		if i < len(values) {
@@ -253,12 +254,12 @@ func (b *PlanSummaryExcel) drawAllContent() error {
 						}
 						// 订单存在时,订单号和下单时间// 合并相同的订单,记录row方便合并
 						if len(stage.BillId) == 24 {
-							billFlag := fmt.Sprintf("%s_%s", splan.SerialNumber[stage.BillId], splan.CreateTimes[stage.BillId].Local().Format("2006-01-02"))
+							billFlag := fmt.Sprintf("%s_%s_%s", splan.SerialNumber[stage.BillId], splan.CreateTimes[stage.BillId].Local().Format("2006-01-02"), splan.SendTo[stage.BillId])
 							cates[billFlag] = append(cates[billFlag], b.Row)
 						}
 
 						b.drawRow(b.Row, "", "", "", "", stageType, stage.Name, orderCount, realCount, stageStatus, supplierName, fmt.Sprintf("%.3f元/%s", stage.Price, stage.Unit), stage.Norm,
-							matHeigth, matWidth, unit, price, budgetPrice, realPrice, stage.Remark)
+							matHeigth, matWidth, unit, price, budgetPrice, realPrice, stage.Remark, "")
 						// if stage.SupplierInfo != nil {
 						// 	cates[stage.SupplierInfo.Name] = append(cates[stage.SupplierInfo.Name], b.Row)
 
@@ -268,13 +269,16 @@ func (b *PlanSummaryExcel) drawAllContent() error {
 					for billFlag, cate := range cates {
 						billInfo := strings.Split(billFlag, "_")
 
-						if len(billInfo) == 2 {
+						if len(billInfo) == 3 {
 							mergeStartRow := cate[0]
 							mergeEndRow := cate[len(cate)-1]
 							b.Excel.MergeCell(b.SheetName, fmt.Sprintf("C%d", mergeStartRow), fmt.Sprintf("C%d", mergeEndRow))
 							b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("C%d", mergeEndRow), billInfo[0])
 							b.Excel.MergeCell(b.SheetName, fmt.Sprintf("D%d", mergeStartRow), fmt.Sprintf("D%d", mergeEndRow))
 							b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("D%d", mergeEndRow), billInfo[1])
+
+							b.Excel.MergeCell(b.SheetName, fmt.Sprintf("T%d", mergeStartRow), fmt.Sprintf("T%d", mergeEndRow))
+							b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("T%d", mergeEndRow), billInfo[2])
 						}
 
 					}
@@ -459,12 +463,12 @@ func (b *PlanSummaryExcel) drawSupplierContent() error {
 									}
 								}
 								if len(stage.BillId) == 24 {
-									billFlag := fmt.Sprintf("%s_%s", splan.SerialNumber[stage.BillId], splan.CreateTimes[stage.BillId].Local().Format("2006-01-02"))
+									billFlag := fmt.Sprintf("%s_%s_%s", splan.SerialNumber[stage.BillId], splan.CreateTimes[stage.BillId].Local().Format("2006-01-02"), splan.SendTo[stage.BillId])
 									cates[billFlag] = append(cates[billFlag], b.Row)
 								}
 
 								b.drawRow(b.Row, "", "", "", "", stageType, stage.Name, orderCount, realCount, stageStatus, supplierName, fmt.Sprintf("%.3f元/%s", stage.Price, stage.Unit),
-									stage.Norm, matHeigth, matWidth, unit, price, budgetPrice, realPrice, stage.Remark)
+									stage.Norm, matHeigth, matWidth, unit, price, budgetPrice, realPrice, stage.Remark, "")
 								// if stage.SupplierInfo != nil {
 								// 	cates[stage.SupplierInfo.Name] = append(cates[stage.SupplierInfo.Name], b.Row)
 
@@ -477,13 +481,16 @@ func (b *PlanSummaryExcel) drawSupplierContent() error {
 
 					for billFlag, cate := range cates {
 						billInfo := strings.Split(billFlag, "_")
-						if len(billInfo) == 2 {
+						if len(billInfo) == 3 {
 							mergeStartRow := cate[0]
 							mergeEndRow := cate[len(cate)-1]
 							b.Excel.MergeCell(b.SheetName, fmt.Sprintf("C%d", mergeStartRow), fmt.Sprintf("C%d", mergeEndRow))
 							b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("C%d", mergeEndRow), billInfo[0])
 							b.Excel.MergeCell(b.SheetName, fmt.Sprintf("D%d", mergeStartRow), fmt.Sprintf("D%d", mergeEndRow))
 							b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("D%d", mergeEndRow), billInfo[1])
+
+							b.Excel.MergeCell(b.SheetName, fmt.Sprintf("T%d", mergeStartRow), fmt.Sprintf("T%d", mergeEndRow))
+							b.Excel.SetCellValue(b.SheetName, fmt.Sprintf("T%d", mergeEndRow), billInfo[2])
 						}
 					}
 
@@ -566,7 +573,7 @@ func (b *PlanSummaryExcel) drawSupplierContent() error {
 	if err != nil {
 		return err
 	}
-	err = b.Excel.SetCellStyle(b.SheetName, "A1", "G1", style)
+	err = b.Excel.SetCellStyle(b.SheetName, "A1", "T1", style)
 	if err != nil {
 		return err
 	}
@@ -618,6 +625,7 @@ func NewPlanSummaryExcel(f *excelize.File) *PlanSummaryExcel {
 	f.SetColWidth(b.SheetName, "M", "P", 12)
 	f.SetColWidth(b.SheetName, "Q", "R", 16)
 	f.SetColWidth(b.SheetName, "S", "S", 20)
+	f.SetColWidth(b.SheetName, "T", "T", 40)
 	f.SetPageMargins(b.SheetName, excelize.PageMarginTop(0), excelize.PageMarginLeft(0), excelize.PageMarginRight(0))
 	return b
 }

+ 5 - 0
boxcost/api/print.go

@@ -75,6 +75,11 @@ func Printr(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	// !如果有omitempty存在,对应字段零值将被忽略
 	// !该字段设置为引用类型
 	// !创建该字段时设置默认值
+	id, err := primitive.ObjectIDFromHex("")
+	if err != nil {
+		fmt.Println(err)
+	}
+	fmt.Println(id.IsZero())
 
 	return nil, nil
 	// type RegCode struct {

+ 9 - 24
boxcost/api/summary.go

@@ -34,6 +34,7 @@ type PlanSummary struct {
 	State        map[string]string
 	CreateTimes  map[string]time.Time
 	SerialNumber map[string]string
+	SendTo       map[string]string
 }
 
 // /summary/download?planIds=id1,id2&supplierId=xxx
@@ -42,11 +43,6 @@ func SummaryDownload(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	_planIds := c.Query("planIds")       // id1,id2...
 	_supplierId := c.Query("supplierId") // 供应商id
 	planIds := strings.Split(_planIds, ",")
-
-	planIds = filter(planIds, func(s string) bool {
-		return s != ""
-	})
-
 	supplierId, _ := primitive.ObjectIDFromHex(_supplierId)
 
 	// 获取详情
@@ -55,8 +51,8 @@ func SummaryDownload(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	}
 	summaryPlans := []*PlanSummary{}
 	for _, _planId := range planIds {
-		id, err := primitive.ObjectIDFromHex(_planId)
-		if err != nil {
+		id, _ := primitive.ObjectIDFromHex(_planId)
+		if id.IsZero() {
 			return nil, errors.New("非法id")
 		}
 		plan := &model.ProductPlan{}
@@ -109,10 +105,6 @@ func SummarySampleDownload(c *gin.Context, apictx *ApiSession) (interface{}, err
 	_supplierId := c.Query("supplierId") // 供应商id
 	planIds := strings.Split(_planIds, ",")
 
-	planIds = filter(planIds, func(s string) bool {
-		return s != ""
-	})
-
 	supplierId, _ := primitive.ObjectIDFromHex(_supplierId)
 
 	// 获取详情
@@ -121,8 +113,8 @@ func SummarySampleDownload(c *gin.Context, apictx *ApiSession) (interface{}, err
 	}
 	summaryPlans := []*PlanSummary{}
 	for _, _planId := range planIds {
-		id, err := primitive.ObjectIDFromHex(_planId)
-		if err != nil {
+		id, _ := primitive.ObjectIDFromHex(_planId)
+		if id.IsZero() {
 			return nil, errors.New("非法id")
 		}
 		plan := &model.ProductPlan{}
@@ -168,19 +160,10 @@ func SummarySampleDownload(c *gin.Context, apictx *ApiSession) (interface{}, err
 
 }
 
-func filter(arr []string, f func(string) bool) []string {
-	var filtered []string
-	for _, s := range arr {
-		if f(s) {
-			filtered = append(filtered, s)
-		}
-	}
-	return filtered
-}
-
 func GetPlanStatus(plan *model.ProductPlan, apictx *ApiSession) *PlanSummary {
 	billStates := map[string]string{}
 	billSerialNumber := map[string]string{}
+	billSendTo := map[string]string{}
 	billIsSend := map[string]bool{}
 	billReviewed := map[string]int32{}
 	billIsAck := map[string]bool{}
@@ -208,10 +191,11 @@ func GetPlanStatus(plan *model.ProductPlan, apictx *ApiSession) *PlanSummary {
 						ok, state := repo.RepoSeachDocMap(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
 							CollectName: collectName,
 							Query:       repo.Map{"_id": stage.BillId},
-							Project:     []string{"status", "isSend", "reviewed", "isAck", "serialNumber", "remark", "createTime"}})
+							Project:     []string{"status", "isSend", "reviewed", "isAck", "serialNumber", "sendTo", "remark", "createTime"}})
 						if ok {
 							billStates[stage.BillId] = state["status"].(string)
 							billSerialNumber[stage.BillId] = state["serialNumber"].(string)
+							billSendTo[stage.BillId] = state["sendTo"].(string)
 							if v, ok := state["isSend"]; ok {
 								billIsSend[stage.BillId] = v.(bool)
 
@@ -249,5 +233,6 @@ func GetPlanStatus(plan *model.ProductPlan, apictx *ApiSession) *PlanSummary {
 		State:        billStates,
 		CreateTimes:  billCreateTimes,
 		SerialNumber: billSerialNumber,
+		SendTo:       billSendTo,
 	}
 }