feat: 新增预警与附件模块,优化工位派工功能
1. 新增预警规则、预警消息、业务附件数据库表与CRUD逻辑 2. 为拧紧记录添加审核人、审核时间字段及审核留痕功能 3. 优化产线点位类型与编号描述,更新工位组合下发菜单名称为工艺路线派工 4. 新增上传文件获取原文件名与大小的工具方法 5. 在系统管理菜单新增预警中心与附件中心入口
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
package production
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"bj_power_mes/common/httpx"
|
||||
"bj_power_mes/internal/logic"
|
||||
"bj_power_mes/internal/svc"
|
||||
)
|
||||
|
||||
// CreateAlertRuleHandler POST /alert/rule 新增预警规则
|
||||
func CreateAlertRuleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Threshold float64 `json:"threshold"`
|
||||
Receiver string `json:"receiver"`
|
||||
Enabled bool `json:"enabled"`
|
||||
}
|
||||
if err := httpx.ParseJSON(r, &req); err != nil {
|
||||
httpx.BadRequest(w, "请求体解析失败")
|
||||
return
|
||||
}
|
||||
if err := logic.New(svcCtx).CreateAlertRule(r.Context(), req.Name, req.Type, req.Threshold, req.Receiver, req.Enabled, operator(r, "")); err != nil {
|
||||
httpx.Fail(w, 3301, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.OkMessage(w, "保存成功", nil)
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateAlertRuleHandler PUT /alert/rule 修改预警规则
|
||||
func UpdateAlertRuleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
Id int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Threshold float64 `json:"threshold"`
|
||||
Receiver string `json:"receiver"`
|
||||
Enabled bool `json:"enabled"`
|
||||
}
|
||||
if err := httpx.ParseJSON(r, &req); err != nil {
|
||||
httpx.BadRequest(w, "请求体解析失败")
|
||||
return
|
||||
}
|
||||
if err := logic.New(svcCtx).UpdateAlertRule(r.Context(), req.Id, req.Name, req.Type, req.Threshold, req.Receiver, req.Enabled); err != nil {
|
||||
httpx.Fail(w, 3302, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.OkMessage(w, "保存成功", nil)
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteAlertRuleHandler DELETE /alert/rule?id= 删除规则
|
||||
func DeleteAlertRuleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
id := atoiDefault(r.URL.Query().Get("id"), 0)
|
||||
if id <= 0 {
|
||||
httpx.Fail(w, 3303, "缺少 id")
|
||||
return
|
||||
}
|
||||
if err := logic.New(svcCtx).DeleteAlertRule(r.Context(), id); err != nil {
|
||||
httpx.Fail(w, 3303, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.OkMessage(w, "删除成功", nil)
|
||||
}
|
||||
}
|
||||
|
||||
// ListAlertRulesHandler GET /alert/rules 规则列表
|
||||
func ListAlertRulesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
data, err := logic.New(svcCtx).ListAlertRules(r.Context())
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3304, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, data)
|
||||
}
|
||||
}
|
||||
|
||||
// ListAlertsHandler GET /alerts?status= 预警消息收件箱
|
||||
func ListAlertsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
status := r.URL.Query().Get("status")
|
||||
data, err := logic.New(svcCtx).ListAlerts(r.Context(), status)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3305, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, data)
|
||||
}
|
||||
}
|
||||
|
||||
// MarkAlertReadHandler POST /alert/read 标记已读 {id}
|
||||
func MarkAlertReadHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
Id int `json:"id"`
|
||||
}
|
||||
if err := httpx.ParseJSON(r, &req); err != nil {
|
||||
httpx.BadRequest(w, "请求体解析失败")
|
||||
return
|
||||
}
|
||||
if err := logic.New(svcCtx).MarkAlertRead(r.Context(), req.Id); err != nil {
|
||||
httpx.Fail(w, 3306, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.OkMessage(w, "已标记已读", nil)
|
||||
}
|
||||
}
|
||||
@@ -149,3 +149,45 @@ func TorqueManualAddHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
httpx.OkMessage(w, "补录成功", nil)
|
||||
}
|
||||
}
|
||||
|
||||
// TorqueAuditHandler POST /torque/audit 拧紧记录审核签字
|
||||
func TorqueAuditHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
RecordId int `json:"recordId"`
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
if err := httpx.ParseJSON(r, &req); err != nil {
|
||||
httpx.BadRequest(w, "请求体解析失败")
|
||||
return
|
||||
}
|
||||
if req.RecordId <= 0 {
|
||||
httpx.Fail(w, 3208, "缺少 recordId")
|
||||
return
|
||||
}
|
||||
if err := logic.New(svcCtx).AuditTorqueRecord(r.Context(), req.RecordId, req.Remark, operator(r, "")); err != nil {
|
||||
httpx.Fail(w, 3208, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.OkMessage(w, "审核成功", nil)
|
||||
}
|
||||
}
|
||||
|
||||
// TorqueAuditLogHandler GET /torque/audit-log 查询拧紧记录修改留痕
|
||||
func TorqueAuditLogHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
q := r.URL.Query()
|
||||
id := atoiDefault(q.Get("recordId"), 0)
|
||||
if id <= 0 {
|
||||
httpx.Fail(w, 3209, "缺少 recordId")
|
||||
return
|
||||
}
|
||||
data, err := logic.New(svcCtx).ListTorqueAuditLog(r.Context(), id)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3209, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, data)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user