导出报表 11点报表
This commit is contained in:
@@ -6,12 +6,15 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.rj.entity.LbDailyUserTrade;
|
||||
import com.rj.entity.LbDailyUserTradeReport;
|
||||
import com.rj.entity.LbDepartmentUser;
|
||||
import com.rj.service.ILbDeductionAmountService;
|
||||
import com.rj.mapper.LbDailyUserTradeMapper;
|
||||
import com.rj.mapper.LbDailyUserTradeReportMapper;
|
||||
import com.rj.service.ILbDailyUserTradeReportService;
|
||||
import com.rj.service.ILbDepartmentUserService;
|
||||
import com.rj.service.support.LbDailyUserTradeReportExportSupport;
|
||||
import com.rj.service.support.LbDailyUserTradeReportWriteSupport;
|
||||
import com.rj.tenant.TenantContextHolder;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -53,6 +56,8 @@ public class LbDailyUserTradeReportServiceImpl extends ServiceImpl<LbDailyUserTr
|
||||
private LbDailyUserTradeMapper lbDailyUserTradeMapper;
|
||||
@Autowired
|
||||
private PlatformTransactionManager transactionManager;
|
||||
@Autowired
|
||||
private ILbDeductionAmountService lbDeductionAmountService;
|
||||
|
||||
@Override
|
||||
public Page<LbDailyUserTrade> pageDailyUserTradeByUserIdAndDateRange(
|
||||
@@ -498,6 +503,60 @@ public class LbDailyUserTradeReportServiceImpl extends ServiceImpl<LbDailyUserTr
|
||||
checkInfo.put("detailCheckPassed", mismatchUsers.isEmpty() && missingInTodayUsers.isEmpty() && extraInTodayUsers.isEmpty());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportByDateAndTenant(String reportDate, String tenantId, HttpServletResponse response) {
|
||||
try {
|
||||
if (tenantId == null || tenantId.trim().isEmpty()) {
|
||||
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "tenantId不能为空");
|
||||
return;
|
||||
}
|
||||
if (reportDate == null || reportDate.trim().isEmpty()) {
|
||||
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "reportDate不能为空");
|
||||
return;
|
||||
}
|
||||
|
||||
LocalDate parsedReportDate;
|
||||
try {
|
||||
parsedReportDate = LocalDate.parse(reportDate.trim());
|
||||
} catch (Exception e) {
|
||||
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "报表日期格式错误,请使用 yyyy-MM-dd");
|
||||
return;
|
||||
}
|
||||
|
||||
String tenantIdTrim = tenantId.trim();
|
||||
List<LbDailyUserTradeReport> rows = listReportsForExport(tenantIdTrim, parsedReportDate);
|
||||
Map<String, BigDecimal> deductionByUserName =
|
||||
lbDeductionAmountService.sumDikouAmtByUserNameForReportDate(tenantIdTrim, parsedReportDate);
|
||||
LbDailyUserTradeReportExportSupport.writeExcel(
|
||||
parsedReportDate, rows, deductionByUserName, response);
|
||||
} catch (Exception e) {
|
||||
LbDailyUserTradeReportExportSupport.writeExportError(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
private List<LbDailyUserTradeReport> listReportsForExport(String tenantId, LocalDate reportDate) {
|
||||
LocalDateTime start = reportDate.atStartOfDay();
|
||||
LocalDateTime end = reportDate.plusDays(1).atStartOfDay();
|
||||
|
||||
LambdaQueryWrapper<LbDailyUserTradeReport> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(LbDailyUserTradeReport::getTenantId, tenantId)
|
||||
.ge(LbDailyUserTradeReport::getReportDate, start)
|
||||
.lt(LbDailyUserTradeReport::getReportDate, end)
|
||||
.orderByDesc(LbDailyUserTradeReport::getCreatedAt);
|
||||
|
||||
List<LbDailyUserTradeReport> rows = list(queryWrapper);
|
||||
rows.sort(
|
||||
Comparator
|
||||
.comparingInt((LbDailyUserTradeReport o) -> DATA_TYPE_REPORT_SUM.equals(o.getDataType()) ? 1 : 0)
|
||||
.thenComparing((a, b) -> {
|
||||
BigDecimal da = a.getDiffAmt() == null ? BigDecimal.ZERO : a.getDiffAmt();
|
||||
BigDecimal db = b.getDiffAmt() == null ? BigDecimal.ZERO : b.getDiffAmt();
|
||||
return db.compareTo(da);
|
||||
})
|
||||
);
|
||||
return rows;
|
||||
}
|
||||
|
||||
private static final class DetailRepairStat {
|
||||
final boolean repaired;
|
||||
final int updatedCount;
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -429,6 +430,30 @@ public class LbDeductionAmountServiceImpl
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, BigDecimal> sumDikouAmtByUserNameForReportDate(String tenantId, LocalDate reportDate) {
|
||||
Map<String, BigDecimal> byUserName = new HashMap<>();
|
||||
if (tenantId == null || tenantId.trim().isEmpty() || reportDate == null) {
|
||||
return byUserName;
|
||||
}
|
||||
LocalDateTime start = reportDate.atStartOfDay();
|
||||
LocalDateTime end = reportDate.plusDays(1).atStartOfDay();
|
||||
LambdaQueryWrapper<LbDeductionAmount> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(LbDeductionAmount::getTenantId, tenantId.trim())
|
||||
.ge(LbDeductionAmount::getCreateTime, start)
|
||||
.lt(LbDeductionAmount::getCreateTime, end);
|
||||
List<LbDeductionAmount> records = list(queryWrapper);
|
||||
for (LbDeductionAmount record : records) {
|
||||
if (record.getUserName() == null || record.getUserName().trim().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
String key = record.getUserName().trim();
|
||||
BigDecimal amt = record.getDikouAmt() == null ? BigDecimal.ZERO : record.getDikouAmt();
|
||||
byUserName.merge(key, amt, BigDecimal::add);
|
||||
}
|
||||
return byUserName;
|
||||
}
|
||||
|
||||
private static LocalDateTime parseDateTime(String text) {
|
||||
if (text == null || text.trim().isEmpty()) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user