MarketCustomerResourcesController.cs 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318
  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. using OASystem.Domain.Attributes;
  14. using EyeSoft.Extensions;
  15. using OASystem.RedisRepository;
  16. using System.Linq.Expressions;
  17. namespace OASystem.API.Controllers
  18. {
  19. /// <summary>
  20. /// 市场客户资料
  21. /// </summary>
  22. [Route("api/[controller]/[action]")]
  23. public class MarketCustomerResourcesController : ControllerBase
  24. {
  25. private readonly NewClientDataRepository _clientDataRepository;
  26. private readonly SqlSugarClient _sqlSugar;
  27. private string keyName = "newClient_SearchKey";
  28. /// <summary>
  29. /// 初始化
  30. /// </summary>
  31. public MarketCustomerResourcesController(NewClientDataRepository clientDataRepository, SqlSugarClient sqlSugar)
  32. {
  33. this._clientDataRepository = clientDataRepository;
  34. _sqlSugar = sqlSugar;
  35. }
  36. /// <summary>
  37. /// 客户资料数据
  38. /// 基础数据
  39. /// </summary>
  40. /// <returns></returns>
  41. [HttpPost]
  42. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  43. public async Task<IActionResult> MarketCustomerInit(MarketCustomerInitDto dto)
  44. {
  45. JsonView jw = new JsonView();
  46. try
  47. {
  48. Result resultData = await _clientDataRepository._Init(dto);
  49. if (resultData.Code == 0)
  50. {
  51. jw = JsonView(true, "查询成功!", resultData.Data);
  52. }
  53. else
  54. {
  55. jw = JsonView(false, resultData.Msg);
  56. }
  57. }
  58. catch (Exception)
  59. {
  60. jw = JsonView(false, "程序错误!");
  61. }
  62. return Ok(jw);
  63. }
  64. /// <summary>
  65. /// 查询客户资料数据
  66. /// </summary>
  67. /// <returns></returns>
  68. [HttpPost]
  69. [ApiLog("Crm_NewClientData", OperationEnum.List)]
  70. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  71. public async Task<IActionResult> QueryNewClientData(NewClientDataQueryDto dto)
  72. {
  73. #region 参数验证
  74. if (dto.OperationUserId < 0)
  75. return Ok(JsonView(false, "请传入有效的OperationUserId参数!"));
  76. if (dto.PortType < 0)
  77. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  78. #endregion
  79. JsonView jw = new JsonView();
  80. try
  81. {
  82. Result resultData = await _clientDataRepository.QueryNewClientData(dto);
  83. if (resultData.Code == 0)
  84. {
  85. #region 客户资料表操作记录
  86. //await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.NoOperation, dto.OperationUserId, 0, "");
  87. #endregion
  88. jw = JsonView(true, resultData.Msg, resultData.Data);
  89. }
  90. else
  91. {
  92. jw = JsonView(false, resultData.Msg);
  93. }
  94. }
  95. catch (Exception)
  96. {
  97. jw = JsonView(false, "程序错误!");
  98. }
  99. return Ok(jw);
  100. }
  101. /// <summary>
  102. /// 客户资料数据
  103. /// Details
  104. /// </summary>
  105. /// <returns></returns>
  106. [HttpPost]
  107. [ApiLog("Crm_NewClientData", OperationEnum.Details)]
  108. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  109. public async Task<IActionResult> PostNewClientDataDetails(NewClientDataDetailsDto dto)
  110. {
  111. #region 参数验证
  112. if (dto.Id < 0)
  113. return Ok(JsonView(false, "请传入有效的Id参数!"));
  114. if (dto.UserId < 0)
  115. return Ok(JsonView(false, "请传入有效的UserId参数!"));
  116. if (dto.PortType < 0)
  117. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  118. #endregion
  119. JsonView jw = new JsonView();
  120. try
  121. {
  122. Result resultData = await _clientDataRepository._Details(dto.PortType, dto.Id);
  123. if (resultData.Code == 0)
  124. {
  125. #region 客户资料表操作记录
  126. //await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Details, dto.UserId, dto.Id, "");
  127. #endregion
  128. jw = JsonView(true, "查询成功!", resultData.Data);
  129. }
  130. else
  131. {
  132. jw = JsonView(false, resultData.Msg);
  133. }
  134. }
  135. catch (Exception)
  136. {
  137. jw = JsonView(false, "程序错误!");
  138. }
  139. return Ok(jw);
  140. }
  141. /// <summary>
  142. /// 客户资料操作(Status:1.新增,2.修改)
  143. /// </summary>
  144. /// <param name="dto"></param>
  145. /// <returns></returns>
  146. [HttpPost]
  147. [ApiLog("Crm_NewClientData", OperationEnum.NoOperation)]
  148. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  149. public async Task<IActionResult> NewClientOp(NewClientOpDto dto)
  150. {
  151. #region 参数验证
  152. if (dto.CreateUserId < 0)
  153. {
  154. return Ok(JsonView(false, "请传入有效的CreateUserId参数!"));
  155. }
  156. if (dto.PortType < 0)
  157. {
  158. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  159. }
  160. #endregion
  161. try
  162. {
  163. Domain.Result result = await _clientDataRepository.NewClientOp(dto);
  164. if (result.Code != 0)
  165. {
  166. return Ok(JsonView(false, result.Msg));
  167. }
  168. #region 客户资料操作记录
  169. //OperationEnum operationEnum = OperationEnum.NoOperation;
  170. //if (dto.Status == 1)
  171. //{
  172. // operationEnum = OperationEnum.Add;
  173. // dto.Id = Convert.ToInt32(result.Data);
  174. //}
  175. //else if (dto.Status == 2) operationEnum = OperationEnum.Edit;
  176. //await GeneralMethod.NewClientOperationRecord(dto.PortType, operationEnum, dto.CreateUserId, dto.Id, "");
  177. #endregion
  178. //this.keyName += "_" + dto.CreateUserId;
  179. //var exists = await RedisFactory.CreateRedisRepository().KeyExistsAsync(keyName);
  180. //if (exists) await RedisFactory.CreateRedisRepository().KeyDeleteAsync(keyName);
  181. return Ok(JsonView(true, result.Msg + "Id:" + dto.Id));
  182. }
  183. catch (Exception ex)
  184. {
  185. return Ok(JsonView(false, "程序错误!Msg:" + ex.Message));
  186. }
  187. }
  188. /// <summary>
  189. /// 新客户资料操作(删除)
  190. /// </summary>
  191. /// <param name="dto"></param>
  192. /// <returns></returns>
  193. [HttpPost]
  194. [ApiLog("Crm_NewClientData", OperationEnum.Del)]
  195. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  196. public async Task<IActionResult> NewClientDel(DelBaseDto dto)
  197. {
  198. #region 参数验证
  199. if (dto.Id < 0)
  200. {
  201. return Ok(JsonView(false, "请传入有效的Id参数!"));
  202. }
  203. if (dto.DeleteUserId < 0)
  204. {
  205. return Ok(JsonView(false, "请传入有效的DeleteUserId参数!"));
  206. }
  207. if (dto.PortType < 0)
  208. {
  209. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  210. }
  211. #endregion
  212. var res = await _clientDataRepository.DelNewClientData(dto);
  213. if (res.Code != 0)
  214. {
  215. return Ok(JsonView(false, "删除失败"));
  216. }
  217. #region 客户资料表操作记录
  218. //await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Del, dto.DeleteUserId, dto.Id, "");
  219. #endregion
  220. //this.keyName += "_" + dto.DeleteUserId;
  221. //var exists = await RedisFactory.CreateRedisRepository().KeyExistsAsync(keyName);
  222. //if (exists) await RedisFactory.CreateRedisRepository().KeyDeleteAsync(keyName);
  223. return Ok(JsonView(true, "删除成功!"));
  224. }
  225. /// <summary>
  226. /// 获取下拉列表数据和单条数据信息
  227. /// </summary>
  228. /// <param name="dto"></param>
  229. /// <returns></returns>
  230. [HttpPost]
  231. [ApiLog("Crm_NewClientData", OperationEnum.Details)]
  232. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  233. public async Task<IActionResult> QuerySelectAndSingleData(QuerySingleDto dto)
  234. {
  235. JsonView jw = new JsonView();
  236. var result = await _clientDataRepository.QuerySelectAndSingleData(dto);
  237. if (result.Code == 0)
  238. {
  239. #region 客户资料表操作记录
  240. //await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Details, dto.UserId, dto.Id, "");
  241. #endregion
  242. jw = JsonView(true, result.Msg, result.Data);
  243. }
  244. else
  245. {
  246. jw = JsonView(false, result.Msg);
  247. }
  248. return Ok(jw);
  249. }
  250. /// <summary>
  251. /// 获取现有负责人
  252. /// </summary>
  253. /// <returns></returns>
  254. [HttpPost]
  255. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  256. public async Task<IActionResult> QueryUserSelect()
  257. {
  258. Result resTable = _clientDataRepository.QueryUserSelect();
  259. return Ok(JsonView(true, resTable.Msg, resTable.Data));
  260. }
  261. /// <summary>
  262. /// 获取出团数据
  263. /// </summary>
  264. /// <returns></returns>
  265. [HttpPost]
  266. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  267. public async Task<IActionResult> QueryNumberGroups()
  268. {
  269. var result = await _clientDataRepository.QueryNumberGroups();
  270. if (result.Code != 0)
  271. {
  272. return Ok(JsonView(false, result.Msg));
  273. }
  274. return Ok(JsonView(true, result.Msg, result.Data));
  275. }
  276. /// <summary>
  277. /// 新客户资料操作
  278. /// 批量分配
  279. /// </summary>
  280. /// <param name="dto"></param>
  281. /// <returns></returns>
  282. [HttpPost]
  283. [ApiLog("Crm_NewClientData", OperationEnum.BatchAssignment)]
  284. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  285. public async Task<IActionResult> PostBatchAssignment(BatchAssignmentDto dto)
  286. {
  287. #region 参数验证
  288. if (dto.UserId < 0)
  289. {
  290. return Ok(JsonView(false, "请传入有效的UserId参数!"));
  291. }
  292. if (dto.PortType < 0)
  293. {
  294. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  295. }
  296. #endregion
  297. var res = await _clientDataRepository._BatchAssignment(dto);
  298. if (res.Code != 0)
  299. {
  300. return Ok(JsonView(false, res.Msg));
  301. }
  302. return Ok(JsonView(true, "操作成功!"));
  303. }
  304. private Dictionary<int, List<int>> MCRSetting()
  305. {
  306. Dictionary<int, List<int>> keyValuePairs = new Dictionary<int, List<int>>();
  307. keyValuePairs.Add(419, new List<int>() //四川
  308. {
  309. 376,377,378,381,382,387,388,389,390,753,754,1296,1303
  310. });
  311. keyValuePairs.Add(420, new List<int>() //云南
  312. {
  313. 407,408,409,410,449,451,452,453,567,754,1297,1304
  314. });
  315. keyValuePairs.Add(421, new List<int>() { 424, 425, 426, 427, 428, 429, 754,1298, 1305,1307,1306 }); // 贵州
  316. keyValuePairs.Add(422, new List<int>() { 415, 416, 754,1317,1316,1315, 455,1321, 1320, 1319, 1318 }); // 西藏
  317. keyValuePairs.Add(423, new List<int>() { 417, 418, 454, 456, 754, 1313, 1314 }); // 重庆
  318. keyValuePairs.Add(578, new List<int>() { 581, 582, 583, 754,1299,1300 }); // 青海
  319. keyValuePairs.Add(605, new List<int>() { 588, 589, 590, 591, 592, 593, 754,1301,1310,1309,1308 }); // 陕西
  320. keyValuePairs.Add(606, new List<int>() { 597, 598, 599, 600, 601, 602, 603, 604, 754,1324,1323,1322 }); // 宁夏
  321. keyValuePairs.Add(625, new List<int>() { 617, 618, 619, 620, 621, 622, 622, 623, 624, 754,1302,1312,1311 }); // 甘肃
  322. keyValuePairs.Add(634, new List<int>() { 630, 631, 632, 633, 754 }); // 新疆
  323. return keyValuePairs;
  324. }
  325. private Dictionary<int, List<int>> MCRSecondSetting()
  326. {
  327. Dictionary<int, List<int>> keyValuePairs = new Dictionary<int, List<int>>();
  328. // 四川
  329. keyValuePairs.Add(349, new List<int>() { 376, 378, 381, 387, 389, 1296 }); // 四川省级
  330. keyValuePairs.Add(350, new List<int>() { 377, 382, 388, 390, 1303 }); // 成都市级
  331. keyValuePairs.Add(348, new List<int>() { 387 }); // 四川地市州 - Explicitly assigning to ensure all source2 IDs are used
  332. keyValuePairs.Add(701, new List<int>() { 388 }); // 成都区市县
  333. // 云南
  334. keyValuePairs.Add(399, new List<int>() { 407, 408, 409, 410, 451 }); // 云南省级
  335. keyValuePairs.Add(400, new List<int>() { 449, 452, 453, 1297, 1304 }); // 昆明市级
  336. keyValuePairs.Add(450, new List<int>() { 410 }); // 云南地市州
  337. keyValuePairs.Add(566, new List<int>() { 567 }); // 昆明区市县
  338. // 贵州
  339. keyValuePairs.Add(401, new List<int>() { 424, 426, 427, 428, 1298 }); // 贵州省级
  340. keyValuePairs.Add(402, new List<int>() { 425, 429, 1306, 1307, 1305 }); // 贵阳市级
  341. keyValuePairs.Add(414, new List<int>() { 428 }); // 贵州地市州
  342. //keyValuePairs.Add(1305, new List<int>() { /* Add relevant IDs if available */ }); // 贵阳区市县 - Placeholder for now
  343. // 重庆
  344. keyValuePairs.Add(403, new List<int>() { 417, 418, 454, 456, 1314 }); // 重庆市级
  345. keyValuePairs.Add(404, new List<int>() { 1313 }); // 重庆区县 - No direct match in source1
  346. // 西藏
  347. keyValuePairs.Add(405, new List<int>() { 415, 1317, 1316, 1315 }); // 西藏自治区
  348. keyValuePairs.Add(406, new List<int>() { 455, 1321, 1320, 1319, 1318 }); // 拉萨市级
  349. keyValuePairs.Add(413, new List<int>() { 416 }); // 西藏地市州
  350. // 青海
  351. keyValuePairs.Add(579, new List<int>() { 581, 582, 583, 1300 }); // 青海省级
  352. keyValuePairs.Add(580, new List<int>() { 1299 }); // 青海市州县 (Includes 地市州)
  353. // 陕西
  354. keyValuePairs.Add(585, new List<int>() { 588, 589, 590, 591, 1301 }); // 陕西省级
  355. keyValuePairs.Add(586, new List<int>() { 589 }); // 陕西地市州
  356. keyValuePairs.Add(587, new List<int>() { 592, 593, 1309, 1310 , 1308 }); // 西安市级
  357. //keyValuePairs.Add(1308, new List<int>() { /* Add relevant IDs if available */ }); // 西安区市县 - Placeholder
  358. // 宁夏
  359. keyValuePairs.Add(594, new List<int>() { 597, 598, 599, 600, 601, 1322 }); // 宁夏自治区 (Includes 地市州 and 区级)
  360. keyValuePairs.Add(595, new List<int>() { 597 }); // 宁夏地市州
  361. keyValuePairs.Add(596, new List<int>() { 598, 599, 600, 603, 604, 602, 1323, 1324 }); // 银川市级 (Includes 区级)
  362. //keyValuePairs.Add(602, new List<int>()); // 银川区市县 - No direct match, but could be considered covered by "区级"
  363. // 甘肃
  364. keyValuePairs.Add(614, new List<int>() { 617, 618, 619, 620, 621, 1302 }); // 甘肃省级
  365. keyValuePairs.Add(615, new List<int>() { 618 }); // 甘肃地市州
  366. keyValuePairs.Add(616, new List<int>() { 622, 623, 624, 1312, 1311 }); // 兰州市级
  367. //keyValuePairs.Add(1311, new List<int>() { /* Add relevant IDs if available */ }); // 兰州区市县 - Placeholder
  368. // 新疆
  369. keyValuePairs.Add(627, new List<int>() { 630, 631, 632 , 1327,1326 ,1325 }); // 新疆自治区级
  370. keyValuePairs.Add(628, new List<int>() { 1326 }); // 新疆地市州 - No direct match
  371. keyValuePairs.Add(629, new List<int>() { 633,1331,1330,1329 ,1328 }); // 乌鲁木齐市级
  372. // 中央直属企业 (Special case)
  373. keyValuePairs.Add(351, new List<int>() { 754 }); // Using "未分级" for 中央直属企业
  374. return keyValuePairs;
  375. }
  376. private Dictionary<int, List<int>> MCRLvSetting()
  377. {
  378. var keyValuePairs = new Dictionary<int, List<int>>();
  379. // 四川 (419)
  380. keyValuePairs.Add(419, new List<int>() { 348, 349, 350, 701 }); // Includes all Sichuan-related IDs from source2
  381. // 云南 (420)
  382. keyValuePairs.Add(420, new List<int>() { 399, 400, 450, 566 }); // Includes all Yunnan-related IDs
  383. // 贵州 (421)
  384. keyValuePairs.Add(421, new List<int>() { 401, 402, 414 });
  385. // 西藏 (422)
  386. keyValuePairs.Add(422, new List<int>() { 405, 406, 413 });
  387. // 重庆 (423)
  388. keyValuePairs.Add(423, new List<int>() { 403, 404 });
  389. // 青海 (578)
  390. keyValuePairs.Add(578, new List<int>() { 579, 580, 626 }); // Includes 市州县 and 西宁市级
  391. // 陕西 (605)
  392. keyValuePairs.Add(605, new List<int>() { 585, 586, 587 });
  393. // 宁夏 (606)
  394. keyValuePairs.Add(606, new List<int>() { 594, 595, 596 });
  395. // 甘肃 (625)
  396. keyValuePairs.Add(625, new List<int>() { 614, 615, 616 });
  397. // 新疆 (634)
  398. keyValuePairs.Add(634, new List<int>() { 627, 628, 629 });
  399. // 未分级 (351) - You'll likely want to remove this as it's no longer a primary key.
  400. // keyValuePairs.Add(351, new List<int>()); //Remove this line.
  401. return keyValuePairs;
  402. }
  403. [HttpPost]
  404. public IActionResult QueryClientType(QueryClientTypeDto Dto)
  405. {
  406. var jw = JsonView(true,"获取成功!");
  407. var dic_lv = MCRLvSetting();
  408. var keyValuePairs = MCRSetting();
  409. ArrayList arr = new ArrayList();
  410. ArrayList lvArr = new ArrayList();
  411. var ids = new List<int>();
  412. var lvids = new List<int>();
  413. foreach (var item in Dto.SetDataIdArr)
  414. {
  415. if (keyValuePairs.Keys.Contains(item))
  416. {
  417. ids.AddRange(keyValuePairs[item]);
  418. }
  419. if (dic_lv.Keys.Contains(item))
  420. {
  421. lvids.AddRange(dic_lv[item]);
  422. }
  423. }
  424. arr.AddRange(_sqlSugar.Queryable<Sys_SetData>()
  425. .Where(u => ids.Contains(u.Id) && u.IsDel == 0)
  426. .Select(x => new { x.Id, x.Name , x.Remark })
  427. .ToList());
  428. if (arr.Count == 0)
  429. {
  430. arr.AddRange(_sqlSugar.Queryable<Sys_SetData>()
  431. .Where(u => u.STid == 37 && u.IsDel == 0)
  432. .Select(x => new { x.Id, x.Name, x.Remark }).ToList());
  433. }
  434. // 创建比较器实例
  435. IComparer remakeComparer = new RemakeComparer();
  436. // 使用ArrayList.Sort方法和自定义比较器对arr进行排序
  437. arr.Sort(remakeComparer);
  438. var rangelv = _sqlSugar.Queryable<Sys_SetData>()
  439. .Where(u => lvids.Contains(u.Id) && u.IsDel == 0)
  440. .Select(x => new { x.Id, x.Name })
  441. .ToList();
  442. lvArr.AddRange(rangelv);
  443. if (lvArr.Count == 0)
  444. {
  445. lvArr.AddRange(_sqlSugar.Queryable<Sys_SetData>()
  446. .Where(u => u.STid == 33 && u.IsDel == 0)
  447. .Select(x => new { x.Id, x.Name}).ToList());
  448. }
  449. jw.Data = new
  450. {
  451. TypeArr = arr,
  452. LvArr = lvArr,
  453. };
  454. return Ok(jw);
  455. }
  456. [HttpPost]
  457. public IActionResult QueryClientTypeSecond(QueryClientTypeDto Dto)
  458. {
  459. var jw = JsonView(true, "获取成功!");
  460. var keyValuePairs = MCRSecondSetting();
  461. ArrayList arr = new ArrayList();
  462. var ids = new List<int>();
  463. foreach (var item in Dto.SetDataIdArr)
  464. {
  465. if (keyValuePairs.Keys.Contains(item))
  466. {
  467. ids.AddRange(keyValuePairs[item]);
  468. }
  469. }
  470. arr.AddRange(_sqlSugar.Queryable<Sys_SetData>()
  471. .Where(u => ids.Contains(u.Id) && u.IsDel == 0)
  472. .Select(x => new { x.Id, x.Name, x.Remark })
  473. .ToList());
  474. if (arr.Count == 0)
  475. {
  476. arr.AddRange(_sqlSugar.Queryable<Sys_SetData>()
  477. .Where(u => u.STid == 37 && u.IsDel == 0)
  478. .Select(x => new { x.Id, x.Name, x.Remark }).ToList());
  479. }
  480. // 创建比较器实例
  481. IComparer remakeComparer = new RemakeComparer();
  482. // 使用ArrayList.Sort方法和自定义比较器对arr进行排序
  483. arr.Sort(remakeComparer);
  484. jw.Data = arr;
  485. return Ok(jw);
  486. }
  487. /// <summary>
  488. /// 客户资料数据 全信息导出 excel 下载
  489. /// </summary>
  490. /// <param name="dto"></param>
  491. /// <returns></returns>
  492. [HttpPost]
  493. [ApiLog("Crm_NewClientData", OperationEnum.Download)]
  494. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  495. public async Task<IActionResult> NewClientDataExcelDownload(NewClientDataExcelDownloadDto dto)
  496. {
  497. #region 参数验证
  498. if (dto.OperationUserId < 0) return Ok(JsonView(false, "请传入有效的OperationUserId参数!"));
  499. if (dto.PortType < 0) return Ok(JsonView(false, "请传入有效的PortType参数!"));
  500. if (dto.PageId < 0) return Ok(JsonView(false, "请传入有效的PageId参数!"));
  501. #endregion
  502. #region 页面操作权限验证
  503. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.OperationUserId, dto.PageId);
  504. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权!"));
  505. #endregion
  506. var dt = await _clientDataRepository.NewClientDataExcelDownload(dto);
  507. if (dt != null)
  508. {
  509. string tempPath = (AppSettingsHelper.Get("ExcelBasePath") + "Template/公司客户资料导出模板.xlsx");
  510. var designer = new WorkbookDesigner();
  511. designer.Workbook = new Workbook(tempPath);
  512. designer.SetDataSource("NCDDT", dt);
  513. designer.Process();
  514. //文件名
  515. string fileName = $"公司客户资料(全信息导出){DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
  516. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + "NewClientDataExcelDownload/" + fileName);
  517. string url = AppSettingsHelper.Get("ExcelBaseUrl") + "Office/Excel/NewClientDataExcelDownload/" + fileName;
  518. #region 客户资料表操作记录
  519. var respose = JsonView(true, "成功", url);
  520. //var paramData = new
  521. //{
  522. // APIName = @"MarketCustomerResources/NewClientDataExcelDownload",
  523. // RequestParam = dto,
  524. // ResposeParam = respose
  525. //};
  526. //await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Download, dto.OperationUserId, 0, JsonConvert.SerializeObject(paramData));
  527. #endregion
  528. return Ok(respose);
  529. }
  530. return Ok(JsonView(false));
  531. }
  532. /// <summary>
  533. /// 客户资料数据 分权限导出 excel 下载
  534. /// </summary>
  535. /// <param name="dto"></param>
  536. /// <returns></returns>
  537. [HttpPost]
  538. [ApiLog("Crm_NewClientData", OperationEnum.Download)]
  539. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  540. public async Task<IActionResult> NewClientDataAuthorityExcelDownload(NewClientDataExcelDownloadDto dto)
  541. {
  542. #region 参数验证
  543. if (dto.OperationUserId < 0) return Ok(JsonView(false, "请传入有效的OperationUserId参数!"));
  544. if (dto.PortType < 0) return Ok(JsonView(false, "请传入有效的PortType参数!"));
  545. if (dto.PageId < 0) return Ok(JsonView(false, "请传入有效的PageId参数!"));
  546. #endregion
  547. #region 页面操作权限验证
  548. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.OperationUserId, dto.PageId);
  549. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权!"));
  550. #endregion
  551. var dt = await _clientDataRepository.NewClientDataExcelDownload(dto);
  552. if (dt != null)
  553. {
  554. string tempPath = (AppSettingsHelper.Get("ExcelBasePath") + "Template/公司客户资料分权限导出模板.xlsx");
  555. var designer = new WorkbookDesigner();
  556. designer.Workbook = new Workbook(tempPath);
  557. designer.SetDataSource("NCDDT", dt);
  558. designer.Process();
  559. //文件名
  560. string fileName = $"公司客户资料(分权限导出){DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
  561. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + "NewClientDataExcelDownload/" + fileName);
  562. string url = AppSettingsHelper.Get("ExcelBaseUrl") + "Office/Excel/NewClientDataExcelDownload/" + fileName;
  563. var respose = JsonView(true, "成功", url);
  564. return Ok(respose);
  565. }
  566. return Ok(JsonView(false));
  567. }
  568. /// <summary>
  569. /// 客户资料数据 历史记录 Init
  570. /// </summary>
  571. /// <param name="dto"></param>
  572. /// <returns></returns>
  573. [HttpPost]
  574. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  575. public async Task<IActionResult> NewClientDataRecordInit(NewClientDataRecordInitDto dto)
  576. {
  577. #region 参数验证
  578. if (dto.UserId < 0) return Ok(JsonView(false, MsgTips.UserId));
  579. if (!SharingStaticData.PortTypes.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  580. if (dto.PageId < 0) return Ok(JsonView(false, MsgTips.PageId));
  581. #endregion
  582. #region 页面操作权限验证
  583. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  584. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  585. #endregion
  586. var enumfiltrates = new string[] { "NoOperation", "Audit", "Login" };
  587. var operations = EnumHelper.GetEnumDescriptions(typeof(OperationEnum), enumfiltrates);
  588. var operation1 = new List<dynamic>();
  589. foreach (var item in operations)
  590. {
  591. operation1.Add(new { value = item.Key, text = item.Value });
  592. }
  593. object userDatas = Array.Empty<object>();
  594. if (dto.UserId == 21)
  595. {
  596. var userIds = await _sqlSugar.Queryable<Crm_ClientDataAndUser>().Where(x => x.IsDel == 0).Select(x => x.usersId).Distinct().ToListAsync();
  597. if (userIds.Any())
  598. {
  599. userDatas = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && userIds.Contains(x.Id)).Select(x => new { value = x.Id, text = x.CnName }).ToListAsync();
  600. }
  601. }
  602. var data = new {
  603. operations = operation1,
  604. userDatas = userDatas
  605. };
  606. return Ok(JsonView(data));
  607. }
  608. /// <summary>
  609. /// 客户资料数据 历史记录
  610. /// </summary>
  611. /// <param name="dto"></param>
  612. /// <returns></returns>
  613. [HttpPost]
  614. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  615. public async Task<IActionResult> NewClientDataRecord(NewClientDataRecordDto dto)
  616. {
  617. #region 参数验证
  618. if (dto.UserId < 0) return Ok(JsonView(false, MsgTips.UserId));
  619. if (!SharingStaticData.PortTypes.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  620. if (dto.PageId < 0) return Ok(JsonView(false, MsgTips.PageId));
  621. #endregion
  622. #region 页面操作权限验证
  623. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  624. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  625. #endregion
  626. return Ok(await _clientDataRepository.NewClientDataRecord(dto));
  627. }
  628. #region 修改数据
  629. //[HttpPost]
  630. //public IActionResult SynchronizationData()
  631. //{
  632. // var keyValuePairs = new Dictionary<int, List<string>>
  633. // {
  634. // { 5, new List<string> { "省级部门", "省级单位" } },
  635. // { 10, new List<string> { "市州" } },
  636. // { 15, new List<string> { "省属国企" } },
  637. // { 20, new List<string> { "省属学校", "省属高校" } },
  638. // { 25, new List<string> { "省级行业协会", "省级社团", "省级联合会" , "省属行业协会", "民营企业", "地方国企" } },
  639. // { 30, new List<string> { "市级部门", "市级单位" } },
  640. // { 35, new List<string> { "区市县" } },
  641. // { 40, new List<string> { "市级国企", "市属国企" } },
  642. // { 45, new List<string> { "市属学校", "市属高校" } },
  643. // { 50, new List<string> { "市级行业协会", "市级社团", "市级联合会" } }
  644. // };
  645. // var setting = MCRSetting();
  646. // var arr = new List<List<Sys_SetData>>();
  647. // foreach (var item in setting.Keys)
  648. // {
  649. // var setDataList_DB = _sqlSugar.Queryable<Sys_SetData>()
  650. // .Where(x => x.IsDel == 0 && setting[item].Contains(x.Id))
  651. // .ToList();
  652. // foreach (var setData in setDataList_DB)
  653. // {
  654. // foreach (var lv in keyValuePairs.Keys)
  655. // {
  656. // var islv = keyValuePairs[lv].Where(x => setData.Name.Contains(x)).Count() > 0;
  657. // if (islv)
  658. // {
  659. // setData.Remark = lv.ToString();
  660. // }
  661. // }
  662. // }
  663. // arr.Add(setDataList_DB);
  664. // }
  665. // _sqlSugar.Updateable(arr.SelectMany(x => x).ToList()).UpdateColumns(x => new
  666. // {
  667. // x.Remark
  668. // }).ExecuteCommand();
  669. // return Ok(arr);
  670. //}
  671. [HttpPost]
  672. public IActionResult QueryData()
  673. {
  674. var db = _sqlSugar.Queryable<Crm_NewClientData>()
  675. .Where(x => x.IsDel == 0)
  676. .Select(x => new Crm_NewClientData
  677. {
  678. Id = x.Id,
  679. Client = x.Client,
  680. Category = x.Category,
  681. Location = x.Location,
  682. }).ToList();
  683. var count = 0;
  684. var updateid = new List<int>();
  685. foreach (var item in db)
  686. {
  687. EncryptionProcessor.DecryptProperties(item);
  688. if (!string.IsNullOrWhiteSpace(item.Location) && item.Location.Contains("重庆") && item.Category == 0)
  689. {
  690. count++;
  691. //if (!string.IsNullOrWhiteSpace(item.Client) && (item.Client.Contains("大学") || item.Client.Contains("学院")))
  692. {
  693. updateid.Add(item.Id);
  694. }
  695. }
  696. }
  697. var updateCount = _sqlSugar.Updateable<Crm_NewClientData>().Where(x => updateid.Contains(x.Id))
  698. .SetColumns(x => new Crm_NewClientData { Category = 456 }).ExecuteCommand();
  699. return Ok( new
  700. {
  701. notCount = count,
  702. updateCount = updateCount
  703. });
  704. }
  705. [HttpPost]
  706. public IActionResult InsertData()
  707. {
  708. string sql = $@"SELECT * FROM [dbo].[Crm_NewClientData] WHERE ID IN (
  709. --所有四川省域的
  710. select Id from [dbo].[Crm_NewClientData] where ISDEL = 0 AND Lvlid IN (
  711. select S.Id from Sys_SetData S
  712. where STid = 33 and isdel = 0 and
  713. (Name like '%四%川%' or Name like '%成%都%')
  714. )
  715. ) AND IsDel = 0
  716. AND ID IN (
  717. SELECT NewClientDataId FROM [dbo].[Crm_ClientDataAndUser]
  718. WHERE NewClientDataId IN (
  719. --所有单独数据
  720. SELECT NewClientDataId FROM [dbo].[Crm_ClientDataAndUser]
  721. WHERE ISDEL = 0
  722. GROUP BY NewClientDataId
  723. HAVING COUNT(NewClientDataId) = 1
  724. ) AND IsDel = 0 AND UsersId = 21
  725. )";
  726. var clientList = _sqlSugar.SqlQueryable<Crm_NewClientData>(sql).Select(x => x.Id).ToList().Select(x => new Crm_ClientDataAndUser
  727. {
  728. NewClientDataId = x,
  729. usersId = 330,
  730. CreateTime = DateTime.Now,
  731. CreateUserId = 235,
  732. IsDel = 0,
  733. }).ToList();
  734. var insertCount = _sqlSugar.Insertable(clientList).ExecuteCommand();
  735. return Ok(insertCount);
  736. }
  737. [HttpPost]
  738. public IActionResult ExportData()
  739. {
  740. var soure = _sqlSugar.Queryable<Crm_NewClientData>()
  741. .InnerJoin<Crm_ClientDataAndUser>((a, b) => b.NewClientDataId == a.Id && b.IsDel == 0)
  742. .Where((a, b) => a.IsDel == 0 && b.usersId == 95)
  743. .Select((a, b) => a)
  744. .ToList();
  745. foreach (var item in soure)
  746. {
  747. EncryptionProcessor.DecryptProperties(item);
  748. }
  749. // 创建WorkbookDesigner对象
  750. WorkbookDesigner designer = new WorkbookDesigner();
  751. // 加载模板文件(包含智能标记)
  752. designer.Workbook = new Workbook("C:\\Users\\PC\\Desktop\\111.xlsx");
  753. // 设置数据源,这里假设你的List集合名为listData
  754. designer.SetDataSource("ListData", soure);
  755. // 处理智能标记以将数据填充到工作表中
  756. designer.Process();
  757. // 保存Excel文件
  758. designer.Workbook.Save("C:\\Users\\PC\\Desktop\\111000.xlsx");
  759. return Ok(1);
  760. }
  761. [HttpPost]
  762. public IActionResult DeleteData()
  763. {
  764. var soure = _sqlSugar.Queryable<Crm_NewClientData>()
  765. .InnerJoin<Crm_ClientDataAndUser>((a, b) => b.NewClientDataId == a.Id && b.IsDel == 0)
  766. .Where((a, b) => a.IsDel == 0 && b.usersId == 330)
  767. .Select((a, b) => b.Id)
  768. .ToList();
  769. var count = _sqlSugar.Updateable<Crm_ClientDataAndUser>()
  770. .Where(u => soure.Contains(u.Id) && u.IsDel == 0)
  771. .SetColumns(x => new Crm_ClientDataAndUser
  772. {
  773. DeleteTime = DateTime.Now.ToString(),
  774. DeleteUserId = 235,
  775. IsDel = 1
  776. }).ExecuteCommand();
  777. return Ok(count);
  778. }
  779. [HttpPost]
  780. public IActionResult ReassignCustomers()
  781. {
  782. var user_Client = _sqlSugar.Queryable<Crm_ClientDataAndUser>()
  783. .Where(x => x.usersId == 302 && x.IsDel == 0)
  784. .Select(x=>new
  785. {
  786. x.Id,
  787. x.NewClientDataId
  788. })
  789. .ToList();
  790. var ids = user_Client.Select(x=>x.NewClientDataId).ToList();
  791. string setDataSql = $"select * from Sys_SetData where STid = 33 and isdel = 0 and (Name like '%重庆%') ";
  792. var setDataids = _sqlSugar.SqlQueryable<Sys_SetData>(setDataSql).Select(x => x.Id).ToList();
  793. var clients = _sqlSugar.Queryable<Crm_NewClientData>().Where(x => ids.Contains(x.Id) && setDataids.Contains(x.Lvlid) && x.IsDel == 0).ToList();
  794. var clients_ids = clients.Select(x=>x.Id).ToList();
  795. int updateCount = 0;
  796. _sqlSugar.BeginTran();
  797. if (clients.Count == 223)
  798. {
  799. updateCount = _sqlSugar.Updateable<Crm_ClientDataAndUser>()
  800. .Where(x => x.usersId == 302 && clients_ids.Contains(x.NewClientDataId) && x.IsDel == 0)
  801. .SetColumns( x => new Crm_ClientDataAndUser
  802. {
  803. usersId = 21
  804. })
  805. .ExecuteCommand();
  806. }
  807. if (updateCount == clients.Count)
  808. {
  809. _sqlSugar.CommitTran();
  810. }
  811. else
  812. {
  813. _sqlSugar.RollbackTran();
  814. }
  815. return Ok( new
  816. {
  817. count = clients.Count,
  818. updateCount,
  819. });
  820. }
  821. [HttpPost]
  822. public IActionResult InsertDataJiang()
  823. {
  824. var list_DB = _sqlSugar.Queryable<Crm_NewClientData>().Where(x => x.IsDel == 0).ToList();
  825. foreach (var item in list_DB)
  826. {
  827. EncryptionProcessor.DecryptProperties(item);
  828. }
  829. list_DB = list_DB.Where(x => !string.IsNullOrWhiteSpace(x.Client) &&(x.Client.Contains("学院") || x.Client.Contains("大学"))).ToList();
  830. var arr = list_DB.Select(x => x.Id).ToList().Select(x => new Crm_ClientDataAndUser
  831. {
  832. NewClientDataId = x,
  833. usersId = 327,
  834. CreateTime = DateTime.Now,
  835. CreateUserId = 235,
  836. IsDel = 0,
  837. }).ToList();
  838. var insertCount = _sqlSugar.Insertable(arr).ExecuteCommand();
  839. return Ok(insertCount);
  840. }
  841. [HttpPost]
  842. public IActionResult InsertDataGu()
  843. {
  844. string sql = @"SELECT * FROM Crm_NewClientData cncd WHERE IsDel = 0
  845. AND Lvlid in (
  846. select Id from Sys_SetData where STid = 33 and isdel = 0
  847. and (Name like '%云%南%' or Name like '%昆%明%')
  848. )";
  849. var list = _sqlSugar.SqlQueryable<Crm_NewClientData>(sql).Select(x => x.Id).ToList();
  850. var toUserList = new List<Crm_ClientDataAndUser>();
  851. foreach (var item in list)
  852. {
  853. toUserList.Add(new Crm_ClientDataAndUser
  854. {
  855. CreateTime = DateTime.Now,
  856. CreateUserId = 235,
  857. NewClientDataId = item,
  858. usersId = 364,
  859. IsDel = 0,
  860. });
  861. }
  862. var updateCount = 0;
  863. if (toUserList.Count == 327)
  864. {
  865. updateCount = _sqlSugar.Insertable(toUserList).ExecuteCommand();
  866. }
  867. return Ok(new
  868. {
  869. updateCount
  870. });
  871. }
  872. [HttpPost]
  873. public IActionResult CloneUserClient(CloneUserClientDto dto)
  874. {
  875. var list = _sqlSugar.Queryable<Crm_ClientDataAndUser>()
  876. .Where(x => x.IsDel == 0 && x.usersId == dto.UserId)
  877. .ToList();
  878. foreach (var item in list)
  879. {
  880. item.usersId = dto.ToUserId;
  881. }
  882. var count = _sqlSugar.Insertable<Crm_ClientDataAndUser>(list).ExecuteCommand();
  883. return Ok(new
  884. {
  885. count,
  886. });
  887. }
  888. #endregion
  889. /// <summary>
  890. /// 客户资料 操作记录记录查询
  891. /// </summary>
  892. /// <param name="userId"></param>
  893. /// <returns></returns>
  894. [HttpGet]
  895. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  896. public async Task<IActionResult> NewClientDataOperatingRrecord(int userId)
  897. {
  898. var datas = await _sqlSugar.Queryable<Crm_TableOperationRecord, Crm_NewClientData, Sys_Users>((tor, ncd, u) =>
  899. new JoinQueryInfos(
  900. JoinType.Left, tor.DataId == ncd.Id,
  901. JoinType.Left, tor.CreateUserId == u.Id
  902. ))
  903. .Where((tor, ncd, u) => tor.TableName == "Crm_NewClientData" && tor.CreateUserId == userId && (int)tor.OperationItem > 1)
  904. .Select((tor, ncd, u) => new
  905. {
  906. tor.PortType,
  907. tor.OperationItem,
  908. tor.DataId,
  909. ncd.Client,
  910. u.CnName,
  911. tor.CreateTime
  912. }).ToListAsync();
  913. var view = new List<dynamic>();
  914. if (datas.Any())
  915. {
  916. datas = datas.OrderByDescending(x => x.CreateTime).ToList();
  917. foreach (var item in datas)
  918. {
  919. var text = item.OperationItem.GetDescription();
  920. view.Add(new
  921. {
  922. Client = AesEncryptionHelper.Decrypt(item.Client),
  923. item.PortType,
  924. item.OperationItem,
  925. text = text,
  926. item.DataId,
  927. item.CnName,
  928. item.CreateTime
  929. });
  930. }
  931. }
  932. return Ok(JsonView(view));
  933. }
  934. [HttpPost]
  935. public async Task<IActionResult> SearchClientByKeyword(SearchClientByKeywordDto dto)
  936. {
  937. var jw = JsonView(true);
  938. var expression = Expressionable.Create<Crm_NewClientData>()
  939. .And(x=>x.IsDel == 0);
  940. this.keyName += "_" + dto.UserId;
  941. //获取个人的客户
  942. if (dto.UserId != 21)
  943. {
  944. var userList = _clientDataRepository.GetNewExistClient(dto.UserId).Select(x=>x.Id);
  945. var newClientData = _sqlSugar.Queryable<Crm_ClientDataAndUser>()
  946. .Where(x => x.IsDel == 0 && userList.Contains(x.usersId))
  947. .Select(x=>x.NewClientDataId)
  948. .Distinct()
  949. .ToList();
  950. expression = expression.And(x=> newClientData.Contains(x.Id));
  951. }
  952. var exists = false;
  953. //var exists = await RedisFactory.CreateRedisRepository().KeyExistsAsync(keyName);
  954. //if (exists) exists = await RedisFactory.CreateRedisRepository().HashFieldExistAsync(keyName, dto.Keyword);
  955. if (!exists)
  956. {
  957. string field = "Id,Client";
  958. var newClitnData = _sqlSugar.Queryable<Crm_NewClientData>()
  959. .Where(expression.ToExpression())
  960. .Select(field)
  961. .ToList();
  962. foreach (var item in newClitnData)
  963. {
  964. EncryptionProcessor.DecryptProperties(item);
  965. }
  966. var keywordArray = dto.Keyword.ToCharArray();
  967. var matches = newClitnData
  968. .Where(fullString => !string.IsNullOrWhiteSpace(fullString.Client) &&
  969. keywordArray.All(keyword => fullString.Client.Contains(keyword)))
  970. .Select(x=> new
  971. {
  972. x.Client,
  973. x.Id
  974. })
  975. .DistinctBy(x=>x.Client)
  976. .ToList();
  977. if (matches.Any())
  978. {
  979. //await RedisFactory.CreateRedisRepository().HashSetAsync(keyName, dto.Keyword, matches);
  980. //await RedisFactory.CreateRedisRepository().KeyExpireInAsync(keyName, new TimeSpan(0,1,0));
  981. jw.Data = matches;
  982. }
  983. else
  984. {
  985. jw.Code = 201;
  986. jw.Msg = "empty list";
  987. jw.Data = new List<string>(1);
  988. }
  989. }
  990. else
  991. {
  992. jw.Data = await RedisFactory.CreateRedisRepository().HashGetAsync<List<string>>(keyName, dto.Keyword);
  993. }
  994. return Ok(jw);
  995. }
  996. [HttpPost]
  997. public IActionResult InsertDataExcel(InsertDataExcelDto dto)
  998. {
  999. //string client = dto.Client;
  1000. int toUser = dto.ToUser;
  1001. var clietnArr = dto.Client;
  1002. var count = 0;
  1003. //var notClentUser = new List<int>() { 21, 95 , 327 };
  1004. var notClentUser = new List<int>() { 213,327 };
  1005. var insertList = new List<Crm_ClientDataAndUser>();
  1006. if (clietnArr.Count > 0)
  1007. {
  1008. _sqlSugar.BeginTran();
  1009. //检索相关客户数据
  1010. var newClientArr = _sqlSugar.Queryable<Crm_NewClientData>()
  1011. .Where(x => x.IsDel == 0)
  1012. .Select(x => new Crm_NewClientData
  1013. {
  1014. Client = x.Client,
  1015. Id = x.Id
  1016. })
  1017. .ToList()
  1018. .Select(x => new
  1019. {
  1020. Client = AesEncryptionHelper.Decrypt(x.Client),
  1021. Id = x.Id
  1022. });
  1023. foreach (var item in clietnArr)
  1024. {
  1025. var searchClient = newClientArr.Where(x => x.Client == item).ToList();
  1026. foreach (var clientData in searchClient)
  1027. {
  1028. var clientDataAndUser = _sqlSugar.Queryable<Crm_ClientDataAndUser>()
  1029. .Where(x => x.NewClientDataId == clientData.Id && x.IsDel == 0)
  1030. .ToList();
  1031. if (clientDataAndUser.Count > 0)
  1032. {
  1033. //清除关联表数据
  1034. _sqlSugar.Updateable<Crm_ClientDataAndUser>()
  1035. .Where(x => !notClentUser.Contains(x.usersId)
  1036. && x.NewClientDataId == clientData.Id && x.IsDel == 0)
  1037. .SetColumns(x=> new Crm_ClientDataAndUser
  1038. {
  1039. IsDel = 1,
  1040. DeleteTime = DateTime.Now.ToString(),
  1041. DeleteUserId = 235
  1042. })
  1043. .ExecuteCommand();
  1044. }
  1045. insertList.Add(new Crm_ClientDataAndUser
  1046. {
  1047. usersId = toUser,
  1048. NewClientDataId = clientData.Id,
  1049. CreateTime = DateTime.Now,
  1050. CreateUserId = 235,
  1051. });
  1052. }
  1053. }
  1054. count = _sqlSugar.Insertable(insertList).ExecuteCommand();
  1055. _sqlSugar.CommitTran();
  1056. }
  1057. return Ok(new
  1058. {
  1059. count,
  1060. });
  1061. }
  1062. #region 回滚数据记录
  1063. //[HttpPost]
  1064. //public async Task<IActionResult> actionResult()
  1065. //{
  1066. // var jw = JsonView(true);
  1067. // var sql = @" SELECT * FROM OA2023DB.dbo.Crm_TableOperationRecord
  1068. // WHERE TableName ='Crm_NewClientData'
  1069. // AND OperationItem IN(4) AND CreateTime > '2025-02-03' AND CreateTime < '2025-03-06'
  1070. // AND ReturnResult LIKE '%修改成功%' ";
  1071. // var list = _sqlSugar.SqlQueryable<Crm_TableOperationRecord>(sql).Select(x=>new Crm_TableOperationRecord
  1072. // {
  1073. // RequestParam = x.RequestParam
  1074. // }).ToList();
  1075. // foreach (var item in list)
  1076. // {
  1077. // var string1 = item.RequestParam.Trim('"').Replace("\\", "");
  1078. // //if (!string.IsNullOrEmpty(item.RequestParam))
  1079. // //{
  1080. // // var req = item.RequestParam;
  1081. // // if (CommonFun.IsValidJson(item.RequestParam))
  1082. // // {
  1083. // // var res1 = JToken.Parse(item.RequestParam);
  1084. // // }
  1085. // // NewClientOpDto dto = JsonConvert.DeserializeObject<NewClientOpDto>(JsonConvert.DeserializeObject<string>(item.RequestParam));
  1086. // NewClientOpDto dto1 = JsonConvert.DeserializeObject<NewClientOpDto>(string1);
  1087. // var result = await this.NewClientOp(dto1);
  1088. // //}
  1089. // }
  1090. // return Ok(jw);
  1091. //}
  1092. #endregion
  1093. }
  1094. }