报表功能查看

This commit is contained in:
lizhenhua 2025-09-27 14:18:22 +08:00
parent dfdd2e2a69
commit a7e125ab1a
14 changed files with 1240 additions and 273 deletions

View File

@ -0,0 +1,287 @@
package com.bonus.sharedstation.auth.entity;
import lombok.Generated;
public class PigxUser {
private Long id;
private Long merchantId;
private Long canteenEffId;
private Long custEffId;
private Long dishesEffId;
private String roleCode;
private String username;
@Generated
public static PigxUserBuilder builder() {
return new PigxUserBuilder();
}
@Generated
public Long getId() {
return this.id;
}
@Generated
public Long getMerchantId() {
return this.merchantId;
}
@Generated
public Long getCanteenEffId() {
return this.canteenEffId;
}
@Generated
public Long getCustEffId() {
return this.custEffId;
}
@Generated
public Long getDishesEffId() {
return this.dishesEffId;
}
@Generated
public String getRoleCode() {
return this.roleCode;
}
@Generated
public String getUsername() {
return this.username;
}
@Generated
public void setId(final Long id) {
this.id = id;
}
@Generated
public void setMerchantId(final Long merchantId) {
this.merchantId = merchantId;
}
@Generated
public void setCanteenEffId(final Long canteenEffId) {
this.canteenEffId = canteenEffId;
}
@Generated
public void setCustEffId(final Long custEffId) {
this.custEffId = custEffId;
}
@Generated
public void setDishesEffId(final Long dishesEffId) {
this.dishesEffId = dishesEffId;
}
@Generated
public void setRoleCode(final String roleCode) {
this.roleCode = roleCode;
}
@Generated
public void setUsername(final String username) {
this.username = username;
}
@Generated
public boolean equals(final Object o) {
if (o == this) {
return true;
} else if (!(o instanceof PigxUser)) {
return false;
} else {
PigxUser other = (PigxUser)o;
if (!other.canEqual(this)) {
return false;
} else {
label95: {
Object this$id = this.getId();
Object other$id = other.getId();
if (this$id == null) {
if (other$id == null) {
break label95;
}
} else if (this$id.equals(other$id)) {
break label95;
}
return false;
}
Object this$merchantId = this.getMerchantId();
Object other$merchantId = other.getMerchantId();
if (this$merchantId == null) {
if (other$merchantId != null) {
return false;
}
} else if (!this$merchantId.equals(other$merchantId)) {
return false;
}
Object this$canteenEffId = this.getCanteenEffId();
Object other$canteenEffId = other.getCanteenEffId();
if (this$canteenEffId == null) {
if (other$canteenEffId != null) {
return false;
}
} else if (!this$canteenEffId.equals(other$canteenEffId)) {
return false;
}
label74: {
Object this$custEffId = this.getCustEffId();
Object other$custEffId = other.getCustEffId();
if (this$custEffId == null) {
if (other$custEffId == null) {
break label74;
}
} else if (this$custEffId.equals(other$custEffId)) {
break label74;
}
return false;
}
label67: {
Object this$dishesEffId = this.getDishesEffId();
Object other$dishesEffId = other.getDishesEffId();
if (this$dishesEffId == null) {
if (other$dishesEffId == null) {
break label67;
}
} else if (this$dishesEffId.equals(other$dishesEffId)) {
break label67;
}
return false;
}
Object this$roleCode = this.getRoleCode();
Object other$roleCode = other.getRoleCode();
if (this$roleCode == null) {
if (other$roleCode != null) {
return false;
}
} else if (!this$roleCode.equals(other$roleCode)) {
return false;
}
Object this$username = this.getUsername();
Object other$username = other.getUsername();
if (this$username == null) {
if (other$username != null) {
return false;
}
} else if (!this$username.equals(other$username)) {
return false;
}
return true;
}
}
}
@Generated
protected boolean canEqual(final Object other) {
return other instanceof PigxUser;
}
@Generated
public String toString() {
Long var10000 = this.getId();
return "PigxUser(id=" + var10000 + ", merchantId=" + this.getMerchantId() + ", canteenEffId=" + this.getCanteenEffId() + ", custEffId=" + this.getCustEffId() + ", dishesEffId=" + this.getDishesEffId() + ", roleCode=" + this.getRoleCode() + ", username=" + this.getUsername() + ")";
}
@Generated
public PigxUser(final Long id, final Long merchantId, final Long canteenEffId, final Long custEffId, final Long dishesEffId, final String roleCode, final String username) {
this.id = id;
this.merchantId = merchantId;
this.canteenEffId = canteenEffId;
this.custEffId = custEffId;
this.dishesEffId = dishesEffId;
this.roleCode = roleCode;
this.username = username;
}
@Generated
public PigxUser() {
}
@Generated
public static class PigxUserBuilder {
@Generated
private Long id;
@Generated
private Long merchantId;
@Generated
private Long canteenEffId;
@Generated
private Long custEffId;
@Generated
private Long dishesEffId;
@Generated
private String roleCode;
@Generated
private String username;
@Generated
PigxUserBuilder() {
}
@Generated
public PigxUserBuilder id(final Long id) {
this.id = id;
return this;
}
@Generated
public PigxUserBuilder merchantId(final Long merchantId) {
this.merchantId = merchantId;
return this;
}
@Generated
public PigxUserBuilder canteenEffId(final Long canteenEffId) {
this.canteenEffId = canteenEffId;
return this;
}
@Generated
public PigxUserBuilder custEffId(final Long custEffId) {
this.custEffId = custEffId;
return this;
}
@Generated
public PigxUserBuilder dishesEffId(final Long dishesEffId) {
this.dishesEffId = dishesEffId;
return this;
}
@Generated
public PigxUserBuilder roleCode(final String roleCode) {
this.roleCode = roleCode;
return this;
}
@Generated
public PigxUserBuilder username(final String username) {
this.username = username;
return this;
}
@Generated
public PigxUser build() {
return new PigxUser(this.id, this.merchantId, this.canteenEffId, this.custEffId, this.dishesEffId, this.roleCode, this.username);
}
@Generated
public String toString() {
return "PigxUser.PigxUserBuilder(id=" + this.id + ", merchantId=" + this.merchantId + ", canteenEffId=" + this.canteenEffId + ", custEffId=" + this.custEffId + ", dishesEffId=" + this.dishesEffId + ", roleCode=" + this.roleCode + ", username=" + this.username + ")";
}
}
}

