Ignore:
Timestamp:
May 24, 2010, 3:48:53 AM (14 years ago)
Author:
gav
Message:

Improvements to Immediate Callout Report.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/services/TaskReportService.groovy

    r542 r544  
    1313//     def messageSource
    1414
    15 //     def g = new org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib()
     15    def g = new org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib()
    1616
    1717    def paramsMax = 100000
     
    174174
    175175        result.taskQuery = "select distinct task " + result.taskQuery
    176         result.taskList = Task.executeQuery(result.taskQuery, namedParams)
    177         result.taskCount = result.taskList.size()
     176        result.taskQueryList = Task.executeQuery(result.taskQuery, namedParams)
     177        result.taskCount = result.taskQueryList.size()
    178178
    179179        // Assets on Tasks Count.
    180180        result.totalAssetsOnTasksCount = 0
     181        result.totalDownTime = [total: 0, hours: 0, minutes:0]
    181182        result.assetList = []
    182183
    183         // Add or update asset details in assetList.
    184         def addAssetToList = { asset, task ->
     184        // Task Details
     185        result.taskList = []
     186
     187        // Add or update lists.
     188        def addToLists = { asset, task ->
    185189
    186190            def downTime = 0
    187191            def faultEntries = Entry.findAllByTaskAndEntryType(task, EntryType.read(1))
     192            def causeEntries = Entry.findAllByTaskAndEntryType(task, EntryType.read(2))
     193            def workDoneEntries = Entry.findAllByTaskAndEntryType(task, EntryType.read(3))
     194            def taskDetails = 'Task #'+task.id+' - '+task.description+'\n'
     195            faultEntries.each(){
     196                taskDetails += '    Faults: '+it.comment+' - '+it.enteredBy+', '+g.formatDate(format: "EEE, dd-MMM-yyyy", date: it.dateDone)+'.\n'
     197            }
     198            causeEntries.each(){
     199                taskDetails += '    Causes: '+it.comment+' - '+it.enteredBy+', '+g.formatDate(format: "EEE, dd-MMM-yyyy", date: it.dateDone)+'.\n'
     200            }
     201            workDoneEntries.each(){
     202                taskDetails += '    Work Done: '+it.comment+' - '+it.enteredBy+', '+g.formatDate(format: "EEE, dd-MMM-yyyy", date: it.dateDone)+'.\n'
     203            }
     204
    188205            faultEntries.each() { downTime += (it.durationHour*60 + it.durationMinute) }
     206            result.totalDownTime.total += downTime
    189207
    190208            def assetDetails = result.assetList.find { it.id == asset.id }
    191209            if(assetDetails) {
    192210                assetDetails.immediateCalloutCount++
    193                 assetDetails.immediateCalloutTaskList.add(task.toString())
     211                assetDetails.downTime += downTime
     212                assetDetails.tasks += taskDetails
    194213            }
    195214            else {
     
    198217                                            immediateCalloutCount: 1,
    199218                                            downTime: downTime,
    200                                             immediateCalloutTaskList: [task.toString()]]
     219                                            tasks: taskDetails]
    201220
    202221                result.assetList << assetDetails
    203222            }
    204         } // addAssetToList
     223        } // addAToLists
    205224
    206225        // Summary Of Calculations.
     
    213232
    214233        result.summaryOfCalculationMethod += 'totalAssetsOnTasksCount = A count of unique assets on each task. \n'
    215         result.taskList.each() { task ->
     234        result.taskQueryList.each() { task ->
    216235            if(task.primaryAsset) {
    217236                result.totalAssetsOnTasksCount++
    218                 addAssetToList(task.primaryAsset, task)
     237                addToLists(task.primaryAsset, task)
    219238            }
    220239            task.associatedAssets.each() { associatedAsset ->
    221240                if(associatedAsset.id != task.primaryAsset?.id) {
    222241                    result.totalAssetsOnTasksCount++
    223                     addAssetToList(associatedAsset, task)
     242                    addToLists(associatedAsset, task)
    224243                }
    225244            }
     
    227246        } // each() task
    228247
    229         // Sort by callout count.
     248        // Sort assetList by callout count.
    230249        result.assetList.sort {a, b -> b.immediateCalloutCount.compareTo(a.immediateCalloutCount)}
     250
     251        // Calculate hours and minutes.
     252        result.totalDownTime.hours = (result.totalDownTime.total / 60).toInteger()
     253        result.totalDownTime.minutes = result.totalDownTime.total % 60
    231254
    232255        // Success.
Note: See TracChangeset for help on using the changeset viewer.