test
This commit is contained in:
@@ -7,6 +7,8 @@ import com.bstek.ureport.Utils;
|
||||
import com.bstek.ureport.export.ExportConfigure;
|
||||
import com.bstek.ureport.export.ExportConfigureImpl;
|
||||
import com.bstek.ureport.export.ExportManager;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.point.strategy.archiveNoSet.bean.ArchiveNoFormat;
|
||||
@@ -80,9 +82,35 @@ public class FourCheckService {
|
||||
|
||||
@Autowired
|
||||
MetadataStandardMapper metadataStandardMapper;
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(FourCheckService.class);
|
||||
|
||||
/**
|
||||
* 对超长字符串进行软换行,避免在PDF中单行过宽/过高造成分页异常。
|
||||
* 简单实现:按固定列宽断行,同时保留已有的换行符。
|
||||
*/
|
||||
private static List<String> softWrap(String text, int maxCols) {
|
||||
List<String> lines = new ArrayList<>();
|
||||
if (text == null) {
|
||||
return lines;
|
||||
}
|
||||
String[] rawLines = text.replace("\r\n", "\n").replace('\r', '\n').split("\n", -1);
|
||||
for (String raw : rawLines) {
|
||||
if (raw.length() <= maxCols) {
|
||||
lines.add(raw);
|
||||
} else {
|
||||
int start = 0;
|
||||
while (start < raw.length()) {
|
||||
int end = Math.min(start + maxCols, raw.length());
|
||||
lines.add(raw.substring(start, end));
|
||||
start = end;
|
||||
}
|
||||
}
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public AjaxJson<Object> addEntity(FourCheck entity) {
|
||||
AjaxJson<Object> result = null;
|
||||
@@ -210,11 +238,55 @@ public class FourCheckService {
|
||||
String pass = "通过";
|
||||
if ("0".equals((new StringBuilder()).append(map1.get("pass")).append("").toString()))
|
||||
pass = "不通过";
|
||||
map1.put("pass", pass);
|
||||
map1.put("checkLink", checkLink);
|
||||
map1.put("dataFormat", dataFormat);
|
||||
map1.put("filePath", fourCheck.getFilePath());
|
||||
returnList.add(map1);
|
||||
|
||||
Object msgObj = map1.get("msg");
|
||||
// 将可能很长的列表消息拆分为多行/多条记录,避免单行过高导致 iText 无限循环异常
|
||||
List<String> msgLines = new ArrayList<>();
|
||||
if (msgObj instanceof List) {
|
||||
for (Object o : (List<?>) msgObj) {
|
||||
// 对每条内容进行软换行展开
|
||||
msgLines.addAll(softWrap(String.valueOf(o), 60));
|
||||
}
|
||||
} else if (msgObj instanceof com.alibaba.fastjson.JSONArray) {
|
||||
com.alibaba.fastjson.JSONArray arr = (com.alibaba.fastjson.JSONArray) msgObj;
|
||||
for (Object o : arr) {
|
||||
msgLines.addAll(softWrap(String.valueOf(o), 60));
|
||||
}
|
||||
} else if (msgObj != null) {
|
||||
msgLines.addAll(softWrap(String.valueOf(msgObj), 60));
|
||||
}
|
||||
|
||||
// 分块,每块最多 N 行,避免某一行高度超过页面
|
||||
final int CHUNK = 15;
|
||||
if (msgLines.isEmpty()) {
|
||||
Map<String, Object> row = new HashMap<>();
|
||||
row.putAll(map1);
|
||||
row.put("type", typeChn);
|
||||
row.put("pass", pass);
|
||||
row.put("checkLink", checkLink);
|
||||
row.put("dataFormat", dataFormat);
|
||||
row.put("filePath", fourCheck.getFilePath());
|
||||
row.put("createdDate", dateFormat.format(fourCheck.getCreatedDate()));
|
||||
row.put("userChnName", fourCheck.getCreatedBy());
|
||||
row.put("msg", "");
|
||||
returnList.add(row);
|
||||
} else {
|
||||
for (int i = 0; i < msgLines.size(); i += CHUNK) {
|
||||
int end = Math.min(i + CHUNK, msgLines.size());
|
||||
String chunkText = String.join("\n", msgLines.subList(i, end));
|
||||
Map<String, Object> row = new HashMap<>();
|
||||
row.putAll(map1);
|
||||
row.put("type", typeChn);
|
||||
row.put("pass", pass);
|
||||
row.put("checkLink", checkLink);
|
||||
row.put("dataFormat", dataFormat);
|
||||
row.put("filePath", fourCheck.getFilePath());
|
||||
row.put("createdDate", dateFormat.format(fourCheck.getCreatedDate()));
|
||||
row.put("userChnName", fourCheck.getCreatedBy());
|
||||
row.put("msg", chunkText);
|
||||
returnList.add(row);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Collections.sort(returnList, (Comparator<? super Map<String, Object>>)new Object());
|
||||
// String pathName = "E:/zzrsda/point-strategy/src/main/webapp/pdffile";
|
||||
@@ -236,13 +308,18 @@ public class FourCheckService {
|
||||
try {
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS");
|
||||
String currentName = "fourcheck_" + df.format(new Date());
|
||||
// 确保输出目录存在,避免因目录缺失导致 FileNotFoundException
|
||||
File outDir = new File(pathName);
|
||||
if (!outDir.exists()) {
|
||||
outDir.mkdirs();
|
||||
}
|
||||
outputStream = new FileOutputStream(new File(pathName + File.separator + currentName + ".pdf"));
|
||||
ExportConfigureImpl exportConfigureImpl = new ExportConfigureImpl("file:四性检测报表.ureport.xml", map, outputStream);
|
||||
ExportManager exportManager = (ExportManager) Utils.getApplicationContext().getBean("ureport.exportManager");
|
||||
exportManager.exportPdf((ExportConfigure)exportConfigureImpl);
|
||||
return currentName;
|
||||
} catch (Exception e) {
|
||||
|
||||
logger.error("导出四性检测报表PDF失败(findResultById-默认路径)", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -303,11 +380,48 @@ public class FourCheckService {
|
||||
String pass = "通过";
|
||||
if ("0".equals((new StringBuilder()).append(map1.get("pass")).append("").toString()))
|
||||
pass = "不通过";
|
||||
map1.put("pass", pass);
|
||||
map1.put("checkLink", checkLink);
|
||||
map1.put("dataFormat", dataFormat);
|
||||
map1.put("filePath", fourCheck.getFilePath());
|
||||
returnList.add(map1);
|
||||
|
||||
Object msgObj = map1.get("msg");
|
||||
List<String> msgLines = new ArrayList<>();
|
||||
if (msgObj instanceof List) {
|
||||
for (Object o : (List<?>) msgObj) msgLines.addAll(softWrap(String.valueOf(o), 60));
|
||||
} else if (msgObj instanceof com.alibaba.fastjson.JSONArray) {
|
||||
com.alibaba.fastjson.JSONArray arr = (com.alibaba.fastjson.JSONArray) msgObj;
|
||||
for (Object o : arr) msgLines.addAll(softWrap(String.valueOf(o), 60));
|
||||
} else if (msgObj != null) {
|
||||
msgLines.addAll(softWrap(String.valueOf(msgObj), 60));
|
||||
}
|
||||
|
||||
final int CHUNK = 15;
|
||||
if (msgLines.isEmpty()) {
|
||||
Map<String, Object> row = new HashMap<>();
|
||||
row.putAll(map1);
|
||||
row.put("type", typeChn);
|
||||
row.put("pass", pass);
|
||||
row.put("checkLink", checkLink);
|
||||
row.put("dataFormat", dataFormat);
|
||||
row.put("filePath", fourCheck.getFilePath());
|
||||
row.put("createdDate", dateFormat.format(fourCheck.getCreatedDate()));
|
||||
row.put("userChnName", fourCheck.getCreatedBy());
|
||||
row.put("msg", "");
|
||||
returnList.add(row);
|
||||
} else {
|
||||
for (int i = 0; i < msgLines.size(); i += CHUNK) {
|
||||
int end = Math.min(i + CHUNK, msgLines.size());
|
||||
String chunkText = String.join("\n", msgLines.subList(i, end));
|
||||
Map<String, Object> row = new HashMap<>();
|
||||
row.putAll(map1);
|
||||
row.put("type", typeChn);
|
||||
row.put("pass", pass);
|
||||
row.put("checkLink", checkLink);
|
||||
row.put("dataFormat", dataFormat);
|
||||
row.put("filePath", fourCheck.getFilePath());
|
||||
row.put("createdDate", dateFormat.format(fourCheck.getCreatedDate()));
|
||||
row.put("userChnName", fourCheck.getCreatedBy());
|
||||
row.put("msg", chunkText);
|
||||
returnList.add(row);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Collections.sort(returnList, (Comparator<? super Map<String, Object>>)new Object());
|
||||
// String pathName = "E:/zzrsda/point-strategy/src/main/webapp/pdffile";
|
||||
@@ -323,13 +437,18 @@ public class FourCheckService {
|
||||
try {
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS");
|
||||
String currentName = "fourcheck_" + df.format(new Date());
|
||||
// 确保输出目录存在
|
||||
File outDir = new File(filePath);
|
||||
if (!outDir.exists()) {
|
||||
outDir.mkdirs();
|
||||
}
|
||||
outputStream = new FileOutputStream(new File(filePath + File.separator + currentName + ".pdf"));
|
||||
ExportConfigureImpl exportConfigureImpl = new ExportConfigureImpl("file:四性检测报表.ureport.xml", map, outputStream);
|
||||
ExportManager exportManager = (ExportManager) Utils.getApplicationContext().getBean("ureport.exportManager");
|
||||
exportManager.exportPdf((ExportConfigure)exportConfigureImpl);
|
||||
return currentName;
|
||||
} catch (Exception e) {
|
||||
|
||||
logger.error("导出四性检测报表PDF失败(findResultById-指定路径)", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -575,7 +694,11 @@ public class FourCheckService {
|
||||
map.put("link",checkItem);
|
||||
map.put("describe",testItems);
|
||||
if(CollectionUtils.isNotEmpty(archivesNosTwo)){
|
||||
map.put("msg",archivesNosTwo);
|
||||
try {
|
||||
map.put("msg",objectMapper.writeValueAsString(archivesNosTwo));
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}else{
|
||||
map.put("msg","");
|
||||
}
|
||||
@@ -588,7 +711,11 @@ public class FourCheckService {
|
||||
map.put("link",checkItem);
|
||||
map.put("describe",testItems);
|
||||
if(CollectionUtils.isNotEmpty(archivesNosThree)){
|
||||
map.put("msg",archivesNosThree);
|
||||
try {
|
||||
map.put("msg",objectMapper.writeValueAsString(archivesNosThree));
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}else{
|
||||
map.put("msg","");
|
||||
}
|
||||
@@ -600,7 +727,11 @@ public class FourCheckService {
|
||||
map.put("link",checkItem);
|
||||
map.put("describe",testItems);
|
||||
if(CollectionUtils.isNotEmpty(archivesNosFour)){
|
||||
map.put("msg",archivesNosFour);
|
||||
try {
|
||||
map.put("msg",objectMapper.writeValueAsString(archivesNosFour));
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}else{
|
||||
map.put("msg","");
|
||||
}
|
||||
@@ -612,7 +743,11 @@ public class FourCheckService {
|
||||
map.put("link",checkItem);
|
||||
map.put("describe",testItems);
|
||||
if(CollectionUtils.isNotEmpty(archivesNos)){
|
||||
map.put("msg",archivesNos);
|
||||
try {
|
||||
map.put("msg",objectMapper.writeValueAsString(archivesNos));
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}else{
|
||||
map.put("msg","");
|
||||
}
|
||||
@@ -626,7 +761,11 @@ public class FourCheckService {
|
||||
map.put("link",checkItem);
|
||||
map.put("describe",testItems);
|
||||
if(CollectionUtils.isNotEmpty(archivesNosOne)){
|
||||
map.put("msg",archivesNosOne);
|
||||
try {
|
||||
map.put("msg",objectMapper.writeValueAsString(archivesNosOne));
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}else{
|
||||
map.put("msg","");
|
||||
}
|
||||
@@ -638,7 +777,11 @@ public class FourCheckService {
|
||||
map.put("link",checkItem);
|
||||
map.put("describe",testItems);
|
||||
if(!StringUtils.isEmpty(archivesNosFive)){
|
||||
map.put("msg",archivesNosFive);
|
||||
try {
|
||||
map.put("msg",objectMapper.writeValueAsString(archivesNosFive));
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}else{
|
||||
map.put("msg","");
|
||||
}
|
||||
|
||||
@@ -588,9 +588,12 @@ public class ReceiveInformationService {
|
||||
map.put("fondscode",fondscode);
|
||||
map.put("detection",detection);
|
||||
String fileName = fourCheckService.check(map);
|
||||
if (fileName.equals("请先设置四性检测条目")){
|
||||
// 避免对 null 调用 equals,先判空
|
||||
if ("请先设置四性检测条目".equals(fileName)){
|
||||
json = AjaxJson.returnExceptionInfo(fileName);
|
||||
}else {
|
||||
} else if (fileName == null) {
|
||||
json = AjaxJson.returnExceptionInfo("四性检测报表生成失败");
|
||||
} else {
|
||||
// //修改检测结果
|
||||
// ReceiveInformation information1 = new ReceiveInformation();
|
||||
// information1.setDetectionresult(2);
|
||||
|
||||
@@ -144,7 +144,7 @@
|
||||
<row row-number="2" height="19"/>
|
||||
<row row-number="3" height="19"/>
|
||||
<row row-number="4" height="19"/>
|
||||
<row row-number="5" height="50"/>
|
||||
<row row-number="5" height="19"/>
|
||||
<column col-number="1" width="68"/>
|
||||
<column col-number="2" width="68"/>
|
||||
<column col-number="3" width="68"/>
|
||||
|
||||
Reference in New Issue
Block a user