作者 yangfu

Merge remote-tracking branch 'origin/dev' into test

@@ -248,6 +248,27 @@ func (this *ChanceController) Templates() { @@ -248,6 +248,27 @@ func (this *ChanceController) Templates() {
248 msg = protocol.NewReturnResponse(chance.Templates(header, request)) 248 msg = protocol.NewReturnResponse(chance.Templates(header, request))
249 } 249 }
250 250
  251 +//Template 模板详情
  252 +//@router /template [post]
  253 +func (this *ChanceController) Template() {
  254 + var msg *protocol.ResponseMessage
  255 + defer func() {
  256 + this.Resp(msg)
  257 + }()
  258 + var request *protocol.TemplateRequest
  259 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  260 + log.Error(err)
  261 + msg = protocol.BadRequestParam(1)
  262 + return
  263 + }
  264 + if b, m := this.Valid(request); !b {
  265 + msg = m
  266 + return
  267 + }
  268 + header := controllers.GetRequestHeader(this.Ctx)
  269 + msg = protocol.NewReturnResponse(chance.Template(header, request))
  270 +}
  271 +
251 //ChanceSubmit 提交机会 272 //ChanceSubmit 提交机会
252 //@router /submit [post] 273 //@router /submit [post]
253 func (this *ChanceController) ChanceSubmit() { 274 func (this *ChanceController) ChanceSubmit() {
@@ -266,11 +287,32 @@ func (this *ChanceController) ChanceSubmit() { @@ -266,11 +287,32 @@ func (this *ChanceController) ChanceSubmit() {
266 return 287 return
267 } 288 }
268 header := controllers.GetRequestHeader(this.Ctx) 289 header := controllers.GetRequestHeader(this.Ctx)
269 - if request.Id > 0 {  
270 - msg = protocol.NewReturnResponse(chance.ChanceUpdate(header, request)) 290 + //if request.Id > 0 {
  291 + // msg = protocol.NewReturnResponse(chance.ChanceUpdate(header, request))
  292 + // return
  293 + //}
  294 + msg = protocol.NewReturnResponse(chance.ChanceSubmit(header, request))
  295 +}
  296 +
  297 +//ChanceUpdate 机会更新
  298 +//@router /update [post]
  299 +func (this *ChanceController) ChanceUpdate() {
  300 + var msg *protocol.ResponseMessage
  301 + defer func() {
  302 + this.Resp(msg)
  303 + }()
  304 + var request *protocol.ChanceUpdateRequest
  305 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  306 + log.Error(err)
  307 + msg = protocol.BadRequestParam(1)
271 return 308 return
272 } 309 }
273 - msg = protocol.NewReturnResponse(chance.ChanceSubmit(header, request)) 310 + if b, m := this.Valid(request); !b {
  311 + msg = m
  312 + return
  313 + }
  314 + header := controllers.GetRequestHeader(this.Ctx)
  315 + msg = protocol.NewReturnResponse(chance.ChanceUpdate(header, request))
274 } 316 }
275 317
276 //ChanceStatistics 机会统计 318 //ChanceStatistics 机会统计
@@ -139,3 +139,32 @@ func CloseAuditFlowProcess(chanceId int64) (err error) { @@ -139,3 +139,32 @@ func CloseAuditFlowProcess(chanceId int64) (err error) {
139 } 139 }
140 return 140 return
141 } 141 }
  142 +
  143 +//获取当前审批节点 是否已经有人审核通过的
  144 +func GetAuditFlowProcessApproved(chanceId int64, level int) (v *[]AuditFlowProcess, err error) {
  145 + o := orm.NewOrm()
  146 + sql := "select id from audit_flow_process where chance_id=? and level=? and is_active=1 and review_status<>1 and enable_status=1"
  147 + if _, err = o.Raw(sql, chanceId, level).QueryRows(&v); err != nil {
  148 + return
  149 + }
  150 + return
  151 +}
  152 +
  153 +//按审核状态获取审核流程
  154 +func GetAuditFlowProcessByReview(chanceId int64, level int, reviewStatus int) (v *AuditFlowProcess, err error) {
  155 + o := orm.NewOrm()
  156 + sql := "select * from audit_flow_process where chance_id=? and level=? and is_active=1 and review_status=? and enable_status=1"
  157 + if err = o.Raw(sql, chanceId, level, reviewStatus).QueryRow(&v); err != nil {
  158 + return
  159 + }
  160 + return
  161 +}
  162 +
  163 +//更新提交
  164 +func UpdatetAuditFlowProcessToSubmit(o orm.Ormer, chanceId int64, level int, reviewStatus int, userId int64) (err error) {
  165 + sql := "update audit_flow_process set enable_status =1,is_active=0,update_at=now(),review_status=? where chance_id=? and uid=? and level=? and review_status=0 and enable_status=1"
  166 + if err = utils.ExecuteSQLWithOrmer(o, sql, reviewStatus, chanceId, userId, level); err != nil {
  167 + return
  168 + }
  169 + return
  170 +}
