作者 yangfu

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

@@ -286,7 +286,7 @@ func (this *ChanceController) ChanceSubmit() { @@ -286,7 +286,7 @@ func (this *ChanceController) ChanceSubmit() {
286 msg = m 286 msg = m
287 return 287 return
288 } 288 }
289 - if e := request.SelfChecks.Valid(); e != nil { 289 + if e := request.SelfChecks.SetSelfChecksLevel1ByRule(); e != nil {
290 log.Error(e) 290 log.Error(e)
291 msg = protocol.NewReturnResponse(nil, e) 291 msg = protocol.NewReturnResponse(nil, e)
292 return 292 return
@@ -312,7 +312,7 @@ func (this *ChanceController) ChanceUpdate() { @@ -312,7 +312,7 @@ func (this *ChanceController) ChanceUpdate() {
312 msg = m 312 msg = m
313 return 313 return
314 } 314 }
315 - if e := request.SelfChecks.Valid(); e != nil { 315 + if e := request.SelfChecks.SetSelfChecksLevel1ByRule(); e != nil {
316 log.Error(e) 316 log.Error(e)
317 msg = protocol.NewReturnResponse(nil, e) 317 msg = protocol.NewReturnResponse(nil, e)
318 return 318 return
@@ -449,7 +449,7 @@ func (this *ChanceController) ChanceApprove() { @@ -449,7 +449,7 @@ func (this *ChanceController) ChanceApprove() {
449 return 449 return
450 } 450 }
451 } 451 }
452 - if e := request.SelfChecks.Valid(); e != nil { 452 + if e := request.SelfChecks.SetSelfChecksLevel1ByRule(); e != nil {
453 log.Error(e) 453 log.Error(e)
454 msg = protocol.NewReturnResponse(nil, e) 454 msg = protocol.NewReturnResponse(nil, e)
455 return 455 return
@@ -668,3 +668,112 @@ func (this *ChanceController) CheckQuestions() { @@ -668,3 +668,112 @@ func (this *ChanceController) CheckQuestions() {
668 header := controllers.GetRequestHeader(this.Ctx) 668 header := controllers.GetRequestHeader(this.Ctx)
669 msg = protocol.NewReturnResponse(chance.CheckQuestions(header, request)) 669 msg = protocol.NewReturnResponse(chance.CheckQuestions(header, request))
670 } 670 }
  671 +
  672 +//SiftingPool 筛选池
  673 +//@router /siftingPool [post]
  674 +func (this *ChanceController) SiftingPool() {
  675 + var msg *protocol.ResponseMessage
  676 + defer func() {
  677 + this.Resp(msg)
  678 + }()
  679 + var request *protocol.SiftingPoolRequest
  680 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  681 + log.Error(err)
  682 + msg = protocol.BadRequestParam(1)
  683 + return
  684 + }
  685 + if b, m := this.Valid(request); !b {
  686 + msg = m
  687 + return
  688 + }
  689 + if !(request.SubmitStatus == protocol.Submiting || request.SubmitStatus == protocol.Submited) {
  690 + msg = protocol.BadRequestParamWithMessage(2, "obj.SubmitStatus must in (0,1)")
  691 + return
  692 + }
  693 + header := controllers.GetRequestHeader(this.Ctx)
  694 + msg = protocol.NewReturnResponse(chance.SiftingPool(header, request))
  695 +}
  696 +
  697 +//SiftingResults 筛选结果
  698 +//@router /siftingResults [post]
  699 +func (this *ChanceController) SiftingResults() {
  700 + var msg *protocol.ResponseMessage
  701 + defer func() {
  702 + this.Resp(msg)
  703 + }()
  704 + var request *protocol.SiftingResultsRequest
  705 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  706 + log.Error(err)
  707 + msg = protocol.BadRequestParam(1)
  708 + return
  709 + }
  710 + if b, m := this.Valid(request); !b {
  711 + msg = m
  712 + return
  713 + }
  714 + header := controllers.GetRequestHeader(this.Ctx)
  715 + msg = protocol.NewReturnResponse(chance.SiftingResults(header, request))
  716 +}
  717 +
  718 +//SubmitChecks 提交自查
  719 +//@router /submitSiftingResult [post]
  720 +func (this *ChanceController) SubmitChecks() {
  721 + var msg *protocol.ResponseMessage
  722 + defer func() {
  723 + this.Resp(msg)
  724 + }()
  725 + var request *protocol.SubmitChecksRequest
  726 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  727 + log.Error(err)
  728 + msg = protocol.BadRequestParam(1)
  729 + return
  730 + }
  731 + if b, m := this.Valid(request); !b {
  732 + msg = m
  733 + return
  734 + }
  735 + header := controllers.GetRequestHeader(this.Ctx)
  736 + msg = protocol.NewReturnResponse(chance.SubmitChecks(header, request))
  737 +}
  738 +
  739 +//SiftingResultsItemHistory 筛选历史
  740 +//@router /siftingResults/itemHistory [post]
  741 +func (this *ChanceController) SiftingResultsItemHistory() {
  742 + var msg *protocol.ResponseMessage
  743 + defer func() {
  744 + this.Resp(msg)
  745 + }()
  746 + var request *protocol.SiftingResultsItemHistoryRequest
  747 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  748 + log.Error(err)
  749 + msg = protocol.BadRequestParam(1)
  750 + return
  751 + }
  752 + if b, m := this.Valid(request); !b {
  753 + msg = m
  754 + return
  755 + }
  756 + header := controllers.GetRequestHeader(this.Ctx)
  757 + msg = protocol.NewReturnResponse(chance.SiftingResultsItemHistory(header, request))
  758 +}
  759 +
  760 +//SiftingResultsItemDetail 筛选历史详情
  761 +//@router /siftingResults/itemDetail [post]
  762 +func (this *ChanceController) SiftingResultsItemDetail() {
  763 + var msg *protocol.ResponseMessage
  764 + defer func() {
  765 + this.Resp(msg)
  766 + }()
  767 + var request *protocol.SiftingResultsItemDetailRequest
  768 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  769 + log.Error(err)
  770 + msg = protocol.BadRequestParam(1)
  771 + return
  772 + }
  773 + if b, m := this.Valid(request); !b {
  774 + msg = m
  775 + return
  776 + }
  777 + header := controllers.GetRequestHeader(this.Ctx)
  778 + msg = protocol.NewReturnResponse(chance.SiftingResultsItemDetail(header, request))
  779 +}
@@ -30,10 +30,34 @@ func (this *VodController) CreateUploadVideo() { @@ -30,10 +30,34 @@ func (this *VodController) CreateUploadVideo() {
30 msg = m 30 msg = m
31 return 31 return
32 } 32 }
  33 + if len(request.FileName) == 0 {
  34 + request.FileName = aliyun.DefaultVideoFileName
  35 + }
33 header := controllers.GetRequestHeader(this.Ctx) 36 header := controllers.GetRequestHeader(this.Ctx)
34 msg = protocol.NewReturnResponse(upload.CreateUploadVideo(header, request)) 37 msg = protocol.NewReturnResponse(upload.CreateUploadVideo(header, request))
35 } 38 }
36 39
  40 +//刷新视频上传凭证 RefreshUploadVideo
  41 +// @router /refreshUploadVideo [post]
  42 +func (this *VodController) RefreshUploadVideo() {
  43 + var msg *protocol.ResponseMessage
  44 + defer func() {
  45 + this.Resp(msg)
  46 + }()
  47 + var request *aliyun.RefreshUploadVideoRequest
  48 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  49 + log.Error(err)
  50 + msg = protocol.BadRequestParam(1)
  51 + return
  52 + }
  53 + if b, m := this.Valid(request); !b {
  54 + msg = m
  55 + return
  56 + }
  57 + header := controllers.GetRequestHeader(this.Ctx)
  58 + msg = protocol.NewReturnResponse(upload.RefreshUploadVideo(header, request))
  59 +}
  60 +
