小如重构
This commit is contained in:
1 parent
685f35f1d5
commit
984b2007a8
5 files changed
+88
-28
No files matched your search
+12
-20
@@ -178,32 +178,24 @@ public class ChannelController {
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 组装返回结果:以货道为主,补充对应的商品名称、容量和库存
|
||||
List<ChannelGoodsRespVO> result = new ArrayList<>(channelList.size());
|
||||
// 4. 组装返回结果:仅包含有绑定商品的货道,补充对应的商品名称、容量和库存
|
||||
List<ChannelGoodsRespVO> 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);
|
||||
}
|
||||
|
||||
+59
-5
@@ -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<DeviceLogRespVO> 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<PageResult<DeviceLogRespVO>> getDeviceLogPage(@Valid DeviceLogPageReqVO pageReqVO) {
|
||||
PageResult<DeviceLogDO> pageResult = deviceLogService.getDeviceLogPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, DeviceLogRespVO.class));
|
||||
List<DeviceLogRespVO> 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<DeviceLogDO> list = deviceLogService.getDeviceLogPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "贩卖机出货日志.xls", "数据", DeviceLogRespVO.class,
|
||||
BeanUtils.toBean(list, DeviceLogRespVO.class));
|
||||
List<DeviceLogRespVO> voList = BeanUtils.toBean(list, DeviceLogRespVO.class);
|
||||
fillUserAndDeviceName(voList);
|
||||
ExcelUtils.write(response, "贩卖机出货日志.xls", "数据", DeviceLogRespVO.class, voList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量填充用户名称和设备名称(用户编号、设备编码译文)
|
||||
*/
|
||||
private void fillUserAndDeviceName(List<DeviceLogRespVO> list) {
|
||||
if (list == null || list.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Set<Long> userIds = list.stream()
|
||||
.map(DeviceLogRespVO::getUserId)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
Set<String> deviceIds = list.stream()
|
||||
.map(DeviceLogRespVO::getDeviceId)
|
||||
.filter(id -> id != null && !id.isEmpty())
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
Map<Long, MemberUserRespDTO> userMap = CollectionUtils.convertMap(
|
||||
userIds.isEmpty() ? Collections.emptyList() : memberUserApi.getUserList(userIds),
|
||||
MemberUserRespDTO::getId);
|
||||
Map<String, DeviceRespDto> 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()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+14
-2
@@ -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;
|
||||
|
||||
+2
@@ -21,6 +21,8 @@ public enum DispenseResultStatusEnum {
|
||||
ORDER_NO_DUPLICATE(5, "销售订单号重复"),
|
||||
CHANNEL_ERROR(6, "通道号错误"),
|
||||
CHANNEL_TYPE_ERROR(7, "通道类型错误"),
|
||||
/** 系统/业务异常(如网络异常、参数错误等) */
|
||||
EXCEPTION(500, "出货异常"),
|
||||
;
|
||||
|
||||
private final int value;
|
||||
|
||||
@@ -132,7 +132,7 @@
|
||||
|
||||
<build>
|
||||
<!-- 设置构建的 jar 包名 -->
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<finalName>xiaoru.jar</finalName>
|
||||
<plugins>
|
||||
<!-- 打包 -->
|
||||
<plugin>
|
||||
|
||||
Reference in new issue
Block a user