DeviceMessage
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
|
||||
using AutoMapper;
|
||||
using DocumentFormat.OpenXml.InkML;
|
||||
using DocumentFormat.OpenXml.Office2010.Excel;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Serilog;
|
||||
@@ -8,6 +9,7 @@ using System.Collections.Generic;
|
||||
using WorkFlowCheck.BL.Services.Interfaces;
|
||||
using WorkFlowCheck.Common.DTO;
|
||||
using WorkFlowCheck.Common.Enums;
|
||||
using WorkFlowCheck.Common.RequestContext;
|
||||
using WorkFlowCheck.DL;
|
||||
using WorkFlowCheck.DL.Entities;
|
||||
|
||||
@@ -15,7 +17,18 @@ namespace WorkFlowCheck.BL.Services
|
||||
{
|
||||
public class SyncService : BaseService, ISyncService
|
||||
{
|
||||
public SyncService(AppDbContext dbContext, IMapper mapper) : base(dbContext, mapper) { }
|
||||
private readonly IRequestContext _requestContext;
|
||||
private readonly IUserService _userService;
|
||||
|
||||
|
||||
public SyncService(AppDbContext dbContext,
|
||||
IMapper mapper,
|
||||
IRequestContext requestContext,
|
||||
IUserService userService) : base(dbContext, mapper)
|
||||
{
|
||||
_requestContext = requestContext;
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
public async Task<List<CheckPointDTO>> GetAllCheckPointAsync()
|
||||
{
|
||||
@@ -361,11 +374,8 @@ namespace WorkFlowCheck.BL.Services
|
||||
|
||||
try
|
||||
{
|
||||
if (checkListHeaderDTO.Id > 0) //Hozzáadás, ha Id == 0
|
||||
if (checkListHeaderDTO.Id > 0)
|
||||
{
|
||||
|
||||
|
||||
|
||||
var res = await _dbContext.CheckListHeaders
|
||||
.Include(i => i.CheckListRows)
|
||||
.Where(w => w.Id == checkListHeaderDTO.Id)
|
||||
@@ -373,12 +383,31 @@ namespace WorkFlowCheck.BL.Services
|
||||
if (res != null && (res.CheckStatus == CheckStatus.Open ||
|
||||
res.CheckStatus == CheckStatus.InProgress))
|
||||
{
|
||||
if(CanBlock(checkListHeaderDTO))
|
||||
if (NeedBlocking(checkListHeaderDTO))
|
||||
{
|
||||
/// TODO: blokkolás miatt
|
||||
res.CheckStatus = CheckStatus.Blocked;
|
||||
await _dbContext.SaveChangesAsync();
|
||||
Log.Warning("");
|
||||
|
||||
Log.Warning($"Ellenőrzési lap blokkolva: Ellenőrzés:{checkListHeaderDTO.Id}, Felhasználó:{_requestContext.CurrentUsername}");
|
||||
|
||||
var user = await _userService.GetUserAsync(_requestContext.CurrentUserId ?? 1);
|
||||
|
||||
foreach (var item in user.RoleDTO)
|
||||
{
|
||||
var deviceMessageDTO = new DeviceMessageDTO()
|
||||
{
|
||||
IsReaded = false,
|
||||
Message = "Ellenőrző lap blokkolva!",
|
||||
SendDate = DateTime.UtcNow,
|
||||
ExtraDataJSON = "",
|
||||
RoleId = item.ParentId,
|
||||
DeviceIdFrom = "",
|
||||
DeviceIdTo = "",
|
||||
};
|
||||
|
||||
await this.DeviceMessageSend(deviceMessageDTO);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@@ -407,8 +436,17 @@ namespace WorkFlowCheck.BL.Services
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CheckIfLastReached(checkListHeaderDTO))
|
||||
{
|
||||
/// TODO: most kell a CheckStatust állítani és menjen üzenet !
|
||||
res.CheckStatus = CheckStatus.Sent;
|
||||
Log.Warning($"Ellenőrzési lap státuszváltozása: Ellenőrzés:{checkListHeaderDTO.Id}, Felhasználó:{_requestContext.CurrentUsername}");
|
||||
|
||||
}
|
||||
|
||||
await _dbContext.SaveChangesAsync();
|
||||
|
||||
|
||||
retVal = _mapper.Map<CheckListHeaderDTO>(res);
|
||||
}
|
||||
}
|
||||
@@ -420,11 +458,64 @@ namespace WorkFlowCheck.BL.Services
|
||||
|
||||
return retVal;
|
||||
}
|
||||
private bool CanBlock(CheckListHeaderDTO checkListHeaderDTO)
|
||||
private bool NeedBlocking(CheckListHeaderDTO checkListHeaderDTO)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var retVal = false;
|
||||
if (checkListHeaderDTO.CheckListRowDTO != null && checkListHeaderDTO.CheckListRowDTO.Count > 0)
|
||||
{
|
||||
var checkListRows = checkListHeaderDTO.CheckListRowDTO;
|
||||
foreach (var row in checkListRows)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(row.Answer))
|
||||
{
|
||||
if (row.CheckListTemplateRowDTO != null)
|
||||
{
|
||||
if (row.CheckListTemplateRowDTO.AnswerType == "PI-N" && row.Answer == "Igen")
|
||||
{
|
||||
retVal = true;
|
||||
break;
|
||||
}
|
||||
if (row.CheckListTemplateRowDTO.AnswerType == "I-PN" && row.Answer == "Nem")
|
||||
{
|
||||
retVal = true;
|
||||
break;
|
||||
}
|
||||
if (row.CheckListTemplateRowDTO.AnswerType == "SI-N" && row.Answer == "Igen")
|
||||
{
|
||||
retVal = true;
|
||||
break;
|
||||
}
|
||||
if (row.CheckListTemplateRowDTO.AnswerType == "I-SN" && row.Answer == "Nem")
|
||||
{
|
||||
retVal = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
private bool CheckIfLastReached(CheckListHeaderDTO checkListHeaderDTO)
|
||||
{
|
||||
var retVal = false;
|
||||
|
||||
if (checkListHeaderDTO !=null && checkListHeaderDTO.CheckListRowDTO !=null && checkListHeaderDTO.CheckListRowDTO.Count > 0)
|
||||
{
|
||||
var totalRowCount = checkListHeaderDTO.CheckListRowDTO.Where(w => w.CheckListTemplateRowDTO.AnswerType != "PN" &&
|
||||
w.CheckListTemplateRowDTO.CheckPointDTO.IsEnabled == true).Count();
|
||||
|
||||
var answeredCount = checkListHeaderDTO.CheckListRowDTO.Where(w => w.CheckListTemplateRowDTO.AnswerType != "PN" &&
|
||||
w.CheckListTemplateRowDTO.CheckPointDTO.IsEnabled == true &&
|
||||
string.IsNullOrEmpty(w.Answer) != false).Count();
|
||||
|
||||
if (totalRowCount != answeredCount) { retVal = true; }
|
||||
}
|
||||
|
||||
|
||||
return retVal;
|
||||
}
|
||||
public async Task<bool> DeviceMessageSend(DeviceMessageDTO deviceMessageDTO)
|
||||
{
|
||||
var retVal = false;
|
||||
|
||||
@@ -16,5 +16,7 @@ namespace WorkFlowCheck.Common.DTO
|
||||
public string Message { get; set; } = null!;
|
||||
public string ExtraDataJSON { get; set; } = null!;
|
||||
public bool IsReaded { get; set; }
|
||||
public int? RoleId { get; set; }
|
||||
public RoleDTO? RoleDTO { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user