fix
This commit is contained in:
parent
8a4e122a0a
commit
0f4ae5164b
|
@ -3,7 +3,7 @@ package gmodel
|
|||
import "context"
|
||||
|
||||
func (ml *FsMapLibraryModel) GetAllEnabledList(ctx context.Context, fields string) (resp []FsMapLibrary, err error) {
|
||||
db := ml.db.WithContext(ctx).Model(&FsMapLibrary{}).Where("`status` = ?", 0)
|
||||
db := ml.db.WithContext(ctx).Model(&FsMapLibrary{}).Where("`status` = ?", 1)
|
||||
if fields != "" {
|
||||
db = db.Select(fields)
|
||||
}
|
||||
|
@ -14,14 +14,14 @@ func (ml *FsMapLibraryModel) GetAllEnabledList(ctx context.Context, fields strin
|
|||
return
|
||||
}
|
||||
func (ml *FsMapLibraryModel) Create(ctx context.Context, data *FsMapLibrary) error {
|
||||
return ml.db.WithContext(ctx).Create(data).Error
|
||||
return ml.db.WithContext(ctx).Model(&FsMapLibrary{}).Create(data).Error
|
||||
}
|
||||
func (ml *FsMapLibraryModel) Update(ctx context.Context, id int64, data *FsMapLibrary) error {
|
||||
return ml.db.WithContext(ctx).Where("`id` = ? ", id).Updates(data).Error
|
||||
return ml.db.WithContext(ctx).Model(&FsMapLibrary{}).Where("`id` = ? ", id).Updates(data).Error
|
||||
}
|
||||
func (ml *FsMapLibraryModel) ChangeStatusByIds(ctx context.Context, ids []int64, status int64) error {
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
return ml.db.WithContext(ctx).Where("`id` in (?) ", ids).Update("status", 0).Error
|
||||
return ml.db.WithContext(ctx).Model(&FsMapLibrary{}).Where("`id` in (?) ", ids).Update("status", 0).Error
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ import (
|
|||
|
||||
"fusenapi/server/map-library/internal/logic"
|
||||
"fusenapi/server/map-library/internal/svc"
|
||||
"fusenapi/server/map-library/internal/types"
|
||||
)
|
||||
|
||||
func SaveMapLibraryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
|
@ -52,20 +51,9 @@ func SaveMapLibraryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||
// 如果claims为nil,则认为用户身份为白板用户
|
||||
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||
}
|
||||
|
||||
var req types.SaveMapLibraryReq
|
||||
// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||
Code: 510,
|
||||
Message: "parameter error",
|
||||
})
|
||||
logx.Info(err)
|
||||
return
|
||||
}
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewSaveMapLibraryLogic(r.Context(), svcCtx)
|
||||
resp := l.SaveMapLibrary(&req, userinfo)
|
||||
resp := l.SaveMapLibrary(userinfo, r)
|
||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||
if resp != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -17,78 +17,74 @@ type MapLibraryListTag struct {
|
|||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
type SaveMapLibraryReq struct {
|
||||
Data []SaveMapLibraryData `json:"-"`
|
||||
}
|
||||
|
||||
type SaveMapLibraryData struct {
|
||||
Mid string `json:"mid"`
|
||||
Tid string `json:"tid"`
|
||||
Ctime string `json:"ctime"`
|
||||
Tag Tag `json:"tag"`
|
||||
Info Info `json:"info"`
|
||||
Tag Tag `json:"tag,optional"`
|
||||
Info Info `json:"info,optional"`
|
||||
}
|
||||
|
||||
type Tag struct {
|
||||
Id int64 `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Id int64 `json:"id,optional"`
|
||||
Title string `json:"title,optional"`
|
||||
}
|
||||
|
||||
type Info struct {
|
||||
Id string `json:"id"`
|
||||
Tag string `json:"tag"`
|
||||
Title string `json:"title"`
|
||||
Type string `json:"type"`
|
||||
Text string `json:"text"`
|
||||
Fill string `json:"fill"`
|
||||
FontSize int64 `json:"fontSize"`
|
||||
FontFamily string `json:"fontFamily"`
|
||||
IfBr bool `json:"ifBr"`
|
||||
IfShow bool `json:"ifShow"`
|
||||
IfGroup bool `json:"ifGroup"`
|
||||
MaxNum int64 `json:"maxNum"`
|
||||
Rotation int64 `json:"rotation"`
|
||||
Align string `json:"align"`
|
||||
VerticalAlign string `json:"verticalAlign"`
|
||||
Material string `json:"material"`
|
||||
Width float64 `json:"width"`
|
||||
Height float64 `json:"height"`
|
||||
X float64 `json:"x"`
|
||||
Y float64 `json:"Y"`
|
||||
Opacity float64 `json:"opacity"`
|
||||
OptionalColor []OptionalColor `json:"optionalColor"`
|
||||
ZIndex int64 `json:"zIndex"`
|
||||
SvgPath string `json:"svgPath"`
|
||||
Follow Follow `json:"follow"`
|
||||
Group []Group `json:"group"`
|
||||
CameraStand CameraStand `json:"cameraStand"`
|
||||
Id string `json:"id,optional"`
|
||||
Tag string `json:"tag,optional"`
|
||||
Title string `json:"title,optional"`
|
||||
Type string `json:"type,optional"`
|
||||
Text string `json:"text,optional"`
|
||||
Fill string `json:"fill,optional"`
|
||||
FontSize int64 `json:"fontSize,optional"`
|
||||
FontFamily string `json:"fontFamily,optional"`
|
||||
IfBr bool `json:"ifBr,optional"`
|
||||
IfShow bool `json:"ifShow,optional"`
|
||||
IfGroup bool `json:"ifGroup,optional"`
|
||||
MaxNum int64 `json:"maxNum,optional"`
|
||||
Rotation int64 `json:"rotation,optional"`
|
||||
Align string `json:"align,optional"`
|
||||
VerticalAlign string `json:"verticalAlign,optional"`
|
||||
Material string `json:"material,optional"`
|
||||
Width float64 `json:"width,optional"`
|
||||
Height float64 `json:"height,optional"`
|
||||
X float64 `json:"x,optional"`
|
||||
Y float64 `json:"Y,optional"`
|
||||
Opacity float64 `json:"opacity,optional"`
|
||||
OptionalColor []OptionalColor `json:"optionalColor,optional"`
|
||||
ZIndex int64 `json:"zIndex,optional"`
|
||||
SvgPath string `json:"svgPath,optional"`
|
||||
Follow Follow `json:"follow,optional"`
|
||||
Group []Group `json:"group,optional"`
|
||||
CameraStand CameraStand `json:"cameraStand,optional"`
|
||||
}
|
||||
|
||||
type Group struct {
|
||||
Tag string `json:"tag"`
|
||||
Text string `json:"text"`
|
||||
Title string `json:"title"`
|
||||
IfBr bool `json:"ifBr"`
|
||||
IfShow bool `json:"ifShow"`
|
||||
MaxNum int64 `json:"maxNum"`
|
||||
Tag string `json:"tag,optional"`
|
||||
Text string `json:"text,optional"`
|
||||
Title string `json:"title,optional"`
|
||||
IfBr bool `json:"ifBr,optional"`
|
||||
IfShow bool `json:"ifShow,optional"`
|
||||
MaxNum int64 `json:"maxNum,optional"`
|
||||
}
|
||||
|
||||
type OptionalColor struct {
|
||||
OptionalColor string `json:"color"`
|
||||
Name string `json:"name"`
|
||||
Default bool `json:"default"`
|
||||
OptionalColor string `json:"color,optional"`
|
||||
Name string `json:"name,optional"`
|
||||
Default bool `json:"default,optional"`
|
||||
}
|
||||
|
||||
type Follow struct {
|
||||
Fill string `json:"fill"`
|
||||
IfShow string `json:"ifShow"`
|
||||
Content string `json:"content"`
|
||||
Fill string `json:"fill,optional"`
|
||||
IfShow string `json:"ifShow,optional"`
|
||||
Content string `json:"content,optional"`
|
||||
}
|
||||
|
||||
type CameraStand struct {
|
||||
X int64 `json:"x"`
|
||||
Y int64 `json:"y"`
|
||||
Z int64 `json:"z"`
|
||||
X int64 `json:"x,optional"`
|
||||
Y int64 `json:"y,optional"`
|
||||
Z int64 `json:"z,optional"`
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
|
|
|
@ -14,7 +14,7 @@ service map-library {
|
|||
get /map-library/list ( ) returns (response);
|
||||
//保存贴图信息
|
||||
@handler SaveMapLibraryHandler
|
||||
post /map-library/save (SaveMapLibraryReq) returns (response);
|
||||
post /map-library/save () returns (response);
|
||||
}
|
||||
|
||||
//获取贴图库列表
|
||||
|
@ -30,70 +30,67 @@ type MapLibraryListTag {
|
|||
}
|
||||
|
||||
//保存贴图信息
|
||||
type SaveMapLibraryReq {
|
||||
Data []SaveMapLibraryData `json:"-"`
|
||||
}
|
||||
type SaveMapLibraryData {
|
||||
Mid string `json:"mid"`
|
||||
Tid string `json:"tid"`
|
||||
Ctime string `json:"ctime"`
|
||||
Tag Tag `json:"tag"`
|
||||
Info Info `json:"info"`
|
||||
Tag Tag `json:"tag,optional"`
|
||||
Info Info `json:"info,optional"`
|
||||
}
|
||||
|
||||
type Tag {
|
||||
Id int64 `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Id int64 `json:"id,optional"`
|
||||
Title string `json:"title,optional"`
|
||||
}
|
||||
type Info {
|
||||
Id string `json:"id"`
|
||||
Tag string `json:"tag"`
|
||||
Title string `json:"title"`
|
||||
Type string `json:"type"`
|
||||
Text string `json:"text"`
|
||||
Fill string `json:"fill"`
|
||||
FontSize int64 `json:"fontSize"`
|
||||
FontFamily string `json:"fontFamily"`
|
||||
IfBr bool `json:"ifBr"`
|
||||
IfShow bool `json:"ifShow"`
|
||||
IfGroup bool `json:"ifGroup"`
|
||||
MaxNum int64 `json:"maxNum"`
|
||||
Rotation int64 `json:"rotation"`
|
||||
Align string `json:"align"`
|
||||
VerticalAlign string `json:"verticalAlign"`
|
||||
Material string `json:"material"`
|
||||
Width float64 `json:"width"`
|
||||
Height float64 `json:"height"`
|
||||
X float64 `json:"x"`
|
||||
Y float64 `json:"Y"`
|
||||
Opacity float64 `json:"opacity"`
|
||||
OptionalColor []OptionalColor `json:"optionalColor"`
|
||||
ZIndex int64 `json:"zIndex"`
|
||||
SvgPath string `json:"svgPath"`
|
||||
Follow Follow `json:"follow"`
|
||||
Group []Group `json:"group"`
|
||||
CameraStand CameraStand `json:"cameraStand"`
|
||||
Id string `json:"id,optional"`
|
||||
Tag string `json:"tag,optional"`
|
||||
Title string `json:"title,optional"`
|
||||
Type string `json:"type,optional"`
|
||||
Text string `json:"text,optional"`
|
||||
Fill string `json:"fill,optional"`
|
||||
FontSize int64 `json:"fontSize,optional"`
|
||||
FontFamily string `json:"fontFamily,optional"`
|
||||
IfBr bool `json:"ifBr,optional"`
|
||||
IfShow bool `json:"ifShow,optional"`
|
||||
IfGroup bool `json:"ifGroup,optional"`
|
||||
MaxNum int64 `json:"maxNum,optional"`
|
||||
Rotation int64 `json:"rotation,optional"`
|
||||
Align string `json:"align,optional"`
|
||||
VerticalAlign string `json:"verticalAlign,optional"`
|
||||
Material string `json:"material,optional"`
|
||||
Width float64 `json:"width,optional"`
|
||||
Height float64 `json:"height,optional"`
|
||||
X float64 `json:"x,optional"`
|
||||
Y float64 `json:"Y,optional"`
|
||||
Opacity float64 `json:"opacity,optional"`
|
||||
OptionalColor []OptionalColor `json:"optionalColor,optional"`
|
||||
ZIndex int64 `json:"zIndex,optional"`
|
||||
SvgPath string `json:"svgPath,optional"`
|
||||
Follow Follow `json:"follow,optional"`
|
||||
Group []Group `json:"group,optional"`
|
||||
CameraStand CameraStand `json:"cameraStand,optional"`
|
||||
}
|
||||
type Group {
|
||||
Tag string `json:"tag"`
|
||||
Text string `json:"text"`
|
||||
Title string `json:"title"`
|
||||
IfBr bool `json:"ifBr"`
|
||||
IfShow bool `json:"ifShow"`
|
||||
MaxNum int64 `json:"maxNum"`
|
||||
Tag string `json:"tag,optional"`
|
||||
Text string `json:"text,optional"`
|
||||
Title string `json:"title,optional"`
|
||||
IfBr bool `json:"ifBr,optional"`
|
||||
IfShow bool `json:"ifShow,optional"`
|
||||
MaxNum int64 `json:"maxNum,optional"`
|
||||
}
|
||||
type OptionalColor {
|
||||
OptionalColor string `json:"color"`
|
||||
Name string `json:"name"`
|
||||
Default bool `json:"default"`
|
||||
OptionalColor string `json:"color,optional"`
|
||||
Name string `json:"name,optional"`
|
||||
Default bool `json:"default,optional"`
|
||||
}
|
||||
type Follow {
|
||||
Fill string `json:"fill"`
|
||||
IfShow string `json:"ifShow"`
|
||||
Content string `json:"content"`
|
||||
Fill string `json:"fill,optional"`
|
||||
IfShow string `json:"ifShow,optional"`
|
||||
Content string `json:"content,optional"`
|
||||
}
|
||||
type CameraStand {
|
||||
X int64 `json:"x"`
|
||||
Y int64 `json:"y"`
|
||||
Z int64 `json:"z"`
|
||||
X int64 `json:"x,optional"`
|
||||
Y int64 `json:"y,optional"`
|
||||
Z int64 `json:"z,optional"`
|
||||
}
|
Loading…
Reference in New Issue
Block a user