This commit is contained in:
那些花儿
2025-05-13 19:09:52 +08:00
parent 7949eec70d
commit 80e9bb6521
5 changed files with 46 additions and 85 deletions
@@ -101,40 +101,40 @@ public class ActScoreEnterController {
@Aop(TransAop.READ_COMMITTED)
@ApiOperation(value = "保存成绩", nickname = "/save-score", httpMethod = "POST")
public Result saveScore(ActItemScoreVo actItemScoreVo) {
List<ActivityItem> itemList = dao.query(ActivityItem.class, Cnd.where(ActivityItem::getActivityId, "=", actItemScoreVo.getActivityId()));
// dao.clear(ActItemGroupScore.class, Cnd.where(ActItemGroupScore::getActivityId, "=", actItemScoreVo.getActivityId()));
List<ActItemGroupScore> activityItemScores = new ArrayList<>();
actItemScoreVo.getData().forEach(item -> {
itemList.forEach(i -> {
ActItemGroupScore score = new ActItemGroupScore();
NutMap data = item.getAs(i.getId().toString(), NutMap.class);
if (Lang.isNotEmpty(data)) {
String totalScore = StrUtil.isNotEmpty(data.getString("totalScore")) ? data.getString("totalScore") : "0";
score.setScore(new BigDecimal(totalScore));
int totalRank = data.getInt("totalRank", 0);
score.setRanking(totalRank);
score.setId(data.getLong("id"));
} else {
score.setScore(new BigDecimal(0));
score.setRanking(0);
}
score.setItemId(i.getId());
score.setActivityId(actItemScoreVo.getActivityId());
score.setGroupId(item.getLong("groupId"));
activityItemScores.add(score);
});
});
dao.update(activityItemScores);
// 更新队伍得分及排名
List<ActGroup> groups = dao.query(ActGroup.class, Cnd.where(ActGroup::getActivityId, "=", actItemScoreVo.getActivityId()));
for (ActGroup group : groups) {
List<ActItemGroupScore> groupScores = activityItemScores.stream().filter(item -> item.getGroupId().equals(group.getId())).collect(Collectors.toList());
groupScores.stream().map(v -> v.getScore()).reduce(BigDecimal::add).ifPresent(group::setTotalScore);
}
groups.sort(Comparator.comparing(ActGroup::getTotalScore).reversed());
IntStream.range(0, groups.size()).forEach(i -> groups.get(i).setTotalRank(i + 1));
dao.update(groups, "totalScore|totalRank");
// List<ActivityItem> itemList = dao.query(ActivityItem.class, Cnd.where(ActivityItem::getActivityId, "=", actItemScoreVo.getActivityId()));
//// dao.clear(ActItemGroupScore.class, Cnd.where(ActItemGroupScore::getActivityId, "=", actItemScoreVo.getActivityId()));
// List<ActItemGroupScore> activityItemScores = new ArrayList<>();
// actItemScoreVo.getData().forEach(item -> {
// itemList.forEach(i -> {
// ActItemGroupScore score = new ActItemGroupScore();
// NutMap data = item.getAs(i.getId().toString(), NutMap.class);
// if (Lang.isNotEmpty(data)) {
// String totalScore = StrUtil.isNotEmpty(data.getString("totalScore")) ? data.getString("totalScore") : "0";
// score.setScore(new BigDecimal(totalScore));
// int totalRank = data.getInt("totalRank", 0);
// score.setRanking(totalRank);
// score.setId(data.getLong("id"));
// } else {
// score.setScore(new BigDecimal(0));
// score.setRanking(0);
// }
// score.setItemId(i.getId());
// score.setActivityId(actItemScoreVo.getActivityId());
// score.setGroupId(item.getLong("groupId"));
// activityItemScores.add(score);
// });
// });
// dao.update(activityItemScores);
//
// // 更新队伍得分及排名
// List<ActGroup> groups = dao.query(ActGroup.class, Cnd.where(ActGroup::getActivityId, "=", actItemScoreVo.getActivityId()));
// for (ActGroup group : groups) {
// List<ActItemGroupScore> groupScores = activityItemScores.stream().filter(item -> item.getGroupId().equals(group.getId())).collect(Collectors.toList());
// groupScores.stream().map(v -> v.getScore()).reduce(BigDecimal::add).ifPresent(group::setTotalScore);
// }
// groups.sort(Comparator.comparing(ActGroup::getTotalScore).reversed());
// IntStream.range(0, groups.size()).forEach(i -> groups.get(i).setTotalRank(i + 1));
// dao.update(groups, "totalScore|totalRank");
return Result.success();
}
@@ -45,5 +45,6 @@ public class ActItemGroupScore extends BaseModel {
@Column
@Comment("队伍排名")
private Integer ranking;
@ColDefine(type = ColType.VARCHAR, width = 50)
private String ranking;
}
@@ -78,18 +78,17 @@ layout("/layouts/platform_1.html"){
<el-table-column label="序号" type="index" header-align="center" align="center" width="50"></el-table-column>
<el-table-column label="队伍名称" prop="groupName"></el-table-column>
<el-table-column label="队伍总人数" prop="groupNum"></el-table-column>
<el-table-column label="男运动员人数" prop="manNum"></el-table-column>
<el-table-column label="女运动员人数" prop="womanNum"></el-table-column>
<el-table-column label="领队" prop="leaderName">
<el-table-column label="男队员人数" prop="manNum"></el-table-column>
<el-table-column label="女队员人数" prop="womanNum"></el-table-column>
<el-table-column label="队长" prop="leaderName">
<template #default="{row}">
<el-tag v-if="row.leaderName">{{row.leaderName}}</el-tag>
<el-tag v-else type="warning">未设置</el-tag>
</template>
</el-table-column>
<el-table-column label="领队联系方式" prop="leaderPhone">
<el-table-column label="队长联系方式" prop="leaderPhone">
<template #default="{row}">
<el-tag v-if="row.leaderPhone">{{row.leaderPhone}}</el-tag>
<el-tag v-else type="warning">未设置</el-tag>
</template>
</el-table-column>
<el-table-column label="操作" fixed="right" width="250">
@@ -9,7 +9,7 @@ const VIEW_INFO = {
<el-table-column label="身份" prop="isLeader">
<template #default="{row}">
<el-tag size="small" v-if="row.isLeader">{{ '队长' }}</el-tag>
<el-tag type="warning" size="small" v-else>{{ '运动员' }}</el-tag>
<el-tag type="warning" size="small" v-else>{{ '队员' }}</el-tag>
</template>
</el-table-column>
<el-table-column label="联系方式" prop="phone"></el-table-column>
@@ -95,7 +95,7 @@ layout("/layouts/platform_1.html"){
<el-table-column label="名次设置" width="220">
<template slot-scope="scope">
<el-select
v-model="getScoreRecord(item.id, scope.row.id).rankingObj"
v-model="getScoreRecord(item.id, scope.row.id).ranking"
placeholder="请选择名次"
@change="updateScore(item.id, scope.row.id)"
class="rank-select">
@@ -103,7 +103,7 @@ layout("/layouts/platform_1.html"){
v-for="(rank, index) in rankScoreOptions"
:key="rank.id"
:label="rank.ranking"
:value="index + 1">
:value="rank.ranking">
</el-option>
</el-select>
</template>
@@ -236,51 +236,14 @@ layout("/layouts/platform_1.html"){
let record = this.itemScoreList.find(score =>
score.itemId === itemId && score.groupId === groupId
)
// 如果没有找到,创建一个新记录
if (!record) {
record = {
activityId: this.pageForm.activityId,
itemId: itemId,
groupId: groupId,
score: null,
ranking: null,
rankingObj: null,
remark: ""
}
this.itemScoreList.push(record)
}
// 确保remark字段存在
if (!record.hasOwnProperty("remark")) {
record.remark = ""
}
// 确保rankingObj字段存在
if (!record.hasOwnProperty("rankingObj")) {
record.rankingObj = record.ranking
}
return record
},
// 更新分数
updateScore(itemId, groupId) {
const record = this.getScoreRecord(itemId, groupId)
const rankingValue = record.rankingObj
// 同步ranking字段和rankingObj字段
record.ranking = rankingValue
if (rankingValue) {
// 查找对应名次的分数
const rankScore = this.rankScoreOptions[rankingValue - 1]
if (rankScore) {
record.score = rankScore.score
}
} else {
record.score = null
}
const score = this.rankScoreOptions.find(v=>v.ranking === record.ranking)?.score
record.score = score
},
// 保存单个项目的分数
@@ -335,9 +298,9 @@ layout("/layouts/platform_1.html"){
async activityChange() {
this.loading = true
try {
await this.listItemScore()
await this.listGroup()
await this.listItem()
await this.listItemScore()
} catch (error) {
console.error(error)
} finally {
@@ -364,9 +327,7 @@ layout("/layouts/platform_1.html"){
<style>
.filter-card {
margin-bottom: 20px;
border-radius: 10px;
overflow: hidden;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05) !important;
}
.score-entry-container {