DeviceMgtController.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. using Ant.Data;
  2. using Ant.ORM;
  3. using Ant.SuperSocket.Common;
  4. using Ant.Service.Common;
  5. using Ant.Service.Common.Enums;
  6. using MES.Production.Entity;
  7. using MES.Production.Entity.Entity;
  8. using MES.Production.Entity.Enum;
  9. using MES.Production.Entity.Extensions;
  10. using MES.Production.Entity.ResponseMod.DeviceMgt;
  11. using Ant.Service.Mongodb;
  12. using ChangFa.Machinery.WebPage.Controllers;
  13. using MongoDB.Driver.Builders;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Data;
  17. using System.Linq;
  18. using System.Text;
  19. using System.Web;
  20. using System.Web.Mvc;
  21. using JsonHelper = Ant.Service.Common.JsonHelper;
  22. namespace ChangFa.Machinery.WebPage.Areas.SysManage.Controllers
  23. {
  24. public class DeviceMgtController : BaseController
  25. {
  26. /// <summary>
  27. /// 设备列表
  28. /// </summary>
  29. /// <returns></returns>
  30. ///
  31. [UserAuthorize(ModuleAlias = "DeviceMgtInfo", OperaAction = "View")]
  32. public ActionResult Index()
  33. {
  34. try
  35. {
  36. #region 加载列表
  37. using (Ant.ORM.AntORM orm = new Ant.ORM.AntORM())
  38. {
  39. orm.db = Ant.Data.DataAccessFactory.CreateDataConnection("CyclingItem");
  40. Ant.ORM.RequestModel request = new Ant.ORM.RequestModel();
  41. request.newSt = new Ant.ORM.SqlNote() { Author = "smj", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "DeviceMgtController-Index" };
  42. var query = orm.Queryable<SYS_Device>().Where(p => p.IsDelete == 0);
  43. // 检索条件
  44. query = query.WhereIf(!string.IsNullOrEmpty(keywords), p => p.Name.Contains(keywords));
  45. // 分页查询
  46. var skipLimit = PageCollection.GetSkipLimit(base.page, base.pagesize);
  47. // 具体查询
  48. var list = query.OrderByDesc(o => o.ModifyDT).Skip(skipLimit.Item1).Top(skipLimit.Item2).ToList(request);
  49. // 查出总数
  50. var total = query.Count();
  51. List<SYS_Device> devices = list.ResultModel;
  52. var result = devices?.Select(device => new DeviceMgtIndexDto()
  53. {
  54. Id = device.Id,
  55. Name = device.Name,
  56. Code = device.Code,
  57. Address = device.Address
  58. }).ToList();
  59. #region 查询出设备的部品和打包盒信息
  60. var deviceIds = devices?.Select(p => p.Id).ToList();
  61. if (deviceIds?.Count() > 0)
  62. {
  63. // 查询设备打包盒信息
  64. var devicePacking = orm.Queryable<YW_DevicePacking>().Where(p => deviceIds.Contains(p.DeviceId));
  65. var packing = orm.Queryable<YW_Packing>();
  66. //连表查询
  67. var ss1 = devicePacking.InnerJoin(packing, (dp, p) => dp.PackingId == p.Id).Select((dp, p) => new DeviceMgtIndexDto
  68. {
  69. Id = dp.DeviceId,
  70. DevicePackingId = dp.Id,
  71. PackingId = p.Id,
  72. PackingName = p.Name,
  73. PackingCapacity = dp.Capacity,
  74. PackingStock = dp.Stock
  75. }).ToList(request);
  76. List<DeviceMgtIndexDto> pcakings = ss1?.ResultModel;
  77. // 查询设备商品信息
  78. var deviceProduct = orm.Queryable<YW_DeviceProduct>().Where(p => deviceIds.Contains(p.DeviceId));
  79. var product = orm.Queryable<YW_Product>();
  80. //连表查询
  81. List<DeviceMgtIndexDto> products = deviceProduct.InnerJoin(product, (dp, p) => dp.ProductId == p.Id).Select((dp, p) => new DeviceMgtIndexDto
  82. {
  83. Id = dp.DeviceId,
  84. DeviceProductId = dp.Id,
  85. ProductId = p.Id,
  86. ProductName = p.Name,
  87. ProductPrice = dp.Price,
  88. ProductStock = dp.Stock
  89. }).ToList(request)?.ResultModel;
  90. result?.ForEach(item =>
  91. {
  92. var currentPacking = pcakings?.FirstOrDefault(p => p.Id == item.Id);
  93. if (currentPacking != null)
  94. {
  95. item.DevicePackingId = currentPacking.DevicePackingId;
  96. item.PackingId = currentPacking.PackingId;
  97. item.PackingName = currentPacking.PackingName;
  98. item.PackingCapacity = currentPacking.PackingCapacity;
  99. item.PackingStock = currentPacking.PackingStock;
  100. }
  101. var currentProduct = products?.FirstOrDefault(p => p.Id == item.Id);
  102. if (currentProduct != null)
  103. {
  104. item.DeviceProductId = currentProduct.DeviceProductId;
  105. item.ProductId = currentProduct.ProductId;
  106. item.ProductName = currentProduct.ProductName;
  107. item.ProductPrice = currentProduct.ProductPrice;
  108. item.ProductStock = currentProduct.ProductStock;
  109. }
  110. });
  111. }
  112. #endregion
  113. var resultDto = new PageInfo(base.page, base.pagesize, total, result);
  114. ViewBag.Search = base.keywords;
  115. return View(resultDto);
  116. }
  117. #endregion
  118. }
  119. catch (Exception e)
  120. {
  121. WriteLog(enumOperator.Select, "加载设备列表:", e);
  122. throw e.InnerException;
  123. }
  124. }
  125. // GET: SysManage/Device
  126. public ActionResult DeviceManage()
  127. {
  128. PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List<DeviceManage>()));
  129. using (AntORM orm = new AntORM())
  130. {
  131. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  132. RequestModel res = new RequestModel();
  133. res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
  134. int pageno = (page - 1) * pagesize;
  135. var q = orm.Queryable<DeviceManage>();
  136. if (!keywords.IsEmpty())
  137. {
  138. q = q.Where(p => p.IMEI.Contains(keywords));
  139. }
  140. var result = q.OrderByDesc(p => p.LastOnlineTime).Skip(pageno).Top(pagesize).ToList(res);
  141. if (result.IsSuccess)
  142. {
  143. result.RecordNum = q.Count();
  144. }
  145. else
  146. {
  147. result = new ResponseModel();
  148. result.RecordNum = 0;
  149. result.ResultModel = new List<DeviceManage>();
  150. }
  151. pageInfo = new PageInfo(base.page, base.pagesize, result.RecordNum, JsonConverter.JsonClass(result.ResultModel));
  152. }
  153. ViewBag.Search = base.keywords;
  154. return View(pageInfo);
  155. }
  156. }
  157. }