BoxApiService.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using AutoMapper;
  2. using Ropin.Inspection.Common.Accessor.Interface;
  3. using Ropin.Inspection.Common.Helper;
  4. using Ropin.Inspection.Model.Entities;
  5. using Ropin.Inspection.Model.SearchModel.PRD;
  6. using Ropin.Inspection.Model.ViewModel.PRD;
  7. using Ropin.Inspection.Repository.PRD.Interface;
  8. using Ropin.Inspection.Service.PRD.Interface;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Net.Http;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. namespace Ropin.Inspection.Service.PRD
  16. {
  17. public class BoxApiService: IBoxApiService
  18. {
  19. private readonly IBoxApiRepository _repository;
  20. private readonly IMapper _mapper;
  21. private readonly IHttpClientFactory _httpClientFactory;
  22. public BoxApiService(IBoxApiRepository repository, IMapper mapper,IHttpClientFactory httpClientFactory)
  23. {
  24. _repository = repository;
  25. _mapper = mapper;
  26. _httpClientFactory = httpClientFactory;
  27. }
  28. public async Task<PrivModel> GetUserPriv(string openId,string deviceCode)
  29. {
  30. var content = await _repository.GetUserPriv(openId, deviceCode);
  31. return content;
  32. }
  33. public async Task<bool> AddDevData(string C_DeviceCode, string C_ConfigCode, string C_Value)
  34. {
  35. TDEV_DevData devData = new TDEV_DevData();
  36. devData.C_DeviceCode = C_DeviceCode;
  37. devData.C_ConfigCode = C_ConfigCode;
  38. devData.C_Value = C_Value;
  39. devData.D_CreateOn = DateTime.Now;
  40. var content = await _repository.AddDevData(devData);
  41. return content;
  42. }
  43. public async Task<bool> AddDevAlert(string C_DeviceCode, string C_ConfigCode, string C_Value)
  44. {
  45. TDEV_DevAlert devAlert = new TDEV_DevAlert();
  46. devAlert.C_ID = Guid.NewGuid();
  47. devAlert.C_DeviceCode = C_DeviceCode;
  48. devAlert.C_ConfigCode = C_ConfigCode;
  49. devAlert.C_Value = C_Value;
  50. devAlert.D_CreateOn = DateTime.Now;
  51. var content = await _repository.AddDevAlert(devAlert);
  52. if (content)
  53. {
  54. //报警通知 推送小程序
  55. List<TSYS_User> users = await _repository.GetAllUser();
  56. List<string> openIds = users.Where(u => u.C_WechatID != null).Select(i => i.C_WechatID).ToList();
  57. TDEV_DevAlertConfig devAlertConfig = await _repository.GetDevAlertConfig(C_ConfigCode);
  58. var contentInfo = new
  59. {
  60. thing2 = new { value = "15366278195" ?? "" },
  61. time4 = new { value = DateTime.Now.ToString("yyyy-MM-dd hh:mm") },
  62. thing5 = new { value = "注意" ?? "" },
  63. thing6 = new { value = C_DeviceCode ?? "" },
  64. thing9 = new { value = devAlertConfig.C_Name ?? "" }
  65. };
  66. new WeChatHelper(_httpClientFactory).PushMessageToUser(openIds, contentInfo);
  67. }
  68. return content;
  69. }
  70. public async Task<TDEV_Device> GetDeviceInfo(string C_MachineCode)
  71. {
  72. var content = await _repository.GetDeviceInfo(C_MachineCode);
  73. return content;
  74. }
  75. public async Task<List<TDEV_Device>> GetAllDeviceInfo()
  76. {
  77. var content = await _repository.GetAllDeviceInfo();
  78. return content;
  79. }
  80. public async Task<List<ProductModel>> GetProductInfo(List<epcModel> models)
  81. {
  82. var content = await _repository.GetProductInfo(models);
  83. return content;
  84. }
  85. public async Task<List<ProductModel>> GetDevProductInfo(string c_DeviceCode)
  86. {
  87. var content = await _repository.GetDevProductInfo(c_DeviceCode);
  88. return content;
  89. }
  90. public async Task<bool> UpOffRackProduct(ProductInfoModel model)
  91. {
  92. var content = await _repository.UpOffRackProduct(model);
  93. return content;
  94. }
  95. public async Task<UserModel> GetUserInfo(string openid)
  96. {
  97. var content = await _repository.GetUserInfo(openid);
  98. return content;
  99. }
  100. }
  101. }