소스 검색

1.控制台利润分析添加明细

wuhp 1 년 전
부모
커밋
ba407644e2

+ 17 - 0
src/main/java/com/ydtech/modules/admin/controller/profitAnalysis/ProfitAnalysisController.java

@@ -62,5 +62,22 @@ public class ProfitAnalysisController {
         }
         }
     }
     }
 
 
+    /**
+     *  @version
+     *  @author: whp
+     *  @Date: 2024/10/16 15:35
+     *  @Description:  查询利润分析统计明细
+     */
+    @PostMapping("getProfitAnalysisQueryDetailsList")
+    @ApiOperation(value = "查询利润分析数据")
+    public HttpResult<List<ProfitAnalysisDto>> getProfitAnalysisQueryDetailsList(@RequestBody ProfitAnalysisQueryDto profitAnalysisQueryDto) {
+        try{
+            List<ProfitAnalysisDto> result = profitAnalysisService.getProfitAnalysisQueryDetailsList(profitAnalysisQueryDto);
+            return HttpResult.ok("查询数据成功", result);
+        }catch (Exception e){
+            return HttpResult.error("查询错误"+e.getMessage());
+        }
+    }
+
 
 
 }
 }

+ 18 - 0
src/main/java/com/ydtech/modules/admin/model/report/profitAnalysis/ProfitAnalysisDto.java

@@ -6,6 +6,7 @@ import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.Data;
 
 
 import java.math.BigDecimal;
 import java.math.BigDecimal;
+import java.util.List;
 
 
 /**
 /**
  *  @version
  *  @version
@@ -25,6 +26,7 @@ public class ProfitAnalysisDto {
 
 
     @ApiModelProperty("应收")
     @ApiModelProperty("应收")
     private String sumcount;
     private String sumcount;
+
     @ApiModelProperty("实付")
     @ApiModelProperty("实付")
     private String paid;
     private String paid;
 
 
@@ -69,4 +71,20 @@ public class ProfitAnalysisDto {
 
 
     @ApiModelProperty("转出银行卡")
     @ApiModelProperty("转出银行卡")
     private String outCardNum;
     private String outCardNum;
+
+    @ApiModelProperty("支出类型")
+    private String expensesType;
+
+    @ApiModelProperty("支出类型id")
+    private String expensesId;
+
+    @ApiModelProperty("父id")
+    private String parentId;
+
+    @ApiModelProperty("类目")
+    private String category;
+
+    @ApiModelProperty("子级")
+    private List<ProfitAnalysisDto> children;
+
 }
 }

+ 7 - 0
src/main/java/com/ydtech/modules/admin/model/report/profitAnalysis/ProfitAnalysisQueryDto.java

@@ -43,4 +43,11 @@ public class ProfitAnalysisQueryDto {
     @ApiModelProperty("年月")
     @ApiModelProperty("年月")
     private String yearAndMonth;
     private String yearAndMonth;
 
 
+
+    @ApiModelProperty("支出类型 人员成本 1 固定成本 2   变动成本 3")
+    private String expensesType;
+
+    @ApiModelProperty("支出ids")
+    private List<String> expensesIds;
+
 }
 }

+ 8 - 0
src/main/java/com/ydtech/modules/admin/service/ProfitAnalysisService.java

@@ -22,6 +22,14 @@ public interface ProfitAnalysisService {
     List<ProfitAnalysisDto> queryPage(ProfitAnalysisQueryDto profitAnalysisQueryDto);
     List<ProfitAnalysisDto> queryPage(ProfitAnalysisQueryDto profitAnalysisQueryDto);
 
 
     List<ProfitAnalysisDto> getProfitAnalysisQueryList(ProfitAnalysisQueryDto profitAnalysisQueryDto);
     List<ProfitAnalysisDto> getProfitAnalysisQueryList(ProfitAnalysisQueryDto profitAnalysisQueryDto);
+    /**
+     *  @version
+     *  @author: whp
+     *  @Date: 2024/10/16 15:35
+     *  @Description:  查询利润分析统计明细
+     */
+    List<ProfitAnalysisDto> getProfitAnalysisQueryDetailsList(ProfitAnalysisQueryDto profitAnalysisQueryDto);
+
 }
 }
 
 
 
 

