Feat/audit/model #7

Merged
YingmoY merged 2 commits from feat/audit/model into main 2026-03-23 02:52:05 +08:00
YingmoY commented 2026-03-23 02:51:53 +08:00 (Migrated from github.com)
No description provided.
copilot-pull-request-reviewer[bot] (Migrated from github.com) reviewed 2026-03-23 02:55:48 +08:00
copilot-pull-request-reviewer[bot] (Migrated from github.com) left a comment

Pull request overview

Adds initial GORM model layer for the new internal/audit domain, providing DB mappings for audit events, audit reviews, and operation logs, plus required module dependencies.

Changes:

  • Introduce AuditEvent, AuditReview, and OperationLog models under internal/audit/model.
  • Add gorm.io/datatypes to support JSONB detail storage in operation logs.
  • Update go.mod / go.sum to reflect the new dependency graph.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
internal/audit/model/operation_log.go Adds OperationLog model with JSONB detail payload for operation auditing.
internal/audit/model/audit_review.go Adds AuditReview model and status constants for pharmacist review results.
internal/audit/model/audit_event.go Adds AuditEvent model to track auditable events and their lifecycle.
go.mod Adds gorm.io/datatypes and several new indirect dependencies.
go.sum Records checksums for newly introduced transitive dependencies.

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

