作者 yangfu

消息 我提交的

... ... @@ -130,7 +130,7 @@ where user_id=? and company_id=? and review_status in (%v)
func GetChanceMyApproveChance(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from (
select a.*,b.user_id,b.source_content,b.enable_status,b.review_status,b.create_at,b.update_at,b.approve_time chance_approve_time from (
select id,approve_time,approve_data,uid,chance_id,approve_message,create_at process_create_time
select id,approve_time,approve_data,uid,chance_id,approve_message,update_at process_create_time
from audit_flow_process where uid=? and enable_status =1 and review_status in (%v) and (?=0 or id<?)
)a left outer join chance b on a.chance_id = b.id
)a left outer join chance_data b on a.chance_id =b.chance_id
... ...
... ... @@ -183,7 +183,7 @@ func GetUserMsgsBulletin(userId, companyId int64, msgType int, lastId int64, pag
func GetChanceMsg(uid, lastId int64, pageSize int, msgType int, v interface{}) (total int, err error) {
sql := `select a.*,b.images,b.speechs,b.videos from (
select a.*,b.source_content,b.enable_status,b.user_id chance_user_id,b.create_at,b.review_status,b.approve_data from (
select id,company_id,receive_user_id,message,source_id,is_read,chance_id,create_at msg_time,data
select id,company_id,receive_user_id,message,source_id,is_read,chance_id,create_at msg_time,data,sender_user_id
from user_msg where receive_user_id=? and source_type=1 and (?=0 or id<?) and msg_type=?
)a left outer join chance b on a.source_id = b.id
)a left outer join chance_data b on a.source_id =b.chance_id
... ...
... ... @@ -271,6 +271,7 @@ type MsgChanceApproveItemOrm struct {
Id int64 `orm:"column(id)"` //消息id
MsgTime time.Time `orm:"column(msg_time)"`
ReceiveUserId int64 `orm:"column(receive_user_id)"`
SenderUserId int64 `orm:"column(sender_user_id)"`
CreateTime time.Time `orm:"column(create_at)"`
Message string `orm:"column(message)"`
IsRead int64 `orm:"column(is_read)"`
... ...
... ... @@ -67,11 +67,34 @@ func SendApproveMsg(receiverId int64, name string, companyId int64, chanceId int
}
//发送审批消息
func SendApproveMsgByFormat(receiverId int64, name string, companyId int64, chanceId int64, chanceTypeId int, format string, data protocol.MsgData) (err error) {
func SendApproveMsgWithHeader(header *protocol.RequestHeader, receiverId int64, chanceId int64, chanceTypeId int, reviewStatus int, msgType int, data protocol.MsgData) (err error) {
return sendApproveMsg(header, receiverId, "", header.CompanyId, chanceId, chanceTypeId, reviewStatus, msgType, data)
}
//发送审批消息
func sendApproveMsg(header *protocol.RequestHeader, receiverId int64, name string, companyId int64, chanceId int64, chanceTypeId int, reviewStatus int, msgType int, data protocol.MsgData) (err error) {
var (
userMsg *models.UserMsg
chanceType *models.ChanceType
format string
)
switch reviewStatus {
case protocol.ReviewStatusAuditging:
format = MessageApproving
break
case protocol.ReviewStatusReturn:
format = MessageApproveReject
break
case protocol.ReviewStatusPass:
format = MessageApproveSuccess
break
case protocol.ReviewStatusAutoPass:
format = MessageApproveAutoPass
break
default:
format = MessageApproving
break
}
if chanceType, err = models.GetChanceTypeById(chanceTypeId); err != nil {
return
}
... ... @@ -79,18 +102,51 @@ func SendApproveMsgByFormat(receiverId int64, name string, companyId int64, chan
Id: idgen.Next(),
CompanyId: companyId,
ReceiveUserId: receiverId,
MsgType: protocol.MsgTypeAuditBy,
MsgType: msgType,
Message: fmt.Sprintf(format, chanceType.Name),
SourceId: chanceId,
SourceType: protocol.SourceTypeChance,
IsPublic: 0,
CreateAt: time.Now(),
ChanceId: chanceId,
Data: common.AssertJson(data),
}
if header != nil {
userMsg.SenderUserId = header.UserId
}
if _, err = models.AddUserMsg(userMsg); err != nil {
return
}
logMsgWithHeaer(header, userMsg, name)
return
}
//发送审批消息
func SendApproveMsgByFormat(header *protocol.RequestHeader, receiverId int64, chanceId int64, message string, data protocol.MsgData) (err error) {
var (
userMsg *models.UserMsg
//chanceType *models.ChanceType
)
//if chanceType, err = models.GetChanceTypeById(chanceTypeId); err != nil {
// return
//}
userMsg = &models.UserMsg{
Id: idgen.Next(),
CompanyId: header.CompanyId,
ReceiveUserId: receiverId,
MsgType: protocol.MsgTypeAuditBy,
Message: message, //fmt.Sprintf(message, chanceType.Name),
SourceId: chanceId,
SourceType: protocol.SourceTypeChance,
IsPublic: 0,
CreateAt: time.Now(),
Data: common.AssertJson(data),
SenderUserId: header.UserId,
}
if _, err = models.AddUserMsg(userMsg); err != nil {
return
}
logMsg(userMsg, name)
logMsg(userMsg, "")
return
}
... ... @@ -211,6 +267,11 @@ func logMsg(msg *models.UserMsg, name string) {
msg.MsgType, msg.ReceiveUserId, name, msg.Message, msg.SourceId, msg.SourceType))
}
func logMsgWithHeaer(header *protocol.RequestHeader, msg *models.UserMsg, name string) {
log.Info(fmt.Sprintf("发送消息 消息类型:%v Receiver:%v(%v) Message:%v SourceId:%v SourceType:%v 发送人:%v",
msg.MsgType, msg.ReceiveUserId, name, msg.Message, msg.SourceId, msg.SourceType, header.UserId))
}
//保查审核日志
func SaveApproveLog(orm orm.Ormer, code int, userId int64, chanceId int64, param ...interface{}) (err error) {
var (
... ...
... ... @@ -351,6 +351,7 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
log.Info(fmt.Sprintf("用户%v 更新机会审核状态 process_id:%v 状态:%v", header.UserId, process.Id, request.ReviewStatus))
orm := orm.NewOrm()
orm.Begin()
//退回同时生成一条提交记录
if request.ReviewStatus == protocol.ReviewStatusReturn {
mapChance["ReviewStatus"] = int8(request.ReviewStatus) //退回也要更新审核状态
//增加一条待处理记录到审核列表
... ... @@ -362,10 +363,9 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
}
}
{
//更新下一批次的审核
//发送审核消息给提交机会的
var nextApprovers []int64
if err = agg.SendApprovedMsg(chance.UserId, "",
header.CompanyId, chance.Id, chance.ChanceTypeId, request.ReviewStatus, protocol.MsgTypeAuditBy, protocol.MsgData{Score: &request.ApproveData.Score}); err != nil {
if err = agg.SendApproveMsgWithHeader(header, chance.UserId, chance.Id, chance.ChanceTypeId, request.ReviewStatus, protocol.MsgTypeAuditBy, protocol.MsgData{Score: &request.ApproveData.Score}); err != nil {
log.Error(err)
orm.Rollback()
return
... ...
... ... @@ -474,8 +474,8 @@ func setChanceAutoPass(header *protocol.RequestHeader, chance *models.Chance, or
chance.ApproveTime = time.Now()
chance.ReviewStatus = protocol.ReviewStatusPass
msgData := protocol.MsgData{Score: &approveData.Score}
if err = agg.SendApproveMsgByFormat(chance.UserId, "",
header.CompanyId, chance.Id, chance.ChanceTypeId, fmt.Sprintf(agg.MessageApproveAutoPass, chanceType.Name), msgData); err != nil {
//发送给机会提交人
if err = agg.SendApproveMsgByFormat(header, chance.UserId, chance.Id, fmt.Sprintf(agg.MessageApproveAutoPass, chanceType.Name), msgData); err != nil {
log.Error(err)
return
}
... ... @@ -1431,7 +1431,7 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove
//CreateTime: chance.CreateTime.Unix() * 1000,
}
if item.ApproveTime < 0 {
item.ApproveTime = 0
item.ApproveTime = chance.UpdateTime.Unix() * 1000
}
jsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = clearEmptyForm(item.FormList)
... ... @@ -1449,6 +1449,9 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove
//审核过的才有审核时间
if request.ReviewStatus != protocol.ReviewStatusAuditging {
approve.ApproveTime = chance.ApproveTime.Unix() * 1000
if approve.ApproveTime < 0 {
approve.ApproveTime = chance.ChanceApproveTime.Unix() * 1000
}
}
commItem.Approve = approve
//审核完有审核数据
... ...
... ... @@ -328,8 +328,11 @@ func MsgChanceSubmit(header *protocol.RequestHeader, request *protocol.MsgChance
} else if chance.ChanceEnableStatus == 0 { //机会关闭
commItem.ChanceStatus = protocol.ChanceStatusClose
}
if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {
approveUserId := chance.ChanceUserId
if chance.SenderUserId != 0 {
approveUserId = chance.SenderUserId
}
if provider, err = agg.GetUserBaseInfo(approveUserId, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(err)
continue
... ...