add企业端资料批量下载

This commit is contained in:
zhangqinlin
2021-09-30 10:55:25 +08:00
parent 249ac92f2e
commit ee0ba5d1e3
6 changed files with 181 additions and 107 deletions
@@ -72,8 +72,6 @@ public class PayDataFileController extends JeroController<PayDataFile, IPayDataF
@Resource
private IPayMeetingSituationService payMeetingSituationService;
@Value("${jero.path.upload}")
private String upLoadPath;
//拼接目录结构
StringBuffer stringBuffer;
@@ -492,95 +490,7 @@ public class PayDataFileController extends JeroController<PayDataFile, IPayDataF
return Result.OK("添加成功!");
}
/**
* 导出下载
*
*/
@AutoLog(value = "导出下载")
@ApiOperation(value="导出下载", notes="导出下载")
@ApiImplicitParam(name = "ids", value = "文件id,多个以逗号隔开")
@GetMapping(value = "/importFile")
public void importFile(@RequestParam(name="ids",required = true) String ids) {
ArrayList<String> fileIdList = new ArrayList<>(Arrays.asList(ids.split(",")));
ArrayList<String> objects = new ArrayList<>();
for(String id :fileIdList){
OSSFile byId = iossFileService.getById(id);
objects.add(byId.getFileName());
}
zipFileDownload(objects);
}
/**
* 打包下载
* @param paths 目前处理是文件绝对路径.
*/
public void zipFileDownload(List<String> paths){
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
//循环将文件写入压缩流
DataOutputStream os = null;
//设置压缩流:直接写入response,实现边压缩边下载
ZipOutputStream zipos = null;
try {
response.reset();
response.setCharacterEncoding("utf-8");
response.setContentType("multipart/form-data");
//设置压缩包的名字
//解决不同浏览器压缩包名字含有中文时乱码的问题
String downloadName = UUID.randomUUID().toString() +".zip";
String agent = request.getHeader("USER-AGENT");
try {
//针对IE或者以IE为内核的浏览器:
if (agent.contains("MSIE") || agent.contains("Trident")) {
downloadName = java.net.URLEncoder.encode(downloadName, "UTF-8");
} else {
//非IE浏览器的处理:
downloadName = new String(downloadName.getBytes("UTF-8"),"ISO-8859-1");
}
} catch (Exception e) {
e.printStackTrace();
}
response.setHeader("Content-Disposition", "attachment;fileName=\"" + downloadName + "\"");
zipos = new ZipOutputStream(new BufferedOutputStream(response.getOutputStream()));
zipos.setMethod(ZipOutputStream.DEFLATED); //设置压缩方法
for (String path : paths){
File file = new File(upLoadPath + "\\temp\\" + path);
if(file.exists()){
try {
//添加ZipEntry,并ZipEntry中写入文件流w
//这里,防止要下载的文件有重名的导致下载失败
zipos.putNextEntry(new ZipEntry("folder/"+ file.getName()));
os = new DataOutputStream(zipos);
InputStream is = new FileInputStream(file);
byte[] b = new byte[100];
int length = 0;
while((length = is.read(b))!= -1){
os.write(b, 0, length);
}
is.close();
zipos.closeEntry();
}catch (Exception e){
e.printStackTrace();
}
}
}
}catch (Exception e){
e.printStackTrace();
}finally {
try {
if (os!= null){
os.flush();
os.close();
}
if (zipos != null){
zipos.close();
}
}catch (Exception e){
e.printStackTrace();
}
}
}
@@ -1,8 +1,13 @@
package com.jero.project.controller;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -19,18 +24,24 @@ import com.jero.company.entity.PayContactsManagement;
import com.jero.data.entity.PayCaseCommitteeSubitem;
import com.jero.data.service.IPayCaseCommitteeSubitemService;
import com.jero.modules.message.handle.impl.EmailSendMsgHandle;
import com.jero.modules.oss.entity.OSSFile;
import com.jero.modules.oss.service.IOSSFileService;
import com.jero.project.common.PayProjectCommon;
import com.jero.project.entity.DownloadFileRecord;
import com.jero.project.entity.PayWorkingGroupDistributionRecord;
import com.jero.project.entity.PayWorkingGroupSubItem;
import com.jero.project.service.IPayWorkingGroupDistributionRecordService;
import com.jero.project.service.IPayWorkingGroupSubItemService;
import io.swagger.annotations.ApiImplicitParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -52,6 +63,11 @@ public class PayWorkingGroupDistributionRecordController extends JeroController<
private IPayWorkingGroupSubItemService payWorkingGroupSubItemService;
@Autowired
private IPayCaseCommitteeSubitemService payCaseCommitteeSubitemService;
@Resource
private IOSSFileService iossFileService;
@Value("${jero.path.upload}")
private String upLoadPath;
/**
* 企业端-资料下载列表查询
@@ -83,6 +99,94 @@ public class PayWorkingGroupDistributionRecordController extends JeroController<
}
return Result.OK(pageList);
}
/**
* 导出下载zip(多个以逗号隔开)
*
*/
@ApiOperation(value="企业端-资料下载多个zip(多个以逗号隔开)", notes="企业端-资料下载多个zip(多个以逗号隔开")
@GetMapping(value = "/zipFile")
public void zipFile(@RequestParam(name="ids",required = true) String ids) {
ArrayList<String> fileIdList = new ArrayList<>(Arrays.asList(ids.split(",")));
ArrayList<String> objects = new ArrayList<>();
for(String id :fileIdList){
OSSFile file = iossFileService.getById(id);
objects.add(file.getUrl());
}
zipFileDownload(objects);
}
/**
* 打包下载
* @param paths 目前处理是文件绝对路径.
*/
public void zipFileDownload(List<String> paths){
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
//循环将文件写入压缩流
DataOutputStream os = null;
//设置压缩流:直接写入response,实现边压缩边下载
ZipOutputStream zipos = null;
try {
response.reset();
response.setCharacterEncoding("utf-8");
response.setContentType("multipart/form-data");
//设置压缩包的名字
//解决不同浏览器压缩包名字含有中文时乱码的问题
String downloadName = UUID.randomUUID().toString() +".zip";
String agent = request.getHeader("USER-AGENT");
try {
//针对IE或者以IE为内核的浏览器:
if (agent.contains("MSIE") || agent.contains("Trident")) {
downloadName = java.net.URLEncoder.encode(downloadName, "UTF-8");
} else {
//非IE浏览器的处理:
downloadName = new String(downloadName.getBytes("UTF-8"),"ISO-8859-1");
}
} catch (Exception e) {
e.printStackTrace();
}
response.setHeader("Content-Disposition", "attachment;fileName=\"" + downloadName + "\"");
zipos = new ZipOutputStream(new BufferedOutputStream(response.getOutputStream()));
zipos.setMethod(ZipOutputStream.DEFLATED); //设置压缩方法
for (String path : paths){
File file = new File(upLoadPath + "\\" + path);
if(file.exists()){
try {
//添加ZipEntry,并ZipEntry中写入文件流w
//这里,防止要下载的文件有重名的导致下载失败
zipos.putNextEntry(new ZipEntry("folder/"+ file.getName()));
os = new DataOutputStream(zipos);
InputStream is = new FileInputStream(file);
byte[] b = new byte[100];
int length = 0;
while((length = is.read(b))!= -1){
os.write(b, 0, length);
}
is.close();
zipos.closeEntry();
}catch (Exception e){
e.printStackTrace();
}
}
}
}catch (Exception e){
e.printStackTrace();
}finally {
try {
if (os!= null){
os.flush();
os.close();
}
if (zipos != null){
zipos.close();
}
}catch (Exception e){
e.printStackTrace();
}
}
}
/**
* 分发成员列表
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jero.common.api.vo.Result;
import com.jero.common.aspect.annotation.AutoLog;
import com.jero.common.exception.JeroBootException;
import com.jero.common.system.api.ISysBaseAPI;
import com.jero.common.system.vo.LoginUser;
import com.jero.mail.commont.constant;
@@ -87,6 +88,8 @@ public class AllProjectStatisticsController {
}else if(roleCodes.contains(constant.XMFZR)&&!(roleCodes.contains(constant.BMFZR)||roleCodes.contains(constant.SLD)||roleCodes.contains(constant.ADMIN))){
String userId = sysUser.getId();
idList.add(userId);
}else {
throw new JeroBootException("权限异常");
}
if (allProjectStatisticsSearch.getYear() == null || allProjectStatisticsSearch.getYear().equals("")) {
@@ -160,6 +163,8 @@ public class AllProjectStatisticsController {
}else if(roleCodes.contains(constant.XMFZR)&&!(roleCodes.contains(constant.BMFZR)||roleCodes.contains(constant.SLD)||roleCodes.contains(constant.ADMIN))){
String userId = sysUser.getId();
idList.add(userId);
}else {
throw new JeroBootException("权限异常");
}
if (allProjectStatisticsSearch.getYear() == null || allProjectStatisticsSearch.getYear().equals("")) {
Calendar calendar = Calendar.getInstance();
@@ -208,16 +213,33 @@ public class AllProjectStatisticsController {
@GetMapping(value = "/statistics/excel")
@ApiOperation(value = "全所统计导出-导出统计", notes = "全所统计导出-导出统计")
public ModelAndView excel( AllProjectStatisticsSearch allProjectStatisticsSearch) {
LoginUser sysUser =(LoginUser) SecurityUtils.getSubject().getPrincipal();
String roleCode = sysUser.getRoleCode();
List<String> roleCodes = new ArrayList<>(Arrays.asList(roleCode.split(",")));
if(roleCodes.contains(constant.SLD)||roleCodes.contains(constant.ADMIN)) {
//根据不同角色加载不同列表的参数
List<String> idList = new ArrayList<>();
//判断登录角色,显示特定工作组内容,判断依据为登录用户的角色和机构编码
LoginUser sysUser =(LoginUser) SecurityUtils.getSubject().getPrincipal();
String roleCode = sysUser.getRoleCode();
List<String> roleCodes = new ArrayList<>(Arrays.asList(roleCode.split(",")));
//科长
if(roleCodes.contains(constant.BMFZR)&&!(roleCodes.contains(constant.SLD)||roleCodes.contains(constant.ADMIN))) {
String orgCode = sysUser.getOrgCode();
List<SysUser> userList = userMapper.selectList(new QueryWrapper<SysUser>().eq("status", 1).eq("del_flag", 0).eq("org_code", orgCode));
idList = userList.stream().map(SysUser::getId).collect(Collectors.toList());
//所领导或者超级管理员
} else if(roleCodes.contains(constant.SLD)||roleCodes.contains(constant.ADMIN)) {
idList=null;
//企业职员项目负责人
}else if(roleCodes.contains(constant.XMFZR)&&!(roleCodes.contains(constant.BMFZR)||roleCodes.contains(constant.SLD)||roleCodes.contains(constant.ADMIN))){
String userId = sysUser.getId();
idList.add(userId);
}else {
throw new JeroBootException("权限异常");
}
if (allProjectStatisticsSearch.getYear() == null || allProjectStatisticsSearch.getYear().equals("")) {
Calendar calendar = Calendar.getInstance();
String year = String.valueOf(calendar.get(Calendar.YEAR));
allProjectStatisticsSearch.setYear(year);
}
List<String> idList =null;
List<AllProjectStatistics> pageList = payWorkingGroupService.queryPageListExcel(allProjectStatisticsSearch,idList);
if (pageList != null) {
for(AllProjectStatistics s: pageList){
@@ -227,33 +249,52 @@ public class AllProjectStatisticsController {
}
}
return AmountUtil.exportListXls(pageList, AllProjectStatistics.class, "所领导统计");
}else {
return new ModelAndView();
}
}
/**
*企业来款统计
*
*/
@AutoLog(value = "企业来款统计-导出统计")
@AutoLog(value = "企业项目统计-导出统计")
@GetMapping(value = "/statistics/excelProject")
@ApiOperation(value = "企业来款统计-导出统计", notes = "企业来款统计-导出统计")
@ApiOperation(value = "企业项目统计-导出统计", notes = "企业项目统计-导出统计")
public ModelAndView excelProject( AllProjectStatisticsSearch allProjectStatisticsSearch) {
List<String> idList =null;
if (allProjectStatisticsSearch.getYear() == null || allProjectStatisticsSearch.getYear().equals("")) {
Calendar calendar = Calendar.getInstance();
String year = String.valueOf(calendar.get(Calendar.YEAR));
allProjectStatisticsSearch.setYear(year);
}
//根据不同角色加载不同列表的参数
List<String> idList = new ArrayList<>();
//判断登录角色,显示特定工作组内容,判断依据为登录用户的角色和机构编码
LoginUser sysUser =(LoginUser) SecurityUtils.getSubject().getPrincipal();
String roleCode = sysUser.getRoleCode();
List<String> roleCodes = new ArrayList<>(Arrays.asList(roleCode.split(",")));
//科长
if(roleCodes.contains(constant.BMFZR)&&!(roleCodes.contains(constant.SLD)||roleCodes.contains(constant.ADMIN))) {
String orgCode = sysUser.getOrgCode();
List<SysUser> userList = userMapper.selectList(new QueryWrapper<SysUser>().eq("status", 1).eq("del_flag", 0).eq("org_code", orgCode));
idList = userList.stream().map(SysUser::getId).collect(Collectors.toList());
//所领导或者超级管理员
} else if(roleCodes.contains(constant.SLD)||roleCodes.contains(constant.ADMIN)) {
idList=null;
//企业职员项目负责人
}else if(roleCodes.contains(constant.XMFZR)&&!(roleCodes.contains(constant.BMFZR)||roleCodes.contains(constant.SLD)||roleCodes.contains(constant.ADMIN))){
String userId = sysUser.getId();
idList.add(userId);
}else {
throw new JeroBootException("权限异常");
}
List<AllProjectStatistics> pageList = payWorkingGroupService.queryPageListExcel(allProjectStatisticsSearch,idList);
if (pageList != null) {
for(AllProjectStatistics s: pageList){
String key = String.valueOf(s.getChargeUse());
String payment_charge_use = sysBaseAPI.translateDict("payment_charge_use", key);
s.setChargeUse_text(payment_charge_use);
if (pageList != null) {
for(AllProjectStatistics s: pageList){
String key = String.valueOf(s.getChargeUse());
String payment_charge_use = sysBaseAPI.translateDict("payment_charge_use", key);
s.setChargeUse_text(payment_charge_use);
}
}
}
return AmountUtil.exportListXls(pageList, AllProjectStatistics.class, "企业来款统计");
}
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jero.common.api.vo.Result;
import com.jero.common.aspect.annotation.AutoLog;
import com.jero.common.exception.JeroBootException;
import com.jero.common.system.api.ISysBaseAPI;
import com.jero.common.system.vo.LoginUser;
import com.jero.mail.commont.constant;
@@ -82,6 +83,8 @@ public class CompanyComeMoneyStatisticsController {
}else if(roleCodes.contains(constant.XMFZR)&&!(roleCodes.contains(constant.BMFZR)||roleCodes.contains(constant.SLD)||roleCodes.contains(constant.ADMIN))){
String userId = sysUser.getId();
idList.add(userId);
}else {
throw new JeroBootException("权限异常");
}
Page<CompanyComeMoneyList> page = new Page<>(pageNo, pageSize);
IPage<CompanyComeMoneyList> pageList = payWorkingGroupService.queryPageListForCompany(page,companyComeMoneySearch,idList);
@@ -147,6 +150,8 @@ public class CompanyComeMoneyStatisticsController {
}else if(roleCodes.contains(constant.XMFZR)&&!(roleCodes.contains(constant.BMFZR)||roleCodes.contains(constant.SLD)||roleCodes.contains(constant.ADMIN))){
String userId = sysUser.getId();
idList.add(userId);
}else {
throw new JeroBootException("权限异常");
}
Page<CompanyComeMoneyDetail> page = new Page<>(pageNo, pageSize);
IPage<CompanyComeMoneyDetail> pageList = payWorkingGroupService.queryPageListForCompanyDetail(page, companyComeMoneyDetailSearch,idList);
@@ -212,6 +217,8 @@ public class CompanyComeMoneyStatisticsController {
}else if(roleCodes.contains(constant.XMFZR)&&!(roleCodes.contains(constant.BMFZR)||roleCodes.contains(constant.SLD)||roleCodes.contains(constant.ADMIN))){
String userId = sysUser.getId();
idList.add(userId);
}else {
throw new JeroBootException("权限异常");
}
List<CompanyComeMoneyList> pageList = payWorkingGroupService.queryPageListForCompanyExcel(companyComeMoneySearch,idList);
@@ -249,6 +256,8 @@ public class CompanyComeMoneyStatisticsController {
}else if(roleCodes.contains(constant.XMFZR)&&!(roleCodes.contains(constant.BMFZR)||roleCodes.contains(constant.SLD)||roleCodes.contains(constant.ADMIN))){
String userId = sysUser.getId();
idList.add(userId);
}else {
throw new JeroBootException("权限异常");
}
List<CompanyComeMoneyDetail> pageList = payWorkingGroupService.queryPageListForCompanyDetailExcel(companyComeMoneyDetailSearch,idList);
for(CompanyComeMoneyDetail s: pageList){
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jero.common.api.vo.Result;
import com.jero.common.aspect.annotation.AutoLog;
import com.jero.common.exception.JeroBootException;
import com.jero.common.system.api.ISysBaseAPI;
import com.jero.common.system.vo.ComboModel;
import com.jero.common.system.vo.DictModel;
@@ -93,6 +94,8 @@ public class PayWorkingGroupStatisticsController {
}else if(roleCodes.contains(constant.XMFZR)&&!(roleCodes.contains(constant.BMFZR)||roleCodes.contains(constant.SLD)||roleCodes.contains(constant.ADMIN))){
String userId = sysUser.getId();
idList.add(userId);
}else {
throw new JeroBootException("权限异常");
}
IPage<PayWorkingGroupStatistics> pageList = payWorkingGroupService.queryPageListForStatistics(page, payWorkingGroupSearch,idList);
List<PayWorkingGroupStatistics> records = pageList.getRecords();
@@ -160,6 +163,8 @@ public class PayWorkingGroupStatisticsController {
}else if(roleCodes.contains(constant.XMFZR)&&!(roleCodes.contains(constant.BMFZR)||roleCodes.contains(constant.SLD)||roleCodes.contains(constant.ADMIN))){
String userId = sysUser.getId();
idList.add(userId);
}else {
throw new JeroBootException("权限异常");
}
List<PayWorkingGroupStatistics> pageList = payWorkingGroupService.queryPageListForStatisticsExcel(payWorkingGroupSearch,idList);
//处理为空数据为0
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jero.common.api.vo.Result;
import com.jero.common.aspect.annotation.AutoLog;
import com.jero.common.exception.JeroBootException;
import com.jero.common.service.ProjectDetailService;
import com.jero.common.system.api.ISysBaseAPI;
import com.jero.common.system.vo.LoginUser;
@@ -88,6 +89,8 @@ public class PrincipalPeopleStatisticsController {
}else if(roleCodes.contains(constant.XMFZR)&&!(roleCodes.contains(constant.BMFZR)||roleCodes.contains(constant.SLD)||roleCodes.contains(constant.ADMIN))){
String userId = sysUser.getId();
idList.add(userId);
}else {
throw new JeroBootException("权限异常");
}
Page<PrincipalPeopleList> page = new Page<>(pageNo, pageSize);
@@ -204,6 +207,8 @@ public class PrincipalPeopleStatisticsController {
}else if(roleCodes.contains(constant.XMFZR)&&!(roleCodes.contains(constant.BMFZR)||roleCodes.contains(constant.SLD)||roleCodes.contains(constant.ADMIN))){
String userId = sysUser.getId();
idList.add(userId);
}else {
throw new JeroBootException("权限异常");
}
List<PrincipalPeopleList> pageList = payWorkingGroupService.queryPageListForPrincipalExcel(principalPeopleSearch,idList);