|
@@ -1,156 +0,0 @@
|
|
|
-func DownLoadCompBills(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
-
|
|
|
- f := excelize.NewFile()
|
|
|
- f.SetDefaultFont("宋体")
|
|
|
- flagIndex := -1
|
|
|
- // 采购 加工 加工-印刷 加工-覆膜 成品采购
|
|
|
- typeRows := []int{0, 0, 0, 0, 0}
|
|
|
- for _, tId := range typeBillIds {
|
|
|
- tidArr := strings.Split(tId, "_")
|
|
|
- var billExcel IExcel
|
|
|
- // 采购
|
|
|
- billId, _ := primitive.ObjectIDFromHex(tidArr[1])
|
|
|
- if tidArr[0] == "1" {
|
|
|
- purchase := model.PurchaseBill{}
|
|
|
- found, _ := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
|
|
|
- CollectName: repo.CollectionBillPurchase,
|
|
|
- Query: repo.Map{"_id": billId},
|
|
|
- }, &purchase)
|
|
|
- if !found {
|
|
|
- continue
|
|
|
- }
|
|
|
- sheetName := "采购单"
|
|
|
- index := f.NewSheet(sheetName)
|
|
|
- if flagIndex < 0 {
|
|
|
- flagIndex = index
|
|
|
- }
|
|
|
- // index := f.NewSheet("采购单")
|
|
|
- // f.SetActiveSheet(index)
|
|
|
- billExcel = NewPurchaseBill(f)
|
|
|
- billExcel.SetSheetName(sheetName)
|
|
|
- if purchase.Reviewed == 1 {
|
|
|
- if len(purchase.SignUsers) > 0 {
|
|
|
- signs := []*model.Signature{}
|
|
|
- repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
|
|
|
- CollectName: repo.CollectionSignature,
|
|
|
- Query: repo.Map{"_id": bson.M{"$in": purchase.SignUsers}},
|
|
|
- Sort: bson.M{"sort": 1},
|
|
|
- }, &signs)
|
|
|
- billExcel.SetSignatures(signs)
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- billExcel.SetContent(&purchase)
|
|
|
- billExcel.SetTitle(fmt.Sprintf("%s原材料采购单", companyName))
|
|
|
-
|
|
|
- billExcel.SetRow(typeRows[0])
|
|
|
- billExcel.Draws()
|
|
|
- typeRows[0] = billExcel.GetRow() + 5
|
|
|
-
|
|
|
- }
|
|
|
- // 工艺
|
|
|
- if tidArr[0] == "2" {
|
|
|
- produce := model.ProduceBill{}
|
|
|
- found, _ := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
|
|
|
- CollectName: repo.CollectionBillProduce,
|
|
|
- Query: repo.Map{"_id": billId},
|
|
|
- }, &produce)
|
|
|
- if !found {
|
|
|
- continue
|
|
|
- }
|
|
|
- sheetName := "加工单"
|
|
|
- if produce.IsPrint {
|
|
|
- sheetName = "加工单-印刷"
|
|
|
- } else if produce.IsLam {
|
|
|
- sheetName = "加工单-覆膜"
|
|
|
- }
|
|
|
- index := f.NewSheet(sheetName)
|
|
|
- if flagIndex < 0 {
|
|
|
- flagIndex = index
|
|
|
- }
|
|
|
- billExcel = NewProduceBill(f)
|
|
|
- billExcel.SetSheetName(sheetName)
|
|
|
- if produce.Reviewed == 1 {
|
|
|
- if len(produce.SignUsers) > 0 {
|
|
|
- signs := []*model.Signature{}
|
|
|
- repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
|
|
|
- CollectName: repo.CollectionSignature,
|
|
|
- Query: repo.Map{"_id": bson.M{"$in": produce.SignUsers}},
|
|
|
- Sort: bson.M{"sort": 1},
|
|
|
- }, &signs)
|
|
|
- billExcel.SetSignatures(signs)
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- billExcel.SetContent(&produce)
|
|
|
- billExcel.SetTitle(fmt.Sprintf("%s加工单", companyName))
|
|
|
-
|
|
|
- if produce.IsPrint {
|
|
|
- billExcel.SetRow(typeRows[2])
|
|
|
- billExcel.Draws()
|
|
|
- typeRows[2] = billExcel.GetRow() + 5
|
|
|
- } else if produce.IsLam {
|
|
|
- billExcel.SetRow(typeRows[3])
|
|
|
- billExcel.Draws()
|
|
|
- typeRows[3] = billExcel.GetRow() + 5
|
|
|
- } else {
|
|
|
- billExcel.SetRow(typeRows[1])
|
|
|
- billExcel.Draws()
|
|
|
- typeRows[1] = billExcel.GetRow() + 5
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- // 成品采购
|
|
|
- if tidArr[0] == "3" {
|
|
|
- product := model.ProductBill{}
|
|
|
- found, _ := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
|
|
|
- CollectName: repo.CollectionBillProduct,
|
|
|
- Query: repo.Map{"_id": billId},
|
|
|
- }, &product)
|
|
|
- if !found {
|
|
|
- continue
|
|
|
- }
|
|
|
- sheetName := "成品采购单"
|
|
|
- index := f.NewSheet(sheetName)
|
|
|
- if flagIndex < 0 {
|
|
|
- flagIndex = index
|
|
|
- }
|
|
|
- billExcel = NewProductBill(f)
|
|
|
- billExcel.SetSheetName(sheetName)
|
|
|
- if product.Reviewed == 1 {
|
|
|
- if len(product.SignUsers) > 0 {
|
|
|
- signs := []*model.Signature{}
|
|
|
- repo.RepoDocsSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
|
|
|
- CollectName: repo.CollectionSignature,
|
|
|
- Query: repo.Map{"_id": bson.M{"$in": product.SignUsers}},
|
|
|
- Sort: bson.M{"sort": 1},
|
|
|
- }, &signs)
|
|
|
- billExcel.SetSignatures(signs)
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- billExcel.SetContent(&product)
|
|
|
- billExcel.SetTitle(companyName)
|
|
|
-
|
|
|
- billExcel.SetRow(typeRows[4])
|
|
|
- billExcel.Draws()
|
|
|
- typeRows[4] = billExcel.GetRow() + 5
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- // 设置活跃sheet
|
|
|
- f.SetActiveSheet(flagIndex)
|
|
|
- // 删除默认Sheet1
|
|
|
- f.DeleteSheet("Sheet1")
|
|
|
-
|
|
|
- c.Header("Content-Type", "application/octet-stream")
|
|
|
- c.Header("Content-Disposition", "attachment; filename="+fmt.Sprintf("%s.xlsx", compNameId))
|
|
|
- c.Header("Content-Transfer-Encoding", "binary")
|
|
|
-
|
|
|
- f.Write(c.Writer)
|
|
|
-
|
|
|
- return nil, nil
|
|
|
-
|
|
|
-}
|