feat(dashboard): 实现仪表板最近活动数据动态加载
- 为订单、出库、发票和返利模块添加最近记录查询接口 - 在仪表板服务中调用各业务模块真实数据替换模拟数据 - 新增时间格式化工具方法,支持显示相对时间 - 注入返利服务依赖并完善相关数据获取逻辑 - 移除无用的Set导入语句,优化代码结构
Showing
9 changed files
with
183 additions
and
34 deletions
| ... | @@ -73,6 +73,14 @@ public interface DeliveryMainService extends IService<DeliveryMain> { | ... | @@ -73,6 +73,14 @@ public interface DeliveryMainService extends IService<DeliveryMain> { |
| 73 | * @return 待出库数量 | 73 | * @return 待出库数量 |
| 74 | */ | 74 | */ |
| 75 | Integer getPendingDeliveryCount(); | 75 | Integer getPendingDeliveryCount(); |
| 76 | + | ||
| 77 | + /** | ||
| 78 | + * 获取最近的出库记录 | ||
| 79 | + * | ||
| 80 | + * @param limit 限制数量 | ||
| 81 | + * @return 最近出库列表 | ||
| 82 | + */ | ||
| 83 | + List<DeliveryRes> getRecentDeliveries(Integer limit); | ||
| 76 | } | 84 | } |
| 77 | 85 | ||
| 78 | 86 | ... | ... |
| ... | @@ -73,6 +73,14 @@ public interface InvoiceMainService extends IService<InvoiceMain> { | ... | @@ -73,6 +73,14 @@ public interface InvoiceMainService extends IService<InvoiceMain> { |
| 73 | * @return 待开票数量 | 73 | * @return 待开票数量 |
| 74 | */ | 74 | */ |
| 75 | Integer getPendingInvoiceCount(); | 75 | Integer getPendingInvoiceCount(); |
| 76 | + | ||
| 77 | + /** | ||
| 78 | + * 获取最近的发票记录 | ||
| 79 | + * | ||
| 80 | + * @param limit 限制数量 | ||
| 81 | + * @return 最近发票列表 | ||
| 82 | + */ | ||
| 83 | + List<InvoiceRes> getRecentInvoices(Integer limit); | ||
| 76 | } | 84 | } |
| 77 | 85 | ||
| 78 | 86 | ... | ... |
| ... | @@ -108,5 +108,13 @@ public interface OrderMainService extends IService<OrderMain> { | ... | @@ -108,5 +108,13 @@ public interface OrderMainService extends IService<OrderMain> { |
| 108 | * @return 销售额 | 108 | * @return 销售额 |
| 109 | */ | 109 | */ |
| 110 | Double getTodaySalesAmount(String date); | 110 | Double getTodaySalesAmount(String date); |
| 111 | + | ||
| 112 | + /** | ||
| 113 | + * 获取最近的订单记录 | ||
| 114 | + * | ||
| 115 | + * @param limit 限制数量 | ||
| 116 | + * @return 最近订单列表 | ||
| 117 | + */ | ||
| 118 | + List<OrderRes> getRecentOrders(Integer limit); | ||
| 111 | } | 119 | } |
| 112 | 120 | ... | ... |
| ... | @@ -139,4 +139,12 @@ public interface RebateService extends IService<Rebate> { | ... | @@ -139,4 +139,12 @@ public interface RebateService extends IService<Rebate> { |
| 139 | * @return 趋势统计数据 | 139 | * @return 趋势统计数据 |
| 140 | */ | 140 | */ |
| 141 | List<Map<String, Object>> getRebateTrendStats(String startDate, String endDate); | 141 | List<Map<String, Object>> getRebateTrendStats(String startDate, String endDate); |
| 142 | + | ||
| 143 | + /** | ||
| 144 | + * 获取最近的返利记录 | ||
| 145 | + * | ||
| 146 | + * @param limit 限制数量 | ||
| 147 | + * @return 最近返利列表 | ||
| 148 | + */ | ||
| 149 | + List<RebateRes> getRecentRebates(Integer limit); | ||
| 142 | } | 150 | } | ... | ... |
| 1 | package com.apple.erp.service.impl; | 1 | package com.apple.erp.service.impl; |
| 2 | 2 | ||
| 3 | import com.apple.erp.dto.response.DashboardStatsRes; | 3 | import com.apple.erp.dto.response.DashboardStatsRes; |
| 4 | +import com.apple.erp.dto.OrderRes; | ||
| 5 | +import com.apple.erp.dto.DeliveryRes; | ||
| 6 | +import com.apple.erp.dto.InvoiceRes; | ||
| 7 | +import com.apple.erp.dto.response.RebateRes; | ||
| 4 | import com.apple.erp.service.DashboardService; | 8 | import com.apple.erp.service.DashboardService; |
| 5 | import com.apple.erp.service.OrderMainService; | 9 | import com.apple.erp.service.OrderMainService; |
| 6 | import com.apple.erp.service.DeliveryMainService; | 10 | import com.apple.erp.service.DeliveryMainService; |
| 7 | import com.apple.erp.service.InvoiceMainService; | 11 | import com.apple.erp.service.InvoiceMainService; |
| 12 | +import com.apple.erp.service.RebateService; | ||
| 8 | import com.apple.erp.service.SessionService; | 13 | import com.apple.erp.service.SessionService; |
| 9 | import lombok.extern.slf4j.Slf4j; | 14 | import lombok.extern.slf4j.Slf4j; |
| 10 | import org.springframework.beans.factory.annotation.Autowired; | 15 | import org.springframework.beans.factory.annotation.Autowired; |
| ... | @@ -16,7 +21,6 @@ import java.util.ArrayList; | ... | @@ -16,7 +21,6 @@ import java.util.ArrayList; |
| 16 | import java.util.HashMap; | 21 | import java.util.HashMap; |
| 17 | import java.util.List; | 22 | import java.util.List; |
| 18 | import java.util.Map; | 23 | import java.util.Map; |
| 19 | -import java.util.Set; | ||
| 20 | 24 | ||
| 21 | /** | 25 | /** |
| 22 | * 首页仪表板服务实现 | 26 | * 首页仪表板服务实现 |
| ... | @@ -35,6 +39,9 @@ public class DashboardServiceImpl implements DashboardService { | ... | @@ -35,6 +39,9 @@ public class DashboardServiceImpl implements DashboardService { |
| 35 | private InvoiceMainService invoiceMainService; | 39 | private InvoiceMainService invoiceMainService; |
| 36 | 40 | ||
| 37 | @Autowired | 41 | @Autowired |
| 42 | + private RebateService rebateService; | ||
| 43 | + | ||
| 44 | + @Autowired | ||
| 38 | private SessionService sessionService; | 45 | private SessionService sessionService; |
| 39 | 46 | ||
| 40 | @Override | 47 | @Override |
| ... | @@ -130,14 +137,15 @@ public class DashboardServiceImpl implements DashboardService { | ... | @@ -130,14 +137,15 @@ public class DashboardServiceImpl implements DashboardService { |
| 130 | private List<Map<String, Object>> getRecentOrders() { | 137 | private List<Map<String, Object>> getRecentOrders() { |
| 131 | List<Map<String, Object>> activities = new ArrayList<>(); | 138 | List<Map<String, Object>> activities = new ArrayList<>(); |
| 132 | try { | 139 | try { |
| 133 | - // 这里应该从数据库查询最近的订单 | 140 | + List<OrderRes> recentOrders = orderMainService.getRecentOrders(2); |
| 134 | - // 暂时返回模拟数据 | 141 | + for (OrderRes order : recentOrders) { |
| 135 | - Map<String, Object> activity = new HashMap<>(); | 142 | + Map<String, Object> activity = new HashMap<>(); |
| 136 | - activity.put("id", 1); | 143 | + activity.put("id", order.getOrderId()); |
| 137 | - activity.put("type", "order"); | 144 | + activity.put("type", "order"); |
| 138 | - activity.put("title", "新订单 ORD-2025-001 已创建"); | 145 | + activity.put("title", "新订单 " + order.getOrderNo() + " 已创建"); |
| 139 | - activity.put("time", "2分钟前"); | 146 | + activity.put("time", formatTimeAgo(order.getCreateTime())); |
| 140 | - activities.add(activity); | 147 | + activities.add(activity); |
| 148 | + } | ||
| 141 | } catch (Exception e) { | 149 | } catch (Exception e) { |
| 142 | log.error("获取最近订单活动失败", e); | 150 | log.error("获取最近订单活动失败", e); |
| 143 | } | 151 | } |
| ... | @@ -150,14 +158,15 @@ public class DashboardServiceImpl implements DashboardService { | ... | @@ -150,14 +158,15 @@ public class DashboardServiceImpl implements DashboardService { |
| 150 | private List<Map<String, Object>> getRecentDeliveries() { | 158 | private List<Map<String, Object>> getRecentDeliveries() { |
| 151 | List<Map<String, Object>> activities = new ArrayList<>(); | 159 | List<Map<String, Object>> activities = new ArrayList<>(); |
| 152 | try { | 160 | try { |
| 153 | - // 这里应该从数据库查询最近的出库记录 | 161 | + List<DeliveryRes> recentDeliveries = deliveryMainService.getRecentDeliveries(2); |
| 154 | - // 暂时返回模拟数据 | 162 | + for (DeliveryRes delivery : recentDeliveries) { |
| 155 | - Map<String, Object> activity = new HashMap<>(); | 163 | + Map<String, Object> activity = new HashMap<>(); |
| 156 | - activity.put("id", 2); | 164 | + activity.put("id", delivery.getDeliveryId()); |
| 157 | - activity.put("type", "delivery"); | 165 | + activity.put("type", "delivery"); |
| 158 | - activity.put("title", "出库单 DEL-2025-001 已完成"); | 166 | + activity.put("title", "出库单 " + delivery.getDeliveryNo() + " 已创建"); |
| 159 | - activity.put("time", "15分钟前"); | 167 | + activity.put("time", formatTimeAgo(delivery.getCreateTime())); |
| 160 | - activities.add(activity); | 168 | + activities.add(activity); |
| 169 | + } | ||
| 161 | } catch (Exception e) { | 170 | } catch (Exception e) { |
| 162 | log.error("获取最近出库活动失败", e); | 171 | log.error("获取最近出库活动失败", e); |
| 163 | } | 172 | } |
| ... | @@ -170,14 +179,15 @@ public class DashboardServiceImpl implements DashboardService { | ... | @@ -170,14 +179,15 @@ public class DashboardServiceImpl implements DashboardService { |
| 170 | private List<Map<String, Object>> getRecentInvoices() { | 179 | private List<Map<String, Object>> getRecentInvoices() { |
| 171 | List<Map<String, Object>> activities = new ArrayList<>(); | 180 | List<Map<String, Object>> activities = new ArrayList<>(); |
| 172 | try { | 181 | try { |
| 173 | - // 这里应该从数据库查询最近的发票记录 | 182 | + List<InvoiceRes> recentInvoices = invoiceMainService.getRecentInvoices(2); |
| 174 | - // 暂时返回模拟数据 | 183 | + for (InvoiceRes invoice : recentInvoices) { |
| 175 | - Map<String, Object> activity = new HashMap<>(); | 184 | + Map<String, Object> activity = new HashMap<>(); |
| 176 | - activity.put("id", 3); | 185 | + activity.put("id", invoice.getInvoiceId()); |
| 177 | - activity.put("type", "invoice"); | 186 | + activity.put("type", "invoice"); |
| 178 | - activity.put("title", "发票 INV-2025-001 已开具"); | 187 | + activity.put("title", "发票 " + invoice.getInvoiceNo() + " 已开具"); |
| 179 | - activity.put("time", "1小时前"); | 188 | + activity.put("time", formatTimeAgo(invoice.getCreateTime())); |
| 180 | - activities.add(activity); | 189 | + activities.add(activity); |
| 190 | + } | ||
| 181 | } catch (Exception e) { | 191 | } catch (Exception e) { |
| 182 | log.error("获取最近发票活动失败", e); | 192 | log.error("获取最近发票活动失败", e); |
| 183 | } | 193 | } |
| ... | @@ -190,14 +200,15 @@ public class DashboardServiceImpl implements DashboardService { | ... | @@ -190,14 +200,15 @@ public class DashboardServiceImpl implements DashboardService { |
| 190 | private List<Map<String, Object>> getRecentRebates() { | 200 | private List<Map<String, Object>> getRecentRebates() { |
| 191 | List<Map<String, Object>> activities = new ArrayList<>(); | 201 | List<Map<String, Object>> activities = new ArrayList<>(); |
| 192 | try { | 202 | try { |
| 193 | - // 这里应该从数据库查询最近的返利记录 | 203 | + List<RebateRes> recentRebates = rebateService.getRecentRebates(2); |
| 194 | - // 暂时返回模拟数据 | 204 | + for (RebateRes rebate : recentRebates) { |
| 195 | - Map<String, Object> activity = new HashMap<>(); | 205 | + Map<String, Object> activity = new HashMap<>(); |
| 196 | - activity.put("id", 4); | 206 | + activity.put("id", rebate.getRebateId()); |
| 197 | - activity.put("type", "rebate"); | 207 | + activity.put("type", "rebate"); |
| 198 | - activity.put("title", "返利计算已完成,共处理 25 条记录"); | 208 | + activity.put("title", "返利 " + rebate.getRebateNo() + " 已计算"); |
| 199 | - activity.put("time", "2小时前"); | 209 | + activity.put("time", formatTimeAgo(rebate.getCreateTime())); |
| 200 | - activities.add(activity); | 210 | + activities.add(activity); |
| 211 | + } | ||
| 201 | } catch (Exception e) { | 212 | } catch (Exception e) { |
| 202 | log.error("获取最近返利活动失败", e); | 213 | log.error("获取最近返利活动失败", e); |
| 203 | } | 214 | } |
| ... | @@ -294,4 +305,28 @@ public class DashboardServiceImpl implements DashboardService { | ... | @@ -294,4 +305,28 @@ public class DashboardServiceImpl implements DashboardService { |
| 294 | return "0%"; | 305 | return "0%"; |
| 295 | } | 306 | } |
| 296 | } | 307 | } |
| 308 | + | ||
| 309 | + /** | ||
| 310 | + * 格式化时间为相对时间 | ||
| 311 | + */ | ||
| 312 | + private String formatTimeAgo(java.time.LocalDateTime dateTime) { | ||
| 313 | + if (dateTime == null) { | ||
| 314 | + return "未知时间"; | ||
| 315 | + } | ||
| 316 | + | ||
| 317 | + java.time.LocalDateTime now = java.time.LocalDateTime.now(); | ||
| 318 | + long minutes = java.time.Duration.between(dateTime, now).toMinutes(); | ||
| 319 | + | ||
| 320 | + if (minutes < 1) { | ||
| 321 | + return "刚刚"; | ||
| 322 | + } else if (minutes < 60) { | ||
| 323 | + return minutes + "分钟前"; | ||
| 324 | + } else if (minutes < 1440) { // 24小时 | ||
| 325 | + long hours = minutes / 60; | ||
| 326 | + return hours + "小时前"; | ||
| 327 | + } else { | ||
| 328 | + long days = minutes / 1440; | ||
| 329 | + return days + "天前"; | ||
| 330 | + } | ||
| 331 | + } | ||
| 297 | } | 332 | } | ... | ... |
| ... | @@ -20,6 +20,7 @@ import org.springframework.util.StringUtils; | ... | @@ -20,6 +20,7 @@ import org.springframework.util.StringUtils; |
| 20 | 20 | ||
| 21 | import java.time.LocalDateTime; | 21 | import java.time.LocalDateTime; |
| 22 | import java.time.format.DateTimeFormatter; | 22 | import java.time.format.DateTimeFormatter; |
| 23 | +import java.util.ArrayList; | ||
| 23 | import java.util.List; | 24 | import java.util.List; |
| 24 | import java.util.stream.Collectors; | 25 | import java.util.stream.Collectors; |
| 25 | 26 | ||
| ... | @@ -235,6 +236,26 @@ public class DeliveryMainServiceImpl extends ServiceImpl<DeliveryMainMapper, Del | ... | @@ -235,6 +236,26 @@ public class DeliveryMainServiceImpl extends ServiceImpl<DeliveryMainMapper, Del |
| 235 | .eq(DeliveryMain::getDeliveryStatus, 0); // 0表示待出库 | 236 | .eq(DeliveryMain::getDeliveryStatus, 0); // 0表示待出库 |
| 236 | return Math.toIntExact(count(wrapper)); | 237 | return Math.toIntExact(count(wrapper)); |
| 237 | } | 238 | } |
| 239 | + | ||
| 240 | + @Override | ||
| 241 | + public List<DeliveryRes> getRecentDeliveries(Integer limit) { | ||
| 242 | + try { | ||
| 243 | + LambdaQueryWrapper<DeliveryMain> wrapper = new LambdaQueryWrapper<>(); | ||
| 244 | + wrapper.eq(DeliveryMain::getDelFlag, "0") | ||
| 245 | + .orderByDesc(DeliveryMain::getCreateTime) | ||
| 246 | + .last("LIMIT " + (limit != null ? limit : 5)); | ||
| 247 | + | ||
| 248 | + List<DeliveryMain> deliveries = list(wrapper); | ||
| 249 | + return deliveries.stream().map(delivery -> { | ||
| 250 | + DeliveryRes deliveryRes = new DeliveryRes(); | ||
| 251 | + BeanUtils.copyProperties(delivery, deliveryRes); | ||
| 252 | + return deliveryRes; | ||
| 253 | + }).collect(Collectors.toList()); | ||
| 254 | + } catch (Exception e) { | ||
| 255 | + log.error("获取最近出库记录失败", e); | ||
| 256 | + return new ArrayList<>(); | ||
| 257 | + } | ||
| 258 | + } | ||
| 238 | } | 259 | } |
| 239 | 260 | ||
| 240 | 261 | ... | ... |
| ... | @@ -21,6 +21,7 @@ import org.springframework.util.StringUtils; | ... | @@ -21,6 +21,7 @@ import org.springframework.util.StringUtils; |
| 21 | import java.time.LocalDate; | 21 | import java.time.LocalDate; |
| 22 | import java.time.LocalDateTime; | 22 | import java.time.LocalDateTime; |
| 23 | import java.time.format.DateTimeFormatter; | 23 | import java.time.format.DateTimeFormatter; |
| 24 | +import java.util.ArrayList; | ||
| 24 | import java.util.List; | 25 | import java.util.List; |
| 25 | import java.util.stream.Collectors; | 26 | import java.util.stream.Collectors; |
| 26 | 27 | ||
| ... | @@ -236,5 +237,24 @@ public class InvoiceMainServiceImpl extends ServiceImpl<InvoiceMainMapper, Invoi | ... | @@ -236,5 +237,24 @@ public class InvoiceMainServiceImpl extends ServiceImpl<InvoiceMainMapper, Invoi |
| 236 | .eq(InvoiceMain::getInvoiceStatus, 0); // 0表示待开票 | 237 | .eq(InvoiceMain::getInvoiceStatus, 0); // 0表示待开票 |
| 237 | return Math.toIntExact(count(wrapper)); | 238 | return Math.toIntExact(count(wrapper)); |
| 238 | } | 239 | } |
| 239 | - | 240 | + |
| 241 | + @Override | ||
| 242 | + public List<InvoiceRes> getRecentInvoices(Integer limit) { | ||
| 243 | + try { | ||
| 244 | + LambdaQueryWrapper<InvoiceMain> wrapper = new LambdaQueryWrapper<>(); | ||
| 245 | + wrapper.eq(InvoiceMain::getDelFlag, "0") | ||
| 246 | + .orderByDesc(InvoiceMain::getCreateTime) | ||
| 247 | + .last("LIMIT " + (limit != null ? limit : 5)); | ||
| 248 | + | ||
| 249 | + List<InvoiceMain> invoices = list(wrapper); | ||
| 250 | + return invoices.stream().map(invoice -> { | ||
| 251 | + InvoiceRes invoiceRes = new InvoiceRes(); | ||
| 252 | + BeanUtils.copyProperties(invoice, invoiceRes); | ||
| 253 | + return invoiceRes; | ||
| 254 | + }).collect(Collectors.toList()); | ||
| 255 | + } catch (Exception e) { | ||
| 256 | + log.error("获取最近发票记录失败", e); | ||
| 257 | + return new ArrayList<>(); | ||
| 258 | + } | ||
| 259 | + } | ||
| 240 | } | 260 | } | ... | ... |
| ... | @@ -16,6 +16,7 @@ import org.springframework.transaction.annotation.Transactional; | ... | @@ -16,6 +16,7 @@ import org.springframework.transaction.annotation.Transactional; |
| 16 | import org.springframework.util.StringUtils; | 16 | import org.springframework.util.StringUtils; |
| 17 | 17 | ||
| 18 | import java.time.LocalDateTime; | 18 | import java.time.LocalDateTime; |
| 19 | +import java.util.ArrayList; | ||
| 19 | import java.util.List; | 20 | import java.util.List; |
| 20 | import java.util.stream.Collectors; | 21 | import java.util.stream.Collectors; |
| 21 | 22 | ||
| ... | @@ -322,5 +323,25 @@ public class OrderMainServiceImpl extends ServiceImpl<OrderMainMapper, OrderMain | ... | @@ -322,5 +323,25 @@ public class OrderMainServiceImpl extends ServiceImpl<OrderMainMapper, OrderMain |
| 322 | return 0.0; | 323 | return 0.0; |
| 323 | } | 324 | } |
| 324 | } | 325 | } |
| 326 | + | ||
| 327 | + @Override | ||
| 328 | + public List<OrderRes> getRecentOrders(Integer limit) { | ||
| 329 | + try { | ||
| 330 | + LambdaQueryWrapper<OrderMain> wrapper = new LambdaQueryWrapper<>(); | ||
| 331 | + wrapper.eq(OrderMain::getDelFlag, "0") | ||
| 332 | + .orderByDesc(OrderMain::getCreateTime) | ||
| 333 | + .last("LIMIT " + (limit != null ? limit : 5)); | ||
| 334 | + | ||
| 335 | + List<OrderMain> orders = list(wrapper); | ||
| 336 | + return orders.stream().map(order -> { | ||
| 337 | + OrderRes orderRes = new OrderRes(); | ||
| 338 | + BeanUtils.copyProperties(order, orderRes); | ||
| 339 | + return orderRes; | ||
| 340 | + }).collect(Collectors.toList()); | ||
| 341 | + } catch (Exception e) { | ||
| 342 | + log.error("获取最近订单失败", e); | ||
| 343 | + return new ArrayList<>(); | ||
| 344 | + } | ||
| 345 | + } | ||
| 325 | } | 346 | } |
| 326 | 347 | ... | ... |
| ... | @@ -275,4 +275,24 @@ public class RebateServiceImpl extends ServiceImpl<RebateMapper, Rebate> impleme | ... | @@ -275,4 +275,24 @@ public class RebateServiceImpl extends ServiceImpl<RebateMapper, Rebate> impleme |
| 275 | log.info("获取返利趋势统计数据,开始日期:{},结束日期:{}", startDate, endDate); | 275 | log.info("获取返利趋势统计数据,开始日期:{},结束日期:{}", startDate, endDate); |
| 276 | return rebateMapper.getRebateTrendStats(startDate, endDate); | 276 | return rebateMapper.getRebateTrendStats(startDate, endDate); |
| 277 | } | 277 | } |
| 278 | + | ||
| 279 | + @Override | ||
| 280 | + public List<RebateRes> getRecentRebates(Integer limit) { | ||
| 281 | + try { | ||
| 282 | + LambdaQueryWrapper<Rebate> wrapper = new LambdaQueryWrapper<>(); | ||
| 283 | + wrapper.eq(Rebate::getDelFlag, "0") | ||
| 284 | + .orderByDesc(Rebate::getCreateTime) | ||
| 285 | + .last("LIMIT " + (limit != null ? limit : 5)); | ||
| 286 | + | ||
| 287 | + List<Rebate> rebates = list(wrapper); | ||
| 288 | + return rebates.stream().map(rebate -> { | ||
| 289 | + RebateRes rebateRes = new RebateRes(); | ||
| 290 | + BeanUtils.copyProperties(rebate, rebateRes); | ||
| 291 | + return rebateRes; | ||
| 292 | + }).collect(Collectors.toList()); | ||
| 293 | + } catch (Exception e) { | ||
| 294 | + log.error("获取最近返利记录失败", e); | ||
| 295 | + return new ArrayList<>(); | ||
| 296 | + } | ||
| 297 | + } | ||
| 278 | } | 298 | } | ... | ... |
-
Please register or login to post a comment