| | |
| | | import ( |
| | | "fmt" |
| | | "gorm.io/gorm/schema" |
| | | "strconv" |
| | | "time" |
| | | "wms/conf" |
| | | "wms/extend/util" |
| | | "wms/pkg/logx" |
| | | "wms/pkg/mysqlx" |
| | | "wms/pkg/snowflake" |
| | | "wms/proto/code" |
| | | |
| | | "gorm.io/gorm" |
| | | ) |
| | |
| | | return nil |
| | | } |
| | | |
| | | 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 + 1) |
| | | 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 |
| | | } |
| | | |
| | | func Init() error { |
| | | fmt.Printf("dsn=%v\n", conf.DbConf.Dsn) |
| | | if err := mysqlx.Init(conf.DbConf, logx.GetLogger()); err != nil { |