Commit 03ccbc6e authored by suhuiguang's avatar suhuiguang

fix(jyjc): 报检规则4.0开发

1.报检申请表生成url功能初始版本提交
parent 25ae6d2f
......@@ -27,6 +27,12 @@
<artifactId>spring-kafka</artifactId>
</dependency>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>19.5jdk</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-spring</artifactId>
</dependency>
......
package com.yeejoin.amos.boot.module.jyjc.biz.file.inspectapp.factory;
import com.yeejoin.amos.boot.module.jyjc.biz.file.inspectapp.factory.support.DocGenerator;
import com.yeejoin.amos.boot.module.jyjc.biz.file.inspectapp.factory.support.SupportableDocGenerator;
import com.yeejoin.amos.boot.module.jyjc.biz.file.inspectapp.wrapper.DocGeneratorWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@Service
@RequiredArgsConstructor
public class DocGeneratorFactory {
private final Map<String, DocGenerator> docGenerators = new ConcurrentHashMap<>();
private final List<SupportableDocGenerator> factories;
public DocGenerator getGenerator(String equList, String equCategory, String equDefine) {
return docGenerators.computeIfAbsent(equList, k ->
new DocGeneratorWrapper(
factories.stream()
.filter(s -> s.support(equList, equCategory, equDefine))
.findFirst()
.orElseThrow(() -> new UnsupportedOperationException(String.format("No generator found for type: %s (list=%s, define=%s)",
equCategory, equList, equDefine))))
);
}
}
package com.yeejoin.amos.boot.module.jyjc.biz.file.inspectapp.factory.support;
public interface DocGenerator {
String generate(String appId);
}
package com.yeejoin.amos.boot.module.jyjc.biz.file.inspectapp.factory.support;
public interface SupportableDocGenerator extends DocGenerator {
boolean support(String equList, String equCategory, String equDefine);
}
package com.yeejoin.amos.boot.module.jyjc.biz.file.inspectapp.strategy;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yeejoin.amos.boot.module.common.api.enums.EquipmentClassifityEnum;
import com.yeejoin.amos.boot.module.jyjc.api.entity.JyjcInspectionApplication;
import com.yeejoin.amos.boot.module.jyjc.api.entity.JyjcInspectionApplicationEquip;
import com.yeejoin.amos.boot.module.jyjc.biz.file.inspectapp.factory.support.SupportableDocGenerator;
import com.yeejoin.amos.boot.module.jyjc.biz.file.inspectapp.strategy.common.InspectAppDocCmService;
import com.yeejoin.amos.boot.module.jyjc.biz.service.impl.JyjcInspectionApplicationEquipServiceImpl;
import com.yeejoin.amos.boot.module.jyjc.biz.service.impl.JyjcInspectionApplicationServiceImpl;
import com.yeejoin.amos.boot.module.jyjc.biz.util.WordTemplateUtils;
import com.yeejoin.amos.boot.module.ymt.api.mapper.IdxBizJgUseInfoMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.typroject.tyboot.core.rdbms.orm.entity.BaseEntity;
import java.io.File;
import java.nio.file.Files;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
@Slf4j
public class GenericDocGeneratorStrategy implements SupportableDocGenerator {
private final JyjcInspectionApplicationServiceImpl jyjcInspectionApplicationService;
private final JyjcInspectionApplicationEquipServiceImpl jyjcInspectionApplicationEquipService;
private final InspectAppDocCmService appDocCmService;
private final IdxBizJgUseInfoMapper idxBizJgUseInfoMapper;
@Override
public boolean support(String equList, String equCategory, String equDefine) {
return !EquipmentClassifityEnum.YLGD.getCode().equals(equList);
}
@Override
public String generate(String appId) {
Map<String, Object> params = appDocCmService.getBaseInFo(appId);
JyjcInspectionApplication inspectionApplication = jyjcInspectionApplicationService.getBaseMapper().selectById(appId);
params.put("numberOfEquip", inspectionApplication.getNumberOfEquip());
params.put("equips", this.buildEquipsBatch(inspectionApplication.getSequenceNbr()));
return this.generatePdfAndUpload(params);
}
private String generatePdfAndUpload(Map<String, Object> formData) {
String wordPath = "inspect-app-generic.ftl";
String fileName = "检验检测报检申请受理单";
File pdfFile = null;
try {
// 填充模板, word转pdf
pdfFile = WordTemplateUtils.wordToPdf(fileName, wordPath, formData);
// 上传文档到文件服务器
return WordTemplateUtils.uploadFile(pdfFile, "upload/tzs/pdf/inspectApp");
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
try {
if (pdfFile != null) {
Files.deleteIfExists(pdfFile.toPath());
}
} catch (Exception e) {
log.error("文件找不到,删除失败:{}", e.getMessage());
}
}
}
private List<Map<String, Object>> buildEquipsBatch(Long sequenceNbr) {
List<JyjcInspectionApplicationEquip> equips = jyjcInspectionApplicationEquipService.list(new LambdaQueryWrapper<JyjcInspectionApplicationEquip>()
.eq(JyjcInspectionApplicationEquip::getApplicationSeq, sequenceNbr)
.select(BaseEntity::getSequenceNbr, JyjcInspectionApplicationEquip::getEquipUnicode));
List<String> records = equips.stream().map(JyjcInspectionApplicationEquip::getEquipUnicode).collect(Collectors.toList());
return idxBizJgUseInfoMapper.queryBaseInfoByIds(records);
}
}
package com.yeejoin.amos.boot.module.jyjc.biz.file.inspectapp.strategy;
import com.yeejoin.amos.boot.module.common.api.enums.EquipmentClassifityEnum;
import com.yeejoin.amos.boot.module.jyjc.api.entity.JyjcInspectionApplication;
import com.yeejoin.amos.boot.module.jyjc.api.entity.JyjcInspectionHistory;
import com.yeejoin.amos.boot.module.jyjc.biz.file.inspectapp.factory.support.SupportableDocGenerator;
import com.yeejoin.amos.boot.module.jyjc.biz.file.inspectapp.strategy.common.InspectAppDocCmService;
import com.yeejoin.amos.boot.module.jyjc.biz.service.impl.JyjcInspectionApplicationServiceImpl;
import com.yeejoin.amos.boot.module.jyjc.biz.service.impl.JyjcInspectionHistoryServiceImpl;
import com.yeejoin.amos.boot.module.jyjc.biz.util.WordTemplateUtils;
import com.yeejoin.amos.boot.module.ymt.api.enums.FlowStatusEnum;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.io.File;
import java.nio.file.Files;
import java.util.List;
import java.util.Map;
@Service
@Slf4j
@RequiredArgsConstructor
public class PipelineDocGeneratorStrategy implements SupportableDocGenerator {
private final JyjcInspectionApplicationServiceImpl jyjcInspectionApplicationService;
private final InspectAppDocCmService appDocCmService;
private final JyjcInspectionHistoryServiceImpl inspectionHistoryService;
@Override
public boolean support(String equList, String equCategory, String equDefine) {
return EquipmentClassifityEnum.YLGD.getCode().equals(equList);
}
@Override
public String generate(String appId) {
Map<String, Object> params = appDocCmService.getBaseInFo(appId);
JyjcInspectionApplication inspectionApplication = jyjcInspectionApplicationService.getBaseMapper().selectById(appId);
this.setPipelineInfo(params, inspectionApplication);
return this.generatePdfAndUpload(params);
}
private void setPipelineInfo(Map<String, Object> params, JyjcInspectionApplication inspectionApplication) {
if (inspectionApplication.getStatus().equals(String.valueOf(FlowStatusEnum.TO_BE_FINISHED.getCode()))) {
JyjcInspectionHistory inspectionHistory = inspectionHistoryService.getBySSeq(inspectionApplication.getSequenceNbr());
if (inspectionHistory != null) {
// 新报检单记录历史数据的逻辑
params.put("pipelines", inspectionHistory.getHistoryData().get("equip"));
params.put("numberOfEquip", inspectionHistory.getHistoryData().get("pipelineLength"));
} else {
List<Map<String, Object>> pipelines = jyjcInspectionApplicationService.getPipelines(inspectionApplication);
params.put("pipelines", pipelines);
params.put("numberOfEquip", JyjcInspectionApplicationServiceImpl.calTotalLength(pipelines));
}
} else {
List<Map<String, Object>> pipelines = jyjcInspectionApplicationService.getPipelines(inspectionApplication);
params.put("pipelines", pipelines);
params.put("numberOfEquip", JyjcInspectionApplicationServiceImpl.calTotalLength(pipelines));
}
}
private String generatePdfAndUpload(Map<String, Object> formData) {
String wordPath = "inspect-app-pipeline.ftl";
String fileName = "检验检测报检申请受理单";
File pdfFile = null;
try {
// 填充模板, word转pdf
pdfFile = WordTemplateUtils.wordToPdf(fileName, wordPath, formData);
// 上传文档到文件服务器
return WordTemplateUtils.uploadFile(pdfFile, "upload/tzs/pdf/inspectApp");
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
try {
if (pdfFile != null) {
Files.deleteIfExists(pdfFile.toPath());
}
} catch (Exception e) {
log.error("文件找不到,删除失败:{}", e.getMessage());
}
}
}
}
package com.yeejoin.amos.boot.module.jyjc.biz.file.inspectapp.strategy.common;
import cn.hutool.core.date.DateUtil;
import com.yeejoin.amos.boot.module.jyjc.api.entity.JyjcInspectionApplication;
import com.yeejoin.amos.boot.module.jyjc.biz.service.impl.JyjcInspectionApplicationServiceImpl;
import com.yeejoin.amos.boot.module.jyjc.biz.typeHandler.EquipCategoryTypeHandler;
import com.yeejoin.amos.boot.module.jyjc.biz.typeHandler.InspectTypeHandler;
import com.yeejoin.amos.boot.module.jyjc.biz.typeHandler.RegionCodeTypeHandler;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
@Service
@RequiredArgsConstructor
public class InspectAppDocCmService {
private final JyjcInspectionApplicationServiceImpl jyjcInspectionApplicationService;
private final EquipCategoryTypeHandler equipCategoryTypeHandler;
private final InspectTypeHandler inspectTypeHandler;
private final RegionCodeTypeHandler regionCodeTypeHandler;
public Map<String, Object> getBaseInFo(String appId) {
Map<String, Object> baseInfo = new HashMap<>();
JyjcInspectionApplication inspectionApplication = jyjcInspectionApplicationService.getBaseMapper().selectById(appId);
baseInfo.put("inspectionType", inspectTypeHandler.handle(inspectionApplication.getInspectionType()));
baseInfo.put("applicationNo", inspectionApplication.getApplicationNo());
baseInfo.put("applicationDate", DateUtil.formatDate(inspectionApplication.getApplicationDate()));
baseInfo.put("applicationUnitName", inspectionApplication.getApplicationUnitName());
baseInfo.put("applicationContactName", inspectionApplication.getApplicationContactName());
baseInfo.put("applicationContactPhone", inspectionApplication.getApplicationContactPhone());
baseInfo.put("address", this.buildAddress(inspectionApplication));
baseInfo.put("equList", this.equCategoryCode2Name(inspectionApplication.getEquipClassify()));
baseInfo.put("equCategory", this.equCategoryCode2Name(inspectionApplication.getEquCategory()));
baseInfo.put("equDefine", this.equCategoryCode2Name(inspectionApplication.getEquDefine()));
baseInfo.put("remark", inspectionApplication.getRemark());
baseInfo.put("inspectionUnitName", inspectionApplication.getInspectionUnitName());
baseInfo.put("acceptDate", DateUtil.formatDate(inspectionApplication.getAcceptDate()));
baseInfo.put("processDescription", inspectionApplication.getProcessDescription());
return baseInfo;
}
private String equCategoryCode2Name(String equipClassify) {
return equipCategoryTypeHandler.handle(equipClassify);
}
private String buildAddress(JyjcInspectionApplication inspectionApplication) {
return "陕西省" + regionCodeTypeHandler.handle(inspectionApplication.getCity()) + regionCodeTypeHandler.handle(inspectionApplication.getCounty());
}
}
package com.yeejoin.amos.boot.module.jyjc.biz.file.inspectapp.wrapper;
import com.yeejoin.amos.boot.module.jyjc.biz.file.inspectapp.factory.support.DocGenerator;
import com.yeejoin.amos.boot.module.jyjc.biz.file.inspectapp.factory.support.SupportableDocGenerator;
public class DocGeneratorWrapper implements DocGenerator {
private final SupportableDocGenerator docGenerator;
public DocGeneratorWrapper(final SupportableDocGenerator docGenerator) {
this.docGenerator = docGenerator;
}
@Override
public String generate(String appId) {
return docGenerator.generate(appId);
}
}
......@@ -1781,6 +1781,12 @@ public class JyjcInspectionApplicationServiceImpl extends BaseService<JyjcInspec
return this.getBaseMapper().selectPieLineListOfInspect(records);
}
public List<Map<String, Object>> getPipelines(JyjcInspectionApplication application) {
List<JyjcInspectionApplicationEquipModel> applicationEquipModels = applicationEquipService.listApplicationEquipByApplicationSeq(application.getSequenceNbr());
List<String> records = applicationEquipModels.stream().map(JyjcInspectionApplicationEquipModel::getEquipUnicode).collect(Collectors.toList());
return this.getBaseMapper().selectPieLineListOfInspect(records);
}
@NotNull
private JSONObject setPieLineInfo(JyjcInspectionApplicationModel applicationModel, IdxBizJgProjectContraption projectContraption, JSONObject jsonObject, List<Map<String, Object>> equList) {
jsonObject.put("equip", equList);
......
package com.yeejoin.amos.boot.module.jyjc.biz.typeHandler;
import com.yeejoin.amos.boot.biz.common.entity.DataDictionary;
import com.yeejoin.amos.boot.biz.common.service.impl.DataDictionaryServiceImpl;
import com.yeejoin.amos.boot.biz.common.typeHandler.TypeHandler;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* 特种设备目录处理器
*/
@Component("equipCategoryTypeHandler")
@RequiredArgsConstructor
public class InspectTypeHandler implements TypeHandler<String> {
private final Map<String, String> CODE_NAME_MAP = new ConcurrentHashMap<>();
private final DataDictionaryServiceImpl dataDictionaryService;
@Override
public String handle(String code) {
return StringUtils.isNotEmpty(code) ? CODE_NAME_MAP.computeIfAbsent(code, (k) -> {
DataDictionary dictionary = dataDictionaryService.getByCode(k, "JYJC");
return dictionary != null ? dictionary.getName() : "";
}) : null;
}
}
package com.yeejoin.amos.boot.module.jyjc.biz.typeHandler;
import com.yeejoin.amos.boot.biz.common.typeHandler.TypeHandler;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Stream;
import static com.yeejoin.amos.boot.module.common.api.constant.TZSCommonConstant.*;
/**
* 行政区划处理器
*/
@Component("regionCodeTypeHandler")
@RequiredArgsConstructor
public class RegionCodeTypeHandler implements TypeHandler<String> {
private final RedisUtils redisUtils;
private final Map<String, String> CODE_NAME_MAP = new ConcurrentHashMap<>();
@Override
public String handle(String regionCode) {
return StringUtils.isNotBlank(regionCode) ? CODE_NAME_MAP.computeIfAbsent(regionCode, (k) -> {
List<LinkedHashMap> list1 = (List<LinkedHashMap>) redisUtils.get(PROVINCE);
List<LinkedHashMap> list2 = (List<LinkedHashMap>) redisUtils.get(CITY);
List<LinkedHashMap> list3 = (List<LinkedHashMap>) redisUtils.get(REGION);
List<LinkedHashMap> list4 = (List<LinkedHashMap>) redisUtils.get(STREET);
Optional<LinkedHashMap> op = Stream.of(list1, list2, list3, list4).flatMap(Collection::stream).filter(item -> String.valueOf(item.get("regionCode")).trim().equals(regionCode)).findFirst();
return op.map(linkedHashMap -> linkedHashMap.get("regionName").toString()).orElse("");
}) : "";
}
}
package com.yeejoin.amos.boot.module.jyjc.biz.util;
import com.aspose.words.Document;
import com.aspose.words.License;
import com.aspose.words.SaveFormat;
import com.yeejoin.amos.boot.module.jg.api.dto.ByteArrayMultipartFile;
import com.yeejoin.amos.component.feign.model.FeignClientResult;
import com.yeejoin.amos.feign.systemctl.Systemctl;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
@Slf4j
public class WordTemplateUtils {
public static final String BASE_PACKAGE_PATH = "/templates";
private static WordTemplateUtils wordTemplateUtils;
private final Configuration configuration;
private WordTemplateUtils() {
configuration = new Configuration(Configuration.VERSION_2_3_23);
}
public static synchronized WordTemplateUtils getInstance() {
if (wordTemplateUtils == null) {
wordTemplateUtils = new WordTemplateUtils();
}
return wordTemplateUtils;
}
/**
* 创建doc并写入内容
*
* @param templatePath doc模板文件路径
* @param dataMap 内容
* @param template 模板
* @return doc文件
*/
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);
if (templatePath.endsWith(".ftl")) {
templatePath = templatePath.replace(".ftl", ".doc");
}
File docFile = new File(templatePath);
try (
// 这个地方不能使用FileWriter因为需要指定编码类型否则生成的Word文档会因为有无法识别的编码而无法打开
Writer writer = new OutputStreamWriter(Files.newOutputStream(docFile.toPath()), StandardCharsets.UTF_8)
) {
template.process(escapeSpecialCharacters(dataMap), writer);
}
return docFile;
}
public File fillAndConvertDocFile(String templatePath, String targetFileName, Map<String, ?> map, int saveFormat) throws Exception {
// 指定模板所在包路径
configuration.setClassForTemplateLoading(this.getClass(), BASE_PACKAGE_PATH);
// 获取模板, 生成Word文档
Template freemarkerTemplate = configuration.getTemplate(templatePath, "UTF-8");
File docFile = createDoc(templatePath, map, freemarkerTemplate);
// 转换Word文档
File converedFile = converDocFile(docFile.getAbsolutePath(), targetFileName, saveFormat);
// 删除临时文件
Files.deleteIfExists(docFile.toPath());
return converedFile;
}
/**
* word转换
*
* @param docPath word文件路径
* @param targetPath 转换后文件路径
* @param saveFormat 目标文件类型 取自 com.aspose.words.SaveFormat
*/
private File converDocFile(String docPath, String targetPath, int saveFormat) throws Exception {
// 验证License 若不验证则转化出的pdf文档会有水印产生
if (!getLicense()) {
throw new RuntimeException("验证License失败");
}
if (StringUtils.isEmpty(docPath)) {
throw new FileNotFoundException("文档文件不存在");
}
try (
InputStream inputStream = Files.newInputStream(Paths.get(docPath));
OutputStream outputStream = Files.newOutputStream(Paths.get(targetPath));
) {
File targetFile = new File(targetPath);
Document doc = new Document(inputStream);
doc.save(outputStream, saveFormat);
return targetFile;
}
}
/**
* 获取License
*
* @return boolean
*/
private boolean getLicense() {
boolean result = false;
try {
String s = "<License><Data><Products><Product>Aspose.Total for Java</Product><Product>Aspose.Words for Java</Product></Products><EditionType>Enterprise</EditionType><SubscriptionExpiry>20991231</SubscriptionExpiry><LicenseExpiry>20991231</LicenseExpiry><SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber></Data><Signature>sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature></License>";
ByteArrayInputStream is = new ByteArrayInputStream(s.getBytes());
License license = new License();
license.setLicense(is);
result = true;
} catch (Exception e) {
log.error("获取License失败", e);
}
return result;
}
public static String templateToPdf(String pdfName, String wordPath, Map<String, Object> placeholders) {
// word转pdf
File pdfFile;
try {
pdfFile = wordToPdf(pdfName, wordPath, placeholders);
} catch (Exception e) {
throw new RuntimeException(e);
}
// 上传pdf至文件服务器
String url = uploadFile(pdfFile);
// 删除临时文件
try {
Files.deleteIfExists(pdfFile.toPath());
} catch (IOException e) {
log.error("删除临时文件失败:{}", e);
}
return url;
}
public static byte[] getTemplateToPdfData(String pdfName, String wordPath, Map<String, Object> placeholders) {
// word转pdf
File pdfFile;
try {
pdfFile = wordToPdf(pdfName, wordPath, placeholders);
} catch (Exception e) {
log.error("模板转pdf失败:", e);
throw new BadRequest("模板转pdf失败");
}
try {
return file2byte(pdfFile);
} finally {
try {
Files.deleteIfExists(pdfFile.toPath());
} catch (Exception e) {
log.error("文件找不到,删除失败:", e);
}
}
}
private static byte[] file2byte(File file) {
try {
FileInputStream in = new FileInputStream(file);
//当文件没有结束时,每次读取一个字节显示
byte[] data = new byte[in.available()];
in.read(data);
in.close();
return data;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* 上传文件至文件服务器
*
* @param file 文件
* @param path 路径
*/
public static String uploadFile(File file, String path) {
Assert.notNull(file, "文件不能为空");
MultipartFile multipartFile = new ByteArrayMultipartFile("file", "file.pdf", "application/pdf", file2byte(file));
// 返回路径 : upload/common/${path}/xxx.xx
FeignClientResult<Map<String, String>> result = Systemctl.fileStorageClient.updateCommonFileFree(multipartFile, path);
String urlString = "";
if (result != null) {
for (String s : result.getResult().keySet()) {
urlString = s;
}
}
return urlString;
}
/**
* 上传文件至文件服务器
*
* @param file 文件
*/
private static String uploadFile(File file) {
Assert.notNull(file, "文件不能为空");
MultipartFile multipartFile = new ByteArrayMultipartFile("file", "file.pdf", "application/pdf", file2byte(file));
FeignClientResult<Map<String, String>> result = Systemctl.fileStorageClient.updateCommonFile(multipartFile);
String urlString = "";
if (result != null) {
for (String s : result.getResult().keySet()) {
urlString = s;
}
}
return urlString;
}
/**
* word 转 pdf
*
* @param wordPath word文件路径
*/
public static File wordToPdf(String pdfName, String wordPath, Map<String, Object> placeholders) throws Exception {
Assert.hasText(wordPath, "word文件路径不能为空");
WordTemplateUtils instance = WordTemplateUtils.getInstance();
return instance.fillAndConvertDocFile(wordPath, pdfName, placeholders, SaveFormat.PDF);
}
/**
* 下载填充模板的字段,特殊符号转义
*/
public static Map<String, Object> escapeSpecialCharacters(Map<String, ?> inputMap) {
Map<String, Object> escapedMap = new HashMap<>();
for (Map.Entry<String, ?> entry : inputMap.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (value instanceof String) {
escapedMap.put(key, escapeValue((String) value));
} else if (value instanceof Map) {
escapedMap.put(key, escapeSpecialCharacters((Map<String, Object>) value));
} else if (value instanceof List) {
escapedMap.put(key, escapeList((List<?>) value));
} else {
escapedMap.put(key, value);
}
}
return escapedMap;
}
private static List<Object> escapeList(List<?> inputList) {
List<Object> escapedList = new ArrayList<>();
for (Object value : inputList) {
if (value instanceof String) {
escapedList.add(escapeValue((String) value));
} else if (value instanceof Map) {
escapedList.add(escapeSpecialCharacters((Map<String, Object>) value));
} else if (value instanceof List) {
escapedList.add(escapeList((List<?>) value));
} else {
escapedList.add(value);
}
}
return escapedList;
}
private static String escapeValue(String value) {
if (value == null) {
return null;
}
value = removeControlCharsManual(value);
return value.replace("&", "&amp;")
.replace("<", "&lt;")
.replace(">", "&gt;")
.replace("\"", "&quot;")
.replace("'", "&apos;")
.replace("(", "&#40;")
.replace(")", "&#41;");
}
public static String removeControlCharsManual(String input) {
if (input == null) return "";
StringBuilder sb = new StringBuilder();
for (int i = 0; i < input.length(); i++) {
char c = input.charAt(i);
// 只保留允许的字符
if (c > 31 || c == '\t' || c == '\n' || c == '\r') {
sb.append(c);
}
}
return sb.toString();
}
}
......@@ -45,4 +45,6 @@ public interface IdxBizJgUseInfoMapper extends CustomBaseMapper<IdxBizJgUseInfo>
Page<String> selectPiPeRecords(Page<String> page);
JSONObject getUsePlaceAndCodeByRecord(@Param("record") String record);
List<Map<String, Object>> queryBaseInfoByIds(@Param("records") List<String> records);
}
......@@ -190,5 +190,30 @@
AND "CLAIM_STATUS" NOT IN ('待认领','已拒领','草稿')
order by ibjui."RECORD" desc
</select>
<select id="queryBaseInfoByIds" resultType="java.util.Map">
SELECT
ibjui."RECORD" AS "record",
ibjsi."ORG_BRANCH_NAME" AS "orgBranchName",
ibjri."USE_ORG_CODE" AS "useOrgCode",
ibjui."USE_INNER_CODE" AS "useInnerCode",
ibjui."DATA_SOURCE" AS "dataSource",
ibjoi."CODE96333" AS "code96333",
ibjri."EQU_CODE" AS "equCode",
ibjoi."SUPERVISORY_CODE" AS "supervisoryCode",
CONCAT_WS('', ibjui."PROVINCE_NAME", ibjui."CITY_NAME", ibjui."COUNTY_NAME", ibjui."STREET_NAME", ibjui."ADDRESS") AS "address",
ibjfi."FACTORY_NUM" AS "factoryNum"
FROM
idx_biz_jg_use_info ibjui
LEFT JOIN amos_tzs_biz.idx_biz_jg_supervision_info ibjsi ON ibjui."RECORD" = ibjsi."RECORD"
LEFT JOIN amos_tzs_biz.idx_biz_jg_register_info ibjri ON ibjui."RECORD" = ibjri."RECORD"
LEFT JOIN amos_tzs_biz.idx_biz_jg_other_info ibjoi ON ibjui."RECORD" = ibjoi."RECORD"
LEFT JOIN amos_tzs_biz.idx_biz_jg_factory_info ibjfi ON ibjui."RECORD" = ibjfi."RECORD"
where ibjui.record = ANY(
ARRAY[
<foreach collection="records" item="record" index="index" separator=",">
#{record}
</foreach>
])
</select>
</mapper>
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