...
|
...
|
@@ -27,6 +27,7 @@ func Favorite(header *protocol.RequestHeader, request *protocol.FavoriteRequest) |
|
|
header.CompanyId,
|
|
|
request.ObjectType,
|
|
|
request.ChanceType,
|
|
|
0,
|
|
|
request.LastId,
|
|
|
request.PageSize)
|
|
|
if err != nil {
|
...
|
...
|
@@ -62,10 +63,13 @@ func SympathyAction(header *protocol.RequestHeader, request *protocol.SympathyAc |
|
|
exists bool
|
|
|
chanceFavoirte *models.ChanceFavorite
|
|
|
chance *models.Chance
|
|
|
comment *models.Comment
|
|
|
chanceType int
|
|
|
incre int = 1
|
|
|
table string = "comment"
|
|
|
message string = protocol.MessageZanComment
|
|
|
sourceId int64
|
|
|
userId int64
|
|
|
)
|
|
|
rsp = &protocol.SympathyActionResponse{}
|
|
|
if chanceFavoirte, err = models.GetChanceFavorite(header.UserId, header.CompanyId, request.Id, request.SourceType); err != nil && err != orm.ErrNoRows {
|
...
|
...
|
@@ -75,11 +79,26 @@ func SympathyAction(header *protocol.RequestHeader, request *protocol.SympathyAc |
|
|
if request.SourceType == protocol.SourceTypeChance {
|
|
|
message = protocol.MessageZanChance
|
|
|
if chance, err = models.GetChanceById(request.Id); err != nil {
|
|
|
log.Error("机会不存在", err)
|
|
|
log.Error(request.Id, "机会不存在", err)
|
|
|
err = protocol.NewErrWithMessage(5101)
|
|
|
return
|
|
|
}
|
|
|
sourceId = chance.Id
|
|
|
userId = chance.UserId
|
|
|
chanceType = chance.ChanceTypeId
|
|
|
table = "chance"
|
|
|
} else if request.SourceType == protocol.SourceTypeComment {
|
|
|
if comment, err = models.GetCommentById(request.Id); err != nil {
|
|
|
log.Error(request.Id, "评论不存在", err)
|
|
|
err = protocol.NewErrWithMessage(5601)
|
|
|
return
|
|
|
}
|
|
|
sourceId = comment.Id
|
|
|
userId = comment.UserId
|
|
|
} else {
|
|
|
log.Error(request.SourceType, "type error")
|
|
|
err = protocol.NewErrWithMessage(2)
|
|
|
return
|
|
|
}
|
|
|
if chanceFavoirte != nil {
|
|
|
exists = true
|
...
|
...
|
@@ -137,10 +156,10 @@ END: |
|
|
if request.SympathyType == protocol.UnMarkFlag {
|
|
|
incre = -1
|
|
|
//删除点赞消息
|
|
|
agg.DeleteSendedMsg(chance.Id, protocol.SourceTypeChance, chance.UserId, protocol.MsgTypeThumbUp)
|
|
|
agg.DeleteSendedMsg(sourceId, request.SourceType, userId, protocol.MsgTypeThumbUp)
|
|
|
} else {
|
|
|
//发送点赞消息
|
|
|
agg.SendMsg(chance.UserId, fmt.Sprintf("%v", chance.UserId), chance.CompanyId, chance.Id, 1, message, protocol.MsgTypeThumbUp)
|
|
|
agg.SendMsg(userId, fmt.Sprintf("%v", userId), header.CompanyId, request.Id, 1, message, protocol.MsgTypeThumbUp)
|
|
|
}
|
|
|
if !utils.ExecuteSqlByRoll(true, agg.GetIncrementSql(table, "zan_total", incre, request.Id)) {
|
|
|
//
|
...
|
...
|
@@ -290,7 +309,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
|
|
}
|
|
|
//4.查询审核配置
|
|
|
//5.生成审核流
|
|
|
if auditFlows, err = GenAuditFlowProcess(header, chance.Id, template.Id, auditConfig); err != nil {
|
|
|
if auditFlows, err = GenAuditFlowProcess(header, chance.Id, chance.DepartmentId, template.Id, auditConfig); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
...
|
...
|
@@ -628,7 +647,7 @@ func GenAuditFlowProcess_Submit(header *protocol.RequestHeader, chanceId int64, |
|
|
}
|
|
|
|
|
|
//生成审批流
|
|
|
func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templateId int64, auditConfig *protocol.AuditConfig) (v []*models.AuditFlowProcess, err error) {
|
|
|
func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, relatedDeparmentId int64, templateId int64, auditConfig *protocol.AuditConfig) (v []*models.AuditFlowProcess, err error) {
|
|
|
var (
|
|
|
configs []*models.AuditFlowConfig
|
|
|
IsSpecailAuditFlow bool = false
|
...
|
...
|
@@ -637,6 +656,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat |
|
|
company *models.Company
|
|
|
roleName string
|
|
|
approver *models.User
|
|
|
roleId []int
|
|
|
)
|
|
|
if configs, err = models.GetAuditFlowConfigsLevel(templateId, 1); err != nil {
|
|
|
if err == orm.ErrNoRows {
|
...
|
...
|
@@ -659,16 +679,18 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat |
|
|
groupId = config.AuditGroupId
|
|
|
continue
|
|
|
}
|
|
|
if len(config.FromSpecialUser) > 0 {
|
|
|
if err = json.Unmarshal([]byte(config.FromSpecialUser), &ids); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
for j := range ids {
|
|
|
if ids[j] == header.Uid {
|
|
|
groupId = config.AuditGroupId
|
|
|
IsSpecailAuditFlow = true
|
|
|
break
|
|
|
if config.FlowType == protocol.FlowTypeSpecail {
|
|
|
if len(config.FromSpecialUser) > 0 {
|
|
|
if err = json.Unmarshal([]byte(config.FromSpecialUser), &ids); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
for j := range ids {
|
|
|
if ids[j] == header.Uid {
|
|
|
groupId = config.AuditGroupId
|
|
|
IsSpecailAuditFlow = true
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -704,18 +726,28 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat |
|
|
var userIds []int64
|
|
|
switch config.AuditFlowType {
|
|
|
case protocol.AuditByDepartmentor:
|
|
|
if userIds, err = getDepartmentors(header); err != nil {
|
|
|
if userIds, err = getDepartmentors(header, relatedDeparmentId); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
break
|
|
|
case protocol.AuditByUser:
|
|
|
if err = json.Unmarshal([]byte(config.ToUser), &userIds); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
break
|
|
|
case protocol.AuditByRole:
|
|
|
//roleName="" //TODO:角色
|
|
|
return
|
|
|
if e := json.Unmarshal([]byte(config.ToRole), &roleId); e == nil {
|
|
|
if userIds, err = getRoleUsers(header, roleId[0]); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
} else {
|
|
|
log.Error(config.ToRole, e)
|
|
|
}
|
|
|
break
|
|
|
}
|
|
|
if len(userIds) == 0 { //当前步骤没有用户 默认一个空审核人
|
|
|
userIds = append(userIds, 0)
|
...
|
...
|
@@ -725,12 +757,15 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat |
|
|
if uid == 0 && auditConfig.NoApprover == protocol.NoApproverToAdmin { //审批人为空 转交给管理员
|
|
|
uid = company.AdminId
|
|
|
}
|
|
|
if uid == header.Uid { //审核人自己 转交给管理员
|
|
|
if uid == 0 {
|
|
|
uid = company.AdminId
|
|
|
}
|
|
|
if uid == header.UserId { //审核人自己 转交给管理员
|
|
|
log.Info(fmt.Sprintf("生成机会审批流-转给管理员:chance_id:%v audit_level:%v audit_user:%v -> admin:%v", chanceId, config.Level, uid, company.AdminId))
|
|
|
uid = company.AdminId
|
|
|
}
|
|
|
if approver, err = models.GetUserByUcid(uid); err != nil {
|
|
|
log.Error(err)
|
|
|
log.Error(uid, err)
|
|
|
return
|
|
|
}
|
|
|
item := &models.AuditFlowProcess{
|
...
|
...
|
@@ -769,33 +804,52 @@ func resolveActionType(t uint) string { |
|
|
}
|
|
|
|
|
|
//获取部门长用户列表
|
|
|
func getDepartmentors(header *protocol.RequestHeader) (ids []int64, err error) {
|
|
|
func getDepartmentors(header *protocol.RequestHeader, relatedDeparmentId int64) (ids []int64, err error) {
|
|
|
var (
|
|
|
departments []*protocol.Department
|
|
|
departments *models.Department
|
|
|
)
|
|
|
if err = models.GetUserDepartments(header.Uid, header.CompanyId, &departments); err != nil {
|
|
|
log.Error(err)
|
|
|
//if err = models.GetUserDepartments(header.UserId, header.CompanyId, &departments); err != nil {
|
|
|
// log.Error(header.UserId,header.CompanyId,err)
|
|
|
// return
|
|
|
//}
|
|
|
if departments, err = models.GetDepartmentById(int(relatedDeparmentId)); err != nil {
|
|
|
log.Error(relatedDeparmentId, err)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
for i := 0; i < len(departments); i++ {
|
|
|
d := departments[i]
|
|
|
//部门长存在
|
|
|
if len(d.ManagerString) > 0 {
|
|
|
var tmpIds []int64
|
|
|
if err = json.Unmarshal([]byte(d.ManagerString), &tmpIds); err == nil && len(ids) > 0 {
|
|
|
if len(departments.Managers) > 0 {
|
|
|
var tmpIds []int64
|
|
|
if err = json.Unmarshal([]byte(departments.Managers), &tmpIds); err == nil {
|
|
|
if len(tmpIds) > 0 {
|
|
|
ids = append(ids, tmpIds...)
|
|
|
continue
|
|
|
}
|
|
|
}
|
|
|
//部门长不存在
|
|
|
if d.PId == 0 {
|
|
|
ids = append(ids, 0)
|
|
|
continue
|
|
|
} else {
|
|
|
ids = append(ids, getParentDepartmentors(d.PId)...)
|
|
|
}
|
|
|
//部门长不存在
|
|
|
if len(ids) == 0 {
|
|
|
ids = append(ids, 0)
|
|
|
}
|
|
|
log.Info(fmt.Sprintf("生成机会审批流-部门:department_id:%v managers:%v ids:%v", relatedDeparmentId, departments.Managers, ids))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//获取角色ids
|
|
|
func getRoleUsers(header *protocol.RequestHeader, roleId int) (ids []int64, err error) {
|
|
|
var (
|
|
|
userRole []*models.UserRole
|
|
|
)
|
|
|
if userRole, err = models.GetUserRolesById(roleId); err != nil {
|
|
|
log.Error(roleId, err)
|
|
|
if err == orm.ErrNoRows {
|
|
|
err = nil
|
|
|
}
|
|
|
}
|
|
|
for i := range userRole {
|
|
|
ids = append(ids, userRole[i].UserCompanyId)
|
|
|
}
|
|
|
if len(ids) == 0 {
|
|
|
ids = append(ids, 0)
|
|
|
}
|
|
|
log.Info(fmt.Sprintf("生成机会审批流-角色:role_id:%v ids:%v", roleId, ids))
|
|
|
return
|
|
|
}
|
|
|
|
...
|
...
|
@@ -888,7 +942,10 @@ func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitCh |
|
|
}
|
|
|
commItem.ReviewStatus = chance.ReviewStatus
|
|
|
if request.ReviewStatus == protocol.ReviewStatusPass {
|
|
|
jsonUnmarshal(chance.ApproveData, &commItem.ApproveData)
|
|
|
var approveData protocol.ApproveData
|
|
|
jsonUnmarshal(chance.ApproveData, &approveData)
|
|
|
//commItem.ApproveData = approveData //TODO:删除不需要
|
|
|
commItem.Score = approveData.Score
|
|
|
}
|
|
|
rsp.List = append(rsp.List, commItem)
|
|
|
}
|
...
|
...
|
|