| | |
| | | import dayjs from "dayjs"; |
| | | import { APPROVAL_MODULE_KEYS } from "./approvalModuleRegistry.js"; |
| | | |
| | | /** 支持审批单号查询/主表展示的审批申请模块 */ |
| | |
| | | return no ? { instanceNo: no } : {}; |
| | | } |
| | | |
| | | /** 组装 approvalInstanceDto 查询片段(申请人 + 审批单号) */ |
| | | /** 组装 approvalInstanceDto 查询片段(申请人 + 审批单号 + 状态 + 时间范围) */ |
| | | export function buildApprovalInstanceSearchDto(searchForm = {}, extraParams = {}) { |
| | | const dto = { |
| | | ...(extraParams && typeof extraParams === "object" ? extraParams : {}), |
| | | }; |
| | | Object.assign(dto, pickApplicantFromSearchForm(searchForm)); |
| | | Object.assign(dto, pickInstanceNoFromSearchForm(searchForm)); |
| | | |
| | | // 审批状态 |
| | | if (searchForm?.status) { |
| | | dto.status = searchForm.status; |
| | | } |
| | | |
| | | // 创建时间范围 |
| | | const range = searchForm?.createTimeRange; |
| | | if (Array.isArray(range) && range[0]) { |
| | | dto.createTimeStart = range[0] + (range[0].includes(":") ? "" : " 00:00:00"); |
| | | } |
| | | if (Array.isArray(range) && range[1]) { |
| | | dto.createTimeEnd = range[1] + (range[1].includes(":") ? "" : " 23:59:59"); |
| | | } |
| | | |
| | | delete dto.createTime; |
| | | delete dto.createTimeStart; |
| | | delete dto.createTimeEnd; |
| | | return dto; |
| | | } |
| | | |
| | |
| | | function matchApplicantKeyword(row, keyword) { |
| | | const kw = (keyword || "").trim().toLowerCase(); |
| | | if (!kw) return true; |
| | | const parts = [ |
| | | row?.applicantName, |
| | | row?.applicantNo, |
| | | row?.applicantId, |
| | | getRowPayloadValue(row, ["applicant", "applicantName", "applicantId"]), |
| | | ] |
| | | .filter((v) => v != null && v !== "") |
| | | .map((v) => String(v).toLowerCase()); |
| | | return parts.some((p) => p.includes(kw)); |
| | | const parts = [row?.applicantName, row?.applicantNo, row?.applicantId, getRowPayloadValue(row, ["applicant", "applicantName", "applicantId"])] |
| | | .filter(v => v != null && v !== "") |
| | | .map(v => String(v).toLowerCase()); |
| | | return parts.some(p => p.includes(kw)); |
| | | } |
| | | |
| | | function matchApplicantId(row, applicantId) { |
| | | if (applicantId == null || applicantId === "") return true; |
| | | const id = String(applicantId); |
| | | if (row?.applicantId != null && String(row.applicantId) === id) return true; |
| | | const payloadApplicant = getRowPayloadValue(row, [ |
| | | "applicant", |
| | | "applicantId", |
| | | "applicantUserId", |
| | | ]); |
| | | const payloadApplicant = getRowPayloadValue(row, ["applicant", "applicantId", "applicantUserId"]); |
| | | return String(payloadApplicant) === id; |
| | | } |
| | | |
| | |
| | | function matchInstanceNo(row, instanceNo) { |
| | | const kw = (instanceNo || "").trim().toLowerCase(); |
| | | if (!kw) return true; |
| | | const parts = [row?.instanceNo, row?.bizId] |
| | | .filter((v) => v != null && v !== "") |
| | | .map((v) => String(v).toLowerCase()); |
| | | return parts.some((p) => p.includes(kw)); |
| | | const parts = [row?.instanceNo, row?.bizId].filter(v => v != null && v !== "").map(v => String(v).toLowerCase()); |
| | | return parts.some(p => p.includes(kw)); |
| | | } |
| | | |
| | | /** 是否存在列表筛选条件(申请人 / 审批单号) */ |
| | | /** 是否存在列表筛选条件(申请人 / 审批单号 / 状态 / 时间范围) */ |
| | | export function hasActiveModuleSearch(moduleKey, searchForm = {}) { |
| | | const sf = searchForm || {}; |
| | | if ((sf.instanceNo || "").trim()) return true; |
| | | if ((sf.applicantKeyword || "").trim()) return true; |
| | | if ((sf.applicantName || "").trim()) return true; |
| | | return sf.applicantId != null && sf.applicantId !== ""; |
| | | if (sf.applicantId != null && sf.applicantId !== "") return true; |
| | | if (sf.status) return true; |
| | | if (Array.isArray(sf.createTimeRange) && sf.createTimeRange.length === 2) return true; |
| | | return false; |
| | | } |
| | | |
| | | /** 按申请人、审批单号做前端兜底筛选 */ |
| | | /** 按申请人、审批单号、状态、时间范围做前端兜底筛选 */ |
| | | export function filterInstanceRowsByModuleSearch(moduleKey, rows, searchForm = {}) { |
| | | const sf = searchForm || {}; |
| | | const list = Array.isArray(rows) ? rows : []; |
| | | if (!hasActiveModuleSearch(moduleKey, sf)) return list; |
| | | |
| | | return list.filter( |
| | | (row) => |
| | | matchInstanceNo(row, sf.instanceNo) && |
| | | matchApplicantId(row, sf.applicantId) && |
| | | matchApplicantKeyword(row, sf.applicantKeyword || sf.applicantName) |
| | | ); |
| | | return list.filter(row => { |
| | | // 审批单号 |
| | | if (!matchInstanceNo(row, sf.instanceNo)) return false; |
| | | // 申请人 |
| | | if (!matchApplicantId(row, sf.applicantId)) return false; |
| | | if (!matchApplicantKeyword(row, sf.applicantKeyword || sf.applicantName)) return false; |
| | | // 状态 |
| | | if (sf.status && String(row.statusRaw || row.status).toUpperCase() !== String(sf.status).toUpperCase()) { |
| | | return false; |
| | | } |
| | | // 时间范围 |
| | | if (Array.isArray(sf.createTimeRange) && sf.createTimeRange.length === 2) { |
| | | const rowTime = row.createTime || row.applyTime; |
| | | if (rowTime) { |
| | | const t = dayjs(rowTime); |
| | | const start = dayjs(sf.createTimeRange[0] + " 00:00:00"); |
| | | const end = dayjs(sf.createTimeRange[1] + " 23:59:59"); |
| | | if (t.isBefore(start) || t.isAfter(end)) return false; |
| | | } |
| | | } |
| | | return true; |
| | | }); |
| | | } |