PriorityAppService.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Business.ResourceExamineManagement.Dto;
  2. using Bussiness.Model.MES.IC;
  3. using Bussiness.Model.Sale;
  4. using Bussiness.MongoModel.MES.IC;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using Volo.Abp.Application.Services;
  11. namespace Business.PriorityManagement
  12. {
  13. /// <summary>
  14. /// 优先级算法
  15. /// </summary>
  16. public class PriorityAppService : ApplicationService
  17. {
  18. /// <summary>
  19. /// 计算订单优先级
  20. /// </summary>
  21. /// <param name="seorders">订单数据</param>
  22. /// <param name="sentrys">订单行数据</param>
  23. /// <returns></returns>
  24. public List<PriorityDto> CalcOrderPriority(List<crm_seorder> seorders, List<crm_seorderentry> sentrys)
  25. {
  26. //数据处理:取主表数据
  27. var rtn = seorders.Select(p=>new PriorityDto {
  28. id = p.Id,
  29. urgent = p.urgent.GetValueOrDefault(),
  30. level = p.custom_level.GetValueOrDefault()
  31. }).AsQueryable<PriorityDto>().ToList(); ;
  32. //子表数据处理:根据订单id分组取出客户要求交期交期最大的数据
  33. var entrys = from t in sentrys
  34. group t by t.seorder_id into temp
  35. select new
  36. {
  37. id = temp.Key,
  38. plan_date = temp.Max(x => x.plan_date.GetValueOrDefault())
  39. };
  40. foreach (var item in rtn)
  41. {
  42. var entry = entrys.FirstOrDefault(p => p.id == item.id);
  43. if (entry != null)
  44. {
  45. item.plan_date = entry.plan_date;
  46. }
  47. }
  48. //根据紧急级别倒序,客户级别升序,交期升序排序
  49. rtn = rtn.OrderByDescending(p => p.urgent).ThenBy(m => m.level).ThenBy(n => n.plan_date).ToList();
  50. return rtn;
  51. }
  52. }
  53. }