Job_InspectionWorkOrder_Quartz.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using Newtonsoft.Json;
  2. using Quartz;
  3. using Ropin.Inspection.Common.Helper;
  4. using Ropin.Inspection.Model.SearchModel;
  5. using Ropin.Inspection.Model.ViewModel;
  6. using Ropin.Inspection.Service.Interface;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace Ropin.Inspection.Tasks.QuartzNet.Jobs
  13. {
  14. public class Job_InspectionWorkOrder_Quartz : JobBase, IJob
  15. {
  16. private readonly ITispRecordItemService _tispRecordItemService;
  17. private readonly IReportService _reportService;
  18. private readonly ITispContentGroupService _tispContentGroupService;
  19. public Job_InspectionWorkOrder_Quartz(ITispRecordItemService tispRecordItemService, IReportService reportService, ITasksQzServices tasksQzServices, ITispContentGroupService tispContentGroupService)
  20. {
  21. _tispRecordItemService = tispRecordItemService;
  22. _tasksQzServices = tasksQzServices;
  23. _reportService = reportService;
  24. _tispContentGroupService = tispContentGroupService;
  25. }
  26. public async Task Execute(IJobExecutionContext context)
  27. {
  28. var executeLog = await ExecuteJob(context, async () => await Run(context));
  29. }
  30. public async Task Run(IJobExecutionContext context)
  31. {
  32. JobDataMap data = context.JobDetail.JobDataMap;
  33. string storeCode = data.GetString("JobParam");
  34. DateTime beginDate;//=Convert.ToDateTime("2025-02-07 00:00:00");
  35. DateTime endDate;//=Convert.ToDateTime("2025-03-20 00:00:00");
  36. DateHelper.GetPeriod(DateHelper.Period.Week, out beginDate, out endDate);
  37. TispContentGroupsSearchModel searchModel = new TispContentGroupsSearchModel();
  38. searchModel.C_StoreCode = storeCode;
  39. var list = await _tispContentGroupService.GetContentGroupsAsync(searchModel);
  40. if (list!=null)
  41. {
  42. var rows = list.GroupBy(item =>new { item.C_DevStoreCode,item.C_DevName }).ToList();
  43. foreach (var item in rows)
  44. {
  45. if (item!=null)
  46. {
  47. var l = await _tispRecordItemService.GetInspectionWorkOrderAsync(beginDate, endDate, storeCode, item.Key.C_DevStoreCode);
  48. ReportViewModel reportViewModel = new ReportViewModel
  49. {
  50. G_ID = Guid.NewGuid(),
  51. C_StoreCode = storeCode,
  52. C_DevStoreCode = item.Key.C_DevStoreCode,
  53. I_Type = 5,
  54. C_GroupName = "点检工单记录",
  55. C_Name = item.Key.C_DevName + "点检工单记录" + "(" + DateTime.Now.AddDays(1).ToString("yyyy/MM/dd HH:mm") + ")",
  56. C_Status = "1",
  57. D_CreateTime = DateTime.Parse(DateTime.Now.AddDays(1).ToString("yyyy/MM/dd HH:mm")),
  58. D_Start = beginDate,
  59. D_End = endDate,
  60. C_Data = JsonConvert.SerializeObject(l)
  61. };
  62. await _reportService.CreateOneAsync(reportViewModel);
  63. }
  64. }
  65. }
  66. }
  67. }
  68. }