feat(t242): delete unused freight orders

This commit is contained in:
QiuSW
2026-07-29 16:10:45 +08:00
parent c80a5c26ed
commit e5f403ff7d
20 changed files with 915 additions and 27 deletions
@@ -89,6 +89,11 @@ func (h *Handler) RegisterProtected(routes gin.IRoutes) {
routes.GET("/freight/import", SecurityHeaders(), h.ImportFreight)
routes.POST("/freight/import", SecurityHeaders(), h.CreateFreightImport)
routes.GET("/freight/:id", SecurityHeaders(), h.FreightDetail)
routes.POST(
"/freight/:id/delete",
SecurityHeaders(),
h.DeleteFreightOrder,
)
}
if _, ok := h.service.(ProcurementService); ok {
routes.POST(
@@ -527,6 +532,57 @@ func (h *Handler) FreightDetail(ctx *gin.Context) {
})
}
func (h *Handler) DeleteFreightOrder(ctx *gin.Context) {
ctx.Request.Body = http.MaxBytesReader(ctx.Writer, ctx.Request.Body, 16<<10)
if err := ctx.Request.ParseForm(); err != nil || !validCSRF(ctx) {
h.renderError(
ctx,
http.StatusForbidden,
"请求已失效",
"请返回货运详情后重新操作。",
)
return
}
if ctx.PostForm("confirm_delete") != "1" {
h.renderError(
ctx,
http.StatusUnprocessableEntity,
"必须确认删除",
"请确认只删除本系统中的货运信息后再提交。",
)
return
}
orderID := strings.TrimSpace(ctx.Param("id"))
service := h.service.(FreightService)
err := service.DeleteFreightOrder(
ctx.Request.Context(),
DeleteFreightOrderInput{
ActorUserID: actorUserID(ctx.Request.Context()),
OrderID: orderID,
},
)
if errors.Is(err, ErrFreightOrderInUse) {
ctx.Redirect(
http.StatusSeeOther,
"/freight/"+pathEscape(orderID)+"?notice=delete-conflict",
)
return
}
if err != nil {
h.renderServiceError(
ctx,
err,
"货运单删除失败,请稍后重试。",
)
return
}
h.logEvent(
"freight_order_deleted order_id=" + orderID +
" actor_user_id=" + actorUserID(ctx.Request.Context()),
)
ctx.Redirect(http.StatusSeeOther, "/freight?notice=deleted")
}
func (h *Handler) CreateFreightProcurementRequest(ctx *gin.Context) {
ctx.Request.Body = http.MaxBytesReader(ctx.Writer, ctx.Request.Body, 16<<10)
if err := ctx.Request.ParseForm(); err != nil || !validCSRF(ctx) {
@@ -662,6 +718,10 @@ func freightNotice(value string) string {
return "需求状态或来源已变化,当前不能生成任务。"
case "import-succeeded":
return "ERP 货运单已同步,货运信息和商品明细已更新。"
case "deleted":
return "货运单已从本系统删除,不影响顺运宝 ERP。"
case "delete-conflict":
return "该货运单已进入采购流程,不能删除。"
default:
return ""
}