View File

@ -0,0 +1,5 @@
package com.bonus.sharedstation.exception;
public interface CodedException {
Integer getCode();
}

View File

@ -0,0 +1,35 @@
package com.bonus.sharedstation.exception;
import com.bonus.common.houqin.constant.RetCodeEnum;
public class LeCheckedException extends BizException {
private static final Integer DEFAULT_ERROR_CODE = 40004;
public LeCheckedException(String message) {
super(DEFAULT_ERROR_CODE, message);
}
public LeCheckedException(RetCodeEnum retCodeEnum, String message) {
super(retCodeEnum.getKey(), message);
}
public LeCheckedException(Integer code, String message) {
super(code, message);
}
public LeCheckedException(Throwable cause) {
super(cause);
}
public LeCheckedException(RetCodeEnum retCodeEnum, Throwable cause) {
super(retCodeEnum.getKey(), cause);
}
public LeCheckedException(String message, Throwable cause) {
super(message, cause);
}
public LeCheckedException(RetCodeEnum retCodeEnum, String message, Throwable cause) {
super(retCodeEnum.getKey(), message, cause);
}
}

View File

@ -0,0 +1,36 @@
package com.bonus.sharedstation.exception;
import com.bonus.common.houqin.constant.RetCodeEnum;
public class LeException extends BizRuntimeException {
private static final Integer DEFAULT_ERROR_CODE = 40004;
public LeException(String message) {
super(DEFAULT_ERROR_CODE, message);
}
public LeException(RetCodeEnum retCodeEnum, String message) {
super(retCodeEnum.getKey(), message);
}
public LeException(Integer code, String message) {
super(code, message);
}
public LeException(Throwable cause) {
super(cause);
}
public LeException(RetCodeEnum retCodeEnum, Throwable cause) {
super(retCodeEnum.getKey(), cause);
}
public LeException(String message, Throwable cause) {
super(message, cause);
}
public LeException(RetCodeEnum retCodeEnum, String message, Throwable cause) {
super(retCodeEnum.getKey(), message, cause);
}
}

View File

@ -1,27 +1,51 @@
package com.bonus.canteen.core.reportforms.beans;
import com.bonus.common.core.annotation.Excel;
import com.bonus.common.core.web.domain.BaseEntity;
import lombok.Data;
import java.util.List;
@Data
public class CanteenRecord extends BaseEntity {
private Long orgId; // 主键ID
private String orgName;
@Excel(name = "用户姓名")
private String custName; // 姓名
@Excel(name = "用户编号")
private String custId; // 用户编号
@Excel(name = "所属组织")
private String orgFullName; // 所属组织
private String flowTypeName; // 消费情况
private String consumeSource; // 订单类型
private String consumeSource;
private String ordDate; // 就餐日期
@Excel(name = "订单金额")
private Double amount; // 订单金额
private String phone; // 用户手机号
@Excel(name = "下单时间")
private String ordTime; // 下单时间
private String remark; // 备注
private String startPayTime;
private String endPayTime;
private String flowType;
private String totalConsume;
private String totalRefund;
private String[] selectedOrg;
// 导出用的字段
@Excel(name = "订单类型")
private String flowTypeText;
// 在查询或封装数据时 flowTypeText 赋值
public void setFlowTypeTextByFlowType() {
if ("110".equals(flowType)) {
this.flowTypeText = "消费";
} else if ("120".equals(flowType)) {
this.flowTypeText = "补助";
} else if ("130".equals(flowType)) {
this.flowTypeText = "退款";
} else {
this.flowTypeText = flowType;
}
}
}

