|
|
@@ -2,13 +2,18 @@ package com.uas.search.service.impl;
|
|
|
|
|
|
import static com.uas.search.constant.SearchConstants.GOODS_TABLE_NAME;
|
|
|
import static com.uas.search.constant.SearchConstants.PRODUCTS_PRIVATE_TABLE_NAME;
|
|
|
+import static com.uas.search.constant.SearchConstants.TRADE_GOODS_TABLE_NAME;
|
|
|
|
|
|
import com.uas.search.constant.SearchConstants;
|
|
|
+import com.uas.search.dao.GoodsDao;
|
|
|
import com.uas.search.model.Brand;
|
|
|
import com.uas.search.model.Component;
|
|
|
+import com.uas.search.model.Goods;
|
|
|
import com.uas.search.model.Kind;
|
|
|
+import com.uas.search.model.Products;
|
|
|
import com.uas.search.model.Property;
|
|
|
import com.uas.search.model.PropertyValue;
|
|
|
+import com.uas.search.model.Store;
|
|
|
import com.uas.search.model.TradeGoods;
|
|
|
import com.uas.search.model.V_Products;
|
|
|
import com.uas.search.service.JdbcService;
|
|
|
@@ -34,8 +39,15 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class JdbcServiceImpl<T> implements JdbcService{
|
|
|
|
|
|
+ private final JdbcTemplate jdbcTemplate;
|
|
|
+
|
|
|
+ private final GoodsDao goodsDao;
|
|
|
+
|
|
|
@Autowired
|
|
|
- private JdbcTemplate jdbcTemplate;
|
|
|
+ public JdbcServiceImpl(JdbcTemplate jdbcTemplate, GoodsDao goodsDao) {
|
|
|
+ this.jdbcTemplate = jdbcTemplate;
|
|
|
+ this.goodsDao = goodsDao;
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public Long getTotalElements(String tablename) {
|
|
|
@@ -66,11 +78,33 @@ public class JdbcServiceImpl<T> implements JdbcService{
|
|
|
List<T> data = null;
|
|
|
// 器件索引
|
|
|
if (SearchConstants.COMPONENT_TABLE_NAME.equals(tableName)) {
|
|
|
- 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 = ";
|
|
|
+ data = queryComponents(sql, true);
|
|
|
+ }
|
|
|
+ // Product索引
|
|
|
+ if (PRODUCTS_PRIVATE_TABLE_NAME.equals(tableName)) {
|
|
|
+ data = queryVProducts(sql);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Goods索引
|
|
|
+ if (TRADE_GOODS_TABLE_NAME.equals(tableName)) {
|
|
|
+ data = queryGoods(sql);
|
|
|
+ }
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取Component
|
|
|
+ * @param sql sql
|
|
|
+ * @param needProperties 是否需要获取属性值
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ 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)) {
|
|
|
for (Component component : components) {
|
|
|
if (component.getKindId() != null) {
|
|
|
List<Kind> kinds = jdbcTemplate.query(kindSql + component.getKindId(), new Kind());
|
|
|
@@ -85,32 +119,40 @@ public class JdbcServiceImpl<T> implements JdbcService{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- 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));
|
|
|
+ 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);
|
|
|
}
|
|
|
- propertyValueSet.add(value);
|
|
|
+ component.setProperties(propertyValueSet);
|
|
|
}
|
|
|
- component.setProperties(propertyValueSet);
|
|
|
}
|
|
|
}
|
|
|
- data = (List<T>) components;
|
|
|
- }
|
|
|
- // Product索引
|
|
|
- if (PRODUCTS_PRIVATE_TABLE_NAME.equals(tableName)) {
|
|
|
- data = (List<T>) jdbcTemplate.query(sql, new V_Products());
|
|
|
}
|
|
|
+ return (List<T>) components;
|
|
|
+ }
|
|
|
|
|
|
- // Goods索引
|
|
|
- if (GOODS_TABLE_NAME.equals(tableName)) {
|
|
|
- List<TradeGoods> goodses = jdbcTemplate.query(sql, new TradeGoods());
|
|
|
- data = (List<T>) goodses;
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 获取V_Products
|
|
|
+ * @param sql sql
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<T> queryVProducts(String sql) {
|
|
|
+ return (List<T>) jdbcTemplate.query(sql, new V_Products());
|
|
|
+ }
|
|
|
|
|
|
- return data;
|
|
|
+ /**
|
|
|
+ * 获取Goods
|
|
|
+ * @param sql sql
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<T> queryGoods(String sql) {
|
|
|
+ return jdbcTemplate.query(sql, new TradeGoods());
|
|
|
}
|
|
|
}
|