// Package asArtshow ----------------------------- // @file : artshowAtistIndex.go // @author : JJXu // @contact : wavingbear@163.com // @time : 2023/3/3 8:25 // ------------------------------------------- package asArtshow import ( "dubbo.apache.org/dubbo-go/v3/common/logger" "fmt" "github.com/dorlolo/simpleRequest" "github.com/fonchain_enterprise/fonchain-main/api/artistInfoUser" "github.com/fonchain_enterprise/fonchain-main/api/artistinfoArtshow" "github.com/fonchain_enterprise/fonchain-main/pkg/config" "github.com/fonchain_enterprise/fonchain-main/pkg/e" "github.com/fonchain_enterprise/fonchain-main/pkg/service" "github.com/fonchain_enterprise/fonchain-main/pkg/service/artistInfo/asPush" "github.com/fonchain_enterprise/fonchain-main/pkg/service/artistInfo/asUser" "github.com/fonchain_enterprise/fonchain-main/pkg/utils/stime" "github.com/fonchain_enterprise/utils/objstorage" "github.com/gin-gonic/gin" "github.com/jinzhu/copier" "golang.org/x/sync/errgroup" "math/rand" "strings" ) const MaxTextLength = 500 // 画家指数 var ArtistSupplement = new(artistSupplement) type artistSupplement struct { } func (a artistSupplement) GenerateArtistSupplementRecords(c *gin.Context) { var req = RequestGenerateArtistSupplementRecord{} if err := c.ShouldBindJSON(&req); err != nil { service.Error(c, e.InvalidParams, err, err.Error()) return } _, err := service.GrpcArtistInfoArtshowImpl.BatchCreateArtistSupplement(c, &artistinfoArtshow.BatchCreateArtistSupplementRequest{ ArtistUids: req.ArtistUids, }) if err != nil { service.ErrorWithMark(c, e.Failed, err, "GenerateArtistSupplementRecord: GrpcArtshowImpl.BatchCreateArtistSupplement Error ", err.Error()) return } else { service.Success(c) } } // GetArtistSupplementListAtUserSide 获取用户端画展视频资料列表 func (a artistSupplement) GetArtistSupplementListAtUserSide(c *gin.Context) { var req RequestGetArtistSupplementListAtUserSide if err := c.ShouldBindJSON(&req); err != nil { service.Error(c, e.InvalidParams, err, err.Error()) return } //获取艺术家uid if req.ArtistUid == "" { userInfo, err, code := asUser.GetUserInfoWithToken(c) if err != nil { service.Error(c, code, err, err.Error()) return } req.ArtistUid = userInfo.MgmtArtistUid } res, err := service.GrpcArtistInfoArtshowImpl.GetArtistSupplementList(c, &artistinfoArtshow.GetArtistSupplementListRequest{ Page: req.Page, PageSize: req.PageSize, ArtistUid: req.ArtistUid, Status: 2, }) if err != nil { service.ErrorWithMark(c, e.Failed, err, "GetArtistSupplementListAtUserSide: GrpcArtshowImpl.GetArtistSupplementList Error ", "查询失败") return } var datas []*ArtistSupplementInfo err = copier.Copy(&datas, &res.Data) if err != nil { service.ErrorWithMark(c, e.Failed, err, "GetArtistSupplementListAtBackendSide: copier.Copy Error ", "查询失败") return } service.ResponseList(c, datas, service.OptionPage(res.Page.Page, res.Page.PageSize, res.Page.Total), service.OptionMsg("查询成功")) } // GetArtistSupplementListAtBackendSide 获取后端画展视频资料列表 func (a artistSupplement) GetArtistSupplementListAtBackendSide(c *gin.Context) { var request = GetArtistSupplementListRequest{} //artistinfoArtshow.GetArtistSupplementListRequest{} if err := c.ShouldBindJSON(&request); err != nil { service.Error(c, e.InvalidParams, err, err.Error()) return } if request.History { request.GetArtistSupplementListRequest.Status = 3 } else { request.GetArtistSupplementListRequest.Status = 2 } res, err := service.GrpcArtistInfoArtshowImpl.GetArtistSupplementList(c, &request.GetArtistSupplementListRequest) if err != nil { service.ErrorWithMark(c, e.Failed, err, "GetArtistSupplementListAtBackendSide: GrpcArtshowImpl.GetArtistSupplementList Error ", "查询失败") return } var datas []*ArtistSupplementInfo err = copier.Copy(&datas, &res.Data) if err != nil { service.ErrorWithMark(c, e.Failed, err, "GetArtistSupplementListAtBackendSide: copier.Copy Error ", "查询失败") return } //下载个人简介/个人荣誉 errGroup := errgroup.Group{} for i, _ := range datas { i := i errGroup.Go(func() error { return a.DownloadLongTextFromBucket(datas[i], i) }) } err = errGroup.Wait() if err != nil { service.ErrorWithMark(c, e.Failed, err, "GetArtistSupplementListAtBackendSide: DownloadLongTextFromBucket Error ", "查询失败,个人简介/个人荣誉下载失败") return } service.ResponseList(c, datas, service.OptionPage(res.Page.Page, res.Page.PageSize, res.Page.Total), service.OptionMsg("查询成功"), service.OptionAddField_ArtshowCount("artistUid"), ) } func (a artistSupplement) UpdateArtistSupplement(c *gin.Context) { var request = artistinfoArtshow.ArtistSupplementInfo{} if err := c.ShouldBindJSON(&request); err != nil { service.Error(c, e.InvalidParams, err, err.Error()) return } _, err := service.GrpcArtistInfoArtshowImpl.UpdateArtistSupplement(c, &artistinfoArtshow.UpdateArtistSupplementRequest{ Id: request.Id, ArtistProfile: request.ArtistProfile, CountryArtLevel: request.CountryArtLevel, ArtistCertPic: request.ArtistCertPic, BankNum: request.BankNum, BankName: request.BankName, //Status: 2, }) if err != nil { service.ErrorWithMark(c, e.Failed, err, "GetArtistSupplementListAtBackendSide: GrpcArtshowImpl.GetArtistSupplementList Error ", "查询失败") return } service.Success(c) } func (a artistSupplement) AuditArtistSupplement(c *gin.Context) { var request = artistinfoArtshow.AuditArtistSupplementRequest{} if err := c.ShouldBindJSON(&request); err != nil { service.Error(c, e.InvalidParams, err, err.Error()) return } go func() { for _, id := range request.ArtistSupplementIds { asUser.UpdateOperationTime(c, artistinfoArtshow.OdType_artistSupplyData, id) artshowDetail, err := service.GrpcArtistInfoArtshowImpl.GetArtistSupplementDetail(c, &artistinfoArtshow.GetArtistSupplementDetailRequest{Id: id}) if err == nil { userInfo, errs := service.GrpcArtistInfoUserImpl.FindUser(c, &artistInfoUser.FindUserRequest{MgmtArtistUid: artshowDetail.ArtistUid}) if errs == nil { //if errs = asUser.ArtistInfoPushNotice.ArtistArtshowSupplementAuditNotice(userInfo.Id, asUser.AuditType_ArtistSupplement); errs != nil { // logger.Error("AuditArtistSupplement,发送app通知失败:" + errs.Error()) //} pusher := asPush.NewPusher() if errs = pusher.ArtistArtshowSupplementAuditNotice(userInfo.Id, asUser.AuditType_ArtistSupplement); errs != nil { logger.Error("AuditArtistSupplement,发送app通知失败:" + errs.Error()) } } } } }() _, err := service.GrpcArtistInfoArtshowImpl.AuditArtistSupplement(c, &request) if err != nil { service.ErrorWithMark(c, e.Failed, err, "AuditArtistSupplement: GrpcArtshowImpl.AuditArtistSupplement Error ", err.Error()) return } service.Success(c) } func (a artistSupplement) GetSupplementDetail(c *gin.Context) { var request = artistinfoArtshow.GetArtistSupplementDetailRequest{} if err := c.ShouldBindJSON(&request); err != nil { service.Error(c, e.InvalidParams, err, err.Error()) return } video, err := service.GrpcArtistInfoArtshowImpl.GetArtistSupplementDetail(c, &request) if err != nil { service.ErrorWithMark(c, e.Failed, err, "GetVideoDetail: GrpcArtshowImpl.GetArtshowVideoDetail ", err.Error()) return } var data = ArtistSupplementDetail{} data.ConvertResponse(video) service.ResponseData(c, data, service.OptionMsg("查询成功")) } func (a artistSupplement) DownloadLongTextFromBucket(data *ArtistSupplementInfo, index int) error { if strings.HasPrefix(data.ArtistProfile, "http") { //下载data.ArtistProfile req := simpleRequest.NewRequest() res, err := req.GET(data.ArtistProfile) if err != nil { return err } data.ArtistProfile = string(res) } if strings.HasPrefix(data.Honor, "http") { //下载data.Honor req := simpleRequest.NewRequest() res, err := req.GET(data.Honor) if err != nil { return err } data.Honor = string(res) } return nil } func (a artistSupplement) DownloadLongText(data string) string { if strings.HasPrefix(data, "http") { req := simpleRequest.NewRequest() res, err := req.GET(data) if err != nil { return "" } return string(res) } else { return data } } // 长文本上传到bos // textType: 1=个人简介 2=个人荣誉 func (a artistSupplement) LongTextUploadToBucket(textType int, text string, artistUid string) (result string, err error) { result = text if len(text) <= MaxTextLength { return } BOSClient, err := objstorage.NewOSS(config.ConfigData.Oss.AccessKeyId, config.ConfigData.Oss.AccessKeySecret, config.ConfigData.Oss.Endpoint) if err != nil { return } var objPath string switch textType { case 1: objPath = fmt.Sprintf("artistmgmt/static/%s/artistProfile/%s_%d", artistUid, stime.Currentime(stime.Format_NoSpacer_YMDhms), rand.Int()) case 2: objPath = fmt.Sprintf("artistmgmt/static/%s/horhor/%s_%d", artistUid, stime.Currentime(stime.Format_NoSpacer_YMDhms), rand.Int()) } _, err = BOSClient.PutObjectFromString(config.ConfigData.Oss.BucketName, objPath, text) if err != nil { fmt.Println("[err] LongTextUploadToBucket--PutObjectFromString(ArtistProfile):" + err.Error()) return } result = config.ConfigData.Oss.CdnHost + "/" + objPath return }