|
|
@@ -14,6 +14,7 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
import shop.alien.entity.second.SecondGoodsRecord;
|
|
|
import shop.alien.entity.store.*;
|
|
|
import shop.alien.entity.store.dto.LifeUserViolationDto;
|
|
|
@@ -562,66 +563,127 @@ public class LifeUserViolationServiceImpl extends ServiceImpl<LifeUserViolationM
|
|
|
|
|
|
@Override
|
|
|
public String exportExcel(String nickName, String phone, String processingStatus) throws IOException {
|
|
|
- // 定义格式化模式
|
|
|
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
- List<String> MIDs = storeUserService.getIds(nickName, phone);
|
|
|
- List<String> UIDs = lifeUserService.getIds(nickName, phone);
|
|
|
- boolean flag = FunctionMagic.isListFlag(MIDs, UIDs);
|
|
|
- QueryWrapper<LifeUserViolation> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq(StringUtils.isNotEmpty(processingStatus), PROCESSING_STATUS, processingStatus).and(flag, wrapper -> wrapper.nested(wq -> wq.eq(REPORTING_USER_TYPE, "1").in(!MIDs.isEmpty(), REPORTING_USER_ID, MIDs)).or(wq -> wq.eq(REPORTING_USER_TYPE, "2").in(!UIDs.isEmpty(), REPORTING_USER_ID, UIDs))).orderByDesc("updated_time");
|
|
|
- List<LifeUserViolation> resultPage = lifeUserViolationMapper.selectList(queryWrapper);
|
|
|
- List<LifeUserViolationExcelVO> res = Lists.newArrayList();
|
|
|
+ QueryWrapper<LifeUserViolationVo> queryWrapper = new QueryWrapper<>();
|
|
|
+
|
|
|
+ // 基础查询条件(与 getViolationPage 保持一致)
|
|
|
+ queryWrapper.eq("luv.delete_flag", 0)
|
|
|
+ .in("luv.report_context_type", Arrays.asList("1", "2", "3"));
|
|
|
+
|
|
|
+ // 动态查询条件
|
|
|
+ queryWrapper.like(StringUtils.isNotEmpty(nickName), "ui.nick_name", nickName)
|
|
|
+ .like(StringUtils.isNotEmpty(phone), "ui.phone", phone);
|
|
|
+ if (StringUtils.isNotEmpty(processingStatus)) {
|
|
|
+ queryWrapper.eq("luv.processing_status", processingStatus);
|
|
|
+ }
|
|
|
+ queryWrapper.orderByDesc("luv.updated_time");
|
|
|
+
|
|
|
+ List<LifeUserViolationVo> violationList = lifeUserViolationMapper.getViolationList(queryWrapper);
|
|
|
+
|
|
|
+ // 如果查询结果为空,返回空列表生成的Excel
|
|
|
+ if (CollectionUtils.isEmpty(violationList)) {
|
|
|
+ log.warn("导出Excel时查询结果为空,nickName={}, phone={}, processingStatus={}", nickName, phone, processingStatus);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 日期格式化器(复用)
|
|
|
+ DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
+ // 使用Stream API进行转换,提高性能和可读性
|
|
|
AtomicInteger serialNumber = new AtomicInteger(1);
|
|
|
- resultPage.forEach(e -> {
|
|
|
- LifeUserViolationExcelVO dto = new LifeUserViolationExcelVO();
|
|
|
- BeanUtils.copyProperties(e, dto);
|
|
|
- dto.setId(serialNumber.getAndIncrement());
|
|
|
- // 图片
|
|
|
- if (Objects.nonNull(e.getReportEvidenceImg())) {
|
|
|
- String firstPart = e.getReportEvidenceImg().split(",")[0];
|
|
|
- dto.setReportEvidenceImg(firstPart);
|
|
|
+ List<LifeUserViolationExcelVO> excelDataList = violationList.stream()
|
|
|
+ .map(vo -> convertToExcelVO(vo, serialNumber.getAndIncrement(), dateTimeFormatter))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 生成Excel文件
|
|
|
+ String fileName = UUID.randomUUID().toString().replace("-", "");
|
|
|
+ String filePath = ExcelGenerator.generateExcel(
|
|
|
+ excelPath + excelGeneratePath + fileName + ".xlsx",
|
|
|
+ excelDataList,
|
|
|
+ LifeUserViolationExcelVO.class);
|
|
|
+
|
|
|
+ // 上传到OSS并返回URL
|
|
|
+ return aliOSSUtil.uploadFile(new File(filePath), "excel/" + fileName + ".xlsx");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将 LifeUserViolationVo 转换为 LifeUserViolationExcelVO
|
|
|
+ *
|
|
|
+ * @param vo 源对象
|
|
|
+ * @param serialNumber 序号
|
|
|
+ * @param formatter 日期格式化器
|
|
|
+ * @return Excel VO对象
|
|
|
+ */
|
|
|
+ private LifeUserViolationExcelVO convertToExcelVO(LifeUserViolationVo vo, int serialNumber, DateTimeFormatter formatter) {
|
|
|
+ LifeUserViolationExcelVO excelVO = new LifeUserViolationExcelVO();
|
|
|
+ BeanUtils.copyProperties(vo, excelVO);
|
|
|
+
|
|
|
+ excelVO.setId(serialNumber);
|
|
|
+ excelVO.setNickname(vo.getNickName());
|
|
|
+
|
|
|
+ // 处理举报凭证图片(安全分割,避免数组越界)
|
|
|
+ if (StringUtils.isNotEmpty(vo.getReportEvidenceImg())) {
|
|
|
+ String[] imageParts = vo.getReportEvidenceImg().split(",");
|
|
|
+ if (imageParts.length > 0 && StringUtils.isNotEmpty(imageParts[0])) {
|
|
|
+ excelVO.setReportEvidenceImg(imageParts[0].trim());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理举报内容类型
|
|
|
+ if (StringUtils.isNotEmpty(vo.getReportContextType())) {
|
|
|
+ try {
|
|
|
+ excelVO.setReportContextType(FunctionMagic.getContext(vo.getReportContextType()));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("转换举报内容类型失败,reportContextType={}, error={}", vo.getReportContextType(), e.getMessage());
|
|
|
+ excelVO.setReportContextType(vo.getReportContextType());
|
|
|
}
|
|
|
- // 举报内容
|
|
|
- dto.setReportContextType(FunctionMagic.getContext(e.getReportContextType()));
|
|
|
- // 举报理由
|
|
|
- dto.setViolationType(FunctionMagic.violation(e.getViolationType()));
|
|
|
- // 状态
|
|
|
- dto.setProcessingStatus(FunctionMagic.status(e.getProcessingStatus()));
|
|
|
- // 时间
|
|
|
- Instant instant = e.getCreatedTime().toInstant();
|
|
|
- String formattedTime = instant.atZone(ZoneId.systemDefault()).toLocalDateTime().format(formatter);
|
|
|
- dto.setCreatedTime(formattedTime);
|
|
|
- if (Objects.nonNull(e.getProcessingTime())) {
|
|
|
- Instant processing = e.getProcessingTime().toInstant();
|
|
|
- String processingTime = processing.atZone(ZoneId.systemDefault()).toLocalDateTime().format(formatter);
|
|
|
- dto.setProcessingTime(processingTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理举报理由
|
|
|
+ if (StringUtils.isNotEmpty(vo.getViolationType())) {
|
|
|
+ try {
|
|
|
+ excelVO.setViolationType(FunctionMagic.violation(vo.getViolationType()));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("转换举报理由失败,violationType={}, error={}", vo.getViolationType(), e.getMessage());
|
|
|
+ excelVO.setViolationType(vo.getViolationType());
|
|
|
}
|
|
|
- if (e.getReportingUserType().equals("1")) {
|
|
|
- // M
|
|
|
- // 举报人
|
|
|
- StoreUser storeUser = storeUserService.getOne(new QueryWrapper<StoreUser>().eq("id", e.getReportingUserId()));
|
|
|
- dto.setNickname(storeUser.getName());
|
|
|
- dto.setPhone(storeUser.getPhone());
|
|
|
- // 被举报人
|
|
|
- StoreUser reportedUser = storeUserService.getOne(new QueryWrapper<StoreUser>().eq("id", e.getReportedUserId()));
|
|
|
- if (Objects.nonNull(reportedUser)) {
|
|
|
- dto.setReportedAcc(reportedUser.getPhone());
|
|
|
- }
|
|
|
- } else {
|
|
|
- // U
|
|
|
- LifeUser lifeUser = lifeUserService.getOne(new QueryWrapper<LifeUser>().eq("id", e.getReportingUserId()));
|
|
|
- dto.setNickname(lifeUser.getUserName());
|
|
|
- dto.setPhone(lifeUser.getUserPhone());
|
|
|
- LifeUser reportedUser = lifeUserService.getOne(new QueryWrapper<LifeUser>().eq("id", e.getReportedUserId()));
|
|
|
- if (Objects.nonNull(reportedUser)) {
|
|
|
- dto.setReportedAcc(reportedUser.getUserPhone());
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理处理状态
|
|
|
+ if (StringUtils.isNotEmpty(vo.getProcessingStatus())) {
|
|
|
+ try {
|
|
|
+ excelVO.setProcessingStatus(FunctionMagic.status(vo.getProcessingStatus()));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("转换处理状态失败,processingStatus={}, error={}", vo.getProcessingStatus(), e.getMessage());
|
|
|
+ excelVO.setProcessingStatus(vo.getProcessingStatus());
|
|
|
}
|
|
|
- res.add(dto);
|
|
|
- });
|
|
|
- String fileName = UUID.randomUUID().toString().replace("-", "");
|
|
|
- String filePath = ExcelGenerator.generateExcel(excelPath + excelGeneratePath + fileName + ".xlsx", res, LifeUserViolationExcelVO.class);
|
|
|
- return aliOSSUtil.uploadFile(new File(filePath), "excel/" + fileName + ".xlsx");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 格式化创建时间
|
|
|
+ if (Objects.nonNull(vo.getCreatedTime())) {
|
|
|
+ try {
|
|
|
+ String formattedTime = vo.getCreatedTime().toInstant()
|
|
|
+ .atZone(ZoneId.systemDefault())
|
|
|
+ .toLocalDateTime()
|
|
|
+ .format(formatter);
|
|
|
+ excelVO.setCreatedTime(formattedTime);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("格式化创建时间失败,createdTime={}, error={}", vo.getCreatedTime(), e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 格式化处理时间
|
|
|
+ if (Objects.nonNull(vo.getProcessingTime())) {
|
|
|
+ try {
|
|
|
+ String formattedProcessingTime = vo.getProcessingTime().toInstant()
|
|
|
+ .atZone(ZoneId.systemDefault())
|
|
|
+ .toLocalDateTime()
|
|
|
+ .format(formatter);
|
|
|
+ excelVO.setProcessingTime(formattedProcessingTime);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("格式化处理时间失败,processingTime={}, error={}", vo.getProcessingTime(), e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return excelVO;
|
|
|
}
|
|
|
|
|
|
@Override
|