瀏覽代碼

修复admin/goodsShop/selectStoreData、admin/goodsShop/selectStoreMessage接口没有按照date查询数据bug

codingliang 1 年之前
父節點
當前提交
0f059f71a4

+ 18 - 12
src/main/java/com/sqx/common/utils/DateUtils.java

@@ -1,5 +1,6 @@
 package com.sqx.common.utils;
 
+import cn.hutool.core.util.StrUtil;
 import com.sqx.modules.datacentre.query.DataCenterQuery;
 import org.apache.commons.lang.StringUtils;
 import org.joda.time.DateTime;
@@ -8,6 +9,7 @@ import org.joda.time.format.DateTimeFormat;
 import org.joda.time.format.DateTimeFormatter;
 
 import java.text.SimpleDateFormat;
+import java.time.temporal.TemporalAdjusters;
 import java.util.Date;
 
 /**
@@ -174,18 +176,22 @@ public class DateUtils {
      *数据中心用
      */
     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)));
+        if (StrUtil.isNotBlank(query.getDate())) {
+            java.time.LocalDate queryDate = java.time.LocalDate.parse(query.getDate());
+            if (StrUtil.equals("year", query.getDateType())) {
+                java.time.LocalDate firstDayOfYear = queryDate.with(TemporalAdjusters.firstDayOfYear());
+                java.time.LocalDate endDayOfYear = firstDayOfYear.plusYears(1).minusDays(1);
+                query.setStartTime(firstDayOfYear + " 00:00:00");
+                query.setEndTime(endDayOfYear + " 23:59:59");
+            } else if (StrUtil.equals("month", query.getDateType())) {
+                java.time.LocalDate firstDayOfMonth = queryDate.with(TemporalAdjusters.firstDayOfMonth());
+                java.time.LocalDate endDayOfMonth = firstDayOfMonth.plusMonths(1).minusDays(1);
+                query.setStartTime(firstDayOfMonth + " 00:00:00");
+                query.setEndTime(endDayOfMonth + " 23:59:59");
+            } else if (StrUtil.equals("day", query.getDateType())) {
+                query.setStartTime(queryDate + " 00:00:00");
+                query.setEndTime(queryDate + " 23:59:59");
+            }
         }
         return query;
     }

+ 1 - 1
src/main/java/com/sqx/modules/datacentre/query/DataCenterQuery.java

@@ -16,7 +16,7 @@ public class DataCenterQuery extends PageQuery {
     @ApiModelProperty(value = "日期")
     private String date;
 
-    @ApiModelProperty(value = "类型")
+    @ApiModelProperty(value = "类型,day、month、year")
     private String dateType;
 
     @ApiModelProperty(value = "商铺id")

+ 2 - 2
src/main/java/com/sqx/modules/goods/controller/GoodsShopController.java

@@ -104,9 +104,9 @@ public class GoodsShopController {
 
     @ApiOperation("统计门店订单详情")
     @GetMapping(value = "selectStoreMessage")
-    public Result selectStoreMessage(Long shopId, String startTime, String endTime, Integer page, Integer limit, String orderNumber){
+    public Result selectStoreMessage(DataCenterQuery query){
 
-        return goodsShopService.selectStoreMessage(shopId, startTime, endTime, page, limit, orderNumber);
+        return goodsShopService.selectStoreMessage(query);
     }
 
     @ApiOperation("商户快捷入驻")

+ 1 - 1
src/main/java/com/sqx/modules/goods/dao/GoodsShopDao.java

@@ -41,7 +41,7 @@ public interface GoodsShopDao extends BaseMapper<GoodsShop> {
 
     BigDecimal selectStoreMoney(@Param("shopId") Long shopId,@Param("startTime") String startTime,@Param("endTime") String endTime);
 
-    IPage<TbOrder> selectStoreMessage(Page<TbOrder> pages, Long shopId, String startTime, String endTime, String orderNumber);
+    IPage<TbOrder> selectStoreMessage(@Param("pages") Page<TbOrder> pages, @Param("shopId") Long shopId, @Param("startTime") String startTime, @Param("endTime") String endTime);
 
     IPage<GoodsShop> selectSearch(Page<GoodsShop> pages, String impotr, Double lng, Double lat, String city);
 

+ 1 - 1
src/main/java/com/sqx/modules/goods/service/GoodsShopService.java

@@ -31,7 +31,7 @@ public interface GoodsShopService extends IService<GoodsShop> {
 
     Result selectStoreData(DataCenterQuery query);
 
-    Result selectStoreMessage(Long shopId, String startTime, String endTime, Integer page, Integer limit, String orderNumber);
+    Result selectStoreMessage(DataCenterQuery query);
 
     Result quickGoodsShop(GoodsShopVo goodsShopVo);
 

+ 23 - 8
src/main/java/com/sqx/modules/goods/service/impl/GoodsShopServiceImpl.java

@@ -1,6 +1,5 @@
 package com.sqx.modules.goods.service.impl;
 
-import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -10,6 +9,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.sqx.common.utils.DateUtils;
 import com.sqx.common.utils.PageUtils;
 import com.sqx.common.utils.Result;
 import com.sqx.modules.app.dao.MsgDao;
@@ -56,6 +56,8 @@ import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.temporal.TemporalAdjusters;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
@@ -365,12 +367,24 @@ public class GoodsShopServiceImpl extends ServiceImpl<GoodsShopDao, GoodsShop> i
         return Result.success();
     }
 
+    public static void main(String[] args) {
+        String date = "2025-04-02";
+        LocalDate queryDate = LocalDate.parse(date);
+        System.out.println(queryDate);
+        LocalDate firstDayOfYear = queryDate.with(TemporalAdjusters.firstDayOfYear());
+        LocalDate endDayOfYear = firstDayOfYear.plusYears(1).minusDays(1);
+        System.out.println(firstDayOfYear + " 00:00:00");
+        System.out.println(endDayOfYear + " 23:59:59");
+
+        LocalDate firstDayOfMonth = queryDate.with(TemporalAdjusters.firstDayOfMonth());
+        LocalDate endDayOfMonth = firstDayOfMonth.plusMonths(1).minusDays(1);
+        System.out.println(firstDayOfMonth + " 00:00:00");
+        System.out.println(endDayOfMonth + " 23:59:59");
+    }
+
     @Override
     public Result selectStoreData(DataCenterQuery query) {
-        if (StrUtil.isNotBlank(query.getDate())) {
-            query.setStartTime(query.getStartTime() + " 00:00:00");
-            query.setEndTime(query.getEndTime() + " 23:59:59");
-        }
+        query = DateUtils.dateStrEndTime(query);
 
         //外卖订单数
         int takeCount2 = dataCentreDao.selectTakeCount(2,query);
@@ -402,9 +416,10 @@ public class GoodsShopServiceImpl extends ServiceImpl<GoodsShopDao, GoodsShop> i
     }
 
     @Override
-    public Result selectStoreMessage(Long shopId, String startTime, String endTime, Integer page, Integer limit, String orderNumber) {
-        Page<TbOrder> pages = new Page<>(page, limit);
-        IPage<TbOrder> tbOrderIPage = goodsShopDao.selectStoreMessage(pages, shopId, startTime, endTime, orderNumber);
+    public Result selectStoreMessage(DataCenterQuery query) {
+        query = DateUtils.dateStrEndTime(query);
+        Page<TbOrder> pages = new Page<>(query.getPage(), query.getLimit());
+        IPage<TbOrder> tbOrderIPage = goodsShopDao.selectStoreMessage(pages, query.getShopId(), query.getStartTime(), query.getEndTime());
         List<TbOrder> records = tbOrderIPage.getRecords();
         for(int i = 0;i<records.size();i++){
             List<OrderGoods> orderGoodsList = orderGoodsDao.selectList(new QueryWrapper<OrderGoods>()

+ 15 - 12
src/main/resources/mapper/goods/GoodsShopMapper.xml

@@ -184,18 +184,21 @@
     </select>
 
     <select id="selectStoreMessage" resultType="com.sqx.modules.order.entity.TbOrder">
-        select tor.*, gs.shop_name as shopName from tb_order tor left join goods_shop gs on tor.shop_id = gs.shop_id
-        where 1 = 1 and tor.status = 4
-        <if test="shopId!=null">
-            and tor.shop_id = #{shopId}
-        </if>
-        <if test="orderNumber!=null and orderNumber!=''">
-            and tor.order_number = #{orderNumber}
-        </if>
-        <if test="(endTime!=null and endTime!='') or (startTime!=null and startTime!='')">
-            and date_format(tor.pay_time,'%Y-%m-%d') &gt;= date_format(#{startTime},'%Y-%m-%d')
-            and date_format(tor.pay_time,'%Y-%m-%d') &lt;= date_format(#{endTime},'%Y-%m-%d')
-        </if>
+        select
+            tor.*,
+            gs.shop_name as shopName
+        from
+            tb_order tor
+            left join goods_shop gs on tor.shop_id = gs.shop_id
+        where
+            tor.status = 4
+            <if test="shopId != null">
+                and tor.shop_id = #{shopId}
+            </if>
+            <if test="(endTime != null and endTime != '') and (startTime != null and startTime != '')">
+                and date_format(tor.pay_time, '%Y-%m-%d') &gt;= date_format(#{startTime}, '%Y-%m-%d')
+                and date_format(tor.pay_time, '%Y-%m-%d') &lt;= date_format(#{endTime}, '%Y-%m-%d')
+            </if>
         order by tor.pay_time desc
     </select>