From e9f9d44c063fcb53b81cd04b79984e28b4569414 Mon Sep 17 00:00:00 2001 From: Paidax Date: Wed, 11 Jun 2025 17:57:42 +0800 Subject: [PATCH] =?UTF-8?q?=E7=96=97=E4=BC=91=E5=85=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lxy/controller/LxyGhbmController.java | 127 +++++++++++++++++- .../nutz/zhgh/lxy/template/LxyImportTemp.java | 14 +- .../static/components/plugins/FileImport.vue | 43 ++++-- .../views/platform/zgfw/lxy/HdGhbm.html | 15 ++- 4 files changed, 172 insertions(+), 27 deletions(-) diff --git a/src/main/java/io/v/nutz/zhgh/lxy/controller/LxyGhbmController.java b/src/main/java/io/v/nutz/zhgh/lxy/controller/LxyGhbmController.java index edb451e..dcb1ff6 100644 --- a/src/main/java/io/v/nutz/zhgh/lxy/controller/LxyGhbmController.java +++ b/src/main/java/io/v/nutz/zhgh/lxy/controller/LxyGhbmController.java @@ -1,7 +1,9 @@ package io.v.nutz.zhgh.lxy.controller; import cn.afterturn.easypoi.excel.ExcelExportUtil; +import cn.afterturn.easypoi.excel.ExcelImportUtil; import cn.afterturn.easypoi.excel.entity.ExportParams; +import cn.afterturn.easypoi.excel.entity.ImportParams; import cn.afterturn.easypoi.excel.entity.enmus.ExcelType; import cn.wizzer.framework.base.Result; import io.v.nutz.base.annontation.ViReturn; @@ -9,10 +11,12 @@ import io.v.nutz.base.utils.DateUtil; import io.v.nutz.base.utils.PageUtil; import io.v.nutz.base.utils.Vi; import io.v.nutz.base.utils.ViTool; +import io.v.nutz.sys.models.User; import io.v.nutz.sys.services.SysUserService; import io.v.nutz.web.commons.utils.ShiroUtil; import io.v.nutz.zhgh.lxy.model.Lxy_bm; import io.v.nutz.zhgh.lxy.model.Lxy_grxx; +import io.v.nutz.zhgh.lxy.model.Lxy_mefp; import io.v.nutz.zhgh.lxy.service.LxyBmService; import io.v.nutz.zhgh.lxy.service.LxyGrxxService; import io.v.nutz.zhgh.lxy.service.LxyHdService; @@ -20,16 +24,19 @@ import io.v.nutz.zhgh.lxy.template.LxyImportTemp; import org.apache.poi.ss.usermodel.Workbook; import org.apache.shiro.authz.annotation.RequiresAuthentication; import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.nutz.aop.interceptor.ioc.TransAop; import org.nutz.dao.Cnd; import org.nutz.dao.Dao; import org.nutz.dao.Sqls; import org.nutz.dao.entity.Record; import org.nutz.dao.sql.Sql; import org.nutz.dao.util.cri.Static; +import org.nutz.ioc.aop.Aop; import org.nutz.ioc.loader.annotation.Inject; import org.nutz.ioc.loader.annotation.IocBean; import org.nutz.lang.Lang; import org.nutz.lang.Strings; +import org.nutz.lang.random.R; import org.nutz.lang.util.NutMap; import org.nutz.mvc.annotation.AdaptBy; import org.nutz.mvc.annotation.At; @@ -43,6 +50,9 @@ import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.concurrent.locks.ReentrantLock; +import java.util.stream.Collectors; /** * @Author: 1V @@ -341,14 +351,121 @@ public class LxyGhbmController { } + private final ReentrantLock lock = new ReentrantLock(true); + @At + @Aop(TransAop.READ_COMMITTED) @RequiresPermissions("zgfw.lxy.ghbm") @AdaptBy(type = UploadAdaptor.class, args = {"ioc:fileUpload"}) public Result doImport(TempFile file, String projectId){ - String unionId = Vi.getUnionId(); - // 已经报名的人 - int count = dao.count(Lxy_bm.class, Cnd.where("hdid", "=", projectId).and("ghid", "=", unionId) - .and("bmzt", "in", List.of("1", "2", "3", "4", "5", "6"))); - return null; + try { + lock.lock(); + String unionId = Vi.getUnionId(); + // 已经报名的,排除审核未通过 + int count = dao.count(Lxy_bm.class, Cnd.where("hdid", "=", projectId).and("ghid", "=", unionId) + .and("bmzt", "in", List.of("1", "2", "3", "4", "5", "6"))); + + Lxy_mefp fetch = dao.fetch(Lxy_mefp.class, Cnd.where("hdid", "=", projectId).and("ghid", "=", unionId)); + + if (count >= fetch.getNumber()) { + return Result.error("报名人数已满"); + } + + List tempList = ExcelImportUtil.importExcel(file.getFile(), LxyImportTemp.class, new ImportParams()); + + if ((tempList.size() + count) >= fetch.getNumber()) { + return Result.error("文件数据超过名额限制,请检查是否存在已报名人员"); + } + + // 获取本 基层工会的会员,判断是不是报名了其他工会的教工和校验有没有用户数据 + List list = dao.query(User.class, Cnd.where("unionid", "=", unionId).and("member", "=", 1)); + Map userMap = list.stream().collect(Collectors.toMap(User::getLoginname, v -> v)); + + List sourceList = dao.query(Lxy_bm.class, Cnd.where("hdid", "=", projectId).and("ghid", "=", unionId)); + List sourUserIdList = sourceList.stream().map(Lxy_bm::getUserid).collect(Collectors.toList()); + + String today = cn.hutool.core.date.DateUtil.today(); + + // 要插入的数据 + List bmList = new ArrayList<>(); + // 删除lxy_grxx里面的数据 + List delUserIds = new ArrayList<>(); + // 插入lxy_grxx的数据 + List grxxList = new ArrayList<>(); + + List errorInfos = new ArrayList<>(); + + for (LxyImportTemp temp : tempList) { + User user = userMap.get(temp.getLoginname()); + + if (Lang.isEmpty(user)) { + temp.setRemark("获取不到此用户信息,请确保该教工归属在本基层工会"); + errorInfos.add(temp); + continue; + } + if (sourUserIdList.contains(user.getId())) { + temp.setRemark("报名数据重复"); + errorInfos.add(temp); + continue; + } + + Lxy_bm bm = new Lxy_bm(); + bm.setId(R.UU32()); + bm.setHdid(projectId); + bm.setLoginname(temp.getLoginname()); + bm.setUserid(user.getId()); + bm.setGhid(unionId); + bm.setUnionname(user.getUnitname()); + bm.setBmsj(today); + bm.setBmzt(3); + bm.setBmlx(1); + bm.setUnitname(user.getUnitname()); + bm.setUnitid(user.getUnitid()); + bm.setNation(temp.getNation()); + bm.setZyhj(temp.getZyhj()); + bm.setIdcard(temp.getIdcard()); + bm.setMobile(temp.getMobile()); + bm.setTalent(temp.getTalent()); + bmList.add(bm); + + + delUserIds.add(user.getId()); + Lxy_grxx grxx = new Lxy_grxx(); + grxx.setId(R.UU32()); + grxx.setHdid(projectId); + grxx.setGhid(unionId); + grxx.setUserid(user.getId()); + grxx.setLoginname(temp.getLoginname()); + grxx.setUsername(user.getUsername()); + grxx.setMobile(temp.getMobile()); + grxx.setSex(user.getSex()); + grxx.setMz(temp.getNation()); + grxx.setIdcard(temp.getIdcard()); + grxxList.add(grxx); + } + + dao.fastInsert(bmList); + dao.clear(Lxy_grxx.class, Cnd.where("userid", "in", delUserIds)); + dao.fastInsert(grxxList); + + NutMap nutMap = NutMap.NEW(); + nutMap.setv("totalCount", tempList.size()); + nutMap.setv("successCount", bmList.size()); + nutMap.setv("errorCount", errorInfos.size()); + if (Lang.isNotEmpty(errorInfos)) { + nutMap.setv("errorList", errorInfos.stream().map(v -> { + return NutMap.NEW().addv("工号", v.getLoginname()).addv("姓名", v.getUsername()).addv("错误原因", v.getRemark()); + }).collect(Collectors.toList())); + } else { + nutMap.setv("errorList", new ArrayList<>()); + } + return Result.success().addData(nutMap); + } catch (Exception e) { + e.printStackTrace(); + return Result.error(); + } finally { + lock.unlock(); + } + } } diff --git a/src/main/java/io/v/nutz/zhgh/lxy/template/LxyImportTemp.java b/src/main/java/io/v/nutz/zhgh/lxy/template/LxyImportTemp.java index c685169..6721077 100644 --- a/src/main/java/io/v/nutz/zhgh/lxy/template/LxyImportTemp.java +++ b/src/main/java/io/v/nutz/zhgh/lxy/template/LxyImportTemp.java @@ -13,25 +13,25 @@ import lombok.Data; @Data public class LxyImportTemp { - @Excel(name = "工号") + @Excel(name = "工号", width = 20) String loginname; - @Excel(name = "姓名") + @Excel(name = "姓名", width = 20) String username; - @Excel(name = "民族") + @Excel(name = "民族", width = 20) String nation; - @Excel(name = "疗休养员身份") + @Excel(name = "疗休养员身份", width = 40) String zyhj; - @Excel(name = "身份证号") + @Excel(name = "身份证号", width = 40) String idcard; - @Excel(name = "联系电话") + @Excel(name = "联系电话", width = 20) String mobile; - @Excel(name = "是否为ABCDE类高层次人才") + @Excel(name = "是否为ABCDE类高层次人才", width = 30) String talent; String remark; diff --git a/src/main/resources/static/components/plugins/FileImport.vue b/src/main/resources/static/components/plugins/FileImport.vue index 0295394..1669393 100644 --- a/src/main/resources/static/components/plugins/FileImport.vue +++ b/src/main/resources/static/components/plugins/FileImport.vue @@ -40,7 +40,7 @@ :file-list="importData.fileList" > 选择文件 -
只能上传 xls/xlsx 文件
+
只能上传 xls/xlsx 文件{{ "," + text }}
@@ -62,8 +62,8 @@
- - 确 定 + 关 闭 + 导 入
@@ -75,6 +75,7 @@ module.exports = { temp_url: { type: String }, post_url: { type: String }, project_id: { type: String, default: "" }, + text: { type: String, default: "" }, is_show_radio: { type: Boolean, default: false } }, mounted() { @@ -128,7 +129,14 @@ module.exports = { this.importData.fileList.forEach((val) => { data.append("file", val.raw, val.raw.name) }) - this.importLoading = true + + const loading = this.$loading({ + lock: true, + text: "导入中,请稍后...", + spinner: "el-icon-loading", + background: "rgba(0, 0, 0, 0.7)" + }) + $.ajax({ url: this.post_url, type: "post", @@ -136,22 +144,29 @@ module.exports = { processData: false, contentType: false, success: (data) => { - this.importLoading = false - if (data.code === 0 && data.data === null) { - this.$notify.success("导入成功") - this.importVisible = false - this.$emit("flush") + loading.close() + if (data.code === 0) { + if (data.data) { + this.errorInfoData = data.data + this.$message.success("导入成功条数:" + data.data.successCount + ",错误条数:" + data.data.errorCount) + if (this.errorInfoData.errorCount <= 0) { + this.$emit("flush") + } + } else { + this.importVisible = false + this.$emit("flush") + this.$message.success("导入成功") + } } else { - this.$notify.warning("导入失败") - this.errorInfoData = data.data + loading.close() + this.$message.warning(data.msg) } }, error: (data) => { - this.$notify.warning(data.msg) - this.importLoading = false + loading.close() + this.$message.warning(data.msg) } }) - this.importLoading = false }, exportErrors() { const data = this.errorInfoData.errorList diff --git a/src/main/resources/views/platform/zgfw/lxy/HdGhbm.html b/src/main/resources/views/platform/zgfw/lxy/HdGhbm.html index 78f2344..7a4d92f 100644 --- a/src/main/resources/views/platform/zgfw/lxy/HdGhbm.html +++ b/src/main/resources/views/platform/zgfw/lxy/HdGhbm.html @@ -487,6 +487,7 @@ display: -webkit-box; temp_url="/platform/zgfw/lxy/ghbm/downloadImportTemp" post_url="/platform/zgfw/lxy/ghbm/doImport" :project_id="pageForm.hdid" + :text="'请确保信息完整并准确,高层次人才一栏中请填写A-E的大写字母,非高层次人才请填写否'" @flush="successImport" > @@ -565,7 +566,19 @@ display: -webkit-box; "file-import": httpVueLoader("/components/plugins/FileImport.vue") }, methods: { - openImport() {}, + openImport() { + this.importDialog = true + this.$nextTick(() => { + this.$refs.viewImport.resetImportData() + }) + }, + successImport() { + this.importDialog = false + this.$nextTick(() => { + this.$refs.viewImport.resetImportData() + this.pageData() + }) + }, openBm2(row) { this.checkTableRowData = row this.tabKey = new Date().getTime()