正在显示
2 个修改的文件
包含
28 行增加
和
167 行删除
@@ -31,181 +31,25 @@ func GetChanceCheckResultInfo(chanceId int64, companyid int64) (protocol.Reponse | @@ -31,181 +31,25 @@ func GetChanceCheckResultInfo(chanceId int64, companyid int64) (protocol.Reponse | ||
31 | log.Error("机会的自查内容筛选状态错误") | 31 | log.Error("机会的自查内容筛选状态错误") |
32 | return rsp, protocol.NewErrWithMessage("1") | 32 | return rsp, protocol.NewErrWithMessage("1") |
33 | } | 33 | } |
34 | - rsp, err = getChanceCheckResultData(chanceId) | ||
35 | - return rsp, err | ||
36 | -} | ||
37 | - | ||
38 | -//getChanceCheckResultData 机会自查内容筛选详情数据输出 | ||
39 | -// func getChanceCheckResultData(chanceId int64) (protocol.ReponseChanceCheckResult, error) { | ||
40 | -// var ( | ||
41 | -// checkResultData []models.ChanceCheckResult | ||
42 | -// err error | ||
43 | -// ) | ||
44 | -// rsp := protocol.ReponseChanceCheckResult{ | ||
45 | -// CustomItem: []string{}, | ||
46 | -// CheckData: []protocol.ChanceCheckResultData{}, | ||
47 | -// } | ||
48 | -// checkResultData, err = models.GetChanceCheckResultByChancce(chanceId) | ||
49 | -// if err != nil { | ||
50 | -// log.Error("未获得指定的机会自查内容筛选结果,err;%s", err) | ||
51 | -// return rsp, nil | ||
52 | -// } | ||
53 | -// //组装响应数据 | ||
54 | -// //自查内容中的用户id | ||
55 | -// userIds := utils.NewArraySetInt64() | ||
56 | -// //一维自查内容项 | ||
57 | -// checkItemsLv1 := utils.NewArraySetInt64() | ||
58 | -// checkItemsLv2 := map[int64]*utils.ArraySetInt64{} | ||
59 | -// checkResultMap := make(map[int64]*protocol.ChanceCheckResultData) | ||
60 | -// //处理一维自查内容数据 | ||
61 | -// for _, v := range checkResultData { | ||
62 | -// if v.CheckPid > 0 { | ||
63 | -// continue | ||
64 | -// } | ||
65 | -// if _, ok := checkResultMap[v.CheckId]; ok { | ||
66 | -// checkResultMap[v.CheckId].CustomItemData[fmt.Sprint(v.UserCompanyId)] = v.Answer | ||
67 | -// switch v.Answer { | ||
68 | -// case "是": | ||
69 | -// checkResultMap[v.CheckId].AnswerYes++ | ||
70 | -// case "否": | ||
71 | -// checkResultMap[v.CheckId].AnswerNo++ | ||
72 | -// case "不清楚": | ||
73 | -// checkResultMap[v.CheckId].AnswerAny++ | ||
74 | -// } | ||
75 | -// } else { | ||
76 | -// userAnswer := map[string]string{ | ||
77 | -// fmt.Sprint(v.UserCompanyId): v.Answer, | ||
78 | -// } | ||
79 | -// r := &protocol.ChanceCheckResultData{ | ||
80 | -// CheckPid: v.CheckPid, | ||
81 | -// CheckId: v.CheckId, | ||
82 | -// CheckItem: v.CheckItem, | ||
83 | -// CustomItemData: userAnswer, | ||
84 | -// } | ||
85 | -// switch v.Answer { | ||
86 | -// case "是": | ||
87 | -// r.AnswerYes++ | ||
88 | -// case "否": | ||
89 | -// r.AnswerNo++ | ||
90 | -// case "不清楚": | ||
91 | -// r.AnswerAny++ | ||
92 | -// } | ||
93 | -// checkResultMap[v.CheckId] = r | ||
94 | -// userIds.Add(v.UserCompanyId) | ||
95 | -// checkItemsLv1.Add(v.CheckId) | ||
96 | -// } | ||
97 | -// } | ||
98 | -// //处理二维自查内容数据 | ||
99 | -// for _, v := range checkResultData { | ||
100 | -// if v.CheckPid == 0 { | ||
101 | -// continue | ||
102 | -// } | ||
103 | -// _, ok := checkResultMap[v.CheckPid] | ||
104 | -// if !ok { | ||
105 | -// continue | ||
106 | -// } | ||
107 | -// _, ok = checkResultMap[v.CheckPid].Child[v.CheckId] | ||
108 | -// if ok { | ||
109 | -// checkResultMap[v.CheckPid].Child[v.CheckId].CustomItemData[fmt.Sprint(v.UserCompanyId)] = v.Answer | ||
110 | -// switch v.Answer { | ||
111 | -// case "是": | ||
112 | -// checkResultMap[v.CheckId].AnswerYes++ | ||
113 | -// case "否": | ||
114 | -// checkResultMap[v.CheckId].AnswerNo++ | ||
115 | -// case "不清楚": | ||
116 | -// checkResultMap[v.CheckId].AnswerAny++ | ||
117 | -// } | ||
118 | -// } else { | ||
119 | -// userAnswer := map[string]string{ | ||
120 | -// fmt.Sprint(v.UserCompanyId): v.Answer, | ||
121 | -// } | ||
122 | -// r := &protocol.ChanceCheckResultData{ | ||
123 | -// CheckPid: v.CheckPid, | ||
124 | -// CheckId: v.CheckId, | ||
125 | -// CheckItem: v.CheckItem, | ||
126 | -// CustomItemData: userAnswer, | ||
127 | -// } | ||
128 | -// switch v.Answer { | ||
129 | -// case "是": | ||
130 | -// r.AnswerYes++ | ||
131 | -// case "否": | ||
132 | -// r.AnswerNo++ | ||
133 | -// case "不清楚": | ||
134 | -// r.AnswerAny++ | ||
135 | -// } | ||
136 | -// checkResultMap[v.CheckPid].Child[v.CheckId] = r | ||
137 | -// userIds.Add(v.UserCompanyId) | ||
138 | -// if _, ok := checkItemsLv2[v.CheckPid]; ok { | ||
139 | -// checkItemsLv2[v.CheckPid].Add(v.CheckId) | ||
140 | -// } else { | ||
141 | - | ||
142 | -// checkItemsLv2[v.CheckPid] = utils.NewArraySetInt64() | ||
143 | -// checkItemsLv2[v.CheckPid].Add(v.CheckId) | ||
144 | -// } | ||
145 | -// } | ||
146 | -// } | ||
147 | -// usernameMap := make(map[string]string) | ||
148 | -// for _, v := range userIds.ToSlice() { | ||
149 | -// idString := fmt.Sprint(v) | ||
150 | -// u, err := models.GetUserCompanyById(v) | ||
151 | -// if err == nil { | ||
152 | -// usernameMap[idString] = u.NickName | ||
153 | -// } else { | ||
154 | -// usernameMap[idString] = idString | ||
155 | -// } | ||
156 | -// rsp.CustomItem = append(rsp.CustomItem, usernameMap[idString]) | ||
157 | -// } | ||
158 | -// for _, Lv1 := range checkItemsLv1.ToSlice() { | ||
159 | -// // 处理一级数据 | ||
160 | -// newCustomItemData := map[string]string{} | ||
161 | -// for uid, uname := range usernameMap { | ||
162 | -// if answer, ok := checkResultMap[Lv1].CustomItemData[uid]; ok { | ||
163 | -// newCustomItemData[uname] = answer | ||
164 | -// } else { | ||
165 | -// newCustomItemData[uname] = "" | ||
166 | -// } | ||
167 | -// } | ||
168 | -// checkResultMap[Lv1].CustomItemData = newCustomItemData | ||
169 | -// checkResultMap[Lv1].Total = fmt.Sprintf("是:%d 否:%d 不清楚:%d", | ||
170 | -// checkResultMap[Lv1].AnswerYes, checkResultMap[Lv1].AnswerNo, checkResultMap[Lv1].AnswerAny) | ||
171 | -// rsp.CheckData = append(rsp.CheckData, *checkResultMap[Lv1]) | ||
172 | -// if _, ok := checkItemsLv2[Lv1]; ok { | ||
173 | -// //处理二级数据 | ||
174 | -// for _, Lv2 := range checkItemsLv2[Lv1].ToSlice() { | ||
175 | -// newCustomItemData := map[string]string{} | ||
176 | -// for uid, uname := range usernameMap { | ||
177 | -// if answer, ok := checkResultMap[Lv1].Child[Lv2].CustomItemData[uid]; ok { | ||
178 | -// newCustomItemData[uname] = answer | ||
179 | -// } else { | ||
180 | -// newCustomItemData[uname] = "" | ||
181 | -// } | ||
182 | -// } | ||
183 | -// checkResultMap[Lv1].Child[Lv2].CustomItemData = newCustomItemData | ||
184 | -// // checkResultMap[Lv1].Child[Lv2].Total = fmt.Sprintf("是:%d 否:%d 不清楚:%d", | ||
185 | -// // checkResultMap[Lv1].Child[Lv2].AnswerYes, checkResultMap[Lv1].Child[Lv2].AnswerNo, | ||
186 | -// // checkResultMap[Lv1].Child[Lv2].AnswerAny) | ||
187 | -// rsp.CheckData = append(rsp.CheckData, *checkResultMap[Lv1].Child[Lv2]) | ||
188 | -// } | ||
189 | -// } | ||
190 | -// } | ||
191 | -// return rsp, nil | ||
192 | -// } | ||
193 | - | ||
194 | -//getChanceCheckResultData 机会自查内容筛选详情数据输出 | ||
195 | -func getChanceCheckResultData(chanceId int64) (protocol.ReponseChanceCheckResult, error) { | ||
196 | var ( | 34 | var ( |
197 | checkResultData []models.ChanceCheckResult | 35 | checkResultData []models.ChanceCheckResult |
198 | - err error | ||
199 | ) | 36 | ) |
200 | - rsp := protocol.ReponseChanceCheckResult{ | ||
201 | - CustomItem: []string{}, | ||
202 | - CheckData: []protocol.ChanceCheckResultData{}, | ||
203 | - } | 37 | + |
204 | checkResultData, err = models.GetChanceCheckResultByChancce(chanceId) | 38 | checkResultData, err = models.GetChanceCheckResultByChancce(chanceId) |
205 | if err != nil { | 39 | if err != nil { |
206 | log.Error("未获得指定的机会自查内容筛选结果,err;%s", err) | 40 | log.Error("未获得指定的机会自查内容筛选结果,err;%s", err) |
207 | return rsp, nil | 41 | return rsp, nil |
208 | } | 42 | } |
43 | + rsp, err = buildChanceCheckResultData(checkResultData) | ||
44 | + return rsp, err | ||
45 | +} | ||
46 | + | ||
47 | +//buildChanceCheckResultData 构建机会自查内容筛选详情数据输出 | ||
48 | +func buildChanceCheckResultData(checkResultData []models.ChanceCheckResult) (protocol.ReponseChanceCheckResult, error) { | ||
49 | + rsp := protocol.ReponseChanceCheckResult{ | ||
50 | + CustomItem: []string{}, | ||
51 | + CheckData: []protocol.ChanceCheckResultData{}, | ||
52 | + } | ||
209 | //人的id | 53 | //人的id |
210 | userIds := utils.NewArraySetInt64() | 54 | userIds := utils.NewArraySetInt64() |
211 | checkResultMap := map[int64]*protocol.ChanceCheckResultData{} | 55 | checkResultMap := map[int64]*protocol.ChanceCheckResultData{} |
@@ -266,6 +110,7 @@ func getChanceCheckResultData(chanceId int64) (protocol.ReponseChanceCheckResult | @@ -266,6 +110,7 @@ func getChanceCheckResultData(chanceId int64) (protocol.ReponseChanceCheckResult | ||
266 | checkReusltSlice[i].AnswerYes, checkReusltSlice[i].AnswerNo, checkReusltSlice[i].AnswerAny) | 110 | checkReusltSlice[i].AnswerYes, checkReusltSlice[i].AnswerNo, checkReusltSlice[i].AnswerAny) |
267 | } | 111 | } |
268 | if checkReusltSlice[i].CheckPid > 0 { | 112 | if checkReusltSlice[i].CheckPid > 0 { |
113 | + //子集归并到父级 | ||
269 | pid := checkReusltSlice[i].CheckPid | 114 | pid := checkReusltSlice[i].CheckPid |
270 | checkResultMap[pid].Child = append(checkResultMap[pid].Child, checkReusltSlice[i]) | 115 | checkResultMap[pid].Child = append(checkResultMap[pid].Child, checkReusltSlice[i]) |
271 | } | 116 | } |
utils/array_test.go
0 → 100644
-
请 注册 或 登录 后发表评论