浏览代码

数据报表:财务数据-经营利润

lipf 1 月之前
父节点
当前提交
f80751b521

+ 29 - 0
commons/src/main/java/com/jzg/commons/entity/report/dto/ReportOperatingProfitDataDto.java

@@ -88,4 +88,33 @@ public class ReportOperatingProfitDataDto {
     @ColumnWidth(20)
     @Schema(description = "实付")
     private BigDecimal paidMoney;
+
+    /**
+     * 将另一个 DTO 的数值字段累加到当前对象中。
+     * 注意:此方法会修改当前对象(this)。
+     *
+     * @param other 要合并的另一个 DTO 对象
+     */
+    public void merge(ReportOperatingProfitDataDto other) {
+        if (other == null) {
+            return;
+        }
+        this.sumPremium = addSafe(this.sumPremium, other.sumPremium);
+        this.receivableMoney = addSafe(this.receivableMoney, other.receivableMoney);
+        this.meetMoney = addSafe(this.meetMoney, other.meetMoney);
+        this.profitMoney = addSafe(this.profitMoney, other.profitMoney);
+        this.receivedMoney = addSafe(this.receivedMoney, other.receivedMoney);
+        this.paidMoney = addSafe(this.paidMoney, other.paidMoney);
+        // 如果还有其他数值类型字段,请在此处继续添加
+    }
+
+    /**
+     * 安全的 BigDecimal 累加,防止空指针异常。
+     * 规则:null + value = value; value + null = value; null + null = null
+     */
+    private BigDecimal addSafe(BigDecimal a, BigDecimal b) {
+        if (a == null) return b;
+        if (b == null) return a;
+        return a.add(b);
+    }
 }

+ 13 - 0
consoleStatistics/src/main/java/com/jzg/console/client/FeeAuditClient.java

@@ -6,9 +6,12 @@ import com.jzg.commons.entity.dto.FeeAuditParam;
 import com.jzg.commons.entity.orders.vo.FeeAuditSummaryParam;
 import com.jzg.commons.entity.orders.vo.FeeAuditSummaryVO;
 import com.jzg.commons.entity.orders.vo.FeeAuditVo;
+import com.jzg.commons.entity.report.dto.ReportOperatingProfitDataDto;
 import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestParam;
 
 import java.util.List;
 
@@ -34,4 +37,14 @@ public interface FeeAuditClient {
     @PostMapping("/feeAudit/queryAuditSummary")
     HttpResult<List<FeeAuditSummaryVO>> queryAuditSummary(@RequestBody FeeAuditSummaryParam param);
 
+    /**
+     * 查询指定年份的经营利润
+     *
+     * @param year 年份,例如 2026
+     * @author lipf
+     * @date 2026/7/25 11:22
+     */
+    @GetMapping("/feeAudit/queryOperatingProfits")
+    HttpResult<List<ReportOperatingProfitDataDto>> queryOperatingProfits(@RequestParam("year") String year);
+
 }

+ 139 - 14
consoleStatistics/src/main/java/com/jzg/console/service/impl/ReportOperatingProfitDataServiceImpl.java

@@ -1,24 +1,22 @@
 package com.jzg.console.service.impl;
 
 
-import com.alibaba.excel.annotation.ExcelProperty;
-import com.alibaba.excel.annotation.write.style.ColumnWidth;
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.jzg.commons.entity.report.dto.ReportOperatingProfitDataDto;
-import com.jzg.commons.entity.report.dto.ReportRiskDataManageDetailDto;
-import com.jzg.commons.entity.report.dto.ReportRiskDataManageDto;
-import com.jzg.commons.entity.report.dto.ReportSalesmanDataManageDto;
 import com.jzg.commons.entity.report.vo.ReportSearchCommonVo;
+import com.jzg.console.client.FeeAuditClient;
 import com.jzg.console.service.ReportOperatingProfitDataService;
