sunsheng 9 months ago
parent
commit
d84e3d2feb
11 changed files with 761 additions and 9 deletions
  1. 1 2
      app.yaml
  2. 61 0
      db/db.go
  3. 235 0
      el/excel.go
  4. 7 0
      go.mod
  5. 17 0
      go.sum
  6. 32 7
      main.go
  7. 282 0
      model/bill.go
  8. 121 0
      model/plan.go
  9. 5 0
      readme.md
  10. 0 0
      tmplate/tmplate-原始.xlsx
  11. BIN
      tmplate/tmplate.xlsx

+ 1 - 2
app.yaml

@@ -1,3 +1,2 @@
 plans:
-  - "xxdwewe"
-  - "xxxxdd"
+  - "6648181a23830800fd7751fd"

+ 61 - 0
db/db.go

@@ -0,0 +1,61 @@
+package db
+
+import (
+	"context"
+	"log"
+	"time"
+
+	"go.mongodb.org/mongo-driver/mongo"
+	"go.mongodb.org/mongo-driver/mongo/options"
+)
+
+const (
+	MONGODB_URI = "mongodb://root:boxcost@124.71.139.24:37030/box-cost?authSource=admin"
+	DB_NAME     = "box-cost"
+	COLL_NAME   = "product-plan"
+)
+
+var (
+	client     *mongo.Client
+	collection *mongo.Collection
+)
+
+// 初始化MongoDB连接
+func InitMongoConn() {
+	// 创建一个新的上下文
+	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
+	defer cancel()
+
+	// 连接到MongoDB
+	var err error
+	client, err = mongo.Connect(ctx, options.Client().ApplyURI(MONGODB_URI))
+	if err != nil {
+		log.Fatal(err)
+	}
+
+	// 选择数据库和集合
+	collection = client.Database(DB_NAME).Collection(COLL_NAME)
+}
+
+// 获取已初始化的集合
+func GetCollection() *mongo.Collection {
+	if collection == nil {
+		log.Fatal("MongoDB connection not initialized")
+	}
+	return collection
+}
+
+// 关闭MongoDB连接
+func CloseMongoConn() {
+	if client != nil {
+		// 创建一个新的上下文
+		ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
+		defer cancel()
+
+		// 关闭连接
+		err := client.Disconnect(ctx)
+		if err != nil {
+			log.Fatal(err)
+		}
+	}
+}

+ 235 - 0
el/excel.go

