报名导入

main
王家东 3 months ago
parent 827e721d80
commit cbda46433f
  1. 186
      jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/annualCompPoint/controller/AnnualCompPointController.java
  2. 31
      jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/annualCompPoint/entity/AnnualCompPointMb.java

@ -33,8 +33,10 @@ import org.jeecg.modules.demo.annualcomp.service.IAnnualCompService;
import org.jeecg.modules.demo.annualcompaward.entity.AnnualCompAward; import org.jeecg.modules.demo.annualcompaward.entity.AnnualCompAward;
import org.jeecg.modules.demo.annualcompaward.service.IAnnualCompAwardService; import org.jeecg.modules.demo.annualcompaward.service.IAnnualCompAwardService;
import org.jeecg.modules.demo.annualcompetitionprojectregistration.entity.AnnualCompetitionProjectRegistration; import org.jeecg.modules.demo.annualcompetitionprojectregistration.entity.AnnualCompetitionProjectRegistration;
import org.jeecg.modules.demo.annualcompetitionprojectregistration.entity.InstructorSheet;
import org.jeecg.modules.demo.annualcompetitionprojectregistration.entity.TeamManagement; import org.jeecg.modules.demo.annualcompetitionprojectregistration.entity.TeamManagement;
import org.jeecg.modules.demo.annualcompetitionprojectregistration.service.IAnnualCompetitionProjectRegistrationService; import org.jeecg.modules.demo.annualcompetitionprojectregistration.service.IAnnualCompetitionProjectRegistrationService;
import org.jeecg.modules.demo.annualcompetitionprojectregistration.service.IInstructorSheetService;
import org.jeecg.modules.demo.annualcompetitionprojectregistration.service.ITeamManagementService; import org.jeecg.modules.demo.annualcompetitionprojectregistration.service.ITeamManagementService;
import org.jeecg.modules.demo.awardpersion.entity.AwardPersion; import org.jeecg.modules.demo.awardpersion.entity.AwardPersion;
import org.jeecg.modules.demo.awardpersion.entity.AwardPersionMb; import org.jeecg.modules.demo.awardpersion.entity.AwardPersionMb;
@ -53,6 +55,7 @@ import org.jeecg.modules.demo.scorepersion.entity.ScorePersion;
import org.jeecg.modules.demo.scorepersion.service.IScorePersionService; import org.jeecg.modules.demo.scorepersion.service.IScorePersionService;
import org.jeecg.modules.demo.upfile_persion.entity.UpfilePersion; import org.jeecg.modules.demo.upfile_persion.entity.UpfilePersion;
import org.jeecg.modules.demo.upfile_persion.service.IUpfilePersionService; import org.jeecg.modules.demo.upfile_persion.service.IUpfilePersionService;
import org.jeecg.modules.system.entity.SysDict;
import org.jeecg.modules.system.entity.SysUser; import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.service.ISysUserService; import org.jeecg.modules.system.service.ISysUserService;
import org.jeecgframework.poi.excel.ExcelImportUtil; import org.jeecgframework.poi.excel.ExcelImportUtil;
@ -133,6 +136,9 @@ public class AnnualCompPointController extends JeecgController<AnnualCompPoint,
@Autowired @Autowired
private RedisUtil redisUtil; private RedisUtil redisUtil;
@Autowired
private IInstructorSheetService instructorSheetService;
/** /**
* 分页列表查询 * 分页列表查询
@ -1049,7 +1055,7 @@ public class AnnualCompPointController extends JeecgController<AnnualCompPoint,
mv.addObject(NormalExcelConstants.FILE_NAME, "报名模板"); mv.addObject(NormalExcelConstants.FILE_NAME, "报名模板");
mv.addObject(NormalExcelConstants.CLASS, AnnualCompPointMb.class); mv.addObject(NormalExcelConstants.CLASS, AnnualCompPointMb.class);
//update-begin--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置-------------------- //update-begin--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置--------------------
ExportParams exportParams=new ExportParams("报名模板" + "报表", "导出人:" + sysUser.getRealname(), "报名模板"); ExportParams exportParams=new ExportParams("报名模板" + "报表", "数据之间请用%隔开即使没有数据也要加一个%,最后一个数据可以不用加%。例如:1%1%1。不可使用空数据。"+"导出人:" + sysUser.getRealname(), "报名模板");
exportParams.setImageBasePath(jeecgBaseConfig.getPath().getUpload()); exportParams.setImageBasePath(jeecgBaseConfig.getPath().getUpload());
//update-end--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置---------------------- //update-end--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置----------------------
mv.addObject(NormalExcelConstants.PARAMS,exportParams); mv.addObject(NormalExcelConstants.PARAMS,exportParams);
@ -1067,6 +1073,12 @@ public class AnnualCompPointController extends JeecgController<AnnualCompPoint,
//@RequiresPermissions("annualCompPoint:annual_comp_point:importExcel") //@RequiresPermissions("annualCompPoint:annual_comp_point:importExcel")
@RequestMapping(value = "/importExcel", method = RequestMethod.POST) @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response,@RequestParam(name = "ndbsxmid", required = true) String ndbsxmid) { public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response,@RequestParam(name = "ndbsxmid", required = true) String ndbsxmid) {
//获取年度比赛项目
AnnualCompPoint annualCompPointss = annualCompPointService.getById(ndbsxmid);
//获取队伍的人数
int teamnumber =annualCompPointss.getTeacherNumber();
//获取教师熟练
int teachernumber = annualCompPointss.getTeacherNumber();
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap(); Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) { for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
@ -1077,22 +1089,115 @@ public class AnnualCompPointController extends JeecgController<AnnualCompPoint,
params.setHeadRows(1); params.setHeadRows(1);
params.setNeedSave(true); params.setNeedSave(true);
try { try {
//个人赛直接导入
if(annualCompPointss.getEntryForm().equals("N")) {
List<AnnualCompPointMb> list = ExcelImportUtil.importExcel(file.getInputStream(), AnnualCompPointMb.class, params);
for (int i = 0; i < list.size(); i++) {
QueryWrapper<SysUser> qw = new QueryWrapper<>();
qw.eq("work_no", list.get(i).getStudentcode());
List<SysUser> listsys = sysUserService.list(qw);
if (listsys.size() == 0) {
return Result.error("文件导入失败:第" + (i + 1) + "行学生学号不存在");
}
// 使用 String 的 split 方法将字符串分割成字符串数组
String[] itemsArray = list.get(i).getTeacherName().split("%");
//判断老师个数信息是否正确
if(itemsArray.length>teachernumber){
return Result.error("文件导入失败:第" + (i + 1) + "老师个数信息有误");
}
}
AnnualCompPoint annualCompPoint = annualCompPointService.getById(ndbsxmid);
String annualId = annualCompService.getById(annualCompPoint.getAnnualCompId()).getAnnualid();
String annualName = annualService.query().eq("id", annualId).one().getAnnualName();
for (int k = 0; k < list.size(); k++) {
//生成报名编号
String enrollCode = getEnrollCode(annualName + "GR");
AnnualCompetitionProjectRegistration ar = new AnnualCompetitionProjectRegistration();
ar.setAnnualCompid(ndbsxmid);
ar.setEnrollCode(enrollCode);
ar.setEnrollStatic("2");
ar.setBackinfo(null);
ar.setEntryFormat("0");
ar.setTeamName(null);
annualCompetitionProjectRegistrationService.save(ar);
TeamManagement tm = new TeamManagement();
tm.setEnrollCode(enrollCode);
QueryWrapper<SysUser> qw1 = new QueryWrapper<>();
qw1.eq("work_no", list.get(k).getStudentcode());
List<SysUser> listsys1 = sysUserService.list(qw1);
tm.setUserId(listsys1.get(0).getId());
tm.setCaptain("0");
teamManagementService.save(tm);
//开始处理指导老师数据
//创建指导老师类型的成字符串数组
String[] teachertypes = list.get(k).getTeacherType().split("%");
//创建指导老师姓名的成字符串数组
String[] teacherNames = list.get(k).getTeacherName().split("%");
//创建指导老师学历的成字符串数组
String[] teacherXls = list.get(k).getTeacherXl().split("%");
//创建指导老师职称的成字符串数组
String[] teacherZcs = list.get(k).getTeacherZc().split("%");
//创建指导老师专业的成字符串数组
String[] teacherZys = list.get(k).getTeacherZy().split("%");
//创建指导老师研究方向的成字符串数组
String[] teacherYjfxs = list.get(k).getTeacherYjfx().split("%");
//创建指导老师手机号的成字符串数组
String[] teacherPhone = list.get(k).getTeacherPhone().split("%");
//开始将这些字符串转化成list
List<String> teachertypelist = Arrays.asList(teachertypes);
List<String> teacherNamelist = Arrays.asList(teacherNames);
List<String> teacherXllist = Arrays.asList(teacherXls);
List<String> teacherZclist = Arrays.asList(teacherZcs);
List<String> teacherZysList = Arrays.asList(teacherZys);
List<String> teacherYjfxlist = Arrays.asList(teacherYjfxs);
List<String> teacherPhonelist = Arrays.asList(teacherPhone);
for (int c =0;c<teachernumber;c++){
InstructorSheet is = new InstructorSheet();
is.setEnrollCode(enrollCode);
is.setAnnualCompid(ndbsxmid);
is.setTeacherXl(teacherXllist.get(c));
if (teachertypelist.get(c).equals("指导老师")){
is.setTeacherType(1);
}else if (teachertypelist.get(c).equals("领队老师")){
is.setTeacherType(2);
}
is.setTeacherName(teacherNamelist.get(c));
is.setTeacherZc(teacherZclist.get(c));
is.setTeacherZy(teacherZysList.get(c));
is.setTeacherYjfx(teacherYjfxlist.get(c));
is.setTeacherPhone(teacherPhonelist.get(c));
instructorSheetService.save(is);
}
}
long start = System.currentTimeMillis();
log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
return Result.ok("文件导入成功!数据行数:" + list.size());
} else if (annualCompPointss.getEntryForm().equals("Y")){
List<AnnualCompPointMb> list = ExcelImportUtil.importExcel(file.getInputStream(), AnnualCompPointMb.class, params); List<AnnualCompPointMb> list = ExcelImportUtil.importExcel(file.getInputStream(), AnnualCompPointMb.class, params);
for (int i = 0 ; i < list.size();i++){ for (int i = 0; i < list.size(); i++) {
QueryWrapper<SysUser> qw = new QueryWrapper<>(); QueryWrapper<SysUser> qw = new QueryWrapper<>();
qw.eq("work_no",list.get(i).getStudentcode()); qw.in("work_no", Arrays.asList(list.get(i).getStudentcode().split("%")));
List<SysUser> listsys = sysUserService.list(qw); List<SysUser> listsys = sysUserService.list(qw);
//SysUser sysUser = sysUserService.getUserByName(list.get(i).getStudentcode()); System.out.println(Arrays.asList(list.get(i).getStudentcode().split("%")));
if(listsys.size()==0){ System.out.println(list.get(i).getStudentcode().split("%").length);
return Result.error("文件导入失败:第"+(i+1)+"行学生学号不存在"); if (listsys.size() != list.get(i).getStudentcode().split("%").length) {
return Result.error("文件导入失败:第" + (i + 1) + "行学生学号不存在");
}
// 使用 String 的 split 方法将字符串分割成字符串数组
String[] itemsArray = list.get(i).getTeacherName().split("%");
//判断老师个数信息是否正确
if(itemsArray.length>teachernumber){
return Result.error("文件导入失败:第" + (i + 1) + "老师个数信息有误");
} }
} }
AnnualCompPoint annualCompPoint = annualCompPointService.getById(ndbsxmid); AnnualCompPoint annualCompPoint = annualCompPointService.getById(ndbsxmid);
String annualId = annualCompService.getById(annualCompPoint.getAnnualCompId()).getAnnualid(); String annualId = annualCompService.getById(annualCompPoint.getAnnualCompId()).getAnnualid();
String annualName = annualService.query().eq("id", annualId).one().getAnnualName(); String annualName = annualService.query().eq("id", annualId).one().getAnnualName();
for (int k = 0 ; k < list.size();k++){ for (int k = 0; k < list.size(); k++) {
//生成报名编号 //生成报名编号
String enrollCode = getEnrollCode(annualName + "gr"); String enrollCode = getEnrollCode(annualName + "TD");
AnnualCompetitionProjectRegistration ar = new AnnualCompetitionProjectRegistration(); AnnualCompetitionProjectRegistration ar = new AnnualCompetitionProjectRegistration();
ar.setAnnualCompid(ndbsxmid); ar.setAnnualCompid(ndbsxmid);
ar.setEnrollCode(enrollCode); ar.setEnrollCode(enrollCode);
@ -1101,24 +1206,74 @@ public class AnnualCompPointController extends JeecgController<AnnualCompPoint,
ar.setEntryFormat("0"); ar.setEntryFormat("0");
ar.setTeamName(null); ar.setTeamName(null);
annualCompetitionProjectRegistrationService.save(ar); annualCompetitionProjectRegistrationService.save(ar);
//将学生信息姓名放入list
String[] teaname = list.get(k).getStudentname().split("%");
List<String> teamnamelist =Arrays.asList(teaname);
//将学生的学号放入list
String[] teamworkno = list.get(k).getStudentcode().split("%");
List<String> teamworknolist =Arrays.asList(teamworkno);
for(int a =0;a<teamnumber;a++) {
TeamManagement tm = new TeamManagement(); TeamManagement tm = new TeamManagement();
tm.setEnrollCode(enrollCode); tm.setEnrollCode(enrollCode);
QueryWrapper<SysUser> qw1 = new QueryWrapper<>(); QueryWrapper<SysUser> qw1 = new QueryWrapper<>();
qw1.eq("work_no",list.get(k).getStudentcode()); qw1.eq("work_no",teamworknolist.get(a));
List<SysUser> listsys1 = sysUserService.list(qw1); List<SysUser> listsys1 = sysUserService.list(qw1);
tm.setUserId(listsys1.get(0).getId()); tm.setUserId(listsys1.get(0).getId());
if (a==0) {
tm.setCaptain("0"); tm.setCaptain("0");
}
teamManagementService.save(tm); teamManagementService.save(tm);
} }
//update-begin-author:taoyan date:20190528 for:批量插入数据 //开始处理指导老师数据
//创建指导老师类型的成字符串数组
String[] teachertypes = list.get(k).getTeacherType().split("%");
//创建指导老师姓名的成字符串数组
String[] teacherNames = list.get(k).getTeacherName().split("%");
//创建指导老师学历的成字符串数组
String[] teacherXls = list.get(k).getTeacherXl().split("%");
//创建指导老师职称的成字符串数组
String[] teacherZcs = list.get(k).getTeacherZc().split("%");
//创建指导老师专业的成字符串数组
String[] teacherZys = list.get(k).getTeacherZy().split("%");
//创建指导老师研究方向的成字符串数组
String[] teacherYjfxs = list.get(k).getTeacherYjfx().split("%");
//创建指导老师手机号的成字符串数组
String[] teacherPhone = list.get(k).getTeacherPhone().split("%");
//开始将这些字符串转化成list
List<String> teachertypelist = Arrays.asList(teachertypes);
List<String> teacherNamelist = Arrays.asList(teacherNames);
List<String> teacherXllist = Arrays.asList(teacherXls);
List<String> teacherZclist = Arrays.asList(teacherZcs);
List<String> teacherZysList = Arrays.asList(teacherZys);
List<String> teacherYjfxlist = Arrays.asList(teacherYjfxs);
List<String> teacherPhonelist = Arrays.asList(teacherPhone);
for (int c =0;c<teachernumber;c++){
InstructorSheet is = new InstructorSheet();
is.setEnrollCode(enrollCode);
is.setAnnualCompid(ndbsxmid);
is.setTeacherXl(teacherXllist.get(c));
if (teachertypelist.get(c).equals("指导老师")){
is.setTeacherType(1);
}else if (teachertypelist.get(c).equals("领队老师")){
is.setTeacherType(2);
}
is.setTeacherName(teacherNamelist.get(c));
is.setTeacherZc(teacherZclist.get(c));
is.setTeacherZy(teacherZysList.get(c));
is.setTeacherYjfx(teacherYjfxlist.get(c));
is.setTeacherPhone(teacherPhonelist.get(c));
instructorSheetService.save(is);
}
}
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
//400条 saveBatch消耗时间1592毫秒 循环插入消耗时间1947毫秒
//1200条 saveBatch消耗时间3687毫秒 循环插入消耗时间5212毫秒
log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒"); log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
//update-end-author:taoyan date:20190528 for:批量插入数据
return Result.ok("文件导入成功!数据行数:" + list.size()); return Result.ok("文件导入成功!数据行数:" + list.size());
}
} catch (Exception e) { } catch (Exception e) {
//update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示
String msg = e.getMessage(); String msg = e.getMessage();
log.error(msg, e); log.error(msg, e);
if(msg!=null && msg.indexOf("Duplicate entry")>=0){ if(msg!=null && msg.indexOf("Duplicate entry")>=0){
@ -1126,7 +1281,6 @@ public class AnnualCompPointController extends JeecgController<AnnualCompPoint,
}else{ }else{
return Result.error("文件导入失败:" + e.getMessage()); return Result.error("文件导入失败:" + e.getMessage());
} }
//update-end-author:taoyan date:20211124 for: 导入数据重复增加提示
} finally { } finally {
try { try {
file.getInputStream().close(); file.getInputStream().close();
@ -1137,6 +1291,8 @@ public class AnnualCompPointController extends JeecgController<AnnualCompPoint,
} }
return Result.error("文件导入失败!"); return Result.error("文件导入失败!");
} }
/** /**
* 2.3生成全局唯一报名编号 * 2.3生成全局唯一报名编号
* @param type * @param type

@ -39,4 +39,35 @@ public class AnnualCompPointMb implements Serializable {
@Excel(name = "学生学号", width = 15) @Excel(name = "学生学号", width = 15)
@TableField(exist = false) @TableField(exist = false)
private String studentcode; private String studentcode;
/**指导老师类型*/
@Excel(name = "指导老师类型", width = 15, dicCode = "teacher_type")
@ApiModelProperty(value = "指导老师类型")
private java.lang.String teacherType;
/**指导老师姓名*/
@Excel(name = "指导老师姓名", width = 15)
@ApiModelProperty(value = "指导老师姓名")
private java.lang.String teacherName;
/**报名编号*/
@ApiModelProperty(value = "报名编号")
private java.lang.String enrollCode;
@Excel(name = "学历", width = 15)
@ApiModelProperty(value = "学历")
private java.lang.String teacherXl;
@Excel(name = "职称", width = 15)
@ApiModelProperty(value = "职称")
private java.lang.String teacherZc;
@Excel(name = "专业", width = 15)
@ApiModelProperty(value = "专业")
private java.lang.String teacherZy;
@Excel(name = "研究方向", width = 15)
@ApiModelProperty(value = "研究方向")
private java.lang.String teacherYjfx;
@Excel(name = "手机号", width = 15)
@ApiModelProperty(value = "手机号")
private java.lang.String teacherPhone;
} }

Loading…
Cancel
Save