数据统计

This commit is contained in:
wangh 2023-12-19 16:54:02 +08:00
parent b4cdb77bdf
commit 79a9d8e47e
7 changed files with 66 additions and 53 deletions

View File

@ -358,28 +358,28 @@
<select id="fuelStream" resultType="java.util.Map">
SELECT
-- 当天的数据和条数
CAST((SELECT COUNT(*) FROM oil_order WHERE DATE(create_time) = CURDATE()) AS CHAR) AS today_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE DATE(create_time) = CURDATE()) AS CHAR) AS today_sum,
CAST((SELECT COUNT(*) FROM oil_order WHERE DATE(create_time) = CURDATE()and store_id = #{storeId}) AS CHAR) AS today_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE DATE(create_time) = CURDATE()and store_id = #{storeId}) AS CHAR) AS today_sum,
-- 当周的数据和条数
CAST((SELECT COUNT(*) FROM oil_order WHERE WEEK(create_time) = WEEK(CURDATE())) AS CHAR) AS this_week_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE WEEK(create_time) = WEEK(CURDATE())) AS CHAR) AS this_week_sum,
CAST((SELECT COUNT(*) FROM oil_order WHERE WEEK(create_time) = WEEK(CURDATE())and store_id = #{storeId}) AS CHAR) AS this_week_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE WEEK(create_time) = WEEK(CURDATE())and store_id = #{storeId}) AS CHAR) AS this_week_sum,
-- 当月的数据和条数
CAST((SELECT COUNT(*) FROM oil_order WHERE MONTH(create_time) = MONTH(CURDATE())) AS CHAR) AS this_month_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE MONTH(create_time) = MONTH(CURDATE())) AS CHAR) AS this_month_sum,
CAST((SELECT COUNT(*) FROM oil_order WHERE MONTH(create_time) = MONTH(CURDATE())and store_id = #{storeId}) AS CHAR) AS this_month_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE MONTH(create_time) = MONTH(CURDATE())and store_id = #{storeId}) AS CHAR) AS this_month_sum,
-- 昨天的数据
CAST((SELECT COUNT(*) FROM oil_order WHERE DATE(create_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)) AS CHAR) AS yesterday_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE DATE(create_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)) AS CHAR) AS yesterday_sum,
CAST((SELECT COUNT(*) FROM oil_order WHERE DATE(create_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)and store_id = #{storeId}) AS CHAR) AS yesterday_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE DATE(create_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)and store_id = #{storeId}) AS CHAR) AS yesterday_sum,
-- 上周的数据
CAST((SELECT COUNT(*) FROM oil_order WHERE WEEK(create_time) = WEEK(DATE_SUB(CURDATE(), INTERVAL 1 WEEK))) AS CHAR) AS last_week_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE WEEK(create_time) = WEEK(DATE_SUB(CURDATE(), INTERVAL 1 WEEK))) AS CHAR) AS last_week_sum,
CAST((SELECT COUNT(*) FROM oil_order WHERE WEEK(create_time) = WEEK(DATE_SUB(CURDATE(), INTERVAL 1 WEEK))and store_id = #{storeId}) AS CHAR) AS last_week_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE WEEK(create_time) = WEEK(DATE_SUB(CURDATE(), INTERVAL 1 WEEK))and store_id = #{storeId}) AS CHAR) AS last_week_sum,
-- 上个月的数据
CAST((SELECT COUNT(*) FROM oil_order WHERE MONTH(create_time) = MONTH(DATE_SUB(CURDATE(), INTERVAL 1 MONTH))) AS CHAR) AS last_month_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE MONTH(create_time) = MONTH(DATE_SUB(CURDATE(), INTERVAL 1 MONTH))) AS CHAR) AS last_month_sum;
CAST((SELECT COUNT(*) FROM oil_order WHERE MONTH(create_time) = MONTH(DATE_SUB(CURDATE(), INTERVAL 1 MONTH))and store_id = #{storeId}) AS CHAR) AS last_month_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE MONTH(create_time) = MONTH(DATE_SUB(CURDATE(), INTERVAL 1 MONTH))and store_id = #{storeId}) AS CHAR) AS last_month_sum;
</select>
<select id="queryByPageApplet"

View File

@ -126,28 +126,28 @@
<select id="cardStream" resultType="java.util.Map">
SELECT
-- 当天的数据和条数
CAST((SELECT COUNT(*) FROM oil_order WHERE DATE(create_time) = CURDATE()) AS CHAR) AS today_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE DATE(create_time) = CURDATE()) AS CHAR) AS today_sum,
CAST((SELECT COUNT(*) FROM oil_order WHERE DATE(create_time) = CURDATE() and store_id = #{storeId}) AS CHAR) AS today_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE DATE(create_time) = CURDATE()and store_id = #{storeId}) AS CHAR) AS today_sum,
-- 当周的数据和条数
CAST((SELECT COUNT(*) FROM oil_order WHERE WEEK(create_time) = WEEK(CURDATE())) AS CHAR) AS this_week_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE WEEK(create_time) = WEEK(CURDATE())) AS CHAR) AS this_week_sum,
CAST((SELECT COUNT(*) FROM oil_order WHERE WEEK(create_time) = WEEK(CURDATE())and store_id = #{storeId}) AS CHAR) AS this_week_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE WEEK(create_time) = WEEK(CURDATE())and store_id = #{storeId}) AS CHAR) AS this_week_sum,
-- 当月的数据和条数
CAST((SELECT COUNT(*) FROM oil_order WHERE MONTH(create_time) = MONTH(CURDATE())) AS CHAR) AS this_month_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE MONTH(create_time) = MONTH(CURDATE())) AS CHAR) AS this_month_sum,
CAST((SELECT COUNT(*) FROM oil_order WHERE MONTH(create_time) = MONTH(CURDATE())and store_id = #{storeId}) AS CHAR) AS this_month_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE MONTH(create_time) = MONTH(CURDATE())and store_id = #{storeId}) AS CHAR) AS this_month_sum,
-- 昨天的数据
CAST((SELECT COUNT(*) FROM oil_order WHERE DATE(create_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)) AS CHAR) AS yesterday_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE DATE(create_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)) AS CHAR) AS yesterday_sum,
CAST((SELECT COUNT(*) FROM oil_order WHERE DATE(create_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)and store_id = #{storeId}) AS CHAR) AS yesterday_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE DATE(create_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)and store_id = #{storeId}) AS CHAR) AS yesterday_sum,
-- 上周的数据
CAST((SELECT COUNT(*) FROM oil_order WHERE WEEK(create_time) = WEEK(DATE_SUB(CURDATE(), INTERVAL 1 WEEK))) AS CHAR) AS last_week_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE WEEK(create_time) = WEEK(DATE_SUB(CURDATE(), INTERVAL 1 WEEK))) AS CHAR) AS last_week_sum,
CAST((SELECT COUNT(*) FROM oil_order WHERE WEEK(create_time) = WEEK(DATE_SUB(CURDATE(), INTERVAL 1 WEEK))and store_id = #{storeId}) AS CHAR) AS last_week_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE WEEK(create_time) = WEEK(DATE_SUB(CURDATE(), INTERVAL 1 WEEK))and store_id = #{storeId}) AS CHAR) AS last_week_sum,
-- 上个月的数据
CAST((SELECT COUNT(*) FROM oil_order WHERE MONTH(create_time) = MONTH(DATE_SUB(CURDATE(), INTERVAL 1 MONTH))) AS CHAR) AS last_month_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE MONTH(create_time) = MONTH(DATE_SUB(CURDATE(), INTERVAL 1 MONTH))) AS CHAR) AS last_month_sum;
CAST((SELECT COUNT(*) FROM oil_order WHERE MONTH(create_time) = MONTH(DATE_SUB(CURDATE(), INTERVAL 1 MONTH))and store_id = #{storeId}) AS CHAR) AS last_month_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE MONTH(create_time) = MONTH(DATE_SUB(CURDATE(), INTERVAL 1 MONTH))and store_id = #{storeId}) AS CHAR) AS last_month_sum;
</select>
<select id="prepaidCardSales" resultType="java.util.Map">

View File

@ -52,6 +52,7 @@
LEFT JOIN oil_order oo ON ms.id = oo.staff_id
LEFT JOIN card_value_record cvr ON ms.id = cvr.mt_staff_id
LEFT JOIN card_fuel_record cfr ON ms.id = cfr.mt_staff_id
where ms.store_id = #{storeId}
GROUP BY
ms.id, ms.real_name
ORDER BY

View File

@ -97,28 +97,28 @@
<select id="goodsStream" resultType="java.util.Map">
SELECT
-- 当天的数据和条数
CAST((SELECT COUNT(*) FROM oil_order WHERE DATE(create_time) = CURDATE()) AS CHAR) AS today_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE DATE(create_time) = CURDATE()) AS CHAR) AS today_sum,
CAST((SELECT COUNT(*) FROM oil_order WHERE DATE(create_time) = CURDATE()and store_id = #{storeId}) AS CHAR) AS today_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE DATE(create_time) = CURDATE()and store_id = #{storeId}) AS CHAR) AS today_sum,
-- 当周的数据和条数
CAST((SELECT COUNT(*) FROM oil_order WHERE WEEK(create_time) = WEEK(CURDATE())) AS CHAR) AS this_week_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE WEEK(create_time) = WEEK(CURDATE())) AS CHAR) AS this_week_sum,
CAST((SELECT COUNT(*) FROM oil_order WHERE WEEK(create_time) = WEEK(CURDATE())and store_id = #{storeId}) AS CHAR) AS this_week_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE WEEK(create_time) = WEEK(CURDATE())and store_id = #{storeId}) AS CHAR) AS this_week_sum,
-- 当月的数据和条数
CAST((SELECT COUNT(*) FROM oil_order WHERE MONTH(create_time) = MONTH(CURDATE())) AS CHAR) AS this_month_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE MONTH(create_time) = MONTH(CURDATE())) AS CHAR) AS this_month_sum,
CAST((SELECT COUNT(*) FROM oil_order WHERE MONTH(create_time) = MONTH(CURDATE())and store_id = #{storeId}) AS CHAR) AS this_month_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE MONTH(create_time) = MONTH(CURDATE())and store_id = #{storeId}) AS CHAR) AS this_month_sum,
-- 昨天的数据
CAST((SELECT COUNT(*) FROM oil_order WHERE DATE(create_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)) AS CHAR) AS yesterday_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE DATE(create_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)) AS CHAR) AS yesterday_sum,
CAST((SELECT COUNT(*) FROM oil_order WHERE DATE(create_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)and store_id = #{storeId}) AS CHAR) AS yesterday_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE DATE(create_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)and store_id = #{storeId}) AS CHAR) AS yesterday_sum,
-- 上周的数据
CAST((SELECT COUNT(*) FROM oil_order WHERE WEEK(create_time) = WEEK(DATE_SUB(CURDATE(), INTERVAL 1 WEEK))) AS CHAR) AS last_week_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE WEEK(create_time) = WEEK(DATE_SUB(CURDATE(), INTERVAL 1 WEEK))) AS CHAR) AS last_week_sum,
CAST((SELECT COUNT(*) FROM oil_order WHERE WEEK(create_time) = WEEK(DATE_SUB(CURDATE(), INTERVAL 1 WEEK))and store_id = #{storeId}) AS CHAR) AS last_week_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE WEEK(create_time) = WEEK(DATE_SUB(CURDATE(), INTERVAL 1 WEEK))and store_id = #{storeId}) AS CHAR) AS last_week_sum,
-- 上个月的数据
CAST((SELECT COUNT(*) FROM oil_order WHERE MONTH(create_time) = MONTH(DATE_SUB(CURDATE(), INTERVAL 1 MONTH))) AS CHAR) AS last_month_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE MONTH(create_time) = MONTH(DATE_SUB(CURDATE(), INTERVAL 1 MONTH))) AS CHAR) AS last_month_sum;
CAST((SELECT COUNT(*) FROM oil_order WHERE MONTH(create_time) = MONTH(DATE_SUB(CURDATE(), INTERVAL 1 MONTH))and store_id = #{storeId}) AS CHAR) AS last_month_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE MONTH(create_time) = MONTH(DATE_SUB(CURDATE(), INTERVAL 1 MONTH))and store_id = #{storeId}) AS CHAR) AS last_month_sum;
</select>
<select id="merchandiseSales" resultType="java.util.Map">
@ -135,9 +135,11 @@
LEFT JOIN
mt_order ON DATE(mt_order.create_time) = date_range.date
WHERE
date_range.date BETWEEN CURDATE() - INTERVAL 30 DAY AND CURDATE()
(date_range.date BETWEEN CURDATE() - INTERVAL 30 DAY AND CURDATE())
GROUP BY
date_range.date
ORDER BY
date_range.date;
</select>

View File

@ -166,28 +166,28 @@
SELECT
-- 当天的数据和条数
CAST((SELECT COUNT(*) FROM oil_order WHERE DATE(create_time) = CURDATE()) AS CHAR) AS today_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE DATE(create_time) = CURDATE()) AS CHAR) AS today_sum,
CAST((SELECT COUNT(*) FROM oil_order WHERE DATE(create_time) = CURDATE() and store_id = #{storeId}) AS CHAR) AS today_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE DATE(create_time) = CURDATE() and store_id = #{storeId}) AS CHAR) AS today_sum,
-- 当周的数据和条数
CAST((SELECT COUNT(*) FROM oil_order WHERE WEEK(create_time) = WEEK(CURDATE())) AS CHAR) AS this_week_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE WEEK(create_time) = WEEK(CURDATE())) AS CHAR) AS this_week_sum,
CAST((SELECT COUNT(*) FROM oil_order WHERE WEEK(create_time) = WEEK(CURDATE()) and store_id = #{storeId} ) AS CHAR) AS this_week_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE WEEK(create_time) = WEEK(CURDATE())and store_id = #{storeId}) AS CHAR) AS this_week_sum,
-- 当月的数据和条数
CAST((SELECT COUNT(*) FROM oil_order WHERE MONTH(create_time) = MONTH(CURDATE())) AS CHAR) AS this_month_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE MONTH(create_time) = MONTH(CURDATE())) AS CHAR) AS this_month_sum,
CAST((SELECT COUNT(*) FROM oil_order WHERE MONTH(create_time) = MONTH(CURDATE())and store_id = #{storeId}) AS CHAR) AS this_month_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE MONTH(create_time) = MONTH(CURDATE())and store_id = #{storeId}) AS CHAR) AS this_month_sum,
-- 昨天的数据
CAST((SELECT COUNT(*) FROM oil_order WHERE DATE(create_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)) AS CHAR) AS yesterday_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE DATE(create_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)) AS CHAR) AS yesterday_sum,
CAST((SELECT COUNT(*) FROM oil_order WHERE DATE(create_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)and store_id = #{storeId}) AS CHAR) AS yesterday_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE DATE(create_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)and store_id = #{storeId}) AS CHAR) AS yesterday_sum,
-- 上周的数据
CAST((SELECT COUNT(*) FROM oil_order WHERE WEEK(create_time) = WEEK(DATE_SUB(CURDATE(), INTERVAL 1 WEEK))) AS CHAR) AS last_week_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE WEEK(create_time) = WEEK(DATE_SUB(CURDATE(), INTERVAL 1 WEEK))) AS CHAR) AS last_week_sum,
CAST((SELECT COUNT(*) FROM oil_order WHERE WEEK(create_time) = WEEK(DATE_SUB(CURDATE(), INTERVAL 1 WEEK))and store_id = #{storeId}) AS CHAR) AS last_week_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE WEEK(create_time) = WEEK(DATE_SUB(CURDATE(), INTERVAL 1 WEEK))and store_id = #{storeId}) AS CHAR) AS last_week_sum,
-- 上个月的数据
CAST((SELECT COUNT(*) FROM oil_order WHERE MONTH(create_time) = MONTH(DATE_SUB(CURDATE(), INTERVAL 1 MONTH))) AS CHAR) AS last_month_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE MONTH(create_time) = MONTH(DATE_SUB(CURDATE(), INTERVAL 1 MONTH))) AS CHAR) AS last_month_sum;
CAST((SELECT COUNT(*) FROM oil_order WHERE MONTH(create_time) = MONTH(DATE_SUB(CURDATE(), INTERVAL 1 MONTH))and store_id = #{storeId}) AS CHAR) AS last_month_count,
CAST((SELECT SUM(pay_amount) FROM oil_order WHERE MONTH(create_time) = MONTH(DATE_SUB(CURDATE(), INTERVAL 1 MONTH))and store_id = #{storeId}) AS CHAR) AS last_month_sum;
</select>
<select id="oilSales" resultType="java.util.Map">
@ -204,13 +204,16 @@
LEFT JOIN
oil_order ON DATE(oil_order.create_time) = date_range.date
WHERE
date_range.date BETWEEN CURDATE() - INTERVAL 30 DAY AND CURDATE()
store_id = #{storeId}
and
(date_range.date BETWEEN CURDATE() - INTERVAL 30 DAY AND CURDATE())
GROUP BY
date_range.date
ORDER BY
date_range.date;
</select>
<!-- COUNT(*) AS count-->
<!-- &#45;&#45; and store_id = #{storeId}-->
<select id="salesByOilProduct" resultType="java.util.Map">
SELECT
@ -232,6 +235,7 @@
oil_order oo
left join oil_name onn on onn.id = oo.oils
WHERE
<if test="type == 'week'">
oo.create_time >= CURDATE() - INTERVAL 6 WEEK
</if>
@ -241,6 +245,7 @@
<if test="type == 'year'">
oo.create_time >= CURDATE() - INTERVAL 6 YEAR
</if>
and store_id = #{storeId}
GROUP BY
YEAR(oo.create_time)
<if test="type == 'week'">

View File

@ -25,6 +25,7 @@ public class ChainStoreInfo extends BaseEntity {
private Integer id;
//连锁店名称
private String storeName;
private String status;
private Long contractDeptId;
@TableField(exist = false)
private String leaderName;

View File

@ -1,5 +1,6 @@
package com.fuint.business.store.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -42,6 +43,9 @@ public class ChainStoreInfoServiceImpl extends ServiceImpl<ChainStoreInfoMapper,
IPage<ChainStoreInfo> res = baseMapper.listVo(page,chainStoreInfo,sysDept.getAncestors());
res.getRecords().forEach(it->{
LambdaQueryWrapper<MtStore> queryWrapper =new LambdaQueryWrapper<>();
if (ObjectUtil.isNotEmpty(chainStoreInfo.getStatus())) {
queryWrapper.eq(MtStore :: getStatus,chainStoreInfo.getStatus());
}
queryWrapper.eq(MtStore::getChainStoreId,it.getId()).orderByDesc(BaseEntity::getCreateTime);
List<MtStore> list = storeService.list(queryWrapper);
it.setStoreList(list);