|
|
package chance
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/astaxie/beego/orm"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/idgen"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
|
...
|
...
|
@@ -8,6 +9,7 @@ import ( |
|
|
"opp/models"
|
|
|
"opp/protocol"
|
|
|
"opp/services/agg"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
...
|
...
|
@@ -80,6 +82,10 @@ func SubmitChecks(header *protocol.RequestHeader, request *protocol.SubmitChecks |
|
|
if request.Uid != 0 {
|
|
|
header.UserId = request.Uid
|
|
|
}
|
|
|
if err = request.SelfChecks.SetSelfChecksLevel1ByRule(); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if p, err = models.GetAuditorLatestAuditFlowProcess(request.ChanceId, header.UserId); err != nil {
|
|
|
log.Error(request.ChanceId, header.UserId, err)
|
|
|
if err == orm.ErrNoRows {
|
...
|
...
|
@@ -179,3 +185,121 @@ func CheckIsCommitAllCheck(chanceId int64) (err error, result bool) { |
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//筛选历史
|
|
|
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)
|
|
|
}
|
|
|
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.OptionNoCertain}
|
|
|
)
|
|
|
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 tmpMap = make(map[string]protocol.SiftingResultDetail)
|
|
|
for i := range checkResults {
|
|
|
checkResult := checkResults[i]
|
|
|
key := strings.TrimSpace(checkResult.Answer)
|
|
|
if len(key) == 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,
|
|
|
}
|
|
|
if v, ok := tmpMap[key]; ok {
|
|
|
v.Items = append(v.Items, commitItem)
|
|
|
tmpMap[key] = v
|
|
|
} else {
|
|
|
tmpMap[key] = protocol.SiftingResultDetail{
|
|
|
Option: key,
|
|
|
Items: []protocol.SiftingCommitItem{commitItem},
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
for i := range sortList {
|
|
|
if v, ok := tmpMap[sortList[i]]; ok {
|
|
|
rsp.SiftingResultDetails = append(rsp.SiftingResultDetails, v)
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
} |
...
|
...
|
|