Changeset 479 for trunk/grails-app/services
- Timestamp:
- Apr 12, 2010, 12:00:04 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/TaskSearchService.groovy
r476 r479 1 import grails.orm.PagedResultList 2 1 3 /** 2 4 * Service class that encapsulates the business logic for Task searches. … … 111 113 } // getQuickSearch 112 114 115 /** 116 * Get all tasks that are not in the trash, by default today's tasks. 117 * @param params The request params. 118 * @param dayAdjustment The number of days to adjust from today, defaults to 0. 119 */ 113 120 def getTodays(params, dayAdjustment=0) { 114 121 params.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) … … 122 129 sort: params.sort, 123 130 order: params.order) { 124 ge("targetStartDate", dateUtilService.today+dayAdjustment)125 131 lt("targetStartDate", dateUtilService.tomorrow+dayAdjustment) 126 eq("trash", false) 127 } 128 } 129 132 ge("targetCompletionDate", dateUtilService.today+dayAdjustment) 133 eq("trash", false) 134 } 135 } 136 137 /** 138 * Get current user's tasks, by default today's tasks. 139 * "Approved tasks where I am the lead or have been assigned" 140 * @param params The request params. 141 * @param dayAdjustment The number of days to adjust from today, defaults to 0. 142 */ 130 143 def getMyTodays(params, dayAdjustment=0) { 144 def paginateParams = [:] 145 paginateParams.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) 146 paginateParams.offset = params?.offset?.toInteger() ?: 0 147 148 def sort = "task." + (params?.sort ?: "attentionFlag") 149 def order = params?.order == "asc" ? "asc" : "desc" 150 def orderBy = " order by " + sort + ' ' + order 151 152 def namedParams = [:] 153 namedParams.currentUser = authService.currentUser 154 namedParams.startOfDay = dateUtilService.today+dayAdjustment 155 namedParams.startOfNextDay = dateUtilService.tomorrow+dayAdjustment 156 157 def baseQuery = "from Task as task \ 158 left join task.assignedPersons as assignedPersonOfTask \ 159 left join assignedPersonOfTask.person as assignedPerson \ 160 left join task.assignedGroups as assignedGroupOfTask \ 161 left join assignedGroupOfTask.personGroup as personGroup \ 162 left join personGroup.persons as assignedPersonViaGroup \ 163 where (task.trash = false \ 164 and task.approved = true \ 165 and ( \ 166 task.targetStartDate < :startOfNextDay \ 167 and task.targetCompletionDate >= :startOfDay \ 168 ) \ 169 and ( \ 170 task.leadPerson = :currentUser \ 171 or assignedPerson = :currentUser \ 172 or assignedPersonViaGroup = :currentUser \ 173 ) \ 174 )" 175 176 def searchQuery = "select distinct task " + baseQuery + orderBy 177 def list = Task.executeQuery(searchQuery, namedParams, paginateParams) 178 179 def countQuery = "select count(distinct task) as taskCount " + baseQuery 180 def totalCount = Task.executeQuery(countQuery, namedParams)[0].toInteger() 181 182 def taskInstanceList = new PagedResultList(list, totalCount) 183 return taskInstanceList 184 } // getMyTodays 185 186 /** 187 * Get all tasks that are not in the trash, during the past week. 188 * @param params The request params. 189 */ 190 def getPastWeek(params) { 131 191 params.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) 132 192 params.offset = params?.offset?.toInteger() ?: 0 … … 134 194 params.order = params?.order ?: "desc" 135 195 136 def currentUser = authService.currentUser137 138 196 def taskInstanceList = Task.createCriteria().list( 139 197 max: params.max, … … 141 199 sort: params.sort, 142 200 order: params.order) { 143 ge("targetStartDate", dateUtilService.today+dayAdjustment) 144 lt("targetStartDate", dateUtilService.tomorrow+dayAdjustment) 145 eq("trash", false) 146 eq("approved", true) 147 or { 148 eq("leadPerson", currentUser) 149 assignedPersons { 150 eq("person", currentUser) 151 } 152 assignedGroups { 153 currentUser.personGroups.each() { 154 eq("personGroup", it) 155 } 156 } // assignedGroups 157 } // or 158 } // criteria 201 lt("targetStartDate", dateUtilService.tomorrow) 202 ge("targetCompletionDate", dateUtilService.oneWeekAgo) 203 eq("trash", false) 204 } 205 } 206 207 /** 208 * Get current user's tasks in the past week. 209 * "Approved tasks where I am the lead or have been assigned" 210 * @param params The request params. 211 */ 212 def getMyPastWeek(params) { 213 def paginateParams = [:] 214 paginateParams.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) 215 paginateParams.offset = params?.offset?.toInteger() ?: 0 216 217 def sort = "task." + (params?.sort ?: "attentionFlag") 218 def order = params?.order == "asc" ? "asc" : "desc" 219 def orderBy = " order by " + sort + ' ' + order 220 221 def namedParams = [:] 222 namedParams.currentUser = authService.currentUser 223 namedParams.startOfDay = dateUtilService.oneWeekAgo 224 namedParams.startOfNextDay = dateUtilService.tomorrow 225 226 def baseQuery = "from Task as task \ 227 left join task.assignedPersons as assignedPersonOfTask \ 228 left join assignedPersonOfTask.person as assignedPerson \ 229 left join task.assignedGroups as assignedGroupOfTask \ 230 left join assignedGroupOfTask.personGroup as personGroup \ 231 left join personGroup.persons as assignedPersonViaGroup \ 232 where (task.trash = false \ 233 and task.approved = true \ 234 and ( \ 235 task.targetStartDate < :startOfNextDay \ 236 and task.targetCompletionDate >= :startOfDay \ 237 ) \ 238 and ( \ 239 task.leadPerson = :currentUser \ 240 or assignedPerson = :currentUser \ 241 or assignedPersonViaGroup = :currentUser \ 242 ) \ 243 )" 244 245 def searchQuery = "select distinct task " + baseQuery + orderBy 246 def list = Task.executeQuery(searchQuery, namedParams, paginateParams) 247 248 def countQuery = "select count(distinct task) as taskCount " + baseQuery 249 def totalCount = Task.executeQuery(countQuery, namedParams)[0].toInteger() 250 251 def taskInstanceList = new PagedResultList(list, totalCount) 252 return taskInstanceList 159 253 } // getMyTodays 160 254 161 def getPastWeek(params) { 162 params.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) 163 params.offset = params?.offset?.toInteger() ?: 0 164 params.sort = params?.sort ?: "attentionFlag" 165 params.order = params?.order ?: "desc" 166 167 def taskInstanceList = Task.createCriteria().list( 168 max: params.max, 169 offset: params.offset, 170 sort: params.sort, 171 order: params.order) { 172 ge("targetStartDate", dateUtilService.oneWeekAgo) 173 lt("targetStartDate", dateUtilService.tomorrow) 174 eq("trash", false) 175 } 176 } 177 178 def getMyPastWeek(params) { 179 params.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) 180 params.offset = params?.offset?.toInteger() ?: 0 181 params.sort = params?.sort ?: "attentionFlag" 182 params.order = params?.order ?: "desc" 183 184 def currentUser = authService.currentUser 185 186 def taskInstanceList = Task.createCriteria().list( 187 max: params.max, 188 offset: params.offset, 189 sort: params.sort, 190 order: params.order) { 191 ge("targetStartDate", dateUtilService.oneWeekAgo) 192 lt("targetStartDate", dateUtilService.tomorrow) 193 eq("trash", false) 194 eq("approved", true) 195 or { 196 eq("leadPerson", currentUser) 197 assignedPersons { 198 eq("person", currentUser) 199 } 200 assignedGroups { 201 currentUser.personGroups.each() { 202 eq("personGroup", it) 203 } 204 } // assignedGroups 205 } // or 206 } // criteria 207 } // getMyPastWeek 208 255 /** 256 * "Tasks with budget status of Planned, in the past week." 257 * @param params The request params. 258 */ 209 259 def getBudgetPlanned(params) { 210 260 params.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) … … 219 269 order: params.order) { 220 270 eq("taskBudgetStatus", TaskBudgetStatus.read(2)) 221 ge("targetStartDate", dateUtilService.oneWeekAgo)222 271 lt("targetStartDate", dateUtilService.tomorrow) 223 eq("trash", false) 224 } 225 } 226 272 ge("targetCompletionDate", dateUtilService.oneWeekAgo) 273 eq("trash", false) 274 } 275 } 276 277 /** 278 * "Tasks with budget status of Unplanned, in the past week." 279 * @param params The request params. 280 */ 227 281 def getBudgetUnplanned(params) { 228 282 params.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) … … 237 291 order: params.order) { 238 292 eq("taskBudgetStatus", TaskBudgetStatus.read(1)) 239 ge("targetStartDate", dateUtilService.oneWeekAgo)240 293 lt("targetStartDate", dateUtilService.tomorrow) 241 eq("trash", false) 242 } 243 } 244 294 ge("targetCompletionDate", dateUtilService.oneWeekAgo) 295 eq("trash", false) 296 } 297 } 298 299 /** 300 * "Tasks in the past week and two weeks ahead." 301 * @param params The request params. 302 */ 245 303 def getPlannersRange(params) { 246 304 params.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax)
Note: See TracChangeset
for help on using the changeset viewer.