liujiandao
2023-10-11 34ef7217a034599217a7fdd1e28e1ae6910e1b4b
model/util.go
@@ -2,8 +2,11 @@
import (
   "aps_crm/pkg/mysqlx"
   "aps_crm/proto/code"
   "fmt"
   "gorm.io/gorm"
   "strconv"
   "time"
)
// WithTransaction : var funcs []func(db *gorm.DB) error,把相关函数添加进去
@@ -26,3 +29,28 @@
   err = tx.Commit().Error
   return
}
func GetAutoCode(id int, codeStandard *code.CodeStandard) string {
   autoCode := ""
   var prefixValue string
   if codeStandard.AutoRule.PrefixMethod == 2 { // 来源单据
      prefixValue = ""
   } else { // 固定值
      prefixValue = codeStandard.AutoRule.PrefixValue
   }
   strMaxAutoIncr := strconv.Itoa(id)
   count := int(codeStandard.AutoRule.AutoLength) - len(strMaxAutoIncr)
   for i := 0; i < count; i++ {
      strMaxAutoIncr = "0" + strMaxAutoIncr
   }
   var suffixValue string
   if codeStandard.AutoRule.SuffixMethod == 2 { // 年月日+自增长
      suffixValue = fmt.Sprintf("%v%v", time.Now().Format("20060102"), strMaxAutoIncr)
   } else { // 自增长
      suffixValue = strMaxAutoIncr
   }
   autoCode = prefixValue + suffixValue
   return autoCode
}