Bläddra i källkod

修改发票管理逻辑

y 2 år sedan
förälder
incheckning
b9b57d4ec6

+ 9 - 5
src/main/java/com/ydtech/modules/inv/controller/InvAccountController.java

@@ -31,11 +31,16 @@ public class InvAccountController {
     private InvAccountCardService invAccountCardService;
 
     @PostMapping("excel")
-    @ApiOperation("导出账户信息")
-    public HttpResult selectAccountExcel(@RequestBody InvAccountQueryVo invAccountQueryVo) {
+    @ApiOperation("费用支出明细导出")
+    public HttpResult excel(@RequestBody InvAccountQueryVo invAccountQueryVo) {
         return invAccountService.selectAccountExcel(invAccountQueryVo);
     }
 
+    @PostMapping("accountExcel")
+    @ApiOperation("费用支出明细导出")
+    public HttpResult accountExcel(@RequestBody InvAccountQueryVo invAccountQueryVo) {
+        return invAccountService.selectAccountList(invAccountQueryVo);
+    }
 
 
     @ApiOperation("获取账户列表")
@@ -45,7 +50,6 @@ public class InvAccountController {
     }
 
 
-
     @ApiOperation("查询账户卡列表")
     @PostMapping("getAccountCardList")
     public HttpResult getInsAccountCardList(@RequestBody InvAccountCard invAccountCard) {
@@ -83,9 +87,9 @@ public class InvAccountController {
             throw new RuntimeException("卡号为空");
         }
 
-        if (invAccountCardService.removeById(bankCardNum)){
+        if (invAccountCardService.removeById(bankCardNum)) {
             return HttpResult.ok("删除成功");
-        }else {
+        } else {
             return HttpResult.error("删除失败");
         }
     }

+ 1 - 3
src/main/java/com/ydtech/modules/inv/dao/InvAccountMapper.java

@@ -1,10 +1,8 @@
 package com.ydtech.modules.inv.dao;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+
 import com.ydtech.modules.inv.model.InvAccount;
-import com.ydtech.modules.inv.model.excel.AccountExcel;
 import com.ydtech.modules.inv.model.vo.InvAccountQueryVo;
 import org.apache.ibatis.annotations.Param;
 

+ 4 - 0
src/main/java/com/ydtech/modules/inv/model/InvAccountOperate.java

@@ -151,6 +151,10 @@ public class InvAccountOperate implements Serializable {
     @TableField(exist = false)
     private String enterCardId;
 
+    @ApiModelProperty(value = "外部转内部需携带转入银行卡id")
+    @TableField(exist = false)
+    private String outCardId;
+
 
     @ApiModelProperty("支出方利润归属")
     @TableField(value = "out_profit", typeHandler = FastjsonTypeHandler.class)

+ 23 - 4
src/main/java/com/ydtech/modules/inv/model/excel/AccountExcel.java

@@ -7,6 +7,7 @@ import com.alibaba.excel.enums.poi.BorderStyleEnum;
 import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum;
 import com.alibaba.excel.enums.poi.VerticalAlignmentEnum;
 import com.google.gson.JsonObject;
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 import java.io.Serializable;
@@ -19,19 +20,37 @@ import java.io.Serializable;
 public class AccountExcel implements Serializable {
 
 
+    @ExcelProperty("编号")
     private String accountId;
 
     /**
      * 开户行名称
      */
+    @ExcelProperty("开户行名称")
     private String bankName;
 
+    //营业性质(3一般纳税 2小规模 1个体户)
+    @ExcelProperty(value = "营业性质")
+    private String businessQuality;
+
+    @ExcelProperty(value = "所属地")
+    private String owned;
+
+    @ExcelProperty("成立日期")
+    private String establishTime;
+
+    @ExcelProperty("总开票额度")
+    private String sumInvoicingAmount;
+
+    @ExcelProperty("季度开票额度剩余")
+    private String quarterAmountExcess;
+
+    @ExcelProperty("剩余开票额度")
+    private String invoicingAmountExcess;
+
     /**
      * 余额
      */
+    @ExcelProperty("余额")
     private String balance;
-
-    private String money;
-
-    private JsonObject profitName;
 }

+ 2 - 0
src/main/java/com/ydtech/modules/inv/service/InvAccountService.java

@@ -23,4 +23,6 @@ public interface InvAccountService extends IService<InvAccount> {
     HttpResult selectByAccountName();
 
     HttpResult selectAccountExcel(InvAccountQueryVo invAccountQueryVo);
+
+    HttpResult selectAccountList(InvAccountQueryVo invAccountQueryVo);
 }

+ 9 - 9
src/main/java/com/ydtech/modules/inv/service/impl/InvAccountOperateServiceImpl.java

@@ -89,11 +89,15 @@ public class InvAccountOperateServiceImpl extends ServiceImpl<InvAccountOperateM
     @Override
     public HttpResult insert(InvAccountOperate invAccountOperate) {
         InvAccountCard enterAccount = invAccountCardService.getById(invAccountOperate.getEnterCardId());
-        InvAccountCard invAccount = outsideTransfer(enterAccount, invAccountOperate);
-        InvAccount account = invAccountService.getById(invAccount.getAccountId());
+        InvAccountCard outAccount = invAccountCardService.getById(invAccountOperate.getOutCardId());
 
-        if (!invAccountCardService.updateById(invAccount)){
+        InvAccount account = invAccountService.getById(enterAccount.getAccountId());
+        InvAccountCard invAccount = new InvAccountCard();
+        if (account.getOuterFlag().equals("0") || !enterAccount.getAccountId().equals(outAccount.getAccountId())){
+            invAccount = outsideTransfer(enterAccount, invAccountOperate);
+        }
 
+        if (!invAccountCardService.updateById(invAccount)){
             return HttpResult.error("新增收入失败");
         }
         invAccountOperate.setCreateTime(LocalDateTime.now());
@@ -118,10 +122,6 @@ public class InvAccountOperateServiceImpl extends ServiceImpl<InvAccountOperateM
         List<InvAccountOperate> invAccountOperates = insAccountOperateMapper.selectInsAccountOperateList(accountOperate);
         List<InvAccountProfit> list = invAccountProfitService.list();
 
-
-
-
-
         for (InvAccountOperate record:invAccountOperates){
             StringBuilder a = new StringBuilder();
             if (record.getPayMethod() != null){
@@ -147,10 +147,10 @@ public class InvAccountOperateServiceImpl extends ServiceImpl<InvAccountOperateM
         }
         File folder = new File(uploadFilePath);
         if (folder.exists()){
-            return HttpResult.ok("", EasyExcelUtils.downExcel(uploadFilePath, InvAccountOperate.class, invAccountOperates));
+            return HttpResult.ok("", EasyExcelUtils.noModelOperateWrite(uploadFilePath, list,invAccountOperates));
         }else {
             if (folder.mkdirs()){
-                return HttpResult.ok("", EasyExcelUtils.downExcel(uploadFilePath, InvAccountOperate.class, invAccountOperates));
+                return HttpResult.ok("", EasyExcelUtils.noModelOperateWrite(uploadFilePath, list,invAccountOperates));
             }else {
                 throw new SystemException("文件导出失败");
             }

+ 111 - 12
src/main/java/com/ydtech/modules/inv/service/impl/InvAccountServiceImpl.java

@@ -1,22 +1,22 @@
 package com.ydtech.modules.inv.service.impl;
 
+import com.alibaba.excel.annotation.format.DateTimeFormat;
 import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ydtech.core.page.HttpResult;
 import com.ydtech.core.page.PageRequest;
 import com.ydtech.exception.SystemException;
 import com.ydtech.modules.inv.dao.InvAccountMapper;
-import com.ydtech.modules.inv.dao.InvAccountOperateMapper;
 import com.ydtech.modules.inv.model.*;
 import com.ydtech.modules.inv.model.excel.AccountExcel;
 import com.ydtech.modules.inv.model.vo.InvAccountQueryVo;
-import com.ydtech.modules.inv.service.InvAccountCardService;
 import com.ydtech.modules.inv.service.InvAccountOpService;
 import com.ydtech.modules.inv.service.InvAccountProfitService;
 import com.ydtech.modules.inv.service.InvAccountService;
 import com.ydtech.modules.inv.utils.EasyExcelUtils;
 import com.ydtech.modules.inv.utils.LocalDateTimeUtils;
+import net.sf.cglib.core.Local;
+import org.joda.time.LocalDateTime;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
@@ -24,8 +24,6 @@ import org.springframework.stereotype.Service;
 import java.io.File;
 import java.math.BigDecimal;
 import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.temporal.TemporalAdjusters;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
@@ -84,9 +82,11 @@ public class InvAccountServiceImpl extends ServiceImpl<InvAccountMapper, InvAcco
                             if (ord.getInvoicingAmountExcess() != null) {
 
                                 rel.setQuarterAmountExcess(new BigDecimal("300000").subtract(new BigDecimal("5000000").subtract(new BigDecimal(ord.getInvoicingAmountExcess()))).toString());
+                                rel.setSumInvoicingAmount("0");
                             } else {
                                 if (!rel.getBusinessQuality().equals("0")) {
                                     rel.setQuarterAmountExcess("300000");
+                                    rel.setSumInvoicingAmount("0");
                                 }
                             }
                             return rel;
@@ -102,7 +102,7 @@ public class InvAccountServiceImpl extends ServiceImpl<InvAccountMapper, InvAcco
                         .map(ord -> {
                             if (ord.getSumInvoicingAmount() != null) {
 
-                                rel.setSumInvoicingAmount(new BigDecimal(ord.getSumInvoicingAmount()).add(new BigDecimal(ord.getSumInvoicingAmount())).toString());
+                                rel.setSumInvoicingAmount(new BigDecimal(rel.getSumInvoicingAmount()).add(new BigDecimal(ord.getSumInvoicingAmount())).toString());
 
                             }
                             return rel;
@@ -165,17 +165,116 @@ public class InvAccountServiceImpl extends ServiceImpl<InvAccountMapper, InvAcco
         List<InvAccountOp> list = invAccountOpService.list();
 
         File folder = new File(uploadFilePath);
-        if (folder.exists()){
-            return HttpResult.ok("",EasyExcelUtils.noModelWrite(uploadFilePath, invAccountProfitList, insAccounts, list));
-        }else {
-            if (folder.mkdirs()){
-                return HttpResult.ok( "",EasyExcelUtils.noModelWrite(uploadFilePath, invAccountProfitList, insAccounts, list));
-            }else {
+        if (folder.exists()) {
+            return HttpResult.ok("", EasyExcelUtils.noModelWrite(uploadFilePath, invAccountProfitList, insAccounts, list));
+        } else {
+            if (folder.mkdirs()) {
+                return HttpResult.ok("", EasyExcelUtils.noModelWrite(uploadFilePath, invAccountProfitList, insAccounts, list));
+            } else {
                 throw new SystemException("文件导出失败");
             }
         }
     }
 
+    @Override
+    public HttpResult selectAccountList(InvAccountQueryVo invAccountQueryVo) {
+        invAccountQueryVo.setInvoiceTimeStart(LocalDateTimeUtils.get12MonthsBefore()); // 获取12月前月的第一天
+        invAccountQueryVo.setInvoiceTimeEnd(LocalDateTimeUtils.getTodayLastDay());  //获取当前月最后一天
+
+
+        List<InvAccount> invAccountIPage = insAccountMapper.selectAccountsListPage(invAccountQueryVo);
+
+
+        //计算当前季度剩余300000减去
+        invAccountQueryVo.setInvoiceTimeStart(LocalDateTimeUtils.quarterStartTime());
+        invAccountQueryVo.setInvoiceTimeEnd(LocalDateTimeUtils.quarterEndTime());
+        List<InvAccount> invAccountIPage1 = insAccountMapper.selectAccountsListPage(invAccountQueryVo);
+
+        //将当前季度额度赋值
+        List<InvAccount> collect = invAccountIPage.stream()
+                .map(rel -> invAccountIPage1.stream()
+                        .filter(ord -> Objects.equals(rel.getAccountId(), ord.getAccountId()))
+                        .findFirst()
+                        .map(ord -> {
+                            if (ord.getInvoicingAmountExcess() != null) {
+
+                                rel.setQuarterAmountExcess(new BigDecimal("300000").subtract(new BigDecimal("5000000").subtract(new BigDecimal(ord.getInvoicingAmountExcess()))).toString());
+                                rel.setSumInvoicingAmount("0");
+                            } else {
+                                if (!rel.getBusinessQuality().equals("0")) {
+                                    rel.setQuarterAmountExcess("300000");
+                                    rel.setSumInvoicingAmount("0");
+                                }
+                            }
+                            return rel;
+                        }).orElse(null)
+                ).collect(Collectors.toList());
+
+        //将总开票额度赋值
+        List<InvAccount> sumInvoicingAmount = insAccountMapper.getSumInvoicingAmount(invAccountQueryVo);
+        List<InvAccount> collect1 = collect.stream()
+                .map(rel -> sumInvoicingAmount.stream()
+                        .filter(ord -> Objects.equals(rel.getAccountId(), ord.getAccountId()))
+                        .findFirst()
+                        .map(ord -> {
+                            if (ord.getSumInvoicingAmount() != null) {
+                                rel.setSumInvoicingAmount(new BigDecimal(rel.getSumInvoicingAmount()).add(new BigDecimal(ord.getSumInvoicingAmount())).toString());
+                            }
+                            return rel;
+                        }).orElse(null)
+                ).collect(Collectors.toList());
+
+
+        collect1.forEach(invAccount -> {
+            if (invAccount != null) {
+                if (invAccount.getInvAccountCardList().size() < 2) {
+                    if (invAccount.getInvAccountCardList().get(0).getBankCardNum() == null) {
+                        invAccount.setInvAccountCardList(null);
+                    }
+                }
+                if (invAccount.getBusinessQuality().equals("3")) {
+                    invAccount.setQuarterAmountExcess(null);
+                    invAccount.setSumInvoicingAmount(null);
+                    invAccount.setInvoicingAmountExcess(null);
+                }
+            }
+        });
+
+        List<AccountExcel> accountExcels = new ArrayList<>();
+
+        collect1.forEach(invAccount -> {
+            if (invAccount.getInvAccountCardList() != null){
+                invAccount.getInvAccountCardList().forEach(invAccountCard -> {
+                    AccountExcel accountExcel = new AccountExcel();
+                    accountExcel.setAccountId(invAccount.getAccountId());
+                    accountExcel.setBankName(invAccountCard.getBankName());
+                   if (invAccount.getBusinessQuality() != null){
+                       if (invAccount.getBusinessQuality().equals("3")){
+                           accountExcel.setBusinessQuality("一般纳税");
+                       }else if (invAccount.getBusinessQuality().equals("1")){
+                           accountExcel.setBusinessQuality("小规模");
+                       }else if (invAccount.getBusinessQuality().equals("2")){
+                           accountExcel.setBusinessQuality("小规模");
+                       }
+                   }
+                    accountExcel.setOwned(invAccount.getOwned());
+                    if (invAccount.getEstablishTime() != null){
+                        LocalDateTime establishTime = LocalDateTime.fromDateFields(invAccount.getEstablishTime());
+                        accountExcel.setEstablishTime(establishTime.toString().substring(0,establishTime.toString().indexOf("T")));
+                    }
+                    accountExcel.setSumInvoicingAmount(invAccount.getSumInvoicingAmount());
+                    accountExcel.setQuarterAmountExcess(invAccount.getQuarterAmountExcess());
+                    accountExcel.setInvoicingAmountExcess(invAccount.getInvoicingAmountExcess());
+                    accountExcel.setBalance(invAccountCard.getBalance());
+                    accountExcels.add(accountExcel);
+                });
+            }
+        });
+
+
+        return HttpResult.ok("", EasyExcelUtils.downExcel(uploadFilePath, AccountExcel.class, accountExcels));
+    }
+
 }
 
 

+ 110 - 8
src/main/java/com/ydtech/modules/inv/utils/EasyExcelUtils.java

@@ -10,13 +10,18 @@ import com.ydtech.modules.inv.model.excel.InvSourceExcel;
 import com.ydtech.modules.inv.service.InvAccountExcelService;
 import com.ydtech.modules.inv.utils.excel.InvSettlementSourceDataListener;
 import com.ydtech.modules.inv.utils.excel.InvSourceDataListener;
+import org.aspectj.weaver.ast.Literal;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.io.File;
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
+import java.time.LocalDate;
 import java.util.*;
 
+import static cn.com.zfc.day018.ZipMultiFile.zipFiles;
+
 /**
  * @author jianlong
  * @date 2023-12-29 16:46
@@ -49,16 +54,19 @@ public class EasyExcelUtils {
     }
 
     private static List<List<String>> head(List<InvAccountProfit> invAccountProfitList) {
-        List<List<String>> list = new ArrayList<>(3 + invAccountProfitList.size());
+        List<List<String>> list = new ArrayList<>(4 + invAccountProfitList.size());
+        List<String> head = ListUtils.newArrayList();
+        head.add("账户性质");
         List<String> head1 = ListUtils.newArrayList();
         head1.add("户名");
         List<String> head2 = ListUtils.newArrayList();
         head2.add("开户银行");
         List<String> head3 = ListUtils.newArrayList();
         head3.add("银行卡余额");
-        list.add(0, head1);
-        list.add(1, head2);
-        list.add(2, head3);
+        list.add(0,head);
+        list.add(1, head1);
+        list.add(2, head2);
+        list.add(3, head3);
         invAccountProfitList.forEach(invAccountProfit -> {
             List<String> head0 = ListUtils.newArrayList();
             head0.add(invAccountProfit.getProfitName());
@@ -69,12 +77,15 @@ public class EasyExcelUtils {
         return list;
     }
 
+
+
     private static List<List<Object>> dataList(List<InvAccount> invAccounts, List<InvAccountOp> invAccountOpList, List<InvAccountProfit> invAccountProfitList) {
         List<List<Object>> list = ListUtils.newArrayList();
         invAccounts.forEach(invAccount -> {
             List<Object> data = ListUtils.newArrayList();
             invAccount.getInvAccountCardList().forEach(invAccountCard -> {
                 if (invAccountCard.getBankCardNum() != null) {
+                    data.add(invAccount.getOuterFlag().equals("0")?"内部账户":"外部账户");
                     data.add(invAccount.getAccountName());
                     data.add(invAccountCard.getBankName());
                     data.add(invAccountCard.getBalance());
@@ -97,6 +108,89 @@ public class EasyExcelUtils {
     }
 
 
+
+    /**
+     * 不创建对象的写
+     */
+    public static String noModelOperateWrite(String uploadFilePath, List<InvAccountProfit> invAccountProfitList, List<InvAccountOperate> invAccountOperates) {
+        // 写法1
+        String file = System.currentTimeMillis() + ".xlsx";
+        String fileName = uploadFilePath + file;
+        // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
+        EasyExcel.write(fileName).head(operateHead(invAccountProfitList)).sheet("1").doWrite(operatedataList(invAccountOperates, invAccountProfitList));
+        return file;
+    }
+
+    private static List<List<String>> operateHead(List<InvAccountProfit> invAccountProfitList) {
+        List<List<String>> list = new ArrayList<>(7 + invAccountProfitList.size());
+        List<String> head = ListUtils.newArrayList();
+        head.add("支出时间");
+        List<String> head1 = ListUtils.newArrayList();
+        head1.add("部门");
+        List<String> head2 = ListUtils.newArrayList();
+        head2.add("支出方");
+        List<String> head3 = ListUtils.newArrayList();
+        head3.add("收入方");
+        List<String> head4 = ListUtils.newArrayList();
+        head4.add("支出项目");
+        List<String> head5 = ListUtils.newArrayList();
+        head5.add("分项");
+        List<String> head6 = ListUtils.newArrayList();
+        head6.add("支出金额");
+
+        list.add(0,head);
+        list.add(1, head1);
+        list.add(2, head2);
+        list.add(3, head3);
+        list.add(4, head4);
+        list.add(5, head5);
+        list.add(6, head6);
+        invAccountProfitList.forEach(invAccountProfit -> {
+            List<String> head0 = ListUtils.newArrayList();
+            head0.add(invAccountProfit.getProfitName());
+            list.add(head0);
+        });
+
+        return list;
+    }
+
+
+
+    private static List<List<Object>> operatedataList( List<InvAccountOperate> invAccountOperates , List<InvAccountProfit> invAccountProfitList) {
+        List<List<Object>> list = ListUtils.newArrayList();
+        invAccountOperates.forEach(invAccountOperate -> {
+            List<Object> data = ListUtils.newArrayList();
+            data.add(invAccountOperate.getCreateTime());
+            data.add(invAccountOperate.getApplySector());
+            data.add(invAccountOperate.getFundFlow().substring(0, invAccountOperate.getFundFlow().indexOf("→")));
+            data.add(invAccountOperate.getFundFlow().substring(invAccountOperate.getFundFlow().indexOf("→") + 1));
+            data.add(invAccountOperate.getFundUse());
+            data.add(invAccountOperate.getFundFen());
+            data.add(invAccountOperate.getApplyAmount());
+            invAccountProfitList.forEach(invAccountProfit -> {
+                if (invAccountOperate.getOutProfit() != null){
+                    for (Map.Entry<String, Object> entry:invAccountOperate.getOutProfit().entrySet()){
+                        if (entry.getKey().equals(invAccountProfit.getProfitEng())){
+                            data.add(entry.getValue());
+                        }
+                    }
+                }
+            });
+            list.add(data);
+        });
+        return list;
+    }
+
+
+
+
+
+
+
+
+
+
+
     public static String downExcel(String uploadFilePath, String fileName, Class clz, List<?> list) {
 
         String file = fileName + System.currentTimeMillis() + ".xlsx";
@@ -130,13 +224,12 @@ public class EasyExcelUtils {
     /**
      * 导出资金申请模板
      */
-    public List<InvAccountExcel> downAccountExcel(String uploadFilePath, List<InvAccountExcel> invAccountExcel) {
+    public String downAccountExcel(String uploadFilePath, List<InvAccountExcel> invAccountExcel) {
         // 加载模板
         String templateFile = "资金申请单模板.xlsx";
         List<InvAccountExcel> list = new ArrayList<>();
         // 获取工作表并填充
         for (InvAccountExcel excel : invAccountExcel) {
-            if (excel.getTransferFlag().equals("1")) {
                 // 写入文件
                 Date date = new Date();
                 String file = date.getTime() + ".xlsx";
@@ -157,10 +250,19 @@ public class EasyExcelUtils {
                 excel.setUplodePath(file);
                 excel.setPayMethod(payMethod);
                 list.add(excel);
-            }
         }
         insAccountExcelService.updateBatchById(list);
-        return list;
+
+        File[] srcFiles = new File[list.size()];
+        for (int i = 0; i < list.size(); i++) {
+            srcFiles[i] = new File(uploadFilePath + list.get(i).getUplodePath());
+        }
+        String a = LocalDate.now()+".zip";
+        File zipFile = new File(uploadFilePath+a);
+        // 调用压缩方法
+        zipFiles(srcFiles, zipFile);
+
+        return a;
     }
 
 }

+ 3 - 1
src/main/java/com/ydtech/modules/inv/utils/TransferUtils.java

@@ -198,7 +198,9 @@ public class TransferUtils {
      * @return
      */
     private static InvAccountCard enterAccountUtils(InvAccountCard enterAccountCard, BigDecimal invAccountExcelApplyAmount) {
-        enterAccountCard.setBalance(new BigDecimal(enterAccountCard.getBalance()).add(invAccountExcelApplyAmount).toString());
+        if(enterAccountCard.getBalance()!=null && !enterAccountCard.getBalance().isEmpty()){
+            enterAccountCard.setBalance(new BigDecimal(enterAccountCard.getBalance()).add(invAccountExcelApplyAmount).toString());
+        }
         return enterAccountCard;
     }
 

+ 68 - 0
src/main/java/com/ydtech/modules/inv/utils/ZipMultiFile.java

@@ -0,0 +1,68 @@
+package cn.com.zfc.day018;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+/**
+ * @describe 压缩多个文件
+ * @author zfc
+ * @date 2018年1月11日 下午8:34:00
+ */
+public class ZipMultiFile {
+
+    public static void main(String[] args) {
+
+    }
+
+    public static void zipFiles(File[] srcFiles, File zipFile) {
+        // 判断压缩后的文件存在不,不存在则创建
+        if (!zipFile.exists()) {
+            try {
+                zipFile.createNewFile();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        // 创建 FileOutputStream 对象
+        FileOutputStream fileOutputStream = null;
+        // 创建 ZipOutputStream
+        ZipOutputStream zipOutputStream = null;
+        // 创建 FileInputStream 对象
+        FileInputStream fileInputStream = null;
+
+        try {
+            // 实例化 FileOutputStream 对象
+            fileOutputStream = new FileOutputStream(zipFile);
+            // 实例化 ZipOutputStream 对象
+            zipOutputStream = new ZipOutputStream(fileOutputStream);
+            // 创建 ZipEntry 对象
+            ZipEntry zipEntry = null;
+            // 遍历源文件数组
+            for (int i = 0; i < srcFiles.length; i++) {
+                // 将源文件数组中的当前文件读入 FileInputStream 流中
+                fileInputStream = new FileInputStream(srcFiles[i]);
+                // 实例化 ZipEntry 对象,源文件数组中的当前文件
+                zipEntry = new ZipEntry(srcFiles[i].getName());
+                zipOutputStream.putNextEntry(zipEntry);
+                // 该变量记录每次真正读的字节个数
+                int len;
+                // 定义每次读取的字节数组
+                byte[] buffer = new byte[1024];
+                while ((len = fileInputStream.read(buffer)) > 0) {
+                    zipOutputStream.write(buffer, 0, len);
+                }
+            }
+            zipOutputStream.closeEntry();
+            zipOutputStream.close();
+            fileInputStream.close();
+            fileOutputStream.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+    }
+}