View File

@ -25,6 +25,8 @@ public class OrgConsume {
private Integer flowType;
private String payTime;
private String orgFullName;
private String walletId;
/**
* 1:APP预定 2:驿站消费 3:食堂消费 4:超市消费
*/

View File

@ -0,0 +1,50 @@
package com.bonus.canteen.core.reportforms.beans;
import com.bonus.common.core.annotation.Excel;
import com.bonus.common.core.web.domain.BaseEntity;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class ReportOrderInfoVo extends BaseEntity {
private String startTime;
private String endTime;
private String[] selectedOrg;
private String[] gzselectedOrg;
// 分页字段
private Integer pageNum = 1;
private Integer pageSize = 10;
private Long orderId;
private Long custId;
@Excel(name = "用户账号")
private String custNum;
@Excel(name = "用户姓名")
private String custName;
@Excel(name = "用户手机号")
private String mobile;
private String orgName;
@Excel(name = "所属组织")
private String orgFullName;
@Excel(name = "交易余额")
private BigDecimal payableAmount;
private BigDecimal payableAmountAll;
private BigDecimal realAmount;
private String payTime;
private Long areaId;
@Excel(name = "消费地")
private String areaName;
private Long diningPlaceId;
@Excel(name = "工作地")
private String workAreaName;
@Excel(name = "交易次数")
private int tradeNum;
private int tradeNumAll;
@Excel(name = "订单类型")
private String orderType;
}

View File

@ -2,6 +2,7 @@ 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.beans.ReportOrderInfoVo;
import com.bonus.canteen.core.reportforms.service.reportformsService;
import com.bonus.common.core.utils.poi.ExcelUtil;
import com.bonus.common.core.web.controller.BaseController;
@ -12,6 +13,8 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
@ -140,4 +143,57 @@ public class reportformsController extends BaseController {
return service.getOrgTree();
}
@GetMapping("/areatree")
public List<CanteenOrg> getOrgareatree() {
List<CanteenOrg> orgareatree = service.getOrgareatree();
return orgareatree;
}
/**
* 查询订单区域不匹配列表
*/
@PostMapping("/getplaceList")
public TableDataInfo getplaceList(@RequestBody ReportOrderInfoVo reportOrderInfoVo) {
int pageNum = reportOrderInfoVo.getPageNum() != null ? reportOrderInfoVo.getPageNum() : 1;
int pageSize = reportOrderInfoVo.getPageSize() != null ? reportOrderInfoVo.getPageSize() : 10;
int offset = (pageNum - 1) * pageSize;
int count =service.selectOrderMismatchListCount(reportOrderInfoVo);
List<ReportOrderInfoVo> list = service.selectOrderMismatchList(reportOrderInfoVo, offset, pageSize);
// 封装返回给前端
return new TableDataInfo(list, count);
}
/**
* 人员报表查询导出功能
* @param orgConsume
* @return
*/
@PostMapping("/consume/placeexportExcel")
public void placeexportExcel(HttpServletResponse response, ReportOrderInfoVo orgConsume) throws UnsupportedEncodingException {
if (orgConsume.getCustName() != null && !orgConsume.getCustName().trim().isEmpty()) {
try {
String decodedName = URLDecoder.decode(orgConsume.getCustName(), StandardCharsets.UTF_8.name());
orgConsume.setCustName(decodedName);
} catch (Exception e) {
// 出错时打印日志但不要影响后续逻辑
e.printStackTrace();
}
}
// 1. 查询数据
List<ReportOrderInfoVo> peoplelist = service.placeexportExcel(orgConsume);
/// ->
peoplelist.forEach(record -> {
if (record.getPayableAmount() != null) {
record.setPayableAmount(
record.getPayableAmount().divide(new BigDecimal(100), 2, RoundingMode.HALF_UP)
);
}
});
// 3. 导出 Excel
ExcelUtil<ReportOrderInfoVo> util = new ExcelUtil<>(ReportOrderInfoVo.class);
util.exportExcel(response, peoplelist, "人员导出数据详情");
}
}

View File

