فهرست منبع

提交相关代码

Lijy 5 ماه پیش
والد
کامیت
53282073d3

+ 14 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/ExpenseSheetController.java

@@ -10,7 +10,9 @@ import com.management.platform.mapper.SysFunctionMapper;
 import com.management.platform.mapper.UserMapper;
 import com.management.platform.service.ExpensePayWayService;
 import com.management.platform.service.ExpenseSheetService;
+import com.management.platform.util.FileZipUtil;
 import com.management.platform.util.HttpRespMsg;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
@@ -18,6 +20,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import java.util.Arrays;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -44,6 +47,9 @@ public class ExpenseSheetController {
     @Resource
     ExpensePayWayService expensePayWayService;
 
+    @Value(value = "${upload.path}")
+    private String uploadPath;
+
     @RequestMapping("/getNextCode")
     public HttpRespMsg getNextCode() {
         String userId = request.getHeader("Token");
@@ -84,6 +90,14 @@ public class ExpenseSheetController {
         return expenseSheetService.getDetail(id,projectId);
 
     }
+    /**
+     * 导出
+     */
+    @RequestMapping("/export")
+    public void getExport(HttpServletResponse response) throws Exception {
+        FileZipUtil.exportZip(response,uploadPath , "报销凭证压缩包", ".zip");
+    }
+
 
     @RequestMapping("/approve")
     public HttpRespMsg approve(Integer id) {

+ 105 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/util/FileZipUtil.java

@@ -0,0 +1,105 @@
+package com.management.platform.util;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+import java.net.URLEncoder;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+public class FileZipUtil {
+
+    /**
+     * 将指定路径下的所有文件打包zip导出
+     * @param response HttpServletResponse
+     * @param sourceFilePath 需要打包的文件夹路径
+     * @param fileName 下载时的文件名称
+     * @param postfix 下载时的文件后缀 .zip/.rar
+     */
+    public static void exportZip(HttpServletResponse response, String sourceFilePath, String fileName, String postfix) {
+        // 默认文件名以时间戳作为前缀
+        if(StringUtils.isBlank(fileName)){
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
+            fileName = sdf.format(new Date());
+        }
+        String downloadName = fileName + postfix;
+        // 将文件进行打包下载
+        try {
+            OutputStream os = response.getOutputStream();
+            // 接收压缩包字节
+            byte[] data = createZip(sourceFilePath);
+            response.reset();
+            response.setCharacterEncoding("UTF-8");
+            response.addHeader("Access-Control-Allow-Origin", "*");
+            response.setHeader("Access-Control-Expose-Headers", "*");
+            // 下载文件名乱码问题
+            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(downloadName, "UTF-8"));
+            //response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + downloadName);
+            response.addHeader("Content-Length", "" + data.length);
+            response.setContentType("application/octet-stream;charset=UTF-8");
+            IOUtils.write(data, os);
+            os.flush();
+            os.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 创建zip文件
+     * @param sourceFilePath
+     * @return byte[]
+     * @throws Exception
+     */
+    private static byte[] createZip(String sourceFilePath) throws Exception{
+        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+        ZipOutputStream zip = new ZipOutputStream(outputStream);
+        // 将目标文件打包成zip导出
+        File file = new File(sourceFilePath);
+        handlerFile(zip, file,"");
+        // 无异常关闭流,它将无条件的关闭一个可被关闭的对象而不抛出任何异常。
+        IOUtils.closeQuietly(zip);
+        return outputStream.toByteArray();
+    }
+
+    /**
+     * 打包处理
+     * @param zip
+     * @param file
+     * @param dir
+     * @throws Exception
+     */
+    private static void handlerFile(ZipOutputStream zip, File file, String dir) throws Exception {
+        // 如果当前的是文件夹,则循环里面的内容继续处理
+        if (file.isDirectory()) {
+            //得到文件列表信息
+            File[] fileArray = file.listFiles();
+            if (fileArray == null) {
+                return;
+            }
+            //将文件夹添加到下一级打包目录
+            zip.putNextEntry(new ZipEntry(dir + "/"));
+            dir = dir.length() == 0 ? "" : dir + "/";
+            // 递归将文件夹中的文件打包
+            for (File f : fileArray) {
+                handlerFile(zip, f, dir + f.getName());
+            }
+        } else {
+            // 如果当前的是文件,打包处理
+            BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
+            ZipEntry entry = new ZipEntry(dir);
+            zip.putNextEntry(entry);
+            zip.write(FileUtils.readFileToByteArray(file));
+            IOUtils.closeQuietly(bis);
+            zip.flush();
+            zip.closeEntry();
+        }
+    }
+
+
+}

+ 6 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/service/impl/ReportServiceImpl.java

@@ -4363,6 +4363,12 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
         List<Map<String,Object>> mapListTempReport=reportMapper.getPersonWorkHoursWagesDetailForTemp(date,userId,user.getCompanyId(),startDate,endDate);
         mapListTempReport.forEach(m->{
             m.put("colorType","green");
+            if (m.get("planExtraInfoId")!=null && m.get("operationName")!=null){
+                m.put("procedureName",m.get("operationName"));
+            }
+            if (m.get("planExtraInfoId")!=null && m.get("partName")!=null){
+                m.put("productName",m.get("partName"));
+            }
         });
         mapListHasReport.addAll(mapListTempReport);
         mapListHasReport.addAll(mapListNoReport);

+ 3 - 1
fhKeeper/formulahousekeeper/management-workshop/src/main/resources/mapper/ReportMapper.xml

@@ -194,10 +194,12 @@
     <select id="getPersonWorkHoursWagesDetailForTemp" resultType="java.util.Map">
         select r.cost,(r.working_time*60) as working_time,r.finish_num, r.creator_id,DATE_FORMAT(r.create_date,'%Y%m%d') as createDate,
         p.name as productName,DATE_FORMAT(plan.start_date,'%Y%m%d') as planStartDate,DATE_FORMAT(plan.end_date,'%Y%m%d') as planEndDate ,
-        plan.task_change_notice_num as taskChangeNoticeNum,plan.plan_type as planType,u.name as checkerName,u2.name as creatorName,plan.task_name as taskName,plan.task_type_name
+        plan.task_change_notice_num as taskChangeNoticeNum,plan.plan_type as planType,u.name as checkerName,u2.name as creatorName,plan.task_name as taskName,plan.task_type_name,
+        pei.id planExtraInfoId,pei.operation_name operationName,pei.part_name partName,plan.product_scheduling_num,plan.num finishNum
         from report r
         left join product p on p.id=r.product_id
         left join plan on plan.id=r.plan_id
+        left join plan_extra_info pei on pei.report_id=r.id
         left join user u on r.checker_id=u.id
         left join user u2 on r.creator_id=u2.id
         where r.company_id=#{companyId}  and r.user_procedure_team_id is null