|
|
@@ -0,0 +1,161 @@
|
|
|
+/**
|
|
|
+ * 作业类型统一解析
|
|
|
+ *
|
|
|
+ * 背景:
|
|
|
+ * - 后端字典 ehs_hazardous_work_type 提供「字典码 -> 作业类型名称」,由后端维护,
|
|
|
+ * 字典码的取值与顺序不保证与前端内置的 1~8 一致;
|
|
|
+ * - 作业票模板与审批流是按源系统编码 HO_PERMIT_* 关联的;
|
|
|
+ * - 若按字典码优先匹配,就会出现「下拉选的是动火作业,套用的却是受限空间作业票模板」,
|
|
|
+ * 甚至「受限空间作业发起了动火作业的审批流」这类张冠李戴。
|
|
|
+ *
|
|
|
+ * 约定:
|
|
|
+ * - 作业类型名称(后端字典值)是与模板、审批流关联的唯一依据;
|
|
|
+ * - 字典码只用于展示与传参;
|
|
|
+ * - 后端字典未配置时用内置作业类型兜底,保证申请页与列表页展示一致。
|
|
|
+ */
|
|
|
+
|
|
|
+/**
|
|
|
+ * 内置作业类型
|
|
|
+ * code:内置字典码(后端字典未配置时兜底使用)
|
|
|
+ * sourceCode:源系统作业票流程编码,与作业票模板一一对应
|
|
|
+ * name:作业类型名称
|
|
|
+ * aliases:名称别名,字典名称与内置名称不完全一致时用于匹配
|
|
|
+ */
|
|
|
+export const BUILT_IN_WORK_TYPES = [
|
|
|
+ { code: '1', name: '动火作业', sourceCode: 'HO_PERMIT_FIRE' },
|
|
|
+ { code: '2', name: '受限空间作业', sourceCode: 'HO_PERMIT_CONFINED_SPACE' },
|
|
|
+ {
|
|
|
+ code: '3',
|
|
|
+ name: '高处作业',
|
|
|
+ sourceCode: 'HO_PERMIT_HEIGHT',
|
|
|
+ aliases: ['高空作业']
|
|
|
+ },
|
|
|
+ { code: '4', name: '吊装作业', sourceCode: 'HO_PERMIT_HOISTING' },
|
|
|
+ { code: '5', name: '临时用电作业', sourceCode: 'HO_PERMIT_ELECTRICITY' },
|
|
|
+ { code: '6', name: '动土作业', sourceCode: 'HO_PERMIT_BREAK_GROUND' },
|
|
|
+ { code: '7', name: '断路作业', sourceCode: 'HO_PERMIT_BREAK_ROAD' },
|
|
|
+ { code: '8', name: '盲板抽堵作业', sourceCode: 'HO_PERMIT_BLIND_PLATE' }
|
|
|
+];
|
|
|
+
|
|
|
+// 泛词不参与包含匹配,避免「作业」「其他」这类名称误命中
|
|
|
+const GENERIC_NAMES = ['作业', '类型', '其他', '其它', '作业票', '其它作业'];
|
|
|
+
|
|
|
+/**
|
|
|
+ * 两个作业类型名称是否指向同一种类型
|
|
|
+ * 完全相同直接命中;否则按包含关系兜底(如字典「受限空间」vs 内置「受限空间作业」)
|
|
|
+ * @param a 名称 a
|
|
|
+ * @param b 名称 b
|
|
|
+ * @returns 是否为同一种作业类型
|
|
|
+ */
|
|
|
+export function isSameWorkTypeName(a, b) {
|
|
|
+ const x = String(a === undefined || a === null ? '' : a).trim();
|
|
|
+ const y = String(b === undefined || b === null ? '' : b).trim();
|
|
|
+ if (!x || !y) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (x === y) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ const short = x.length <= y.length ? x : y;
|
|
|
+ const long = x.length <= y.length ? y : x;
|
|
|
+ if (short.length < 2 || GENERIC_NAMES.includes(short)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return long.indexOf(short) > -1;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 匹配内置作业类型
|
|
|
+ * 匹配顺序:作业类型名称 -> 源系统编码 HO_PERMIT_* -> 内置字典码
|
|
|
+ * @param workType 作业类型编码(后端字典码或源系统 HO_PERMIT_* 编码)
|
|
|
+ * @param workTypeName 作业类型名称
|
|
|
+ * @returns 匹配到的内置作业类型,未匹配返回 null
|
|
|
+ */
|
|
|
+export function matchBuiltInWorkType(workType, workTypeName) {
|
|
|
+ const name =
|
|
|
+ workTypeName === undefined || workTypeName === null
|
|
|
+ ? ''
|
|
|
+ : String(workTypeName).trim();
|
|
|
+ if (name) {
|
|
|
+ const byName = BUILT_IN_WORK_TYPES.find((item) =>
|
|
|
+ [item.name, ...(item.aliases || [])].some((n) =>
|
|
|
+ isSameWorkTypeName(n, name)
|
|
|
+ )
|
|
|
+ );
|
|
|
+ if (byName) {
|
|
|
+ return byName;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const code =
|
|
|
+ workType === undefined || workType === null ? '' : String(workType).trim();
|
|
|
+ if (code) {
|
|
|
+ const byCode = BUILT_IN_WORK_TYPES.find(
|
|
|
+ (item) => item.code === code || item.sourceCode === code
|
|
|
+ );
|
|
|
+ if (byCode) {
|
|
|
+ return byCode;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 构建作业类型下拉项
|
|
|
+ * @param {Array} dictList 后端字典 ehs_hazardous_work_type 的字典项 [{dictCode, dictValue}]
|
|
|
+ * @returns [{ value, label, code, name, sourceCode }],value 为字典码(后端传参用)
|
|
|
+ */
|
|
|
+export function buildWorkTypeOptions(dictList) {
|
|
|
+ const dict = (dictList || []).filter(
|
|
|
+ (item) =>
|
|
|
+ item &&
|
|
|
+ item.dictCode !== undefined &&
|
|
|
+ item.dictCode !== null &&
|
|
|
+ item.dictCode !== ''
|
|
|
+ );
|
|
|
+ if (dict.length) {
|
|
|
+ return dict.map((item) => {
|
|
|
+ const builtIn = matchBuiltInWorkType(item.dictCode, item.dictValue);
|
|
|
+ return {
|
|
|
+ value: item.dictCode,
|
|
|
+ label: item.dictValue,
|
|
|
+ // 内置映射(命中的才有),用于作业票模板、审批流匹配
|
|
|
+ code: builtIn ? builtIn.code : '',
|
|
|
+ name: item.dictValue,
|
|
|
+ sourceCode: builtIn ? builtIn.sourceCode : ''
|
|
|
+ };
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 后端字典未配置时用内置作业类型兜底,保证申请页与列表页展示一致
|
|
|
+ return BUILT_IN_WORK_TYPES.map((item) => ({
|
|
|
+ value: item.code,
|
|
|
+ label: item.name,
|
|
|
+ code: item.code,
|
|
|
+ name: item.name,
|
|
|
+ sourceCode: item.sourceCode
|
|
|
+ }));
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 解析作业类型展示名称
|
|
|
+ * 顺序:后端字典值 -> 内置名称 -> 原始值
|
|
|
+ * @param workType 作业类型编码
|
|
|
+ * @param {Array} dictList 后端字典 ehs_hazardous_work_type 的字典项
|
|
|
+ * @returns 作业类型名称,取不到时返回原始编码
|
|
|
+ */
|
|
|
+export function resolveWorkTypeLabel(workType, dictList) {
|
|
|
+ if (workType === undefined || workType === null || workType === '') {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ const dict = dictList || [];
|
|
|
+ const hit = dict.find(
|
|
|
+ (item) => item && String(item.dictCode) === String(workType)
|
|
|
+ );
|
|
|
+ if (hit && hit.dictValue) {
|
|
|
+ return hit.dictValue;
|
|
|
+ }
|
|
|
+ const builtIn = matchBuiltInWorkType(workType, '');
|
|
|
+ if (builtIn) {
|
|
|
+ return builtIn.name;
|
|
|
+ }
|
|
|
+ return String(workType);
|
|
|
+}
|