|
|
package audit
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"oppmg/common/log"
|
|
|
"oppmg/models"
|
|
|
"oppmg/protocol"
|
...
|
...
|
@@ -21,9 +23,11 @@ type SqlData struct { |
|
|
EnableStatus int `orm:"column(enable_status)"`
|
|
|
DiscoveryScore string `orm:"column(discovery_score)"`
|
|
|
CommentTotal string `orm:"column(comment_total)"`
|
|
|
Code string `orm:"column(code)"`
|
|
|
TemplateName string `orm:"column(template_name)"`
|
|
|
}
|
|
|
|
|
|
func GetAuditList(param protocol.RequestAuditList, companyid int64) (protocol.ResponseAuditList, error) {
|
|
|
func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64) (protocol.ResponseAuditList, error) {
|
|
|
|
|
|
var (
|
|
|
datasql = strings.Builder{}
|
...
|
...
|
@@ -31,7 +35,7 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64) (protocol.Re |
|
|
data []SqlData
|
|
|
cnt int
|
|
|
err error
|
|
|
//listdata = make([]protocol.RspAuditList, 0)
|
|
|
cond []interface{}
|
|
|
)
|
|
|
returnData := protocol.ResponseAuditList{
|
|
|
ResponsePageInfo: protocol.ResponsePageInfo{
|
...
|
...
|
@@ -40,15 +44,63 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64) (protocol.Re |
|
|
},
|
|
|
List: make([]protocol.RspAuditList, 0),
|
|
|
}
|
|
|
dataStart := (param.PageIndex - 1) * param.PageSize
|
|
|
datasql.WriteString(`SELECT id,user_id,department_id,audit_template_id,chance_type_id
|
|
|
,publish_status,create_at,review_status,enable_status
|
|
|
,discovery_score,comment_total
|
|
|
FROM chance
|
|
|
limit ?,? `)
|
|
|
datasql.WriteString(`SELECT a.id,a.user_id,a.department_id,a.audit_template_id,a.chance_type_id
|
|
|
,a.publish_status,a.create_at,a.review_status,a.enable_status
|
|
|
,a.discovery_score,a.comment_total,b.name AS template_name ,b.code
|
|
|
FROM chance AS a
|
|
|
JOIN audit_template AS b on a.audit_template_id = b.id
|
|
|
where a.company_id=? `)
|
|
|
|
|
|
countsql.WriteString(`SELECT count(*) FROM chance`)
|
|
|
err = utils.ExecuteQueryOne(&cnt, countsql.String())
|
|
|
countsql.WriteString(`SELECT count(*) FROM chance as a
|
|
|
JOIN audit_template AS b on a.audit_template_id = b.id
|
|
|
where a.company_id=? `)
|
|
|
cond = append(cond, companyid)
|
|
|
if param.ChanceTypeId > 0 {
|
|
|
//一级分类过滤
|
|
|
cond = append(cond, param.ChanceTypeId)
|
|
|
s := ` And a.chance_type_id=? `
|
|
|
datasql.WriteString(s)
|
|
|
countsql.WriteString(s)
|
|
|
}
|
|
|
if param.TempalteId > 0 {
|
|
|
cond = append(cond, param.TempalteId)
|
|
|
s := ` AND a.audit_template_id=? `
|
|
|
datasql.WriteString(s)
|
|
|
countsql.WriteString(s)
|
|
|
}
|
|
|
if param.PublishStatus >= 0 {
|
|
|
cond = append(cond, param.PublishStatus)
|
|
|
s := ` And a.publish_status=? `
|
|
|
datasql.WriteString(s)
|
|
|
countsql.WriteString(s)
|
|
|
}
|
|
|
if param.EnableStatus >= 0 {
|
|
|
cond = append(cond, param.EnableStatus)
|
|
|
s := ` AND a.enable_status=? `
|
|
|
datasql.WriteString(s)
|
|
|
countsql.WriteString(s)
|
|
|
}
|
|
|
if param.ReviewStatus >= 0 {
|
|
|
cond = append(cond, param.ReviewStatus)
|
|
|
s := ` AND a.review_status=? `
|
|
|
datasql.WriteString(s)
|
|
|
countsql.WriteString(s)
|
|
|
}
|
|
|
if param.CreateTimeBegin > 0 && param.CreateTimeEnd > 0 {
|
|
|
cond = append(cond, param.CreateTimeBegin, param.CreateTimeEnd)
|
|
|
s := ` AND (UNIX_TIMESTAMP(a.create_at) BETWEEN ? AND ? ) `
|
|
|
datasql.WriteString(s)
|
|
|
countsql.WriteString(s)
|
|
|
}
|
|
|
if len(param.Code) > 0 {
|
|
|
cond = append(cond, param.Code)
|
|
|
s := ` And b.code=? `
|
|
|
datasql.WriteString(s)
|
|
|
countsql.WriteString(s)
|
|
|
}
|
|
|
dataStart := (param.PageIndex - 1) * param.PageSize
|
|
|
datasql.WriteString(fmt.Sprintf(` limit %d,%d `, dataStart, param.PageSize))
|
|
|
err = utils.ExecuteQueryOne(&cnt, countsql.String(), cond...)
|
|
|
if err != nil {
|
|
|
log.Error("EXCUTE SQL ERR:%s", err)
|
|
|
return returnData, nil
|
...
|
...
|
@@ -56,7 +108,7 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64) (protocol.Re |
|
|
if cnt <= 0 {
|
|
|
return returnData, nil
|
|
|
}
|
|
|
err = utils.ExecuteQueryOne(&data, datasql.String(), dataStart, param.PageSize)
|
|
|
err = utils.ExecuteQueryAll(&data, datasql.String(), cond...)
|
|
|
if err != nil {
|
|
|
log.Error("EXCUTE SQL ERR:%s", err)
|
|
|
return returnData, nil
|
...
|
...
|
@@ -64,10 +116,17 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64) (protocol.Re |
|
|
for _, v := range data {
|
|
|
t := v.CreateAt.Unix()
|
|
|
item := protocol.RspAuditList{
|
|
|
Id: v.Id,
|
|
|
Id: fmt.Sprint(v.Id),
|
|
|
EnableStatus: v.EnableStatus,
|
|
|
EnableStatusName: models.ChanceEnableStatusMap[v.EnableStatus],
|
|
|
PublishStatus: v.PublishStatus,
|
|
|
PublishStatusName: models.ChancePublishStatusMap[v.PublishStatus],
|
|
|
ReviewStatus: v.ReviewStatus,
|
|
|
ReviewStatusName: models.ChanceReviewStatusMap[v.ReviewStatus],
|
|
|
Code: v.Code,
|
|
|
TemplateName: v.TemplateName,
|
|
|
}
|
|
|
|
|
|
if t < 0 {
|
|
|
item.CreateTime = 0
|
|
|
} else {
|
...
|
...
|
@@ -79,15 +138,61 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64) (protocol.Re |
|
|
if d, err := models.GetDepartmentById(v.DepartmentId); err == nil {
|
|
|
item.Department = d.Name
|
|
|
}
|
|
|
if at, err := models.GetAuditTemplateById(v.AuditTemplateId); err == nil {
|
|
|
item.TemplateName = at.Name
|
|
|
item.Code = at.Code
|
|
|
}
|
|
|
if ct, err := models.GetChanceTypeById(v.ChanceTypeId); err == nil {
|
|
|
item.ChanceType = ct.Name
|
|
|
}
|
|
|
returnData.List = append(returnData.List, item)
|
|
|
|
|
|
}
|
|
|
returnData.TotalPage = cnt
|
|
|
returnData.CurrentPage = param.PageIndex
|
|
|
return returnData, nil
|
|
|
}
|
|
|
|
|
|
type ResponseChanceInfo struct {
|
|
|
BaseContent []protocol.InputElement `json:"base_content"`
|
|
|
ExtraContent []protocol.InputElement `json:"extra_content"`
|
|
|
ImageData []models.ChanceDataImage `json:"image_data"`
|
|
|
VideoData []models.ChanceDataVideos `json:"video_data"`
|
|
|
SpeechData []models.ChanceDataSpeechs `json:"speech_data"`
|
|
|
FlowLog []protocol.ChanceFlowLog `json:"flow_log"`
|
|
|
}
|
|
|
|
|
|
//机会详情
|
|
|
func GetChanceDetail(chanceid int64, companyid int64) (ResponseChanceInfo, error) {
|
|
|
var (
|
|
|
chanceInfo *models.Chance
|
|
|
err error
|
|
|
returnData = ResponseChanceInfo{
|
|
|
BaseContent: make([]protocol.InputElement, 0),
|
|
|
ExtraContent: make([]protocol.InputElement, 0),
|
|
|
ImageData: make([]models.ChanceDataImage, 0),
|
|
|
VideoData: make([]models.ChanceDataVideos, 0),
|
|
|
SpeechData: make([]models.ChanceDataSpeechs, 0),
|
|
|
FlowLog: make([]protocol.ChanceFlowLog, 0),
|
|
|
}
|
|
|
)
|
|
|
chanceInfo, err = models.GetChanceById(chanceid)
|
|
|
if err != nil {
|
|
|
log.Error("获取机会详情失败:%s", err)
|
|
|
return returnData, protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
if chanceInfo.CompanyId != companyid {
|
|
|
log.Error("机会的公司不匹配")
|
|
|
return returnData, protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
var (
|
|
|
chanceContent []protocol.InputElement
|
|
|
)
|
|
|
json.Unmarshal([]byte(chanceInfo.Content), &chanceContent)
|
|
|
for i := range chanceContent {
|
|
|
if chanceContent[i].SectionType == 1 {
|
|
|
returnData.BaseContent = append(returnData.BaseContent, chanceContent[i])
|
|
|
}
|
|
|
if chanceContent[i].SectionType == 2 {
|
|
|
returnData.ExtraContent = append(returnData.ExtraContent, chanceContent[i])
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return returnData, nil
|
|
|
} |
...
|
...
|
|