refactor(backend): 引入 BeanCopyUtils、统一账户 VO 并清理遗留代码与未使用注入以消除编译/IDE 警告

This commit is contained in:
小蟑螂
2026-06-03 16:29:04 +08:00
parent b19f6d60f9
commit 28fba73928
63 changed files with 323 additions and 831 deletions
+3
View File
@@ -0,0 +1,3 @@
{
"java.compile.nullAnalysis.mode": "automatic"
}
+13
View File
@@ -19,7 +19,20 @@
<maven.compiler.target>17</maven.compiler.target>
<lombok.version>1.18.30</lombok.version>
<mybatis-plus.version>3.5.5</mybatis-plus.version>
<!-- 统一 httpclient 版本,消除 aliyun-sdk-oss 传递依赖 4.5.13/4.5.14 冲突 -->
<httpclient.version>4.5.14</httpclient.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!--Spring Boot Web启动器-->
<dependency>
@@ -1,6 +1,7 @@
package top.xyquan.ecomdmbbackend.common.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.lang.NonNull;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@@ -12,7 +13,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
public class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
public void addResourceHandlers(@NonNull ResourceHandlerRegistry registry) {
// 配置静态资源处理
registry.addResourceHandler("/static/**")
.addResourceLocations("classpath:/static/");
@@ -30,7 +31,7 @@ public class WebConfig implements WebMvcConfigurer {
}
@Override
public void addCorsMappings(CorsRegistry registry) {
public void addCorsMappings(@NonNull CorsRegistry registry) {
registry.addMapping("/**")
.allowedOriginPatterns("*")
.allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS")
@@ -4,9 +4,9 @@ import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.lang.NonNull;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.filter.OncePerRequestFilter;
@@ -27,13 +27,16 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
}
@Override
protected boolean shouldNotFilter(HttpServletRequest request) {
protected boolean shouldNotFilter(@NonNull HttpServletRequest request) {
String uri = request.getRequestURI();
return uri != null && uri.startsWith("/open/");
}
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
protected void doFilterInternal(
@NonNull HttpServletRequest request,
@NonNull HttpServletResponse response,
@NonNull FilterChain filterChain)
throws ServletException, IOException {
// 添加调试日志
@@ -0,0 +1,31 @@
package top.xyquan.ecomdmbbackend.common.utils;
import org.springframework.beans.BeanUtils;
import java.util.Objects;
/**
* 属性拷贝工具:在调用 Spring {@link BeanUtils#copyProperties} 前断言 source/target 非空,
* 消除 IDE 空值分析对 {@code BeanUtils.copyProperties} 入参的 Null type safety 警告。
*/
public final class BeanCopyUtils {
private BeanCopyUtils() {
}
public static void copyProperties(Object source, Object target) {
BeanUtils.copyProperties(Objects.requireNonNull(source), Objects.requireNonNull(target));
}
public static void copyProperties(Object source, Object target, String... ignoreProperties) {
Object nonNullSource = Objects.requireNonNull(source);
Object nonNullTarget = Objects.requireNonNull(target);
// varargs 在分析器里可能是可空数组,需显式断言后再传给 Spring
String[] nonNullIgnores = Objects.requireNonNull(ignoreProperties);
if (nonNullIgnores.length == 0) {
BeanUtils.copyProperties(nonNullSource, nonNullTarget);
return;
}
BeanUtils.copyProperties(nonNullSource, nonNullTarget, nonNullIgnores);
}
}
@@ -1,10 +1,10 @@
package top.xyquan.ecomdmbbackend.modules.ecom.brushorder.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
@@ -150,7 +150,7 @@ public class BrushOrderServiceImpl extends ServiceImpl<BrushOrderMapper, BrushOr
// 更新刷单记录
BrushOrderPO before = new BrushOrderPO();
BeanUtils.copyProperties(existingBrushOrder, before);
BeanCopyUtils.copyProperties(existingBrushOrder, before);
existingBrushOrder.setShopId(updateBrushOrderDTO.getShopId());
existingBrushOrder.setProductId(updateBrushOrderDTO.getProductId());
existingBrushOrder.setProductSpecId(updateBrushOrderDTO.getProductSpecId());
@@ -275,7 +275,7 @@ public class BrushOrderServiceImpl extends ServiceImpl<BrushOrderMapper, BrushOr
*/
private BrushOrderVO convertToVO(BrushOrderPO brushOrder) {
BrushOrderVO brushOrderVO = new BrushOrderVO();
BeanUtils.copyProperties(brushOrder, brushOrderVO);
BeanCopyUtils.copyProperties(brushOrder, brushOrderVO);
// 设置店铺名称
ShopPO shop = shopService.getById(brushOrder.getShopId());
@@ -1,10 +1,10 @@
package top.xyquan.ecomdmbbackend.modules.ecom.category.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
@@ -256,7 +256,7 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, CategoryPO>
private CategoryVO convertToVO(CategoryPO po, Map<Long, String> parentNameMap) {
CategoryVO vo = new CategoryVO();
BeanUtils.copyProperties(po, vo);
BeanCopyUtils.copyProperties(po, vo);
if (po.getParentId() != null) {
vo.setParentName(parentNameMap.getOrDefault(po.getParentId(), null));
}
@@ -1,10 +1,10 @@
package top.xyquan.ecomdmbbackend.modules.ecom.importmapping.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
@@ -58,7 +58,7 @@ public class ImportMappingServiceImpl extends ServiceImpl<ImportMappingMapper, I
// 创建导入映射模板
ImportMappingPO importMappingPO = new ImportMappingPO();
BeanUtils.copyProperties(createImportMappingDTO, importMappingPO);
BeanCopyUtils.copyProperties(createImportMappingDTO, importMappingPO);
importMappingPO.setCompanyId(companyId);
importMappingPO.setCreateBy(currentUserContext.getCurrentUserId());
@@ -105,7 +105,7 @@ public class ImportMappingServiceImpl extends ServiceImpl<ImportMappingMapper, I
// 更新模板
ImportMappingPO importMappingPO = new ImportMappingPO();
BeanUtils.copyProperties(updateImportMappingDTO, importMappingPO);
BeanCopyUtils.copyProperties(updateImportMappingDTO, importMappingPO);
importMappingPO.setId(id);
importMappingPO.setUpdateBy(currentUserContext.getCurrentUserId());
@@ -183,7 +183,7 @@ public class ImportMappingServiceImpl extends ServiceImpl<ImportMappingMapper, I
*/
private ImportMappingVO convertToVO(ImportMappingPO importMappingPO) {
ImportMappingVO importMappingVO = new ImportMappingVO();
BeanUtils.copyProperties(importMappingPO, importMappingVO);
BeanCopyUtils.copyProperties(importMappingPO, importMappingVO);
return importMappingVO;
}
}
@@ -5,7 +5,6 @@ import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductPO;
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSpecPO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.po.ShopProductRelationPO;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
@@ -1,5 +1,6 @@
package top.xyquan.ecomdmbbackend.modules.ecom.importtask.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.ibatis.session.SqlSessionFactory;
@@ -16,15 +17,11 @@ import top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.order.stat.service.FeeStatRefreshService;
import top.xyquan.ecomdmbbackend.modules.ecom.order.stat.service.OrderStatRefreshCoordinator;
import top.xyquan.ecomdmbbackend.modules.ecom.order.stat.support.RefreshSource;
import top.xyquan.ecomdmbbackend.modules.ecom.order.service.OrderService;
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.service.OrderStatusService;
import top.xyquan.ecomdmbbackend.modules.ecom.product.mapper.ProductMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductService;
import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductSpecService;
import top.xyquan.ecomdmbbackend.modules.ecom.promotion.service.impl.PromotionFeeImportProcessor;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.mapper.ShopProductRelationMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.po.ShopPO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.service.ShopService;
import top.xyquan.ecomdmbbackend.modules.sys.file.service.OssService;
import top.xyquan.ecomdmbbackend.modules.sys.file.service.SysFileService;
import top.xyquan.ecomdmbbackend.modules.sys.file.model.vo.SysFileVO;
@@ -56,32 +53,22 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
private static final Logger log = LoggerFactory.getLogger(ImportTaskProcessorServiceImpl.class);
private final ImportTaskService importTaskService;
private final ProductSpecService productSpecService;
private final OrderMapper orderMapper;
private final ProductMapper productMapper;
private final ShopService shopService;
private final ShopProductRelationMapper shopProductRelationMapper;
private final SseNotificationService sseNotificationService;
private final ObjectMapper objectMapper;
private final OrderStatusService orderStatusService;
private final SqlSessionFactory sqlSessionFactory;
private final OssService ossService;
private final SysFileService sysFileService;
// 提取出的处理器
// 提取出的处理器(构造时组装,不单独持有 helper 的中间依赖)
private final OrderImportProcessor orderImportProcessor;
private final ProductSpecImportHelper productSpecImportHelper;
private final PromotionFeeImportProcessor promotionFeeImportProcessor;
private final OrderStatRefreshCoordinator orderStatRefreshCoordinator;
private final FeeStatRefreshService feeStatRefreshService;
public ImportTaskProcessorServiceImpl(ImportTaskService importTaskService,
OrderService orderService,
ProductService productService,
ProductSpecService productSpecService,
OrderMapper orderMapper,
ProductMapper productMapper,
ShopService shopService,
ShopProductRelationMapper shopProductRelationMapper,
SseNotificationService sseNotificationService,
ObjectMapper objectMapper,
@@ -93,23 +80,16 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
OrderStatRefreshCoordinator orderStatRefreshCoordinator,
FeeStatRefreshService feeStatRefreshService) {
this.importTaskService = importTaskService;
this.productSpecService = productSpecService;
this.orderMapper = orderMapper;
this.productMapper = productMapper;
this.shopService = shopService;
this.shopProductRelationMapper = shopProductRelationMapper;
this.sseNotificationService = sseNotificationService;
this.objectMapper = objectMapper;
this.orderStatusService = orderStatusService;
this.sqlSessionFactory = sqlSessionFactory;
this.ossService = ossService;
this.sysFileService = sysFileService;
this.promotionFeeImportProcessor = promotionFeeImportProcessor;
this.orderStatRefreshCoordinator = orderStatRefreshCoordinator;
this.feeStatRefreshService = feeStatRefreshService;
// 初始化 helper 和 processor
this.productSpecImportHelper = new ProductSpecImportHelper(
ProductSpecImportHelper productSpecImportHelper = new ProductSpecImportHelper(
productMapper, productSpecService, orderStatusService, shopProductRelationMapper);
this.orderImportProcessor = new OrderImportProcessor(
productSpecImportHelper, orderMapper, shopProductRelationMapper, sqlSessionFactory);
@@ -177,8 +157,8 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
String storagePath = fileInfo.getStoragePath();
String storageType = fileInfo.getStorageType();
String filename = fileInfo.getFilename();
boolean isExcel = filename != null && (filename.toLowerCase().endsWith(".xlsx") || filename.toLowerCase().endsWith(".xls"));
String filename = fileInfo.getFilename() != null ? fileInfo.getFilename() : "";
boolean isExcel = filename.toLowerCase().endsWith(".xlsx") || filename.toLowerCase().endsWith(".xls");
String fileExt = isExcel ? (filename.toLowerCase().endsWith(".xlsx") ? ".xlsx" : ".xls") : ".csv";
InputStream fileInputStream;
@@ -300,8 +280,8 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
String storagePath = fileInfo.getStoragePath();
String storageType = fileInfo.getStorageType();
String filename = fileInfo.getFilename();
boolean isExcel = filename != null && (filename.toLowerCase().endsWith(".xlsx") || filename.toLowerCase().endsWith(".xls"));
String filename = fileInfo.getFilename() != null ? fileInfo.getFilename() : "";
boolean isExcel = filename.toLowerCase().endsWith(".xlsx") || filename.toLowerCase().endsWith(".xls");
if ("local".equals(storageType)) {
File localFile = new File(storagePath);
@@ -444,7 +424,7 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
private ImportTaskVO convertToVO(ImportTaskPO importTaskPO) {
if (importTaskPO == null) return null;
ImportTaskVO vo = new ImportTaskVO();
org.springframework.beans.BeanUtils.copyProperties(importTaskPO, vo);
BeanCopyUtils.copyProperties(importTaskPO, vo);
return vo;
}
@@ -1,10 +1,10 @@
package top.xyquan.ecomdmbbackend.modules.ecom.importtask.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionSynchronizationManager;
@@ -63,7 +63,7 @@ public class ImportTaskServiceImpl extends ServiceImpl<ImportTaskMapper, ImportT
// 创建导入任务
ImportTaskPO importTaskPO = new ImportTaskPO();
BeanUtils.copyProperties(createImportTaskDTO, importTaskPO);
BeanCopyUtils.copyProperties(createImportTaskDTO, importTaskPO);
importTaskPO.setCompanyId(companyId);
importTaskPO.setTaskName(generateTaskName(companyId, createImportTaskDTO.getType()));
importTaskPO.setStatus("pending"); // 初始状态为待处理
@@ -139,7 +139,7 @@ public class ImportTaskServiceImpl extends ServiceImpl<ImportTaskMapper, ImportT
*/
private ImportTaskVO convertToVO(ImportTaskPO importTaskPO) {
ImportTaskVO importTaskVO = new ImportTaskVO();
BeanUtils.copyProperties(importTaskPO, importTaskVO);
BeanCopyUtils.copyProperties(importTaskPO, importTaskVO);
if (importTaskPO.getShopId() != null) {
ShopPO shop = shopService.getById(importTaskPO.getShopId());
if (shop != null) {
@@ -1,7 +1,5 @@
package top.xyquan.ecomdmbbackend.modules.ecom.importtask.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
@@ -24,7 +22,6 @@ import java.nio.charset.Charset;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.*;
import java.util.function.Function;
@@ -32,13 +29,8 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import java.io.IOException;
/**
* 订单导入核心处理器(并行版本)
* <p>
@@ -51,7 +43,6 @@ public class OrderImportProcessor {
private static final int ORDER_BATCH_SIZE = 200;
private static final int RELATION_BATCH_SIZE = 500;
private static final int IN_QUERY_BATCH_SIZE = 1000;
private static final int PARALLELISM = 4; // Worker 线程数
private static final int WORKER_TERMINATE_TIMEOUT_SEC = 60; // awaitTermination 超时
@@ -75,35 +66,6 @@ public class OrderImportProcessor {
/**
* 队列元素:原始 CSV 行数据(由主线程解析出,传递给 workers)
*/
/** Excel 行数据包装器(用于替代 CSVRecord) */
public static class ExcelRow {
private final Map<String, String> rowData;
private final List<String> orderedHeaders;
public ExcelRow(Map<String, String> rowData, List<String> orderedHeaders) {
this.rowData = rowData;
this.orderedHeaders = orderedHeaders;
}
public String get(String header) {
if (header == null) return null;
String v = rowData.get(header);
if (v != null) return v;
String normalized = normalizeHeader(header);
for (Map.Entry<String, String> e : rowData.entrySet()) {
if (normalizeHeader(e.getKey()).equals(normalized)) {
return e.getValue();
}
}
return null;
}
public boolean isEmpty(String header) {
String v = get(header);
return v == null || v.trim().isEmpty();
}
}
public static class PendingRow {
public final int rowNumber;
/** 原始行数据(CSV → Map via csvRecordToMap;Excel → 直接为 Map) */
@@ -930,11 +892,6 @@ public class OrderImportProcessor {
CreateOrderDTO dto = row.dto;
Long companyId = row.companyId;
String specCode = dto.getPlatformOrderNo() != null ? null : null; // DTO中无specCode,需从record重新获取
// 重新从 CSVRecord 获取 specCode(Worker 不能直接访问 CSVRecordParser)
// 方案:从 DTO 中取,或者在 parseOrderFromCSV 时预存
// 由于 parseOrderFromCSV 已填充了 productSpecId 等,此处只处理找不到的情况
if (dto.getProductSpecId() == null) {
// 重新获取关键字段
String specCodeRaw = getValue(row.rowData, row.fieldMapping.get("spec_code"));
@@ -1101,22 +1058,6 @@ public class OrderImportProcessor {
return workerFailCount;
}
/**
* 等待 workers 把当前 pendingOrders 消费完(flushed)
* 通过轮询 pendingOrders size 为 0 实现,最多等待 30 秒
*/
private void waitForBatchFlush(ImportRuntimeContext context) {
long deadline = System.currentTimeMillis() + 30_000;
while (context.pendingOrders.size() > 0 && System.currentTimeMillis() < deadline) {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
}
}
private int[] doFlushPendingOrders(ImportRuntimeContext context, StringBuilder errorMessages) {
synchronized (context.pendingOrders) {
if (context.pendingOrders.isEmpty()) {
@@ -1846,16 +1787,6 @@ public class OrderImportProcessor {
}
}
private String getValue(CSVRecord record, String header) {
if (header == null || header.trim().isEmpty()) return null;
try {
String val = record.get(header.trim());
return (val != null && !val.trim().isEmpty()) ? val.trim() : null;
} catch (IllegalArgumentException e) {
return null;
}
}
private static String normalizeHeader(String header) {
if (header == null) return "";
return header.replace("\uFEFF", "")
@@ -3,6 +3,7 @@ package top.xyquan.ecomdmbbackend.modules.ecom.importtask.service.impl;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import top.xyquan.ecomdmbbackend.modules.ecom.importtask.model.po.ImportTaskPO;
@@ -14,6 +15,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.*;
/**
@@ -129,7 +131,7 @@ public class SseNotificationServiceImpl implements SseNotificationService {
);
emitter.send(SseEmitter.event()
.name("message")
.data(objectMapper.writeValueAsString(msg)));
.data(Objects.requireNonNull(serializeForSse(msg))));
} catch (IOException e) {
logger.error("发送初始SSE消息失败,userId={}, deviceId={}", userId, deviceId, e);
entries.remove(newEntry);
@@ -233,7 +235,7 @@ public class SseNotificationServiceImpl implements SseNotificationService {
try {
entry.emitter.send(SseEmitter.event()
.name("ping")
.data(objectMapper.writeValueAsString(pingMsg)));
.data(Objects.requireNonNull(serializeForSse(pingMsg))));
entry.lastHeartbeat = System.currentTimeMillis();
} catch (IOException e) {
logger.debug("心跳发送失败,移除连接,userId={}, deviceId={}", userId, entry.deviceId);
@@ -280,7 +282,7 @@ public class SseNotificationServiceImpl implements SseNotificationService {
try {
entry.emitter.send(SseEmitter.event()
.name("task_progress")
.data(objectMapper.writeValueAsString(progressMsg)));
.data(Objects.requireNonNull(serializeForSse(progressMsg))));
} catch (IOException e) {
logger.debug("发送任务进度失败,移除连接,userId={}, deviceId={}", userId, entry.deviceId);
deadEntries.add(entry);
@@ -330,7 +332,7 @@ public class SseNotificationServiceImpl implements SseNotificationService {
try {
entry.emitter.send(SseEmitter.event()
.name("all_tasks_completed")
.data(objectMapper.writeValueAsString(msg)));
.data(Objects.requireNonNull(serializeForSse(msg))));
} catch (IOException e) {
deadEntries.add(entry);
}
@@ -362,6 +364,11 @@ public class SseNotificationServiceImpl implements SseNotificationService {
// ==================== 查询 ====================
/** 序列化 SSE 载荷;@NonNull 满足 IDE 对 SseEmitter.data(@NonNull Object) 的空值分析 */
private @NonNull String serializeForSse(Object payload) throws IOException {
return Objects.requireNonNull(objectMapper.writeValueAsString(payload));
}
@Override
public boolean hasActiveTasks(Long userId) {
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<ImportTaskPO> wrapper =
@@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderPO;
import top.xyquan.ecomdmbbackend.modules.ecom.order.stat.model.OrderShopStatDateRow;
@@ -1,10 +1,10 @@
package top.xyquan.ecomdmbbackend.modules.ecom.order.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
@@ -235,7 +235,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
// 更新订单
OrderPO order = new OrderPO();
BeanUtils.copyProperties(updateOrderDTO, order);
BeanCopyUtils.copyProperties(updateOrderDTO, order);
order.setId(id);
order.setCompanyId(companyId);
@@ -453,7 +453,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
*/
private OrderVO convertToVO(OrderPO order) {
OrderVO orderVO = new OrderVO();
BeanUtils.copyProperties(order, orderVO);
BeanCopyUtils.copyProperties(order, orderVO);
// 设置状态信息
if (order.getStatusId() != null) {
@@ -461,7 +461,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
if (orderStatus != null) {
orderVO.setStatusName(orderStatus.getStatusName());
OrderStatusVO orderStatusVO = new OrderStatusVO();
BeanUtils.copyProperties(orderStatus, orderStatusVO);
BeanCopyUtils.copyProperties(orderStatus, orderStatusVO);
orderVO.setOrderStatus(orderStatusVO);
}
}
@@ -471,7 +471,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
if (shop != null) {
orderVO.setShopName(shop.getName());
ShopVO shopVO = new ShopVO();
BeanUtils.copyProperties(shop, shopVO);
BeanCopyUtils.copyProperties(shop, shopVO);
orderVO.setShop(shopVO);
}
@@ -480,13 +480,13 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
ProductSpecPO productSpec = productSpecService.getById(order.getProductSpecId());
if (productSpec != null) {
ProductSpecVO productSpecVO = new ProductSpecVO();
BeanUtils.copyProperties(productSpec, productSpecVO);
BeanCopyUtils.copyProperties(productSpec, productSpecVO);
orderVO.setProductSpec(productSpecVO);
if (productSpec.getProductId() != null) {
ProductPO product = productService.getById(productSpec.getProductId());
if (product != null) {
ProductVO productVO = new ProductVO();
BeanUtils.copyProperties(product, productVO);
BeanCopyUtils.copyProperties(product, productVO);
orderVO.setProduct(productVO);
}
}
@@ -3,10 +3,12 @@ package top.xyquan.ecomdmbbackend.modules.ecom.order.stat.service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service;
import top.xyquan.ecomdmbbackend.modules.ecom.order.stat.config.OrderStatProperties;
import java.time.LocalDate;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
/**
@@ -19,10 +21,10 @@ public class OrderStatCacheService {
private static final String KEY_PREFIX = "order-stat:read:";
private final OrderStatProperties properties;
private final RedisTemplate<String, Object> redisTemplate;
private final @NonNull RedisTemplate<String, Object> redisTemplate;
public OrderStatCacheService(OrderStatProperties properties,
RedisTemplate<String, Object> redisTemplate) {
@NonNull RedisTemplate<String, Object> redisTemplate) {
this.properties = properties;
this.redisTemplate = redisTemplate;
}
@@ -33,11 +35,15 @@ public class OrderStatCacheService {
/** 写入缓存(Query 层按需调用) */
public void put(String cacheKey, Object value, long ttlSeconds) {
if (!isEnabled() || cacheKey == null) {
if (!isEnabled() || cacheKey == null || value == null) {
return;
}
try {
redisTemplate.opsForValue().set(KEY_PREFIX + cacheKey, value, ttlSeconds, TimeUnit.SECONDS);
redisTemplate.opsForValue().set(
KEY_PREFIX + cacheKey,
Objects.requireNonNull(value),
ttlSeconds,
TimeUnit.SECONDS);
} catch (Exception e) {
log.debug("order-stat cache put skip: {}", cacheKey, e);
}
@@ -5,7 +5,6 @@ import top.xyquan.ecomdmbbackend.modules.ecom.order.status.support.OrderStatusSt
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
/** 将 OrderStatusStatSets 转为 MyBatis IN 列表参数。 */
public final class OrderStatParamHelper {
@@ -1,8 +1,8 @@
package top.xyquan.ecomdmbbackend.modules.ecom.order.status.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -63,7 +63,7 @@ public class OrderStatusServiceImpl extends ServiceImpl<OrderStatusMapper, Order
// 创建订单状态
OrderStatusPO orderStatus = new OrderStatusPO();
BeanUtils.copyProperties(createOrderStatusDTO, orderStatus);
BeanCopyUtils.copyProperties(createOrderStatusDTO, orderStatus);
orderStatus.setCompanyId(companyId);
// 设置默认值
@@ -115,7 +115,7 @@ public class OrderStatusServiceImpl extends ServiceImpl<OrderStatusMapper, Order
// 更新订单状态
OrderStatusPO orderStatus = new OrderStatusPO();
BeanUtils.copyProperties(updateOrderStatusDTO, orderStatus);
BeanCopyUtils.copyProperties(updateOrderStatusDTO, orderStatus);
orderStatus.setId(id);
orderStatus.setCompanyId(companyId);
@@ -250,7 +250,7 @@ public class OrderStatusServiceImpl extends ServiceImpl<OrderStatusMapper, Order
*/
private OrderStatusVO convertToVO(OrderStatusPO orderStatus) {
OrderStatusVO vo = new OrderStatusVO();
BeanUtils.copyProperties(orderStatus, vo);
BeanCopyUtils.copyProperties(orderStatus, vo);
return vo;
}
@@ -1,46 +1,27 @@
package top.xyquan.ecomdmbbackend.modules.ecom.overview.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
import top.xyquan.ecomdmbbackend.modules.ecom.brushorder.mapper.BrushOrderMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.brushorder.model.po.BrushOrderPO;
import top.xyquan.ecomdmbbackend.modules.ecom.category.model.po.CategoryPO;
import top.xyquan.ecomdmbbackend.modules.ecom.category.service.CategoryService;
import top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderPO;
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.support.OrderStatusStatSets;
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.CategoryExportDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.ShopOverviewQueryDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.vo.CompanyOverviewVO;
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.vo.ShopOverviewStatisticsVO;
import top.xyquan.ecomdmbbackend.modules.ecom.overview.service.CategoryExportExcelService;
import top.xyquan.ecomdmbbackend.modules.ecom.overview.service.ShopOverviewStatisticsService;
import top.xyquan.ecomdmbbackend.modules.ecom.product.mapper.ProductSpecMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductPO;
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSpecPO;
import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductService;
import top.xyquan.ecomdmbbackend.modules.ecom.promotion.mapper.PromotionFeeMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.promotion.model.po.PromotionFeePO;
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
import java.io.ByteArrayOutputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
@@ -61,33 +42,12 @@ public class CategoryExportExcelServiceImpl implements CategoryExportExcelServic
return base.multiply(r).setScale(2, RoundingMode.HALF_UP);
}
private final CurrentUserContext currentUserContext;
private final OrderMapper orderMapper;
private final PromotionFeeMapper promotionFeeMapper;
private final BrushOrderMapper brushOrderMapper;
private final ProductService productService;
private final ProductSpecMapper productSpecMapper;
private final CategoryService categoryService;
private final ExportStatusRangeHelper exportStatusRangeHelper;
private final ShopOverviewStatisticsService shopOverviewStatisticsService;
public CategoryExportExcelServiceImpl(
CurrentUserContext currentUserContext,
OrderMapper orderMapper,
PromotionFeeMapper promotionFeeMapper,
BrushOrderMapper brushOrderMapper,
ProductService productService,
ProductSpecMapper productSpecMapper,
CategoryService categoryService,
ExportStatusRangeHelper exportStatusRangeHelper,
ShopOverviewStatisticsService shopOverviewStatisticsService) {
this.currentUserContext = currentUserContext;
this.orderMapper = orderMapper;
this.promotionFeeMapper = promotionFeeMapper;
this.brushOrderMapper = brushOrderMapper;
this.productService = productService;
this.productSpecMapper = productSpecMapper;
this.categoryService = categoryService;
this.exportStatusRangeHelper = exportStatusRangeHelper;
this.shopOverviewStatisticsService = shopOverviewStatisticsService;
}
@@ -577,31 +577,6 @@ public class ExportServiceImpl implements ExportService {
return style;
}
private CellStyle createLabelStyle(Workbook workbook) {
CellStyle style = workbook.createCellStyle();
Font font = workbook.createFont();
font.setBold(true);
style.setFont(font);
style.setBorderBottom(BorderStyle.THIN);
style.setBorderTop(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
return style;
}
private CellStyle createValueStyle(Workbook workbook) {
CellStyle style = workbook.createCellStyle();
style.setBorderBottom(BorderStyle.THIN);
style.setBorderTop(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
return style;
}
private CellStyle createDataStyle(Workbook workbook) {
CellStyle style = workbook.createCellStyle();
style.setBorderBottom(BorderStyle.THIN);
@@ -635,12 +610,6 @@ public class ExportServiceImpl implements ExportService {
cell.setCellStyle(style);
}
private void setCell(Row row, int col, int value, CellStyle style) {
Cell cell = row.createCell(col);
cell.setCellValue(value);
cell.setCellStyle(style);
}
@Override
public byte[] exportPlatformOverview(PlatformExportDTO dto) {
BigDecimal taxRate = dto.getTaxRate() != null ? dto.getTaxRate() : DEFAULT_TAX_RATE;
@@ -410,16 +410,6 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
return netSales.divide(promotionFee, 2, RoundingMode.HALF_UP);
}
/**
* 计算ROI
*/
private BigDecimal calculateROI(BigDecimal profit, BigDecimal totalCost) {
if (totalCost.compareTo(BigDecimal.ZERO) <= 0) {
return BigDecimal.ZERO;
}
return profit.divide(totalCost, 2, RoundingMode.HALF_UP);
}
private Map<Long, Long> orderSpecIdToProductIdMap(List<OrderPO> orders) {
List<Long> specIds = orders.stream()
.map(OrderPO::getProductSpecId)
@@ -1,10 +1,10 @@
package top.xyquan.ecomdmbbackend.modules.ecom.platform.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
@@ -57,7 +57,7 @@ public class PlatformServiceImpl extends ServiceImpl<PlatformMapper, PlatformPO>
// 创建平台
PlatformPO platform = new PlatformPO();
BeanUtils.copyProperties(createPlatformDTO, platform);
BeanCopyUtils.copyProperties(createPlatformDTO, platform);
platform.setCompanyId(companyId);
// 设置默认值
@@ -109,7 +109,7 @@ public class PlatformServiceImpl extends ServiceImpl<PlatformMapper, PlatformPO>
// 更新平台
PlatformPO platform = new PlatformPO();
BeanUtils.copyProperties(updatePlatformDTO, platform);
BeanCopyUtils.copyProperties(updatePlatformDTO, platform);
platform.setId(id);
platform.setCompanyId(companyId);
@@ -223,7 +223,7 @@ public class PlatformServiceImpl extends ServiceImpl<PlatformMapper, PlatformPO>
private PlatformVO convertToVO(PlatformPO platform) {
PlatformVO vo = new PlatformVO();
BeanUtils.copyProperties(platform, vo);
BeanCopyUtils.copyProperties(platform, vo);
return vo;
}
}
@@ -1,5 +1,6 @@
package top.xyquan.ecomdmbbackend.modules.ecom.product.controller;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -90,7 +91,7 @@ public class ProductSpecController {
.filter(spec -> spec.getCompanyId().equals(companyId))
.map(spec -> {
ProductSpecVO vo = new ProductSpecVO();
org.springframework.beans.BeanUtils.copyProperties(spec, vo);
BeanCopyUtils.copyProperties(spec, vo);
return vo;
})
.collect(java.util.stream.Collectors.toList());
@@ -1,13 +1,11 @@
package top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
/**
* 同步规格成本到订单的请求DTO
@@ -294,10 +294,11 @@ public class ProductOverviewServiceImpl implements ProductOverviewService {
.map(ShopMonthlyTargetPO::getTargetAmount)
.filter(Objects::nonNull)
.reduce(BigDecimal.ZERO, BigDecimal::add);
Integer totalTargetOrderCount = shopTargets.stream()
int totalTargetOrderCount = shopTargets.stream()
.map(ShopMonthlyTargetPO::getTargetOrderCount)
.filter(Objects::nonNull)
.reduce(0, Integer::sum);
.mapToInt(Integer::intValue)
.sum();
if (totalTargetAmount.compareTo(BigDecimal.ZERO) > 0) {
BigDecimal salesRate = totalSalesAmount
@@ -306,7 +307,7 @@ public class ProductOverviewServiceImpl implements ProductOverviewService {
.setScale(2, RoundingMode.HALF_UP);
vo.setSalesAmountAchievementRate(salesRate);
}
if (totalTargetOrderCount != null && totalTargetOrderCount > 0) {
if (totalTargetOrderCount > 0) {
BigDecimal orderRate = BigDecimal.valueOf((long) totalOrderCount)
.divide(BigDecimal.valueOf(totalTargetOrderCount), 4, RoundingMode.HALF_UP)
.multiply(new BigDecimal("100"))
@@ -589,8 +590,8 @@ public class ProductOverviewServiceImpl implements ProductOverviewService {
// 总件数
int quantity = specOrders.stream()
.map(o -> o.getQuantity() != null ? o.getQuantity() : 1)
.reduce(0, Integer::sum);
.mapToInt(o -> o.getQuantity() != null ? o.getQuantity() : 1)
.sum();
// 客单价
BigDecimal avgOV = orderCount > 0
@@ -1,10 +1,10 @@
package top.xyquan.ecomdmbbackend.modules.ecom.product.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -86,7 +86,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
// 创建商品
ProductPO product = new ProductPO();
BeanUtils.copyProperties(createProductDTO, product);
BeanCopyUtils.copyProperties(createProductDTO, product);
// 设置公司ID
product.setCompanyId(companyId);
@@ -157,7 +157,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
throw new BusinessException("同公司下商品名称与商品编码组合已存在");
}
ProductPO product = new ProductPO();
BeanUtils.copyProperties(createProductDTO, product);
BeanCopyUtils.copyProperties(createProductDTO, product);
product.setCompanyId(companyId);
product.setCreateBy(userId);
this.save(product);
@@ -282,7 +282,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
// 更新商品
ProductPO product = new ProductPO();
BeanUtils.copyProperties(updateProductDTO, product);
BeanCopyUtils.copyProperties(updateProductDTO, product);
product.setId(id);
product.setCompanyId(companyId);
@@ -564,7 +564,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
*/
private ProductVO convertToVO(ProductPO product) {
ProductVO productVO = new ProductVO();
BeanUtils.copyProperties(product, productVO);
BeanCopyUtils.copyProperties(product, productVO);
// 查询主图文件信息并生成访问URL
if (product.getMainImageId() != null) {
@@ -604,7 +604,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
*/
private ProductSpecVO convertSpecToVO(ProductSpecPO productSpec) {
ProductSpecVO productSpecVO = new ProductSpecVO();
BeanUtils.copyProperties(productSpec, productSpecVO);
BeanCopyUtils.copyProperties(productSpec, productSpecVO);
return productSpecVO;
}
}
@@ -1,10 +1,10 @@
package top.xyquan.ecomdmbbackend.modules.ecom.product.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
@@ -29,6 +29,7 @@ import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
import java.math.BigDecimal;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
@@ -131,20 +132,13 @@ public class ProductSpecServiceImpl extends ServiceImpl<ProductSpecMapper, Produ
// 辅助方法:检测成本是否有实际变化
// 规则:null 和 0 都视为"未填成本",互为等价;只有非零值才算有效成本
// 使用 compareTo 替代 equals 避免 BigDecimal scale 不同导致误判(如 100 vs 100.00)
java.util.function.BiFunction<java.math.BigDecimal, java.math.BigDecimal, Boolean> isCostReallyChanged = (dbVal, dtoVal) -> {
boolean dbIsEmpty = dbVal == null || dbVal.compareTo(java.math.BigDecimal.ZERO) == 0;
boolean dtoIsEmpty = dtoVal == null || dtoVal.compareTo(java.math.BigDecimal.ZERO) == 0;
if (dbIsEmpty && dtoIsEmpty) return false; // 都是空,无变化
if (dbIsEmpty || dtoIsEmpty) return true; // 一个是空一个有值,有变化
return dbVal.compareTo(dtoVal) != 0; // 都有非零值,精确比较
};
boolean costChanged = isCostReallyChanged.apply(existingProductSpec.getProductCost(), updateProductSpecDTO.getProductCost())
|| isCostReallyChanged.apply(existingProductSpec.getShippingCost(), updateProductSpecDTO.getShippingCost())
|| isCostReallyChanged.apply(existingProductSpec.getOtherCost(), updateProductSpecDTO.getOtherCost());
boolean costChanged = isSpecCostChanged(existingProductSpec.getProductCost(), updateProductSpecDTO.getProductCost())
|| isSpecCostChanged(existingProductSpec.getShippingCost(), updateProductSpecDTO.getShippingCost())
|| isSpecCostChanged(existingProductSpec.getOtherCost(), updateProductSpecDTO.getOtherCost());
// 更新商品规格
ProductSpecPO productSpec = new ProductSpecPO();
BeanUtils.copyProperties(updateProductSpecDTO, productSpec);
BeanCopyUtils.copyProperties(updateProductSpecDTO, productSpec);
productSpec.setId(id);
productSpec.setCompanyId(companyId);
productSpec.setProductId(existingProductSpec.getProductId());
@@ -355,7 +349,7 @@ public class ProductSpecServiceImpl extends ServiceImpl<ProductSpecMapper, Produ
}
ProductSpecPO productSpec = new ProductSpecPO();
BeanUtils.copyProperties(dto, productSpec);
BeanCopyUtils.copyProperties(dto, productSpec);
productSpec.setCompanyId(companyId);
if (!trimmedCode.isEmpty()) {
productSpec.setSpecCode(trimmedCode);
@@ -377,7 +371,7 @@ public class ProductSpecServiceImpl extends ServiceImpl<ProductSpecMapper, Produ
if (dbEmpty || dtoEmpty) {
return true;
}
return dbVal.compareTo(dtoVal) != 0;
return Objects.requireNonNull(dbVal).compareTo(Objects.requireNonNull(dtoVal)) != 0;
}
@Override
@@ -460,7 +454,7 @@ public class ProductSpecServiceImpl extends ServiceImpl<ProductSpecMapper, Produ
.map(product -> {
// 转换为商品VO
ProductVO productVO = new ProductVO();
BeanUtils.copyProperties(product, productVO);
BeanCopyUtils.copyProperties(product, productVO);
// 添加匹配的规格信息
List<ProductSpecPO> specs = productSpecsMap.get(product.getId());
@@ -488,7 +482,7 @@ public class ProductSpecServiceImpl extends ServiceImpl<ProductSpecMapper, Produ
*/
private ProductSpecVO convertToVO(ProductSpecPO productSpec) {
ProductSpecVO productSpecVO = new ProductSpecVO();
BeanUtils.copyProperties(productSpec, productSpecVO);
BeanCopyUtils.copyProperties(productSpec, productSpecVO);
return productSpecVO;
}
}
@@ -1,7 +1,6 @@
package top.xyquan.ecomdmbbackend.modules.ecom.promotion.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
@@ -11,7 +10,6 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.xyquan.ecomdmbbackend.modules.ecom.importtask.model.po.ImportTaskPO;
import top.xyquan.ecomdmbbackend.modules.ecom.importtask.util.ImportTaskMessageAppender;
import top.xyquan.ecomdmbbackend.modules.ecom.promotion.mapper.PromotionFeeMapper;
@@ -39,12 +37,6 @@ public class PromotionFeeImportProcessor extends ServiceImpl<PromotionFeeMapper,
/** 推广费金额不合规时的统一失败原因 */
private static final String INVALID_FEE_AMOUNT_REASON = "推广费金额为空或须大于0";
private final ObjectMapper objectMapper;
public PromotionFeeImportProcessor(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
}
/**
* 执行导入
*/
@@ -1,9 +1,9 @@
package top.xyquan.ecomdmbbackend.modules.ecom.promotion.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
@@ -71,7 +71,7 @@ public class PromotionFeeServiceImpl implements PromotionFeeService {
public Long createPromotionFee(CreatePromotionFeeDTO dto) {
assertOptionalCategoryInCompany(dto.getCategoryId());
PromotionFeePO po = new PromotionFeePO();
BeanUtils.copyProperties(dto, po);
BeanCopyUtils.copyProperties(dto, po);
po.setCompanyId(currentUserContext.getCurrentCompanyId());
po.setCreateBy(currentUserContext.getCurrentUserId());
po.setUpdateBy(currentUserContext.getCurrentUserId());
@@ -95,7 +95,7 @@ public class PromotionFeeServiceImpl implements PromotionFeeService {
}
assertOptionalCategoryInCompany(dto.getCategoryId());
PromotionFeePO po = new PromotionFeePO();
BeanUtils.copyProperties(dto, po);
BeanCopyUtils.copyProperties(dto, po);
po.setUpdateBy(currentUserContext.getCurrentUserId());
po.setCompanyId(companyId);
promotionFeeMapper.updateById(po);
@@ -186,7 +186,7 @@ public class PromotionFeeServiceImpl implements PromotionFeeService {
*/
private PromotionFeeVO convertToVO(PromotionFeePO po) {
PromotionFeeVO vo = new PromotionFeeVO();
BeanUtils.copyProperties(po, vo);
BeanCopyUtils.copyProperties(po, vo);
// 填充店铺名称
if (po.getShopId() != null) {
@@ -1,8 +1,8 @@
package top.xyquan.ecomdmbbackend.modules.ecom.promotion.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.xyquan.ecomdmbbackend.modules.ecom.promotion.mapper.PromotionFeeTypeMapper;
@@ -43,7 +43,7 @@ public class PromotionFeeTypeServiceImpl implements PromotionFeeTypeService {
}
PromotionFeeTypePO po = new PromotionFeeTypePO();
BeanUtils.copyProperties(dto, po);
BeanCopyUtils.copyProperties(dto, po);
po.setCompanyId(currentUserContext.getCurrentCompanyId());
po.setCreateBy(currentUserContext.getCurrentUserId());
po.setUpdateBy(currentUserContext.getCurrentUserId());
@@ -60,7 +60,7 @@ public class PromotionFeeTypeServiceImpl implements PromotionFeeTypeService {
@Transactional(rollbackFor = Exception.class)
public void updatePromotionFeeType(UpdatePromotionFeeTypeDTO dto) {
PromotionFeeTypePO po = new PromotionFeeTypePO();
BeanUtils.copyProperties(dto, po);
BeanCopyUtils.copyProperties(dto, po);
po.setUpdateBy(currentUserContext.getCurrentUserId());
promotionFeeTypeMapper.updateById(po);
@@ -90,7 +90,7 @@ public class PromotionFeeTypeServiceImpl implements PromotionFeeTypeService {
}
PromotionFeeTypeVO vo = new PromotionFeeTypeVO();
BeanUtils.copyProperties(po, vo);
BeanCopyUtils.copyProperties(po, vo);
// 设置计算方式描述
if (po.getCalculationMethod() != null) {
@@ -131,7 +131,7 @@ public class PromotionFeeTypeServiceImpl implements PromotionFeeTypeService {
return poList.stream()
.map(po -> {
PromotionFeeTypeVO vo = new PromotionFeeTypeVO();
BeanUtils.copyProperties(po, vo);
BeanCopyUtils.copyProperties(po, vo);
// 设置计算方式描述
if (po.getCalculationMethod() != null) {
@@ -173,7 +173,7 @@ public class PromotionFeeTypeServiceImpl implements PromotionFeeTypeService {
return poList.stream()
.map(po -> {
PromotionFeeTypeVO vo = new PromotionFeeTypeVO();
BeanUtils.copyProperties(po, vo);
BeanCopyUtils.copyProperties(po, vo);
// 设置计算方式描述
if (po.getCalculationMethod() != null) {
@@ -1,10 +1,10 @@
package top.xyquan.ecomdmbbackend.modules.ecom.shop.monthlytarget.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
@@ -74,7 +74,7 @@ public class ShopMonthlyTargetServiceImpl extends ServiceImpl<ShopMonthlyTargetM
// 创建目标记录
ShopMonthlyTargetPO target = new ShopMonthlyTargetPO();
BeanUtils.copyProperties(createDTO, target);
BeanCopyUtils.copyProperties(createDTO, target);
target.setCompanyId(companyId);
target.setCreateBy(userId);
@@ -120,7 +120,7 @@ public class ShopMonthlyTargetServiceImpl extends ServiceImpl<ShopMonthlyTargetM
// 更新目标记录
ShopMonthlyTargetPO target = new ShopMonthlyTargetPO();
BeanUtils.copyProperties(updateDTO, target);
BeanCopyUtils.copyProperties(updateDTO, target);
target.setId(id);
target.setCompanyId(companyId);
target.setShopId(existingTarget.getShopId()); // 保持店铺ID不变
@@ -206,7 +206,7 @@ public class ShopMonthlyTargetServiceImpl extends ServiceImpl<ShopMonthlyTargetM
*/
private ShopMonthlyTargetVO convertToVO(ShopMonthlyTargetPO target) {
ShopMonthlyTargetVO vo = new ShopMonthlyTargetVO();
BeanUtils.copyProperties(target, vo);
BeanCopyUtils.copyProperties(target, vo);
// 设置店铺名称
if (target.getShopId() != null) {
@@ -1,10 +1,10 @@
package top.xyquan.ecomdmbbackend.modules.ecom.shop.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
@@ -38,19 +38,15 @@ import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopDashboardVO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopVO;
import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductSpecService;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.service.ShopService;
import top.xyquan.ecomdmbbackend.modules.sys.file.mapper.SysFileMapper;
import top.xyquan.ecomdmbbackend.modules.sys.file.model.po.SysFilePO;
import top.xyquan.ecomdmbbackend.modules.sys.file.model.vo.SysFileUploadVO;
import top.xyquan.ecomdmbbackend.modules.sys.file.service.SysFileService;
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
import top.xyquan.ecomdmbbackend.utils.SysFileUtils;
import org.springframework.web.multipart.MultipartFile;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@@ -62,7 +58,6 @@ import java.util.stream.Collectors;
public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements ShopService {
private final CurrentUserContext currentUserContext;
private final SysFileMapper sysFileMapper;
private final SysFileService sysFileService;
private final OrderMapper orderMapper;
private final PromotionFeeMapper promotionFeeMapper;
@@ -73,14 +68,13 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
private final BrushOrderMapper brushOrderMapper;
private final ShopMonthlyTargetMapper shopMonthlyTargetMapper;
public ShopServiceImpl(CurrentUserContext currentUserContext, SysFileMapper sysFileMapper, SysFileService sysFileService,
public ShopServiceImpl(CurrentUserContext currentUserContext, SysFileService sysFileService,
OrderMapper orderMapper, PromotionFeeMapper promotionFeeMapper,
ProductMapper productMapper,
ShopProductRelationMapper shopProductRelationMapper, ProductSpecService productSpecService,
PlatformMapper platformMapper,
BrushOrderMapper brushOrderMapper, ShopMonthlyTargetMapper shopMonthlyTargetMapper) {
this.currentUserContext = currentUserContext;
this.sysFileMapper = sysFileMapper;
this.sysFileService = sysFileService;
this.orderMapper = orderMapper;
this.promotionFeeMapper = promotionFeeMapper;
@@ -113,7 +107,7 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
// 创建店铺
ShopPO shop = new ShopPO();
BeanUtils.copyProperties(createShopDTO, shop);
BeanCopyUtils.copyProperties(createShopDTO, shop);
// 设置公司ID
shop.setCompanyId(companyId);
@@ -157,7 +151,7 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
// 更新店铺
ShopPO shop = new ShopPO();
BeanUtils.copyProperties(updateShopDTO, shop);
BeanCopyUtils.copyProperties(updateShopDTO, shop);
shop.setId(id);
shop.setCompanyId(companyId);
@@ -254,7 +248,7 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
*/
private ShopVO convertToVO(ShopPO shop) {
ShopVO shopVO = new ShopVO();
BeanUtils.copyProperties(shop, shopVO);
BeanCopyUtils.copyProperties(shop, shopVO);
if (shop.getLogoImageId() != null) {
shopVO.setLogo(sysFileService.getFileAccessUrl(shop.getLogoImageId()));
@@ -337,7 +331,7 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
*/
private ProductVO convertProductToVO(ProductPO product) {
ProductVO productVO = new ProductVO();
BeanUtils.copyProperties(product, productVO);
BeanCopyUtils.copyProperties(product, productVO);
// 查询商品规格列表
LambdaQueryWrapper<ProductSpecPO> specWrapper = new LambdaQueryWrapper<>();
@@ -359,7 +353,7 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
*/
private ProductSpecVO convertSpecToVO(ProductSpecPO productSpec) {
ProductSpecVO productSpecVO = new ProductSpecVO();
BeanUtils.copyProperties(productSpec, productSpecVO);
BeanCopyUtils.copyProperties(productSpec, productSpecVO);
return productSpecVO;
}
@@ -3,14 +3,10 @@ package top.xyquan.ecomdmbbackend.modules.ecom.workbench.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
import top.xyquan.ecomdmbbackend.modules.ecom.brushorder.mapper.BrushOrderMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.brushorder.model.po.BrushOrderPO;
import top.xyquan.ecomdmbbackend.modules.ecom.category.model.po.CategoryPO;
import top.xyquan.ecomdmbbackend.modules.ecom.category.service.CategoryService;
import top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderStatAggMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.order.stat.service.OrderStatReadFacade;
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderPO;
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.support.OrderStatusStatResolver;
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.support.OrderStatusStatSets;
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.vo.CompanyOverviewVO;
@@ -18,11 +14,7 @@ import top.xyquan.ecomdmbbackend.modules.ecom.overview.service.CompanyOverviewSe
import top.xyquan.ecomdmbbackend.modules.ecom.platform.mapper.PlatformMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.po.PlatformPO;
import top.xyquan.ecomdmbbackend.modules.ecom.product.mapper.ProductMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.product.mapper.ProductSpecMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductPO;
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSpecPO;
import top.xyquan.ecomdmbbackend.modules.ecom.promotion.mapper.PromotionFeeMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.promotion.model.po.PromotionFeePO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.po.ShopPO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.service.ShopService;
import top.xyquan.ecomdmbbackend.modules.ecom.workbench.model.dto.WorkbenchQueryDTO;
@@ -63,9 +55,9 @@ import java.util.stream.Collectors;
* <ul>
* <li>「实际销售额、成本、退款、多维行、趋势」等与 {@link OrderStatusStatSets} 一致:仅统计配置为「计入销售额」的订单状态,
* 金额字段由 {@code stat} 解析商家实收、成本、退款等。</li>
* <li>「总 GMV」为同店铺、同时间范围内<strong>全部订单状态</strong>的 {@link OrderPO#getReceivedAmount()} 合计。</li>
* <li>「总 GMV」为同店铺、同时间范围内<strong>全部订单状态</strong>的商家实收合计(由汇总表 KPI 提供)。</li>
* <li>推广费、刷单费为区间汇总;多维行与趋势中的「净利润」按销售额 / 净销售额占比将区间推广、刷单、税额<strong>分摊</strong>到各维度或各日,
* 与 {@link #aggregateTotals} 得到的区间总毛利润、总税额自洽。</li>
* 与 {@link #totalsFromOrderRows} 得到的区间总毛利润、总税额自洽。</li>
* </ul>
* <p>
* 分 Tab 输出:{@link #financeSlice}、{@link #multiAnalysis}、{@link #salesRank}。
@@ -79,12 +71,8 @@ public class WorkbenchServiceImpl implements WorkbenchService {
private static final DateTimeFormatter TREND_DATE_FMT = DateTimeFormatter.ofPattern("M/d");
private final CurrentUserContext currentUserContext;
private final OrderMapper orderMapper;
private final ShopService shopService;
private final OrderStatusStatResolver orderStatusStatResolver;
private final PromotionFeeMapper promotionFeeMapper;
private final BrushOrderMapper brushOrderMapper;
private final ProductSpecMapper productSpecMapper;
private final ProductMapper productMapper;
private final CategoryService categoryService;
private final PlatformMapper platformMapper;
@@ -92,24 +80,16 @@ public class WorkbenchServiceImpl implements WorkbenchService {
private final CompanyOverviewService companyOverviewService;
public WorkbenchServiceImpl(CurrentUserContext currentUserContext,
OrderMapper orderMapper,
ShopService shopService,
OrderStatusStatResolver orderStatusStatResolver,
PromotionFeeMapper promotionFeeMapper,
BrushOrderMapper brushOrderMapper,
ProductSpecMapper productSpecMapper,
ProductMapper productMapper,
CategoryService categoryService,
PlatformMapper platformMapper,
OrderStatReadFacade orderStatReadFacade,
CompanyOverviewService companyOverviewService) {
this.currentUserContext = currentUserContext;
this.orderMapper = orderMapper;
this.shopService = shopService;
this.orderStatusStatResolver = orderStatusStatResolver;
this.promotionFeeMapper = promotionFeeMapper;
this.brushOrderMapper = brushOrderMapper;
this.productSpecMapper = productSpecMapper;
this.productMapper = productMapper;
this.categoryService = categoryService;
this.platformMapper = platformMapper;
@@ -413,15 +393,6 @@ public class WorkbenchServiceImpl implements WorkbenchService {
.stream().collect(Collectors.toMap(CategoryPO::getId, CategoryPO::getName, (a, b) -> a));
}
private static List<Long> statusList(java.util.Set<Long> ids) {
if (ids == null || ids.isEmpty()) {
return List.of(-1L);
}
List<Long> list = new ArrayList<>(ids);
Collections.sort(list);
return list;
}
private static BigDecimal dayNetSales(OrderStatAggMapper.DailyRow row) {
if (row == null) {
return BigDecimal.ZERO;
@@ -488,95 +459,6 @@ public class WorkbenchServiceImpl implements WorkbenchService {
}
}
/** 当前区间:计入销售额订单、推广/刷单、汇总 Totals(导出等仍用) */
private CurrentPeriodBundle loadCurrentPeriod(ShopContext ctx) {
List<Long> unionStatusIds = ctx.stat().getUnionStatusIds();
List<OrderPO> orders = loadOrders(ctx.companyId(), ctx.shopIds(),
ctx.range().startDateTime(), ctx.range().endDateTime(), unionStatusIds);
List<PromotionFeePO> promotionFees = loadPromotionFees(ctx.companyId(), ctx.shopIds(),
ctx.range().startDate(), ctx.range().endDate());
List<BrushOrderPO> brushOrders = loadBrushOrders(ctx.companyId(), ctx.shopIds(),
ctx.range().startDateTime(), ctx.range().endDateTime());
Totals totals = aggregateTotals(orders, ctx.stat(), promotionFees, brushOrders, ctx.taxRate());
return new CurrentPeriodBundle(orders, promotionFees, brushOrders, totals);
}
/** 环比/同比:用于 KPI 对比与总 GMV(导出等仍用) */
private ComparePeriodBundle loadComparePeriods(ShopContext ctx) {
List<Long> unionStatusIds = ctx.stat().getUnionStatusIds();
List<OrderPO> curOrdersAllStatuses = loadOrdersAllStatuses(ctx.companyId(), ctx.shopIds(),
ctx.range().startDateTime(), ctx.range().endDateTime());
DateRange lastRange = lastMonthSameSpan(ctx.range());
List<OrderPO> lastOrders = loadOrders(ctx.companyId(), ctx.shopIds(),
lastRange.startDateTime(), lastRange.endDateTime(), unionStatusIds);
List<OrderPO> lastOrdersAllStatuses = loadOrdersAllStatuses(ctx.companyId(), ctx.shopIds(),
lastRange.startDateTime(), lastRange.endDateTime());
List<PromotionFeePO> lastPromo = loadPromotionFees(ctx.companyId(), ctx.shopIds(),
lastRange.startDate(), lastRange.endDate());
List<BrushOrderPO> lastBrush = loadBrushOrders(ctx.companyId(), ctx.shopIds(),
lastRange.startDateTime(), lastRange.endDateTime());
Totals prev = aggregateTotals(lastOrders, ctx.stat(), lastPromo, lastBrush, ctx.taxRate());
DateRange yoyRange = new DateRange(ctx.range().startDate().minusYears(1), ctx.range().endDate().minusYears(1));
List<OrderPO> yoyOrders = loadOrders(ctx.companyId(), ctx.shopIds(),
yoyRange.startDateTime(), yoyRange.endDateTime(), unionStatusIds);
List<OrderPO> yoyOrdersAllStatuses = loadOrdersAllStatuses(ctx.companyId(), ctx.shopIds(),
yoyRange.startDateTime(), yoyRange.endDateTime());
List<PromotionFeePO> yoyPromo = loadPromotionFees(ctx.companyId(), ctx.shopIds(),
yoyRange.startDate(), yoyRange.endDate());
List<BrushOrderPO> yoyBrush = loadBrushOrders(ctx.companyId(), ctx.shopIds(),
yoyRange.startDateTime(), yoyRange.endDateTime());
Totals yoy = aggregateTotals(yoyOrders, ctx.stat(), yoyPromo, yoyBrush, ctx.taxRate());
return new ComparePeriodBundle(lastRange, yoyRange, prev, yoy,
sumAllReceivedAmount(curOrdersAllStatuses),
sumAllReceivedAmount(lastOrdersAllStatuses),
sumAllReceivedAmount(yoyOrdersAllStatuses));
}
/** 四维订单聚合 + 名称解析 */
private DimensionAggMaps aggregateDimensions(List<OrderPO> orders,
List<ShopPO> shops,
Map<Long, ShopPO> shopById,
OrderStatusStatSets stat) {
Map<Long, Long> specToProduct = buildSpecToProductMap(orders);
Map<Long, ProductPO> productById = loadProducts(specToProduct.values());
Map<Long, String> categoryNames = loadCategoryNames(productById.values());
Map<Long, String> platformNames = loadPlatformNames(shops);
Map<String, Agg> platformAgg = new HashMap<>();
Map<String, Agg> shopAgg = new HashMap<>();
Map<String, Agg> categoryAgg = new HashMap<>();
Map<String, Agg> productAgg = new HashMap<>();
for (OrderPO o : orders) {
ShopPO shop = shopById.get(o.getShopId());
if (shop == null) {
continue;
}
long platformKey = shop.getPlatformId() != null ? shop.getPlatformId() : 0L;
long shopKey = shop.getId() != null ? shop.getId() : 0L;
long productId = o.getProductSpecId() != null
? specToProduct.getOrDefault(o.getProductSpecId(), -1L)
: -1L;
long categoryKey = 0L;
if (productId > 0) {
ProductPO p = productById.get(productId);
if (p != null && p.getCategoryId() != null) {
categoryKey = p.getCategoryId();
}
}
addOrder(platformAgg, String.valueOf(platformKey), o, stat);
addOrder(shopAgg, String.valueOf(shopKey), o, stat);
addOrder(categoryAgg, String.valueOf(categoryKey), o, stat);
addOrder(productAgg, String.valueOf(productId), o, stat);
}
return new DimensionAggMaps(platformAgg, shopAgg, categoryAgg, productAgg,
platformNames, categoryNames, productById, shopById);
}
private WorkbenchMultiAnalysisPanelVO buildMultiPanel(DimensionAggMaps aggs, Totals cur) {
BigDecimal salesAllocBase = cur.totalSales();
return WorkbenchMultiAnalysisPanelVO.builder()
@@ -615,29 +497,6 @@ public class WorkbenchServiceImpl implements WorkbenchService {
.build();
}
private WorkbenchFinancePanelVO buildFinancePanel(ShopContext ctx,
CurrentPeriodBundle current,
ComparePeriodBundle compare,
Map<String, Agg> platformAgg,
Map<Long, String> platformNames) {
List<OrderPO> ordersAllStatuses = loadOrdersAllStatuses(ctx.companyId(), ctx.shopIds(),
ctx.range().startDateTime(), ctx.range().endDateTime());
BigDecimal totalGmvCur = sumAllReceivedAmount(ordersAllStatuses);
BigDecimal salesAllocBase = current.totals().totalSales();
return WorkbenchFinancePanelVO.builder()
.kpis(buildKpis(current.totals(), compare.prev(), compare.yoy(), ctx.range(), ctx.taxRate(),
totalGmvCur, compare.totalGmvPrev(), compare.totalGmvYoy()))
.gmvTrend(buildTrend(current.orders(), ctx.stat(),
ctx.range().startDate(), ctx.range().endDate(), current.totals()))
.platformSalesShare(buildPlatformSalesSlices(platformAgg, platformNames, salesAllocBase))
.momCompareDateStart(compare.lastRange().startDate().toString())
.momCompareDateEnd(compare.lastRange().endDate().toString())
.yoyCompareDateStart(compare.yoyRange().startDate().toString())
.yoyCompareDateEnd(compare.yoyRange().endDate().toString())
.build();
}
/**
* 按公司 + 可选平台/单店筛选店铺列表;指定 {@code shopId} 时校验归属与平台一致性。
*/
@@ -660,103 +519,6 @@ public class WorkbenchServiceImpl implements WorkbenchService {
return shopService.list(w);
}
/**
* 查询「计入销售额」口径订单:状态 id 落在 {@code unionStatusIds} 内;若公司未配置任何计入状态则查不到数据(条件恒假)。
*/
private List<OrderPO> loadOrders(Long companyId, List<Long> shopIds,
LocalDateTime start, LocalDateTime end, List<Long> unionStatusIds) {
if (shopIds.isEmpty()) {
return Collections.emptyList();
}
LambdaQueryWrapper<OrderPO> orderWrapper = new LambdaQueryWrapper<>();
orderWrapper.eq(OrderPO::getCompanyId, companyId)
.in(OrderPO::getShopId, shopIds)
.ge(OrderPO::getOrderTime, start)
.le(OrderPO::getOrderTime, end);
if (!unionStatusIds.isEmpty()) {
orderWrapper.in(OrderPO::getStatusId, unionStatusIds);
} else {
orderWrapper.isNull(OrderPO::getId);
}
return orderMapper.selectList(orderWrapper);
}
/**
* 总 GMV 用:同店铺、时间范围内<strong>全部订单状态</strong>的列表,不按「计入销售额」过滤。
*/
private List<OrderPO> loadOrdersAllStatuses(Long companyId, List<Long> shopIds,
LocalDateTime start, LocalDateTime end) {
if (shopIds.isEmpty()) {
return Collections.emptyList();
}
LambdaQueryWrapper<OrderPO> w = new LambdaQueryWrapper<>();
w.eq(OrderPO::getCompanyId, companyId)
.in(OrderPO::getShopId, shopIds)
.ge(OrderPO::getOrderTime, start)
.le(OrderPO::getOrderTime, end);
return orderMapper.selectList(w);
}
/** 将订单列表的商家实收相加,用于总 GMV KPI */
private static BigDecimal sumAllReceivedAmount(List<OrderPO> orders) {
BigDecimal s = BigDecimal.ZERO;
if (orders == null) {
return s;
}
for (OrderPO o : orders) {
if (o.getReceivedAmount() != null) {
s = s.add(o.getReceivedAmount());
}
}
return s;
}
/** 推广费按费用发生日落在 [start, end] 闭区间内 */
private List<PromotionFeePO> loadPromotionFees(Long companyId, List<Long> shopIds, LocalDate start, LocalDate end) {
if (shopIds.isEmpty()) {
return Collections.emptyList();
}
LambdaQueryWrapper<PromotionFeePO> w = new LambdaQueryWrapper<>();
w.eq(PromotionFeePO::getCompanyId, companyId)
.in(PromotionFeePO::getShopId, shopIds)
.ge(PromotionFeePO::getFeeDate, start)
.le(PromotionFeePO::getFeeDate, end);
return promotionFeeMapper.selectList(w);
}
/** 刷单记录按刷单时间落在 [start, end] 内 */
private List<BrushOrderPO> loadBrushOrders(Long companyId, List<Long> shopIds, LocalDateTime start, LocalDateTime end) {
if (shopIds.isEmpty()) {
return Collections.emptyList();
}
LambdaQueryWrapper<BrushOrderPO> w = new LambdaQueryWrapper<>();
w.eq(BrushOrderPO::getCompanyId, companyId)
.in(BrushOrderPO::getShopId, shopIds)
.ge(BrushOrderPO::getBrushTime, start)
.le(BrushOrderPO::getBrushTime, end);
return brushOrderMapper.selectList(w);
}
/** 批量解析订单中出现的规格 id → 商品 id,减少重复查库 */
private Map<Long, Long> buildSpecToProductMap(List<OrderPO> orders) {
List<Long> specIds = orders.stream()
.map(OrderPO::getProductSpecId)
.filter(Objects::nonNull)
.distinct()
.toList();
if (specIds.isEmpty()) {
return Collections.emptyMap();
}
List<ProductSpecPO> specs = productSpecMapper.selectList(new LambdaQueryWrapper<ProductSpecPO>()
.in(ProductSpecPO::getId, specIds)
.select(ProductSpecPO::getId, ProductSpecPO::getProductId));
Map<Long, Long> map = new HashMap<>();
for (ProductSpecPO s : specs) {
map.put(s.getId(), s.getProductId());
}
return map;
}
/** 按商品 id 批量加载主数据,供类目解析与商品名称展示 */
private Map<Long, ProductPO> loadProducts(Iterable<Long> productIds) {
List<Long> ids = new ArrayList<>();
@@ -773,22 +535,6 @@ public class WorkbenchServiceImpl implements WorkbenchService {
return list.stream().collect(Collectors.toMap(ProductPO::getId, p -> p, (a, b) -> a));
}
/** 从商品上收集类目 id,再批量查类目名称 */
private Map<Long, String> loadCategoryNames(Iterable<ProductPO> products) {
List<Long> catIds = new ArrayList<>();
for (ProductPO p : products) {
if (p.getCategoryId() != null) {
catIds.add(p.getCategoryId());
}
}
catIds = catIds.stream().distinct().toList();
if (catIds.isEmpty()) {
return Collections.emptyMap();
}
List<CategoryPO> cats = categoryService.list(new LambdaQueryWrapper<CategoryPO>().in(CategoryPO::getId, catIds));
return cats.stream().collect(Collectors.toMap(CategoryPO::getId, CategoryPO::getName, (a, b) -> a));
}
/** 从店铺收集平台 id,再批量查平台名称(多维「平台」行展示) */
private Map<Long, String> loadPlatformNames(List<ShopPO> shops) {
List<Long> pids = shops.stream()
@@ -803,11 +549,6 @@ public class WorkbenchServiceImpl implements WorkbenchService {
return list.stream().collect(Collectors.toMap(PlatformPO::getId, PlatformPO::getPlatformName, (a, b) -> a));
}
/** 将单条订单累加到指定 key 的 {@link Agg} 桶中 */
private void addOrder(Map<String, Agg> map, String key, OrderPO o, OrderStatusStatSets stat) {
map.computeIfAbsent(key, k -> new Agg()).add(o, stat);
}
/**
* 将「字符串 key → 聚合桶」转为多维表格行:每行毛利润 = 销售−成本−退款;
* 推广费、刷单费按该行销售额占 {@code salesTotalCompany} 比例分摊;税额按该行净销售额占全部分桶净销售额之和比例分摊;
@@ -885,60 +626,6 @@ public class WorkbenchServiceImpl implements WorkbenchService {
return amount.multiply(part).divide(total, 4, RoundingMode.HALF_UP);
}
/**
* 趋势点:毛利润按日订单聚合;净利润按区间总推广/刷单/税额,以「日销售额占比」「日净销售额占比」分摊到各日,
* 与 {@link #buildDimRows} 及 KPI 净利润口径一致。
*/
private List<WorkbenchTrendPointVO> buildTrend(List<OrderPO> orders, OrderStatusStatSets stat,
LocalDate start, LocalDate end, Totals periodTotals) {
Map<LocalDate, Agg> byDay = new HashMap<>();
for (OrderPO o : orders) {
if (o.getOrderTime() == null) {
continue;
}
LocalDate day = o.getOrderTime().toLocalDate();
byDay.computeIfAbsent(day, x -> new Agg()).add(o, stat);
}
BigDecimal salesTotal = periodTotals.totalSales();
BigDecimal promoTotal = periodTotals.promotion();
BigDecimal brushTotal = periodTotals.brush();
BigDecimal taxTotal = periodTotals.tax();
BigDecimal netSum = BigDecimal.ZERO;
for (LocalDate x = start; !x.isAfter(end); x = x.plusDays(1)) {
netSum = netSum.add(byDay.getOrDefault(x, new Agg()).netSalesBase());
}
List<WorkbenchTrendPointVO> list = new ArrayList<>();
LocalDate d = start;
while (!d.isAfter(end)) {
Agg a = byDay.getOrDefault(d, new Agg());
BigDecimal salesYuan = yuan2(a.sales);
BigDecimal gross = a.sales.subtract(a.cost).subtract(a.refund);
BigDecimal profitYuan = yuan2(gross);
BigDecimal refundYuan = yuan2(a.refund);
BigDecimal promoB = allocShare(a.sales, salesTotal, promoTotal);
BigDecimal brushB = allocShare(a.sales, salesTotal, brushTotal);
BigDecimal taxB = allocShare(a.netSalesBase(), netSum.max(BigDecimal.ONE), taxTotal);
if (netSum.compareTo(BigDecimal.ZERO) <= 0) {
taxB = BigDecimal.ZERO;
}
BigDecimal netDay = gross.subtract(promoB).subtract(brushB).subtract(taxB);
BigDecimal netProfitYuan = yuan2(netDay);
list.add(WorkbenchTrendPointVO.builder()
.date(d.format(TREND_DATE_FMT))
.salesYuan(salesYuan)
.profitYuan(profitYuan)
.netProfitYuan(netProfitYuan)
.refundYuan(refundYuan)
.build());
d = d.plusDays(1);
}
return list;
}
/**
* 各平台实际销售额占比:与多维分析「平台」维度同源订单聚合;分母为当前筛选下公司实际销售额合计。
*/
@@ -1076,51 +763,6 @@ public class WorkbenchServiceImpl implements WorkbenchService {
.setScale(2, RoundingMode.HALF_UP);
}
/**
* 将一段时间内的订单 + 推广 + 刷单聚合成 {@link Totals}:销售额/退款/成本分项、推广与刷单合计、
* 按「销售额−退款」为税基的税额、毛利润、净利润、计入销售额订单数与客单价。
*/
private Totals aggregateTotals(List<OrderPO> orders, OrderStatusStatSets stat,
List<PromotionFeePO> promotionFees, List<BrushOrderPO> brushOrders,
BigDecimal taxRate) {
BigDecimal sales = BigDecimal.ZERO;
BigDecimal refund = BigDecimal.ZERO;
BigDecimal cost = BigDecimal.ZERO;
BigDecimal productCost = BigDecimal.ZERO;
BigDecimal freight = BigDecimal.ZERO;
BigDecimal other = BigDecimal.ZERO;
int orderCount = 0;
for (OrderPO o : orders) {
sales = sales.add(stat.receivedForSales(o));
refund = refund.add(stat.receivedForRefund(o));
productCost = productCost.add(stat.productCostForStats(o));
freight = freight.add(stat.freightCostForStats(o));
other = other.add(stat.otherCostForStats(o));
cost = cost.add(stat.totalCostForStats(o));
if (stat.includesSales(o.getStatusId())) {
orderCount++;
}
}
BigDecimal promotion = promotionFees.stream()
.map(f -> f.getFeeAmount() != null ? f.getFeeAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal brush = brushOrders.stream()
.map(b -> b.getBrushAmount() != null ? b.getBrushAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal grossOrder = sales.subtract(cost).subtract(refund);
BigDecimal profitBeforeTax = grossOrder.subtract(promotion).subtract(brush);
BigDecimal tax = salesTaxOnNetSales(sales, refund, taxRate);
BigDecimal netProfit = profitBeforeTax.subtract(tax);
BigDecimal aov = orderCount > 0
? sales.divide(BigDecimal.valueOf(orderCount), 2, RoundingMode.HALF_UP)
: BigDecimal.ZERO;
return new Totals(sales, refund, cost, productCost, freight, other, promotion, brush, tax,
grossOrder, netProfit, orderCount, aov);
}
/**
* 与单店概览一致:订单流水中「销售额−成本」的合计,再扣推广、刷单得税前;再扣税得净利。
*/
@@ -1207,13 +849,6 @@ public class WorkbenchServiceImpl implements WorkbenchService {
Map<Long, ShopPO> shopById) {
}
/** 当前区间订单与费用 */
private record CurrentPeriodBundle(List<OrderPO> orders,
List<PromotionFeePO> promotionFees,
List<BrushOrderPO> brushOrders,
Totals totals) {
}
/** 环比/同比汇总 */
private record ComparePeriodBundle(DateRange lastRange,
DateRange yoyRange,
@@ -1265,41 +900,22 @@ public class WorkbenchServiceImpl implements WorkbenchService {
BigDecimal netProfit,
int orderCount,
BigDecimal averageOrderValue) {
/** max(0, 销售额 − 退款),作税额分摊分母用 */
BigDecimal netSalesBase() {
BigDecimal b = totalSales.subtract(totalRefund);
return b.max(BigDecimal.ZERO);
}
}
/**
* 多维或按日聚合用的累加桶:与 {@link OrderStatusStatSets} 同步累计销售额、退款、成本,并统计计入销售额的订单笔数。
*/
/** 多维或按日聚合用的累加桶:累计销售额、退款、成本 */
private static final class Agg {
BigDecimal sales = BigDecimal.ZERO;
BigDecimal refund = BigDecimal.ZERO;
BigDecimal cost = BigDecimal.ZERO;
int orders;
/** 累加单笔订单的销售额、退款、成本;若状态计入销售额则订单笔数 +1 */
void add(OrderPO o, OrderStatusStatSets stat) {
sales = sales.add(stat.receivedForSales(o));
refund = refund.add(stat.receivedForRefund(o));
cost = cost.add(stat.totalCostForStats(o));
if (stat.includesSales(o.getStatusId())) {
orders++;
}
}
/** 累加 SQL 聚合行 */
void addFromAggRow(OrderStatAggMapper.ShopProductRow row) {
sales = sales.add(nz(row.getSalesAmount()));
refund = refund.add(nz(row.getRefundAmount()));
cost = cost.add(nz(row.getProductCost())).add(nz(row.getFreightCost())).add(nz(row.getOtherCost()));
orders += row.getOrderCount() != null ? row.getOrderCount().intValue() : 0;
}
/** 桶内净销售额 max(0, 销售−退款),与 {@link Totals#netSalesBase()} 含义一致,用于税额分摊 */
/** 桶内净销售额 max(0, 销售−退款),用于税额分摊 */
BigDecimal netSalesBase() {
BigDecimal b = sales.subtract(refund);
return b.max(BigDecimal.ZERO);
@@ -6,6 +6,7 @@ import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.lang.NonNull;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
@@ -41,13 +42,16 @@ public class ApiKeyAuthenticationFilter extends OncePerRequestFilter {
}
@Override
protected boolean shouldNotFilter(HttpServletRequest request) {
protected boolean shouldNotFilter(@NonNull HttpServletRequest request) {
String uri = request.getRequestURI();
return uri == null || !uri.startsWith(OPEN_PATH_PREFIX);
}
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
protected void doFilterInternal(
@NonNull HttpServletRequest request,
@NonNull HttpServletResponse response,
@NonNull FilterChain filterChain)
throws ServletException, IOException {
try {
String apiKey = extractApiKey(request);
@@ -1,10 +1,10 @@
package top.xyquan.ecomdmbbackend.modules.open.key.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
@@ -256,7 +256,7 @@ public class OpenApiKeyServiceImpl implements OpenApiKeyService {
}
private void copyToVo(OpenApiKeyPO po, OpenApiKeyVO vo) {
BeanUtils.copyProperties(po, vo, "ipWhitelist");
BeanCopyUtils.copyProperties(po, vo, "ipWhitelist");
List<OpenApiAvailablePermissionVO> permissions =
openApiKeyPermissionMapper.selectPermissionsByApiKeyId(po.getId());
vo.setPermissions(permissions);
@@ -1,4 +1,4 @@
package top.xyquan.ecomdmbbackend.modules.org.account.controller;
package top.xyquan.ecomdmbbackend.modules.org.company.account.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
@@ -9,11 +9,11 @@ import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
import top.xyquan.ecomdmbbackend.modules.org.account.model.dto.AccountFilterDTO;
import top.xyquan.ecomdmbbackend.modules.org.account.model.dto.CreateAccountDTO;
import top.xyquan.ecomdmbbackend.modules.org.account.model.dto.UpdateAccountDTO;
import top.xyquan.ecomdmbbackend.modules.org.account.model.vo.AccountVO;
import top.xyquan.ecomdmbbackend.modules.org.account.service.AccountService;
import top.xyquan.ecomdmbbackend.modules.org.company.account.model.dto.AccountFilterDTO;
import top.xyquan.ecomdmbbackend.modules.org.company.account.model.dto.CreateAccountDTO;
import top.xyquan.ecomdmbbackend.modules.org.company.account.model.dto.UpdateAccountDTO;
import top.xyquan.ecomdmbbackend.modules.org.company.account.model.vo.CompanyAccountVO;
import top.xyquan.ecomdmbbackend.modules.org.company.account.service.AccountService;
/**
* 公司账户管理控制器
@@ -35,8 +35,8 @@ public class AccountController {
@Operation(summary = "创建账户(拥有者)", description = "公司拥有者创建本公司账户;手机号已存在时将用户拉入本公司,不存在则新建用户")
@PostMapping("/create")
@RequirePermission(value = "org:company:manage", description = "创建账户", allowSuper = true)
public ApiResponse<AccountVO> createAccountForCompany(@Valid @RequestBody CreateAccountDTO createAccountDTO) {
AccountVO accountVO = accountService.createAccountForCompany(createAccountDTO);
public ApiResponse<CompanyAccountVO> createAccountForCompany(@Valid @RequestBody CreateAccountDTO createAccountDTO) {
CompanyAccountVO accountVO = accountService.createAccountForCompany(createAccountDTO);
return ApiResponse.success("账户创建成功", accountVO);
}
@@ -44,8 +44,8 @@ public class AccountController {
@Operation(summary = "分页查询账户(拥有者)", description = "公司拥有者分页查询本公司账户")
@PostMapping("/list")
@RequirePermission(value = "org:company:manage", description = "查询账户列表", allowSuper = true)
public ApiResponse<PageResultVO<AccountVO>> getAccountPageForCompany(@Valid @RequestBody PageQueryDTO<AccountFilterDTO> pageQuery) {
PageResultVO<AccountVO> pageResult = accountService.getAccountPageForCompany(pageQuery);
public ApiResponse<PageResultVO<CompanyAccountVO>> getAccountPageForCompany(@Valid @RequestBody PageQueryDTO<AccountFilterDTO> pageQuery) {
PageResultVO<CompanyAccountVO> pageResult = accountService.getAccountPageForCompany(pageQuery);
return ApiResponse.success("获取账户列表成功", pageResult);
}
@@ -53,10 +53,10 @@ public class AccountController {
@Operation(summary = "更新账户信息", description = "公司拥有者更新本公司账户信息")
@PutMapping("/update/{accountId}")
@RequirePermission(value = "org:company:manage", description = "更新账户", allowSuper = true)
public ApiResponse<AccountVO> updateAccount(
public ApiResponse<CompanyAccountVO> updateAccount(
@Parameter(description = "账户ID", example = "1") @PathVariable Long accountId,
@Valid @RequestBody UpdateAccountDTO updateAccountDTO) {
AccountVO accountVO = accountService.updateAccountForCompany(updateAccountDTO, accountId);
CompanyAccountVO accountVO = accountService.updateAccountForCompany(updateAccountDTO, accountId);
return ApiResponse.success("账户更新成功", accountVO);
}
@@ -73,9 +73,9 @@ public class AccountController {
@Operation(summary = "获取账户详情", description = "获取账户详细信息")
@GetMapping("/detail/{accountId}")
@RequirePermission(value = "org:company:manage", description = "获取账户详情", allowSuper = true)
public ApiResponse<AccountVO> getAccountDetail(
public ApiResponse<CompanyAccountVO> getAccountDetail(
@Parameter(description = "账户ID", example = "1") @PathVariable Long accountId) {
AccountVO accountVO = accountService.getAccountDetail(accountId);
CompanyAccountVO accountVO = accountService.getAccountDetail(accountId);
return ApiResponse.success("获取账户详情成功", accountVO);
}
}
@@ -1,4 +1,4 @@
package top.xyquan.ecomdmbbackend.modules.org.account.controller;
package top.xyquan.ecomdmbbackend.modules.org.company.account.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
@@ -9,11 +9,11 @@ import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
import top.xyquan.ecomdmbbackend.modules.org.account.model.dto.AccountFilterDTO;
import top.xyquan.ecomdmbbackend.modules.org.account.model.dto.SuperCreateAccountDTO;
import top.xyquan.ecomdmbbackend.modules.org.account.model.dto.SuperUpdateAccountDTO;
import top.xyquan.ecomdmbbackend.modules.org.account.model.vo.AccountVO;
import top.xyquan.ecomdmbbackend.modules.org.account.service.SuperAccountService;
import top.xyquan.ecomdmbbackend.modules.org.company.account.model.dto.AccountFilterDTO;
import top.xyquan.ecomdmbbackend.modules.org.company.account.model.dto.SuperCreateAccountDTO;
import top.xyquan.ecomdmbbackend.modules.org.company.account.model.dto.SuperUpdateAccountDTO;
import top.xyquan.ecomdmbbackend.modules.org.company.account.model.vo.CompanyAccountVO;
import top.xyquan.ecomdmbbackend.modules.org.company.account.service.SuperAccountService;
/**
* 超级管理员账户管理控制器
@@ -32,26 +32,26 @@ public class SuperAccountController {
@Operation(summary = "创建账户", description = "超级管理员创建账户,可指定公司")
@PostMapping("/create")
@RequirePermission(value = "org:company:manage", description = "创建账户", allowSuper = true)
public ApiResponse<AccountVO> createAccount(@Valid @RequestBody SuperCreateAccountDTO superCreateAccountDTO) {
AccountVO accountVO = superAccountService.createAccount(superCreateAccountDTO);
public ApiResponse<CompanyAccountVO> createAccount(@Valid @RequestBody SuperCreateAccountDTO superCreateAccountDTO) {
CompanyAccountVO accountVO = superAccountService.createAccount(superCreateAccountDTO);
return ApiResponse.success("账户创建成功", accountVO);
}
@Operation(summary = "分页查询账户", description = "超级管理员分页查询所有账户")
@PostMapping("/list")
@RequirePermission(value = "org:company:manage", description = "查询账户列表", allowSuper = true)
public ApiResponse<PageResultVO<AccountVO>> getAccountPage(@Valid @RequestBody PageQueryDTO<AccountFilterDTO> pageQuery) {
PageResultVO<AccountVO> pageResult = superAccountService.getAccountPage(pageQuery);
public ApiResponse<PageResultVO<CompanyAccountVO>> getAccountPage(@Valid @RequestBody PageQueryDTO<AccountFilterDTO> pageQuery) {
PageResultVO<CompanyAccountVO> pageResult = superAccountService.getAccountPage(pageQuery);
return ApiResponse.success("获取账户列表成功", pageResult);
}
@Operation(summary = "更新账户信息", description = "超级管理员更新账户信息")
@PutMapping("/update/{accountId}")
@RequirePermission(value = "org:company:manage", description = "更新账户", allowSuper = true)
public ApiResponse<AccountVO> updateAccount(
public ApiResponse<CompanyAccountVO> updateAccount(
@Parameter(description = "账户ID", example = "1") @PathVariable Long accountId,
@Valid @RequestBody SuperUpdateAccountDTO superUpdateAccountDTO) {
AccountVO accountVO = superAccountService.updateAccount(superUpdateAccountDTO, accountId);
CompanyAccountVO accountVO = superAccountService.updateAccount(superUpdateAccountDTO, accountId);
return ApiResponse.success("账户更新成功", accountVO);
}
@@ -67,9 +67,9 @@ public class SuperAccountController {
@Operation(summary = "获取账户详情", description = "超级管理员获取账户详细信息")
@GetMapping("/detail/{accountId}")
@RequirePermission(value = "org:company:manage", description = "查询账户详情", allowSuper = true)
public ApiResponse<AccountVO> getAccountDetail(
public ApiResponse<CompanyAccountVO> getAccountDetail(
@Parameter(description = "账户ID", example = "1") @PathVariable Long accountId) {
AccountVO accountVO = superAccountService.getAccountDetail(accountId);
CompanyAccountVO accountVO = superAccountService.getAccountDetail(accountId);
return ApiResponse.success("获取账户详情成功", accountVO);
}
}
@@ -1,4 +1,4 @@
package top.xyquan.ecomdmbbackend.modules.org.account.model.dto;
package top.xyquan.ecomdmbbackend.modules.org.company.account.model.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@@ -1,4 +1,4 @@
package top.xyquan.ecomdmbbackend.modules.org.account.model.dto;
package top.xyquan.ecomdmbbackend.modules.org.company.account.model.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
@@ -1,4 +1,4 @@
package top.xyquan.ecomdmbbackend.modules.org.account.model.dto;
package top.xyquan.ecomdmbbackend.modules.org.company.account.model.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
@@ -1,4 +1,4 @@
package top.xyquan.ecomdmbbackend.modules.org.account.model.dto;
package top.xyquan.ecomdmbbackend.modules.org.company.account.model.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Pattern;
@@ -1,4 +1,4 @@
package top.xyquan.ecomdmbbackend.modules.org.account.model.dto;
package top.xyquan.ecomdmbbackend.modules.org.company.account.model.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Pattern;
@@ -1,4 +1,4 @@
package top.xyquan.ecomdmbbackend.modules.org.account.model.vo;
package top.xyquan.ecomdmbbackend.modules.org.company.account.model.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@@ -13,7 +13,7 @@ import java.util.List;
public class AccountPageVO {
@Schema(description = "账户列表")
private List<AccountVO> records;
private List<CompanyAccountVO> records;
@Schema(description = "总记录数", example = "100")
private Long total;
@@ -1,4 +1,4 @@
package top.xyquan.ecomdmbbackend.modules.org.account.model.vo;
package top.xyquan.ecomdmbbackend.modules.org.company.account.model.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@@ -10,7 +10,7 @@ import java.time.LocalDateTime;
*/
@Data
@Schema(description = "账户信息")
public class AccountVO {
public class CompanyAccountVO {
@Schema(description = "用户ID", example = "1")
private Long id;
@@ -1,13 +1,13 @@
package top.xyquan.ecomdmbbackend.modules.org.account.service;
package top.xyquan.ecomdmbbackend.modules.org.company.account.service;
import com.baomidou.mybatisplus.extension.service.IService;
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
import top.xyquan.ecomdmbbackend.modules.org.account.model.dto.AccountFilterDTO;
import top.xyquan.ecomdmbbackend.modules.org.account.model.dto.CreateAccountDTO;
import top.xyquan.ecomdmbbackend.modules.org.account.model.dto.UpdateAccountDTO;
import top.xyquan.ecomdmbbackend.modules.org.company.account.model.dto.AccountFilterDTO;
import top.xyquan.ecomdmbbackend.modules.org.company.account.model.dto.CreateAccountDTO;
import top.xyquan.ecomdmbbackend.modules.org.company.account.model.dto.UpdateAccountDTO;
import top.xyquan.ecomdmbbackend.modules.org.company.account.model.vo.CompanyAccountVO;
import top.xyquan.ecomdmbbackend.modules.sys.user.model.po.UserPO;
import top.xyquan.ecomdmbbackend.modules.org.account.model.vo.AccountVO;
/**
* 账户管理服务接口
@@ -23,7 +23,7 @@ public interface AccountService extends IService<UserPO> {
* @param createAccountDTO 创建账户信息
* @return 账户信息
*/
AccountVO createAccountForCompany(CreateAccountDTO createAccountDTO);
CompanyAccountVO createAccountForCompany(CreateAccountDTO createAccountDTO);
/**
* 更新账户信息(拥有者接口)
@@ -32,7 +32,7 @@ public interface AccountService extends IService<UserPO> {
* @param accountId 账户ID
* @return 更新后的账户信息
*/
AccountVO updateAccountForCompany(UpdateAccountDTO updateAccountDTO, Long accountId);
CompanyAccountVO updateAccountForCompany(UpdateAccountDTO updateAccountDTO, Long accountId);
/**
* 删除账户(逻辑删除)
@@ -47,7 +47,7 @@ public interface AccountService extends IService<UserPO> {
* @param accountId 账户ID
* @return 账户详情
*/
AccountVO getAccountDetail(Long accountId);
CompanyAccountVO getAccountDetail(Long accountId);
/**
* 分页查询账户(超管接口)
@@ -55,7 +55,7 @@ public interface AccountService extends IService<UserPO> {
* @param pageQuery 分页查询参数
* @return 分页结果
*/
PageResultVO<AccountVO> getAccountPage(PageQueryDTO<AccountFilterDTO> pageQuery);
PageResultVO<CompanyAccountVO> getAccountPage(PageQueryDTO<AccountFilterDTO> pageQuery);
/**
* 分页查询账户(拥有者接口,只能查询本公司账户)
@@ -63,5 +63,5 @@ public interface AccountService extends IService<UserPO> {
* @param pageQuery 分页查询参数
* @return 分页结果
*/
PageResultVO<AccountVO> getAccountPageForCompany(PageQueryDTO<AccountFilterDTO> pageQuery);
PageResultVO<CompanyAccountVO> getAccountPageForCompany(PageQueryDTO<AccountFilterDTO> pageQuery);
}
@@ -1,13 +1,13 @@
package top.xyquan.ecomdmbbackend.modules.org.account.service;
package top.xyquan.ecomdmbbackend.modules.org.company.account.service;
import com.baomidou.mybatisplus.extension.service.IService;
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
import top.xyquan.ecomdmbbackend.modules.org.account.model.dto.AccountFilterDTO;
import top.xyquan.ecomdmbbackend.modules.org.account.model.dto.SuperCreateAccountDTO;
import top.xyquan.ecomdmbbackend.modules.org.account.model.dto.SuperUpdateAccountDTO;
import top.xyquan.ecomdmbbackend.modules.org.company.account.model.dto.AccountFilterDTO;
import top.xyquan.ecomdmbbackend.modules.org.company.account.model.dto.SuperCreateAccountDTO;
import top.xyquan.ecomdmbbackend.modules.org.company.account.model.dto.SuperUpdateAccountDTO;
import top.xyquan.ecomdmbbackend.modules.org.company.account.model.vo.CompanyAccountVO;
import top.xyquan.ecomdmbbackend.modules.sys.user.model.po.UserPO;
import top.xyquan.ecomdmbbackend.modules.org.account.model.vo.AccountVO;
/**
* 超级管理员账户管理服务接口
@@ -20,7 +20,7 @@ public interface SuperAccountService extends IService<UserPO> {
* @param superCreateAccountDTO 创建账户信息
* @return 账户信息
*/
AccountVO createAccount(SuperCreateAccountDTO superCreateAccountDTO);
CompanyAccountVO createAccount(SuperCreateAccountDTO superCreateAccountDTO);
/**
* 更新账户信息(超管接口)
@@ -29,7 +29,7 @@ public interface SuperAccountService extends IService<UserPO> {
* @param accountId 账户ID
* @return 更新后的账户信息
*/
AccountVO updateAccount(SuperUpdateAccountDTO superUpdateAccountDTO, Long accountId);
CompanyAccountVO updateAccount(SuperUpdateAccountDTO superUpdateAccountDTO, Long accountId);
/**
* 删除账户(逻辑删除)
@@ -44,7 +44,7 @@ public interface SuperAccountService extends IService<UserPO> {
* @param accountId 账户ID
* @return 账户详情
*/
AccountVO getAccountDetail(Long accountId);
CompanyAccountVO getAccountDetail(Long accountId);
/**
* 分页查询账户(超管接口)
@@ -52,5 +52,5 @@ public interface SuperAccountService extends IService<UserPO> {
* @param pageQuery 分页查询参数
* @return 分页结果
*/
PageResultVO<AccountVO> getAccountPage(PageQueryDTO<AccountFilterDTO> pageQuery);
PageResultVO<CompanyAccountVO> getAccountPage(PageQueryDTO<AccountFilterDTO> pageQuery);
}
@@ -1,10 +1,10 @@
package top.xyquan.ecomdmbbackend.modules.org.account.service.impl;
package top.xyquan.ecomdmbbackend.modules.org.company.account.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
@@ -12,12 +12,12 @@ import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
import top.xyquan.ecomdmbbackend.modules.sys.user.mapper.UserMapper;
import top.xyquan.ecomdmbbackend.modules.org.account.model.dto.AccountFilterDTO;
import top.xyquan.ecomdmbbackend.modules.org.account.model.dto.CreateAccountDTO;
import top.xyquan.ecomdmbbackend.modules.org.account.model.dto.UpdateAccountDTO;
import top.xyquan.ecomdmbbackend.modules.org.company.account.model.dto.AccountFilterDTO;
import top.xyquan.ecomdmbbackend.modules.org.company.account.model.dto.CreateAccountDTO;
import top.xyquan.ecomdmbbackend.modules.org.company.account.model.dto.UpdateAccountDTO;
import top.xyquan.ecomdmbbackend.modules.org.company.account.model.vo.CompanyAccountVO;
import top.xyquan.ecomdmbbackend.modules.org.company.account.service.AccountService;
import top.xyquan.ecomdmbbackend.modules.sys.user.model.po.UserPO;
import top.xyquan.ecomdmbbackend.modules.org.account.model.vo.AccountVO;
import top.xyquan.ecomdmbbackend.modules.org.account.service.AccountService;
import top.xyquan.ecomdmbbackend.modules.org.company.service.CompanyService;
import top.xyquan.ecomdmbbackend.modules.org.department.member.model.po.DepartmentMemberPO;
import top.xyquan.ecomdmbbackend.modules.org.department.member.model.vo.DepartmentMemberVO;
@@ -80,7 +80,7 @@ public class AccountServiceImpl extends ServiceImpl<UserMapper, UserPO> implemen
* @return 账户VO
*/
@Override
public AccountVO createAccountForCompany(CreateAccountDTO createAccountDTO) {
public CompanyAccountVO createAccountForCompany(CreateAccountDTO createAccountDTO) {
Long companyId = currentUserContext.getCurrentCompanyId();
if (companyId == null) {
throw new BusinessException("无法获取公司信息");
@@ -124,7 +124,7 @@ public class AccountServiceImpl extends ServiceImpl<UserMapper, UserPO> implemen
* 将已存在用户加入当前公司
* 不修改密码;可选更新姓名、备注;同时建立公司成员及部门关联
*/
private AccountVO addExistingUserToCompany(
private CompanyAccountVO addExistingUserToCompany(
UserPO user,
Long companyId,
CreateAccountDTO createAccountDTO,
@@ -160,7 +160,7 @@ public class AccountServiceImpl extends ServiceImpl<UserMapper, UserPO> implemen
* 新建用户并加入当前公司
* 登录账号与手机号相同,系统角色固定为 user,须传入密码
*/
private AccountVO createNewUserAndAddToCompany(
private CompanyAccountVO createNewUserAndAddToCompany(
Long companyId,
CreateAccountDTO createAccountDTO,
CompanyMemberRole memberRole) {
@@ -169,7 +169,7 @@ public class AccountServiceImpl extends ServiceImpl<UserMapper, UserPO> implemen
}
UserPO user = new UserPO();
BeanUtils.copyProperties(createAccountDTO, user);
BeanCopyUtils.copyProperties(createAccountDTO, user);
user.setPassword(passwordEncoder.encode(createAccountDTO.getPassword()));
user.setLoginCode(createAccountDTO.getPhone());
user.setRole("user");
@@ -197,7 +197,7 @@ public class AccountServiceImpl extends ServiceImpl<UserMapper, UserPO> implemen
* @return 账户VO
*/
@Override
public AccountVO updateAccountForCompany(UpdateAccountDTO updateAccountDTO, Long accountId) {
public CompanyAccountVO updateAccountForCompany(UpdateAccountDTO updateAccountDTO, Long accountId) {
// 查询账户
UserPO user = super.getById(accountId);
if (user == null) {
@@ -287,7 +287,7 @@ public class AccountServiceImpl extends ServiceImpl<UserMapper, UserPO> implemen
* @return 账户VO
*/
@Override
public AccountVO getAccountDetail(Long accountId) {
public CompanyAccountVO getAccountDetail(Long accountId) {
// 查询账户
UserPO user = super.getById(accountId);
if (user == null) {
@@ -304,7 +304,7 @@ public class AccountServiceImpl extends ServiceImpl<UserMapper, UserPO> implemen
* @return 分页结果VO
*/
@Override
public PageResultVO<AccountVO> getAccountPage(PageQueryDTO<AccountFilterDTO> pageQuery) {
public PageResultVO<CompanyAccountVO> getAccountPage(PageQueryDTO<AccountFilterDTO> pageQuery) {
// 构建查询条件
LambdaQueryWrapper<UserPO> wrapper = buildQueryWrapper(pageQuery.getFilters());
@@ -313,7 +313,7 @@ public class AccountServiceImpl extends ServiceImpl<UserMapper, UserPO> implemen
IPage<UserPO> pageResult = this.page(page, wrapper);
// 转换为VO
List<AccountVO> records = pageResult.getRecords().stream()
List<CompanyAccountVO> records = pageResult.getRecords().stream()
.map(this::convertToVO)
.collect(Collectors.toList());
@@ -327,7 +327,7 @@ public class AccountServiceImpl extends ServiceImpl<UserMapper, UserPO> implemen
* @return 分页结果VO
*/
@Override
public PageResultVO<AccountVO> getAccountPageForCompany(PageQueryDTO<AccountFilterDTO> pageQuery) {
public PageResultVO<CompanyAccountVO> getAccountPageForCompany(PageQueryDTO<AccountFilterDTO> pageQuery) {
// 从用户上下文获取公司ID
Long companyId = currentUserContext.getCurrentCompanyId();
if (companyId == null) {
@@ -411,9 +411,9 @@ public class AccountServiceImpl extends ServiceImpl<UserMapper, UserPO> implemen
* @param user 用户PO
* @return 账户VO
*/
private AccountVO convertToVO(UserPO user) {
AccountVO accountVO = new AccountVO();
BeanUtils.copyProperties(user, accountVO);
private CompanyAccountVO convertToVO(UserPO user) {
CompanyAccountVO accountVO = new CompanyAccountVO();
BeanCopyUtils.copyProperties(user, accountVO);
// 设置状态名称
accountVO.setStatusName(getStatusName(user.getStatus()));
@@ -1,10 +1,10 @@
package top.xyquan.ecomdmbbackend.modules.org.account.service.impl;
package top.xyquan.ecomdmbbackend.modules.org.company.account.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
@@ -12,12 +12,12 @@ import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
import top.xyquan.ecomdmbbackend.modules.sys.user.mapper.UserMapper;
import top.xyquan.ecomdmbbackend.modules.org.account.model.dto.AccountFilterDTO;
import top.xyquan.ecomdmbbackend.modules.org.account.model.dto.SuperCreateAccountDTO;
import top.xyquan.ecomdmbbackend.modules.org.account.model.dto.SuperUpdateAccountDTO;
import top.xyquan.ecomdmbbackend.modules.org.company.account.model.dto.AccountFilterDTO;
import top.xyquan.ecomdmbbackend.modules.org.company.account.model.dto.SuperCreateAccountDTO;
import top.xyquan.ecomdmbbackend.modules.org.company.account.model.dto.SuperUpdateAccountDTO;
import top.xyquan.ecomdmbbackend.modules.org.company.account.model.vo.CompanyAccountVO;
import top.xyquan.ecomdmbbackend.modules.org.company.account.service.SuperAccountService;
import top.xyquan.ecomdmbbackend.modules.sys.user.model.po.UserPO;
import top.xyquan.ecomdmbbackend.modules.org.account.model.vo.AccountVO;
import top.xyquan.ecomdmbbackend.modules.org.account.service.SuperAccountService;
import top.xyquan.ecomdmbbackend.modules.org.company.service.CompanyService;
import top.xyquan.ecomdmbbackend.modules.org.department.member.model.po.DepartmentMemberPO;
import top.xyquan.ecomdmbbackend.modules.org.department.member.model.vo.DepartmentMemberVO;
@@ -67,7 +67,7 @@ public class SuperAccountServiceImpl extends ServiceImpl<UserMapper, UserPO> imp
* @return 账户VO
*/
@Override
public AccountVO createAccount(SuperCreateAccountDTO superCreateAccountDTO) {
public CompanyAccountVO createAccount(SuperCreateAccountDTO superCreateAccountDTO) {
// 验证登录账号是否已存在
if (StringUtils.hasText(superCreateAccountDTO.getLoginCode())) {
LambdaQueryWrapper<UserPO> wrapper = new LambdaQueryWrapper<>();
@@ -88,7 +88,7 @@ public class SuperAccountServiceImpl extends ServiceImpl<UserMapper, UserPO> imp
// 创建账户
UserPO user = new UserPO();
BeanUtils.copyProperties(superCreateAccountDTO, user);
BeanCopyUtils.copyProperties(superCreateAccountDTO, user);
user.setPassword(passwordEncoder.encode(superCreateAccountDTO.getPassword()));
user.setStatus(1); // 正常状态(与 sys_user 表定义一致:1=正常,0=停用)
user.setPwdSecurityLevel(calculatePasswordSecurityLevel(superCreateAccountDTO.getPassword()));
@@ -120,7 +120,7 @@ public class SuperAccountServiceImpl extends ServiceImpl<UserMapper, UserPO> imp
* @return 账户VO
*/
@Override
public AccountVO updateAccount(SuperUpdateAccountDTO superUpdateAccountDTO, Long accountId) {
public CompanyAccountVO updateAccount(SuperUpdateAccountDTO superUpdateAccountDTO, Long accountId) {
// 查询账户
UserPO user = super.getById(accountId);
if (user == null) {
@@ -247,7 +247,7 @@ public class SuperAccountServiceImpl extends ServiceImpl<UserMapper, UserPO> imp
* @return 账户详情
*/
@Override
public AccountVO getAccountDetail(Long accountId) {
public CompanyAccountVO getAccountDetail(Long accountId) {
// 查询账户
UserPO user = super.getById(accountId);
if (user == null) {
@@ -264,7 +264,7 @@ public class SuperAccountServiceImpl extends ServiceImpl<UserMapper, UserPO> imp
* @return 分页结果VO
*/
@Override
public PageResultVO<AccountVO> getAccountPage(PageQueryDTO<AccountFilterDTO> pageQuery) {
public PageResultVO<CompanyAccountVO> getAccountPage(PageQueryDTO<AccountFilterDTO> pageQuery) {
// 构建查询条件
LambdaQueryWrapper<UserPO> wrapper = buildQueryWrapper(pageQuery.getFilters());
@@ -273,7 +273,7 @@ public class SuperAccountServiceImpl extends ServiceImpl<UserMapper, UserPO> imp
IPage<UserPO> pageResult = this.page(page, wrapper);
// 转换为VO
List<AccountVO> records = pageResult.getRecords().stream()
List<CompanyAccountVO> records = pageResult.getRecords().stream()
.map(this::convertToVO)
.collect(Collectors.toList());
@@ -376,9 +376,9 @@ public class SuperAccountServiceImpl extends ServiceImpl<UserMapper, UserPO> imp
/**
* 转换为VO
*/
private AccountVO convertToVO(UserPO user) {
AccountVO accountVO = new AccountVO();
BeanUtils.copyProperties(user, accountVO);
private CompanyAccountVO convertToVO(UserPO user) {
CompanyAccountVO accountVO = new CompanyAccountVO();
BeanCopyUtils.copyProperties(user, accountVO);
// 设置状态名称
accountVO.setStatusName(getStatusName(user.getStatus()));
@@ -1,8 +1,8 @@
package top.xyquan.ecomdmbbackend.modules.org.company.member.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
@@ -68,7 +68,7 @@ public class CompanyMemberServiceImpl extends ServiceImpl<CompanyMemberMapper, C
}
CompanyMemberPO member = new CompanyMemberPO();
BeanUtils.copyProperties(dto, member);
BeanCopyUtils.copyProperties(dto, member);
// DTO 的 role 是 String,PO 是枚举;BeanUtils 无法自动转换,需显式映射
member.setRole(CompanyMemberRole.fromCode(dto.getRole()));
member.setStatus(1);
@@ -211,7 +211,7 @@ public class CompanyMemberServiceImpl extends ServiceImpl<CompanyMemberMapper, C
@Override
public CompanyMemberVO convertToVO(CompanyMemberPO member) {
CompanyMemberVO vo = new CompanyMemberVO();
BeanUtils.copyProperties(member, vo);
BeanCopyUtils.copyProperties(member, vo);
// 设置状态名称
vo.setStatusName(member.getStatus() != null && member.getStatus() == 1 ? "正常" : "禁用");
@@ -1,8 +1,8 @@
package top.xyquan.ecomdmbbackend.modules.org.company.menu.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
@@ -70,7 +70,7 @@ public class CompanyMenuServiceImpl extends ServiceImpl<CompanyMenuMapper, Compa
// 创建公司菜单
CompanyMenuPO companyMenu = new CompanyMenuPO();
BeanUtils.copyProperties(createCompanyMenuDTO, companyMenu);
BeanCopyUtils.copyProperties(createCompanyMenuDTO, companyMenu);
// 设置默认值
if (companyMenu.getStatus() == null) {
@@ -119,7 +119,7 @@ public class CompanyMenuServiceImpl extends ServiceImpl<CompanyMenuMapper, Compa
return menus.stream()
.map(menu -> {
MenuVO menuVO = new MenuVO();
BeanUtils.copyProperties(menu, menuVO);
BeanCopyUtils.copyProperties(menu, menuVO);
return menuVO;
})
.collect(Collectors.toList());
@@ -315,7 +315,7 @@ public class CompanyMenuServiceImpl extends ServiceImpl<CompanyMenuMapper, Compa
*/
private CompanyMenuVO convertToCompanyMenuVO(MenuPO menu, CompanyMenuPO companyMenu) {
CompanyMenuVO companyMenuVO = new CompanyMenuVO();
BeanUtils.copyProperties(menu, companyMenuVO);
BeanCopyUtils.copyProperties(menu, companyMenuVO);
// 设置公司菜单ID
if (companyMenu != null) {
@@ -335,7 +335,7 @@ public class CompanyMenuServiceImpl extends ServiceImpl<CompanyMenuMapper, Compa
*/
private CompanyMenuVO convertToVO(CompanyMenuPO companyMenu) {
CompanyMenuVO companyMenuVO = new CompanyMenuVO();
BeanUtils.copyProperties(companyMenu, companyMenuVO);
BeanCopyUtils.copyProperties(companyMenu, companyMenuVO);
return companyMenuVO;
}
}
@@ -1,10 +1,10 @@
package top.xyquan.ecomdmbbackend.modules.org.company.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
@@ -99,7 +99,7 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, CompanyPO> im
// 创建公司
CompanyPO company = new CompanyPO();
BeanUtils.copyProperties(createCompanyDTO, company);
BeanCopyUtils.copyProperties(createCompanyDTO, company);
// 设置默认值
if (company.getStatus() == null) {
@@ -179,7 +179,7 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, CompanyPO> im
// 更新公司
CompanyPO company = new CompanyPO();
BeanUtils.copyProperties(updateCompanyDTO, company);
BeanCopyUtils.copyProperties(updateCompanyDTO, company);
// 设置公司ID(必须在updateById之前设置)
company.setId(id);
@@ -386,7 +386,7 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, CompanyPO> im
*/
private CompanyVO convertToVO(CompanyPO company) {
CompanyVO companyVO = new CompanyVO();
BeanUtils.copyProperties(company, companyVO);
BeanCopyUtils.copyProperties(company, companyVO);
// 计算是否过期
if (company.getExpireTime() != null) {
@@ -1,8 +1,8 @@
package top.xyquan.ecomdmbbackend.modules.org.department.member.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
@@ -122,7 +122,7 @@ public class DepartmentMemberServiceImpl extends ServiceImpl<DepartmentMemberMap
@Override
public DepartmentMemberVO convertToVO(DepartmentMemberPO member) {
DepartmentMemberVO vo = new DepartmentMemberVO();
BeanUtils.copyProperties(member, vo);
BeanCopyUtils.copyProperties(member, vo);
// 设置状态名称
vo.setStatusName(member.getStatus() != null && member.getStatus() == 1 ? "正常" : "禁用");
@@ -1,10 +1,10 @@
package top.xyquan.ecomdmbbackend.modules.org.department.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
@@ -59,7 +59,7 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
// 创建部门
DepartmentPO department = new DepartmentPO();
BeanUtils.copyProperties(createDepartmentDTO, department);
BeanCopyUtils.copyProperties(createDepartmentDTO, department);
// 设置公司ID
department.setCompanyId(companyId);
@@ -113,7 +113,7 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
// 更新部门
DepartmentPO department = new DepartmentPO();
BeanUtils.copyProperties(updateDepartmentDTO, department);
BeanCopyUtils.copyProperties(updateDepartmentDTO, department);
department.setId(id); // 确保ID正确设置
department.setCompanyId(companyId); // 设置公司ID
@@ -272,7 +272,7 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
// 创建部门
DepartmentPO department = new DepartmentPO();
BeanUtils.copyProperties(createDepartmentDTO, department);
BeanCopyUtils.copyProperties(createDepartmentDTO, department);
// 设置公司ID
department.setCompanyId(companyId);
@@ -299,7 +299,7 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
*/
private DepartmentVO convertToVO(DepartmentPO department) {
DepartmentVO departmentVO = new DepartmentVO();
BeanUtils.copyProperties(department, departmentVO);
BeanCopyUtils.copyProperties(department, departmentVO);
return departmentVO;
}
}
@@ -1,8 +1,8 @@
package top.xyquan.ecomdmbbackend.modules.org.position.menu.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
@@ -273,7 +273,7 @@ public class PositionMenuServiceImpl extends ServiceImpl<PositionMenuMapper, Pos
return menus.stream()
.map(menu -> {
MenuVO menuVO = new MenuVO();
BeanUtils.copyProperties(menu, menuVO);
BeanCopyUtils.copyProperties(menu, menuVO);
return menuVO;
})
.collect(Collectors.toList());
@@ -1,10 +1,10 @@
package top.xyquan.ecomdmbbackend.modules.org.position.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
@@ -55,7 +55,7 @@ public class PositionServiceImpl extends ServiceImpl<PositionMapper, PositionPO>
// 创建岗位
PositionPO position = new PositionPO();
BeanUtils.copyProperties(createPositionDTO, position);
BeanCopyUtils.copyProperties(createPositionDTO, position);
// 设置公司ID
position.setCompanyId(companyId);
@@ -109,7 +109,7 @@ public class PositionServiceImpl extends ServiceImpl<PositionMapper, PositionPO>
// 更新岗位
PositionPO position = new PositionPO();
BeanUtils.copyProperties(updatePositionDTO, position);
BeanCopyUtils.copyProperties(updatePositionDTO, position);
position.setId(id); // 确保ID正确设置
position.setCompanyId(companyId); // 设置公司ID
@@ -209,7 +209,7 @@ public class PositionServiceImpl extends ServiceImpl<PositionMapper, PositionPO>
// 创建岗位
PositionPO position = new PositionPO();
BeanUtils.copyProperties(createPositionDTO, position);
BeanCopyUtils.copyProperties(createPositionDTO, position);
// 设置公司ID
position.setCompanyId(companyId);
@@ -234,7 +234,7 @@ public class PositionServiceImpl extends ServiceImpl<PositionMapper, PositionPO>
*/
private PositionVO convertToVO(PositionPO position) {
PositionVO positionVO = new PositionVO();
BeanUtils.copyProperties(position, positionVO);
BeanCopyUtils.copyProperties(position, positionVO);
return positionVO;
}
}
@@ -1,10 +1,10 @@
package top.xyquan.ecomdmbbackend.modules.sub.plan.pricing.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
@@ -59,7 +59,7 @@ public class PlanPricingServiceImpl extends ServiceImpl<PlanPricingMapper, PlanP
// 创建定价
PlanPricingPO planPricing = new PlanPricingPO();
BeanUtils.copyProperties(createPlanPricingDTO, planPricing);
BeanCopyUtils.copyProperties(createPlanPricingDTO, planPricing);
// 设置默认值
if (planPricing.getStatus() == null) {
@@ -107,7 +107,7 @@ public class PlanPricingServiceImpl extends ServiceImpl<PlanPricingMapper, PlanP
// 更新定价
PlanPricingPO planPricing = new PlanPricingPO();
BeanUtils.copyProperties(updatePlanPricingDTO, planPricing);
BeanCopyUtils.copyProperties(updatePlanPricingDTO, planPricing);
// 设置更新人ID
planPricing.setUpdateBy(SecurityUtils.getCurrentUserId());
@@ -186,7 +186,7 @@ public class PlanPricingServiceImpl extends ServiceImpl<PlanPricingMapper, PlanP
*/
private PlanPricingVO convertToVO(PlanPricingPO planPricing) {
PlanPricingVO planPricingVO = new PlanPricingVO();
BeanUtils.copyProperties(planPricing, planPricingVO);
BeanCopyUtils.copyProperties(planPricing, planPricingVO);
// 获取套餐名称
if (planPricing.getPlanId() != null) {
@@ -204,7 +204,7 @@ public class PlanPricingServiceImpl extends ServiceImpl<PlanPricingMapper, PlanP
*/
private PlanPricingListVO convertToListVO(PlanPricingPO planPricing) {
PlanPricingListVO planPricingListVO = new PlanPricingListVO();
BeanUtils.copyProperties(planPricing, planPricingListVO);
BeanCopyUtils.copyProperties(planPricing, planPricingListVO);
// 获取套餐名称
if (planPricing.getPlanId() != null) {
@@ -1,10 +1,10 @@
package top.xyquan.ecomdmbbackend.modules.sub.plan.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
@@ -52,7 +52,7 @@ public class PlanServiceImpl extends ServiceImpl<PlanMapper, PlanPO> implements
// 创建套餐
PlanPO plan = new PlanPO();
BeanUtils.copyProperties(createPlanDTO, plan);
BeanCopyUtils.copyProperties(createPlanDTO, plan);
// 设置默认值
if (plan.getStatus() == null) {
@@ -100,7 +100,7 @@ public class PlanServiceImpl extends ServiceImpl<PlanMapper, PlanPO> implements
// 更新套餐
PlanPO plan = new PlanPO();
BeanUtils.copyProperties(updatePlanDTO, plan);
BeanCopyUtils.copyProperties(updatePlanDTO, plan);
// 设置更新人ID
plan.setUpdateBy(SecurityUtils.getCurrentUserId());
@@ -172,7 +172,7 @@ public class PlanServiceImpl extends ServiceImpl<PlanMapper, PlanPO> implements
*/
private PlanVO convertToVO(PlanPO plan) {
PlanVO planVO = new PlanVO();
BeanUtils.copyProperties(plan, planVO);
BeanCopyUtils.copyProperties(plan, planVO);
return planVO;
}
@@ -181,7 +181,7 @@ public class PlanServiceImpl extends ServiceImpl<PlanMapper, PlanPO> implements
*/
private PlanListVO convertToListVO(PlanPO plan) {
PlanListVO planListVO = new PlanListVO();
BeanUtils.copyProperties(plan, planListVO);
BeanCopyUtils.copyProperties(plan, planListVO);
return planListVO;
}
}
@@ -1,10 +1,10 @@
package top.xyquan.ecomdmbbackend.modules.sub.subscription.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
@@ -57,7 +57,7 @@ public class SubscriptionServiceImpl extends ServiceImpl<SubscriptionMapper, Sub
// 创建订阅
SubscriptionPO subscription = new SubscriptionPO();
BeanUtils.copyProperties(createSubscriptionDTO, subscription);
BeanCopyUtils.copyProperties(createSubscriptionDTO, subscription);
// 设置默认值
if (subscription.getStatus() == null) {
@@ -107,7 +107,7 @@ public class SubscriptionServiceImpl extends ServiceImpl<SubscriptionMapper, Sub
// 更新订阅
SubscriptionPO subscription = new SubscriptionPO();
BeanUtils.copyProperties(updateSubscriptionDTO, subscription);
BeanCopyUtils.copyProperties(updateSubscriptionDTO, subscription);
// 设置更新人ID
subscription.setUpdateBy(SecurityUtils.getCurrentUserId());
@@ -195,7 +195,7 @@ public class SubscriptionServiceImpl extends ServiceImpl<SubscriptionMapper, Sub
*/
private SubscriptionVO convertToVO(SubscriptionPO subscription) {
SubscriptionVO subscriptionVO = new SubscriptionVO();
BeanUtils.copyProperties(subscription, subscriptionVO);
BeanCopyUtils.copyProperties(subscription, subscriptionVO);
// 获取套餐名称
if (subscription.getPlanId() != null) {
@@ -221,7 +221,7 @@ public class SubscriptionServiceImpl extends ServiceImpl<SubscriptionMapper, Sub
*/
private SubscriptionListVO convertToListVO(SubscriptionPO subscription) {
SubscriptionListVO subscriptionListVO = new SubscriptionListVO();
BeanUtils.copyProperties(subscription, subscriptionListVO);
BeanCopyUtils.copyProperties(subscription, subscriptionListVO);
// 获取套餐名称
if (subscription.getPlanId() != null) {
@@ -1,10 +1,10 @@
package top.xyquan.ecomdmbbackend.modules.sys.file.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
@@ -112,7 +112,7 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFilePO> im
// 创建当前公司的文件记录
SysFilePO sysFile = new SysFilePO();
BeanUtils.copyProperties(otherCompanyFile, sysFile);
BeanCopyUtils.copyProperties(otherCompanyFile, sysFile);
sysFile.setId(null);
sysFile.setCompanyId(companyId);
sysFile.setStoragePath(storagePath);
@@ -268,7 +268,7 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFilePO> im
if (verifyFileExists(otherCompanyFile)) {
// 创建当前公司的文件记录
SysFilePO newFile = new SysFilePO();
BeanUtils.copyProperties(otherCompanyFile, newFile);
BeanCopyUtils.copyProperties(otherCompanyFile, newFile);
newFile.setId(null);
newFile.setCompanyId(companyId);
newFile.setFilename(item.getFilename());
@@ -363,7 +363,7 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFilePO> im
if (otherCompanyFile != null) {
// 其他公司已有相同文件,复制记录并关联当前公司
sysFile = new SysFilePO();
BeanUtils.copyProperties(otherCompanyFile, sysFile);
BeanCopyUtils.copyProperties(otherCompanyFile, sysFile);
sysFile.setId(null);
sysFile.setCompanyId(companyId);
sysFile.setStoragePath(item.getStoragePath());
@@ -521,7 +521,7 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFilePO> im
*/
private SysFileVO convertToVO(SysFilePO sysFile) {
SysFileVO vo = new SysFileVO();
BeanUtils.copyProperties(sysFile, vo);
BeanCopyUtils.copyProperties(sysFile, vo);
// 使用工具类生成访问URL
String accessUrl = SysFileUtils.getFileAccessUrl(sysFile.getStoragePath(), sysFile.getStorageType());
@@ -628,7 +628,7 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFilePO> im
return null;
}
SysFileVO vo = new SysFileVO();
BeanUtils.copyProperties(file, vo);
BeanCopyUtils.copyProperties(file, vo);
return vo;
}
}
@@ -1,9 +1,9 @@
package top.xyquan.ecomdmbbackend.modules.sys.menu.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
@@ -59,7 +59,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, MenuPO> implements
// 创建菜单
MenuPO menu = new MenuPO();
BeanUtils.copyProperties(createMenuDTO, menu);
BeanCopyUtils.copyProperties(createMenuDTO, menu);
// 设置默认值
if (menu.getSuperMenu() == null) {
@@ -122,7 +122,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, MenuPO> implements
}
// 更新菜单
BeanUtils.copyProperties(updateMenuDTO, existingMenu);
BeanCopyUtils.copyProperties(updateMenuDTO, existingMenu);
existingMenu.setId(id); // 确保ID正确设置
// 设置更新人ID
@@ -285,7 +285,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, MenuPO> implements
*/
private MenuVO convertToVO(MenuPO menu) {
MenuVO menuVO = new MenuVO();
BeanUtils.copyProperties(menu, menuVO);
BeanCopyUtils.copyProperties(menu, menuVO);
// 查询菜单关联的权限
List<PermissionVO> permissions = baseMapper.selectPermissionsByMenuId(menu.getId());
@@ -1,11 +1,11 @@
package top.xyquan.ecomdmbbackend.modules.sys.permission.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
@@ -58,7 +58,7 @@ public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permiss
}
PermissionPO po = new PermissionPO();
BeanUtils.copyProperties(dto, po);
BeanCopyUtils.copyProperties(dto, po);
if (po.getStatus() == null) po.setStatus(1);
if (po.getSortOrder() == null) po.setSortOrder(0);
po.setCreateBy(currentUserContext.getCurrentUserId());
@@ -82,7 +82,7 @@ public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permiss
throw new BusinessException("该父节点下已存在相同权限码");
}
BeanUtils.copyProperties(dto, existing);
BeanCopyUtils.copyProperties(dto, existing);
existing.setUpdateBy(currentUserContext.getCurrentUserId());
permissionMapper.updateById(existing);
return convertToVO(existing);
@@ -231,7 +231,7 @@ public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permiss
for (PermissionVO node : nodes) {
if (visibleIds.contains(node.getId())) {
PermissionVO filteredNode = new PermissionVO();
BeanUtils.copyProperties(node, filteredNode);
BeanCopyUtils.copyProperties(node, filteredNode);
if (node.getChildren() != null && !node.getChildren().isEmpty()) {
filteredNode.setChildren(filterVisibleTree(node.getChildren(), visibleIds));
}
@@ -255,7 +255,7 @@ public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permiss
private PermissionVO convertToVO(PermissionPO po) {
PermissionVO vo = new PermissionVO();
BeanUtils.copyProperties(po, vo);
BeanCopyUtils.copyProperties(po, vo);
return vo;
}
}
@@ -1,8 +1,8 @@
package top.xyquan.ecomdmbbackend.modules.sys.user.service.impl;
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.context.annotation.Lazy;
@@ -184,7 +184,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserPO> implements
// 转换为VO
UserVO userVO = new UserVO();
BeanUtils.copyProperties(user, userVO);
BeanCopyUtils.copyProperties(user, userVO);
fillCompanyFromCurrentToken(userVO);
userVO.setCompanyCount(countAvailableCompanies(userId));
return userVO;
@@ -255,7 +255,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserPO> implements
// 转换为VO并返回
UserVO userVO = new UserVO();
BeanUtils.copyProperties(user, userVO);
BeanCopyUtils.copyProperties(user, userVO);
fillCompanyFromCurrentToken(userVO);
return userVO;
}
@@ -321,7 +321,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserPO> implements
// 转换为VO并返回
UserVO userVO = new UserVO();
BeanUtils.copyProperties(user, userVO);
BeanCopyUtils.copyProperties(user, userVO);
fillCompanyFromCurrentToken(userVO);
return userVO;
}
@@ -557,7 +557,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserPO> implements
*/
private UserVO convertToUserVO(UserPO user) {
UserVO userVO = new UserVO();
BeanUtils.copyProperties(user, userVO);
BeanCopyUtils.copyProperties(user, userVO);
fillCompanyByCompanyId(userVO, user.getLastCompanyId());
return userVO;
}
@@ -3,6 +3,7 @@ package top.xyquan.ecomdmbbackend.utils;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;
import top.xyquan.ecomdmbbackend.modules.sys.permission.service.PermissionCheckService;
@@ -16,7 +17,7 @@ public class PermissionUtils implements ApplicationContextAware {
private static ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
public void setApplicationContext(@NonNull ApplicationContext applicationContext) throws BeansException {
PermissionUtils.applicationContext = applicationContext;
}