Parcourir la source

按天/月/季度/年粒度统计收入汇总列表

gqx il y a 2 ans
Parent
commit
4ee61ec2d0

+ 17 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/finance/controller/SummaryController.java

@@ -154,4 +154,21 @@ public class SummaryController {
 		}
 		return Result.OK(data);
 	}
+
+	/**
+	 *
+	 * @param hotelId 酒店id
+	 * @param startTime 开始日期
+	 * @param endTime 截至日期
+	 * @param section 1天 2月 3季度 4年
+	 * @return
+	 */
+	@ApiOperation(value = "当天收入统计", notes = "当天收入统计")
+	@GetMapping(value = "/shouRuStatList")
+	public Result<List<HashMap<String, Object>>> getDayShouRuStatList(@RequestParam String hotelId, @RequestParam(name = "startTime", required = true) @JsonFormat(pattern = "yyyy-MM-dd")  @DateTimeFormat(pattern="yyyy-MM-dd") DateTime startTime,
+											  @RequestParam(name = "endTime", required = true) @JsonFormat(pattern = "yyyy-MM-dd")  @DateTimeFormat(pattern="yyyy-MM-dd") DateTime endTime,
+											  @RequestParam(name = "section", defaultValue = "1") Integer section) {
+		List<HashMap<String, Object>> pageList = summaryService.dayShouRuStatList(hotelId, startTime, endTime, section);
+		return Result.OK(pageList);
+	}
 }

+ 102 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/finance/mapper/SummaryMapper.java

@@ -181,4 +181,106 @@ public interface SummaryMapper extends BaseMapper<PosOrderGoodsPayment>  {
             "</script>")
     public List<HashMap<String,Object>> roomFinancePage(Page<HashMap<String,Object>> page, @Param("hotelId") String hotelId, @Param("startTime") DateTime startTime, @Param("endTime") DateTime endTime);
 
+    /**
+     * 按时间每天收入统计列表
+     * @param hotelId
+     * @param startTime
+     * @param endTime
+     * @return
+     */
+    @Select("<script>select time,sum(room_money) as room_money,sum(other_money) as other_money from \n" +
+            "(SELECT 'pos' as type, a.time\n" +
+            ",0 AS room_money,\n" +
+            "sum(ifnull(b.pay_money,0)) as other_money\n" +
+            "FROM (\n" +
+            "\tselect time from\n" +
+            "\t(select adddate('1970-01-01',t4.i*10000 + t3.i*1000 + t2.i*100 + t1.i*10 + t0.i) AS time from\n" +
+            "\t (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t0,\n" +
+            "\t (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t1,\n" +
+            "\t (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t2,\n" +
+            "\t (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t3,\n" +
+            "\t (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t4) v\n" +
+            "\twhere time between #{startTime} and #{endTime}\n" +
+            "\tORDER BY time\n" +
+            "\t) a\n" +
+            "\tLEFT JOIN \n" +
+            "\t( SELECT id,create_time,pay_money FROM pos_order_goods_payment where 1=1" +
+            "<if test='hotelId != null and hotelId !=\"\"'> and hotel_id = #{hotelId} </if>"+
+            ") b\n" +
+            "\tON a.time =date(b.create_time)\n" +
+            "GROUP BY a.time\t\n" +
+            "UNION All\n" +
+            "SELECT '客房' as type, a.time,\n" +
+            "sum(ifnull((case b.subject_type when 1 then b.money when 2 then b.money when 3 then b.money else 0 end),0)) AS room_money,\n" +
+            "sum(ifnull((case b.subject_type when 6 then b.money when 7 then b.money else 0 end),0)) AS other_money\n" +
+            "FROM (\n" +
+            "\tselect time from\n" +
+            "\t(select adddate('1970-01-01',t4.i*10000 + t3.i*1000 + t2.i*100 + t1.i*10 + t0.i) AS time from\n" +
+            "\t (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t0,\n" +
+            "\t (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t1,\n" +
+            "\t (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t2,\n" +
+            "\t (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t3,\n" +
+            "\t (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t4) v\n" +
+            "\twhere time between #{startTime} and #{endTime}\n" +
+            "\tORDER BY time\n" +
+            "\t) a\n" +
+            "\tLEFT JOIN \n" +
+            "\t( SELECT * FROM bus_order_fee where fee_type=1 and preferential_status=2" +
+            "<if test='hotelId != null and hotelId !=\"\"'> and hotel_id = #{hotelId} </if>"+
+            ") b\n" +
+            "\tON a.time =date(b.create_time)\n" +
+            "GROUP BY a.time)t\n" +
+            "group by time\t</script>")
+    public List<HashMap<String,Object>> dayShouRuStatList(@Param("hotelId") String hotelId, @Param("startTime") DateTime startTime, @Param("endTime") DateTime endTime);
+
+    /**
+     * 按时间每月收入统计列表
+     * @param hotelId
+     * @param startTime
+     * @param endTime
+     * @param months
+     * @return
+     */
+    @Select("<script>select time,sum(room_money) as room_money,sum(other_money) as other_money from \n" +
+            "(SELECT 'pos' as type, a.time\n" +
+            ",0 AS room_money,\n" +
+            "sum(ifnull(b.pay_money,0)) as other_money\n" +
+            "FROM (\n" +
+            "\tselect DATE_FORMAT(time, '%Y-%m' ) as time from\n" +
+            "\t(select adddate('${startTime}',INTERVAL  t0.i MONTH ) AS time from\n" +
+            "\t (select 0 i " +
+            "<foreach item='item' index='index' collection='months' open=' union ' separator=' union ' close=' '>"+
+            " select ${item}"+
+            "</foreach>"+
+            ") t0) v\n" +
+            "\tORDER BY time\n" +
+            "\t) a\n" +
+            "\tLEFT JOIN \n" +
+            "\t( SELECT id,create_time,pay_money FROM pos_order_goods_payment where 1=1" +
+            "<if test='hotelId != null and hotelId !=\"\"'> and hotel_id = '${hotelId}' </if>"+
+            ") b\n" +
+            "\tON a.time =DATE_FORMAT(b.create_time, '%Y-%m' )\n" +
+            "GROUP BY a.time\t\n" +
+            "UNION ALL\n" +
+            "SELECT '客房' as type, a.time,\n" +
+            "sum(ifnull((case b.subject_type when 1 then b.money when 2 then b.money when 3 then b.money else 0 end),0)) AS room_money,\n" +
+            "sum(ifnull((case b.subject_type when 6 then b.money when 7 then b.money else 0 end),0)) AS other_money\n" +
+            "FROM (\n" +
+            "\tselect DATE_FORMAT(time, '%Y-%m' ) as time from\n" +
+            "\t(select adddate('${startTime}',INTERVAL  t0.i MONTH ) AS time from\n" +
+            "\t (select 0 i " +
+            "<foreach item='item' index='index' collection='months' open=' union ' separator=' union ' close=' '>"+
+            " select ${item}"+
+            "</foreach>"+
+            ") t0) v\n" +
+            "\tORDER BY time\n" +
+            "\t) a\n" +
+            "\tLEFT JOIN \n" +
+            "\t( SELECT * FROM bus_order_fee where fee_type=1 and preferential_status=2\n" +
+            "<if test='hotelId != null and hotelId !=\"\"'> and hotel_id = '${hotelId}' </if>"+
+            "\t) b ON a.time =DATE_FORMAT(b.create_time, '%Y-%m' )\n" +
+            "GROUP BY a.time)t\n" +
+            "group by time\t</script>")
+    public List<HashMap<String,Object>> monthShouRuStatList(@Param("hotelId") String hotelId, @Param("startTime") DateTime startTime, @Param("endTime") DateTime endTime, @Param("months") List<Integer> months);
+
 }

