Files
jinko.yikatong/Src/Dlhis.External/Appointment/Services/Implements/AppointmentService.cs
2024-08-16 21:48:14 +08:00

88 lines
3.0 KiB
C#

using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Visitor.Entity;
using Dlhis.Entity.Visitor.Enums;
using Dlhis.External.Appointment.Request;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
using Kurisu.AspNetCore.Utils.Extensions;
namespace Dlhis.External.Appointment.Services.Implements;
public class AppointmentService : IAppointmentService
{
private readonly IDbContext _dbContext;
public AppointmentService(IDbContext dbContext)
{
_dbContext = dbContext;
}
public async Task ReceiveAsync(AppointmentReceiveRequest request)
{
var exists = await _dbContext.Queryable<VisitorAppointmentEntity>().Where(x => x.No == request.No).AnyAsync();
exists.ThrowIfTrue("已经存在申请");
var id = await _dbContext.InsertReturnIdentityAsync(new VisitorAppointmentEntity
{
No = request.No,
Title = request.Title,
Code = request.Code,
Company = request.Company,
ApplyTime = request.ApplyTime,
ApplyArea = request.ApplyArea,
Factory = request.Factory,
Reason = request.Reason,
Start = request.Start,
End = request.End,
Remark = request.Remark,
IsEnterWorkplace = request.IsEnterWorkplace
});
foreach (var item in request.Items)
{
var no = await _dbContext.Queryable<GainfoEntity>().Where(x => x.IdNo == item.IdNo).Select(x => x.No).SingleAsync();
var isExternal = no.IsEmpty();
if (isExternal)
{
var gainfoExternal = await _dbContext.Queryable<GainfoExternalEntity>().Where(x => x.IdNo == item.IdNo).FirstAsync();
if (gainfoExternal == null)
{
gainfoExternal = new GainfoExternalEntity
{
No = Guid.NewGuid().ToString(),
Code = item.IdNo,
IdNo = item.IdNo,
Name = item.Name,
Company = request.Company,
Phone = item.Phone
};
await _dbContext.InsertAsync(gainfoExternal);
}
else
{
gainfoExternal.Phone = item.Phone;
gainfoExternal.Company = request.Company;
await _dbContext.UpdateAsync(gainfoExternal);
}
no = gainfoExternal.No;
}
var detail = new VisitorAppointmentDetailEntity
{
UserNo = no,
AppointmentId = id,
No = request.No,
IdNo = item.IdNo,
Name = item.Name,
Phone = item.Phone,
Remark = item.Remark,
Status = AppointmentDetailEnumType.Wait,
IsExternal = isExternal,
LicensePlate = item.LicensePlate
};
await _dbContext.InsertAsync(detail);
}
}
}