报表功能查看

This commit is contained in:
lizhenhua 2025-09-05 10:04:37 +08:00
parent 5cadd2e17d
commit 98d2cf5f3b
3 changed files with 841 additions and 54 deletions

View File

@ -1,20 +1,17 @@
package com.bonus.canteen.core.reportforms.controller;
import com.bonus.canteen.core.reportforms.beans.CanteenOrg;
import com.bonus.canteen.core.reportforms.beans.CanteenRecord;
import com.bonus.canteen.core.reportforms.beans.OrgConsume;
import com.bonus.canteen.core.reportforms.service.reportformsService;
import com.bonus.common.core.utils.poi.ExcelUtil;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.page.TableDataInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import static com.bonus.common.core.utils.PageUtils.startPage;
@RestController
@RequestMapping({"/api/v2/report"})
public class reportformsController extends BaseController {
@ -33,6 +30,34 @@ public class reportformsController extends BaseController {
List<CanteenRecord> peoplelist = service.getPeoplelist(orgConsume);
return getDataTable(peoplelist);
}
/**
* 人员报表查询导出功能
* @param orgConsume
* @return
*/
@PostMapping("/consume/exportExcel")
public void exportExcel(HttpServletResponse response, CanteenRecord orgConsume) {
// 1. 查询数据
List<CanteenRecord> peoplelist = service.getPeoplelist(orgConsume);
// 2. flowTypeText 赋值
for (CanteenRecord record : peoplelist) {
//获取的金额除以100
record.setAmount(record.getAmount()/100);
if ("110".equals(record.getFlowType())) {
record.setFlowTypeText("消费");
} else if ("120".equals(record.getFlowType())) {
record.setFlowTypeText("补助");
} else if ("130".equals(record.getFlowType())) {
record.setFlowTypeText("退款");
} else {
record.setFlowTypeText(record.getFlowType());
}
}
// 3. 导出 Excel
ExcelUtil<CanteenRecord> util = new ExcelUtil<>(CanteenRecord.class);
util.exportExcel(response, peoplelist, "人员导出数据详情");
}
/**
* 食堂预订餐接口查询
* 通过区域名称查询
@ -40,46 +65,6 @@ public class reportformsController extends BaseController {
* @return
*/
@PostMapping("/consume/listByArea")
/*public List<OrgConsume> listByArea(@RequestBody OrgConsume orgConsume) {
//区域
String orgName = orgConsume.getOrgName();
// 去掉里面的食堂字样
if (orgName != null) {
orgName = orgName.replace("食堂", "");
orgConsume.setOrgName(orgName);
}
if(orgConsume.getConSource() == 1){
if ("运检后勤".equals(orgName)) {
orgName = "运检分公司";
orgConsume.setOrgName(orgName);
}
return service.getlistByH5list(orgConsume);
} else if (orgConsume.getConSource() == 3) {
//如果是送变电工业园食堂 修改成sbd工业园
if ("送变电工业园".equals(orgName)) {
orgName = "sbd工业园";
orgConsume.setOrgName(orgName);
}
return service.getlistByArealist(orgConsume);
} else if (orgConsume.getConSource() ==4 ) {
if ("送变电工业园".equals(orgName)) {
orgName = "sbd工业园";
orgConsume.setOrgName(orgName);
}
return service.getlistBySuperlist(orgConsume);
}else if (orgConsume.getConSource() ==5){
if ("送变电工业园".equals(orgName)) {
orgName = "sbd工业园";
orgConsume.setOrgName(orgName);
return service.getDeductionlist(orgConsume);
}
}
else if (orgConsume.getConSource() ==2 ) {
//驿站消费
return service.getlistByOtherlist(orgConsume);
}
return null;
}*/
public List<OrgConsume> listByArea(@RequestBody OrgConsume orgConsume) {
String orgName = orgConsume.getOrgName();
Integer conSource = orgConsume.getConSource();

View File

@ -20,11 +20,24 @@ public class reportformsServiceImpl implements reportformsService {
private OrgConsumeMapper mapper;
@Override
public List<OrgConsume> getOrgConsumeList(OrgConsume orgConsume) {
// 查询食堂超市的所有数据信息
// 查询食堂超市消费补扣的所有数据信息
List<Map<String, Object>> consumeRecords = mapper.selectConsumeRecords(orgConsume);
//查询预订的订单信息
List<Map<String, Object>> reserveRecords = mapper.selectReserveRecords(orgConsume);
//查询区域关联的字段信息
// 查询预定的订单信息
List<Map<String, Object>> reserveRecords = mapper.selectReserveRecords(orgConsume);
// 判断是否包含指定的食堂假设指定食堂的名称为 '宏源工业园食堂'
boolean containsCanteen = reserveRecords.stream()
.anyMatch(record -> "宏源工业园食堂".equals(record.get("orgName")));
// 如果没有找到食堂重新查询并赋值
if (!containsCanteen) {
List<Map<String, Object>> newReserveRecords = mapper.selectReserveRecordsFromDatabase(orgConsume);
// 插入新的记录到原有的数据列表
reserveRecords.addAll(newReserveRecords); // 保证格式一致直接合并
}
//针对特殊食堂退款的问题进行处理专门写一个方法
//查询区域关联的字段信息
List<Map<String, String>> areaOrgMaps = mapper.selectAreaOrgMap();
// area -> org 映射
@ -78,9 +91,6 @@ public class reportformsServiceImpl implements reportformsService {
}
resultMap.put(orgName, oc);
}
//处理驿站退款情况逻辑
// int yzsum = mapper.yzSumMoney(orgConsume);
return new ArrayList<>(resultMap.values());
}
@ -135,14 +145,24 @@ public class reportformsServiceImpl implements reportformsService {
}
@Override
public List<OrgConsume> getlistByH5list(OrgConsume orgConsume) {
List<OrgConsume> orgConsumes = mapper.getlistByH5list(orgConsume)
if ("宏源工业园".equals(orgConsume.getOrgName())) {
// "宏源工业园" 使用专门的查询逻辑
return getListForH5Special(orgConsume);
} else {
// 使用原有的查询逻辑
return getListByH5list(orgConsume);
}
}
private List<OrgConsume> getListForH5Special(OrgConsume orgConsume) {
// 专门处理 "宏源工业园" 的查询逻辑
List<OrgConsume> orgConsumes = mapper.getlistForH5Special(orgConsume)
.stream()
.peek(c -> {
if (c.getCustName() != null && !c.getCustName().isEmpty()) {
try {
c.setCustName(SM4EncryptUtils.sm4Decrypt(c.getCustName()));
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace();
}
}
})
@ -150,6 +170,22 @@ public class reportformsServiceImpl implements reportformsService {
return orgConsumes;
}
private List<OrgConsume> getListByH5list(OrgConsume orgConsume) {
// 使用原有的查询逻辑
List<OrgConsume> orgConsumes = mapper.getlistByH5list(orgConsume)
.stream()
.peek(c -> {
if (c.getCustName() != null && !c.getCustName().isEmpty()) {
try {
c.setCustName(SM4EncryptUtils.sm4Decrypt(c.getCustName()));
} catch (Exception e) {
e.printStackTrace();
}
}
})
.collect(Collectors.toList());
return orgConsumes;
}
@Override
public List<OrgConsume> getlistByOtherlist(OrgConsume orgConsume) {
List<OrgConsume> orgConsumes = mapper.getlistByOtherlist(orgConsume)

View File

@ -0,0 +1,766 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.bonus.canteen.core.reportforms.mapper.OrgConsumeMapper">
<select id="selectConsumeRecords" resultType="java.util.Map">
SELECT
t.area_name AS areaName,
CASE
WHEN t.flow_type = 120 THEN 'deduction'
WHEN t.source_type = 7 THEN 'H5'
WHEN t.source_type = 53 THEN 'super'
WHEN (t.source_type IS NULL OR t.source_type = '' OR t.source_type = 0) AND t.remark LIKE '%支付%' THEN 'station'
ELSE 'canteen'
END AS conSource,
ROUND(SUM(t.flow_real_amount) / 100, 2) AS amount
FROM
(
-- 第一段正常消费flow_type = 110
SELECT DISTINCT
aa.canteen_name,
aac.area_name,
f.source_type,
f.remark,
f.flow_id,
f.flow_real_amount,
f.flow_type,
f.ord_time
FROM report_account_flow f
LEFT JOIN device_info di ON f.mch_sn = di.device_sn
LEFT JOIN device_bind bd ON di.device_id = bd.device_id
LEFT JOIN alloc_canteen aa ON aa.canteen_id = bd.canteen_id
LEFT JOIN alloc_area aac ON aac.area_id = aa.area_id
WHERE 1 = 1
<if test="startPayTime != null">
AND f.pay_time &gt;= #{startPayTime}
</if>
<if test="endPayTime != null">
AND f.pay_time &lt; #{endPayTime}
</if>
AND f.flow_type = 110
UNION ALL
-- 第二段补充没有设备号的消费flow_type = 130
SELECT
bo.canteen_name,
bo.area_name,
f.source_type,
f.remark,
f.flow_id,
f.flow_real_amount,
f.flow_type,
f.ord_time
FROM report_account_flow f
INNER JOIN (
SELECT
aa.canteen_name,
aac.area_name,
f.ord_time
FROM report_account_flow f
LEFT JOIN device_info di ON f.mch_sn = di.device_sn
LEFT JOIN device_bind bd ON di.device_id = bd.device_id
LEFT JOIN alloc_canteen aa ON aa.canteen_id = bd.canteen_id
LEFT JOIN alloc_area aac ON aac.area_id = aa.area_id
WHERE 1 = 1
<if test="startPayTime != null">
AND f.pay_time &gt;= #{startPayTime}
</if>
<if test="endPayTime != null">
AND f.pay_time &lt; #{endPayTime}
</if>
AND f.flow_type = 110
) bo ON f.ord_time = bo.ord_time
WHERE 1 = 1
<if test="startPayTime != null">
AND f.pay_time &gt;= #{startPayTime}
</if>
<if test="endPayTime != null">
AND f.pay_time &lt; #{endPayTime}
</if>
AND f.flow_type = 130
AND (f.mch_sn IS NULL OR f.mch_sn = '')
UNION ALL
-- 第三段补扣金额flow_type = 120
SELECT
aa.canteen_name,
aac.area_name,
f.source_type,
f.remark,
f.flow_id,
f.flow_real_amount,
f.flow_type,
f.ord_time
FROM report_account_flow f
LEFT JOIN device_info di ON f.mch_sn = di.device_sn
LEFT JOIN device_bind bd ON di.device_id = bd.device_id
LEFT JOIN alloc_canteen aa ON aa.canteen_id = bd.canteen_id
LEFT JOIN alloc_area aac ON aac.area_id = aa.area_id
WHERE 1 = 1
<if test="startPayTime != null">
AND f.pay_time &gt;= #{startPayTime}
</if>
<if test="endPayTime != null">
AND f.pay_time &lt; #{endPayTime}
</if>
AND f.flow_type = 120
) t
GROUP BY
t.area_name,
CASE
WHEN t.flow_type = 120 THEN 'deduction'
WHEN t.source_type = 7 THEN 'H5'
WHEN t.source_type = 53 THEN 'super'
WHEN (t.source_type IS NULL OR t.source_type = '' OR t.source_type = 0) AND t.remark LIKE '%支付%' THEN 'station'
ELSE 'canteen'
END
ORDER BY
t.area_name
</select>
<select id="selectReserveRecords" resultType="java.util.Map">
WITH org_hierarchy AS (
SELECT
co.org_id,
co.org_name
FROM cust_org co
WHERE
(co.org_level = 2 AND co.if_del = 2 AND co.org_id != 456365640698040320)
OR (co.super_id = 456365640698040320 AND co.if_del = 2)
),
normal_transactions AS (
SELECT
f.org_id,
f.flow_real_amount AS amount
FROM report_account_flow f
WHERE f.pay_time &gt;= #{startPayTime}
AND f.pay_time &lt;= #{endPayTime}
AND f.flow_type = 110
AND f.source_type = 7
),
refund_transactions AS (
SELECT
f.org_id,
at.actual_amount AS amount
FROM acc_trade at
INNER JOIN report_account_flow f
ON at.origin_trade_id = f.flow_id
AND f.flow_type = 110
AND f.source_type = 7
WHERE at.trade_time &gt;= #{startPayTime}
AND at.trade_time &lt;= #{endPayTime}
AND at.trade_type = 130
AND at.trade_state = 2
AND (at.machine_sn IS NULL OR at.machine_sn = '')
),
combined_transactions AS (
SELECT org_id, amount FROM normal_transactions
UNION ALL
SELECT org_id, amount FROM refund_transactions
)
SELECT
oh.org_name AS orgName,
ROUND(COALESCE(SUM(ct.amount), 0) / 100, 2) AS reserveAmount
FROM org_hierarchy oh
LEFT JOIN cust_org c
ON c.if_del = 2
AND (c.org_id = oh.org_id OR c.org_full_id LIKE CONCAT('%/', oh.org_id, '/%'))
LEFT JOIN combined_transactions ct
ON c.org_id = ct.org_id
WHERE 1=1
<if test="orgName != null and orgName != ''">
AND oh.org_name LIKE CONCAT('%', #{orgName}, '%')
</if>
GROUP BY oh.org_id, oh.org_name
HAVING COALESCE(SUM(ct.amount), 0) != 0
ORDER BY oh.org_id
</select>
<select id="selectAreaOrgMap" resultType="java.util.Map">
SELECT area_name, org_name FROM area_org_map
</select>
<select id="getlistByArealist" resultType="com.bonus.canteen.core.reportforms.beans.OrgConsume">
SELECT distinct
co.org_full_name as orgFullName,
t.remark,
u.cust_name,
u.cust_name_like,
t.canteen_name,
t.area_name,
t.consume_source,
t.flow_id,
t.flow_type,
CASE
WHEN t.flow_type = 110 THEN '消费'
WHEN t.flow_type = 130 THEN '退款'
ELSE '其他'
END AS flow_type_name,
t.flow_real_amount / 100 AS amount,
t.ord_time,
t.pay_time
FROM
(
SELECT
aa.canteen_name,
aac.area_name,
CASE
WHEN f.source_type = 7 THEN 'H5'
WHEN f.source_type = 53 THEN 'super'
ELSE 'canteen'
END AS consume_source,
f.flow_id,
d.flow_type,
f.flow_real_amount,
f.ord_time,
d.pay_time,
f.cust_id,
f.remark
FROM report_account_flow f
INNER JOIN report_account_flow_detail d ON f.flow_id = d.flow_id
INNER JOIN device_info di ON f.mch_sn = di.device_sn
INNER JOIN device_bind bd ON di.device_id = bd.device_id
INNER JOIN alloc_canteen aa ON aa.canteen_id = bd.canteen_id
INNER JOIN alloc_area aac ON aac.area_id = aa.area_id
WHERE 1=1
<if test="startPayTime != null">
AND d.pay_time &gt;= #{startPayTime}
</if>
<if test="endPayTime != null">
AND d.pay_time &lt; #{endPayTime}
</if>
AND d.flow_type = 110
AND (f.source_type NOT IN (7, 53) OR f.source_type IS NULL)
UNION ALL
SELECT
bo.canteen_name,
bo.area_name,
bo.consume_source,
f.flow_id,
d.flow_type,
f.flow_real_amount,
f.ord_time,
d.pay_time,
f.cust_id,
f.remark
FROM report_account_flow f
INNER JOIN report_account_flow_detail d ON f.flow_id = d.flow_id
INNER JOIN (
SELECT
aa.canteen_name,
aac.area_name,
CASE
WHEN f.source_type = 7 THEN 'H5'
WHEN f.source_type = 53 THEN 'super'
ELSE 'canteen'
END AS consume_source,
f.ord_time
FROM report_account_flow f
INNER JOIN report_account_flow_detail d ON f.flow_id = d.flow_id
INNER JOIN device_info di ON f.mch_sn = di.device_sn
INNER JOIN device_bind bd ON di.device_id = bd.device_id
INNER JOIN alloc_canteen aa ON aa.canteen_id = bd.canteen_id
INNER JOIN alloc_area aac ON aac.area_id = aa.area_id
WHERE 1=1
<if test="startPayTime != null">
AND d.pay_time &gt;= #{startPayTime}
</if>
<if test="endPayTime != null">
AND d.pay_time &lt; #{endPayTime}
</if>
AND d.flow_type = 110
) bo ON f.ord_time = bo.ord_time
WHERE 1=1
<if test="startPayTime != null">
AND d.pay_time &gt;= #{startPayTime}
</if>
<if test="endPayTime != null">
AND d.pay_time &lt; #{endPayTime}
</if>
AND d.flow_type = 130
AND (f.mch_sn IS NULL OR f.mch_sn = '')
) t
LEFT JOIN cust_info u ON t.cust_id = u.cust_id
LEFT JOIN cust_org co ON u.org_id = co.org_id
WHERE 1=1
AND t.area_name LIKE CONCAT('%', #{orgName}, '%')
ORDER BY t.pay_time DESC
</select>
<select id="getlistBySuperlist" resultType="com.bonus.canteen.core.reportforms.beans.OrgConsume">
SELECT DISTINCT
co.org_full_name as orgFullName,
u.cust_name,
u.cust_name_like,
t.canteen_name,
t.area_name,
t.consume_source,
t.flow_id,
t.flow_type,
CASE
WHEN t.flow_type = 110 THEN '消费'
WHEN t.flow_type = 130 THEN '退款'
ELSE '其他'
END AS flow_type_name,
t.flow_real_amount / 100 AS amount,
t.ord_time,
t.pay_time
FROM
(
SELECT
aa.canteen_name,
aac.area_name,
'super' AS consume_source,
f.flow_id,
d.flow_type,
f.flow_real_amount,
f.ord_time,
d.pay_time,
f.cust_id
FROM report_account_flow f
INNER JOIN report_account_flow_detail d ON f.flow_id = d.flow_id
INNER JOIN device_info di ON f.mch_sn = di.device_sn
INNER JOIN device_bind bd ON di.device_id = bd.device_id
INNER JOIN alloc_canteen aa ON aa.canteen_id = bd.canteen_id
INNER JOIN alloc_area aac ON aac.area_id = aa.area_id
WHERE d.pay_time &gt;= #{startPayTime}
AND d.pay_time &lt; #{endPayTime}
AND d.flow_type = 110
AND f.source_type = 53
UNION ALL
SELECT
bo.canteen_name,
bo.area_name,
bo.consume_source,
f.flow_id,
d.flow_type,
f.flow_real_amount,
f.ord_time,
d.pay_time,
f.cust_id
FROM report_account_flow f
INNER JOIN report_account_flow_detail d ON f.flow_id = d.flow_id
INNER JOIN (
SELECT
aa.canteen_name,
aac.area_name,
'super' AS consume_source,
f.ord_time
FROM report_account_flow f
INNER JOIN report_account_flow_detail d ON f.flow_id = d.flow_id
INNER JOIN device_info di ON f.mch_sn = di.device_sn
INNER JOIN device_bind bd ON di.device_id = bd.device_id
INNER JOIN alloc_canteen aa ON aa.canteen_id = bd.canteen_id
INNER JOIN alloc_area aac ON aac.area_id = aa.area_id
WHERE d.pay_time &gt;= #{startPayTime}
AND d.pay_time &lt; #{endPayTime}
AND d.flow_type = 110
AND f.source_type = 53
) bo ON f.ord_time = bo.ord_time
WHERE d.pay_time &gt;= #{startPayTime}
AND d.pay_time &lt; #{endPayTime}
AND d.flow_type = 130
AND (f.mch_sn IS NULL OR f.mch_sn = '')
) t
LEFT JOIN cust_info u ON t.cust_id = u.cust_id
LEFT JOIN cust_org co ON u.org_id = co.org_id
WHERE t.area_name = #{orgName}
ORDER BY t.pay_time DESC
</select>
<!--目前这个sql展示的是食堂sql-->
<select id="getlistByH5list" resultType="com.bonus.canteen.core.reportforms.beans.OrgConsume">
SELECT
co2.org_full_name AS orgFullName,
co2.org_name AS orgName,
u.cust_name,
u.cust_name_like,
t.flow_id,
t.flow_type,
CASE
WHEN t.flow_type = 110 THEN '消费'
WHEN t.flow_type = 130 THEN '退款'
ELSE '其他'
END AS flow_type_name,
t.flow_real_amount / 100 AS amount,
t.org_id,
t.pay_time,
t.ord_time
FROM cust_org co2
LEFT JOIN (
SELECT
f.flow_id,
f.flow_real_amount,
f.flow_type,
f.org_id,
f.pay_time,
f.ord_time,
f.cust_id
FROM report_account_flow f
WHERE 1=1
<if test="startPayTime != null">
AND f.pay_time &gt;= #{startPayTime}
</if>
<if test="endPayTime != null">
AND f.pay_time &lt; #{endPayTime}
</if>
AND f.flow_type IN (110, 130)
AND f.source_type = 7
) t
ON (
t.org_id = co2.org_id
OR EXISTS (
SELECT 1
FROM cust_org c3
WHERE c3.org_id = t.org_id
AND c3.if_del = 2
AND c3.org_full_id LIKE CONCAT('%/', co2.org_id, '/%')
)
)
LEFT JOIN cust_info u
ON t.cust_id = u.cust_id
WHERE co2.org_level = 2
AND co2.if_del = 2
AND co2.org_name LIKE CONCAT('%', #{orgName}, '%')
ORDER BY t.pay_time DESC;
</select>
<select id="yzSumMoney" resultType="java.math.BigDecimal">
SELECT
SUM(t.flow_real_amount) / 100 AS total_amount
FROM (
<!-- station 正常消费 -->
SELECT
aa.canteen_name,
aac.area_name,
'station' AS consume_source,
f.flow_id,
d.flow_type,
f.flow_real_amount,
f.ord_time,
d.pay_time,
f.cust_id,
f.remark
FROM report_account_flow f
INNER JOIN report_account_flow_detail d ON f.flow_id = d.flow_id
LEFT JOIN device_info di ON f.mch_sn = di.device_sn
LEFT JOIN device_bind bd ON di.device_id = bd.device_id
LEFT JOIN alloc_canteen aa ON aa.canteen_id = bd.canteen_id
LEFT JOIN alloc_area aac ON aac.area_id = aa.area_id
WHERE d.pay_time &gt;= #{startPayTime}
AND d.pay_time &lt; #{endPayTime}
AND d.flow_type = 110
AND (f.source_type IS NULL OR f.source_type = 0)
AND f.remark LIKE '%支付%'
UNION ALL
<!-- station 退款 -->
SELECT
aa.canteen_name,
aac.area_name,
'station' AS consume_source,
f.flow_id,
130 AS flow_type,
at.actual_amount AS flow_real_amount,
f.ord_time,
at.trade_time AS pay_time,
f.cust_id,
f.remark
FROM report_account_flow f
INNER JOIN acc_trade at
ON at.cust_id = f.cust_id
AND at.trade_type = 130
AND DATE(at.trade_time) = DATE(f.pay_time)
LEFT JOIN device_info di ON f.mch_sn = di.device_sn
LEFT JOIN device_bind bd ON di.device_id = bd.device_id
LEFT JOIN alloc_canteen aa ON aa.canteen_id = bd.canteen_id
LEFT JOIN alloc_area aac ON aac.area_id = aa.area_id
WHERE at.trade_time &gt;= #{startPayTime}
AND at.trade_time &lt; #{endPayTime}
AND (f.source_type IS NULL OR f.source_type = 0)
AND f.remark LIKE '%支付%'
) t
LEFT JOIN cust_info u ON t.cust_id = u.cust_id
WHERE t.area_name = #{orgName}
</select>
<select id="getlistByOtherlist" resultType="com.bonus.canteen.core.reportforms.beans.OrgConsume">
SELECT
co.org_full_name as orgFullName,
u.cust_name,
u.cust_name_like,
t.canteen_name,
t.area_name,
t.consume_source,
t.flow_id,
t.flow_type,
CASE
WHEN t.flow_type = 110 THEN '消费'
WHEN t.flow_type = 130 THEN '退款'
ELSE '其他'
END AS flow_type_name,
t.flow_real_amount / 100 AS amount,
t.ord_time,
t.pay_time,
t.remark
FROM (
<!-- station 正常消费 -->
SELECT
aa.canteen_name,
aac.area_name,
'station' AS consume_source,
f.flow_id,
d.flow_type,
f.flow_real_amount,
f.ord_time,
d.pay_time,
f.cust_id,
f.remark
FROM report_account_flow f
INNER JOIN report_account_flow_detail d ON f.flow_id = d.flow_id
LEFT JOIN device_info di ON f.mch_sn = di.device_sn
LEFT JOIN device_bind bd ON di.device_id = bd.device_id
LEFT JOIN alloc_canteen aa ON aa.canteen_id = bd.canteen_id
LEFT JOIN alloc_area aac ON aac.area_id = aa.area_id
WHERE d.pay_time >= #{startPayTime}
AND d.pay_time &lt; #{endPayTime}
AND d.flow_type = 110
AND (f.source_type IS NULL OR f.source_type = 0)
AND f.remark LIKE '%支付%'
UNION ALL
SELECT
aa.canteen_name,
aac.area_name,
'station' AS consume_source,
f.flow_id,
130 AS flow_type,
at.actual_amount AS flow_real_amount,
f.ord_time,
at.trade_time AS pay_time,
f.cust_id,
f.remark
FROM report_account_flow f
INNER JOIN acc_trade at
ON at.cust_id = f.cust_id
AND at.trade_type = 130
AND DATE(at.trade_time) = DATE(f.pay_time)
LEFT JOIN device_info di ON f.mch_sn = di.device_sn
LEFT JOIN device_bind bd ON di.device_id = bd.device_id
LEFT JOIN alloc_canteen aa ON aa.canteen_id = bd.canteen_id
LEFT JOIN alloc_area aac ON aac.area_id = aa.area_id
WHERE at.trade_time >= #{startPayTime}
AND at.trade_time &lt; #{endPayTime}
AND (f.source_type IS NULL OR f.source_type = 0)
AND f.remark LIKE '%支付%'
) t
LEFT JOIN cust_info u ON t.cust_id = u.cust_id
LEFT JOIN cust_org co ON u.org_id = co.org_id
WHERE t.area_name LIKE CONCAT('%', #{orgName}, '%')
ORDER BY t.pay_time DESC
</select>
<select id="getlistConsmerlist" resultType="com.bonus.canteen.core.reportforms.beans.OrgConsume">
SELECT
co.org_full_name as orgFullName,
aa.canteen_name,
f.flow_id ,
d.flow_type,
f.flow_real_amount as amount,
f.ord_time,
d.pay_time,
f.cust_id,
f.remark,
u.cust_name
FROM report_account_flow f
INNER JOIN report_account_flow_detail d ON f.flow_id = d.flow_id
LEFT JOIN device_info di ON f.mch_sn = di.device_sn
LEFT JOIN device_bind bd ON di.device_id = bd.device_id
LEFT JOIN alloc_canteen aa ON aa.canteen_id = bd.canteen_id
LEFT JOIN alloc_area aac ON aac.area_id = aa.area_id
LEFT JOIN cust_info u ON f.cust_id = u.cust_id
LEFT JOIN cust_org co ON u.org_id = co.org_id
WHERE d.pay_time >= #{startPayTime}
AND d.pay_time &lt; #{endPayTime}
AND d.flow_type = 110
AND (f.source_type IS NULL OR f.source_type = 0)
AND f.remark LIKE '%支付%'
AND aac.area_name LIKE #{orgName}
</select>
<select id="getPeoplelist" resultType="com.bonus.canteen.core.reportforms.beans.CanteenRecord">
SELECT
rf.flow_id AS flowId,
ci.cust_id AS custId,
ci.cust_name AS custName,
ci.mobile AS phone,
co.org_id AS orgId,
co.org_name AS orgName,
co.org_full_name AS orgFullName,
rf.flow_amount AS amount,
rf.flow_type AS flowType,
rf.pay_time AS payTime,
rf.ord_time AS ordTime,
rf.remark AS remark
FROM report_account_flow rf
LEFT JOIN cust_info ci ON rf.cust_id = ci.cust_id
LEFT JOIN cust_org co ON ci.org_id = co.org_id
WHERE 1=1 and rf.flow_type IN (110, 120,130)
<if test="startPayTime != null and startPayTime != ''">
AND rf.pay_time &gt;= #{startPayTime}
</if>
<if test="endPayTime != null and endPayTime != ''">
AND rf.pay_time &lt;= #{endPayTime}
</if>
<if test="custName != null">
AND ci.cust_name = #{custName}
</if>
<if test="selectedOrg != null and selectedOrg.length > 0">
AND co.org_id IN
<foreach collection="selectedOrg" item="orgId" open="(" separator="," close=")">
#{orgId}
</foreach>
</if>
ORDER BY rf.pay_time DESC
</select>
<select id="selectAllOrgs" resultType="com.bonus.canteen.core.reportforms.beans.CanteenOrg">
SELECT
org_id AS orgId,
org_name AS orgName,
org_full_name AS orgFullName,
super_id AS superId
FROM cust_org
WHERE if_del = 2
ORDER BY org_id ASC
</select>
<select id="getDeductionlist" resultType="com.bonus.canteen.core.reportforms.beans.OrgConsume">
SELECT
co.org_full_name as orgFullName,
u.cust_name,
f.flow_real_amount / 100 AS amount,
aa.canteen_name,
aac.area_name,
f.source_type,
f.remark,
f.flow_id,
f.flow_type,
f.pay_time as payTime
FROM report_account_flow f
LEFT JOIN device_info di ON f.mch_sn = di.device_sn
LEFT JOIN device_bind bd ON di.device_id = bd.device_id
LEFT JOIN alloc_canteen aa ON aa.canteen_id = bd.canteen_id
LEFT JOIN alloc_area aac ON aac.area_id = aa.area_id
LEFT JOIN cust_info u ON f.cust_id = u.cust_id
LEFT JOIN cust_org co ON u.org_id = co.org_id
WHERE 1=1
<if test="startPayTime != null and startPayTime != ''">
AND f.pay_time &gt;= #{startPayTime}
</if>
<if test="endPayTime != null and endPayTime != ''">
AND f.pay_time &lt; #{endPayTime}
</if>
AND f.flow_type = 120
and aac.area_name LIKE CONCAT('%', #{orgName}, '%')
</select>
<select id="selectReserveRecordsFromDatabase" resultType="java.util.Map">
SELECT
'宏源工业园食堂' AS orgName,
ROUND( COALESCE ( SUM( f.flow_real_amount ), 0 ) / 100, 2 ) AS reserveAmount
FROM
report_account_flow f
WHERE
f.pay_time >= #{startPayTime} AND f.pay_time &lt;#{endPayTime}
AND f.flow_type IN ( 110, 130 )
AND f.source_type = 7
AND f.org_id IN (
SELECT
org_id
FROM
cust_org
WHERE
org_full_name LIKE '%宏源工业园%'
AND if_del = 2
)
</select>
<select id="getlistForH5Special" resultType="com.bonus.canteen.core.reportforms.beans.OrgConsume">
SELECT
co2.org_full_name AS orgFullName,
co2.org_name AS orgName,
u.cust_name,
u.cust_name_like,
t.flow_id,
t.flow_type,
CASE
WHEN t.flow_type = 110 THEN '消费'
WHEN t.flow_type = 130 THEN '退款'
ELSE '其他'
END AS flow_type_name,
t.amount / 100 AS amount,
t.org_id,
t.pay_time,
t.ord_time
FROM cust_org co2
LEFT JOIN (
-- 合并消费和退款
SELECT
f.flow_id,
f.flow_real_amount AS amount,
f.flow_type,
f.org_id,
f.pay_time,
f.ord_time,
f.cust_id
FROM report_account_flow f
WHERE f.pay_time >= #{startPayTime}
AND f.pay_time &lt;= #{endPayTime}
AND f.flow_type = 110
AND f.source_type = 7
UNION ALL
SELECT
f.flow_id,
at.actual_amount AS amount,
130 AS flow_type,
f.org_id,
at.trade_time AS pay_time,
f.ord_time,
at.cust_id
FROM acc_trade at
INNER JOIN report_account_flow f
ON at.origin_trade_id = f.flow_id
AND f.flow_type = 110
AND f.source_type = 7
WHERE at.trade_time >= #{startPayTime}
AND at.trade_time &lt;= #{endPayTime}
AND at.trade_type = 130
AND at.trade_state = 2
AND (at.machine_sn IS NULL OR at.machine_sn = '')
) t
ON t.org_id = co2.org_id
OR EXISTS (
SELECT 1
FROM cust_org c3
WHERE c3.org_id = t.org_id
AND c3.if_del = 2
AND c3.org_full_id LIKE CONCAT('%/', co2.org_id, '/%')
)
LEFT JOIN cust_info u ON t.cust_id = u.cust_id
WHERE co2.org_level = 2
AND co2.if_del = 2
AND co2.org_name LIKE CONCAT('%', #{orgName}, '%')
ORDER BY t.pay_time DESC
</select>
</mapper>