Browse Source

首页数据中心优化;订单查询优化

wanxl 1 year atrás
parent
commit
f7787ee261

+ 38 - 0
src/main/java/com/sqx/common/utils/DateUtils.java

@@ -1,5 +1,6 @@
 package com.sqx.common.utils;
 
+import com.sqx.modules.datacentre.query.DataCenterQuery;
 import org.apache.commons.lang.StringUtils;
 import org.joda.time.DateTime;
 import org.joda.time.LocalDate;
@@ -156,4 +157,41 @@ public class DateUtils {
         DateTime dateTime = new DateTime(date);
         return dateTime.plusYears(years).toDate();
     }
+    /**
+     * 获取str日期的当天/当月/当年的结束时间
+     *数据中心用
+     */
+    public static DataCenterQuery dateStrEndTime(DataCenterQuery query) {
+        if ("day".equals(query.getDateType())){
+            Date day= DateUtils.stringToDate(query.getDate().substring(0,10),"yyyy-MM-dd");
+            query.setStartTime(query.getDate().substring(0,10)+" 00:00:00");
+            query.setEndTime(format(addDateDays(day,1)));
+        }else if ("month".equals(query.getDateType())){
+            Date day= DateUtils.stringToDate(query.getDate().substring(0,7),"yyyy-MM");
+            query.setStartTime(query.getDate().substring(0,7)+"-01 00:00:00");
+            query.setEndTime(format(addDateMonths(day,1)));
+        }else if ("year".equals(query.getDateType())){
+            Date day= DateUtils.stringToDate(query.getDate().substring(0,4),"yyyy");
+            query.setStartTime(query.getDate().substring(0,4)+"-01-01 00:00:00");
+            query.setEndTime(format(addDateYears(day,1)));
+        }
+        return query;
+    }
+    /**
+     * 获取str日期的当天/当月/当年的结束时间
+     *数据中心用
+     */
+    public static String dateStrEndTime(String dateStr,String dateType) {
+        if ("day".equals(dateType)){
+            Date day= DateUtils.stringToDate(dateStr.substring(0,10),"yyyy-MM-dd");
+            return format(addDateDays(day,1));
+        }else if ("month".equals(dateType)){
+            Date day= DateUtils.stringToDate(dateStr.substring(0,7),"yyyy-MM");
+            return format(addDateMonths(day,1));
+        }else if ("year".equals(dateType)){
+            Date day= DateUtils.stringToDate(dateStr.substring(0,4),"yyyy");
+            return format(addDateYears(day,1));
+        }
+        return dateStr;
+    }
 }

+ 4 - 4
src/main/java/com/sqx/modules/datacentre/dao/DataCentreDao.java

