Commit 6df23e31 authored by liboyang's avatar liboyang

Merge remote-tracking branch 'origin/dev' into dev

parents 79a5b47e 199f75a2
package com.yxproject.start.api;
import java.io.*;
import java.net.URLEncoder;
import com.yxproject.start.service.DetailReceiptListService;
import com.yxproject.start.service.ReceiptService;
import com.yxproject.start.utils.ExportExcel;
......@@ -12,11 +14,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map;
......@@ -60,27 +59,84 @@ public class ExportExcelApi {
* 导出交接单
*/
@RequestMapping("printReceiptExcelData")
public byte[] printReceiptExcelData(@RequestBody String list, HttpServletResponse response){
public byte[] printReceiptExcelData(@RequestBody String list, HttpServletResponse response, HttpServletRequest request){
JSONObject jsonObject = JSONObject.fromObject(list);
JSONArray jsonArray = JSONArray.fromObject(jsonObject.get("list"));
String date = jsonObject.get("date").toString();
String type = jsonObject.get("type").toString();
List<Map<String, Object>> mapList = receiptService.selectReceiptList(jsonArray,replaceDate(date),Long.valueOf(type));
// List<Map<String, Object>> mapList = new ArrayList<>();
response.setContentType("application/x-download");
response.setCharacterEncoding("UTF-8");
String dateTime = DateFormatUtils.format(new Date(), "yyyy-MM-dd");
String dateTime = DateFormatUtils.format(new Date(), "yyyy_MM_dd");
// //使用Servlet实现文件下载的时候,避免浏览器自动打开文件
String fout = null;
fout = ExportExcel.exportReceiptExcelDate(mapList);
String outFile = dateTime+"交接单" ;
String outFile = dateTime+"" ;
//
// String agent = request.getHeader("User-Agent").toUpperCase(); //获得浏览器信息并转换为大写
// if (agent.indexOf("MSIE") > 0 || (agent.indexOf("GECKO")>0 && agent.indexOf("RV:11")>0)) { //IE浏览器和Edge浏览器
// try {
// outFile = URLEncoder.encode(outFile, "UTF-8");
// } catch (UnsupportedEncodingException e) {
// e.printStackTrace();
// }
// } else { //其他浏览器
// try {
// outFile = new String(outFile.getBytes("UTF-8"), "iso-8859-1");
// } catch (UnsupportedEncodingException e) {
// e.printStackTrace();
// }
// }
//
// try {
// outFile = URLEncoder.encode(outFile, "UTF8");
// } catch (UnsupportedEncodingException e) {
// e.printStackTrace();
// }
// String userAgent = request.getHeader("User-Agent");
// /*针对IE或者以IE为内核的浏览器:*/
// if (userAgent != null) {
// userAgent = userAgent.toLowerCase();
// /*IE浏览器,只能采用URLEncoder编码*/
// if (userAgent.indexOf("msie") != -1) {
// outFile = "filename=\"" + outFile + "\"";
// }
// /*Opera浏览器只能采用filename**/
// else if (userAgent.indexOf("opera") != -1) {
// outFile = "filename*=UTF-8''" + outFile;
// }
// /*Safari浏览器,只能采用ISO编码的中文输出*/
// else if (userAgent.indexOf("safari") != -1) {
// try {
// outFile = "filename=\"" + new String(outFile.getBytes("UTF-8"), "ISO8859-1") + "\"";
// } catch (UnsupportedEncodingException e) {
// e.printStackTrace();
// }
// }
// /*Chrome浏览器,只能采用MimeUtility编码或ISO编码的中文输出*/
//// else if (userAgent.indexOf("applewebkit") != -1) {
//// fileName = MimeUtility.encodeText(fileName, "UTF8", "B");
//// rtn = "filename=\"" + fileName + "\"";
//// }
// /* FireFox浏览器,可以使用MimeUtility或filename*或ISO编码的中文输出*/
// else if (userAgent.indexOf("mozilla") != -1) {
// outFile = "filename*=UTF-8''" + outFile;
// }
// }
////
//
//
// }
try {
FileInputStream fis = new FileInputStream(new File(fout));
byte[] b = new byte[fis.available()];
fis.read(b);
fis.close();
response.setCharacterEncoding("utf-8");
response.setContentType("APPLICATION/OCTET-STREAM");
response.addHeader("Content-Disposition", "attachment;filename=" + outFile + ".xls");
response.addHeader("Content-Disposition", "attachment;" + new String(outFile.getBytes(),"iso-8859-1") +".xls");
//
return b;
} catch (FileNotFoundException e) {
e.printStackTrace();
......
......@@ -226,12 +226,12 @@ public interface TaskListMapper {
* @param process 工序
* @return
*/
@Select("select task.submit_date, task.task_id,CARD_TYPE_DIC.CARD_TYPE,CARD_TYPE_DIC.CARD_TYPE_ID,COUNTY_DIC.COUNTY_CODE,\n" +
@Select("select distinct task.submit_date, task.task_id,CARD_TYPE_DIC.CARD_TYPE,CARD_TYPE_DIC.CARD_TYPE_ID,COUNTY_DIC.COUNTY_CODE,\n" +
"COUNTY_DIC.COUNTYNAME, group_no.VALID_COUNT,group_no.INVALID_COUNT,group_no.SPECIAL_CARD_COUNT,group_no.GROUP_NO, nvl(fc.faileCount,0) faileCount\n" +
"from group_no left join task on group_no.task_id= task.TASK_ID\n" +
"left join CARD_TYPE_DIC on CARD_TYPE_DIC.CARD_TYPE_ID = task.CARD_TYPE\n" +
"left join COUNTY_DIC on COUNTY_DIC.COUNTY_CODE = task.COUNTY_CODE\n" +
"left join (select accept_no, nvl(count(*),0) faileCount from FAILED_CARD where FAILED_CARD.state <=#{process2} and FAILED_CARD.state != FAILED_CARD.INITIATOR group by accept_no ) fc on substr(fc.accept_no,0,8) = group_no.group_no \n" +
"left join (select accept_no, nvl(count(*),0) faileCount from FAILED_CARD where FAILED_CARD.state <=#{process2} and FAILED_CARD.state != FAILED_CARD.INITIATOR and accept_no not in (select accept_no from special_card ) group by accept_no ) fc on substr(fc.accept_no,0,8) = group_no.group_no \n" +
"where task.TASK_STATE_ID = #{process} order by group_no.GROUP_NO")
public List<Map<String,Object>> selectByCountyAtAuxiliary_common(@Param("process") long process,@Param("process2") long process2);
......@@ -418,7 +418,7 @@ public interface TaskListMapper {
"from group_no left join task on group_no.task_id= task.TASK_ID\n" +
"left join CARD_TYPE_DIC on CARD_TYPE_DIC.CARD_TYPE_ID = task.CARD_TYPE\n" +
"left join COUNTY_DIC on COUNTY_DIC.COUNTY_CODE = task.COUNTY_CODE\n" +
"left join (select accept_no, nvl(count(*),0) faileCount from FAILED_CARD where FAILED_CARD.state <=#{process2} and FAILED_CARD.state != FAILED_CARD.INITIATOR \n" +
"left join (select accept_no, nvl(count(*),0) faileCount from FAILED_CARD where FAILED_CARD.state <=#{process2} and FAILED_CARD.state != FAILED_CARD.INITIATOR and accept_no not in (select accept_no from special_card ) \n" +
"group by accept_no ) fc on substr(fc.accept_no,0,8) = group_no.group_no \n" +
"left join prod_trace_t@PROD_LINK on SUBSTR(prod_trace_t.ACCEPT_NO,0,8) = group_no.GROUP_NO\n" +
"left join prod_card_t@PROD_LINK on prod_trace_t.ACCEPT_NO =prod_card_t.ACCEPT_NO\n" +
......
......@@ -172,7 +172,7 @@ public class ExportExcel {
FileOutputStream fout = null;
try {
// fout = new FileOutputStream("E:\\Excel\\" + simpleDateFormat.format(new Date()) + countyInfoList.get(0).get("COUNTYNAME") + ".xls");
fout = new FileOutputStream("F:\\Excel\\" + simpleDateFormat.format(new Date())+ "交接单" + ".xls");
fout = new FileOutputStream("D:\\Excel\\" + simpleDateFormat.format(new Date())+ "交接单" + ".xls");
wb.write(fout);
fout.close();
} catch (IOException e) {
......@@ -181,7 +181,7 @@ public class ExportExcel {
System.out.println("Excel文件生成成功..." + new Date());
// return "E:\\Excel\\" + simpleDateFormat.format(new Date()) +countyInfoList.get(0).get("COUNTYNAME") + ".xls";
return "F:\\Excel\\" + simpleDateFormat.format(new Date()) + "交接单" + ".xls";
return "D:\\Excel\\" + simpleDateFormat.format(new Date()) + "交接单" + ".xls";
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment