|
@RequestMapping(params = "pzDownload",method=RequestMethod.POST)
@ResponseBody
public AjaxJson pzDownload(HttpServletRequest req,TTaskList tTaskList,TproofPage proof,HttpServletResponse response) {
AjaxJson j = new AjaxJson();
TSUser user = getCurrentUser();
TSDepart depart = user.getDepartID();
Integer fiAttr = Integer.parseInt(depart.getFiAttr());
if (fiAttr != 0 ) {
message = "权限不足,只有【连队会计】才能进行凭证下载的操作";
j.setMsg(message);
return j;
}
try {
String fsInvoice = req.getParameter("fsInvoice");
String hql=" from TproofPage where fs_invoice=?";
List<TproofPage> proofList=this.tTaskListService.findHql(hql, fsInvoice);
if(proofList!=null && proofList.size()>0){
TproofPage roof=proofList.get(0);
hql="from TTempletList t where t.fsInvoice= ?";
List<TTempletList> ttempletList= this.tTaskListService.findHql(hql,fsInvoice);
if(ttempletList!=null && ttempletList.size()>0){
List<String> rowList=new ArrayList<String>();
rowList.add("填制凭证,V800");
for(TTempletList templet:ttempletList){
String row=new String();
StringBuffer sb=new StringBuffer();
String fsName=templet.getFsName();
String sql="select t.fs_workno as fsWorkNo,t.fs_tlotcode as departCode from tcustominfo t where t.fs_cardno='"+templet.getFsCardNo()+"'";
Map<String,Object> m = this.tTaskListService.findOneForJdbc(sql);
if(m!=null){
row+=roof.getFsDate()+"," //登记日期
+roof.getFiTask()+"," //任务状态
+roof.getFsDetail()+"," //摘要
+roof.getFsInvoice()+"," //任务号
+roof.getFdMoney()+"," //总金额
+roof.getFdNum()+"," //总数量
+roof.getFdPrice1()+"," //单价
+roof.getFsObj()+"," //所属机构
+roof.getFsAgent()+"," //经办机构
+roof.getFsOper()+"," //操作员
+roof.getFsAccDate()+","//记帐日期
+roof.getFsAutoDate()+"," //自动记帐日期
+roof.getFiAim()+"," //收费项目编号
+roof.getFiTranFlag()+"," //收息标志
+roof.getFiStatus()+"," //任务状态
+fsName+"," //职工姓名
+m.get("fsWorkNo")+"," //职工代码
+m.get("departCode"); //部门编码
rowList.add(row);
}
}
PrintWriter pw=null;
FileInputStream fis=null;
OutputStream out=null;
try {
String path=req.getSession().getServletContext().getRealPath("/");
//准备好一个目的地
File file=new File(path+"upload\\pz.txt");
pw= new PrintWriter(file);
for(String str:rowList){
pw.print(str+"\n");
}
pw.close();
// File srcFile=new File(path+"upload\\pz.txt");
// File destFile=new File(path+"upload\\pzz.txt");
// FileUtils.copyFile(srcFile, destFile);
//
//文件下载
response.setCharacterEncoding("ISO8859-1");
String newtitle = new String("导出凭证下载".getBytes("UTF-8"),"ISO8859-1");
response.setContentType("text/plain;charset=UTF-8");
response.setHeader("content-disposition","attachment;filename="+newtitle+".txt");
// File f=new File(path+"upload\\pzz.txt");
// fis=new FileInputStream(f);
// System.out.println(fis);
// out = response.getOutputStream();
// byte[] b = new byte[1024];
// int len=0;
// while ((len = fis.read(b)) != -1) {
// out.write(b, 0, len);
// }
BufferedOutputStream buff = null;
StringBuffer write = new StringBuffer();
String enter = "\r\n";
String result=new String();
for(String str:rowList){
result += str+"\n";
}
out = response.getOutputStream(); // 建立
buff = new BufferedOutputStream(out);
write.append(result.replaceAll("\n", enter));
buff.write(write.toString().getBytes("UTF-8"));
buff.flush();
buff.close();
} catch (Exception e) {
j.setMsg(e.getMessage());
logger.error(ExceptionUtil.getExceptionMessage(e));
}finally{
// try {
// fis.close();
// out.close();
// } catch (Exception e2) {
// e2.printStackTrace();
// }
}
}
}
j.setMsg("文件下载成功");
} catch (Exception e) {
j.setMsg(e.getMessage());
logger.error(ExceptionUtil.getExceptionMessage(e));
}
return j;
}
用这种方式能读取到上穿的文件但是 实现下载的时候能读取到该文件,但是就是下载不下来,很奇怪的一件事情,我想jeecg实现下载是不是一块短板,希望看到本贴的开发人士如果有好的方案请与我分享
|
|