From d4268ddf78ae57371e6c3d5fc51a63ac27b63435 Mon Sep 17 00:00:00 2001 From: Wang YiHang <3060234389@qq.com> Date: Sun, 8 Sep 2024 11:19:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=81=E4=B8=9A=E5=88=97=E8=A1=A8=E5=87=BA?= =?UTF-8?q?=E6=9D=A5=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../market/controller/MyApiController.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/cloud-market-server/src/main/java/com/muyu/market/controller/MyApiController.java b/cloud-market-server/src/main/java/com/muyu/market/controller/MyApiController.java index 0f8d203..0b13c28 100644 --- a/cloud-market-server/src/main/java/com/muyu/market/controller/MyApiController.java +++ b/cloud-market-server/src/main/java/com/muyu/market/controller/MyApiController.java @@ -1,6 +1,11 @@ package com.muyu.market.controller; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; import java.util.Arrays; +import java.util.Date; import java.util.List; import jakarta.servlet.http.HttpServletResponse; import javax.annotation.Resource; @@ -127,11 +132,27 @@ public class MyApiController extends BaseController { Long userId = SecurityUtils.getUserId(); myApi.setUserId(userId); - if (myApiService.checkIdUnique(myApi)) { - MyApi myApi1 = myApiService.selectMyApiByMyId(myApi.getMyId()); + MyApi myApi1 = myApiService.selectMyApiByMyId(myApi.getMyId()); + if (myApi1!=null) { myApi.setMyNum(myApi1.getMyNum()+myApi.getMyNum()); return toAjax(myApiService.updateById(myApi)); } + // 获取当前时间(没有时区) + LocalDateTime now = LocalDateTime.now(); + + // 假设我们使用系统默认时区 + ZoneId zoneId = ZoneId.systemDefault(); + + // 将LocalDateTime转换为ZonedDateTime(添加了时区信息) + ZonedDateTime zdt = now.atZone(zoneId); + + // 将ZonedDateTime转换为Instant(UTC时间线上的点) + Instant instant = zdt.toInstant(); + + // 将Instant转换为Date + Date date = Date.from(instant); + myApi.setMyTime(date); + myApi.setMyStates("Y"); return toAjax(myApiService.save(myApi)); } }