37 //创建图片上传凭证 CreateUploadImage 61 //创建图片上传凭证 CreateUploadImage
38 // @router /createUploadImage [post] 62 // @router /createUploadImage [post]
39 func (this *VodController) CreateUploadImage() { 63 func (this *VodController) CreateUploadImage() {
@@ -55,6 +79,45 @@ func (this *VodController) CreateUploadImage() { @@ -55,6 +79,45 @@ func (this *VodController) CreateUploadImage() {
55 msg = protocol.NewReturnResponse(upload.CreateUploadImage(header, request)) 79 msg = protocol.NewReturnResponse(upload.CreateUploadImage(header, request))
56 } 80 }
57 81
  82 +//创建图片上传凭证 CreateUploadImages
  83 +// @router /createUploadImages [post]
  84 +func (this *VodController) CreateUploadImages() {
  85 + var msg *protocol.ResponseMessage
  86 + defer func() {
  87 + this.Resp(msg)
  88 + }()
  89 + var (
  90 + request *aliyun.CreateUploadImagesRequest
  91 + response *aliyun.CreateUploadImagesResponse = &aliyun.CreateUploadImagesResponse{
  92 + List: make([]*aliyun.CreateUploadImageResponse, 0),
  93 + }
  94 + )
  95 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  96 + log.Error(err)
  97 + msg = protocol.BadRequestParam(1)
  98 + return
  99 + }
  100 + if b, m := this.Valid(request); !b {
  101 + msg = m
  102 + return
  103 + }
  104 + var err error
  105 + if len(request.Items) == 0 {
  106 + msg = protocol.BadRequestParam(2)
  107 + }
  108 + header := controllers.GetRequestHeader(this.Ctx)
  109 + for i := range request.Items {
  110 + r := request.Items[i]
  111 + if rsp, e := upload.CreateUploadImage(header, r); e != nil {
  112 + err = e
  113 + break
  114 + } else {
  115 + response.List = append(response.List, rsp)
  116 + }
  117 + }
  118 + msg = protocol.NewReturnResponse(response, err)
  119 +}
  120 +
58 //获取视频播放地址 GetPlayInfo 121 //获取视频播放地址 GetPlayInfo
59 // @router /getPlayInfo [post] 122 // @router /getPlayInfo [post]
60 func (this *VodController) GetPlayInfo() { 123 func (this *VodController) GetPlayInfo() {
@@ -13,3 +13,9 @@ const ( @@ -13,3 +13,9 @@ const (
13 FileVoice = "voice" 13 FileVoice = "voice"
14 FileVideo = "video" 14 FileVideo = "video"
15 ) 15 )
  16 +
  17 +const (
  18 + DefaultVideoFileName = "test.mp4"
  19 + DefaultVoiceFileName = "test.mp3"
  20 + DefaultImageFileName = "test.jpg"
  21 +)
  1 +package aliyun
  2 +
  3 +import (
  4 + "github.com/astaxie/beego"
  5 +)
  6 +
  7 +/*
  8 +AK AccessKey 完全访问权限
  9 +STS (Security Token Service) 临时访问控制
  10 +*/
  11 +
  12 +var (
  13 + Endpoint string = beego.AppConfig.String("end_point")
  14 + BucketName string = beego.AppConfig.String("bucket_name")
  15 + //BucketNameCdn string = beego.AppConfig.String("bucket_name_cdn")
  16 + //EndpointCdn string = beego.AppConfig.String("end_point_cdn")
  17 +)
  18 +
  19 +//type OssSts struct{
  20 +//
  21 +//}
  22 +
  23 +//func NewSTS(){
  24 +// client,_ :=oos.NewClientWithAccessKey(RegionID,AccessKeyID,AccessKeySecret)
  25 +// client.DoAction()
  26 +//}
@@ -3,6 +3,7 @@ package aliyun @@ -3,6 +3,7 @@ package aliyun
3 //创建视频上传凭证 3 //创建视频上传凭证
4 /*CreateUploadVideo */ 4 /*CreateUploadVideo */
5 type CreateUploadVideoRequest struct { 5 type CreateUploadVideoRequest struct {
  6 + FileName string `json:"fileName"`
6 } 7 }
7 8
8 type CreateUploadVideoResponse struct { 9 type CreateUploadVideoResponse struct {
@@ -10,6 +11,20 @@ type CreateUploadVideoResponse struct { @@ -10,6 +11,20 @@ type CreateUploadVideoResponse struct {
10 VideoId string `json:"videoId"` 11 VideoId string `json:"videoId"`
11 UploadAddress string `json:"uploadAddress"` 12 UploadAddress string `json:"uploadAddress"`
12 UploadAuth string `json:"uploadAuth"` 13 UploadAuth string `json:"uploadAuth"`
  14 + FileURL string `json:"fileURL"`
  15 +}
  16 +
  17 +//刷新视频上传凭证 RefreshUploadVideo
  18 +type RefreshUploadVideoRequest struct {
  19 + VideoId string `json:"videoId" valid:"Required;"`
  20 +}
  21 +
  22 +type RefreshUploadVideoResponse struct {
  23 + RequestId string `json:"requestId"`
  24 + VideoId string `json:"videoId"`
  25 + UploadAddress string `json:"uploadAddress"`
  26 + UploadAuth string `json:"uploadAuth"`
  27 + FileURL string `json:"fileURL"`
13 } 28 }
14 29
15 /*GetPlayInfo 获取播放信息*/ 30 /*GetPlayInfo 获取播放信息*/
@@ -74,3 +89,19 @@ type PlayInfo struct { @@ -74,3 +89,19 @@ type PlayInfo struct {
74 PlayURL string `json:"PlayURL" xml:"PlayURL"` 89 PlayURL string `json:"PlayURL" xml:"PlayURL"`
75 Specification string `json:"Specification" xml:"Specification"` 90 Specification string `json:"Specification" xml:"Specification"`
76 } 91 }
  92 +
  93 +//GetVideoPlayAuthResponse is the response struct for api GetVideoPlayAuth
  94 +type GetVideoPlayAuthResponse struct {
  95 + RequestId string `json:"requestId" xml:"RequestId"`
  96 + PlayAuth string `json:"playAuth" xml:"PlayAuth"`
  97 + VideoMeta VideoMeta `json:"videoMeta" xml:"VideoMeta"`
  98 +}
  99 +
  100 +// VideoMeta is a nested struct in vod response
  101 +type VideoMeta struct {
  102 + CoverURL string `json:"coverURL" xml:"CoverURL"`
  103 + Duration float64 `json:"duration" xml:"Duration"`
  104 + Status string `json:"-" xml:"Status"`
  105 + Title string `json:"title" xml:"Title"`
  106 + VideoId string `json:"videoId" xml:"VideoId"`
  107 +}
1 package aliyun 1 package aliyun
2 2
3 type CreateUploadImageRequest struct { 3 type CreateUploadImageRequest struct {
  4 + FileName string `json:"fileName"`
4 } 5 }
5 6
6 type CreateUploadImageResponse struct { 7 type CreateUploadImageResponse struct {
7 - RequestId string `json:"requestId" xml:"RequestId"`  
8 - ImageId string `json:"imageId" xml:"ImageId"`  
9 - ImageURL string `json:"imageURL" xml:"ImageURL"`  
10 - UploadAddress string `json:"uploadAddress" xml:"UploadAddress"`  
11 - UploadAuth string `json:"uploadAuth" xml:"UploadAuth"`  
12 - FileURL string `json:"fileURL" xml:"FileURL"` 8 + RequestId string `json:"requestId"`
  9 + ImageId string `json:"imageId" `
  10 + ImageURL string `json:"imageURL"`
  11 + UploadAddress string `json:"uploadAddress"`
  12 + UploadAuth string `json:"uploadAuth"`
  13 + FileURL string `json:"fileURL"`
  14 +}
  15 +
  16 +type CreateUploadImagesRequest struct {
  17 + Items []*CreateUploadImageRequest `json:"items"`
  18 +}
  19 +
  20 +type CreateUploadImagesResponse struct {
  21 + List []*CreateUploadImageResponse `json:"list"`
13 } 22 }
  1 +package aliyun
  2 +
  3 +import (
  4 + "encoding/base64"
  5 + "encoding/json"
  6 + "fmt"
  7 + "strings"
  8 +)
  9 +
  10 +type UploadAddress struct {
  11 + Endpoint string
  12 + Bucket string
  13 + FileName string
  14 +}
  15 +
  16 +//@cname 绑定域名
  17 +func (up UploadAddress) GetFileUrl(cname string) string {
  18 + if len(cname) > 0 {
  19 + return fmt.Sprintf("%v%v", cname, up.FileName)
  20 + }
  21 + if strings.Contains(up.Endpoint, "https") {
  22 + return fmt.Sprintf("%v%v.%v/%v", up.Endpoint[:8], up.Bucket, up.Endpoint[8:], up.FileName)
  23 + } else if strings.Contains(up.Endpoint, "http") {
  24 + return fmt.Sprintf("%v%v.%v/%v", up.Endpoint[:7], up.Bucket, up.Endpoint[7:], up.FileName)
  25 + }
  26 + return ""
  27 +}
  28 +
  29 +//解析UploadAddress
  30 +func ParseUploadAddress(uploadAddress string) (up UploadAddress, err error) {
  31 + var jsData []byte
  32 + jsData, err = base64.StdEncoding.DecodeString(uploadAddress)
  33 + if err != nil {
  34 + return
  35 + }
  36 + if err = json.Unmarshal(jsData, &up); err != nil {
  37 + return
  38 + }
  39 + return
  40 +}
@@ -6,10 +6,12 @@ import ( @@ -6,10 +6,12 @@ import (
6 "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials" 6 "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
7 "github.com/aliyun/alibaba-cloud-sdk-go/services/vod" 7 "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
8 "github.com/astaxie/beego" 8 "github.com/astaxie/beego"
  9 + "github.com/prometheus/common/log"
9 "gitlab.fjmaimaimai.com/mmm-go/gocomm/common" 10 "gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
10 comm_time "gitlab.fjmaimaimai.com/mmm-go/gocomm/time" 11 comm_time "gitlab.fjmaimaimai.com/mmm-go/gocomm/time"
11 "opp/internal/utils" 12 "opp/internal/utils"
12 "path" 13 "path"
  14 + "path/filepath"
13 "time" 15 "time"
14 ) 16 )
15 17
@@ -39,10 +41,12 @@ func InitVodClient(accessKeyId string, accessKeySecret string) (client *vod.Clie @@ -39,10 +41,12 @@ func InitVodClient(accessKeyId string, accessKeySecret string) (client *vod.Clie
39 //获取视频上传地址和凭证,并创建视频信息 41 //获取视频上传地址和凭证,并创建视频信息
40 func CreateUploadVideo(client *vod.Client, r *CreateUploadVideoRequest) (response *CreateUploadVideoResponse, err error) { 42 func CreateUploadVideo(client *vod.Client, r *CreateUploadVideoRequest) (response *CreateUploadVideoResponse, err error) {
41 request := vod.CreateCreateUploadVideoRequest() 43 request := vod.CreateCreateUploadVideoRequest()
42 - request.Title = getFileName(FileVideo, "video_file.mp4")  
43 - request.FileName = getFileName(FileVideo, "video_file.mp4")  
44 - //request.CoverURL = "http://img.alicdn.com/tps/TB1qnJ1PVXXXXXCXXXXXXXXXXXX-700-700.png"  
45 - //request.Tags = "tag1,tag2" 44 + filePath := getFileName(FileVideo, r.FileName)
  45 + if filepath.Ext(r.FileName) == "mp3" {
  46 + filePath = getFileName(FileVoice, r.FileName)
  47 + }
  48 + request.Title = filePath
  49 + request.FileName = filePath
46 request.AcceptFormat = "JSON" 50 request.AcceptFormat = "JSON"
47 rsp, err := client.CreateUploadVideo(request) 51 rsp, err := client.CreateUploadVideo(request)
48 if err != nil { 52 if err != nil {
@@ -54,15 +58,44 @@ func CreateUploadVideo(client *vod.Client, r *CreateUploadVideoRequest) (respons @@ -54,15 +58,44 @@ func CreateUploadVideo(client *vod.Client, r *CreateUploadVideoRequest) (respons
54 UploadAddress: rsp.UploadAddress, 58 UploadAddress: rsp.UploadAddress,
55 UploadAuth: rsp.UploadAuth, 59 UploadAuth: rsp.UploadAuth,
56 } 60 }
  61 + if up, e := ParseUploadAddress(rsp.UploadAddress); e != nil {
  62 + log.Error(e)
  63 + } else {
  64 + response.FileURL = up.GetFileUrl("")
  65 + }
  66 + return
  67 +}
  68 +
  69 +func RefreshUploadVideo(client *vod.Client, r *RefreshUploadVideoRequest) (response *RefreshUploadVideoResponse, err error) {
  70 + request := vod.CreateRefreshUploadVideoRequest()
  71 + request.VideoId = r.VideoId
  72 + request.AcceptFormat = "JSON"
  73 +
  74 + var rsp *vod.RefreshUploadVideoResponse
  75 + rsp, err = client.RefreshUploadVideo(request)
  76 + if err != nil {
  77 + return
  78 + }
  79 + if err = utils.JsonDeepCopy(&response, &rsp); err != nil {
  80 + return
  81 + }
  82 + if up, e := ParseUploadAddress(rsp.UploadAddress); e != nil {
  83 + log.Error(e)
  84 + } else {
  85 + response.FileURL = up.GetFileUrl("")
  86 + }
57 return 87 return
58 } 88 }
59 89
60 //获取图片上传地址和凭证,并创建视频信息 90 //获取图片上传地址和凭证,并创建视频信息
61 func CreateUploadImage(client *vod.Client, r *CreateUploadImageRequest) (response *CreateUploadImageResponse, err error) { 91 func CreateUploadImage(client *vod.Client, r *CreateUploadImageRequest) (response *CreateUploadImageResponse, err error) {
62 request := vod.CreateCreateUploadImageRequest() 92 request := vod.CreateCreateUploadImageRequest()
63 - request.ImageType = "cover" 93 + filePath := getFileName(FileImage, r.FileName)
  94 + request.ImageType = "default"
  95 + request.Title = filePath
  96 + request.ImageExt = filepath.Ext(r.FileName)[1:]
64 request.AcceptFormat = "JSON" 97 request.AcceptFormat = "JSON"
65 - request.ImageExt = "jpg" 98 + //request.StorageLocation = filepath.Base(request.Title)
66 rsp, err := client.CreateUploadImage(request) 99 rsp, err := client.CreateUploadImage(request)
67 if err != nil { 100 if err != nil {
68 return 101 return
@@ -80,11 +113,17 @@ func GetPlayInfo(client *vod.Client, r *GetPlayInfoRequest) (response *vod.GetPl @@ -80,11 +113,17 @@ func GetPlayInfo(client *vod.Client, r *GetPlayInfoRequest) (response *vod.GetPl
80 } 113 }
81 114
82 //获取播放信息 115 //获取播放信息
83 -func GetGetVideoPlayAuth(client *vod.Client, r *GetVideoPlayAuthRequest) (response interface{}, err error) { 116 +func GetGetVideoPlayAuth(client *vod.Client, r *GetVideoPlayAuthRequest) (response GetVideoPlayAuthResponse, err error) {
84 request := vod.CreateGetVideoPlayAuthRequest() 117 request := vod.CreateGetVideoPlayAuthRequest()
85 request.VideoId = r.VideoId 118 request.VideoId = r.VideoId
86 request.AcceptFormat = "JSON" 119 request.AcceptFormat = "JSON"
87 - return client.GetVideoPlayAuth(request) 120 + var rsp *vod.GetVideoPlayAuthResponse
  121 + if rsp, err = client.GetVideoPlayAuth(request); err != nil {
  122 + log.Error(err)
  123 + return
  124 + }
  125 + err = utils.JsonDeepCopy(&response, rsp)
  126 + return
88 } 127 }
89 128
90 //fileType: video voice image 129 //fileType: video voice image
@@ -98,6 +98,8 @@ func main() { @@ -98,6 +98,8 @@ func main() {
98 beego.BConfig.Listen.HTTPSKeyFile = "conf/_.fjmaimaimai.com.key" 98 beego.BConfig.Listen.HTTPSKeyFile = "conf/_.fjmaimaimai.com.key"
99 contrab.Run() 99 contrab.Run()
100 100
  101 + //beego.BConfig.Listen.EnableAdmin = true //开启进程内监控模块
  102 +
101 beego.Run() 103 beego.Run()
102 } 104 }
103 105
@@ -35,13 +35,13 @@ func GetAuditCheckById(id int) (v *AuditCheck, err error) { @@ -35,13 +35,13 @@ func GetAuditCheckById(id int) (v *AuditCheck, err error) {
35 return nil, err 35 return nil, err
36 } 36 }
37 37
38 -func GetAuditCheckBy(tpId int64) (v []*AuditCheck, err error) { 38 +func GetAuditCheckBy(tpId int64, v interface{}) (err error) {
39 sql := `select * from( 39 sql := `select * from(
40 -select id,(case when pid=0 then id else pid end) pid,title,items from audit_check where template_id=? and enable=1 40 +select id,(case when pid=0 then id else pid end) pid,title,items,pid parent_id from audit_check where template_id=? and enable=1
41 )a 41 )a
42 order by a.pid` 42 order by a.pid`
43 o := orm.NewOrm() 43 o := orm.NewOrm()
44 - if _, err = o.Raw(sql, tpId).QueryRows(&v); err != nil { 44 + if _, err = o.Raw(sql, tpId).QueryRows(v); err != nil {
45 if err == orm.ErrNoRows { 45 if err == orm.ErrNoRows {
46 err = nil 46 err = nil
47 } 47 }
@@ -33,6 +33,8 @@ type AuditFlowProcess struct { @@ -33,6 +33,8 @@ type AuditFlowProcess struct {
33 ApproveMessage string `orm:"column(approve_message);size(50)" description:"审核消息-冗余"` 33 ApproveMessage string `orm:"column(approve_message);size(50)" description:"审核消息-冗余"`
34 TemplateId int `orm:"column(template_id);size(50)" description:"模板编号-冗余"` 34 TemplateId int `orm:"column(template_id);size(50)" description:"模板编号-冗余"`
35 SelfChecks string `orm:"column(self_checks);null" description:"自查内容"` 35 SelfChecks string `orm:"column(self_checks);null" description:"自查内容"`
  36 + SubmitCheckTime time.Time `orm:"column(submit_check_time);type(timestamp)" description:"提交筛选时间"`
  37 + SubmitCheckStatus int `orm:"column(submit_check_status)" description:"提交筛选状态 0:未提交 1:已提交"`
36 } 38 }
37 39
38 func (t *AuditFlowProcess) TableName() string { 40 func (t *AuditFlowProcess) TableName() string {
@@ -180,3 +182,23 @@ func UpdatetAuditFlowProcessToSubmit(o orm.Ormer, chanceId int64, level int, rev @@ -180,3 +182,23 @@ func UpdatetAuditFlowProcessToSubmit(o orm.Ormer, chanceId int64, level int, rev
180 } 182 }
181 return 183 return
182 } 184 }
  185 +
  186 +//获取审核人最新的审核节点
  187 +func GetAuditorLatestAuditFlowProcess(chanceId int64, userId int64) (v *AuditFlowProcess, err error) {
  188 + o := orm.NewOrm()
  189 + sql := "select * from audit_flow_process where chance_id=? and level>0 and uid=? order by id desc limit 1"
  190 + if err = utils.ExecuteQueryOneWithOrmer(o, &v, sql, chanceId, userId); err != nil {
  191 + return
  192 + }
  193 + return
  194 +}
  195 +
  196 +//获取机会所有审核人
  197 +func GetChanceAllAuditors(chanceId int64) (v []*AuditFlowProcess, err error) {
  198 + o := orm.NewOrm()
  199 + sql := "select MAX(id) AS id,uid from audit_flow_process where chance_id=? and `level`>0 group by chance_id,uid"
  200 + if err = utils.ExecuteQueryAllWithOrmer(o, &v, sql, chanceId); err != nil {
  201 + return
  202 + }
  203 + return
  204 +}
@@ -36,6 +36,9 @@ type Chance struct { @@ -36,6 +36,9 @@ type Chance struct {
36 Code string `orm:"column(code)" description:"机会编码 一级编码+二级编码"` 36 Code string `orm:"column(code)" description:"机会编码 一级编码+二级编码"`
37 Status int8 `orm:"column(status)" description:"状态 1:开启 2:关闭 "` 37 Status int8 `orm:"column(status)" description:"状态 1:开启 2:关闭 "`
38 SelfChecks string `orm:"column(self_checks);size(1000);null" description:"自查内容"` 38 SelfChecks string `orm:"column(self_checks);size(1000);null" description:"自查内容"`
  39 + CheckTime time.Time `orm:"column(check_time);type(timestamp)" description:"时间"`
  40 + CheckResultStatus int `orm:"column(check_result_status)" description:"机会筛选状态【1:待处理】【2:通过】【3:不通过】"`
  41 + CheckResult string `orm:"column(check_result);null" description:"筛选结果"`
39 } 42 }
40 43
41 const ( 44 const (
@@ -116,9 +119,9 @@ func DeleteChance(id int64) (err error) { @@ -116,9 +119,9 @@ func DeleteChance(id int64) (err error) {
116 func GetChanceMyChance(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) { 119 func GetChanceMyChance(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) {
117 sql := `select a.*,b.images,speechs,videos 120 sql := `select a.*,b.images,speechs,videos
118 from ( 121 from (
119 -select id,user_id,create_at,update_at,update_at chance_approve_time,source_content,approve_data,review_status,enable_status,status from chance 122 +select id chance_id,user_id chance_user_id,create_at,update_at,update_at chance_approve_time,source_content,approve_data chance_approve_data,review_status,enable_status,status from chance
120 where user_id=? and company_id=? and review_status in (?) and (?=0 or unix_timestamp(update_at)<?) and status=1 and enable_status=1 123 where user_id=? and company_id=? and review_status in (?) and (?=0 or unix_timestamp(update_at)<?) and status=1 and enable_status=1
121 -) a left JOIN chance_data b on a.id =b.chance_id 124 +) a left JOIN chance_data b on a.chance_id =b.chance_id
122 order by update_at desc 125 order by update_at desc
123 limit ? 126 limit ?
124 ` //approve_time 127 ` //approve_time
@@ -140,14 +143,14 @@ where user_id=? and company_id=? and review_status in (%v) and status=1 and enab @@ -140,14 +143,14 @@ where user_id=? and company_id=? and review_status in (%v) and status=1 and enab
140 143
141 func GetChanceMyApproveChance(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) { 144 func GetChanceMyApproveChance(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) {
142 sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from ( 145 sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from (
143 -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,b.status from ( 146 +select a.*,b.user_id chance_user_id,b.source_content,b.enable_status,b.review_status,b.create_at,b.update_at,b.approve_time chance_approve_time,b.status from (
144 select id,approve_time,approve_data,uid,chance_id,approve_message,update_at process_create_time 147 select id,approve_time,approve_data,uid,chance_id,approve_message,update_at process_create_time
145 from audit_flow_process where uid=? and review_status in (%v) 148 from audit_flow_process where uid=? and review_status in (%v)
146 )a left outer join chance b on a.chance_id = b.id 149 )a left outer join chance b on a.chance_id = b.id
147 )a left outer join chance_data b on a.chance_id =b.chance_id 150 )a left outer join chance_data b on a.chance_id =b.chance_id
148 where (?=0 or unix_timestamp(a.update_at)<?) 151 where (?=0 or unix_timestamp(a.update_at)<?)
149 order by a.update_at desc 152 order by a.update_at desc
150 -LIMIT ?`, utils.JoinInt8s(reviewStatus, ",")) //and enable_status =1 //就算已经删除了,列表上面还是要体现已经删除 153 +LIMIT ?`, utils.JoinInt8s(reviewStatus, ",")) //备注:and enable_status =1 //就算已经删除了,列表上面还是要体现已经删除
151 154
152 sqlCount := fmt.Sprintf(`select count(0) 155 sqlCount := fmt.Sprintf(`select count(0)
153 from audit_flow_process where uid=? and review_status in (%v) `, utils.JoinInt8s(reviewStatus, ",")) //and enable_status =1 156 from audit_flow_process where uid=? and review_status in (%v) `, utils.JoinInt8s(reviewStatus, ",")) //and enable_status =1
@@ -162,9 +165,10 @@ from audit_flow_process where uid=? and review_status in (%v) `, utils.JoinInt8 @@ -162,9 +165,10 @@ from audit_flow_process where uid=? and review_status in (%v) `, utils.JoinInt8
162 return 165 return
163 } 166 }
164 167
  168 +//获取有效的机会
165 func GetChanceMyApproveChanceEnable(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) { 169 func GetChanceMyApproveChanceEnable(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) {
166 sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from ( 170 sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from (
167 -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,b.status,b.update_at process_create_time,b.self_checks from ( 171 +select a.*,b.user_id chance_user_id,b.source_content,b.enable_status,b.review_status,b.create_at,b.update_at,b.approve_time chance_approve_time,b.status,b.update_at process_create_time,b.self_checks from (
168 select id,approve_time,approve_data,uid,chance_id,approve_message 172 select id,approve_time,approve_data,uid,chance_id,approve_message
169 from audit_flow_process where uid=? and review_status in (%v) and enable_status =1 173 from audit_flow_process where uid=? and review_status in (%v) and enable_status =1
170 )a left outer join chance b on a.chance_id = b.id 174 )a left outer join chance b on a.chance_id = b.id
@@ -246,7 +250,7 @@ func GetChanceComment(uid int64, lastId int64, pageSize int, v interface{}) (tot @@ -246,7 +250,7 @@ func GetChanceComment(uid int64, lastId int64, pageSize int, v interface{}) (tot
246 sql := fmt.Sprintf(`select a.*,b.content commented_content,b.create_at commented_time,b.user_id commented_user_id 250 sql := fmt.Sprintf(`select a.*,b.content commented_content,b.create_at commented_time,b.user_id commented_user_id
247 from ( 251 from (
248 select a.*,b.images,b.speechs,b.videos from ( 252 select a.*,b.images,b.speechs,b.videos from (
249 -select a.*,b.source_content,b.enable_status,b.user_id chance_user_id,b.create_at,b.review_status,b.approve_data,b.publish_status,b.status from ( 253 +select a.*,b.id chance_id,b.source_content,b.enable_status,b.user_id chance_user_id,b.create_at,b.review_status,b.approve_data,b.publish_status,b.status from (
250 select id,content,view_total,zan_total,comment_total,source_type,source_id,create_at comment_time from comment 254 select id,content,view_total,zan_total,comment_total,source_type,source_id,create_at comment_time from comment
251 where user_id =? and (?=0 or id<?) 255 where user_id =? and (?=0 or id<?)
252 )a left outer join chance b on a.source_id = b.id and source_type=1 256 )a left outer join chance b on a.source_id = b.id and source_type=1
@@ -677,3 +681,97 @@ and department_id in (%v)`, @@ -677,3 +681,97 @@ and department_id in (%v)`,
677 } 681 }
678 return 682 return
679 } 683 }
  684 +
  685 +//获取筛选中的机会
  686 +//@submitStatus 提交状态:已提交 未提交
  687 +//@checkResultStatus 筛选结果状态:通过 / 不通过
  688 +func GetSiftingChance(uid int64, submitStatus int, checkResultStatus int, offset int, pageSize int, v interface{}) (total int, err error) {
  689 + var where string
  690 + if submitStatus == 1 {
  691 + where = fmt.Sprintf(`order by a.submit_check_time desc`)
  692 + } else {
  693 + where = fmt.Sprintf(`order by a.chance_approve_time desc`)
  694 + }
  695 + sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos
  696 +from (
  697 + select a.*,b.user_id chance_user_id,b.source_content,b.enable_status,b.review_status,b.audit_template_id,b.chance_type_id,b.create_at,
  698 + b.view_total,
  699 + b.update_at,b.approve_time chance_approve_time,b.status,b.self_checks,b.check_result_status,b.check_time
  700 + from (
  701 + select max(id) id,approve_time,approve_data,uid,chance_id,submit_check_status,submit_check_time,level
  702 + from audit_flow_process a,(select MAX(id) AS max_id from audit_flow_process as t where t.uid=%v group by chance_id) b
  703 + where a.uid=%v and b.max_id=a.id and a.submit_check_status=%v and level>0
  704 + GROUP BY chance_id
  705 + )a left outer join chance b on a.chance_id = b.id
  706 + where b.review_status=3 and b.enable_status=1 and b.status=1 and b.check_result_status <=%v and length(b.self_checks)>5
  707 +)a left outer join chance_data b on a.chance_id =b.chance_id
  708 +%v
  709 +limit %v,%v`, uid, uid, submitStatus, checkResultStatus, where, offset, pageSize) //,update_at process_create_time
  710 +
  711 + sqlCount := fmt.Sprintf(`select count(0)
  712 +from (
  713 + select a.*,b.user_id chance_user_id,b.source_content,b.enable_status,b.review_status,b.create_at,
  714 + b.update_at,b.approve_time chance_approve_time,b.status,b.self_checks,b.check_result_status
  715 + from (
  716 + select max(id) id,approve_time,approve_data,uid,chance_id,submit_check_status,submit_check_time,level
  717 + from audit_flow_process a,(select MAX(id) AS max_id from audit_flow_process as t where t.uid=%v group by chance_id) b
  718 + where a.uid=%v and b.max_id=a.id and a.submit_check_status=%v and level>0
  719 + GROUP BY chance_id
  720 + )a left outer join chance b on a.chance_id = b.id
  721 + where b.review_status=3 and b.enable_status=1 and b.status=1 and b.check_result_status <=%v and length(b.self_checks)>5
  722 +)a
  723 +`, uid, uid, submitStatus, checkResultStatus) //and enable_status =1
  724 + if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil {
  725 + return
  726 + }
  727 + if v != nil {
  728 + if err = utils.ExecuteQueryAll(v, sql); err != nil {
  729 + return
  730 + }
  731 + }
  732 + return
  733 +}
  734 +
  735 +//获取筛选结果的机会
  736 +//@submitStatus 提交状态:已提交 未提交
  737 +//@checkResultStatus 筛选结果状态:通过 / 不通过
  738 +func GetSiftingResults(uid int64, submitStatus, checkResultStatus int, offset int, pageSize int, v interface{}) (total int, err error) {
  739 + sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos
  740 +from (
  741 + select a.*,b.user_id chance_user_id,b.source_content,b.enable_status,b.review_status,b.audit_template_id,b.chance_type_id,b.create_at,
  742 + b.view_total,
  743 + b.update_at,b.approve_time chance_approve_time,b.status,b.self_checks,b.check_result_status,b.check_time
  744 + from (
  745 + select max(id) id,approve_time,approve_data,uid,chance_id,submit_check_status,submit_check_time,level
  746 + from audit_flow_process a,(select MAX(id) AS max_id from audit_flow_process as t where t.uid=%v group by chance_id) b
  747 + where a.uid=%v and b.max_id=a.id and a.submit_check_status=%v and level>0
  748 + GROUP BY chance_id
  749 + )a left outer join chance b on a.chance_id = b.id
  750 + where b.review_status=3 and b.enable_status=1 and b.status=1 and b.check_result_status =%v
  751 +)a left outer join chance_data b on a.chance_id =b.chance_id
  752 +order by a.check_time desc
  753 +limit %v,%v`, uid, uid, submitStatus, checkResultStatus, offset, pageSize) //,update_at process_create_time
  754 +
  755 + sqlCount := fmt.Sprintf(`select count(0)
  756 +from (
  757 + select a.*,b.user_id chance_user_id,b.source_content,b.enable_status,b.review_status,b.create_at,
  758 + b.update_at,b.approve_time chance_approve_time,b.status,b.self_checks,b.check_result_status
  759 + from (
  760 + select max(id) id,approve_time,approve_data,uid,chance_id,submit_check_status,submit_check_time,level
  761 + from audit_flow_process a,(select MAX(id) AS max_id from audit_flow_process as t where t.uid=%v group by chance_id) b
  762 + where a.uid=%v and b.max_id=a.id and a.submit_check_status=%v and level>0
  763 + GROUP BY chance_id
  764 + )a left outer join chance b on a.chance_id = b.id
  765 + where b.review_status=3 and b.enable_status=1 and b.status=1 and b.check_result_status =%v
  766 +)a
  767 +`, uid, uid, submitStatus, checkResultStatus) //and enable_status =1
  768 + if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil {
  769 + return
  770 + }
  771 + if v != nil {
  772 + if err = utils.ExecuteQueryAll(v, sql); err != nil {
  773 + return
  774 + }
  775 + }
  776 + return
  777 +}
  1 +package models
  2 +
  3 +import (
  4 + "fmt"
  5 + "opp/internal/utils"
  6 + "time"
  7 +
  8 + "github.com/astaxie/beego/orm"
  9 +)
  10 +
  11 +type ChanceCheckResult struct {
  12 + Id int64 `orm:"column(id);pk"`
  13 + ChanceId int64 `orm:"column(chance_id)"`
  14 + GroupId int64 `orm:"column(group_id);null"`
  15 + CheckPid int64 `orm:"column(check_pid)"`
  16 + CheckId int `orm:"column(check_id);null"`
  17 + CheckItem string `orm:"column(check_item);size(20);null" description:"检查项"`
  18 + Answer string `orm:"column(answer);size(50);null" description:"回答"`
  19 + Reason string `orm:"column(reason);size(200);null" description:"理由"`
  20 + UserCompanyId int64 `orm:"column(user_company_id);null"`
  21 + CreateAt time.Time `orm:"column(create_at);type(timestamp);null"`
  22 +}
  23 +
  24 +func (t *ChanceCheckResult) TableName() string {
  25 + return "chance_check_result"
  26 +}
  27 +
  28 +func init() {
  29 + orm.RegisterModel(new(ChanceCheckResult))
  30 +}
  31 +
  32 +var (
  33 + SqlGetUserCheckResults = `select * from chance_check_result where chance_id =? and user_company_id=? order by group_id,check_id` //机会自查数据
  34 +)
  35 +
  36 +// AddChanceCheckResult insert a new ChanceCheckResult into database and returns
  37 +// last inserted Id on success.
  38 +func AddChanceCheckResult(m *ChanceCheckResult) (id int64, err error) {
  39 + o := orm.NewOrm()
  40 + id, err = o.Insert(m)
  41 + return
  42 +}
  43 +
  44 +// GetChanceCheckResultById retrieves ChanceCheckResult by Id. Returns error if
  45 +// Id doesn't exist
  46 +func GetChanceCheckResultById(id int64) (v *ChanceCheckResult, err error) {
  47 + o := orm.NewOrm()
  48 + v = &ChanceCheckResult{Id: id}
  49 + if err = o.Read(v); err == nil {
  50 + return v, nil
  51 + }
  52 + return nil, err
  53 +}
  54 +
  55 +// UpdateChanceCheckResult updates ChanceCheckResult by Id and returns error if
  56 +// the record to be updated doesn't exist
  57 +func UpdateChanceCheckResultById(m *ChanceCheckResult) (err error) {
  58 + o := orm.NewOrm()
  59 + v := ChanceCheckResult{Id: m.Id}
  60 + // ascertain id exists in the database
  61 + if err = o.Read(&v); err == nil {
  62 + var num int64
  63 + if num, err = o.Update(m); err == nil {
  64 + fmt.Println("Number of records updated in database:", num)
  65 + }
  66 + }
  67 + return
  68 +}
  69 +
  70 +// DeleteChanceCheckResult deletes ChanceCheckResult by Id and returns error if
  71 +// the record to be deleted doesn't exist
  72 +func DeleteChanceCheckResult(id int64) (err error) {
  73 + o := orm.NewOrm()
  74 + v := ChanceCheckResult{Id: id}
  75 + // ascertain id exists in the database
  76 + if err = o.Read(&v); err == nil {
  77 + var num int64
  78 + if num, err = o.Delete(&ChanceCheckResult{Id: id}); err == nil {
  79 + fmt.Println("Number of records deleted in database:", num)
  80 + }
  81 + }
  82 + return
  83 +}
  84 +
  85 +//获取机会所有审核人
  86 +func GetCheckResultAllSubmitters(chanceId int64) (v []int64, err error) {
  87 + o := orm.NewOrm()
  88 + sql := "select DISTINCT user_company_id from chance_check_result where chance_id=?"
  89 + if err = utils.ExecuteQueryAllWithOrmer(o, &v, sql, chanceId); err != nil {
  90 + return
  91 + }
  92 + return
  93 +}
  94 +
  95 +//获取机会所有筛选结果
  96 +func GetCheckResultsByChanceId(chanceId int64) (v []*ChanceCheckResult, err error) {
  97 + o := orm.NewOrm()
  98 + sql := "select * from chance_check_result where chance_id =? order by check_pid,check_id"
  99 + if err = utils.ExecuteQueryAllWithOrmer(o, &v, sql, chanceId); err != nil {
  100 + return
  101 + }
  102 + return
  103 +}
  104 +
  105 +func GetCheckResultsByCheckId(chanceId int64, checkId int) (v []*ChanceCheckResult, err error) {
  106 + o := orm.NewOrm()
  107 + sql := "select * from chance_check_result where chance_id =? and check_id=? order by id"
  108 + if err = utils.ExecuteQueryAllWithOrmer(o, &v, sql, chanceId, checkId); err != nil {
  109 + return
  110 + }
  111 + return
  112 +}
@@ -198,7 +198,7 @@ func GetUserMsgsBulletin(userId, companyId int64, msgType int, lastId int64, pag @@ -198,7 +198,7 @@ func GetUserMsgsBulletin(userId, companyId int64, msgType int, lastId int64, pag
198 //获取机会消息 198 //获取机会消息
199 func GetChanceMsg(uid, lastId int64, pageSize int, msgType int, v interface{}) (total int, err error) { 199 func GetChanceMsg(uid, lastId int64, pageSize int, msgType int, v interface{}) (total int, err error) {
200 sql := `select a.*,b.images,b.speechs,b.videos from ( 200 sql := `select a.*,b.images,b.speechs,b.videos from (
201 -select a.*,b.source_content,b.enable_status,b.user_id chance_user_id,b.create_at,b.review_status,b.approve_data,b.status from ( 201 +select a.*,b.source_content,b.enable_status,b.user_id chance_user_id,b.create_at,b.review_status,b.approve_data chance_approve_data,b.status from (
202 select id,company_id,receive_user_id,message,source_id,is_read,chance_id,create_at msg_time,data,sender_user_id 202 select id,company_id,receive_user_id,message,source_id,is_read,chance_id,create_at msg_time,data,sender_user_id
203 from user_msg where receive_user_id=? and source_type=1 and (?=0 or id<?) and msg_type=? 203 from user_msg where receive_user_id=? and source_type=1 and (?=0 or id<?) and msg_type=?
204 )a left outer join chance b on a.source_id = b.id 204 )a left outer join chance b on a.source_id = b.id
@@ -191,8 +191,8 @@ type ChancePoolResponse struct { @@ -191,8 +191,8 @@ type ChancePoolResponse struct {
191 191
192 //我的机会列表 192 //我的机会列表
193 type ChanceItemOrm struct { 193 type ChanceItemOrm struct {
194 - Id int64 `orm:"column(id)"`  
195 - Uid int64 `orm:"column(user_id)"` 194 + ChanceId int64 `orm:"column(id)"`
  195 + ChanceUserId int64 `orm:"column(user_id)"`
196 CreateTime time.Time `orm:"column(create_at)"` 196 CreateTime time.Time `orm:"column(create_at)"`
197 UpdateTime time.Time `orm:"column(update_at)"` 197 UpdateTime time.Time `orm:"column(update_at)"`
198 ApproveTime time.Time `orm:"column(chance_approve_time)"` 198 ApproveTime time.Time `orm:"column(chance_approve_time)"`
@@ -219,17 +219,18 @@ type MyApproveChanceResponse struct { @@ -219,17 +219,18 @@ type MyApproveChanceResponse struct {
219 219
220 //我的审核机会列表 220 //我的审核机会列表
221 type ChanceApproveItemOrm struct { 221 type ChanceApproveItemOrm struct {
222 - ChanceUserId int64 `orm:"column(user_id)"`  
223 - CreateTime time.Time `orm:"column(create_at)"`  
224 - UpdateTime time.Time `orm:"column(update_at)"`  
225 - ChanceApproveTime time.Time `orm:"column(chance_approve_time)"`  
226 - SourceContent string `orm:"column(source_content)"`  
227 - ChanceEnableStatus int `orm:"column(enable_status)"`  
228 - Images string `orm:"column(images)"`  
229 - Voices string `orm:"column(speechs)"`  
230 - Videos string `orm:"column(videos)"`  
231 - ReviewStatus int `orm:"column(review_status)"`  
232 - Status int `orm:"column(status)"` 222 + //ChanceUserId int64 `orm:"column(user_id)"`
  223 + //CreateTime time.Time `orm:"column(create_at)"`
  224 + //UpdateTime time.Time `orm:"column(update_at)"`
  225 + //ChanceApproveTime time.Time `orm:"column(chance_approve_time)"`
  226 + //SourceContent string `orm:"column(source_content)"`
  227 + //ChanceEnableStatus int `orm:"column(enable_status)"`
  228 + //Images string `orm:"column(images)"`
  229 + //Voices string `orm:"column(speechs)"`
  230 + //Videos string `orm:"column(videos)"`
  231 + //ReviewStatus int `orm:"column(review_status)"`
  232 + //Status int `orm:"column(status)"`
  233 + CommChanceItemOrm
233 234
234 Id int64 `orm:"column(id)"` //审核id 235 Id int64 `orm:"column(id)"` //审核id
235 ApproveTime time.Time `orm:"column(approve_time)"` 236 ApproveTime time.Time `orm:"column(approve_time)"`
@@ -362,6 +363,8 @@ type CommChanceItemOrm struct { @@ -362,6 +363,8 @@ type CommChanceItemOrm struct {
362 ChanceId int64 `orm:"column(chance_id)"` 363 ChanceId int64 `orm:"column(chance_id)"`
363 ChanceUserId int64 `orm:"column(chance_user_id)"` 364 ChanceUserId int64 `orm:"column(chance_user_id)"`
364 CreateTime time.Time `orm:"column(create_at)"` 365 CreateTime time.Time `orm:"column(create_at)"`
  366 + UpdateTime time.Time `orm:"column(update_at)"`
  367 + ChanceApproveTime time.Time `orm:"column(chance_approve_time)"`
365 SourceContent string `orm:"column(source_content)"` 368 SourceContent string `orm:"column(source_content)"`
366 ChanceEnableStatus int `orm:"column(enable_status)"` 369 ChanceEnableStatus int `orm:"column(enable_status)"`
367 ReviewStatus int `orm:"column(review_status)"` //审核状态 1:待审核 2:被退回 3:已通过 370 ReviewStatus int `orm:"column(review_status)"` //审核状态 1:待审核 2:被退回 3:已通过
@@ -370,9 +373,13 @@ type CommChanceItemOrm struct { @@ -370,9 +373,13 @@ type CommChanceItemOrm struct {
370 Videos string `orm:"column(videos)"` 373 Videos string `orm:"column(videos)"`
371 PublishStatus int `orm:"column(publish_status)"` //公开状态 374 PublishStatus int `orm:"column(publish_status)"` //公开状态
372 Status int `orm:"column(status)"` //开启状态 375 Status int `orm:"column(status)"` //开启状态
  376 + ChanceApproveData string `orm:"column(chance_approve_data)"` //审核数据
373 CommentTotal int `orm:"column(comment_total)"` 377 CommentTotal int `orm:"column(comment_total)"`
374 ZanTotal int `orm:"column(zan_total)"` 378 ZanTotal int `orm:"column(zan_total)"`
375 ViewTotal int `orm:"column(view_total)"` 379 ViewTotal int `orm:"column(view_total)"`
  380 +
  381 + TemplateId int `orm:"column(audit_template_id)"`
  382 + ChanceTypeId int `orm:"column(chance_type_id)"`
376 } 383 }
377 384
378 /*ChanceDetail 机会详情*/ 385 /*ChanceDetail 机会详情*/
@@ -492,6 +499,7 @@ func ClearEmptyForm(inputFormList []*Form) (FormList []*Form) { @@ -492,6 +499,7 @@ func ClearEmptyForm(inputFormList []*Form) (FormList []*Form) {
492 type Speech struct { 499 type Speech struct {
493 Path string `json:"path"` 500 Path string `json:"path"`
494 Duration int `json:"duration"` 501 Duration int `json:"duration"`
  502 + VideoId string `json:"videoId"`
495 } 503 }
496 504
497 //图片 505 //图片
@@ -499,6 +507,7 @@ type Picture struct { @@ -499,6 +507,7 @@ type Picture struct {
499 Path string `json:"path"` 507 Path string `json:"path"`
500 W int `json:"w"` 508 W int `json:"w"`
501 H int `json:"h"` 509 H int `json:"h"`
  510 + ImageId string `json:"imageId"`
502 } 511 }
503 512
504 //视频 513 //视频
@@ -506,6 +515,7 @@ type Video struct { @@ -506,6 +515,7 @@ type Video struct {
506 Path string `json:"path"` 515 Path string `json:"path"`
507 Cover Cover `json:"cover"` //封面 516 Cover Cover `json:"cover"` //封面
508 Duration int `json:"duration"` 517 Duration int `json:"duration"`
  518 + VideoId string `json:"videoId"`
509 } 519 }
510 520
511 //审批配置 521 //审批配置
@@ -653,3 +663,25 @@ type ChanceReviseDetailResponse struct { @@ -653,3 +663,25 @@ type ChanceReviseDetailResponse struct {
653 ChanceReviseData ChanceReviseLog `json:"chanceReviseData"` 663 ChanceReviseData ChanceReviseLog `json:"chanceReviseData"`
654 ChanceId int64 `json:"chanceId"` //机会编号 664 ChanceId int64 `json:"chanceId"` //机会编号
655 } 665 }
  666 +
  667 +//机会池筛选项
  668 +type ChanceSiftItemOrm struct {
  669 + CommChanceItemOrm
  670 +
  671 + //ApproveData string `json:"approveData"` //审核数据
  672 + TemplateId int `orm:"column(audit_template_id)"`
  673 + ChanceTypeId int `orm:"column(chance_type_id)"`
  674 +
  675 + SubmitCheckTime time.Time `orm:"column(submit_check_time)"` //提交自查时间
  676 +}
  677 +
  678 +//机会池筛选项
  679 +type ChanceSiftResultOrm struct {
  680 + CommChanceItemOrm
  681 +
  682 + //ApproveData string `json:"approveData"` //审核数据
  683 + TemplateId int `orm:"column(audit_template_id)"`
  684 + ChanceTypeId int `orm:"column(chance_type_id)"`
  685 +
  686 + CheckTime time.Time `orm:"column(check_time)"` //通过时间时间
  687 +}
@@ -10,22 +10,59 @@ import ( @@ -10,22 +10,59 @@ import (
10 ) 10 )
11 11
12 const ( 12 const (
13 - TypeSubmit = iota + 1  
14 - TypeApprove 13 + TypeSubmit = iota + 1 //提交者类型
  14 + TypeApprove //审核人类型
  15 +)
  16 +
  17 +//提交状态
  18 +const (
  19 + Submiting = iota //待我提交
  20 + Submited //我已提交
  21 +)
  22 +
  23 +//通过状态
  24 +const (
  25 + None = iota //未提交
  26 + Waiting //已提交待处理
  27 + Reject //退回
  28 + Pass //通过
  29 +)
  30 +
  31 +const (
  32 + OptionYes = "是"
  33 + OptionNo = "否"
  34 + OptionUncertain = "不清楚"
15 ) 35 )
16 36
17 /*机会-自查内容*/ 37 /*机会-自查内容*/
18 var CheckOptionsCommit = []CheckOption{{Item: "是", NeedOther: false}, {Item: "否", NeedOther: false}, {Item: "不清楚", NeedOther: false}} 38 var CheckOptionsCommit = []CheckOption{{Item: "是", NeedOther: false}, {Item: "否", NeedOther: false}, {Item: "不清楚", NeedOther: false}}
19 var CheckOptionsApprove = []CheckOption{{Item: "是", NeedOther: false}, {Item: "否", NeedOther: true}, {Item: "不清楚", NeedOther: false}} 39 var CheckOptionsApprove = []CheckOption{{Item: "是", NeedOther: false}, {Item: "否", NeedOther: true}, {Item: "不清楚", NeedOther: false}}
20 40
21 -//自查结果列表 41 +/*自查结果列表*/
22 type SelfCheckResults []selfCheckResult 42 type SelfCheckResults []selfCheckResult
23 type selfCheckResult struct { 43 type selfCheckResult struct {
24 Item string `json:"item"` 44 Item string `json:"item"`
25 Total int `json:"total"` 45 Total int `json:"total"`
26 } 46 }
27 47
28 -//自查项列表 48 +/*自查项*/
  49 +type SelfCheck struct {
  50 + CheckItem string `json:"checkItem"`
  51 + GroupId int64 `json:"groupId"` //分组
  52 + Answer string `json:"answer,omitempty"`
  53 + Reason string `json:"reason,omitempty"`
  54 +
  55 + Id int64 `json:"id"`
  56 + ParentId int64 `json:"parentId"`
  57 +}
  58 +
  59 +//自查项 键值
  60 +func (c SelfCheck) Key() string {
  61 + return fmt.Sprintf("%v-%v", c.GroupId, c.CheckItem)
  62 +}
  63 +
  64 +//新建自查项列表
  65 +//@data json格式的数据体
29 func NewSelfChecks(data string) (rsp SelfChecks) { 66 func NewSelfChecks(data string) (rsp SelfChecks) {
30 if len(data) == 0 { 67 if len(data) == 0 {
31 return 68 return
@@ -37,27 +74,22 @@ func NewSelfChecks(data string) (rsp SelfChecks) { @@ -37,27 +74,22 @@ func NewSelfChecks(data string) (rsp SelfChecks) {
37 return 74 return
38 } 75 }
39 76
  77 +/*自查项列表*/
40 type SelfChecks []SelfCheck 78 type SelfChecks []SelfCheck
41 79
42 -type SelfCheck struct {  
43 - CheckItem string `json:"checkItem"`  
44 - GroupId int64 `json:"groupId"` //分组  
45 - Answer string `json:"answer,omitempty"`  
46 - Reason string `json:"reason,omitempty"`  
47 -}  
48 -  
49 -func (c SelfCheck) Key() string {  
50 - return fmt.Sprintf("%v-%v", c.GroupId, c.CheckItem)  
51 -}  
52 -  
53 //统计自查结果 80 //统计自查结果
54 func (s SelfChecks) Static() SelfCheckResults { 81 func (s SelfChecks) Static() SelfCheckResults {
55 if len(s) == 0 { 82 if len(s) == 0 {
56 return []selfCheckResult{} 83 return []selfCheckResult{}
57 } 84 }
58 results := []selfCheckResult{{Item: "是"}, {Item: "否"}, {Item: "不清楚"}} 85 results := []selfCheckResult{{Item: "是"}, {Item: "否"}, {Item: "不清楚"}}
  86 + var gIdx int64
59 for i := range s { 87 for i := range s {
60 check := (s)[i] 88 check := (s)[i]
  89 + if gIdx == check.GroupId {
  90 + continue
  91 + }
  92 + gIdx = check.GroupId
61 for k := range results { 93 for k := range results {
62 if strings.EqualFold(results[k].Item, strings.TrimSpace(check.Answer)) { 94 if strings.EqualFold(results[k].Item, strings.TrimSpace(check.Answer)) {
63 results[k].Total = results[k].Total + 1 95 results[k].Total = results[k].Total + 1
@@ -96,6 +128,9 @@ func (s SelfChecks) String() string { @@ -96,6 +128,9 @@ func (s SelfChecks) String() string {
96 var buf bytes.Buffer 128 var buf bytes.Buffer
97 for i := range s { 129 for i := range s {
98 c := s[i] 130 c := s[i]
  131 + if len(c.Answer) == 0 {
  132 + continue
  133 + }
99 if len(c.Reason) == 0 { 134 if len(c.Reason) == 0 {
100 buf.WriteString(fmt.Sprintf("\n%v:%v;", c.CheckItem, c.Answer)) 135 buf.WriteString(fmt.Sprintf("\n%v:%v;", c.CheckItem, c.Answer))
101 } else { 136 } else {
@@ -104,6 +139,8 @@ func (s SelfChecks) String() string { @@ -104,6 +139,8 @@ func (s SelfChecks) String() string {
104 } 139 }
105 return buf.String() 140 return buf.String()
106 } 141 }
  142 +
  143 +//比较自查内容 ,返回差级
107 func (s SelfChecks) Compare(dst string) (rspChecks SelfChecks, err error) { 144 func (s SelfChecks) Compare(dst string) (rspChecks SelfChecks, err error) {
108 var ( 145 var (
109 dstChecks SelfChecks 146 dstChecks SelfChecks
@@ -126,7 +163,7 @@ func (s SelfChecks) Compare(dst string) (rspChecks SelfChecks, err error) { @@ -126,7 +163,7 @@ func (s SelfChecks) Compare(dst string) (rspChecks SelfChecks, err error) {
126 for i := range s { 163 for i := range s {
127 c := s[i] 164 c := s[i]
128 if v, ok := mapChecks[c.Key()]; ok { 165 if v, ok := mapChecks[c.Key()]; ok {
129 - //回答不一 166 + //回答不一
130 if !strings.EqualFold(c.Answer, v.Answer) { 167 if !strings.EqualFold(c.Answer, v.Answer) {
131 rspChecks = append(rspChecks, c) 168 rspChecks = append(rspChecks, c)
132 continue 169 continue
@@ -140,7 +177,75 @@ func (s SelfChecks) Compare(dst string) (rspChecks SelfChecks, err error) { @@ -140,7 +177,75 @@ func (s SelfChecks) Compare(dst string) (rspChecks SelfChecks, err error) {
140 return 177 return
141 } 178 }
142 179
143 -//自查问题 180 +//按规则设置自查 一级自查
  181 +func (s SelfChecks) SetSelfChecksLevel1ByRule() (err error) {
  182 + if len(s) == 0 {
  183 + return
  184 + }
  185 + s.Format()
  186 + var gIdx = -1
  187 + for i := 0; i < len(s); i++ {
  188 + if gIdx < 0 || s[gIdx].GroupId != s[i].GroupId {
  189 + gIdx = i
  190 + } else {
  191 + continue
  192 + }
  193 + hasSub := false
  194 + var (
  195 + cntYes = 0 //是
  196 + cntNo = 0 //否
  197 + cntUncertain = 0 //不确定
  198 + )
  199 + for j := i + 1; j < len(s); j++ {
  200 + if s[i].GroupId == s[j].GroupId {
  201 + if !hasSub {
  202 + hasSub = true
  203 + }
  204 + } else {
  205 + break
  206 + }
  207 + answer := s[j].Answer
  208 + if strings.EqualFold(strings.TrimSpace(answer), OptionYes) {
  209 + cntYes++
  210 + } else if strings.EqualFold(strings.TrimSpace(answer), OptionNo) {
  211 + cntNo++
  212 + } else if strings.EqualFold(strings.TrimSpace(answer), OptionUncertain) {
  213 + cntUncertain++
  214 + }
  215 + }
  216 + //只有一级维度的必须填写
  217 + if hasSub {
  218 + if cntYes > 0 {
  219 + s[gIdx].Answer = OptionYes
  220 + } else if cntNo > 0 {
  221 + s[gIdx].Answer = OptionNo
  222 + } else if cntUncertain > 0 {
  223 + s[gIdx].Answer = OptionUncertain
  224 + }
  225 + }
  226 + if hasSub && cntYes == 0 && cntNo == 0 && cntUncertain == 0 {
  227 + err = NewCustomMessage(2, fmt.Sprintf("未填写自查项:%v,二级维度至少需要填写一项", s[gIdx].CheckItem))
  228 + }
  229 + if !hasSub && len(s[gIdx].Answer) == 0 {
  230 + err = NewCustomMessage(2, fmt.Sprintf("未填写自查项:%v", s[gIdx].CheckItem))
  231 + }
  232 + }
  233 + return
  234 +}
  235 +
  236 +//格式化数据结构
  237 +func (s SelfChecks) Format() {
  238 + if len(s) == 0 {
  239 + return
  240 + }
  241 + for i := range s {
  242 + if strings.TrimSpace(s[i].Answer) == OptionNo {
  243 + s[i].Reason = strings.TrimSpace(s[i].Reason)
  244 + }
  245 + }
  246 +}
  247 +
  248 +//新建自查问题
144 func NewCheckQuestion(checkItem, title string, groupId int64, ops []CheckOption) *CheckQuestion { 249 func NewCheckQuestion(checkItem, title string, groupId int64, ops []CheckOption) *CheckQuestion {
145 return &CheckQuestion{ 250 return &CheckQuestion{
146 CheckItem: checkItem, 251 CheckItem: checkItem,
@@ -150,22 +255,185 @@ func NewCheckQuestion(checkItem, title string, groupId int64, ops []CheckOption) @@ -150,22 +255,185 @@ func NewCheckQuestion(checkItem, title string, groupId int64, ops []CheckOption)
150 } 255 }
151 } 256 }
152 257
  258 +/*问题*/
153 type CheckQuestion struct { 259 type CheckQuestion struct {
  260 + Id int64 `json:"id"`
  261 + ParentId int64 `json:"parentId"`
  262 +
154 CheckItem string `json:"checkItem"` 263 CheckItem string `json:"checkItem"`
155 Title string `json:"title"` 264 Title string `json:"title"`
156 GroupId int64 `json:"groupId"` 265 GroupId int64 `json:"groupId"`
157 Answer string `json:"answer,omitempty"` 266 Answer string `json:"answer,omitempty"`
  267 + Reason string `json:"reason,omitempty"`
158 CheckOptions []CheckOption `json:"options"` 268 CheckOptions []CheckOption `json:"options"`
  269 +
  270 + Required bool `json:"required"` //是否必填
159 } 271 }
  272 +
  273 +/*问题选项*/
160 type CheckOption struct { 274 type CheckOption struct {
161 Item string `json:"item"` 275 Item string `json:"item"`
162 NeedOther bool `json:"needOther"` //是否需填写其他的内容【1:需要】【2:不需要】 276 NeedOther bool `json:"needOther"` //是否需填写其他的内容【1:需要】【2:不需要】
163 } 277 }
164 278
  279 +//筛选结果
  280 +type SiftingResult struct {
  281 + CheckId int `json:"checkId"` //检查项id
  282 + CheckParentId int64 `json:"parentId"` //项父id
  283 + //GroupId int `json:"json:groupId"`//项分组id
  284 + Title string `json:"title"` //标题
  285 + CheckItem string `json:"checkItem"` //自查项
  286 +
  287 + TotalYes int `json:"totalYes"` //选择是的人数
  288 + TotalNo int `json:"totalNo"` //选择否的人数
  289 + TotalUncertain int `json:"totalUncertain"` //选择不清楚的人数
  290 + TotalSubmitters int `json:"totalSubmitters"` //总提交人数
  291 +
  292 + SubSiftingResults SiftingResults `json:"subSiftingResults"`
  293 +}
  294 +
  295 +//筛选结果列表
  296 +type SiftingResults []SiftingResult
  297 +
  298 +//清空统计结果
  299 +func (s SiftingResults) ClearStatic() {
  300 + for i := range s {
  301 + s[i].TotalYes = 0
  302 + s[i].TotalNo = 0
  303 + s[i].TotalUncertain = 0
  304 + s[i].TotalSubmitters = 0
  305 + s[i].SubSiftingResults.ClearStatic()
  306 + }
  307 +}
  308 +
  309 +/*
  310 +设置一级筛选结果
  311 +
  312 +单个维度显示“是”、“否”、“不清楚”的规则:
  313 + 1、所有人均选择“是”,则该维度的结果为“是”
  314 + 2、只要有一个“否”,则该维度的结果为“否” ,不需要显示理由
  315 + 3、其他情况则显示为“不清楚”
  316 +*/
  317 +func (s SiftingResults) SetSelfChecksLevel1ByRule() {
  318 + for i := range s {
  319 + tmpAnswer := ""
  320 + if s[i].TotalNo > 0 {
  321 + tmpAnswer = OptionNo
  322 + }
  323 + if s[i].TotalYes > 0 && s[i].TotalNo == 0 && s[i].TotalUncertain == 0 {
  324 + tmpAnswer = OptionYes
  325 + }
  326 + if s[i].TotalNo == 0 && s[i].TotalUncertain > 0 {
  327 + tmpAnswer = OptionUncertain
  328 + }
  329 + s[i].TotalNo = 0
  330 + s[i].TotalYes = 0
  331 + s[i].TotalUncertain = 0
  332 + if tmpAnswer == OptionNo {
  333 + s[i].TotalNo = s[i].TotalSubmitters
  334 + } else if tmpAnswer == OptionYes {
  335 + s[i].TotalYes = s[i].TotalSubmitters
  336 + } else if tmpAnswer == OptionUncertain {
  337 + s[i].TotalUncertain = s[i].TotalSubmitters
  338 + }
  339 + }
  340 +}
  341 +
  342 +//添加统计
  343 +func (s SiftingResults) AddStatic(checkId int, answer string) {
  344 + s.addStatic(checkId, answer)
  345 +}
  346 +func (s SiftingResults) addStatic(checkId int, answer string) {
  347 + for i := range s {
  348 + if s[i].CheckId == checkId {
  349 + var isAnswer = true
  350 + switch answer {
  351 + case OptionYes:
  352 + s[i].TotalYes++
  353 + break
  354 + case OptionNo:
  355 + s[i].TotalNo++
  356 + break
  357 + case OptionUncertain:
  358 + s[i].TotalUncertain++
  359 + break
  360 + default:
  361 + isAnswer = false
  362 + break
  363 + }
  364 + if isAnswer {
  365 + s[i].TotalSubmitters++
  366 + }
  367 + }
  368 + s[i].SubSiftingResults.AddStatic(checkId, answer)
  369 + }
  370 +}
  371 +
  372 +//筛选结果详情
  373 +type SiftingResultDetail struct {
  374 + Option string `json:"option"` //选项:是 否 不清楚
  375 + Items SiftingCommitItems `json:"items"`
  376 + TotalSubmitters int `json:"totalSubmitters"` //总提交人数
  377 +}
  378 +
  379 +//筛选结果提交人项
  380 +type SiftingCommitItems []SiftingCommitItem
  381 +type SiftingCommitItem struct {
  382 + Provider *BaseUserInfo `json:"provider"`
  383 + Reason string `json:"reason"` //理由
  384 +}
  385 +
  386 +/******************REQUEST/RESPONSE (请求应答实体)*******************/
165 /*CheckQuestions 自查问题列表*/ 387 /*CheckQuestions 自查问题列表*/
166 type CheckQuestionsRequest struct { 388 type CheckQuestionsRequest struct {
  389 + Type int `json:"type"` //0.自查 1.筛选结果
167 ChanceId int64 `json:"chanceId" valid:"Required"` 390 ChanceId int64 `json:"chanceId" valid:"Required"`
168 } 391 }
169 type CheckQuestionsResponse struct { 392 type CheckQuestionsResponse struct {
170 Questions []*CheckQuestion `json:"questions"` 393 Questions []*CheckQuestion `json:"questions"`
171 } 394 }
  395 +
  396 +//SiftingPool 筛选池
  397 +type SiftingPoolRequest struct {
  398 + PageInfo
  399 + Uid int64 `json:"uid"` //注入用户 测试使用
  400 + SubmitStatus int `json:"submitStatus"` //0:待我提交 1:提交
  401 + SiftedStatus int `-` //筛选状态 1:提交中 2:通过 3:不通过
  402 +}
  403 +type SiftingPoolResponse struct{ ChancePoolResponse }
  404 +
  405 +/*筛选结果 SiftingResults */
  406 +type SiftingResultsRequest struct {
  407 + PageInfo
  408 + Uid int64 `json:"uid"` //注入用户 测试使用
  409 + SiftedStatus int `json:"siftingStatus"` //筛选状态 1:待处理 2:通过 3:不通过
  410 +}
  411 +type SiftingResultsResponse struct{ ChancePoolResponse }
  412 +
  413 +/*SubmitChecks 提交自查*/
  414 +type SubmitChecksRequest struct {
  415 + //Type int `json:"type"` //1.审核人
  416 + Uid int64 `json:"uid"`
  417 + ChanceId int64 `json:"chanceId" valid:"Required"`
  418 + SelfChecks SelfChecks `json:"selfChecks"`
  419 +}
  420 +type SubmitChecksResponse struct{}
  421 +
  422 +/*SiftingResultsItemHistory 筛选历史*/
  423 +type SiftingResultsItemHistoryRequest struct {
  424 + ChanceId int64 `json:"chanceId" valid:"Required"`
  425 +}
  426 +type SiftingResultsItemHistoryResponse struct {
  427 + SiftingResults SiftingResults `json:"siftingResults"`
  428 + TotalSubmitters int `json:"totalSubmitters"`
  429 +}
  430 +
  431 +/*SiftingResultsItemDetail 筛选历史详情*/
  432 +type SiftingResultsItemDetailRequest struct {
  433 + ChanceId int64 `json:"chanceId" valid:"Required"`
  434 + CheckId int `json:"checkId" valid:"Required"` //检查项id
  435 +}
  436 +type SiftingResultsItemDetailResponse struct {
  437 + SiftingResultDetails []SiftingResultDetail `json:"siftingResultDetails"`
  438 + TotalSubmitters int `json:"totalSubmitters"` //总提交人数
  439 +}
  1 +package protocol
  2 +
  3 +import (
  4 + "encoding/json"
  5 + "fmt"
  6 + "testing"
  7 +)
  8 +
  9 +func TestSelfChecks(t *testing.T) {
  10 + nsc := func(id, pid int64, checkItem, answer string) SelfCheck {
  11 + item := SelfCheck{
  12 + CheckItem: checkItem, Answer: answer, Id: id, ParentId: pid,
  13 + }
  14 + item.GroupId = pid
  15 + if pid == 0 {
  16 + item.GroupId = id
  17 + }
  18 + return item
  19 + }
  20 + nscNo := func(id, pid int64, checkItem, answer, reason string) SelfCheck {
  21 + item := nsc(id, pid, checkItem, answer)
  22 + item.Reason = reason
  23 + return item
  24 + }
  25 + input := SelfChecks([]SelfCheck{
  26 + nsc(1, 0, "1", ""),
  27 + nsc(2, 1, "2", OptionYes),
  28 + nsc(3, 1, "3", OptionNo),
  29 + nsc(4, 1, "4", OptionUncertain),
  30 + nsc(5, 1, "5", ""),
  31 +
  32 + nsc(6, 0, "6", ""),
  33 + nsc(7, 6, "7", OptionUncertain),
  34 + nscNo(8, 6, "8", OptionNo, " "),
  35 + nsc(9, 6, "9", OptionUncertain),
  36 + nsc(10, 6, "10", ""),
  37 +
  38 + nsc(11, 0, "11", OptionYes),
  39 + nsc(12, 0, "12", OptionYes),
  40 + })
  41 + input.SetSelfChecksLevel1ByRule()
  42 + if input[0].Answer != OptionYes || input[5].Answer != OptionNo {
  43 + t.Fatal(fmt.Sprintf("SetSelfChecksLevel1ByRule Fail"))
  44 + }
  45 + if input.Static()[0].Total != 3 || input.Static()[0].Item != OptionYes {
  46 + t.Fatal(fmt.Sprintf("Static Fail"))
  47 + }
  48 + if input[7].Reason != " " {
  49 + t.Fatal("reason data error")
  50 + }
  51 + input.Format()
  52 + if input[7].Reason == " " {
  53 + t.Fatal("reason data error")
  54 + }
  55 + t.Log(input.String())
  56 +
  57 + inputCompare := SelfChecks([]SelfCheck{
  58 + nsc(1, 0, "1", ""),
  59 + nsc(2, 1, "2", OptionYes),
  60 + nsc(3, 1, "3", OptionNo),
  61 + nsc(4, 1, "4", OptionNo), //diff
  62 + nsc(5, 1, "5", ""),
  63 +
  64 + nsc(6, 0, "6", ""),
  65 + nsc(7, 6, "7", OptionUncertain),
  66 + nscNo(8, 6, "8", OptionNo, " "),
  67 + nsc(9, 6, "9", OptionUncertain),
  68 + nsc(10, 6, "10", ""),
  69 +
  70 + nsc(11, 0, "11", OptionYes),
  71 + nsc(12, 0, "12", OptionNo), //diff
  72 + })
  73 + inputCompare.SetSelfChecksLevel1ByRule()
  74 + inputCompare.Format()
  75 + data, err := json.Marshal(input)
  76 + if err != nil {
  77 + t.Fatal(err)
  78 + }
  79 + o, err := inputCompare.Compare(string(data))
  80 + if err != nil {
  81 + t.Fatal(err)
  82 + }
  83 + if len(o) != 2 {
  84 + t.Fatal("Compare fail")
  85 + }
  86 + t.Log("Compare:", o.String())
  87 +}
  88 +
  89 +func TestSiftingResults(t *testing.T) {
  90 +
  91 +}
@@ -108,6 +108,12 @@ func BadRequestParam(code int) *ResponseMessage { @@ -108,6 +108,12 @@ func BadRequestParam(code int) *ResponseMessage {
108 return NewMesage(code) 108 return NewMesage(code)
109 } 109 }
110 110
  111 +func BadRequestParamWithMessage(code int, message string) *ResponseMessage {
  112 + msg := NewMesage(code)
  113 + msg.Errmsg = message
  114 + return msg
  115 +}
  116 +
111 func NewSuccessWithMessage(msg string) *ErrWithMessage { 117 func NewSuccessWithMessage(msg string) *ErrWithMessage {
112 return &ErrWithMessage{ 118 return &ErrWithMessage{
113 Err: nil, 119 Err: nil,
1 package protocol 1 package protocol
2 2
3 -const RequireVersion = "0.9.0" 3 +const (
  4 + VERSION = "0.11.5"
  5 + RequireVersion = "0.9.0"
  6 +)
4 7
5 /* 8 /*
6 全局变量声明 9 全局变量声明
@@ -87,3 +90,18 @@ type NameItem struct { @@ -87,3 +90,18 @@ type NameItem struct {
87 Id int `json:"id"` 90 Id int `json:"id"`
88 Name string `json:"name"` 91 Name string `json:"name"`
89 } 92 }
  93 +
  94 +type PageInfo struct {
  95 + PageIndex int `json:"pageIndex"` //页码(默认0代表第1页)
  96 + PageSize int `json:"pageSize" valid:"Required"` //每页数量
  97 +}
  98 +
  99 +//获取分页信息
  100 +func (p PageInfo) Offset() (offset int) {
  101 + var size = p.PageSize
  102 + if size == 0 {
  103 + size = 20
  104 + }
  105 + offset = size * p.PageIndex
  106 + return
  107 +}
@@ -272,15 +272,7 @@ type MsgChanceReviseResponse struct { @@ -272,15 +272,7 @@ type MsgChanceReviseResponse struct {
272 272
273 //我的审核机会列表 273 //我的审核机会列表
274 type MsgChanceApproveItemOrm struct { 274 type MsgChanceApproveItemOrm struct {
275 - ChanceUserId int64 `orm:"column(chance_user_id)"`  
276 - SourceContent string `orm:"column(source_content)"`  
277 - ChanceEnableStatus int `orm:"column(enable_status)"`  
278 - Images string `orm:"column(images)"`  
279 - Voices string `orm:"column(speechs)"`  
280 - Videos string `orm:"column(videos)"`  
281 - ReviewStatus int `orm:"column(review_status)"`  
282 - Status int `orm:"column(status)"`  
283 - ApproveData string `orm:"column(approve_data)"` //审核数据 275 + CommChanceItemOrm
284 276
285 Id int64 `orm:"column(id)"` //消息id 277 Id int64 `orm:"column(id)"` //消息id
286 MsgTime time.Time `orm:"column(msg_time)"` 278 MsgTime time.Time `orm:"column(msg_time)"`
@@ -289,8 +281,8 @@ type MsgChanceApproveItemOrm struct { @@ -289,8 +281,8 @@ type MsgChanceApproveItemOrm struct {
289 CreateTime time.Time `orm:"column(create_at)"` 281 CreateTime time.Time `orm:"column(create_at)"`
290 Message string `orm:"column(message)"` 282 Message string `orm:"column(message)"`
291 IsRead int64 `orm:"column(is_read)"` 283 IsRead int64 `orm:"column(is_read)"`
292 - ChanceId int64 `orm:"column(chance_id)"` // 机会id  
293 - //EnableStatus int `orm:"column(enable_status)"` 284 + //ChanceId int64 `orm:"column(chance_id)"` // 机会id
  285 + EnableStatus int `orm:"column(enable_status)"`
294 SourceId int64 `orm:"column(source_id)"` // 机会id 286 SourceId int64 `orm:"column(source_id)"` // 机会id
295 Data string `orm:"column(data)"` 287 Data string `orm:"column(data)"`
296 } 288 }
@@ -257,6 +257,38 @@ func init() { @@ -257,6 +257,38 @@ func init() {
257 257
258 beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"], 258 beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
259 beego.ControllerComments{ 259 beego.ControllerComments{
  260 + Method: "SiftingPool",
  261 + Router: `/siftingPool`,
  262 + AllowHTTPMethods: []string{"post"},
  263 + MethodParams: param.Make(),
  264 + Params: nil})
  265 +
  266 + beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
  267 + beego.ControllerComments{
  268 + Method: "SiftingResults",
  269 + Router: `/siftingResults`,
  270 + AllowHTTPMethods: []string{"post"},
  271 + MethodParams: param.Make(),
  272 + Params: nil})
  273 +
  274 + beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
  275 + beego.ControllerComments{
  276 + Method: "SiftingResultsItemDetail",
  277 + Router: `/siftingResults/itemDetail`,
  278 + AllowHTTPMethods: []string{"post"},
  279 + MethodParams: param.Make(),
  280 + Params: nil})
  281 +
  282 + beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
  283 + beego.ControllerComments{
  284 + Method: "SiftingResultsItemHistory",
  285 + Router: `/siftingResults/itemHistory`,
  286 + AllowHTTPMethods: []string{"post"},
  287 + MethodParams: param.Make(),
  288 + Params: nil})
  289 +
  290 + beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
  291 + beego.ControllerComments{
260 Method: "ChanceStatistics", 292 Method: "ChanceStatistics",
261 Router: `/statistics`, 293 Router: `/statistics`,
262 AllowHTTPMethods: []string{"post"}, 294 AllowHTTPMethods: []string{"post"},
@@ -273,6 +305,14 @@ func init() { @@ -273,6 +305,14 @@ func init() {
273 305
274 beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"], 306 beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
275 beego.ControllerComments{ 307 beego.ControllerComments{
  308 + Method: "SubmitChecks",
  309 + Router: `/submitSiftingResult`,
  310 + AllowHTTPMethods: []string{"post"},
  311 + MethodParams: param.Make(),
  312 + Params: nil})
  313 +
  314 + beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
  315 + beego.ControllerComments{
276 Method: "SympathyAction", 316 Method: "SympathyAction",
277 Router: `/sympathyAction`, 317 Router: `/sympathyAction`,
278 AllowHTTPMethods: []string{"post"}, 318 AllowHTTPMethods: []string{"post"},
@@ -625,6 +665,14 @@ func init() { @@ -625,6 +665,14 @@ func init() {
625 665
626 beego.GlobalControllerRouter["opp/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:VodController"], 666 beego.GlobalControllerRouter["opp/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:VodController"],
627 beego.ControllerComments{ 667 beego.ControllerComments{
  668 + Method: "CreateUploadImages",
  669 + Router: `/createUploadImages`,
  670 + AllowHTTPMethods: []string{"post"},
  671 + MethodParams: param.Make(),
  672 + Params: nil})
  673 +
  674 + beego.GlobalControllerRouter["opp/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:VodController"],
  675 + beego.ControllerComments{
628 Method: "CreateUploadVideo", 676 Method: "CreateUploadVideo",
629 Router: `/createUploadVideo`, 677 Router: `/createUploadVideo`,
630 AllowHTTPMethods: []string{"post"}, 678 AllowHTTPMethods: []string{"post"},
@@ -647,4 +695,12 @@ func init() { @@ -647,4 +695,12 @@ func init() {
647 MethodParams: param.Make(), 695 MethodParams: param.Make(),
648 Params: nil}) 696 Params: nil})
649 697
  698 + beego.GlobalControllerRouter["opp/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:VodController"],
  699 + beego.ControllerComments{
  700 + Method: "RefreshUploadVideo",
  701 + Router: `/refreshUploadVideo`,
  702 + AllowHTTPMethods: []string{"post"},
  703 + MethodParams: param.Make(),
  704 + Params: nil})
  705 +
650 } 706 }
@@ -222,6 +222,14 @@ func SetChanceItem(header *protocol.RequestHeader, chance protocol.CommChanceIte @@ -222,6 +222,14 @@ func SetChanceItem(header *protocol.RequestHeader, chance protocol.CommChanceIte
222 CreateTime: chance.CreateTime.Unix() * 1000, 222 CreateTime: chance.CreateTime.Unix() * 1000,
223 PublicStatus: chance.PublishStatus, 223 PublicStatus: chance.PublishStatus,
224 } 224 }
  225 + item.UpdateTime = chance.UpdateTime.Unix() * 1000
  226 + item.ApproveTime = chance.ChanceApproveTime.Unix() * 1000
  227 + if item.ApproveTime < 0 {
  228 + item.ApproveTime = 0
  229 + }
  230 + if item.UpdateTime < 0 {
  231 + item.UpdateTime = 0
  232 + }
225 utils.JsonUnmarshal(chance.SourceContent, &item.FormList) 233 utils.JsonUnmarshal(chance.SourceContent, &item.FormList)
226 item.FormList = ClearEmptyForm(item.FormList) 234 item.FormList = ClearEmptyForm(item.FormList)
227 utils.JsonUnmarshal(chance.Images, &item.Pictures) 235 utils.JsonUnmarshal(chance.Images, &item.Pictures)
@@ -239,11 +247,17 @@ func SetMsgItem(header *protocol.RequestHeader, msg protocol.MsgItemOrm, commIte @@ -239,11 +247,17 @@ func SetMsgItem(header *protocol.RequestHeader, msg protocol.MsgItemOrm, commIte
239 247
240 //获取自查问题列表 通过模板 248 //获取自查问题列表 通过模板
241 func GetCheckQuestionsByTemplateId(id int64) (rsp []*protocol.CheckQuestion, err error) { 249 func GetCheckQuestionsByTemplateId(id int64) (rsp []*protocol.CheckQuestion, err error) {
  250 + type check struct {
  251 + models.AuditCheck
  252 + Id int64 `orm:"column(id)"`
  253 + ParentId int64 `orm:"column(parent_id)"`
  254 + }
242 var ( 255 var (
243 - checks []*models.AuditCheck 256 + checks []*check
244 ) 257 )
245 rsp = make([]*protocol.CheckQuestion, 0) 258 rsp = make([]*protocol.CheckQuestion, 0)
246 - if checks, err = models.GetAuditCheckBy(id); err != nil { 259 +
  260 + if err = models.GetAuditCheckBy(id, &checks); err != nil {
247 log.Error(err) 261 log.Error(err)
248 return 262 return
249 } 263 }
@@ -253,18 +267,22 @@ func GetCheckQuestionsByTemplateId(id int64) (rsp []*protocol.CheckQuestion, err @@ -253,18 +267,22 @@ func GetCheckQuestionsByTemplateId(id int64) (rsp []*protocol.CheckQuestion, err
253 var tmpGroupId int64 267 var tmpGroupId int64
254 var idx int = 0 268 var idx int = 0
255 var groupIdx = 0 269 var groupIdx = 0
  270 + var parentId = 0
256 for i := range checks { 271 for i := range checks {
257 c := checks[i] 272 c := checks[i]
258 273
259 if tmpGroupId != c.Pid { 274 if tmpGroupId != c.Pid {
260 groupIdx++ 275 groupIdx++
261 idx = 0 276 idx = 0
  277 + parentId = i + 1
262 } 278 }
263 tmpGroupId = c.Pid 279 tmpGroupId = c.Pid
264 item := protocol.NewCheckQuestion(c.Title, getQuestionTitle(groupIdx, idx, c.Title), c.Pid, protocol.CheckOptionsCommit) 280 item := protocol.NewCheckQuestion(c.Title, getQuestionTitle(groupIdx, idx, c.Title), c.Pid, protocol.CheckOptionsCommit)
  281 + item.Id, item.ParentId = genCustomizeQuestionId(i, idx, int64(parentId))
265 rsp = append(rsp, item) 282 rsp = append(rsp, item)
266 idx++ 283 idx++
267 } 284 }
  285 + setQuestionRequire(rsp)
268 return 286 return
269 } 287 }
270 288
@@ -286,22 +304,20 @@ func GetCheckQuestionsByChanceId(header *protocol.RequestHeader, id int64) (rsp @@ -286,22 +304,20 @@ func GetCheckQuestionsByChanceId(header *protocol.RequestHeader, id int64) (rsp
286 if len(chance.SelfChecks) == 0 { 304 if len(chance.SelfChecks) == 0 {
287 return 305 return
288 } 306 }
289 - if chance.ReviewStatus == protocol.ReviewStatusPass {  
290 - log.Warn("机会已审核通过不可编辑自查数据:", chance.Id)  
291 - return  
292 - }  
293 if e := json.Unmarshal([]byte(chance.SelfChecks), &selfChecks); e != nil { 307 if e := json.Unmarshal([]byte(chance.SelfChecks), &selfChecks); e != nil {
294 log.Error(e) 308 log.Error(e)
295 return 309 return
296 } 310 }
297 var tmpGroupId int64 311 var tmpGroupId int64
298 - var idx int = 0  
299 - var groupIdx = 0 312 + var idx int = 0 //组内排序
  313 + var groupIdx = 0 //分组序号
  314 + var parentId = 0
300 for i := range selfChecks { 315 for i := range selfChecks {
301 c := selfChecks[i] 316 c := selfChecks[i]
302 if tmpGroupId != c.GroupId { 317 if tmpGroupId != c.GroupId {
303 groupIdx++ 318 groupIdx++
304 idx = 0 319 idx = 0
  320 + parentId = i + 1
305 } 321 }
306 tmpGroupId = c.GroupId 322 tmpGroupId = c.GroupId
307 item := protocol.NewCheckQuestion(c.CheckItem, getQuestionTitle(groupIdx, idx, c.CheckItem), c.GroupId, protocol.CheckOptionsApprove) 323 item := protocol.NewCheckQuestion(c.CheckItem, getQuestionTitle(groupIdx, idx, c.CheckItem), c.GroupId, protocol.CheckOptionsApprove)
@@ -311,16 +327,103 @@ func GetCheckQuestionsByChanceId(header *protocol.RequestHeader, id int64) (rsp @@ -311,16 +327,103 @@ func GetCheckQuestionsByChanceId(header *protocol.RequestHeader, id int64) (rsp
311 item.Answer = c.Answer 327 item.Answer = c.Answer
312 } 328 }
313 } 329 }
  330 + //if item.Id == 0 {
  331 + item.Id, item.ParentId = genCustomizeQuestionId(i, idx, int64(parentId))
  332 + //}
314 rsp = append(rsp, item) 333 rsp = append(rsp, item)
315 idx++ 334 idx++
316 } 335 }
  336 + setQuestionRequire(rsp)
  337 + return
  338 +}
  339 +
  340 +//从问题筛选结果获取已回答的问题
  341 +func GetCheckQuestionsByChanceCheckResult(header *protocol.RequestHeader, id int64) (rsp []*protocol.CheckQuestion, err error) {
  342 + var (
  343 + checks []*models.ChanceCheckResult
  344 + groupIdx int = 1 //分组序号
  345 + )
  346 + if err = utils.ExecuteQueryAll(&checks, models.SqlGetUserCheckResults, id, header.UserId); err != nil {
  347 + if err == orm.ErrNoRows {
317 return 348 return
  349 + }
  350 + log.Error(err)
  351 + return
  352 + }
  353 + for i := range checks {
  354 + c := checks[i]
  355 + item := &protocol.CheckQuestion{
  356 + Id: int64(c.CheckId),
  357 + ParentId: int64(c.CheckPid),
  358 + GroupId: int64(c.GroupId),
  359 + CheckItem: c.CheckItem,
  360 + Answer: c.Answer,
  361 + Reason: c.Reason,
  362 + CheckOptions: protocol.CheckOptionsApprove,
  363 + }
  364 + if c.CheckPid == 0 {
  365 + item.Title = fmt.Sprintf("%v、%v", groupIdx, c.CheckItem)
  366 + } else {
  367 + item.Title = c.CheckItem
  368 + }
  369 + rsp = append(rsp, item)
  370 + }
  371 + setQuestionRequire(rsp)
  372 + return
  373 +}
  374 +
  375 +//设置问题需要填写
  376 +func setQuestionRequire(list []*protocol.CheckQuestion) {
  377 + if len(list) == 0 {
  378 + return
  379 + }
  380 + //var gIdx = -1
  381 + for i := 0; i < len(list); i++ {
  382 + //if gIdx < 0 || list[gIdx].GroupId != list[i].GroupId {
  383 + // gIdx = i
  384 + //} else {
  385 + // continue
  386 + //}
  387 + //hasSub := false
  388 + //for j := i + 1; j < len(list); j++ {
  389 + // if list[i].GroupId == list[j].GroupId {
  390 + // if !hasSub {
  391 + // hasSub = true
  392 + // }
  393 + // } else {
  394 + // break
  395 + // }
  396 + //}
  397 + ////只有一级维度的必须填写
  398 + //if !hasSub {
  399 + // list[gIdx].Required = true
  400 + //}
  401 + if list[i].ParentId == 0 { //一级都默认true
  402 + list[i].Required = true
  403 + }
  404 + }
318 } 405 }
  406 +
319 func getQuestionTitle(groupIdx int, idx int, title string) string { 407 func getQuestionTitle(groupIdx int, idx int, title string) string {
320 if idx == 0 { 408 if idx == 0 {
321 - return fmt.Sprintf("%v、%v?", groupIdx, title) 409 + return fmt.Sprintf("%v、%v", groupIdx, title)
  410 + }
  411 + //return fmt.Sprintf("%v.%v、%v", groupIdx, idx, title)
  412 + return fmt.Sprintf("%v", title)
  413 +}
  414 +
  415 +//自定义id
  416 +//@return id:问题序号 parentId:父级id
  417 +func genCustomizeQuestionId(seq int, idx int, groupId int64) (id int64, parentId int64) {
  418 + id = int64(seq) + 1
  419 + //同一分组的第一个 是一级
  420 + if idx == 0 {
  421 + //id = groupId
  422 + parentId = 0
  423 + return
322 } 424 }
323 - return fmt.Sprintf("%v.%v、%v?", groupIdx, idx, title) 425 + parentId = int64(groupId)
  426 + return
324 } 427 }
325 428
326 //自查问题回答批量入库 429 //自查问题回答批量入库
@@ -381,6 +484,7 @@ func BulkInsertSelfChecks(header *protocol.RequestHeader, relateId, chanceId int @@ -381,6 +484,7 @@ func BulkInsertSelfChecks(header *protocol.RequestHeader, relateId, chanceId int
381 o.Commit() 484 o.Commit()
382 } 485 }
383 486
  487 +//自查问题回答内容
384 func NewChanceSelfCheck(header *protocol.RequestHeader, check protocol.SelfCheck, chanceId, r int64, checkerType int) *models.ChanceSelfCheck { 488 func NewChanceSelfCheck(header *protocol.RequestHeader, check protocol.SelfCheck, chanceId, r int64, checkerType int) *models.ChanceSelfCheck {
385 return &models.ChanceSelfCheck{ 489 return &models.ChanceSelfCheck{
386 Id: idgen.Next(), 490 Id: idgen.Next(),
@@ -397,3 +501,71 @@ func NewChanceSelfCheck(header *protocol.RequestHeader, check protocol.SelfCheck @@ -397,3 +501,71 @@ func NewChanceSelfCheck(header *protocol.RequestHeader, check protocol.SelfCheck
397 Type: checkerType, 501 Type: checkerType,
398 } 502 }
399 } 503 }
  504 +
  505 +//新建通用列表项
  506 +func NewCommonListItem(header *protocol.RequestHeader, ormItem protocol.CommChanceItemOrm) protocol.CommonListItem {
  507 + commItem := protocol.CommonListItem{}
  508 + commItem.Chance, commItem.ChanceStatus = SetChanceItem(header, ormItem)
  509 + commItem.ReviewStatus = ormItem.ReviewStatus
  510 + commItem.ChanceId = ormItem.ChanceId
  511 +
  512 + ////模板数据
  513 + commItem.ChanceTemplate = GetTemplate(ormItem.TemplateId)
  514 + commItem.ChanceType = GetChanceType(ormItem.ChanceTypeId)
  515 + return commItem
  516 +}
  517 +
  518 +//获取模板
  519 +func GetTemplate(templateId int) protocol.NameItem {
  520 + if template, e := models.GetAuditTemplateById(int64(templateId)); e == nil {
  521 + item := protocol.NameItem{
  522 + Id: int(template.Id),
  523 + Name: template.Name,
  524 + }
  525 + return item
  526 + } else {
  527 + log.Error(templateId, e)
  528 + }
  529 + return protocol.NameItem{}
  530 +}
  531 +
  532 +//获取机会一级分类
  533 +func GetChanceType(chanceTypeId int) protocol.NameItem {
  534 + if template, e := models.GetChanceTypeById(chanceTypeId); e == nil {
  535 + item := protocol.NameItem{
  536 + Id: int(template.Id),
  537 + Name: template.Name,
  538 + }
  539 + return item
  540 + } else {
  541 + log.Error(chanceTypeId, e)
  542 + }
  543 + return protocol.NameItem{}
  544 +}
  545 +
  546 +//获取自查内容 筛选前使用SelfChecks(提交人的筛查结果)
  547 +func GetChanceSelfChecks(chanceInfo *models.Chance) []protocol.SelfCheck {
  548 + var selfChecks []protocol.SelfCheck = make([]protocol.SelfCheck, 0)
  549 + switch chanceInfo.CheckResultStatus {
  550 + case protocol.None: //未提交筛查结果
  551 + utils.JsonUnmarshal(chanceInfo.SelfChecks, &selfChecks)
  552 + if len(selfChecks) != 0 {
  553 + protocol.SelfChecks(selfChecks).SetSelfChecksLevel1ByRule()
  554 + }
  555 + break
  556 + case protocol.Waiting: //未通过审核的返回所有筛查结果(一级/二级)
  557 + utils.JsonUnmarshal(chanceInfo.CheckResult, &selfChecks)
  558 + break
  559 + default: //审核通过/不通过只显示一级
  560 + utils.JsonUnmarshal(chanceInfo.CheckResult, &selfChecks)
  561 + var lv1List []protocol.SelfCheck
  562 + for i := 0; i < len(selfChecks); i++ {
  563 + if selfChecks[i].ParentId == 0 {
  564 + lv1List = append(lv1List, selfChecks[i])
  565 + }
  566 + }
  567 + return lv1List
  568 + }
  569 + protocol.SelfChecks(selfChecks).Format()
  570 + return selfChecks
  571 +}
@@ -1494,11 +1494,12 @@ func ChanceStatistics(header *protocol.RequestHeader, request *protocol.ChanceSt @@ -1494,11 +1494,12 @@ func ChanceStatistics(header *protocol.RequestHeader, request *protocol.ChanceSt
1494 //我提交的机会 1494 //我提交的机会
1495 func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitChanceRequest) (rsp *protocol.MySubmitChanceResponse, err error) { 1495 func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitChanceRequest) (rsp *protocol.MySubmitChanceResponse, err error) {
1496 var ( 1496 var (
1497 - myChances []protocol.ChanceItemOrm  
1498 - total int  
1499 - provider *protocol.BaseUserInfo 1497 + ormItems []protocol.CommChanceItemOrm
1500 chance *models.Chance 1498 chance *models.Chance
1501 ) 1499 )
  1500 + rsp = &protocol.MySubmitChanceResponse{
  1501 + List: make([]protocol.CommonListItem, 0),
  1502 + }
1502 if request.LastId > 0 { 1503 if request.LastId > 0 {
1503 if chance, err = models.GetChanceById(request.LastId); err != nil { 1504 if chance, err = models.GetChanceById(request.LastId); err != nil {
1504 log.Error("机会不存在", request.LastId, err) 1505 log.Error("机会不存在", request.LastId, err)
@@ -1506,7 +1507,7 @@ func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitCh @@ -1506,7 +1507,7 @@ func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitCh
1506 } 1507 }
1507 request.LastId = chance.UpdateAt.Unix() 1508 request.LastId = chance.UpdateAt.Unix()
1508 } 1509 }
1509 - if total, err = models.GetChanceMyChance(header.UserId, header.CompanyId, []int8{request.ReviewStatus}, request.LastId, request.PageSize, &myChances); err != nil { 1510 + if rsp.Total, err = models.GetChanceMyChance(header.UserId, header.CompanyId, []int8{request.ReviewStatus}, request.LastId, request.PageSize, &ormItems); err != nil {
1510 if err == orm.ErrNoRows { 1511 if err == orm.ErrNoRows {
1511 err = nil 1512 err = nil
1512 return 1513 return
@@ -1514,41 +1515,15 @@ func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitCh @@ -1514,41 +1515,15 @@ func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitCh
1514 log.Error(err) 1515 log.Error(err)
1515 return 1516 return
1516 } 1517 }
1517 - if provider, err = agg.GetUserBaseInfo(header.UserId, header.CompanyId); err != nil {  
1518 - log.Error(err)  
1519 - return  
1520 - }  
1521 - rsp = &protocol.MySubmitChanceResponse{Total: total}  
1522 1518
1523 - for i := 0; i < len(myChances); i++ {  
1524 - chance := myChances[i] 1519 + for i := 0; i < len(ormItems); i++ {
  1520 + ormItem := ormItems[i]
1525 commItem := protocol.CommonListItem{} 1521 commItem := protocol.CommonListItem{}
1526 - {  
1527 - item := protocol.ChanceItem{  
1528 - Id: chance.Id,  
1529 - Provider: provider,  
1530 - CreateTime: chance.CreateTime.Unix() * 1000,  
1531 - UpdateTime: chance.UpdateTime.Unix() * 1000,  
1532 - ApproveTime: chance.ApproveTime.Unix() * 1000,  
1533 - }  
1534 - if item.ApproveTime < 0 {  
1535 - item.ApproveTime = 0  
1536 - }  
1537 - jsonUnmarshal(chance.SourceContent, &item.FormList)  
1538 - item.FormList = clearEmptyForm(item.FormList)  
1539 - jsonUnmarshal(chance.Images, &item.Pictures)  
1540 - jsonUnmarshal(chance.Voices, &item.Speechs)  
1541 - jsonUnmarshal(chance.Videos, &item.Videos)  
1542 - commItem.Chance = item  
1543 - }  
1544 - if chance.Status == models.ChanceStatusClose {  
1545 - commItem.ChanceStatus = protocol.ChanceStatusClose  
1546 - }  
1547 - commItem.ReviewStatus = chance.ReviewStatus 1522 + commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem)
  1523 + commItem.ReviewStatus = ormItem.ReviewStatus
1548 if request.ReviewStatus == protocol.ReviewStatusPass { 1524 if request.ReviewStatus == protocol.ReviewStatusPass {
1549 var approveData protocol.ApproveData 1525 var approveData protocol.ApproveData
1550 - jsonUnmarshal(chance.ApproveData, &approveData)  
1551 - //commItem.ApproveData = approveData //TODO:删除不需要 1526 + jsonUnmarshal(ormItem.ChanceApproveData, &approveData)
1552 commItem.Score = approveData.Score 1527 commItem.Score = approveData.Score
1553 } 1528 }
1554 rsp.List = append(rsp.List, commItem) 1529 rsp.List = append(rsp.List, commItem)
@@ -1559,12 +1534,12 @@ func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitCh @@ -1559,12 +1534,12 @@ func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitCh
1559 //机会池 1534 //机会池
1560 func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequest) (rsp *protocol.ChancePoolResponse, err error) { 1535 func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequest) (rsp *protocol.ChancePoolResponse, err error) {
1561 var ( 1536 var (
1562 - myChances []protocol.ChancePoolItemOrm 1537 + chanceItems []protocol.ChancePoolItemOrm
1563 total int 1538 total int
1564 provider *protocol.BaseUserInfo 1539 provider *protocol.BaseUserInfo
1565 flag int 1540 flag int
1566 ) 1541 )
1567 - if total, err = agg.GetChancePool(header.UserId, header.CompanyId, request.ChanceTypeId, request.DepartmentId, request.IncludeSubDepartment, request.LastId, request.PageSize, &myChances); err != nil { 1542 + if total, err = agg.GetChancePool(header.UserId, header.CompanyId, request.ChanceTypeId, request.DepartmentId, request.IncludeSubDepartment, request.LastId, request.PageSize, &chanceItems); err != nil {
1568 if err == orm.ErrNoRows { 1543 if err == orm.ErrNoRows {
1569 err = nil 1544 err = nil
1570 return 1545 return
@@ -1573,14 +1548,16 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ @@ -1573,14 +1548,16 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ
1573 return 1548 return
1574 } 1549 }
1575 rsp = &protocol.ChancePoolResponse{Total: total, List: make([]protocol.CommonListItem, 0)} 1550 rsp = &protocol.ChancePoolResponse{Total: total, List: make([]protocol.CommonListItem, 0)}
1576 - for i := 0; i < len(myChances); i++ {  
1577 - chance := myChances[i] 1551 + for i := 0; i < len(chanceItems); i++ {
  1552 + chance := chanceItems[i]
1578 if provider, err = agg.GetUserBaseInfo(chance.Uid, header.CompanyId); err != nil { 1553 if provider, err = agg.GetUserBaseInfo(chance.Uid, header.CompanyId); err != nil {
1579 log.Error(err) 1554 log.Error(err)
1580 return 1555 return
1581 } 1556 }
1582 commItem := protocol.CommonListItem{} 1557 commItem := protocol.CommonListItem{}
1583 - { 1558 + commItem.ReviewStatus = chance.ReviewStatus //审核状态
  1559 +
  1560 + //机会数据
1584 item := protocol.ChanceItem{ 1561 item := protocol.ChanceItem{
1585 Id: chance.ChanceId, 1562 Id: chance.ChanceId,
1586 Provider: provider, 1563 Provider: provider,
@@ -1592,9 +1569,8 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ @@ -1592,9 +1569,8 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ
1592 jsonUnmarshal(chance.Voices, &item.Speechs) 1569 jsonUnmarshal(chance.Voices, &item.Speechs)
1593 jsonUnmarshal(chance.Videos, &item.Videos) 1570 jsonUnmarshal(chance.Videos, &item.Videos)
1594 commItem.Chance = item 1571 commItem.Chance = item
1595 - }  
1596 - commItem.ReviewStatus = chance.ReviewStatus  
1597 - { 1572 +
  1573 + //点赞评论数据
1598 var chanceData = protocol.ChanceData{ 1574 var chanceData = protocol.ChanceData{
1599 ThumbsUpTotal: chance.ZanTotal, 1575 ThumbsUpTotal: chance.ZanTotal,
1600 CommentTotal: chance.CommentTotal, 1576 CommentTotal: chance.CommentTotal,
@@ -1607,23 +1583,10 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ @@ -1607,23 +1583,10 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ
1607 chanceData.IsThumbsUp = (flag & protocol.MarkFlagZan) == protocol.MarkFlagZan 1583 chanceData.IsThumbsUp = (flag & protocol.MarkFlagZan) == protocol.MarkFlagZan
1608 chanceData.IsCollect = (flag & protocol.MarkFlagCollect) == protocol.MarkFlagCollect 1584 chanceData.IsCollect = (flag & protocol.MarkFlagCollect) == protocol.MarkFlagCollect
1609 commItem.ChanceData = chanceData 1585 commItem.ChanceData = chanceData
1610 - }  
1611 1586
1612 - {  
1613 - //做一次查询 查回所有的模板数据  
1614 - if template, e := models.GetAuditTemplateById(int64(chance.TemplateId)); e == nil {  
1615 - commItem.ChanceTemplate = protocol.NameItem{  
1616 - Id: int(template.Id),  
1617 - Name: template.Name,  
1618 - }  
1619 - }  
1620 - if chanceType, e := models.GetChanceTypeById(chance.ChanceTypeId); e == nil {  
1621 - commItem.ChanceType = protocol.NameItem{  
1622 - Id: int(chanceType.Id),  
1623 - Name: chanceType.Name,  
1624 - }  
1625 - }  
1626 - } 1587 + //模板数据
  1588 + commItem.ChanceTemplate = getTemplate(chance.TemplateId)
  1589 + commItem.ChanceType = getChanceType(chance.ChanceTypeId)
1627 rsp.List = append(rsp.List, commItem) 1590 rsp.List = append(rsp.List, commItem)
1628 } 1591 }
1629 return 1592 return
@@ -1632,11 +1595,10 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ @@ -1632,11 +1595,10 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ
1632 //我审核的机会 1595 //我审核的机会
1633 func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApproveChanceRequest) (rsp *protocol.MyApproveChanceResponse, err error) { 1596 func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApproveChanceRequest) (rsp *protocol.MyApproveChanceResponse, err error) {
1634 var ( 1597 var (
1635 - myChances []protocol.ChanceApproveItemOrm  
1636 - total int  
1637 - provider *protocol.BaseUserInfo 1598 + ormItems []protocol.ChanceApproveItemOrm
1638 chance *models.Chance 1599 chance *models.Chance
1639 ) 1600 )
  1601 + rsp = &protocol.MyApproveChanceResponse{List: make([]protocol.CommonListItem, 0)}
1640 if request.LastId > 0 { 1602 if request.LastId > 0 {
1641 if chance, err = models.GetChanceById(request.LastId); err != nil { 1603 if chance, err = models.GetChanceById(request.LastId); err != nil {
1642 log.Error("审批不存在", request.LastId, err) 1604 log.Error("审批不存在", request.LastId, err)
@@ -1645,7 +1607,7 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove @@ -1645,7 +1607,7 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove
1645 request.LastId = chance.UpdateAt.Unix() 1607 request.LastId = chance.UpdateAt.Unix()
1646 } 1608 }
1647 if request.ReviewStatus == protocol.ReviewStatusAuditging { 1609 if request.ReviewStatus == protocol.ReviewStatusAuditging {
1648 - if total, err = models.GetChanceMyApproveChanceEnable(header.UserId, header.CompanyId, []int8{request.ReviewStatus}, request.LastId, request.PageSize, &myChances); err != nil { 1610 + if rsp.Total, err = models.GetChanceMyApproveChanceEnable(header.UserId, header.CompanyId, []int8{request.ReviewStatus}, request.LastId, request.PageSize, &ormItems); err != nil {
1649 if err == orm.ErrNoRows { 1611 if err == orm.ErrNoRows {
1650 err = nil 1612 err = nil
1651 return 1613 return
@@ -1654,7 +1616,7 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove @@ -1654,7 +1616,7 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove
1654 return 1616 return
1655 } 1617 }
1656 } else { 1618 } else {
1657 - if total, err = models.GetChanceMyApproveChance(header.UserId, header.CompanyId, []int8{request.ReviewStatus}, request.LastId, request.PageSize, &myChances); err != nil { 1619 + if rsp.Total, err = models.GetChanceMyApproveChance(header.UserId, header.CompanyId, []int8{request.ReviewStatus}, request.LastId, request.PageSize, &ormItems); err != nil {
1658 if err == orm.ErrNoRows { 1620 if err == orm.ErrNoRows {
1659 err = nil 1621 err = nil
1660 return 1622 return
@@ -1663,65 +1625,45 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove @@ -1663,65 +1625,45 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove
1663 return 1625 return
1664 } 1626 }
1665 } 1627 }
1666 - rsp = &protocol.MyApproveChanceResponse{Total: total}  
1667 - for i := 0; i < len(myChances); i++ {  
1668 - chance := myChances[i] 1628 + for i := 0; i < len(ormItems); i++ {
  1629 + ormItem := ormItems[i]
1669 commItem := protocol.CommonListItem{} 1630 commItem := protocol.CommonListItem{}
1670 - commItem.ReviewStatus = chance.ReviewStatus  
1671 - if len(chance.SourceContent) == 0 || chance.ChanceEnableStatus == 0 { //机会删除  
1672 - commItem.ChanceStatus = protocol.ChanceStatusDelete  
1673 - }  
1674 - if chance.Status == models.ChanceStatusClose {  
1675 - commItem.ChanceStatus = protocol.ChanceStatusClose  
1676 - }  
1677 - if chance.ChanceUserId > 0 {  
1678 - if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {  
1679 - commItem.ChanceStatus = protocol.ChanceStatusDelete  
1680 - log.Error(chance.ChanceUserId, header.CompanyId, err)  
1681 - err = nil  
1682 - } else {  
1683 - item := protocol.ChanceItem{  
1684 - Id: chance.ChanceId,  
1685 - Provider: provider,  
1686 - CreateTime: chance.CreateTime.Unix() * 1000,  
1687 - UpdateTime: chance.UpdateTime.Unix() * 1000,  
1688 - ApproveTime: chance.ChanceApproveTime.Unix() * 1000,  
1689 - }  
1690 - if item.ApproveTime < 0 {  
1691 - item.ApproveTime = chance.UpdateTime.Unix() * 1000  
1692 - }  
1693 - jsonUnmarshal(chance.SourceContent, &item.FormList)  
1694 - item.FormList = clearEmptyForm(item.FormList)  
1695 - jsonUnmarshal(chance.Images, &item.Pictures)  
1696 - jsonUnmarshal(chance.Voices, &item.Speechs)  
1697 - jsonUnmarshal(chance.Videos, &item.Videos)  
1698 - commItem.Chance = item  
1699 - } 1631 + commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem.CommChanceItemOrm)
  1632 + commItem.ReviewStatus = ormItem.ReviewStatus
  1633 + if commItem.Chance.ApproveTime <= 0 {
  1634 + commItem.Chance.ApproveTime = ormItem.UpdateTime.Unix() * 1000
1700 } 1635 }
  1636 +
  1637 + //审核流数据
1701 approve := protocol.Approve{ 1638 approve := protocol.Approve{
1702 - ProcessId: chance.Id,  
1703 - CreateTime: chance.ProcessCreateTime.Unix() * 1000, 1639 + ProcessId: ormItem.Id,
  1640 + CreateTime: ormItem.ProcessCreateTime.Unix() * 1000,
1704 } 1641 }
1705 - //审核过的有审核时间 1642 + //审核过的机会 有审核时间
1706 if request.ReviewStatus != protocol.ReviewStatusAuditging { 1643 if request.ReviewStatus != protocol.ReviewStatusAuditging {
1707 - approve.ApproveTime = chance.ApproveTime.Unix() * 1000 1644 + approve.ApproveTime = ormItem.ApproveTime.Unix() * 1000
1708 if approve.ApproveTime < 0 { 1645 if approve.ApproveTime < 0 {
1709 - approve.ApproveTime = chance.ChanceApproveTime.Unix() * 1000 1646 + approve.ApproveTime = ormItem.ChanceApproveTime.Unix() * 1000
1710 } 1647 }
1711 } 1648 }
1712 commItem.Approve = approve 1649 commItem.Approve = approve
1713 - //审核完有审核数据 1650 + //审核中 有审核消息
1714 if request.ReviewStatus == protocol.ReviewStatusAuditging { 1651 if request.ReviewStatus == protocol.ReviewStatusAuditging {
1715 - commItem.Message = chance.ApproveMessage 1652 + commItem.Message = ormItem.ApproveMessage
1716 } 1653 }
  1654 + //审核通过有审核评分数据
1717 if request.ReviewStatus == protocol.ReviewStatusPass { 1655 if request.ReviewStatus == protocol.ReviewStatusPass {
1718 var approveData *protocol.ApproveData 1656 var approveData *protocol.ApproveData
1719 - jsonUnmarshal(chance.ApproveData, &approveData) 1657 + jsonUnmarshal(ormItem.ApproveData, &approveData)
1720 if approveData != nil { 1658 if approveData != nil {
1721 commItem.Score = approveData.Score 1659 commItem.Score = approveData.Score
1722 } 1660 }
1723 } 1661 }
1724 - commItem.SelfCheckResult = protocol.NewSelfChecks(chance.SelfChecks).Static() 1662 +
  1663 + selfChecks := protocol.NewSelfChecks(ormItem.SelfChecks)
  1664 + selfChecks.SetSelfChecksLevel1ByRule()
  1665 + commItem.SelfCheckResult = selfChecks.Static() //自查统计数据
  1666 +
1725 rsp.List = append(rsp.List, commItem) 1667 rsp.List = append(rsp.List, commItem)
1726 } 1668 }
1727 return 1669 return
@@ -1730,9 +1672,8 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove @@ -1730,9 +1672,8 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove
1730 // 我的收藏 1672 // 我的收藏
1731 func MyCollectChance(header *protocol.RequestHeader, request *protocol.MyCollectChanceRequest) (rsp *protocol.MyCollectChanceResponse, err error) { 1673 func MyCollectChance(header *protocol.RequestHeader, request *protocol.MyCollectChanceRequest) (rsp *protocol.MyCollectChanceResponse, err error) {
1732 var ( 1674 var (
1733 - myChances []protocol.ChanceCollectItemOrm 1675 + ormItems []protocol.ChanceCollectItemOrm
1734 total int 1676 total int
1735 - provider *protocol.BaseUserInfo  
1736 favorite *models.ChanceFavorite 1677 favorite *models.ChanceFavorite
1737 ) 1678 )
1738 if request.LastId > 0 { 1679 if request.LastId > 0 {
@@ -1742,7 +1683,7 @@ func MyCollectChance(header *protocol.RequestHeader, request *protocol.MyCollect @@ -1742,7 +1683,7 @@ func MyCollectChance(header *protocol.RequestHeader, request *protocol.MyCollect
1742 } 1683 }
1743 request.LastId = favorite.CollectTime.Unix() 1684 request.LastId = favorite.CollectTime.Unix()
1744 } 1685 }
1745 - if total, err = models.GetChanceCollect(header.UserId, request.LastId, request.PageSize, &myChances); err != nil { 1686 + if total, err = models.GetChanceCollect(header.UserId, request.LastId, request.PageSize, &ormItems); err != nil {
1746 if err == orm.ErrNoRows { 1687 if err == orm.ErrNoRows {
1747 err = nil 1688 err = nil
1748 return 1689 return
@@ -1751,67 +1692,38 @@ func MyCollectChance(header *protocol.RequestHeader, request *protocol.MyCollect @@ -1751,67 +1692,38 @@ func MyCollectChance(header *protocol.RequestHeader, request *protocol.MyCollect
1751 return 1692 return
1752 } 1693 }
1753 rsp = &protocol.MyCollectChanceResponse{Total: total} 1694 rsp = &protocol.MyCollectChanceResponse{Total: total}
1754 - for i := 0; i < len(myChances); i++ {  
1755 - chance := myChances[i] 1695 + for i := 0; i < len(ormItems); i++ {
  1696 + ormItem := ormItems[i]
1756 commItem := &protocol.CommonListItem{} 1697 commItem := &protocol.CommonListItem{}
1757 - commItem.ReviewStatus = chance.ReviewStatus  
1758 - commItem.ChanceId = chance.ChanceId  
1759 - if len(chance.SourceContent) == 0 || chance.ChanceEnableStatus == 0 { //机会删除  
1760 - commItem.ChanceStatus = protocol.ChanceStatusDelete  
1761 - }  
1762 - if chance.Status == models.ChanceStatusClose { //机会关闭  
1763 - commItem.ChanceStatus = protocol.ChanceStatusClose  
1764 - } 1698 + commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem.CommChanceItemOrm)
  1699 + commItem.ReviewStatus = ormItem.ReviewStatus
  1700 + commItem.ChanceId = ormItem.ChanceId
  1701 + commItem.Chance.UpdateTime = 0
  1702 + commItem.Chance.ApproveTime = 0
1765 1703
1766 - if chance.ChanceUserId > 0 {  
1767 - if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {  
1768 - commItem.ChanceStatus = protocol.ChanceStatusDelete  
1769 - log.Error(err)  
1770 - //return  
1771 - } else {  
1772 - item := protocol.ChanceItem{  
1773 - Id: chance.ChanceId,  
1774 - Provider: provider,  
1775 - CreateTime: chance.CreateTime.Unix() * 1000,  
1776 - PublicStatus: chance.PublishStatus,  
1777 - }  
1778 - jsonUnmarshal(chance.SourceContent, &item.FormList)  
1779 - item.FormList = clearEmptyForm(item.FormList)  
1780 - jsonUnmarshal(chance.Images, &item.Pictures)  
1781 - jsonUnmarshal(chance.Voices, &item.Speechs)  
1782 - jsonUnmarshal(chance.Videos, &item.Videos)  
1783 - commItem.Chance = item  
1784 - }  
1785 - }  
1786 -  
1787 - commItem.ReviewStatus = chance.ReviewStatus  
1788 - { 1704 + //chanceData
1789 var chanceData = protocol.ChanceData{ 1705 var chanceData = protocol.ChanceData{
1790 - ThumbsUpTotal: chance.ZanTotal,  
1791 - CommentTotal: chance.CommentTotal,  
1792 - PageViewTotal: chance.ViewTotal, 1706 + ThumbsUpTotal: ormItem.ZanTotal,
  1707 + CommentTotal: ormItem.CommentTotal,
  1708 + PageViewTotal: ormItem.ViewTotal,
1793 } 1709 }
1794 - chanceData.IsThumbsUp, chanceData.IsCollect, _ = getChanceMarkFlag(header, chance.ChanceId) 1710 + chanceData.IsThumbsUp, chanceData.IsCollect, _ = getChanceMarkFlag(header, ormItem.ChanceId)
1795 commItem.ChanceData = chanceData 1711 commItem.ChanceData = chanceData
1796 - }  
1797 - { 1712 +
1798 //做一次查询 查回所有的模板数据 1713 //做一次查询 查回所有的模板数据
1799 - commItem.ChanceTemplate = getTemplate(chance.TemplateId)  
1800 - commItem.ChanceType = getChanceType(chance.ChanceTypeId)  
1801 - }  
1802 - { 1714 + commItem.ChanceTemplate = getTemplate(ormItem.TemplateId)
  1715 + commItem.ChanceType = getChanceType(ormItem.ChanceTypeId)
  1716 +
  1717 + //收藏数据
1803 collect := protocol.CollectData{ 1718 collect := protocol.CollectData{
1804 - Id: chance.CollectId,  
1805 - CollectTime: chance.CollectTime.Unix() * 1000, 1719 + Id: ormItem.CollectId,
  1720 + CollectTime: ormItem.CollectTime.Unix() * 1000,
1806 } 1721 }
1807 - if collect.CollectTime <= 0 && chance.UpdateTime.Unix() > 0 {  
1808 - collect.CollectTime = chance.UpdateTime.Unix() * 1000 1722 + if collect.CollectTime <= 0 && ormItem.UpdateTime.Unix() > 0 {
  1723 + collect.CollectTime = ormItem.UpdateTime.Unix() * 1000
1809 } 1724 }
1810 - //收藏数据  
1811 commItem.CollectData = collect 1725 commItem.CollectData = collect
1812 1726
1813 - //commItem.ChanceId = chance.ChanceId  
1814 - }  
1815 rsp.List = append(rsp.List, commItem) 1727 rsp.List = append(rsp.List, commItem)
1816 } 1728 }
1817 agg.ValidChancePermission(header.UserId, header.CompanyId, rsp.List) 1729 agg.ValidChancePermission(header.UserId, header.CompanyId, rsp.List)
@@ -1821,9 +1733,8 @@ func MyCollectChance(header *protocol.RequestHeader, request *protocol.MyCollect @@ -1821,9 +1733,8 @@ func MyCollectChance(header *protocol.RequestHeader, request *protocol.MyCollect
1821 //我点赞的机会 1733 //我点赞的机会
1822 func MyThumbUpChance(header *protocol.RequestHeader, request *protocol.MyThumbUpChanceRequest) (rsp *protocol.MyThumbUpChanceResponse, err error) { 1734 func MyThumbUpChance(header *protocol.RequestHeader, request *protocol.MyThumbUpChanceRequest) (rsp *protocol.MyThumbUpChanceResponse, err error) {
1823 var ( 1735 var (
1824 - myChances []protocol.ChanceThumbUpItemOrm 1736 + ormItems []protocol.ChanceThumbUpItemOrm
1825 total int 1737 total int
1826 - provider *protocol.BaseUserInfo  
1827 favorite *models.ChanceFavorite 1738 favorite *models.ChanceFavorite
1828 ) 1739 )
1829 if request.LastId > 0 { 1740 if request.LastId > 0 {
@@ -1833,7 +1744,7 @@ func MyThumbUpChance(header *protocol.RequestHeader, request *protocol.MyThumbUp @@ -1833,7 +1744,7 @@ func MyThumbUpChance(header *protocol.RequestHeader, request *protocol.MyThumbUp
1833 } 1744 }
1834 request.LastId = favorite.ZanTime.Unix() 1745 request.LastId = favorite.ZanTime.Unix()
1835 } 1746 }
1836 - if total, err = models.GetChanceThumbUp(header.UserId, request.LastId, request.PageSize, &myChances); err != nil { 1747 + if total, err = models.GetChanceThumbUp(header.UserId, request.LastId, request.PageSize, &ormItems); err != nil {
1837 if err == orm.ErrNoRows { 1748 if err == orm.ErrNoRows {
1838 err = nil 1749 err = nil
1839 return 1750 return
@@ -1842,63 +1753,38 @@ func MyThumbUpChance(header *protocol.RequestHeader, request *protocol.MyThumbUp @@ -1842,63 +1753,38 @@ func MyThumbUpChance(header *protocol.RequestHeader, request *protocol.MyThumbUp
1842 return 1753 return
1843 } 1754 }
1844 rsp = &protocol.MyThumbUpChanceResponse{Total: total} 1755 rsp = &protocol.MyThumbUpChanceResponse{Total: total}
1845 - for i := 0; i < len(myChances); i++ {  
1846 - chance := myChances[i] 1756 + for i := 0; i < len(ormItems); i++ {
  1757 + ormItem := ormItems[i]
1847 commItem := &protocol.CommonListItem{} 1758 commItem := &protocol.CommonListItem{}
1848 - commItem.ReviewStatus = chance.ReviewStatus  
1849 - commItem.ChanceId = chance.ChanceId  
1850 - if len(chance.SourceContent) == 0 || chance.ChanceEnableStatus == 0 { //机会删除  
1851 - commItem.ChanceStatus = protocol.ChanceStatusDelete  
1852 - }  
1853 - if chance.Status == models.ChanceStatusClose { //机会关闭  
1854 - commItem.ChanceStatus = protocol.ChanceStatusClose  
1855 - }  
1856 - if chance.ChanceUserId > 0 {  
1857 - if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {  
1858 - commItem.ChanceStatus = protocol.ChanceStatusDelete  
1859 - log.Error(err)  
1860 - //return  
1861 - } else {  
1862 - item := protocol.ChanceItem{  
1863 - Id: chance.ChanceId,  
1864 - Provider: provider,  
1865 - CreateTime: chance.CreateTime.Unix() * 1000,  
1866 - PublicStatus: chance.PublishStatus,  
1867 - }  
1868 - jsonUnmarshal(chance.SourceContent, &item.FormList)  
1869 - item.FormList = clearEmptyForm(item.FormList)  
1870 - jsonUnmarshal(chance.Images, &item.Pictures)  
1871 - jsonUnmarshal(chance.Voices, &item.Speechs)  
1872 - jsonUnmarshal(chance.Videos, &item.Videos)  
1873 - commItem.Chance = item  
1874 - }  
1875 - }  
1876 - commItem.ReviewStatus = chance.ReviewStatus  
1877 - { 1759 + commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem.CommChanceItemOrm)
  1760 + commItem.ReviewStatus = ormItem.ReviewStatus
  1761 + commItem.ChanceId = ormItem.ChanceId
  1762 + commItem.Chance.UpdateTime = 0
  1763 + commItem.Chance.ApproveTime = 0
  1764 +
  1765 + //点赞收藏数据
1878 var chanceData = protocol.ChanceData{ 1766 var chanceData = protocol.ChanceData{
1879 - ThumbsUpTotal: chance.ZanTotal,  
1880 - CommentTotal: chance.CommentTotal,  
1881 - PageViewTotal: chance.ViewTotal, 1767 + ThumbsUpTotal: ormItem.ZanTotal,
  1768 + CommentTotal: ormItem.CommentTotal,
  1769 + PageViewTotal: ormItem.ViewTotal,
1882 } 1770 }
1883 - chanceData.IsThumbsUp, chanceData.IsCollect, _ = getChanceMarkFlag(header, chance.ChanceId) 1771 + chanceData.IsThumbsUp, chanceData.IsCollect, _ = getChanceMarkFlag(header, ormItem.ChanceId)
1884 commItem.ChanceData = chanceData 1772 commItem.ChanceData = chanceData
1885 - }  
1886 - {  
1887 - //做一次查询 查回所有的模板数据  
1888 - commItem.ChanceTemplate = getTemplate(chance.TemplateId)  
1889 - commItem.ChanceType = getChanceType(chance.ChanceTypeId)  
1890 - }  
1891 - { 1773 +
  1774 + //模板数据
  1775 + commItem.ChanceTemplate = getTemplate(ormItem.TemplateId)
  1776 + commItem.ChanceType = getChanceType(ormItem.ChanceTypeId)
  1777 +
  1778 + //点赞数据
1892 thumb := protocol.ThumbUpData{ 1779 thumb := protocol.ThumbUpData{
1893 - Id: chance.CollectId,  
1894 - ThumbUpTime: chance.ZanTime.Unix() * 1000, 1780 + Id: ormItem.CollectId,
  1781 + ThumbUpTime: ormItem.ZanTime.Unix() * 1000,
1895 } 1782 }
1896 - if thumb.ThumbUpTime <= 0 && chance.UpdateTime.Unix() > 0 {  
1897 - thumb.ThumbUpTime = chance.UpdateTime.Unix() * 1000 1783 + if thumb.ThumbUpTime <= 0 && ormItem.UpdateTime.Unix() > 0 {
  1784 + thumb.ThumbUpTime = ormItem.UpdateTime.Unix() * 1000
1898 } 1785 }
1899 - //收藏数据  
1900 commItem.ThumbUpData = thumb 1786 commItem.ThumbUpData = thumb
1901 - } 1787 +
1902 rsp.List = append(rsp.List, commItem) 1788 rsp.List = append(rsp.List, commItem)
1903 } 1789 }
1904 agg.ValidChancePermission(header.UserId, header.CompanyId, rsp.List) 1790 agg.ValidChancePermission(header.UserId, header.CompanyId, rsp.List)
@@ -1908,11 +1794,11 @@ func MyThumbUpChance(header *protocol.RequestHeader, request *protocol.MyThumbUp @@ -1908,11 +1794,11 @@ func MyThumbUpChance(header *protocol.RequestHeader, request *protocol.MyThumbUp
1908 //我的评论 1794 //我的评论
1909 func MyComment(header *protocol.RequestHeader, request *protocol.MyCommentRequest) (rsp *protocol.MyCommentResponse, err error) { 1795 func MyComment(header *protocol.RequestHeader, request *protocol.MyCommentRequest) (rsp *protocol.MyCommentResponse, err error) {
1910 var ( 1796 var (
1911 - myChances []protocol.ChanceCommentItemOrm 1797 + ormItems []protocol.ChanceCommentItemOrm
1912 total int 1798 total int
1913 provider *protocol.BaseUserInfo 1799 provider *protocol.BaseUserInfo
1914 ) 1800 )
1915 - if total, err = models.GetChanceComment(header.UserId, request.LastId, request.PageSize, &myChances); err != nil { 1801 + if total, err = models.GetChanceComment(header.UserId, request.LastId, request.PageSize, &ormItems); err != nil {
1916 if err == orm.ErrNoRows { 1802 if err == orm.ErrNoRows {
1917 err = nil 1803 err = nil
1918 return 1804 return
@@ -1925,47 +1811,30 @@ func MyComment(header *protocol.RequestHeader, request *protocol.MyCommentReques @@ -1925,47 +1811,30 @@ func MyComment(header *protocol.RequestHeader, request *protocol.MyCommentReques
1925 log.Error(err) 1811 log.Error(err)
1926 return 1812 return
1927 } 1813 }
1928 - for i := 0; i < len(myChances); i++ {  
1929 - chance := myChances[i] 1814 + for i := 0; i < len(ormItems); i++ {
  1815 + ormItem := ormItems[i]
1930 commItem := &protocol.CommonListItem{} 1816 commItem := &protocol.CommonListItem{}
1931 - commItem.ChanceId = chance.SourceId  
1932 - if chance.SourceType == protocol.SourceTypeChance {  
1933 - commItem.ReviewStatus = chance.ReviewStatus  
1934 - if len(chance.SourceContent) == 0 { //机会删除  
1935 - commItem.ChanceStatus = protocol.ChanceStatusDelete  
1936 - } else if chance.ChanceEnableStatus == 0 { //机会关闭  
1937 - commItem.ChanceStatus = protocol.ChanceStatusClose  
1938 - }  
1939 - if chance.Status == models.ChanceStatusClose { //机会关闭  
1940 - commItem.ChanceStatus = protocol.ChanceStatusClose  
1941 - }  
1942 - item := protocol.ChanceItem{  
1943 - Id: chance.SourceId,  
1944 - Provider: provider,  
1945 - CreateTime: chance.CreateTime.Unix() * 1000,  
1946 - PublicStatus: chance.PublishStatus,  
1947 - }  
1948 - jsonUnmarshal(chance.SourceContent, &item.FormList)  
1949 - item.FormList = clearEmptyForm(item.FormList)  
1950 - jsonUnmarshal(chance.Images, &item.Pictures)  
1951 - jsonUnmarshal(chance.Voices, &item.Speechs)  
1952 - jsonUnmarshal(chance.Videos, &item.Videos)  
1953 - commItem.Chance = item  
1954 - commItem.ReviewStatus = chance.ReviewStatus  
1955 - }  
1956 - if chance.SourceType == protocol.SourceTypeComment { 1817 + commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem.CommChanceItemOrm)
  1818 + commItem.ReviewStatus = ormItem.ReviewStatus
  1819 + commItem.ChanceId = ormItem.SourceId
  1820 + commItem.Chance.UpdateTime = 0
  1821 + commItem.Chance.ApproveTime = 0
  1822 + commItem.Chance.Provider = provider
  1823 + //被评论的数据内容
  1824 + if ormItem.SourceType == protocol.SourceTypeComment {
1957 commItem.CommentedData = protocol.CommentData{ 1825 commItem.CommentedData = protocol.CommentData{
1958 - Id: chance.SourceId,  
1959 - Content: chance.CommentedContent,  
1960 - CommentTime: chance.CommentedTime.Unix() * 1000, 1826 + Id: ormItem.SourceId,
  1827 + Content: ormItem.CommentedContent,
  1828 + CommentTime: ormItem.CommentedTime.Unix() * 1000,
1961 } 1829 }
1962 } 1830 }
  1831 + //评论内容
1963 commItem.CommentData = protocol.CommentData{ 1832 commItem.CommentData = protocol.CommentData{
1964 - Id: chance.CommentId,  
1965 - CommentTime: chance.CommentTime.Unix() * 1000,  
1966 - Content: chance.CommentContent, 1833 + Id: ormItem.CommentId,
  1834 + CommentTime: ormItem.CommentTime.Unix() * 1000,
  1835 + Content: ormItem.CommentContent,
1967 } 1836 }
1968 - commItem.SourceType = chance.SourceType 1837 + commItem.SourceType = ormItem.SourceType
1969 rsp.List = append(rsp.List, commItem) 1838 rsp.List = append(rsp.List, commItem)
1970 } 1839 }
1971 agg.ValidChancePermission(header.UserId, header.CompanyId, rsp.List) 1840 agg.ValidChancePermission(header.UserId, header.CompanyId, rsp.List)
@@ -2105,7 +1974,8 @@ func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetail @@ -2105,7 +1974,8 @@ func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetail
2105 UpdateTime: chance.UpdateAt.Unix() * 1000, 1974 UpdateTime: chance.UpdateAt.Unix() * 1000,
2106 } 1975 }
2107 jsonUnmarshal(chance.SourceContent, &item.FormList) 1976 jsonUnmarshal(chance.SourceContent, &item.FormList)
2108 - jsonUnmarshal(chance.SelfChecks, &item.SelfChecks) 1977 + //jsonUnmarshal(chance.SelfChecks, &item.SelfChecks)
  1978 + item.SelfChecks = agg.GetChanceSelfChecks(chance)
2109 item.FormList = clearEmptyForm(item.FormList) 1979 item.FormList = clearEmptyForm(item.FormList)
2110 1980
2111 if chanceData, err = models.GetChanceDataByChanceId(chance.Id); err == nil { 1981 if chanceData, err = models.GetChanceDataByChanceId(chance.Id); err == nil {
@@ -2351,9 +2221,29 @@ func ChanceReviseDetail(header *protocol.RequestHeader, request *protocol.Chance @@ -2351,9 +2221,29 @@ func ChanceReviseDetail(header *protocol.RequestHeader, request *protocol.Chance
2351 func CheckQuestions(header *protocol.RequestHeader, request *protocol.CheckQuestionsRequest) (rsp *protocol.CheckQuestionsResponse, err error) { 2221 func CheckQuestions(header *protocol.RequestHeader, request *protocol.CheckQuestionsRequest) (rsp *protocol.CheckQuestionsResponse, err error) {
2352 var () 2222 var ()
2353 rsp = &protocol.CheckQuestionsResponse{} 2223 rsp = &protocol.CheckQuestionsResponse{}
  2224 + switch request.Type {
  2225 + case 0: //自查问题列表
2354 rsp.Questions, err = agg.GetCheckQuestionsByChanceId(header, request.ChanceId) 2226 rsp.Questions, err = agg.GetCheckQuestionsByChanceId(header, request.ChanceId)
2355 if err != nil { 2227 if err != nil {
2356 log.Error(err) 2228 log.Error(err)
  2229 + return
  2230 + }
  2231 + case 1: //筛选结果问题列表
  2232 + rsp.Questions, err = agg.GetCheckQuestionsByChanceCheckResult(header, request.ChanceId)
  2233 + if err == orm.ErrNoRows || len(rsp.Questions) == 0 {
  2234 + rsp.Questions, err = agg.GetCheckQuestionsByChanceId(header, request.ChanceId)
  2235 + if err != nil {
  2236 + log.Error(err)
  2237 + return
  2238 + }
  2239 + err = nil
  2240 + }
  2241 + for i := range rsp.Questions {
  2242 + rsp.Questions[i].CheckOptions = protocol.CheckOptionsApprove
  2243 + //if rsp.Questions[i].ParentId!=0{
  2244 + // rsp.Questions[i].Title= rsp.Questions[i].CheckItem
  2245 + //}
  2246 + }
2357 } 2247 }
2358 return 2248 return
2359 } 2249 }
  1 +package chance
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/orm"
  6 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
  7 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/idgen"
  8 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
  9 + "opp/internal/utils"
  10 + "opp/models"
  11 + "opp/protocol"
  12 + "opp/services/agg"
  13 + "strings"
  14 + "time"
  15 +)
  16 +
  17 +//SiftingPool 筛选池
  18 +func SiftingPool(header *protocol.RequestHeader, request *protocol.SiftingPoolRequest) (rsp *protocol.SiftingPoolResponse, err error) {
  19 + var (
  20 + ormItems []protocol.ChanceSiftItemOrm
  21 + )
  22 + rsp = &protocol.SiftingPoolResponse{}
  23 + rsp.List = make([]protocol.CommonListItem, 0)
  24 + //测试使用
  25 + if request.Uid != 0 {
  26 + header.UserId = request.Uid
  27 + }
  28 + if rsp.Total, err = models.GetSiftingChance(header.UserId, request.SubmitStatus, protocol.None, request.Offset(), request.PageSize, &ormItems); err != nil {
  29 + if err == orm.ErrNoRows {
  30 + err = nil
  31 + return
  32 + }
  33 + log.Error(err)
  34 + return
  35 + }
  36 + for i := 0; i < len(ormItems); i++ {
  37 + ormItem := ormItems[i]
  38 + commItem := agg.NewCommonListItem(header, ormItem.CommChanceItemOrm)
  39 + commItem.Chance.CreateTime = ormItem.ChanceApproveTime.Unix() * 1000
  40 + commItem.Chance.UpdateTime = 0
  41 + commItem.Chance.ApproveTime = 0
  42 + if request.SubmitStatus == protocol.Submited {
  43 + commItem.Chance.CreateTime = ormItem.SubmitCheckTime.Unix() * 1000
  44 + }
  45 +
  46 + //点赞评论数据
  47 + var chanceData = protocol.ChanceData{
  48 + PageViewTotal: ormItem.ViewTotal,
  49 + }
  50 + commItem.ChanceData = chanceData
  51 +
  52 + rsp.List = append(rsp.List, commItem)
  53 + }
  54 + return
  55 +}
  56 +
  57 +//筛选结果
  58 +func SiftingResults(header *protocol.RequestHeader, request *protocol.SiftingResultsRequest) (rsp *protocol.SiftingResultsResponse, err error) {
  59 + var (
  60 + ormItems []protocol.ChanceSiftResultOrm
  61 + )
  62 + rsp = &protocol.SiftingResultsResponse{}
  63 + rsp.List = make([]protocol.CommonListItem, 0)
  64 + //测试使用
  65 + if request.Uid != 0 {
  66 + header.UserId = request.Uid
  67 + }
  68 + if rsp.Total, err = models.GetSiftingResults(header.UserId, protocol.Submited, request.SiftedStatus, request.Offset(), request.PageSize, &ormItems); err != nil {
  69 + if err == orm.ErrNoRows {
  70 + err = nil
  71 + return
  72 + }
  73 + log.Error(err)
  74 + return
  75 + }
  76 + for i := 0; i < len(ormItems); i++ {
  77 + ormItem := ormItems[i]
  78 + commItem := agg.NewCommonListItem(header, ormItem.CommChanceItemOrm)
  79 + commItem.Chance.CreateTime = ormItem.CheckTime.Unix() * 1000
  80 + commItem.Chance.UpdateTime = 0
  81 + commItem.Chance.ApproveTime = 0
  82 +
  83 + //点赞评论数据
  84 + var chanceData = protocol.ChanceData{
  85 + PageViewTotal: ormItem.ViewTotal,
  86 + }
  87 + commItem.ChanceData = chanceData
  88 + rsp.List = append(rsp.List, commItem)
  89 + }
  90 + return
  91 +}
  92 +
  93 +//提交自查
  94 +func SubmitChecks(header *protocol.RequestHeader, request *protocol.SubmitChecksRequest) (rsp *protocol.SubmitChecksResponse, err error) {
  95 + var (
  96 + p *models.AuditFlowProcess
  97 + )
  98 + //测试
  99 + if request.Uid != 0 {
  100 + header.UserId = request.Uid
  101 + }
  102 + if err = request.SelfChecks.SetSelfChecksLevel1ByRule(); err != nil {
  103 + log.Error(err)
  104 + return
  105 + }
  106 + if _, result := CheckIsCommitAllCheck(request.ChanceId); result {
  107 + err = protocol.NewCustomMessage(1, "所有人均已提交,不允许修改自查内容")
  108 + return
  109 + }
  110 + if p, err = models.GetAuditorLatestAuditFlowProcess(request.ChanceId, header.UserId); err != nil {
  111 + log.Error(request.ChanceId, header.UserId, err)
  112 + if err == orm.ErrNoRows {
  113 + err = nil
  114 + }
  115 + return
  116 + }
  117 + rsp = &protocol.SubmitChecksResponse{}
  118 + o := orm.NewOrm()
  119 + o.Begin()
  120 + var (
  121 + DeleteAll = `delete from chance_check_result where chance_id =? and user_company_id=? `
  122 + UpdateCommitStatus = `update audit_flow_process set submit_check_status=? ,submit_check_time=now() where chance_id=? and id=?`
  123 + UpdateChanceCheckResultStatus = `update chance set check_result_status=?,check_result=? where id=?`
  124 + )
  125 + if err = utils.ExecuteSQLWithOrmer(o, DeleteAll, request.ChanceId, header.UserId); err != nil {
  126 + log.Error(err)
  127 + o.Rollback()
  128 + return
  129 + }
  130 + var groupIdx = -1
  131 + for i := range request.SelfChecks {
  132 + c := request.SelfChecks[i]
  133 + m := NewChanceCheckResult(c, request.ChanceId, header.UserId)
  134 + if groupIdx == -1 || request.SelfChecks[groupIdx].GroupId != request.SelfChecks[i].GroupId {
  135 + groupIdx = i
  136 + }
  137 + if c.Id == 0 {
  138 + m.CheckId = i + 1
  139 + m.CheckPid = int64(groupIdx + 1)
  140 + if groupIdx == i {
  141 + m.CheckPid = 0
  142 + }
  143 + } else {
  144 + m.CheckId = int(c.Id)
  145 + m.CheckPid = int64(c.ParentId)
  146 + }
  147 + if _, err = o.Insert(m); err != nil {
  148 + log.Error(err)
  149 + o.Rollback()
  150 + return
  151 + }
  152 + }
  153 + //更新审核人提交状态
  154 + if err = utils.ExecuteSQLWithOrmer(o, UpdateCommitStatus, protocol.Submited, request.ChanceId, p.Id); err != nil {
  155 + log.Error(err)
  156 + o.Rollback()
  157 + return
  158 + }
  159 + //插入一条数据
  160 + o.Commit()
  161 +
  162 + //更新机会筛选状态
  163 + if _, result := CheckIsCommitAllCheck(request.ChanceId); result {
  164 + var results []*models.ChanceCheckResult
  165 + if results, err = models.GetCheckResultsByChanceId(request.ChanceId); err != nil {
  166 + log.Error(err)
  167 + return
  168 + }
  169 + var checkResult = collectChanceCheckResultData(results)
  170 + if err = utils.ExecuteSQLWithOrmer(o, UpdateChanceCheckResultStatus, protocol.Waiting, common.AssertJson(checkResult), request.ChanceId); err != nil {
  171 + log.Error(err)
  172 + return
  173 + }
  174 + }
  175 + return
  176 +}
  177 +
  178 +func NewChanceCheckResult(c protocol.SelfCheck, chanceId int64, uid int64) *models.ChanceCheckResult {
  179 + //不是否的时候 不需要理由
  180 + if c.Answer != protocol.OptionNo {
  181 + c.Reason = ""
  182 + }
  183 + return &models.ChanceCheckResult{
  184 + Id: idgen.Next(),
  185 + ChanceId: chanceId,
  186 + GroupId: c.GroupId,
  187 + CheckItem: c.CheckItem,
  188 + Answer: c.Answer,
  189 + Reason: c.Reason,
  190 + UserCompanyId: uid,
  191 + CreateAt: time.Now(),
  192 + }
  193 +}
  194 +
  195 +//判断审核人筛选结果是否都已提交
  196 +func CheckIsCommitAllCheck(chanceId int64) (err error, result bool) {
  197 + var (
  198 + audits []*models.AuditFlowProcess
  199 + submiters []int64
  200 + )
  201 + result = false
  202 + if audits, err = models.GetChanceAllAuditors(chanceId); err != nil {
  203 + log.Error(err)
  204 + return
  205 + }
  206 + if submiters, err = models.GetCheckResultAllSubmitters(chanceId); err != nil {
  207 + log.Error(err)
  208 + return
  209 + }
  210 + if len(audits) == len(submiters) {
  211 + result = true
  212 + }
  213 + return
  214 +}
  215 +
  216 +type chanceCheckResultTotal struct {
  217 + GroupId int64
  218 + CheckItem string
  219 + CheckId int64
  220 + CheckPid int64
  221 + AnswerYes int
  222 + AnswerNo int
  223 + AnswerAny int
  224 + Child []*chanceCheckResultTotal
  225 +}
  226 +
  227 +//collectChanceCheckResultData 汇总机会自查内容筛选结果
  228 +func collectChanceCheckResultData(checkResultData []*models.ChanceCheckResult) protocol.SelfChecks {
  229 + checkResultMap := map[int]*chanceCheckResultTotal{}
  230 + checkResultSlice := []*chanceCheckResultTotal{}
  231 + for i := range checkResultData {
  232 + resultData := checkResultData[i]
  233 + answerYes := 0
  234 + answerNo := 0
  235 + answerAny := 0
  236 + switch resultData.Answer {
  237 + case "是":
  238 + answerYes++
  239 + case "否":
  240 + answerNo++
  241 + case "不清楚":
  242 + answerAny++
  243 + }
  244 + if _, ok := checkResultMap[resultData.CheckId]; !ok {
  245 + r := &chanceCheckResultTotal{
  246 + CheckId: int64(resultData.CheckId),
  247 + CheckPid: resultData.CheckPid,
  248 + CheckItem: resultData.CheckItem,
  249 + GroupId: resultData.GroupId,
  250 + AnswerYes: answerYes,
  251 + AnswerNo: answerNo,
  252 + AnswerAny: answerAny,
  253 + }
  254 + checkResultMap[resultData.CheckId] = r
  255 + checkResultSlice = append(checkResultSlice, r)
  256 + } else {
  257 + checkResultMap[resultData.CheckId].AnswerYes += answerYes
  258 + checkResultMap[resultData.CheckId].AnswerNo += answerNo
  259 + checkResultMap[resultData.CheckId].AnswerAny += answerAny
  260 + }
  261 + }
  262 + //构建层级关系
  263 + for i := range checkResultSlice {
  264 + if checkResultSlice[i].CheckPid == 0 {
  265 + continue
  266 + }
  267 + pid := int(checkResultSlice[i].CheckPid)
  268 + if _, ok := checkResultMap[pid]; ok {
  269 + checkResultMap[pid].Child = append(checkResultMap[pid].Child, checkResultSlice[i])
  270 + }
  271 + }
  272 + var selfCheckData []protocol.SelfCheck
  273 + for i := range checkResultSlice {
  274 + if checkResultSlice[i].CheckPid > 0 {
  275 + continue
  276 + }
  277 + dd := protocol.SelfCheck{
  278 + CheckItem: checkResultSlice[i].CheckItem,
  279 + GroupId: checkResultSlice[i].GroupId,
  280 + Id: checkResultSlice[i].CheckId,
  281 + ParentId: checkResultSlice[i].CheckPid,
  282 + }
  283 +
  284 + if checkResultSlice[i].AnswerNo > 0 {
  285 + dd.Answer = protocol.OptionNo
  286 + }
  287 + if checkResultSlice[i].AnswerYes > 0 && checkResultSlice[i].AnswerNo == 0 && checkResultSlice[i].AnswerAny == 0 {
  288 + dd.Answer = protocol.OptionYes
  289 + }
  290 + if checkResultSlice[i].AnswerNo == 0 && checkResultSlice[i].AnswerAny > 0 {
  291 + dd.Answer = protocol.OptionUncertain
  292 + }
  293 + selfCheckData = append(selfCheckData, dd)
  294 + for j := range checkResultSlice[i].Child {
  295 + child := checkResultSlice[i].Child[j]
  296 + dd := protocol.SelfCheck{
  297 + CheckItem: child.CheckItem,
  298 + GroupId: child.GroupId,
  299 + Id: child.CheckId,
  300 + ParentId: child.CheckPid,
  301 + }
  302 +
  303 + if child.AnswerNo > 0 {
  304 + dd.Answer = protocol.OptionNo
  305 + }
  306 + if child.AnswerYes > 0 && child.AnswerNo == 0 && child.AnswerAny == 0 {
  307 + dd.Answer = protocol.OptionYes
  308 + }
  309 + if child.AnswerNo == 0 && child.AnswerAny > 0 {
  310 + dd.Answer = protocol.OptionUncertain
  311 + }
  312 + selfCheckData = append(selfCheckData, dd)
  313 + }
  314 + }
  315 + return selfCheckData
  316 +}
  317 +
  318 +//筛选历史
  319 +func SiftingResultsItemHistory(header *protocol.RequestHeader, request *protocol.SiftingResultsItemHistoryRequest) (rsp *protocol.SiftingResultsItemHistoryResponse, err error) {
  320 + var (
  321 + checkResults []*models.ChanceCheckResult
  322 + ids []int64
  323 + )
  324 + rsp = &protocol.SiftingResultsItemHistoryResponse{}
  325 + if checkResults, err = models.GetCheckResultsByChanceId(request.ChanceId); err != nil {
  326 + if err == orm.ErrNoRows {
  327 + err = nil
  328 + return
  329 + }
  330 + log.Error(err)
  331 + return
  332 + }
  333 + rsp.SiftingResults = NewSiftingResults(checkResults)
  334 + if ids, err = models.GetCheckResultAllSubmitters(request.ChanceId); err == nil {
  335 + rsp.TotalSubmitters = len(ids)
  336 + }
  337 + for i := range checkResults {
  338 + item := checkResults[i]
  339 + rsp.SiftingResults.AddStatic(item.CheckId, item.Answer)
  340 + }
  341 + rsp.SiftingResults.SetSelfChecksLevel1ByRule()
  342 + return
  343 +}
  344 +
  345 +//新建筛选结果列表
  346 +func NewSiftingResults(checkResults []*models.ChanceCheckResult) protocol.SiftingResults {
  347 + var rsp []protocol.SiftingResult
  348 + var maps = make(map[int]*protocol.SiftingResult, 0)
  349 + var ids []int
  350 + for i := range checkResults {
  351 + r := checkResults[i]
  352 + var tmp *protocol.SiftingResult
  353 + var ok bool
  354 + new := &protocol.SiftingResult{
  355 + CheckId: r.CheckId,
  356 + CheckParentId: r.CheckPid,
  357 + CheckItem: r.CheckItem,
  358 + Title: r.CheckItem,
  359 + SubSiftingResults: make([]protocol.SiftingResult, 0),
  360 + }
  361 + if tmp, ok = maps[new.CheckId]; !ok && new.CheckParentId == 0 {
  362 + new.Title = fmt.Sprintf("%v、%v", len(ids)+1, new.CheckItem) //父级标题 1、素食为主 子级标题:素食为主
  363 + maps[new.CheckId] = new
  364 + ids = append(ids, new.CheckId)
  365 + }
  366 + //已存在的向子级增加一条记录
  367 + if tmp, ok = maps[int(new.CheckParentId)]; ok {
  368 + var exists bool = false
  369 + for i := range tmp.SubSiftingResults {
  370 + if tmp.SubSiftingResults[i].CheckId == new.CheckId {
  371 + exists = true
  372 + break
  373 + }
  374 + }
  375 + if !exists {
  376 + tmp.SubSiftingResults = append(tmp.SubSiftingResults, *new)
  377 + }
  378 + }
  379 + }
  380 + for i := range ids {
  381 + if v, ok := maps[ids[i]]; ok {
  382 + rsp = append(rsp, *v)
  383 + }
  384 + }
  385 + return rsp
  386 +}
  387 +
  388 +//筛选历史详情
  389 +func SiftingResultsItemDetail(header *protocol.RequestHeader, request *protocol.SiftingResultsItemDetailRequest) (rsp *protocol.SiftingResultsItemDetailResponse, err error) {
  390 + var (
  391 + checkResults []*models.ChanceCheckResult
  392 + sortList []string = []string{protocol.OptionYes, protocol.OptionNo, protocol.OptionUncertain}
  393 + )
  394 + rsp = &protocol.SiftingResultsItemDetailResponse{}
  395 + if checkResults, err = models.GetCheckResultsByCheckId(request.ChanceId, request.CheckId); err != nil {
  396 + if err == orm.ErrNoRows {
  397 + err = nil
  398 + return
  399 + }
  400 + log.Error(err)
  401 + return
  402 + }
  403 + var resultsMap = make(map[string]protocol.SiftingResultDetail)
  404 + for i := range checkResults {
  405 + checkResult := checkResults[i]
  406 + answer := strings.TrimSpace(checkResult.Answer)
  407 + if len(answer) == 0 {
  408 + continue
  409 + }
  410 +
  411 + /*提交人信息*/
  412 + var provider *protocol.BaseUserInfo
  413 + if provider, err = agg.GetUserBaseInfo(checkResult.UserCompanyId, header.CompanyId); err != nil {
  414 + log.Error(err)
  415 + return
  416 + }
  417 + commitItem := protocol.SiftingCommitItem{
  418 + Provider: provider,
  419 + Reason: checkResult.Reason,
  420 + }
  421 +
  422 + //追加到Map列表
  423 + if v, ok := resultsMap[answer]; ok {
  424 + v.Items = append(v.Items, commitItem)
  425 + resultsMap[answer] = v
  426 + } else {
  427 + resultsMap[answer] = protocol.SiftingResultDetail{
  428 + Option: answer,
  429 + Items: []protocol.SiftingCommitItem{commitItem},
  430 + }
  431 + }
  432 + }
  433 + for i := range sortList {
  434 + //返回数据
  435 + if v, ok := resultsMap[sortList[i]]; ok {
  436 + v.TotalSubmitters = len(v.Items)
  437 + rsp.SiftingResultDetails = append(rsp.SiftingResultDetails, v)
  438 + rsp.TotalSubmitters += len(v.Items)
  439 + }
  440 + }
  441 + return
  442 +}
  1 +package chance
  2 +
  3 +import (
  4 + "opp/protocol"
  5 + "testing"
  6 +)
  7 +
  8 +type A []int
  9 +
  10 +func (a A) Change() {
  11 + if len(a) == 0 {
  12 + return
  13 + }
  14 + a[0] = 5
  15 +}
  16 +
  17 +func TestArrayStruct(t *testing.T) {
  18 + var a = A([]int{1, 2})
  19 + //a.Change()
  20 +
  21 + var b = a
  22 + b.Change()
  23 + t.Log(a)
  24 +}
  25 +
  26 +func TestSelfChecks(t *testing.T) {
  27 + var selfs = []protocol.SelfCheck{
  28 + {
  29 + GroupId: 1,
  30 + CheckItem: "1",
  31 + },
  32 + {
  33 + GroupId: 1,
  34 + Answer: "否",
  35 + },
  36 + {
  37 + GroupId: 1,
  38 + Answer: "是",
  39 + },
  40 + {
  41 + GroupId: 1,
  42 + Answer: "不清楚",
  43 + },
  44 + {
  45 + GroupId: 2,
  46 + CheckItem: "2",
  47 + },
  48 + {
  49 + GroupId: 2,
  50 + Answer: "否",
  51 + },
  52 + {
  53 + GroupId: 2,
  54 + Answer: "否",
  55 + },
  56 + {
  57 + GroupId: 2,
  58 + Answer: "不清楚",
  59 + },
  60 + }
  61 + var s = protocol.SelfChecks(selfs)
  62 + s.SetSelfChecksLevel1ByRule()
  63 + t.Log(s[0], s[4])
  64 +}
@@ -303,11 +303,10 @@ func MsgCompanyNotice(header *protocol.RequestHeader, request *protocol.MsgCompa @@ -303,11 +303,10 @@ func MsgCompanyNotice(header *protocol.RequestHeader, request *protocol.MsgCompa
303 //消息中心-机会审核消息 303 //消息中心-机会审核消息
304 func MsgChanceApprove(header *protocol.RequestHeader, request *protocol.MsgChanceApproveRequest) (rsp *protocol.MsgChanceApproveResponse, err error) { 304 func MsgChanceApprove(header *protocol.RequestHeader, request *protocol.MsgChanceApproveRequest) (rsp *protocol.MsgChanceApproveResponse, err error) {
305 var ( 305 var (
306 - myChances []protocol.MsgChanceApproveItemOrm 306 + ormItems []protocol.MsgChanceApproveItemOrm
307 total int 307 total int
308 - provider *protocol.BaseUserInfo  
309 ) 308 )
310 - if total, err = models.GetChanceMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeAudit, &myChances); err != nil { 309 + if total, err = models.GetChanceMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeAudit, &ormItems); err != nil {
311 if err == orm.ErrNoRows { 310 if err == orm.ErrNoRows {
312 err = nil 311 err = nil
313 return 312 return
@@ -317,49 +316,18 @@ func MsgChanceApprove(header *protocol.RequestHeader, request *protocol.MsgChanc @@ -317,49 +316,18 @@ func MsgChanceApprove(header *protocol.RequestHeader, request *protocol.MsgChanc
317 } 316 }
318 rsp = &protocol.MsgChanceApproveResponse{Total: total} 317 rsp = &protocol.MsgChanceApproveResponse{Total: total}
319 rsp.List = make([]protocol.MsgCommonListItem, 0) 318 rsp.List = make([]protocol.MsgCommonListItem, 0)
320 - for i := 0; i < len(myChances); i++ {  
321 - chance := myChances[i] 319 + for i := 0; i < len(ormItems); i++ {
  320 + ormItem := ormItems[i]
322 commItem := protocol.MsgCommonListItem{} 321 commItem := protocol.MsgCommonListItem{}
323 - commItem.ReviewStatus = chance.ReviewStatus  
324 - if len(chance.SourceContent) == 0 { //机会删除  
325 - commItem.ChanceStatus = protocol.ChanceStatusDelete  
326 - } else if chance.ChanceEnableStatus == 0 { //机会关闭  
327 - commItem.ChanceStatus = protocol.ChanceStatusDelete  
328 - }  
329 - if chance.Status == models.ChanceStatusClose {  
330 - commItem.ChanceStatus = protocol.ChanceStatusClose  
331 - }  
332 - if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {  
333 - commItem.ChanceStatus = protocol.ChanceStatusDelete  
334 - log.Error(err)  
335 - continue  
336 - } else {  
337 - item := protocol.ChanceItem{  
338 - Id: chance.ChanceId,  
339 - Provider: provider,  
340 - CreateTime: chance.CreateTime.Unix() * 1000,  
341 - }  
342 - utils.JsonUnmarshal(chance.SourceContent, &item.FormList)  
343 - item.FormList = agg.ClearEmptyForm(item.FormList)  
344 - utils.JsonUnmarshal(chance.Images, &item.Pictures)  
345 - utils.JsonUnmarshal(chance.Voices, &item.Speechs)  
346 - utils.JsonUnmarshal(chance.Videos, &item.Videos)  
347 - commItem.Chance = item  
348 - } 322 + commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem.CommChanceItemOrm)
  323 + commItem.ReviewStatus = ormItem.ReviewStatus
349 324
350 - //if chance.ReviewStatus == protocol.ReviewStatusPass {  
351 - // var approveData *protocol.ApproveData  
352 - // utils.JsonUnmarshal(chance.ApproveData, &approveData)  
353 - // if approveData != nil {  
354 - // commItem.Score = approveData.Score  
355 - // }  
356 - //}  
357 - commItem.MsgId = chance.Id  
358 - commItem.MsgTime = chance.MsgTime.Unix() * 1000 325 + commItem.MsgId = ormItem.Id
  326 + commItem.MsgTime = ormItem.MsgTime.Unix() * 1000
359 //审核完有审核数据 327 //审核完有审核数据
360 - commItem.Message = chance.Message  
361 - commItem.IsRead = chance.IsRead == 1  
362 - commItem.ChanceId = chance.ChanceId 328 + commItem.Message = ormItem.Message
  329 + commItem.IsRead = ormItem.IsRead == 1
  330 + commItem.ChanceId = ormItem.ChanceId
363 rsp.List = append(rsp.List, commItem) 331 rsp.List = append(rsp.List, commItem)
364 } 332 }
365 return 333 return
@@ -368,11 +336,10 @@ func MsgChanceApprove(header *protocol.RequestHeader, request *protocol.MsgChanc @@ -368,11 +336,10 @@ func MsgChanceApprove(header *protocol.RequestHeader, request *protocol.MsgChanc
368 // 消息中心-我提交的 336 // 消息中心-我提交的
369 func MsgChanceSubmit(header *protocol.RequestHeader, request *protocol.MsgChanceSubmitRequest) (rsp *protocol.MsgChanceSubmitResponse, err error) { 337 func MsgChanceSubmit(header *protocol.RequestHeader, request *protocol.MsgChanceSubmitRequest) (rsp *protocol.MsgChanceSubmitResponse, err error) {
370 var ( 338 var (
371 - myChances []protocol.MsgChanceApproveItemOrm  
372 - total int  
373 - provider *protocol.BaseUserInfo 339 + ormItems []protocol.MsgChanceApproveItemOrm
374 ) 340 )
375 - if total, err = models.GetChanceMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeAuditBy, &myChances); err != nil { 341 + rsp = &protocol.MsgChanceSubmitResponse{List: make([]protocol.MsgCommonListItem, 0)}
  342 + if rsp.Total, err = models.GetChanceMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeAuditBy, &ormItems); err != nil {
376 if err == orm.ErrNoRows { 343 if err == orm.ErrNoRows {
377 err = nil 344 err = nil
378 return 345 return
@@ -380,62 +347,33 @@ func MsgChanceSubmit(header *protocol.RequestHeader, request *protocol.MsgChance @@ -380,62 +347,33 @@ func MsgChanceSubmit(header *protocol.RequestHeader, request *protocol.MsgChance
380 log.Error(err) 347 log.Error(err)
381 return 348 return
382 } 349 }
383 - rsp = &protocol.MsgChanceSubmitResponse{Total: total}  
384 - rsp.List = make([]protocol.MsgCommonListItem, 0)  
385 - for i := 0; i < len(myChances); i++ {  
386 - chance := myChances[i] 350 +
  351 + for i := 0; i < len(ormItems); i++ {
  352 + ormItem := ormItems[i]
387 commItem := protocol.MsgCommonListItem{} 353 commItem := protocol.MsgCommonListItem{}
388 - commItem.ReviewStatus = chance.ReviewStatus  
389 - if len(chance.SourceContent) == 0 { //机会删除  
390 - commItem.ChanceStatus = protocol.ChanceStatusDelete  
391 - } else if chance.ChanceEnableStatus == 0 { //机会关闭  
392 - commItem.ChanceStatus = protocol.ChanceStatusDelete  
393 - }  
394 - if chance.Status == models.ChanceStatusClose {  
395 - commItem.ChanceStatus = protocol.ChanceStatusClose  
396 - }  
397 - approveUserId := chance.ChanceUserId  
398 - if chance.SenderUserId != 0 {  
399 - approveUserId = chance.SenderUserId  
400 - }  
401 - if provider, err = agg.GetUserBaseInfo(approveUserId, header.CompanyId); err != nil {  
402 - commItem.ChanceStatus = protocol.ChanceStatusDelete  
403 - log.Error(err)  
404 - continue  
405 - } else {  
406 - item := protocol.ChanceItem{  
407 - Id: chance.ChanceId,  
408 - Provider: provider,  
409 - CreateTime: chance.CreateTime.Unix() * 1000,  
410 - }  
411 - utils.JsonUnmarshal(chance.SourceContent, &item.FormList)  
412 - item.FormList = agg.ClearEmptyForm(item.FormList)  
413 - utils.JsonUnmarshal(chance.Images, &item.Pictures)  
414 - utils.JsonUnmarshal(chance.Voices, &item.Speechs)  
415 - utils.JsonUnmarshal(chance.Videos, &item.Videos)  
416 - commItem.Chance = item 354 +
  355 + //注:此处是审核人的用户信息
  356 + if ormItem.SenderUserId != 0 {
  357 + ormItem.CommChanceItemOrm.ChanceUserId = ormItem.SenderUserId
417 } 358 }
  359 + commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem.CommChanceItemOrm)
  360 + commItem.ReviewStatus = ormItem.ReviewStatus
418 361
419 - //if chance.ReviewStatus == protocol.ReviewStatusPass {  
420 - // var approveData *protocol.ApproveData  
421 - // utils.JsonUnmarshal(chance.ApproveData, &approveData)  
422 - // if approveData != nil {  
423 - // commItem.Score = approveData.Score  
424 - // }  
425 - //}  
426 - if len(chance.Data) > 0 && chance.ReviewStatus != protocol.ReviewStatusReturn { //获取评分 && chance.ReviewStatus == protocol.ReviewStatusPass 362 + //审核数据
  363 + if len(ormItem.Data) > 0 && ormItem.ReviewStatus != protocol.ReviewStatusReturn { //获取评分 && chance.ReviewStatus == protocol.ReviewStatusPass
427 var msgData *protocol.MsgData 364 var msgData *protocol.MsgData
428 - utils.JsonUnmarshal(chance.Data, &msgData) 365 + utils.JsonUnmarshal(ormItem.Data, &msgData)
429 commItem.Score = msgData.Score 366 commItem.Score = msgData.Score
430 } 367 }
431 - commItem.IsRead = chance.IsRead == 1  
432 - //审核完有审核数据  
433 - commItem.Message = chance.Message  
434 - commItem.MsgId = chance.Id  
435 - commItem.MsgTime = chance.MsgTime.Unix() * 1000  
436 - commItem.ChanceId = chance.ChanceId  
437 - if commItem.ChanceId == 0 && chance.SourceId > 0 {  
438 - commItem.ChanceId = chance.SourceId 368 +
  369 + //消息基础数据
  370 + commItem.IsRead = ormItem.IsRead == 1
  371 + commItem.Message = ormItem.Message
  372 + commItem.MsgId = ormItem.Id
  373 + commItem.MsgTime = ormItem.MsgTime.Unix() * 1000
  374 + commItem.ChanceId = ormItem.ChanceId
  375 + if commItem.ChanceId == 0 && ormItem.SourceId > 0 {
  376 + commItem.ChanceId = ormItem.SourceId
439 } 377 }
440 rsp.List = append(rsp.List, commItem) //非指针 append对象完 再修改数据也是无效 378 rsp.List = append(rsp.List, commItem) //非指针 append对象完 再修改数据也是无效
441 } 379 }
@@ -445,11 +383,11 @@ func MsgChanceSubmit(header *protocol.RequestHeader, request *protocol.MsgChance @@ -445,11 +383,11 @@ func MsgChanceSubmit(header *protocol.RequestHeader, request *protocol.MsgChance
445 // 消息中心-互动消息.评论 383 // 消息中心-互动消息.评论
446 func MsgChanceComment(header *protocol.RequestHeader, request *protocol.MsgChanceCommentRequest) (rsp *protocol.MsgChanceCommentResponse, err error) { 384 func MsgChanceComment(header *protocol.RequestHeader, request *protocol.MsgChanceCommentRequest) (rsp *protocol.MsgChanceCommentResponse, err error) {
447 var ( 385 var (
448 - myChances []protocol.ChanceCommentItemOrm 386 + ormItems []protocol.ChanceCommentItemOrm
449 total int 387 total int
450 provider *protocol.BaseUserInfo 388 provider *protocol.BaseUserInfo
451 ) 389 )
452 - if total, err = models.GetChanceCommentMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeComment, &myChances); err != nil { 390 + if total, err = models.GetChanceCommentMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeComment, &ormItems); err != nil {
453 if err == orm.ErrNoRows { 391 if err == orm.ErrNoRows {
454 err = nil 392 err = nil
455 return 393 return
@@ -459,66 +397,46 @@ func MsgChanceComment(header *protocol.RequestHeader, request *protocol.MsgChanc @@ -459,66 +397,46 @@ func MsgChanceComment(header *protocol.RequestHeader, request *protocol.MsgChanc
459 } 397 }
460 rsp = &protocol.MsgChanceCommentResponse{Total: total} 398 rsp = &protocol.MsgChanceCommentResponse{Total: total}
461 rsp.List = make([]protocol.MsgCommonListItem, 0) 399 rsp.List = make([]protocol.MsgCommonListItem, 0)
462 - for i := 0; i < len(myChances); i++ {  
463 - chance := myChances[i] 400 + for i := 0; i < len(ormItems); i++ {
  401 + ormItem := ormItems[i]
464 commItem := protocol.MsgCommonListItem{} 402 commItem := protocol.MsgCommonListItem{}
465 - if chance.SourceType == protocol.SourceTypeChance {  
466 - commItem.ReviewStatus = chance.ReviewStatus  
467 - if len(chance.SourceContent) == 0 { //机会删除  
468 - commItem.ChanceStatus = protocol.ChanceStatusDelete  
469 - } else if chance.ChanceEnableStatus == 0 { //机会关闭  
470 - commItem.ChanceStatus = protocol.ChanceStatusClose  
471 - }  
472 - if chance.Status == models.ChanceStatusClose {  
473 - commItem.ChanceStatus = protocol.ChanceStatusClose  
474 - }  
475 - if chance.ChanceUserId > 0 {  
476 - if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {  
477 - commItem.ChanceStatus = protocol.ChanceStatusDelete  
478 - log.Error(err)  
479 - //return  
480 - } else {  
481 - item := protocol.ChanceItem{  
482 - Id: chance.SourceId,  
483 - Provider: provider,  
484 - CreateTime: chance.CreateTime.Unix() * 1000,  
485 - }  
486 - utils.JsonUnmarshal(chance.SourceContent, &item.FormList)  
487 - item.FormList = protocol.ClearEmptyForm(item.FormList)  
488 - utils.JsonUnmarshal(chance.Images, &item.Pictures)  
489 - utils.JsonUnmarshal(chance.Voices, &item.Speechs)  
490 - utils.JsonUnmarshal(chance.Videos, &item.Videos)  
491 - commItem.Chance = item  
492 - } 403 + if ormItem.SourceType == protocol.SourceTypeChance {
  404 + commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem.CommChanceItemOrm)
  405 + commItem.ReviewStatus = ormItem.ReviewStatus
493 } 406 }
494 - commItem.ReviewStatus = chance.ReviewStatus  
495 - }  
496 - if chance.SourceType == protocol.SourceTypeComment {  
497 - if provider, err = agg.GetUserBaseInfo(chance.CommentedUserId, header.CompanyId); err != nil { 407 +
  408 + //被评论内容
  409 + if ormItem.SourceType == protocol.SourceTypeComment {
  410 + if provider, err = agg.GetUserBaseInfo(ormItem.CommentedUserId, header.CompanyId); err != nil {
498 commItem.ChanceStatus = protocol.ChanceStatusDelete 411 commItem.ChanceStatus = protocol.ChanceStatusDelete
499 log.Error(err) 412 log.Error(err)
500 //return 413 //return
501 } 414 }
502 commItem.CommentedData = protocol.CommentData{ 415 commItem.CommentedData = protocol.CommentData{
503 - Id: chance.SourceId,  
504 - Content: chance.CommentedContent,  
505 - CommentTime: chance.CommentedTime.Unix() * 1000, 416 + Id: ormItem.SourceId,
  417 + Content: ormItem.CommentedContent,
  418 + CommentTime: ormItem.CommentedTime.Unix() * 1000,
506 Provider: provider, 419 Provider: provider,
507 } 420 }
508 } 421 }
  422 +
  423 + //评论内容
509 comment := protocol.CommentData{ 424 comment := protocol.CommentData{
510 - Id: chance.CommentId,  
511 - CommentTime: chance.CommentTime.Unix() * 1000,  
512 - Content: chance.CommentContent, 425 + Id: ormItem.CommentId,
  426 + CommentTime: ormItem.CommentTime.Unix() * 1000,
  427 + Content: ormItem.CommentContent,
513 //Provider: provider, 428 //Provider: provider,
514 } 429 }
515 - comment.Provider, _ = agg.GetUserBaseInfo(chance.SenderUserId, header.CompanyId) 430 + comment.Provider, _ = agg.GetUserBaseInfo(ormItem.SenderUserId, header.CompanyId)
516 commItem.CommentData = comment 431 commItem.CommentData = comment
517 - commItem.IsRead = chance.IsRead == 1  
518 - commItem.SourceType = chance.SourceType  
519 - commItem.MsgId = chance.CommentId  
520 - commItem.MsgTime = chance.CommentTime.Unix() * 1000  
521 - commItem.ChanceId = chance.ChanceId 432 +
  433 + //消息基础内容
  434 + commItem.IsRead = ormItem.IsRead == 1
  435 + commItem.SourceType = ormItem.SourceType
  436 + commItem.MsgId = ormItem.CommentId
  437 + commItem.MsgTime = ormItem.CommentTime.Unix() * 1000
  438 + commItem.ChanceId = ormItem.ChanceId
  439 +
522 rsp.List = append(rsp.List, commItem) 440 rsp.List = append(rsp.List, commItem)
523 } 441 }
524 return 442 return
@@ -527,11 +445,11 @@ func MsgChanceComment(header *protocol.RequestHeader, request *protocol.MsgChanc @@ -527,11 +445,11 @@ func MsgChanceComment(header *protocol.RequestHeader, request *protocol.MsgChanc
527 //消息中心-互动消息.点赞 445 //消息中心-互动消息.点赞
528 func MsgChanceThumbUp(header *protocol.RequestHeader, request *protocol.MsgChanceThumbUpRequest) (rsp *protocol.MsgChanceThumbUpResponse, err error) { 446 func MsgChanceThumbUp(header *protocol.RequestHeader, request *protocol.MsgChanceThumbUpRequest) (rsp *protocol.MsgChanceThumbUpResponse, err error) {
529 var ( 447 var (
530 - myChances []protocol.ChanceCommentItemOrm 448 + ormItems []protocol.ChanceCommentItemOrm
531 total int 449 total int
532 provider *protocol.BaseUserInfo 450 provider *protocol.BaseUserInfo
533 ) 451 )
534 - if total, err = models.GetChanceCommentMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeThumbUp, &myChances); err != nil { 452 + if total, err = models.GetChanceCommentMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeThumbUp, &ormItems); err != nil {
535 if err == orm.ErrNoRows { 453 if err == orm.ErrNoRows {
536 err = nil 454 err = nil
537 return 455 return
@@ -541,65 +459,44 @@ func MsgChanceThumbUp(header *protocol.RequestHeader, request *protocol.MsgChanc @@ -541,65 +459,44 @@ func MsgChanceThumbUp(header *protocol.RequestHeader, request *protocol.MsgChanc
541 } 459 }
542 rsp = &protocol.MsgChanceThumbUpResponse{Total: total} 460 rsp = &protocol.MsgChanceThumbUpResponse{Total: total}
543 rsp.List = make([]protocol.MsgCommonListItem, 0) 461 rsp.List = make([]protocol.MsgCommonListItem, 0)
544 - for i := 0; i < len(myChances); i++ {  
545 - chance := myChances[i] 462 + for i := 0; i < len(ormItems); i++ {
  463 + ormItem := ormItems[i]
546 commItem := protocol.MsgCommonListItem{} 464 commItem := protocol.MsgCommonListItem{}
547 - if chance.SourceType == protocol.SourceTypeChance {  
548 - commItem.ReviewStatus = chance.ReviewStatus  
549 - if len(chance.SourceContent) == 0 { //机会删除  
550 - commItem.ChanceStatus = protocol.ChanceStatusDelete  
551 - } else if chance.ChanceEnableStatus == 0 { //机会关闭  
552 - commItem.ChanceStatus = protocol.ChanceStatusClose  
553 - }  
554 - if chance.Status == models.ChanceStatusClose {  
555 - commItem.ChanceStatus = protocol.ChanceStatusClose  
556 - }  
557 - if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {  
558 - commItem.ChanceStatus = protocol.ChanceStatusDelete  
559 - log.Error(err)  
560 - //return  
561 - } else {  
562 - item := protocol.ChanceItem{  
563 - Id: chance.SourceId,  
564 - Provider: provider,  
565 - CreateTime: chance.CreateTime.Unix() * 1000,  
566 - }  
567 - utils.JsonUnmarshal(chance.SourceContent, &item.FormList)  
568 - item.FormList = protocol.ClearEmptyForm(item.FormList)  
569 - utils.JsonUnmarshal(chance.Images, &item.Pictures)  
570 - utils.JsonUnmarshal(chance.Voices, &item.Speechs)  
571 - utils.JsonUnmarshal(chance.Videos, &item.Videos)  
572 - commItem.Chance = item  
573 - }  
574 - commItem.ReviewStatus = chance.ReviewStatus 465 + if ormItem.SourceType == protocol.SourceTypeChance {
  466 + commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem.CommChanceItemOrm)
  467 + commItem.ReviewStatus = ormItem.ReviewStatus
575 } 468 }
576 - if chance.SourceType == protocol.SourceTypeComment {  
577 - if provider, err = agg.GetUserBaseInfo(chance.CommentedUserId, header.CompanyId); err != nil { 469 +
  470 + //点赞评论的内容
  471 + if ormItem.SourceType == protocol.SourceTypeComment {
  472 + if provider, err = agg.GetUserBaseInfo(ormItem.CommentedUserId, header.CompanyId); err != nil {
578 commItem.ChanceStatus = protocol.ChanceStatusDelete 473 commItem.ChanceStatus = protocol.ChanceStatusDelete
579 log.Error(err) 474 log.Error(err)
580 //return 475 //return
581 } 476 }
582 commItem.CommentedData = protocol.CommentData{ 477 commItem.CommentedData = protocol.CommentData{
583 - Id: chance.SourceId,  
584 - Content: chance.CommentedContent,  
585 - CommentTime: chance.CommentedTime.Unix() * 1000, 478 + Id: ormItem.SourceId,
  479 + Content: ormItem.CommentedContent,
  480 + CommentTime: ormItem.CommentedTime.Unix() * 1000,
586 Provider: provider, 481 Provider: provider,
587 } 482 }
588 } 483 }
589 - 484 + //点赞数据
590 thumb := protocol.ThumbUpData{ 485 thumb := protocol.ThumbUpData{
591 - Id: chance.CommentId,  
592 - ThumbUpTime: chance.CommentTime.Unix() * 1000,  
593 - Content: chance.CommentContent, 486 + Id: ormItem.CommentId,
  487 + ThumbUpTime: ormItem.CommentTime.Unix() * 1000,
  488 + Content: ormItem.CommentContent,
594 //Provider: provider, 489 //Provider: provider,
595 } 490 }
596 - thumb.Provider, _ = agg.GetUserBaseInfo(chance.SenderUserId, header.CompanyId) 491 + thumb.Provider, _ = agg.GetUserBaseInfo(ormItem.SenderUserId, header.CompanyId)
597 commItem.ThumbUpData = thumb 492 commItem.ThumbUpData = thumb
598 - commItem.IsRead = chance.IsRead == 1  
599 - commItem.SourceType = chance.SourceType  
600 - commItem.MsgId = chance.CommentId  
601 - commItem.MsgTime = chance.CommentTime.Unix() * 1000  
602 - commItem.ChanceId = chance.ChanceId 493 +
  494 + //消息基础数据
  495 + commItem.IsRead = ormItem.IsRead == 1
  496 + commItem.SourceType = ormItem.SourceType
  497 + commItem.MsgId = ormItem.CommentId
  498 + commItem.MsgTime = ormItem.CommentTime.Unix() * 1000
  499 + commItem.ChanceId = ormItem.ChanceId
603 rsp.List = append(rsp.List, commItem) 500 rsp.List = append(rsp.List, commItem)
604 } 501 }
605 return 502 return
@@ -145,6 +145,25 @@ func CreateUploadVideo(header *protocol.RequestHeader, request *aliyun.CreateUpl @@ -145,6 +145,25 @@ func CreateUploadVideo(header *protocol.RequestHeader, request *aliyun.CreateUpl
145 return 145 return
146 } 146 }
147 rsp, err = aliyun.CreateUploadVideo(client, request) 147 rsp, err = aliyun.CreateUploadVideo(client, request)
  148 + if err != nil {
  149 + log.Error(err)
  150 + }
  151 + return
  152 +}
  153 +
  154 +//创建视频上传凭证
  155 +func RefreshUploadVideo(header *protocol.RequestHeader, request *aliyun.RefreshUploadVideoRequest) (rsp *aliyun.RefreshUploadVideoResponse, err error) {
  156 + var ()
  157 + client, e := aliyun.DefaultVodClient()
  158 + if e != nil {
  159 + log.Error(e)
  160 + err = e
  161 + return
  162 + }
  163 + rsp, err = aliyun.RefreshUploadVideo(client, request)
  164 + if err != nil {
  165 + log.Error(err)
  166 + }
148 return 167 return
149 } 168 }
150 169
@@ -157,6 +176,9 @@ func CreateUploadImage(header *protocol.RequestHeader, request *aliyun.CreateUpl @@ -157,6 +176,9 @@ func CreateUploadImage(header *protocol.RequestHeader, request *aliyun.CreateUpl
157 err = e 176 err = e
158 return 177 return
159 } 178 }
  179 + if len(request.FileName) == 0 {
  180 + request.FileName = aliyun.DefaultImageFileName
  181 + }
160 rsp, err = aliyun.CreateUploadImage(client, request) 182 rsp, err = aliyun.CreateUploadImage(client, request)
161 if err != nil { 183 if err != nil {
162 log.Error(err) 184 log.Error(err)