设备维修导出和零部件实体类

master
马雪伟 7 hours ago
parent dd1bc05ee4
commit 92910e636a

@ -87,6 +87,11 @@
<groupId>com.hw</groupId> <groupId>com.hw</groupId>
<artifactId>hw-api-system</artifactId> <artifactId>hw-api-system</artifactId>
</dependency> </dependency>
<dependency>
<groupId>net.sf.jxls</groupId>
<artifactId>jxls-core</artifactId>
<version>1.0.3</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

@ -6,9 +6,8 @@ import java.util.List;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.hw.dms.TemplateExcelUtils;
import com.hw.dms.domain.DmsFaultInstanceActivity; import com.hw.dms.domain.DmsFaultInstanceActivity;
import com.hw.dms.utils.TemplateExcelUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;

@ -0,0 +1,12 @@
package com.hw.dms.domain;
import lombok.Data;
@Data
public class DmsFaultCompentsParts {
private Long compentsPartsId;
private Long faultId;
private String partName;
private String partSpecifications;
private Integer amount;
}

@ -0,0 +1,63 @@
package com.hw.dms.utils;
import net.sf.jxls.transformer.XLSTransformer;
import org.apache.poi.ss.usermodel.Workbook;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.Map;
public class TemplateExcelUtils {
/**
*
* @param fileName
* @param sourcePath resource/template
* @param beanParams
* @param response
* @throws Exception
*/
public static void downLoadExcel(String fileName,String sourcePath, Map<String, Object> beanParams, HttpServletResponse response)
throws Exception {
try{
OutputStream os = getOutputStream(fileName,response);
//读取模板
InputStream is = TemplateExcelUtils.class.getResourceAsStream("/weixiu.xlsx");
XLSTransformer transformer = new XLSTransformer();
// beanParams.put("title","titl");
//向模板中写入内容
Workbook workbook = transformer.transformXLS(is, beanParams);
//写入成功后转化为输出流
workbook.write(os);
}catch (Exception e){
e.printStackTrace();
throw e;
}
}
/**
* WriterOutputStream.
* @param fileName
* @param response response
* @return ""
*/
private static OutputStream getOutputStream(String fileName,
HttpServletResponse response) throws Exception {
try {
fileName = URLEncoder.encode(fileName, "UTF-8");
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf8");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".xls");
response.setHeader("Pragma", "public");
response.setHeader("Cache-Control", "no-store");
response.addHeader("Cache-Control", "max-age=0");
return response.getOutputStream();
} catch (IOException e) {
throw new Exception("导出excel表格失败!", e);
}
}
}
Loading…
Cancel
Save