疗休养

This commit is contained in:
Paidax
2025-06-11 17:57:42 +08:00
parent c243daddec
commit e9f9d44c06
4 changed files with 172 additions and 27 deletions
@@ -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<LxyImportTemp> tempList = ExcelImportUtil.importExcel(file.getFile(), LxyImportTemp.class, new ImportParams());
if ((tempList.size() + count) >= fetch.getNumber()) {
return Result.error("文件数据超过名额限制,请检查是否存在已报名人员");
}
// 获取本 基层工会的会员,判断是不是报名了其他工会的教工和校验有没有用户数据
List<User> list = dao.query(User.class, Cnd.where("unionid", "=", unionId).and("member", "=", 1));
Map<String, User> userMap = list.stream().collect(Collectors.toMap(User::getLoginname, v -> v));
List<Lxy_bm> sourceList = dao.query(Lxy_bm.class, Cnd.where("hdid", "=", projectId).and("ghid", "=", unionId));
List<String> sourUserIdList = sourceList.stream().map(Lxy_bm::getUserid).collect(Collectors.toList());
String today = cn.hutool.core.date.DateUtil.today();
// 要插入的数据
List<Lxy_bm> bmList = new ArrayList<>();
// 删除lxy_grxx里面的数据
List<String> delUserIds = new ArrayList<>();
// 插入lxy_grxx的数据
List<Lxy_grxx> grxxList = new ArrayList<>();
List<LxyImportTemp> 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();
}
}
}
@@ -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;