...
|
...
|
@@ -235,6 +235,48 @@ func Templates(header *protocol.RequestHeader, request *protocol.TemplatesReques |
|
|
return
|
|
|
}
|
|
|
|
|
|
//模板详情
|
|
|
func Template(header *protocol.RequestHeader, request *protocol.TemplateRequest) (rsp *protocol.TemplateResponse, err error) {
|
|
|
var (
|
|
|
templates *models.AuditTemplate
|
|
|
forms []*models.AuditForm
|
|
|
)
|
|
|
rsp = &protocol.TemplateResponse{}
|
|
|
if templates, err = models.GetAuditTemplate(header.CompanyId, request.ChanceTypeId, request.TemplateId); err != nil {
|
|
|
log.Error(fmt.Sprintf("公司:%v chance_type_id:%v id:%v无模板 ", header.CompanyId, request.ChanceTypeId, request.TemplateId), err)
|
|
|
return
|
|
|
}
|
|
|
item := templates
|
|
|
//TODO:检查模板可见
|
|
|
//
|
|
|
//查询表单
|
|
|
if forms, err = models.GetAuditForms(header.CompanyId, item.Id); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
template := &protocol.Template{
|
|
|
Id: item.Id,
|
|
|
Name: item.Name,
|
|
|
Icon: item.Icon,
|
|
|
Doc: item.Doc,
|
|
|
FormList: make([]*protocol.Form, len(forms)),
|
|
|
Link: fmt.Sprintf("%v/#/ability/opportunity?id=%v", beego.AppConfig.String("h5_host"), item.Id),
|
|
|
}
|
|
|
for j := range forms {
|
|
|
form := forms[j]
|
|
|
template.FormList[j] = &protocol.Form{
|
|
|
Id: form.Id,
|
|
|
Label: form.Label,
|
|
|
Value: "",
|
|
|
InputType: form.InputType,
|
|
|
SectionType: form.Section,
|
|
|
Required: form.Required,
|
|
|
}
|
|
|
}
|
|
|
rsp.Template = template
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func checkTemplateIsVisible(header *protocol.RequestHeader, template *models.AuditTemplate) (result bool, err error) {
|
|
|
//if template.VisibleType ==
|
|
|
return
|
...
|
...
|
@@ -302,7 +344,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
|
|
}
|
|
|
|
|
|
//生成提交记录
|
|
|
if _, err = orm.Insert(GenAuditFlowProcess_Submit(header, chance.Id, template.Id, protocol.ReviewStatusSubmit)); err != nil {
|
|
|
if _, err = orm.Insert(GenAuditFlowProcess_Submit(header.UserId, chance.Id, template.Id, protocol.ReviewStatusSubmit)); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
...
|
...
|
@@ -368,35 +410,67 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
|
|
}
|
|
|
|
|
|
//机会编辑
|
|
|
func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceSubmitRequest) (rsp *protocol.ChanceSubmitResponse, err error) {
|
|
|
func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdateRequest) (rsp *protocol.ChanceUpdateResponse, err error) {
|
|
|
var (
|
|
|
template *models.AuditTemplate
|
|
|
chance *models.Chance
|
|
|
auditConfig *protocol.AuditConfig
|
|
|
chanceData *models.ChanceData
|
|
|
//auditFlows []*models.AuditFlowProcess
|
|
|
//auditFlows *models.AuditFlowProcess
|
|
|
updateMap = make(map[string]interface{})
|
|
|
|
|
|
auditFlows []*models.AuditFlowProcess
|
|
|
suplusApprove SuplusApprove
|
|
|
chanceType *models.ChanceType
|
|
|
)
|
|
|
//验证机会是否存在
|
|
|
if chance, err = models.GetChanceById(request.Id); err != nil {
|
|
|
log.Error(err)
|
|
|
log.Error(request.Id, err)
|
|
|
err = protocol.NewErrWithMessage(5101)
|
|
|
return
|
|
|
}
|
|
|
//1.模板是否存在
|
|
|
if template, err = models.GetAuditTemplateById(int64(chance.AuditTemplateId)); err != nil {
|
|
|
log.Error("模板不存在:", chance.AuditTemplateId, err)
|
|
|
return
|
|
|
}
|
|
|
//TODO:非本人 1.需要验证角色权限,是否是审核人
|
|
|
if chanceType, err = models.GetChanceTypeById(chance.ChanceTypeId); err != nil {
|
|
|
log.Error("一级分类不存在:", chance.ChanceTypeId, err)
|
|
|
return
|
|
|
}
|
|
|
//编辑重新发布 是否可以重新发布
|
|
|
if request.IsPublish && chance.ReviewStatus == protocol.ReviewStatusReturn && chance.UserId == header.UserId {
|
|
|
request.IsPublish = false
|
|
|
//当前没有被人审核过
|
|
|
//if _, e := models.GetAuditFlowProcessApproved(request.Id, 1); e == orm.ErrNoRows && chance.AuditLevel == 1 {
|
|
|
// //当前状态是退回-待处理
|
|
|
//
|
|
|
//}
|
|
|
if _, e := models.GetAuditFlowProcessByReview(request.Id, 0, protocol.ReviewStatusWait); e == nil {
|
|
|
request.IsPublish = true
|
|
|
}
|
|
|
} else {
|
|
|
request.IsPublish = false
|
|
|
}
|
|
|
//TODO:非本人 1.需要验证角色权限 2是否是审核人 3.是否是本人 (目前本人才可以审核)
|
|
|
if chance.UserId != header.Uid {
|
|
|
err = protocol.NewErrWithMessage(1)
|
|
|
err = protocol.NewErrWithMessage(5206)
|
|
|
log.Error(fmt.Sprintf("user:%v 无权限操作机会 chance:%v", header.Uid, chance.Id))
|
|
|
return
|
|
|
}
|
|
|
//TODO:验证机会当前是否在审核中
|
|
|
//1.模板是否存在
|
|
|
if template, err = models.GetAuditTemplateById(request.AuditTemplateId); err != nil {
|
|
|
log.Error("模板不存在:", request.AuditTemplateId, err)
|
|
|
if template, err = models.GetAuditTemplateById(chance.AuditTemplateId); err != nil {
|
|
|
log.Error("模板不存在:", chance.AuditTemplateId, err)
|
|
|
err = protocol.NewErrWithMessage(5301)
|
|
|
return
|
|
|
}
|
|
|
auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover}
|
|
|
orm := orm.NewOrm()
|
|
|
orm.Begin()
|
|
|
{
|
|
|
if request.IsPublish {
|
|
|
updateMap["ReviewStatus"] = int8(protocol.ReviewStatusAuditging)
|
|
|
}
|
|
|
updateMap["AuditTemplateConfig"] = common.AssertJson(auditConfig)
|
|
|
updateMap["Content"] = request.Content
|
|
|
updateMap["SourceContent"] = common.AssertJson(request.FormList)
|
...
|
...
|
@@ -440,11 +514,56 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
orm.Commit()
|
|
|
|
|
|
//6.激活审核流
|
|
|
//TODO:7.发送消息通知给审核人(审核消息)
|
|
|
rsp = &protocol.ChanceSubmitResponse{}
|
|
|
{
|
|
|
if request.IsPublish {
|
|
|
|
|
|
//更新待处理->提交
|
|
|
if err = models.UpdatetAuditFlowProcessToSubmit(orm, request.Id, 0, protocol.ReviewStatusSubmit, header.UserId); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
//4.查询审核配置
|
|
|
//5.生成审核流
|
|
|
if auditFlows, err = GenAuditFlowProcess(header, chance.Id, chance.DepartmentId, template.Id, auditConfig); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
for i := 0; i < len(auditFlows); i++ {
|
|
|
auditFlows[i].ApproveMessage = fmt.Sprintf(protocol.MessageApproving, chanceType.Name)
|
|
|
//auditFlows[i].TemplateId = int(template.Id)
|
|
|
if _, err = orm.Insert(auditFlows[i]); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
if len(auditFlows) > 0 {
|
|
|
//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, protocol.ReviewStatusAuditging); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
orm.Commit()
|
|
|
rsp = &protocol.ChanceUpdateResponse{}
|
|
|
return
|
|
|
}
|
|
|
|
...
|
...
|
@@ -549,7 +668,10 @@ func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceC |
|
|
return
|
|
|
}
|
|
|
orm.Commit()
|
|
|
rsp = &protocol.ChanceChangeScoreResponse{}
|
|
|
rsp = &protocol.ChanceChangeScoreResponse{
|
|
|
DiscoveryScore: result.DiscoveryScore,
|
|
|
DiscoveryScorePercent: result.DiscoveryScorePercent,
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
...
|
...
|
@@ -626,18 +748,19 @@ func ChancePermission(header *protocol.RequestHeader, request *protocol.ChancePe |
|
|
}
|
|
|
|
|
|
//生成审批流-提交记录
|
|
|
func GenAuditFlowProcess_Submit(header *protocol.RequestHeader, chanceId int64, templateId int64, reviewStatus int) (v *models.AuditFlowProcess) {
|
|
|
func GenAuditFlowProcess_Submit(userId, chanceId int64, templateId int64, reviewStatus int) (v *models.AuditFlowProcess) {
|
|
|
v = &models.AuditFlowProcess{
|
|
|
Id: idgen.Next(),
|
|
|
ChanceId: chanceId,
|
|
|
Uid: header.UserId,
|
|
|
Uid: userId,
|
|
|
CreateAt: time.Now(),
|
|
|
UpdateAt: time.Now(),
|
|
|
ApproveTime: time.Now(),
|
|
|
EnableStatus: 1,
|
|
|
IsActive: 1,
|
|
|
ReviewStatus: int8(reviewStatus),
|
|
|
}
|
|
|
if approver, err := models.GetUsersById(header.Uid); err != nil {
|
|
|
if approver, err := models.GetUsersById(userId); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
} else {
|
...
|
...
|
@@ -656,7 +779,8 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related |
|
|
company *models.Company
|
|
|
roleName string
|
|
|
approver *models.User
|
|
|
roleId []int
|
|
|
roleIds []int
|
|
|
roleId int
|
|
|
)
|
|
|
if configs, err = models.GetAuditFlowConfigsLevel(templateId, 1); err != nil {
|
|
|
if err == orm.ErrNoRows {
|
...
|
...
|
@@ -738,11 +862,15 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related |
|
|
}
|
|
|
break
|
|
|
case protocol.AuditByRole:
|
|
|
if e := json.Unmarshal([]byte(config.ToRole), &roleId); e == nil {
|
|
|
if userIds, err = getRoleUsers(header, roleId[0]); err != nil {
|
|
|
if e := json.Unmarshal([]byte(config.ToRole), &roleIds); e == nil {
|
|
|
if userIds, err = getRoleUsers(header, roleIds[0]); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if role, e := models.GetRoleById(roleIds[0]); e == nil {
|
|
|
roleName = role.Name
|
|
|
roleId = role.Id
|
|
|
}
|
|
|
} else {
|
|
|
log.Error(config.ToRole, e)
|
|
|
}
|
...
|
...
|
@@ -779,6 +907,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related |
|
|
ActionType: int(config.ActionType),
|
|
|
RoleName: roleName,
|
|
|
UserName: approver.NickName,
|
|
|
RoleId: roleId,
|
|
|
ReviewStatus: protocol.ReviewStatusAuditging,
|
|
|
TemplateId: int(templateId),
|
|
|
}
|
...
|
...
|
@@ -786,7 +915,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related |
|
|
item.IsActive = 1
|
|
|
item.EnableStatus = 1
|
|
|
}
|
|
|
log.Info(fmt.Sprintf("生成机会审批流:chance_id:%v audit_id:%v audit_level:%v audit_user:%v action_type:%v", chanceId, item.Id, config.Level, uid, resolveActionType(config.ActionType)))
|
|
|
log.Info(fmt.Sprintf("生成机会审批流:chance_id:%v audit_id:%v audit_level:%v audit_user:%v action_type:%v is_active:%v", chanceId, item.Id, config.Level, uid, resolveActionType(config.ActionType), item.IsActive))
|
|
|
v = append(v, item)
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -794,10 +923,10 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related |
|
|
}
|
|
|
func resolveActionType(t uint) string {
|
|
|
if t == 1 {
|
|
|
return "or"
|
|
|
return "and"
|
|
|
}
|
|
|
if t == 2 {
|
|
|
return "and"
|
|
|
return "or"
|
|
|
}
|
|
|
return fmt.Sprintf("%v", t)
|
|
|
}
|
...
|
...
|
|