作者 yangfu

增加审核日志

  1 +package models
  2 +
  3 +import (
  4 + "fmt"
  5 + "time"
  6 +
  7 + "github.com/astaxie/beego/orm"
  8 +)
  9 +
  10 +type AuditFlowLog struct {
  11 + Id int `orm:"column(id);auto" description:"唯一编号"`
  12 + ChanceId int64 `orm:"column(chance_id)" description:"表chance.id 所属机会编号"`
  13 + Content string `orm:"column(content);size(500)" description:"内容 json"`
  14 + ApproveUserId int64 `orm:"column(approve_user_id)" description:"审核人用户编号"`
  15 + CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now" description:"创建时间"`
  16 + Code int `orm:"column(code)" description:"消息编码"`
  17 +}
  18 +
  19 +func (t *AuditFlowLog) TableName() string {
  20 + return "audit_flow_log"
  21 +}
  22 +
  23 +func init() {
  24 + orm.RegisterModel(new(AuditFlowLog))
  25 +}
  26 +
  27 +// AddAuditFlowLog insert a new AuditFlowLog into database and returns
  28 +// last inserted Id on success.
  29 +func AddAuditFlowLog(m *AuditFlowLog) (id int64, err error) {
  30 + o := orm.NewOrm()
  31 + id, err = o.Insert(m)
  32 + return
  33 +}
  34 +
  35 +// GetAuditFlowLogById retrieves AuditFlowLog by Id. Returns error if
  36 +// Id doesn't exist
  37 +func GetAuditFlowLogById(id int) (v *AuditFlowLog, err error) {
  38 + o := orm.NewOrm()
  39 + v = &AuditFlowLog{Id: id}
  40 + if err = o.Read(v); err == nil {
  41 + return v, nil
  42 + }
  43 + return nil, err
  44 +}
  45 +
  46 +// UpdateAuditFlowLog updates AuditFlowLog by Id and returns error if
  47 +// the record to be updated doesn't exist
  48 +func UpdateAuditFlowLogById(m *AuditFlowLog) (err error) {
  49 + o := orm.NewOrm()
  50 + v := AuditFlowLog{Id: m.Id}
  51 + // ascertain id exists in the database
  52 + if err = o.Read(&v); err == nil {
  53 + var num int64
  54 + if num, err = o.Update(m); err == nil {
  55 + fmt.Println("Number of records updated in database:", num)
  56 + }
  57 + }
  58 + return
  59 +}
  60 +
  61 +// DeleteAuditFlowLog deletes AuditFlowLog by Id and returns error if
  62 +// the record to be deleted doesn't exist
  63 +func DeleteAuditFlowLog(id int) (err error) {
  64 + o := orm.NewOrm()
  65 + v := AuditFlowLog{Id: id}
  66 + // ascertain id exists in the database
  67 + if err = o.Read(&v); err == nil {
  68 + var num int64
  69 + if num, err = o.Delete(&AuditFlowLog{Id: id}); err == nil {
  70 + fmt.Println("Number of records deleted in database:", num)
  71 + }
  72 + }
  73 + return
  74 +}
