Commit be0640c6 authored by liming's avatar liming

日常赛报名列表查询

parent 0e642677
......@@ -2,7 +2,9 @@ package com.antai.sport.http.server.server.api.business.simplematch.controller;
import com.antai.sport.http.server.common.base.Result;
import com.antai.sport.http.server.server.api.business.simplematch.dto.ReqSimpleMatchInit;
import com.antai.sport.http.server.server.api.business.simplematch.dto.ReqSimpleMatchRegist;
import com.antai.sport.http.server.server.api.business.simplematch.dto.RespSimpleMatchBanner;
import com.antai.sport.http.server.server.api.business.simplematch.dto.RespSimpleMatchList;
import com.antai.sport.http.server.server.api.business.simplematch.service.SimpleMatchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -34,4 +36,23 @@ public class SimpleMatchController {
public ResponseEntity<Result<List<RespSimpleMatchBanner>>> getSimpleMatchBannerList() {
return success(simpleMatchService.getSimpleMatchBannerList());
}
@ApiOperation("通过用户id查询未完赛事列表")
@GetMapping("/list/user/{userId}")
public ResponseEntity<Result<List<RespSimpleMatchList>>> getUnFinishedSimpleMatchForUser(@PathVariable("userId") Long userId) {
return success(simpleMatchService.getUnFinishedSimpleMatchForUser(userId));
}
@ApiOperation("查询所有未完赛事列表")
@GetMapping("/list")
public ResponseEntity<Result<List<RespSimpleMatchList>>> getUnFinishedSimpleMatchForServer() {
return success(simpleMatchService.getUnFinishedSimpleMatchForServer());
}
@ApiOperation("赛事报名")
@PostMapping("/regist")
public ResponseEntity<Result> regist(@RequestBody ReqSimpleMatchRegist param) {
simpleMatchService.regist(param);
return success();
}
}
package com.antai.sport.http.server.server.api.business.simplematch.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel("比赛报名对象")
public class ReqSimpleMatchRegist {
@ApiModelProperty("比赛id")
private Long matchId;
@ApiModelProperty("玩家id")
private Long playerId;
}
package com.antai.sport.http.server.server.api.business.simplematch.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Data
@ApiModel("比赛列表对象")
public class RespSimpleMatchList {
@ApiModelProperty("比赛id")
public Long id;
@ApiModelProperty("比赛名称")
public String name;
@ApiModelProperty("列表展示时间 yyyy-MM-dd HH:mm")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
public LocalDateTime showTime;
@ApiModelProperty("logo")
private String logo;
@ApiModelProperty("地图")
private String map;
@ApiModelProperty("赛道")
private String path;
@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;
@ApiModelProperty("长度")
public BigDecimal distance;
@ApiModelProperty("爬坡高度")
public BigDecimal climbDistance;
@ApiModelProperty("是否已报名,只有当按用户查询时有效")
public Boolean registered;
}
package com.antai.sport.http.server.server.api.business.simplematch.mapper;
import com.antai.sport.http.server.server.api.business.simplematch.dto.RespSimpleMatchList;
import org.apache.ibatis.annotations.Param;
import java.time.LocalDateTime;
import java.util.List;
public interface SimpleMatchBusinessMapper {
List<RespSimpleMatchList> getUnFinishedSimpleMatchListForUser(@Param("userId") Long userId, @Param("now") LocalDateTime now);
List<RespSimpleMatchList> getUnFinishedSimpleMatchListForServer(@Param("now") LocalDateTime now);
}
......@@ -4,17 +4,23 @@ import com.antai.sport.http.server.common.exception.BusinessException;
import com.antai.sport.http.server.constants.DeleteStatus;
import com.antai.sport.http.server.repository.simplematch.entity.SimpleMatch;
import com.antai.sport.http.server.repository.simplematch.entity.SimpleMatchBanner;
import com.antai.sport.http.server.repository.simplematch.entity.SimpleMatchPlayerRegistLog;
import com.antai.sport.http.server.repository.simplematch.mapper.SimpleMatchBannerMapper;
import com.antai.sport.http.server.repository.simplematch.mapper.SimpleMatchMapper;
import com.antai.sport.http.server.repository.simplematch.mapper.SimpleMatchPlayerRegistLogMapper;
import com.antai.sport.http.server.server.api.business.simplematch.converter.SimpleMatchConverter;
import com.antai.sport.http.server.server.api.business.simplematch.dto.ReqSimpleMatchInit;
import com.antai.sport.http.server.server.api.business.simplematch.dto.ReqSimpleMatchRegist;
import com.antai.sport.http.server.server.api.business.simplematch.dto.RespSimpleMatchBanner;
import com.antai.sport.http.server.server.api.business.simplematch.dto.RespSimpleMatchList;
import com.antai.sport.http.server.server.api.business.simplematch.mapper.SimpleMatchBusinessMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.time.LocalDateTime;
import java.util.List;
@Service
......@@ -23,6 +29,11 @@ public class SimpleMatchService {
private SimpleMatchMapper simpleMatchMapper;
@Resource
private SimpleMatchBannerMapper simpleMatchBannerMapper;
@Resource
private SimpleMatchPlayerRegistLogMapper simpleMatchPlayerRegistLogMapper;
@Resource
private SimpleMatchBusinessMapper simpleMatchBusinessMapper;
@Resource
private SimpleMatchConverter simpleMatchConverter;
......@@ -56,6 +67,11 @@ public class SimpleMatchService {
simpleMatchMapper.insert(simpleMatch);
}
/**
* 获取日常赛banner列表
*
* @return
*/
public List<RespSimpleMatchBanner> getSimpleMatchBannerList() {
QueryWrapper<SimpleMatchBanner> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("deleted", DeleteStatus.UNDELETED)
......@@ -63,4 +79,42 @@ public class SimpleMatchService {
List<SimpleMatchBanner> bannerList = simpleMatchBannerMapper.selectList(queryWrapper);
return simpleMatchConverter.toRespBannerList(bannerList);
}
/**
* 通过用户id查看未完赛事列表
*
* @param userId
* @return
*/
public List<RespSimpleMatchList> getUnFinishedSimpleMatchForUser(Long userId) {
return simpleMatchBusinessMapper.getUnFinishedSimpleMatchListForUser(userId, LocalDateTime.now());
}
/**
* 查询所有未完赛事列表
*
* @return
*/
public List<RespSimpleMatchList> getUnFinishedSimpleMatchForServer() {
return simpleMatchBusinessMapper.getUnFinishedSimpleMatchListForServer(LocalDateTime.now());
}
/**
* 比赛报名
*
* @param param
*/
public void regist(ReqSimpleMatchRegist param) {
QueryWrapper<SimpleMatchPlayerRegistLog> countQuery = new QueryWrapper<>();
countQuery.eq("match_id", param.getMatchId()).eq("player_id", param.getPlayerId());
Integer count = simpleMatchPlayerRegistLogMapper.selectCount(countQuery);
if (count > 0) {
throw new BusinessException("不成重复报名");
}
SimpleMatchPlayerRegistLog registLog = new SimpleMatchPlayerRegistLog();
registLog.setMatchId(param.getMatchId());
registLog.setPlayerId(param.getPlayerId());
registLog.setCreateTime(LocalDateTime.now());
simpleMatchPlayerRegistLogMapper.insert(registLog);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.antai.sport.http.server.server.api.business.simplematch.mapper.SimpleMatchBusinessMapper">
<select id="getUnFinishedSimpleMatchListForUser"
resultType="com.antai.sport.http.server.server.api.business.simplematch.dto.RespSimpleMatchList">
select *
from (
select ifnull(t2.base_order, 0) registered,
t1.start_time as show_time,
t1.*
from simple_match t1
left join (
select j1.match_id, 1 base_order
from simple_match_player_regist_log j1
where j1.player_id = #{userId}
) t2 on t1.id = t2.match_id
where t1.end_time &gt; #{now}
and t1.deleted = 0
) t1
order by t1.registered desc, t1.show_order, t1.start_time
</select>
<select id="getUnFinishedSimpleMatchListForServer"
resultType="com.antai.sport.http.server.server.api.business.simplematch.dto.RespSimpleMatchList">
select t1.start_time as show_time, t1.*
from simple_match t1
where t1.end_time &gt; #{now}
and t1.deleted = 0
order by t1.show_order, t1.start_time
</select>
</mapper>
\ No newline at end of file
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