MarketCustomerResourcesController.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. using OASystem.API.OAMethodLib;
  2. using OASystem.Domain.AesEncryption;
  3. using OASystem.Domain.Dtos.CRM;
  4. using OASystem.Domain.Entities.Customer;
  5. using OASystem.Infrastructure.Repositories.CRM;
  6. using System.Diagnostics;
  7. namespace OASystem.API.Controllers
  8. {
  9. /// <summary>
  10. /// 市场客户资料
  11. /// </summary>
  12. [Route("api/[controller]/[action]")]
  13. public class MarketCustomerResourcesController : ControllerBase
  14. {
  15. private readonly NewClientDataRepository _clientDataRepository;
  16. private readonly SqlSugarClient _sqlSugar;
  17. /// <summary>
  18. /// 初始化
  19. /// </summary>
  20. public MarketCustomerResourcesController(NewClientDataRepository clientDataRepository, SqlSugarClient sqlSugar)
  21. {
  22. this._clientDataRepository = clientDataRepository;
  23. _sqlSugar = sqlSugar;
  24. }
  25. /// <summary>
  26. /// 客户资料数据
  27. /// 基础数据
  28. /// </summary>
  29. /// <returns></returns>
  30. [HttpPost]
  31. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  32. public async Task<IActionResult> MarketCustomerInit(MarketCustomerInitDto dto)
  33. {
  34. JsonView jw = new JsonView();
  35. try
  36. {
  37. Result resultData = await _clientDataRepository._Init(dto);
  38. if (resultData.Code == 0)
  39. {
  40. jw = JsonView(true, "查询成功!", resultData.Data);
  41. }
  42. else
  43. {
  44. jw = JsonView(false, resultData.Msg);
  45. }
  46. }
  47. catch (Exception)
  48. {
  49. jw = JsonView(false, "程序错误!");
  50. }
  51. return Ok(jw);
  52. }
  53. /// <summary>
  54. /// 查询客户资料数据
  55. /// </summary>
  56. /// <returns></returns>
  57. [HttpPost]
  58. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  59. public async Task<IActionResult> QueryNewClientData(NewClientDataQueryDto dto)
  60. {
  61. #region 参数验证
  62. if (dto.OperationUserId < 0)
  63. return Ok(JsonView(false, "请传入有效的OperationUserId参数!"));
  64. if (dto.PortType < 0)
  65. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  66. #endregion
  67. JsonView jw = new JsonView();
  68. try
  69. {
  70. Result resultData = await _clientDataRepository.QueryNewClientData(dto);
  71. if (resultData.Code == 0)
  72. {
  73. #region 客户资料表操作记录
  74. await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.NoOperation, dto.OperationUserId, 0, "");
  75. #endregion
  76. jw = JsonView(true, resultData.Msg, resultData.Data);
  77. }
  78. else
  79. {
  80. jw = JsonView(false, resultData.Msg);
  81. }
  82. }
  83. catch (Exception)
  84. {
  85. jw = JsonView(false, "程序错误!");
  86. }
  87. return Ok(jw);
  88. }
  89. /// <summary>
  90. /// 客户资料数据
  91. /// Details
  92. /// </summary>
  93. /// <returns></returns>
  94. [HttpPost]
  95. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  96. public async Task<IActionResult> PostNewClientDataDetails(NewClientDataDetailsDto dto)
  97. {
  98. #region 参数验证
  99. if (dto.Id < 0)
  100. return Ok(JsonView(false, "请传入有效的Id参数!"));
  101. if (dto.UserId < 0)
  102. return Ok(JsonView(false, "请传入有效的UserId参数!"));
  103. if (dto.PortType < 0)
  104. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  105. #endregion
  106. JsonView jw = new JsonView();
  107. try
  108. {
  109. Result resultData = await _clientDataRepository._Details(dto.PortType, dto.Id);
  110. if (resultData.Code == 0)
  111. {
  112. #region 客户资料表操作记录
  113. await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Details, dto.UserId, dto.Id, "");
  114. #endregion
  115. jw = JsonView(true, "查询成功!", resultData.Data);
  116. }
  117. else
  118. {
  119. jw = JsonView(false, resultData.Msg);
  120. }
  121. }
  122. catch (Exception)
  123. {
  124. jw = JsonView(false, "程序错误!");
  125. }
  126. return Ok(jw);
  127. }
  128. /// <summary>
  129. /// 客户资料操作(Status:1.新增,2.修改)
  130. /// </summary>
  131. /// <param name="dto"></param>
  132. /// <returns></returns>
  133. [HttpPost]
  134. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  135. public async Task<IActionResult> NewClientOp(NewClientOpDto dto)
  136. {
  137. #region 参数验证
  138. if (dto.CreateUserId < 0)
  139. {
  140. return Ok(JsonView(false, "请传入有效的CreateUserId参数!"));
  141. }
  142. if (dto.PortType < 0)
  143. {
  144. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  145. }
  146. #endregion
  147. try
  148. {
  149. Domain.Result result = await _clientDataRepository.NewClientOp(dto);
  150. if (result.Code != 0)
  151. {
  152. return Ok(JsonView(false, result.Msg));
  153. }
  154. #region 客户资料操作记录
  155. OperationEnum operationEnum = OperationEnum.NoOperation;
  156. if (dto.Status == 1)
  157. {
  158. operationEnum = OperationEnum.Add;
  159. dto.Id = Convert.ToInt32(result.Data);
  160. }
  161. else if (dto.Status == 2) operationEnum = OperationEnum.Edit;
  162. await GeneralMethod.NewClientOperationRecord(dto.PortType, operationEnum, dto.CreateUserId, dto.Id, "");
  163. #endregion
  164. return Ok(JsonView(true, result.Msg + "Id:" + dto.Id));
  165. }
  166. catch (Exception ex)
  167. {
  168. return Ok(JsonView(false, "程序错误!Msg:" + ex.Message));
  169. }
  170. }
  171. /// <summary>
  172. /// 新客户资料操作(删除)
  173. /// </summary>
  174. /// <param name="dto"></param>
  175. /// <returns></returns>
  176. [HttpPost]
  177. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  178. public async Task<IActionResult> NewClientDel(DelBaseDto dto)
  179. {
  180. #region 参数验证
  181. if (dto.Id < 0)
  182. {
  183. return Ok(JsonView(false, "请传入有效的Id参数!"));
  184. }
  185. if (dto.DeleteUserId < 0)
  186. {
  187. return Ok(JsonView(false, "请传入有效的DeleteUserId参数!"));
  188. }
  189. if (dto.PortType < 0)
  190. {
  191. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  192. }
  193. #endregion
  194. var res = await _clientDataRepository.DelNewClientData(dto);
  195. if (res.Code != 0)
  196. {
  197. return Ok(JsonView(false, "删除失败"));
  198. }
  199. #region 客户资料表操作记录
  200. await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Del, dto.DeleteUserId, dto.Id, "");
  201. #endregion
  202. return Ok(JsonView(true, "删除成功!"));
  203. }
  204. /// <summary>
  205. /// 获取下拉列表数据和单条数据信息
  206. /// </summary>
  207. /// <param name="dto"></param>
  208. /// <returns></returns>
  209. [HttpPost]
  210. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  211. public async Task<IActionResult> QuerySelectAndSingleData(QuerySingleDto dto)
  212. {
  213. JsonView jw = new JsonView();
  214. var result = await _clientDataRepository.QuerySelectAndSingleData(dto);
  215. if (result.Code == 0)
  216. {
  217. #region 客户资料表操作记录
  218. await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Details, dto.UserId, dto.Id, "");
  219. #endregion
  220. jw = JsonView(true, result.Msg, result.Data);
  221. }
  222. else
  223. {
  224. jw = JsonView(false, result.Msg);
  225. }
  226. return Ok(jw);
  227. }
  228. /// <summary>
  229. /// 获取现有负责人
  230. /// </summary>
  231. /// <returns></returns>
  232. [HttpPost]
  233. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  234. public async Task<IActionResult> QueryUserSelect()
  235. {
  236. try
  237. {
  238. Result resTable = _clientDataRepository.QueryUserSelect();
  239. return Ok(JsonView(true, resTable.Msg, resTable.Data));
  240. }
  241. catch (Exception)
  242. {
  243. return Ok(JsonView(false, "程序错误!"));
  244. }
  245. }
  246. /// <summary>
  247. /// 获取出团数据
  248. /// </summary>
  249. /// <returns></returns>
  250. [HttpPost]
  251. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  252. public async Task<IActionResult> QueryNumberGroups()
  253. {
  254. var result = await _clientDataRepository.QueryNumberGroups();
  255. if (result.Code != 0)
  256. {
  257. return Ok(JsonView(false, result.Msg));
  258. }
  259. return Ok(JsonView(true, result.Msg, result.Data));
  260. }
  261. /// <summary>
  262. /// 新客户资料操作
  263. /// 批量分配
  264. /// </summary>
  265. /// <param name="dto"></param>
  266. /// <returns></returns>
  267. [HttpPost]
  268. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  269. public async Task<IActionResult> PostBatchAssignment(BatchAssignmentDto dto)
  270. {
  271. #region 参数验证
  272. if (dto.UserId < 0)
  273. {
  274. return Ok(JsonView(false, "请传入有效的UserId参数!"));
  275. }
  276. if (dto.PortType < 0)
  277. {
  278. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  279. }
  280. #endregion
  281. var res = await _clientDataRepository._BatchAssignment(dto);
  282. if (res.Code != 0)
  283. {
  284. return Ok(JsonView(false, res.Msg));
  285. }
  286. return Ok(JsonView(true, "操作成功!"));
  287. }
  288. [HttpPost]
  289. public IActionResult QueryClientType(QueryClientTypeDto Dto)
  290. {
  291. var jw = JsonView(true,"获取成功!");
  292. Dictionary<int,List<int>> keyValuePairs = new Dictionary<int,List<int>>();
  293. keyValuePairs.Add(419, new List<int>() //四川
  294. {
  295. 376,377,378,381,382,387,388,389,390,753,754
  296. });
  297. keyValuePairs.Add(420, new List<int>() //云南
  298. {
  299. 407,408,409,410,449,451,452,453,567,754
  300. });
  301. keyValuePairs.Add(421, new List<int>() { 424, 425, 426, 427, 428, 429, 754 }); // 贵州
  302. keyValuePairs.Add(422, new List<int>() { 415, 416, 754 }); // 西藏
  303. keyValuePairs.Add(423, new List<int>() { 417, 418, 454, 456, 754 }); // 重庆
  304. keyValuePairs.Add(578, new List<int>() { 581, 582, 583, 754 }); // 青海
  305. keyValuePairs.Add(605, new List<int>() { 588, 589, 590, 591, 592, 593, 754 }); // 陕西
  306. keyValuePairs.Add(606, new List<int>() { 597, 598, 599, 600, 601, 602, 603, 604, 754 }); // 宁夏
  307. keyValuePairs.Add(625, new List<int>() { 617, 618, 619, 620, 621, 622, 622, 623, 624, 754 }); // 甘肃
  308. keyValuePairs.Add(634, new List<int>() { 455, 630, 631, 632, 633, 754 }); // 新疆
  309. if (keyValuePairs.Keys.Contains(Dto.SetDataId))
  310. {
  311. jw.Data = _sqlSugar.Queryable<Sys_SetData>()
  312. .Where(u => keyValuePairs[Dto.SetDataId].Contains(u.Id) && u.IsDel == 0 )
  313. .Select(x => new { x.Id, x.Name }).ToList();
  314. }
  315. else
  316. {
  317. jw.Data = _sqlSugar.Queryable<Sys_SetData>()
  318. .Where(u => u.STid == 37 && u.IsDel == 0)
  319. .Select(x => new { x.Id, x.Name }).ToList();
  320. }
  321. return Ok(jw);
  322. }
  323. }
  324. }