feat(location): 设计新增货位领域实体 #13

Merged
YingmoY merged 1 commit from feat/location/entity into main 2026-04-13 08:56:10 +08:00
YingmoY commented 2026-04-13 08:55:33 +08:00 (Migrated from github.com)
No description provided.
copilot-pull-request-reviewer[bot] (Migrated from github.com) reviewed 2026-04-13 08:57:56 +08:00
copilot-pull-request-reviewer[bot] (Migrated from github.com) left a comment

Pull request overview

该 PR 新增“货位(Location)”领域实体,用于在领域层封装货位的状态与基础业务校验,并提供与 GORM 数据模型之间的转换。

Changes:

  • 新增 Location 领域实体结构体,承载货位核心字段与状态
  • 增加 FromModel/ToModel 用于领域实体与 model.LocationInfo 间转换
  • 增加货位状态辅助方法(IsEnabled/ToggleStatus)与基础必填校验(Validate)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

## Pull request overview 该 PR 新增“货位(Location)”领域实体,用于在领域层封装货位的状态与基础业务校验,并提供与 GORM 数据模型之间的转换。 **Changes:** - 新增 `Location` 领域实体结构体,承载货位核心字段与状态 - 增加 `FromModel`/`ToModel` 用于领域实体与 `model.LocationInfo` 间转换 - 增加货位状态辅助方法(`IsEnabled`/`ToggleStatus`)与基础必填校验(`Validate`) --- 💡 <a href="/YingmoY/PharmacyERP/new/main?filename=.github/instructions/*.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.
@ -0,0 +36,4 @@
// ToModel 将领域实体转换为 GORM 数据库模型,供仓储层写入使用。
// ID 为零时表示新建,GORM 将自动填充自增主键。
func (l *Location) ToModel() *model.LocationInfo {
return &model.LocationInfo{
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2026-04-13 08:57:55 +08:00

ToModel() 的注释说明“ID 为零时表示新建”,但当前返回的 model.LocationInfo 没有带上领域实体的 l.ID(嵌入的 BaseModel.ID 会保持为 0)。如果仓储层使用 GORM 的 Save/基于主键的更新逻辑,这会导致本应更新时被当作新建插入;同时注释与实现不一致。建议在构造后显式把 ID 写回(例如构造完后 m.ID = l.ID,或初始化 BaseModel),或修改注释明确该方法仅用于创建。

	return &model.LocationInfo{
		ID:           l.ID,
`ToModel()` 的注释说明“ID 为零时表示新建”,但当前返回的 `model.LocationInfo` 没有带上领域实体的 `l.ID`(嵌入的 `BaseModel.ID` 会保持为 0)。如果仓储层使用 GORM 的 `Save`/基于主键的更新逻辑,这会导致本应更新时被当作新建插入;同时注释与实现不一致。建议在构造后显式把 `ID` 写回(例如构造完后 `m.ID = l.ID`,或初始化 `BaseModel`),或修改注释明确该方法仅用于创建。 ```suggestion return &model.LocationInfo{ ID: l.ID, ```
Sign in to join this conversation.
No description provided.