Commit d821beed authored by 刘林's avatar 刘林

fix(JG):使用登记证套打改为word功能

parent a2f3a42b
......@@ -9,6 +9,7 @@ public enum PrintingTypeEnum {
* 登记证(普打)
*/
REGULAR(2, "登记证(普打)"),
OVERPLAY(3, "登记证(套打)"),
/**
* 登记证(电子版)
*/
......
......@@ -45,6 +45,8 @@ public interface ICommonService {
void generateCertificateReport(Map<String, Object> map, HttpServletResponse response);
void generateCertificateReportDoc(Map<String, Object> map, HttpServletResponse response);
void generatePdfPrint(Map<String, Object> map, HttpServletResponse response);
byte[] generateSummaryOfCylinderInfo(Map<String, Object> map, String wordPath,String filePrefix);
......
......@@ -61,6 +61,7 @@ import com.yeejoin.amos.feign.systemctl.model.TaskV2Model;
import com.yeejoin.amos.feign.workflow.model.ActTaskDTO;
import com.yeejoin.amos.feign.workflow.model.FlowTaskVo;
import com.yeejoin.amos.feign.workflow.model.ProcessTaskDTO;
import freemarker.template.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.redisson.api.RBucket;
......@@ -83,8 +84,8 @@ import org.typroject.tyboot.core.foundation.utils.Bean;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.annotation.PostConstruct;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.lang.reflect.Field;
......@@ -229,6 +230,8 @@ public class CommonServiceImpl implements ICommonService {
private Map<String, String> companyCodeRegNameMap;
@Autowired
private TaskV2FeignService taskV2FeignService;
@Autowired
private Configuration configuration;
public static byte[] file2byte(File file) {
try {
......@@ -894,6 +897,53 @@ public class CommonServiceImpl implements ICommonService {
}
/**
* 使用登记证套打生成Word
* @param map 参数
* @param response 返回值
*/
public void generateCertificateReportDoc(Map<String, Object> map, HttpServletResponse response) {
if (CollectionUtils.isEmpty(map)) {
throw new IllegalArgumentException("参数不能为空");
}
// Populate template variables with default values if not present
String[] keys = {"useRegistrationCode", "useUnitName", "fullAddress", "equList", "equipDefine", "equipCode",
"equipCategory", "useInnerCode", "factoryNum", "receiveOrgName", "giveOutYear",
"giveOutMonth", "giveOutDay", "excelType", "tableName"};
String[] defaultValues = {"", "", "", "", "", "", "", "", "", "", "", "", "", "使用登记", "特种设备使用登记证"};
for (int i = 0; i < keys.length; i++) {
map.put(keys[i], Optional.ofNullable(map.get(keys[i])).orElse(defaultValues[i]).toString());
}
map.put("supervisoryCode", ImageUtils.generateQRCode(Optional.ofNullable(map.get("applyNo")).orElse("").toString(), 100, 100));
map.put("printingType", PrintingTypeEnum.REGULAR.getCode());
File file = null;
try (ServletOutputStream out = response.getOutputStream()) {
file = WordTemplateUtils.createDoc("/templates/use-registration-model.ftl", map, configuration.getTemplate("use-registration-model.ftl", "UTF-8"));
try (InputStream fin = Files.newInputStream(file.toPath())) {
response.setCharacterEncoding("utf-8");
response.setContentType("application/msword");
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("使用登记证.docx", "UTF-8"));
byte[] buffer = new byte[512];
int bytesRead;
while ((bytesRead = fin.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
}
}
} catch (Exception e) {
throw new RuntimeException("Error generating the certificate report", e);
} finally {
if (file != null && file.exists() && !file.delete()) {
file.deleteOnExit();
}
}
}
/**
* 返回附件
*
* @param map 参数
......
......@@ -1550,7 +1550,8 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
commonService.generateCertificateReport(exportParamsMap, response);
} else if ("1".equals(printType)) {
// 套打
commonService.generatePdfPrint(exportParamsMap, response);
//commonService.generatePdfPrint(exportParamsMap, response);
commonService.generateCertificateReportDoc(exportParamsMap, response);
} else if ("2".equals(printType)) {
// 使用标志普通打印
commonService.useFlagGenerate(this.buildUseFlagParamDto(useRegistration, registerInfo, factoryInfo, exportParamsMap), response);
......
......@@ -1106,7 +1106,8 @@ public class JgVehicleInformationServiceImpl extends BaseService<JgVehicleInform
break;
case "1":
// 使用登记证-套打--
this.generatePdfPrint(exportParamsMap, response);
//this.generatePdfPrint(exportParamsMap, response);
commonService.generateCertificateReportDoc(exportParamsMap, response);
break;
case "2":
// 使用标志-普通打印--
......
......@@ -50,7 +50,7 @@ public class WordTemplateUtils {
* @param template 模板
* @return doc文件
*/
private File createDoc(String templatePath, Map<String, ?> dataMap, Template template) throws TemplateException, IOException {
public static File createDoc(String templatePath, Map<String, ?> dataMap, Template template) throws TemplateException, IOException {
// templatePath在后缀之前加上UUID是为了防止并发时多个线程使用同一个模板文件而导致生成的Word文档内容不一致
int i = templatePath.lastIndexOf(".");
templatePath = UUID.randomUUID() + templatePath.substring(i);
......
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