王先生 2 gadi atpakaļ
vecāks
revīzija
ebf075a803

+ 5 - 1
eladmin-system/src/main/java/me/zhengjie/modules/dm/statement/repository/DmHaveDinnerRepository.java

@@ -295,6 +295,11 @@ public interface DmHaveDinnerRepository extends JpaRepository<DmHaveDinner,Integ
     @Query(nativeQuery = true,value = "create view `DAY_DINING_STATEMENTS_TOP` as SELECT item.pid,item.name,COUNT(item.pid) as countPid,sum(item.price) as price,rec.create_date,item.seq FROM dm_order_record rec LEFT JOIN  dm_order_item item on rec.seq = item.seq WHERE item.pid is not NULL and rec.create_date BETWEEN ?1  AND ?2  GROUP BY item.pid ORDER BY countPid desc LIMIT 0,3 ")
     void createDayDiningStatementsTopThreeView(@Param("startTime") String startTime,@Param("nowTime") String nowTime,@Param("viewName") String viewName);
 
+    @Query(nativeQuery = true, value = "SELECT item.pid,item.name,COUNT(item.pid) as countPid,sum(item.price) as price,rec.create_date,item.seq FROM dm_order_record rec LEFT JOIN  dm_order_item item on rec.seq = item.seq WHERE item.pid is not NULL and rec.create_date BETWEEN ?1  AND ?2  GROUP BY item.pid ORDER BY countPid desc LIMIT 0,3")
+    Page<List<Map<String,Object>>> selectTop(String startTime, String nowTime,Pageable pageable);
+
+    @Query(nativeQuery = true, value = "SELECT item.pid,item.name,COUNT(item.pid) as countPid,sum(item.price) as price,rec.create_date,item.seq FROM dm_order_record rec LEFT JOIN  dm_order_item item on rec.seq = item.seq WHERE item.pid is not NULL and rec.create_date BETWEEN ?1  AND ?2  GROUP BY item.pid ORDER BY countPid ASC LIMIT 0,3")
+    Page<List<Map<String,Object>>> selectStop(String startTime, String nowTime,Pageable pageable);
     /**
      * 创建后三日视图
      * @param startTime //开始时间
@@ -428,7 +433,6 @@ public interface DmHaveDinnerRepository extends JpaRepository<DmHaveDinner,Integ
      * 查询后三 月报
      * @param startTime
      * @param nowTime
-     * @param monthsInYear
      * @param pageable
      * @return
      */

+ 83 - 10
eladmin-system/src/main/java/me/zhengjie/modules/dm/statement/service/impl/DmHaveDinnerServiceImpl.java

@@ -11,6 +11,7 @@ import me.zhengjie.modules.dm.statement.service.dto.DmStatementDto;
 import me.zhengjie.modules.dm.statement.service.mapstruct.DmHaveDinnerMapper;
 import me.zhengjie.utils.FileUtil;
 import me.zhengjie.utils.PageUtil;
