MarketCustomerResourcesController.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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.Collections;
  7. using System.Diagnostics;
  8. namespace OASystem.API.Controllers
  9. {
  10. /// <summary>
  11. /// 市场客户资料
  12. /// </summary>
  13. [Route("api/[controller]/[action]")]
  14. public class MarketCustomerResourcesController : ControllerBase
  15. {
  16. private readonly NewClientDataRepository _clientDataRepository;
  17. private readonly SqlSugarClient _sqlSugar;
  18. /// <summary>
  19. /// 初始化
  20. /// </summary>
  21. public MarketCustomerResourcesController(NewClientDataRepository clientDataRepository, SqlSugarClient sqlSugar)
  22. {
  23. this._clientDataRepository = clientDataRepository;
  24. _sqlSugar = sqlSugar;
  25. }
  26. /// <summary>
  27. /// 客户资料数据
  28. /// 基础数据
  29. /// </summary>
  30. /// <returns></returns>
  31. [HttpPost]
  32. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  33. public async Task<IActionResult> MarketCustomerInit(MarketCustomerInitDto dto)
  34. {
  35. JsonView jw = new JsonView();
  36. try
  37. {
  38. Result resultData = await _clientDataRepository._Init(dto);
  39. if (resultData.Code == 0)
  40. {
  41. jw = JsonView(true, "查询成功!", resultData.Data);
  42. }
  43. else
  44. {
  45. jw = JsonView(false, resultData.Msg);
  46. }
  47. }
  48. catch (Exception)
  49. {
  50. jw = JsonView(false, "程序错误!");
  51. }
  52. return Ok(jw);
  53. }
  54. /// <summary>
  55. /// 查询客户资料数据
  56. /// </summary>
  57. /// <returns></returns>
  58. [HttpPost]
  59. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  60. public async Task<IActionResult> QueryNewClientData(NewClientDataQueryDto dto)
  61. {
  62. #region 参数验证
  63. if (dto.OperationUserId < 0)
  64. return Ok(JsonView(false, "请传入有效的OperationUserId参数!"));
  65. if (dto.PortType < 0)
  66. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  67. #endregion
  68. JsonView jw = new JsonView();
  69. try
  70. {
  71. Result resultData = await _clientDataRepository.QueryNewClientData(dto);
  72. if (resultData.Code == 0)
  73. {
  74. #region 客户资料表操作记录
  75. await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.NoOperation, dto.OperationUserId, 0, "");
  76. #endregion
  77. jw = JsonView(true, resultData.Msg, resultData.Data);
  78. }
  79. else
  80. {
  81. jw = JsonView(false, resultData.Msg);
  82. }
  83. }
  84. catch (Exception)
  85. {
  86. jw = JsonView(false, "程序错误!");
  87. }
  88. return Ok(jw);
  89. }
  90. /// <summary>
  91. /// 客户资料数据
  92. /// Details
  93. /// </summary>
  94. /// <returns></returns>
  95. [HttpPost]
  96. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  97. public async Task<IActionResult> PostNewClientDataDetails(NewClientDataDetailsDto dto)
  98. {
  99. #region 参数验证
  100. if (dto.Id < 0)
  101. return Ok(JsonView(false, "请传入有效的Id参数!"));
  102. if (dto.UserId < 0)
  103. return Ok(JsonView(false, "请传入有效的UserId参数!"));
  104. if (dto.PortType < 0)
  105. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  106. #endregion
  107. JsonView jw = new JsonView();
  108. try
  109. {
  110. Result resultData = await _clientDataRepository._Details(dto.PortType, dto.Id);
  111. if (resultData.Code == 0)
  112. {
  113. #region 客户资料表操作记录
  114. await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Details, dto.UserId, dto.Id, "");
  115. #endregion
  116. jw = JsonView(true, "查询成功!", resultData.Data);
  117. }
  118. else
  119. {
  120. jw = JsonView(false, resultData.Msg);
  121. }
  122. }
  123. catch (Exception)
  124. {
  125. jw = JsonView(false, "程序错误!");
  126. }
  127. return Ok(jw);
  128. }
  129. /// <summary>
  130. /// 客户资料操作(Status:1.新增,2.修改)
  131. /// </summary>
  132. /// <param name="dto"></param>
  133. /// <returns></returns>
  134. [HttpPost]
  135. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  136. public async Task<IActionResult> NewClientOp(NewClientOpDto dto)
  137. {
  138. #region 参数验证
  139. if (dto.CreateUserId < 0)
  140. {
  141. return Ok(JsonView(false, "请传入有效的CreateUserId参数!"));
  142. }
  143. if (dto.PortType < 0)
  144. {
  145. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  146. }
  147. #endregion
  148. try
  149. {
  150. Domain.Result result = await _clientDataRepository.NewClientOp(dto);
  151. if (result.Code != 0)
  152. {
  153. return Ok(JsonView(false, result.Msg));
  154. }
  155. #region 客户资料操作记录
  156. OperationEnum operationEnum = OperationEnum.NoOperation;
  157. if (dto.Status == 1)
  158. {
  159. operationEnum = OperationEnum.Add;
  160. dto.Id = Convert.ToInt32(result.Data);
  161. }
  162. else if (dto.Status == 2) operationEnum = OperationEnum.Edit;
  163. await GeneralMethod.NewClientOperationRecord(dto.PortType, operationEnum, dto.CreateUserId, dto.Id, "");
  164. #endregion
  165. return Ok(JsonView(true, result.Msg + "Id:" + dto.Id));
  166. }
  167. catch (Exception ex)
  168. {
  169. return Ok(JsonView(false, "程序错误!Msg:" + ex.Message));
  170. }
  171. }
  172. /// <summary>
  173. /// 新客户资料操作(删除)
  174. /// </summary>
  175. /// <param name="dto"></param>
  176. /// <returns></returns>
  177. [HttpPost]
  178. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  179. public async Task<IActionResult> NewClientDel(DelBaseDto dto)
  180. {
  181. #region 参数验证
  182. if (dto.Id < 0)
  183. {
  184. return Ok(JsonView(false, "请传入有效的Id参数!"));
  185. }
  186. if (dto.DeleteUserId < 0)
  187. {
  188. return Ok(JsonView(false, "请传入有效的DeleteUserId参数!"));
  189. }
  190. if (dto.PortType < 0)
  191. {
  192. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  193. }
  194. #endregion
  195. var res = await _clientDataRepository.DelNewClientData(dto);
  196. if (res.Code != 0)
  197. {
  198. return Ok(JsonView(false, "删除失败"));
  199. }
  200. #region 客户资料表操作记录
  201. await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Del, dto.DeleteUserId, dto.Id, "");
  202. #endregion
  203. return Ok(JsonView(true, "删除成功!"));
  204. }
  205. /// <summary>
  206. /// 获取下拉列表数据和单条数据信息
  207. /// </summary>
  208. /// <param name="dto"></param>
  209. /// <returns></returns>
  210. [HttpPost]
  211. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  212. public async Task<IActionResult> QuerySelectAndSingleData(QuerySingleDto dto)
  213. {
  214. JsonView jw = new JsonView();
  215. var result = await _clientDataRepository.QuerySelectAndSingleData(dto);
  216. if (result.Code == 0)
  217. {
  218. #region 客户资料表操作记录
  219. await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Details, dto.UserId, dto.Id, "");
  220. #endregion
  221. jw = JsonView(true, result.Msg, result.Data);
  222. }
  223. else
  224. {
  225. jw = JsonView(false, result.Msg);
  226. }
  227. return Ok(jw);
  228. }
  229. /// <summary>
  230. /// 获取现有负责人
  231. /// </summary>
  232. /// <returns></returns>
  233. [HttpPost]
  234. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  235. public async Task<IActionResult> QueryUserSelect()
  236. {
  237. try
  238. {
  239. Result resTable = _clientDataRepository.QueryUserSelect();
  240. return Ok(JsonView(true, resTable.Msg, resTable.Data));
  241. }
  242. catch (Exception)
  243. {
  244. return Ok(JsonView(false, "程序错误!"));
  245. }
  246. }
  247. /// <summary>
  248. /// 获取出团数据
  249. /// </summary>
  250. /// <returns></returns>
  251. [HttpPost]
  252. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  253. public async Task<IActionResult> QueryNumberGroups()
  254. {
  255. var result = await _clientDataRepository.QueryNumberGroups();
  256. if (result.Code != 0)
  257. {
  258. return Ok(JsonView(false, result.Msg));
  259. }
  260. return Ok(JsonView(true, result.Msg, result.Data));
  261. }
  262. /// <summary>
  263. /// 新客户资料操作
  264. /// 批量分配
  265. /// </summary>
  266. /// <param name="dto"></param>
  267. /// <returns></returns>
  268. [HttpPost]
  269. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  270. public async Task<IActionResult> PostBatchAssignment(BatchAssignmentDto dto)
  271. {
  272. #region 参数验证
  273. if (dto.UserId < 0)
  274. {
  275. return Ok(JsonView(false, "请传入有效的UserId参数!"));
  276. }
  277. if (dto.PortType < 0)
  278. {
  279. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  280. }
  281. #endregion
  282. var res = await _clientDataRepository._BatchAssignment(dto);
  283. if (res.Code != 0)
  284. {
  285. return Ok(JsonView(false, res.Msg));
  286. }
  287. return Ok(JsonView(true, "操作成功!"));
  288. }
  289. private Dictionary<int, List<int>> MCRSetting()
  290. {
  291. Dictionary<int, List<int>> keyValuePairs = new Dictionary<int, List<int>>();
  292. keyValuePairs.Add(419, new List<int>() //四川
  293. {
  294. 376,377,378,381,382,387,388,389,390,753,754,1296,1303
  295. });
  296. keyValuePairs.Add(420, new List<int>() //云南
  297. {
  298. 407,408,409,410,449,451,452,453,567,754,1297,1304
  299. });
  300. keyValuePairs.Add(421, new List<int>() { 424, 425, 426, 427, 428, 429, 754,1298, 1305,1307,1306 }); // 贵州
  301. keyValuePairs.Add(422, new List<int>() { 415, 416, 754 }); // 西藏
  302. keyValuePairs.Add(423, new List<int>() { 417, 418, 454, 456, 754 }); // 重庆
  303. keyValuePairs.Add(578, new List<int>() { 581, 582, 583, 754,1299,1300 }); // 青海
  304. keyValuePairs.Add(605, new List<int>() { 588, 589, 590, 591, 592, 593, 754,1301,1310,1309,1308 }); // 陕西
  305. keyValuePairs.Add(606, new List<int>() { 597, 598, 599, 600, 601, 602, 603, 604, 754 }); // 宁夏
  306. keyValuePairs.Add(625, new List<int>() { 617, 618, 619, 620, 621, 622, 622, 623, 624, 754,1302,1312,1311 }); // 甘肃
  307. keyValuePairs.Add(634, new List<int>() { 455, 630, 631, 632, 633, 754 }); // 新疆
  308. return keyValuePairs;
  309. }
  310. [HttpPost]
  311. public IActionResult QueryClientType(QueryClientTypeDto Dto)
  312. {
  313. var jw = JsonView(true,"获取成功!");
  314. var keyValuePairs = MCRSetting();
  315. ArrayList arr = new ArrayList();
  316. var ids = new List<int>();
  317. foreach (var item in Dto.SetDataIdArr)
  318. {
  319. if (keyValuePairs.Keys.Contains(item))
  320. {
  321. ids.AddRange(keyValuePairs[item]);
  322. }
  323. }
  324. arr.AddRange(_sqlSugar.Queryable<Sys_SetData>()
  325. .Where(u => ids.Contains(u.Id) && u.IsDel == 0)
  326. .Select(x => new { x.Id, x.Name , x.Remark })
  327. .ToList());
  328. if (arr.Count == 0)
  329. {
  330. arr.AddRange(_sqlSugar.Queryable<Sys_SetData>()
  331. .Where(u => u.STid == 37 && u.IsDel == 0)
  332. .Select(x => new { x.Id, x.Name, x.Remark }).ToList());
  333. }
  334. // 创建比较器实例
  335. IComparer remakeComparer = new RemakeComparer();
  336. // 使用ArrayList.Sort方法和自定义比较器对arr进行排序
  337. arr.Sort(remakeComparer);
  338. jw.Data = arr;
  339. return Ok(jw);
  340. }
  341. [HttpPost]
  342. public IActionResult SynchronizationData()
  343. {
  344. var keyValuePairs = new Dictionary<int, List<string>>
  345. {
  346. { 5, new List<string> { "省级部门", "省级单位" } },
  347. { 10, new List<string> { "市州" } },
  348. { 15, new List<string> { "省属国企" } },
  349. { 20, new List<string> { "省属学校", "省属高校" } },
  350. { 25, new List<string> { "省级行业协会", "省级社团", "省级联合会" , "省属行业协会", "民营企业", "地方国企" } },
  351. { 30, new List<string> { "市级部门", "市级单位" } },
  352. { 35, new List<string> { "区市县" } },
  353. { 40, new List<string> { "市级国企", "市属国企" } },
  354. { 45, new List<string> { "市属学校", "市属高校" } },
  355. { 50, new List<string> { "市级行业协会", "市级社团", "市级联合会" } }
  356. };
  357. var setting = MCRSetting();
  358. var arr = new List<List<Sys_SetData>>();
  359. foreach (var item in setting.Keys)
  360. {
  361. var setDataList_DB = _sqlSugar.Queryable<Sys_SetData>()
  362. .Where(x => x.IsDel == 0 && setting[item].Contains(x.Id))
  363. .ToList();
  364. foreach (var setData in setDataList_DB)
  365. {
  366. foreach (var lv in keyValuePairs.Keys)
  367. {
  368. var islv = keyValuePairs[lv].Where(x => setData.Name.Contains(x)).Count() > 0;
  369. if (islv)
  370. {
  371. setData.Remark = lv.ToString();
  372. }
  373. }
  374. }
  375. arr.Add(setDataList_DB);
  376. }
  377. _sqlSugar.Updateable(arr.SelectMany(x => x).ToList()).UpdateColumns(x => new
  378. {
  379. x.Remark
  380. }).ExecuteCommand();
  381. return Ok(arr);
  382. }
  383. }
  384. }