getDefaultStdStatusMapping retrieves default standard status mappings for the given TapdTaskData and status list. It takes TapdTaskData, a Dal interface, and a statusList of type S (models.TapdStatus). It returns a map of English to Chinese status names, a function to get standard status from status
(data *TapdTaskData, db dal.Dal, statusList []S)
| 234 | // It takes TapdTaskData, a Dal interface, and a statusList of type S (models.TapdStatus). |
| 235 | // It returns a map of English to Chinese status names, a function to get standard status from status key, and an error, if any. |
| 236 | func getDefaultStdStatusMapping[S models.TapdStatus](data *TapdTaskData, db dal.Dal, statusList []S) (map[string]string, func(statusKey string) string, errors.Error) { |
| 237 | // Create clauses for querying the database |
| 238 | clauses := []dal.Clause{ |
| 239 | dal.Where("connection_id = ? and workspace_id = ?", data.Options.ConnectionId, data.Options.WorkspaceId), |
| 240 | } |
| 241 | // Query the database for status list |
| 242 | err := db.All(&statusList, clauses...) |
| 243 | if err != nil { |
| 244 | return nil, nil, err |
| 245 | } |
| 246 | |
| 247 | // Create status language and last step maps |
| 248 | statusLanguageMap := make(map[string]string, len(statusList)) |
| 249 | statusLastStepMap := make(map[string]bool, len(statusList)) |
| 250 | |
| 251 | // Populate status maps |
| 252 | for _, v := range statusList { |
| 253 | statusLanguageMap[v.GetEnglish()] = v.GetChinese() |
| 254 | statusLastStepMap[v.GetChinese()] = v.GetIsLastStep() |
| 255 | } |
| 256 | |
| 257 | // Define function to get standard status from status key |
| 258 | getStdStatus := func(statusKey string) string { |
| 259 | if statusLastStepMap[statusKey] { |
| 260 | return ticket.DONE |
| 261 | } else if statusKey == "草稿" { |
| 262 | return ticket.TODO |
| 263 | } else { |
| 264 | return ticket.IN_PROGRESS |
| 265 | } |
| 266 | } |
| 267 | return statusLanguageMap, getStdStatus, nil |
| 268 | } |
| 269 | |
| 270 | // unicodeToZh converts a string containing Unicode escape sequences to a Chinese string. |
| 271 | // It returns the converted string and an error if the conversion fails. |