Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop

This commit is contained in:
momo 2023-10-10 11:29:43 +08:00
commit 019a717706
58 changed files with 367 additions and 97 deletions

View File

@ -2,14 +2,22 @@
name=${1%%\\*}
#进入对应服务目录
cd server/$name
#把https加密密钥对复制进来
cp /opt/env.yaml ./
cp /opt/server.fusen.3718.cn.pem ./
cp /opt/server.fusen.3718.cn.key ./
#构建二进制文件
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o ./bin/api-$name-srv ./$name.go
#删除之前旧的镜像
docker rmi -f api-$name-srv:latest
docker rmi -f registry.cn-hangzhou.aliyuncs.com/fusen-test/fusen_docker_hub:latest
#打包docker镜像
docker build -t api-$name-srv:latest .
#删除临时复制进来的文件
rm ./env.yaml
rm ./server.fusen.3718.cn.pem
rm ./server.fusen.3718.cn.key
#打tag(测试环境正式把命名空间fusentest改成fusen)
docker tag api-$name-srv:latest registry.cn-hangzhou.aliyuncs.com/fusen-test/$name:latest
#推送到阿里云镜像库(测试环境正式把命名空间fusentest改成fusen)
docker push registry.cn-hangzhou.aliyuncs.com/fusen-test/$name:latest
#上传了的镜像
docker rmi -f api-$name-srv:latest
docker rmi -f registry.cn-hangzhou.aliyuncs.com/fusen-test/$name:latest

View File

