add:社团管理,入团信息,会议信息,在研信息导出模板;

update:社团管理,入团信息,在研信息导入接口
This commit is contained in:
sunzheng
2024-09-13 18:17:12 +08:00
parent 1c8005c218
commit 14818f4854
21 changed files with 997 additions and 269 deletions
@@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
@@ -180,12 +181,12 @@ public class LawsClubController extends JeroController<LawsClub, ILawsClubServic
/**
* 模板下载
*/
@AutoLog(value = "社团管理-导出征集调研意见")
@ApiOperation(value="社团管理-导出征集调研意见", notes="社团管理-导出征集调研意见")
@AutoLog(value = "社团管理-模板下载")
@ApiOperation(value="社团管理-模板下载", notes="社团管理-模板下载")
@GetMapping(value = "/exportTemplate")
@RequiresPermissions("clubManagement:clubManagement:templateDownload")
public ModelAndView exportTemplate(HttpServletRequest request) {
return lawsClubService.exportTemplate(request);
public void exportTemplate(HttpServletRequest request, HttpServletResponse response) {
lawsClubService.exportTemplate(request,response);
}
/**
@@ -0,0 +1,53 @@
package com.jero.modules.laws.club.controller;
import com.jero.common.api.vo.Result;
import com.jero.common.aspect.annotation.AutoLog;
import com.jero.modules.laws.club.service.ILawsClubJoinTeamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* <p>
* 社团管理-入团信息表 前端控制器
* </p>
*
* @author sz
* @since 2024-08-29
*/
@Api(tags="社团管理-入团信息表")
@RestController
@RequestMapping("/club/joinTeam")
@Slf4j
public class LawsClubJoinTeamController {
@Resource
private ILawsClubJoinTeamService lawsClubJoinTeamService;
/**
* 模板下载
*/
@AutoLog(value = "社团管理-入团信息表-模板下载")
@ApiOperation(value="社团管理-入团信息表-模板下载", notes="社团管理-入团信息表-模板下载")
@GetMapping(value = "/exportTemplate")
// @RequiresPermissions("clubManagement:clubManagement:templateDownload")
public void exportTemplate(HttpServletRequest request, HttpServletResponse response) {
lawsClubJoinTeamService.exportTemplate(request,response);
}
/**
* 导入
*/
@AutoLog(value = "社团管理-入团信息表-导入")
@ApiOperation(value="社团管理-入团信息表-导入", notes="社团管理-入团信息表-导入")
@PostMapping(value = "/importExcel")
// @RequiresPermissions("clubManagement:clubManagement:import")
public Result<?> excelimport(HttpServletRequest request) {
return lawsClubJoinTeamService.importExcel(request);
}
}
@@ -0,0 +1,56 @@
package com.jero.modules.laws.club.controller;
import com.jero.common.api.vo.Result;
import com.jero.common.aspect.annotation.AutoLog;
import com.jero.modules.laws.club.service.ILawsClubMeetingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* <p>
* 社团管理-参会信息表 前端控制器
* </p>
*
* @author sz
* @since 2024-08-29
*/
@Api(tags="社团管理-参会信息表")
@RestController
@RequestMapping("/club/meeting")
@Slf4j
public class LawsClubMeetingController {
@Resource
private ILawsClubMeetingService lawsClubMeetingService;
/**
* 模板下载
*/
@AutoLog(value = "社团管理-参会信息表-模板下载")
@ApiOperation(value="社团管理-参会信息表-模板下载", notes="社团管理-参会信息表-模板下载")
@GetMapping(value = "/exportTemplate")
// @RequiresPermissions("clubManagement:clubManagement:templateDownload")
public void exportTemplate(HttpServletRequest request, HttpServletResponse response) {
lawsClubMeetingService.exportTemplate(request,response);
}
/**
* 导入
*/
@AutoLog(value = "社团管理-参会信息表-导入")
@ApiOperation(value="社团管理-参会信息表-导入", notes="社团管理-参会信息表-导入")
@PostMapping(value = "/importExcel")
// @RequiresPermissions("clubManagement:clubManagement:import")
public Result<?> excelimport(HttpServletRequest request) {
return lawsClubMeetingService.importExcel(request);
}
}
@@ -0,0 +1,56 @@
package com.jero.modules.laws.club.controller;
import com.jero.common.api.vo.Result;
import com.jero.common.aspect.annotation.AutoLog;
import com.jero.modules.laws.club.service.ILawsClubResearchInformationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* <p>
* 社团管理-征集调研信息表 前端控制器
* </p>
*
* @author sz
* @since 2024-08-29
*/
@Api(tags="社团管理-征集调研信息表")
@RestController
@RequestMapping("/club/researchInformation")
@Slf4j
public class LawsClubResearchInformationController {
@Resource
private ILawsClubResearchInformationService lawsClubResearchInformationService;
/**
* 模板下载
*/
@AutoLog(value = "社团管理-征集调研信息表-模板下载")
@ApiOperation(value="社团管理-征集调研信息表-模板下载", notes="社团管理-征集调研信息表-模板下载")
@GetMapping(value = "/exportTemplate")
// @RequiresPermissions("clubManagement:clubManagement:templateDownload")
public void exportTemplate(HttpServletRequest request, HttpServletResponse response) {
lawsClubResearchInformationService.exportTemplate(request,response);
}
/**
* 导入
*/
@AutoLog(value = "社团管理-征集调研信息表-导入")
@ApiOperation(value="社团管理-征集调研信息表-导入", notes="社团管理-征集调研信息表-导入")
@PostMapping(value = "/importExcel")
// @RequiresPermissions("clubManagement:clubManagement:import")
public Result<?> excelimport(HttpServletRequest request) {
return lawsClubResearchInformationService.importExcel(request);
}
}
@@ -0,0 +1,28 @@
package com.jero.modules.laws.club.enums;
public enum FieldTypeEnum {
TEXT_INPUT("文本输入","1","文本输入"),
DATE_INPUT("日期输入","2","日期输入"),
TEXT_INPUT_NAME("文本输入,姓名(工号)","3","文本输入,姓名(工号)")
;
final String name;
final String value;
final String description;
FieldTypeEnum(String name, String value, String description) {
this.name = name;
this.value = value;
this.description = description;
}
public String getValue() {
return value;
}
public String getDescription() {
return description;
}
}
@@ -1,7 +1,10 @@
package com.jero.modules.laws.club.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.jero.common.api.vo.Result;
import com.jero.modules.laws.club.entity.LawsClubJoinTeam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* <p>
@@ -12,4 +15,8 @@ import com.jero.modules.laws.club.entity.LawsClubJoinTeam;
* @since 2024-08-29
*/
public interface ILawsClubJoinTeamService extends IService<LawsClubJoinTeam> {
void exportTemplate(HttpServletRequest request, HttpServletResponse response);
Result<?> importExcel(HttpServletRequest request);
}
@@ -1,7 +1,10 @@
package com.jero.modules.laws.club.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.jero.common.api.vo.Result;
import com.jero.modules.laws.club.entity.LawsClubMeeting;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* <p>
@@ -13,4 +16,7 @@ import com.jero.modules.laws.club.entity.LawsClubMeeting;
*/
public interface ILawsClubMeetingService extends IService<LawsClubMeeting> {
void exportTemplate(HttpServletRequest request, HttpServletResponse response);
Result<?> importExcel(HttpServletRequest request);
}
@@ -1,7 +1,10 @@
package com.jero.modules.laws.club.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.jero.common.api.vo.Result;
import com.jero.modules.laws.club.entity.LawsClubResearchInformation;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* <p>
@@ -13,4 +16,7 @@ import com.jero.modules.laws.club.entity.LawsClubResearchInformation;
*/
public interface ILawsClubResearchInformationService extends IService<LawsClubResearchInformation> {
void exportTemplate(HttpServletRequest request, HttpServletResponse response);
Result<?> importExcel(HttpServletRequest request);
}
@@ -1,5 +1,6 @@
package com.jero.modules.laws.club.service;
import cn.hutool.http.HttpResponse;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.jero.common.api.vo.Result;
@@ -7,6 +8,7 @@ import com.jero.modules.laws.club.entity.LawsClub;
import com.jero.modules.laws.club.vo.LawsClubTreeNodeModel;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
@@ -35,7 +37,7 @@ public interface ILawsClubService extends IService<LawsClub> {
ModelAndView exportresearchXls(LawsClub lawsClub, HttpServletRequest request);
ModelAndView exportTemplate(HttpServletRequest request);
void exportTemplate(HttpServletRequest request, HttpServletResponse response);
Result<?> importExcel(HttpServletRequest request);
@@ -1,12 +1,44 @@
package com.jero.modules.laws.club.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jero.common.api.vo.Result;
import com.jero.common.exception.JeroBootException;
import com.jero.common.system.vo.DictModel;
import com.jero.modules.laws.club.entity.LawsClubJoinTeam;
import com.jero.modules.laws.club.mapper.LawsClubJoinTeamMapper;
import com.jero.modules.laws.club.service.ILawsClubJoinTeamService;
import com.jero.modules.laws.club.utils.ExcelUtil;
import com.jero.modules.laws.club.vo.excel.LawsClubJoinTeamExcel;
import com.jero.modules.system.entity.SysDepart;
import com.jero.modules.system.entity.SysUser;
import com.jero.modules.system.service.ISysDepartService;
import com.jero.modules.system.service.ISysDictService;
import com.jero.modules.system.service.ISysUserService;
import com.jero.modules.tag.entity.LawsTag;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* <p>
@@ -18,4 +50,144 @@ import javax.annotation.Resource;
*/
@Service
public class LawsClubJoinTeamServiceImpl extends ServiceImpl<LawsClubJoinTeamMapper, LawsClubJoinTeam> implements ILawsClubJoinTeamService {
@Resource
private ISysUserService sysUserService;
@Resource
private ISysDepartService sysDepartService;
@Resource
private ISysDictService sysDictService;
@Override
@SneakyThrows
public void exportTemplate(HttpServletRequest request, HttpServletResponse response) {
// 创建一个Excel工作簿
String describe = "填写说明:\n" +
"1.所有带星号的为必填\n" +
"2.导入数据从第四行开始,第一行为表头,第二行为填写说明,第三行为示例。第四行才是正式数据\n" +
"3.社团名称需要与系统中的社团名称匹配。";
String fieldTxts = "入团日期,社团职务担任者,入团经费,社团简介,部门名称,专业模块,申请人,秘书处,联系人,备注";
String mustInputFlags = "no,no,no,no,no,no,no,no,no,no";
String fieldTypeLists = "2,1,1,1,1,1,1,1,1,1"; // 1代表是文本输入类型 2代表日期输入
List<LawsTag> lawsTags = ExcelUtil.createLawsTags(fieldTxts, mustInputFlags, fieldTypeLists);
try (Workbook workbook = ExcelUtil.createWorkBookWithLawsTags(lawsTags, "入团信息", describe);
OutputStream out = response.getOutputStream()) {
// 设置HTTP响应头
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("UTF-8"); // 确保响应流使用UTF-8编码
// 处理文件名乱码问题
String encodedFileName = URLEncoder.encode("基本信息", StandardCharsets.UTF_8.name()).replace("+", "%20");
response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encodedFileName + ".xls");
// 写入Excel并输出
workbook.write(out);
out.flush();
} catch (IOException e) {
log.error("导出Excel失败", e);
}
}
@Override
public Result<?> importExcel(HttpServletRequest request) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
List<LawsClubJoinTeam> lawsClubJoinTeamList = new ArrayList<>();
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
MultipartFile file = entity.getValue();// 获取上传文件对象
try {
ImportParams params = new ImportParams();
params.setNeedSave(true);
List<LawsClubJoinTeamExcel> excelList = ExcelImportUtil.importExcel(file.getInputStream(), LawsClubJoinTeamExcel.class, params);
excelList = excelList.stream().skip(2).filter(item -> !Objects.isNull(item)).collect(Collectors.toList());
if (CollectionUtils.isEmpty(excelList)) {
throw new JeroBootException("没有数据可导入");
}
StringBuilder msg = validateExcelData(excelList); // 校验数据
if (StringUtils.isNotEmpty(msg.toString())) {
return Result.error(msg.toString());
}
// 保存数据
for (LawsClubJoinTeamExcel lawsClubJoinTeamExcel : excelList) {
LawsClubJoinTeam lawsClubJoinTeam = new LawsClubJoinTeam();
BeanUtils.copyProperties(lawsClubJoinTeamExcel, lawsClubJoinTeam);
lawsClubJoinTeamList.add(lawsClubJoinTeam);
}
}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(lawsClubJoinTeamList);
}
// 校验Excel数据
private StringBuilder validateExcelData(List<LawsClubJoinTeamExcel> excelList) {
StringBuilder msg = new StringBuilder();
// 拿到这个流程的名称
List<DictModel> specializedModuleList = sysDictService.getDictItems("professional_module");
Map<String, String> specializedModuleMap = specializedModuleList.stream().collect(Collectors.toMap(DictModel::getText, DictModel::getValue));
for (int i = 0; i < excelList.size(); i++) {
LawsClubJoinTeamExcel lawsClubJoinTeamExcel = excelList.get(i);
StringBuilder msgSub = new StringBuilder();
// 校验入团日期
if (StringUtils.isNotBlank(lawsClubJoinTeamExcel.getJoinDate())) {
try {
LocalDate.parse(lawsClubJoinTeamExcel.getJoinDate());
} catch (Exception e) {
msgSub.append(getErrorMsg(i, "入团日期格式不正确;"));
}
}
// 校验职务担任人
if (StringUtils.isNotBlank(lawsClubJoinTeamExcel.getLeadId())) {
List<SysUser> sysUser = sysUserService.list(new LambdaQueryWrapper<SysUser>().eq(SysUser::getRealname, lawsClubJoinTeamExcel.getLeadId()));
if (CollectionUtils.isEmpty(sysUser)) {
msgSub.append(getErrorMsg(i, "社团职务担任者不存在;"));
}else {
lawsClubJoinTeamExcel.setLeadId(sysUser.get(0).getId());
}
}
// 校验部门名称
if (StringUtils.isNotBlank(lawsClubJoinTeamExcel.getDepartId())) {
List<SysDepart> sysDepart = sysDepartService.list(new LambdaQueryWrapper<SysDepart>().eq(SysDepart::getDepartName, lawsClubJoinTeamExcel.getDepartId()));
if (CollectionUtils.isEmpty(sysDepart)) {
msgSub.append(getErrorMsg(i, "部门名称不存在;"));
}else {
lawsClubJoinTeamExcel.setDepartId(sysDepart.get(0).getId());
}
}
// 校验专业模块
if (StringUtils.isNotBlank(lawsClubJoinTeamExcel.getSpecializedModule())) {
String specializedModule = specializedModuleMap.get(lawsClubJoinTeamExcel.getSpecializedModule());
if (StringUtils.isBlank(specializedModule)) {
msgSub.append(getErrorMsg(i, "专业模块不存在;"));
}else {
lawsClubJoinTeamExcel.setSpecializedModule(specializedModule);
}
}
// 校验申请人
if (StringUtils.isNotBlank(lawsClubJoinTeamExcel.getProposerId())) {
List<SysUser> sysUser = sysUserService.list(new LambdaQueryWrapper<SysUser>().eq(SysUser::getRealname, lawsClubJoinTeamExcel.getProposerId()));
if (CollectionUtils.isEmpty(sysUser)) {
msgSub.append(getErrorMsg(i, "申请人不存在;"));
}else {
lawsClubJoinTeamExcel.setProposerId(sysUser.get(0).getId());
}
}
if (msgSub.length() > 0) {
msg.append(msgSub).append("</br>");
}
}
return msg;
}
// 错误消息格式化
private String getErrorMsg(int rowIndex, String errorMsg) {
return "" + (rowIndex + 4) + "" + errorMsg;
}
}
@@ -1,10 +1,22 @@
package com.jero.modules.laws.club.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jero.common.api.vo.Result;
import com.jero.modules.laws.club.entity.LawsClubMeeting;
import com.jero.modules.laws.club.mapper.LawsClubMeetingMapper;
import com.jero.modules.laws.club.service.ILawsClubMeetingService;
import com.jero.modules.laws.club.utils.ExcelUtil;
import com.jero.modules.tag.entity.LawsTag;
import lombok.SneakyThrows;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
/**
* <p>
@@ -17,4 +29,38 @@ import org.springframework.stereotype.Service;
@Service
public class LawsClubMeetingServiceImpl extends ServiceImpl<LawsClubMeetingMapper, LawsClubMeeting> implements ILawsClubMeetingService {
@Override
@SneakyThrows
public void exportTemplate(HttpServletRequest request, HttpServletResponse response) {
// 创建一个Excel工作簿
String describe = "填写说明:\n" +
"1.所有带星号的为必填\n" +
"2.导入数据从第四行开始,第一行为表头,第二行为填写说明,第三行为示例。第四行才是正式数据\n" +
"3.一条参会信息中如有多个参会人,需要按照每个参会人一行数据进行展示,参会基本信息合并展示。\n" +
"4.社团名称需要与系统中的社团名称匹配。";
String fieldTxts = "会议名称,会议日期,会议费用,线上/线下地点,计划完成日期,通知人,通知部门,通知部门专业模块," +
"是否宣贯,会议组织人,会议内容,参会人员,参会部门,参会部门专业模块,参会报告,备注";
String mustInputFlags = "no,no,no,no,no,no,no,no,no,no,no,no,no,no,no,no";
String fieldTypeLists = "1,2,1,1,2,3,1,1,1,1,1,3,1,1,1,1"; // 1代表是文本输入类型 2代表日期输入 3代表 文本输入,姓名(工号)
List<LawsTag> lawsTags = ExcelUtil.createLawsTags(fieldTxts, mustInputFlags, fieldTypeLists);
try (Workbook workbook = ExcelUtil.createWorkBookWithLawsTags(lawsTags, "参会信息", describe);
OutputStream out = response.getOutputStream()) {
// 设置HTTP响应头
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("UTF-8"); // 确保响应流使用UTF-8编码
// 处理文件名乱码问题
String encodedFileName = URLEncoder.encode("基本信息", StandardCharsets.UTF_8.name()).replace("+", "%20");
response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encodedFileName + ".xls");
// 写入Excel并输出
workbook.write(out);
out.flush();
} catch (IOException e) {
log.error("导出Excel失败", e);
}
}
@Override
public Result<?> importExcel(HttpServletRequest request) {
return null;
}
}
@@ -1,10 +1,46 @@
package com.jero.modules.laws.club.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jero.common.api.vo.Result;
import com.jero.common.exception.JeroBootException;
import com.jero.common.system.vo.DictModel;
import com.jero.modules.laws.club.entity.LawsClubResearchInformation;
import com.jero.modules.laws.club.mapper.LawsClubResearchInformationMapper;
import com.jero.modules.laws.club.service.ILawsClubResearchInformationService;
import com.jero.modules.laws.club.utils.ExcelUtil;
import com.jero.modules.laws.club.vo.excel.LawsClubResearchInformationExcel;
import com.jero.modules.system.entity.SysDepart;
import com.jero.modules.system.entity.SysUser;
import com.jero.modules.system.service.ISysDepartService;
import com.jero.modules.system.service.ISysDictService;
import com.jero.modules.system.service.ISysUserService;
import com.jero.modules.tag.entity.LawsTag;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* <p>
@@ -17,4 +53,182 @@ import org.springframework.stereotype.Service;
@Service
public class LawsClubResearchInformationServiceImpl extends ServiceImpl<LawsClubResearchInformationMapper, LawsClubResearchInformation> implements ILawsClubResearchInformationService {
@Resource
private ISysUserService sysUserService;
@Resource
private ISysDepartService sysDepartService;
@Resource
private ISysDictService sysDictService;
@Override
@SneakyThrows
public void exportTemplate(HttpServletRequest request, HttpServletResponse response) {
// 创建一个Excel工作簿
String describe = "填写说明:\n" +
"1.所有带星号的为必填\n" +
"2.导入数据从第四行开始,第一行为表头,第二行为填写说明,第三行为示例。第四行才是正式数据\n" +
"3.社团名称需要与系统中的社团名称匹配。";
String fieldTxts = "名称,内容,接收日期,截止日期,专业接口人,专业模块,反馈人,反馈部门,反馈部门专业模块,反馈情况,任务来源,盖章流程完成情况,所属社团";
String mustInputFlags = "no,no,no,no,no,no,no,no,no,no,no,no,no";
String fieldTypeLists = "1,1,2,2,3,1,3,1,1,1,1,1,1"; // 1代表是文本输入类型 2代表日期输入 3代表 文本输入,姓名(工号)
List<LawsTag> lawsTags = ExcelUtil.createLawsTags(fieldTxts, mustInputFlags, fieldTypeLists);
try (Workbook workbook = ExcelUtil.createWorkBookWithLawsTags(lawsTags, "征集调研信息", describe);
OutputStream out = response.getOutputStream()) {
// 设置HTTP响应头
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("UTF-8"); // 确保响应流使用UTF-8编码
// 处理文件名乱码问题
String encodedFileName = URLEncoder.encode("征集调研信息", StandardCharsets.UTF_8.name()).replace("+", "%20");
response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encodedFileName + ".xls");
// 写入Excel并输出
workbook.write(out);
out.flush();
} catch (IOException e) {
log.error("导出Excel失败", e);
}
}
@Override
public Result<?> importExcel(HttpServletRequest request) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
List<LawsClubResearchInformation> lawsClubResearchInformationList = new ArrayList<>();
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
MultipartFile file = entity.getValue();// 获取上传文件对象
try {
ImportParams params = new ImportParams();
params.setNeedSave(true);
List<LawsClubResearchInformationExcel> excelList = ExcelImportUtil.importExcel(file.getInputStream(), LawsClubResearchInformationExcel.class, params);
excelList = excelList.stream().skip(2).filter(item -> !Objects.isNull(item)).collect(Collectors.toList());
if (CollectionUtils.isEmpty(excelList)) {
throw new JeroBootException("没有数据可导入");
}
StringBuilder msg = validateExcelData(excelList); // 校验数据
if (StringUtils.isNotEmpty(msg.toString())) {
return Result.error(msg.toString());
}
// 保存数据
for (LawsClubResearchInformationExcel lawsClubResearchInformationExcel : excelList) {
LawsClubResearchInformation lawsClubResearchInformation = new LawsClubResearchInformation();
BeanUtils.copyProperties(lawsClubResearchInformationExcel, lawsClubResearchInformation);
lawsClubResearchInformationList.add(lawsClubResearchInformation);
}
}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(lawsClubResearchInformationList);
}
// 校验Excel数据
private StringBuilder validateExcelData(List<LawsClubResearchInformationExcel> excelList) {
StringBuilder msg = new StringBuilder();
// 拿到这个流程的名称
List<DictModel> specializedModuleList = sysDictService.getDictItems("professional_module");
List<DictModel> clubTaskSourceList = sysDictService.getDictItems("club_task_source");
Map<String, String> specializedModuleMap = specializedModuleList.stream().collect(Collectors.toMap(DictModel::getText, DictModel::getValue));
Map<String, String> clubTaskSourceMap = clubTaskSourceList.stream().collect(Collectors.toMap(DictModel::getText, DictModel::getValue));
for (int i = 0; i < excelList.size(); i++) {
LawsClubResearchInformationExcel lawsClubResearchInformationExcel = excelList.get(i);
StringBuilder msgSub = new StringBuilder();
// 校验接收日期
if (StringUtils.isNotBlank(lawsClubResearchInformationExcel.getReceiveDate())) {
try {
LocalDate.parse(lawsClubResearchInformationExcel.getReceiveDate());
} catch (Exception e) {
msgSub.append(getErrorMsg(i, "接收日期格式不正确;"));
}
}
// 校验截止日期
if (StringUtils.isNotBlank(lawsClubResearchInformationExcel.getDeadlineDate())) {
try {
LocalDate.parse(lawsClubResearchInformationExcel.getDeadlineDate());
} catch (Exception e) {
msgSub.append(getErrorMsg(i, "截止日期格式不正确;"));
}
}
// 校验专业接口人
if (StringUtils.isNotBlank(lawsClubResearchInformationExcel.getSpecializedInterfacePerson())) {
String specializedInterfacePerson = extractEmployeeId(lawsClubResearchInformationExcel.getSpecializedInterfacePerson());
SysUser sysUser = sysUserService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUsername, specializedInterfacePerson),false);
if (Objects.isNull(sysUser)) {
msgSub.append(getErrorMsg(i, "专业接口人不存在;"));
}else {
lawsClubResearchInformationExcel.setSpecializedInterfacePerson(sysUser.getId());
}
}
// 校验专业模块
if (StringUtils.isNotBlank(lawsClubResearchInformationExcel.getSpecializedModule())) {
String specializedModule = specializedModuleMap.get(lawsClubResearchInformationExcel.getSpecializedModule());
if (StringUtils.isBlank(specializedModule)) {
msgSub.append(getErrorMsg(i, "专业模块不存在;"));
}else {
lawsClubResearchInformationExcel.setSpecializedModule(specializedModule);
}
}
// 校验反馈人
if (StringUtils.isNotBlank(lawsClubResearchInformationExcel.getFeedbackPerson())) {
String feedbackPerson = extractEmployeeId(lawsClubResearchInformationExcel.getFeedbackPerson());
SysUser sysUser = sysUserService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUsername, feedbackPerson),false);
if (Objects.isNull(sysUser)) {
msgSub.append(getErrorMsg(i, "反馈人不存在;"));
}else {
lawsClubResearchInformationExcel.setFeedbackPerson(sysUser.getId());
}
}
// 校验反馈部门
if (StringUtils.isNotBlank(lawsClubResearchInformationExcel.getFeedbackDepart())) {
List<SysDepart> sysDepart = sysDepartService.list(new LambdaQueryWrapper<SysDepart>().eq(SysDepart::getDepartName, lawsClubResearchInformationExcel.getFeedbackDepart()));
if (CollectionUtils.isEmpty(sysDepart)) {
msgSub.append(getErrorMsg(i, "反馈部门不存在;"));
}else {
lawsClubResearchInformationExcel.setFeedbackDepart(sysDepart.get(0).getId());
}
}
// 校验反馈部门专业模块
if (StringUtils.isNotBlank(lawsClubResearchInformationExcel.getFeedbackSpecializedModule())) {
String feedbackSpecializedModule = specializedModuleMap.get(lawsClubResearchInformationExcel.getFeedbackSpecializedModule());
if (StringUtils.isBlank(feedbackSpecializedModule)) {
msgSub.append(getErrorMsg(i, "反馈部门专业模块不存在;"));
}else {
lawsClubResearchInformationExcel.setFeedbackSpecializedModule(feedbackSpecializedModule);
}
}
// 校验任务来源
if (StringUtils.isNotBlank(lawsClubResearchInformationExcel.getTaskSource())) {
String taskSource = clubTaskSourceMap.get(lawsClubResearchInformationExcel.getTaskSource());
if (StringUtils.isBlank(taskSource)) {
msgSub.append(getErrorMsg(i, "任务来源不存在;"));
}else {
lawsClubResearchInformationExcel.setTaskSource(taskSource);
}
}
if (msgSub.length() > 0) {
msg.append(msgSub).append("</br>");
}
}
return msg;
}
// 错误消息格式化
private String getErrorMsg(int rowIndex, String errorMsg) {
return "" + (rowIndex + 4) + "" + errorMsg;
}
public String extractEmployeeId(String input) {
// 正则表达式,匹配括号内的内容
Pattern pattern = Pattern.compile("\\((.*?)\\)");
Matcher matcher = pattern.matcher(input);
if (matcher.find()) {
return matcher.group(1); // 返回匹配到的内容,即括号中的内容
}
return input; // 如果没有匹配到,返回null
}
}
@@ -13,13 +13,16 @@ import com.jero.modules.laws.club.config.CustomExcelExportStyler;
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.utils.ExcelUtil;
import com.jero.modules.laws.club.vo.LawsClubTreeNodeModel;
import com.jero.modules.laws.club.vo.excel.*;
import com.jero.modules.system.entity.SysDepart;
import com.jero.modules.system.entity.SysUser;
import com.jero.modules.system.service.ISysDepartService;
import com.jero.modules.system.service.ISysUserService;
import com.jero.modules.tag.entity.LawsTag;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.*;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
@@ -27,6 +30,7 @@ import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
@@ -35,9 +39,10 @@ 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.text.SimpleDateFormat;
import java.time.LocalDate;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -52,6 +57,7 @@ import java.util.stream.Collectors;
*/
@Service
@Transactional(rollbackFor = JeroBootException.class)
@Slf4j
public class LawsClubServiceImpl extends ServiceImpl<LawsClubMapper, LawsClub> implements ILawsClubService {
@Resource
@@ -72,6 +78,8 @@ public class LawsClubServiceImpl extends ServiceImpl<LawsClubMapper, LawsClub> i
private ISysUserService sysUserService;
@Resource
private ISysDepartService sysDepartService;
@Value("${jero.path.exportExcelTempPath}")
private String exportExcelTempPath;
@Override
public List<LawsClubTreeNodeModel> getTreeStructure(String parentId, String nodeType) {
@@ -522,8 +530,7 @@ public class LawsClubServiceImpl extends ServiceImpl<LawsClubMapper, LawsClub> i
//导出文件名称
mv.addObject(JeroController.FILE_NAME, "入团信息统计表");
mv.addObject(JeroController.CLASS, LawsClubJoinTeam.class);
ExportParams exportParams = new ExportParams(null, "入团信息");
mv.addObject(JeroController.PARAMS, exportParams);
mv.addObject(JeroController.PARAMS, createExportParams("密级:核心商密□普通商密□内部资料■外部公开□", "入团信息"));
mv.addObject(NormalExcelConstants.DATA_LIST, excelList);
return mv;
}
@@ -551,8 +558,7 @@ public class LawsClubServiceImpl extends ServiceImpl<LawsClubMapper, LawsClub> i
//导出文件名称
mv.addObject(JeroController.FILE_NAME, "参会记录表");
mv.addObject(JeroController.CLASS, LawsClubMeeting.class);
ExportParams exportParams = new ExportParams(null, "参会信息");
mv.addObject(JeroController.PARAMS, exportParams);
mv.addObject(JeroController.PARAMS, createExportParams("密级:核心商密□普通商密□内部资料■外部公开□", "参会信息"));
mv.addObject(NormalExcelConstants.DATA_LIST, excelList);
return mv;
}
@@ -574,25 +580,38 @@ public class LawsClubServiceImpl extends ServiceImpl<LawsClubMapper, LawsClub> i
excelList = lawsClubResearchInformationService.list(new LambdaQueryWrapper<LawsClubResearchInformation>().in(LawsClubResearchInformation::getClubId, ids));
}
//导出文件名称
mv.addObject(JeroController.FILE_NAME, "征集调研信记录");
mv.addObject(JeroController.FILE_NAME, "征集调研信统计");
mv.addObject(JeroController.CLASS, LawsClubResearchInformation.class);
ExportParams exportParams = new ExportParams(null, "征集调研信息");
mv.addObject(JeroController.PARAMS, exportParams);
mv.addObject(JeroController.PARAMS, createExportParams("密级:核心商密□普通商密□内部资料■外部公开□", "征集调研信息"));
mv.addObject(NormalExcelConstants.DATA_LIST, excelList);
return mv;
}
@Override
public ModelAndView exportTemplate(HttpServletRequest request) {
List<LawsClubExcel> excelList = new ArrayList<>();
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
mv.addObject(JeroController.FILE_NAME, "社团管理");
mv.addObject(JeroController.CLASS, LawsClubExcel.class);
ExportParams exportParams = new ExportParams("社团管理", "社团管理");
mv.addObject(JeroController.PARAMS, exportParams);
mv.addObject(NormalExcelConstants.DATA_LIST, excelList);
return mv;
@SneakyThrows
public void exportTemplate(HttpServletRequest request, HttpServletResponse response) {
// 创建一个Excel工作簿
String describe = "填写说明:\n" +
"1.所有带星号的为必填\n" +
"2.导入数据从第四行开始,第一行为表头,第二行为填写说明,第三行为示例。第四行才是正式数据";
String fieldTxts = "上级节点,节点类型,社团名称,社团地址,社团联系人,联系电话,编号";
String mustInputFlags = "yes,yes,yes,no,no,no,no";
String fieldTypeLists = "1,1,1,1,1,1,1"; // 1 代表是文本输入类型
List<LawsTag> lawsTags = ExcelUtil.createLawsTags(fieldTxts, mustInputFlags, fieldTypeLists);
try (Workbook workbook = ExcelUtil.createWorkBookWithLawsTags(lawsTags, "基础信息", describe);
OutputStream out = response.getOutputStream()) {
// 设置HTTP响应头
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("UTF-8"); // 确保响应流使用UTF-8编码
// 处理文件名乱码问题
String encodedFileName = URLEncoder.encode("基础信息", StandardCharsets.UTF_8.name()).replace("+", "%20");
response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encodedFileName + ".xls");
// 写入Excel并输出
workbook.write(out);
out.flush();
} catch (IOException e) {
log.error("导出Excel失败", e);
}
}
@Override
@@ -601,12 +620,11 @@ public class LawsClubServiceImpl extends ServiceImpl<LawsClubMapper, LawsClub> i
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 {
ImportParams params = new ImportParams();
params.setNeedSave(true);
List<LawsClubExcel> excelList = ExcelImportUtil.importExcel(file.getInputStream(), LawsClubExcel.class, params);
excelList = excelList.stream().skip(2).filter(item -> !Objects.isNull(item)).collect(Collectors.toList());
if (CollectionUtils.isEmpty(excelList)) {
throw new JeroBootException("没有数据可导入");
}
@@ -614,7 +632,12 @@ public class LawsClubServiceImpl extends ServiceImpl<LawsClubMapper, LawsClub> i
if (StringUtils.isNotEmpty(msg.toString())) {
return Result.error(msg.toString());
}
saveExcelData(excelList); // 保存数据
// 保存数据
for (LawsClubExcel lawsClubExcel : excelList) {
LawsClub lawsClub = new LawsClub();
BeanUtils.copyProperties(lawsClubExcel, lawsClub);
save(lawsClub);
}
}catch (Exception e) {
log.error(e.getMessage(),e);
return Result.error("文件导入失败:"+e.getMessage());
@@ -632,20 +655,34 @@ public class LawsClubServiceImpl extends ServiceImpl<LawsClubMapper, LawsClub> i
// 校验Excel数据
private StringBuilder validateExcelData(List<LawsClubExcel> excelList) {
StringBuilder msg = new StringBuilder();
for (LawsClubExcel lawsClubExcel : excelList) {
for (int i = 0; i < excelList.size(); i++) {
LawsClubExcel lawsClubExcel = excelList.get(i);
StringBuilder msgSub = new StringBuilder();
// 校验上级节点
validateParentNode(lawsClubExcel, msgSub, excelList);
// 校验基本信息
validateBasicInfo(lawsClubExcel, msgSub, excelList);
// 校验入团信息
validateTeamInfo(lawsClubExcel.getLawsClubJoinTeamList(), msgSub, lawsClubExcel, excelList);
// 校验参会信息
validateMeetingInfo(lawsClubExcel.getLawsClubMeetings(), msgSub, lawsClubExcel, excelList);
// 校验调研征集信息
validateResearchInfo(lawsClubExcel.getLawsClubResearchInformations(), msgSub, lawsClubExcel, excelList);
// 校验支付信息
validatePaymentInfo(lawsClubExcel.getLawsClubPayment(), msgSub, lawsClubExcel, excelList);
String parentId = lawsClubExcel.getParentId();
if (StringUtils.isBlank(parentId)) {
msgSub.append(getErrorMsg(i, "上级节点不能为空;"));
} else {
LawsClub club = getOne(new LambdaQueryWrapper<LawsClub>().eq(LawsClub::getNodeType, parentId));
if (club == null) {
msgSub.append(getErrorMsg(i, "上级节点不存在,请重新输入;"));
} else {
lawsClubExcel.setParentId(club.getId());
}
}
// 校验节点类型
if (StringUtils.isBlank(lawsClubExcel.getNodeType())) {
msgSub.append(getErrorMsg(i, "节点类型不能为空;"));
}
if (StringUtils.isBlank(lawsClubExcel.getClubName())) {
msgSub.append(getErrorMsg(i, "社团名称不能为空;"));
}
String contactNumber = lawsClubExcel.getContactNumber();
if (StringUtils.isNotBlank(contactNumber) && !contactNumber.matches("^(?:(0\\d{2,3}-)?\\d{7,8}|1[3-9]\\d{9})$")) {
msgSub.append(getErrorMsg(i, "联系方式格式不正确;"));
} else {
lawsClubExcel.setContactNumber(PasswordUtil.encrypt(contactNumber));
}
if (msgSub.length() > 0) {
msg.append(msgSub).append("</br>");
}
@@ -653,168 +690,9 @@ public class LawsClubServiceImpl extends ServiceImpl<LawsClubMapper, LawsClub> i
return msg;
}
private void validateParentNode(LawsClubExcel lawsClubExcel, StringBuilder msgSub, List<LawsClubExcel> excelList) {
String parentId = lawsClubExcel.getParentId();
if (StringUtils.isBlank(parentId)) {
msgSub.append(getErrorMsg(excelList, lawsClubExcel, "上级节点不能为空;"));
} else {
LawsClub club = getOne(new LambdaQueryWrapper<LawsClub>().eq(LawsClub::getNodeType, parentId));
if (club == null) {
msgSub.append(getErrorMsg(excelList, lawsClubExcel, "上级节点不存在,请重新输入;"));
} else {
lawsClubExcel.setParentId(club.getId());
}
}
}
private void validateBasicInfo(LawsClubExcel lawsClubExcel, StringBuilder msgSub, List<LawsClubExcel> excelList) {
if (StringUtils.isBlank(lawsClubExcel.getNodeType())) {
msgSub.append(getErrorMsg(excelList, lawsClubExcel, "节点类型不能为空;"));
}
if (hasAdditionalInfo(lawsClubExcel) && StringUtils.isBlank(lawsClubExcel.getClubName())) {
msgSub.append(getErrorMsg(excelList, lawsClubExcel, "社团名称不能为空;"));
}
String contactNumber = lawsClubExcel.getContactNumber();
if (StringUtils.isNotBlank(contactNumber) && !contactNumber.matches("^(?:(0\\d{2,3}-)?\\d{7,8}|1[3-9]\\d{9})$")) {
msgSub.append(getErrorMsg(excelList, lawsClubExcel, "联系方式格式不正确;"));
} else {
lawsClubExcel.setContactNumber(PasswordUtil.encrypt(contactNumber));
}
}
private void validateTeamInfo(List<LawsClubJoinTeamExcel> teamList, StringBuilder msgSub, LawsClubExcel lawsClubExcel, List<LawsClubExcel> excelList) {
if (CollectionUtils.isEmpty(teamList)) return;
for (LawsClubJoinTeamExcel team : teamList) {
String proposerId = team.getProposerId();
String departId = team.getDepartId();
if (StringUtils.isNotBlank(proposerId)) {
List<SysUser> sysUser = sysUserService.list(new LambdaQueryWrapper<SysUser>().eq(SysUser::getRealname, proposerId));
if (CollectionUtils.isEmpty(sysUser)) {
msgSub.append(getErrorMsg(excelList, lawsClubExcel, "入团信息的申请人不存在;"));
}else {
team.setProposerId(sysUser.get(0).getId());
}
}
if (StringUtils.isNotBlank(departId)) {
List<SysDepart> sysDepart = sysDepartService.list(new LambdaQueryWrapper<SysDepart>().eq(SysDepart::getDepartName, departId));
if (CollectionUtils.isEmpty(sysDepart)) {
msgSub.append(getErrorMsg(excelList, lawsClubExcel, "入团信息的部门名称不存在;"));
}else {
team.setDepartId(sysDepart.get(0).getId());
}
}
validateDateFormat(team.getJoinDate(), "入团信息的入团日期格式不正确;", msgSub, excelList, lawsClubExcel);
}
}
private void validateMeetingInfo(List<LawsClubMeetingImportExcel> meetings, StringBuilder msgSub, LawsClubExcel lawsClubExcel, List<LawsClubExcel> excelList) {
if (CollectionUtils.isEmpty(meetings)) return;
for (LawsClubMeetingImportExcel meeting : meetings) {
validateDateFormat(meeting.getMeetingDate(), "参会信息的会议日期格式不正确;", msgSub, excelList, lawsClubExcel);
}
}
private void validateResearchInfo(List<LawsClubResearchInformationExcel> researchList, StringBuilder msgSub, LawsClubExcel lawsClubExcel, List<LawsClubExcel> excelList) {
if (CollectionUtils.isEmpty(researchList)) return;
for (LawsClubResearchInformationExcel research : researchList) {
validateDateFormat(research.getReceiveDate(), "征集调研信息的接收日期格式不正确;", msgSub, excelList, lawsClubExcel);
validateDateFormat(research.getDeadlineDate(), "征集调研信息的截止日期格式不正确;", msgSub, excelList, lawsClubExcel);
}
}
private void validatePaymentInfo(List<LawsClubPaymentExcel> payments, StringBuilder msgSub, LawsClubExcel lawsClubExcel, List<LawsClubExcel> excelList) {
if (CollectionUtils.isEmpty(payments)) return;
for (LawsClubPaymentExcel payment : payments) {
validateDateFormat(payment.getPaymentTime(), "支付信息的缴费时间格式不正确;", msgSub, excelList, lawsClubExcel);
}
}
private void validateDateFormat(String dateStr, String errorMsg, StringBuilder msgSub, List<LawsClubExcel> excelList, LawsClubExcel lawsClubExcel) {
if (StringUtils.isNotBlank(dateStr)) {
try {
LocalDate.parse(dateStr);
} catch (Exception e) {
msgSub.append(getErrorMsg(excelList, lawsClubExcel, errorMsg));
}
}
}
// 保存Excel数据
private void saveExcelData(List<LawsClubExcel> excelList) {
for (LawsClubExcel lawsClubExcel : excelList) {
LawsClub lawsClub = new LawsClub();
BeanUtils.copyProperties(lawsClubExcel, lawsClub);
// 转换和保存数据
List<LawsClubJoinTeam> joinTeamList = convertList(lawsClubExcel.getLawsClubJoinTeamList(), this::convertToJoinTeam);
List<LawsClubPayment> paymentList = convertList(lawsClubExcel.getLawsClubPayment(), this::convertToPayment);
List<LawsClubMeeting> meetingList = convertList(lawsClubExcel.getLawsClubMeetings(), this::convertToMeeting);
List<LawsClubResearchInformation> researchInfoList = convertList(lawsClubExcel.getLawsClubResearchInformations(), this::convertToResearchInformation);
save(lawsClub);
saveAssociationTable(lawsClub, joinTeamList, paymentList, meetingList, researchInfoList, null);
}
}
// 错误消息格式化
private String getErrorMsg(List<LawsClubExcel> excelList, LawsClubExcel lawsClubExcel, String errorMsg) {
return "" + (excelList.indexOf(lawsClubExcel) + 4) + "" + errorMsg;
}
// 判断是否有额外信息
private boolean hasAdditionalInfo(LawsClubExcel lawsClubExcel) {
return !CollectionUtils.isEmpty(lawsClubExcel.getLawsClubMeetings()) ||
!CollectionUtils.isEmpty(lawsClubExcel.getLawsClubJoinTeamList()) ||
!CollectionUtils.isEmpty(lawsClubExcel.getLawsClubResearchInformations());
}
// 通用的转换方法
private <T, R> List<R> convertList(List<T> sourceList, Function<T, R> converter) {
return Optional.ofNullable(sourceList).orElse(Collections.emptyList()).stream()
.map(converter)
.collect(Collectors.toList());
}
// 通用的日期转换方法
private Date parseDate(String dateStr, String errorMessage) {
if (StringUtils.isNotBlank(dateStr)) {
try {
return new SimpleDateFormat("yyyy-MM-dd").parse(dateStr);
} catch (Exception e) {
log.error(errorMessage);
}
}
return null;
}
// 转换方法
private LawsClubJoinTeam convertToJoinTeam(LawsClubJoinTeamExcel joinTeamExcel) {
LawsClubJoinTeam joinTeam = new LawsClubJoinTeam();
BeanUtils.copyProperties(joinTeamExcel, joinTeam);
joinTeam.setJoinDate(parseDate(joinTeamExcel.getJoinDate(), "入团日期转换异常"));
return joinTeam;
}
private LawsClubPayment convertToPayment(LawsClubPaymentExcel paymentExcel) {
LawsClubPayment payment = new LawsClubPayment();
BeanUtils.copyProperties(paymentExcel, payment);
payment.setPaymentTime(parseDate(paymentExcel.getPaymentTime(), "缴费时间转换异常"));
return payment;
}
private LawsClubMeeting convertToMeeting(LawsClubMeetingImportExcel meetingImportExcel) {
LawsClubMeeting meeting = new LawsClubMeeting();
BeanUtils.copyProperties(meetingImportExcel, meeting);
meeting.setMeetingDate(parseDate(meetingImportExcel.getMeetingDate(), "会议日期转换异常"));
return meeting;
}
private LawsClubResearchInformation convertToResearchInformation(LawsClubResearchInformationExcel researchInformationExcel) {
LawsClubResearchInformation researchInfo = new LawsClubResearchInformation();
BeanUtils.copyProperties(researchInformationExcel, researchInfo);
researchInfo.setReceiveDate(parseDate(researchInformationExcel.getReceiveDate(), "接收日期转换异常"));
researchInfo.setDeadlineDate(parseDate(researchInformationExcel.getDeadlineDate(), "截止日期转换异常"));
return researchInfo;
private String getErrorMsg(int rowIndex, String errorMsg) {
return "" + (rowIndex + 4) + "" + errorMsg;
}
}
@@ -0,0 +1,126 @@
package com.jero.modules.laws.club.utils;
import com.jero.common.constant.enums.YesOrNoEnum;
import com.jero.modules.laws.club.enums.FieldTypeEnum;
import com.jero.modules.tag.entity.LawsTag;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import java.util.ArrayList;
import java.util.List;
@Slf4j
public class ExcelUtil {
// 通用方法,传入逗号分隔的字段名称和对应的必填标志
public static List<LawsTag> createLawsTags(String fieldTxts, String mustInputFlags, String fieldTypeLists) {
List<LawsTag> lawsTags = new ArrayList<>();
// 将输入字符串按照逗号分割
String[] fieldArray = fieldTxts.split(",");
String[] mustInputArray = mustInputFlags.split(",");
String[] fieldTypeArray = fieldTypeLists.split(",");
// 遍历每一个字段并设置 LawsTag 对象
for (int i = 0; i < fieldArray.length; i++) {
LawsTag lawsTag = new LawsTag();
lawsTag.setDbFieldTxt(fieldArray[i].trim()); // 设置字段名,trim() 去除可能的空格
// 根据必填标志设置是否为必填
String mustInputFlag = mustInputArray[i].trim();
if (mustInputFlag.equalsIgnoreCase("yes")) {
lawsTag.setFieldMustInput(YesOrNoEnum.YES.getValue());
} else if (mustInputFlag.equalsIgnoreCase("no")) {
lawsTag.setFieldMustInput(YesOrNoEnum.NO.getValue());
}
lawsTag.setFieldShowType(fieldTypeArray[i].trim());
lawsTags.add(lawsTag);
}
return lawsTags;
}
public static Workbook createWorkBookWithLawsTags(List<LawsTag> fieldList, String sheetName, String describe) {
// 创建一个Excel工作簿
Workbook workbook = new HSSFWorkbook();
// 创建一个工作表
Sheet sheet = workbook.createSheet(sheetName);
// 创建数据格式
DataFormat fmt = workbook.createDataFormat();
// 创建一个单元格样式并设置数据格式为文本
CellStyle textStyle = workbook.createCellStyle();
textStyle.setDataFormat(fmt.getFormat("@"));
// 设置列宽
for (int i = 0; i < fieldList.size(); i++) {
sheet.setColumnWidth(i, 13 * 256);
}
// 创建红色字体
Font redFont = workbook.createFont();
redFont.setColor(IndexedColors.RED.getIndex());
// 创建默认字体(黑色)
Font defaultFont = workbook.createFont();
defaultFont.setColor(IndexedColors.BLACK.getIndex());
// 创建第一行并添加字段
Row row1 = sheet.createRow(0);
for (int i = 0; i < fieldList.size(); i++) {
LawsTag tag = fieldList.get(i);
String cellValue = tag.getDbFieldTxt();
// 创建单元格
Cell cell = row1.createCell(i);
// 判断是否为必填项
if (YesOrNoEnum.YES.getValue().equals(tag.getFieldMustInput())) {
// 创建富文本字符串
CreationHelper createHelper = workbook.getCreationHelper();
RichTextString richString = createHelper.createRichTextString("*" + cellValue);
// 设置 * 为红色
richString.applyFont(0, 1, redFont);
// 设置其他文字为默认样式(黑色)
richString.applyFont(1, richString.length(), defaultFont);
// 设置单元格的值
cell.setCellValue(richString);
} else {
cell.setCellValue(cellValue);
}
}
// 确保所有新建的单元格都应用这个文本格式
for (int i = 0; i < fieldList.size(); i++) {
// 在后续创建单元格时应用文本样式
sheet.setDefaultColumnStyle(i, textStyle);
}
// 创建第二行并合并单元格
Row row2 = sheet.createRow(1);
row2.setHeightInPoints(65);
// 创建一个单元格样式,并设置为自动换行
CellStyle style = workbook.createCellStyle();
// 设置文字在单元格中垂直居中
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setWrapText(true);
sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, fieldList.size() - 1));
Cell cell2 = row2.createCell(0);
cell2.setCellValue(describe);
// 应用样式到单元格
cell2.setCellStyle(style);
// 创建第三行并添加固定内容
Row row3 = sheet.createRow(2);
row3.setHeightInPoints(25);
setRow3CellValue(row3, fieldList, style);
return workbook;
}
public static void setRow3CellValue(Row row3, List<LawsTag> fieldList, CellStyle style) {
for (int i = 0; i < fieldList.size(); i++) {
LawsTag tag = fieldList.get(i);
// 创建单元格
Cell cell = row3.createCell(i);
cell.setCellStyle(style);
cell.setCellValue(getDescription(tag));
}
}
public static String getDescription(LawsTag tag){
String value = tag.getFieldShowType();
for (FieldTypeEnum fieldTypeEnum: FieldTypeEnum.values()) {
if (fieldTypeEnum.getValue().equals(value)) {
return fieldTypeEnum.getDescription();
}
}
return "";
}
}
@@ -2,19 +2,20 @@ package com.jero.modules.laws.club.vo.excel;
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 {
@Excel(name = "上级节点", width = 20)
@Excel(name = "*上级节点", width = 20)
private String parentId;
@Excel(name = "节点类型", width = 20)
@Excel(name = "*节点类型", width = 20)
private String nodeType;
@Excel(name = "社团名称", width = 20)
@Excel(name = "编号", width = 20)
private String number;
@Excel(name = "*社团名称", width = 20)
private String clubName;
@Excel(name = "社团地址", width = 20)
@@ -26,16 +27,4 @@ public class LawsClubExcel {
@Excel(name = "联系电话", width = 20)
private String contactNumber;
@ExcelCollection(name = "入团信息")
private List<LawsClubJoinTeamExcel> lawsClubJoinTeamList;
@ExcelCollection(name = "参会信息")
private List<LawsClubMeetingImportExcel> lawsClubMeetings;
@ExcelCollection(name = "支付信息")
private List<LawsClubPaymentExcel> lawsClubPayment;
@ExcelCollection(name = "征集调研信息")
private List<LawsClubResearchInformationExcel> lawsClubResearchInformations;
}
@@ -1,25 +1,44 @@
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")
@Excel(name = "*社团名称", width = 20)
private String clubId;
@Excel(name = "入团日期", width = 20)
private String joinDate;
@ApiModelProperty(value = "部门id")
@Excel(name = "社团职务担任者", width = 20)
private String leadId;
@Excel(name = "入团经费", width = 20)
private String joinCast;
@Excel(name = "社团简介", width = 20)
private String clubProfile;
@Excel(name = "部门名称", width = 20)
private String departId;
@ApiModelProperty(value = "申请人的id")
@Excel(name = "专业模块", width = 20)
private String specializedModule;
@Excel(name = "申请人", width = 20)
private String proposerId;
@Excel(name = "秘书处", width = 20)
private String secretariat;
@Excel(name = "联系人", width = 20)
private String contacts;
@Excel(name = "备注", width = 20)
private String remark;
}
@@ -0,0 +1,52 @@
package com.jero.modules.laws.club.vo.excel;
import lombok.Data;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.jeecgframework.poi.excel.annotation.ExcelCollection;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
@Data
public class LawsClubMeetingExcel implements Serializable {
@Excel(name = "*社团名称", width = 20)
private String clubId;
@Excel(name = "会议名称", width = 20)
private String meetingName;
@Excel(name = "会议日期", width = 20)
private String meetingDate;
@Excel(name = "会议费用", width = 20)
private String meetingCost;
@Excel(name = "线下/线上地点", width = 20)
private String meetingPlace;
@Excel(name = "计划完成日期", width = 20)
private Date planCompletionDate;
@Excel(name = "通知人", width = 20)
private String notifierId;
@Excel(name = "通知部门", width = 20)
private String notifyDepartId;
@Excel(name = "通知部门专业模块", width = 20)
private String informSpecializedModule;
@Excel(name = "是否宣贯", width = 20)
private String isPublicize;
@Excel(name = "会议组织人", width = 20)
private String meetingOrganizer;
@Excel(name = "会议内容", width = 20)
private String meetingContent;
@ExcelCollection(name = "")
private List<LawsClubMeetingMemberExcel> meetingMemberList;
}
@@ -1,31 +0,0 @@
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 String meetingDate;
@Excel(name = "会议费用", width = 20)
private String meetingCost;
@Excel(name = "线下/线上地点", width = 20)
private String meetingPlace;
}
@@ -0,0 +1,24 @@
package com.jero.modules.laws.club.vo.excel;
import lombok.Data;
import org.jeecgframework.poi.excel.annotation.Excel;
import java.io.Serializable;
@Data
public class LawsClubMeetingMemberExcel implements Serializable {
@Excel(name = "参会人员", width = 20)
private String memberId;
@Excel(name = "参会部门", width = 20)
private String departId;
@Excel(name = "参会部门专业模块", width = 20)
private String meetingSpecializedModule;
@Excel(name = "参会报告", width = 20)
private String meetingFileId;
@Excel(name = "备注", width = 20)
private String remark;
}
@@ -7,6 +7,9 @@ import java.io.Serializable;
@Data
public class LawsClubPaymentExcel implements Serializable {
@Excel(name = "*社团名称", width = 20)
private String clubId;
@Excel(name = "缴费金额", width = 20)
private String paymentAmount;
@@ -1,15 +1,9 @@
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 {
@@ -20,9 +14,36 @@ public class LawsClubResearchInformationExcel implements Serializable {
@Excel(name = "内容", width = 20)
private String researchContent;
@Excel(name = "接收日期", width = 20, format = "yyyy-MM-dd")
@Excel(name = "接收日期", width = 20)
private String receiveDate;
@Excel(name = "截止日期", width = 20, format = "yyyy-MM-dd")
@Excel(name = "截止日期", width = 20)
private String deadlineDate;
@Excel(name = "专业接口人", width = 20)
private String specializedInterfacePerson;
@Excel(name = "专业模块", width = 20)
private String specializedModule;
@Excel(name = "反馈人", width = 20)
private String feedbackPerson;
@Excel(name = "反馈部门", width = 20)
private String feedbackDepart;
@Excel(name = "反馈部门专业模块", width = 20)
private String feedbackSpecializedModule;
@Excel(name = "反馈情况", width = 20)
private String feedbackSituation;
@Excel(name = "任务来源", width = 20)
private String taskSource;
@Excel(name = "盖章流程完成情况", width = 20)
private String sealSituation;
@Excel(name = "所属社团", width = 20)
private String clubName;
}