@@ -131,10 +131,9 @@ func GetAuditFlowProcessList(chanceId int64) (v []*AuditFlowProcess, err error) @@ -131,10 +131,9 @@ func GetAuditFlowProcessList(chanceId int64) (v []*AuditFlowProcess, err error)
131 } 131 }
132 132
133 //删除机会时关闭所有审核信息 133 //删除机会时关闭所有审核信息
134 -func CloseAuditFlowProcess(chanceId int64) (err error) {  
135 - o := orm.NewOrm() 134 +func CloseAuditFlowProcess(orm orm.Ormer, chanceId int64) (err error) {
136 sql := "update audit_flow_process set enable_status =0,is_active=0,update_at=now() where chance_id=?" 135 sql := "update audit_flow_process set enable_status =0,is_active=0,update_at=now() where chance_id=?"
137 - if err = utils.ExecuteSQLWithOrmer(o, sql, chanceId); err != nil { 136 + if err = utils.ExecuteSQLWithOrmer(orm, sql, chanceId); err != nil {
138 return 137 return
139 } 138 }
140 return 139 return
@@ -154,7 +153,7 @@ func GetAuditFlowProcessApproved(chanceId int64, level int) (v *[]AuditFlowProce @@ -154,7 +153,7 @@ func GetAuditFlowProcessApproved(chanceId int64, level int) (v *[]AuditFlowProce
154 func GetAuditFlowProcessByReview(chanceId int64, level int, reviewStatus int) (v *AuditFlowProcess, err error) { 153 func GetAuditFlowProcessByReview(chanceId int64, level int, reviewStatus int) (v *AuditFlowProcess, err error) {
155 o := orm.NewOrm() 154 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" 155 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 { 156 + if err = utils.ExecuteQueryOneWithOrmer(o, &v, sql, chanceId, level, reviewStatus); err != nil {
158 return 157 return
159 } 158 }
160 return 159 return
@@ -32,6 +32,7 @@ type Chance struct { @@ -32,6 +32,7 @@ type Chance struct {
32 PublishStatus int `orm:"column(publish_status)" description:"公开状态 0未公开、1部门公开、2公司公开"` 32 PublishStatus int `orm:"column(publish_status)" description:"公开状态 0未公开、1部门公开、2公司公开"`
33 ApproveData string `orm:"column(approve_data)" description:"审核数据 冗余"` 33 ApproveData string `orm:"column(approve_data)" description:"审核数据 冗余"`
34 AuditLevel int `orm:"column(audit_level)" description:"当前审批步骤"` 34 AuditLevel int `orm:"column(audit_level)" description:"当前审批步骤"`
  35 + ApproveTime time.Time `orm:"column(approve_time);type(timestamp)" description:"审批时间"`
35 } 36 }
36 37
37 func (t *Chance) TableName() string { 38 func (t *Chance) TableName() string {
@@ -103,7 +104,7 @@ func DeleteChance(id int64) (err error) { @@ -103,7 +104,7 @@ func DeleteChance(id int64) (err error) {
103 func GetChanceMyChance(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) { 104 func GetChanceMyChance(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) {
104 sql := `select a.*,b.images,speechs,videos 105 sql := `select a.*,b.images,speechs,videos
105 from ( 106 from (
106 -select id,user_id,create_at,source_content,approve_data,review_status from chance 107 +select id,user_id,create_at,update_at,approve_time chance_approve_time,source_content,approve_data,review_status from chance
107 where user_id=? and company_id=? and review_status in (?) and (?=0 or id<?) 108 where user_id=? and company_id=? and review_status in (?) and (?=0 or id<?)
108 order by create_at desc 109 order by create_at desc
109 limit ? 110 limit ?
@@ -126,7 +127,7 @@ where user_id=? and company_id=? and review_status in (%v) @@ -126,7 +127,7 @@ where user_id=? and company_id=? and review_status in (%v)
126 127
127 func GetChanceMyApproveChance(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) { 128 func GetChanceMyApproveChance(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) {
128 sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from ( 129 sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from (
129 -select a.*,b.user_id,b.source_content,b.enable_status,b.review_status from ( 130 +select a.*,b.user_id,b.source_content,b.enable_status,b.review_status,b.create_at,b.update_at,b.approve_time chance_approve_time from (
130 select id,approve_time,approve_data,uid,chance_id,approve_message,create_at process_create_time 131 select id,approve_time,approve_data,uid,chance_id,approve_message,create_at process_create_time
131 from audit_flow_process where uid=? and enable_status =1 and review_status in (%v) and (?=0 or id<?) 132 from audit_flow_process where uid=? and enable_status =1 and review_status in (%v) and (?=0 or id<?)
132 )a left outer join chance b on a.chance_id = b.id 133 )a left outer join chance b on a.chance_id = b.id
@@ -184,6 +184,8 @@ type ChanceItemOrm struct { @@ -184,6 +184,8 @@ type ChanceItemOrm struct {
184 Id int64 `orm:"column(id)"` 184 Id int64 `orm:"column(id)"`
185 Uid int64 `orm:"column(user_id)"` 185 Uid int64 `orm:"column(user_id)"`
186 CreateTime time.Time `orm:"column(create_at)"` 186 CreateTime time.Time `orm:"column(create_at)"`
  187 + UpdateTime time.Time `orm:"column(update_at)"`
  188 + ApproveTime time.Time `orm:"column(approve_time)"`
187 SourceContent string `orm:"column(source_content)"` 189 SourceContent string `orm:"column(source_content)"`
188 Images string `orm:"column(images)"` 190 Images string `orm:"column(images)"`
189 Voices string `orm:"column(speechs)"` 191 Voices string `orm:"column(speechs)"`
@@ -43,7 +43,7 @@ var errmessge ErrorMap = map[int]string{ @@ -43,7 +43,7 @@ var errmessge ErrorMap = map[int]string{
43 5204: "评分或者公开状态不能为空", 43 5204: "评分或者公开状态不能为空",
44 5205: "机会未审核通过,不能修改评分或者公开状态", 44 5205: "机会未审核通过,不能修改评分或者公开状态",
45 5206: "未找到审批节点或者无权限", 45 5206: "未找到审批节点或者无权限",
46 - //5207:"部门不存在", 46 + 5207: "公司管理员未设置",
47 47
48 //模板相关 48 //模板相关
49 5301: "机会模板不存在", 49 5301: "机会模板不存在",
@@ -152,6 +152,26 @@ func logMsg(msg *models.UserMsg, name string) { @@ -152,6 +152,26 @@ func logMsg(msg *models.UserMsg, name string) {
152 msg.MsgType, msg.ReceiveUserId, name, msg.Message, msg.SourceId, msg.SourceType)) 152 msg.MsgType, msg.ReceiveUserId, name, msg.Message, msg.SourceId, msg.SourceType))
153 } 153 }
154 154
155 -func SaveApproveLog(orm orm.Ormer, code int, userId int64, param ...interface{}) (err error) { 155 +//保查审核日志
  156 +func SaveApproveLog(orm orm.Ormer, code int, userId int64, chanceId int64, param ...interface{}) (err error) {
  157 + var (
  158 + message string
  159 + ok bool
  160 + )
  161 + if message, ok = protocol.ApproveLog[code]; !ok {
  162 + err = fmt.Errorf("approve log not exists code:%v", code)
  163 + return
  164 + }
  165 + message = fmt.Sprintf(message, param...)
  166 + if _, err = orm.Insert(&models.AuditFlowLog{
  167 + ChanceId: chanceId,
  168 + Content: message,
  169 + ApproveUserId: userId,
  170 + CreateAt: time.Now(),
  171 + Code: code,
  172 + }); err != nil {
  173 + log.Error(err)
  174 + }
  175 + log.Debug(fmt.Sprintf("保存审核日志: code:%v userId:%v chanceId:%v message:%v", code, userId, chanceId, message))
156 return 176 return
157 } 177 }
@@ -15,6 +15,7 @@ import ( @@ -15,6 +15,7 @@ import (
15 "opp/models" 15 "opp/models"
16 "opp/protocol" 16 "opp/protocol"
17 "opp/services/agg" 17 "opp/services/agg"
  18 + "strings"
18 "time" 19 "time"
19 ) 20 )
20 21
@@ -320,6 +321,8 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro @@ -320,6 +321,8 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
320 { 321 {
321 mapProcess["ReviewStatus"] = int8(request.ReviewStatus) 322 mapProcess["ReviewStatus"] = int8(request.ReviewStatus)
322 mapProcess["ApproveTime"] = time.Now() 323 mapProcess["ApproveTime"] = time.Now()
  324 + mapProcess["IsActive"] = int8(0)
  325 + mapChance["ApproveTime"] = time.Now()
323 if request.ReviewStatus == protocol.ReviewStatusPass { 326 if request.ReviewStatus == protocol.ReviewStatusPass {
324 mapProcess["BasicScore"] = request.ApproveData.Score.BasicScore 327 mapProcess["BasicScore"] = request.ApproveData.Score.BasicScore
325 mapProcess["ExtraScore"] = request.ApproveData.Score.ExtraScore 328 mapProcess["ExtraScore"] = request.ApproveData.Score.ExtraScore
@@ -408,6 +411,11 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro @@ -408,6 +411,11 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
408 } 411 }
409 } 412 }
410 } 413 }
  414 + if err = saveApproveMsgByApproveData(orm, request.ReviewStatus, chance, request.ApproveData); err != nil {
  415 + orm.Rollback()
  416 + log.Error("发送审核日志失败", err)
  417 + return
  418 + }
411 if err = utils.UpdateTableByMapWithOrmer(orm, process, mapProcess); err != nil { 419 if err = utils.UpdateTableByMapWithOrmer(orm, process, mapProcess); err != nil {
412 log.Error("更新机会审核流程 状态失败 process_id:", process.Id, err) 420 log.Error("更新机会审核流程 状态失败 process_id:", process.Id, err)
413 orm.Rollback() 421 orm.Rollback()
@@ -465,6 +473,40 @@ func ProcessIntegrate(header *protocol.RequestHeader, request *ProcessIntegrateR @@ -465,6 +473,40 @@ func ProcessIntegrate(header *protocol.RequestHeader, request *ProcessIntegrateR
465 return 473 return
466 } 474 }
467 475
  476 +//发送审核日志
  477 +func saveApproveMsgByApproveData(orm orm.Ormer, reviewStatus int, chance *models.Chance, approveData protocol.ApproveData) (err error) {
  478 + var (
  479 + parames = make([]interface{}, 0)
  480 + code = 0
  481 + )
  482 + if reviewStatus == protocol.ReviewStatusReturn {
  483 + //发送退回日志
  484 + code = 3
  485 + }
  486 + if reviewStatus == protocol.ReviewStatusPass {
  487 + //发送通过日志
  488 + score := approveData.Score
  489 + parames = append(parames, []interface{}{score.BasicScore, score.ExtraScore, score.ValueScore}...)
  490 + if approveData.PublicData.PublishStatus == protocol.PublicToCompany {
  491 + code = 4
  492 + }
  493 + if approveData.PublicData.PublishStatus == protocol.PublicToDepartment {
  494 + code = 5
  495 + var department []string
  496 + for i := range approveData.PublicData.VisibleObjects {
  497 + v := approveData.PublicData.VisibleObjects[i]
  498 + department = append(department, v.Name)
  499 + }
  500 + parames = append(parames, strings.Join(department, ","))
  501 + }
  502 + }
  503 + if err = agg.SaveApproveLog(orm, code, chance.UserId, chance.Id, parames...); err != nil {
  504 + log.Error(err)
  505 + return
  506 + }
  507 + return
  508 +}
  509 +
468 //系统审核状态转为审核类型 reviewStatus - > approveType 510 //系统审核状态转为审核类型 reviewStatus - > approveType
469 func ConverReviewStatus(reviewStatus int) (approveType int) { 511 func ConverReviewStatus(reviewStatus int) (approveType int) {
470 if reviewStatus == protocol.ReviewStatusPass { 512 if reviewStatus == protocol.ReviewStatusPass {
@@ -12,6 +12,7 @@ import ( @@ -12,6 +12,7 @@ import (
12 "opp/models" 12 "opp/models"
13 "opp/protocol" 13 "opp/protocol"
14 "opp/services/agg" 14 "opp/services/agg"
  15 + "strings"
15 "time" 16 "time"
16 ) 17 )
17 18
@@ -403,6 +404,12 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit @@ -403,6 +404,12 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit
403 return 404 return
404 } 405 }
405 } 406 }
  407 + //发送提交日志
  408 + if err = agg.SaveApproveLog(orm, 1, header.UserId, chance.Id); err != nil {
  409 + log.Error(err)
  410 + orm.Rollback()
  411 + return
  412 + }
406 orm.Commit() 413 orm.Commit()
407 414
408 rsp = &protocol.ChanceSubmitResponse{} 415 rsp = &protocol.ChanceSubmitResponse{}
@@ -449,10 +456,13 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate @@ -449,10 +456,13 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate
449 if _, e := models.GetAuditFlowProcessByReview(request.Id, 0, protocol.ReviewStatusWait); e == nil { 456 if _, e := models.GetAuditFlowProcessByReview(request.Id, 0, protocol.ReviewStatusWait); e == nil {
450 request.IsPublish = true 457 request.IsPublish = true
451 updateMap["DepartmentId"] = request.RelatedDepartment 458 updateMap["DepartmentId"] = request.RelatedDepartment
  459 + //log.Info(fmt.Sprintf("机会编辑 is_publish:%v chance.review_status:%v 是否是本人:%v",request.IsPublish,chance.ReviewStatus,chance.UserId==header.UserId))
  460 + } else {
  461 + log.Info(fmt.Sprintf("机会编辑 chance_id:%v chance.review_status:%v 无待处理 审核数据", request.Id, chance.ReviewStatus))
452 } 462 }
453 -  
454 } else { 463 } else {
455 request.IsPublish = false 464 request.IsPublish = false
  465 + log.Info(fmt.Sprintf("机会编辑 is_publish:%v chance.review_status:%v 是否是本人:%v", request.IsPublish, chance.ReviewStatus, chance.UserId == header.UserId))
456 } 466 }
457 //TODO:非本人 1.需要验证角色权限 2是否是审核人 3.是否是本人 (目前本人才可以审核) 467 //TODO:非本人 1.需要验证角色权限 2是否是审核人 3.是否是本人 (目前本人才可以审核)
458 if chance.UserId != header.UserId { 468 if chance.UserId != header.UserId {
@@ -561,6 +571,12 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate @@ -561,6 +571,12 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate
561 } 571 }
562 } 572 }
563 } 573 }
  574 + //发送提交日志
  575 + if err = agg.SaveApproveLog(orm, 1, chance.UserId, chance.Id); err != nil {
  576 + log.Error(err)
  577 + orm.Rollback()
  578 + return
  579 + }
564 } 580 }
565 } 581 }
566 orm.Commit() 582 orm.Commit()
@@ -621,12 +637,43 @@ func ChanceChangePublish(header *protocol.RequestHeader, request *protocol.Chanc @@ -621,12 +637,43 @@ func ChanceChangePublish(header *protocol.RequestHeader, request *protocol.Chanc
621 } 637 }
622 } 638 }
623 } 639 }
  640 +
  641 + if err = saveApproveMsgChangePublic(orm, chance, request.PublicData); err != nil {
  642 + log.Error(err)
  643 + orm.Rollback()
  644 + return
  645 + }
624 orm.Commit() 646 orm.Commit()
625 //TODO:添加log 647 //TODO:添加log
626 rsp = &protocol.ChanceChangePublishResponse{} 648 rsp = &protocol.ChanceChangePublishResponse{}
627 return 649 return
628 } 650 }
629 651
  652 +//发送审核日志
  653 +func saveApproveMsgChangePublic(orm orm.Ormer, chance *models.Chance, approveData protocol.PublicData) (err error) {
  654 + var (
  655 + parames = make([]interface{}, 0)
  656 + code = 0
  657 + )
  658 + if approveData.PublishStatus == protocol.PublicToCompany {
  659 + code = 7
  660 + }
  661 + if approveData.PublishStatus == protocol.PublicToDepartment {
  662 + code = 8
  663 + var department []string
  664 + for i := range approveData.VisibleObjects {
  665 + v := approveData.VisibleObjects[i]
  666 + department = append(department, v.Name)
  667 + }
  668 + parames = append(parames, strings.Join(department, ","))
  669 + }
  670 + if err = agg.SaveApproveLog(orm, code, chance.UserId, chance.Id, parames...); err != nil {
  671 + log.Error(err)
  672 + return
  673 + }
  674 + return
  675 +}
  676 +