-import com.jzg.console.service.ReportReceivableDataService;
-import io.swagger.v3.oas.annotations.media.Schema;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  *  @version
@@ -28,6 +26,12 @@ import java.util.List;
  */
 @Service
 public class ReportOperatingProfitDataServiceImpl extends ReportBaseServiceImpl implements ReportOperatingProfitDataService {
+
+    private static final Logger log = LoggerFactory.getLogger(ReportOperatingProfitDataServiceImpl.class);
+
+    @Autowired
+    private FeeAuditClient feeAuditClient;
+
     /**
      *  @version
      *  @author: hxl
@@ -36,16 +40,137 @@ public class ReportOperatingProfitDataServiceImpl extends ReportBaseServiceImpl
      */
     @Override
     public IPage<?> getPageListByParams(ReportSearchCommonVo reportSearchCommonVo) {
-        Page<ReportOperatingProfitDataDto> page = new Page<>(reportSearchCommonVo.getPageNo(), reportSearchCommonVo.getPageSize());
+        log.info("财务数据-经营利润-列表查询: reportSearchCommonVo=[{}]", JSONUtil.toJsonStr(reportSearchCommonVo));
+        String sql1 = """
+                
+                select
+                	a.ym ,
+                	sum(a.total_premium),
+                	sum(a.total_receivable_premium)
+                	-- ,sum(a.total_payable_premium)
+                from
+                	(
+                	select
+                		io.id as order_no,
+                		io.signing_time ,
+                		DATE_FORMAT(io.signing_time, '%Y-%m') as ym,
+                		ifo.total_premium ,
+                		ifo.total_payable_premium ,
+                		ifo.total_receivable_premium,
+                		io.system_code
+                	from
+                		ins_fee_orders ifo
+                	left join ins_orders io on
+                		ifo.order_no = io.id
+                	where
+                		io.system_code = 'G111'
+                		and io.signing_time >= '2016-01-01 00:00:00'
+                ) as a
+                group by a.ym
+                order by a.ym asc
+             
+                """;
+
+        String sql11 = """
+                
+                select
+                	a.ym ,
+                	sum(a.total_payable_premium)
+                from
+                	(
+                	select
+                		io.id as order_no,
+                		io.signing_time ,
+                		DATE_FORMAT(io.signing_time, '%Y-%m') as ym,
+                		ifo.total_premium ,
+                		ifo.total_payable_premium ,
+                		ifo.total_receivable_premium,
+                		io.system_code
+                	from
+                		ins_fee_orders ifo
+                	left join ins_orders io on
+                		ifo.order_no = io.id
+                	where
+                		io.system_code = 'G111'
+                		and io.signing_time >= '2016-01-01 00:00:00'
+                		and io.id in (
+                		select
+                			ifa.order_no
+                		from
+                			ins_fee_audit ifa
+                		where
+                			ifa.audit_status = 1
+                )
+                ) as a
+                group by	a.ym
+                order by	a.ym asc
+                
+                """;
+
+        String sql2 = """
+                    select
+                    	sum(ipiis.actual_received_amount),
+                    	DATE_FORMAT(ipiis.receive_payment_date, '%Y-%m') as ym
+                    from
+                    	ins_ply_income_invoice_settlement ipiis
+                    where
+                    	receive_payment_date >= '2026-07-01 00:00:00'
+                    	and ipiis.system_code = 'G111'
+                    group by ym
+                
+                """;
+
+        String sql3 = """
+                select
+                	DATE_FORMAT(suacl.create_time, '%Y-%m') as ym,
+                	sum(suacl.amount)
+                from
+                	sys_user_account_change_log suacl
+                where
+                	suacl.system_code = 'G111'
+                	and suacl.amount < 0
+                	and suacl.create_time >= '2026-01-01 00:00:00'
+                group by
+                	ym
+                """;
+
+        Map<String, ReportOperatingProfitDataDto> map1 = new HashMap<>();
+        Map<String, ReportOperatingProfitDataDto> map2 = new HashMap<>();
+        Map<String, ReportOperatingProfitDataDto> map3 = new HashMap<>();
+        Map<String, ReportOperatingProfitDataDto> map4 = new HashMap<>();
+        List<Map<String, ReportOperatingProfitDataDto>>  allMaps = new ArrayList<>();
+        Map<String, ReportOperatingProfitDataDto> compMaps = this.mergeMaps(allMaps);
+        List<ReportOperatingProfitDataDto> values = new ArrayList<>(compMaps.values());
+
+
+        // Page<ReportOperatingProfitDataDto> page = new Page<>(reportSearchCommonVo.getPageNo(), reportSearchCommonVo.getPageSize());
         IPage<ReportOperatingProfitDataDto> pageList = new Page<ReportOperatingProfitDataDto>();
-        List<ReportOperatingProfitDataDto> list = getList();
-        pageList.setRecords(list);
-        pageList.setTotal(1l);
+        pageList.setRecords(values);
+        pageList.setTotal(CollUtil.size(values));
         pageList.setCurrent(reportSearchCommonVo.getPageNo());
         pageList.setPages(reportSearchCommonVo.getPageNo());
         pageList.setPages(reportSearchCommonVo.getPageSize());
         return pageList;
     }
+
+
+    public Map<String, ReportOperatingProfitDataDto> mergeMaps(List<Map<String, ReportOperatingProfitDataDto>> mapList) {
+        return mapList.stream()
+                // 1. 将 List<Map> 展平为 Stream<Map.Entry>
+                .flatMap(map -> map.entrySet().stream())
+                // 2. 收集为新的 LinkedHashMap (保持插入顺序)
+                .collect(Collectors.toMap(
+                        Map.Entry::getKey,
+                        Map.Entry::getValue,
+                        (dto1, dto2) -> {
+                            // 3. 遇到相同 Key,调用 merge 方法累加字段
+                            dto1.merge(dto2);
+                            return dto1;
+                        },
+                        HashMap::new // 保证结果 Map 是 LinkedHashMap
+                ));
+    }
+
     /**
      *  @version
      *  @author: hxl

+ 17 - 0
tenant/insurance/quotation-summary/src/main/java/com/jzg/quotation/summary/controller/InsFeeOrderController.java

@@ -1,9 +1,11 @@
 package com.jzg.quotation.summary.controller;
 
 import cn.hutool.json.JSONUtil;
+import com.jzg.commons.core.base.BaseController;
 import com.jzg.commons.core.page.HttpResult;
 import com.jzg.commons.entity.dto.InsFeeOrdersParam;
 import com.jzg.commons.entity.po.InsFeeOrders;
+import com.jzg.commons.entity.report.dto.ReportOperatingProfitDataDto;
 import com.jzg.quotation.summary.entity.dto.RightsAmountUpdateDto;
 import com.jzg.quotation.summary.service.InsFeeOrdersService;
 import io.swagger.v3.oas.annotations.Operation;
@@ -26,6 +28,8 @@ import java.util.List;
 public class InsFeeOrderController {
     @Autowired
     private InsFeeOrdersService insFeeOrdersService;
+    @Autowired
+    private BaseController baseController;
 
     private static final Logger log = LoggerFactory.getLogger(InsFeeOrderController.class);
 
@@ -88,4 +92,17 @@ public class InsFeeOrderController {
         return insFeeOrdersService.updateAvailableAmount(rightsAmountUpdateDto.getOrderNo(),rightsAmountUpdateDto.getAvailableAmount());
     }
 
+
+    /**
+     * 查询指定年份的经营利润
+     *
+     * @param year 年份,例如 2026
+     * @author lipf
+     * @date 2026/7/25 11:22
+     */
+    @GetMapping("/feeAudit/queryOperatingProfits")
+    HttpResult<List<ReportOperatingProfitDataDto>> queryOperatingProfits(@RequestParam("year") String year){
+        String systemCode = baseController.getSystemCode();
+        return HttpResult.ok(insFeeOrdersService.queryOperatingProfits(year,systemCode));
+    }
 }