@@ -100,3 +100,14 @@ func GetAuditTemplateExample(id int64) (v string, err error) { @@ -100,3 +100,14 @@ func GetAuditTemplateExample(id int64) (v string, err error) {
100 } 100 }
101 return 101 return
102 } 102 }
  103 +
  104 +//按 1.公司编号 2.机会类型编号 3.模板编号
  105 +//获取审核模板列表
  106 +func GetAuditTemplate(companyId int64, chanceTypeId, templateId int) (v *AuditTemplate, err error) {
  107 + o := orm.NewOrm()
  108 + sql := "select * from audit_template where id=? and company_id=? and chance_type_id=? and enable_status=1"
  109 + if err = o.Raw(sql, templateId, companyId, chanceTypeId).QueryRow(&v); err == nil {
  110 + return
  111 + }
  112 + return
  113 +}
@@ -15,8 +15,8 @@ const ( @@ -15,8 +15,8 @@ const (
15 ) 15 )
16 16
17 const ( 17 const (
18 - ActionTypeOr = 1  
19 - ActionTypeAnd = 2 18 + ActionTypeAnd = 1 //会签
  19 + ActionTypeOr = 2 //或签
20 ) 20 )
21 21
22 //审核类型 22 //审核类型
@@ -92,6 +92,15 @@ type TemplatesResponse struct { @@ -92,6 +92,15 @@ type TemplatesResponse struct {
92 Templates []*Template `json:"list"` 92 Templates []*Template `json:"list"`
93 } 93 }
94 94
  95 +/*Template 模板详情*/
  96 +type TemplateRequest struct {
  97 + ChanceTypeId int `json:"chanceTypeId" valid:"Required"`
  98 + TemplateId int `json:"templateId" valid:"Required"`
  99 +}
  100 +type TemplateResponse struct {
  101 + Template *Template `json:"template"`
  102 +}
  103 +