+ 68 - 4
src/main/java/com/ydtech/modules/admin/service/impl/ProfitAnalysisServiceImpl.java

@@ -4,20 +4,20 @@ import com.ydtech.modules.admin.model.report.profitAnalysis.ProfitAnalysisDto;
 import com.ydtech.modules.admin.model.report.profitAnalysis.ProfitAnalysisQueryDto;
 import com.ydtech.modules.admin.model.report.profitAnalysis.ProfitAnalysisQueryDto;
 import com.ydtech.modules.admin.service.ProfitAnalysisService;
 import com.ydtech.modules.admin.service.ProfitAnalysisService;
 import com.ydtech.modules.admin.utils.SliceUpDateUtil;
 import com.ydtech.modules.admin.utils.SliceUpDateUtil;
+import com.ydtech.modules.console.dao.ProfitAnalysisMapper;
 import com.ydtech.modules.fnc.dao.InsPlyIncomeMapper;
 import com.ydtech.modules.fnc.dao.InsPlyIncomeMapper;
 import com.ydtech.modules.inv.dao.InvAccountMapper;
 import com.ydtech.modules.inv.dao.InvAccountMapper;
 import com.ydtech.modules.inv.model.InvAccount;
 import com.ydtech.modules.inv.model.InvAccount;
 import com.ydtech.modules.inv.model.InvAccountCardVo;
 import com.ydtech.modules.inv.model.InvAccountCardVo;
