作者 yangfu

把握分修改

... ... @@ -242,3 +242,24 @@ func (this *MessageController) MsgChanceThumbUp() {
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(message.MsgChanceThumbUp(header, request))
}
//MsgChanceRevise 消息中心-机会补充
//@router /msgChanceRevise [post]
func (this *MessageController) MsgChanceRevise() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.MsgChanceReviseRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(message.MsgChanceRevise(header, request))
}
... ...
package models
import (
"time"
"github.com/astaxie/beego/orm"
)
type ChanceReviseLog struct {
Id int64 `orm:"column(id);pk" description:"id 主键"`
ChanceId int64 `orm:"column(chance_id)" description:"机会编号"`
UserCompanyId int64 `orm:"column(user_company_id);null" description:"用户编号 编辑机会的人"`
Data string `orm:"column(data);null" description:"机会数据"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
}
func (t *ChanceReviseLog) TableName() string {
return "chance_revise_log"
}
func init() {
orm.RegisterModel(new(ChanceReviseLog))
}
// AddChanceReviseLog insert a new ChanceReviseLog into database and returns
// last inserted Id on success.
func AddChanceReviseLog(m *ChanceReviseLog) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetChanceReviseLogById retrieves ChanceReviseLog by Id. Returns error if
// Id doesn't exist
func GetChanceReviseLogById(id int64) (v *ChanceReviseLog, err error) {
o := orm.NewOrm()
v = &ChanceReviseLog{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
... ...
... ... @@ -14,6 +14,11 @@ type AchievementItem struct {
Provider *BaseUserInfo `json:"provider"`
Content string `json:"content"`
Pictures []Picture `json:"pictures"`
//GraspScore float64 `json:"graspScore"` //把握分
//GraspScorePercent float64 `json:"graspScorePercent"` //把握分百分比
}
type GraspScore struct {
GraspScore float64 `json:"graspScore"` //把握分
GraspScorePercent float64 `json:"graspScorePercent"` //把握分百分比
}
... ... @@ -24,6 +29,7 @@ type AchievementCommonListItem struct {
StatisticData interface{} `json:"statisticData,omitempty"` //统计数据(是否收藏/点赞 浏览数 点赞总数 评论数)ChanceData
//我审核的-通过
Score interface{} `json:"score,omitempty"`
GraspScore interface{} `json:"graspScore,omitempty"` //把握分
//模板
ChanceType interface{} `json:"chanceType,omitempty"` //机会类型
ChanceTemplate interface{} `json:"template,omitempty"` //机会模板
... ... @@ -96,6 +102,7 @@ type AchievementDetailRequest struct {
}
type AchievementDetailResponse struct {
Achievement AchievementItem `json:"achievement,omitempty"` //成果详情
GraspScore interface{} `json:"graspScore,omitempty"` //把握分
StatisticData interface{} `json:"statisticData,omitempty"` //统计数据(是否收藏/点赞 浏览数 点赞总数 评论数
//模板
ChanceType interface{} `json:"chanceType,omitempty"` //机会类型
... ... @@ -107,8 +114,8 @@ type AchievementDetailResponse struct {
type UserGraspInfo struct {
Provider *BaseUserInfo `json:"provider"`
GraspScore float64 `json:"graspScore"` //把握分
GraspScorePercent float64 `json:"graspScorePercent"` //把握分百分比
GraspScore GraspScore `json:"graspScore"` //把握分
//GraspScorePercent float64 `json:"graspScorePercent"` //把握分百分比
Type int `json:"type"` //1:把握人 2:提供者
}
... ...
... ... @@ -332,6 +332,24 @@ type ChanceCommentItemOrm struct {
SenderUserId int64 `orm:"column(sender_user_id)"`
}
//我的评论
type ChanceReviseItemOrm struct {
CommChanceItemOrm
MsgItemOrm
}
//消息
type MsgItemOrm struct {
MsgId int64 `orm:"column(msg_id)"`
MsgTime time.Time `orm:"column(msg_time)"` //收藏时间
//评论对象类型
SourceType int `orm:"column(source_type)"`
SourceId int64 `orm:"column(source_id)"`
IsRead int64 `orm:"column(is_read)"`
ReceiveUserId int64 `orm:"column(receive_user_id)"`
SenderUserId int64 `orm:"column(sender_user_id)"`
}
//通用 机会orm对象
type CommChanceItemOrm struct {
ChanceId int64 `orm:"column(chance_id)"`
... ... @@ -544,11 +562,16 @@ type MsgCommonListItem struct {
CommentedData interface{} `json:"commentedData,omitempty"`
SourceType int `json:"sourceType,omitempty"` //类型 1:机会 2:评论
SourceId int64 `json:"sourceId,omitempty"` //类型 1:机会 2:评论
ChanceStatus int `json:"chanceStatus"` //0:正常 1.删除 2.关闭
ReviewStatus int `json:"reviewStatus"` //审核状态
IsRead bool `json:"isRead"`
ChanceId int64 `json:"chanceId"` //机会编号
ChanceReviseLogId int64 `json:"chanceReviseLogId,omitempty"` //机会补充编号
}
type MsgItem struct {
}
type ChanceItem struct {
Id int64 `json:"id"`
... ...
... ... @@ -3,9 +3,10 @@ package protocol
const (
SourceTypeChance = 1 //机会
SourceTypeComment = 2 //机会评论
SourceTypeBulletin = 3
SourceTypeBulletin = 3 //公告
SourceTypeAchievement = 4 //成果
SourceTypeAchievementComment = 5 //成果评论
SourceTypeChanceReviseLog = 6 //机会变更
)
/*IComment */
... ...
... ... @@ -72,6 +72,7 @@ const (
MsgTypeAuditBy = 16 //机会被审核消息-我提交的
MsgTypeComment = 32 //评论
MsgTypeThumbUp = 64 //点赞
MsgTypeChanceRevise = 128 //补充机会
)
var (
... ... @@ -81,6 +82,7 @@ var (
MessageZanChance = "点赞了您发布的机会"
MessageZanComment = "点赞了您发布的评论"
MessageChanceRevise = "补充了您发布的%v机会信息"
)
/*MessageCenter */
... ... @@ -258,6 +260,16 @@ type MsgChanceThumbUpResponse struct {
Total int `json:"total"`
}
/*MsgChanceRevise 消息中心-机会补充*/
type MsgChanceReviseRequest struct {
LastId int64 `json:"lastId"`
PageSize int `json:"pageSize" valid:"Required"`
}
type MsgChanceReviseResponse struct {
List []MsgCommonListItem `json:"list"`
Total int `json:"total"`
}
//我的审核机会列表
type MsgChanceApproveItemOrm struct {
ChanceUserId int64 `orm:"column(chance_user_id)"`
... ...
... ... @@ -393,6 +393,14 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"],
beego.ControllerComments{
Method: "MsgChanceRevise",
Router: `/msgChanceRevise`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"],
beego.ControllerComments{
Method: "MsgChanceSubmit",
Router: `/msgChanceSubmit`,
AllowHTTPMethods: []string{"post"},
... ...
... ... @@ -3,6 +3,7 @@ package agg
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/internal/utils"
"opp/models"
"opp/protocol"
)
... ... @@ -197,3 +198,41 @@ func ValidChancePermission(uid, cid int64, items []*protocol.CommonListItem) (er
}
return
}
//设置机会详情
func SetChanceItem(header *protocol.RequestHeader, chance protocol.CommChanceItemOrm) (item protocol.ChanceItem, chanceStatus int) {
var provider *protocol.BaseUserInfo
var err error
if provider, err = GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {
chanceStatus = protocol.ChanceStatusDelete
log.Error(err)
return
}
if len(chance.SourceContent) == 0 || chance.ChanceEnableStatus == 0 { //机会删除
chanceStatus = protocol.ChanceStatusDelete
}
if chance.Status == models.ChanceStatusClose { //机会关闭
chanceStatus = protocol.ChanceStatusClose
return
}
item = protocol.ChanceItem{
Id: chance.ChanceId,
Provider: provider,
CreateTime: chance.CreateTime.Unix() * 1000,
//PublicStatus: chance.PublishStatus,
}
utils.JsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = ClearEmptyForm(item.FormList)
utils.JsonUnmarshal(chance.Images, &item.Pictures)
utils.JsonUnmarshal(chance.Voices, &item.Speechs)
utils.JsonUnmarshal(chance.Videos, &item.Videos)
return item, chanceStatus
}
func SetMsgItem(header *protocol.RequestHeader, msg protocol.MsgItemOrm, commItem *protocol.MsgCommonListItem) {
commItem.MsgId = msg.MsgId
commItem.MsgTime = msg.MsgTime.Unix() * 1000
commItem.IsRead = msg.IsRead == 1
commItem.SourceId = msg.SourceId
}
... ...
... ... @@ -44,6 +44,10 @@ func AchievementPool(header *protocol.RequestHeader, request *protocol.Achieveme
item := ormItems[i]
rspItem := &protocol.AchievementCommonListItem{
Achievement: GetAchievementItem(header, item),
GraspScore: protocol.GraspScore{
GraspScore: item.GraspScore,
GraspScorePercent: item.GraspScore,
},
StatisticData: GetStatisticData(header, item.StaticDataOrm, item.AchievementId),
ChanceTemplate: getTemplate(item.TemplateId),
ChanceType: getChanceType(item.ChanceTypeId),
... ... @@ -69,8 +73,8 @@ func GetAchievementItem(header *protocol.RequestHeader, from protocol.CommAchiev
Provider: provider,
CreateTime: from.CreateTime.Unix() * 1000,
Content: from.SourceContent,
GraspScore: from.GraspScore,
GraspScorePercent: from.GraspScore,
//GraspScore: from.GraspScore,
//GraspScorePercent: from.GraspScore,
}
jsonUnmarshal(from.Images, &item.Pictures)
}
... ... @@ -127,6 +131,10 @@ func AchievementDetail(header *protocol.RequestHeader, request *protocol.Achieve
rsp = &protocol.AchievementDetailResponse{}
{
rsp.Achievement = GetAchievementItem(header, item)
rsp.GraspScore = protocol.GraspScore{
GraspScore: item.GraspScore,
GraspScorePercent: item.GraspScore,
}
rsp.StatisticData = GetStatisticData(header, item.StaticDataOrm, item.AchievementId)
rsp.ChanceTemplate = getTemplate(item.TemplateId)
rsp.ChanceType = getChanceType(item.ChanceTypeId)
... ... @@ -139,8 +147,10 @@ func AchievementDetail(header *protocol.RequestHeader, request *protocol.Achieve
newParticipant := func(user *protocol.BaseUserInfo, score float64, t int) protocol.UserGraspInfo {
return protocol.UserGraspInfo{
Provider: user,
GraspScore: protocol.GraspScore{
GraspScore: score,
GraspScorePercent: score,
},
Type: t,
}
}
... ... @@ -168,43 +178,16 @@ func AchievementDetail(header *protocol.RequestHeader, request *protocol.Achieve
for i := range chances {
chance := chances[i]
commItem := &protocol.CommonListItem{}
commItem.Chance, commItem.ChanceStatus = SetChanceItem(header, chance.CommChanceItemOrm)
commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, chance.CommChanceItemOrm)
//commItem.ChanceTemplate = getTemplate(chance.TemplateId)
//commItem.ChanceType = getChanceType(chance.ChanceTypeId)
//commItem.Score=protocol.GraspScore{
// GraspScore:chance.,
// GraspScorePercent:chance.GraspScore,
//}
commItem.ChanceId = chance.ChanceId
rsp.SourceChance = append(rsp.SourceChance, commItem)
}
agg.ValidChancePermission(header.UserId, header.CompanyId, rsp.SourceChance)
return
}
//设置机会详情
func SetChanceItem(header *protocol.RequestHeader, chance protocol.CommChanceItemOrm) (item protocol.ChanceItem, chanceStatus int) {
var provider *protocol.BaseUserInfo
var err error
if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {
chanceStatus = protocol.ChanceStatusDelete
log.Error(err)
return
}
if len(chance.SourceContent) == 0 || chance.ChanceEnableStatus == 0 { //机会删除
chanceStatus = protocol.ChanceStatusDelete
}
if chance.Status == models.ChanceStatusClose { //机会关闭
chanceStatus = protocol.ChanceStatusClose
return
}
item = protocol.ChanceItem{
Id: chance.ChanceId,
Provider: provider,
CreateTime: chance.CreateTime.Unix() * 1000,
//PublicStatus: chance.PublishStatus,
}
jsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = clearEmptyForm(item.FormList)
jsonUnmarshal(chance.Images, &item.Pictures)
jsonUnmarshal(chance.Voices, &item.Speechs)
jsonUnmarshal(chance.Videos, &item.Videos)
return item, chanceStatus
}
... ...
... ... @@ -12,6 +12,7 @@ import (
"opp/models"
"opp/protocol"
"opp/services/agg"
"reflect"
"strings"
"time"
)
... ... @@ -576,6 +577,9 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate
return
}
auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover}
go CheckChanceUpdate(header, chance, request)
orm := orm.NewOrm()
orm.Begin()
//6.更新文件
... ... @@ -707,6 +711,142 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate
return
}
//检查机会更新
func CheckChanceUpdate(header *protocol.RequestHeader, chance *models.Chance, request *protocol.ChanceUpdateRequest) {
var (
//chanceData *models.ChanceData
isSaveLog bool = false
chanceReviseLog *models.ChanceReviseLog
message string
)
defer func() {
if p := recover(); p != nil {
log.Error(p)
} else {
log.Debug("")
}
}()
if header.UserId == chance.UserId {
return
}
type ChanceModifyLog struct {
DiffContents interface{} `json:"diffContents"`
Speechs []protocol.Speech `json:"speechs"`
Pictures []protocol.Picture `json:"pictures"`
Videos []protocol.Video `json:"videos"`
}
var modifyLog = ChanceModifyLog{}
diffFormList := func(source string, dis []*protocol.Form) {
type DiffContent struct {
Content string `json:"content"`
}
var (
src []*protocol.Form
mapForm map[string]*protocol.Form = make(map[string]*protocol.Form)
diffStructs = []DiffContent{}
)
jsonUnmarshal(source, &src)
for i := range src {
mapForm[src[i].Label] = src[i]
}
for i := range dis {
isDiff := false
srcValue := ""
if v, ok := mapForm[dis[i].Label]; ok {
srcValue = v.Value
if dis[i].Value != v.Value {
isDiff = true
}
} else {
isDiff = true
}
if isDiff {
diffStructs = append(diffStructs, DiffContent{
Content: fmt.Sprintf("将“%v”由“%v”改为 “%v“", dis[i].Label, srcValue, dis[i].Value)})
if !isSaveLog {
isSaveLog = true
}
}
}
modifyLog.DiffContents = diffStructs
}
diffChanceData := func() {
var (
speechs []protocol.Speech
pictures []protocol.Picture
videos []protocol.Video
)
if chanceData, e := models.GetChanceDataByChanceId(chance.Id); e == nil {
jsonUnmarshal(chanceData.Speechs, &speechs)
jsonUnmarshal(chanceData.Images, &pictures)
jsonUnmarshal(chanceData.Videos, &videos)
if !reflect.DeepEqual(request.Videos, videos) || !reflect.DeepEqual(request.Pictures, pictures) {
if !isSaveLog {
isSaveLog = true
}
modifyLog.Videos = request.Videos
}
if !reflect.DeepEqual(request.Pictures, pictures) {
if !isSaveLog {
isSaveLog = true
}
modifyLog.Pictures = request.Pictures
}
if !reflect.DeepEqual(request.Speechs, speechs) {
if !isSaveLog {
isSaveLog = true
}
modifyLog.Speechs = request.Speechs
}
} else {
if !isSaveLog {
isSaveLog = true
}
modifyLog.Speechs = request.Speechs
modifyLog.Videos = request.Videos
modifyLog.Speechs = request.Speechs
}
}
diffFormList(chance.SourceContent, request.FormList)
diffChanceData()
if isSaveLog {
orm := orm.NewOrm()
orm.Begin()
//保存修改详情
chanceReviseLog = &models.ChanceReviseLog{
Id: idgen.Next(),
ChanceId: chance.Id,
UserCompanyId: header.UserId,
Data: common.AssertJson(modifyLog),
CreateAt: time.Now(),
}
if _, e := orm.Insert(chanceReviseLog); e != nil {
log.Error(e)
orm.Rollback()
return
}
if chanceType, err := models.GetChanceTypeById(chance.ChanceTypeId); err != nil {
log.Error(err)
orm.Rollback()
return
} else {
message = fmt.Sprintf(protocol.MessageChanceRevise, chanceType.Name)
}
//发送修改机会消息
if err := agg.SendMsgWithHeader(header, chance.UserId, "", chanceReviseLog.Id, protocol.SourceTypeChanceReviseLog, message, protocol.MsgTypeChanceRevise, chance.Id); err != nil {
log.Error(err)
orm.Rollback()
return
}
//TODO:保存变更日志
orm.Commit()
}
}
//修改公开状态
func ChanceChangePublish(header *protocol.RequestHeader, request *protocol.ChanceChangePublishRequest) (rsp *protocol.ChanceChangePublishResponse, err error) {
var (
... ...
... ... @@ -586,6 +586,37 @@ func MsgChanceThumbUp(header *protocol.RequestHeader, request *protocol.MsgChanc
return
}
//消息中心-机会补充
func MsgChanceRevise(header *protocol.RequestHeader, request *protocol.MsgChanceReviseRequest) (rsp *protocol.MsgChanceReviseResponse, err error) {
var (
myChances []protocol.ChanceReviseItemOrm
total int
)
if total, err = models.GetChanceCommentMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeThumbUp, &myChances); err != nil {
if err == orm.ErrNoRows {
err = nil
return
}
log.Error(err)
return
}
rsp = &protocol.MsgChanceReviseResponse{Total: total}
rsp.List = make([]protocol.MsgCommonListItem, 0)
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
commItem := protocol.MsgCommonListItem{}
commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, chance.CommChanceItemOrm)
agg.SetMsgItem(header, chance.MsgItemOrm, &commItem)
commItem.ChanceId = chance.ChanceId
commItem.ReviewStatus = chance.ReviewStatus
//commItem.ChanceReviseLogId = chance.SourceId
rsp.List = append(rsp.List, commItem)
}
return
}
//H5公告详情
func H5Announcement(header *protocol.RequestHeader, request *protocol.AnnouncementRequest) (rsp *protocol.AnnouncementResponse, err error) {
var (
... ...