Browse Source

rename func && fix serialNumber length

animeic 2 years ago
parent
commit
1b515e8829
4 changed files with 11 additions and 11 deletions
  1. 3 3
      boxcost/api/bill-produce.go
  2. 3 3
      boxcost/api/bill.go
  3. 1 1
      boxcost/api/test_print.go
  4. 4 4
      boxcost/api/utils.go

+ 3 - 3
boxcost/api/bill-produce.go

@@ -53,7 +53,7 @@ func CreateProduceBill(c *gin.Context, apictx *ApiSession) (interface{}, error)
 		return nil, errors.New("类型为空")
 	}
 
-	bill.SerialNumber, err = incrementer(apictx, bill.Type)
+	bill.SerialNumber, err = generateSerial(apictx, bill.Type)
 	if err != nil {
 		return nil, err
 	}
@@ -120,14 +120,14 @@ func UpdateProduceBill(c *gin.Context, apictx *ApiSession) (interface{}, error)
 		return nil, errors.New("id的为空")
 	}
 
-	billType, err := SearchBillTypeById(apictx, repo.CollectionBillProduce, bill.Id)
+	billType, err := searchBillTypeById(apictx, repo.CollectionBillProduce, bill.Id)
 	if err != nil {
 		return nil, err
 	}
 
 	// 如果更改类型
 	if billType != bill.Type {
-		bill.SerialNumber, err = incrementer(apictx, bill.Type)
+		bill.SerialNumber, err = generateSerial(apictx, bill.Type)
 		if err != nil {
 			return nil, err
 		}

+ 3 - 3
boxcost/api/bill.go

@@ -61,7 +61,7 @@ func CreateBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 		return nil, errors.New("类型为空")
 	}
 
-	bill.SerialNumber, err = incrementer(apictx, bill.Type)
+	bill.SerialNumber, err = generateSerial(apictx, bill.Type)
 	if err != nil {
 		return nil, err
 	}
@@ -126,14 +126,14 @@ func UpdateBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	if bill.Id.Hex() == "" {
 		return nil, errors.New("id的为空")
 	}
-	billType, err := SearchBillTypeById(apictx, repo.CollectionBillPurchase, bill.Id)
+	billType, err := searchBillTypeById(apictx, repo.CollectionBillPurchase, bill.Id)
 	if err != nil {
 		return nil, err
 	}
 
 	// 如果更改类型
 	if billType != bill.Type {
-		bill.SerialNumber, err = incrementer(apictx, bill.Type)
+		bill.SerialNumber, err = generateSerial(apictx, bill.Type)
 		if err != nil {
 			return nil, err
 		}

+ 1 - 1
boxcost/api/test_print.go

@@ -10,7 +10,7 @@ import (
 func Printr(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 	id, _ := primitive.ObjectIDFromHex("638edc9ac3242a12b462efce")
-	return SearchBillTypeById(apictx, repo.CollectionBillProduce, id)
+	return searchBillTypeById(apictx, repo.CollectionBillProduce, id)
 	// return incrementer(apictx, "纸张类")
 
 }

+ 4 - 4
boxcost/api/utils.go

@@ -9,7 +9,7 @@ import (
 	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
-func incrementer(ctx *ApiSession, typeName string) (serial string, err error) {
+func generateSerial(ctx *ApiSession, typeName string) (serial string, err error) {
 	// 获取类型
 	cate := &model.Category{}
 	found, err := repo.RepoSeachDoc(ctx.CreateRepoCtx(), &repo.DocSearchOptions{
@@ -21,7 +21,7 @@ func incrementer(ctx *ApiSession, typeName string) (serial string, err error) {
 	if !found || err != nil {
 		return "", fmt.Errorf("未找到该分类")
 	}
-	// increment index加1
+	// 自增器 increment index加1
 	increment := &model.Increment{}
 	repo.RepoSeachDoc(ctx.CreateRepoCtx(), &repo.DocSearchOptions{
 		CollectName: repo.CollectionIncrement,
@@ -32,11 +32,11 @@ func incrementer(ctx *ApiSession, typeName string) (serial string, err error) {
 	repo.RepoAddDoc(ctx.CreateRepoCtx(), repo.CollectionIncrement, &model.Increment{Index: index})
 
 	// 拼接为序号
-	return fmt.Sprintf("%s-%05d", cate.LetterName, index), nil
+	return fmt.Sprintf("%s-%06d", cate.LetterName, index), nil
 
 }
 
-func SearchBillTypeById(ctx *ApiSession, collectName string, id primitive.ObjectID) (string, error) {
+func searchBillTypeById(ctx *ApiSession, collectName string, id primitive.ObjectID) (string, error) {
 	found, curbill := repo.RepoSeachDocMap(ctx.CreateRepoCtx(), &repo.DocSearchOptions{
 		CollectName: collectName,
 		Project:     []string{"type"},