This commit is contained in:
2026-08-25 16:15:19 +08:00
parent b8c210fb6b
commit 4e1a162660
27 changed files with 236 additions and 82 deletions
@@ -95,6 +95,20 @@ public class ImportFailureExcelUtil {
* @param excelClass 原导入 Excel 类型
*/
public static void export(HttpServletResponse response, String fileName, String sheetName, List<?> data, Class<?> excelClass) {
exportFailureReasonOnly(response, fileName, sheetName, data, excelClass);
}
/**
* 导出仅标红失败原因列的导入失败明细
*
* @param response 响应
* @param fileName 文件名
* @param sheetName 工作表名
* @param data 失败数据
* @param excelClass 原导入 Excel 类型
*/
public static void exportFailureReasonOnly(HttpServletResponse response, String fileName, String sheetName,
List<?> data, Class<?> excelClass) {
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
String encodeFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8);
@@ -104,7 +118,7 @@ public class ImportFailureExcelUtil {
List<List<Object>> rows = buildRows(data, excelFields);
try {
FastExcel.write(response.getOutputStream())
.registerWriteHandler(new ImportFailureCellStyleHandler(excelFields, rows))
.registerWriteHandler(new ImportFailureCellStyleHandler(excelFields.size()))
.head(head)
.sheet(sheetName)
.doWrite(rows);
@@ -182,44 +196,15 @@ public class ImportFailureExcelUtil {
throw new NoSuchFieldException(String.join(",", fieldNames));
}
private static String columnName(Field field) {
ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class);
String[] value = excelProperty.value();
return value.length == 0 ? field.getName() : value[0];
}
private static String normalize(String value) {
return value == null ? "" : value.replaceAll("[\\s*_:,。;;()()\\[\\]【】<>《》-]", "").toLowerCase();
}
private static List<String> columnKeywords(Field field) {
String columnName = columnName(field);
List<String> keywords = new ArrayList<>();
keywords.add(columnName);
keywords.add(field.getName());
keywords.addAll(Arrays.asList(columnName.replace("*", "").split("[//、()()\\s]+")));
return keywords.stream()
.map(ImportFailureExcelUtil::normalize)
.filter(keyword -> keyword.length() >= 2)
.distinct()
.toList();
}
private static class ImportFailureCellStyleHandler implements CellWriteHandler {
private final List<List<String>> columnKeywords;
private final List<List<Object>> rows;
private final int failureReasonColumnIndex;
private final Map<Short, CellStyle> redStyleCache = new HashMap<>();
private final Map<Short, CellStyle> noWrapStyleCache = new HashMap<>();
private final Map<Integer, Integer> columnWidthCache = new HashMap<>();
private ImportFailureCellStyleHandler(List<Field> excelFields, List<List<Object>> rows) {
this.columnKeywords = excelFields.stream()
.map(ImportFailureExcelUtil::columnKeywords)
.toList();
this.rows = rows;
this.failureReasonColumnIndex = excelFields.size();
private ImportFailureCellStyleHandler(int failureReasonColumnIndex) {
this.failureReasonColumnIndex = failureReasonColumnIndex;
}
@Override
@@ -237,25 +222,11 @@ public class ImportFailureExcelUtil {
return;
}
adjustColumnWidth(cell);
if (relativeRowIndex == null || relativeRowIndex < 0 || relativeRowIndex >= rows.size()) {
return;
}
if (shouldMarkRed(relativeRowIndex, cell.getColumnIndex())) {
if (cell.getColumnIndex() == failureReasonColumnIndex) {
markRed(cell);
}
}
private boolean shouldMarkRed(int rowIndex, int columnIndex) {
if (columnIndex == failureReasonColumnIndex) {
return true;
}
if (columnIndex < 0 || columnIndex >= columnKeywords.size()) {
return false;
}
String failureReason = normalize(String.valueOf(rows.get(rowIndex).get(failureReasonColumnIndex)));
return columnKeywords.get(columnIndex).stream().anyMatch(failureReason::contains);
}
private void markRed(Cell cell) {
CellStyle currentStyle = cell.getCellStyle();
CellStyle redStyle = redStyleCache.computeIfAbsent(currentStyle.getIndex(), styleIndex -> {
@@ -25,6 +25,7 @@
*/
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 io.swagger.v3.oas.annotations.media.Schema;
@@ -63,6 +64,7 @@ public class AirportMaster extends BaseEntity {
* ICAO代码
*/
@Schema(description = "ICAO代码")
@TableField(updateStrategy = FieldStrategy.ALWAYS)
private String icaoCode;
/**
* 机场标准名称
@@ -25,6 +25,8 @@
*/
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 io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@@ -62,5 +64,11 @@ public class FeeItem extends BaseEntity {
*/
@Schema(description = "费用项代码")
private String englishName;
/**
* 备注
*/
@Schema(description = "备注")
@TableField(updateStrategy = FieldStrategy.ALWAYS)
private String remark;
}
@@ -122,9 +122,11 @@ public class CustomerArchive extends TenantEntity {
private String customerLevel;
@Schema(description = "最大资金使用额度(万元)")
@TableField(updateStrategy = FieldStrategy.ALWAYS)
private BigDecimal maxCreditLimit;
@Schema(description = "申请总资金使用额度(万元)")
@TableField(updateStrategy = FieldStrategy.ALWAYS)
private BigDecimal applyCreditLimit;
@Schema(description = "备注")
@@ -158,7 +158,7 @@ public class AirportMasterController extends BladeController {
}
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);
org.springblade.common.excel.ImportFailureExcelUtil.exportFailureReasonOnly(response, "空港机场主数据导入失败明细" + DateUtil.time(), "导入失败明细", failureList, AirportMasterExcel.class);
return null;
}
return R.success("操作成功");
@@ -77,7 +77,11 @@ public class PortTerminalController extends BladeController {
private static final int DEFAULT_CURRENT = 1;
private static final int DEFAULT_SIZE = 10;
private static final int MAX_SIZE = 100;
private static final String SOURCE_INITIAL = "初始化";
private static final String SOURCE_INITIAL = "初始化";
private static final String SOURCE_INITIAL_IMPORT = "初始化导入";
private static final String SOURCE_INITIAL_OLD = "初始导入";
private static final String SOURCE_MANUAL = "手动录入";
private static final String SOURCE_MANUAL_OLD = "手工导入";
private final IPortTerminalService portTerminalService;
@@ -95,6 +99,7 @@ public class PortTerminalController extends BladeController {
if (Func.isEmpty(detail)) {
return R.fail("港口码头不存在");
}
detail.setDataSource(normalizeDataSource(detail.getDataSource()));
return R.data(PortTerminalWrapper.build().entityVO(detail));
}
@@ -150,7 +155,9 @@ public class PortTerminalController extends BladeController {
@ApiOperationSupport(order = 6)
@Operation(summary = "上级港口下拉数据源")
public R<List<PortTerminal>> portSelect() {
return R.data(portTerminalService.selectEnabledPorts());
List<PortTerminal> ports = portTerminalService.selectEnabledPorts();
ports.forEach(port -> port.setDataSource(normalizeDataSource(port.getDataSource())));
return R.data(ports);
}
/**
@@ -169,7 +176,7 @@ public class PortTerminalController extends BladeController {
}
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);
org.springblade.common.excel.ImportFailureExcelUtil.exportFailureReasonOnly(response, "港口码头主数据导入失败明细" + DateUtil.time(), "导入失败明细", failureList, PortTerminalExcel.class);
return null;
}
return R.success("操作成功");
@@ -237,10 +244,19 @@ public class PortTerminalController extends BladeController {
return;
}
if (SOURCE_INITIAL.equals(value)) {
queryWrapper.in("data_source", SOURCE_INITIAL, "初始导入");
queryWrapper.in("data_source", SOURCE_INITIAL, SOURCE_INITIAL_IMPORT, SOURCE_INITIAL_OLD);
} else if (SOURCE_MANUAL.equals(value)) {
queryWrapper.in("data_source", SOURCE_MANUAL, SOURCE_MANUAL_OLD);
} else {
queryWrapper.eq("data_source", value);
}
}
private String normalizeDataSource(String dataSource) {
if (SOURCE_INITIAL_IMPORT.equals(dataSource) || SOURCE_INITIAL_OLD.equals(dataSource)) {
return SOURCE_INITIAL;
}
return SOURCE_MANUAL_OLD.equals(dataSource) ? SOURCE_MANUAL : dataSource;
}
}
@@ -161,7 +161,7 @@ public class RailwayStationController extends BladeController {
}
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);
org.springblade.common.excel.ImportFailureExcelUtil.exportFailureReasonOnly(response, "铁路车站主数据导入失败明细" + DateUtil.time(), "导入失败明细", failureList, RailwayStationExcel.class);
return null;
}
return R.success("操作成功");
@@ -16,6 +16,7 @@
<result column="fee_category" property="feeCategory"/>
<result column="name" property="name"/>
<result column="english_name" property="englishName"/>
<result column="remark" property="remark"/>
</resultMap>
<select id="selectFeeItemPage" resultMap="feeItemResultMap">
@@ -54,7 +54,11 @@
pt.detail_address,
CASE WHEN pt.longitude BETWEEN -180 AND 180 THEN pt.longitude ELSE NULL END AS longitude,
CASE WHEN pt.latitude BETWEEN -90 AND 90 THEN pt.latitude ELSE NULL END AS latitude,
CASE WHEN pt.data_source = '初始导入' THEN '初始化导入' ELSE pt.data_source END AS data_source,
CASE
WHEN pt.data_source IN ('初始化导入', '初始导入') THEN '初始化录入'
WHEN pt.data_source = '手工导入' THEN '手动录入'
ELSE pt.data_source
END AS data_source,
pt.remark
FROM
blade_port_terminal pt
@@ -77,8 +81,11 @@
</if>
<if test="portTerminal.dataSource != null and portTerminal.dataSource != ''">
<choose>
<when test="portTerminal.dataSource == '初始化入'">
AND pt.data_source IN ('初始化导入', '初始导入')
<when test="portTerminal.dataSource == '初始化入'">
AND pt.data_source IN ('初始化录入', '初始化导入', '初始导入')
</when>
<when test="portTerminal.dataSource == '手动录入'">
AND pt.data_source IN ('手动录入', '手工导入')
</when>
<otherwise>
AND pt.data_source = #{portTerminal.dataSource}
@@ -181,7 +181,7 @@ public class AirportMasterServiceImpl extends BaseServiceImpl<AirportMasterMappe
private void normalizeImportAirportMaster(AirportMaster airportMaster) {
airportMaster.setIataCode(trimToEmpty(airportMaster.getIataCode()).toUpperCase(Locale.ROOT));
airportMaster.setCode(CODE_PREFIX + airportMaster.getIataCode());
airportMaster.setIcaoCode(trimToEmpty(airportMaster.getIcaoCode()).toUpperCase(Locale.ROOT));
airportMaster.setIcaoCode(normalizeOptionalCode(airportMaster.getIcaoCode()));
airportMaster.setName(trimToEmpty(airportMaster.getName()));
airportMaster.setShortName(trimToNull(airportMaster.getShortName()));
airportMaster.setProvinceCode(trimToNull(airportMaster.getProvinceCode()));
@@ -213,9 +213,7 @@ public class AirportMasterServiceImpl extends BaseServiceImpl<AirportMasterMappe
validateImportUnique(AirportMaster::getIataCode, airportMaster.getIataCode(), "该IATA编码已存在", validationErrors);
validateImportUnique(AirportMaster::getCode, airportMaster.getCode(), "该编码已存在", validationErrors);
}
if (Func.isEmpty(airportMaster.getIcaoCode())) {
addValidationError(validationErrors, "ICAO代码不能为空");
} else {
if (Func.isNotEmpty(airportMaster.getIcaoCode())) {
if (!ICAO_CODE_PATTERN.matcher(airportMaster.getIcaoCode()).matches()) {
addValidationError(validationErrors, "ICAO代码为4位大写字母");
}
@@ -234,6 +232,9 @@ public class AirportMasterServiceImpl extends BaseServiceImpl<AirportMasterMappe
validateImportLength(airportMaster.getCityName(), REGION_NAME_MAX_LENGTH, "所属城市不能超过128字", validationErrors);
validateImportLength(airportMaster.getDistrictName(), REGION_NAME_MAX_LENGTH, "所属区县不能超过128字", validationErrors);
validateImportLength(airportMaster.getRegionCode(), REGION_CODE_MAX_LENGTH, "行政区划编号不能超过32字", validationErrors);
if (Func.isEmpty(airportMaster.getDetailAddress())) {
addValidationError(validationErrors, "详细地址不能为空");
}
validateImportLength(airportMaster.getDetailAddress(), DETAIL_ADDRESS_MAX_LENGTH, "详细地址不能超过255字", validationErrors);
validateImportLength(airportMaster.getRemark(), REMARK_MAX_LENGTH, "备注不能超过200字", validationErrors);
if (Func.isEmpty(airportMaster.getLongitude())) {
@@ -328,7 +329,7 @@ public class AirportMasterServiceImpl extends BaseServiceImpl<AirportMasterMappe
private void prepare(AirportMaster airportMaster, String defaultDataSource) {
airportMaster.setIataCode(trimToEmpty(airportMaster.getIataCode()).toUpperCase(Locale.ROOT));
airportMaster.setCode(CODE_PREFIX + airportMaster.getIataCode());
airportMaster.setIcaoCode(trimToEmpty(airportMaster.getIcaoCode()).toUpperCase(Locale.ROOT));
airportMaster.setIcaoCode(normalizeOptionalCode(airportMaster.getIcaoCode()));
airportMaster.setName(trimToEmpty(airportMaster.getName()));
airportMaster.setShortName(trimToNull(airportMaster.getShortName()));
airportMaster.setProvinceCode(trimToNull(airportMaster.getProvinceCode()));
@@ -361,10 +362,7 @@ public class AirportMasterServiceImpl extends BaseServiceImpl<AirportMasterMappe
if (!IATA_CODE_PATTERN.matcher(airportMaster.getIataCode()).matches()) {
throw new ServiceException("IATA编码为3位大写字母");
}
if (Func.isEmpty(airportMaster.getIcaoCode())) {
throw new ServiceException("ICAO代码不能为空");
}
if (!ICAO_CODE_PATTERN.matcher(airportMaster.getIcaoCode()).matches()) {
if (Func.isNotEmpty(airportMaster.getIcaoCode()) && !ICAO_CODE_PATTERN.matcher(airportMaster.getIcaoCode()).matches()) {
throw new ServiceException("ICAO代码为4位大写字母");
}
if (Func.isEmpty(airportMaster.getName())) {
@@ -383,6 +381,9 @@ public class AirportMasterServiceImpl extends BaseServiceImpl<AirportMasterMappe
if (Func.isEmpty(airportMaster.getProvinceCode()) || Func.isEmpty(airportMaster.getCityCode()) || Func.isEmpty(airportMaster.getDistrictCode())) {
throw new ServiceException("请选择省份、城市和区县");
}
if (Func.isEmpty(airportMaster.getDetailAddress())) {
throw new ServiceException("详细地址不能为空");
}
validateCoordinate(airportMaster.getLongitude(), MIN_LONGITUDE, MAX_LONGITUDE, "经度");
validateCoordinate(airportMaster.getLatitude(), MIN_LATITUDE, MAX_LATITUDE, "纬度");
validateDataSource(airportMaster.getDataSource());
@@ -479,6 +480,9 @@ public class AirportMasterServiceImpl extends BaseServiceImpl<AirportMasterMappe
}
private void validateUnique(AirportMaster airportMaster, com.baomidou.mybatisplus.core.toolkit.support.SFunction<AirportMaster, ?> column, String value, String message) {
if (Func.isEmpty(value)) {
return;
}
LambdaQueryWrapper<AirportMaster> queryWrapper = Wrappers.<AirportMaster>lambdaQuery()
.eq(column, value)
.eq(AirportMaster::getIsDeleted, 0);
@@ -499,6 +503,11 @@ public class AirportMasterServiceImpl extends BaseServiceImpl<AirportMasterMappe
return trimValue.isEmpty() ? null : trimValue;
}
private String normalizeOptionalCode(String value) {
String normalizedValue = trimToNull(value);
return normalizedValue == null ? null : normalizedValue.toUpperCase(Locale.ROOT);
}
private String normalizeDataSource(String dataSource) {
String value = trimToEmpty(dataSource);
return SOURCE_MANUAL_OLD.equals(value) ? SOURCE_MANUAL : value;
@@ -62,6 +62,7 @@ public class FeeItemServiceImpl extends BaseServiceImpl<FeeItemMapper, FeeItem>
private static final int FEE_CATEGORY_MAX_LENGTH = 50;
private static final int NAME_MAX_LENGTH = 50;
private static final int ENGLISH_NAME_MAX_LENGTH = 100;
private static final int REMARK_MAX_LENGTH = 200;
@Override
public IPage<FeeItemVO> selectFeeItemPage(IPage<FeeItemVO> page, FeeItemVO feeItem) {
@@ -126,6 +127,7 @@ public class FeeItemServiceImpl extends BaseServiceImpl<FeeItemMapper, FeeItem>
feeItem.setFeeCategory(trimToEmpty(feeItem.getFeeCategory()));
feeItem.setName(trimToEmpty(feeItem.getName()));
feeItem.setEnglishName(trimToNull(feeItem.getEnglishName()));
feeItem.setRemark(trimToNull(feeItem.getRemark()));
appendFeeCategoryPrefix(feeItem);
if (Func.isEmpty(feeItem.getStatus())) {
feeItem.setStatus(STATUS_ENABLED);
@@ -151,6 +153,9 @@ public class FeeItemServiceImpl extends BaseServiceImpl<FeeItemMapper, FeeItem>
if (Func.isNotEmpty(feeItem.getEnglishName()) && feeItem.getEnglishName().length() > ENGLISH_NAME_MAX_LENGTH) {
throw new ServiceException("费用项代码不能超过100字");
}
if (Func.isNotEmpty(feeItem.getRemark()) && feeItem.getRemark().length() > REMARK_MAX_LENGTH) {
throw new ServiceException("备注不能超过200个字");
}
validateUniqueName(feeItem);
}
@@ -66,10 +66,12 @@ public class PortTerminalServiceImpl extends BaseServiceImpl<PortTerminalMapper,
private static final String CATEGORY_PORT = "港口";
private static final String CATEGORY_TERMINAL = "码头";
private static final String SOURCE_INITIAL = "初始化";
private static final String SOURCE_INITIAL = "初始化";
private static final String SOURCE_INITIAL_IMPORT = "初始化导入";
private static final String SOURCE_INITIAL_OLD = "初始导入";
private static final String SOURCE_BATCH = "批量导入";
private static final String SOURCE_MANUAL = "工导";
private static final String SOURCE_MANUAL = "动录";
private static final String SOURCE_MANUAL_OLD = "手工导入";
private static final int STATUS_ENABLED = 1;
private static final int STATUS_DISABLED = 2;
private static final int CODE_MAX_LENGTH = 30;
@@ -248,6 +250,9 @@ public class PortTerminalServiceImpl extends BaseServiceImpl<PortTerminalMapper,
validateImportLength(portTerminal.getCity(), REGION_MAX_LENGTH, "城市不能超过50字", validationErrors);
validateImportLength(portTerminal.getDistrictName(), REGION_MAX_LENGTH, "区县不能超过50字", validationErrors);
validateImportLength(portTerminal.getRegionCode(), REGION_CODE_MAX_LENGTH, "行政区划编码不能超过32字", validationErrors);
if (Func.isEmpty(portTerminal.getDetailAddress())) {
addValidationError(validationErrors, "详细地址不能为空");
}
validateImportLength(portTerminal.getDetailAddress(), DETAIL_ADDRESS_MAX_LENGTH, "详细地址不能超过255字", validationErrors);
validateImportLength(portTerminal.getRemark(), REMARK_MAX_LENGTH, "备注不能超过200个字", validationErrors);
if (Func.isEmpty(portTerminal.getLongitude())) {
@@ -471,6 +476,9 @@ public class PortTerminalServiceImpl extends BaseServiceImpl<PortTerminalMapper,
if (Func.isEmpty(portTerminal.getDistrictCode())) {
throw new ServiceException("区县不能为空");
}
if (Func.isEmpty(portTerminal.getDetailAddress())) {
throw new ServiceException("详细地址不能为空");
}
validateDataSource(portTerminal.getDataSource());
validateStatus(portTerminal.getStatus());
validateRange(portTerminal.getLongitude(), MIN_LONGITUDE, MAX_LONGITUDE, "经度范围为 -180 到 180");
@@ -523,7 +531,10 @@ public class PortTerminalServiceImpl extends BaseServiceImpl<PortTerminalMapper,
private String normalizeDataSource(String dataSource) {
String value = trimToEmpty(dataSource);
return SOURCE_INITIAL_OLD.equals(value) ? SOURCE_INITIAL : value;
if (SOURCE_INITIAL_IMPORT.equals(value) || SOURCE_INITIAL_OLD.equals(value)) {
return SOURCE_INITIAL;
}
return SOURCE_MANUAL_OLD.equals(value) ? SOURCE_MANUAL : value;
}
private void validateEnabledTerminal(Long parentId) {
@@ -251,6 +251,9 @@ public class RailwayStationServiceImpl extends BaseServiceImpl<RailwayStationMap
validateImportLength(railwayStation.getCityName(), REGION_NAME_MAX_LENGTH, "所属城市不能超过128字", validationErrors);
validateImportLength(railwayStation.getDistrictName(), REGION_NAME_MAX_LENGTH, "所属区县不能超过128字", validationErrors);
validateImportLength(railwayStation.getRegionCode(), REGION_CODE_MAX_LENGTH, "行政区划编号不能超过32字", validationErrors);
if (Func.isEmpty(railwayStation.getDetailAddress())) {
addValidationError(validationErrors, "详细地址不能为空");
}
validateImportLength(railwayStation.getDetailAddress(), DETAIL_ADDRESS_MAX_LENGTH, "详细地址不能超过255字", validationErrors);
validateImportLength(railwayStation.getRemark(), REMARK_MAX_LENGTH, "备注不能超过200字", validationErrors);
validateImportCoordinate(railwayStation.getLongitude(), MIN_LONGITUDE, MAX_LONGITUDE, "经度", validationErrors);
@@ -416,6 +419,9 @@ public class RailwayStationServiceImpl extends BaseServiceImpl<RailwayStationMap
if (Func.isEmpty(railwayStation.getDistrictCode())) {
throw new ServiceException("请选择所属区县");
}
if (Func.isEmpty(railwayStation.getDetailAddress())) {
throw new ServiceException("详细地址不能为空");
}
validateCoordinate(railwayStation.getLongitude(), MIN_LONGITUDE, MAX_LONGITUDE, "经度");
validateCoordinate(railwayStation.getLatitude(), MIN_LATITUDE, MAX_LATITUDE, "纬度");
validateDataSource(railwayStation.getDataSource());
@@ -46,6 +46,7 @@ import java.time.LocalDate;
import java.time.LocalDateTime;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -224,6 +225,7 @@ public class ContractManageServiceImpl extends BaseServiceImpl<ContractManageMap
BeanUtil.copyProperties(source, candidate);
candidate.setPartyB(TransportBusinessSupport.trimToNull(request.getPartyB()));
validateContractPartyCombinationUnique(candidate);
validateBillingPlans(request.getBillingPlanJson());
validatePaymentRatios(request.getPaymentRatioJson());
source.setContractName(request.getContractName()); source.setPartyB(request.getPartyB());
source.setStartDate(request.getStartDate()); source.setEndDate(request.getEndDate()); source.setContractFormat(request.getContractFormat());
@@ -464,9 +466,48 @@ public class ContractManageServiceImpl extends BaseServiceImpl<ContractManageMap
TransportBusinessSupport.validateRequired(contractManage.getContractCategory(), "请选择合同类别");
validateContractNameUnique(contractManage);
TransportBusinessSupport.validateLength(contractManage.getRemark(), 2000, "备注不能超过2000字");
validateBillingPlans(contractManage.getBillingPlanJson());
validatePaymentRatios(contractManage.getPaymentRatioJson());
}
private void validateBillingPlans(String billingPlanJson) {
if (Func.isEmpty(billingPlanJson)) {
return;
}
try {
Object parsed = JsonUtil.parse(billingPlanJson, List.class);
if (!(parsed instanceof List<?> plans)) {
throw new ServiceException("计费方案设置格式不正确");
}
Map<String, Integer> defaultPlanCount = new HashMap<>();
for (Object value : plans) {
if (!(value instanceof Map<?, ?> plan)) {
throw new ServiceException("计费方案设置格式不正确");
}
String transportMode = trimValue(plan.get("transportMode"));
if (isDefaultBillingPlan(plan)) {
int count = defaultPlanCount.merge(transportMode, 1, Integer::sum);
if (count > 1) {
throw new ServiceException("同一运输方式仅支持配置一个默认计费方案");
}
}
}
} catch (ServiceException exception) {
throw exception;
} catch (Exception exception) {
throw new ServiceException("计费方案设置格式不正确");
}
}
private boolean isDefaultBillingPlan(Map<?, ?> plan) {
Object value = plan.get("defaultPlan");
return Boolean.TRUE.equals(value) || "true".equalsIgnoreCase(String.valueOf(value)) || "1".equals(String.valueOf(value));
}
private String trimValue(Object value) {
return value == null ? null : TransportBusinessSupport.trimToNull(String.valueOf(value));
}
private void validatePaymentRatios(String paymentRatioJson) {
if (Func.isEmpty(paymentRatioJson)) return;
try {
@@ -173,8 +173,8 @@ public class CustomerArchiveServiceImpl extends BaseServiceImpl<CustomerArchiveM
if (created && result) {
grantNewCustomerToIncludedUsers(entity);
}
if (result) {
addChangeRecord(entity.getId(), created ? "新增客商档案" : "修改客商档案", before, entity, beforeDetail, customer);
if (result && !created) {
addChangeRecord(entity.getId(), "修改客商档案", before, entity, beforeDetail, customer);
}
return result;
}
@@ -297,6 +297,8 @@ public class CustomerArchiveServiceImpl extends BaseServiceImpl<CustomerArchiveM
customer.setBusinessScope(trimToNull(customer.getBusinessScope()));
customer.setInvoiceTaxRate(normalizeSentinelAmount(customer.getInvoiceTaxRate()));
customer.setRegisteredCapital(normalizeSentinelAmount(customer.getRegisteredCapital()));
customer.setMaxCreditLimit(normalizeSentinelAmount(customer.getMaxCreditLimit()));
customer.setApplyCreditLimit(normalizeSentinelAmount(customer.getApplyCreditLimit()));
customer.setRegisteredRegionName(trimToNull(customer.getRegisteredRegionName()));
customer.setRegisteredDetailAddress(trimToNull(customer.getRegisteredDetailAddress()));
customer.setRegisteredAddress(buildRegisteredAddress(customer));
@@ -486,6 +488,8 @@ public class CustomerArchiveServiceImpl extends BaseServiceImpl<CustomerArchiveM
continue;
}
Long scoreId = IdWorker.getId();
scoreVO.setMaxCreditLimit(normalizeSentinelAmount(scoreVO.getMaxCreditLimit()));
scoreVO.setApplyCreditLimit(normalizeSentinelAmount(scoreVO.getApplyCreditLimit()));
scoreVO.setTempApplyCreditLimit(normalizeOptionalScoreAmount(scoreVO.getTempApplyCreditLimit()));
scoreVO.setProofAttachments(normalizeScoreProofAttachments(scoreVO));
CustomerCreditScore score = Objects.requireNonNull(BeanUtil.copyProperties(scoreVO, CustomerCreditScore.class));
@@ -202,6 +202,10 @@ public class FormalSettlementServiceImpl extends BaseServiceImpl<FormalSettlemen
PreSettlement first = sources.isEmpty() ? null : sources.get(0);
ContractManage contract = contractManageService.getById(contractId);
if (contract == null || Objects.equals(contract.getIsDeleted(), 1)) throw new ServiceException("合同不存在");
if (!List.of("approved", "change_approved").contains(contract.getApprovalStatus())
|| "terminated".equals(contract.getContractStage())) {
throw new ServiceException("合同未审核完成,不可转正式结算单");
}
if (settlement.getId() == null) {
settlement.setFormalSettlementNo(nextNo());
settlement.setApprovalStatus(DRAFT);
@@ -431,6 +431,7 @@ public class ReceivablePayableDetailServiceImpl
throw new ServiceException("存在无效的费用明细");
}
validateTransferDetails(details);
validateSettlementContract(details.get(0).getContractId());
List<Long> detailIds = details.stream().map(ReceivablePayableDetail::getId).toList();
ReceivablePayableDetail first = details.get(0);
if ("pre".equals(request.getSettlementBillType())) {
@@ -475,7 +476,12 @@ public class ReceivablePayableDetailServiceImpl
query.setSettlementType(Func.isEmpty(settlementType) ? null : settlementType(settlementType));
query.setGenerateStartDate(parseDate(generateStartDate));
query.setGenerateEndDate(parseDate(generateEndDate));
List<Long> availableContractIds = settlementContractIds();
if (availableContractIds.isEmpty()) {
return new Page<>(page.getCurrent(), page.getSize(), 0);
}
LambdaQueryWrapper<ReceivablePayableDetail> wrapper = buildQuery(query)
.in(ReceivablePayableDetail::getContractId, availableContractIds)
.and(item -> item.isNull(ReceivablePayableDetail::getPreSettlementNo)
.or().eq(ReceivablePayableDetail::getPreSettlementNo, ""))
.and(item -> item.isNull(ReceivablePayableDetail::getFormalSettlementNo)
@@ -488,6 +494,24 @@ public class ReceivablePayableDetailServiceImpl
return result;
}
private List<Long> settlementContractIds() {
return contractManageService.list(Wrappers.<ContractManage>lambdaQuery()
.select(ContractManage::getId)
.eq(ContractManage::getIsDeleted, 0)
.in(ContractManage::getApprovalStatus, "approved", "change_approved")
.ne(ContractManage::getContractStage, "terminated"))
.stream().map(ContractManage::getId).toList();
}
private void validateSettlementContract(Long contractId) {
ContractManage contract = contractId == null ? null : contractManageService.getById(contractId);
if (contract == null || Objects.equals(contract.getIsDeleted(), 1)
|| !List.of("approved", "change_approved").contains(contract.getApprovalStatus())
|| "terminated".equals(contract.getContractStage())) {
throw new ServiceException("合同未审核完成,不可转预结算单或正式结算单");
}
}
@Override
public IPage<Map<String, Object>> generateWaybills(IPage<?> page, ReceivablePayableGenerateRequest request) {
validateGenerateRequest(request, false);
@@ -640,7 +664,6 @@ public class ReceivablePayableDetailServiceImpl
.eq(ContractManage::getPartyA, customerContract.getPartyA())
.eq(ContractManage::getPartyB, waybill.getCarrierName())
.eq(ContractManage::getContractCategory, "承运商合同")
.in(ContractManage::getApprovalStatus, "approved", "change_approved")
.and(wrapper -> wrapper.isNull(ContractManage::getContractStage)
.or().ne(ContractManage::getContractStage, "terminated"))
.orderByDesc(ContractManage::getCreateTime), false);
@@ -767,7 +790,7 @@ public class ReceivablePayableDetailServiceImpl
private String matchedPlanId(Waybill waybill, ContractManage contract) {
List<Map<String, Object>> plans = parseList(contract.getBillingPlanJson());
if (plans.isEmpty()) return null;
Map<String, Object> plan = plans.stream().filter(this::isDefaultPlan).findFirst().orElse(null);
Map<String, Object> plan = resolveDefaultBillingPlan(plans, waybill.getTransportType());
if (plan == null) return null;
if (!(plan.get("rules") instanceof List<?> rules)) return null;
boolean matched = rules.stream().anyMatch(value -> value instanceof Map<?, ?> raw && matchesRule(raw, waybill));
@@ -1149,7 +1172,9 @@ public class ReceivablePayableDetailServiceImpl
private List<ReceivablePayableCargoFee> calculatedFees(Waybill waybill, ContractManage contract, String planId, boolean matchOnly) {
List<Map<String, Object>> plans = parseList(contract == null ? null : contract.getBillingPlanJson());
Map<String, Object> plan = resolveBillingPlan(plans, planId);
Map<String, Object> plan = "__matched__".equals(planId)
? resolveDefaultBillingPlan(plans, waybill.getTransportType())
: resolveBillingPlan(plans, planId);
return calculatedFees(waybill, plan, matchOnly);
}
@@ -1298,7 +1323,17 @@ public class ReceivablePayableDetailServiceImpl
private boolean isDefaultPlan(Map<String, Object> plan) {
Object value = plan.get("defaultPlan");
return Boolean.TRUE.equals(value) || "true".equalsIgnoreCase(String.valueOf(value));
return Boolean.TRUE.equals(value) || "true".equalsIgnoreCase(String.valueOf(value)) || "1".equals(String.valueOf(value));
}
private Map<String, Object> resolveDefaultBillingPlan(List<Map<String, Object>> plans, String transportType) {
return plans.stream().filter(this::isDefaultPlan)
.filter(plan -> !isBlank(plan.get("transportMode")))
.filter(plan -> matchesCondition(plan.get("transportMode"), transportType))
.findFirst()
.orElseGet(() -> plans.stream().filter(this::isDefaultPlan)
.filter(plan -> isBlank(plan.get("transportMode")))
.findFirst().orElse(null));
}
private BigDecimal calculateRule(Map<String, Object> rule, Waybill waybill) {
+3 -2
View File
@@ -1505,7 +1505,7 @@ CREATE TABLE `blade_port_terminal` (
`detail_address` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '详细地址',
`longitude` decimal(12,6) NULL DEFAULT NULL COMMENT '经度',
`latitude` decimal(12,6) NULL DEFAULT NULL COMMENT '纬度',
`data_source` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '工导' COMMENT '数据来源',
`data_source` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '动录' 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 '创建部门',
@@ -1594,7 +1594,7 @@ CREATE TABLE `blade_airport_master` (
`id` bigint NOT NULL COMMENT '主键',
`code` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '编码',
`iata_code` varchar(3) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'IATA编码',
`icao_code` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'ICAO代码',
`icao_code` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT 'ICAO代码',
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '机场标准名称',
`short_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '机场简称',
`province_code` varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '所属省份编码',
@@ -1719,6 +1719,7 @@ CREATE TABLE `blade_fee_item` (
`fee_category` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '费用类型',
`name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '费用项',
`english_name` varchar(100) 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 '创建时间',
+1 -1
View File
@@ -6,7 +6,7 @@ CREATE TABLE `blade_airport_master` (
`id` bigint NOT NULL COMMENT '主键',
`code` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '编码',
`iata_code` varchar(3) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'IATA编码',
`icao_code` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'ICAO代码',
`icao_code` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT 'ICAO代码',
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '机场标准名称',
`short_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '机场简称',
`province_code` varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '所属省份编码',
@@ -0,0 +1,8 @@
-- 空港机场 ICAO 代码调整为非必填;唯一索引允许存在多条 NULL 数据
ALTER TABLE `blade_airport_master`
MODIFY COLUMN `icao_code` varchar(4) DEFAULT NULL COMMENT 'ICAO代码';
UPDATE `blade_airport_master`
SET `icao_code` = NULL
WHERE TRIM(`icao_code`) = '';
@@ -0,0 +1,5 @@
-- 合同计费方案运输方式存储于 billing_plan_json,无需新增表字段。
-- 新增/编辑接口会校验同一运输方式至多一个默认计费方案。
-- 历史计费方案的 transportMode 为空时继续兼容,编辑时可补充运输方式。
ALTER TABLE blade_contract_manage
MODIFY COLUMN billing_plan_json text DEFAULT NULL COMMENT '计费方案JSON(含运输方式及默认方案配置)';
+1
View File
@@ -7,6 +7,7 @@ CREATE TABLE `blade_fee_item` (
`fee_category` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '费用类型',
`name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '费用项',
`english_name` varchar(100) 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 '创建时间',
@@ -0,0 +1,4 @@
-- 费用项新增备注字段
ALTER TABLE `blade_fee_item`
ADD COLUMN `remark` varchar(200) DEFAULT NULL COMMENT '备注' AFTER `english_name`;
+1 -1
View File
@@ -17,7 +17,7 @@ CREATE TABLE `blade_port_terminal` (
`detail_address` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '详细地址',
`longitude` decimal(12,6) NULL DEFAULT NULL COMMENT '经度',
`latitude` decimal(12,6) NULL DEFAULT NULL COMMENT '纬度',
`data_source` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '工导' COMMENT '数据来源',
`data_source` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '动录' 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 '创建部门',
@@ -0,0 +1,12 @@
-- 港口码头数据来源枚举统一为:初始化录入、批量导入、手动录入
ALTER TABLE `blade_port_terminal`
MODIFY COLUMN `data_source` varchar(20) DEFAULT '手动录入' COMMENT '数据来源';
UPDATE `blade_port_terminal`
SET `data_source` = CASE
WHEN `data_source` IN ('初始导入', '初始化导入') THEN '初始化录入'
WHEN `data_source` = '手工导入' THEN '手动录入'
ELSE `data_source`
END
WHERE `data_source` IN ('初始导入', '初始化导入', '手工导入');
@@ -142,7 +142,7 @@ CREATE TABLE `blade_contract_manage` (
`billing_enabled` int(11) DEFAULT '0' COMMENT '计费信息开关',
`contract_file_json` text DEFAULT NULL COMMENT '合同主文件JSON',
`attachments_json` text DEFAULT NULL COMMENT '其它附件JSON',
`billing_plan_json` text DEFAULT NULL COMMENT '计费方案JSON',
`billing_plan_json` text DEFAULT NULL COMMENT '计费方案JSON(含运输方式及默认方案配置)',
`settlement_rule_json` text DEFAULT NULL COMMENT '结算生成规则JSON',
`reconciliation_json` text DEFAULT NULL COMMENT '对账配置JSON',
`change_record_json` text DEFAULT NULL COMMENT '变更记录JSON',
+4 -3
View File
@@ -25,7 +25,7 @@ CREATE TABLE `blade_airport_master` (
`id` bigint(20) NOT NULL COMMENT '主键',
`code` varchar(20) NOT NULL COMMENT '编码',
`iata_code` varchar(3) NOT NULL COMMENT 'IATA编码',
`icao_code` varchar(4) NOT NULL COMMENT 'ICAO代码',
`icao_code` varchar(4) DEFAULT NULL COMMENT 'ICAO代码',
`name` varchar(100) NOT NULL COMMENT '机场标准名称',
`short_name` varchar(100) DEFAULT NULL COMMENT '机场简称',
`province_code` varchar(12) DEFAULT NULL COMMENT '所属省份编码',
@@ -134,6 +134,7 @@ CREATE TABLE `blade_fee_item` (
`fee_category` varchar(50) NOT NULL COMMENT '费用类型',
`name` varchar(50) NOT NULL COMMENT '费用项',
`english_name` varchar(100) DEFAULT NULL COMMENT '费用项代码',
`remark` varchar(200) DEFAULT NULL COMMENT '备注',
`create_user` bigint(20) DEFAULT NULL COMMENT '创建人',
`create_dept` bigint(20) DEFAULT NULL COMMENT '创建部门',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
@@ -1323,7 +1324,7 @@ CREATE TABLE `blade_port_terminal` (
`detail_address` varchar(255) DEFAULT NULL COMMENT '详细地址',
`longitude` decimal(12,6) DEFAULT NULL COMMENT '经度',
`latitude` decimal(12,6) DEFAULT NULL COMMENT '纬度',
`data_source` varchar(20) DEFAULT '工导' COMMENT '数据来源',
`data_source` varchar(20) DEFAULT '动录' COMMENT '数据来源',
`remark` varchar(200) DEFAULT NULL COMMENT '备注',
`create_user` bigint(20) DEFAULT NULL COMMENT '创建人',
`create_dept` bigint(20) DEFAULT NULL COMMENT '创建部门',
@@ -1343,7 +1344,7 @@ CREATE TABLE `blade_port_terminal` (
-- Records of blade_port_terminal
-- ----------------------------
BEGIN;
INSERT INTO `blade_port_terminal` (`id`, `code`, `name`, `category`, `parent_id`, `parent_code`, `parent_name`, `country`, `city`, `longitude`, `latitude`, `data_source`, `remark`, `create_user`, `create_dept`, `create_time`, `update_user`, `update_time`, `status`, `is_deleted`) VALUES (2075434814939308033, 'TJGAS', '天津港', '港口', NULL, NULL, NULL, '天津市', '天津市', NULL, NULL, '工导', '', 1123598821738675201, 1123598813738675201, '2026-07-10 12:19:54', 1123598821738675201, '2026-07-10 12:19:54', 1, 0);
INSERT INTO `blade_port_terminal` (`id`, `code`, `name`, `category`, `parent_id`, `parent_code`, `parent_name`, `country`, `city`, `longitude`, `latitude`, `data_source`, `remark`, `create_user`, `create_dept`, `create_time`, `update_user`, `update_time`, `status`, `is_deleted`) VALUES (2075434814939308033, 'TJGAS', '天津港', '港口', NULL, NULL, NULL, '天津市', '天津市', NULL, NULL, '动录', '', 1123598821738675201, 1123598813738675201, '2026-07-10 12:19:54', 1123598821738675201, '2026-07-10 12:19:54', 1, 0);
COMMIT;
-- ----------------------------