修改分页

master
xiaoCJ 6 months ago
parent da52a08d23
commit 512b13c431

@ -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("操作失败");
}
}

Loading…
Cancel
Save