打印日志报错处理

This commit is contained in:
xiang2lin 2025-04-07 17:24:30 +08:00
parent 4cd1dadc75
commit cbeb66f9dd
2 changed files with 78 additions and 61 deletions

View File

@ -528,11 +528,8 @@ GSDM,KJND,mlId
<if test="zt != null and zt != ''"> ZT = #{zt},</if> <if test="zt != null and zt != ''"> ZT = #{zt},</if>
<if test="curshjd != null and curshjd != ''"> curshjd = #{curshjd},</if> <if test="curshjd != null and curshjd != ''"> curshjd = #{curshjd},</if>
<if test="nextshjd != null and nextshjd != ''"> nextshjd = #{nextshjd},</if> <if test="nextshjd != null and nextshjd != ''"> nextshjd = #{nextshjd},</if>
ssrid = #{ssrid}, <if test="shrId != null and shrId != ''"> shrid = #{shrId},</if>
ssr = #{ssr}, <if test="shrq != null and shrq != ''"> shrq = #{shrq}</if>
ssrq = #{ssrq},
shrid = #{ssrid},
shrq = #{shrq}
</trim> </trim>
where MLID = #{mlId} and DJBH = #{djbh} where MLID = #{mlId} and DJBH = #{djbh}
</update> </update>

View File

