147 lines
5.4 KiB
C#
147 lines
5.4 KiB
C#
using Dlhis.Entity.Basic.Entity;
|
|
using Dlhis.Entity.Basic.Enums;
|
|
using Dlhis.Entity.Canteen.Entities;
|
|
using Dlhis.Entity.Canteen.Enums;
|
|
using Dlhis.ScheduledTask.TaskAssignment.Request;
|
|
using Dlhis.ScheduledTask.TaskAssignment.Response;
|
|
using Dlhis.ScheduledTask.TaskAssignment.Services;
|
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop;
|
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
|
using Kurisu.AspNetCore.UnifyResultAndValidation.Aop;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using SqlSugar;
|
|
|
|
namespace Dlhis.ScheduledTask.TaskAssignment.Controllers;
|
|
|
|
/// <summary>
|
|
/// 任务分配
|
|
/// </summary>
|
|
[Authorize]
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class AssignmentsController : ControllerBase
|
|
{
|
|
private readonly IAssignmentService _assignmentService;
|
|
private readonly IDbContext _dbContext;
|
|
|
|
public AssignmentsController(IAssignmentService assignmentService, IDbContext dbContext)
|
|
{
|
|
_assignmentService = assignmentService;
|
|
_dbContext = dbContext;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取设备任务(按设备)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[DisableApiLog]
|
|
[IgnoreTenant]
|
|
[HttpGet("deviceTasks")]
|
|
public async Task<List<DeviceTaskToDeviceByDeviceResponse>> DeviceGetTasksGetAsync([FromQuery] DeviceTaskGetRequest request)
|
|
{
|
|
return await _assignmentService.DeviceGetTasksAsync(request);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取设备任务(按设备)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[DisableApiLog]
|
|
[HttpPost("deviceTasks")]
|
|
[IgnoreTenant]
|
|
public async Task<List<DeviceTaskToDeviceByDeviceResponse>> DeviceGetTasksPostAsync(DeviceTaskGetRequest request)
|
|
{
|
|
return await _assignmentService.DeviceGetTasksAsync(request);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新任务状态
|
|
/// </summary>
|
|
/// <param name="requests"></param>
|
|
/// <returns></returns>
|
|
[DisableApiLog]
|
|
[HttpPost("taskStatus")]
|
|
[IgnoreTenant]
|
|
public async Task UpdateDeviceTaskStatusAsync(List<UpdateDeviceTaskStatusRequest> requests)
|
|
{
|
|
await _assignmentService.UpdateDeviceTaskStatusAsync(requests);
|
|
}
|
|
|
|
[AllowAnonymous]
|
|
[HttpPost("balance/calc")]
|
|
[IgnoreTenant]
|
|
public async Task Calc()
|
|
{
|
|
var s = new DateTime(2025, 7, 1);
|
|
var e = new DateTime(2025, 8, 1);
|
|
|
|
var userCodes = await _dbContext.Queryable<UserBalanceEntity>()
|
|
.Where(x => SqlFunc.Subqueryable<UserBalanceTmpEntity>().Where(p => p.UserCode == x.UserCode).NotAny())
|
|
.Select(x => x.UserCode)
|
|
.Distinct()
|
|
.ToListAsync();
|
|
|
|
foreach (var userCode in userCodes)
|
|
{
|
|
if (!await _dbContext.Queryable<UserBalanceTmpEntity>().Where(x => x.UserCode == userCode).AnyAsync())
|
|
{
|
|
await _dbContext.InsertAsync(new UserBalanceTmpEntity
|
|
{
|
|
UserCode = userCode,
|
|
Balance = 0,
|
|
Version = 0
|
|
});
|
|
}
|
|
|
|
var balance = await _dbContext.Queryable<BalanceRecordEntity>()
|
|
.Where(x => x.UserCode == userCode)
|
|
.Where(x => x.Status == BalanceRecordStatusEnumType.Valid)
|
|
.Where(x => x.Type == BalanceRecordTypeEnumType.Out)
|
|
.Where(x => x.CostDate >= s && x.CostDate <= e)
|
|
.Where(x => !BalanceRecordSourceConstants.IgnoreSources.Contains(x.Source))
|
|
.SumAsync(x => x.Amount);
|
|
|
|
await _dbContext.Updateable<UserBalanceTmpEntity>()
|
|
.SetColumns(x => x.Balance == balance)
|
|
.SetColumns(x => x.ModifiedTime == DateTime.Now)
|
|
.Where(x => x.UserCode == userCode)
|
|
.ExecuteCommandAsync();
|
|
}
|
|
|
|
|
|
//
|
|
// var userCodes = await _dbContext.Queryable<GainfoLeaveEntity>().Where(x => x.ResignationDate.HasValue && x.ResignationDate >= s && x.ResignationDate <= e)
|
|
// .Where(x => x.Type != GainfoUserTypeEnumType.External && x.Type != GainfoUserTypeEnumType.Outsource)
|
|
// .Select(x => x.Code)
|
|
// .Distinct()
|
|
// .ToListAsync();
|
|
//
|
|
// foreach (var userCode in userCodes)
|
|
// {
|
|
// if (!await _dbContext.Queryable<UserBalanceTmpEntity>().Where(x => x.UserCode == userCode).AnyAsync())
|
|
// {
|
|
// await _dbContext.InsertAsync(new UserBalanceTmpEntity
|
|
// {
|
|
// UserCode = userCode,
|
|
// Balance = 0,
|
|
// Version = 0
|
|
// });
|
|
// }
|
|
//
|
|
// var balance = await _dbContext.Queryable<BalanceRecordEntity>()
|
|
// .Where(x => x.UserCode == userCode)
|
|
// .Where(x => x.Status == BalanceRecordStatusEnumType.Valid)
|
|
// .Where(x => !BalanceRecordSourceConstants.IgnoreSources.Contains(x.Source))
|
|
// .Where(x => x.CostDate >= s && x.CostDate <= e)
|
|
// .Where(x => x.Type == BalanceRecordTypeEnumType.In)
|
|
// .SumAsync(x => x.Amount);
|
|
//
|
|
// await _dbContext.Updateable<UserBalanceTmpEntity>()
|
|
// .SetColumns(x => x.Balance == balance)
|
|
// .SetColumns(x => x.ModifiedTime == DateTime.Now)
|
|
// .Where(x => x.UserCode == userCode)
|
|
// .ExecuteCommandAsync();
|
|
// }
|
|
}
|
|
} |