update:新增支付信息,工作组文件导入导出;修改导出全部;修改会议导入
This commit is contained in:
@@ -223,5 +223,7 @@ public class ResultCommon {
|
||||
public static final String NODE_EXIST_SUBSETS = "node.exist.subsets";
|
||||
// 社团名称不能重复
|
||||
public static final String CLUB_ALREADY_EXISTS = "club.already.exists";
|
||||
// 根节点不能删除
|
||||
public static final String ROOT_NODE_CANNOT_BE_DELETE = "root.node.cannot.be.delete"; // 根节点不能编辑
|
||||
|
||||
}
|
||||
|
||||
+10
-1
@@ -1,6 +1,8 @@
|
||||
package com.jero.modules.laws.club.config;
|
||||
|
||||
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
|
||||
import org.apache.poi.hssf.usermodel.HSSFFont;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.jeecgframework.poi.excel.export.styler.ExcelExportStylerDefaultImpl;
|
||||
@@ -17,8 +19,15 @@ public class CustomExcelExportStyler extends ExcelExportStylerDefaultImpl {
|
||||
// 设置标题的左对齐样式
|
||||
@Override
|
||||
public HSSFCellStyle getHeaderStyle(short color) {
|
||||
HSSFCellStyle headerStyle = (HSSFCellStyle) super.getHeaderStyle(color);
|
||||
HSSFCellStyle headerStyle = (HSSFCellStyle) super.getHeaderStyle(color); // 确保 getHeaderStyle 返回的是 HSSFCellStyle
|
||||
headerStyle.setAlignment(HorizontalAlignment.LEFT); // 左对齐
|
||||
// 将 workbook 转换为 HSSFWorkbook,以便创建 HSSFFont
|
||||
if (workbook instanceof HSSFWorkbook) {
|
||||
HSSFWorkbook hssfWorkbook = (HSSFWorkbook) workbook;
|
||||
HSSFFont font = hssfWorkbook.createFont(); // 创建 HSSFFont
|
||||
font.setFontHeightInPoints((short) 10); // 设置字体大小为10
|
||||
headerStyle.setFont(font); // 将字体设置到样式中
|
||||
}
|
||||
return headerStyle;
|
||||
}
|
||||
}
|
||||
|
||||
+26
-4
@@ -141,8 +141,8 @@ public class LawsClubController extends JeroController<LawsClub, ILawsClubServic
|
||||
@ApiOperation(value="社团管理-导出", notes="社团管理-导出")
|
||||
@GetMapping(value = "/exportXls")
|
||||
@RequiresPermissions("clubManagement:clubManagement:export")
|
||||
public ModelAndView exportAll(LawsClub lawsClub, HttpServletRequest request) {
|
||||
return lawsClubService.exportAll(lawsClub,request);
|
||||
public void exportAll(LawsClub lawsClub, HttpServletRequest request, HttpServletResponse response) {
|
||||
lawsClubService.exportAll(lawsClub,request, response);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,6 +156,17 @@ public class LawsClubController extends JeroController<LawsClub, ILawsClubServic
|
||||
return lawsClubService.exportTeamXls(lawsClub,request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出支付信息
|
||||
*/
|
||||
@AutoLog(value = "社团管理-导出支付信息")
|
||||
@ApiOperation(value="社团管理-导出支付信息", notes="社团管理-导出支付信息")
|
||||
@GetMapping(value = "/exportPaymentXls")
|
||||
@RequiresPermissions("clubManagement:clubManagement:exportPaymentInformation")
|
||||
public ModelAndView exportPaymentXls(LawsClub lawsClub, HttpServletRequest request) {
|
||||
return lawsClubService.exportPaymentXls(lawsClub,request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出参会信息
|
||||
*/
|
||||
@@ -163,8 +174,19 @@ public class LawsClubController extends JeroController<LawsClub, ILawsClubServic
|
||||
@ApiOperation(value="社团管理-导出参会信息", notes="社团管理-导出参会信息")
|
||||
@GetMapping(value = "/exportMeetingXls")
|
||||
@RequiresPermissions("clubManagement:clubManagement:exportConferenceInformation")
|
||||
public ModelAndView exportMeetingXls(LawsClub lawsClub, HttpServletRequest request) {
|
||||
return lawsClubService.exportMeetingXls(lawsClub,request);
|
||||
public void exportMeetingXls(LawsClub lawsClub, HttpServletRequest request, HttpServletResponse response) {
|
||||
lawsClubService.exportMeetingXls(lawsClub,request,response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出工作组资料
|
||||
*/
|
||||
@AutoLog(value = "社团管理-导出工作组资料")
|
||||
@ApiOperation(value="社团管理-导出工作组资料", notes="社团管理-导出工作组资料")
|
||||
@GetMapping(value = "/exportWorkingGroupFileXls")
|
||||
@RequiresPermissions("clubManagement:clubManagement:exportWorkgroupData")
|
||||
public void exportWorkingGroupFileXls(LawsClub lawsClub, HttpServletRequest request, HttpServletResponse response) {
|
||||
lawsClubService.exportWorkingGroupFileXls(lawsClub,request,response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+56
@@ -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.common.aspect.annotation.Translation;
|
||||
import com.jero.modules.laws.club.service.ILawsClubPaymentService;
|
||||
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/payment")
|
||||
@Slf4j
|
||||
public class LawsClubJoinPaymentController {
|
||||
|
||||
@Resource
|
||||
private ILawsClubPaymentService lawsClubPaymentService;
|
||||
|
||||
/**
|
||||
* 模板下载
|
||||
*/
|
||||
@AutoLog(value = "社团管理-支付信息表-模板下载")
|
||||
@ApiOperation(value="社团管理-支付信息表-模板下载", notes="社团管理-支付信息表-模板下载")
|
||||
@GetMapping(value = "/exportTemplate")
|
||||
public void exportTemplate(HttpServletRequest request, HttpServletResponse response) {
|
||||
lawsClubPaymentService.exportTemplate(request,response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入
|
||||
*/
|
||||
@AutoLog(value = "社团管理-支付信息表-导入")
|
||||
@ApiOperation(value="社团管理-支付信息表-导入", notes="社团管理-支付信息表-导入")
|
||||
@PostMapping(value = "/importExcel")
|
||||
@Translation
|
||||
public Result<?> excelimport(HttpServletRequest request) {
|
||||
return lawsClubPaymentService.importExcel(request);
|
||||
}
|
||||
|
||||
}
|
||||
+56
@@ -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.common.aspect.annotation.Translation;
|
||||
import com.jero.modules.laws.club.service.ILawsClubWorkingGroupFileService;
|
||||
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/workingGroupFile")
|
||||
@Slf4j
|
||||
public class LawsClubWorkingGroupFileController {
|
||||
|
||||
@Resource
|
||||
private ILawsClubWorkingGroupFileService lawsClubWorkingGroupFileService;
|
||||
|
||||
/**
|
||||
* 模板下载
|
||||
*/
|
||||
@AutoLog(value = "社团管理-工作组资料表-模板下载")
|
||||
@ApiOperation(value="社团管理-参会信息表-模板下载", notes="社团管理-参会信息表-模板下载")
|
||||
@GetMapping(value = "/exportTemplate")
|
||||
public void exportTemplate(HttpServletRequest request, HttpServletResponse response) {
|
||||
lawsClubWorkingGroupFileService.exportTemplate(request,response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入
|
||||
*/
|
||||
@AutoLog(value = "社团管理-工作组资料表-导入")
|
||||
@ApiOperation(value="社团管理-参会信息表-导入", notes="社团管理-参会信息表-导入")
|
||||
@PostMapping(value = "/importExcel")
|
||||
@Translation
|
||||
public Result<?> excelimport(HttpServletRequest request) {
|
||||
return lawsClubWorkingGroupFileService.importExcel(request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
/**
|
||||
@@ -35,17 +36,21 @@ public class LawsClubPayment implements Serializable {
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(value = "社团id")
|
||||
@Excel(name = "社团名称", width = 20, dicText = "club_name", dicCode = "id", dictTable = "laws_club")
|
||||
private String clubId;
|
||||
|
||||
@ApiModelProperty(value = "缴费金额")
|
||||
@Excel(name = "缴费金额", width = 20)
|
||||
private String paymentAmount;
|
||||
|
||||
@ApiModelProperty(value = "缴费时间")
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd")
|
||||
@Excel(name = "缴费时间", width = 20, format = "yyyy-MM-dd")
|
||||
private Date paymentTime;
|
||||
|
||||
@ApiModelProperty(value = "备注")
|
||||
@Excel(name = "备注", width = 20)
|
||||
private String remark;
|
||||
|
||||
@ApiModelProperty(value = "创建人")
|
||||
|
||||
+4
@@ -12,6 +12,7 @@ import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
/**
|
||||
@@ -36,14 +37,17 @@ public class LawsClubWorkingGroupFile implements Serializable {
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(value = "社团id")
|
||||
@Excel(name = "社团名称", width = 20, dicText = "club_name", dicCode = "id", dictTable = "laws_club")
|
||||
private String clubId;
|
||||
|
||||
@ApiModelProperty(value = "文件id")
|
||||
@Dict(dictTable = "oss_file", dicCode = "id", dicText = "file_name")
|
||||
@Excel(name = "文件名称", width = 20, dicText = "file_name", dicCode = "id", dictTable = "oss_file")
|
||||
private String fileId;
|
||||
|
||||
@ApiModelProperty(value = "文件类型 1:报批稿 2:送审稿 3:征求意见稿 4:月报 5:咨询月报 6:会议资料 7:通知 8:其他")
|
||||
@Dict(dicCode = "club_file_type")
|
||||
@Excel(name = "文件类型", width = 20, dicCode = "club_file_type")
|
||||
private String fileType;
|
||||
|
||||
@ApiModelProperty(value = "创建人")
|
||||
|
||||
@@ -5,7 +5,8 @@ public enum FieldTypeEnum {
|
||||
|
||||
TEXT_INPUT("文本输入","1","文本输入"),
|
||||
DATE_INPUT("日期输入","2","日期输入"),
|
||||
TEXT_INPUT_NAME("文本输入,姓名(工号)","3","文本输入,姓名(工号)")
|
||||
TEXT_INPUT_NAME("文本输入,姓名(工号)","3","文本输入,姓名(工号)"),
|
||||
FILE_UPLOAD("文件上传","4","文件上传"),
|
||||
;
|
||||
|
||||
final String name;
|
||||
|
||||
+6
@@ -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.LawsClubPayment;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -13,4 +16,7 @@ import com.jero.modules.laws.club.entity.LawsClubPayment;
|
||||
*/
|
||||
public interface ILawsClubPaymentService extends IService<LawsClubPayment> {
|
||||
|
||||
void exportTemplate(HttpServletRequest request, HttpServletResponse response);
|
||||
|
||||
Result<?> importExcel(HttpServletRequest request);
|
||||
}
|
||||
|
||||
@@ -31,9 +31,9 @@ public interface ILawsClubService extends IService<LawsClub> {
|
||||
|
||||
IPage<LawsClub> queryPageList(LawsClub lawsClub, Integer pageNo, Integer pageSize, HttpServletRequest req);
|
||||
|
||||
ModelAndView exportAll(LawsClub lawsClub, HttpServletRequest request);
|
||||
void exportAll(LawsClub lawsClub, HttpServletRequest request, HttpServletResponse response);
|
||||
|
||||
ModelAndView exportMeetingXls(LawsClub lawsClub, HttpServletRequest request);
|
||||
void exportMeetingXls(LawsClub lawsClub, HttpServletRequest request, HttpServletResponse response);
|
||||
|
||||
ModelAndView exportresearchXls(LawsClub lawsClub, HttpServletRequest request);
|
||||
|
||||
@@ -42,4 +42,8 @@ public interface ILawsClubService extends IService<LawsClub> {
|
||||
Result<?> importExcel(HttpServletRequest request);
|
||||
|
||||
List<LawsClubTreeNodeModel> getTreeStructure(String part, String nodeType);
|
||||
|
||||
ModelAndView exportPaymentXls(LawsClub lawsClub, HttpServletRequest request);
|
||||
|
||||
void exportWorkingGroupFileXls(LawsClub lawsClub, HttpServletRequest request, HttpServletResponse response);
|
||||
}
|
||||
|
||||
+6
@@ -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.LawsClubWorkingGroupFile;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -13,4 +16,7 @@ import com.jero.modules.laws.club.entity.LawsClubWorkingGroupFile;
|
||||
*/
|
||||
public interface ILawsClubWorkingGroupFileService extends IService<LawsClubWorkingGroupFile> {
|
||||
|
||||
void exportTemplate(HttpServletRequest request, HttpServletResponse response);
|
||||
|
||||
Result<?> importExcel(HttpServletRequest request);
|
||||
}
|
||||
|
||||
+35
-7
@@ -19,12 +19,14 @@ 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 lombok.extern.slf4j.Slf4j;
|
||||
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.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
@@ -38,6 +40,8 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -49,6 +53,8 @@ import java.util.stream.Collectors;
|
||||
* @since 2024-08-29
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional(rollbackFor = JeroBootException.class)
|
||||
public class LawsClubJoinTeamServiceImpl extends ServiceImpl<LawsClubJoinTeamMapper, LawsClubJoinTeam> implements ILawsClubJoinTeamService {
|
||||
|
||||
@Resource
|
||||
@@ -74,7 +80,7 @@ public class LawsClubJoinTeamServiceImpl extends ServiceImpl<LawsClubJoinTeamMap
|
||||
"2.导入数据从第四行开始,第一行为表头,第二行为填写说明,第三行为示例。第四行才是正式数据";
|
||||
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代表日期输入
|
||||
String fieldTypeLists = "2,3,1,1,1,1,3,1,1,1"; // 1代表是文本输入类型 2代表日期输入
|
||||
List<LawsTag> lawsTags = ExcelUtil.createLawsTags(fieldTxts, mustInputFlags, fieldTypeLists);
|
||||
try (Workbook workbook = ExcelUtil.createWorkBookWithLawsTags(lawsTags, "入团信息", describe);
|
||||
OutputStream out = response.getOutputStream()) {
|
||||
@@ -165,11 +171,13 @@ public class LawsClubJoinTeamServiceImpl extends ServiceImpl<LawsClubJoinTeamMap
|
||||
}
|
||||
// 校验职务担任人
|
||||
if (StringUtils.isNotBlank(lawsClubJoinTeamExcel.getLeadId())) {
|
||||
List<SysUser> sysUser = sysUserService.list(new LambdaQueryWrapper<SysUser>().eq(SysUser::getRealname, lawsClubJoinTeamExcel.getLeadId()));
|
||||
if (CollectionUtils.isEmpty(sysUser)) {
|
||||
String leadName = extractEmployeeId(lawsClubJoinTeamExcel.getLeadId());
|
||||
String fullName = extractFullName(lawsClubJoinTeamExcel.getLeadId());
|
||||
SysUser sysUser = sysUserService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUsername, leadName).eq(SysUser::getRealname,fullName),false);
|
||||
if (Objects.isNull(sysUser)) {
|
||||
msgSub.append(getErrorMsg(i, "社团职务担任者不存在;"));
|
||||
}else {
|
||||
lawsClubJoinTeamExcel.setLeadId(sysUser.get(0).getId());
|
||||
lawsClubJoinTeamExcel.setLeadId(sysUser.getId());
|
||||
}
|
||||
}
|
||||
// 校验部门名称
|
||||
@@ -192,11 +200,13 @@ public class LawsClubJoinTeamServiceImpl extends ServiceImpl<LawsClubJoinTeamMap
|
||||
}
|
||||
// 校验申请人
|
||||
if (StringUtils.isNotBlank(lawsClubJoinTeamExcel.getProposerId())) {
|
||||
List<SysUser> sysUser = sysUserService.list(new LambdaQueryWrapper<SysUser>().eq(SysUser::getRealname, lawsClubJoinTeamExcel.getProposerId()));
|
||||
if (CollectionUtils.isEmpty(sysUser)) {
|
||||
String proposerName = extractEmployeeId(lawsClubJoinTeamExcel.getProposerId());
|
||||
String fullName = extractFullName(lawsClubJoinTeamExcel.getProposerId());
|
||||
SysUser sysUser = sysUserService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUsername, proposerName).eq(SysUser::getRealname,fullName),false);
|
||||
if (Objects.isNull(sysUser)) {
|
||||
msgSub.append(getErrorMsg(i, "申请人不存在;"));
|
||||
}else {
|
||||
lawsClubJoinTeamExcel.setProposerId(sysUser.get(0).getId());
|
||||
lawsClubJoinTeamExcel.setProposerId(sysUser.getId());
|
||||
}
|
||||
}
|
||||
if (msgSub.length() > 0) {
|
||||
@@ -225,4 +235,22 @@ public class LawsClubJoinTeamServiceImpl extends ServiceImpl<LawsClubJoinTeamMap
|
||||
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
|
||||
}
|
||||
|
||||
private String extractFullName(String notifierId) {
|
||||
int startIndex = notifierId.indexOf('(');
|
||||
if (startIndex != -1) {
|
||||
return notifierId.substring(0, startIndex).trim(); // 提取括号前的部分并去除前后的空格
|
||||
}
|
||||
return notifierId; // 如果没有括号,则返回整个字符串
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+25
-81
@@ -13,6 +13,7 @@ import com.jero.modules.laws.club.mapper.LawsClubMeetingMapper;
|
||||
import com.jero.modules.laws.club.service.ILawsClubMeetingService;
|
||||
import com.jero.modules.laws.club.service.RolePermissionService;
|
||||
import com.jero.modules.laws.club.utils.ExcelUtil;
|
||||
import com.jero.modules.laws.club.utils.ZipUtils;
|
||||
import com.jero.modules.laws.club.vo.excel.LawsClubMeetingExcel;
|
||||
import com.jero.modules.laws.club.vo.excel.LawsClubMeetingMemberExcel;
|
||||
import com.jero.modules.oss.entity.OSSFile;
|
||||
@@ -25,15 +26,17 @@ 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.io.FileUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.tools.zip.ZipEntry;
|
||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||
import org.jeecgframework.poi.excel.entity.ImportParams;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
@@ -46,12 +49,10 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
/**
|
||||
@@ -63,6 +64,8 @@ import java.util.zip.ZipOutputStream;
|
||||
* @since 2024-08-29
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional(rollbackFor = JeroBootException.class)
|
||||
public class LawsClubMeetingServiceImpl extends ServiceImpl<LawsClubMeetingMapper, LawsClubMeeting> implements ILawsClubMeetingService {
|
||||
|
||||
@Resource
|
||||
@@ -95,7 +98,7 @@ public class LawsClubMeetingServiceImpl extends ServiceImpl<LawsClubMeetingMappe
|
||||
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代表文本输入, 姓名(工号)
|
||||
String fieldTypeLists = "1,2,1,1,2,3,1,1,1,1,1,3,1,1,4,1"; // 1代表文本输入类型, 2代表日期输入, 3代表文本输入, 姓名(工号)
|
||||
List<LawsTag> lawsTags = ExcelUtil.createLawsTags(fieldTxts, mustInputFlags, fieldTypeLists);
|
||||
// 生成 Excel 文件并写入字节数组
|
||||
try (Workbook workbook = ExcelUtil.createWorkBookWithLawsTags(lawsTags, "参会信息", describe);
|
||||
@@ -107,7 +110,13 @@ public class LawsClubMeetingServiceImpl extends ServiceImpl<LawsClubMeetingMappe
|
||||
ByteArrayOutputStream baosZip = new ByteArrayOutputStream();
|
||||
try (ZipOutputStream zos = new ZipOutputStream(baosZip)) {
|
||||
// 将Excel文件放入ZIP包中的目录下
|
||||
ZipEntry entry = new ZipEntry( "参会信息导入模板.xls");
|
||||
String templateName = "";
|
||||
if(MessageUtils.getLanguage().getValue().equals(LanguageEnum.CN.getValue())){
|
||||
templateName = "参会信息导入模板.xls";
|
||||
}else{
|
||||
templateName = "Conference InformationImport Template.xls";
|
||||
}
|
||||
ZipEntry entry = new ZipEntry( templateName);
|
||||
zos.putNextEntry(entry);
|
||||
zos.write(excelBytes);
|
||||
zos.closeEntry();
|
||||
@@ -151,21 +160,23 @@ public class LawsClubMeetingServiceImpl extends ServiceImpl<LawsClubMeetingMappe
|
||||
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
||||
MultipartFile file = entity.getValue();// 获取上传文件对象
|
||||
try {
|
||||
Map<String, File> unZipFileMap = analyzeZipFile(file);
|
||||
String templateName = "";
|
||||
if(MessageUtils.getLanguage().getValue().equals(LanguageEnum.CN.getValue())){
|
||||
templateName = "参会信息导入模板.xls";
|
||||
}else{
|
||||
templateName = "Conference InformationImport Template.xls";
|
||||
}
|
||||
Map<String, File> unZipFileMap = ZipUtils.analyzeZipFile(file,uploadpath,templateName);
|
||||
saveDirectory = unZipFileMap.get("saveDirectory");
|
||||
// 移除键为 "saveDirectory" 的文件
|
||||
unZipFileMap.remove("saveDirectory");
|
||||
// 拿到excel的导入文件
|
||||
File meetingCnTemplate = unZipFileMap.get("参会信息导入模板.xls");
|
||||
File meetingEnTemplate = unZipFileMap.get("Conference InformationImport Template.xls");
|
||||
// 确定哪个文件不为空,并赋值给 excelImportFile
|
||||
File excelImportFile = (meetingCnTemplate != null) ? meetingCnTemplate : meetingEnTemplate;
|
||||
File templateFile = unZipFileMap.get(templateName);
|
||||
// 将模板文件移除
|
||||
unZipFileMap.remove("参会信息导入模板.xls");
|
||||
unZipFileMap.remove("Conference InformationImport Template.xls");
|
||||
unZipFileMap.remove(templateFile);
|
||||
ImportParams params = new ImportParams();
|
||||
params.setNeedSave(false);
|
||||
List<LawsClubMeetingExcel> excelList = ExcelImportUtil.importExcel(new FileInputStream(excelImportFile), LawsClubMeetingExcel.class, params);
|
||||
List<LawsClubMeetingExcel> excelList = ExcelImportUtil.importExcel(new FileInputStream(templateFile), LawsClubMeetingExcel.class, params);
|
||||
excelList = excelList.stream().skip(2).filter(item -> !Objects.isNull(item)).collect(Collectors.toList());
|
||||
if (CollectionUtils.isEmpty(excelList)) {
|
||||
throw new JeroBootException("没有数据可导入");
|
||||
@@ -203,73 +214,6 @@ public class LawsClubMeetingServiceImpl extends ServiceImpl<LawsClubMeetingMappe
|
||||
return Result.OK(lawsClubMeetingList);
|
||||
}
|
||||
|
||||
public Map<String, File> analyzeZipFile(MultipartFile file) throws IOException {
|
||||
int pos = file.getOriginalFilename().lastIndexOf(".");
|
||||
String str = file.getOriginalFilename().substring(pos+1).toLowerCase();
|
||||
String filenameorg = file.getOriginalFilename().substring(0,pos);
|
||||
String resultMsg = "";
|
||||
if (!str.equals("zip")) {
|
||||
if(MessageUtils.getLanguage().getValue().equals(LanguageEnum.CN.getValue())){
|
||||
resultMsg = "请上传zip文件";
|
||||
}else{
|
||||
resultMsg = "Please upload a zip file";
|
||||
}
|
||||
throw new JeroBootException(resultMsg);
|
||||
}
|
||||
String path = uploadpath + File.separator + "modal" + File.separator + filenameorg + System.currentTimeMillis();
|
||||
File saveDirectory = new File(path);
|
||||
if(!saveDirectory.isDirectory()){
|
||||
saveDirectory.mkdir();
|
||||
}
|
||||
FileUtils.copyInputStreamToFile(file.getInputStream(), new File(path +File.separator+ file.getOriginalFilename()));
|
||||
try {
|
||||
//解压缩
|
||||
String zipEntryName = FileUnZip.unZipFiles2(path +File.separator+ file.getOriginalFilename(), path);
|
||||
// 1.获取其中的文件,
|
||||
File zipFile = new File(zipEntryName);
|
||||
List<File> fileList = new ArrayList<>();
|
||||
if (zipFile.isDirectory()) {
|
||||
File[] files = zipFile.listFiles();
|
||||
for (File fi : files) {
|
||||
fileList.add(fi);
|
||||
}
|
||||
}
|
||||
if (fileList.size() < 1) {
|
||||
FileUnZip.deleteDir(saveDirectory);
|
||||
if(MessageUtils.getLanguage().getValue().equals(LanguageEnum.CN.getValue())){
|
||||
resultMsg = "没有可导入的数据,请检查!";
|
||||
}else{
|
||||
resultMsg = "No data to import, please check";
|
||||
}
|
||||
throw new JeroBootException(resultMsg);
|
||||
}
|
||||
Map<String, File> fileMap = fileList.stream().collect(Collectors.toMap(File::getName, Function.identity()));
|
||||
File meetingCnTemplate = fileMap.get("参会信息导入模板.xls");
|
||||
File meetingEnTemplate = fileMap.get("Conference InformationImport Template.xls");
|
||||
if (Objects.isNull(meetingCnTemplate) && Objects.isNull(meetingEnTemplate)) {
|
||||
//删除原上传文件
|
||||
FileUnZip.deleteDir(saveDirectory);
|
||||
if(MessageUtils.getLanguage().getValue().equals(LanguageEnum.CN.getValue())){
|
||||
resultMsg = "压缩包内没有Excel模板文件";
|
||||
}else{
|
||||
resultMsg = "In the cabinet did not upload the Excel template file";
|
||||
}
|
||||
throw new JeroBootException(resultMsg);
|
||||
}
|
||||
fileMap.put("saveDirectory", saveDirectory);
|
||||
return fileMap;
|
||||
} catch (StringIndexOutOfBoundsException e){
|
||||
//删除原上传文件
|
||||
FileUnZip.deleteDir(saveDirectory);
|
||||
if(MessageUtils.getLanguage().getValue().equals(LanguageEnum.CN.getValue())){
|
||||
resultMsg = "读取失败,压缩包内需要把所有导入文件放入一个父级文件夹下";
|
||||
}else{
|
||||
resultMsg = "The data fails to be read. In the compressed package, all imported files need to be placed in a parent folder";
|
||||
}
|
||||
throw new JeroBootException(resultMsg);
|
||||
}
|
||||
}
|
||||
|
||||
private StringBuilder validateExcelData(List<LawsClubMeetingExcel> meetingExcels, Map<String, File> unZipFileMap) throws IOException{
|
||||
StringBuilder msg = new StringBuilder();
|
||||
// 拿到这个流程的名称
|
||||
@@ -375,7 +319,7 @@ public class LawsClubMeetingServiceImpl extends ServiceImpl<LawsClubMeetingMappe
|
||||
FileInputStream input = new FileInputStream(file);
|
||||
MultipartFile multipartFile = new MockMultipartFile(file.getName(), file.getName(), "application/octet-stream", input);
|
||||
// 上传该文件
|
||||
Result<OSSFile> ossFileResult = iossFileService.commonUpload(multipartFile, "");
|
||||
Result<OSSFile> ossFileResult = iossFileService.commonUpload(multipartFile, "temp");
|
||||
lawsClubMeetingMemberExcel.setMeetingFileId(ossFileResult.getResult().getId());
|
||||
}
|
||||
}
|
||||
|
||||
+159
@@ -1,10 +1,39 @@
|
||||
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.common.api.vo.ResultCommon;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.modules.laws.club.entity.LawsClubPayment;
|
||||
import com.jero.modules.laws.club.mapper.LawsClubPaymentMapper;
|
||||
import com.jero.modules.laws.club.service.ILawsClubPaymentService;
|
||||
import com.jero.modules.laws.club.service.RolePermissionService;
|
||||
import com.jero.modules.laws.club.utils.ExcelUtil;
|
||||
import com.jero.modules.laws.club.vo.excel.LawsClubPaymentExcel;
|
||||
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.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.transaction.annotation.Transactional;
|
||||
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.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -15,6 +44,136 @@ import org.springframework.stereotype.Service;
|
||||
* @since 2024-08-29
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional(rollbackFor = JeroBootException.class)
|
||||
public class LawsClubPaymentServiceImpl extends ServiceImpl<LawsClubPaymentMapper, LawsClubPayment> implements ILawsClubPaymentService {
|
||||
|
||||
@Resource
|
||||
private RolePermissionService rolePermissionService;
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public void exportTemplate(HttpServletRequest request, HttpServletResponse response) {
|
||||
// 先验证权限, 只有有社团管理新增或修改的其中之一即可
|
||||
boolean result = validatingPermission();
|
||||
if (!result) {
|
||||
throw new JeroBootException(ResultCommon.NO_PERMISSION);
|
||||
}
|
||||
// 创建一个Excel工作簿
|
||||
String describe = "填写说明:\n" +
|
||||
"1.所有带星号的为必填\n" +
|
||||
"2.导入数据从第四行开始,第一行为表头,第二行为填写说明,第三行为示例。第四行才是正式数据";
|
||||
String fieldTxts = "缴费金额,缴费时间,备注";
|
||||
String mustInputFlags = "no,no,no";
|
||||
String fieldTypeLists = "2,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) {
|
||||
// 先验证权限, 只有有社团管理新增或修改的其中之一即可
|
||||
boolean result = validatingPermission();
|
||||
if (!result) {
|
||||
throw new JeroBootException(ResultCommon.NO_PERMISSION);
|
||||
}
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
||||
List<LawsClubPayment> lawsClubPaymentList = new ArrayList<>();
|
||||
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
||||
MultipartFile file = entity.getValue();// 获取上传文件对象
|
||||
try {
|
||||
ImportParams params = new ImportParams();
|
||||
params.setNeedSave(true);
|
||||
List<LawsClubPaymentExcel> excelList = ExcelImportUtil.importExcel(file.getInputStream(), LawsClubPaymentExcel.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 (LawsClubPaymentExcel lawsClubPaymentExcel : excelList) {
|
||||
LawsClubPayment lawsClubPayment = new LawsClubPayment();
|
||||
BeanUtils.copyProperties(lawsClubPaymentExcel, lawsClubPayment);
|
||||
lawsClubPayment.setPaymentTime(convertStringToDate(lawsClubPaymentExcel.getPaymentTime()));
|
||||
lawsClubPaymentList.add(lawsClubPayment);
|
||||
}
|
||||
}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(lawsClubPaymentList);
|
||||
}
|
||||
|
||||
// 校验Excel数据
|
||||
private StringBuilder validateExcelData(List<LawsClubPaymentExcel> excelList) {
|
||||
StringBuilder msg = new StringBuilder();
|
||||
for (int i = 0; i < excelList.size(); i++) {
|
||||
LawsClubPaymentExcel lawsClubPaymentExcel = excelList.get(i);
|
||||
StringBuilder msgSub = new StringBuilder();
|
||||
// 校验缴费日期格
|
||||
if (StringUtils.isNotBlank(lawsClubPaymentExcel.getPaymentTime())) {
|
||||
try {
|
||||
LocalDate.parse(lawsClubPaymentExcel.getPaymentTime());
|
||||
} catch (Exception e) {
|
||||
msgSub.append(getErrorMsg(i, "缴费日期格式不正确;"));
|
||||
}
|
||||
}
|
||||
if (msgSub.length() > 0) {
|
||||
msg.append(msgSub).append("</br>");
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
private boolean validatingPermission() {
|
||||
String addPermission = "clubManagement:clubManagement:add";
|
||||
String editPermission = "clubManagement:clubManagement:edit";
|
||||
boolean add = rolePermissionService.getRolePermission(addPermission);
|
||||
boolean edit = rolePermissionService.getRolePermission(editPermission);
|
||||
boolean result = add || edit;
|
||||
return result;
|
||||
}
|
||||
|
||||
private Date convertStringToDate(String dateStr) {
|
||||
if (StringUtils.isBlank(dateStr)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date date = simpleDateFormat.parse(dateStr);
|
||||
return date;
|
||||
}catch (Exception e) {
|
||||
log.error("日期转换异常");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 错误消息格式化
|
||||
private String getErrorMsg(int rowIndex, String errorMsg) {
|
||||
return "第" + (rowIndex + 4) + "行" + errorMsg;
|
||||
}
|
||||
}
|
||||
|
||||
+4
@@ -19,12 +19,14 @@ 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 lombok.extern.slf4j.Slf4j;
|
||||
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.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
@@ -51,6 +53,8 @@ import java.util.stream.Collectors;
|
||||
* @since 2024-08-29
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional(rollbackFor = JeroBootException.class)
|
||||
public class LawsClubResearchInformationServiceImpl extends ServiceImpl<LawsClubResearchInformationMapper, LawsClubResearchInformation> implements ILawsClubResearchInformationService {
|
||||
|
||||
@Resource
|
||||
|
||||
+202
-37
@@ -6,9 +6,11 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.api.vo.ResultCommon;
|
||||
import com.jero.common.constant.enums.LanguageEnum;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.base.controller.JeroController;
|
||||
import com.jero.common.util.*;
|
||||
import com.jero.common.util.obs.ObsBootUtil;
|
||||
import com.jero.modules.laws.club.config.CustomExcelExportStyler;
|
||||
import com.jero.modules.laws.club.entity.*;
|
||||
import com.jero.modules.laws.club.mapper.LawsClubMapper;
|
||||
@@ -16,11 +18,15 @@ 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.oss.entity.OSSFile;
|
||||
import com.jero.modules.oss.service.IOSSFileService;
|
||||
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.apache.tools.zip.ZipEntry;
|
||||
import org.jeecgframework.poi.excel.ExcelExportUtil;
|
||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
@@ -43,6 +49,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -71,6 +78,8 @@ public class LawsClubServiceImpl extends ServiceImpl<LawsClubMapper, LawsClub> i
|
||||
private ILawsClubResearchInformationService lawsClubResearchInformationService;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
private IOSSFileService iossFileService;
|
||||
|
||||
@Override
|
||||
public List<LawsClubTreeNodeModel> getTreeStructure(String parentId, String nodeType) {
|
||||
@@ -420,6 +429,10 @@ public class LawsClubServiceImpl extends ServiceImpl<LawsClubMapper, LawsClub> i
|
||||
if(StringUtils.isBlank(id)){
|
||||
return Result.error(ResultCommon.PLEASE_SELECT_DATA);
|
||||
}
|
||||
LawsClub lawsClub = getOne(new LambdaQueryWrapper<LawsClub>().eq(LawsClub::getId, id));
|
||||
if (!Objects.isNull(lawsClub) && "Part".equals(lawsClub.getParentId())) {
|
||||
return Result.error(ResultCommon.ROOT_NODE_CANNOT_BE_DELETE);
|
||||
}
|
||||
List<LawsClub> list = list(new LambdaQueryWrapper<LawsClub>().eq(LawsClub::getParentId, id));
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
return Result.error(ResultCommon.NODE_EXIST_SUBSETS);
|
||||
@@ -430,10 +443,8 @@ public class LawsClubServiceImpl extends ServiceImpl<LawsClubMapper, LawsClub> i
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelAndView exportAll(LawsClub lawsClub, HttpServletRequest request) {
|
||||
// Step.1 组装查询条件
|
||||
public void exportAll(LawsClub lawsClub, HttpServletRequest request, HttpServletResponse response) {
|
||||
LambdaQueryWrapper<LawsClub> lawsClubQueryWrapper = createLawsClubQueryWrapper(lawsClub);
|
||||
//Step.2 AutoPoi 导出Excel
|
||||
String selections = request.getParameter("selections");
|
||||
if(!oConvertUtils.isEmpty(selections)){
|
||||
lawsClubQueryWrapper.in(LawsClub::getId, Arrays.asList(selections.split(",")));
|
||||
@@ -441,6 +452,8 @@ public class LawsClubServiceImpl extends ServiceImpl<LawsClubMapper, LawsClub> i
|
||||
List<LawsClub> clubList = list(lawsClubQueryWrapper);
|
||||
List<LawsClubJoinTeam> lawsClubJoinTeams = new ArrayList<>();
|
||||
List<LawsClubMeeting> lawsClubMeetings = new ArrayList<>();
|
||||
List<LawsClubPayment> lawsClubPayments = new ArrayList<>();
|
||||
List<LawsClubWorkingGroupFile> lawsClubWorkingGroupFiles = new ArrayList<>();
|
||||
List<LawsClubResearchInformation> lawsClubResearchInformations = new ArrayList<>();
|
||||
for (LawsClub club : clubList) {
|
||||
// 如果是根节点那么上级节点为空
|
||||
@@ -454,66 +467,83 @@ public class LawsClubServiceImpl extends ServiceImpl<LawsClubMapper, LawsClub> i
|
||||
club.setContactNumber(encryptNumber);
|
||||
}
|
||||
}
|
||||
List<String> fileIdList = new ArrayList<>();
|
||||
List<String> ids = clubList.stream().map(LawsClub::getId).collect(Collectors.toList());
|
||||
if (!CollectionUtils.isEmpty(ids)) {
|
||||
lawsClubJoinTeams = lawsClubJoinTeamService.list(new LambdaQueryWrapper<LawsClubJoinTeam>().in(LawsClubJoinTeam::getClubId, ids));
|
||||
lawsClubMeetings = lawsClubMeetingService.list(new LambdaQueryWrapper<LawsClubMeeting>().in(LawsClubMeeting::getClubId, ids));
|
||||
lawsClubPayments = lawsClubPaymentService.list(new LambdaQueryWrapper<LawsClubPayment>().in(LawsClubPayment::getClubId, ids));
|
||||
for (LawsClubMeeting lawsClubMeeting : lawsClubMeetings) {
|
||||
List<LawsClubMeetingMember> memberList = lawsClubMeetingMemberService.list(new LambdaQueryWrapper<LawsClubMeetingMember>().eq(LawsClubMeetingMember::getMeetingId, lawsClubMeeting.getId()));
|
||||
List<String> meetingFileIds = memberList.stream().map(LawsClubMeetingMember::getMeetingFileId).filter(Objects::nonNull).collect(Collectors.toList());
|
||||
fileIdList.addAll(meetingFileIds);
|
||||
lawsClubMeeting.setMeetingMemberList(memberList);
|
||||
}
|
||||
lawsClubWorkingGroupFiles = lawsClubWorkingGroupFileService.list(new LambdaQueryWrapper<LawsClubWorkingGroupFile>().in(LawsClubWorkingGroupFile::getClubId, ids));
|
||||
List<String> fileIds = lawsClubWorkingGroupFiles.stream().map(LawsClubWorkingGroupFile::getFileId).filter(Objects::nonNull).collect(Collectors.toList());
|
||||
fileIdList.addAll(fileIds);
|
||||
lawsClubResearchInformations = lawsClubResearchInformationService.list(new LambdaQueryWrapper<LawsClubResearchInformation>().in(LawsClubResearchInformation::getClubId, ids));
|
||||
}
|
||||
//导出文件名称
|
||||
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
||||
mv.addObject(JeroController.FILE_NAME, "社团管理信息");
|
||||
List<Map<String, Object>> sheetList = new ArrayList<>();
|
||||
// 基本信息
|
||||
Map<String, Object> basicSheet = new HashMap<>();
|
||||
basicSheet.put(NormalExcelConstants.DATA_LIST, clubList);
|
||||
basicSheet.put(JeroController.CLASS, LawsClub.class);
|
||||
basicSheet.put(JeroController.PARAMS, createExportParams("密级:核心商密□普通商密□内部资料■外部公开□", "基本信息"));
|
||||
basicSheet.put(JeroController.FILE_NAME, "基本信息");
|
||||
basicSheet.put("entity", LawsClub.class);
|
||||
basicSheet.put("title", createExportParams("密级:核心商密□普通商密□内部资料■外部公开□", "基本信息"));
|
||||
sheetList.add(basicSheet);
|
||||
// 入团信息
|
||||
Map<String, Object> joinTeamSheet = new HashMap<>();
|
||||
joinTeamSheet.put(NormalExcelConstants.DATA_LIST, lawsClubJoinTeams);
|
||||
joinTeamSheet.put(JeroController.CLASS, LawsClubJoinTeam.class);
|
||||
joinTeamSheet.put(JeroController.PARAMS, createExportParams(null, "入团信息"));
|
||||
joinTeamSheet.put(JeroController.FILE_NAME, "入团信息");
|
||||
joinTeamSheet.put("title", createExportParams(null, "入团信息"));
|
||||
sheetList.add(joinTeamSheet);
|
||||
// 支付信息
|
||||
Map<String, Object> paymentSheet = new HashMap<>();
|
||||
paymentSheet.put(NormalExcelConstants.DATA_LIST, lawsClubPayments);
|
||||
paymentSheet.put(JeroController.CLASS, LawsClubPayment.class);
|
||||
paymentSheet.put("title", createExportParams(null, "支付信息"));
|
||||
sheetList.add(paymentSheet);
|
||||
// 参会信息
|
||||
Map<String, Object> meetingSheet = new HashMap<>();
|
||||
meetingSheet.put(NormalExcelConstants.DATA_LIST, lawsClubMeetings);
|
||||
meetingSheet.put(JeroController.CLASS, LawsClubMeeting.class);
|
||||
meetingSheet.put(JeroController.PARAMS, createExportParams(null, "参会信息"));
|
||||
meetingSheet.put(JeroController.FILE_NAME, "参会信息");
|
||||
meetingSheet.put("title", createExportParams(null, "参会信息"));
|
||||
sheetList.add(meetingSheet);
|
||||
// 工作组资料
|
||||
Map<String, Object> workingGroupFileSheet = new HashMap<>();
|
||||
workingGroupFileSheet.put(NormalExcelConstants.DATA_LIST, lawsClubWorkingGroupFiles);
|
||||
workingGroupFileSheet.put(JeroController.CLASS, LawsClubWorkingGroupFile.class);
|
||||
workingGroupFileSheet.put("title", createExportParams(null, "工作组资料"));
|
||||
sheetList.add(workingGroupFileSheet);
|
||||
// 征集调研信息
|
||||
Map<String, Object> researchSheet = new HashMap<>();
|
||||
researchSheet.put(NormalExcelConstants.DATA_LIST, lawsClubResearchInformations);
|
||||
researchSheet.put(JeroController.CLASS, LawsClubResearchInformation.class);
|
||||
researchSheet.put(JeroController.PARAMS, createExportParams(null, "征集调研信息"));
|
||||
researchSheet.put(JeroController.FILE_NAME, "征集调研信息");
|
||||
researchSheet.put("title", createExportParams(null, "征集调研信息"));
|
||||
sheetList.add(researchSheet);
|
||||
mv.addObject(NormalExcelConstants.MAP_LIST, sheetList);
|
||||
return mv;
|
||||
}
|
||||
|
||||
private ExportParams createExportParams(String title, String sheetName) {
|
||||
ExportParams exportParams = new ExportParams();
|
||||
exportParams.setTitle(title);
|
||||
exportParams.setType(ExcelType.HSSF);
|
||||
exportParams.setSheetName(sheetName);
|
||||
exportParams.setStyle(CustomExcelExportStyler.class); // 使用自定义的样式
|
||||
return exportParams;
|
||||
// 生成 Workbook
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(sheetList, ExcelType.HSSF);
|
||||
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
|
||||
// 将 Excel 写入到字节数组
|
||||
workbook.write(baos);
|
||||
byte[] excelBytes = baos.toByteArray();
|
||||
workbook.close();
|
||||
String excelName = "";
|
||||
if(MessageUtils.getLanguage().getValue().equals(LanguageEnum.CN.getValue())){
|
||||
excelName = "社团管理表.xls";
|
||||
}else{
|
||||
excelName = "Club Management Form.xls";
|
||||
}
|
||||
createZipWithAttachments(response, excelBytes, excelName, "参会信息", fileIdList);
|
||||
} catch (IOException e) {
|
||||
log.error("导出失败" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelAndView exportTeamXls(LawsClub lawsClub, HttpServletRequest request) {
|
||||
// Step.1 组装查询条件
|
||||
LambdaQueryWrapper<LawsClub> lawsClubQueryWrapper = createLawsClubQueryWrapper(lawsClub);
|
||||
//Step.2 AutoPoi 导出Excel
|
||||
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
||||
String selections = request.getParameter("selections");
|
||||
if(!oConvertUtils.isEmpty(selections)){
|
||||
@@ -534,10 +564,8 @@ public class LawsClubServiceImpl extends ServiceImpl<LawsClubMapper, LawsClub> i
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelAndView exportMeetingXls(LawsClub lawsClub, HttpServletRequest request) {
|
||||
// Step.1 组装查询条件
|
||||
public ModelAndView exportPaymentXls(LawsClub lawsClub, HttpServletRequest request) {
|
||||
LambdaQueryWrapper<LawsClub> lawsClubQueryWrapper = createLawsClubQueryWrapper(lawsClub);
|
||||
//Step.2 AutoPoi 导出Excel
|
||||
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
||||
String selections = request.getParameter("selections");
|
||||
if(!oConvertUtils.isEmpty(selections)){
|
||||
@@ -545,20 +573,91 @@ public class LawsClubServiceImpl extends ServiceImpl<LawsClubMapper, LawsClub> i
|
||||
}
|
||||
List<LawsClub> list = list(lawsClubQueryWrapper);
|
||||
List<String> ids = list.stream().map(LawsClub::getId).collect(Collectors.toList());
|
||||
List<LawsClubPayment> excelList = new ArrayList<>();
|
||||
if (!CollectionUtils.isEmpty(ids)) {
|
||||
excelList = lawsClubPaymentService.list(new LambdaQueryWrapper<LawsClubPayment>().in(LawsClubPayment::getClubId, ids));
|
||||
}
|
||||
//导出文件名称
|
||||
mv.addObject(JeroController.FILE_NAME, "支付信息统计表");
|
||||
mv.addObject(JeroController.CLASS, LawsClubPayment.class);
|
||||
mv.addObject(JeroController.PARAMS, createExportParams("密级:核心商密□普通商密□内部资料■外部公开□", "支付信息"));
|
||||
mv.addObject(NormalExcelConstants.DATA_LIST, excelList);
|
||||
return mv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportMeetingXls(LawsClub lawsClub, HttpServletRequest request, HttpServletResponse response) {
|
||||
LambdaQueryWrapper<LawsClub> lawsClubQueryWrapper = createLawsClubQueryWrapper(lawsClub);
|
||||
String selections = request.getParameter("selections");
|
||||
if(!oConvertUtils.isEmpty(selections)){
|
||||
lawsClubQueryWrapper.in(LawsClub::getId, Arrays.asList(selections.split(",")));
|
||||
}
|
||||
List<LawsClub> list = list(lawsClubQueryWrapper);
|
||||
List<String> ids = list.stream().map(LawsClub::getId).collect(Collectors.toList());
|
||||
List<LawsClubMeeting> excelList = new ArrayList<>();
|
||||
List<String> fileIdList = new ArrayList<>();
|
||||
if (!CollectionUtils.isEmpty(ids)) {
|
||||
excelList = lawsClubMeetingService.list(new LambdaQueryWrapper<LawsClubMeeting>().in(LawsClubMeeting::getClubId, ids));
|
||||
for (LawsClubMeeting lawsClubMeeting : excelList) {
|
||||
List<LawsClubMeetingMember> memberList = lawsClubMeetingMemberService.list(new LambdaQueryWrapper<LawsClubMeetingMember>().eq(LawsClubMeetingMember::getMeetingId, lawsClubMeeting.getId()));
|
||||
List<String> meetingFileIds = memberList.stream().map(LawsClubMeetingMember::getMeetingFileId).filter(Objects::nonNull).collect(Collectors.toList());
|
||||
fileIdList.addAll(meetingFileIds);
|
||||
lawsClubMeeting.setMeetingMemberList(memberList);
|
||||
}
|
||||
}
|
||||
//导出文件名称
|
||||
mv.addObject(JeroController.FILE_NAME, "参会记录表");
|
||||
mv.addObject(JeroController.CLASS, LawsClubMeeting.class);
|
||||
mv.addObject(JeroController.PARAMS, createExportParams("密级:核心商密□普通商密□内部资料■外部公开□", "参会信息"));
|
||||
mv.addObject(NormalExcelConstants.DATA_LIST, excelList);
|
||||
return mv;
|
||||
// 生成 Workbook
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(createExportParams("密级:核心商密□普通商密□内部资料■外部公开□", "参会信息"), LawsClubMeeting.class,excelList);
|
||||
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
|
||||
// 将 Excel 写入到字节数组
|
||||
workbook.write(baos);
|
||||
byte[] excelBytes = baos.toByteArray();
|
||||
workbook.close();
|
||||
String excelName = "";
|
||||
if(MessageUtils.getLanguage().getValue().equals(LanguageEnum.CN.getValue())){
|
||||
excelName = "参会信息表.xls";
|
||||
}else{
|
||||
excelName = "Participation Information Form.xls";
|
||||
}
|
||||
createZipWithAttachments(response, excelBytes, excelName, "参会信息", fileIdList);
|
||||
} catch (IOException e) {
|
||||
log.error("导出失败" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportWorkingGroupFileXls(LawsClub lawsClub, HttpServletRequest request, HttpServletResponse response) {
|
||||
// Step.1 组装查询条件
|
||||
LambdaQueryWrapper<LawsClub> lawsClubQueryWrapper = createLawsClubQueryWrapper(lawsClub);
|
||||
//Step.2 AutoPoi 导出Excel
|
||||
String selections = request.getParameter("selections");
|
||||
if(!oConvertUtils.isEmpty(selections)){
|
||||
lawsClubQueryWrapper.in(LawsClub::getId, Arrays.asList(selections.split(",")));
|
||||
}
|
||||
List<LawsClub> list = list(lawsClubQueryWrapper);
|
||||
List<String> ids = list.stream().map(LawsClub::getId).collect(Collectors.toList());
|
||||
List<LawsClubWorkingGroupFile> excelList = new ArrayList<>();
|
||||
if (!CollectionUtils.isEmpty(ids)) {
|
||||
excelList = lawsClubWorkingGroupFileService.list(new LambdaQueryWrapper<LawsClubWorkingGroupFile>().in(LawsClubWorkingGroupFile::getClubId, ids));
|
||||
}
|
||||
List<String> fileIdList = excelList.stream().map(LawsClubWorkingGroupFile::getFileId).filter(Objects::nonNull).collect(Collectors.toList());
|
||||
// 生成 Workbook
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(createExportParams("密级:核心商密□普通商密□内部资料■外部公开□", "工作组资料"), LawsClubWorkingGroupFile.class,excelList);
|
||||
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ByteArrayOutputStream baosZip = new ByteArrayOutputStream()) {
|
||||
// 将 Excel 写入到字节数组
|
||||
workbook.write(baos);
|
||||
byte[] excelBytes = baos.toByteArray();
|
||||
workbook.close();
|
||||
String excelName = "";
|
||||
if(MessageUtils.getLanguage().getValue().equals(LanguageEnum.CN.getValue())){
|
||||
excelName = "工作组资料表.xls";
|
||||
}else{
|
||||
excelName = "WorkingGroup File Form.xls";
|
||||
}
|
||||
createZipWithAttachments(response, excelBytes, excelName, "工作组资料", fileIdList);
|
||||
} catch (IOException e) {
|
||||
log.error("导出失败" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -595,7 +694,6 @@ public class LawsClubServiceImpl extends ServiceImpl<LawsClubMapper, LawsClub> i
|
||||
String fieldTxts = "上级节点,节点类型,社团名称,社团地址,社团联系人,联系电话,编号";
|
||||
String mustInputFlags = "yes,yes,yes,no,no,no,no";
|
||||
String fieldTypeLists = "1,1,1,1,1,1,1"; // 1 代表是文本输入类型
|
||||
boolean mergeAttendees = false;
|
||||
List<LawsTag> lawsTags = ExcelUtil.createLawsTags(fieldTxts, mustInputFlags, fieldTypeLists);
|
||||
try (Workbook workbook = ExcelUtil.createWorkBookWithLawsTags(lawsTags, "基础信息", describe);
|
||||
OutputStream out = response.getOutputStream()) {
|
||||
@@ -695,6 +793,73 @@ public class LawsClubServiceImpl extends ServiceImpl<LawsClubMapper, LawsClub> i
|
||||
return msg;
|
||||
}
|
||||
|
||||
private void createZipWithAttachments(HttpServletResponse response, byte[] excelBytes, String excelName, String zipFileName, List<String> fileIdList) throws IOException {
|
||||
try (ByteArrayOutputStream baosZip = new ByteArrayOutputStream();
|
||||
ZipOutputStream zos = new ZipOutputStream(baosZip)) {
|
||||
// 将 Excel 文件写入 ZIP
|
||||
ZipEntry entry = new ZipEntry(excelName);
|
||||
zos.putNextEntry(entry);
|
||||
zos.write(excelBytes);
|
||||
zos.closeEntry(); // 必须关闭当前的 ZipEntry
|
||||
// 创建 “附件” 文件夹并添加文件
|
||||
String folderPath = "附件/";
|
||||
Set<String> addedEntries = new HashSet<>();
|
||||
for (String fileId : fileIdList) {
|
||||
addFileToZip(fileId, zos, folderPath, addedEntries);
|
||||
}
|
||||
// 确保关闭所有条目后再关闭 ZipOutputStream
|
||||
zos.finish();
|
||||
// 设置 HTTP 响应头,处理文件名乱码
|
||||
response.setContentType("application/zip;charset=UTF-8");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
String encodedFileName = URLEncoder.encode(zipFileName, StandardCharsets.UTF_8.name()).replace("+", "%20");
|
||||
response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encodedFileName + ".zip");
|
||||
// 输出 ZIP 文件到响应流中
|
||||
try (OutputStream out = response.getOutputStream()) {
|
||||
baosZip.writeTo(out); // 将最终的 ZIP 字节流写入响应
|
||||
out.flush(); // 确保输出完整
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 将文件添加到 ZIP 中,放入指定的文件夹内,处理文件重复和 null 的情况
|
||||
private void addFileToZip(String fileId, ZipOutputStream zipos, String folderPath, Set<String> addedEntries) throws IOException {
|
||||
OSSFile ossFile = iossFileService.getById(fileId);
|
||||
if (ossFile == null) {
|
||||
return;
|
||||
}
|
||||
InputStream inputStream = ObsBootUtil.getOssFile(ossFile.getUrl());
|
||||
if (Objects.isNull(inputStream)) {
|
||||
return;
|
||||
}
|
||||
String entryPath = folderPath + ossFile.getFileName();
|
||||
if (addedEntries.contains(entryPath)) {
|
||||
return; // 如果文件已经被添加,跳过
|
||||
}
|
||||
zipos.putNextEntry(new ZipEntry(entryPath));
|
||||
try (InputStream is = inputStream) {
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length = is.read(buffer)) != -1) {
|
||||
zipos.write(buffer, 0, length);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
zipos.closeEntry();
|
||||
addedEntries.add(entryPath); // 记录已添加的文件,防止重复添加
|
||||
}
|
||||
|
||||
private ExportParams createExportParams(String title, String sheetName) {
|
||||
ExportParams exportParams = new ExportParams();
|
||||
exportParams.setTitle(title);
|
||||
exportParams.setType(ExcelType.HSSF);
|
||||
exportParams.setSheetName(sheetName);
|
||||
exportParams.setStyle(CustomExcelExportStyler.class); // 使用自定义的样式
|
||||
return exportParams;
|
||||
}
|
||||
|
||||
// 错误消息格式化
|
||||
private String getErrorMsg(int rowIndex, String errorMsg) {
|
||||
return "第" + (rowIndex + 4) + "行" + errorMsg;
|
||||
|
||||
+220
@@ -1,10 +1,51 @@
|
||||
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.common.api.vo.ResultCommon;
|
||||
import com.jero.common.constant.enums.LanguageEnum;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.vo.DictModel;
|
||||
import com.jero.common.util.MessageUtils;
|
||||
import com.jero.modules.laws.club.entity.LawsClubWorkingGroupFile;
|
||||
import com.jero.modules.laws.club.mapper.LawsClubWorkingGroupFileMapper;
|
||||
import com.jero.modules.laws.club.service.ILawsClubWorkingGroupFileService;
|
||||
import com.jero.modules.laws.club.service.RolePermissionService;
|
||||
import com.jero.modules.laws.club.utils.ExcelUtil;
|
||||
import com.jero.modules.laws.club.utils.ZipUtils;
|
||||
import com.jero.modules.laws.club.vo.excel.LawsClubWorkingGroupFileExcel;
|
||||
import com.jero.modules.oss.entity.OSSFile;
|
||||
import com.jero.modules.oss.service.IOSSFileService;
|
||||
import com.jero.modules.split.common.FileUnZip;
|
||||
import com.jero.modules.system.service.ISysDictService;
|
||||
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.Workbook;
|
||||
import org.apache.tools.zip.ZipEntry;
|
||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||
import org.jeecgframework.poi.excel.entity.ImportParams;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -15,6 +56,185 @@ import org.springframework.stereotype.Service;
|
||||
* @since 2024-08-29
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional(rollbackFor = JeroBootException.class)
|
||||
public class LawsClubWorkingGroupFileServiceImpl extends ServiceImpl<LawsClubWorkingGroupFileMapper, LawsClubWorkingGroupFile> implements ILawsClubWorkingGroupFileService {
|
||||
|
||||
@Resource
|
||||
private ISysDictService sysDictService;
|
||||
@Resource
|
||||
private IOSSFileService iossFileService;
|
||||
@Value(value = "${jero.path.upload}")
|
||||
private String uploadpath;
|
||||
@Resource
|
||||
private RolePermissionService rolePermissionService;
|
||||
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public void exportTemplate(HttpServletRequest request, HttpServletResponse response) {
|
||||
// 先验证权限, 只有有社团管理新增或修改的其中之一即可
|
||||
boolean result = validatingPermission();
|
||||
if (!result) {
|
||||
throw new JeroBootException(ResultCommon.NO_PERMISSION);
|
||||
}
|
||||
// 创建一个Excel工作簿
|
||||
String describe = "填写说明:\n" +
|
||||
"1.所有带星号的为必填\n" +
|
||||
"2.导入数据从第四行开始,第一行为表头,第二行为填写说明,第三行为示例。第四行才是正式数据";
|
||||
String fieldTxts = "文件名称,文件类型";
|
||||
String mustInputFlags = "no,no";
|
||||
String fieldTypeLists = "4,1"; // 1代表文本输入类型, 4代表文件上传
|
||||
List<LawsTag> lawsTags = ExcelUtil.createLawsTags(fieldTxts, mustInputFlags, fieldTypeLists);
|
||||
// 生成 Excel 文件并写入字节数组
|
||||
try (Workbook workbook = ExcelUtil.createWorkBookWithLawsTags(lawsTags, "工作组资料", describe);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
|
||||
// 将Excel写入到字节数组
|
||||
workbook.write(baos);
|
||||
byte[] excelBytes = baos.toByteArray();
|
||||
// 生成ZIP文件
|
||||
ByteArrayOutputStream baosZip = new ByteArrayOutputStream();
|
||||
try (ZipOutputStream zos = new ZipOutputStream(baosZip)) {
|
||||
// 将Excel文件放入ZIP包中的目录下
|
||||
String templateName = "";
|
||||
if(MessageUtils.getLanguage().getValue().equals(LanguageEnum.CN.getValue())){
|
||||
templateName = "工作组资料导入模板.xls";
|
||||
}else{
|
||||
templateName = "WorkingGroup File Template.xls";
|
||||
}
|
||||
ZipEntry entry = new ZipEntry( templateName);
|
||||
zos.putNextEntry(entry);
|
||||
zos.write(excelBytes);
|
||||
zos.closeEntry();
|
||||
}
|
||||
// 设置HTTP响应头
|
||||
response.setContentType("application/zip;charset=UTF-8");
|
||||
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 + ".zip");
|
||||
// 输出ZIP文件到响应流中
|
||||
try (OutputStream out = response.getOutputStream()) {
|
||||
baosZip.writeTo(out);
|
||||
out.flush();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("导出模板失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<?> importExcel(HttpServletRequest request) {
|
||||
// 先验证权限, 只有有社团管理新增或修改的其中之一即可
|
||||
boolean result = validatingPermission();
|
||||
if (!result) {
|
||||
throw new JeroBootException(ResultCommon.NO_PERMISSION);
|
||||
}
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
||||
List<LawsClubWorkingGroupFile> lawsClubWorkingGroupFileList = new ArrayList<>();
|
||||
File saveDirectory = null;
|
||||
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
||||
MultipartFile file = entity.getValue();// 获取上传文件对象
|
||||
try {
|
||||
String templateName = "";
|
||||
if(MessageUtils.getLanguage().getValue().equals(LanguageEnum.CN.getValue())){
|
||||
templateName = "工作组资料导入模板.xls";
|
||||
}else{
|
||||
templateName = "WorkingGroup File Template.xls";
|
||||
}
|
||||
Map<String, File> unZipFileMap = ZipUtils.analyzeZipFile(file, uploadpath, templateName);
|
||||
saveDirectory = unZipFileMap.get("saveDirectory");
|
||||
// 移除键为 "saveDirectory" 的文件
|
||||
unZipFileMap.remove("saveDirectory");
|
||||
// 拿到excel的导入文件
|
||||
File templateFile = unZipFileMap.get(templateName);
|
||||
// 将模板文件移除
|
||||
unZipFileMap.remove(templateName);
|
||||
ImportParams params = new ImportParams();
|
||||
params.setNeedSave(false);
|
||||
List<LawsClubWorkingGroupFileExcel> excelList = ExcelImportUtil.importExcel(new FileInputStream(templateFile), LawsClubWorkingGroupFileExcel.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, unZipFileMap);
|
||||
if (StringUtils.isNotEmpty(msg.toString())) {
|
||||
return Result.error(msg.toString());
|
||||
}
|
||||
// 保存数据
|
||||
for (LawsClubWorkingGroupFileExcel lawsClubMeetingExcel : excelList) {
|
||||
LawsClubWorkingGroupFile lawsClubWorkingGroupFile = new LawsClubWorkingGroupFile();
|
||||
BeanUtils.copyProperties(lawsClubMeetingExcel, lawsClubWorkingGroupFile);
|
||||
lawsClubWorkingGroupFileList.add(lawsClubWorkingGroupFile);
|
||||
}
|
||||
}catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
return Result.error("文件导入失败:"+e.getMessage());
|
||||
} finally {
|
||||
//删除原上传文件
|
||||
if (!Objects.isNull(saveDirectory)) {
|
||||
FileUnZip.deleteDir(saveDirectory);
|
||||
}
|
||||
try {
|
||||
file.getInputStream().close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.OK(lawsClubWorkingGroupFileList);
|
||||
}
|
||||
|
||||
private StringBuilder validateExcelData(List<LawsClubWorkingGroupFileExcel> excelList, Map<String, File> unZipFileMap) throws IOException{
|
||||
StringBuilder msg = new StringBuilder();
|
||||
// 拿到这个流程的名称
|
||||
List<DictModel> fileTypeList = sysDictService.getDictItems("club_file_type");
|
||||
Map<String, String> fileTypeMap = fileTypeList.stream().collect(Collectors.toMap(DictModel::getText, DictModel::getValue));
|
||||
for (int i = 0; i < excelList.size(); i++) {
|
||||
LawsClubWorkingGroupFileExcel lawsClubWorkingGroupFileExcel = excelList.get(i);
|
||||
StringBuilder msgSub = new StringBuilder();
|
||||
// 校验通知部门专业模块
|
||||
if (StringUtils.isNotBlank(lawsClubWorkingGroupFileExcel.getFileType())) {
|
||||
String fileType = fileTypeMap.get(lawsClubWorkingGroupFileExcel.getFileType());
|
||||
if (StringUtils.isBlank(fileType)) {
|
||||
msgSub.append(getErrorMsg(i, "文件类型不存在;"));
|
||||
}else {
|
||||
lawsClubWorkingGroupFileExcel.setFileType(fileType);
|
||||
}
|
||||
}
|
||||
// 校验参会报告
|
||||
if (StringUtils.isNotBlank(lawsClubWorkingGroupFileExcel.getFileId())) {
|
||||
File file = unZipFileMap.get(lawsClubWorkingGroupFileExcel.getFileId());
|
||||
if (Objects.isNull(file)) {
|
||||
msgSub.append(getErrorMsg(i, "参会报告:" + lawsClubWorkingGroupFileExcel.getFileId() + "在压缩包内不存在;"));
|
||||
}else {
|
||||
FileInputStream input = new FileInputStream(file);
|
||||
MultipartFile multipartFile = new MockMultipartFile(file.getName(), file.getName(), "application/octet-stream", input);
|
||||
// 上传该文件
|
||||
Result<OSSFile> ossFileResult = iossFileService.commonUpload(multipartFile, "temp");
|
||||
lawsClubWorkingGroupFileExcel.setFileId(ossFileResult.getResult().getId());
|
||||
}
|
||||
}
|
||||
if (msgSub.length() > 0) {
|
||||
msg.append(msgSub).append("</br>");
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
// 错误消息格式化
|
||||
private String getErrorMsg(int rowIndex, String errorMsg) {
|
||||
return "第" + (rowIndex + 4) + "行" + errorMsg;
|
||||
}
|
||||
|
||||
private boolean validatingPermission() {
|
||||
String addPermission = "clubManagement:clubManagement:add";
|
||||
String editPermission = "clubManagement:clubManagement:edit";
|
||||
boolean add = rolePermissionService.getRolePermission(addPermission);
|
||||
boolean edit = rolePermissionService.getRolePermission(editPermission);
|
||||
boolean result = add || edit;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
+4
@@ -13,11 +13,13 @@ import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.modules.laws.club.entity.LawsCompanyStandardStatistics;
|
||||
import com.jero.modules.laws.club.mapper.LawsCompanyStandardStatisticsMapper;
|
||||
import com.jero.modules.laws.club.service.ILawsCompanyStandardStatisticsService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Arrays;
|
||||
@@ -33,6 +35,8 @@ import java.util.Objects;
|
||||
* @since 2024-08-28
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional(rollbackFor = JeroBootException.class)
|
||||
public class LawsCompanyStandardStatisticsServiceImpl extends ServiceImpl<LawsCompanyStandardStatisticsMapper, LawsCompanyStandardStatistics> implements ILawsCompanyStandardStatisticsService {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
package com.jero.modules.laws.club.utils;
|
||||
|
||||
import com.jero.common.constant.enums.LanguageEnum;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.util.MessageUtils;
|
||||
import com.jero.modules.split.common.FileUnZip;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.tools.zip.ZipEntry;
|
||||
import org.apache.tools.zip.ZipFile;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ZipUtils {
|
||||
|
||||
|
||||
public static Map<String, File> analyzeZipFile(MultipartFile file, String uploadpath, String templateName) throws IOException {
|
||||
int pos = file.getOriginalFilename().lastIndexOf(".");
|
||||
String str = file.getOriginalFilename().substring(pos+1).toLowerCase();
|
||||
String filenameorg = file.getOriginalFilename().substring(0,pos);
|
||||
String resultMsg = "";
|
||||
if (!str.equals("zip")) {
|
||||
if(MessageUtils.getLanguage().getValue().equals(LanguageEnum.CN.getValue())){
|
||||
resultMsg = "请上传zip文件";
|
||||
}else{
|
||||
resultMsg = "Please upload a zip file";
|
||||
}
|
||||
throw new JeroBootException(resultMsg);
|
||||
}
|
||||
String path = uploadpath + File.separator + "modal" + File.separator + filenameorg + System.currentTimeMillis();
|
||||
File saveDirectory = new File(path);
|
||||
if(!saveDirectory.isDirectory()){
|
||||
saveDirectory.mkdir();
|
||||
}
|
||||
FileUtils.copyInputStreamToFile(file.getInputStream(), new File(path +File.separator+ file.getOriginalFilename()));
|
||||
try {
|
||||
//解压缩
|
||||
unZipFiles2(path +File.separator+ file.getOriginalFilename(), path);
|
||||
// 获取其中的文件,
|
||||
File zipFile = new File(path);
|
||||
List<File> fileList = new ArrayList<>();
|
||||
if (zipFile.isDirectory()) {
|
||||
traverseDirectory(zipFile, fileList);
|
||||
}
|
||||
if (fileList.size() < 1) {
|
||||
FileUnZip.deleteDir(saveDirectory);
|
||||
if(MessageUtils.getLanguage().getValue().equals(LanguageEnum.CN.getValue())){
|
||||
resultMsg = "没有可导入的数据,请检查!";
|
||||
}else{
|
||||
resultMsg = "No data to import, please check";
|
||||
}
|
||||
throw new JeroBootException(resultMsg);
|
||||
}
|
||||
Map<String, File> fileMap = fileList.stream().collect(Collectors.toMap(File::getName, Function.identity(), (existing, replacement) -> existing));
|
||||
File templateFile = fileMap.get(templateName);
|
||||
if (Objects.isNull(templateFile)) {
|
||||
//删除原上传文件
|
||||
FileUnZip.deleteDir(saveDirectory);
|
||||
if(MessageUtils.getLanguage().getValue().equals(LanguageEnum.CN.getValue())){
|
||||
resultMsg = "压缩包内没有Excel模板文件";
|
||||
}else{
|
||||
resultMsg = "In the cabinet did not upload the Excel template file";
|
||||
}
|
||||
throw new JeroBootException(resultMsg);
|
||||
}
|
||||
fileMap.put("saveDirectory", saveDirectory);
|
||||
return fileMap;
|
||||
} catch (Exception e){
|
||||
//删除原上传文件
|
||||
FileUnZip.deleteDir(saveDirectory);
|
||||
if(MessageUtils.getLanguage().getValue().equals(LanguageEnum.CN.getValue())){
|
||||
resultMsg = "读取失败,请严格按照模板文件导入数据";
|
||||
}else{
|
||||
resultMsg = "The data fails to be read. Import data strictly according to the template file";
|
||||
}
|
||||
throw new JeroBootException(resultMsg);
|
||||
}
|
||||
}
|
||||
|
||||
private static void traverseDirectory(File dir, List<File> fileList) {
|
||||
for (File file : dir.listFiles()) {
|
||||
if (file.isDirectory()) {
|
||||
// 递归遍历子文件夹
|
||||
traverseDirectory(file, fileList);
|
||||
} else {
|
||||
// 添加文件到fileList中
|
||||
fileList.add(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void unZipFiles2(String sourceFile, String descDir) throws IOException {
|
||||
File zipFile = new File(sourceFile);
|
||||
File pathFile = new File(descDir);
|
||||
if (!pathFile.exists()) {
|
||||
pathFile.mkdirs();
|
||||
}
|
||||
try (ZipFile zip = new ZipFile(zipFile, "gbk")) {
|
||||
for (Enumeration<? extends ZipEntry> entries = zip.getEntries(); entries.hasMoreElements(); ) {
|
||||
ZipEntry entry = entries.nextElement();
|
||||
String zipEntryName = entry.getName();
|
||||
// 修正文件路径,避免重复文件夹
|
||||
String outPath = (descDir + File.separator + zipEntryName).replaceAll("\\*", "/");
|
||||
File outFile = new File(outPath);
|
||||
// 判断是否为文件夹
|
||||
if (entry.isDirectory()) {
|
||||
if (!outFile.exists()) {
|
||||
outFile.mkdirs(); // 创建文件夹
|
||||
}
|
||||
} else {
|
||||
// 如果是文件,确保父级目录存在
|
||||
File parentDir = outFile.getParentFile();
|
||||
if (!parentDir.exists()) {
|
||||
parentDir.mkdirs(); // 创建父级目录
|
||||
}
|
||||
// 解压文件
|
||||
try (InputStream in = zip.getInputStream(entry);
|
||||
OutputStream out = new FileOutputStream(outFile)) {
|
||||
byte[] buffer = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buffer)) > 0) {
|
||||
out.write(buffer, 0, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 删除压缩包自身
|
||||
if (zipFile.exists()) {
|
||||
zipFile.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
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 LawsClubWorkingGroupFileExcel implements Serializable {
|
||||
|
||||
@Excel(name = "社团名称", width = 20)
|
||||
private String clubId;
|
||||
|
||||
@Excel(name = "文件名称", width = 20)
|
||||
private String fileId;
|
||||
|
||||
@Excel(name = "文件类型", width = 20)
|
||||
private String fileType;
|
||||
|
||||
}
|
||||
@@ -90,4 +90,5 @@ can_not_find_template_file=\u627E\u4E0D\u5230\u540D\u4E3A{0}\u7684\u6A21\u677F\u
|
||||
can_not_find_field=\u627E\u4E0D\u5230\u540D\u4E3A{0}\u7684\u5B57\u6BB5
|
||||
tree.node.exists=\u5DF2\u5B58\u5728\u540D\u4E3A"{0}"\u7684\u8282\u70B9"
|
||||
node.exist.subsets=\u5f53\u524d\u8282\u70b9\u4e0b\u5b58\u5728\u5b50\u96c6
|
||||
club.already.exists=\u793e\u56e2\u540d\u79f0\u5df2\u5b58\u5728
|
||||
club.already.exists=\u793e\u56e2\u540d\u79f0\u5df2\u5b58\u5728
|
||||
root.node.cannot.be.delete=\u6839\u8282\u70b9\u4e0d\u80fd\u5220\u9664
|
||||
@@ -109,4 +109,5 @@ tag.add.error.1=The attribute name is too long
|
||||
tree.node.exists=Name {0} tree node exists
|
||||
data.mismatch={0} Data mismatch
|
||||
node.exist.subsets=Node exist subsets
|
||||
club.already.exists=Club already exists
|
||||
club.already.exists=Club already exists
|
||||
root.node.cannot.be.delete=Root node cannot be delete
|
||||
@@ -108,4 +108,5 @@ tag.add.error.1=\u5C5E\u6027\u540D\u79F0\u592A\u957F
|
||||
tree.node.exists=\u5DF2\u5B58\u5728\u540D\u4E3A"{0}"\u7684\u8282\u70B9"
|
||||
data.mismatch={0}\u6570\u636E\u4E0D\u5339\u914D
|
||||
node.exist.subsets=\u5f53\u524d\u8282\u70b9\u4e0b\u5b58\u5728\u5b50\u96c6
|
||||
club.already.exists=\u793e\u56e2\u540d\u79f0\u5df2\u5b58\u5728
|
||||
club.already.exists=\u793e\u56e2\u540d\u79f0\u5df2\u5b58\u5728
|
||||
root.node.cannot.be.delete=\u6839\u8282\u70b9\u4e0d\u80fd\u5220\u9664
|
||||
Reference in New Issue
Block a user