feat:完善计量单位管理
This commit is contained in:
@@ -19,4 +19,13 @@ public interface UnitErrorCodeConstants {
|
||||
ErrorCode UNT_INFO_NOT_EXISTS =
|
||||
new ErrorCode(1_010_000_004, "单位信息记录不存在");
|
||||
|
||||
ErrorCode UNIT_NOT_FOUND =
|
||||
new ErrorCode(1_010_000_005, "找不到单位: %s");
|
||||
|
||||
ErrorCode UNIT_CONVERSION_PATH_NOT_FOUND =
|
||||
new ErrorCode(1_010_000_006, "无法找到从单位 [%s] 到单位 [%s] 的转换路径,请检查单位是否属于同一量纲或配置转换规则");
|
||||
|
||||
ErrorCode UNIT_DIFFERENT_QUANTITY =
|
||||
new ErrorCode(1_010_000_007, "单位 [%s] 和单位 [%s] 不属于同一量纲,无法转换");
|
||||
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@ import com.zt.plat.module.unitmanagement.service.UnitConversion.UnitConversionSe
|
||||
@Validated
|
||||
public class UnitConversionController implements BusinessControllerMarker {
|
||||
|
||||
|
||||
@Resource
|
||||
private UnitConversionService unitConversionService;
|
||||
|
||||
@@ -105,4 +104,54 @@ public class UnitConversionController implements BusinessControllerMarker {
|
||||
BeanUtils.toBean(list, UnitConversionRespVO.class));
|
||||
}
|
||||
|
||||
@PostMapping("/convert")
|
||||
@Operation(summary = "单位转换")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unit-conversion:query')")
|
||||
public CommonResult<UnitConvertRespVO> convert(@Valid @RequestBody UnitConvertReqVO convertReqVO) {
|
||||
return success(unitConversionService.convert(convertReqVO));
|
||||
}
|
||||
|
||||
@PostMapping("/batch-convert")
|
||||
@Operation(summary = "批量单位转换")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unit-conversion:query')")
|
||||
public CommonResult<BatchUnitConvertRespVO> batchConvert(@Valid @RequestBody BatchUnitConvertReqVO batchReqVO) {
|
||||
return success(unitConversionService.batchConvert(batchReqVO));
|
||||
}
|
||||
|
||||
@PostMapping("/convert-by-symbol")
|
||||
@Operation(summary = "按单位符号转换")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unit-conversion:query')")
|
||||
public CommonResult<UnitConvertRespVO> convertBySymbol(@Valid @RequestBody UnitConvertBySymbolReqVO reqVO) {
|
||||
return success(unitConversionService.convertBySymbol(reqVO));
|
||||
}
|
||||
|
||||
@PostMapping("/convert-by-name")
|
||||
@Operation(summary = "按单位名称转换")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unit-conversion:query')")
|
||||
public CommonResult<UnitConvertRespVO> convertByName(@Valid @RequestBody UnitConvertByNameReqVO reqVO) {
|
||||
return success(unitConversionService.convertByName(reqVO));
|
||||
}
|
||||
|
||||
@PostMapping("/batch-convert-by-symbol")
|
||||
@Operation(summary = "批量按单位符号转换")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unit-conversion:query')")
|
||||
public CommonResult<BatchUnitConvertRespVO> batchConvertBySymbol(@Valid @RequestBody BatchUnitConvertBySymbolReqVO reqVO) {
|
||||
return success(unitConversionService.batchConvertBySymbol(reqVO));
|
||||
}
|
||||
|
||||
@PostMapping("/batch-convert-by-name")
|
||||
@Operation(summary = "批量按单位名称转换")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unit-conversion:query')")
|
||||
public CommonResult<BatchUnitConvertRespVO> batchConvertByName(@Valid @RequestBody BatchUnitConvertByNameReqVO reqVO) {
|
||||
return success(unitConversionService.batchConvertByName(reqVO));
|
||||
}
|
||||
|
||||
@GetMapping("/validate-paths")
|
||||
@Operation(summary = "校验量纲的转换路径")
|
||||
@Parameter(name = "quantityId", description = "量纲ID", required = true, example = "1")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unit-conversion:query')")
|
||||
public CommonResult<UnitConversionValidationRespVO> validateConversionPaths(@RequestParam("quantityId") Long quantityId) {
|
||||
return success(unitConversionService.validateConversionPaths(quantityId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.zt.plat.module.unitmanagement.controller.admin.UnitConversion.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "管理后台 - 批量按名称单位转换 Request VO")
|
||||
@Data
|
||||
public class BatchUnitConvertByNameReqVO {
|
||||
|
||||
@Schema(description = "源单位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "千克")
|
||||
@NotBlank(message = "源单位名称不能为空")
|
||||
private String srcUnitName;
|
||||
|
||||
@Schema(description = "目标单位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "吨")
|
||||
@NotBlank(message = "目标单位名称不能为空")
|
||||
private String tgtUnitName;
|
||||
|
||||
@Schema(description = "待转换的值列表", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "待转换的值列表不能为空")
|
||||
private List<BigDecimal> values;
|
||||
|
||||
@Schema(description = "精度(小数位数)", example = "6")
|
||||
private Integer precision = 6;
|
||||
|
||||
@Schema(description = "是否忽略错误(true:遇到错误继续执行, false:遇到错误立即停止)", example = "false")
|
||||
private Boolean ignoreErrors = false;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.zt.plat.module.unitmanagement.controller.admin.UnitConversion.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "管理后台 - 批量按符号单位转换 Request VO")
|
||||
@Data
|
||||
public class BatchUnitConvertBySymbolReqVO {
|
||||
|
||||
@Schema(description = "源单位符号", requiredMode = Schema.RequiredMode.REQUIRED, example = "m")
|
||||
@NotBlank(message = "源单位符号不能为空")
|
||||
private String srcUnitSymbol;
|
||||
|
||||
@Schema(description = "目标单位符号", requiredMode = Schema.RequiredMode.REQUIRED, example = "km")
|
||||
@NotBlank(message = "目标单位符号不能为空")
|
||||
private String tgtUnitSymbol;
|
||||
|
||||
@Schema(description = "待转换的值列表", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "待转换的值列表不能为空")
|
||||
private List<BigDecimal> values;
|
||||
|
||||
@Schema(description = "精度(小数位数)", example = "6")
|
||||
private Integer precision = 6;
|
||||
|
||||
@Schema(description = "是否忽略错误(true:遇到错误继续执行, false:遇到错误立即停止)", example = "false")
|
||||
private Boolean ignoreErrors = false;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.zt.plat.module.unitmanagement.controller.admin.UnitConversion.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "管理后台 - 批量单位转换 Request VO")
|
||||
@Data
|
||||
public class BatchUnitConvertReqVO {
|
||||
|
||||
@Schema(description = "转换项列表", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "转换项列表不能为空")
|
||||
private List<UnitConvertReqVO> items;
|
||||
|
||||
@Schema(description = "是否忽略错误(true:遇到错误继续执行, false:遇到错误立即停止)", example = "false")
|
||||
private Boolean ignoreErrors = false;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.zt.plat.module.unitmanagement.controller.admin.UnitConversion.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.Builder;
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "管理后台 - 批量单位转换 Response VO")
|
||||
@Data
|
||||
@Builder
|
||||
public class BatchUnitConvertRespVO {
|
||||
|
||||
@Schema(description = "转换结果列表")
|
||||
private List<UnitConvertResultItem> results;
|
||||
|
||||
@Schema(description = "成功数量", example = "10")
|
||||
private Integer successCount;
|
||||
|
||||
@Schema(description = "失败数量", example = "0")
|
||||
private Integer failureCount;
|
||||
|
||||
@Schema(description = "总数量", example = "10")
|
||||
private Integer totalCount;
|
||||
|
||||
@Schema(description = "转换结果项")
|
||||
@Data
|
||||
@Builder
|
||||
public static class UnitConvertResultItem {
|
||||
|
||||
@Schema(description = "是否成功", example = "true")
|
||||
private Boolean success;
|
||||
|
||||
@Schema(description = "转换结果(成功时返回)")
|
||||
private UnitConvertRespVO data;
|
||||
|
||||
@Schema(description = "错误信息(失败时返回)", example = "找不到转换规则")
|
||||
private String errorMessage;
|
||||
|
||||
@Schema(description = "原始请求")
|
||||
private UnitConvertReqVO request;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,28 @@
|
||||
package com.zt.plat.module.unitmanagement.controller.admin.UnitConversion.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Schema(description = "管理后台 - 按名称单位转换 Request VO")
|
||||
@Data
|
||||
public class UnitConvertByNameReqVO {
|
||||
|
||||
@Schema(description = "源单位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "千克")
|
||||
@NotBlank(message = "源单位名称不能为空")
|
||||
private String srcUnitName;
|
||||
|
||||
@Schema(description = "目标单位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "吨")
|
||||
@NotBlank(message = "目标单位名称不能为空")
|
||||
private String tgtUnitName;
|
||||
|
||||
@Schema(description = "待转换的值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
|
||||
@NotNull(message = "待转换的值不能为空")
|
||||
private BigDecimal value;
|
||||
|
||||
@Schema(description = "精度(小数位数)", example = "6")
|
||||
private Integer precision = 6;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.zt.plat.module.unitmanagement.controller.admin.UnitConversion.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Schema(description = "管理后台 - 按符号单位转换 Request VO")
|
||||
@Data
|
||||
public class UnitConvertBySymbolReqVO {
|
||||
|
||||
@Schema(description = "源单位符号", requiredMode = Schema.RequiredMode.REQUIRED, example = "kg")
|
||||
@NotBlank(message = "源单位符号不能为空")
|
||||
private String srcUnitSymbol;
|
||||
|
||||
@Schema(description = "目标单位符号", requiredMode = Schema.RequiredMode.REQUIRED, example = "t")
|
||||
@NotBlank(message = "目标单位符号不能为空")
|
||||
private String tgtUnitSymbol;
|
||||
|
||||
@Schema(description = "待转换的值", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
|
||||
@NotNull(message = "待转换的值不能为空")
|
||||
private BigDecimal value;
|
||||
|
||||
@Schema(description = "精度(小数位数)", example = "6")
|
||||
private Integer precision = 6;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.zt.plat.module.unitmanagement.controller.admin.UnitConversion.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Schema(description = "管理后台 - 单位转换 Request VO")
|
||||
@Data
|
||||
public class UnitConvertReqVO {
|
||||
|
||||
@Schema(description = "源单位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "源单位ID不能为空")
|
||||
private Long srcUntId;
|
||||
|
||||
@Schema(description = "目标单位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@NotNull(message = "目标单位ID不能为空")
|
||||
private Long tgtUntId;
|
||||
|
||||
@Schema(description = "待转换的值", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
|
||||
@NotNull(message = "待转换的值不能为空")
|
||||
private BigDecimal value;
|
||||
|
||||
@Schema(description = "精度(小数位数)", example = "6")
|
||||
private Integer precision = 6;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user