Compare commits
No commits in common. "cac0161585ccecfb0b48c4ce651fe8c2e910412f" and "89dfd58e1c6ddd3e3cd25627ddaaee69db8a3fe6" have entirely different histories.
cac0161585
...
89dfd58e1c
@ -1,12 +1,9 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import {{.authImport}}
|
import {{.authImport}}
|
||||||
import "fusenapi/server/faq/internal/types"
|
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
SourceMysql string
|
|
||||||
Auth types.Auth
|
|
||||||
{{.auth}}
|
{{.auth}}
|
||||||
{{.jwtTrans}}
|
{{.jwtTrans}}
|
||||||
}
|
}
|
||||||
|
@ -27,11 +27,7 @@ func (m *FsGuestModel) GenerateGuestID(ctx context.Context, AccessSecret *string
|
|||||||
}
|
}
|
||||||
record.AuthKey = &authKey
|
record.AuthKey = &authKey
|
||||||
record.CreatedAt = &now
|
record.CreatedAt = &now
|
||||||
err = tx.Updates(record).Error
|
tx.Updates(record)
|
||||||
if err != nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
import (
|
import "context"
|
||||||
"context"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
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` = ?", 1)
|
db := ml.db.WithContext(ctx).Model(&FsMapLibrary{}).Where("`status` = ?", 1)
|
||||||
@ -28,26 +25,3 @@ func (ml *FsMapLibraryModel) ChangeStatusByIds(ctx context.Context, ids []int64,
|
|||||||
}
|
}
|
||||||
return ml.db.WithContext(ctx).Model(&FsMapLibrary{}).Where("`id` in (?) ", ids).Update("status", 0).Error
|
return ml.db.WithContext(ctx).Model(&FsMapLibrary{}).Where("`id` in (?) ", ids).Update("status", 0).Error
|
||||||
}
|
}
|
||||||
func (ml *FsMapLibraryModel) SaveMapLibraryWithTransaction(ctx context.Context, createList []FsMapLibrary, updateList []FsMapLibrary) error {
|
|
||||||
return ml.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
|
||||||
//创建
|
|
||||||
for _, v := range createList {
|
|
||||||
if err := tx.Model(&FsMapLibrary{}).Create(&v).Error; err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(updateList) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
//更新
|
|
||||||
notInIds := make([]int64, 0, len(updateList))
|
|
||||||
for _, v := range updateList {
|
|
||||||
notInIds = append(notInIds, v.Id)
|
|
||||||
if err := tx.Model(&FsMapLibrary{}).Where("`id` = ?", v.Id).Updates(&v).Error; err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//删除
|
|
||||||
return tx.Model(&FsMapLibrary{}).Where("`id` not in (?) ", notInIds).Update("status", 0).Error
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
import (
|
import "context"
|
||||||
"context"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
||||||
|
|
||||||
@ -15,23 +12,3 @@ func (bm *FsProductTemplateBasemapModel) GetAllEnabledList(ctx context.Context,
|
|||||||
err = db.Find(&resp).Error
|
err = db.Find(&resp).Error
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bm *FsProductTemplateBasemapModel) UpdateBaseMapWithTransaction(ctx context.Context, dataList []FsProductTemplateBasemap) error {
|
|
||||||
return bm.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
|
||||||
notInIds := make([]int64, 0, len(dataList))
|
|
||||||
//更新
|
|
||||||
for _, v := range dataList {
|
|
||||||
notInIds = append(notInIds, v.Id)
|
|
||||||
err := tx.Where("`id` = ? ", v.Id).Updates(&v).Error
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(notInIds) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
//删除不在ids里面的
|
|
||||||
return tx.Model(&FsProductTemplateBasemap{}).
|
|
||||||
Where("`status` = ? and `id` not in (?)", 1, notInIds).Update("status", 0).Error
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
Name: faq
|
|
||||||
Host: 0.0.0.0
|
|
||||||
Port: 8888
|
|
||||||
SourceMysql: ""
|
|
||||||
Auth:
|
|
||||||
AccessSecret: fusen2023
|
|
||||||
AccessExpire: 604800
|
|
||||||
RefreshAfter: 345600
|
|
@ -1,49 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"fusenapi/server/faq/internal/config"
|
|
||||||
"fusenapi/server/faq/internal/handler"
|
|
||||||
"fusenapi/server/faq/internal/svc"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/conf"
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
|
||||||
)
|
|
||||||
|
|
||||||
var configFile = flag.String("f", "etc/faq.yaml", "the config file")
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
var c config.Config
|
|
||||||
conf.MustLoad(*configFile, &c)
|
|
||||||
|
|
||||||
server := rest.MustNewServer(c.RestConf)
|
|
||||||
defer server.Stop()
|
|
||||||
|
|
||||||
ctx := svc.NewServiceContext(c)
|
|
||||||
handler.RegisterHandlers(server, ctx)
|
|
||||||
|
|
||||||
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
|
||||||
server.Start()
|
|
||||||
}
|
|
||||||
|
|
||||||
// var testConfigFile = flag.String("f", "../etc/faq.yaml", "the config file")
|
|
||||||
// var cnf config.Config
|
|
||||||
|
|
||||||
// func GetTestServer() *rest.Server {
|
|
||||||
// flag.Parse()
|
|
||||||
|
|
||||||
// conf.MustLoad(*testConfigFile, &cnf)
|
|
||||||
|
|
||||||
// server := rest.MustNewServer(cnf.RestConf)
|
|
||||||
// defer server.Stop()
|
|
||||||
|
|
||||||
// ctx := svc.NewServiceContext(cnf)
|
|
||||||
// handler.RegisterHandlers(server, ctx)
|
|
||||||
|
|
||||||
// fmt.Printf("Starting server at %s:%d...\n", cnf.Host, cnf.Port)
|
|
||||||
// return server
|
|
||||||
// }
|
|
@ -1,13 +0,0 @@
|
|||||||
package config
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fusenapi/server/faq/internal/types"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Config struct {
|
|
||||||
rest.RestConf
|
|
||||||
SourceMysql string
|
|
||||||
Auth types.Auth
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
// Code generated by goctl. DO NOT EDIT.
|
|
||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"fusenapi/server/faq/internal/svc"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
|
||||||
)
|
|
||||||
|
|
||||||
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|
||||||
server.AddRoutes(
|
|
||||||
[]rest.Route{
|
|
||||||
{
|
|
||||||
Method: http.MethodGet,
|
|
||||||
Path: "/web-set/setting",
|
|
||||||
Handler: WetSetSettingHandler(serverCtx),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
@ -1,78 +0,0 @@
|
|||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
|
||||||
|
|
||||||
"fusenapi/utils/auth"
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
|
|
||||||
"fusenapi/server/faq/internal/logic"
|
|
||||||
"fusenapi/server/faq/internal/svc"
|
|
||||||
"fusenapi/server/faq/internal/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
func WetSetSettingHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
|
|
||||||
var (
|
|
||||||
// 定义错误变量
|
|
||||||
err error
|
|
||||||
// 定义用户信息变量
|
|
||||||
userinfo *auth.UserInfo
|
|
||||||
)
|
|
||||||
// 解析JWT token,并对空用户进行判断
|
|
||||||
claims, err := svcCtx.ParseJwtToken(r)
|
|
||||||
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
|
||||||
if err != nil {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
|
||||||
Code: 401, // 返回401状态码,表示未授权
|
|
||||||
Message: "unauthorized", // 返回未授权信息
|
|
||||||
})
|
|
||||||
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if claims != nil {
|
|
||||||
// 从token中获取对应的用户信息
|
|
||||||
userinfo, err = auth.GetUserInfoFormMapClaims(claims)
|
|
||||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
|
||||||
if err != nil {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
|
||||||
Code: 401,
|
|
||||||
Message: "unauthorized",
|
|
||||||
})
|
|
||||||
logx.Info("unauthorized:", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 如果claims为nil,则认为用户身份为白板用户
|
|
||||||
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
|
||||||
}
|
|
||||||
|
|
||||||
var req types.Request
|
|
||||||
// 如果端点有请求结构体,则使用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.NewWetSetSettingLogic(r.Context(), svcCtx)
|
|
||||||
resp := l.WetSetSetting(&req, userinfo)
|
|
||||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
|
||||||
if resp != nil {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
} else {
|
|
||||||
err := errors.New("server logic is error, resp must not be nil")
|
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
logx.Error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
package logic
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fusenapi/utils/auth"
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"fusenapi/server/faq/internal/svc"
|
|
||||||
"fusenapi/server/faq/internal/types"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
)
|
|
||||||
|
|
||||||
type WetSetSettingLogic struct {
|
|
||||||
logx.Logger
|
|
||||||
ctx context.Context
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewWetSetSettingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WetSetSettingLogic {
|
|
||||||
return &WetSetSettingLogic{
|
|
||||||
Logger: logx.WithContext(ctx),
|
|
||||||
ctx: ctx,
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *WetSetSettingLogic) WetSetSetting(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
|
||||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
|
||||||
// userinfo 传入值时, 一定不为null
|
|
||||||
|
|
||||||
return resp.SetStatus(basic.CodeOK)
|
|
||||||
}
|
|
@ -1,56 +0,0 @@
|
|||||||
package svc
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"fusenapi/server/faq/internal/config"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"fusenapi/initalize"
|
|
||||||
"fusenapi/model/gmodel"
|
|
||||||
|
|
||||||
"github.com/golang-jwt/jwt"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ServiceContext struct {
|
|
||||||
Config config.Config
|
|
||||||
|
|
||||||
MysqlConn *gorm.DB
|
|
||||||
AllModels *gmodel.AllModelsGen
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewServiceContext(c config.Config) *ServiceContext {
|
|
||||||
|
|
||||||
return &ServiceContext{
|
|
||||||
Config: c,
|
|
||||||
MysqlConn: initalize.InitMysql(c.SourceMysql),
|
|
||||||
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
|
||||||
AuthKey := r.Header.Get("Authorization")
|
|
||||||
if len(AuthKey) <= 50 {
|
|
||||||
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
|
|
||||||
}
|
|
||||||
|
|
||||||
token, err := jwt.Parse(AuthKey, func(token *jwt.Token) (interface{}, error) {
|
|
||||||
// 检查签名方法是否为 HS256
|
|
||||||
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
|
|
||||||
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
|
|
||||||
}
|
|
||||||
// 返回用于验证签名的密钥
|
|
||||||
return []byte(svcCtx.Config.Auth.AccessSecret), nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.New(fmt.Sprint("Error parsing token:", err))
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证成功返回
|
|
||||||
if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid {
|
|
||||||
return claims, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, errors.New(fmt.Sprint("Invalid token", err))
|
|
||||||
}
|
|
@ -1,61 +0,0 @@
|
|||||||
// Code generated by goctl. DO NOT EDIT.
|
|
||||||
package types
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Request struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
type Response struct {
|
|
||||||
Code int `json:"code"`
|
|
||||||
Message string `json:"msg"`
|
|
||||||
Data interface{} `json:"data"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Auth struct {
|
|
||||||
AccessSecret string `json:"accessSecret"`
|
|
||||||
AccessExpire int64 `json:"accessExpire"`
|
|
||||||
RefreshAfter int64 `json:"refreshAfter"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set 设置Response的Code和Message值
|
|
||||||
func (resp *Response) Set(Code int, Message string) *Response {
|
|
||||||
return &Response{
|
|
||||||
Code: Code,
|
|
||||||
Message: Message,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set 设置整个Response
|
|
||||||
func (resp *Response) SetWithData(Code int, Message string, Data interface{}) *Response {
|
|
||||||
return &Response{
|
|
||||||
Code: Code,
|
|
||||||
Message: Message,
|
|
||||||
Data: Data,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetStatus 设置默认StatusResponse(内部自定义) 默认msg, 可以带data, data只使用一个参数
|
|
||||||
func (resp *Response) SetStatus(sr *basic.StatusResponse, data ...interface{}) *Response {
|
|
||||||
newResp := &Response{
|
|
||||||
Code: sr.Code,
|
|
||||||
}
|
|
||||||
if len(data) == 1 {
|
|
||||||
newResp.Data = data[0]
|
|
||||||
}
|
|
||||||
return newResp
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetStatusWithMessage 设置默认StatusResponse(内部自定义) 非默认msg, 可以带data, data只使用一个参数
|
|
||||||
func (resp *Response) SetStatusWithMessage(sr *basic.StatusResponse, msg string, data ...interface{}) *Response {
|
|
||||||
newResp := &Response{
|
|
||||||
Code: sr.Code,
|
|
||||||
Message: msg,
|
|
||||||
}
|
|
||||||
if len(data) == 1 {
|
|
||||||
newResp.Data = data[0]
|
|
||||||
}
|
|
||||||
return newResp
|
|
||||||
}
|
|
@ -125,10 +125,10 @@ func (l *UserOderDeleteLogic) UserOderDelete(req *types.RequestOrderId, userinfo
|
|||||||
Uploads: stripe.GetBackendWithConfig(stripe.UploadsBackend, config),
|
Uploads: stripe.GetBackendWithConfig(stripe.UploadsBackend, config),
|
||||||
})
|
})
|
||||||
// ['order_number' => $order->sn, 'is_refund' => 0, 'pay_status' => 1]
|
// ['order_number' => $order->sn, 'is_refund' => 0, 'pay_status' => 1]
|
||||||
payM := l.svcCtx.AllModels.FsPay
|
pay := l.svcCtx.AllModels.FsPay
|
||||||
|
|
||||||
// 查询支付信息
|
// 查询支付信息
|
||||||
pays, err := payM.GetOrderPayList(l.ctx, *order.Sn, 1, 0)
|
pays, err := pay.GetOrderPayList(l.ctx, *order.Sn, 1, 0)
|
||||||
for _, pay := range pays {
|
for _, pay := range pays {
|
||||||
sc.Refunds.New(&stripe.RefundParams{
|
sc.Refunds.New(&stripe.RefundParams{
|
||||||
PaymentIntent: pay.TradeNo,
|
PaymentIntent: pay.TradeNo,
|
||||||
@ -140,11 +140,12 @@ func (l *UserOderDeleteLogic) UserOderDelete(req *types.RequestOrderId, userinfo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return resp.SetStatus(basic.CodePayCancelOk, uOrder)
|
// if err == nil && err == nil {
|
||||||
|
// return ResponseSuccess(200, "Cancel successfully", order)
|
||||||
|
// }
|
||||||
// return ResponseError(500, "Cancellation failure")
|
// return ResponseError(500, "Cancellation failure")
|
||||||
|
|
||||||
// return resp.SetStatus(basic.CodePayCancelNotOk)
|
return resp.SetStatus(basic.CodePayCancelNotOk)
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (l *OrderLogic) CancelOrder(req *types.RequestCancelOrder, userinfo *auth.UserInfo) (resp *basic.Response) {
|
// func (l *OrderLogic) CancelOrder(req *types.RequestCancelOrder, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"fusenapi/model/gmodel"
|
"fusenapi/model/gmodel"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
|
"gorm.io/gorm"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -42,44 +43,66 @@ func (l *SaveMapLibraryLogic) SaveMapLibrary(userinfo *auth.UserInfo, req *http.
|
|||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeSaveErr, "param err")
|
return resp.SetStatusWithMessage(basic.CodeSaveErr, "param err")
|
||||||
}
|
}
|
||||||
|
//获取所有贴图数据[获取id]
|
||||||
|
mapLibraryModel := gmodel.NewFsMapLibraryModel(l.svcCtx.MysqlConn)
|
||||||
|
maplibraryList, err := mapLibraryModel.GetAllEnabledList(l.ctx, "id")
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get map library list")
|
||||||
|
}
|
||||||
|
|
||||||
sort := int64(0)
|
sort := int64(0)
|
||||||
status := int64(1)
|
status := int64(1)
|
||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
createList := make([]gmodel.FsMapLibrary, 0, len(postData))
|
needDeleteMid := make([]int64, 0, len(postData))
|
||||||
updateList := make([]gmodel.FsMapLibrary, 0, len(postData))
|
mapPostMid := make(map[int64]struct{})
|
||||||
//开启事务
|
//开启事务
|
||||||
for _, v := range postData {
|
err = l.svcCtx.MysqlConn.Transaction(func(tx *gorm.DB) error {
|
||||||
postDataVal := v
|
for _, v := range postData {
|
||||||
infoByte, _ := json.Marshal(postDataVal.Info)
|
infoByte, _ := json.Marshal(v.Info)
|
||||||
infoJsonStr := string(infoByte)
|
infoJsonStr := string(infoByte)
|
||||||
switch postDataVal.Mid {
|
switch v.Mid {
|
||||||
case "": //新增
|
case "": //新增
|
||||||
createList = append(createList, gmodel.FsMapLibrary{
|
err = mapLibraryModel.Create(l.ctx, &gmodel.FsMapLibrary{
|
||||||
Title: &postDataVal.Info.Title,
|
Title: &v.Info.Title,
|
||||||
Info: &infoJsonStr,
|
Info: &infoJsonStr,
|
||||||
Sort: &sort,
|
Sort: &sort,
|
||||||
Status: &status,
|
Status: &status,
|
||||||
Ctime: &now,
|
Ctime: &now,
|
||||||
TagId: &postDataVal.Tag.Id,
|
TagId: &v.Tag.Id,
|
||||||
})
|
})
|
||||||
default: //修改
|
if err != nil {
|
||||||
midInt, err := strconv.ParseInt(postDataVal.Mid, 10, 64)
|
return err
|
||||||
if err != nil {
|
}
|
||||||
logx.Error(err)
|
default: //修改
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "mid is not a number")
|
midInt, err := strconv.ParseInt(v.Mid, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
mapPostMid[midInt] = struct{}{}
|
||||||
|
err = mapLibraryModel.Update(l.ctx, midInt, &gmodel.FsMapLibrary{
|
||||||
|
Title: &v.Info.Title,
|
||||||
|
Info: &infoJsonStr,
|
||||||
|
TagId: &v.Tag.Id,
|
||||||
|
Status: &status,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
updateList = append(updateList, gmodel.FsMapLibrary{
|
|
||||||
Id: midInt,
|
|
||||||
Title: &postDataVal.Info.Title,
|
|
||||||
Info: &infoJsonStr,
|
|
||||||
TagId: &postDataVal.Tag.Id,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
//删除需要删除的
|
||||||
err = l.svcCtx.AllModels.FsMapLibrary.SaveMapLibraryWithTransaction(l.ctx, createList, updateList)
|
for _, v := range maplibraryList {
|
||||||
|
//旧的不在新的里面则删除
|
||||||
|
if _, ok := mapPostMid[v.Id]; !ok {
|
||||||
|
needDeleteMid = append(needDeleteMid, v.Id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mapLibraryModel.ChangeStatusByIds(l.ctx, needDeleteMid, 0)
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to save map library")
|
return resp.SetStatusWithMessage(basic.CodeSaveErr, "failed to save map library info")
|
||||||
}
|
}
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success")
|
return resp.SetStatusWithMessage(basic.CodeOK, "success")
|
||||||
}
|
}
|
||||||
|
@ -22,11 +22,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
Path: "/product-template/base-map-list",
|
Path: "/product-template/base-map-list",
|
||||||
Handler: GetBaseMapListHandler(serverCtx),
|
Handler: GetBaseMapListHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Method: http.MethodPost,
|
|
||||||
Path: "/product-template/base-map-update",
|
|
||||||
Handler: SaveBaseMapHandler(serverCtx),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
|
||||||
|
|
||||||
"fusenapi/server/product-templatev2/internal/logic"
|
|
||||||
"fusenapi/server/product-templatev2/internal/svc"
|
|
||||||
)
|
|
||||||
|
|
||||||
func SaveBaseMapHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
// 创建一个业务逻辑层实例
|
|
||||||
l := logic.NewSaveBaseMapLogic(r.Context(), svcCtx)
|
|
||||||
resp := l.SaveBaseMap(r)
|
|
||||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
|
||||||
if resp != nil {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
|
||||||
} else {
|
|
||||||
err := errors.New("server logic is error, resp must not be nil")
|
|
||||||
httpx.ErrorCtx(r.Context(), w, err)
|
|
||||||
logx.Error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,79 +0,0 @@
|
|||||||
package logic
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"fusenapi/model/gmodel"
|
|
||||||
"fusenapi/server/product-templatev2/internal/types"
|
|
||||||
"fusenapi/utils/basic"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"fusenapi/server/product-templatev2/internal/svc"
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
)
|
|
||||||
|
|
||||||
type SaveBaseMapLogic struct {
|
|
||||||
logx.Logger
|
|
||||||
ctx context.Context
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewSaveBaseMapLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveBaseMapLogic {
|
|
||||||
return &SaveBaseMapLogic{
|
|
||||||
Logger: logx.WithContext(ctx),
|
|
||||||
ctx: ctx,
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *SaveBaseMapLogic) SaveBaseMap(r *http.Request) (resp *basic.Response) {
|
|
||||||
authKey := r.Header.Get("Auth-Key")
|
|
||||||
genentModel := gmodel.NewFsGerentModel(l.svcCtx.MysqlConn)
|
|
||||||
_, err := genentModel.Find(l.ctx, authKey)
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first..")
|
|
||||||
}
|
|
||||||
logx.Error(err)
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "failed to get user info")
|
|
||||||
}
|
|
||||||
bodyBytes, err := ioutil.ReadAll(r.Body)
|
|
||||||
defer r.Body.Close()
|
|
||||||
var postData []types.SaveBaseMapReq
|
|
||||||
if err = json.Unmarshal(bodyBytes, &postData); err != nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid request param")
|
|
||||||
}
|
|
||||||
//空数组
|
|
||||||
if len(postData) == 0 {
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "param can`t be empty array")
|
|
||||||
}
|
|
||||||
updDataArr := make([]gmodel.FsProductTemplateBasemap, 0, len(postData))
|
|
||||||
for _, v := range postData {
|
|
||||||
val := v
|
|
||||||
ctimeT, err := time.ParseInLocation("2006-01-02 15:04:05", v.Ctime, time.Local)
|
|
||||||
if err != nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err create time format")
|
|
||||||
}
|
|
||||||
ctime := ctimeT.Unix()
|
|
||||||
updDataArr = append(updDataArr, gmodel.FsProductTemplateBasemap{
|
|
||||||
Id: val.Id,
|
|
||||||
Name: &val.Name,
|
|
||||||
Url: &val.Url,
|
|
||||||
Ctime: &ctime,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
//更新
|
|
||||||
err = l.svcCtx.AllModels.FsProductTemplateBasemap.UpdateBaseMapWithTransaction(l.ctx, updDataArr)
|
|
||||||
if err != nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to update base map")
|
|
||||||
}
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success")
|
|
||||||
}
|
|
@ -35,13 +35,6 @@ type GetBaseMapListRsp struct {
|
|||||||
Ctime string `json:"ctime"`
|
Ctime string `json:"ctime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SaveBaseMapReq struct {
|
|
||||||
Id int64 `json:"id"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
Url string `json:"url"`
|
|
||||||
Ctime string `json:"ctime"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
Code int `json:"code"`
|
Code int `json:"code"`
|
||||||
Message string `json:"msg"`
|
Message string `json:"msg"`
|
||||||
|
@ -7,7 +7,15 @@ info (
|
|||||||
email: ""
|
email: ""
|
||||||
)
|
)
|
||||||
|
|
||||||
import "basic.api"
|
type request {
|
||||||
|
// TODO: add members here and delete this comment
|
||||||
|
Name string `path:"name,options=you|me"` // parameters are auto validated
|
||||||
|
}
|
||||||
|
|
||||||
|
type response {
|
||||||
|
// TODO: add members here and delete this comment
|
||||||
|
Message string `json:"message"`
|
||||||
|
}
|
||||||
|
|
||||||
service user-auth {
|
service user-auth {
|
||||||
@handler GreetHandler
|
@handler GreetHandler
|
||||||
|
@ -7,9 +7,6 @@ info (
|
|||||||
email: ""
|
email: ""
|
||||||
)
|
)
|
||||||
|
|
||||||
type request {}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// response 统一返回码
|
// response 统一返回码
|
||||||
type response {
|
type response {
|
||||||
@ -18,6 +15,17 @@ type response {
|
|||||||
Data interface{} `json:"data"`
|
Data interface{} `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// responseJwt 统一返回码
|
||||||
|
type responseJwt {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Message string `json:"msg"`
|
||||||
|
Data interface{} `json:"data"`
|
||||||
|
AccessSecret string `json:"accessSecret"`
|
||||||
|
AccessExpire int64 `json:"accessExpire"`
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Auth 认证结构
|
// Auth 认证结构
|
||||||
type Auth {
|
type Auth {
|
||||||
AccessSecret string `json:"accessSecret"`
|
AccessSecret string `json:"accessSecret"`
|
||||||
|
@ -7,7 +7,6 @@ info (
|
|||||||
email: ""
|
email: ""
|
||||||
)
|
)
|
||||||
import "basic.api"
|
import "basic.api"
|
||||||
|
|
||||||
service canteen {
|
service canteen {
|
||||||
//获取餐厅详情
|
//获取餐厅详情
|
||||||
@handler GetCanteenDetailHandler
|
@handler GetCanteenDetailHandler
|
||||||
|
@ -7,7 +7,15 @@ info (
|
|||||||
email: ""
|
email: ""
|
||||||
)
|
)
|
||||||
|
|
||||||
import "basic.api"
|
type request {
|
||||||
|
// TODO: add members here and delete this comment
|
||||||
|
Name string `path:"name,options=you|me"` // parameters are auto validated
|
||||||
|
}
|
||||||
|
|
||||||
|
type response {
|
||||||
|
// TODO: add members here and delete this comment
|
||||||
|
Message string `json:"message"`
|
||||||
|
}
|
||||||
|
|
||||||
service user-auth {
|
service user-auth {
|
||||||
@handler GreetHandler
|
@handler GreetHandler
|
||||||
|
@ -7,7 +7,15 @@ info (
|
|||||||
email: ""
|
email: ""
|
||||||
)
|
)
|
||||||
|
|
||||||
import "basic.api"
|
type request {
|
||||||
|
// TODO: add members here and delete this comment
|
||||||
|
Name string `path:"name,options=you|me"` // parameters are auto validated
|
||||||
|
}
|
||||||
|
|
||||||
|
type response {
|
||||||
|
// TODO: add members here and delete this comment
|
||||||
|
Message string `json:"message"`
|
||||||
|
}
|
||||||
|
|
||||||
service user-auth {
|
service user-auth {
|
||||||
@handler GreetHandler
|
@handler GreetHandler
|
||||||
|
@ -7,7 +7,15 @@ info (
|
|||||||
email: ""
|
email: ""
|
||||||
)
|
)
|
||||||
|
|
||||||
import "basic.api"
|
type request {
|
||||||
|
// TODO: add members here and delete this comment
|
||||||
|
Name string `path:"name,options=you|me"` // parameters are auto validated
|
||||||
|
}
|
||||||
|
|
||||||
|
type response {
|
||||||
|
// TODO: add members here and delete this comment
|
||||||
|
Message string `json:"message"`
|
||||||
|
}
|
||||||
|
|
||||||
service user-auth {
|
service user-auth {
|
||||||
@handler GreetHandler
|
@handler GreetHandler
|
||||||
|
@ -7,9 +7,17 @@ info (
|
|||||||
email: ""
|
email: ""
|
||||||
)
|
)
|
||||||
|
|
||||||
import "basic.api"
|
type request {
|
||||||
|
// TODO: add members here and delete this comment
|
||||||
|
Name string `path:"name,options=you|me"` // parameters are auto validated
|
||||||
|
}
|
||||||
|
|
||||||
service faq {
|
type response {
|
||||||
@handler WetSetSettingHandler
|
// TODO: add members here and delete this comment
|
||||||
get /web-set/setting(request) returns (response);
|
Message string `json:"message"`
|
||||||
|
}
|
||||||
|
|
||||||
|
service user-auth {
|
||||||
|
@handler GreetHandler
|
||||||
|
get /greet/from/:name(request) returns (response);
|
||||||
}
|
}
|
@ -42,9 +42,6 @@ service home-user-auth {
|
|||||||
@handler UserAddAddressHandler
|
@handler UserAddAddressHandler
|
||||||
post /user/add-address(RequestAddAddress) returns (response);
|
post /user/add-address(RequestAddAddress) returns (response);
|
||||||
|
|
||||||
// @handler UserOderListHandler
|
|
||||||
// get /user/order-list(RequestOrderId) returns (response);
|
|
||||||
|
|
||||||
@handler UserOderDeleteHandler
|
@handler UserOderDeleteHandler
|
||||||
post /user/order-delete(RequestOrderId) returns (response);
|
post /user/order-delete(RequestOrderId) returns (response);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ info (
|
|||||||
author: ""
|
author: ""
|
||||||
email: ""
|
email: ""
|
||||||
)
|
)
|
||||||
|
|
||||||
import "basic.api"
|
import "basic.api"
|
||||||
|
|
||||||
service map-library {
|
service map-library {
|
||||||
|
@ -6,9 +6,7 @@ info (
|
|||||||
author: ""
|
author: ""
|
||||||
email: ""
|
email: ""
|
||||||
)
|
)
|
||||||
|
|
||||||
import "basic.api"
|
import "basic.api"
|
||||||
|
|
||||||
service orders {
|
service orders {
|
||||||
//获取订单发票
|
//获取订单发票
|
||||||
@handler GetOrderInvoiceHandler
|
@handler GetOrderInvoiceHandler
|
||||||
|
@ -6,9 +6,7 @@ info (
|
|||||||
author: ""
|
author: ""
|
||||||
email: ""
|
email: ""
|
||||||
)
|
)
|
||||||
|
|
||||||
import "basic.api"
|
import "basic.api"
|
||||||
|
|
||||||
service product-templatev2 {
|
service product-templatev2 {
|
||||||
//获取产品模板详情
|
//获取产品模板详情
|
||||||
@handler GetTemplatevDetailHandler
|
@handler GetTemplatevDetailHandler
|
||||||
@ -16,10 +14,6 @@ service product-templatev2 {
|
|||||||
//获取底图列表
|
//获取底图列表
|
||||||
@handler GetBaseMapListHandler
|
@handler GetBaseMapListHandler
|
||||||
get /product-template/base-map-list( ) returns (response);
|
get /product-template/base-map-list( ) returns (response);
|
||||||
//保存底图信息
|
|
||||||
@handler SaveBaseMapHandler
|
|
||||||
post /product-template/base-map-update ( ) returns (response);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取产品模板详情
|
//获取产品模板详情
|
||||||
@ -50,11 +44,4 @@ type GetBaseMapListRsp {
|
|||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Url string `json:"url"`
|
Url string `json:"url"`
|
||||||
Ctime string `json:"ctime"`
|
Ctime string `json:"ctime"`
|
||||||
}
|
|
||||||
//保存底图信息
|
|
||||||
type SaveBaseMapReq {
|
|
||||||
Id int64 `json:"id"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
Url string `json:"url"`
|
|
||||||
Ctime string `json:"ctime"`
|
|
||||||
}
|
}
|
@ -6,9 +6,7 @@ info (
|
|||||||
author: ""
|
author: ""
|
||||||
email: ""
|
email: ""
|
||||||
)
|
)
|
||||||
|
|
||||||
import "basic.api"
|
import "basic.api"
|
||||||
|
|
||||||
service product {
|
service product {
|
||||||
//获取产品列表
|
//获取产品列表
|
||||||
@handler GetProductListHandler
|
@handler GetProductListHandler
|
||||||
|
@ -7,7 +7,15 @@ info (
|
|||||||
email: ""
|
email: ""
|
||||||
)
|
)
|
||||||
|
|
||||||
import "basic.api"
|
type request {
|
||||||
|
// TODO: add members here and delete this comment
|
||||||
|
Name string `path:"name,options=you|me"` // parameters are auto validated
|
||||||
|
}
|
||||||
|
|
||||||
|
type response {
|
||||||
|
// TODO: add members here and delete this comment
|
||||||
|
Message string `json:"message"`
|
||||||
|
}
|
||||||
|
|
||||||
service user-auth {
|
service user-auth {
|
||||||
@handler GreetHandler
|
@handler GreetHandler
|
||||||
|
@ -6,9 +6,7 @@ info (
|
|||||||
author: "ldm"
|
author: "ldm"
|
||||||
email: ""
|
email: ""
|
||||||
)
|
)
|
||||||
|
|
||||||
import "basic.api"
|
import "basic.api"
|
||||||
|
|
||||||
service shopping-cart-confirmation {
|
service shopping-cart-confirmation {
|
||||||
//添加入购物车
|
//添加入购物车
|
||||||
@handler CartAddHandler
|
@handler CartAddHandler
|
||||||
|
@ -116,7 +116,6 @@ func (resp *Response) SetStatusAddMessage(sr *StatusResponse, msg string, data .
|
|||||||
Code: sr.Code,
|
Code: sr.Code,
|
||||||
Message: sr.Message + ":" + msg,
|
Message: sr.Message + ":" + msg,
|
||||||
}
|
}
|
||||||
|
|
||||||
switch len(data) {
|
switch len(data) {
|
||||||
case 0:
|
case 0:
|
||||||
// 0 直接返回
|
// 0 直接返回
|
||||||
|
Loading…
x
Reference in New Issue
Block a user