MarketCustomerResourcesController.cs 29 KB

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