From f0b515c2e0fd1d0b7b2b4361123851b5dabe89a0 Mon Sep 17 00:00:00 2001 From: b2894lxlx <517289602@qq.com> Date: Mon, 27 Jul 2026 11:50:23 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=96=B0=E5=A2=9E=E8=B4=A7=E7=89=A9?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E6=A8=A1=E5=9D=97=202=E3=80=81=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=AF=BC=E5=85=A5=E5=A4=B1=E8=B4=A5=EF=BC=8C=E5=AF=BC?= =?UTF-8?q?=E5=87=BAexcel=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AGENTS.md | 11 +- blade-common/pom.xml | 4 + .../common/excel/ImportFailureExcelUtil.java | 132 ++++++ .../system/pojo/entity/CargoType.java | 93 +++++ .../system/pojo/vo/CargoTypeVO.java | 68 ++++ .../controller/AirportMasterController.java | 9 +- .../controller/CargoTypeController.java | 224 ++++++++++ .../system/controller/CurrencyController.java | 9 +- .../controller/PortTerminalController.java | 9 +- .../controller/RailwayStationController.java | 9 +- .../system/controller/RegionController.java | 10 +- .../system/excel/AirportMasterExcel.java | 2 +- .../system/excel/CargoTypeExcel.java | 72 ++++ .../system/excel/CargoTypeExportExcel.java | 78 ++++ .../excel/CargoTypeImportFailureExcel.java | 71 ++++ .../system/excel/CargoTypeImporter.java | 49 +++ .../system/excel/CurrencyExcel.java | 2 +- .../system/excel/PortTerminalExcel.java | 2 +- .../system/excel/RailwayStationExcel.java | 2 +- .../springblade/system/excel/RegionExcel.java | 4 + .../system/mapper/CargoTypeMapper.java | 52 +++ .../system/mapper/CargoTypeMapper.xml | 77 ++++ .../system/service/IAirportMasterService.java | 2 +- .../system/service/ICargoTypeService.java | 103 +++++ .../system/service/ICurrencyService.java | 2 +- .../system/service/IPortTerminalService.java | 2 +- .../service/IRailwayStationService.java | 2 +- .../system/service/IRegionService.java | 2 +- .../impl/AirportMasterServiceImpl.java | 11 +- .../service/impl/CargoTypeServiceImpl.java | 384 ++++++++++++++++++ .../service/impl/CurrencyServiceImpl.java | 11 +- .../service/impl/PortTerminalServiceImpl.java | 11 +- .../impl/RailwayStationServiceImpl.java | 11 +- .../service/impl/RegionServiceImpl.java | 29 +- .../system/wrapper/CargoTypeWrapper.java | 57 +++ .../controller/AccidentRecordController.java | 9 +- .../AnnualInspectionRecordController.java | 9 +- .../CreditScoreQuantificationController.java | 9 +- .../controller/EtcRecordController.java | 9 +- .../controller/InsuranceRecordController.java | 9 +- .../controller/MaintenancePlanController.java | 9 +- .../MaintenanceRecordController.java | 9 +- .../controller/MileageRecordController.java | 9 +- .../OilElectricRecordController.java | 9 +- .../OtherExpenseRecordController.java | 9 +- .../TireReplacementRecordController.java | 9 +- .../TransportChangeRecordController.java | 9 +- .../controller/ViolationRecordController.java | 9 +- .../transport/excel/AccidentRecordExcel.java | 2 +- .../excel/AnnualInspectionRecordExcel.java | 2 +- .../excel/CreditScoreQuantificationExcel.java | 3 +- .../transport/excel/EtcRecordExcel.java | 2 +- .../transport/excel/InsuranceRecordExcel.java | 2 +- .../transport/excel/MaintenancePlanExcel.java | 2 +- .../excel/MaintenanceRecordExcel.java | 2 +- .../transport/excel/MileageRecordExcel.java | 2 +- .../excel/OilElectricRecordExcel.java | 2 +- .../excel/OtherExpenseRecordExcel.java | 2 +- .../excel/TireReplacementRecordExcel.java | 2 +- .../excel/TransportChangeRecordExcel.java | 2 +- .../transport/excel/ViolationRecordExcel.java | 2 +- .../service/IAccidentRecordService.java | 2 +- .../IAnnualInspectionRecordService.java | 2 +- .../ICreditScoreQuantificationService.java | 3 +- .../transport/service/IEtcRecordService.java | 2 +- .../service/IInsuranceRecordService.java | 2 +- .../service/IMaintenancePlanService.java | 2 +- .../service/IMaintenanceRecordService.java | 2 +- .../service/IMileageRecordService.java | 2 +- .../service/IOilElectricRecordService.java | 2 +- .../service/IOtherExpenseRecordService.java | 2 +- .../ITireReplacementRecordService.java | 2 +- .../ITransportChangeRecordService.java | 2 +- .../service/IViolationRecordService.java | 2 +- .../impl/AccidentRecordServiceImpl.java | 14 +- .../AnnualInspectionRecordServiceImpl.java | 13 +- .../CreditScoreQuantificationServiceImpl.java | 14 +- .../service/impl/EtcRecordServiceImpl.java | 14 +- .../impl/InsuranceRecordServiceImpl.java | 14 +- .../impl/MaintenancePlanServiceImpl.java | 14 +- .../impl/MaintenanceRecordServiceImpl.java | 14 +- .../impl/MileageRecordServiceImpl.java | 14 +- .../impl/OilElectricRecordServiceImpl.java | 14 +- .../impl/OtherExpenseRecordServiceImpl.java | 14 +- .../TireReplacementRecordServiceImpl.java | 14 +- .../TransportChangeRecordServiceImpl.java | 14 +- .../impl/ViolationRecordServiceImpl.java | 13 +- doc/sql/transport/blade_cargo_type.sql | 39 ++ 88 files changed, 1791 insertions(+), 215 deletions(-) create mode 100644 blade-common/src/main/java/org/springblade/common/excel/ImportFailureExcelUtil.java create mode 100644 blade-service-api/blade-system-api/src/main/java/org/springblade/system/pojo/entity/CargoType.java create mode 100644 blade-service-api/blade-system-api/src/main/java/org/springblade/system/pojo/vo/CargoTypeVO.java create mode 100644 blade-service/blade-system/src/main/java/org/springblade/system/controller/CargoTypeController.java create mode 100644 blade-service/blade-system/src/main/java/org/springblade/system/excel/CargoTypeExcel.java create mode 100644 blade-service/blade-system/src/main/java/org/springblade/system/excel/CargoTypeExportExcel.java create mode 100644 blade-service/blade-system/src/main/java/org/springblade/system/excel/CargoTypeImportFailureExcel.java create mode 100644 blade-service/blade-system/src/main/java/org/springblade/system/excel/CargoTypeImporter.java create mode 100644 blade-service/blade-system/src/main/java/org/springblade/system/mapper/CargoTypeMapper.java create mode 100644 blade-service/blade-system/src/main/java/org/springblade/system/mapper/CargoTypeMapper.xml create mode 100644 blade-service/blade-system/src/main/java/org/springblade/system/service/ICargoTypeService.java create mode 100644 blade-service/blade-system/src/main/java/org/springblade/system/service/impl/CargoTypeServiceImpl.java create mode 100644 blade-service/blade-system/src/main/java/org/springblade/system/wrapper/CargoTypeWrapper.java create mode 100644 doc/sql/transport/blade_cargo_type.sql diff --git a/AGENTS.md b/AGENTS.md index 71ef371..118bba3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -211,7 +211,16 @@ Entity 基类的选择**直接决定** Service 和 ServiceImpl 的继承方式 - 导出经度、纬度字段时必须保留 6 位小数;导出前仍需遵守经度 `-180 ~ 180`、纬度 `-90 ~ 90` 的有效范围约束。 - 精度格式化应在导出 DTO/Excel 模型、导出组装逻辑或专用格式化工具中完成,禁止只依赖前端展示格式。 -### 6.11 日志 +### 6.11 导入失败明细导出 + +- 所有 Excel 批量导入功能如果存在部分数据无法导入、校验失败或处理异常,后端必须将导入失败的数据导出为 Excel 文件返回给前端下载。 +- 导入失败 Excel 的字段顺序必须与原导入模板保持一致,并在最后一列追加“导入失败原因”;失败原因应包含明确行号和可读错误信息。 +- 导入模板本身不得包含失败原因列;如复用导入模型,应使用 `@ExcelIgnore` 忽略内部错误字段,或单独定义 `XxxImportFailureExcel` 模型。 +- 导入逻辑应逐行处理:可成功导入的数据正常保存,失败行收集到失败明细;除非业务明确要求全量事务回滚,不得因部分失败回滚已成功行。 +- Controller 在失败明细非空时应直接通过 `ExcelUtil.export` 写入 `HttpServletResponse`,文件名统一包含业务名称、`导入失败明细` 和时间戳;全部成功时返回标准 `R.success`。 +- Service 层应返回失败明细列表或等效结构,禁止只抛出拼接后的错误字符串导致前端无法下载失败数据。 + +### 6.12 日志 - 使用 `@Slf4j`,占位符传参(禁止字符串拼接) - 包含关键业务标识,异常必须携带堆栈,禁止打印敏感信息 diff --git a/blade-common/pom.xml b/blade-common/pom.xml index 993b866..3ae15c5 100644 --- a/blade-common/pom.xml +++ b/blade-common/pom.xml @@ -22,6 +22,10 @@ org.springblade blade-starter-loadbalancer + + cn.idev.excel + fastexcel + org.springblade blade-core-auto diff --git a/blade-common/src/main/java/org/springblade/common/excel/ImportFailureExcelUtil.java b/blade-common/src/main/java/org/springblade/common/excel/ImportFailureExcelUtil.java new file mode 100644 index 0000000..db2c0e4 --- /dev/null +++ b/blade-common/src/main/java/org/springblade/common/excel/ImportFailureExcelUtil.java @@ -0,0 +1,132 @@ +/** + * BladeX Commercial License Agreement + * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved. + *

+ * Use of this software is governed by the Commercial License Agreement + * obtained after purchasing a license from BladeX. + *

+ * 1. This software is for development use only under a valid license + * from BladeX. + *

+ * 2. Redistribution of this software's source code to any third party + * without a commercial license is strictly prohibited. + *

+ * 3. Licensees may copyright their own code but cannot use segments + * from this software for such purposes. Copyright of this software + * remains with BladeX. + *

+ * Using this software signifies agreement to this License, and the software + * must not be used for illegal purposes. + *

+ * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is + * not liable for any claims arising from secondary or illegal development. + *