@ -338,10 +338,14 @@ public class OerDjmlExtServiceImpl implements IOerDjmlExtService {
djml.setNextshjd("-1"); djml.setNextshjd("-1");
//查询协同附件 //查询协同附件
List<FileInfoDTO> fileInfoList = fileDownload(summaryId, fileApiCode); List<FileInfoDTO> fileInfoList = fileDownload(summaryId, fileApiCode);
logger.info("接收文件22222");
djml.setFileInfoList(fileInfoList); djml.setFileInfoList(fileInfoList);
logger.info("set文件33333");
} }
logger.info("序列化djml对象444444");
String djmlStr = JSONObject.toJSONString(djml); String djmlStr = JSONObject.toJSONString(djml);
logger.info("费用报销单报文:{}",djmlStr); //logger.info("费用报销单报文:{}",djmlStr);
logger.info("序列化djml完成55555");
return djmlStr; return djmlStr;
} }
@ -569,91 +573,107 @@ public class OerDjmlExtServiceImpl implements IOerDjmlExtService {
} }
return timestamp; return timestamp;
} }
public List<FileInfoDTO> fileDownload(String summaryId, String apiCode) {
/**
* 附件下载并压缩成zip
* @param summaryId
* @param apiCode
* @return
*/
private List<FileInfoDTO> fileDownload(String summaryId,String apiCode){
try { try {
List<GrpU8CollAttachmentResDTO> colAttachmentList = restUtil.getColAttachments(summaryId, "0", apiCode, null); List<GrpU8CollAttachmentResDTO> colAttachmentList = restUtil.getColAttachments(summaryId, "0", apiCode, null);
//下载协同附件 // 下载协同附件
if (CollectionUtils.isNotEmpty(colAttachmentList)){ if (CollectionUtils.isNotEmpty(colAttachmentList)) {
String token = restUtil.getToken(null, apiCode); String token = restUtil.getToken(null, apiCode);
List<FileInfoDTO> fileList = new ArrayList<>(); List<FileInfoDTO> fileList = new ArrayList<>();
for (GrpU8CollAttachmentResDTO att : colAttachmentList) { String today = DateUtil.today();
FileInfoDTO fileInfoDTO = new FileInfoDTO(); String zipPath = DSK + File.separator + today + File.separator + "attachments.zip";
String fileName = URLDecoder.decode(att.getFilename(), "UTF-8"); // 确保目录存在
byte[] bytes = restUtil.downloadFileBytes(null, apiCode, att.getFileUrl(), fileName,token); if (!FileUtil.isDirectory(DSK + File.separator + today)) {
if (!FileUtil.isDirectory(DSK+ File.separator+DateUtil.today())){ FileUtil.mkdir(DSK + File.separator + today);
FileUtil.mkdir(DSK+ File.separator+DateUtil.today()); }
}
String filePath = DSK+ File.separator+DateUtil.today()+File.separator+att.getFileUrl()+"."+att.getExtension(); // 创建 ZipOutputStream
File file = new File(filePath); try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipPath), Charset.forName("GBK"))) {
// 使用 FileOutputStream 写入字节数组到文件 for (GrpU8CollAttachmentResDTO att : colAttachmentList) {
try (FileOutputStream fos = new FileOutputStream(file)) { FileInfoDTO fileInfoDTO = new FileInfoDTO();
fos.write(bytes);
} String fileName = URLDecoder.decode(att.getFilename(), "UTF-8");
if (null != file){ String fileUrl = att.getFileUrl();
String zipPath = DSK+File.separator+DateUtil.today()+File.separator+att.getFileUrl()+".zip"; byte[] bytes = restUtil.downloadFileBytes(null, apiCode, att.getFileUrl(), fileName, token);
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipPath), Charset.forName("GBK")); String filePath = DSK + File.separator + today + File.separator + att.getFileUrl() + "." + att.getExtension();
writeZipFile(file, zos, fileName); File file = new File(filePath);
zos.close();
// 获取压缩文件的字节数组 // 使用 FileOutputStream 写入字节数组到文件
File zipFile = new File(zipPath); try (FileOutputStream fos = new FileOutputStream(file)) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream((int) zipFile.length()); fos.write(bytes);
BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(zipFile)); }
int buf_size = 1024;
byte[] buffer = new byte[buf_size]; if (null != file) {
int len = 0; // 将文件添加到压缩包
while (-1 != (len = bufferedInputStream.read(buffer, 0, buf_size))) { writeZipFile(file, zos, fileName, fileUrl);
byteArrayOutputStream.write(buffer, 0, len);
} // 读取压缩文件的字节数组
byte[] fileByte = byteArrayOutputStream.toByteArray(); File zipFile = new File(zipPath);
fileInfoDTO.setData(fileByte); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream((int) zipFile.length());
fileInfoDTO.setFile_size(att.getSize()); try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(zipFile))) {
fileInfoDTO.setFile_name(fileName); int buf_size = 1024;
fileList.add(fileInfoDTO); byte[] buffer = new byte[buf_size];
} int len;
while (-1 != (len = bufferedInputStream.read(buffer, 0, buf_size))) {
byteArrayOutputStream.write(buffer, 0, len);
}
byte[] fileByte = byteArrayOutputStream.toByteArray();
fileInfoDTO.setData(fileByte);
fileInfoDTO.setFile_size(att.getSize());
fileInfoDTO.setFile_name(fileName);
fileList.add(fileInfoDTO);
logger.info("压缩后的文件读取字节数组完成");
} catch (Exception e) {
logger.error("压缩附件&读取字节数组出错:{}", e);
}
}
}
logger.info("压缩文件1111111");
return fileList;
} catch (Exception ex) {
logger.error("压缩附件添加到fileList出错{}", ex);
} }
return fileList;
} }
}catch (Exception e){ } catch (Exception e) {
logger.error("下载附件出错:{}",e); logger.error("下载附件出错:{}", e);
} }
return null; return null;
} }
/** /**
* 把文件压缩成zip * 把文件压缩成zip
* @param file 要压缩的文件 * @param file 要压缩的文件
* @param zos 文件压缩流 * @param zos 文件压缩流
* @param fileName 文件名 * @param fileName 文件名
* @param fileUrl 文件id
*/ */
private void writeZipFile(File file, ZipOutputStream zos, String fileName) { private void writeZipFile(File file, ZipOutputStream zos, String fileName, String fileUrl) {
if (null != file && null != zos) { if (null != file && null != zos) {
try { try (FileInputStream fos = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fos)) {
logger.info("=====压缩文件====="); logger.info("=====压缩文件=====");
zos.putNextEntry(new ZipEntry(fileName)); zos.putNextEntry(new ZipEntry(fileName + fileUrl));
FileInputStream fos = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fos);
int len; int len;
byte[] buf = new byte[1024]; byte[] buf = new byte[1024];
while ((len = bis.read(buf, 0, 1024)) != -1) { while ((len = bis.read(buf, 0, 1024)) != -1) {
zos.write(buf, 0, len); zos.write(buf, 0, len);
} }
bis.close(); zos.closeEntry();
fos.close();
logger.info("=====压缩完成====="); logger.info("=====压缩完成=====");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
logger.error("=====压缩文件出错====="); logger.error("=====压缩文件出错=====:{}", e);
try {
zos.closeEntry();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
} }
} }
} }
/** /**
* code和name拼接[] * code和name拼接[]
* @param code * @param code