package com.example.rzgb.profile; import jakarta.validation.Valid; import jakarta.validation.constraints.*; import java.time.Instant; /** 八组档案保留前端字段;completed/version/updatedAt 由服务端计算,不采信客户端值。 */ public record CompanyProfile( @NotNull @Size(max=200) String companyName, @NotNull @Size(max=5000) String intro, @NotNull @Size(max=5000) String mainBusiness, @NotNull @Size(max=5000) String products, @NotNull @Size(max=5000) String advantages, @NotNull @Size(max=2000) String serviceRegions, @NotNull @Size(max=2000) String customerTypes, @NotNull @Size(max=2000) String projectTypes, @NotNull @Size(max=1000) String amountPreference, @NotNull @Size(max=5000) String qualifications, @NotNull @Size(max=5000) String trackRecord, @NotNull @Size(max=5000) String delivery, @NotNull @Size(max=2000) String bidPreparation, @NotNull @Size(max=5000) String boundaries, @NotNull @Valid Weights matchWeights, boolean completed, @Min(0) long version, Instant updatedAt) { /** 使用有限且非负的整数权重;允许任意正总和,评分时统一归一化。 */ public record Weights(@Min(0) @Max(100) int business, @Min(0) @Max(100) int region, @Min(0) @Max(100) int amount, @Min(0) @Max(100) int track) { public int total() { return business + region + amount + track; } } public static CompanyProfile empty() { return new CompanyProfile("", "", "", "", "", "", "", "", "", "", "", "", "", "", new Weights(40, 20, 20, 20), false, 0, null); } public CompanyProfile saved(long nextVersion, Instant time) { return new CompanyProfile(companyName.trim(), intro, mainBusiness.trim(), products, advantages, serviceRegions, customerTypes, projectTypes, amountPreference, qualifications, trackRecord, delivery, bidPreparation, boundaries, matchWeights, !companyName.isBlank() && !mainBusiness.isBlank(), nextVersion, time); } }