Просмотр исходного кода

品类产品查找增加时间过滤

hejq 7 лет назад
Родитель
Сommit
7392fdfab3

+ 35 - 11
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/GoodsServiceImpl.java

@@ -4062,12 +4062,41 @@ public class GoodsServiceImpl implements GoodsService {
      */
     @Override
     public com.uas.sso.support.Page<BrandCount> getBrandProductsCount(Pageable pageable, Date startTime, Date endTime) {
+        java.sql.Date startDate = assignStartDate(startTime);
+        java.sql.Date endDate = assignEndDate(endTime);
+        StringBuffer sql = new StringBuffer("select br_name_en as brand, count(1) as count from trade$goods where br_name_en is not null and go_update_date >= ? and go_update_date < ? group by br_name_en");
+        StringBuffer countSql = new StringBuffer("select count(1) from (").append(sql).append(") as a");
+        Integer count = commonDao.queryForObject(countSql.toString(), Integer.class, startDate, endDate);
+        // 分页参数
+        Integer offset = (pageable.getPageNumber() - 1) * pageable.getPageSize();
+        sql.append(" limit ? offset ?");
+        List<BrandCount> brandCountList = commonDao.query(sql.toString(), BrandCount.class, startDate, endDate, pageable.getPageSize(), offset);
+        return new com.uas.sso.support.Page<>(pageable.getPageNumber(), pageable.getPageSize(), brandCountList, count);
+    }
+
+    /**
+     * 设置开始时间
+     *
+     * @param startTime 前端传入开始时间
+     * @return java.sql.Date
+     */
+    private java.sql.Date assignStartDate(Date startTime) {
         java.sql.Date startDate;
         if (null == startTime) {
             startDate = new java.sql.Date(DateUtils.addTime(new Date(), -30, 0, 0, 0).getTime());
         } else {
             startDate = new java.sql.Date(startTime.getTime());
         }
+       return startDate;
+    }
+
+    /**
+     * 设置截止时间
+     *
+     * @param endTime 前端传入截止时间
+     * @return java.sql.Date
+     */
+    private java.sql.Date assignEndDate(Date endTime) {
         java.sql.Date endDate;
         // 截止时间+1天
         if (null == endTime) {
@@ -4077,14 +4106,7 @@ public class GoodsServiceImpl implements GoodsService {
         }
         Integer addend = 60 * 60 * 24 * 1000;
         endDate = new java.sql.Date(endDate.getTime() + addend);
-        StringBuffer sql = new StringBuffer("select br_name_en as brand, count(1) as count from trade$goods where br_name_en is not null and go_update_date >= ? and go_update_date < ? group by br_name_en");
-        StringBuffer countSql = new StringBuffer("select count(1) from (").append(sql).append(") as a");
-        Integer count = commonDao.queryForObject(countSql.toString(), Integer.class, startDate, endDate);
-        // 分页参数
-        Integer offset = (pageable.getPageNumber() - 1) * pageable.getPageSize();
-        sql.append(" limit ? offset ?");
-        List<BrandCount> brandCountList = commonDao.query(sql.toString(), BrandCount.class, startDate, endDate, pageable.getPageSize(), offset);
-        return new com.uas.sso.support.Page<>(pageable.getPageNumber(), pageable.getPageSize(), brandCountList, count);
+        return endDate;
     }
 
     /**
@@ -4097,13 +4119,15 @@ public class GoodsServiceImpl implements GoodsService {
      */
     @Override
     public com.uas.sso.support.Page<KindHierarchicalCount> getKindProductsCount(Pageable pageable, Date startTime, Date endTime) {
-        StringBuffer sql = new StringBuffer("select ki_name as thirdKind, go_kind_uuid as kindId, count(1) as count from trade$goods group by ki_name, go_kind_uuid");
+        java.sql.Date startDate = assignStartDate(startTime);
+        java.sql.Date endDate = assignEndDate(endTime);
+        StringBuffer sql = new StringBuffer("select ki_name as thirdKind, go_kind_uuid as kindId, count(1) as count from trade$goods where go_update_date between ? and ? group by ki_name, go_kind_uuid");
         StringBuffer countSql = new StringBuffer("select count(1) from (").append(sql).append(") as a");
-        Integer count = commonDao.queryForObject(countSql.toString(), Integer.class);
+        Integer count = commonDao.queryForObject(countSql.toString(), Integer.class, startDate, endDate);
         // 分页参数
         Integer offset = (pageable.getPageNumber() - 1) * pageable.getPageSize();
         sql.append(" limit ? offset ?");
-        List<KindHierarchicalCount> kindList = commonDao.query(sql.toString(), KindHierarchicalCount.class, pageable.getPageSize(), offset);
+        List<KindHierarchicalCount> kindList = commonDao.query(sql.toString(), KindHierarchicalCount.class, startDate, endDate, pageable.getPageSize(), offset);
         if (CollectionUtils.isNotEmpty(kindList)) {
             kindList.forEach(kind -> {
                 if (null != kind.getKindId()) {