|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package com.gary.exercise.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.gary.exercise.config.FileConfig;
|
|
|
|
|
import com.gary.exercise.dto.ActionDto;
|
|
|
|
|
import com.gary.exercise.service.ExerciseService;
|
|
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
@ -11,18 +12,17 @@ import java.io.FileInputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class ExerciseServiceImpl implements ExerciseService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final FileConfig fileConfig;
|
|
|
|
|
|
|
|
|
|
public ExerciseServiceImpl(FileConfig fileConfig) {
|
|
|
|
|
this.fileConfig = fileConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取单元格的值,并转换为字符串
|
|
|
|
|
*/
|
|
|
|
@ -32,26 +32,33 @@ public class ExerciseServiceImpl implements ExerciseService {
|
|
|
|
|
}
|
|
|
|
|
return switch (cell.getCellType()) {
|
|
|
|
|
case STRING -> cell.getStringCellValue();
|
|
|
|
|
case BOOLEAN -> String.valueOf(cell.getBooleanCellValue());
|
|
|
|
|
case FORMULA -> cell.getCellFormula();
|
|
|
|
|
case BLANK -> "";
|
|
|
|
|
case NUMERIC -> {
|
|
|
|
|
// 检查是否为日期格式
|
|
|
|
|
if (DateUtil.isCellDateFormatted(cell)) {
|
|
|
|
|
yield new SimpleDateFormat("yyyy-MM-dd").format(cell.getDateCellValue());
|
|
|
|
|
// 将日期格式化为字符串
|
|
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm");
|
|
|
|
|
yield dateFormat.format(cell.getDateCellValue());
|
|
|
|
|
} else {
|
|
|
|
|
// 处理数字类型
|
|
|
|
|
yield String.valueOf(cell.getNumericCellValue());
|
|
|
|
|
}
|
|
|
|
|
yield String.valueOf(cell.getNumericCellValue());
|
|
|
|
|
}
|
|
|
|
|
case BOOLEAN -> String.valueOf(cell.getBooleanCellValue());
|
|
|
|
|
case FORMULA -> cell.getCellFormula();
|
|
|
|
|
case BLANK -> "";
|
|
|
|
|
default -> "UNKNOWN";
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 读取 Excel 文件中一行的数据
|
|
|
|
|
* 读取 Excel 文件中一行的数据 将每一个单元格使用List进行存储
|
|
|
|
|
*
|
|
|
|
|
* @param rowIndex 行号(从 0 开始)
|
|
|
|
|
* @return 返回一行数据的列表
|
|
|
|
|
* @throws IOException 如果文件读取失败
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<String> readRow( int rowIndex) throws IOException {
|
|
|
|
|
public List<String> readRow(int rowIndex) throws IOException {
|
|
|
|
|
List<String> rowData = new ArrayList<>();
|
|
|
|
|
String filePath = fileConfig.getFilePath();
|
|
|
|
|
String sheetName = fileConfig.getSheetNumber();
|
|
|
|
@ -72,19 +79,221 @@ public class ExerciseServiceImpl implements ExerciseService {
|
|
|
|
|
return rowData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Map<String, String> processRow(int rowIndex) throws IOException {
|
|
|
|
|
return Map.of();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getLakerAction(ArrayList<String> rowData) {
|
|
|
|
|
if (rowData.size() != 4)
|
|
|
|
|
return null;//说明表示第一节 第二节 没有数据
|
|
|
|
|
else {
|
|
|
|
|
if (rowData.get(3).isEmpty() && rowData.get(1).isEmpty()) {
|
|
|
|
|
//第一行和第二行的数据都是空 说明没有动作
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return rowData.get(1);//直接返回第一行的数据
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getWolfAction(ArrayList<String> rowData) {
|
|
|
|
|
if (rowData.size() != 4)
|
|
|
|
|
return null;//说明表示第一节 第二节 没有数据
|
|
|
|
|
else {
|
|
|
|
|
if (rowData.get(3).isEmpty() && rowData.get(2).isEmpty()) {
|
|
|
|
|
//第一行和第二行的数据都是空 说明没有动作
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return rowData.get(3);//直接返回第三行的数据
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public String getActionTeam(int rowIndex) throws IOException {
|
|
|
|
|
ArrayList<String> rowData = (ArrayList<String>) this.readRow(rowIndex);
|
|
|
|
|
String lakerAction = this.getLakerAction(rowData);
|
|
|
|
|
System.out.println(lakerAction);
|
|
|
|
|
String wolfAction = this.getWolfAction(rowData);
|
|
|
|
|
System.out.println(wolfAction);
|
|
|
|
|
if(Objects.equals(lakerAction, " ") &&!wolfAction.isEmpty()){
|
|
|
|
|
return "wolf";
|
|
|
|
|
}else if (!lakerAction.isEmpty()&& Objects.equals(wolfAction, " ")){
|
|
|
|
|
return "laker";
|
|
|
|
|
}
|
|
|
|
|
return "null";
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 获取剩余的分钟数
|
|
|
|
|
*
|
|
|
|
|
* @param rowIndex
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public String getLeftMinute(int rowIndex) throws IOException {
|
|
|
|
|
ArrayList<String> rowData = (ArrayList<String>) this.readRow(rowIndex);
|
|
|
|
|
String time = rowData.get(0); // 假设时间在第一列
|
|
|
|
|
String minute = "";
|
|
|
|
|
|
|
|
|
|
// 使用 ":" 分割时间字符串
|
|
|
|
|
String[] parts = time.split(":");
|
|
|
|
|
if (parts.length > 0) {
|
|
|
|
|
minute = parts[0]; // 提取分钟部分
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return minute; // 返回分钟
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 获取剩余的秒数
|
|
|
|
|
*
|
|
|
|
|
* @param rowIndex
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public String getLeftSecond(int rowIndex) throws IOException {
|
|
|
|
|
ArrayList<String> rowData = (ArrayList<String>) this.readRow(rowIndex);
|
|
|
|
|
String time = rowData.get(0); // 假设时间在第一列
|
|
|
|
|
String second = "";
|
|
|
|
|
|
|
|
|
|
// 使用 ":" 分割时间字符串
|
|
|
|
|
String[] parts = time.split(":");
|
|
|
|
|
if (parts.length > 1) {
|
|
|
|
|
second = parts[1]; // 提取秒数部分
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return second; // 返回秒数
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 封装统一返回结构返回给前端
|
|
|
|
|
*
|
|
|
|
|
* @param rowIndex
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public ActionDto getResult(int rowIndex) throws IOException {
|
|
|
|
|
ActionDto actionDto = new ActionDto();
|
|
|
|
|
String leftMinute = this.getLeftMinute(rowIndex);
|
|
|
|
|
System.out.println(leftMinute);
|
|
|
|
|
String leftSecond = this.getLeftSecond(rowIndex);
|
|
|
|
|
System.out.println(leftSecond);
|
|
|
|
|
String whichTeamAttack = this.getActionTeam(rowIndex);
|
|
|
|
|
System.out.println(whichTeamAttack);
|
|
|
|
|
String action = this.getLakerAction((ArrayList<String>) this.readRow(rowIndex));
|
|
|
|
|
System.out.println(action);
|
|
|
|
|
int lakerScore=this.getLakerScore(rowIndex);
|
|
|
|
|
System.out.println(lakerScore);
|
|
|
|
|
int wolfScore=this.getWolfScore(rowIndex);
|
|
|
|
|
System.out.println(wolfScore);
|
|
|
|
|
String getScoreType = this.getScoreType(rowIndex);
|
|
|
|
|
System.out.println(getScoreType);
|
|
|
|
|
Boolean isGetSocre = this.isGetScore(rowIndex);
|
|
|
|
|
System.out.println(isGetSocre);
|
|
|
|
|
|
|
|
|
|
actionDto.setIsGetSocre(isGetSocre);
|
|
|
|
|
actionDto.setGetScoreType(getScoreType);
|
|
|
|
|
actionDto.setLakerScore(lakerScore);
|
|
|
|
|
actionDto.setWolfScore(wolfScore);
|
|
|
|
|
actionDto.setLeftMinute(leftMinute);
|
|
|
|
|
actionDto.setLeftSecond(leftSecond);
|
|
|
|
|
actionDto.setWhichTeamAttack(whichTeamAttack);
|
|
|
|
|
actionDto.setAction(action);
|
|
|
|
|
System.out.println(actionDto);
|
|
|
|
|
|
|
|
|
|
return actionDto;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取当前的湖人队比分
|
|
|
|
|
*
|
|
|
|
|
* @param rowIndex
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Map<String, String> processRow(int rowIndex) throws IOException{
|
|
|
|
|
List<String> rowData = readRow(rowIndex);
|
|
|
|
|
public int getLakerScore(int rowIndex) throws IOException {
|
|
|
|
|
List<String> rowData = this.readRow(rowIndex); // 读取 Excel 数据
|
|
|
|
|
System.out.println(rowData);
|
|
|
|
|
String data=rowData.get(2);
|
|
|
|
|
System.out.println(data);
|
|
|
|
|
// 使用 "- 分割时间字符串
|
|
|
|
|
String[] parts = data.split("-");
|
|
|
|
|
if (parts.length > 1) {
|
|
|
|
|
return Integer.parseInt(parts[0]); // 提取湖人队比分
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取当前森林狼队比分
|
|
|
|
|
*
|
|
|
|
|
* @param rowIndex
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public int getWolfScore(int rowIndex) throws IOException {
|
|
|
|
|
List<String> rowData = this.readRow(rowIndex); // 读取 Excel 数据
|
|
|
|
|
System.out.println(rowData);
|
|
|
|
|
String data=rowData.get(2);
|
|
|
|
|
System.out.println(data);
|
|
|
|
|
// 使用 "- 分割时间字符串
|
|
|
|
|
String[] parts = data.split("-");
|
|
|
|
|
if (parts.length > 1) {
|
|
|
|
|
return Integer.parseInt(parts[1]); // 提取森林狼队比分
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取当前回合的得分类型
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public String getScoreType(int rowIndex) throws IOException {
|
|
|
|
|
String action = this.getAction(rowIndex);
|
|
|
|
|
|
|
|
|
|
// 检查是否包含 "三分" 或 "两分"
|
|
|
|
|
if (action.contains("三分")) {
|
|
|
|
|
return "三分";
|
|
|
|
|
} else if (action.contains("两分")) {
|
|
|
|
|
return "两分"; // 如果有明确的两分投篮
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 其他得分类型
|
|
|
|
|
if (action.contains("篮板")) {
|
|
|
|
|
return "篮板";
|
|
|
|
|
} else if (action.contains("抢断")) {
|
|
|
|
|
return "抢断";
|
|
|
|
|
} else if (action.contains("罚球")) {
|
|
|
|
|
return "罚球";
|
|
|
|
|
} else if (action.contains("盖帽")) {
|
|
|
|
|
return "盖帽";
|
|
|
|
|
} else if (action.contains("犯规")) {
|
|
|
|
|
return "犯规";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "未知"; // 如果没有匹配的类型
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断球员是否得分
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Boolean isGetScore(int rowIndex) throws IOException {
|
|
|
|
|
String action = this.getAction(rowIndex);
|
|
|
|
|
return action.contains("命中") && !action.contains("不中");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Map.of();
|
|
|
|
|
/**
|
|
|
|
|
* 获取当前球队的action
|
|
|
|
|
*
|
|
|
|
|
* @param rowIndex
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public String getAction(int rowIndex) throws IOException {
|
|
|
|
|
String whichTeamAttack = this.getActionTeam(rowIndex);
|
|
|
|
|
if (whichTeamAttack.equals("laker")) {
|
|
|
|
|
return this.getLakerAction((ArrayList<String>) this.readRow(rowIndex));
|
|
|
|
|
}else if (whichTeamAttack.equals("wolf")) {
|
|
|
|
|
return this.getWolfAction((ArrayList<String>) this.readRow(rowIndex));
|
|
|
|
|
}
|
|
|
|
|
else return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|