设备线体管理 - 批量导入和模板导出接口
{"@Data","@EqualsAndHashCode(callSuper = true)","@TableName("APS_PROCESS_CONFIG")","public class ApsProcessConfig extends BaseEntity {","\n"," private static final long serialVersionUID=1L;","\n"," /"," * "," */"," @TableId(value = "id", type=IdType.AUTO)"," private Long id;"," /"," * 设备编号"," */"," private Long deviceCode;"," /"," * wiotCode"," */"," private Long wiotCode;"," /"," * 设备名称"," */"," private String wiotDeviceName;"," /"," * mes设备编号"," */"," private String mesDeviceNo;"," /"," * aps系统内设备名称"," */"," private String apsDeviceName;"," /"," * 工序编号"," */"," private Integer processNo;"," /"," * 工序名称"," */"," private String processName;"," /"," * 工作中心"," */"," private String workStation;"," /"," * 月度产能"," */"," private String monthlyCapacity;"," /"," * 单位"," */"," private String unit;"," /"," * 是否删除"," */"," @TableLogic"," private Boolean isDeleted;"," /"," * 产线分组"," */"," private String processGroup;"," /"," * 公司编码"," */"," private String companyCode;","\n","}","\n","这个是设备线体的实体类,其中wiotCode是唯一的,其中同一个产线分组下设备名称是唯一的。新增一个设备线体批量导入的接口和一个模板导出的接口内容:可以参考以下代码实现设备线体批量导入和模板导出的接口:","\n","1. 设备线体批量导入接口:","\n","java","@PostMapping("/devices/import")","public Result importDevices(@RequestParam("file") MultipartFile file) {"," try {"," List<ApsProcessConfig> devices = ExcelUtil.importExcel(file.getInputStream(), ApsProcessConfig.class, ExcelUtil.EXCEL_TYPE_XLSX);","\n"," // 批量插入设备线体数据到数据库"," for (ApsProcessConfig device : devices) {"," // 根据wiotCode判断设备是否已存在,如果存在则更新,否则插入"," ApsProcessConfig existingDevice = deviceService.getByWiotCode(device.getWiotCode());"," if (existingDevice != null) {"," device.setId(existingDevice.getId());"," deviceService.updateById(device);"," } else {"," deviceService.save(device);"," } "," }","\n"," return Result.success("设备线体批量导入成功");"," } catch (IOException e) {"," e.printStackTrace();"," return Result.error("设备线体批量导入失败");"," }","}","","\n","2. 设备线体模板导出接口:","\n","java","@GetMapping("/devices/export/template")","public void exportDevicesTemplate(HttpServletResponse response) {"," try {"," List<ApsProcessConfig> devices = new ArrayList<>();"," devices.add(new ApsProcessConfig());"," ExcelUtil.exportExcel(response.getOutputStream(), devices, "设备线体模板", "设备线体模板", ExcelUtil.EXCEL_TYPE_XLSX);"," } catch (IOException e) {"," e.printStackTrace();"," }","}","","\n","其中,ExcelUtil 是一个工具类,用于导入和导出 Excel 文件。你可以根据具体的需求自行实现或使用第三方库,例如 Apache POI。
原文地址: https://www.cveoy.top/t/topic/pItM 著作权归作者所有。请勿转载和采集!