package com.estate.expert.admin.io.processor.impl.business; import com.estate.expert.admin.domain.business.device.Device; import com.estate.expert.admin.domain.business.device.DeviceType; import com.estate.expert.admin.io.processor.RowDataProcessorBase; import com.estate.expert.admin.utils.ExcelParseUtils; import java.util.HashMap; import java.util.List; /** * 设备处理器 * * 用于处理设备信息的读取和写入 */ public class DeviceProcessor extends RowDataProcessorBase { /** * 获取表头 * * @return 表头 */ protected final String[] getHeaders() { return new String[]{ "设备类型", "设备编号", "设备型号", "设备出厂日期", "出厂编号", "报废年限", "使用单位", "工程起重机械生产单位", "工程起重机械租赁单位", "工程起重机械维保单位", "工程起重机械安拆单位", "工程起重机械设备备案登记证号", "设备备案登记日期", "备案机构", "设备备案登记有效期", "设备使用登记证号", "使用登记日期", "使用登记机构", "使用登记有效期截止日期", "初装高度", "最大安装高度", "最终安装高度", "验收日期", "安拆人员证件号" }; } @Override protected List buildRowData(Device data) { return List.of( data.getType().getDesc(), data.getName(), getProp(data, "设备型号"), getProp(data, "设备出厂日期"), data.getManufacturerNumber(), getProp(data, "报废年限"), getProp(data, "使用单位"), getProp(data, "工程起重机械生产单位"), getProp(data, "工程起重机械租赁单位"), getProp(data, "工程起重机械维保单位"), getProp(data, "工程起重机械安拆单位"), getProp(data, "工程起重机械设备备案登记证号"), getProp(data, "设备备案登记日期"), getProp(data, "备案机构"), getProp(data, "设备备案登记有效期"), getProp(data, "设备使用登记证号"), getProp(data, "使用登记日期"), getProp(data, "使用登记机构"), getProp(data, "使用登记有效期截止日期"), getProp(data, "初装高度"), getProp(data, "最大安装高度"), getProp(data, "最终安装高度"), getProp(data, "验收日期"), getProp(data, "安拆人员证件号") ); } @Override protected Device parseRowData(int rowIndex, List rowData) { var index = 0; var device = new Device(); // 初始化 properties Map device.setProperties(new HashMap<>()); device.setType(DeviceType.getByDescription(rowData.get(index++))); device.setName(ExcelParseUtils.parseString(rowData.get(index++))); // 移除重名检查,由 DeviceService.importEntities 统一处理(自动加数字) String model = ExcelParseUtils.parseString(rowData.get(index++)); if(model != null) { device.getProperties().put("设备型号", model); } String manufactureDate = ExcelParseUtils.parseString(rowData.get(index++)); if(manufactureDate != null) { device.getProperties().put("设备出厂日期", manufactureDate); } device.setManufacturerNumber(ExcelParseUtils.parseString(rowData.get(index++))); var headers = getHeaders(); for(int i = 6, n=headers.length; i