95 /*ChanceExample 机会示例*/ 104 /*ChanceExample 机会示例*/
96 type ChanceExampleRequest struct { 105 type ChanceExampleRequest struct {
97 TemplateId int `json:"templateId" valid:"Required"` 106 TemplateId int `json:"templateId" valid:"Required"`
@@ -114,6 +123,22 @@ type ChanceSubmitRequest struct { @@ -114,6 +123,22 @@ type ChanceSubmitRequest struct {
114 type ChanceSubmitResponse struct { 123 type ChanceSubmitResponse struct {
115 } 124 }
116 125
  126 +/*ChanceUpdate 机会更新*/
  127 +type ChanceUpdateRequest struct {
  128 + Id int64 `json:"id"` // = 0添加 >0 编辑
  129 + //AuditTemplateId int64 `json:"auditTemplateId" valid:"Required"`
  130 + Content string `json:"content"`
  131 + FormList []*Form `json:"formList" valid:"Required"`
  132 + Speechs []Speech `json:"speechs"`
  133 + Pictures []Picture `json:"pictures"`
  134 + Videos []Video `json:"videos"`
  135 + RelatedDepartment int64 `json:"relatedDepartments" valid:"Required"`
  136 +
  137 + IsPublish bool `json:"isPublish"` //是否重新发布
  138 +}
  139 +type ChanceUpdateResponse struct {
  140 +}
  141 +
117 /*ChanceStatistics 首页-机会池统计*/ 142 /*ChanceStatistics 首页-机会池统计*/
118 type ChanceStatisticsRequest struct { 143 type ChanceStatisticsRequest struct {
119 } 144 }
@@ -361,6 +386,8 @@ type ChanceChangeScoreRequest struct { @@ -361,6 +386,8 @@ type ChanceChangeScoreRequest struct {
361 Score Score `json:"score"` 386 Score Score `json:"score"`
362 } 387 }
363 type ChanceChangeScoreResponse struct { 388 type ChanceChangeScoreResponse struct {
  389 + DiscoveryScore float64 `json:"discoveryScore"` //发现分
  390 + DiscoveryScorePercent int `json:"discoveryScorePercent"` //发现分-百分比
364 } 391 }
365 392
366 /*ChanceCalculateScore 计算发现分*/ 393 /*ChanceCalculateScore 计算发现分*/
@@ -54,6 +54,18 @@ func init() { @@ -54,6 +54,18 @@ func init() {
54 MapStaticName[MyAuditChanceReturn] = "我审核的机会-已退回" 54 MapStaticName[MyAuditChanceReturn] = "我审核的机会-已退回"
55 } 55 }
56 56
  57 +var ApproveLog = map[int]string{
  58 + 1: "提交了机会", //提交人提交机会
  59 + 2: "删除了机会", //提交人删除机会
  60 + 3: "退回了机会", //审批人退回机会
  61 + 4: "通过了机会;基础评分:%v分,附加评分:%v分,价值评分:%v分,公开状态:公司公开", //审批人通过机会(公司公开)
  62 + 5: "通过了机会;基础评分:%v分,附加评分:%v分,价值评分:%v分,公开状态:%v", //审批人通过机会(部门公开) 测试部、销售部
  63 + 6: "系统 自动通过了机会;基础评分:0,附加评分:0,价值评分:0,公开状态:公司公开", //审批人通过了机会(系统自动通过)
  64 + 7: "修改了公开状态:公司公开", //审批通过后修改公开状态(公司公开)
  65 + 8: "修改了公开状态:%v", //审批通过后修改公开状态(部门公开)
  66 + 9: "修改了基础评分:“修改后的基础评分%v分,修改后的附加评分%v分,修改后的价值评分%v分“", //审批通过后修改评分
  67 +}
  68 +
57 //用户项 69 //用户项
58 type UserItem struct { 70 type UserItem struct {
59 Uid int64 `json:"uid"` 71 Uid int64 `json:"uid"`
@@ -241,6 +241,14 @@ func init() { @@ -241,6 +241,14 @@ func init() {
241 241
242 beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"], 242 beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
243 beego.ControllerComments{ 243 beego.ControllerComments{
  244 + Method: "Template",
  245 + Router: `/template`,
  246 + AllowHTTPMethods: []string{"post"},
  247 + MethodParams: param.Make(),
  248 + Params: nil})
  249 +
  250 + beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
  251 + beego.ControllerComments{
244 Method: "Templates", 252 Method: "Templates",
245 Router: `/templates`, 253 Router: `/templates`,
246 AllowHTTPMethods: []string{"post"}, 254 AllowHTTPMethods: []string{"post"},
@@ -255,6 +263,14 @@ func init() { @@ -255,6 +263,14 @@ func init() {
255 MethodParams: param.Make(), 263 MethodParams: param.Make(),
256 Params: nil}) 264 Params: nil})
257 265
  266 + beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
  267 + beego.ControllerComments{
  268 + Method: "ChanceUpdate",
  269 + Router: `/update`,
  270 + AllowHTTPMethods: []string{"post"},
  271 + MethodParams: param.Make(),
  272 + Params: nil})
  273 +
258 beego.GlobalControllerRouter["opp/controllers/v1:CommendController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:CommendController"], 274 beego.GlobalControllerRouter["opp/controllers/v1:CommendController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:CommendController"],
259 beego.ControllerComments{ 275 beego.ControllerComments{
260 Method: "Company", 276 Method: "Company",
@@ -349,7 +349,7 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro @@ -349,7 +349,7 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
349 mapChance["ReviewStatus"] = int8(request.ReviewStatus) //退回也要更新审核状态 349 mapChance["ReviewStatus"] = int8(request.ReviewStatus) //退回也要更新审核状态
350 //增加一条待处理记录到审核列表 350 //增加一条待处理记录到审核列表
351 //生成提交记录 351 //生成提交记录
352 - if _, err = orm.Insert(GenAuditFlowProcess_Submit(header, chance.Id, chance.AuditTemplateId, protocol.ReviewStatusWait)); err != nil { 352 + if _, err = orm.Insert(GenAuditFlowProcess_Submit(chance.UserId, chance.Id, chance.AuditTemplateId, protocol.ReviewStatusWait)); err != nil {
353 log.Error(err) 353 log.Error(err)
354 orm.Rollback() 354 orm.Rollback()
355 return 355 return
@@ -235,6 +235,48 @@ func Templates(header *protocol.RequestHeader, request *protocol.TemplatesReques @@ -235,6 +235,48 @@ func Templates(header *protocol.RequestHeader, request *protocol.TemplatesReques
235 return 235 return
236 } 236 }
237 237
  238 +//模板详情
  239 +func Template(header *protocol.RequestHeader, request *protocol.TemplateRequest) (rsp *protocol.TemplateResponse, err error) {
  240 + var (
  241 + templates *models.AuditTemplate
  242 + forms []*models.AuditForm
  243 + )
  244 + rsp = &protocol.TemplateResponse{}
  245 + if templates, err = models.GetAuditTemplate(header.CompanyId, request.ChanceTypeId, request.TemplateId); err != nil {
  246 + log.Error(fmt.Sprintf("公司:%v chance_type_id:%v id:%v无模板 ", header.CompanyId, request.ChanceTypeId, request.TemplateId), err)
  247 + return
  248 + }
  249 + item := templates
  250 + //TODO:检查模板可见
  251 + //
  252 + //查询表单
  253 + if forms, err = models.GetAuditForms(header.CompanyId, item.Id); err != nil {
  254 + log.Error(err)
  255 + return
  256 + }
  257 + template := &protocol.Template{
  258 + Id: item.Id,
  259 + Name: item.Name,
  260 + Icon: item.Icon,
  261 + Doc: item.Doc,
  262 + FormList: make([]*protocol.Form, len(forms)),
  263 + Link: fmt.Sprintf("%v/#/ability/opportunity?id=%v", beego.AppConfig.String("h5_host"), item.Id),
  264 + }
  265 + for j := range forms {
  266 + form := forms[j]
  267 + template.FormList[j] = &protocol.Form{
  268 + Id: form.Id,
  269 + Label: form.Label,
  270 + Value: "",
  271 + InputType: form.InputType,
  272 + SectionType: form.Section,
  273 + Required: form.Required,
  274 + }
  275 + }
  276 + rsp.Template = template
  277 + return
  278 +}
  279 +
238 func checkTemplateIsVisible(header *protocol.RequestHeader, template *models.AuditTemplate) (result bool, err error) { 280 func checkTemplateIsVisible(header *protocol.RequestHeader, template *models.AuditTemplate) (result bool, err error) {
239 //if template.VisibleType == 281 //if template.VisibleType ==
240 return 282 return
@@ -302,7 +344,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit @@ -302,7 +344,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit
302 } 344 }
303 345
304 //生成提交记录 346 //生成提交记录
305 - if _, err = orm.Insert(GenAuditFlowProcess_Submit(header, chance.Id, template.Id, protocol.ReviewStatusSubmit)); err != nil { 347 + if _, err = orm.Insert(GenAuditFlowProcess_Submit(header.UserId, chance.Id, template.Id, protocol.ReviewStatusSubmit)); err != nil {
306 log.Error(err) 348 log.Error(err)
307 orm.Rollback() 349 orm.Rollback()
308 return 350 return
@@ -368,35 +410,67 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit @@ -368,35 +410,67 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit
368 } 410 }
369 411
370 //机会编辑 412 //机会编辑
371 -func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceSubmitRequest) (rsp *protocol.ChanceSubmitResponse, err error) { 413 +func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdateRequest) (rsp *protocol.ChanceUpdateResponse, err error) {
372 var ( 414 var (
373 template *models.AuditTemplate 415 template *models.AuditTemplate
374 chance *models.Chance 416 chance *models.Chance
375 auditConfig *protocol.AuditConfig 417 auditConfig *protocol.AuditConfig
376 chanceData *models.ChanceData 418 chanceData *models.ChanceData
377 - //auditFlows []*models.AuditFlowProcess 419 + //auditFlows *models.AuditFlowProcess
378 updateMap = make(map[string]interface{}) 420 updateMap = make(map[string]interface{})
  421 +
  422 + auditFlows []*models.AuditFlowProcess
  423 + suplusApprove SuplusApprove
  424 + chanceType *models.ChanceType
379 ) 425 )
  426 + //验证机会是否存在
380 if chance, err = models.GetChanceById(request.Id); err != nil { 427 if chance, err = models.GetChanceById(request.Id); err != nil {
381 - log.Error(err) 428 + log.Error(request.Id, err)
  429 + err = protocol.NewErrWithMessage(5101)
  430 + return
  431 + }
  432 + //1.模板是否存在
  433 + if template, err = models.GetAuditTemplateById(int64(chance.AuditTemplateId)); err != nil {
  434 + log.Error("模板不存在:", chance.AuditTemplateId, err)
382 return 435 return
383 } 436 }
384 - //TODO:非本人 1.需要验证角色权限,是否是审核人 437 + if chanceType, err = models.GetChanceTypeById(chance.ChanceTypeId); err != nil {
  438 + log.Error("一级分类不存在:", chance.ChanceTypeId, err)
  439 + return
  440 + }
  441 + //编辑重新发布 是否可以重新发布
  442 + if request.IsPublish && chance.ReviewStatus == protocol.ReviewStatusReturn && chance.UserId == header.UserId {
  443 + request.IsPublish = false
  444 + //当前没有被人审核过
  445 + //if _, e := models.GetAuditFlowProcessApproved(request.Id, 1); e == orm.ErrNoRows && chance.AuditLevel == 1 {
  446 + // //当前状态是退回-待处理
  447 + //
  448 + //}
  449 + if _, e := models.GetAuditFlowProcessByReview(request.Id, 0, protocol.ReviewStatusWait); e == nil {
  450 + request.IsPublish = true
  451 + }
  452 + } else {
  453 + request.IsPublish = false
  454 + }
  455 + //TODO:非本人 1.需要验证角色权限 2是否是审核人 3.是否是本人 (目前本人才可以审核)
385 if chance.UserId != header.Uid { 456 if chance.UserId != header.Uid {
386 - err = protocol.NewErrWithMessage(1) 457 + err = protocol.NewErrWithMessage(5206)
387 log.Error(fmt.Sprintf("user:%v 无权限操作机会 chance:%v", header.Uid, chance.Id)) 458 log.Error(fmt.Sprintf("user:%v 无权限操作机会 chance:%v", header.Uid, chance.Id))
388 return 459 return
389 } 460 }
390 - //TODO:验证机会当前是否在审核中  
391 //1.模板是否存在 461 //1.模板是否存在
392 - if template, err = models.GetAuditTemplateById(request.AuditTemplateId); err != nil {  
393 - log.Error("模板不存在:", request.AuditTemplateId, err) 462 + if template, err = models.GetAuditTemplateById(chance.AuditTemplateId); err != nil {
  463 + log.Error("模板不存在:", chance.AuditTemplateId, err)
  464 + err = protocol.NewErrWithMessage(5301)
394 return 465 return
395 } 466 }
396 auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover} 467 auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover}
397 orm := orm.NewOrm() 468 orm := orm.NewOrm()
398 orm.Begin() 469 orm.Begin()
399 { 470 {
  471 + if request.IsPublish {
  472 + updateMap["ReviewStatus"] = int8(protocol.ReviewStatusAuditging)
  473 + }
400 updateMap["AuditTemplateConfig"] = common.AssertJson(auditConfig) 474 updateMap["AuditTemplateConfig"] = common.AssertJson(auditConfig)
401 updateMap["Content"] = request.Content 475 updateMap["Content"] = request.Content
402 updateMap["SourceContent"] = common.AssertJson(request.FormList) 476 updateMap["SourceContent"] = common.AssertJson(request.FormList)
@@ -440,11 +514,56 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceSubmit @@ -440,11 +514,56 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceSubmit
440 } 514 }
441 } 515 }
442 } 516 }
443 - orm.Commit()  
444 517
445 - //6.激活审核流  
446 - //TODO:7.发送消息通知给审核人(审核消息)  
447 - rsp = &protocol.ChanceSubmitResponse{} 518 + {
  519 + if request.IsPublish {
  520 +
  521 + //更新待处理->提交
  522 + if err = models.UpdatetAuditFlowProcessToSubmit(orm, request.Id, 0, protocol.ReviewStatusSubmit, header.UserId); err != nil {
  523 + log.Error(err)
  524 + orm.Rollback()
  525 + return
  526 + }
  527 + //4.查询审核配置
  528 + //5.生成审核流
  529 + if auditFlows, err = GenAuditFlowProcess(header, chance.Id, chance.DepartmentId, template.Id, auditConfig); err != nil {
  530 + log.Error(err)
  531 + orm.Rollback()
  532 + return
  533 + }
  534 + for i := 0; i < len(auditFlows); i++ {
  535 + auditFlows[i].ApproveMessage = fmt.Sprintf(protocol.MessageApproving, chanceType.Name)
  536 + //auditFlows[i].TemplateId = int(template.Id)
  537 + if _, err = orm.Insert(auditFlows[i]); err != nil {
  538 + log.Error(err)
  539 + orm.Rollback()
  540 + return
  541 + }
  542 + }
  543 + if len(auditFlows) > 0 {
  544 + //7.发送审批实例给审批服务器
  545 + if m, e := suplusApprove.NewApproveInstance(header, auditFlows); e != nil {
  546 + log.Error(fmt.Sprintf("uid:%v", header.UserId), "request suplus-approve.NewApproveInstance err", e)
  547 + orm.Rollback()
  548 + err = e
  549 + return
  550 + } else {
  551 + //7.发送消息通知给审核人(审核消息)
  552 + for i := range m.MessageData {
  553 + message := m.MessageData[i]
  554 + if err = agg.SendApproveMsg(message.ReceiverInfo.ReceiverUid, message.ReceiverInfo.ReceiverName,
  555 + header.CompanyId, chance.Id, chance.ChanceTypeId, protocol.ReviewStatusAuditging); err != nil {
  556 + log.Error(err)
  557 + orm.Rollback()
  558 + return
  559 + }
  560 + }
  561 + }
  562 + }
  563 + }
  564 + }
  565 + orm.Commit()
  566 + rsp = &protocol.ChanceUpdateResponse{}
448 return 567 return
449 } 568 }
450 569
@@ -549,7 +668,10 @@ func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceC @@ -549,7 +668,10 @@ func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceC
549 return 668 return
550 } 669 }
551 orm.Commit() 670 orm.Commit()
552 - rsp = &protocol.ChanceChangeScoreResponse{} 671 + rsp = &protocol.ChanceChangeScoreResponse{
  672 + DiscoveryScore: result.DiscoveryScore,
  673 + DiscoveryScorePercent: result.DiscoveryScorePercent,
  674 + }
