批量下载发票
This commit is contained in:
parent
dc7d67f716
commit
913dec0014
@ -34,13 +34,9 @@
|
||||
|
||||
var planIds = "";
|
||||
for(var i = 0;i < sParm.length; i++){
|
||||
//if(planIds.length == 0){
|
||||
//planIds += sParm[i] +"@";
|
||||
//}else{
|
||||
planIds += sParm[i] +"@";
|
||||
//}
|
||||
}
|
||||
//alert(planIds);
|
||||
|
||||
planIds = planIds.substr(0,planIds.length-1);
|
||||
//alert(planIds);
|
||||
spara = "planIds="+planIds+",CurUserID=<%=CurUser.getUserID()%>";
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
%><%@include file="/Frame/resources/include/ui/include_list.jspf"%>
|
||||
<script type="text/javascript">
|
||||
function submitInvoice(){
|
||||
debugger;
|
||||
//debugger;
|
||||
var sParm = getItemValueArray(0,"id");
|
||||
if(typeof(sParm) == "undefined" || sParm.length == 0 )
|
||||
{
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
dwTemp.Style="1"; //--设置为Grid风格--
|
||||
dwTemp.ReadOnly = "1"; //只读模式
|
||||
dwTemp.setPageSize(10);
|
||||
dwTemp.MultiSelect=true;
|
||||
dwTemp.genHTMLObjectWindow("");
|
||||
|
||||
//0、是否展示 1、 权限控制 2、 展示类型 3、按钮显示名称 4、按钮解释文字 5、按钮触发事件代码 6、 7、 8、 9、图标,CSS层叠样式 10、风格
|
||||
@ -17,6 +18,7 @@
|
||||
//{"true","All","Button","新增","新增","newRecord()","","","","btn_icon_add",""},
|
||||
{"true","","Button","详情","详情","viewAndEdit()","","","","btn_icon_detail",""},
|
||||
{"true","","Button","查询","查询","selectInvoice()","","","","",""},
|
||||
{"true","","Button","批量下载","批量下载","lotdown()","","","","btn_icon_transfer",""},
|
||||
{"true","","Button","删除","删除","if(confirm('确实要删除吗?'))as_delete(0)","","","","btn_icon_delete",""},
|
||||
};
|
||||
%><%@include file="/Frame/resources/include/ui/include_list.jspf"%>
|
||||
@ -37,20 +39,49 @@
|
||||
if(!frames["downloadTemplate"]) $("<iframe name='downloadTemplate' style='display:none;'></iframe>").appendTo("body");
|
||||
window.open(sWebRootPath+"/servlet/view/invoiceDownloadServlet?CompClientID=<%=sCompClientID%>&path="+path, "downloadTemplate");
|
||||
}
|
||||
|
||||
function lotdown(){
|
||||
var localFiles=getItemValueArray(0,"localFile");
|
||||
|
||||
//alert(localFiles);
|
||||
if(typeof(localFiles)=="undefined"||localFiles==null||localFiles==""){alert("请选择");return;}
|
||||
var files = "";
|
||||
for(var i=0;i<localFiles.length;i++){
|
||||
files += localFiles[i]+"@";
|
||||
|
||||
}
|
||||
files = files.substr(0,files.length-1);
|
||||
alert(files);
|
||||
// para = "files="+files;
|
||||
// alert(para);
|
||||
if(!frames["downloadTemplate"]) $("<iframe name='downloadTemplate' style='display:none;'></iframe>").appendTo("body");
|
||||
window.open(sWebRootPath+"/servlet/view/invoiceLotDownloadServlet?CompClientID=<%=sCompClientID%>&files="+files, "downloadTemplate");
|
||||
reloadSelf();
|
||||
|
||||
}
|
||||
function selectInvoice(){
|
||||
var sid = getItemValue(0,getRow(0),"sid");
|
||||
//var sid = getItemValue(0,getRow(0),"sid");
|
||||
var sid = getItemValueArray(0,"sid");
|
||||
if(typeof(sid) == "undefined" || sid.length == 0 )
|
||||
{
|
||||
alert("请选择查询数据!");
|
||||
return;
|
||||
}
|
||||
//alert(sid);
|
||||
/* if(typeof(sid)=="undefined" || sObjectInfo.length==0 ){
|
||||
alert("请选择查询开票数据!");
|
||||
return ;
|
||||
} */
|
||||
spara = "sid="+sid+",CurUserID=<%=CurUser.getUserID()%>";
|
||||
//var returnValue = AsControl.RunJavaMethodTrans("com.tenwa.lease.app.invoicemanager.InvoiceManagerController","selectConfirm",spara);
|
||||
|
||||
var sids = "";
|
||||
for(var i = 0;i < sid.length; i++){
|
||||
|
||||
sids += sid[i] +"@";
|
||||
|
||||
}
|
||||
|
||||
sids = sids.substr(0,sids.length-1);
|
||||
//alert(sids);
|
||||
spara = "sid="+sids+",CurUserID=<%=CurUser.getUserID()%>";
|
||||
|
||||
var returnValue = AsControl.RunJavaMethodTrans("com.tenwa.apzl.invoicemanager.rentplaninvoice.rentPlanInvoiceManager","selectConfirm",spara);
|
||||
|
||||
alert(returnValue);
|
||||
alert(returnValue);
|
||||
reloadSelf();
|
||||
}
|
||||
function newRecord(){
|
||||
|
||||
@ -16,6 +16,9 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import com.amarsoft.are.ARE;
|
||||
import com.amarsoft.are.jbo.BizObject;
|
||||
import com.amarsoft.are.jbo.JBOException;
|
||||
import com.amarsoft.are.jbo.JBOFactory;
|
||||
import com.amarsoft.are.util.DataConvert;
|
||||
import com.amarsoft.awe.Configure;
|
||||
import com.tenwa.util.SecurityUtil;
|
||||
@ -30,6 +33,19 @@ public class InvoiceDownloadServlet extends HttpServlet {
|
||||
@Override
|
||||
protected void service(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
String customerName = "";
|
||||
String sid = "";
|
||||
try {
|
||||
BizObject invoiceResult = JBOFactory.createBizObjectQuery("jbo.app.tenwa.calc.LI_INVOICE_RESULT", "localFile=:localFile").setParameter("localFile", request.getParameter("path")).getSingleResult(false);
|
||||
sid = invoiceResult.getAttribute("sid").toString();
|
||||
BizObject invoiceConfirm = JBOFactory.createBizObjectQuery("jbo.app.tenwa.calc.LI_INVOICE_CONFIRM", "sid=:sid").setParameter("sid",sid).getSingleResult(false);
|
||||
if(invoiceConfirm !=null){
|
||||
customerName = invoiceConfirm.getAttribute("ghdwmc").toString();
|
||||
}
|
||||
} catch (JBOException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
try {
|
||||
HttpSession session = request.getSession(true);
|
||||
if ((session == null) || (session.getAttributeNames() == null)) {
|
||||
@ -43,14 +59,16 @@ public class InvoiceDownloadServlet extends HttpServlet {
|
||||
String path = DataConvert.toString(request.getParameter("path"));
|
||||
path = SecurityUtil.detrypt(path, "invoice");
|
||||
localFile = localFile + path;
|
||||
|
||||
|
||||
File file = new File(localFile);
|
||||
if (!file.exists())
|
||||
throw new Exception("Îļþ²»´æÔÚ");
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("YYYYMMddHHmmss");
|
||||
String filename = dateFormat.format(new Date()) + ".pdf";
|
||||
//String filename = dateFormat.format(new Date()) + ".pdf";
|
||||
String filename = customerName + ".pdf";
|
||||
//response.setContentType("text/html;charset=UTF-8");
|
||||
response.setContentType(getServletContext().getMimeType(filename));
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + filename);
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + new String( filename.getBytes("gb2312"), "ISO8859-1" ) );
|
||||
InputStream in = new FileInputStream(localFile);
|
||||
OutputStream out = response.getOutputStream();
|
||||
int b;
|
||||
|
||||
@ -0,0 +1,136 @@
|
||||
package com.tenwa.app.invoice.servlet;
|
||||
|
||||
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.net.URLDecoder;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import com.amarsoft.are.ARE;
|
||||
import com.amarsoft.are.jbo.BizObject;
|
||||
import com.amarsoft.are.jbo.JBOException;
|
||||
import com.amarsoft.are.jbo.JBOFactory;
|
||||
import com.amarsoft.are.util.DataConvert;
|
||||
import com.amarsoft.awe.Configure;
|
||||
import com.tenwa.app.invoice.utils.FileCopy;
|
||||
import com.tenwa.app.invoice.utils.FilesToZipUtils;
|
||||
import com.tenwa.util.SecurityUtil;
|
||||
|
||||
public class InvoiceLotDownloadServlet extends HttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public InvoiceLotDownloadServlet() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void service(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
String files = request.getParameter("files");
|
||||
String[] arr = files.split("@");
|
||||
String str = "";
|
||||
String sid ="";
|
||||
String customerName = "";
|
||||
String zipLocalPath = "";
|
||||
List<File> filess = new ArrayList<>();
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
|
||||
str = arr[i];
|
||||
try {
|
||||
BizObject invoiceResult = JBOFactory.createBizObjectQuery("jbo.app.tenwa.calc.LI_INVOICE_RESULT", "localFile=:localFile").setParameter("localFile", str).getSingleResult(false);
|
||||
if(invoiceResult !=null){
|
||||
|
||||
sid = invoiceResult.getAttribute("sid").toString();
|
||||
}
|
||||
BizObject invoiceConfirm = JBOFactory.createBizObjectQuery("jbo.app.tenwa.calc.LI_INVOICE_CONFIRM", "sid=:sid").setParameter("sid", sid).getSingleResult(false);
|
||||
if(invoiceConfirm !=null){
|
||||
|
||||
customerName = invoiceConfirm.getAttribute("ghdwmc").toString();
|
||||
}
|
||||
} catch (JBOException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
try {
|
||||
HttpSession session = request.getSession(true);
|
||||
if ((session == null) || (session.getAttributeNames() == null)) {
|
||||
throw new Exception("------Timeout------");
|
||||
}
|
||||
Configure CurConfig = Configure.getInstance(session.getServletContext());
|
||||
if (CurConfig == null) {
|
||||
throw new ServletException("读取配置文件错误!请检查配置文件。");
|
||||
}
|
||||
String localFile = CurConfig.getConfigure("INVOICE_LOCAL_PATH");
|
||||
String copyLocalPath = CurConfig.getConfigure("COPY_LOCAL_PATH");
|
||||
zipLocalPath = CurConfig.getConfigure("ZIP_LOCAL_PATH");
|
||||
String path = DataConvert.toString(str);
|
||||
path = SecurityUtil.detrypt(path, "invoice");
|
||||
localFile = localFile + path;
|
||||
|
||||
File file = new File(localFile);
|
||||
if (!file.exists())
|
||||
throw new Exception("文件不存在");
|
||||
//复制文件
|
||||
File from = new File(localFile);
|
||||
String pdfname = customerName + ".pdf";
|
||||
//String name ="E:/liuzhaoPDF/"+pdfname;
|
||||
String name =copyLocalPath+pdfname;
|
||||
File to = new File(name);
|
||||
FileCopy.copyFile(from, to);
|
||||
//filess.add(new File(localFile));
|
||||
filess.add(to);
|
||||
|
||||
} catch (Exception e) {
|
||||
ARE.getLog().error("AttachmentView SQL Error:", e);
|
||||
}
|
||||
}
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("YYYYMMddHHmmss");
|
||||
String filename = dateFormat.format(new Date()) + ".zip";
|
||||
//String zipFilename ="E:/liuzhaoCopyPDF/"+filename;
|
||||
String zipFilename =zipLocalPath+filename;
|
||||
|
||||
try {
|
||||
FilesToZipUtils.toZipFiles(filess, zipFilename);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
//error
|
||||
}
|
||||
File localZipFile = new File(zipFilename);
|
||||
try {
|
||||
if (localZipFile.exists() && localZipFile.isFile() && localZipFile.length() > 0) {
|
||||
|
||||
response.setContentType(getServletContext().getMimeType(filename));
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + filename);
|
||||
InputStream in = new FileInputStream(localZipFile);
|
||||
OutputStream out = response.getOutputStream();
|
||||
int b;
|
||||
while ((b = in.read()) != -1) {
|
||||
out.write(b);
|
||||
}
|
||||
in.close();
|
||||
out.close();
|
||||
|
||||
}else{
|
||||
|
||||
throw new Exception("压缩包不存在!");
|
||||
|
||||
}} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
21
src_invoice/com/tenwa/app/invoice/utils/FileCopy.java
Normal file
21
src_invoice/com/tenwa/app/invoice/utils/FileCopy.java
Normal file
@ -0,0 +1,21 @@
|
||||
package com.tenwa.app.invoice.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class FileCopy {
|
||||
public static void copyFile(File fromFile,File toFile) throws IOException{
|
||||
FileInputStream ins = new FileInputStream(fromFile);
|
||||
FileOutputStream out = new FileOutputStream(toFile);
|
||||
byte[] b = new byte[1024];
|
||||
int n=0;
|
||||
while((n=ins.read(b))!=-1){
|
||||
out.write(b, 0, n);
|
||||
}
|
||||
|
||||
ins.close();
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
128
src_invoice/com/tenwa/app/invoice/utils/FilesToZipUtils.java
Normal file
128
src_invoice/com/tenwa/app/invoice/utils/FilesToZipUtils.java
Normal file
@ -0,0 +1,128 @@
|
||||
package com.tenwa.app.invoice.utils;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
//import org.apache.logging.log4j.LogManager;
|
||||
//import org.apache.logging.log4j.Logger;
|
||||
import org.apache.tomcat.util.http.fileupload.FileUtils;
|
||||
|
||||
|
||||
public class FilesToZipUtils {
|
||||
|
||||
private static final Logger log = LogManager.getLogger(FilesToZipUtils.class);
|
||||
|
||||
public static void delZipFile(String zipFilename) {
|
||||
File file = new File(zipFilename);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
try {
|
||||
File localZipParentFile= file.getParentFile() ;
|
||||
File[] listFiles = localZipParentFile.listFiles();
|
||||
if(listFiles!=null && listFiles.length==0)
|
||||
FileUtils.deleteDirectory(localZipParentFile);
|
||||
} catch (IOException e) {
|
||||
log.error(">>>>>>>>[error] file parent is not deleted>>>>>>>>" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void delZipFiles(List<File> files) {
|
||||
if(files!=null && files.size()>0)
|
||||
for(File file :files){
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
try {
|
||||
File localZipParentFile= file.getParentFile() ;
|
||||
File[] listFiles = localZipParentFile.listFiles();
|
||||
if(listFiles!=null && listFiles.length==0)
|
||||
FileUtils.deleteDirectory(localZipParentFile);
|
||||
} catch (IOException e) {
|
||||
log.error(">>>>>>>>[error] file parent is not deleted>>>>>>>>" + e.getMessage());
|
||||
}
|
||||
}else {
|
||||
log.error(">>>>>>>>[error] file is not exists>>>>>>>>" + file);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void toZipFiles(List<File> files, String zipFilename) throws Exception {
|
||||
try {
|
||||
File file = new File(zipFilename);
|
||||
if (!file.exists()) {
|
||||
String path = zipFilename.substring(0, zipFilename.lastIndexOf("/")) ;
|
||||
if(!new File(path).exists()) {
|
||||
new File(path).mkdirs();
|
||||
}
|
||||
file.createNewFile();
|
||||
}
|
||||
FileOutputStream fous = new FileOutputStream(file);
|
||||
ZipOutputStream zipOut = new ZipOutputStream(fous);
|
||||
zipFile(files, zipOut);
|
||||
zipOut.close();
|
||||
fous.close();
|
||||
if (file.exists()) {
|
||||
log.info(">>>>>>>>[success] zip file is generated success>>>>>>>>" + file);
|
||||
log.info(">>>>>>>>fils will be delete>>>>>>>>" );
|
||||
log.info(">>>>>>>>fils is deleting>>>>>>>>" );
|
||||
delZipFiles(files);
|
||||
}else {
|
||||
log.error(">>>>>>>>[error] zip file is not generated success>>>>>>>>" + file);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void zipFile(List<File> files, ZipOutputStream outputStream) {
|
||||
int size = files.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
File file = (File) files.get(i);
|
||||
if (file.exists()) {
|
||||
zipFile(file, outputStream);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void zipFile(File inputFile, ZipOutputStream ouputStream) {
|
||||
try {
|
||||
if (inputFile.exists()) {
|
||||
if (inputFile.isFile()) {
|
||||
FileInputStream IN = new FileInputStream(inputFile);
|
||||
BufferedInputStream bins = new BufferedInputStream(IN, 512);
|
||||
ZipEntry entry = new ZipEntry(inputFile.getName());
|
||||
ouputStream.putNextEntry(entry);
|
||||
// 向压缩文件中输出数据
|
||||
int nNumber;
|
||||
byte[] buffer = new byte[512];
|
||||
while ((nNumber = bins.read(buffer)) != -1) {
|
||||
ouputStream.write(buffer, 0, nNumber);
|
||||
}
|
||||
// 关闭创建的流对象
|
||||
bins.close();
|
||||
IN.close();
|
||||
} else {
|
||||
try {
|
||||
File[] files = inputFile.listFiles();
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
zipFile(files[i], ouputStream);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -100,10 +100,10 @@ public class rentPlanInvoiceDirectManager extends BaseTable{
|
||||
BizObjectManager viInvoiceRentManager = JBOFactory.getBizObjectManager(VI_LI_INVOICE_RENT_DIRECT.CLASS_NAME);
|
||||
|
||||
tx.join(lriiManager);
|
||||
tx.join(viInvoiceRentManager);
|
||||
//tx.join(viInvoiceRentManager);
|
||||
String[] planIds = this.getPlanIds().split("@");
|
||||
String invoice_status = "1";
|
||||
String bill_type = "invoice";
|
||||
String bill_type = "special";
|
||||
String invoice_money = "";
|
||||
String tax_type = "";
|
||||
String plan_id = "";
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user