Kaynağa Gözat

Merge remote-tracking branch 'origin/dev_jzg_lipf_v20260622' into dev_jzg_lipf_v20260622

lipf 1 ay önce
ebeveyn
işleme
cfdb8293c2

+ 168 - 0
commons/src/main/java/com/jzg/commons/entity/finance/vo/ExportPlatFormReceivableVO.java

@@ -0,0 +1,168 @@
+package com.jzg.commons.entity.finance.vo;
+
+import com.alibaba.excel.annotation.ExcelIgnore;
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.jzg.commons.core.base.BaseModel;
+import com.jzg.commons.entity.po.InsFeeOrders;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.io.Serial;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
+@EqualsAndHashCode(callSuper = true)
+@Data
+@Schema(description = "财务应收表")
+public class ExportPlatFormReceivableVO extends BaseModel {
+
+    @Serial
+    private static final long serialVersionUID = 6161862008963938376L;
+
+    @ExcelIgnore
+    private String id;
+
+    // ==================== 以下为按表头顺序导出的字段 ====================
+
+    @Schema(description = "子订单号")
+    @ExcelProperty(value = "子订单号", index = 0)
+    private String orderNo;
+
+    @Schema(description = "协议号")
+    @ExcelProperty(value = "协议号", index = 1)
+    private String agreementId;
+
+    @Schema(description = "签单日期 yyyy-mm-dd 格式")
+    @TableField(exist = false)
+    @ExcelProperty(value = "签单日期", index = 2)
+    private String signDate;
+
+    @Schema(description = "车牌号")
+    @ExcelProperty(value = "车牌号", index = 3)
+    private String licenseNo;
+
+    @Schema(description = "被保险人")
+    @ExcelProperty(value = "被保险人", index = 4)
+    private String insuredPerson;
+
+    @Schema(description = "保险公司名称")
+    @TableField(exist = false)
+    @ExcelProperty(value = "保险公司名称", index = 5)
+    private String companyName;
+
+    @Schema(description = "险种")
+    @ExcelProperty(value = "险种", index = 6)
+    private String productName;
+
+    @Schema(description = "保司机构")
+    @TableField(exist = false)
+    @ExcelProperty(value = "保司机构", index = 7)
+    private String partnerCompanySimplyName;
+
+    @Schema(description = "对接人")
+    @ExcelProperty(value = "对接人", index = 8)
+    private String contactPerson;
+
+    @Schema(description = "交强险保单号")
+    @ExcelProperty(value = "交强险保单号", index = 9)
+    private String jqPolicyNo;
+
+    @Schema(description = "商业保单号")
+    @ExcelProperty(value = "商业保单号", index = 10)
+    private String syPolicyNo;
+
+    @Schema(description = "非车保单号")
+    @ExcelProperty(value = "非车保单号", index = 11)
+    private String jyPolicyNo;
+
+    @Schema(description = "交强险保费")
+    @ExcelProperty(value = "交强险保费", index = 12)
+    private String jqPremium;
+
+    @Schema(description = "车船税")
+    @ExcelProperty(value = "车船税", index = 13)
+    private String taxPremium;
+
+    @Schema(description = "商业险保费")
+    @ExcelProperty(value = "商业险保费", index = 14)
+    private String syPremium;
+
+    @Schema(description = "非车保费")
+    @ExcelProperty(value = "非车保费", index = 15)
+    private String jyPremium;
+
+    @Schema(description = "交强险应收比例")
+    @TableField(exist = false)
+    @ExcelProperty(value = "交强险应收比例", index = 16)
+    private String jqTotalProportion;
+
+    @Schema(description = "交强险手续费比例")
+    @ExcelProperty(value = "交强险手续费比例", index = 17)
+    private String jqSuperviseCostsProportion;
+
+    @Schema(description = "交强险非跟单比例")
+    @ExcelProperty(value = "交强险非跟单比例", index = 18)
+    private String jqOtherCostsProportion;
+
+    @Schema(description = "商业应收比例")
+    @TableField(exist = false)
+    @ExcelProperty(value = "商业应收比例", index = 19)
+    private String syTotalProportion;
+
+    @Schema(description = "商业手续费比例")
+    @ExcelProperty(value = "商业手续费比例", index = 20)
+    private String sySuperviseCostsProportion;
+
+    @Schema(description = "商业非跟单比例")
+    @ExcelProperty(value = "商业非跟单比例", index = 21)
+    private String syOtherCostsProportion;
+
+    @Schema(description = "非车应收比例")
+    @TableField(exist = false)
+    @ExcelProperty(value = "非车应收比例", index = 22)
+    private String jyTotalProportion;
+
+    @Schema(description = "非车手续费比例")
+    @ExcelProperty(value = "非车手续费比例", index = 23)
+    private String jySuperviseCostsProportion;
+
+    @Schema(description = "非车非跟单比例")
+    @ExcelProperty(value = "非车非跟单比例", index = 24)
+    private String jyOtherCostsProportion;
+
+    @Schema(description = "手续费金额")
+    @TableField(exist = false)
+    @ExcelProperty(value = "手续费金额", index = 25)
+    private String superviseCostsPremiums;
+
+    @Schema(description = "非跟单金额")
+    @TableField(exist = false)
+    @ExcelProperty(value = "非跟单金额", index = 26)
+    private String otherCostsPremiums;
+
+    @Schema(description = "创建日期")
+    @TableField(exist = false)
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ExcelProperty(value = "创建日期", index = 27)
+    private LocalDateTime createTime;
+
+    @Schema(description = "结算日期")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ExcelProperty(value = "结算日期", index = 28)
+    private LocalDateTime settlementTime;
+
+    @Schema(description = "结算人")
+    @TableField(exist = false)
+    @ExcelProperty(value = "结算人", index = 29)
+    private String settlementPerson;
+
+    @Schema(description = "结算状态")
+    @TableField(exist = false)
+    @ExcelProperty(value = "结算状态", index = 30)
+    private String settlementStatusName;
+
+
+}

