RateService.java 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. package com.izouma.wenlvju.service;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.util.ObjectUtil;
  4. import cn.hutool.core.util.StrUtil;
  5. import com.github.kevinsawicki.http.HttpRequest;
  6. import com.izouma.wenlvju.config.DateConfig;
  7. import com.izouma.wenlvju.domain.*;
  8. import com.izouma.wenlvju.dto.PageQuery;
  9. import com.izouma.wenlvju.dto.ReviewTime;
  10. import com.izouma.wenlvju.enums.AuthorityName;
  11. import com.izouma.wenlvju.enums.RateStatus;
  12. import com.izouma.wenlvju.exception.BusinessException;
  13. import com.izouma.wenlvju.repo.*;
  14. import com.izouma.wenlvju.security.Authority;
  15. import com.izouma.wenlvju.service.sms.NjwlSmsService;
  16. import com.izouma.wenlvju.utils.JpaUtils;
  17. import com.izouma.wenlvju.utils.ObjUtils;
  18. import com.lowagie.text.Document;
  19. import com.lowagie.text.DocumentException;
  20. import com.lowagie.text.Image;
  21. import com.lowagie.text.PageSize;
  22. import com.lowagie.text.pdf.PdfWriter;
  23. import freemarker.template.Configuration;
  24. import freemarker.template.Template;
  25. import freemarker.template.Version;
  26. import lombok.AllArgsConstructor;
  27. import lombok.extern.slf4j.Slf4j;
  28. import org.apache.pdfbox.io.MemoryUsageSetting;
  29. import org.apache.pdfbox.multipdf.PDFMergerUtility;
  30. import org.springframework.data.domain.Page;
  31. import org.springframework.stereotype.Service;
  32. import javax.servlet.ServletOutputStream;
  33. import javax.servlet.http.HttpServletResponse;
  34. import java.io.*;
  35. import java.time.LocalDate;
  36. import java.time.LocalDateTime;
  37. import java.time.format.DateTimeFormatter;
  38. import java.util.*;
  39. import java.util.concurrent.atomic.AtomicInteger;
  40. import java.util.stream.Collectors;
  41. @Service
  42. @Slf4j
  43. @AllArgsConstructor
  44. public class RateService {
  45. private final RateRepo rateRepo;
  46. private final CollaborateRepo collaborateRepo;
  47. private final GradingOrganizationRepo gradingOrganizationRepo;
  48. private final RateAuditRepo rateAuditRepo;
  49. private final UserRepo userRepo;
  50. private final NjwlSmsService njwlSmsService;
  51. public Page<Rate> all(PageQuery pageQuery) {
  52. return rateRepo.findAll(JpaUtils.toSpecification(pageQuery, Rate.class), JpaUtils.toPageRequest(pageQuery));
  53. }
  54. public Rate save(Rate record) {
  55. LocalDateTime now = LocalDateTime.now();
  56. String district = record.getDistrict();
  57. if (record.getId() != null) {
  58. Rate orig = rateRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
  59. boolean examination = orig.isUndertakeExamination();
  60. ObjUtils.merge(orig, record);
  61. switch (record.getStatus()) {
  62. case FIRST_REVIEW_PENDING: // 初审中 1
  63. orig.setApplyTime(now);
  64. //发送短信给地区考级管理人员
  65. Map<String, String> applyMap = this.applyMessage(district, now);
  66. njwlSmsService.sendSms(applyMap.get("phone"), applyMap.get("message"));
  67. break;
  68. case REVIEW_PENDING: // 分配专家组 3
  69. // 发送给专家组长和组员
  70. if (ObjectUtil.isEmpty(orig.getExpertUserId()) || CollUtil.isEmpty(orig.getExpertMemberUserId())) {
  71. throw new BusinessException("专家组长或组员不能为空");
  72. }
  73. Map<String, String> map = this.reviewTimesMessage(orig);
  74. // njwlSmsService.sendSms(map.get("phone"), map.get("message"));
  75. // njwlSmsService.sendSms(map.get("phone1"), map.get("message1"));
  76. break;
  77. case SUBMIT_GRADE:// 专家组提交成绩 4
  78. orig.setUndertakeExamination(examination);
  79. RateAudit rateAudit = RateAudit.builder()
  80. .userId(orig.getExpertUserId())
  81. .rateId(orig.getId())
  82. .remark("专家组已线下考察完毕")
  83. .status(RateStatus.SUBMIT_GRADE)
  84. .build();
  85. rateAuditRepo.save(rateAudit);
  86. Map<String, String> gradeMessage = this.gradeMessage(now, orig.getExpertUserId(), orig
  87. .getName());
  88. njwlSmsService.sendSms(gradeMessage.get("phone"), gradeMessage.get("message"));
  89. break;
  90. default:
  91. break;
  92. }
  93. orig.setSort(orig.getStatus().getSort());
  94. return rateRepo.save(orig);
  95. }
  96. String year = String.valueOf(LocalDate.now().getYear());
  97. if (rateRepo.countAllByOrganizationIdAndYearAndStatusNot(record.getOrganizationId(), year, RateStatus.CANCEL) > 0) {
  98. throw new BusinessException("已申请");
  99. }
  100. record.setYear(year);
  101. if (record.isSubmit() && RateStatus.FIRST_REVIEW_PENDING.equals(record.getStatus())) {
  102. record.setApplyTime(now);
  103. //发送短信给地区考级管理人员
  104. Map<String, String> map = this.applyMessage(district, now);
  105. njwlSmsService.sendSms(map.get("phone"), map.get("message"));
  106. }
  107. record.setSort(record.getStatus().getSort());
  108. return rateRepo.save(record);
  109. }
  110. /*
  111. 线下退回
  112. */
  113. public void offline(Long id, Long userId, RateStatus status) {
  114. Rate rate = rateRepo.findById(id).orElseThrow(new BusinessException("无记录"));
  115. rate.setStatus(status);
  116. rate.setSort(rate.getStatus().getSort());
  117. rateRepo.save(rate);
  118. RateAudit rateAudit = RateAudit.builder()
  119. .userId(userId)
  120. .rateId(id)
  121. .remark(RateStatus.REVIEW_PENDING.equals(status) ? "线下考察材料提交不全,被退回!" : "已取消专家组分配!")
  122. .status(status)
  123. .build();
  124. rateAuditRepo.save(rateAudit);
  125. }
  126. public void audit(Long id, RateStatus status, String remark, Long userId) {
  127. Rate rate = rateRepo.findById(id).orElseThrow(new BusinessException("无记录"));
  128. rate.setStatus(status);
  129. if (RateStatus.REVIEW_DENY.equals(status)) {
  130. // 市里退回
  131. rate.setRejected(true);
  132. rate.setRejectedAt(LocalDateTime.now());
  133. }
  134. RateAudit rateAudit = RateAudit.builder()
  135. .userId(userId)
  136. .rateId(id)
  137. .remark(remark)
  138. .status(status)
  139. .build();
  140. rateAuditRepo.save(rateAudit);
  141. rate.setSort(rate.getStatus().getSort());
  142. rateRepo.save(rate);
  143. switch (status) {
  144. case FIRST_REVIEW_DENY:
  145. // 发送短信给承办单位
  146. njwlSmsService.sendSms(rate.getOwnerPhone(), "你单位等级评定申请被" + rate.getDistrict() + "文化和旅游局退回,请根据反馈意见及时处理!");
  147. break;
  148. case ASSIGN_EXPERT:
  149. DateTimeFormatter dtf = DateTimeFormatter.ofPattern(DateConfig.DEFAULT_DATE_TIME_FORMAT);
  150. String phone1 = userRepo.findAllByAuthoritiesContainsAndDelFalse(Authority.get(AuthorityName.ROLE_ADMIN))
  151. .stream()
  152. .map(User::getPhone)
  153. .collect(Collectors.joining(","));
  154. String message1 = "您于" + dtf.format(LocalDateTime.now()) + ",收到" + rate.getDistrict() + "文化和旅游局上报的承办单位等级评定申请。";
  155. njwlSmsService.sendSms(phone1, message1);
  156. break;
  157. case REVIEW_DENY:
  158. String phone = userRepo.findAllByDistrictAndAuthoritiesContainsAndDelFalse(rate.getDistrict(), Authority
  159. .get(AuthorityName.ROLE_DISTRICT_STAFF))
  160. .stream()
  161. .map(User::getPhone)
  162. .collect(Collectors.joining(","));
  163. String message = "你区上报的承办单位等级评定申请被市文化和旅游局等级评定委员会退回,请根据反馈意见及时处理!";
  164. njwlSmsService.sendSms(phone, message);
  165. break;
  166. // case REVIEW_PENDING:
  167. // List<Long> ids = new ArrayList<>(rate.getExpertMemberUserId());
  168. // ids.add(rate.getExpertUserId());
  169. // String expertPhone = userRepo.findAllById(ids)
  170. // .stream()
  171. // .map(User::getPhone)
  172. // .collect(Collectors.joining(","));
  173. // njwlSmsService.sendSms(expertPhone,"评分已被退回!");
  174. // break;
  175. default:
  176. break;
  177. }
  178. }
  179. public Rate saveReviewTime(Long id, LocalDateTime time, Long userId) {
  180. Rate rate = rateRepo.findById(id).orElseThrow(new BusinessException("无记录"));
  181. rate.setReviewTime(time);
  182. rate.getReviewTimes().add(ReviewTime.builder()
  183. .reviewTime(time)
  184. .operatingTime(LocalDateTime.now())
  185. .build());
  186. DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DateConfig.DEFAULT_DATE_TIME_FORMAT);
  187. RateAudit rateAudit = RateAudit.builder()
  188. .userId(userId)
  189. .rateId(id)
  190. .remark("专家组长设置线下审查时间为:" + formatter.format(time))
  191. .status(RateStatus.REVIEW_PENDING)
  192. .build();
  193. rateAuditRepo.save(rateAudit);
  194. rate.setSort(RateStatus.REVIEW_PENDING.getSort());
  195. rate = rateRepo.save(rate);
  196. // 发送短信 确定审查时间
  197. if (ObjectUtil.isNull(rate.getReviewTime())) {
  198. throw new BusinessException("未设置具体审查时间");
  199. }
  200. Map<String, String> body = this.reviewTimeMessage(rate);
  201. njwlSmsService.sendSms(body.get("phone"), body.get("message"));
  202. njwlSmsService.sendSms(body.get("phone1"), body.get("message1"));
  203. return rate;
  204. }
  205. /*
  206. 提交纸质材料
  207. */
  208. public void paperMaterial(Long id, RateStatus status, String remark, Long userId) {
  209. Rate rate = rateRepo.findById(id).orElseThrow(new BusinessException("无记录"));
  210. rate.setStatus(status);
  211. rate.setSort(status.getSort());
  212. rateRepo.save(rate);
  213. RateAudit rateAudit = RateAudit.builder()
  214. .userId(userId)
  215. .rateId(id)
  216. .remark(remark)
  217. .status(status)
  218. .build();
  219. rateAuditRepo.save(rateAudit);
  220. if (RateStatus.COMPLETE.equals(status)) {
  221. njwlSmsService.sendSms(rate.getOwnerPhone(), "等级评定结果公告已发布,请在南京市文化和旅游局官方网站(http://wlj.nanjing.gov.cn/)上查询。");
  222. }
  223. }
  224. public String export(Rate rate) {
  225. Map<String, Object> dataMap = new HashMap<>();
  226. try {
  227. //单位
  228. dataMap.put("name", rate.getName());
  229. //日期
  230. dataMap.put("date", DateTimeFormatter.ofPattern(DateConfig.DEFAULT_DATE_FORMAT)
  231. .format(rate.getCreatedAt()));
  232. //负责人
  233. dataMap.put("owner", rate.getOwner());
  234. //电话
  235. dataMap.put("phone", rate.getOwnerPhone());
  236. //邮箱
  237. dataMap.put("email", rate.getOwnerEmail());
  238. //承办过
  239. dataMap.put("undertake", rate.isUndertakeExamination() ? "是" : "否");
  240. //考级机构名称
  241. Set<Long> ids = collaborateRepo.findAllByRateId(rate.getId())
  242. .stream()
  243. .map(Collaborate::getGradingOrganizationId)
  244. .collect(Collectors.toSet());
  245. if (CollUtil.isNotEmpty(ids)) {
  246. String str = gradingOrganizationRepo.findAllById(ids)
  247. .stream()
  248. .map(GradingOrganization::getName)
  249. .collect(Collectors.joining(","));
  250. dataMap.put("examination", str);
  251. }
  252. //单位概况
  253. dataMap.put("introduction", rate.getIntroduction());
  254. //Configuration 用于读取ftl文件
  255. Configuration configuration = new Configuration(new Version("2.3.0"));
  256. configuration.setDefaultEncoding("utf-8");
  257. configuration.setClassForTemplateLoading(this.getClass(), "/templates");//指定ftl所在目录,根据自己的改
  258. StringWriter writer = new StringWriter();
  259. Template template = configuration.getTemplate("RateTemplate.ftl", "utf-8");//以utf-8的编码读取ftl文件
  260. template.process(dataMap, writer);
  261. return writer.toString();
  262. } catch (Exception e) {
  263. log.error("生成word错误", e);
  264. throw new BusinessException(e.getMessage());
  265. }
  266. }
  267. public void imgToPdf(List<InputStream> files, Rate rate) {
  268. List<String> imageUrllist = new ArrayList<>();
  269. this.addList(imageUrllist, rate.getIntroductionAnnex());
  270. this.addList(imageUrllist, rate.getPrivacyPolicy());
  271. this.addList(imageUrllist, rate.getBusiness());
  272. this.addList(imageUrllist, rate.getCredits());
  273. this.addList(imageUrllist, rate.getFire());
  274. this.addList(imageUrllist, rate.getHygiene());
  275. this.addList(imageUrllist, rate.getFinance());
  276. this.addList(imageUrllist, rate.getProperty());
  277. String filename = "img.pdf";
  278. Document doc = new Document(PageSize.A4, 20, 20, 20, 20);
  279. try {
  280. FileOutputStream os = new FileOutputStream(filename);
  281. PdfWriter.getInstance(doc, os);
  282. doc.open();
  283. for (String img : imageUrllist) {
  284. doc.newPage();
  285. Image png1 = Image.getInstance(img);
  286. // float heigth = png1.getHeight();
  287. float width = png1.getWidth();
  288. int percent = this.getPercent(width);
  289. png1.setAlignment(Image.MIDDLE);
  290. png1.scalePercent(percent + 3);// 表示是原来图像的比例;
  291. doc.add(png1);
  292. }
  293. // b = os.toByteArray();
  294. File file = new File(filename);
  295. InputStream is = new FileInputStream(file);
  296. files.add(is);
  297. } catch (IOException | DocumentException e) {
  298. e.printStackTrace();
  299. } finally {
  300. doc.close();
  301. }
  302. }
  303. public void addList(List<String> list, List<String> imgs) {
  304. imgs.forEach(img -> {
  305. if ("png".equalsIgnoreCase(this.getSuffix(img)) || "jpg".equalsIgnoreCase(this.getSuffix(img))
  306. || "jpeg".equalsIgnoreCase(this.getSuffix(img))) {
  307. list.add(img);
  308. }
  309. });
  310. }
  311. /**
  312. * 等比压缩,获取压缩百分比
  313. *
  314. * @param weight 图片的宽度
  315. * @return 压缩百分比
  316. */
  317. public int getPercent(float weight) {
  318. // float percent;
  319. // if (height > weight) {
  320. // percent = PageSize.A4.getHeight() / height * 100;
  321. // } else {
  322. // percent = PageSize.A4.getWidth() / weight * 100;
  323. // }
  324. // return Math.round(percent);
  325. int p;
  326. float p2;
  327. p2 = 530 / weight * 100;
  328. p = Math.round(p2);
  329. return p;
  330. }
  331. public List<InputStream> upLoad1(Rate rate) throws UnsupportedEncodingException {
  332. List<InputStream> files = new ArrayList<>();
  333. String uri = "http://convert.izouma.com/word2pdf";
  334. // 表格
  335. String export = this.export(rate);
  336. InputStream is = new ByteArrayInputStream(export.getBytes());
  337. InputStream stream = HttpRequest.post(uri)
  338. .accept("*/*")
  339. .part("file", "审核材料.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", is)
  340. .stream();
  341. files.add(stream);
  342. this.downloadFile1(files, rate.getIntroductionAnnex());
  343. this.downloadFile1(files, rate.getPrivacyPolicy());
  344. this.downloadFile1(files, rate.getBusiness());
  345. this.downloadFile1(files, rate.getCredits());
  346. this.downloadFile1(files, rate.getFire());
  347. this.downloadFile1(files, rate.getHygiene());
  348. this.downloadFile1(files, rate.getFinance());
  349. this.downloadFile1(files, rate.getProperty());
  350. this.imgToPdf(files, rate);
  351. return files;
  352. }
  353. public void downloadFile1(List<InputStream> files, List<String> urls) {
  354. AtomicInteger num = new AtomicInteger(1);
  355. urls.forEach(privacy -> {
  356. num.getAndIncrement();
  357. if (getSuffix(privacy).equals("doc") || getSuffix(privacy).equals("docx")) {
  358. InputStream is1 = HttpRequest.get(privacy)
  359. .stream();
  360. InputStream stream = HttpRequest.post("http://convert.izouma.com/word2pdf")
  361. .accept("*/*")
  362. .part("file", "审核材料.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", is1)
  363. .stream();
  364. files.add(stream);
  365. } else if (getSuffix(privacy).equals("pdf")) {
  366. InputStream stream = HttpRequest.get(privacy).stream();
  367. files.add(stream);
  368. }
  369. });
  370. }
  371. public List<File> upLoad(Rate rate) {
  372. List<File> files = new ArrayList<>();
  373. String uri = "http://convert.izouma.com/word2pdf";
  374. // 表格
  375. String export = this.export(rate);
  376. InputStream is = new ByteArrayInputStream(export.getBytes());
  377. File file = new File("/Users/qiufangchao/Desktop/" + "申请表" + ".pdf");
  378. HttpRequest.post(uri)
  379. .accept("*/*")
  380. .part("file", "审核材料.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", is)
  381. .receive(file);
  382. files.add(file);
  383. this.downloadFile(files, rate.getPrivacyPolicy(), "法人资格");
  384. // this.downloadFile(files, rate.getBusiness(), "业务内容");
  385. // this.downloadFile(files, rate.getCredits(), "社会信誉");
  386. // this.downloadFile(files, rate.getFire(), "消防安全");
  387. // this.downloadFile(files, rate.getHygiene(), "卫生防疫");
  388. // this.downloadFile(files, rate.getFinance(), "财务报表");
  389. // this.downloadFile(files, rate.getProperty(), "房产证明");
  390. return files;
  391. }
  392. public void downloadFile(List<File> files, List<String> urls, String filename) {
  393. AtomicInteger num = new AtomicInteger(1);
  394. urls.forEach(privacy -> {
  395. num.getAndIncrement();
  396. File file1 = new File("/Users/qiufangchao/Desktop/" + filename + num + ".pdf");
  397. if (getSuffix(privacy).equals("doc") || getSuffix(privacy).equals("docx")) {
  398. InputStream is1 = HttpRequest.get(privacy).stream();
  399. HttpRequest.post("http://convert.izouma.com/word2pdf")
  400. .accept("*/*")
  401. .part("file", "审核材料.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", is1)
  402. .receive(file1);
  403. files.add(file1);
  404. } else if (getSuffix(privacy).equals("pdf")) {
  405. HttpRequest.get(privacy).receive(file1);
  406. files.add(file1);
  407. }
  408. });
  409. }
  410. public String getSuffix(String url) {
  411. int index = url.lastIndexOf(".");
  412. if (index < 0) {
  413. return "";
  414. }
  415. return url.substring(index + 1);
  416. }
  417. public void exportPdf(Long id, HttpServletResponse response) throws IOException {
  418. Rate rate = rateRepo.findById(id).orElseThrow(new BusinessException("无记录"));
  419. List<InputStream> files = this.upLoad1(rate);
  420. // pdf合并工具类
  421. PDFMergerUtility mergePdf = new PDFMergerUtility();
  422. mergePdf.addSources(files);
  423. // 指定目标文件输出流
  424. ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  425. mergePdf.setDestinationStream(outputStream);
  426. mergePdf.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
  427. // 设置合并生成pdf文件名称
  428. // String targetPath = "/Users/qiufangchao/Desktop/result.pdf";
  429. // mergePdf.setDestinationFileName(targetPath);
  430. for (InputStream is : files) {
  431. is.close();
  432. }
  433. // return outputStream.toString();
  434. response.setContentType("application/pdf");
  435. response.setHeader("Content-Disposition", "attachment; filename=" + "result.pdf");
  436. ServletOutputStream sos = response.getOutputStream();
  437. sos.write(outputStream.toByteArray());
  438. sos.flush();
  439. outputStream.close();
  440. }
  441. public Map<String, String> reviewTimesMessage(Rate rate) {
  442. List<Long> ids = new ArrayList<>(rate.getExpertMemberUserId());
  443. ids.add(rate.getExpertUserId());
  444. Map<Long, User> userMap = userRepo.findAllById(ids)
  445. .stream()
  446. .collect(Collectors.toMap(User::getId, user -> user));
  447. String message = "现场检查计划已分配:\n" +
  448. "审核单位:%s\n" +
  449. "单位地址:%s\n" +
  450. "单位负责人:%s\n" +
  451. "电话:%s\n" +
  452. "检查日期:%s\n" +
  453. "组长:%s-%s\n" +
  454. "组员:%s\n" +
  455. "宁艺通入口地址:http://wlj.izouma.com/h5/login\n" +
  456. "请在指定日期内完成现场检查任务,谢谢!";
  457. String message1 = "现场检查计划已分配:\n" +
  458. "审核单位:%s\n" +
  459. "单位地址:%s\n" +
  460. "检查日期:%s\n" +
  461. "组长:%s-%s";
  462. DateTimeFormatter dtf = DateTimeFormatter.ofPattern(DateConfig.DEFAULT_DATE_TIME_FORMAT);
  463. User user = userMap.get(rate.getExpertUserId());
  464. StringBuilder sb = new StringBuilder();
  465. rate.getExpertMemberUserId().forEach(userId -> {
  466. User user1 = userMap.get(userId);
  467. sb.append(user1.getNickname()).append("-").append(user1.getPhone()).append("、");
  468. System.out.println(sb);
  469. });
  470. String str = "";
  471. if (StrUtil.isNotEmpty(sb)) {
  472. str = sb.substring(0, sb.length() - 1);
  473. }
  474. String date = dtf.format(rate.getReviewStartTime()) + " 至 " + dtf.format(rate.getReviewEndTime());
  475. String body = String.format(message, rate.getName(), rate.getDetailAddress(), rate.getOwner(), rate.getOwnerPhone(), date, user
  476. .getNickname(), user.getPhone(), str);
  477. String body1 = String.format(message1, rate.getName(), rate.getDetailAddress(), date, user
  478. .getNickname(), user.getPhone());
  479. String phone = rate.getExpertMemberUserId()
  480. .stream()
  481. .map(userId -> userMap.get(userId).getPhone())
  482. .collect(Collectors.joining(","));
  483. Map<String, String> map = new HashMap<>();
  484. map.put("message", body);
  485. map.put("phone", user.getPhone());
  486. map.put("message1", body1);
  487. map.put("phone1", phone);
  488. return map;
  489. }
  490. public Map<String, String> reviewTimeMessage(Rate rate) {
  491. // Rate rate = rateRepo.findById(id).orElseThrow(new BusinessException("无记录"));
  492. List<Long> ids = new ArrayList<>(rate.getExpertMemberUserId());
  493. ids.add(rate.getExpertUserId());
  494. Map<Long, User> userMap = userRepo.findAllById(ids)
  495. .stream()
  496. .collect(Collectors.toMap(User::getId, user -> user));
  497. String message = "现场检查时间已确定:\n" +
  498. "审核单位:%s\n" +
  499. "单位地址:%s\n" +
  500. "检查时间:%s\n" +
  501. "单位负责人:%s\n" +
  502. "电话:%s\n" +
  503. "请在确定的时间内完成现场检查任务,谢谢!";
  504. String message1 = "现场检查时间已确定:\n" +
  505. "组长:%s-%s\n" +
  506. "检查时间:%s\n" +
  507. "请主动与检查组联系,配合做好承办单位等级评定工作!";
  508. DateTimeFormatter dtf = DateTimeFormatter.ofPattern(DateConfig.DEFAULT_DATE_TIME_FORMAT);
  509. String body = String.format(message, rate.getName(), rate.getDetailAddress(), dtf.format(rate.getReviewTime()), rate
  510. .getOwner(), rate.getOwnerPhone());
  511. User user = userMap.get(rate.getExpertUserId());
  512. String body1 = String.format(message1, user.getNickname(), user.getPhone(), dtf.format(rate.getReviewTime()));
  513. String phone = rate.getExpertMemberUserId()
  514. .stream()
  515. .map(userId -> userMap.get(userId).getPhone())
  516. .collect(Collectors.joining(","));
  517. phone += "," + user.getPhone();
  518. Map<String, String> map = new HashMap<>();
  519. map.put("message", body);
  520. map.put("phone", phone);
  521. map.put("message1", body1);
  522. map.put("phone1", rate.getOwnerPhone());
  523. return map;
  524. }
  525. public Map<String, String> gradeMessage(LocalDateTime time, Long expertId, String name) {
  526. DateTimeFormatter dtf = DateTimeFormatter.ofPattern(DateConfig.DEFAULT_DATE_TIME_FORMAT);
  527. String phone = userRepo.findAllByAuthoritiesContainsAndDelFalse(Authority.get(AuthorityName.ROLE_ADMIN))
  528. .stream()
  529. .map(User::getPhone)
  530. .collect(Collectors.joining(","));
  531. User expert = userRepo.findById(expertId).orElseThrow(new BusinessException("无专家"));
  532. String body = "现场检查已完成:\n" +
  533. "单位名称:%s\n" +
  534. "完成时间:%s \n" +
  535. "组长 : %s-%s\n";
  536. String message = String.format(body, name, dtf.format(time), expert.getNickname(), expert.getPhone());
  537. Map<String, String> map = new HashMap<>();
  538. map.put("message", message);
  539. map.put("phone", phone);
  540. return map;
  541. }
  542. public Map<String, String> applyMessage(String district, LocalDateTime time) {
  543. DateTimeFormatter dtf = DateTimeFormatter.ofPattern(DateConfig.DEFAULT_DATE_TIME_FORMAT);
  544. String phone = userRepo.findAllByDistrictAndAuthoritiesContainsAndDelFalse(district, Authority.get(AuthorityName.ROLE_DISTRICT_STAFF))
  545. .stream()
  546. .map(User::getPhone)
  547. .collect(Collectors.joining(","));
  548. String message = "您于" + dtf.format(time) + ",收到新的承办单位等级评定申请,请在15天内办结。";
  549. Map<String, String> map = new HashMap<>();
  550. map.put("message", message);
  551. map.put("phone", phone);
  552. return map;
  553. }
  554. }