| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- using Admin.NET.Plugin.AiDOP.Dto.S8;
- using Admin.NET.Plugin.AiDOP.Entity.S0.Manufacturing;
- using Admin.NET.Plugin.AiDOP.Entity.S0.Warehouse;
- using Admin.NET.Plugin.AiDOP.Entity.S8;
- namespace Admin.NET.Plugin.AiDOP.Service.S8;
- public class S8ManualReportService : ITransient
- {
- private readonly SqlSugarRepository<AdoS8Exception> _rep;
- private readonly SqlSugarRepository<AdoS8ExceptionTimeline> _timelineRep;
- private readonly SqlSugarRepository<AdoS8Evidence> _evidenceRep;
- private readonly SqlSugarRepository<AdoS8SceneConfig> _sceneRep;
- private readonly SqlSugarRepository<AdoS0DepartmentMaster> _deptRep;
- private readonly SqlSugarRepository<AdoS0LineMaster> _lineRep;
- public S8ManualReportService(
- SqlSugarRepository<AdoS8Exception> rep,
- SqlSugarRepository<AdoS8ExceptionTimeline> timelineRep,
- SqlSugarRepository<AdoS8Evidence> evidenceRep,
- SqlSugarRepository<AdoS8SceneConfig> sceneRep,
- SqlSugarRepository<AdoS0DepartmentMaster> deptRep,
- SqlSugarRepository<AdoS0LineMaster> lineRep)
- {
- _rep = rep;
- _timelineRep = timelineRep;
- _evidenceRep = evidenceRep;
- _sceneRep = sceneRep;
- _deptRep = deptRep;
- _lineRep = lineRep;
- }
- public async Task<object> GetFormOptionsAsync(long tenantId, long factoryId)
- {
- var scenes = await _sceneRep.AsQueryable()
- .Where(x => x.TenantId == tenantId && x.FactoryId == factoryId && x.Enabled)
- .OrderBy(x => x.SortNo)
- .Select(x => new { value = x.SceneCode, label = x.SceneName })
- .ToListAsync();
- var departments = await _deptRep.AsQueryable()
- .Where(x => x.FactoryRefId == factoryId)
- .OrderBy(x => x.Department)
- .Take(500)
- .Select(x => new { value = x.Id, label = x.Descr ?? x.Department })
- .ToListAsync();
- var lines = await _lineRep.AsQueryable()
- .Where(x => x.FactoryRefId == factoryId)
- .OrderBy(x => x.Line)
- .Take(500)
- .Select(x => new { value = x.Id, label = x.Describe ?? x.Line })
- .ToListAsync();
- return new
- {
- scenes,
- severities = new[]
- {
- new { value = "CRITICAL", label = "紧急" },
- new { value = "HIGH", label = "高" },
- new { value = "MEDIUM", label = "中" },
- new { value = "LOW", label = "低" }
- },
- departments,
- lines,
- materials = Array.Empty<object>()
- };
- }
- public async Task<AdoS8ManualReportResultDto> CreateAsync(AdoS8ManualReportCreateDto dto)
- {
- if (string.IsNullOrWhiteSpace(dto.Title)) throw new S8BizException("标题必填");
- if (string.IsNullOrWhiteSpace(dto.SceneCode)) throw new S8BizException("场景必填");
- var code = $"EX-{DateTime.Now:yyyyMMdd}-{Guid.NewGuid().ToString("N")[..8].ToUpperInvariant()}";
- var entity = new AdoS8Exception
- {
- TenantId = dto.TenantId,
- FactoryId = dto.FactoryId,
- ExceptionCode = code,
- Title = dto.Title.Trim(),
- Description = dto.Description,
- SceneCode = dto.SceneCode.Trim(),
- SourceType = "MANUAL",
- Status = "NEW",
- Severity = string.IsNullOrWhiteSpace(dto.Severity) ? "MEDIUM" : dto.Severity,
- PriorityScore = 0,
- PriorityLevel = "P3",
- OccurrenceDeptId = dto.OccurrenceDeptId,
- ResponsibleDeptId = dto.ResponsibleDeptId,
- ReporterId = dto.ReporterId,
- CreatedAt = DateTime.Now,
- IsDeleted = false
- };
- await _rep.AsTenant().UseTranAsync(async () =>
- {
- entity = await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
- await _timelineRep.InsertAsync(new AdoS8ExceptionTimeline
- {
- ExceptionId = entity.Id,
- ActionCode = "CREATE",
- ActionLabel = "创建",
- FromStatus = null,
- ToStatus = "NEW",
- OperatorId = dto.ReporterId,
- ActionRemark = "主动提报",
- CreatedAt = DateTime.Now
- });
- }, ex => throw ex);
- return new AdoS8ManualReportResultDto
- {
- ExceptionId = entity.Id,
- ExceptionCode = entity.ExceptionCode,
- TaskId = entity.Id
- };
- }
- public async Task<AdoS8Exception?> GetAsync(long id) =>
- await _rep.GetByIdAsync(id);
- public async Task<AdoS8Evidence> AddAttachmentAsync(long id, AdoS8AttachmentCreateDto dto)
- {
- var entity = await _rep.GetFirstAsync(x => x.Id == id && !x.IsDeleted)
- ?? throw new S8BizException("异常不存在");
- if (string.IsNullOrWhiteSpace(dto.FileName) || string.IsNullOrWhiteSpace(dto.FileUrl))
- throw new S8BizException("附件名称和地址必填");
- var evidence = new AdoS8Evidence
- {
- ExceptionId = id,
- EvidenceType = string.IsNullOrWhiteSpace(dto.EvidenceType) ? "file" : dto.EvidenceType,
- FileName = dto.FileName.Trim(),
- FileUrl = dto.FileUrl.Trim(),
- SourceSystem = dto.SourceSystem,
- UploadedBy = dto.UploadedBy,
- UploadedAt = DateTime.Now,
- IsDeleted = false
- };
- await _evidenceRep.InsertAsync(evidence);
- return evidence;
- }
- }
|