commitafdd9e6f14Author: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 21:48:05 2024 +0800 fix 价格默认获取菜单中的设置 commita3cfc472c8Author: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 21:40:04 2024 +0800 fix 时间范围逻辑 commit83f8906f12Author: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 21:32:55 2024 +0800 fix 时间范围逻辑 commit35660b1d0cAuthor: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 21:29:36 2024 +0800 fix 数据范围罗逻辑修改 commit7407955bc5Author: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 21:14:06 2024 +0800 fix 分类树增加营业点参数 commited5196d1a1Author: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 21:02:52 2024 +0800 feat 用户创建 commitd25909a235Author: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 20:51:20 2024 +0800 fix 菜单明细调整 commit8915f9ff0fAuthor: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 20:42:08 2024 +0800 fix 判断提前 commit45aa52aa2aAuthor: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 20:34:22 2024 +0800 fix 逻辑取反 commit89904fead1Author: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 20:23:20 2024 +0800 fix 菜单时效范围 commit573911f907Author: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 19:13:33 2024 +0800 fix 订单聚合返回状态 commit93c38be18aAuthor: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 18:40:12 2024 +0800 fix 订单查询 commite256d18d36Author: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 18:14:33 2024 +0800 fix 订单取消接口,分页权限控制 commit1218aec811Author: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 17:32:45 2024 +0800 fix 营业点权限控制优化 commit226c61ee41Author: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 17:09:42 2024 +0800 fix tenantId赋值 commit28d2c1d8d4Author: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 17:05:37 2024 +0800 fix ignoretenant commit5ae6dd97b4Author: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 16:53:40 2024 +0800 fix ignoretenant commit4c866eaf3fAuthor: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 16:40:24 2024 +0800 feat 获取所有地址 commit2ca8f2db49Author: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 16:22:47 2024 +0800 fix 优化查询 commit212a1fa073Author: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 16:01:49 2024 +0800 fix 临时数据模拟 commit0eb76e878cAuthor: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 15:48:59 2024 +0800 fix 处理删除缺少判断 commitc582fb40c0Author: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 15:40:22 2024 +0800 fix 查询优化 commit6d3a19b283Author: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 11:48:45 2024 +0800 fix 错误值修改 commitc39f77008dAuthor: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 11:31:50 2024 +0800 fix 营业点控制(admin),unit返回 commita5dcab1d07Author: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 11:16:23 2024 +0800 fix 营业点分页控制 commit02084be82bAuthor: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 11:01:14 2024 +0800 fix 分类控制菜品获取 commit96c5c5febaAuthor: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 10:39:58 2024 +0800 fix DI commit367ede2eebAuthor: liguoyang <Ligy.97@foxmail.com> Date: Thu Mar 21 10:35:24 2024 +0800 fix 订餐返回当前信息,增加数量入参和响应 commit0e1f6cb4a0Author: liguoyang <Ligy.97@foxmail.com> Date: Wed Mar 20 16:40:10 2024 +0800 fix 餐补查询代码调整 commit21fc2f78d3Author: liguoyang <Ligy.97@foxmail.com> Date: Wed Mar 20 15:52:46 2024 +0800 fix 支付批量操作 commit878b44a146Merge:a90d4e6bf5c937Author: cheche <717840555@qq.com> Date: Wed Mar 20 15:27:39 2024 +0800 Merge branch 'development' of https://git.dlhis.com/liguoyang/jinko.yikatong into development commita90d4e66a7Author: cheche <717840555@qq.com> Date: Wed Mar 20 15:27:37 2024 +0800 fix 餐补查询及日志删除 commitbf5c937037Author: liguoyang <Ligy.97@foxmail.com> Date: Wed Mar 20 15:12:30 2024 +0800 fix 补充营业点分配权限接口 commit07672f1d32Author: liguoyang <Ligy.97@foxmail.com> Date: Wed Mar 20 13:56:33 2024 +0800 fix 优化changeDb commit7090ee4a33Author: liguoyang <Ligy.97@foxmail.com> Date: Wed Mar 20 13:41:25 2024 +0800 fix 敏感信息混淆 commit4366b68831Author: liguoyang <Ligy.97@foxmail.com> Date: Wed Mar 20 12:42:48 2024 +0800 fix 代码优化 commit03b73515b5Author: liguoyang <Ligy.97@foxmail.com> Date: Wed Mar 20 10:59:08 2024 +0800 fix tree返回营业点 commit1ce60bedc2Merge:aba4fa72d83930Author: cheche <717840555@qq.com> Date: Wed Mar 20 09:55:17 2024 +0800 Merge branch 'development' of https://git.dlhis.com/liguoyang/jinko.yikatong into development commitaba4fa7ee9Author: cheche <717840555@qq.com> Date: Wed Mar 20 09:55:13 2024 +0800 fix 删除日志优化 commit2d8393068fAuthor: liguoyang <Ligy.97@foxmail.com> Date: Tue Mar 19 20:53:16 2024 +0800 feat 订单聚合接口 commit0cde1d3d92Author: liguoyang <Ligy.97@foxmail.com> Date: Tue Mar 19 20:03:06 2024 +0800 fix 表名称调整 commitf003e30169Author: liguoyang <Ligy.97@foxmail.com> Date: Tue Mar 19 19:51:56 2024 +0800 fix 订餐null异常处理 commitf427338715Author: liguoyang <Ligy.97@foxmail.com> Date: Tue Mar 19 18:43:19 2024 +0800 feat 获取菜品 commit3a65d95701Merge:9a7091b7432faeAuthor: cheche <717840555@qq.com> Date: Tue Mar 19 18:36:16 2024 +0800 Merge branch 'development' of https://git.dlhis.com/liguoyang/jinko.yikatong into development commit9a7091b4e0Author: cheche <717840555@qq.com> Date: Tue Mar 19 18:36:14 2024 +0800 fix 删除日志try commit7432fae103Author: liguoyang <Ligy.97@foxmail.com> Date: Tue Mar 19 18:02:31 2024 +0800 fix 配送点增加 commitecd162c7afAuthor: liguoyang <Ligy.97@foxmail.com> Date: Tue Mar 19 17:51:15 2024 +0800 fix 预定就餐送货地点 commit1c7a054ed4Author: liguoyang <Ligy.97@foxmail.com> Date: Tue Mar 19 15:53:22 2024 +0800 feat 获取所有营业点接口 commit84398a566eMerge:217d9f784b4025Author: cheche <717840555@qq.com> Date: Tue Mar 19 15:26:42 2024 +0800 Merge branch 'development' of https://git.dlhis.com/liguoyang/jinko.yikatong into development commit217d9f7770Author: cheche <717840555@qq.com> Date: Tue Mar 19 15:26:40 2024 +0800 feat 配送点管理 commit84b402538eAuthor: liguoyang <Ligy.97@foxmail.com> Date: Tue Mar 19 14:59:21 2024 +0800 fix 菜单分页响应调整,增加详情接口 commit098d7c7e9dAuthor: liguoyang <Ligy.97@foxmail.com> Date: Tue Mar 19 14:26:24 2024 +0800 fix 代码优化
321 lines
11 KiB
C#
321 lines
11 KiB
C#
using Dlhis.Basic.Places.Request;
|
|
using Dlhis.Basic.BusinessPlace.Response;
|
|
using Dlhis.Basic.BusinessShift.Request;
|
|
using Dlhis.Basic.BusinessShift.Response;
|
|
using Dlhis.Entity.Basic.Entity;
|
|
using Dlhis.Entity.Device.Entities;
|
|
using Dlhis.Sys.Api;
|
|
using Kurisu.AspNetCore.Utils.Extensions;
|
|
using Kurisu.Core.CustomClass;
|
|
using Kurisu.Core.DataAccess.Dto;
|
|
using Kurisu.Core.Result;
|
|
using Kurisu.SqlSugar.Extensions;
|
|
using Kurisu.SqlSugar.Services;
|
|
using Mapster;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Dlhis.Basic.BusinessShift.Services.Implements;
|
|
|
|
public class BusinessPlaceShiftService : IBusinessPlaceShiftService
|
|
{
|
|
private readonly IDbContext _dbContext;
|
|
private readonly ITenantApi _tenantApi;
|
|
|
|
public BusinessPlaceShiftService(IDbContext dbContext, ITenantApi tenantApi)
|
|
{
|
|
_dbContext = dbContext;
|
|
_tenantApi = tenantApi;
|
|
}
|
|
|
|
public async Task<Pagination<BusinessPlaceShiftResponse>> GetPageAsync(BusinessPlaceShiftPageRequest request)
|
|
{
|
|
var page = await _dbContext.Queryable<BusinessShiftEntity>()
|
|
.WhereIF(request.Search.IsPresent(), (shift) => shift.CustomCode.Contains(request.Search) || shift.Name.Contains(request.Search))
|
|
.Select<BusinessPlaceShiftResponse>()
|
|
.ToPageListAsync(request);
|
|
|
|
var shiftCodes = page.Data.Select(x => x.Code).ToList();
|
|
|
|
//下级就餐时间段
|
|
var mealShifts = await _dbContext.Queryable<BusinessShiftMealRelationshipEntity>()
|
|
.Where(x => shiftCodes.Contains(x.ShiftCode))
|
|
.Select((x) => new MealShiftResponse
|
|
{
|
|
Id = x.Id,
|
|
ShiftCode = x.ShiftCode,
|
|
ShiftType = x.ShiftType,
|
|
Start = x.Start,
|
|
End = x.End,
|
|
})
|
|
.ToListAsync();
|
|
|
|
page.Data.ForEach(x =>
|
|
{
|
|
x.MealShifts = mealShifts.Where(item => item.ShiftCode == x.Code).ToList();
|
|
});
|
|
|
|
return page;
|
|
}
|
|
|
|
public async Task<List<BusinessPlaceShiftResponse>> GetListAsync()
|
|
{
|
|
var result = await _dbContext.Queryable<BusinessShiftEntity>()
|
|
.Select<BusinessPlaceShiftResponse>()
|
|
.ToListAsync();
|
|
|
|
return result;
|
|
}
|
|
|
|
public async Task<Guid> SaveAsync(BusinessPlaceShiftSaveRequest request)
|
|
{
|
|
await CheckExistsAsync(request);
|
|
|
|
if (!request.Id.HasValue)
|
|
{
|
|
var entity = request.Adapt<BusinessShiftEntity>();
|
|
entity.CustomCode = request.CustomCode;
|
|
entity.Code = Guid.NewGuid();
|
|
await _dbContext.InsertAsync(entity);
|
|
|
|
return entity.Code;
|
|
}
|
|
else
|
|
{
|
|
var entity = await _dbContext.Queryable<BusinessShiftEntity>().FirstAsync(x => x.Id == request.Id);
|
|
entity.ThrowIfNull("餐次不存在");
|
|
|
|
request.Adapt(entity);
|
|
await _dbContext.UpdateAsync(entity);
|
|
|
|
return entity.Code;
|
|
}
|
|
}
|
|
|
|
public async Task SaveMealShiftsAsync(List<BusinessPlaceShiftSaveMealShiftRequest> requests)
|
|
{
|
|
foreach (var request in requests)
|
|
{
|
|
var shift = await CheckExistsShiftAsync(request.ShiftCode);
|
|
await CheckExistsMealShiftAsync(request);
|
|
await DuplicateTimePeriodAsync(request);
|
|
|
|
if (!request.Id.HasValue)
|
|
{
|
|
var entity = request.Adapt<BusinessShiftMealRelationshipEntity>();
|
|
|
|
entity.ShiftCode = shift.Code;
|
|
entity.ShiftCustomCode = shift.CustomCode;
|
|
entity.Start = request.TimePeriod.Start.Value;
|
|
entity.End = request.TimePeriod.End.Value;
|
|
|
|
await _dbContext.InsertAsync(entity);
|
|
}
|
|
else
|
|
{
|
|
var entity = await _dbContext.Queryable<BusinessShiftMealRelationshipEntity>().FirstAsync(x => x.Id == request.Id);
|
|
entity.ThrowIfNull("餐次段不存在");
|
|
|
|
request.Adapt(entity);
|
|
await _dbContext.UpdateAsync(entity);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public async Task<BusinessPlaceWithShiftResponse> GetShiftsByPlaceCustomCodeAsync(string placeCustomCode)
|
|
{
|
|
var place = await _dbContext.Queryable<BusinessPlaceEntity>().Where(x => x.CustomCode == placeCustomCode).FirstAsync();
|
|
if (place == null)
|
|
{
|
|
return new BusinessPlaceWithShiftResponse()
|
|
{
|
|
Shifts = new List<BusinessPlaceShiftTinyResponse>()
|
|
};
|
|
}
|
|
|
|
var tenantResult = await _tenantApi.GetTenantByCodeAsync(place.TenantId);
|
|
(tenantResult.Code == ApiStateCode.Success).ThrowIfFalse(tenantResult.Msg);
|
|
var tenantInfo = tenantResult.Data;
|
|
|
|
var relationship = await _dbContext.Queryable<BusinessPlaceShiftRelationshipEntity>().Where(x => x.PlaceCode == place.Code).FirstAsync();
|
|
if (relationship == null)
|
|
{
|
|
return new BusinessPlaceWithShiftResponse()
|
|
{
|
|
CustomCode = placeCustomCode,
|
|
Name = place.Name,
|
|
TenantCode = tenantInfo.Code,
|
|
TenantName = tenantInfo.Name,
|
|
Shifts = new List<BusinessPlaceShiftTinyResponse>()
|
|
};
|
|
}
|
|
|
|
var shifts = await _dbContext.Queryable<BusinessShiftMealRelationshipEntity>()
|
|
.Where(x => x.ShiftCode == relationship.ShiftCode)
|
|
.OrderBy(x => x.Sequence) //排序
|
|
.ToListAsync();
|
|
|
|
var list = new List<BusinessPlaceShiftTinyResponse>();
|
|
|
|
foreach (BusinessShiftMealRelationshipEntity shiftinfo in shifts)
|
|
{
|
|
var name = _dbContext.Queryable<BasicTypeEntity>()
|
|
.Where(x => x.Code == shiftinfo.ShiftType.ToString())
|
|
.Select(x => x.Display)
|
|
.First();
|
|
|
|
var shift = new BusinessPlaceShiftTinyResponse
|
|
{
|
|
CustomCode = shiftinfo.Id.ToString(),
|
|
Name = name,
|
|
Start = shiftinfo.Start,
|
|
End = shiftinfo.End
|
|
};
|
|
|
|
list.Add(shift);
|
|
}
|
|
return new BusinessPlaceWithShiftResponse
|
|
{
|
|
CustomCode = placeCustomCode,
|
|
Name = place.Name,
|
|
TenantCode = tenantInfo.Code,
|
|
TenantName = tenantInfo.Name,
|
|
Shifts = list
|
|
};
|
|
}
|
|
|
|
public async Task<Pagination<DeviceCodeNameDetail>> GetDevicesByCode(BusinessPlaceGetByCodeRequest request)
|
|
{
|
|
var regiss = await _dbContext.Queryable<DeviceRegistryEntity>()
|
|
.Where(x => x.BusinessPlaceCode.ToString() == request.Code)
|
|
.ToListAsync();
|
|
|
|
var devices = await _dbContext.Queryable<DeviceEntity>().ToListAsync();
|
|
|
|
var list = new List<DeviceCodeNameDetail>();
|
|
if (regiss.Count > 0)
|
|
{
|
|
foreach (var regis in regiss)
|
|
{
|
|
var device = devices.Where(x => x.UniqueNo == regis.DeviceUniqueNo)
|
|
.FirstOrDefault();
|
|
if (device != null)
|
|
{
|
|
var detail = new DeviceCodeNameDetail
|
|
{
|
|
UniqueNo = regis.DeviceUniqueNo,
|
|
UniqueName = device.Supplier
|
|
};
|
|
list.Add(detail);
|
|
}
|
|
}
|
|
}
|
|
//分页
|
|
var startIndex = (request.PageIndex - 1) * request.PageSize;
|
|
var pagedData = list.Skip(startIndex).Take(request.PageSize).ToList();
|
|
|
|
var pagination = new Pagination<DeviceCodeNameDetail>
|
|
{
|
|
PageIndex = request.PageIndex,
|
|
PageSize = request.PageSize,
|
|
Total = list.Count, // 使用原始列表的总数进行分页
|
|
Data = pagedData
|
|
};
|
|
|
|
return pagination;
|
|
}
|
|
|
|
|
|
public async Task DispositionDeviceAsync(DispositionDeviceRequest request)
|
|
{
|
|
var places = await _dbContext.Queryable<BusinessPlaceEntity>().ToListAsync();
|
|
var place = places.Where(x => x.Code.ToString() == request.PlaceCode).First();
|
|
place.ThrowIfNull($"{request.PlaceCode}:该营业点不存在");
|
|
|
|
var devices = await _dbContext.Queryable<DeviceEntity>().ToListAsync();
|
|
|
|
if (request.UniqueNos != null && request.UniqueNos.Count > 0)
|
|
{
|
|
foreach (var no in request.UniqueNos)
|
|
{
|
|
var device = devices.Where(x => x.UniqueNo == no).FirstOrDefault();
|
|
device.ThrowIfNull($"{no}:设备不存在");
|
|
}
|
|
}
|
|
|
|
var regiss = await _dbContext.Queryable<DeviceRegistryEntity>()
|
|
.Where(x => request.UniqueNos.Contains(x.DeviceUniqueNo))
|
|
.ToListAsync();
|
|
|
|
var list = new List<DeviceRegistryEntity>();
|
|
|
|
foreach (var regis in regiss)
|
|
{
|
|
regis.BusinessPlaceCode = place.Code;
|
|
regis.BusinessPlaceCustomCode = place.CustomCode;
|
|
list.Add(regis);
|
|
}
|
|
await _dbContext.UpdateAsync(list);
|
|
}
|
|
|
|
//*********************************************** help methods ***************************************************//
|
|
|
|
/// <summary>
|
|
/// 时间段重合检查
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
private async Task DuplicateTimePeriodAsync(BusinessPlaceShiftSaveMealShiftRequest request)
|
|
{
|
|
var periods = await _dbContext.Queryable<BusinessShiftMealRelationshipEntity>()
|
|
.Where(x => x.ShiftCode == request.ShiftCode)
|
|
.WhereIF(request.Id.HasValue, x => x.Id != request.Id)
|
|
.Select(x => new TimePeriod
|
|
{
|
|
Start = x.Start,
|
|
End = x.End,
|
|
})
|
|
.ToListAsync();
|
|
|
|
foreach (var period in periods)
|
|
{
|
|
period.IsDuplicate1(request.TimePeriod).ThrowIfTrue($"存在时间段重合[{period.Start}-{period.End}]");
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 检查重复
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
private async Task CheckExistsAsync(BusinessPlaceShiftSaveRequest request)
|
|
{
|
|
var existsSameCustomCode = await _dbContext.Queryable<BusinessShiftEntity>()
|
|
.Where(x => x.CustomCode == request.CustomCode || x.Name == request.Name)
|
|
.WhereIF(request.Id.HasValue, x => x.Id != request.Id)
|
|
.AnyAsync();
|
|
|
|
existsSameCustomCode.ThrowIfTrue($"自定义手工号或者名称存在重复,请检查.");
|
|
}
|
|
|
|
private async Task<BusinessShiftEntity> CheckExistsShiftAsync(Guid shiftCode)
|
|
{
|
|
var shift = await _dbContext.Queryable<BusinessShiftEntity>().Where(x => x.Code == shiftCode).FirstAsync();
|
|
shift.ThrowIfNull("餐次不存在");
|
|
|
|
return shift;
|
|
}
|
|
|
|
private async Task CheckExistsMealShiftAsync(BusinessPlaceShiftSaveMealShiftRequest request)
|
|
{
|
|
var exists = await _dbContext.Queryable<BusinessShiftMealRelationshipEntity>()
|
|
.Where(x => x.ShiftCode == request.ShiftCode)
|
|
.Where(x => x.ShiftType == request.ShiftType)
|
|
.WhereIF(request.Id.HasValue, x => x.Id != request.Id)
|
|
.AnyAsync();
|
|
|
|
exists.ThrowIfTrue("重复设置!");
|
|
}
|
|
}
|