模板导入报名

main
Gitea 1 year ago
parent 786dc14775
commit 0701107917
  1. 140
      jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/annualCompPoint/controller/AnnualCompPointController.java
  2. 42
      jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/annualCompPoint/entity/AnnualCompPointMb.java

@ -1,5 +1,6 @@
package org.jeecg.modules.demo.annualCompPoint.controller;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@ -14,15 +15,23 @@ import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.config.JeecgBaseConfig;
import org.jeecg.modules.demo.anncomgrotopp.entity.AnnComGroTopP;
import org.jeecg.modules.demo.anncomgrotopp.service.IAnnComGroTopPService;
import org.jeecg.modules.demo.annual.service.IAnnualService;
import org.jeecg.modules.demo.annualCompPoint.entity.AnnualCompPoint;
import org.jeecg.modules.demo.annualCompPoint.entity.AnnualCompPointMb;
import org.jeecg.modules.demo.annualCompPoint.service.IAnnualCompPointService;
import org.jeecg.modules.demo.annualcomp.entity.AnnualComp;
import org.jeecg.modules.demo.annualcomp.service.IAnnualCompService;
import org.jeecg.modules.demo.annualcompaward.entity.AnnualCompAward;
import org.jeecg.modules.demo.annualcompaward.service.IAnnualCompAwardService;
import org.jeecg.modules.demo.annualcompetitionprojectregistration.entity.AnnualCompetitionProjectRegistration;
import org.jeecg.modules.demo.annualcompetitionprojectregistration.entity.TeamManagement;
import org.jeecg.modules.demo.annualcompetitionprojectregistration.service.IAnnualCompetitionProjectRegistrationService;
import org.jeecg.modules.demo.annualcompetitionprojectregistration.service.ITeamManagementService;
import org.jeecg.modules.demo.awardpersion.entity.AwardPersion;
import org.jeecg.modules.demo.awardpersion.entity.AwardPersionMb;
import org.jeecg.modules.demo.awardpersion.entity.AwardPersionOptions;
import org.jeecg.modules.demo.awardpersion.service.IAwardPersionService;
import org.jeecg.modules.demo.comp.entity.Comp;
@ -31,15 +40,28 @@ import org.jeecg.modules.demo.expscore.entity.ExpScore;
import org.jeecg.modules.demo.expscore.service.IExpScoreService;
import org.jeecg.modules.demo.scorepersion.entity.ScorePersion;
import org.jeecg.modules.demo.scorepersion.service.IScorePersionService;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.service.ISysUserService;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -70,6 +92,16 @@ public class AnnualCompPointController extends JeecgController<AnnualCompPoint,
private IExpScoreService expScoreService;
@Autowired
private IAnnComGroTopPService annComGroTopPService;
@Autowired
private ISysUserService sysUserService;
@Autowired
private IAnnualCompetitionProjectRegistrationService annualCompetitionProjectRegistrationService;
@Autowired
private ITeamManagementService teamManagementService;
@Autowired
private IAnnualService annualService;
@Resource
private JeecgBaseConfig jeecgBaseConfig;
/**
* 分页列表查询
@ -622,6 +654,31 @@ public class AnnualCompPointController extends JeecgController<AnnualCompPoint,
return super.exportXls(request, annualCompPoint, AnnualCompPoint.class, "年度比赛项目管理");
}
/**
* 导出excel模板
*
*/
//@RequiresPermissions("awardpersion:award_persion:exportXls")
@RequestMapping(value = "/exportXlsMb")
public ModelAndView exportXlsMb(HttpServletRequest request, AnnualCompPoint annualCompPoint) {
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
// Step.2 获取导出数据
List<AnnualCompPointMb> exportList = new ArrayList<>();
// Step.3 AutoPoi 导出Excel
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
//此处设置的filename无效 ,前端会重更新设置一下
mv.addObject(NormalExcelConstants.FILE_NAME, "报名模板");
mv.addObject(NormalExcelConstants.CLASS, AnnualCompPointMb.class);
//update-begin--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置--------------------
ExportParams exportParams=new ExportParams("报名模板" + "报表", "导出人:" + sysUser.getRealname(), "报名模板");
exportParams.setImageBasePath(jeecgBaseConfig.getPath().getUpload());
//update-end--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置----------------------
mv.addObject(NormalExcelConstants.PARAMS,exportParams);
mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
return mv;
}
/**
* 通过excel导入数据
*
@ -629,10 +686,87 @@ public class AnnualCompPointController extends JeecgController<AnnualCompPoint,
* @param response
* @return
*/
@RequiresPermissions("annualCompPoint:annual_comp_point:importExcel")
//@RequiresPermissions("annualCompPoint:annual_comp_point:importExcel")
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
return super.importExcel(request, response, AnnualCompPoint.class);
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response,@RequestParam(name = "ndbsxmid", required = true) String ndbsxmid) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
// 获取上传文件对象
MultipartFile file = entity.getValue();
ImportParams params = new ImportParams();
params.setTitleRows(2);
params.setHeadRows(1);
params.setNeedSave(true);
try {
List<AnnualCompPointMb> list = ExcelImportUtil.importExcel(file.getInputStream(), AnnualCompPointMb.class, params);
for (int i = 0 ; i < list.size();i++){
SysUser sysUser = sysUserService.getUserByName(list.get(i).getStudentcode());
if(sysUser==null){
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);
tm.setUserId(sysUserService.getUserByName(list.get(k).getStudentcode()).getId());
tm.setCaptain("0");
teamManagementService.save(tm);
}
//update-begin-author:taoyan date:20190528 for:批量插入数据
long start = System.currentTimeMillis();
//400条 saveBatch消耗时间1592毫秒 循环插入消耗时间1947毫秒
//1200条 saveBatch消耗时间3687毫秒 循环插入消耗时间5212毫秒
log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
//update-end-author:taoyan date:20190528 for:批量插入数据
return Result.ok("文件导入成功!数据行数:" + list.size());
} catch (Exception e) {
//update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示
String msg = e.getMessage();
log.error(msg, e);
if(msg!=null && msg.indexOf("Duplicate entry")>=0){
return Result.error("文件导入失败:有重复数据!");
}else{
return Result.error("文件导入失败:" + e.getMessage());
}
//update-end-author:taoyan date:20211124 for: 导入数据重复增加提示
} finally {
try {
file.getInputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return Result.error("文件导入失败!");
}
/**
* 2.3生成全局唯一报名编号
* @param type
* @return
*/
public String getEnrollCode(String type){
String enrollCode = type;
String uuid = IdUtil.randomUUID().replaceAll("-","");;
enrollCode += uuid.substring(0, 16);
List<AnnualCompetitionProjectRegistration> list = annualCompetitionProjectRegistrationService.query().eq("enroll_code", enrollCode).list();
if (list == null || list.size() == 0)
return enrollCode.toUpperCase();
else
return getEnrollCode(type);
}
/**

@ -0,0 +1,42 @@
package org.jeecg.modules.demo.annualCompPoint.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.jeecg.common.aspect.annotation.Dict;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
/**
* @Description: 模板
* @Author: jeecg-boot
* @Date: 2023-10-31
* @Version: V1.0
*/
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="", description="模板")
public class AnnualCompPointMb implements Serializable {
private static final long serialVersionUID = 1L;
/**学生姓名*/
@Excel(name = "学生姓名", width = 15)
@TableField(exist = false)
private String studentname;
/**学生学号*/
@Excel(name = "学生学号", width = 15)
@TableField(exist = false)
private String studentcode;
}
Loading…
Cancel
Save