diff --git a/laws-modules/src/main/java/com/jero/modules/laws/club/controller/LawsClubController.java b/laws-modules/src/main/java/com/jero/modules/laws/club/controller/LawsClubController.java index 25f53c4f..02e5af5b 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/club/controller/LawsClubController.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/club/controller/LawsClubController.java @@ -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 + * 社团管理-入团信息表 前端控制器 + *

+ * + * @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); + } + +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/club/controller/LawsClubMeetingController.java b/laws-modules/src/main/java/com/jero/modules/laws/club/controller/LawsClubMeetingController.java new file mode 100644 index 00000000..c45dafe2 --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/club/controller/LawsClubMeetingController.java @@ -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; + +/** + *

+ * 社团管理-参会信息表 前端控制器 + *

+ * + * @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); + } + +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/club/controller/LawsClubResearchInformationController.java b/laws-modules/src/main/java/com/jero/modules/laws/club/controller/LawsClubResearchInformationController.java new file mode 100644 index 00000000..5c574abd --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/club/controller/LawsClubResearchInformationController.java @@ -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; + +/** + *

+ * 社团管理-征集调研信息表 前端控制器 + *

+ * + * @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); + } + +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/club/enums/FieldTypeEnum.java b/laws-modules/src/main/java/com/jero/modules/laws/club/enums/FieldTypeEnum.java new file mode 100644 index 00000000..0084a58b --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/club/enums/FieldTypeEnum.java @@ -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; + } +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/club/service/ILawsClubJoinTeamService.java b/laws-modules/src/main/java/com/jero/modules/laws/club/service/ILawsClubJoinTeamService.java index 0f7de0a1..498198b1 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/club/service/ILawsClubJoinTeamService.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/club/service/ILawsClubJoinTeamService.java @@ -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; /** *

@@ -12,4 +15,8 @@ import com.jero.modules.laws.club.entity.LawsClubJoinTeam; * @since 2024-08-29 */ public interface ILawsClubJoinTeamService extends IService { + + void exportTemplate(HttpServletRequest request, HttpServletResponse response); + + Result importExcel(HttpServletRequest request); } diff --git a/laws-modules/src/main/java/com/jero/modules/laws/club/service/ILawsClubMeetingService.java b/laws-modules/src/main/java/com/jero/modules/laws/club/service/ILawsClubMeetingService.java index 979ec5a1..26297524 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/club/service/ILawsClubMeetingService.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/club/service/ILawsClubMeetingService.java @@ -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; /** *

@@ -13,4 +16,7 @@ import com.jero.modules.laws.club.entity.LawsClubMeeting; */ public interface ILawsClubMeetingService extends IService { + void exportTemplate(HttpServletRequest request, HttpServletResponse response); + + Result importExcel(HttpServletRequest request); } diff --git a/laws-modules/src/main/java/com/jero/modules/laws/club/service/ILawsClubResearchInformationService.java b/laws-modules/src/main/java/com/jero/modules/laws/club/service/ILawsClubResearchInformationService.java index e6badd2e..124f5a7d 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/club/service/ILawsClubResearchInformationService.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/club/service/ILawsClubResearchInformationService.java @@ -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; /** *

@@ -13,4 +16,7 @@ import com.jero.modules.laws.club.entity.LawsClubResearchInformation; */ public interface ILawsClubResearchInformationService extends IService { + void exportTemplate(HttpServletRequest request, HttpServletResponse response); + + Result importExcel(HttpServletRequest request); } diff --git a/laws-modules/src/main/java/com/jero/modules/laws/club/service/ILawsClubService.java b/laws-modules/src/main/java/com/jero/modules/laws/club/service/ILawsClubService.java index b3a5466f..637bd741 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/club/service/ILawsClubService.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/club/service/ILawsClubService.java @@ -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 { ModelAndView exportresearchXls(LawsClub lawsClub, HttpServletRequest request); - ModelAndView exportTemplate(HttpServletRequest request); + void exportTemplate(HttpServletRequest request, HttpServletResponse response); Result importExcel(HttpServletRequest request); diff --git a/laws-modules/src/main/java/com/jero/modules/laws/club/service/impl/LawsClubJoinTeamServiceImpl.java b/laws-modules/src/main/java/com/jero/modules/laws/club/service/impl/LawsClubJoinTeamServiceImpl.java index a5d44a33..53baf0ed 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/club/service/impl/LawsClubJoinTeamServiceImpl.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/club/service/impl/LawsClubJoinTeamServiceImpl.java @@ -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; /** *

@@ -18,4 +50,144 @@ import javax.annotation.Resource; */ @Service public class LawsClubJoinTeamServiceImpl extends ServiceImpl 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 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 fileMap = multipartRequest.getFileMap(); + List lawsClubJoinTeamList = new ArrayList<>(); + for (Map.Entry entity : fileMap.entrySet()) { + MultipartFile file = entity.getValue();// 获取上传文件对象 + try { + ImportParams params = new ImportParams(); + params.setNeedSave(true); + List 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 excelList) { + StringBuilder msg = new StringBuilder(); + // 拿到这个流程的名称 + List specializedModuleList = sysDictService.getDictItems("professional_module"); + Map 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 = sysUserService.list(new LambdaQueryWrapper().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 = sysDepartService.list(new LambdaQueryWrapper().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 = sysUserService.list(new LambdaQueryWrapper().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("
"); + } + } + return msg; + } + + // 错误消息格式化 + private String getErrorMsg(int rowIndex, String errorMsg) { + return "第" + (rowIndex + 4) + "行" + errorMsg; + } + } diff --git a/laws-modules/src/main/java/com/jero/modules/laws/club/service/impl/LawsClubMeetingServiceImpl.java b/laws-modules/src/main/java/com/jero/modules/laws/club/service/impl/LawsClubMeetingServiceImpl.java index cd66fa7b..f52bd631 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/club/service/impl/LawsClubMeetingServiceImpl.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/club/service/impl/LawsClubMeetingServiceImpl.java @@ -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; /** *

@@ -17,4 +29,38 @@ import org.springframework.stereotype.Service; @Service public class LawsClubMeetingServiceImpl extends ServiceImpl 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 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; + } } diff --git a/laws-modules/src/main/java/com/jero/modules/laws/club/service/impl/LawsClubResearchInformationServiceImpl.java b/laws-modules/src/main/java/com/jero/modules/laws/club/service/impl/LawsClubResearchInformationServiceImpl.java index 95cd1c92..33c09c33 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/club/service/impl/LawsClubResearchInformationServiceImpl.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/club/service/impl/LawsClubResearchInformationServiceImpl.java @@ -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; /** *

@@ -17,4 +53,182 @@ import org.springframework.stereotype.Service; @Service public class LawsClubResearchInformationServiceImpl extends ServiceImpl 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 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 fileMap = multipartRequest.getFileMap(); + List lawsClubResearchInformationList = new ArrayList<>(); + for (Map.Entry entity : fileMap.entrySet()) { + MultipartFile file = entity.getValue();// 获取上传文件对象 + try { + ImportParams params = new ImportParams(); + params.setNeedSave(true); + List 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 excelList) { + StringBuilder msg = new StringBuilder(); + // 拿到这个流程的名称 + List specializedModuleList = sysDictService.getDictItems("professional_module"); + List clubTaskSourceList = sysDictService.getDictItems("club_task_source"); + Map specializedModuleMap = specializedModuleList.stream().collect(Collectors.toMap(DictModel::getText, DictModel::getValue)); + Map 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().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().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 = sysDepartService.list(new LambdaQueryWrapper().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("
"); + } + } + 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 + } } diff --git a/laws-modules/src/main/java/com/jero/modules/laws/club/service/impl/LawsClubServiceImpl.java b/laws-modules/src/main/java/com/jero/modules/laws/club/service/impl/LawsClubServiceImpl.java index a99d77ed..d5f95f75 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/club/service/impl/LawsClubServiceImpl.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/club/service/impl/LawsClubServiceImpl.java @@ -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 implements ILawsClubService { @Resource @@ -72,6 +78,8 @@ public class LawsClubServiceImpl extends ServiceImpl i private ISysUserService sysUserService; @Resource private ISysDepartService sysDepartService; + @Value("${jero.path.exportExcelTempPath}") + private String exportExcelTempPath; @Override public List getTreeStructure(String parentId, String nodeType) { @@ -522,8 +530,7 @@ public class LawsClubServiceImpl extends ServiceImpl 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 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 i excelList = lawsClubResearchInformationService.list(new LambdaQueryWrapper().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 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 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 i Map fileMap = multipartRequest.getFileMap(); for (Map.Entry 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 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 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 i // 校验Excel数据 private StringBuilder validateExcelData(List 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().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("
"); } @@ -653,168 +690,9 @@ public class LawsClubServiceImpl extends ServiceImpl i return msg; } - private void validateParentNode(LawsClubExcel lawsClubExcel, StringBuilder msgSub, List excelList) { - String parentId = lawsClubExcel.getParentId(); - if (StringUtils.isBlank(parentId)) { - msgSub.append(getErrorMsg(excelList, lawsClubExcel, "上级节点不能为空;")); - } else { - LawsClub club = getOne(new LambdaQueryWrapper().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 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 teamList, StringBuilder msgSub, LawsClubExcel lawsClubExcel, List excelList) { - if (CollectionUtils.isEmpty(teamList)) return; - for (LawsClubJoinTeamExcel team : teamList) { - String proposerId = team.getProposerId(); - String departId = team.getDepartId(); - if (StringUtils.isNotBlank(proposerId)) { - List sysUser = sysUserService.list(new LambdaQueryWrapper().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 = sysDepartService.list(new LambdaQueryWrapper().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 meetings, StringBuilder msgSub, LawsClubExcel lawsClubExcel, List excelList) { - if (CollectionUtils.isEmpty(meetings)) return; - - for (LawsClubMeetingImportExcel meeting : meetings) { - validateDateFormat(meeting.getMeetingDate(), "参会信息的会议日期格式不正确;", msgSub, excelList, lawsClubExcel); - } - } - - private void validateResearchInfo(List researchList, StringBuilder msgSub, LawsClubExcel lawsClubExcel, List 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 payments, StringBuilder msgSub, LawsClubExcel lawsClubExcel, List 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 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 excelList) { - for (LawsClubExcel lawsClubExcel : excelList) { - LawsClub lawsClub = new LawsClub(); - BeanUtils.copyProperties(lawsClubExcel, lawsClub); - // 转换和保存数据 - List joinTeamList = convertList(lawsClubExcel.getLawsClubJoinTeamList(), this::convertToJoinTeam); - List paymentList = convertList(lawsClubExcel.getLawsClubPayment(), this::convertToPayment); - List meetingList = convertList(lawsClubExcel.getLawsClubMeetings(), this::convertToMeeting); - List researchInfoList = convertList(lawsClubExcel.getLawsClubResearchInformations(), this::convertToResearchInformation); - save(lawsClub); - saveAssociationTable(lawsClub, joinTeamList, paymentList, meetingList, researchInfoList, null); - } - } - // 错误消息格式化 - private String getErrorMsg(List 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 List convertList(List sourceList, Function 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; } } diff --git a/laws-modules/src/main/java/com/jero/modules/laws/club/utils/ExcelUtil.java b/laws-modules/src/main/java/com/jero/modules/laws/club/utils/ExcelUtil.java new file mode 100644 index 00000000..51cd0e6c --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/club/utils/ExcelUtil.java @@ -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 createLawsTags(String fieldTxts, String mustInputFlags, String fieldTypeLists) { + List 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 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 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 ""; + } +} \ No newline at end of file diff --git a/laws-modules/src/main/java/com/jero/modules/laws/club/vo/excel/LawsClubExcel.java b/laws-modules/src/main/java/com/jero/modules/laws/club/vo/excel/LawsClubExcel.java index 8ffc39cb..18506ab0 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/club/vo/excel/LawsClubExcel.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/club/vo/excel/LawsClubExcel.java @@ -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 lawsClubJoinTeamList; - - @ExcelCollection(name = "参会信息") - private List lawsClubMeetings; - - @ExcelCollection(name = "支付信息") - private List lawsClubPayment; - - @ExcelCollection(name = "征集调研信息") - private List lawsClubResearchInformations; - } diff --git a/laws-modules/src/main/java/com/jero/modules/laws/club/vo/excel/LawsClubJoinTeamExcel.java b/laws-modules/src/main/java/com/jero/modules/laws/club/vo/excel/LawsClubJoinTeamExcel.java index a3633b8d..382e75b9 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/club/vo/excel/LawsClubJoinTeamExcel.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/club/vo/excel/LawsClubJoinTeamExcel.java @@ -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; + } diff --git a/laws-modules/src/main/java/com/jero/modules/laws/club/vo/excel/LawsClubMeetingExcel.java b/laws-modules/src/main/java/com/jero/modules/laws/club/vo/excel/LawsClubMeetingExcel.java new file mode 100644 index 00000000..d0ba18f5 --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/club/vo/excel/LawsClubMeetingExcel.java @@ -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 meetingMemberList; + +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/club/vo/excel/LawsClubMeetingImportExcel.java b/laws-modules/src/main/java/com/jero/modules/laws/club/vo/excel/LawsClubMeetingImportExcel.java deleted file mode 100644 index 3291b5b7..00000000 --- a/laws-modules/src/main/java/com/jero/modules/laws/club/vo/excel/LawsClubMeetingImportExcel.java +++ /dev/null @@ -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; - -} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/club/vo/excel/LawsClubMeetingMemberExcel.java b/laws-modules/src/main/java/com/jero/modules/laws/club/vo/excel/LawsClubMeetingMemberExcel.java new file mode 100644 index 00000000..6935c106 --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/club/vo/excel/LawsClubMeetingMemberExcel.java @@ -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; +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/club/vo/excel/LawsClubPaymentExcel.java b/laws-modules/src/main/java/com/jero/modules/laws/club/vo/excel/LawsClubPaymentExcel.java index 6399de2a..443b4d63 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/club/vo/excel/LawsClubPaymentExcel.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/club/vo/excel/LawsClubPaymentExcel.java @@ -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; diff --git a/laws-modules/src/main/java/com/jero/modules/laws/club/vo/excel/LawsClubResearchInformationExcel.java b/laws-modules/src/main/java/com/jero/modules/laws/club/vo/excel/LawsClubResearchInformationExcel.java index d657930c..4ea79af3 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/club/vo/excel/LawsClubResearchInformationExcel.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/club/vo/excel/LawsClubResearchInformationExcel.java @@ -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; }