fonchain-fiee/pkg/service/artistInfo/asArtshow/artshowAtistIndex.go

478 lines
17 KiB
Go
Raw Normal View History

2025-02-19 06:24:15 +00:00
// 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/fonchain_enterprise/fonchain-main/api/artist"
"github.com/fonchain_enterprise/fonchain-main/pkg/service/artistInfo/asArtwork"
"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/service/artistInfo/asUtil"
"github.com/fonchain_enterprise/fonchain-main/pkg/utils/stime"
"sort"
"sync"
"time"
"github.com/fonchain_enterprise/fonchain-main/api/artistInfoUser"
"github.com/fonchain_enterprise/fonchain-main/api/artistinfoArtshow"
"github.com/fonchain_enterprise/fonchain-main/pkg/e"
"github.com/fonchain_enterprise/fonchain-main/pkg/service"
"github.com/gin-gonic/gin"
"github.com/jinzhu/copier"
)
// 画家指数
var ArtshowIndex = new(artshowIndex)
type artshowIndex struct {
}
func (a artshowIndex) GenerateArtistIndexRecords(c *gin.Context) {
var req = RequestGenerateArtistIndexRecord{}
if err := c.ShouldBindJSON(&req); err != nil {
service.Error(c, e.InvalidParams, err, err.Error())
return
}
_, err := service.GrpcArtistInfoArtshowImpl.BatchCreateArtistIndex(c, &artistinfoArtshow.BatchCreateArtistIndexRequest{
ArtistUids: req.ArtistUids,
})
if err != nil {
service.ErrorWithMark(c, e.Failed, err, "GenerateArtistIndexRecord: GrpcArtshowImpl.BatchCreateArtistIndex Error ", err.Error())
return
} else {
service.Success(c)
}
}
// GetArtistIndexListAtUserSide 获取用户端画展视频资料列表
func (a artshowIndex) GetArtistIndexListAtUserSide(c *gin.Context) {
var req RequestGetArtistIndexListAtUserSide
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.GetArtistIndexList(c, &artistinfoArtshow.GetArtistIndexListRequest{
Page: req.Page,
PageSize: req.PageSize,
ArtistUid: req.ArtistUid,
Status: 2,
})
if err != nil {
service.ErrorWithMark(c, e.Failed, err, "GetArtistIndexListAtUserSide: GrpcArtshowImpl.GetArtistIndexList Error ", "查询失败")
return
}
var datas []*ArtistIndexInfo
err = copier.Copy(&datas, &res.Data)
if err != nil {
service.ErrorWithMark(c, e.Failed, err, "GetArtistIndexListAtBackendSide: copier.Copy Error ", "查询失败")
return
}
service.ResponseList(c, datas, service.OptionPage(res.Page.Page, res.Page.PageSize, res.Page.Total), service.OptionMsg("查询成功"))
}
// GetArtistIndexListAtBackendSide 获取后端画展视频资料列表
func (a artshowIndex) GetArtistIndexListAtBackendSide(c *gin.Context) {
var request = GetArtistIndexListRequest{} //artistinfoArtshow.GetArtistIndexListRequest{}
if err := c.ShouldBindJSON(&request); err != nil {
service.Error(c, e.InvalidParams, err, err.Error())
return
}
if request.History {
request.Status = 3 //解锁状态即查询历史记录
} else {
request.Status = 2
}
res, err := service.GrpcArtistInfoArtshowImpl.GetArtistIndexList(c, &request.GetArtistIndexListRequest)
if err != nil {
service.ErrorWithMark(c, e.Failed, err, "GetArtistIndexListAtBackendSide: GrpcArtshowImpl.GetArtistIndexList Error ", "查询失败")
return
}
var datas []*ArtistIndexInfo
err = copier.Copy(&datas, &res.Data)
if err != nil {
service.ErrorWithMark(c, e.Failed, err, "GetArtistIndexListAtBackendSide: copier.Copy Error ", "查询失败")
return
}
service.ResponseList(c, datas, service.OptionPage(res.Page.Page, res.Page.PageSize, res.Page.Total), service.OptionMsg("查询成功"))
}
var generateArtistIndexLock sync.Mutex
func (a artshowIndex) UpdateArtistIndex(c *gin.Context) {
generateArtistIndexLock.Lock()
defer generateArtistIndexLock.Unlock()
var request = artistinfoArtshow.ArtistIndexInfo{}
if err := c.ShouldBindJSON(&request); err != nil {
service.Error(c, e.InvalidParams, err, err.Error())
return
}
var err error
reslist, err := service.GrpcArtistInfoArtshowImpl.GetArtistIndexList(c, &artistinfoArtshow.GetArtistIndexListRequest{
ArtistUid: request.ArtistUid,
})
if err != nil {
service.Error(c, e.InvalidParams, err, err.Error())
return
}
found := false
for _, v := range reslist.Data {
if v.Class == request.Class {
found = true
_, err = service.GrpcArtistInfoArtshowImpl.UpdateArtistIndex(c, &artistinfoArtshow.UpdateArtistIndexRequest{
Id: v.Id,
TitleScore: request.TitleScore,
Score: request.Score,
Status: 2,
})
if err != nil {
service.ErrorWithMark(c, e.Failed, err, "GetArtistIndexListAtBackendSide: GrpcArtshowImpl.GetArtistIndexList Error ", "更新失败")
return
}
break
}
}
if !found {
request.LatestBrokerUpdatedAt = time.Now().Format(stime.Format_Normal_YMDhms)
request.DataUpdatedAt = request.LatestBrokerUpdatedAt
_, err = service.GrpcArtistInfoArtshowImpl.CreateArtistIndex(c, &request)
if err != nil {
service.ErrorWithMark(c, e.Failed, err, "CreateArtistIndex Error ", "更新失败")
return
}
}
//同步到画家系统
_ = SyncArtistIndexToArtistSystem(&request, c)
service.Success(c)
}
func (a artshowIndex) AuditArtistIndex(c *gin.Context) {
var request = artistinfoArtshow.AuditArtistIndexRequest{}
if err := c.ShouldBindJSON(&request); err != nil {
service.Error(c, e.InvalidParams, err, err.Error())
return
}
go func() {
//var userIds []int64
var userIdMap = make(map[int64]UserRelationArtistSupplement)
for _, id := range request.ArtistIndexIds {
asUser.UpdateOperationTime(c, artistinfoArtshow.OdType_artistIndex, id)
artshowDetail, err := service.GrpcArtistInfoArtshowImpl.GetArtistIndexDetail(c, &artistinfoArtshow.GetArtistIndexDetailRequest{Id: id})
if err == nil {
userInfo, errs := service.GrpcArtistInfoUserImpl.FindUser(c, &artistInfoUser.FindUserRequest{MgmtArtistUid: artshowDetail.ArtistUid})
if errs == nil && request.AuditStatus == 4 {
//userIds = append(userIds, userInfo.Id)
userIdMap[userInfo.Id] = UserRelationArtistSupplement{userInfo, artshowDetail}
}
}
}
fmt.Printf("画家指数map%+v \n", userIdMap)
if len(userIdMap) > 0 {
fmt.Println("aaaaa")
for userId, relationData := range userIdMap {
//if errs := asUser.ArtistInfoPushNotice.ArtistArtshowSupplementAuditNotice(userId, asUser.AuditType_ArtistInex); errs != nil {
// fmt.Println("1111:", errs.Error())
// logger.Error("AuditArtistIndex,发送app通知失败:" + errs.Error())
// continue
//}
pusher := asPush.NewPusher()
if errs := pusher.ArtistArtshowSupplementAuditNotice(userId, asUser.AuditType_ArtistInex); errs != nil {
fmt.Println("1111:", errs.Error())
logger.Error("AuditArtistIndex,发送app通知失败:" + errs.Error())
continue
}
fmt.Println("bbbbb")
//获取画家系统的画家指数数据
//artistSystemIndex, errs := service.GrpcArtistImpl.GetIndex(c, &artist.GetIndexRequest{
// Uid: relationData.UserInfo.MgmtArtistUid,
//})
//if errs != nil {
// fmt.Println("2222:", errs.Error())
// logger.Error("GrpcArtistImpl.ArtistDetail,获取画家系统详情失败:" + errs.Error())
// continue
//}
//fmt.Println("ccccc")
//更新画家指数
updateArtistSystemIndexRequest := &artist.IndexRequest{
Uid: relationData.UserInfo.MgmtArtistUid,
//Exhibition: artistSystemIndex.Exhibition,
//Collectible: artistSystemIndex.Collectible,
//Education: artistSystemIndex.Education,
//Influence: artistSystemIndex.Influence,
//Professionalism: artistSystemIndex.Professionalism,
InSource: 2, //这个字段不要使用artistSystemIndex.InSource,两个字段含义不同
Exhibition: -1,
Education: -1,
Professionalism: -1,
Influence: -1,
Collectible: -1,
}
switch relationData.ArtistIndex.Title {
case "艺术家-展览":
updateArtistSystemIndexRequest.Exhibition = relationData.ArtistIndex.TitleScore
case "艺术家-资历":
updateArtistSystemIndexRequest.Education = relationData.ArtistIndex.TitleScore
case "艺术家-专业":
updateArtistSystemIndexRequest.Professionalism = relationData.ArtistIndex.TitleScore
case "艺术家-影响力":
updateArtistSystemIndexRequest.Influence = relationData.ArtistIndex.TitleScore
case "艺术家-收藏":
updateArtistSystemIndexRequest.Collectible = relationData.ArtistIndex.TitleScore
}
fmt.Println("ddddd")
fmt.Printf("画家指数:%+v\n", updateArtistSystemIndexRequest)
if _, errs := service.GrpcArtistImpl.UpdateIndex(c, updateArtistSystemIndexRequest); errs != nil {
fmt.Println("3333:", errs.Error())
logger.Error("更新画家系统的画家指数失败", errs)
continue
}
}
}
}()
_, err := service.GrpcArtistInfoArtshowImpl.AuditArtistIndex(c, &request)
if err != nil {
service.ErrorWithMark(c, e.Failed, err, "AuditArtistIndex: GrpcArtshowImpl.AuditArtistIndex Error ", err.Error())
return
}
service.Success(c)
}
// DEPRECATED
// 新方法为GetViewArtistIndexStaticList
func (a artshowIndex) GetLockedArtistList(c *gin.Context) {
var request = artistinfoArtshow.ArtistListRequest{}
if err := c.ShouldBindJSON(&request); err != nil {
service.Error(c, e.InvalidParams, err, err.Error())
return
}
lockedUsers, err := service.GrpcArtistInfoUserImpl.FindUsers(c, &artistInfoUser.FindUsersRequest{
ArtistRealName: request.ArtistName,
Page: int32(request.Page),
PageSize: int32(request.PageSize),
IsLock: true,
})
if err != nil {
service.ErrorWithMark(c, e.Failed, err, "GetLockedArtistList: service.GrpcArtistInfoUserImpl.FindUsers ", err.Error())
return
}
var returnData = ResponseGetLockedArtistList{}
for _, user := range lockedUsers.Data {
artistIndexList, err := service.GrpcArtistInfoArtshowImpl.GetArtistIndexList(c, &artistinfoArtshow.GetArtistIndexListRequest{
ArtistUid: user.MgmtArtistUid,
//LockTime: user.LatestLockTime,
Status: 2,
Page: 1,
PageSize: -1,
})
if err != nil {
service.ErrorWithMark(c, e.Failed, err, "GetLockedArtistList: service.GrpcArtistInfoUserImpl.FindUsers ", err.Error())
return
}
//查找最新一次更新的记录,然后拿去该条数据的更新时间
dataCreatedAt := ""
dataUpdatedAt := ""
if len(artistIndexList.Data) > 0 {
sort.Slice(artistIndexList.Data, func(i, j int) bool { // asc
return artistIndexList.Data[i].UpdatedAt > artistIndexList.Data[j].UpdatedAt
})
dataCreatedAt = artistIndexList.Data[0].CreatedAt
dataUpdatedAt = artistIndexList.Data[0].UpdatedAt
}
returnData.Data = append(returnData.Data, ArtistUserInfo{
ArtistUid: user.MgmtArtistUid,
ArtistName: user.RealName.Name,
DataCreatedAt: dataCreatedAt,
DataUpdatedAt: dataUpdatedAt,
})
}
if err != nil {
service.ErrorWithMark(c, e.Failed, err, "GetLockedArtistList: GrpcArtshowImpl.AuditArtistIndex Error ", err.Error())
return
}
service.ResponseList(c, returnData.Data, service.OptionPage(request.Page, request.PageSize, lockedUsers.Page.Total), service.OptionMsg("查询成功"))
}
func (a artshowIndex) GetArtistIndexDetail(c *gin.Context) {
var request = artistinfoArtshow.ArtistIndexInfo{}
if err := c.ShouldBindJSON(&request); err != nil {
service.Error(c, e.InvalidParams, err, err.Error())
return
}
res, err := service.GrpcArtistInfoArtshowImpl.GetArtistIndexDetail(c, &artistinfoArtshow.GetArtistIndexDetailRequest{
Id: request.Id,
})
if err != nil {
service.ErrorWithMark(c, e.Failed, err, "GetArtistIndexListAtBackendSide: GrpcArtshowImpl.GetArtistIndexList Error ", "查询失败")
return
}
var returnData ArtistIndexDetail
err = copier.Copy(&returnData, res)
if err != nil {
service.Error(c, e.Failed, err, err.Error())
}
service.ResponseData(c, returnData)
}
var generateAllSupplementLock sync.Mutex
func (a artshowIndex) GenerateAllSupplement(c *gin.Context) {
generateAllSupplementLock.Lock()
defer generateAllSupplementLock.Unlock()
type GenerateAllSupplementRequest struct {
ArtistUid string `json:"artistUid"`
}
var (
artistUid string
err error
request GenerateAllSupplementRequest
)
if err = c.ShouldBindJSON(&request); err != nil {
service.Error(c, e.InvalidParams, err, err.Error())
return
}
artistUid = request.ArtistUid
if artistUid == "" {
service.Error(c, e.Failed, err, "画家uid不能为空")
return
}
//获取用户信息
userInfo, err := service.GrpcArtistInfoUserImpl.FindUser(c, &artistInfoUser.FindUserRequest{
MgmtArtistUid: artistUid,
})
if err != nil {
service.ErrorWithMark(c, e.Failed, err, "GenerateAllSupplement FindUser Error ", err.Error())
return
}
if !userInfo.IsLock {
service.Error(c, e.Failed, err, "画家未锁定")
return
}
//生成画展视频资料
{
// 又改为通过画家系统同步过来 by jjxu 2023-09-20
//获取访谈视频资料
//var oriUrl string
//resp, err := service.GrpcArtistImpl.ArtistDetail(c, &artist.DetailRequest{
// Uid: artistUid,
//})
//if err == nil && resp.MediaInfo != nil && len(resp.MediaInfo.InterviewVideos) > 0 {
// oriUrl = resp.MediaInfo.InterviewVideos[0].OriUrl
//}
////创建画展视频记录
//_, err = service.GrpcArtistInfoArtshowImpl.BatchCreateArtshowVideo(c, &artistinfoArtshow.BatchCreateArtshowVideoRequest{
// Data: []*artistinfoArtshow.ArtshowVideoInfo{
// {
// ArtistUid: artistUid,
// LockTime: userInfo.LatestLockTime,
// ArtistName: userInfo.RealName.Name,
// AuditStatus: utils.If(oriUrl == "", int64(asArtwork.AuditType_Supplemented), int64(asArtwork.AuditType_Pass)).(int64),
// Status: 2, //锁定
// VideoUrl: oriUrl,
// },
// },
//})
_, err = service.GrpcArtistInfoArtshowImpl.BatchCreateArtshowVideo(c, &artistinfoArtshow.BatchCreateArtshowVideoRequest{
Data: []*artistinfoArtshow.ArtshowVideoInfo{
{
ArtistUid: artistUid,
LockTime: userInfo.LatestLockTime,
ArtistName: userInfo.RealName.Name,
AuditStatus: int64(asArtwork.AuditType_Supplemented),
Status: 2, //锁定
},
},
})
}
//if err != nil {
// service.ErrorWithMark(c, e.Failed, err, "BatchCreateArtshowVideo Error ", err.Error())
// return
//}
//生成画家指数
_, err = service.GrpcArtistInfoArtshowImpl.BatchCreateArtistIndex(c, &artistinfoArtshow.BatchCreateArtistIndexRequest{
ArtistUids: []string{artistUid},
})
//if err != nil {
// service.ErrorWithMark(c, e.Failed, err, "BatchCreateArtistIndex Error ", err.Error())
// return
//}
//生成画家补充信息
_, err = service.GrpcArtistInfoArtshowImpl.BatchCreateArtistSupplement(c, &artistinfoArtshow.BatchCreateArtistSupplementRequest{
ArtistUids: []string{artistUid},
})
//if err != nil {
// service.ErrorWithMark(c, e.Failed, err, "BatchCreateArtistSupplement Error ", err.Error())
// return
//}
//生成经纪人补充信息
//_, err = service.GrpcArtistInfoArtshowImpl.GenerateBrokerRecord(c, &artistinfoArtshow.GenerateBrokerRecordRequest{ArtistUid: artistUid})
//if err != nil {
// service.ErrorWithMark(c, e.Failed, err, "GetItemList: GrpcArtistInfoArtshowImpl.GenerateBrokerRecord Error ", err.Error())
// return
//}
//发送画展补充信息的通知
//if err = asUser.ArtistInfoPushNotice.ArtistArtshowSupplementBeginNotice(userInfo.Id); err != nil {
// logger.Error(err)
//}
pusher := asPush.NewPusher()
if err = pusher.ArtistArtshowSupplementBeginNotice(userInfo.Id); err != nil {
logger.Error(err)
}
service.Success(c)
}
// 使用id查询ViewArtistIndexStatic
func (a *artshowIndex) GetViewArtistIndexStaticDetail(c *gin.Context) {
var req artistinfoArtshow.GetViewArtistIndexStaticByIdRequest
if err := c.ShouldBindJSON(&req); err != nil {
service.Error(c, e.InvalidParams, err, "无效参数")
return
}
resp, err := service.GrpcArtistInfoArtshowImpl.GetViewArtistIndexStaticDetail(c, &req)
if err != nil {
service.ErrorWithMark(c, e.Failed, err, "GrpcArtistinfoArtshowImpl.GetViewArtistIndexStaticDetail Err", "查询失败")
return
}
service.Success(c, resp)
}
// 批量查询ViewArtistIndexStatic
func (a *artshowIndex) GetViewArtistIndexStaticList(c *gin.Context) {
var req GetViewArtistIndexStaticListRequest
if err := c.ShouldBindJSON(&req); err != nil {
service.Error(c, e.InvalidParams, err, "无效参数")
return
}
var protoReq = artistinfoArtshow.GetViewArtistIndexStaticListRequest{Query: &artistinfoArtshow.ViewArtistIndexStaticData{}}
asUtil.RequestDataConvert(&req, &protoReq)
resp, err := service.GrpcArtistInfoArtshowImpl.GetViewArtistIndexStaticList(c, &protoReq)
if err != nil {
service.ErrorWithMark(c, e.Failed, err, "GetViewArtistIndexStaticList Err", "查询失败")
return
}
service.ResponseList(c, resp.List,
service.OptionPage(resp.Page, resp.PageSize, resp.Total), service.OptionMsg("查询成功"),
service.OptionAddField_ArtshowCount("artistUid"),
)
}