Browse Source

器件数据获取优化

wangyc 7 years ago
parent
commit
8b60a5a518

+ 2 - 0
mall-search/src/main/java/com/uas/search/model/Component.java

@@ -285,7 +285,9 @@ public class Component implements Serializable, RowMapper {
 		component.setVisitCount(rs.getLong("cmp_visit_count"));
 		component.setVisitCount(rs.getLong("cmp_visit_count"));
 		component.setWeight(rs.getDouble("searchweight"));
 		component.setWeight(rs.getDouble("searchweight"));
 		component.setKindId(rs.getLong("cmp_kiid"));
 		component.setKindId(rs.getLong("cmp_kiid"));
+		component.setKind(new Kind().mapRow(rs, i));
 		component.setBrandId(rs.getLong("cmp_brid"));
 		component.setBrandId(rs.getLong("cmp_brid"));
+		component.setBrand(new Brand().mapRow(rs, i));
 		return component;
 		return component;
 	}
 	}
 }
 }

+ 1 - 0
mall-search/src/main/java/com/uas/search/model/PropertyValue.java

@@ -128,6 +128,7 @@ public class PropertyValue implements RowMapper, Serializable {
 		propertyValue.setValue(rs.getString("pv_value"));
 		propertyValue.setValue(rs.getString("pv_value"));
 		propertyValue.setComponentid(rs.getLong("pv_componentid"));
 		propertyValue.setComponentid(rs.getLong("pv_componentid"));
 		propertyValue.setDetno(rs.getShort("pv_detno"));
 		propertyValue.setDetno(rs.getShort("pv_detno"));
+		propertyValue.setProperty(new Property().mapRow(rs, i));
 		return propertyValue;
 		return propertyValue;
 	}
 	}
 }
 }

+ 9 - 35
mall-search/src/main/java/com/uas/search/service/impl/JdbcServiceImpl.java

@@ -83,9 +83,9 @@ public class JdbcServiceImpl<T> implements JdbcService{
     }
     }
 
 
     @Override
     @Override
-    public List<T> getData(String tableName, Long startId, Long endId, String sortField,
-        String direct) {
-        String sql = String.format("select * from %s where %s between %d and %d order by %s %s", tableName, sortField, startId, endId, sortField, direct);
+    public List<T> getData(String tableName, Long startId, Long endId, String sortField, String direct) {
+        String sql = String.format("select * from %s where %s between %d and %d order by %s %s", tableName, sortField,
+            startId, endId, sortField, direct);
         List<T> data = null;
         List<T> data = null;
         // 器件索引
         // 器件索引
         if (SearchConstants.COMPONENT_TABLE_NAME.equals(tableName)) {
         if (SearchConstants.COMPONENT_TABLE_NAME.equals(tableName)) {
@@ -115,39 +115,13 @@ public class JdbcServiceImpl<T> implements JdbcService{
      * @return
      * @return
      */
      */
     private List<T> queryComponents(String sql, boolean needProperties) {
     private List<T> queryComponents(String sql, boolean needProperties) {
-        List<Component> components = jdbcTemplate.query(sql, new Component());
-        String kindSql = "select * from product$kind where ki_id = ";
-        String brandSql = "select * from product$brand where br_id = ";
-        String propertyValueSql = "select * from product$propertyvalue where pv_componentid = ";
-        String propertySql = "select * from product$property where pt_id = ";
-        if (!CollectionUtils.isEmpty(components)) {
+        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) {
             for (Component component : components) {
-                if (component.getKindId() != null) {
-                    List<Kind> kinds = jdbcTemplate.query(kindSql + component.getKindId(), new Kind());
-                    if (!CollectionUtils.isEmpty(kinds)) {
-                        component.setKind(kinds.get(0));
-                    }
-                }
-                if (component.getBrandId() != null) {
-                    List<Brand> brands = jdbcTemplate.query(brandSql + component.getBrandId(), new Brand());
-                    if (!CollectionUtils.isEmpty(brands)) {
-                        component.setBrand(brands.get(0));
-                    }
-                }
-
-                if (needProperties) {
-                    List<PropertyValue> propertyValues = jdbcTemplate.query(propertyValueSql + component.getId(), new PropertyValue());
-                    if (!CollectionUtils.isEmpty(propertyValues)) {
-                        Set<PropertyValue> propertyValueSet = new HashSet<>();
-                        for (PropertyValue value : propertyValues) {
-                            List<Property> properties = jdbcTemplate.query(propertySql + value.getPropertyid(), new Property());
-                            if (!CollectionUtils.isEmpty(properties)) {
-                                value.setProperty(properties.get(0));
-                            }
-                            propertyValueSet.add(value);
-                        }
-                        component.setProperties(propertyValueSet);
-                    }
+                List<PropertyValue> propertyValues = jdbcTemplate.query(propertyValueSql + component.getId(), new PropertyValue());
+                if (!CollectionUtils.isEmpty(propertyValues)) {
+                    component.setProperties(new HashSet<>(propertyValues));
                 }
                 }
             }
             }
         }
         }