Commit b589e7fbe3dd80e2b659a29bd4d33c8d84b2ca4f

Authored by 房远帅
1 parent 2f564a2e

采购-资金支付:请购单基础信息(临时提交)

Showing 33 changed files with 2699 additions and 0 deletions
@@ -143,6 +143,48 @@ public GetXxxBo(Xxx dto) { @@ -143,6 +143,48 @@ public GetXxxBo(Xxx dto) {
143 **后果**:编译失败;IDE 诊断若未及时覆盖会带到提交环节才暴露。 143 **后果**:编译失败;IDE 诊断若未及时覆盖会带到提交环节才暴露。
144 **正确做法**:使用工具类(StringUtil/CollectionUtil/NumberUtil 等)前先 Grep 项目内该方法既有用法确认存在;字符串等值判断项目内用 `java.util.Objects.equals(a, b)`(自带 null 安全),或 Grep StringUtil 源码/既有调用确认真实方法名。 144 **正确做法**:使用工具类(StringUtil/CollectionUtil/NumberUtil 等)前先 Grep 项目内该方法既有用法确认存在;字符串等值判断项目内用 `java.util.Objects.equals(a, b)`(自带 null 安全),或 Grep StringUtil 源码/既有调用确认真实方法名。
145 145
  146 +## 24. 「可制单」判定在下拉、提交校验、按钮标记三处必须复用同一套逻辑
  147 +
  148 +**坑**:新增单据时,可制单下拉按 A 口径过滤,create 提交按 B 口径校验,来源单的前端按钮标记按 C 口径(或根本没有标记),三处各自维护条件,改一处漏两处。实证:请款单里结算比例100%的仓库收料单只在下拉里排除,收料单按钮仍显示;买断自提多车收料单按 receiveId 判占用,同一计划三张收料单可各生成一张尾款请款单(重复付款)。
  149 +**后果**:前端能点、后端拒绝,或后端放行本应禁止的单据,严重时超付/重复付款。
  150 +**正确做法**:把「可制单判定」收敛到一个 private assert 方法(抛具体中文提示);按钮标记用 try-catch 该断言转 boolean,下拉、新增页带出数据全部复用;跨模块按钮标记通过 Service 暴露 `canApplyFromXxx(id)` 供来源单 `fillOperateFlags` 调用。按钮标记字段用 `@TableField(exist = false)`,Bo 加同名字段由 copyProperties 带出,无需改 XML resultMap/SELECT。
  151 +**当前实现(2026-11-10)**:请款单已取消「可制单来源下拉」,改为计划/过磅码单/仓库收料单三个来源单列表统一返回 `showApplyPayment`(true/false),前端按该字段显示「生成请款单」按钮并携带来源单ID进入新增页(`/generateData` 带出数据)。判定入口统一为 `canApplyFromPlan/canApplyFromTicket/canApplyFromReceive`,三者内部均 try-catch 对应的 `assertXxxUsable`,与 `create` 提交校验同源;采购计划在 `fillShowExamineInfo` 内回填,避免另起一套筛选口径。
  152 +
  153 +## 25. 过磅码单作废联动链新增单据时,必须同时补调用
  154 +
  155 +**坑**:过磅码单 `delete()` 里是一串 `xxxService.deleteByWeighingTicketId(id)` 联动(化验送样/化验报告/结算详情/收料单/买断核算/请款单)。新模块只写了自己的 `deleteByWeighingTicketId` 实现,忘了在码单 delete() 里加调用。
  156 +**后果**:码单作废后该模块单据仍然有效,形成孤儿数据。
  157 +**正确做法**:新增「按码单联动作废」方法后,Grep `ProcurementWeighingTicketServiceImpl.delete` 的联动链,确认新方法在调用列表里。查询范围要同时覆盖 `ticket_id = 码单ID` 与 `receive_id IN (该码单下所有收料单ID)` 两类并去重,避免来源收料单未冗余码单ID时漏作废;查收料单ID时不要过滤 deleted(此时收料单已被前面的联动标记作废)。
  158 +
  159 +## 26. 已有码值直接透传,不要二次映射或补中文名称字段
  160 +
  161 +**坑**:请款单 `bizType` 用 `determineBizType(plan.getDeliveryMode())` 做「兜底转换」(非 PICK_UP 一律归 FACTORY_DELIVERY),Swagger 里还预留了 `bizTypeName` 中文名称字段。
  162 +**后果**:来源表原值被改写,null/未知值被伪装成合法业务类型;前后端要维护两套码值和中文映射,口径容易走偏。
  163 +**正确做法**:来源字段本来就是码值时直接 `setBizType(plan.getDeliveryMode())`;判断处统一用同一套常量比较(如 `DELIVERY_MODE_PICK_UP`),不额外生成中文名称字段,`@ApiModelProperty` 只写字段语义不做值翻译。
  164 +
  165 +## 27. 单据自动带出的业务附件要独立字段 + 独立上传接口,并写进制单断言
  166 +
  167 +**坑**:请款单「计划生成时自动带出计划请款附件」直接取了计划的通用附件 `attachment_file_ids`;而计划表根本没有独立的请款附件,也没有「附件已上传」的制单前置校验。通用附件与业务附件(请款附件、签字凭证)语义不同,不能混用。
  168 +**后果**:生成的请款单带出的可能是无关附件或空附件,财务审核无凭证;按钮显示 true 但后端拒绝(或反过来),口径不一致。
  169 +**正确做法**:
  170 +1. 已有表加列按开发流程在 `base.sql` 尾部 `ALTER TABLE ... ADD COLUMN`,不改原 CREATE;Entity、Bo、Mapper `resultMap`、自定义 SQL 的显式 SELECT 列四处同步加。注意 `selectById` 走实体字段会自动带出新列,但分页/详情走自定义 resultMap 会漏值,只测一条路径容易漏改。
  171 +2. 上传走独立接口(如 `PUT /attachment/request`)+ 独立 Vo,Service 内只 `lambdaUpdate().set(两个附件字段)`;不要复用整表 `update`(`BeanUtil.copyProperties(vo, Entity.class)` 会带出 null,还可能覆盖流程/审核字段)。
  172 +3. 把「附件非空」写进唯一的 `assertXxxUsable`;按钮标记 `canApplyFromXxx` try-catch 同一断言,`/generateData` 与 `create` 复用 `buildContext`,三处口径自动一致,无需各自加判断。
  173 +**本次实现(2026-11-10)**:计划新增 `request_file_ids/request_file_names` + `uploadRequestFiles`(Vo 中 `fileIds` @NotBlank,权限复用 `plan-manage:domestic-plan:upload`);`buildContext` 改读计划请款附件;`assertPlanUsable` 增加「请先上传请款附件再生成请款单」。注意子计划 `createSubPlan` 从 Vo 复制,不继承父计划请款附件,拆分后需重新上传。
  174 +
  175 +## 28. 「带出数据」接口改成「调用即建单」时:收敛建单逻辑、幂等、提交前拦截
  176 +
  177 +**坑**:`generateData` 原本只读带出数据、`create` 才落库,两份组装逻辑;改为「调用 generateData 就生成草稿」时若复制一遍 create 的字段填充,后续改口径必然只改一处。GET 落库还会被刷新/预取重复触发;草稿的手填字段为空却可以直接提交审核。
  178 +**后果**:两条路径生成的单据字段不一致;重复请求产生多张单;申请金额为空的草稿进入审核流程。
  179 +**正确做法**:
  180 +1. 抽私有 `buildDraft(source, sourceId, vo)`,`vo=null` 时只写自动字段并跳过 `matchApplyAmount` 等手填校验;`create` 与 `generateData` 共用,只有一份建单口径。
  181 +2. 幂等:按 `source + sourceId + 草稿状态 + deleted=false` 先查已有单,有则直接返回该单 ID,不重复建单。
  182 +3. 生成类接口加 `@Transactional` 和 `@OpLog`;对草稿留空的必填字段,在 `submit` 加拦截(本次:明细 `applyAmount` 为 null 不允许提交)。
  183 +4. 有副作用就别用纯 GET:本次 `@RequestMapping(method={POST, GET})` 保留前端兼容并在 Swagger 标注推荐 POST。
  184 +5. **生成接口只返回落库单据 ID(String),不要组装一份「生成数据 Bo」回传**:前端后续拿 ID 走详情查询(`GetFundPaymentRequestBo` 已含主表 + 明细全部字段),再走 `update` 修改补充,不再有「新增页带出数据」这一环。回传 Bo 等于把详情 Bo 复制一份,字段口径必然分叉,且白查一次主表/明细。
  185 +**本次实现(2026-11-10)**:`requestDate=LocalDate.now()`、`payMethod` 固定「电汇」由 `buildDraft` 统一写入;自动带出来源单信息、请款附件、明细预付金额与合计;对方户名/开户行/账号、请款说明、补充说明附件、明细申请金额留空由 `update` 补充(`update` 的 `matchApplyAmount` 仍要求传全量明细,编辑页从详情 `lines` 取 `planId` 后逐行填 `applyAmount`)。
  186 +**后续调整(2026-11-10)**:删除 `GetFundPaymentGenerateDataBo`(含 `LineBo`)与 `getGenerateData` 中「从落库单据读回再组装 Bo」的整段;Service 方法改名 `generate` 返回 `String`,Controller 返回 `InvokeResult<String>`。接口路径 `/generateData` 保留兼容,Swagger 文案改为「调用即落库,仅返回请款单ID」。
  187 +
146 --- 188 ---
147 189
148 ## 回写模板(新增踩坑时复制) 190 ## 回写模板(新增踩坑时复制)
@@ -3041,3 +3041,73 @@ CREATE TABLE `fund_payment_supplier` ( @@ -3041,3 +3041,73 @@ CREATE TABLE `fund_payment_supplier` (
3041 `update_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间', 3041 `update_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
3042 PRIMARY KEY (`id`) 3042 PRIMARY KEY (`id`)
3043 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT='资金支付-供应商信息'; 3043 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT='资金支付-供应商信息';
  3044 +
  3045 +CREATE TABLE IF NOT EXISTS `fund_payment_request` (
  3046 + `id` varchar(32) NOT NULL COMMENT 'ID',
  3047 + `source` varchar(20) NOT NULL COMMENT '生成来源 PLAN-采购计划(买断自提首付款) TICKET-过磅码单(送货到厂正常) RECEIVE-仓库收料单(尾款/一次性结算/退料)',
  3048 + `source_id` varchar(32) NOT NULL COMMENT '来源单ID(计划ID/码单ID/收料单ID)',
  3049 + `request_kind` varchar(20) NOT NULL DEFAULT 'NORMAL' COMMENT '请款单类型 NORMAL-正常 SUPPLEMENT-补充请款单',
  3050 + `biz_type` varchar(20) NOT NULL COMMENT '类型 PICK_UP-买断自提 FACTORY_DELIVERY-送货到厂(按计划交提货方式自动判定)',
  3051 + `plan_ids` varchar(1000) DEFAULT NULL COMMENT '计划ID集合(逗号分隔)',
  3052 + `plan_codes` varchar(1000) DEFAULT NULL COMMENT '计划编号集合(逗号分隔)',
  3053 + `ticket_id` varchar(32) DEFAULT NULL COMMENT '过磅码单ID(码单来源或收料单关联码单,送货到厂请款链维度)',
  3054 + `ticket_code` varchar(50) DEFAULT NULL COMMENT '过磅码单编号',
  3055 + `receive_id` varchar(32) DEFAULT NULL COMMENT '仓库收料单ID(收料单来源时)',
  3056 + `company_short_id` varchar(32) DEFAULT NULL COMMENT '公司简称ID',
  3057 + `company_short_name` varchar(100) DEFAULT NULL COMMENT '公司名称(公司简称)',
  3058 + `workshop_id` varchar(32) DEFAULT NULL COMMENT '分厂ID',
  3059 + `workshop_name` varchar(100) DEFAULT NULL COMMENT '分厂名称',
  3060 + `request_date` date NOT NULL COMMENT '请款日期(生成请款单的当天日期)',
  3061 + `pay_method` varchar(20) NOT NULL DEFAULT '电汇' COMMENT '付款方式(电汇)',
  3062 + `supplier_id` varchar(32) DEFAULT NULL COMMENT '资金支付供应商信息ID(关联 fund_payment_supplier,对方户名/开户银行/账号来源)',
  3063 + `payee_name` varchar(200) DEFAULT NULL COMMENT '对方户名(供应商信息客户名称)',
  3064 + `bank_name` varchar(200) DEFAULT NULL COMMENT '开户银行(对方户名对应)',
  3065 + `bank_account` varchar(50) DEFAULT NULL COMMENT '账号(对方户名对应)',
  3066 + `request_remark` varchar(500) DEFAULT NULL COMMENT '请款说明(多行文本)',
  3067 + `request_file_ids` varchar(1000) DEFAULT NULL COMMENT '请款附件文件ID集合(计划生成时自动带出计划请款附件,不可改)',
  3068 + `request_file_names` varchar(1000) DEFAULT NULL COMMENT '请款附件文件名称集合',
  3069 + `supplement_remark` varchar(500) DEFAULT NULL COMMENT '补充说明(补充请款单填写、显示)',
  3070 + `supplement_file_ids` varchar(1000) DEFAULT NULL COMMENT '补充说明附件文件ID集合(补充请款单时上传)',
  3071 + `supplement_file_names` varchar(1000) DEFAULT NULL COMMENT '补充说明附件文件名称集合',
  3072 + `other_file_ids` varchar(1000) DEFAULT NULL COMMENT '其它附件文件ID集合(任何状态可上传)',
  3073 + `other_file_names` varchar(1000) DEFAULT NULL COMMENT '其它附件文件名称集合',
  3074 + `total_prepaid_amount` decimal(14,2) DEFAULT NULL COMMENT '合计-预付金额(明细预付金额之和,自动计算)',
  3075 + `total_apply_amount` decimal(14,2) DEFAULT NULL COMMENT '合计-申请金额(明细申请金额之和)',
  3076 + `flow_node` varchar(50) DEFAULT NULL COMMENT '流程节点 GYGLKZJY-供应管理科资金管理员 GYGLKZG-供应管理科主管',
  3077 + `approval_status` varchar(20) NOT NULL COMMENT '审核状态 DRAFT-草稿 AUDIT-审核中 PASS-审核通过 REFUSE-已驳回',
  3078 + `gyglkzg_id` varchar(32) DEFAULT NULL COMMENT '供应管理科主管审核人ID(审核通过时记录)',
  3079 + `gyglkzg_name` varchar(64) DEFAULT NULL COMMENT '供应管理科主管审核人',
  3080 + `deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否作废 0-有效单 1-作废单(作废单只能查看;码单作废联动全部作废)',
  3081 + `create_by_id` varchar(32) NOT NULL COMMENT '创建人ID',
  3082 + `create_by` varchar(64) NOT NULL COMMENT '创建人',
  3083 + `update_by_id` varchar(32) DEFAULT NULL COMMENT '更新人ID',
  3084 + `update_by` varchar(64) DEFAULT NULL COMMENT '更新人',
  3085 + `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  3086 + `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  3087 + PRIMARY KEY (`id`),
  3088 + KEY `idx_fpr_ticket_id` (`ticket_id`),
  3089 + KEY `idx_fpr_source` (`source`, `source_id`)
  3090 +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT='资金支付-请款单';
  3091 +
  3092 +CREATE TABLE IF NOT EXISTS `fund_payment_request_line` (
  3093 + `id` varchar(32) NOT NULL COMMENT 'ID',
  3094 + `request_id` varchar(32) NOT NULL COMMENT '请款单主表ID',
  3095 + `plan_id` varchar(32) NOT NULL COMMENT '采购计划ID',
  3096 + `plan_code` varchar(50) DEFAULT NULL COMMENT '计划编号(自动带出关联的计划编号)',
  3097 + `prepaid_amount` decimal(14,2) DEFAULT NULL COMMENT '预付金额(界限值,按来源自动计算,不可改)',
  3098 + `apply_amount` decimal(14,2) DEFAULT NULL COMMENT '申请金额(数值,保留两位小数)',
  3099 + `create_by_id` varchar(32) DEFAULT NULL COMMENT '创建人ID',
  3100 + `create_by` varchar(64) DEFAULT NULL COMMENT '创建人',
  3101 + `update_by_id` varchar(32) DEFAULT NULL COMMENT '更新人ID',
  3102 + `update_by` varchar(64) DEFAULT NULL COMMENT '更新人',
  3103 + `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  3104 + `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  3105 + PRIMARY KEY (`id`),
  3106 + KEY `idx_fprl_request_id` (`request_id`),
  3107 + KEY `idx_fprl_plan_id` (`plan_id`)
  3108 +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT='资金支付-请款单明细';
  3109 +
  3110 +-- 采购计划:请款附件(买断自提首付款请款单生成时带出到 request_file_ids/names;上传后才允许生成请款单)
  3111 +ALTER TABLE procurement_plan
  3112 + ADD COLUMN request_file_ids varchar(1000) DEFAULT NULL COMMENT '请款附件文件ID集合(多文件,逗号分隔)',
  3113 + ADD COLUMN request_file_names varchar(1000) DEFAULT NULL COMMENT '请款附件文件名称集合(多文件,逗号分隔)';
  1 +package com.lframework.xingyun.sc.bo.procurement;
  2 +
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +import lombok.Data;
  5 +
  6 +import java.math.BigDecimal;
  7 +import java.time.LocalDate;
  8 +import java.time.LocalDateTime;
  9 +import java.util.ArrayList;
  10 +import java.util.List;
  11 +
  12 +/**
  13 + * 资金支付请款单详情(主表 + 明细)
  14 + */
  15 +@Data
  16 +public class GetFundPaymentRequestBo {
  17 +
  18 + @ApiModelProperty("ID")
  19 + private String id;
  20 +
  21 + @ApiModelProperty("生成来源 PLAN/TICKET/RECEIVE")
  22 + private String source;
  23 +
  24 + @ApiModelProperty("来源单ID")
  25 + private String sourceId;
  26 +
  27 + @ApiModelProperty("请款单类型 NORMAL-正常 SUPPLEMENT-补充请款单")
  28 + private String requestKind;
  29 +
  30 + @ApiModelProperty("交提货方式(采购计划 deliveryMode 原值)")
  31 + private String bizType;
  32 +
  33 + @ApiModelProperty("计划编号集合")
  34 + private List<String> planCodes = new ArrayList<>();
  35 +
  36 + @ApiModelProperty("过磅码单ID")
  37 + private String ticketId;
  38 +
  39 + @ApiModelProperty("过磅码单编号")
  40 + private String ticketCode;
  41 +
  42 + @ApiModelProperty("仓库收料单ID")
  43 + private String receiveId;
  44 +
  45 + @ApiModelProperty("公司简称ID")
  46 + private String companyShortId;
  47 +
  48 + @ApiModelProperty("公司名称(公司简称)")
  49 + private String companyShortName;
  50 +
  51 + @ApiModelProperty("分厂ID")
  52 + private String workshopId;
  53 +
  54 + @ApiModelProperty("分厂名称")
  55 + private String workshopName;
  56 +
  57 + @ApiModelProperty("请款日期")
  58 + private LocalDate requestDate;
  59 +
  60 + @ApiModelProperty("付款方式(电汇)")
  61 + private String payMethod;
  62 +
  63 + @ApiModelProperty("资金支付供应商信息ID")
  64 + private String supplierId;
  65 +
  66 + @ApiModelProperty("对方户名")
  67 + private String payeeName;
  68 +
  69 + @ApiModelProperty("开户银行")
  70 + private String bankName;
  71 +
  72 + @ApiModelProperty("账号")
  73 + private String bankAccount;
  74 +
  75 + @ApiModelProperty("请款说明")
  76 + private String requestRemark;
  77 +
  78 + @ApiModelProperty("请款附件文件ID集合")
  79 + private String requestFileIds;
  80 +
  81 + @ApiModelProperty("请款附件文件名称集合")
  82 + private String requestFileNames;
  83 +
  84 + @ApiModelProperty("补充说明")
  85 + private String supplementRemark;
  86 +
  87 + @ApiModelProperty("补充说明附件文件ID集合")
  88 + private String supplementFileIds;
  89 +
  90 + @ApiModelProperty("补充说明附件文件名称集合")
  91 + private String supplementFileNames;
  92 +
  93 + @ApiModelProperty("其它附件文件ID集合")
  94 + private String otherFileIds;
  95 +
  96 + @ApiModelProperty("其它附件文件名称集合")
  97 + private String otherFileNames;
  98 +
  99 + @ApiModelProperty("合计-预付金额")
  100 + private BigDecimal totalPrepaidAmount;
  101 +
  102 + @ApiModelProperty("合计-申请金额")
  103 + private BigDecimal totalApplyAmount;
  104 +
  105 + @ApiModelProperty("流程节点 GYGLKZJY/GYGLKZG")
  106 + private String flowNode;
  107 +
  108 + @ApiModelProperty("审核状态 DRAFT/AUDIT/PASS/REFUSE")
  109 + private String approvalStatus;
  110 +
  111 + @ApiModelProperty("供应管理科主管审核人ID")
  112 + private String gyglkzgId;
  113 +
  114 + @ApiModelProperty("供应管理科主管审核人")
  115 + private String gyglkzgName;
  116 +
  117 + @ApiModelProperty("是否作废")
  118 + private Boolean deleted;
  119 +
  120 + @ApiModelProperty("创建人")
  121 + private String createBy;
  122 +
  123 + @ApiModelProperty("创建时间")
  124 + private LocalDateTime createTime;
  125 +
  126 + @ApiModelProperty("审核按钮标记(当前用户有待办且审核中)")
  127 + private Boolean showExamine;
  128 +
  129 + @ApiModelProperty("审核详情按钮标记(存在流程实例)")
  130 + private Boolean showExamineDetail;
  131 +
  132 + @ApiModelProperty("明细数据")
  133 + private List<LineBo> lines = new ArrayList<>();
  134 +
  135 + /**
  136 + * 资金支付请款单明细行
  137 + */
  138 + @Data
  139 + public static class LineBo {
  140 +
  141 + @ApiModelProperty("明细行ID")
  142 + private String id;
  143 +
  144 + @ApiModelProperty("采购计划ID")
  145 + private String planId;
  146 +
  147 + @ApiModelProperty("计划编号")
  148 + private String planCode;
  149 +
  150 + @ApiModelProperty("预付金额(自动计算)")
  151 + private BigDecimal prepaidAmount;
  152 +
  153 + @ApiModelProperty("申请金额")
  154 + private BigDecimal applyAmount;
  155 + }
  156 +}
@@ -406,6 +406,18 @@ public class GetProcurementPlanBo extends BaseBo<ProcurementPlan> { @@ -406,6 +406,18 @@ public class GetProcurementPlanBo extends BaseBo<ProcurementPlan> {
406 private String attachmentFileNames; 406 private String attachmentFileNames;
407 407
408 /** 408 /**
  409 + * 请款附件文件ID集合(上传后才可生成请款单)
  410 + */
  411 + @ApiModelProperty("请款附件文件ID集合(上传后才可生成请款单)")
  412 + private String requestFileIds;
  413 +
  414 + /**
  415 + * 请款附件文件名称集合
  416 + */
  417 + @ApiModelProperty("请款附件文件名称集合")
  418 + private String requestFileNames;
  419 +
  420 + /**
409 * 删除标记 true=已删除(变更归档原始数据)false=正常数据 421 * 删除标记 true=已删除(变更归档原始数据)false=正常数据
410 */ 422 */
411 @ApiModelProperty("删除标记") 423 @ApiModelProperty("删除标记")
@@ -454,6 +466,12 @@ public class GetProcurementPlanBo extends BaseBo<ProcurementPlan> { @@ -454,6 +466,12 @@ public class GetProcurementPlanBo extends BaseBo<ProcurementPlan> {
454 private Boolean showExamineDetail; 466 private Boolean showExamineDetail;
455 467
456 /** 468 /**
  469 + * 是否可生成请款单
  470 + */
  471 + @ApiModelProperty("是否可生成请款单")
  472 + private Boolean showApplyPayment = false;
  473 +
  474 + /**
457 * 审核通过时间(精确到时分秒) 475 * 审核通过时间(精确到时分秒)
458 */ 476 */
459 @ApiModelProperty("审核通过时间") 477 @ApiModelProperty("审核通过时间")
@@ -145,6 +145,9 @@ public class GetProcurementWeighingTicketBo extends BaseBo<ProcurementWeighingTi @@ -145,6 +145,9 @@ public class GetProcurementWeighingTicketBo extends BaseBo<ProcurementWeighingTi
145 @ApiModelProperty("是否展示审核详情按钮") 145 @ApiModelProperty("是否展示审核详情按钮")
146 private Boolean showExamineDetail; 146 private Boolean showExamineDetail;
147 147
  148 + @ApiModelProperty("是否展示申请请款单按钮")
  149 + private Boolean showApplyPayment = false;
  150 +
148 @ApiModelProperty("创建人") 151 @ApiModelProperty("创建人")
149 private String createBy; 152 private String createBy;
150 153
@@ -119,6 +119,9 @@ public class GetWarehouseReceiveOrderBo { @@ -119,6 +119,9 @@ public class GetWarehouseReceiveOrderBo {
119 @ApiModelProperty("是否展示审核详情按钮") 119 @ApiModelProperty("是否展示审核详情按钮")
120 private Boolean showExamineDetail; 120 private Boolean showExamineDetail;
121 121
  122 + @ApiModelProperty("是否展示申请请款单按钮")
  123 + private Boolean showApplyPayment = false;
  124 +
122 @ApiModelProperty("创建人") 125 @ApiModelProperty("创建人")
123 private String createBy; 126 private String createBy;
124 127
@@ -21,6 +21,7 @@ import com.lframework.xingyun.sc.enums.CustomerDevelopStatus; @@ -21,6 +21,7 @@ import com.lframework.xingyun.sc.enums.CustomerDevelopStatus;
21 import com.lframework.xingyun.sc.procurement.entity.ProcurementDomesticCustomerCredit; 21 import com.lframework.xingyun.sc.procurement.entity.ProcurementDomesticCustomerCredit;
22 import com.lframework.xingyun.sc.procurement.entity.ProcurementForeignTradeCredit; 22 import com.lframework.xingyun.sc.procurement.entity.ProcurementForeignTradeCredit;
23 import com.lframework.xingyun.sc.procurement.service.buyoutAccount.ProcurementBuyoutAccountOrderService; 23 import com.lframework.xingyun.sc.procurement.service.buyoutAccount.ProcurementBuyoutAccountOrderService;
  24 +import com.lframework.xingyun.sc.procurement.service.fundpayment.FundPaymentRequestService;
24 import com.lframework.xingyun.sc.procurement.service.change.ProcurementPlanChangeService; 25 import com.lframework.xingyun.sc.procurement.service.change.ProcurementPlanChangeService;
25 import com.lframework.xingyun.sc.procurement.service.coordination.CoordinationSummaryApprovalService; 26 import com.lframework.xingyun.sc.procurement.service.coordination.CoordinationSummaryApprovalService;
26 import com.lframework.xingyun.sc.procurement.service.contract.ProcurementContractService; 27 import com.lframework.xingyun.sc.procurement.service.contract.ProcurementContractService;
@@ -189,6 +190,8 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic @@ -189,6 +190,8 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic
189 private ProcurementWarehouseReceiveOrderService procurementWarehouseReceiveOrderService; 190 private ProcurementWarehouseReceiveOrderService procurementWarehouseReceiveOrderService;
190 @Resource 191 @Resource
191 private ProcurementBuyoutAccountOrderService procurementBuyoutAccountOrderService; 192 private ProcurementBuyoutAccountOrderService procurementBuyoutAccountOrderService;
  193 + @Resource
  194 + private FundPaymentRequestService fundPaymentRequestService;
192 195
193 196
194 197
@@ -312,6 +315,9 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic @@ -312,6 +315,9 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic
312 case "BUYOUT_ACCOUNT_ORDER": 315 case "BUYOUT_ACCOUNT_ORDER":
313 handleBuyoutAccountOrderData(flowStatus, businessId); 316 handleBuyoutAccountOrderData(flowStatus, businessId);
314 break; 317 break;
  318 + case "FUND_PAYMENT_REQUEST":
  319 + handleFundPaymentRequestData(flowStatus, businessId);
  320 + break;
315 default: 321 default:
316 break; 322 break;
317 } 323 }
@@ -1342,4 +1348,15 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic @@ -1342,4 +1348,15 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic
1342 procurementBuyoutAccountOrderService.updateApprovalStatus(businessId, "REFUSE"); 1348 procurementBuyoutAccountOrderService.updateApprovalStatus(businessId, "REFUSE");
1343 } 1349 }
1344 } 1350 }
  1351 +
  1352 + private void handleFundPaymentRequestData(String flowStatus, String businessId) {
  1353 + if (FlowInstanceStatus.APPROVE_PASS.getCode().equals(flowStatus)
  1354 + || FlowInstanceStatus.FINISH.getCode().equals(flowStatus)) {
  1355 + fundPaymentRequestService.updateApprovalStatus(businessId, "PASS");
  1356 + } else if (FlowInstanceStatus.REVOKE.getCode().equals(flowStatus)
  1357 + || FlowInstanceStatus.REFUSE.getCode().equals(flowStatus)
  1358 + || FlowInstanceStatus.TERMINATION.getCode().equals(flowStatus)) {
  1359 + fundPaymentRequestService.updateApprovalStatus(businessId, "REFUSE");
  1360 + }
  1361 + }
1345 } 1362 }
  1 +package com.lframework.xingyun.sc.procurement.controller.fundpayment;
  2 +
  3 +import com.lframework.starter.web.core.annotations.security.HasPermission;
  4 +import com.lframework.starter.web.core.components.resp.InvokeResult;
  5 +import com.lframework.starter.web.core.components.resp.InvokeResultBuilder;
  6 +import com.lframework.starter.web.core.components.resp.PageResult;
  7 +import com.lframework.starter.web.core.controller.DefaultBaseController;
  8 +import com.lframework.starter.web.core.utils.PageResultUtil;
  9 +import com.lframework.xingyun.sc.bo.procurement.GetFundPaymentRequestBo;
  10 +import com.lframework.xingyun.sc.procurement.entity.fundpayment.FundPaymentRequest;
  11 +import com.lframework.xingyun.sc.procurement.service.fundpayment.FundPaymentRequestService;
  12 +import com.lframework.xingyun.sc.procurement.vo.fundpayment.CreateFundPaymentRequestVo;
  13 +import com.lframework.xingyun.sc.procurement.vo.fundpayment.FundPaymentOtherAttachmentVo;
  14 +import com.lframework.xingyun.sc.procurement.vo.fundpayment.QueryFundPaymentRequestVo;
  15 +import com.lframework.xingyun.sc.procurement.vo.fundpayment.UpdateFundPaymentRequestVo;
  16 +import io.swagger.annotations.Api;
  17 +import io.swagger.annotations.ApiImplicitParam;
  18 +import io.swagger.annotations.ApiImplicitParams;
  19 +import io.swagger.annotations.ApiOperation;
  20 +import java.util.List;
  21 +import java.util.stream.Collectors;
  22 +import javax.annotation.Resource;
  23 +import javax.validation.Valid;
  24 +import javax.validation.constraints.NotBlank;
  25 +import org.springframework.util.CollectionUtils;
  26 +import org.springframework.validation.annotation.Validated;
  27 +import org.springframework.web.bind.annotation.GetMapping;
  28 +import org.springframework.web.bind.annotation.PostMapping;
  29 +import org.springframework.web.bind.annotation.PutMapping;
  30 +import org.springframework.web.bind.annotation.RequestBody;
  31 +import org.springframework.web.bind.annotation.RequestMapping;
  32 +import org.springframework.web.bind.annotation.RequestMethod;
  33 +import org.springframework.web.bind.annotation.RestController;
  34 +
  35 +/**
  36 + * 资金支付-请款单(供应管理科资金管理员制单,供应管理科主管审核)
  37 + */
  38 +@Api(tags = "资金支付-请款单")
  39 +@Validated
  40 +@RestController
  41 +@RequestMapping("/procurement/fundPaymentRequest")
  42 +public class FundPaymentRequestController extends DefaultBaseController {
  43 +
  44 + @Resource
  45 + private FundPaymentRequestService fundPaymentRequestService;
  46 +
  47 + @ApiOperation("分页查询请款单")
  48 + @HasPermission({"procure-manage:payment-request:query"})
  49 + @GetMapping("/query")
  50 + public InvokeResult<PageResult<GetFundPaymentRequestBo>> query(@Valid QueryFundPaymentRequestVo vo) {
  51 + PageResult<FundPaymentRequest> pageResult = fundPaymentRequestService.query(
  52 + getPageIndex(vo), getPageSize(vo), vo);
  53 +
  54 + List<GetFundPaymentRequestBo> results = null;
  55 + if (!CollectionUtils.isEmpty(pageResult.getDatas())) {
  56 + results = pageResult.getDatas().stream().map(entity -> {
  57 + GetFundPaymentRequestBo bo = new GetFundPaymentRequestBo();
  58 + org.springframework.beans.BeanUtils.copyProperties(entity, bo);
  59 + bo.setPlanCodes(splitPlanCodes(entity.getPlanCodes()));
  60 + return bo;
  61 + }).collect(Collectors.toList());
  62 + }
  63 + return InvokeResultBuilder.success(PageResultUtil.rebuild(pageResult, results));
  64 + }
  65 +
  66 + @ApiOperation("查询请款单详情")
  67 + @ApiImplicitParam(value = "ID", name = "id", paramType = "query", required = true)
  68 + @HasPermission({"procure-manage:payment-request:query", "procure-manage:payment-request:review"})
  69 + @GetMapping("")
  70 + public InvokeResult<GetFundPaymentRequestBo> findById(@NotBlank(message = "ID不能为空!") String id) {
  71 + return InvokeResultBuilder.success(fundPaymentRequestService.findDetail(id));
  72 + }
  73 +
  74 + @ApiOperation("按来源单生成草稿请款单(调用即落库,仅返回请款单ID;自动带出/计算的字段直接生成,需手填的字段凭 ID 查询详情后修改补充。"
  75 + + "请款日期=生成当天、付款方式固定电汇;同一来源单已有草稿时幂等返回该单ID。推荐 POST,保留 GET 兼容)")
  76 + @ApiImplicitParams({
  77 + @ApiImplicitParam(value = "生成来源 PLAN/TICKET/RECEIVE", name = "source", paramType = "query", required = true),
  78 + @ApiImplicitParam(value = "来源单ID", name = "sourceId", paramType = "query", required = true)
  79 + })
  80 + @HasPermission({"procure-manage:payment-request:add"})
  81 + @RequestMapping(value = "/generateData", method = {RequestMethod.POST, RequestMethod.GET})
  82 + public InvokeResult<String> generate(@NotBlank(message = "生成来源不能为空!") String source,
  83 + @NotBlank(message = "来源单ID不能为空!") String sourceId) {
  84 + return InvokeResultBuilder.success(fundPaymentRequestService.generate(source, sourceId));
  85 + }
  86 +
  87 + @ApiOperation("一次性提交新增请款单(草稿,含全部手填字段;与生成接口生成草稿后走修改补充二选一)")
  88 + @HasPermission({"procure-manage:payment-request:add"})
  89 + @PostMapping("")
  90 + public InvokeResult<String> create(@RequestBody @Valid CreateFundPaymentRequestVo vo) {
  91 + String id = fundPaymentRequestService.create(vo);
  92 + return InvokeResultBuilder.success(id);
  93 + }
  94 +
  95 + @ApiOperation("修改请款单(仅草稿、已驳回可修改;来源单/预付金额/请款附件不可改)")
  96 + @HasPermission({"procure-manage:payment-request:modify"})
  97 + @PutMapping("")
  98 + public InvokeResult<Void> update(@RequestBody @Valid UpdateFundPaymentRequestVo vo) {
  99 + fundPaymentRequestService.update(vo);
  100 + return InvokeResultBuilder.success();
  101 + }
  102 +
  103 + @ApiOperation("提交请款单审核(生成接口落库的草稿须先修改补充明细申请金额)")
  104 + @ApiImplicitParam(value = "ID", name = "id", paramType = "query", required = true)
  105 + @HasPermission({"procure-manage:payment-request:submit"})
  106 + @PutMapping("/submit")
  107 + public InvokeResult<Void> submit(@NotBlank(message = "ID不能为空!") String id) {
  108 + fundPaymentRequestService.submit(id);
  109 + return InvokeResultBuilder.success();
  110 + }
  111 +
  112 + @ApiOperation("作废请款单(仅审核通过可作废,作废后释放来源单可重新请款)")
  113 + @ApiImplicitParam(value = "ID", name = "id", paramType = "query", required = true)
  114 + @HasPermission({"procure-manage:payment-request:invalid"})
  115 + @PutMapping("/invalid")
  116 + public InvokeResult<Void> invalid(@NotBlank(message = "ID不能为空!") String id) {
  117 + fundPaymentRequestService.invalid(id);
  118 + return InvokeResultBuilder.success();
  119 + }
  120 +
  121 + @ApiOperation("上传其它附件(请款单任何状态可上传)")
  122 + @HasPermission({"procure-manage:payment-request:modify"})
  123 + @PutMapping("/otherAttachment")
  124 + public InvokeResult<Void> uploadOtherAttachment(@RequestBody @Valid FundPaymentOtherAttachmentVo vo) {
  125 + fundPaymentRequestService.uploadOtherAttachment(vo);
  126 + return InvokeResultBuilder.success();
  127 + }
  128 +
  129 + private List<String> splitPlanCodes(String planCodes) {
  130 + if (planCodes == null || planCodes.isEmpty()) {
  131 + return java.util.Collections.emptyList();
  132 + }
  133 + return java.util.Arrays.stream(planCodes.split("[,,]"))
  134 + .map(String::trim)
  135 + .filter(s -> !s.isEmpty())
  136 + .distinct()
  137 + .collect(Collectors.toList());
  138 + }
  139 +}
@@ -22,6 +22,7 @@ import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService @@ -22,6 +22,7 @@ import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService
22 import com.lframework.xingyun.sc.procurement.vo.plan.CreateProcurementPlanVo; 22 import com.lframework.xingyun.sc.procurement.vo.plan.CreateProcurementPlanVo;
23 import com.lframework.xingyun.sc.procurement.vo.plan.QueryProcurementPlanVo; 23 import com.lframework.xingyun.sc.procurement.vo.plan.QueryProcurementPlanVo;
24 import com.lframework.xingyun.sc.procurement.vo.plan.UpdateProcurementPlanVo; 24 import com.lframework.xingyun.sc.procurement.vo.plan.UpdateProcurementPlanVo;
  25 +import com.lframework.xingyun.sc.procurement.vo.plan.UploadProcurementPlanRequestFileVo;
25 import com.lframework.xingyun.sc.utils.ExcelUtil; 26 import com.lframework.xingyun.sc.utils.ExcelUtil;
26 import io.swagger.annotations.Api; 27 import io.swagger.annotations.Api;
27 import io.swagger.annotations.ApiImplicitParam; 28 import io.swagger.annotations.ApiImplicitParam;
@@ -200,6 +201,19 @@ public class ProcurementPlanController extends DefaultBaseController { @@ -200,6 +201,19 @@ public class ProcurementPlanController extends DefaultBaseController {
200 } 201 }
201 202
202 /** 203 /**
  204 + * 上传请款附件(买断自提首付款请款单生成时带出;上传后才显示「生成请款单」按钮)
  205 + */
  206 + @ApiOperation("上传请款附件(上传后才可生成请款单)")
  207 + @HasPermission({"plan-manage:domestic-plan:upload"})
  208 + @PutMapping("/attachment/request")
  209 + public InvokeResult<Void> uploadRequestFiles(@RequestBody @Valid UploadProcurementPlanRequestFileVo vo) {
  210 +
  211 + procurementPlanService.uploadRequestFiles(vo.getId(), vo.getFileIds(), vo.getFileNames());
  212 +
  213 + return InvokeResultBuilder.success();
  214 + }
  215 +
  216 + /**
203 * 生成合同 217 * 生成合同
204 */ 218 */
205 @ApiOperation("生成合同") 219 @ApiOperation("生成合同")
@@ -335,6 +335,16 @@ public class ProcurementPlan extends BaseEntity implements BaseDto { @@ -335,6 +335,16 @@ public class ProcurementPlan extends BaseEntity implements BaseDto {
335 private String attachmentFileNames; 335 private String attachmentFileNames;
336 336
337 /** 337 /**
  338 + * 请款附件文件ID集合(多文件,逗号分隔;未上传不可生成请款单)
  339 + */
  340 + private String requestFileIds;
  341 +
  342 + /**
  343 + * 请款附件文件名称集合(多文件,逗号分隔)
  344 + */
  345 + private String requestFileNames;
  346 +
  347 + /**
338 * 删除标记 true=已删除(变更归档原始数据)false=正常数据 348 * 删除标记 true=已删除(变更归档原始数据)false=正常数据
339 */ 349 */
340 private Boolean deleted; 350 private Boolean deleted;
@@ -382,6 +392,12 @@ public class ProcurementPlan extends BaseEntity implements BaseDto { @@ -382,6 +392,12 @@ public class ProcurementPlan extends BaseEntity implements BaseDto {
382 private Boolean showExamineDetail; 392 private Boolean showExamineDetail;
383 393
384 /** 394 /**
  395 + * 是否可生成请款单(非持久化字段,买断自提首付款:流程完成+买断计划+未被有效请款单占用)
  396 + */
  397 + @TableField(exist = false)
  398 + private Boolean showApplyPayment = false;
  399 +
  400 + /**
385 * 创建人ID 401 * 创建人ID
386 */ 402 */
387 @TableField(fill = FieldFill.DEFAULT) 403 @TableField(fill = FieldFill.DEFAULT)
  1 +package com.lframework.xingyun.sc.procurement.entity.fundpayment;
  2 +
  3 +import com.baomidou.mybatisplus.annotation.FieldFill;
  4 +import com.baomidou.mybatisplus.annotation.TableField;
  5 +import com.baomidou.mybatisplus.annotation.TableName;
  6 +import com.lframework.starter.web.core.dto.BaseDto;
  7 +import com.lframework.starter.web.core.entity.BaseEntity;
  8 +import java.math.BigDecimal;
  9 +import java.time.LocalDate;
  10 +import java.time.LocalDateTime;
  11 +import lombok.Data;
  12 +
  13 +/**
  14 + * <p>
  15 + * 资金支付-请款单(供应管理科资金管理员制单,供应管理科主管审核)
  16 + * 生成来源:PLAN-采购计划(买断自提首付款,单计划) TICKET-过磅码单(送货到厂正常,可链式多张) RECEIVE-仓库收料单(尾款/一次性结算/退料)
  17 + * 过磅码单作废时联动全部作废
  18 + * </p>
  19 + *
  20 + */
  21 +@Data
  22 +@TableName("fund_payment_request")
  23 +public class FundPaymentRequest extends BaseEntity implements BaseDto {
  24 +
  25 + private static final long serialVersionUID = 1L;
  26 +
  27 + public static final String CACHE_NAME = "FundPaymentRequest";
  28 +
  29 + /**
  30 + * ID
  31 + */
  32 + private String id;
  33 +
  34 + /**
  35 + * 生成来源 PLAN-采购计划(买断自提首付款) TICKET-过磅码单(送货到厂正常) RECEIVE-仓库收料单(尾款/一次性结算/退料)
  36 + */
  37 + private String source;
  38 +
  39 + /**
  40 + * 来源单ID(计划ID/码单ID/收料单ID)
  41 + */
  42 + private String sourceId;
  43 +
  44 + /**
  45 + * 请款单类型 NORMAL-正常 SUPPLEMENT-补充请款单
  46 + */
  47 + private String requestKind;
  48 +
  49 + /**
  50 + * 交提货方式(取采购计划 delivery_mode 原值,不做转换)
  51 + */
  52 + private String bizType;
  53 +
  54 + /**
  55 + * 计划ID集合(逗号分隔)
  56 + */
  57 + private String planIds;
  58 +
  59 + /**
  60 + * 计划编号集合(逗号分隔)
  61 + */
  62 + private String planCodes;
  63 +
  64 + /**
  65 + * 过磅码单ID(码单来源或收料单关联码单,送货到厂请款链维度)
  66 + */
  67 + private String ticketId;
  68 +
  69 + /**
  70 + * 过磅码单编号
  71 + */
  72 + private String ticketCode;
  73 +
  74 + /**
  75 + * 仓库收料单ID(收料单来源时)
  76 + */
  77 + private String receiveId;
  78 +
  79 + /**
  80 + * 公司简称ID
  81 + */
  82 + private String companyShortId;
  83 +
  84 + /**
  85 + * 公司名称(公司简称)
  86 + */
  87 + private String companyShortName;
  88 +
  89 + /**
  90 + * 分厂ID
  91 + */
  92 + private String workshopId;
  93 +
  94 + /**
  95 + * 分厂名称
  96 + */
  97 + private String workshopName;
  98 +
  99 + /**
  100 + * 请款日期(生成请款单的当天日期)
  101 + */
  102 + private LocalDate requestDate;
  103 +
  104 + /**
  105 + * 付款方式(电汇)
  106 + */
  107 + private String payMethod;
  108 +
  109 + /**
  110 + * 资金支付供应商信息ID(关联 fund_payment_supplier)
  111 + */
  112 + private String supplierId;
  113 +
  114 + /**
  115 + * 对方户名(供应商信息客户名称)
  116 + */
  117 + private String payeeName;
  118 +
  119 + /**
  120 + * 开户银行(对方户名对应)
  121 + */
  122 + private String bankName;
  123 +
  124 + /**
  125 + * 账号(对方户名对应)
  126 + */
  127 + private String bankAccount;
  128 +
  129 + /**
  130 + * 请款说明(多行文本)
  131 + */
  132 + private String requestRemark;
  133 +
  134 + /**
  135 + * 请款附件文件ID集合(计划生成时自动带出计划请款附件,不可改)
  136 + */
  137 + private String requestFileIds;
  138 +
  139 + /**
  140 + * 请款附件文件名称集合
  141 + */
  142 + private String requestFileNames;
  143 +
  144 + /**
  145 + * 补充说明(补充请款单填写、显示)
  146 + */
  147 + private String supplementRemark;
  148 +
  149 + /**
  150 + * 补充说明附件文件ID集合(补充请款单时上传)
  151 + */
  152 + private String supplementFileIds;
  153 +
  154 + /**
  155 + * 补充说明附件文件名称集合
  156 + */
  157 + private String supplementFileNames;
  158 +
  159 + /**
  160 + * 其它附件文件ID集合(任何状态可上传)
  161 + */
  162 + private String otherFileIds;
  163 +
  164 + /**
  165 + * 其它附件文件名称集合
  166 + */
  167 + private String otherFileNames;
  168 +
  169 + /**
  170 + * 合计-预付金额(明细预付金额之和,自动计算)
  171 + */
  172 + private BigDecimal totalPrepaidAmount;
  173 +
  174 + /**
  175 + * 合计-申请金额(明细申请金额之和)
  176 + */
  177 + private BigDecimal totalApplyAmount;
  178 +
  179 + /**
  180 + * 流程节点 GYGLKZJY-供应管理科资金管理员 GYGLKZG-供应管理科主管
  181 + */
  182 + private String flowNode;
  183 +
  184 + /**
  185 + * 审核状态 DRAFT-草稿 AUDIT-审核中 PASS-审核通过 REFUSE-已驳回
  186 + */
  187 + private String approvalStatus;
  188 +
  189 + /**
  190 + * 供应管理科主管审核人ID(审核通过时记录)
  191 + */
  192 + private String gyglkzgId;
  193 +
  194 + /**
  195 + * 供应管理科主管审核人
  196 + */
  197 + private String gyglkzgName;
  198 +
  199 + /**
  200 + * 是否作废 0-有效单 1-作废单(作废单只能查看;码单作废联动全部作废)
  201 + */
  202 + private Boolean deleted;
  203 +
  204 + /**
  205 + * 创建人ID
  206 + */
  207 + @TableField(fill = FieldFill.INSERT)
  208 + private String createById;
  209 +
  210 + /**
  211 + * 创建人
  212 + */
  213 + @TableField(fill = FieldFill.INSERT)
  214 + private String createBy;
  215 +
  216 + /**
  217 + * 更新人ID
  218 + */
  219 + @TableField(fill = FieldFill.INSERT_UPDATE)
  220 + private String updateById;
  221 +
  222 + /**
  223 + * 更新人
  224 + */
  225 + @TableField(fill = FieldFill.INSERT_UPDATE)
  226 + private String updateBy;
  227 +
  228 + /**
  229 + * 创建时间
  230 + */
  231 + @TableField(fill = FieldFill.INSERT)
  232 + private LocalDateTime createTime;
  233 +
  234 + /**
  235 + * 更新时间
  236 + */
  237 + @TableField(fill = FieldFill.INSERT_UPDATE)
  238 + private LocalDateTime updateTime;
  239 +
  240 + /**
  241 + * 审核按钮标记(待办驱动,非数据库字段)
  242 + */
  243 + @TableField(exist = false)
  244 + private Boolean showExamine;
  245 +
  246 + /**
  247 + * 审核详情按钮标记(存在流程实例,非数据库字段)
  248 + */
  249 + @TableField(exist = false)
  250 + private Boolean showExamineDetail;
  251 +}
  1 +package com.lframework.xingyun.sc.procurement.entity.fundpayment;
  2 +
  3 +import com.baomidou.mybatisplus.annotation.FieldFill;
  4 +import com.baomidou.mybatisplus.annotation.TableField;
  5 +import com.baomidou.mybatisplus.annotation.TableName;
  6 +import com.lframework.starter.web.core.dto.BaseDto;
  7 +import com.lframework.starter.web.core.entity.BaseEntity;
  8 +import java.math.BigDecimal;
  9 +import java.time.LocalDateTime;
  10 +import lombok.Data;
  11 +
  12 +/**
  13 + * <p>
  14 + * 资金支付-请款单明细(每行一个采购计划;预付金额按来源自动计算,申请金额资金管理员填写,合计金额=预付+申请)
  15 + * </p>
  16 + *
  17 + */
  18 +@Data
  19 +@TableName("fund_payment_request_line")
  20 +public class FundPaymentRequestLine extends BaseEntity implements BaseDto {
  21 +
  22 + private static final long serialVersionUID = 1L;
  23 +
  24 + /**
  25 + * ID
  26 + */
  27 + private String id;
  28 +
  29 + /**
  30 + * 请款单主表ID
  31 + */
  32 + private String requestId;
  33 +
  34 + /**
  35 + * 采购计划ID
  36 + */
  37 + private String planId;
  38 +
  39 + /**
  40 + * 计划编号(自动带出关联的计划编号)
  41 + */
  42 + private String planCode;
  43 +
  44 + /**
  45 + * 预付金额(界限值,按来源自动计算,不可改)
  46 + */
  47 + private BigDecimal prepaidAmount;
  48 +
  49 + /**
  50 + * 申请金额(数值,保留两位小数)
  51 + */
  52 + private BigDecimal applyAmount;
  53 +
  54 + /**
  55 + * 创建人ID
  56 + */
  57 + @TableField(fill = FieldFill.INSERT)
  58 + private String createById;
  59 +
  60 + /**
  61 + * 创建人
  62 + */
  63 + @TableField(fill = FieldFill.INSERT)
  64 + private String createBy;
  65 +
  66 + /**
  67 + * 更新人ID
  68 + */
  69 + @TableField(fill = FieldFill.INSERT_UPDATE)
  70 + private String updateById;
  71 +
  72 + /**
  73 + * 更新人
  74 + */
  75 + @TableField(fill = FieldFill.INSERT_UPDATE)
  76 + private String updateBy;
  77 +
  78 + /**
  79 + * 创建时间
  80 + */
  81 + @TableField(fill = FieldFill.INSERT)
  82 + private LocalDateTime createTime;
  83 +
  84 + /**
  85 + * 更新时间
  86 + */
  87 + @TableField(fill = FieldFill.INSERT_UPDATE)
  88 + private LocalDateTime updateTime;
  89 +}
@@ -244,4 +244,10 @@ public class ProcurementWarehouseReceiveOrder extends BaseEntity implements Base @@ -244,4 +244,10 @@ public class ProcurementWarehouseReceiveOrder extends BaseEntity implements Base
244 */ 244 */
245 @TableField(exist = false) 245 @TableField(exist = false)
246 private Boolean showExamineDetail; 246 private Boolean showExamineDetail;
  247 +
  248 + /**
  249 + * 是否展示申请请款单按钮(非持久化,结算比例100%无尾款时不展示)
  250 + */
  251 + @TableField(exist = false)
  252 + private Boolean showApplyPayment = false;
247 } 253 }
@@ -289,4 +289,10 @@ public class ProcurementWeighingTicket extends BaseEntity implements BaseDto { @@ -289,4 +289,10 @@ public class ProcurementWeighingTicket extends BaseEntity implements BaseDto {
289 */ 289 */
290 @TableField(exist = false) 290 @TableField(exist = false)
291 private Boolean showExamineDetail = false; 291 private Boolean showExamineDetail = false;
  292 +
  293 + /**
  294 + * 是否展示申请请款单按钮(非持久化,退料码单、未完成码单、已存在在途请款单时不展示)
  295 + */
  296 + @TableField(exist = false)
  297 + private Boolean showApplyPayment = false;
292 } 298 }
  1 +package com.lframework.xingyun.sc.procurement.impl.fundpayment;
  2 +
  3 +import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  4 +import com.lframework.starter.web.core.impl.BaseMpServiceImpl;
  5 +import com.lframework.xingyun.sc.procurement.entity.fundpayment.FundPaymentRequestLine;
  6 +import com.lframework.xingyun.sc.procurement.mappers.fundpayment.FundPaymentRequestLineMapper;
  7 +import com.lframework.xingyun.sc.procurement.service.fundpayment.FundPaymentRequestLineService;
  8 +import java.util.Collections;
  9 +import java.util.List;
  10 +import org.springframework.stereotype.Service;
  11 +
  12 +@Service
  13 +public class FundPaymentRequestLineServiceImpl
  14 + extends BaseMpServiceImpl<FundPaymentRequestLineMapper, FundPaymentRequestLine>
  15 + implements FundPaymentRequestLineService {
  16 +
  17 + @Override
  18 + public List<FundPaymentRequestLine> getByRequestId(String requestId) {
  19 + if (requestId == null || requestId.isEmpty()) {
  20 + return Collections.emptyList();
  21 + }
  22 + return getBaseMapper().listByRequestId(requestId);
  23 + }
  24 +
  25 + @Override
  26 + public List<FundPaymentRequestLine> getByRequestIds(List<String> requestIds) {
  27 + if (requestIds == null || requestIds.isEmpty()) {
  28 + return Collections.emptyList();
  29 + }
  30 + return getBaseMapper().selectList(Wrappers.lambdaQuery(FundPaymentRequestLine.class)
  31 + .in(FundPaymentRequestLine::getRequestId, requestIds));
  32 + }
  33 +
  34 + @Override
  35 + public void deleteByRequestId(String requestId) {
  36 + if (requestId == null || requestId.isEmpty()) {
  37 + return;
  38 + }
  39 + getBaseMapper().delete(Wrappers.lambdaQuery(FundPaymentRequestLine.class)
  40 + .eq(FundPaymentRequestLine::getRequestId, requestId));
  41 + }
  42 +}
  1 +package com.lframework.xingyun.sc.procurement.impl.fundpayment;
  2 +
  3 +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4 +import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  5 +import com.github.pagehelper.PageInfo;
  6 +import com.lframework.starter.bpm.dto.FlowTaskDto;
  7 +import com.lframework.starter.bpm.entity.FlowInstanceWrapper;
  8 +import com.lframework.starter.bpm.mappers.FlowTaskWrapperMapper;
  9 +import com.lframework.starter.bpm.service.FlowInstanceWrapperService;
  10 +import com.lframework.starter.bpm.service.FlowTaskWrapperService;
  11 +import com.lframework.starter.bpm.vo.flow.task.QueryTodoTaskListVo;
  12 +import com.lframework.starter.web.core.components.resp.PageResult;
  13 +import com.lframework.starter.web.core.components.security.SecurityUtil;
  14 +import com.lframework.starter.web.core.impl.BaseMpServiceImpl;
  15 +import com.lframework.starter.web.core.utils.OpLogUtil;
  16 +import com.lframework.starter.web.core.utils.PageHelperUtil;
  17 +import com.lframework.starter.web.core.utils.PageResultUtil;
  18 +import com.lframework.starter.web.core.utils.IdUtil;
  19 +import com.lframework.starter.common.exceptions.impl.DefaultClientException;
  20 +import com.lframework.starter.common.utils.Assert;
  21 +import com.lframework.starter.common.utils.CollectionUtil;
  22 +import com.lframework.starter.common.utils.StringUtil;
  23 +import com.lframework.starter.web.core.annotations.oplog.OpLog;
  24 +import com.lframework.starter.web.inner.components.oplog.OtherOpLogType;
  25 +import com.lframework.xingyun.sc.bo.procurement.GetFundPaymentRequestBo;
  26 +import com.lframework.xingyun.sc.procurement.entity.ProcurementPlan;
  27 +import com.lframework.xingyun.sc.procurement.entity.ProcurementPlanLine;
  28 +import com.lframework.xingyun.sc.procurement.entity.fundpayment.FundPaymentRequest;
  29 +import com.lframework.xingyun.sc.procurement.entity.fundpayment.FundPaymentRequestLine;
  30 +import com.lframework.xingyun.sc.procurement.entity.receive.ProcurementWarehouseReceiveOrder;
  31 +import com.lframework.xingyun.sc.procurement.entity.receive.ProcurementWarehouseReceiveOrderLine;
  32 +import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementWeighingTicket;
  33 +import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementWeighingTicketLine;
  34 +import com.lframework.xingyun.sc.procurement.entity.fundpayment.FundPaymentSupplier;
  35 +import com.lframework.xingyun.sc.procurement.mappers.fundpayment.FundPaymentRequestMapper;
  36 +import com.lframework.xingyun.sc.procurement.mappers.plan.ProcurementPlanLineMapper;
  37 +import com.lframework.xingyun.sc.procurement.mappers.plan.ProcurementPlanMapper;
  38 +import com.lframework.xingyun.sc.procurement.mappers.receive.ProcurementWarehouseReceiveOrderLineMapper;
  39 +import com.lframework.xingyun.sc.procurement.mappers.receive.ProcurementWarehouseReceiveOrderMapper;
  40 +import com.lframework.xingyun.sc.procurement.mappers.weighing.ProcurementWeighingTicketLineMapper;
  41 +import com.lframework.xingyun.sc.procurement.mappers.weighing.ProcurementWeighingTicketMapper;
  42 +import com.lframework.xingyun.sc.procurement.service.fundpayment.FundPaymentRequestLineService;
  43 +import com.lframework.xingyun.sc.procurement.service.fundpayment.FundPaymentRequestService;
  44 +import com.lframework.xingyun.sc.procurement.service.fundpayment.FundPaymentSupplierService;
  45 +import com.lframework.xingyun.sc.procurement.vo.fundpayment.CreateFundPaymentRequestVo;
  46 +import com.lframework.xingyun.sc.procurement.vo.fundpayment.FundPaymentOtherAttachmentVo;
  47 +import com.lframework.xingyun.sc.procurement.vo.fundpayment.FundPaymentRequestLineVo;
  48 +import com.lframework.xingyun.sc.procurement.vo.fundpayment.QueryFundPaymentRequestVo;
  49 +import com.lframework.xingyun.sc.procurement.vo.fundpayment.UpdateFundPaymentRequestVo;
  50 +import java.math.BigDecimal;
  51 +import java.math.RoundingMode;
  52 +import java.time.LocalDate;
  53 +import java.util.ArrayList;
  54 +import java.util.Collections;
  55 +import java.util.HashMap;
  56 +import java.util.HashSet;
  57 +import java.util.List;
  58 +import java.util.Map;
  59 +import java.util.Set;
  60 +import java.util.stream.Collectors;
  61 +import javax.annotation.Resource;
  62 +import org.springframework.stereotype.Service;
  63 +import org.springframework.transaction.annotation.Transactional;
  64 +
  65 +@Service
  66 +public class FundPaymentRequestServiceImpl
  67 + extends BaseMpServiceImpl<FundPaymentRequestMapper, FundPaymentRequest>
  68 + implements FundPaymentRequestService {
  69 +
  70 + private static final String STATUS_DRAFT = "DRAFT";
  71 + private static final String STATUS_AUDIT = "AUDIT";
  72 + private static final String STATUS_PASS = "PASS";
  73 + private static final String STATUS_REFUSE = "REFUSE";
  74 +
  75 + private static final String SOURCE_PLAN = "PLAN";
  76 + private static final String SOURCE_TICKET = "TICKET";
  77 + private static final String SOURCE_RECEIVE = "RECEIVE";
  78 +
  79 + private static final String KIND_NORMAL = "NORMAL";
  80 + private static final String KIND_SUPPLEMENT = "SUPPLEMENT";
  81 +
  82 + private static final String NODE_GYGLKZJY = "GYGLKZJY";
  83 + private static final String NODE_GYGLKZG = "GYGLKZG";
  84 +
  85 + private static final String BPM_FLAG = "FUND_PAYMENT_REQUEST";
  86 +
  87 + private static final String PAY_METHOD_DEFAULT = "电汇";
  88 +
  89 + /**
  90 + * 计划交提货方式-自提
  91 + */
  92 + private static final String DELIVERY_MODE_PICK_UP = "PICK_UP";
  93 + /**
  94 + * 计划交提货方式-送货到厂
  95 + */
  96 + private static final String DELIVERY_MODE_FACTORY_DELIVERY = "FACTORY_DELIVERY";
  97 +
  98 + @Resource
  99 + private FundPaymentRequestLineService requestLineService;
  100 + @Resource
  101 + private FundPaymentSupplierService fundPaymentSupplierService;
  102 + @Resource
  103 + private ProcurementPlanMapper procurementPlanMapper;
  104 + @Resource
  105 + private ProcurementPlanLineMapper procurementPlanLineMapper;
  106 + @Resource
  107 + private ProcurementWeighingTicketMapper weighingTicketMapper;
  108 + @Resource
  109 + private ProcurementWeighingTicketLineMapper weighingTicketLineMapper;
  110 + @Resource
  111 + private ProcurementWarehouseReceiveOrderMapper receiveOrderMapper;
  112 + @Resource
  113 + private ProcurementWarehouseReceiveOrderLineMapper receiveOrderLineMapper;
  114 + @Resource
  115 + private FlowInstanceWrapperService flowInstanceWrapperService;
  116 + @Resource
  117 + private FlowTaskWrapperMapper flowTaskWrapperMapper;
  118 + @Resource
  119 + private FlowTaskWrapperService flowTaskWrapperService;
  120 +
  121 + @Override
  122 + public PageResult<FundPaymentRequest> query(Integer pageIndex, Integer pageSize, QueryFundPaymentRequestVo vo) {
  123 + Assert.greaterThanZero(pageIndex);
  124 + Assert.greaterThanZero(pageSize);
  125 +
  126 + PageHelperUtil.startPage(pageIndex, pageSize);
  127 + List<FundPaymentRequest> datas = getBaseMapper().query(vo);
  128 + fillOperateFlags(datas);
  129 +
  130 + return PageResultUtil.convert(new PageInfo<>(datas));
  131 + }
  132 +
  133 + @Override
  134 + public GetFundPaymentRequestBo findDetail(String id) {
  135 + Assert.notBlank(id);
  136 +
  137 + FundPaymentRequest entity = getBaseMapper().findById(id);
  138 + if (entity == null) {
  139 + throw new DefaultClientException("请款单不存在!");
  140 + }
  141 +
  142 + GetFundPaymentRequestBo bo = new GetFundPaymentRequestBo();
  143 + org.springframework.beans.BeanUtils.copyProperties(entity, bo);
  144 + bo.setPlanCodes(splitList(entity.getPlanCodes()));
  145 +
  146 + List<FundPaymentRequestLine> lines = requestLineService.getByRequestId(id);
  147 + for (FundPaymentRequestLine line : lines) {
  148 + GetFundPaymentRequestBo.LineBo lineBo = new GetFundPaymentRequestBo.LineBo();
  149 + org.springframework.beans.BeanUtils.copyProperties(line, lineBo);
  150 + bo.getLines().add(lineBo);
  151 + }
  152 +
  153 + fillOperateFlags(Collections.singletonList(entity));
  154 + bo.setShowExamine(entity.getShowExamine());
  155 + bo.setShowExamineDetail(entity.getShowExamineDetail());
  156 +
  157 + return bo;
  158 + }
  159 +
  160 + @Override
  161 + @Transactional(rollbackFor = Exception.class)
  162 + @OpLog(type = OtherOpLogType.class, name = "按来源单生成请款单草稿,来源单ID:{}", params = {"#sourceId"})
  163 + public String generate(String source, String sourceId) {
  164 + Assert.notBlank(source);
  165 + Assert.notBlank(sourceId);
  166 + assertSourceValid(source);
  167 +
  168 + // 幂等:同一来源单已有草稿时直接返回该单,避免重复请求生成多张请款单
  169 + FundPaymentRequest entity = findDraft(source, sourceId);
  170 + if (entity == null) {
  171 + // 能自动带出/计算的字段直接落库,申请金额等需人工填写的字段留空,由前端修改请款单时补充
  172 + entity = buildDraft(source, sourceId, null);
  173 + }
  174 +
  175 + OpLogUtil.setVariable("id", entity.getId());
  176 + OpLogUtil.setExtra(entity);
  177 + // 只返回落库单据ID:单据数据前端凭 ID 走详情查询,后续操作直接走修改请款单,无需在此回传
  178 + return entity.getId();
  179 + }
  180 +
  181 + /**
  182 + * 同一来源单的未提交草稿(取最新一张),用于生成接口幂等
  183 + */
  184 + private FundPaymentRequest findDraft(String source, String sourceId) {
  185 + List<FundPaymentRequest> drafts = this.list(Wrappers.lambdaQuery(FundPaymentRequest.class)
  186 + .eq(FundPaymentRequest::getSource, source)
  187 + .eq(FundPaymentRequest::getSourceId, sourceId)
  188 + .eq(FundPaymentRequest::getApprovalStatus, STATUS_DRAFT)
  189 + .eq(FundPaymentRequest::getDeleted, false)
  190 + .orderByDesc(FundPaymentRequest::getCreateTime));
  191 + return CollectionUtil.isEmpty(drafts) ? null : drafts.get(0);
  192 + }
  193 +
  194 + @Override
  195 + @Transactional(rollbackFor = Exception.class)
  196 + @OpLog(type = OtherOpLogType.class, name = "新增资金支付请款单,ID:{}", params = {"#result"})
  197 + public String create(CreateFundPaymentRequestVo vo) {
  198 + assertSourceValid(vo.getSource());
  199 + // 来源单校验、自动带出数据、明细计算统一收敛到 buildDraft,与生成接口生成的草稿口径一致
  200 + FundPaymentRequest entity = buildDraft(vo.getSource(), vo.getSourceId(), vo);
  201 +
  202 + OpLogUtil.setVariable("id", entity.getId());
  203 + OpLogUtil.setExtra(entity);
  204 +
  205 + return entity.getId();
  206 + }
  207 +
  208 + /**
  209 + * 按来源单生成草稿请款单:能自动带出/计算的字段一次性落库,需人工填写的字段留空,由前端修改请款单时补充。
  210 + *
  211 + * @param vo 一次性提交的手填数据;为 null 时(生成接口)只生成草稿、不校验申请金额
  212 + */
  213 + private FundPaymentRequest buildDraft(String source, String sourceId, CreateFundPaymentRequestVo vo) {
  214 + // 来源单可用性校验 + 占用校验(同一时间同一来源只能生成一张在途请款单)
  215 + FundPaymentRequest context = buildContext(source, sourceId);
  216 + // 明细以服务端按来源单计算为准(预付金额不可篡改);申请金额需人工填写,草稿阶段留空
  217 + List<FundPaymentRequestLine> lines = calcLines(source, sourceId);
  218 + if (vo != null) {
  219 + matchApplyAmount(lines, vo.getLines());
  220 + }
  221 +
  222 + FundPaymentRequest entity = new FundPaymentRequest();
  223 + entity.setId(IdUtil.getId());
  224 + entity.setSource(context.getSource());
  225 + entity.setSourceId(context.getSourceId());
  226 + entity.setRequestKind(context.getRequestKind());
  227 + entity.setBizType(context.getBizType());
  228 + entity.setPlanIds(context.getPlanIds());
  229 + entity.setPlanCodes(context.getPlanCodes());
  230 + entity.setTicketId(context.getTicketId());
  231 + entity.setTicketCode(context.getTicketCode());
  232 + entity.setReceiveId(context.getReceiveId());
  233 + entity.setCompanyShortId(context.getCompanyShortId());
  234 + entity.setCompanyShortName(context.getCompanyShortName());
  235 + entity.setWorkshopId(context.getWorkshopId());
  236 + entity.setWorkshopName(context.getWorkshopName());
  237 + // 请款日期为生成当天,付款方式固定电汇
  238 + entity.setRequestDate(LocalDate.now());
  239 + entity.setPayMethod(PAY_METHOD_DEFAULT);
  240 + // 请款附件:计划来源自动带出计划请款附件,不可改
  241 + entity.setRequestFileIds(context.getRequestFileIds());
  242 + entity.setRequestFileNames(context.getRequestFileNames());
  243 + entity.setApprovalStatus(STATUS_DRAFT);
  244 + entity.setDeleted(false);
  245 + // 制单阶段当前节点为供应管理科资金管理员
  246 + entity.setFlowNode(NODE_GYGLKZJY);
  247 +
  248 + if (vo != null) {
  249 + // 对方户名/开户银行/账号来自资金支付供应商信息
  250 + applySupplier(entity, vo.getSupplierId(), vo.getPayeeName(), vo.getBankName(), vo.getBankAccount());
  251 + entity.setRequestRemark(vo.getRequestRemark());
  252 + entity.setSupplementRemark(vo.getSupplementRemark());
  253 + entity.setSupplementFileIds(vo.getSupplementFileIds());
  254 + entity.setSupplementFileNames(vo.getSupplementFileNames());
  255 + }
  256 +
  257 + fillTotalAmount(entity, lines);
  258 +
  259 + this.save(entity);
  260 + saveLines(entity.getId(), lines);
  261 +
  262 + return entity;
  263 + }
  264 +
  265 + private void assertSourceValid(String source) {
  266 + if (!SOURCE_PLAN.equals(source) && !SOURCE_TICKET.equals(source) && !SOURCE_RECEIVE.equals(source)) {
  267 + throw new DefaultClientException("生成来源不合法!");
  268 + }
  269 + }
  270 +
  271 + @Override
  272 + @Transactional(rollbackFor = Exception.class)
  273 + @OpLog(type = OtherOpLogType.class, name = "修改资金支付请款单,ID:{}", params = {"#vo.id"})
  274 + public void update(UpdateFundPaymentRequestVo vo) {
  275 + Assert.notBlank(vo.getId(), "ID不能为空!");
  276 +
  277 + FundPaymentRequest oldEntity = this.getById(vo.getId());
  278 + if (oldEntity == null) {
  279 + throw new DefaultClientException("请款单不存在!");
  280 + }
  281 + assertValid(oldEntity);
  282 + assertEditable(oldEntity);
  283 +
  284 + // 预付金额按来源单重新计算(界限值随前置请款变化),申请金额按计划ID匹配前端传入
  285 + List<FundPaymentRequestLine> lines = calcLines(oldEntity.getSource(), oldEntity.getSourceId());
  286 + matchApplyAmount(lines, vo.getLines());
  287 +
  288 + FundPaymentRequest entity = new FundPaymentRequest();
  289 + entity.setId(vo.getId());
  290 + applySupplier(entity, vo.getSupplierId(), vo.getPayeeName(), vo.getBankName(), vo.getBankAccount());
  291 + entity.setRequestRemark(vo.getRequestRemark());
  292 + entity.setSupplementRemark(vo.getSupplementRemark());
  293 + entity.setSupplementFileIds(vo.getSupplementFileIds());
  294 + entity.setSupplementFileNames(vo.getSupplementFileNames());
  295 + // 明细重建后必须同步回填主表合计,否则列表/详情仍显示修改前的金额
  296 + fillTotalAmount(entity, lines);
  297 +
  298 + this.updateById(entity);
  299 +
  300 + // 明细整体重建
  301 + requestLineService.deleteByRequestId(vo.getId());
  302 + saveLines(vo.getId(), lines);
  303 +
  304 + OpLogUtil.setVariable("id", entity.getId());
  305 + OpLogUtil.setExtra(entity);
  306 + }
  307 +
  308 + @Override
  309 + @Transactional(rollbackFor = Exception.class)
  310 + @OpLog(type = OtherOpLogType.class, name = "提交资金支付请款单审核,ID:{}", params = {"#id"})
  311 + public void submit(String id) {
  312 + Assert.notBlank(id);
  313 +
  314 + FundPaymentRequest entity = getBaseMapper().findById(id);
  315 + if (entity == null) {
  316 + throw new DefaultClientException("请款单不存在!");
  317 + }
  318 + assertValid(entity);
  319 + if (!STATUS_DRAFT.equals(entity.getApprovalStatus()) && !STATUS_REFUSE.equals(entity.getApprovalStatus())) {
  320 + throw new DefaultClientException("当前单据状态不允许提交审核!");
  321 + }
  322 +
  323 + List<FundPaymentRequestLine> lines = requestLineService.getByRequestId(id);
  324 + if (CollectionUtil.isEmpty(lines)) {
  325 + throw new DefaultClientException("明细不能为空!");
  326 + }
  327 + // 生成接口直接落库的草稿申请金额为空,必须先修改补充,不允许空金额提交审核
  328 + if (lines.stream().anyMatch(line -> line.getApplyAmount() == null)) {
  329 + throw new DefaultClientException("请先补充请款明细申请金额再提交审核!");
  330 + }
  331 +
  332 + this.update(Wrappers.lambdaUpdate(FundPaymentRequest.class)
  333 + .set(FundPaymentRequest::getApprovalStatus, STATUS_AUDIT)
  334 + // 提交审核后流程节点推进到供应管理科主管
  335 + .set(FundPaymentRequest::getFlowNode, NODE_GYGLKZG)
  336 + .eq(FundPaymentRequest::getId, id));
  337 +
  338 + flowInstanceWrapperService.startInstance(BPM_FLAG, entity.getId(), BPM_FLAG, entity);
  339 +
  340 + OpLogUtil.setVariable("id", id);
  341 + OpLogUtil.setExtra(entity);
  342 + }
  343 +
  344 + @Override
  345 + @Transactional(rollbackFor = Exception.class)
  346 + @OpLog(type = OtherOpLogType.class, name = "作废资金支付请款单,ID:{}", params = {"#id"})
  347 + public void invalid(String id) {
  348 + Assert.notBlank(id);
  349 +
  350 + FundPaymentRequest entity = this.getById(id);
  351 + if (entity == null) {
  352 + throw new DefaultClientException("请款单不存在!");
  353 + }
  354 + assertValid(entity);
  355 + if (!STATUS_PASS.equals(entity.getApprovalStatus())) {
  356 + throw new DefaultClientException("仅审核通过的请款单可作废!");
  357 + }
  358 +
  359 + this.update(Wrappers.lambdaUpdate(FundPaymentRequest.class)
  360 + .set(FundPaymentRequest::getDeleted, true)
  361 + .set(FundPaymentRequest::getFlowNode, null)
  362 + .eq(FundPaymentRequest::getId, id));
  363 +
  364 + OpLogUtil.setVariable("id", id);
  365 + OpLogUtil.setExtra(entity);
  366 + }
  367 +
  368 + @Override
  369 + @Transactional(rollbackFor = Exception.class)
  370 + @OpLog(type = OtherOpLogType.class, name = "上传资金支付请款单其它附件,ID:{}", params = {"#vo.id"})
  371 + public void uploadOtherAttachment(FundPaymentOtherAttachmentVo vo) {
  372 + Assert.notBlank(vo.getId());
  373 +
  374 + FundPaymentRequest entity = this.getById(vo.getId());
  375 + if (entity == null) {
  376 + throw new DefaultClientException("请款单不存在!");
  377 + }
  378 + assertValid(entity);
  379 +
  380 + this.update(Wrappers.lambdaUpdate(FundPaymentRequest.class)
  381 + .set(FundPaymentRequest::getOtherFileIds, vo.getOtherFileIds())
  382 + .set(FundPaymentRequest::getOtherFileNames, vo.getOtherFileNames())
  383 + .eq(FundPaymentRequest::getId, vo.getId()));
  384 +
  385 + OpLogUtil.setVariable("id", vo.getId());
  386 + OpLogUtil.setExtra(vo);
  387 + }
  388 +
  389 + @Override
  390 + @Transactional(rollbackFor = Exception.class)
  391 + public void updateApprovalStatus(String id, String approvalStatus) {
  392 + if (StringUtil.isBlank(id) || StringUtil.isBlank(approvalStatus)) {
  393 + throw new DefaultClientException("请款单ID、审核状态不能为空!");
  394 + }
  395 +
  396 + FundPaymentRequest entity = this.getById(id);
  397 + if (entity == null) {
  398 + throw new DefaultClientException("请款单不存在!");
  399 + }
  400 +
  401 + this.update(Wrappers.lambdaUpdate(FundPaymentRequest.class)
  402 + .set(FundPaymentRequest::getApprovalStatus, approvalStatus)
  403 + .set(FundPaymentRequest::getFlowNode, STATUS_PASS.equals(approvalStatus) ? null : NODE_GYGLKZJY)
  404 + .eq(FundPaymentRequest::getId, id));
  405 + }
  406 +
  407 + @Override
  408 + @Transactional(rollbackFor = Exception.class)
  409 + public void updateNoFlowInstance(Map<String, Object> map) {
  410 + try {
  411 + // 审核状态
  412 + Object examStatusObj = map.get("examStatus");
  413 + String examStatus = examStatusObj == null ? null : String.valueOf(examStatusObj);
  414 +
  415 + // 刚审核完成的环节编码
  416 + Object nodeObj = map.get("nodeCode");
  417 + String nodeCode = nodeObj == null ? null : String.valueOf(nodeObj);
  418 +
  419 + // 业务ID(兼容 variables 子 map 包裹)
  420 + String bizId = resolveBizId(map);
  421 + if (StringUtil.isBlank(bizId)) {
  422 + throw new DefaultClientException("请款单审核回调缺少业务ID!");
  423 + }
  424 +
  425 + boolean gyglkzgNode = nodeCode != null && nodeCode.endsWith("gyglkzg");
  426 + if (!gyglkzgNode) {
  427 + return;
  428 + }
  429 +
  430 + // 拒绝/撤销/终止:统一回到供应管理科资金管理员(制单)
  431 + if (StringUtil.isNotBlank(examStatus) && !"PASS".equals(examStatus)) {
  432 + this.update(Wrappers.lambdaUpdate(FundPaymentRequest.class)
  433 + .set(FundPaymentRequest::getFlowNode, NODE_GYGLKZJY)
  434 + .eq(FundPaymentRequest::getId, bizId));
  435 + return;
  436 + }
  437 +
  438 + // 审核通过:记录供应管理科主管审核人
  439 + String userId = SecurityUtil.getCurrentUser().getId();
  440 + String userName = SecurityUtil.getCurrentUser().getName();
  441 + this.update(Wrappers.lambdaUpdate(FundPaymentRequest.class)
  442 + .set(FundPaymentRequest::getGyglkzgId, userId)
  443 + .set(FundPaymentRequest::getGyglkzgName, userName)
  444 + .eq(FundPaymentRequest::getId, bizId));
  445 + } catch (Exception ex) {
  446 + ex.printStackTrace();
  447 + }
  448 + }
  449 +
  450 + @Override
  451 + @Transactional(rollbackFor = Exception.class)
  452 + public void deleteByWeighingTicketId(String weighingTicketId) {
  453 + if (StringUtil.isBlank(weighingTicketId)) {
  454 + return;
  455 + }
  456 +
  457 + // 码单来源的请款单(含该码单链上后续生成的补充请款单)
  458 + List<FundPaymentRequest> requests = this.list(
  459 + Wrappers.lambdaQuery(FundPaymentRequest.class)
  460 + .eq(FundPaymentRequest::getTicketId, weighingTicketId)
  461 + .eq(FundPaymentRequest::getDeleted, false));
  462 +
  463 + // 该码单关联收料单生成的请款单(收料单未冗余码单ID时仍能全部作废),按ID去重合并
  464 + List<String> receiveIds = receiveOrderMapper.selectList(
  465 + Wrappers.lambdaQuery(ProcurementWarehouseReceiveOrder.class)
  466 + .eq(ProcurementWarehouseReceiveOrder::getWeighingTicketId, weighingTicketId))
  467 + .stream().map(ProcurementWarehouseReceiveOrder::getId).collect(Collectors.toList());
  468 + if (CollectionUtil.isNotEmpty(receiveIds)) {
  469 + List<FundPaymentRequest> byReceive = this.list(
  470 + Wrappers.lambdaQuery(FundPaymentRequest.class)
  471 + .in(FundPaymentRequest::getReceiveId, receiveIds)
  472 + .eq(FundPaymentRequest::getDeleted, false));
  473 + if (CollectionUtil.isNotEmpty(byReceive)) {
  474 + Map<String, FundPaymentRequest> merged = new HashMap<>();
  475 + requests.forEach(r -> merged.put(r.getId(), r));
  476 + byReceive.forEach(r -> merged.put(r.getId(), r));
  477 + requests = new ArrayList<>(merged.values());
  478 + }
  479 + }
  480 +
  481 + if (CollectionUtil.isEmpty(requests)) {
  482 + return;
  483 + }
  484 +
  485 + for (FundPaymentRequest request : requests) {
  486 + // 审核中的先终止流程,再作废
  487 + if (STATUS_AUDIT.equals(request.getApprovalStatus())) {
  488 + terminateRunningFlow(request.getId());
  489 + }
  490 + this.update(Wrappers.lambdaUpdate(FundPaymentRequest.class)
  491 + .set(FundPaymentRequest::getDeleted, true)
  492 + .set(STATUS_AUDIT.equals(request.getApprovalStatus()),
  493 + FundPaymentRequest::getApprovalStatus, STATUS_REFUSE)
  494 + .eq(FundPaymentRequest::getId, request.getId()));
  495 + }
  496 + }
  497 +
  498 + /**
  499 + * 来源单可用性校验 + 组装请款单主表冗余数据(来源单信息、请款单类型、请款附件)
  500 + */
  501 + private FundPaymentRequest buildContext(String source, String sourceId) {
  502 + FundPaymentRequest context = new FundPaymentRequest();
  503 + context.setSource(source);
  504 + context.setSourceId(sourceId);
  505 +
  506 + if (SOURCE_PLAN.equals(source)) {
  507 + ProcurementPlan plan = assertPlanUsable(sourceId);
  508 + // 买断自提首付款:请款单只会有一个计划
  509 + context.setPlanIds(plan.getId());
  510 + context.setPlanCodes(plan.getCode());
  511 + context.setBizType(plan.getDeliveryMode());
  512 + context.setCompanyShortId(plan.getCompanyShortId());
  513 + context.setCompanyShortName(plan.getCompanyShortName());
  514 + context.setWorkshopId(plan.getWorkshopId());
  515 + context.setWorkshopName(plan.getWorkshopName());
  516 + // 请款附件:计划生成的请款单自动带出计划上单独上传的请款附件
  517 + context.setRequestFileIds(plan.getRequestFileIds());
  518 + context.setRequestFileNames(plan.getRequestFileNames());
  519 + context.setRequestKind(KIND_NORMAL);
  520 + return context;
  521 + }
  522 +
  523 + if (SOURCE_TICKET.equals(source)) {
  524 + ProcurementWeighingTicket ticket = assertTicketUsable(sourceId);
  525 + List<String> planIdList = ticketLinesPlanIds(sourceId);
  526 + if (CollectionUtil.isEmpty(planIdList)) {
  527 + throw new DefaultClientException("该过磅码单未关联采购计划,无法生成请款单!");
  528 + }
  529 + List<ProcurementPlan> plans = procurementPlanMapper.selectBatchIds(planIdList);
  530 + if (CollectionUtil.isEmpty(plans)) {
  531 + throw new DefaultClientException("过磅码单关联的采购计划不存在!");
  532 + }
  533 + ProcurementPlan first = plans.get(0);
  534 + context.setPlanIds(String.join(",", planIdList));
  535 + context.setPlanCodes(plans.stream().map(ProcurementPlan::getCode).collect(Collectors.joining(",")));
  536 + context.setBizType(first.getDeliveryMode());
  537 + context.setCompanyShortId(ticket.getCompanyShortId());
  538 + context.setCompanyShortName(ticket.getCompanyShortName());
  539 + context.setWorkshopId(ticket.getWorkshopId());
  540 + context.setWorkshopName(ticket.getWorkshopName());
  541 + context.setTicketId(ticket.getId());
  542 + context.setTicketCode(ticket.getCode());
  543 + // 同一码单存在审核通过的请款单时,本次生成为补充请款单
  544 + context.setRequestKind(hasPassedRequest(r -> r.eq(FundPaymentRequest::getTicketId, ticket.getId()))
  545 + ? KIND_SUPPLEMENT : KIND_NORMAL);
  546 + return context;
  547 + }
  548 +
  549 + // RECEIVE
  550 + ProcurementWarehouseReceiveOrder receive = assertReceiveUsable(sourceId);
  551 + List<String> planIdList = splitList(receive.getPlanIds());
  552 + if (CollectionUtil.isEmpty(planIdList)) {
  553 + throw new DefaultClientException("仓库收料单未关联采购计划,无法生成请款单!");
  554 + }
  555 + List<ProcurementPlan> plans = procurementPlanMapper.selectBatchIds(planIdList);
  556 + if (CollectionUtil.isEmpty(plans)) {
  557 + throw new DefaultClientException("仓库收料单关联的采购计划不存在!");
  558 + }
  559 + ProcurementPlan first = plans.get(0);
  560 + context.setPlanIds(String.join(",", planIdList));
  561 + context.setPlanCodes(plans.stream().map(ProcurementPlan::getCode).collect(Collectors.joining(",")));
  562 + context.setBizType(first.getDeliveryMode());
  563 + // 公司简称取关联过磅码单
  564 + if (StringUtil.isNotBlank(receive.getWeighingTicketId())) {
  565 + ProcurementWeighingTicket ticket = weighingTicketMapper.selectById(receive.getWeighingTicketId());
  566 + if (ticket != null) {
  567 + context.setCompanyShortId(ticket.getCompanyShortId());
  568 + context.setCompanyShortName(ticket.getCompanyShortName());
  569 + }
  570 + }
  571 + context.setWorkshopId(receive.getWorkshopId());
  572 + context.setWorkshopName(receive.getWorkshopName());
  573 + context.setTicketId(receive.getWeighingTicketId());
  574 + context.setTicketCode(receive.getWeighingTicketCode());
  575 + context.setReceiveId(receive.getId());
  576 + // 补充请款单只针对送货到厂正常:同一码单链上已有审核通过的码单请款单时,收料单尾款视为补充;
  577 + // 买断自提尾款、退料收料单均为正常请款单,不要求填写补充说明及附件
  578 + boolean supplement = DELIVERY_MODE_FACTORY_DELIVERY.equals(context.getBizType())
  579 + && StringUtil.isNotBlank(context.getTicketId())
  580 + && hasPassedRequest(r -> r.eq(FundPaymentRequest::getSource, SOURCE_TICKET)
  581 + .eq(FundPaymentRequest::getTicketId, context.getTicketId()));
  582 + context.setRequestKind(supplement ? KIND_SUPPLEMENT : KIND_NORMAL);
  583 + return context;
  584 + }
  585 +
  586 + /**
  587 + * 明细预付金额计算(按来源自动计算,界限值口径见各分支)
  588 + */
  589 + private List<FundPaymentRequestLine> calcLines(String source, String sourceId) {
  590 + List<FundPaymentRequestLine> lines = new ArrayList<>();
  591 +
  592 + if (SOURCE_PLAN.equals(source)) {
  593 + // 买断自提首付款(单计划):预付金额 = Σ(计划明细数量×实际采购价)×结算比例/100
  594 + FundPaymentRequestLine line = new FundPaymentRequestLine();
  595 + line.setPlanId(sourceId);
  596 + ProcurementPlan plan = procurementPlanMapper.selectById(sourceId);
  597 + line.setPlanCode(plan == null ? null : plan.getCode());
  598 + line.setPrepaidAmount(calcPlanPrepaid(sourceId));
  599 + lines.add(line);
  600 + return lines;
  601 + }
  602 +
  603 + if (SOURCE_TICKET.equals(source)) {
  604 + // 送货到厂正常(码单完成状态):
  605 + // 第一个界限值 = (Σ明细过磅数量×单价)×结算比例;第二个界限值 = 第一个界限值-第一个申请金额,依次计算
  606 + // 即每行预付金额 = 该计划份额(Σ码单明细过磅数量(kg→吨)×计划明细实际采购价×结算比例/100)- 该计划前置请款单申请金额合计
  607 + List<ProcurementWeighingTicketLine> ticketLines = weighingTicketLineMapper.selectList(
  608 + Wrappers.lambdaQuery(ProcurementWeighingTicketLine.class)
  609 + .eq(ProcurementWeighingTicketLine::getWeighingTicketId, sourceId));
  610 + Map<String, BigDecimal> poolByPlan = new HashMap<>();
  611 + Map<String, String> planCodeByPlan = new HashMap<>();
  612 + for (ProcurementWeighingTicketLine ticketLine : ticketLines) {
  613 + if (ticketLine.getProcurementPlanId() == null || ticketLine.getQuantity() == null) {
  614 + continue;
  615 + }
  616 + BigDecimal price = resolveActualPurchasePrice(ticketLine.getProcurementPlanId(),
  617 + ticketLine.getProductId());
  618 + if (price == null) {
  619 + continue;
  620 + }
  621 + // 过磅码单单位公斤,实际采购价为元/吨:kg→吨换算
  622 + BigDecimal amount = ticketLine.getQuantity().movePointLeft(3).multiply(price);
  623 + poolByPlan.merge(ticketLine.getProcurementPlanId(), amount, BigDecimal::add);
  624 + if (!planCodeByPlan.containsKey(ticketLine.getProcurementPlanId())) {
  625 + ProcurementPlan plan = procurementPlanMapper.selectById(ticketLine.getProcurementPlanId());
  626 + planCodeByPlan.put(ticketLine.getProcurementPlanId(), plan == null ? null : plan.getCode());
  627 + }
  628 + }
  629 + Map<String, BigDecimal> preApplied = sumPreAppliedByTicketPlans(poolByPlan.keySet(), sourceId);
  630 + for (Map.Entry<String, BigDecimal> entry : poolByPlan.entrySet()) {
  631 + FundPaymentRequestLine line = new FundPaymentRequestLine();
  632 + line.setPlanId(entry.getKey());
  633 + line.setPlanCode(planCodeByPlan.get(entry.getKey()));
  634 + BigDecimal ratio = getSettlementRatio(entry.getKey());
  635 + BigDecimal prepaid = entry.getValue().multiply(ratio)
  636 + .divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP)
  637 + .subtract(preApplied.getOrDefault(entry.getKey(), BigDecimal.ZERO))
  638 + .setScale(2, RoundingMode.HALF_UP);
  639 + line.setPrepaidAmount(prepaid);
  640 + lines.add(line);
  641 + }
  642 + return lines;
  643 + }
  644 +
  645 + // RECEIVE(仓库收料单)
  646 + ProcurementWarehouseReceiveOrder receive = receiveOrderMapper.selectById(sourceId);
  647 + List<ProcurementWarehouseReceiveOrderLine> receiveLines = receiveOrderLineMapper.selectList(
  648 + Wrappers.lambdaQuery(ProcurementWarehouseReceiveOrderLine.class)
  649 + .eq(ProcurementWarehouseReceiveOrderLine::getReceiveOrderId, sourceId));
  650 + // 按计划分组:本收料单该计划行含税金额合计
  651 + Map<String, BigDecimal> baseByPlan = receiveLines.stream()
  652 + .filter(l -> l.getProcurementPlanId() != null && l.getTaxAmount() != null)
  653 + .collect(Collectors.groupingBy(ProcurementWarehouseReceiveOrderLine::getProcurementPlanId,
  654 + Collectors.reducing(BigDecimal.ZERO, ProcurementWarehouseReceiveOrderLine::getTaxAmount,
  655 + BigDecimal::add)));
  656 +
  657 + // 退料码单(不在码单生成请款单,只在收料单生成):界限值 = 明细过磅数量×单价合计,无前置扣减
  658 + boolean returnTicket = false;
  659 + if (StringUtil.isNotBlank(receive.getWeighingTicketId())) {
  660 + ProcurementWeighingTicket ticket = weighingTicketMapper.selectById(receive.getWeighingTicketId());
  661 + returnTicket = ticket != null && "RETURN".equals(ticket.getType());
  662 + }
  663 +
  664 + for (Map.Entry<String, BigDecimal> entry : baseByPlan.entrySet()) {
  665 + String planId = entry.getKey();
  666 + FundPaymentRequestLine line = new FundPaymentRequestLine();
  667 + line.setPlanId(planId);
  668 + ProcurementPlan plan = procurementPlanMapper.selectById(planId);
  669 + line.setPlanCode(plan == null ? null : plan.getCode());
  670 +
  671 + BigDecimal prepaid = entry.getValue();
  672 + if (returnTicket) {
  673 + // 退料:无前置扣减
  674 + line.setPrepaidAmount(prepaid.setScale(2, RoundingMode.HALF_UP));
  675 + lines.add(line);
  676 + continue;
  677 + }
  678 +
  679 + if (plan != null && DELIVERY_MODE_PICK_UP.equals(plan.getDeliveryMode())) {
  680 + // 买断自提尾款:同一计划所有审核通过收料单合计含税累加 - 预付款(首付款请款单的申请金额)
  681 + BigDecimal allReceivedTax = sumReceivedTaxByPlan(planId);
  682 + BigDecimal prepaidFromPlan = sumPreAppliedFromPlanSource(planId);
  683 + prepaid = allReceivedTax.subtract(prepaidFromPlan);
  684 + } else {
  685 + // 送货到厂一次性结算尾款:所有明细过磅数量×单价的和 - 所有前置请款单的申请金额
  686 + BigDecimal preApplied = sumPreAppliedByTicket(Collections.singletonList(planId),
  687 + receive.getWeighingTicketId()).getOrDefault(planId, BigDecimal.ZERO);
  688 + prepaid = prepaid.subtract(preApplied);
  689 + }
  690 + line.setPrepaidAmount(prepaid.setScale(2, RoundingMode.HALF_UP));
  691 + lines.add(line);
  692 + }
  693 + return lines;
  694 + }
  695 +
  696 + /**
  697 + * 买断自提首付款预付金额:Σ(计划明细数量(吨)×实际采购价(元/吨))×结算比例/100
  698 + */
  699 + private BigDecimal calcPlanPrepaid(String planId) {
  700 + ProcurementPlan plan = procurementPlanMapper.selectById(planId);
  701 + List<ProcurementPlanLine> planLines = procurementPlanLineMapper.selectList(
  702 + Wrappers.lambdaQuery(ProcurementPlanLine.class)
  703 + .eq(ProcurementPlanLine::getProcurementPlanId, planId));
  704 + BigDecimal sum = planLines.stream()
  705 + .filter(l -> l.getQuantity() != null && l.getActualPurchasePrice() != null)
  706 + .map(l -> l.getQuantity().multiply(l.getActualPurchasePrice()))
  707 + .reduce(BigDecimal.ZERO, BigDecimal::add);
  708 + BigDecimal ratio = plan == null || plan.getSettlementRatio() == null
  709 + ? BigDecimal.valueOf(100) : plan.getSettlementRatio();
  710 + return sum.multiply(ratio).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP);
  711 + }
  712 +
  713 + /**
  714 + * 计划明细实际采购价(按计划ID+品种ID匹配,取第一行)
  715 + */
  716 + private BigDecimal resolveActualPurchasePrice(String planId, String productId) {
  717 + List<ProcurementPlanLine> lines = procurementPlanLineMapper.selectList(
  718 + Wrappers.lambdaQuery(ProcurementPlanLine.class)
  719 + .eq(ProcurementPlanLine::getProcurementPlanId, planId)
  720 + .eq(productId != null, ProcurementPlanLine::getProductId, productId));
  721 + if (CollectionUtil.isEmpty(lines)) {
  722 + return null;
  723 + }
  724 + return lines.get(0).getActualPurchasePrice();
  725 + }
  726 +
  727 + /**
  728 + * 前置请款单(同一码单、审核通过、未作废)中各计划的申请金额合计
  729 + */
  730 + private Map<String, BigDecimal> sumPreAppliedByTicketPlans(Set<String> planIds, String ticketId) {
  731 + Map<String, BigDecimal> result = new HashMap<>();
  732 + if (CollectionUtil.isEmpty(planIds) || StringUtil.isBlank(ticketId)) {
  733 + return result;
  734 + }
  735 + return sumPreAppliedByTicket(new ArrayList<>(planIds), ticketId);
  736 + }
  737 +
  738 + private Map<String, BigDecimal> sumPreAppliedByTicket(List<String> planIds, String ticketId) {
  739 + Map<String, BigDecimal> result = new HashMap<>();
  740 + if (CollectionUtil.isEmpty(planIds) || StringUtil.isBlank(ticketId)) {
  741 + return result;
  742 + }
  743 + List<FundPaymentRequest> preRequests = this.list(Wrappers.lambdaQuery(FundPaymentRequest.class)
  744 + .eq(FundPaymentRequest::getSource, SOURCE_TICKET)
  745 + .eq(FundPaymentRequest::getTicketId, ticketId)
  746 + .eq(FundPaymentRequest::getApprovalStatus, STATUS_PASS)
  747 + .eq(FundPaymentRequest::getDeleted, false));
  748 + if (CollectionUtil.isEmpty(preRequests)) {
  749 + return result;
  750 + }
  751 + List<String> requestIds = preRequests.stream().map(FundPaymentRequest::getId).collect(Collectors.toList());
  752 + for (FundPaymentRequestLine line : requestLineService.getByRequestIds(requestIds)) {
  753 + if (planIds.contains(line.getPlanId()) && line.getApplyAmount() != null) {
  754 + result.merge(line.getPlanId(), line.getApplyAmount(), BigDecimal::add);
  755 + }
  756 + }
  757 + return result;
  758 + }
  759 +
  760 + /**
  761 + * 首付款(PLAN 来源、审核通过、未作废)中该计划的申请金额合计
  762 + */
  763 + private BigDecimal sumPreAppliedFromPlanSource(String planId) {
  764 + List<FundPaymentRequest> preRequests = this.list(Wrappers.lambdaQuery(FundPaymentRequest.class)
  765 + .eq(FundPaymentRequest::getSource, SOURCE_PLAN)
  766 + .eq(FundPaymentRequest::getSourceId, planId)
  767 + .eq(FundPaymentRequest::getApprovalStatus, STATUS_PASS)
  768 + .eq(FundPaymentRequest::getDeleted, false));
  769 + if (CollectionUtil.isEmpty(preRequests)) {
  770 + return BigDecimal.ZERO;
  771 + }
  772 + List<String> requestIds = preRequests.stream().map(FundPaymentRequest::getId).collect(Collectors.toList());
  773 + BigDecimal sum = BigDecimal.ZERO;
  774 + for (FundPaymentRequestLine line : requestLineService.getByRequestIds(requestIds)) {
  775 + if (planId.equals(line.getPlanId()) && line.getApplyAmount() != null) {
  776 + sum = sum.add(line.getApplyAmount());
  777 + }
  778 + }
  779 + return sum;
  780 + }
  781 +
  782 + /**
  783 + * 同一计划所有审核通过收料单(含当前单)的该计划行含税金额合计(审核通过几张算几张)
  784 + */
  785 + private BigDecimal sumReceivedTaxByPlan(String planId) {
  786 + List<ProcurementWarehouseReceiveOrder> receives = receiveOrderMapper.selectList(
  787 + Wrappers.lambdaQuery(ProcurementWarehouseReceiveOrder.class)
  788 + .eq(ProcurementWarehouseReceiveOrder::getDeleted, false)
  789 + .eq(ProcurementWarehouseReceiveOrder::getApprovalStatus, STATUS_PASS));
  790 + if (CollectionUtil.isEmpty(receives)) {
  791 + return BigDecimal.ZERO;
  792 + }
  793 + // planIds 为逗号分隔,拆分后精确匹配,避免 LIKE 命中ID子串
  794 + List<String> receiveIds = receives.stream()
  795 + .filter(r -> splitList(r.getPlanIds()).contains(planId))
  796 + .map(ProcurementWarehouseReceiveOrder::getId)
  797 + .collect(Collectors.toList());
  798 + if (CollectionUtil.isEmpty(receiveIds)) {
  799 + return BigDecimal.ZERO;
  800 + }
  801 + List<ProcurementWarehouseReceiveOrderLine> lines = receiveOrderLineMapper.selectList(
  802 + Wrappers.lambdaQuery(ProcurementWarehouseReceiveOrderLine.class)
  803 + .in(ProcurementWarehouseReceiveOrderLine::getReceiveOrderId, receiveIds)
  804 + .eq(ProcurementWarehouseReceiveOrderLine::getProcurementPlanId, planId));
  805 + return lines.stream()
  806 + .filter(l -> l.getTaxAmount() != null)
  807 + .map(ProcurementWarehouseReceiveOrderLine::getTaxAmount)
  808 + .reduce(BigDecimal.ZERO, BigDecimal::add);
  809 + }
  810 +
  811 + /**
  812 + * 条件存在审核通过请款单(简单条件封装)
  813 + */
  814 + private boolean hasPassedRequest(java.util.function.Consumer<LambdaQueryWrapper<FundPaymentRequest>> condition) {
  815 + LambdaQueryWrapper<FundPaymentRequest> wrapper = Wrappers.lambdaQuery(FundPaymentRequest.class)
  816 + .eq(FundPaymentRequest::getApprovalStatus, STATUS_PASS)
  817 + .eq(FundPaymentRequest::getDeleted, false);
  818 + condition.accept(wrapper);
  819 + return this.count(wrapper) > 0;
  820 + }
  821 +
  822 + /**
  823 + * 保存明细并回填主表合计(合计预付/合计申请)
  824 + */
  825 + private void saveLines(String requestId, List<FundPaymentRequestLine> lines) {
  826 + for (FundPaymentRequestLine line : lines) {
  827 + line.setId(IdUtil.getId());
  828 + line.setRequestId(requestId);
  829 + }
  830 + if (CollectionUtil.isNotEmpty(lines)) {
  831 + requestLineService.saveBatch(lines);
  832 + }
  833 + }
  834 +
  835 + /**
  836 + * 回填主表合计字段
  837 + */
  838 + private void fillTotalAmount(FundPaymentRequest entity, List<FundPaymentRequestLine> lines) {
  839 + BigDecimal totalPrepaid = lines.stream().map(FundPaymentRequestLine::getPrepaidAmount)
  840 + .filter(java.util.Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
  841 + BigDecimal totalApply = lines.stream().map(FundPaymentRequestLine::getApplyAmount)
  842 + .filter(java.util.Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
  843 + entity.setTotalPrepaidAmount(totalPrepaid.setScale(2, RoundingMode.HALF_UP));
  844 + entity.setTotalApplyAmount(totalApply.setScale(2, RoundingMode.HALF_UP));
  845 + }
  846 +
  847 + /**
  848 + * 明细申请金额按计划ID匹配前端传入(预付金额以服务端计算为准)
  849 + */
  850 + private void matchApplyAmount(List<FundPaymentRequestLine> lines, List<FundPaymentRequestLineVo> lineVos) {
  851 + Map<String, BigDecimal> applyByPlan = new HashMap<>();
  852 + if (CollectionUtil.isNotEmpty(lineVos)) {
  853 + for (FundPaymentRequestLineVo lineVo : lineVos) {
  854 + if (StringUtil.isBlank(lineVo.getPlanId()) || lineVo.getApplyAmount() == null) {
  855 + throw new DefaultClientException("请款明细计划编号、申请金额不能为空!");
  856 + }
  857 + applyByPlan.put(lineVo.getPlanId(), lineVo.getApplyAmount());
  858 + }
  859 + }
  860 + // 前端明细必须与服务端按来源计算出的计划一致,禁止多传、漏传计划
  861 + Set<String> expectPlanIds = lines.stream().map(FundPaymentRequestLine::getPlanId)
  862 + .collect(Collectors.toSet());
  863 + if (!applyByPlan.keySet().equals(expectPlanIds)) {
  864 + throw new DefaultClientException("请款明细与来源单关联计划不一致,请重新生成请款单!");
  865 + }
  866 + for (FundPaymentRequestLine line : lines) {
  867 + BigDecimal apply = applyByPlan.get(line.getPlanId()).setScale(2, RoundingMode.HALF_UP);
  868 + if (apply.compareTo(BigDecimal.ZERO) < 0) {
  869 + throw new DefaultClientException("请款明细申请金额不能为负数!");
  870 + }
  871 + // 明细预付金额即本次可申请的界限值,申请金额不得超限
  872 + BigDecimal limit = line.getPrepaidAmount() == null ? BigDecimal.ZERO : line.getPrepaidAmount();
  873 + if (apply.compareTo(limit) > 0) {
  874 + throw new DefaultClientException("计划“" + line.getPlanCode() + "”的申请金额不能超过界限值"
  875 + + limit.setScale(2, RoundingMode.HALF_UP).toPlainString() + "!");
  876 + }
  877 + line.setApplyAmount(apply);
  878 + }
  879 + }
  880 +
  881 + /**
  882 + * 对方户名/开户银行/账号:供应商信息ID非空时以供应商信息为准校验并带出客户名称
  883 + */
  884 + private void applySupplier(FundPaymentRequest entity, String supplierId, String payeeName,
  885 + String bankName, String bankAccount) {
  886 + if (StringUtil.isNotBlank(supplierId)) {
  887 + FundPaymentSupplier supplier = fundPaymentSupplierService.getById(supplierId);
  888 + if (supplier == null) {
  889 + throw new DefaultClientException("资金支付供应商信息不存在!");
  890 + }
  891 + entity.setSupplierId(supplier.getId());
  892 + entity.setPayeeName(supplier.getCustomerName());
  893 + entity.setBankName(bankName);
  894 + entity.setBankAccount(bankAccount);
  895 + return;
  896 + }
  897 + entity.setSupplierId(supplierId);
  898 + entity.setPayeeName(payeeName);
  899 + entity.setBankName(bankName);
  900 + entity.setBankAccount(bankAccount);
  901 + }
  902 +
  903 + /**
  904 + * 来源单可用性校验:计划(买断自提首付款)
  905 + */
  906 + private ProcurementPlan assertPlanUsable(String planId) {
  907 + ProcurementPlan plan = procurementPlanMapper.selectById(planId);
  908 + if (plan == null || Boolean.TRUE.equals(plan.getDeleted())) {
  909 + throw new DefaultClientException("采购计划不存在!");
  910 + }
  911 + if (!"COMPLETED".equals(plan.getProcessStatus())) {
  912 + throw new DefaultClientException("采购计划流程未完成,无法生成请款单!");
  913 + }
  914 + if (!DELIVERY_MODE_PICK_UP.equals(plan.getDeliveryMode())) {
  915 + throw new DefaultClientException("仅买断自提计划可生成首付款请款单!");
  916 + }
  917 + // 必须先上传请款附件:按钮标记 canApplyFromPlan 与 create 提交校验共用本断言
  918 + if (StringUtil.isBlank(plan.getRequestFileIds())) {
  919 + throw new DefaultClientException("请先上传请款附件再生成请款单!");
  920 + }
  921 + // 同一计划同一时间只能生成一张有效请款单(首付款唯一,作废释放)
  922 + int occupied = this.count(Wrappers.lambdaQuery(FundPaymentRequest.class)
  923 + .eq(FundPaymentRequest::getSource, SOURCE_PLAN)
  924 + .eq(FundPaymentRequest::getSourceId, planId)
  925 + .eq(FundPaymentRequest::getDeleted, false));
  926 + if (occupied > 0) {
  927 + throw new DefaultClientException("该采购计划已存在请款单!");
  928 + }
  929 + return plan;
  930 + }
  931 +
  932 + /**
  933 + * 来源单可用性校验:过磅码单(送货到厂正常,完成状态)
  934 + */
  935 + private ProcurementWeighingTicket assertTicketUsable(String ticketId) {
  936 + ProcurementWeighingTicket ticket = weighingTicketMapper.selectById(ticketId);
  937 + if (ticket == null || Boolean.TRUE.equals(ticket.getDeleted())) {
  938 + throw new DefaultClientException("过磅码单不存在!");
  939 + }
  940 + if (!STATUS_PASS.equals(ticket.getApprovalStatus())) {
  941 + throw new DefaultClientException("仅审核通过的过磅码单可生成请款单!");
  942 + }
  943 + // 完成状态口径与化验送样单、化验报告单一致:审核通过 + 已上传签字凭证(completeTime 非空)
  944 + if (ticket.getCompleteTime() == null) {
  945 + throw new DefaultClientException("过磅码单未完成(未上传签字凭证),无法生成请款单!");
  946 + }
  947 + if ("RETURN".equals(ticket.getType())) {
  948 + throw new DefaultClientException("退料过磅码单不允许生成请款单,请在仓库收料单上申请!");
  949 + }
  950 + // 关联计划必须送货到厂且流程已完成(码单完成状态)
  951 + List<String> planIdList = ticketLinesPlanIds(ticketId);
  952 + if (CollectionUtil.isEmpty(planIdList)
  953 + || !isFactoryDeliveryCompletedPlans(new HashSet<>(planIdList))) {
  954 + throw new DefaultClientException("过磅码单关联的采购计划未完成或非送货到厂,无法生成请款单!");
  955 + }
  956 + // 同一码单存在在途(草稿/审核中/已驳回)请款单时不可再生成,审核通过后允许继续生成下一张
  957 + int occupied = this.count(Wrappers.lambdaQuery(FundPaymentRequest.class)
  958 + .eq(FundPaymentRequest::getSource, SOURCE_TICKET)
  959 + .eq(FundPaymentRequest::getTicketId, ticketId)
  960 + .eq(FundPaymentRequest::getDeleted, false)
  961 + .in(FundPaymentRequest::getApprovalStatus, STATUS_DRAFT, STATUS_AUDIT, STATUS_REFUSE));
  962 + if (occupied > 0) {
  963 + throw new DefaultClientException("该过磅码单已存在在途请款单,审核通过后再生成下一张请款单!");
  964 + }
  965 + return ticket;
  966 + }
  967 +
  968 + /**
  969 + * 来源单可用性校验:仓库收料单(尾款/一次性结算/退料)
  970 + */
  971 + private ProcurementWarehouseReceiveOrder assertReceiveUsable(String receiveId) {
  972 + ProcurementWarehouseReceiveOrder receive = receiveOrderMapper.selectById(receiveId);
  973 + if (receive == null || Boolean.TRUE.equals(receive.getDeleted())) {
  974 + throw new DefaultClientException("仓库收料单不存在!");
  975 + }
  976 + if (!STATUS_PASS.equals(receive.getApprovalStatus())) {
  977 + throw new DefaultClientException("仅审核通过的仓库收料单可生成请款单!");
  978 + }
  979 + List<String> planIdList = splitList(receive.getPlanIds());
  980 + if (CollectionUtil.isEmpty(planIdList)) {
  981 + throw new DefaultClientException("仓库收料单未关联采购计划,无法生成请款单!");
  982 + }
  983 + List<ProcurementPlan> plans = procurementPlanMapper.selectBatchIds(planIdList);
  984 + if (CollectionUtil.isEmpty(plans)) {
  985 + throw new DefaultClientException("仓库收料单关联的采购计划不存在!");
  986 + }
  987 + // 同一收料单同一时间只能生成一张有效请款单
  988 + int occupied = this.count(Wrappers.lambdaQuery(FundPaymentRequest.class)
  989 + .eq(FundPaymentRequest::getSource, SOURCE_RECEIVE)
  990 + .eq(FundPaymentRequest::getReceiveId, receiveId)
  991 + .eq(FundPaymentRequest::getDeleted, false));
  992 + if (occupied > 0) {
  993 + throw new DefaultClientException("该仓库收料单已存在请款单,同一时间只能生成一张请款单!");
  994 + }
  995 + // 买断自提专属规则:结算比例100%(含未维护)时首付款已含全款,收料单不展示申请按钮、无尾款可请;
  996 + // 且一个计划分多车时只允许在其中一张审核通过的收料单上生成一张尾款请款单
  997 + // 送货到厂(含退料)不受100%限制,仍须在收料单生成请款单结算尾款
  998 + if (DELIVERY_MODE_PICK_UP.equals(plans.get(0).getDeliveryMode())) {
  999 + if (plans.stream().allMatch(this::isFullRatio)) {
  1000 + throw new DefaultClientException("结算比例为100%,首付款已含全款,无需申请尾款请款单!");
  1001 + }
  1002 + Set<String> occupiedPlanIds = occupiedPickUpPlanIds();
  1003 + if (planIdList.stream().anyMatch(occupiedPlanIds::contains)) {
  1004 + throw new DefaultClientException("该采购计划已在其它仓库收料单生成尾款请款单,不能重复申请!");
  1005 + }
  1006 + }
  1007 + return receive;
  1008 + }
  1009 +
  1010 + /**
  1011 + * 码单关联的计划ID集合(码单明细)
  1012 + */
  1013 + private List<String> ticketLinesPlanIds(String ticketId) {
  1014 + List<ProcurementWeighingTicketLine> lines = weighingTicketLineMapper.selectList(
  1015 + Wrappers.lambdaQuery(ProcurementWeighingTicketLine.class)
  1016 + .eq(ProcurementWeighingTicketLine::getWeighingTicketId, ticketId));
  1017 + return lines.stream()
  1018 + .map(ProcurementWeighingTicketLine::getProcurementPlanId)
  1019 + .filter(java.util.Objects::nonNull)
  1020 + .distinct()
  1021 + .collect(Collectors.toList());
  1022 + }
  1023 +
  1024 + /**
  1025 + * 计划集合是否全部为送货到厂且流程已完成(码单完成状态口径)
  1026 + */
  1027 + private boolean isFactoryDeliveryCompletedPlans(Set<String> planIdSet) {
  1028 + List<ProcurementPlan> plans = procurementPlanMapper.selectBatchIds(planIdSet);
  1029 + if (CollectionUtil.isEmpty(plans) || plans.size() != planIdSet.size()) {
  1030 + return false;
  1031 + }
  1032 + return plans.stream().allMatch(p ->
  1033 + DELIVERY_MODE_FACTORY_DELIVERY.equals(p.getDeliveryMode())
  1034 + && "COMPLETED".equals(p.getProcessStatus())
  1035 + && !Boolean.TRUE.equals(p.getFrozen()));
  1036 + }
  1037 +
  1038 + @Override
  1039 + public boolean canApplyFromPlan(String planId) {
  1040 + if (StringUtil.isBlank(planId)) {
  1041 + return false;
  1042 + }
  1043 + try {
  1044 + // 复用制单校验,保证计划列表按钮标记与 create 提交校验口径完全一致
  1045 + assertPlanUsable(planId);
  1046 + return true;
  1047 + } catch (DefaultClientException ex) {
  1048 + return false;
  1049 + }
  1050 + }
  1051 +
  1052 + @Override
  1053 + public boolean canApplyFromReceive(String receiveId) {
  1054 + if (StringUtil.isBlank(receiveId)) {
  1055 + return false;
  1056 + }
  1057 + try {
  1058 + // 复用制单校验,保证按钮标记与提交校验口径完全一致
  1059 + assertReceiveUsable(receiveId);
  1060 + return true;
  1061 + } catch (DefaultClientException ex) {
  1062 + return false;
  1063 + }
  1064 + }
  1065 +
  1066 + @Override
  1067 + public boolean canApplyFromTicket(String ticketId) {
  1068 + if (StringUtil.isBlank(ticketId)) {
  1069 + return false;
  1070 + }
  1071 + try {
  1072 + assertTicketUsable(ticketId);
  1073 + return true;
  1074 + } catch (DefaultClientException ex) {
  1075 + return false;
  1076 + }
  1077 + }
  1078 +
  1079 + /**
  1080 + * 结算比例是否为全额(未维护按100%处理,与 calcPlanPrepaid、getSettlementRatio 口径一致)
  1081 + */
  1082 + private boolean isFullRatio(ProcurementPlan plan) {
  1083 + return plan.getSettlementRatio() == null
  1084 + || plan.getSettlementRatio().compareTo(BigDecimal.valueOf(100)) == 0;
  1085 + }
  1086 +
  1087 + /**
  1088 + * 买断自提已生成尾款请款单的计划ID集合(同一计划只允许在其中一张审核通过的收料单上申请一次)
  1089 + */
  1090 + private Set<String> occupiedPickUpPlanIds() {
  1091 + List<FundPaymentRequest> requests = this.list(Wrappers.lambdaQuery(FundPaymentRequest.class)
  1092 + .eq(FundPaymentRequest::getSource, SOURCE_RECEIVE)
  1093 + .eq(FundPaymentRequest::getBizType, DELIVERY_MODE_PICK_UP)
  1094 + .eq(FundPaymentRequest::getDeleted, false));
  1095 + if (CollectionUtil.isEmpty(requests)) {
  1096 + return Collections.emptySet();
  1097 + }
  1098 + return requests.stream()
  1099 + .map(FundPaymentRequest::getPlanIds)
  1100 + .filter(StringUtil::isNotBlank)
  1101 + .flatMap(ids -> splitList(ids).stream())
  1102 + .collect(Collectors.toSet());
  1103 + }
  1104 +
  1105 + private BigDecimal getSettlementRatio(String planId) {
  1106 + ProcurementPlan plan = procurementPlanMapper.selectById(planId);
  1107 + return plan == null || plan.getSettlementRatio() == null
  1108 + ? BigDecimal.valueOf(100) : plan.getSettlementRatio();
  1109 + }
  1110 +
  1111 + /**
  1112 + * 作废单校验:作废单只能查看
  1113 + */
  1114 + private void assertValid(FundPaymentRequest entity) {
  1115 + if (Boolean.TRUE.equals(entity.getDeleted())) {
  1116 + throw new DefaultClientException("作废单据只能查看,不允许该操作!");
  1117 + }
  1118 + }
  1119 +
  1120 + /**
  1121 + * 编辑校验:仅草稿、已驳回可修改
  1122 + */
  1123 + private void assertEditable(FundPaymentRequest entity) {
  1124 + if (!STATUS_DRAFT.equals(entity.getApprovalStatus()) && !STATUS_REFUSE.equals(entity.getApprovalStatus())) {
  1125 + throw new DefaultClientException("当前单据状态不允许修改!");
  1126 + }
  1127 + }
  1128 +
  1129 + /**
  1130 + * 审核按钮标记:待办驱动(列表 + 详情两条返回路径都要调用)
  1131 + */
  1132 + private void fillOperateFlags(List<FundPaymentRequest> datas) {
  1133 + if (CollectionUtil.isEmpty(datas)) {
  1134 + return;
  1135 + }
  1136 +
  1137 + List<String> businessIds = datas.stream()
  1138 + .filter(java.util.Objects::nonNull)
  1139 + .map(FundPaymentRequest::getId)
  1140 + .collect(Collectors.toList());
  1141 +
  1142 + List<FlowInstanceWrapper> flowList = flowInstanceWrapperService.getFlowByBusinessIdList(businessIds);
  1143 + Set<String> flowBusinessIdSet = CollectionUtil.isNotEmpty(flowList)
  1144 + ? flowList.stream().map(FlowInstanceWrapper::getBusinessId).collect(Collectors.toSet())
  1145 + : new HashSet<>();
  1146 +
  1147 + List<FlowTaskDto> todoFlowTaskList = flowTaskWrapperMapper.queryTodoList(
  1148 + new QueryTodoTaskListVo(), SecurityUtil.getCurrentUser().getId());
  1149 + Set<String> todoBusinessIdSet = CollectionUtil.isNotEmpty(todoFlowTaskList)
  1150 + ? todoFlowTaskList.stream().map(FlowTaskDto::getBusinessId).collect(Collectors.toSet())
  1151 + : new HashSet<>();
  1152 +
  1153 + for (FundPaymentRequest data : datas) {
  1154 + if (data == null) {
  1155 + continue;
  1156 + }
  1157 + boolean hasFlow = flowBusinessIdSet.contains(data.getId());
  1158 + boolean hasTodo = todoBusinessIdSet.contains(data.getId());
  1159 + data.setShowExamine(hasTodo && STATUS_AUDIT.equals(data.getApprovalStatus()));
  1160 + data.setShowExamineDetail(hasFlow && StringUtil.isNotBlank(data.getApprovalStatus()));
  1161 + }
  1162 + }
  1163 +
  1164 + /**
  1165 + * 从回调参数解析业务ID(兼容 variables 子 map 包裹)
  1166 + */
  1167 + private String resolveBizId(Map<String, Object> map) {
  1168 + Object id = map.get("id");
  1169 + String bizId = id == null ? null : String.valueOf(id);
  1170 + if (StringUtil.isBlank(bizId) || "null".equals(bizId)) {
  1171 + Object bizIdObj = map.get("bizId");
  1172 + bizId = bizIdObj == null ? null : String.valueOf(bizIdObj);
  1173 + }
  1174 + if (StringUtil.isBlank(bizId) || "null".equals(bizId)) {
  1175 + Object variables = map.get("variables");
  1176 + if (variables instanceof Map) {
  1177 + Map<?, ?> variablesMap = (Map<?, ?>) variables;
  1178 + Object vId = variablesMap.get("id");
  1179 + if (vId == null) {
  1180 + vId = variablesMap.get("bizId");
  1181 + }
  1182 + bizId = vId == null ? null : String.valueOf(vId);
  1183 + }
  1184 + }
  1185 + return bizId;
  1186 + }
  1187 +
  1188 + /**
  1189 + * 终止单据进行中的审核流程(作废审核中的单据前先终止流程)
  1190 + */
  1191 + private void terminateRunningFlow(String businessId) {
  1192 + List<FlowInstanceWrapper> flowList = flowInstanceWrapperService.getFlowByBusinessIdList(
  1193 + Collections.singletonList(businessId));
  1194 + if (CollectionUtil.isEmpty(flowList)) {
  1195 + return;
  1196 + }
  1197 + flowList.stream()
  1198 + .filter(f -> f != null && f.getId() != null)
  1199 + .findFirst()
  1200 + .ifPresent(flow -> flowTaskWrapperService.termination(flow.getId()));
  1201 + }
  1202 +
  1203 + private List<String> splitList(String joined) {
  1204 + if (joined == null || joined.isEmpty()) {
  1205 + return Collections.emptyList();
  1206 + }
  1207 + return java.util.Arrays.stream(joined.split("[,,]"))
  1208 + .map(String::trim)
  1209 + .filter(s -> !s.isEmpty())
  1210 + .distinct()
  1211 + .collect(Collectors.toList());
  1212 + }
  1213 +}
@@ -40,6 +40,7 @@ import com.lframework.xingyun.sc.procurement.mappers.plan.ProcurementPlanMapper; @@ -40,6 +40,7 @@ import com.lframework.xingyun.sc.procurement.mappers.plan.ProcurementPlanMapper;
40 import com.lframework.xingyun.sc.procurement.mappers.weighing.ProcurementWeighingTicketMapper; 40 import com.lframework.xingyun.sc.procurement.mappers.weighing.ProcurementWeighingTicketMapper;
41 import com.lframework.xingyun.sc.procurement.service.buyout.ProcurementBuyoutApplyService; 41 import com.lframework.xingyun.sc.procurement.service.buyout.ProcurementBuyoutApplyService;
42 import com.lframework.xingyun.sc.procurement.service.contract.ProcurementContractService; 42 import com.lframework.xingyun.sc.procurement.service.contract.ProcurementContractService;
  43 +import com.lframework.xingyun.sc.procurement.service.fundpayment.FundPaymentRequestService;
43 import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanLineService; 44 import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanLineService;
44 import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService; 45 import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService;
45 import com.lframework.xingyun.sc.procurement.service.quotation.SalesmanQuotationService; 46 import com.lframework.xingyun.sc.procurement.service.quotation.SalesmanQuotationService;
@@ -90,6 +91,8 @@ public class ProcurementPlanServiceImpl extends BaseMpServiceImpl<ProcurementPla @@ -90,6 +91,8 @@ public class ProcurementPlanServiceImpl extends BaseMpServiceImpl<ProcurementPla
90 private SalesmanQuotationService salesmanQuotationService; 91 private SalesmanQuotationService salesmanQuotationService;
91 @Resource 92 @Resource
92 private ProcurementContractService procurementContractService; 93 private ProcurementContractService procurementContractService;
  94 + @Resource
  95 + private FundPaymentRequestService fundPaymentRequestService;
93 96
94 @Override 97 @Override
95 public PageResult<ProcurementPlan> query(Integer pageIndex, Integer pageSize, 98 public PageResult<ProcurementPlan> query(Integer pageIndex, Integer pageSize,
@@ -269,6 +272,31 @@ public class ProcurementPlanServiceImpl extends BaseMpServiceImpl<ProcurementPla @@ -269,6 +272,31 @@ public class ProcurementPlanServiceImpl extends BaseMpServiceImpl<ProcurementPla
269 saveOrUpdateLines(vo.getId(), vo.getProcurementPlanLineList()); 272 saveOrUpdateLines(vo.getId(), vo.getProcurementPlanLineList());
270 } 273 }
271 274
  275 + @Override
  276 + @Transactional(rollbackFor = Exception.class)
  277 + @OpLog(type = OtherOpLogType.class, name = "上传采购计划请款附件,ID:{}", params = {"#id"})
  278 + public void uploadRequestFiles(String id, String fileIds, String fileNames) {
  279 + Assert.notBlank(id);
  280 + if (StringUtil.isBlank(fileIds)) {
  281 + throw new DefaultClientException("请款附件不能为空!");
  282 + }
  283 +
  284 + ProcurementPlan entity = this.getById(id);
  285 + if (entity == null || Boolean.TRUE.equals(entity.getDeleted())) {
  286 + throw new DefaultClientException("采购计划不存在!");
  287 + }
  288 +
  289 + // 只更新请款附件两个字段,避免整表 update 覆盖流程/审核等其它字段
  290 + LambdaUpdateWrapper<ProcurementPlan> wrapper = Wrappers.lambdaUpdate(ProcurementPlan.class)
  291 + .set(ProcurementPlan::getRequestFileIds, fileIds)
  292 + .set(ProcurementPlan::getRequestFileNames, fileNames)
  293 + .eq(ProcurementPlan::getId, id);
  294 + this.update(wrapper);
  295 +
  296 + OpLogUtil.setVariable("id", id);
  297 + OpLogUtil.setExtra(entity);
  298 + }
  299 +
272 /** 300 /**
273 * 保存或更新采购计划明细 301 * 保存或更新采购计划明细
274 * 302 *
@@ -953,6 +981,8 @@ public class ProcurementPlanServiceImpl extends BaseMpServiceImpl<ProcurementPla @@ -953,6 +981,8 @@ public class ProcurementPlanServiceImpl extends BaseMpServiceImpl<ProcurementPla
953 boolean hasTodo = todoBusinessIdSet.contains(data.getId()); 981 boolean hasTodo = todoBusinessIdSet.contains(data.getId());
954 data.setShowExamineDetail(hasFlow && StringUtils.isNotBlank(data.getApprovalStatus())); 982 data.setShowExamineDetail(hasFlow && StringUtils.isNotBlank(data.getApprovalStatus()));
955 data.setShowExamine(hasTodo && CustomerDevelopStatus.AUDIT.name().equals(data.getApprovalStatus())); 983 data.setShowExamine(hasTodo && CustomerDevelopStatus.AUDIT.name().equals(data.getApprovalStatus()));
  984 + // 是否可生成请款单:复用请款单制单校验,保证列表按钮与提交校验口径一致
  985 + data.setShowApplyPayment(fundPaymentRequestService.canApplyFromPlan(data.getId()));
956 } 986 }
957 } 987 }
958 988
@@ -44,6 +44,7 @@ import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementWeighing @@ -44,6 +44,7 @@ import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementWeighing
44 import com.lframework.xingyun.sc.procurement.mappers.receive.ProcurementWarehouseReceiveOrderMapper; 44 import com.lframework.xingyun.sc.procurement.mappers.receive.ProcurementWarehouseReceiveOrderMapper;
45 import com.lframework.xingyun.sc.procurement.mappers.settle.ProcurementMaterialSettleDetailMapper; 45 import com.lframework.xingyun.sc.procurement.mappers.settle.ProcurementMaterialSettleDetailMapper;
46 import com.lframework.xingyun.sc.procurement.mappers.weighing.ProcurementWeighingTicketMapper; 46 import com.lframework.xingyun.sc.procurement.mappers.weighing.ProcurementWeighingTicketMapper;
  47 +import com.lframework.xingyun.sc.procurement.service.fundpayment.FundPaymentRequestService;
47 import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanLineService; 48 import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanLineService;
48 import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService; 49 import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService;
49 import com.lframework.xingyun.sc.procurement.service.receive.ProcurementWarehouseReceiveOrderLineService; 50 import com.lframework.xingyun.sc.procurement.service.receive.ProcurementWarehouseReceiveOrderLineService;
@@ -165,6 +166,8 @@ public class ProcurementWarehouseReceiveOrderServiceImpl @@ -165,6 +166,8 @@ public class ProcurementWarehouseReceiveOrderServiceImpl
165 166
166 @Resource 167 @Resource
167 private SysRoleService sysRoleService; 168 private SysRoleService sysRoleService;
  169 + @Resource
  170 + private FundPaymentRequestService fundPaymentRequestService;
168 171
169 @Override 172 @Override
170 public PageResult<ProcurementWarehouseReceiveOrder> query(Integer pageIndex, Integer pageSize, 173 public PageResult<ProcurementWarehouseReceiveOrder> query(Integer pageIndex, Integer pageSize,
@@ -972,6 +975,8 @@ public class ProcurementWarehouseReceiveOrderServiceImpl @@ -972,6 +975,8 @@ public class ProcurementWarehouseReceiveOrderServiceImpl
972 boolean hasTodo = todoBusinessIdSet.contains(data.getId()); 975 boolean hasTodo = todoBusinessIdSet.contains(data.getId());
973 data.setShowExamine(hasTodo && STATUS_AUDIT.equals(data.getApprovalStatus())); 976 data.setShowExamine(hasTodo && STATUS_AUDIT.equals(data.getApprovalStatus()));
974 data.setShowExamineDetail(hasFlow && StringUtil.isNotBlank(data.getApprovalStatus())); 977 data.setShowExamineDetail(hasFlow && StringUtil.isNotBlank(data.getApprovalStatus()));
  978 + // 申请请款单按钮:结算比例100%无尾款、审核未通过、已申请过的收料单均不展示
  979 + data.setShowApplyPayment(fundPaymentRequestService.canApplyFromReceive(data.getId()));
975 } 980 }
976 } 981 }
977 982
@@ -37,6 +37,7 @@ import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementWeighing @@ -37,6 +37,7 @@ import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementWeighing
37 import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementWeighingTicketLine; 37 import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementWeighingTicketLine;
38 import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementWeighingTicketPlan; 38 import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementWeighingTicketPlan;
39 import com.lframework.xingyun.sc.procurement.mappers.weighing.ProcurementWeighingTicketMapper; 39 import com.lframework.xingyun.sc.procurement.mappers.weighing.ProcurementWeighingTicketMapper;
  40 +import com.lframework.xingyun.sc.procurement.service.fundpayment.FundPaymentRequestService;
40 import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanLineService; 41 import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanLineService;
41 import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService; 42 import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService;
42 import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleDetailService; 43 import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleDetailService;
@@ -127,6 +128,8 @@ public class ProcurementWeighingTicketServiceImpl @@ -127,6 +128,8 @@ public class ProcurementWeighingTicketServiceImpl
127 private ProcurementWarehouseReceiveOrderService warehouseReceiveOrderService; 128 private ProcurementWarehouseReceiveOrderService warehouseReceiveOrderService;
128 @Resource 129 @Resource
129 private ProcurementBuyoutAccountOrderService buyoutAccountOrderService; 130 private ProcurementBuyoutAccountOrderService buyoutAccountOrderService;
  131 + @Resource
  132 + private FundPaymentRequestService fundPaymentRequestService;
130 133
131 @Override 134 @Override
132 public PageResult<ProcurementWeighingTicket> query(Integer pageIndex, Integer pageSize, 135 public PageResult<ProcurementWeighingTicket> query(Integer pageIndex, Integer pageSize,
@@ -591,6 +594,9 @@ public class ProcurementWeighingTicketServiceImpl @@ -591,6 +594,9 @@ public class ProcurementWeighingTicketServiceImpl
591 // 联动作废该码单关联的买断入库核算单(审核中的先终止流程再作废) 594 // 联动作废该码单关联的买断入库核算单(审核中的先终止流程再作废)
592 buyoutAccountOrderService.deleteByWeighingTicketId(id); 595 buyoutAccountOrderService.deleteByWeighingTicketId(id);
593 596
  597 + // 联动作废该码单关联的全部请款单(含码单来源、该码单收料单来源,审核中的先终止流程再作废)
  598 + fundPaymentRequestService.deleteByWeighingTicketId(id);
  599 +
594 OpLogUtil.setVariable("id", id); 600 OpLogUtil.setVariable("id", id);
595 OpLogUtil.setExtra(entity); 601 OpLogUtil.setExtra(entity);
596 } 602 }
@@ -882,6 +888,8 @@ public class ProcurementWeighingTicketServiceImpl @@ -882,6 +888,8 @@ public class ProcurementWeighingTicketServiceImpl
882 boolean hasTodo = todoBusinessIdSet.contains(data.getId()); 888 boolean hasTodo = todoBusinessIdSet.contains(data.getId());
883 data.setShowExamine(hasTodo && STATUS_AUDIT.equals(data.getApprovalStatus())); 889 data.setShowExamine(hasTodo && STATUS_AUDIT.equals(data.getApprovalStatus()));
884 data.setShowExamineDetail(hasFlow && StringUtil.isNotBlank(data.getApprovalStatus())); 890 data.setShowExamineDetail(hasFlow && StringUtil.isNotBlank(data.getApprovalStatus()));
  891 + // 申请请款单按钮:退料码单、未完成码单、已存在在途请款单均不展示
  892 + data.setShowApplyPayment(fundPaymentRequestService.canApplyFromTicket(data.getId()));
885 } 893 }
886 } 894 }
887 895
  1 +package com.lframework.xingyun.sc.procurement.mappers.fundpayment;
  2 +
  3 +import com.lframework.starter.web.core.mapper.BaseMapper;
  4 +import com.lframework.xingyun.sc.procurement.entity.fundpayment.FundPaymentRequestLine;
  5 +import java.util.List;
  6 +import org.apache.ibatis.annotations.Param;
  7 +
  8 +public interface FundPaymentRequestLineMapper extends BaseMapper<FundPaymentRequestLine> {
  9 +
  10 + /**
  11 + * 按请款单ID查询明细
  12 + */
  13 + List<FundPaymentRequestLine> listByRequestId(@Param("requestId") String requestId);
  14 +}
  1 +package com.lframework.xingyun.sc.procurement.mappers.fundpayment;
  2 +
  3 +import com.lframework.starter.web.core.mapper.BaseMapper;
  4 +import com.lframework.xingyun.sc.procurement.entity.fundpayment.FundPaymentRequest;
  5 +import com.lframework.xingyun.sc.procurement.vo.fundpayment.QueryFundPaymentRequestVo;
  6 +import java.util.List;
  7 +import org.apache.ibatis.annotations.Param;
  8 +
  9 +public interface FundPaymentRequestMapper extends BaseMapper<FundPaymentRequest> {
  10 +
  11 + /**
  12 + * 分页查询资金支付请款单
  13 + */
  14 + List<FundPaymentRequest> query(@Param("vo") QueryFundPaymentRequestVo vo);
  15 +
  16 + /**
  17 + * 单条查询
  18 + */
  19 + FundPaymentRequest findById(@Param("id") String id);
  20 +}
  1 +package com.lframework.xingyun.sc.procurement.service.fundpayment;
  2 +
  3 +import com.lframework.starter.web.core.service.BaseMpService;
  4 +import com.lframework.xingyun.sc.procurement.entity.fundpayment.FundPaymentRequestLine;
  5 +import java.util.List;
  6 +
  7 +public interface FundPaymentRequestLineService extends BaseMpService<FundPaymentRequestLine> {
  8 +
  9 + /**
  10 + * 按请款单ID查询明细
  11 + */
  12 + List<FundPaymentRequestLine> getByRequestId(String requestId);
  13 +
  14 + /**
  15 + * 按请款单ID集合查询明细
  16 + */
  17 + List<FundPaymentRequestLine> getByRequestIds(List<String> requestIds);
  18 +
  19 + /**
  20 + * 按请款单ID删除明细(修改时整体重建)
  21 + */
  22 + void deleteByRequestId(String requestId);
  23 +}
  1 +package com.lframework.xingyun.sc.procurement.service.fundpayment;
  2 +
  3 +import com.lframework.starter.web.core.components.resp.PageResult;
  4 +import com.lframework.starter.web.core.service.BaseMpService;
  5 +import com.lframework.xingyun.sc.bo.procurement.GetFundPaymentRequestBo;
  6 +import com.lframework.xingyun.sc.procurement.entity.fundpayment.FundPaymentRequest;
  7 +import com.lframework.xingyun.sc.procurement.vo.fundpayment.CreateFundPaymentRequestVo;
  8 +import com.lframework.xingyun.sc.procurement.vo.fundpayment.FundPaymentOtherAttachmentVo;
  9 +import com.lframework.xingyun.sc.procurement.vo.fundpayment.QueryFundPaymentRequestVo;
  10 +import com.lframework.xingyun.sc.procurement.vo.fundpayment.UpdateFundPaymentRequestVo;
  11 +import java.util.Map;
  12 +
  13 +public interface FundPaymentRequestService extends BaseMpService<FundPaymentRequest> {
  14 +
  15 + /**
  16 + * 分页查询请款单(列表)
  17 + */
  18 + PageResult<FundPaymentRequest> query(Integer pageIndex, Integer pageSize, QueryFundPaymentRequestVo vo);
  19 +
  20 + /**
  21 + * 详情(主表 + 明细)
  22 + */
  23 + GetFundPaymentRequestBo findDetail(String id);
  24 +
  25 + /**
  26 + * 按来源单生成草稿请款单(调用即落库,仅返回生成的请款单ID):
  27 + * 来源单信息、请款附件、请款单类型、请款日期(当天)、付款方式(电汇)、明细预付金额与合计均自动带出/计算;
  28 + * 对方户名/开户行/账号、请款说明、补充说明及附件、明细申请金额留空,由前端凭 ID 查询详情后走修改请款单补充。
  29 + * 同一来源单已有草稿时幂等返回该单ID,不重复生成。
  30 + */
  31 + String generate(String source, String sourceId);
  32 +
  33 + /**
  34 + * 新增请款单(草稿,供应管理科资金管理员)
  35 + */
  36 + String create(CreateFundPaymentRequestVo vo);
  37 +
  38 + /**
  39 + * 修改请款单(仅草稿、已驳回可修改;来源单/预付金额/请款附件不可改)
  40 + */
  41 + void update(UpdateFundPaymentRequestVo vo);
  42 +
  43 + /**
  44 + * 提交请款单审核(草稿、已驳回可提交)
  45 + */
  46 + void submit(String id);
  47 +
  48 + /**
  49 + * 作废请款单(仅审核通过可作废;作废后释放来源单可重新请款)
  50 + */
  51 + void invalid(String id);
  52 +
  53 + /**
  54 + * 上传其它附件(请款单任何状态可上传)
  55 + */
  56 + void uploadOtherAttachment(FundPaymentOtherAttachmentVo vo);
  57 +
  58 + /**
  59 + * 审核流程回调更新审核状态(流程结束时由 BusinessDataHandlerService 调用)
  60 + */
  61 + void updateApprovalStatus(String id, String approvalStatus);
  62 +
  63 + /**
  64 + * 审核过程回调:记录供应管理科主管审核人
  65 + */
  66 + void updateNoFlowInstance(Map<String, Object> map);
  67 +
  68 + /**
  69 + * 按过磅码单作废请款单(码单作废联动,全部作废,审核中的先终止流程)
  70 + */
  71 + void deleteByWeighingTicketId(String weighingTicketId);
  72 +
  73 + /**
  74 + * 采购计划是否可生成请款单(按钮标记,口径与 create 提交校验完全一致)
  75 + */
  76 + boolean canApplyFromPlan(String planId);
  77 +
  78 + /**
  79 + * 仓库收料单是否可生成请款单(按钮标记,口径与 create 提交校验完全一致)
  80 + */
  81 + boolean canApplyFromReceive(String receiveId);
  82 +
  83 + /**
  84 + * 过磅码单是否可生成请款单(按钮标记,口径与 create 提交校验完全一致)
  85 + */
  86 + boolean canApplyFromTicket(String ticketId);
  87 +}
@@ -86,6 +86,15 @@ public interface ProcurementPlanService extends BaseMpService<ProcurementPlan> { @@ -86,6 +86,15 @@ public interface ProcurementPlanService extends BaseMpService<ProcurementPlan> {
86 void update(UpdateProcurementPlanVo vo); 86 void update(UpdateProcurementPlanVo vo);
87 87
88 /** 88 /**
  89 + * 上传请款附件(买断自提首付款请款单生成时自动带出,未上传不可生成请款单)
  90 + *
  91 + * @param id 采购计划ID
  92 + * @param fileIds 请款附件文件ID集合(多文件,逗号分隔)
  93 + * @param fileNames 请款附件文件名称集合(多文件,逗号分隔)
  94 + */
  95 + void uploadRequestFiles(String id, String fileIds, String fileNames);
  96 +
  97 + /**
89 * 保存或更新采购计划明细 98 * 保存或更新采购计划明细
90 * 99 *
91 * @param procurementPlanId 采购计划id 100 * @param procurementPlanId 采购计划id
  1 +package com.lframework.xingyun.sc.procurement.vo.fundpayment;
  2 +
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +import lombok.Data;
  5 +
  6 +import javax.validation.Valid;
  7 +import javax.validation.constraints.NotBlank;
  8 +import javax.validation.constraints.NotEmpty;
  9 +import java.io.Serializable;
  10 +import java.util.List;
  11 +
  12 +@Data
  13 +public class CreateFundPaymentRequestVo implements Serializable {
  14 +
  15 + private static final long serialVersionUID = 1L;
  16 +
  17 + @NotBlank(message = "生成来源不能为空!")
  18 + @ApiModelProperty("生成来源 PLAN-采购计划 TICKET-过磅码单 RECEIVE-仓库收料单")
  19 + private String source;
  20 +
  21 + @NotBlank(message = "来源单ID不能为空!")
  22 + @ApiModelProperty("来源单ID(计划ID/码单ID/收料单ID)")
  23 + private String sourceId;
  24 +
  25 + @ApiModelProperty("资金支付供应商信息ID(对方户名/开户银行/账号来源)")
  26 + private String supplierId;
  27 +
  28 + @ApiModelProperty("对方户名(供应商信息客户名称)")
  29 + private String payeeName;
  30 +
  31 + @ApiModelProperty("开户银行(对方户名对应)")
  32 + private String bankName;
  33 +
  34 + @ApiModelProperty("账号(对方户名对应)")
  35 + private String bankAccount;
  36 +
  37 + @ApiModelProperty("请款说明(多行文本)")
  38 + private String requestRemark;
  39 +
  40 + @ApiModelProperty("补充说明(补充请款单填写)")
  41 + private String supplementRemark;
  42 +
  43 + @ApiModelProperty("补充说明附件文件ID集合(补充请款单时上传)")
  44 + private String supplementFileIds;
  45 +
  46 + @ApiModelProperty("补充说明附件文件名称集合")
  47 + private String supplementFileNames;
  48 +
  49 + @NotEmpty(message = "明细不能为空!")
  50 + @Valid
  51 + @ApiModelProperty("明细数据(预付金额由后端按来源自动计算,前端传 applyAmount)")
  52 + private List<FundPaymentRequestLineVo> lines;
  53 +}
  1 +package com.lframework.xingyun.sc.procurement.vo.fundpayment;
  2 +
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +import lombok.Data;
  5 +
  6 +import javax.validation.constraints.NotBlank;
  7 +import java.io.Serializable;
  8 +
  9 +/**
  10 + * 上传资金支付请款单其它附件(请款单任何状态都可上传)
  11 + */
  12 +@Data
  13 +public class FundPaymentOtherAttachmentVo implements Serializable {
  14 +
  15 + private static final long serialVersionUID = 1L;
  16 +
  17 + @NotBlank(message = "ID不能为空!")
  18 + @ApiModelProperty("请款单ID")
  19 + private String id;
  20 +
  21 + @ApiModelProperty("其它附件文件ID集合(多文件,逗号分隔)")
  22 + private String otherFileIds;
  23 +
  24 + @ApiModelProperty("其它附件文件名称集合(多文件,逗号分隔)")
  25 + private String otherFileNames;
  26 +}
  1 +package com.lframework.xingyun.sc.procurement.vo.fundpayment;
  2 +
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +import lombok.Data;
  5 +
  6 +import java.io.Serializable;
  7 +import java.math.BigDecimal;
  8 +
  9 +/**
  10 + * 资金支付请款单明细行(新增/修改共用;预付金额由后端按来源自动计算,申请金额资金管理员填写,合计金额=预付+申请由后端计算)
  11 + */
  12 +@Data
  13 +public class FundPaymentRequestLineVo implements Serializable {
  14 +
  15 + private static final long serialVersionUID = 1L;
  16 +
  17 + @ApiModelProperty("采购计划ID")
  18 + private String planId;
  19 +
  20 + @ApiModelProperty("计划编号(自动带出)")
  21 + private String planCode;
  22 +
  23 + @ApiModelProperty("预付金额(自动带出,不可改)")
  24 + private BigDecimal prepaidAmount;
  25 +
  26 + @ApiModelProperty("申请金额(数值,保留两位小数)")
  27 + private BigDecimal applyAmount;
  28 +}
  1 +package com.lframework.xingyun.sc.procurement.vo.fundpayment;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonFormat;
  4 +import com.lframework.starter.common.constants.StringPool;
  5 +import com.lframework.starter.web.core.components.validation.TypeMismatch;
  6 +import com.lframework.starter.web.core.vo.SortPageVo;
  7 +import io.swagger.annotations.ApiModel;
  8 +import io.swagger.annotations.ApiModelProperty;
  9 +import lombok.Data;
  10 +
  11 +import java.io.Serializable;
  12 +import java.time.LocalDateTime;
  13 +
  14 +@Data
  15 +@ApiModel("查询资金支付请款单Vo")
  16 +public class QueryFundPaymentRequestVo extends SortPageVo implements Serializable {
  17 +
  18 + private static final long serialVersionUID = 1L;
  19 +
  20 + @ApiModelProperty("计划编号(模糊匹配)")
  21 + private String planCode;
  22 +
  23 + @ApiModelProperty("户名(对方户名,模糊匹配)")
  24 + private String payeeName;
  25 +
  26 + @ApiModelProperty("分厂ID")
  27 + private String workshopId;
  28 +
  29 + @ApiModelProperty("审核状态 DRAFT/AUDIT/PASS/REFUSE")
  30 + private String approvalStatus;
  31 +
  32 + @ApiModelProperty("创建时间-开始")
  33 + @JsonFormat(pattern = StringPool.DATE_TIME_PATTERN)
  34 + @TypeMismatch(message = "创建时间开始格式有误!")
  35 + private LocalDateTime startTime;
  36 +
  37 + @ApiModelProperty("创建时间-结束")
  38 + @JsonFormat(pattern = StringPool.DATE_TIME_PATTERN)
  39 + @TypeMismatch(message = "创建时间结束格式有误!")
  40 + private LocalDateTime endTime;
  41 +
  42 + @ApiModelProperty("创建人(模糊匹配)")
  43 + private String createBy;
  44 +
  45 + @ApiModelProperty("是否作废 true-已作废 false-有效单(不传默认查有效单)")
  46 + private Boolean deleted;
  47 +}
  1 +package com.lframework.xingyun.sc.procurement.vo.fundpayment;
  2 +
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +import lombok.Data;
  5 +
  6 +import javax.validation.Valid;
  7 +import javax.validation.constraints.NotBlank;
  8 +import javax.validation.constraints.NotEmpty;
  9 +import java.io.Serializable;
  10 +import java.util.List;
  11 +
  12 +/**
  13 + * 修改资金支付请款单(仅草稿、已驳回可修改;来源单/预付金额/请款附件不可改)
  14 + */
  15 +@Data
  16 +public class UpdateFundPaymentRequestVo implements Serializable {
  17 +
  18 + private static final long serialVersionUID = 1L;
  19 +
  20 + @NotBlank(message = "ID不能为空!")
  21 + @ApiModelProperty("ID")
  22 + private String id;
  23 +
  24 + @ApiModelProperty("资金支付供应商信息ID(对方户名/开户银行/账号来源)")
  25 + private String supplierId;
  26 +
  27 + @ApiModelProperty("对方户名(供应商信息客户名称)")
  28 + private String payeeName;
  29 +
  30 + @ApiModelProperty("开户银行(对方户名对应)")
  31 + private String bankName;
  32 +
  33 + @ApiModelProperty("账号(对方户名对应)")
  34 + private String bankAccount;
  35 +
  36 + @ApiModelProperty("请款说明(多行文本)")
  37 + private String requestRemark;
  38 +
  39 + @ApiModelProperty("补充说明(补充请款单填写)")
  40 + private String supplementRemark;
  41 +
  42 + @ApiModelProperty("补充说明附件文件ID集合")
  43 + private String supplementFileIds;
  44 +
  45 + @ApiModelProperty("补充说明附件文件名称集合")
  46 + private String supplementFileNames;
  47 +
  48 + @NotEmpty(message = "明细不能为空!")
  49 + @Valid
  50 + @ApiModelProperty("明细数据(预付金额由后端按来源自动计算,前端传 applyAmount)")
  51 + private List<FundPaymentRequestLineVo> lines;
  52 +}
  1 +package com.lframework.xingyun.sc.procurement.vo.plan;
  2 +
  3 +import com.lframework.starter.web.core.vo.BaseVo;
  4 +import io.swagger.annotations.ApiModel;
  5 +import io.swagger.annotations.ApiModelProperty;
  6 +import lombok.Data;
  7 +
  8 +import javax.validation.constraints.NotBlank;
  9 +import java.io.Serializable;
  10 +
  11 +@Data
  12 +@ApiModel("采购计划上传请款附件Vo")
  13 +public class UploadProcurementPlanRequestFileVo implements BaseVo, Serializable {
  14 +
  15 + private static final long serialVersionUID = 1L;
  16 +
  17 + @ApiModelProperty(value = "采购计划ID", required = true)
  18 + @NotBlank(message = "采购计划ID不能为空!")
  19 + private String id;
  20 +
  21 + @ApiModelProperty(value = "请款附件文件ID集合(多文件,逗号分隔)", required = true)
  22 + @NotBlank(message = "请款附件不能为空!")
  23 + private String fileIds;
  24 +
  25 + @ApiModelProperty("请款附件文件名称集合(多文件,逗号分隔)")
  26 + private String fileNames;
  27 +}
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper
  3 + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4 + "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5 +<mapper namespace="com.lframework.xingyun.sc.procurement.mappers.fundpayment.FundPaymentRequestLineMapper">
  6 +
  7 + <resultMap id="FundPaymentRequestLineResult"
  8 + type="com.lframework.xingyun.sc.procurement.entity.fundpayment.FundPaymentRequestLine">
  9 + <id column="id" property="id"/>
  10 + <result column="request_id" property="requestId"/>
  11 + <result column="plan_id" property="planId"/>
  12 + <result column="plan_code" property="planCode"/>
  13 + <result column="prepaid_amount" property="prepaidAmount"/>
  14 + <result column="apply_amount" property="applyAmount"/>
  15 + <result column="create_by_id" property="createById"/>
  16 + <result column="create_by" property="createBy"/>
  17 + <result column="update_by_id" property="updateById"/>
  18 + <result column="update_by" property="updateBy"/>
  19 + <result column="create_time" property="createTime"/>
  20 + <result column="update_time" property="updateTime"/>
  21 + </resultMap>
  22 +
  23 + <select id="listByRequestId" resultMap="FundPaymentRequestLineResult">
  24 + SELECT
  25 + tb.id,
  26 + tb.request_id,
  27 + tb.plan_id,
  28 + tb.plan_code,
  29 + tb.prepaid_amount,
  30 + tb.apply_amount,
  31 + tb.create_by_id,
  32 + tb.create_by,
  33 + tb.update_by_id,
  34 + tb.update_by,
  35 + tb.create_time,
  36 + tb.update_time
  37 + FROM fund_payment_request_line AS tb
  38 + WHERE tb.request_id = #{requestId}
  39 + ORDER BY tb.create_time ASC, tb.id ASC
  40 + </select>
  41 +</mapper>
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper
  3 + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4 + "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5 +<mapper namespace="com.lframework.xingyun.sc.procurement.mappers.fundpayment.FundPaymentRequestMapper">
  6 +
  7 + <resultMap id="FundPaymentRequestResult"
  8 + type="com.lframework.xingyun.sc.procurement.entity.fundpayment.FundPaymentRequest">
  9 + <id column="id" property="id"/>
  10 + <result column="source" property="source"/>
  11 + <result column="source_id" property="sourceId"/>
  12 + <result column="request_kind" property="requestKind"/>
  13 + <result column="biz_type" property="bizType"/>
  14 + <result column="plan_ids" property="planIds"/>
  15 + <result column="plan_codes" property="planCodes"/>
  16 + <result column="ticket_id" property="ticketId"/>
  17 + <result column="ticket_code" property="ticketCode"/>
  18 + <result column="receive_id" property="receiveId"/>
  19 + <result column="company_short_id" property="companyShortId"/>
  20 + <result column="company_short_name" property="companyShortName"/>
  21 + <result column="workshop_id" property="workshopId"/>
  22 + <result column="workshop_name" property="workshopName"/>
  23 + <result column="request_date" property="requestDate"/>
  24 + <result column="pay_method" property="payMethod"/>
  25 + <result column="supplier_id" property="supplierId"/>
  26 + <result column="payee_name" property="payeeName"/>
  27 + <result column="bank_name" property="bankName"/>
  28 + <result column="bank_account" property="bankAccount"/>
  29 + <result column="request_remark" property="requestRemark"/>
  30 + <result column="request_file_ids" property="requestFileIds"/>
  31 + <result column="request_file_names" property="requestFileNames"/>
  32 + <result column="supplement_remark" property="supplementRemark"/>
  33 + <result column="supplement_file_ids" property="supplementFileIds"/>
  34 + <result column="supplement_file_names" property="supplementFileNames"/>
  35 + <result column="other_file_ids" property="otherFileIds"/>
  36 + <result column="other_file_names" property="otherFileNames"/>
  37 + <result column="total_prepaid_amount" property="totalPrepaidAmount"/>
  38 + <result column="total_apply_amount" property="totalApplyAmount"/>
  39 + <result column="flow_node" property="flowNode"/>
  40 + <result column="approval_status" property="approvalStatus"/>
  41 + <result column="gyglkzg_id" property="gyglkzgId"/>
  42 + <result column="gyglkzg_name" property="gyglkzgName"/>
  43 + <result column="deleted" property="deleted"/>
  44 + <result column="create_by_id" property="createById"/>
  45 + <result column="create_by" property="createBy"/>
  46 + <result column="update_by_id" property="updateById"/>
  47 + <result column="update_by" property="updateBy"/>
  48 + <result column="create_time" property="createTime"/>
  49 + <result column="update_time" property="updateTime"/>
  50 + </resultMap>
  51 +
  52 + <sql id="FPR_sql">
  53 + SELECT
  54 + tb.id,
  55 + tb.source,
  56 + tb.source_id,
  57 + tb.request_kind,
  58 + tb.biz_type,
  59 + tb.plan_ids,
  60 + tb.plan_codes,
  61 + tb.ticket_id,
  62 + tb.ticket_code,
  63 + tb.receive_id,
  64 + tb.company_short_id,
  65 + tb.company_short_name,
  66 + tb.workshop_id,
  67 + tb.workshop_name,
  68 + tb.request_date,
  69 + tb.pay_method,
  70 + tb.supplier_id,
  71 + tb.payee_name,
  72 + tb.bank_name,
  73 + tb.bank_account,
  74 + tb.request_remark,
  75 + tb.request_file_ids,
  76 + tb.request_file_names,
  77 + tb.supplement_remark,
  78 + tb.supplement_file_ids,
  79 + tb.supplement_file_names,
  80 + tb.other_file_ids,
  81 + tb.other_file_names,
  82 + tb.total_prepaid_amount,
  83 + tb.total_apply_amount,
  84 + tb.flow_node,
  85 + tb.approval_status,
  86 + tb.gyglkzg_id,
  87 + tb.gyglkzg_name,
  88 + tb.deleted,
  89 + tb.create_by_id,
  90 + tb.create_by,
  91 + tb.update_by_id,
  92 + tb.update_by,
  93 + tb.create_time,
  94 + tb.update_time
  95 + FROM fund_payment_request AS tb
  96 + </sql>
  97 +
  98 + <select id="query" resultMap="FundPaymentRequestResult">
  99 + <include refid="FPR_sql"/>
  100 + <where>
  101 + <choose>
  102 + <when test="vo.deleted != null">
  103 + tb.deleted = #{vo.deleted}
  104 + </when>
  105 + <otherwise>
  106 + tb.deleted = 0
  107 + </otherwise>
  108 + </choose>
  109 + <if test="vo.planCode != null and vo.planCode != ''">
  110 + AND tb.plan_codes LIKE CONCAT('%', #{vo.planCode}, '%')
  111 + </if>
  112 + <if test="vo.payeeName != null and vo.payeeName != ''">
  113 + AND tb.payee_name LIKE CONCAT('%', #{vo.payeeName}, '%')
  114 + </if>
  115 + <if test="vo.workshopId != null and vo.workshopId != ''">
  116 + AND tb.workshop_id = #{vo.workshopId}
  117 + </if>
  118 + <if test="vo.approvalStatus != null and vo.approvalStatus != ''">
  119 + AND tb.approval_status = #{vo.approvalStatus}
  120 + </if>
  121 + <if test="vo.startTime != null">
  122 + AND tb.create_time &gt;= #{vo.startTime}
  123 + </if>
  124 + <if test="vo.endTime != null">
  125 + AND tb.create_time &lt;= #{vo.endTime}
  126 + </if>
  127 + <if test="vo.createBy != null and vo.createBy != ''">
  128 + AND tb.create_by LIKE CONCAT('%', #{vo.createBy}, '%')
  129 + </if>
  130 + </where>
  131 + ORDER BY tb.create_time DESC
  132 + </select>
  133 +
  134 + <select id="findById" resultMap="FundPaymentRequestResult">
  135 + <include refid="FPR_sql"/>
  136 + <where>
  137 + AND tb.id = #{id}
  138 + </where>
  139 + </select>
  140 +</mapper>
@@ -65,6 +65,8 @@ @@ -65,6 +65,8 @@
65 <result column="salesman_quotation_id" property="salesmanQuotationId"/> 65 <result column="salesman_quotation_id" property="salesmanQuotationId"/>
66 <result column="attachment_file_ids" property="attachmentFileIds"/> 66 <result column="attachment_file_ids" property="attachmentFileIds"/>
67 <result column="attachment_file_names" property="attachmentFileNames"/> 67 <result column="attachment_file_names" property="attachmentFileNames"/>
  68 + <result column="request_file_ids" property="requestFileIds"/>
  69 + <result column="request_file_names" property="requestFileNames"/>
68 <result column="deleted" property="deleted"/> 70 <result column="deleted" property="deleted"/>
69 <result column="general_manager_name" property="generalManagerName"/> 71 <result column="general_manager_name" property="generalManagerName"/>
70 <result column="marketing_manager_name" property="marketingManagerName"/> 72 <result column="marketing_manager_name" property="marketingManagerName"/>
@@ -144,6 +146,8 @@ @@ -144,6 +146,8 @@
144 pp.salesman_quotation_id, 146 pp.salesman_quotation_id,
145 pp.attachment_file_ids, 147 pp.attachment_file_ids,
146 pp.attachment_file_names, 148 pp.attachment_file_names,
  149 + pp.request_file_ids,
  150 + pp.request_file_names,
147 pp.deleted, 151 pp.deleted,
148 pp.general_manager_name, 152 pp.general_manager_name,
149 pp.marketing_manager_name, 153 pp.marketing_manager_name,