作者 yangfu

增加 多部门统计,机会补充详情

@@ -614,3 +614,24 @@ func (this *ChanceController) ChancePool() { @@ -614,3 +614,24 @@ func (this *ChanceController) ChancePool() {
614 header := controllers.GetRequestHeader(this.Ctx) 614 header := controllers.GetRequestHeader(this.Ctx)
615 msg = protocol.NewReturnResponse(chance.ChancePool(header, request)) 615 msg = protocol.NewReturnResponse(chance.ChancePool(header, request))
616 } 616 }
  617 +
  618 +//ChanceReviseDetail 机会补充详情
  619 +//@router /chanceReviseDetail [post]
  620 +func (this *ChanceController) ChanceReviseDetail() {
  621 + var msg *protocol.ResponseMessage
  622 + defer func() {
  623 + this.Resp(msg)
  624 + }()
  625 + var request *protocol.ChanceReviseDetailRequest
  626 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  627 + log.Error(err)
  628 + msg = protocol.BadRequestParam(1)
  629 + return
  630 + }
  631 + if b, m := this.Valid(request); !b {
  632 + msg = m
  633 + return
  634 + }
  635 + header := controllers.GetRequestHeader(this.Ctx)
  636 + msg = protocol.NewReturnResponse(chance.ChanceReviseDetail(header, request))
  637 +}
@@ -34,7 +34,7 @@ func (this *DepartmentController) Departments() { @@ -34,7 +34,7 @@ func (this *DepartmentController) Departments() {
34 msg = protocol.NewReturnResponse(department.Departments(header, request)) 34 msg = protocol.NewReturnResponse(department.Departments(header, request))
35 } 35 }
36 36
37 -//DepartmentStatistics 部门统计 37 +//DepartmentStatistics 部门统计
38 //@router /statistics [post] 38 //@router /statistics [post]
39 func (this *DepartmentController) DepartmentStatistics() { 39 func (this *DepartmentController) DepartmentStatistics() {
40 var msg *protocol.ResponseMessage 40 var msg *protocol.ResponseMessage
@@ -52,5 +52,26 @@ func (this *DepartmentController) DepartmentStatistics() { @@ -52,5 +52,26 @@ func (this *DepartmentController) DepartmentStatistics() {
52 return 52 return
53 } 53 }
54 header := controllers.GetRequestHeader(this.Ctx) 54 header := controllers.GetRequestHeader(this.Ctx)
55 - msg = protocol.NewReturnResponse(department.DepartmentStatistics(header, request)) 55 + msg = protocol.NewReturnResponse(department.Statistics(header, request))
  56 +}
  57 +
  58 +//DepartmentStatistic 单部门统计
  59 +//@router /statistic [post]
  60 +func (this *DepartmentController) DepartmentStatistic() {
  61 + var msg *protocol.ResponseMessage
  62 + defer func() {
  63 + this.Resp(msg)
  64 + }()
  65 + var request *protocol.DepartmentStatisticRequest
  66 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  67 + log.Error(err)
  68 + msg = protocol.BadRequestParam(1)
  69 + return
  70 + }
  71 + if b, m := this.Valid(request); !b {
  72 + msg = m
  73 + return
  74 + }
  75 + header := controllers.GetRequestHeader(this.Ctx)
  76 + msg = protocol.NewReturnResponse(department.DepartmentStatistic(header, request))
56 } 77 }
@@ -244,3 +244,26 @@ from user_msg where receive_user_id=? and source_type=1 and msg_type=? and send @@ -244,3 +244,26 @@ from user_msg where receive_user_id=? and source_type=1 and msg_type=? and send
244 } 244 }
245 return 245 return
246 } 246 }
  247 +
  248 +func GetChanceReviseMsg(uid, lastId int64, pageSize int, msgType int, v interface{}) (total int, err error) {
  249 + sql := `select a.*,b.images,b.speechs,b.videos from (
  250 +select a.*,b.source_content,b.enable_status,b.user_id chance_user_id,b.create_at,b.review_status,b.status from (
  251 +select id msg_id,message content,source_type,source_id,is_read,create_at msg_time,chance_id,receive_user_id,sender_user_id from user_msg
  252 +where receive_user_id =? and (?=0 or id<?) and msg_type=?
  253 +)a left outer join chance b on a.chance_id = b.id
  254 +)a left outer join chance_data b on a.source_id = b.chance_id
  255 +order by id
  256 +LIMIT ?`
  257 +
  258 + sqlCount := `select count(0)
  259 +from user_msg where receive_user_id=? and msg_type=?`
  260 + if err = utils.ExecuteQueryOne(&total, sqlCount, uid, msgType); err != nil {
  261 + return
  262 + }
  263 + if v != nil {
  264 + if err = utils.ExecuteQueryAll(v, sql, uid, lastId, lastId, msgType, pageSize); err != nil {
  265 + return
  266 + }
  267 + }
  268 + return
  269 +}
