Browse Source

修复isAck bool默认值

animeic 2 năm trước cách đây
mục cha
commit
33ff87db25

+ 2 - 0
boxcost/api/bill-produce.go

@@ -117,6 +117,8 @@ func CreateProduceBill(c *gin.Context, apictx *ApiSession) (interface{}, error)
 	}
 	bill.CreateTime = time.Now()
 	bill.UpdateTime = time.Now()
+	notAck := false
+	bill.IsAck = &notAck
 	// 制单人数据
 	userId, _ := primitive.ObjectIDFromHex(apictx.User.Parent)
 	fmt.Println("userId:", apictx.User.Parent)

+ 2 - 0
boxcost/api/bill-product.go

@@ -117,6 +117,8 @@ func CreateProductBill(c *gin.Context, apictx *ApiSession) (interface{}, error)
 	}
 	bill.CreateTime = time.Now()
 	bill.UpdateTime = time.Now()
+	notAck := false
+	bill.IsAck = &notAck
 	// 制单人数据
 	userId, _ := primitive.ObjectIDFromHex(apictx.User.Parent)
 	fmt.Println("userId:", apictx.User.Parent)

+ 2 - 1
boxcost/api/bill.go

@@ -126,7 +126,8 @@ func CreateBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	}
 	bill.CreateTime = time.Now()
 	bill.UpdateTime = time.Now()
-
+	notAck := false
+	bill.IsAck = &notAck
 	// 制单人数据
 	userId, _ := primitive.ObjectIDFromHex(apictx.User.Parent)
 	fmt.Println("userId:", apictx.User.Parent)

+ 15 - 25
boxcost/api/plan-cost-excel.go

@@ -230,7 +230,7 @@ func (b *PlanCostExcel) drawAllContent() error {
 						}
 
 						// 接单状态
