suncloud 1 год назад
Родитель
Сommit
c6cc3dac85
4 измененных файлов с 65 добавлено и 634 удалено
  1. 31 605
      src/api/excel.go
  2. 32 28
      src/api/test.go
  3. 0 0
      src/api/utils.go
  4. 2 1
      src/db/repo/repo.go

+ 31 - 605
src/api/excel.go

@@ -15,7 +15,7 @@ type TestExcel struct {
 	Excel            *excelize.File
 	SheetName        string
 	AlignCenterStyle int
-	Content          *model.Test
+	Content          []*model.Test
 	RowMap           map[string]int
 	RowWidthArray    []float64
 	RowsHeightArray  []map[int]float64
@@ -54,22 +54,21 @@ func (b *TestExcel) getRangeWidth(r string) float64 {
 func (b *TestExcel) drawTitle() error {
 	b.Row++
 	startCell := fmt.Sprintf("A%d", b.Row)
-	marginLeft := excelize.PageMarginLeft(0.1)
-	endCell := fmt.Sprintf("I%d", b.Row)
-
-	b.RowMap = map[string]int{"A": 0, "B": 1, "C": 2, "D": 3, "E": 4, "F": 5, "G": 6, "H": 7, "I": 8}
-	b.RowWidthArray = []float64{11, 11, 11, 10, 7, 10, 7, 6.5, 9, 9, 12, 14}
-	b.Excel.SetColWidth(b.SheetName, "A", "C", 11)
+	// marginLeft := excelize.PageMarginLeft(0.1)
+	endCell := fmt.Sprintf("H%d", b.Row)
+
+	b.RowMap = map[string]int{"A": 0, "B": 1, "C": 2, "D": 3, "E": 4, "F": 5, "G": 6, "H": 7}
+	b.RowWidthArray = []float64{11, 11, 11, 10, 7, 10, 7, 6.5}
+	b.Excel.SetColWidth(b.SheetName, "A", "A", 11)
+	b.Excel.SetColWidth(b.SheetName, "B", "B", 10)
+	b.Excel.SetColWidth(b.SheetName, "C", "C", 7)
 	b.Excel.SetColWidth(b.SheetName, "D", "D", 10)
 	b.Excel.SetColWidth(b.SheetName, "E", "E", 7)
-	b.Excel.SetColWidth(b.SheetName, "F", "F", 10)
-	b.Excel.SetColWidth(b.SheetName, "G", "G", 7)
-	b.Excel.SetColWidth(b.SheetName, "H", "H", 6.5)
-	b.Excel.SetColWidth(b.SheetName, "I", "J", 9)
-	b.Excel.SetColWidth(b.SheetName, "K", "K", 12)
-	b.Excel.SetColWidth(b.SheetName, "L", "L", 14)
+	b.Excel.SetColWidth(b.SheetName, "F", "F", 6.5)
+	b.Excel.SetColWidth(b.SheetName, "G", "G", 9)
+	b.Excel.SetColWidth(b.SheetName, "H", "H", 12)
 
-	b.Excel.SetPageMargins(b.SheetName, marginLeft)
+	// b.Excel.SetPageMargins(b.SheetName, marginLeft)
 	err := b.Excel.MergeCell(b.SheetName, startCell, endCell)
 	if err != nil {
 		return err
@@ -90,247 +89,8 @@ func (b *TestExcel) drawTitle() error {
 	return nil
 }
 
-func (b *TestExcel) drawSubTitles() error {
-	b.Row++
-	styleLeft, err := b.Excel.NewStyle(&excelize.Style{
-		Alignment: &excelize.Alignment{Horizontal: "left", Vertical: "center", WrapText: true},
-		Font:      &excelize.Font{Size: 11}})
-	if err != nil {
-		return err
-	}
-	styleRight, err := b.Excel.NewStyle(&excelize.Style{
-		Alignment: &excelize.Alignment{Horizontal: "right", Vertical: "center"},
-		Font:      &excelize.Font{Size: 11}})
-	if err != nil {
-		return err
-	}
-
-	drawLeft := func(rowIndex int, value string) error {
-		//左边1
-		left1Cell := fmt.Sprintf("A%d", rowIndex)
-		err = b.Excel.MergeCell(b.SheetName, left1Cell, fmt.Sprintf("I%d", rowIndex))
-		if err != nil {
-			return err
-		}
-		err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left1Cell, styleLeft)
-		if err != nil {
-			return err
-		}
-		b.Excel.SetCellValue(b.SheetName, left1Cell, value)
-		// 设置行高
-		b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{rowIndex: getRowHeight(value, b.getRangeWidth("A:I"))})
-		return nil
-	}
-
-	drawRight := func(rowIndex int, value string) error {
-		right1Cell := fmt.Sprintf("J%d", rowIndex)
-		err = b.Excel.MergeCell(b.SheetName, right1Cell, fmt.Sprintf("L%d", rowIndex))
-		if err != nil {
-			return err
-		}
-		err = b.Excel.SetCellStyle(b.SheetName, right1Cell, right1Cell, styleRight)
-		if err != nil {
-			return err
-		}
-		b.Excel.SetCellValue(b.SheetName, right1Cell, value)
-		return nil
-	}
-
-	drawLall := func(rowIndex int, value string) error {
-		//左边1
-		left1Cell := fmt.Sprintf("A%d", rowIndex)
-		err = b.Excel.MergeCell(b.SheetName, left1Cell, fmt.Sprintf("L%d", rowIndex))
-		if err != nil {
-			return err
-		}
-		err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left1Cell, styleLeft)
-		if err != nil {
-			return err
-		}
-		b.Excel.SetCellValue(b.SheetName, left1Cell, value)
-		// 设置行高
-		b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{rowIndex: getRowHeight(value, b.getRangeWidth("A:L"))})
-		return nil
-	}
-
-	if !b.Content.IsPrint {
-		drawLeft = func(rowIndex int, value string) error {
-			//左边1
-			left1Cell := fmt.Sprintf("A%d", rowIndex)
-			err = b.Excel.MergeCell(b.SheetName, left1Cell, fmt.Sprintf("F%d", rowIndex))
-			if err != nil {
-				return err
-			}
-			err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left1Cell, styleLeft)
-			if err != nil {
-				return err
-			}
-			b.Excel.SetCellValue(b.SheetName, left1Cell, value)
-			// 设置行高
-			b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{rowIndex: getRowHeight(value, b.getRangeWidth("A:F"))})
-			return nil
-		}
-
-		drawRight = func(rowIndex int, value string) error {
-			right1Cell := fmt.Sprintf("G%d", rowIndex)
-			err = b.Excel.MergeCell(b.SheetName, right1Cell, fmt.Sprintf("H%d", rowIndex))
-			if err != nil {
-				return err
-			}
-			err = b.Excel.SetCellStyle(b.SheetName, right1Cell, right1Cell, styleRight)
-			if err != nil {
-				return err
-			}
-			b.Excel.SetCellValue(b.SheetName, right1Cell, value)
-			return nil
-		}
-
-		drawLall = func(rowIndex int, value string) error {
-			//左边1
-			left1Cell := fmt.Sprintf("A%d", rowIndex)
-			err = b.Excel.MergeCell(b.SheetName, left1Cell, fmt.Sprintf("H%d", rowIndex))
-			if err != nil {
-				return err
-			}
-			err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left1Cell, styleLeft)
-			if err != nil {
-				return err
-			}
-			b.Excel.SetCellValue(b.SheetName, left1Cell, value)
-			// 设置行高
-			b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{rowIndex: getRowHeight(value, b.getRangeWidth("A:H"))})
-			return nil
-		}
-		if b.Content.IsLam {
-			drawLeft = func(rowIndex int, value string) error {
-				//左边1
-				left1Cell := fmt.Sprintf("A%d", rowIndex)
-				err = b.Excel.MergeCell(b.SheetName, left1Cell, fmt.Sprintf("F%d", rowIndex))
-				if err != nil {
-					return err
-				}
-				err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left1Cell, styleLeft)
-				if err != nil {
-					return err
-				}
-				b.Excel.SetCellValue(b.SheetName, left1Cell, value)
-				// 设置行高
-				b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{rowIndex: getRowHeight(value, b.getRangeWidth("A:F"))})
-				return nil
-			}
-
-			drawRight = func(rowIndex int, value string) error {
-				right1Cell := fmt.Sprintf("G%d", rowIndex)
-				err = b.Excel.MergeCell(b.SheetName, right1Cell, fmt.Sprintf("I%d", rowIndex))
-				if err != nil {
-					return err
-				}
-				err = b.Excel.SetCellStyle(b.SheetName, right1Cell, right1Cell, styleRight)
-				if err != nil {
-					return err
-				}
-				b.Excel.SetCellValue(b.SheetName, right1Cell, value)
-				return nil
-			}
-
-			drawLall = func(rowIndex int, value string) error {
-				//左边1
-				left1Cell := fmt.Sprintf("A%d", rowIndex)
-				err = b.Excel.MergeCell(b.SheetName, left1Cell, fmt.Sprintf("I%d", rowIndex))
-				if err != nil {
-					return err
-				}
-				err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left1Cell, styleLeft)
-				if err != nil {
-					return err
-				}
-				b.Excel.SetCellValue(b.SheetName, left1Cell, value)
-				// 设置行高
-				b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{rowIndex: getRowHeight(value, b.getRangeWidth("A:I"))})
-				return nil
-			}
-
-		}
-		if b.Content.IsPaper {
-			drawLeft = func(rowIndex int, value string) error {
-				//左边1
-				left1Cell := fmt.Sprintf("A%d", rowIndex)
-				err = b.Excel.MergeCell(b.SheetName, left1Cell, fmt.Sprintf("H%d", rowIndex))
-				if err != nil {
-					return err
-				}
-				err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left1Cell, styleLeft)
-				if err != nil {
-					return err
-				}
-				b.Excel.SetCellValue(b.SheetName, left1Cell, value)
-				// 设置行高
-				b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{rowIndex: getRowHeight(value, b.getRangeWidth("A:H"))})
-				return nil
-			}
-
-			drawRight = func(rowIndex int, value string) error {
-				right1Cell := fmt.Sprintf("I%d", rowIndex)
-				err = b.Excel.MergeCell(b.SheetName, right1Cell, fmt.Sprintf("K%d", rowIndex))
-				if err != nil {
-					return err
-				}
-				err = b.Excel.SetCellStyle(b.SheetName, right1Cell, right1Cell, styleRight)
-				if err != nil {
-					return err
-				}
-				b.Excel.SetCellValue(b.SheetName, right1Cell, value)
-				return nil
-			}
-
-			drawLall = func(rowIndex int, value string) error {
-				//左边1
-				left1Cell := fmt.Sprintf("A%d", rowIndex)
-				err = b.Excel.MergeCell(b.SheetName, left1Cell, fmt.Sprintf("K%d", rowIndex))
-				if err != nil {
-					return err
-				}
-				err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left1Cell, styleLeft)
-				if err != nil {
-					return err
-				}
-				b.Excel.SetCellValue(b.SheetName, left1Cell, value)
-				// 设置行高
-				b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{rowIndex: getRowHeight(value, b.getRangeWidth("A:K"))})
-				return nil
-			}
-
-		}
-	}
-
-	//第一行
-	drawLeft(b.Row, "类别:"+b.Content.Type)
-	drawRight(b.Row, "单号:"+b.Content.SerialNumber)
-
-	//第二行
-	drawLeft(b.Row+1, "供应商名称:"+b.Content.Supplier)
-	timeformat := b.Content.CreateTime.Local().Format("2006年01月02号 15:04:05")
-	drawRight(b.Row+1, "下单时间:"+timeformat)
-
-	//第三行
-	drawLeft(b.Row+2, "产品名称:"+b.Content.ProductName)
-	status := ""
-	if b.Content.Status == "complete" {
-		status = "已完成"
-	}
-	if b.Content.Status == "created" {
-		status = "进行中"
-	}
-	drawRight(b.Row+2, "状态:"+status)
-
-	// 第四行
-	drawLall(b.Row+3, "包含工序:"+b.Content.CompProduceName)
-
-	return nil
-}
-
 func (b *TestExcel) drawTableTitle() error {
-	b.Row += 4
+	b.Row++
 	var drawCol = func(prefix string, value string) error {
 		left1Cell := fmt.Sprintf("%s%d", prefix, b.Row)
 		left2Cell := fmt.Sprintf("%s%d", prefix, b.Row+1)
@@ -347,82 +107,14 @@ func (b *TestExcel) drawTableTitle() error {
 		return b.Excel.SetCellValue(b.SheetName, left1Cell, value)
 	}
 
-	var drawCol3 = func(prefix1 string, prefix2 string, value1 string, value2 string, value3 string) error {
-		left1Cell := fmt.Sprintf("%s%d", prefix1, b.Row)
-		left2Cell := fmt.Sprintf("%s%d", prefix2, b.Row)
-		err := b.Excel.MergeCell(b.SheetName, left1Cell, left2Cell)
-		if err != nil {
-			return err
-		}
-		if err != nil {
-			fmt.Println(err)
-			return err
-		}
-		err = b.Excel.SetCellStyle(b.SheetName, left1Cell, left2Cell, b.AlignCenterStyle)
-		if err != nil {
-			return err
-		}
-		b.Excel.SetCellValue(b.SheetName, left1Cell, value1)
-
-		val2Cel := fmt.Sprintf("%s%d", prefix1, b.Row+1)
-		b.Excel.SetCellStyle(b.SheetName, val2Cel, val2Cel, b.AlignCenterStyle)
-		b.Excel.SetCellValue(b.SheetName, val2Cel, value2)
-
-		val3Cel := fmt.Sprintf("%s%d", prefix2, b.Row+1)
-		b.Excel.SetCellStyle(b.SheetName, val3Cel, val3Cel, b.AlignCenterStyle)
-		b.Excel.SetCellValue(b.SheetName, val3Cel, value3)
-		return nil
-	}
-
-	unit := b.Content.Produces[0].Unit
-	if b.Content.IsPrint {
-		drawCol("A", "加工项目")
-		drawCol("B", "规格")
-		drawCol("C", "纸张")
-		drawCol("D", "来纸尺寸")
-		drawCol("E", "来纸数量")
-		drawCol("F", "印刷尺寸")
-		drawCol("G", "下单数量")
-		drawCol("H", "单位")
-		drawCol("I", "单价")
-		drawCol("J", "预算金额")
-		drawCol("K", "交货时间")
-		drawCol("L", "备注")
-
-	} else if b.Content.IsLam {
-
-		drawCol("A", "加工项目")
-		drawCol("B", "规格")
-		drawCol("C", "覆膜尺寸")
-		drawCol("D", "下单数量")
-		unit2 := b.Content.Produces[0].Unit2
-		drawCol3("E", "F", "单价", unit, unit2)
-		drawCol("G", "预算金额")
-		drawCol("H", "交货时间")
-		drawCol("I", "备注")
-	} else if b.Content.IsPaper {
-		drawCol("A", "加工项目")
-		drawCol("B", "规格")
-		drawCol("C", "纸张")
-		drawCol("D", "来纸数量")
-		drawCol("E", "来纸尺寸")
-		drawCol("F", "下单数量")
-		drawCol("G", "单位")
-		drawCol("H", "单价")
-		drawCol("I", "预算金额")
-		drawCol("J", "交货时间")
-		drawCol("K", "备注")
-	} else {
-		drawCol("A", "加工项目")
-		drawCol("B", "规格")
-		drawCol("C", "下单数量")
-		drawCol("D", "单位")
-		drawCol("E", "单价")
-		drawCol("F", "预算金额")
-		drawCol("G", "交货时间")
-		drawCol("H", "备注")
-
-	}
+	drawCol("A", "题目")
+	drawCol("B", "类型")
+	drawCol("C", "选项A")
+	drawCol("D", "选项B")
+	drawCol("E", "选项C")
+	drawCol("F", "选项D")
+	drawCol("G", "分值")
+	drawCol("H", "答案")
 
 	return nil
 }
@@ -431,16 +123,7 @@ func (b *TestExcel) drawTableContent() error {
 	b.Row += 2
 	var DrawRow = func(rowIndex int, values ...string) float64 {
 		charas := []string{"A", "B", "C", "D", "E", "F", "G", "H"}
-		if !b.Content.IsPrint {
-			charas = []string{"A", "B", "C", "D", "E", "F", "G", "H"}
-			if b.Content.IsLam {
-				charas = []string{"A", "B", "C", "D", "E", "F", "G", "H", "I"}
-			}
-			if b.Content.IsPaper {
-				charas = []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K"}
-			}
-		}
-		// 获取改行最大行高
+		// 获取该行最大行高
 		max := getRowHeight(values[0], b.getRangeWidth(charas[0]))
 		for i, c := range charas {
 			v := ""
@@ -458,53 +141,10 @@ func (b *TestExcel) drawTableContent() error {
 		return max
 	}
 
-	produces := b.Content.Produces
-	if len(produces) > 0 {
-		for _, produce := range produces {
-			realCount := ""
-			price := produce.OrderPrice
-			priceStr := fmt.Sprintf("%.3f", price)
-			b.FormatToEmpty(&priceStr)
-			// 预算金额
-			budgetAmount := fmt.Sprintf("%.3f", produce.OrderPrice*float64(produce.OrderCount))
-			b.FormatToEmpty(&budgetAmount)
-			// 实际金额
-			realPrice := ""
-			// 实际完成数
-			realCount = fmt.Sprintf("%d", produce.ConfirmCount)
-			b.FormatToEmpty(&realCount)
-			realPrice = fmt.Sprintf("%.3f", produce.OrderPrice*float64(produce.ConfirmCount))
-
-			// !10.27 如果是固定价格
-			if produce.IsFix == nil {
-				_fix := false
-				produce.IsFix = &_fix
-			}
-			if *produce.IsFix {
-				realPrice = budgetAmount
-			}
-
-			b.FormatToEmpty(&realPrice)
-
-			deliveryTime := produce.DeliveryTime.Local().Format("2006-01-02")
-
-			paperCount := fmt.Sprintf("%d", produce.PaperCount)
-			b.FormatToEmpty(&paperCount)
-
-			rowMaxHeight := 0.0
-			if b.Content.IsPrint {
-				rowMaxHeight = DrawRow(b.Row, produce.Name, produce.Norm, produce.Paper, produce.PaperSize, paperCount, produce.PrintSize, fmt.Sprintf("%d", produce.OrderCount), produce.Unit, priceStr, budgetAmount, deliveryTime, produce.Remark)
-			} else if b.Content.IsLam {
-				// 覆膜
-				rowMaxHeight = DrawRow(b.Row, produce.Name, produce.Norm, produce.PrintSize, fmt.Sprintf("%d", produce.OrderCount), priceStr, fmt.Sprintf("%.3f", produce.Price2), budgetAmount, deliveryTime, produce.Remark)
-
-			} else if b.Content.IsPaper {
-				// 对裱
-				rowMaxHeight = DrawRow(b.Row, produce.Name, produce.Norm, produce.Paper, paperCount, produce.PaperSize, fmt.Sprintf("%d", produce.OrderCount), produce.Unit, priceStr, budgetAmount, deliveryTime, produce.Remark)
-			} else {
-				rowMaxHeight = DrawRow(b.Row, produce.Name, produce.Norm, fmt.Sprintf("%d", produce.OrderCount), produce.Unit, priceStr, budgetAmount, deliveryTime, produce.Remark)
-			}
-
+	tests := b.Content
+	if len(tests) > 0 {
+		for _, test := range tests {
+			rowMaxHeight := DrawRow(b.Row, test.Content, test.Type, test.Options["A"], test.Options["B"], test.Options["C"], test.Options["D"], fmt.Sprintf("%d", *test.Socre), test.Answer)
 			b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: rowMaxHeight})
 			b.Row++
 		}
@@ -513,201 +153,16 @@ func (b *TestExcel) drawTableContent() error {
 	return nil
 }
 
-func (b *TestExcel) drawTableFooter() error {
-	border := []excelize.Border{
-		{Type: "top", Style: 1, Color: "000000"},
-		{Type: "left", Style: 1, Color: "000000"},
-		{Type: "right", Style: 1, Color: "000000"},
-		{Type: "bottom", Style: 1, Color: "000000"},
-	}
-
-	styleLeft, _ := b.Excel.NewStyle(&excelize.Style{
-		Alignment: &excelize.Alignment{Horizontal: "left", Vertical: "center", WrapText: true},
-		Border:    border,
-	})
-
-	sendToStartCell := fmt.Sprintf("A%d", b.Row)
-
-	sendToEndCell := fmt.Sprintf("I%d", b.Row)
-	supplierStartCell := fmt.Sprintf("J%d", b.Row)
-	supplierEndCell := fmt.Sprintf("L%d", b.Row)
-	b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: getRowHeight("送货地址:"+b.Content.SendTo, b.getRangeWidth("A:I"))})
-	if !b.Content.IsPrint {
-		sendToEndCell = fmt.Sprintf("E%d", b.Row)
-		supplierStartCell = fmt.Sprintf("F%d", b.Row)
-		supplierEndCell = fmt.Sprintf("H%d", b.Row)
-		b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: getRowHeight("送货地址:"+b.Content.SendTo, b.getRangeWidth("A:E"))})
-
-		if b.Content.IsLam {
-			sendToEndCell = fmt.Sprintf("F%d", b.Row)
-			supplierStartCell = fmt.Sprintf("G%d", b.Row)
-			supplierEndCell = fmt.Sprintf("I%d", b.Row)
-			b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: getRowHeight("送货地址:"+b.Content.SendTo, b.getRangeWidth("A:F"))})
-
-		}
-		if b.Content.IsPaper {
-			sendToEndCell = fmt.Sprintf("H%d", b.Row)
-			supplierStartCell = fmt.Sprintf("I%d", b.Row)
-			supplierEndCell = fmt.Sprintf("K%d", b.Row)
-			b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: getRowHeight("送货地址:"+b.Content.SendTo, b.getRangeWidth("A:K"))})
-
-		}
-	}
-
-	b.Excel.MergeCell(b.SheetName, sendToStartCell, sendToEndCell)
-	b.Excel.SetCellStyle(b.SheetName, sendToStartCell, sendToEndCell, styleLeft)
-	b.Excel.SetCellValue(b.SheetName, sendToStartCell, "送货地址:"+b.Content.SendTo)
-	b.Excel.MergeCell(b.SheetName, supplierStartCell, supplierEndCell)
-	b.Excel.SetCellStyle(b.SheetName, supplierStartCell, supplierEndCell, styleLeft)
-	b.Excel.SetCellValue(b.SheetName, supplierStartCell, "供应商签字:")
-
-	return nil
-}
-func (b *TestExcel) drawSupplierRemark() error {
-	b.Row++
-	border := []excelize.Border{
-		{Type: "top", Style: 1, Color: "000000"},
-		{Type: "left", Style: 1, Color: "000000"},
-		{Type: "right", Style: 1, Color: "000000"},
-		{Type: "bottom", Style: 1, Color: "000000"},
-	}
-
-	styleLeft, _ := b.Excel.NewStyle(&excelize.Style{
-		Alignment: &excelize.Alignment{Horizontal: "left", Vertical: "center", WrapText: true},
-		Border:    border,
-	})
-
-	sendToStartCell := fmt.Sprintf("A%d", b.Row)
-
-	sendToEndCell := fmt.Sprintf("L%d", b.Row)
-	// 设置行高
-	b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: getRowHeight("供应商备注:"+b.Content.SupplierRemark, b.getRangeWidth("A:L"))})
-	if !b.Content.IsPrint {
-		sendToEndCell = fmt.Sprintf("H%d", b.Row)
-		// 设置行高
-		b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: getRowHeight("供应商备注:"+b.Content.SupplierRemark, b.getRangeWidth("A:H"))})
-
-		if b.Content.IsLam || b.Content.IsPaper {
-			sendToEndCell = fmt.Sprintf("I%d", b.Row)
-			// 设置行高
-			b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: getRowHeight("供应商备注:"+b.Content.SupplierRemark, b.getRangeWidth("A:I"))})
-
-		}
-		if b.Content.IsPaper {
-			sendToEndCell = fmt.Sprintf("K%d", b.Row)
-			// 设置行高
-			b.RowsHeightArray = append(b.RowsHeightArray, map[int]float64{b.Row: getRowHeight("供应商备注:"+b.Content.SupplierRemark, b.getRangeWidth("A:K"))})
-
-		}
-	}
-
-	b.Excel.MergeCell(b.SheetName, sendToStartCell, sendToEndCell)
-	b.Excel.SetCellStyle(b.SheetName, sendToStartCell, sendToEndCell, styleLeft)
-	b.Excel.SetCellValue(b.SheetName, sendToStartCell, "供应商备注:"+b.Content.SupplierRemark)
-	return nil
-
-}
-
-func (b *TestExcel) drawTableSignature() error {
-	b.Row += 2
-
-	style1, _ := b.Excel.NewStyle(&excelize.Style{
-		Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
-		// Border:    border,
-	})
-
-	// 制单人
-	billUserCellS := fmt.Sprintf("A%d", b.Row+1)
-	billUserCellE := fmt.Sprintf("B%d", b.Row+1)
-	b.Excel.MergeCell(b.SheetName, billUserCellS, billUserCellE)
-	b.Excel.SetCellValue(b.SheetName, billUserCellS, "制单人:"+b.Content.UserName)
-
-	fontNum := "G"
-	fontENum := "H"
-	image1s := "I"
-	image2s := "K"
-	image1e := "J"
-	image2e := "L"
-	if !b.Content.IsPrint {
-		fontNum = "E"
-		fontENum = "E"
-		image1s = "F"
-		image2s = "H"
-		image1e = "G"
-		image2e = "H"
-		if b.Content.IsLam {
-			fontNum = "E"
-			fontENum = "E"
-			image1s = "F"
-			image2s = "H"
-			image1e = "G"
-			image2e = "I"
-
-		}
-		if b.Content.IsPaper {
-			fontNum = "G"
-			fontENum = "G"
-			image1s = "H"
-			image2s = "J"
-			image1e = "I"
-			image2e = "K"
-
-		}
-	}
-
-	fontCell := fmt.Sprintf("%s%d", fontNum, b.Row)
-	fontEndCell := fmt.Sprintf("%s%d", fontENum, b.Row+2)
-
-	imageCell1 := fmt.Sprintf("%s%d", image1s, b.Row)
-	imageEndCell1 := fmt.Sprintf("%s%d", image1e, b.Row+2)
-
-	imageCell2 := fmt.Sprintf("%s%d", image2s, b.Row)
-	imageEndCell2 := fmt.Sprintf("%s%d", image2e, b.Row+2)
-
-	b.Excel.MergeCell(b.SheetName, fontCell, fontEndCell)
-	b.Excel.SetCellStyle(b.SheetName, fontCell, fontCell, style1)
-	b.Excel.SetCellValue(b.SheetName, fontCell, "审核签字:")
-
-	// 签字图片1 I10-J12
-	b.Excel.MergeCell(b.SheetName, imageCell1, imageEndCell1)
-	b.Excel.SetCellStyle(b.SheetName, imageCell1, imageCell1, style1)
-	b.Excel.SetCellValue(b.SheetName, imageCell1, "")
-
-	// 签字图片2 K10-L12
-	b.Excel.MergeCell(b.SheetName, imageCell2, imageEndCell2)
-	b.Excel.SetCellStyle(b.SheetName, imageCell2, imageCell1, style1)
-	b.Excel.SetCellValue(b.SheetName, imageCell2, "")
-
-	// 状态为已审核时,签字
-	if b.Content.Reviewed == 1 {
-		imageCells := []string{imageCell1, imageCell2}
-		if len(b.Signatures) > 0 {
-			for k, sign := range b.Signatures {
-				b.Excel.AddPicture(b.SheetName, imageCells[k], sign.Path, sign.Format)
-
-			}
-		}
-	}
-
-	return nil
-}
-
 func (b *TestExcel) Draws() {
 	b.drawTitle()
-	b.drawSubTitles()
+
 	b.drawTableTitle()
 	b.drawTableContent()
-	b.drawTableFooter()
-	if len(b.Content.SupplierRemark) > 1 {
-		b.drawSupplierRemark()
-
-	}
-	b.drawTableSignature()
 	// 设置行高
 	b.setRowsHeight()
 }
 
