MachineToPmController.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using Cksoft.Data;
  2. using Cksoft.Data.Repository;
  3. using DllEapDal;
  4. using DllEapEntity.Dtos;
  5. using DllEapEntity.PM;
  6. using Microsoft.AspNetCore.Authorization;
  7. using Microsoft.AspNetCore.Mvc;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Text;
  11. namespace DllEapBll.Controllers
  12. {
  13. /// <summary>
  14. /// 机台保养
  15. /// </summary>
  16. [Authorize]
  17. [ApiController]
  18. [Route("eap/api/[controller]/[action]")]
  19. public class MachineToPmController : ControllerBase
  20. {
  21. /// <summary>
  22. /// 机台保养情况列表
  23. /// </summary>
  24. /// <param name="filter"></param>
  25. /// <param name="sort"></param>
  26. /// <param name="states"></param>
  27. /// <param name="pageIndex"></param>
  28. /// <param name="pageSize"></param>
  29. /// <param name="sortField"></param>
  30. /// <param name="sortOrder"></param>
  31. /// <returns></returns>
  32. [HttpGet]
  33. public LayuiModel<MachineToPM> Get(string filter, string sort, string states, int pageIndex = 1, int pageSize = 10, string sortField = "ID", string sortOrder = "ascend")
  34. {
  35. if (!string.IsNullOrEmpty(sort))
  36. {
  37. var arr = sort.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  38. if (arr != null && arr.Length > 0)
  39. {
  40. sortField = arr[0];
  41. sortOrder = arr[1];
  42. }
  43. }
  44. if (sortOrder == "descend")
  45. {
  46. sortOrder = "desc";
  47. }
  48. else
  49. {
  50. sortOrder = "asc";
  51. }
  52. int start, end;
  53. start = (pageIndex - 1) * pageSize + 1;
  54. end = start + pageSize;
  55. using (IDatabase db = DbFactory.Base("eapslave"))
  56. {
  57. db.BeginTrans();
  58. var dal = new MachineToPmDal(db);
  59. // var total = dal.GetCount(filter);
  60. int total = 0;
  61. string errorinfo = string.Empty;
  62. var roles = dal.Get(start, pageSize, sortOrder, sortField, filter, states, errorinfo, out total);
  63. return new LayuiModel<MachineToPM>
  64. {
  65. code = 1,
  66. count = total,
  67. data = roles,
  68. msg = ""
  69. };
  70. }
  71. }
  72. /// <summary>
  73. /// 详情
  74. /// </summary>
  75. /// <param name="id"></param>
  76. /// <returns></returns>
  77. [HttpGet]
  78. public MachineToPM GetSingle(int id)
  79. {
  80. using (IDatabase db = DbFactory.Base("eapslave"))
  81. {
  82. var dal = new MachineToPmDal(db);
  83. return dal.Get(id);
  84. }
  85. }
  86. }
  87. }