## Pull request overview Adds initial GORM model layer for the new `internal/audit` domain, providing DB mappings for audit events, audit reviews, and operation logs, plus required module dependencies. **Changes:** - Introduce `AuditEvent`, `AuditReview`, and `OperationLog` models under `internal/audit/model`. - Add `gorm.io/datatypes` to support JSONB detail storage in operation logs. - Update `go.mod` / `go.sum` to reflect the new dependency graph. ### Reviewed changes Copilot reviewed 4 out of 5 changed files in this pull request and generated 5 comments. <details> <summary>Show a summary per file</summary> | File | Description | | ---- | ----------- | | internal/audit/model/operation_log.go | Adds `OperationLog` model with JSONB `detail` payload for operation auditing. | | internal/audit/model/audit_review.go | Adds `AuditReview` model and status constants for pharmacist review results. | | internal/audit/model/audit_event.go | Adds `AuditEvent` model to track auditable events and their lifecycle. | | go.mod | Adds `gorm.io/datatypes` and several new indirect dependencies. | | go.sum | Records checksums for newly introduced transitive dependencies. | </details> --- 💡 <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>.
@ -15,3 +16,4 @@
)
require (
filippo.io/edwards25519 v1.1.0 // indirect
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2026-03-23 02:55:48 +08:00

本 PR 仅新增审计模型,但这里额外新增了 filippo.io/edwards25519(indirect)。当前仓库代码中未找到相关 import/使用痕迹,建议确认是否误引入;若无实际用途请移除并在最后执行 go mod tidy。


本 PR 仅新增审计模型,但这里额外新增了 `filippo.io/edwards25519`(indirect)。当前仓库代码中未找到相关 import/使用痕迹,建议确认是否误引入;若无实际用途请移除并在最后执行 `go mod tidy`。 ```suggestion ```
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2026-03-23 02:55:48 +08:00

本 PR 仅新增审计模型,但这里新增了 github.com/go-sql-driver/mysql / github.com/google/uuid(indirect)。在仓库 Go 代码中未搜索到对应 import(例如 gorm.io/driver/mysql、github.com/google/uuid),建议确认是否误引入;若无使用请移除并运行 go mod tidy,避免不必要的依赖膨胀。

本 PR 仅新增审计模型,但这里新增了 `github.com/go-sql-driver/mysql` / `github.com/google/uuid`(indirect)。在仓库 Go 代码中未搜索到对应 import(例如 `gorm.io/driver/mysql`、`github.com/google/uuid`),建议确认是否误引入;若无使用请移除并运行 `go mod tidy`,避免不必要的依赖膨胀。
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2026-03-23 02:55:48 +08:00

这里新增了 gorm.io/driver/mysql(indirect),但仓库内未找到 gorm.io/driver/mysql 的 import。若项目目前仅使用 Postgres(已直接依赖 driver/postgres),建议去掉该 driver 依赖并 go mod tidy,避免引入额外数据库 driver 及其传递依赖。


这里新增了 `gorm.io/driver/mysql`(indirect),但仓库内未找到 `gorm.io/driver/mysql` 的 import。若项目目前仅使用 Postgres(已直接依赖 driver/postgres),建议去掉该 driver 依赖并 `go mod tidy`,避免引入额外数据库 driver 及其传递依赖。 ```suggestion ```
@ -0,0 +9,4 @@
const (
// AuditReviewStatusPassed 审核通过。
AuditReviewStatusPassed = "PASSED"
// AuditReviewStatusRejected 审核驳回。
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2026-03-23 02:55:47 +08:00

AuditReview 的状态常量使用了全大写值("PASSED"/"REJECTED"),与仓库里其他业务状态字段普遍使用的 lower snake-case(如 inbound_order.go / trace_inventory.go 中的 "draft"、"pending_shelving" 等)不一致。建议统一状态取值风格,避免跨模块状态值难以复用/比对;如果数据库已固定为大写,请至少在注释中说明该取值来自 DB/外部系统且不可更改。

	// AuditReviewStatusPassed 审核通过。
	// 注意:状态值由 DB/public.audit_review.status 字段(或外部系统)定义为全大写 "PASSED",为保持兼容性不可修改,
	// 因此未采用仓库其余业务状态字段常用的 lower snake-case 风格。
	AuditReviewStatusPassed = "PASSED"
	// AuditReviewStatusRejected 审核驳回。
	// 注意:状态值由 DB/public.audit_review.status 字段(或外部系统)定义为全大写 "REJECTED",为保持兼容性不可修改,
	// 因此未采用仓库其余业务状态字段常用的 lower snake-case 风格。
AuditReview 的状态常量使用了全大写值("PASSED"/"REJECTED"),与仓库里其他业务状态字段普遍使用的 lower snake-case(如 inbound_order.go / trace_inventory.go 中的 "draft"、"pending_shelving" 等)不一致。建议统一状态取值风格,避免跨模块状态值难以复用/比对;如果数据库已固定为大写,请至少在注释中说明该取值来自 DB/外部系统且不可更改。 ```suggestion // AuditReviewStatusPassed 审核通过。 // 注意:状态值由 DB/public.audit_review.status 字段(或外部系统)定义为全大写 "PASSED",为保持兼容性不可修改, // 因此未采用仓库其余业务状态字段常用的 lower snake-case 风格。 AuditReviewStatusPassed = "PASSED" // AuditReviewStatusRejected 审核驳回。 // 注意:状态值由 DB/public.audit_review.status 字段(或外部系统)定义为全大写 "REJECTED",为保持兼容性不可修改, // 因此未采用仓库其余业务状态字段常用的 lower snake-case 风格。 ```
@ -0,0 +18,4 @@
core.BaseModel
OrderID int64 `gorm:"column:order_id;type:bigint;not null;index:idx_audit_review_order" json:"order_id"`
PharmacistID int64 `gorm:"column:pharmacist_id;type:bigint;not null" json:"pharmacist_id"`
Status string `gorm:"column:status;type:varchar(20);not null" json:"status"`
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2026-03-23 02:55:48 +08:00

Status 字段为 not null 的 string,但没有 default 或约束;在未显式赋值时,GORM 仍可能写入空字符串(""),从而产生不符合 PASSED/REJECTED 预期的记录。建议在 DB 层加 CHECK 约束/枚举约束,或在模型/写入逻辑中增加校验并(如有需要)为初始状态设置默认值。

	Status       string    `gorm:"column:status;type:varchar(20);not null;default:PASSED;check:status IN ('PASSED','REJECTED')" json:"status"`
Status 字段为 not null 的 string,但没有 default 或约束;在未显式赋值时,GORM 仍可能写入空字符串(""),从而产生不符合 PASSED/REJECTED 预期的记录。建议在 DB 层加 CHECK 约束/枚举约束,或在模型/写入逻辑中增加校验并(如有需要)为初始状态设置默认值。 ```suggestion Status string `gorm:"column:status;type:varchar(20);not null;default:PASSED;check:status IN ('PASSED','REJECTED')" json:"status"` ```
Sign in to join this conversation.
No description provided.