|
|
@@ -2,6 +2,7 @@ package com.izouma.wenlvju.service;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.poi.word.WordUtil;
|
|
|
import com.github.kevinsawicki.http.HttpRequest;
|
|
|
import com.izouma.wenlvju.config.DateConfig;
|
|
|
import com.izouma.wenlvju.domain.*;
|
|
|
@@ -24,6 +25,7 @@ import org.apache.pdfbox.io.MemoryUsageSetting;
|
|
|
import org.apache.pdfbox.multipdf.PDFMergerUtility;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import sun.misc.BASE64Encoder;
|
|
|
|
|
|
import javax.servlet.ServletOutputStream;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
@@ -208,6 +210,12 @@ public class RateService {
|
|
|
//Configuration 用于读取ftl文件
|
|
|
Configuration configuration = new Configuration(new Version("2.3.0"));
|
|
|
|
|
|
+ //图片
|
|
|
+ if (CollUtil.isNotEmpty(rate.getBusiness())) {
|
|
|
+ String img = this.Image2Base64(rate.getBusiness().get(0));
|
|
|
+ dataMap.put("content", img);
|
|
|
+ }
|
|
|
+
|
|
|
configuration.setDefaultEncoding("utf-8");
|
|
|
configuration.setClassForTemplateLoading(this.getClass(), "/templates");//指定ftl所在目录,根据自己的改
|
|
|
StringWriter writer = new StringWriter();
|
|
|
@@ -220,6 +228,57 @@ public class RateService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public String Image2Base64(String imgUrl) {
|
|
|
+// URL url = null;
|
|
|
+ InputStream is = HttpRequest.get(imgUrl).stream();
|
|
|
+ ByteArrayOutputStream outStream = null;
|
|
|
+// HttpURLConnection httpUrl = null;
|
|
|
+ try {
|
|
|
+// url = new URL(imgUrl);
|
|
|
+// httpUrl = (HttpURLConnection) url.openConnection();
|
|
|
+// httpUrl.connect();
|
|
|
+// httpUrl.getInputStream();
|
|
|
+// is = httpUrl.getInputStream();
|
|
|
+
|
|
|
+ outStream = new ByteArrayOutputStream();
|
|
|
+ //创建一个Buffer字符串
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ //每次读取的字符串长度,如果为-1,代表全部读取完毕
|
|
|
+ int len = 0;
|
|
|
+ //使用一个输入流从buffer里把数据读取出来
|
|
|
+ while ((len = is.read(buffer)) != -1) {
|
|
|
+ //用输出流往buffer里写入数据,中间参数代表从哪个位置开始读,len代表读取的长度
|
|
|
+ outStream.write(buffer, 0, len);
|
|
|
+ }
|
|
|
+ // 对字节数组Base64编码
|
|
|
+// return new BASE64Encoder().encode(outStream.toByteArray());
|
|
|
+ BASE64Encoder encoder = new BASE64Encoder();
|
|
|
+ return encoder.encode(outStream.toByteArray()).replace("\n", "\r\n").replace("\r\r\n", "\r\n");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } //下载
|
|
|
+ finally {
|
|
|
+ if (is != null) {
|
|
|
+ try {
|
|
|
+ is.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (outStream != null) {
|
|
|
+ try {
|
|
|
+ outStream.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+// if (httpUrl != null) {
|
|
|
+// httpUrl.disconnect();
|
|
|
+// }
|
|
|
+ }
|
|
|
+ return imgUrl;
|
|
|
+ }
|
|
|
+
|
|
|
public List<File> upLoad(Rate rate) {
|
|
|
List<File> files = new ArrayList<>();
|
|
|
String uri = "http://192.168.50.238:8080/word2pdf";
|
|
|
@@ -462,7 +521,7 @@ public class RateService {
|
|
|
|
|
|
public Map<String, String> applyMessage(String district, LocalDateTime time) {
|
|
|
DateTimeFormatter dtf = DateTimeFormatter.ofPattern(DateConfig.DEFAULT_DATE_TIME_FORMAT);
|
|
|
- String phone = userRepo.findAllByDistrictAndAuthoritiesContainsAndDelFalse(district, Authority.get(AuthorityName.ROLE_DISTRICT))
|
|
|
+ String phone = userRepo.findAllByDistrictAndAuthoritiesContainsAndDelFalse(district, Authority.get(AuthorityName.ROLE_DISTRICT_STAFF))
|
|
|
.stream()
|
|
|
.map(User::getPhone)
|
|
|
.collect(Collectors.joining(","));
|