update:移动计量单位管理模块位置
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package com.zt.plat.module.unitmanagement.enums;
|
||||
|
||||
import com.zt.plat.framework.common.exception.ErrorCode;
|
||||
|
||||
/**
|
||||
* unit-management 模块的错误码常量
|
||||
*/
|
||||
public interface UnitErrorCodeConstants {
|
||||
|
||||
ErrorCode QUANTITY_UNIT_RELATION_NOT_EXISTS =
|
||||
new ErrorCode(1_010_000_001, "计量单位量与单位关联不存在");
|
||||
|
||||
ErrorCode UNIT_CONVERSION_NOT_EXISTS =
|
||||
new ErrorCode(1_010_000_002, "单位转换记录不存在");
|
||||
|
||||
ErrorCode UNIT_QUANTITY_NOT_EXISTS =
|
||||
new ErrorCode(1_010_000_003, "单位数量记录不存在");
|
||||
|
||||
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] 不属于同一量纲,无法转换");
|
||||
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package com.zt.plat.module.base.controller.admin.quantityUnitRelation;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import com.zt.plat.framework.business.interceptor.BusinessControllerMarker;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import jakarta.validation.*;
|
||||
import jakarta.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.zt.plat.framework.common.pojo.vo.BatchDeleteReqVO;
|
||||
import com.zt.plat.framework.common.pojo.PageParam;
|
||||
import com.zt.plat.framework.common.pojo.PageResult;
|
||||
import com.zt.plat.framework.common.pojo.CommonResult;
|
||||
import com.zt.plat.framework.common.util.object.BeanUtils;
|
||||
import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import com.zt.plat.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import com.zt.plat.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import static com.zt.plat.framework.apilog.core.enums.OperateTypeEnum.*;
|
||||
|
||||
import com.zt.plat.module.base.controller.admin.quantityUnitRelation.vo.*;
|
||||
import com.zt.plat.module.base.dal.dataobject.quantityUnitRelation.QuantityUnitRelationDO;
|
||||
import com.zt.plat.module.base.service.quantityUnitRelation.QuantityUnitRelationService;
|
||||
|
||||
@Tag(name = "管理后台 - 计量单位量与单位关联")
|
||||
@RestController
|
||||
@RequestMapping("/base/unit-management/quantity-unit-relation")
|
||||
@Validated
|
||||
public class QuantityUnitRelationController implements BusinessControllerMarker {
|
||||
|
||||
|
||||
@Resource
|
||||
private QuantityUnitRelationService quantityUnitRelationService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建计量单位量与单位关联")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:quantity-unit-relation:create')")
|
||||
public CommonResult<QuantityUnitRelationRespVO> createQuantityUnitRelation(@Valid @RequestBody QuantityUnitRelationSaveReqVO createReqVO) {
|
||||
return success(quantityUnitRelationService.createQuantityUnitRelation(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新计量单位量与单位关联")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:quantity-unit-relation:update')")
|
||||
public CommonResult<Boolean> updateQuantityUnitRelation(@Valid @RequestBody QuantityUnitRelationSaveReqVO updateReqVO) {
|
||||
quantityUnitRelationService.updateQuantityUnitRelation(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除计量单位量与单位关联")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:quantity-unit-relation:delete')")
|
||||
public CommonResult<Boolean> deleteQuantityUnitRelation(@RequestParam("id") Long id) {
|
||||
quantityUnitRelationService.deleteQuantityUnitRelation(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除计量单位量与单位关联")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:quantity-unit-relation:delete')")
|
||||
public CommonResult<Boolean> deleteQuantityUnitRelationList(@RequestBody BatchDeleteReqVO req) {
|
||||
quantityUnitRelationService.deleteQuantityUnitRelationListByIds(req.getIds());
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得计量单位量与单位关联")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:quantity-unit-relation:query')")
|
||||
public CommonResult<QuantityUnitRelationRespVO> getQuantityUnitRelation(@RequestParam("id") Long id) {
|
||||
QuantityUnitRelationDO quantityUnitRelation = quantityUnitRelationService.getQuantityUnitRelation(id);
|
||||
return success(BeanUtils.toBean(quantityUnitRelation, QuantityUnitRelationRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得计量单位量与单位关联分页")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:quantity-unit-relation:query')")
|
||||
public CommonResult<PageResult<QuantityUnitRelationRespVO>> getQuantityUnitRelationPage(@Valid QuantityUnitRelationPageReqVO pageReqVO) {
|
||||
PageResult<QuantityUnitRelationDO> pageResult = quantityUnitRelationService.getQuantityUnitRelationPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, QuantityUnitRelationRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出计量单位量与单位关联 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:quantity-unit-relation:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportQuantityUnitRelationExcel(@Valid QuantityUnitRelationPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<QuantityUnitRelationDO> list = quantityUnitRelationService.getQuantityUnitRelationPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "计量单位量与单位关联.xls", "数据", QuantityUnitRelationRespVO.class,
|
||||
BeanUtils.toBean(list, QuantityUnitRelationRespVO.class));
|
||||
}
|
||||
|
||||
@PostMapping("/batch-save")
|
||||
@Operation(summary = "批量保存计量单位量与单位关联")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:quantity-unit-relation:create')")
|
||||
public CommonResult<Boolean> batchSaveQuantityUnitRelations(@Valid @RequestBody QuantityUnitRelationBatchSaveReqVO batchSaveReqVO) {
|
||||
quantityUnitRelationService.batchSaveQuantityUnitRelations(batchSaveReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/create-unit-with-relation")
|
||||
@Operation(summary = "创建单位并关联到量纲(组合接口)")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:quantity-unit-relation:create')")
|
||||
public CommonResult<QuantityUnitRelationRespVO> createUnitWithRelation(@Valid @RequestBody CreateUnitWithRelationReqVO createReqVO) {
|
||||
return success(quantityUnitRelationService.createUnitWithRelation(createReqVO));
|
||||
}
|
||||
|
||||
@PostMapping("/delete-unit-with-relation")
|
||||
@Operation(summary = "删除单位及关联关系(组合接口)")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:quantity-unit-relation:delete')")
|
||||
public CommonResult<Boolean> deleteUnitWithRelation(@Valid @RequestBody DeleteUnitWithRelationReqVO deleteReqVO) {
|
||||
quantityUnitRelationService.deleteUnitWithRelation(deleteReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.zt.plat.module.base.controller.admin.quantityUnitRelation.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 创建单位并关联到量纲 Request VO")
|
||||
@Data
|
||||
public class CreateUnitWithRelationReqVO {
|
||||
|
||||
@Schema(description = "量纲ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "量纲ID不能为空")
|
||||
private Long untQtyId;
|
||||
|
||||
@Schema(description = "单位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "米")
|
||||
@NotEmpty(message = "单位名称不能为空")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "单位符号", requiredMode = Schema.RequiredMode.REQUIRED, example = "m")
|
||||
@NotEmpty(message = "单位符号不能为空")
|
||||
private String smb;
|
||||
|
||||
@Schema(description = "是否基准单位:0=否,1=是", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "是否基准单位不能为空")
|
||||
private Integer isBse;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.zt.plat.module.base.controller.admin.quantityUnitRelation.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 删除单位及关联关系 Request VO")
|
||||
@Data
|
||||
public class DeleteUnitWithRelationReqVO {
|
||||
|
||||
@Schema(description = "关联关系ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "关联关系ID不能为空")
|
||||
private Long relationId;
|
||||
|
||||
@Schema(description = "单位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "单位ID不能为空")
|
||||
private Long untId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.zt.plat.module.base.controller.admin.quantityUnitRelation.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 计量单位量与单位关联批量保存 Request VO")
|
||||
@Data
|
||||
public class QuantityUnitRelationBatchSaveReqVO {
|
||||
|
||||
@Schema(description = "计量单位量ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "11015")
|
||||
@NotNull(message = "计量单位量ID不能为空")
|
||||
private Long untQtyId;
|
||||
|
||||
@Schema(description = "单位关联列表", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "单位关联列表不能为空")
|
||||
private List<UnitRelationItemVO> unitRelations;
|
||||
|
||||
@Schema(description = "单位关联项")
|
||||
@Data
|
||||
public static class UnitRelationItemVO {
|
||||
|
||||
@Schema(description = "主键ID(新增时为空,更新时必填)", example = "11015")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "计量单位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "30976")
|
||||
@NotNull(message = "计量单位ID不能为空")
|
||||
private Long untId;
|
||||
|
||||
@Schema(description = "是否基准单位-标识该维度基准单位")
|
||||
private Integer isBse;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.zt.plat.module.base.controller.admin.quantityUnitRelation.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import com.zt.plat.framework.common.pojo.PageParam;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static com.zt.plat.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 计量单位量与单位关联分页 Request VO")
|
||||
@Data
|
||||
public class QuantityUnitRelationPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "所属量纲")
|
||||
private Long untQtyId;
|
||||
|
||||
@Schema(description = "是否基准单位-标识该维度基准单位")
|
||||
private Integer isBse;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.zt.plat.module.base.controller.admin.quantityUnitRelation.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import com.alibaba.excel.annotation.*;
|
||||
|
||||
@Schema(description = "管理后台 - 计量单位量与单位关联 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class QuantityUnitRelationRespVO {
|
||||
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "11015")
|
||||
@ExcelProperty("ID")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "计量单位量ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "11015")
|
||||
@ExcelProperty("计量单位量ID")
|
||||
private Long untQtyId;
|
||||
|
||||
@Schema(description = "计量单位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "30976")
|
||||
@ExcelProperty("计量单位ID")
|
||||
private Long untId;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "是否基准单位-标识该维度基准单位")
|
||||
@ExcelProperty("是否基准单位-标识该维度基准单位")
|
||||
private Integer isBse;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.zt.plat.module.base.controller.admin.quantityUnitRelation.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 计量单位量与单位关联新增/修改 Request VO")
|
||||
@Data
|
||||
public class QuantityUnitRelationSaveReqVO {
|
||||
|
||||
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "11015")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "计量单位量ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "11015")
|
||||
private Long untQtyId;
|
||||
|
||||
@Schema(description = "计量单位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "30976")
|
||||
private Long untId;
|
||||
|
||||
@Schema(description = "是否基准单位-标识该维度基准单位")
|
||||
private Integer isBse;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
package com.zt.plat.module.base.controller.admin.unitConversion;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import com.zt.plat.framework.business.interceptor.BusinessControllerMarker;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import jakarta.validation.*;
|
||||
import jakarta.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.zt.plat.framework.common.pojo.vo.BatchDeleteReqVO;
|
||||
import com.zt.plat.framework.common.pojo.PageParam;
|
||||
import com.zt.plat.framework.common.pojo.PageResult;
|
||||
import com.zt.plat.framework.common.pojo.CommonResult;
|
||||
import com.zt.plat.framework.common.util.object.BeanUtils;
|
||||
import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import com.zt.plat.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import com.zt.plat.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import static com.zt.plat.framework.apilog.core.enums.OperateTypeEnum.*;
|
||||
|
||||
import com.zt.plat.module.base.controller.admin.unitConversion.vo.*;
|
||||
import com.zt.plat.module.base.dal.dataobject.unitConversion.UnitConversionDO;
|
||||
import com.zt.plat.module.base.service.unitConversion.UnitConversionService;
|
||||
|
||||
@Tag(name = "管理后台 - 单位转换")
|
||||
@RestController
|
||||
@RequestMapping("/base/unit-management/unit-conversion")
|
||||
@Validated
|
||||
public class UnitConversionController implements BusinessControllerMarker {
|
||||
|
||||
@Resource
|
||||
private UnitConversionService unitConversionService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建单位转换")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unit-conversion:create')")
|
||||
public CommonResult<UnitConversionRespVO> createUnitConversion(@Valid @RequestBody UnitConversionSaveReqVO createReqVO) {
|
||||
return success(unitConversionService.createUnitConversion(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新单位转换")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unit-conversion:update')")
|
||||
public CommonResult<Boolean> updateUnitConversion(@Valid @RequestBody UnitConversionSaveReqVO updateReqVO) {
|
||||
unitConversionService.updateUnitConversion(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除单位转换")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unit-conversion:delete')")
|
||||
public CommonResult<Boolean> deleteUnitConversion(@RequestParam("id") Long id) {
|
||||
unitConversionService.deleteUnitConversion(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除单位转换")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unit-conversion:delete')")
|
||||
public CommonResult<Boolean> deleteUnitConversionList(@RequestBody BatchDeleteReqVO req) {
|
||||
unitConversionService.deleteUnitConversionListByIds(req.getIds());
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得单位转换")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unit-conversion:query')")
|
||||
public CommonResult<UnitConversionRespVO> getUnitConversion(@RequestParam("id") Long id) {
|
||||
UnitConversionDO unitConversion = unitConversionService.getUnitConversion(id);
|
||||
return success(BeanUtils.toBean(unitConversion, UnitConversionRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得单位转换分页")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unit-conversion:query')")
|
||||
public CommonResult<PageResult<UnitConversionRespVO>> getUnitConversionPage(@Valid UnitConversionPageReqVO pageReqVO) {
|
||||
PageResult<UnitConversionDO> pageResult = unitConversionService.getUnitConversionPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, UnitConversionRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出单位转换 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unit-conversion:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportUnitConversionExcel(@Valid UnitConversionPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<UnitConversionDO> list = unitConversionService.getUnitConversionPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "单位转换.xls", "数据", UnitConversionRespVO.class,
|
||||
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.base.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.base.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.base.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.base.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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.zt.plat.module.base.controller.admin.unitConversion.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import com.zt.plat.framework.common.pojo.PageParam;
|
||||
import java.math.BigDecimal;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static com.zt.plat.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 单位转换分页 Request VO")
|
||||
@Data
|
||||
public class UnitConversionPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "计量单位量ID(量纲ID)", example = "1")
|
||||
private Long untQtyId;
|
||||
|
||||
@Schema(description = "源单位ID", example = "26239")
|
||||
private Long srcUntId;
|
||||
|
||||
@Schema(description = "目标单位ID", example = "25640")
|
||||
private Long tgtUntId;
|
||||
|
||||
@Schema(description = "转换因子")
|
||||
private BigDecimal fctr;
|
||||
|
||||
@Schema(description = "转换公式")
|
||||
private String fmu;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.zt.plat.module.base.controller.admin.unitConversion.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.math.BigDecimal;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import com.alibaba.excel.annotation.*;
|
||||
|
||||
@Schema(description = "管理后台 - 单位转换 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class UnitConversionRespVO {
|
||||
|
||||
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "339")
|
||||
@ExcelProperty("主键ID")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "源单位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "26239")
|
||||
@ExcelProperty("源单位ID")
|
||||
private Long srcUntId;
|
||||
|
||||
@Schema(description = "目标单位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "25640")
|
||||
@ExcelProperty("目标单位ID")
|
||||
private Long tgtUntId;
|
||||
|
||||
@Schema(description = "转换因子")
|
||||
@ExcelProperty("转换因子")
|
||||
private BigDecimal fctr;
|
||||
|
||||
@Schema(description = "转换公式", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("转换公式")
|
||||
private String fmu;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.zt.plat.module.base.controller.admin.unitConversion.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import jakarta.validation.constraints.*;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Schema(description = "管理后台 - 单位转换新增/修改 Request VO")
|
||||
@Data
|
||||
public class UnitConversionSaveReqVO {
|
||||
|
||||
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "339")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "计量单位量ID(量纲ID)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "量纲ID不能为空")
|
||||
private Long untQtyId;
|
||||
|
||||
@Schema(description = "源单位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "26239")
|
||||
@NotNull(message = "源单位ID不能为空")
|
||||
private Long srcUntId;
|
||||
|
||||
@Schema(description = "目标单位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "25640")
|
||||
@NotNull(message = "目标单位ID不能为空")
|
||||
private Long tgtUntId;
|
||||
|
||||
@Schema(description = "转换因子")
|
||||
private BigDecimal fctr;
|
||||
|
||||
@Schema(description = "转换公式", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String fmu;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package com.zt.plat.module.base.controller.admin.unitConversion.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "管理后台 - 单位转换路径校验响应 VO")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class UnitConversionValidationRespVO {
|
||||
|
||||
@Schema(description = "量纲ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Long quantityId;
|
||||
|
||||
@Schema(description = "量纲名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "长度")
|
||||
private String quantityName;
|
||||
|
||||
@Schema(description = "量纲符号", example = "L")
|
||||
private String quantitySymbol;
|
||||
|
||||
@Schema(description = "总单位数", requiredMode = Schema.RequiredMode.REQUIRED, example = "8")
|
||||
private Integer totalUnits;
|
||||
|
||||
@Schema(description = "可转换单位数", requiredMode = Schema.RequiredMode.REQUIRED, example = "8")
|
||||
private Integer convertibleUnits;
|
||||
|
||||
@Schema(description = "不可转换单位数", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
|
||||
private Integer unconvertibleUnits;
|
||||
|
||||
@Schema(description = "是否全部可转换", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
|
||||
private Boolean allConvertible;
|
||||
|
||||
@Schema(description = "基准单位信息")
|
||||
private BaseUnitInfo baseUnit;
|
||||
|
||||
@Schema(description = "不可转换的单位列表")
|
||||
private List<UnconvertibleUnitInfo> unconvertibleUnitList;
|
||||
|
||||
@Schema(description = "转换路径详情")
|
||||
private List<ConversionPathInfo> conversionPaths;
|
||||
|
||||
@Schema(description = "基准单位信息")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public static class BaseUnitInfo {
|
||||
@Schema(description = "单位ID", example = "1")
|
||||
private Long unitId;
|
||||
|
||||
@Schema(description = "单位名称", example = "米")
|
||||
private String unitName;
|
||||
|
||||
@Schema(description = "单位符号", example = "m")
|
||||
private String unitSymbol;
|
||||
}
|
||||
|
||||
@Schema(description = "不可转换单位信息")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public static class UnconvertibleUnitInfo {
|
||||
@Schema(description = "单位ID", example = "1")
|
||||
private Long unitId;
|
||||
|
||||
@Schema(description = "单位名称", example = "光年")
|
||||
private String unitName;
|
||||
|
||||
@Schema(description = "单位符号", example = "ly")
|
||||
private String unitSymbol;
|
||||
|
||||
@Schema(description = "原因", example = "缺少到基准单位的转换规则")
|
||||
private String reason;
|
||||
}
|
||||
|
||||
@Schema(description = "转换路径信息")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public static class ConversionPathInfo {
|
||||
@Schema(description = "源单位ID", example = "1")
|
||||
private Long srcUnitId;
|
||||
|
||||
@Schema(description = "源单位名称", example = "千米")
|
||||
private String srcUnitName;
|
||||
|
||||
@Schema(description = "目标单位ID", example = "2")
|
||||
private Long tgtUnitId;
|
||||
|
||||
@Schema(description = "目标单位名称", example = "米")
|
||||
private String tgtUnitName;
|
||||
|
||||
@Schema(description = "是否有直接转换", example = "true")
|
||||
private Boolean hasDirect;
|
||||
|
||||
@Schema(description = "是否可通过基准单位转换", example = "true")
|
||||
private Boolean hasViaBase;
|
||||
|
||||
@Schema(description = "转换路径描述", example = "千米 → 米 (直接转换)")
|
||||
private String pathDescription;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.zt.plat.module.base.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.base.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.base.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;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.zt.plat.module.base.controller.admin.unitConversion.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.Builder;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Schema(description = "管理后台 - 单位转换 Response VO")
|
||||
@Data
|
||||
@Builder
|
||||
public class UnitConvertRespVO {
|
||||
|
||||
@Schema(description = "源单位ID", example = "1")
|
||||
private Long srcUntId;
|
||||
|
||||
@Schema(description = "源单位名称", example = "米")
|
||||
private String srcUntName;
|
||||
|
||||
@Schema(description = "源单位符号", example = "m")
|
||||
private String srcUntSmb;
|
||||
|
||||
@Schema(description = "目标单位ID", example = "2")
|
||||
private Long tgtUntId;
|
||||
|
||||
@Schema(description = "目标单位名称", example = "千米")
|
||||
private String tgtUntName;
|
||||
|
||||
@Schema(description = "目标单位符号", example = "km")
|
||||
private String tgtUntSmb;
|
||||
|
||||
@Schema(description = "原始值", example = "1000")
|
||||
private BigDecimal originalValue;
|
||||
|
||||
@Schema(description = "转换后的值", example = "1")
|
||||
private BigDecimal convertedValue;
|
||||
|
||||
@Schema(description = "转换因子", example = "0.001")
|
||||
private BigDecimal factor;
|
||||
|
||||
@Schema(description = "转换公式", example = "1000m = 1km")
|
||||
private String formula;
|
||||
|
||||
@Schema(description = "转换策略", example = "DIRECT")
|
||||
private String strategy;
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package com.zt.plat.module.base.controller.admin.unitQuantity;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import com.zt.plat.framework.business.interceptor.BusinessControllerMarker;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import jakarta.validation.*;
|
||||
import jakarta.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.zt.plat.framework.common.pojo.vo.BatchDeleteReqVO;
|
||||
import com.zt.plat.framework.common.pojo.PageParam;
|
||||
import com.zt.plat.framework.common.pojo.PageResult;
|
||||
import com.zt.plat.framework.common.pojo.CommonResult;
|
||||
import com.zt.plat.framework.common.util.object.BeanUtils;
|
||||
import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import com.zt.plat.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import com.zt.plat.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import static com.zt.plat.framework.apilog.core.enums.OperateTypeEnum.*;
|
||||
|
||||
import com.zt.plat.module.base.controller.admin.unitQuantity.vo.*;
|
||||
import com.zt.plat.module.base.dal.dataobject.unitQuantity.UnitQuantityDO;
|
||||
import com.zt.plat.module.base.service.unitQuantity.UnitQuantityService;
|
||||
|
||||
@Tag(name = "管理后台 - 计量单位量")
|
||||
@RestController
|
||||
@RequestMapping("/base/unit-management/unit-quantity")
|
||||
@Validated
|
||||
public class UnitQuantityController implements BusinessControllerMarker {
|
||||
|
||||
|
||||
@Resource
|
||||
private UnitQuantityService unitQuantityService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建计量单位量")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unit-quantity:create')")
|
||||
public CommonResult<UnitQuantityRespVO> createUnitQuantity(@Valid @RequestBody UnitQuantitySaveReqVO createReqVO) {
|
||||
return success(unitQuantityService.createUnitQuantity(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新计量单位量")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unit-quantity:update')")
|
||||
public CommonResult<Boolean> updateUnitQuantity(@Valid @RequestBody UnitQuantitySaveReqVO updateReqVO) {
|
||||
unitQuantityService.updateUnitQuantity(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除计量单位量")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unit-quantity:delete')")
|
||||
public CommonResult<Boolean> deleteUnitQuantity(@RequestParam("id") Long id) {
|
||||
unitQuantityService.deleteUnitQuantity(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除计量单位量")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unit-quantity:delete')")
|
||||
public CommonResult<Boolean> deleteUnitQuantityList(@RequestBody BatchDeleteReqVO req) {
|
||||
unitQuantityService.deleteUnitQuantityListByIds(req.getIds());
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得计量单位量")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unit-quantity:query')")
|
||||
public CommonResult<UnitQuantityRespVO> getUnitQuantity(@RequestParam("id") Long id) {
|
||||
UnitQuantityDO unitQuantity = unitQuantityService.getUnitQuantity(id);
|
||||
return success(BeanUtils.toBean(unitQuantity, UnitQuantityRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得计量单位量分页")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unit-quantity:query')")
|
||||
public CommonResult<PageResult<UnitQuantityRespVO>> getUnitQuantityPage(@Valid UnitQuantityPageReqVO pageReqVO) {
|
||||
PageResult<UnitQuantityDO> pageResult = unitQuantityService.getUnitQuantityPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, UnitQuantityRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出计量单位量 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unit-quantity:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportUnitQuantityExcel(@Valid UnitQuantityPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<UnitQuantityDO> list = unitQuantityService.getUnitQuantityPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "计量单位量.xls", "数据", UnitQuantityRespVO.class,
|
||||
BeanUtils.toBean(list, UnitQuantityRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/tree")
|
||||
@Operation(summary = "获取量纲及单位树")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unit-quantity:query')")
|
||||
public CommonResult<List<UnitQuantityTreeRespVO>> getUnitQuantityTree() {
|
||||
return success(unitQuantityService.getUnitQuantityTree());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.zt.plat.module.base.controller.admin.unitQuantity.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import com.zt.plat.framework.common.pojo.PageParam;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static com.zt.plat.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 计量单位量分页 Request VO")
|
||||
@Data
|
||||
public class UnitQuantityPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "计量名称", example = "王五")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "计量符号")
|
||||
private String symbol;
|
||||
|
||||
@Schema(description = "计量描述")
|
||||
private String dsp;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.zt.plat.module.base.controller.admin.unitQuantity.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import com.alibaba.excel.annotation.*;
|
||||
|
||||
@Schema(description = "管理后台 - 计量单位量 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class UnitQuantityRespVO {
|
||||
|
||||
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "314")
|
||||
@ExcelProperty("主键ID")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "计量名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
|
||||
@ExcelProperty("计量名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "计量符号", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("计量符号")
|
||||
private String symbol;
|
||||
|
||||
@Schema(description = "计量描述", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("计量描述")
|
||||
private String dsp;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.zt.plat.module.base.controller.admin.unitQuantity.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 计量单位量新增/修改 Request VO")
|
||||
@Data
|
||||
public class UnitQuantitySaveReqVO {
|
||||
|
||||
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "314")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "计量名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
|
||||
@NotEmpty(message = "计量名称不能为空")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "计量符号", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "计量符号不能为空")
|
||||
private String symbol;
|
||||
|
||||
@Schema(description = "计量描述", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "计量描述不能为空")
|
||||
private String dsp;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.zt.plat.module.base.controller.admin.unitQuantity.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "管理后台 - 量纲及单位树 Response VO")
|
||||
@Data
|
||||
public class UnitQuantityTreeRespVO {
|
||||
|
||||
@Schema(description = "量纲ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "量纲名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "长度")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "量纲符号", requiredMode = Schema.RequiredMode.REQUIRED, example = "L")
|
||||
private String symbol;
|
||||
|
||||
@Schema(description = "量纲描述", example = "用于测量物体长短、距离的物理量")
|
||||
private String dsp;
|
||||
|
||||
@Schema(description = "下属单位列表")
|
||||
private List<UnitItemVO> units;
|
||||
|
||||
@Schema(description = "单位项")
|
||||
@Data
|
||||
public static class UnitItemVO {
|
||||
|
||||
@Schema(description = "单位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "单位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "米")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "单位符号", requiredMode = Schema.RequiredMode.REQUIRED, example = "m")
|
||||
private String smb;
|
||||
|
||||
@Schema(description = "是否基准单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer isBse;
|
||||
|
||||
@Schema(description = "关联关系ID", example = "1")
|
||||
private Long relationId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package com.zt.plat.module.base.controller.admin.untInfo;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import com.zt.plat.framework.business.interceptor.BusinessControllerMarker;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import jakarta.validation.*;
|
||||
import jakarta.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.zt.plat.framework.common.pojo.vo.BatchDeleteReqVO;
|
||||
import com.zt.plat.framework.common.pojo.PageParam;
|
||||
import com.zt.plat.framework.common.pojo.PageResult;
|
||||
import com.zt.plat.framework.common.pojo.CommonResult;
|
||||
import com.zt.plat.framework.common.util.object.BeanUtils;
|
||||
import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import com.zt.plat.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import com.zt.plat.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import static com.zt.plat.framework.apilog.core.enums.OperateTypeEnum.*;
|
||||
|
||||
import com.zt.plat.module.base.controller.admin.untInfo.vo.*;
|
||||
import com.zt.plat.module.base.dal.dataobject.untInfo.UntInfoDO;
|
||||
import com.zt.plat.module.base.service.untInfo.UntInfoService;
|
||||
|
||||
@Tag(name = "管理后台 - 计量单位")
|
||||
@RestController
|
||||
@RequestMapping("/base/unit-management/unt-info")
|
||||
@Validated
|
||||
public class UntInfoController implements BusinessControllerMarker {
|
||||
|
||||
|
||||
@Resource
|
||||
private UntInfoService untInfoService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建计量单位")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unt-info:create')")
|
||||
public CommonResult<UntInfoRespVO> createUntInfo(@Valid @RequestBody UntInfoSaveReqVO createReqVO) {
|
||||
return success(untInfoService.createUntInfo(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新计量单位")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unt-info:update')")
|
||||
public CommonResult<Boolean> updateUntInfo(@Valid @RequestBody UntInfoSaveReqVO updateReqVO) {
|
||||
untInfoService.updateUntInfo(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除计量单位")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unt-info:delete')")
|
||||
public CommonResult<Boolean> deleteUntInfo(@RequestParam("id") Long id) {
|
||||
untInfoService.deleteUntInfo(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除计量单位")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unt-info:delete')")
|
||||
public CommonResult<Boolean> deleteUntInfoList(@RequestBody BatchDeleteReqVO req) {
|
||||
untInfoService.deleteUntInfoListByIds(req.getIds());
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得计量单位")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unt-info:query')")
|
||||
public CommonResult<UntInfoRespVO> getUntInfo(@RequestParam("id") Long id) {
|
||||
UntInfoDO untInfo = untInfoService.getUntInfo(id);
|
||||
return success(BeanUtils.toBean(untInfo, UntInfoRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得计量单位分页")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unt-info:query')")
|
||||
public CommonResult<PageResult<UntInfoRespVO>> getUntInfoPage(@Valid UntInfoPageReqVO pageReqVO) {
|
||||
PageResult<UntInfoDO> pageResult = untInfoService.getUntInfoPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, UntInfoRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出计量单位 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('unitmanagement:unt-info:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportUntInfoExcel(@Valid UntInfoPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<UntInfoDO> list = untInfoService.getUntInfoPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "计量单位.xls", "数据", UntInfoRespVO.class,
|
||||
BeanUtils.toBean(list, UntInfoRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.zt.plat.module.base.controller.admin.untInfo.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import com.zt.plat.framework.common.pojo.PageParam;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static com.zt.plat.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 计量单位分页 Request VO")
|
||||
@Data
|
||||
public class UntInfoPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "单位名称", example = "王五")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "单位符号")
|
||||
private String smb;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.zt.plat.module.base.controller.admin.untInfo.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import com.alibaba.excel.annotation.*;
|
||||
|
||||
@Schema(description = "管理后台 - 计量单位 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class UntInfoRespVO {
|
||||
|
||||
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "18527")
|
||||
@ExcelProperty("主键ID")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "单位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
|
||||
@ExcelProperty("单位名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "单位符号", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("单位符号")
|
||||
private String smb;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.zt.plat.module.base.controller.admin.untInfo.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 计量单位新增/修改 Request VO")
|
||||
@Data
|
||||
public class UntInfoSaveReqVO {
|
||||
|
||||
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "18527")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "单位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
|
||||
@NotEmpty(message = "单位名称不能为空")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "单位符号", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "单位符号不能为空")
|
||||
private String smb;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.zt.plat.module.base.dal.dao.quantityUnitRelation;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.zt.plat.framework.common.pojo.PageResult;
|
||||
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.zt.plat.module.base.dal.dataobject.quantityUnitRelation.QuantityUnitRelationDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import com.zt.plat.module.base.controller.admin.quantityUnitRelation.vo.*;
|
||||
|
||||
/**
|
||||
* 计量单位量与单位关联 Mapper
|
||||
*
|
||||
* @author 后台管理-1
|
||||
*/
|
||||
@Mapper
|
||||
public interface QuantityUnitRelationMapper extends BaseMapperX<QuantityUnitRelationDO> {
|
||||
|
||||
default PageResult<QuantityUnitRelationDO> selectPage(QuantityUnitRelationPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<QuantityUnitRelationDO>()
|
||||
.eqIfPresent(QuantityUnitRelationDO::getUntQtyId, reqVO.getUntQtyId())
|
||||
.eqIfPresent(QuantityUnitRelationDO::getIsBse, reqVO.getIsBse())
|
||||
.orderByDesc(QuantityUnitRelationDO::getUntQtyId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据量纲ID查询所有关联关系
|
||||
*
|
||||
* @param untQtyId 量纲ID
|
||||
* @return 关联关系列表
|
||||
*/
|
||||
default List<QuantityUnitRelationDO> selectListByUntQtyId(Long untQtyId) {
|
||||
return selectList(new LambdaQueryWrapperX<QuantityUnitRelationDO>()
|
||||
.eq(QuantityUnitRelationDO::getUntQtyId, untQtyId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.zt.plat.module.base.dal.dao.unitConversion;
|
||||
|
||||
import com.zt.plat.framework.common.pojo.PageResult;
|
||||
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.zt.plat.module.base.dal.dataobject.unitConversion.UnitConversionDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import com.zt.plat.module.base.controller.admin.unitConversion.vo.*;
|
||||
|
||||
/**
|
||||
* 单位转换 Mapper
|
||||
*
|
||||
* @author 后台管理-1
|
||||
*/
|
||||
@Mapper
|
||||
public interface UnitConversionMapper extends BaseMapperX<UnitConversionDO> {
|
||||
|
||||
default PageResult<UnitConversionDO> selectPage(UnitConversionPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<UnitConversionDO>()
|
||||
.eqIfPresent(UnitConversionDO::getUntQtyId, reqVO.getUntQtyId())
|
||||
.eqIfPresent(UnitConversionDO::getSrcUntId, reqVO.getSrcUntId())
|
||||
.eqIfPresent(UnitConversionDO::getTgtUntId, reqVO.getTgtUntId())
|
||||
.eqIfPresent(UnitConversionDO::getFctr, reqVO.getFctr())
|
||||
.eqIfPresent(UnitConversionDO::getFmu, reqVO.getFmu())
|
||||
.betweenIfPresent(UnitConversionDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(UnitConversionDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.zt.plat.module.base.dal.dao.unitQuantity;
|
||||
|
||||
import com.zt.plat.framework.common.pojo.PageResult;
|
||||
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.zt.plat.module.base.dal.dataobject.unitQuantity.UnitQuantityDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import com.zt.plat.module.base.controller.admin.unitQuantity.vo.*;
|
||||
|
||||
/**
|
||||
* 计量单位量 Mapper
|
||||
*
|
||||
* @author 后台管理-1
|
||||
*/
|
||||
@Mapper
|
||||
public interface UnitQuantityMapper extends BaseMapperX<UnitQuantityDO> {
|
||||
|
||||
default PageResult<UnitQuantityDO> selectPage(UnitQuantityPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<UnitQuantityDO>()
|
||||
.likeIfPresent(UnitQuantityDO::getName, reqVO.getName())
|
||||
.eqIfPresent(UnitQuantityDO::getSymbol, reqVO.getSymbol())
|
||||
.eqIfPresent(UnitQuantityDO::getDsp, reqVO.getDsp())
|
||||
.betweenIfPresent(UnitQuantityDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(UnitQuantityDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.zt.plat.module.base.dal.dao.untInfo;
|
||||
|
||||
import com.zt.plat.framework.common.pojo.PageResult;
|
||||
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.zt.plat.module.base.dal.dataobject.untInfo.UntInfoDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import com.zt.plat.module.base.controller.admin.untInfo.vo.*;
|
||||
|
||||
/**
|
||||
* 计量单位 Mapper
|
||||
*
|
||||
* @author 后台管理-1
|
||||
*/
|
||||
@Mapper
|
||||
public interface UntInfoMapper extends BaseMapperX<UntInfoDO> {
|
||||
|
||||
default PageResult<UntInfoDO> selectPage(UntInfoPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<UntInfoDO>()
|
||||
.likeIfPresent(UntInfoDO::getName, reqVO.getName())
|
||||
.eqIfPresent(UntInfoDO::getSmb, reqVO.getSmb())
|
||||
.betweenIfPresent(UntInfoDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(UntInfoDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.zt.plat.module.base.dal.dataobject.quantityUnitRelation;
|
||||
|
||||
import com.zt.plat.framework.mybatis.core.dataobject.BaseDO;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
/**
|
||||
* 计量单位量与单位关联 DO
|
||||
*
|
||||
* @author 后台管理-1
|
||||
*/
|
||||
@TableName("bse_unt_qty_unt")
|
||||
@KeySequence("bse_unt_qty_unt_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
/**
|
||||
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
||||
*/
|
||||
public class QuantityUnitRelationDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 计量单位量ID
|
||||
*/
|
||||
@TableField("UNT_QTY_ID")
|
||||
private Long untQtyId;
|
||||
/**
|
||||
* 计量单位ID
|
||||
*/
|
||||
@TableField("UNT_ID")
|
||||
private Long untId;
|
||||
/**
|
||||
* 是否基准单位-标识该维度基准单位
|
||||
*/
|
||||
@TableField("IS_BSE")
|
||||
private Integer isBse;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.zt.plat.module.base.dal.dataobject.unitConversion;
|
||||
|
||||
import com.zt.plat.framework.mybatis.core.dataobject.BaseDO;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
/**
|
||||
* 单位转换 DO
|
||||
*
|
||||
* @author 后台管理-1
|
||||
*/
|
||||
@TableName("bse_unt_cnv")
|
||||
@KeySequence("bse_unt_cnv_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
/**
|
||||
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
||||
*/
|
||||
public class UnitConversionDO extends BaseDO {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
/**
|
||||
* 计量单位量ID(量纲ID)
|
||||
*/
|
||||
@TableField("UNT_QTY_ID")
|
||||
private Long untQtyId;
|
||||
/**
|
||||
* 源单位ID
|
||||
*/
|
||||
@TableField("SRC_UNT_ID")
|
||||
private Long srcUntId;
|
||||
/**
|
||||
* 目标单位ID
|
||||
*/
|
||||
@TableField("TGT_UNT_ID")
|
||||
private Long tgtUntId;
|
||||
/**
|
||||
* 转换因子
|
||||
*/
|
||||
@TableField("FCTR")
|
||||
private BigDecimal fctr;
|
||||
/**
|
||||
* 转换公式
|
||||
*/
|
||||
@TableField("FMU")
|
||||
private String fmu;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.zt.plat.module.base.dal.dataobject.unitQuantity;
|
||||
|
||||
import com.zt.plat.framework.mybatis.core.dataobject.BaseDO;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
/**
|
||||
* 计量单位量 DO
|
||||
*
|
||||
* @author 后台管理-1
|
||||
*/
|
||||
@TableName("bse_unt_qty")
|
||||
@KeySequence("bse_unt_qty_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
/**
|
||||
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
||||
*/
|
||||
public class UnitQuantityDO extends BaseDO {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
/**
|
||||
* 计量名称
|
||||
*/
|
||||
@TableField("NAME")
|
||||
private String name;
|
||||
/**
|
||||
* 计量符号
|
||||
*/
|
||||
@TableField("SYMBOL")
|
||||
private String symbol;
|
||||
/**
|
||||
* 计量描述
|
||||
*/
|
||||
@TableField("DSP")
|
||||
private String dsp;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.zt.plat.module.base.dal.dataobject.untInfo;
|
||||
|
||||
import com.zt.plat.framework.mybatis.core.dataobject.BaseDO;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
/**
|
||||
* 计量单位 DO
|
||||
*
|
||||
* @author 后台管理-1
|
||||
*/
|
||||
@TableName("bse_unt_inf")
|
||||
@KeySequence("bse_unt_inf_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
/**
|
||||
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
||||
*/
|
||||
public class UntInfoDO extends BaseDO {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
/**
|
||||
* 单位名称
|
||||
*/
|
||||
@TableField("NAME")
|
||||
private String name;
|
||||
/**
|
||||
* 单位符号
|
||||
*/
|
||||
@TableField("SMB")
|
||||
private String smb;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.zt.plat.module.base.service.quantityUnitRelation;
|
||||
|
||||
import java.util.*;
|
||||
import jakarta.validation.*;
|
||||
import com.zt.plat.module.base.controller.admin.quantityUnitRelation.vo.*;
|
||||
import com.zt.plat.module.base.dal.dataobject.quantityUnitRelation.QuantityUnitRelationDO;
|
||||
import com.zt.plat.framework.common.pojo.PageResult;
|
||||
|
||||
/**
|
||||
* 计量单位量与单位关联 Service 接口
|
||||
*
|
||||
* @author 后台管理-1
|
||||
*/
|
||||
public interface QuantityUnitRelationService {
|
||||
|
||||
/**
|
||||
* 创建计量单位量与单位关联
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
QuantityUnitRelationRespVO createQuantityUnitRelation(@Valid QuantityUnitRelationSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新计量单位量与单位关联
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateQuantityUnitRelation(@Valid QuantityUnitRelationSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除计量单位量与单位关联
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteQuantityUnitRelation(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除计量单位量与单位关联
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void deleteQuantityUnitRelationListByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得计量单位量与单位关联
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 计量单位量与单位关联
|
||||
*/
|
||||
QuantityUnitRelationDO getQuantityUnitRelation(Long id);
|
||||
|
||||
/**
|
||||
* 获得计量单位量与单位关联分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 计量单位量与单位关联分页
|
||||
*/
|
||||
PageResult<QuantityUnitRelationDO> getQuantityUnitRelationPage(QuantityUnitRelationPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 批量保存计量单位量与单位关联
|
||||
* 根据传入的量纲ID和单位列表,进行新增、更新和逻辑删除操作
|
||||
*
|
||||
* @param batchSaveReqVO 批量保存请求
|
||||
*/
|
||||
void batchSaveQuantityUnitRelations(@Valid QuantityUnitRelationBatchSaveReqVO batchSaveReqVO);
|
||||
|
||||
/**
|
||||
* 创建单位并关联到量纲(组合接口)
|
||||
* 1. 创建计量单位
|
||||
* 2. 创建量纲-单位关联关系
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 关联关系响应VO
|
||||
*/
|
||||
QuantityUnitRelationRespVO createUnitWithRelation(@Valid CreateUnitWithRelationReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 删除单位及关联关系(组合接口)
|
||||
* 1. 删除量纲-单位关联关系
|
||||
* 2. 删除计量单位
|
||||
*
|
||||
* @param deleteReqVO 删除信息
|
||||
*/
|
||||
void deleteUnitWithRelation(@Valid DeleteUnitWithRelationReqVO deleteReqVO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
package com.zt.plat.module.base.service.quantityUnitRelation;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import com.zt.plat.module.base.controller.admin.quantityUnitRelation.vo.*;
|
||||
import com.zt.plat.module.base.dal.dataobject.quantityUnitRelation.QuantityUnitRelationDO;
|
||||
import com.zt.plat.framework.common.pojo.PageResult;
|
||||
import com.zt.plat.framework.common.util.object.BeanUtils;
|
||||
|
||||
import com.zt.plat.module.base.dal.dao.quantityUnitRelation.QuantityUnitRelationMapper;
|
||||
import com.zt.plat.module.base.service.untInfo.UntInfoService;
|
||||
import com.zt.plat.module.base.controller.admin.untInfo.vo.UntInfoSaveReqVO;
|
||||
import com.zt.plat.module.base.controller.admin.untInfo.vo.UntInfoRespVO;
|
||||
|
||||
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static com.zt.plat.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static com.zt.plat.module.unitmanagement.enums.UnitErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 计量单位量与单位关联 Service 实现类
|
||||
*
|
||||
* @author 后台管理-1
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class QuantityUnitRelationServiceImpl implements QuantityUnitRelationService {
|
||||
|
||||
@Resource
|
||||
private QuantityUnitRelationMapper quantityUnitRelationMapper;
|
||||
|
||||
@Resource
|
||||
private UntInfoService untInfoService;
|
||||
|
||||
@Override
|
||||
public QuantityUnitRelationRespVO createQuantityUnitRelation(QuantityUnitRelationSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
QuantityUnitRelationDO quantityUnitRelation = BeanUtils.toBean(createReqVO, QuantityUnitRelationDO.class);
|
||||
quantityUnitRelationMapper.insert(quantityUnitRelation);
|
||||
// 返回
|
||||
return BeanUtils.toBean(quantityUnitRelation, QuantityUnitRelationRespVO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateQuantityUnitRelation(QuantityUnitRelationSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateQuantityUnitRelationExists(updateReqVO.getId());
|
||||
// 更新
|
||||
QuantityUnitRelationDO updateObj = BeanUtils.toBean(updateReqVO, QuantityUnitRelationDO.class);
|
||||
quantityUnitRelationMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteQuantityUnitRelation(Long id) {
|
||||
// 校验存在
|
||||
validateQuantityUnitRelationExists(id);
|
||||
// 删除
|
||||
quantityUnitRelationMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteQuantityUnitRelationListByIds(List<Long> ids) {
|
||||
// 校验存在
|
||||
validateQuantityUnitRelationExists(ids);
|
||||
// 删除
|
||||
quantityUnitRelationMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
private void validateQuantityUnitRelationExists(List<Long> ids) {
|
||||
List<QuantityUnitRelationDO> list = quantityUnitRelationMapper.selectByIds(ids);
|
||||
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
|
||||
throw exception(QUANTITY_UNIT_RELATION_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateQuantityUnitRelationExists(Long id) {
|
||||
if (quantityUnitRelationMapper.selectById(id) == null) {
|
||||
throw exception(QUANTITY_UNIT_RELATION_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuantityUnitRelationDO getQuantityUnitRelation(Long id) {
|
||||
return quantityUnitRelationMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<QuantityUnitRelationDO> getQuantityUnitRelationPage(QuantityUnitRelationPageReqVO pageReqVO) {
|
||||
return quantityUnitRelationMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void batchSaveQuantityUnitRelations(QuantityUnitRelationBatchSaveReqVO batchSaveReqVO) {
|
||||
Long untQtyId = batchSaveReqVO.getUntQtyId();
|
||||
List<QuantityUnitRelationBatchSaveReqVO.UnitRelationItemVO> requestItems = batchSaveReqVO.getUnitRelations();
|
||||
|
||||
// 1. 查询数据库中该量纲下的所有现有关联关系
|
||||
List<QuantityUnitRelationDO> existingRelations = quantityUnitRelationMapper.selectListByUntQtyId(untQtyId);
|
||||
|
||||
// 2. 提取请求中的ID列表(排除null)
|
||||
List<Long> requestIds = requestItems.stream()
|
||||
.map(QuantityUnitRelationBatchSaveReqVO.UnitRelationItemVO::getId)
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
|
||||
// 3. 提取现有数据的ID列表
|
||||
List<Long> existingIds = convertList(existingRelations, QuantityUnitRelationDO::getId);
|
||||
|
||||
// 4. 找出需要删除的ID(数据库有但请求中没有的)
|
||||
List<Long> toDeleteIds = new ArrayList<>();
|
||||
for (Long existingId : existingIds) {
|
||||
if (!requestIds.contains(existingId)) {
|
||||
toDeleteIds.add(existingId);
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 执行逻辑删除
|
||||
if (CollUtil.isNotEmpty(toDeleteIds)) {
|
||||
quantityUnitRelationMapper.deleteByIds(toDeleteIds);
|
||||
}
|
||||
|
||||
// 6. 处理新增和更新
|
||||
for (QuantityUnitRelationBatchSaveReqVO.UnitRelationItemVO item : requestItems) {
|
||||
QuantityUnitRelationDO relation = new QuantityUnitRelationDO();
|
||||
relation.setUntQtyId(untQtyId);
|
||||
relation.setUntId(item.getUntId());
|
||||
relation.setIsBse(item.getIsBse());
|
||||
|
||||
if (item.getId() != null) {
|
||||
// 更新操作
|
||||
relation.setId(item.getId());
|
||||
quantityUnitRelationMapper.updateById(relation);
|
||||
} else {
|
||||
// 新增操作
|
||||
quantityUnitRelationMapper.insert(relation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public QuantityUnitRelationRespVO createUnitWithRelation(CreateUnitWithRelationReqVO createReqVO) {
|
||||
// 1. 创建计量单位
|
||||
UntInfoSaveReqVO untInfoReqVO = new UntInfoSaveReqVO();
|
||||
untInfoReqVO.setName(createReqVO.getName());
|
||||
untInfoReqVO.setSmb(createReqVO.getSmb());
|
||||
UntInfoRespVO untInfoResp = untInfoService.createUntInfo(untInfoReqVO);
|
||||
|
||||
// 2. 创建量纲-单位关联关系
|
||||
QuantityUnitRelationSaveReqVO relationReqVO = new QuantityUnitRelationSaveReqVO();
|
||||
relationReqVO.setUntQtyId(createReqVO.getUntQtyId());
|
||||
relationReqVO.setUntId(untInfoResp.getId());
|
||||
relationReqVO.setIsBse(createReqVO.getIsBse());
|
||||
|
||||
return createQuantityUnitRelation(relationReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteUnitWithRelation(DeleteUnitWithRelationReqVO deleteReqVO) {
|
||||
// 1. 先删除关联关系(外键约束,必须先删除)
|
||||
deleteQuantityUnitRelation(deleteReqVO.getRelationId());
|
||||
|
||||
// 2. 再删除计量单位
|
||||
untInfoService.deleteUntInfo(deleteReqVO.getUntId());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
package com.zt.plat.module.base.service.unitConversion;
|
||||
|
||||
import com.zt.plat.module.base.dal.dao.unitConversion.UnitConversionMapper;
|
||||
import com.zt.plat.module.base.dal.dao.quantityUnitRelation.QuantityUnitRelationMapper;
|
||||
import com.zt.plat.module.base.dal.dao.untInfo.UntInfoMapper;
|
||||
import com.zt.plat.module.base.dal.dataobject.unitConversion.UnitConversionDO;
|
||||
import com.zt.plat.module.base.dal.dataobject.quantityUnitRelation.QuantityUnitRelationDO;
|
||||
import com.zt.plat.module.base.dal.dataobject.untInfo.UntInfoDO;
|
||||
import com.zt.plat.module.base.util.UnitConversionUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 单位转换辅助服务
|
||||
*
|
||||
* 为其他模块提供简单易用的单位转换方法
|
||||
* 支持按单位符号和单位名称进行转换
|
||||
*
|
||||
* @author 系统
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class UnitConversionHelperService {
|
||||
|
||||
@Resource
|
||||
private UnitConversionMapper unitConversionMapper;
|
||||
|
||||
@Resource
|
||||
private QuantityUnitRelationMapper quantityUnitRelationMapper;
|
||||
|
||||
@Resource
|
||||
private UntInfoMapper untInfoMapper;
|
||||
|
||||
/**
|
||||
* 按单位符号转换(推荐使用)
|
||||
*
|
||||
* @param value 待转换的值
|
||||
* @param srcSymbol 源单位符号(如: "kg", "m", "km")
|
||||
* @param tgtSymbol 目标单位符号
|
||||
* @return 转换后的值
|
||||
*/
|
||||
public BigDecimal convertBySymbol(BigDecimal value, String srcSymbol, String tgtSymbol) {
|
||||
return convertBySymbol(value, srcSymbol, tgtSymbol, 6);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按单位符号转换(推荐使用)
|
||||
*
|
||||
* @param value 待转换的值
|
||||
* @param srcSymbol 源单位符号(如: "kg", "m", "km")
|
||||
* @param tgtSymbol 目标单位符号
|
||||
* @param precision 精度(小数位数)
|
||||
* @return 转换后的值
|
||||
*/
|
||||
public BigDecimal convertBySymbol(BigDecimal value, String srcSymbol, String tgtSymbol, int precision) {
|
||||
log.debug("按符号转换: {} {} → {}", value, srcSymbol, tgtSymbol);
|
||||
|
||||
// 加载数据
|
||||
List<UnitConversionDO> conversions = unitConversionMapper.selectList();
|
||||
List<QuantityUnitRelationDO> relations = quantityUnitRelationMapper.selectList();
|
||||
List<UntInfoDO> units = untInfoMapper.selectList();
|
||||
|
||||
// 调用工具类
|
||||
UnitConversionUtil.ConversionResult result = UnitConversionUtil.convertBySymbol(
|
||||
value, srcSymbol, tgtSymbol, conversions, relations, units, precision
|
||||
);
|
||||
|
||||
log.debug("转换结果: {} (策略: {})", result.getValue(), result.getStrategy());
|
||||
return result.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 按单位名称转换
|
||||
*
|
||||
* @param value 待转换的值
|
||||
* @param srcName 源单位名称(如: "千克", "米", "千米")
|
||||
* @param tgtName 目标单位名称
|
||||
* @return 转换后的值
|
||||
*/
|
||||
public BigDecimal convertByName(BigDecimal value, String srcName, String tgtName) {
|
||||
return convertByName(value, srcName, tgtName, 6);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按单位名称转换
|
||||
*
|
||||
* @param value 待转换的值
|
||||
* @param srcName 源单位名称(如: "千克", "米", "千米")
|
||||
* @param tgtName 目标单位名称
|
||||
* @param precision 精度(小数位数)
|
||||
* @return 转换后的值
|
||||
*/
|
||||
public BigDecimal convertByName(BigDecimal value, String srcName, String tgtName, int precision) {
|
||||
log.debug("按名称转换: {} {} → {}", value, srcName, tgtName);
|
||||
|
||||
// 加载数据
|
||||
List<UnitConversionDO> conversions = unitConversionMapper.selectList();
|
||||
List<QuantityUnitRelationDO> relations = quantityUnitRelationMapper.selectList();
|
||||
List<UntInfoDO> units = untInfoMapper.selectList();
|
||||
|
||||
// 调用工具类
|
||||
UnitConversionUtil.ConversionResult result = UnitConversionUtil.convertByName(
|
||||
value, srcName, tgtName, conversions, relations, units, precision
|
||||
);
|
||||
|
||||
log.debug("转换结果: {} (策略: {})", result.getValue(), result.getStrategy());
|
||||
return result.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 按单位符号批量转换
|
||||
*
|
||||
* @param values 待转换的值列表
|
||||
* @param srcSymbol 源单位符号
|
||||
* @param tgtSymbol 目标单位符号
|
||||
* @return 转换后的值列表
|
||||
*/
|
||||
public List<BigDecimal> batchConvertBySymbol(List<BigDecimal> values, String srcSymbol, String tgtSymbol) {
|
||||
return batchConvertBySymbol(values, srcSymbol, tgtSymbol, 6);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按单位符号批量转换
|
||||
*
|
||||
* @param values 待转换的值列表
|
||||
* @param srcSymbol 源单位符号
|
||||
* @param tgtSymbol 目标单位符号
|
||||
* @param precision 精度(小数位数)
|
||||
* @return 转换后的值列表
|
||||
*/
|
||||
public List<BigDecimal> batchConvertBySymbol(List<BigDecimal> values, String srcSymbol, String tgtSymbol, int precision) {
|
||||
log.debug("批量按符号转换: {} 个值, {} → {}", values.size(), srcSymbol, tgtSymbol);
|
||||
|
||||
// 加载数据
|
||||
List<UnitConversionDO> conversions = unitConversionMapper.selectList();
|
||||
List<QuantityUnitRelationDO> relations = quantityUnitRelationMapper.selectList();
|
||||
List<UntInfoDO> units = untInfoMapper.selectList();
|
||||
|
||||
// 调用工具类
|
||||
List<UnitConversionUtil.ConversionResult> results = UnitConversionUtil.batchConvertBySymbol(
|
||||
values, srcSymbol, tgtSymbol, conversions, relations, units, precision
|
||||
);
|
||||
|
||||
// 提取转换后的值
|
||||
return results.stream()
|
||||
.map(UnitConversionUtil.ConversionResult::getValue)
|
||||
.toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 按单位名称批量转换
|
||||
*
|
||||
* @param values 待转换的值列表
|
||||
* @param srcName 源单位名称
|
||||
* @param tgtName 目标单位名称
|
||||
* @return 转换后的值列表
|
||||
*/
|
||||
public List<BigDecimal> batchConvertByName(List<BigDecimal> values, String srcName, String tgtName) {
|
||||
return batchConvertByName(values, srcName, tgtName, 6);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按单位名称批量转换
|
||||
*
|
||||
* @param values 待转换的值列表
|
||||
* @param srcName 源单位名称
|
||||
* @param tgtName 目标单位名称
|
||||
* @param precision 精度(小数位数)
|
||||
* @return 转换后的值列表
|
||||
*/
|
||||
public List<BigDecimal> batchConvertByName(List<BigDecimal> values, String srcName, String tgtName, int precision) {
|
||||
log.debug("批量按名称转换: {} 个值, {} → {}", values.size(), srcName, tgtName);
|
||||
|
||||
// 加载数据
|
||||
List<UnitConversionDO> conversions = unitConversionMapper.selectList();
|
||||
List<QuantityUnitRelationDO> relations = quantityUnitRelationMapper.selectList();
|
||||
List<UntInfoDO> units = untInfoMapper.selectList();
|
||||
|
||||
// 调用工具类
|
||||
List<UnitConversionUtil.ConversionResult> results = UnitConversionUtil.batchConvertByName(
|
||||
values, srcName, tgtName, conversions, relations, units, precision
|
||||
);
|
||||
|
||||
// 提取转换后的值
|
||||
return results.stream()
|
||||
.map(UnitConversionUtil.ConversionResult::getValue)
|
||||
.toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 按单位符号转换(返回完整结果)
|
||||
*
|
||||
* @param value 待转换的值
|
||||
* @param srcSymbol 源单位符号
|
||||
* @param tgtSymbol 目标单位符号
|
||||
* @param precision 精度(小数位数)
|
||||
* @return 转换结果(包含值、因子、策略等)
|
||||
*/
|
||||
public UnitConversionUtil.ConversionResult convertBySymbolWithDetails(
|
||||
BigDecimal value, String srcSymbol, String tgtSymbol, int precision) {
|
||||
|
||||
// 加载数据
|
||||
List<UnitConversionDO> conversions = unitConversionMapper.selectList();
|
||||
List<QuantityUnitRelationDO> relations = quantityUnitRelationMapper.selectList();
|
||||
List<UntInfoDO> units = untInfoMapper.selectList();
|
||||
|
||||
// 调用工具类
|
||||
return UnitConversionUtil.convertBySymbol(
|
||||
value, srcSymbol, tgtSymbol, conversions, relations, units, precision
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按单位名称转换(返回完整结果)
|
||||
*
|
||||
* @param value 待转换的值
|
||||
* @param srcName 源单位名称
|
||||
* @param tgtName 目标单位名称
|
||||
* @param precision 精度(小数位数)
|
||||
* @return 转换结果(包含值、因子、策略等)
|
||||
*/
|
||||
public UnitConversionUtil.ConversionResult convertByNameWithDetails(
|
||||
BigDecimal value, String srcName, String tgtName, int precision) {
|
||||
|
||||
// 加载数据
|
||||
List<UnitConversionDO> conversions = unitConversionMapper.selectList();
|
||||
List<QuantityUnitRelationDO> relations = quantityUnitRelationMapper.selectList();
|
||||
List<UntInfoDO> units = untInfoMapper.selectList();
|
||||
|
||||
// 调用工具类
|
||||
return UnitConversionUtil.convertByName(
|
||||
value, srcName, tgtName, conversions, relations, units, precision
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package com.zt.plat.module.base.service.unitConversion;
|
||||
|
||||
import java.util.*;
|
||||
import jakarta.validation.*;
|
||||
import com.zt.plat.module.base.controller.admin.unitConversion.vo.*;
|
||||
import com.zt.plat.module.base.dal.dataobject.unitConversion.UnitConversionDO;
|
||||
import com.zt.plat.framework.common.pojo.PageResult;
|
||||
|
||||
/**
|
||||
* 单位转换 Service 接口
|
||||
*
|
||||
* @author 后台管理-1
|
||||
*/
|
||||
public interface UnitConversionService {
|
||||
|
||||
/**
|
||||
* 创建单位转换
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
UnitConversionRespVO createUnitConversion(@Valid UnitConversionSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新单位转换
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateUnitConversion(@Valid UnitConversionSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除单位转换
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteUnitConversion(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除单位转换
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void deleteUnitConversionListByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得单位转换
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 单位转换
|
||||
*/
|
||||
UnitConversionDO getUnitConversion(Long id);
|
||||
|
||||
/**
|
||||
* 获得单位转换分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 单位转换分页
|
||||
*/
|
||||
PageResult<UnitConversionDO> getUnitConversionPage(UnitConversionPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 单位转换
|
||||
*
|
||||
* @param convertReqVO 转换请求
|
||||
* @return 转换结果
|
||||
*/
|
||||
UnitConvertRespVO convert(@Valid UnitConvertReqVO convertReqVO);
|
||||
|
||||
/**
|
||||
* 批量单位转换
|
||||
*
|
||||
* @param batchReqVO 批量转换请求
|
||||
* @return 批量转换结果
|
||||
*/
|
||||
BatchUnitConvertRespVO batchConvert(@Valid BatchUnitConvertReqVO batchReqVO);
|
||||
|
||||
/**
|
||||
* 按单位符号转换
|
||||
*
|
||||
* @param reqVO 转换请求
|
||||
* @return 转换结果
|
||||
*/
|
||||
UnitConvertRespVO convertBySymbol(@Valid UnitConvertBySymbolReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 按单位名称转换
|
||||
*
|
||||
* @param reqVO 转换请求
|
||||
* @return 转换结果
|
||||
*/
|
||||
UnitConvertRespVO convertByName(@Valid UnitConvertByNameReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 批量按单位符号转换
|
||||
*
|
||||
* @param reqVO 批量转换请求
|
||||
* @return 批量转换结果
|
||||
*/
|
||||
BatchUnitConvertRespVO batchConvertBySymbol(@Valid BatchUnitConvertBySymbolReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 批量按单位名称转换
|
||||
*
|
||||
* @param reqVO 批量转换请求
|
||||
* @return 批量转换结果
|
||||
*/
|
||||
BatchUnitConvertRespVO batchConvertByName(@Valid BatchUnitConvertByNameReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 校验量纲内所有单位的转换路径
|
||||
*
|
||||
* @param quantityId 量纲ID
|
||||
* @return 校验结果
|
||||
*/
|
||||
UnitConversionValidationRespVO validateConversionPaths(Long quantityId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,615 @@
|
||||
package com.zt.plat.module.base.service.unitConversion;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.*;
|
||||
import com.zt.plat.module.base.controller.admin.unitConversion.vo.*;
|
||||
import com.zt.plat.module.base.dal.dataobject.unitConversion.UnitConversionDO;
|
||||
import com.zt.plat.framework.common.pojo.PageResult;
|
||||
import com.zt.plat.framework.common.util.object.BeanUtils;
|
||||
|
||||
import com.zt.plat.module.base.dal.dao.unitConversion.UnitConversionMapper;
|
||||
import com.zt.plat.module.base.dal.dao.quantityUnitRelation.QuantityUnitRelationMapper;
|
||||
import com.zt.plat.module.base.dal.dao.untInfo.UntInfoMapper;
|
||||
import com.zt.plat.module.base.dal.dataobject.quantityUnitRelation.QuantityUnitRelationDO;
|
||||
import com.zt.plat.module.base.dal.dataobject.untInfo.UntInfoDO;
|
||||
import com.zt.plat.module.base.dal.dataobject.unitQuantity.UnitQuantityDO;
|
||||
import com.zt.plat.module.base.service.unitQuantity.UnitQuantityService;
|
||||
import com.zt.plat.module.base.util.UnitConversionUtil;
|
||||
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static com.zt.plat.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static com.zt.plat.module.unitmanagement.enums.UnitErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 单位转换 Service 实现类
|
||||
*
|
||||
* @author 后台管理-1
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
@Slf4j
|
||||
public class UnitConversionServiceImpl implements UnitConversionService {
|
||||
|
||||
@Resource
|
||||
private UnitConversionMapper unitConversionMapper;
|
||||
|
||||
@Resource
|
||||
private QuantityUnitRelationMapper quantityUnitRelationMapper;
|
||||
|
||||
@Resource
|
||||
private UntInfoMapper untInfoMapper;
|
||||
|
||||
@Resource
|
||||
private UnitQuantityService unitQuantityService;
|
||||
|
||||
@Override
|
||||
public UnitConversionRespVO createUnitConversion(UnitConversionSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
UnitConversionDO unitConversion = BeanUtils.toBean(createReqVO, UnitConversionDO.class);
|
||||
unitConversionMapper.insert(unitConversion);
|
||||
// 返回
|
||||
return BeanUtils.toBean(unitConversion, UnitConversionRespVO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUnitConversion(UnitConversionSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateUnitConversionExists(updateReqVO.getId());
|
||||
// 更新
|
||||
UnitConversionDO updateObj = BeanUtils.toBean(updateReqVO, UnitConversionDO.class);
|
||||
unitConversionMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteUnitConversion(Long id) {
|
||||
// 校验存在
|
||||
validateUnitConversionExists(id);
|
||||
// 删除
|
||||
unitConversionMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteUnitConversionListByIds(List<Long> ids) {
|
||||
// 校验存在
|
||||
validateUnitConversionExists(ids);
|
||||
// 删除
|
||||
unitConversionMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
private void validateUnitConversionExists(List<Long> ids) {
|
||||
List<UnitConversionDO> list = unitConversionMapper.selectByIds(ids);
|
||||
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
|
||||
throw exception(UNIT_CONVERSION_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateUnitConversionExists(Long id) {
|
||||
if (unitConversionMapper.selectById(id) == null) {
|
||||
throw exception(UNIT_CONVERSION_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitConversionDO getUnitConversion(Long id) {
|
||||
return unitConversionMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<UnitConversionDO> getUnitConversionPage(UnitConversionPageReqVO pageReqVO) {
|
||||
return unitConversionMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitConvertRespVO convert(UnitConvertReqVO convertReqVO) {
|
||||
log.info("开始单位转换: 源单位ID={}, 目标单位ID={}, 值={}",
|
||||
convertReqVO.getSrcUntId(), convertReqVO.getTgtUntId(), convertReqVO.getValue());
|
||||
|
||||
// 1. 查询所有转换规则和关联关系
|
||||
List<UnitConversionDO> conversions = unitConversionMapper.selectList();
|
||||
List<QuantityUnitRelationDO> relations = quantityUnitRelationMapper.selectList();
|
||||
|
||||
// 2. 使用工具类进行转换
|
||||
UnitConversionUtil.ConversionResult result = UnitConversionUtil.convert(
|
||||
convertReqVO.getValue(),
|
||||
convertReqVO.getSrcUntId(),
|
||||
convertReqVO.getTgtUntId(),
|
||||
conversions,
|
||||
relations,
|
||||
convertReqVO.getPrecision() != null ? convertReqVO.getPrecision() : 6
|
||||
);
|
||||
|
||||
// 3. 查询单位信息
|
||||
UntInfoDO srcUnit = untInfoMapper.selectById(convertReqVO.getSrcUntId());
|
||||
UntInfoDO tgtUnit = untInfoMapper.selectById(convertReqVO.getTgtUntId());
|
||||
|
||||
// 4. 构建响应
|
||||
return UnitConvertRespVO.builder()
|
||||
.srcUntId(convertReqVO.getSrcUntId())
|
||||
.srcUntName(srcUnit != null ? srcUnit.getName() : null)
|
||||
.srcUntSmb(srcUnit != null ? srcUnit.getSmb() : null)
|
||||
.tgtUntId(convertReqVO.getTgtUntId())
|
||||
.tgtUntName(tgtUnit != null ? tgtUnit.getName() : null)
|
||||
.tgtUntSmb(tgtUnit != null ? tgtUnit.getSmb() : null)
|
||||
.originalValue(convertReqVO.getValue())
|
||||
.convertedValue(result.getValue())
|
||||
.factor(result.getFactor())
|
||||
.formula(result.getFormula())
|
||||
.strategy(result.getStrategy().name())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BatchUnitConvertRespVO batchConvert(BatchUnitConvertReqVO batchReqVO) {
|
||||
log.info("开始批量单位转换: 转换项数量={}, 忽略错误={}",
|
||||
batchReqVO.getItems().size(), batchReqVO.getIgnoreErrors());
|
||||
|
||||
List<BatchUnitConvertRespVO.UnitConvertResultItem> results = new ArrayList<>();
|
||||
int successCount = 0;
|
||||
int failureCount = 0;
|
||||
|
||||
for (UnitConvertReqVO item : batchReqVO.getItems()) {
|
||||
try {
|
||||
// 执行转换
|
||||
UnitConvertRespVO convertResult = convert(item);
|
||||
|
||||
// 构建成功结果
|
||||
results.add(BatchUnitConvertRespVO.UnitConvertResultItem.builder()
|
||||
.success(true)
|
||||
.data(convertResult)
|
||||
.request(item)
|
||||
.build());
|
||||
|
||||
successCount++;
|
||||
} catch (Exception e) {
|
||||
log.warn("单位转换失败: 源单位ID={}, 目标单位ID={}, 错误={}",
|
||||
item.getSrcUntId(), item.getTgtUntId(), e.getMessage());
|
||||
|
||||
// 构建失败结果
|
||||
results.add(BatchUnitConvertRespVO.UnitConvertResultItem.builder()
|
||||
.success(false)
|
||||
.errorMessage(e.getMessage())
|
||||
.request(item)
|
||||
.build());
|
||||
|
||||
failureCount++;
|
||||
|
||||
// 如果不忽略错误,直接抛出异常
|
||||
if (!Boolean.TRUE.equals(batchReqVO.getIgnoreErrors())) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return BatchUnitConvertRespVO.builder()
|
||||
.results(results)
|
||||
.successCount(successCount)
|
||||
.failureCount(failureCount)
|
||||
.totalCount(batchReqVO.getItems().size())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitConvertRespVO convertBySymbol(UnitConvertBySymbolReqVO reqVO) {
|
||||
log.info("开始按符号转换: 源单位符号={}, 目标单位符号={}, 值={}",
|
||||
reqVO.getSrcUnitSymbol(), reqVO.getTgtUnitSymbol(), reqVO.getValue());
|
||||
|
||||
// 1. 查询所有转换规则、关联关系和单位信息
|
||||
List<UnitConversionDO> conversions = unitConversionMapper.selectList();
|
||||
List<QuantityUnitRelationDO> relations = quantityUnitRelationMapper.selectList();
|
||||
List<UntInfoDO> units = untInfoMapper.selectList();
|
||||
|
||||
// 2. 使用工具类进行转换
|
||||
UnitConversionUtil.ConversionResult result = UnitConversionUtil.convertBySymbol(
|
||||
reqVO.getValue(),
|
||||
reqVO.getSrcUnitSymbol(),
|
||||
reqVO.getTgtUnitSymbol(),
|
||||
conversions,
|
||||
relations,
|
||||
units,
|
||||
reqVO.getPrecision() != null ? reqVO.getPrecision() : 6
|
||||
);
|
||||
|
||||
// 3. 构建响应
|
||||
return UnitConvertRespVO.builder()
|
||||
.srcUntName(reqVO.getSrcUnitSymbol())
|
||||
.srcUntSmb(reqVO.getSrcUnitSymbol())
|
||||
.tgtUntName(reqVO.getTgtUnitSymbol())
|
||||
.tgtUntSmb(reqVO.getTgtUnitSymbol())
|
||||
.originalValue(reqVO.getValue())
|
||||
.convertedValue(result.getValue())
|
||||
.factor(result.getFactor())
|
||||
.formula(result.getFormula())
|
||||
.strategy(result.getStrategy().name())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitConvertRespVO convertByName(UnitConvertByNameReqVO reqVO) {
|
||||
log.info("开始按名称转换: 源单位名称={}, 目标单位名称={}, 值={}",
|
||||
reqVO.getSrcUnitName(), reqVO.getTgtUnitName(), reqVO.getValue());
|
||||
|
||||
// 1. 查询所有转换规则、关联关系和单位信息
|
||||
List<UnitConversionDO> conversions = unitConversionMapper.selectList();
|
||||
List<QuantityUnitRelationDO> relations = quantityUnitRelationMapper.selectList();
|
||||
List<UntInfoDO> units = untInfoMapper.selectList();
|
||||
|
||||
// 2. 使用工具类进行转换
|
||||
UnitConversionUtil.ConversionResult result = UnitConversionUtil.convertByName(
|
||||
reqVO.getValue(),
|
||||
reqVO.getSrcUnitName(),
|
||||
reqVO.getTgtUnitName(),
|
||||
conversions,
|
||||
relations,
|
||||
units,
|
||||
reqVO.getPrecision() != null ? reqVO.getPrecision() : 6
|
||||
);
|
||||
|
||||
// 3. 构建响应
|
||||
return UnitConvertRespVO.builder()
|
||||
.srcUntName(reqVO.getSrcUnitName())
|
||||
.tgtUntName(reqVO.getTgtUnitName())
|
||||
.originalValue(reqVO.getValue())
|
||||
.convertedValue(result.getValue())
|
||||
.factor(result.getFactor())
|
||||
.formula(result.getFormula())
|
||||
.strategy(result.getStrategy().name())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BatchUnitConvertRespVO batchConvertBySymbol(BatchUnitConvertBySymbolReqVO reqVO) {
|
||||
log.info("开始批量按符号转换: 源单位符号={}, 目标单位符号={}, 值数量={}",
|
||||
reqVO.getSrcUnitSymbol(), reqVO.getTgtUnitSymbol(), reqVO.getValues().size());
|
||||
|
||||
List<BatchUnitConvertRespVO.UnitConvertResultItem> results = new ArrayList<>();
|
||||
int successCount = 0;
|
||||
int failureCount = 0;
|
||||
|
||||
// 1. 查询所有转换规则、关联关系和单位信息(只查询一次)
|
||||
List<UnitConversionDO> conversions = unitConversionMapper.selectList();
|
||||
List<QuantityUnitRelationDO> relations = quantityUnitRelationMapper.selectList();
|
||||
List<UntInfoDO> units = untInfoMapper.selectList();
|
||||
|
||||
for (BigDecimal value : reqVO.getValues()) {
|
||||
try {
|
||||
// 2. 使用工具类进行转换
|
||||
UnitConversionUtil.ConversionResult result = UnitConversionUtil.convertBySymbol(
|
||||
value,
|
||||
reqVO.getSrcUnitSymbol(),
|
||||
reqVO.getTgtUnitSymbol(),
|
||||
conversions,
|
||||
relations,
|
||||
units,
|
||||
reqVO.getPrecision() != null ? reqVO.getPrecision() : 6
|
||||
);
|
||||
|
||||
// 3. 构建成功结果
|
||||
results.add(BatchUnitConvertRespVO.UnitConvertResultItem.builder()
|
||||
.success(true)
|
||||
.data(UnitConvertRespVO.builder()
|
||||
.srcUntSmb(reqVO.getSrcUnitSymbol())
|
||||
.tgtUntSmb(reqVO.getTgtUnitSymbol())
|
||||
.originalValue(value)
|
||||
.convertedValue(result.getValue())
|
||||
.factor(result.getFactor())
|
||||
.strategy(result.getStrategy().name())
|
||||
.build())
|
||||
.build());
|
||||
successCount++;
|
||||
} catch (Exception e) {
|
||||
log.warn("按符号转换失败: 源单位符号={}, 目标单位符号={}, 值={}, 错误={}",
|
||||
reqVO.getSrcUnitSymbol(), reqVO.getTgtUnitSymbol(), value, e.getMessage());
|
||||
|
||||
// 4. 构建失败结果
|
||||
results.add(BatchUnitConvertRespVO.UnitConvertResultItem.builder()
|
||||
.success(false)
|
||||
.errorMessage(e.getMessage())
|
||||
.build());
|
||||
failureCount++;
|
||||
|
||||
// 5. 如果不忽略错误,直接抛出异常
|
||||
if (!Boolean.TRUE.equals(reqVO.getIgnoreErrors())) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return BatchUnitConvertRespVO.builder()
|
||||
.results(results)
|
||||
.successCount(successCount)
|
||||
.failureCount(failureCount)
|
||||
.totalCount(reqVO.getValues().size())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BatchUnitConvertRespVO batchConvertByName(BatchUnitConvertByNameReqVO reqVO) {
|
||||
log.info("开始批量按名称转换: 源单位名称={}, 目标单位名称={}, 值数量={}",
|
||||
reqVO.getSrcUnitName(), reqVO.getTgtUnitName(), reqVO.getValues().size());
|
||||
|
||||
List<BatchUnitConvertRespVO.UnitConvertResultItem> results = new ArrayList<>();
|
||||
int successCount = 0;
|
||||
int failureCount = 0;
|
||||
|
||||
// 1. 查询所有转换规则、关联关系和单位信息(只查询一次)
|
||||
List<UnitConversionDO> conversions = unitConversionMapper.selectList();
|
||||
List<QuantityUnitRelationDO> relations = quantityUnitRelationMapper.selectList();
|
||||
List<UntInfoDO> units = untInfoMapper.selectList();
|
||||
|
||||
for (BigDecimal value : reqVO.getValues()) {
|
||||
try {
|
||||
// 2. 使用工具类进行转换
|
||||
UnitConversionUtil.ConversionResult result = UnitConversionUtil.convertByName(
|
||||
value,
|
||||
reqVO.getSrcUnitName(),
|
||||
reqVO.getTgtUnitName(),
|
||||
conversions,
|
||||
relations,
|
||||
units,
|
||||
reqVO.getPrecision() != null ? reqVO.getPrecision() : 6
|
||||
);
|
||||
|
||||
// 3. 构建成功结果
|
||||
results.add(BatchUnitConvertRespVO.UnitConvertResultItem.builder()
|
||||
.success(true)
|
||||
.data(UnitConvertRespVO.builder()
|
||||
.srcUntName(reqVO.getSrcUnitName())
|
||||
.tgtUntName(reqVO.getTgtUnitName())
|
||||
.originalValue(value)
|
||||
.convertedValue(result.getValue())
|
||||
.factor(result.getFactor())
|
||||
.strategy(result.getStrategy().name())
|
||||
.build())
|
||||
.build());
|
||||
successCount++;
|
||||
} catch (Exception e) {
|
||||
log.warn("按名称转换失败: 源单位名称={}, 目标单位名称={}, 值={}, 错误={}",
|
||||
reqVO.getSrcUnitName(), reqVO.getTgtUnitName(), value, e.getMessage());
|
||||
|
||||
// 4. 构建失败结果
|
||||
results.add(BatchUnitConvertRespVO.UnitConvertResultItem.builder()
|
||||
.success(false)
|
||||
.errorMessage(e.getMessage())
|
||||
.build());
|
||||
failureCount++;
|
||||
|
||||
// 5. 如果不忽略错误,直接抛出异常
|
||||
if (!Boolean.TRUE.equals(reqVO.getIgnoreErrors())) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return BatchUnitConvertRespVO.builder()
|
||||
.results(results)
|
||||
.successCount(successCount)
|
||||
.failureCount(failureCount)
|
||||
.totalCount(reqVO.getValues().size())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitConversionValidationRespVO validateConversionPaths(Long quantityId) {
|
||||
log.info("开始校验量纲 {} 的转换路径", quantityId);
|
||||
|
||||
// 1. 查询量纲信息
|
||||
UnitQuantityDO quantity = unitQuantityService.getUnitQuantity(quantityId);
|
||||
if (quantity == null) {
|
||||
throw exception(UNIT_QUANTITY_NOT_EXISTS);
|
||||
}
|
||||
|
||||
// 2. 查询该量纲下的所有单位
|
||||
List<QuantityUnitRelationDO> relations = quantityUnitRelationMapper.selectList(
|
||||
new LambdaQueryWrapperX<QuantityUnitRelationDO>()
|
||||
.eq(QuantityUnitRelationDO::getUntQtyId, quantityId)
|
||||
);
|
||||
|
||||
if (CollUtil.isEmpty(relations)) {
|
||||
return buildEmptyValidationResult(quantityId, quantity);
|
||||
}
|
||||
|
||||
// 3. 获取单位详细信息
|
||||
List<Long> unitIds = relations.stream()
|
||||
.map(QuantityUnitRelationDO::getUntId)
|
||||
.collect(Collectors.toList());
|
||||
List<UntInfoDO> units = untInfoMapper.selectByIds(unitIds);
|
||||
Map<Long, UntInfoDO> unitMap = units.stream()
|
||||
.collect(Collectors.toMap(UntInfoDO::getId, u -> u));
|
||||
|
||||
// 4. 找到基准单位
|
||||
QuantityUnitRelationDO baseRelation = relations.stream()
|
||||
.filter(r -> r.getIsBse() == 1)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
UnitConversionValidationRespVO.BaseUnitInfo baseUnitInfo = null;
|
||||
Long baseUnitId = null;
|
||||
if (baseRelation != null) {
|
||||
UntInfoDO baseUnit = unitMap.get(baseRelation.getUntId());
|
||||
baseUnitId = baseRelation.getUntId();
|
||||
if (baseUnit != null) {
|
||||
baseUnitInfo = UnitConversionValidationRespVO.BaseUnitInfo.builder()
|
||||
.unitId(baseUnit.getId())
|
||||
.unitName(baseUnit.getName())
|
||||
.unitSymbol(baseUnit.getSmb())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 查询该量纲下的所有转换规则
|
||||
List<UnitConversionDO> conversions = unitConversionMapper.selectList(
|
||||
new LambdaQueryWrapperX<UnitConversionDO>()
|
||||
.eq(UnitConversionDO::getUntQtyId, quantityId)
|
||||
);
|
||||
|
||||
// 6. 检查所有单位对之间的转换路径(两两互相转换)
|
||||
List<UnitConversionValidationRespVO.UnconvertibleUnitInfo> unconvertibleUnits = new ArrayList<>();
|
||||
List<UnitConversionValidationRespVO.ConversionPathInfo> conversionPaths = new ArrayList<>();
|
||||
|
||||
// 统计:能够互相转换的单位数量
|
||||
Set<Long> fullyConvertibleUnits = new HashSet<>();
|
||||
|
||||
// 遍历所有单位对
|
||||
for (int i = 0; i < units.size(); i++) {
|
||||
UntInfoDO srcUnit = units.get(i);
|
||||
boolean canConvertToAll = true;
|
||||
|
||||
for (int j = 0; j < units.size(); j++) {
|
||||
if (i == j) continue; // 跳过自己
|
||||
|
||||
UntInfoDO tgtUnit = units.get(j);
|
||||
|
||||
// 尝试转换(使用工具类)
|
||||
boolean canConvert = canConvert(srcUnit.getId(), tgtUnit.getId(), conversions, relations, baseUnitId);
|
||||
|
||||
if (!canConvert) {
|
||||
canConvertToAll = false;
|
||||
// 只记录第一个方向的失败(避免重复:A→B 和 B→A)
|
||||
if (i < j) {
|
||||
unconvertibleUnits.add(UnitConversionValidationRespVO.UnconvertibleUnitInfo.builder()
|
||||
.unitId(srcUnit.getId())
|
||||
.unitName(srcUnit.getName())
|
||||
.unitSymbol(srcUnit.getSmb())
|
||||
.reason(String.format("无法转换到 %s", tgtUnit.getName()))
|
||||
.build());
|
||||
}
|
||||
} else {
|
||||
// 记录转换路径(只记录到基准单位的路径,避免太多)
|
||||
if (baseUnitId != null && tgtUnit.getId().equals(baseUnitId)) {
|
||||
String strategy = getConversionStrategy(srcUnit.getId(), tgtUnit.getId(), conversions, baseUnitId);
|
||||
conversionPaths.add(UnitConversionValidationRespVO.ConversionPathInfo.builder()
|
||||
.srcUnitId(srcUnit.getId())
|
||||
.srcUnitName(srcUnit.getName())
|
||||
.tgtUnitId(tgtUnit.getId())
|
||||
.tgtUnitName(tgtUnit.getName())
|
||||
.hasDirect(strategy.equals("DIRECT"))
|
||||
.hasViaBase(strategy.equals("VIA_BASE_UNIT"))
|
||||
.pathDescription(srcUnit.getName() + " → " + tgtUnit.getName() +
|
||||
(strategy.equals("DIRECT") ? " (直接转换)" : " (通过基准单位)"))
|
||||
.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (canConvertToAll) {
|
||||
fullyConvertibleUnits.add(srcUnit.getId());
|
||||
}
|
||||
}
|
||||
|
||||
// 7. 构建响应
|
||||
return UnitConversionValidationRespVO.builder()
|
||||
.quantityId(quantityId)
|
||||
.quantityName(quantity.getName())
|
||||
.quantitySymbol(quantity.getSymbol())
|
||||
.totalUnits(units.size())
|
||||
.convertibleUnits(fullyConvertibleUnits.size())
|
||||
.unconvertibleUnits(units.size() - fullyConvertibleUnits.size())
|
||||
.allConvertible(fullyConvertibleUnits.size() == units.size())
|
||||
.baseUnit(baseUnitInfo)
|
||||
.unconvertibleUnitList(unconvertibleUnits)
|
||||
.conversionPaths(conversionPaths)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查两个单位是否能够转换(考虑反向推导)
|
||||
*/
|
||||
private boolean canConvert(Long srcUnitId, Long tgtUnitId,
|
||||
List<UnitConversionDO> conversions,
|
||||
List<QuantityUnitRelationDO> relations,
|
||||
Long baseUnitId) {
|
||||
// 1. 检查直接转换(正向)
|
||||
boolean hasDirectForward = conversions.stream()
|
||||
.anyMatch(c -> c.getSrcUntId().equals(srcUnitId) && c.getTgtUntId().equals(tgtUnitId));
|
||||
if (hasDirectForward) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 2. 检查直接转换(反向,可以推导)
|
||||
boolean hasDirectReverse = conversions.stream()
|
||||
.anyMatch(c -> c.getSrcUntId().equals(tgtUnitId) && c.getTgtUntId().equals(srcUnitId));
|
||||
if (hasDirectReverse) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. 检查通过基准单位的间接转换
|
||||
if (baseUnitId == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 如果源单位是基准单位
|
||||
if (srcUnitId.equals(baseUnitId)) {
|
||||
// 检查是否有 基准 → 目标 的转换规则(正向或反向)
|
||||
boolean hasBaseToTgt = conversions.stream()
|
||||
.anyMatch(c -> c.getSrcUntId().equals(baseUnitId) && c.getTgtUntId().equals(tgtUnitId));
|
||||
boolean hasTgtToBase = conversions.stream()
|
||||
.anyMatch(c -> c.getSrcUntId().equals(tgtUnitId) && c.getTgtUntId().equals(baseUnitId));
|
||||
return hasBaseToTgt || hasTgtToBase;
|
||||
}
|
||||
|
||||
// 如果目标单位是基准单位
|
||||
if (tgtUnitId.equals(baseUnitId)) {
|
||||
// 检查是否有 源 → 基准 的转换规则(正向或反向)
|
||||
boolean hasSrcToBase = conversions.stream()
|
||||
.anyMatch(c -> c.getSrcUntId().equals(srcUnitId) && c.getTgtUntId().equals(baseUnitId));
|
||||
boolean hasBaseToSrc = conversions.stream()
|
||||
.anyMatch(c -> c.getSrcUntId().equals(baseUnitId) && c.getTgtUntId().equals(srcUnitId));
|
||||
return hasSrcToBase || hasBaseToSrc;
|
||||
}
|
||||
|
||||
// 两者都不是基准单位,需要两步转换:源 → 基准 → 目标
|
||||
// 检查 源 → 基准(正向或反向)
|
||||
boolean srcToBase = conversions.stream()
|
||||
.anyMatch(c -> c.getSrcUntId().equals(srcUnitId) && c.getTgtUntId().equals(baseUnitId));
|
||||
boolean baseToSrc = conversions.stream()
|
||||
.anyMatch(c -> c.getSrcUntId().equals(baseUnitId) && c.getTgtUntId().equals(srcUnitId));
|
||||
|
||||
// 检查 基准 → 目标(正向或反向)
|
||||
boolean baseToTgt = conversions.stream()
|
||||
.anyMatch(c -> c.getSrcUntId().equals(baseUnitId) && c.getTgtUntId().equals(tgtUnitId));
|
||||
boolean tgtToBase = conversions.stream()
|
||||
.anyMatch(c -> c.getSrcUntId().equals(tgtUnitId) && c.getTgtUntId().equals(baseUnitId));
|
||||
|
||||
return (srcToBase || baseToSrc) && (baseToTgt || tgtToBase);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取转换策略
|
||||
*/
|
||||
private String getConversionStrategy(Long srcUnitId, Long tgtUnitId,
|
||||
List<UnitConversionDO> conversions,
|
||||
Long baseUnitId) {
|
||||
// 检查直接转换
|
||||
boolean hasDirect = conversions.stream()
|
||||
.anyMatch(c -> c.getSrcUntId().equals(srcUnitId) && c.getTgtUntId().equals(tgtUnitId));
|
||||
if (hasDirect) {
|
||||
return "DIRECT";
|
||||
}
|
||||
return "VIA_BASE_UNIT";
|
||||
}
|
||||
|
||||
private UnitConversionValidationRespVO buildEmptyValidationResult(Long quantityId, UnitQuantityDO quantity) {
|
||||
return UnitConversionValidationRespVO.builder()
|
||||
.quantityId(quantityId)
|
||||
.quantityName(quantity.getName())
|
||||
.quantitySymbol(quantity.getSymbol())
|
||||
.totalUnits(0)
|
||||
.convertibleUnits(0)
|
||||
.unconvertibleUnits(0)
|
||||
.allConvertible(true)
|
||||
.baseUnit(null)
|
||||
.unconvertibleUnitList(new ArrayList<>())
|
||||
.conversionPaths(new ArrayList<>())
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.zt.plat.module.base.service.unitQuantity;
|
||||
|
||||
import java.util.*;
|
||||
import jakarta.validation.*;
|
||||
import com.zt.plat.module.base.controller.admin.unitQuantity.vo.*;
|
||||
import com.zt.plat.module.base.dal.dataobject.unitQuantity.UnitQuantityDO;
|
||||
import com.zt.plat.framework.common.pojo.PageResult;
|
||||
|
||||
/**
|
||||
* 计量单位量 Service 接口
|
||||
*
|
||||
* @author 后台管理-1
|
||||
*/
|
||||
public interface UnitQuantityService {
|
||||
|
||||
/**
|
||||
* 创建计量单位量
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
UnitQuantityRespVO createUnitQuantity(@Valid UnitQuantitySaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新计量单位量
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateUnitQuantity(@Valid UnitQuantitySaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除计量单位量
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteUnitQuantity(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除计量单位量
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void deleteUnitQuantityListByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得计量单位量
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 计量单位量
|
||||
*/
|
||||
UnitQuantityDO getUnitQuantity(Long id);
|
||||
|
||||
/**
|
||||
* 获得计量单位量分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 计量单位量分页
|
||||
*/
|
||||
PageResult<UnitQuantityDO> getUnitQuantityPage(UnitQuantityPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 获取量纲及单位树
|
||||
*
|
||||
* @return 量纲及单位树列表
|
||||
*/
|
||||
List<UnitQuantityTreeRespVO> getUnitQuantityTree();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
package com.zt.plat.module.base.service.unitQuantity;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.*;
|
||||
import com.zt.plat.module.base.controller.admin.unitQuantity.vo.*;
|
||||
import com.zt.plat.module.base.dal.dataobject.unitQuantity.UnitQuantityDO;
|
||||
import com.zt.plat.framework.common.pojo.PageResult;
|
||||
import com.zt.plat.framework.common.util.object.BeanUtils;
|
||||
|
||||
import com.zt.plat.module.base.dal.dao.unitQuantity.UnitQuantityMapper;
|
||||
import com.zt.plat.module.base.dal.dao.quantityUnitRelation.QuantityUnitRelationMapper;
|
||||
import com.zt.plat.module.base.dal.dao.untInfo.UntInfoMapper;
|
||||
import com.zt.plat.module.base.dal.dataobject.quantityUnitRelation.QuantityUnitRelationDO;
|
||||
import com.zt.plat.module.base.dal.dataobject.untInfo.UntInfoDO;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static com.zt.plat.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static com.zt.plat.module.unitmanagement.enums.UnitErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 计量单位量 Service 实现类
|
||||
*
|
||||
* @author 后台管理-1
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class UnitQuantityServiceImpl implements UnitQuantityService {
|
||||
|
||||
@Resource
|
||||
private UnitQuantityMapper unitQuantityMapper;
|
||||
|
||||
@Resource
|
||||
private QuantityUnitRelationMapper quantityUnitRelationMapper;
|
||||
|
||||
@Resource
|
||||
private UntInfoMapper untInfoMapper;
|
||||
|
||||
@Override
|
||||
public UnitQuantityRespVO createUnitQuantity(UnitQuantitySaveReqVO createReqVO) {
|
||||
// 插入
|
||||
UnitQuantityDO unitQuantity = BeanUtils.toBean(createReqVO, UnitQuantityDO.class);
|
||||
unitQuantityMapper.insert(unitQuantity);
|
||||
// 返回
|
||||
return BeanUtils.toBean(unitQuantity, UnitQuantityRespVO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUnitQuantity(UnitQuantitySaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateUnitQuantityExists(updateReqVO.getId());
|
||||
// 更新
|
||||
UnitQuantityDO updateObj = BeanUtils.toBean(updateReqVO, UnitQuantityDO.class);
|
||||
unitQuantityMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteUnitQuantity(Long id) {
|
||||
// 校验存在
|
||||
validateUnitQuantityExists(id);
|
||||
// 删除
|
||||
unitQuantityMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteUnitQuantityListByIds(List<Long> ids) {
|
||||
// 校验存在
|
||||
validateUnitQuantityExists(ids);
|
||||
// 删除
|
||||
unitQuantityMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
private void validateUnitQuantityExists(List<Long> ids) {
|
||||
List<UnitQuantityDO> list = unitQuantityMapper.selectByIds(ids);
|
||||
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
|
||||
throw exception(UNIT_QUANTITY_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateUnitQuantityExists(Long id) {
|
||||
if (unitQuantityMapper.selectById(id) == null) {
|
||||
throw exception(UNIT_QUANTITY_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitQuantityDO getUnitQuantity(Long id) {
|
||||
return unitQuantityMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<UnitQuantityDO> getUnitQuantityPage(UnitQuantityPageReqVO pageReqVO) {
|
||||
return unitQuantityMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UnitQuantityTreeRespVO> getUnitQuantityTree() {
|
||||
// 1. 查询所有量纲
|
||||
List<UnitQuantityDO> quantities = unitQuantityMapper.selectList();
|
||||
|
||||
// 2. 查询所有关联关系
|
||||
List<QuantityUnitRelationDO> relations = quantityUnitRelationMapper.selectList();
|
||||
|
||||
// 3. 查询所有单位
|
||||
List<UntInfoDO> units = untInfoMapper.selectList();
|
||||
Map<Long, UntInfoDO> unitMap = units.stream()
|
||||
.collect(Collectors.toMap(UntInfoDO::getId, u -> u));
|
||||
|
||||
// 4. 组装树形结构
|
||||
return quantities.stream().map(quantity -> {
|
||||
UnitQuantityTreeRespVO treeVO = new UnitQuantityTreeRespVO();
|
||||
treeVO.setId(quantity.getId());
|
||||
treeVO.setName(quantity.getName());
|
||||
treeVO.setSymbol(quantity.getSymbol());
|
||||
treeVO.setDsp(quantity.getDsp());
|
||||
|
||||
// 获取该量纲下的所有单位
|
||||
List<UnitQuantityTreeRespVO.UnitItemVO> unitItems = relations.stream()
|
||||
.filter(r -> r.getUntQtyId().equals(quantity.getId()))
|
||||
.map(r -> {
|
||||
UnitQuantityTreeRespVO.UnitItemVO unitItem = new UnitQuantityTreeRespVO.UnitItemVO();
|
||||
unitItem.setRelationId(r.getId());
|
||||
unitItem.setId(r.getUntId());
|
||||
unitItem.setIsBse(r.getIsBse());
|
||||
|
||||
// 填充单位信息
|
||||
UntInfoDO unit = unitMap.get(r.getUntId());
|
||||
if (unit != null) {
|
||||
unitItem.setName(unit.getName());
|
||||
unitItem.setSmb(unit.getSmb());
|
||||
}
|
||||
|
||||
return unitItem;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
treeVO.setUnits(unitItems);
|
||||
return treeVO;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.zt.plat.module.base.service.untInfo;
|
||||
|
||||
import java.util.*;
|
||||
import jakarta.validation.*;
|
||||
import com.zt.plat.module.base.controller.admin.untInfo.vo.*;
|
||||
import com.zt.plat.module.base.dal.dataobject.untInfo.UntInfoDO;
|
||||
import com.zt.plat.framework.common.pojo.PageResult;
|
||||
|
||||
/**
|
||||
* 计量单位 Service 接口
|
||||
*
|
||||
* @author 后台管理-1
|
||||
*/
|
||||
public interface UntInfoService {
|
||||
|
||||
/**
|
||||
* 创建计量单位
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
UntInfoRespVO createUntInfo(@Valid UntInfoSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新计量单位
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateUntInfo(@Valid UntInfoSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除计量单位
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteUntInfo(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除计量单位
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void deleteUntInfoListByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得计量单位
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 计量单位
|
||||
*/
|
||||
UntInfoDO getUntInfo(Long id);
|
||||
|
||||
/**
|
||||
* 获得计量单位分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 计量单位分页
|
||||
*/
|
||||
PageResult<UntInfoDO> getUntInfoPage(UntInfoPageReqVO pageReqVO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.zt.plat.module.base.service.untInfo;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.*;
|
||||
import com.zt.plat.module.base.controller.admin.untInfo.vo.*;
|
||||
import com.zt.plat.module.base.dal.dataobject.untInfo.UntInfoDO;
|
||||
import com.zt.plat.framework.common.pojo.PageResult;
|
||||
import com.zt.plat.framework.common.util.object.BeanUtils;
|
||||
|
||||
import com.zt.plat.module.base.dal.dao.untInfo.UntInfoMapper;
|
||||
|
||||
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static com.zt.plat.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static com.zt.plat.module.unitmanagement.enums.UnitErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 计量单位 Service 实现类
|
||||
*
|
||||
* @author 后台管理-1
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class UntInfoServiceImpl implements UntInfoService {
|
||||
|
||||
@Resource
|
||||
private UntInfoMapper untInfoMapper;
|
||||
|
||||
@Override
|
||||
public UntInfoRespVO createUntInfo(UntInfoSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
UntInfoDO untInfo = BeanUtils.toBean(createReqVO, UntInfoDO.class);
|
||||
untInfoMapper.insert(untInfo);
|
||||
// 返回
|
||||
return BeanUtils.toBean(untInfo, UntInfoRespVO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUntInfo(UntInfoSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateUntInfoExists(updateReqVO.getId());
|
||||
// 更新
|
||||
UntInfoDO updateObj = BeanUtils.toBean(updateReqVO, UntInfoDO.class);
|
||||
untInfoMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteUntInfo(Long id) {
|
||||
// 校验存在
|
||||
validateUntInfoExists(id);
|
||||
// 删除
|
||||
untInfoMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteUntInfoListByIds(List<Long> ids) {
|
||||
// 校验存在
|
||||
validateUntInfoExists(ids);
|
||||
// 删除
|
||||
untInfoMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
private void validateUntInfoExists(List<Long> ids) {
|
||||
List<UntInfoDO> list = untInfoMapper.selectByIds(ids);
|
||||
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
|
||||
throw exception(UNT_INFO_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateUntInfoExists(Long id) {
|
||||
if (untInfoMapper.selectById(id) == null) {
|
||||
throw exception(UNT_INFO_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UntInfoDO getUntInfo(Long id) {
|
||||
return untInfoMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<UntInfoDO> getUntInfoPage(UntInfoPageReqVO pageReqVO) {
|
||||
return untInfoMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,406 @@
|
||||
package com.zt.plat.module.base.util;
|
||||
|
||||
import com.zt.plat.module.base.dal.dataobject.unitConversion.UnitConversionDO;
|
||||
import com.zt.plat.module.base.dal.dataobject.quantityUnitRelation.QuantityUnitRelationDO;
|
||||
import com.zt.plat.module.base.dal.dataobject.untInfo.UntInfoDO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static com.zt.plat.module.unitmanagement.enums.UnitErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 单位转换工具类
|
||||
*
|
||||
* <p>支持三种转换策略:
|
||||
* <ul>
|
||||
* <li>直接转换:使用预定义的转换规则</li>
|
||||
* <li>基准单位转换:通过基准单位进行中转</li>
|
||||
* <li>公式转换:使用自定义转换公式</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author 系统
|
||||
*/
|
||||
@Slf4j
|
||||
public class UnitConversionUtil {
|
||||
|
||||
/**
|
||||
* 转换策略枚举
|
||||
*/
|
||||
public enum ConversionStrategy {
|
||||
/** 直接转换 */
|
||||
DIRECT,
|
||||
/** 基准单位转换 */
|
||||
VIA_BASE_UNIT,
|
||||
/** 公式转换 */
|
||||
FORMULA,
|
||||
/** 无法转换 */
|
||||
NONE
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换结果
|
||||
*/
|
||||
public static class ConversionResult {
|
||||
private final BigDecimal value;
|
||||
private final BigDecimal factor;
|
||||
private final ConversionStrategy strategy;
|
||||
private final String formula;
|
||||
|
||||
public ConversionResult(BigDecimal value, BigDecimal factor, ConversionStrategy strategy, String formula) {
|
||||
this.value = value;
|
||||
this.factor = factor;
|
||||
this.strategy = strategy;
|
||||
this.formula = formula;
|
||||
}
|
||||
|
||||
public BigDecimal getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public BigDecimal getFactor() {
|
||||
return factor;
|
||||
}
|
||||
|
||||
public ConversionStrategy getStrategy() {
|
||||
return strategy;
|
||||
}
|
||||
|
||||
public String getFormula() {
|
||||
return formula;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 单位转换
|
||||
*
|
||||
* @param value 待转换的值
|
||||
* @param srcUntId 源单位ID
|
||||
* @param tgtUntId 目标单位ID
|
||||
* @param conversions 转换规则列表
|
||||
* @param relations 量纲-单位关联关系列表
|
||||
* @param precision 精度(小数位数)
|
||||
* @return 转换结果
|
||||
*/
|
||||
public static ConversionResult convert(
|
||||
BigDecimal value,
|
||||
Long srcUntId,
|
||||
Long tgtUntId,
|
||||
List<UnitConversionDO> conversions,
|
||||
List<QuantityUnitRelationDO> relations,
|
||||
int precision) {
|
||||
|
||||
// 1. 如果源单位和目标单位相同,直接返回
|
||||
if (srcUntId.equals(tgtUntId)) {
|
||||
return new ConversionResult(value, BigDecimal.ONE, ConversionStrategy.DIRECT, "相同单位,无需转换");
|
||||
}
|
||||
|
||||
// 2. 尝试直接转换
|
||||
ConversionResult directResult = tryDirectConversion(value, srcUntId, tgtUntId, conversions, precision);
|
||||
if (directResult != null) {
|
||||
return directResult;
|
||||
}
|
||||
|
||||
// 3. 尝试通过基准单位转换
|
||||
ConversionResult viaBaseResult = tryViaBaseUnitConversion(value, srcUntId, tgtUntId, conversions, relations, precision);
|
||||
if (viaBaseResult != null) {
|
||||
return viaBaseResult;
|
||||
}
|
||||
|
||||
// 4. 无法转换 - 抛出业务异常
|
||||
log.warn("无法找到从单位 {} 到单位 {} 的转换路径", srcUntId, tgtUntId);
|
||||
throw exception(UNIT_CONVERSION_PATH_NOT_FOUND,
|
||||
"ID:" + srcUntId, "ID:" + tgtUntId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 尝试直接转换(支持自动反向推导)
|
||||
*/
|
||||
private static ConversionResult tryDirectConversion(
|
||||
BigDecimal value,
|
||||
Long srcUntId,
|
||||
Long tgtUntId,
|
||||
List<UnitConversionDO> conversions,
|
||||
int precision) {
|
||||
|
||||
// 1. 查找正向转换规则:源 → 目标
|
||||
UnitConversionDO forwardConversion = conversions.stream()
|
||||
.filter(c -> c.getSrcUntId().equals(srcUntId) && c.getTgtUntId().equals(tgtUntId))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if (forwardConversion != null) {
|
||||
BigDecimal factor = forwardConversion.getFctr();
|
||||
BigDecimal result = value.multiply(factor).setScale(precision, RoundingMode.HALF_UP);
|
||||
String formula = forwardConversion.getFmu() != null ? forwardConversion.getFmu() :
|
||||
String.format("value * %s", factor);
|
||||
|
||||
log.debug("直接转换(正向): {} (单位{}) * {} = {} (单位{})", value, srcUntId, factor, result, tgtUntId);
|
||||
return new ConversionResult(result, factor, ConversionStrategy.DIRECT, formula);
|
||||
}
|
||||
|
||||
// 2. 查找反向转换规则:目标 → 源,然后取倒数
|
||||
UnitConversionDO reverseConversion = conversions.stream()
|
||||
.filter(c -> c.getSrcUntId().equals(tgtUntId) && c.getTgtUntId().equals(srcUntId))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if (reverseConversion != null) {
|
||||
// 反向系数:如果 目标→源 的系数是 f,则 源→目标 的系数是 1/f
|
||||
BigDecimal reverseFactor = reverseConversion.getFctr();
|
||||
BigDecimal factor = BigDecimal.ONE.divide(reverseFactor, Math.max(precision + 10, 20), RoundingMode.HALF_UP);
|
||||
BigDecimal result = value.multiply(factor).setScale(precision, RoundingMode.HALF_UP);
|
||||
String formula = String.format("value / %s (反向推导)", reverseFactor);
|
||||
|
||||
log.debug("直接转换(反向推导): {} (单位{}) / {} = {} (单位{})", value, srcUntId, reverseFactor, result, tgtUntId);
|
||||
return new ConversionResult(result, factor, ConversionStrategy.DIRECT, formula);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 尝试通过基准单位转换
|
||||
*/
|
||||
private static ConversionResult tryViaBaseUnitConversion(
|
||||
BigDecimal value,
|
||||
Long srcUntId,
|
||||
Long tgtUntId,
|
||||
List<UnitConversionDO> conversions,
|
||||
List<QuantityUnitRelationDO> relations,
|
||||
int precision) {
|
||||
|
||||
// 1. 找到源单位和目标单位的量纲
|
||||
QuantityUnitRelationDO srcRelation = relations.stream()
|
||||
.filter(r -> r.getUntId().equals(srcUntId))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
QuantityUnitRelationDO tgtRelation = relations.stream()
|
||||
.filter(r -> r.getUntId().equals(tgtUntId))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if (srcRelation == null || tgtRelation == null) {
|
||||
log.warn("找不到单位 {} 或 {} 的量纲关联关系", srcUntId, tgtUntId);
|
||||
return null;
|
||||
}
|
||||
|
||||
// 2. 检查是否属于同一量纲
|
||||
if (!srcRelation.getUntQtyId().equals(tgtRelation.getUntQtyId())) {
|
||||
log.warn("单位 {} 和 {} 不属于同一量纲", srcUntId, tgtUntId);
|
||||
return null;
|
||||
}
|
||||
|
||||
// 3. 找到基准单位
|
||||
Long quantityId = srcRelation.getUntQtyId();
|
||||
QuantityUnitRelationDO baseRelation = relations.stream()
|
||||
.filter(r -> r.getUntQtyId().equals(quantityId) && r.getIsBse() == 1)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if (baseRelation == null) {
|
||||
log.warn("量纲 {} 没有设置基准单位", quantityId);
|
||||
return null;
|
||||
}
|
||||
|
||||
Long baseUnitId = baseRelation.getUntId();
|
||||
|
||||
// 4. 源单位 → 基准单位
|
||||
BigDecimal toBaseValue;
|
||||
BigDecimal toBaseFactor;
|
||||
if (srcUntId.equals(baseUnitId)) {
|
||||
toBaseValue = value;
|
||||
toBaseFactor = BigDecimal.ONE;
|
||||
} else {
|
||||
ConversionResult toBaseResult = tryDirectConversion(value, srcUntId, baseUnitId, conversions, precision);
|
||||
if (toBaseResult == null) {
|
||||
log.warn("无法从源单位 {} 转换到基准单位 {}", srcUntId, baseUnitId);
|
||||
return null;
|
||||
}
|
||||
toBaseValue = toBaseResult.getValue();
|
||||
toBaseFactor = toBaseResult.getFactor();
|
||||
}
|
||||
|
||||
// 5. 基准单位 → 目标单位
|
||||
BigDecimal finalValue;
|
||||
BigDecimal fromBaseFactor;
|
||||
if (tgtUntId.equals(baseUnitId)) {
|
||||
finalValue = toBaseValue;
|
||||
fromBaseFactor = BigDecimal.ONE;
|
||||
} else {
|
||||
ConversionResult fromBaseResult = tryDirectConversion(toBaseValue, baseUnitId, tgtUntId, conversions, precision);
|
||||
if (fromBaseResult == null) {
|
||||
log.warn("无法从基准单位 {} 转换到目标单位 {}", baseUnitId, tgtUntId);
|
||||
return null;
|
||||
}
|
||||
finalValue = fromBaseResult.getValue();
|
||||
fromBaseFactor = fromBaseResult.getFactor();
|
||||
}
|
||||
|
||||
// 6. 计算总转换因子
|
||||
BigDecimal totalFactor = toBaseFactor.multiply(fromBaseFactor);
|
||||
String formula = String.format("通过基准单位(ID:%d): value * %s * %s", baseUnitId, toBaseFactor, fromBaseFactor);
|
||||
|
||||
log.debug("基准单位转换: {} (单位{}) → {} (基准{}) → {} (单位{})",
|
||||
value, srcUntId, toBaseValue, baseUnitId, finalValue, tgtUntId);
|
||||
|
||||
return new ConversionResult(finalValue, totalFactor, ConversionStrategy.VIA_BASE_UNIT, formula);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量转换
|
||||
*
|
||||
* @param values 待转换的值列表
|
||||
* @param srcUntId 源单位ID
|
||||
* @param tgtUntId 目标单位ID
|
||||
* @param conversions 转换规则列表
|
||||
* @param relations 量纲-单位关联关系列表
|
||||
* @param precision 精度(小数位数)
|
||||
* @return 转换结果列表
|
||||
*/
|
||||
public static List<ConversionResult> batchConvert(
|
||||
List<BigDecimal> values,
|
||||
Long srcUntId,
|
||||
Long tgtUntId,
|
||||
List<UnitConversionDO> conversions,
|
||||
List<QuantityUnitRelationDO> relations,
|
||||
int precision) {
|
||||
|
||||
return values.stream()
|
||||
.map(value -> convert(value, srcUntId, tgtUntId, conversions, relations, precision))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 按单位符号转换(推荐使用)
|
||||
*
|
||||
* @param value 待转换的值
|
||||
* @param srcUnitSymbol 源单位符号(如: "kg", "m", "km")
|
||||
* @param tgtUnitSymbol 目标单位符号
|
||||
* @param conversions 转换规则列表
|
||||
* @param relations 量纲-单位关联关系列表
|
||||
* @param units 单位信息列表
|
||||
* @param precision 精度(小数位数)
|
||||
* @return 转换结果
|
||||
*/
|
||||
public static ConversionResult convertBySymbol(
|
||||
BigDecimal value,
|
||||
String srcUnitSymbol,
|
||||
String tgtUnitSymbol,
|
||||
List<UnitConversionDO> conversions,
|
||||
List<QuantityUnitRelationDO> relations,
|
||||
List<UntInfoDO> units,
|
||||
int precision) {
|
||||
|
||||
// 1. 根据符号查找单位
|
||||
UntInfoDO srcUnit = units.stream()
|
||||
.filter(u -> u.getSmb() != null && u.getSmb().equals(srcUnitSymbol))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> exception(UNIT_NOT_FOUND, "符号:" + srcUnitSymbol));
|
||||
|
||||
UntInfoDO tgtUnit = units.stream()
|
||||
.filter(u -> u.getSmb() != null && u.getSmb().equals(tgtUnitSymbol))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> exception(UNIT_NOT_FOUND, "符号:" + tgtUnitSymbol));
|
||||
|
||||
log.debug("按符号转换: {} ({}) → {} ({})", srcUnitSymbol, srcUnit.getId(), tgtUnitSymbol, tgtUnit.getId());
|
||||
|
||||
// 2. 调用原有方法
|
||||
return convert(value, srcUnit.getId(), tgtUnit.getId(), conversions, relations, precision);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按单位名称转换
|
||||
*
|
||||
* @param value 待转换的值
|
||||
* @param srcUnitName 源单位名称(如: "千克", "米", "千米")
|
||||
* @param tgtUnitName 目标单位名称
|
||||
* @param conversions 转换规则列表
|
||||
* @param relations 量纲-单位关联关系列表
|
||||
* @param units 单位信息列表
|
||||
* @param precision 精度(小数位数)
|
||||
* @return 转换结果
|
||||
*/
|
||||
public static ConversionResult convertByName(
|
||||
BigDecimal value,
|
||||
String srcUnitName,
|
||||
String tgtUnitName,
|
||||
List<UnitConversionDO> conversions,
|
||||
List<QuantityUnitRelationDO> relations,
|
||||
List<UntInfoDO> units,
|
||||
int precision) {
|
||||
|
||||
// 1. 根据名称查找单位
|
||||
UntInfoDO srcUnit = units.stream()
|
||||
.filter(u -> u.getName() != null && u.getName().equals(srcUnitName))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> exception(UNIT_NOT_FOUND, "名称:" + srcUnitName));
|
||||
|
||||
UntInfoDO tgtUnit = units.stream()
|
||||
.filter(u -> u.getName() != null && u.getName().equals(tgtUnitName))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> exception(UNIT_NOT_FOUND, "名称:" + tgtUnitName));
|
||||
|
||||
log.debug("按名称转换: {} ({}) → {} ({})", srcUnitName, srcUnit.getId(), tgtUnitName, tgtUnit.getId());
|
||||
|
||||
// 2. 调用原有方法
|
||||
return convert(value, srcUnit.getId(), tgtUnit.getId(), conversions, relations, precision);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按单位符号批量转换
|
||||
*
|
||||
* @param values 待转换的值列表
|
||||
* @param srcUnitSymbol 源单位符号
|
||||
* @param tgtUnitSymbol 目标单位符号
|
||||
* @param conversions 转换规则列表
|
||||
* @param relations 量纲-单位关联关系列表
|
||||
* @param units 单位信息列表
|
||||
* @param precision 精度(小数位数)
|
||||
* @return 转换结果列表
|
||||
*/
|
||||
public static List<ConversionResult> batchConvertBySymbol(
|
||||
List<BigDecimal> values,
|
||||
String srcUnitSymbol,
|
||||
String tgtUnitSymbol,
|
||||
List<UnitConversionDO> conversions,
|
||||
List<QuantityUnitRelationDO> relations,
|
||||
List<UntInfoDO> units,
|
||||
int precision) {
|
||||
|
||||
return values.stream()
|
||||
.map(value -> convertBySymbol(value, srcUnitSymbol, tgtUnitSymbol, conversions, relations, units, precision))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 按单位名称批量转换
|
||||
*
|
||||
* @param values 待转换的值列表
|
||||
* @param srcUnitName 源单位名称
|
||||
* @param tgtUnitName 目标单位名称
|
||||
* @param conversions 转换规则列表
|
||||
* @param relations 量纲-单位关联关系列表
|
||||
* @param units 单位信息列表
|
||||
* @param precision 精度(小数位数)
|
||||
* @return 转换结果列表
|
||||
*/
|
||||
public static List<ConversionResult> batchConvertByName(
|
||||
List<BigDecimal> values,
|
||||
String srcUnitName,
|
||||
String tgtUnitName,
|
||||
List<UnitConversionDO> conversions,
|
||||
List<QuantityUnitRelationDO> relations,
|
||||
List<UntInfoDO> units,
|
||||
int precision) {
|
||||
|
||||
return values.stream()
|
||||
.map(value -> convertByName(value, srcUnitName, tgtUnitName, conversions, relations, units, precision))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?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="com.zt.plat.module.unit-management.dal.dao.QuantityUnitRelation.QuantityUnitRelationMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?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="com.zt.plat.module.unit-management.dal.dao.UnitConversion.UnitConversionMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?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="com.zt.plat.module.unit-management.dal.dao.unitQuantity.UnitQuantityMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?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="com.zt.plat.module.unit-management.dal.dao.untinfo.UntInfoMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user