You've already forked FrameTour-BE
feat(service): 批量获取景区和设备信息
- 在 DeviceRepository 中添加批量获取设备信息的方法 - 在 ScenicRepository 中添加批量获取景区信息的方法 - 修改 OrderServiceImpl,使用批量方法获取景区名称 - 移除多个 mapper 文件中冗余的景区信息查询
This commit is contained in:
@@ -17,6 +17,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Slf4j
|
||||
@@ -165,4 +167,77 @@ public class DeviceRepository {
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量获取设备信息
|
||||
* @param deviceIds 设备ID列表
|
||||
* @return 设备ID到设备实体的映射
|
||||
*/
|
||||
public Map<Long, DeviceEntity> batchGetDevices(List<Long> deviceIds) {
|
||||
if (deviceIds == null || deviceIds.isEmpty()) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
Map<Long, DeviceEntity> result = new HashMap<>();
|
||||
for (Long deviceId : deviceIds) {
|
||||
try {
|
||||
DeviceEntity device = getDevice(deviceId);
|
||||
if (device != null) {
|
||||
result.put(deviceId, device);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("获取设备信息失败: {}, 错误: {}", deviceId, e.getMessage());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量根据设备编号获取设备信息
|
||||
* @param deviceNos 设备编号列表
|
||||
* @return 设备编号到设备实体的映射
|
||||
*/
|
||||
public Map<String, DeviceEntity> batchGetDevicesByNo(List<String> deviceNos) {
|
||||
if (deviceNos == null || deviceNos.isEmpty()) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
Map<String, DeviceEntity> result = new HashMap<>();
|
||||
for (String deviceNo : deviceNos) {
|
||||
try {
|
||||
DeviceEntity device = getDeviceByDeviceNo(deviceNo);
|
||||
if (device != null) {
|
||||
result.put(deviceNo, device);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("根据设备编号获取设备信息失败: {}, 错误: {}", deviceNo, e.getMessage());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量获取设备名称
|
||||
* @param deviceIds 设备ID列表
|
||||
* @return 设备ID到设备名称的映射
|
||||
*/
|
||||
public Map<Long, String> batchGetDeviceNames(List<Long> deviceIds) {
|
||||
if (deviceIds == null || deviceIds.isEmpty()) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
Map<Long, String> result = new HashMap<>();
|
||||
for (Long deviceId : deviceIds) {
|
||||
try {
|
||||
DeviceEntity device = getDevice(deviceId);
|
||||
if (device != null) {
|
||||
result.put(deviceId, device.getName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("获取设备名称失败: {}, 错误: {}", deviceId, e.getMessage());
|
||||
result.put(deviceId, "未知设备");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@@ -25,6 +25,9 @@ import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
public class ScenicRepository {
|
||||
@@ -359,4 +362,79 @@ public class ScenicRepository {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量获取景区名称
|
||||
* @param scenicIds 景区ID列表
|
||||
* @return 景区ID到景区名称的映射
|
||||
*/
|
||||
public Map<Long, String> batchGetScenicNames(List<Long> scenicIds) {
|
||||
if (scenicIds == null || scenicIds.isEmpty()) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
Map<Long, String> result = new HashMap<>();
|
||||
for (Long scenicId : scenicIds) {
|
||||
try {
|
||||
ScenicV2DTO scenic = getScenicBasic(scenicId);
|
||||
if (scenic != null) {
|
||||
result.put(scenicId, scenic.getName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 获取失败时使用默认值
|
||||
result.put(scenicId, "未知景区");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量获取景区完整信息
|
||||
* @param scenicIds 景区ID列表
|
||||
* @return 景区ID到景区实体的映射
|
||||
*/
|
||||
public Map<Long, ScenicEntity> batchGetScenics(List<Long> scenicIds) {
|
||||
if (scenicIds == null || scenicIds.isEmpty()) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
Map<Long, ScenicEntity> result = new HashMap<>();
|
||||
for (Long scenicId : scenicIds) {
|
||||
try {
|
||||
ScenicEntity scenic = getScenic(scenicId);
|
||||
if (scenic != null) {
|
||||
result.put(scenicId, scenic);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 获取失败时记录日志但不中断处理
|
||||
System.err.println("获取景区信息失败: " + scenicId + ", 错误: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量获取景区基础信息DTO
|
||||
* @param scenicIds 景区ID列表
|
||||
* @return 景区ID到景区DTO的映射
|
||||
*/
|
||||
public Map<Long, ScenicV2DTO> batchGetScenicBasics(List<Long> scenicIds) {
|
||||
if (scenicIds == null || scenicIds.isEmpty()) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
Map<Long, ScenicV2DTO> result = new HashMap<>();
|
||||
for (Long scenicId : scenicIds) {
|
||||
try {
|
||||
ScenicV2DTO scenic = getScenicBasic(scenicId);
|
||||
if (scenic != null) {
|
||||
result.put(scenicId, scenic);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 获取失败时记录日志但不中断处理
|
||||
System.err.println("获取景区基础信息失败: " + scenicId + ", 错误: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -53,6 +53,7 @@ import com.ycwl.basic.pay.adapter.IPayAdapter;
|
||||
import com.ycwl.basic.pay.entity.PayResponse;
|
||||
import com.ycwl.basic.repository.FaceRepository;
|
||||
import com.ycwl.basic.repository.PriceRepository;
|
||||
import com.ycwl.basic.repository.ScenicRepository;
|
||||
import com.ycwl.basic.repository.TemplateRepository;
|
||||
import com.ycwl.basic.repository.VideoRepository;
|
||||
import com.ycwl.basic.repository.VideoTaskRepository;
|
||||
@@ -129,6 +130,8 @@ public class OrderServiceImpl implements OrderService {
|
||||
@Autowired
|
||||
private ScenicService scenicService;
|
||||
@Autowired
|
||||
private ScenicRepository scenicRepository;
|
||||
@Autowired
|
||||
private VideoMapper videoMapper;
|
||||
@Autowired
|
||||
private IVoucherService iVoucherService;
|
||||
@@ -139,7 +142,21 @@ public class OrderServiceImpl implements OrderService {
|
||||
public ApiResponse<PageInfo<OrderRespVO>> pageQuery(OrderReqQuery query) {
|
||||
PageHelper.startPage(query.getPageNum(), query.getPageSize());
|
||||
List<OrderRespVO> list = orderMapper.list(query);
|
||||
|
||||
// 批量获取景区名称
|
||||
List<Long> scenicIds = list.stream()
|
||||
.map(OrderRespVO::getScenicId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
Map<Long, String> scenicNames = scenicRepository.batchGetScenicNames(scenicIds);
|
||||
|
||||
list.forEach(item -> {
|
||||
// 设置景区名称
|
||||
if (item.getScenicId() != null) {
|
||||
item.setScenicName(scenicNames.get(item.getScenicId()));
|
||||
}
|
||||
|
||||
if (Integer.valueOf(-1).equals(item.getType())) {
|
||||
item.setGoodsName("一口价");
|
||||
item.setOrderType("一口价");
|
||||
@@ -181,8 +198,21 @@ public class OrderServiceImpl implements OrderService {
|
||||
public ApiResponse<PageInfo<OrderRespVO>> pageQueryDetail(OrderReqQuery query) {
|
||||
PageHelper.startPage(query.getPageNum(), query.getPageSize());
|
||||
List<OrderRespVO> list = orderMapper.listDetail(query);
|
||||
|
||||
// 批量获取景区名称
|
||||
List<Long> scenicIds = list.stream()
|
||||
.map(OrderRespVO::getScenicId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
Map<Long, String> scenicNames = scenicRepository.batchGetScenicNames(scenicIds);
|
||||
|
||||
for (OrderRespVO item : list) {
|
||||
item.setPrice(item.getPayPrice());
|
||||
// 设置景区名称
|
||||
if (item.getScenicId() != null) {
|
||||
item.setScenicName(scenicNames.get(item.getScenicId()));
|
||||
}
|
||||
}
|
||||
PageInfo<OrderRespVO> pageInfo = new PageInfo<>(list);
|
||||
return ApiResponse.success(pageInfo);
|
||||
@@ -191,8 +221,21 @@ public class OrderServiceImpl implements OrderService {
|
||||
@Override
|
||||
public ApiResponse<List<OrderRespVO>> list(OrderReqQuery query) {
|
||||
List<OrderRespVO> list = orderMapper.list(query);
|
||||
|
||||
// 批量获取景区名称
|
||||
List<Long> scenicIds = list.stream()
|
||||
.map(OrderRespVO::getScenicId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
Map<Long, String> scenicNames = scenicRepository.batchGetScenicNames(scenicIds);
|
||||
|
||||
for (OrderRespVO item : list) {
|
||||
item.setPrice(item.getPayPrice());
|
||||
// 设置景区名称
|
||||
if (item.getScenicId() != null) {
|
||||
item.setScenicName(scenicNames.get(item.getScenicId()));
|
||||
}
|
||||
}
|
||||
return ApiResponse.success(list);
|
||||
}
|
||||
@@ -318,6 +361,18 @@ public class OrderServiceImpl implements OrderService {
|
||||
}
|
||||
});
|
||||
order.setGoodsList(goodsList);
|
||||
|
||||
// 设置景区名称
|
||||
if (order.getScenicId() != null) {
|
||||
try {
|
||||
String scenicName = scenicRepository.batchGetScenicNames(List.of(order.getScenicId()))
|
||||
.get(order.getScenicId());
|
||||
order.setScenicName(scenicName);
|
||||
} catch (Exception e) {
|
||||
log.warn("获取景区名称失败: {}", order.getScenicId(), e);
|
||||
}
|
||||
}
|
||||
|
||||
return ApiResponse.success(order);
|
||||
}
|
||||
|
||||
@@ -437,6 +492,22 @@ public class OrderServiceImpl implements OrderService {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 批量获取景区名称
|
||||
List<Long> scenicIds = list.stream()
|
||||
.map(OrderAppRespVO::getScenicId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
Map<Long, String> scenicNames = scenicRepository.batchGetScenicNames(scenicIds);
|
||||
|
||||
// 设置景区名称
|
||||
list.forEach(order -> {
|
||||
if (order.getScenicId() != null) {
|
||||
order.setScenicName(scenicNames.get(order.getScenicId()));
|
||||
}
|
||||
});
|
||||
|
||||
PageInfo<OrderAppRespVO> pageInfo = new PageInfo<>(list);
|
||||
return ApiResponse.success(pageInfo);
|
||||
}
|
||||
@@ -444,6 +515,18 @@ public class OrderServiceImpl implements OrderService {
|
||||
@Override
|
||||
public ApiResponse<OrderAppRespVO> appDetail(Long id) {
|
||||
OrderAppRespVO orderAppRespVO = orderMapper.appDetail(id);
|
||||
|
||||
// 设置景区名称
|
||||
if (orderAppRespVO != null && orderAppRespVO.getScenicId() != null) {
|
||||
try {
|
||||
String scenicName = scenicRepository.batchGetScenicNames(List.of(orderAppRespVO.getScenicId()))
|
||||
.get(orderAppRespVO.getScenicId());
|
||||
orderAppRespVO.setScenicName(scenicName);
|
||||
} catch (Exception e) {
|
||||
log.warn("获取景区名称失败: {}", orderAppRespVO.getScenicId(), e);
|
||||
}
|
||||
}
|
||||
|
||||
return ApiResponse.success(orderAppRespVO);
|
||||
}
|
||||
|
||||
@@ -484,7 +567,21 @@ public class OrderServiceImpl implements OrderService {
|
||||
public ApiResponse<PageInfo<OrderRespVO>> refundPageQuery(OrderReqQuery query) {
|
||||
PageHelper.startPage(query.getPageNum(), query.getPageSize());
|
||||
List<OrderRespVO> list = orderMapper.refundList(query);
|
||||
|
||||
// 批量获取景区名称
|
||||
List<Long> scenicIds = list.stream()
|
||||
.map(OrderRespVO::getScenicId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
Map<Long, String> scenicNames = scenicRepository.batchGetScenicNames(scenicIds);
|
||||
|
||||
list.forEach(item -> {
|
||||
// 设置景区名称
|
||||
if (item.getScenicId() != null) {
|
||||
item.setScenicName(scenicNames.get(item.getScenicId()));
|
||||
}
|
||||
|
||||
if (Integer.valueOf(-1).equals(item.getType())) {
|
||||
item.setGoodsName("一口价");
|
||||
item.setOrderType("一口价");
|
||||
|
Reference in New Issue
Block a user