anderx 1 год назад
Родитель
Сommit
18ba4e6667

+ 6 - 0
pom.xml

@@ -449,6 +449,12 @@
 			<artifactId>pinyin4j</artifactId>
 			<version>2.5.1</version>
 		</dependency>
+		<dependency>
+			<groupId>com.mchange</groupId>
+			<artifactId>mchange-commons-java</artifactId>
+			<version>0.2.15</version>
+			<scope>compile</scope>
+		</dependency>
 
 	</dependencies>
 	<build>

+ 1 - 0
src/main/java/com/goafanti/common/mapper/TOrderNewMapper.xml

@@ -966,6 +966,7 @@ left join department d on o.order_dep = d.id   left join t_order_mid a on o.orde
   <select id="selectOrderNewListByPage" resultType="com.goafanti.order.bo.TOrderNewBo">
   	select a.order_no as orderNo,a.create_time as createTime, date_format(a.sign_time,'%Y-%m-%d' ) as signDate,a.delete_sign deleteSign,
   	a.contract_no as contractNo, b.nickname as userName ,a.process_status as processStatus,a.total_amount as totalAmount,a.tag,
+  	a.contract_picture_url contractPictureUrl,
   	a.order_status as orderStatus, a.liquidation_status as liquidationStatus,a.approval,c.salesman_name as salesmanName,c.project_type projectType,
   	dep.name as depName,c.finance_name as financeName,c.invoice_amount invoiceAmount,a.settlement_amount settlementAmount,
     a.sales_type salesType, a.channel_id channelId ,a.other,a.examine_name examineName,c.stop_project stopProject

+ 21 - 14
src/main/java/com/goafanti/common/utils/FileUtils.java

@@ -1,23 +1,16 @@
 package com.goafanti.common.utils;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.util.regex.Pattern;
-
-import javax.servlet.http.HttpServletResponse;
-
+import com.goafanti.common.enums.AttachmentType;
+import com.goafanti.common.error.BusinessException;
+import com.mchange.v1.io.InputStreamUtils;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.multipart.MultipartFile;
 
-import com.goafanti.common.enums.AttachmentType;
-import com.goafanti.common.error.BusinessException;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+import java.net.URLEncoder;
+import java.util.regex.Pattern;
 
 public class FileUtils {
 	@Value(value = "${upload.private.path}")
@@ -333,4 +326,18 @@ public class FileUtils {
 		}
 	}
 
+
+	public static byte[] getBytes(File file) throws IOException {
+		BufferedInputStream var1 = new BufferedInputStream(new FileInputStream(file));
+
+		byte[] var2;
+		try {
+			var2 = InputStreamUtils.getBytes(var1);
+		} finally {
+			InputStreamUtils.attemptClose(var1);
+		}
+
+		return var2;
+	}
+
 }

+ 13 - 0
src/main/java/com/goafanti/order/controller/AdminNewOrderApiController.java