+import com.ydtech.modules.inv.model.InvAccountExpenses;
 import com.ydtech.utils.BigDecimalUtils;
 import com.ydtech.utils.BigDecimalUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import java.math.BigDecimal;
 import java.math.BigDecimal;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
 
 
 /**
 /**
  *  @version
  *  @version
@@ -32,6 +32,8 @@ public class ProfitAnalysisServiceImpl implements ProfitAnalysisService {
 
 
     @Autowired
     @Autowired
     private InsPlyIncomeMapper insPlyIncomeMapper;
     private InsPlyIncomeMapper insPlyIncomeMapper;
+    @Autowired
+    private ProfitAnalysisMapper profitAnalysisMapper;
 
 
     /**
     /**
      *  @version
      *  @version
@@ -82,6 +84,68 @@ public class ProfitAnalysisServiceImpl implements ProfitAnalysisService {
         return profitAnalysisQueryList;
         return profitAnalysisQueryList;
     }
     }
 
 
+    @Override
+    public List<ProfitAnalysisDto> getProfitAnalysisQueryDetailsList(ProfitAnalysisQueryDto profitAnalysisQueryDto) {
+        List<ProfitAnalysisDto> resultList =new ArrayList<>();
+
+        if (StringUtils.isNotEmpty(profitAnalysisQueryDto.getExpensesType()) && "3".equals(profitAnalysisQueryDto.getExpensesType())) {
+            List<ProfitAnalysisDto> profitAnalysisDtos =  profitAnalysisMapper.selectAccountExpenses(profitAnalysisQueryDto);
+            resultList.addAll(profitAnalysisDtos) ;
+            List<ProfitAnalysisDto> addVariableCost = new ArrayList<>();
+            List<ProfitAnalysisDto> profitAnalysisDto1 = insPlyIncomeMapper.changeAmount(profitAnalysisQueryDto);
+            for (ProfitAnalysisDto analysisDto : profitAnalysisDto1) {
+                String outCardNum = analysisDto.getOutCardNum();
+                String enterCardNum = analysisDto.getEnterCardNum();
+                InvAccountCardVo outAccount = invAccountMapper.getByCarNumber(outCardNum);
+                InvAccountCardVo enterAccount = invAccountMapper.getByCarNumber(enterCardNum);
+                if (StringUtils.isNotEmpty(outAccount.getOuterFlag()) && StringUtils.isNotEmpty(enterAccount.getOuterFlag())) {
+                    if (!enterAccount.getOuterFlag().equals(outAccount.getOuterFlag())) {
+                        addVariableCost.add(analysisDto);
+
+                    }
+                }
+            }
+
+            Map<String, BigDecimal> profitAnalysisDtoMap = addVariableCost.stream()
+                    .collect(Collectors.toMap(
+                            ProfitAnalysisDto::getExpensesId,  // keyMapper,用于提取键(expensesId)
+                            ProfitAnalysisDto::getApplyAmount, // valueMapper,用于提取初始值(applyAmount)
+                            BigDecimal::add                    // mergeFunction,用于处理键冲突(相加 applyAmount)
+                    ));
+
+            for (ProfitAnalysisDto profitAnalysisDto : resultList) {
+                String expensesId = profitAnalysisDto.getExpensesId();
+                if (profitAnalysisDtoMap.containsKey(expensesId)) {
+                    BigDecimal bigDecimal = profitAnalysisDtoMap.get(expensesId);
+                    profitAnalysisDto.setApplyAmount(bigDecimal);
+                }
+            }
+        }else {
+            resultList.addAll(profitAnalysisMapper.getAllAccountExpenses(profitAnalysisQueryDto));
+        }
+        return getTree(resultList);
+    }
+
+    /**
+     * 组装树形结构结果集方法
+     */
+
+    public List<ProfitAnalysisDto> getTree(List<ProfitAnalysisDto> list){
+
+        return list.stream().filter(accountExpenses -> accountExpenses.getParentId().equals("0"))
+                .peek(accountExpenses -> accountExpenses.setChildren(getChildren(accountExpenses,list))).collect(Collectors.toList());
+    }
+
+    public List<ProfitAnalysisDto> getChildren(ProfitAnalysisDto user,List<ProfitAnalysisDto> userList){
+        return userList.stream().filter(u -> Objects.equals(u.getParentId(),user.getExpensesId())).map(
+                u -> {
+                    u.setChildren(getChildren(u,userList));
+                    return u;
+                }
+        ).collect(Collectors.toList());
+    }
+
+
     /**
     /**
      *  @version
      *  @version
      *  @author: hxl
      *  @author: hxl

+ 19 - 0
src/main/java/com/ydtech/modules/console/dao/ProfitAnalysisMapper.java

@@ -0,0 +1,19 @@
+package com.ydtech.modules.console.dao;
+
+import com.ydtech.modules.admin.model.report.profitAnalysis.ProfitAnalysisDto;
+import com.ydtech.modules.admin.model.report.profitAnalysis.ProfitAnalysisQueryDto;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.HashMap;
+import java.util.List;
+
+@Mapper
+public interface ProfitAnalysisMapper {
+    List<ProfitAnalysisDto> getAllAccountExpenses(@Param("vo") ProfitAnalysisQueryDto profitAnalysisQueryDto);
+
+    List<ProfitAnalysisDto> getAllAccountExpensesId(@Param("vo") ProfitAnalysisQueryDto profitAnalysisQueryDto);
+
+    List<ProfitAnalysisDto> selectAccountExpenses(@Param("vo") ProfitAnalysisQueryDto profitAnalysisQueryDto);
+
+}

+ 130 - 0
src/main/resources/mapper/modules/console/ProfitAnalysisMapper.xml

@@ -0,0 +1,130 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ydtech.modules.console.dao.ProfitAnalysisMapper">
+
+
+    <select id="getAllAccountExpenses" resultType="com.ydtech.modules.admin.model.report.profitAnalysis.ProfitAnalysisDto">
+
+        select iae.expenses_id as "expensesId",
+               iae.parent_id as "parentId",
+               iae.category as "category",
+               a.applyAmount as "applyAmount"
+        from inv_account_expenses iae
+        left  join  (
+            SELECT
+                b.expensesId,
+                sum( CAST(a.apply_amount AS DECIMAL ( 10, 2 )) ) AS "applyAmount"
+            FROM
+                inv_account_operate a
+                    LEFT JOIN (
+                    SELECT
+                        a.category AS "aCategory",
+                        b.category AS "bCategory",
+                        a.expenditure_details AS "expenditureDetails",
+                        a.expenses_id AS "expensesId"
+                    FROM
+                        inv_account_expenses a
+                            LEFT JOIN inv_account_expenses b ON a.parent_id = b.expenses_id
+                    WHERE
+                        b.category IS NOT NULL
+                ) b ON a.fund_use = b.bCategory
+                    AND a.fund_fen = b.aCategory
+            WHERE
+                a.out_card_num IN (
+                    SELECT
+                        bank_card_num
+                    FROM
+                        inv_account_card iac
+                            LEFT JOIN inv_account ia ON iac.account_id = ia.account_id
+                    WHERE
+                        ia.del_flag = '0'
+                      AND ia.outer_flag LIKE concat( '%', '0', '%' )
+                )
+              AND a.revenue_outlay = '1'
+              AND a.del_flag = '0'
+              <if test="vo.expensesType !=null  and  vo.expensesType !='' ">
+                  AND b.expenditureDetails  =#{vo.expensesType}
+              </if>
+
+              <if test="vo.yearAndMonth !=null and vo.yearAndMonth !=''">
+                  AND DATE_FORMAT( a.create_time, '%Y-%m' )=#{vo.yearAndMonth}
+              </if>
+            <if test="vo.expensesIds !=null  and  vo.expensesIds !='' and vo.expensesIds.size()>0 ">
+                and b.expensesId in
+                <foreach collection="vo.expensesIds" item="item" open="(" separator="," close=")">
+                    #{item}
+                </foreach>
+            </if>
+            GROUP BY
+                b.expensesId
+        ) a  on a.expensesId  =iae.expenses_id
+    </select>
+
+
+    <select id="getAllAccountExpensesId" resultType="com.ydtech.modules.admin.model.report.profitAnalysis.ProfitAnalysisDto">
+        SELECT
+        b.expensesId,
+        sum( CAST(a.apply_amount AS DECIMAL ( 10, 2 )) ) AS "applyAmount"
+        FROM
+        inv_account_operate a
+        LEFT JOIN (
+        SELECT
+        a.category AS "aCategory",
+        b.category AS "bCategory",
+        a.expenditure_details AS "expenditureDetails",
+        a.expenses_id AS "expensesId"
+        FROM
+        inv_account_expenses a
+        LEFT JOIN inv_account_expenses b ON a.parent_id = b.expenses_id
+        WHERE
+        b.category IS NOT NULL
+        ) b ON a.fund_use = b.bCategory
+        AND a.fund_fen = b.aCategory
+        WHERE
+        a.out_card_num IN (
+        SELECT
+        bank_card_num
+        FROM
+        inv_account_card iac
+        LEFT JOIN inv_account ia ON iac.account_id = ia.account_id
+        WHERE
+        ia.del_flag = '0'
+        AND ia.outer_flag LIKE concat( '%', '0', '%' )
+        )
+        AND a.revenue_outlay = '1'
+        AND a.del_flag = '0'
+        <if test="vo.expensesType !=null  and  vo.expensesType !='' ">
+            <choose>
+                <when test="vo.expensesType !=3 ">
+                    AND b.expenditureDetails = #{vo.expensesType}
+                </when>
+                <when test="vo.expensesType = 3 ">
+                    AND b.expenditureDetails !=  #{vo.expensesType}
+                </when>
+            </choose>
+        </if>
+
+        <if test="vo.yearAndMonth !=null and vo.yearAndMonth !=''">
+            AND DATE_FORMAT( a.create_time, '%Y-%m' )=#{vo.yearAndMonth}
+        </if>
+        <if test="vo.expensesIds !=null  and  vo.expensesIds !='' and vo.expensesIds.size()>0 ">
+            and b.expensesId in
+            <foreach collection="vo.expensesIds" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        GROUP BY
+        b.expensesId
+    </select>
+
+    <select id="selectAccountExpenses" resultType="com.ydtech.modules.admin.model.report.profitAnalysis.ProfitAnalysisDto">
+        select iae.expenses_id as "expensesId",
+        iae.parent_id as "parentId",
+        iae.category as "category"
+        from inv_account_expenses iae
+    </select>
+
+
+</mapper>