@ -14,6 +14,7 @@ func (a *FsAddressModel) GetOne(ctx context.Context, addressId int64, userId int
}
func (a *FsAddressModel) GetUserAllAddress(ctx context.Context, userId int64) (resp []*FsAddressWithDefault, err error) {
resp = make([]*FsAddressWithDefault, 0)
var dbresp []*FsAddress
err = a.db.WithContext(ctx).Model(&FsAddress{}).Where("`user_id` = ? and `status` = 1", userId).Order("`ltime` DESC").Find(&dbresp).Error

View File

@ -91,23 +91,20 @@ func main() {
routes...))
}
Backends = append(Backends, NewBackend(mux,
fmt.Sprintf("http://%s:%d", "localhost", 9501),
"/api/v1/namespaces/kubernetes-dashboard"))
// 定义用于服务Vue dist文件夹的静态文件服务器
fs := http.FileServer(http.Dir(vueBuild))
indexHtmlPath := vueBuild + "/index.html"
mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/api/") {
r.ParseMultipartForm(100 << 20)
// if err != nil {
// logx.Error(err)
// }
// 对/api开头的请求进行反向代理
proxy := httputil.NewSingleHostReverseProxy(apiURL)
proxy.ServeHTTP(w, r)
return
} else {
// 根据请求路径判断是服务静态文件或者是返回index.html
idx := strings.Index(r.URL.Path[1:], "/")

View File

@ -48,7 +48,7 @@ run_server() {
# 循环检查screen进程是否存在
[ -f .gitignore ] || echo $server_name > .gitignore
[ -f .gitignore ] || (echo "$server_name" > .gitignore && echo "main" >> .gitignore)
# 使用 screen 运行 go run <server_name>.go
echo "Running $server_name"

View File

@ -1 +1,2 @@
auth
main

View File

@ -1,6 +1,8 @@
FROM alpine
WORKDIR /www/fusenapi/
COPY ./bin/api-assistant-srv /www/fusenapi/
COPY ./etc /www/fusenapi/etc
CMD ["/www/fusenapi/api-assistant-srv"]
COPY ./bin/api-auth-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-auth-srv"]

View File

@ -2,6 +2,7 @@ Name: auth
Host: localhost
Port: 9980
ReplicaId: 10
HomePage: "http://www.fusen.3718.cn"
MainAddress: "https://server.fusen.3718.cn:9900"
WebsocketAddr: "https://server.fusen.3718.cn:9914"
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"

View File

@ -12,6 +12,7 @@ type Config struct {
Auth types.Auth
ReplicaId uint64
HomePage string
MainAddress string
WebsocketAddr string

View File

@ -28,7 +28,7 @@ func init() {
log.Fatal(err)
}
TimeLimit = check.NewTimelimit[string](EmailTaskResendTime)
TimeLimit = check.NewTimeLimit[string](EmailTaskResendTime)
// Initialize the email manager
EmailManager = &EmailSender{
@ -53,16 +53,17 @@ func init() {
}
type EmailFormat struct {
TemplateName string // 模板名字
UniqueKey string // 用于处理唯一的任务,重发都会被利用到
TargetEmail string // 发送的目标email
CompanyName string // fs公司名
ConfirmationLink string // fs确认连接
SenderName string // 发送人
SenderTitle string // 发送标题
Extend map[string]string
TemplateName string // 模板名字
UniqueKey string // 用于处理唯一的任务,重发都会被利用到
TargetEmail string // 发送的目标email
CompanyName string // fs公司名
ConfirmationLink string // fs确认连接
SenderName string // 发送人
SenderTitle string // 发送标题
Extend map[string]string // 扩展参数
}
// 验证邮件格式是否符合要求
func (eformat *EmailFormat) Vaild() error {
// 1. 检查模板名称
@ -123,39 +124,47 @@ type EmailTask struct {
SendTime time.Time // 处理的任务时间
}
// ProcessEmailTasks 是 EmailSender 结构体的方法,用于处理邮件任务。
func (m *EmailSender) ProcessEmailTasks() {
for {
// 从 EmailTasks 通道中接收邮件任务
emailformat, ok := <-m.EmailTasks
if !ok {
log.Println("Email task channel closed")
break
}
// 验证邮件格式是否合法
err := emailformat.Vaild()
if err != nil {
logx.Error(err)
continue
}
// 加锁,避免并发修改 emailSending 字典
m.lock.Lock()
// 检查 emailSending 字典中是否已存在相同的任务
_, isSending := m.emailSending[emailformat.UniqueKey]
if isSending {
m.lock.Unlock()
continue
}
// 将邮件任务添加到 emailSending 字典中
m.emailSending[emailformat.UniqueKey] = &EmailTask{
Email: emailformat,
SendTime: time.Now().UTC(),
}
m.lock.Unlock()
// Acquire a token
// 获取一个信号量,限制同时发送的邮件任务数量
m.semaphore <- struct{}{}
go func() {
defer func() { <-m.semaphore }() // Release a token
defer func() { <-m.semaphore }() // 释放一个信号量
// 渲染邮件模板内容
content := RenderEmailTemplate(
emailformat.TemplateName,
emailformat.CompanyName,
@ -164,34 +173,41 @@ func (m *EmailSender) ProcessEmailTasks() {
emailformat.SenderTitle,
emailformat.Extend,
)
// 发送邮件
err := smtp.SendMail("smtp.gmail.com:587", m.Auth, m.FromEmail, []string{emailformat.TargetEmail}, content)
if err != nil {
log.Printf("Failed to send email to %s: %v\n", emailformat, err)
// 重新发送邮件
m.Resend(emailformat.UniqueKey, content)
}
}()
}
}
// Resend 重发邮件
// Resend 是 EmailSender 结构体的方法,用于重发邮件
func (m *EmailSender) Resend(uniqueKey string, content []byte) {
// 等待一段时间后重发邮件,避免频繁重发
time.Sleep(m.ResendTimeLimit)
m.lock.Lock()
defer m.lock.Unlock()
// Check if the email task still exists and has not been sent successfully
// 检查邮件任务是否仍存在并且未成功发送
if task, ok := m.emailSending[uniqueKey]; ok && task.SendTime.Add(m.ResendTimeLimit).After(time.Now().UTC()) {
err := smtp.SendMail(task.Email.TargetEmail, m.Auth, m.FromEmail, []string{task.Email.TargetEmail}, content)
if err != nil {
log.Printf("Failed to resend email to %s: %v\n", task.Email.TargetEmail, err)
} else {
// 从 emailSending 字典中删除已成功发送的邮件任务
delete(m.emailSending, uniqueKey)
}
}
}
// ClearExpiredTasks 清除过期的邮件任务
// ClearExpiredTasks 是 EmailSender 结构体的方法,用于清除过期的邮件任务
func (m *EmailSender) ClearExpiredTasks() {
// 每分钟触发一次清除操作
ticker := time.NewTicker(time.Minute)
defer ticker.Stop()
@ -199,6 +215,7 @@ func (m *EmailSender) ClearExpiredTasks() {
<-ticker.C
m.lock.Lock()
// 遍历 emailSending 字典,删除发送时间超过一定限制的过期任务
for email, task := range m.emailSending {
if task.SendTime.Add(m.ResendTimeLimit).Before(time.Now().UTC()) {
delete(m.emailSending, email)
@ -208,8 +225,19 @@ func (m *EmailSender) ClearExpiredTasks() {
}
}
func RenderEmailTemplate(templateName, companyName, confirmationLink, senderName, senderTitle string, extend map[string]string) []byte {
// RenderEmailTemplate 是一个渲染邮件模板的函数,根据给定的参数生成邮件内容。
// 参数:
// - templateName: 邮件模板的名称
// - companyName: 公司名称
// - confirmationLink: 确认链接
// - senderName: 发件人姓名
// - senderTitle: 发件人职务
// - extend: 扩展字段,包含其他自定义键值对的映射
// 返回值:
// - []byte: 渲染后的邮件内容(以字节切片形式返回)
func RenderEmailTemplate(templateName, companyName, confirmationLink, senderName, senderTitle string, extend map[string]string) []byte {
// 创建一个包含邮件模板所需数据的映射
data := map[string]string{
"CompanyName": companyName,
"ConfirmationLink": confirmationLink,
@ -217,16 +245,20 @@ func RenderEmailTemplate(templateName, companyName, confirmationLink, senderName
"SenderTitle": senderTitle,
}
// 将扩展字段中的键值对添加到数据映射中
for k, v := range extend {
data[k] = v
}
// 创建一个字节缓冲区,用于存储渲染后的邮件内容
var result bytes.Buffer
// result.Write([]byte("MIME-version: 1.0;\nContent-Type: text/html; charset=\"UTF-8\";\n\n"))
// 使用给定的数据映射执行邮件模板渲染
err := tpls.ExecuteTemplate(&result, templateName, data)
if err != nil {
log.Fatal(err)
}
// 将渲染后的邮件内容转换为字节切片并返回
return result.Bytes()
}

View File

@ -14,7 +14,6 @@ import (
"fusenapi/server/auth/internal/svc"
"fusenapi/server/auth/internal/types"
"github.com/474420502/requests"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"gorm.io/gorm"
@ -57,7 +56,7 @@ func FinishRegister(svcCtx *svc.ServiceContext, user *gmodel.FsUser, token *auth
event.Data = wevent.DataEmailRegister{
JwtToken: jwtToken,
}
err = CommonNotify(svcCtx.Config.WebsocketAddr, token.Wid, event)
err = wevent.CommonNotify(svcCtx.Config.WebsocketAddr, token.Wid, event)
if err != nil {
// logx.Error(err, token.TraceId)
return err
@ -66,34 +65,6 @@ func FinishRegister(svcCtx *svc.ServiceContext, user *gmodel.FsUser, token *auth
return nil
}
func CommonNotify(WebsocketAddr, wid string, event *wevent.WebsocketEvent) error {
reqWebsocketAddr := fmt.Sprintf("%s/api/websocket/common_notify", WebsocketAddr)
tp := requests.Post(reqWebsocketAddr)
tp.SetBodyJson(requests.M{
"wid": wid,
"data": event,
})
wresp, err := tp.Execute()
if err != nil {
// logx.Error(err, token.TraceId)
return err
}
result := wresp.Json()
if !result.Get("code").Exists() {
return fmt.Errorf("send %s is error", reqWebsocketAddr)
}
if result.Get("code").Int() != 200 {
return fmt.Errorf("%s", result.String())
}
return nil
}
func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEmailConfirmation, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
@ -176,7 +147,7 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma
}
event := wevent.NewWebsocketEventSuccess(wevent.UserResetToken, rt.TraceId)
err = CommonNotify(l.svcCtx.Config.MainAddress, rt.Wid, event)
err = wevent.CommonNotify(l.svcCtx.Config.MainAddress, rt.Wid, event)
if err != nil {
logx.Error(err, rt.TraceId)
return resp.SetStatus(basic.CodeResetPasswordErr, err.Error())

View File

@ -50,7 +50,7 @@ func (l *UserResetPasswordHtmlLogic) UserResetPasswordHtml(req *types.RequestUse
func (l *UserResetPasswordHtmlLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
err := tpls.ExecuteTemplate(w, "reset_confirm.tpl", map[string]string{
"HomePage": "http://www.fusen.3718.cn",
"HomePage": l.svcCtx.Config.HomePage,
"ResetToken": l.ResetToken,
"ResetPasswordLink": l.svcCtx.Config.MainAddress + "/api/auth/reset/password",
})

View File

@ -51,7 +51,7 @@ func (l *UserResetPasswordLogic) UserResetPassword(req *types.RequestUserResetPa
}
if time.Since(rt.CreateAt) > 30*time.Minute {
return resp.SetStatusWithMessage(basic.CodeOAuthConfirmationTimeoutErr, "Verification links expire after 30 minute.")
return resp.SetStatusWithMessage(basic.CodeOAuthConfirmationTimeoutErr, "verification links expire after 30 minute.")
}
err = l.svcCtx.AllModels.FsUser.Transaction(l.ctx, func(tx *gorm.DB) error {
@ -67,7 +67,7 @@ func (l *UserResetPasswordLogic) UserResetPassword(req *types.RequestUserResetPa
}
if *user.PasswordHash == req.NewPassword {
return fmt.Errorf("the password is the same as the old one. It needs to be changed")
return fmt.Errorf("the password is the same as the old one. it needs to be changed")
}
return tx.Where("id = ?", rt.UserId).Update("PasswordHash", req.NewPassword).Error
@ -79,7 +79,7 @@ func (l *UserResetPasswordLogic) UserResetPassword(req *types.RequestUserResetPa
}
event := wevent.NewWebsocketEventSuccess(wevent.UserResetToken, rt.TraceId)
err = CommonNotify(l.svcCtx.Config.WebsocketAddr, rt.Wid, event)
err = wevent.CommonNotify(l.svcCtx.Config.WebsocketAddr, rt.Wid, event)
if err != nil {
logx.Error(err, rt.TraceId)
return resp.SetStatusWithMessage(basic.CodeResetPasswordErr, err.Error())

View File

@ -1 +1,2 @@
base
main

8
server/base/Dockerfile Executable file
View File

@ -0,0 +1,8 @@
FROM alpine
WORKDIR /www/fusenapi/
COPY ./bin/api-base-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-base-srv"]

View File

@ -1 +1,2 @@
canteen
main

View File

@ -2,5 +2,7 @@ FROM alpine
WORKDIR /www/fusenapi/
COPY ./bin/api-canteen-srv /www/fusenapi/
COPY ./etc /www/fusenapi/etc
COPY ./env.yaml /opt/
COPY ./server.fusen.3718.cn.pem /opt/
COPY ./server.fusen.3718.cn.key /opt/
CMD ["/www/fusenapi/api-canteen-srv"]

2
server/collection/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
collection
main

8
server/collection/Dockerfile Executable file
View File

@ -0,0 +1,8 @@
FROM alpine
WORKDIR /www/fusenapi/
COPY ./bin/api-collection-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-collection-srv"]

View File

@ -27,6 +27,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/api/collection/get_collect_product_list",
Handler: GetCollectProductListHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/api/collection/test_ai",
Handler: TestAiHandler(serverCtx),
},
},
)
}

View File

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

File diff suppressed because one or more lines are too long

View File

@ -40,6 +40,10 @@ type GetCollectProductListRspItem struct {
IsDeleted int64 `json:"is_deleted"`
}
type TestAiReq struct {
Num int `form:"num"`
}
type Request struct {
}

View File

@ -1 +1,2 @@
data-transfer
main

View File

@ -2,5 +2,7 @@ FROM alpine
WORKDIR /www/fusenapi/
COPY ./bin/api-data-transfer-srv /www/fusenapi/
COPY ./etc /www/fusenapi/etc
COPY ./env.yaml /opt/
COPY ./server.fusen.3718.cn.pem /opt/
COPY ./server.fusen.3718.cn.key /opt/
CMD ["/www/fusenapi/api-data-transfer-srv"]

View File

@ -1 +1,2 @@
home-user-auth
main

View File

@ -2,5 +2,7 @@ FROM alpine
WORKDIR /www/fusenapi/
COPY ./bin/api-home-user-auth-srv /www/fusenapi/
COPY ./etc /www/fusenapi/etc
COPY ./env.yaml /opt/
COPY ./server.fusen.3718.cn.pem /opt/
COPY ./server.fusen.3718.cn.key /opt/
CMD ["/www/fusenapi/api-home-user-auth-srv"]

View File

@ -1 +1,2 @@
info
main

8
server/info/Dockerfile Executable file
View File

@ -0,0 +1,8 @@
FROM alpine
WORKDIR /www/fusenapi/
COPY ./bin/api-info-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-info-srv"]

View File

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

View File

@ -2,5 +2,7 @@ FROM alpine
WORKDIR /www/fusenapi/
COPY ./bin/api-map-library-srv /www/fusenapi/
COPY ./etc /www/fusenapi/etc
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 +1,2 @@
order
main

8
server/order/Dockerfile Executable file
View File

@ -0,0 +1,8 @@
FROM alpine
WORKDIR /www/fusenapi/
COPY ./bin/api-order-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-order-srv"]

View File

@ -1 +1,2 @@
pay
main

View File

@ -2,5 +2,7 @@ FROM alpine
WORKDIR /www/fusenapi/
COPY ./bin/api-pay-srv /www/fusenapi/
COPY ./etc /www/fusenapi/etc
COPY ./env.yaml /opt/
COPY ./server.fusen.3718.cn.pem /opt/
COPY ./server.fusen.3718.cn.key /opt/
CMD ["/www/fusenapi/api-pay-srv"]

View File

@ -1 +1,2 @@
product-model
main

View File

@ -2,5 +2,7 @@ FROM alpine
WORKDIR /www/fusenapi/
COPY ./bin/api-product-model-srv /www/fusenapi/
COPY ./etc /www/fusenapi/etc
COPY ./env.yaml /opt/
COPY ./server.fusen.3718.cn.pem /opt/
COPY ./server.fusen.3718.cn.key /opt/
CMD ["/www/fusenapi/api-product-model-srv"]

View File

@ -1 +1,2 @@
product-template-tag
main

View File

@ -2,5 +2,7 @@ FROM alpine
WORKDIR /www/fusenapi/
COPY ./bin/api-product-template-tag-srv /www/fusenapi/
COPY ./etc /www/fusenapi/etc
COPY ./env.yaml /opt/
COPY ./server.fusen.3718.cn.pem /opt/
COPY ./server.fusen.3718.cn.key /opt/
CMD ["/www/fusenapi/api-product-template-tag-srv"]

View File

@ -1 +1,2 @@
product-template
main

View File

@ -2,5 +2,7 @@ FROM alpine
WORKDIR /www/fusenapi/
COPY ./bin/api-product-template-srv /www/fusenapi/
COPY ./etc /www/fusenapi/etc
COPY ./env.yaml /opt/
COPY ./server.fusen.3718.cn.pem /opt/
COPY ./server.fusen.3718.cn.key /opt/
CMD ["/www/fusenapi/api-product-template-srv"]

View File

@ -1 +1,2 @@
product
main

View File

@ -2,5 +2,7 @@ FROM alpine
WORKDIR /www/fusenapi/
COPY ./bin/api-product-srv /www/fusenapi/
COPY ./etc /www/fusenapi/etc
COPY ./env.yaml /opt/
COPY ./server.fusen.3718.cn.pem /opt/
COPY ./server.fusen.3718.cn.key /opt/
CMD ["/www/fusenapi/api-product-srv"]

View File

@ -49,7 +49,6 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
tStatus := int64(1)
tReq := gmodel.GetAllTagByParamsReq{
Status: &tStatus,
OrderBy: "`sort` DESC",
WithChild: true, //需要子集
Category: 1, //前台网站用的
Level: 2, //等级是2的
@ -425,20 +424,6 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL
if _, ok = req.MapTagProp[productInfo.Id]; ok {
item.CoverDefault = req.MapTagProp[productInfo.Id]
}
//千人千面处理
/*r := image.ThousandFaceImageFormatReq{
Size: int(req.Size),
IsThousandFace: 0,
Cover: *productInfo.Cover,
CoverImg: *productInfo.CoverImg,
ProductId: productInfo.Id,
UserId: req.User.Id,
}
if req.User.Id != 0 {
r.IsThousandFace = int(*req.User.IsThousandFace)
}
image.ThousandFaceImageFormat(&r)
item.Cover = r.Cover*/
//加入分类产品切片
productListRsp = append(productListRsp, item)
}

View File

@ -1 +1,2 @@
resource
main

8
server/resource/Dockerfile Executable file
View File

@ -0,0 +1,8 @@
FROM alpine
WORKDIR /www/fusenapi/
COPY ./bin/api-resource-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-resource-srv"]

View File

@ -1 +1,2 @@
shopping-cart
main

View File

@ -2,5 +2,7 @@ FROM alpine
WORKDIR /www/fusenapi/
COPY ./bin/api-shopping-cart-srv /www/fusenapi/
COPY ./etc /www/fusenapi/etc
COPY ./env.yaml /opt/
COPY ./server.fusen.3718.cn.pem /opt/
COPY ./server.fusen.3718.cn.key /opt/
CMD ["/www/fusenapi/api-shopping-cart-srv"]

View File

@ -1 +1,2 @@
upload
main

View File

@ -2,5 +2,7 @@ FROM alpine
WORKDIR /www/fusenapi/
COPY ./bin/api-upload-srv /www/fusenapi/
COPY ./etc /www/fusenapi/etc
COPY ./env.yaml /opt/
COPY ./server.fusen.3718.cn.pem /opt/
COPY ./server.fusen.3718.cn.key /opt/
CMD ["/www/fusenapi/api-upload-srv"]

View File

@ -1 +1,2 @@
webset
main

View File

@ -2,5 +2,7 @@ FROM alpine
WORKDIR /www/fusenapi/
COPY ./bin/api-webset-srv /www/fusenapi/
COPY ./etc /www/fusenapi/etc
COPY ./env.yaml /opt/
COPY ./server.fusen.3718.cn.pem /opt/
COPY ./server.fusen.3718.cn.key /opt/
CMD ["/www/fusenapi/api-webset-srv"]

View File

@ -1 +1,2 @@
websocket
main

View File

@ -2,5 +2,7 @@ FROM alpine
WORKDIR /www/fusenapi/
COPY ./bin/api-websocket-srv /www/fusenapi/
COPY ./etc /www/fusenapi/etc
COPY ./env.yaml /opt/
COPY ./server.fusen.3718.cn.pem /opt/
COPY ./server.fusen.3718.cn.key /opt/
CMD ["/www/fusenapi/api-websocket-srv"]

View File

@ -115,7 +115,7 @@ func (w *wsConnectItem) consumeRenderImageData() {
}()
select {
case <-w.extendRenderProperty.renderCtx.Done():
panic("=========渲染取消旧的上下文=======")
panic("=========检测到模板标签/颜色变化,渲染取消旧的任务=======")
case <-tmpChan:
return
}
@ -277,6 +277,10 @@ func (w *wsConnectItem) getProductRelateionInfo(renderImageData *websocket_data.
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取对应开启云渲染模板失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
return nil, nil, nil, errors.New("获取对应开启云渲染模板失败")
}
if productTemplate.TemplateInfo == nil || *productTemplate.TemplateInfo == "" {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "模板设计信息是空的", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, 0, 0, 0)
return nil, nil, nil, errors.New("模板设计信息是空的")
}
//根据模板找到模型
model3d, err = w.logic.svcCtx.AllModels.FsProductModel3d.FindOne(w.logic.ctx, *productTemplate.ModelId)
if err != nil {
@ -288,6 +292,10 @@ func (w *wsConnectItem) getProductRelateionInfo(renderImageData *websocket_data.
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取对应模型失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, 0, 0, 0)
return nil, nil, nil, errors.New("获取对应模型失败")
}
if model3d.ModelInfo == nil || *model3d.ModelInfo == "" {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "模型设计信息是空的", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3d.Id, 0, 0)
return nil, nil, nil, errors.New("模型设计信息是空的")
}
//根据模型id获取尺寸信息
productSize, err = w.logic.svcCtx.AllModels.FsProductSize.FindOne(w.logic.ctx, *model3d.SizeId)
if err != nil {

View File

@ -18,6 +18,9 @@ service collection {
//获取收藏列表
@handler GetCollectProductListHandler
get /api/collection/get_collect_product_list(GetCollectProductListReq) returns (response);
//测试
@handler TestAiHandler
get /api/collection/test_ai(TestAiReq) returns (response);
}
//收藏产品
@ -52,4 +55,8 @@ type GetCollectProductListRspItem {
MinPrice string `json:"min_price"`
IsShelf int64 `json:"is_shelf"`
IsDeleted int64 `json:"is_deleted"`
}
//测试
type TestAiReq {
Num int `form:"num"`
}

View File

@ -56,7 +56,7 @@ var (
CodeUserIdNotFoundErr = &StatusResponse{5051, "user not found"} // 未找到用户
CodePasswordErr = &StatusResponse{5052, "invalid password"} // 无效密码
CodeEmailExistsErr = &StatusResponse{5053, "email exists"} // email存在
CodeEmailTimeShortErr = &StatusResponse{5053, "email with the time of resend is too short"} // email存在
CodeEmailTimeShortErr = &StatusResponse{5053, "email with the time of resend is too short"} // email重发的时间太短
CodeResetPasswordErr = &StatusResponse{5054, "reset password error"} // 无效密码
CodeSafeValueRangeErr = &StatusResponse{5040, "value not in range"} // 值不在范围内

View File

@ -15,9 +15,9 @@ type TimeLimit[T comparable] struct {
dur time.Duration
}
// NewTimelimit构造函数,接收限频的时间间隔
// NewTimeLimit构造函数,接收限频的时间间隔
// 并初始化内部字典和间隔字段
func NewTimelimit[T comparable](dur time.Duration) *TimeLimit[T] {
func NewTimeLimit[T comparable](dur time.Duration) *TimeLimit[T] {
return &TimeLimit[T]{
dict: make(map[T]struct{}),
dur: dur,

View File

@ -1,7 +1,10 @@
package wevent
import (
"fmt"
"time"
"github.com/474420502/requests"
)
// 和前端交流的事件机制
@ -22,6 +25,34 @@ type WebsocketEvent struct {
Data any `json:"data"` // 关注的数据
}
func CommonNotify(WebsocketAddr, wid string, event *WebsocketEvent) error {
reqWebsocketAddr := fmt.Sprintf("%s/api/websocket/common_notify", WebsocketAddr)
tp := requests.Post(reqWebsocketAddr)
tp.SetBodyJson(requests.M{
"wid": wid,
"data": event,
})
wresp, err := tp.Execute()
if err != nil {
// logx.Error(err, token.TraceId)
return err
}
result := wresp.Json()
if !result.Get("code").Exists() {
return fmt.Errorf("send %s is error", reqWebsocketAddr)
}
if result.Get("code").Int() != 200 {
return fmt.Errorf("%s", result.String())
}
return nil
}
// NewWebsocketEvent 创建一个Websocket事件
func NewWebsocketEvent(etype EventType, TraceId string) *WebsocketEvent {
return &WebsocketEvent{