@@ -617,3 +617,23 @@ type CommentData struct { @@ -617,3 +617,23 @@ type CommentData struct {
617 //IsRead bool `json:"isRead"` //是否已读 617 //IsRead bool `json:"isRead"` //是否已读
618 Provider interface{} `json:"provider,omitempty"` 618 Provider interface{} `json:"provider,omitempty"`
619 } 619 }
  620 +
  621 +type ChanceReviseLog struct {
  622 + Provider *BaseUserInfo `json:"provider,omitempty"`
  623 + DiffContents []ReviseContent `json:"reviseContents"`
  624 + Speechs []Speech `json:"speechs"`
  625 + Pictures []Picture `json:"pictures"`
  626 + Videos []Video `json:"videos"`
  627 +}
  628 +
  629 +type ReviseContent struct {
  630 + Content string `json:"content"`
  631 +}
  632 +
  633 +/*ChanceReviseDetail 机会补充详情*/
  634 +type ChanceReviseDetailRequest struct {
  635 + Id int64 `json:"id"`
  636 +}
  637 +type ChanceReviseDetailResponse struct {
  638 + ChanceReviseData ChanceReviseLog `json:"chanceReviseData"`
  639 +}
@@ -108,3 +108,11 @@ type DepartmentStatistics struct { @@ -108,3 +108,11 @@ type DepartmentStatistics struct {
108 108
109 ACTotal int `json:"-"` //机会成果总数 (显示) 109 ACTotal int `json:"-"` //机会成果总数 (显示)
110 } 110 }
  111 +
  112 +/*DepartmentStatistic 单部门统计*/
  113 +type DepartmentStatisticRequest struct {
  114 + DepartmentId int `json:"did"`
  115 +}
  116 +type DepartmentStatisticResponse struct {
  117 + DepartmentStatistic DepartmentStatistics `json:"departmentStatistic"`
  118 +}