+ 36 - 2
tenant/organization/src/main/java/com/jzg/organization/service/impl/ReceivableServiceImpl.java

@@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.collection.ListUtil;
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.date.LocalDateTimeUtil;
 import cn.hutool.core.lang.tree.Tree;
 import cn.hutool.core.lang.tree.TreeNodeConfig;
 import cn.hutool.core.lang.tree.TreeUtil;
@@ -54,6 +55,7 @@ import com.jzg.organization.mapper.*;
 import com.jzg.organization.service.ReceivableService;
 import com.jzg.organization.service.SysUserJzgInfoSalesmanService;
 import com.jzg.organization.service.importincome.ImportIncomeService;
+import com.jzg.organization.utils.IncomeInvoiceLinkUtil;
 import org.apache.ibatis.annotations.Param;
 import org.jetbrains.annotations.NotNull;
 import org.redisson.api.RBucket;
@@ -88,6 +90,7 @@ import java.util.function.BiConsumer;
 import java.util.function.Function;
 import java.util.function.Predicate;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * @author tz
@@ -5474,11 +5477,42 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
 
         List<InsPlyIncome> receivableList = baseMapper.getReceivableList(receivableQueryVo);
         receivableList = this.fillOtherInfo(receivableList, null);
+        // 类型转换
+        List<ExportPlatFormReceivableVO> exportPlatFormReceivableVOS = BeanUtil.copyToList(receivableList, ExportPlatFormReceivableVO.class);
+        // 用ins_ply_income的id关联查到ins_ply_income_invoice_link再关联到ins_ply_income_invoice_settlement,取出结算日期、结算人
+        if (CollUtil.isNotEmpty(exportPlatFormReceivableVOS)) {
+            //1.拿到所有incomeId集合
+            List<Long> incomeIdList = exportPlatFormReceivableVOS.stream()
+                    .map(item -> Long.valueOf(item.getId()))
+                    .collect(Collectors.toList());
+
+            Map<String, InsPlyIncomeInvoiceSettlement> settlementMap = IncomeInvoiceLinkUtil.querySettlementByIncomeList(incomeIdList, insPlyIncomeInvoiceLinkMapper, insPlyIncomeInvoiceSettlementMapper);
+            Map<String, List<InsPlyIncomeInvoiceLink>> linkGroupByIncomeId = IncomeInvoiceLinkUtil.queryInvoiceLinkByIncomeId(incomeIdList, insPlyIncomeInvoiceLinkMapper);
+
+            //回填vo
+            for (ExportPlatFormReceivableVO vo : exportPlatFormReceivableVOS) {
+                List<InsPlyIncomeInvoiceLink> linkList = linkGroupByIncomeId.getOrDefault(vo.getId(), CollUtil.newArrayList());
+                if (CollUtil.isEmpty(linkList)) {
+                    continue;
+                }
+                // 取第一条有结算数据的link,可按业务修改:比如取最新一条
+                for (InsPlyIncomeInvoiceLink link : linkList) {
+                    InsPlyIncomeInvoiceSettlement settlement = settlementMap.get(link.getInvoiceId());
+                    if (settlement != null) {
+                        //结算日期
+                        vo.setSettlementTime(LocalDateTimeUtil.of(settlement.getReceivePaymentDate()));
+                        //结算人:创建人即为结算操作人
+                        vo.setSettlementPerson(settlement.getCreateBy());
+                        break;
+                    }
+                }
+            }
+        }
 
         // 调用动态导出
         return exportBaseService.upLoadFile(
-                InsPlyIncome.class,
-                receivableList,
+                ExportPlatFormReceivableVO.class,
+                exportPlatFormReceivableVOS,
                 "平台协议应收-批量导入-导出-" + Instant.now()
         );
     }

+ 93 - 0
tenant/organization/src/main/java/com/jzg/organization/utils/IncomeInvoiceLinkUtil.java

