diff --git a/src/main/java/com/bigdata/wxappserver/service/OrderService.java b/src/main/java/com/bigdata/wxappserver/service/OrderService.java index d96b7a3..a0e01e6 100644 --- a/src/main/java/com/bigdata/wxappserver/service/OrderService.java +++ b/src/main/java/com/bigdata/wxappserver/service/OrderService.java @@ -42,6 +42,9 @@ public class OrderService extends ServiceImpl { if (order == null) { return Result.error("参数错误"); } + List userList = userService.list(); + User userTemp = userList.stream().filter(e -> Objects.equals(e.getOpenId(), jsonObject.get("openId"))).findFirst().orElse(null); + order.setUserId(userTemp.getId()); if (!StringUtils.hasLength(order.getAddress())) { User user = userService.getById(order.getUserId()); order.setAddress(user.getAddress()); diff --git a/src/main/java/com/bigdata/wxappserver/service/UserService.java b/src/main/java/com/bigdata/wxappserver/service/UserService.java index 0921ce9..23aa867 100644 --- a/src/main/java/com/bigdata/wxappserver/service/UserService.java +++ b/src/main/java/com/bigdata/wxappserver/service/UserService.java @@ -26,7 +26,8 @@ import java.util.stream.Collectors; @Service public class UserService extends ServiceImpl { - private static final String UPLOAD_DIR = "uploads/"; + private static final String UPLOAD_DIR = "static/uploads/"; + private static final String GET_URL = "uploads/"; @Transactional(rollbackFor = Exception.class) public JSONObject addOrUpdate(JSONObject jsonObject) { @@ -88,6 +89,9 @@ public class UserService extends ServiceImpl { List userList = list(); User user = userList.stream().filter(e -> Objects.equals(e.getOpenId(), openId)).findFirst().orElse(null); + if (user == null) { + return new JSONObject().fluentPut("success", false).fluentPut("message", "用户不存在"); + } return new JSONObject().fluentPut("data", user); } @@ -105,10 +109,11 @@ public class UserService extends ServiceImpl { // 保存文件到服务器 String fileName = System.currentTimeMillis() + "_" + file.getOriginalFilename(); Path path = Paths.get(UPLOAD_DIR + fileName); + Files.createDirectories(path.getParent()); Files.write(path, file.getBytes()); // 构建文件的访问URL String fileDownloadUri = ServletUriComponentsBuilder.fromCurrentContextPath() - .path("/" + UPLOAD_DIR) + .path("/" + GET_URL) .path(fileName) .toUriString(); return new JSONObject().fluentPut("success", true).fluentPut("fileDownloadUri", fileDownloadUri);