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

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