fix
This commit is contained in:
@@ -7,6 +7,8 @@ import (
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"gorm.io/gorm"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -30,10 +32,17 @@ func NewSaveMapLibraryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Sa
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SaveMapLibraryLogic) SaveMapLibrary(req *types.SaveMapLibraryReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
func (l *SaveMapLibraryLogic) SaveMapLibrary(userinfo *auth.UserInfo, req *http.Request) (resp *basic.Response) {
|
||||
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first")
|
||||
}
|
||||
bodyData, err := ioutil.ReadAll(req.Body)
|
||||
defer req.Body.Close()
|
||||
var postData []types.SaveMapLibraryData
|
||||
if err = json.Unmarshal(bodyData, &postData); err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeSaveErr, "param err")
|
||||
}
|
||||
//获取所有贴图数据[获取id]
|
||||
mapLibraryModel := gmodel.NewFsMapLibraryModel(l.svcCtx.MysqlConn)
|
||||
maplibraryList, err := mapLibraryModel.GetAllEnabledList(l.ctx, "`id`")
|
||||
@@ -45,11 +54,11 @@ func (l *SaveMapLibraryLogic) SaveMapLibrary(req *types.SaveMapLibraryReq, useri
|
||||
sort := int64(0)
|
||||
status := int64(1)
|
||||
now := time.Now().Unix()
|
||||
needDeleteMid := make([]int64, 0, len(req.Data))
|
||||
needDeleteMid := make([]int64, 0, len(postData))
|
||||
mapPostMid := make(map[int64]struct{})
|
||||
//开启事务
|
||||
err = l.svcCtx.MysqlConn.Transaction(func(tx *gorm.DB) error {
|
||||
for _, v := range req.Data {
|
||||
for _, v := range postData {
|
||||
infoByte, _ := json.Marshal(v.Info)
|
||||
infoJsonStr := string(infoByte)
|
||||
switch v.Mid {
|
||||
@@ -72,9 +81,10 @@ func (l *SaveMapLibraryLogic) SaveMapLibrary(req *types.SaveMapLibraryReq, useri
|
||||
}
|
||||
mapPostMid[midInt] = struct{}{}
|
||||
err = mapLibraryModel.Update(l.ctx, midInt, &gmodel.FsMapLibrary{
|
||||
Title: &v.Info.Title,
|
||||
Info: &infoJsonStr,
|
||||
TagId: &v.Tag.Id,
|
||||
Title: &v.Info.Title,
|
||||
Info: &infoJsonStr,
|
||||
TagId: &v.Tag.Id,
|
||||
Status: &status,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user