package com.yuanchu.mom.service.impl;
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import com.deepoove.poi.XWPFTemplate;
|
import com.deepoove.poi.config.Configure;
|
import com.deepoove.poi.config.ConfigureBuilder;
|
import com.deepoove.poi.data.Pictures;
|
import com.yuanchu.mom.dto.PersonSupervisionProcessingSheetDto;
|
import com.yuanchu.mom.exception.ErrorException;
|
import com.yuanchu.mom.mapper.UserMapper;
|
import com.yuanchu.mom.pojo.PersonSupervisionProcessingSheet;
|
import com.yuanchu.mom.mapper.PersonSupervisionProcessingSheetMapper;
|
import com.yuanchu.mom.service.PersonSupervisionProcessingSheetService;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.InputStream;
|
import java.io.OutputStream;
|
import java.net.URLEncoder;
|
import java.time.format.DateTimeFormatter;
|
import java.util.HashMap;
|
|
/**
|
* <p>
|
* 监督记录 - 处理单 服务实现类
|
* </p>
|
*
|
* @author
|
* @since 2024-10-10 05:35:58
|
*/
|
@Service
|
public class PersonSupervisionProcessingSheetServiceImpl extends ServiceImpl<PersonSupervisionProcessingSheetMapper, PersonSupervisionProcessingSheet> implements PersonSupervisionProcessingSheetService {
|
|
@Resource
|
private UserMapper userMapper;
|
|
@Value("${file.path}")
|
private String imgUrl;
|
|
/**
|
* 导出人员监督记录纠正处理单
|
* @param supervisionRecordId
|
* @param response
|
*/
|
@Override
|
public void exportSupervisionProcessingSheet(Integer supervisionRecordId, HttpServletResponse response) {
|
PersonSupervisionProcessingSheetDto processingSheetDto = baseMapper.selectProcessingSheet(supervisionRecordId);
|
|
// 提出人签名
|
String raiseUrl = null;
|
if (processingSheetDto.getProposingDepartmentPersonId() != null) {
|
raiseUrl = userMapper.selectById(processingSheetDto.getProposingDepartmentPersonId()).getSignatureUrl();
|
if (StringUtils.isBlank(raiseUrl)) {
|
throw new ErrorException("找不到提出人的签名");
|
}
|
}
|
|
// 原因分析人
|
String causeUrl = null;
|
if (processingSheetDto.getCauseAnalysisPersonId() != null) {
|
causeUrl = userMapper.selectById(processingSheetDto.getCauseAnalysisPersonId()).getSignatureUrl();
|
if (StringUtils.isBlank(causeUrl)) {
|
throw new ErrorException("找不到原因分析人的签名");
|
}
|
}
|
|
// 纠正人
|
String correctUrl = null;
|
if (processingSheetDto.getCorrectiveActionId() != null) {
|
correctUrl = userMapper.selectById(processingSheetDto.getCorrectiveActionId()).getSignatureUrl();
|
if (StringUtils.isBlank(correctUrl)) {
|
throw new ErrorException("找不到纠正人的签名");
|
}
|
}
|
|
// 验证人
|
String validationUrl = null;
|
if (processingSheetDto.getVerificationDepartmentPersonId() != null) {
|
validationUrl = userMapper.selectById(processingSheetDto.getVerificationDepartmentPersonId()).getSignatureUrl();
|
if (StringUtils.isBlank(validationUrl)) {
|
throw new ErrorException("找不到验证人的签名");
|
}
|
}
|
|
// 获取路径
|
InputStream inputStream = this.getClass().getResourceAsStream("/static/supervision-processing-sheet.docx");
|
ConfigureBuilder builder = Configure.builder();
|
builder.useSpringEL(true);
|
String finalRaiseUrl = raiseUrl;
|
String finalCauseUrl = causeUrl;
|
String finalCorrectUrl = correctUrl;
|
String finalValidationUrl = validationUrl;
|
XWPFTemplate template = XWPFTemplate.compile(inputStream, builder.build()).render(
|
new HashMap<String, Object>() {{
|
put("processing", processingSheetDto);
|
put("raiseUrl", StringUtils.isNotBlank(finalRaiseUrl) ? Pictures.ofLocal(imgUrl + "/" + finalRaiseUrl).create() : null);
|
put("causeUrl", StringUtils.isNotBlank(finalCauseUrl) ? Pictures.ofLocal(imgUrl + "/" + finalCauseUrl).create() : null);
|
put("correctUrl", StringUtils.isNotBlank(finalCorrectUrl) ? Pictures.ofLocal(imgUrl + "/" + finalCorrectUrl).create() : null);
|
put("validationUrl", StringUtils.isNotBlank(finalValidationUrl) ? Pictures.ofLocal(imgUrl + "/" + finalValidationUrl).create() : null);
|
}});
|
|
try {
|
response.setContentType("application/msword");
|
String fileName = URLEncoder.encode(
|
"人员监督记录纠正处理单", "UTF-8");
|
response.setHeader("Content-disposition",
|
"attachment;filename=" + fileName + ".docx");
|
OutputStream os = response.getOutputStream();
|
template.write(os);
|
os.flush();
|
os.close();
|
} catch (Exception e) {
|
e.printStackTrace();
|
throw new RuntimeException("导出失败");
|
}
|
}
|
}
|