CRMController.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. using NPOI.SS.Formula.Functions;
  2. using OASystem.API.OAMethodLib.AMapApi;
  3. using OASystem.Domain.AesEncryption;
  4. using OASystem.Domain.Dtos.CRM;
  5. using OASystem.Domain.Entities.Customer;
  6. using OASystem.Infrastructure.Repositories.CRM;
  7. namespace OASystem.API.Controllers
  8. {
  9. /// <summary>
  10. /// 签证客户资料相关
  11. /// </summary>
  12. [Route("api/[controller]/[action]")]
  13. //[ApiController]
  14. public class CRMController : ControllerBase
  15. {
  16. private readonly VisaDeleClientCompanyRepository _clientCompanyRepository;
  17. private readonly VisaDeleClientRepository _clientRepository;
  18. private readonly CustomerCertRepository _customerCertRep;
  19. private readonly CustomerFamilyRepository _customerFamilyRep;
  20. private readonly CustomerSchoolRepository _customerSchoolRep;
  21. private readonly CustomerCompanyRepository _customerCompanyRep;
  22. private readonly GeocodeService _geocodeService;
  23. /// <summary>
  24. /// 初始化
  25. /// </summary>
  26. /// <param name="clientCompanyRepository"></param>
  27. /// <param name="clientRepository"></param>
  28. /// <param name="customerCertRep"></param>
  29. /// <param name="customerFamilyRep"></param>
  30. /// <param name="customerSchoolRep"></param>
  31. /// <param name="customerCompanyRep"></param>
  32. /// <param name="geocodeService"></param>
  33. public CRMController(
  34. VisaDeleClientCompanyRepository clientCompanyRepository,
  35. VisaDeleClientRepository clientRepository,
  36. CustomerCertRepository customerCertRep,
  37. CustomerFamilyRepository customerFamilyRep,
  38. CustomerSchoolRepository customerSchoolRep,
  39. CustomerCompanyRepository customerCompanyRep,
  40. GeocodeService geocodeService
  41. )
  42. {
  43. this._clientCompanyRepository = clientCompanyRepository;
  44. this._clientRepository = clientRepository;
  45. this._customerCertRep = customerCertRep;
  46. this._customerFamilyRep = customerFamilyRep;
  47. this._customerSchoolRep = customerSchoolRep;
  48. _customerCompanyRep = customerCompanyRep;
  49. _geocodeService = geocodeService;
  50. }
  51. /// <summary>
  52. /// 获取签证客户公司列表
  53. /// </summary>
  54. /// <param name="dto"></param>
  55. /// <returns></returns>
  56. [HttpPost]
  57. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  58. public async Task<IActionResult> GetClientCompanyList(DtoBase dto)
  59. {
  60. var clientCompanyData = await _clientCompanyRepository.GetCrm_ClientCompanyList(dto);
  61. if (clientCompanyData.Code != 0)
  62. {
  63. return Ok(JsonView(false, clientCompanyData.Msg ?? "操作失败"));
  64. }
  65. return Ok(JsonView(clientCompanyData.Data, clientCompanyData.Data.Count));
  66. }
  67. /// <summary>
  68. /// 签证客户公司列表操作(Status:1.新增,2.修改)
  69. /// </summary>
  70. /// <param name="dto"></param>
  71. /// <returns></returns>
  72. [HttpPost]
  73. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  74. public async Task<IActionResult> OperationClientCompany(OperationClientCompanyDto dto)
  75. {
  76. try
  77. {
  78. if (dto.CompanyName == "")
  79. {
  80. return Ok(JsonView(false, "请检查客户单位名称是否填写!"));
  81. }
  82. if (dto.Address == "")
  83. {
  84. return Ok(JsonView(false, "请检查客户单位地址是否填写!"));
  85. }
  86. if (dto.PostCodes == "")
  87. {
  88. return Ok(JsonView(false, "请检查客户单位邮编是否填写!"));
  89. }
  90. Result clientCompanyData = await _clientCompanyRepository.OperationClientCompany(dto);
  91. if (clientCompanyData.Code != 0)
  92. {
  93. return Ok(JsonView(false, clientCompanyData.Msg));
  94. }
  95. return Ok(JsonView(true, clientCompanyData.Msg));
  96. }
  97. catch (Exception)
  98. {
  99. return Ok(JsonView(false, "程序错误!"));
  100. throw;
  101. }
  102. }
  103. /// <summary>
  104. /// 签证客户公司列表操作(删除)
  105. /// </summary>
  106. /// <returns></returns>
  107. [HttpPost]
  108. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  109. public async Task<IActionResult> DelClientCompany(DelBaseDto dto)
  110. {
  111. try
  112. {
  113. var res = await _clientCompanyRepository.SoftDeleteByIdAsync<Crm_CustomerCompany>(dto.Id.ToString(), dto.DeleteUserId);
  114. if (!res)
  115. {
  116. return Ok(JsonView(false, "删除失败"));
  117. }
  118. return Ok(JsonView(true, "删除成功!"));
  119. }
  120. catch (Exception ex)
  121. {
  122. return Ok(JsonView(false, $"程序错误!{ex.Message}"));
  123. }
  124. }
  125. /// <summary>
  126. /// 获取签证客户列表
  127. /// </summary>
  128. /// <param name="dto"></param>
  129. /// <returns></returns>
  130. [HttpPost]
  131. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  132. public async Task<IActionResult> GetClientList(DtoBase dto)
  133. {
  134. var clientData = await _clientRepository.GetCrmList(dto);
  135. if (clientData.Code != 0)
  136. {
  137. return Ok(JsonView(false, clientData.Msg ?? "操作失败"));
  138. }
  139. return Ok(JsonView(clientData.Data, clientData.Data.Count));
  140. }
  141. /// <summary>
  142. /// 根据Id获取签证客户信息
  143. /// </summary>
  144. /// <param name="dto"></param>
  145. /// <returns></returns>
  146. [HttpPost]
  147. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  148. public async Task<IActionResult> CustomerInfo(CustomerDto dto)
  149. {
  150. try
  151. {
  152. Crm_DeleClient crm_Dele = await _clientRepository.GetAsync<Crm_DeleClient>(x => x.Id == dto.Id);
  153. if (crm_Dele == null)
  154. {
  155. return Ok(JsonView(false, "查询失败!"));
  156. }
  157. EncryptionProcessor.DecryptProperties(crm_Dele);
  158. List<Crm_VisaCustomerCompany> _VisaCustomerCompany = _clientRepository.Query<Crm_VisaCustomerCompany>(x => x.DcId == crm_Dele.Id && x.IsDel == 0).ToList();//客户工作经历表
  159. List<Crm_VisaCustomerSchool> _VisaCustomerSchool = _clientRepository.Query<Crm_VisaCustomerSchool>(x => x.DcId == crm_Dele.Id && x.IsDel == 0).ToList();//客户学历表
  160. List<Crm_VisaCustomerFamily> _VisaCustomerFamily = _clientRepository.Query<Crm_VisaCustomerFamily>(x => x.DcId == crm_Dele.Id && x.IsDel == 0).ToList();//客户学历表
  161. List<Crm_CustomerCert> _CustomerCerts = _clientRepository.Query<Crm_CustomerCert>(x => x.DcId == crm_Dele.Id && x.IsDel == 0).ToList();//客户证件表
  162. Crm_CustomerCompany _CustomerCompany = await _clientCompanyRepository.GetAsync<Crm_CustomerCompany>(x => x.Id == crm_Dele.CrmCompanyId);//客户公司信息
  163. var data = new
  164. {
  165. DeleClient = crm_Dele,
  166. WorkExperience = _VisaCustomerCompany,
  167. CustomerSchool = _VisaCustomerSchool,
  168. CustomerFamily = _VisaCustomerFamily,
  169. CustomerCompany = _CustomerCompany,
  170. CustomerCerts = _CustomerCerts
  171. };
  172. return Ok(JsonView(true, "查询成功!", data));
  173. }
  174. catch (Exception)
  175. {
  176. return Ok(JsonView(false, "程序错误!"));
  177. throw;
  178. }
  179. }
  180. /// <summary>
  181. /// 客户资料操作(Status:1.新增,2.修改)
  182. /// </summary>
  183. /// <param name="dto"></param>
  184. /// <returns></returns>
  185. [HttpPost]
  186. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  187. public async Task<IActionResult> EditCustomer(DeleClientOpDto dto)
  188. {
  189. try
  190. {
  191. Domain.Result result = await _clientRepository.OpCustomer(dto);
  192. if (result.Code != 0)
  193. {
  194. return Ok(JsonView(false, result.Msg));
  195. }
  196. return Ok(JsonView(true, result.Msg));
  197. }
  198. catch (Exception)
  199. {
  200. return Ok(JsonView(false, "程序错误!"));
  201. throw;
  202. }
  203. }
  204. /// <summary>
  205. /// 客户资料操作删除
  206. /// </summary>
  207. /// <param name="dto"></param>
  208. /// <returns></returns>
  209. [HttpPost]
  210. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  211. public async Task<IActionResult> DelCustomer(DeleClientDelDto dto)
  212. {
  213. Result result = await _clientRepository.DelCustomer(dto);
  214. if (result.Code != 0)
  215. {
  216. return Ok(JsonView(false, result.Msg));
  217. }
  218. return Ok(JsonView(true, result.Msg));
  219. }
  220. /// <summary>
  221. /// 证件表数据删除
  222. /// </summary>
  223. /// <param name="dto"></param>
  224. /// <returns></returns>
  225. [HttpPost]
  226. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  227. public async Task<IActionResult> DelCustomerCerts(DelBaseDto dto)
  228. {
  229. var result = await _customerCertRep.SoftDeleteByIdAsync<Crm_CustomerCert>(dto.Id.ToString(), dto.DeleteUserId);
  230. if (!result)
  231. {
  232. return Ok(JsonView(false, "删除失败"));
  233. }
  234. return Ok(JsonView(true, "删除成功!"));
  235. }
  236. /// <summary>
  237. /// 家庭成员表数据删除
  238. /// </summary>
  239. /// <param name="dto"></param>
  240. /// <returns></returns>
  241. [HttpPost]
  242. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  243. public async Task<IActionResult> DelCustomerFamily(DelBaseDto dto)
  244. {
  245. var result = await _customerFamilyRep.SoftDeleteByIdAsync<Crm_VisaCustomerFamily>(dto.Id.ToString(), dto.DeleteUserId);
  246. if (!result)
  247. {
  248. return Ok(JsonView(false, "删除失败"));
  249. }
  250. return Ok(JsonView(true, "删除成功!"));
  251. }
  252. /// <summary>
  253. /// 客户学历表数据删除
  254. /// </summary>
  255. /// <param name="dto"></param>
  256. /// <returns></returns>
  257. [HttpPost]
  258. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  259. public async Task<IActionResult> DelCustomerSchool(DelBaseDto dto)
  260. {
  261. var result = await _customerSchoolRep.SoftDeleteByIdAsync<Crm_VisaCustomerSchool>(dto.Id.ToString(), dto.DeleteUserId);
  262. if (!result)
  263. {
  264. return Ok(JsonView(false, "删除失败"));
  265. }
  266. return Ok(JsonView(true, "删除成功!"));
  267. }
  268. /// <summary>
  269. /// 客户工作经历表数据删除
  270. /// </summary>
  271. /// <param name="dto"></param>
  272. /// <returns></returns>
  273. [HttpPost]
  274. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  275. public async Task<IActionResult> DelVisaCustomerCompany(DelBaseDto dto)
  276. {
  277. var result = await _customerCompanyRep.SoftDeleteByIdAsync<Crm_VisaCustomerCompany>(dto.Id.ToString(), dto.DeleteUserId);
  278. if (!result)
  279. {
  280. return Ok(JsonView(false, "删除失败"));
  281. }
  282. return Ok(JsonView(true, "删除成功!"));
  283. }
  284. /// <summary>
  285. /// 客户资料导入
  286. /// </summary>
  287. /// <param name="dto"></param>
  288. /// <returns></returns>
  289. [HttpPost]
  290. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  291. public async Task<IActionResult> PostClient(DelBaseDto dto)
  292. {
  293. var result = await _customerCompanyRep.SoftDeleteByIdAsync<Crm_VisaCustomerCompany>(dto.Id.ToString(), dto.DeleteUserId);
  294. if (!result)
  295. {
  296. return Ok(JsonView(false, "删除失败"));
  297. }
  298. return Ok(JsonView(true, "删除成功!"));
  299. }
  300. /// <summary>
  301. /// 客户资料 地址经纬度查询
  302. /// </summary>
  303. /// <param name="province">省份</param>
  304. /// <param name="city">城市</param>
  305. /// <param name="area">区域</param>
  306. /// <returns></returns>
  307. [HttpPost]
  308. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  309. public async Task<IActionResult> ClientCompanyNautica(string province, string city, string area)
  310. {
  311. if (string.IsNullOrEmpty(province) && string.IsNullOrEmpty(city) && string.IsNullOrEmpty(area))
  312. {
  313. return Ok(JsonView(false, "省份、城市、区域,其中一个必须有值!", Array.Empty<T>()));
  314. }
  315. var datas = await _customerCertRep._sqlSugar.Queryable<Crm_NewClientData>()
  316. .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.Address))
  317. .Select(x => new Crm_NewClientData() { Id = x.Id, Address = x.Address })
  318. .ToListAsync();
  319. foreach (var item in datas) EncryptionProcessor.DecryptProperties(item);
  320. var seledtIds = datas
  321. .WhereIF(!string.IsNullOrEmpty(province), x => x.Address.Contains(province))
  322. .WhereIF(!string.IsNullOrEmpty(city), x => x.Address.Contains(city))
  323. .WhereIF(!string.IsNullOrEmpty(area), x => x.Address.Contains(area))
  324. .Select(x => x.Id)
  325. .ToList();
  326. if (!seledtIds.Any()) return Ok(JsonView(false, "暂无相关地址信息!", Array.Empty<T>()));
  327. var clients = await _customerCertRep._sqlSugar.Queryable<Crm_NewClientData>()
  328. .Where(x => seledtIds.Contains(x.Id))
  329. .Select(x => new Crm_NewClientData() { Id = x.Id, Client = x.Client, Address = x.Address })
  330. .ToListAsync();
  331. foreach (var item in clients) EncryptionProcessor.DecryptProperties(item);
  332. var requestData = clients.Select(x => x.Address).ToList();
  333. var aMapResults = await _geocodeService.GetGeocodesAsync(requestData);
  334. var res = new List<dynamic>();
  335. foreach (var item in aMapResults)
  336. {
  337. var client = clients.Find(x => x.Address.Equals(item.Address))?.Client ?? "-";
  338. if (item.Status.Equals("Success"))
  339. {
  340. res.Add(new
  341. {
  342. client,
  343. address = item.Address,
  344. item.Longitude,
  345. item.Latitude,
  346. });
  347. }
  348. else
  349. {
  350. res.Add(new
  351. {
  352. client,
  353. item.Address,
  354. Longitude = 0d,
  355. Latitude = 0d,
  356. });
  357. }
  358. }
  359. return Ok(JsonView(res));
  360. }
  361. }
  362. }