bug修改
This commit is contained in:
+187
-21
@@ -1,32 +1,45 @@
|
||||
package com.jero.project.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
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.base.controller.JeroController;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.util.ValidUtil;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
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.PayWorkingGroupDataFile;
|
||||
import com.jero.project.service.IPayWorkingGroupDataFileService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.env.Environment;
|
||||
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;
|
||||
@@ -42,10 +55,14 @@ import io.swagger.annotations.ApiOperation;
|
||||
@RequestMapping("/project/payWorkingGroupDataFile")
|
||||
@Slf4j
|
||||
public class PayWorkingGroupDataFileController extends JeroController<PayWorkingGroupDataFile, IPayWorkingGroupDataFileService> {
|
||||
@Autowired
|
||||
@Resource
|
||||
private IPayWorkingGroupDataFileService payWorkingGroupDataFileService;
|
||||
@Autowired
|
||||
@Resource
|
||||
private Environment env;
|
||||
@Resource
|
||||
private IOSSFileService iossFileService;
|
||||
@Value("${jero.path.upload}")
|
||||
private String upLoadPath;
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
@@ -198,16 +215,19 @@ public class PayWorkingGroupDataFileController extends JeroController<PayWorking
|
||||
@RequiresPermissions("fileMaintenance:export")
|
||||
@ApiOperation(value="资料维护-导出excel", notes="资料维护-导出excel")
|
||||
@GetMapping(value = "/exportXls")
|
||||
public ModelAndView exportXls(HttpServletRequest request, PayWorkingGroupDataFile payWorkingGroupDataFile) {
|
||||
public void exportXls(HttpServletRequest request,HttpServletResponse response, PayWorkingGroupDataFile payWorkingGroupDataFile) {
|
||||
if(StringUtils.isBlank(payWorkingGroupDataFile.getProjectId())){
|
||||
throw new JeroBootException("项目id不能为空!");
|
||||
}
|
||||
if(payWorkingGroupDataFile.getProjectType() != PayProjectCommon.PROJECT_TYPE_FILE1
|
||||
&& payWorkingGroupDataFile.getProjectType() != PayProjectCommon.PROJECT_TYPE_FILE2){
|
||||
if(!Objects.equals(payWorkingGroupDataFile.getProjectType(),PayProjectCommon.PROJECT_TYPE_FILE1)
|
||||
&& !Objects.equals(payWorkingGroupDataFile.getProjectType(),PayProjectCommon.PROJECT_TYPE_FILE2)){
|
||||
throw new JeroBootException("项目状态不正确!");
|
||||
}
|
||||
// Step.1 组装查询条件
|
||||
QueryWrapper<PayWorkingGroupDataFile> queryWrapper = QueryGenerator.initQueryWrapper(payWorkingGroupDataFile, request.getParameterMap());
|
||||
|
||||
// Step.2 获取导出数据
|
||||
List<PayWorkingGroupDataFile> pageList = payWorkingGroupDataFileService.queryList(payWorkingGroupDataFile.getProjectId(),payWorkingGroupDataFile.getProjectType());
|
||||
List<PayWorkingGroupDataFile> pageList = payWorkingGroupDataFileService.list(queryWrapper);
|
||||
List<PayWorkingGroupDataFile> exportList = null;
|
||||
|
||||
// 过滤选中数据
|
||||
@@ -218,20 +238,166 @@ public class PayWorkingGroupDataFileController extends JeroController<PayWorking
|
||||
} else {
|
||||
exportList = pageList;
|
||||
}
|
||||
|
||||
// Step.3 AutoPoi 导出Excel
|
||||
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
||||
mv.addObject(NormalExcelConstants.FILE_NAME, "资料维护"); //此处设置的filename无效 ,前端会重更新设置一下
|
||||
mv.addObject(NormalExcelConstants.CLASS, PayWorkingGroupDataFile.class);
|
||||
//update-begin--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置--------------------
|
||||
ExportParams exportParams=new ExportParams("资料维护", "资料维护");
|
||||
exportParams.setImageBasePath(env.getProperty("jero.path.upload"));
|
||||
//update-end--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置----------------------
|
||||
mv.addObject(NormalExcelConstants.PARAMS,exportParams);
|
||||
mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
|
||||
return mv;
|
||||
if(CollectionUtils.isEmpty(exportList)){
|
||||
throw new JeroBootException("请选中文件!");
|
||||
}
|
||||
List<String> files = exportList.stream().map(PayWorkingGroupDataFile::getFileId).collect(Collectors.toList());
|
||||
LambdaQueryWrapper<OSSFile> queryOSSFile = new LambdaQueryWrapper<>();
|
||||
queryOSSFile.in(OSSFile::getId,files);
|
||||
List<OSSFile> listOSSFile = iossFileService.list(queryOSSFile);
|
||||
if(CollectionUtils.isEmpty(listOSSFile)){
|
||||
throw new JeroBootException("文件不存在!");
|
||||
}
|
||||
//循环将文件写入压缩流
|
||||
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 (OSSFile ossFile : listOSSFile) {
|
||||
File file = new File(upLoadPath + "\\" + ossFile.getUrl());
|
||||
if(file.exists()){
|
||||
try {
|
||||
//添加ZipEntry,并ZipEntry中写入文件流w
|
||||
//这里,防止要下载的文件有重名的导致下载失败
|
||||
zipos.putNextEntry(new ZipEntry(ossFile.getFileName()));
|
||||
os = new DataOutputStream(zipos);
|
||||
InputStream is = new FileInputStream(file);
|
||||
byte[] b = new byte[1024];
|
||||
int length = 0;
|
||||
while((length = is.read(b))!= -1){
|
||||
os.write(b, 0, length);
|
||||
}
|
||||
is.close();
|
||||
zipos.closeEntry();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
assert os != null;
|
||||
os.flush();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
try {
|
||||
if (os!= null){os.close();}
|
||||
if (zipos != null){zipos.close();}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出下载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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过excel导入数据
|
||||
*
|
||||
|
||||
+3
-7
@@ -367,14 +367,10 @@ public class PayWorkingGroupSubItemController extends JeroController<PayWorkingG
|
||||
LambdaQueryWrapper<PayWorkingGroupSubItem> query = new LambdaQueryWrapper<>();
|
||||
query.in(PayWorkingGroupSubItem::getId, Arrays.asList(ids.split(",")));
|
||||
query.eq(PayWorkingGroupSubItem::getWorkingGroupId, workingGroupId);
|
||||
List<PayWorkingGroupSubItem> list = payWorkingGroupSubItemService.list();
|
||||
query.ne(PayWorkingGroupSubItem::getChargeWay,PayProjectCommon.CHARGE_WAY3);
|
||||
List<PayWorkingGroupSubItem> list = payWorkingGroupSubItemService.list(query);
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
List<PayWorkingGroupSubItem> listNew = list.stream().filter(p -> !Objects.equals(p.getChargeWay(), PayProjectCommon.CHARGE_WAY3)).collect(Collectors.toList());
|
||||
if (!CollectionUtils.isEmpty(listNew)) {
|
||||
return Result.error("存在来款方式不是收费通知的选项!");
|
||||
}
|
||||
} else {
|
||||
return Result.error("请选择项目!");
|
||||
return Result.error("存在来款方式不是收费通知的选项!");
|
||||
}
|
||||
return Result.OK("来款方式都是收费通知!");
|
||||
}
|
||||
|
||||
+2
-2
@@ -60,7 +60,7 @@ public class PayWorkingGroupSubItem implements Serializable {
|
||||
/**企业联系人一id*/
|
||||
@ApiModelProperty(value = "企业联系人一id")
|
||||
@Size(max = 32,message = "企业联系人一id长度不能大于32个字符")
|
||||
@NotEmpty(message = "企业联系人一id不能为空")
|
||||
// @NotEmpty(message = "企业联系人一id不能为空")
|
||||
private java.lang.String contactsIdOne;
|
||||
/**临时企业联系人一id*/
|
||||
@ApiModelProperty(value = "临时企业联系人一id")
|
||||
@@ -109,7 +109,7 @@ public class PayWorkingGroupSubItem implements Serializable {
|
||||
private Integer chargeUse;
|
||||
/**邮寄联系人id*/
|
||||
@ApiModelProperty(value = "邮寄联系人id")
|
||||
@NotEmpty(message = "邮寄联系人id不能为空")
|
||||
// @NotEmpty(message = "邮寄联系人id不能为空")
|
||||
@Size(max = 32,message = "邮寄联系人id长度不能大于32个字符")
|
||||
private java.lang.String mailContactsId;
|
||||
/**临时邮寄联系人id*/
|
||||
|
||||
Reference in New Issue
Block a user