+ 11 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/finance/service/ISummaryService.java

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import org.jeecg.modules.pos.entity.PosOrderGoodsPayment;
 
 import java.util.HashMap;
+import java.util.List;
 
 /**
  * @Description: 收款汇总统计
@@ -36,4 +37,14 @@ public interface ISummaryService extends IService<PosOrderGoodsPayment> {
      * @return
      */
     public Page<HashMap<String, Object>> financePageList(Page<HashMap<String, Object>> page, String hotelId, DateTime startTime, DateTime endTime, Integer departmentId);
+
+    /**
+     *
+     * @param hotelId 酒店id
+     * @param startTime 开始日期
+     * @param endTime 截至日期
+     * @param section 1天 2月 3季度 4年
+     * @return
+     */
+    public List<HashMap<String, Object>> dayShouRuStatList(String hotelId, DateTime startTime, DateTime endTime, Integer section);
 }

+ 32 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/finance/service/impl/SummaryServiceImpl.java

@@ -1,6 +1,7 @@
 package org.jeecg.modules.finance.service.impl;
 
 import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import org.apache.ibatis.annotations.Param;
@@ -13,6 +14,7 @@ import org.jeecg.modules.fw.mapper.FwRoomRepairMapper;
 import org.jeecg.modules.fw.service.IFwRoomRepairService;
 import org.jeecg.modules.pos.entity.PosOrderGoodsPayment;
 import org.jeecg.modules.rooms.mapper.CesRoomLayoutPriceDateMapper;
+import org.jetbrains.annotations.NotNull;
 import org.springframework.stereotype.Service;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -20,6 +22,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import javax.annotation.Resource;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.temporal.ChronoUnit;
+import java.time.temporal.Temporal;
 import java.util.*;
 
 /**
@@ -59,6 +64,7 @@ public class SummaryServiceImpl extends ServiceImpl<SummaryMapper, PosOrderGoods
 
     /**
      * 收退款明细列表
+     *
      * @param page
      * @param hotelId
      * @param startTime
@@ -76,4 +82,30 @@ public class SummaryServiceImpl extends ServiceImpl<SummaryMapper, PosOrderGoods
         }
         return page.setRecords(summaryMapper.financePage(page, hotelId, startTime, endTime));
     }
+
+
+    /**
+     * 按时间每天收入统计列表
+     *
+     * @param hotelId   酒店id
+     * @param startTime 开始日期
+     * @param endTime   截至日期
+     * @param section   1天 2月 3季度 4年
+     * @return
+     */
+    public List<HashMap<String, Object>> dayShouRuStatList(String hotelId, DateTime startTime, DateTime endTime, Integer section) {
+        if (section.equals(1)) {
+            return summaryMapper.dayShouRuStatList(hotelId, startTime, endTime);
+        } else if (section.equals(2)) {
+            ArrayList<Integer> months = new ArrayList<Integer>();
+            Temporal temporal1 =LocalDate.parse(startTime.toDateStr());
+            Temporal temporal2 =LocalDate.parse(endTime.toDateStr());
+            long sum = ChronoUnit.MONTHS.between(temporal1, temporal2);
+            for (Integer i = 1; i <= sum; i++) {
+                months.add(i);
+            }
+            return summaryMapper.monthShouRuStatList(hotelId, startTime, endTime, months);
+        }
+        return null;
+    }
 }