作者 yangfu

增加 筛选历史,筛选历史详情

... ... @@ -739,3 +739,45 @@ func (this *ChanceController) SubmitChecks() {
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))
}
... ...
... ... @@ -91,3 +91,22 @@ func GetCheckResultAllSubmitters(chanceId int64) (v []int64, err error) {
}
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
}
... ...
... ... @@ -28,6 +28,12 @@ const (
Pass //通过
)
const (
OptionYes = "是"
OptionNo = "否"
OptionNoCertain = "不清楚"
)
/*机会-自查内容*/
var CheckOptionsCommit = []CheckOption{{Item: "是", NeedOther: false}, {Item: "否", NeedOther: false}, {Item: "不清楚", NeedOther: false}}
var CheckOptionsApprove = []CheckOption{{Item: "是", NeedOther: false}, {Item: "否", NeedOther: true}, {Item: "不清楚", NeedOther: false}}
... ... @@ -157,6 +163,61 @@ func (s SelfChecks) Compare(dst string) (rspChecks SelfChecks, err error) {
return
}
//按规则设置自查 一级自查
func (s SelfChecks) SetSelfChecksLevel1ByRule() (err error) {
if len(s) == 0 {
return
}
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), OptionNoCertain) {
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 = OptionNoCertain
}
}
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 NewCheckQuestion(checkItem, title string, groupId int64, ops []CheckOption) *CheckQuestion {
return &CheckQuestion{
... ... @@ -224,3 +285,93 @@ type SubmitChecksRequest struct {
}
type SubmitChecksResponse struct {
}
/*SiftingResultsItemHistory 筛选历史*/
type SiftingResultsItemHistoryRequest struct {
ChanceId int64 `json:"chanceId" valid:"Required"`
}
type SiftingResultsItemHistoryResponse struct {
SiftingResults SiftingResults `json:"siftingResults"`
TotalSubmitters int `json:"totalSubmitters"`
}
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) AddStatic(checkId int, answer string) {
s.addStatic(checkId, answer)
}
//清空统计结果
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()
}
}
//添加统计
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 OptionNoCertain:
s[i].TotalUncertain++
break
default:
isAnswer = false
break
}
if isAnswer {
s[i].TotalSubmitters++
}
}
s[i].SubSiftingResults.AddStatic(checkId, answer)
}
}
/*SiftingResultsItemDetail 筛选历史详情*/
type SiftingResultsItemDetailRequest struct {
ChanceId int64 `json:"chanceId" valid:"Required"`
CheckId int `json:"checkId" valid:"Required"` //检查项id
}
type SiftingResultsItemDetailResponse struct {
SiftingResultDetails []SiftingResultDetail `json:"siftingResultDetails"`
}
//筛选结果详情
type SiftingResultDetail struct {
Option string `json:"option"` //选项:是 否 不清楚
Items SiftingCommitItems `json:"items"`
}
//筛选结果提交人项
type SiftingCommitItems []SiftingCommitItem
type SiftingCommitItem struct {
Provider *BaseUserInfo `json:"provider"`
Reason string `json:"reason"` //理由
}
... ...
... ... @@ -273,6 +273,22 @@ func init() {
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"},
... ...
... ... @@ -2235,6 +2235,9 @@ func CheckQuestions(header *protocol.RequestHeader, request *protocol.CheckQuest
}
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/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
}
... ...