|
|
package audit
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"oppmg/common/log"
|
|
|
"oppmg/models"
|
|
|
"oppmg/protocol"
|
...
|
...
|
@@ -21,9 +22,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 +34,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 +43,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 +107,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 +115,17 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64) (protocol.Re |
|
|
for _, v := range data {
|
|
|
t := v.CreateAt.Unix()
|
|
|
item := protocol.RspAuditList{
|
|
|
Id: v.Id,
|
|
|
EnableStatus: v.EnableStatus,
|
|
|
PublishStatus: v.PublishStatus,
|
|
|
Id: 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 +137,15 @@ 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
|
|
|
}
|
|
|
|
|
|
// 机会管理的列表搜索项数据 |
...
|
...
|
|