@@ -0,0 +1,93 @@
+package com.jzg.organization.utils;
+
+import cn.hutool.core.collection.CollUtil;
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.util.*;
+import java.util.stream.Collectors;
+
+import com.jzg.commons.entity.finance.po.InsPlyIncomeInvoiceLink;
+import com.jzg.commons.entity.finance.po.InsPlyIncomeInvoiceSettlement;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.jzg.organization.mapper.InsPlyIncomeInvoiceLinkMapper;
+import com.jzg.organization.mapper.InsPlyIncomeInvoiceSettlementMapper;
+
+public class IncomeInvoiceLinkUtil {
+
+    private IncomeInvoiceLinkUtil() {
+    }
+
+    /**
+     * 根据incomeId集合 查询应收开票结算
+     * @param incomeIdList 应收主表id集合
+     * @param linkMapper link表mapper
+     * @param settlementMapper settlement表mapper
+     * @return key: invoiceId, value: settlement结算记录,旧值会被新值替换,按创建时间倒序
+     */
+    public static Map<String, InsPlyIncomeInvoiceSettlement> querySettlementByIncomeList(List<Long> incomeIdList,
+                                                                          InsPlyIncomeInvoiceLinkMapper linkMapper,
+                                                                          InsPlyIncomeInvoiceSettlementMapper settlementMapper) {
+        if (CollUtil.isEmpty(incomeIdList)) {
+            return null;
+        }
+
+        List<InsPlyIncomeInvoiceLink> invoiceLinkList = getInvoiceLinkList(incomeIdList, linkMapper);
+        if (CollUtil.isEmpty(invoiceLinkList)) {
+            return null;
+        }
+
+        // 2、拿到所有invoiceId
+        List<String> invoiceIdList = invoiceLinkList.stream()
+                .map(InsPlyIncomeInvoiceLink::getInvoiceId)
+                .filter(Objects::nonNull)
+                .collect(Collectors.toList());
+
+        // 3、key: invoiceId, value: settlement结算记录
+        Map<String, InsPlyIncomeInvoiceSettlement> settlementMap = new HashMap<>();
+        if (CollUtil.isNotEmpty(invoiceIdList)) {
+            LambdaQueryWrapper<InsPlyIncomeInvoiceSettlement> settlementWrapper = new LambdaQueryWrapper<>();
+            settlementWrapper.in(InsPlyIncomeInvoiceSettlement::getInvoiceId, invoiceIdList);
+            settlementWrapper.eq(InsPlyIncomeInvoiceSettlement::getIsDelete, 0);
+            List<InsPlyIncomeInvoiceSettlement> settlementList = settlementMapper.selectList(settlementWrapper);
+            // 按创建时间倒序
+            settlementList.sort((a,b)->b.getCreateTime().compareTo(a.getCreateTime()));
+            settlementMap = settlementList.stream()
+                    .collect(Collectors.toMap(InsPlyIncomeInvoiceSettlement::getInvoiceId, s -> s, (exist, newVal) -> newVal));
+        }
+
+
+
+        return settlementMap;
+    }
+
+
+    /**
+     * 根据incomeId获取invoiceLink的Map分组
+     * @param incomeIdList
+     * @param linkMapper
+     * @return
+     */
+    public static Map<String, List<InsPlyIncomeInvoiceLink>> queryInvoiceLinkByIncomeId(List<Long> incomeIdList,
+                                                                                   InsPlyIncomeInvoiceLinkMapper linkMapper) {
+
+        List<InsPlyIncomeInvoiceLink> invoiceLinkList = getInvoiceLinkList(incomeIdList, linkMapper);
+        if (CollUtil.isEmpty(invoiceLinkList)) {
+            return null;
+        }
+
+        // 按incomeId分组,一个income可能多条link
+        return invoiceLinkList.stream()
+                .collect(Collectors.groupingBy(InsPlyIncomeInvoiceLink::getIncomeId));
+    }
+
+
+    // 单纯获取InsPlyIncomeInvoiceLink的列表
+    public static List<InsPlyIncomeInvoiceLink> getInvoiceLinkList(List<Long> incomeIdList, InsPlyIncomeInvoiceLinkMapper linkMapper) {
+        // 1、查询link关联表
+        LambdaQueryWrapper<InsPlyIncomeInvoiceLink> linkWrapper = new LambdaQueryWrapper<>();
+        linkWrapper.in(InsPlyIncomeInvoiceLink::getIncomeId, incomeIdList);
+        linkWrapper.eq(InsPlyIncomeInvoiceLink::getIsDelete, 0);
+        return linkMapper.selectList(linkWrapper);
+    }
+}

+ 2 - 0
tenant/organization/src/main/resources/mapper/SysUserMapper.xml

@@ -64,6 +64,8 @@
                 AND su.mobile = #{mobile}
             </if>
         </where>
+        order by su.id desc
+        LIMIT 1
     </select>
 
     <select id="getUserRoleName" resultType="String">