Initial commit
This commit is contained in:
@@ -0,0 +1,246 @@
|
||||
package com.datao.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.datao.domain.*;
|
||||
import com.datao.result.PageResult;
|
||||
import com.datao.result.Result;
|
||||
import com.datao.service.*;
|
||||
import com.datao.vo.*;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springdoc.core.annotations.ParameterObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class DataServiceController {
|
||||
private final FetchService fetchService;
|
||||
private final ScanService scanService;
|
||||
private final MatchService matchService;
|
||||
private final OurateService rateService;
|
||||
private final OustatService oustatService;
|
||||
private final GameService gameService;
|
||||
private final TeamService teamService;
|
||||
// private final PredMatchService predMatchService;
|
||||
// private final PredWjrulesService predWjRulesService;
|
||||
|
||||
private DataThreadService thread = null;
|
||||
// private static String startServiceTime = "";
|
||||
// private static String stopServiceTime = "";
|
||||
// private static String lastScanTime = "";
|
||||
|
||||
@GetMapping("/startService")
|
||||
public Result<ServiceVo> startService() {
|
||||
int res = 1;
|
||||
if(thread == null){
|
||||
thread = new DataThreadService(fetchService,scanService,matchService,
|
||||
rateService,oustatService);//,predMatchService,predWjRulesService);
|
||||
thread.start();
|
||||
}
|
||||
else{
|
||||
if(thread.isInterrupted()){
|
||||
thread = null;
|
||||
res = -1;
|
||||
}
|
||||
}
|
||||
|
||||
return Result.success(new ServiceVo(res));
|
||||
}
|
||||
|
||||
@GetMapping("/stopService")
|
||||
public Result<ServiceVo> stopService() {
|
||||
int res = 0;
|
||||
if(thread != null) {
|
||||
thread.interrupt();
|
||||
try {
|
||||
thread.join();
|
||||
} catch (InterruptedException e) {
|
||||
// result = e.getMessage();
|
||||
e.printStackTrace();
|
||||
res = -1;
|
||||
}
|
||||
thread = null;
|
||||
}
|
||||
|
||||
return Result.success(new ServiceVo(res));
|
||||
}
|
||||
|
||||
@GetMapping("/checkService")
|
||||
public Result<ServiceVo> checkService() {
|
||||
int res = 1;
|
||||
if(thread == null){
|
||||
res = 0;
|
||||
}
|
||||
else{
|
||||
if(thread.isInterrupted()) {
|
||||
res = -1;
|
||||
}
|
||||
}
|
||||
|
||||
return Result.success(new ServiceVo(res));
|
||||
}
|
||||
|
||||
@GetMapping("/scan")
|
||||
public PageResult<Scan> getScanPage(@ParameterObject BasePageQuery query) {
|
||||
IPage<Scan> page = scanService.page(
|
||||
new Page<>(query.getPageNum(), query.getPageSize()),
|
||||
new LambdaQueryWrapper<Scan>()
|
||||
.orderByDesc(Scan::getState)
|
||||
.orderByDesc(Scan::getSeason)
|
||||
.orderByAsc(Scan::getGid)
|
||||
.orderByAsc(Scan::getSubid)
|
||||
);
|
||||
return PageResult.success(page);
|
||||
}
|
||||
|
||||
@PutMapping("/scan")
|
||||
public Result updateScan(@RequestBody @Validated Scan scanData) {
|
||||
boolean result = scanService.updateById(scanData);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@PostMapping("/scan")
|
||||
public Result addScan(@RequestBody @Validated Scan scanData) {
|
||||
boolean result = scanService.save(scanData);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@GetMapping("/game")
|
||||
public PageResult<Game> getGamePage(@ParameterObject BasePageQuery query) {
|
||||
IPage<Game> page = gameService.page(new Page<>(query.getPageNum(), query.getPageSize()),
|
||||
new QueryWrapper<Game>().orderByAsc("gid"));
|
||||
return PageResult.success(page);
|
||||
}
|
||||
|
||||
@PostMapping("/game")
|
||||
public Result saveGame(@RequestBody @Validated Game gameData) {
|
||||
boolean result = gameService.saveOrUpdate(gameData);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
private QueryWrapper<Match> buildWrapper(OUStatQuery query){
|
||||
QueryWrapper<Match> wrapper = new QueryWrapper<>();
|
||||
wrapper.ge(ObjectUtils.isNotEmpty(query.getDtstart()),"time",query.getDtstart())
|
||||
.le(ObjectUtils.isNotEmpty(query.getDtend()),"time",query.getDtend())
|
||||
.eq(ObjectUtils.isNotEmpty(query.getIhand()),"ihand",query.getIhand())
|
||||
.eq(ObjectUtils.isNotEmpty(query.getEhand()),"ehand",query.getEhand())
|
||||
.eq(ObjectUtils.isNotEmpty(query.getHname()),"th.name",query.getHname())
|
||||
.in(ObjectUtils.isNotEmpty(query.getGids()),"g.gid", (Object[]) query.getGids());
|
||||
|
||||
if(ObjectUtils.isNotEmpty(query.getIorate())){
|
||||
wrapper.ge("iorate", query.getIorate() - query.getFluct())
|
||||
.le("iorate", query.getIorate() + query.getFluct());
|
||||
}
|
||||
if(ObjectUtils.isNotEmpty(query.getIurate())){
|
||||
wrapper.ge("iurate", query.getIurate() - query.getFluct())
|
||||
.le("iurate", query.getIurate() + query.getFluct());
|
||||
}
|
||||
if(ObjectUtils.isNotEmpty(query.getEorate())){
|
||||
wrapper.ge("eorate", query.getEorate() - query.getFluct())
|
||||
.le("eorate", query.getEorate() + query.getFluct());
|
||||
}
|
||||
if(ObjectUtils.isNotEmpty(query.getEurate())){
|
||||
wrapper.ge("eurate", query.getEurate() - query.getFluct())
|
||||
.le("eurate", query.getEurate() + query.getFluct());
|
||||
}
|
||||
if(ObjectUtils.isNotEmpty(query.getGoal())){
|
||||
String cmp = (query.getGoal()<5 ? "=" : ">=");
|
||||
wrapper.apply("(hgoal+agoal)" + cmp + "{0}", query.getGoal());
|
||||
}
|
||||
if(ObjectUtils.isNotEmpty(query.getChgnum())){
|
||||
String cmp = (query.getChgnum()<5 ? "=" : ">=");
|
||||
wrapper.apply("chgnum" + cmp + "{0}", query.getChgnum());
|
||||
}
|
||||
if(ObjectUtils.isNotEmpty(query.getVhour()) && query.getVhour()>0){
|
||||
int hrMax = query.getVhour() + query.getVhfluct() * 100,
|
||||
hrMin = query.getVhour() - query.getVhfluct() * 100;
|
||||
wrapper.isNotNull("vhour")
|
||||
.ge("vhour", Math.max(hrMin, 0))
|
||||
.le("vhour", hrMax );
|
||||
}
|
||||
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
@PostMapping("/oustat")
|
||||
public Result<OUStatVo> getOUStat(@RequestBody @Validated OUStatQuery query) {
|
||||
QueryWrapper<Match> wrapper = buildWrapper(query);
|
||||
wrapper.apply("LENGTH(hgoal)>0"); //只计算完场比赛
|
||||
|
||||
OUStatVo stat = matchService.getOUStat(wrapper);
|
||||
return Result.success(stat);
|
||||
}
|
||||
|
||||
@PostMapping("/ouinfos")
|
||||
public PageResult<OUInfoVo> getOUInfoPage(@RequestBody @Validated OUInfoQuery query) {
|
||||
QueryWrapper<Match> wrapper = buildWrapper(query);
|
||||
wrapper.orderByDesc("time");
|
||||
|
||||
IPage<OUInfoVo> page = matchService.getOUInfo(new Page<>(query.getPageNum(), query.getPageSize()), wrapper);
|
||||
return PageResult.success(page);
|
||||
}
|
||||
|
||||
@GetMapping("/dbinfo")
|
||||
public Result<DBInfoVo> getDBInfo(){
|
||||
DBInfoVo dbInfo = new DBInfoVo();
|
||||
|
||||
dbInfo.setGameNum( (int)gameService.count() );
|
||||
dbInfo.setTeamNum( (int)teamService.count() );
|
||||
dbInfo.setMatchNum(matchService.getMatchCount());
|
||||
|
||||
Map<String, Object> map = matchService.getMap(new QueryWrapper<Match>().select("min(time) as dtMin, max(time) as dtMax"));
|
||||
LocalDateTime dt = LocalDateTime.ofEpochSecond((Integer) map.get("dtMin"), 0, ZoneOffset.ofHours(8));
|
||||
dbInfo.setYearStart( dt.getYear() );
|
||||
dt = LocalDateTime.ofEpochSecond((Integer) map.get("dtMax"), 0, ZoneOffset.ofHours(8));
|
||||
dbInfo.setYearEnd( dt.getYear() );
|
||||
|
||||
return Result.success(dbInfo);
|
||||
}
|
||||
|
||||
@GetMapping("/ourate/{id}")
|
||||
public Result<Ourate> getOurate(@Parameter @PathVariable Integer id){
|
||||
Ourate rate = rateService.getById(id);
|
||||
return Result.success(rate);
|
||||
}
|
||||
|
||||
// @GetMapping("/predmatches")
|
||||
// public Result<List<PredMatchVo>> getPredMatches(@RequestParam(required=false) Integer sid){
|
||||
// List<PredMatchVo> list = new ArrayList<>();
|
||||
//
|
||||
// if(sid==null)
|
||||
// sid = 20;
|
||||
//
|
||||
// LambdaQueryWrapper<PredMatch> wrapper = sid==21 ? new LambdaQueryWrapper<PredMatch>().gt(PredMatch::getWjstate, 0)
|
||||
// : new LambdaQueryWrapper<PredMatch>().eq(PredMatch::getState, 1);
|
||||
// List<PredMatch> matches = predMatchService.list(wrapper);
|
||||
// for(PredMatch m : matches){
|
||||
// PredMatchVo vo = new PredMatchVo();
|
||||
// vo.setMid( m.getMid() );
|
||||
// vo.setLname( m.getLname() );
|
||||
// vo.setTime( m.getTime() );
|
||||
// vo.setHname( m.getHname() );
|
||||
// vo.setGname( m.getGname() );
|
||||
// vo.setPred( sid==21 ? m.getWjstate() : m.getPred() );
|
||||
//
|
||||
// list.add( vo );
|
||||
// }
|
||||
//
|
||||
// return Result.success(list);
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user