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