报销单附件问题处理
This commit is contained in:
parent
f19ee30d0b
commit
9ef284e9f3
|
@ -77,8 +77,7 @@
|
|||
FROM
|
||||
OER_ANNEX
|
||||
<trim prefix="where" prefixOverrides="and">
|
||||
<if test="kjnd != null and kjnd !='' "> KJND = #{kjnd} </if>
|
||||
<if test="gsdm != null and gsdm !='' ">and GSDM = #{gsdm} </if>
|
||||
<if test="gsdm != null and gsdm !='' "> GSDM = #{gsdm} </if>
|
||||
</trim>
|
||||
</select>
|
||||
|
||||
|
|
|
@ -9,7 +9,10 @@ public class FileInfoDTO {
|
|||
private byte[] data;//附件压缩成zip后的数据
|
||||
private String file_name;//附件名字
|
||||
private String file_size;//附件大小
|
||||
|
||||
//压缩后附件路径
|
||||
private String zip_file_path;
|
||||
//原始附件路径
|
||||
private String original_file_path;
|
||||
public byte[] getData() {
|
||||
return data;
|
||||
}
|
||||
|
@ -33,4 +36,20 @@ public class FileInfoDTO {
|
|||
public void setFile_size(String file_size) {
|
||||
this.file_size = file_size;
|
||||
}
|
||||
|
||||
public String getZip_file_path() {
|
||||
return zip_file_path;
|
||||
}
|
||||
|
||||
public void setZip_file_path(String zip_file_path) {
|
||||
this.zip_file_path = zip_file_path;
|
||||
}
|
||||
|
||||
public String getOriginal_file_path() {
|
||||
return original_file_path;
|
||||
}
|
||||
|
||||
public void setOriginal_file_path(String original_file_path) {
|
||||
this.original_file_path = original_file_path;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import cn.hutool.core.convert.Convert;
|
|||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
@ -17,6 +18,7 @@ import com.hzya.frame.grpU8.nxproof.oerdjml.entity.OerDjmlEntity;
|
|||
import com.hzya.frame.grpU8.nxproof.oerdjml.entity.RestUtil;
|
||||
import com.hzya.frame.grpU8.nxproof.oerdjml.enums.ColEventTypeEnum;
|
||||
import com.hzya.frame.grpU8.nxproof.oerdjml.service.IOerDjmlExtService;
|
||||
import com.hzya.frame.grpU8.nxproof.oerdjml.util.OerDjmlUtil;
|
||||
import com.hzya.frame.grpU8.nxproof.oerdjnr.entity.OerDjnrEntity;
|
||||
import com.hzya.frame.grpU8.nxproof.oeryszb.entity.OerYszbEntity;
|
||||
import com.hzya.frame.sysnew.application.database.entity.SysApplicationDatabaseEntity;
|
||||
|
@ -236,7 +238,7 @@ public class OerDjmlExtServiceImpl implements IOerDjmlExtService {
|
|||
djml.setCurshjd("-9");
|
||||
djml.setNextshjd("999");
|
||||
djml.setFlowcode(flowcode);
|
||||
djml.setJsfs(spliceStr(forsonData0.getString("field0042"),forsonData0.getString("field0043")));//结算方式
|
||||
djml.setJsfs(OerDjmlUtil.spliceStr(forsonData0.getString("field0042"),forsonData0.getString("field0043")));//结算方式
|
||||
djml.setTel("");//电话
|
||||
djml.setSsrq(DateUtil.format(formmainData.getDate("field0039"),"yyyyMMddHHmmssSSS"));//送审日期
|
||||
djml.setSsrid(formmainData.getString("field0037"));//送审人id
|
||||
|
@ -341,16 +343,14 @@ public class OerDjmlExtServiceImpl implements IOerDjmlExtService {
|
|||
djml.setZt("3");
|
||||
djml.setCurshjd("999");
|
||||
djml.setNextshjd("-1");
|
||||
djml.setCrerdm(formmainData.getString("field0037"));//制单人代码
|
||||
djml.setCrermc(formmainData.getString("field0038"));//制单人名称
|
||||
//查询协同附件
|
||||
List<FileInfoDTO> fileInfoList = fileDownload(summaryId, fileApiCode);
|
||||
logger.info("接收文件22222");
|
||||
List<FileInfoDTO> fileInfoList = fileDownloadV1(summaryId, fileApiCode);
|
||||
djml.setFileInfoList(fileInfoList);
|
||||
logger.info("set文件33333");
|
||||
}
|
||||
logger.info("序列化djml对象444444");
|
||||
String djmlStr = JSONObject.toJSONString(djml);
|
||||
//logger.info("费用报销单报文:{}",djmlStr);
|
||||
logger.info("序列化djml完成55555");
|
||||
logger.info("费用报销单报文:{}",djmlStr);
|
||||
return djmlStr;
|
||||
}
|
||||
|
||||
|
@ -408,7 +408,7 @@ public class OerDjmlExtServiceImpl implements IOerDjmlExtService {
|
|||
djml.setCurshjd("-9");
|
||||
djml.setNextshjd("999");
|
||||
djml.setFlowcode(flowcode);
|
||||
djml.setJsfs(spliceStr(forjsonData0.getString("field0086"), forjsonData0.getString("field0042")));
|
||||
djml.setJsfs(OerDjmlUtil.spliceStr(forjsonData0.getString("field0086"), forjsonData0.getString("field0042")));
|
||||
//电话
|
||||
djml.setTel(formmainData.getString("field0005"));
|
||||
djml.setClf_ccr(formmainData.getString("field0089"));
|
||||
|
@ -546,7 +546,7 @@ public class OerDjmlExtServiceImpl implements IOerDjmlExtService {
|
|||
djml.setCurshjd("999");
|
||||
djml.setNextshjd("-1");
|
||||
//查询协同附件
|
||||
List<FileInfoDTO> fileInfoList = fileDownload(summaryId, fileApiCode);
|
||||
List<FileInfoDTO> fileInfoList = fileDownloadV1(summaryId, fileApiCode);
|
||||
djml.setFileInfoList(fileInfoList);
|
||||
}
|
||||
String djmlStr = JSONObject.toJSONString(djml);
|
||||
|
@ -578,7 +578,8 @@ public class OerDjmlExtServiceImpl implements IOerDjmlExtService {
|
|||
}
|
||||
return timestamp;
|
||||
}
|
||||
public List<FileInfoDTO> fileDownload(String summaryId, String apiCode) {
|
||||
//这个方法暂时没用
|
||||
public List<FileInfoDTO> fileDownloadDiscard(String summaryId, String apiCode) {
|
||||
try {
|
||||
List<GrpU8CollAttachmentResDTO> colAttachmentList = restUtil.getColAttachments(summaryId, "0", apiCode, null);
|
||||
// 下载协同附件
|
||||
|
@ -646,6 +647,56 @@ public class OerDjmlExtServiceImpl implements IOerDjmlExtService {
|
|||
return null;
|
||||
}
|
||||
|
||||
//从OA下载附件
|
||||
public List<FileInfoDTO> fileDownloadV1(String summaryId, String apiCode) {
|
||||
Assert.notEmpty(summaryId,"summaryId不能为空");
|
||||
Assert.notEmpty(apiCode,"apiCode不能为空");
|
||||
try {
|
||||
//1、查询协同附件
|
||||
List<GrpU8CollAttachmentResDTO> colAttachmentList = restUtil.getColAttachments(summaryId, "0", apiCode, null);
|
||||
//2、下载协同附件
|
||||
if (CollectionUtils.isNotEmpty(colAttachmentList)){
|
||||
//获取OA token
|
||||
String token = restUtil.getToken(null, apiCode);
|
||||
List<FileInfoDTO> fileList = new ArrayList<>();
|
||||
String today = DateUtil.today();
|
||||
String basePath = DSK + File.separator + today + File.separator;
|
||||
// 确保目录存在
|
||||
if (!FileUtil.isDirectory(basePath)) {
|
||||
FileUtil.mkdir(basePath);
|
||||
}
|
||||
for (GrpU8CollAttachmentResDTO att : colAttachmentList) {
|
||||
String fileName = URLDecoder.decode(att.getFilename(), "UTF-8");
|
||||
String fileUrl = att.getFileUrl();
|
||||
byte[] bytes = restUtil.downloadFileBytes(null, apiCode, att.getFileUrl(), fileName, token);
|
||||
String filePath = basePath + att.getFileUrl() + "." + att.getExtension();
|
||||
File file = new File(filePath);
|
||||
// 使用 FileOutputStream 写入字节数组到文件
|
||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||
fos.write(bytes);
|
||||
}
|
||||
//3、把协同附件压缩成.zip
|
||||
if (null != file){
|
||||
String zipPath = basePath + att.getFileUrl() + ".zip";
|
||||
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipPath), Charset.forName("GBK"));
|
||||
writeZipFile(file, zos, fileName,fileUrl);
|
||||
zos.close();
|
||||
//4、返回.zip附件路径
|
||||
FileInfoDTO fileInfo = new FileInfoDTO();
|
||||
fileInfo.setZip_file_path(zipPath);
|
||||
fileInfo.setOriginal_file_path(filePath);
|
||||
fileInfo.setFile_name(fileName);
|
||||
fileInfo.setFile_size(att.getSize());
|
||||
fileList.add(fileInfo);
|
||||
}
|
||||
}
|
||||
return fileList;
|
||||
}
|
||||
}catch(Exception e){
|
||||
logger.error("下载OA附件出错:{}",e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* 把文件压缩成zip
|
||||
* @param file 要压缩的文件
|
||||
|
@ -658,37 +709,22 @@ public class OerDjmlExtServiceImpl implements IOerDjmlExtService {
|
|||
try (FileInputStream fos = new FileInputStream(file);
|
||||
BufferedInputStream bis = new BufferedInputStream(fos)) {
|
||||
logger.info("=====压缩文件=====");
|
||||
zos.putNextEntry(new ZipEntry(fileName + fileUrl));
|
||||
zos.putNextEntry(new ZipEntry(fileUrl+fileName ));
|
||||
int len;
|
||||
byte[] buf = new byte[1024];
|
||||
while ((len = bis.read(buf, 0, 1024)) != -1) {
|
||||
zos.write(buf, 0, len);
|
||||
}
|
||||
zos.closeEntry();
|
||||
logger.info("=====压缩完成=====");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("=====压缩文件出错=====:{}", e);
|
||||
try {
|
||||
zos.closeEntry();
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* code和name拼接[]
|
||||
* @param code
|
||||
* @param name
|
||||
* @return 格式:03[公务卡]
|
||||
*/
|
||||
private String spliceStr(String code,String name){
|
||||
String template = "{}[{}]";
|
||||
return StrUtil.format(template,code,name);
|
||||
}
|
||||
|
||||
|
||||
public enum DjlxEnum {
|
||||
TRAVEL("travel","差旅报销单"),
|
||||
|
|
|
@ -23,6 +23,7 @@ import com.hzya.frame.grpU8.nxproof.oerdjml.entity.GbiZbsyrecAllEntity;
|
|||
import com.hzya.frame.grpU8.nxproof.oerdjml.entity.OerDjmlEntity;
|
||||
import com.hzya.frame.grpU8.nxproof.oerdjml.enums.ColEventTypeEnum;
|
||||
import com.hzya.frame.grpU8.nxproof.oerdjml.service.IOerDjmlService;
|
||||
import com.hzya.frame.grpU8.nxproof.oerdjml.util.OerDjmlUtil;
|
||||
import com.hzya.frame.grpU8.nxproof.oerdjnr.dao.IOerDjnrDao;
|
||||
import com.hzya.frame.grpU8.nxproof.oerdjnr.entity.OerDjnrEntity;
|
||||
import com.hzya.frame.grpU8.nxproof.oeryszb.dao.IOerYszbDao;
|
||||
|
@ -41,6 +42,10 @@ import org.apache.logging.log4j.Logger;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
@ -837,14 +842,16 @@ public class OerDjmlServiceImpl implements IOerDjmlService {
|
|||
delete.setGsdm(oerDjmlAllEntities.get(0).getGsdm());
|
||||
delete.setDataSourceCode(entity.getDataSourceCode());
|
||||
oerAnnexDao.deleteAnnex(delete);
|
||||
int no = 1;
|
||||
int no = 0;
|
||||
for (FileInfoDTO fileInfo : entity.getFileInfoList()) {
|
||||
try {
|
||||
AttachmentFileEntity fileEntity = new AttachmentFileEntity();
|
||||
fileEntity.setDataSourceCode(entity.getDataSourceCode());
|
||||
String fileName = URLDecoder.decode(fileInfo.getFile_name(), "UTF-8");
|
||||
fileEntity.setaTFileName(fileName);
|
||||
fileEntity.setaTFile(fileInfo.getData());
|
||||
fileEntity.setaTFile(file2bytes(fileInfo.getZip_file_path()));
|
||||
fileEntity.setCreateID(OerDjmlUtil.spliceStr(entity.getCrerdm(),entity.getCrermc()));
|
||||
fileEntity.setUpdateID(OerDjmlUtil.spliceStr(entity.getCrerdm(),entity.getCrermc()));
|
||||
saveAttachment(fileEntity);
|
||||
//保存附件关系
|
||||
OerAnnexEntity annexEntity = new OerAnnexEntity();
|
||||
|
@ -870,7 +877,7 @@ public class OerDjmlServiceImpl implements IOerDjmlService {
|
|||
annexEntity.setShowSize(showSize);
|
||||
}
|
||||
|
||||
annexEntity.setFjType("其它");
|
||||
//annexEntity.setFjType("其它");
|
||||
oerAnnexDao.saveData(annexEntity);
|
||||
no++;
|
||||
}catch (Exception e){
|
||||
|
@ -887,6 +894,28 @@ public class OerDjmlServiceImpl implements IOerDjmlService {
|
|||
return BaseResult.getSuccessMessageEntity("处理成功");
|
||||
}
|
||||
|
||||
//附件转成字节数组
|
||||
private byte[] file2bytes(String filePath){
|
||||
if (null != filePath){
|
||||
File zipFile = new File(filePath);
|
||||
if (null != zipFile){
|
||||
try(ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream((int) zipFile.length());
|
||||
BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(zipFile))) {
|
||||
int buf_size = 1024;
|
||||
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();
|
||||
return fileByte;
|
||||
}catch (Exception ex){
|
||||
logger.error("附件转成字节数组出错:{}",ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public String queryMaxId(OerAnnexEntity entity) {
|
||||
if (null == entity){
|
||||
entity = new OerAnnexEntity();
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package com.hzya.frame.grpU8.nxproof.oerdjml.util;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
/**
|
||||
* @Description 报销单工具类
|
||||
* @Author xiangerlin
|
||||
* @Date 2025/4/8 18:01
|
||||
**/
|
||||
public class OerDjmlUtil {
|
||||
|
||||
/**
|
||||
* code和name拼接[]
|
||||
* @param code
|
||||
* @param name
|
||||
* @return 格式:03[公务卡]
|
||||
*/
|
||||
public static String spliceStr(String code,String name){
|
||||
String template = "{}[{}]";
|
||||
return StrUtil.format(template,code,name);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue