Procházet zdrojové kódy

用户导入,公司LOGO与名称开发

anderx před 2 roky
rodič
revize
e5ff863767

+ 13 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/project/ProjectTaskController.java

@@ -6,7 +6,9 @@ import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.page.TableDataInfo;
 import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.file.FileUploadUtils;
 import com.ruoyi.common.utils.file.MimeTypeUtils;
 import com.ruoyi.common.utils.poi.ExcelUtil;
@@ -29,8 +31,11 @@ import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.util.Date;
 import java.util.List;
+import java.util.zip.ZipOutputStream;
 
 /**
  *  项目管理
@@ -409,4 +414,12 @@ public class ProjectTaskController extends BaseController {
         }
         return projectTaskService.selectProjectImg(pid);
     }
+    @GetMapping("/download")
+    public void downloadFiles(HttpServletResponse response,String ids) throws IOException {
+        if (StringUtils.isEmpty(ids)){
+            throw new ServiceException("编号不能为空");
+        }
+        projectStaffRecordService.downloadFiles(ids, response);
+
+    }
 }

+ 6 - 0
ruoyi-common/pom.xml

@@ -129,6 +129,12 @@
             <groupId>org.apache.httpcomponents</groupId>
             <artifactId>httpasyncclient</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.mchange</groupId>
+            <artifactId>mchange-commons-java</artifactId>
+            <version>0.2.15</version>
+            <scope>compile</scope>
+        </dependency>
 
     </dependencies>
 

+ 1 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java

@@ -27,6 +27,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
     public static String YYYY_MM = "yyyy-MM";
 
     public static String YYYY_MM_DD = "yyyy-MM-dd";
+    public static String YYYYMMDD = "yyyyMMdd";
 
     public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
 

+ 25 - 16
ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java

@@ -1,16 +1,12 @@
 package com.ruoyi.common.utils.file;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
+import java.io.*;
 import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+
+import com.mchange.v1.io.InputStreamUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.ArrayUtils;
 import com.ruoyi.common.config.RuoYiConfig;
@@ -21,7 +17,7 @@ import org.apache.commons.io.FilenameUtils;
 
 /**
  * 文件处理工具类
- * 
+ *
  * @author ruoyi
  */
 public class FileUtils
@@ -30,7 +26,7 @@ public class FileUtils
 
     /**
      * 输出指定文件的byte数组
-     * 
+     *
      * @param filePath 文件路径
      * @param os 输出流
      * @return
@@ -105,7 +101,7 @@ public class FileUtils
 
     /**
      * 删除文件
-     * 
+     *
      * @param filePath 文件
      * @return
      */
@@ -123,7 +119,7 @@ public class FileUtils
 
     /**
      * 文件名称验证
-     * 
+     *
      * @param filename 文件名称
      * @return true 正常 false 非法
      */
@@ -134,7 +130,7 @@ public class FileUtils
 
     /**
      * 检查文件是否可下载
-     * 
+     *
      * @param resource 需要下载的文件
      * @return true 正常 false 非法
      */
@@ -158,7 +154,7 @@ public class FileUtils
 
     /**
      * 下载文件名重新编码
-     * 
+     *
      * @param request 请求对象
      * @param fileName 文件名
      * @return 编码后的文件名
@@ -228,7 +224,7 @@ public class FileUtils
 
     /**
      * 获取图像后缀
-     * 
+     *
      * @param photoByte 图像数据
      * @return 后缀名
      */
@@ -257,7 +253,7 @@ public class FileUtils
 
     /**
      * 获取文件名称 /profile/upload/2022/04/16/ruoyi.png -- ruoyi.png
-     * 
+     *
      * @param fileName 路径名称
      * @return 没有文件路径的名称
      */
@@ -275,7 +271,7 @@ public class FileUtils
 
     /**
      * 获取不带后缀文件名称 /profile/upload/2022/04/16/ruoyi.png -- ruoyi
-     * 
+     *
      * @param fileName 路径名称
      * @return 没有文件路径和后缀的名称
      */
@@ -288,4 +284,17 @@ public class FileUtils
         String baseName = FilenameUtils.getBaseName(fileName);
         return baseName;
     }
+
+    public static byte[] getBytes(File file) throws IOException {
+        BufferedInputStream var1 = new BufferedInputStream(new FileInputStream(file));
+
+        byte[] var2;
+        try {
+            var2 = InputStreamUtils.getBytes(var1);
+        } finally {
+            InputStreamUtils.attemptClose(var1);
+        }
+
+        return var2;
+    }
 }

+ 3 - 0
ruoyi-system/src/main/java/com/ruoyi/project/service/ProjectStaffRecordService.java

@@ -6,6 +6,7 @@ import com.ruoyi.project.bo.ProjectStaffRecordOut;
 import com.ruoyi.project.domain.ProjectStaffRecord;
 import com.ruoyi.project.domain.ProjectStaffRecordLog;
 
