fix 处理营业点分配功能问题

This commit is contained in:
2024-07-02 15:53:55 +08:00
parent 38ab947790
commit 2cea51232f
9 changed files with 46 additions and 91 deletions

View File

@@ -27,6 +27,7 @@ public class BusinessPlaceShiftSaveMealShiftRequest : IValidatableObject
/// <summary> /// <summary>
/// 时间段 /// 时间段
/// </summary> /// </summary>
[Required(ErrorMessage = "时间段不可为空")]
public TimePeriod TimePeriod { get; set; } public TimePeriod TimePeriod { get; set; }
@@ -37,12 +38,12 @@ public class BusinessPlaceShiftSaveMealShiftRequest : IValidatableObject
yield return new ValidationResult("时间段配置错误", new[] { nameof(TimePeriod) }); yield return new ValidationResult("时间段配置错误", new[] { nameof(TimePeriod) });
} }
if (TimePeriod?.Start == null || TimePeriod?.End == null) if (TimePeriod!.Start == null || TimePeriod!.End == null)
{ {
yield return new ValidationResult("时间段配置错误", new[] { nameof(TimePeriod) }); yield return new ValidationResult("时间段配置错误", new[] { nameof(TimePeriod) });
} }
if (TimePeriod.Start == TimePeriod.End) if (TimePeriod!.Start == TimePeriod!.End)
{ {
yield return new ValidationResult("时间段设置区间有误,开始时段不能等于结束时段.", new[] { nameof(TimePeriod) }); yield return new ValidationResult("时间段设置区间有误,开始时段不能等于结束时段.", new[] { nameof(TimePeriod) });
} }

View File

@@ -18,7 +18,7 @@ public interface IBusinessPlaceShiftService : IScopeDependency
Task<BusinessPlaceWithShiftResponse> GetShiftsByPlaceCustomCodeAsync(string placeCustomCode); Task<BusinessPlaceWithShiftResponse> GetShiftsByPlaceCustomCodeAsync(string placeCustomCode);
Task<Pagination<DeviceCodeNameDetail>> GetDevicesByCode(BusinessPlaceGetByCodeRequest request); Task<List<DeviceCodeNameDetail>> GetAssignmentsAsync(Guid code);
Task DispositionDeviceAsync(DispositionDeviceRequest request); Task AssignAsync(DispositionDeviceRequest request);
} }

View File

@@ -102,8 +102,8 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService
entity.ShiftCode = shift.Code; entity.ShiftCode = shift.Code;
entity.ShiftCustomCode = shift.CustomCode; entity.ShiftCustomCode = shift.CustomCode;
entity.Start = request.TimePeriod.Start.Value; entity.Start = request.TimePeriod.Start!.Value;
entity.End = request.TimePeriod.End.Value; entity.End = request.TimePeriod.End!.Value;
await _dbContext.InsertAsync(entity); await _dbContext.InsertAsync(entity);
} }
@@ -115,8 +115,8 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService
entity.ThrowIfNull("餐次段不存在"); entity.ThrowIfNull("餐次段不存在");
entity.Start = request.TimePeriod.Start.Value; entity.Start = request.TimePeriod.Start!.Value;
entity.End = request.TimePeriod.End.Value; entity.End = request.TimePeriod.End!.Value;
request.Adapt(entity); request.Adapt(entity);
await _dbContext.UpdateAsync(entity); await _dbContext.UpdateAsync(entity);
@@ -183,62 +183,30 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService
}; };
} }
public async Task<Pagination<DeviceCodeNameDetail>> GetDevicesByCode(BusinessPlaceGetByCodeRequest request) public async Task<List<DeviceCodeNameDetail>> GetAssignmentsAsync(Guid code)
{ {
var regiss = await _dbContext.Queryable<DeviceRegistryEntity>() return await _dbContext.Queryable<DeviceRegistryEntity>()
.Where(x => x.BusinessPlaceCode.ToString() == request.Code) .LeftJoin<DeviceEntity>((x, d) => x.DeviceUniqueNo == d.UniqueNo)
.Where(x => x.BusinessPlaceCode == code)
.Select((x, d) => new DeviceCodeNameDetail
{
UniqueNo = x.DeviceUniqueNo,
UniqueName = d.DeployPlace
})
.ToListAsync(); .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) public async Task AssignAsync(DispositionDeviceRequest request)
{ {
var place = await _dbContext.Queryable<BusinessPlaceEntity>().Where(x => x.Code == request.PlaceCode).SingleAsync(); var place = await _dbContext.Queryable<BusinessPlaceEntity>().Where(x => x.Code == request.PlaceCode).SingleAsync();
place.ThrowIfNull("营业点不存在"); place.ThrowIfNull("营业点不存在");
var registries = await _dbContext.Queryable<DeviceRegistryEntity>() var registries = await _dbContext.Queryable<DeviceRegistryEntity>()
.Where(x => request.UniqueNos.Contains(x.DeviceUniqueNo)) .Where(x => x.BusinessPlaceCode == request.PlaceCode || request.UniqueNos.Contains(x.DeviceUniqueNo))
.ToListAsync(); .ToListAsync();
foreach (var item in registries) registries.ForEach(item => { item.BusinessPlaceCode = request.UniqueNos.Contains(item.DeviceUniqueNo) ? request.PlaceCode : null; });
{
item.BusinessPlaceCode = request.PlaceCode;
}
await _dbContext.UpdateAsync(registries); await _dbContext.UpdateAsync(registries);
} }

View File

@@ -15,10 +15,8 @@ public class AssignPermissionLimitAttribute : Attribute, IAsyncActionFilter
var currentTenantId = currentUser.GetStringTenantId(); var currentTenantId = currentUser.GetStringTenantId();
await using (var handler = await redisCache.LockAsync($"permission:generate:{currentTenantId}")) await using var handler = await redisCache.LockAsync($"permission:generate:{currentTenantId}");
{
handler.Acquired.ThrowIfFalse("请勿频繁分配"); handler.Acquired.ThrowIfFalse("请勿频繁分配");
await next(); await next();
} }
}
} }

View File

@@ -1,4 +1,5 @@
using Dlhis.Basic.BusinessShift.Services; using Dlhis.Basic.BusinessShift.Services;
using Dlhis.Basic.Device.Filters;
using Dlhis.Basic.Places.Request; using Dlhis.Basic.Places.Request;
using Dlhis.Basic.Places.Response; using Dlhis.Basic.Places.Response;
using Dlhis.Basic.Places.Services; using Dlhis.Basic.Places.Services;
@@ -109,12 +110,12 @@ public class BusinessPlacesController : ControllerBase
/// <summary> /// <summary>
/// 根据营业点获取下面的设备 /// 根据营业点获取下面的设备
/// </summary> /// </summary>
/// <param name="request"></param> /// <param name="code"></param>
/// <returns></returns> /// <returns></returns>
[HttpGet("devicenos")] [HttpGet("device/assignments")]
public async Task<Pagination<DeviceCodeNameDetail>> GetDevicesByCode([FromQuery] BusinessPlaceGetByCodeRequest request) public async Task<List<DeviceCodeNameDetail>> GetAssignments(Guid code)
{ {
return await _businessPlaceShiftService.GetDevicesByCode(request); return await _businessPlaceShiftService.GetAssignmentsAsync(code);
} }
/// <summary> /// <summary>
@@ -122,9 +123,11 @@ public class BusinessPlacesController : ControllerBase
/// </summary> /// </summary>
/// <param name="request"></param> /// <param name="request"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost("disposition")] [HttpPost("device/assign")]
public async Task DispositionDeviceAsync(DispositionDeviceRequest request) [AssignPermissionLimit]
[DataPermission]
public async Task Assign(DispositionDeviceRequest request)
{ {
await _businessPlaceShiftService.DispositionDeviceAsync(request); await _businessPlaceShiftService.AssignAsync(request);
} }
} }

View File

@@ -1,14 +0,0 @@
using System.ComponentModel.DataAnnotations;
using Kurisu.AspNetCore.DataAccess.Dto;
namespace Dlhis.Basic.Places.Request
{
public class BusinessPlaceGetByCodeRequest : PageDto
{
/// <summary>
/// 营业点号
/// </summary>
[Required(ErrorMessage = "营业点号不能为空")]
public string Code { get; set; }
}
}

View File

@@ -1,8 +1,7 @@
namespace Dlhis.Basic.Places.Response namespace Dlhis.Basic.Places.Response;
public class DeviceCodeNameDetail
{ {
public class DeviceCodeNameDetail
{
public string UniqueNo { get; set; } public string UniqueNo { get; set; }
public string UniqueName { get; set; } public string UniqueName { get; set; }
}
} }

View File

@@ -86,7 +86,7 @@ public class MealSupplementRecordService : IMealSupplementRecordService
.Where(x => x.Status == BalanceRecordStatusEnumType.Valid) .Where(x => x.Status == BalanceRecordStatusEnumType.Valid)
.Where(x => x.ApplicationType == CanteenApplicationTypeEnumType.MealSupplement) .Where(x => x.ApplicationType == CanteenApplicationTypeEnumType.MealSupplement)
.Where(x => x.UserCode == code) .Where(x => x.UserCode == code)
.OrderBy(x => x.CostDateTime, OrderByType.Desc) .OrderBy(x => x.CostDateTime)
.Select(x => new MealSupplementRecordItemResponse .Select(x => new MealSupplementRecordItemResponse
{ {
CurrentAmount = x.Amount, CurrentAmount = x.Amount,

View File

@@ -303,7 +303,7 @@ public class BalanceService : IBalanceService
.WhereIF(request.SearchDateTimePeriod?.End.HasValue == true, record => record.CostDate <= request.SearchDateTimePeriod.End) .WhereIF(request.SearchDateTimePeriod?.End.HasValue == true, record => record.CostDate <= request.SearchDateTimePeriod.End)
.WhereIF(request.ApplicationType.HasValue, record => record.ApplicationType == request.ApplicationType) .WhereIF(request.ApplicationType.HasValue, record => record.ApplicationType == request.ApplicationType)
.Where((record, ga) => ga.Code == jinkoCode) .Where((record, ga) => ga.Code == jinkoCode)
.OrderBy(record => record.CreateTime, OrderByType.Desc) .OrderBy(record => record.CostDateTime)
.Select((record, ga, department, bPlace) => new BalanceRecordUserPageResponse .Select((record, ga, department, bPlace) => new BalanceRecordUserPageResponse
{ {
Id = record.Id, Id = record.Id,
@@ -621,7 +621,7 @@ public class BalanceService : IBalanceService
.Where(x => x.Code == request.UserCode) .Where(x => x.Code == request.UserCode)
.SingleAsync(); .SingleAsync();
(gainfo == null).ThrowIfTrue($"工号{request.UserCode}不存在"); gainfo.ThrowIfNull($"工号{request.UserCode}不存在");
await _dbContext.InsertAsync(new BalanceRecordEntity await _dbContext.InsertAsync(new BalanceRecordEntity
{ {