|
|
@@ -0,0 +1,954 @@
|
|
|
+package com.jeeplus.psimanage.oss.service;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.extra.spring.SpringUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.aliyun.oss.HttpMethod;
|
|
|
+import com.aliyun.oss.OSSClient;
|
|
|
+import com.aliyun.oss.model.GeneratePresignedUrlRequest;
|
|
|
+import com.aliyun.oss.model.OSSObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.jeeplus.psimanage.oss.domain.PsiWorkAttachment;
|
|
|
+import com.jeeplus.psimanage.oss.mapper.PsiOssServiceMapper;
|
|
|
+import com.jeeplus.psimanage.oss.service.dto.AttachmentDTO;
|
|
|
+import com.jeeplus.psimanage.oss.service.dto.FileDetailDTO;
|
|
|
+import com.jeeplus.psimanage.oss.service.dto.FileUrlDto;
|
|
|
+import com.jeeplus.psimanage.oss.service.dto.WorkAttachmentDto;
|
|
|
+import com.jeeplus.sys.domain.WorkAttachmentInfo;
|
|
|
+import com.jeeplus.sys.feign.IUserApi;
|
|
|
+import com.jeeplus.sys.service.dto.UserDTO;
|
|
|
+import com.jeeplus.sys.service.dto.WorkAttachmentInfoDTO;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+import org.w3c.dom.Document;
|
|
|
+import org.w3c.dom.Node;
|
|
|
+import org.w3c.dom.NodeList;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import javax.xml.parsers.DocumentBuilder;
|
|
|
+import javax.xml.parsers.DocumentBuilderFactory;
|
|
|
+import java.io.BufferedInputStream;
|
|
|
+import java.io.BufferedOutputStream;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.net.URL;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class PsiOssService extends ServiceImpl<PsiOssServiceMapper, PsiWorkAttachment> {
|
|
|
+
|
|
|
+ @Value("${config.accessory.aliyun.aliyunUrl}")
|
|
|
+ private String aliyunUrl;
|
|
|
+
|
|
|
+ @Value("${config.accessory.aliyun.aliyunDownloadUrl}")
|
|
|
+ private String aliyunDownloadUrl;
|
|
|
+
|
|
|
+ @Value("${config.accessory.aliyun.endpoint}")
|
|
|
+ private String endpoint;
|
|
|
+
|
|
|
+ @Value("${config.accessory.aliyun.accessKeyId}")
|
|
|
+ private String accessKeyId;
|
|
|
+
|
|
|
+ @Value("${config.accessory.aliyun.accessKeySecret}")
|
|
|
+ private String accessKeySecret;
|
|
|
+
|
|
|
+ @Value("${config.accessory.aliyun.bucketName}")
|
|
|
+ private String bucketName;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PsiOssServiceMapper psiOssServiceMapper;
|
|
|
+
|
|
|
+ @Value("${aliyun_directory}")
|
|
|
+ private String directory = "attachment-file/assess";
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PsiOSSClientService psiOssClientService;
|
|
|
+
|
|
|
+ public void insertWorkAttachment (PsiWorkAttachment psiWorkAttachment, UserDTO userDto){
|
|
|
+ psiOssServiceMapper.insertWorkAttachment(psiWorkAttachment, userDto);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存数据
|
|
|
+ * @param psiWorkAttachments
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public void saveMsg(List<PsiWorkAttachment> psiWorkAttachments, String currentToken) {
|
|
|
+// String currentToken = TokenProvider.getCurrentToken();
|
|
|
+ if (CollectionUtil.isNotEmpty(psiWorkAttachments)) {
|
|
|
+ //获取当前登录人信息
|
|
|
+ String id = SpringUtil.getBean ( IUserApi.class ).getByToken (currentToken).getId();
|
|
|
+ int i = 1;
|
|
|
+ for (PsiWorkAttachment psiWorkAttachment : psiWorkAttachments) {
|
|
|
+ //判断文件是否存在
|
|
|
+ /*LambdaQueryWrapper<WorkAttachment> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.eq(WorkAttachment::getUrl, workAttachment.getUrl());
|
|
|
+ lambdaQueryWrapper.eq(WorkAttachment::getAttachmentId, workAttachment.getAttachmentId());*/
|
|
|
+ WorkAttachmentInfo workAttachmentInfo = new WorkAttachmentInfo();
|
|
|
+ workAttachmentInfo.setUrl(psiWorkAttachment.getUrl());
|
|
|
+ workAttachmentInfo.setAttachmentId(psiWorkAttachment.getAttachmentId());
|
|
|
+ List<WorkAttachmentInfo> list = psiOssServiceMapper.getByAttachmentIdAndUrlAndAttachmentFlag(workAttachmentInfo);
|
|
|
+ if (CollectionUtil.isNotEmpty(list)) {
|
|
|
+ i++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ log.info("开始执行保存操作,入参:{}" , JSONObject.toJSONString(psiWorkAttachments));
|
|
|
+ //文件后缀名赋值
|
|
|
+ List<String> strings = Arrays.asList(psiWorkAttachment.getUrl().split("\\."));
|
|
|
+ psiWorkAttachment.setType(strings.get(strings.size()-1));
|
|
|
+ psiWorkAttachment.setId(UUID.randomUUID().toString().replace("-",""));
|
|
|
+ //排序赋值
|
|
|
+ psiWorkAttachment.setSort(i);
|
|
|
+ //基础信息赋值
|
|
|
+ //workAttachment.getCreateBy().setId(id);
|
|
|
+ psiWorkAttachment.setCreateTime(new Date());
|
|
|
+ //workAttachment.getUpdateBy().setId(id);
|
|
|
+ psiWorkAttachment.setUpdateTime(new Date());
|
|
|
+ psiWorkAttachment.setDelFlag(0);
|
|
|
+ i++;
|
|
|
+
|
|
|
+ UserDTO userDTO = SpringUtil.getBean ( IUserApi.class ).getByToken (currentToken);
|
|
|
+ psiOssServiceMapper.insertWorkAttachment(psiWorkAttachment, userDTO);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ log.info("保存操作执行完成");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据文件路径删除文件
|
|
|
+ * @param url
|
|
|
+ */
|
|
|
+ public void deleteMsgByFileName(String url) {
|
|
|
+ log.info("开始执行删除操作,入参:{}" , url);
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ map.put("url", url);
|
|
|
+ int i = psiOssServiceMapper.deleteByMap(map);
|
|
|
+ log.info("删除操作完成,共删除{}条数据" , i);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据id删除数据
|
|
|
+ * @param id
|
|
|
+ */
|
|
|
+ public void deleteMsgById(String id) {
|
|
|
+ log.info("开始执行删除操作,入参:{}" , id);
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ map.put("id", id);
|
|
|
+ int i = psiOssServiceMapper.deleteById(id);
|
|
|
+ //项目文件删除后处理项目文件状态
|
|
|
+ Integer num = psiOssServiceMapper.selectSaveById(id);
|
|
|
+ if (num == 0) {
|
|
|
+ psiOssServiceMapper.updateProjectRecord(id);
|
|
|
+ }
|
|
|
+ log.info("删除操作完成,共删除{}条数据" , i);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据附件对应父节点id查询文件列表
|
|
|
+ * @param attachmentId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<AttachmentDTO> findFileList(String attachmentId) {
|
|
|
+
|
|
|
+ log.info("文件查询开始,入参:{}" , attachmentId);
|
|
|
+ QueryWrapper<PsiWorkAttachment> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq ("a.attachment_id", attachmentId );
|
|
|
+ queryWrapper.eq ("a.del_flag", "0" );
|
|
|
+ List<AttachmentDTO> list = psiOssServiceMapper.findList(queryWrapper);
|
|
|
+ //创建人和文件名称处理
|
|
|
+ if (CollectionUtil.isNotEmpty(list)) {
|
|
|
+ temporaryUrl(list);
|
|
|
+ }
|
|
|
+ log.info("文件查询结束,查询结果:{}" , JSONObject.toJSONString(list));
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成临时文件
|
|
|
+ * @param list
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<AttachmentDTO> temporaryUrl(List<AttachmentDTO> list) {
|
|
|
+ list.stream().forEach(work -> {
|
|
|
+ String url = null;
|
|
|
+ if (StringUtils.isNotEmpty(work.getUrl())) {
|
|
|
+ url = aliyunUrl + work.getUrl();
|
|
|
+ work.setTemporaryUrl(getFileTemporaryLookUrl(url));
|
|
|
+ }
|
|
|
+
|
|
|
+ //对文件大小进行处理
|
|
|
+ if(StringUtils.isBlank(work.getFileSize())){
|
|
|
+ work.setFileSize("0");
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(work.getFileSize())){
|
|
|
+ Long fileSizeBytes = Long.parseLong(work.getFileSize());
|
|
|
+ //如果数据库文件大小小于等于0, 则访问阿里云获取文件大小
|
|
|
+ fileSizeBytes = 0L;
|
|
|
+ if (fileSizeBytes<=0){
|
|
|
+ fileSizeBytes = psiOssClientService.getSimplifiedObjectMeta(url);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(null != fileSizeBytes){
|
|
|
+ Double fileSize = (double)fileSizeBytes/1024/1024;
|
|
|
+ work.setFileSize(String.format("%.2f", fileSize));
|
|
|
+ }else{
|
|
|
+ work.setFileSize("0.00");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据文件路径获取文件信息
|
|
|
+ * @param url
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public FileDetailDTO getFileSizeByUrl(String url){
|
|
|
+ FileDetailDTO fileDetailDTO = new FileDetailDTO();
|
|
|
+ fileDetailDTO.setUrl(getFileTemporaryLookUrl(aliyunUrl + url));
|
|
|
+ Long fileSizeBytes = psiOssClientService.getSimplifiedObjectMeta(aliyunUrl + url);
|
|
|
+ if(null != fileSizeBytes){
|
|
|
+ Double fileSize = (double)fileSizeBytes;
|
|
|
+ fileDetailDTO.setSize(String.format("%.2f", fileSize));
|
|
|
+ }else{
|
|
|
+ fileDetailDTO.setSize("0");
|
|
|
+ }
|
|
|
+ return fileDetailDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据文件路径获取文件信息
|
|
|
+ * @param url
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public FileDetailDTO getSFZSizeByUrl(String url){
|
|
|
+ FileDetailDTO fileDetailDTO = new FileDetailDTO();
|
|
|
+ fileDetailDTO.setUrl(getFileTemporaryLookUrlWithWatermark(aliyunUrl + url));
|
|
|
+ Long fileSizeBytes = psiOssClientService.getSimplifiedObjectMeta(aliyunUrl + url);
|
|
|
+ if(null != fileSizeBytes){
|
|
|
+ Double fileSize = (double)fileSizeBytes;
|
|
|
+ fileDetailDTO.setSize(String.format("%.2f", fileSize));
|
|
|
+ }else{
|
|
|
+ fileDetailDTO.setSize("0");
|
|
|
+ }
|
|
|
+ return fileDetailDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 阿里云获取临时文件查看url
|
|
|
+ * @param url
|
|
|
+ */
|
|
|
+ public String getFileTemporaryLookUrl(String url){
|
|
|
+ url = url.replace("amp;","");
|
|
|
+ String cons = "";
|
|
|
+ if (url.contains(aliyunUrl)){
|
|
|
+ cons = aliyunUrl;
|
|
|
+ }else if (url.contains("http://gangwan-app.oss-cn-hangzhou.aliyuncs.com")){
|
|
|
+ cons = "http://gangwan-app.oss-cn-hangzhou.aliyuncs.com";
|
|
|
+ }else {
|
|
|
+ cons = aliyunDownloadUrl;
|
|
|
+ }
|
|
|
+ String key = "";
|
|
|
+ String[] split = url.split(cons + "/");
|
|
|
+ if(split.length>1){
|
|
|
+ key = split[1];
|
|
|
+ }else{
|
|
|
+ key = url;
|
|
|
+ }
|
|
|
+ // 指定过期时间为24小时。
|
|
|
+ Date expiration = new Date(new Date().getTime() + 1000 * 60 * 60 * 24 );
|
|
|
+ //初始化OSSClient
|
|
|
+ OSSClient ossClient = new OSSClient(endpoint,accessKeyId,accessKeySecret);
|
|
|
+ return ossClient.generatePresignedUrl(bucketName, key, expiration).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 缩略图
|
|
|
+ * 获取阿里云 OSS 上图片的缩略图临时访问地址
|
|
|
+ * @param file 图片完整路径(包含 http(s)://)
|
|
|
+ * @return 带缩略图样式的临时URL
|
|
|
+ */
|
|
|
+ public String getThumbnailTemporaryLookUrl(String file) {
|
|
|
+ try {
|
|
|
+ file = file.replace("amp;", "");
|
|
|
+ String cons;
|
|
|
+
|
|
|
+ if (file.contains(aliyunUrl)) {
|
|
|
+ cons = aliyunUrl;
|
|
|
+ } else if (file.contains("http://gangwan-app.oss-cn-hangzhou.aliyuncs.com")) {
|
|
|
+ cons = "http://gangwan-app.oss-cn-hangzhou.aliyuncs.com";
|
|
|
+ } else {
|
|
|
+ cons = aliyunDownloadUrl;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取 key(即 OSS 路径)
|
|
|
+ String key = file.split(cons + "/")[1];
|
|
|
+
|
|
|
+ // 设置过期时间(24小时)
|
|
|
+ Date expiration = new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 24);
|
|
|
+
|
|
|
+ // 设置图片处理参数,这里按宽度200缩放
|
|
|
+ GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucketName, key, HttpMethod.GET);
|
|
|
+ request.setExpiration(expiration);
|
|
|
+ request.setProcess("image/resize,w_200"); // ✅ 这里是关键:缩略图处理样式
|
|
|
+
|
|
|
+ //初始化OSSClient
|
|
|
+ OSSClient ossClient = new OSSClient(endpoint,accessKeyId,accessKeySecret);
|
|
|
+ // 生成带签名的URL
|
|
|
+ URL url = ossClient.generatePresignedUrl(request);
|
|
|
+ return url.toString();
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 带水印、虚化原图(水印旋转45度)
|
|
|
+ * 阿里云获取临时文件查看url(带水印)
|
|
|
+ * @param file OSS 文件完整 URL
|
|
|
+ * @return 带临时访问权限的 URL
|
|
|
+ */
|
|
|
+ public String getFileTemporaryLookUrlWithWatermark(String file) {
|
|
|
+ try {
|
|
|
+ file = file.replace("amp;", "");
|
|
|
+
|
|
|
+ String cons;
|
|
|
+ if (file.contains(aliyunUrl)) {
|
|
|
+ cons = aliyunUrl;
|
|
|
+ } else if (file.contains("http://gangwan-app.oss-cn-hangzhou.aliyuncs.com")) {
|
|
|
+ cons = "http://gangwan-app.oss-cn-hangzhou.aliyuncs.com";
|
|
|
+ } else {
|
|
|
+ cons = aliyunDownloadUrl;
|
|
|
+ }
|
|
|
+
|
|
|
+ String key = file.split(cons + "/")[1];
|
|
|
+
|
|
|
+ // 过期时间 24 小时
|
|
|
+ Date expiration = new Date(System.currentTimeMillis() + 1000L * 60 * 60 * 24);
|
|
|
+
|
|
|
+ // 构建预签名请求(带水印)
|
|
|
+ GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucketName, key, HttpMethod.GET);
|
|
|
+
|
|
|
+ String text = "仅用于公司人员信息备案,其他用途无效";
|
|
|
+ // 将字符串转为 UTF-8 字节
|
|
|
+ byte[] bytes = text.getBytes(java.nio.charset.StandardCharsets.UTF_8);
|
|
|
+
|
|
|
+ // 使用 URL Safe Base64 编码
|
|
|
+ String base64Text = Base64.getUrlEncoder().withoutPadding().encodeToString(bytes);
|
|
|
+
|
|
|
+ // 设置水印参数:中间 g_center,红色 FF0000,字号 40
|
|
|
+ String imageProcess = "image/blur,r_50,s_5" + "/watermark,text_" + base64Text + ",color_FF0000,size_40,g_center,rotate_45";
|
|
|
+
|
|
|
+ request.setProcess(imageProcess);
|
|
|
+
|
|
|
+ request.setExpiration(expiration);
|
|
|
+
|
|
|
+ //初始化OSSClient
|
|
|
+ OSSClient ossClient = new OSSClient(endpoint,accessKeyId,accessKeySecret);
|
|
|
+ URL url = ossClient.generatePresignedUrl(request);
|
|
|
+ return url.toString();
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 带水印、虚化、缩略图(水印旋转45度)
|
|
|
+ * 获取阿里云 OSS 上图片的缩略图临时访问地址(带水印、缩略图、图片虚化)
|
|
|
+ * @param file 图片完整路径(包含 http(s)://)
|
|
|
+ * @return 带缩略图样式的临时URL
|
|
|
+ */
|
|
|
+ public String getThumbnailTemporaryWithWatermarkDimLookUrl(String file) {
|
|
|
+ try {
|
|
|
+ file = file.replace("amp;", "");
|
|
|
+
|
|
|
+ String cons;
|
|
|
+
|
|
|
+ if (file.contains(aliyunUrl)) {
|
|
|
+ cons = aliyunUrl;
|
|
|
+ } else if (file.contains("http://gangwan-app.oss-cn-hangzhou.aliyuncs.com")) {
|
|
|
+ cons = "http://gangwan-app.oss-cn-hangzhou.aliyuncs.com";
|
|
|
+ } else {
|
|
|
+ cons = aliyunDownloadUrl;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取 key(即 OSS 路径)
|
|
|
+ String key = file.split(cons + "/")[1];
|
|
|
+
|
|
|
+ // 设置过期时间(24小时)
|
|
|
+ Date expiration = new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 24);
|
|
|
+
|
|
|
+ // 设置图片处理参数,这里按宽度200缩放
|
|
|
+ GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucketName, key, HttpMethod.GET);
|
|
|
+ request.setExpiration(expiration);
|
|
|
+
|
|
|
+ String text = "仅用于公司人员信息备案,其他用途无效";
|
|
|
+ // 将字符串转为 UTF-8 字节
|
|
|
+ byte[] bytes = text.getBytes(java.nio.charset.StandardCharsets.UTF_8);
|
|
|
+
|
|
|
+ // 使用 URL Safe Base64 编码
|
|
|
+ String base64Text = Base64.getUrlEncoder().withoutPadding().encodeToString(bytes);
|
|
|
+
|
|
|
+ String imageProcess = "image/blur,r_50,s_5" + "/watermark,text_" + base64Text + ",color_FF0000,size_40,g_center,rotate_45"+ "/resize,w_200";
|
|
|
+
|
|
|
+ request.setProcess(imageProcess);
|
|
|
+
|
|
|
+ //初始化OSSClient
|
|
|
+ OSSClient ossClient = new OSSClient(endpoint,accessKeyId,accessKeySecret);
|
|
|
+ // 生成带签名的URL
|
|
|
+ URL url = ossClient.generatePresignedUrl(request);
|
|
|
+ return url.toString();
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 附件下载
|
|
|
+ * @param key
|
|
|
+ * @param fileName
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
+ public void downByStream(String key, String fileName, HttpServletResponse response, String agent){
|
|
|
+ try {
|
|
|
+ String newName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20").replaceAll("%28", "\\(").replaceAll("%29", "\\)").replaceAll("%3B", ";").replaceAll("%40", "@").replaceAll("%23", "\\#").replaceAll("%26", "\\&").replaceAll("%2C", "\\,");
|
|
|
+ // 创建OSSClient实例
|
|
|
+ //初始化OSSClient
|
|
|
+ OSSClient ossClient = new OSSClient(endpoint,accessKeyId,accessKeySecret);
|
|
|
+ OSSObject ossObject = ossClient.getObject(bucketName, key);
|
|
|
+ BufferedInputStream in = new BufferedInputStream(ossObject.getObjectContent());
|
|
|
+ BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
|
|
|
+ response.setHeader("Content-Disposition","attachment;filename*=UTF-8''"+ newName);
|
|
|
+
|
|
|
+ /*if(agent != null && agent.toLowerCase().indexOf("firefox") > 0){
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''"+ URLEncoder.encode(fileName,"utf-8"));
|
|
|
+ }else {
|
|
|
+ response.setHeader("Content-Disposition","attachment;filename="+ URLEncoder.encode(fileName,"utf-8"));
|
|
|
+ }*/
|
|
|
+ byte[] car=new byte[1024];
|
|
|
+ int L=0;
|
|
|
+ while((L=in.read(car))!=-1){
|
|
|
+ out.write(car, 0,L);
|
|
|
+ }
|
|
|
+ if(out!=null){
|
|
|
+ out.flush();
|
|
|
+ out.close();
|
|
|
+ }
|
|
|
+ if(in!=null){
|
|
|
+ in.close();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传文件
|
|
|
+ * @param file
|
|
|
+ * @param dir 存放文件夹名称
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public FileUrlDto webUpload(MultipartFile file, String dir) throws IOException {
|
|
|
+ FileUrlDto dto = new FileUrlDto();
|
|
|
+ // 文件保存路径
|
|
|
+ String fileDir =directory+"/"+dir+ psiOssClientService.datePath()+"/"+ System.currentTimeMillis();
|
|
|
+ // 判断文件是否为空
|
|
|
+ if (!file.isEmpty()) {
|
|
|
+ String name = file.getOriginalFilename ();
|
|
|
+ psiOssClientService.uploadFile2OSS(file.getInputStream(), fileDir, name);
|
|
|
+ String url = fileDir +name;
|
|
|
+ String lsUrl = this.getFileTemporaryLookUrl(aliyunUrl + "/" + fileDir +name);
|
|
|
+ dto.setUrl(url);
|
|
|
+ dto.setLsUrl(lsUrl);
|
|
|
+ }
|
|
|
+ return dto;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存/修改附件
|
|
|
+ * @param fileList 要保存的附件,传空值则删除attachmentId下的所有附件
|
|
|
+ * @param attachmentId 附件的attachmentId
|
|
|
+ * @param attachmentFlag 附件的attachmentFlag
|
|
|
+ */
|
|
|
+ public void saveOrUpdateFileList(List<WorkAttachmentDto> fileList, String attachmentId, String attachmentFlag, String currentToken){
|
|
|
+// String currentToken = TokenProvider.getCurrentToken();
|
|
|
+
|
|
|
+ UserDTO userDTO = SpringUtil.getBean ( IUserApi.class ).getByToken (currentToken);
|
|
|
+ if (CollectionUtil.isNotEmpty(fileList)) {
|
|
|
+ List<String> ids = fileList.stream().filter(item -> {
|
|
|
+ if (StringUtils.isNotBlank(item.getId())) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }).map(WorkAttachmentDto::getId).collect(Collectors.toList());
|
|
|
+ if(CollectionUtil.isNotEmpty(ids)){
|
|
|
+ if(StringUtils.isNotBlank(attachmentFlag)){
|
|
|
+ psiOssServiceMapper.delete(new QueryWrapper<PsiWorkAttachment>().lambda()
|
|
|
+ .eq(PsiWorkAttachment::getAttachmentId, attachmentId)
|
|
|
+ .eq(PsiWorkAttachment::getAttachmentFlag, attachmentFlag)
|
|
|
+ .notIn(PsiWorkAttachment::getId,ids));
|
|
|
+ }else{
|
|
|
+ psiOssServiceMapper.delete(new QueryWrapper<PsiWorkAttachment>().lambda()
|
|
|
+ .eq(PsiWorkAttachment::getAttachmentId, attachmentId)
|
|
|
+ .notIn(PsiWorkAttachment::getId,ids));
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if(StringUtils.isNotBlank(attachmentFlag)){
|
|
|
+ psiOssServiceMapper.delete(new QueryWrapper<PsiWorkAttachment>().lambda()
|
|
|
+ .eq(PsiWorkAttachment::getAttachmentId, attachmentId)
|
|
|
+ .eq(PsiWorkAttachment::getAttachmentFlag, attachmentFlag));
|
|
|
+ }else{
|
|
|
+ psiOssServiceMapper.delete(new QueryWrapper<PsiWorkAttachment>().lambda()
|
|
|
+ .eq(PsiWorkAttachment::getAttachmentId, attachmentId));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<WorkAttachmentDto> dtoList = fileList.stream().filter(item -> {
|
|
|
+ if (StringUtils.isNotBlank(item.getId())) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ this.saveFileList(dtoList, userDTO, attachmentId,attachmentFlag);
|
|
|
+ } else {
|
|
|
+ if(StringUtils.isNotBlank(attachmentFlag)){
|
|
|
+ psiOssServiceMapper.delete(new QueryWrapper<PsiWorkAttachment>().lambda()
|
|
|
+ .eq(PsiWorkAttachment::getAttachmentId, attachmentId)
|
|
|
+ .eq(PsiWorkAttachment::getAttachmentFlag, attachmentFlag));
|
|
|
+ }else{
|
|
|
+ psiOssServiceMapper.delete(new QueryWrapper<PsiWorkAttachment>().lambda()
|
|
|
+ .eq(PsiWorkAttachment::getAttachmentId, attachmentId));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存/修改附件
|
|
|
+ * @param fileList 要保存的附件,传空值则删除attachmentId下attachmentFlag下的所有附件
|
|
|
+ * @param attachmentId 附件的attachmentId
|
|
|
+ * @param attachmentFlag 附件的attachmentFlag
|
|
|
+ */
|
|
|
+ public void saveOrUpdateFileListFlag(List<WorkAttachmentInfoDTO> fileList, String attachmentId, String attachmentFlag,String currentToken){
|
|
|
+
|
|
|
+// Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
|
|
+// String bearerToken = authentication.getCredentials().toString();
|
|
|
+
|
|
|
+ UserDTO userDTO = SpringUtil.getBean ( IUserApi.class ).getByToken (currentToken);
|
|
|
+ if (CollectionUtil.isNotEmpty(fileList)) {
|
|
|
+ List<String> ids = fileList.stream().filter(item -> {
|
|
|
+ if (StringUtils.isNotBlank(item.getId())) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }).map(WorkAttachmentInfoDTO::getId).collect(Collectors.toList());
|
|
|
+ if(CollectionUtil.isNotEmpty(ids)){
|
|
|
+ psiOssServiceMapper.delete(new QueryWrapper<PsiWorkAttachment>().lambda()
|
|
|
+ .eq(PsiWorkAttachment::getAttachmentId, attachmentId)
|
|
|
+ .eq(PsiWorkAttachment::getAttachmentFlag, attachmentFlag)
|
|
|
+ .notIn(PsiWorkAttachment::getId,ids));
|
|
|
+ }else{
|
|
|
+ psiOssServiceMapper.delete(new QueryWrapper<PsiWorkAttachment>().lambda()
|
|
|
+ .eq(PsiWorkAttachment::getAttachmentId, attachmentId)
|
|
|
+ .eq(PsiWorkAttachment::getAttachmentFlag, attachmentFlag));
|
|
|
+ }
|
|
|
+
|
|
|
+ List<WorkAttachmentInfoDTO> dtoList = fileList.stream().filter(item -> {
|
|
|
+ if (StringUtils.isNotBlank(item.getId())) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ this.saveFileList2(dtoList, userDTO, attachmentId,attachmentFlag);
|
|
|
+ } else {
|
|
|
+ psiOssServiceMapper.delete(new QueryWrapper<PsiWorkAttachment>().lambda().eq(PsiWorkAttachment::getAttachmentId, attachmentId).eq(PsiWorkAttachment::getAttachmentFlag, attachmentFlag));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存附件信息
|
|
|
+ * @param list 待保存的附件列表
|
|
|
+ * @param userDTO 当前登录用户
|
|
|
+ * @param attachmentId 关联id
|
|
|
+ */
|
|
|
+ public void saveFileList2(List<WorkAttachmentInfoDTO> list, UserDTO userDTO, String attachmentId,String attachmentFlag) {
|
|
|
+ int sort = 1;
|
|
|
+ for (WorkAttachmentInfoDTO dto : list) {
|
|
|
+ PsiWorkAttachment i = new PsiWorkAttachment();
|
|
|
+ //包含了url、size、name
|
|
|
+ i.setId(UUID.randomUUID().toString().replace("-", ""));
|
|
|
+// i.getCreateBy().setId(userDTO.getId());
|
|
|
+ i.setCreateTime(new Date());
|
|
|
+// i.getUpdateBy().setId(userDTO.getId());
|
|
|
+ i.setUpdateTime(new Date());
|
|
|
+ i.setDelFlag(0);
|
|
|
+ i.setUrl(dto.getUrl());
|
|
|
+ //文件类型处理
|
|
|
+ String fileName = dto.getName();
|
|
|
+ List<String> strings = Arrays.asList(fileName.split("\\."));
|
|
|
+ // 检查文件名是否有后缀
|
|
|
+ if (CollectionUtil.isNotEmpty(strings) && strings.size() > 1) {
|
|
|
+ // 获取最后一个部分作为文件类型
|
|
|
+ i.setType(strings.get(strings.size() - 1));
|
|
|
+ } else {
|
|
|
+ // 如果没有后缀或文件名无效,设置一个默认类型或空
|
|
|
+ i.setType("");
|
|
|
+ }
|
|
|
+ i.setAttachmentId(attachmentId);
|
|
|
+ i.setAttachmentName(dto.getName());
|
|
|
+ i.setAttachmentFlag(attachmentFlag);
|
|
|
+ i.setFileSize(dto.getSize());
|
|
|
+ i.setSort(sort);
|
|
|
+ psiOssServiceMapper.insertWorkAttachment(i, userDTO);
|
|
|
+ sort++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存附件信息
|
|
|
+ * @param list 待保存的附件列表
|
|
|
+ * @param userDTO 当前登录用户
|
|
|
+ * @param attachmentId 关联id
|
|
|
+ */
|
|
|
+ public void saveFileList(List<WorkAttachmentDto> list, UserDTO userDTO, String attachmentId,String attachmentFlag) {
|
|
|
+ int sort = 1;
|
|
|
+ for (WorkAttachmentDto dto : list) {
|
|
|
+ PsiWorkAttachment i = new PsiWorkAttachment();
|
|
|
+ //包含了url、size、name
|
|
|
+ i.setId(UUID.randomUUID().toString().replace("-", ""));
|
|
|
+// i.getCreateBy().setId(userDTO.getId());
|
|
|
+ i.setCreateTime(new Date());
|
|
|
+// i.getUpdateBy().setId(userDTO.getId());
|
|
|
+ i.setUpdateTime(new Date());
|
|
|
+ i.setDelFlag(0);
|
|
|
+ i.setUrl(dto.getUrl());
|
|
|
+ // 文件类型处理
|
|
|
+ String fileName = dto.getName();
|
|
|
+ List<String> strings = Arrays.asList(fileName.split("\\."));
|
|
|
+ // 检查文件名是否有后缀
|
|
|
+ if (CollectionUtil.isNotEmpty(strings) && strings.size() > 1) {
|
|
|
+ // 获取最后一个部分作为文件类型
|
|
|
+ i.setType(strings.get(strings.size() - 1));
|
|
|
+ } else {
|
|
|
+ // 如果没有后缀或文件名无效,设置一个默认类型或空
|
|
|
+ i.setType("");
|
|
|
+ }
|
|
|
+ i.setAttachmentId(attachmentId);
|
|
|
+ i.setAttachmentName(dto.getName());
|
|
|
+ i.setAttachmentFlag(attachmentFlag);
|
|
|
+ i.setFileSize(dto.getSize());
|
|
|
+ i.setSort(sort);
|
|
|
+ psiOssServiceMapper.insertWorkAttachment(i, userDTO);
|
|
|
+ sort++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存附件信息
|
|
|
+ * @param workAttachmentDto 待保存的附件信息
|
|
|
+ * @param userDTO 当前登录用户
|
|
|
+ * @param attachmentId 关联id
|
|
|
+ * @param attachmentFlag
|
|
|
+ * @param sort
|
|
|
+ */
|
|
|
+ public String saveFile(WorkAttachmentDto workAttachmentDto, UserDTO userDTO, String attachmentId,String attachmentFlag, Integer sort) {
|
|
|
+ PsiWorkAttachment i = new PsiWorkAttachment();
|
|
|
+ //包含了url、size、name
|
|
|
+ i.setId(UUID.randomUUID().toString().replace("-", ""));
|
|
|
+ i.setCreateTime(new Date());
|
|
|
+ i.setUpdateTime(new Date());
|
|
|
+ i.setDelFlag(0);
|
|
|
+ i.setUrl(workAttachmentDto.getUrl());
|
|
|
+ //文件类型处理
|
|
|
+ String fileName = workAttachmentDto.getName();
|
|
|
+ List<String> strings = Arrays.asList(fileName.split("\\."));
|
|
|
+ // 检查文件名是否有后缀
|
|
|
+ if (CollectionUtil.isNotEmpty(strings) && strings.size() > 1) {
|
|
|
+ // 获取最后一个部分作为文件类型
|
|
|
+ i.setType(strings.get(strings.size() - 1));
|
|
|
+ } else {
|
|
|
+ // 如果没有后缀或文件名无效,设置一个默认类型或空
|
|
|
+ i.setType("");
|
|
|
+ }
|
|
|
+ i.setAttachmentId(attachmentId);
|
|
|
+ i.setAttachmentName(workAttachmentDto.getName());
|
|
|
+ i.setAttachmentFlag(attachmentFlag);
|
|
|
+ i.setFileSize(workAttachmentDto.getSize());
|
|
|
+ i.setSort(sort);
|
|
|
+ psiOssServiceMapper.insertWorkAttachment(i, userDTO);
|
|
|
+ return i.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<WorkAttachmentInfo> selectWorkAttachmentByAttachmentId (String id){
|
|
|
+ return psiOssServiceMapper.selectWorkAttachmentByAttachmentId(id);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void deleteById(String id) {
|
|
|
+ psiOssServiceMapper.deleteById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据attachmentId删除附件
|
|
|
+ * @param attachmentId
|
|
|
+ */
|
|
|
+ public void deleteByAttachmentId(String attachmentId) {
|
|
|
+ psiOssServiceMapper.deleteByAttachmentId(attachmentId);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<WorkAttachmentInfo> selectListByAttachmentId(String attachmentId) {
|
|
|
+ return psiOssServiceMapper.selectListByAttachmentId(attachmentId);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<WorkAttachmentInfo> getByAttachmentIdAndUrlAndAttachmentFlag(WorkAttachmentInfo workattachment) {
|
|
|
+
|
|
|
+ return psiOssServiceMapper.getByAttachmentIdAndUrlAndAttachmentFlag(workattachment);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void deleteByAttachmentIdNotInIds(String attachmentId, List<String> delIds) {
|
|
|
+ psiOssServiceMapper.deleteByAttachmentIdNotInIds(attachmentId,delIds);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String,Object> downLoadFileDisposeXmlFile(String file) {
|
|
|
+ file = "http://oss.gangwaninfo.com" + file;
|
|
|
+ file = file.replace("amp;", "");
|
|
|
+ String fileName = file.substring(file.lastIndexOf("/") + 1, file.length());
|
|
|
+ String cons = "";
|
|
|
+ if (file.contains(aliyunUrl)) {
|
|
|
+ cons = aliyunUrl;
|
|
|
+ } else if (file.contains("http://gangwan-app.oss-cn-hangzhou.aliyuncs.com")) {
|
|
|
+ cons = "http://gangwan-app.oss-cn-hangzhou.aliyuncs.com";
|
|
|
+ } else {
|
|
|
+ cons = aliyunDownloadUrl;
|
|
|
+ }
|
|
|
+ String key = file.split(cons + "/")[1];
|
|
|
+ log.info("-----------------------------------------");
|
|
|
+ log.info("fileName=" + fileName);
|
|
|
+ log.info("key=" + key);
|
|
|
+ log.info("-----------------------------------------");
|
|
|
+
|
|
|
+ String path = null;
|
|
|
+ if(System.getProperty("os.name").toLowerCase().contains("win")){
|
|
|
+ path = "D:/attachment-file/";
|
|
|
+ }else{
|
|
|
+ path = "/attachment-file/";
|
|
|
+ }
|
|
|
+ psiOssClientService.downByStreamSaveLocal(key, fileName, path+fileName);
|
|
|
+
|
|
|
+ Map<String,Object> map = new HashMap();
|
|
|
+ //创建DOM4J解析器对象
|
|
|
+ File newFile = new File(path + fileName);
|
|
|
+ try {
|
|
|
+ //MultipartFile转File
|
|
|
+ //newFile = FileUtil.transformMultipartFile(file);
|
|
|
+ // 创建一个 DocumentBuilderFactory
|
|
|
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
|
|
+ // 使用工厂创建一个 DocumentBuilder
|
|
|
+ DocumentBuilder builder = factory.newDocumentBuilder();
|
|
|
+ // 使用 DocumentBuilder 解析 XML 文件
|
|
|
+ Document document = builder.parse(newFile);
|
|
|
+ // 获取所有header节点的集合
|
|
|
+ NodeList headerList = document.getElementsByTagName("Header");
|
|
|
+ // 获取所有eInvoiceDataList节点的集合
|
|
|
+ NodeList eInvoiceDataList = document.getElementsByTagName("EInvoiceData");
|
|
|
+ // 获取所有taxSupervisionInfo节点的集合
|
|
|
+ NodeList taxSupervisionInfoList = document.getElementsByTagName("TaxSupervisionInfo");
|
|
|
+
|
|
|
+ Map<String,String> map1 = xmlNodeListDataDispose(headerList, document);
|
|
|
+ Map<String,String> map2 = xmlNodeListDataDispose(eInvoiceDataList, document);
|
|
|
+ Map<String,String> map3 = xmlNodeListDataDispose(taxSupervisionInfoList, document);
|
|
|
+ map.putAll(map1);
|
|
|
+ map.putAll(map2);
|
|
|
+ map.putAll(map3);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }finally {
|
|
|
+ newFile.delete();
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 对节点集合进行遍历,并获取每个节点下的参数信息
|
|
|
+ * @param nodeList
|
|
|
+ * @param document
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String,String> xmlNodeListDataDispose(NodeList nodeList,Document document){
|
|
|
+ Map<String,String> map = new HashMap<>();
|
|
|
+ if(null != nodeList && nodeList.getLength()>0){
|
|
|
+ //遍历每一个header节点
|
|
|
+ for (int i = 0; i < nodeList.getLength(); i++) {
|
|
|
+ //通过 item(i)方法 获取一个header节点,nodelist的索引值从0开始
|
|
|
+ Node header = nodeList.item(i);
|
|
|
+ //解析定义节点的子节点
|
|
|
+ NodeList childNodes = header.getChildNodes();
|
|
|
+ //节点数据处理
|
|
|
+ Map<String,String> map1 = xmlDataDispose(childNodes, document);
|
|
|
+ map.putAll(map1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 子节点遍历获取参数,若其下还有子节点,则循环调用 xmlNodeListDataDispose 方法
|
|
|
+ * @param childNodes
|
|
|
+ * @param document
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String,String> xmlDataDispose(NodeList childNodes,Document document){
|
|
|
+ Map<String,String> map = new HashMap<>();
|
|
|
+ for (int k = 0; k < childNodes.getLength(); k++) {
|
|
|
+ // 区分出text类型的node以及element类型的node
|
|
|
+ if (childNodes.item(k).getNodeType() == Node.ELEMENT_NODE) {
|
|
|
+ Node firstChild = childNodes.item(k).getFirstChild();
|
|
|
+ if(null != firstChild){
|
|
|
+ if(StringUtils.isBlank(childNodes.item(k).getFirstChild().getNodeValue())){
|
|
|
+ // 获取所有header节点的集合
|
|
|
+ NodeList childList = document.getElementsByTagName(childNodes.item(k).getNodeName());
|
|
|
+
|
|
|
+ String parentName = childNodes.item(k).getNodeName();
|
|
|
+ //循环调用,获取最低级节点数据信息
|
|
|
+ Map<String,String> map1 = xmlNodeListDataDispose(childList, document);
|
|
|
+ Map<String,String> map2 = new HashMap<>();
|
|
|
+ if(map1.size()>0){
|
|
|
+ //将获取到的数据进行遍历,添加父节点的参数信息,防止子节点key键相同,导致数据被覆盖
|
|
|
+ for (String key : map1.keySet()) {
|
|
|
+ if(key.contains("-")){
|
|
|
+ String newKey = key.replaceAll("-","");
|
|
|
+ map2.put(parentName + newKey,map1.get(key));
|
|
|
+ }else{
|
|
|
+ map2.put(parentName + key,map1.get(key));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.putAll(map2);
|
|
|
+ }
|
|
|
+ //判定key 和value 值均存在,则进行储存,否则不进行储存
|
|
|
+ if(StringUtils.isNotBlank(childNodes.item(k).getNodeName()) && StringUtils.isNotBlank(childNodes.item(k).getFirstChild().getNodeValue())){
|
|
|
+ map.put(childNodes.item(k).getNodeName(),childNodes.item(k).getFirstChild().getNodeValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param attachmentIdList
|
|
|
+ * @param type 代表处理类型,不同类型代表不同的分公司的报销数据:1、评估;2、会计;3、ccpm;4、中审;5、咨询
|
|
|
+ */
|
|
|
+ public Map<String,String> disposeElectronicEngineeringInvoice(List<String> attachmentIdList, String type){
|
|
|
+ Map<String,String> map = new HashMap<>();
|
|
|
+ //首先获取所有数电发票报销信息
|
|
|
+ List<WorkAttachmentInfo> attachmentList = psiOssServiceMapper.getElectronicEngineeringInvoiceAttachmentList(attachmentIdList,"");
|
|
|
+ //遍历所有附件发票信息,并将其下载到本地固定文件夹,并对下载的文件进行数据解析
|
|
|
+ try{
|
|
|
+ for (WorkAttachmentInfo attachmentInfo : attachmentList) {
|
|
|
+ if(attachmentInfo.getUrl().contains(".xml")){
|
|
|
+ Map<String, Object> stringObjectMap = this.downLoadFileDisposeXmlFile(attachmentInfo.getUrl());
|
|
|
+ String invoiceNumber = (String) stringObjectMap.get("InvoiceNumber");
|
|
|
+ String buyerInformationBuyerName = (String) stringObjectMap.get("BuyerInformationBuyerName");
|
|
|
+ if(StringUtils.isNotBlank(invoiceNumber) && StringUtils.isNotBlank(buyerInformationBuyerName)){
|
|
|
+ map.put(invoiceNumber,buyerInformationBuyerName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.getMessage();
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param attachmentIdList
|
|
|
+ * @param type 代表处理类型,不同类型代表不同的分公司的报销数据:1、评估;2、会计;3、ccpm;4、中审;5、咨询
|
|
|
+ */
|
|
|
+ public Map<String,String> disposeElectronicEngineeringInvoiceNumber(List<String> attachmentIdList, String type){
|
|
|
+ Map<String,String> map = new HashMap<>();
|
|
|
+ //首先获取所有数电发票报销信息
|
|
|
+ List<WorkAttachmentInfo> attachmentList = psiOssServiceMapper.getElectronicEngineeringInvoiceAttachmentList(attachmentIdList,"");
|
|
|
+ //遍历所有附件发票信息,并将其下载到本地固定文件夹,并对下载的文件进行数据解析
|
|
|
+ try{
|
|
|
+ for (WorkAttachmentInfo attachmentInfo : attachmentList) {
|
|
|
+ if(attachmentInfo.getUrl().contains(".xml")){
|
|
|
+ Map<String, Object> stringObjectMap = this.downLoadFileDisposeXmlFile(attachmentInfo.getUrl());
|
|
|
+ if (stringObjectMap != null){
|
|
|
+ String invoiceNumber = (String) stringObjectMap.get("InvoiceNumber");
|
|
|
+ String buyerInformationBuyerName = (String) stringObjectMap.get("BuyerInformationBuyerName");
|
|
|
+ if(StringUtils.isNotBlank(invoiceNumber) && StringUtils.isNotBlank(buyerInformationBuyerName)){
|
|
|
+ map.put(invoiceNumber,attachmentInfo.getUrl());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.getMessage();
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据发票号查询该发票是否已经被报销
|
|
|
+ * @param invoiceNumber
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean isUsedByInvoiceNumber(String invoiceNumber) {
|
|
|
+ Integer data = psiOssServiceMapper.isUsedByInvoiceNumber(invoiceNumber);
|
|
|
+ if (data != 0){
|
|
|
+ //被报销
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询资质附件
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<WorkAttachmentInfoDTO> findAttachement(String id, String attachmentFlag) {
|
|
|
+ return psiOssServiceMapper.findDtos(id, attachmentFlag);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public List<WorkAttachmentInfo> getByAttachmentIdListAndFlag (List<String> ids){
|
|
|
+ return psiOssServiceMapper.getByAttachmentIdListAndFlag(ids);
|
|
|
+ }
|
|
|
+}
|