You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.1 KiB

package command
import (
"math/rand"
command2 "recook/internal/v2/model/recook/command"
"recook/tools"
"time"
)
var CommandLogic = &commandLogic{}
type commandLogic struct {
}
// Random @Title 生成随机数
func (*commandLogic) Random(length int) string {
var strByte = []byte("QWERTYUIOPLKJHGFDSAZXCVBNMqweasdzxcrtyfghvbnuiojklmop123456789")
strByteLen := len(strByte)
result := ""
r := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := 0; i < length; i++ {
result += string(strByte[r.Intn(strByteLen)])
}
return result
}
// @Style 生成瑞口令
func (*commandLogic) Generate(value string) string {
command := tools.RandStr(12)
recookCommandModel := &command2.RecookCommandModel{
Command: command,
Value: value,
}
recookCommandModel.Create(recookCommandModel)
if recookCommandModel.Id > 0 {
return recookCommandModel.Command
}
return ""
}
// @Style 解析瑞口令
func (*commandLogic) Analysis(command string) string {
recookCommandModel := &command2.RecookCommandModel{}
commandInfo := recookCommandModel.FindByCommand(command)
return commandInfo.Value
}