|
@@ -20,6 +20,7 @@ const (
|
|
|
PURCHASE_COLLECTION = "bill-purchase"
|
|
|
PRODUCE_COLLECTION = "bill-produce"
|
|
|
PRODUCT_COLLECTION = "bill-product"
|
|
|
+ CELL_BACKGROUND = "808080"
|
|
|
)
|
|
|
|
|
|
var needChangeCol = map[string]string{
|
|
@@ -36,6 +37,7 @@ var needChangeCol = map[string]string{
|
|
|
"模切": "O",
|
|
|
"粘盒": "P",
|
|
|
"组装": "Q",
|
|
|
+ "交货": "R",
|
|
|
}
|
|
|
|
|
|
func MatchString(targetStr string, regexPattern string) bool {
|
|
@@ -53,7 +55,7 @@ func UpdateExcel(client *mongo.Client, plans []*model.ProductPlan) {
|
|
|
|
|
|
for _, comp := range plan.Pack.Components {
|
|
|
// ""代表该部件没有该工艺 "〇"代表正在进行的工艺
|
|
|
- // "8080"背景颜色代表部件所含未进行工艺 √代表已完成工序
|
|
|
+ // "808080"背景颜色代表部件所含未进行工艺 √代表已完成工序
|
|
|
compStatus := map[string]string{
|
|
|
"部件": " ",
|
|
|
"行数": "5",
|
|
@@ -81,6 +83,7 @@ func UpdateExcel(client *mongo.Client, plans []*model.ProductPlan) {
|
|
|
"粘盒": " ",
|
|
|
// 遍历工艺单,工序中包含组装
|
|
|
"组装": " ",
|
|
|
+ "交货": " ",
|
|
|
}
|
|
|
compStatus["部件"] = comp.Name
|
|
|
compStatus["行数"] = fmt.Sprintf("%d", row)
|
|
@@ -90,6 +93,7 @@ func UpdateExcel(client *mongo.Client, plans []*model.ProductPlan) {
|
|
|
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 {
|
|
@@ -98,6 +102,23 @@ func UpdateExcel(client *mongo.Client, plans []*model.ProductPlan) {
|
|
|
// 添加到结果数组
|
|
|
tbills = append(tbills, value)
|
|
|
}
|
|
|
+ } else {
|
|
|
+ // 产品中填写了这个工序但是没有下单 黑色背景
|
|
|
+ for k := range compStatus {
|
|
|
+ if k == "下单" || k == "交货" || k == "部件" || k == "行数" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ // 纸张 只要是采购单就设置纸张状态
|
|
|
+ if stage.Type == 1 {
|
|
|
+ compStatus["纸张"] = CELL_BACKGROUND
|
|
|
+ }
|
|
|
+
|
|
|
+ // 匹配工艺关键字 匹配到就设置状态为黑背景
|
|
|
+ if MatchString(stage.Name, k) {
|
|
|
+ compStatus[k] = CELL_BACKGROUND
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -105,11 +126,15 @@ func UpdateExcel(client *mongo.Client, plans []*model.ProductPlan) {
|
|
|
// 如果tbills为空,说明该部件没有订单
|
|
|
if len(tbills) == 0 {
|
|
|
// 该部件没有订单,跳过
|
|
|
+ planCompStatus = append(planCompStatus, compStatus)
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
// 查询数据库获取bill详细信息
|
|
|
+ // 最后工序订单号
|
|
|
+ lastBillType := tbills[len(tbills)-1]
|
|
|
for _, billType := range tbills {
|
|
|
+
|
|
|
compStatus["下单"] = "√"
|
|
|
bt := strings.Split(billType, "_")[0]
|
|
|
billId, _ := primitive.ObjectIDFromHex(strings.Split(billType, "_")[1])
|
|
@@ -120,13 +145,25 @@ func UpdateExcel(client *mongo.Client, plans []*model.ProductPlan) {
|
|
|
if err != nil {
|
|
|
log.Fatal(err)
|
|
|
}
|
|
|
- if bill.Type == "纸张" {
|
|
|
- compStatus["纸张"] = "〇"
|
|
|
- if bill.Status == "complete" {
|
|
|
- compStatus["纸张"] = "√"
|
|
|
- }
|
|
|
+ // if bill.Type == "纸张" {
|
|
|
+ // compStatus["纸张"] = "〇"
|
|
|
+ // if bill.Status == "complete" {
|
|
|
+ // compStatus["纸张"] = "√"
|
|
|
+ // }
|
|
|
|
|
|
+ // }
|
|
|
+
|
|
|
+ compStatus["纸张"] = "〇"
|
|
|
+ if bill.Status == "complete" {
|
|
|
+ compStatus["纸张"] = "√"
|
|
|
}
|
|
|
+
|
|
|
+ if lastBillType == billType {
|
|
|
+ for _, paper := range bill.Paper {
|
|
|
+ compStatus["交货"] = fmt.Sprintf("%d", paper.ConfirmCount)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
if bt == "2" {
|
|
|
// 查询工艺单
|
|
@@ -136,8 +173,8 @@ func UpdateExcel(client *mongo.Client, plans []*model.ProductPlan) {
|
|
|
log.Fatal(err)
|
|
|
}
|
|
|
for _, produce := range bill.Produces {
|
|
|
- for k, _ := range compStatus {
|
|
|
- if k == "下单" || k == "纸张" {
|
|
|
+ for k := range compStatus {
|
|
|
+ if k == "下单" || k == "纸张" || k == "交货" || k == "部件" || k == "行数" {
|
|
|
continue
|
|
|
}
|
|
|
if MatchString(produce.Name, k) {
|
|
@@ -146,6 +183,8 @@ func UpdateExcel(client *mongo.Client, plans []*model.ProductPlan) {
|
|
|
compStatus[k] = "√"
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ compStatus["交货"] = fmt.Sprintf("%d", produce.ConfirmCount)
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -160,8 +199,12 @@ func UpdateExcel(client *mongo.Client, plans []*model.ProductPlan) {
|
|
|
log.Fatal(err)
|
|
|
}
|
|
|
// fmt.Println(bill)
|
|
|
+ if lastBillType == billType {
|
|
|
+ for _, product := range bill.Products {
|
|
|
+ compStatus["交货"] = fmt.Sprintf("%d", product.ConfirmCount)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
planCompStatus = append(planCompStatus, compStatus)
|
|
@@ -182,8 +225,8 @@ func UpdateCell(planCompStatus []map[string]string) {
|
|
|
sheetName := tmpfile.GetSheetName(excelIndex)
|
|
|
|
|
|
for _, compStatus := range planCompStatus {
|
|
|
- fmt.Println("-----------------------------------------------")
|
|
|
- fmt.Println(compStatus)
|
|
|
+ // fmt.Println("-----------------------------------------------")
|
|
|
+ // fmt.Println(compStatus)
|
|
|
row := compStatus["行数"]
|
|
|
for colk, col := range needChangeCol {
|
|
|
for csk, csv := range compStatus {
|
|
@@ -192,19 +235,44 @@ func UpdateCell(planCompStatus []map[string]string) {
|
|
|
// fmt.Println(cell)
|
|
|
|
|
|
// 设置背景
|
|
|
- if csv == "8080" {
|
|
|
+ if csv == CELL_BACKGROUND {
|
|
|
// 设置单元格的值
|
|
|
- styleId, err := tmpfile.NewStyle(&excelize.Style{
|
|
|
- Fill: excelize.Fill{
|
|
|
|
|
|
- Color: []string{"8080"},
|
|
|
+ // 定义样式
|
|
|
+ style, err := tmpfile.NewStyle(&excelize.Style{
|
|
|
+ Border: []excelize.Border{
|
|
|
+ {
|
|
|
+ Type: "left",
|
|
|
+ Color: "FF000000",
|
|
|
+ Style: 1,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Type: "right",
|
|
|
+ Color: "FF000000",
|
|
|
+ Style: 1,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Type: "top",
|
|
|
+ Color: "FF000000",
|
|
|
+ Style: 1,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Type: "bottom",
|
|
|
+ Color: "FF000000",
|
|
|
+ Style: 1,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ Fill: excelize.Fill{
|
|
|
+ Type: "pattern",
|
|
|
+ Pattern: 1, // 1 表示实心填充
|
|
|
+ Color: []string{CELL_BACKGROUND},
|
|
|
},
|
|
|
})
|
|
|
if err != nil {
|
|
|
log.Fatal(err)
|
|
|
}
|
|
|
|
|
|
- err = tmpfile.SetCellStyle(sheetName, cell, cell, styleId)
|
|
|
+ err = tmpfile.SetCellStyle(sheetName, cell, cell, style)
|
|
|
if err != nil {
|
|
|
log.Fatal(err)
|
|
|
}
|