Index: src/main/groovy/com/lemans/pricecalc/services/catalog/CatalogPartService.groovy =================================================================== diff -u -rd625529fe2a4082047688c0abd2b157c0ffd6194 -r2f0ca134141786cb874d4ee6395b360c1bdc13ac --- src/main/groovy/com/lemans/pricecalc/services/catalog/CatalogPartService.groovy (.../CatalogPartService.groovy) (revision d625529fe2a4082047688c0abd2b157c0ffd6194) +++ src/main/groovy/com/lemans/pricecalc/services/catalog/CatalogPartService.groovy (.../CatalogPartService.groovy) (revision 2f0ca134141786cb874d4ee6395b360c1bdc13ac) @@ -50,18 +50,8 @@ vp.subComCodeId, scc.subComCode, scc.subComCodeDescr, - vp.supplierPrice AS cost, - vp.nprice, - vp.npriceDate, - vp.nretPrice, - vp.lockPrice, - vp.retailAA, - vp.dealerAA, - vp.originalDealerPrice, vp.derivedPartStatusId, - vp.derivedPartStatusDescr, - partDealerMargin = CASE WHEN (cp.baseDealerPrice > 0 AND vp.supplierPrice > 0 ) THEN Round(((cp.baseDealerPrice - vp.supplierPrice ) / cp.baseDealerPrice ) * 100, 1) ELSE 0 END, - partRetailMargin = CASE WHEN (cp.retailPrice > 0 AND cp.baseDealerPrice > 0 ) THEN Round(((cp.retailPrice - cp.baseDealerPrice ) / cp.retailPrice ) * 100, 1) ELSE 0 END + vp.derivedPartStatusDescr FROM [PartsSource_DS].dbo.vwPart vp WITH(NOLOCK) LEFT OUTER JOIN dbo.SubComCode scc WITH(NOLOCK) Index: src/main/groovy/com/lemans/pricecalc/services/vendor/VendorService.groovy =================================================================== diff -u -r22565e63e0f2599d4c7a520b755587b5083bcb99 -r2f0ca134141786cb874d4ee6395b360c1bdc13ac --- src/main/groovy/com/lemans/pricecalc/services/vendor/VendorService.groovy (.../VendorService.groovy) (revision 22565e63e0f2599d4c7a520b755587b5083bcb99) +++ src/main/groovy/com/lemans/pricecalc/services/vendor/VendorService.groovy (.../VendorService.groovy) (revision 2f0ca134141786cb874d4ee6395b360c1bdc13ac) @@ -8,6 +8,7 @@ import org.springframework.stereotype.Service import javax.servlet.ServletResponse +import java.util.concurrent.CompletableFuture @Service @SuppressWarnings(['CyclomaticComplexity']) @@ -23,11 +24,7 @@ cv.vendorId, cv.vendorName, cv.vendorDueDate, - cv.revisionDeadlineDate, - cv.buyerGlobalId, - cv.buyerManagerGlobalId, - cv.managerName AS manager, - cv.buyerName AS buyer + cv.revisionDeadlineDate FROM CalcPro.[vwcatalogVendor] cv WITH(NOLOCK) ) @@ -53,7 +50,7 @@ """ private static final String VENDOR_DOWNLOAD_QUERY = """ -SELECT catalogName, vendorId, vendorName, sectionName, catalogCode, buyer, manager, calcDueDate, revisionDeadline +SELECT catalogName, vendorId, vendorName, sectionName, catalogCode, calcDueDate, revisionDeadline FROM (SELECT DISTINCT c.catalogName AS catalogName, @@ -63,8 +60,6 @@ s.sectionName AS sectionName, s.sequence, c.catalogCode AS catalogCode, -cv.buyerGlobalId AS buyer, -cv.managerName AS manager, CONVERT(nvarchar(30), cv.vendorDueDate, 101) AS calcDueDate, CONVERT(nvarchar(30), cv.revisionDeadlineDate, 101) AS revisionDeadline, ROW_NUMBER() OVER (PARTITION BY p.vendorId ORDER BY s.sequence) AS row_number @@ -94,11 +89,33 @@ Map findVendors(Map criteria) { criteria.sorting = criteria.sorting ?: 'vendorId+ASC' Map data = dqx(criteria).executeFrom(VENDOR_QUERY, clauses(criteria)) - augmentFirstSection(data.results, criteria) - vendorMetaData(data.results, criteria) + CompletableFuture augmentTask = CompletableFuture.runAsync ({ -> augmentFirstSection(data.results, criteria) }) + CompletableFuture vendorMetaDataTask = CompletableFuture.runAsync ({ -> vendorMetaData(data.results, criteria) }) + CompletableFuture buyerManagerTask = CompletableFuture.runAsync ({ -> buyerManager(data.results, criteria) }) + CompletableFuture.allOf(augmentTask, vendorMetaDataTask, buyerManagerTask).join() data } + private void buyerManager(List vendors, Map criteria) { + if (vendors) { + String query = """SELECT DISTINCT vp.buyerGlobalId, vp.buyerManagerGlobalId, vp.buyerName, vp.buyerManagerName, vp.vendorId FROM vwPart vp WITH(NOLOCK) WHERE vp.vendorId IN (${vendors?.collect { "'${it?.vendorId}'" }?.join(',')})""" + + Map buyerManagerData = sql().rows(query).groupBy { it.vendorId } + vendors.each { vendor -> + def vendorId = vendor.vendorId + List data = buyerManagerData.get(vendorId, []).collect { it -> + [ + buyerGlobalId: it.buyerGlobalId, + buyerManagerGlobalId: it.buyerManagerGlobalId, + buyer: it.buyerName, + manager: it.buyerManagerName + ] + } + vendor.buyerManager = data + } + } + } + Map findVendor(Map criteria) { CatalogVendor catalogVendor = catalogVendorRepository.findByIdAndDateDeletedIsNull(criteria.catalogVendorId) dqx([catalogVendorId: catalogVendor.id]).executeOneFrom('CalcPro.vwCatalogVendor', ['catalogVendorId = :catalogVendorId']) @@ -172,19 +189,28 @@ void downloadVendors(Map criteria, ServletResponse response) { List vendors List results = sql().rows([catalogId: criteria.catalogId], VENDOR_DOWNLOAD_QUERY) - if (criteria._is_pc_manager_) { vendors = results.findAll { it.manager?.replaceAll("\\s", '')?.equalsIgnoreCase(criteria.username) } } - else if (criteria._is_pc_buyer_) { vendors = results.findAll { it.buyer?.replaceAll("\\s", '')?.equalsIgnoreCase(criteria.username) } } - else { vendors = results } - CSVWriter csvWriter = new CSVWriter(response.writer) - String[] header = vendors[0]?.keySet() - List output = [] - output << header - vendors?.each { Map it -> - String[] temp = it.values() - output << temp + if (results) { + String query = """SELECT DISTINCT vp.buyerName, vp.buyerManagerName, vp.vendorId FROM vwPart vp WITH(NOLOCK) WHERE vp.vendorId IN (${results?.collect { "'${it?.vendorId}'" }?.join(',')})""" + Map buyerManagerData = sql().rows(query).groupBy { it.vendorId } + results.each { vendor -> + def vendorId = vendor.vendorId + vendor.buyer = buyerManagerData.get(vendorId, []).collect { it.buyerName }.findAll { it != null }.unique().join('|') + vendor.manager = buyerManagerData.get(vendorId, []).collect { it.buyerManagerName }.findAll { it != null }.unique().join('|') + } + if (criteria._is_pc_manager_) { vendors = results.findAll { it.manager?.replaceAll("\\s", '')?.equalsIgnoreCase(criteria.username) } } + else if (criteria._is_pc_buyer_) { vendors = results.findAll { it.buyer?.replaceAll("\\s", '')?.equalsIgnoreCase(criteria.username) } } + else { vendors = results } + CSVWriter csvWriter = new CSVWriter(response.writer) + String[] header = vendors[0]?.keySet() + List output = [] + output << header + vendors?.each { Map it -> + String[] temp = it.values() + output << temp + } + csvWriter.writeAll(output) + csvWriter.close() } - csvWriter.writeAll(output) - csvWriter.close() } List clauses(Map criteria) {