Changeset 489 for trunk/grails-app/services
- Timestamp:
- Apr 16, 2010, 2:10:52 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/InventoryItemSearchService.groovy
r485 r489 1 import grails.orm.PagedResultList 2 1 3 /** 2 4 * Service class that encapsulates the business logic for InventoryItem searches. … … 6 8 boolean transactional = false 7 9 10 def dateUtilService 8 11 def messageSource 9 12 … … 37 40 else 38 41 result.message = getMessage(code:"inventoryItem.search.text.below.reorder.none.found") 42 break 43 case "recentlyUsed": 44 result.daysBack = params.daysBack?.isInteger() ? params.daysBack.toInteger() : 14 45 result.inventoryItemList = getRecentlyUsed(params, result.daysBack) 46 if(result.inventoryItemList.totalCount > 0) 47 result.message = getMessage(code:"inventoryItem.search.text.recently.used.description", args:[result.daysBack]) 48 else 49 result.message = getMessage(code:"inventoryItem.search.text.recently.used.none.found", args:[result.daysBack]) 39 50 break 40 51 default: … … 93 104 } // getInventoryBelowReorder 94 105 106 /** 107 * Get a list of recently used inventory items. 108 * @param params The request params. 109 * @param daysBack The number of days back to get results for. 110 */ 111 def getRecentlyUsed(params, daysBack) { 112 def paginateParams = [:] 113 paginateParams.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) 114 paginateParams.offset = params?.offset?.toInteger() ?: 0 115 116 def sort = "inventoryItem." + (params?.sort ?: "name") 117 def order = params?.order == "desc" ? "desc" : "asc" 118 def orderBy = " order by " + sort + ' ' + order 119 120 def namedParams = [:] 121 namedParams.startOfDay = dateUtilService.today - daysBack 122 123 def baseQuery = "from InventoryItem as inventoryItem \ 124 left join inventoryItem.inventoryMovements as inventoryMovement \ 125 where (inventoryItem.isActive = true \ 126 and inventoryMovement.date > :startOfDay \ 127 and inventoryMovement.inventoryMovementType = 1 \ 128 )" 129 130 def searchQuery = "select distinct inventoryItem " + baseQuery + orderBy 131 def list = InventoryItem.executeQuery(searchQuery, namedParams, paginateParams) 132 133 def countQuery = "select count(distinct inventoryItem) as inventoryItemCount " + baseQuery 134 def totalCount = InventoryItem.executeQuery(countQuery, namedParams)[0].toInteger() 135 136 def inventoryItemInstanceList = new PagedResultList(list, totalCount) 137 return inventoryItemInstanceList 138 } // getRecentlyUsed 139 95 140 } // end class
Note: See TracChangeset
for help on using the changeset viewer.