TbdmCodeController.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.Extensions.Logging;
  4. using Newtonsoft.Json;
  5. using NPOI.SS.Formula.Functions;
  6. using Ropin.Inspection.Api.Common;
  7. using Ropin.Inspection.Model;
  8. using Ropin.Inspection.Model.ViewModel.MTN;
  9. using Ropin.Inspection.Service;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Threading.Tasks;
  14. namespace Ropin.Inspection.Api.Controllers
  15. {
  16. public class TbdmCodeController : BaseController
  17. {
  18. public readonly ILogger<TbdmCodeController> _logger;
  19. private readonly ITbdmCodeService _TbdmCodeService;
  20. /// <summary>
  21. /// 构造函数
  22. /// </summary>
  23. /// <param name="TbdmCodeService"></param>
  24. /// <param name="logger"></param>
  25. public TbdmCodeController(ITbdmCodeService TbdmCodeService, ILogger<TbdmCodeController> logger)
  26. {
  27. _TbdmCodeService = TbdmCodeService;
  28. _logger = logger;
  29. }
  30. /// <summary>
  31. /// 获取公用代码树
  32. /// </summary>
  33. /// <returns></returns>
  34. [HttpGet("GetCodeListTreeAsync")]
  35. [AllowAnonymous]
  36. public async Task<ApiResult> GetCodeListTreeAsync()
  37. {
  38. try
  39. {
  40. var content = await _TbdmCodeService.GetCodeListTreeAsync();
  41. return new ApiResult<List<TbdmCodeViewModel>>(content);
  42. }
  43. catch (Exception ex)
  44. {
  45. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  46. }
  47. }
  48. /// <summary>
  49. /// 条件查询获取基础数据-子表-不分页
  50. /// </summary>
  51. /// <param name="searchModel"></param>
  52. /// <returns></returns>
  53. [HttpPost("GetDetailCodeListByAsync")]
  54. public async Task<ApiResult> GetDetailCodeListByAsync(TbdmCodeSearchModel searchModel)
  55. {
  56. if (searchModel == null)
  57. {
  58. return new ApiResult(ReturnCode.ArgsError);
  59. }
  60. searchModel.IsPagination = false;
  61. try
  62. {
  63. var contentList = await _TbdmCodeService.GetConditionDetailAsync(searchModel);
  64. return new ApiResult<IEnumerable<TbdmDetailCode>>(contentList);
  65. }
  66. catch (Exception ex)
  67. {
  68. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  69. }
  70. }
  71. /// <summary>
  72. /// 条件查询获取基础数据-子表-分页
  73. /// </summary>
  74. /// <param name="searchModel"></param>
  75. /// <returns></returns>
  76. [HttpPost("GetDetailCodePageByAsync")]
  77. public async Task<ApiResult> GetDetailCodePageByAsync(TbdmCodeSearchModel searchModel)
  78. {
  79. if (searchModel == null)
  80. {
  81. return new ApiResult(ReturnCode.ArgsError);
  82. }
  83. try
  84. {
  85. var contentList = await _TbdmCodeService.GetConditionDetailAsync(searchModel);
  86. var datas = new PagesModel<TbdmDetailCode>(contentList, searchModel);
  87. return new ApiResult<PagesModel<TbdmDetailCode>>(datas);
  88. }
  89. catch (Exception ex)
  90. {
  91. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  92. }
  93. }
  94. /// <summary>
  95. /// 条件查询获取基础数据-主表-分页
  96. /// </summary>
  97. /// <param name="searchModel"></param>
  98. /// <returns></returns>
  99. [HttpPost("GetCodeListByAsync")]
  100. public async Task<ApiResult> GetCodeListByAsync(TbdmCodeSearchModel searchModel)
  101. {
  102. if (searchModel == null)
  103. {
  104. return new ApiResult(ReturnCode.ArgsError);
  105. }
  106. try
  107. {
  108. var contentList = await _TbdmCodeService.GetConditionAsync(searchModel);
  109. var datas = new PagesModel<TbdmCodeViewModel>(contentList, searchModel);
  110. return new ApiResult<PagesModel<TbdmCodeViewModel>>(datas);
  111. }
  112. catch (Exception ex)
  113. {
  114. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  115. }
  116. }
  117. /// <summary>
  118. /// 创建-主表
  119. /// </summary>
  120. /// <param name="content"></param>
  121. /// <returns></returns>
  122. [HttpPost("CreateAsync")]
  123. public async Task<ApiResult> CreateAsync(TbdmCodeViewModel content)
  124. {
  125. if (content == null)
  126. {
  127. return new ApiResult(ReturnCode.ArgsError);
  128. }
  129. try
  130. {
  131. await _TbdmCodeService.CreateOneAsync(content);
  132. }
  133. catch (Exception ex)
  134. {
  135. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  136. }
  137. return new ApiResult(ReturnCode.Success);
  138. }
  139. /// <summary>
  140. /// 创建-子表
  141. /// </summary>
  142. /// <param name="content"></param>
  143. /// <returns></returns>
  144. [HttpPost("CreateDetailAsync")]
  145. public async Task<ApiResult> CreateDetailAsync(TbdmCodeDetailCreateModel content)
  146. {
  147. if (content == null)
  148. {
  149. return new ApiResult(ReturnCode.ArgsError);
  150. }
  151. try
  152. {
  153. await _TbdmCodeService.CreateDetailAsync(content);
  154. }
  155. catch (Exception ex)
  156. {
  157. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  158. }
  159. return new ApiResult(ReturnCode.Success);
  160. }
  161. /// <summary>
  162. /// 删除-主表、子表
  163. /// </summary>
  164. /// <param name="id"></param>
  165. /// <returns></returns>
  166. [HttpDelete("DeleteAsync/{id}")]
  167. public async Task<ApiResult> DeleteAsync(string id)
  168. {
  169. if (string.IsNullOrEmpty(id))
  170. {
  171. return new ApiResult(ReturnCode.GeneralError);
  172. }
  173. try
  174. {
  175. await _TbdmCodeService.DeleteAsync(id);
  176. }
  177. catch (Exception ex)
  178. {
  179. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  180. }
  181. return new ApiResult(ReturnCode.Success);
  182. }
  183. /// <summary>
  184. /// 删除-子表
  185. /// </summary>
  186. /// <param name="id"></param>
  187. /// <returns></returns>
  188. [HttpDelete("DeleteDetailAsync/{id}")]
  189. public async Task<ApiResult> DeleteDetailAsync(string id)
  190. {
  191. if (string.IsNullOrEmpty(id))
  192. {
  193. return new ApiResult(ReturnCode.GeneralError);
  194. }
  195. try
  196. {
  197. await _TbdmCodeService.DeleteDetailAsync(id);
  198. }
  199. catch (Exception ex)
  200. {
  201. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  202. }
  203. return new ApiResult(ReturnCode.Success);
  204. }
  205. /// <summary>
  206. /// 禁用-主表、子表
  207. /// </summary>
  208. /// <param name="id"></param>
  209. /// <returns></returns>
  210. [HttpPut("DisabledStatusAsync/{id}")]
  211. public async Task<ApiResult> DisabledStatusAsync(string id)
  212. {
  213. if (string.IsNullOrEmpty(id))
  214. {
  215. return new ApiResult(ReturnCode.GeneralError);
  216. }
  217. try
  218. {
  219. await _TbdmCodeService.DisabledStatusAsync(id);
  220. }
  221. catch (Exception ex)
  222. {
  223. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  224. }
  225. return new ApiResult(ReturnCode.Success);
  226. }
  227. /// <summary>
  228. /// 禁用-子表
  229. /// </summary>
  230. /// <param name="id"></param>
  231. /// <returns></returns>
  232. [HttpPut("DisabledDetailStatusAsync/{id}")]
  233. public async Task<ApiResult> DisabledDetailStatusAsync(string id)
  234. {
  235. if (string.IsNullOrEmpty(id))
  236. {
  237. return new ApiResult(ReturnCode.GeneralError);
  238. }
  239. try
  240. {
  241. await _TbdmCodeService.DisabledDetailStatusAsync(id);
  242. }
  243. catch (Exception ex)
  244. {
  245. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  246. }
  247. return new ApiResult(ReturnCode.Success);
  248. }
  249. /// <summary>
  250. /// 更新-主表
  251. /// </summary>
  252. /// <param name="id"></param>
  253. /// <param name="updateModel"></param>
  254. /// <returns></returns>
  255. [HttpPut("UpdateAsync/{id}")]
  256. public async Task<ApiResult> UpdateAsync(string id, TbdmCodeViewModel updateModel)
  257. {
  258. if (string.IsNullOrEmpty(id))
  259. {
  260. return new ApiResult(ReturnCode.GeneralError);
  261. }
  262. try
  263. {
  264. await _TbdmCodeService.UpdateAsync(id, updateModel);
  265. }
  266. catch (Exception ex)
  267. {
  268. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  269. }
  270. return new ApiResult(ReturnCode.Success);
  271. }
  272. /// <summary>
  273. /// 更新-子表
  274. /// </summary>
  275. /// <param name="id"></param>
  276. /// <param name="updateModel"></param>
  277. /// <returns></returns>
  278. [HttpPut("UpdateDetailAsync/{id}")]
  279. public async Task<ApiResult> UpdateDetailAsync(string id, TbdmCodeDetailUpdateModel updateModel)
  280. {
  281. if (string.IsNullOrEmpty(id))
  282. {
  283. return new ApiResult(ReturnCode.GeneralError);
  284. }
  285. try
  286. {
  287. await _TbdmCodeService.UpdateDetailAsync(id, updateModel);
  288. }
  289. catch (Exception ex)
  290. {
  291. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  292. }
  293. return new ApiResult(ReturnCode.Success);
  294. }
  295. }
  296. }