Pārlūkot izejas kodu

重构用餐报表

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

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

@@ -296,10 +296,10 @@ public interface DmHaveDinnerRepository extends JpaRepository<DmHaveDinner,Integ
     void createDayDiningStatementsTopThreeView(@Param("startTime") String startTime,@Param("nowTime") String nowTime,@Param("viewName") String viewName);
 
     @Query(nativeQuery = true, value = "SELECT rec.create_date,item.pid,item.name,COUNT(item.pid) as countPid,sum(item.price) as price,item.seq FROM (SELECT create_date,seq FROM dm_order_record WHERE create_date BETWEEN ?1 AND ?2) rec left join  dm_order_item item on rec.seq = item.seq WHERE item.pid is not NULL GROUP BY item.pid ORDER BY countPid DESC LIMIT 0,3")
-    Page<List<Map<String,Object>>> selectTop(String startTime, String nowTime,Pageable pageable);
+    Page<Map<String,Object>> selectTop(String startTime, String nowTime,Pageable pageable);
 
     @Query(nativeQuery = true, value = "SELECT rec.create_date,item.pid,item.name,COUNT(item.pid) as countPid,sum(item.price) as price,item.seq FROM (SELECT create_date,seq FROM dm_order_record WHERE create_date BETWEEN ?1 AND ?2) rec left join  dm_order_item item on rec.seq = item.seq WHERE item.pid is not NULL GROUP BY item.pid ORDER BY countPid ASC LIMIT 0,3")
