...
|
...
|
@@ -12,6 +12,7 @@ import ( |
|
|
"opp/models"
|
|
|
"opp/protocol"
|
|
|
"opp/services/agg"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
...
|
...
|
@@ -76,13 +77,18 @@ func SympathyAction(header *protocol.RequestHeader, request *protocol.SympathyAc |
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if chance, err = models.GetChanceById(request.ChanceId); err != nil {
|
|
|
log.Error(request.Id, "机会不存在", err)
|
|
|
err = protocol.NewErrWithMessage(5101)
|
|
|
return
|
|
|
}
|
|
|
if request.SourceType == protocol.SourceTypeChance {
|
|
|
message = protocol.MessageZanChance
|
|
|
if chance, err = models.GetChanceById(request.Id); err != nil {
|
|
|
log.Error(request.Id, "机会不存在", err)
|
|
|
err = protocol.NewErrWithMessage(5101)
|
|
|
return
|
|
|
}
|
|
|
//if chance, err = models.GetChanceById(request.Id); err != nil {
|
|
|
// log.Error(request.Id, "机会不存在", err)
|
|
|
// err = protocol.NewErrWithMessage(5101)
|
|
|
// return
|
|
|
//}
|
|
|
sourceId = chance.Id
|
|
|
userId = chance.UserId
|
|
|
chanceType = chance.ChanceTypeId
|
...
|
...
|
@@ -140,6 +146,7 @@ func SympathyAction(header *protocol.RequestHeader, request *protocol.SympathyAc |
|
|
ChanceType: chanceType,
|
|
|
CreateAt: time.Now(),
|
|
|
EnableStatus: 1,
|
|
|
ChanceId: request.ChanceId,
|
|
|
}
|
|
|
if _, err = models.AddChanceFavorite(chanceFavoirte); err != nil {
|
|
|
log.Error(err)
|
...
|
...
|
@@ -159,7 +166,9 @@ END: |
|
|
agg.DeleteSendedMsg(sourceId, request.SourceType, userId, protocol.MsgTypeThumbUp)
|
|
|
} else {
|
|
|
//发送点赞消息
|
|
|
agg.SendMsg(userId, fmt.Sprintf("%v", userId), header.CompanyId, request.Id, 1, message, protocol.MsgTypeThumbUp)
|
|
|
if header.UserId != userId {
|
|
|
agg.SendMsg(userId, fmt.Sprintf("%v", userId), header.CompanyId, request.Id, request.SourceType, message, protocol.MsgTypeThumbUp, request.ChanceId)
|
|
|
}
|
|
|
}
|
|
|
if !utils.ExecuteSqlByRoll(true, agg.GetIncrementSql(table, "zan_total", incre, request.Id)) {
|
|
|
//
|
...
|
...
|
@@ -336,6 +345,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
|
|
AuditLevel: 1,
|
|
|
ReviewStatus: protocol.ReviewStatusAuditging,
|
|
|
DepartmentId: request.RelatedDepartment,
|
|
|
Code: fmt.Sprintf("%v%v", chanceType.Code, template.Code),
|
|
|
}
|
|
|
if _, err = orm.Insert(chance); err != nil {
|
|
|
log.Error(err)
|
...
|
...
|
@@ -403,6 +413,12 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
|
|
return
|
|
|
}
|
|
|
}
|
|
|
//发送提交日志
|
|
|
if err = agg.SaveApproveLog(orm, 1, header.UserId, chance.Id); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
orm.Commit()
|
|
|
|
|
|
rsp = &protocol.ChanceSubmitResponse{}
|
...
|
...
|
@@ -448,14 +464,19 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate |
|
|
//}
|
|
|
if _, e := models.GetAuditFlowProcessByReview(request.Id, 0, protocol.ReviewStatusWait); e == nil {
|
|
|
request.IsPublish = true
|
|
|
updateMap["DepartmentId"] = request.RelatedDepartment
|
|
|
//log.Info(fmt.Sprintf("机会编辑 is_publish:%v chance.review_status:%v 是否是本人:%v",request.IsPublish,chance.ReviewStatus,chance.UserId==header.UserId))
|
|
|
} else {
|
|
|
log.Info(fmt.Sprintf("机会编辑 chance_id:%v chance.review_status:%v 无待处理 审核数据", request.Id, chance.ReviewStatus))
|
|
|
}
|
|
|
} else {
|
|
|
request.IsPublish = false
|
|
|
log.Info(fmt.Sprintf("机会编辑 is_publish:%v chance.review_status:%v 是否是本人:%v", request.IsPublish, chance.ReviewStatus, chance.UserId == header.UserId))
|
|
|
}
|
|
|
//TODO:非本人 1.需要验证角色权限 2是否是审核人 3.是否是本人 (目前本人才可以审核)
|
|
|
if chance.UserId != header.Uid {
|
|
|
if chance.UserId != header.UserId {
|
|
|
err = protocol.NewErrWithMessage(5206)
|
|
|
log.Error(fmt.Sprintf("user:%v 无权限操作机会 chance:%v", header.Uid, chance.Id))
|
|
|
log.Error(fmt.Sprintf("user:%v 无权限操作机会 chance:%v", header.UserId, chance.Id))
|
|
|
return
|
|
|
}
|
|
|
//1.模板是否存在
|
...
|
...
|
@@ -474,7 +495,6 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate |
|
|
updateMap["AuditTemplateConfig"] = common.AssertJson(auditConfig)
|
|
|
updateMap["Content"] = request.Content
|
|
|
updateMap["SourceContent"] = common.AssertJson(request.FormList)
|
|
|
updateMap["DepartmentId"] = request.RelatedDepartment
|
|
|
|
|
|
if err = utils.UpdateTableByMapWithOrmer(orm, &models.Chance{Id: chance.Id}, updateMap); err != nil {
|
|
|
log.Error(err)
|
...
|
...
|
@@ -560,6 +580,12 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//发送提交日志
|
|
|
if err = agg.SaveApproveLog(orm, 1, chance.UserId, chance.Id); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
orm.Commit()
|
...
|
...
|
@@ -620,12 +646,43 @@ func ChanceChangePublish(header *protocol.RequestHeader, request *protocol.Chanc |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if err = saveApproveMsgChangePublic(orm, chance, request.PublicData); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
orm.Commit()
|
|
|
//TODO:添加log
|
|
|
rsp = &protocol.ChanceChangePublishResponse{}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//发送审核日志
|
|
|
func saveApproveMsgChangePublic(orm orm.Ormer, chance *models.Chance, approveData protocol.PublicData) (err error) {
|
|
|
var (
|
|
|
parames = make([]interface{}, 0)
|
|
|
code = 0
|
|
|
)
|
|
|
if approveData.PublishStatus == protocol.PublicToCompany {
|
|
|
code = 7
|
|
|
}
|
|
|
if approveData.PublishStatus == protocol.PublicToDepartment {
|
|
|
code = 8
|
|
|
var department []string
|
|
|
for i := range approveData.VisibleObjects {
|
|
|
v := approveData.VisibleObjects[i]
|
|
|
department = append(department, v.Name)
|
|
|
}
|
|
|
parames = append(parames, strings.Join(department, ","))
|
|
|
}
|
|
|
if err = agg.SaveApproveLog(orm, code, chance.UserId, chance.Id, parames...); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//修改评分
|
|
|
func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceChangeScoreRequest) (rsp *protocol.ChanceChangeScoreResponse, err error) {
|
|
|
var (
|
...
|
...
|
@@ -667,6 +724,17 @@ func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceC |
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
//修改评分日志
|
|
|
if err = agg.SaveApproveLog(orm, 9, chance.UserId, chance.Id, request.Score.BasicScore, request.Score.ExtraScore, request.Score.ValueScore); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//if err = agg.SaveApproveLog(orm,9,chance.UserId,chance.Id,request.Score.BasicScore,request.Score.ExtraScore,request.Score.ValueScore);err!=nil{
|
|
|
// log.Error(err)
|
|
|
// return
|
|
|
//}
|
|
|
|
|
|
orm.Commit()
|
|
|
rsp = &protocol.ChanceChangeScoreResponse{
|
|
|
DiscoveryScore: result.DiscoveryScore,
|
...
|
...
|
@@ -781,6 +849,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related |
|
|
approver *models.User
|
|
|
roleIds []int
|
|
|
roleId int
|
|
|
admin *models.UserCompany
|
|
|
)
|
|
|
if configs, err = models.GetAuditFlowConfigsLevel(templateId, 1); err != nil {
|
|
|
if err == orm.ErrNoRows {
|
...
|
...
|
@@ -842,8 +911,16 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related |
|
|
|
|
|
if company.AdminId == 0 {
|
|
|
err = fmt.Errorf("GenAuditFlowProcess:company.admin is not set")
|
|
|
err = protocol.NewErrWithMessage(5207)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if admin, err = models.GetUserCompanyByUserId(company.AdminId, header.CompanyId); err != nil {
|
|
|
err = fmt.Errorf("GenAuditFlowProcess:company.admin is not set")
|
|
|
err = protocol.NewErrWithMessage(5207)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//3.生成审核列表
|
|
|
for i := range configs {
|
|
|
config := configs[i]
|
...
|
...
|
@@ -882,14 +959,14 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related |
|
|
for j := 0; j < len(userIds); j++ {
|
|
|
uid := userIds[j]
|
|
|
if uid == 0 && auditConfig.NoApprover == protocol.NoApproverToAdmin { //审批人为空 转交给管理员
|
|
|
uid = company.AdminId
|
|
|
uid = admin.Id
|
|
|
}
|
|
|
if uid == 0 {
|
|
|
uid = company.AdminId
|
|
|
uid = admin.Id
|
|
|
}
|
|
|
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
|
|
|
uid = admin.Id
|
|
|
}
|
|
|
if approver, err = models.GetUserByUcid(uid); err != nil {
|
|
|
log.Error(uid, err)
|
...
|
...
|
@@ -934,7 +1011,8 @@ func resolveActionType(t uint) string { |
|
|
//获取部门长用户列表
|
|
|
func getDepartmentors(header *protocol.RequestHeader, relatedDeparmentId int64) (ids []int64, err error) {
|
|
|
var (
|
|
|
departments *models.Department
|
|
|
departments *models.Department
|
|
|
lastDepartmentId int
|
|
|
)
|
|
|
//if err = models.GetUserDepartments(header.UserId, header.CompanyId, &departments); err != nil {
|
|
|
// log.Error(header.UserId,header.CompanyId,err)
|
...
|
...
|
@@ -944,19 +1022,37 @@ func getDepartmentors(header *protocol.RequestHeader, relatedDeparmentId int64) |
|
|
log.Error(relatedDeparmentId, err)
|
|
|
return
|
|
|
}
|
|
|
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...)
|
|
|
//部门长
|
|
|
for {
|
|
|
if len(departments.Managers) > 0 {
|
|
|
var tmpIds []int64
|
|
|
if e := json.Unmarshal([]byte(departments.Managers), &tmpIds); e == nil {
|
|
|
if len(tmpIds) > 0 {
|
|
|
ids = append(ids, tmpIds...)
|
|
|
}
|
|
|
break
|
|
|
} else {
|
|
|
log.Error(e)
|
|
|
}
|
|
|
//break
|
|
|
}
|
|
|
if departments.ParentId != 0 {
|
|
|
//relatedDeparmentId = int64departments.ParentId
|
|
|
lastDepartmentId = departments.ParentId
|
|
|
if departments, err = models.GetDepartmentById(int(departments.ParentId)); err != nil {
|
|
|
log.Error(relatedDeparmentId, err)
|
|
|
err = nil
|
|
|
break
|
|
|
}
|
|
|
} else {
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
//部门长不存在
|
|
|
if len(ids) == 0 {
|
|
|
ids = append(ids, 0)
|
|
|
}
|
|
|
log.Info(fmt.Sprintf("生成机会审批流-部门:department_id:%v managers:%v ids:%v", relatedDeparmentId, departments.Managers, ids))
|
|
|
log.Info(fmt.Sprintf("生成机会审批流-部门:department_id:%v managers:%v ids:%v last_department_id:%v", relatedDeparmentId, departments.Managers, ids, lastDepartmentId))
|
|
|
return
|
|
|
}
|
|
|
|
...
|
...
|
@@ -1057,9 +1153,14 @@ func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitCh |
|
|
commItem := protocol.CommonListItem{}
|
|
|
{
|
|
|
item := protocol.ChanceItem{
|
|
|
Id: chance.Id,
|
|
|
Provider: provider,
|
|
|
CreateTime: chance.CreateTime.Unix() * 1000,
|
|
|
Id: chance.Id,
|
|
|
Provider: provider,
|
|
|
CreateTime: chance.CreateTime.Unix() * 1000,
|
|
|
UpdateTime: chance.UpdateTime.Unix() * 1000,
|
|
|
ApproveTime: chance.ApproveTime.Unix() * 1000,
|
|
|
}
|
|
|
if item.ApproveTime < 0 {
|
|
|
item.ApproveTime = 0
|
|
|
}
|
|
|
jsonUnmarshal(chance.SourceContent, &item.FormList)
|
|
|
item.FormList = clearEmptyForm(item.FormList)
|
...
|
...
|
@@ -1185,10 +1286,17 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove |
|
|
//return
|
|
|
} else {
|
|
|
item := protocol.ChanceItem{
|
|
|
Id: chance.ChanceId,
|
|
|
Provider: provider,
|
|
|
Id: chance.ChanceId,
|
|
|
Provider: provider,
|
|
|
CreateTime: chance.CreateTime.Unix() * 1000,
|
|
|
UpdateTime: chance.UpdateTime.Unix() * 1000,
|
|
|
ApproveTime: chance.ChanceApproveTime.Unix() * 1000,
|
|
|
//CreateTime:chance.c
|
|
|
//CreateTime: chance.CreateTime.Unix() * 1000,
|
|
|
}
|
|
|
if item.ApproveTime < 0 {
|
|
|
item.ApproveTime = 0
|
|
|
}
|
|
|
jsonUnmarshal(chance.SourceContent, &item.FormList)
|
|
|
item.FormList = clearEmptyForm(item.FormList)
|
|
|
jsonUnmarshal(chance.Images, &item.Pictures)
|
...
|
...
|
@@ -1287,6 +1395,7 @@ func MyCollectChance(header *protocol.RequestHeader, request *protocol.MyCollect |
|
|
Id: chance.CollectId,
|
|
|
CollectTime: chance.CollectTime.Unix() * 1000,
|
|
|
}
|
|
|
//commItem.ChanceId = chance.ChanceId
|
|
|
}
|
|
|
rsp.List = append(rsp.List, commItem)
|
|
|
}
|
...
|
...
|
@@ -1614,15 +1723,26 @@ func ChanceDelete(header *protocol.RequestHeader, request *protocol.ChanceDelete |
|
|
err = protocol.NewErrWithMessage(5202)
|
|
|
return
|
|
|
}
|
|
|
if err = utils.UpdateTableByMap(chance, map[string]interface{}{
|
|
|
orm := orm.NewOrm()
|
|
|
orm.Begin()
|
|
|
//发送提交日志
|
|
|
if err = agg.SaveApproveLog(orm, 2, chance.UserId, chance.Id); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
if err = utils.UpdateTableByMapWithOrmer(orm, chance, map[string]interface{}{
|
|
|
"EnableStatus": int8(0),
|
|
|
}); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
if err = models.CloseAuditFlowProcess(chance.Id); err != nil {
|
|
|
if err = models.CloseAuditFlowProcess(orm, chance.Id); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
orm.Commit()
|
|
|
return
|
|
|
} |
...
|
...
|
|