|
|
package audit
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"oppmg/common/log"
|
|
|
"oppmg/models"
|
|
|
"oppmg/protocol"
|
|
|
"oppmg/utils"
|
|
|
)
|
|
|
|
|
|
//GetChanceCheckResultInfo 获取机会详情
|
|
|
func GetChanceCheckResultInfo(chanceId int64, companyid int64) (protocol.ReponseChanceCheckResult, error) {
|
|
|
var (
|
|
|
chanceData *models.Chance
|
|
|
err error
|
|
|
)
|
|
|
rsp := protocol.ReponseChanceCheckResult{
|
|
|
CustomItem: []string{},
|
|
|
CheckData: []protocol.ChanceCheckResultData{},
|
|
|
}
|
|
|
chanceData, err = models.GetChanceById(chanceId)
|
|
|
if err != nil {
|
|
|
log.Error("获取机会数据失败,err:%s", err)
|
|
|
return rsp, protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
if chanceData.CompanyId != companyid {
|
|
|
log.Error("机会的公司数据无法对应")
|
|
|
return rsp, protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
if chanceData.CheckResultStatus < models.CheckResultStatusWait {
|
|
|
log.Error("机会的自查内容筛选状态错误")
|
|
|
return rsp, protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
var (
|
|
|
checkResultData []models.ChanceCheckResult
|
|
|
)
|
|
|
checkResultData, err = models.GetChanceCheckResultByChancce(chanceId)
|
|
|
if err != nil {
|
|
|
log.Error("未获得指定的机会自查内容筛选结果,err;%s", err)
|
|
|
return rsp, nil
|
|
|
}
|
|
|
//组装响应数据
|
|
|
//定义动态数据列
|
|
|
customItems := utils.NewArraySetString()
|
|
|
//自查内容项
|
|
|
checkItems := utils.NewArraySetString()
|
|
|
_ = checkResultData
|
|
|
_ = customItems
|
|
|
_ = checkItems
|
|
|
return rsp, err
|
|
|
}
|
|
|
|
|
|
func GetChanceCheckResultList(pageIndex int, pageSize int, companyId int64, checkResultStatus int8) protocol.ResponseChanceCheckResultList {
|
|
|
type SqlData struct {
|
|
|
Id int64 `orm:"column(id)"`
|
|
|
UserId int64 `orm:"column(user_id)"`
|
|
|
NickName string `orm:"column(nick_name)"`
|
|
|
DepartmentId int64 `orm:"column(department_id)"`
|
|
|
AuditTemplateId int64 `orm:"column(audit_template_id)"`
|
|
|
ChanceTypeId int `orm:"column(chance_type_id)"`
|
|
|
PublishStatus int `orm:"column(publish_status)"`
|
|
|
CreateAt string `orm:"column(create_at)"`
|
|
|
ReviewStatus int8 `orm:"column(review_status)"`
|
|
|
Status int8 `orm:"column(status)"`
|
|
|
DiscoveryScore string `orm:"column(discovery_score)"`
|
|
|
CommentTotal string `orm:"column(comment_total)"`
|
|
|
Code string `orm:"column(code)"`
|
|
|
CheckResultStatus int8 `orm:"column(check_result_status)"`
|
|
|
}
|
|
|
|
|
|
returnData := protocol.ResponseChanceCheckResultList{
|
|
|
ResponsePageInfo: protocol.ResponsePageInfo{
|
|
|
TotalPage: 0,
|
|
|
CurrentPage: pageIndex,
|
|
|
},
|
|
|
List: make([]protocol.RspCheckResultList, 0),
|
|
|
}
|
|
|
datasql := `SELECT a.id,a.department_id,a.audit_template_id,a.chance_type_id
|
|
|
,a.publish_status,a.create_at,a.review_status,a.status,a.check_result_status
|
|
|
,a.discovery_score,a.comment_total ,a.code,d.nick_name,d.id as user_id
|
|
|
FROM chance AS a
|
|
|
LEFt JOIN user_company AS c ON c.id = a.user_id
|
|
|
LEFt JOIN user AS d ON c.user_id = d.id
|
|
|
where a.company_id=? `
|
|
|
countsql := ` SELECT count(*) FROM chance as a
|
|
|
where a.company_id=? `
|
|
|
cond := []interface{}{companyId}
|
|
|
if checkResultStatus > 0 {
|
|
|
datasql += ` AND a.check_result_status=? `
|
|
|
countsql += ` AND a.check_result_status=? `
|
|
|
cond = append(cond, checkResultStatus)
|
|
|
} else {
|
|
|
datasql += ` AND a.check_result_status>0 `
|
|
|
countsql += ` AND a.check_result_status>0 `
|
|
|
}
|
|
|
dataStart := (pageIndex - 1) * pageSize
|
|
|
datasql += fmt.Sprintf(` ORDER BY a.create_at DESC limit %d,%d `, dataStart, pageSize)
|
|
|
var (
|
|
|
cnt int
|
|
|
sqldata []SqlData
|
|
|
err error
|
|
|
)
|
|
|
err = utils.ExecuteQueryOne(&cnt, countsql, cond...)
|
|
|
if err != nil {
|
|
|
log.Error("EXCUTE SQL ERR:%s", err)
|
|
|
return returnData
|
|
|
}
|
|
|
if cnt <= 0 {
|
|
|
return returnData
|
|
|
}
|
|
|
err = utils.ExecuteQueryAll(&sqldata, datasql, cond...)
|
|
|
if err != nil {
|
|
|
log.Error("EXCUTE SQL ERR:%s", err)
|
|
|
return returnData
|
|
|
}
|
|
|
for _, v := range sqldata {
|
|
|
item := protocol.RspCheckResultList{
|
|
|
Id: fmt.Sprint(v.Id),
|
|
|
Status: v.Status,
|
|
|
StatusName: models.ChanceStatusMap[v.Status],
|
|
|
PublishStatus: v.PublishStatus,
|
|
|
PublishStatusName: models.ChancePublishStatusMap[v.PublishStatus],
|
|
|
ReviewStatus: v.ReviewStatus,
|
|
|
ReviewStatusName: models.ChanceReviewStatusMap[v.ReviewStatus],
|
|
|
Code: v.Code,
|
|
|
DiscoveryScore: v.DiscoveryScore,
|
|
|
CommentTotal: v.CommentTotal,
|
|
|
UserName: v.NickName,
|
|
|
CreateTime: v.CreateAt,
|
|
|
CheckResultStatusName: models.CheckResultStatusMap[v.CheckResultStatus],
|
|
|
}
|
|
|
if d, err := models.GetDepartmentById(v.DepartmentId); err == nil {
|
|
|
item.Department = d.Name
|
|
|
}
|
|
|
if ct, err := models.GetChanceTypeById(v.ChanceTypeId); err == nil {
|
|
|
item.ChanceType = ct.Name
|
|
|
}
|
|
|
if tp, err := models.GetAuditTemplateById(v.AuditTemplateId); err == nil {
|
|
|
item.TemplateName = tp.Name
|
|
|
}
|
|
|
returnData.List = append(returnData.List, item)
|
|
|
|
|
|
}
|
|
|
returnData.TotalPage = cnt
|
|
|
returnData.CurrentPage = pageIndex
|
|
|
return returnData
|
|
|
} |
...
|
...
|
|