Browse Source

支出接口、报表导出添加成本分类

Qchen 2 years ago
parent
commit
3e1335724d

+ 4 - 3
src/main/java/com/ydtech/modules/inv/controller/invAccountExcelController.java

@@ -61,7 +61,7 @@ public class invAccountExcelController {
     @PostMapping("deriveReport")
     @ApiOperation("导出支出报表")
     public HttpResult deriveReport(@RequestBody List<String> idList) throws IOException {
-        List<InvAccountOperate> insAccountExcels = invAccountOperateMapper.selectBatchIds(idList);
+        List<InvAccountOperate> insAccountExcels = invAccountOperateMapper.selectIds(idList);
         String uploadPath = this.uploadPath + "/excel/";
         Path path = Paths.get(uploadPath);
         if (!Files.exists(path)) {
@@ -94,6 +94,7 @@ public class invAccountExcelController {
         }
         invAccountExcel.setTransferFlag("1"); //默认新增时未转帐状态
         invAccountExcel.setExcelAccountOperateId(String.valueOf(new Date().getTime()));
+        invAccountExcel.setPayoutAmount("0");
 
         if (invAccountExcelService.save(invAccountExcel)) {
             return HttpResult.ok("", "新增成功");
@@ -179,10 +180,10 @@ public class invAccountExcelController {
 
     @ApiOperation("修改转账状态")
     @GetMapping("updateTransferFlag")
-    public HttpResult updateTransferFlag(@RequestParam("excelAccountOperateId") String excelAccountOperateId) {
+    public HttpResult updateTransferFlag(@RequestParam("excelAccountOperateId") String excelAccountOperateId,@RequestParam("payOutAmount") String payOutAmount) {
         if (excelAccountOperateId == null) {
             return HttpResult.error("id不能为空");
         }
-        return invAccountExcelService.updateTransferFlag(excelAccountOperateId);
+        return invAccountExcelService.updateTransferFlag(excelAccountOperateId,payOutAmount);
     }
 }

+ 2 - 0
src/main/java/com/ydtech/modules/inv/dao/InvAccountOperateMapper.java

@@ -21,6 +21,8 @@ public interface InvAccountOperateMapper extends BaseMapper<InvAccountOperate> {
 
     List<InvAccountOperate> selectOperateList(List<String> cardNumList);
 
+    List<InvAccountOperate> selectIds(List<String> idList);
+
     /**
      * 删除方法
      * @param invAccountIncoiceId

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

@@ -125,6 +125,15 @@ public class InvAccountExcel implements Serializable {
     @NotBlank
     private String applyAmount;
 
+
+    /**
+     * 已转金额
+     */
+    @ApiModelProperty(value = "已转金额")
+    @NotBlank
+    private String payoutAmount;
+
+
     /**
      * 大写金额
      */

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

@@ -198,6 +198,9 @@ public class InvAccountOperate implements Serializable {
     @TableField(exist = false)
     private int pageSize;
 
+    @TableField(exist = false)
+    private String label;
+
 
     @TableField(exist = false)
     private static final long serialVersionUID = 1L;

+ 11 - 2
src/main/java/com/ydtech/modules/inv/model/excel/InvDisburseExcel.java

@@ -10,11 +10,20 @@ import java.util.Date;
 
 @Data
 public class InvDisburseExcel implements Serializable {
-    @ExcelProperty("转账日期")
-    @ApiModelProperty(value = "转账日期")
+    @ExcelProperty("转账时间")
+    @ApiModelProperty(value = "转账时间")
     @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
     private String createTime;
 
+    @ExcelProperty("申请时间")
+    @ApiModelProperty(value = "申请时间")
+    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
+    private Date applyTime;
+
+    @ExcelProperty("成本分类")
+    @ApiModelProperty(value = "成本分类")
+    private String label;
+
     @ExcelProperty("费用类型")
     @ApiModelProperty(value = "资金用途")
     private String fundUse;

+ 9 - 0
src/main/java/com/ydtech/modules/inv/model/vo/InvAccountOperateVo.java

@@ -19,6 +19,10 @@ public class InvAccountOperateVo implements Serializable {
     @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
     private Date createTime;
 
+    @ExcelProperty("申请时间")
+    @ApiModelProperty(value = "申请时间")
+    private Date applyTime;
+
     @ExcelProperty("费用类型")
     @ApiModelProperty(value = "资金用途")
     private String fundUse;
@@ -60,7 +64,12 @@ public class InvAccountOperateVo implements Serializable {
     @TableField(exist = false)
     private String createTimeEnd;
 
+    @TableField(exist = false)
+    private String label;
+
+    @TableField(exist = false)
     private int pageNum;
 
+    @TableField(exist = false)
     private int PageSize;
 }

+ 1 - 1
src/main/java/com/ydtech/modules/inv/service/InvAccountExcelService.java

@@ -20,6 +20,6 @@ public interface InvAccountExcelService extends IService<InvAccountExcel> {
 
     HttpResult selectDisburse(InvAccountOperateVo invAccountOperateVo);
 
-    HttpResult updateTransferFlag(String excelAccountOperateId);
+    HttpResult updateTransferFlag(String excelAccountOperateId,String payOutAmount);
 
 }

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

@@ -1,6 +1,7 @@
 package com.ydtech.modules.inv.service.impl;
 
 
+import com.alibaba.excel.EasyExcel;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -18,7 +19,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
-import java.io.File;
+import java.io.*;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -115,26 +117,25 @@ public class InvAccountExcelServiceImpl extends ServiceImpl<InvAccountExcelMappe
      * @return
      */
     @Override
-    public HttpResult updateTransferFlag(String excelAccountOperateId) {
+    public HttpResult updateTransferFlag(String excelAccountOperateId, String payOutAmount) {
         InvAccountExcel invAccountExcel = insAccountExcelMapper.selectById(excelAccountOperateId);
         if (invAccountExcel == null) {
-            throw new RuntimeException("该记录不存在");
+            HttpResult.error("该记录不存在");
+        }
+        if ((payOutAmount + invAccountExcel.getPayoutAmount()).compareTo(invAccountExcel.getApplyAmount()) > 0) {
+           HttpResult.error("已转金额不能大于申请金额");
         }
 
         InvAccountCard outAccountCard = invAccountCardService.getById(invAccountExcel.getOutCardNum());
         InvAccountCard enterAccountCard = invAccountCardService.getById(invAccountExcel.getEnterCardNum());
         InvAccount outAccount = insAccountService.getById(outAccountCard.getAccountId());
         InvAccount enterAccount = insAccountService.getById(enterAccountCard.getAccountId());
-        //操作金额
-        String applyAmount = invAccountExcel.getApplyAmount();
 
-        //修改转账状态
-        invAccountExcel.setTransferFlag("0");
 
         //判断是转账给内部还是外部
         if (invAccountExcel.getOutFlag().equals("0")) {
             //如果转账失败就返回错误
-            List<InvAccountCard> insAccountCards = insideTransfer(outAccountCard, outAccount, enterAccountCard, enterAccount, applyAmount);
+            List<InvAccountCard> insAccountCards = insideTransfer(outAccountCard, outAccount, enterAccountCard, enterAccount, payOutAmount);
             if (insAccountCards.isEmpty()) {
                 throw new RuntimeException("转账失败");
             }
@@ -173,9 +174,17 @@ public class InvAccountExcelServiceImpl extends ServiceImpl<InvAccountExcelMappe
             outJsonUtil(outProfit, outAccount, outAccountCard,invAccountOperate.getAccountOperateId());
             entJsonUtil(entProfit, enterAccount, enterAccountCard, invAccountOperate1.getAccountOperateId());
 
+            if (invAccountExcel.getApplyAmount().equals(payOutAmount)) {
+                invAccountExcel.setTransferFlag("0");
+                invAccountExcel.setPayoutAmount(String.valueOf(Integer.parseInt(payOutAmount) + Integer.parseInt(invAccountExcel.getPayoutAmount())));
+            } else {
+                invAccountExcel.setTransferFlag("1");
+                invAccountExcel.setPayoutAmount(String.valueOf(Integer.parseInt(payOutAmount) + Integer.parseInt(invAccountExcel.getPayoutAmount())));
+            }
+
         } else {
             //内转外部转账
-            List<InvAccountCard> invAccounts = enterDeTransfer(outAccountCard, outAccount, enterAccountCard, enterAccount, applyAmount);
+            List<InvAccountCard> invAccounts = enterDeTransfer(outAccountCard, outAccount, enterAccountCard, enterAccount, payOutAmount);
             if (!invAccountCardService.saveBatch(invAccounts)) {
                 throw new RuntimeException("添加转账信息失败");
             }
@@ -185,6 +194,14 @@ public class InvAccountExcelServiceImpl extends ServiceImpl<InvAccountExcelMappe
             insAccountOperateService.save(invAccountOperate);
             JSONObject outProfit = invAccountExcel.getOutProfit();
             outJsonUtil(outProfit, outAccount, outAccountCard,invAccountOperate.getAccountOperateId());
+
+            if (invAccountExcel.getApplyAmount().equals(payOutAmount)) {
+                invAccountExcel.setTransferFlag("0");
+                invAccountExcel.setPayoutAmount(String.valueOf(Integer.parseInt(payOutAmount) + Integer.parseInt(invAccountExcel.getPayoutAmount())));
+            } else {
+                invAccountExcel.setTransferFlag("1");
+                invAccountExcel.setPayoutAmount(String.valueOf(Integer.parseInt(payOutAmount) + Integer.parseInt(invAccountExcel.getPayoutAmount())));
+            }
         }
         return HttpResult.ok("", insAccountExcelMapper.updateById(invAccountExcel));
     }

+ 3 - 6
src/main/java/com/ydtech/modules/inv/utils/EasyExcelUtils.java

@@ -22,10 +22,7 @@ import java.io.InputStream;
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.time.LocalDate;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 import static com.ydtech.modules.inv.utils.ZipMultiFile.zipFiles;
@@ -246,7 +243,7 @@ public class EasyExcelUtils {
         // 加载模板
         InputStream inputStream = getClass().getResourceAsStream("/template/资金申请单模板.xlsx");
 
-        byte[] bytes = saveaIns(inputStream);
+        byte[] bytes = saveIns(inputStream);
 
         if (inputStream != null) {
             inputStream.close();
@@ -338,7 +335,7 @@ public class EasyExcelUtils {
 
 
     //保存流对象(输入流在第二次使用的时候会失效)
-    public byte[] saveaIns(InputStream ins){
+    public byte[] saveIns(InputStream ins){
         byte[] buf = null;
         try {
             if(ins!=null){

+ 11 - 2
src/main/resources/mapper/modules/inv/InvAccountExcelMapper.xml

@@ -39,7 +39,7 @@
         excel_account_operate_id,company,applicant,
         apply_time,apply_sector,collection_message,
         fund_flow,fund_use,
-        apply_amount,big_apply_amount,uplode_path,
+        apply_amount,payout_amount,big_apply_amount,uplode_path,
         update_by,update_time,create_by,
         create_time,enter_card_num,out_card_num,
         del_flag,out_flag,out_account_quality,transfer_flag,pay_method,out_profit,ent_profit,fund_fen,remark
@@ -129,6 +129,7 @@
         <result property="applyAmount" column="apply_amount" jdbcType="VARCHAR"/>
         <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
         <result property="remark" column="remark" jdbcType="VARCHAR"/>
+        <result property="label" column="label" jdbcType="VARCHAR"/>
     </resultMap>
 
 
@@ -142,10 +143,15 @@
             a.apply_sector,
             a.company,
             a.collection_message,
-            a.create_time
+            a.create_time,
+            c.label as label
+
         from inv_account_operate a
             LEFT JOIN inv_account_expenses b ON a.fund_fen = b.category
+            Left join sys_dict c on b.expenditure_details = c.value
         WHERE
+            c.itemname = 'cost_type'
+        AND
             a.fund_use != '往来款'
 	    AND collection_message LIKE '外部用户%'
         and a.revenue_outlay = '1'
@@ -171,6 +177,9 @@
         <if test="inAccountOperateVo.applyAmount!= null and inAccountOperateVo.applyAmount!= ''">
             and a.apply_amount = #{inAccountOperateVo.applyAmount}
         </if>
+        <if test="inAccountOperateVo.label!= null and inAccountOperateVo.label!= ''">
+            and c.label = #{inAccountOperateVo.label}
+        </if>
         order by a.create_time desc
     </select>
 

+ 39 - 0
src/main/resources/mapper/modules/inv/InvAccountOperateMapper.xml

@@ -135,4 +135,43 @@
         </foreach>
         )
     </select>
+
+    <resultMap id="InvAccountOperateVoResultMap" type="com.ydtech.modules.inv.model.InvAccountOperate">
+        <id property="accountOperateId" column="account_operate_id" jdbcType="VARCHAR"/>
+        <result property="company" column="company" jdbcType="VARCHAR"/>
+        <result property="applySector" column="apply_sector" jdbcType="VARCHAR"/>
+        <result property="collectionMessage" column="collection_message" jdbcType="VARCHAR"/>
+        <result property="fundUse" column="fund_use" jdbcType="VARCHAR"/>
+        <result property="applyAmount" column="apply_amount" jdbcType="VARCHAR"/>
+        <result property="createTime" column="create_time" jdbcType="VARCHAR"/>
+        <result property="applyTime"  column="apply_time" jdbcType="VARCHAR"/>
+        <result property="remark" column="remark" jdbcType="VARCHAR"/>
+        <result property="label" column="label" jdbcType="VARCHAR"/>
+    </resultMap>
+
+
+    <select id="selectIds" resultMap="InvAccountOperateVoResultMap">
+        SELECT
+        a.create_time,
+        a.apply_time,
+        a.fund_use,
+        a.remark,
+        a.apply_amount,
+        a.apply_sector,
+        a.company,
+        a.collection_message,
+        c.label as label
+
+        from inv_account_operate a
+        LEFT JOIN inv_account_expenses b ON a.fund_fen = b.category
+        Left join sys_dict c on b.expenditure_details = c.value
+        WHERE
+        c.itemname = 'cost_type'
+        AND
+        a.account_operate_id in
+        <foreach item="item" index="index" collection="list"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+    </select>
 </mapper>