553 return 675 return
554 } 676 }
555 677
@@ -626,18 +748,19 @@ func ChancePermission(header *protocol.RequestHeader, request *protocol.ChancePe @@ -626,18 +748,19 @@ func ChancePermission(header *protocol.RequestHeader, request *protocol.ChancePe
626 } 748 }
627 749
628 //生成审批流-提交记录 750 //生成审批流-提交记录
629 -func GenAuditFlowProcess_Submit(header *protocol.RequestHeader, chanceId int64, templateId int64, reviewStatus int) (v *models.AuditFlowProcess) { 751 +func GenAuditFlowProcess_Submit(userId, chanceId int64, templateId int64, reviewStatus int) (v *models.AuditFlowProcess) {
630 v = &models.AuditFlowProcess{ 752 v = &models.AuditFlowProcess{
631 Id: idgen.Next(), 753 Id: idgen.Next(),
632 ChanceId: chanceId, 754 ChanceId: chanceId,
633 - Uid: header.UserId, 755 + Uid: userId,
634 CreateAt: time.Now(), 756 CreateAt: time.Now(),
635 UpdateAt: time.Now(), 757 UpdateAt: time.Now(),
636 ApproveTime: time.Now(), 758 ApproveTime: time.Now(),
637 EnableStatus: 1, 759 EnableStatus: 1,
  760 + IsActive: 1,
638 ReviewStatus: int8(reviewStatus), 761 ReviewStatus: int8(reviewStatus),
639 } 762 }
640 - if approver, err := models.GetUsersById(header.Uid); err != nil { 763 + if approver, err := models.GetUsersById(userId); err != nil {
641 log.Error(err) 764 log.Error(err)
642 return 765 return
643 } else { 766 } else {
@@ -656,7 +779,8 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related @@ -656,7 +779,8 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related
656 company *models.Company 779 company *models.Company
657 roleName string 780 roleName string
658 approver *models.User 781 approver *models.User
659 - roleId []int 782 + roleIds []int
  783 + roleId int
660 ) 784 )
661 if configs, err = models.GetAuditFlowConfigsLevel(templateId, 1); err != nil { 785 if configs, err = models.GetAuditFlowConfigsLevel(templateId, 1); err != nil {
662 if err == orm.ErrNoRows { 786 if err == orm.ErrNoRows {
@@ -738,11 +862,15 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related @@ -738,11 +862,15 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related
738 } 862 }
739 break 863 break
740 case protocol.AuditByRole: 864 case protocol.AuditByRole:
741 - if e := json.Unmarshal([]byte(config.ToRole), &roleId); e == nil {  
742 - if userIds, err = getRoleUsers(header, roleId[0]); err != nil { 865 + if e := json.Unmarshal([]byte(config.ToRole), &roleIds); e == nil {
  866 + if userIds, err = getRoleUsers(header, roleIds[0]); err != nil {
743 log.Error(err) 867 log.Error(err)
744 return 868 return
745 } 869 }
  870 + if role, e := models.GetRoleById(roleIds[0]); e == nil {
  871 + roleName = role.Name
  872 + roleId = role.Id
  873 + }
746 } else { 874 } else {
747 log.Error(config.ToRole, e) 875 log.Error(config.ToRole, e)
748 } 876 }
@@ -779,6 +907,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related @@ -779,6 +907,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related
779 ActionType: int(config.ActionType), 907 ActionType: int(config.ActionType),
780 RoleName: roleName, 908 RoleName: roleName,
781 UserName: approver.NickName, 909 UserName: approver.NickName,
  910 + RoleId: roleId,
782 ReviewStatus: protocol.ReviewStatusAuditging, 911 ReviewStatus: protocol.ReviewStatusAuditging,
783 TemplateId: int(templateId), 912 TemplateId: int(templateId),
784 } 913 }
@@ -786,7 +915,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related @@ -786,7 +915,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related
786 item.IsActive = 1 915 item.IsActive = 1
787 item.EnableStatus = 1 916 item.EnableStatus = 1
788 } 917 }
789 - 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))) 918 + 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))
790 v = append(v, item) 919 v = append(v, item)
791 } 920 }
792 } 921 }
@@ -794,10 +923,10 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related @@ -794,10 +923,10 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related
794 } 923 }
795 func resolveActionType(t uint) string { 924 func resolveActionType(t uint) string {
796 if t == 1 { 925 if t == 1 {
797 - return "or" 926 + return "and"
798 } 927 }
799 if t == 2 { 928 if t == 2 {
800 - return "and" 929 + return "or"
801 } 930 }
802 return fmt.Sprintf("%v", t) 931 return fmt.Sprintf("%v", t)
803 } 932 }