add:社团管理-导入
This commit is contained in:
@@ -45,6 +45,9 @@ public class LawsClub implements Serializable {
|
||||
@Excel(name = "节点类型", width = 20)
|
||||
private String nodeType;
|
||||
|
||||
@ApiModelProperty(value = "编号")
|
||||
private String number;
|
||||
|
||||
@ApiModelProperty(value = "社团名称")
|
||||
@Excel(name = "社团名称", width = 20)
|
||||
private String clubName;
|
||||
|
||||
+118
-30
@@ -10,26 +10,32 @@ import com.jero.common.api.vo.ResultCommon;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.base.controller.JeroController;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.common.util.CommonUtils;
|
||||
import com.jero.common.util.PasswordUtil;
|
||||
import com.jero.common.util.RedisUtil;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.common.util.*;
|
||||
import com.jero.modules.laws.club.entity.*;
|
||||
import com.jero.modules.laws.club.mapper.LawsClubMapper;
|
||||
import com.jero.modules.laws.club.service.*;
|
||||
import com.jero.modules.laws.club.vo.LawsClubMeetingExcel;
|
||||
import com.jero.modules.laws.club.vo.LawsClubTreeNodeModel;
|
||||
import com.jero.modules.laws.club.vo.excel.LawsClubExcel;
|
||||
import com.jero.modules.laws.club.vo.excel.LawsClubJoinTeamExcel;
|
||||
import com.jero.modules.laws.club.vo.excel.LawsClubMeetingImportExcel;
|
||||
import com.jero.modules.laws.club.vo.excel.LawsClubResearchInformationExcel;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
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.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
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 java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -519,10 +525,10 @@ public class LawsClubServiceImpl extends ServiceImpl<LawsClubMapper, LawsClub> i
|
||||
|
||||
@Override
|
||||
public ModelAndView exportTemplate(HttpServletRequest request) {
|
||||
List<LawsClub> excelList = new ArrayList<>();
|
||||
List<LawsClubExcel> excelList = new ArrayList<>();
|
||||
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
||||
mv.addObject(JeroController.FILE_NAME, "社团管理");
|
||||
mv.addObject(JeroController.CLASS, LawsClub.class);
|
||||
mv.addObject(JeroController.CLASS, LawsClubExcel.class);
|
||||
ExportParams exportParams = new ExportParams("社团管理", "社团管理");
|
||||
mv.addObject(JeroController.PARAMS, exportParams);
|
||||
mv.addObject(NormalExcelConstants.DATA_LIST, excelList);
|
||||
@@ -531,29 +537,111 @@ public class LawsClubServiceImpl extends ServiceImpl<LawsClubMapper, LawsClub> i
|
||||
|
||||
@Override
|
||||
public Result<?> importExcel(HttpServletRequest request) {
|
||||
return null;
|
||||
// MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
// List<String> errorMessageList = new ArrayList<>();
|
||||
// List<SysDepart> listSysDeparts = null;
|
||||
// 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 {
|
||||
//
|
||||
// }catch (Exception e) {
|
||||
// log.error(e.getMessage(),e);
|
||||
// return Result.error("文件导入失败:"+e.getMessage());
|
||||
// } finally {
|
||||
// try {
|
||||
// file.getInputStream().close();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
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(1);
|
||||
params.setHeadRows(1);
|
||||
params.setNeedSave(true);
|
||||
try {
|
||||
List<LawsClubExcel> excelList = ExcelImportUtil.importExcel(file.getInputStream(), LawsClubExcel.class, params);
|
||||
if (CollectionUtils.isEmpty(excelList)) {
|
||||
throw new JeroBootException("没有数据可导入");
|
||||
}
|
||||
StringBuilder msg = new StringBuilder();
|
||||
for (LawsClubExcel lawsClubExcel : excelList) {
|
||||
String parentId = lawsClubExcel.getParentId();
|
||||
String nodeType = lawsClubExcel.getNodeType();
|
||||
String clubName = lawsClubExcel.getClubName();
|
||||
List<LawsClubMeetingImportExcel> lawsClubMeetings = lawsClubExcel.getLawsClubMeetings();
|
||||
List<LawsClubJoinTeamExcel> lawsClubJoinTeamList = lawsClubExcel.getLawsClubJoinTeamList();
|
||||
List<LawsClubResearchInformationExcel> lawsClubResearchInformations = lawsClubExcel.getLawsClubResearchInformations();
|
||||
LawsClub club = this.getOne(new LambdaQueryWrapper<LawsClub>().eq(LawsClub::getNodeType, parentId));
|
||||
StringBuilder msgSub = new StringBuilder();
|
||||
if (StringUtils.isBlank(parentId)) {
|
||||
// 如果上级节点为空,添加错误消息
|
||||
msgSub.append("第").append(excelList.indexOf(lawsClubExcel) + 4).append("行上级节点不能为空;");
|
||||
} else {
|
||||
// 如果上级节点不为空,检查是否存在对应的节点
|
||||
if (Objects.isNull(club)) {
|
||||
msgSub.append("第").append(excelList.indexOf(lawsClubExcel) + 4).append("行上级节点不存在,请重新输入;");
|
||||
}else {
|
||||
lawsClubExcel.setParentId(club.getId());
|
||||
}
|
||||
}
|
||||
if (StringUtils.isBlank(nodeType)) {
|
||||
msgSub.append("第").append(excelList.indexOf(lawsClubExcel) + 4).append("行节点类型不能为空;");
|
||||
}
|
||||
// 检查是否存在其他信息
|
||||
boolean hasAdditionalInfo = !CollectionUtils.isEmpty(lawsClubMeetings) ||
|
||||
!CollectionUtils.isEmpty(lawsClubJoinTeamList) ||
|
||||
!CollectionUtils.isEmpty(lawsClubResearchInformations);
|
||||
// 如果存在其他信息并且社团名称为空,则添加错误消息
|
||||
if (hasAdditionalInfo && StringUtils.isBlank(clubName)) {
|
||||
msgSub.append("第").append(excelList.indexOf(lawsClubExcel) + 4).append("行社团名称不能为空;");
|
||||
}
|
||||
if (StringUtils.isNotBlank(lawsClubExcel.getContactNumber())) {
|
||||
String contactNumber = lawsClubExcel.getContactNumber();
|
||||
if (!contactNumber.matches("^(1[3-9]\\d{9})$|^(0\\d{2,3}-?\\d{7,8})$")) {
|
||||
msgSub.append("第").append(excelList.indexOf(lawsClubExcel) + 4).append("行联系方式格式不正确;");
|
||||
}else {
|
||||
// 联系方式如果不为空,且格式正确,进行加密
|
||||
String encrypt = PasswordUtil.encrypt(contactNumber);
|
||||
lawsClubExcel.setContactNumber(encrypt);
|
||||
}
|
||||
}
|
||||
if(!StringUtils.isEmpty(msgSub.toString())){
|
||||
msg.append(msgSub).append("</br>");
|
||||
}
|
||||
if(!StringUtils.isEmpty(msg.toString())){
|
||||
return Result.error(msg.toString());
|
||||
}
|
||||
LawsClub lawsClub = new LawsClub();
|
||||
BeanUtils.copyProperties(lawsClubExcel, lawsClub);
|
||||
// 转换 LawsClubJoinTeamExcel -> LawsClubJoinTeam
|
||||
List<LawsClubJoinTeam> lawsClubJoinTeamsList = Optional.ofNullable(lawsClubExcel.getLawsClubJoinTeamList())
|
||||
.orElse(Collections.emptyList()).stream().map(this::convertToJoinTeam).collect(Collectors.toList());
|
||||
// 转换 LawsClubMeetingImportExcel -> LawsClubMeetingImport
|
||||
List<LawsClubMeeting> lawsClubMeetingsList = Optional.ofNullable(lawsClubExcel.getLawsClubMeetings())
|
||||
.orElse(Collections.emptyList()).stream().map(this::convertToMeetingImport).collect(Collectors.toList());
|
||||
// 转换 LawsClubResearchInformationExcel -> LawsClubResearchInformation
|
||||
List<LawsClubResearchInformation> lawsClubResearchInformationsList = Optional.ofNullable(lawsClubExcel.getLawsClubResearchInformations())
|
||||
.orElse(Collections.emptyList()).stream().map(this::convertToResearchInformation).collect(Collectors.toList());
|
||||
save(lawsClub);
|
||||
saveAssociationTable(lawsClub,lawsClubJoinTeamsList,null,lawsClubMeetingsList,lawsClubResearchInformationsList,null);
|
||||
}
|
||||
}catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
return Result.error("文件导入失败:"+e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
file.getInputStream().close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.OK(ResultCommon.OK);
|
||||
}
|
||||
|
||||
private LawsClubJoinTeam convertToJoinTeam(LawsClubJoinTeamExcel joinTeamExcel) {
|
||||
LawsClubJoinTeam joinTeam = new LawsClubJoinTeam();
|
||||
BeanUtils.copyProperties(joinTeamExcel, joinTeam);
|
||||
return joinTeam;
|
||||
}
|
||||
|
||||
private LawsClubMeeting convertToMeetingImport(LawsClubMeetingImportExcel meetingImportExcel) {
|
||||
LawsClubMeeting meetingImport = new LawsClubMeeting();
|
||||
BeanUtils.copyProperties(meetingImportExcel, meetingImport);
|
||||
return meetingImport;
|
||||
}
|
||||
|
||||
private LawsClubResearchInformation convertToResearchInformation(LawsClubResearchInformationExcel researchInformationExcel) {
|
||||
LawsClubResearchInformation researchInformation = new LawsClubResearchInformation();
|
||||
BeanUtils.copyProperties(researchInformationExcel, researchInformation);
|
||||
return researchInformation;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.jero.modules.laws.club.vo.excel;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
import org.jeecgframework.poi.excel.annotation.ExcelCollection;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class LawsClubExcel {
|
||||
|
||||
@ApiModelProperty(value = "上级节点id")
|
||||
@Excel(name = "上级节点", width = 20)
|
||||
private String parentId;
|
||||
|
||||
@ApiModelProperty(value = "节点类型")
|
||||
@Excel(name = "节点类型", width = 20)
|
||||
private String nodeType;
|
||||
|
||||
@ApiModelProperty(value = "社团名称")
|
||||
@Excel(name = "社团名称", width = 20)
|
||||
private String clubName;
|
||||
|
||||
@ApiModelProperty(value = "社团地址")
|
||||
@Excel(name = "社团地址", width = 20)
|
||||
private String clubAddress;
|
||||
|
||||
@ApiModelProperty(value = "社团联系人")
|
||||
@Excel(name = "社团联系人", width = 20)
|
||||
private String clubContact;
|
||||
|
||||
@ApiModelProperty(value = "联系电话")
|
||||
@Excel(name = "联系电话", width = 20)
|
||||
private String contactNumber;
|
||||
|
||||
@ApiModelProperty(value = "入团信息列表数据")
|
||||
@ExcelCollection(name = "入团信息")
|
||||
private List<LawsClubJoinTeamExcel> lawsClubJoinTeamList;
|
||||
|
||||
@ApiModelProperty(value = "参会信息列表数据")
|
||||
@ExcelCollection(name = "参会信息")
|
||||
private List<LawsClubMeetingImportExcel> lawsClubMeetings;
|
||||
|
||||
@ApiModelProperty(value = "征集调研信息列表数据")
|
||||
@ExcelCollection(name = "征集调研信息")
|
||||
private List<LawsClubResearchInformationExcel> lawsClubResearchInformations;
|
||||
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.jero.modules.laws.club.vo.excel;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
@Data
|
||||
public class LawsClubJoinTeamExcel implements Serializable {
|
||||
|
||||
@ApiModelProperty(value = "入团日期")
|
||||
@Excel(name = "入团日期", width = 20, format = "yyyy-MM-dd")
|
||||
private Date joinDate;
|
||||
|
||||
@ApiModelProperty(value = "部门id")
|
||||
@Excel(name = "部门名称", width = 20)
|
||||
private String departId;
|
||||
|
||||
@ApiModelProperty(value = "申请人的id")
|
||||
@Excel(name = "申请人", width = 20)
|
||||
private String proposerId;
|
||||
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.jero.modules.laws.club.vo.excel;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.jero.common.aspect.annotation.Dict;
|
||||
import com.jero.modules.laws.club.entity.LawsClubMeetingMember;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Data
|
||||
public class LawsClubMeetingImportExcel implements Serializable {
|
||||
|
||||
@Excel(name = "会议名称", width = 20)
|
||||
private String meetingName;
|
||||
|
||||
@Excel(name = "会议日期", width = 20, format = "yyyy-MM-dd")
|
||||
private Date meetingDate;
|
||||
|
||||
@Excel(name = "会议费用", width = 20)
|
||||
private String meetingCost;
|
||||
|
||||
@Excel(name = "线下/线上地点", width = 20)
|
||||
private String meetingPlace;
|
||||
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.jero.modules.laws.club.vo.excel;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.jero.common.aspect.annotation.Dict;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class LawsClubResearchInformationExcel implements Serializable {
|
||||
|
||||
@Excel(name = "名称", width = 20)
|
||||
private String researchName;
|
||||
|
||||
@Excel(name = "内容", width = 20)
|
||||
private String researchContent;
|
||||
|
||||
@Excel(name = "接收日期", width = 20, format = "yyyy-MM-dd")
|
||||
private Date receiveDate;
|
||||
|
||||
@Excel(name = "截止日期", width = 20, format = "yyyy-MM-dd")
|
||||
private Date deadlineDate;
|
||||
}
|
||||
Reference in New Issue
Block a user