作者 yangfu

修改 筛选历史/详情

... ... @@ -31,34 +31,21 @@ const (
const (
OptionYes = "是"
OptionNo = "否"
OptionNoCertain = "不清楚"
OptionUncertain = "不清楚"
)
/*机会-自查内容*/
var CheckOptionsCommit = []CheckOption{{Item: "是", NeedOther: false}, {Item: "否", NeedOther: false}, {Item: "不清楚", NeedOther: false}}
var CheckOptionsApprove = []CheckOption{{Item: "是", NeedOther: false}, {Item: "否", NeedOther: true}, {Item: "不清楚", NeedOther: false}}
//自查结果列表
/*自查结果列表*/
type SelfCheckResults []selfCheckResult
type selfCheckResult struct {
Item string `json:"item"`
Total int `json:"total"`
}
//自查项列表
func NewSelfChecks(data string) (rsp SelfChecks) {
if len(data) == 0 {
return
}
e := json.Unmarshal([]byte(data), &rsp)
if e != nil {
log.Error(e)
}
return
}
type SelfChecks []SelfCheck
/*自查项*/
type SelfCheck struct {
CheckItem string `json:"checkItem"`
GroupId int64 `json:"groupId"` //分组
... ... @@ -69,10 +56,27 @@ type SelfCheck struct {
ParentId int64 `json:"parentId"`
}
//自查项 键值
func (c SelfCheck) Key() string {
return fmt.Sprintf("%v-%v", c.GroupId, c.CheckItem)
}
//新建自查项列表
//@data json格式的数据体
func NewSelfChecks(data string) (rsp SelfChecks) {
if len(data) == 0 {
return
}
e := json.Unmarshal([]byte(data), &rsp)
if e != nil {
log.Error(e)
}
return
}
/*自查项列表*/
type SelfChecks []SelfCheck
//统计自查结果
func (s SelfChecks) Static() SelfCheckResults {
if len(s) == 0 {
... ... @@ -124,6 +128,9 @@ func (s SelfChecks) String() string {
var buf bytes.Buffer
for i := range s {
c := s[i]
if len(c.Answer) == 0 {
continue
}
if len(c.Reason) == 0 {
buf.WriteString(fmt.Sprintf("\n%v:%v;", c.CheckItem, c.Answer))
} else {
... ... @@ -132,6 +139,8 @@ func (s SelfChecks) String() string {
}
return buf.String()
}
//比较自查内容 ,返回差级
func (s SelfChecks) Compare(dst string) (rspChecks SelfChecks, err error) {
var (
dstChecks SelfChecks
... ... @@ -154,12 +163,12 @@ func (s SelfChecks) Compare(dst string) (rspChecks SelfChecks, err error) {
for i := range s {
c := s[i]
if v, ok := mapChecks[c.Key()]; ok {
//回答不一
//回答不一
if !strings.EqualFold(c.Answer, v.Answer) {
rspChecks = append(rspChecks, c)
continue
}
if len(c.Reason) > 0 {
if len(strings.TrimSpace(c.Reason)) > 0 {
rspChecks = append(rspChecks, c)
continue
}
... ... @@ -199,7 +208,7 @@ func (s SelfChecks) SetSelfChecksLevel1ByRule() (err error) {
cntYes++
} else if strings.EqualFold(strings.TrimSpace(answer), OptionNo) {
cntNo++
} else if strings.EqualFold(strings.TrimSpace(answer), OptionNoCertain) {
} else if strings.EqualFold(strings.TrimSpace(answer), OptionUncertain) {
cntUncertain++
}
}
... ... @@ -210,7 +219,7 @@ func (s SelfChecks) SetSelfChecksLevel1ByRule() (err error) {
} else if cntNo > 0 {
s[gIdx].Answer = OptionNo
} else if cntUncertain > 0 {
s[gIdx].Answer = OptionNoCertain
s[gIdx].Answer = OptionUncertain
}
}
if hasSub && cntYes == 0 && cntNo == 0 && cntUncertain == 0 {
... ... @@ -223,7 +232,19 @@ func (s SelfChecks) SetSelfChecksLevel1ByRule() (err error) {
return
}
//自查问题
//格式化数据结构
func (s SelfChecks) Format() {
if len(s) == 0 {
return
}
for i := range s {
if strings.TrimSpace(s[i].Answer) == OptionNo {
s[i].Reason = strings.TrimSpace(s[i].Reason)
}
}
}
//新建自查问题
func NewCheckQuestion(checkItem, title string, groupId int64, ops []CheckOption) *CheckQuestion {
return &CheckQuestion{
CheckItem: checkItem,
... ... @@ -233,6 +254,7 @@ func NewCheckQuestion(checkItem, title string, groupId int64, ops []CheckOption)
}
}
/*问题*/
type CheckQuestion struct {
Id int64 `json:"id"`
ParentId int64 `json:"parentId"`
... ... @@ -246,60 +268,14 @@ type CheckQuestion struct {
Required bool `json:"required"` //是否必填
}
/*问题选项*/
type CheckOption struct {
Item string `json:"item"`
NeedOther bool `json:"needOther"` //是否需填写其他的内容【1:需要】【2:不需要】
}
/*CheckQuestions 自查问题列表*/
type CheckQuestionsRequest struct {
Type int `json:"type"` //0.自查 1.筛选结果
ChanceId int64 `json:"chanceId" valid:"Required"`
}
type CheckQuestionsResponse struct {
Questions []*CheckQuestion `json:"questions"`
}
//SiftingPool 筛选池
type SiftingPoolRequest struct {
PageInfo
Uid int64 `json:"uid"` //注入用户 测试使用
SubmitStatus int `json:"submitStatus"` //0:待我提交 1:提交
SiftedStatus int `-` //筛选状态 1:提交中 2:通过 3:不通过
}
type SiftingPoolResponse struct {
ChancePoolResponse
}
/*筛选结果 SiftingResults */
type SiftingResultsRequest struct {
PageInfo
Uid int64 `json:"uid"` //注入用户 测试使用
SiftedStatus int `json:"siftingStatus"` //筛选状态 1:待处理 2:通过 3:不通过
}
type SiftingResultsResponse struct {
ChancePoolResponse
}
/*SubmitChecks 提交自查*/
type SubmitChecksRequest struct {
//Type int `json:"type"` //1.审核人
Uid int64 `json:"uid"`
ChanceId int64 `json:"chanceId" valid:"Required"`
SelfChecks SelfChecks `json:"selfChecks"`
}
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
... ... @@ -315,12 +291,9 @@ type SiftingResult struct {
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 {
... ... @@ -332,7 +305,43 @@ func (s SiftingResults) ClearStatic() {
}
}
/*
设置一级筛选结果
单个维度显示“是”、“否”、“不清楚”的规则:
1、所有人均选择“是”,则该维度的结果为“是”
2、只要有一个“否”,则该维度的结果为“否” ,不需要显示理由
3、其他情况则显示为“不清楚”
*/
func (s SiftingResults) SetSelfChecksLevel1ByRule() {
for i := range s {
tmpAnswer := ""
if s[i].TotalNo > 0 {
tmpAnswer = OptionNo
}
if s[i].TotalYes > 0 && s[i].TotalNo == 0 && s[i].TotalUncertain == 0 {
tmpAnswer = OptionYes
}
if s[i].TotalNo == 0 && s[i].TotalUncertain > 0 {
tmpAnswer = OptionUncertain
}
s[i].TotalNo = 0
s[i].TotalYes = 0
s[i].TotalUncertain = 0
if tmpAnswer == OptionNo {
s[i].TotalNo = s[i].TotalSubmitters
} else if tmpAnswer == OptionYes {
s[i].TotalYes = s[i].TotalSubmitters
} else if tmpAnswer == OptionUncertain {
s[i].TotalUncertain = s[i].TotalSubmitters
}
}
}
//添加统计
func (s SiftingResults) AddStatic(checkId int, answer string) {
s.addStatic(checkId, answer)
}
func (s SiftingResults) addStatic(checkId int, answer string) {
for i := range s {
if s[i].CheckId == checkId {
... ... @@ -344,7 +353,7 @@ func (s SiftingResults) addStatic(checkId int, answer string) {
case OptionNo:
s[i].TotalNo++
break
case OptionNoCertain:
case OptionUncertain:
s[i].TotalUncertain++
break
default:
... ... @@ -359,16 +368,6 @@ func (s SiftingResults) addStatic(checkId int, answer string) {
}
}
/*SiftingResultsItemDetail 筛选历史详情*/
type SiftingResultsItemDetailRequest struct {
ChanceId int64 `json:"chanceId" valid:"Required"`
CheckId int `json:"checkId" valid:"Required"` //检查项id
}
type SiftingResultsItemDetailResponse struct {
SiftingResultDetails []SiftingResultDetail `json:"siftingResultDetails"`
TotalSubmitters int `json:"totalSubmitters"` //总提交人数
}
//筛选结果详情
type SiftingResultDetail struct {
Option string `json:"option"` //选项:是 否 不清楚
... ... @@ -382,3 +381,58 @@ type SiftingCommitItem struct {
Provider *BaseUserInfo `json:"provider"`
Reason string `json:"reason"` //理由
}
/******************REQUEST/RESPONSE (请求应答实体)*******************/
/*CheckQuestions 自查问题列表*/
type CheckQuestionsRequest struct {
Type int `json:"type"` //0.自查 1.筛选结果
ChanceId int64 `json:"chanceId" valid:"Required"`
}
type CheckQuestionsResponse struct {
Questions []*CheckQuestion `json:"questions"`
}
//SiftingPool 筛选池
type SiftingPoolRequest struct {
PageInfo
Uid int64 `json:"uid"` //注入用户 测试使用
SubmitStatus int `json:"submitStatus"` //0:待我提交 1:提交
SiftedStatus int `-` //筛选状态 1:提交中 2:通过 3:不通过
}
type SiftingPoolResponse struct{ ChancePoolResponse }
/*筛选结果 SiftingResults */
type SiftingResultsRequest struct {
PageInfo
Uid int64 `json:"uid"` //注入用户 测试使用
SiftedStatus int `json:"siftingStatus"` //筛选状态 1:待处理 2:通过 3:不通过
}
type SiftingResultsResponse struct{ ChancePoolResponse }
/*SubmitChecks 提交自查*/
type SubmitChecksRequest struct {
//Type int `json:"type"` //1.审核人
Uid int64 `json:"uid"`
ChanceId int64 `json:"chanceId" valid:"Required"`
SelfChecks SelfChecks `json:"selfChecks"`
}
type SubmitChecksResponse struct{}
/*SiftingResultsItemHistory 筛选历史*/
type SiftingResultsItemHistoryRequest struct {
ChanceId int64 `json:"chanceId" valid:"Required"`
}
type SiftingResultsItemHistoryResponse struct {
SiftingResults SiftingResults `json:"siftingResults"`
TotalSubmitters int `json:"totalSubmitters"`
}
/*SiftingResultsItemDetail 筛选历史详情*/
type SiftingResultsItemDetailRequest struct {
ChanceId int64 `json:"chanceId" valid:"Required"`
CheckId int `json:"checkId" valid:"Required"` //检查项id
}
type SiftingResultsItemDetailResponse struct {
SiftingResultDetails []SiftingResultDetail `json:"siftingResultDetails"`
TotalSubmitters int `json:"totalSubmitters"` //总提交人数
}
... ...
package protocol
import (
"encoding/json"
"fmt"
"testing"
)
func TestSelfChecks(t *testing.T) {
nsc := func(id, pid int64, checkItem, answer string) SelfCheck {
item := SelfCheck{
CheckItem: checkItem, Answer: answer, Id: id, ParentId: pid,
}
item.GroupId = pid
if pid == 0 {
item.GroupId = id
}
return item
}
nscNo := func(id, pid int64, checkItem, answer, reason string) SelfCheck {
item := nsc(id, pid, checkItem, answer)
item.Reason = reason
return item
}
input := SelfChecks([]SelfCheck{
nsc(1, 0, "1", ""),
nsc(2, 1, "2", OptionYes),
nsc(3, 1, "3", OptionNo),
nsc(4, 1, "4", OptionUncertain),
nsc(5, 1, "5", ""),
nsc(6, 0, "6", ""),
nsc(7, 6, "7", OptionUncertain),
nscNo(8, 6, "8", OptionNo, " "),
nsc(9, 6, "9", OptionUncertain),
nsc(10, 6, "10", ""),
nsc(11, 0, "11", OptionYes),
nsc(12, 0, "12", OptionYes),
})
input.SetSelfChecksLevel1ByRule()
if input[0].Answer != OptionYes || input[5].Answer != OptionNo {
t.Fatal(fmt.Sprintf("SetSelfChecksLevel1ByRule Fail"))
}
if input.Static()[0].Total != 3 || input.Static()[0].Item != OptionYes {
t.Fatal(fmt.Sprintf("Static Fail"))
}
if input[7].Reason != " " {
t.Fatal("reason data error")
}
input.Format()
if input[7].Reason == " " {
t.Fatal("reason data error")
}
t.Log(input.String())
inputCompare := SelfChecks([]SelfCheck{
nsc(1, 0, "1", ""),
nsc(2, 1, "2", OptionYes),
nsc(3, 1, "3", OptionNo),
nsc(4, 1, "4", OptionNo), //diff
nsc(5, 1, "5", ""),
nsc(6, 0, "6", ""),
nsc(7, 6, "7", OptionUncertain),
nscNo(8, 6, "8", OptionNo, " "),
nsc(9, 6, "9", OptionUncertain),
nsc(10, 6, "10", ""),
nsc(11, 0, "11", OptionYes),
nsc(12, 0, "12", OptionNo), //diff
})
inputCompare.SetSelfChecksLevel1ByRule()
inputCompare.Format()
data, err := json.Marshal(input)
if err != nil {
t.Fatal(err)
}
o, err := inputCompare.Compare(string(data))
if err != nil {
t.Fatal(err)
}
if len(o) != 2 {
t.Fatal("Compare fail")
}
t.Log("Compare:", o.String())
}
func TestSiftingResults(t *testing.T) {
}
... ...
... ... @@ -566,5 +566,6 @@ func GetChanceSelfChecks(chanceInfo *models.Chance) []protocol.SelfCheck {
}
return lv1List
}
protocol.SelfChecks(selfChecks).Format()
return selfChecks
}
... ...
... ... @@ -51,7 +51,6 @@ func SiftingPool(header *protocol.RequestHeader, request *protocol.SiftingPoolRe
rsp.List = append(rsp.List, commItem)
}
return
}
... ... @@ -289,7 +288,7 @@ func collectChanceCheckResultData(checkResultData []*models.ChanceCheckResult) p
dd.Answer = protocol.OptionYes
}
if checkResultSlice[i].AnswerNo == 0 && checkResultSlice[i].AnswerAny > 0 {
dd.Answer = protocol.OptionNoCertain
dd.Answer = protocol.OptionUncertain
}
selfCheckData = append(selfCheckData, dd)
for j := range checkResultSlice[i].Child {
... ... @@ -308,7 +307,7 @@ func collectChanceCheckResultData(checkResultData []*models.ChanceCheckResult) p
dd.Answer = protocol.OptionYes
}
if child.AnswerNo == 0 && child.AnswerAny > 0 {
dd.Answer = protocol.OptionNoCertain
dd.Answer = protocol.OptionUncertain
}
selfCheckData = append(selfCheckData, dd)
}
... ... @@ -339,6 +338,7 @@ func SiftingResultsItemHistory(header *protocol.RequestHeader, request *protocol
item := checkResults[i]
rsp.SiftingResults.AddStatic(item.CheckId, item.Answer)
}
rsp.SiftingResults.SetSelfChecksLevel1ByRule()
return
}
... ... @@ -389,8 +389,7 @@ func NewSiftingResults(checkResults []*models.ChanceCheckResult) protocol.Siftin
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}
ids []int64
sortList []string = []string{protocol.OptionYes, protocol.OptionNo, protocol.OptionUncertain}
)
rsp = &protocol.SiftingResultsItemDetailResponse{}
if checkResults, err = models.GetCheckResultsByCheckId(request.ChanceId, request.CheckId); err != nil {
... ... @@ -401,13 +400,15 @@ func SiftingResultsItemDetail(header *protocol.RequestHeader, request *protocol.
log.Error(err)
return
}
var tmpMap = make(map[string]protocol.SiftingResultDetail)
var resultsMap = make(map[string]protocol.SiftingResultDetail)
for i := range checkResults {
checkResult := checkResults[i]
key := strings.TrimSpace(checkResult.Answer)
if len(key) == 0 {
answer := strings.TrimSpace(checkResult.Answer)
if len(answer) == 0 {
continue
}
/*提交人信息*/
var provider *protocol.BaseUserInfo
if provider, err = agg.GetUserBaseInfo(checkResult.UserCompanyId, header.CompanyId); err != nil {
log.Error(err)
... ... @@ -417,24 +418,25 @@ func SiftingResultsItemDetail(header *protocol.RequestHeader, request *protocol.
Provider: provider,
Reason: checkResult.Reason,
}
if v, ok := tmpMap[key]; ok {
//追加到Map列表
if v, ok := resultsMap[answer]; ok {
v.Items = append(v.Items, commitItem)
tmpMap[key] = v
resultsMap[answer] = v
} else {
tmpMap[key] = protocol.SiftingResultDetail{
Option: key,
resultsMap[answer] = protocol.SiftingResultDetail{
Option: answer,
Items: []protocol.SiftingCommitItem{commitItem},
}
}
}
for i := range sortList {
if v, ok := tmpMap[sortList[i]]; ok {
//返回数据
if v, ok := resultsMap[sortList[i]]; ok {
v.TotalSubmitters = len(v.Items)
rsp.SiftingResultDetails = append(rsp.SiftingResultDetails, v)
rsp.TotalSubmitters += len(v.Items)
}
}
if ids, err = models.GetCheckResultAllSubmitters(request.ChanceId); err == nil {
rsp.TotalSubmitters = len(ids)
}
return
}
... ...