+import javax.servlet.http.HttpServletResponse;
 import java.util.List;
 
 public interface ProjectStaffRecordService {
@@ -30,4 +31,6 @@ public interface ProjectStaffRecordService {
     AjaxResult recordDetails(Long id);
 
     AjaxResult listRecordLog(ProjectStaffRecordLog in);
+
+    void downloadFiles(String ids, HttpServletResponse response);
 }

+ 2 - 0
ruoyi-system/src/main/java/com/ruoyi/project/service/ProjectTaskService.java

@@ -5,6 +5,7 @@ import com.ruoyi.project.bo.ProjectListInput;
 import com.ruoyi.project.bo.ProjectTaskListOut;
 import com.ruoyi.project.domain.ProjectTask;
 
+import javax.servlet.http.HttpServletResponse;
 import java.util.List;
 
 public interface ProjectTaskService {
@@ -23,4 +24,5 @@ public interface ProjectTaskService {
     AjaxResult selectProjectImg(Long pid);
 
     boolean checkProjectNumber(ProjectTask projectTask);
+
 }

+ 66 - 1
ruoyi-system/src/main/java/com/ruoyi/project/service/impl/ProjectStaffRecordServiceImpl.java

@@ -11,6 +11,7 @@ import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.bean.BeanValidators;
+import com.ruoyi.common.utils.file.FileUtils;
 import com.ruoyi.project.bo.MyMonthDays;
 import com.ruoyi.project.bo.ProjectStaffRecordInput;
 import com.ruoyi.project.bo.ProjectStaffRecordOut;
@@ -25,18 +26,25 @@ import com.ruoyi.system.mapper.SysUserMapper;
 import com.ruoyi.system.service.ISysDeptService;
 import com.ruoyi.system.service.impl.SysConfigServiceImpl;
 import com.ruoyi.weChat.service.WeChatService;
+import org.apache.commons.io.IOUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.servlet.http.HttpServletResponse;
 import javax.validation.Validator;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
 import java.math.BigDecimal;
-import java.time.Duration;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicReference;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
 
 @Service
 public class ProjectStaffRecordServiceImpl implements ProjectStaffRecordService {
@@ -176,6 +184,63 @@ public class ProjectStaffRecordServiceImpl implements ProjectStaffRecordService
         return AjaxResult.success(projectStaffRecordLogMapper.selectByPsrId(in.getPsrId()));
     }
 
+    @Override
+    public void downloadFiles(String ids, HttpServletResponse response) {
+        String downloadFileName = "";
+        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+        ZipOutputStream zip = new ZipOutputStream(outputStream);
+        downloadFileName="项目打卡数据_"+DateUtils.dateTimeNow()+".zip";
+        String[] idList = ids.split(",");
+        for (String id : idList) {
+            ProjectStaffRecord psr = projectStaffRecordMapper.selectByPrimaryKey(Long.valueOf(id));
+            if (psr != null) {
+                ProjectTask projectTask = projectTaskMapper.selectByPrimaryKey(psr.getPid());
+                String annexUrl = psr.getAnnexUrl();
+                String[] split = annexUrl.split(",");
+                if (split.length>0){
+                    String recordTimes=DateUtils.parseDateToStr(DateUtils.YYYYMMDD,psr.getRecordTime());
+                    int index =0;
+                    for (String s : split) {
+                        if (StringUtils.isNotEmpty(s)){
+                            index++;
+                            String url=s.replace("/profile/upload","");
+                            url=RuoYiConfig.getUploadPath()+url;
+                            System.out.println(url);
+                            File file = new File(url);
+                            if (file.exists()){
+                                try {
+                                    String suffix = s.substring(s.indexOf("."), s.length());
+                                    String fileName=projectTask.getName()+"_"+psr.getName()+"_"+recordTimes+"_"+index+suffix;
+                                    ZipEntry e = new ZipEntry(fileName);
+                                    zip.putNextEntry(e);
+                                    IOUtils.write(FileUtils.getBytes(file),zip);
+                                    zip.closeEntry();
+                                    zip.flush();
+                                } catch (IOException e){
+                                    throw  new ServiceException("文件写入压缩失败:"+e.getLocalizedMessage());
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        IOUtils.closeQuietly(zip);
+        try {
+            byte[] data = outputStream.toByteArray();
+            response.reset();
+            response.addHeader("Access-Control-Allow-Origin", "*");
+            response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
+            response.setHeader("Content-Disposition", "attachment; filename=\"" + java.net.URLEncoder.encode(downloadFileName, "utf-8").replaceAll("\\+", "%20") + "\"");
+            response.addHeader("Content-Length", "" + data.length);
+            response.setContentType("application/octet-stream; charset=UTF-8");
+            IOUtils.write(data,response.getOutputStream());
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+
     /**
      *
      * @param date 当前时间

+ 6 - 0
ruoyi-system/src/main/java/com/ruoyi/project/service/impl/ProjectTaskServiceImpl.java

@@ -26,8 +26,11 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.servlet.http.HttpServletResponse;
 import javax.validation.Validator;
+import java.io.ByteArrayOutputStream;
 import java.util.List;
+import java.util.zip.ZipOutputStream;
 
 @Service
 public class ProjectTaskServiceImpl   implements ProjectTaskService {
@@ -244,6 +247,9 @@ public class ProjectTaskServiceImpl   implements ProjectTaskService {
         return false;
     }
 
+
+
+
     private void addStaffAndDelete(  ProjectTaskListOut p) {
         String[] split = p.getStaffName().split(",");
         List<ProjectStaff> projectStaffs = projectStaffMapper.selectByPid(p.getId());