删除产品服务无用的接口

This commit is contained in:
laodaming 2023-10-30 16:54:09 +08:00
parent 55f1be350b
commit 6adbfef8e8
13 changed files with 0 additions and 673 deletions

View File

@ -1,2 +0,0 @@
map-library
main

View File

@ -1,8 +0,0 @@
FROM alpine
WORKDIR /www/fusenapi/
COPY ./bin/api-map-library-srv /www/fusenapi/
COPY ./env.yaml /opt/
COPY ./server.fusen.3718.cn.pem /opt/
COPY ./server.fusen.3718.cn.key /opt/
CMD ["/www/fusenapi/api-map-library-srv"]

View File

@ -1,12 +0,0 @@
Name: map-library
Host: localhost
Port: 9906
ReplicaId: 40
Timeout: 15000 #服务超时时间
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
Log:
Stat: false
Auth:
AccessSecret: fusen2023
AccessExpire: 2592000
RefreshAfter: 1592000

View File

@ -1,14 +0,0 @@
package config
import (
"fusenapi/server/map-library/internal/types"
"github.com/zeromicro/go-zero/rest"
)
type Config struct {
rest.RestConf
SourceMysql string
Auth types.Auth
ReplicaId uint64
}

View File

@ -1,35 +0,0 @@
package handler
import (
"net/http"
"reflect"
"fusenapi/utils/basic"
"fusenapi/server/map-library/internal/logic"
"fusenapi/server/map-library/internal/svc"
"fusenapi/server/map-library/internal/types"
)
func GetMapLibraryListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.Request
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
// 创建一个业务逻辑层实例
l := logic.NewGetMapLibraryListLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.GetMapLibraryList(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)
}
}
}

View File

@ -1,27 +0,0 @@
// Code generated by goctl. DO NOT EDIT.
package handler
import (
"net/http"
"fusenapi/server/map-library/internal/svc"
"github.com/zeromicro/go-zero/rest"
)
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodGet,
Path: "/api/map-library/list",
Handler: GetMapLibraryListHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/api/map-library/save",
Handler: SaveMapLibraryHandler(serverCtx),
},
},
)
}

View File

@ -1,35 +0,0 @@
package handler
import (
"net/http"
"reflect"
"fusenapi/utils/basic"
"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 {
return func(w http.ResponseWriter, r *http.Request) {
var req types.Request
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
// 创建一个业务逻辑层实例
l := logic.NewSaveMapLibraryLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.SaveMapLibrary(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)
}
}
}

View File

@ -1,82 +0,0 @@
package logic
import (
"encoding/json"
"fusenapi/model/gmodel"
"fusenapi/server/map-library/internal/svc"
"fusenapi/server/map-library/internal/types"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"time"
"context"
"github.com/zeromicro/go-zero/core/logx"
)
type GetMapLibraryListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetMapLibraryListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMapLibraryListLogic {
return &GetMapLibraryListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetMapLibraryListLogic) GetMapLibraryList(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
if userinfo.GetIdType() != auth.IDTYPE_User {
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please sign in first")
}
mapLibraryModel := gmodel.NewFsMapLibraryModel(l.svcCtx.MysqlConn)
mapLibraryList, err := mapLibraryModel.GetAllEnabledList(l.ctx)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get map library list")
}
if len(mapLibraryList) == 0 {
return resp.SetStatus(basic.CodeOK)
}
productTemplateTagIds := make([]int64, 0, len(mapLibraryList))
for _, v := range mapLibraryList {
productTemplateTagIds = append(productTemplateTagIds, *v.TagId)
}
//获取标签列表
productTemplateTagsModel := gmodel.NewFsProductTemplateTagsModel(l.svcCtx.MysqlConn)
templateTagList, err := productTemplateTagsModel.GetListByIds(l.ctx, productTemplateTagIds)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product template tags")
}
mapTag := make(map[int64]int)
for k, v := range templateTagList {
mapTag[v.Id] = k
}
list := make([]types.GetMapLibraryListRsp, 0, len(mapLibraryList))
for _, v := range mapLibraryList {
data := types.GetMapLibraryListRsp{
Mid: v.Id,
Ctime: time.Unix(*v.Ctime, 0).Format("2006-01-02 15:04:05"),
}
//tag拼装
if tagIndex, ok := mapTag[*v.TagId]; ok {
data.Tag = &types.MapLibraryListTag{
Id: templateTagList[tagIndex].Id,
Title: *templateTagList[tagIndex].TemplateTag,
}
}
//解析info
var info interface{}
if err = json.Unmarshal([]byte(*v.Info), &info); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "json parse info err")
}
data.Info = info
list = append(list, data)
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", list)
}

View File

@ -1,103 +0,0 @@
package logic
import (
"context"
"encoding/json"
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"io/ioutil"
"net/http"
"strconv"
"time"
"fusenapi/server/map-library/internal/svc"
"fusenapi/server/map-library/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SaveMapLibraryLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
bodyData []byte
}
func NewSaveMapLibraryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveMapLibraryLogic {
return &SaveMapLibraryLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
func (l *SaveMapLibraryLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
bodyData, err := ioutil.ReadAll(r.Body)
defer r.Body.Close()
if err != nil {
logx.Error(err)
return
}
l.bodyData = bodyData
}
func (l *SaveMapLibraryLogic) SaveMapLibrary(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
if userinfo.GetIdType() != auth.IDTYPE_User {
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please sign in first")
}
if len(l.bodyData) == 0 {
return resp.SetStatus(basic.CodeApiErr, http.ErrBodyReadAfterClose.Error())
}
var err error
var postData []types.SaveMapLibraryData
if err = json.Unmarshal(l.bodyData, &postData); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeSaveErr, "param err")
}
sort := int64(0)
status := int64(1)
now := time.Now().UTC().Unix()
createList := make([]gmodel.FsMapLibrary, 0, len(postData))
updateList := make([]gmodel.FsMapLibrary, 0, len(postData))
//开启事务
for _, v := range postData {
postDataVal := v
infoByte, _ := json.Marshal(postDataVal.Info)
infoJsonStr := string(infoByte)
switch postDataVal.Mid {
case "": //新增
createList = append(createList, gmodel.FsMapLibrary{
Title: &postDataVal.Info.Title,
Info: &infoJsonStr,
Sort: &sort,
Status: &status,
Ctime: &now,
TagId: &postDataVal.Tag.Id,
})
default: //修改
midInt, err := strconv.ParseInt(postDataVal.Mid, 10, 64)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "mid is not a number")
}
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)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to save map library")
}
return resp.SetStatusWithMessage(basic.CodeOK, "success")
}

