mirror of
https://gitee.com/dromara/dax-pay
synced 2026-08-09 22:45:58 +08:00
feat(system): 用户协议版本新建支持继承上一版内容
新增 find-inherit-source 接口,供新建草稿时按同语言已发布或最新归档版本预填内容。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -13,6 +13,7 @@ import cn.daxpay.open.platform.system.result.protocol.UserProtocolVersionResult;
|
||||
import cn.daxpay.open.platform.system.service.protocol.UserProtocolVersionService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -85,6 +86,20 @@ public class UserProtocolVersionController {
|
||||
return Res.ok(userProtocolVersionService.findById(id));
|
||||
}
|
||||
|
||||
/// 查询新建草稿可继承的源版本(同语言已发布优先, 否则最新归档)
|
||||
///
|
||||
/// @param protocolId 协议ID
|
||||
/// @param language 语言
|
||||
/// @return 源版本, 无则 null
|
||||
@PermCode(code = PermCodes.Action.VIEW)
|
||||
@Operation(summary = "查询可继承源版本")
|
||||
@GetMapping("/find-inherit-source")
|
||||
public Result<UserProtocolVersionResult> findInheritSource(
|
||||
@NotNull(message = "{validation.field.protocolId.notNull}") Long protocolId,
|
||||
@NotBlank(message = "{validation.field.language.notBlank}") String language){
|
||||
return Res.ok(userProtocolVersionService.findInheritSource(protocolId, language));
|
||||
}
|
||||
|
||||
/// 发布版本(草稿 -> 已发布, 同协议同语言原已发布自动归档)
|
||||
///
|
||||
/// @param id 版本ID
|
||||
|
||||
@@ -40,6 +40,21 @@ public class UserProtocolVersionManager extends BaseManager<UserProtocolVersionM
|
||||
.oneOpt();
|
||||
}
|
||||
|
||||
/// 查询可继承的源版本: 同协议同语言已发布优先, 否则取 versionNo 最大的归档版
|
||||
public Optional<UserProtocolVersion> findLatestForInherit(Long protocolId, String language){
|
||||
Optional<UserProtocolVersion> published = this.findPublished(protocolId, language);
|
||||
if (published.isPresent()) {
|
||||
return published;
|
||||
}
|
||||
return this.lambdaQuery()
|
||||
.eq(UserProtocolVersion::getProtocolId, protocolId)
|
||||
.eq(UserProtocolVersion::getLanguage, language)
|
||||
.eq(UserProtocolVersion::getStatus, "ARCHIVED")
|
||||
.orderByDesc(UserProtocolVersion::getVersionNo)
|
||||
.last("LIMIT 1")
|
||||
.oneOpt();
|
||||
}
|
||||
|
||||
/// 查询某协议下所有版本(级联删除/复制用)
|
||||
public List<UserProtocolVersion> findAllByProtocol(Long protocolId){
|
||||
return this.lambdaQuery()
|
||||
|
||||
@@ -114,6 +114,13 @@ public class UserProtocolVersionService {
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
/// 查询新建草稿可继承的源版本(已发布优先, 否则最新归档; 无则 null)
|
||||
public UserProtocolVersionResult findInheritSource(Long protocolId, String language){
|
||||
return userProtocolVersionManager.findLatestForInherit(protocolId, language)
|
||||
.map(UserProtocolVersion::toResult)
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
/// 复制版本到目标协议(用于复制到其他端, 直接以已发布状态写入)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void copyVersion(UserProtocolVersion source, Long targetProtocolId){
|
||||
|
||||
Reference in New Issue
Block a user