SupplierApplyController.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. using Microsoft.AspNetCore.Mvc;
  2. using Microsoft.Extensions.Caching.Memory;
  3. using Microsoft.Extensions.Configuration;
  4. using Newtonsoft.Json;
  5. using NLog;
  6. using Sugar.Enties;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Net.Http;
  12. using WebAPIBase.Utils;
  13. namespace WebAPIBase.API.Controllers
  14. {
  15. /// <summary>
  16. /// 供应商申请相关
  17. /// </summary>
  18. [Produces("application/json;charset=UTF-8")]
  19. [Route("api/SupplierApply")]
  20. [ServiceFilter(typeof(Filter.TokenAuthorize))]
  21. public class SupplierApplyController : Controller
  22. {
  23. private static Logger logger = NLog.LogManager.GetCurrentClassLogger();
  24. #region 供应商扩展信息
  25. /// <summary>
  26. /// 根据供应商编码获取供应商扩展信息
  27. /// </summary>
  28. /// <param name="supplierCode">供应商编号</param>
  29. /// <returns></returns>
  30. [HttpGet]
  31. [Route("GetzzSupplierExList")]
  32. public JsonResult GetzzSupplierExList(string supplierCode)
  33. {
  34. if (supplierCode.IsNullOrEmpty())
  35. {
  36. return Json("-1");
  37. }
  38. try
  39. {
  40. var service = new zzSupplierExManager();
  41. var list = service.GetzzSupplierExDTOList(supplierCode);
  42. return Json(list);
  43. }
  44. catch (Exception ex)
  45. {
  46. logger.Error(ex);
  47. return Json("-2");
  48. }
  49. }
  50. /// <summary>
  51. /// 根据项目获取供应商申请的信息
  52. /// </summary>
  53. /// <param name="projectCode"></param>
  54. /// <returns></returns>
  55. [HttpGet]
  56. [Route("GetzzSupplierExListByProject")]
  57. public JsonResult GetzzSupplierExListByProject(string projectCode)
  58. {
  59. if (projectCode.IsNullOrEmpty())
  60. {
  61. return Json("参数错误");
  62. }
  63. try
  64. {
  65. var service = new zzSupplierExManager();
  66. var list = service.GetzzSupplierExListByProject(projectCode);
  67. return Json(list);
  68. }
  69. catch (Exception ex)
  70. {
  71. logger.Error(ex);
  72. return Json(ex.Message + "\r\n" + ex.StackTrace);
  73. }
  74. }
  75. /// <summary>
  76. /// 获取供应商扩展实例信息
  77. /// </summary>
  78. /// <param name="id"></param>
  79. /// <returns></returns>
  80. [HttpGet]
  81. [Route("GetzzSupplierEx")]
  82. public JsonResult GetzzSupplierEx(int id)
  83. {
  84. if (id.IsNullOrEmpty())
  85. {
  86. return Json("参数错误");
  87. }
  88. try
  89. {
  90. var bll = new RequisitionManager();
  91. var service = new zzSupplierExManager();
  92. var entity = service.GetzzSupplierExDTO(id);
  93. var attachments = bll.GetAttachMents(id.ToString(), "zzSupplierExAttach");
  94. var data = new
  95. {
  96. entity = entity,
  97. attachments = attachments
  98. };
  99. return Json(data);
  100. }
  101. catch (Exception ex)
  102. {
  103. logger.Error(ex);
  104. return Json(ex.Message + "\r\n" + ex.StackTrace);
  105. }
  106. }
  107. /// <summary>
  108. /// 供应商扩展信息添加
  109. /// </summary>
  110. /// <param name="dto"></param>
  111. /// <returns></returns>
  112. [HttpPost]
  113. [Route("InsertzzSupplierEx")]
  114. public JsonResult InsertzzSupplierEx([FromBody] zzSupplierEx dto)
  115. {
  116. logger.Info($"【InsertzzSupplierEx】dto:{JsonConvert.SerializeObject(dto)}");
  117. if (dto.Title.IsNullOrEmpty())
  118. {
  119. return Json("标题不能为空");
  120. }
  121. if (dto.Title.Length > 200)
  122. {
  123. return Json("标题不能超过200字");
  124. }
  125. if (dto.Reason.IsNullOrEmpty())
  126. {
  127. return Json("原因不能为空");
  128. }
  129. if (dto.Reason.Length > 500)
  130. {
  131. return Json("原因不能超过500字");
  132. }
  133. try
  134. {
  135. dto.CheckDate = null;
  136. dto.CheckPerson = "";
  137. var service = new zzSupplierExManager();
  138. var id = service.Db.Insertable(dto).ExecuteReturnIdentity();
  139. if (id > 0)
  140. {
  141. return Json(id);
  142. }
  143. else
  144. {
  145. return Json("插入失败");
  146. }
  147. }
  148. catch (Exception ex)
  149. {
  150. logger.Error(ex);
  151. return Json(ex.Message);
  152. }
  153. }
  154. /// <summary>
  155. /// 更新供应商申请
  156. /// </summary>
  157. /// <param name="dto"></param>
  158. /// <returns></returns>
  159. [HttpPost]
  160. [Route("UpdatezzSupplierEx")]
  161. public JsonResult UpdatezzSupplierEx([FromBody] zzSupplierEx dto)
  162. {
  163. logger.Info($"【UpdatezzSupplierEx】dto:{JsonConvert.SerializeObject(dto)}");
  164. if (dto.ID.IsNullOrEmpty())
  165. {
  166. return Json("参数错误,不能审核");
  167. }
  168. if (dto.Title.IsNullOrEmpty())
  169. {
  170. return Json("标题不能为空");
  171. }
  172. if (dto.Title.Length > 200)
  173. {
  174. return Json("标题不能超过200字");
  175. }
  176. if (dto.Reason.IsNullOrEmpty())
  177. {
  178. return Json("原因不能为空");
  179. }
  180. if (dto.Reason.Length > 500)
  181. {
  182. return Json("原因不能超过500字");
  183. }
  184. try
  185. {
  186. var service = new zzSupplierExManager();
  187. dto.CheckDate = DateTime.Now;
  188. var row = service.Db.Updateable(dto).ExecuteCommand();
  189. if (row > 0)
  190. {
  191. return Json("success");
  192. }
  193. else
  194. {
  195. return Json("更新失败");
  196. }
  197. }
  198. catch (Exception ex)
  199. {
  200. logger.Error(ex);
  201. return Json(ex.Message + "\r\n" + ex.StackTrace);
  202. }
  203. }
  204. /// <summary>
  205. /// 管理员审核供应商提交的信息
  206. /// </summary>
  207. /// <param name="dto"></param>
  208. /// <returns></returns>
  209. [HttpPost]
  210. [Route("AuditzzSupplierEx")]
  211. public JsonResult AuditzzSupplierEx([FromBody] zzSupplierEx dto)
  212. {
  213. logger.Info($"【AuditzzSupplierEx】dto:{JsonConvert.SerializeObject(dto)}");
  214. if (dto.ID.IsNullOrEmpty()||dto.ProjectCode.IsNullOrEmpty())
  215. {
  216. return Json("参数错误或无权限,不能审核");
  217. }
  218. try
  219. {
  220. var service = new zzSupplierExManager();
  221. var model = service.GetById(dto.ID);
  222. if(model.ProjectCode!=dto.ProjectCode)
  223. {
  224. return Json("无权限操作");
  225. }
  226. if(model.State!=1)
  227. {
  228. return Json("非审核中状态,不能操作");
  229. }
  230. var success = service.AuditzzSupplierEx(dto);
  231. if (success)
  232. {
  233. return Json("success");
  234. }
  235. else
  236. {
  237. return Json("审核失败");
  238. }
  239. }
  240. catch (Exception ex)
  241. {
  242. logger.Error(ex);
  243. return Json(ex.Message + "\r\n" + ex.StackTrace);
  244. }
  245. }
  246. /// <summary>
  247. /// 提交供应商申请信息
  248. /// </summary>
  249. /// <param name="dto"></param>
  250. /// <returns></returns>
  251. [HttpPost]
  252. [Route("SubmitzzSupplierEx")]
  253. public JsonResult SubmitzzSupplierEx([FromBody] zzSupplierEx dto)
  254. {
  255. logger.Info($"【SubmitzzSupplierEx】dto:{JsonConvert.SerializeObject(dto)}");
  256. if (dto.ID.IsNullOrEmpty() || dto.SupplierCode.IsNullOrEmpty())
  257. {
  258. return Json("参数错误或无权限,不能审核");
  259. }
  260. try
  261. {
  262. var service = new zzSupplierExManager();
  263. var model = service.GetById(dto.ID);
  264. if (model.SupplierCode != dto.SupplierCode)
  265. {
  266. return Json("无权限操作");
  267. }
  268. if (model.State != 0)
  269. {
  270. return Json("非待审核状态,不能操作");
  271. }
  272. var success = service.SubmitzzSupplierEx(dto);
  273. if (success)
  274. {
  275. return Json("success");
  276. }
  277. else
  278. {
  279. return Json("提交失败");
  280. }
  281. }
  282. catch (Exception ex)
  283. {
  284. logger.Error(ex);
  285. return Json(ex.Message + "\r\n" + ex.StackTrace);
  286. }
  287. }
  288. /// <summary>
  289. /// 删除供应商扩展信息
  290. /// </summary>
  291. /// <param name="suppliercode"></param>
  292. /// <param name="id"></param>
  293. /// <returns></returns>
  294. [HttpGet]
  295. [Route("DeletezzSupplierEx")]
  296. public JsonResult DeletezzSupplierEx(string suppliercode, int id)
  297. {
  298. if (suppliercode.IsNullOrEmpty())
  299. {
  300. return Json("参数错误,不能删除");
  301. }
  302. if (id <= 0)
  303. {
  304. return Json("参数错误,不能删除");
  305. }
  306. try
  307. {
  308. var service = new zzSupplierExManager();
  309. var success = service.Delete(m => m.SupplierCode == suppliercode && m.ID == id);
  310. if (success)
  311. {
  312. return Json("success");
  313. }
  314. else
  315. {
  316. return Json("删除失败");
  317. }
  318. }
  319. catch (Exception ex)
  320. {
  321. logger.Error(ex);
  322. return Json(ex.Message + "\r\n" + ex.StackTrace);
  323. }
  324. }
  325. /// <summary>
  326. /// 根据供应商编号获取其对应所有项目
  327. /// </summary>
  328. /// <param name="supplierCode"></param>
  329. /// <returns></returns>
  330. [HttpGet]
  331. [Route("GetProjectBySupplierCode")]
  332. public JsonResult GetProjectBySupplierCode(string supplierCode)
  333. {
  334. if (supplierCode.IsNullOrEmpty())
  335. {
  336. return Json("请输入供应商编号");
  337. }
  338. try
  339. {
  340. var service = new zzSupplierExManager();
  341. var list = service.GetProjectBySupplierCode(supplierCode);
  342. logger.Info($"【GetProjectBySupplierCode】list:" + JsonConvert.SerializeObject(list));
  343. return Json(list);
  344. }
  345. catch (Exception ex)
  346. {
  347. return Json(ex.Message + "\r\n" + ex.StackTrace);
  348. }
  349. }
  350. #endregion
  351. }
  352. }