@@ -340,6 +340,19 @@ public class AdminNewOrderApiController extends CertifyApiController {
 	}
 
 	/**
+	 * 		订单列表导出文件
+	 *  specially 0 个人 1 营销员管理 2 驳回 3 特批 4 咨询师管理 5部门订单查询 6客服查询 7统计签单订单 8客户订单列表 9 复审订单 10 营销经理
+	 *  distribution (咨询师管理列表 0 未分配 1部分 2全部
+	 *  amountStatus  0 10万元以下 1 10万~20万 2 20万~30万 3 30万~40万  4 40万以上
+	 * @return
+	 */
+	@RequestMapping(value="/orderNewListDownload", method = RequestMethod.GET)
+	public Result orderNewListDownload(InputOrderNewListBo in,HttpServletResponse response){
+		orderNewService.orderNewListDownload(in,response);
+		return new Result();
+	}
+
+	/**
 	 * 销售来源订单列表
 	 * @param in
 	 * @return

+ 3 - 0
src/main/java/com/goafanti/order/service/OrderNewService.java

@@ -5,6 +5,7 @@ import com.goafanti.common.model.*;
 import com.goafanti.core.mybatis.page.Pagination;
 import com.goafanti.order.bo.*;
 
+import javax.servlet.http.HttpServletResponse;
 import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
@@ -226,4 +227,6 @@ public interface OrderNewService {
 
 
 	void financeCountOrderUnauditedSubtraction(TOrderNew use, Integer i);
+
+	void orderNewListDownload(InputOrderNewListBo in, HttpServletResponse response);
 }

+ 69 - 0
src/main/java/com/goafanti/order/service/impl/OrderNewServiceImpl.java

@@ -31,6 +31,7 @@ import com.goafanti.order.service.OrderProjectService;
 import com.goafanti.organization.bo.*;
 import com.goafanti.patent.service.PatentNewService;
 import groovy.transform.Synchronized;
+import org.apache.commons.io.IOUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
@@ -42,6 +43,9 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.mail.MessagingException;
+import javax.servlet.http.HttpServletResponse;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.math.BigDecimal;
@@ -49,6 +53,8 @@ import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
 
 @Service
 @EnableAsync
@@ -1766,6 +1772,69 @@ public class OrderNewServiceImpl extends BaseMybatisDao<TOrderNewMapper> impleme
 		}
 	}
 
+	@Override
+	public void orderNewListDownload(InputOrderNewListBo in,HttpServletResponse response) {
+		in.setPageSize(99999);
+		Pagination<TOrderNewBo> pagination = orderNewList(in);
+		List<TOrderNewBo> list = (List<TOrderNewBo>) pagination.getList();
+		downloadOrderImg( list,  response);
+	}
+
+	public void downloadOrderImg(List<TOrderNewBo> list, HttpServletResponse response){
+
+			String downloadFileName = "";
+			ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+			ZipOutputStream zip = new ZipOutputStream(outputStream);
+			downloadFileName="订单合同数据.zip";
+			for (TOrderNewBo t : list) {
+
+				//防止重名码
+				if (t != null) {
+
+					String annexUrl = t.getContractPictureUrl();
+					String[] split = annexUrl.split(",");
+					if (split.length>0){
+						int index =0;
+						for (String s : split) {
+							if (StringUtils.isNotEmpty(s)){
+								index++;
+								String url=s.replace("/profile/upload","");
+								url=uploadPath+url;
+								System.out.println(url);
+								File file = new File(url);
+								if (file.exists()){
+									try {
+										String suffix = s.substring(s.indexOf("."));
+										String fileName=t.getUserName()+"/"+t.getUserName()+"_"+index+suffix;
+										ZipEntry e = new ZipEntry(fileName);
+										zip.putNextEntry(e);
+										IOUtils.write(FileUtils.getBytes(file),zip);
+										zip.closeEntry();
+										zip.flush();
+									} catch (IOException e){
+										throw  new BusinessException("文件写入压缩失败:"+e.getLocalizedMessage());
+									}
+								}
+							}
+						}
+					}
+				}
+			}
+			IOUtils.closeQuietly(zip);
+			try {
+				byte[] data = outputStream.toByteArray();
+				response.reset();
+				response.addHeader("Access-Control-Allow-Origin", "*");
+				response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
+				response.setHeader("Content-Disposition", "attachment; filename=\"" + java.net.URLEncoder.encode(downloadFileName, "utf-8").replaceAll("\\+", "%20") + "\"");
+				response.addHeader("Content-Length", "" + data.length);
+				response.setContentType("application/octet-stream; charset=UTF-8");
+				IOUtils.write(data,response.getOutputStream());
+			} catch (IOException e) {
+				throw new RuntimeException(e);
+			}
+
+	}
 	private TOrderNew checkDeleteSign(String orderNo) {
 		TOrderNew t=tOrderNewMapper.selectByPrimaryKey(orderNo);
 		//if(t.getDeleteSign()==2) throw new BusinessException(new Error(ErrorConstants.ORDER_ALREADY_REVOKE, t.getOrderNo(),""));