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

This commit is contained in:
eson 2023-10-18 15:44:05 +08:00
commit bf0f8b9a5d
9 changed files with 98 additions and 66 deletions

View File

@ -196,7 +196,7 @@ const INVOICE_TEMPLATE_01 = `
const INVOICE_TEMPLATE_02 = `
<!-- information -->
<table class="information_warp" border="0" align="center" cellpadding="0" cellspacing="0" width="100%">
<table class="information_warp width100" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td class="information_td bill" align="left">Bill To:</td>
<td class="information_td right" align="right">Invoice No. #%v</td>
@ -221,7 +221,7 @@ const INVOICE_TEMPLATE_02 = `
`
const INVOICE_TEMPLATE_03 = `
<!-- bill -->
<table class="bill_warp" border="0" align="center" cellpadding="0" cellspacing="0" width="100%">
<table class="bill_warp width100" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td class="bill_td title" align="left">Product Name</td>
<td class="bill_td title" align="right">Price</td>
@ -242,7 +242,7 @@ const INVOICE_TEMPLATE_0301 = `
`
const INVOICE_TEMPLATE_04 = `
<!-- total -->
<table class="total_warp" border="0" align="right" cellpadding="0" cellspacing="0" width="50%">
<table class="total_warp width50" border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<td class="total_td" align="right">Subtotal</td>
<td class="total_td info" align="right">%v</td>
@ -271,7 +271,7 @@ const INVOICE_TEMPLATE_04 = `
`
const INVOICE_TEMPLATE_05 = `
<!-- notes -->
<table class="notes_warp" border="0" align="center" cellpadding="0" cellspacing="0" width="100%">
<table class="notes_warp width100" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td class="notes_td title" align="left">Payment Method:</td>
<td class="notes_td title" align="left">Notes:</td>
@ -287,7 +287,14 @@ const INVOICE_TEMPLATE_05 = `
`
const INVOICE_TEMPLATE_06 = `
</body>
<style>
.width50 {
width: 50%;
}
.width100 {
width: 100%;
}
</style>
</html>

View File

@ -116,6 +116,7 @@ func (l *LogoCombineLogic) LogoCombine(req *types.LogoCombineReq, userinfo *auth
},
ProductTemplateTagGroups: req.TemplateTagGroups,
ProductTemplateV2Info: productTemplateV2Info,
Debug: userinfo.Debug,
})
if err != nil {
@ -124,10 +125,8 @@ func (l *LogoCombineLogic) LogoCombine(req *types.LogoCombineReq, userinfo *auth
// 返回成功的响应和上传URL
return resp.SetStatus(basic.CodeOK, map[string]interface{}{
"resource_id": res.ResourceId,
"resource_url": res.ResourceUrl,
"resource_metadata": "",
"diff_time_logo_combine": res.DiffTimeLogoCombine,
"diff_time_upload_file": res.DiffTimeUploadFile,
})
"resource_id": res.ResourceId,
"resource_url": res.ResourceUrl,
"resource_metadata": "",
}).WithDebug(res.DebugData)
}

View File

