From 512b13c431d58f3ff81f77dc1e84c57569658745 Mon Sep 17 00:00:00 2001
From: xiaoCJ <406612557@qq.com>
Date: Sat, 21 Sep 2024 14:48:56 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=86=E9=A1=B5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../competitiion/pc/biz/PCCompetitionBiz.java | 110 +++++++++---------
 1 file changed, 55 insertions(+), 55 deletions(-)

diff --git a/tz/competition/competition-service/src/main/java/com/tz/platform/competitiion/pc/biz/PCCompetitionBiz.java b/tz/competition/competition-service/src/main/java/com/tz/platform/competitiion/pc/biz/PCCompetitionBiz.java
index 8bd3893..b30dc12 100644
--- a/tz/competition/competition-service/src/main/java/com/tz/platform/competitiion/pc/biz/PCCompetitionBiz.java
+++ b/tz/competition/competition-service/src/main/java/com/tz/platform/competitiion/pc/biz/PCCompetitionBiz.java
@@ -28,29 +28,29 @@ import java.util.concurrent.TimeUnit;
 public class PCCompetitionBiz {
 
     @Autowired
-    private CompetitionDao competitionDao ;
+    private CompetitionDao competitionDao;
 
     @Autowired
     private IFeignUser feignUser;
 
     @Autowired
-    private RedisTemplate<String,Object> template;
+    private RedisTemplate<String, Object> template;
 
-    public Result<Long> add(CompetitionVO vo){
-        if(StringUtils.isEmpty(vo.getName())){
+    public Result<Long> add(CompetitionVO vo) {
+        if (StringUtils.isEmpty(vo.getName())) {
             return Result.error("大赛名称不能为空");
         }
-        if(vo.getType() == null||vo.getType()<=0){
+        if (vo.getType() == null || vo.getType() <= 0) {
             return Result.error("大赛类型不能为空");
         }
         Competition competition = null;
-        if(vo.getId() == null){
+        if (vo.getId() == null) {
             competition = new Competition();
-            BeanUtils.copyProperties(vo,competition);
+            BeanUtils.copyProperties(vo, competition);
             competition.setStatus(-1);
-            UserVo userVo =  feignUser.getByUserNo(competition.getUserNo());
+            UserVo userVo = feignUser.getByUserNo(competition.getUserNo());
             competition.setSchoolId(userVo.getSchoolId());
-        }else{
+        } else {
             competition = competitionDao.getById(vo.getId());
             competition.setName(vo.getName());
             competition.setSponsor(vo.getSponsor());
@@ -71,27 +71,27 @@ public class PCCompetitionBiz {
         }
 
 
-        Date startTime=competition.getStageList().get(0).getStartTime();
-        Date endTime =competition.getStageList().get(competition.getStageList().size()-1).getEndTime();
+        Date startTime = competition.getStageList().get(0).getStartTime();
+        Date endTime = competition.getStageList().get(competition.getStageList().size() - 1).getEndTime();
         Stage signupStage = competition.getStageList().stream().filter(stage -> stage.isEnableSignUp()).findFirst().orElse(null);
         Date signUpStartTime = null;
         Date signupEndTime = null;
 
-        if(endTime.getTime()<=startTime.getTime()){
+        if (endTime.getTime() <= startTime.getTime()) {
             return Result.error("结束时间必须大于开始时间");
         }
 
-        if(signupStage !=null){
+        if (signupStage != null) {
             signUpStartTime = signupStage.getSignUpStartTime();
             signupEndTime = signupStage.getSingUpEndTime();
-            if(signupEndTime.getTime()<=signUpStartTime.getTime()){
-                return  Result.error("报名截止时间必须大于报名开始时间");
+            if (signupEndTime.getTime() <= signUpStartTime.getTime()) {
+                return Result.error("报名截止时间必须大于报名开始时间");
             }
-            if(signupEndTime.getTime()>startTime.getTime()){
+            if (signupEndTime.getTime() > startTime.getTime()) {
                 return Result.error("报名截止时间必须早于大赛开始时间");
             }
             competition.setEnableSignup(true);
-        }else{
+        } else {
             competition.setEnableSignup(false);
         }
 
@@ -101,83 +101,83 @@ public class PCCompetitionBiz {
         competition.setSignupEndTime(signupEndTime);
 
 
-        if(competition.getId() == null){
+        if (competition.getId() == null) {
             competition.setCreateTime(new Date());
         }
         competition.getNews().forEach(competitionNews -> {
-            if(competitionNews.getCreateTime() == null){
+            if (competitionNews.getCreateTime() == null) {
                 competitionNews.setCreateTime(System.currentTimeMillis());
             }
         });
 
         competition.getSchoolNews().forEach(competitionNews -> {
-            if(competitionNews.getCreateTime() == null){
+            if (competitionNews.getCreateTime() == null) {
                 competitionNews.setCreateTime(System.currentTimeMillis());
             }
-        } );
+        });
 
-        competition =competitionDao.save(competition);
+        competition = competitionDao.save(competition);
 
-        String compKey = "competition_"+competition.getId();
-        template.opsForValue().set(compKey,competition,5, TimeUnit.MINUTES);
+        String compKey = "competition_" + competition.getId();
+        template.opsForValue().set(compKey, competition, 5, TimeUnit.MINUTES);
 
         return Result.success(competition.getId());
     }
 
-    public Result<String> update(CompetitionVO vo){
-        if(StringUtils.isEmpty(vo.getName())){
+    public Result<String> update(CompetitionVO vo) {
+        if (StringUtils.isEmpty(vo.getName())) {
             return Result.error("大赛名称不能为空");
         }
         Competition competition = new Competition();
-        BeanUtils.copyProperties(vo,competition);
+        BeanUtils.copyProperties(vo, competition);
         competition = competitionDao.save(competition);
-        String compKey = "competition_"+competition.getId();
-        template.opsForValue().set(compKey,competition,5, TimeUnit.MINUTES);
+        String compKey = "competition_" + competition.getId();
+        template.opsForValue().set(compKey, competition, 5, TimeUnit.MINUTES);
         return Result.success("编辑成功");
     }
 
-    public Result<String> delete(CompetitionVO vo){
+    public Result<String> delete(CompetitionVO vo) {
         competitionDao.deleteById(vo.getId());
         return Result.success("success");
     }
 
-    public Result<PageCompetitionDTO> list(PageCompetitionVO vo){
-        Sort sort = Sort.by(Sort.Direction.DESC,"id");
-        Pageable pageable = PageRequest.of(vo.getPageNo(),vo.getPageSize(),sort);
+    public Result<PageCompetitionDTO> list(PageCompetitionVO vo) {
+        Sort sort = Sort.by(Sort.Direction.DESC, "id");
+        Pageable pageable = PageRequest.of(vo.getPageNo() - 1, vo.getPageSize(), sort);
         UserVo userVo = feignUser.getByUserNo(vo.getUserNo());
         PageCompetitionDTO dto = new PageCompetitionDTO();
-        if(userVo.getUserType()< UserTypeEnum.ADMIN.getCode()){
-            Page<Competition>  competitionPage = competitionDao.findAllBySchoolId(userVo.getSchoolId(),pageable);
+        if (userVo.getUserType() < UserTypeEnum.ADMIN.getCode()) {
+            Page<Competition> competitionPage = competitionDao.findAllBySchoolId(userVo.getSchoolId(), pageable);
             dto.setPage(competitionPage);
-        }else{
-            Page<Competition>  competitionPage = competitionDao.findAll(pageable);
+        } else {
+            Page<Competition> competitionPage = competitionDao.findAll(pageable);
             dto.setPage(competitionPage);
         }
-        return  Result.success(dto);
+        return Result.success(dto);
     }
 
-    public Result<CompetitionDTO> get(CompetitionVO vo){
+    public Result<CompetitionDTO> get(CompetitionVO vo) {
         Competition competition = competitionDao.getById(vo.getId());
         CompetitionDTO dto = new CompetitionDTO();
-        BeanUtils.copyProperties(competition,dto);
+        BeanUtils.copyProperties(competition, dto);
         return Result.success(dto);
     }
 
 
-    public Result<String> send(CompetitionVO vo){
-       Competition competition =  competitionDao.getById(vo.getId());
-       if(competition == null){
-           return Result.error("大赛不存在");
-       }
-       if(competition.getStatus() == -1){
-           int rs =   competitionDao.updateStatus(vo.getId(),0);
-           if(rs>0){
-               return Result.success("发布成功");
-           }
-       }else{
-           return Result.error("大赛已发布");
-       }
-
-       return Result.error("操作失败");
+    public Result<String> send(CompetitionVO vo) {
+        Competition competition = competitionDao.getById(vo.getId());
+        if (competition == null) {
+            return Result.error("大赛不存在");
+        }
+        if (competition.getStatus() == -1) {
+            int rs = competitionDao.updateStatus(vo.getId(), 0);
+            if (rs > 0) {
+                return Result.success("发布成功");
+            }
+        } else {
+            return Result.error("大赛已发布");
+        }
+
+        return Result.error("操作失败");
     }
 }