MarketCustomerResourcesController.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. using Aspose.Cells;
  2. using Microsoft.AspNetCore.Mvc.RazorPages;
  3. using OASystem.API.OAMethodLib;
  4. using OASystem.Domain.AesEncryption;
  5. using OASystem.Domain.Dtos.CRM;
  6. using OASystem.Domain.Entities.Customer;
  7. using OASystem.Domain.ViewModels.CRM;
  8. using OASystem.Infrastructure.Repositories.CRM;
  9. using System.Collections;
  10. using System.Data;
  11. using System.Diagnostics;
  12. using System.Linq;
  13. namespace OASystem.API.Controllers
  14. {
  15. /// <summary>
  16. /// 市场客户资料
  17. /// </summary>
  18. [Route("api/[controller]/[action]")]
  19. public class MarketCustomerResourcesController : ControllerBase
  20. {
  21. private readonly NewClientDataRepository _clientDataRepository;
  22. private readonly SqlSugarClient _sqlSugar;
  23. /// <summary>
  24. /// 初始化
  25. /// </summary>
  26. public MarketCustomerResourcesController(NewClientDataRepository clientDataRepository, SqlSugarClient sqlSugar)
  27. {
  28. this._clientDataRepository = clientDataRepository;
  29. _sqlSugar = sqlSugar;
  30. }
  31. /// <summary>
  32. /// 客户资料数据
  33. /// 基础数据
  34. /// </summary>
  35. /// <returns></returns>
  36. [HttpPost]
  37. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  38. public async Task<IActionResult> MarketCustomerInit(MarketCustomerInitDto dto)
  39. {
  40. JsonView jw = new JsonView();
  41. try
  42. {
  43. Result resultData = await _clientDataRepository._Init(dto);
  44. if (resultData.Code == 0)
  45. {
  46. jw = JsonView(true, "查询成功!", resultData.Data);
  47. }
  48. else
  49. {
  50. jw = JsonView(false, resultData.Msg);
  51. }
  52. }
  53. catch (Exception)
  54. {
  55. jw = JsonView(false, "程序错误!");
  56. }
  57. return Ok(jw);
  58. }
  59. /// <summary>
  60. /// 查询客户资料数据
  61. /// </summary>
  62. /// <returns></returns>
  63. [HttpPost]
  64. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  65. public async Task<IActionResult> QueryNewClientData(NewClientDataQueryDto dto)
  66. {
  67. #region 参数验证
  68. if (dto.OperationUserId < 0)
  69. return Ok(JsonView(false, "请传入有效的OperationUserId参数!"));
  70. if (dto.PortType < 0)
  71. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  72. #endregion
  73. JsonView jw = new JsonView();
  74. try
  75. {
  76. Result resultData = await _clientDataRepository.QueryNewClientData(dto);
  77. if (resultData.Code == 0)
  78. {
  79. #region 客户资料表操作记录
  80. await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.NoOperation, dto.OperationUserId, 0, "");
  81. #endregion
  82. jw = JsonView(true, resultData.Msg, resultData.Data);
  83. }
  84. else
  85. {
  86. jw = JsonView(false, resultData.Msg);
  87. }
  88. }
  89. catch (Exception)
  90. {
  91. jw = JsonView(false, "程序错误!");
  92. }
  93. return Ok(jw);
  94. }
  95. /// <summary>
  96. /// 客户资料数据
  97. /// Details
  98. /// </summary>
  99. /// <returns></returns>
  100. [HttpPost]
  101. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  102. public async Task<IActionResult> PostNewClientDataDetails(NewClientDataDetailsDto dto)
  103. {
  104. #region 参数验证
  105. if (dto.Id < 0)
  106. return Ok(JsonView(false, "请传入有效的Id参数!"));
  107. if (dto.UserId < 0)
  108. return Ok(JsonView(false, "请传入有效的UserId参数!"));
  109. if (dto.PortType < 0)
  110. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  111. #endregion
  112. JsonView jw = new JsonView();
  113. try
  114. {
  115. Result resultData = await _clientDataRepository._Details(dto.PortType, dto.Id);
  116. if (resultData.Code == 0)
  117. {
  118. #region 客户资料表操作记录
  119. await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Details, dto.UserId, dto.Id, "");
  120. #endregion
  121. jw = JsonView(true, "查询成功!", resultData.Data);
  122. }
  123. else
  124. {
  125. jw = JsonView(false, resultData.Msg);
  126. }
  127. }
  128. catch (Exception)
  129. {
  130. jw = JsonView(false, "程序错误!");
  131. }
  132. return Ok(jw);
  133. }
  134. /// <summary>
  135. /// 客户资料操作(Status:1.新增,2.修改)
  136. /// </summary>
  137. /// <param name="dto"></param>
  138. /// <returns></returns>
  139. [HttpPost]
  140. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  141. public async Task<IActionResult> NewClientOp(NewClientOpDto dto)
  142. {
  143. #region 参数验证
  144. if (dto.CreateUserId < 0)
  145. {
  146. return Ok(JsonView(false, "请传入有效的CreateUserId参数!"));
  147. }
  148. if (dto.PortType < 0)
  149. {
  150. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  151. }
  152. #endregion
  153. try
  154. {
  155. Domain.Result result = await _clientDataRepository.NewClientOp(dto);
  156. if (result.Code != 0)
  157. {
  158. return Ok(JsonView(false, result.Msg));
  159. }
  160. #region 客户资料操作记录
  161. OperationEnum operationEnum = OperationEnum.NoOperation;
  162. if (dto.Status == 1)
  163. {
  164. operationEnum = OperationEnum.Add;
  165. dto.Id = Convert.ToInt32(result.Data);
  166. }
  167. else if (dto.Status == 2) operationEnum = OperationEnum.Edit;
  168. await GeneralMethod.NewClientOperationRecord(dto.PortType, operationEnum, dto.CreateUserId, dto.Id, "");
  169. #endregion
  170. return Ok(JsonView(true, result.Msg + "Id:" + dto.Id));
  171. }
  172. catch (Exception ex)
  173. {
  174. return Ok(JsonView(false, "程序错误!Msg:" + ex.Message));
  175. }
  176. }
  177. /// <summary>
  178. /// 新客户资料操作(删除)
  179. /// </summary>
  180. /// <param name="dto"></param>
  181. /// <returns></returns>
  182. [HttpPost]
  183. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  184. public async Task<IActionResult> NewClientDel(DelBaseDto dto)
  185. {
  186. #region 参数验证
  187. if (dto.Id < 0)
  188. {
  189. return Ok(JsonView(false, "请传入有效的Id参数!"));
  190. }
  191. if (dto.DeleteUserId < 0)
  192. {
  193. return Ok(JsonView(false, "请传入有效的DeleteUserId参数!"));
  194. }
  195. if (dto.PortType < 0)
  196. {
  197. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  198. }
  199. #endregion
  200. var res = await _clientDataRepository.DelNewClientData(dto);
  201. if (res.Code != 0)
  202. {
  203. return Ok(JsonView(false, "删除失败"));
  204. }
  205. #region 客户资料表操作记录
  206. await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Del, dto.DeleteUserId, dto.Id, "");
  207. #endregion
  208. return Ok(JsonView(true, "删除成功!"));
  209. }
  210. /// <summary>
  211. /// 获取下拉列表数据和单条数据信息
  212. /// </summary>
  213. /// <param name="dto"></param>
  214. /// <returns></returns>
  215. [HttpPost]
  216. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  217. public async Task<IActionResult> QuerySelectAndSingleData(QuerySingleDto dto)
  218. {
  219. JsonView jw = new JsonView();
  220. var result = await _clientDataRepository.QuerySelectAndSingleData(dto);
  221. if (result.Code == 0)
  222. {
  223. #region 客户资料表操作记录
  224. await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Details, dto.UserId, dto.Id, "");
  225. #endregion
  226. jw = JsonView(true, result.Msg, result.Data);
  227. }
  228. else
  229. {
  230. jw = JsonView(false, result.Msg);
  231. }
  232. return Ok(jw);
  233. }
  234. /// <summary>
  235. /// 获取现有负责人
  236. /// </summary>
  237. /// <returns></returns>
  238. [HttpPost]
  239. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  240. public async Task<IActionResult> QueryUserSelect()
  241. {
  242. try
  243. {
  244. Result resTable = _clientDataRepository.QueryUserSelect();
  245. return Ok(JsonView(true, resTable.Msg, resTable.Data));
  246. }
  247. catch (Exception)
  248. {
  249. return Ok(JsonView(false, "程序错误!"));
  250. }
  251. }
  252. /// <summary>
  253. /// 获取出团数据
  254. /// </summary>
  255. /// <returns></returns>
  256. [HttpPost]
  257. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  258. public async Task<IActionResult> QueryNumberGroups()
  259. {
  260. var result = await _clientDataRepository.QueryNumberGroups();
  261. if (result.Code != 0)
  262. {
  263. return Ok(JsonView(false, result.Msg));
  264. }
  265. return Ok(JsonView(true, result.Msg, result.Data));
  266. }
  267. /// <summary>
  268. /// 新客户资料操作
  269. /// 批量分配
  270. /// </summary>
  271. /// <param name="dto"></param>
  272. /// <returns></returns>
  273. [HttpPost]
  274. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  275. public async Task<IActionResult> PostBatchAssignment(BatchAssignmentDto dto)
  276. {
  277. #region 参数验证
  278. if (dto.UserId < 0)
  279. {
  280. return Ok(JsonView(false, "请传入有效的UserId参数!"));
  281. }
  282. if (dto.PortType < 0)
  283. {
  284. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  285. }
  286. #endregion
  287. var res = await _clientDataRepository._BatchAssignment(dto);
  288. if (res.Code != 0)
  289. {
  290. return Ok(JsonView(false, res.Msg));
  291. }
  292. return Ok(JsonView(true, "操作成功!"));
  293. }
  294. private Dictionary<int, List<int>> MCRSetting()
  295. {
  296. Dictionary<int, List<int>> keyValuePairs = new Dictionary<int, List<int>>();
  297. keyValuePairs.Add(419, new List<int>() //四川
  298. {
  299. 376,377,378,381,382,387,388,389,390,753,754,1296,1303
  300. });
  301. keyValuePairs.Add(420, new List<int>() //云南
  302. {
  303. 407,408,409,410,449,451,452,453,567,754,1297,1304
  304. });
  305. keyValuePairs.Add(421, new List<int>() { 424, 425, 426, 427, 428, 429, 754,1298, 1305,1307,1306 }); // 贵州
  306. keyValuePairs.Add(422, new List<int>() { 415, 416, 754,1317,1316,1315, 455,1321, 1320, 1319, 1318 }); // 西藏
  307. keyValuePairs.Add(423, new List<int>() { 417, 418, 454, 456, 754, 1313, 1314 }); // 重庆
  308. keyValuePairs.Add(578, new List<int>() { 581, 582, 583, 754,1299,1300 }); // 青海
  309. keyValuePairs.Add(605, new List<int>() { 588, 589, 590, 591, 592, 593, 754,1301,1310,1309,1308 }); // 陕西
  310. keyValuePairs.Add(606, new List<int>() { 597, 598, 599, 600, 601, 602, 603, 604, 754,1324,1323,1322 }); // 宁夏
  311. keyValuePairs.Add(625, new List<int>() { 617, 618, 619, 620, 621, 622, 622, 623, 624, 754,1302,1312,1311 }); // 甘肃
  312. keyValuePairs.Add(634, new List<int>() { 630, 631, 632, 633, 754 }); // 新疆
  313. return keyValuePairs;
  314. }
  315. private Dictionary<int, List<int>> MCRSecondSetting()
  316. {
  317. Dictionary<int, List<int>> keyValuePairs = new Dictionary<int, List<int>>();
  318. // 四川
  319. keyValuePairs.Add(349, new List<int>() { 376, 378, 381, 387, 389, 1296 }); // 四川省级
  320. keyValuePairs.Add(350, new List<int>() { 377, 382, 388, 390, 1303 }); // 成都市级
  321. keyValuePairs.Add(348, new List<int>() { 387 }); // 四川地市州 - Explicitly assigning to ensure all source2 IDs are used
  322. keyValuePairs.Add(701, new List<int>() { 388 }); // 成都区市县
  323. // 云南
  324. keyValuePairs.Add(399, new List<int>() { 407, 408, 409, 410, 451 }); // 云南省级
  325. keyValuePairs.Add(400, new List<int>() { 449, 452, 453, 1297, 1304 }); // 昆明市级
  326. keyValuePairs.Add(450, new List<int>() { 410 }); // 云南地市州
  327. keyValuePairs.Add(566, new List<int>() { 567 }); // 昆明区市县
  328. // 贵州
  329. keyValuePairs.Add(401, new List<int>() { 424, 426, 427, 428, 1298 }); // 贵州省级
  330. keyValuePairs.Add(402, new List<int>() { 425, 429, 1306, 1307, 1305 }); // 贵阳市级
  331. keyValuePairs.Add(414, new List<int>() { 428 }); // 贵州地市州
  332. //keyValuePairs.Add(1305, new List<int>() { /* Add relevant IDs if available */ }); // 贵阳区市县 - Placeholder for now
  333. // 重庆
  334. keyValuePairs.Add(403, new List<int>() { 417, 418, 454, 456, 1314 }); // 重庆市级
  335. keyValuePairs.Add(404, new List<int>() { 1313 }); // 重庆区县 - No direct match in source1
  336. // 西藏
  337. keyValuePairs.Add(405, new List<int>() { 415, 1317, 1316, 1315 }); // 西藏自治区
  338. keyValuePairs.Add(406, new List<int>() { 455, 1321, 1320, 1319, 1318 }); // 拉萨市级
  339. keyValuePairs.Add(413, new List<int>() { 416 }); // 西藏地市州
  340. // 青海
  341. keyValuePairs.Add(579, new List<int>() { 581, 582, 583, 1300 }); // 青海省级
  342. keyValuePairs.Add(580, new List<int>() { 1299 }); // 青海市州县 (Includes 地市州)
  343. // 陕西
  344. keyValuePairs.Add(585, new List<int>() { 588, 589, 590, 591, 1301 }); // 陕西省级
  345. keyValuePairs.Add(586, new List<int>() { 589 }); // 陕西地市州
  346. keyValuePairs.Add(587, new List<int>() { 592, 593, 1309, 1310 , 1308 }); // 西安市级
  347. //keyValuePairs.Add(1308, new List<int>() { /* Add relevant IDs if available */ }); // 西安区市县 - Placeholder
  348. // 宁夏
  349. keyValuePairs.Add(594, new List<int>() { 597, 598, 599, 600, 601, 1322 }); // 宁夏自治区 (Includes 地市州 and 区级)
  350. keyValuePairs.Add(595, new List<int>() { 597 }); // 宁夏地市州
  351. keyValuePairs.Add(596, new List<int>() { 598, 599, 600, 603, 604, 602, 1323, 1324 }); // 银川市级 (Includes 区级)
  352. //keyValuePairs.Add(602, new List<int>()); // 银川区市县 - No direct match, but could be considered covered by "区级"
  353. // 甘肃
  354. keyValuePairs.Add(614, new List<int>() { 617, 618, 619, 620, 621, 1302 }); // 甘肃省级
  355. keyValuePairs.Add(615, new List<int>() { 618 }); // 甘肃地市州
  356. keyValuePairs.Add(616, new List<int>() { 622, 623, 624, 1312, 1311 }); // 兰州市级
  357. //keyValuePairs.Add(1311, new List<int>() { /* Add relevant IDs if available */ }); // 兰州区市县 - Placeholder
  358. // 新疆
  359. keyValuePairs.Add(627, new List<int>() { 630, 631, 632 , 1327,1326 ,1325 }); // 新疆自治区级
  360. keyValuePairs.Add(628, new List<int>() { 1326 }); // 新疆地市州 - No direct match
  361. keyValuePairs.Add(629, new List<int>() { 633,1331,1330,1329 ,1328 }); // 乌鲁木齐市级
  362. // 中央直属企业 (Special case)
  363. keyValuePairs.Add(351, new List<int>() { 754 }); // Using "未分级" for 中央直属企业
  364. return keyValuePairs;
  365. }
  366. private Dictionary<int, List<int>> MCRLvSetting()
  367. {
  368. var keyValuePairs = new Dictionary<int, List<int>>();
  369. // 四川 (419)
  370. keyValuePairs.Add(419, new List<int>() { 348, 349, 350, 701 }); // Includes all Sichuan-related IDs from source2
  371. // 云南 (420)
  372. keyValuePairs.Add(420, new List<int>() { 399, 400, 450, 566 }); // Includes all Yunnan-related IDs
  373. // 贵州 (421)
  374. keyValuePairs.Add(421, new List<int>() { 401, 402, 414 });
  375. // 西藏 (422)
  376. keyValuePairs.Add(422, new List<int>() { 405, 406, 413 });
  377. // 重庆 (423)
  378. keyValuePairs.Add(423, new List<int>() { 403, 404 });
  379. // 青海 (578)
  380. keyValuePairs.Add(578, new List<int>() { 579, 580, 626 }); // Includes 市州县 and 西宁市级
  381. // 陕西 (605)
  382. keyValuePairs.Add(605, new List<int>() { 585, 586, 587 });
  383. // 宁夏 (606)
  384. keyValuePairs.Add(606, new List<int>() { 594, 595, 596 });
  385. // 甘肃 (625)
  386. keyValuePairs.Add(625, new List<int>() { 614, 615, 616 });
  387. // 新疆 (634)
  388. keyValuePairs.Add(634, new List<int>() { 627, 628, 629 });
  389. // 未分级 (351) - You'll likely want to remove this as it's no longer a primary key.
  390. // keyValuePairs.Add(351, new List<int>()); //Remove this line.
  391. return keyValuePairs;
  392. }
  393. [HttpPost]
  394. public IActionResult QueryClientType(QueryClientTypeDto Dto)
  395. {
  396. var jw = JsonView(true,"获取成功!");
  397. var dic_lv = MCRLvSetting();
  398. var keyValuePairs = MCRSetting();
  399. ArrayList arr = new ArrayList();
  400. ArrayList lvArr = new ArrayList();
  401. var ids = new List<int>();
  402. var lvids = new List<int>();
  403. foreach (var item in Dto.SetDataIdArr)
  404. {
  405. if (keyValuePairs.Keys.Contains(item))
  406. {
  407. ids.AddRange(keyValuePairs[item]);
  408. }
  409. if (dic_lv.Keys.Contains(item))
  410. {
  411. lvids.AddRange(dic_lv[item]);
  412. }
  413. }
  414. arr.AddRange(_sqlSugar.Queryable<Sys_SetData>()
  415. .Where(u => ids.Contains(u.Id) && u.IsDel == 0)
  416. .Select(x => new { x.Id, x.Name , x.Remark })
  417. .ToList());
  418. if (arr.Count == 0)
  419. {
  420. arr.AddRange(_sqlSugar.Queryable<Sys_SetData>()
  421. .Where(u => u.STid == 37 && u.IsDel == 0)
  422. .Select(x => new { x.Id, x.Name, x.Remark }).ToList());
  423. }
  424. // 创建比较器实例
  425. IComparer remakeComparer = new RemakeComparer();
  426. // 使用ArrayList.Sort方法和自定义比较器对arr进行排序
  427. arr.Sort(remakeComparer);
  428. var rangelv = _sqlSugar.Queryable<Sys_SetData>()
  429. .Where(u => lvids.Contains(u.Id) && u.IsDel == 0)
  430. .Select(x => new { x.Id, x.Name })
  431. .ToList();
  432. lvArr.AddRange(rangelv);
  433. if (lvArr.Count == 0)
  434. {
  435. lvArr.AddRange(_sqlSugar.Queryable<Sys_SetData>()
  436. .Where(u => u.STid == 33 && u.IsDel == 0)
  437. .Select(x => new { x.Id, x.Name}).ToList());
  438. }
  439. jw.Data = new
  440. {
  441. TypeArr = arr,
  442. LvArr = lvArr,
  443. };
  444. return Ok(jw);
  445. }
  446. [HttpPost]
  447. public IActionResult QueryClientTypeSecond(QueryClientTypeDto Dto)
  448. {
  449. var jw = JsonView(true, "获取成功!");
  450. var keyValuePairs = MCRSecondSetting();
  451. ArrayList arr = new ArrayList();
  452. var ids = new List<int>();
  453. foreach (var item in Dto.SetDataIdArr)
  454. {
  455. if (keyValuePairs.Keys.Contains(item))
  456. {
  457. ids.AddRange(keyValuePairs[item]);
  458. }
  459. }
  460. arr.AddRange(_sqlSugar.Queryable<Sys_SetData>()
  461. .Where(u => ids.Contains(u.Id) && u.IsDel == 0)
  462. .Select(x => new { x.Id, x.Name, x.Remark })
  463. .ToList());
  464. if (arr.Count == 0)
  465. {
  466. arr.AddRange(_sqlSugar.Queryable<Sys_SetData>()
  467. .Where(u => u.STid == 37 && u.IsDel == 0)
  468. .Select(x => new { x.Id, x.Name, x.Remark }).ToList());
  469. }
  470. // 创建比较器实例
  471. IComparer remakeComparer = new RemakeComparer();
  472. // 使用ArrayList.Sort方法和自定义比较器对arr进行排序
  473. arr.Sort(remakeComparer);
  474. jw.Data = arr;
  475. return Ok(jw);
  476. }
  477. /// <summary>
  478. /// 客户资料数据 excel 下载
  479. /// </summary>
  480. /// <param name="dto"></param>
  481. /// <returns></returns>
  482. [HttpPost]
  483. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  484. public async Task<IActionResult> NewClientDataExcelDownload(NewClientDataExcelDownloadDto dto)
  485. {
  486. #region 参数验证
  487. if (dto.OperationUserId < 0) return Ok(JsonView(false, "请传入有效的OperationUserId参数!"));
  488. if (dto.PortType < 0) return Ok(JsonView(false, "请传入有效的PortType参数!"));
  489. if (dto.PageId < 0) return Ok(JsonView(false, "请传入有效的PageId参数!"));
  490. #endregion
  491. #region 页面操作权限验证
  492. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.OperationUserId, dto.PageId);
  493. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权!"));
  494. #endregion
  495. var dt = await _clientDataRepository.NewClientDataExcelDownload(dto);
  496. if (dt != null)
  497. {
  498. string tempPath = (AppSettingsHelper.Get("ExcelBasePath") + "Template/公司客户资料导出模板.xlsx");
  499. var designer = new WorkbookDesigner();
  500. designer.Workbook = new Workbook(tempPath);
  501. designer.SetDataSource("NCDDT", dt);
  502. designer.Process();
  503. //文件名
  504. string fileName = $"公司客户资料{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
  505. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + "NewClientDataExcelDownload/" + fileName);
  506. string url = AppSettingsHelper.Get("ExcelBaseUrl") + "Office/Excel/NewClientDataExcelDownload/" + fileName;
  507. #region 客户资料表操作记录
  508. var respose = JsonView(true, "成功", url);
  509. var paramData = new
  510. {
  511. APIName = @"MarketCustomerResources/NewClientDataExcelDownload",
  512. RequestParam = dto,
  513. ResposeParam = respose
  514. };
  515. await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Download, dto.OperationUserId, 0, JsonConvert.SerializeObject(paramData));
  516. #endregion
  517. return Ok(respose);
  518. }
  519. return Ok(JsonView(false));
  520. }
  521. #region 修改数据
  522. //[HttpPost]
  523. //public IActionResult SynchronizationData()
  524. //{
  525. // var keyValuePairs = new Dictionary<int, List<string>>
  526. // {
  527. // { 5, new List<string> { "省级部门", "省级单位" } },
  528. // { 10, new List<string> { "市州" } },
  529. // { 15, new List<string> { "省属国企" } },
  530. // { 20, new List<string> { "省属学校", "省属高校" } },
  531. // { 25, new List<string> { "省级行业协会", "省级社团", "省级联合会" , "省属行业协会", "民营企业", "地方国企" } },
  532. // { 30, new List<string> { "市级部门", "市级单位" } },
  533. // { 35, new List<string> { "区市县" } },
  534. // { 40, new List<string> { "市级国企", "市属国企" } },
  535. // { 45, new List<string> { "市属学校", "市属高校" } },
  536. // { 50, new List<string> { "市级行业协会", "市级社团", "市级联合会" } }
  537. // };
  538. // var setting = MCRSetting();
  539. // var arr = new List<List<Sys_SetData>>();
  540. // foreach (var item in setting.Keys)
  541. // {
  542. // var setDataList_DB = _sqlSugar.Queryable<Sys_SetData>()
  543. // .Where(x => x.IsDel == 0 && setting[item].Contains(x.Id))
  544. // .ToList();
  545. // foreach (var setData in setDataList_DB)
  546. // {
  547. // foreach (var lv in keyValuePairs.Keys)
  548. // {
  549. // var islv = keyValuePairs[lv].Where(x => setData.Name.Contains(x)).Count() > 0;
  550. // if (islv)
  551. // {
  552. // setData.Remark = lv.ToString();
  553. // }
  554. // }
  555. // }
  556. // arr.Add(setDataList_DB);
  557. // }
  558. // _sqlSugar.Updateable(arr.SelectMany(x => x).ToList()).UpdateColumns(x => new
  559. // {
  560. // x.Remark
  561. // }).ExecuteCommand();
  562. // return Ok(arr);
  563. //}
  564. [HttpPost]
  565. public IActionResult QueryData()
  566. {
  567. var db = _sqlSugar.Queryable<Crm_NewClientData>()
  568. .Where(x => x.IsDel == 0)
  569. .Select(x => new Crm_NewClientData
  570. {
  571. Id = x.Id,
  572. Client = x.Client,
  573. Category = x.Category,
  574. Location = x.Location,
  575. }).ToList();
  576. var count = 0;
  577. var updateid = new List<int>();
  578. foreach (var item in db)
  579. {
  580. EncryptionProcessor.DecryptProperties(item);
  581. if (!string.IsNullOrWhiteSpace(item.Location) && item.Location.Contains("重庆") && item.Category == 0)
  582. {
  583. count++;
  584. //if (!string.IsNullOrWhiteSpace(item.Client) && (item.Client.Contains("大学") || item.Client.Contains("学院")))
  585. {
  586. updateid.Add(item.Id);
  587. }
  588. }
  589. }
  590. var updateCount = _sqlSugar.Updateable<Crm_NewClientData>().Where(x => updateid.Contains(x.Id))
  591. .SetColumns(x => new Crm_NewClientData { Category = 456 }).ExecuteCommand();
  592. return Ok( new
  593. {
  594. notCount = count,
  595. updateCount = updateCount
  596. });
  597. }
  598. [HttpPost]
  599. public IActionResult InsertData()
  600. {
  601. string sql = $@"SELECT * FROM [dbo].[Crm_NewClientData] WHERE ID IN (
  602. --所有四川省域的
  603. select Id from [dbo].[Crm_NewClientData] where ISDEL = 0 AND Lvlid IN (
  604. select S.Id from Sys_SetData S
  605. where STid = 33 and isdel = 0 and
  606. (Name like '%四%川%' or Name like '%成%都%')
  607. )
  608. ) AND IsDel = 0
  609. AND ID IN (
  610. SELECT NewClientDataId FROM [dbo].[Crm_ClientDataAndUser]
  611. WHERE NewClientDataId IN (
  612. --所有单独数据
  613. SELECT NewClientDataId FROM [dbo].[Crm_ClientDataAndUser]
  614. WHERE ISDEL = 0
  615. GROUP BY NewClientDataId
  616. HAVING COUNT(NewClientDataId) = 1
  617. ) AND IsDel = 0 AND UsersId = 21
  618. )";
  619. var clientList = _sqlSugar.SqlQueryable<Crm_NewClientData>(sql).Select(x => x.Id).ToList().Select(x => new Crm_ClientDataAndUser
  620. {
  621. NewClientDataId = x,
  622. usersId = 330,
  623. CreateTime = DateTime.Now,
  624. CreateUserId = 235,
  625. IsDel = 0,
  626. }).ToList();
  627. var insertCount = _sqlSugar.Insertable(clientList).ExecuteCommand();
  628. return Ok(insertCount);
  629. }
  630. [HttpPost]
  631. public IActionResult ExportData()
  632. {
  633. var soure = _sqlSugar.Queryable<Crm_NewClientData>()
  634. .InnerJoin<Crm_ClientDataAndUser>((a, b) => b.NewClientDataId == a.Id && b.IsDel == 0)
  635. .Where((a, b) => a.IsDel == 0 && b.usersId == 95)
  636. .Select((a, b) => a)
  637. .ToList();
  638. foreach (var item in soure)
  639. {
  640. EncryptionProcessor.DecryptProperties(item);
  641. }
  642. // 创建WorkbookDesigner对象
  643. WorkbookDesigner designer = new WorkbookDesigner();
  644. // 加载模板文件(包含智能标记)
  645. designer.Workbook = new Workbook("C:\\Users\\PC\\Desktop\\111.xlsx");
  646. // 设置数据源,这里假设你的List集合名为listData
  647. designer.SetDataSource("ListData", soure);
  648. // 处理智能标记以将数据填充到工作表中
  649. designer.Process();
  650. // 保存Excel文件
  651. designer.Workbook.Save("C:\\Users\\PC\\Desktop\\111000.xlsx");
  652. return Ok(1);
  653. }
  654. [HttpPost]
  655. public IActionResult DeleteData()
  656. {
  657. var soure = _sqlSugar.Queryable<Crm_NewClientData>()
  658. .InnerJoin<Crm_ClientDataAndUser>((a, b) => b.NewClientDataId == a.Id && b.IsDel == 0)
  659. .Where((a, b) => a.IsDel == 0 && b.usersId == 330)
  660. .Select((a, b) => b.Id)
  661. .ToList();
  662. var count = _sqlSugar.Updateable<Crm_ClientDataAndUser>()
  663. .Where(u => soure.Contains(u.Id) && u.IsDel == 0)
  664. .SetColumns(x => new Crm_ClientDataAndUser
  665. {
  666. DeleteTime = DateTime.Now.ToString(),
  667. DeleteUserId = 235,
  668. IsDel = 1
  669. }).ExecuteCommand();
  670. return Ok(count);
  671. }
  672. [HttpPost]
  673. public IActionResult InsertDataJiang()
  674. {
  675. var list_DB = _sqlSugar.Queryable<Crm_NewClientData>().Where(x => x.IsDel == 0).ToList();
  676. foreach (var item in list_DB)
  677. {
  678. EncryptionProcessor.DecryptProperties(item);
  679. }
  680. list_DB = list_DB.Where(x => !string.IsNullOrWhiteSpace(x.Client) &&(x.Client.Contains("学院") || x.Client.Contains("大学"))).ToList();
  681. var arr = list_DB.Select(x => x.Id).ToList().Select(x => new Crm_ClientDataAndUser
  682. {
  683. NewClientDataId = x,
  684. usersId = 327,
  685. CreateTime = DateTime.Now,
  686. CreateUserId = 235,
  687. IsDel = 0,
  688. }).ToList();
  689. var insertCount = _sqlSugar.Insertable(arr).ExecuteCommand();
  690. return Ok(insertCount);
  691. }
  692. #endregion
  693. /// <summary>
  694. /// 客户资料 操作记录记录查询
  695. /// </summary>
  696. /// <param name="dto"></param>
  697. /// <returns></returns>
  698. [HttpGet]
  699. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  700. public async Task<IActionResult> NewClientDataOperatingRrecord(int userId)
  701. {
  702. var datas = await _sqlSugar.Queryable<Crm_TableOperationRecord, Crm_NewClientData, Sys_Users>((tor, ncd, u) =>
  703. new JoinQueryInfos(
  704. JoinType.Left, tor.DataId == ncd.Id,
  705. JoinType.Left, tor.CreateUserId == u.Id
  706. ))
  707. .Where((tor, ncd, u) => tor.TableName == "Crm_NewClientData" && tor.CreateUserId == userId && (int)tor.OperationItem > 1)
  708. .Select((tor, ncd, u) => new
  709. {
  710. tor.PortType,
  711. tor.OperationItem,
  712. tor.DataId,
  713. ncd.Client,
  714. u.CnName,
  715. tor.CreateTime
  716. }).ToListAsync();
  717. var view = new List<dynamic>();
  718. foreach (var item in datas)
  719. {
  720. var text = item.OperationItem.GetDescription();
  721. view.Add(new {
  722. Client = AesEncryptionHelper.Decrypt(item.Client),
  723. item.PortType,
  724. item.OperationItem,
  725. text = text,
  726. item.DataId,
  727. item.CnName,
  728. item.CreateTime
  729. });
  730. }
  731. return Ok(JsonView(view));
  732. }
  733. }
  734. }