View File

@ -1,66 +0,0 @@
package svc
import (
"errors"
"fmt"
"fusenapi/server/map-library/internal/config"
"fusenapi/shared"
"net/http"
"fusenapi/initalize"
"fusenapi/model/gmodel"
"github.com/golang-jwt/jwt"
"gorm.io/gorm"
)
type ServiceContext struct {
Config config.Config
SharedState *shared.SharedState
MysqlConn *gorm.DB
AllModels *gmodel.AllModelsGen
}
func NewServiceContext(c config.Config) *ServiceContext {
conn := initalize.InitMysql(c.SourceMysql)
// StateServer := shared.StartNode(c.ReplicaId, autoconfig.AutoGetAllServerConfig(), conn)
return &ServiceContext{
Config: c,
MysqlConn: conn,
SharedState: nil,
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
}
}
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
AuthKey := r.Header.Get("Authorization")
if AuthKey == "" {
return nil, nil
}
AuthKey = AuthKey[7:]
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))
}

View File

@ -1,157 +0,0 @@
// Code generated by goctl. DO NOT EDIT.
package types
import (
"fusenapi/utils/basic"
)
type GetMapLibraryListRsp struct {
Mid int64 `json:"mid"`
Ctime string `json:"ctime"`
Tag *MapLibraryListTag `json:"tag"`
Info interface{} `json:"info"`
}
type MapLibraryListTag struct {
Id int64 `json:"id"`
Title string `json:"title"`
}
type SaveMapLibraryData struct {
Mid string `json:"mid"`
Tid string `json:"tid"`
Ctime string `json:"ctime"`
Tag Tag `json:"tag,optional"`
Info Info `json:"info,optional"`
}
type Tag struct {
Id int64 `json:"id,optional"`
Title string `json:"title,optional"`
}
type Info struct {
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,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,optional"`
Name string `json:"name,optional"`
Default bool `json:"default,optional"`
}
type Follow struct {
Fill string `json:"fill,optional"`
IfShow string `json:"ifShow,optional"`
Content string `json:"content,optional"`
}
type CameraStand struct {
X int64 `json:"x,optional"`
Y int64 `json:"y,optional"`
Z int64 `json:"z,optional"`
}
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"`
}
type File struct {
Filename string `fsfile:"filename"`
Header map[string][]string `fsfile:"header"`
Size int64 `fsfile:"size"`
Data []byte `fsfile:"data"`
}
type Meta struct {
TotalCount int64 `json:"totalCount"`
PageCount int64 `json:"pageCount"`
CurrentPage int `json:"currentPage"`
PerPage int `json:"perPage"`
}
// 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
}

View File

@ -1,35 +0,0 @@
package main
import (
"flag"
"fmt"
"net/http"
"fusenapi/server/map-library/internal/config"
"fusenapi/server/map-library/internal/handler"
"fusenapi/server/map-library/internal/svc"
"fusenapi/utils/auth"
"fusenapi/utils/fsconfig"
"github.com/zeromicro/go-zero/rest"
)
var configFile = flag.String("f", "etc/map-library.yaml", "the config file")
func main() {
flag.Parse()
var c config.Config
fsconfig.StartNacosConfig(*configFile, &c, nil)
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
}))
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()
}

View File

@ -1,97 +0,0 @@
syntax = "v1"
info (
title: "贴图库服务"// TODO: add title
desc: // TODO: add description
author: ""
email: ""
)
import "basic.api"
service map-library {
//获取贴图库列表
@handler GetMapLibraryListHandler
get /api/map-library/list (request) returns (response);
//保存贴图信息
@handler SaveMapLibraryHandler
post /api/map-library/save (request) returns (response);
}
//获取贴图库列表
type GetMapLibraryListRsp {
Mid int64 `json:"mid"`
Ctime string `json:"ctime"`
Tag *MapLibraryListTag `json:"tag"`
Info interface{} `json:"info"`
}
type MapLibraryListTag {
Id int64 `json:"id"`
Title string `json:"title"`
}
//保存贴图信息
type SaveMapLibraryData {
Mid string `json:"mid"`
Tid string `json:"tid"`
Ctime string `json:"ctime"`
Tag Tag `json:"tag,optional"`
Info Info `json:"info,optional"`
}
type Tag {
Id int64 `json:"id,optional"`
Title string `json:"title,optional"`
}
type Info {
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,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,optional"`
Name string `json:"name,optional"`
Default bool `json:"default,optional"`
}
type Follow {
Fill string `json:"fill,optional"`
IfShow string `json:"ifShow,optional"`
Content string `json:"content,optional"`
}
type CameraStand {
X int64 `json:"x,optional"`
Y int64 `json:"y,optional"`
Z int64 `json:"z,optional"`
}