|
@ -48,13 +48,13 @@ public class DishService { |
|
|
@Resource |
|
|
@Resource |
|
|
private DishRepository dishRepository; |
|
|
private DishRepository dishRepository; |
|
|
|
|
|
|
|
|
@Scheduled(cron = "0/5 * * * * *") |
|
|
@Scheduled(cron = "0/2 * * * * *") |
|
|
public void init() { |
|
|
public void init() { |
|
|
if (!UPDATE_LABEL_LOCK.tryLock()) { |
|
|
if (!UPDATE_LABEL_LOCK.tryLock()) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
try { |
|
|
try { |
|
|
List<Dish> dishes = UPDATE_LABEL_TIME == null ? dishRepository.findAll() : dishRepository.findByModifyGreaterThan(UPDATE_LABEL_TIME); |
|
|
List<Dish> dishes = UPDATE_LABEL_TIME == null ? dishRepository.findAll() : dishRepository.findByModifyGreaterThan(UPDATE_LABEL_TIME.minusMillis(1000)); |
|
|
if (dishes.isEmpty()) { |
|
|
if (dishes.isEmpty()) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
@ -99,7 +99,7 @@ public class DishService { |
|
|
|
|
|
|
|
|
public void copy(Dish dish, List<Long> vendors, String operator) { |
|
|
public void copy(Dish dish, List<Long> vendors, String operator) { |
|
|
Instant instant = Instant.now(); |
|
|
Instant instant = Instant.now(); |
|
|
List<Dish> dishes = vendors.stream().filter(vender -> exists(null, dish.getName(), vender)).map(vender -> Dish.builder().name(dish.getName()).vender(vender).marks(dish.getMarks()).poly(dish.getPoly()).label(dish.getLabel()).month(dish.getMonth()).icon(dish.getIcon()).ingredient(dish.getIngredient()).operate(operator).created(instant).modify(instant).build()).collect(Collectors.toList()); |
|
|
List<Dish> dishes = vendors.stream().filter(vender -> !exists(null, dish.getName(), vender)).map(vender -> Dish.builder().name(dish.getName()).vender(vender).marks(dish.getMarks()).poly(dish.getPoly()).label(dish.getLabel()).month(dish.getMonth()).icon(dish.getIcon()).ingredient(dish.getIngredient()).operate(operator).created(instant).modify(instant).build()).collect(Collectors.toList()); |
|
|
dishRepository.saveAll(dishes); |
|
|
dishRepository.saveAll(dishes); |
|
|
log.info("[DishService] copy dishes count = " + dishes.size() + ", operator = " + operator); |
|
|
log.info("[DishService] copy dishes count = " + dishes.size() + ", operator = " + operator); |
|
|
} |
|
|
} |
|
|