|
@@ -20,6 +20,7 @@ import com.iamberry.rst.utils.StitchAttrUtil;
|
|
|
import com.iamberry.wechat.tools.ResponseJson;
|
|
|
import net.sf.json.JSONArray;
|
|
|
import net.sf.json.JSONObject;
|
|
|
+import org.apache.poi.hssf.usermodel.*;
|
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
@@ -28,7 +29,10 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.*;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
@@ -504,5 +508,180 @@ public class AdminSignclosedController {
|
|
|
return msg;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 进入导出签收页面
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/to_download_signclose")
|
|
|
+ public ModelAndView toDownloadDetection(HttpServletRequest request) {
|
|
|
+ ModelAndView mv = new ModelAndView("cm/signclosed/download_signclosed");
|
|
|
+ return mv;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出签收信息
|
|
|
+ * @param request
|
|
|
+ * @param res
|
|
|
+ * @param signclosedInfo
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @RequestMapping("/download_signclosed")
|
|
|
+ public void downloadDetection(HttpServletRequest request,HttpServletResponse res
|
|
|
+ , ComplaintSignclosedInfo signclosedInfo) throws Exception{
|
|
|
+ //根据id查询订单数据
|
|
|
+
|
|
|
+ List<ComplaintSignclosedInfo> signclosedList = complaintSignclosedInfoService.listSignclosed(signclosedInfo);
|
|
|
+ /*if (detectList == null || detectList.size() == 0) {
|
|
|
+ return;
|
|
|
+ }*/
|
|
|
+ String[] cells = {
|
|
|
+ "序号","维修编号","产品名称","生产月份","机身条码","是否少件",
|
|
|
+ "退货地区","返厂日期","售后处理类型","工厂检测现象","是否翻新机","故障原因","判断结果","故障指向","原因分析","维修内容"
|
|
|
+ };
|
|
|
+ exportExcel2(request,res,cells,signclosedList);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 导出订单Excel并下载
|
|
|
+ * @param request
|
|
|
+ * @param res
|
|
|
+ * @param cells
|
|
|
+ * @param signclosedList
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public void exportExcel2(HttpServletRequest request,HttpServletResponse res,
|
|
|
+ String[] cells,List<ComplaintSignclosedInfo> signclosedList) throws Exception {
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ //创建一个workbook,对应一个Excel文件
|
|
|
+ HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
+ //在workbook中添加一个sheet,对应Excel中的一个sheet
|
|
|
+ HSSFSheet sheet = wb.createSheet("导出签收");
|
|
|
+ //在sheet中添加表头第0行,老版本poi对excel行数列数有限制short
|
|
|
+ HSSFRow row = sheet.createRow((int) 0);
|
|
|
+ //创建单元格,设置值表头,设置表头居中
|
|
|
+ HSSFCellStyle style = wb.createCellStyle();
|
|
|
+ //居中格式
|
|
|
+ style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
|
|
|
+ //设置表头
|
|
|
+
|
|
|
+ if (cells == null || cells.length == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //循环设置表头
|
|
|
+ HSSFCell cell = null;
|
|
|
+ for (int i = 0;i < cells.length;i++) {
|
|
|
+ String name = cells[i];
|
|
|
+ cell = row.createCell(i);
|
|
|
+ cell.setCellValue(name);
|
|
|
+ cell.setCellStyle(style);
|
|
|
+ }
|
|
|
+ for (int i = 0; i < signclosedList.size(); i++) {
|
|
|
+ row = sheet.createRow((int) i + 1);
|
|
|
+ ComplaintSignclosedInfo info = signclosedList.get(i);
|
|
|
+ String detectFilmType = "";
|
|
|
+
|
|
|
+
|
|
|
+ String signclosedIsWhetherLess = "";
|
|
|
+ if(info.getSignclosedIsWhetherLess() != null){
|
|
|
+ switch (info.getSignclosedIsWhetherLess()) {
|
|
|
+ case 1:signclosedIsWhetherLess = "是";break;
|
|
|
+ case 2:signclosedIsWhetherLess = "否";break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String detectIsRefurbishing = "";
|
|
|
+ if(info.getDetectIsRefurbishing() != null){
|
|
|
+ switch (info.getDetectIsRefurbishing()) {
|
|
|
+ case 1:detectIsRefurbishing = "是";break;
|
|
|
+ case 2:detectIsRefurbishing = "否";break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String productName = "";
|
|
|
+ String productColor = "";
|
|
|
+ if(info.getSignclosedProductInfoList().size() > 0){
|
|
|
+ for (SignclosedProductInfo productInfo : info.getSignclosedProductInfoList()){
|
|
|
+ productName = productName+productInfo.getProductName()+"("+productInfo.getColorName()+")" + "*" + productInfo.getProductNum();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 创建单元格,设置值
|
|
|
+ row.createCell(0).setCellValue(info.getSignclosedId());
|
|
|
+ if(info.getDetectNumber() == null){
|
|
|
+ row.createCell(1).setCellValue("");
|
|
|
+ }else{
|
|
|
+ row.createCell(1).setCellValue(info.getDetectNumber());
|
|
|
+ }
|
|
|
+ row.createCell(2).setCellValue(productName);
|
|
|
+ row.createCell(3).setCellValue(info.getDetectProduction()==null?"":info.getDetectProduction());
|
|
|
+ row.createCell(4).setCellValue(info.getDetectFuselageBarcode()==null?"":info.getDetectProduction());
|
|
|
+ row.createCell(5).setCellValue(signclosedIsWhetherLess);
|
|
|
+ StringBuffer area = new StringBuffer(" ");
|
|
|
+ if(info.getSignclosedAddrProvincesName() == null || info.getSignclosedAddrProvincesName().equals("")){
|
|
|
+ area.append("");
|
|
|
+ }else{
|
|
|
+ area.append(info.getSignclosedAddrProvincesName());
|
|
|
+ }
|
|
|
+ if(info.getSignclosedAddrCityName() == null || info.getSignclosedAddrCityName().equals("")){
|
|
|
+ area.append("");
|
|
|
+ }else{
|
|
|
+ area.append("-"+info.getSignclosedAddrCityName());
|
|
|
+ }
|
|
|
+ row.createCell(6).setCellValue(area.toString());
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ if(info.getSignclosedDate()==null){
|
|
|
+ row.createCell(7).setCellValue( "");
|
|
|
+ }else{
|
|
|
+ row.createCell(7).setCellValue(sdf.format(info.getSignclosedDate()));
|
|
|
+ }
|
|
|
+ row.createCell(8).setCellValue(info.getProcMethodName()==null?"":info.getProcMethodName());
|
|
|
+ row.createCell(9).setCellValue(info.getDetectPhenomenon()==null?"":info.getDetectPhenomenon());
|
|
|
+ row.createCell(10).setCellValue(detectIsRefurbishing);
|
|
|
+ row.createCell(11).setCellValue(info.getDetectFailureCause()==null?"":info.getDetectFailureCause());
|
|
|
+ row.createCell(12).setCellValue(info.getDetectResults()==null?"":info.getDetectResults());
|
|
|
+ row.createCell(13).setCellValue(info.getDetectPoint()==null?"":info.getDetectPoint());
|
|
|
+ row.createCell(14).setCellValue(info.getDetectNalysis()==null?"":info.getDetectNalysis());
|
|
|
+ row.createCell(15).setCellValue(info.getDetectContent()==null?"":info.getDetectContent());
|
|
|
+ }
|
|
|
+ //下载导出订单Excel
|
|
|
+ downloadOrderExcel(res,wb);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下载导出订单Excel
|
|
|
+ * @param res
|
|
|
+ * @param wb
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public void downloadOrderExcel(HttpServletResponse res, HSSFWorkbook wb) throws Exception{
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ String fileName = format.format(new Date()) + "签收报表";
|
|
|
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
|
|
|
+ wb.write(os);
|
|
|
+ byte[] content = os.toByteArray();
|
|
|
+ InputStream is = new ByteArrayInputStream(content);
|
|
|
+ // 设置response参数,可以打开下载页面
|
|
|
+ res.reset();
|
|
|
+ res.setContentType("application/vnd.ms-excel;charset=utf-8");
|
|
|
+ res.setHeader("Content-Disposition", "attachment;filename="
|
|
|
+ + new String((fileName + ".xls").getBytes(), "iso-8859-1"));
|
|
|
+ ServletOutputStream out = res.getOutputStream();
|
|
|
+ BufferedInputStream bis = null;
|
|
|
+ BufferedOutputStream bos = null;
|
|
|
+ try {
|
|
|
+ bis = new BufferedInputStream(is);
|
|
|
+ bos = new BufferedOutputStream(out);
|
|
|
+ byte[] buff = new byte[2048];
|
|
|
+ int bytesRead;
|
|
|
+ // Simple read/write loop.
|
|
|
+ while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
|
|
|
+ bos.write(buff, 0, bytesRead);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ // TODO: handle exception
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ if (bis != null)
|
|
|
+ bis.close();
|
|
|
+ if (bos != null)
|
|
|
+ bos.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|