|
@@ -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));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|