From 984b2007a834a71a9066add636f2ad5fa3718a77 Mon Sep 17 00:00:00 2001 From: zjf <1799650030@qq.com> Date: Fri, 13 Feb 2026 18:00:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E5=A6=82=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/channel/ChannelController.java | 32 ++++------ .../admin/devicelog/DeviceLogController.java | 64 +++++++++++++++++-- .../admin/devicelog/vo/DeviceLogRespVO.java | 16 ++++- .../order/bo/DispenseResultStatusEnum.java | 2 + yudao-server/pom.xml | 2 +- 5 files changed, 88 insertions(+), 28 deletions(-) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/channel/ChannelController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/channel/ChannelController.java index 102e1d7..07ecf38 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/channel/ChannelController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/channel/ChannelController.java @@ -178,32 +178,24 @@ public class ChannelController { } } - // 4. 组装返回结果:以货道为主,补充对应的商品名称、容量和库存 - List result = new ArrayList<>(channelList.size()); + // 4. 组装返回结果:仅包含有绑定商品的货道,补充对应的商品名称、容量和库存 + List result = new ArrayList<>(); for (ChannelDO channel : channelList) { + ProductSkuDO sku = skuByChannel.get(channel.getCabinetChannel()); + if (sku == null) { + // 该货道没有绑定商品,不返回此条数据 + continue; + } + ChannelGoodsRespVO vo = new ChannelGoodsRespVO(); vo.setId(channel.getId()); - // 这里返回设备 IMEI,便于前端直接使用 vo.setDeviceId(channel.getDeviceImei()); vo.setCabinetChannel(channel.getCabinetChannel()); vo.setMaxNum(channel.getMaxNum()); - - ProductSkuDO sku = skuByChannel.get(channel.getCabinetChannel()); - if (sku != null) { - vo.setSkuId(sku.getId()); - ProductSpuDO spu = spuMap.get(sku.getSpuId()); - if (spu != null) { - vo.setSpuName(spu.getName()); - } - vo.setSpuStock(sku.getStock()); - } else { - // 没有关联商品时,名称和库存留空/0 - vo.setSkuId(null); - vo.setSpuName(null); - vo.setSpuStock(0); - } - - // 预留的货道状态字段,目前默认置为 1(启用) + vo.setSkuId(sku.getId()); + ProductSpuDO spu = spuMap.get(sku.getSpuId()); + vo.setSpuName(spu != null ? spu.getName() : null); + vo.setSpuStock(sku.getStock()); vo.setStatus(1); result.add(vo); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/devicelog/DeviceLogController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/devicelog/DeviceLogController.java index 56f89fa..18d8d44 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/devicelog/DeviceLogController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/devicelog/DeviceLogController.java @@ -13,11 +13,13 @@ import javax.validation.*; import javax.servlet.http.*; import java.util.*; import java.io.IOException; +import java.util.stream.Collectors; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; @@ -28,6 +30,11 @@ import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*; import cn.iocoder.yudao.module.trade.controller.admin.devicelog.vo.*; import cn.iocoder.yudao.module.trade.dal.dataobject.devicelog.DeviceLogDO; import cn.iocoder.yudao.module.trade.service.devicelog.DeviceLogService; +import cn.iocoder.yudao.module.member.api.user.MemberUserApi; +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; +import cn.iocoder.yudao.module.product.api.device.DeviceApi; +import cn.iocoder.yudao.module.product.api.device.dto.DeviceRespDto; +import cn.iocoder.yudao.module.trade.service.order.bo.DispenseResultStatusEnum; @Tag(name = "管理后台 - 贩卖机出货日志") @RestController @@ -38,6 +45,12 @@ public class DeviceLogController { @Resource private DeviceLogService deviceLogService; + @Resource + private MemberUserApi memberUserApi; + + @Resource + private DeviceApi deviceApi; + @PostMapping("/create") @Operation(summary = "创建贩卖机出货日志") @PreAuthorize("@ss.hasPermission('trade:device-log:create')") @@ -68,7 +81,9 @@ public class DeviceLogController { @PreAuthorize("@ss.hasPermission('trade:device-log:query')") public CommonResult getDeviceLog(@RequestParam("id") Long id) { DeviceLogDO deviceLog = deviceLogService.getDeviceLog(id); - return success(BeanUtils.toBean(deviceLog, DeviceLogRespVO.class)); + DeviceLogRespVO vo = BeanUtils.toBean(deviceLog, DeviceLogRespVO.class); + fillUserAndDeviceName(Collections.singletonList(vo)); + return success(vo); } @GetMapping("/page") @@ -76,7 +91,9 @@ public class DeviceLogController { @PreAuthorize("@ss.hasPermission('trade:device-log:query')") public CommonResult> getDeviceLogPage(@Valid DeviceLogPageReqVO pageReqVO) { PageResult pageResult = deviceLogService.getDeviceLogPage(pageReqVO); - return success(BeanUtils.toBean(pageResult, DeviceLogRespVO.class)); + List list = BeanUtils.toBean(pageResult.getList(), DeviceLogRespVO.class); + fillUserAndDeviceName(list); + return success(new PageResult<>(list, pageResult.getTotal())); } @GetMapping("/export-excel") @@ -87,9 +104,46 @@ public class DeviceLogController { HttpServletResponse response) throws IOException { pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); List list = deviceLogService.getDeviceLogPage(pageReqVO).getList(); - // 导出 Excel - ExcelUtils.write(response, "贩卖机出货日志.xls", "数据", DeviceLogRespVO.class, - BeanUtils.toBean(list, DeviceLogRespVO.class)); + List voList = BeanUtils.toBean(list, DeviceLogRespVO.class); + fillUserAndDeviceName(voList); + ExcelUtils.write(response, "贩卖机出货日志.xls", "数据", DeviceLogRespVO.class, voList); + } + + /** + * 批量填充用户名称和设备名称(用户编号、设备编码译文) + */ + private void fillUserAndDeviceName(List list) { + if (list == null || list.isEmpty()) { + return; + } + Set userIds = list.stream() + .map(DeviceLogRespVO::getUserId) + .filter(Objects::nonNull) + .collect(Collectors.toSet()); + Set deviceIds = list.stream() + .map(DeviceLogRespVO::getDeviceId) + .filter(id -> id != null && !id.isEmpty()) + .collect(Collectors.toSet()); + + Map userMap = CollectionUtils.convertMap( + userIds.isEmpty() ? Collections.emptyList() : memberUserApi.getUserList(userIds), + MemberUserRespDTO::getId); + Map deviceMap = CollectionUtils.convertMap( + deviceIds.isEmpty() ? Collections.emptyList() : deviceApi.getDeviceByDeviceIds(new ArrayList<>(deviceIds)), + DeviceRespDto::getDeviceId); + + for (DeviceLogRespVO vo : list) { + if (vo.getUserId() != null) { + MemberUserRespDTO user = userMap.get(vo.getUserId()); + vo.setUserName(user != null ? user.getNickname() : null); + } + if (vo.getDeviceId() != null && !vo.getDeviceId().isEmpty()) { + DeviceRespDto device = deviceMap.get(vo.getDeviceId()); + vo.setDeviceName(device != null ? device.getName() : null); + } + // 出货状态译文 + vo.setDeviceStatusName(DispenseResultStatusEnum.getDescByValue(vo.getDeviceStatus())); + } } } \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/devicelog/vo/DeviceLogRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/devicelog/vo/DeviceLogRespVO.java index ea9b673..669a9e0 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/devicelog/vo/DeviceLogRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/devicelog/vo/DeviceLogRespVO.java @@ -20,6 +20,10 @@ public class DeviceLogRespVO { @ExcelProperty("用户编号") private Long userId; + @Schema(description = "用户名称(昵称)", example = "张三") + @ExcelProperty("用户名称") + private String userName; + @Schema(description = "订单号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1703") @ExcelProperty("订单号") private Long orderId; @@ -28,14 +32,22 @@ public class DeviceLogRespVO { @ExcelProperty("订单流水号") private String orderNo; - @Schema(description = "设备IMEI", example = "23208") + @Schema(description = "设备IMEI", example = "869667070283722") @ExcelProperty("设备IMEI") private String deviceId; - @Schema(description = "出货状态", example = "1") + @Schema(description = "设备名称", example = "1号楼售货机") + @ExcelProperty("设备名称") + private String deviceName; + + @Schema(description = "出货状态", example = "0") @ExcelProperty("出货状态") private Integer deviceStatus; + @Schema(description = "出货状态说明", example = "出货成功/开门成功") + @ExcelProperty("出货状态说明") + private String deviceStatusName; + @Schema(description = "内容", requiredMode = Schema.RequiredMode.REQUIRED) @ExcelProperty("内容") private String content; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/bo/DispenseResultStatusEnum.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/bo/DispenseResultStatusEnum.java index 54afe20..5e18766 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/bo/DispenseResultStatusEnum.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/bo/DispenseResultStatusEnum.java @@ -21,6 +21,8 @@ public enum DispenseResultStatusEnum { ORDER_NO_DUPLICATE(5, "销售订单号重复"), CHANNEL_ERROR(6, "通道号错误"), CHANNEL_TYPE_ERROR(7, "通道类型错误"), + /** 系统/业务异常(如网络异常、参数错误等) */ + EXCEPTION(500, "出货异常"), ; private final int value; diff --git a/yudao-server/pom.xml b/yudao-server/pom.xml index 23a8c81..2854aa7 100644 --- a/yudao-server/pom.xml +++ b/yudao-server/pom.xml @@ -132,7 +132,7 @@ - ${project.artifactId} + xiaoru.jar