+ * Author: Chill Zhuang (bladejava@qq.com) + */ +package org.springblade.common.excel; + +import cn.idev.excel.FastExcel; +import cn.idev.excel.annotation.ExcelIgnore; +import cn.idev.excel.annotation.ExcelProperty; +import jakarta.servlet.http.HttpServletResponse; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + +/** + * 导入失败明细 Excel 导出工具类 + * + * @author Chill + */ +public class ImportFailureExcelUtil { + + private static final String FAILURE_REASON = "导入失败原因"; + private static final String ERROR_MESSAGE_FIELD = "errorMessage"; + + private ImportFailureExcelUtil() { + } + + /** + * 导出导入失败明细 + * + * @param response 响应 + * @param fileName 文件名 + * @param sheetName 工作表名 + * @param data 失败数据 + * @param excelClass 原导入 Excel 类型 + * @param 泛型 + */ + public static void export(HttpServletResponse response, String fileName, String sheetName, List data, Class excelClass) { + response.setContentType("application/vnd.ms-excel"); + response.setCharacterEncoding(StandardCharsets.UTF_8.name()); + String encodeFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8); + response.setHeader("Content-disposition", "attachment;filename=" + encodeFileName + ".xlsx"); + List excelFields = excelFields(excelClass); + List> head = buildHead(excelFields); + List> rows = buildRows(data, excelFields); + try { + FastExcel.write(response.getOutputStream()).head(head).sheet(sheetName).doWrite(rows); + } catch (IOException exception) { + throw new IllegalStateException("导出导入失败明细失败", exception); + } + } + + private static List excelFields(Class excelClass) { + return Arrays.stream(excelClass.getDeclaredFields()) + .filter(field -> field.getAnnotation(ExcelProperty.class) != null) + .filter(field -> field.getAnnotation(ExcelIgnore.class) == null) + .filter(field -> !Objects.equals(field.getName(), ERROR_MESSAGE_FIELD)) + .toList(); + } + + private static List> buildHead(List excelFields) { + List> head = new ArrayList<>(); + for (Field field : excelFields) { + ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class); + String[] value = excelProperty.value(); + head.add(List.of(value.length == 0 ? field.getName() : value[0])); + } + head.add(List.of(FAILURE_REASON)); + return head; + } + + private static List> buildRows(List data, List excelFields) { + List> rows = new ArrayList<>(); + for (T item : data) { + List row = new ArrayList<>(); + for (Field field : excelFields) { + row.add(fieldValue(item, field)); + } + row.add(errorMessage(item)); + rows.add(row); + } + return rows; + } + + private static Object fieldValue(Object item, Field field) { + try { + field.setAccessible(true); + return field.get(item); + } catch (IllegalAccessException exception) { + return null; + } + } + + private static Object errorMessage(Object item) { + try { + Field field = item.getClass().getDeclaredField(ERROR_MESSAGE_FIELD); + field.setAccessible(true); + Object value = field.get(item); + return value == null ? "" : String.valueOf(value); + } catch (NoSuchFieldException | IllegalAccessException exception) { + return ""; + } + } + +} diff --git a/blade-service-api/blade-system-api/src/main/java/org/springblade/system/pojo/entity/CargoType.java b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/pojo/entity/CargoType.java new file mode 100644 index 0000000..c6efd0a --- /dev/null +++ b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/pojo/entity/CargoType.java @@ -0,0 +1,93 @@ +/** + * BladeX Commercial License Agreement + * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved. + *

+ * Use of this software is governed by the Commercial License Agreement + * obtained after purchasing a license from BladeX. + *

+ * 1. This software is for development use only under a valid license + * from BladeX. + *

+ * 2. Redistribution of this software's source code to any third party + * without a commercial license is strictly prohibited. + *

+ * 3. Licensees may copyright their own code but cannot use segments + * from this software for such purposes. Copyright of this software + * remains with BladeX. + *

+ * Using this software signifies agreement to this License, and the software + * must not be used for illegal purposes. + *

+ * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is + * not liable for any claims arising from secondary or illegal development. + *

+ * Author: Chill Zhuang (bladejava@qq.com) + */ +package org.springblade.system.pojo.entity; + +import com.baomidou.mybatisplus.annotation.FieldStrategy; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.mp.base.BaseEntity; + +import java.io.Serial; + +/** + * 货物类型实体类 + * + * @author Chill + */ +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("blade_cargo_type") +@Schema(description = "货物类型") +public class CargoType extends BaseEntity { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * 类型级别:1一级货物类型,2二级货物类型 + */ + @Schema(description = "类型级别") + private Integer typeLevel; + /** + * 上级货物类型ID + */ + @JsonSerialize(using = ToStringSerializer.class) + @TableField(updateStrategy = FieldStrategy.ALWAYS) + @Schema(description = "上级货物类型ID") + private Long parentId; + /** + * 上级货物类型编码 + */ + @TableField(updateStrategy = FieldStrategy.ALWAYS) + @Schema(description = "上级货物类型编码") + private String parentCargoCode; + /** + * 货物类型 + */ + @Schema(description = "货物类型") + private String cargoName; + /** + * 货物类型编码 + */ + @Schema(description = "货物类型编码") + private String cargoCode; + /** + * 数据来源 + */ + @Schema(description = "数据来源") + private String dataSource; + /** + * 备注 + */ + @Schema(description = "备注") + private String remark; + +} diff --git a/blade-service-api/blade-system-api/src/main/java/org/springblade/system/pojo/vo/CargoTypeVO.java b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/pojo/vo/CargoTypeVO.java new file mode 100644 index 0000000..622a79b --- /dev/null +++ b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/pojo/vo/CargoTypeVO.java @@ -0,0 +1,68 @@ +/** + * BladeX Commercial License Agreement + * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved. + *

+ * Use of this software is governed by the Commercial License Agreement + * obtained after purchasing a license from BladeX. + *

+ * 1. This software is for development use only under a valid license + * from BladeX. + *

+ * 2. Redistribution of this software's source code to any third party + * without a commercial license is strictly prohibited. + *

+ * 3. Licensees may copyright their own code but cannot use segments + * from this software for such purposes. Copyright of this software + * remains with BladeX. + *

+ * Using this software signifies agreement to this License, and the software + * must not be used for illegal purposes. + *

+ * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is + * not liable for any claims arising from secondary or illegal development. + *

+ * Author: Chill Zhuang (bladejava@qq.com) + */ +package org.springblade.system.pojo.vo; + +import com.baomidou.mybatisplus.annotation.TableField; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.system.pojo.entity.CargoType; + +import java.io.Serial; + +/** + * 货物类型视图实体类 + * + * @author Chill + */ +@Data +@EqualsAndHashCode(callSuper = true) +@Schema(description = "货物类型") +public class CargoTypeVO extends CargoType { + @Serial + private static final long serialVersionUID = 1L; + + @TableField(exist = false) + @Schema(description = "类型名称") + private String typeLevelName; + + @TableField(exist = false) + @Schema(description = "上级货物类型") + private String parentCargoName; + + @TableField(exist = false) + @Schema(description = "创建人姓名") + private String createUserName; + + @TableField(exist = false) + @Schema(description = "更新人姓名") + private String updateUserName; + + @TableField(exist = false) + @Schema(description = "导入错误信息") + private String errorMessage; + +} diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/controller/AirportMasterController.java b/blade-service/blade-system/src/main/java/org/springblade/system/controller/AirportMasterController.java index dd5d721..caf288f 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/controller/AirportMasterController.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/controller/AirportMasterController.java @@ -148,7 +148,7 @@ public class AirportMasterController extends BladeController { @PostMapping("/import-airport-master") @ApiOperationSupport(order = 6) @Operation(summary = "导入空港机场主数据", description = "传入excel") - public R importAirportMaster(MultipartFile file) { + public R importAirportMaster(MultipartFile file, HttpServletResponse response) { if (file == null || file.isEmpty()) { return R.fail("上传文件不能为空"); } @@ -156,8 +156,11 @@ public class AirportMasterController extends BladeController { if (!fileName.endsWith(".xls") && !fileName.endsWith(".xlsx")) { return R.fail("请上传 .xls,.xlsx 标准格式文件"); } - AirportMasterImporter airportMasterImporter = new AirportMasterImporter(airportMasterService); - ExcelUtil.save(file, airportMasterImporter, AirportMasterExcel.class); + List failureList = airportMasterService.importAirportMaster(ExcelUtil.read(file, AirportMasterExcel.class)); + if (Func.isNotEmpty(failureList)) { + org.springblade.common.excel.ImportFailureExcelUtil.export(response, "空港机场主数据导入失败明细" + DateUtil.time(), "导入失败明细", failureList, AirportMasterExcel.class); + return null; + } return R.success("操作成功"); } diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/controller/CargoTypeController.java b/blade-service/blade-system/src/main/java/org/springblade/system/controller/CargoTypeController.java new file mode 100644 index 0000000..2266757 --- /dev/null +++ b/blade-service/blade-system/src/main/java/org/springblade/system/controller/CargoTypeController.java @@ -0,0 +1,224 @@ +/** + * BladeX Commercial License Agreement + * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved. + *

+ * Use of this software is governed by the Commercial License Agreement + * obtained after purchasing a license from BladeX. + *

+ * 1. This software is for development use only under a valid license + * from BladeX. + *

+ * 2. Redistribution of this software's source code to any third party + * without a commercial license is strictly prohibited. + *

+ * 3. Licensees may copyright their own code but cannot use segments + * from this software for such purposes. Copyright of this software + * remains with BladeX. + *

+ * Using this software signifies agreement to this License, and the software + * must not be used for illegal purposes. + *

+ * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is + * not liable for any claims arising from secondary or illegal development. + *

+ * Author: Chill Zhuang (bladejava@qq.com) + */ +package org.springblade.system.controller; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.validation.Valid; +import lombok.AllArgsConstructor; +import org.springblade.core.boot.ctrl.BladeController; +import org.springblade.core.excel.util.ExcelUtil; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.mp.support.Condition; +import org.springblade.core.mp.support.Query; +import org.springblade.core.secure.annotation.PreAuth; +import org.springblade.core.tenant.annotation.NonDS; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.DateUtil; +import org.springblade.core.tool.utils.Func; +import org.springblade.system.excel.CargoTypeExcel; +import org.springblade.system.excel.CargoTypeExportExcel; +import org.springblade.system.excel.CargoTypeImportFailureExcel; +import org.springblade.system.pojo.entity.CargoType; +import org.springblade.system.pojo.vo.CargoTypeVO; +import org.springblade.system.service.ICargoTypeService; +import org.springblade.system.wrapper.CargoTypeWrapper; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import java.util.ArrayList; +import java.util.List; + +/** + * 货物类型 控制器 + * + * @author Chill + */ +@NonDS +@RestController +@AllArgsConstructor +@PreAuth(menu = "cargo_type") +@RequestMapping("/cargo-type") +@Tag(name = "货物类型", description = "货物类型") +public class CargoTypeController extends BladeController { + + private final ICargoTypeService cargoTypeService; + + /** + * 详情 + */ + @GetMapping("/detail") + @ApiOperationSupport(order = 1) + @Operation(summary = "详情", description = "传入cargoType") + public R detail(CargoType cargoType) { + CargoType detail = cargoTypeService.getOne(Condition.getQueryWrapper(cargoType)); + if (detail == null) { + throw new ServiceException("数据不存在"); + } + CargoTypeVO cargoTypeVO = CargoTypeWrapper.build().entityVO(detail); + if (Func.isNotEmpty(detail.getParentId())) { + CargoType parent = cargoTypeService.getById(detail.getParentId()); + cargoTypeVO.setParentCargoName(parent == null ? "" : parent.getCargoName()); + } + return R.data(cargoTypeVO); + } + + /** + * 分页 + */ + @GetMapping("/list") + @ApiOperationSupport(order = 2) + @Operation(summary = "分页", description = "传入cargoType") + public R> list(CargoTypeVO cargoType, Query query) { + IPage pages = cargoTypeService.selectCargoTypePage(Condition.getPage(query), cargoType); + return R.data(pages); + } + + /** + * 一级货物类型选项 + */ + @GetMapping("/parent-options") + @ApiOperationSupport(order = 3) + @Operation(summary = "一级货物类型选项", description = "传入keyword") + public R> parentOptions(@RequestParam(required = false) String keyword) { + return R.data(cargoTypeService.parentOptions(keyword)); + } + + /** + * 二级货物类型建议编码 + */ + @GetMapping("/next-code") + @ApiOperationSupport(order = 4) + @Operation(summary = "二级货物类型建议编码", description = "传入parentCargoCode") + public R nextCode(@Parameter(description = "上级货物类型编码", required = true) @RequestParam String parentCargoCode) { + return R.data(cargoTypeService.nextChildCode(parentCargoCode)); + } + + /** + * 新增或修改 + */ + @PostMapping("/submit") + @ApiOperationSupport(order = 5) + @Operation(summary = "新增或修改", description = "传入cargoType") + public R submit(@Valid @RequestBody CargoType cargoType) { + return R.status(cargoTypeService.submit(cargoType)); + } + + /** + * 删除 + */ + @PostMapping("/remove") + @ApiOperationSupport(order = 6) + @Operation(summary = "逻辑删除", description = "传入ids") + public R remove(@Parameter(description = "主键集合", required = true) @RequestParam String ids) { + return R.status(cargoTypeService.deleteCargoTypes(Func.toLongList(ids))); + } + + /** + * 导入货物类型 + */ + @PostMapping("/import-cargo-type") + @ApiOperationSupport(order = 7) + @Operation(summary = "导入货物类型", description = "传入excel") + public R importCargoType(MultipartFile file, HttpServletResponse response) { + List data = ExcelUtil.read(file, CargoTypeExcel.class); + List failureList = cargoTypeService.importCargoType(data); + if (Func.isNotEmpty(failureList)) { + ExcelUtil.export(response, "货物类型导入失败明细" + DateUtil.time(), "导入失败明细", failureList, CargoTypeImportFailureExcel.class); + return null; + } + return R.success("导入数据成功"); + } + + /** + * 导出货物类型 + */ + @GetMapping("/export-cargo-type") + @ApiOperationSupport(order = 8) + @Operation(summary = "导出货物类型") + public void exportCargoType(CargoTypeVO cargoType, + @RequestParam(required = false) String ids, + HttpServletResponse response) { + List list = cargoTypeService.exportCargoType(buildExportQuery(cargoType, ids)); + ExcelUtil.export(response, "货物类型" + DateUtil.time(), "货物类型表", list, CargoTypeExportExcel.class); + } + + /** + * 导出模板 + */ + @GetMapping("/export-template") + @ApiOperationSupport(order = 9) + @Operation(summary = "导出模板") + public void exportTemplate(HttpServletResponse response) { + List list = new ArrayList<>(); + ExcelUtil.export(response, "货物类型模板", "货物类型导入模板", list, CargoTypeExcel.class); + } + + private LambdaQueryWrapper buildExportQuery(CargoTypeVO cargoType, String ids) { + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery() + .eq(CargoType::getIsDeleted, 0) + .orderByDesc(CargoType::getCreateTime); + if (Func.isNotEmpty(ids)) { + queryWrapper.in(CargoType::getId, Func.toLongList(ids)); + } + if (Func.isNotEmpty(cargoType.getTypeLevel())) { + queryWrapper.eq(CargoType::getTypeLevel, cargoType.getTypeLevel()); + } + if (Func.isNotEmpty(cargoType.getCargoName())) { + queryWrapper.like(CargoType::getCargoName, cargoType.getCargoName()); + } + if (Func.isNotEmpty(cargoType.getCargoCode())) { + queryWrapper.like(CargoType::getCargoCode, cargoType.getCargoCode()); + } + if (Func.isNotEmpty(cargoType.getParentCargoCode())) { + queryWrapper.like(CargoType::getParentCargoCode, cargoType.getParentCargoCode()); + } + if (Func.isNotEmpty(cargoType.getParentCargoName())) { + List parentCodes = cargoTypeService.parentOptions(cargoType.getParentCargoName()) + .stream() + .map(CargoTypeVO::getCargoCode) + .toList(); + if (Func.isEmpty(parentCodes)) { + queryWrapper.eq(CargoType::getParentCargoCode, "__none__"); + } else { + queryWrapper.in(CargoType::getParentCargoCode, parentCodes); + } + } + return queryWrapper; + } + +} diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/controller/CurrencyController.java b/blade-service/blade-system/src/main/java/org/springblade/system/controller/CurrencyController.java index d6ec0ef..4bc43d9 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/controller/CurrencyController.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/controller/CurrencyController.java @@ -148,9 +148,12 @@ public class CurrencyController extends BladeController { @PostMapping("/import-currency") @ApiOperationSupport(order = 7) @Operation(summary = "导入币种汇率", description = "传入excel") - public R importCurrency(MultipartFile file) { - CurrencyImporter currencyImporter = new CurrencyImporter(currencyService); - ExcelUtil.save(file, currencyImporter, CurrencyExcel.class); + public R importCurrency(MultipartFile file, HttpServletResponse response) { + List failureList = currencyService.importCurrency(ExcelUtil.read(file, CurrencyExcel.class)); + if (Func.isNotEmpty(failureList)) { + org.springblade.common.excel.ImportFailureExcelUtil.export(response, "币种汇率导入失败明细" + DateUtil.time(), "导入失败明细", failureList, CurrencyExcel.class); + return null; + } return R.success("操作成功"); } diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/controller/PortTerminalController.java b/blade-service/blade-system/src/main/java/org/springblade/system/controller/PortTerminalController.java index ae055fa..a34396b 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/controller/PortTerminalController.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/controller/PortTerminalController.java @@ -159,7 +159,7 @@ public class PortTerminalController extends BladeController { @PostMapping("/import-port-terminal") @ApiOperationSupport(order = 7) @Operation(summary = "导入港口码头主数据", description = "传入excel") - public R importPortTerminal(MultipartFile file) { + public R importPortTerminal(MultipartFile file, HttpServletResponse response) { if (file == null || file.isEmpty()) { return R.fail("上传文件不能为空"); } @@ -167,8 +167,11 @@ public class PortTerminalController extends BladeController { if (!fileName.endsWith(".xls") && !fileName.endsWith(".xlsx")) { return R.fail("请上传 .xls,.xlsx 标准格式文件"); } - PortTerminalImporter portTerminalImporter = new PortTerminalImporter(portTerminalService); - ExcelUtil.save(file, portTerminalImporter, PortTerminalExcel.class); + List failureList = portTerminalService.importPortTerminal(ExcelUtil.read(file, PortTerminalExcel.class)); + if (Func.isNotEmpty(failureList)) { + org.springblade.common.excel.ImportFailureExcelUtil.export(response, "港口码头主数据导入失败明细" + DateUtil.time(), "导入失败明细", failureList, PortTerminalExcel.class); + return null; + } return R.success("操作成功"); } diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/controller/RailwayStationController.java b/blade-service/blade-system/src/main/java/org/springblade/system/controller/RailwayStationController.java index f5d01f2..011df66 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/controller/RailwayStationController.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/controller/RailwayStationController.java @@ -151,7 +151,7 @@ public class RailwayStationController extends BladeController { @PostMapping("/import-railway-station") @ApiOperationSupport(order = 6) @Operation(summary = "导入铁路车站主数据", description = "传入excel") - public R importRailwayStation(MultipartFile file) { + public R importRailwayStation(MultipartFile file, HttpServletResponse response) { if (file == null || file.isEmpty()) { return R.fail("上传文件不能为空"); } @@ -159,8 +159,11 @@ public class RailwayStationController extends BladeController { if (!fileName.endsWith(".xls") && !fileName.endsWith(".xlsx")) { return R.fail("请上传 .xls,.xlsx 标准格式文件"); } - RailwayStationImporter railwayStationImporter = new RailwayStationImporter(railwayStationService); - ExcelUtil.save(file, railwayStationImporter, RailwayStationExcel.class); + List failureList = railwayStationService.importRailwayStation(ExcelUtil.read(file, RailwayStationExcel.class)); + if (Func.isNotEmpty(failureList)) { + org.springblade.common.excel.ImportFailureExcelUtil.export(response, "铁路车站主数据导入失败明细" + DateUtil.time(), "导入失败明细", failureList, RailwayStationExcel.class); + return null; + } return R.success("操作成功"); } diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/controller/RegionController.java b/blade-service/blade-system/src/main/java/org/springblade/system/controller/RegionController.java index d366c36..2ff8c72 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/controller/RegionController.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/controller/RegionController.java @@ -58,6 +58,7 @@ import org.springframework.web.multipart.MultipartFile; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Objects; /** * 行政区划表 控制器 @@ -188,9 +189,12 @@ public class RegionController extends BladeController { @PostMapping("import-region") @ApiOperationSupport(order = 10) @Operation(summary = "导入行政区划", description = "传入excel") - public R importRegion(MultipartFile file, Integer isCovered) { - RegionImporter regionImporter = new RegionImporter(regionService, isCovered == 1); - ExcelUtil.save(file, regionImporter, RegionExcel.class); + public R importRegion(MultipartFile file, Integer isCovered, HttpServletResponse response) { + List failureList = regionService.importRegion(ExcelUtil.read(file, RegionExcel.class), Objects.equals(isCovered, 1)); + if (!failureList.isEmpty()) { + org.springblade.common.excel.ImportFailureExcelUtil.export(response, "行政区划导入失败明细" + DateUtil.time(), "导入失败明细", failureList, RegionExcel.class); + return null; + } return R.success("操作成功"); } diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/excel/AirportMasterExcel.java b/blade-service/blade-system/src/main/java/org/springblade/system/excel/AirportMasterExcel.java index 8152b25..a2e023a 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/excel/AirportMasterExcel.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/excel/AirportMasterExcel.java @@ -100,7 +100,7 @@ public class AirportMasterExcel implements Serializable { @ExcelProperty("备注") private String remark; - @ExcelProperty("报错文案") + @ExcelProperty private String errorMessage; } diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/excel/CargoTypeExcel.java b/blade-service/blade-system/src/main/java/org/springblade/system/excel/CargoTypeExcel.java new file mode 100644 index 0000000..ffdf008 --- /dev/null +++ b/blade-service/blade-system/src/main/java/org/springblade/system/excel/CargoTypeExcel.java @@ -0,0 +1,72 @@ +/** + * BladeX Commercial License Agreement + * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved. + *

+ * Use of this software is governed by the Commercial License Agreement + * obtained after purchasing a license from BladeX. + *

+ * 1. This software is for development use only under a valid license + * from BladeX. + *

+ * 2. Redistribution of this software's source code to any third party + * without a commercial license is strictly prohibited. + *

+ * 3. Licensees may copyright their own code but cannot use segments + * from this software for such purposes. Copyright of this software + * remains with BladeX. + *

+ * Using this software signifies agreement to this License, and the software + * must not be used for illegal purposes. + *

+ * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is + * not liable for any claims arising from secondary or illegal development. + *

+ * Author: Chill Zhuang (bladejava@qq.com) + */ +package org.springblade.system.excel; + +import cn.idev.excel.annotation.ExcelIgnore; +import cn.idev.excel.annotation.ExcelProperty; +import cn.idev.excel.annotation.write.style.ColumnWidth; +import cn.idev.excel.annotation.write.style.ContentRowHeight; +import cn.idev.excel.annotation.write.style.HeadRowHeight; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +/** + * 货物类型导入 Excel + * + * @author Chill + */ +@Data +@ColumnWidth(24) +@HeadRowHeight(20) +@ContentRowHeight(18) +public class CargoTypeExcel implements Serializable { + @Serial + private static final long serialVersionUID = 1L; + + @ExcelProperty("*类型") + private String typeLevelName; + + @ExcelProperty("*上级货物类型") + private String parentCargoName; + + @ExcelProperty("*上级货物类型编码") + private String parentCargoCode; + + @ExcelProperty("*货物类型") + private String cargoName; + + @ExcelProperty("*货物类型编码") + private String cargoCode; + + @ExcelProperty("备注") + private String remark; + + @ExcelIgnore + private String errorMessage; + +} diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/excel/CargoTypeExportExcel.java b/blade-service/blade-system/src/main/java/org/springblade/system/excel/CargoTypeExportExcel.java new file mode 100644 index 0000000..8b4f0eb --- /dev/null +++ b/blade-service/blade-system/src/main/java/org/springblade/system/excel/CargoTypeExportExcel.java @@ -0,0 +1,78 @@ +/** + * BladeX Commercial License Agreement + * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved. + *

+ * Use of this software is governed by the Commercial License Agreement + * obtained after purchasing a license from BladeX. + *

+ * 1. This software is for development use only under a valid license + * from BladeX. + *

+ * 2. Redistribution of this software's source code to any third party + * without a commercial license is strictly prohibited. + *

+ * 3. Licensees may copyright their own code but cannot use segments + * from this software for such purposes. Copyright of this software + * remains with BladeX. + *

+ * Using this software signifies agreement to this License, and the software + * must not be used for illegal purposes. + *

+ * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is + * not liable for any claims arising from secondary or illegal development. + *

+ * Author: Chill Zhuang (bladejava@qq.com) + */ +package org.springblade.system.excel; + +import cn.idev.excel.annotation.ExcelProperty; +import cn.idev.excel.annotation.write.style.ColumnWidth; +import cn.idev.excel.annotation.write.style.ContentRowHeight; +import cn.idev.excel.annotation.write.style.HeadRowHeight; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; +import java.util.Date; + +/** + * 货物类型导出 Excel + * + * @author Chill + */ +@Data +@ColumnWidth(22) +@HeadRowHeight(20) +@ContentRowHeight(18) +public class CargoTypeExportExcel implements Serializable { + @Serial + private static final long serialVersionUID = 1L; + + @ExcelProperty("类型") + private String typeLevelName; + + @ExcelProperty("货物类型") + private String cargoName; + + @ExcelProperty("货物类型编码") + private String cargoCode; + + @ExcelProperty("上级货物类型") + private String parentCargoName; + + @ExcelProperty("上级货物类型编码") + private String parentCargoCode; + + @ExcelProperty("创建人") + private String createUserName; + + @ExcelProperty("备注") + private String remark; + + @ExcelProperty("更新时间") + private Date updateTime; + + @ExcelProperty("创建时间") + private Date createTime; + +} diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/excel/CargoTypeImportFailureExcel.java b/blade-service/blade-system/src/main/java/org/springblade/system/excel/CargoTypeImportFailureExcel.java new file mode 100644 index 0000000..9e34298 --- /dev/null +++ b/blade-service/blade-system/src/main/java/org/springblade/system/excel/CargoTypeImportFailureExcel.java @@ -0,0 +1,71 @@ +/** + * BladeX Commercial License Agreement + * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved. + *

+ * Use of this software is governed by the Commercial License Agreement + * obtained after purchasing a license from BladeX. + *

+ * 1. This software is for development use only under a valid license + * from BladeX. + *

+ * 2. Redistribution of this software's source code to any third party + * without a commercial license is strictly prohibited. + *

+ * 3. Licensees may copyright their own code but cannot use segments + * from this software for such purposes. Copyright of this software + * remains with BladeX. + *

+ * Using this software signifies agreement to this License, and the software + * must not be used for illegal purposes. + *

+ * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is + * not liable for any claims arising from secondary or illegal development. + *

+ * Author: Chill Zhuang (bladejava@qq.com) + */ +package org.springblade.system.excel; + +import cn.idev.excel.annotation.ExcelProperty; +import cn.idev.excel.annotation.write.style.ColumnWidth; +import cn.idev.excel.annotation.write.style.ContentRowHeight; +import cn.idev.excel.annotation.write.style.HeadRowHeight; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +/** + * 货物类型导入失败 Excel + * + * @author Chill + */ +@Data +@ColumnWidth(24) +@HeadRowHeight(20) +@ContentRowHeight(18) +public class CargoTypeImportFailureExcel implements Serializable { + @Serial + private static final long serialVersionUID = 1L; + + @ExcelProperty("*类型") + private String typeLevelName; + + @ExcelProperty("*上级货物类型") + private String parentCargoName; + + @ExcelProperty("*上级货物类型编码") + private String parentCargoCode; + + @ExcelProperty("*货物类型") + private String cargoName; + + @ExcelProperty("*货物类型编码") + private String cargoCode; + + @ExcelProperty("备注") + private String remark; + + @ExcelProperty("导入失败原因") + private String failureReason; + +} diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/excel/CargoTypeImporter.java b/blade-service/blade-system/src/main/java/org/springblade/system/excel/CargoTypeImporter.java new file mode 100644 index 0000000..71719c4 --- /dev/null +++ b/blade-service/blade-system/src/main/java/org/springblade/system/excel/CargoTypeImporter.java @@ -0,0 +1,49 @@ +/** + * BladeX Commercial License Agreement + * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved. + *

+ * Use of this software is governed by the Commercial License Agreement + * obtained after purchasing a license from BladeX. + *

+ * 1. This software is for development use only under a valid license + * from BladeX. + *

+ * 2. Redistribution of this software's source code to any third party + * without a commercial license is strictly prohibited. + *

+ * 3. Licensees may copyright their own code but cannot use segments + * from this software for such purposes. Copyright of this software + * remains with BladeX. + *

+ * Using this software signifies agreement to this License, and the software + * must not be used for illegal purposes. + *

+ * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is + * not liable for any claims arising from secondary or illegal development. + *

+ * Author: Chill Zhuang (bladejava@qq.com) + */ +package org.springblade.system.excel; + +import lombok.RequiredArgsConstructor; +import org.springblade.core.excel.support.ExcelImporter; +import org.springblade.system.service.ICargoTypeService; + +import java.util.List; + +/** + * 货物类型导入类 + * + * @author Chill + */ +@RequiredArgsConstructor +public class CargoTypeImporter implements ExcelImporter { + + private final ICargoTypeService service; + + @Override + public void save(List data) { + service.importCargoType(data); + } + +} diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/excel/CurrencyExcel.java b/blade-service/blade-system/src/main/java/org/springblade/system/excel/CurrencyExcel.java index 89e6bf0..941b7eb 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/excel/CurrencyExcel.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/excel/CurrencyExcel.java @@ -77,7 +77,7 @@ public class CurrencyExcel implements Serializable { @ExcelProperty("备注") private String remark; - @ExcelProperty("报错文案") + @ExcelProperty private String errorMessage; } diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/excel/PortTerminalExcel.java b/blade-service/blade-system/src/main/java/org/springblade/system/excel/PortTerminalExcel.java index 1f8f2de..6e394a2 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/excel/PortTerminalExcel.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/excel/PortTerminalExcel.java @@ -100,7 +100,7 @@ public class PortTerminalExcel implements Serializable { @ExcelProperty("备注") private String remark; - @ExcelProperty("报错文案") + @ExcelProperty private String errorMessage; } diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/excel/RailwayStationExcel.java b/blade-service/blade-system/src/main/java/org/springblade/system/excel/RailwayStationExcel.java index 0c38d75..b91a170 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/excel/RailwayStationExcel.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/excel/RailwayStationExcel.java @@ -96,7 +96,7 @@ public class RailwayStationExcel implements Serializable { @ExcelProperty("备注") private String remark; - @ExcelProperty("报错文案") + @ExcelProperty private String errorMessage; } diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/excel/RegionExcel.java b/blade-service/blade-system/src/main/java/org/springblade/system/excel/RegionExcel.java index bd73c2c..65e0a22 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/excel/RegionExcel.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/excel/RegionExcel.java @@ -25,6 +25,7 @@ */ package org.springblade.system.excel; +import cn.idev.excel.annotation.ExcelIgnore; import cn.idev.excel.annotation.ExcelProperty; import cn.idev.excel.annotation.write.style.ColumnWidth; import cn.idev.excel.annotation.write.style.ContentRowHeight; @@ -98,4 +99,7 @@ public class RegionExcel implements Serializable { @ExcelProperty("备注") private String remark; + @ExcelIgnore + private String errorMessage; + } diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/mapper/CargoTypeMapper.java b/blade-service/blade-system/src/main/java/org/springblade/system/mapper/CargoTypeMapper.java new file mode 100644 index 0000000..84d3098 --- /dev/null +++ b/blade-service/blade-system/src/main/java/org/springblade/system/mapper/CargoTypeMapper.java @@ -0,0 +1,52 @@ +/** + * BladeX Commercial License Agreement + * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved. + *

+ * Use of this software is governed by the Commercial License Agreement + * obtained after purchasing a license from BladeX. + *

+ * 1. This software is for development use only under a valid license + * from BladeX. + *

+ * 2. Redistribution of this software's source code to any third party + * without a commercial license is strictly prohibited. + *

+ * 3. Licensees may copyright their own code but cannot use segments + * from this software for such purposes. Copyright of this software + * remains with BladeX. + *

+ * Using this software signifies agreement to this License, and the software + * must not be used for illegal purposes. + *

+ * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is + * not liable for any claims arising from secondary or illegal development. + *

+ * Author: Chill Zhuang (bladejava@qq.com) + */ +package org.springblade.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import org.apache.ibatis.annotations.Param; +import org.springblade.system.pojo.entity.CargoType; +import org.springblade.system.pojo.vo.CargoTypeVO; + +import java.util.List; + +/** + * 货物类型 Mapper 接口 + * + * @author Chill + */ +public interface CargoTypeMapper extends BaseMapper { + + /** + * 自定义分页 + * + * @param page 分页参数 + * @param cargoType 查询参数 + * @return 货物类型分页 + */ + List selectCargoTypePage(IPage page, @Param("cargoType") CargoTypeVO cargoType); + +} diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/mapper/CargoTypeMapper.xml b/blade-service/blade-system/src/main/java/org/springblade/system/mapper/CargoTypeMapper.xml new file mode 100644 index 0000000..3a6a1a4 --- /dev/null +++ b/blade-service/blade-system/src/main/java/org/springblade/system/mapper/CargoTypeMapper.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/service/IAirportMasterService.java b/blade-service/blade-system/src/main/java/org/springblade/system/service/IAirportMasterService.java index c3b2911..ee4bc29 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/service/IAirportMasterService.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/service/IAirportMasterService.java @@ -72,7 +72,7 @@ public interface IAirportMasterService extends BaseService { * * @param data 导入数据 */ - void importAirportMaster(List data); + List importAirportMaster(List data); /** * 导出空港机场 diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/service/ICargoTypeService.java b/blade-service/blade-system/src/main/java/org/springblade/system/service/ICargoTypeService.java new file mode 100644 index 0000000..d04ad7e --- /dev/null +++ b/blade-service/blade-system/src/main/java/org/springblade/system/service/ICargoTypeService.java @@ -0,0 +1,103 @@ +/** + * BladeX Commercial License Agreement + * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved. + *

+ * Use of this software is governed by the Commercial License Agreement + * obtained after purchasing a license from BladeX. + *

+ * 1. This software is for development use only under a valid license + * from BladeX. + *

+ * 2. Redistribution of this software's source code to any third party + * without a commercial license is strictly prohibited. + *

+ * 3. Licensees may copyright their own code but cannot use segments + * from this software for such purposes. Copyright of this software + * remains with BladeX. + *

+ * Using this software signifies agreement to this License, and the software + * must not be used for illegal purposes. + *

+ * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is + * not liable for any claims arising from secondary or illegal development. + *

+ * Author: Chill Zhuang (bladejava@qq.com) + */ +package org.springblade.system.service; + +import com.baomidou.mybatisplus.core.conditions.Wrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import org.springblade.core.mp.base.BaseService; +import org.springblade.system.excel.CargoTypeExcel; +import org.springblade.system.excel.CargoTypeExportExcel; +import org.springblade.system.excel.CargoTypeImportFailureExcel; +import org.springblade.system.pojo.entity.CargoType; +import org.springblade.system.pojo.vo.CargoTypeVO; + +import java.util.List; + +/** + * 货物类型 服务类 + * + * @author Chill + */ +public interface ICargoTypeService extends BaseService { + + /** + * 自定义分页 + * + * @param page 分页参数 + * @param cargoType 查询参数 + * @return 货物类型分页 + */ + IPage selectCargoTypePage(IPage page, CargoTypeVO cargoType); + + /** + * 新增或修改货物类型 + * + * @param cargoType 货物类型 + * @return 是否成功 + */ + boolean submit(CargoType cargoType); + + /** + * 删除货物类型 + * + * @param ids 主键集合 + * @return 是否成功 + */ + boolean deleteCargoTypes(List ids); + + /** + * 一级货物类型选项 + * + * @param keyword 关键字 + * @return 一级货物类型列表 + */ + List parentOptions(String keyword); + + /** + * 获取二级货物类型建议编码 + * + * @param parentCargoCode 上级货物类型编码 + * @return 建议编码 + */ + String nextChildCode(String parentCargoCode); + + /** + * 导入货物类型 + * + * @param data 导入数据 + * @return 导入失败数据 + */ + List importCargoType(List data); + + /** + * 导出货物类型 + * + * @param queryWrapper 查询条件 + * @return 导出数据 + */ + List exportCargoType(Wrapper queryWrapper); + +} diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/service/ICurrencyService.java b/blade-service/blade-system/src/main/java/org/springblade/system/service/ICurrencyService.java index 1908734..6452c62 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/service/ICurrencyService.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/service/ICurrencyService.java @@ -73,7 +73,7 @@ public interface ICurrencyService extends BaseService { * * @param data 导入数据 */ - void importCurrency(List data); + List importCurrency(List data); /** * 导出币种汇率 diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/service/IPortTerminalService.java b/blade-service/blade-system/src/main/java/org/springblade/system/service/IPortTerminalService.java index 3bfcac8..ffbfb20 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/service/IPortTerminalService.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/service/IPortTerminalService.java @@ -79,7 +79,7 @@ public interface IPortTerminalService extends BaseService { * * @param data 导入数据 */ - void importPortTerminal(List data); + List importPortTerminal(List data); /** * 导出港口码头 diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/service/IRailwayStationService.java b/blade-service/blade-system/src/main/java/org/springblade/system/service/IRailwayStationService.java index 6171446..03133ad 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/service/IRailwayStationService.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/service/IRailwayStationService.java @@ -72,7 +72,7 @@ public interface IRailwayStationService extends BaseService { * * @param data 导入数据 */ - void importRailwayStation(List data); + List importRailwayStation(List data); /** * 导出铁路车站 diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/service/IRegionService.java b/blade-service/blade-system/src/main/java/org/springblade/system/service/IRegionService.java index ffe3a3a..339bc16 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/service/IRegionService.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/service/IRegionService.java @@ -82,7 +82,7 @@ public interface IRegionService extends IService { * @param isCovered * @return */ - void importRegion(List data, Boolean isCovered); + List importRegion(List data, Boolean isCovered); /** * 导出区划数据 diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/AirportMasterServiceImpl.java b/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/AirportMasterServiceImpl.java index 214db59..53dc0a5 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/AirportMasterServiceImpl.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/AirportMasterServiceImpl.java @@ -119,11 +119,11 @@ public class AirportMasterServiceImpl extends BaseServiceImpl data) { + public List importAirportMaster(List data) { if (Func.isEmpty(data)) { throw new ServiceException("导入数据不能为空"); } - List errorList = new ArrayList<>(); + List errorList = new ArrayList<>(); for (int index = 0; index < data.size(); index++) { AirportMasterExcel excel = data.get(index); try { @@ -135,12 +135,11 @@ public class AirportMasterServiceImpl extends BaseServiceImpl + * Use of this software is governed by the Commercial License Agreement + * obtained after purchasing a license from BladeX. + *

+ * 1. This software is for development use only under a valid license + * from BladeX. + *

+ * 2. Redistribution of this software's source code to any third party + * without a commercial license is strictly prohibited. + *

+ * 3. Licensees may copyright their own code but cannot use segments + * from this software for such purposes. Copyright of this software + * remains with BladeX. + *

+ * Using this software signifies agreement to this License, and the software + * must not be used for illegal purposes. + *

+ * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is + * not liable for any claims arising from secondary or illegal development. + *

+ * Author: Chill Zhuang (bladejava@qq.com) + */ +package org.springblade.system.service.impl; + +import com.baomidou.mybatisplus.core.conditions.Wrapper; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.tool.utils.Func; +import org.springblade.system.cache.UserCache; +import org.springblade.system.excel.CargoTypeExcel; +import org.springblade.system.excel.CargoTypeExportExcel; +import org.springblade.system.excel.CargoTypeImportFailureExcel; +import org.springblade.system.mapper.CargoTypeMapper; +import org.springblade.system.pojo.entity.CargoType; +import org.springblade.system.pojo.vo.CargoTypeVO; +import org.springblade.system.service.ICargoTypeService; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.regex.Pattern; + +/** + * 货物类型 服务实现类 + * + * @author Chill + */ +@Service +public class CargoTypeServiceImpl extends BaseServiceImpl implements ICargoTypeService { + + private static final int TYPE_LEVEL_ONE = 1; + private static final int TYPE_LEVEL_TWO = 2; + private static final int STATUS_ENABLED = 1; + private static final int CARGO_NAME_MAX_LENGTH = 50; + private static final int REMARK_MAX_LENGTH = 200; + private static final String SOURCE_BATCH = "批量导入"; + private static final String SOURCE_MANUAL = "手工录入"; + private static final Pattern PARENT_CODE_PATTERN = Pattern.compile("^\\d{2}$"); + private static final Pattern CHILD_CODE_PATTERN = Pattern.compile("^\\d{4}$"); + + @Override + public IPage selectCargoTypePage(IPage page, CargoTypeVO cargoType) { + return page.setRecords(baseMapper.selectCargoTypePage(page, cargoType)); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean submit(CargoType cargoType) { + prepare(cargoType, SOURCE_MANUAL); + validate(cargoType); + return saveOrUpdate(cargoType); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean deleteCargoTypes(List ids) { + if (Func.isEmpty(ids)) { + throw new ServiceException("请选择至少一条数据"); + } + long childCount = count(Wrappers.lambdaQuery() + .in(CargoType::getParentId, ids) + .eq(CargoType::getIsDeleted, 0)); + if (childCount > 0L) { + throw new ServiceException("存在下级货物类型,不能删除"); + } + return deleteLogic(ids); + } + + @Override + public List parentOptions(String keyword) { + String trimKeyword = trimToEmpty(keyword); + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery() + .eq(CargoType::getTypeLevel, TYPE_LEVEL_ONE) + .eq(CargoType::getIsDeleted, 0) + .orderByAsc(CargoType::getCargoCode); + if (Func.isNotEmpty(trimKeyword)) { + queryWrapper.and(wrapper -> wrapper.like(CargoType::getCargoName, trimKeyword) + .or() + .like(CargoType::getCargoCode, trimKeyword)); + } + return list(queryWrapper).stream().map(this::toParentOption).toList(); + } + + @Override + public String nextChildCode(String parentCargoCode) { + CargoType parent = findParentByCode(trimToEmpty(parentCargoCode)); + if (parent == null) { + throw new ServiceException("请选择上级货物类型"); + } + String parentCode = parent.getCargoCode(); + String maxCode = list(Wrappers.lambdaQuery() + .eq(CargoType::getTypeLevel, TYPE_LEVEL_TWO) + .eq(CargoType::getParentCargoCode, parentCode) + .eq(CargoType::getIsDeleted, 0) + .orderByDesc(CargoType::getCargoCode)) + .stream() + .map(CargoType::getCargoCode) + .filter(code -> code != null && CHILD_CODE_PATTERN.matcher(code).matches()) + .findFirst() + .orElse(null); + int nextSerial = maxCode == null ? 1 : Integer.parseInt(maxCode.substring(2)) + 1; + if (nextSerial > 99) { + throw new ServiceException("二级编码序号已超过99"); + } + return parentCode + String.format("%02d", nextSerial); + } + + @Override + public List importCargoType(List data) { + if (Func.isEmpty(data)) { + throw new ServiceException("导入数据不能为空"); + } + List failureList = new ArrayList<>(); + for (int index = 0; index < data.size(); index++) { + CargoTypeExcel excel = data.get(index); + try { + CargoType cargoType = buildImportCargoType(excel); + prepare(cargoType, SOURCE_BATCH); + validate(cargoType); + save(cargoType); + } catch (Exception exception) { + String message = exception instanceof ServiceException ? exception.getMessage() : "导入失败"; + excel.setErrorMessage(message); + failureList.add(toImportFailureExcel(excel, "第" + (index + 2) + "行:" + message)); + } + } + return failureList; + } + + @Override + public List exportCargoType(Wrapper queryWrapper) { + return list(queryWrapper).stream().map(this::toExportExcel).toList(); + } + + private CargoType buildImportCargoType(CargoTypeExcel excel) { + CargoType cargoType = new CargoType(); + cargoType.setTypeLevel(parseTypeLevel(excel.getTypeLevelName())); + cargoType.setParentCargoCode(trimToNull(excel.getParentCargoCode())); + cargoType.setCargoName(trimToEmpty(excel.getCargoName())); + cargoType.setCargoCode(trimToEmpty(excel.getCargoCode())); + cargoType.setRemark(trimToNull(excel.getRemark())); + if (Objects.equals(cargoType.getTypeLevel(), TYPE_LEVEL_TWO)) { + CargoType parent = resolveImportParent(excel); + cargoType.setParentId(parent.getId()); + cargoType.setParentCargoCode(parent.getCargoCode()); + } + return cargoType; + } + + private Integer parseTypeLevel(String typeLevelName) { + String value = trimToEmpty(typeLevelName); + if ("一级货物类型".equals(value)) { + return TYPE_LEVEL_ONE; + } + if ("二级货物类型".equals(value)) { + return TYPE_LEVEL_TWO; + } + throw new ServiceException("请选择货物类型级别"); + } + + private CargoType resolveImportParent(CargoTypeExcel excel) { + String parentCode = trimToEmpty(excel.getParentCargoCode()); + String parentName = trimToEmpty(excel.getParentCargoName()); + if (Func.isEmpty(parentCode) && Func.isEmpty(parentName)) { + throw new ServiceException("请选择上级货物类型"); + } + CargoType parent = Func.isNotEmpty(parentCode) ? findParentByCode(parentCode) : findParentByName(parentName); + if (parent == null) { + throw new ServiceException("请选择上级货物类型"); + } + if (Func.isNotEmpty(parentName) && !Objects.equals(parent.getCargoName(), parentName)) { + throw new ServiceException("请选择上级货物类型"); + } + return parent; + } + + private void prepare(CargoType cargoType, String defaultDataSource) { + cargoType.setCargoName(trimToEmpty(cargoType.getCargoName())); + cargoType.setCargoCode(trimToEmpty(cargoType.getCargoCode())); + cargoType.setParentCargoCode(trimToNull(cargoType.getParentCargoCode())); + cargoType.setDataSource(Func.toStrWithEmpty(cargoType.getDataSource(), defaultDataSource)); + cargoType.setRemark(trimToNull(cargoType.getRemark())); + if (Objects.equals(cargoType.getTypeLevel(), TYPE_LEVEL_ONE)) { + cargoType.setParentId(null); + cargoType.setParentCargoCode(null); + } + if (Func.isEmpty(cargoType.getStatus())) { + cargoType.setStatus(STATUS_ENABLED); + } + } + + private void validate(CargoType cargoType) { + if (!Objects.equals(cargoType.getTypeLevel(), TYPE_LEVEL_ONE) && !Objects.equals(cargoType.getTypeLevel(), TYPE_LEVEL_TWO)) { + throw new ServiceException("请选择货物类型级别"); + } + if (Func.isEmpty(cargoType.getCargoName())) { + throw new ServiceException("请输入货物类型名称"); + } + if (cargoType.getCargoName().length() > CARGO_NAME_MAX_LENGTH) { + throw new ServiceException("货物类型名称不能超过50字符"); + } + if (Func.isEmpty(cargoType.getCargoCode())) { + throw new ServiceException("货物类型编码格式不正确"); + } + if (Objects.equals(cargoType.getTypeLevel(), TYPE_LEVEL_ONE)) { + validateParentCargoType(cargoType); + } else { + validateChildCargoType(cargoType); + } + if (Func.isNotEmpty(cargoType.getRemark()) && cargoType.getRemark().length() > REMARK_MAX_LENGTH) { + throw new ServiceException("备注不能超过200字"); + } + validateUniqueCode(cargoType); + validateUniqueName(cargoType); + } + + private void validateParentCargoType(CargoType cargoType) { + if (!PARENT_CODE_PATTERN.matcher(cargoType.getCargoCode()).matches()) { + throw new ServiceException("货物类型编码格式不正确"); + } + } + + private void validateChildCargoType(CargoType cargoType) { + CargoType parent = resolveParent(cargoType); + if (parent == null) { + throw new ServiceException("请选择上级货物类型"); + } + if (!CHILD_CODE_PATTERN.matcher(cargoType.getCargoCode()).matches()) { + throw new ServiceException("货物类型编码格式不正确"); + } + if (!cargoType.getCargoCode().startsWith(parent.getCargoCode())) { + throw new ServiceException("二级编码前2位必须与上级货物类型编码一致"); + } + if (Objects.equals(cargoType.getId(), parent.getId())) { + throw new ServiceException("请选择上级货物类型"); + } + cargoType.setParentId(parent.getId()); + cargoType.setParentCargoCode(parent.getCargoCode()); + } + + private CargoType resolveParent(CargoType cargoType) { + if (Func.isNotEmpty(cargoType.getParentId())) { + CargoType parent = getById(cargoType.getParentId()); + if (parent != null && Objects.equals(parent.getTypeLevel(), TYPE_LEVEL_ONE) && Objects.equals(parent.getIsDeleted(), 0)) { + return parent; + } + } + if (Func.isNotEmpty(cargoType.getParentCargoCode())) { + return findParentByCode(cargoType.getParentCargoCode()); + } + return null; + } + + private CargoType findParentByCode(String cargoCode) { + String code = trimToEmpty(cargoCode); + if (Func.isEmpty(code)) { + return null; + } + return getOne(Wrappers.lambdaQuery() + .eq(CargoType::getTypeLevel, TYPE_LEVEL_ONE) + .eq(CargoType::getCargoCode, code) + .eq(CargoType::getIsDeleted, 0) + .last("limit 1")); + } + + private CargoType findParentByName(String cargoName) { + String name = trimToEmpty(cargoName); + if (Func.isEmpty(name)) { + return null; + } + return getOne(Wrappers.lambdaQuery() + .eq(CargoType::getTypeLevel, TYPE_LEVEL_ONE) + .eq(CargoType::getCargoName, name) + .eq(CargoType::getIsDeleted, 0) + .last("limit 1")); + } + + private void validateUniqueCode(CargoType cargoType) { + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery() + .eq(CargoType::getCargoCode, cargoType.getCargoCode()) + .eq(CargoType::getIsDeleted, 0); + if (Func.isNotEmpty(cargoType.getId())) { + queryWrapper.ne(CargoType::getId, cargoType.getId()); + } + if (count(queryWrapper) > 0L) { + throw new ServiceException("该货物类型编码已存在"); + } + } + + private void validateUniqueName(CargoType cargoType) { + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery() + .eq(CargoType::getCargoName, cargoType.getCargoName()) + .eq(CargoType::getTypeLevel, cargoType.getTypeLevel()) + .eq(CargoType::getIsDeleted, 0); + if (Objects.equals(cargoType.getTypeLevel(), TYPE_LEVEL_TWO)) { + queryWrapper.eq(CargoType::getParentCargoCode, cargoType.getParentCargoCode()); + } + if (Func.isNotEmpty(cargoType.getId())) { + queryWrapper.ne(CargoType::getId, cargoType.getId()); + } + if (count(queryWrapper) > 0L) { + throw new ServiceException("该上级下已存在同名货物类型"); + } + } + + private CargoTypeVO toParentOption(CargoType cargoType) { + CargoTypeVO cargoTypeVO = new CargoTypeVO(); + cargoTypeVO.setId(cargoType.getId()); + cargoTypeVO.setCargoName(cargoType.getCargoName()); + cargoTypeVO.setCargoCode(cargoType.getCargoCode()); + cargoTypeVO.setTypeLevel(cargoType.getTypeLevel()); + cargoTypeVO.setTypeLevelName("一级货物类型"); + return cargoTypeVO; + } + + private CargoTypeExportExcel toExportExcel(CargoType cargoType) { + CargoTypeExportExcel excel = new CargoTypeExportExcel(); + excel.setTypeLevelName(Objects.equals(cargoType.getTypeLevel(), TYPE_LEVEL_ONE) ? "一级货物类型" : "二级货物类型"); + excel.setCargoName(cargoType.getCargoName()); + excel.setCargoCode(cargoType.getCargoCode()); + excel.setParentCargoName("/"); + excel.setParentCargoCode("/"); + if (Objects.equals(cargoType.getTypeLevel(), TYPE_LEVEL_TWO)) { + CargoType parent = resolveParent(cargoType); + excel.setParentCargoName(parent == null ? "" : parent.getCargoName()); + excel.setParentCargoCode(cargoType.getParentCargoCode()); + } + excel.setCreateUserName(Func.isEmpty(cargoType.getCreateUser()) ? "" : UserCache.getUserRealName(cargoType.getCreateUser())); + excel.setRemark(cargoType.getRemark()); + excel.setUpdateTime(cargoType.getUpdateTime()); + excel.setCreateTime(cargoType.getCreateTime()); + return excel; + } + + private CargoTypeImportFailureExcel toImportFailureExcel(CargoTypeExcel excel, String failureReason) { + CargoTypeImportFailureExcel failureExcel = new CargoTypeImportFailureExcel(); + failureExcel.setTypeLevelName(excel.getTypeLevelName()); + failureExcel.setParentCargoName(excel.getParentCargoName()); + failureExcel.setParentCargoCode(excel.getParentCargoCode()); + failureExcel.setCargoName(excel.getCargoName()); + failureExcel.setCargoCode(excel.getCargoCode()); + failureExcel.setRemark(excel.getRemark()); + failureExcel.setFailureReason(failureReason); + return failureExcel; + } + + private String trimToEmpty(String value) { + return value == null ? "" : value.trim(); + } + + private String trimToNull(String value) { + String trimValue = trimToEmpty(value); + return trimValue.isEmpty() ? null : trimValue; + } + +} diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/CurrencyServiceImpl.java b/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/CurrencyServiceImpl.java index b564f7f..a403af8 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/CurrencyServiceImpl.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/CurrencyServiceImpl.java @@ -115,11 +115,11 @@ public class CurrencyServiceImpl extends BaseServiceImpl data) { + public List importCurrency(List data) { if (Func.isEmpty(data)) { throw new ServiceException("导入数据不能为空"); } - List errorList = new ArrayList<>(); + List errorList = new ArrayList<>(); int successCount = 0; for (int index = 0; index < data.size(); index++) { CurrencyExcel excel = data.get(index); @@ -134,12 +134,11 @@ public class CurrencyServiceImpl extends BaseServiceImpl data) { + public List importPortTerminal(List data) { if (Func.isEmpty(data)) { throw new ServiceException("导入数据不能为空"); } - List errorList = new ArrayList<>(); + List errorList = new ArrayList<>(); for (int index = 0; index < data.size(); index++) { PortTerminalExcel excel = data.get(index); try { @@ -145,12 +145,11 @@ public class PortTerminalServiceImpl extends BaseServiceImpl data) { + public List importRailwayStation(List data) { if (Func.isEmpty(data)) { throw new ServiceException("导入数据不能为空"); } - List errorList = new ArrayList<>(); + List errorList = new ArrayList<>(); for (int index = 0; index < data.size(); index++) { RailwayStationExcel excel = data.get(index); try { @@ -140,12 +140,11 @@ public class RailwayStationServiceImpl extends BaseServiceImpl impleme } @Override - public void importRegion(List data, Boolean isCovered) { - List list = new ArrayList<>(); - data.forEach(regionExcel -> { - Region region = BeanUtil.copyProperties(regionExcel, Region.class); - list.add(region); - }); - if (isCovered) { - this.saveOrUpdateBatch(list); - } else { - this.saveBatch(list); + public List importRegion(List data, Boolean isCovered) { + if (Func.isEmpty(data)) { + throw new ServiceException("导入数据不能为空"); } + List errorList = new ArrayList<>(); + for (int index = 0; index < data.size(); index++) { + RegionExcel excel = data.get(index); + try { + Region region = BeanUtil.copyProperties(excel, Region.class); + if (Boolean.TRUE.equals(isCovered)) { + this.saveOrUpdate(region); + } else { + this.save(region); + } + } catch (Exception exception) { + excel.setErrorMessage("第" + (index + 2) + "行:" + exception.getMessage()); + errorList.add(excel); + } + } + return errorList; } @Override diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/wrapper/CargoTypeWrapper.java b/blade-service/blade-system/src/main/java/org/springblade/system/wrapper/CargoTypeWrapper.java new file mode 100644 index 0000000..78eda53 --- /dev/null +++ b/blade-service/blade-system/src/main/java/org/springblade/system/wrapper/CargoTypeWrapper.java @@ -0,0 +1,57 @@ +/** + * BladeX Commercial License Agreement + * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved. + *

+ * Use of this software is governed by the Commercial License Agreement + * obtained after purchasing a license from BladeX. + *

+ * 1. This software is for development use only under a valid license + * from BladeX. + *

+ * 2. Redistribution of this software's source code to any third party + * without a commercial license is strictly prohibited. + *

+ * 3. Licensees may copyright their own code but cannot use segments + * from this software for such purposes. Copyright of this software + * remains with BladeX. + *

+ * Using this software signifies agreement to this License, and the software + * must not be used for illegal purposes. + *

+ * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is + * not liable for any claims arising from secondary or illegal development. + *

+ * Author: Chill Zhuang (bladejava@qq.com) + */ +package org.springblade.system.wrapper; + +import org.springblade.core.mp.support.BaseEntityWrapper; +import org.springblade.core.tool.utils.BeanUtil; +import org.springblade.core.tool.utils.Func; +import org.springblade.system.cache.UserCache; +import org.springblade.system.pojo.entity.CargoType; +import org.springblade.system.pojo.vo.CargoTypeVO; + +import java.util.Objects; + +/** + * 货物类型包装类 + * + * @author Chill + */ +public class CargoTypeWrapper extends BaseEntityWrapper { + + public static CargoTypeWrapper build() { + return new CargoTypeWrapper(); + } + + @Override + public CargoTypeVO entityVO(CargoType cargoType) { + CargoTypeVO cargoTypeVO = Objects.requireNonNull(BeanUtil.copyProperties(cargoType, CargoTypeVO.class)); + cargoTypeVO.setTypeLevelName(Objects.equals(cargoType.getTypeLevel(), 1) ? "一级货物类型" : "二级货物类型"); + cargoTypeVO.setCreateUserName(Func.isEmpty(cargoType.getCreateUser()) ? "" : UserCache.getUserRealName(cargoType.getCreateUser())); + cargoTypeVO.setUpdateUserName(Func.isEmpty(cargoType.getUpdateUser()) ? "" : UserCache.getUserRealName(cargoType.getUpdateUser())); + return cargoTypeVO; + } + +} diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/AccidentRecordController.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/AccidentRecordController.java index 9c7b171..31128b0 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/AccidentRecordController.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/AccidentRecordController.java @@ -126,9 +126,12 @@ public class AccidentRecordController extends BladeController { @PostMapping("/import-accident-record") @ApiOperationSupport(order = 5) @Operation(summary = "导入事故记录", description = "传入excel") - public R importAccidentRecord(MultipartFile file) { - AccidentRecordImporter accidentRecordImporter = new AccidentRecordImporter(accidentRecordService); - ExcelUtil.save(file, accidentRecordImporter, AccidentRecordExcel.class); + public R importAccidentRecord(MultipartFile file, HttpServletResponse response) { + List failureList = accidentRecordService.importAccidentRecord(ExcelUtil.read(file, AccidentRecordExcel.class)); + if (Func.isNotEmpty(failureList)) { + org.springblade.common.excel.ImportFailureExcelUtil.export(response, "事故记录导入失败明细" + DateUtil.time(), "导入失败明细", failureList, AccidentRecordExcel.class); + return null; + } return R.success("操作成功"); } diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/AnnualInspectionRecordController.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/AnnualInspectionRecordController.java index 47cee3d..6c5c8d7 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/AnnualInspectionRecordController.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/AnnualInspectionRecordController.java @@ -111,9 +111,12 @@ public class AnnualInspectionRecordController extends BladeController { @PostMapping("/import-annual-inspection-record") @ApiOperationSupport(order = 5) @Operation(summary = "导入年检记录", description = "传入excel") - public R importAnnualInspectionRecord(MultipartFile file) { - AnnualInspectionRecordImporter annualInspectionRecordImporter = new AnnualInspectionRecordImporter(annualInspectionRecordService); - ExcelUtil.save(file, annualInspectionRecordImporter, AnnualInspectionRecordExcel.class); + public R importAnnualInspectionRecord(MultipartFile file, HttpServletResponse response) { + List failureList = annualInspectionRecordService.importAnnualInspectionRecord(ExcelUtil.read(file, AnnualInspectionRecordExcel.class)); + if (Func.isNotEmpty(failureList)) { + org.springblade.common.excel.ImportFailureExcelUtil.export(response, "年检记录导入失败明细" + DateUtil.time(), "导入失败明细", failureList, AnnualInspectionRecordExcel.class); + return null; + } return R.success("操作成功"); } diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/CreditScoreQuantificationController.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/CreditScoreQuantificationController.java index 459c19f..59c404f 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/CreditScoreQuantificationController.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/CreditScoreQuantificationController.java @@ -137,9 +137,12 @@ public class CreditScoreQuantificationController extends BladeController { @PostMapping("/import-credit-score-quantification") @ApiOperationSupport(order = 7) @Operation(summary = "导入评分量化表", description = "传入excel") - public R importCreditScoreQuantification(MultipartFile file) { - CreditScoreQuantificationImporter importer = new CreditScoreQuantificationImporter(creditScoreQuantificationService); - ExcelUtil.save(file, importer, CreditScoreQuantificationExcel.class); + public R importCreditScoreQuantification(MultipartFile file, HttpServletResponse response) { + List failureList = creditScoreQuantificationService.importCreditScoreQuantification(ExcelUtil.read(file, CreditScoreQuantificationExcel.class)); + if (Func.isNotEmpty(failureList)) { + org.springblade.common.excel.ImportFailureExcelUtil.export(response, "评分量化表导入失败明细" + DateUtil.time(), "导入失败明细", failureList, CreditScoreQuantificationExcel.class); + return null; + } return R.success("操作成功"); } diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/EtcRecordController.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/EtcRecordController.java index 677fbba..5fcef71 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/EtcRecordController.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/EtcRecordController.java @@ -92,9 +92,12 @@ public class EtcRecordController extends BladeController { @PostMapping("/import-etc-record") @ApiOperationSupport(order = 5) @Operation(summary = "导入ETC记录", description = "传入excel") - public R importEtcRecord(MultipartFile file) { - EtcRecordImporter etcRecordImporter = new EtcRecordImporter(etcRecordService); - ExcelUtil.save(file, etcRecordImporter, EtcRecordExcel.class); + public R importEtcRecord(MultipartFile file, HttpServletResponse response) { + List failureList = etcRecordService.importEtcRecord(ExcelUtil.read(file, EtcRecordExcel.class)); + if (Func.isNotEmpty(failureList)) { + org.springblade.common.excel.ImportFailureExcelUtil.export(response, "ETC记录导入失败明细" + DateUtil.time(), "导入失败明细", failureList, EtcRecordExcel.class); + return null; + } return R.success("操作成功"); } diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/InsuranceRecordController.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/InsuranceRecordController.java index a623839..d0def3a 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/InsuranceRecordController.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/InsuranceRecordController.java @@ -127,9 +127,12 @@ public class InsuranceRecordController extends BladeController { @PostMapping("/import-insurance-record") @ApiOperationSupport(order = 5) @Operation(summary = "导入保险记录", description = "传入excel") - public R importInsuranceRecord(MultipartFile file) { - InsuranceRecordImporter insuranceRecordImporter = new InsuranceRecordImporter(insuranceRecordService); - ExcelUtil.save(file, insuranceRecordImporter, InsuranceRecordExcel.class); + public R importInsuranceRecord(MultipartFile file, HttpServletResponse response) { + List failureList = insuranceRecordService.importInsuranceRecord(ExcelUtil.read(file, InsuranceRecordExcel.class)); + if (Func.isNotEmpty(failureList)) { + org.springblade.common.excel.ImportFailureExcelUtil.export(response, "保险记录导入失败明细" + DateUtil.time(), "导入失败明细", failureList, InsuranceRecordExcel.class); + return null; + } return R.success("操作成功"); } diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/MaintenancePlanController.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/MaintenancePlanController.java index ba022b3..7d2f1fe 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/MaintenancePlanController.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/MaintenancePlanController.java @@ -126,9 +126,12 @@ public class MaintenancePlanController extends BladeController { @PostMapping("/import-maintenance-plan") @ApiOperationSupport(order = 5) @Operation(summary = "导入保养记录", description = "传入excel") - public R importMaintenancePlan(MultipartFile file) { - MaintenancePlanImporter maintenancePlanImporter = new MaintenancePlanImporter(maintenancePlanService); - ExcelUtil.save(file, maintenancePlanImporter, MaintenancePlanExcel.class); + public R importMaintenancePlan(MultipartFile file, HttpServletResponse response) { + List failureList = maintenancePlanService.importMaintenancePlan(ExcelUtil.read(file, MaintenancePlanExcel.class)); + if (Func.isNotEmpty(failureList)) { + org.springblade.common.excel.ImportFailureExcelUtil.export(response, "保养记录导入失败明细" + DateUtil.time(), "导入失败明细", failureList, MaintenancePlanExcel.class); + return null; + } return R.success("操作成功"); } diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/MaintenanceRecordController.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/MaintenanceRecordController.java index 7c90daf..840f98e 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/MaintenanceRecordController.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/MaintenanceRecordController.java @@ -126,9 +126,12 @@ public class MaintenanceRecordController extends BladeController { @PostMapping("/import-maintenance-record") @ApiOperationSupport(order = 5) @Operation(summary = "导入维修记录", description = "传入excel") - public R importMaintenanceRecord(MultipartFile file) { - MaintenanceRecordImporter maintenanceRecordImporter = new MaintenanceRecordImporter(maintenanceRecordService); - ExcelUtil.save(file, maintenanceRecordImporter, MaintenanceRecordExcel.class); + public R importMaintenanceRecord(MultipartFile file, HttpServletResponse response) { + List failureList = maintenanceRecordService.importMaintenanceRecord(ExcelUtil.read(file, MaintenanceRecordExcel.class)); + if (Func.isNotEmpty(failureList)) { + org.springblade.common.excel.ImportFailureExcelUtil.export(response, "维修记录导入失败明细" + DateUtil.time(), "导入失败明细", failureList, MaintenanceRecordExcel.class); + return null; + } return R.success("操作成功"); } diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/MileageRecordController.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/MileageRecordController.java index 81b8953..9fff809 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/MileageRecordController.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/MileageRecordController.java @@ -111,9 +111,12 @@ public class MileageRecordController extends BladeController { @PostMapping("/import-mileage-record") @ApiOperationSupport(order = 5) @Operation(summary = "导入里程记录", description = "传入excel") - public R importMileageRecord(MultipartFile file) { - MileageRecordImporter mileageRecordImporter = new MileageRecordImporter(mileageRecordService); - ExcelUtil.save(file, mileageRecordImporter, MileageRecordExcel.class); + public R importMileageRecord(MultipartFile file, HttpServletResponse response) { + List failureList = mileageRecordService.importMileageRecord(ExcelUtil.read(file, MileageRecordExcel.class)); + if (Func.isNotEmpty(failureList)) { + org.springblade.common.excel.ImportFailureExcelUtil.export(response, "里程记录导入失败明细" + DateUtil.time(), "导入失败明细", failureList, MileageRecordExcel.class); + return null; + } return R.success("操作成功"); } diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/OilElectricRecordController.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/OilElectricRecordController.java index 9b23538..8312864 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/OilElectricRecordController.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/OilElectricRecordController.java @@ -92,9 +92,12 @@ public class OilElectricRecordController extends BladeController { @PostMapping("/import-oil-electric-record") @ApiOperationSupport(order = 5) @Operation(summary = "导入油电记录", description = "传入excel") - public R importOilElectricRecord(MultipartFile file) { - OilElectricRecordImporter oilElectricRecordImporter = new OilElectricRecordImporter(oilElectricRecordService); - ExcelUtil.save(file, oilElectricRecordImporter, OilElectricRecordExcel.class); + public R importOilElectricRecord(MultipartFile file, HttpServletResponse response) { + List failureList = oilElectricRecordService.importOilElectricRecord(ExcelUtil.read(file, OilElectricRecordExcel.class)); + if (Func.isNotEmpty(failureList)) { + org.springblade.common.excel.ImportFailureExcelUtil.export(response, "油电记录导入失败明细" + DateUtil.time(), "导入失败明细", failureList, OilElectricRecordExcel.class); + return null; + } return R.success("操作成功"); } diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/OtherExpenseRecordController.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/OtherExpenseRecordController.java index 45b773b..e549b90 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/OtherExpenseRecordController.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/OtherExpenseRecordController.java @@ -92,9 +92,12 @@ public class OtherExpenseRecordController extends BladeController { @PostMapping("/import-other-expense-record") @ApiOperationSupport(order = 5) @Operation(summary = "导入其他费用记录", description = "传入excel") - public R importOtherExpenseRecord(MultipartFile file) { - OtherExpenseRecordImporter otherExpenseRecordImporter = new OtherExpenseRecordImporter(otherExpenseRecordService); - ExcelUtil.save(file, otherExpenseRecordImporter, OtherExpenseRecordExcel.class); + public R importOtherExpenseRecord(MultipartFile file, HttpServletResponse response) { + List failureList = otherExpenseRecordService.importOtherExpenseRecord(ExcelUtil.read(file, OtherExpenseRecordExcel.class)); + if (Func.isNotEmpty(failureList)) { + org.springblade.common.excel.ImportFailureExcelUtil.export(response, "其他费用记录导入失败明细" + DateUtil.time(), "导入失败明细", failureList, OtherExpenseRecordExcel.class); + return null; + } return R.success("操作成功"); } diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/TireReplacementRecordController.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/TireReplacementRecordController.java index 56d63a1..f729cca 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/TireReplacementRecordController.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/TireReplacementRecordController.java @@ -126,9 +126,12 @@ public class TireReplacementRecordController extends BladeController { @PostMapping("/import-tire-replacement-record") @ApiOperationSupport(order = 5) @Operation(summary = "导入换胎记录", description = "传入excel") - public R importTireReplacementRecord(MultipartFile file) { - TireReplacementRecordImporter tireReplacementRecordImporter = new TireReplacementRecordImporter(tireReplacementRecordService); - ExcelUtil.save(file, tireReplacementRecordImporter, TireReplacementRecordExcel.class); + public R importTireReplacementRecord(MultipartFile file, HttpServletResponse response) { + List failureList = tireReplacementRecordService.importTireReplacementRecord(ExcelUtil.read(file, TireReplacementRecordExcel.class)); + if (Func.isNotEmpty(failureList)) { + org.springblade.common.excel.ImportFailureExcelUtil.export(response, "换胎记录导入失败明细" + DateUtil.time(), "导入失败明细", failureList, TireReplacementRecordExcel.class); + return null; + } return R.success("操作成功"); } diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/TransportChangeRecordController.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/TransportChangeRecordController.java index ed5d7f1..d66588c 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/TransportChangeRecordController.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/TransportChangeRecordController.java @@ -111,9 +111,12 @@ public class TransportChangeRecordController extends BladeController { @PostMapping("/import-transport-change-record") @ApiOperationSupport(order = 5) @Operation(summary = "导入变更记录", description = "传入excel") - public R importTransportChangeRecord(MultipartFile file) { - TransportChangeRecordImporter transportChangeRecordImporter = new TransportChangeRecordImporter(transportChangeRecordService); - ExcelUtil.save(file, transportChangeRecordImporter, TransportChangeRecordExcel.class); + public R importTransportChangeRecord(MultipartFile file, HttpServletResponse response) { + List failureList = transportChangeRecordService.importTransportChangeRecord(ExcelUtil.read(file, TransportChangeRecordExcel.class)); + if (Func.isNotEmpty(failureList)) { + org.springblade.common.excel.ImportFailureExcelUtil.export(response, "变更记录导入失败明细" + DateUtil.time(), "导入失败明细", failureList, TransportChangeRecordExcel.class); + return null; + } return R.success("操作成功"); } diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/ViolationRecordController.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/ViolationRecordController.java index 8098c50..98d05ab 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/ViolationRecordController.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/controller/ViolationRecordController.java @@ -126,9 +126,12 @@ public class ViolationRecordController extends BladeController { @PostMapping("/import-violation-record") @ApiOperationSupport(order = 5) @Operation(summary = "导入违章记录", description = "传入excel") - public R importViolationRecord(MultipartFile file) { - ViolationRecordImporter violationRecordImporter = new ViolationRecordImporter(violationRecordService); - ExcelUtil.save(file, violationRecordImporter, ViolationRecordExcel.class); + public R importViolationRecord(MultipartFile file, HttpServletResponse response) { + List failureList = violationRecordService.importViolationRecord(ExcelUtil.read(file, ViolationRecordExcel.class)); + if (Func.isNotEmpty(failureList)) { + org.springblade.common.excel.ImportFailureExcelUtil.export(response, "违章记录导入失败明细" + DateUtil.time(), "导入失败明细", failureList, ViolationRecordExcel.class); + return null; + } return R.success("操作成功"); } diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/AccidentRecordExcel.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/AccidentRecordExcel.java index cf25278..c2a588d 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/AccidentRecordExcel.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/AccidentRecordExcel.java @@ -86,7 +86,7 @@ public class AccidentRecordExcel implements Serializable { @ExcelProperty("备注") private String remark; - @ExcelProperty("报错文案") + @ExcelProperty private String errorMessage; } diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/AnnualInspectionRecordExcel.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/AnnualInspectionRecordExcel.java index 98081bd..904b933 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/AnnualInspectionRecordExcel.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/AnnualInspectionRecordExcel.java @@ -83,7 +83,7 @@ public class AnnualInspectionRecordExcel implements Serializable { @ExcelProperty("备注") private String remark; - @ExcelProperty("报错文案") + @ExcelProperty private String errorMessage; } diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/CreditScoreQuantificationExcel.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/CreditScoreQuantificationExcel.java index af7cf23..1752e62 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/CreditScoreQuantificationExcel.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/CreditScoreQuantificationExcel.java @@ -22,6 +22,7 @@ */ package org.springblade.transport.excel; +import cn.idev.excel.annotation.ExcelIgnore; import cn.idev.excel.annotation.ExcelProperty; import cn.idev.excel.annotation.write.style.ColumnWidth; import cn.idev.excel.annotation.write.style.ContentRowHeight; @@ -103,7 +104,7 @@ public class CreditScoreQuantificationExcel implements Serializable { @ExcelProperty("评估标准说明") private String ratingStandardDescription; - @ExcelProperty("报错文案") + @ExcelIgnore private String errorMessage; } diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/EtcRecordExcel.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/EtcRecordExcel.java index 5d83d8e..a78f65f 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/EtcRecordExcel.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/EtcRecordExcel.java @@ -58,7 +58,7 @@ public class EtcRecordExcel implements Serializable { @ExcelProperty("备注") private String remark; - @ExcelProperty("报错文案") + @ExcelProperty private String errorMessage; } diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/InsuranceRecordExcel.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/InsuranceRecordExcel.java index 8077577..385a9e9 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/InsuranceRecordExcel.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/InsuranceRecordExcel.java @@ -86,7 +86,7 @@ public class InsuranceRecordExcel implements Serializable { @ExcelProperty("备注") private String remark; - @ExcelProperty("报错文案") + @ExcelProperty private String errorMessage; } diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/MaintenancePlanExcel.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/MaintenancePlanExcel.java index 67ff3f3..1aeda78 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/MaintenancePlanExcel.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/MaintenancePlanExcel.java @@ -100,7 +100,7 @@ public class MaintenancePlanExcel implements Serializable { @ExcelProperty("备注") private String remark; - @ExcelProperty("报错文案") + @ExcelProperty private String errorMessage; } diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/MaintenanceRecordExcel.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/MaintenanceRecordExcel.java index 9c735bf..2530a70 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/MaintenanceRecordExcel.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/MaintenanceRecordExcel.java @@ -101,7 +101,7 @@ public class MaintenanceRecordExcel implements Serializable { @ExcelProperty("备注") private String remark; - @ExcelProperty("报错文案") + @ExcelProperty private String errorMessage; } diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/MileageRecordExcel.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/MileageRecordExcel.java index 9c46a76..1c79291 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/MileageRecordExcel.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/MileageRecordExcel.java @@ -81,7 +81,7 @@ public class MileageRecordExcel implements Serializable { @ExcelProperty("备注") private String remark; - @ExcelProperty("报错文案") + @ExcelProperty private String errorMessage; } diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/OilElectricRecordExcel.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/OilElectricRecordExcel.java index d71e5f1..750cb3a 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/OilElectricRecordExcel.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/OilElectricRecordExcel.java @@ -79,7 +79,7 @@ public class OilElectricRecordExcel implements Serializable { @ExcelProperty("备注") private String remark; - @ExcelProperty("报错文案") + @ExcelProperty private String errorMessage; } diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/OtherExpenseRecordExcel.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/OtherExpenseRecordExcel.java index 6246240..f170657 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/OtherExpenseRecordExcel.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/OtherExpenseRecordExcel.java @@ -52,7 +52,7 @@ public class OtherExpenseRecordExcel implements Serializable { @ExcelProperty("备注") private String remark; - @ExcelProperty("报错文案") + @ExcelProperty private String errorMessage; } diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/TireReplacementRecordExcel.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/TireReplacementRecordExcel.java index ff1f821..626466e 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/TireReplacementRecordExcel.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/TireReplacementRecordExcel.java @@ -79,7 +79,7 @@ public class TireReplacementRecordExcel implements Serializable { @ExcelProperty("备注") private String remark; - @ExcelProperty("报错文案") + @ExcelProperty private String errorMessage; } diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/TransportChangeRecordExcel.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/TransportChangeRecordExcel.java index 6b3b2d8..9390f75 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/TransportChangeRecordExcel.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/TransportChangeRecordExcel.java @@ -66,7 +66,7 @@ public class TransportChangeRecordExcel implements Serializable { @ExcelProperty("备注") private String remark; - @ExcelProperty("报错文案") + @ExcelProperty private String errorMessage; } diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/ViolationRecordExcel.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/ViolationRecordExcel.java index 51fbc5a..b07d3cb 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/ViolationRecordExcel.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/excel/ViolationRecordExcel.java @@ -89,7 +89,7 @@ public class ViolationRecordExcel implements Serializable { @ExcelProperty("处理结果") private String processResult; - @ExcelProperty("报错文案") + @ExcelProperty private String errorMessage; } diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IAccidentRecordService.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IAccidentRecordService.java index c3b9508..af60e21 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IAccidentRecordService.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IAccidentRecordService.java @@ -63,7 +63,7 @@ public interface IAccidentRecordService extends BaseService { * * @param data 导入数据 */ - void importAccidentRecord(List data); + List importAccidentRecord(List data); /** * 导出事故记录 diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IAnnualInspectionRecordService.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IAnnualInspectionRecordService.java index 8dfe1b0..ab7b08b 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IAnnualInspectionRecordService.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IAnnualInspectionRecordService.java @@ -45,7 +45,7 @@ public interface IAnnualInspectionRecordService extends BaseService data); + List importAnnualInspectionRecord(List data); List exportAnnualInspectionRecord(Wrapper queryWrapper); diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/ICreditScoreQuantificationService.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/ICreditScoreQuantificationService.java index 307be83..0c42b2e 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/ICreditScoreQuantificationService.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/ICreditScoreQuantificationService.java @@ -95,8 +95,9 @@ public interface ICreditScoreQuantificationService extends BaseService data); + List importCreditScoreQuantification(List data); /** * 导出评分量化表 diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IEtcRecordService.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IEtcRecordService.java index 07214a9..0fc0aa5 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IEtcRecordService.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IEtcRecordService.java @@ -26,7 +26,7 @@ public interface IEtcRecordService extends BaseService { boolean submit(EtcRecord etcRecord); - void importEtcRecord(List data); + List importEtcRecord(List data); List exportEtcRecord(Wrapper queryWrapper); diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IInsuranceRecordService.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IInsuranceRecordService.java index 2cbb28e..23207b8 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IInsuranceRecordService.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IInsuranceRecordService.java @@ -64,7 +64,7 @@ public interface IInsuranceRecordService extends BaseService { * * @param data 导入数据 */ - void importInsuranceRecord(List data); + List importInsuranceRecord(List data); /** * 导出保险记录 diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IMaintenancePlanService.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IMaintenancePlanService.java index 67e8e86..449688d 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IMaintenancePlanService.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IMaintenancePlanService.java @@ -63,7 +63,7 @@ public interface IMaintenancePlanService extends BaseService { * * @param data 导入数据 */ - void importMaintenancePlan(List data); + List importMaintenancePlan(List data); /** * 导出保养记录 diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IMaintenanceRecordService.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IMaintenanceRecordService.java index 3d7d7ab..bd3977a 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IMaintenanceRecordService.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IMaintenanceRecordService.java @@ -63,7 +63,7 @@ public interface IMaintenanceRecordService extends BaseService data); + List importMaintenanceRecord(List data); /** * 导出维修记录 diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IMileageRecordService.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IMileageRecordService.java index b3478ab..e6c3d62 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IMileageRecordService.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IMileageRecordService.java @@ -45,7 +45,7 @@ public interface IMileageRecordService extends BaseService { boolean submit(MileageRecord mileageRecord); - void importMileageRecord(List data); + List importMileageRecord(List data); List exportMileageRecord(Wrapper queryWrapper); diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IOilElectricRecordService.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IOilElectricRecordService.java index b270435..3d6977e 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IOilElectricRecordService.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IOilElectricRecordService.java @@ -26,7 +26,7 @@ public interface IOilElectricRecordService extends BaseService data); + List importOilElectricRecord(List data); List exportOilElectricRecord(Wrapper queryWrapper); diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IOtherExpenseRecordService.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IOtherExpenseRecordService.java index 7a5d763..abea775 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IOtherExpenseRecordService.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IOtherExpenseRecordService.java @@ -26,7 +26,7 @@ public interface IOtherExpenseRecordService extends BaseService data); + List importOtherExpenseRecord(List data); List exportOtherExpenseRecord(Wrapper queryWrapper); diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/ITireReplacementRecordService.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/ITireReplacementRecordService.java index 7e8d5a2..54b7b68 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/ITireReplacementRecordService.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/ITireReplacementRecordService.java @@ -63,7 +63,7 @@ public interface ITireReplacementRecordService extends BaseService data); + List importTireReplacementRecord(List data); /** * 导出换胎记录 diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/ITransportChangeRecordService.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/ITransportChangeRecordService.java index 9dd406b..8a4c8bd 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/ITransportChangeRecordService.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/ITransportChangeRecordService.java @@ -45,7 +45,7 @@ public interface ITransportChangeRecordService extends BaseService data); + List importTransportChangeRecord(List data); List exportTransportChangeRecord(Wrapper queryWrapper); diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IViolationRecordService.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IViolationRecordService.java index c865351..7a5cdff 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IViolationRecordService.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/IViolationRecordService.java @@ -63,7 +63,7 @@ public interface IViolationRecordService extends BaseService { * * @param data 导入数据 */ - void importViolationRecord(List data); + List importViolationRecord(List data); /** * 导出违章记录 diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/AccidentRecordServiceImpl.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/AccidentRecordServiceImpl.java index 7f399d0..c9bcb0d 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/AccidentRecordServiceImpl.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/AccidentRecordServiceImpl.java @@ -77,22 +77,22 @@ public class AccidentRecordServiceImpl extends BaseServiceImpl data) { + public List importAccidentRecord(List data) { if (Func.isEmpty(data)) { throw new ServiceException("导入数据不能为空"); } - List errorList = new ArrayList<>(); + List errorList = new ArrayList<>(); for (int index = 0; index < data.size(); index++) { + AccidentRecordExcel excel = data.get(index); try { - AccidentRecord accidentRecord = Objects.requireNonNull(BeanUtil.copyProperties(data.get(index), AccidentRecord.class)); + AccidentRecord accidentRecord = Objects.requireNonNull(BeanUtil.copyProperties(excel, AccidentRecord.class)); submit(accidentRecord); } catch (Exception exception) { - errorList.add("第" + (index + 2) + "行:" + exception.getMessage()); + excel.setErrorMessage("第" + (index + 2) + "行:" + exception.getMessage()); + errorList.add(excel); } } - if (Func.isNotEmpty(errorList)) { - throw new ServiceException(String.join(";", errorList)); - } + return errorList; } @Override diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/AnnualInspectionRecordServiceImpl.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/AnnualInspectionRecordServiceImpl.java index 3b40c29..9948f9b 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/AnnualInspectionRecordServiceImpl.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/AnnualInspectionRecordServiceImpl.java @@ -79,24 +79,23 @@ public class AnnualInspectionRecordServiceImpl extends BaseServiceImpl data) { + public List importAnnualInspectionRecord(List data) { if (Func.isEmpty(data)) { throw new ServiceException("导入数据不能为空"); } - List errorList = new ArrayList<>(); + List errorList = new ArrayList<>(); for (int index = 0; index < data.size(); index++) { + AnnualInspectionRecordExcel excel = data.get(index); try { - AnnualInspectionRecordExcel excel = data.get(index); AnnualInspectionRecord annualInspectionRecord = Objects.requireNonNull(BeanUtil.copyProperties(excel, AnnualInspectionRecord.class)); fillInspectionContent(annualInspectionRecord, excel.getInspectionContent()); submit(annualInspectionRecord); } catch (Exception exception) { - errorList.add("第" + (index + 2) + "行:" + exception.getMessage()); + excel.setErrorMessage("第" + (index + 2) + "行:" + exception.getMessage()); + errorList.add(excel); } } - if (Func.isNotEmpty(errorList)) { - throw new ServiceException(String.join(";", errorList)); - } + return errorList; } @Override diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/CreditScoreQuantificationServiceImpl.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/CreditScoreQuantificationServiceImpl.java index 7821374..de58ee4 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/CreditScoreQuantificationServiceImpl.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/CreditScoreQuantificationServiceImpl.java @@ -189,7 +189,7 @@ public class CreditScoreQuantificationServiceImpl extends BaseServiceImpl data) { + public List importCreditScoreQuantification(List data) { if (Func.isEmpty(data)) { throw new ServiceException("导入数据不能为空"); } @@ -197,19 +197,19 @@ public class CreditScoreQuantificationServiceImpl extends BaseServiceImpl Func.isNotEmpty(trimToNull(row.getTableName()))) .collect(Collectors.groupingBy(row -> trimToEmpty(row.getTableName()), java.util.LinkedHashMap::new, Collectors.toList())); if (Func.isEmpty(dataMap)) { - throw new ServiceException("评定表名称不能为空"); + data.forEach(row -> row.setErrorMessage("评定表名称不能为空")); + return data; } - List errorList = new ArrayList<>(); + List errorList = new ArrayList<>(); dataMap.forEach((tableName, rows) -> { try { submit(buildImportVO(tableName, rows)); } catch (Exception exception) { - errorList.add(tableName + ":" + exception.getMessage()); + rows.forEach(row -> row.setErrorMessage(tableName + ":" + exception.getMessage())); + errorList.addAll(rows); } }); - if (Func.isNotEmpty(errorList)) { - throw new ServiceException(String.join(";", errorList)); - } + return errorList; } @Override diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/EtcRecordServiceImpl.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/EtcRecordServiceImpl.java index 7506cf0..4b6fca2 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/EtcRecordServiceImpl.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/EtcRecordServiceImpl.java @@ -58,23 +58,23 @@ public class EtcRecordServiceImpl extends BaseServiceImpl data) { + public List importEtcRecord(List data) { if (Func.isEmpty(data)) { throw new ServiceException("导入数据不能为空"); } - List errorList = new ArrayList<>(); + List errorList = new ArrayList<>(); for (int index = 0; index < data.size(); index++) { + EtcRecordExcel excel = data.get(index); try { - EtcRecord etcRecord = Objects.requireNonNull(BeanUtil.copyProperties(data.get(index), EtcRecord.class)); + EtcRecord etcRecord = Objects.requireNonNull(BeanUtil.copyProperties(excel, EtcRecord.class)); etcRecord.setDataSource("批量导入"); submit(etcRecord); } catch (Exception exception) { - errorList.add("第" + (index + 2) + "行:" + exception.getMessage()); + excel.setErrorMessage("第" + (index + 2) + "行:" + exception.getMessage()); + errorList.add(excel); } } - if (Func.isNotEmpty(errorList)) { - throw new ServiceException(String.join(";", errorList)); - } + return errorList; } @Override diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/InsuranceRecordServiceImpl.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/InsuranceRecordServiceImpl.java index 20832a4..6e384b8 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/InsuranceRecordServiceImpl.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/InsuranceRecordServiceImpl.java @@ -80,22 +80,22 @@ public class InsuranceRecordServiceImpl extends BaseServiceImpl data) { + public List importInsuranceRecord(List data) { if (Func.isEmpty(data)) { throw new ServiceException("导入数据不能为空"); } - List errorList = new ArrayList<>(); + List errorList = new ArrayList<>(); for (int index = 0; index < data.size(); index++) { + InsuranceRecordExcel excel = data.get(index); try { - InsuranceRecord insuranceRecord = Objects.requireNonNull(BeanUtil.copyProperties(data.get(index), InsuranceRecord.class)); + InsuranceRecord insuranceRecord = Objects.requireNonNull(BeanUtil.copyProperties(excel, InsuranceRecord.class)); submit(insuranceRecord); } catch (Exception exception) { - errorList.add("第" + (index + 2) + "行:" + exception.getMessage()); + excel.setErrorMessage("第" + (index + 2) + "行:" + exception.getMessage()); + errorList.add(excel); } } - if (Func.isNotEmpty(errorList)) { - throw new ServiceException(String.join(";", errorList)); - } + return errorList; } @Override diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/MaintenancePlanServiceImpl.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/MaintenancePlanServiceImpl.java index 2ac0921..bc5b0f1 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/MaintenancePlanServiceImpl.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/MaintenancePlanServiceImpl.java @@ -73,22 +73,22 @@ public class MaintenancePlanServiceImpl extends BaseServiceImpl data) { + public List importMaintenancePlan(List data) { if (Func.isEmpty(data)) { throw new ServiceException("导入数据不能为空"); } - List errorList = new ArrayList<>(); + List errorList = new ArrayList<>(); for (int index = 0; index < data.size(); index++) { + MaintenancePlanExcel excel = data.get(index); try { - MaintenancePlan maintenancePlan = Objects.requireNonNull(BeanUtil.copyProperties(data.get(index), MaintenancePlan.class)); + MaintenancePlan maintenancePlan = Objects.requireNonNull(BeanUtil.copyProperties(excel, MaintenancePlan.class)); submit(maintenancePlan); } catch (Exception exception) { - errorList.add("第" + (index + 2) + "行:" + exception.getMessage()); + excel.setErrorMessage("第" + (index + 2) + "行:" + exception.getMessage()); + errorList.add(excel); } } - if (Func.isNotEmpty(errorList)) { - throw new ServiceException(String.join(";", errorList)); - } + return errorList; } @Override diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/MaintenanceRecordServiceImpl.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/MaintenanceRecordServiceImpl.java index b2a72f2..2a4d1ed 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/MaintenanceRecordServiceImpl.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/MaintenanceRecordServiceImpl.java @@ -75,22 +75,22 @@ public class MaintenanceRecordServiceImpl extends BaseServiceImpl data) { + public List importMaintenanceRecord(List data) { if (Func.isEmpty(data)) { throw new ServiceException("导入数据不能为空"); } - List errorList = new ArrayList<>(); + List errorList = new ArrayList<>(); for (int index = 0; index < data.size(); index++) { + MaintenanceRecordExcel excel = data.get(index); try { - MaintenanceRecord maintenanceRecord = Objects.requireNonNull(BeanUtil.copyProperties(data.get(index), MaintenanceRecord.class)); + MaintenanceRecord maintenanceRecord = Objects.requireNonNull(BeanUtil.copyProperties(excel, MaintenanceRecord.class)); submit(maintenanceRecord); } catch (Exception exception) { - errorList.add("第" + (index + 2) + "行:" + exception.getMessage()); + excel.setErrorMessage("第" + (index + 2) + "行:" + exception.getMessage()); + errorList.add(excel); } } - if (Func.isNotEmpty(errorList)) { - throw new ServiceException(String.join(";", errorList)); - } + return errorList; } @Override diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/MileageRecordServiceImpl.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/MileageRecordServiceImpl.java index d758169..b144077 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/MileageRecordServiceImpl.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/MileageRecordServiceImpl.java @@ -78,22 +78,22 @@ public class MileageRecordServiceImpl extends BaseServiceImpl data) { + public List importMileageRecord(List data) { if (Func.isEmpty(data)) { throw new ServiceException("导入数据不能为空"); } - List errorList = new ArrayList<>(); + List errorList = new ArrayList<>(); for (int index = 0; index < data.size(); index++) { + MileageRecordExcel excel = data.get(index); try { - MileageRecord mileageRecord = Objects.requireNonNull(BeanUtil.copyProperties(data.get(index), MileageRecord.class)); + MileageRecord mileageRecord = Objects.requireNonNull(BeanUtil.copyProperties(excel, MileageRecord.class)); submit(mileageRecord); } catch (Exception exception) { - errorList.add("第" + (index + 2) + "行:" + exception.getMessage()); + excel.setErrorMessage("第" + (index + 2) + "行:" + exception.getMessage()); + errorList.add(excel); } } - if (Func.isNotEmpty(errorList)) { - throw new ServiceException(String.join(";", errorList)); - } + return errorList; } @Override diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/OilElectricRecordServiceImpl.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/OilElectricRecordServiceImpl.java index 4957c91..ad7a6dd 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/OilElectricRecordServiceImpl.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/OilElectricRecordServiceImpl.java @@ -67,23 +67,23 @@ public class OilElectricRecordServiceImpl extends BaseServiceImpl data) { + public List importOilElectricRecord(List data) { if (Func.isEmpty(data)) { throw new ServiceException("导入数据不能为空"); } - List errorList = new ArrayList<>(); + List errorList = new ArrayList<>(); for (int index = 0; index < data.size(); index++) { + OilElectricRecordExcel excel = data.get(index); try { - OilElectricRecord oilElectricRecord = Objects.requireNonNull(BeanUtil.copyProperties(data.get(index), OilElectricRecord.class)); + OilElectricRecord oilElectricRecord = Objects.requireNonNull(BeanUtil.copyProperties(excel, OilElectricRecord.class)); oilElectricRecord.setDataSource(defaultDataSource(oilElectricRecord.getDataSource())); submit(oilElectricRecord); } catch (Exception exception) { - errorList.add("第" + (index + 2) + "行:" + exception.getMessage()); + excel.setErrorMessage("第" + (index + 2) + "行:" + exception.getMessage()); + errorList.add(excel); } } - if (Func.isNotEmpty(errorList)) { - throw new ServiceException(String.join(";", errorList)); - } + return errorList; } @Override diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/OtherExpenseRecordServiceImpl.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/OtherExpenseRecordServiceImpl.java index 1f88b9b..23f9df8 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/OtherExpenseRecordServiceImpl.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/OtherExpenseRecordServiceImpl.java @@ -61,23 +61,23 @@ public class OtherExpenseRecordServiceImpl extends BaseServiceImpl data) { + public List importOtherExpenseRecord(List data) { if (Func.isEmpty(data)) { throw new ServiceException("导入数据不能为空"); } - List errorList = new ArrayList<>(); + List errorList = new ArrayList<>(); for (int index = 0; index < data.size(); index++) { + OtherExpenseRecordExcel excel = data.get(index); try { - OtherExpenseRecord otherExpenseRecord = Objects.requireNonNull(BeanUtil.copyProperties(data.get(index), OtherExpenseRecord.class)); + OtherExpenseRecord otherExpenseRecord = Objects.requireNonNull(BeanUtil.copyProperties(excel, OtherExpenseRecord.class)); otherExpenseRecord.setDataSource("批量导入"); submit(otherExpenseRecord); } catch (Exception exception) { - errorList.add("第" + (index + 2) + "行:" + exception.getMessage()); + excel.setErrorMessage("第" + (index + 2) + "行:" + exception.getMessage()); + errorList.add(excel); } } - if (Func.isNotEmpty(errorList)) { - throw new ServiceException(String.join(";", errorList)); - } + return errorList; } @Override diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/TireReplacementRecordServiceImpl.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/TireReplacementRecordServiceImpl.java index 9ec810a..18bc39f 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/TireReplacementRecordServiceImpl.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/TireReplacementRecordServiceImpl.java @@ -75,22 +75,22 @@ public class TireReplacementRecordServiceImpl extends BaseServiceImpl data) { + public List importTireReplacementRecord(List data) { if (Func.isEmpty(data)) { throw new ServiceException("导入数据不能为空"); } - List errorList = new ArrayList<>(); + List errorList = new ArrayList<>(); for (int index = 0; index < data.size(); index++) { + TireReplacementRecordExcel excel = data.get(index); try { - TireReplacementRecord tireReplacementRecord = Objects.requireNonNull(BeanUtil.copyProperties(data.get(index), TireReplacementRecord.class)); + TireReplacementRecord tireReplacementRecord = Objects.requireNonNull(BeanUtil.copyProperties(excel, TireReplacementRecord.class)); submit(tireReplacementRecord); } catch (Exception exception) { - errorList.add("第" + (index + 2) + "行:" + exception.getMessage()); + excel.setErrorMessage("第" + (index + 2) + "行:" + exception.getMessage()); + errorList.add(excel); } } - if (Func.isNotEmpty(errorList)) { - throw new ServiceException(String.join(";", errorList)); - } + return errorList; } @Override diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/TransportChangeRecordServiceImpl.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/TransportChangeRecordServiceImpl.java index 71b5feb..d5d23db 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/TransportChangeRecordServiceImpl.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/TransportChangeRecordServiceImpl.java @@ -78,22 +78,22 @@ public class TransportChangeRecordServiceImpl extends BaseServiceImpl data) { + public List importTransportChangeRecord(List data) { if (Func.isEmpty(data)) { throw new ServiceException("导入数据不能为空"); } - List errorList = new ArrayList<>(); + List errorList = new ArrayList<>(); for (int index = 0; index < data.size(); index++) { + TransportChangeRecordExcel excel = data.get(index); try { - TransportChangeRecord transportChangeRecord = Objects.requireNonNull(BeanUtil.copyProperties(data.get(index), TransportChangeRecord.class)); + TransportChangeRecord transportChangeRecord = Objects.requireNonNull(BeanUtil.copyProperties(excel, TransportChangeRecord.class)); submit(transportChangeRecord); } catch (Exception exception) { - errorList.add("第" + (index + 2) + "行:" + exception.getMessage()); + excel.setErrorMessage("第" + (index + 2) + "行:" + exception.getMessage()); + errorList.add(excel); } } - if (Func.isNotEmpty(errorList)) { - throw new ServiceException(String.join(";", errorList)); - } + return errorList; } @Override diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/ViolationRecordServiceImpl.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/ViolationRecordServiceImpl.java index d50a500..8902239 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/ViolationRecordServiceImpl.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/ViolationRecordServiceImpl.java @@ -82,24 +82,23 @@ public class ViolationRecordServiceImpl extends BaseServiceImpl data) { + public List importViolationRecord(List data) { if (Func.isEmpty(data)) { throw new ServiceException("导入数据不能为空"); } - List errorList = new ArrayList<>(); + List errorList = new ArrayList<>(); for (int index = 0; index < data.size(); index++) { + ViolationRecordExcel excel = data.get(index); try { - ViolationRecordExcel excel = data.get(index); ViolationRecord violationRecord = Objects.requireNonNull(BeanUtil.copyProperties(excel, ViolationRecord.class)); fillViolationContent(violationRecord, excel.getViolationContent()); submit(violationRecord); } catch (Exception exception) { - errorList.add("第" + (index + 2) + "行:" + exception.getMessage()); + excel.setErrorMessage("第" + (index + 2) + "行:" + exception.getMessage()); + errorList.add(excel); } } - if (Func.isNotEmpty(errorList)) { - throw new ServiceException(String.join(";", errorList)); - } + return errorList; } @Override diff --git a/doc/sql/transport/blade_cargo_type.sql b/doc/sql/transport/blade_cargo_type.sql new file mode 100644 index 0000000..6002366 --- /dev/null +++ b/doc/sql/transport/blade_cargo_type.sql @@ -0,0 +1,39 @@ +-- ---------------------------- +-- Table structure for blade_cargo_type +-- ---------------------------- +DROP TABLE IF EXISTS `blade_cargo_type`; +CREATE TABLE `blade_cargo_type` ( + `id` bigint NOT NULL COMMENT '主键', + `type_level` int NOT NULL COMMENT '类型级别:1一级货物类型,2二级货物类型', + `parent_id` bigint NULL DEFAULT NULL COMMENT '上级货物类型ID', + `parent_cargo_code` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '上级货物类型编码', + `cargo_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '货物类型', + `cargo_code` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '货物类型编码', + `data_source` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '数据来源', + `remark` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '备注', + `create_user` bigint NULL DEFAULT NULL COMMENT '创建人', + `create_dept` bigint NULL DEFAULT NULL COMMENT '创建部门', + `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间', + `update_user` bigint NULL DEFAULT NULL COMMENT '修改人', + `update_time` datetime NULL DEFAULT NULL COMMENT '修改时间', + `status` int NULL DEFAULT 1 COMMENT '状态', + `is_deleted` int NULL DEFAULT 0 COMMENT '是否已删除', + PRIMARY KEY (`id`) USING BTREE, + UNIQUE INDEX `uk_cargo_type_code`(`cargo_code`) USING BTREE, + INDEX `idx_cargo_type_parent`(`parent_id`) USING BTREE, + INDEX `idx_cargo_type_parent_code`(`parent_cargo_code`) USING BTREE, + INDEX `idx_cargo_type_level`(`type_level`) USING BTREE, + INDEX `idx_cargo_type_create_time`(`create_time`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '货物类型'; + +-- ---------------------------- +-- Records of blade_menu for cargo type +-- ---------------------------- +INSERT INTO `blade_menu` (`id`, `parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `component`, `remark`, `is_deleted`) VALUES (2075449200000000001, 1164733399668962201, 'cargo_type', '货物类型', 'cargo_type', '/base/cargo-type', 'iconfont icon-caidanguanli', 55, 1, 0, 1, NULL, '', 0); +INSERT INTO `blade_menu` (`id`, `parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `component`, `remark`, `is_deleted`) VALUES (2075449200000000002, 2075449200000000001, 'cargo_type_add', '新增', 'cargo_type_add', '', '', 1, 2, 0, 1, NULL, '', 0); +INSERT INTO `blade_menu` (`id`, `parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `component`, `remark`, `is_deleted`) VALUES (2075449200000000003, 2075449200000000001, 'cargo_type_view', '查看', 'cargo_type_view', '', '', 2, 2, 0, 1, NULL, '', 0); +INSERT INTO `blade_menu` (`id`, `parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `component`, `remark`, `is_deleted`) VALUES (2075449200000000004, 2075449200000000001, 'cargo_type_edit', '编辑', 'cargo_type_edit', '', '', 3, 2, 0, 1, NULL, '', 0); +INSERT INTO `blade_menu` (`id`, `parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `component`, `remark`, `is_deleted`) VALUES (2075449200000000005, 2075449200000000001, 'cargo_type_delete', '删除', 'cargo_type_delete', '', '', 4, 2, 0, 1, NULL, '', 0); +INSERT INTO `blade_menu` (`id`, `parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `component`, `remark`, `is_deleted`) VALUES (2075449200000000006, 2075449200000000001, 'cargo_type_import', '批量导入', 'cargo_type_import', '', '', 5, 2, 0, 1, NULL, '', 0); +INSERT INTO `blade_menu` (`id`, `parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `component`, `remark`, `is_deleted`) VALUES (2075449200000000007, 2075449200000000001, 'cargo_type_template', '下载模板', 'cargo_type_template', '', '', 6, 2, 0, 1, NULL, '', 0); +INSERT INTO `blade_menu` (`id`, `parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `component`, `remark`, `is_deleted`) VALUES (2075449200000000008, 2075449200000000001, 'cargo_type_export', '批量导出', 'cargo_type_export', '', '', 7, 2, 0, 1, NULL, '', 0);