1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- package logic
- import (
- se "app.yhyue.com/moapp/jybase/encrypt"
- "context"
- "fmt"
- "jyBXBase/rpc/bxcollection/model"
- "log"
- "strconv"
- "time"
- "jyBXBase/rpc/bxcollection/bxcol"
- "jyBXBase/rpc/bxcollection/internal/svc"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type AddlabelLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewAddlabelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddlabelLogic {
- return &AddlabelLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- // 新增标签
- func (l *AddlabelLogic) Addlabel(in *bxcol.AddlabelReq) (*bxcol.AddlabelRes, error) {
- userid := in.UserId
- var resp bxcol.AddlabelRes
- if in.Name == "" {
- return &bxcol.AddlabelRes{
- ErrCode: -1,
- ErrMsg: "未传入名字",
- }, nil
- }
- //now := time.Now().Unix()
- if model.Mysql.CountBySql(fmt.Sprintf(`select count(1) from %s where userid =?`, "bdlabel"), userid) >= 50 {
- return &bxcol.AddlabelRes{
- ErrCode: -1,
- ErrMsg: "标签数量已达上限",
- }, nil
- }
- //是否有重名
- if labArr := *model.Mysql.SelectBySql(fmt.Sprintf("select * from %s where labelname = ? and userid = ?", "bdlabel"), in.Name, userid); len(labArr) == 1 {
- return &bxcol.AddlabelRes{
- ErrCode: -1,
- ErrMsg: "该标签已经存在",
- }, nil
- } else { //新增标签
- insertMap := map[string]interface{}{
- "userid": userid,
- "labelname": in.Name,
- "createdate": time.Now(),
- }
- if lid := model.Mysql.Insert("bdlabel", insertMap); lid > 0 {
- resp.Labid = se.SE.EncodeString(strconv.FormatInt(lid, 10))
- return &resp, nil
- } else {
- log.Println("新增标签失败 - name:", in.Name)
- resp.ErrMsg = "保存失败"
- resp.ErrCode = -1
- return &resp, nil
- }
- }
- }
|