Files
ai4se-harness-suite/example-project/docs/standards/templates/05-ddd-domain-service.md
ning-inspire 26975e5c3a Initial commit: ai4se-harness-suite
Import harness suite (skills, installers, overnight-runner, docs) as a fresh history for InspireChina.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-17 09:57:41 +08:00

32 lines
885 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Domain Service(Domain 层)
```java
package com.xxx.domain.service;
import com.xxx.domain.aggregate.Xxx;
import com.xxx.domain.vo.XxxStatus;
import java.util.List;
public class XxxConflictService {
/**
* 校验新建记录与已有记录不冲突。
* 冲突时抛出 IllegalStateException(HTTP 409)。
*/
public void validateNoConflict(List<Xxx> existing, CheckParam param) {
boolean conflict = existing.stream().anyMatch(a ->
a.getField1().equals(param.field1()) &&
a.getStatus() != XxxStatus.CANCELLED);
if (conflict) throw new IllegalStateException("冲突:该条件已存在");
}
public record CheckParam(String field1) {}
}
```
## 要点
- Domain Service 处理跨聚合的业务校验,不在任何一个聚合根内
- 不依赖 Spring,纯 Java
- 在 AppService 中组合使用