feat: 迁移plant

This commit is contained in:
Blizzard
2026-05-23 13:55:05 +08:00
parent a93477ea8e
commit ae6d03d351
228 changed files with 25296 additions and 917 deletions
@@ -0,0 +1,84 @@
package myPlant
import (
"context"
"time"
filePb "sundynix-micro-go/app/file/rpc/file"
"sundynix-micro-go/app/plant/api/internal/svc"
)
// ========== 图片 DTO ==========
// ImageInfo 图片信息 DTO,匹配旧单体 Oss 结构
type ImageInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Url string `json:"url"`
Tag string `json:"tag"`
Key string `json:"key"`
Suffix string `json:"suffix"`
MD5 string `json:"md5"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
CreatedAtStr string `json:"createdAtStr"`
}
// ========== 时间格式化 ==========
func FormatTime(t time.Time) string {
if t.IsZero() {
return ""
}
return t.Format(time.RFC3339)
}
func FormatTimeShort(t time.Time) string {
if t.IsZero() {
return ""
}
return t.Format("2006-01-02 15:04:05")
}
func UnixToTimeStr(ts int64) string {
if ts == 0 {
return ""
}
return time.Unix(ts, 0).Format(time.RFC3339)
}
func UnixToTimeStrShort(ts int64) string {
if ts == 0 {
return ""
}
return time.Unix(ts, 0).Format("2006-01-02 15:04:05")
}
// ========== 文件服务 RPC 封装 ==========
// FetchFilesByIds 通过 FileRpc 批量获取文件信息,返回 id->ImageInfo 映射
func FetchFilesByIds(ctx context.Context, svcCtx *svc.ServiceContext, ids []string) map[string]ImageInfo {
result := make(map[string]ImageInfo)
if len(ids) == 0 {
return result
}
resp, err := svcCtx.FileRpc.GetFilesByIds(ctx, &filePb.GetFilesByIdsReq{Ids: ids})
if err != nil || resp == nil {
return result
}
for _, f := range resp.Files {
result[f.Id] = ImageInfo{
ID: f.Id,
Name: f.Name,
Url: f.Url,
Tag: f.Tag,
Key: f.Key,
Suffix: f.Suffix,
MD5: f.Md5,
CreatedAt: UnixToTimeStr(f.CreatedAt),
UpdatedAt: UnixToTimeStr(f.CreatedAt),
CreatedAtStr: UnixToTimeStrShort(f.CreatedAt),
}
}
return result
}