颐和api

HangfirePlanTimeingController.cs 3.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Mvc;
  6. using MadRunFabric.Common;
  7. using Microsoft.AspNetCore.Authorization;
  8. using DistributionApi.IRepositories;
  9. using Microsoft.Extensions.Logging;
  10. using Api.SignToken;
  11. using MadRunFabric.Model;
  12. using MongoDB.Bson;
  13. using System.Security.Claims;
  14. namespace DistributionApi.Controllers
  15. {
  16. /// <summary>
  17. /// 自动定时计划
  18. /// </summary>
  19. [Authorize]
  20. [ApiVersion("6.0")]
  21. [Produces("application/json")]
  22. [Route("api/[controller]")]
  23. public class HangfirePlanTimeingController : BaseController
  24. {
  25. private readonly ILogger<HangfirePlanTimeingController> _logger;
  26. private readonly IHangfirePlan_DistributionRepository _hangfireplan_distributionrepository;
  27. private readonly IHangfireService _hangfireService;
  28. public HangfirePlanTimeingController(
  29. ILogger<HangfirePlanTimeingController> logger,
  30. IHangfirePlan_DistributionRepository hangfireplan_distributionrepository,
  31. IHangfireService hangfireService
  32. )
  33. {
  34. _logger = logger;
  35. _hangfireplan_distributionrepository = hangfireplan_distributionrepository;
  36. _hangfireService = hangfireService;
  37. }
  38. /// <summary>
  39. /// 自动定时计划 - 自动分配
  40. /// 配送岗 抢单时效 3分钟(某单子此时间内没人抢,系统强制分配)
  41. /// 配送岗 待配送工单滞留时效 30分钟(超时就记一次超时违规记录,可以有违规申诉)
  42. /// </summary>
  43. /// <param name="wotype"></param>
  44. /// <param name="plancycle"></param>
  45. /// <param name="planinterval"></param>
  46. /// <returns></returns>
  47. [HttpPost("addautoassign")]
  48. public async Task<IActionResult> AddAutoAssignAsync(int plancycle, int planinterval)
  49. {
  50. var usercode = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  51. var model = new HangfirePlan_Distribution();
  52. model.id = ObjectId.GenerateNewId().ToString();
  53. model.wotype = 2;
  54. model.plantype = (int)EnumDistributionPlanType.timing;
  55. model.plancycle = plancycle;
  56. model.planinterval = planinterval;
  57. model.planstate = (int)EnumDistributionPlanState.start;//默认计划开启
  58. model.createby = usercode;
  59. model.createtime = DateTime.Now;
  60. model.isdelete = 0;
  61. bool b = await _hangfireplan_distributionrepository.Add(model);
  62. if (b)
  63. {
  64. SetTask(model.id, model.wotype, model.plancycle, model.planinterval);
  65. return Success("添加成功");
  66. }
  67. return Error("添加失败");
  68. }
  69. ///// <summary>
  70. ///// 获取计划定时事件详情
  71. ///// </summary>
  72. ///// <param name="planid"></param>
  73. ///// <returns></returns>
  74. //[AllowAnonymous]
  75. //[HttpPost("gethangfireplaninfo")]
  76. //public async Task<IActionResult> GetHangfirePlanInfo(string planid)
  77. //{
  78. // var model = await _hangfireplan_distributionrepository.GetSingle(planid);
  79. // if (model!=null)
  80. // {
  81. // return Success("添加成功", model);
  82. // }
  83. // return Error("添加失败");
  84. //}
  85. #region 设置定时任务
  86. private void SetTask(string id, int wotype, int plancycle, int planinterval)
  87. {
  88. _hangfireService.SaveAutoAssign(id, wotype, plancycle, planinterval);
  89. }
  90. #endregion
  91. }
  92. }