提交
This commit is contained in:
1 parent
31be9bfd95
commit
843e13bce3
722 files changed
+288067
-110680
No files matched your search
@@ -10,6 +10,19 @@ export type HazardFlagProduct = {
|
||||
is_explosive?: number
|
||||
}
|
||||
|
||||
export type HazardCertSlotKey = 'purchaseCertUrl' | 'transportCertUrl' | 'legalUseCertUrl'
|
||||
|
||||
export interface HazardCertSlot {
|
||||
key: HazardCertSlotKey
|
||||
label: string
|
||||
}
|
||||
|
||||
const HAZARD_CERT_SLOT_LABELS: Record<HazardCertSlotKey, string> = {
|
||||
purchaseCertUrl: '购买证',
|
||||
transportCertUrl: '运输证',
|
||||
legalUseCertUrl: '合法使用证明'
|
||||
}
|
||||
|
||||
function isTruthyHazardFlag(value: unknown) {
|
||||
return value === 1 || value === true || value === '1'
|
||||
}
|
||||
@@ -34,6 +47,35 @@ export function getHazardProductLabel(product: Pick<PlanProduct, 'isToxic' | 'is
|
||||
return ''
|
||||
}
|
||||
|
||||
/** 按产品危化属性返回所需证书槽位(单一规则源) */
|
||||
export function getRequiredCertSlots(product: HazardFlagProduct): HazardCertSlot[] {
|
||||
const { isToxic, isExplosive } = resolveProductHazardFlags(product)
|
||||
const slots: HazardCertSlot[] = []
|
||||
if (isToxic) {
|
||||
slots.push({ key: 'purchaseCertUrl', label: HAZARD_CERT_SLOT_LABELS.purchaseCertUrl })
|
||||
slots.push({ key: 'transportCertUrl', label: HAZARD_CERT_SLOT_LABELS.transportCertUrl })
|
||||
}
|
||||
if (isExplosive) {
|
||||
slots.push({ key: 'legalUseCertUrl', label: HAZARD_CERT_SLOT_LABELS.legalUseCertUrl })
|
||||
}
|
||||
return slots
|
||||
}
|
||||
|
||||
export function getProductCertUrl(product: PlanProduct, key: HazardCertSlotKey): string {
|
||||
const value = product[key]
|
||||
return typeof value === 'string' ? value.trim() : ''
|
||||
}
|
||||
|
||||
export function isProductCertSlotFilled(product: PlanProduct, key: HazardCertSlotKey): boolean {
|
||||
return Boolean(getProductCertUrl(product, key))
|
||||
}
|
||||
|
||||
export function isProductCertComplete(product: PlanProduct): boolean {
|
||||
const slots = getRequiredCertSlots(product)
|
||||
if (!slots.length) return true
|
||||
return slots.every(slot => isProductCertSlotFilled(product, slot.key))
|
||||
}
|
||||
|
||||
/** 产品名称后追加易制毒/易制爆标识:毒、爆,或「毒 爆」 */
|
||||
export function formatPlProductNameWithHazardMarks(product: HazardFlagProduct) {
|
||||
const name = product.productName || ''
|
||||
@@ -88,9 +130,7 @@ export async function enrichPlanProductsHazardFromCrm<T extends HazardFlagProduc
|
||||
}
|
||||
|
||||
export function findMissingHazardCerts(products: PlanProduct[]) {
|
||||
return products.filter(
|
||||
p => isHazardProduct(p) && (!p.purchaseCertUrl?.trim() || !p.transportCertUrl?.trim())
|
||||
)
|
||||
return products.filter(p => isHazardProduct(p) && !isProductCertComplete(p))
|
||||
}
|
||||
|
||||
export function planHasHazardProducts(products: PlanProduct[] | undefined) {
|
||||
@@ -119,9 +159,21 @@ export function buildMissingHazardCertReadyMessage(
|
||||
return '该计划危化品证书尚未确认齐备'
|
||||
}
|
||||
|
||||
function formatMissingCertLabels(product: PlanProduct): string {
|
||||
const missing = getRequiredCertSlots(product)
|
||||
.filter(slot => !isProductCertSlotFilled(product, slot.key))
|
||||
.map(slot => slot.label)
|
||||
return missing.join('、')
|
||||
}
|
||||
|
||||
export function buildMissingHazardCertMessage(products: PlanProduct[]) {
|
||||
const missing = findMissingHazardCerts(products)
|
||||
if (!missing.length) return ''
|
||||
const names = missing.map(p => `「${p.productName}」`).join('、')
|
||||
return `以下产品须上传购买证和合法使用证明:${names}`
|
||||
const details = missing
|
||||
.map(p => `「${p.productName}」须补充:${formatMissingCertLabels(p)}`)
|
||||
.join(';')
|
||||
return `以下产品证书尚未齐全:${details}`
|
||||
}
|
||||
|
||||
export const HAZARD_CERT_READY_CONFIRM_HINT =
|
||||
'易制毒产品需购买证与运输证;易制爆产品需合法使用证明;同时具备易制毒与易制爆属性的产品需三种证书。'
|
||||
Reference in new issue
Block a user