|
@ -1,7 +1,12 @@ |
|
|
package com.epmet.controller; |
|
|
package com.epmet.controller; |
|
|
|
|
|
|
|
|
|
|
|
import cn.afterturn.easypoi.word.WordExportUtil; |
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
import com.epmet.commons.tools.aop.NoRepeatSubmit; |
|
|
import com.epmet.commons.tools.aop.NoRepeatSubmit; |
|
|
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
|
|
import com.epmet.commons.tools.utils.DateUtils; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.commons.tools.validator.AssertUtils; |
|
|
import com.epmet.commons.tools.validator.AssertUtils; |
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
@ -9,10 +14,16 @@ import com.epmet.commons.tools.validator.group.AddGroup; |
|
|
import com.epmet.commons.tools.validator.group.DefaultGroup; |
|
|
import com.epmet.commons.tools.validator.group.DefaultGroup; |
|
|
import com.epmet.commons.tools.validator.group.UpdateGroup; |
|
|
import com.epmet.commons.tools.validator.group.UpdateGroup; |
|
|
import com.epmet.dto.MemoConcernDTO; |
|
|
import com.epmet.dto.MemoConcernDTO; |
|
|
|
|
|
import com.epmet.dto.MemoWorkDiaryDTO; |
|
|
import com.epmet.service.MemoConcernService; |
|
|
import com.epmet.service.MemoConcernService; |
|
|
|
|
|
import org.apache.poi.xwpf.usermodel.XWPFDocument; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
import org.springframework.http.HttpHeaders; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletOutputStream; |
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
import java.net.URL; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -67,6 +78,56 @@ public class MemoConcernController { |
|
|
return new Result(); |
|
|
return new Result(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/{id}/exportWord") |
|
|
|
|
|
public void exportWord(@PathVariable("id") String id, HttpServletResponse response) throws Exception { |
|
|
|
|
|
URL resource = this.getClass().getClassLoader().getResource("templates/memo_concern_export_template.docx"); |
|
|
|
|
|
|
|
|
|
|
|
MemoConcernDTO data = memoConcernService.get(id); |
|
|
|
|
|
|
|
|
|
|
|
if (data == null) { |
|
|
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "未找到id为" + id + "的关怀项目", "未找到该关怀项目"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> map = BeanUtil.beanToMap(data); |
|
|
|
|
|
|
|
|
|
|
|
// 创建时间
|
|
|
|
|
|
if (data.getCreatedTime() != null) { |
|
|
|
|
|
String createTimeStr = DateUtils.format(data.getCreatedTime(), "yyyy年MM月dd日 HH:mm"); |
|
|
|
|
|
map.put("createTime", createTimeStr); |
|
|
|
|
|
} else { |
|
|
|
|
|
map.put("createTime", ""); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 预计关怀时间
|
|
|
|
|
|
if (data.getScheduledTime() != null) { |
|
|
|
|
|
String scheduledTimeStr = DateUtils.format(data.getScheduledTime(), "yyyy年MM月dd日 HH:mm"); |
|
|
|
|
|
map.put("scheduledTime", scheduledTimeStr); |
|
|
|
|
|
} else { |
|
|
|
|
|
map.put("scheduledTime", ""); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//状态
|
|
|
|
|
|
map.put("statusName", "0".equals(data.getStatus()) ? "未完成" : "已完成"); |
|
|
|
|
|
|
|
|
|
|
|
XWPFDocument doc = WordExportUtil.exportWord07(resource.getFile(), map); |
|
|
|
|
|
|
|
|
|
|
|
String filePath = resource.getFile(); |
|
|
|
|
|
String suffix = filePath.substring(filePath.lastIndexOf(".")); |
|
|
|
|
|
|
|
|
|
|
|
response.setHeader(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, "Content-Disposition"); |
|
|
|
|
|
response.setHeader(HttpHeaders.CONTENT_TYPE, "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); |
|
|
|
|
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;fileName=人员关怀导入模板" + suffix); |
|
|
|
|
|
|
|
|
|
|
|
ServletOutputStream fos = null; |
|
|
|
|
|
try { |
|
|
|
|
|
fos = response.getOutputStream(); |
|
|
|
|
|
doc.write(fos); |
|
|
|
|
|
} finally { |
|
|
|
|
|
if (fos != null) { |
|
|
|
|
|
fos.close(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|