@@ -0,0 +1,235 @@
+package el
+
+import (
+	"box-cost/model"
+	"context"
+	"fmt"
+	"log"
+	"regexp"
+	"strings"
+	"time"
+
+	"github.com/xuri/excelize/v2"
+	"go.mongodb.org/mongo-driver/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
+	"go.mongodb.org/mongo-driver/mongo"
+)
+
+const (
+	EXCEL_TMPLATE_FILE  = "tmplate/tmplate.xlsx"
+	PURCHASE_COLLECTION = "bill-purchase"
+	PRODUCE_COLLECTION  = "bill-produce"
+	PRODUCT_COLLECTION  = "bill-product"
+)
+
+var needChangeCol = map[string]string{
+	"部件": "E",
+	"下单": "F",
+	"纸张": "G",
+	"印刷": "H",
+	"覆膜": "I",
+	"烫金": "J",
+	"丝印": "K",
+	"对裱": "L",
+	"压纹": "M",
+	"裱瓦": "N",
+	"模切": "O",
+	"粘盒": "P",
+	"组装": "Q",
+}
+
+func MatchString(targetStr string, regexPattern string) bool {
+	// 编译正则表达式
+	re := regexp.MustCompile(regexPattern)
+	// 检查目标字符串是否包含匹配的子串
+	return re.MatchString(targetStr)
+}
+
+func UpdateExcel(client *mongo.Client, plans []*model.ProductPlan) {
+	row := 5
+	planCompStatus := []map[string]string{}
+
+	for _, plan := range plans {
+
+		for _, comp := range plan.Pack.Components {
+			// ""代表该部件没有该工艺 "〇"代表正在进行的工艺
+			// "8080"背景颜色代表部件所含未进行工艺 √代表已完成工序
+			compStatus := map[string]string{
+				"部件": " ",
+				"行数": "5",
+				// 部件中只要有一个订单就说明下单了
+				"下单": " ",
+				// 采购单中type为纸张 订单对应状态为完成
+				"纸张": " ",
+				// 遍历工艺单,工序中包含印刷
+				"印刷": " ",
+				// 遍历工艺单,工序中包含覆膜
+				"覆膜": " ",
+				// 遍历工艺单,工序中包含烫金
+				"烫金": " ",
+				// 遍历工艺单,工序中包含丝印
+				"丝印": " ",
+				// 遍历工艺单,工序中包含对裱
+				"对裱": " ",
+				// 遍历工艺单,工序中包含压纹
+				"压纹": " ",
+				// 遍历工艺单,工序中包含裱瓦
+				"裱瓦": " ",
+				// 遍历工艺单,工序中包含模切
+				"模切": " ",
+				// 遍历工艺单,工序中包含粘盒
+				"粘盒": " ",
+				// 遍历工艺单,工序中包含组装
+				"组装": " ",
+			}
+			compStatus["部件"] = comp.Name
+			compStatus["行数"] = fmt.Sprintf("%d", row)
+			row++
+			// 去重获取所有订单
+			seen := make(map[string]bool)
+			tbills := make([]string, 0, len(comp.Stages)) // 结果数组,容量初始化为原数组的长度
+
+			for _, stage := range comp.Stages {
+				if len(stage.BillId) > 0 {
+					value := fmt.Sprintf("%d_%s", stage.BillType, stage.BillId)
+					if _, ok := seen[value]; !ok {
+						// 标记为已出现
+						seen[value] = true
+						// 添加到结果数组
+						tbills = append(tbills, value)
+					}
+				}
+
+			}
+
+			// 如果tbills为空,说明该部件没有订单
+			if len(tbills) == 0 {
+				// 该部件没有订单,跳过
+				continue
+			}
+
+			// 查询数据库获取bill详细信息
+			for _, billType := range tbills {
+				compStatus["下单"] = "√"
+				bt := strings.Split(billType, "_")[0]
+				billId, _ := primitive.ObjectIDFromHex(strings.Split(billType, "_")[1])
+				if bt == "1" {
+					// 查询采购单
+					bill := &model.PurchaseBill{}
+					err := client.Database("box-cost").Collection(PURCHASE_COLLECTION).FindOne(context.Background(), bson.M{"_id": billId}).Decode(bill)
+					if err != nil {
+						log.Fatal(err)
+					}
+					if bill.Type == "纸张" {
+						compStatus["纸张"] = "〇"
+						if bill.Status == "complete" {
+							compStatus["纸张"] = "√"
+						}
+
+					}
+				}
+				if bt == "2" {
+					// 查询工艺单
+					bill := &model.ProduceBill{}
+					err := client.Database("box-cost").Collection(PRODUCE_COLLECTION).FindOne(context.Background(), bson.M{"_id": billId}).Decode(bill)
+					if err != nil {
+						log.Fatal(err)
+					}
+					for _, produce := range bill.Produces {
+						for k, _ := range compStatus {
+							if k == "下单" || k == "纸张" {
+								continue
+							}
+							if MatchString(produce.Name, k) {
+								compStatus[k] = "〇"
+								if bill.Status == "complete" {
+									compStatus[k] = "√"
+								}
+							}
+						}
+
+					}
+				}
+
+				// 暂时没有状态标定
+				if bt == "3" {
+					// 查询成品单
+					bill := &model.ProductBill{}
+					err := client.Database("box-cost").Collection(PRODUCT_COLLECTION).FindOne(context.Background(), bson.M{"_id": billId}).Decode(bill)
+					if err != nil {
+						log.Fatal(err)
+					}
+					// fmt.Println(bill)
+				}
+
+			}
+
+			planCompStatus = append(planCompStatus, compStatus)
+		}
+
+	}
+	// fmt.Printf("%#v\n", planCompStatus)
+	UpdateCell(planCompStatus)
+
+}
+
+func UpdateCell(planCompStatus []map[string]string) {
+	tmpfile, err := excelize.OpenFile(EXCEL_TMPLATE_FILE)
+	if err != nil {
+		log.Fatal(err)
+	}
+	excelIndex := tmpfile.GetActiveSheetIndex()
+	sheetName := tmpfile.GetSheetName(excelIndex)
+
+	for _, compStatus := range planCompStatus {
+		fmt.Println("-----------------------------------------------")
+		fmt.Println(compStatus)
+		row := compStatus["行数"]
+		for colk, col := range needChangeCol {
+			for csk, csv := range compStatus {
+				if colk == csk {
+					cell := fmt.Sprintf("%s%s", col, row)
+					// fmt.Println(cell)
+
+					// 设置背景
+					if csv == "8080" {
+						// 设置单元格的值
+						styleId, err := tmpfile.NewStyle(&excelize.Style{
+							Fill: excelize.Fill{
+
+								Color: []string{"8080"},
+							},
+						})
+						if err != nil {
+							log.Fatal(err)
+						}
+
+						err = tmpfile.SetCellStyle(sheetName, cell, cell, styleId)
+						if err != nil {
+							log.Fatal(err)
+						}
+					} else {
+						// 设置字符
+						err = tmpfile.SetCellValue(sheetName, cell, csv)
+						if err != nil {
+							log.Fatal(err)
+						}
+
+					}
+
+				}
+
+			}
+		}
+	}
+
+	// 获取当前日期
+	date := time.Now().Format("2006年01月02日_150405")
+	fileName := fmt.Sprintf("礼盒加工追踪表_%s.xlsx", date)
+
+	// 以新的文件名保存文件
+	err = tmpfile.SaveAs(fileName)
+	if err != nil {
+		log.Fatal(err)
+	}
+}