630 //修改评分 677 //修改评分
631 func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceChangeScoreRequest) (rsp *protocol.ChanceChangeScoreResponse, err error) { 678 func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceChangeScoreRequest) (rsp *protocol.ChanceChangeScoreResponse, err error) {
632 var ( 679 var (
@@ -668,6 +715,17 @@ func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceC @@ -668,6 +715,17 @@ func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceC
668 orm.Rollback() 715 orm.Rollback()
669 return 716 return
670 } 717 }
  718 + //修改评分日志
  719 + if err = agg.SaveApproveLog(orm, 9, chance.UserId, chance.Id, request.Score.BasicScore, request.Score.ExtraScore, request.Score.ValueScore); err != nil {
  720 + log.Error(err)
  721 + return
  722 + }
  723 +
  724 + //if err = agg.SaveApproveLog(orm,9,chance.UserId,chance.Id,request.Score.BasicScore,request.Score.ExtraScore,request.Score.ValueScore);err!=nil{
  725 + // log.Error(err)
  726 + // return
  727 + //}
  728 +
671 orm.Commit() 729 orm.Commit()
672 rsp = &protocol.ChanceChangeScoreResponse{ 730 rsp = &protocol.ChanceChangeScoreResponse{
673 DiscoveryScore: result.DiscoveryScore, 731 DiscoveryScore: result.DiscoveryScore,
@@ -844,11 +902,13 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related @@ -844,11 +902,13 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related
844 902
845 if company.AdminId == 0 { 903 if company.AdminId == 0 {
846 err = fmt.Errorf("GenAuditFlowProcess:company.admin is not set") 904 err = fmt.Errorf("GenAuditFlowProcess:company.admin is not set")
  905 + err = protocol.NewErrWithMessage(5207)
847 return 906 return
848 } 907 }
849 908
850 if admin, err = models.GetUserCompanyByUserId(company.AdminId, header.CompanyId); err != nil { 909 if admin, err = models.GetUserCompanyByUserId(company.AdminId, header.CompanyId); err != nil {
851 err = fmt.Errorf("GenAuditFlowProcess:company.admin is not set") 910 err = fmt.Errorf("GenAuditFlowProcess:company.admin is not set")
  911 + err = protocol.NewErrWithMessage(5207)
852 return 912 return
853 } 913 }
854 914
@@ -943,6 +1003,7 @@ func resolveActionType(t uint) string { @@ -943,6 +1003,7 @@ func resolveActionType(t uint) string {
943 func getDepartmentors(header *protocol.RequestHeader, relatedDeparmentId int64) (ids []int64, err error) { 1003 func getDepartmentors(header *protocol.RequestHeader, relatedDeparmentId int64) (ids []int64, err error) {
944 var ( 1004 var (
945 departments *models.Department 1005 departments *models.Department
  1006 + lastDepartmentId int
946 ) 1007 )
947 //if err = models.GetUserDepartments(header.UserId, header.CompanyId, &departments); err != nil { 1008 //if err = models.GetUserDepartments(header.UserId, header.CompanyId, &departments); err != nil {
948 // log.Error(header.UserId,header.CompanyId,err) 1009 // log.Error(header.UserId,header.CompanyId,err)
@@ -952,6 +1013,7 @@ func getDepartmentors(header *protocol.RequestHeader, relatedDeparmentId int64) @@ -952,6 +1013,7 @@ func getDepartmentors(header *protocol.RequestHeader, relatedDeparmentId int64)
952 log.Error(relatedDeparmentId, err) 1013 log.Error(relatedDeparmentId, err)
953 return 1014 return
954 } 1015 }
  1016 + //部门长
955 for { 1017 for {
956 if len(departments.Managers) > 0 { 1018 if len(departments.Managers) > 0 {
957 var tmpIds []int64 1019 var tmpIds []int64
@@ -966,7 +1028,9 @@ func getDepartmentors(header *protocol.RequestHeader, relatedDeparmentId int64) @@ -966,7 +1028,9 @@ func getDepartmentors(header *protocol.RequestHeader, relatedDeparmentId int64)
966 //break 1028 //break
967 } 1029 }
968 if departments.ParentId != 0 { 1030 if departments.ParentId != 0 {
969 - if departments, err = models.GetDepartmentById(int(relatedDeparmentId)); err != nil { 1031 + //relatedDeparmentId = int64departments.ParentId
  1032 + lastDepartmentId = departments.ParentId
  1033 + if departments, err = models.GetDepartmentById(int(departments.ParentId)); err != nil {
970 log.Error(relatedDeparmentId, err) 1034 log.Error(relatedDeparmentId, err)
971 err = nil 1035 err = nil
972 break 1036 break
@@ -979,7 +1043,7 @@ func getDepartmentors(header *protocol.RequestHeader, relatedDeparmentId int64) @@ -979,7 +1043,7 @@ func getDepartmentors(header *protocol.RequestHeader, relatedDeparmentId int64)
979 if len(ids) == 0 { 1043 if len(ids) == 0 {
980 ids = append(ids, 0) 1044 ids = append(ids, 0)
981 } 1045 }
982 - log.Info(fmt.Sprintf("生成机会审批流-部门:department_id:%v managers:%v ids:%v", relatedDeparmentId, departments.Managers, ids)) 1046 + log.Info(fmt.Sprintf("生成机会审批流-部门:department_id:%v managers:%v ids:%v last_department_id:%v", relatedDeparmentId, departments.Managers, ids, lastDepartmentId))
983 return 1047 return
984 } 1048 }
985 1049
@@ -1083,6 +1147,8 @@ func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitCh @@ -1083,6 +1147,8 @@ func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitCh
1083 Id: chance.Id, 1147 Id: chance.Id,
1084 Provider: provider, 1148 Provider: provider,
1085 CreateTime: chance.CreateTime.Unix() * 1000, 1149 CreateTime: chance.CreateTime.Unix() * 1000,
  1150 + UpdateTime: chance.UpdateTime.Unix() * 1000,
  1151 + ApproveTime: chance.ApproveTime.Unix() * 1000,
1086 } 1152 }
1087 jsonUnmarshal(chance.SourceContent, &item.FormList) 1153 jsonUnmarshal(chance.SourceContent, &item.FormList)
1088 item.FormList = clearEmptyForm(item.FormList) 1154 item.FormList = clearEmptyForm(item.FormList)
@@ -1638,15 +1704,26 @@ func ChanceDelete(header *protocol.RequestHeader, request *protocol.ChanceDelete @@ -1638,15 +1704,26 @@ func ChanceDelete(header *protocol.RequestHeader, request *protocol.ChanceDelete
1638 err = protocol.NewErrWithMessage(5202) 1704 err = protocol.NewErrWithMessage(5202)
1639 return 1705 return
1640 } 1706 }
1641 - if err = utils.UpdateTableByMap(chance, map[string]interface{}{ 1707 + orm := orm.NewOrm()
  1708 + orm.Begin()
  1709 + //发送提交日志
  1710 + if err = agg.SaveApproveLog(orm, 2, chance.UserId, chance.Id); err != nil {
  1711 + log.Error(err)
  1712 + orm.Rollback()
  1713 + return
  1714 + }
  1715 + if err = utils.UpdateTableByMapWithOrmer(orm, chance, map[string]interface{}{
1642 "EnableStatus": int8(0), 1716 "EnableStatus": int8(0),
1643 }); err != nil { 1717 }); err != nil {
1644 log.Error(err) 1718 log.Error(err)
  1719 + orm.Rollback()
1645 return 1720 return
1646 } 1721 }
1647 - if err = models.CloseAuditFlowProcess(chance.Id); err != nil { 1722 + if err = models.CloseAuditFlowProcess(orm, chance.Id); err != nil {
1648 log.Error(err) 1723 log.Error(err)
  1724 + orm.Rollback()
1649 return 1725 return
1650 } 1726 }
  1727 + orm.Commit()
1651 return 1728 return
1652 } 1729 }