TpntStoreController.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. using Microsoft.AspNetCore.Mvc;
  2. using Microsoft.Extensions.Logging;
  3. using Ropin.Inspection.Api.Common;
  4. using Ropin.Inspection.Model;
  5. using Ropin.Inspection.Model.ViewModel;
  6. using Ropin.Inspection.Service;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Threading.Tasks;
  11. namespace Ropin.Inspection.Api.Controllers
  12. {
  13. public class TpntStoreController : BaseController
  14. {
  15. private readonly ILogger<TpntStoreController> _logger;
  16. private readonly ITpntStoreService _TpntStoreService;
  17. private readonly ITpntStoreOrgService _TpntStoreOrgService;
  18. /// <summary>
  19. /// 构造函数
  20. /// </summary>
  21. /// <param name="TpntStoreService"></param>
  22. /// <param name="TpntStoreOrgService"></param>
  23. /// <param name="logger"></param>
  24. public TpntStoreController(ITpntStoreService TpntStoreService, ITpntStoreOrgService TpntStoreOrgService, ILogger<TpntStoreController> logger)
  25. {
  26. _TpntStoreService = TpntStoreService;
  27. _TpntStoreOrgService = TpntStoreOrgService;
  28. _logger = logger;
  29. }
  30. /// <summary>
  31. /// 通过ID获取网点信息
  32. /// </summary>
  33. /// <param name="id"></param>
  34. /// <returns></returns>
  35. [HttpGet("GetStoreAsync/{id}")]
  36. public async Task<ApiResult> GetStoreAsync(Guid id)
  37. {
  38. if (Guid.Empty == id)
  39. {
  40. return new ApiResult(ReturnCode.GeneralError);
  41. }
  42. try
  43. {
  44. var content = await _TpntStoreService.GetByIdAsync(id);
  45. return new ApiResult<TpntStoreViewModel>(content);
  46. }
  47. catch (Exception ex)
  48. {
  49. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  50. }
  51. }
  52. /// <summary>
  53. /// 获取所有网点
  54. /// </summary>
  55. /// <returns></returns>
  56. [HttpGet("GetStoresAsync")]
  57. public async Task<ApiResult> GetStoresAsync()
  58. {
  59. try
  60. {
  61. var contentList = await _TpntStoreService.GetAllAsync();
  62. return new ApiResult<IEnumerable<TpntStoreViewModel>>(contentList);
  63. }
  64. catch (Exception ex)
  65. {
  66. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  67. }
  68. }
  69. /// <summary>
  70. /// 通过网点名称条件查询
  71. /// </summary>
  72. /// <param name="searchModel"></param>
  73. /// <returns></returns>
  74. [HttpPost("GetStoresByAsync")]
  75. public async Task<ApiResult> GetStoresByAsync(TpntStoreSearchModel searchModel)
  76. {
  77. if (searchModel == null)
  78. {
  79. return new ApiResult(ReturnCode.ArgsError);
  80. }
  81. searchModel.IsPagination = false;
  82. try
  83. {
  84. var contentList = await _TpntStoreService.GetConditionAsync(searchModel);
  85. return new ApiResult<IEnumerable<TpntStoreViewModel>>(contentList);
  86. }
  87. catch (Exception ex)
  88. {
  89. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  90. }
  91. }
  92. /// <summary>
  93. /// 创建网点
  94. /// </summary>
  95. /// <param name="content"></param>
  96. /// <returns></returns>
  97. [HttpPost("CreateStoreAsync")]
  98. public async Task<ApiResult> CreateStoreAsync(TpntStoreViewModel content)
  99. {
  100. if (content == null)
  101. {
  102. return new ApiResult(ReturnCode.ArgsError);
  103. }
  104. try
  105. {
  106. await _TpntStoreService.CreateOneAsync(content);
  107. }
  108. catch (Exception ex)
  109. {
  110. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  111. }
  112. return new ApiResult(ReturnCode.Success);
  113. }
  114. /// <summary>
  115. /// 创建组织架构下网点
  116. /// </summary>
  117. /// <param name="orgCode"></param>
  118. /// <param name="content"></param>
  119. /// <returns></returns>
  120. [HttpPost("CreateStoreByOrgAsync/{orgCode}")]
  121. public async Task<ApiResult> CreateStoreByOrgAsync(Guid orgCode, TpntStoreCreateModel content)
  122. {
  123. if (content == null ||Guid.Empty == orgCode)
  124. {
  125. return new ApiResult(ReturnCode.ArgsError);
  126. }
  127. try
  128. {
  129. await _TpntStoreService.CreateStoreByOrgAsync(orgCode,content);
  130. }
  131. catch (Exception ex)
  132. {
  133. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  134. }
  135. return new ApiResult(ReturnCode.Success);
  136. }
  137. /// <summary>
  138. /// 分配组织架构下网点
  139. /// </summary>
  140. /// <param name="orgCode"></param>
  141. /// <param name="storeCode"></param>
  142. /// <returns></returns>
  143. [HttpPost("AllotStoreByOrgAsync/{orgCode}/{storeCode}")]
  144. public async Task<ApiResult> AllotStoreByOrgAsync(Guid orgCode, Guid storeCode)
  145. {
  146. if (Guid.Empty == storeCode || Guid.Empty == orgCode)
  147. {
  148. return new ApiResult(ReturnCode.ArgsError);
  149. }
  150. try
  151. {
  152. await _TpntStoreService.AllotStoreByOrgAsync(orgCode, storeCode);
  153. }
  154. catch (Exception ex)
  155. {
  156. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  157. }
  158. return new ApiResult(ReturnCode.Success);
  159. }
  160. /// <summary>
  161. /// 删除网点
  162. /// </summary>
  163. /// <param name="id"></param>
  164. /// <returns></returns>
  165. [HttpDelete("DeleteStoreAsync/{id}")]
  166. public async Task<ApiResult> DeleteStoreAsync(Guid id)
  167. {
  168. if (Guid.Empty == id)
  169. {
  170. return new ApiResult(ReturnCode.GeneralError);
  171. }
  172. try
  173. {
  174. await _TpntStoreService.DeleteAsync(id);
  175. }
  176. catch (Exception ex)
  177. {
  178. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  179. }
  180. return new ApiResult(ReturnCode.Success);
  181. }
  182. /// <summary>
  183. /// 更新网点
  184. /// </summary>
  185. /// <param name="id"></param>
  186. /// <param name="updateModel"></param>
  187. /// <returns></returns>
  188. [HttpPut("UpdateStoreAsync/{id}")]
  189. public async Task<ApiResult> UpdateStoreAsync(Guid id, TpntStoreUpdateModel updateModel)
  190. {
  191. if (Guid.Empty == id)
  192. {
  193. return new ApiResult(ReturnCode.GeneralError);
  194. }
  195. try
  196. {
  197. await _TpntStoreService.UpdateAsync(id, updateModel);
  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="orgCode"></param>
  209. /// <param name="storeCodes"></param>
  210. /// <returns></returns>
  211. [HttpPost("CreateOrgStoresAsync/{orgCode}")]
  212. public async Task<ApiResult> CreateOrgStoresAsync(Guid orgCode, IEnumerable<string> storeCodes)
  213. {
  214. if (Guid.Empty.Equals(orgCode) || storeCodes == null || !storeCodes.Any())
  215. {
  216. return new ApiResult(ReturnCode.ArgsError);
  217. }
  218. try
  219. {
  220. await _TpntStoreOrgService.CreateOrgStoresAsync(orgCode, storeCodes);
  221. }
  222. catch (Exception ex)
  223. {
  224. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  225. }
  226. return new ApiResult(ReturnCode.Success);
  227. }
  228. /// <summary>
  229. /// 创建组织架构下网点
  230. /// </summary>
  231. /// <param name="mode"></param>
  232. /// <returns></returns>
  233. [HttpPost("CreateStoreOrgAsync")]
  234. public async Task<ApiResult> CreateStoreOrgAsync(TpntStoreOrgViewModel mode)
  235. {
  236. if (mode == null || Guid.Empty.Equals(mode.C_OrgCode) || string.Empty.Equals(mode.C_StoreCode))
  237. {
  238. return new ApiResult(ReturnCode.ArgsError);
  239. }
  240. try
  241. {
  242. TpntStoreSearchModel searchModel = new TpntStoreSearchModel();
  243. searchModel.orgCode = mode.C_OrgCode;
  244. IEnumerable<TpntStoreViewModel> stores = await _TpntStoreOrgService.GetStoresByOrgCodeAsync(searchModel);
  245. List<TpntStoreViewModel> listStores = stores.ToList();
  246. if (listStores[0] != null && listStores.FirstOrDefault(i => i.C_Code == mode.C_StoreCode) != null)
  247. return new ApiResult(ReturnCode.GeneralError, "此组织架构下已有此网点");
  248. await _TpntStoreOrgService.CreateOneAsync(mode);
  249. }
  250. catch (Exception ex)
  251. {
  252. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  253. }
  254. return new ApiResult(ReturnCode.Success);
  255. }
  256. /// <summary>
  257. /// 删除组织架构下网点
  258. /// </summary>
  259. /// <param name="orgCode"></param>
  260. /// <param name="storeCode"></param>
  261. /// <returns></returns>
  262. [HttpDelete("DeleteByOrgStoreCodeAsync/{orgCode}/{storeCode}")]
  263. public async Task<ApiResult> DeleteByOrgStoreCodeAsync(Guid orgCode,string storeCode)
  264. {
  265. if (Guid.Empty.Equals(orgCode)|| string.IsNullOrEmpty(storeCode))
  266. {
  267. return new ApiResult(ReturnCode.GeneralError);
  268. }
  269. try
  270. {
  271. await _TpntStoreOrgService.DeleteByOrgStoreCodeAsync(orgCode, storeCode);
  272. }
  273. catch (Exception ex)
  274. {
  275. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  276. }
  277. return new ApiResult(ReturnCode.Success);
  278. }
  279. /// <summary>
  280. /// 通过网点Code获取关联的组织架构
  281. /// </summary>
  282. /// <param name="storeCode"></param>
  283. /// <returns></returns>
  284. [HttpGet("GetOrgsByStoreCodeAsync/{storeCode}")]
  285. public async Task<ApiResult> GetOrgsByStoreCodeAsync(string storeCode)
  286. {
  287. if (string.IsNullOrEmpty(storeCode))
  288. {
  289. return new ApiResult(ReturnCode.GeneralError);
  290. }
  291. try
  292. {
  293. var contentList = await _TpntStoreOrgService.GetOrgsByStoreCodeAsync(storeCode);
  294. return new ApiResult<IEnumerable<TsysOrganizeViewModel>>(contentList);
  295. }
  296. catch (Exception ex)
  297. {
  298. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  299. }
  300. }
  301. /// <summary>
  302. /// 通过点击组织机构树查看下面的网点
  303. /// </summary>
  304. /// <param name="orgCode"></param>
  305. /// <returns></returns>
  306. [HttpGet("GetStoresByOrgCodeAsync/{orgCode}")]
  307. public async Task<ApiResult> GetStoresByOrgCodeAsync(Guid orgCode)
  308. {
  309. if (Guid.Empty == orgCode)
  310. {
  311. return new ApiResult(ReturnCode.GeneralError);
  312. }
  313. try
  314. {
  315. TpntStoreSearchModel searchModel = new TpntStoreSearchModel();
  316. searchModel.orgCode = orgCode;
  317. var contentList = await _TpntStoreOrgService.GetStoresByOrgCodeAsync(searchModel);
  318. return new ApiResult<IEnumerable<TpntStoreViewModel>>(contentList);
  319. }
  320. catch (Exception ex)
  321. {
  322. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  323. }
  324. }
  325. /// <summary>
  326. /// 通过点击组织机构树查看下面的网点
  327. /// </summary>
  328. /// <returns></returns>
  329. [HttpPost("GetStoresByOrgCodeNameAsync")]
  330. public async Task<ApiResult> GetStoresByOrgCodeNameAsync(TpntStoreSearchModel searchModel)
  331. {
  332. if (searchModel==null||Guid.Empty == searchModel.orgCode)
  333. {
  334. return new ApiResult(ReturnCode.GeneralError);
  335. }
  336. try
  337. {
  338. var contentList = await _TpntStoreOrgService.GetStoresByOrgCodeAsync(searchModel);
  339. return new ApiResult<IEnumerable<TpntStoreViewModel>>(contentList);
  340. }
  341. catch (Exception ex)
  342. {
  343. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  344. }
  345. }
  346. /// <summary>
  347. /// 通过组织架构Code获取关联的网点,管理公司可以查看所有
  348. /// </summary>
  349. /// <param name="orgCode"></param>
  350. /// <returns></returns>
  351. [HttpGet("GetStoresOnlyByOrgCodeAsync/{orgCode}")]
  352. public async Task<ApiResult> GetStoresOnlyByOrgCodeAsync(Guid orgCode)
  353. {
  354. if (Guid.Empty == orgCode)
  355. {
  356. return new ApiResult(ReturnCode.GeneralError);
  357. }
  358. try
  359. {
  360. var contentList = await _TpntStoreOrgService.GetStoresOnlyByOrgCodeAsync(orgCode);
  361. return new ApiResult<IEnumerable<TpntStoreViewModel>>(contentList);
  362. }
  363. catch (Exception ex)
  364. {
  365. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  366. }
  367. }
  368. /// <summary>
  369. /// 获取所有的PNT类型
  370. /// </summary>
  371. /// <returns></returns>
  372. [HttpGet("GetAllPntType")]
  373. public async Task<ApiResult> GetAllPntType()
  374. {
  375. try
  376. {
  377. var contentList = await _TpntStoreService.GetAllPntType();
  378. return new ApiResult<IList<TpntTypeViewModel>>(contentList);
  379. }
  380. catch (Exception ex)
  381. {
  382. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  383. }
  384. }
  385. /// <summary>
  386. /// 通过网点code获取网点信息
  387. /// </summary>
  388. /// <param name="code"></param>
  389. /// <returns></returns>
  390. [HttpGet("GetStoreByCodeAsync/{code}")]
  391. public async Task<ApiResult> GetStoreByCodeAsync(string code)
  392. {
  393. if (string.IsNullOrEmpty(code))
  394. {
  395. return new ApiResult(ReturnCode.GeneralError);
  396. }
  397. try
  398. {
  399. var content = await _TpntStoreService.GetStoreByCodeAsync(code);
  400. return new ApiResult<TpntStoreViewModel>(content);
  401. }
  402. catch (Exception ex)
  403. {
  404. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  405. }
  406. }
  407. }
  408. }