fix 处理营业点分配功能问题
This commit is contained in:
@@ -27,6 +27,7 @@ public class BusinessPlaceShiftSaveMealShiftRequest : IValidatableObject
|
||||
/// <summary>
|
||||
/// 时间段
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "时间段不可为空")]
|
||||
public TimePeriod TimePeriod { get; set; }
|
||||
|
||||
|
||||
@@ -37,14 +38,14 @@ public class BusinessPlaceShiftSaveMealShiftRequest : IValidatableObject
|
||||
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) });
|
||||
}
|
||||
|
||||
if (TimePeriod.Start == TimePeriod.End)
|
||||
if (TimePeriod!.Start == TimePeriod!.End)
|
||||
{
|
||||
yield return new ValidationResult("时间段设置区间有误,开始时段不能等于结束时段.", new[] { nameof(TimePeriod) });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public interface IBusinessPlaceShiftService : IScopeDependency
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -102,8 +102,8 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService
|
||||
|
||||
entity.ShiftCode = shift.Code;
|
||||
entity.ShiftCustomCode = shift.CustomCode;
|
||||
entity.Start = request.TimePeriod.Start.Value;
|
||||
entity.End = request.TimePeriod.End.Value;
|
||||
entity.Start = request.TimePeriod.Start!.Value;
|
||||
entity.End = request.TimePeriod.End!.Value;
|
||||
|
||||
await _dbContext.InsertAsync(entity);
|
||||
}
|
||||
@@ -112,11 +112,11 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService
|
||||
var entity = await _dbContext.Queryable<BusinessShiftMealRelationshipEntity>()
|
||||
.Where(x => x.ShiftCode == shiftCode)
|
||||
.SingleAsync(x => x.Id == request.Id);
|
||||
|
||||
|
||||
entity.ThrowIfNull("餐次段不存在");
|
||||
|
||||
entity.Start = request.TimePeriod.Start.Value;
|
||||
entity.End = request.TimePeriod.End.Value;
|
||||
entity.Start = request.TimePeriod.Start!.Value;
|
||||
entity.End = request.TimePeriod.End!.Value;
|
||||
|
||||
request.Adapt(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>()
|
||||
.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)
|
||||
return await _dbContext.Queryable<DeviceRegistryEntity>()
|
||||
.LeftJoin<DeviceEntity>((x, d) => x.DeviceUniqueNo == d.UniqueNo)
|
||||
.Where(x => x.BusinessPlaceCode == code)
|
||||
.Select((x, d) => new DeviceCodeNameDetail
|
||||
{
|
||||
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;
|
||||
UniqueNo = x.DeviceUniqueNo,
|
||||
UniqueName = d.DeployPlace
|
||||
})
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
place.ThrowIfNull("营业点不存在");
|
||||
|
||||
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();
|
||||
|
||||
foreach (var item in registries)
|
||||
{
|
||||
item.BusinessPlaceCode = request.PlaceCode;
|
||||
}
|
||||
registries.ForEach(item => { item.BusinessPlaceCode = request.UniqueNos.Contains(item.DeviceUniqueNo) ? request.PlaceCode : null; });
|
||||
|
||||
await _dbContext.UpdateAsync(registries);
|
||||
}
|
||||
|
||||
@@ -15,10 +15,8 @@ public class AssignPermissionLimitAttribute : Attribute, IAsyncActionFilter
|
||||
|
||||
var currentTenantId = currentUser.GetStringTenantId();
|
||||
|
||||
await using (var handler = await redisCache.LockAsync($"permission:generate:{currentTenantId}"))
|
||||
{
|
||||
handler.Acquired.ThrowIfFalse("请勿频繁分配");
|
||||
await next();
|
||||
}
|
||||
await using var handler = await redisCache.LockAsync($"permission:generate:{currentTenantId}");
|
||||
handler.Acquired.ThrowIfFalse("请勿频繁分配");
|
||||
await next();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Dlhis.Basic.BusinessShift.Services;
|
||||
using Dlhis.Basic.Device.Filters;
|
||||
using Dlhis.Basic.Places.Request;
|
||||
using Dlhis.Basic.Places.Response;
|
||||
using Dlhis.Basic.Places.Services;
|
||||
@@ -109,12 +110,12 @@ public class BusinessPlacesController : ControllerBase
|
||||
/// <summary>
|
||||
/// 根据营业点获取下面的设备
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="code"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("devicenos")]
|
||||
public async Task<Pagination<DeviceCodeNameDetail>> GetDevicesByCode([FromQuery] BusinessPlaceGetByCodeRequest request)
|
||||
[HttpGet("device/assignments")]
|
||||
public async Task<List<DeviceCodeNameDetail>> GetAssignments(Guid code)
|
||||
{
|
||||
return await _businessPlaceShiftService.GetDevicesByCode(request);
|
||||
return await _businessPlaceShiftService.GetAssignmentsAsync(code);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -122,9 +123,11 @@ public class BusinessPlacesController : ControllerBase
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("disposition")]
|
||||
public async Task DispositionDeviceAsync(DispositionDeviceRequest request)
|
||||
[HttpPost("device/assign")]
|
||||
[AssignPermissionLimit]
|
||||
[DataPermission]
|
||||
public async Task Assign(DispositionDeviceRequest request)
|
||||
{
|
||||
await _businessPlaceShiftService.DispositionDeviceAsync(request);
|
||||
await _businessPlaceShiftService.AssignAsync(request);
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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 UniqueName { get; set; }
|
||||
}
|
||||
}
|
||||
public string UniqueNo { get; set; }
|
||||
public string UniqueName { get; set; }
|
||||
}
|
||||
@@ -86,7 +86,7 @@ public class MealSupplementRecordService : IMealSupplementRecordService
|
||||
.Where(x => x.Status == BalanceRecordStatusEnumType.Valid)
|
||||
.Where(x => x.ApplicationType == CanteenApplicationTypeEnumType.MealSupplement)
|
||||
.Where(x => x.UserCode == code)
|
||||
.OrderBy(x => x.CostDateTime, OrderByType.Desc)
|
||||
.OrderBy(x => x.CostDateTime)
|
||||
.Select(x => new MealSupplementRecordItemResponse
|
||||
{
|
||||
CurrentAmount = x.Amount,
|
||||
|
||||
@@ -303,7 +303,7 @@ public class BalanceService : IBalanceService
|
||||
.WhereIF(request.SearchDateTimePeriod?.End.HasValue == true, record => record.CostDate <= request.SearchDateTimePeriod.End)
|
||||
.WhereIF(request.ApplicationType.HasValue, record => record.ApplicationType == request.ApplicationType)
|
||||
.Where((record, ga) => ga.Code == jinkoCode)
|
||||
.OrderBy(record => record.CreateTime, OrderByType.Desc)
|
||||
.OrderBy(record => record.CostDateTime)
|
||||
.Select((record, ga, department, bPlace) => new BalanceRecordUserPageResponse
|
||||
{
|
||||
Id = record.Id,
|
||||
@@ -621,7 +621,7 @@ public class BalanceService : IBalanceService
|
||||
.Where(x => x.Code == request.UserCode)
|
||||
.SingleAsync();
|
||||
|
||||
(gainfo == null).ThrowIfTrue($"工号{request.UserCode}不存在");
|
||||
gainfo.ThrowIfNull($"工号{request.UserCode}不存在");
|
||||
|
||||
await _dbContext.InsertAsync(new BalanceRecordEntity
|
||||
{
|
||||
@@ -686,7 +686,7 @@ public class BalanceService : IBalanceService
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task ReCalcAsync(BalanceReCalcRequest request)
|
||||
{
|
||||
await CommonHelper.RetryAsync(async () =>
|
||||
|
||||
Reference in New Issue
Block a user