fix
This commit is contained in:
parent
8a4e122a0a
commit
0f4ae5164b
@ -3,7 +3,7 @@ package gmodel
|
|||||||
import "context"
|
import "context"
|
||||||
|
|
||||||
func (ml *FsMapLibraryModel) GetAllEnabledList(ctx context.Context, fields string) (resp []FsMapLibrary, err error) {
|
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 != "" {
|
if fields != "" {
|
||||||
db = db.Select(fields)
|
db = db.Select(fields)
|
||||||
}
|
}
|
||||||
@ -14,14 +14,14 @@ func (ml *FsMapLibraryModel) GetAllEnabledList(ctx context.Context, fields strin
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
func (ml *FsMapLibraryModel) Create(ctx context.Context, data *FsMapLibrary) error {
|
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 {
|
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 {
|
func (ml *FsMapLibraryModel) ChangeStatusByIds(ctx context.Context, ids []int64, status int64) error {
|
||||||
if len(ids) == 0 {
|
if len(ids) == 0 {
|
||||||
return nil
|
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/logic"
|
||||||
"fusenapi/server/map-library/internal/svc"
|
"fusenapi/server/map-library/internal/svc"
|
||||||
"fusenapi/server/map-library/internal/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func SaveMapLibraryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func SaveMapLibraryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
@ -52,20 +51,9 @@ func SaveMapLibraryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
// 如果claims为nil,则认为用户身份为白板用户
|
// 如果claims为nil,则认为用户身份为白板用户
|
||||||
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
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)
|
l := logic.NewSaveMapLibraryLogic(r.Context(), svcCtx)
|
||||||
resp := l.SaveMapLibrary(&req, userinfo)
|
resp := l.SaveMapLibrary(userinfo, r)
|
||||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
@ -7,6 +7,8 @@ import (
|
|||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"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 {
|
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first")
|
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]
|
//获取所有贴图数据[获取id]
|
||||||
mapLibraryModel := gmodel.NewFsMapLibraryModel(l.svcCtx.MysqlConn)
|
mapLibraryModel := gmodel.NewFsMapLibraryModel(l.svcCtx.MysqlConn)
|
||||||
maplibraryList, err := mapLibraryModel.GetAllEnabledList(l.ctx, "`id`")
|
maplibraryList, err := mapLibraryModel.GetAllEnabledList(l.ctx, "`id`")
|
||||||
@ -45,11 +54,11 @@ func (l *SaveMapLibraryLogic) SaveMapLibrary(req *types.SaveMapLibraryReq, useri
|
|||||||
sort := int64(0)
|
sort := int64(0)
|
||||||
status := int64(1)
|
status := int64(1)
|
||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
needDeleteMid := make([]int64, 0, len(req.Data))
|
needDeleteMid := make([]int64, 0, len(postData))
|
||||||
mapPostMid := make(map[int64]struct{})
|
mapPostMid := make(map[int64]struct{})
|
||||||
//开启事务
|
//开启事务
|
||||||
err = l.svcCtx.MysqlConn.Transaction(func(tx *gorm.DB) error {
|
err = l.svcCtx.MysqlConn.Transaction(func(tx *gorm.DB) error {
|
||||||
for _, v := range req.Data {
|
for _, v := range postData {
|
||||||
infoByte, _ := json.Marshal(v.Info)
|
infoByte, _ := json.Marshal(v.Info)
|
||||||
infoJsonStr := string(infoByte)
|
infoJsonStr := string(infoByte)
|
||||||
switch v.Mid {
|
switch v.Mid {
|
||||||
@ -72,9 +81,10 @@ func (l *SaveMapLibraryLogic) SaveMapLibrary(req *types.SaveMapLibraryReq, useri
|
|||||||
}
|
}
|
||||||
mapPostMid[midInt] = struct{}{}
|
mapPostMid[midInt] = struct{}{}
|
||||||
err = mapLibraryModel.Update(l.ctx, midInt, &gmodel.FsMapLibrary{
|
err = mapLibraryModel.Update(l.ctx, midInt, &gmodel.FsMapLibrary{
|
||||||
Title: &v.Info.Title,
|
Title: &v.Info.Title,
|
||||||
Info: &infoJsonStr,
|
Info: &infoJsonStr,
|
||||||
TagId: &v.Tag.Id,
|
TagId: &v.Tag.Id,
|
||||||
|
Status: &status,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -17,78 +17,74 @@ type MapLibraryListTag struct {
|
|||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SaveMapLibraryReq struct {
|
|
||||||
Data []SaveMapLibraryData `json:"-"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type SaveMapLibraryData struct {
|
type SaveMapLibraryData struct {
|
||||||
Mid string `json:"mid"`
|
Mid string `json:"mid"`
|
||||||
Tid string `json:"tid"`
|
Tid string `json:"tid"`
|
||||||
Ctime string `json:"ctime"`
|
Ctime string `json:"ctime"`
|
||||||
Tag Tag `json:"tag"`
|
Tag Tag `json:"tag,optional"`
|
||||||
Info Info `json:"info"`
|
Info Info `json:"info,optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Tag struct {
|
type Tag struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id,optional"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title,optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Info struct {
|
type Info struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id,optional"`
|
||||||
Tag string `json:"tag"`
|
Tag string `json:"tag,optional"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title,optional"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type,optional"`
|
||||||
Text string `json:"text"`
|
Text string `json:"text,optional"`
|
||||||
Fill string `json:"fill"`
|
Fill string `json:"fill,optional"`
|
||||||
FontSize int64 `json:"fontSize"`
|
FontSize int64 `json:"fontSize,optional"`
|
||||||
FontFamily string `json:"fontFamily"`
|
FontFamily string `json:"fontFamily,optional"`
|
||||||
IfBr bool `json:"ifBr"`
|
IfBr bool `json:"ifBr,optional"`
|
||||||
IfShow bool `json:"ifShow"`
|
IfShow bool `json:"ifShow,optional"`
|
||||||
IfGroup bool `json:"ifGroup"`
|
IfGroup bool `json:"ifGroup,optional"`
|
||||||
MaxNum int64 `json:"maxNum"`
|
MaxNum int64 `json:"maxNum,optional"`
|
||||||
Rotation int64 `json:"rotation"`
|
Rotation int64 `json:"rotation,optional"`
|
||||||
Align string `json:"align"`
|
Align string `json:"align,optional"`
|
||||||
VerticalAlign string `json:"verticalAlign"`
|
VerticalAlign string `json:"verticalAlign,optional"`
|
||||||
Material string `json:"material"`
|
Material string `json:"material,optional"`
|
||||||
Width float64 `json:"width"`
|
Width float64 `json:"width,optional"`
|
||||||
Height float64 `json:"height"`
|
Height float64 `json:"height,optional"`
|
||||||
X float64 `json:"x"`
|
X float64 `json:"x,optional"`
|
||||||
Y float64 `json:"Y"`
|
Y float64 `json:"Y,optional"`
|
||||||
Opacity float64 `json:"opacity"`
|
Opacity float64 `json:"opacity,optional"`
|
||||||
OptionalColor []OptionalColor `json:"optionalColor"`
|
OptionalColor []OptionalColor `json:"optionalColor,optional"`
|
||||||
ZIndex int64 `json:"zIndex"`
|
ZIndex int64 `json:"zIndex,optional"`
|
||||||
SvgPath string `json:"svgPath"`
|
SvgPath string `json:"svgPath,optional"`
|
||||||
Follow Follow `json:"follow"`
|
Follow Follow `json:"follow,optional"`
|
||||||
Group []Group `json:"group"`
|
Group []Group `json:"group,optional"`
|
||||||
CameraStand CameraStand `json:"cameraStand"`
|
CameraStand CameraStand `json:"cameraStand,optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Group struct {
|
type Group struct {
|
||||||
Tag string `json:"tag"`
|
Tag string `json:"tag,optional"`
|
||||||
Text string `json:"text"`
|
Text string `json:"text,optional"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title,optional"`
|
||||||
IfBr bool `json:"ifBr"`
|
IfBr bool `json:"ifBr,optional"`
|
||||||
IfShow bool `json:"ifShow"`
|
IfShow bool `json:"ifShow,optional"`
|
||||||
MaxNum int64 `json:"maxNum"`
|
MaxNum int64 `json:"maxNum,optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OptionalColor struct {
|
type OptionalColor struct {
|
||||||
OptionalColor string `json:"color"`
|
OptionalColor string `json:"color,optional"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name,optional"`
|
||||||
Default bool `json:"default"`
|
Default bool `json:"default,optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Follow struct {
|
type Follow struct {
|
||||||
Fill string `json:"fill"`
|
Fill string `json:"fill,optional"`
|
||||||
IfShow string `json:"ifShow"`
|
IfShow string `json:"ifShow,optional"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content,optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CameraStand struct {
|
type CameraStand struct {
|
||||||
X int64 `json:"x"`
|
X int64 `json:"x,optional"`
|
||||||
Y int64 `json:"y"`
|
Y int64 `json:"y,optional"`
|
||||||
Z int64 `json:"z"`
|
Z int64 `json:"z,optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
|
@ -14,7 +14,7 @@ service map-library {
|
|||||||
get /map-library/list ( ) returns (response);
|
get /map-library/list ( ) returns (response);
|
||||||
//保存贴图信息
|
//保存贴图信息
|
||||||
@handler SaveMapLibraryHandler
|
@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 {
|
type SaveMapLibraryData {
|
||||||
Mid string `json:"mid"`
|
Mid string `json:"mid"`
|
||||||
Tid string `json:"tid"`
|
Tid string `json:"tid"`
|
||||||
Ctime string `json:"ctime"`
|
Ctime string `json:"ctime"`
|
||||||
Tag Tag `json:"tag"`
|
Tag Tag `json:"tag,optional"`
|
||||||
Info Info `json:"info"`
|
Info Info `json:"info,optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Tag {
|
type Tag {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id,optional"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title,optional"`
|
||||||
}
|
}
|
||||||
type Info {
|
type Info {
|
||||||
Id string `json:"id"`
|
Id string `json:"id,optional"`
|
||||||
Tag string `json:"tag"`
|
Tag string `json:"tag,optional"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title,optional"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type,optional"`
|
||||||
Text string `json:"text"`
|
Text string `json:"text,optional"`
|
||||||
Fill string `json:"fill"`
|
Fill string `json:"fill,optional"`
|
||||||
FontSize int64 `json:"fontSize"`
|
FontSize int64 `json:"fontSize,optional"`
|
||||||
FontFamily string `json:"fontFamily"`
|
FontFamily string `json:"fontFamily,optional"`
|
||||||
IfBr bool `json:"ifBr"`
|
IfBr bool `json:"ifBr,optional"`
|
||||||
IfShow bool `json:"ifShow"`
|
IfShow bool `json:"ifShow,optional"`
|
||||||
IfGroup bool `json:"ifGroup"`
|
IfGroup bool `json:"ifGroup,optional"`
|
||||||
MaxNum int64 `json:"maxNum"`
|
MaxNum int64 `json:"maxNum,optional"`
|
||||||
Rotation int64 `json:"rotation"`
|
Rotation int64 `json:"rotation,optional"`
|
||||||
Align string `json:"align"`
|
Align string `json:"align,optional"`
|
||||||
VerticalAlign string `json:"verticalAlign"`
|
VerticalAlign string `json:"verticalAlign,optional"`
|
||||||
Material string `json:"material"`
|
Material string `json:"material,optional"`
|
||||||
Width float64 `json:"width"`
|
Width float64 `json:"width,optional"`
|
||||||
Height float64 `json:"height"`
|
Height float64 `json:"height,optional"`
|
||||||
X float64 `json:"x"`
|
X float64 `json:"x,optional"`
|
||||||
Y float64 `json:"Y"`
|
Y float64 `json:"Y,optional"`
|
||||||
Opacity float64 `json:"opacity"`
|
Opacity float64 `json:"opacity,optional"`
|
||||||
OptionalColor []OptionalColor `json:"optionalColor"`
|
OptionalColor []OptionalColor `json:"optionalColor,optional"`
|
||||||
ZIndex int64 `json:"zIndex"`
|
ZIndex int64 `json:"zIndex,optional"`
|
||||||
SvgPath string `json:"svgPath"`
|
SvgPath string `json:"svgPath,optional"`
|
||||||
Follow Follow `json:"follow"`
|
Follow Follow `json:"follow,optional"`
|
||||||
Group []Group `json:"group"`
|
Group []Group `json:"group,optional"`
|
||||||
CameraStand CameraStand `json:"cameraStand"`
|
CameraStand CameraStand `json:"cameraStand,optional"`
|
||||||
}
|
}
|
||||||
type Group {
|
type Group {
|
||||||
Tag string `json:"tag"`
|
Tag string `json:"tag,optional"`
|
||||||
Text string `json:"text"`
|
Text string `json:"text,optional"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title,optional"`
|
||||||
IfBr bool `json:"ifBr"`
|
IfBr bool `json:"ifBr,optional"`
|
||||||
IfShow bool `json:"ifShow"`
|
IfShow bool `json:"ifShow,optional"`
|
||||||
MaxNum int64 `json:"maxNum"`
|
MaxNum int64 `json:"maxNum,optional"`
|
||||||
}
|
}
|
||||||
type OptionalColor {
|
type OptionalColor {
|
||||||
OptionalColor string `json:"color"`
|
OptionalColor string `json:"color,optional"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name,optional"`
|
||||||
Default bool `json:"default"`
|
Default bool `json:"default,optional"`
|
||||||
}
|
}
|
||||||
type Follow {
|
type Follow {
|
||||||
Fill string `json:"fill"`
|
Fill string `json:"fill,optional"`
|
||||||
IfShow string `json:"ifShow"`
|
IfShow string `json:"ifShow,optional"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content,optional"`
|
||||||
}
|
}
|
||||||
type CameraStand {
|
type CameraStand {
|
||||||
X int64 `json:"x"`
|
X int64 `json:"x,optional"`
|
||||||
Y int64 `json:"y"`
|
Y int64 `json:"y,optional"`
|
||||||
Z int64 `json:"z"`
|
Z int64 `json:"z,optional"`
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user