f5749b87dc
CI / changes (push) Successful in 1m30s
CI / ad (push) Successful in 31s
CI / admin (push) Successful in 22s
CI / bff (push) Successful in 20s
CI / chore (push) Successful in 21s
CI / equipment (push) Successful in 22s
CI / express (push) Successful in 21s
CI / factory (push) Successful in 19s
CI / message (push) Successful in 18s
CI / order (push) Successful in 19s
CI / payment (push) Successful in 20s
CI / percutaneous (push) Successful in 19s
CI / product (push) Successful in 20s
CI / record (push) Successful in 19s
CI / sale (push) Successful in 19s
CI / support (push) Successful in 19s
CI / task (push) Successful in 18s
CI / user (push) Successful in 19s
CI / wecom (push) Successful in 20s
77 lines
1.8 KiB
Go
77 lines
1.8 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"lone-services/pkg/utils"
|
|
"lone-services/services/express/internal/dao"
|
|
"lone-services/services/express/internal/model"
|
|
"lone-services/services/express/validator"
|
|
"strconv"
|
|
"time"
|
|
|
|
"lone-services/rpc/express/pb"
|
|
"lone-services/services/express/internal/svc"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type PrintBarCodeLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
BaseLogic
|
|
}
|
|
|
|
func NewPrintBarCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PrintBarCodeLogic {
|
|
return &PrintBarCodeLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *PrintBarCodeLogic) PrintBarCode(in *express.PrintBarCodeRequest) (*express.Response, error) {
|
|
var v validator.PrintBarCodeValidator
|
|
if fail := l.checkParams(in, &v); fail != nil {
|
|
return fail, nil
|
|
}
|
|
adminInfo := utils.GetUserFromCtx(l.ctx)
|
|
if adminInfo.ID < utils.NumberOne {
|
|
return l.fail(utils.ErrorNoLoginInfo)
|
|
}
|
|
|
|
var info []dao.CodeInfo
|
|
modelObj := model.CodeModel{}.Init()
|
|
for i := utils.NumberOne; i <= int(in.Number); i++ {
|
|
tmp := dao.CodeCreate{
|
|
Code: l.getCode(in.ProductId, adminInfo.ID),
|
|
ProductId: int(in.ProductId),
|
|
AdminId: int(adminInfo.ID),
|
|
AdminName: adminInfo.Name,
|
|
Status: utils.StatusOk,
|
|
}
|
|
err := modelObj.Create(&tmp)
|
|
if err != nil {
|
|
l.Logger.Error(err)
|
|
} else {
|
|
info = append(info, dao.CodeInfo{
|
|
Id: tmp.Id,
|
|
ProductId: tmp.ProductId,
|
|
Code: tmp.Code,
|
|
Status: utils.StatusOk,
|
|
})
|
|
}
|
|
}
|
|
|
|
return l.ok(info)
|
|
}
|
|
|
|
func (l *PrintBarCodeLogic) getCode(productId, uId int64) string {
|
|
now := time.Now()
|
|
code := dao.BacCode + fmt.Sprintf("%04d", productId) +
|
|
fmt.Sprintf("%04d", uId) + now.Format("20060102150405") +
|
|
strconv.Itoa(utils.GetRandNum(1000))
|
|
return code
|
|
}
|