-						if splan.IsAck[stage.BillId] {
+						if splan.IsAck[stage.BillId] != nil && *splan.IsAck[stage.BillId] {
 							stageStatus = "已接单"
 						} else {
 							stageStatus = "未接单"
@@ -382,41 +382,31 @@ func (b *PlanCostExcel) drawSupplierContent() error {
 								}
 
 								// 状态
-								stop := false
 								stageStatus := ""
+
 								if len(stage.BillId) < 1 {
 									stageStatus = "未生成订单"
-									stop = true
+								}
+								if splan.State[stage.BillId] == "created" {
+									stageStatus = "进行中"
 								}
 								// 审核状态
-								if !stop {
-									if splan.Reviewed[stage.BillId] == 1 {
-										stageStatus = "已审核"
-									} else {
-										stageStatus = "未审核"
-										stop = true
-									}
-
+								if splan.Reviewed[stage.BillId] == 1 {
+									stageStatus = "已审核"
+								} else {
+									stageStatus = "未审核"
 								}
 
 								// 接单状态
-								if !stop {
-									if splan.IsAck[stage.BillId] {
-										stageStatus = "已接单"
-									} else {
-										stageStatus = "未接单"
-										stop = true
-									}
-
+								if splan.IsAck[stage.BillId] != nil && *splan.IsAck[stage.BillId] {
+									stageStatus = "已接单"
+								} else {
+									stageStatus = "未接单"
 								}
 
 								// 完成状态
-								if !stop {
-									if splan.State[stage.BillId] == "complete" {
-										stageStatus = "已完成"
-									} else if splan.State[stage.BillId] == "created" {
-										stageStatus = "进行中"
-									}
+								if splan.State[stage.BillId] == "complete" {
+									stageStatus = "已完成"
 								}
 
 								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)

+ 2 - 2
boxcost/api/plan-summary-excel.go

@@ -231,7 +231,7 @@ func (b *PlanSummaryExcel) drawAllContent() error {
 						}
 
 						// 接单状态
-						if splan.IsAck[stage.BillId] {
+						if splan.IsAck[stage.BillId] != nil && *splan.IsAck[stage.BillId] {
 							stageStatus = "已接单"
 						} else {
 							stageStatus = "未接单"
@@ -411,7 +411,7 @@ func (b *PlanSummaryExcel) drawSupplierContent() error {
 								}
 
 								// 接单状态
-								if splan.IsAck[stage.BillId] {
+								if splan.IsAck[stage.BillId] != nil && *splan.IsAck[stage.BillId] {
 									stageStatus = "已接单"
 								} else {
 									stageStatus = "未接单"

+ 4 - 3
boxcost/api/plan.go

@@ -1033,7 +1033,7 @@ func GetProductPlan(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	billStates := map[string]string{}
 	billIsSend := map[string]bool{}
 	billReviewed := map[string]int32{}
-	billIsAck := map[string]bool{}
+	billIsAck := map[string]*bool{}
 	if plan.Pack != nil && plan.Pack.Components != nil {
 		for _, comp := range plan.Pack.Components {
 			if comp.Stages != nil {
@@ -1072,10 +1072,11 @@ func GetProductPlan(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 								billReviewed[stage.BillId] = -1
 							}
 							if v, ok := state["isAck"]; ok {
-								billIsAck[stage.BillId] = v.(bool)
+								billIsAck[stage.BillId] = v.(*bool)
 
 							} else {
-								billIsAck[stage.BillId] = false
+								notAck := false
+								billIsAck[stage.BillId] = &notAck
 							}
 
 						}

+ 2 - 2
boxcost/api/summary-sample-excel.go

@@ -131,7 +131,7 @@ func (b *SummarySampleExcel) drawAllContent() error {
 						}
 
 						// 接单状态
-						if splan.IsAck[stage.BillId] {
+						if splan.IsAck[stage.BillId] != nil && *splan.IsAck[stage.BillId] {
 							stageStatus = "已接单"
 						} else {
 							stageStatus = "未接单"
@@ -262,7 +262,7 @@ func (b *SummarySampleExcel) drawSupplierContent() error {
 								}
 
 								// 接单状态
-								if splan.IsAck[stage.BillId] {
+								if splan.IsAck[stage.BillId] != nil && *splan.IsAck[stage.BillId] {
 									stageStatus = "已接单"
 								} else {
 									stageStatus = "未接单"

+ 10 - 8
boxcost/api/summary.go

@@ -26,11 +26,12 @@ type SupplierPlanSummary struct {
 	SupplierId primitive.ObjectID
 }
 type PlanSummary struct {
-	Plan          *model.ProductPlan
-	IsSend, IsAck map[string]bool
-	Reviewed      map[string]int32
-	State         map[string]string
-	CreateTimes   map[string]time.Time
+	Plan        *model.ProductPlan
+	IsSend      map[string]bool
+	IsAck       map[string]*bool
+	Reviewed    map[string]int32
+	State       map[string]string
+	CreateTimes map[string]time.Time
 }
 
 // /summary/download?planIds=id1,id2&supplierId=xxx
@@ -178,7 +179,7 @@ func GetPlanStatus(plan *model.ProductPlan, apictx *ApiSession) *PlanSummary {
 	billStates := map[string]string{}
 	billIsSend := map[string]bool{}
 	billReviewed := map[string]int32{}
-	billIsAck := map[string]bool{}
+	billIsAck := map[string]*bool{}
 	billCreateTimes := map[string]time.Time{}
 	if plan.Pack != nil && plan.Pack.Components != nil {
 		for _, comp := range plan.Pack.Components {
@@ -218,10 +219,11 @@ func GetPlanStatus(plan *model.ProductPlan, apictx *ApiSession) *PlanSummary {
 								billReviewed[stage.BillId] = -1
 							}
 							if v, ok := state["isAck"]; ok {
-								billIsAck[stage.BillId] = v.(bool)
+								billIsAck[stage.BillId] = v.(*bool)
 
 							} else {
-								billIsAck[stage.BillId] = false
+								notAck := false
+								billIsAck[stage.BillId] = &notAck
 							}
 							if v, ok := state["createTime"]; ok {
 								billCreateTimes[stage.BillId] = v.(primitive.DateTime).Time()

+ 43 - 0
boxcost/api/supplier.go

@@ -38,6 +38,9 @@ func Supplier(r *GinRouter) {
 	// 供应商获取自己的单据列表
 	r.GETJWT("/supplier/bill/list", SupplierBillList)
 
+	// 供应商接单
+	r.POSTJWT("/supplier/bill/ack", SupplierBillAck)
+
 	// 单据分配给供应商
 	r.GET("/supplier/bill/alloc", SupplierBillAlloc)
 
@@ -77,6 +80,46 @@ func SupplierBillAlloc(c *gin.Context, apictx *ApiSession) (interface{}, error)
 	}
 }
 
+// 供应商-接单
+// purchase produce product
+// POST /supplier/bill/ack?id=xxxx&type=purchase
+func SupplierBillAck(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	userId, _ := primitive.ObjectIDFromHex(apictx.User.Parent)
+	billType := c.Query("type")
+	_id := c.Query("id")
+	id, _ := primitive.ObjectIDFromHex(_id)
+	if id.IsZero() {
+		return nil, errors.New("id为空")
+	}
+	if userId.IsZero() {
+		return nil, errors.New("非法用户")
+	}
+	// purchase produce product
+	billTypes := []string{"purchase", "produce", "product"}
+	flagType := false
+	for _, bt := range billTypes {
+		if bt == billType {
+			flagType = true
+			break
+		}
+	}
+	if !flagType {
+		return nil, errors.New("订单类型错误")
+	}
+	isAck := true
+	switch billType {
+	case "purchase":
+		return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionBillPurchase, _id, &model.PurchaseBill{IsAck: &isAck, AckTime: time.Now()})
+	case "produce":
+		return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionBillProduce, _id, &model.ProduceBill{IsAck: &isAck, AckTime: time.Now()})
+	case "product":
+		return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionBillProduct, _id, &model.ProductBill{IsAck: &isAck, AckTime: time.Now()})
+	default:
+		return nil, errors.New("更新类型错误")
+	}
+
+}
+
 // 供应商-订单列表
 // purchase produce product
 // /supplier/bill/list?type=purchase&query={"status":"created"}

+ 3 - 3
boxcost/db/model/bill.go

@@ -84,7 +84,7 @@ type PurchaseBill struct {
 	SendTime time.Time `bson:"sendTime,omitempty" json:"sendTime"`
 
 	// 供应商确认
-	IsAck   bool      `bson:"isAck,omitempty" json:"isAck"`
+	IsAck   *bool     `bson:"isAck,omitempty" json:"isAck"`
 	AckTime time.Time `bson:"ackTime,omitempty" json:"ackTime"`
 	// 部件工序名
 	CompProduceName string `bson:"compProduceName,omitempty" json:"compProduceName"`
@@ -176,7 +176,7 @@ type ProduceBill struct {
 	IsSend   bool      `bson:"isSend,omitempty" json:"isSend"`
 	SendTime time.Time `bson:"sendTime,omitempty" json:"sendTime"`
 	// 供应商确认
-	IsAck   bool      `bson:"isAck,omitempty" json:"isAck"`
+	IsAck   *bool     `bson:"isAck,omitempty" json:"isAck"`
 	AckTime time.Time `bson:"ackTime,omitempty" json:"ackTime"`
 	// 部件包含工序
 	CompProduceName string `bson:"compProduceName,omitempty" json:"compProduceName"`
@@ -227,7 +227,7 @@ type ProductBill struct {
 	IsSend   bool      `bson:"isSend,omitempty" json:"isSend"`
 	SendTime time.Time `bson:"sendTime,omitempty" json:"sendTime"`
 	// 供应商确认
-	IsAck   bool      `bson:"isAck,omitempty" json:"isAck"`
+	IsAck   *bool     `bson:"isAck,omitempty" json:"isAck"`
 	AckTime time.Time `bson:"ackTime,omitempty" json:"ackTime"`
 	// 部件工序名
 	CompProduceName string `bson:"compProduceName,omitempty" json:"compProduceName"`

BIN
boxcost/thunder-file_0394cf77.xlsx