CRMController.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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 == null ? "操作失败" : 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, "程序错误!"));
  123. throw;
  124. }
  125. }
  126. /// <summary>
  127. /// 获取签证客户列表
  128. /// </summary>
  129. /// <param name="dto"></param>
  130. /// <returns></returns>
  131. [HttpPost]
  132. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  133. public async Task<IActionResult> GetClientList(DtoBase dto)
  134. {
  135. var clientData = await _clientRepository.GetCrmList(dto);
  136. if (clientData.Code != 0)
  137. {
  138. return Ok(JsonView(false, clientData.Msg == null ? "操作失败" : clientData.Msg));
  139. }
  140. return Ok(JsonView(clientData.Data, clientData.Data.Count));
  141. }
  142. /// <summary>
  143. /// 根据Id获取签证客户信息
  144. /// </summary>
  145. /// <param name="dto"></param>
  146. /// <returns></returns>
  147. [HttpPost]
  148. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  149. public async Task<IActionResult> CustomerInfo(CustomerDto dto)
  150. {
  151. try
  152. {
  153. Crm_DeleClient crm_Dele = await _clientRepository.GetAsync<Crm_DeleClient>(x => x.Id == dto.Id);
  154. if (crm_Dele == null)
  155. {
  156. return Ok(JsonView(false, "查询失败!"));
  157. }
  158. EncryptionProcessor.DecryptProperties(crm_Dele);
  159. List<Crm_VisaCustomerCompany> _VisaCustomerCompany = _clientRepository.Query<Crm_VisaCustomerCompany>(x => x.DcId == crm_Dele.Id && x.IsDel == 0).ToList();//客户工作经历表
  160. List<Crm_VisaCustomerSchool> _VisaCustomerSchool = _clientRepository.Query<Crm_VisaCustomerSchool>(x => x.DcId == crm_Dele.Id && x.IsDel == 0).ToList();//客户学历表
  161. List<Crm_VisaCustomerFamily> _VisaCustomerFamily = _clientRepository.Query<Crm_VisaCustomerFamily>(x => x.DcId == crm_Dele.Id && x.IsDel == 0).ToList();//客户学历表
  162. List<Crm_CustomerCert> _CustomerCerts = _clientRepository.Query<Crm_CustomerCert>(x => x.DcId == crm_Dele.Id && x.IsDel == 0).ToList();//客户证件表
  163. Crm_CustomerCompany _CustomerCompany = await _clientCompanyRepository.GetAsync<Crm_CustomerCompany>(x => x.Id == crm_Dele.CrmCompanyId);//客户公司信息
  164. var data = new
  165. {
  166. DeleClient = crm_Dele,
  167. WorkExperience = _VisaCustomerCompany,
  168. CustomerSchool = _VisaCustomerSchool,
  169. CustomerFamily = _VisaCustomerFamily,
  170. CustomerCompany = _CustomerCompany,
  171. CustomerCerts = _CustomerCerts
  172. };
  173. return Ok(JsonView(true, "查询成功!", data));
  174. }
  175. catch (Exception)
  176. {
  177. return Ok(JsonView(false, "程序错误!"));
  178. throw;
  179. }
  180. }
  181. /// <summary>
  182. /// 客户资料操作(Status:1.新增,2.修改)
  183. /// </summary>
  184. /// <param name="dto"></param>
  185. /// <returns></returns>
  186. [HttpPost]
  187. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  188. public async Task<IActionResult> EditCustomer(DeleClientOpDto dto)
  189. {
  190. try
  191. {
  192. Domain.Result result = await _clientRepository.OpCustomer(dto);
  193. if (result.Code != 0)
  194. {
  195. return Ok(JsonView(false, result.Msg));
  196. }
  197. return Ok(JsonView(true, result.Msg));
  198. }
  199. catch (Exception)
  200. {
  201. return Ok(JsonView(false, "程序错误!"));
  202. throw;
  203. }
  204. }
  205. /// <summary>
  206. /// 客户资料操作删除
  207. /// </summary>
  208. /// <param name="dto"></param>
  209. /// <returns></returns>
  210. [HttpPost]
  211. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  212. public async Task<IActionResult> DelCustomer(DeleClientDelDto dto)
  213. {
  214. Result result = await _clientRepository.DelCustomer(dto);
  215. if (result.Code != 0)
  216. {
  217. return Ok(JsonView(false, result.Msg));
  218. }
  219. return Ok(JsonView(true, result.Msg));
  220. }
  221. /// <summary>
  222. /// 证件表数据删除
  223. /// </summary>
  224. /// <param name="dto"></param>
  225. /// <returns></returns>
  226. [HttpPost]
  227. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  228. public async Task<IActionResult> DelCustomerCerts(DelBaseDto dto)
  229. {
  230. var result = await _customerCertRep.SoftDeleteByIdAsync<Crm_CustomerCert>(dto.Id.ToString(), dto.DeleteUserId);
  231. if (!result)
  232. {
  233. return Ok(JsonView(false, "删除失败"));
  234. }
  235. return Ok(JsonView(true, "删除成功!"));
  236. }
  237. /// <summary>
  238. /// 家庭成员表数据删除
  239. /// </summary>
  240. /// <param name="dto"></param>
  241. /// <returns></returns>
  242. [HttpPost]
  243. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  244. public async Task<IActionResult> DelCustomerFamily(DelBaseDto dto)
  245. {
  246. var result = await _customerFamilyRep.SoftDeleteByIdAsync<Crm_VisaCustomerFamily>(dto.Id.ToString(), dto.DeleteUserId);
  247. if (!result)
  248. {
  249. return Ok(JsonView(false, "删除失败"));
  250. }
  251. return Ok(JsonView(true, "删除成功!"));
  252. }
  253. /// <summary>
  254. /// 客户学历表数据删除
  255. /// </summary>
  256. /// <param name="dto"></param>
  257. /// <returns></returns>
  258. [HttpPost]
  259. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  260. public async Task<IActionResult> DelCustomerSchool(DelBaseDto dto)
  261. {
  262. var result = await _customerSchoolRep.SoftDeleteByIdAsync<Crm_VisaCustomerSchool>(dto.Id.ToString(), dto.DeleteUserId);
  263. if (!result)
  264. {
  265. return Ok(JsonView(false, "删除失败"));
  266. }
  267. return Ok(JsonView(true, "删除成功!"));
  268. }
  269. /// <summary>
  270. /// 客户工作经历表数据删除
  271. /// </summary>
  272. /// <param name="dto"></param>
  273. /// <returns></returns>
  274. [HttpPost]
  275. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  276. public async Task<IActionResult> DelVisaCustomerCompany(DelBaseDto dto)
  277. {
  278. var result = await _customerCompanyRep.SoftDeleteByIdAsync<Crm_VisaCustomerCompany>(dto.Id.ToString(), dto.DeleteUserId);
  279. if (!result)
  280. {
  281. return Ok(JsonView(false, "删除失败"));
  282. }
  283. return Ok(JsonView(true, "删除成功!"));
  284. }
  285. /// <summary>
  286. /// 客户资料导入
  287. /// </summary>
  288. /// <param name="dto"></param>
  289. /// <returns></returns>
  290. [HttpPost]
  291. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  292. public async Task<IActionResult> PostClient(DelBaseDto dto)
  293. {
  294. var result = await _customerCompanyRep.SoftDeleteByIdAsync<Crm_VisaCustomerCompany>(dto.Id.ToString(), dto.DeleteUserId);
  295. if (!result)
  296. {
  297. return Ok(JsonView(false, "删除失败"));
  298. }
  299. return Ok(JsonView(true, "删除成功!"));
  300. }
  301. /// <summary>
  302. /// 客户资料 地址经纬度查询
  303. /// </summary>
  304. /// <param name="province">省份</param>
  305. /// <param name="city">城市</param>
  306. /// <param name="area">区域</param>
  307. /// <returns></returns>
  308. [HttpPost]
  309. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  310. public async Task<IActionResult> ClientCompanyNautica(string province,string city,string area)
  311. {
  312. if (string.IsNullOrEmpty(province) && string.IsNullOrEmpty(city) && string.IsNullOrEmpty(area))
  313. {
  314. return Ok(JsonView(false, "省份、城市、区域,其中一个必须有值!", Array.Empty<T>()));
  315. }
  316. var datas = await _customerCertRep._sqlSugar.Queryable<Crm_NewClientData>()
  317. .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.Address))
  318. .Select(x => new Crm_NewClientData() { Id = x.Id, Address = x.Address })
  319. .ToListAsync();
  320. foreach (var item in datas) EncryptionProcessor.DecryptProperties(item);
  321. var seledtIds = datas
  322. .WhereIF(!string.IsNullOrEmpty(province), x => x.Address.Contains(province))
  323. .WhereIF(!string.IsNullOrEmpty(city), x => x.Address.Contains(city))
  324. .WhereIF(!string.IsNullOrEmpty(area), x => x.Address.Contains(area))
  325. .Select(x => x.Id)
  326. .ToList();
  327. if (!seledtIds.Any()) return Ok(JsonView(false, "暂无相关地址信息!", Array.Empty<T>()));
  328. var clients = await _customerCertRep._sqlSugar.Queryable<Crm_NewClientData>()
  329. .Where(x => seledtIds.Contains(x.Id))
  330. .Select(x => new Crm_NewClientData() { Id = x.Id, Client = x.Client, Address = x.Address })
  331. .ToListAsync();
  332. foreach (var item in clients) EncryptionProcessor.DecryptProperties(item);
  333. var requestData = clients.Select(x => x.Address).ToList();
  334. var aMapResults = await _geocodeService.GetGeocodesAsync(requestData);
  335. var res = new List<dynamic>();
  336. foreach (var item in aMapResults)
  337. {
  338. var client = clients.Find(x => x.Address.Equals(item.Address))?.Client ?? "-";
  339. if (item.Status.Equals("Success"))
  340. {
  341. res.Add(new {
  342. client = client,
  343. address = item.Address,
  344. Longitude =item.Longitude,
  345. Latitude = item.Latitude,
  346. });
  347. }
  348. else
  349. {
  350. res.Add(new
  351. {
  352. client = client,
  353. address = item.Address,
  354. Longitude = 0d,
  355. Latitude = 0d,
  356. });
  357. }
  358. }
  359. return Ok(JsonView(res));
  360. }
  361. }
  362. }