Pārlūkot izejas kodu

重构用餐报表

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

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

@@ -213,25 +213,251 @@ public interface DmHaveDinnerRepository extends JpaRepository<DmHaveDinner,Integ
     String judgeView(@Param("viewName") String viewName);
 
     /**
-     * 删除视图
+     * 删除前三名日报表视图
      * @param viewName
      */
     @Modifying
     @Transactional
-    @Query(nativeQuery = true,value = "drop view `DAY_DINING_STATEMENTS`")
-    void dropDayView(@Param("viewName") String viewName);
+    @Query(nativeQuery = true,value = "drop view `DAY_DINING_STATEMENTS_TOP`")
+    void dropDayTopView(@Param("viewName") String viewName);
 
     /**
-     * 创建视图
+     * 删除后三日名报表视图
+     * @param viewName
+     */
+    @Modifying
+    @Transactional
+    @Query(nativeQuery = true,value = "drop view `DAY_DINING_STATEMENTS_STOP`")
+    void dropDayStopView(@Param("viewName") String viewName);
+
+    /**
+     * 删除前三名周报表视图
+     * @param viewName
+     */
+    @Modifying
+    @Transactional
+    @Query(nativeQuery = true,value = "drop view `WEEK_DINING_STATEMENTS_TOP`")
+    void dropWeekTopView(String viewName);
+
+    /**
+     * 删除前三名周报表视图
+     * @param viewName
+     */
+    @Modifying
+    @Transactional
+    @Query(nativeQuery = true,value = "drop view `WEEK_DINING_STATEMENTS_STOP`")
+    void dropWeekStopView(String viewName);
+
+    /**
+     * 删除前三名月报表视图
+     * @param viewName
+     */
+    @Modifying
+    @Transactional
+    @Query(nativeQuery = true,value = "drop view `MONTH_DINING_STATEMENTS_TOP`")
+    void dropMonthTopView(String viewName);
+
+    /**
+     * 删除后三名月报表视图
+     * @param viewName
+     */
+    @Modifying
+    @Transactional
+    @Query(nativeQuery = true,value = "drop view `MONTH_DINING_STATEMENTS_STOP`")
+    void dropMonthStopView(String viewName);
+
+    /**
+     * 删除前三名年报表视图
+     * @param viewName
+     */
+    @Modifying
+    @Transactional
+    @Query(nativeQuery = true,value = "drop view `YEAR_DINING_STATEMENTS_TOP`")
+    void dropYearTopView(String viewName);
+
+    /**
+     * 删除前三名年报表视图
+     * @param viewName
+     */
+    @Modifying
+    @Transactional
+    @Query(nativeQuery = true,value = "drop view `YEAR_DINING_STATEMENTS_STOP`")
+    void dropYearStopView(String viewName);
+
+    /**
+     * 创建前三日报表视图
+     * @param startTime //开始时间
+     * @param nowTime  //当前时间
+     * @param viewName //视图名称
+     */
+    @Modifying
+    @Transactional
+    @Query(nativeQuery = true,value = "create view `DAY_DINING_STATEMENTS_TOP` as SELECT item.pid,item.name,COUNT(item.pid) as countPid,item.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);
+
+    /**
+     * 创建后三日视图
+     * @param startTime //开始时间
+     * @param nowTime  //当前时间
+     * @param viewName //视图名称
+     */
+    @Modifying
+    @Transactional
+    @Query(nativeQuery = true,value = "create view `DAY_DINING_STATEMENTS_STOP` as SELECT item.pid,item.name,COUNT(item.pid) as countPid,item.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 ")
+    void createDayDiningStatementsStopThreeView(@Param("startTime") String startTime,@Param("nowTime") String nowTime,@Param("viewName") String viewName);
+
+    /**
+     * 创建创建前三周报视图
+     * @param startTime //开始时间
+     * @param nowTime  //当前时间
+     * @param viewName //视图名称
+     */
+    @Modifying
+    @Transactional
+    @Query(nativeQuery = true,value = "create view `WEEK_DINING_STATEMENTS_TOP` as SELECT item.pid,item.name,COUNT(item.pid) as countPid,item.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 createWeekDiningStatementsTopThreeView(@Param("startTime") String startTime,@Param("nowTime") String nowTime,@Param("viewName") String viewName);
+
+    /**
+     * 创建后三周报视图
+     * @param startTime //开始时间
+     * @param nowTime  //当前时间
+     * @param viewName //视图名称
+     */
+    @Modifying
+    @Transactional
+    @Query(nativeQuery = true,value = "create view `WEEK_DINING_STATEMENTS_STOP` as SELECT item.pid,item.name,COUNT(item.pid) as countPid,item.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 ")
+    void createWeekDiningStatementsStopThreeView(@Param("startTime") String startTime,@Param("nowTime") String nowTime,@Param("viewName") String viewName);
+
+    /**
+     * 创建前三月报视图
+     * @param startTime //开始时间
+     * @param nowTime  //当前时间
+     * @param viewName //视图名称
+     */
+    @Modifying
+    @Transactional
+    @Query(nativeQuery = true,value = "create view `MONTH_DINING_STATEMENTS_TOP` as SELECT item.pid,item.name,COUNT(item.pid) as countPid,item.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 createMonthDiningStatementsTopThreeView(@Param("startTime") String startTime,@Param("nowTime") String nowTime,@Param("viewName") String viewName);
+
+    /**
+     * 创建后三月报视图
+     * @param startTime //开始时间
+     * @param nowTime  //当前时间
+     * @param viewName //视图名称
+     */
+    @Modifying
+    @Transactional
+    @Query(nativeQuery = true,value = "create view `MONTH_DINING_STATEMENTS_STOP` as SELECT item.pid,item.name,COUNT(item.pid) as countPid,item.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 ")
+    void createMonthDiningStatementsStopThreeView(@Param("startTime") String startTime,@Param("nowTime") String nowTime,@Param("viewName") String viewName);
+
+    /**
+     * 创建前三 年报表视图
+     * @param startTime //开始时间
+     * @param nowTime  //当前时间
+     * @param viewName //视图名称
+     */
+    @Modifying
+    @Transactional
+    @Query(nativeQuery = true,value = "create view `YEAR_DINING_STATEMENTS_TOP` as SELECT item.pid,item.name,COUNT(item.pid) as countPid,item.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 createYearDiningStatementsTopThreeView(@Param("startTime") String startTime,@Param("nowTime") String nowTime,@Param("viewName") String viewName);
+
+    /**
+     * 创建后三 年报视图
      * @param startTime //开始时间
      * @param nowTime  //当前时间
      * @param viewName //视图名称
      */
     @Modifying
     @Transactional
-    @Query(nativeQuery = true,value = "create view DAY_DINING_STATEMENTS as SELECT item.pid,item.name,COUNT(item.pid) as countPid,item.price,rec.create_date,item.seq FROM dm_order_record rec LEFT JOIN  dm_order_item item on rec.seq = item.seq WHERE rec.create_date BETWEEN ?1  AND ?2  GROUP BY item.pid ")
-    void createDayView(@Param("startTime") String startTime,@Param("nowTime") String nowTime,@Param("viewName") String viewName);
+    @Query(nativeQuery = true,value = "create view `YEAR_DINING_STATEMENTS_STOP` as SELECT item.pid,item.name,COUNT(item.pid) as countPid,item.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 ")
+    void createYearDiningStatementsStopThreeView(@Param("startTime") String startTime,@Param("nowTime") String nowTime,@Param("viewName") String viewName);
+
+    /**
+     * 查询前三日报
+     * @return
+     */
+    @Query(nativeQuery = true,value = "SELECT pid,name,countPid,price,create_date FROM `DAY_DINING_STATEMENTS_TOP` where create_date between ?1 and ?2 ",
+    countQuery = "SELECT count(1) FROM `DAY_DINING_STATEMENTS_TOP` where create_date between ?1 and ?2 ")
+    List<Map<String,Object>> selectDayTopView(String startTime, String nowTime,Pageable pageable);
+
+    /**
+     * 查询后三日报
+     * @return
+     */
+    @Query(nativeQuery = true,value = "SELECT pid,name,countPid,price,create_date FROM `DAY_DINING_STATEMENTS_STOP` where create_date between ?1 and ?2",
+    countQuery = "SELECT count(1) FROM `DAY_DINING_STATEMENTS_STOP` where create_date between ?1 and ?2")
+    List<Map<String,Object>> selectDayStopView(String startTime, String nowTime,Pageable pageable);
+
+    /**
+     * 查询前三周报
+     * @param startTime
+     * @param nowTime
+     * @param weeksInWeekYear
+     * @param pageable
+     * @return
+     */
+    @Query(nativeQuery = true,value = "SELECT pid,name,countPid,price,create_date FROM `WEEK_DINING_STATEMENTS_TOP` where create_date between ?1 and ?2 ",
+    countQuery = "SELECT count(1) FROM `WEEK_DINING_STATEMENTS_TOP` where create_date between ?1 and ?2 ")
+    List<Map<String,Object>> selectWeekTopView(String startTime, String nowTime, Pageable pageable);
+
+    /**
+     * 查询后三周报
+     * @param startTime
+     * @param nowTime
+     * @param weeksInWeekYear
+     * @param pageable
+     * @return
+     */
+    @Query(nativeQuery = true,value = "SELECT pid,name,countPid,price,create_date FROM `WEEK_DINING_STATEMENTS_STOP` where create_date between ?1 and ?2 ",
+    countQuery = "SELECT count(1) FROM `WEEK_DINING_STATEMENTS_STOP` where create_date between ?1 and ?2 ")
+    List<Map<String,Object>> selectWeekStopView(String startTime, String nowTime, Pageable pageable);
+
+    /**
+     * 查询前三 月报
+     * @param startTime
+     * @param nowTime
+     * @param monthsInYear
+     * @param pageable
+     * @return
+     */
+    @Query(nativeQuery = true,value = "SELECT pid,name,countPid,price,create_date FROM `MONTH_DINING_STATEMENTS_TOP` where create_date between ?1 and ?2",
+    countQuery = "SELECT count(1) FROM `MONTH_DINING_STATEMENTS_TOP` where create_date between ?1 and ?2 ")
+    List<Map<String,Object>> selectMonthTopView(String startTime, String nowTime, Pageable pageable);
+
+    /**
+     * 查询后三 月报
+     * @param startTime
+     * @param nowTime
+     * @param monthsInYear
+     * @param pageable
+     * @return
+     */
+    @Query(nativeQuery = true,value = "SELECT pid,name,countPid,price,create_date FROM `MONTH_DINING_STATEMENTS_STOP` where create_date between ?1 and ?2",
+    countQuery = "SELECT pid,name,countPid,price,create_date FROM `MONTH_DINING_STATEMENTS_STOP` where create_date between ?1 and ?2")
+    List<Map<String,Object>> selectMonthStopView(String startTime, String nowTime, Pageable pageable);
+
+    /**
+     * 查询前三 年报
+     * @param startTime
+     * @param nowTime
+     * @param year
+     * @param pageable
+     * @return
+     */
+    @Query(nativeQuery = true,value = "SELECT pid,name,countPid,price,create_date FROM `YEAR_DINING_STATEMENTS_TOP` where create_date between ?1 and ?2",
+    countQuery = "SELECT count(1) FROM `YEAR_DINING_STATEMENTS_TOP` where create_date between ?1 and ?2 ")
+    List<Map<String,Object>> selectYearTopView(String startTime, String nowTime, Pageable pageable);
+
+    /**
+     * 查询后三 年报
+     * @param startTime
+     * @param nowTime
+     * @param year
+     * @param pageable
+     * @return
+     */
+    @Query(nativeQuery = true,value = "SELECT pid,name,countPid,price,create_date FROM `YEAR_DINING_STATEMENTS_STOP` where create_date between ?1 and ?2",
+    countQuery = "SELECT count(1) FROM `YEAR_DINING_STATEMENTS_STOP` where create_date between ?1 and ?2")
+    List<Map<String,Object>> selectYearStopView(String startTime, String nowTime, Pageable pageable);
 
-    @Query(nativeQuery = true,value = "SELECT * FROM `DAY_DINING_STATEMENTS`")
-    List<Map<String,Object>> selectDayView();
 }

+ 218 - 7
eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/DiningStatementsTask.java

@@ -11,15 +11,20 @@ package me.zhengjie.modules.quartz.task;/**
  * Description: iot-zhcy
  */
 
+import cn.hutool.core.util.ObjectUtil;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import me.zhengjie.modules.dm.statement.repository.DmHaveDinnerRepository;
 import me.zhengjie.modules.dm.statement.service.mapstruct.DmHaveDinnerMapper;
 import me.zhengjie.utils.StringUtils;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
 import org.springframework.stereotype.Component;
 
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
+import java.util.List;
+import java.util.Map;
 
 /**
  * <功能简要> <br>
@@ -37,6 +42,17 @@ public class DiningStatementsTask {
 
     private final DmHaveDinnerRepository dmHaveDinnerRepository;
 
+    public void  run(){
+        //日报
+        dayDiningStatements();
+        //周报
+        weekDiningStatements();
+        //月报
+        monthDiningStatements();
+        //年报
+        yearDiningStatements();
+    }
+
     /**
      * 定时生成用餐日报  DAY_DINING_STATEMENTS
      */
@@ -47,20 +63,215 @@ public class DiningStatementsTask {
         //当前时间
         String nowTime = simpleDateFormat.format(instance.getTime()) + " 23:59:59";
         String StartTime = simpleDateFormat.format(instance.getTime()) + " 00:00:00";
-        //第一步判断是否有Day_Dining_Statements视图
-       String viewName = dmHaveDinnerRepository.judgeView("DAY_DINING_STATEMENTS");
+
+        /**
+         * 前三名
+         */
+        //第一步判断是否有DAY_DINING_STATEMENTS_TOP视图
+        String viewTopName = dmHaveDinnerRepository.judgeView("DAY_DINING_STATEMENTS_TOP");
+//由于是一天一生成 那就再新增之前就要删除之前的视图
+        if (!StringUtils.isEmpty(viewTopName)){
+            //删除视图
+            dmHaveDinnerRepository.dropDayTopView("DAY_DINING_STATEMENTS_TOP");
+            //创建视图
+            dmHaveDinnerRepository.createDayDiningStatementsTopThreeView(StartTime,nowTime,"DAY_DINING_STATEMENTS_TOP");
+        }else {
+            //创建视图
+            dmHaveDinnerRepository.createDayDiningStatementsTopThreeView(StartTime,nowTime,"DAY_DINING_STATEMENTS_TOP");
+        }
+        /**
+         * 后三名
+         */
+        //第一步判断是否有DAY_DINING_STATEMENTS_STOP视图
+       String viewStopName = dmHaveDinnerRepository.judgeView("DAY_DINING_STATEMENTS_STOP");
        //由于是一天一生成 那就再新增之前就要删除之前的视图
-       if (!StringUtils.isEmpty(viewName)){
+       if (!StringUtils.isEmpty(viewStopName)){
            //删除视图
-           dmHaveDinnerRepository.dropDayView("DAY_DINING_STATEMENTS");
+           dmHaveDinnerRepository.dropDayStopView("DAY_DINING_STATEMENTS_STOP");
            //创建视图
-           dmHaveDinnerRepository.createDayView(StartTime,nowTime,"DAY_DINING_STATEMENTS");
-
+           dmHaveDinnerRepository.createDayDiningStatementsStopThreeView(StartTime,nowTime,"DAY_DINING_STATEMENTS_STOP");
        }else {
            //创建视图
-           dmHaveDinnerRepository.createDayView(StartTime,nowTime,"DAY_DINING_STATEMENTS");
+           dmHaveDinnerRepository.createDayDiningStatementsStopThreeView(StartTime,nowTime,"DAY_DINING_STATEMENTS_STOP");
        }
 
     }
 
+    /**
+     * 定时生成用餐周报  WEEK_DINING_STATEMENTS
+     */
+    public void weekDiningStatements(){
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+
+        Calendar instance = Calendar.getInstance();
+        // 当前当前时间在当年中是第几个星期  后面要用来判断是否执行
+        int weeksInWeekYear = instance.get(Calendar.WEEK_OF_YEAR);
+        //判断当前时间在当前星期中事星期几  由于日历类中星期一是从周日算的
+        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";
+        }
+        /**
+         * 前三名
+         */
+        //第一步判断是否有WEEK_DINING_STATEMENTS视图
+        String viewTopName = dmHaveDinnerRepository.judgeView("WEEK_DINING_STATEMENTS_TOP");
+        if (!StringUtils.isEmpty(viewTopName)){
+            //查询视图
+            List<Map<String, Object>> maps = dmHaveDinnerRepository.selectWeekTopView(startTime, nowTime, null);
+            if (ObjectUtil.isEmpty(maps)){
+                //删除视图
+                dmHaveDinnerRepository.dropWeekTopView("WEEK_DINING_STATEMENTS_TOP");
+                //创建视图
+                dmHaveDinnerRepository.createWeekDiningStatementsTopThreeView(startTime,nowTime,"WEEK_DINING_STATEMENTS_TOP");
+            }
+        }else{
+            //创建视图
+            dmHaveDinnerRepository.createWeekDiningStatementsTopThreeView(startTime,nowTime,"WEEK_DINING_STATEMENTS_TOP");
+        }
+
+        /**
+         * 后三名
+         */
+        //第一步判断是否有WEEK_DINING_STATEMENTS视图
+        String viewStopName = dmHaveDinnerRepository.judgeView("WEEK_DINING_STATEMENTS_STOP");
+        //由于是一周一生成 那就再新增之前就要删除之前的视图
+        if (!StringUtils.isEmpty(viewStopName)){
+            //查询视图
+            List<Map<String, Object>> maps = dmHaveDinnerRepository.selectWeekStopView(startTime, nowTime, null);
+             if (ObjectUtil.isEmpty(maps)){
+                 //删除视图
+                 dmHaveDinnerRepository.dropWeekTopView("WEEK_DINING_STATEMENTS_STOP");
+                 //创建视图
+                 dmHaveDinnerRepository.createWeekDiningStatementsStopThreeView(startTime,nowTime,"WEEK_DINING_STATEMENTS_STOP");
+             }
+        }else {
+            //创建视图
+            dmHaveDinnerRepository.createWeekDiningStatementsStopThreeView(startTime,nowTime,"WEEK_DINING_STATEMENTS_STOP");
+        }
+
+    }
+
+
+    /**
+     * 定时生成用餐月报  MONTH_DINING_STATEMENTS
+     */
+    public void  monthDiningStatements(){
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
+        Calendar instance = Calendar.getInstance();
+        // 当前月份
+        int monthsInYear = instance.get(Calendar.MONTH)+1;
+        // 当前月份最大多少天
+        int actualMaximum = instance.getActualMaximum(Calendar.DATE);
+        //当前时间
+        String nowTime = simpleDateFormat.format(instance.getTime()) + "-"+actualMaximum+" 23:59:59";
+        String startTime = simpleDateFormat.format(instance.getTime()) + "-01 00:00:00";
+        /**
+         * 前三名
+         */
+        //第一步判断是否有WEEK_DINING_STATEMENTS视图
+        String viewTopName = dmHaveDinnerRepository.judgeView("MONTH_DINING_STATEMENTS_TOP");
+        if (!StringUtils.isEmpty(viewTopName)){
+            //查询视图
+            List<Map<String, Object>> maps = dmHaveDinnerRepository.selectMonthTopView(startTime, nowTime, null);
+            if (ObjectUtil.isEmpty(maps)){
+                //删除视图
+                dmHaveDinnerRepository.dropWeekTopView("MONTH_DINING_STATEMENTS_TOP");
+                //创建视图
+                dmHaveDinnerRepository.createWeekDiningStatementsTopThreeView(startTime,nowTime,"MONTH_DINING_STATEMENTS_TOP");
+            }
+        }else{
+            //创建视图
+            dmHaveDinnerRepository.createMonthDiningStatementsTopThreeView(startTime,nowTime,"MONTH_DINING_STATEMENTS_TOP");
+        }
+
+        /**
+         * 后三名
+         */
+        //第一步判断是否有WEEK_DINING_STATEMENTS视图
+        String viewStopName = dmHaveDinnerRepository.judgeView("MONTH_DINING_STATEMENTS_STOP");
+        //由于是一周一生成 那就再新增之前就要删除之前的视图
+        if (!StringUtils.isEmpty(viewStopName)){
+            //查询视图
+            List<Map<String, Object>> maps = dmHaveDinnerRepository.selectWeekStopView(startTime, nowTime, null);
+            if (ObjectUtil.isEmpty(maps)){
+                //删除视图
+                dmHaveDinnerRepository.dropMonthTopView("MONTH_DINING_STATEMENTS_STOP");
+                //创建视图
+                dmHaveDinnerRepository.createMonthDiningStatementsStopThreeView(startTime,nowTime,"MONTH_DINING_STATEMENTS_STOP");
+            }
+        }else {
+            //创建视图
+            dmHaveDinnerRepository.createMonthDiningStatementsStopThreeView(startTime,nowTime,"MONTH_DINING_STATEMENTS_STOP");
+        }
+
+    }
+
+    /**
+     * 定时生成用餐年报  MONTH_DINING_STATEMENTS
+     */
+    public void  yearDiningStatements(){
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy");
+        Calendar instance = Calendar.getInstance();
+        //设置到12月用来取最大天数
+        instance.set(Calendar.MONTH, 11);
+        // 当年最大月份最大多少天
+        int actualMaximum = instance.getActualMaximum(Calendar.DATE);
+        //当前时间
+        String nowTime = simpleDateFormat.format(instance.getTime())+ "-12-"+actualMaximum+" 23:59:59";
+        String startTime = simpleDateFormat.format( instance.getTime())+ "-01-01 00:00:00";
+        /**
+         * 前三名
+         */
+        //第一步判断是否有WEEK_DINING_STATEMENTS视图
+        String viewTopName = dmHaveDinnerRepository.judgeView("YEAR_DINING_STATEMENTS_TOP");
+        if (!StringUtils.isEmpty(viewTopName)){
+            //查询视图
+            List<Map<String, Object>> maps = dmHaveDinnerRepository.selectYearTopView(startTime, nowTime, null);
+            if (ObjectUtil.isEmpty(maps)){
+                //删除视图
+                dmHaveDinnerRepository.dropYearTopView("YEAR_DINING_STATEMENTS_TOP");
+                //创建视图
+                dmHaveDinnerRepository.createYearDiningStatementsTopThreeView(startTime,nowTime,"YEAR_DINING_STATEMENTS_TOP");
+            }
+        }else{
+            //创建视图
+            dmHaveDinnerRepository.createYearDiningStatementsTopThreeView(startTime,nowTime,"MONTH_DINING_STATEMENTS_TOP");
+        }
+
+        /**
+         * 后三名
+         */
+        //第一步判断是否有WEEK_DINING_STATEMENTS视图
+        String viewStopName = dmHaveDinnerRepository.judgeView("YEAR_DINING_STATEMENTS_STOP");
+        //由于是一周一生成 那就再新增之前就要删除之前的视图
+        if (!StringUtils.isEmpty(viewStopName)){
+            //查询视图
+            List<Map<String, Object>> maps = dmHaveDinnerRepository.selectYearStopView(startTime, nowTime, null);
+            if (ObjectUtil.isEmpty(maps)){
+                //删除视图
+                dmHaveDinnerRepository.dropYearStopView("YEAR_DINING_STATEMENTS_STOP");
+                //创建视图
+                dmHaveDinnerRepository.createYearDiningStatementsStopThreeView(startTime,nowTime,"YEAR_DINING_STATEMENTS_STOP");
+            }
+        }else {
+            //创建视图
+            dmHaveDinnerRepository.createYearDiningStatementsStopThreeView(startTime,nowTime,"YEAR_DINING_STATEMENTS_STOP");
+        }
+
+    }
 }

+ 0 - 8
eladmin-system/src/main/java/me/zhengjie/modules/thirdparty/v1/OpenApiController.java

@@ -341,12 +341,4 @@ public class OpenApiController {
         jsonObject.put("countTheTopThree",countTheTopThree);
         return new BaseResponse<>(jsonObject);
     }
-
-    @AnonymousGetMapping(value = "/getDiningStatements")
-    @Log("获取用餐日报")
-    @ApiOperation("获取用餐日报")
-    public BaseResponse<Object> getDiningStatements(){
-       List<Map<String,Object>> maps = dmHaveDinnerRepository.selectDayView();
-        return new BaseResponse<>(maps);
-    }
 }