TdevBoxController.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.Extensions.Logging;
  4. using Ropin.Inspection.Api.Common;
  5. using Ropin.Inspection.Api.Controllers;
  6. using Ropin.Inspection.Model;
  7. using Ropin.Inspection.Service;
  8. using Ropin.Inspection.Service.Interface;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Threading.Tasks;
  13. namespace Ropin.Inspection.Api
  14. {
  15. public class TdevBoxController : BaseController
  16. {
  17. public ILogger<TdevBoxController> _logger { get; }
  18. private readonly ITdevBoxService _TdevBoxService;
  19. private readonly ITdevBoxDevSpotService _TdevBoxDevSpotService;
  20. /// <summary>
  21. /// 构造函数
  22. /// </summary>
  23. /// <param name="TdevBoxService"></param>
  24. /// <param name="logger"></param>
  25. public TdevBoxController(ITdevBoxService TdevBoxService, ILogger<TdevBoxController> logger, ITdevBoxDevSpotService TdevBoxDevSpotService)
  26. {
  27. _TdevBoxService = TdevBoxService;
  28. _logger = logger;
  29. _TdevBoxDevSpotService = TdevBoxDevSpotService;
  30. }
  31. /// <summary>
  32. /// 创建业主盒子信息
  33. /// </summary>
  34. /// <param name="content"></param>
  35. /// <returns></returns>
  36. [HttpPost("CreateBoxAsync")]
  37. public async Task<ApiResult> CreateBoxAsync(TdevBoxViewModel content)
  38. {
  39. if (content == null)
  40. {
  41. return new ApiResult(ReturnCode.ArgsError);
  42. }
  43. try
  44. {
  45. await _TdevBoxService.CreateOneAsync(content);
  46. }
  47. catch (Exception ex)
  48. {
  49. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  50. }
  51. return new ApiResult(ReturnCode.Success);
  52. }
  53. /// <summary>
  54. /// 删除业主盒子信息
  55. /// </summary>
  56. /// <param name="id"></param>
  57. /// <returns></returns>
  58. [HttpDelete("DeleteBoxAsync/{id}")]
  59. public async Task<ApiResult> DeleteBoxAsync(string id)
  60. {
  61. if (string.IsNullOrEmpty(id))
  62. {
  63. return new ApiResult(ReturnCode.GeneralError);
  64. }
  65. try
  66. {
  67. await _TdevBoxService.DeleteAsync(id);
  68. }
  69. catch (Exception ex)
  70. {
  71. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  72. }
  73. return new ApiResult(ReturnCode.Success);
  74. }
  75. /// <summary>
  76. /// 更新业主盒子信息
  77. /// </summary>
  78. /// <param name="id"></param>
  79. /// <param name="updateModel"></param>
  80. /// <returns></returns>
  81. [HttpPut("UpdateBoxAsync/{id}")]
  82. [AllowAnonymous]
  83. public async Task<ApiResult> UpdateBoxAsync(string id, TdevBoxUpdateModel updateModel)
  84. {
  85. if (string.IsNullOrEmpty(id))
  86. {
  87. return new ApiResult(ReturnCode.GeneralError);
  88. }
  89. try
  90. {
  91. await _TdevBoxService.UpdateAsync(id, updateModel);
  92. }
  93. catch (Exception ex)
  94. {
  95. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  96. }
  97. return new ApiResult(ReturnCode.Success);
  98. }
  99. /// <summary>
  100. /// 取业主盒子信息
  101. /// </summary>
  102. /// <returns></returns>
  103. [HttpPost("GetDevStoreDocAsync")]
  104. [AllowAnonymous]
  105. public async Task<ApiResult> GetDevStoreDocAsync(TdevBoxSearchModel searchModel)
  106. {
  107. if (searchModel == null)
  108. {
  109. return new ApiResult(ReturnCode.ArgsError);
  110. }
  111. try
  112. {
  113. var contentList = await _TdevBoxService.GetConditionAsync(searchModel);
  114. return new ApiResult<PagesModel<TdevBoxViewModel>>(new PagesModel<TdevBoxViewModel>(contentList, searchModel));
  115. }
  116. catch (Exception ex)
  117. {
  118. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  119. }
  120. }
  121. /// <summary>
  122. /// 通过id获取业主盒子信息
  123. /// </summary>
  124. /// <returns></returns>
  125. [HttpPost("GetDevStoreDocByIDAsync")]
  126. [AllowAnonymous]
  127. public async Task<ApiResult> GetDevStoreDocByIDAsync(TdevBoxSearchModel searchModel)
  128. {
  129. if (searchModel == null)
  130. {
  131. return new ApiResult(ReturnCode.ArgsError);
  132. }
  133. try
  134. {
  135. var content = await _TdevBoxService.GetConditionByIdAsync(searchModel.C_ID);
  136. TdevBoxDevSpotSearchModel tdev = new TdevBoxDevSpotSearchModel();
  137. tdev.C_BoxCode = searchModel.C_ID;
  138. var contentList = await _TdevBoxDevSpotService.GetConditionAsync(tdev);
  139. TdevBoxViewSpotModel data = new TdevBoxViewSpotModel();
  140. data.entity = content;
  141. data.tdevBoxes = contentList.ToList();
  142. return new ApiResult<TdevBoxViewSpotModel>(data);
  143. }
  144. catch (Exception ex)
  145. {
  146. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  147. }
  148. }
  149. /// <summary>
  150. /// 拷贝业主盒子信息
  151. /// </summary>
  152. /// <param name="id"></param>
  153. /// <returns></returns>
  154. [HttpGet("CopyBoxStoreInfo")]
  155. [AllowAnonymous]
  156. public async Task<ApiResult> CopyBoxStoreInfo(string id)
  157. {
  158. if (string.IsNullOrEmpty(id))
  159. {
  160. return new ApiResult(ReturnCode.GeneralError);
  161. }
  162. try
  163. {
  164. await _TdevBoxService.CopyCreateAsync(id);
  165. return new ApiResult(ReturnCode.Success);
  166. }
  167. catch (Exception ex)
  168. {
  169. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  170. }
  171. }
  172. /// <summary>
  173. /// 通过
  174. /// </summary>
  175. /// <param name="id"></param>
  176. /// <returns></returns>
  177. //[HttpGet("GetDevStoreDocByCodeAsync/{id}")]
  178. //[AllowAnonymous]
  179. //public async Task<ApiResult> GetDevStoreDocByCodeAsync(string id)
  180. //{
  181. // if (string.IsNullOrEmpty(id))
  182. // {
  183. // return new ApiResult(ReturnCode.GeneralError);
  184. // }
  185. // try
  186. // {
  187. // var content = await _TdevBoxService.GetConditionAsync(new TdevBoxSearchModel { C_StoreCode = id });
  188. // var dev = content.ToList();
  189. // return new ApiResult<IEnumerable<TdevBoxViewModel>>(new List<TdevBoxViewModel>(dev));
  190. // }
  191. // catch (Exception ex)
  192. // {
  193. // return new ApiResult(ReturnCode.GeneralError, ex.Message);
  194. // }
  195. //}
  196. }
  197. }