@ -174,6 +174,7 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us
resLogoStandard, err := l.svcCtx.Repositories.ImageHandle.LogoInfoSet(l.ctx, &repositories.LogoInfoSetReq{
LogoUrl: logoUrl,
Version: l.svcCtx.Config.BLMService.Version,
Debug: userinfo.Debug,
})
if err != nil {

View File

@ -104,14 +104,28 @@ type wsConnectItem struct {
// 请求建立连接升级websocket协议
func (l *DataTransferLogic) DataTransfer(req *types.DataTransferReq, w http.ResponseWriter, r *http.Request) {
//把子协议携带的token设置到标准token头信息中
token := r.Header.Get("Sec-Websocket-Protocol")
tokens := r.Header.Get("Sec-Websocket-Protocol")
oldWid := req.Wid
oldWid = strings.Trim(oldWid, " ")
//有token是正常用户无则是白板用户也可以连接
if token != "" {
if tokens != "" {
token := ""
debugToken := ""
tokenSlice := strings.Split(tokens, ",")
switch len(tokenSlice) {
case 1:
token = strings.Trim(tokenSlice[0], " ")
case 2:
token = strings.Trim(tokenSlice[0], " ")
debugToken = strings.Trim(tokenSlice[1], " ")
r.Header.Set("Debug-Token", debugToken)
default:
logx.Error("invalid ws token:", tokens)
return
}
r.Header.Set("Authorization", "Bearer "+token)
//设置Sec-Websocket-Protocol
upgrader.Subprotocols = []string{token}
upgrader.Subprotocols = []string{tokens}
}
//判断下是否火狐浏览器(获取浏览器第一条消息返回有收不到的bug需要延迟1秒)
userAgent := r.Header.Get("User-Agent")
@ -167,6 +181,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use
l.sendGetUniqueIdErrResponse(conn)
return wsConnectItem{}, err
}
//传入绑定的wid判断是否可重用
if oldWid != "" {
for i := 0; i < 1; i++ {
//解析传入的wid是不是属于自己的用户的
@ -224,12 +239,6 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use
},
debug: userInfo.Debug,
}
//先设置下debug(后面要删掉)
ws.debug = &auth.Debug{
Exp: &userInfo.Exp,
IsCache: 1,
IsAllTemplateTag: 0,
}
//保存连接
mapConnPool.Store(uniqueId, ws)
//非白板用户需要为这个用户建立map索引便于通过用户查询
@ -237,8 +246,8 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use
if isFirefoxBrowser {
time.Sleep(time.Second * 1) //兼容下火狐(直接发回去收不到第一条消息:有待研究)
}
ws.sendToOutChan(ws.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, websocket_data.ConnectSuccessMsg{Wid: uniqueId}))
//发送累加统计连接
ws.sendToOutChan(ws.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, websocket_data.ConnectSuccessMsg{Wid: uniqueId, Debug: ws.debug != nil}))
//发送累加统计连接
increaseWebsocketConnectCount()
return ws, nil
}
@ -275,6 +284,7 @@ func (l *DataTransferLogic) checkAuth(r *http.Request) (isAuth bool, userInfo *a
// 解析JWT token,并对空用户进行判断
userInfo, err := basic.ParseJwtToken(r, l.svcCtx)
if err != nil {
logx.Error("未授权:", err.Error())
return false, nil
}
if userInfo.UserId > 0 {
@ -328,6 +338,10 @@ func (w *wsConnectItem) heartbeat() {
w.close()
return
}
//查看debug的时间是否过期
if w.debug != nil && w.debug.Exp != nil && *w.debug.Exp < time.Now().UTC().Unix() {
w.debug = nil
}
//发送心跳信息
if err := w.conn.WriteMessage(websocket.PongMessage, nil); err != nil {
logx.Error("发送心跳信息异常,关闭连接:", w.uniqueId, err)

View File

@ -10,6 +10,7 @@ import (
"fusenapi/constants"
"fusenapi/model/gmodel"
"fusenapi/service/repositories"
"fusenapi/utils/auth"
"fusenapi/utils/curl"
"fusenapi/utils/hash"
"fusenapi/utils/websocket_data"
@ -132,7 +133,7 @@ func (w *wsConnectItem) consumeRenderImageData() {
}()
select {
case <-w.extendRenderProperty.renderCtx.Done():
panic("=========检测到模板标签/颜色变化,渲染取消旧的任务=======")
panic("检测到模板标签/颜色/logo变化,渲染取消旧的任务")
case <-tmpChan:
return
}
@ -245,7 +246,7 @@ func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageRe
return
}
//发送合图完毕阶段消息
w.sendCombineImageStepResponseMessage(renderImageData.RenderId, renderImageData.RequestId, combineImage, productSize.Id, model3dInfo.Id, productTemplate.Id, res.DiffTimeLogoCombine, res.DiffTimeUploadFile)
w.sendCombineImageStepResponseMessage(renderImageData.RenderId, renderImageData.RequestId, combineImage, productSize.Id, model3dInfo.Id, productTemplate.Id, res.DebugData)
//获取唯一id
taskId := w.genRenderTaskId(combineImage, renderImageData, model3dInfo, productTemplate, element)
//查询有没有缓存的资源,有就返回
@ -467,17 +468,17 @@ func (w *wsConnectItem) genRenderTaskId(combineImage string, renderImageData web
// ****************************下面的发送消息的*********************************
// 发送合图完毕阶段通知消息
func (w *wsConnectItem) sendCombineImageStepResponseMessage(renderId, requestId, combineImage string, sizeId, modelId, templateId, combineTime, uploadTime int64) {
func (w *wsConnectItem) sendCombineImageStepResponseMessage(renderId, requestId, combineImage string, sizeId, modelId, templateId int64, debugData *auth.DebugData) {
if w.debug == nil {
return
}
combineTakesTime := "cache"
uploadCombineImageTakesTime := "cache"
if combineTime > 0 {
combineTakesTime = fmt.Sprintf("%dms", combineTime)
if debugData.DiffTimeLogoCombine > 0 {
combineTakesTime = fmt.Sprintf("%dms", debugData.DiffTimeLogoCombine)
}
if uploadTime > 0 {
uploadCombineImageTakesTime = fmt.Sprintf("%dms", uploadTime)
if debugData.DiffTimeUploadFile > 0 {
uploadCombineImageTakesTime = fmt.Sprintf("%dms", debugData.DiffTimeUploadFile)
}
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_COMBINE_IMAGE, websocket_data.CombineImageRspMsg{
RenderId: renderId,

View File

@ -68,8 +68,9 @@ type (
/* logo信息 */
type (
LogoInfoSetReq struct {
LogoUrl string `json:"logo_url"`
Version string `json:"version"`
LogoUrl string `json:"logo_url"`
Version string `json:"version"`
Debug *auth.Debug `json:"debug"`
}
LogoInfoSetRes struct {
Res string `json:"res"`
@ -90,6 +91,10 @@ func (l *defaultImageHandle) LogoInfoSet(ctx context.Context, in *LogoInfoSetReq
postMap["logo_url"] = in.LogoUrl
postMap["version"] = in.Version
if in.Debug != nil && in.Debug.IsAllTemplateTag == 1 {
postMap["is_all_template"] = "1"
}
logc.Infof(ctx, "算法请求--LOGO基础信息--开始时间:%v", time.Now().UTC())
err := curl.NewClient(ctx, &curl.Config{
BaseUrl: bLMServicePort,
@ -131,11 +136,10 @@ type (
Debug *auth.Debug `json:"debug"`
}
LogoCombineRes struct {
ResourceId string
ResourceUrl *string
Metadata *string
DiffTimeLogoCombine int64
DiffTimeUploadFile int64
ResourceId string
ResourceUrl *string
Metadata *string
DebugData *auth.DebugData `json:"debug_data"`
}
)
type TemplateTagColor struct {
@ -144,6 +148,7 @@ type TemplateTagColor struct {
}
func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq) (*LogoCombineRes, error) {
var resp = &LogoCombineRes{}
logoResourceId := s3url_to_s3id.GetS3ResourceIdFormUrl(in.LogoUrl)
if logoResourceId == "" {
return nil, errors.New("invalid logo url")
@ -167,10 +172,12 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq
resourceModel := gmodel.NewFsResourceModel(l.MysqlConn)
resourceInfo, err := resourceModel.FindOneById(ctx, resourceId)
if err == nil && resourceInfo.ResourceId != "" {
return &LogoCombineRes{
ResourceId: resourceId,
ResourceUrl: resourceInfo.ResourceUrl,
}, nil
if in.Debug == nil || (in.Debug != nil && in.Debug.IsCache == 1) {
return &LogoCombineRes{
ResourceId: resourceId,
ResourceUrl: resourceInfo.ResourceUrl,
}, nil
}
} else {
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
@ -308,12 +315,16 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq
return nil, err
}
return &LogoCombineRes{
ResourceId: uploadRes.ResourceId,
ResourceUrl: &uploadRes.ResourceUrl,
DiffTimeLogoCombine: diffTimeLogoCombine,
DiffTimeUploadFile: diffTimeUploadFile,
}, nil
resp.ResourceId = uploadRes.ResourceId
resp.ResourceUrl = &uploadRes.ResourceUrl
if in.Debug != nil {
resp.DebugData = &auth.DebugData{
DiffTimeLogoCombine: diffTimeLogoCombine,
DiffTimeUploadFile: diffTimeUploadFile,
}
}
return resp, nil
}
/* logo合图 */

View File

@ -365,11 +365,15 @@ func (d *defaultOrder) Invoice(ctx context.Context, in *InvoiceReq) (res *Invoic
var city string
var street string
var state string
var suite string
var zipCode string
if ress.OrderDetail.DeliveryAddress != nil {
name = fmt.Sprintf("%s %s", ress.OrderDetail.DeliveryAddress.FirstName, ress.OrderDetail.DeliveryAddress.LastName)
street = ress.OrderDetail.DeliveryAddress.Street
city = ress.OrderDetail.DeliveryAddress.City
state = ress.OrderDetail.DeliveryAddress.State
suite = ress.OrderDetail.DeliveryAddress.Suite
zipCode = ress.OrderDetail.DeliveryAddress.ZipCode
}
var products string
@ -380,7 +384,7 @@ func (d *defaultOrder) Invoice(ctx context.Context, in *InvoiceReq) (res *Invoic
var productsInfo = fmt.Sprintf(model00301, orderProduct.ProductName, price, orderProduct.PurchaseQuantity.Current, priceTotal)
products = products + productsInfo
}
model003 = fmt.Sprintf(constants.INVOICE_TEMPLATE_03, "", products)
model003 = fmt.Sprintf(constants.INVOICE_TEMPLATE_03, products)
var subtotal = fmt.Sprintf("%s%s", constants.OrderCurrencyMessage[constants.Currency(ress.OrderDetail.OrderAmount.Subtotal.Current.CurrentCurrency)], ress.OrderDetail.OrderAmount.Subtotal.Current.CurrentAmount.(string))
var taxStr = "0.00"
@ -396,22 +400,16 @@ func (d *defaultOrder) Invoice(ctx context.Context, in *InvoiceReq) (res *Invoic
// 生成收据发票--首款
if receiptSnsDeposit != "" {
v1 := receiptSnsDeposit
v2 := name
v3 := ctimeDate
v4 := street
v5 := city
v6 := state
model002 = fmt.Sprintf(constants.INVOICE_TEMPLATE_02, "", v1, v2, v3, v4, v5, v6)
model002 = fmt.Sprintf(constants.INVOICE_TEMPLATE_02, receiptSnsDeposit, name, ctimeDate, street+" "+suite, city, state+zipCode)
v7 := "Deposit Requested"
v8 := fmt.Sprintf("%s%s", constants.OrderCurrencyMessage[constants.Currency(ress.OrderDetail.OrderAmount.Deposit.PayAmount.Current.CurrentCurrency)], ress.OrderDetail.OrderAmount.Deposit.PayAmount.Current.CurrentAmount.(string))
v9 := "Deposit Due"
v10 := v8
model004 = fmt.Sprintf(constants.INVOICE_TEMPLATE_04, "", subtotal, tax, total, v7, v8, v9, v10)
model004 = fmt.Sprintf(constants.INVOICE_TEMPLATE_04, subtotal, tax, total, v7, v8, v9, v10)
cardSn := "****" + *orderTradeDeposit.CardSn
model005 = fmt.Sprintf(constants.INVOICE_TEMPLATE_05, "", *orderTradeDeposit.CardBrand, cardSn)
model005 = fmt.Sprintf(constants.INVOICE_TEMPLATE_05, *orderTradeDeposit.CardBrand, cardSn)
var content = model001 + model002 + model003 + model004 + model005 + model006
@ -456,22 +454,16 @@ func (d *defaultOrder) Invoice(ctx context.Context, in *InvoiceReq) (res *Invoic
// 生成收据发票--尾款
if receiptSnsFinal != "" {
v1 := receiptSnsFinal
v2 := name
v3 := ctimeDate
v4 := street
v5 := city
v6 := state
model002 = fmt.Sprintf(constants.INVOICE_TEMPLATE_02, "", v1, v2, v3, v4, v5, v6)
model002 = fmt.Sprintf(constants.INVOICE_TEMPLATE_02, receiptSnsDeposit, name, ctimeDate, street+" "+suite, city, state+zipCode)
v7 := "Balance Requested"
v8 := fmt.Sprintf("%s%s", constants.OrderCurrencyMessage[constants.Currency(ress.OrderDetail.OrderAmount.RemainingBalance.PayAmount.Current.CurrentCurrency)], ress.OrderDetail.OrderAmount.RemainingBalance.PayAmount.Current.CurrentAmount.(string))
v9 := "Balance Due"
v10 := v8
model004 = fmt.Sprintf(constants.INVOICE_TEMPLATE_04, "", subtotal, tax, total, v7, v8, v9, v10)
model004 = fmt.Sprintf(constants.INVOICE_TEMPLATE_04, subtotal, tax, total, v7, v8, v9, v10)
cardSn := "****" + *orderTradeFinal.CardSn
model005 = fmt.Sprintf(constants.INVOICE_TEMPLATE_05, "", *orderTradeDeposit.CardBrand, cardSn)
model005 = fmt.Sprintf(constants.INVOICE_TEMPLATE_05, *orderTradeDeposit.CardBrand, cardSn)
var content = model001 + model002 + model003 + model004 + model005 + model006
base64, err := pdf.HtmlToPdfBase64(content, "html")
if err != nil {

View File

@ -24,6 +24,12 @@ const (
IDTYPE_Guest IDTYPE = 2
)
// DebugData
type DebugData struct {
DiffTimeLogoCombine int64 `json:"diff_time_logo_combine"` // 合图算法时间
DiffTimeUploadFile int64 `json:"diff_time_upload_file"` // 合图上传时间
}
// Debug 相关的结构
type Debug struct {
Exp *int64 `json:"exp"`

View File

@ -2,7 +2,8 @@ package websocket_data
// 基础连接成功返回
type ConnectSuccessMsg struct {
Wid string `json:"wid"`
Wid string `json:"wid"` //websocket连接唯一标识
Debug bool `json:"debug"` //是否开启debug
}
// 连接失败