-    Page<List<Map<String,Object>>> selectStop(String startTime, String nowTime,Pageable pageable);
+    Page<Map<String,Object>> selectStop(String startTime, String nowTime,Pageable pageable);
     /**
      * 创建后三日视图
      * @param startTime //开始时间

+ 15 - 14
eladmin-system/src/main/java/me/zhengjie/modules/dm/statement/rest/DmHaveDinnerController.java

@@ -34,18 +34,20 @@ import java.util.Map;
 public class DmHaveDinnerController {
     private final DmHaveDinnerService dmHaveDinnerService;
 
-    @Log("导出数据")
-    @ApiOperation("导出数据")
-    @GetMapping(value = "/download")
+    @Log("导出受欢迎前三数据")
+    @ApiOperation("导出受欢迎前三数据")
+    @GetMapping(value = "/downloadTop")
     @PreAuthorize("@el.check('dmHaveDinner:list')")
-    public void download(HttpServletResponse response, String stateDate, String endDate, String type, Pageable pageable) throws IOException {
-        Map<String,Object> map = dmHaveDinnerService.selectZgHaveDinner(stateDate,endDate,type,pageable);
-        List<DmHaveDinnerDto> all = (List<DmHaveDinnerDto>)map.get("content");
-        if (type.equals("week")){
-            dmHaveDinnerService.downWeekload(all, response);
-        }else {
-            dmHaveDinnerService.download(all, response);
-        }
+    public void downloadTop(HttpServletResponse response, String stateDate, String endDate, String type, Pageable pageable) throws IOException {
+        dmHaveDinnerService.downDiningTopStatements(stateDate,endDate,type,pageable,response);
+    }
+    @Log("导出不受欢迎前三数据")
+    @ApiOperation("导出不受欢迎前三数据")
+    @GetMapping(value = "/downloadStop")
+    @PreAuthorize("@el.check('dmHaveDinner:list')")
+    public void downloadStop(HttpServletResponse response, String stateDate, String endDate, String type, Pageable pageable) throws IOException {
+        dmHaveDinnerService.downDiningStopStatements(stateDate,endDate,type,pageable,response);
+
     }
 
 
@@ -54,7 +56,7 @@ public class DmHaveDinnerController {
     @ApiOperation("用餐报表")
 //    @PreAuthorize("@el.check('dmHaveDinner:list')")
     public ResponseEntity<Object> selectZgHaveDinner(String stateDate, String endDate, String type, Pageable pageable){
-        JSONObject map = dmHaveDinnerService.selectDiningStatements(stateDate,endDate,type,pageable);
+        JSONObject map = dmHaveDinnerService.selectDiningTopStatements(stateDate,endDate,type,pageable);
         return new ResponseEntity<>(map, HttpStatus.OK);
     }
 
@@ -62,8 +64,7 @@ public class DmHaveDinnerController {
     @Log("用餐报表")
     @ApiOperation("用餐报表")
     public ResponseEntity<Object> selectZdHaveDinner(String stateDate, String endDate, String type, Pageable pageable){
-        Map<String,Object> map = new HashMap<>();
-        map.put("two",dmHaveDinnerService.selectZdHaveDinner(stateDate,endDate,type,pageable));
+        JSONObject map = dmHaveDinnerService.selectDiningStopStatements(stateDate,endDate,type,pageable);
         return new ResponseEntity<>(map, HttpStatus.OK);
     }
 

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

@@ -47,5 +47,9 @@ public interface DmHaveDinnerService {
 
     JSONObject selectDiningTopStatements(String stateDate, String endDate, String type, Pageable pageable);
 
-    JSONObject selectDiningsStopStatements(String stateDate, String endDate, String type, Pageable pageable);
+    JSONObject selectDiningStopStatements(String stateDate, String endDate, String type, Pageable pageable);
+
+    void downDiningTopStatements(String stateDate, String endDate, String type, Pageable pageable,HttpServletResponse response) throws IOException;
+
+    void downDiningStopStatements(String stateDate, String endDate, String type, Pageable pageable,HttpServletResponse response) throws IOException;
 }

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

@@ -49,7 +49,7 @@ public class DmHaveDinnerServiceImpl implements DmHaveDinnerService {
         }
 
        // 前三
-        Page<List<Map<String, Object>>> top = null;
+        Page<Map<String, Object>> top = null;
         // 默认按月来
         if (type == null){
            type = "month";
@@ -132,7 +132,7 @@ public class DmHaveDinnerServiceImpl implements DmHaveDinnerService {
     }
 
     @Override
-    public JSONObject selectDiningsStopStatements(String stateDate, String endDate, String type, Pageable pageable) {
+    public JSONObject selectDiningStopStatements(String stateDate, String endDate, String type, Pageable pageable) {
 
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
 
@@ -146,7 +146,7 @@ public class DmHaveDinnerServiceImpl implements DmHaveDinnerService {
             flag = true;
         }
         // 后三
-        Page<List<Map<String, Object>>> stop = null;
+        Page<Map<String, Object>> stop = null;
         // 默认按月来
         if (type == null){
             type = "month";
@@ -387,5 +387,216 @@ public class DmHaveDinnerServiceImpl implements DmHaveDinnerService {
         FileUtil.downloadExcel(list, response);
     }
 
+    @Override
+    public void downDiningTopStatements(String stateDate, String endDate, String type, Pageable pageable, HttpServletResponse response) throws IOException {
+
+        List<Map<String, Object>> list = new ArrayList<>();
+
+        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<Map<String, Object>> top = null;
+        // 默认按月来
+        if (type == null){
+            type = "month";
+        }
+        //按日报来
+        if (type.equals("day")){
+            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);
+            }else {
+                top = dmHaveDinnerRepository.selectTop(StartTime,nowTime,null);
+            }
+
+        }
+        // 按周报来
+        if (type.equals("week")){
+            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);
+            }else {
+                top = dmHaveDinnerRepository.selectTop(startTime,nowTime,null);
+            }
+        }
+        // 按月报来
+        if (type.equals("month")){
+
+            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);
+            }else {
+                top = dmHaveDinnerRepository.selectTop(startTime,nowTime,null);
+            }
+        }
+        // 按年报来
+        if (type.equals("year")){
+            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);
+            }else {
+                top = dmHaveDinnerRepository.selectTop(startTime,nowTime,null);
+            }
+        }
+        List<Map<String, Object>> content = top.getContent();
+        content.forEach(item->{
+            Map<String,Object> map = new LinkedHashMap<>();
+            map.put("菜品受欢迎前三-菜品名称", item.get("name"));
+            map.put("菜品受欢迎前三-购买次数", item.get("countPid"));
+            map.put("菜品受欢迎前三-总消费", item.get("price"));
+            list.add(map);
+        });
+        FileUtil.downloadExcel(list, response);
+    }
+
+    @Override
+    public void downDiningStopStatements(String stateDate, String endDate, String type, Pageable pageable,HttpServletResponse response) throws IOException {
+
+        List<Map<String, Object>> list = new ArrayList<>();
+
+        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<Map<String, Object>> stop = null;
+        // 默认按月来
+        if (type == null){
+            type = "month";
+        }
+        //按日报来
+        if (type.equals("day")){
+            Calendar instance = Calendar.getInstance();
+            //当前时间
+            String nowTime = simpleDateFormat.format(instance.getTime()) + " 23:59:59";
+            String StartTime = simpleDateFormat.format(instance.getTime()) + " 00:00:00";
+            if (flag){
+                stop = dmHaveDinnerRepository.selectStop(stateDate, endDate,null);
+            }else {
+                stop = dmHaveDinnerRepository.selectStop(StartTime, nowTime,null);
+            }
+
+        }
+        // 按周报来
+        if (type.equals("week")){
+            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){
+                stop = dmHaveDinnerRepository.selectStop(stateDate, endDate,null);
+            }else {
+                stop = dmHaveDinnerRepository.selectStop(startTime, nowTime,null);
+            }
+        }
+        // 按月报来
+        if (type.equals("month")){
+
+            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){
+                stop = dmHaveDinnerRepository.selectStop(stateDate, endDate,null);
+            }else {
+                stop = dmHaveDinnerRepository.selectStop(startTime, nowTime,null);
+            }
+        }
+        // 按年报来
+        if (type.equals("year")){
+            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){
+                stop = dmHaveDinnerRepository.selectStop(stateDate, endDate,null);
+            }else {
+                stop = dmHaveDinnerRepository.selectStop(startTime, nowTime,null);
+            }
+        }
+        List<Map<String, Object>> content = stop.getContent();
+        content.forEach(item->{
+            Map<String,Object> map = new LinkedHashMap<>();
+            map.put("菜品不受欢迎前三-菜品名称", item.get("name"));
+            map.put("菜品不受欢迎前三-购买次数", item.get("countPid"));
+            map.put("菜品不受欢迎前三-总消费", item.get("price"));
+            list.add(map);
+        });
+        FileUtil.downloadExcel(list, response);
+    }
+
 
 }