|
|
@ -1,7 +1,15 @@ |
|
|
|
package com.epmet.controller; |
|
|
|
|
|
|
|
import cn.afterturn.easypoi.word.WordExportUtil; |
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import com.epmet.commons.tools.annotation.LoginUser; |
|
|
|
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.exception.ExceptionUtils; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
|
import com.epmet.commons.tools.utils.DateUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.commons.tools.validator.AssertUtils; |
|
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
|
@ -9,10 +17,25 @@ import com.epmet.commons.tools.validator.group.AddGroup; |
|
|
|
import com.epmet.commons.tools.validator.group.DefaultGroup; |
|
|
|
import com.epmet.commons.tools.validator.group.UpdateGroup; |
|
|
|
import com.epmet.dto.MemoConcernDTO; |
|
|
|
import com.epmet.dto.form.MemoConcernFormDTO; |
|
|
|
import com.epmet.service.MemoConcernService; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.io.IOUtils; |
|
|
|
import org.apache.poi.xwpf.usermodel.XWPFDocument; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.http.HttpHeaders; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
import javax.servlet.ServletOutputStream; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.OutputStream; |
|
|
|
import java.net.URL; |
|
|
|
import java.nio.file.Files; |
|
|
|
import java.nio.file.Path; |
|
|
|
import java.nio.file.Paths; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
@ -22,6 +45,7 @@ import java.util.Map; |
|
|
|
* @author generator generator@elink-cn.com |
|
|
|
* @since v1.0.0 2022-03-15 |
|
|
|
*/ |
|
|
|
@Slf4j |
|
|
|
@RestController |
|
|
|
@RequestMapping("memoConcern") |
|
|
|
public class MemoConcernController { |
|
|
@ -30,31 +54,36 @@ public class MemoConcernController { |
|
|
|
private MemoConcernService memoConcernService; |
|
|
|
|
|
|
|
@RequestMapping("page") |
|
|
|
public Result<PageData<MemoConcernDTO>> page(@RequestParam Map<String, Object> params){ |
|
|
|
PageData<MemoConcernDTO> page = memoConcernService.page(params); |
|
|
|
public Result<PageData<MemoConcernDTO>> page(@LoginUser TokenDto tokenDto, @RequestBody MemoConcernFormDTO formDTO){ |
|
|
|
formDTO.setUserId(tokenDto.getUserId()); |
|
|
|
PageData<MemoConcernDTO> page = memoConcernService.page(formDTO); |
|
|
|
return new Result<PageData<MemoConcernDTO>>().ok(page); |
|
|
|
} |
|
|
|
|
|
|
|
@RequestMapping(value = "{id}",method = {RequestMethod.POST,RequestMethod.GET}) |
|
|
|
public Result<MemoConcernDTO> get(@PathVariable("id") String id){ |
|
|
|
MemoConcernDTO data = memoConcernService.get(id); |
|
|
|
@RequestMapping(method = {RequestMethod.POST,RequestMethod.GET}) |
|
|
|
public Result<MemoConcernDTO> get(@RequestBody MemoConcernFormDTO formDTO){ |
|
|
|
MemoConcernDTO data = memoConcernService.get(formDTO); |
|
|
|
return new Result<MemoConcernDTO>().ok(data); |
|
|
|
} |
|
|
|
|
|
|
|
@NoRepeatSubmit |
|
|
|
@PostMapping("save") |
|
|
|
public Result save(@RequestBody MemoConcernDTO dto){ |
|
|
|
public Result save(@LoginUser TokenDto tokenDto, @RequestBody MemoConcernDTO dto){ |
|
|
|
//效验数据
|
|
|
|
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); |
|
|
|
|
|
|
|
dto.setCustomerId(tokenDto.getCustomerId()); |
|
|
|
dto.setCreatedBy(tokenDto.getUserId()); |
|
|
|
memoConcernService.save(dto); |
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
|
|
|
|
@NoRepeatSubmit |
|
|
|
@PostMapping("update") |
|
|
|
public Result update(@RequestBody MemoConcernDTO dto){ |
|
|
|
public Result update(@LoginUser TokenDto tokenDto, @RequestBody MemoConcernDTO dto){ |
|
|
|
//效验数据
|
|
|
|
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); |
|
|
|
dto.setCustomerId(tokenDto.getCustomerId()); |
|
|
|
memoConcernService.update(dto); |
|
|
|
return new Result(); |
|
|
|
} |
|
|
@ -67,6 +96,102 @@ public class MemoConcernController { |
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping("/{id}/exportWord") |
|
|
|
public void exportWord(@PathVariable("id") String id, HttpServletResponse response) throws Exception { |
|
|
|
String templateFilePath = loadTemplate("memo_concern_export_template.docx"); |
|
|
|
MemoConcernFormDTO formDTO = new MemoConcernFormDTO(); |
|
|
|
formDTO.setId(id); |
|
|
|
MemoConcernDTO data = memoConcernService.get(formDTO); |
|
|
|
|
|
|
|
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(templateFilePath, map); |
|
|
|
|
|
|
|
String suffix = templateFilePath.substring(templateFilePath.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(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 加载模板 |
|
|
|
* @param templateFileName |
|
|
|
* @return |
|
|
|
* @throws IOException |
|
|
|
*/ |
|
|
|
private String loadTemplate(String templateFileName) throws IOException { |
|
|
|
String homeDir = System.getProperty("user.home"); |
|
|
|
Path templates = Paths.get(homeDir, "epmet_files", "templates"); |
|
|
|
if (Files.notExists(templates)) { |
|
|
|
Files.createDirectories(templates); |
|
|
|
} |
|
|
|
|
|
|
|
Path templateFilePath = templates.resolve(templateFileName); |
|
|
|
String templateFilePathStr = templateFilePath.toString(); |
|
|
|
if (Files.exists(templateFilePath)) { |
|
|
|
return templateFilePathStr; |
|
|
|
} |
|
|
|
|
|
|
|
// 将项目中的模板拷贝至用户家目录中
|
|
|
|
OutputStream os = null; |
|
|
|
InputStream is = null; |
|
|
|
try { |
|
|
|
is = this.getClass().getClassLoader().getResourceAsStream("templates/" + templateFileName); |
|
|
|
os = new FileOutputStream(templateFilePathStr); |
|
|
|
IOUtils.copy(is, os); |
|
|
|
} finally { |
|
|
|
try { |
|
|
|
if (is != null) { |
|
|
|
is.close(); |
|
|
|
} |
|
|
|
} catch (IOException e) { |
|
|
|
String errorMsg = ExceptionUtils.getThrowableErrorStackTrace(e); |
|
|
|
log.error("【导出工作日志doc】关闭输入流出错:{}", errorMsg); |
|
|
|
} |
|
|
|
try { |
|
|
|
if (os != null) { |
|
|
|
os.close(); |
|
|
|
} |
|
|
|
} catch (IOException e) { |
|
|
|
String errorMsg = ExceptionUtils.getThrowableErrorStackTrace(e); |
|
|
|
log.error("【导出工作日志doc】关闭输出流出错:{}", errorMsg); |
|
|
|
} |
|
|
|
} |
|
|
|
return templateFilePathStr; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|