+ 7 - 0
go.mod

@@ -4,6 +4,7 @@ go 1.22.1
 
 require (
 	github.com/spf13/viper v1.19.0
+	github.com/xuri/excelize/v2 v2.8.1
 	go.mongodb.org/mongo-driver v1.16.0
 )
 
@@ -14,8 +15,11 @@ require (
 	github.com/klauspost/compress v1.17.2 // indirect
 	github.com/magiconair/properties v1.8.7 // indirect
 	github.com/mitchellh/mapstructure v1.5.0 // indirect
+	github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
 	github.com/montanaflynn/stats v0.7.1 // indirect
 	github.com/pelletier/go-toml/v2 v2.2.2 // indirect
+	github.com/richardlehane/mscfb v1.0.4 // indirect
+	github.com/richardlehane/msoleps v1.0.3 // indirect
 	github.com/sagikazarmark/locafero v0.4.0 // indirect
 	github.com/sagikazarmark/slog-shim v0.1.0 // indirect
 	github.com/sourcegraph/conc v0.3.0 // indirect
@@ -26,11 +30,14 @@ require (
 	github.com/xdg-go/pbkdf2 v1.0.0 // indirect
 	github.com/xdg-go/scram v1.1.2 // indirect
 	github.com/xdg-go/stringprep v1.0.4 // indirect
+	github.com/xuri/efp v0.0.0-20231025114914-d1ff6096ae53 // indirect
+	github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05 // indirect
 	github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
 	go.uber.org/atomic v1.9.0 // indirect
 	go.uber.org/multierr v1.9.0 // indirect
 	golang.org/x/crypto v0.22.0 // indirect
 	golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
+	golang.org/x/net v0.23.0 // indirect
 	golang.org/x/sync v0.7.0 // indirect
 	golang.org/x/sys v0.19.0 // indirect
 	golang.org/x/text v0.14.0 // indirect

+ 17 - 0
go.sum

@@ -22,6 +22,8 @@ github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0V
 github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
 github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
 github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
+github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
+github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
 github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
 github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
 github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
@@ -29,6 +31,11 @@ github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
 github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/richardlehane/mscfb v1.0.4 h1:WULscsljNPConisD5hR0+OyZjwK46Pfyr6mPu5ZawpM=
+github.com/richardlehane/mscfb v1.0.4/go.mod h1:YzVpcZg9czvAuhk9T+a3avCpcFPMUWm7gK3DypaEsUk=
+github.com/richardlehane/msoleps v1.0.1/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
+github.com/richardlehane/msoleps v1.0.3 h1:aznSZzrwYRl3rLKRT3gUk9am7T/mLNSnJINvN0AQoVM=
+github.com/richardlehane/msoleps v1.0.3/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
 github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
 github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
 github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
@@ -63,6 +70,12 @@ github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
 github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4=
 github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8=
 github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM=
+github.com/xuri/efp v0.0.0-20231025114914-d1ff6096ae53 h1:Chd9DkqERQQuHpXjR/HSV1jLZA6uaoiwwH3vSuF3IW0=
+github.com/xuri/efp v0.0.0-20231025114914-d1ff6096ae53/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
+github.com/xuri/excelize/v2 v2.8.1 h1:pZLMEwK8ep+CLIUWpWmvW8IWE/yxqG0I1xcN6cVMGuQ=
+github.com/xuri/excelize/v2 v2.8.1/go.mod h1:oli1E4C3Pa5RXg1TBXn4ENCXDV5JUMlBluUhG7c+CEE=
+github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05 h1:qhbILQo1K3mphbwKh1vNm4oGezE1eF9fQWmNiIpSfI4=
+github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ=
 github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
 github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
 github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
@@ -78,10 +91,14 @@ golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
 golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
 golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
 golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
+golang.org/x/image v0.14.0 h1:tNgSxAFe3jC4uYqvZdTr84SZoM1KfwdC9SKIFrLjFn4=
+golang.org/x/image v0.14.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
 golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
 golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
 golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
 golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
+golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
+golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
 golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=

+ 32 - 7
main.go

@@ -1,6 +1,8 @@
 package main
 
 import (
+	"box-cost/el"
+	"box-cost/model"
 	"context"
 	"fmt"
 	"log"
@@ -8,6 +10,8 @@ import (
 	"time"
 
 	"github.com/spf13/viper"
+	"go.mongodb.org/mongo-driver/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 	"go.mongodb.org/mongo-driver/mongo"
 	"go.mongodb.org/mongo-driver/mongo/options"
 )
@@ -39,6 +43,12 @@ func LoadConfFile() (*AppConf, error) {
 }
 
 func main() {
+	// 读取配置
+	conf, err := LoadConfFile()
+	if err != nil {
+		log.Fatal(err)
+	}
+	planIds := conf.Plans
 
 	// 连接数据库
 	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
@@ -52,13 +62,28 @@ func main() {
 	}
 	defer client.Disconnect(ctx)
 
-	// 获取配置planIds
-	// 查询plans详情
-
-	// 读取表格
-
-	// 数据处理
+	collection := client.Database("box-cost").Collection("product-plan")
+	// 构建查询管道
+	pipeline := make([]bson.M, 0)
+	for _, planIdstr := range planIds {
+		planId, _ := primitive.ObjectIDFromHex(planIdstr)
+		pipeline = append(pipeline, bson.M{"$match": bson.M{"_id": planId}})
+	}
 
-	// 填写表格
+	// 执行聚合查询
+	cursor, err := collection.Aggregate(context.Background(), pipeline)
+	if err != nil {
+		log.Fatal(err)
+	}
+	defer cursor.Close(context.Background())
+	// 获取结果
+	plans := make([]*model.ProductPlan, 0)
+	err = cursor.All(context.Background(), &plans)
+	if err != nil {
+		log.Fatal(err)
+	}
+	// 读取excel
+	fmt.Println(plans[0].Name)
+	el.UpdateExcel(client, plans)
 
 }

+ 282 - 0
model/bill.go

@@ -0,0 +1,282 @@
+package model
+
+import (
+	"time"
+
+	"go.mongodb.org/mongo-driver/bson/primitive"
+)
+
+// 采购单
+type PaperBill struct {
+	Id string `bson:"id,omitempty" json:"id"`
+	//名字
+	Name string `bson:"name,omitempty" json:"name"`
+	//规格
+	Norm string `bson:"norm,omitempty" json:"norm"`
+
+	//宽
+	Width string `bson:"width,omitempty" json:"width"`
+
+	//长
+	Height string `bson:"height,omitempty" json:"height"`
+
+	Price      float64 `bson:"price,omitempty" json:"price"`
+	Price2     float64 `bson:"price2,omitempty" json:"price2"`
+	PriceUnit  string  `bson:"priceUnit,omitempty" json:"priceUnit"`
+	Price2Unit string  `bson:"price2Unit,omitempty" json:"price2Unit"`
+
+	// 下单数量
+	OrderCount int `bson:"orderCount,omitempty" json:"orderCount"`
+
+	// 下单单价
+	OrderPrice float64 `bson:"orderPrice,omitempty" json:"orderPrice"`
+
+	//备注
+	Remark string `bson:"remark,omitempty" json:"remark"`
+
+	//备注
+	ConfirmCount int `bson:"confirmCount,omitempty" json:"confirmCount"`
+
+	//交货时间
+	DeliveryTime time.Time `bson:"deliveryTime,omitempty" json:"deliveryTime"`
+}
+
+type PurchaseBill struct {
+	Id         primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
+	PackId     primitive.ObjectID `bson:"packId,omitempty" json:"packId"`
+	PlanId     primitive.ObjectID `bson:"planId,omitempty" json:"planId"`
+	SupplierId primitive.ObjectID `bson:"supplierId,omitempty" json:"supplierId"`
+	UserId     primitive.ObjectID `bson:"userId,omitempty" json:"userId"`
+	UserName   string             `bson:"userName,omitempty" json:"userName"`
+	//类别
+	Type string `bson:"type,omitempty" json:"type"`
+
+	// 进行中 created  已完成 complete 已弃用 deprecated  已审核 reviewed
+	Status       string               `bson:"status,omitempty" json:"status"`
+	Reviewed     int                  `bson:"reviewed,omitempty" json:"reviewed"`   // -1 代表未审核 1已审核
+	SignUsers    []primitive.ObjectID `bson:"signUsers,omitempty" json:"signUsers"` // 多个签名人
+	CreateTime   time.Time            `bson:"createTime,omitempty" json:"createTime"`
+	UpdateTime   time.Time            `bson:"updateTime,omitempty" json:"updateTime"`
+	CompleteTime time.Time            `bson:"completeTime,omitempty" json:"completeTime"`
+
+	//供应商
+	Supplier string `bson:"supplier,omitempty" json:"supplier"`
+
+	//送货地址
+	SendTo string `bson:"sendTo,omitempty" json:"sendTo"`
+
+	//商品名字
+	ProductName string `bson:"productName,omitempty" json:"productName"`
+
+	//纸张类采购
+	Paper []*PaperBill `bson:"papers,omitempty" json:"papers"`
+
+	// 序号
+	SerialNumber string `bson:"serialNumber,omitempty" json:"serialNumber"`
+
+	Remark string `bson:"remark,omitempty" json:"remark"`
+
+	// 单据类型
+	BillType string `bson:"billType,omitempty" json:"billType"`
+
+	// 发送给供应商
+	IsSend   bool      `bson:"isSend,omitempty" json:"isSend"`
+	SendTime time.Time `bson:"sendTime,omitempty" json:"sendTime"`
+
+	// 供应商确认
+	IsAck   *bool     `bson:"isAck,omitempty" json:"isAck"`
+	AckTime time.Time `bson:"ackTime,omitempty" json:"ackTime"`
+	// 部件工序名
+	CompProduceName string `bson:"compProduceName,omitempty" json:"compProduceName"`
+	// 供应商备注
+	SupplierRemark string `bson:"supplierRemark,omitempty" json:"supplierRemark"`
+}
+
+// 工艺生产数据
+type ProduceBillData struct {
+	Id string `bson:"id,omitempty" json:"id"`
+	//名字
+	Name string `bson:"name,omitempty" json:"name"`
+
+	//规格(质量要求)
+	Norm string `bson:"norm,omitempty" json:"norm"`
+
+	//单价 数量
+	Price float64 `bson:"price,omitempty" json:"price"`
+
+	Price2 float64 `bson:"price2,omitempty" json:"price2"` // 对应unit2
+
+	// 下单数量
+	OrderCount int `bson:"orderCount,omitempty" json:"orderCount"`
+
+	// 下单单价
+	OrderPrice float64 `bson:"orderPrice,omitempty" json:"orderPrice"`
+
+	// 确认收货数量
+	ConfirmCount int `bson:"confirmCount,omitempty" json:"confirmCount"`
+
+	// 来纸数量
+	PaperCount int `bson:"paperCount,omitempty" json:"paperCount"`
+
+	//备注
+	Remark string `bson:"remark,omitempty" json:"remark"`
+
+	//纸张
+	Paper string `bson:"paper,omitempty" json:"paper"`
+
+	//来纸尺寸
+	PaperSize string `bson:"paperSize,omitempty" json:"paperSize"`
+
+	//印刷尺寸/覆膜尺寸
+	PrintSize string `bson:"printSize,omitempty" json:"printSize"`
+
+	//交货时间
+	DeliveryTime time.Time `bson:"deliveryTime,omitempty" json:"deliveryTime"`
+
+	Unit  string `bson:"unit,omitempty" json:"unit"`
+	Unit2 string `bson:"unit2,omitempty" json:"unit2"`
+}
+
+type ProduceBill struct {
+	Id         primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
+	PackId     primitive.ObjectID `bson:"packId,omitempty" json:"packId"`
+	PlanId     primitive.ObjectID `bson:"planId,omitempty" json:"planId"`
+	SupplierId primitive.ObjectID `bson:"supplierId,omitempty" json:"supplierId"`
+	UserId     primitive.ObjectID `bson:"userId,omitempty" json:"userId"`
+	UserName   string             `bson:"userName,omitempty" json:"userName"`
+
+	// 类别
+	Type string `bson:"type,omitempty" json:"type"`
+
+	// 进行中 created  已完成 complete 已弃用 deprecated
+	Status       string               `bson:"status,omitempty" json:"status"`
+	Reviewed     int                  `bson:"reviewed,omitempty" json:"reviewed"`   // -1 代表未审核 1已审核
+	SignUsers    []primitive.ObjectID `bson:"signUsers,omitempty" json:"signUsers"` // 多个签名人
+	CreateTime   time.Time            `bson:"createTime,omitempty" json:"createTime"`
+	UpdateTime   time.Time            `bson:"updateTime,omitempty" json:"updateTime"`
+	CompleteTime time.Time            `bson:"completeTime,omitempty" json:"completeTime"`
+
+	//供应商
+	Supplier string `bson:"supplier,omitempty" json:"supplier"`
+
+	//送货地址
+	SendTo string `bson:"sendTo,omitempty" json:"sendTo"`
+
+	//商品名字
+	ProductName string `bson:"productName,omitempty" json:"productName"`
+
+	//纸张类采购
+	Produces []*ProduceBillData `bson:"produces,omitempty" json:"produces"`
+
+	// 序号
+	SerialNumber string `bson:"serialNumber,omitempty" json:"serialNumber"`
+
+	//备注
+	Remark string `bson:"remark,omitempty" json:"remark"`
+
+	IsPrint bool `bson:"isPrint,omitempty" json:"isPrint"`
+	IsLam   bool `bson:"isLam,omitempty" json:"isLam"`
+	//是否需要纸张尺寸
+	IsPaper bool `bson:"isPaper,omitempty" json:"isPaper"`
+
+	// 单据类型
+	BillType string `bson:"billType,omitempty" json:"billType"`
+
+	// 发送给供应商
+	IsSend   bool      `bson:"isSend,omitempty" json:"isSend"`
+	SendTime time.Time `bson:"sendTime,omitempty" json:"sendTime"`
+	// 供应商确认
+	IsAck   *bool     `bson:"isAck,omitempty" json:"isAck"`
+	AckTime time.Time `bson:"ackTime,omitempty" json:"ackTime"`
+	// 部件包含工序
+	CompProduceName string `bson:"compProduceName,omitempty" json:"compProduceName"`
+	// 供应商备注
+	SupplierRemark string `bson:"supplierRemark,omitempty" json:"supplierRemark"`
+}
+
+// 成品采购单据
+type ProductBill struct {
+	Id         primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
+	PackId     primitive.ObjectID `bson:"packId,omitempty" json:"packId"`
+	PlanId     primitive.ObjectID `bson:"planId,omitempty" json:"planId"`
+	SupplierId primitive.ObjectID `bson:"supplierId,omitempty" json:"supplierId"`
+	UserId     primitive.ObjectID `bson:"userId,omitempty" json:"userId"`
+	UserName   string             `bson:"userName,omitempty" json:"userName"`
+
+	// 类别
+	Type string `bson:"type,omitempty" json:"type"`
+
+	// 进行中 created  已完成 complete 已弃用 deprecated
+	Status       string               `bson:"status,omitempty" json:"status"`
+	Reviewed     int                  `bson:"reviewed,omitempty" json:"reviewed"`   // -1 代表未审核 1已审核
+	SignUsers    []primitive.ObjectID `bson:"signUsers,omitempty" json:"signUsers"` // 多个签名人
+	CreateTime   time.Time            `bson:"createTime,omitempty" json:"createTime"`
+	UpdateTime   time.Time            `bson:"updateTime,omitempty" json:"updateTime"`
+	CompleteTime time.Time            `bson:"completeTime,omitempty" json:"completeTime"`
+
+	//供应商
+	Supplier string `bson:"supplier,omitempty" json:"supplier"`
+
+	//送货地址
+	SendTo string `bson:"sendTo,omitempty" json:"sendTo"`
+
+	//商品名字
+	ProductName string `bson:"productName,omitempty" json:"productName"`
+
+	//有哪些成品采购数据
+	Products []*ProductBillData `bson:"products,omitempty" json:"products"`
+
+	// 序号
+	SerialNumber string `bson:"serialNumber,omitempty" json:"serialNumber"`
+
+	//备注
+	Remark string `bson:"remark,omitempty" json:"remark"`
+
+	// 单据类型
+	BillType string `bson:"billType,omitempty" json:"billType"`
+
+	// 发送给供应商
+	IsSend   bool      `bson:"isSend,omitempty" json:"isSend"`
+	SendTime time.Time `bson:"sendTime,omitempty" json:"sendTime"`
+	// 供应商确认
+	IsAck   *bool     `bson:"isAck,omitempty" json:"isAck"`
+	AckTime time.Time `bson:"ackTime,omitempty" json:"ackTime"`
+	// 部件工序名
+	CompProduceName string `bson:"compProduceName,omitempty" json:"compProduceName"`
+	// 供应商备注
+	SupplierRemark string `bson:"supplierRemark,omitempty" json:"supplierRemark"`
+}
+
+// 工艺生产数据
+type ProductBillData struct {
+	Id string `bson:"id,omitempty" json:"id"`
+	//名字
+	Name string `bson:"name,omitempty" json:"name"`
+
+	//规格(质量要求)
+	Norm string `bson:"norm,omitempty" json:"norm"`
+
+	// 尺寸
+	Size string `bson:"size,omitempty" json:"size"`
+
+	//单价 数量
+	Price float64 `bson:"price,omitempty" json:"price"`
+
+	// 下单数量
+	OrderCount int `bson:"orderCount,omitempty" json:"orderCount"`
+
+	// 下单单价
+	OrderPrice float64 `bson:"orderPrice,omitempty" json:"orderPrice"`
+
+	//备注
+	Remark string `bson:"remark,omitempty" json:"remark"`
+
+	//交货时间
+	DeliveryTime time.Time `bson:"deliveryTime,omitempty" json:"deliveryTime"`
+
+	// 确认收货数量
+	ConfirmCount int `bson:"confirmCount,omitempty" json:"confirmCount"`
+
+	//纸张
+	Unit string `bson:"unit,omitempty" json:"unit"`
+}

+ 121 - 0
model/plan.go

@@ -0,0 +1,121 @@
+package model
+
+import (
+	"time"
+
+	"go.mongodb.org/mongo-driver/bson/primitive"
+)
+
+// 生产计划
+type ProductPlan struct {
+	Id   primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
+	Name string             `bson:"name,omitempty" json:"name"`
+	// 包装 待生产的产品
+	Pack       *Pack  `bson:"pack,omitempty" json:"pack"`
+	Thumbnail  string `bson:"thumbnail,omitempty" json:"thumbnail"`
+	CreateUser string `bson:"createUser,omitempty" json:"createUser"`
+
+	//生产数量
+	Total int `bson:"total,omitempty" json:"total"`
+
+	//状态
+	Status string `bson:"status,omitempty" json:"status"`
+
+	//总价
+	TotalPrice float64 `bson:"totalPrice,omitempty" json:"totalPrice"`
+
+	UpdateTime time.Time `bson:"updteTime,omitempty" json:"updateTime"`
+
+	CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
+}
+
+// 包装
+type Pack struct {
+	Id        primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
+	Name      string             `bson:"name,omitempty" json:"name"`
+	Thumbnail string             `bson:"thumbnail,omitempty" json:"thumbnail"`
+	// 部件数量
+	CompCounts int `bson:"compCounts,omitempty" json:"compCounts"`
+	// 设计师
+	Designer string `bson:"designer,omitempty" json:"designer"`
+	// 组成包装的部件
+	Components []*PackComponent `bson:"components,omitempty" json:"components"`
+	CreateTime time.Time        `bson:"createTime,omitempty" json:"createTime"`
+	UpdateTime time.Time        `bson:"updateTime,omitempty" json:"updateTime"`
+}
+
+type PackComponent struct {
+	Id        string `bson:"id,omitempty" json:"id"`
+	Name      string `bson:"name,omitempty" json:"name"`
+	Thumbnail string `bson:"thumbnail,omitempty" json:"thumbnail"`
+	//数量
+	Count int `bson:"count,omitempty" json:"count"`
+
+	//刀版图
+	Uv string `bson:"uv,omitempty" json:"uv"`
+
+	//部件尺寸
+	UvSize string `bson:"uvSize,omitempty" json:"uvSize"`
+
+	//所有材料
+	Stages []*ComponentStage `bson:"stages,omitempty" json:"stages"`
+
+	Remark string `bson:"remark,omitempty" json:"remark"`
+
+	//部件总价
+	TotalPrice float64 `bson:"totalPrice,omitempty" json:"totalPrice"`
+}
+
+type ComponentStage struct {
+	Id     string             `bson:"id,omitempty" json:"id"`
+	TypeId primitive.ObjectID `bson:"typeId,omitempty" json:"typeId"`
+
+	// 下单单价
+	OrderPrice float64 `bson:"orderPrice,omitempty" json:"orderPrice"`
+
+	// 下单数量
+	OrderCount int `bson:"orderCount,omitempty" json:"orderCount"`
+
+	//实际价格 OrderPrice*ConfirmCount
+	//预算价格 OrderPrice*OrderCount
+
+	//确认收货数量
+	ConfirmCount int `bson:"confirmCount,omitempty" json:"confirmCount"`
+
+	// 供应相关信息
+	// 交货时间
+	DeliveryTime time.Time `bson:"deliveryTime,omitempty" json:"deliveryTime"`
+
+	// 供应商信息
+	SupplierInfo *Supplier `bson:"supplierInfo,omitempty" json:"supplierInfo"`
+
+	BatchCount      int `bson:"batchCount,omitempty" json:"batchCount"`           //拼版数量
+	BatchSizeWidth  int `bson:"batchSizeWidth,omitempty" json:"batchSizeWidth"`   //平板尺寸
+	BatchSizeHeight int `bson:"batchSizeHeight,omitempty" json:"batchSizeHeight"` //平板尺寸
+
+	Remark     string    `bson:"remark,omitempty" json:"remark"`     //备注
+	Size       string    `bson:"size,omitempty" json:"size"`         //工艺尺寸
+	Name       string    `bson:"name,omitempty" json:"name"`         //名称
+	Category   string    `bson:"category,omitempty" json:"category"` //分类
+	Price      float64   `bson:"price,omitempty" json:"price"`       //单价
+	Unit       string    `bson:"unit,omitempty" json:"unit"`         //单位
+	Norm       string    `bson:"norm,omitempty" json:"norm"`         // 规格
+	CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
+	UpdateTime time.Time `bson:"updateTime,omitempty" json:"updateTime"`
+	Type       int       `bson:"type,omitempty" json:"type"`         //1-材料 2-工艺 3-成品
+	Group      string    `bson:"group,omitempty" json:"group"`       //工序合标记,相同Group的数据合并成一个单据
+	BillId     string    `bson:"billId,omitempty" json:"billId"`     //订单Id
+	BillType   int       `bson:"billType,omitempty" json:"billType"` //订单type // 1,2,3
+}
+
+// 供应商
+type Supplier struct {
+	Id         primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
+	Name       string             `bson:"name,omitempty" json:"name"`
+	Address    string             `bson:"address,omitempty" json:"address"`
+	Phone      string             `bson:"phone,omitempty" json:"phone"`
+	Categorys  []string           `bson:"categorys,omitempty" json:"categorys"` // 多个分类
+	Category   string             `bson:"category,omitempty" json:"category"`   // todo 旧的待删除
+	CreateTime time.Time          `bson:"createTime,omitempty" json:"createTime"`
+	UpdateTime time.Time          `bson:"updateTime,omitempty" json:"updateTime"`
+}

+ 5 - 0
readme.md

@@ -0,0 +1,5 @@
+// 读取表格
+
+	// 数据处理
+
+	// 填写表格

+ 0 - 0
2024月饼礼盒包装进度追踪表.xlsx → tmplate/tmplate-原始.xlsx


BIN
tmplate/tmplate.xlsx