打印日志报错处理

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="curshjd != null and curshjd != ''"> curshjd = #{curshjd},</if>
<if test="nextshjd != null and nextshjd != ''"> nextshjd = #{nextshjd},</if>
ssrid = #{ssrid},
ssr = #{ssr},
ssrq = #{ssrq},
shrid = #{ssrid},
shrq = #{shrq}
<if test="shrId != null and shrId != ''"> shrid = #{shrId},</if>
<if test="shrq != null and shrq != ''"> shrq = #{shrq}</if>
</trim>
where MLID = #{mlId} and DJBH = #{djbh}
</update>

View File

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