Egyéb javítások

This commit is contained in:
2025-03-24 14:01:58 +01:00
parent d55dee91e9
commit 50a7eb5521
8 changed files with 85 additions and 17 deletions
@@ -86,6 +86,26 @@ namespace WorkFlowCheck.API.Controllers
} }
return retVal; return retVal;
} }
[HttpPost("UpdateAllCheckPoint")]
public async Task<ApiResponseDTO<List<CheckPointDTO>>> UpdateAllCheckPoint([FromBody] List<CheckPointDTO> checkPointListDTO)
{
var retVal = new ApiResponseDTO<List<CheckPointDTO>>()
{
IsSuccess = true
};
try
{
var result = await _syncService.UpdateAllCheckPointAsync(checkPointListDTO);
retVal.Data = result;
}
catch (Exception ex)
{
retVal.IsSuccess = false;
Log.Error(ex.Message);
}
return retVal;
}
[HttpGet("GetEquipment/{id}")] [HttpGet("GetEquipment/{id}")]
@@ -46,6 +46,9 @@ namespace WorkFlowCheck.BL.Mappings
CreateMap<CheckListHeader, CheckListHeaderDTO>() CreateMap<CheckListHeader, CheckListHeaderDTO>()
.ForMember(dest => dest.UserDTO, opt => opt.MapFrom(src => src.User)) .ForMember(dest => dest.UserDTO, opt => opt.MapFrom(src => src.User))
.ForMember(dest => dest.CheckListRowDTO, opt => opt.MapFrom(src => src.CheckListRows)); .ForMember(dest => dest.CheckListRowDTO, opt => opt.MapFrom(src => src.CheckListRows));
CreateMap<CheckListRow, CheckListRowDTO>()
.ForMember(dest => dest.CheckListTemplateRowDTO, opt => opt.MapFrom(src => src.CheckListTemplateRow));
} }
} }
} }
@@ -61,7 +61,7 @@ namespace WorkFlowCheck.BL.Services
{ {
var roles = await _dbContext.CheckListHeaders var roles = await _dbContext.CheckListHeaders
.Include(i => i.CheckListRows) .Include(i => i.CheckListRows)
.Include(i=>i.User) .Include(i => i.User)
.AsNoTracking() .AsNoTracking()
.ToListAsync(); .ToListAsync();
if (roles != null) if (roles != null)
@@ -121,7 +121,7 @@ namespace WorkFlowCheck.BL.Services
{ {
CheckListRowDTO = new List<CheckListRowDTO>() CheckListRowDTO = new List<CheckListRowDTO>()
}; };
using var transaction = await _dbContext.Database.BeginTransactionAsync();
try try
{ {
var checkListTemplateHeader = await _dbContext.CheckListTemplateHeaders var checkListTemplateHeader = await _dbContext.CheckListTemplateHeaders
@@ -132,7 +132,7 @@ namespace WorkFlowCheck.BL.Services
return retVal; return retVal;
} }
var currentDate = DateTime.UtcNow; var currentDate = DateTime.UtcNow;
var documentNumber = await _numberGeneratorService.GenerateNextNumberAsync(checkListTemplateHeader.NumberGenerator1Id ?? 1, currentDate); var documentNumber = await _numberGeneratorService.GenerateNextNumberAsync(checkListTemplateHeader.NumberGenerator1Id ?? 1, transaction, currentDate);
CheckListHeader checkListHeader = new CheckListHeader() CheckListHeader checkListHeader = new CheckListHeader()
{ {
CheckListTemplateHeaderId = checkListHeaderNewDTO.CheckListTemplateHeaderId, CheckListTemplateHeaderId = checkListHeaderNewDTO.CheckListTemplateHeaderId,
@@ -147,13 +147,37 @@ namespace WorkFlowCheck.BL.Services
IsStorno = false, IsStorno = false,
CheckListRows = new List<CheckListRow>() CheckListRows = new List<CheckListRow>()
}; };
_dbContext.CheckListHeaders.Add(checkListHeader); _dbContext.CheckListHeaders.Add(checkListHeader);
await _dbContext.SaveChangesAsync(); await _dbContext.SaveChangesAsync();
var checkListTemplateRows = await _dbContext.CheckListTemplateRows
.Where(w => w.CheckListTemplateHeaderId == checkListHeaderNewDTO.CheckListTemplateHeaderId)
.OrderBy(o => o.RowIndex)
.ToListAsync();
foreach (var item in checkListTemplateRows)
{
CheckListRow checkListRow = new CheckListRow()
{
Answer = "",
CheckListHeaderId = checkListHeader.Id,
CheckListTemplateRowId = item.Id,
GuidNumber = Guid.NewGuid(),
IsDeleted = false,
Photo = new byte[0],
};
_dbContext.CheckListRows.Add(checkListRow);
}
await _dbContext.SaveChangesAsync();
await transaction.CommitAsync();
retVal = _mapper.Map<CheckListHeaderDTO>(checkListHeader); retVal = _mapper.Map<CheckListHeaderDTO>(checkListHeader);
} }
catch (Exception ex) catch (Exception ex)
{ {
await transaction.RollbackAsync();
Log.Error(ex.Message); Log.Error(ex.Message);
} }
return retVal; return retVal;
@@ -1,4 +1,5 @@
using System; using Microsoft.EntityFrameworkCore.Storage;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@@ -8,7 +9,7 @@ namespace WorkFlowCheck.BL.Services.Interfaces
{ {
public interface INumberGeneratorService public interface INumberGeneratorService
{ {
Task<string> GenerateNextNumberAsync(int templateId, DateTime? baseDate = null); Task<string> GenerateNextNumberAsync(int templateId, IDbContextTransaction transaction, DateTime? baseDate = null);
Task<string> GetSampleAsync(int templateId, DateTime? baseDate = null); Task<string> GetSampleAsync(int templateId, DateTime? baseDate = null);
} }
} }
@@ -8,6 +8,7 @@ namespace WorkFlowCheck.BL.Services.Interfaces
Task<List<CheckPointDTO>> GetAllCheckPointAsync(); Task<List<CheckPointDTO>> GetAllCheckPointAsync();
Task<CheckPointDTO> GetCheckPointAsync(int id); Task<CheckPointDTO> GetCheckPointAsync(int id);
Task<CheckPointDTO> UpdateCheckPointAsync(CheckPointDTO checkPointDTO); Task<CheckPointDTO> UpdateCheckPointAsync(CheckPointDTO checkPointDTO);
Task<List<CheckPointDTO>> UpdateAllCheckPointAsync(List<CheckPointDTO> checkPointListDTO);
Task<List<LocationDTO>> GetAllLocationAsync(); Task<List<LocationDTO>> GetAllLocationAsync();
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -20,14 +21,13 @@ namespace WorkFlowCheck.BL.Services
_dbContext = dbContext; _dbContext = dbContext;
} }
public async Task<string> GenerateNextNumberAsync(int templateId, DateTime? baseDate = null) public async Task<string> GenerateNextNumberAsync(int templateId, IDbContextTransaction transaction, DateTime? baseDate = null)
{ {
var semaphore = GetOrCreateSemaphore(templateId); var semaphore = GetOrCreateSemaphore(templateId);
await semaphore.WaitAsync(); await semaphore.WaitAsync();
try try
{ {
using var transaction = await _dbContext.Database.BeginTransactionAsync();
var template = await _dbContext.Set<NumberGeneratorTemplate>() var template = await _dbContext.Set<NumberGeneratorTemplate>()
.FirstOrDefaultAsync(t => t.Id == templateId); .FirstOrDefaultAsync(t => t.Id == templateId);
@@ -60,13 +60,10 @@ namespace WorkFlowCheck.BL.Services
templateDate.LastGeneratedNumber = result; templateDate.LastGeneratedNumber = result;
await _dbContext.SaveChangesAsync(); await _dbContext.SaveChangesAsync();
await transaction.CommitAsync();
return result; return result;
} }
catch catch
{ {
await _dbContext.Database.RollbackTransactionAsync();
throw; throw;
} }
finally finally
+26 -5
View File
@@ -101,8 +101,33 @@ namespace WorkFlowCheck.BL.Services
return retVal; return retVal;
} }
public async Task<List<CheckPointDTO>> UpdateAllCheckPointAsync(List<CheckPointDTO> checkPointListDTO)
{
var retVal = new List<CheckPointDTO>();
try
{
var ids = checkPointListDTO.Select(dto => dto.Id).ToList();
var checkPoints = await _dbContext.CheckPoints
.Where(cp => ids.Contains(cp.Id))
.ToListAsync();
foreach (var checkPoint in checkPoints)
{
var dto = checkPointListDTO.FirstOrDefault(d => d.Id == checkPoint.Id);
if (dto != null)
{
checkPoint.Code = dto.Code;
}
}
await _dbContext.SaveChangesAsync();
retVal = _mapper.Map<List<CheckPointDTO>>(checkPoints);
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<List<LocationDTO>> GetAllLocationAsync() public async Task<List<LocationDTO>> GetAllLocationAsync()
{ {
@@ -180,10 +205,6 @@ namespace WorkFlowCheck.BL.Services
return retVal; return retVal;
} }
public async Task<List<EquipmentDTO>> GetAllEquipmentAsync() public async Task<List<EquipmentDTO>> GetAllEquipmentAsync()
{ {
var retVal = new List<EquipmentDTO>(); var retVal = new List<EquipmentDTO>();
@@ -11,6 +11,7 @@ namespace WorkFlowCheck.Common.DTO
public int Id { get; set; } public int Id { get; set; }
public int CheckListHeaderId { get; set; } public int CheckListHeaderId { get; set; }
public int CheckListTemplateRowId { get; set; } public int CheckListTemplateRowId { get; set; }
public virtual CheckListTemplateRowDTO CheckListTemplateRowDTO { get; set; }
public string Answer { get; set; } = null!; public string Answer { get; set; } = null!;
public byte[] Photo { get; set; } = null!; public byte[] Photo { get; set; } = null!;
public Guid GuidNumber { get; set; } public Guid GuidNumber { get; set; }