@@ -113,6 +113,14 @@ func init() { @@ -113,6 +113,14 @@ func init() {
113 113
114 beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"], 114 beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
115 beego.ControllerComments{ 115 beego.ControllerComments{
  116 + Method: "ChanceReviseDetail",
  117 + Router: `/chanceReviseDetail`,
  118 + AllowHTTPMethods: []string{"post"},
  119 + MethodParams: param.Make(),
  120 + Params: nil})
  121 +
  122 + beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
  123 + beego.ControllerComments{
116 Method: "ChanceType", 124 Method: "ChanceType",
117 Router: `/chanceType`, 125 Router: `/chanceType`,
118 AllowHTTPMethods: []string{"post"}, 126 AllowHTTPMethods: []string{"post"},
@@ -313,6 +321,14 @@ func init() { @@ -313,6 +321,14 @@ func init() {
313 321
314 beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"], 322 beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"],
315 beego.ControllerComments{ 323 beego.ControllerComments{
  324 + Method: "DepartmentStatistic",
  325 + Router: `/statistic`,
  326 + AllowHTTPMethods: []string{"post"},
  327 + MethodParams: param.Make(),
  328 + Params: nil})
  329 +
  330 + beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"],
  331 + beego.ControllerComments{
316 Method: "DepartmentStatistics", 332 Method: "DepartmentStatistics",
317 Router: `/statistics`, 333 Router: `/statistics`,
318 AllowHTTPMethods: []string{"post"}, 334 AllowHTTPMethods: []string{"post"},
@@ -235,4 +235,5 @@ func SetMsgItem(header *protocol.RequestHeader, msg protocol.MsgItemOrm, commIte @@ -235,4 +235,5 @@ func SetMsgItem(header *protocol.RequestHeader, msg protocol.MsgItemOrm, commIte
235 commItem.MsgTime = msg.MsgTime.Unix() * 1000 235 commItem.MsgTime = msg.MsgTime.Unix() * 1000
236 commItem.IsRead = msg.IsRead == 1 236 commItem.IsRead = msg.IsRead == 1
237 commItem.SourceId = msg.SourceId 237 commItem.SourceId = msg.SourceId
  238 + commItem.SourceType = msg.SourceType
238 } 239 }
@@ -578,7 +578,7 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate @@ -578,7 +578,7 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate
578 } 578 }
579 auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover} 579 auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover}
580 580
581 - go CheckChanceUpdate(header, chance, request) 581 + CheckChanceDifferent(header, chance, request)
582 582
583 orm := orm.NewOrm() 583 orm := orm.NewOrm()
584 orm.Begin() 584 orm.Begin()
@@ -712,9 +712,8 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate @@ -712,9 +712,8 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate
712 } 712 }
713 713
714 //检查机会更新 714 //检查机会更新
715 -func CheckChanceUpdate(header *protocol.RequestHeader, chance *models.Chance, request *protocol.ChanceUpdateRequest) { 715 +func CheckChanceDifferent(header *protocol.RequestHeader, chance *models.Chance, request *protocol.ChanceUpdateRequest) {
716 var ( 716 var (
717 - //chanceData *models.ChanceData  
718 isSaveLog bool = false 717 isSaveLog bool = false
719 chanceReviseLog *models.ChanceReviseLog 718 chanceReviseLog *models.ChanceReviseLog
720 message string 719 message string
@@ -729,21 +728,18 @@ func CheckChanceUpdate(header *protocol.RequestHeader, chance *models.Chance, re @@ -729,21 +728,18 @@ func CheckChanceUpdate(header *protocol.RequestHeader, chance *models.Chance, re
729 if header.UserId == chance.UserId { 728 if header.UserId == chance.UserId {
730 return 729 return
731 } 730 }
732 - type ChanceModifyLog struct {  
733 - DiffContents interface{} `json:"diffContents"`  
734 - Speechs []protocol.Speech `json:"speechs"`  
735 - Pictures []protocol.Picture `json:"pictures"`  
736 - Videos []protocol.Video `json:"videos"` 731 + var modifyLog = protocol.ChanceReviseLog{}
  732 + checkIsSaveLog := func() {
  733 + if !isSaveLog {
  734 + isSaveLog = true
  735 + }
737 } 736 }
738 - var modifyLog = ChanceModifyLog{} 737 +
739 diffFormList := func(source string, dis []*protocol.Form) { 738 diffFormList := func(source string, dis []*protocol.Form) {
740 - type DiffContent struct {  
741 - Content string `json:"content"`  
742 - }  
743 var ( 739 var (
744 - src []*protocol.Form  
745 - mapForm map[string]*protocol.Form = make(map[string]*protocol.Form)  
746 - diffStructs = []DiffContent{} 740 + src []*protocol.Form
  741 + mapForm map[string]*protocol.Form = make(map[string]*protocol.Form)
  742 + reviseContents []protocol.ReviseContent
747 ) 743 )
748 jsonUnmarshal(source, &src) 744 jsonUnmarshal(source, &src)
749 for i := range src { 745 for i := range src {
@@ -761,16 +757,13 @@ func CheckChanceUpdate(header *protocol.RequestHeader, chance *models.Chance, re @@ -761,16 +757,13 @@ func CheckChanceUpdate(header *protocol.RequestHeader, chance *models.Chance, re
761 isDiff = true 757 isDiff = true
762 } 758 }
763 if isDiff { 759 if isDiff {
764 - diffStructs = append(diffStructs, DiffContent{ 760 + reviseContents = append(reviseContents, protocol.ReviseContent{
765 Content: fmt.Sprintf("将“%v”由“%v”改为 “%v“", dis[i].Label, srcValue, dis[i].Value)}) 761 Content: fmt.Sprintf("将“%v”由“%v”改为 “%v“", dis[i].Label, srcValue, dis[i].Value)})
766 - if !isSaveLog {  
767 - isSaveLog = true  
768 - } 762 + checkIsSaveLog()
769 } 763 }
770 } 764 }
771 - modifyLog.DiffContents = diffStructs 765 + modifyLog.DiffContents = reviseContents
772 } 766 }
773 -  
774 diffChanceData := func() { 767 diffChanceData := func() {
775 var ( 768 var (
776 speechs []protocol.Speech 769 speechs []protocol.Speech
@@ -782,27 +775,19 @@ func CheckChanceUpdate(header *protocol.RequestHeader, chance *models.Chance, re @@ -782,27 +775,19 @@ func CheckChanceUpdate(header *protocol.RequestHeader, chance *models.Chance, re
782 jsonUnmarshal(chanceData.Images, &pictures) 775 jsonUnmarshal(chanceData.Images, &pictures)
783 jsonUnmarshal(chanceData.Videos, &videos) 776 jsonUnmarshal(chanceData.Videos, &videos)
784 if !reflect.DeepEqual(request.Videos, videos) || !reflect.DeepEqual(request.Pictures, pictures) { 777 if !reflect.DeepEqual(request.Videos, videos) || !reflect.DeepEqual(request.Pictures, pictures) {
785 - if !isSaveLog {  
786 - isSaveLog = true  
787 - } 778 + checkIsSaveLog()
788 modifyLog.Videos = request.Videos 779 modifyLog.Videos = request.Videos
789 } 780 }
790 if !reflect.DeepEqual(request.Pictures, pictures) { 781 if !reflect.DeepEqual(request.Pictures, pictures) {
791 - if !isSaveLog {  
792 - isSaveLog = true  
793 - } 782 + checkIsSaveLog()
794 modifyLog.Pictures = request.Pictures 783 modifyLog.Pictures = request.Pictures
795 } 784 }
796 if !reflect.DeepEqual(request.Speechs, speechs) { 785 if !reflect.DeepEqual(request.Speechs, speechs) {
797 - if !isSaveLog {  
798 - isSaveLog = true  
799 - } 786 + checkIsSaveLog()
800 modifyLog.Speechs = request.Speechs 787 modifyLog.Speechs = request.Speechs
801 } 788 }
802 } else { 789 } else {
803 - if !isSaveLog {  
804 - isSaveLog = true  
805 - } 790 + checkIsSaveLog()
806 modifyLog.Speechs = request.Speechs 791 modifyLog.Speechs = request.Speechs
807 modifyLog.Videos = request.Videos 792 modifyLog.Videos = request.Videos
808 modifyLog.Speechs = request.Speechs 793 modifyLog.Speechs = request.Speechs
@@ -2264,3 +2249,23 @@ func Permission(header *protocol.RequestHeader, request *protocol.PermissionRequ @@ -2264,3 +2249,23 @@ func Permission(header *protocol.RequestHeader, request *protocol.PermissionRequ
2264 } 2249 }
2265 return 2250 return
2266 } 2251 }
  2252 +
  2253 +//机会补充详情
  2254 +func ChanceReviseDetail(header *protocol.RequestHeader, request *protocol.ChanceReviseDetailRequest) (rsp *protocol.ChanceReviseDetailResponse, err error) {
  2255 + var (
  2256 + detail *models.ChanceReviseLog
  2257 + provider *protocol.BaseUserInfo
  2258 + )
  2259 + if detail, err = models.GetChanceReviseLogById(request.Id); err != nil {
  2260 + log.Error(err)
  2261 + return
  2262 + }
  2263 + rsp = &protocol.ChanceReviseDetailResponse{}
  2264 + if provider, err = agg.GetUserBaseInfo(detail.UserCompanyId, header.CompanyId); err != nil {
  2265 + log.Error(err)
  2266 + return
  2267 + }
  2268 + json.Unmarshal([]byte(detail.Data), &rsp.ChanceReviseData)
  2269 + rsp.ChanceReviseData.Provider = provider
  2270 + return
  2271 +}
@@ -74,8 +74,8 @@ func walkDepartment(to *protocol.Department, dfrom *models.Department) (err erro @@ -74,8 +74,8 @@ func walkDepartment(to *protocol.Department, dfrom *models.Department) (err erro
74 return nil 74 return nil
75 } 75 }
76 76
77 -//部门统计  
78 -func DepartmentStatistics(header *protocol.RequestHeader, request *protocol.DepartmentStatisticsRequest) (rsp *protocol.DepartmentStatisticsResponse, err error) { 77 +//多部门统计
  78 +func Statistics(header *protocol.RequestHeader, request *protocol.DepartmentStatisticsRequest) (rsp *protocol.DepartmentStatisticsResponse, err error) {
79 var ( 79 var (
80 departmentsResponse *protocol.DepartmentsResponse 80 departmentsResponse *protocol.DepartmentsResponse
81 ) 81 )
@@ -127,3 +127,31 @@ func DepartmentStatistics(header *protocol.RequestHeader, request *protocol.Depa @@ -127,3 +127,31 @@ func DepartmentStatistics(header *protocol.RequestHeader, request *protocol.Depa
127 sort.Sort(rsp) 127 sort.Sort(rsp)
128 return 128 return
129 } 129 }
  130 +
  131 +//单部门统计
  132 +func DepartmentStatistic(header *protocol.RequestHeader, request *protocol.DepartmentStatisticRequest) (rsp *protocol.DepartmentStatisticResponse, err error) {
  133 + var (
  134 + dIds []int
  135 + deparment *models.Department
  136 + )
  137 + rsp = &protocol.DepartmentStatisticResponse{}
  138 + if deparment, err = models.GetDepartmentById(request.DepartmentId); err != nil {
  139 + log.Error(err)
  140 + return
  141 + }
  142 + departmentStatistic := protocol.DepartmentStatistics{}
  143 + departmentStatistic.Dep = protocol.Dep{
  144 + Id: deparment.Id,
  145 + Name: deparment.Name,
  146 + }
  147 + if dIds, err = agg.GetDepartmentIds(header.CompanyId, request.DepartmentId); err != nil {
  148 + log.Error(err)
  149 + return
  150 + }
  151 + departmentStatistic.AchievementTotal, _ = agg.AchievementDepartmentStatic(header, 0, dIds)
  152 + departmentStatistic.ChanceApprovedTotal, _ = agg.GetChancePool(header.UserId, header.CompanyId, 0, request.DepartmentId, 0, 0, nil)
  153 + departmentStatistic.ACTotal = departmentStatistic.AchievementTotal + departmentStatistic.ChanceApprovedTotal
  154 + departmentStatistic.ChanceApprovingTotal, _ = agg.ChanceApprovingStatistic(header, dIds)
  155 + rsp.DepartmentStatistic = departmentStatistic
  156 + return
  157 +}
@@ -593,7 +593,7 @@ func MsgChanceRevise(header *protocol.RequestHeader, request *protocol.MsgChance @@ -593,7 +593,7 @@ func MsgChanceRevise(header *protocol.RequestHeader, request *protocol.MsgChance
593 total int 593 total int
594 ) 594 )
595 595
596 - if total, err = models.GetChanceCommentMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeThumbUp, &myChances); err != nil { 596 + if total, err = models.GetChanceReviseMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeChanceRevise, &myChances); err != nil {
597 if err == orm.ErrNoRows { 597 if err == orm.ErrNoRows {
598 err = nil 598 err = nil
599 return 599 return
@@ -611,7 +611,6 @@ func MsgChanceRevise(header *protocol.RequestHeader, request *protocol.MsgChance @@ -611,7 +611,6 @@ func MsgChanceRevise(header *protocol.RequestHeader, request *protocol.MsgChance
611 611
612 commItem.ChanceId = chance.ChanceId 612 commItem.ChanceId = chance.ChanceId
613 commItem.ReviewStatus = chance.ReviewStatus 613 commItem.ReviewStatus = chance.ReviewStatus
614 - //commItem.ChanceReviseLogId = chance.SourceId  
615 rsp.List = append(rsp.List, commItem) 614 rsp.List = append(rsp.List, commItem)
616 } 615 }
617 return 616 return