TaskAssignment.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using OASystem.Domain.Entities.PersonnelModule;
  2. using OASystem.Infrastructure.Repositories.PersonnelModule;
  3. using ILogger = Microsoft.Extensions.Logging.ILogger;
  4. namespace OASystem.API.OAMethodLib.Quartz.Business
  5. {
  6. /// <summary>
  7. /// 任务指派
  8. /// 定时任务
  9. /// </summary>
  10. public static class TaskAssignment
  11. {
  12. private readonly static TaskAllocationRepository _taskAllocationRep = AutofacIocManager.Instance.GetService<TaskAllocationRepository>();
  13. //private readonly static SqlSugarClient _sqlSugar = AutofacIocManager.Instance.GetService<SqlSugarClient>();
  14. private readonly static ILogger _logger;
  15. /// <summary>
  16. /// 定时任务更改状态
  17. /// 每天下午六点定时更新
  18. /// </summary>
  19. public static async void PostTaskUpdateStatus()
  20. {
  21. //_taskAllocationRep.ChangeDataBase(DBEnum.OA2023DB);
  22. var newDB = _taskAllocationRep._sqlSugar.CopyNew();
  23. var data = newDB.Queryable<Pm_TaskAllocation>()
  24. .Where(it => it.IsDel == 0 &&
  25. !string.IsNullOrEmpty(it.PredictEndTime) &&
  26. Convert.ToDateTime(it.PredictEndTime) >= DateTime.Now
  27. )
  28. .ToList();
  29. if (data.Count > 0)
  30. {
  31. //处理要变更状态的员工
  32. List<int> primaryIds = new List<int>();
  33. primaryIds = data.Select(it => it.Id).ToList();
  34. var subData = newDB.Queryable<Pm_TaskRelevanceUser>()
  35. .Where(it =>
  36. it.IsDel == 0 &&
  37. primaryIds.Contains(it.TAId) &&
  38. it.TaskStatus <= TaskerEnum.UnderWay
  39. )
  40. .ToList();
  41. if (subData.Count > 0)
  42. {
  43. foreach (var item in subData)
  44. {
  45. item.OverTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  46. item.TaskStatus = TaskerEnum.UnFinished;
  47. item.Cause = string.Format(@"任务没有提交完成或者超时,由系统设置任务未完成");
  48. }
  49. var updateStatus = newDB.Updateable(subData)
  50. .WhereColumns(it => it.Id)
  51. .ExecuteCommand();
  52. //_taskAllocationRep._sqlSugar.Close();
  53. }
  54. }
  55. }
  56. }
  57. }