Changeset 476 for trunk/grails-app/services
- Timestamp:
- Apr 7, 2010, 1:49:22 PM (15 years ago)
- Location:
- trunk/grails-app/services
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/DateUtilService.groovy
r474 r476 99 99 100 100 /** 101 * Get the date one year in the future. 102 * @param date The Date object to start with. 103 * @returns A Date object one year in the future. 104 */ 105 public static Date getNextYear(Date date) { 106 use(TimeCategory) { 107 date + 1.years 108 } 109 } 110 111 /** 112 * Get the date one year ago. 113 * @param date The Date object to start with. 114 * @returns A Date object one year ago. 115 */ 116 public static Date getPreviousYear(Date date) { 117 use(TimeCategory) { 118 date - 1.years 119 } 120 } 121 122 /** 101 123 * Make a date object from supplied year, month, day values. 102 124 * The Calendar.getInstance() or Calendar.instance factory returns a new calendar instance, usually … … 104 126 * The time fields are set to zero and cal.getTime() or cal.time returns a java.util.Date object. 105 127 * @param year The year as a string or integer. 106 * @param month The month as a string or integer .107 * @param day The day as a string or integer .128 * @param month The month as a string or integer, defaults to 1 (i.e. January). 129 * @param day The day as a string or integer, defaults to 1. 108 130 * @returns A Date object having the given date and all time fields set to 0, so the very start of the given day. 109 131 */ 110 public static Date makeDate(year, month , day) {132 public static Date makeDate(year, month=1, day=1) { 111 133 Calendar cal = Calendar.instance 112 134 cal.clear() … … 116 138 } 117 139 140 /** 141 * Get the day of month from supplied date. 142 * @param date The date to extract the day of month from. 143 * @returns An integer representing the day of the month. 144 */ 145 public static Integer getDayFromDate(Date date) { 146 Calendar cal = Calendar.instance 147 cal.setTime(date) 148 cal.get(Calendar.DAY_OF_MONTH) 149 } 150 151 /** 152 * Get the month from supplied date. 153 * @param date The date to extract the month from. 154 * @returns An integer representing the month. 155 */ 156 public static Integer getMonthFromDate(Date date) { 157 Calendar cal = Calendar.instance 158 cal.setTime(date) 159 cal.get(Calendar.MONTH) + 1 // Stupid month is 0-based, grumble. 160 } 161 162 /** 163 * Get the year from supplied date. 164 * @param date The date to extract the year from. 165 * @returns An integer representing the year. 166 */ 167 public static Integer getYearFromDate(Date date) { 168 Calendar cal = Calendar.instance 169 cal.setTime(date) 170 cal.get(Calendar.YEAR) 171 } 172 118 173 } -
trunk/grails-app/services/TaskSearchService.groovy
r419 r476 1 /** 2 * Service class that encapsulates the business logic for Task searches. 3 */ 1 4 class TaskSearchService { 2 5 3 6 boolean transactional = false 4 7 8 def authService 5 9 def dateUtilService 6 def authenticateService 7 8 def paramsMax = 99999 9 10 def getTodays(params) { 11 params.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) 12 params.offset = params?.offset?.toInteger() ?: 0 13 params.sort = params?.sort ?: "attentionFlag" 14 params.order = params?.order ?: "desc" 15 16 def taskInstanceList = Task.createCriteria().list( 17 max: params.max, 18 offset: params.offset, 19 sort: params.sort, 20 order: params.order) { 21 ge("targetStartDate", dateUtilService.today) 22 lt("targetStartDate", dateUtilService.getTomorrow()) 23 eq("trash", false) 24 } 25 } 26 27 def getMyTodays(params) { 28 params.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) 29 params.offset = params?.offset?.toInteger() ?: 0 30 params.sort = params?.sort ?: "attentionFlag" 31 params.order = params?.order ?: "desc" 32 33 def taskInstanceList = Task.createCriteria().list( 34 max: params.max, 35 offset: params.offset, 36 sort: params.sort, 37 order: params.order) { 38 eq("leadPerson", Person.get(authenticateService.userDomain().id)) 39 ge("targetStartDate", dateUtilService.today) 40 lt("targetStartDate", dateUtilService.getTomorrow()) 41 eq("trash", false) 42 } 43 } 44 45 def getInTheLastWeek(params) { 46 params.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) 47 params.offset = params?.offset?.toInteger() ?: 0 48 params.sort = params?.sort ?: "attentionFlag" 49 params.order = params?.order ?: "desc" 50 51 def taskInstanceList = Task.createCriteria().list( 52 max: params.max, 53 offset: params.offset, 54 sort: params.sort, 55 order: params.order) { 56 ge("targetStartDate", dateUtilService.oneWeekAgo) 57 lt("targetStartDate", dateUtilService.getTomorrow()) 58 eq("trash", false) 59 } 60 } 61 62 def getMyInTheLastWeek(params) { 63 params.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) 64 params.offset = params?.offset?.toInteger() ?: 0 65 params.sort = params?.sort ?: "attentionFlag" 66 params.order = params?.order ?: "desc" 67 68 def taskInstanceList = Task.createCriteria().list( 69 max: params.max, 70 offset: params.offset, 71 sort: params.sort, 72 order: params.order) { 73 eq("leadPerson", Person.get(authenticateService.userDomain().id)) 74 ge("targetStartDate", dateUtilService.oneWeekAgo) 75 lt("targetStartDate", dateUtilService.getTomorrow()) 76 eq("trash", false) 77 } 78 } 10 def messageSource 11 12 def paramsMax = 100000 13 14 /** 15 * Selects and returns the correct search results based on the supplied quickSearch. 16 * @param params The request params, may contain params.quickSearch string to specify the search. 17 * @param locale The locale to use when generating result.message. 18 */ 19 def getQuickSearch(params, locale) { 20 def result = [:] 21 def currentUser = authService.currentUser 22 result.quickSearch = params.quickSearch ?: "searchPlannersRange" 23 24 def getMessage = { Map m -> 25 messageSource.getMessage(m.code, m.args == null ? null : m.args.toArray(), locale) 26 } 27 28 switch (result.quickSearch) { 29 case "myTodays": 30 result.taskInstanceList = getMyTodays(params) 31 if(result.taskInstanceList.totalCount > 0) 32 result.message = getMessage(code:"task.search.text.my.todays", args:[currentUser]) 33 else 34 result.message = getMessage(code:"task.search.text.my.todays.none.found", args:[currentUser]) 35 break 36 case "myYesterdays": 37 result.taskInstanceList = getMyTodays(params, -1) 38 if(result.taskInstanceList.totalCount > 0) 39 result.message = getMessage(code:"task.search.text.my.yesterdays", args:[currentUser]) 40 else 41 result.message = getMessage(code:"task.search.text.my.yesterdays.none.found", args:[currentUser]) 42 break 43 case "myTomorrows": 44 result.taskInstanceList = getMyTodays(params, 1) 45 if(result.taskInstanceList.totalCount > 0) 46 result.message = getMessage(code:"task.search.text.my.tomorrows", args:[currentUser]) 47 else 48 result.message = getMessage(code:"task.search.text.my.tomorrows.none.found", args:[currentUser]) 49 break 50 case "myPastWeek": 51 result.taskInstanceList = getMyPastWeek(params) 52 if(result.taskInstanceList.totalCount > 0) 53 result.message = getMessage(code:"task.search.text.my.past.week", args:[currentUser]) 54 else 55 result.message = getMessage(code:"task.search.text.my.past.week.none.found", args:[currentUser]) 56 break 57 case "todays": 58 result.taskInstanceList = getTodays(params) 59 if(result.taskInstanceList.totalCount > 0) 60 result.message = getMessage(code:"task.search.text.todays") 61 else 62 result.message = getMessage(code:"task.search.text.todays.none.found") 63 break 64 case "yesterdays": 65 result.taskInstanceList = getTodays(params, -1) 66 if(result.taskInstanceList.totalCount > 0) 67 result.message = getMessage(code:"task.search.text.yesterdays") 68 else 69 result.message = getMessage(code:"task.search.text.yesterdays.none.found") 70 break 71 case "tomorrows": 72 result.taskInstanceList = getTodays(params, 1) 73 if(result.taskInstanceList.totalCount > 0) 74 result.message = getMessage(code:"task.search.text.tomorrows") 75 else 76 result.message = getMessage(code:"task.search.text.tomorrows.none.found") 77 break 78 case "pastWeek": 79 result.taskInstanceList = getPastWeek(params) 80 if(result.taskInstanceList.totalCount > 0) 81 result.message = getMessage(code:"task.search.text.past.week") 82 else 83 result.message = getMessage(code:"task.search.text.past.week.none.found") 84 break 85 case "budgetUnplanned": 86 result.taskInstanceList = getBudgetUnplanned(params) 87 if(result.taskInstanceList.totalCount > 0) 88 result.message = getMessage(code:"task.search.text.budget.unplanned") 89 else 90 result.message = getMessage(code:"task.search.text.budget.unplanned.none.found") 91 break 92 case "budgetPlanned": 93 result.taskInstanceList = getBudgetPlanned(params) 94 if(result.taskInstanceList.totalCount > 0) 95 result.message = getMessage(code:"task.search.text.budget.planned") 96 else 97 result.message = getMessage(code:"task.search.text.budget.planned.none.found") 98 break 99 default: 100 result.taskInstanceList = getPlannersRange(params) 101 if(result.taskInstanceList.totalCount > 0) 102 result.message = getMessage(code:"task.search.text.planners.range") 103 else 104 result.message = getMessage(code:"task.search.text.planners.range.none.found") 105 break 106 } // switch. 107 108 // Success. 109 return result 110 111 } // getQuickSearch 112 113 def getTodays(params, dayAdjustment=0) { 114 params.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) 115 params.offset = params?.offset?.toInteger() ?: 0 116 params.sort = params?.sort ?: "attentionFlag" 117 params.order = params?.order ?: "desc" 118 119 def taskInstanceList = Task.createCriteria().list( 120 max: params.max, 121 offset: params.offset, 122 sort: params.sort, 123 order: params.order) { 124 ge("targetStartDate", dateUtilService.today+dayAdjustment) 125 lt("targetStartDate", dateUtilService.tomorrow+dayAdjustment) 126 eq("trash", false) 127 } 128 } 129 130 def getMyTodays(params, dayAdjustment=0) { 131 params.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) 132 params.offset = params?.offset?.toInteger() ?: 0 133 params.sort = params?.sort ?: "attentionFlag" 134 params.order = params?.order ?: "desc" 135 136 def currentUser = authService.currentUser 137 138 def taskInstanceList = Task.createCriteria().list( 139 max: params.max, 140 offset: params.offset, 141 sort: params.sort, 142 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 159 } // getMyTodays 160 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 79 208 80 209 def getBudgetPlanned(params) { 81 210 params.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) 82 211 params.offset = params?.offset?.toInteger() ?: 0 83 params.sort = params?.sort ?: " attentionFlag"84 params.order = params?.order ?: " desc"212 params.sort = params?.sort ?: "targetStartDate" 213 params.order = params?.order ?: "asc" 85 214 86 215 def taskInstanceList = Task.createCriteria().list( … … 89 218 sort: params.sort, 90 219 order: params.order) { 91 eq("taskBudgetStatus", TaskBudgetStatus. get(2))220 eq("taskBudgetStatus", TaskBudgetStatus.read(2)) 92 221 ge("targetStartDate", dateUtilService.oneWeekAgo) 93 222 lt("targetStartDate", dateUtilService.tomorrow) … … 99 228 params.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) 100 229 params.offset = params?.offset?.toInteger() ?: 0 101 params.sort = params?.sort ?: " attentionFlag"102 params.order = params?.order ?: " desc"230 params.sort = params?.sort ?: "targetStartDate" 231 params.order = params?.order ?: "asc" 103 232 104 233 def taskInstanceList = Task.createCriteria().list( … … 107 236 sort: params.sort, 108 237 order: params.order) { 109 eq("taskBudgetStatus", TaskBudgetStatus.get(1)) 110 ge("targetStartDate", dateUtilService.oneWeekAgo) 111 lt("targetStartDate", dateUtilService.getTomorrow()) 238 eq("taskBudgetStatus", TaskBudgetStatus.read(1)) 239 ge("targetStartDate", dateUtilService.oneWeekAgo) 240 lt("targetStartDate", dateUtilService.tomorrow) 241 eq("trash", false) 242 } 243 } 244 245 def getPlannersRange(params) { 246 params.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) 247 params.offset = params?.offset?.toInteger() ?: 0 248 params.sort = params?.sort ?: "targetStartDate" 249 params.order = params?.order ?: "asc" 250 251 def taskInstanceList = Task.createCriteria().list( 252 max: params.max, 253 offset: params.offset, 254 sort: params.sort, 255 order: params.order) { 256 ge("targetStartDate", dateUtilService.oneWeekAgo) 257 lt("targetStartDate", dateUtilService.today + 15) 112 258 eq("trash", false) 113 259 }
Note: See TracChangeset
for help on using the changeset viewer.