@ -5,6 +5,7 @@ import com.bonus.canteen.core.menu.vo.AppletWeekCanteenVO;
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.beans.ReportOrderInfoVo;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -47,4 +48,14 @@ public interface OrgConsumeMapper {
List<Map<String, Object>> selectReserveRecordsFromDatabase(OrgConsume orgConsume);
List<OrgConsume> getlistForH5Special(OrgConsume orgConsume);
List<ReportOrderInfoVo> selectOrderMismatchList( @Param("vo") ReportOrderInfoVo reportOrderInfoVo, @Param("offset")int offset, @Param("pageSize") int pageSize);
// 查询总数
int selectOrderMismatchListCount(ReportOrderInfoVo reportOrderInfoVo);
ReportOrderInfoVo selectOrderMismatchListTotal(ReportOrderInfoVo reportOrderInfoVo);
List<CanteenOrg> selectAllareaOrgs();
}

View File

@ -0,0 +1,19 @@
package com.bonus.canteen.core.reportforms.mapper;
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.beans.ReportOrderInfoVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
@Mapper
public interface PlaceMapper {
List<ReportOrderInfoVo> placeexportExcel(ReportOrderInfoVo orgConsume);
}

View File

@ -3,7 +3,9 @@ package com.bonus.canteen.core.reportforms.service.impl;
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.beans.ReportOrderInfoVo;
import com.bonus.canteen.core.reportforms.mapper.OrgConsumeMapper;
import com.bonus.canteen.core.reportforms.mapper.PlaceMapper;
import com.bonus.canteen.core.reportforms.service.reportformsService;
import com.bonus.common.houqin.utils.SM4EncryptUtils;
import org.springframework.stereotype.Service;
@ -18,6 +20,9 @@ import java.util.stream.Collectors;
public class reportformsServiceImpl implements reportformsService {
@Resource
private OrgConsumeMapper mapper;
@Resource
private PlaceMapper placemapper;
@Override
public List<OrgConsume> getOrgConsumeList(OrgConsume orgConsume) {
// 查询食堂超市消费补扣的所有数据信息
@ -143,6 +148,49 @@ public class reportformsServiceImpl implements reportformsService {
.collect(Collectors.toList());
return orgConsumes;
}
@Override
public List<ReportOrderInfoVo> selectOrderMismatchList(ReportOrderInfoVo reportOrderInfoVo, int pageNum, int pageSize) {
List<ReportOrderInfoVo> reportOrderInfoVos = mapper.selectOrderMismatchList(reportOrderInfoVo, pageNum, pageSize)
.stream()
.peek(c -> {
if (c.getCustName() != null && !c.getCustName().isEmpty()) {
try {
c.setCustName(SM4EncryptUtils.sm4Decrypt(c.getCustName()));
if (c.getMobile() != null) {
String phone = SM4EncryptUtils.sm4Decrypt(c.getMobile());
if (phone.length() == 11) {
phone = phone.substring(0, 3) + "****" + phone.substring(7);
}
c.setMobile(phone);
}
} catch (Exception e) {
e.printStackTrace();
}
}
})
.collect(Collectors.toList());
// 查询全表合计
ReportOrderInfoVo totalVo = mapper.selectOrderMismatchListTotal(reportOrderInfoVo);
if (totalVo != null) {
ReportOrderInfoVo totalRow = new ReportOrderInfoVo();
totalRow.setCustNum("合计");
totalRow.setTradeNum(totalVo.getTradeNum());
totalRow.setPayableAmount(totalVo.getPayableAmount());
// 其它字段按需填充空或默认值
reportOrderInfoVos.add(totalRow);
}
return reportOrderInfoVos;
}
@Override
public int selectOrderMismatchListCount(ReportOrderInfoVo reportOrderInfoVo) {
return mapper.selectOrderMismatchListCount(reportOrderInfoVo);
}
@Override
public List<OrgConsume> getlistByH5list(OrgConsume orgConsume) {
if ("宏源工业园".equals(orgConsume.getOrgName())) {
@ -248,6 +296,48 @@ public class reportformsServiceImpl implements reportformsService {
List<CanteenOrg> all = mapper.selectAllOrgs();
return buildTree(all, -1L); // 假设顶级 super_id = 0
}
@Override
public List<CanteenOrg> getOrgareatree() {
List<CanteenOrg> all = mapper.selectAllareaOrgs();
return buildAreaTree(all, 378915229716713472L); // 假设顶级 super_id = 0
}
@Override
public List<ReportOrderInfoVo> placeexportExcel(ReportOrderInfoVo orgConsume) {
List<ReportOrderInfoVo> reportOrderInfoVos = placemapper.placeexportExcel(orgConsume)
.stream()
.peek(c -> {
if (c.getCustName() != null && !c.getCustName().isEmpty()) {
try {
c.setCustName(SM4EncryptUtils.sm4Decrypt(c.getCustName()));
if (c.getMobile() != null) {
String phone = SM4EncryptUtils.sm4Decrypt(c.getMobile());
c.setMobile(phone);
}
} catch (Exception e) {
e.printStackTrace();
}
}
})
.collect(Collectors.toList());
return reportOrderInfoVos;
}
private List<CanteenOrg> buildAreaTree(List<CanteenOrg> list, Long parentId) {
System.err.println("parentId = " + parentId);
List<CanteenOrg> tree = new ArrayList<>();
for (CanteenOrg org : list) {
System.err.println("orgId=" + org.getOrgId() + ", superId=" + org.getSuperId());
if ((parentId == null && org.getSuperId() == null)
|| (parentId != null && parentId.equals(org.getSuperId()))) {
org.setChildren(buildAreaTree(list, org.getOrgId()));
tree.add(org);
}
}
return tree;
}
private List<CanteenOrg> buildTree(List<CanteenOrg> list, Long parentId) {

View File

@ -3,6 +3,7 @@ package com.bonus.canteen.core.reportforms.service;
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.beans.ReportOrderInfoVo;
import java.util.List;
@ -22,4 +23,13 @@ public interface reportformsService {
List<CanteenOrg> getOrgTree();
List<OrgConsume> getDeductionlist(OrgConsume orgConsume);
List<ReportOrderInfoVo> selectOrderMismatchList(ReportOrderInfoVo reportOrderInfoVo,int pageNum, int pageSize);
int selectOrderMismatchListCount(ReportOrderInfoVo reportOrderInfoVo);
List<CanteenOrg> getOrgareatree();
List<ReportOrderInfoVo> placeexportExcel(ReportOrderInfoVo orgConsume);
}

View File

@ -150,10 +150,103 @@
SELECT area_name, org_name FROM area_org_map
</select>
<select id="getlistByArealist" resultType="com.bonus.canteen.core.reportforms.beans.OrgConsume">
<!-- Mapper XML -->
SELECT DISTINCT
SELECT
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,
CASE
WHEN LENGTH(t.wallets) - LENGTH(REPLACE(t.wallets, ',', '')) > 0 THEN 3
ELSE t.wallets
END AS walletId
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,
GROUP_CONCAT(DISTINCT atwd.wallet_id) AS wallets
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
LEFT JOIN acc_trade_wallet_detail atwd ON atwd.trade_id = f.flow_id
WHERE d.pay_time >= #{startPayTime}
AND d.pay_time &lt; #{endPayTime}
AND d.flow_type = 110
AND f.source_type IS NOT NULL
AND f.source_type NOT IN (7,53)
GROUP BY f.flow_id
UNION ALL
-- 退款逻辑
SELECT
aa.canteen_name,
aac.area_name,
'canteen' AS consume_source,
f.flow_id AS flow_id,
130 AS flow_type,
AT.actual_amount AS flow_real_amount,
f.ord_time,
AT.trade_time AS pay_time,
AT.cust_id,
f.remark,
GROUP_CONCAT(DISTINCT atwd.wallet_id) AS wallets
FROM report_account_flow f
INNER JOIN acc_trade AT
ON AT.origin_trade_id = f.flow_id
AND f.flow_type = 110
AND AT.actual_amount = f.flow_real_amount
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 acc_trade_wallet_detail atwd ON atwd.trade_id = f.flow_id
WHERE AT.trade_type = 130
AND AT.trade_state = 2
AND f.source_type IS NOT NULL
AND (AT.machine_sn IS NULL OR AT.machine_sn = '')
AND AT.trade_time >= #{startPayTime}
AND AT.trade_time &lt;#{endPayTime}
GROUP BY f.flow_id
) 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="getlistBySuperlist" 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,
@ -162,200 +255,118 @@
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,
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,
CASE
WHEN LENGTH(t.wallets) - LENGTH(REPLACE(t.wallets, ',', '')) > 0 THEN 3
ELSE t.wallets
END AS walletId,
t.pay_time
FROM (
<!-- 1. 原消费逻辑 -->
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 d.pay_time &gt;= #{startPayTime}
AND d.pay_time &lt; #{endPayTime}
AND d.flow_type = 110
AND f.source_type IS NOT NULL
AND f.source_type NOT IN (7,53)
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,
GROUP_CONCAT(DISTINCT atwd.wallet_id) AS wallets,
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
LEFT JOIN acc_trade_wallet_detail atwd ON atwd.trade_id = f.flow_id
WHERE d.pay_time <![CDATA[>=]]> #{startPayTime}
AND d.pay_time <![CDATA[<]]> #{endPayTime}
AND d.flow_type = 110
AND f.source_type = 53
GROUP BY f.flow_id
UNION ALL
UNION ALL
<!-- 2. 补充消费逻辑 -->
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 d.pay_time &gt;= #{startPayTime}
AND d.pay_time &lt; #{endPayTime}
AND d.flow_type = 110
) 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 = '')
AND f.source_type IS NOT NULL
-- 补充消费逻辑
SELECT
bo.canteen_name,
bo.area_name,
bo.consume_source,
f.flow_id,
d.flow_type,
f.flow_real_amount,
f.ord_time,
GROUP_CONCAT(DISTINCT atwd.wallet_id) AS wallets,
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 <![CDATA[>=]]> #{startPayTime}
AND d.pay_time <![CDATA[<]]> #{endPayTime}
AND d.flow_type = 110
AND f.source_type = 53
) bo ON f.ord_time = bo.ord_time
LEFT JOIN acc_trade_wallet_detail atwd ON atwd.trade_id = f.flow_id
WHERE d.pay_time <![CDATA[>=]]> #{startPayTime}
AND d.pay_time <![CDATA[<]]> #{endPayTime}
AND d.flow_type = 130
AND (f.mch_sn IS NULL OR f.mch_sn = '')
GROUP BY f.flow_id
UNION ALL
UNION ALL
<!-- 3. 退款逻辑 -->
SELECT
aa.canteen_name,
aac.area_name,
'canteen' AS consume_source,
f.flow_id AS flow_id,
130 AS flow_type,
AT.actual_amount AS flow_real_amount,
f.ord_time,
AT.trade_time AS pay_time,
AT.cust_id,
f.remark
FROM report_account_flow f
INNER JOIN acc_trade AT
ON AT.origin_trade_id = f.flow_id
AND f.flow_type = 110
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_type = 130
AND AT.trade_state = 2
AND f.source_type IS NOT NULL
AND (AT.machine_sn IS NULL OR AT.machine_sn = '')
AND AT.trade_time &gt;= #{startPayTime}
AND AT.trade_time &lt; #{endPayTime}
) 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
aa.canteen_name,
aac.area_name,
'super' AS consume_source,
f.flow_id,
130 AS flow_type,
AT.actual_amount AS flow_real_amount,
f.ord_time,
GROUP_CONCAT(DISTINCT atwd.wallet_id) AS wallets,
AT.trade_time AS pay_time,
f.cust_id
FROM report_account_flow f
INNER JOIN acc_trade AT
ON AT.origin_trade_id = f.flow_id
AND f.flow_type = 110
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 acc_trade_wallet_detail atwd ON atwd.trade_id = f.flow_id
WHERE AT.trade_type = 130
AND AT.trade_state = 2
AND f.source_type = 53
AND AT.trade_time <![CDATA[>=]]> #{startPayTime}
AND AT.trade_time <![CDATA[<]]> #{endPayTime}
GROUP BY f.flow_id
) 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>
<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">
@ -371,33 +382,56 @@
WHEN t.flow_type = 130 THEN '退款'
ELSE '其他'
END AS flow_type_name,
t.flow_real_amount / 100 AS amount,
t.amount / 100 AS amount, -- 消费/退款金额
t.org_id,
t.pay_time,
t.ord_time
t.ord_time,
t.walletId
FROM cust_org co2
LEFT JOIN (
<!-- 消费 -->
SELECT
f.flow_id,
f.flow_real_amount,
f.flow_real_amount AS amount,
f.flow_type,
f.org_id,
f.pay_time,
f.ord_time,
f.cust_id
f.cust_id,
atwd.wallet_id AS walletId
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)
LEFT JOIN acc_trade_wallet_detail atwd
ON atwd.trade_id = f.flow_id
WHERE f.pay_time >= #{startPayTime}
AND f.pay_time &lt; #{endPayTime}
AND f.flow_type = 110
AND f.source_type = 7
) t
ON (
t.org_id = co2.org_id
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,
atwd.wallet_id AS walletId
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
LEFT JOIN acc_trade_wallet_detail atwd
ON atwd.trade_id = f.flow_id
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
@ -405,13 +439,11 @@
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
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;
ORDER BY t.pay_time DESC
</select>
@ -493,6 +525,7 @@
t.flow_real_amount / 100 AS amount,
t.ord_time,
t.pay_time,
t.walletId,
t.remark
FROM (
<!-- station 正常消费 -->
@ -506,8 +539,10 @@
f.ord_time,
d.pay_time,
f.cust_id,
atwd.wallet_id as walletId,
f.remark
FROM report_account_flow f
left join acc_trade_wallet_detail atwd on atwd.trade_id = f.flow_id
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
@ -529,12 +564,14 @@
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)
left join acc_trade_wallet_detail atwd on atwd.trade_id = f.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
@ -666,9 +703,11 @@
f.source_type,
f.remark,
f.flow_id,
atwd.wallet_id as walletId,
f.flow_type,
f.pay_time as payTime
FROM report_account_flow f
left join acc_trade_wallet_detail atwd on atwd.trade_id = f.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
@ -708,72 +747,291 @@
</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
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,
t.walletId
FROM cust_org co2
LEFT JOIN (
-- 合并消费和退款
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,
atwd.wallet_id AS walletId
FROM report_account_flow f
LEFT JOIN (
SELECT trade_id, MIN(wallet_id) AS wallet_id
FROM acc_trade_wallet_detail
GROUP BY trade_id
) atwd ON atwd.trade_id = f.flow_id
WHERE f.pay_time &gt;= #{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,
atwd.wallet_id AS walletId
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
LEFT JOIN (
SELECT trade_id, MIN(wallet_id) AS wallet_id
FROM acc_trade_wallet_detail
GROUP BY trade_id
) atwd ON atwd.trade_id = f.flow_id
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 = '')
) 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="selectOrderMismatchList"
resultType="com.bonus.canteen.core.reportforms.beans.ReportOrderInfoVo">
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
cust_num,
cust_name,
mobile,
org_name,
org_full_name,
COUNT(1) AS tradeNum,
order_type,
SUM(payable_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,
co.org_name,
co.org_full_name,
a.payable_amount,
a.real_amount,
a.pay_time,
ac.area_id,
ar.area_name,
p.dining_place_id,
ap.area_name AS work_area_name,
a.mch_sn
FROM (
SELECT
a.order_id, a.cust_id, a.payable_amount, a.real_amount, a.pay_time, a.canteen_id, NULL AS mch_sn
FROM report_order_info a
WHERE a.pay_time >= #{vo.startTime} AND a.pay_time &lt;= #{vo.endTime}
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>
a.flow_id AS order_id,
a.cust_id,
a.flow_amount AS payable_amount,
replace(a.flow_real_amount,'-','') AS real_amount,
a.pay_time,
bd.canteen_id,
a.mch_sn
FROM report_account_flow 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
WHERE a.pay_time >= #{vo.startTime} AND a.pay_time &lt;= #{vo.endTime} AND a.remark LIKE '%支付'
) a
LEFT JOIN report_order_info_snapshot ros ON ros.order_id = a.order_id
LEFT JOIN alloc_canteen ac ON ac.canteen_id = a.canteen_id
LEFT JOIN cust_info ci ON ci.cust_id = a.cust_id
LEFT JOIN cust_org co ON co.org_id = ci.org_id
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 = ac.area_id
LEFT JOIN alloc_area ap ON ap.area_id = p.dining_place_id
WHERE ac.area_id != p.dining_place_id
<!-- 判断消费地 -->
<if test="vo.selectedOrg != null and vo.selectedOrg.length > 0">
AND ac.area_id IN
<foreach collection="vo.selectedOrg" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
<!-- 判断工作地 -->
<if test="vo.gzselectedOrg != null and vo.gzselectedOrg.length > 0">
AND p.dining_place_id IN
<foreach collection="vo.gzselectedOrg" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
) a
GROUP BY cust_id, area_name, work_area_name,order_type
ORDER BY a.pay_time DESC
LIMIT #{offset}, #{pageSize}
</select>
<!-- 查询总数 -->
<select id="selectOrderMismatchListCount" resultType="int">
SELECT COUNT(1) FROM (
SELECT
a.cust_id,
ac.area_id,
ac.canteen_type,
p.dining_place_id
FROM (
SELECT
a.order_id, a.cust_id, a.payable_amount, a.real_amount, a.pay_time, a.canteen_id, NULL AS mch_sn
FROM report_order_info a
WHERE a.pay_time >= #{startTime} AND a.pay_time &lt;= #{endTime}
UNION ALL
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,
bd.canteen_id,
a.mch_sn
FROM report_account_flow 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
WHERE a.pay_time >= #{startTime} AND a.pay_time &lt;= #{endTime} AND a.remark LIKE '%支付'
) a
LEFT JOIN alloc_canteen ac ON ac.canteen_id = a.canteen_id
JOIN cust_info ci ON ci.cust_id = a.cust_id
JOIN cust_dining_place p ON p.cust_id = ci.cust_id AND p.type = 'area'
WHERE ac.area_id != p.dining_place_id
<!-- 判断消费地 -->
<if test="selectedOrg != null and selectedOrg.length > 0">
AND ac.area_id IN
<foreach collection="selectedOrg" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
<!-- 判断工作地 -->
<if test="gzselectedOrg != null and gzselectedOrg.length > 0">
AND p.dining_place_id IN
<foreach collection="gzselectedOrg" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
GROUP BY a.cust_id, ac.area_id, p.dining_place_id,ac.canteen_type
) t
</select>
<select id="selectOrderMismatchListTotal"
resultType="com.bonus.canteen.core.reportforms.beans.ReportOrderInfoVo">
SELECT
SUM(tradeNum) AS tradeNum,
SUM(payable_amount) AS payableAmount,
SUM(real_amount) AS realAmount
FROM (
SELECT
COUNT(1) AS tradeNum,
SUM(a.payable_amount) AS payable_amount,
SUM(a.real_amount) AS real_amount
FROM (
SELECT
a.order_id,
a.cust_id,
a.payable_amount,
a.real_amount,
a.pay_time,
a.canteen_id,
a.mch_sn
FROM (
SELECT
order_id, cust_id, payable_amount, real_amount, pay_time, canteen_id, NULL AS mch_sn
FROM report_order_info
WHERE pay_time >= #{startTime} AND pay_time &lt;= #{endTime}
UNION ALL
SELECT
flow_id AS order_id,
cust_id,
flow_amount AS payable_amount,
replace(flow_real_amount,'-','') AS real_amount,
pay_time,
bd.canteen_id,
mch_sn
FROM report_account_flow 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
WHERE pay_time >= #{startTime} AND pay_time &lt;= #{endTime} AND remark LIKE '%支付'
) 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
JOIN cust_dining_place p ON p.cust_id = ci.cust_id AND p.type = 'area'
WHERE ac.area_id != p.dining_place_id
<!-- 判断消费地 -->
<if test="selectedOrg != null and selectedOrg.length > 0">
AND ac.area_id IN
<foreach collection="selectedOrg" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
<!-- 判断工作地 -->
<if test="gzselectedOrg != null and gzselectedOrg.length > 0">
AND p.dining_place_id IN
<foreach collection="gzselectedOrg" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
) a
) t
</select>
<select id="selectAllareaOrgs" resultType="com.bonus.canteen.core.reportforms.beans.CanteenOrg">
SELECT
area_id AS orgId,
area_name AS orgName,
first_area_name AS orgFullName,
super_id AS superId
FROM alloc_area
WHERE if_del = 2
ORDER BY area_id ASC;
</select>
<select id="exportselectOrderMismatchListTotal"
resultType="com.bonus.canteen.core.reportforms.beans.ReportOrderInfoVo">
</select>
</mapper>

