| | |
| | | import com.panzhihua.common.service.partybuilding.PartyBuildingService; |
| | | import com.panzhihua.common.utlis.SFTPUtil; |
| | | import com.panzhihua.community_backstage.excel.CustomSheetWriteHandler; |
| | | import freemarker.template.Configuration; |
| | | import freemarker.template.Template; |
| | | import freemarker.template.Version; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.*; |
| | | import java.net.URL; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "导出图片测试") |
| | | @PostMapping("/export/picture") |
| | | public void test(@RequestParam(value = "id") Long id){ |
| | | Long communityId = this.getLoginUserInfo().getCommunityId(); |
| | | Map<String,Object> dataMap = new HashMap<String, Object>(); |
| | | try { |
| | | ComSwSafetyWorkRecordVO comSwSafetyWorkRecordVO = JSONObject.parseObject(JSONObject.toJSONString(communityService.detailSafetyWorkRecord(id, communityId).getData()),ComSwSafetyWorkRecordVO.class); |
| | | //日期 |
| | | dataMap.put("date", new SimpleDateFormat("yyyy-MM-dd").format(comSwSafetyWorkRecordVO.getPatrolTime())); |
| | | Configuration configuration = new Configuration(new Version("2.3.0")); |
| | | configuration.setDefaultEncoding("utf-8"); |
| | | |
| | | /** |
| | | * 以下是两种指定ftl文件所在目录路径的方式,注意这两种方式都是 |
| | | * 指定ftl文件所在目录的路径,而不是ftl文件的路径 |
| | | */ |
| | | //指定路径的第一种方式(根据某个类的相对路径指定) |
| | | // configuration.setClassForTemplateLoading(this.getClass(), ""); |
| | | |
| | | //指定路径的第二种方式,我的路径是C:/a.ftl |
| | | configuration.setDirectoryForTemplateLoading(new File("c:/")); |
| | | |
| | | //输出文档路径及名称 |
| | | File outFile = new File("D:/报销信息导出.doc"); |
| | | |
| | | //以utf-8的编码读取ftl文件 |
| | | Template template = configuration.getTemplate("报告.ftl", "utf-8"); |
| | | Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"), 10240); |
| | | template.process(dataMap, out); |
| | | out.close(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | private List<List<String>> headDataFilling(){ |
| | | List<List<String>> list = new ArrayList<List<String>>(); |
| | | List<String> head0 = new ArrayList<String>(); |