Commit 3126b3d2 authored by KeYong's avatar KeYong

更新代码

parent ec22bd72
......@@ -21,6 +21,8 @@ import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import java.io.File;
import java.util.*;
......@@ -160,7 +162,7 @@ public class JgTransferNoticeController extends BaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "特种设备登记证导出", notes = "特种设备登记证导出")
@GetMapping(value = "/certificate/report")
public ResponseModel<File> generateCertificateReport() {
public void generateCertificateReport(HttpServletResponse response) {
Map<String, Object> map = new HashMap<>();
// 组装模板变量
map.put("useRegistrationCode", "20231225123"); // 编号
......@@ -179,6 +181,6 @@ public class JgTransferNoticeController extends BaseController {
// 生成二维码
String qrCode = ImageUtils.generateQRCode("YZGZ20231225001", 70, 65);
map.put("supervisoryCode", qrCode); // 监管二维码
return ResponseHelper.buildResponse(commonService.generateCertificateReport(map));
commonService.generateCertificateReport(map, response);
}
}
......@@ -2,8 +2,9 @@ package com.yeejoin.amos.boot.module.jg.biz.service;
import com.yeejoin.amos.boot.module.ymt.api.entity.EquipmentCategory;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.io.File;
import javax.servlet.http.HttpServletResponse;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
......@@ -34,5 +35,5 @@ public interface ICommonService {
List<Map<String,Object>> getEnterpriseEmployee(String unitCode);
File generateCertificateReport(Map<String, Object> map);
void generateCertificateReport(Map<String, Object> map, HttpServletResponse response);
}
package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aspose.words.SaveFormat;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yeejoin.amos.boot.biz.common.bo.CompanyBo;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.boot.biz.common.service.impl.DataDictionaryServiceImpl;
import com.yeejoin.amos.boot.biz.common.utils.RedisKey;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.module.jg.api.dto.ByteArrayMultipartFile;
import com.yeejoin.amos.boot.module.jg.api.mapper.CommonMapper;
import com.yeejoin.amos.boot.module.jg.biz.service.ICommonService;
import com.yeejoin.amos.boot.module.jg.biz.utils.FileExporter;
import com.yeejoin.amos.boot.module.jg.biz.utils.ImageUtils;
import com.yeejoin.amos.boot.module.jg.biz.utils.WordTemplateUtils;
import com.yeejoin.amos.boot.module.jg.flc.api.fegin.PrivilegeFeginService;
import com.yeejoin.amos.boot.module.ymt.api.entity.EquipmentCategory;
import com.yeejoin.amos.boot.module.ymt.api.mapper.EquipmentCategoryMapper;
import com.yeejoin.amos.boot.module.ymt.api.mapper.IdxBizJgFactoryInfoMapper;
import com.yeejoin.amos.component.feign.model.FeignClientResult;
import com.yeejoin.amos.component.feign.utils.FeignUtil;
import com.yeejoin.amos.feign.privilege.Privilege;
import com.yeejoin.amos.feign.privilege.model.CompanyModel;
import com.yeejoin.amos.feign.systemctl.Systemctl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -32,11 +27,13 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.multipart.MultipartFile;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.io.InputStream;
import java.util.*;
import java.util.stream.Collectors;
......@@ -286,7 +283,7 @@ public class CommonServiceImpl implements ICommonService {
}
@Override
public File generateCertificateReport(Map<String, Object> map) {
public void generateCertificateReport(Map<String, Object> map, HttpServletResponse response) {
if (CollectionUtils.isEmpty(map)) {
throw new IllegalArgumentException("参数不能为空");
}
......@@ -325,7 +322,13 @@ public class CommonServiceImpl implements ICommonService {
// } catch (IOException e) {
// log.error("删除临时文件失败:{}", e);
// }
return pdfFile;
try {
byte[] bytes = file2byte(pdfFile);
String docTitle = pdfFile.getName();
FileExporter.exportFile(FileExporter.FileType.valueOf("pdf"), docTitle, bytes, response);
} catch (Exception e) {
log.error("pdf文件转换失败:{}", e);
}
}
/**
......
package com.yeejoin.amos.boot.module.jg.biz.utils;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
public class FileExporter {
public static void exportFile(FileType fileType, String fileName, byte[] data, HttpServletResponse response) {
try {
response.reset();
response.setCharacterEncoding("utf-8");
response.setContentType(fileType.getContentType());
fileName = fileName.replaceAll("\\.", "·");
fileName = URLEncoder.encode(fileName + fileType.getFileSufix(), "UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName + "");
response.getOutputStream().write(data);
response.getOutputStream().flush();
} catch (Exception e) {
throw new BadRequest("导出文档出错");
} finally {
try {
response.getOutputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 文件类型
*/
public enum FileType {
// word文档
docx(".docx", "application/msword"),
// pdf文档
pdf(".pdf", "application/pdf");
private String fileSufix;
private String contentType;
private FileType(String fileSufix, String contentType) {
this.fileSufix = fileSufix;
this.contentType = contentType;
}
public String getFileSufix() {
return fileSufix;
}
public String getContentType() {
return contentType;
}
public static FileType getInstance(String fileSufix) {
FileType knowledgeRoleName = null;
for (FileType fileType : FileType.values()) {
if (fileType.getFileSufix().equals(fileSufix)) {
knowledgeRoleName = fileType;
}
}
return knowledgeRoleName;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment