|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- /*
-
- Copyright (c) [2023] [pcm]
- [pcm-coordinator] is licensed under Mulan PSL v2.
- You can use this software according to the terms and conditions of the Mulan PSL v2.
- You may obtain a copy of Mulan PSL v2 at:
- http://license.coscl.org.cn/MulanPSL2
- THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
- EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
- MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
- See the Mulan PSL v2 for more details.
-
- */
-
- package storelink
-
- import (
- "context"
- "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/storeLink"
- "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
- "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
- "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models"
-
- "github.com/zeromicro/go-zero/core/logx"
- )
-
- type UploadLinkImageLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
- }
-
- func NewUploadLinkImageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadLinkImageLogic {
- return &UploadLinkImageLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx,
- }
- }
-
- func (l *UploadLinkImageLogic) UploadLinkImage(req *types.UploadLinkImageReq) (resp *types.UploadLinkImageResp, err error) {
- participant := storeLink.GetParticipantById(req.PartId, l.svcCtx.DbEngin)
- if *participant == (models.StorelinkCenter{}) {
- resp = &types.UploadLinkImageResp{}
- resp.Success = false
- resp.Image = nil
- resp.ErrorMsg = "partId不存在"
- return resp, nil
- }
-
- storelink := storeLink.NewStoreLink(l.ctx, l.svcCtx, participant)
- if storelink == nil {
- return nil, nil
- }
-
- img, err := storelink.ILinkage.UploadImage(req.FilePath)
- if err != nil {
- return nil, err
- }
- if img == nil {
- return nil, storeLink.ERROR_RESP_EMPTY
- }
-
- resp = &types.UploadLinkImageResp{}
- //转换成统一返回类型
- imgResp, err := storeLink.ConvertType(img, resp, participant)
- if err != nil {
- return nil, err
- }
- if imgResp == nil {
- return nil, storeLink.ERROR_CONVERT_EMPTY
- }
-
- return imgResp.(*types.UploadLinkImageResp), nil
- }
|