作者 yangfu

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

... ... @@ -286,7 +286,7 @@ func (this *ChanceController) ChanceSubmit() {
msg = m
return
}
if e := request.SelfChecks.Valid(); e != nil {
if e := request.SelfChecks.SetSelfChecksLevel1ByRule(); e != nil {
log.Error(e)
msg = protocol.NewReturnResponse(nil, e)
return
... ... @@ -312,7 +312,7 @@ func (this *ChanceController) ChanceUpdate() {
msg = m
return
}
if e := request.SelfChecks.Valid(); e != nil {
if e := request.SelfChecks.SetSelfChecksLevel1ByRule(); e != nil {
log.Error(e)
msg = protocol.NewReturnResponse(nil, e)
return
... ... @@ -449,7 +449,7 @@ func (this *ChanceController) ChanceApprove() {
return
}
}
if e := request.SelfChecks.Valid(); e != nil {
if e := request.SelfChecks.SetSelfChecksLevel1ByRule(); e != nil {
log.Error(e)
msg = protocol.NewReturnResponse(nil, e)
return
... ... @@ -668,3 +668,112 @@ func (this *ChanceController) CheckQuestions() {
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.CheckQuestions(header, request))
}
//SiftingPool 筛选池
//@router /siftingPool [post]
func (this *ChanceController) SiftingPool() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.SiftingPoolRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
if !(request.SubmitStatus == protocol.Submiting || request.SubmitStatus == protocol.Submited) {
msg = protocol.BadRequestParamWithMessage(2, "obj.SubmitStatus must in (0,1)")
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.SiftingPool(header, request))
}
//SiftingResults 筛选结果
//@router /siftingResults [post]
func (this *ChanceController) SiftingResults() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.SiftingResultsRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.SiftingResults(header, request))
}
//SubmitChecks 提交自查
//@router /submitSiftingResult [post]
func (this *ChanceController) SubmitChecks() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.SubmitChecksRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.SubmitChecks(header, request))
}
//SiftingResultsItemHistory 筛选历史
//@router /siftingResults/itemHistory [post]
func (this *ChanceController) SiftingResultsItemHistory() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.SiftingResultsItemHistoryRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.SiftingResultsItemHistory(header, request))
}
//SiftingResultsItemDetail 筛选历史详情
//@router /siftingResults/itemDetail [post]
func (this *ChanceController) SiftingResultsItemDetail() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.SiftingResultsItemDetailRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.SiftingResultsItemDetail(header, request))
}
... ...
... ... @@ -30,10 +30,34 @@ func (this *VodController) CreateUploadVideo() {
msg = m
return
}
if len(request.FileName) == 0 {
request.FileName = aliyun.DefaultVideoFileName
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(upload.CreateUploadVideo(header, request))
}
//刷新视频上传凭证 RefreshUploadVideo
// @router /refreshUploadVideo [post]
func (this *VodController) RefreshUploadVideo() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *aliyun.RefreshUploadVideoRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(upload.RefreshUploadVideo(header, request))
}
//创建图片上传凭证 CreateUploadImage
// @router /createUploadImage [post]
func (this *VodController) CreateUploadImage() {
... ... @@ -55,6 +79,45 @@ func (this *VodController) CreateUploadImage() {
msg = protocol.NewReturnResponse(upload.CreateUploadImage(header, request))
}
//创建图片上传凭证 CreateUploadImages
// @router /createUploadImages [post]
func (this *VodController) CreateUploadImages() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var (
request *aliyun.CreateUploadImagesRequest
response *aliyun.CreateUploadImagesResponse = &aliyun.CreateUploadImagesResponse{
List: make([]*aliyun.CreateUploadImageResponse, 0),
}
)
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
var err error
if len(request.Items) == 0 {
msg = protocol.BadRequestParam(2)
}
header := controllers.GetRequestHeader(this.Ctx)
for i := range request.Items {
r := request.Items[i]
if rsp, e := upload.CreateUploadImage(header, r); e != nil {
err = e
break
} else {
response.List = append(response.List, rsp)
}
}
msg = protocol.NewReturnResponse(response, err)
}
//获取视频播放地址 GetPlayInfo
// @router /getPlayInfo [post]
func (this *VodController) GetPlayInfo() {
... ...
... ... @@ -13,3 +13,9 @@ const (
FileVoice = "voice"
FileVideo = "video"
)
const (
DefaultVideoFileName = "test.mp4"
DefaultVoiceFileName = "test.mp3"
DefaultImageFileName = "test.jpg"
)
... ...
package aliyun
import (
"github.com/astaxie/beego"
)
/*
AK AccessKey 完全访问权限
STS (Security Token Service) 临时访问控制
*/
var (
Endpoint string = beego.AppConfig.String("end_point")
BucketName string = beego.AppConfig.String("bucket_name")
//BucketNameCdn string = beego.AppConfig.String("bucket_name_cdn")
//EndpointCdn string = beego.AppConfig.String("end_point_cdn")
)
//type OssSts struct{
//
//}
//func NewSTS(){
// client,_ :=oos.NewClientWithAccessKey(RegionID,AccessKeyID,AccessKeySecret)
// client.DoAction()
//}
... ...
... ... @@ -3,6 +3,7 @@ package aliyun
//创建视频上传凭证
/*CreateUploadVideo */
type CreateUploadVideoRequest struct {
FileName string `json:"fileName"`
}
type CreateUploadVideoResponse struct {
... ... @@ -10,6 +11,20 @@ type CreateUploadVideoResponse struct {
VideoId string `json:"videoId"`
UploadAddress string `json:"uploadAddress"`
UploadAuth string `json:"uploadAuth"`
FileURL string `json:"fileURL"`
}
//刷新视频上传凭证 RefreshUploadVideo
type RefreshUploadVideoRequest struct {
VideoId string `json:"videoId" valid:"Required;"`
}
type RefreshUploadVideoResponse struct {
RequestId string `json:"requestId"`
VideoId string `json:"videoId"`
UploadAddress string `json:"uploadAddress"`
UploadAuth string `json:"uploadAuth"`
FileURL string `json:"fileURL"`
}
/*GetPlayInfo 获取播放信息*/
... ... @@ -74,3 +89,19 @@ type PlayInfo struct {
PlayURL string `json:"PlayURL" xml:"PlayURL"`
Specification string `json:"Specification" xml:"Specification"`
}
//GetVideoPlayAuthResponse is the response struct for api GetVideoPlayAuth
type GetVideoPlayAuthResponse struct {
RequestId string `json:"requestId" xml:"RequestId"`
PlayAuth string `json:"playAuth" xml:"PlayAuth"`
VideoMeta VideoMeta `json:"videoMeta" xml:"VideoMeta"`
}
// VideoMeta is a nested struct in vod response
type VideoMeta struct {
CoverURL string `json:"coverURL" xml:"CoverURL"`
Duration float64 `json:"duration" xml:"Duration"`
Status string `json:"-" xml:"Status"`
Title string `json:"title" xml:"Title"`
VideoId string `json:"videoId" xml:"VideoId"`
}
... ...
package aliyun
type CreateUploadImageRequest struct {
FileName string `json:"fileName"`
}
type CreateUploadImageResponse struct {
RequestId string `json:"requestId" xml:"RequestId"`
ImageId string `json:"imageId" xml:"ImageId"`
ImageURL string `json:"imageURL" xml:"ImageURL"`
UploadAddress string `json:"uploadAddress" xml:"UploadAddress"`
UploadAuth string `json:"uploadAuth" xml:"UploadAuth"`
FileURL string `json:"fileURL" xml:"FileURL"`
RequestId string `json:"requestId"`
ImageId string `json:"imageId" `
ImageURL string `json:"imageURL"`
UploadAddress string `json:"uploadAddress"`
UploadAuth string `json:"uploadAuth"`
FileURL string `json:"fileURL"`
}
type CreateUploadImagesRequest struct {
Items []*CreateUploadImageRequest `json:"items"`
}
type CreateUploadImagesResponse struct {
List []*CreateUploadImageResponse `json:"list"`
}
... ...
package aliyun
import (
"encoding/base64"
"encoding/json"
"fmt"
"strings"
)
type UploadAddress struct {
Endpoint string
Bucket string
FileName string
}
//@cname 绑定域名
func (up UploadAddress) GetFileUrl(cname string) string {
if len(cname) > 0 {
return fmt.Sprintf("%v%v", cname, up.FileName)
}
if strings.Contains(up.Endpoint, "https") {
return fmt.Sprintf("%v%v.%v/%v", up.Endpoint[:8], up.Bucket, up.Endpoint[8:], up.FileName)
} else if strings.Contains(up.Endpoint, "http") {
return fmt.Sprintf("%v%v.%v/%v", up.Endpoint[:7], up.Bucket, up.Endpoint[7:], up.FileName)
}
return ""
}
//解析UploadAddress
func ParseUploadAddress(uploadAddress string) (up UploadAddress, err error) {
var jsData []byte
jsData, err = base64.StdEncoding.DecodeString(uploadAddress)
if err != nil {
return
}
if err = json.Unmarshal(jsData, &up); err != nil {
return
}
return
}
... ...
... ... @@ -6,10 +6,12 @@ import (
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
"github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
"github.com/astaxie/beego"
"github.com/prometheus/common/log"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
comm_time "gitlab.fjmaimaimai.com/mmm-go/gocomm/time"
"opp/internal/utils"
"path"
"path/filepath"
"time"
)
... ... @@ -39,10 +41,12 @@ func InitVodClient(accessKeyId string, accessKeySecret string) (client *vod.Clie
//获取视频上传地址和凭证,并创建视频信息
func CreateUploadVideo(client *vod.Client, r *CreateUploadVideoRequest) (response *CreateUploadVideoResponse, err error) {
request := vod.CreateCreateUploadVideoRequest()
request.Title = getFileName(FileVideo, "video_file.mp4")
request.FileName = getFileName(FileVideo, "video_file.mp4")
//request.CoverURL = "http://img.alicdn.com/tps/TB1qnJ1PVXXXXXCXXXXXXXXXXXX-700-700.png"
//request.Tags = "tag1,tag2"
filePath := getFileName(FileVideo, r.FileName)
if filepath.Ext(r.FileName) == "mp3" {
filePath = getFileName(FileVoice, r.FileName)
}
request.Title = filePath
request.FileName = filePath
request.AcceptFormat = "JSON"
rsp, err := client.CreateUploadVideo(request)
if err != nil {
... ... @@ -54,15 +58,44 @@ func CreateUploadVideo(client *vod.Client, r *CreateUploadVideoRequest) (respons
UploadAddress: rsp.UploadAddress,
UploadAuth: rsp.UploadAuth,
}
if up, e := ParseUploadAddress(rsp.UploadAddress); e != nil {
log.Error(e)
} else {
response.FileURL = up.GetFileUrl("")
}
return
}
func RefreshUploadVideo(client *vod.Client, r *RefreshUploadVideoRequest) (response *RefreshUploadVideoResponse, err error) {
request := vod.CreateRefreshUploadVideoRequest()
request.VideoId = r.VideoId
request.AcceptFormat = "JSON"
var rsp *vod.RefreshUploadVideoResponse
rsp, err = client.RefreshUploadVideo(request)
if err != nil {
return
}
if err = utils.JsonDeepCopy(&response, &rsp); err != nil {
return
}
if up, e := ParseUploadAddress(rsp.UploadAddress); e != nil {
log.Error(e)
} else {
response.FileURL = up.GetFileUrl("")
}
return
}
//获取图片上传地址和凭证,并创建视频信息
func CreateUploadImage(client *vod.Client, r *CreateUploadImageRequest) (response *CreateUploadImageResponse, err error) {
request := vod.CreateCreateUploadImageRequest()
request.ImageType = "cover"
filePath := getFileName(FileImage, r.FileName)
request.ImageType = "default"
request.Title = filePath
request.ImageExt = filepath.Ext(r.FileName)[1:]
request.AcceptFormat = "JSON"
request.ImageExt = "jpg"
//request.StorageLocation = filepath.Base(request.Title)
rsp, err := client.CreateUploadImage(request)
if err != nil {
return
... ... @@ -80,11 +113,17 @@ func GetPlayInfo(client *vod.Client, r *GetPlayInfoRequest) (response *vod.GetPl
}
//获取播放信息
func GetGetVideoPlayAuth(client *vod.Client, r *GetVideoPlayAuthRequest) (response interface{}, err error) {
func GetGetVideoPlayAuth(client *vod.Client, r *GetVideoPlayAuthRequest) (response GetVideoPlayAuthResponse, err error) {
request := vod.CreateGetVideoPlayAuthRequest()
request.VideoId = r.VideoId
request.AcceptFormat = "JSON"
return client.GetVideoPlayAuth(request)
var rsp *vod.GetVideoPlayAuthResponse
if rsp, err = client.GetVideoPlayAuth(request); err != nil {
log.Error(err)
return
}
err = utils.JsonDeepCopy(&response, rsp)
return
}
//fileType: video voice image
... ...
... ... @@ -98,6 +98,8 @@ func main() {
beego.BConfig.Listen.HTTPSKeyFile = "conf/_.fjmaimaimai.com.key"
contrab.Run()
//beego.BConfig.Listen.EnableAdmin = true //开启进程内监控模块
beego.Run()
}
... ...
... ... @@ -35,13 +35,13 @@ func GetAuditCheckById(id int) (v *AuditCheck, err error) {
return nil, err
}
func GetAuditCheckBy(tpId int64) (v []*AuditCheck, err error) {
func GetAuditCheckBy(tpId int64, v interface{}) (err error) {
sql := `select * from(
select id,(case when pid=0 then id else pid end) pid,title,items from audit_check where template_id=? and enable=1
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
)a
order by a.pid`
o := orm.NewOrm()
if _, err = o.Raw(sql, tpId).QueryRows(&v); err != nil {
if _, err = o.Raw(sql, tpId).QueryRows(v); err != nil {
if err == orm.ErrNoRows {
err = nil
}
... ...
... ... @@ -33,6 +33,8 @@ type AuditFlowProcess struct {
ApproveMessage string `orm:"column(approve_message);size(50)" description:"审核消息-冗余"`
TemplateId int `orm:"column(template_id);size(50)" description:"模板编号-冗余"`
SelfChecks string `orm:"column(self_checks);null" description:"自查内容"`
SubmitCheckTime time.Time `orm:"column(submit_check_time);type(timestamp)" description:"提交筛选时间"`
SubmitCheckStatus int `orm:"column(submit_check_status)" description:"提交筛选状态 0:未提交 1:已提交"`
}
func (t *AuditFlowProcess) TableName() string {
... ... @@ -180,3 +182,23 @@ func UpdatetAuditFlowProcessToSubmit(o orm.Ormer, chanceId int64, level int, rev
}
return
}
//获取审核人最新的审核节点
func GetAuditorLatestAuditFlowProcess(chanceId int64, userId int64) (v *AuditFlowProcess, err error) {
o := orm.NewOrm()
sql := "select * from audit_flow_process where chance_id=? and level>0 and uid=? order by id desc limit 1"
if err = utils.ExecuteQueryOneWithOrmer(o, &v, sql, chanceId, userId); err != nil {
return
}
return
}
//获取机会所有审核人
func GetChanceAllAuditors(chanceId int64) (v []*AuditFlowProcess, err error) {
o := orm.NewOrm()
sql := "select MAX(id) AS id,uid from audit_flow_process where chance_id=? and `level`>0 group by chance_id,uid"
if err = utils.ExecuteQueryAllWithOrmer(o, &v, sql, chanceId); err != nil {
return
}
return
}
... ...
... ... @@ -36,6 +36,9 @@ type Chance struct {
Code string `orm:"column(code)" description:"机会编码 一级编码+二级编码"`
Status int8 `orm:"column(status)" description:"状态 1:开启 2:关闭 "`
SelfChecks string `orm:"column(self_checks);size(1000);null" description:"自查内容"`
CheckTime time.Time `orm:"column(check_time);type(timestamp)" description:"时间"`
CheckResultStatus int `orm:"column(check_result_status)" description:"机会筛选状态【1:待处理】【2:通过】【3:不通过】"`
CheckResult string `orm:"column(check_result);null" description:"筛选结果"`
}
const (
... ... @@ -116,9 +119,9 @@ func DeleteChance(id int64) (err error) {
func GetChanceMyChance(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := `select a.*,b.images,speechs,videos
from (
select id,user_id,create_at,update_at,update_at chance_approve_time,source_content,approve_data,review_status,enable_status,status from chance
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
where user_id=? and company_id=? and review_status in (?) and (?=0 or unix_timestamp(update_at)<?) and status=1 and enable_status=1
) a left JOIN chance_data b on a.id =b.chance_id
) a left JOIN chance_data b on a.chance_id =b.chance_id
order by update_at desc
limit ?
` //approve_time
... ... @@ -140,14 +143,14 @@ where user_id=? and company_id=? and review_status in (%v) and status=1 and enab
func GetChanceMyApproveChance(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from (
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 (
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 (
select id,approve_time,approve_data,uid,chance_id,approve_message,update_at process_create_time
from audit_flow_process where uid=? and review_status in (%v)
)a left outer join chance b on a.chance_id = b.id
)a left outer join chance_data b on a.chance_id =b.chance_id
where (?=0 or unix_timestamp(a.update_at)<?)
order by a.update_at desc
LIMIT ?`, utils.JoinInt8s(reviewStatus, ",")) //and enable_status =1 //就算已经删除了,列表上面还是要体现已经删除
LIMIT ?`, utils.JoinInt8s(reviewStatus, ",")) //备注:and enable_status =1 //就算已经删除了,列表上面还是要体现已经删除
sqlCount := fmt.Sprintf(`select count(0)
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
return
}
//获取有效的机会
func GetChanceMyApproveChanceEnable(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from (
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 (
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 (
select id,approve_time,approve_data,uid,chance_id,approve_message
from audit_flow_process where uid=? and review_status in (%v) and enable_status =1
)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
sql := fmt.Sprintf(`select a.*,b.content commented_content,b.create_at commented_time,b.user_id commented_user_id
from (
select a.*,b.images,b.speechs,b.videos from (
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 (
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 (
select id,content,view_total,zan_total,comment_total,source_type,source_id,create_at comment_time from comment
where user_id =? and (?=0 or id<?)
)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)`,
}
return
}
//获取筛选中的机会
//@submitStatus 提交状态:已提交 未提交
//@checkResultStatus 筛选结果状态:通过 / 不通过
func GetSiftingChance(uid int64, submitStatus int, checkResultStatus int, offset int, pageSize int, v interface{}) (total int, err error) {
var where string
if submitStatus == 1 {
where = fmt.Sprintf(`order by a.submit_check_time desc`)
} else {
where = fmt.Sprintf(`order by a.chance_approve_time desc`)
}
sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos
from (
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,
b.view_total,
b.update_at,b.approve_time chance_approve_time,b.status,b.self_checks,b.check_result_status,b.check_time
from (
select max(id) id,approve_time,approve_data,uid,chance_id,submit_check_status,submit_check_time,level
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
where a.uid=%v and b.max_id=a.id and a.submit_check_status=%v and level>0
GROUP BY chance_id
)a left outer join chance b on a.chance_id = b.id
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
)a left outer join chance_data b on a.chance_id =b.chance_id
%v
limit %v,%v`, uid, uid, submitStatus, checkResultStatus, where, offset, pageSize) //,update_at process_create_time
sqlCount := fmt.Sprintf(`select count(0)
from (
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.self_checks,b.check_result_status
from (
select max(id) id,approve_time,approve_data,uid,chance_id,submit_check_status,submit_check_time,level
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
where a.uid=%v and b.max_id=a.id and a.submit_check_status=%v and level>0
GROUP BY chance_id
)a left outer join chance b on a.chance_id = b.id
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
)a
`, uid, uid, submitStatus, checkResultStatus) //and enable_status =1
if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil {
return
}
if v != nil {
if err = utils.ExecuteQueryAll(v, sql); err != nil {
return
}
}
return
}
//获取筛选结果的机会
//@submitStatus 提交状态:已提交 未提交
//@checkResultStatus 筛选结果状态:通过 / 不通过
func GetSiftingResults(uid int64, submitStatus, checkResultStatus int, offset int, pageSize int, v interface{}) (total int, err error) {
sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos
from (
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,
b.view_total,
b.update_at,b.approve_time chance_approve_time,b.status,b.self_checks,b.check_result_status,b.check_time
from (
select max(id) id,approve_time,approve_data,uid,chance_id,submit_check_status,submit_check_time,level
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
where a.uid=%v and b.max_id=a.id and a.submit_check_status=%v and level>0
GROUP BY chance_id
)a left outer join chance b on a.chance_id = b.id
where b.review_status=3 and b.enable_status=1 and b.status=1 and b.check_result_status =%v
)a left outer join chance_data b on a.chance_id =b.chance_id
order by a.check_time desc
limit %v,%v`, uid, uid, submitStatus, checkResultStatus, offset, pageSize) //,update_at process_create_time
sqlCount := fmt.Sprintf(`select count(0)
from (
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.self_checks,b.check_result_status
from (
select max(id) id,approve_time,approve_data,uid,chance_id,submit_check_status,submit_check_time,level
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
where a.uid=%v and b.max_id=a.id and a.submit_check_status=%v and level>0
GROUP BY chance_id
)a left outer join chance b on a.chance_id = b.id
where b.review_status=3 and b.enable_status=1 and b.status=1 and b.check_result_status =%v
)a
`, uid, uid, submitStatus, checkResultStatus) //and enable_status =1
if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil {
return
}
if v != nil {
if err = utils.ExecuteQueryAll(v, sql); err != nil {
return
}
}
return
}
... ...
package models
import (
"fmt"
"opp/internal/utils"
"time"
"github.com/astaxie/beego/orm"
)
type ChanceCheckResult struct {
Id int64 `orm:"column(id);pk"`
ChanceId int64 `orm:"column(chance_id)"`
GroupId int64 `orm:"column(group_id);null"`
CheckPid int64 `orm:"column(check_pid)"`
CheckId int `orm:"column(check_id);null"`
CheckItem string `orm:"column(check_item);size(20);null" description:"检查项"`
Answer string `orm:"column(answer);size(50);null" description:"回答"`
Reason string `orm:"column(reason);size(200);null" description:"理由"`
UserCompanyId int64 `orm:"column(user_company_id);null"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null"`
}
func (t *ChanceCheckResult) TableName() string {
return "chance_check_result"
}
func init() {
orm.RegisterModel(new(ChanceCheckResult))
}
var (
SqlGetUserCheckResults = `select * from chance_check_result where chance_id =? and user_company_id=? order by group_id,check_id` //机会自查数据
)
// AddChanceCheckResult insert a new ChanceCheckResult into database and returns
// last inserted Id on success.
func AddChanceCheckResult(m *ChanceCheckResult) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetChanceCheckResultById retrieves ChanceCheckResult by Id. Returns error if
// Id doesn't exist
func GetChanceCheckResultById(id int64) (v *ChanceCheckResult, err error) {
o := orm.NewOrm()
v = &ChanceCheckResult{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateChanceCheckResult updates ChanceCheckResult by Id and returns error if
// the record to be updated doesn't exist
func UpdateChanceCheckResultById(m *ChanceCheckResult) (err error) {
o := orm.NewOrm()
v := ChanceCheckResult{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Update(m); err == nil {
fmt.Println("Number of records updated in database:", num)
}
}
return
}
// DeleteChanceCheckResult deletes ChanceCheckResult by Id and returns error if
// the record to be deleted doesn't exist
func DeleteChanceCheckResult(id int64) (err error) {
o := orm.NewOrm()
v := ChanceCheckResult{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&ChanceCheckResult{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
//获取机会所有审核人
func GetCheckResultAllSubmitters(chanceId int64) (v []int64, err error) {
o := orm.NewOrm()
sql := "select DISTINCT user_company_id from chance_check_result where chance_id=?"
if err = utils.ExecuteQueryAllWithOrmer(o, &v, sql, chanceId); err != nil {
return
}
return
}
//获取机会所有筛选结果
func GetCheckResultsByChanceId(chanceId int64) (v []*ChanceCheckResult, err error) {
o := orm.NewOrm()
sql := "select * from chance_check_result where chance_id =? order by check_pid,check_id"
if err = utils.ExecuteQueryAllWithOrmer(o, &v, sql, chanceId); err != nil {
return
}
return
}
func GetCheckResultsByCheckId(chanceId int64, checkId int) (v []*ChanceCheckResult, err error) {
o := orm.NewOrm()
sql := "select * from chance_check_result where chance_id =? and check_id=? order by id"
if err = utils.ExecuteQueryAllWithOrmer(o, &v, sql, chanceId, checkId); err != nil {
return
}
return
}
... ...
... ... @@ -198,7 +198,7 @@ func GetUserMsgsBulletin(userId, companyId int64, msgType int, lastId int64, pag
//获取机会消息
func GetChanceMsg(uid, lastId int64, pageSize int, msgType int, v interface{}) (total int, err error) {
sql := `select a.*,b.images,b.speechs,b.videos from (
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 (
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 (
select id,company_id,receive_user_id,message,source_id,is_read,chance_id,create_at msg_time,data,sender_user_id
from user_msg where receive_user_id=? and source_type=1 and (?=0 or id<?) and msg_type=?
)a left outer join chance b on a.source_id = b.id
... ...
... ... @@ -191,8 +191,8 @@ type ChancePoolResponse struct {
//我的机会列表
type ChanceItemOrm struct {
Id int64 `orm:"column(id)"`
Uid int64 `orm:"column(user_id)"`
ChanceId int64 `orm:"column(id)"`
ChanceUserId int64 `orm:"column(user_id)"`
CreateTime time.Time `orm:"column(create_at)"`
UpdateTime time.Time `orm:"column(update_at)"`
ApproveTime time.Time `orm:"column(chance_approve_time)"`
... ... @@ -219,17 +219,18 @@ type MyApproveChanceResponse struct {
//我的审核机会列表
type ChanceApproveItemOrm struct {
ChanceUserId int64 `orm:"column(user_id)"`
CreateTime time.Time `orm:"column(create_at)"`
UpdateTime time.Time `orm:"column(update_at)"`
ChanceApproveTime time.Time `orm:"column(chance_approve_time)"`
SourceContent string `orm:"column(source_content)"`
ChanceEnableStatus int `orm:"column(enable_status)"`
Images string `orm:"column(images)"`
Voices string `orm:"column(speechs)"`
Videos string `orm:"column(videos)"`
ReviewStatus int `orm:"column(review_status)"`
Status int `orm:"column(status)"`
//ChanceUserId int64 `orm:"column(user_id)"`
//CreateTime time.Time `orm:"column(create_at)"`
//UpdateTime time.Time `orm:"column(update_at)"`
//ChanceApproveTime time.Time `orm:"column(chance_approve_time)"`
//SourceContent string `orm:"column(source_content)"`
//ChanceEnableStatus int `orm:"column(enable_status)"`
//Images string `orm:"column(images)"`
//Voices string `orm:"column(speechs)"`
//Videos string `orm:"column(videos)"`
//ReviewStatus int `orm:"column(review_status)"`
//Status int `orm:"column(status)"`
CommChanceItemOrm
Id int64 `orm:"column(id)"` //审核id
ApproveTime time.Time `orm:"column(approve_time)"`
... ... @@ -362,6 +363,8 @@ type CommChanceItemOrm struct {
ChanceId int64 `orm:"column(chance_id)"`
ChanceUserId int64 `orm:"column(chance_user_id)"`
CreateTime time.Time `orm:"column(create_at)"`
UpdateTime time.Time `orm:"column(update_at)"`
ChanceApproveTime time.Time `orm:"column(chance_approve_time)"`
SourceContent string `orm:"column(source_content)"`
ChanceEnableStatus int `orm:"column(enable_status)"`
ReviewStatus int `orm:"column(review_status)"` //审核状态 1:待审核 2:被退回 3:已通过
... ... @@ -370,9 +373,13 @@ type CommChanceItemOrm struct {
Videos string `orm:"column(videos)"`
PublishStatus int `orm:"column(publish_status)"` //公开状态
Status int `orm:"column(status)"` //开启状态
ChanceApproveData string `orm:"column(chance_approve_data)"` //审核数据
CommentTotal int `orm:"column(comment_total)"`
ZanTotal int `orm:"column(zan_total)"`
ViewTotal int `orm:"column(view_total)"`
TemplateId int `orm:"column(audit_template_id)"`
ChanceTypeId int `orm:"column(chance_type_id)"`
}
/*ChanceDetail 机会详情*/
... ... @@ -492,6 +499,7 @@ func ClearEmptyForm(inputFormList []*Form) (FormList []*Form) {
type Speech struct {
Path string `json:"path"`
Duration int `json:"duration"`
VideoId string `json:"videoId"`
}
//图片
... ... @@ -499,6 +507,7 @@ type Picture struct {
Path string `json:"path"`
W int `json:"w"`
H int `json:"h"`
ImageId string `json:"imageId"`
}
//视频
... ... @@ -506,6 +515,7 @@ type Video struct {
Path string `json:"path"`
Cover Cover `json:"cover"` //封面
Duration int `json:"duration"`
VideoId string `json:"videoId"`
}
//审批配置
... ... @@ -653,3 +663,25 @@ type ChanceReviseDetailResponse struct {
ChanceReviseData ChanceReviseLog `json:"chanceReviseData"`
ChanceId int64 `json:"chanceId"` //机会编号
}
//机会池筛选项
type ChanceSiftItemOrm struct {
CommChanceItemOrm
//ApproveData string `json:"approveData"` //审核数据
TemplateId int `orm:"column(audit_template_id)"`
ChanceTypeId int `orm:"column(chance_type_id)"`
SubmitCheckTime time.Time `orm:"column(submit_check_time)"` //提交自查时间
}
//机会池筛选项
type ChanceSiftResultOrm struct {
CommChanceItemOrm
//ApproveData string `json:"approveData"` //审核数据
TemplateId int `orm:"column(audit_template_id)"`
ChanceTypeId int `orm:"column(chance_type_id)"`
CheckTime time.Time `orm:"column(check_time)"` //通过时间时间
}
... ...
... ... @@ -10,22 +10,59 @@ import (
)
const (
TypeSubmit = iota + 1
TypeApprove
TypeSubmit = iota + 1 //提交者类型
TypeApprove //审核人类型
)
//提交状态
const (
Submiting = iota //待我提交
Submited //我已提交
)
//通过状态
const (
None = iota //未提交
Waiting //已提交待处理
Reject //退回
Pass //通过
)
const (
OptionYes = "是"
OptionNo = "否"
OptionUncertain = "不清楚"
)
/*机会-自查内容*/
var CheckOptionsCommit = []CheckOption{{Item: "是", NeedOther: false}, {Item: "否", NeedOther: false}, {Item: "不清楚", NeedOther: false}}
var CheckOptionsApprove = []CheckOption{{Item: "是", NeedOther: false}, {Item: "否", NeedOther: true}, {Item: "不清楚", NeedOther: false}}
//自查结果列表
/*自查结果列表*/
type SelfCheckResults []selfCheckResult
type selfCheckResult struct {
Item string `json:"item"`
Total int `json:"total"`
}
//自查项列表
/*自查项*/
type SelfCheck struct {
CheckItem string `json:"checkItem"`
GroupId int64 `json:"groupId"` //分组
Answer string `json:"answer,omitempty"`
Reason string `json:"reason,omitempty"`
Id int64 `json:"id"`
ParentId int64 `json:"parentId"`
}
//自查项 键值
func (c SelfCheck) Key() string {
return fmt.Sprintf("%v-%v", c.GroupId, c.CheckItem)
}
//新建自查项列表
//@data json格式的数据体
func NewSelfChecks(data string) (rsp SelfChecks) {
if len(data) == 0 {
return
... ... @@ -37,27 +74,22 @@ func NewSelfChecks(data string) (rsp SelfChecks) {
return
}
/*自查项列表*/
type SelfChecks []SelfCheck
type SelfCheck struct {
CheckItem string `json:"checkItem"`
GroupId int64 `json:"groupId"` //分组
Answer string `json:"answer,omitempty"`
Reason string `json:"reason,omitempty"`
}
func (c SelfCheck) Key() string {
return fmt.Sprintf("%v-%v", c.GroupId, c.CheckItem)
}
//统计自查结果
func (s SelfChecks) Static() SelfCheckResults {
if len(s) == 0 {
return []selfCheckResult{}
}
results := []selfCheckResult{{Item: "是"}, {Item: "否"}, {Item: "不清楚"}}
var gIdx int64
for i := range s {
check := (s)[i]
if gIdx == check.GroupId {
continue
}
gIdx = check.GroupId
for k := range results {
if strings.EqualFold(results[k].Item, strings.TrimSpace(check.Answer)) {
results[k].Total = results[k].Total + 1
... ... @@ -96,6 +128,9 @@ func (s SelfChecks) String() string {
var buf bytes.Buffer
for i := range s {
c := s[i]
if len(c.Answer) == 0 {
continue
}
if len(c.Reason) == 0 {
buf.WriteString(fmt.Sprintf("\n%v:%v;", c.CheckItem, c.Answer))
} else {
... ... @@ -104,6 +139,8 @@ func (s SelfChecks) String() string {
}
return buf.String()
}
//比较自查内容 ,返回差级
func (s SelfChecks) Compare(dst string) (rspChecks SelfChecks, err error) {
var (
dstChecks SelfChecks
... ... @@ -126,7 +163,7 @@ func (s SelfChecks) Compare(dst string) (rspChecks SelfChecks, err error) {
for i := range s {
c := s[i]
if v, ok := mapChecks[c.Key()]; ok {
//回答不一
//回答不一
if !strings.EqualFold(c.Answer, v.Answer) {
rspChecks = append(rspChecks, c)
continue
... ... @@ -140,7 +177,75 @@ func (s SelfChecks) Compare(dst string) (rspChecks SelfChecks, err error) {
return
}
//自查问题
//按规则设置自查 一级自查
func (s SelfChecks) SetSelfChecksLevel1ByRule() (err error) {
if len(s) == 0 {
return
}
s.Format()
var gIdx = -1
for i := 0; i < len(s); i++ {
if gIdx < 0 || s[gIdx].GroupId != s[i].GroupId {
gIdx = i
} else {
continue
}
hasSub := false
var (
cntYes = 0 //是
cntNo = 0 //否
cntUncertain = 0 //不确定
)
for j := i + 1; j < len(s); j++ {
if s[i].GroupId == s[j].GroupId {
if !hasSub {
hasSub = true
}
} else {
break
}
answer := s[j].Answer
if strings.EqualFold(strings.TrimSpace(answer), OptionYes) {
cntYes++
} else if strings.EqualFold(strings.TrimSpace(answer), OptionNo) {
cntNo++
} else if strings.EqualFold(strings.TrimSpace(answer), OptionUncertain) {
cntUncertain++
}
}
//只有一级维度的必须填写
if hasSub {
if cntYes > 0 {
s[gIdx].Answer = OptionYes
} else if cntNo > 0 {
s[gIdx].Answer = OptionNo
} else if cntUncertain > 0 {
s[gIdx].Answer = OptionUncertain
}
}
if hasSub && cntYes == 0 && cntNo == 0 && cntUncertain == 0 {
err = NewCustomMessage(2, fmt.Sprintf("未填写自查项:%v,二级维度至少需要填写一项", s[gIdx].CheckItem))
}
if !hasSub && len(s[gIdx].Answer) == 0 {
err = NewCustomMessage(2, fmt.Sprintf("未填写自查项:%v", s[gIdx].CheckItem))
}
}
return
}
//格式化数据结构
func (s SelfChecks) Format() {
if len(s) == 0 {
return
}
for i := range s {
if strings.TrimSpace(s[i].Answer) == OptionNo {
s[i].Reason = strings.TrimSpace(s[i].Reason)
}
}
}
//新建自查问题
func NewCheckQuestion(checkItem, title string, groupId int64, ops []CheckOption) *CheckQuestion {
return &CheckQuestion{
CheckItem: checkItem,
... ... @@ -150,22 +255,185 @@ func NewCheckQuestion(checkItem, title string, groupId int64, ops []CheckOption)
}
}
/*问题*/
type CheckQuestion struct {
Id int64 `json:"id"`
ParentId int64 `json:"parentId"`
CheckItem string `json:"checkItem"`
Title string `json:"title"`
GroupId int64 `json:"groupId"`
Answer string `json:"answer,omitempty"`
Reason string `json:"reason,omitempty"`
CheckOptions []CheckOption `json:"options"`
Required bool `json:"required"` //是否必填
}
/*问题选项*/
type CheckOption struct {
Item string `json:"item"`
NeedOther bool `json:"needOther"` //是否需填写其他的内容【1:需要】【2:不需要】
}
//筛选结果
type SiftingResult struct {
CheckId int `json:"checkId"` //检查项id
CheckParentId int64 `json:"parentId"` //项父id
//GroupId int `json:"json:groupId"`//项分组id
Title string `json:"title"` //标题
CheckItem string `json:"checkItem"` //自查项
TotalYes int `json:"totalYes"` //选择是的人数
TotalNo int `json:"totalNo"` //选择否的人数
TotalUncertain int `json:"totalUncertain"` //选择不清楚的人数
TotalSubmitters int `json:"totalSubmitters"` //总提交人数
SubSiftingResults SiftingResults `json:"subSiftingResults"`
}
//筛选结果列表
type SiftingResults []SiftingResult
//清空统计结果
func (s SiftingResults) ClearStatic() {
for i := range s {
s[i].TotalYes = 0
s[i].TotalNo = 0
s[i].TotalUncertain = 0
s[i].TotalSubmitters = 0
s[i].SubSiftingResults.ClearStatic()
}
}
/*
设置一级筛选结果
单个维度显示“是”、“否”、“不清楚”的规则:
1、所有人均选择“是”,则该维度的结果为“是”
2、只要有一个“否”,则该维度的结果为“否” ,不需要显示理由
3、其他情况则显示为“不清楚”
*/
func (s SiftingResults) SetSelfChecksLevel1ByRule() {
for i := range s {
tmpAnswer := ""
if s[i].TotalNo > 0 {
tmpAnswer = OptionNo
}
if s[i].TotalYes > 0 && s[i].TotalNo == 0 && s[i].TotalUncertain == 0 {
tmpAnswer = OptionYes
}
if s[i].TotalNo == 0 && s[i].TotalUncertain > 0 {
tmpAnswer = OptionUncertain
}
s[i].TotalNo = 0
s[i].TotalYes = 0
s[i].TotalUncertain = 0
if tmpAnswer == OptionNo {
s[i].TotalNo = s[i].TotalSubmitters
} else if tmpAnswer == OptionYes {
s[i].TotalYes = s[i].TotalSubmitters
} else if tmpAnswer == OptionUncertain {
s[i].TotalUncertain = s[i].TotalSubmitters
}
}
}
//添加统计
func (s SiftingResults) AddStatic(checkId int, answer string) {
s.addStatic(checkId, answer)
}
func (s SiftingResults) addStatic(checkId int, answer string) {
for i := range s {
if s[i].CheckId == checkId {
var isAnswer = true
switch answer {
case OptionYes:
s[i].TotalYes++
break
case OptionNo:
s[i].TotalNo++
break
case OptionUncertain:
s[i].TotalUncertain++
break
default:
isAnswer = false
break
}
if isAnswer {
s[i].TotalSubmitters++
}
}
s[i].SubSiftingResults.AddStatic(checkId, answer)
}
}
//筛选结果详情
type SiftingResultDetail struct {
Option string `json:"option"` //选项:是 否 不清楚
Items SiftingCommitItems `json:"items"`
TotalSubmitters int `json:"totalSubmitters"` //总提交人数
}
//筛选结果提交人项
type SiftingCommitItems []SiftingCommitItem
type SiftingCommitItem struct {
Provider *BaseUserInfo `json:"provider"`
Reason string `json:"reason"` //理由
}
/******************REQUEST/RESPONSE (请求应答实体)*******************/
/*CheckQuestions 自查问题列表*/
type CheckQuestionsRequest struct {
Type int `json:"type"` //0.自查 1.筛选结果
ChanceId int64 `json:"chanceId" valid:"Required"`
}
type CheckQuestionsResponse struct {
Questions []*CheckQuestion `json:"questions"`
}
//SiftingPool 筛选池
type SiftingPoolRequest struct {
PageInfo
Uid int64 `json:"uid"` //注入用户 测试使用
SubmitStatus int `json:"submitStatus"` //0:待我提交 1:提交
SiftedStatus int `-` //筛选状态 1:提交中 2:通过 3:不通过
}
type SiftingPoolResponse struct{ ChancePoolResponse }
/*筛选结果 SiftingResults */
type SiftingResultsRequest struct {
PageInfo
Uid int64 `json:"uid"` //注入用户 测试使用
SiftedStatus int `json:"siftingStatus"` //筛选状态 1:待处理 2:通过 3:不通过
}
type SiftingResultsResponse struct{ ChancePoolResponse }
/*SubmitChecks 提交自查*/
type SubmitChecksRequest struct {
//Type int `json:"type"` //1.审核人
Uid int64 `json:"uid"`
ChanceId int64 `json:"chanceId" valid:"Required"`
SelfChecks SelfChecks `json:"selfChecks"`
}
type SubmitChecksResponse struct{}
/*SiftingResultsItemHistory 筛选历史*/
type SiftingResultsItemHistoryRequest struct {
ChanceId int64 `json:"chanceId" valid:"Required"`
}
type SiftingResultsItemHistoryResponse struct {
SiftingResults SiftingResults `json:"siftingResults"`
TotalSubmitters int `json:"totalSubmitters"`
}
/*SiftingResultsItemDetail 筛选历史详情*/
type SiftingResultsItemDetailRequest struct {
ChanceId int64 `json:"chanceId" valid:"Required"`
CheckId int `json:"checkId" valid:"Required"` //检查项id
}
type SiftingResultsItemDetailResponse struct {
SiftingResultDetails []SiftingResultDetail `json:"siftingResultDetails"`
TotalSubmitters int `json:"totalSubmitters"` //总提交人数
}
... ...
package protocol
import (
"encoding/json"
"fmt"
"testing"
)
func TestSelfChecks(t *testing.T) {
nsc := func(id, pid int64, checkItem, answer string) SelfCheck {
item := SelfCheck{
CheckItem: checkItem, Answer: answer, Id: id, ParentId: pid,
}
item.GroupId = pid
if pid == 0 {
item.GroupId = id
}
return item
}
nscNo := func(id, pid int64, checkItem, answer, reason string) SelfCheck {
item := nsc(id, pid, checkItem, answer)
item.Reason = reason
return item
}
input := SelfChecks([]SelfCheck{
nsc(1, 0, "1", ""),
nsc(2, 1, "2", OptionYes),
nsc(3, 1, "3", OptionNo),
nsc(4, 1, "4", OptionUncertain),
nsc(5, 1, "5", ""),
nsc(6, 0, "6", ""),
nsc(7, 6, "7", OptionUncertain),
nscNo(8, 6, "8", OptionNo, " "),
nsc(9, 6, "9", OptionUncertain),
nsc(10, 6, "10", ""),
nsc(11, 0, "11", OptionYes),
nsc(12, 0, "12", OptionYes),
})
input.SetSelfChecksLevel1ByRule()
if input[0].Answer != OptionYes || input[5].Answer != OptionNo {
t.Fatal(fmt.Sprintf("SetSelfChecksLevel1ByRule Fail"))
}
if input.Static()[0].Total != 3 || input.Static()[0].Item != OptionYes {
t.Fatal(fmt.Sprintf("Static Fail"))
}
if input[7].Reason != " " {
t.Fatal("reason data error")
}
input.Format()
if input[7].Reason == " " {
t.Fatal("reason data error")
}
t.Log(input.String())
inputCompare := SelfChecks([]SelfCheck{
nsc(1, 0, "1", ""),
nsc(2, 1, "2", OptionYes),
nsc(3, 1, "3", OptionNo),
nsc(4, 1, "4", OptionNo), //diff
nsc(5, 1, "5", ""),
nsc(6, 0, "6", ""),
nsc(7, 6, "7", OptionUncertain),
nscNo(8, 6, "8", OptionNo, " "),
nsc(9, 6, "9", OptionUncertain),
nsc(10, 6, "10", ""),
nsc(11, 0, "11", OptionYes),
nsc(12, 0, "12", OptionNo), //diff
})
inputCompare.SetSelfChecksLevel1ByRule()
inputCompare.Format()
data, err := json.Marshal(input)
if err != nil {
t.Fatal(err)
}
o, err := inputCompare.Compare(string(data))
if err != nil {
t.Fatal(err)
}
if len(o) != 2 {
t.Fatal("Compare fail")
}
t.Log("Compare:", o.String())
}
func TestSiftingResults(t *testing.T) {
}
... ...
... ... @@ -108,6 +108,12 @@ func BadRequestParam(code int) *ResponseMessage {
return NewMesage(code)
}
func BadRequestParamWithMessage(code int, message string) *ResponseMessage {
msg := NewMesage(code)
msg.Errmsg = message
return msg
}
func NewSuccessWithMessage(msg string) *ErrWithMessage {
return &ErrWithMessage{
Err: nil,
... ...
package protocol
const RequireVersion = "0.9.0"
const (
VERSION = "0.11.5"
RequireVersion = "0.9.0"
)
/*
全局变量声明
... ... @@ -87,3 +90,18 @@ type NameItem struct {
Id int `json:"id"`
Name string `json:"name"`
}
type PageInfo struct {
PageIndex int `json:"pageIndex"` //页码(默认0代表第1页)
PageSize int `json:"pageSize" valid:"Required"` //每页数量
}
//获取分页信息
func (p PageInfo) Offset() (offset int) {
var size = p.PageSize
if size == 0 {
size = 20
}
offset = size * p.PageIndex
return
}
... ...
... ... @@ -272,15 +272,7 @@ type MsgChanceReviseResponse struct {
//我的审核机会列表
type MsgChanceApproveItemOrm struct {
ChanceUserId int64 `orm:"column(chance_user_id)"`
SourceContent string `orm:"column(source_content)"`
ChanceEnableStatus int `orm:"column(enable_status)"`
Images string `orm:"column(images)"`
Voices string `orm:"column(speechs)"`
Videos string `orm:"column(videos)"`
ReviewStatus int `orm:"column(review_status)"`
Status int `orm:"column(status)"`
ApproveData string `orm:"column(approve_data)"` //审核数据
CommChanceItemOrm
Id int64 `orm:"column(id)"` //消息id
MsgTime time.Time `orm:"column(msg_time)"`
... ... @@ -289,8 +281,8 @@ type MsgChanceApproveItemOrm struct {
CreateTime time.Time `orm:"column(create_at)"`
Message string `orm:"column(message)"`
IsRead int64 `orm:"column(is_read)"`
ChanceId int64 `orm:"column(chance_id)"` // 机会id
//EnableStatus int `orm:"column(enable_status)"`
//ChanceId int64 `orm:"column(chance_id)"` // 机会id
EnableStatus int `orm:"column(enable_status)"`
SourceId int64 `orm:"column(source_id)"` // 机会id
Data string `orm:"column(data)"`
}
... ...
... ... @@ -257,6 +257,38 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "SiftingPool",
Router: `/siftingPool`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "SiftingResults",
Router: `/siftingResults`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "SiftingResultsItemDetail",
Router: `/siftingResults/itemDetail`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "SiftingResultsItemHistory",
Router: `/siftingResults/itemHistory`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "ChanceStatistics",
Router: `/statistics`,
AllowHTTPMethods: []string{"post"},
... ... @@ -273,6 +305,14 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "SubmitChecks",
Router: `/submitSiftingResult`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "SympathyAction",
Router: `/sympathyAction`,
AllowHTTPMethods: []string{"post"},
... ... @@ -625,6 +665,14 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:VodController"],
beego.ControllerComments{
Method: "CreateUploadImages",
Router: `/createUploadImages`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:VodController"],
beego.ControllerComments{
Method: "CreateUploadVideo",
Router: `/createUploadVideo`,
AllowHTTPMethods: []string{"post"},
... ... @@ -647,4 +695,12 @@ func init() {
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:VodController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:VodController"],
beego.ControllerComments{
Method: "RefreshUploadVideo",
Router: `/refreshUploadVideo`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
}
... ...
... ... @@ -222,6 +222,14 @@ func SetChanceItem(header *protocol.RequestHeader, chance protocol.CommChanceIte
CreateTime: chance.CreateTime.Unix() * 1000,
PublicStatus: chance.PublishStatus,
}
item.UpdateTime = chance.UpdateTime.Unix() * 1000
item.ApproveTime = chance.ChanceApproveTime.Unix() * 1000
if item.ApproveTime < 0 {
item.ApproveTime = 0
}
if item.UpdateTime < 0 {
item.UpdateTime = 0
}
utils.JsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = ClearEmptyForm(item.FormList)
utils.JsonUnmarshal(chance.Images, &item.Pictures)
... ... @@ -239,11 +247,17 @@ func SetMsgItem(header *protocol.RequestHeader, msg protocol.MsgItemOrm, commIte
//获取自查问题列表 通过模板
func GetCheckQuestionsByTemplateId(id int64) (rsp []*protocol.CheckQuestion, err error) {
type check struct {
models.AuditCheck
Id int64 `orm:"column(id)"`
ParentId int64 `orm:"column(parent_id)"`
}
var (
checks []*models.AuditCheck
checks []*check
)
rsp = make([]*protocol.CheckQuestion, 0)
if checks, err = models.GetAuditCheckBy(id); err != nil {
if err = models.GetAuditCheckBy(id, &checks); err != nil {
log.Error(err)
return
}
... ... @@ -253,18 +267,22 @@ func GetCheckQuestionsByTemplateId(id int64) (rsp []*protocol.CheckQuestion, err
var tmpGroupId int64
var idx int = 0
var groupIdx = 0
var parentId = 0
for i := range checks {
c := checks[i]
if tmpGroupId != c.Pid {
groupIdx++
idx = 0
parentId = i + 1
}
tmpGroupId = c.Pid
item := protocol.NewCheckQuestion(c.Title, getQuestionTitle(groupIdx, idx, c.Title), c.Pid, protocol.CheckOptionsCommit)
item.Id, item.ParentId = genCustomizeQuestionId(i, idx, int64(parentId))
rsp = append(rsp, item)
idx++
}
setQuestionRequire(rsp)
return
}
... ... @@ -286,22 +304,20 @@ func GetCheckQuestionsByChanceId(header *protocol.RequestHeader, id int64) (rsp
if len(chance.SelfChecks) == 0 {
return
}
if chance.ReviewStatus == protocol.ReviewStatusPass {
log.Warn("机会已审核通过不可编辑自查数据:", chance.Id)
return
}
if e := json.Unmarshal([]byte(chance.SelfChecks), &selfChecks); e != nil {
log.Error(e)
return
}
var tmpGroupId int64
var idx int = 0
var groupIdx = 0
var idx int = 0 //组内排序
var groupIdx = 0 //分组序号
var parentId = 0
for i := range selfChecks {
c := selfChecks[i]
if tmpGroupId != c.GroupId {
groupIdx++
idx = 0
parentId = i + 1
}
tmpGroupId = c.GroupId
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
item.Answer = c.Answer
}
}
//if item.Id == 0 {
item.Id, item.ParentId = genCustomizeQuestionId(i, idx, int64(parentId))
//}
rsp = append(rsp, item)
idx++
}
setQuestionRequire(rsp)
return
}
//从问题筛选结果获取已回答的问题
func GetCheckQuestionsByChanceCheckResult(header *protocol.RequestHeader, id int64) (rsp []*protocol.CheckQuestion, err error) {
var (
checks []*models.ChanceCheckResult
groupIdx int = 1 //分组序号
)
if err = utils.ExecuteQueryAll(&checks, models.SqlGetUserCheckResults, id, header.UserId); err != nil {
if err == orm.ErrNoRows {
return
}
log.Error(err)
return
}
for i := range checks {
c := checks[i]
item := &protocol.CheckQuestion{
Id: int64(c.CheckId),
ParentId: int64(c.CheckPid),
GroupId: int64(c.GroupId),
CheckItem: c.CheckItem,
Answer: c.Answer,
Reason: c.Reason,
CheckOptions: protocol.CheckOptionsApprove,
}
if c.CheckPid == 0 {
item.Title = fmt.Sprintf("%v、%v", groupIdx, c.CheckItem)
} else {
item.Title = c.CheckItem
}
rsp = append(rsp, item)
}
setQuestionRequire(rsp)
return
}
//设置问题需要填写
func setQuestionRequire(list []*protocol.CheckQuestion) {
if len(list) == 0 {
return
}
//var gIdx = -1
for i := 0; i < len(list); i++ {
//if gIdx < 0 || list[gIdx].GroupId != list[i].GroupId {
// gIdx = i
//} else {
// continue
//}
//hasSub := false
//for j := i + 1; j < len(list); j++ {
// if list[i].GroupId == list[j].GroupId {
// if !hasSub {
// hasSub = true
// }
// } else {
// break
// }
//}
////只有一级维度的必须填写
//if !hasSub {
// list[gIdx].Required = true
//}
if list[i].ParentId == 0 { //一级都默认true
list[i].Required = true
}
}
}
func getQuestionTitle(groupIdx int, idx int, title string) string {
if idx == 0 {
return fmt.Sprintf("%v、%v?", groupIdx, title)
return fmt.Sprintf("%v、%v", groupIdx, title)
}
//return fmt.Sprintf("%v.%v、%v", groupIdx, idx, title)
return fmt.Sprintf("%v", title)
}
//自定义id
//@return id:问题序号 parentId:父级id
func genCustomizeQuestionId(seq int, idx int, groupId int64) (id int64, parentId int64) {
id = int64(seq) + 1
//同一分组的第一个 是一级
if idx == 0 {
//id = groupId
parentId = 0
return
}
return fmt.Sprintf("%v.%v、%v?", groupIdx, idx, title)
parentId = int64(groupId)
return
}
//自查问题回答批量入库
... ... @@ -381,6 +484,7 @@ func BulkInsertSelfChecks(header *protocol.RequestHeader, relateId, chanceId int
o.Commit()
}
//自查问题回答内容
func NewChanceSelfCheck(header *protocol.RequestHeader, check protocol.SelfCheck, chanceId, r int64, checkerType int) *models.ChanceSelfCheck {
return &models.ChanceSelfCheck{
Id: idgen.Next(),
... ... @@ -397,3 +501,71 @@ func NewChanceSelfCheck(header *protocol.RequestHeader, check protocol.SelfCheck
Type: checkerType,
}
}
//新建通用列表项
func NewCommonListItem(header *protocol.RequestHeader, ormItem protocol.CommChanceItemOrm) protocol.CommonListItem {
commItem := protocol.CommonListItem{}
commItem.Chance, commItem.ChanceStatus = SetChanceItem(header, ormItem)
commItem.ReviewStatus = ormItem.ReviewStatus
commItem.ChanceId = ormItem.ChanceId
////模板数据
commItem.ChanceTemplate = GetTemplate(ormItem.TemplateId)
commItem.ChanceType = GetChanceType(ormItem.ChanceTypeId)
return commItem
}
//获取模板
func GetTemplate(templateId int) protocol.NameItem {
if template, e := models.GetAuditTemplateById(int64(templateId)); e == nil {
item := protocol.NameItem{
Id: int(template.Id),
Name: template.Name,
}
return item
} else {
log.Error(templateId, e)
}
return protocol.NameItem{}
}
//获取机会一级分类
func GetChanceType(chanceTypeId int) protocol.NameItem {
if template, e := models.GetChanceTypeById(chanceTypeId); e == nil {
item := protocol.NameItem{
Id: int(template.Id),
Name: template.Name,
}
return item
} else {
log.Error(chanceTypeId, e)
}
return protocol.NameItem{}
}
//获取自查内容 筛选前使用SelfChecks(提交人的筛查结果)
func GetChanceSelfChecks(chanceInfo *models.Chance) []protocol.SelfCheck {
var selfChecks []protocol.SelfCheck = make([]protocol.SelfCheck, 0)
switch chanceInfo.CheckResultStatus {
case protocol.None: //未提交筛查结果
utils.JsonUnmarshal(chanceInfo.SelfChecks, &selfChecks)
if len(selfChecks) != 0 {
protocol.SelfChecks(selfChecks).SetSelfChecksLevel1ByRule()
}
break
case protocol.Waiting: //未通过审核的返回所有筛查结果(一级/二级)
utils.JsonUnmarshal(chanceInfo.CheckResult, &selfChecks)
break
default: //审核通过/不通过只显示一级
utils.JsonUnmarshal(chanceInfo.CheckResult, &selfChecks)
var lv1List []protocol.SelfCheck
for i := 0; i < len(selfChecks); i++ {
if selfChecks[i].ParentId == 0 {
lv1List = append(lv1List, selfChecks[i])
}
}
return lv1List
}
protocol.SelfChecks(selfChecks).Format()
return selfChecks
}
... ...
... ... @@ -1494,11 +1494,12 @@ func ChanceStatistics(header *protocol.RequestHeader, request *protocol.ChanceSt
//我提交的机会
func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitChanceRequest) (rsp *protocol.MySubmitChanceResponse, err error) {
var (
myChances []protocol.ChanceItemOrm
total int
provider *protocol.BaseUserInfo
ormItems []protocol.CommChanceItemOrm
chance *models.Chance
)
rsp = &protocol.MySubmitChanceResponse{
List: make([]protocol.CommonListItem, 0),
}
if request.LastId > 0 {
if chance, err = models.GetChanceById(request.LastId); err != nil {
log.Error("机会不存在", request.LastId, err)
... ... @@ -1506,7 +1507,7 @@ func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitCh
}
request.LastId = chance.UpdateAt.Unix()
}
if total, err = models.GetChanceMyChance(header.UserId, header.CompanyId, []int8{request.ReviewStatus}, request.LastId, request.PageSize, &myChances); err != nil {
if rsp.Total, err = models.GetChanceMyChance(header.UserId, header.CompanyId, []int8{request.ReviewStatus}, request.LastId, request.PageSize, &ormItems); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ... @@ -1514,41 +1515,15 @@ func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitCh
log.Error(err)
return
}
if provider, err = agg.GetUserBaseInfo(header.UserId, header.CompanyId); err != nil {
log.Error(err)
return
}
rsp = &protocol.MySubmitChanceResponse{Total: total}
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
for i := 0; i < len(ormItems); i++ {
ormItem := ormItems[i]
commItem := protocol.CommonListItem{}
{
item := protocol.ChanceItem{
Id: chance.Id,
Provider: provider,
CreateTime: chance.CreateTime.Unix() * 1000,
UpdateTime: chance.UpdateTime.Unix() * 1000,
ApproveTime: chance.ApproveTime.Unix() * 1000,
}
if item.ApproveTime < 0 {
item.ApproveTime = 0
}
jsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = clearEmptyForm(item.FormList)
jsonUnmarshal(chance.Images, &item.Pictures)
jsonUnmarshal(chance.Voices, &item.Speechs)
jsonUnmarshal(chance.Videos, &item.Videos)
commItem.Chance = item
}
if chance.Status == models.ChanceStatusClose {
commItem.ChanceStatus = protocol.ChanceStatusClose
}
commItem.ReviewStatus = chance.ReviewStatus
commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem)
commItem.ReviewStatus = ormItem.ReviewStatus
if request.ReviewStatus == protocol.ReviewStatusPass {
var approveData protocol.ApproveData
jsonUnmarshal(chance.ApproveData, &approveData)
//commItem.ApproveData = approveData //TODO:删除不需要
jsonUnmarshal(ormItem.ChanceApproveData, &approveData)
commItem.Score = approveData.Score
}
rsp.List = append(rsp.List, commItem)
... ... @@ -1559,12 +1534,12 @@ func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitCh
//机会池
func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequest) (rsp *protocol.ChancePoolResponse, err error) {
var (
myChances []protocol.ChancePoolItemOrm
chanceItems []protocol.ChancePoolItemOrm
total int
provider *protocol.BaseUserInfo
flag int
)
if total, err = agg.GetChancePool(header.UserId, header.CompanyId, request.ChanceTypeId, request.DepartmentId, request.IncludeSubDepartment, request.LastId, request.PageSize, &myChances); err != nil {
if total, err = agg.GetChancePool(header.UserId, header.CompanyId, request.ChanceTypeId, request.DepartmentId, request.IncludeSubDepartment, request.LastId, request.PageSize, &chanceItems); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ... @@ -1573,14 +1548,16 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ
return
}
rsp = &protocol.ChancePoolResponse{Total: total, List: make([]protocol.CommonListItem, 0)}
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
for i := 0; i < len(chanceItems); i++ {
chance := chanceItems[i]
if provider, err = agg.GetUserBaseInfo(chance.Uid, header.CompanyId); err != nil {
log.Error(err)
return
}
commItem := protocol.CommonListItem{}
{
commItem.ReviewStatus = chance.ReviewStatus //审核状态
//机会数据
item := protocol.ChanceItem{
Id: chance.ChanceId,
Provider: provider,
... ... @@ -1592,9 +1569,8 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ
jsonUnmarshal(chance.Voices, &item.Speechs)
jsonUnmarshal(chance.Videos, &item.Videos)
commItem.Chance = item
}
commItem.ReviewStatus = chance.ReviewStatus
{
//点赞评论数据
var chanceData = protocol.ChanceData{
ThumbsUpTotal: chance.ZanTotal,
CommentTotal: chance.CommentTotal,
... ... @@ -1607,23 +1583,10 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ
chanceData.IsThumbsUp = (flag & protocol.MarkFlagZan) == protocol.MarkFlagZan
chanceData.IsCollect = (flag & protocol.MarkFlagCollect) == protocol.MarkFlagCollect
commItem.ChanceData = chanceData
}
{
//做一次查询 查回所有的模板数据
if template, e := models.GetAuditTemplateById(int64(chance.TemplateId)); e == nil {
commItem.ChanceTemplate = protocol.NameItem{
Id: int(template.Id),
Name: template.Name,
}
}
if chanceType, e := models.GetChanceTypeById(chance.ChanceTypeId); e == nil {
commItem.ChanceType = protocol.NameItem{
Id: int(chanceType.Id),
Name: chanceType.Name,
}
}
}
//模板数据
commItem.ChanceTemplate = getTemplate(chance.TemplateId)
commItem.ChanceType = getChanceType(chance.ChanceTypeId)
rsp.List = append(rsp.List, commItem)
}
return
... ... @@ -1632,11 +1595,10 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ
//我审核的机会
func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApproveChanceRequest) (rsp *protocol.MyApproveChanceResponse, err error) {
var (
myChances []protocol.ChanceApproveItemOrm
total int
provider *protocol.BaseUserInfo
ormItems []protocol.ChanceApproveItemOrm
chance *models.Chance
)
rsp = &protocol.MyApproveChanceResponse{List: make([]protocol.CommonListItem, 0)}
if request.LastId > 0 {
if chance, err = models.GetChanceById(request.LastId); err != nil {
log.Error("审批不存在", request.LastId, err)
... ... @@ -1645,7 +1607,7 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove
request.LastId = chance.UpdateAt.Unix()
}
if request.ReviewStatus == protocol.ReviewStatusAuditging {
if total, err = models.GetChanceMyApproveChanceEnable(header.UserId, header.CompanyId, []int8{request.ReviewStatus}, request.LastId, request.PageSize, &myChances); err != nil {
if rsp.Total, err = models.GetChanceMyApproveChanceEnable(header.UserId, header.CompanyId, []int8{request.ReviewStatus}, request.LastId, request.PageSize, &ormItems); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ... @@ -1654,7 +1616,7 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove
return
}
} else {
if total, err = models.GetChanceMyApproveChance(header.UserId, header.CompanyId, []int8{request.ReviewStatus}, request.LastId, request.PageSize, &myChances); err != nil {
if rsp.Total, err = models.GetChanceMyApproveChance(header.UserId, header.CompanyId, []int8{request.ReviewStatus}, request.LastId, request.PageSize, &ormItems); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ... @@ -1663,65 +1625,45 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove
return
}
}
rsp = &protocol.MyApproveChanceResponse{Total: total}
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
for i := 0; i < len(ormItems); i++ {
ormItem := ormItems[i]
commItem := protocol.CommonListItem{}
commItem.ReviewStatus = chance.ReviewStatus
if len(chance.SourceContent) == 0 || chance.ChanceEnableStatus == 0 { //机会删除
commItem.ChanceStatus = protocol.ChanceStatusDelete
}
if chance.Status == models.ChanceStatusClose {
commItem.ChanceStatus = protocol.ChanceStatusClose
}
if chance.ChanceUserId > 0 {
if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(chance.ChanceUserId, header.CompanyId, err)
err = nil
} else {
item := protocol.ChanceItem{
Id: chance.ChanceId,
Provider: provider,
CreateTime: chance.CreateTime.Unix() * 1000,
UpdateTime: chance.UpdateTime.Unix() * 1000,
ApproveTime: chance.ChanceApproveTime.Unix() * 1000,
}
if item.ApproveTime < 0 {
item.ApproveTime = chance.UpdateTime.Unix() * 1000
}
jsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = clearEmptyForm(item.FormList)
jsonUnmarshal(chance.Images, &item.Pictures)
jsonUnmarshal(chance.Voices, &item.Speechs)
jsonUnmarshal(chance.Videos, &item.Videos)
commItem.Chance = item
}
commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem.CommChanceItemOrm)
commItem.ReviewStatus = ormItem.ReviewStatus
if commItem.Chance.ApproveTime <= 0 {
commItem.Chance.ApproveTime = ormItem.UpdateTime.Unix() * 1000
}
//审核流数据
approve := protocol.Approve{
ProcessId: chance.Id,
CreateTime: chance.ProcessCreateTime.Unix() * 1000,
ProcessId: ormItem.Id,
CreateTime: ormItem.ProcessCreateTime.Unix() * 1000,
}
//审核过的有审核时间
//审核过的机会 有审核时间
if request.ReviewStatus != protocol.ReviewStatusAuditging {
approve.ApproveTime = chance.ApproveTime.Unix() * 1000
approve.ApproveTime = ormItem.ApproveTime.Unix() * 1000
if approve.ApproveTime < 0 {
approve.ApproveTime = chance.ChanceApproveTime.Unix() * 1000
approve.ApproveTime = ormItem.ChanceApproveTime.Unix() * 1000
}
}
commItem.Approve = approve
//审核完有审核数据
//审核中 有审核消息
if request.ReviewStatus == protocol.ReviewStatusAuditging {
commItem.Message = chance.ApproveMessage
commItem.Message = ormItem.ApproveMessage
}
//审核通过有审核评分数据
if request.ReviewStatus == protocol.ReviewStatusPass {
var approveData *protocol.ApproveData
jsonUnmarshal(chance.ApproveData, &approveData)
jsonUnmarshal(ormItem.ApproveData, &approveData)
if approveData != nil {
commItem.Score = approveData.Score
}
}
commItem.SelfCheckResult = protocol.NewSelfChecks(chance.SelfChecks).Static()
selfChecks := protocol.NewSelfChecks(ormItem.SelfChecks)
selfChecks.SetSelfChecksLevel1ByRule()
commItem.SelfCheckResult = selfChecks.Static() //自查统计数据
rsp.List = append(rsp.List, commItem)
}
return
... ... @@ -1730,9 +1672,8 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove
// 我的收藏
func MyCollectChance(header *protocol.RequestHeader, request *protocol.MyCollectChanceRequest) (rsp *protocol.MyCollectChanceResponse, err error) {
var (
myChances []protocol.ChanceCollectItemOrm
ormItems []protocol.ChanceCollectItemOrm
total int
provider *protocol.BaseUserInfo
favorite *models.ChanceFavorite
)
if request.LastId > 0 {
... ... @@ -1742,7 +1683,7 @@ func MyCollectChance(header *protocol.RequestHeader, request *protocol.MyCollect
}
request.LastId = favorite.CollectTime.Unix()
}
if total, err = models.GetChanceCollect(header.UserId, request.LastId, request.PageSize, &myChances); err != nil {
if total, err = models.GetChanceCollect(header.UserId, request.LastId, request.PageSize, &ormItems); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ... @@ -1751,67 +1692,38 @@ func MyCollectChance(header *protocol.RequestHeader, request *protocol.MyCollect
return
}
rsp = &protocol.MyCollectChanceResponse{Total: total}
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
for i := 0; i < len(ormItems); i++ {
ormItem := ormItems[i]
commItem := &protocol.CommonListItem{}
commItem.ReviewStatus = chance.ReviewStatus
commItem.ChanceId = chance.ChanceId
if len(chance.SourceContent) == 0 || chance.ChanceEnableStatus == 0 { //机会删除
commItem.ChanceStatus = protocol.ChanceStatusDelete
}
if chance.Status == models.ChanceStatusClose { //机会关闭
commItem.ChanceStatus = protocol.ChanceStatusClose
}
commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem.CommChanceItemOrm)
commItem.ReviewStatus = ormItem.ReviewStatus
commItem.ChanceId = ormItem.ChanceId
commItem.Chance.UpdateTime = 0
commItem.Chance.ApproveTime = 0
if chance.ChanceUserId > 0 {
if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(err)
//return
} else {
item := protocol.ChanceItem{
Id: chance.ChanceId,
Provider: provider,
CreateTime: chance.CreateTime.Unix() * 1000,
PublicStatus: chance.PublishStatus,
}
jsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = clearEmptyForm(item.FormList)
jsonUnmarshal(chance.Images, &item.Pictures)
jsonUnmarshal(chance.Voices, &item.Speechs)
jsonUnmarshal(chance.Videos, &item.Videos)
commItem.Chance = item
}
}
commItem.ReviewStatus = chance.ReviewStatus
{
//chanceData
var chanceData = protocol.ChanceData{
ThumbsUpTotal: chance.ZanTotal,
CommentTotal: chance.CommentTotal,
PageViewTotal: chance.ViewTotal,
ThumbsUpTotal: ormItem.ZanTotal,
CommentTotal: ormItem.CommentTotal,
PageViewTotal: ormItem.ViewTotal,
}
chanceData.IsThumbsUp, chanceData.IsCollect, _ = getChanceMarkFlag(header, chance.ChanceId)
chanceData.IsThumbsUp, chanceData.IsCollect, _ = getChanceMarkFlag(header, ormItem.ChanceId)
commItem.ChanceData = chanceData
}
{
//做一次查询 查回所有的模板数据
commItem.ChanceTemplate = getTemplate(chance.TemplateId)
commItem.ChanceType = getChanceType(chance.ChanceTypeId)
}
{
commItem.ChanceTemplate = getTemplate(ormItem.TemplateId)
commItem.ChanceType = getChanceType(ormItem.ChanceTypeId)
//收藏数据
collect := protocol.CollectData{
Id: chance.CollectId,
CollectTime: chance.CollectTime.Unix() * 1000,
Id: ormItem.CollectId,
CollectTime: ormItem.CollectTime.Unix() * 1000,
}
if collect.CollectTime <= 0 && chance.UpdateTime.Unix() > 0 {
collect.CollectTime = chance.UpdateTime.Unix() * 1000
if collect.CollectTime <= 0 && ormItem.UpdateTime.Unix() > 0 {
collect.CollectTime = ormItem.UpdateTime.Unix() * 1000
}
//收藏数据
commItem.CollectData = collect
//commItem.ChanceId = chance.ChanceId
}
rsp.List = append(rsp.List, commItem)
}
agg.ValidChancePermission(header.UserId, header.CompanyId, rsp.List)
... ... @@ -1821,9 +1733,8 @@ func MyCollectChance(header *protocol.RequestHeader, request *protocol.MyCollect
//我点赞的机会
func MyThumbUpChance(header *protocol.RequestHeader, request *protocol.MyThumbUpChanceRequest) (rsp *protocol.MyThumbUpChanceResponse, err error) {
var (
myChances []protocol.ChanceThumbUpItemOrm
ormItems []protocol.ChanceThumbUpItemOrm
total int
provider *protocol.BaseUserInfo
favorite *models.ChanceFavorite
)
if request.LastId > 0 {
... ... @@ -1833,7 +1744,7 @@ func MyThumbUpChance(header *protocol.RequestHeader, request *protocol.MyThumbUp
}
request.LastId = favorite.ZanTime.Unix()
}
if total, err = models.GetChanceThumbUp(header.UserId, request.LastId, request.PageSize, &myChances); err != nil {
if total, err = models.GetChanceThumbUp(header.UserId, request.LastId, request.PageSize, &ormItems); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ... @@ -1842,63 +1753,38 @@ func MyThumbUpChance(header *protocol.RequestHeader, request *protocol.MyThumbUp
return
}
rsp = &protocol.MyThumbUpChanceResponse{Total: total}
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
for i := 0; i < len(ormItems); i++ {
ormItem := ormItems[i]
commItem := &protocol.CommonListItem{}
commItem.ReviewStatus = chance.ReviewStatus
commItem.ChanceId = chance.ChanceId
if len(chance.SourceContent) == 0 || chance.ChanceEnableStatus == 0 { //机会删除
commItem.ChanceStatus = protocol.ChanceStatusDelete
}
if chance.Status == models.ChanceStatusClose { //机会关闭
commItem.ChanceStatus = protocol.ChanceStatusClose
}
if chance.ChanceUserId > 0 {
if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(err)
//return
} else {
item := protocol.ChanceItem{
Id: chance.ChanceId,
Provider: provider,
CreateTime: chance.CreateTime.Unix() * 1000,
PublicStatus: chance.PublishStatus,
}
jsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = clearEmptyForm(item.FormList)
jsonUnmarshal(chance.Images, &item.Pictures)
jsonUnmarshal(chance.Voices, &item.Speechs)
jsonUnmarshal(chance.Videos, &item.Videos)
commItem.Chance = item
}
}
commItem.ReviewStatus = chance.ReviewStatus
{
commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem.CommChanceItemOrm)
commItem.ReviewStatus = ormItem.ReviewStatus
commItem.ChanceId = ormItem.ChanceId
commItem.Chance.UpdateTime = 0
commItem.Chance.ApproveTime = 0
//点赞收藏数据
var chanceData = protocol.ChanceData{
ThumbsUpTotal: chance.ZanTotal,
CommentTotal: chance.CommentTotal,
PageViewTotal: chance.ViewTotal,
ThumbsUpTotal: ormItem.ZanTotal,
CommentTotal: ormItem.CommentTotal,
PageViewTotal: ormItem.ViewTotal,
}
chanceData.IsThumbsUp, chanceData.IsCollect, _ = getChanceMarkFlag(header, chance.ChanceId)
chanceData.IsThumbsUp, chanceData.IsCollect, _ = getChanceMarkFlag(header, ormItem.ChanceId)
commItem.ChanceData = chanceData
}
{
//做一次查询 查回所有的模板数据
commItem.ChanceTemplate = getTemplate(chance.TemplateId)
commItem.ChanceType = getChanceType(chance.ChanceTypeId)
}
{
//模板数据
commItem.ChanceTemplate = getTemplate(ormItem.TemplateId)
commItem.ChanceType = getChanceType(ormItem.ChanceTypeId)
//点赞数据
thumb := protocol.ThumbUpData{
Id: chance.CollectId,
ThumbUpTime: chance.ZanTime.Unix() * 1000,
Id: ormItem.CollectId,
ThumbUpTime: ormItem.ZanTime.Unix() * 1000,
}
if thumb.ThumbUpTime <= 0 && chance.UpdateTime.Unix() > 0 {
thumb.ThumbUpTime = chance.UpdateTime.Unix() * 1000
if thumb.ThumbUpTime <= 0 && ormItem.UpdateTime.Unix() > 0 {
thumb.ThumbUpTime = ormItem.UpdateTime.Unix() * 1000
}
//收藏数据
commItem.ThumbUpData = thumb
}
rsp.List = append(rsp.List, commItem)
}
agg.ValidChancePermission(header.UserId, header.CompanyId, rsp.List)
... ... @@ -1908,11 +1794,11 @@ func MyThumbUpChance(header *protocol.RequestHeader, request *protocol.MyThumbUp
//我的评论
func MyComment(header *protocol.RequestHeader, request *protocol.MyCommentRequest) (rsp *protocol.MyCommentResponse, err error) {
var (
myChances []protocol.ChanceCommentItemOrm
ormItems []protocol.ChanceCommentItemOrm
total int
provider *protocol.BaseUserInfo
)
if total, err = models.GetChanceComment(header.UserId, request.LastId, request.PageSize, &myChances); err != nil {
if total, err = models.GetChanceComment(header.UserId, request.LastId, request.PageSize, &ormItems); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ... @@ -1925,47 +1811,30 @@ func MyComment(header *protocol.RequestHeader, request *protocol.MyCommentReques
log.Error(err)
return
}
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
for i := 0; i < len(ormItems); i++ {
ormItem := ormItems[i]
commItem := &protocol.CommonListItem{}
commItem.ChanceId = chance.SourceId
if chance.SourceType == protocol.SourceTypeChance {
commItem.ReviewStatus = chance.ReviewStatus
if len(chance.SourceContent) == 0 { //机会删除
commItem.ChanceStatus = protocol.ChanceStatusDelete
} else if chance.ChanceEnableStatus == 0 { //机会关闭
commItem.ChanceStatus = protocol.ChanceStatusClose
}
if chance.Status == models.ChanceStatusClose { //机会关闭
commItem.ChanceStatus = protocol.ChanceStatusClose
}
item := protocol.ChanceItem{
Id: chance.SourceId,
Provider: provider,
CreateTime: chance.CreateTime.Unix() * 1000,
PublicStatus: chance.PublishStatus,
}
jsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = clearEmptyForm(item.FormList)
jsonUnmarshal(chance.Images, &item.Pictures)
jsonUnmarshal(chance.Voices, &item.Speechs)
jsonUnmarshal(chance.Videos, &item.Videos)
commItem.Chance = item
commItem.ReviewStatus = chance.ReviewStatus
}
if chance.SourceType == protocol.SourceTypeComment {
commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem.CommChanceItemOrm)
commItem.ReviewStatus = ormItem.ReviewStatus
commItem.ChanceId = ormItem.SourceId
commItem.Chance.UpdateTime = 0
commItem.Chance.ApproveTime = 0
commItem.Chance.Provider = provider
//被评论的数据内容
if ormItem.SourceType == protocol.SourceTypeComment {
commItem.CommentedData = protocol.CommentData{
Id: chance.SourceId,
Content: chance.CommentedContent,
CommentTime: chance.CommentedTime.Unix() * 1000,
Id: ormItem.SourceId,
Content: ormItem.CommentedContent,
CommentTime: ormItem.CommentedTime.Unix() * 1000,
}
}
//评论内容
commItem.CommentData = protocol.CommentData{
Id: chance.CommentId,
CommentTime: chance.CommentTime.Unix() * 1000,
Content: chance.CommentContent,
Id: ormItem.CommentId,
CommentTime: ormItem.CommentTime.Unix() * 1000,
Content: ormItem.CommentContent,
}
commItem.SourceType = chance.SourceType
commItem.SourceType = ormItem.SourceType
rsp.List = append(rsp.List, commItem)
}
agg.ValidChancePermission(header.UserId, header.CompanyId, rsp.List)
... ... @@ -2105,7 +1974,8 @@ func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetail
UpdateTime: chance.UpdateAt.Unix() * 1000,
}
jsonUnmarshal(chance.SourceContent, &item.FormList)
jsonUnmarshal(chance.SelfChecks, &item.SelfChecks)
//jsonUnmarshal(chance.SelfChecks, &item.SelfChecks)
item.SelfChecks = agg.GetChanceSelfChecks(chance)
item.FormList = clearEmptyForm(item.FormList)
if chanceData, err = models.GetChanceDataByChanceId(chance.Id); err == nil {
... ... @@ -2351,9 +2221,29 @@ func ChanceReviseDetail(header *protocol.RequestHeader, request *protocol.Chance
func CheckQuestions(header *protocol.RequestHeader, request *protocol.CheckQuestionsRequest) (rsp *protocol.CheckQuestionsResponse, err error) {
var ()
rsp = &protocol.CheckQuestionsResponse{}
switch request.Type {
case 0: //自查问题列表
rsp.Questions, err = agg.GetCheckQuestionsByChanceId(header, request.ChanceId)
if err != nil {
log.Error(err)
return
}
case 1: //筛选结果问题列表
rsp.Questions, err = agg.GetCheckQuestionsByChanceCheckResult(header, request.ChanceId)
if err == orm.ErrNoRows || len(rsp.Questions) == 0 {
rsp.Questions, err = agg.GetCheckQuestionsByChanceId(header, request.ChanceId)
if err != nil {
log.Error(err)
return
}
err = nil
}
for i := range rsp.Questions {
rsp.Questions[i].CheckOptions = protocol.CheckOptionsApprove
//if rsp.Questions[i].ParentId!=0{
// rsp.Questions[i].Title= rsp.Questions[i].CheckItem
//}
}
}
return
}
... ...
package chance
import (
"fmt"
"github.com/astaxie/beego/orm"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/idgen"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/internal/utils"
"opp/models"
"opp/protocol"
"opp/services/agg"
"strings"
"time"
)
//SiftingPool 筛选池
func SiftingPool(header *protocol.RequestHeader, request *protocol.SiftingPoolRequest) (rsp *protocol.SiftingPoolResponse, err error) {
var (
ormItems []protocol.ChanceSiftItemOrm
)
rsp = &protocol.SiftingPoolResponse{}
rsp.List = make([]protocol.CommonListItem, 0)
//测试使用
if request.Uid != 0 {
header.UserId = request.Uid
}
if rsp.Total, err = models.GetSiftingChance(header.UserId, request.SubmitStatus, protocol.None, request.Offset(), request.PageSize, &ormItems); err != nil {
if err == orm.ErrNoRows {
err = nil
return
}
log.Error(err)
return
}
for i := 0; i < len(ormItems); i++ {
ormItem := ormItems[i]
commItem := agg.NewCommonListItem(header, ormItem.CommChanceItemOrm)
commItem.Chance.CreateTime = ormItem.ChanceApproveTime.Unix() * 1000
commItem.Chance.UpdateTime = 0
commItem.Chance.ApproveTime = 0
if request.SubmitStatus == protocol.Submited {
commItem.Chance.CreateTime = ormItem.SubmitCheckTime.Unix() * 1000
}
//点赞评论数据
var chanceData = protocol.ChanceData{
PageViewTotal: ormItem.ViewTotal,
}
commItem.ChanceData = chanceData
rsp.List = append(rsp.List, commItem)
}
return
}
//筛选结果
func SiftingResults(header *protocol.RequestHeader, request *protocol.SiftingResultsRequest) (rsp *protocol.SiftingResultsResponse, err error) {
var (
ormItems []protocol.ChanceSiftResultOrm
)
rsp = &protocol.SiftingResultsResponse{}
rsp.List = make([]protocol.CommonListItem, 0)
//测试使用
if request.Uid != 0 {
header.UserId = request.Uid
}
if rsp.Total, err = models.GetSiftingResults(header.UserId, protocol.Submited, request.SiftedStatus, request.Offset(), request.PageSize, &ormItems); err != nil {
if err == orm.ErrNoRows {
err = nil
return
}
log.Error(err)
return
}
for i := 0; i < len(ormItems); i++ {
ormItem := ormItems[i]
commItem := agg.NewCommonListItem(header, ormItem.CommChanceItemOrm)
commItem.Chance.CreateTime = ormItem.CheckTime.Unix() * 1000
commItem.Chance.UpdateTime = 0
commItem.Chance.ApproveTime = 0
//点赞评论数据
var chanceData = protocol.ChanceData{
PageViewTotal: ormItem.ViewTotal,
}
commItem.ChanceData = chanceData
rsp.List = append(rsp.List, commItem)
}
return
}
//提交自查
func SubmitChecks(header *protocol.RequestHeader, request *protocol.SubmitChecksRequest) (rsp *protocol.SubmitChecksResponse, err error) {
var (
p *models.AuditFlowProcess
)
//测试
if request.Uid != 0 {
header.UserId = request.Uid
}
if err = request.SelfChecks.SetSelfChecksLevel1ByRule(); err != nil {
log.Error(err)
return
}
if _, result := CheckIsCommitAllCheck(request.ChanceId); result {
err = protocol.NewCustomMessage(1, "所有人均已提交,不允许修改自查内容")
return
}
if p, err = models.GetAuditorLatestAuditFlowProcess(request.ChanceId, header.UserId); err != nil {
log.Error(request.ChanceId, header.UserId, err)
if err == orm.ErrNoRows {
err = nil
}
return
}
rsp = &protocol.SubmitChecksResponse{}
o := orm.NewOrm()
o.Begin()
var (
DeleteAll = `delete from chance_check_result where chance_id =? and user_company_id=? `
UpdateCommitStatus = `update audit_flow_process set submit_check_status=? ,submit_check_time=now() where chance_id=? and id=?`
UpdateChanceCheckResultStatus = `update chance set check_result_status=?,check_result=? where id=?`
)
if err = utils.ExecuteSQLWithOrmer(o, DeleteAll, request.ChanceId, header.UserId); err != nil {
log.Error(err)
o.Rollback()
return
}
var groupIdx = -1
for i := range request.SelfChecks {
c := request.SelfChecks[i]
m := NewChanceCheckResult(c, request.ChanceId, header.UserId)
if groupIdx == -1 || request.SelfChecks[groupIdx].GroupId != request.SelfChecks[i].GroupId {
groupIdx = i
}
if c.Id == 0 {
m.CheckId = i + 1
m.CheckPid = int64(groupIdx + 1)
if groupIdx == i {
m.CheckPid = 0
}
} else {
m.CheckId = int(c.Id)
m.CheckPid = int64(c.ParentId)
}
if _, err = o.Insert(m); err != nil {
log.Error(err)
o.Rollback()
return
}
}
//更新审核人提交状态
if err = utils.ExecuteSQLWithOrmer(o, UpdateCommitStatus, protocol.Submited, request.ChanceId, p.Id); err != nil {
log.Error(err)
o.Rollback()
return
}
//插入一条数据
o.Commit()
//更新机会筛选状态
if _, result := CheckIsCommitAllCheck(request.ChanceId); result {
var results []*models.ChanceCheckResult
if results, err = models.GetCheckResultsByChanceId(request.ChanceId); err != nil {
log.Error(err)
return
}
var checkResult = collectChanceCheckResultData(results)
if err = utils.ExecuteSQLWithOrmer(o, UpdateChanceCheckResultStatus, protocol.Waiting, common.AssertJson(checkResult), request.ChanceId); err != nil {
log.Error(err)
return
}
}
return
}
func NewChanceCheckResult(c protocol.SelfCheck, chanceId int64, uid int64) *models.ChanceCheckResult {
//不是否的时候 不需要理由
if c.Answer != protocol.OptionNo {
c.Reason = ""
}
return &models.ChanceCheckResult{
Id: idgen.Next(),
ChanceId: chanceId,
GroupId: c.GroupId,
CheckItem: c.CheckItem,
Answer: c.Answer,
Reason: c.Reason,
UserCompanyId: uid,
CreateAt: time.Now(),
}
}
//判断审核人筛选结果是否都已提交
func CheckIsCommitAllCheck(chanceId int64) (err error, result bool) {
var (
audits []*models.AuditFlowProcess
submiters []int64
)
result = false
if audits, err = models.GetChanceAllAuditors(chanceId); err != nil {
log.Error(err)
return
}
if submiters, err = models.GetCheckResultAllSubmitters(chanceId); err != nil {
log.Error(err)
return
}
if len(audits) == len(submiters) {
result = true
}
return
}
type chanceCheckResultTotal struct {
GroupId int64
CheckItem string
CheckId int64
CheckPid int64
AnswerYes int
AnswerNo int
AnswerAny int
Child []*chanceCheckResultTotal
}
//collectChanceCheckResultData 汇总机会自查内容筛选结果
func collectChanceCheckResultData(checkResultData []*models.ChanceCheckResult) protocol.SelfChecks {
checkResultMap := map[int]*chanceCheckResultTotal{}
checkResultSlice := []*chanceCheckResultTotal{}
for i := range checkResultData {
resultData := checkResultData[i]
answerYes := 0
answerNo := 0
answerAny := 0
switch resultData.Answer {
case "是":
answerYes++
case "否":
answerNo++
case "不清楚":
answerAny++
}
if _, ok := checkResultMap[resultData.CheckId]; !ok {
r := &chanceCheckResultTotal{
CheckId: int64(resultData.CheckId),
CheckPid: resultData.CheckPid,
CheckItem: resultData.CheckItem,
GroupId: resultData.GroupId,
AnswerYes: answerYes,
AnswerNo: answerNo,
AnswerAny: answerAny,
}
checkResultMap[resultData.CheckId] = r
checkResultSlice = append(checkResultSlice, r)
} else {
checkResultMap[resultData.CheckId].AnswerYes += answerYes
checkResultMap[resultData.CheckId].AnswerNo += answerNo
checkResultMap[resultData.CheckId].AnswerAny += answerAny
}
}
//构建层级关系
for i := range checkResultSlice {
if checkResultSlice[i].CheckPid == 0 {
continue
}
pid := int(checkResultSlice[i].CheckPid)
if _, ok := checkResultMap[pid]; ok {
checkResultMap[pid].Child = append(checkResultMap[pid].Child, checkResultSlice[i])
}
}
var selfCheckData []protocol.SelfCheck
for i := range checkResultSlice {
if checkResultSlice[i].CheckPid > 0 {
continue
}
dd := protocol.SelfCheck{
CheckItem: checkResultSlice[i].CheckItem,
GroupId: checkResultSlice[i].GroupId,
Id: checkResultSlice[i].CheckId,
ParentId: checkResultSlice[i].CheckPid,
}
if checkResultSlice[i].AnswerNo > 0 {
dd.Answer = protocol.OptionNo
}
if checkResultSlice[i].AnswerYes > 0 && checkResultSlice[i].AnswerNo == 0 && checkResultSlice[i].AnswerAny == 0 {
dd.Answer = protocol.OptionYes
}
if checkResultSlice[i].AnswerNo == 0 && checkResultSlice[i].AnswerAny > 0 {
dd.Answer = protocol.OptionUncertain
}
selfCheckData = append(selfCheckData, dd)
for j := range checkResultSlice[i].Child {
child := checkResultSlice[i].Child[j]
dd := protocol.SelfCheck{
CheckItem: child.CheckItem,
GroupId: child.GroupId,
Id: child.CheckId,
ParentId: child.CheckPid,
}
if child.AnswerNo > 0 {
dd.Answer = protocol.OptionNo
}
if child.AnswerYes > 0 && child.AnswerNo == 0 && child.AnswerAny == 0 {
dd.Answer = protocol.OptionYes
}
if child.AnswerNo == 0 && child.AnswerAny > 0 {
dd.Answer = protocol.OptionUncertain
}
selfCheckData = append(selfCheckData, dd)
}
}
return selfCheckData
}
//筛选历史
func SiftingResultsItemHistory(header *protocol.RequestHeader, request *protocol.SiftingResultsItemHistoryRequest) (rsp *protocol.SiftingResultsItemHistoryResponse, err error) {
var (
checkResults []*models.ChanceCheckResult
ids []int64
)
rsp = &protocol.SiftingResultsItemHistoryResponse{}
if checkResults, err = models.GetCheckResultsByChanceId(request.ChanceId); err != nil {
if err == orm.ErrNoRows {
err = nil
return
}
log.Error(err)
return
}
rsp.SiftingResults = NewSiftingResults(checkResults)
if ids, err = models.GetCheckResultAllSubmitters(request.ChanceId); err == nil {
rsp.TotalSubmitters = len(ids)
}
for i := range checkResults {
item := checkResults[i]
rsp.SiftingResults.AddStatic(item.CheckId, item.Answer)
}
rsp.SiftingResults.SetSelfChecksLevel1ByRule()
return
}
//新建筛选结果列表
func NewSiftingResults(checkResults []*models.ChanceCheckResult) protocol.SiftingResults {
var rsp []protocol.SiftingResult
var maps = make(map[int]*protocol.SiftingResult, 0)
var ids []int
for i := range checkResults {
r := checkResults[i]
var tmp *protocol.SiftingResult
var ok bool
new := &protocol.SiftingResult{
CheckId: r.CheckId,
CheckParentId: r.CheckPid,
CheckItem: r.CheckItem,
Title: r.CheckItem,
SubSiftingResults: make([]protocol.SiftingResult, 0),
}
if tmp, ok = maps[new.CheckId]; !ok && new.CheckParentId == 0 {
new.Title = fmt.Sprintf("%v、%v", len(ids)+1, new.CheckItem) //父级标题 1、素食为主 子级标题:素食为主
maps[new.CheckId] = new
ids = append(ids, new.CheckId)
}
//已存在的向子级增加一条记录
if tmp, ok = maps[int(new.CheckParentId)]; ok {
var exists bool = false
for i := range tmp.SubSiftingResults {
if tmp.SubSiftingResults[i].CheckId == new.CheckId {
exists = true
break
}
}
if !exists {
tmp.SubSiftingResults = append(tmp.SubSiftingResults, *new)
}
}
}
for i := range ids {
if v, ok := maps[ids[i]]; ok {
rsp = append(rsp, *v)
}
}
return rsp
}
//筛选历史详情
func SiftingResultsItemDetail(header *protocol.RequestHeader, request *protocol.SiftingResultsItemDetailRequest) (rsp *protocol.SiftingResultsItemDetailResponse, err error) {
var (
checkResults []*models.ChanceCheckResult
sortList []string = []string{protocol.OptionYes, protocol.OptionNo, protocol.OptionUncertain}
)
rsp = &protocol.SiftingResultsItemDetailResponse{}
if checkResults, err = models.GetCheckResultsByCheckId(request.ChanceId, request.CheckId); err != nil {
if err == orm.ErrNoRows {
err = nil
return
}
log.Error(err)
return
}
var resultsMap = make(map[string]protocol.SiftingResultDetail)
for i := range checkResults {
checkResult := checkResults[i]
answer := strings.TrimSpace(checkResult.Answer)
if len(answer) == 0 {
continue
}
/*提交人信息*/
var provider *protocol.BaseUserInfo
if provider, err = agg.GetUserBaseInfo(checkResult.UserCompanyId, header.CompanyId); err != nil {
log.Error(err)
return
}
commitItem := protocol.SiftingCommitItem{
Provider: provider,
Reason: checkResult.Reason,
}
//追加到Map列表
if v, ok := resultsMap[answer]; ok {
v.Items = append(v.Items, commitItem)
resultsMap[answer] = v
} else {
resultsMap[answer] = protocol.SiftingResultDetail{
Option: answer,
Items: []protocol.SiftingCommitItem{commitItem},
}
}
}
for i := range sortList {
//返回数据
if v, ok := resultsMap[sortList[i]]; ok {
v.TotalSubmitters = len(v.Items)
rsp.SiftingResultDetails = append(rsp.SiftingResultDetails, v)
rsp.TotalSubmitters += len(v.Items)
}
}
return
}
... ...
package chance
import (
"opp/protocol"
"testing"
)
type A []int
func (a A) Change() {
if len(a) == 0 {
return
}
a[0] = 5
}
func TestArrayStruct(t *testing.T) {
var a = A([]int{1, 2})
//a.Change()
var b = a
b.Change()
t.Log(a)
}
func TestSelfChecks(t *testing.T) {
var selfs = []protocol.SelfCheck{
{
GroupId: 1,
CheckItem: "1",
},
{
GroupId: 1,
Answer: "否",
},
{
GroupId: 1,
Answer: "是",
},
{
GroupId: 1,
Answer: "不清楚",
},
{
GroupId: 2,
CheckItem: "2",
},
{
GroupId: 2,
Answer: "否",
},
{
GroupId: 2,
Answer: "否",
},
{
GroupId: 2,
Answer: "不清楚",
},
}
var s = protocol.SelfChecks(selfs)
s.SetSelfChecksLevel1ByRule()
t.Log(s[0], s[4])
}
... ...
... ... @@ -303,11 +303,10 @@ func MsgCompanyNotice(header *protocol.RequestHeader, request *protocol.MsgCompa
//消息中心-机会审核消息
func MsgChanceApprove(header *protocol.RequestHeader, request *protocol.MsgChanceApproveRequest) (rsp *protocol.MsgChanceApproveResponse, err error) {
var (
myChances []protocol.MsgChanceApproveItemOrm
ormItems []protocol.MsgChanceApproveItemOrm
total int
provider *protocol.BaseUserInfo
)
if total, err = models.GetChanceMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeAudit, &myChances); err != nil {
if total, err = models.GetChanceMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeAudit, &ormItems); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ... @@ -317,49 +316,18 @@ func MsgChanceApprove(header *protocol.RequestHeader, request *protocol.MsgChanc
}
rsp = &protocol.MsgChanceApproveResponse{Total: total}
rsp.List = make([]protocol.MsgCommonListItem, 0)
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
for i := 0; i < len(ormItems); i++ {
ormItem := ormItems[i]
commItem := protocol.MsgCommonListItem{}
commItem.ReviewStatus = chance.ReviewStatus
if len(chance.SourceContent) == 0 { //机会删除
commItem.ChanceStatus = protocol.ChanceStatusDelete
} else if chance.ChanceEnableStatus == 0 { //机会关闭
commItem.ChanceStatus = protocol.ChanceStatusDelete
}
if chance.Status == models.ChanceStatusClose {
commItem.ChanceStatus = protocol.ChanceStatusClose
}
if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(err)
continue
} else {
item := protocol.ChanceItem{
Id: chance.ChanceId,
Provider: provider,
CreateTime: chance.CreateTime.Unix() * 1000,
}
utils.JsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = agg.ClearEmptyForm(item.FormList)
utils.JsonUnmarshal(chance.Images, &item.Pictures)
utils.JsonUnmarshal(chance.Voices, &item.Speechs)
utils.JsonUnmarshal(chance.Videos, &item.Videos)
commItem.Chance = item
}
commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem.CommChanceItemOrm)
commItem.ReviewStatus = ormItem.ReviewStatus
//if chance.ReviewStatus == protocol.ReviewStatusPass {
// var approveData *protocol.ApproveData
// utils.JsonUnmarshal(chance.ApproveData, &approveData)
// if approveData != nil {
// commItem.Score = approveData.Score
// }
//}
commItem.MsgId = chance.Id
commItem.MsgTime = chance.MsgTime.Unix() * 1000
commItem.MsgId = ormItem.Id
commItem.MsgTime = ormItem.MsgTime.Unix() * 1000
//审核完有审核数据
commItem.Message = chance.Message
commItem.IsRead = chance.IsRead == 1
commItem.ChanceId = chance.ChanceId
commItem.Message = ormItem.Message
commItem.IsRead = ormItem.IsRead == 1
commItem.ChanceId = ormItem.ChanceId
rsp.List = append(rsp.List, commItem)
}
return
... ... @@ -368,11 +336,10 @@ func MsgChanceApprove(header *protocol.RequestHeader, request *protocol.MsgChanc
// 消息中心-我提交的
func MsgChanceSubmit(header *protocol.RequestHeader, request *protocol.MsgChanceSubmitRequest) (rsp *protocol.MsgChanceSubmitResponse, err error) {
var (
myChances []protocol.MsgChanceApproveItemOrm
total int
provider *protocol.BaseUserInfo
ormItems []protocol.MsgChanceApproveItemOrm
)
if total, err = models.GetChanceMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeAuditBy, &myChances); err != nil {
rsp = &protocol.MsgChanceSubmitResponse{List: make([]protocol.MsgCommonListItem, 0)}
if rsp.Total, err = models.GetChanceMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeAuditBy, &ormItems); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ... @@ -380,62 +347,33 @@ func MsgChanceSubmit(header *protocol.RequestHeader, request *protocol.MsgChance
log.Error(err)
return
}
rsp = &protocol.MsgChanceSubmitResponse{Total: total}
rsp.List = make([]protocol.MsgCommonListItem, 0)
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
for i := 0; i < len(ormItems); i++ {
ormItem := ormItems[i]
commItem := protocol.MsgCommonListItem{}
commItem.ReviewStatus = chance.ReviewStatus
if len(chance.SourceContent) == 0 { //机会删除
commItem.ChanceStatus = protocol.ChanceStatusDelete
} else if chance.ChanceEnableStatus == 0 { //机会关闭
commItem.ChanceStatus = protocol.ChanceStatusDelete
}
if chance.Status == models.ChanceStatusClose {
commItem.ChanceStatus = protocol.ChanceStatusClose
}
approveUserId := chance.ChanceUserId
if chance.SenderUserId != 0 {
approveUserId = chance.SenderUserId
}
if provider, err = agg.GetUserBaseInfo(approveUserId, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(err)
continue
} else {
item := protocol.ChanceItem{
Id: chance.ChanceId,
Provider: provider,
CreateTime: chance.CreateTime.Unix() * 1000,
}
utils.JsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = agg.ClearEmptyForm(item.FormList)
utils.JsonUnmarshal(chance.Images, &item.Pictures)
utils.JsonUnmarshal(chance.Voices, &item.Speechs)
utils.JsonUnmarshal(chance.Videos, &item.Videos)
commItem.Chance = item
//注:此处是审核人的用户信息
if ormItem.SenderUserId != 0 {
ormItem.CommChanceItemOrm.ChanceUserId = ormItem.SenderUserId
}
commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem.CommChanceItemOrm)
commItem.ReviewStatus = ormItem.ReviewStatus
//if chance.ReviewStatus == protocol.ReviewStatusPass {
// var approveData *protocol.ApproveData
// utils.JsonUnmarshal(chance.ApproveData, &approveData)
// if approveData != nil {
// commItem.Score = approveData.Score
// }
//}
if len(chance.Data) > 0 && chance.ReviewStatus != protocol.ReviewStatusReturn { //获取评分 && chance.ReviewStatus == protocol.ReviewStatusPass
//审核数据
if len(ormItem.Data) > 0 && ormItem.ReviewStatus != protocol.ReviewStatusReturn { //获取评分 && chance.ReviewStatus == protocol.ReviewStatusPass
var msgData *protocol.MsgData
utils.JsonUnmarshal(chance.Data, &msgData)
utils.JsonUnmarshal(ormItem.Data, &msgData)
commItem.Score = msgData.Score
}
commItem.IsRead = chance.IsRead == 1
//审核完有审核数据
commItem.Message = chance.Message
commItem.MsgId = chance.Id
commItem.MsgTime = chance.MsgTime.Unix() * 1000
commItem.ChanceId = chance.ChanceId
if commItem.ChanceId == 0 && chance.SourceId > 0 {
commItem.ChanceId = chance.SourceId
//消息基础数据
commItem.IsRead = ormItem.IsRead == 1
commItem.Message = ormItem.Message
commItem.MsgId = ormItem.Id
commItem.MsgTime = ormItem.MsgTime.Unix() * 1000
commItem.ChanceId = ormItem.ChanceId
if commItem.ChanceId == 0 && ormItem.SourceId > 0 {
commItem.ChanceId = ormItem.SourceId
}
rsp.List = append(rsp.List, commItem) //非指针 append对象完 再修改数据也是无效
}
... ... @@ -445,11 +383,11 @@ func MsgChanceSubmit(header *protocol.RequestHeader, request *protocol.MsgChance
// 消息中心-互动消息.评论
func MsgChanceComment(header *protocol.RequestHeader, request *protocol.MsgChanceCommentRequest) (rsp *protocol.MsgChanceCommentResponse, err error) {
var (
myChances []protocol.ChanceCommentItemOrm
ormItems []protocol.ChanceCommentItemOrm
total int
provider *protocol.BaseUserInfo
)
if total, err = models.GetChanceCommentMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeComment, &myChances); err != nil {
if total, err = models.GetChanceCommentMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeComment, &ormItems); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ... @@ -459,66 +397,46 @@ func MsgChanceComment(header *protocol.RequestHeader, request *protocol.MsgChanc
}
rsp = &protocol.MsgChanceCommentResponse{Total: total}
rsp.List = make([]protocol.MsgCommonListItem, 0)
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
for i := 0; i < len(ormItems); i++ {
ormItem := ormItems[i]
commItem := protocol.MsgCommonListItem{}
if chance.SourceType == protocol.SourceTypeChance {
commItem.ReviewStatus = chance.ReviewStatus
if len(chance.SourceContent) == 0 { //机会删除
commItem.ChanceStatus = protocol.ChanceStatusDelete
} else if chance.ChanceEnableStatus == 0 { //机会关闭
commItem.ChanceStatus = protocol.ChanceStatusClose
}
if chance.Status == models.ChanceStatusClose {
commItem.ChanceStatus = protocol.ChanceStatusClose
}
if chance.ChanceUserId > 0 {
if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(err)
//return
} else {
item := protocol.ChanceItem{
Id: chance.SourceId,
Provider: provider,
CreateTime: chance.CreateTime.Unix() * 1000,
}
utils.JsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = protocol.ClearEmptyForm(item.FormList)
utils.JsonUnmarshal(chance.Images, &item.Pictures)
utils.JsonUnmarshal(chance.Voices, &item.Speechs)
utils.JsonUnmarshal(chance.Videos, &item.Videos)
commItem.Chance = item
}
if ormItem.SourceType == protocol.SourceTypeChance {
commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem.CommChanceItemOrm)
commItem.ReviewStatus = ormItem.ReviewStatus
}
commItem.ReviewStatus = chance.ReviewStatus
}
if chance.SourceType == protocol.SourceTypeComment {
if provider, err = agg.GetUserBaseInfo(chance.CommentedUserId, header.CompanyId); err != nil {
//被评论内容
if ormItem.SourceType == protocol.SourceTypeComment {
if provider, err = agg.GetUserBaseInfo(ormItem.CommentedUserId, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(err)
//return
}
commItem.CommentedData = protocol.CommentData{
Id: chance.SourceId,
Content: chance.CommentedContent,
CommentTime: chance.CommentedTime.Unix() * 1000,
Id: ormItem.SourceId,
Content: ormItem.CommentedContent,
CommentTime: ormItem.CommentedTime.Unix() * 1000,
Provider: provider,
}
}
//评论内容
comment := protocol.CommentData{
Id: chance.CommentId,
CommentTime: chance.CommentTime.Unix() * 1000,
Content: chance.CommentContent,
Id: ormItem.CommentId,
CommentTime: ormItem.CommentTime.Unix() * 1000,
Content: ormItem.CommentContent,
//Provider: provider,
}
comment.Provider, _ = agg.GetUserBaseInfo(chance.SenderUserId, header.CompanyId)
comment.Provider, _ = agg.GetUserBaseInfo(ormItem.SenderUserId, header.CompanyId)
commItem.CommentData = comment
commItem.IsRead = chance.IsRead == 1
commItem.SourceType = chance.SourceType
commItem.MsgId = chance.CommentId
commItem.MsgTime = chance.CommentTime.Unix() * 1000
commItem.ChanceId = chance.ChanceId
//消息基础内容
commItem.IsRead = ormItem.IsRead == 1
commItem.SourceType = ormItem.SourceType
commItem.MsgId = ormItem.CommentId
commItem.MsgTime = ormItem.CommentTime.Unix() * 1000
commItem.ChanceId = ormItem.ChanceId
rsp.List = append(rsp.List, commItem)
}
return
... ... @@ -527,11 +445,11 @@ func MsgChanceComment(header *protocol.RequestHeader, request *protocol.MsgChanc
//消息中心-互动消息.点赞
func MsgChanceThumbUp(header *protocol.RequestHeader, request *protocol.MsgChanceThumbUpRequest) (rsp *protocol.MsgChanceThumbUpResponse, err error) {
var (
myChances []protocol.ChanceCommentItemOrm
ormItems []protocol.ChanceCommentItemOrm
total int
provider *protocol.BaseUserInfo
)
if total, err = models.GetChanceCommentMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeThumbUp, &myChances); err != nil {
if total, err = models.GetChanceCommentMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeThumbUp, &ormItems); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ... @@ -541,65 +459,44 @@ func MsgChanceThumbUp(header *protocol.RequestHeader, request *protocol.MsgChanc
}
rsp = &protocol.MsgChanceThumbUpResponse{Total: total}
rsp.List = make([]protocol.MsgCommonListItem, 0)
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
for i := 0; i < len(ormItems); i++ {
ormItem := ormItems[i]
commItem := protocol.MsgCommonListItem{}
if chance.SourceType == protocol.SourceTypeChance {
commItem.ReviewStatus = chance.ReviewStatus
if len(chance.SourceContent) == 0 { //机会删除
commItem.ChanceStatus = protocol.ChanceStatusDelete
} else if chance.ChanceEnableStatus == 0 { //机会关闭
commItem.ChanceStatus = protocol.ChanceStatusClose
}
if chance.Status == models.ChanceStatusClose {
commItem.ChanceStatus = protocol.ChanceStatusClose
}
if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(err)
//return
} else {
item := protocol.ChanceItem{
Id: chance.SourceId,
Provider: provider,
CreateTime: chance.CreateTime.Unix() * 1000,
}
utils.JsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = protocol.ClearEmptyForm(item.FormList)
utils.JsonUnmarshal(chance.Images, &item.Pictures)
utils.JsonUnmarshal(chance.Voices, &item.Speechs)
utils.JsonUnmarshal(chance.Videos, &item.Videos)
commItem.Chance = item
}
commItem.ReviewStatus = chance.ReviewStatus
if ormItem.SourceType == protocol.SourceTypeChance {
commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem.CommChanceItemOrm)
commItem.ReviewStatus = ormItem.ReviewStatus
}
if chance.SourceType == protocol.SourceTypeComment {
if provider, err = agg.GetUserBaseInfo(chance.CommentedUserId, header.CompanyId); err != nil {
//点赞评论的内容
if ormItem.SourceType == protocol.SourceTypeComment {
if provider, err = agg.GetUserBaseInfo(ormItem.CommentedUserId, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(err)
//return
}
commItem.CommentedData = protocol.CommentData{
Id: chance.SourceId,
Content: chance.CommentedContent,
CommentTime: chance.CommentedTime.Unix() * 1000,
Id: ormItem.SourceId,
Content: ormItem.CommentedContent,
CommentTime: ormItem.CommentedTime.Unix() * 1000,
Provider: provider,
}
}
//点赞数据
thumb := protocol.ThumbUpData{
Id: chance.CommentId,
ThumbUpTime: chance.CommentTime.Unix() * 1000,
Content: chance.CommentContent,
Id: ormItem.CommentId,
ThumbUpTime: ormItem.CommentTime.Unix() * 1000,
Content: ormItem.CommentContent,
//Provider: provider,
}
thumb.Provider, _ = agg.GetUserBaseInfo(chance.SenderUserId, header.CompanyId)
thumb.Provider, _ = agg.GetUserBaseInfo(ormItem.SenderUserId, header.CompanyId)
commItem.ThumbUpData = thumb
commItem.IsRead = chance.IsRead == 1
commItem.SourceType = chance.SourceType
commItem.MsgId = chance.CommentId
commItem.MsgTime = chance.CommentTime.Unix() * 1000
commItem.ChanceId = chance.ChanceId
//消息基础数据
commItem.IsRead = ormItem.IsRead == 1
commItem.SourceType = ormItem.SourceType
commItem.MsgId = ormItem.CommentId
commItem.MsgTime = ormItem.CommentTime.Unix() * 1000
commItem.ChanceId = ormItem.ChanceId
rsp.List = append(rsp.List, commItem)
}
return
... ...
... ... @@ -145,6 +145,25 @@ func CreateUploadVideo(header *protocol.RequestHeader, request *aliyun.CreateUpl
return
}
rsp, err = aliyun.CreateUploadVideo(client, request)
if err != nil {
log.Error(err)
}
return
}
//创建视频上传凭证
func RefreshUploadVideo(header *protocol.RequestHeader, request *aliyun.RefreshUploadVideoRequest) (rsp *aliyun.RefreshUploadVideoResponse, err error) {
var ()
client, e := aliyun.DefaultVodClient()
if e != nil {
log.Error(e)
err = e
return
}
rsp, err = aliyun.RefreshUploadVideo(client, request)
if err != nil {
log.Error(err)
}
return
}
... ... @@ -157,6 +176,9 @@ func CreateUploadImage(header *protocol.RequestHeader, request *aliyun.CreateUpl
err = e
return
}
if len(request.FileName) == 0 {
request.FileName = aliyun.DefaultImageFileName
}
rsp, err = aliyun.CreateUploadImage(client, request)
if err != nil {
log.Error(err)
... ...