+ 10 - 0
tenant/insurance/quotation-summary/src/main/java/com/jzg/quotation/summary/service/InsFeeOrdersService.java

@@ -5,6 +5,7 @@ import com.jzg.commons.core.page.HttpResult;
 import com.jzg.commons.entity.dto.CostCalculateRespVO;
 import com.jzg.commons.entity.dto.InsFeeOrdersParam;
 import com.jzg.commons.entity.po.InsFeeOrders;
+import com.jzg.commons.entity.report.dto.ReportOperatingProfitDataDto;
 import com.jzg.commons.entity.vo.PtlAgreementCostRatioVo;
 
 import java.math.BigDecimal;
@@ -57,4 +58,13 @@ public interface InsFeeOrdersService extends IService<InsFeeOrders> {
      */
     InsFeeOrders updateFeeRatio(String orderNo, BigDecimal jqInletRatio, BigDecimal syInletRatio, BigDecimal jyInletRatio,
                                 BigDecimal jqExportRatio, BigDecimal syExportRatio, BigDecimal jyExportRatio);
+
+    /**
+     * 查询指定年份的经营利润
+     *
+     * @param year 年份,例如 2026
+     * @author lipf
+     * @date 2026/7/25 11:22
+     */
+    List<ReportOperatingProfitDataDto> queryOperatingProfits(String year, String systemCode);
 }

+ 17 - 0
tenant/insurance/quotation-summary/src/main/java/com/jzg/quotation/summary/service/impl/InsFeeOrdersServiceImpl.java

@@ -14,6 +14,7 @@ import com.jzg.commons.entity.orders.po.InsOrders;
 import com.jzg.commons.entity.orders.po.InsOrdersCosts;
 import com.jzg.commons.entity.po.InsFeeOrders;
 import com.jzg.commons.entity.po.PtlAgreement;
+import com.jzg.commons.entity.report.dto.ReportOperatingProfitDataDto;
 import com.jzg.commons.entity.vo.PtlAgreementCostRatioVo;
 import com.jzg.commons.exception.SystemException;
 import com.jzg.commons.util.AssertionUtils;
@@ -710,4 +711,20 @@ public class InsFeeOrdersServiceImpl extends ServiceImpl<InsFeeOrdersMapper, Ins
         }
         return initAmout;
     }
+
+    /**
+     * 查询指定年份的经营利润
+     *
+     * @param year       年份,例如 2026
+     * @param systemCode
+     * @author lipf
+     * @date 2026/7/25 11:22
+     */
+    @Override
+    public List<ReportOperatingProfitDataDto> queryOperatingProfits(String year, String systemCode) {
+        log.info("查询租户[{}]在指定年份[{}]的经营利润之保费等信息",systemCode,year);
+
+
+        return List.of();
+    }
 }