View File

@ -0,0 +1,84 @@
<?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.PlaceMapper">
<select id="placeexportExcel" resultType="com.bonus.canteen.core.reportforms.beans.ReportOrderInfoVo">
SELECT
cust_num,
cust_name,
mobile,
org_name,
org_full_name,
COUNT(1) AS tradeNum,
order_type,
SUM(payable_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,
co.org_name,
co.org_full_name,
a.payable_amount,
a.real_amount,
a.pay_time,
ac.area_id,
ar.area_name,
p.dining_place_id,
ap.area_name AS work_area_name,
a.mch_sn
FROM (
SELECT
a.order_id, a.cust_id, a.payable_amount, a.real_amount, a.pay_time, a.canteen_id, NULL AS mch_sn
FROM report_order_info a
WHERE a.pay_time >= #{startTime} AND a.pay_time &lt;= #{endTime}
UNION ALL
SELECT
a.flow_id AS order_id,
a.cust_id,
a.flow_amount AS payable_amount,
replace(a.flow_real_amount,'-','') AS real_amount,
a.pay_time,
bd.canteen_id,
a.mch_sn
FROM report_account_flow 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
WHERE a.pay_time >= #{startTime} AND a.pay_time &lt;= #{endTime} AND a.remark LIKE '%支付'
) a
LEFT JOIN report_order_info_snapshot ros ON ros.order_id = a.order_id
LEFT JOIN alloc_canteen ac ON ac.canteen_id = a.canteen_id
LEFT JOIN cust_info ci ON ci.cust_id = a.cust_id
LEFT JOIN cust_org co ON co.org_id = ci.org_id
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 = ac.area_id
LEFT JOIN alloc_area ap ON ap.area_id = p.dining_place_id
WHERE ac.area_id != p.dining_place_id
<!-- 判断消费地 -->
<if test="selectedOrg != null and selectedOrg.length > 0">
AND ac.area_id IN
<foreach collection="selectedOrg" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
<!-- 判断工作地 -->
<if test="gzselectedOrg != null and gzselectedOrg.length > 0">
AND p.dining_place_id IN
<foreach collection="gzselectedOrg" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
) a
GROUP BY cust_id, area_name, work_area_name,order_type
ORDER BY a.pay_time DESC
</select>
</mapper>