作者 yangfu

审核消息发送

... ... @@ -23,7 +23,7 @@ yunpian_app_key ="0bf6fb10a11a68a95dee80901eb545b5"
#存储 http://ability.fjmaimaimai.com:8080/
source_host ="http://mmm-opp-dev.fjmaimaimai.com/"
source_virtual_path=file/opp
source_path ="${aliyun_file_access||/var/www/opp/file}
source_path =/var/www/opp/file
#网易云信 IM
net_im_base_url ="https://api.netease.im/nimserver"
... ...
... ... @@ -39,6 +39,13 @@ var errmessge ErrorMap = map[int]string{
5201: "该机会模板未配置审批人,请选择其他模板",
}
const (
MsgTypeBulletin = 1 //公告
MsgTypeCommend = 2 //表彰
MsgTypeInteraction = 4 //互动消息
MsgTypeAudit = 8 //机会审核
)
/*MessageCenter */
type MessageCenterRequest struct {
MsgType int `json:"msgType" valid:"Required"`
... ...
package agg
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/idgen"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/models"
"opp/protocol"
"time"
)
var (
MessageApprove = "提交了一条%v机会消息,需要您审核"
)
//发送审批消息
func SendApproveMsg(receiverId int64, name string, companyId int64, chanceId int64, chanceTypeId int) (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: companyId,
ReceiveUserId: receiverId,
MsgType: protocol.MsgTypeAudit,
Message: fmt.Sprintf(MessageApprove, chanceType.Name),
SourceId: chanceId,
SourceType: protocol.SourceTypeChance,
IsPublic: 0,
CreateAt: time.Now(),
}
if _, err = models.AddUserMsg(userMsg); err != nil {
return
}
logMsg(userMsg, name)
return
}
//打印消息日志
func logMsg(msg *models.UserMsg, name string) {
log.Info(fmt.Sprintf("发送消息 消息类型:%v Receiver:%v(%v) Message:%v SourceId:%v SourceType:%v",
msg.MsgType, msg.ReceiveUserId, name, msg.Message, msg.SourceId, msg.SourceType))
}
... ...
... ... @@ -30,10 +30,10 @@ type SuplusApprove struct {
}
//新增审批实例
func (s SuplusApprove) NewApproveInstance(header *protocol.RequestHeader, process []*models.AuditFlowProcess) (err error) {
func (s SuplusApprove) NewApproveInstance(header *protocol.RequestHeader, process []*models.AuditFlowProcess) (response NewApproveInstanceResponse, err error) {
var (
request NewApproveInstanceRequest
response NewApproveInstanceResponse
request NewApproveInstanceRequest
//response NewApproveInstanceResponse
mapApproves map[int]*Approve = make(map[int]*Approve)
relativeId int64
userCompany *models.UserCompany
... ... @@ -85,8 +85,6 @@ func (s SuplusApprove) NewApproveInstance(header *protocol.RequestHeader, proces
approve.ApproveUsers = append(approve.ApproveUsers, ApproveUsers{
Uid: item.Uid,
Name: approver.NickName,
//RoleId:5,
RoleId: 0,
})
}
request.RelativeId = relativeId
... ... @@ -193,25 +191,42 @@ type NewApproveInstanceRequest struct {
RelativeId int64 `json:"relativeId"` //关联id
}
type NewApproveInstanceResponse interface{}
type NewApproveInstanceResponse struct {
MessageData []MessageDataItem `json:"messageData"`
}
//审批节点
type Approve struct {
ApproveWay int `json:"approveWay"` //审批方式 1 会签 2 或签 3 发起人从角色成员中自选
ApproveType int `json:"approveType"` //审批类型 1 业务区域负责人 2 指定成员 3 角色
IsDefault int `json:"isDefault"` //1 是默认 0 不是
RoleName string `json:"roleName"` //角色名/负责人
RoleId int `json:"roleId"` //角色id
ApproveUsers []ApproveUsers `json:"approveUsers"` //审批人
}
//审批人
type ApproveUsers struct {
Uid int64 `json:"uid"` //用户id
Name string `json:"name"` //用户名
IsDefault int `json:"isDefault"` //1 是默认 0 不是
RoleName string `json:"roleName"` //角色名/负责人
RoleId int `json:"roleId"` //角色id
Uid int64 `json:"uid"` //用户id
Name string `json:"name"` //用户名
ParentIds []int `json:"parentIds"`
}
//审批 消息列表
type MessageDataItem struct {
MessageContent contentItem `json:"messageContent"`
ReceiverInfo receiverInfo `json:"receiverInfo"`
}
type contentItem struct {
ApproveInstanceId int `json:"approveInstanceId"` //审批实例-id
ApproveProcessId int `json:"approveProcessId"` //审批进程节点-id
RelativeId int `json:"relativeId"` //机会编号
}
type receiverInfo struct {
ReceiverUid int64 `json:"receiverUid"` //用户id
ReceiverName string `json:"receiverName"` //接收人
}
/*ApproveItem 审批操作*/
type ApproveItemRequest struct {
RelativeId int64 `json:"relativeId"` //关联id
... ...
... ... @@ -269,10 +269,23 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit
}
}
if len(auditFlows) > 0 {
if err = suplusApprove.NewApproveInstance(header, auditFlows); err != nil {
log.Error(fmt.Sprintf("uid:%v", header.UserId), "request suplus-approve.NewApproveInstance err", err)
//7.发送审批实例给审批服务器
if m, e := suplusApprove.NewApproveInstance(header, auditFlows); e != nil {
log.Error(fmt.Sprintf("uid:%v", header.UserId), "request suplus-approve.NewApproveInstance err", e)
orm.Rollback()
err = e
return
} else {
//7.发送消息通知给审核人(审核消息)
for i := range m.MessageData {
message := m.MessageData[i]
if err = agg.SendApproveMsg(message.ReceiverInfo.ReceiverUid, message.ReceiverInfo.ReceiverName,
header.CompanyId, chance.Id, chance.ChanceTypeId); err != nil {
log.Error(err)
orm.Rollback()
return
}
}
}
}
... ... @@ -295,8 +308,6 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit
}
orm.Commit()
//6.激活审核流
//TODO:7.发送消息通知给审核人(审核消息)
rsp = &protocol.ChanceSubmitResponse{}
return
}
... ... @@ -342,21 +353,6 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceSubmit
}
}
//4.查询审核配置
//5.生成审核流 删除旧的 生成新的
//if auditFlows, err = GenAuditFlowProcess(header, chance.Id, template.Id, auditConfig); err != nil {
// log.Error(err)
// orm.Rollback()
// return
//}
//for i := 0; i < len(auditFlows); i++ {
// if _, err = orm.Insert(auditFlows[i]); err != nil {
// log.Error(err)
// orm.Rollback()
// return
// }
//}
//6.更新文件
{
if chanceData, err = models.GetChanceDataByChanceId(chance.Id); err == nil {
... ...