package service import ( "context" "dubbo.apache.org/dubbo-go/v3/common/constant" "dubbo.apache.org/dubbo-go/v3/common/logger" v3Config "dubbo.apache.org/dubbo-go/v3/config" "encoding/json" "errors" "fmt" "github.com/fonchain_enterprise/fonchain-main/api/approval" art_show "github.com/fonchain_enterprise/fonchain-main/api/artShow" "github.com/fonchain_enterprise/fonchain-main/api/artistInfoArtwork" "github.com/fonchain_enterprise/fonchain-main/api/artistInfoUser" "github.com/fonchain_enterprise/fonchain-main/api/artwork_third_party" "github.com/fonchain_enterprise/fonchain-main/api/digital_copyright" "github.com/fonchain_enterprise/fonchain-main/api/note" "github.com/fonchain_enterprise/fonchain-main/pkg/cache" projectConf "github.com/fonchain_enterprise/fonchain-main/pkg/config" "github.com/fonchain_enterprise/fonchain-main/pkg/logic" "github.com/jinzhu/copier" "github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go/log" uuid "github.com/satori/go.uuid" "io/ioutil" "os" "path" "path/filepath" "sort" "strconv" "strings" "sync" "time" dubboV3Config "dubbo.apache.org/dubbo-go/v3/config" artShow "github.com/fonchain_enterprise/fonchain-main/api/artShow" "github.com/fonchain_enterprise/fonchain-main/api/artist" "github.com/fonchain_enterprise/fonchain-main/api/artwork" "github.com/fonchain_enterprise/fonchain-main/api/artwork_query" "github.com/fonchain_enterprise/fonchain-main/pkg/common" "github.com/fonchain_enterprise/fonchain-main/pkg/config" "github.com/fonchain_enterprise/fonchain-main/pkg/e" "github.com/fonchain_enterprise/fonchain-main/pkg/model" "github.com/fonchain_enterprise/fonchain-main/pkg/serializer" "github.com/fonchain_enterprise/fonchain-main/pkg/utils" "github.com/gin-gonic/gin" "github.com/go-playground/validator/v10" "go.uber.org/zap" "google.golang.org/protobuf/types/known/wrapperspb" ) func CreateAwProfile(c *gin.Context) { var profileRequest artwork.CreArtProRequest if err := c.ShouldBind(&profileRequest); err != nil { logger.Errorf("CreateAwProfile ShouldBind err", err) ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } // 创建来源1 后台 profileRequest.CreateSource = 1 if profileRequest.Mask == 0 { //没有传的话默认是1 profileRequest.Mask = model.MaskFirstHand } var logicArtist logic.ArtistInfo profileRequest.ArtistName = logicArtist.RecheckArtistName(profileRequest.ArtistName) if err := profileRequest.Validate(); err != nil { err = common.SubstrError(err) ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } artistInfo, err := GrpcArtistImpl.ArtistInfo(c, &artist.ArtistInfoRequest{Uid: profileRequest.ArtistUuid}) if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } var findUserResp *artistInfoUser.UserInfo if artistInfo.ProfileInfo.Insource == 3 { // 在此之前需要去画家宝判断是否锁定 var findUserReq artistInfoUser.FindUserRequest findUserReq.MgmtArtistUid = profileRequest.ArtistUuid findUserResp, err = GrpcArtistInfoUserImpl.FindUser(context.Background(), &findUserReq) if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } //新业务逻辑:其它画作(赠画、卷轴)无需同步到画家宝 by xjjXu 2023-12-14 if utils.Contains([]int32{1, 4}, profileRequest.ArtworkType) { if findUserResp.Id != 0 && !findUserResp.IsLock { ResponseQuickMsg(c, e.Failed, e.GetMsg(e.ErrorArtistNotLock), nil) return } } } nativeTrace := opentracing.GlobalTracer() span := nativeTrace.StartSpan("createArtwork") defer span.Finish() ctx := opentracing.ContextWithSpan(context.Background(), span) resp, err := GrpcArtworkImpl.CreateArtworkProfile(ctx, &profileRequest) if err != nil { ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } //在画家宝中添加画作记录,并修改画作insource字段状态为3 by xjj 2023-06-28 //新业务逻辑:其它画作(赠画、卷轴)无需同步到画家宝 by xjjXu 2023-12-14 if artistInfo.ProfileInfo.Insource == 3 && findUserResp != nil && findUserResp.Id != 0 && findUserResp.IsLock && utils.Contains([]int32{1, 4}, profileRequest.ArtworkType) { var artistInfoArtworkReq = artistInfoArtwork.CreateArtworkFromMgmtRequest{ ArtistUid: profileRequest.ArtistUuid, ArtworkUid: resp.Data.ArtworkUuid, Origin: model.CREATE_SOURCE_SYSTEM, } span = span.SetTag("CreateArtworkLockRecordFromMgmt", resp.Data.ArtworkUuid) mgmtCtx := opentracing.ContextWithSpan(context.Background(), span) _, err = GrpcArtistInfoArtworkImpl.CreateArtworkLockRecordFromMgmt(mgmtCtx, &artistInfoArtworkReq) if err != nil { ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } span = span.SetTag("UpdateInsource", resp.Data.ArtworkUuid) artworkCtx := opentracing.ContextWithSpan(context.Background(), span) _, err = GrpcArtworkImpl.UpdateInsource(artworkCtx, &artwork.UpdateInsourceReq{ ArtworkUid: resp.Data.ArtworkUuid, InSource: 3, }) if err != nil { ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } } //新业务逻辑:其它画作(赠画、卷轴)无需同步到画家宝 by xjjXu 2023-12-14 //if resp.Data.ArtworkUuid != "" && utils.Contains([]int32{1, 4}, profileRequest.ArtworkType) { // fmt.Println("同步到画家宝") // // 创建完毕通知画家宝 // record := &artistInfoArtwork.AddArtworkFlowRecordRequest{ // ArtistUid: profileRequest.ArtistUuid, // ArtworkUid: resp.Data.ArtworkUuid, // TimeStamp: time.Now().Unix(), // Pic: profileRequest.HdPic, // FlowState: artistInfoArtwork.FlowState(model.FlowState_FirstUpload), // Operator: artistInfoArtwork.Operator(model.Operator_Backend), // } // logger.Infof("record create", record) // _, _ = GrpcArtistInfoArtworkImpl.AddArtworkFlowRecord(context.Background(), record) //} ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: resp.Msg, Status: e.Ok, Data: resp.Data, }) } func UpdateAwProfile(c *gin.Context) { var profileRequest artwork.CreArtProRequest if err := c.ShouldBind(&profileRequest); err != nil { logger.Errorf("CreateAwProfile ShouldBind err", err) ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } var logicArtist logic.ArtistInfo profileRequest.ArtistName = logicArtist.RecheckArtistName(profileRequest.ArtistName) atta := make(map[string]interface{}, 2) userInfoAny, ok := c.Get("mLoginInfo") if ok { loginInfo := userInfoAny.(model.LoginInfo) loginInfo.Extend = nil loginInfo.PositionUsers = nil loginInfoByte, _ := json.Marshal(loginInfo) atta["userinfo"] = string(loginInfoByte) } reqContext := context.WithValue(context.Background(), constant.DubboCtxKey("attachment"), atta) //查询dci状态 copyrightInfo, _err := GrpcCopyrightImpl.CopyrightInfo(context.Background(), &digital_copyright.CopyrightInfoReq{ArtworkUuid: profileRequest.ArtworkUuid}) if _err != nil { ResponseQuickMsg(c, e.Failed, _err.Error(), nil) return } if copyrightInfo.DigitalRegisterId != "" { profileRequest.CopyrightStep = 1 } if copyrightInfo.Status == "DISREGARD" { profileRequest.CopyrightStep = 0 } //查询数据库的值如果变动不允许修改 if err := checkArtworkApprovalStatus(&profileRequest, model.CheckArtworkArtshowActionEdit); err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } profileRequest.SupplementEdit, _ = ArtworkSupplementEdit(profileRequest.ArtistUuid, profileRequest.ArtworkUuid) profileRequest.SystemSource = artwork.InSource_InSourceManager resp, err := GrpcArtworkImpl.UpdateArtworkProfile(reqContext, &profileRequest) if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } if len(resp.Data) > 0 { var artistUids []string = make([]string, 0, len(resp.Data)) for _, v := range resp.Data { artistUids = append(artistUids, v.ArtistUuid) v.ArtistShowCount = fmt.Sprintf("%s(0)", v.ArtistName) } artshowResp, errS := GrpcArtShowImpl.ArtistExhibitionCount(context.Background(), &artShow.ArtistExhibitionCountReq{ArtistUid: artistUids}) if errS != nil { zap.L().Error("artist ArtistExhibitionCount err", zap.Error(errS)) } if artshowResp != nil && len(artshowResp.ArtistShowCount) > 0 { for k, v := range resp.Data { for _, v1 := range artshowResp.ArtistShowCount { if v.ArtistUuid == v1.ArtistUid { resp.Data[k].ArtistShowCount = fmt.Sprintf("%s(%d)", v.ArtistName, v1.ShowCount) break } } } } } ResponseQuickMsg(c, e.Ok, resp.Msg, resp) } // 检查画作的审批状态 func checkArtworkApprovalStatus(req *artwork.CreArtProRequest, action int32) (err error) { var oldDetail *artwork.ArtworkDetailResponse = new(artwork.ArtworkDetailResponse) if action == model.CheckArtworkArtshowActionEdit { oldDetail, err = GrpcArtworkImpl.ArtworkDetail(context.Background(), &artwork.ArtworkDetailRequest{ Type: "1", ArtworkUuid: req.ArtworkUuid, }) if err != nil { return } var change bool zap.L().Info("checkArtworkApprovalStatus", zap.Any("oldDetail", oldDetail)) change = oldDetail.ProfileInfo.HdPic != req.HdPic || oldDetail.ProfileInfo.ArtworkName != req.ArtworkName || oldDetail.ProfileInfo.ArtistName != req.ArtistName || oldDetail.ProfileInfo.ArtworkType != req.ArtworkType || oldDetail.ProfileInfo.Length != req.Length || oldDetail.ProfileInfo.Width != req.Width || oldDetail.ProfileInfo.Ruler != req.Ruler if !change { return } zap.L().Info("checkArtworkApprovalStatus", zap.Any("change", change)) } if err = CheckArtworkApproval(req.ArtworkUuid); err != nil { return } return } // 画作审批状态检查 func CheckArtworkApproval(artworkUuid string) (err error) { resp, _err := ApprovalProvider.ListApprovalStatusByArtworkUID(context.Background(), &approval.ArtworkStatusReq{ArtworkUID: artworkUuid}) if _err != nil { err = _err return } zap.L().Info("checkArtworkApprovalStatus", zap.Any("resp", resp)) if resp.Status == 0 || resp.ApprovalType == "" { return } if resp.ApprovalType != model.ApprovalTypeExhibition { err = errors.New(e.ErrorArtworkEditNo) return } if resp.Status != model.ApprovalWorkStatusFail && resp.Status != model.ApprovalWorkStatusRevokeOk { err = errors.New(e.ErrorArtworkEditNo) return } return } func UpdateMarketInfo(c *gin.Context) { var pmInfoRequest artwork.UpdateMInfoRequest if err := c.ShouldBind(&pmInfoRequest); err != nil { logger.Errorf("UpdateMarketInfo ShouldBind err", err) ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } resp, err := GrpcArtworkImpl.UpdateMarketInfo(context.Background(), &pmInfoRequest) if err != nil { ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: resp.Msg, Status: e.Ok, }) } func UpdateExtInfo(c *gin.Context) { var extDataRequest artwork.UpdateExtDataRequest if err := c.ShouldBind(&extDataRequest); err != nil { logger.Errorf("UpdateExtInfo ShouldBind err", err) ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } //查询dci状态 copyrightInfo, _err := GrpcCopyrightImpl.CopyrightInfo(context.Background(), &digital_copyright.CopyrightInfoReq{ArtworkUuid: extDataRequest.ArtworkUuid}) if _err != nil { ResponseQuickMsg(c, e.Failed, _err.Error(), nil) return } if copyrightInfo.DigitalRegisterId != "" { extDataRequest.CopyrightStep = 1 } if copyrightInfo.Status == "DISREGARD" { extDataRequest.CopyrightStep = 0 } resp, err := GrpcArtworkImpl.UpdateExtData(context.Background(), &extDataRequest) if err != nil { ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: resp.Msg, Status: e.Ok, }) } func DigiInfo(c *gin.Context) { var digiRequest artwork.UpdateDigiInfoRequest if err := c.ShouldBind(&digiRequest); err != nil { logger.Errorf("DigiInfo ShouldBind err", err) ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } resp, err := GrpcArtworkImpl.UpdateDigiInfo(context.Background(), &digiRequest) if err != nil { ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: resp.Msg, Status: e.Ok, }) } func AwTags(c *gin.Context) { var tagsRequest artwork.UpdateTagsRequest if err := c.ShouldBind(&tagsRequest); err != nil { logger.Errorf("DigiInfo ShouldBind err", err) ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } resp, err := GrpcArtworkImpl.UpdateTags(context.Background(), &tagsRequest) if err != nil { ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: resp.Msg, Status: e.Ok, }) } func AuthData(c *gin.Context) { var authDataRequest artwork.UpdateAuthDataRequest if err := c.ShouldBind(&authDataRequest); err != nil { logger.Errorf("AuthData ShouldBind err", err) ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } resp, err := GrpcArtworkImpl.UpdateAuthData(context.Background(), &authDataRequest) if err != nil { ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: resp.Msg, Status: e.Ok, }) } func VerifyData(c *gin.Context) { var verifyDataRequest artwork.UpdateVerifyDataReq if err := c.ShouldBind(&verifyDataRequest); err != nil { logger.Errorf("verifyData ShouldBind err", err) ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } resp, err := GrpcArtworkImpl.UpdateVerifyData(context.Background(), &verifyDataRequest) if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } ResponseQuickMsg(c, e.Ok, resp.Msg, nil) } func AuthImg(c *gin.Context) { var authDataRequest artwork.UpdateAuthImgRequest if err := c.ShouldBind(&authDataRequest); err != nil { logger.Errorf("AuthImg ShouldBind err", err) ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } if authDataRequest.Action == "" { //默认更新首张图片 authDataRequest.Action = model.AuthImgActionFirst } if authDataRequest.Action == model.AuthImgActionMore { if mLoginInfoAny, exists := c.Get("mLoginInfo"); exists { userInfo := mLoginInfoAny.(model.LoginInfo) authDataRequest.AdminId = int32(userInfo.ID) } } if err := authDataRequest.Validate(); err != nil { err = common.SubstrError(err) ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } resp, err := GrpcArtworkImpl.UpdateAuthImg(context.Background(), &authDataRequest) if err != nil { ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: resp.Msg, Status: e.Ok, }) } func Storage(c *gin.Context) { var storageRequest artwork.UpdateStorageRequest if err := c.ShouldBind(&storageRequest); err != nil { logger.Errorf("Storage ShouldBind err", err) ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } if err := storageRequest.Validate(); err != nil { err = common.SubstrError(err) ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } nativeTrace := opentracing.GlobalTracer() span := nativeTrace.StartSpan("storageStart") var detailCtx context.Context defer span.Finish() // 如果是入库则查询画家信息 1 入库 if storageRequest.Type == 1 { span.LogFields( log.String("event", "storage"), log.String("value", storageRequest.ArtworkUuid), ) var artworkDetailReq artwork.ArtworkDetailRequest artworkDetailReq.ArtworkUuid = storageRequest.ArtworkUuid artworkDetailReq.Type = "1" detailCtx = opentracing.ContextWithSpan(context.Background(), span) awDetailInfo, err := GrpcArtworkImpl.ArtworkDetail(detailCtx, &artworkDetailReq) if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } span.SetTag("storage-detail", "200") var artistInfoReq artist.ArtistInfoRequest artistInfoReq.Uid = awDetailInfo.ProfileInfo.ArtistUuid artistInfo, err := GrpcArtistImpl.ArtistInfo(detailCtx, &artistInfoReq) if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } storageRequest.ArtistData = &artwork.UpdateStorageRequest_ArtistInfo{} storageRequest.ArtistData.ArtistUuid = artistInfo.ProfileInfo.Uid storageRequest.ArtistData.Seqnum = artistInfo.ProfileInfo.Seqnum storageRequest.ArtistData.Tnum = artistInfo.ProfileInfo.Tnum storageRequest.ArtistData.Num = artistInfo.ProfileInfo.Num } span.SetTag("storage-update-storage", storageRequest.ArtworkUuid) if detailCtx == nil { detailCtx = opentracing.ContextWithSpan(context.Background(), span) } resp, err := GrpcArtworkImpl.UpdateStorage(detailCtx, &storageRequest) if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } ResponseQuickMsg(c, e.Ok, resp.Msg, resp) } func AwDetail(c *gin.Context) { var detailRequest artwork.ArtworkDetailRequest if err := c.ShouldBind(&detailRequest); err != nil { logger.Errorf("AwDetail ShouldBind err", err) ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } zap.L().Info("AwDetail", zap.Any("detailRequest1", detailRequest.ArtworkUuid)) if err := detailRequest.Validate(); err != nil { err = common.SubstrError(err) ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } resp, err := GrpcArtworkImpl.ArtworkDetail(context.Background(), &detailRequest) if err != nil { ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } zap.L().Info("AwDetail", zap.Any("detailRequest2", detailRequest.ArtworkUuid)) ok := dubboV3Config.GetConsumerService("CopyrightClientImpl") != nil if ok { if resp.CopyRightInfo == nil { resp.CopyRightInfo = &artwork.UpdateCopyrightInfoRequest{} } copyrightResp, _err := GrpcCopyrightImpl.CopyrightDetail(context.Background(), &digital_copyright.CopyrightDetailReq{ArtworkUuid: detailRequest.ArtworkUuid}) if _err == nil { if copyrightResp.BaseInfo.DigitalRegisterId != "" && resp.ProfileInfo != nil { resp.ProfileInfo.CopyrightStep = 1 } //if _err != nil { // ResponseQuickMsg(c, e.Failed, _err.Error(), nil) // return //} if copyrightResp.BaseInfo != nil && copyrightResp.BaseInfo.RegNumber != "" && resp.CopyRightInfo != nil { resp.CopyRightInfo.SerialNumber = copyrightResp.BaseInfo.CopyrightId resp.CopyRightInfo.ApplyTime = copyrightResp.ApplyInfo.ApplyTime resp.CopyRightInfo.RegisterNumber = copyrightResp.BaseInfo.RegNumber resp.CopyRightInfo.CertDigi = copyrightResp.BaseInfo.DigitalRegisterCertUrl resp.CopyRightInfo.CertRegisterTime = copyrightResp.BaseInfo.DigitalRegisterCompletionDate // 数登完成时间 resp.CopyRightInfo.EntrustLetterUrl = copyrightResp.WorkInfo.OthersWorkAuthFileId } } } // 基础信息里面的定价数据 要去画展包那边查询 if config.Env != "dev" { zap.L().Info("AwDetail", zap.Any("detailRequest3", detailRequest.ArtworkUuid)) if strings.Contains(detailRequest.Type, fmt.Sprintf("%d", model.ADTypeProfile)) { var artworkPriceReq artShow.ArtworkPriceReq artworkPriceReq.ArtworkUID = detailRequest.ArtworkUuid artworkPriceRes, err := GrpcArtShowImpl.ArtworkPrice(context.Background(), &artworkPriceReq) //if err != nil { // ResponseQuickMsg(c, e.Failed, err.Error(), nil) // return //} zap.L().Info("AwDetail", zap.Any("detailRequest4", detailRequest.ArtworkUuid)) if err == nil && artworkPriceRes != nil && artworkPriceRes.Data != nil { resp.ProfileInfo.PriceMarket = float32(artworkPriceRes.Data.MarketPrice) resp.ProfileInfo.PriceRuler = float32(artworkPriceRes.Data.RulerPrice) resp.ProfileInfo.PriceArtwork = float32(artworkPriceRes.Data.ArtworkPrice) resp.ProfileInfo.PriceCopyright = float32(artworkPriceRes.Data.CopyrightPrice) } zap.L().Info("AwDetail", zap.Any("detailRequest5", detailRequest.ArtworkUuid)) } } zap.L().Info("AwDetail", zap.Any("detailRequest6", detailRequest.ArtworkUuid)) if len(resp.MarketInfo) == 0 { resp.MarketInfo = []*artwork.UpdateMInfoRequest{} } if resp.AuthData != nil && len(resp.AuthData.Data) == 0 { resp.AuthData.Data = []*artwork.UpdateAuthDataRequest_BitMap{} } if len(resp.TagsData) == 0 { resp.TagsData = []*artwork.ArtworkDetailResponse_TagsInfo{} } //if resp.DigiInfo != nil && resp.DigiInfo.DigiArtCopyrightImg != "" { // resp.DigiInfo.DigiArtCopyrightImg = fmt.Sprintf("%s%s", config.ProjectMapDir, resp.DigiInfo.DigiArtCopyrightImg[1:]) //} if strings.Contains(detailRequest.Type, "6") { if resp.AuthData != nil && len(resp.AuthData.AuthImgData) == 0 { resp.AuthData.AuthImgData = []*artwork.AuthImgInfo{} } } if resp.ProfileInfo != nil { resp.ProfileInfo.SupplementEdit, _ = ArtworkSupplementEdit(resp.ProfileInfo.ArtistUuid, resp.ProfileInfo.ArtworkUuid) } ResponseQuickMsg(c, e.Ok, resp.Msg, resp) } func StorageInfo(c *gin.Context) { var infoRequest artwork.StorageInfoRequest if err := c.ShouldBind(&infoRequest); err != nil { logger.Errorf("StorageInfo ShouldBind err", err) ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } resp, err := GrpcArtworkImpl.StorageInfo(context.Background(), &infoRequest) if err != nil { ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } if len(resp.StorageData) == 0 { resp.StorageData = []*artwork.UpdateStorageRequest{} } ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: resp.Msg, Status: e.Ok, Data: resp.StorageData, }) } func MarketInfo(c *gin.Context) { var infoRequest artwork.MarketInfoRequest if err := c.ShouldBind(&infoRequest); err != nil { logger.Errorf("MarketInfo ShouldBind err", err) ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } resp, err := GrpcArtworkImpl.MarketInfo(context.Background(), &infoRequest) if err != nil { ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } if len(resp.MarketInfo) == 0 { resp.MarketInfo = []*artwork.UpdateMInfoRequest{} } ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: resp.Msg, Status: e.Ok, Data: resp.MarketInfo, }) } func AwList(c *gin.Context) { var detailRequest artwork_query.ArtworkListRequest var awReq model.AwListReq if err := c.ShouldBind(&awReq); err != nil { logger.Errorf("AwDetail ShouldBind err", err) ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } if err := copier.Copy(&detailRequest, awReq); err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } // 留言板不为空查询留言板数据 if awReq.NoteKeyword != "" { noteResp, err := GrpcNoteImpl.NoteList(context.Background(), ¬e.NoteListreq{ Page: 1, PageSize: 9999, Keyword: awReq.NoteKeyword, }) if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } for _, v := range noteResp.Data { detailRequest.ArtworkUuids = append(detailRequest.ArtworkUuids, v.ArtworkUuid) } if len(detailRequest.ArtworkUuids) == 0 { detailRequest.ArtworkUuids = append(detailRequest.ArtworkUuids, awReq.NoteKeyword) } } if awReq.FilterStatus == nil { detailRequest.FilterStatus = nil } else { detailRequest.FilterStatus = &wrapperspb.Int32Value{Value: *awReq.FilterStatus} } if awReq.StorageStatus == nil { detailRequest.StorageStatus = nil } else { detailRequest.StorageStatus = &wrapperspb.Int32Value{Value: *awReq.StorageStatus} } if awReq.SaleStatus == nil { detailRequest.SaleStatus = nil } else { detailRequest.SaleStatus = &wrapperspb.Int32Value{Value: *awReq.SaleStatus} } resp, err := GrpcArtworkQueryImpl.ArtworkList(context.Background(), &detailRequest) if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), resp) return } if len(resp.Data) == 0 { resp.Data = []*artwork_query.ArtworkListResponse_Info{} } for _, v := range resp.Data { if v.BlackListStatus == 2 { v.ArtistName = fmt.Sprintf("#%s", v.ArtistName) } } if len(resp.Data) > 0 && len(resp.Data) <= 50 && v3Config.GetConsumerService("ArtShowClientImpl") != nil { var artistUids []string = make([]string, 0, len(resp.Data)) for k, v := range resp.Data { artistUids = append(artistUids, v.ArtistUuid) resp.Data[k].ArtistShowCount = fmt.Sprintf("%s(0)", v.ArtistName) } artshowResp, _err := GrpcArtShowImpl.ArtistExhibitionCount(c, &artShow.ArtistExhibitionCountReq{ArtistUid: artistUids}) if _err != nil { zap.L().Error("artist ArtistExhibitionCount err", zap.Error(err)) } if artshowResp != nil && len(artshowResp.ArtistShowCount) > 0 { for k, v := range resp.Data { for _, v1 := range artshowResp.ArtistShowCount { if v.ArtistUuid == v1.ArtistUid { resp.Data[k].ArtistShowCount = fmt.Sprintf("%s(%d)", v.ArtistName, v1.ShowCount) break } } } } } ResponseQuickMsg(c, e.Ok, resp.Msg, resp) } func AwTagList(c *gin.Context) { var tagListRequest artwork_query.TagsListRequest if err := c.ShouldBind(&tagListRequest); err != nil { logger.Errorf("AwDetail ShouldBind err", err) ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } resp, err := GrpcArtworkQueryImpl.TagsList(context.Background(), &tagListRequest) if err != nil { ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: resp.Msg, Status: e.Ok, Data: resp, }) } func DelAuthData(c *gin.Context) { var delAuthRequest artwork_query.DelAuthDataRequest if err := c.ShouldBind(&delAuthRequest); err != nil { logger.Errorf("DelAuthData ShouldBind err", err) ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } resp, err := GrpcArtworkQueryImpl.DelAuthData(context.Background(), &delAuthRequest) if err != nil { ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: resp.Msg, Status: e.Ok, }) } func DelMarketData(c *gin.Context) { var delMarketRequest artwork_query.DelMarketDataRequest if err := c.ShouldBind(&delMarketRequest); err != nil { logger.Errorf("DelMarketData ShouldBind err", err) ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } resp, err := GrpcArtworkQueryImpl.DelMarketData(context.Background(), &delMarketRequest) if err != nil { ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: resp.Msg, Status: e.Ok, }) } func DelStorageData(c *gin.Context) { var delStorageRequest artwork_query.DelStorageDataRequest if err := c.ShouldBind(&delStorageRequest); err != nil { logger.Errorf("DelStorageData ShouldBind err", err) ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } resp, err := GrpcArtworkQueryImpl.DelStorageData(context.Background(), &delStorageRequest) if err != nil { ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: resp.Msg, Status: e.Ok, }) } func RandomHash(c *gin.Context) { var delStorageRequest artwork.RandomHashRequest resp, err := GrpcArtworkImpl.RandomHash(context.Background(), &delStorageRequest) if err != nil { ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: resp.Msg, Status: e.Ok, Data: resp.Hash, }) } func DelAwProfile(c *gin.Context) { var delAwRequest artwork_query.DelAwRequest if err := c.ShouldBind(&delAwRequest); err != nil { logger.Errorf("DelAwProfile ShouldBind err", err) ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } var profileRequest artwork.CreArtProRequest profileRequest.ArtworkUuid = delAwRequest.ArtworkUuid if err := checkArtworkApprovalStatus(&profileRequest, model.CheckArtworkArtshowActionDel); err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } resp, err := GrpcArtworkQueryImpl.DelArtwork(context.Background(), &delAwRequest) if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } _, _ = GrpcArtShowImpl.SyncArtworkDel(context.Background(), &art_show.SyncArtworkDelReq{ArtworkUid: delAwRequest.ArtworkUuid}) ResponseQuickMsg(c, e.Ok, resp.Msg, nil) } func CatList(c *gin.Context) { var tagListRequest artwork_query.CatListRequest if err := c.ShouldBind(&tagListRequest); err != nil { logger.Errorf("CatList ShouldBind err", err) ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } resp, err := GrpcArtworkQueryImpl.CatList(context.Background(), &tagListRequest) if err != nil { ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: resp.Msg, Status: e.Ok, Data: resp.Data, }) } // UpdateThirdParty 更新第三方评论 func UpdateThirdParty(c *gin.Context) { var req artwork_query.UpdateThirdPartyRequest if err := c.ShouldBind(&req); err != nil { logger.Errorf("UpdateThirdParty ShouldBind err", err) ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } resp, err := GrpcArtworkQueryImpl.UpdateThirdParty(context.Background(), &req) if err != nil { ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: resp.Msg, Status: e.Ok, }) return } // DelThirdParty 删除第三方评论 func DelThirdParty(c *gin.Context) { var req artwork_query.DelThirdPartyRequest if err := c.ShouldBind(&req); err != nil { logger.Errorf("DelThirdParty ShouldBind err", err) ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } resp, err := GrpcArtworkQueryImpl.DelThirdParty(context.Background(), &req) if err != nil { ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: resp.Msg, Status: e.Ok, }) return } func ThirdPartyList(c *gin.Context) { var req artwork_query.ThirdPartyListRequest if err := c.ShouldBind(&req); err != nil { logger.Errorf("ThirdPartyList ShouldBind err", err) ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } resp, err := GrpcArtworkQueryImpl.ThirdPartyList(context.Background(), &req) if err != nil { ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: err.Error(), Status: e.Failed, }) return } if len(resp.Data) == 0 { resp.Data = []string{} } ResponseMsg(c, e.SUCCESS, serializer.Response{ Msg: resp.Msg, Status: e.Ok, Data: resp.Data, }) } // GetFileChunkInfo 获取文件分块信息 func GetFileChunkInfo(c *gin.Context) { var chunkInfo model.GetChunkInfo var err error data := &model.UploadChunkResp{ FullFileUrl: "", FileName: "", ChunkList: []string{}, } if err = c.BindJSON(&chunkInfo); err != nil { errs, _ := err.(validator.ValidationErrors) msgMap := utils.RemoveTopStruct(errs.Translate(utils.Trans)) var msg string for _, v := range msgMap { msg += v + ";" } ResponseQuickMsg(c, e.Failed, msg, data) return } //批量上传去掉版权图 if chunkInfo.UseType == 5 { ResponseQuickMsg(c, e.Failed, e.GetMsg(e.ERROR_COPYRIGHT_CHUNK), nil) return } var artworkId int32 var artworkUuid string fileSuffix := path.Ext(chunkInfo.FileName) prefix := strings.TrimSuffix(chunkInfo.FileName, fileSuffix) artworkInfo, err := checkArtworkTfnum(prefix) if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), data) return } artworkId = artworkInfo.ArtworkId artworkUuid = artworkInfo.ArtworkUuid /*var uuid uuid4.UUID if uuid, err = uuid4.NewV4(); err != nil { err = errors.New(e.GetMsg(e.ERROR_UID)) return }*/ var newFileName string = fmt.Sprintf("%s%s", artworkUuid, path.Ext(chunkInfo.FileName)) chunkPath := fmt.Sprintf("%v/%v/%v/%v", ArtworkChunkBasePath, chunkInfo.UseType, prefix, chunkInfo.FileMd5) //newDst := fmt.Sprintf("%v/%v/%v/%s", ArtworkChunkBasePath, chunkInfo.UseType, prefix, chunkInfo.FileName) fullFileDir := fmt.Sprintf("%s%s/%v/%d", MediaPath, ArtworkFilePath, chunkInfo.UseType, artworkId) fullFileAPath := fmt.Sprintf("%s/%s", fullFileDir, newFileName) var fileExists bool fileExists, err = utils.CheckDirPath(chunkPath, false) if err != nil { logger.Error("GetFileChunkInfo checkChunk err", zap.Error(err)) ResponseQuickMsg(c, e.Failed, e.GetMsg(e.ErrorFileReadErr), data) return } if !fileExists { ResponseQuickMsg(c, e.Failed, e.GetMsg(e.ErrorFileNotExists), data) return } _, err = utils.CheckDirPath(fullFileDir, true) resp, err := checkChunk(c, model.CheckChunkInfo{ Total: chunkInfo.Total, ChunkPath: chunkPath, NewDst: fullFileAPath, UseType: chunkInfo.UseType, FileName: chunkInfo.FileName, MediaType: "", }) if err != nil { logger.Error("GetFileChunkInfo checkChunk err", zap.Error(err)) ResponseQuickMsg(c, e.Failed, err.Error(), data) return } var msg string msg = e.GetMsg(e.SUCCESS) if resp.FullFileUrl != "" { // 提交到微服务进行更新 msg, err = imgMatchUpdate(int32(chunkInfo.UseType), artworkUuid, resp.FullFileUrl, fullFileAPath, prefix) if err != nil { ResponseQuickMsg(c, e.Ok, msg, resp) return } } resp.FileName = chunkInfo.FileName ResponseQuickMsg(c, e.Ok, e.GetMsg(e.SUCCESS), resp) } // UploadChunk 分块上传 func UploadChunk(c *gin.Context) { data := &model.UploadChunkResp{ FullFileUrl: "", CoverUrl: "", FileName: "", ChunkList: []string{}, } var uploadInfo = new(model.UploadChunk) zap.L().Info("UploadChunk 1") if err := c.Bind(uploadInfo); err != nil { errs, _ := err.(validator.ValidationErrors) msgMap := utils.RemoveTopStruct(errs.Translate(utils.Trans)) var msg string for _, v := range msgMap { msg += v + ";" msg += v + ";" } ResponseQuickMsg(c, e.Ok, msg, nil) return } zap.L().Info("UploadChunk 2", zap.Any("uploadInfo", uploadInfo.FileName)) //批量上传去掉版权图 if uploadInfo.UseType == 5 { ResponseQuickMsg(c, e.Failed, e.GetMsg(e.ERROR_COPYRIGHT_CHUNK), nil) return } file, err := c.FormFile("Chunk") if int32(uploadInfo.UseType) == model.BitmapImg && path.Ext(uploadInfo.FileName) != ".zip" { ResponseQuickMsg(c, e.Failed, e.GetMsg(e.ERROR_NOT_ZIP), nil) return } if err != nil { logger.Error("UploadChunk FormFile err", err) ResponseQuickMsg(c, e.Failed, e.GetMsg(e.ErrorChunk), data) return } var artworkId int32 var artworkUuid, fullFileDir, newScreenHotName, tempDir string /*var uuid uuid4.UUID if uuid, err = uuid4.NewV4(); err != nil { err = errors.New(e.GetMsg(e.ERROR_UID)) return }*/ zap.L().Info("UploadChunk 3", zap.Any("uploadInfo", uploadInfo.FileName)) //检测画作名字 prefix := strings.TrimSuffix(uploadInfo.FileName, path.Ext(uploadInfo.FileName)) fmt.Println(path.Ext(uploadInfo.FileName)) var artworkInfo model.ArtworkInfo if uploadInfo.UseType != model.UseTypeOther { artworkInfo, err = checkArtworkTfnum(prefix) } else { artworkId = int32(time.Now().Unix()) artworkUuid = fmt.Sprintf("%d", artworkId) } if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), data) return } artworkId = artworkInfo.ArtworkId artworkUuid = artworkInfo.ArtworkUuid var newFileName string = fmt.Sprintf("%s%s", artworkUuid, path.Ext(uploadInfo.FileName)) //分块保存位置 chunkPath := fmt.Sprintf("%v/%v/%v/%v", ArtworkChunkBasePath, uploadInfo.UseType, prefix, uploadInfo.FileMd5) uploadInfo.Source = strings.Trim(uploadInfo.Source, "/") if uploadInfo.Type == "" { uploadInfo.Type = "image" } if uploadInfo.UseType == model.UseTypeOther { if uploadInfo.Mask == "" { newUuid, _ := uuid.NewV4() uploadInfo.Mask = newUuid.String() } newUuid, _ := uuid.NewV4() newScreenHotName = newUuid.String() } if uploadInfo.Mask != "" { uploadInfo.Mask = fmt.Sprintf("/%s", uploadInfo.Mask) } zap.L().Info("UploadChunk 4", zap.Any("uploadInfo", uploadInfo.FileName)) //完整文件路径 if uploadInfo.Source == "" { fullFileDir = fmt.Sprintf("%s%s%s/%s/%v/%d", MediaPath, ArtworkFilePath, uploadInfo.Mask, uploadInfo.Type, uploadInfo.UseType, artworkId) } else { tempDir = fmt.Sprintf("%s%s%s", MediaPath, uploadInfo.Source, uploadInfo.Mask) fullFileDir = fmt.Sprintf("%s/%s/%v/%d", tempDir, uploadInfo.Type, uploadInfo.UseType, artworkId) } fullFileAPath := fmt.Sprintf("%s/%s", fullFileDir, newFileName) // 创建文件夹路径 zap.L().Info("UploadChunk 5", zap.Any("uploadInfo", uploadInfo.FileName)) _, err = utils.CheckDirPath(chunkPath, true) if err != nil { zap.L().Error("UploadChunk CheckDirPath err", zap.Error(err)) ResponseMsg(c, e.SUCCESS, serializer.Response{ Status: e.Failed, Data: data, Msg: e.GetMsg(e.ErrorFileReadErr), }) return } zap.L().Info("UploadChunk 6", zap.Any("uploadInfo", uploadInfo.FileName)) a := chunkPath + "/" + uploadInfo.ChunkFileName err = c.SaveUploadedFile(file, a) zap.L().Info("UploadChunk 7", zap.Any("uploadInfo", uploadInfo.FileName)) if err != nil { zap.L().Error("UploadChunk SaveUploadedFile err", zap.Error(err)) ResponseMsg(c, e.SUCCESS, serializer.Response{ Status: e.Failed, Data: data, Msg: err.Error(), }) return } zap.L().Info("UploadChunk 8", zap.Any("uploadInfo", uploadInfo.FileName)) _, err = utils.CheckDirPath(fullFileDir, true) resp, err := checkChunk(c, model.CheckChunkInfo{ Total: uploadInfo.Total, ChunkPath: chunkPath, NewDst: fullFileAPath, UseType: int32(uploadInfo.UseType), FileName: uploadInfo.FileName, MediaType: uploadInfo.Type, FullFileDir: fullFileDir, NewScreenHotName: newScreenHotName, TempDir: tempDir, }) zap.L().Info("UploadChunk 9", zap.Any("uploadInfo", uploadInfo.FileName)) if err != nil { ResponseMsg(c, e.SUCCESS, serializer.Response{ Status: e.Failed, Data: data, Msg: err.Error(), }) return } var msg string msg = e.GetMsg(e.SUCCESS) if resp.FullFileUrl != "" { msg, err = imgMatchUpdate(int32(uploadInfo.UseType), artworkUuid, resp.FullFileUrl, fullFileAPath, prefix) if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), resp) return } } resp.FileName = uploadInfo.FileName ResponseQuickMsg(c, e.Ok, msg, resp) } func checkChunk(c *gin.Context, checkChunkInfo model.CheckChunkInfo) (resp *model.UploadChunkResp, err error) { resp = &model.UploadChunkResp{} files, err := os.ReadDir(checkChunkInfo.ChunkPath) if err != nil { return } logger.Errorf("UploadChunk 8.1", checkChunkInfo.FileName) // 判断当前是否全部分块已经齐全 if len(files) == checkChunkInfo.Total { // 进行合并 if err = MergeChunk(checkChunkInfo.ChunkPath, checkChunkInfo.NewDst, checkChunkInfo.FileName); err != nil { zap.L().Error("checkChunk MergeChunk err", zap.Error(err)) return } logger.Errorf("UploadChunk 8.4", checkChunkInfo.FileName) // 如果是视频截取封面 if checkChunkInfo.UseType == model.UseTypeOther { logger.Errorf("UploadChunk 8.5", checkChunkInfo.FileName) if checkChunkInfo.MediaType == model.MediaTypeVideo { videoCover := fmt.Sprintf("%s/%s", checkChunkInfo.FullFileDir, checkChunkInfo.NewScreenHotName) _, err = GetSnapshot(checkChunkInfo.NewDst, videoCover, 1) if err != nil { return } //data["cover_url"] = fmt.Sprintf("%s/%s/%s/%s/%s", config.ServerDM, BaseRoute, source, mask, fmt.Sprintf("%s.%s", filename, PngType)) coverUrl, errS := PutBos(videoCover+"."+PngType, model.MediaTypeImage, true) logger.Errorf("UploadChunk 8.6", checkChunkInfo.FileName) resp.CoverUrl = coverUrl if errS != nil { logger.Errorf("Upload GetSnapshot err", zap.Error(errS)) err = errS //ResponseQuickMsg(c, e.Failed, errS.Error(), nil) return } //ResponseQuickMsg(c, e.Ok, e.GetMsg(e.SUCCESS), data) //return } } if checkChunkInfo.UseType != model.BitmapImg { //点位图在此不上传 //合并成功 上传文件 resp.FullFileUrl, err = PutBos(checkChunkInfo.NewDst, "image", true) } else if checkChunkInfo.UseType == model.BitmapImg { resp.FullFileUrl = checkChunkInfo.NewDst } // 清除临时文件 if err = os.RemoveAll(checkChunkInfo.ChunkPath); err != nil { zap.L().Error("checkChunk RemoveAll err", zap.Error(err)) return } if checkChunkInfo.TempDir != "" { _ = os.RemoveAll(checkChunkInfo.TempDir) } logger.Errorf("UploadChunk 8.7", checkChunkInfo.FileName) //if mediaType == VideoType { // videoCover := fmt.Sprintf("%s/%s", imgPath, filename) // _, err = GetSnapshot(dst, videoCover, 1) // //data["cover_url"] = fmt.Sprintf("%s/%s/%s/%s/%s", config.ServerDM, BaseRoute, source, mask, fmt.Sprintf("%s.%s", filename, PngType)) // coverUrl, err := PutBos(videoCover+"."+PngType, mediaType, true) // data["cover_url"] = coverUrl // if err != nil { // logger.Errorf("Upload GetSnapshot err", zap.Error(err)) // ResponseQuickMsg(c, e.Failed, err.Error(), nil) // return // } // //ResponseQuickMsg(c, e.Ok, e.GetMsg(e.SUCCESS), data) // //return //} } for _, f := range files { resp.ChunkList = append(resp.ChunkList, f.Name()) } return } // MergeChunk 合并文件块 func MergeChunk(chunkDst string, newDst string, fileName string) (err error) { completeFile, err := os.Create(newDst) if err != nil { logger.Errorf("MergeChunk err %s", err.Error()) err = errors.New(e.GetMsg(e.ErrorFileCreate)) return } defer completeFile.Close() files, err := os.ReadDir(chunkDst) if err != nil { logger.Errorf("MergeChunk ReadFile1 err %s", err.Error()) err = errors.New(e.GetMsg(e.ErrorFileReadErr)) return } sort.Slice(files, func(i, j int) bool { fileNumI, _ := strconv.Atoi(files[i].Name()[strings.LastIndex(files[i].Name(), "_")+1:]) fileNumJ, _ := strconv.Atoi(files[j].Name()[strings.LastIndex(files[j].Name(), "_")+1:]) return fileNumI < fileNumJ }) //var fileSlice []string //for _, f := range files { // fileSlice = append(fileSlice, f.Name()) //} //sort.Strings(fileSlice[:]) logger.Errorf("UploadChunk 8.2 %s", fileName) //var blobName string for _, file := range files { //blobName = fmt.Sprintf("%s/%s/%s", chunkDst, "/", f.Name()) /*var fName = fmt.Sprintf("%s_%v", fileName, k) blobName = fmt.Sprintf("%s/%s", chunkDst, fName) fileBuf, errS := os.ReadFile(blobName) if errS != nil { logger.Errorf("MergeChunk ReadFile2 err %s", err.Error()) err = errors.New(e.GetMsg(e.ErrorFileReadErr)) return } _, _ = completeFile.Write(fileBuf)*/ fName := filepath.Join(chunkDst, file.Name()) fileBuf, _err := os.ReadFile(fName) if _err != nil { err = errors.New(e.GetMsg(e.ErrorFileReadErr)) return } if len(fileBuf) > 0 { _, _ = completeFile.Write(fileBuf) } } logger.Errorf("UploadChunk 8.3 %s", fileName) return } // imgMatchUpdate 根据画作名更新画作 func imgMatchUpdate(useType int32, artworkUuid string, imgUrl string, fullFileAPath string, artworkName string) (msg string, err error) { if useType == model.UseTypeOther { return } var bitNameStr string = ",bitmap,60,200,600,2000," if useType == model.BitmapImg { // 如果是点位图需要校验数据 //解压zip filePath := fmt.Sprintf("%s/%s", model.TmpArtworkDir, artworkName) _ = os.RemoveAll(filePath) if err = utils.Unzip(fullFileAPath, filePath); err != nil { return } var imgMap = make(map[string][]string, 5) _ = os.Remove(fullFileAPath) err = getDirRecur(filePath, &imgMap, "") if len(imgMap) == 0 { err = errors.New(e.GetMsg(e.ERROR_EMPTY_ZIP)) return } var imgOssUrl string //var ossImgMap = make([]map[string]interface{}, 0, 20) var wg sync.WaitGroup wg.Add(1) var req artwork_query.BatchBitMapRequest req.ArtworkUuid = artworkUuid go func() { defer wg.Done() for bitName, bitFileSlice := range imgMap { if !strings.Contains(bitNameStr, fmt.Sprintf(",%s,", bitName)) { continue } if len(bitFileSlice) > 0 { // 遍历获取文件名 var fileSlice []string var fileMap map[string]int = make(map[string]int, len(bitFileSlice)) for _, v := range bitFileSlice { fileSlice = append(fileSlice, v) } sort.Strings(fileSlice[:]) for k, v := range fileSlice { fileMap[v] = k + 1 } for _, v := range bitFileSlice { imgPath := fmt.Sprintf("%s/%s/%s", filePath, bitName, v) ossPath := fmt.Sprintf("/artwork/%s/bitmap/%s/%s", artworkUuid, bitName, v) imgOssUrl, err = PutBosWithName(imgPath, true, ossPath) //bitIndex := v[0:strings.LastIndex(v, ".")] bitIndex := fileMap[v] var temp artwork_query.BatchBitMapRequest_BitInfo temp.BitIndex = fmt.Sprintf("%v", bitIndex) temp.BitName = bitName temp.ImgOssUrl = imgOssUrl req.BitData = append(req.BitData, &temp) //ossImgMap = append(ossImgMap, map[string]interface{}{ // "bitIndex": bitIndex, // "bitName": bitName, // "imgOssUrl": imgOssUrl, //}) } } } }() wg.Wait() _ = os.RemoveAll(filePath) resp, errS := GrpcArtworkQueryImpl.BatchBitMap(context.Background(), &req) msg = resp.Msg if errS != nil { err = errS return } } else { req := artwork_query.ImgMatchRequest{ //ArtworkName: artworkName, ArtworkUuid: artworkUuid, ImgUrl: imgUrl, UseType: useType, } resp, errS := GrpcArtworkQueryImpl.ImgMatchByUuid(context.Background(), &req) msg = resp.Msg if errS != nil { err = errS return } } return } func getDirRecur(filePath string, imgMap *map[string][]string, parentDir string) (err error) { var fileInfo []os.FileInfo if fileInfo, err = ioutil.ReadDir(filePath); err != nil { logger.Errorf("getDirRecur 01", zap.Error(err)) return } for _, file := range fileInfo { if file.IsDir() { pathDir := filepath.Join(filePath, file.Name()) if err = getDirRecur(pathDir, imgMap, file.Name()); err != nil { logger.Errorf("getDirRecur 02", zap.Error(err)) return } } else { (*imgMap)[parentDir] = append((*imgMap)[parentDir], file.Name()) } } return } // checkArtworkName 检查画作名字 func checkArtworkName(artworkName string) (artworkId int32, artworkUuid string, err error) { var req artwork_query.CheckArtworkNameRequest var resp *artwork_query.CheckArtworkNameResponse req.ArtworkName = artworkName resp, err = GrpcArtworkQueryImpl.CheckArtworkName(context.Background(), &req) if err != nil { return } artworkId = resp.ArtworkId artworkUuid = resp.ArtworkUuid return } // checkArtworkTfnum 检查画作tfnum func checkArtworkTfnum(Tfnum string) (info model.ArtworkInfo, err error) { var req artwork_query.CheckArtworkTfnumRequest var resp *artwork_query.CheckArtworkTfnumResponse req.Tfnum = Tfnum resp, err = GrpcArtworkQueryImpl.CheckArtworkTfnum(context.Background(), &req) if err != nil { return } info.ArtworkId = resp.ArtworkId info.ArtworkUuid = resp.ArtworkUuid return } // GetArtistInfoBYAwUuid 根据画作ID 获取画家信息 func GetArtistInfoBYAwUuid(artistUuid string) (artistInfo *artist.ArtistInfoResponse, err error) { artistInfo = &artist.ArtistInfoResponse{} var artworkDetailReq artwork.ArtworkDetailRequest artworkDetailReq.ArtworkUuid = artistUuid artworkDetailReq.Type = "1" awDetailInfo, err := GrpcArtworkImpl.ArtworkDetail(context.Background(), &artworkDetailReq) if err != nil { return } var artistInfoReq artist.ArtistInfoRequest artistInfoReq.Uid = awDetailInfo.ProfileInfo.ArtistUuid artistInfo, err = GrpcArtistImpl.ArtistInfo(context.Background(), &artistInfoReq) if err != nil { return } return } func UpdateTransferInfo(c *gin.Context) { var req artwork.UpdateTransferInfoRequest var err error if err = c.ShouldBind(&req); err != nil { logger.Errorf("UpdateTransferInfo ShouldBind err %v", err) ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } if err = req.Validate(); err != nil { err = common.SubstrError(err) ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } resp, err := GrpcArtworkImpl.UpdateTransferInfo(context.Background(), &req) if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } ResponseQuickMsg(c, e.Ok, resp.Msg, nil) return } func TransferInfoList(c *gin.Context) { var req artwork.TransferInfoListRequest if err := c.ShouldBind(&req); err != nil { logger.Errorf("UpdateTransferInfo ShouldBind err", err) ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } if err := req.Validate(); err != nil { err = common.SubstrError(err) ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } resp, err := GrpcArtworkImpl.TransferInfoList(context.Background(), &req) if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } ResponseQuickMsg(c, e.Ok, resp.Msg, resp) return } func UpdateAwPriceRun(c *gin.Context) { var req artwork.UpdateAwPriceRunRequest if err := c.ShouldBind(&req); err != nil { logger.Errorf("UpdateAwPriceRun ShouldBind err", err) ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } if err := req.Validate(); err != nil { err = common.SubstrError(err) ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } resp, err := GrpcArtworkImpl.UpdateAwPriceRun(context.Background(), &req) if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } ResponseQuickMsg(c, e.Ok, resp.Msg, nil) return } func UpdateAwComment(c *gin.Context) { var req artwork.UpdateAwCommentReq var err error if err = c.ShouldBind(&req); err != nil { logger.Errorf("UpdateAwComment ShouldBind err", err) ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } if err = req.Validate(); err != nil { err = common.SubstrError(err) ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } if req.Action == 0 { req.Action = 1 } resp, errs := GrpcArtworkImpl.UpdateAwComment(context.Background(), &req) if errs != nil { ResponseQuickMsg(c, e.Failed, errs.Error(), nil) return } ResponseQuickMsg(c, e.Ok, resp.Msg, nil) return } func DownloadTfImage(c *gin.Context) { var req artwork_third_party.TfImagesReq var err error if err = c.ShouldBind(&req); err != nil { logger.Errorf("TfImagesReq ShouldBind err", err) ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } if err = req.Validate(); err != nil { err = common.SubstrError(err) ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } if len(req.Tfnums) == 0 { ResponseQuickMsg(c, e.Failed, e.GetMsg(e.NOTDATA), nil) return } resp, errs := GrpcArtworkThirdPartyImpl.TfImages(context.Background(), &req) if resp.Data == nil && len(resp.Data) == 0 { ResponseQuickMsg(c, e.Failed, e.GetMsg(e.NOTDATA), nil) return } // 将文件下载放入并压缩 var adminId uint64 if config.Env != "dev" { if mLoginInfoAny, exists := c.Get("mLoginInfo"); exists { userInfo := mLoginInfoAny.(model.LoginInfo) adminId = userInfo.ID } } var downloadImgPathArtwork string = fmt.Sprintf("%s%d", "tfimage", adminId) var zipName string = "泰丰图录.zip" var zipFilepath string = "runtime/" + zipName var tfImgNum int for _, v := range resp.Data { if v.ImageUrl == "" { continue } _, err = utils.SaveUrlFileDisk(v.ImageUrl, downloadImgPathArtwork, fmt.Sprintf("%s%s", v.Tfnum, v.ImgageExt)) if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } tfImgNum++ } if tfImgNum == 0 { ResponseQuickMsg(c, e.Failed, e.GetMsg(e.NOTDATA), nil) return } if err = utils.ZipFile(downloadImgPathArtwork, zipFilepath); err != nil { logger.Errorf("utils.ZipFile err", err) err = errors.New(e.GetMsg(e.ERROR_ZIP)) return } os.RemoveAll(downloadImgPathArtwork) if errs != nil { ResponseQuickMsg(c, e.Failed, errs.Error(), nil) return } var httpType string if config.IsHttps { httpType = model.HttpsType } else { httpType = model.HttpType } var exportUrl string = fmt.Sprintf("%s%s/static/%s", httpType, c.Request.Host, zipName) ResponseQuickMsg(c, e.Ok, resp.Msg, map[string]string{ "url": exportUrl, }) return } func CountVerifySimilar(c *gin.Context) { var req artwork_query.CountVerifySimilarReq var err error if err = c.ShouldBind(&req); err != nil { logger.Errorf("CountVerifySimilar ShouldBind err %+v", err) ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } var userInfo model.LoginInfo if projectConf.Env == "dev" { c.Set("mLoginInfo", model.LoginInfo{ ID: 1, NickName: "ddd", }) } if mLoginInfoAny, exists := c.Get("mLoginInfo"); exists { userInfo = mLoginInfoAny.(model.LoginInfo) } var mm = make(map[string]interface{}, 2) mm["userid"] = fmt.Sprintf("%d", userInfo.ID) mm["nickname"] = userInfo.NickName reqContext := context.WithValue(context.Background(), constant.DubboCtxKey("attachment"), mm) resp, errs := GrpcArtworkQueryImpl.CountVerifySimilar(reqContext, &req) if errs != nil { ResponseQuickMsg(c, e.Failed, errs.Error(), nil) return } ResponseQuickMsg(c, e.Ok, e.CountSimilarIng, resp) return } func OneQueryList(c *gin.Context) { var req artwork_query.OneQueryReq var err error if err = c.ShouldBind(&req); err != nil { logger.Errorf("OneQueryList ShouldBind err", err) ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } fmt.Println(111111) //查询暂存的画作评价2记录 if req.CheckStatus == 4 { req.CheckStatus = 2 artworkUidList, err := GetArtworkUidListFromOneQueryDataCache() if err != nil { Error(c, e.Failed, err, "获取暂存数据失败") return } if len(req.SearchArtworkUuids) > 0 { req.SearchArtworkUuids = utils.Intersection(artworkUidList, req.SearchArtworkUuids) } else { req.SearchArtworkUuids = artworkUidList } } fmt.Println(2222222) fmt.Printf("oneQueryReq:%+v\n", req) //新增需求:去除黑名单中画家的画作 2024-09-07 var blackListRes *artist.BlackListResp var blackArtistUids []string blackListRes, err = GrpcArtistImpl.BlackList(context.Background(), &artist.BlackListReq{Page: 1, PageSize: -1, Gender: -1, BlackListStatus: 2}) if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } if blackListRes.Count > 0 { for _, v := range blackListRes.Data { blackArtistUids = append(blackArtistUids, v.ArtistUuid) } //req.BlackListArtistUid = blackArtistUids //使用此条件会把黑名单中的画家从列表中剔除 } fmt.Printf("blackListRes:%+v\n", blackArtistUids) resp, errs := GrpcArtworkQueryImpl.OneQuery(context.Background(), &req) if errs != nil { ResponseQuickMsg(c, e.Failed, errs.Error(), nil) return } fmt.Println(3333333) resp2, err := UpdateArtworkOneQueryDataUseCache(resp.Data, req.Permission) if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } fmt.Println(44444444444444) if len(resp2) > 0 { //在黑名单画家名字前面加#号 for k, v := range resp2 { if utils.Contains(blackArtistUids, v.ArtistUuid) { resp2[k].ArtistName = "#" + resp2[k].ArtistName } } var artistUids []string = make([]string, 0, len(resp2)) for k, v := range resp2 { artistUids = append(artistUids, v.ArtistUuid) resp2[k].ArtistShowCount = fmt.Sprintf("%s(0)", v.ArtistName) } artshowResp, _err := GrpcArtShowImpl.ArtistExhibitionCount(c, &artShow.ArtistExhibitionCountReq{ArtistUid: artistUids}) if _err != nil { zap.L().Error("artist ArtistExhibitionCount err", zap.Error(err)) } if artshowResp != nil && len(artshowResp.ArtistShowCount) > 0 { for k, v := range resp2 { for _, v1 := range artshowResp.ArtistShowCount { if v.ArtistUuid == v1.ArtistUid { resp2[k].ArtistShowCount = fmt.Sprintf("%s(%d)", v.ArtistName, v1.ShowCount) break } } } } } ResponseQuickMsg(c, e.Ok, resp.Msg, map[string]any{"Data": resp2, "Page": resp.Page, "PageSize": resp.PageSize, "Count": resp.Count}) return } func OneQueryExport(c *gin.Context) { var req artwork_query.OneQueryReq var err error if err = c.ShouldBind(&req); err != nil { logger.Errorf("OneQueryList ShouldBind err", err) ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } resp, errs := GrpcArtworkQueryImpl.OneQuery(context.Background(), &req) if errs != nil { ResponseQuickMsg(c, e.Failed, errs.Error(), nil) return } var adminId uint64 var fileName string if config.Env != "dev" { if mLoginInfoAny, exists := c.Get("mLoginInfo"); exists { userInfo := mLoginInfoAny.(model.LoginInfo) adminId = userInfo.ID } } if len(resp.Data) > 0 { columns := []string{"画作名称", "画家姓名", "长度", "宽度", "平尺数", "画作简介", "画作评价", "数字化(内部拍摄)"} var data []interface{} for _, v := range resp.Data { var temp []string temp = append(temp, v.ArtworkName) temp = append(temp, v.ArtistName) temp = append(temp, fmt.Sprintf("%d", v.Length)) temp = append(temp, fmt.Sprintf("%d", v.Width)) temp = append(temp, fmt.Sprintf("%d", v.Ruler)) temp = append(temp, v.Abstract) temp = append(temp, v.Comment) temp = append(temp, v.DigiArtImg) data = append(data, &temp) } fileName = fmt.Sprintf("画作数据%d.xlsx", adminId) _, err = utils.ToExcelByType(columns, data, "slice", "./runtime/"+fileName) if err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) } } var httpType string if config.IsHttps { httpType = model.HttpsType } else { httpType = model.HttpType } var exportUrl string = fmt.Sprintf("%s%s/static/%s", httpType, c.Request.Host, fileName) ResponseQuickMsg(c, e.Ok, resp.Msg, map[string]string{ "url": exportUrl, }) return } func ArtworkEditFilter(c *gin.Context) { var req artwork.UpdateAwFilterReq var err error if err = c.ShouldBind(&req); err != nil { logger.Errorf("ArtworkEditFilter ShouldBind err%v", err) ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } resp, errs := GrpcArtworkImpl.UpdateAwFilter(context.Background(), &req) if errs != nil { ResponseQuickMsg(c, e.Failed, errs.Error(), nil) return } ResponseQuickMsg(c, e.Ok, resp.Msg, nil) return } func BatchDciList(c *gin.Context) { var req artwork_query.BatchDciListReq var err error if err = c.ShouldBind(&req); err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } //查询redis缓存进行遍历 var cacheAllKey = "batchDciCopyright" var cacheKeySlice []string if cacheKeySlice, err = cache.RedisClient.SMembers(cacheAllKey).Result(); err != nil { ResponseQuickMsg(c, e.Failed, err.Error(), nil) return } var allArtworkUuids []string for _, cacheKey := range cacheKeySlice { var tempArtworkUuids []string if cache.RedisClient.Exists(cacheKey).Val() == 0 { cache.RedisClient.SRem(cacheAllKey, cacheKey) continue } if tempArtworkUuids, err = cache.RedisClient.SMembers(cacheKey).Result(); err != nil { continue } allArtworkUuids = append(allArtworkUuids, tempArtworkUuids...) } req.NotInArtworkUuids = allArtworkUuids resp, errs := GrpcArtworkQueryImpl.BatchDciList(context.Background(), &req) if errs != nil { ResponseQuickMsg(c, e.Failed, errs.Error(), nil) return } ResponseQuickMsg(c, e.Ok, e.GetMsg(e.SUCCESS), resp) return } // 检测画作的补充信息是否可编辑 func ArtworkSupplementEdit(artistUuid, artworkUuid string) (edit bool, err error) { edit = true /* // 画家被锁定了不可编辑 var findUserReq artistInfoUser.FindUserRequest findUserReq.MgmtArtistUid = artistUuid findUserResp, _err := GrpcArtistInfoUserImpl.FindUser(context.Background(), &findUserReq) if _err != nil { err = _err edit = false return } if findUserResp.IsLock { edit = false return } // 画作通过画家宝审核不可编辑 lockDetailResp, _err := GrpcArtistInfoArtworkImpl.GetArtworkLockDetail(context.Background(), &artistInfoArtwork.GetArtworkLockDetailRequest{ArtworkUid: artworkUuid}) if _err != nil { err = _err edit = false return } if lockDetailResp.BaseAuditStatus == artistInfoArtwork.BaseAuditStatus_BA_Pass { edit = false return }*/ // 画作被绑定入画展包且画展包已通过画展包审核,则不可编辑 if err = CheckArtworkApproval(artworkUuid); err != nil { err = nil edit = false return } return }