Changeset 701 for trunk/grails-app/services/TaskSearchService.groovy
- Timestamp:
- Nov 2, 2010, 9:24:28 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/TaskSearchService.groovy
r582 r701 1 1 import grails.orm.PagedResultList 2 import org.hibernate.FetchMode as FM 2 3 3 4 /** … … 348 349 } // getWorkDone() 349 350 351 /** 352 * Get work load by task group and date. 353 * Group ID's and date range may be specified in params otherwise no group and today are used. 354 * @param params The request params. 355 * @returns A map containing the results. 356 */ 357 def getWorkLoad(params, locale) { 358 def result = [:] 359 def max = 1000 360 361 // TaskStatus.. 362 result.taskStatusList = [] 363 if(params.taskStatusList instanceof String) 364 result.taskStatusList << TaskStatus.get(params.taskStatusList.toInteger()) 365 else if(params.taskStatusList) 366 result.taskStatusList = TaskStatus.getAll( params.taskStatusList.collect {it.toInteger()} ) 367 368 // TaskGroups. 369 result.taskGroups = [] 370 if(params.taskGroups instanceof String) 371 result.taskGroups << TaskGroup.get(params.taskGroups.toInteger()) 372 else if(params.taskGroups) 373 result.taskGroups = TaskGroup.getAll( params.taskGroups.collect {it.toInteger()} ) 374 375 // Start Date. 376 if(params.startDate_year && params.startDate_month && params.startDate_day) 377 result.startDate = dateUtilService.makeDate(params.startDate_year, params.startDate_month, params.startDate_day) 378 else 379 result.startDate = dateUtilService.today 380 381 // End Date. 382 if(params.endDate_year && params.endDate_month && params.endDate_day) 383 result.endDate = dateUtilService.makeDate(params.endDate_year, params.endDate_month, params.endDate_day) 384 else 385 result.endDate = result.startDate 386 387 // Normalise date range. 388 if(result.endDate < result.startDate) 389 result.endDate = result.startDate 390 391 def formattedStartDate = g.formatDate(format: "EEE, dd-MMM-yyyy", date: result.startDate) 392 def formattedEndDate = g.formatDate(format: "EEE, dd-MMM-yyyy", date: result.endDate) 393 394 def getMessage = { Map m -> 395 messageSource.getMessage(m.code, m.args == null ? null : m.args.toArray(), locale) 396 } 397 398 result.tasks = new PagedResultList([], 0) 399 400 if(result.taskGroups && result.taskStatusList) { 401 402 result.tasks = Task.createCriteria().list(max: max) { 403 eq("trash", false) 404 lt("targetStartDate", result.endDate+1) 405 ge("targetCompletionDate", result.startDate) 406 inList("taskStatus", result.taskStatusList) 407 inList("taskGroup", result.taskGroups) 408 order("taskStatus", "asc") 409 order("taskPriority", "asc") 410 order("targetStartDate", "asc") 411 fetchMode("assignedGroups", FM.EAGER) 412 fetchMode("assignedGroups.personGroup", FM.EAGER) 413 } // createCriteria 414 415 } 416 417 result.tasks.list.unique() 418 result.totalHours = 0 419 result.totalMinutes = 0 420 result.workLoadGroups = [:] 421 422 // Exit early! 423 if(result.tasks.totalCount > result.tasks.size()) { 424 result.errorMessage = getMessage(code:"task.search.text.work.load.too.many.results", 425 args:[result.tasks.size(), result.tasks.totalCount]) 426 return result 427 } 428 else if(result.tasks.size() > 0) 429 result.message = getMessage(code:"task.search.text.work.load.message", 430 args:[formattedStartDate, formattedEndDate]) 431 else 432 result.message = getMessage(code:"task.search.text.work.load.none.found", 433 args:[formattedStartDate, formattedEndDate]) 434 435 // Collect all assignedGroups. 436 def assignedGroups = [] 437 for(task in result.tasks) { 438 for(assignedGroup in task.assignedGroups) { 439 assignedGroups << assignedGroup 440 } 441 } 442 443 // Calculate work load for each personGroup and minute totals. 444 def tempHours = 0 445 def tempMinutes = 0 446 def personGroup 447 for(assignedGroup in assignedGroups) { 448 personGroup = assignedGroup.personGroup 449 if(!result.workLoadGroups.containsKey(personGroup)) { 450 result.workLoadGroups[personGroup] = [hours: 0, minutes: 0] 451 } 452 453 tempMinutes = (assignedGroup.estimatedHour*60) + assignedGroup.estimatedMinute 454 result.totalMinutes += tempMinutes 455 result.workLoadGroups[personGroup].minutes += tempMinutes 456 } 457 458 // Resolve totals and sort. 459 result.workLoadGroups.each { workLoadGroup -> 460 workLoadGroup.value.hours = (workLoadGroup.value.minutes / 60).toInteger() 461 workLoadGroup.value.minutes = workLoadGroup.value.minutes % 60 462 } 463 result.workLoadGroups = result.workLoadGroups.sort { p1, p2 -> p1.key.name.compareToIgnoreCase(p2.key.name) } 464 result.totalHours = (result.totalMinutes / 60).toInteger() 465 result.totalMinutes = result.totalMinutes % 60 466 467 // Success. 468 return result 469 } // getWorkLoad() 470 350 471 } // end class
Note: See TracChangeset
for help on using the changeset viewer.