+import me.zhengjie.utils.StringUtils;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Service;
@@ -34,34 +35,106 @@ public class DmHaveDinnerServiceImpl implements DmHaveDinnerService {
 
     @Override
     public JSONObject selectDiningStatements(String stateDate, String endDate, String type, Pageable pageable) {
+
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+
+        SimpleDateFormat month = new SimpleDateFormat("yyyy-MM");
+
+        SimpleDateFormat year = new SimpleDateFormat("yyyy");
+
+        Boolean flag = false;
+
+        if (!StringUtils.isEmpty(stateDate) || !StringUtils.isEmpty(endDate)){
+            flag = true;
+        }
+
        // 前三
         Page<List<Map<String, Object>>> top = null;
        // 后三
         Page<List<Map<String, Object>>> stop = null;
         // 默认按月来
         if (type == null){
-            top = dmHaveDinnerRepository.selectMonthTopView(stateDate,endDate,pageable);
-            stop = dmHaveDinnerRepository.selectMonthStopView(stateDate, endDate, pageable);
+           type = "month";
         }
         //按日报来
         if (type.equals("day")){
-            top = dmHaveDinnerRepository.selectDayTopView(stateDate,endDate,pageable);
-            stop = dmHaveDinnerRepository.selectDayStopView(stateDate, endDate, pageable);
+            Calendar instance = Calendar.getInstance();
+            //当前时间
+            String nowTime = simpleDateFormat.format(instance.getTime()) + " 23:59:59";
+            String StartTime = simpleDateFormat.format(instance.getTime()) + " 00:00:00";
+            if (flag){
+                top = dmHaveDinnerRepository.selectTop(stateDate,endDate,null);
+                stop = dmHaveDinnerRepository.selectStop(stateDate, endDate,null);
+            }else {
+                top = dmHaveDinnerRepository.selectTop(StartTime,nowTime,null);
+                stop = dmHaveDinnerRepository.selectStop(StartTime, nowTime,null);
+            }
+
         }
         // 按周报来
         if (type.equals("week")){
-            top = dmHaveDinnerRepository.selectWeekTopView(stateDate,endDate,pageable);
-            stop = dmHaveDinnerRepository.selectWeekStopView(stateDate, endDate, pageable);
+            Calendar instance = Calendar.getInstance();
+            //判断当前时间在当前星期中事星期几  由于日历类中星期一是从周日算的
+            int i = instance.get(Calendar.DAY_OF_WEEK)-1;
+
+            //当前时间
+            String nowTime = "";
+            //开始时间
+            String startTime = "";
+
+            if (i==0){
+                instance.add(Calendar.DATE, 1-i);
+                startTime = simpleDateFormat.format(instance.getTime()) + " 00:00:00";
+                instance.add(Calendar.DATE, 7-1);
+                nowTime = simpleDateFormat.format(instance.getTime()) + " 23:59:59";
+            }else {
+                instance.add(Calendar.DATE,1-i);
+                startTime = simpleDateFormat.format(instance.getTime()) + " 00:00:00";
+                instance.add(Calendar.DATE, 7-1);
+                nowTime = simpleDateFormat.format(instance.getTime()) + " 23:59:59";
+            }
+            if (flag){
+                top = dmHaveDinnerRepository.selectTop(stateDate,endDate,null);
+                stop = dmHaveDinnerRepository.selectStop(stateDate, endDate,null);
+            }else {
+                top = dmHaveDinnerRepository.selectTop(startTime,nowTime,null);
+                stop = dmHaveDinnerRepository.selectStop(startTime, nowTime,null);
+            }
         }
         // 按月报来
         if (type.equals("month")){
-            top = dmHaveDinnerRepository.selectMonthTopView(stateDate,endDate,pageable);
-            stop = dmHaveDinnerRepository.selectMonthStopView(stateDate, endDate, pageable);
+
+            Calendar instance = Calendar.getInstance();
+            // 当前月份最大多少天
+            int actualMaximum = instance.getActualMaximum(Calendar.DATE);
+            //当前时间
+            String nowTime = month.format(instance.getTime()) + "-"+actualMaximum+" 23:59:59";
+            String startTime = month.format(instance.getTime()) + "-01 00:00:00";
+            if (flag){
+                top = dmHaveDinnerRepository.selectTop(stateDate,endDate,null);
+                stop = dmHaveDinnerRepository.selectStop(stateDate, endDate,null);
+            }else {
+                top = dmHaveDinnerRepository.selectTop(startTime,nowTime,null);
+                stop = dmHaveDinnerRepository.selectStop(startTime, nowTime,null);
+            }
         }
         // 按年报来
         if (type.equals("year")){
-            top = dmHaveDinnerRepository.selectYearTopView(stateDate,endDate,pageable);
-            stop = dmHaveDinnerRepository.selectYearStopView(stateDate, endDate, pageable);
+            Calendar instance = Calendar.getInstance();
+            //设置到12月用来取最大天数
+            instance.set(Calendar.MONTH, 11);
+            // 当年最大月份最大多少天
+            int actualMaximum = instance.getActualMaximum(Calendar.DATE);
+            //当前时间
+            String nowTime = year.format(instance.getTime())+ "-12-"+actualMaximum+" 23:59:59";
+            String startTime = year.format( instance.getTime())+ "-01-01 00:00:00";
+            if (flag){
+                top = dmHaveDinnerRepository.selectTop(stateDate,endDate,null);
+                stop = dmHaveDinnerRepository.selectStop(stateDate, endDate,null);
+            }else {
+                top = dmHaveDinnerRepository.selectTop(startTime,nowTime,null);
+                stop = dmHaveDinnerRepository.selectStop(startTime, nowTime,null);
+            }
         }
         JSONObject jsonObject = new JSONObject();
         jsonObject.put("top", PageUtil.toPage(top));