This commit is contained in:
2026-04-24 13:39:30 +08:00
parent 0aca47b15e
commit fce211073a
5 changed files with 375 additions and 12 deletions
@@ -2,43 +2,56 @@ package com.budwk.app.zhgh.activity.basic.controller;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
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.stp.StpUtil;
import cn.hutool.json.JSONUtil;
import cn.hutool.core.util.StrUtil;
import com.budwk.app.base.annotation.SLog;
import com.budwk.app.base.constant.RoleConstant;
import com.budwk.app.base.page.Pagination;
import com.budwk.app.base.result.Result;
import com.budwk.app.base.service.BaseService;
import com.budwk.app.base.utils.CommonDownloadUtil;
import com.budwk.app.base.utils.EasyExcelUtil;
import com.budwk.app.sys.models.Sys_role;
import com.budwk.app.web.commons.auth.utils.AuthUtil;
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
import com.budwk.app.zhgh.activity.basic.models.ActivityUserScope;
import com.budwk.app.zhgh.activity.basic.param.ActivityUserScopePageParam;
import com.budwk.app.zhgh.activity.basic.service.ActivityBasicScopeService;
import com.budwk.app.zhgh.activity.basic.template.UserTemp;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.poi.ss.formula.functions.T;
import org.apache.poi.ss.usermodel.Workbook;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.nutz.dao.util.cri.Static;
import org.nutz.integration.jedis.RedisService;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.json.Json;
import org.nutz.lang.Lang;
import org.nutz.lang.util.NutMap;
import org.nutz.mvc.annotation.AdaptBy;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;
import org.nutz.mvc.upload.TempFile;
import org.nutz.mvc.upload.UploadAdaptor;
import javax.management.relation.Role;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
/**
@@ -61,6 +74,9 @@ public class ActivityBasicScopeController {
@Inject
private Dao dao;
@Inject
private RedisService redisService;
@At("")
@Ok("beetl:platform/zhgh/activity/basic/userScope/index.html")
@SaCheckPermission("activity.basic.scope")
@@ -349,6 +365,11 @@ public class ActivityBasicScopeController {
}
}
if (StrUtil.isNotBlank(activityUserScopePageParam.getExistsLoginNameRedisKey())) {
List<String> loginNames = redisService.lrange(activityUserScopePageParam.getExistsLoginNameRedisKey(), 0, -1);
cnd.andEX("u.loginname", "IN", loginNames);
}
if (StrUtil.isAllNotBlank(activityUserScopePageParam.getStartJoinDate(), activityUserScopePageParam.getEndJoinDate())) {
if (activityUserScopePageParam.getReverseSelection()) {
cnd.andNot("u.arrivalAtSchoolDate", "between", new String[]{activityUserScopePageParam.getStartJoinDate(), activityUserScopePageParam.getEndJoinDate()});
@@ -375,5 +396,73 @@ public class ActivityBasicScopeController {
}
@At
@Ok("void")
@SaCheckPermission("activity.basic.scope")
public void downloadImport(HttpServletResponse response) {
List<ExcelExportEntity> entityList = new ArrayList<>();
entityList.add(new ExcelExportEntity("工号", "loginname", 20));
entityList.add(new ExcelExportEntity("姓名", "username", 20));
ExportParams exportParams = new ExportParams();
exportParams.setType(ExcelType.XSSF);
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, entityList, new ArrayList<>());
CommonDownloadUtil.download("人员导入模板.xlsx", workbook, response);
}
@At
@SaCheckPermission("activity.basic.scope")
@AdaptBy(type = UploadAdaptor.class, args = {"ioc:fileUpload"})
public Result doImport(TempFile file) {
String matchUserLoginNamesKey = "ActivityBasicScopeController.doImport.time=" + System.currentTimeMillis();
List<T> ts = EasyExcelUtil.syncReadModel(file.getFile(), UserTemp.class, 0, 1);
List<UserTemp> userImportList = JSONUtil.parseArray(JSONUtil.toJsonStr(ts)).toList(UserTemp.class);
List<String> importLoginNames = userImportList.stream().map(UserTemp::getLoginname).filter(StrUtil::isNotBlank).collect(Collectors.toList());
Set<String> sysLoginNames = new HashSet<>();
if (Lang.isNotEmpty(importLoginNames)) {
Sql userSql = Sqls.create("SELECT loginname FROM sys_user $condition");
userSql.setCondition(Cnd.where("loginname", "IN", importLoginNames));
List<NutMap> sysUserList = baseService.listMap(userSql);
sysLoginNames = sysUserList
.stream()
.map(item -> item.getString("loginname"))
.collect(Collectors.toSet());
}
List<String> existsLoginNames = new ArrayList<>();
for (UserTemp excelUser : userImportList) {
if (StrUtil.isNotBlank(excelUser.getLoginname()) && sysLoginNames.contains(excelUser.getLoginname())) {
existsLoginNames.add(excelUser.getLoginname());
} else {
excelUser.setErrorInfo("系统查不到此人");
}
}
List<UserTemp> errorExcelTempUsers = userImportList.stream().filter(v -> StrUtil.isNotBlank(v.getErrorInfo())).collect(Collectors.toList());
NutMap nutMap = NutMap.NEW();
nutMap.setv("totalCount", userImportList.size());
nutMap.setv("successCount", existsLoginNames.size());
nutMap.setv("errorCount", errorExcelTempUsers.size());
nutMap.setv("errorList", errorExcelTempUsers.stream().map(v -> NutMap.NEW()
.addv("工号", v.getLoginname())
.addv("姓名", v.getUsername())
.addv("错误原因", v.getErrorInfo())).collect(Collectors.toList()));
nutMap.setv("existsLoginNameRedisKey", matchUserLoginNamesKey);
if (Lang.isNotEmpty(existsLoginNames)) {
redisService.lpush(matchUserLoginNamesKey, existsLoginNames.toArray(new String[0]));
redisService.expire(matchUserLoginNamesKey, 60 * 3);
}
return Result.success(nutMap);
}
@At
@SaCheckPermission("activity.basic.scope")
public Result clearSearchCnd(String existsLoginNameRedisKey) {
if (StrUtil.isNotBlank(existsLoginNameRedisKey)) {
redisService.del(existsLoginNameRedisKey);
}
return Result.success();
}
}
@@ -47,6 +47,9 @@ public class ActivityUserScopePageParam extends PageForm {
private String props;
@ApiModelProperty(value = "导入XLSX核对成功人员缓存key")
private String existsLoginNameRedisKey;
@ApiModelProperty(value = "开始加入时间(会员)")
private String startJoinDate;
@@ -0,0 +1,26 @@
package com.budwk.app.zhgh.activity.basic.template;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode
@ContentRowHeight(20)
@HeadRowHeight(20)
@ColumnWidth(25)
public class UserTemp {
@ExcelProperty("工号")
private String loginname;
@ExcelProperty("姓名")
private String username;
@ExcelIgnore
private String errorInfo;
}
@@ -0,0 +1,203 @@
<template>
<div style="padding: 20px 50px">
<el-timeline>
<el-timeline-item timestamp="下载模板" placement="top">
<el-card>
<el-button size="medium" style="width: 200px"
@click="$downLoad('/platform/activity/basic/scope/downloadImport')" icon="el-icon-download">下载模板
</el-button>
</el-card>
</el-timeline-item>
<el-timeline-item timestamp="上传文件" placement="top">
<el-card>
<el-form>
<el-upload
action="#"
name="file"
ref="upload"
:on-remove="handleFileRemove"
:on-change="handleFileChange"
:auto-upload="false"
:limit="1"
:file-list="importData.fileList"
>
<el-button size="medium" icon="el-icon-upload" style="width: 200px">选择文件</el-button>
<div class="el-upload__tip" slot="tip" style="color: #f56c6c">只能上传 xls/xlsx 文件</div>
</el-upload>
</el-form>
</el-card>
</el-timeline-item>
<el-timeline-item placement="top" timestamp="导入结果">
<el-card shadow="never">
<p>总记录数{{ errorInfoData.totalCount }}</p>
<p>
成功数
<span class="text-success">{{ errorInfoData.successCount }}</span>
</p>
<p>
错误数
<span class="text-danger">{{ errorInfoData.errorCount }}</span>
</p>
<el-link @click="exportErrors" type="primary" v-if="errorInfoData.errorCount > 0">下载错误记录</el-link>
</el-card>
</el-timeline-item>
</el-timeline>
<div style="text-align: right">
<span slot="footer" class="dialog-footer">
<el-button @click="clearImportDialog" type="primary"
:disabled="importLoading"> </el-button>
<el-button type="primary" @click="clearSearchCnd"
:loading="importLoading">清空查询条件</el-button>
<el-button type="primary" @click="doImport" :loading="importLoading">核对人员</el-button>
<el-button type="primary" @click="doImportSearch"
:loading="importLoading">查询人员</el-button>
</span>
</div>
</div>
</template>
<script>
module.exports = {
props: {
exists_login_name_redis_key: {type: String, required: ""},
do_import_url: {type: String, required: ""}
},
mounted() {
const s = document.createElement("script")
s.type = "text/javascript"
s.src = "/assets/platform/plugins/xlsx/xlsx.full.min.js"
document.body.appendChild(s)
},
data() {
return {
importData: {
fileList: []
},
errorInfoData: {
totalCount: 0,
successCount: 0,
errorCount: 0,
errorList: []
},
importLoading: false
}
},
methods: {
clearImportDialog() {
this.$emit("clear_import_dialog")
},
handleFileRemove(file, fileList) {
this.$set(this.importData, "fileList", this.fileHandleRemove(file, fileList))
this.$set(this, "errorInfoData", {
errorCount: 0,
successCount: 0,
totalCount: 0,
errorList: []
})
},
handleFileChange(file, fileList) {
this.$set(this.importData, "fileList", this.fileHandleChange(file, fileList, {type: ["xls", "xlsx"]}))
},
clearSearchCnd() {
this.$set(this, "importData", {
fileList: []
})
this.$set(this, "errorInfoData", {
totalCount: 0,
successCount: 0,
errorCount: 0,
errorList: []
})
$.get("/platform/activity/basic/scope/clearSearchCnd", {existsLoginNameRedisKey: this.exists_login_name_redis_key}).then((res) => {
if (res.code === 0) {
this.$emit("flush", "")
this.$message.success(res.msg)
} else {
this.$message.error(res.msg)
}
})
},
doImportSearch() {
this.$emit("flush", this.exists_login_name_redis_key)
this.clearImportDialog()
},
doImport() {
if (this.importData.fileList.length === 0) {
this.$message.error({
title: "错误",
message: "请选择文件!"
})
return
}
const data = new FormData()
this.importData.fileList.forEach((val) => {
data.append("file", val.raw, val.raw.name)
})
this.importLoading = true
this.$axios.post(this.do_import_url, data).then((res) => {
if (res.code === 0) {
if (res.data.errorList && res.data.errorList.length > 0) {
this.$message.warning("核对失败")
} else {
this.$message.success("核对成功")
}
this.$set(this, "errorInfoData", res.data)
this.$emit("flush", res.data.existsLoginNameRedisKey)
} else {
this.$message.warning("核对失败")
}
}).finally(() => {
this.importLoading = false
})
},
exportErrors() {
const data = this.errorInfoData.errorList
const workbook = XLSX.utils.book_new()
const worksheet = XLSX.utils.json_to_sheet(data)
XLSX.utils.book_append_sheet(workbook, worksheet, "Sheet1")
const excelBuffer = XLSX.write(workbook, {bookType: "xlsx", type: "array"})
const blob = new Blob([excelBuffer], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"})
const url = window.URL.createObjectURL(blob)
const link = document.createElement("a")
link.href = url
link.download = "错误记录.xlsx"
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
window.URL.revokeObjectURL(url)
},
fileHandleRemove(file, fileList) {
return fileList
},
fileHandleChange(file, fileList, {type, size}) {
const removeFile = () => {
fileList.splice(fileList.findIndex((v) => v === file))
}
if (!file.size) {
this.$message.warning("您选择的是空文件!")
removeFile()
}
if (type && type.length && !type.includes(file.name.split(".").pop().toLowerCase())) {
this.$message.warning("文件只能是 " + type.map((v) => v.toUpperCase()).join("/") + " 格式!")
removeFile()
}
if (size && !file.size < size) {
this.$message.warning("文件大小不能超过 " + (size / 1024 / 1024) + "MB")
removeFile()
}
return fileList
}
}
}
</script>
<style>
.el-card__body {
padding: 25px;
}
</style>
@@ -278,8 +278,12 @@
<el-card class="mt10" shadow="never">
<table-tool label="筛选人员">
<el-button v-if="is_sysadmin || is_A06"
type="primary" size="medium" icon="el-icon-printer" @click="openImportDialog">
导入XLSX设置分组
</el-button>
<el-button @click="doExportUser" size="medium" type="primary" icon="el-icon-download">导出查询人员</el-button>
<el-button @click="setDialogVisible = true" size="medium" type="primary">设置为活动人员</el-button>
<el-button @click="openSetDialog" size="medium" type="primary">设置为活动人员</el-button>
</table-tool>
<el-table :data="tableData" :size="tableSize" @sort-change="pageOrder" border ref="userTable" stripe>
<el-table-column label="序号" type="index" width="80">
@@ -342,10 +346,19 @@
</el-row>
</el-form>
<span class="dialog-footer" slot="footer">
<el-button @click="setDialogVisible = false"> </el-button>
<el-button @click="closeSetDialog"> </el-button>
<el-button @click="doSetActivityUser" type="primary" v-loading="settingLoading"> </el-button>
</span>
</el-dialog>
<el-dialog :visible.sync="importDialogVisible" title="设置活动人员" width="45%" :append-to-body="true"
:close-on-click-modal="false">
<activity-import-user ref="importUserRef"
@clear_import_dialog="clearImportDialog"
@flush="flush"
do_import_url="/platform/activity/basic/scope/doImport"
:exists_login_name_redis_key="pageForm.existsLoginNameRedisKey"></activity-import-user>
</el-dialog>
</div>
</template>
@@ -360,9 +373,12 @@ module.exports = {
clubOptions: [],
settingLoading: false,
setDialogVisible: false,
setGroupType: null,
setGroupId: null,
setGroupName: null,
importDialogVisible: false,
formData: {
setGroupType: null,
setGroupId: null,
setGroupName: null
},
personTypeOptions: [],
userStateOptions: [],
activityGroupList: [],
@@ -448,10 +464,40 @@ module.exports = {
}
},
components: {
"user-cnd": httpVueLoader("/components/plugins/UserCnd.vue")
"user-cnd": httpVueLoader("/components/plugins/UserCnd.vue"),
"activity-import-user": httpVueLoader("/components/module/activity/ActivityImportUser.vue?v=" + new Date().getTime())
},
methods: {
getDefaultFormData() {
return {
setGroupType: null,
setGroupId: null,
setGroupName: null
}
},
openSetDialog() {
this.$set(this, "formData", this.getDefaultFormData())
this.$set(this, "setDialogVisible", true)
this.$nextTick(() => {
if (this.$refs.setForm) {
this.$refs.setForm.clearValidate()
}
})
},
closeSetDialog() {
this.$set(this, "setDialogVisible", false)
},
flush(existsLoginNameRedisKey) {
this.$set(this.pageForm, "existsLoginNameRedisKey", existsLoginNameRedisKey)
this.doSearch()
},
openImportDialog() {
this.$set(this, "importDialogVisible", true)
},
clearImportDialog() {
this.$set(this, "importDialogVisible", false)
},
doExportUser() {
let props = {}
this.tableColumns.forEach((v) => {
@@ -575,16 +621,12 @@ module.exports = {
Object.assign(pageForm, this.formData)
const resp = await $.post("/platform/activity/basic/scope/doSetActivityUser", {data: JSON.stringify(pageForm)})
if (resp.code === 0) {
this.setDialogVisible = false
this.$set(this, "setDialogVisible", false)
// this.userScopeDialog = false
await this.getActivityGroup()
this.doSearch()
this.$message.success(resp.msg)
this.formData = {
setGroupType: null,
setGroupId: null,
setGroupName: null
}
this.$set(this, "formData", this.getDefaultFormData())
} else {
this.$message.error(resp.msg)
}