|
|
@@ -1,12 +1,23 @@
|
|
|
package cc.iotkit.data.service;
|
|
|
|
|
|
+import cc.iotkit.common.api.PageRequest;
|
|
|
import cc.iotkit.common.api.Paging;
|
|
|
import cc.iotkit.common.utils.MapstructUtils;
|
|
|
+import cc.iotkit.common.utils.StringUtils;
|
|
|
import cc.iotkit.data.dao.IJPACommData;
|
|
|
import cc.iotkit.data.dao.ProductRepository;
|
|
|
import cc.iotkit.data.manager.IProductData;
|
|
|
+import cc.iotkit.data.model.TbDeviceInfo;
|
|
|
import cc.iotkit.data.model.TbProduct;
|
|
|
+import cc.iotkit.data.model.TbSysConfig;
|
|
|
+import cc.iotkit.data.util.PageBuilder;
|
|
|
+import cc.iotkit.data.util.PredicateBuilder;
|
|
|
+import cc.iotkit.model.device.DeviceInfo;
|
|
|
import cc.iotkit.model.product.Product;
|
|
|
+import cc.iotkit.model.system.SysConfig;
|
|
|
+import com.querydsl.core.QueryResults;
|
|
|
+import com.querydsl.core.types.Predicate;
|
|
|
+import com.querydsl.jpa.impl.JPAQuery;
|
|
|
import com.querydsl.jpa.impl.JPAQueryFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Primary;
|
|
|
@@ -15,9 +26,13 @@ import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.data.jpa.repository.JpaRepository;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import static cc.iotkit.data.model.QTbDeviceInfo.tbDeviceInfo;
|
|
|
+import static cc.iotkit.data.model.QTbDeviceSubUser.tbDeviceSubUser;
|
|
|
import static cc.iotkit.data.model.QTbProduct.tbProduct;
|
|
|
+import static cc.iotkit.data.model.QTbSysConfig.tbSysConfig;
|
|
|
|
|
|
@Primary
|
|
|
@Service
|
|
|
@@ -79,4 +94,46 @@ public class ProductDataImpl implements IProductData, IJPACommData<Product, Long
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Paging<Product> findAllByConditions(PageRequest<Product> pageRequest) {
|
|
|
+ Product data = pageRequest.getData();
|
|
|
+ Predicate predicate = buildPredicate(data);
|
|
|
+ QueryResults<TbProduct> tbSysConfigQueryResults = jpaQueryFactory.select(tbProduct).from(tbProduct).where(predicate).limit(pageRequest.getPageSize()).offset(pageRequest.getOffset()).fetchResults();
|
|
|
+ return PageBuilder.queryResults2Page(tbSysConfigQueryResults, SysConfig.class);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private Predicate buildPredicate(Product data) {
|
|
|
+ return PredicateBuilder.instance()
|
|
|
+ .and(StringUtils.isNotEmpty(data.getProductKey()), () -> tbProduct.productKey.eq(data.getProductKey()))
|
|
|
+ .and(StringUtils.isNotEmpty(data.getName()), () -> tbProduct.name.like(data.getName()))
|
|
|
+// .and(StringUtils.isNotEmpty(data.getTenantId()), () -> tbSysConfig.tenantId.eq(data.getTenantId()))
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Paging<Product> findByConditions(String uid, String subUid, String productKey, String name, Integer page, Integer size) {
|
|
|
+ JPAQuery<TbProduct> query = jpaQueryFactory.selectFrom(tbProduct);
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isNotBlank(uid)) {
|
|
|
+ query.where(tbProduct.uid.eq(uid));
|
|
|
+ }
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isNotBlank(productKey)) {
|
|
|
+ query.where(tbProduct.productKey.eq(productKey));
|
|
|
+ }
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isNotBlank(name)) {
|
|
|
+ query.where(tbProduct.name.like("%" + name + "%"));
|
|
|
+ }
|
|
|
+ query.orderBy(tbDeviceInfo.createAt.desc());
|
|
|
+ query.offset((page - 1) * size).limit(size);
|
|
|
+
|
|
|
+ List<TbProduct> tbProducts = query.fetch();
|
|
|
+ long total = query.fetchCount();
|
|
|
+ List<Product> products = new ArrayList<>(tbProducts.size());
|
|
|
+ for (TbProduct tbProduct : tbProducts) {
|
|
|
+ Product product = MapstructUtils.convert(tbProduct, Product.class);
|
|
|
+ products.add(product);
|
|
|
+ }
|
|
|
+ return new Paging<>(total, products);
|
|
|
+ }
|
|
|
}
|