1、新增货物类型模块

2、新增导入失败,导出excel功能
This commit is contained in:
2026-07-27 11:50:23 +08:00
parent fd98744b46
commit f0b515c2e0
88 changed files with 1791 additions and 215 deletions

View File

@@ -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`,占位符传参(禁止字符串拼接)
- 包含关键业务标识,异常必须携带堆栈,禁止打印敏感信息

View File

@@ -22,6 +22,10 @@
<groupId>org.springblade</groupId>
<artifactId>blade-starter-loadbalancer</artifactId>
</dependency>
<dependency>
<groupId>cn.idev.excel</groupId>
<artifactId>fastexcel</artifactId>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-core-auto</artifactId>

View File

@@ -0,0 +1,132 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* 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 <T> 泛型
*/
public static <T> void export(HttpServletResponse response, String fileName, String sheetName, List<T> data, Class<T> 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<Field> excelFields = excelFields(excelClass);
List<List<String>> head = buildHead(excelFields);
List<List<Object>> 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<Field> 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<List<String>> buildHead(List<Field> excelFields) {
List<List<String>> 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 <T> List<List<Object>> buildRows(List<T> data, List<Field> excelFields) {
List<List<Object>> rows = new ArrayList<>();
for (T item : data) {
List<Object> 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 "";
}
}
}

View File

@@ -0,0 +1,93 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* 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;
}

View File

@@ -0,0 +1,68 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* 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;
}

View File

@@ -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<AirportMasterExcel> 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("操作成功");
}

View File

@@ -0,0 +1,224 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* 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<CargoTypeVO> 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<IPage<CargoTypeVO>> list(CargoTypeVO cargoType, Query query) {
IPage<CargoTypeVO> pages = cargoTypeService.selectCargoTypePage(Condition.getPage(query), cargoType);
return R.data(pages);
}
/**
* 一级货物类型选项
*/
@GetMapping("/parent-options")
@ApiOperationSupport(order = 3)
@Operation(summary = "一级货物类型选项", description = "传入keyword")
public R<List<CargoTypeVO>> parentOptions(@RequestParam(required = false) String keyword) {
return R.data(cargoTypeService.parentOptions(keyword));
}
/**
* 二级货物类型建议编码
*/
@GetMapping("/next-code")
@ApiOperationSupport(order = 4)
@Operation(summary = "二级货物类型建议编码", description = "传入parentCargoCode")
public R<String> 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<CargoTypeExcel> data = ExcelUtil.read(file, CargoTypeExcel.class);
List<CargoTypeImportFailureExcel> 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<CargoTypeExportExcel> 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<CargoTypeExcel> list = new ArrayList<>();
ExcelUtil.export(response, "货物类型模板", "货物类型导入模板", list, CargoTypeExcel.class);
}
private LambdaQueryWrapper<CargoType> buildExportQuery(CargoTypeVO cargoType, String ids) {
LambdaQueryWrapper<CargoType> queryWrapper = Wrappers.<CargoType>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<String> 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;
}
}

View File

@@ -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<CurrencyExcel> 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("操作成功");
}

View File

@@ -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<PortTerminalExcel> 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("操作成功");
}

View File

@@ -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<RailwayStationExcel> 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("操作成功");
}

View File

@@ -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<RegionExcel> 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("操作成功");
}

View File

@@ -100,7 +100,7 @@ public class AirportMasterExcel implements Serializable {
@ExcelProperty("备注")
private String remark;
@ExcelProperty("报错文案")
@ExcelProperty
private String errorMessage;
}

View File

@@ -0,0 +1,72 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* 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;
}

View File

@@ -0,0 +1,78 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* 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;
}

View File

@@ -0,0 +1,71 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* 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;
}

View File

@@ -0,0 +1,49 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* 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<CargoTypeExcel> {
private final ICargoTypeService service;
@Override
public void save(List<CargoTypeExcel> data) {
service.importCargoType(data);
}
}

View File

@@ -77,7 +77,7 @@ public class CurrencyExcel implements Serializable {
@ExcelProperty("备注")
private String remark;
@ExcelProperty("报错文案")
@ExcelProperty
private String errorMessage;
}

View File

@@ -100,7 +100,7 @@ public class PortTerminalExcel implements Serializable {
@ExcelProperty("备注")
private String remark;
@ExcelProperty("报错文案")
@ExcelProperty
private String errorMessage;
}

View File

@@ -96,7 +96,7 @@ public class RailwayStationExcel implements Serializable {
@ExcelProperty("备注")
private String remark;
@ExcelProperty("报错文案")
@ExcelProperty
private String errorMessage;
}

View File

@@ -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;
}

View File

@@ -0,0 +1,52 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* 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<CargoType> {
/**
* 自定义分页
*
* @param page 分页参数
* @param cargoType 查询参数
* @return 货物类型分页
*/
List<CargoTypeVO> selectCargoTypePage(IPage<CargoTypeVO> page, @Param("cargoType") CargoTypeVO cargoType);
}

View File

@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.springblade.system.mapper.CargoTypeMapper">
<resultMap id="cargoTypeResultMap" type="org.springblade.system.pojo.vo.CargoTypeVO">
<result column="id" property="id"/>
<result column="create_user" property="createUser"/>
<result column="create_user_name" property="createUserName"/>
<result column="create_dept" property="createDept"/>
<result column="create_time" property="createTime"/>
<result column="update_user" property="updateUser"/>
<result column="update_user_name" property="updateUserName"/>
<result column="update_time" property="updateTime"/>
<result column="status" property="status"/>
<result column="is_deleted" property="isDeleted"/>
<result column="type_level" property="typeLevel"/>
<result column="type_level_name" property="typeLevelName"/>
<result column="parent_id" property="parentId"/>
<result column="parent_cargo_name" property="parentCargoName"/>
<result column="parent_cargo_code" property="parentCargoCode"/>
<result column="cargo_name" property="cargoName"/>
<result column="cargo_code" property="cargoCode"/>
<result column="data_source" property="dataSource"/>
<result column="remark" property="remark"/>
</resultMap>
<select id="selectCargoTypePage" resultMap="cargoTypeResultMap">
SELECT
ct.id,
ct.create_user,
cu.real_name AS create_user_name,
ct.create_dept,
ct.create_time,
ct.update_user,
uu.real_name AS update_user_name,
ct.update_time,
ct.status,
ct.is_deleted,
ct.type_level,
CASE ct.type_level WHEN 1 THEN '一级货物类型' WHEN 2 THEN '二级货物类型' ELSE '' END AS type_level_name,
ct.parent_id,
pct.cargo_name AS parent_cargo_name,
ct.parent_cargo_code,
ct.cargo_name,
ct.cargo_code,
ct.data_source,
ct.remark
FROM
blade_cargo_type ct
LEFT JOIN blade_cargo_type pct ON pct.id = ct.parent_id AND pct.is_deleted = 0
LEFT JOIN blade_user cu ON cu.id = ct.create_user
LEFT JOIN blade_user uu ON uu.id = ct.update_user
WHERE
ct.is_deleted = 0
<if test="cargoType.typeLevel != null">
AND ct.type_level = #{cargoType.typeLevel}
</if>
<if test="cargoType.cargoName != null and cargoType.cargoName != ''">
<bind name="cargoNameLike" value="'%' + cargoType.cargoName + '%'"/>
AND ct.cargo_name LIKE #{cargoNameLike}
</if>
<if test="cargoType.cargoCode != null and cargoType.cargoCode != ''">
<bind name="cargoCodeLike" value="'%' + cargoType.cargoCode + '%'"/>
AND ct.cargo_code LIKE #{cargoCodeLike}
</if>
<if test="cargoType.parentCargoName != null and cargoType.parentCargoName != ''">
<bind name="parentCargoNameLike" value="'%' + cargoType.parentCargoName + '%'"/>
AND pct.cargo_name LIKE #{parentCargoNameLike}
</if>
<if test="cargoType.parentCargoCode != null and cargoType.parentCargoCode != ''">
<bind name="parentCargoCodeLike" value="'%' + cargoType.parentCargoCode + '%'"/>
AND ct.parent_cargo_code LIKE #{parentCargoCodeLike}
</if>
ORDER BY ct.create_time DESC
</select>
</mapper>

View File

@@ -72,7 +72,7 @@ public interface IAirportMasterService extends BaseService<AirportMaster> {
*
* @param data 导入数据
*/
void importAirportMaster(List<AirportMasterExcel> data);
List<AirportMasterExcel> importAirportMaster(List<AirportMasterExcel> data);
/**
* 导出空港机场

View File

@@ -0,0 +1,103 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* 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<CargoType> {
/**
* 自定义分页
*
* @param page 分页参数
* @param cargoType 查询参数
* @return 货物类型分页
*/
IPage<CargoTypeVO> selectCargoTypePage(IPage<CargoTypeVO> page, CargoTypeVO cargoType);
/**
* 新增或修改货物类型
*
* @param cargoType 货物类型
* @return 是否成功
*/
boolean submit(CargoType cargoType);
/**
* 删除货物类型
*
* @param ids 主键集合
* @return 是否成功
*/
boolean deleteCargoTypes(List<Long> ids);
/**
* 一级货物类型选项
*
* @param keyword 关键字
* @return 一级货物类型列表
*/
List<CargoTypeVO> parentOptions(String keyword);
/**
* 获取二级货物类型建议编码
*
* @param parentCargoCode 上级货物类型编码
* @return 建议编码
*/
String nextChildCode(String parentCargoCode);
/**
* 导入货物类型
*
* @param data 导入数据
* @return 导入失败数据
*/
List<CargoTypeImportFailureExcel> importCargoType(List<CargoTypeExcel> data);
/**
* 导出货物类型
*
* @param queryWrapper 查询条件
* @return 导出数据
*/
List<CargoTypeExportExcel> exportCargoType(Wrapper<CargoType> queryWrapper);
}

View File

@@ -73,7 +73,7 @@ public interface ICurrencyService extends BaseService<Currency> {
*
* @param data 导入数据
*/
void importCurrency(List<CurrencyExcel> data);
List<CurrencyExcel> importCurrency(List<CurrencyExcel> data);
/**
* 导出币种汇率

View File

@@ -79,7 +79,7 @@ public interface IPortTerminalService extends BaseService<PortTerminal> {
*
* @param data 导入数据
*/
void importPortTerminal(List<PortTerminalExcel> data);
List<PortTerminalExcel> importPortTerminal(List<PortTerminalExcel> data);
/**
* 导出港口码头

View File

@@ -72,7 +72,7 @@ public interface IRailwayStationService extends BaseService<RailwayStation> {
*
* @param data 导入数据
*/
void importRailwayStation(List<RailwayStationExcel> data);
List<RailwayStationExcel> importRailwayStation(List<RailwayStationExcel> data);
/**
* 导出铁路车站

View File

@@ -82,7 +82,7 @@ public interface IRegionService extends IService<Region> {
* @param isCovered
* @return
*/
void importRegion(List<RegionExcel> data, Boolean isCovered);
List<RegionExcel> importRegion(List<RegionExcel> data, Boolean isCovered);
/**
* 导出区划数据

View File

@@ -119,11 +119,11 @@ public class AirportMasterServiceImpl extends BaseServiceImpl<AirportMasterMappe
@Override
@Transactional(rollbackFor = Exception.class)
public void importAirportMaster(List<AirportMasterExcel> data) {
public List<AirportMasterExcel> importAirportMaster(List<AirportMasterExcel> data) {
if (Func.isEmpty(data)) {
throw new ServiceException("导入数据不能为空");
}
List<String> errorList = new ArrayList<>();
List<AirportMasterExcel> 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<AirportMasterMappe
save(airportMaster);
} catch (Exception exception) {
String message = exception instanceof ServiceException ? exception.getMessage() : "导入失败";
errorList.add("" + (index + 2) + "行:" + message);
excel.setErrorMessage("" + (index + 2) + "行:" + message);
errorList.add(excel);
}
}
if (Func.isNotEmpty(errorList)) {
throw new ServiceException(String.join("", errorList));
}
return errorList;
}
@Override

View File

@@ -0,0 +1,384 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* 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<CargoTypeMapper, CargoType> 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<CargoTypeVO> selectCargoTypePage(IPage<CargoTypeVO> 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<Long> ids) {
if (Func.isEmpty(ids)) {
throw new ServiceException("请选择至少一条数据");
}
long childCount = count(Wrappers.<CargoType>lambdaQuery()
.in(CargoType::getParentId, ids)
.eq(CargoType::getIsDeleted, 0));
if (childCount > 0L) {
throw new ServiceException("存在下级货物类型,不能删除");
}
return deleteLogic(ids);
}
@Override
public List<CargoTypeVO> parentOptions(String keyword) {
String trimKeyword = trimToEmpty(keyword);
LambdaQueryWrapper<CargoType> queryWrapper = Wrappers.<CargoType>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.<CargoType>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<CargoTypeImportFailureExcel> importCargoType(List<CargoTypeExcel> data) {
if (Func.isEmpty(data)) {
throw new ServiceException("导入数据不能为空");
}
List<CargoTypeImportFailureExcel> 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<CargoTypeExportExcel> exportCargoType(Wrapper<CargoType> 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.<CargoType>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.<CargoType>lambdaQuery()
.eq(CargoType::getTypeLevel, TYPE_LEVEL_ONE)
.eq(CargoType::getCargoName, name)
.eq(CargoType::getIsDeleted, 0)
.last("limit 1"));
}
private void validateUniqueCode(CargoType cargoType) {
LambdaQueryWrapper<CargoType> queryWrapper = Wrappers.<CargoType>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<CargoType> queryWrapper = Wrappers.<CargoType>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;
}
}

View File

@@ -115,11 +115,11 @@ public class CurrencyServiceImpl extends BaseServiceImpl<CurrencyMapper, Currenc
}
@Override
public void importCurrency(List<CurrencyExcel> data) {
public List<CurrencyExcel> importCurrency(List<CurrencyExcel> data) {
if (Func.isEmpty(data)) {
throw new ServiceException("导入数据不能为空");
}
List<String> errorList = new ArrayList<>();
List<CurrencyExcel> 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<CurrencyMapper, Currenc
successCount++;
} catch (Exception exception) {
String message = exception instanceof ServiceException ? exception.getMessage() : "导入失败";
errorList.add("" + (index + 2) + "行:" + message);
excel.setErrorMessage("" + (index + 2) + "行:" + message);
errorList.add(excel);
}
}
if (Func.isNotEmpty(errorList)) {
throw new ServiceException("导入成功" + successCount + "条,失败" + errorList.size() + "条:" + String.join("", errorList));
}
return errorList;
}
@Override

View File

@@ -129,11 +129,11 @@ public class PortTerminalServiceImpl extends BaseServiceImpl<PortTerminalMapper,
@Override
@Transactional(rollbackFor = Exception.class)
public void importPortTerminal(List<PortTerminalExcel> data) {
public List<PortTerminalExcel> importPortTerminal(List<PortTerminalExcel> data) {
if (Func.isEmpty(data)) {
throw new ServiceException("导入数据不能为空");
}
List<String> errorList = new ArrayList<>();
List<PortTerminalExcel> 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<PortTerminalMapper,
save(portTerminal);
} catch (Exception exception) {
String message = exception instanceof ServiceException ? exception.getMessage() : "导入失败";
errorList.add("" + (index + 2) + "行:" + message);
excel.setErrorMessage("" + (index + 2) + "行:" + message);
errorList.add(excel);
}
}
if (Func.isNotEmpty(errorList)) {
throw new ServiceException(String.join("", errorList));
}
return errorList;
}
@Override

View File

@@ -122,11 +122,11 @@ public class RailwayStationServiceImpl extends BaseServiceImpl<RailwayStationMap
@Override
@Transactional(rollbackFor = Exception.class)
public void importRailwayStation(List<RailwayStationExcel> data) {
public List<RailwayStationExcel> importRailwayStation(List<RailwayStationExcel> data) {
if (Func.isEmpty(data)) {
throw new ServiceException("导入数据不能为空");
}
List<String> errorList = new ArrayList<>();
List<RailwayStationExcel> 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<RailwayStationMap
save(railwayStation);
} catch (Exception exception) {
String message = exception instanceof ServiceException ? exception.getMessage() : "导入失败";
errorList.add("" + (index + 2) + "行:" + message);
excel.setErrorMessage("" + (index + 2) + "行:" + message);
errorList.add(excel);
}
}
if (Func.isNotEmpty(errorList)) {
throw new ServiceException(String.join("", errorList));
}
return errorList;
}
@Override

View File

@@ -144,17 +144,26 @@ public class RegionServiceImpl extends ServiceImpl<RegionMapper, Region> impleme
}
@Override
public void importRegion(List<RegionExcel> data, Boolean isCovered) {
List<Region> 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<RegionExcel> importRegion(List<RegionExcel> data, Boolean isCovered) {
if (Func.isEmpty(data)) {
throw new ServiceException("导入数据不能为空");
}
List<RegionExcel> 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

View File

@@ -0,0 +1,57 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* 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<CargoType, CargoTypeVO> {
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;
}
}

View File

@@ -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<AccidentRecordExcel> 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("操作成功");
}

View File

@@ -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<AnnualInspectionRecordExcel> 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("操作成功");
}

View File

@@ -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<CreditScoreQuantificationExcel> 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("操作成功");
}

View File

@@ -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<EtcRecordExcel> 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("操作成功");
}

View File

@@ -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<InsuranceRecordExcel> 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("操作成功");
}

View File

@@ -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<MaintenancePlanExcel> 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("操作成功");
}

View File

@@ -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<MaintenanceRecordExcel> 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("操作成功");
}

View File

@@ -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<MileageRecordExcel> 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("操作成功");
}

View File

@@ -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<OilElectricRecordExcel> 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("操作成功");
}

View File

@@ -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<OtherExpenseRecordExcel> 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("操作成功");
}

View File

@@ -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<TireReplacementRecordExcel> 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("操作成功");
}

View File

@@ -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<TransportChangeRecordExcel> 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("操作成功");
}

View File

@@ -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<ViolationRecordExcel> 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("操作成功");
}

View File

@@ -86,7 +86,7 @@ public class AccidentRecordExcel implements Serializable {
@ExcelProperty("备注")
private String remark;
@ExcelProperty("报错文案")
@ExcelProperty
private String errorMessage;
}

View File

@@ -83,7 +83,7 @@ public class AnnualInspectionRecordExcel implements Serializable {
@ExcelProperty("备注")
private String remark;
@ExcelProperty("报错文案")
@ExcelProperty
private String errorMessage;
}

View File

@@ -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;
}

View File

@@ -58,7 +58,7 @@ public class EtcRecordExcel implements Serializable {
@ExcelProperty("备注")
private String remark;
@ExcelProperty("报错文案")
@ExcelProperty
private String errorMessage;
}

View File

@@ -86,7 +86,7 @@ public class InsuranceRecordExcel implements Serializable {
@ExcelProperty("备注")
private String remark;
@ExcelProperty("报错文案")
@ExcelProperty
private String errorMessage;
}

View File

@@ -100,7 +100,7 @@ public class MaintenancePlanExcel implements Serializable {
@ExcelProperty("备注")
private String remark;
@ExcelProperty("报错文案")
@ExcelProperty
private String errorMessage;
}

View File

@@ -101,7 +101,7 @@ public class MaintenanceRecordExcel implements Serializable {
@ExcelProperty("备注")
private String remark;
@ExcelProperty("报错文案")
@ExcelProperty
private String errorMessage;
}

View File

@@ -81,7 +81,7 @@ public class MileageRecordExcel implements Serializable {
@ExcelProperty("备注")
private String remark;
@ExcelProperty("报错文案")
@ExcelProperty
private String errorMessage;
}

View File

@@ -79,7 +79,7 @@ public class OilElectricRecordExcel implements Serializable {
@ExcelProperty("备注")
private String remark;
@ExcelProperty("报错文案")
@ExcelProperty
private String errorMessage;
}

View File

@@ -52,7 +52,7 @@ public class OtherExpenseRecordExcel implements Serializable {
@ExcelProperty("备注")
private String remark;
@ExcelProperty("报错文案")
@ExcelProperty
private String errorMessage;
}

View File

@@ -79,7 +79,7 @@ public class TireReplacementRecordExcel implements Serializable {
@ExcelProperty("备注")
private String remark;
@ExcelProperty("报错文案")
@ExcelProperty
private String errorMessage;
}

View File

@@ -66,7 +66,7 @@ public class TransportChangeRecordExcel implements Serializable {
@ExcelProperty("备注")
private String remark;
@ExcelProperty("报错文案")
@ExcelProperty
private String errorMessage;
}

View File

@@ -89,7 +89,7 @@ public class ViolationRecordExcel implements Serializable {
@ExcelProperty("处理结果")
private String processResult;
@ExcelProperty("报错文案")
@ExcelProperty
private String errorMessage;
}

View File

@@ -63,7 +63,7 @@ public interface IAccidentRecordService extends BaseService<AccidentRecord> {
*
* @param data 导入数据
*/
void importAccidentRecord(List<AccidentRecordExcel> data);
List<AccidentRecordExcel> importAccidentRecord(List<AccidentRecordExcel> data);
/**
* 导出事故记录

View File

@@ -45,7 +45,7 @@ public interface IAnnualInspectionRecordService extends BaseService<AnnualInspec
boolean submit(AnnualInspectionRecord annualInspectionRecord);
void importAnnualInspectionRecord(List<AnnualInspectionRecordExcel> data);
List<AnnualInspectionRecordExcel> importAnnualInspectionRecord(List<AnnualInspectionRecordExcel> data);
List<AnnualInspectionRecordExcel> exportAnnualInspectionRecord(Wrapper<AnnualInspectionRecord> queryWrapper);

View File

@@ -95,8 +95,9 @@ public interface ICreditScoreQuantificationService extends BaseService<CreditSco
* 导入评分量化表
*
* @param data 导入数据
* @return 导入失败数据
*/
void importCreditScoreQuantification(List<CreditScoreQuantificationExcel> data);
List<CreditScoreQuantificationExcel> importCreditScoreQuantification(List<CreditScoreQuantificationExcel> data);
/**
* 导出评分量化表

View File

@@ -26,7 +26,7 @@ public interface IEtcRecordService extends BaseService<EtcRecord> {
boolean submit(EtcRecord etcRecord);
void importEtcRecord(List<EtcRecordExcel> data);
List<EtcRecordExcel> importEtcRecord(List<EtcRecordExcel> data);
List<EtcRecordExcel> exportEtcRecord(Wrapper<EtcRecord> queryWrapper);

View File

@@ -64,7 +64,7 @@ public interface IInsuranceRecordService extends BaseService<InsuranceRecord> {
*
* @param data 导入数据
*/
void importInsuranceRecord(List<InsuranceRecordExcel> data);
List<InsuranceRecordExcel> importInsuranceRecord(List<InsuranceRecordExcel> data);
/**
* 导出保险记录

View File

@@ -63,7 +63,7 @@ public interface IMaintenancePlanService extends BaseService<MaintenancePlan> {
*
* @param data 导入数据
*/
void importMaintenancePlan(List<MaintenancePlanExcel> data);
List<MaintenancePlanExcel> importMaintenancePlan(List<MaintenancePlanExcel> data);
/**
* 导出保养记录

View File

@@ -63,7 +63,7 @@ public interface IMaintenanceRecordService extends BaseService<MaintenanceRecord
*
* @param data 导入数据
*/
void importMaintenanceRecord(List<MaintenanceRecordExcel> data);
List<MaintenanceRecordExcel> importMaintenanceRecord(List<MaintenanceRecordExcel> data);
/**
* 导出维修记录

View File

@@ -45,7 +45,7 @@ public interface IMileageRecordService extends BaseService<MileageRecord> {
boolean submit(MileageRecord mileageRecord);
void importMileageRecord(List<MileageRecordExcel> data);
List<MileageRecordExcel> importMileageRecord(List<MileageRecordExcel> data);
List<MileageRecordExcel> exportMileageRecord(Wrapper<MileageRecord> queryWrapper);

View File

@@ -26,7 +26,7 @@ public interface IOilElectricRecordService extends BaseService<OilElectricRecord
boolean submit(OilElectricRecord oilElectricRecord);
void importOilElectricRecord(List<OilElectricRecordExcel> data);
List<OilElectricRecordExcel> importOilElectricRecord(List<OilElectricRecordExcel> data);
List<OilElectricRecordExcel> exportOilElectricRecord(Wrapper<OilElectricRecord> queryWrapper);

View File

@@ -26,7 +26,7 @@ public interface IOtherExpenseRecordService extends BaseService<OtherExpenseReco
boolean submit(OtherExpenseRecord otherExpenseRecord);
void importOtherExpenseRecord(List<OtherExpenseRecordExcel> data);
List<OtherExpenseRecordExcel> importOtherExpenseRecord(List<OtherExpenseRecordExcel> data);
List<OtherExpenseRecordExcel> exportOtherExpenseRecord(Wrapper<OtherExpenseRecord> queryWrapper);

View File

@@ -63,7 +63,7 @@ public interface ITireReplacementRecordService extends BaseService<TireReplaceme
*
* @param data 导入数据
*/
void importTireReplacementRecord(List<TireReplacementRecordExcel> data);
List<TireReplacementRecordExcel> importTireReplacementRecord(List<TireReplacementRecordExcel> data);
/**
* 导出换胎记录

View File

@@ -45,7 +45,7 @@ public interface ITransportChangeRecordService extends BaseService<TransportChan
boolean submit(TransportChangeRecord transportChangeRecord);
void importTransportChangeRecord(List<TransportChangeRecordExcel> data);
List<TransportChangeRecordExcel> importTransportChangeRecord(List<TransportChangeRecordExcel> data);
List<TransportChangeRecordExcel> exportTransportChangeRecord(Wrapper<TransportChangeRecord> queryWrapper);

View File

@@ -63,7 +63,7 @@ public interface IViolationRecordService extends BaseService<ViolationRecord> {
*
* @param data 导入数据
*/
void importViolationRecord(List<ViolationRecordExcel> data);
List<ViolationRecordExcel> importViolationRecord(List<ViolationRecordExcel> data);
/**
* 导出违章记录

View File

@@ -77,22 +77,22 @@ public class AccidentRecordServiceImpl extends BaseServiceImpl<AccidentRecordMap
@Override
@Transactional(rollbackFor = Exception.class)
public void importAccidentRecord(List<AccidentRecordExcel> data) {
public List<AccidentRecordExcel> importAccidentRecord(List<AccidentRecordExcel> data) {
if (Func.isEmpty(data)) {
throw new ServiceException("导入数据不能为空");
}
List<String> errorList = new ArrayList<>();
List<AccidentRecordExcel> 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

View File

@@ -79,24 +79,23 @@ public class AnnualInspectionRecordServiceImpl extends BaseServiceImpl<AnnualIns
@Override
@Transactional(rollbackFor = Exception.class)
public void importAnnualInspectionRecord(List<AnnualInspectionRecordExcel> data) {
public List<AnnualInspectionRecordExcel> importAnnualInspectionRecord(List<AnnualInspectionRecordExcel> data) {
if (Func.isEmpty(data)) {
throw new ServiceException("导入数据不能为空");
}
List<String> errorList = new ArrayList<>();
List<AnnualInspectionRecordExcel> 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

View File

@@ -189,7 +189,7 @@ public class CreditScoreQuantificationServiceImpl extends BaseServiceImpl<Credit
@Override
@Transactional(rollbackFor = Exception.class)
public void importCreditScoreQuantification(List<CreditScoreQuantificationExcel> data) {
public List<CreditScoreQuantificationExcel> importCreditScoreQuantification(List<CreditScoreQuantificationExcel> data) {
if (Func.isEmpty(data)) {
throw new ServiceException("导入数据不能为空");
}
@@ -197,19 +197,19 @@ public class CreditScoreQuantificationServiceImpl extends BaseServiceImpl<Credit
.filter(row -> 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<String> errorList = new ArrayList<>();
List<CreditScoreQuantificationExcel> 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

View File

@@ -58,23 +58,23 @@ public class EtcRecordServiceImpl extends BaseServiceImpl<EtcRecordMapper, EtcRe
@Override
@Transactional(rollbackFor = Exception.class)
public void importEtcRecord(List<EtcRecordExcel> data) {
public List<EtcRecordExcel> importEtcRecord(List<EtcRecordExcel> data) {
if (Func.isEmpty(data)) {
throw new ServiceException("导入数据不能为空");
}
List<String> errorList = new ArrayList<>();
List<EtcRecordExcel> 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

View File

@@ -80,22 +80,22 @@ public class InsuranceRecordServiceImpl extends BaseServiceImpl<InsuranceRecordM
@Override
@Transactional(rollbackFor = Exception.class)
public void importInsuranceRecord(List<InsuranceRecordExcel> data) {
public List<InsuranceRecordExcel> importInsuranceRecord(List<InsuranceRecordExcel> data) {
if (Func.isEmpty(data)) {
throw new ServiceException("导入数据不能为空");
}
List<String> errorList = new ArrayList<>();
List<InsuranceRecordExcel> 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

View File

@@ -73,22 +73,22 @@ public class MaintenancePlanServiceImpl extends BaseServiceImpl<MaintenancePlanM
@Override
@Transactional(rollbackFor = Exception.class)
public void importMaintenancePlan(List<MaintenancePlanExcel> data) {
public List<MaintenancePlanExcel> importMaintenancePlan(List<MaintenancePlanExcel> data) {
if (Func.isEmpty(data)) {
throw new ServiceException("导入数据不能为空");
}
List<String> errorList = new ArrayList<>();
List<MaintenancePlanExcel> 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

View File

@@ -75,22 +75,22 @@ public class MaintenanceRecordServiceImpl extends BaseServiceImpl<MaintenanceRec
@Override
@Transactional(rollbackFor = Exception.class)
public void importMaintenanceRecord(List<MaintenanceRecordExcel> data) {
public List<MaintenanceRecordExcel> importMaintenanceRecord(List<MaintenanceRecordExcel> data) {
if (Func.isEmpty(data)) {
throw new ServiceException("导入数据不能为空");
}
List<String> errorList = new ArrayList<>();
List<MaintenanceRecordExcel> 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

View File

@@ -78,22 +78,22 @@ public class MileageRecordServiceImpl extends BaseServiceImpl<MileageRecordMappe
@Override
@Transactional(rollbackFor = Exception.class)
public void importMileageRecord(List<MileageRecordExcel> data) {
public List<MileageRecordExcel> importMileageRecord(List<MileageRecordExcel> data) {
if (Func.isEmpty(data)) {
throw new ServiceException("导入数据不能为空");
}
List<String> errorList = new ArrayList<>();
List<MileageRecordExcel> 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

View File

@@ -67,23 +67,23 @@ public class OilElectricRecordServiceImpl extends BaseServiceImpl<OilElectricRec
@Override
@Transactional(rollbackFor = Exception.class)
public void importOilElectricRecord(List<OilElectricRecordExcel> data) {
public List<OilElectricRecordExcel> importOilElectricRecord(List<OilElectricRecordExcel> data) {
if (Func.isEmpty(data)) {
throw new ServiceException("导入数据不能为空");
}
List<String> errorList = new ArrayList<>();
List<OilElectricRecordExcel> 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

View File

@@ -61,23 +61,23 @@ public class OtherExpenseRecordServiceImpl extends BaseServiceImpl<OtherExpenseR
@Override
@Transactional(rollbackFor = Exception.class)
public void importOtherExpenseRecord(List<OtherExpenseRecordExcel> data) {
public List<OtherExpenseRecordExcel> importOtherExpenseRecord(List<OtherExpenseRecordExcel> data) {
if (Func.isEmpty(data)) {
throw new ServiceException("导入数据不能为空");
}
List<String> errorList = new ArrayList<>();
List<OtherExpenseRecordExcel> 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

View File

@@ -75,22 +75,22 @@ public class TireReplacementRecordServiceImpl extends BaseServiceImpl<TireReplac
@Override
@Transactional(rollbackFor = Exception.class)
public void importTireReplacementRecord(List<TireReplacementRecordExcel> data) {
public List<TireReplacementRecordExcel> importTireReplacementRecord(List<TireReplacementRecordExcel> data) {
if (Func.isEmpty(data)) {
throw new ServiceException("导入数据不能为空");
}
List<String> errorList = new ArrayList<>();
List<TireReplacementRecordExcel> 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

View File

@@ -78,22 +78,22 @@ public class TransportChangeRecordServiceImpl extends BaseServiceImpl<TransportC
@Override
@Transactional(rollbackFor = Exception.class)
public void importTransportChangeRecord(List<TransportChangeRecordExcel> data) {
public List<TransportChangeRecordExcel> importTransportChangeRecord(List<TransportChangeRecordExcel> data) {
if (Func.isEmpty(data)) {
throw new ServiceException("导入数据不能为空");
}
List<String> errorList = new ArrayList<>();
List<TransportChangeRecordExcel> 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

View File

@@ -82,24 +82,23 @@ public class ViolationRecordServiceImpl extends BaseServiceImpl<ViolationRecordM
@Override
@Transactional(rollbackFor = Exception.class)
public void importViolationRecord(List<ViolationRecordExcel> data) {
public List<ViolationRecordExcel> importViolationRecord(List<ViolationRecordExcel> data) {
if (Func.isEmpty(data)) {
throw new ServiceException("导入数据不能为空");
}
List<String> errorList = new ArrayList<>();
List<ViolationRecordExcel> 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

View File

@@ -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);