提交
This commit is contained in:
@@ -199,8 +199,13 @@ func AttachmentFileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
// 中文文件名走 RFC 5987;下载(dl=1)才强制 attachment,否则内联预览
|
||||
disp := "inline"
|
||||
// 中文文件名走 RFC 5987;图片/PDF 内联预览,其他类型强制下载;
|
||||
// 显式 dl=1 一律强制下载(对齐 WMS /uploads/ 行为)。
|
||||
ext := strings.ToLower(filepath.Ext(abs))
|
||||
disp := "attachment"
|
||||
if isInlineExt(ext) {
|
||||
disp = "inline"
|
||||
}
|
||||
if r.URL.Query().Get("dl") == "1" {
|
||||
disp = "attachment"
|
||||
}
|
||||
@@ -219,6 +224,27 @@ func AttachmentDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
httpx.BadRequest(w, "参数错误:id 必填")
|
||||
return
|
||||
}
|
||||
// 删除保护(对齐 WMS):关键工艺文件 / 保留期内检验件禁止删除,避免质量/工艺记录丢失。
|
||||
rec, gerr := logic.New(svcCtx).GetAttachment(r.Context(), req.Id)
|
||||
if gerr != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
switch rec.FileType {
|
||||
case FileTypeProcessPDF, FileTypeProcessCard:
|
||||
httpx.Fail(w, 3315, "工艺流程 / 流程卡为关键工艺文件,禁止删除")
|
||||
return
|
||||
case FileTypeInspectionPhoto, FileTypeInspectionPDF:
|
||||
years := svcCtx.Config.Upload.LocalRetentionYears
|
||||
if years <= 0 {
|
||||
years = 1
|
||||
}
|
||||
cutYear := time.Now().Year() - years
|
||||
if rec.CreatedAt.Year() >= cutYear {
|
||||
httpx.Fail(w, 3315, fmt.Sprintf("检验记录在质量追溯保留期(%d 年)内,禁止删除", years))
|
||||
return
|
||||
}
|
||||
}
|
||||
att, err := logic.New(svcCtx).DeleteAttachment(r.Context(), req.Id, operator(r, ""))
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3313, "删除附件失败:"+err.Error())
|
||||
|
||||
@@ -170,6 +170,7 @@ func CreateUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
httpx.Fail(w, 1006, err.Error())
|
||||
return
|
||||
}
|
||||
svcCtx.EventLog.Write(r.Context(), "user.create", "", ctxOperator(r), "user", req.Username, "创建用户 "+req.Username, nil)
|
||||
httpx.OkMessage(w, "创建成功", nil)
|
||||
}
|
||||
}
|
||||
@@ -185,6 +186,7 @@ func UpdateUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
httpx.Fail(w, 1007, err.Error())
|
||||
return
|
||||
}
|
||||
svcCtx.EventLog.Write(r.Context(), "user.update", "", ctxOperator(r), "user", req.Username, "更新用户 "+req.Username, nil)
|
||||
httpx.OkMessage(w, "更新成功", nil)
|
||||
}
|
||||
}
|
||||
@@ -195,6 +197,7 @@ func DeleteUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
httpx.Fail(w, 1008, err.Error())
|
||||
return
|
||||
}
|
||||
svcCtx.EventLog.Write(r.Context(), "user.delete", "", ctxOperator(r), "user", strconv.Itoa(pathId(r)), "删除用户 id="+strconv.Itoa(pathId(r)), nil)
|
||||
httpx.OkMessage(w, "删除成功", nil)
|
||||
}
|
||||
}
|
||||
@@ -220,7 +223,8 @@ func ChangePasswordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
|
||||
func ListRolesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
data, err := logic.New(svcCtx).ListRoles(r.Context())
|
||||
keyword := strings.TrimSpace(r.URL.Query().Get("keyword"))
|
||||
data, err := logic.New(svcCtx).ListRoles(r.Context(), keyword)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 1009, err.Error())
|
||||
return
|
||||
@@ -240,6 +244,7 @@ func CreateRoleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
httpx.Fail(w, 1010, err.Error())
|
||||
return
|
||||
}
|
||||
svcCtx.EventLog.Write(r.Context(), "role.create", "", ctxOperator(r), "role", req.Code, "创建角色 "+req.Name, nil)
|
||||
httpx.OkMessage(w, "创建成功", nil)
|
||||
}
|
||||
}
|
||||
@@ -255,6 +260,7 @@ func UpdateRoleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
httpx.Fail(w, 1011, err.Error())
|
||||
return
|
||||
}
|
||||
svcCtx.EventLog.Write(r.Context(), "role.update", "", ctxOperator(r), "role", req.Code, "更新角色 "+req.Name, nil)
|
||||
httpx.OkMessage(w, "更新成功", nil)
|
||||
}
|
||||
}
|
||||
@@ -265,6 +271,7 @@ func DeleteRoleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
httpx.Fail(w, 1012, err.Error())
|
||||
return
|
||||
}
|
||||
svcCtx.EventLog.Write(r.Context(), "role.delete", "", ctxOperator(r), "role", strconv.Itoa(pathId(r)), "删除角色 id="+strconv.Itoa(pathId(r)), nil)
|
||||
httpx.OkMessage(w, "删除成功", nil)
|
||||
}
|
||||
}
|
||||
@@ -293,6 +300,7 @@ func CreatePermissionHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
httpx.Fail(w, 1014, err.Error())
|
||||
return
|
||||
}
|
||||
svcCtx.EventLog.Write(r.Context(), "rbac.permission.create", "", ctxOperator(r), "permission", req.Code, "创建权限 "+req.Name, nil)
|
||||
httpx.OkMessage(w, "创建成功", nil)
|
||||
}
|
||||
}
|
||||
@@ -308,6 +316,7 @@ func UpdatePermissionHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
httpx.Fail(w, 1015, err.Error())
|
||||
return
|
||||
}
|
||||
svcCtx.EventLog.Write(r.Context(), "rbac.permission.update", "", ctxOperator(r), "permission", req.Code, "更新权限 "+req.Name, nil)
|
||||
httpx.OkMessage(w, "更新成功", nil)
|
||||
}
|
||||
}
|
||||
@@ -318,6 +327,7 @@ func DeletePermissionHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
httpx.Fail(w, 1016, err.Error())
|
||||
return
|
||||
}
|
||||
svcCtx.EventLog.Write(r.Context(), "rbac.permission.delete", "", ctxOperator(r), "permission", strconv.Itoa(pathId(r)), "删除权限 id="+strconv.Itoa(pathId(r)), nil)
|
||||
httpx.OkMessage(w, "删除成功", nil)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
var pathPermMap = map[string]string{
|
||||
"POST:/api/v1/product-types": "produce.product:add",
|
||||
"PUT:/api/v1/product-types": "produce.product:edit",
|
||||
"POST:/api/v1/product-types/*": "produce.product:edit",
|
||||
"DELETE:/api/v1/product-types/*": "produce.product:delete",
|
||||
"POST:/api/v1/work-orders": "produce.workorder:add",
|
||||
"PUT:/api/v1/work-orders": "produce.workorder:edit",
|
||||
|
||||
@@ -17,7 +17,8 @@ func ListProcessFlowsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
stationNo := atoiDefault(r.URL.Query().Get("stationNo"), 0)
|
||||
page := atoiDefault(r.URL.Query().Get("page"), 0)
|
||||
pageSize := atoiDefault(r.URL.Query().Get("pageSize"), 20)
|
||||
data, err := logic.New(svcCtx).ListFlows(r.Context(), stationNo, r.URL.Query().Get("pp"), page, pageSize)
|
||||
data, err := logic.New(svcCtx).ListFlows(r.Context(), stationNo, r.URL.Query().Get("pp"),
|
||||
r.URL.Query().Get("name"), r.URL.Query().Get("status"), atoiDefault(r.URL.Query().Get("stepMin"), 0), page, pageSize)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 2201, err.Error())
|
||||
return
|
||||
|
||||
@@ -2,6 +2,7 @@ package production
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"bj_power_mes/common/httpx"
|
||||
"bj_power_mes/internal/logic"
|
||||
@@ -26,6 +27,7 @@ func CreateAlertRuleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
httpx.Fail(w, 3301, err.Error())
|
||||
return
|
||||
}
|
||||
svcCtx.EventLog.Write(r.Context(), "alert.rule.create", "", operator(r, ""), "alert_rule", req.Name, "新增预警规则 "+req.Name, nil)
|
||||
httpx.OkMessage(w, "保存成功", nil)
|
||||
}
|
||||
}
|
||||
@@ -49,6 +51,7 @@ func UpdateAlertRuleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
httpx.Fail(w, 3302, err.Error())
|
||||
return
|
||||
}
|
||||
svcCtx.EventLog.Write(r.Context(), "alert.rule.update", "", operator(r, ""), "alert_rule", strconv.Itoa(req.Id), "修改预警规则 "+req.Name, nil)
|
||||
httpx.OkMessage(w, "保存成功", nil)
|
||||
}
|
||||
}
|
||||
@@ -65,6 +68,7 @@ func DeleteAlertRuleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
httpx.Fail(w, 3303, err.Error())
|
||||
return
|
||||
}
|
||||
svcCtx.EventLog.Write(r.Context(), "alert.rule.delete", "", operator(r, ""), "alert_rule", strconv.Itoa(id), "删除预警规则 id="+strconv.Itoa(id), nil)
|
||||
httpx.OkMessage(w, "删除成功", nil)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ func UpsertMaterialInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
|
||||
httpx.Fail(w, 3120, err.Error())
|
||||
return
|
||||
}
|
||||
svcCtx.EventLog.Write(r.Context(), "material.upsert", "", operator(r, ""), "material", req.Code, "物料档案 upsert "+req.Code, nil)
|
||||
httpx.Ok(w, map[string]any{"created": created})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +96,17 @@ func DeleteProductTypeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// RetryProductTypeSyncHandler POST /product-types/:id/sync-retry 手动重推单行物料到 WMS(替代原列表自动重推)
|
||||
func RetryProductTypeSyncHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if err := logic.New(svcCtx).RetryProductTypeSync(r.Context(), pathID(r)); err != nil {
|
||||
httpx.Fail(w, 3015, "重推失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
httpx.OkMessage(w, "重推成功", nil)
|
||||
}
|
||||
}
|
||||
|
||||
// SetProductTypeStatusHandler POST /product-types/status 物料档案启用/停用专用通道(body {id,isActive})
|
||||
func SetProductTypeStatusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -154,8 +154,21 @@ func ListEventLogsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
isAdmin := false
|
||||
if me != nil {
|
||||
candidates = []string{me.Username, me.Name}
|
||||
if rl, err := svcCtx.EntClient.Role.Get(context.Background(), me.RoleId); err == nil && rl.Code == "SUPER_ADMIN" {
|
||||
isAdmin = true
|
||||
}
|
||||
// B3.3 isAdmin 优先取 JWT 中的 roleCode(上下文注入 / 解析 token),缺失时回退 DB Role 查 code,避免每次查库
|
||||
if rc, ok := r.Context().Value("roleCode").(string); ok && rc != "" {
|
||||
isAdmin = rc == "SUPER_ADMIN"
|
||||
} else {
|
||||
auth := strings.TrimPrefix(r.Header.Get("Authorization"), "Bearer ")
|
||||
if auth != "" {
|
||||
if claims, err := tokenx.Parse(svcCtx.Config.Auth.AccessSecret, auth); err == nil && claims.RoleCode == "SUPER_ADMIN" {
|
||||
isAdmin = true
|
||||
}
|
||||
}
|
||||
if !isAdmin && me != nil {
|
||||
if rl, err := svcCtx.EntClient.Role.Get(context.Background(), me.RoleId); err == nil && rl.Code == "SUPER_ADMIN" {
|
||||
isAdmin = true
|
||||
}
|
||||
}
|
||||
}
|
||||
explicitFilter := q.Get("operator")
|
||||
@@ -165,7 +178,7 @@ func ListEventLogsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
|
||||
list, total, err := logic.New(svcCtx).ListEventLogs(r.Context(),
|
||||
q.Get("orderNo"), operatorCandidates(explicitFilter, candidates), q.Get("eventType"), fromMs, toMs, page, pageSize)
|
||||
q.Get("orderNo"), operatorCandidates(explicitFilter, candidates), q.Get("eventType"), q.Get("entityType"), fromMs, toMs, page, pageSize)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3308, err.Error())
|
||||
return
|
||||
|
||||
@@ -18,7 +18,8 @@ func ListProductProcessesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
page := atoiDefault(q.Get("page"), 0)
|
||||
pageSize := atoiDefault(q.Get("pageSize"), 20)
|
||||
data, err := logic.New(svcCtx).ListProductProcesses(r.Context(),
|
||||
q.Get("productCode"), q.Get("status"), atoiDefault(q.Get("flowId"), 0), q.Get("keyword"), page, pageSize)
|
||||
q.Get("productCode"), q.Get("status"), atoiDefault(q.Get("flowId"), 0), q.Get("keyword"),
|
||||
q.Get("name"), atoiDefault(q.Get("stepMin"), 0), atoiDefault(q.Get("stepMax"), 0), page, pageSize)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 2231, err.Error())
|
||||
return
|
||||
|
||||
@@ -222,6 +222,7 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
|
||||
{Method: http.MethodPut, Path: "/product-types", Handler: production.UpdateProductTypeHandler(serverCtx)},
|
||||
// 物料档案启用/停用专用通道(body {id,isActive}):本地置 isActive 并同步 WMS,停用=退出新建下拉
|
||||
{Method: http.MethodPost, Path: "/product-types/status", Handler: production.SetProductTypeStatusHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/product-types/:id/sync-retry", Handler: production.RetryProductTypeSyncHandler(serverCtx)},
|
||||
{Method: http.MethodDelete, Path: "/product-types/:id", Handler: production.DeleteProductTypeHandler(serverCtx)},
|
||||
|
||||
{Method: http.MethodGet, Path: "/work-orders", Handler: production.ListWorkOrdersHandler(serverCtx)},
|
||||
|
||||
@@ -32,13 +32,14 @@ const (
|
||||
FileTypeProcessCard = "PROCESS_CARD" // 流程卡
|
||||
FileTypePackagePhoto = "PACKAGE_PHOTO" // 包装照片
|
||||
FileTypeExcelImport = "EXCEL_IMPORT" // Excel 导入
|
||||
FileTypeImage = "IMAGE" // 图片(通用,不细分业务:png/jpg/jpeg/gif/webp)
|
||||
FileTypeOther = "OTHER" // 其他
|
||||
)
|
||||
|
||||
var validFileTypes = map[string]bool{
|
||||
FileTypeProcessPDF: true, FileTypeInspectionPhoto: true, FileTypeInspectionPDF: true,
|
||||
FileTypeDrawing: true, FileTypeProcessCard: true, FileTypePackagePhoto: true,
|
||||
FileTypeExcelImport: true, FileTypeOther: true,
|
||||
FileTypeExcelImport: true, FileTypeImage: true, FileTypeOther: true,
|
||||
}
|
||||
|
||||
// allowedExt 允许的扩展名白名单(图纸/报告/图片/表格/压缩包)。白名单而非黑名单,避免上传可执行文件。
|
||||
@@ -48,27 +49,45 @@ var allowedExt = map[string]bool{
|
||||
".dwg": true, ".dxf": true, ".zip": true, ".txt": true, ".csv": true,
|
||||
}
|
||||
|
||||
// deriveFileType 未显式指定文件类型时,按业务类型 + 扩展名推断,兜底 OTHER。
|
||||
// deriveFileType 未显式指定文件类型时,按「扩展名优先」推断:
|
||||
// 1) 图片类(png/jpg/jpeg/gif/webp)→ 按业务类型细分(检验/来料→检验照片,包裹/出库→包裹照片),无更细业务类型归「图片(IMAGE)」;
|
||||
// 2) 非图片按业务类型 + 扩展名细分(PDF/DWG 等);
|
||||
// 3) 兜底 OTHER。
|
||||
// 扩展名优先可避免「material 的 png 照片被误判为其他」等问题。
|
||||
func deriveFileType(bizType, ext string) string {
|
||||
ext = strings.ToLower(ext)
|
||||
switch {
|
||||
case ext == ".xlsx" || ext == ".xls" || ext == ".csv":
|
||||
return FileTypeExcelImport
|
||||
case bizType == "inspection":
|
||||
// 扩展名优先:图片类
|
||||
if ext == ".png" || ext == ".jpg" || ext == ".jpeg" || ext == ".gif" || ext == ".webp" {
|
||||
switch bizType {
|
||||
case "inspection", "inbound":
|
||||
return FileTypeInspectionPhoto
|
||||
case "outbound", "package":
|
||||
return FileTypePackagePhoto
|
||||
default:
|
||||
return FileTypeImage
|
||||
}
|
||||
}
|
||||
// 非图片:按业务类型 + 扩展名细分
|
||||
switch bizType {
|
||||
case "inspection":
|
||||
if ext == ".pdf" {
|
||||
return FileTypeInspectionPDF
|
||||
}
|
||||
if ext == ".png" || ext == ".jpg" || ext == ".jpeg" || ext == ".gif" {
|
||||
return FileTypeInspectionPhoto
|
||||
case "material":
|
||||
if ext == ".pdf" || ext == ".dwg" || ext == ".dxf" {
|
||||
return FileTypeDrawing
|
||||
}
|
||||
case bizType == "material" && (ext == ".pdf" || ext == ".dwg" || ext == ".dxf"):
|
||||
return FileTypeDrawing
|
||||
case bizType == "work_order":
|
||||
case "work_order":
|
||||
if ext == ".pdf" {
|
||||
return FileTypeProcessCard
|
||||
}
|
||||
case bizType == "process_flow" && ext == ".pdf":
|
||||
return FileTypeProcessPDF
|
||||
case "process_flow":
|
||||
if ext == ".pdf" {
|
||||
return FileTypeProcessPDF
|
||||
}
|
||||
}
|
||||
if ext == ".xlsx" || ext == ".xls" || ext == ".csv" {
|
||||
return FileTypeExcelImport
|
||||
}
|
||||
return FileTypeOther
|
||||
}
|
||||
@@ -267,6 +286,17 @@ func serveUploadFile(w http.ResponseWriter, r *http.Request, dir, name string) {
|
||||
http.ServeContent(w, r, filepath.Base(abs), time.Time{}, f)
|
||||
}
|
||||
|
||||
// isInlineExt 判断扩展名是否可在浏览器内联预览(图片 / PDF)。
|
||||
// 与 WMS attachment 包的判定保持一致:只有这类文件才允许 inline,其余一律强制下载,
|
||||
// 避免 docx/xlsx/zip 等被当垃圾数据内联打开(B1.1 对齐两端行为)。
|
||||
func isInlineExt(ext string) bool {
|
||||
switch strings.ToLower(ext) {
|
||||
case ".png", ".jpg", ".jpeg", ".gif", ".webp", ".pdf":
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// randHex 随机十六进制串(保留给其他场景的短随机名使用)。
|
||||
func randHex(n int) string {
|
||||
b := make([]byte, n)
|
||||
|
||||
Reference in New Issue
Block a user