Browse Source

修改发票管理逻辑

y 2 năm trước cách đây
mục cha
commit
f73235d8df

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

@@ -37,7 +37,7 @@ public class InvAccountController {
     }
 
     @PostMapping("accountExcel")
-    @ApiOperation("费用支出明细导出")
+    @ApiOperation("账户信息导出")
     public HttpResult accountExcel(@RequestBody InvAccountQueryVo invAccountQueryVo) {
         return invAccountService.selectAccountList(invAccountQueryVo);
     }

+ 19 - 2
src/main/java/com/ydtech/modules/inv/controller/invAccountExcelController.java

@@ -56,10 +56,10 @@ public class invAccountExcelController {
         for (Map.Entry<String, Object> entry:entProfit.entrySet()){
             entAmount = entAmount.add(new BigDecimal(entry.getValue().toString()));
         }
-        if (String.valueOf(outAmount).equals("1000")){
+        if (!String.valueOf(outAmount).equals("100")){
             throw new SystemException("支出金额未完全分配");
         }
-        if (String.valueOf(entAmount).equals("1000")){
+        if (!String.valueOf(entAmount).equals("100")){
             throw new SystemException("收入金额未完全分配");
         }
 
@@ -81,6 +81,23 @@ public class invAccountExcelController {
     @PostMapping("update")
     @ApiOperation("修改资金模板信息")
     public HttpResult updateAccount(@RequestBody InvAccountExcel invAccountExcel) {
+        JSONObject outProfit = invAccountExcel.getOutProfit();
+        JSONObject entProfit = invAccountExcel.getEntProfit();
+        BigDecimal outAmount = new BigDecimal(0);
+        BigDecimal entAmount = new BigDecimal(0);
+        for (Map.Entry<String, Object> entry:outProfit.entrySet()){
+            outAmount = outAmount.add(new BigDecimal(entry.getValue().toString()));
+        }
+        for (Map.Entry<String, Object> entry:entProfit.entrySet()){
+            entAmount = entAmount.add(new BigDecimal(entry.getValue().toString()));
+        }
+        if (!String.valueOf(outAmount).equals("100")){
+            throw new SystemException("支出金额未完全分配");
+        }
+        if (!String.valueOf(entAmount).equals("100")){
+            throw new SystemException("收入金额未完全分配");
+        }
+
         if (invAccountExcel.getExcelAccountOperateId() != null) {
             if (invAccountExcel.getTransferFlag().equals("1")) {
                 BaseController baseController = new BaseController();

+ 5 - 0
src/main/java/com/ydtech/modules/inv/model/InvAccountExcel.java

@@ -74,6 +74,11 @@ public class InvAccountExcel implements Serializable {
     @NotBlank
     private String applySector;
 
+
+    @ApiModelProperty(value = "板块")
+    @TableField(exist = false)
+    private String plate;
+
     /**
      * 收款单位信息
      */

+ 18 - 13
src/main/java/com/ydtech/modules/inv/service/impl/InvAccountExcelServiceImpl.java

@@ -52,6 +52,9 @@ public class InvAccountExcelServiceImpl extends ServiceImpl<InvAccountExcelMappe
     @Autowired
     private InvAccountOpService insAccountOpService;
 
+    @Autowired
+    private InvAccountProfitService insAccountProfitService;
+
 
     @Value("${upload.file.path}")
     String uploadFilePath;
@@ -59,14 +62,15 @@ public class InvAccountExcelServiceImpl extends ServiceImpl<InvAccountExcelMappe
     @Override
     public HttpResult excelAccount(List<String> idList) {
         List<InvAccountExcel> insAccountExcels = insAccountExcelMapper.selectBatchIds(idList);
+        List<InvAccountProfit> list = insAccountProfitService.list();
         if (!insAccountExcels.isEmpty()) {
             File folder = new File(uploadFilePath);
-            if (folder.exists()){
-                return HttpResult.ok("", easyExcelUtils.downAccountExcel(uploadFilePath, insAccountExcels));
-            }else {
-                if (folder.mkdirs()){
-                    return HttpResult.ok("", easyExcelUtils.downAccountExcel(uploadFilePath, insAccountExcels));
-                }else {
+            if (folder.exists()) {
+                return HttpResult.ok("", easyExcelUtils.downAccountExcel(uploadFilePath, insAccountExcels,list));
+            } else {
+                if (folder.mkdirs()) {
+                    return HttpResult.ok("", easyExcelUtils.downAccountExcel(uploadFilePath, insAccountExcels,list));
+                } else {
                     throw new SystemException("文件导出失败");
                 }
             }
@@ -84,7 +88,7 @@ public class InvAccountExcelServiceImpl extends ServiceImpl<InvAccountExcelMappe
         Page page = PageRequest.buildPageRequest(pageRequest);
         IPage<InvAccountExcel> invAccountExcelIPage = insAccountExcelMapper.selectExcelAccount(page, invAccountExcel);
         List<InvAccountExcel> records = invAccountExcelIPage.getRecords();
-        for (InvAccountExcel record:records){
+        for (InvAccountExcel record : records) {
             StringBuilder a = new StringBuilder();
             String[] split = record.getPayMethod().split(",");
             for (String i : split) {
@@ -126,7 +130,7 @@ public class InvAccountExcelServiceImpl extends ServiceImpl<InvAccountExcelMappe
             if (insAccountCards.isEmpty()) {
                 throw new RuntimeException("转账失败");
             }
-            if (!invAccountCardService.updateBatchById(insAccountCards)){
+            if (!invAccountCardService.updateBatchById(insAccountCards)) {
                 throw new RuntimeException("转账失败");
             }
 
@@ -135,7 +139,7 @@ public class InvAccountExcelServiceImpl extends ServiceImpl<InvAccountExcelMappe
             JSONObject outProfit = invAccountExcel.getOutProfit();
             JSONObject entProfit = invAccountExcel.getEntProfit();
             InvAccountExcel out = outJsonUtil(invAccountExcel, outProfit, outAccount, outAccountCard);
-            InvAccountExcel ent = entJsonUtil(invAccountExcel, entProfit, enterAccount,enterAccountCard);
+            InvAccountExcel ent = entJsonUtil(invAccountExcel, entProfit, enterAccount, enterAccountCard);
 
 
             //支出信息
@@ -143,7 +147,7 @@ public class InvAccountExcelServiceImpl extends ServiceImpl<InvAccountExcelMappe
             //收入信息
             list.add(insertRevenueAccountOperate(ent));
 
-            if (!insAccountOperateService.saveBatch(list)){
+            if (!insAccountOperateService.saveBatch(list)) {
                 throw new RuntimeException("添加转账信息失败");
             }
             //重新将值赋值回去方便编辑
@@ -152,11 +156,11 @@ public class InvAccountExcelServiceImpl extends ServiceImpl<InvAccountExcelMappe
         } else {
             //内转外部转账
             List<InvAccountCard> invAccounts = enterDeTransfer(outAccountCard, enterAccountCard, invAccountExcel);
-            if (!invAccountCardService.saveBatch(invAccounts)){
+            if (!invAccountCardService.saveBatch(invAccounts)) {
                 throw new RuntimeException("添加转账信息失败");
             }
             JSONObject outProfit = invAccountExcel.getOutProfit();
-            InvAccountExcel out = outJsonUtil(invAccountExcel, outProfit, outAccount,outAccountCard);
+            InvAccountExcel out = outJsonUtil(invAccountExcel, outProfit, outAccount, outAccountCard);
             insAccountOperateService.save(insertOutAccountOperate(out));
 
             //重新将值赋值回去方便编辑
@@ -189,7 +193,8 @@ public class InvAccountExcelServiceImpl extends ServiceImpl<InvAccountExcelMappe
         invAccountExcel.setOutProfit(jsonObject);
         return invAccountExcel;
     }
-    private InvAccountExcel entJsonUtil(InvAccountExcel invAccountExcel, JSONObject outProfit,InvAccount entAccount,InvAccountCard entCard) {
+
+    private InvAccountExcel entJsonUtil(InvAccountExcel invAccountExcel, JSONObject outProfit, InvAccount entAccount, InvAccountCard entCard) {
         JSONObject jsonObject = new JSONObject();
         List<InvAccountOp> list = new ArrayList<>();
         for (Map.Entry<String, Object> entry : outProfit.entrySet()) {

+ 21 - 25
src/main/java/com/ydtech/modules/inv/service/impl/InvAccountIncoiceServiceImpl.java

@@ -23,6 +23,7 @@ import org.springframework.util.ObjectUtils;
 import java.io.File;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
+import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -77,6 +78,10 @@ public class InvAccountIncoiceServiceImpl extends ServiceImpl<InvAccountIncoiceM
     @Override
     public HttpResult updateInvAccountIncoice(InvAccountIncoice invAccountIncoice) {
         InvAccountIncoice invAccountIncoice1 = invAccountIncoiceMapper.selectById(invAccountIncoice.getInvoiceId());
+        InvAccount account = invAccountService.getById(invAccountIncoice1.getAccountId());
+        InvAccountCard entCard = invAccountCardService.getById(invAccountIncoice1.getRevBankCardNum());
+        InvAccountCard outCard = invAccountCardService.getById(invAccountIncoice1.getOutBankCardNum());
+        List<InvAccountOp> list = new ArrayList<>();
 
         if (new BigDecimal(invAccountIncoice1.getInvoiceMoney()).subtract(new BigDecimal(invAccountIncoice1.getPayoutMoney()).add(new BigDecimal(invAccountIncoice.getPayoutMoney()))).compareTo(new BigDecimal("0")) < 0) {
             throw new SystemException("进账金额大于开票金额");
@@ -106,24 +111,14 @@ public class InvAccountIncoiceServiceImpl extends ServiceImpl<InvAccountIncoiceM
         invAccountOperate.setFundUse(invAccountIncoice.getFundUse());
         invAccountOperate.setFundFen(invAccountIncoice.getFundFen());
         invAccountOperate.setInvoiceId(invAccountIncoice1.getInvoiceId());
+        invAccountOperate.setCreateTime(LocalDateTime.now());
         //计算收入百分比
         JSONObject entProfit = invAccountIncoice.getEntProfit();
         JSONObject jsonObject = new JSONObject();
         for (Map.Entry<String, Object> entry : entProfit.entrySet()) {
-            BigDecimal multiply = new BigDecimal(String.valueOf(entry.getValue())).multiply(new BigDecimal(invAccountIncoice.getPayoutMoney())).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
-            jsonObject.put(entry.getKey(), multiply);
-        }
-        invAccountOperate.setOutProfit(jsonObject);
-        invAccountOperate.setEnterCardId(invAccountIncoice.getRevBankCardNum());
-
-        InvAccount account = invAccountService.getById(invAccountIncoice1.getAccountId());
-        InvAccountCard entCard = invAccountCardService.getById(invAccountIncoice1.getRevBankCardNum());
-        InvAccountCard outCard = invAccountCardService.getById(invAccountIncoice1.getOutBankCardNum());
-
-
-        List<InvAccountOp> list = new ArrayList<>();
-        for (Map.Entry<String, Object> entry : invAccountIncoice.getEntProfit().entrySet()) {
             if (Integer.parseInt(entry.getValue().toString()) != 0) {
+                BigDecimal multiply = new BigDecimal(String.valueOf(entry.getValue())).multiply(new BigDecimal(invAccountIncoice.getPayoutMoney())).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
+                jsonObject.put(entry.getKey(), multiply);
                 InvAccountOp invAccountOp = new InvAccountOp();
                 invAccountOp.setAccountId(invAccountIncoice1.getAccountId());
                 invAccountOp.setAccountName(account.getAccountName());
@@ -135,6 +130,9 @@ public class InvAccountIncoiceServiceImpl extends ServiceImpl<InvAccountIncoiceM
                 list.add(invAccountOp);
             }
         }
+        invAccountOperate.setOutProfit(jsonObject);
+        invAccountOperate.setEnterCardId(invAccountIncoice.getRevBankCardNum());
+
 
 
         //支出操作
@@ -148,23 +146,14 @@ public class InvAccountIncoiceServiceImpl extends ServiceImpl<InvAccountIncoiceM
         outInvAccountOperate.setFundUse(invAccountIncoice.getFundUse());
         outInvAccountOperate.setFundFen(invAccountIncoice.getFundFen());
         outInvAccountOperate.setInvoiceId(invAccountIncoice1.getInvoiceId());
+        outInvAccountOperate.setCreateTime(LocalDateTime.now());
         //计算支出百分比
         JSONObject outProfit = invAccountIncoice.getOutProfit();
         JSONObject outJsonObject = new JSONObject();
         for (Map.Entry<String, Object> entry : outProfit.entrySet()) {
-            BigDecimal multiply = new BigDecimal(String.valueOf(entry.getValue())).multiply(new BigDecimal(invAccountIncoice.getPayoutMoney())).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP).negate();
-            outJsonObject.put(entry.getKey(), multiply.negate());
-        }
-        outInvAccountOperate.setOutProfit(outJsonObject);
-        invAccountOperate.setEnterCardId(invAccountIncoice.getOutBankCardNum());
-
-        List<InvAccountOperate> invAccountOperateList = new ArrayList<>();
-        invAccountOperateList.add(outInvAccountOperate);
-        invAccountOperateList.add(invAccountOperate);
-
-
-        for (Map.Entry<String, Object> entry : outInvAccountOperate.getOutProfit().entrySet()) {
             if (Integer.parseInt(entry.getValue().toString()) != 0) {
+                BigDecimal multiply = new BigDecimal(String.valueOf(entry.getValue())).multiply(new BigDecimal(invAccountIncoice.getPayoutMoney())).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP).negate();
+                outJsonObject.put(entry.getKey(), multiply.negate());
                 InvAccountOp invAccountOp = new InvAccountOp();
                 invAccountOp.setAccountId(invAccountIncoice1.getAccountId());
                 invAccountOp.setAccountName(account.getAccountName());
@@ -176,6 +165,13 @@ public class InvAccountIncoiceServiceImpl extends ServiceImpl<InvAccountIncoiceM
                 list.add(invAccountOp);
             }
         }
+        outInvAccountOperate.setOutProfit(outJsonObject);
+        invAccountOperate.setEnterCardId(invAccountIncoice.getOutBankCardNum());
+
+        List<InvAccountOperate> invAccountOperateList = new ArrayList<>();
+        invAccountOperateList.add(outInvAccountOperate);
+        invAccountOperateList.add(invAccountOperate);
+
 
 
         //支出卡号

+ 58 - 43
src/main/java/com/ydtech/modules/inv/utils/EasyExcelUtils.java

@@ -19,6 +19,7 @@ import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.time.LocalDate;
 import java.util.*;
+import java.util.stream.Collectors;
 
 import static cn.com.zfc.day018.ZipMultiFile.zipFiles;
 
@@ -63,7 +64,7 @@ public class EasyExcelUtils {
         head2.add("开户银行");
         List<String> head3 = ListUtils.newArrayList();
         head3.add("银行卡余额");
-        list.add(0,head);
+        list.add(0, head);
         list.add(1, head1);
         list.add(2, head2);
         list.add(3, head3);
@@ -78,22 +79,21 @@ public class EasyExcelUtils {
     }
 
 
-
     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.getOuterFlag().equals("0") ? "内部账户" : "外部账户");
                     data.add(invAccount.getAccountName());
                     data.add(invAccountCard.getBankName());
                     data.add(invAccountCard.getBalance());
 
                     invAccountProfitList.forEach(invAccountProfitList1 -> {
                         String a = "0";
-                        for (InvAccountOp invAccountProfit :  invAccountOpList){
-                            if (invAccountProfitList1.getProfitEng().equals(invAccountProfit.getProfit())&&invAccountCard.getBankCardNum().equals(invAccountProfit.getCardNum())) {
+                        for (InvAccountOp invAccountProfit : invAccountOpList) {
+                            if (invAccountProfitList1.getProfitEng().equals(invAccountProfit.getProfit()) && invAccountCard.getBankCardNum().equals(invAccountProfit.getCardNum())) {
                                 a = new BigDecimal(a).add(new BigDecimal(invAccountProfit.getMoney())).toString();
                             }
                         }
@@ -108,7 +108,6 @@ public class EasyExcelUtils {
     }
 
 
-
     /**
      * 不创建对象的写
      */
@@ -137,8 +136,10 @@ public class EasyExcelUtils {
         head5.add("分项");
         List<String> head6 = ListUtils.newArrayList();
         head6.add("支出金额");
+        List<String> head7 = ListUtils.newArrayList();
+        head7.add("转账类型");
 
-        list.add(0,head);
+        list.add(0, head);
         list.add(1, head1);
         list.add(2, head2);
         list.add(3, head3);
@@ -155,8 +156,7 @@ public class EasyExcelUtils {
     }
 
 
-
-    private static List<List<Object>> operatedataList( List<InvAccountOperate> invAccountOperates , List<InvAccountProfit> invAccountProfitList) {
+    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();
@@ -167,10 +167,11 @@ public class EasyExcelUtils {
             data.add(invAccountOperate.getFundUse());
             data.add(invAccountOperate.getFundFen());
             data.add(invAccountOperate.getApplyAmount());
+            data.add(invAccountOperate.getRevenueOutlay().equals("0")?"收入":"支出");
             invAccountProfitList.forEach(invAccountProfit -> {
-                if (invAccountOperate.getOutProfit() != null){
-                    for (Map.Entry<String, Object> entry:invAccountOperate.getOutProfit().entrySet()){
-                        if (entry.getKey().equals(invAccountProfit.getProfitEng())){
+                if (invAccountOperate.getOutProfit() != null) {
+                    for (Map.Entry<String, Object> entry : invAccountOperate.getOutProfit().entrySet()) {
+                        if (entry.getKey().equals(invAccountProfit.getProfitEng())) {
                             data.add(entry.getValue());
                         }
                     }
@@ -182,15 +183,6 @@ public class EasyExcelUtils {
     }
 
 
-
-
-
-
-
-
-
-
-
     public static String downExcel(String uploadFilePath, String fileName, Class clz, List<?> list) {
 
         String file = fileName + System.currentTimeMillis() + ".xlsx";
@@ -224,32 +216,55 @@ public class EasyExcelUtils {
     /**
      * 导出资金申请模板
      */
-    public String downAccountExcel(String uploadFilePath, List<InvAccountExcel> invAccountExcel) {
+    public String downAccountExcel(String uploadFilePath, List<InvAccountExcel> invAccountExcel,List<InvAccountProfit> invAccountProfit) {
         // 加载模板
         String templateFile = "资金申请单模板.xlsx";
         List<InvAccountExcel> list = new ArrayList<>();
         // 获取工作表并填充
         for (InvAccountExcel excel : invAccountExcel) {
-                // 写入文件
-                Date date = new Date();
-                String file = date.getTime() + ".xlsx";
-                String fileName = uploadFilePath + file;
-                excel.setExcelApplyTime(new SimpleDateFormat("yyyy-MM-dd").format(excel.getApplyTime()));
-                String payMethod = excel.getPayMethod();
-                String[] split = payMethod.split(",");
-                StringBuilder a = new StringBuilder();
-                for (String i : split) {
-                    a.append(InvPayMethodEnum.getNameByCode(i)).append(",");
+            // 写入文件
+            Date date = new Date();
+            String file = date.getTime() + ".xlsx";
+            String fileName = uploadFilePath + file;
+            excel.setExcelApplyTime(new SimpleDateFormat("yyyy-MM-dd").format(excel.getApplyTime()));
+            String payMethod = excel.getPayMethod();
+            String[] split = payMethod.split(",");
+            StringBuilder a = new StringBuilder();
+            for (String i : split) {
+                a.append(InvPayMethodEnum.getNameByCode(i)).append(",");
+            }
+
+            StringBuilder stringBuffer = new StringBuilder();
+
+            Map<String, List<InvAccountProfit>> collect = invAccountProfit.stream().collect(
+                    Collectors.groupingBy(
+                            InvAccountProfit::getProfitEng
+                    ));
+
+            for (Map.Entry<String, Object> entry : excel.getEntProfit().entrySet()) {
+                if (Integer.parseInt(entry.getValue().toString()) != 0) {
+                    stringBuffer.append(collect.get(entry.getKey()).get(0).getProfitName()).append("   ").append(entry.getValue()).append("%");
+                }
+            }
+            stringBuffer.append("→");
+
+            for (Map.Entry<String, Object> entry : excel.getOutProfit().entrySet()) {
+                if (Integer.parseInt(entry.getValue().toString()) != 0) {
+                    stringBuffer.append(collect.get(entry.getKey()).get(0).getProfitName()).append("    ").append(entry.getValue()).append("%");
                 }
-                excel.setPayMethod(a.toString());
-                // 生成工作簿对象
-                ExcelWriterBuilder workBookWriter = EasyExcel.write(fileName, InvAccountExcel.class)
-                        .withTemplate(templateFile);
-
-                workBookWriter.sheet().doFill(excel);
-                excel.setUplodePath(file);
-                excel.setPayMethod(payMethod);
-                list.add(excel);
+            }
+            excel.setPlate(stringBuffer.toString());
+
+
+            excel.setPayMethod(a.toString());
+            // 生成工作簿对象
+            ExcelWriterBuilder workBookWriter = EasyExcel.write(fileName, InvAccountExcel.class)
+                    .withTemplate(templateFile);
+
+            workBookWriter.sheet().doFill(excel);
+            excel.setUplodePath(file);
+            excel.setPayMethod(payMethod);
+            list.add(excel);
         }
         insAccountExcelService.updateBatchById(list);
 
@@ -257,8 +272,8 @@ public class EasyExcelUtils {
         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);
+        String a = LocalDate.now() + ".zip";
+        File zipFile = new File(uploadFilePath + a);
         // 调用压缩方法
         zipFiles(srcFiles, zipFile);
 

BIN
资金申请单模板.xlsx