@@ -29,13 +29,13 @@ public interface DataCentreDao {
 
     int findYearAddUser(String format);
 
-    BigDecimal findDayIncome(String format);
+    BigDecimal findDayIncome(String starTime,String endTime);
 
-    BigDecimal findMonthIncome(String format);
+//    BigDecimal findMonthIncome(String format);
 
-    BigDecimal findYearIncome(String format);
+//    BigDecimal findYearIncome(String format);
 
-    int findIndentCount(String format);
+    int findIndentCount(String starTime,String endTime);
 
     IPage<TbOrder> selectPayOrderAnalyze(Page<TbOrder> pages, @Param("query") DataCenterQuery query);
 

+ 13 - 6
src/main/java/com/sqx/modules/datacentre/service/impl/DataCentreServiceImpl.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.sqx.common.utils.DateUtils;
 import com.sqx.common.utils.PageUtils;
 import com.sqx.common.utils.Result;
 import com.sqx.modules.app.dao.UserDao;
@@ -80,13 +81,13 @@ public class DataCentreServiceImpl implements DataCentreService {
         //本年新增用户数
         int yearAddUser = dataCentreDao.findYearAddUser(format);
         //今日收入
-        BigDecimal dayIncome = dataCentreDao.findDayIncome(format);
+        BigDecimal dayIncome = dataCentreDao.findDayIncome(format.substring(0,10)+" 00:00:00",DateUtils.dateStrEndTime(format,"day"));
         //本月收入
-        BigDecimal monthIncome = dataCentreDao.findMonthIncome(format);
+        BigDecimal monthIncome = dataCentreDao.findDayIncome(format.substring(0,7)+"-01 00:00:00",DateUtils.dateStrEndTime(format,"month"));
         //本年收入
-        BigDecimal yearIncome = dataCentreDao.findYearIncome(format);
+        BigDecimal yearIncome = dataCentreDao.findDayIncome(format.substring(0,4)+"-01-01 00:00:00",DateUtils.dateStrEndTime(format,"year"));
         //今日接单数量
-        int indentCount = dataCentreDao.findIndentCount(format);
+        int indentCount = dataCentreDao.findIndentCount(format.substring(0,10)+" 00:00:00",DateUtils.dateStrEndTime(format,"day"));
         dataCenter.put("allCount", allCount);
         dataCenter.put("dayAddUser", dayAddUser);
         dataCenter.put("monthAddUser", monthAddUser);
@@ -101,7 +102,7 @@ public class DataCentreServiceImpl implements DataCentreService {
     @Override
     public Result selectPayOrderAnalyze(DataCenterQuery query) {
         Page<TbOrder> pages=new Page<>(query.getPage(),query.getLimit());
-        PageUtils pageUtils = new PageUtils(dataCentreDao.selectPayOrderAnalyze(pages, query));
+        PageUtils pageUtils = new PageUtils(dataCentreDao.selectPayOrderAnalyze(pages, DateUtils.dateStrEndTime(query)));
         return Result.success().put("data", pageUtils);
     }
 
@@ -136,7 +137,8 @@ public class DataCentreServiceImpl implements DataCentreService {
     }
 
     @Override
-    public Result selectOrderData(DataCenterQuery query) {
+    public Result selectOrderData(DataCenterQuery oldQuery) {
+        DataCenterQuery query=DateUtils.dateStrEndTime(oldQuery);
         HashMap hashMap = new HashMap();
         BigDecimal sumMoney = appOrderDao.selectSumMoney(query);
         int countOrder = appOrderDao.selectCountOrder(query);
@@ -241,6 +243,11 @@ public class DataCentreServiceImpl implements DataCentreService {
         int newShopCount = dataCentreDao.selectNewShopCount(query);
         //门店收益排行榜
         Page<TbOrder> pages=new Page<>(query.getPage(),query.getLimit());
+        //计算年月日开始结束时间
+        DataCenterQuery dataCenterQuery=query;
+        dataCenterQuery=DateUtils.dateStrEndTime(dataCenterQuery);
+        query.setStartTime(dataCenterQuery.getStartTime());
+        query.setEndTime(dataCenterQuery.getEndTime());
         IPage<TbOrder> tbOrderIPage = dataCentreDao.selectRankingList(pages, query);
         for(int i = 0;i<query.getLimit();i++){
             Integer a = ((query.getPage()-1)*query.getLimit())+i+1;

+ 17 - 0
src/main/java/com/sqx/modules/order/dto/OrderQueryDto.java

@@ -119,4 +119,21 @@ public class OrderQueryDto extends PageQuery {
             default: return state+"";
         }
     }
+
+    public void setStartTime(String startTime) {
+        this.startTime = startTime+" 00:00:00";
+    }
+
+    public void setEndTime(String endTime) {
+        this.endTime = endTime+" 24:00:00";
+    }
+
+
+    public void setPayStartTime(String payStartTime) {
+        this.payStartTime = payStartTime+" 00:00:00";
+    }
+
+    public void setPayEndTime(String payEndTime) {
+        this.payEndTime = payEndTime+" 24:00:00";
+    }
 }

+ 3 - 0
src/main/java/com/sqx/modules/order/service/impl/AppAppOrderServiceImpl.java

@@ -1357,6 +1357,9 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
     @Override
     public Result selectAllOrderAdmin(OrderQueryDto queryDto) {
         Page<TbOrder> pages = new Page<>(queryDto.getPage(), queryDto.getLimit());
+//        pages.setOptimizeCountSql(false);
+//        pages.setSearchCount(false);
+//        pages.setTotal()
         IPage<TbOrder> tbOrderIPage = appOrderDao.selectAllOrderAdmin(pages, queryDto);
         for (int i = 0; i < tbOrderIPage.getRecords().size(); i++) {
             List<OrderGoods> orderGoodsList = orderGoodsDao.selectList(new QueryWrapper<OrderGoods>()

+ 6 - 71
src/main/resources/mapper/dataCentre/dataCenterMapper.xml

@@ -29,33 +29,22 @@
         where status = 1
           and date_format(create_time, '%Y') = date_format(#{date}, '%Y')
     </select>
-    <!--今日收入-->
+    <!--时间范围内收入-->
     <select id="findDayIncome" resultType="java.math.BigDecimal">
         select ifnull(sum(pay_money), 0)
         from tb_order
         where status in (3, 4)
-          and date_format(pay_time, '%Y-%m-%d') = date_format(#{date}, '%Y-%m-%d')
-    </select>
-    <!--本月收入-->
-    <select id="findMonthIncome" resultType="java.math.BigDecimal">
-        select ifnull(sum(pay_money), 0)
-        from tb_order
-        where status in (3, 4)
-          and date_format(pay_time, '%Y-%m') = date_format(#{date}, '%Y-%m')
-    </select>
-    <!--本年收入-->
-    <select id="findYearIncome" resultType="java.math.BigDecimal">
-        select ifnull(sum(pay_money), 0)
-        from tb_order
-        where status in (3, 4)
-          and date_format(pay_time, '%Y') = date_format(#{date}, '%Y')
+          and pay_time >= #{starTime}
+          and pay_time <![CDATA[<=]]> #{endTime}
     </select>
+
     <!--今日发单数量-->
     <select id="findIndentCount" resultType="int">
         select count(*)
         from tb_order
         where status in (3, 4)
-          and date_format(pay_time, '%Y-%m-%d') = date_format(#{date}, '%Y-%m-%d')
+          and pay_time >= #{starTime}
+          and pay_time <![CDATA[<=]]> #{endTime}
     </select>
 
     <select id="selectPayOrderAnalyze" resultType="com.sqx.modules.order.entity.TbOrder">
@@ -270,15 +259,6 @@
         <if test="query.shopType != null and query.shopType != '' ">
             and gp.id = #{query.shopType}
         </if>
-        <if test="query.dateType=='day'">
-            and date_format(tor.pay_time,'%Y-%m-%d')=date_format(#{query.date},'%Y-%m-%d')
-        </if>
-        <if test="query.dateType=='month'">
-            and date_format(tor.pay_time,'%Y-%m')=date_format(#{query.date},'%Y-%m')
-        </if>
-        <if test="query.dateType=='year'">
-            and date_format(tor.pay_time,'%Y')=date_format(#{query.date},'%Y')
-        </if>
         GROUP BY tor.shop_id ) a
         ORDER BY shopMoney DESC
     </select>
@@ -297,15 +277,6 @@
         <if test="query.shopType != null and query.shopType != '' ">
             and gp.id = #{query.shopType}
         </if>
-        <if test="query.dateType=='day'">
-            and date_format(tor.pay_time,'%Y-%m-%d')=date_format(#{query.date},'%Y-%m-%d')
-        </if>
-        <if test="query.dateType=='month'">
-            and date_format(tor.pay_time,'%Y-%m')=date_format(#{query.date},'%Y-%m')
-        </if>
-        <if test="query.dateType=='year'">
-            and date_format(tor.pay_time,'%Y')=date_format(#{query.date},'%Y')
-        </if>
     </select>
 
     <select id="excelShopCenter" resultType="com.sqx.modules.order.entity.TbOrder">
@@ -516,15 +487,6 @@
         <if test="query.shopId!=null">
             and shop_id = #{query.shopId}
         </if>
-        <if test="query.dateType=='day'">
-            and date_format(pay_time,'%Y-%m-%d')=date_format(#{query.date},'%Y-%m-%d')
-        </if>
-        <if test="query.dateType=='month'">
-            and date_format(pay_time,'%Y-%m')=date_format(#{query.date},'%Y-%m')
-        </if>
-        <if test="query.dateType=='year'">
-            and date_format(pay_time,'%Y')=date_format(#{query.date},'%Y')
-        </if>
         <if test="query.startTime!=null and query.startTime!=''">
             and pay_time>=#{query.startTime}
         </if>
@@ -540,15 +502,6 @@
         <if test="query.shopId!=null">
             and shop_id = #{query.shopId}
         </if>
-        <if test="query.dateType=='day'">
-            and date_format(pay_time,'%Y-%m-%d')=date_format(#{query.date},'%Y-%m-%d')
-        </if>
-        <if test="query.dateType=='month'">
-            and date_format(pay_time,'%Y-%m')=date_format(#{query.date},'%Y-%m')
-        </if>
-        <if test="query.dateType=='year'">
-            and date_format(pay_time,'%Y')=date_format(#{query.date},'%Y')
-        </if>
         <if test="query.startTime!=null and query.startTime!=''">
             and pay_time>=#{query.startTime}
         </if>
@@ -562,15 +515,6 @@
         <if test="query.shopId!=null">
             and shop_id = #{query.shopId}
         </if>
-        <if test="query.dateType=='day'">
-            and date_format(create_time,'%Y-%m-%d')=date_format(#{query.date},'%Y-%m-%d')
-        </if>
-        <if test="query.dateType=='month'">
-            and date_format(create_time,'%Y-%m')=date_format(#{query.date},'%Y-%m')
-        </if>
-        <if test="query.dateType=='year'">
-            and date_format(create_time,'%Y')=date_format(#{query.date},'%Y')
-        </if>
         <if test="query.startTime!=null and query.startTime!=''">
             and create_time>=#{query.startTime}
         </if>
@@ -584,15 +528,6 @@
         <if test="query.shopId!=null">
             and shop_id = #{query.shopId}
         </if>
-        <if test="query.dateType=='day'">
-            and date_format(create_time,'%Y-%m-%d')=date_format(#{query.date},'%Y-%m-%d')
-        </if>
-        <if test="query.dateType=='month'">
-            and date_format(create_time,'%Y-%m')=date_format(#{query.date},'%Y-%m')
-        </if>
-        <if test="query.dateType=='year'">
-            and date_format(create_time,'%Y')=date_format(#{query.date},'%Y')
-        </if>
         <if test="query.startTime!=null and query.startTime!=''">
             and create_time>=#{query.startTime}
         </if>

+ 16 - 34
src/main/resources/mapper/order/OrderMapper.xml

@@ -140,16 +140,16 @@
             and tor.reservation_flag = #{query.reservationFlag}
         </if>
         <if test="query.startTime!=null and query.startTime!=''">
-            and date_format(tor.create_time,'%Y-%m-%d') >= date_format(#{query.startTime},'%Y-%m-%d')
+            and tor.create_time >= #{query.startTime}
         </if>
         <if test="query.endTime!=null and query.endTime!='' ">
-            and date_format(tor.create_time,'%Y-%m-%d') &lt;= date_format(#{query.endTime},'%Y-%m-%d')
+            and tor.create_time &lt;= #{query.endTime}
         </if>
         <if test="query.payStartTime != null and query.payStartTime != ''">
-            and date_format(tor.pay_time,'%Y-%m-%d') >= date_format(#{query.payStartTime},'%Y-%m-%d')
+            and tor.pay_time >= #{query.payStartTime}
         </if>
         <if test="query.payEndTime != null and query.payEndTime != '' ">
-            and date_format(tor.pay_time,'%Y-%m-%d') &lt;= date_format(#{query.payEndTime},'%Y-%m-%d')
+            and tor.pay_time &lt;= #{query.payEndTime}
         </if>
         <if test="query.riderStationId!=null and query.riderStationId!=''">
             and tiu.rider_station_id=#{query.riderStationId}
@@ -224,16 +224,16 @@
             and tor.reservation_flag = #{query.reservationFlag}
         </if>
         <if test="query.startTime!=null and query.startTime!=''">
-            and date_format(tor.create_time,'%Y-%m-%d') >= date_format(#{query.startTime},'%Y-%m-%d')
+            and tor.create_time >= #{query.startTime}
         </if>
         <if test="query.endTime!=null and query.endTime!='' ">
-            and date_format(tor.create_time,'%Y-%m-%d') &lt;= date_format(#{query.endTime},'%Y-%m-%d')
+            and tor.create_time &lt;= #{query.endTime}
         </if>
         <if test="query.payStartTime != null and query.payStartTime != ''">
-            and date_format(tor.pay_time,'%Y-%m-%d') >= date_format(#{query.payStartTime},'%Y-%m-%d')
+            and tor.pay_time >= #{query.payStartTime}
         </if>
         <if test="query.payEndTime != null and query.payEndTime != '' ">
-            and date_format(tor.pay_time,'%Y-%m-%d') &lt;= date_format(#{query.payEndTime},'%Y-%m-%d')
+            and tor.pay_time &lt;= #{query.payEndTime}
         </if>
         <if test="query.riderStationId!=null and query.riderStationId!=''">
             and tiu.rider_station_id=#{query.riderStationId}
@@ -292,16 +292,16 @@
             and tor.reservation_flag = #{query.reservationFlag}
         </if>
         <if test="query.startTime!=null and query.startTime!=''">
-            and date_format(tor.create_time,'%Y-%m-%d') >= date_format(#{query.startTime},'%Y-%m-%d')
+            and tor.create_time >= #{query.startTime}
         </if>
         <if test="query.endTime!=null and query.endTime!='' ">
-            and date_format(tor.create_time,'%Y-%m-%d') &lt;= date_format(#{query.endTime},'%Y-%m-%d')
+            and tor.create_time &lt;= #{query.endTime}
         </if>
         <if test="query.payStartTime != null and query.payStartTime != ''">
-            and date_format(tor.pay_time,'%Y-%m-%d') >= date_format(#{query.payStartTime},'%Y-%m-%d')
+            and tor.pay_time >= #{query.payStartTime}
         </if>
         <if test="query.payEndTime != null and query.payEndTime != '' ">
-            and date_format(tor.pay_time,'%Y-%m-%d') &lt;= date_format(#{query.payEndTime},'%Y-%m-%d')
+            and tor.pay_time &lt;= #{query.payEndTime}
         </if>
         <if test="query.riderStationId!=null and query.riderStationId!=''">
             and tiu.rider_station_id=#{query.riderStationId}
@@ -433,15 +433,6 @@
         <if test="query.shopId!=null">
             and shop_id=#{query.shopId}
         </if>
-        <if test="query.dateType=='day'">
-            and date_format(pay_time,'%Y-%m-%d')=date_format(#{query.date},'%Y-%m-%d')
-        </if>
-        <if test="query.dateType=='month'">
-            and date_format(pay_time,'%Y-%m')=date_format(#{query.date},'%Y-%m')
-        </if>
-        <if test="query.dateType=='year'">
-            and date_format(pay_time,'%Y')=date_format(#{query.date},'%Y')
-        </if>
         <if test="query.startTime!=null and query.startTime!=''">
             and pay_time>=#{query.startTime}
         </if>
@@ -455,15 +446,6 @@
         <if test="query.shopId!=null">
             and shop_id=#{query.shopId}
         </if>
-        <if test="query.dateType=='day'">
-            and date_format(pay_time,'%Y-%m-%d')=date_format(#{query.date},'%Y-%m-%d')
-        </if>
-        <if test="query.dateType=='month'">
-            and date_format(pay_time,'%Y-%m')=date_format(#{query.date},'%Y-%m')
-        </if>
-        <if test="query.dateType=='year'">
-            and date_format(pay_time,'%Y')=date_format(#{query.date},'%Y')
-        </if>
         <if test="query.startTime!=null and query.startTime!=''">
             and pay_time>=#{query.startTime}
         </if>
@@ -667,16 +649,16 @@
             and tor.reservation_flag = #{query.reservationFlag}
         </if>
         <if test="query.startTime!=null and query.startTime!=''">
-            and date_format(tor.create_time,'%Y-%m-%d') >= date_format(#{query.startTime},'%Y-%m-%d')
+            and tor.create_time >= #{query.startTime}
         </if>
         <if test="query.endTime!=null and query.endTime!='' ">
-            and date_format(tor.create_time,'%Y-%m-%d') &lt;= date_format(#{query.endTime},'%Y-%m-%d')
+            and tor.create_time &lt;= #{query.endTime}
         </if>
         <if test="query.payStartTime != null and query.payStartTime != ''">
-            and date_format(tor.pay_time,'%Y-%m-%d') >= date_format(#{query.payStartTime},'%Y-%m-%d')
+            and tor.pay_time >= #{query.payStartTime}
         </if>
         <if test="query.payEndTime != null and query.payEndTime != '' ">
-            and date_format(tor.pay_time,'%Y-%m-%d') &lt;= date_format(#{query.payEndTime},'%Y-%m-%d')
+            and tor.pay_time &lt;= #{query.payEndTime}
         </if>
         <if test="query.riderStationId!=null and query.riderStationId!=''">
             and tiu.rider_station_id=#{query.riderStationId}