feat: 新增预警与附件模块,优化工位派工功能
1. 新增预警规则、预警消息、业务附件数据库表与CRUD逻辑 2. 为拧紧记录添加审核人、审核时间字段及审核留痕功能 3. 优化产线点位类型与编号描述,更新工位组合下发菜单名称为工艺路线派工 4. 新增上传文件获取原文件名与大小的工具方法 5. 在系统管理菜单新增预警中心与附件中心入口
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"bj_power_mes/ent"
|
||||
"bj_power_mes/ent/attachment"
|
||||
)
|
||||
|
||||
// AddAttachment 新增附件记录
|
||||
func (s *Service) AddAttachment(ctx context.Context, bizType, bizId, fileName, filePath string, fileSize int, uploader string) (*ent.Attachment, error) {
|
||||
return s.ctx.EntClient.Attachment.Create().
|
||||
SetBizType(bizType).SetBizId(bizId).SetFileName(fileName).
|
||||
SetFilePath(filePath).SetFileSize(fileSize).SetUploader(uploader).Save(ctx)
|
||||
}
|
||||
|
||||
// ListAttachments 按业务类型/ID 查询附件
|
||||
func (s *Service) ListAttachments(ctx context.Context, bizType, bizId string) ([]*ent.Attachment, error) {
|
||||
q := s.ctx.EntClient.Attachment.Query()
|
||||
if bizType != "" {
|
||||
q = q.Where(attachment.BizType(bizType))
|
||||
}
|
||||
if bizId != "" {
|
||||
q = q.Where(attachment.BizId(bizId))
|
||||
}
|
||||
return q.Order(ent.Desc(attachment.FieldCreatedAt), ent.Desc(attachment.FieldID)).All(ctx)
|
||||
}
|
||||
|
||||
// DeleteAttachment 删除附件记录并返回记录(供删除物理文件)
|
||||
func (s *Service) DeleteAttachment(ctx context.Context, id int) (*ent.Attachment, error) {
|
||||
att, err := s.ctx.EntClient.Attachment.Get(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.ctx.EntClient.Attachment.DeleteOneID(id).Exec(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return att, nil
|
||||
}
|
||||
Reference in New Issue
Block a user