-func NewProduceBill(f *excelize.File) *TestExcel {
+func NewTestExcel(f *excelize.File) *TestExcel {
 
 	border := []excelize.Border{
 		{Type: "top", Style: 1, Color: "000000"},
@@ -722,7 +177,7 @@ func NewProduceBill(f *excelize.File) *TestExcel {
 	})
 
 	b := &TestExcel{
-		Title:            "中鱼互动加工单",
+		Title:            "考核试题",
 		SheetName:        "Sheet1",
 		Excel:            f,
 		Offset:           0,
@@ -732,7 +187,7 @@ func NewProduceBill(f *excelize.File) *TestExcel {
 		RowsHeightArray:  make([]map[int]float64, 0),
 	}
 
-	f.SetPageMargins(b.SheetName, excelize.PageMarginTop(1), excelize.PageMarginLeft(0), excelize.PageMarginRight(0))
+	// f.SetPageMargins(b.SheetName, excelize.PageMarginTop(1), excelize.PageMarginLeft(0), excelize.PageMarginRight(0))
 
 	return b
 }
@@ -743,32 +198,3 @@ func (b *TestExcel) FormatToEmpty(str *string) {
 	}
 
 }
-
-func (b *TestExcel) SetContent(content interface{}) {
-	b.Content = content.(*model.ProduceBill)
-
-}
-func (b *TestExcel) SetTitle(title string) {
-	b.Title = title
-
-}
-
-func (b *TestExcel) SetSheetName(name string) {
-	b.SheetName = name
-
-}
-func (b *TestExcel) SetRow(row int) {
-	b.Row = row
-}
-
-func (b *TestExcel) SetIsPdf(isPdf string) {
-	b.IsPdf = isPdf
-}
-func (b *TestExcel) GetRow() int {
-	return b.Row
-}
-
-func (b *TestExcel) SetSignatures(sign interface{}) {
-	b.Signatures = sign.([]*model.Signature)
-
-}

+ 32 - 28
src/api/test.go

@@ -178,6 +178,10 @@ func ImportTest(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 			if index == 0 {
 				continue
 			}
+			// 表头
+			if index == 1 {
+				continue
+			}
 			// 去除可能的空行
 			if len(ts[0]) < 3 {
 				continue
@@ -209,7 +213,7 @@ func ImportTest(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 			test.UpdateTime = time.Now()
 
 			rowNum := index + 1
-			_, err = repo.RepoAddDoc(apictx.CreateRepoCtx(), repo.CollectionTest, test)
+			_, err = repo.RepoAddDbDoc(apictx.CreateRepoCtx(), db, repo.CollectionTest, test)
 			if err != nil {
 				errors = append(errors, fmt.Sprintf("第%d行错误: %s", rowNum, "保存数据失败, 请检查数据格式是否正确"))
 				log.Error(err)
@@ -223,38 +227,39 @@ func ImportTest(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 // 导出试题
 func ExportTest(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	isAdmin, err := IsAdmin(c, apictx)
+	if err != nil {
+		return nil, err
+	}
+	if !isAdmin {
+		return nil, errors.New("没有权限")
+	}
+	db := c.Param("scope")
+	if len(db) == 0 {
+		return nil, errors.New("scope不能为空")
+	}
 	f := excelize.NewFile()
-	// Create a new sheet.
-	index := f.NewSheet("Sheet1")
+	index, _ := f.NewSheet("Sheet1")
 	f.SetActiveSheet(index)
 	f.SetDefaultFont("宋体")
 
-	billExcel := NewProduceBill(f)
-	// 获取已审核的签名数据
-	if bill.Reviewed == 1 {
-		if len(bill.SignUsers) > 0 {
-			signs := []*model.Signature{}
-			repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
-				CollectName: repo.CollectionSignature,
-				Query:       repo.Map{"_id": bson.M{"$in": bill.SignUsers}},
-				Sort:        bson.M{"sort": 1}, // 升序
-			}, &signs)
-			billExcel.Signatures = signs
-		}
+	testExcel := NewTestExcel(f)
+	testExcel.Title = fmt.Sprintf("%s-考核试题", db)
 
+	_, _, query := UtilQueryPageSize(c)
+	// 获取试题列表
+	tests := make([]*model.Test, 0)
+	err = repo.RepoSeachDocs(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+		Db:          db,
+		CollectName: repo.CollectionTest,
+		Query:       query,
+		Sort:        bson.M{"createTime": 1},
+	}, &tests)
+	if err != nil {
+		return nil, err
 	}
-	// 覆膜、打印与其他有来纸尺寸类型互斥
-	// 如果是这两种类型,不管isPaper的值,都需要有自己的表格
-	if bill.IsLam || bill.IsPrint {
-		bill.IsPaper = false
-	}
-	billExcel.Content = &bill
-	billExcel.IsPdf = isPdf
-	companyName := getCompanyName(apictx)
-	billExcel.Title = fmt.Sprintf("%s加工单", companyName)
-	//设置对应的数据
-	billExcel.Draws()
-
+	testExcel.Content = tests
+	testExcel.Draws()
 	c.Header("Content-Type", "application/octet-stream")
 	c.Header("Content-Disposition", "attachment; filename="+"bill.xlsx")
 	c.Header("Content-Transfer-Encoding", "binary")
@@ -265,7 +270,6 @@ func ExportTest(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	}
 
 	return nil, nil
-	return nil, nil
 }
 
 // 下载试题模板

+ 0 - 0
src/api/const.go → src/api/utils.go


+ 2 - 1
src/db/repo/repo.go

@@ -193,7 +193,8 @@ func RepoSeachDoc(ctx *RepoSession, param *DocSearchOptions, v interface{}) (boo
 
 func RepoSeachDocs(ctx *RepoSession, param *DocSearchOptions, out interface{}) error {
 
-	colls := ctx.Client.GetCollection(param.CollectName)
+	colls := ctx.Client.GetDbCollection(param.Db, param.CollectName)
+	// colls := ctx.Client.GetCollection(param.CollectName)
 	opt := &options.FindOptions{}
 	if len(param.Project) > 0 {
 		prj := bson.M{}