Browse Source

修复赛事bug

zhangxin 3 days ago
parent
commit
df98ae43cb

+ 26 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/service/impl/AppGameServiceImpl.java

@@ -24,7 +24,10 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.time.LocalDate;
+import java.time.ZoneId;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
 import static org.jeecg.common.constant.CommonConstant.SC_INTERNAL_SERVER_ERROR_500;
@@ -54,12 +57,15 @@ public class AppGameServiceImpl extends ServiceImpl<AppGameMapper, AppGame> impl
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Boolean saveWitchPriceRules(AppGameDTO gameDTO) {
+
         AppGameCuDTO gameCuDTO = gameDTO.getGame();
         AppGame game = new AppGame();
         BeanUtils.copyProperties(gameCuDTO, game);
         LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
         game.setOrgCode(sysUser.getOrgCode());
         game.setTenantId(sysUser.getOrgId());
+
+        checkTime(gameCuDTO.getApplicationEndTime(),gameCuDTO.getStartTime(),gameCuDTO.getEndTime());
         int saveGameResult = baseMapper.insert(game);
         if (saveGameResult < 1) {
             throw new JeecgBootException("赛事信息保存失败");
@@ -102,6 +108,7 @@ public class AppGameServiceImpl extends ServiceImpl<AppGameMapper, AppGame> impl
 //        checkPermission(sysUser,dbGame);
         game.setOrgCode(sysUser.getOrgCode());
         game.setTenantId(sysUser.getOrgId());
+        checkTime(gameCuDTO.getApplicationEndTime(),gameCuDTO.getStartTime(),gameCuDTO.getEndTime());
         int updateGameResult = baseMapper.updateById(game);
         if (updateGameResult < 1) {
             throw new JeecgBootException("赛事信息保存失败");
@@ -243,4 +250,23 @@ public class AppGameServiceImpl extends ServiceImpl<AppGameMapper, AppGame> impl
         if (!sysUser.getOrgCode().equals(game.getOrgCode()))
             throw new JeecgBootException("无权限操作", SC_INTERNAL_SERVER_ERROR_500);
     }
+
+    private void checkTime(Date applicationEndTime,Date startTime,Date endTime){
+        if (applicationEndTime==null){
+            throw new JeecgBootException("赛事信息保存失败,报名截止时间不能为空");
+        }
+        if (startTime==null||endTime==null){
+            throw new JeecgBootException("赛事信息保存失败,比赛时间不能为空");
+        }
+        LocalDate localDate = applicationEndTime.toInstant()
+                .atZone(ZoneId.systemDefault()) // 使用系统默认时区
+                .toLocalDate();
+        LocalDate localDateStart = startTime.toInstant()
+                .atZone(ZoneId.systemDefault()) // 使用系统默认时区
+                .toLocalDate();
+        boolean before = localDate.isBefore(localDateStart);
+        if (!before) {
+            throw new JeecgBootException("赛事信息保存失败,报名截止时间必须在比赛时间之前");
+        }
+    }
 }