导出列表

This commit is contained in:
18942506660
2023-11-14 14:01:42 +08:00
parent 7f3f1838af
commit 239105b6d5
17 changed files with 724 additions and 6 deletions

View File

@@ -0,0 +1,103 @@
using AutoMapper;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WMS.Web.Core;
using WMS.Web.Core.Dto;
using WMS.Web.Domain.Entitys;
using WMS.Web.Domain.Infrastructure;
using WMS.Web.Domain.IService.Public;
using WMS.Web.Domain.Values;
using WMS.Web.Domain.Values.Single;
using WMS.Web.Repositories.Configuration;
namespace WMS.Web.Repositories
{
public class FileDownManagerRepositories : IFileDownManagerRepositories
{
private readonly IMapper _mapper;
private readonly RepositoryDbContext _context;
private readonly ISingleDataService _singleDataService;
public FileDownManagerRepositories(RepositoryDbContext context, IMapper mapper, ISingleDataService singleDataService)
{
_mapper = mapper;
_context = context;
_singleDataService = singleDataService;
}
public async Task<FileDownManager> Add(FileDownManager entity)
{
await _context.FileDownManager.AddAsync(entity);
await _context.SaveChangesAsync();
return entity;
}
public async Task<FileDownManager> Edit(FileDownManager entity)
{
var res = await _context.FileDownManager
.FirstOrDefaultAsync(f => f.Id == entity.Id);
if (res == null) return null;
_mapper.Map(entity, res);
await _context.SaveChangesAsync();
return res;
}
public async Task<FileDownManagerResponse> GetList(FileDownManagerRequest dto, int companyId)
{
List<int> userIds = new List<int>();
if (!string.IsNullOrEmpty(dto.User))
userIds = _singleDataService.GetIdsBySingleName(SingleAction.Staffs, companyId, dto.User);
var res = _context.FileDownManager
//.GroupJoin(_context.UcStaff, manager => manager.UserId, user => user.Id, (manager, user) => new { manager, user })
// .SelectMany(x => x.user.DefaultIfEmpty(), (d, user) => new { d.manager, user })
.OrderByDescending(o => o.Date)
.Where(w => w.CompanyId == companyId);
#region
if (!string.IsNullOrEmpty(dto.User))
res = res.Where(w => userIds.Contains(w.UserId));
if (dto.BeginDate != null)
res = res.Where(w => w.Date >= dto.BeginDate);
if (dto.EndDate != null)
res = res.Where(w => w.Date <= (dto.EndDate ?? DateTime.Now).AddHours(23).AddMinutes(59).AddSeconds(59));
if (dto.Type != null)
res = res.Where(w => w.Type == (FileDownLoadOrderType)dto.Type);
if (dto.SupplierId != null)
res = res.Where(w => w.SupplierId == dto.SupplierId);
if (dto.Status != null)
{
if ((ExportStatus)dto.Status == ExportStatus.Ing)
res = res.Where(w => w.Status == ExportStatus.Ing && w.Date >= DateTime.Now.AddHours(-1));
else if ((ExportStatus)dto.Status == ExportStatus.Fail)
res = res.Where(w => (w.Status == ExportStatus.Fail) || (w.Status == ExportStatus.Ing && w.Date < DateTime.Now.AddHours(-1)));
else
res = res.Where(w => w.Status == (ExportStatus)dto.Status);
}
#endregion
int total = await res.CountAsync();
var list = await res.Select(s => new FileDownInfoManagerResponse(_mapper.Map<FileDownInfoManagerResponse>(s))
{
StatusKey = (s.Status == ExportStatus.Ing && s.Date < DateTime.Now.AddHours(-1)) ? (int)ExportStatus.Fail : (int)s.Status,
Status = (s.Status == ExportStatus.Ing && s.Date < DateTime.Now.AddHours(-1)) ? ExportStatus.Fail.GetRemark() : s.Status.GetRemark(),
UserName = dto.SupplierId != null
? _singleDataService.GetSingleData(SingleAction.Users, companyId, s.UserId)
: _singleDataService.GetSingleData(SingleAction.Staffs, companyId, s.UserId),//s.StaffName
})
.Skip((dto.PageNo - 1) * dto.PageSize).Take(dto.PageSize)
.ToListAsync();
return new FileDownManagerResponse(list, total);
}
}
}