safety-eval-service-frontend/src/api/enterpriseInfo/adapter.js

454 lines
15 KiB
JavaScript
Raw Normal View History

2026-06-23 18:07:30 +08:00
/** 企业信息管理:前后端字段与分页格式适配 */
import { formatDate, formatDateTime, toApiDate, toApiDateTime } from "../../utils/dateFormat";
2026-06-25 16:30:37 +08:00
import { asId, isIdFieldName, normalizeQueryIds } from "./idUtil";
import { withOrgId } from "./orgContext";
2026-06-23 18:07:30 +08:00
const GENDER_NAME = { 1: "男", 2: "女" };
const RESIGN_AUDIT_STATUS_NAME = { 0: "未审核", 1: "已审核", 2: "已退回" };
2026-06-25 16:30:37 +08:00
/** 分页查询参数:子表 org_id → org_info.id机构信息管理 getInfo 不走此方法 */
2026-06-23 18:07:30 +08:00
export function toPageQuery(params = {}, fieldMap = {}) {
const query = {
current: params.pageIndex ?? params.current ?? 1,
size: params.pageSize ?? params.size ?? 10,
};
Object.entries(fieldMap).forEach(([from, to]) => {
const value = params[from];
if (value !== undefined && value !== null && value !== "") {
2026-06-25 16:30:37 +08:00
query[to] = isIdFieldName(to) ? asId(value) : value;
2026-06-23 18:07:30 +08:00
}
});
2026-06-25 16:30:37 +08:00
return withOrgId(normalizeQueryIds(query));
2026-06-23 18:07:30 +08:00
}
export function fromPageResponse(res, mapItem) {
if (!res) {
return { success: false, data: [], totalCount: 0 };
}
const list = Array.isArray(res.data) ? res.data : [];
return {
...res,
data: mapItem ? list.map(mapItem) : list,
totalCount: res.totalCount ?? res.total ?? list.length,
};
}
export function fromSingleResponse(res, mapItem) {
if (!res) {
return { success: false, data: null };
}
return {
...res,
data: res.data && mapItem ? mapItem(res.data) : res.data,
};
}
function pick(obj, keys) {
const next = {};
keys.forEach((key) => {
if (obj[key] !== undefined) {
2026-06-25 16:30:37 +08:00
next[key] = isIdFieldName(key) ? asId(obj[key]) : obj[key];
2026-06-23 18:07:30 +08:00
}
});
return next;
}
// ─── 机构信息 ───
export function toOrgInfoForm(data = {}) {
return {
2026-06-25 16:30:37 +08:00
id: asId(data.id),
2026-06-23 18:07:30 +08:00
orgName: data.unitName,
creditCode: data.creditCode,
safetyIndustryCategory: data.safetyIndustryCategoryName,
regionCountyName: data.districtName,
regionStreetName: data.townStreet,
regionCommunityName: data.villageCommunity,
longitude: data.longitude,
latitude: data.latitude,
registerAddress: data.registerAddress,
businessAddress: data.businessAddress,
ownershipType: data.ownershipTypeName,
gbIndustryCode: data.economyIndustryCode,
legalRepresentative: data.legalRepresentative,
legalRepPhone: data.legalRepresentativePhone,
principal: data.principalName,
principalPhone: data.principalPhone,
safetyDeptHead: data.safetyDeptManager,
safetyDeptPhone: data.safetyDeptManagerPhone,
safetyVpPhone: data.safetyDeputyPhone,
productionDate: data.productionDate,
businessStatus: data.businessStatusName,
disclosureUrl: data.infoDisclosureUrl,
workplaceArea: data.workplaceArea,
archiveRoomArea: data.archiveRoomArea,
fullTimeEvaluatorCount: data.fulltimeEvaluatorCount,
registeredSafetyEngineerCount: data.registeredEngineerCount,
authStatusCode: data.authStatusCode,
};
}
export function fromOrgInfoForm(values = {}, options = {}) {
const { isDraft = false } = options;
return {
...pick(values, ["id", "tenantId"]),
unitName: values.orgName,
creditCode: values.creditCode,
safetyIndustryCategoryName: values.safetyIndustryCategory,
districtName: values.regionCountyName,
townStreet: values.regionStreetName,
villageCommunity: values.regionCommunityName,
longitude: values.longitude,
latitude: values.latitude,
registerAddress: values.registerAddress,
businessAddress: values.businessAddress,
ownershipTypeName: values.ownershipType,
economyIndustryCode: values.gbIndustryCode,
legalRepresentative: values.legalRepresentative,
legalRepresentativePhone: values.legalRepPhone,
principalName: values.principal,
principalPhone: values.principalPhone,
safetyDeptManager: values.safetyDeptHead,
safetyDeptManagerPhone: values.safetyDeptPhone,
safetyDeputyPhone: values.safetyVpPhone,
productionDate: values.productionDate,
businessStatusName: values.businessStatus,
infoDisclosureUrl: values.disclosureUrl,
workplaceArea: values.workplaceArea,
archiveRoomArea: values.archiveRoomArea,
fulltimeEvaluatorCount: values.fullTimeEvaluatorCount,
registeredEngineerCount: values.registeredSafetyEngineerCount,
authStatusCode: isDraft ? 0 : 1,
authStatusName: isDraft ? "草稿" : "已提交",
};
}
// ─── 部门 / 岗位 ───
export function toDepartmentForm(data = {}) {
return {
2026-06-25 16:30:37 +08:00
id: asId(data.id),
parentId: asId(data.parentId),
2026-06-23 18:07:30 +08:00
deptName: data.deptName,
leaderName: data.managerName,
leaderAccount: data.managerAccount,
deptLevel: data.deptLevelName ?? data.deptLevelCode,
};
}
export function fromDepartmentForm(values = {}) {
return {
...pick(values, ["id", "parentId", "tenantId"]),
deptName: values.deptName,
managerName: values.leaderName,
managerAccount: values.leaderAccount,
deptLevelName: values.deptLevel,
deptLevelCode: values.deptLevel,
};
}
export function buildDepartmentTree(departments = []) {
const map = new Map();
departments.forEach((item) => {
2026-06-25 16:30:37 +08:00
map.set(asId(item.id), { ...toDepartmentForm(item), children: [] });
2026-06-23 18:07:30 +08:00
});
const roots = [];
departments.forEach((item) => {
2026-06-25 16:30:37 +08:00
const node = map.get(asId(item.id));
const parentId = asId(item.parentId);
if (parentId != null && parentId !== "0" && map.has(parentId)) {
map.get(parentId).children.push(node);
2026-06-23 18:07:30 +08:00
}
else {
roots.push(node);
}
});
return roots;
}
export function toPositionForm(data = {}) {
return {
2026-06-25 16:30:37 +08:00
id: asId(data.id),
deptId: asId(data.deptId),
2026-06-23 18:07:30 +08:00
deptName: data.deptName,
positionName: data.positionName,
dutyDesc: data.dutyDesc,
remark: data.remark ?? data.remarks,
};
}
export function fromPositionForm(values = {}) {
return {
...pick(values, ["id", "tenantId"]),
2026-06-25 16:30:37 +08:00
deptId: asId(values.deptId),
2026-06-23 18:07:30 +08:00
positionName: values.positionName,
dutyDesc: values.dutyDesc,
remark: values.remark,
};
}
// ─── 人员 ───
export function toStaffForm(data = {}) {
return {
2026-06-25 16:30:37 +08:00
id: asId(data.id),
2026-06-23 18:07:30 +08:00
staffName: data.userName,
account: data.account,
gender: data.genderCode,
birthDate: data.birthDate,
2026-06-25 16:30:37 +08:00
deptId: asId(data.deptId),
positionId: asId(data.postId),
2026-06-23 18:07:30 +08:00
idCardNo: data.idCardNo,
homeAddress: data.currentAddress,
officeAddress: data.officeAddress,
education: data.educationName ?? data.educationCode,
graduateSchool: data.graduateSchool,
major: data.major,
employmentStatus: data.employmentStatusCode,
deptName: data.deptName,
positionName: data.postName ?? data.positionName,
certNames: data.certNames,
};
}
export function fromStaffForm(values = {}) {
const genderCode = values.gender;
return {
2026-06-25 16:30:37 +08:00
...pick(values, ["id", "tenantId"]),
2026-06-23 18:07:30 +08:00
userName: values.staffName,
account: values.account,
genderCode,
genderName: GENDER_NAME[genderCode] ?? values.genderName,
birthDate: toApiDate(values.birthDate),
2026-06-25 16:30:37 +08:00
deptId: asId(values.deptId),
postId: asId(values.positionId ?? values.postId),
2026-06-23 18:07:30 +08:00
idCardNo: values.idCardNo,
currentAddress: values.homeAddress,
officeAddress: values.officeAddress,
educationName: values.education,
educationCode: values.education,
graduateSchool: values.graduateSchool,
major: values.major,
employmentStatusCode: values.employmentStatus ?? 1,
employmentStatusName: values.employmentStatus === 2 ? "离职" : "在职",
};
}
// ─── 人员证书 ───
export function toStaffCertForm(data = {}) {
const certImgs = data.certAttachmentUrl
? [{ url: data.certAttachmentUrl, fileName: data.certName }]
: data.certImgFiles || [];
return {
2026-06-25 16:30:37 +08:00
id: asId(data.id),
staffId: asId(data.personnelId),
2026-06-23 18:07:30 +08:00
certName: data.certName,
certCategory: data.certCategoryName ?? data.certCategoryCode,
certWorkCategory: data.operationCategoryName ?? data.operationCategoryCode,
certNo: data.certNo,
issueOrg: data.issueOrg,
validStartDate: data.validStartDate,
validEndDate: data.validEndDate,
reviewDate: data.reviewDate,
certImgFiles: certImgs,
certImgs,
};
}
export function fromStaffCertForm(values = {}) {
const certAttachmentUrl = values.certAttachmentUrl
|| values.certImgs?.[0]?.url
|| values.certImgFiles?.[0]?.url;
return {
...pick(values, ["id", "tenantId"]),
2026-06-25 16:30:37 +08:00
personnelId: asId(values.staffId),
2026-06-23 18:07:30 +08:00
certName: values.certName,
certCategoryName: values.certCategory,
certCategoryCode: values.certCategory,
operationCategoryName: values.certWorkCategory,
operationCategoryCode: values.certWorkCategory,
certNo: values.certNo,
issueOrg: values.issueOrg,
validStartDate: values.validStartDate,
validEndDate: values.validEndDate,
reviewDate: values.reviewDate,
certAttachmentUrl,
};
}
// ─── 机构资质证书 ───
export function toQualificationForm(data = {}) {
const certImgs = data.certImageUrl
? [{ url: data.certImageUrl, fileName: data.certName }]
: data.certImgFiles || [];
return {
2026-06-25 16:30:37 +08:00
id: asId(data.id),
2026-06-23 18:07:30 +08:00
certType: data.licenseTypeName ?? data.licenseTypeCode,
certName: data.certName,
certNo: data.certNo,
issueOrg: data.issueOrg,
issueDate: data.issueDate,
validStartDate: data.validStartDate,
validEndDate: data.validEndDate,
remark: data.remark ?? data.remarks,
enableStatus: data.enableFlag,
issueDate: formatDate(data.issueDate),
validStartDate: formatDate(data.validStartDate),
validEndDate: formatDate(data.validEndDate),
certImgFiles: certImgs,
certImgs,
};
}
export function fromQualificationForm(values = {}) {
const certImageUrl = values.certImageUrl
|| values.certImgs?.[0]?.url
|| values.certImgFiles?.[0]?.url;
return {
...pick(values, ["id", "tenantId"]),
licenseTypeName: values.certType,
licenseTypeCode: values.certType,
certName: values.certName,
certNo: values.certNo,
issueOrg: values.issueOrg,
issueDate: toApiDate(values.issueDate),
validStartDate: toApiDate(values.validStartDate ?? values.validDate?.[0]),
validEndDate: toApiDate(values.validEndDate ?? values.validDate?.[1]),
certImageUrl,
remark: values.remark,
enableFlag: values.enableStatus ?? 1,
};
}
// ─── 装备 ───
export function toEquipForm(data = {}) {
const instrumentType = data.instrumentTypeName ?? data.instrumentTypeCode;
return {
2026-06-25 16:30:37 +08:00
id: asId(data.id),
2026-06-23 18:07:30 +08:00
instrumentType,
deviceType: data.deviceTypeName ?? data.deviceTypeCode,
deviceName: data.deviceName,
model: data.deviceModel,
flowDesc: data.flowDesc,
manufacturer: data.manufacturer,
minFlow: data.minFlow,
maxFlow: data.maxFlow,
calibrationUnit: data.calibrationUnit,
calibrationInitialValue: data.calibrationInitValue,
onSiteCalibrationType: data.fieldCalibrationTypeName ?? data.fieldCalibrationTypeCode,
isDualChannel: data.dualChannelFlag,
enableStatus: data.enableFlag,
};
}
export function fromEquipForm(values = {}) {
return {
...pick(values, ["id", "tenantId"]),
deviceName: values.deviceName,
deviceModel: values.model,
instrumentTypeName: values.instrumentCategory,
instrumentTypeCode: values.instrumentCategory,
deviceTypeName: values.deviceType,
deviceTypeCode: values.deviceType,
manufacturer: values.manufacturer,
flowDesc: values.flowDesc,
minFlow: values.minFlow,
maxFlow: values.maxFlow,
calibrationUnit: values.calibrationUnit,
calibrationInitValue: values.calibrationInitialValue,
fieldCalibrationTypeName: values.onSiteCalibrationType,
fieldCalibrationTypeCode: values.onSiteCalibrationType,
dualChannelFlag: values.isDualChannel,
enableFlag: values.enableStatus ?? 1,
};
}
// ─── 人员变更 / 离职 ───
export function toChangeLogForm(data = {}) {
return {
2026-06-25 16:30:37 +08:00
id: asId(data.id),
staffId: asId(data.personnelId),
2026-06-23 18:07:30 +08:00
changeItem: data.changeItem,
changeTime: formatDateTime(data.changeTime),
createBy: data.operatorName,
};
}
export function toResignApplyForm(data = {}) {
const auditStatus = data.auditStatusCode ?? data.auditStatus ?? 0;
return {
2026-06-25 16:30:37 +08:00
id: asId(data.id),
personnelId: asId(data.personnelId),
2026-06-23 18:07:30 +08:00
applicantName: data.applicantName,
applyTime: formatDateTime(data.applyTime),
expectedLeaveDate: formatDate(data.expectedResignDate),
leaveReason: data.resignReason,
remark: data.remark ?? data.remarks,
rejectReason: data.rejectReason,
auditStatus,
auditStatusName: data.auditStatusName ?? RESIGN_AUDIT_STATUS_NAME[auditStatus] ?? "未审核",
attachmentId: data.reportFileUrl,
account: data.account,
deptName: data.deptName,
};
}
export function fromResignApplyForm(values = {}) {
return {
...pick(values, ["id", "tenantId"]),
2026-06-25 16:30:37 +08:00
personnelId: asId(values.personnelId),
2026-06-23 18:07:30 +08:00
applicantName: values.applicantName,
applyTime: toApiDateTime(values.applyTime),
expectedResignDate: toApiDate(values.expectedLeaveDate),
resignReason: values.leaveReason,
remark: values.remark,
reportFileUrl: values.attachmentId ?? values.reportFileUrl,
auditStatusCode: values.auditStatus ?? 0,
auditStatusName: values.auditStatus === 1 ? "已审核" : values.auditStatus === 2 ? "已退回" : "未审核",
};
}
export function fromResignAuditForm(values = {}) {
const auditStatus = values.auditStatus;
return {
2026-06-25 16:30:37 +08:00
id: asId(values.id),
personnelId: asId(values.personnelId),
2026-06-23 18:07:30 +08:00
auditStatusCode: auditStatus,
auditStatusName: auditStatus === 1 ? "已审核" : auditStatus === 2 ? "已退回" : "未审核",
rejectReason: values.rejectReason,
};
}
export function toStaffChangeSummary(personnel = {}) {
const employmentCode = Number(personnel.employmentStatusCode ?? personnel.employmentStatus ?? 1);
const hasResignApply = personnel.resignApplyId != null && personnel.resignApplyId !== "";
const resignStatusRaw = personnel.resignAuditStatus;
let resignStatus = null;
if (hasResignApply) {
resignStatus = resignStatusRaw === null || resignStatusRaw === undefined
? 0
: Number(resignStatusRaw);
}
return {
2026-06-25 16:30:37 +08:00
id: asId(personnel.id),
staffId: asId(personnel.id),
2026-06-23 18:07:30 +08:00
account: personnel.account,
staffName: personnel.userName ?? personnel.staffName,
deptName: personnel.deptName || "",
employmentStatus: employmentCode,
employmentStatusCode: employmentCode,
employmentStatusName: personnel.employmentStatusName
|| (employmentCode === 2 ? "离职" : "在职"),
changeCount: Number(personnel.changeCount ?? 0),
2026-06-25 16:30:37 +08:00
resignApplyId: asId(personnel.resignApplyId),
2026-06-23 18:07:30 +08:00
resignAuditStatus: resignStatus,
resignAuditStatusName: personnel.resignAuditStatusName
?? (resignStatus !== null ? RESIGN_AUDIT_STATUS_NAME[resignStatus] : undefined),
};
}