|
|
package chance
|
|
|
|
|
|
import (
|
|
|
"github.com/astaxie/beego/orm"
|
|
|
"opp/internal/utils"
|
|
|
"opp/models"
|
|
|
"opp/protocol"
|
|
|
"opp/services/agg"
|
|
|
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
|
|
|
)
|
|
|
|
|
|
//成果池
|
|
|
func AchievementPool(header *protocol.RequestHeader, request *protocol.AchievementPoolRequest) (rsp *protocol.AchievementPoolResponse, err error) {
|
|
|
var (
|
|
|
ormItems []protocol.CommAchievementItemOrm
|
|
|
total int
|
|
|
)
|
|
|
rsp = &protocol.AchievementPoolResponse{}
|
|
|
rsp.List = make([]*protocol.AchievementCommonListItem, 0)
|
|
|
if total, err = models.GetAchievementAll(request.UserId, header.CompanyId, request.ChanceTypeId, request.LastId, request.DepartmentId, request.PageSize, &ormItems); err != nil {
|
|
|
if err == orm.ErrNoRows {
|
|
|
err = nil
|
|
|
return
|
|
|
}
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
rsp.Total = total
|
|
|
for i := range ormItems {
|
|
|
item := ormItems[i]
|
|
|
rspItem := &protocol.AchievementCommonListItem{
|
|
|
Achievement: GetAchievementItem(header, item),
|
|
|
StatisticData: GetStatisticData(header, item.StaticDataOrm, item.AchievementId),
|
|
|
ChanceTemplate: getTemplate(item.TemplateId),
|
|
|
ChanceType: getChanceType(item.ChanceTypeId),
|
|
|
}
|
|
|
rsp.List = append(rsp.List, rspItem)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//获取成果项
|
|
|
func GetAchievementItem(header *protocol.RequestHeader, from protocol.CommAchievementItemOrm) (item protocol.AchievementItem) {
|
|
|
var (
|
|
|
provider *protocol.BaseUserInfo
|
|
|
err error
|
|
|
)
|
|
|
if from.UserId > 0 {
|
|
|
if provider, err = agg.GetUserBaseInfo(from.UserId, header.CompanyId); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
} else {
|
|
|
item = protocol.AchievementItem{
|
|
|
Id: from.AchievementId,
|
|
|
Provider: provider,
|
|
|
CreateTime: from.CreateTime.Unix() * 1000,
|
|
|
Content: from.SourceContent,
|
|
|
GraspScore: from.GraspScore,
|
|
|
}
|
|
|
jsonUnmarshal(from.Images, &item.Pictures)
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//获取统计数据
|
|
|
func GetStatisticData(header *protocol.RequestHeader, from protocol.StaticDataOrm, sourceId int64) (chanceData protocol.ChanceData) {
|
|
|
chanceData = protocol.ChanceData{
|
|
|
ThumbsUpTotal: from.ZanTotal,
|
|
|
CommentTotal: from.CommentTotal,
|
|
|
PageViewTotal: from.ViewTotal,
|
|
|
}
|
|
|
chanceData.IsThumbsUp, chanceData.IsCollect, _ = getMarkFlag(header, sourceId, protocol.SourceTypeAchievement)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//我把握的
|
|
|
func MyGrasp(header *protocol.RequestHeader, request *protocol.MyGraspRequest) (rsp *protocol.MyGraspResponse, err error) {
|
|
|
var (
|
|
|
achievementPool *protocol.AchievementPoolResponse
|
|
|
)
|
|
|
request.UserId = header.UserId
|
|
|
if achievementPool, err = AchievementPool(header, &request.AchievementPoolRequest); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
rsp = &protocol.MyGraspResponse{}
|
|
|
rsp.AchievementPoolResponse = *achievementPool
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//成果详情
|
|
|
func AchievementDetail(header *protocol.RequestHeader, request *protocol.AchievementDetailRequest) (rsp *protocol.AchievementDetailResponse, err error) {
|
|
|
var (
|
|
|
items []protocol.CommAchievementItemOrm
|
|
|
participants []*models.AchievementProvider
|
|
|
)
|
|
|
if err = models.GetCommAchievementItemOrmId(request.Id, &items); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if len(items) == 0 {
|
|
|
err = protocol.NewErrWithMessage(1)
|
|
|
log.Error("items not empty", request.Id)
|
|
|
return
|
|
|
}
|
|
|
item := items[0]
|
|
|
if item.Status != 1 {
|
|
|
//错误 成果删除或关闭
|
|
|
}
|
|
|
rsp = &protocol.AchievementDetailResponse{}
|
|
|
{
|
|
|
rsp.Achievement = GetAchievementItem(header, item)
|
|
|
rsp.StatisticData = GetStatisticData(header, item.StaticDataOrm, item.AchievementId)
|
|
|
rsp.ChanceTemplate = getTemplate(item.TemplateId)
|
|
|
rsp.ChanceType = getChanceType(item.ChanceTypeId)
|
|
|
}
|
|
|
|
|
|
if participants, err = models.GetAchievementProviders(request.Id); err != nil && err != orm.ErrNoRows {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
newParticipant := func(user *protocol.BaseUserInfo, score float64, t int) protocol.UserGraspInfo {
|
|
|
return protocol.UserGraspInfo{
|
|
|
Provider: user,
|
|
|
GraspScore: score,
|
|
|
Type: t,
|
|
|
}
|
|
|
}
|
|
|
addParticipants := func(item protocol.UserGraspInfo) {
|
|
|
rsp.Participants = append(rsp.Participants, item)
|
|
|
}
|
|
|
addParticipants(newParticipant(rsp.Achievement.Provider, item.UserGraspScore, protocol.Grasper))
|
|
|
for i := range participants {
|
|
|
p := participants[i]
|
|
|
if provider, e := agg.GetUserBaseInfo(p.UserCompanyId, header.CompanyId); e != nil {
|
|
|
log.Error(e)
|
|
|
return
|
|
|
} else {
|
|
|
addParticipants(newParticipant(provider, p.UserGraspScore, protocol.Provider))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//查看数量
|
|
|
utils.ExecuteSqlByRoll(true, agg.GetIncrementSql((&models.Achievement{}).TableName(), "view_total", 1, request.Id))
|
|
|
|
|
|
return
|
|
|
} |
...
|
...
|
|