修改分页

master
xiaoCJ 6 months ago
parent da52a08d23
commit 512b13c431

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

Loading…
Cancel
Save