diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/reportforms/beans/ReportOrderInfoVo.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/reportforms/beans/ReportOrderInfoVo.java index b3f4e155..ada1d74d 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/reportforms/beans/ReportOrderInfoVo.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/reportforms/beans/ReportOrderInfoVo.java @@ -30,9 +30,9 @@ public class ReportOrderInfoVo extends BaseEntity { private String orgName; @Excel(name = "所属组织") private String orgFullName; - @Excel(name = "交易金额") private BigDecimal payableAmount; private BigDecimal payableAmountAll; + @Excel(name = "交易金额") private BigDecimal realAmount; private String payTime; private Long areaId; @@ -41,7 +41,7 @@ public class ReportOrderInfoVo extends BaseEntity { private Long diningPlaceId; @Excel(name = "工作地") private String workAreaName; - @Excel(name = "交易次数") + // @Excel(name = "交易次数") private int tradeNum; private int tradeNumAll; @Excel(name = "订单类型") diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/reportforms/controller/reportformsController.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/reportforms/controller/reportformsController.java index 0897e9bf..f8842acf 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/reportforms/controller/reportformsController.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/reportforms/controller/reportformsController.java @@ -98,7 +98,7 @@ public class reportformsController extends BaseController { // 特殊机构名称处理 if ("运检后勤".equals(orgName) && conSource == 1) { orgName = "运检分公司"; - } else if ("送变电工业园".equals(orgName) && (conSource == 3 || conSource == 4 || conSource == 5)) { + } else if ("送变电工业园".equals(orgName) && (conSource == 3 || conSource == 4 || conSource == 5 || conSource == 6)) { orgName = "sbd工业园"; } @@ -204,6 +204,11 @@ public class reportformsController extends BaseController { record.getPayableAmount().divide(new BigDecimal(100), 2, RoundingMode.HALF_UP) ); } + if (record.getRealAmount()!= null) { + record.setRealAmount( + record.getRealAmount().divide(new BigDecimal(100), 2, RoundingMode.HALF_UP) + ); + } }); // 3. 导出 Excel ExcelUtil util = new ExcelUtil<>(ReportOrderInfoVo.class); diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/reportforms/service/impl/reportformsServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/reportforms/service/impl/reportformsServiceImpl.java index 19d4db98..e73ed213 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/reportforms/service/impl/reportformsServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/reportforms/service/impl/reportformsServiceImpl.java @@ -282,8 +282,8 @@ public class reportformsServiceImpl implements reportformsService { return orgConsumes; } // 去重退款记录(flowType=130,payTime相同保留第一次) - Set seenPayTimes = new HashSet<>(); - orgConsumes.removeIf(c -> c.getFlowType() == 130 && !seenPayTimes.add(c.getPayTime())); + /* Set seenPayTimes = new HashSet<>(); + orgConsumes.removeIf(c -> c.getFlowType() == 130 && !seenPayTimes.add(c.getPayTime()));*/ return orgConsumes; } diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/reportforms/OrgConsumerMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/reportforms/OrgConsumerMapper.xml index ec417611..d4e6d022 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/reportforms/OrgConsumerMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/reportforms/OrgConsumerMapper.xml @@ -35,7 +35,7 @@ f.pay_time = ]]> #{startPayTime} AND f.pay_time #{endPayTime} AND f.flow_type = 110 - + AND f.status = 1 UNION ALL -- ========= 退款记录 ========= @@ -61,7 +61,7 @@ AND AT.trade_type = 130 AND AT.trade_state = 2 AND (AT.machine_sn IS NULL OR AT.machine_sn = '') - + AND f.status = 1 UNION ALL SELECT @@ -81,7 +81,8 @@ f.pay_time = ]]> #{startPayTime} AND f.pay_time #{endPayTime} AND f.flow_type = 120 - ) t + AND f.status = 1 + ) t GROUP BY t.area_name, CASE @@ -559,48 +560,44 @@ 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 < #{endPayTime} + AND d.pay_time < #{endPayTime} AND d.flow_type = 110 AND f.source_type IS NULL AND f.remark LIKE '%支付%' UNION ALL - SELECT aa.canteen_name, aac.area_name, 'station' AS consume_source, - f.flow_id, + at.origin_trade_id AS 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, - atwd.wallet_id AS walletId, - 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) - AND at.actual_amount = -f.flow_real_amount - LEFT JOIN acc_trade_wallet_detail atwd ON atwd.trade_id = f.flow_id + at.cust_id, + atwd_refund.wallet_id AS walletId, + CONCAT('退款-', f.remark) AS remark + FROM acc_trade at + INNER JOIN report_account_flow f ON at.origin_trade_id = f.flow_id AND f.flow_type = 110 + LEFT JOIN acc_trade_wallet_detail atwd_refund ON atwd_refund.trade_id = at.id -- 假设acc_trade的主键是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 f.source_type IS NULL - AND f.remark LIKE '%支付%' - AND at.trade_time >= #{startPayTime} + WHERE + at.trade_time >= #{startPayTime} AND at.trade_time < #{endPayTime} - + AND at.trade_type = 130 + AND at.trade_state = 2 + AND (at.machine_sn IS NULL OR at.machine_sn = '') + AND f.source_type IS NULL + 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; - - + ORDER BY t.pay_time DESC SELECT - ANY_VALUE(cust_num) AS cust_num, - ANY_VALUE(cust_name) AS cust_name, - ANY_VALUE(mobile) AS mobile, - ANY_VALUE(org_name) AS org_name, - ANY_VALUE(org_full_name) AS org_full_name, - COUNT(1) AS tradeNum, + ANY_VALUE(cust_num) AS cust_num, + ANY_VALUE(cust_name) AS cust_name, + ANY_VALUE(mobile) AS mobile, + ANY_VALUE(org_name) AS org_name, + ANY_VALUE(org_full_name) AS org_full_name, + COUNT(1) AS tradeNum, order_type, - SUM(payable_amount) AS payable_amount, - SUM(real_amount) AS real_amount, + SUM(real_amount) AS payable_amount, + SUM(real_amount) AS real_amount, area_name, work_area_name FROM ( @@ -863,7 +860,7 @@ ci.cust_num, ci.cust_name, ci.mobile, - CASE WHEN ac.canteen_type='1' THEN '食堂' ELSE '超市' END AS order_type, + CASE WHEN ac.canteen_type = '1' THEN '食堂' ELSE '超市' END AS order_type, co.org_name, co.org_full_name, a.payable_amount, @@ -875,40 +872,86 @@ ap.area_name AS work_area_name, a.mch_sn FROM ( - select a.flow_id as order_id, a.cust_id,a.flow_amount as payable_amount,a.flow_real_amount as real_amount,a.pay_time, - case when bd.area_id is not null then bd.area_id when ac.area_id is not null then ac.area_id - when cdp.dining_place_id is not null then cdp.dining_place_id - else a.canteen_id end as area_id,CONCAT(a.cust_id,a.ord_time) as id - ,case when bd.canteen_id is not null then bd.canteen_id when roi.canteen_id is not null then roi.canteen_id - else a.canteen_id end as canteen_id - ,a.mch_sn as mch_sn - from (select * from report_account_flow a where a.pay_time >= #{vo.startTime} AND a.flow_type IN ( 110, 120 ) - AND a.pay_time <= #{vo.endTime} ) a + SELECT + a.flow_id AS order_id, + a.cust_id, + a.flow_amount AS payable_amount, + a.flow_real_amount AS real_amount, + a.pay_time, + CASE + WHEN bd.area_id IS NOT NULL THEN bd.area_id + WHEN ac.area_id IS NOT NULL THEN ac.area_id + WHEN cdp.dining_place_id IS NOT NULL THEN cdp.dining_place_id + ELSE a.canteen_id + END AS area_id, + CONCAT(a.cust_id, a.ord_time) AS id, + CASE + WHEN bd.canteen_id IS NOT NULL THEN bd.canteen_id + WHEN roi.canteen_id IS NOT NULL THEN roi.canteen_id + ELSE a.canteen_id + END AS canteen_id, + a.mch_sn AS mch_sn + FROM ( + SELECT * + FROM report_account_flow a + WHERE a.pay_time >= #{vo.startTime} + AND a.flow_type IN (110, 120) + AND a.pay_time <= #{vo.endTime} + ) a LEFT JOIN device_info di ON a.mch_sn = di.device_sn LEFT JOIN device_bind bd ON di.device_id = bd.device_id - LEFT JOIN (select * from report_order_info a where a.pay_time >= #{vo.startTime} - AND a.pay_time <= #{vo.endTime} ) roi on CONCAT(a.cust_id,a.ord_time)=CONCAT(roi.cust_id,roi.order_time) + LEFT JOIN ( + SELECT * + FROM report_order_info a + WHERE a.pay_time >= #{vo.startTime} + AND a.pay_time <= #{vo.endTime} + ) roi ON CONCAT(a.cust_id, a.ord_time) = CONCAT(roi.cust_id, roi.order_time) LEFT JOIN alloc_canteen ac ON ac.canteen_id = roi.canteen_id - left join cust_dining_place cdp on a.cust_id=cdp.cust_id and cdp.type = 'area' - union - select a.flow_id as order_id, a.cust_id,a.flow_amount as payable_amount,a.flow_real_amount as real_amount,a.pay_time, - case when bd.area_id is not null then bd.area_id when ac.area_id is not null then ac.area_id - when cdp.dining_place_id is not null then cdp.dining_place_id - else a.canteen_id end as area_id,CONCAT(a.cust_id,a.ord_time) as id - ,case when bd.canteen_id is not null then bd.canteen_id when roi.canteen_id is not null then roi.canteen_id - else a.canteen_id end as canteen_id - ,a.mch_sn as mch_sn - from (select * from report_account_flow a where a.pay_time >= #{vo.startTime} AND a.flow_type IN ( 130 ) - AND a.pay_time <= #{vo.endTime} ) a - left join acc_trade atr on a.flow_id=atr.id - left join (select * from report_account_flow a where a.pay_time >= #{vo.startTime} AND a.flow_type IN ( 110, 120 ) - AND a.pay_time <= #{vo.endTime} ) aa on atr.origin_trade_id=aa.flow_id - LEFT JOIN device_info di ON aa.mch_sn = di.device_sn + LEFT JOIN cust_dining_place cdp ON a.cust_id = cdp.cust_id AND cdp.type = 'area' + + UNION + SELECT + rf.flow_id AS order_id, + rf.cust_id, + rf.flow_amount AS payable_amount, + rf.flow_real_amount AS real_amount, + rf.pay_time, + CASE + WHEN bd.area_id IS NOT NULL THEN bd.area_id + WHEN ac.area_id IS NOT NULL THEN ac.area_id + WHEN cdp.dining_place_id IS NOT NULL THEN cdp.dining_place_id + ELSE COALESCE(ori.canteen_id, rf.canteen_id) + END AS area_id, + CONCAT(rf.cust_id, rf.ord_time) AS id, + CASE + WHEN bd.canteen_id IS NOT NULL THEN bd.canteen_id + WHEN roi.canteen_id IS NOT NULL THEN roi.canteen_id + ELSE COALESCE(ori.canteen_id, rf.canteen_id) + END AS canteen_id, + COALESCE(ori.mch_sn, rf.mch_sn) AS mch_sn + FROM ( + SELECT * + FROM report_account_flow a + WHERE a.flow_type = 130 + AND a.pay_time >= #{vo.startTime} + AND a.pay_time <= #{vo.endTime} + ) rf + LEFT JOIN acc_trade atr ON rf.flow_id = atr.id + LEFT JOIN report_account_flow ori ON atr.origin_trade_id = ori.flow_id + LEFT JOIN device_info di ON COALESCE(ori.mch_sn, rf.mch_sn) = di.device_sn LEFT JOIN device_bind bd ON di.device_id = bd.device_id - LEFT JOIN (select * from report_order_info a where a.pay_time >= #{vo.startTime} - AND a.pay_time <= #{vo.endTime} ) roi on CONCAT(aa.cust_id,a.ord_time)=CONCAT(roi.cust_id,roi.order_time) + LEFT JOIN ( + SELECT * + FROM report_order_info a + WHERE a.pay_time >= #{vo.startTime} + AND a.pay_time <= #{vo.endTime} + ) roi ON ( + (ori.cust_id IS NOT NULL AND CONCAT(ori.cust_id, ori.ord_time) = CONCAT(roi.cust_id, roi.order_time)) + OR (ori.cust_id IS NULL AND CONCAT(rf.cust_id, rf.ord_time) = CONCAT(roi.cust_id, roi.order_time)) + ) LEFT JOIN alloc_canteen ac ON ac.canteen_id = roi.canteen_id - left join cust_dining_place cdp on aa.cust_id=cdp.cust_id and cdp.type = 'area' + LEFT JOIN cust_dining_place cdp ON rf.cust_id = cdp.cust_id AND cdp.type = 'area' + WHERE rf.flow_id IS NOT NULL ) a LEFT JOIN alloc_canteen ac ON ac.canteen_id = a.canteen_id LEFT JOIN cust_info ci ON ci.cust_id = a.cust_id @@ -916,9 +959,9 @@ JOIN cust_dining_place p ON p.cust_id = ci.cust_id AND p.type = 'area' LEFT JOIN alloc_area ar ON ar.area_id = a.area_id LEFT JOIN alloc_area ap ON ap.area_id = p.dining_place_id - where 1=1 + WHERE 1=1 - and ar.area_id != p.dining_place_id + AND ar.area_id != p.dining_place_id @@ -942,6 +985,7 @@ - SELECT - ANY_VALUE(cust_num) AS cust_num, - ANY_VALUE(cust_name) AS cust_name, - ANY_VALUE(mobile) AS mobile, - ANY_VALUE(org_name) AS org_name, - ANY_VALUE(org_full_name) AS org_full_name, - COUNT(1) AS tradeNum, - SUM(real_amount) AS payable_amount, - SUM(real_amount) AS real_amount, - area_name, - work_area_name - FROM ( SELECT a.order_id, a.cust_id, ci.cust_num, ci.cust_name, ci.mobile, - CASE WHEN ac.canteen_type='1' THEN '食堂' ELSE '超市' END AS order_type, + CASE WHEN ac.canteen_type = '1' THEN '食堂' ELSE '超市' END AS order_type, co.org_name, co.org_full_name, a.payable_amount, @@ -33,40 +21,87 @@ ap.area_name AS work_area_name, a.mch_sn FROM ( - select a.flow_id as order_id, a.cust_id,a.flow_amount as payable_amount,a.flow_real_amount as real_amount,a.pay_time, - case when bd.area_id is not null then bd.area_id when ac.area_id is not null then ac.area_id - when cdp.dining_place_id is not null then cdp.dining_place_id - else a.canteen_id end as area_id,CONCAT(a.cust_id,a.ord_time) as id - ,case when bd.canteen_id is not null then bd.canteen_id when roi.canteen_id is not null then roi.canteen_id - else a.canteen_id end as canteen_id - ,a.mch_sn as mch_sn - from (select * from report_account_flow a where a.pay_time >= #{startTime} AND a.flow_type IN ( 110, 120 ) - AND a.pay_time <= #{endTime} ) a + SELECT + a.flow_id AS order_id, + a.cust_id, + a.flow_amount AS payable_amount, + a.flow_real_amount AS real_amount, + a.pay_time, + CASE + WHEN bd.area_id IS NOT NULL THEN bd.area_id + WHEN ac.area_id IS NOT NULL THEN ac.area_id + WHEN cdp.dining_place_id IS NOT NULL THEN cdp.dining_place_id + ELSE a.canteen_id + END AS area_id, + CONCAT(a.cust_id, a.ord_time) AS id, + CASE + WHEN bd.canteen_id IS NOT NULL THEN bd.canteen_id + WHEN roi.canteen_id IS NOT NULL THEN roi.canteen_id + ELSE a.canteen_id + END AS canteen_id, + a.mch_sn AS mch_sn + FROM ( + SELECT * + FROM report_account_flow a + WHERE a.pay_time >= #{startTime} + AND a.flow_type IN (110, 120) + AND a.pay_time <= #{endTime} + ) a LEFT JOIN device_info di ON a.mch_sn = di.device_sn LEFT JOIN device_bind bd ON di.device_id = bd.device_id - LEFT JOIN (select * from report_order_info a where a.pay_time >= #{startTime} - AND a.pay_time <= #{endTime} ) roi on CONCAT(a.cust_id,a.ord_time)=CONCAT(roi.cust_id,roi.order_time) + LEFT JOIN ( + SELECT * + FROM report_order_info a + WHERE a.pay_time >= #{startTime} + AND a.pay_time <= #{endTime} + ) roi ON CONCAT(a.cust_id, a.ord_time) = CONCAT(roi.cust_id, roi.order_time) LEFT JOIN alloc_canteen ac ON ac.canteen_id = roi.canteen_id - left join cust_dining_place cdp on a.cust_id=cdp.cust_id and cdp.type = 'area' - union - select a.flow_id as order_id, a.cust_id,a.flow_amount as payable_amount,a.flow_real_amount as real_amount,a.pay_time, - case when bd.area_id is not null then bd.area_id when ac.area_id is not null then ac.area_id - when cdp.dining_place_id is not null then cdp.dining_place_id - else a.canteen_id end as area_id,CONCAT(a.cust_id,a.ord_time) as id - ,case when bd.canteen_id is not null then bd.canteen_id when roi.canteen_id is not null then roi.canteen_id - else a.canteen_id end as canteen_id - ,a.mch_sn as mch_sn - from (select * from report_account_flow a where a.pay_time >= #{startTime} AND a.flow_type IN ( 130 ) - AND a.pay_time <= #{endTime} ) a - left join acc_trade atr on a.flow_id=atr.id - left join (select * from report_account_flow a where a.pay_time >= #{startTime} AND a.flow_type IN ( 110, 120 ) - AND a.pay_time <= #{endTime} ) aa on atr.origin_trade_id=aa.flow_id - LEFT JOIN device_info di ON aa.mch_sn = di.device_sn + LEFT JOIN cust_dining_place cdp ON a.cust_id = cdp.cust_id AND cdp.type = 'area' + + UNION + + SELECT + rf.flow_id AS order_id, + rf.cust_id, + rf.flow_amount AS payable_amount, + rf.flow_real_amount AS real_amount, + rf.pay_time, + CASE + WHEN bd.area_id IS NOT NULL THEN bd.area_id + WHEN ac.area_id IS NOT NULL THEN ac.area_id + WHEN cdp.dining_place_id IS NOT NULL THEN cdp.dining_place_id + ELSE COALESCE(ori.canteen_id, rf.canteen_id) + END AS area_id, + CONCAT(rf.cust_id, rf.ord_time) AS id, + CASE + WHEN bd.canteen_id IS NOT NULL THEN bd.canteen_id + WHEN roi.canteen_id IS NOT NULL THEN roi.canteen_id + ELSE COALESCE(ori.canteen_id, rf.canteen_id) + END AS canteen_id, + COALESCE(ori.mch_sn, rf.mch_sn) AS mch_sn + FROM ( + SELECT * + FROM report_account_flow a + WHERE a.flow_type = 130 + AND a.pay_time >= #{startTime} + AND a.pay_time <= #{endTime} + ) rf + LEFT JOIN acc_trade atr ON rf.flow_id = atr.id + LEFT JOIN report_account_flow ori ON atr.origin_trade_id = ori.flow_id + LEFT JOIN device_info di ON COALESCE(ori.mch_sn, rf.mch_sn) = di.device_sn LEFT JOIN device_bind bd ON di.device_id = bd.device_id - LEFT JOIN (select * from report_order_info a where a.pay_time >= #{startTime} - AND a.pay_time <= #{endTime} ) roi on CONCAT(aa.cust_id,a.ord_time)=CONCAT(roi.cust_id,roi.order_time) + LEFT JOIN ( + SELECT * + FROM report_order_info a + WHERE a.pay_time >= #{startTime} + AND a.pay_time <= #{endTime} + ) roi ON ( + (ori.cust_id IS NOT NULL AND CONCAT(ori.cust_id, ori.ord_time) = CONCAT(roi.cust_id, roi.order_time)) + OR (ori.cust_id IS NULL AND CONCAT(rf.cust_id, rf.ord_time) = CONCAT(roi.cust_id, roi.order_time)) + ) LEFT JOIN alloc_canteen ac ON ac.canteen_id = roi.canteen_id - left join cust_dining_place cdp on aa.cust_id=cdp.cust_id and cdp.type = 'area' + LEFT JOIN cust_dining_place cdp ON rf.cust_id = cdp.cust_id AND cdp.type = 'area' + WHERE rf.flow_id IS NOT NULL ) a LEFT JOIN alloc_canteen ac ON ac.canteen_id = a.canteen_id LEFT JOIN cust_info ci ON ci.cust_id = a.cust_id @@ -74,9 +109,9 @@ JOIN cust_dining_place p ON p.cust_id = ci.cust_id AND p.type = 'area' LEFT JOIN alloc_area ar ON ar.area_id = a.area_id LEFT JOIN alloc_area ap ON ap.area_id = p.dining_place_id - where 1=1 + WHERE 1=1 - and ar.area_id != p.dining_place_id + AND ar.area_id != p.dining_place_id @@ -92,8 +127,7 @@ #{id} - ) a - GROUP BY cust_id, area_name, work_area_name - ORDER BY MAX(a.pay_time) DESC + ORDER BY a.pay_time DESC +