CRMController.cs 15 KB

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