commit
This commit is contained in:
+69
-3
@@ -1,5 +1,10 @@
|
|||||||
package com.budwk.app.module.activity.controller;
|
package com.budwk.app.module.activity.controller;
|
||||||
|
|
||||||
|
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||||
|
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||||
|
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
|
||||||
|
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
|
||||||
|
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
|
||||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.budwk.app.base.result.Result;
|
import com.budwk.app.base.result.Result;
|
||||||
@@ -10,6 +15,9 @@ import com.budwk.app.module.activity.vo.page.ActScoreEnterPageForm;
|
|||||||
import com.budwk.app.module.activity.vo.page.ActSignInUserPageForm;
|
import com.budwk.app.module.activity.vo.page.ActSignInUserPageForm;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.apache.poi.ss.usermodel.*;
|
||||||
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||||
import org.nutz.dao.Cnd;
|
import org.nutz.dao.Cnd;
|
||||||
import org.nutz.dao.Dao;
|
import org.nutz.dao.Dao;
|
||||||
@@ -23,10 +31,11 @@ import org.nutz.lang.util.NutMap;
|
|||||||
import org.nutz.mvc.annotation.At;
|
import org.nutz.mvc.annotation.At;
|
||||||
import org.nutz.mvc.annotation.Ok;
|
import org.nutz.mvc.annotation.Ok;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.net.URLEncoder;
|
||||||
import java.util.Comparator;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
@@ -139,4 +148,61 @@ public class ActScoreEnterController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@At
|
||||||
|
@Ok("void")
|
||||||
|
@SaCheckPermission("activity.scoreEnter")
|
||||||
|
public void doExport(Long activityId, HttpServletResponse response) {
|
||||||
|
try {
|
||||||
|
Activity activity = activityService.fetch(activityId);
|
||||||
|
|
||||||
|
Sql sql = Sqls.create("""
|
||||||
|
SELECT
|
||||||
|
groupName,
|
||||||
|
id
|
||||||
|
FROM
|
||||||
|
`act_group`
|
||||||
|
WHERE
|
||||||
|
activityId = @activityId
|
||||||
|
""").setParam("activityId", activityId);
|
||||||
|
List<NutMap> listMap = activityService.listMap(sql);
|
||||||
|
List<ActivityItem> itemList = activityService.dao().query(ActivityItem.class, Cnd.where(ActivityItem::getActivityId, "=", activityId).asc(ActivityItem::getSort));
|
||||||
|
ActivityItem activityItem = new ActivityItem();
|
||||||
|
activityItem.setName("总分");
|
||||||
|
activityItem.setId(0L);
|
||||||
|
itemList.add(activityItem);
|
||||||
|
List<ActItemGroupScore> scoreList = dao.query(ActItemGroupScore.class, Cnd.where(ActItemGroupScore::getActivityId, "=", activityId));
|
||||||
|
|
||||||
|
listMap.stream().forEach(group -> {
|
||||||
|
itemList.forEach(item -> {
|
||||||
|
if (item.getId() == 0) {
|
||||||
|
BigDecimal totalScore = scoreList.stream().filter(score -> score.getGroupId().equals(group.getLong("id")) && score.getScore() != null).map(ActItemGroupScore::getScore).reduce(BigDecimal::add).orElse(new BigDecimal(0));
|
||||||
|
group.put("totalScore", totalScore);
|
||||||
|
} else {
|
||||||
|
ActItemGroupScore itemGroupScore = scoreList.stream().filter(score ->
|
||||||
|
score.getGroupId().equals(group.getLong("id"))
|
||||||
|
&& score.getItemId().equals(item.getId())).findFirst().orElse(null);
|
||||||
|
group.put(item.getName() + "score", itemGroupScore.getScore());
|
||||||
|
group.put(item.getName() + "ranking", itemGroupScore.getRanking());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
|
map.put("mapList", listMap);
|
||||||
|
map.put("title", activity.getTitle());
|
||||||
|
map.put("itemList", itemList);
|
||||||
|
response.setContentType("application/octet-stream");
|
||||||
|
response.setHeader("Content-Disposition", "attachment;filename=" + new String((activity.getTitle() + "评分表.xlsx").getBytes(StandardCharsets.UTF_8), "ISO8859-1"));
|
||||||
|
TemplateExportParams params = new TemplateExportParams("templates/scoreEnter.xlsx");
|
||||||
|
params.setColForEach(true);
|
||||||
|
Workbook workbook = ExcelExportUtil.exportExcel(params, map);
|
||||||
|
workbook.write(response.getOutputStream());
|
||||||
|
workbook.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -35,10 +35,12 @@ layout("/layouts/platform_1.html"){
|
|||||||
<div class="search-query">
|
<div class="search-query">
|
||||||
<el-button type="primary" icon="el-icon-search" @click="doSearch">搜索</el-button>
|
<el-button type="primary" icon="el-icon-search" @click="doSearch">搜索</el-button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</el-card>
|
</el-card>
|
||||||
<el-card shadow="never" class="mt-3">
|
<el-card shadow="never" class="mt-3">
|
||||||
|
<el-row type="flex" class="mb-3" style="justify-content: flex-end">
|
||||||
|
<el-button type="primary" size="small" @click="doExport">导出</el-button>
|
||||||
|
</el-row>
|
||||||
<el-table v-loading="tableLoading" show-overflow-tooltip :data="tableData" @cell-click="cellClick">
|
<el-table v-loading="tableLoading" show-overflow-tooltip :data="tableData" @cell-click="cellClick">
|
||||||
<el-table-column label="队伍" prop="groupName" fixed="left" width="100px"></el-table-column>
|
<el-table-column label="队伍" prop="groupName" fixed="left" width="100px"></el-table-column>
|
||||||
|
|
||||||
@@ -49,19 +51,20 @@ layout("/layouts/platform_1.html"){
|
|||||||
</template>
|
</template>
|
||||||
<el-table-column label="成绩" :prop="item.id+item.name" min-width="50px">
|
<el-table-column label="成绩" :prop="item.id+item.name" min-width="50px">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-input v-model="scope.row[item.id]['totalScore']"></el-input>
|
{{scope.row[item.id]['totalScore']}}
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="名次" :prop="item.id+item.name" min-width="50px">
|
|
||||||
|
<el-table-column label="名次" :prop="item.id+item.name" min-width="50px" v-if="item.id!=='all'">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-input v-model="scope.row[item.id]['totalRank']"></el-input>
|
{{scope.row[item.id]['totalRank']}}
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
<el-row type="flex" justify="end" class="mt-3">
|
<!-- <el-row type="flex" justify="end" class="mt-3">
|
||||||
<el-button type="primary" @click="saveScore">保存</el-button>
|
<el-button type="primary" @click="saveScore">保存</el-button>
|
||||||
</el-row>
|
</el-row>-->
|
||||||
</el-card>
|
</el-card>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -86,6 +89,9 @@ layout("/layouts/platform_1.html"){
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
doExport() {
|
||||||
|
window.open("/platform/activity/scoreEnter/doExport?activityId=" + this.pageForm.activityId )
|
||||||
|
},
|
||||||
// 格式化名称
|
// 格式化名称
|
||||||
formatName(name) {
|
formatName(name) {
|
||||||
if (!name) return ""
|
if (!name) return ""
|
||||||
@@ -127,6 +133,7 @@ layout("/layouts/platform_1.html"){
|
|||||||
} = await $.get("/platform/activity/scoreEnter/list-item/" + this.pageForm.activityId)
|
} = await $.get("/platform/activity/scoreEnter/list-item/" + this.pageForm.activityId)
|
||||||
if (code === 0) {
|
if (code === 0) {
|
||||||
this.itemOptions = data
|
this.itemOptions = data
|
||||||
|
this.itemOptions.push({id: "all", "name": "总积分"})
|
||||||
} else {
|
} else {
|
||||||
this.$message.error(msg)
|
this.$message.error(msg)
|
||||||
}
|
}
|
||||||
@@ -160,20 +167,32 @@ layout("/layouts/platform_1.html"){
|
|||||||
groupName: group.groupName
|
groupName: group.groupName
|
||||||
}
|
}
|
||||||
this.itemOptions.forEach((item) => {
|
this.itemOptions.forEach((item) => {
|
||||||
let data = this.itemScoreList.find(s => s.groupId === group.id && s.itemId === item.id);
|
if (item.id === "all") {
|
||||||
if (data) {
|
let data = this.itemScoreList.filter(s => s.groupId === group.id);
|
||||||
|
const sum = data.map(d => d.score).reduce((total, value) => {
|
||||||
|
return total + (value || 0);
|
||||||
|
}, 0);
|
||||||
row[item.id] = {
|
row[item.id] = {
|
||||||
id: data.id,
|
id: data.id,
|
||||||
totalScore: data.score ? data.score : null,
|
totalScore: sum,
|
||||||
totalRank: data.ranking ? data.ranking : null
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
row[item.id] = {
|
let data = this.itemScoreList.find(s => s.groupId === group.id && s.itemId === item.id);
|
||||||
totalScore: null,
|
if (data) {
|
||||||
totalRank: null
|
row[item.id] = {
|
||||||
|
id: data.id,
|
||||||
|
totalScore: data.score ? data.score : null,
|
||||||
|
totalRank: data.ranking ? data.ranking : null
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
row[item.id] = {
|
||||||
|
totalScore: null,
|
||||||
|
totalRank: null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
return row
|
return row
|
||||||
})
|
})
|
||||||
@@ -187,12 +206,12 @@ layout("/layouts/platform_1.html"){
|
|||||||
activityId: this.pageForm.activityId,
|
activityId: this.pageForm.activityId,
|
||||||
data: JSON.stringify(this.tableData)
|
data: JSON.stringify(this.tableData)
|
||||||
}
|
}
|
||||||
const {code,data,msg} = await $.post("/platform/activity/scoreEnter/save-score", formData)
|
const {code, data, msg} = await $.post("/platform/activity/scoreEnter/save-score", formData)
|
||||||
if (code === 0) {
|
if (code === 0) {
|
||||||
await this.listItemScore()
|
await this.listItemScore()
|
||||||
this.buildTableData()
|
this.buildTableData()
|
||||||
this.$message.success("保存成功")
|
this.$message.success("保存成功")
|
||||||
}else{
|
} else {
|
||||||
this.$message.error(msg)
|
this.$message.error(msg)
|
||||||
}
|
}
|
||||||
console.log(this.tableData)
|
console.log(this.tableData)
|
||||||
|
|||||||
Reference in New Issue
Block a user