|
|
@@ -1,15 +1,33 @@
|
|
|
package com.xintong.visualinspection.service.impl;
|
|
|
|
|
|
+import java.io.BufferedInputStream;
|
|
|
+import java.io.BufferedOutputStream;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+import org.jxls.common.Context;
|
|
|
+import org.jxls.util.JxlsHelper;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import com.alibaba.druid.util.Utils;
|
|
|
import com.xintong.visualinspection.bean.CheckOther;
|
|
|
import com.xintong.visualinspection.dao.master.CheckOtherDao;
|
|
|
import com.xintong.visualinspection.service.BaseService;
|
|
|
import com.xintong.visualinspection.service.CheckOtherService;
|
|
|
+import com.xintong.visualinspection.util.CodeUtil;
|
|
|
+import com.xintong.visualinspection.util.DateUtil;
|
|
|
|
|
|
/**
|
|
|
* 文件名:CheckOtherServiceImpl
|
|
|
@@ -31,6 +49,84 @@ public class CheckOtherServiceImpl extends BaseService implements CheckOtherSer
|
|
|
List<CheckOther> checkOtherList = checkOtherDao.getCheckByDeptId(checkOther);
|
|
|
return checkOtherList;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getOtherCheckExcel(CheckOther checkOther, HttpServletRequest req, HttpServletResponse resp) {
|
|
|
+ List<CheckOther> checkOtherList = getCheckByDeptId(checkOther);
|
|
|
+ Long id = 1L ;
|
|
|
+ for(CheckOther co : checkOtherList){
|
|
|
+ co.setId(id++);
|
|
|
+ if(co.getWrecker_check_type()!=null){
|
|
|
+ co.setWrecker_check_type_name(CodeUtil.getCodeNameByFlagAndValue("wrecker_group_check_type", co.getWrecker_check_type()+""));
|
|
|
+ }
|
|
|
+ if(co.getSpecial_check_type()!=null){
|
|
|
+ co.setSpecial_check_type_name(CodeUtil.getCodeNameByFlagAndValue("special_check_type", co.getSpecial_check_type()+""));
|
|
|
+ }
|
|
|
+ co.setCheck_time_name(DateUtil.DateFormatStr(co.getCheck_time()));
|
|
|
+ if( co.getUsername() == null || "".equals(co.getUsername()) ){
|
|
|
+ co.setUsername("站部");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<String, Object> map = new HashMap<String, Object>();
|
|
|
+ map.put("list", checkOtherList);
|
|
|
+ if(checkOther.getCheck_type() == 1){
|
|
|
+ exportExcel("第三方暗访稽查" , "third_check", map, resp);
|
|
|
+ }else if(checkOther.getCheck_type() == 2){
|
|
|
+ exportExcel("特情稽查" , "special_check", map, resp);
|
|
|
+ }else if(checkOther.getCheck_type() == 3){
|
|
|
+ exportExcel("现场稽查" , "duty_check", map, resp);
|
|
|
+ }else if(checkOther.getCheck_type() == 4){
|
|
|
+ exportExcel("数据平台应用稽查" , "data_platform", map, resp);
|
|
|
+ }else if(checkOther.getCheck_type() == 5){
|
|
|
+ exportExcel("清排障稽查" , "solve_traffic", map, resp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void exportExcel(String fileName, String excelTemplateName, Map<String, Object> map,
|
|
|
+ HttpServletResponse resp) {
|
|
|
+ String path = "./" + fileName + ".xls";
|
|
|
+ try (InputStream is = this.getClass().getResourceAsStream("/" + excelTemplateName + ".xls")) {
|
|
|
+ try (OutputStream os = new FileOutputStream(path)) {
|
|
|
+ Context context = new Context();
|
|
|
+ // context.putVar("list", map.get("list"));
|
|
|
+ // context.putVar("totalMan", map.get("totalMan"));
|
|
|
+ for (String key : map.keySet()) {
|
|
|
+ context.putVar(key, map.get(key));
|
|
|
+ }
|
|
|
+ JxlsHelper.getInstance().processTemplate(is, os, context);
|
|
|
+ }
|
|
|
+ Thread.sleep(1000);
|
|
|
+ // path是指欲下载的文件的路径。
|
|
|
+ File file = new File(path);
|
|
|
+ // 取得文件名。
|
|
|
+ String filename = file.getName();
|
|
|
+ // 以流的形式下载文件。
|
|
|
+ InputStream bis = new BufferedInputStream(new FileInputStream(file));
|
|
|
+ byte[] buffer = new byte[bis.available()];
|
|
|
+ bis.read(buffer);
|
|
|
+ bis.close();
|
|
|
+ // 清空response
|
|
|
+ resp.reset();
|
|
|
+ // 设置response的Header
|
|
|
+ resp.addHeader("Content-Disposition",
|
|
|
+ "attachment;filename=" + new String(filename.getBytes("gb2312"), "ISO8859-1"));
|
|
|
+ resp.addHeader("Content-Length", "" + file.length());
|
|
|
+ OutputStream toClient = new BufferedOutputStream(resp.getOutputStream());
|
|
|
+ resp.setContentType("application/vnd.ms-excel;charset=gb2312");
|
|
|
+ toClient.write(buffer);
|
|
|
+ toClient.flush();
|
|
|
+ toClient.close();
|
|
|
+ // 删除生成的临时文件
|
|
|
+ if (file.exists()) {
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error(e.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public void delete(Long id) {
|
|
|
checkOtherDao.delete(id);
|
|
|
@@ -44,4 +140,5 @@ public class CheckOtherServiceImpl extends BaseService implements CheckOtherSer
|
|
|
public void update(CheckOther checkOther) {
|
|
|
checkOtherDao.update(checkOther);
|
|
|
}
|
|
|
+
|
|
|
}
|