Commit 6e68d241 authored by liming's avatar liming

增加比赛创建删除接口

parent ae274dbc
......@@ -2,7 +2,9 @@ package com.antai.sport.http.server.game.api.business.match.bicycle;
import com.antai.sport.http.server.game.api.business.match.bicycle.dto.DtoMatchBicycleResult;
import com.antai.sport.http.server.game.api.business.match.bicycle.dto.RespMatchBicycleList;
import org.apache.ibatis.annotations.Param;
import java.time.LocalDateTime;
import java.util.List;
/**
......@@ -15,4 +17,6 @@ public interface MatchBicycleBusinessMapper {
List<RespMatchBicycleList> getMatchBicycleList();
List<DtoMatchBicycleResult> getMatchBicyclePlayerRecord(Long matchId);
Boolean checkMatchRepeat(@Param("entryTime") LocalDateTime entryTime, @Param("endTime") LocalDateTime endTime);
}
......@@ -3,6 +3,7 @@ package com.antai.sport.http.server.game.api.business.match.bicycle;
import com.antai.sport.http.server.common.annotation.LoginSportUser;
import com.antai.sport.http.server.common.base.Result;
import com.antai.sport.http.server.game.api.business.match.bicycle.dto.DtoMatchBicycleResult;
import com.antai.sport.http.server.game.api.business.match.bicycle.dto.ReqMatchBicycleSave;
import com.antai.sport.http.server.game.api.business.match.bicycle.dto.RespMatchBicycleList;
import com.antai.sport.http.server.repository.sport.entity.SportUser;
import io.swagger.annotations.Api;
......@@ -30,12 +31,25 @@ public class MatchBicycleController {
@Resource
private MatchBicyclePlayerService matchBicyclePlayerService;
@PostMapping
@ApiOperation(value = "创建比赛", notes = "data 为创建成功的比赛Id")
public ResponseEntity<Result<Long>> saveMatchBicycle(@RequestBody ReqMatchBicycleSave data) {
return success(matchBicycleService.saveMatchBicycle(data));
}
@GetMapping()
@ApiOperation(value = "获取比赛列表接口", notes = "data为比赛列表数据")
public ResponseEntity<Result<List<RespMatchBicycleList>>> getMatchBicycleList() {
return success(matchBicycleService.getMatchBicycleList());
}
@DeleteMapping("/{matchId}")
@ApiOperation(value = "删除比赛接口" )
public ResponseEntity<Result> deleteMatchBicycle(@PathVariable Long matchId) {
matchBicycleService.removeById(matchId);
return success();
}
@PostMapping("/entry/{matchId}")
@ApiOperation(value = "加入比赛接口")
public ResponseEntity<Result> entryMatchBicycle(@LoginSportUser SportUser loginUser, @PathVariable Long matchId) {
......
package com.antai.sport.http.server.game.api.business.match.bicycle;
import com.antai.sport.http.server.common.exception.BusinessException;
import com.antai.sport.http.server.game.api.business.match.bicycle.dto.ReqMatchBicycleSave;
import com.antai.sport.http.server.game.api.business.match.bicycle.dto.RespMatchBicycleList;
import com.antai.sport.http.server.repository.match.entity.MatchBicycle;
import com.antai.sport.http.server.repository.match.mapper.MatchBicycleMapper;
import com.antai.sport.http.server.repository.sport.entity.SportUser;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import javax.annotation.Resource;
import java.time.LocalDateTime;
......@@ -23,6 +26,36 @@ public class MatchBicycleService extends ServiceImpl<MatchBicycleMapper, MatchBi
@Resource
private MatchBicycleBusinessMapper matchBicycleBusinessMapper;
public Long saveMatchBicycle(@RequestBody ReqMatchBicycleSave data) {
if (StringUtils.isBlank(data.getName())) {
throw new BusinessException("比赛名称不能为空");
}
if (data.getEntryTime() == null || data.getStartTime() == null || data.getEndTime() == null) {
throw new BusinessException("所有输入时间不能为空");
}
if (data.getEntryTime().equals(data.getStartTime()) || data.getEntryTime().isAfter(data.getStartTime())) {
throw new BusinessException("允许进入时间必须早于比赛开始时间");
}
if (data.getStartTime().equals(data.getEndTime()) || data.getStartTime().isAfter(data.getEndTime())) {
throw new BusinessException("比赛开始时间必须早于比赛结束时间");
}
if (matchBicycleBusinessMapper.checkMatchRepeat(data.getEntryTime(), data.getEndTime())) {
throw new BusinessException("比赛时间段有冲突,请修改比赛时间");
}
MatchBicycle match = new MatchBicycle();
match.setName(data.getName());
match.setEntryTime(data.getEntryTime());
match.setStartTime(data.getStartTime());
match.setEndTime(data.getEndTime());
this.save(match);
return match.getId();
}
public List<RespMatchBicycleList> getMatchBicycleList() {
return matchBicycleBusinessMapper.getMatchBicycleList();
}
......
package com.antai.sport.http.server.game.api.business.match.bicycle.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.time.LocalDateTime;
@Data
@ApiModel("创建比赛")
public class ReqMatchBicycleSave {
@ApiModelProperty("比赛名称")
private String name;
@ApiModelProperty("允许进入时间 yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime entryTime;
@ApiModelProperty("开始比赛时间 yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime startTime;
@ApiModelProperty("比赛结束时间 yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime endTime;
}
package com.antai.sport.http.server.game.api.business.match.bicycle.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
......@@ -20,9 +21,12 @@ public class RespMatchBicycleList {
@ApiModelProperty("比赛名称")
private String name;
@ApiModelProperty("允许进入时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime entryTime;
@ApiModelProperty("开始比赛时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime startTime;
@ApiModelProperty("比赛结束时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime endTime;
}
......@@ -8,7 +8,7 @@ spring:
database: 0
host: 127.0.0.1
port: 6379
password: 123
password: 123456
swagger:
enable: true
......@@ -46,6 +46,7 @@ project:
- /login
- /login/sms/**
- /match/bicycle
- /match/bicycle/*
- /match/bicycle/player/record
swagger:
......
......@@ -9,6 +9,17 @@
order by end_time desc
</select>
<select id="checkMatchRepeat"
resultType="java.lang.Boolean">
select count(1)>0
from match_bicycle
where deleted = 0 and (
(entry_time &gt;= #{entryTime} and entry_time &lt;= #{endTime}) or
(end_time &gt;= #{entryTime} and end_time &lt;= #{endTime}) or
(entry_time &lt;= #{entryTime} and end_time &gt;= #{endTime})
)
</select>
<select id="getMatchBicyclePlayerRecord"
resultType="com.antai.sport.http.server.game.api.business.match.bicycle.dto.DtoMatchBicycleResult">
select *
......@@ -16,4 +27,6 @@
where deleted = 0
order by match_rank
</select>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment