|
@@ -1,14 +1,32 @@
|
|
package com.ruoyi.project.plant.controller;
|
|
package com.ruoyi.project.plant.controller;
|
|
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.io.InputStream;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.deepoove.poi.XWPFTemplate;
|
|
|
|
+import com.deepoove.poi.config.Configure;
|
|
|
|
+import com.deepoove.poi.data.Pictures;
|
|
|
|
+import com.deepoove.poi.data.Texts;
|
|
|
|
+import com.deepoove.poi.plugin.table.LoopColumnTableRenderPolicy;
|
|
|
|
+import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
|
|
|
|
+import com.deepoove.poi.policy.RenderPolicy;
|
|
import com.ruoyi.common.sendEmail.IMailService;
|
|
import com.ruoyi.common.sendEmail.IMailService;
|
|
|
|
+import com.ruoyi.common.utils.DateUtils;
|
|
|
|
+import com.ruoyi.common.utils.file.FileUploadUtils;
|
|
import com.ruoyi.framework.config.RuoYiConfig;
|
|
import com.ruoyi.framework.config.RuoYiConfig;
|
|
import com.ruoyi.project.plant.domain.TMtdItem;
|
|
import com.ruoyi.project.plant.domain.TMtdItem;
|
|
import com.ruoyi.project.plant.mapper.TMtdItemMapper;
|
|
import com.ruoyi.project.plant.mapper.TMtdItemMapper;
|
|
|
|
+import com.ruoyi.project.sems.safecheck.domain.TSpecWeekcheck;
|
|
|
|
+import com.ruoyi.project.system.domain.SysUser;
|
|
|
|
+import com.ruoyi.project.system.mapper.SysUserMapper;
|
|
|
|
+import io.jsonwebtoken.lang.Assert;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
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;
|
|
@@ -49,6 +67,9 @@ public class TMtdDailyController extends BaseController
|
|
//系统基础配置
|
|
//系统基础配置
|
|
@Autowired
|
|
@Autowired
|
|
private RuoYiConfig ruoyiConfig;
|
|
private RuoYiConfig ruoyiConfig;
|
|
|
|
+ @Resource
|
|
|
|
+ private SysUserMapper sysUserMapper;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 查询调度会议列表
|
|
* 查询调度会议列表
|
|
*/
|
|
*/
|
|
@@ -90,6 +111,7 @@ public class TMtdDailyController extends BaseController
|
|
item.setDailyId(id);
|
|
item.setDailyId(id);
|
|
item.setItemType(0);
|
|
item.setItemType(0);
|
|
List<TMtdItem> item0 = tMtdItemMapper.selectTMtdItemList(item);
|
|
List<TMtdItem> item0 = tMtdItemMapper.selectTMtdItemList(item);
|
|
|
|
+
|
|
tMtdDaily.setItems0(item0);
|
|
tMtdDaily.setItems0(item0);
|
|
|
|
|
|
item.setItemType(1);
|
|
item.setItemType(1);
|
|
@@ -133,9 +155,10 @@ public class TMtdDailyController extends BaseController
|
|
@PreAuthorize("@ss.hasPermi('plant:dailyMeeting:edit')")
|
|
@PreAuthorize("@ss.hasPermi('plant:dailyMeeting:edit')")
|
|
@Log(title = "调度会议", businessType = BusinessType.UPDATE)
|
|
@Log(title = "调度会议", businessType = BusinessType.UPDATE)
|
|
@PutMapping
|
|
@PutMapping
|
|
- public AjaxResult edit(@RequestBody TMtdDaily tMtdDaily)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult edit(@RequestBody TMtdDaily tMtdDaily) throws IOException {
|
|
logger.info(JSON.toJSONString(tMtdDaily));
|
|
logger.info(JSON.toJSONString(tMtdDaily));
|
|
|
|
+ String url = PreView(tMtdDaily.getId());
|
|
|
|
+ tMtdDaily.setWordUrl(url);
|
|
return toAjax(tMtdDailyService.updateTMtdDaily(tMtdDaily));
|
|
return toAjax(tMtdDailyService.updateTMtdDaily(tMtdDaily));
|
|
}
|
|
}
|
|
|
|
|
|
@@ -151,7 +174,7 @@ public class TMtdDailyController extends BaseController
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 查询调度会议列表
|
|
|
|
|
|
+ * 发送调度会议邮件
|
|
*/
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('plant:dailyMeeting:edit')")
|
|
@PreAuthorize("@ss.hasPermi('plant:dailyMeeting:edit')")
|
|
@Log(title = "发送调度会议邮件", businessType = BusinessType.OTHER)
|
|
@Log(title = "发送调度会议邮件", businessType = BusinessType.OTHER)
|
|
@@ -176,10 +199,10 @@ public class TMtdDailyController extends BaseController
|
|
String prime = "";
|
|
String prime = "";
|
|
String firstcenter = "<tr><td><div style=\"padding:25px 35px 40px; background-color:#fff;\"><h2 style=\"margin: 5px 0px; \">" +
|
|
String firstcenter = "<tr><td><div style=\"padding:25px 35px 40px; background-color:#fff;\"><h2 style=\"margin: 5px 0px; \">" +
|
|
"<font color=\"#333333\" style=\"line-height: 20px; \"><font style=\"line-height: 22px; \" size=\"4\">" +
|
|
"<font color=\"#333333\" style=\"line-height: 20px; \"><font style=\"line-height: 22px; \" size=\"4\">" +
|
|
- "亲爱的 用户</font><br><font style=\"line-height: 22px; \" size=\"4\">" +
|
|
|
|
|
|
+ "亲爱的 CPMS用户</font><br><font style=\"line-height: 22px; \" size=\"4\">" +
|
|
"<p>您有一条新的调度会议:<br>" +
|
|
"<p>您有一条新的调度会议:<br>" +
|
|
"会议日期:<b>meetingDate</b><br>" +
|
|
"会议日期:<b>meetingDate</b><br>" +
|
|
- "请前往<a href=\"requestJumpPath/plant/meeting/detail/dailyId\">会议详情</a>查看。<br>" +
|
|
|
|
|
|
+ "请前往<a href=\"requestJumpPath/plant/meeting/detail/dailyId\">会议详情</a>查看或下载邮件附件。<br>" +
|
|
"<p align=\"right\">date</p>" +
|
|
"<p align=\"right\">date</p>" +
|
|
"<div style=\"width:700px;margin:0 auto;\">" +
|
|
"<div style=\"width:700px;margin:0 auto;\">" +
|
|
"<div style=\"padding:10px 10px 0;border-top:1px solid #ccc;color:#747474;margin-bottom:20px;line-height:1.3em;font-size:12px;\">" +
|
|
"<div style=\"padding:10px 10px 0;border-top:1px solid #ccc;color:#747474;margin-bottom:20px;line-height:1.3em;font-size:12px;\">" +
|
|
@@ -199,7 +222,171 @@ public class TMtdDailyController extends BaseController
|
|
prime = prime + result;
|
|
prime = prime + result;
|
|
//拼接html
|
|
//拼接html
|
|
String html = start + prime + end;
|
|
String html = start + prime + end;
|
|
- mailService.sendHtmlMail(email, "CPMS:您有一条"+ formattedDate+"装置调度会议信息", html, emailCc);
|
|
|
|
|
|
+
|
|
|
|
+ // 需要转换的文件路径
|
|
|
|
+ String filePath = RuoYiConfig.getProfile()+daily.getWordUrl().replace("/profile","");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ mailService.sendAttachmentsMail(email, "CPMS:您有一条"+ formattedDate+"装置调度会议信息", html, emailCc,filePath);
|
|
return AjaxResult.success();
|
|
return AjaxResult.success();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @param id 生成文件名
|
|
|
|
+ * @return
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ public String PreView(Long id) throws IOException {
|
|
|
|
+ //根据ID查询并生成
|
|
|
|
+ TMtdDaily tMtdDaily = tMtdDailyService.selectTMtdDailyById(id);
|
|
|
|
+ //获取item列表
|
|
|
|
+ TMtdItem item = new TMtdItem();
|
|
|
|
+ item.setDailyId(id);
|
|
|
|
+ item.setItemType(0);
|
|
|
|
+ List<TMtdItem> item0 = tMtdItemMapper.selectTMtdItemList(item);
|
|
|
|
+ tMtdDaily.setItems0(item0);
|
|
|
|
+
|
|
|
|
+ item.setItemType(1);
|
|
|
|
+ List<TMtdItem> item1 = tMtdItemMapper.selectTMtdItemList(item);
|
|
|
|
+ tMtdDaily.setItems1(getItemAndName(item1 , "1",tMtdDaily));
|
|
|
|
+
|
|
|
|
+ item.setItemType(2);
|
|
|
|
+ List<TMtdItem> item2 = tMtdItemMapper.selectTMtdItemList(item);
|
|
|
|
+ tMtdDaily.setItems2(getItemAndName(item2 , "2",tMtdDaily));
|
|
|
|
+
|
|
|
|
+ item.setItemType(3);
|
|
|
|
+ List<TMtdItem> item3 = tMtdItemMapper.selectTMtdItemList(item);
|
|
|
|
+ tMtdDaily.setItems3(getItemAndName(item3 , "3",tMtdDaily));
|
|
|
|
+
|
|
|
|
+ item.setItemType(4);
|
|
|
|
+ List<TMtdItem> item4 = tMtdItemMapper.selectTMtdItemList(item);
|
|
|
|
+ tMtdDaily.setItems4(getItemAndName(item4 , "4",tMtdDaily));
|
|
|
|
+
|
|
|
|
+ item.setItemType(5);
|
|
|
|
+ List<TMtdItem> item5 = tMtdItemMapper.selectTMtdItemList(item);
|
|
|
|
+ tMtdDaily.setItems5(getItemAndName(item5 , "5",tMtdDaily));
|
|
|
|
+ String url = this.createcheck(tMtdDaily);
|
|
|
|
+ return url;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<TMtdItem> getItemAndName(List<TMtdItem> items, String itemNum, TMtdDaily tMtdDaily){
|
|
|
|
+ int num = 1;
|
|
|
|
+ for (TMtdItem t: items
|
|
|
|
+ ) {
|
|
|
|
+ t.setItem(itemNum + "." + num);
|
|
|
|
+ SysUser sysUser = sysUserMapper.selectUserByStaffId(t.getActionby());
|
|
|
|
+ t.setActionName(sysUser.getNickName());
|
|
|
|
+ t.setBeginTime(DateUtils.parseDateToStr("MM-dd",tMtdDaily.getMeetingDate()));
|
|
|
|
+ num++;
|
|
|
|
+ }
|
|
|
|
+ return items;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 生成wordt
|
|
|
|
+ */
|
|
|
|
+ public String createcheck(TMtdDaily tMtdDaily) throws IOException {
|
|
|
|
+ //生成word
|
|
|
|
+ //渲染文本
|
|
|
|
+ Map<String, Object> params = getWordData(tMtdDaily);
|
|
|
|
+ // 模板路径
|
|
|
|
+ String templatePath = "static/word/plant/dailymeeting.docx";
|
|
|
|
+ // 生成word的路径
|
|
|
|
+ String fileDir = RuoYiConfig.getProfile() + "/" + "plant/dailymeeting";
|
|
|
|
+ // 生成word的文件名称
|
|
|
|
+ String fileName = DateUtils.parseDateToStr("YYYY-MM-dd",tMtdDaily.getMeetingDate())+"装置调度会议"+tMtdDaily.getId() + ".docx";
|
|
|
|
+ String wordPath = this.createWord(templatePath, fileDir, fileName, params);
|
|
|
|
+ return wordPath;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取word数据
|
|
|
|
+ */
|
|
|
|
+ public Map<String, Object> getWordData(TMtdDaily tMtdDaily) {
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
+ params.put("meetingDate", DateUtils.parseDateToStr("YYYY-MM-dd",tMtdDaily.getMeetingDate()));
|
|
|
|
+ params.put("reDate", DateUtils.parseDateToStr("MM-dd",tMtdDaily.getMeetingDate()));
|
|
|
|
+ params.put("venue", tMtdDaily.getVenue());
|
|
|
|
+
|
|
|
|
+ params.put("optMode", tMtdDaily.getOptMode());
|
|
|
|
+ params.put("optItem", tMtdDaily.getOptItem());
|
|
|
|
+ params.put("split", tMtdDaily.getSplit());
|
|
|
|
+ params.put("pgu", tMtdDaily.getPgu());
|
|
|
|
+ params.put("aeu", tMtdDaily.getAeu());
|
|
|
|
+
|
|
|
|
+ SysUser recorder = sysUserMapper.selectUserByStaffId(tMtdDaily.getRecorder());
|
|
|
|
+ params.put("recorder", recorder.getNickName());
|
|
|
|
+
|
|
|
|
+ params.put("cracker",tMtdDaily.getAttendCracker());
|
|
|
|
+ params.put("ctm",tMtdDaily.getAttendCtm());
|
|
|
|
+ params.put("cta",tMtdDaily.getAttendCta());
|
|
|
|
+ params.put("lab",tMtdDaily.getAttendLab());
|
|
|
|
+
|
|
|
|
+ params.put("item1",tMtdDaily.getItems1());
|
|
|
|
+ params.put("item2",tMtdDaily.getItems2());
|
|
|
|
+ params.put("item3",tMtdDaily.getItems3());
|
|
|
|
+ params.put("item4",tMtdDaily.getItems4());
|
|
|
|
+ params.put("item5",tMtdDaily.getItems5());
|
|
|
|
+ // 渲染文本
|
|
|
|
+ return params;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String getUserName(String str){
|
|
|
|
+ String names = "";
|
|
|
|
+ if (str == null) return "";
|
|
|
|
+ String[] arr = str.split(",");
|
|
|
|
+ for (int i = 0; i < arr.length; i++) {
|
|
|
|
+ SysUser user = sysUserMapper.selectUserByStaffId(arr[i]);
|
|
|
|
+ names = names + user.getNickName() + ",";
|
|
|
|
+ }
|
|
|
|
+ return names;
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @param templatePath word模板文件路径
|
|
|
|
+ * @param fileDir 生成的文件存放地址
|
|
|
|
+ * @param fileName 生成的文件名
|
|
|
|
+ * @param paramMap 参数集合
|
|
|
|
+ * @return 返回word生成的路径
|
|
|
|
+ */
|
|
|
|
+ public String createWord(String templatePath, String fileDir, String fileName, Map<String, Object> paramMap) throws IOException {
|
|
|
|
+ Assert.notNull(templatePath, "word模板文件路径不能为空");
|
|
|
|
+ Assert.notNull(fileDir, "生成的文件存放地址不能为空");
|
|
|
|
+ Assert.notNull(fileName, "生成的文件名不能为空");
|
|
|
|
+ File dir = new File(fileDir);
|
|
|
|
+ if (!dir.exists()) {
|
|
|
|
+ logger.info("目录不存在,创建文件夹{}!", fileDir);
|
|
|
|
+ dir.mkdirs();
|
|
|
|
+ }
|
|
|
|
+ fileName = fileName.replaceAll("/", "_"); //替换文件中敏感字段
|
|
|
|
+ logger.info("目录文件{}!", fileName);
|
|
|
|
+ String filePath = fileDir + "/" + fileName;
|
|
|
|
+ logger.info("目录{}!", filePath);
|
|
|
|
+ // 读取模板渲染参数
|
|
|
|
+ InputStream is = getClass().getClassLoader().getResourceAsStream(templatePath);
|
|
|
|
+
|
|
|
|
+ LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
|
|
|
|
+ RenderPolicy hackLoopSameLineTableRenderPolicy = new LoopColumnTableRenderPolicy(true);
|
|
|
|
+
|
|
|
|
+ Configure config = Configure.builder()
|
|
|
|
+ .bind("item1", policy)
|
|
|
|
+ .bind("item2", policy)
|
|
|
|
+ .bind("item3", policy)
|
|
|
|
+ .bind("item4", policy)
|
|
|
|
+ .bind("item5", policy)
|
|
|
|
+ .build();
|
|
|
|
+
|
|
|
|
+ XWPFTemplate template = XWPFTemplate.compile(is,config).render(paramMap);
|
|
|
|
+ try {
|
|
|
|
+ // 将模板参数写入路径
|
|
|
|
+ template.writeToFile(filePath);
|
|
|
|
+ template.close();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ logger.error("生成word异常{}", e.getMessage());
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ String pathFileName = FileUploadUtils.getPathFileName(RuoYiConfig.getFilePath("/" + "plant/dailymeeting"), fileName);
|
|
|
|
+ return pathFileName;
|
|
|
|
+ }
|
|
}
|
|
}
|