| Line 179... |
Line 179... |
| 179 |
// ?limit=100 -> process only N stores (for staged runs)
|
179 |
// ?limit=100 -> process only N stores (for staged runs)
|
| 180 |
@GetMapping(value = "/beatPlan/migrateStoreLatLng")
|
180 |
@GetMapping(value = "/beatPlan/migrateStoreLatLng")
|
| 181 |
public ResponseEntity<?> migrateStoreLatLng(
|
181 |
public ResponseEntity<?> migrateStoreLatLng(
|
| 182 |
@RequestParam(required = false, defaultValue = "false") boolean apply,
|
182 |
@RequestParam(required = false, defaultValue = "false") boolean apply,
|
| 183 |
@RequestParam(required = false, defaultValue = "5") double thresholdKm,
|
183 |
@RequestParam(required = false, defaultValue = "5") double thresholdKm,
|
| - |
|
184 |
@RequestParam(required = false, defaultValue = "0") int limit,
|
| 184 |
@RequestParam(required = false, defaultValue = "0") int limit) throws ProfitMandiBusinessException {
|
185 |
@RequestParam(required = false, defaultValue = "0") int offset) throws ProfitMandiBusinessException {
|
| 185 |
|
186 |
|
| 186 |
List<FofoStore> stores = fofoStoreRepository.selectActiveStores();
|
187 |
List<FofoStore> all = fofoStoreRepository.selectActiveStores();
|
| - |
|
188 |
int totalAvailable = all.size();
|
| - |
|
189 |
// offset + limit so this can be run in batches against large datasets
|
| - |
|
190 |
int from = Math.max(0, Math.min(offset, totalAvailable));
|
| 187 |
if (limit > 0 && stores.size() > limit) stores = stores.subList(0, limit);
|
191 |
int to = limit > 0 ? Math.min(from + limit, totalAvailable) : totalAvailable;
|
| - |
|
192 |
List<FofoStore> stores = all.subList(from, to);
|
| 188 |
|
193 |
|
| 189 |
List<Integer> ids = stores.stream().map(FofoStore::getId).collect(Collectors.toList());
|
194 |
List<Integer> ids = stores.stream().map(FofoStore::getId).collect(Collectors.toList());
|
| 190 |
Map<Integer, CustomRetailer> retailerMap = retailerService.getFofoRetailers(ids);
|
195 |
Map<Integer, CustomRetailer> retailerMap = retailerService.getFofoRetailers(ids);
|
| 191 |
|
196 |
|
| 192 |
int total = stores.size();
|
197 |
int total = stores.size();
|
| Line 259... |
Line 264... |
| 259 |
}
|
264 |
}
|
| 260 |
|
265 |
|
| 261 |
Map<String, Object> result = new HashMap<>();
|
266 |
Map<String, Object> result = new HashMap<>();
|
| 262 |
result.put("mode", apply ? "APPLIED" : "DRY RUN — pass &apply=true to actually update");
|
267 |
result.put("mode", apply ? "APPLIED" : "DRY RUN — pass &apply=true to actually update");
|
| 263 |
result.put("thresholdKm", thresholdKm);
|
268 |
result.put("thresholdKm", thresholdKm);
|
| - |
|
269 |
result.put("totalAvailable", totalAvailable); // total active stores in DB
|
| 264 |
result.put("total", total);
|
270 |
result.put("offset", from);
|
| - |
|
271 |
result.put("processed", total); // stores processed this run
|
| - |
|
272 |
result.put("nextOffset", to); // next offset to resume (or = totalAvailable when done)
|
| - |
|
273 |
result.put("done", to >= totalAvailable);
|
| 265 |
result.put("updated", updated);
|
274 |
result.put("updated", updated);
|
| 266 |
result.put("kept", kept);
|
275 |
result.put("kept", kept);
|
| 267 |
result.put("noAddress", noAddress);
|
276 |
result.put("noAddress", noAddress);
|
| 268 |
result.put("noGeocode", noGeocode);
|
277 |
result.put("noGeocode", noGeocode);
|
| 269 |
result.put("errored", errored);
|
278 |
result.put("errored", errored);
|