|
@ -19,7 +19,6 @@ import org.springframework.data.jpa.domain.Specification; |
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
import javax.annotation.PostConstruct; |
|
|
|
|
|
import javax.annotation.Resource; |
|
|
import javax.annotation.Resource; |
|
|
import javax.persistence.criteria.Predicate; |
|
|
import javax.persistence.criteria.Predicate; |
|
|
import java.math.BigDecimal; |
|
|
import java.math.BigDecimal; |
|
@ -56,6 +55,10 @@ public class DishService { |
|
|
} |
|
|
} |
|
|
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); |
|
|
|
|
|
if (dishes.isEmpty()) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
UPDATE_LABEL_TIME = Instant.now(); |
|
|
Map<String, Ingredient> ingredientMap = ingredientService.getFullByKeys(dishes.stream().filter(x -> CollectionUtils.isNotEmpty(x.getIngredient())).flatMap(x -> x.getIngredient().stream().map(DishItemDTO::getKey)).collect(Collectors.toSet())).stream().collect(Collectors.toMap(Ingredient::getKey, v -> v)); |
|
|
Map<String, Ingredient> ingredientMap = ingredientService.getFullByKeys(dishes.stream().filter(x -> CollectionUtils.isNotEmpty(x.getIngredient())).flatMap(x -> x.getIngredient().stream().map(DishItemDTO::getKey)).collect(Collectors.toSet())).stream().collect(Collectors.toMap(Ingredient::getKey, v -> v)); |
|
|
dishes.forEach(dish -> { |
|
|
dishes.forEach(dish -> { |
|
|
Map<String, BigDecimal> items = dish.getIngredient().stream().filter(x -> ingredientMap.containsKey(x.getKey())).flatMap(x -> |
|
|
Map<String, BigDecimal> items = dish.getIngredient().stream().filter(x -> ingredientMap.containsKey(x.getKey())).flatMap(x -> |
|
@ -79,7 +82,6 @@ public class DishService { |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
log.error("[DishService] update label exception : " + e.getMessage(), e); |
|
|
log.error("[DishService] update label exception : " + e.getMessage(), e); |
|
|
} finally { |
|
|
} finally { |
|
|
UPDATE_LABEL_TIME = Instant.now(); |
|
|
|
|
|
UPDATE_LABEL_LOCK.unlock(); |
|
|
UPDATE_LABEL_LOCK.unlock(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|