|
@@ -21,8 +21,11 @@ import com.uas.search.util.CollectionUtils;
|
|
|
import java.lang.annotation.Annotation;
|
|
|
import java.lang.reflect.Field;
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Map.Entry;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
import javax.persistence.Column;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.dao.EmptyResultDataAccessException;
|
|
@@ -99,7 +102,7 @@ public class JdbcServiceImpl<T> implements JdbcService{
|
|
|
List<T> data = null;
|
|
|
// 器件索引
|
|
|
if (SearchConstants.COMPONENT_TABLE_NAME.equals(tableName)) {
|
|
|
- data = queryComponents(sql, true);
|
|
|
+ data = queryComponents(sql, startId, endId, true);
|
|
|
}
|
|
|
// Product索引
|
|
|
if (PRODUCTS_PRIVATE_TABLE_NAME.equals(tableName)) {
|
|
@@ -126,15 +129,25 @@ public class JdbcServiceImpl<T> implements JdbcService{
|
|
|
* @param needProperties 是否需要获取属性值
|
|
|
* @return
|
|
|
*/
|
|
|
- private List<T> queryComponents(String sql, boolean needProperties) {
|
|
|
- List<Component> components = jdbcTemplate.query(sql.replace("where", "left join product$brand on product$brand.br_id=product$component.cmp_brid left join product$kind on product$kind.ki_id = product$component.cmp_kiid where"), new Component());
|
|
|
- String propertyValueSql = "select * from product$propertyvalue left join product$property on product$propertyvalue.pv_propertyid = product$property.pt_id where pv_componentid = ";
|
|
|
- if (!CollectionUtils.isEmpty(components) && needProperties) {
|
|
|
- for (Component component : components) {
|
|
|
- component.setProperties(new HashSet<>(jdbcTemplate.query(propertyValueSql + component.getId(), new PropertyValue())));
|
|
|
+ private List<T> queryComponents(String sql, Long startId, Long endId, boolean needProperties) {
|
|
|
+ List<Component> components = new ArrayList<>();
|
|
|
+ if (needProperties) {
|
|
|
+ String propertyValueSql = "select * from product$component left join product$propertyvalue on product$propertyvalue.pv_componentid = product$component.cmp_id left join product$property on product$propertyvalue.pv_propertyid = product$property.pt_id left join product$kind on product$component.cmp_kiid = product$kind.ki_id left join product$brand on product$component.cmp_brid = product$brand.br_id where product$component.cmp_id between %d and %d";
|
|
|
+ List<Component> componentList = jdbcTemplate.query(String.format(propertyValueSql, startId, endId), new Component());
|
|
|
+ Map<Long, List<Component>> componentMap = componentList.stream().collect(Collectors.groupingBy(Component :: getId));
|
|
|
+ for (Entry<Long, List<Component>> entery : componentMap.entrySet()) {
|
|
|
+ List<Component> componentLists = componentMap.get(entery.getKey());
|
|
|
+ Component finalComponent = componentLists.get(0);
|
|
|
+ Set<PropertyValue> propertyValues = componentLists.stream().filter(
|
|
|
+ c -> c.getPropertyValue() != null).map(c -> c.getPropertyValue()).collect(Collectors.toSet());
|
|
|
+ finalComponent.setProperties(propertyValues);
|
|
|
+ finalComponent.setPropertyValue(null);
|
|
|
+ components.add(finalComponent);
|
|
|
}
|
|
|
+ return (List<T>)components;
|
|
|
+ } else {
|
|
|
+ return jdbcTemplate.query(sql.replace("where", "left join product$brand on product$brand.br_id=product$component.cmp_brid left join product$kind on product$kind.ki_id = product$component.cmp_kiid where"), new Component());
|
|
|
}
|
|
|
- return (List<T>) components;
|
|
|
}
|
|
|
|
|
|
/**
|