zhangxin hace 3 semanas
padre
commit
97c7be265a

+ 8 - 3
prod-line-imes/src/main/java/com/huaxia/imes/service/MesLineService.java

@@ -73,8 +73,10 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
         if (boy.getCreateTime() == null) {
             boy.setCreateTime(new Date());
         } else {
-            //如果创建时间不为空,则判断时间是否在今天之后 如果是则提醒 创建时间只能小于等于今天
-            Assert.isTrue(boy.getCreateTime().after(new Date()), "500-创建时间不能大于今天");
+            // 转换为 Instant 进行比较,避免时区问题
+            Instant createInstant = boy.getCreateTime().toInstant();
+            Instant nowInstant = Instant.now();
+            Assert.isTrue(!createInstant.isAfter(nowInstant), "500-创建时间不能大于当前时间");
         }
         //通过产线名称和创建如期去查询产线数据是否存在
         LambdaQueryWrapper<MesLine> wr = new LambdaQueryWrapper<>();
@@ -99,7 +101,10 @@ public class MesLineService extends ServiceImpl<MesLineMapper, MesLine> implemen
         this.check(boy);
         //判断一下时间
         Assert.isTrue(boy.getCreateTime() != null, "500-时间不能为空");
-        Assert.isTrue(boy.getCreateTime().after(new Date()), "500-创建时间不能大于今天");
+        // 转换为 Instant 进行比较,避免时区问题
+        Instant createInstant = boy.getCreateTime().toInstant();
+        Instant nowInstant = Instant.now();
+        Assert.isTrue(!createInstant.isAfter(nowInstant), "500-创建时间不能大于当前时间");
         boy.setUpdateTime(new Date())
                 .setUpdateBy(SecurityUtils.getUsername());
         this.updateById(boy);