v1.1
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"ycc-server/app/main/api/internal/config"
|
||||
"ycc-server/app/main/model"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jung-kurt/gofpdf"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
@@ -36,9 +37,9 @@ func NewAuthorizationService(c config.Config, authDocModel model.AuthorizationDo
|
||||
// GenerateAuthorizationDocument 生成授权书PDF
|
||||
func (s *AuthorizationService) GenerateAuthorizationDocument(
|
||||
ctx context.Context,
|
||||
userID int64,
|
||||
orderID int64,
|
||||
queryID int64,
|
||||
userID string,
|
||||
orderID string,
|
||||
queryID string,
|
||||
userInfo map[string]interface{},
|
||||
) (*model.AuthorizationDocument, error) {
|
||||
// 1. 生成PDF内容
|
||||
@@ -56,7 +57,7 @@ func (s *AuthorizationService) GenerateAuthorizationDocument(
|
||||
}
|
||||
|
||||
// 3. 生成文件名和路径
|
||||
fileName := fmt.Sprintf("auth_%d_%d_%s.pdf", userID, orderID, time.Now().Format("20060102_150405"))
|
||||
fileName := fmt.Sprintf("auth_%s_%s_%s.pdf", userID, orderID, time.Now().Format("20060102_150405"))
|
||||
filePath := filepath.Join(dirPath, fileName)
|
||||
// 只存储相对路径,不包含域名
|
||||
relativePath := fmt.Sprintf("%s/%s/%s", year, month, fileName)
|
||||
@@ -68,6 +69,7 @@ func (s *AuthorizationService) GenerateAuthorizationDocument(
|
||||
|
||||
// 5. 保存到数据库
|
||||
authDoc := &model.AuthorizationDocument{
|
||||
Id: uuid.NewString(),
|
||||
UserId: userID,
|
||||
OrderId: orderID,
|
||||
QueryId: queryID,
|
||||
@@ -80,15 +82,14 @@ func (s *AuthorizationService) GenerateAuthorizationDocument(
|
||||
ExpireTime: sql.NullTime{Valid: false}, // 永久保留,不设置过期时间
|
||||
}
|
||||
|
||||
result, err := s.authDocModel.Insert(ctx, nil, authDoc)
|
||||
_, err = s.authDocModel.Insert(ctx, nil, authDoc)
|
||||
if err != nil {
|
||||
// 如果数据库保存失败,删除已创建的文件
|
||||
os.Remove(filePath)
|
||||
return nil, errors.Wrapf(err, "保存授权书记录失败")
|
||||
}
|
||||
|
||||
authDoc.Id, _ = result.LastInsertId()
|
||||
logx.Infof("授权书生成成功: userID=%d, orderID=%d, filePath=%s", userID, orderID, filePath)
|
||||
logx.Infof("授权书生成成功: userID=%s, orderID=%s, filePath=%s", userID, orderID, filePath)
|
||||
|
||||
return authDoc, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user