using NPOI.SS.Formula.Functions; using OASystem.API.OAMethodLib.AMapApi; using OASystem.Domain.AesEncryption; using OASystem.Domain.Dtos.CRM; using OASystem.Domain.Entities.Customer; using OASystem.Infrastructure.Repositories.CRM; namespace OASystem.API.Controllers { /// /// 签证客户资料相关 /// [Route("api/[controller]/[action]")] //[ApiController] public class CRMController : ControllerBase { private readonly VisaDeleClientCompanyRepository _clientCompanyRepository; private readonly VisaDeleClientRepository _clientRepository; private readonly CustomerCertRepository _customerCertRep; private readonly CustomerFamilyRepository _customerFamilyRep; private readonly CustomerSchoolRepository _customerSchoolRep; private readonly CustomerCompanyRepository _customerCompanyRep; private readonly GeocodeService _geocodeService; /// /// 初始化 /// /// /// public CRMController( VisaDeleClientCompanyRepository clientCompanyRepository, VisaDeleClientRepository clientRepository, CustomerCertRepository customerCertRep, CustomerFamilyRepository customerFamilyRep, CustomerSchoolRepository customerSchoolRep, CustomerCompanyRepository customerCompanyRep, GeocodeService geocodeService ) { this._clientCompanyRepository = clientCompanyRepository; this._clientRepository = clientRepository; this._customerCertRep = customerCertRep; this._customerFamilyRep = customerFamilyRep; this._customerSchoolRep = customerSchoolRep; _customerCompanyRep = customerCompanyRep; _geocodeService = geocodeService; } /// /// 获取签证客户公司列表 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task GetClientCompanyList(DtoBase dto) { var clientCompanyData = await _clientCompanyRepository.GetCrm_ClientCompanyList(dto); if (clientCompanyData.Code != 0) { return Ok(JsonView(false, clientCompanyData.Msg == null ? "操作失败" : clientCompanyData.Msg)); } return Ok(JsonView(clientCompanyData.Data, clientCompanyData.Data.Count)); } /// /// 签证客户公司列表操作(Status:1.新增,2.修改) /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task OperationClientCompany(OperationClientCompanyDto dto) { try { if (dto.CompanyName == "") { return Ok(JsonView(false, "请检查客户单位名称是否填写!")); } if (dto.Address == "") { return Ok(JsonView(false, "请检查客户单位地址是否填写!")); } if (dto.PostCodes == "") { return Ok(JsonView(false, "请检查客户单位邮编是否填写!")); } Result clientCompanyData = await _clientCompanyRepository.OperationClientCompany(dto); if (clientCompanyData.Code != 0) { return Ok(JsonView(false, clientCompanyData.Msg)); } return Ok(JsonView(true, clientCompanyData.Msg)); } catch (Exception) { return Ok(JsonView(false, "程序错误!")); throw; } } /// /// 签证客户公司列表操作(删除) /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task DelClientCompany(DelBaseDto dto) { try { var res = await _clientCompanyRepository.SoftDeleteByIdAsync(dto.Id.ToString(), dto.DeleteUserId); if (!res) { return Ok(JsonView(false, "删除失败")); } return Ok(JsonView(true, "删除成功!")); } catch (Exception ex) { return Ok(JsonView(false, "程序错误!")); throw; } } /// /// 获取签证客户列表 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task GetClientList(DtoBase dto) { var clientData = await _clientRepository.GetCrmList(dto); if (clientData.Code != 0) { return Ok(JsonView(false, clientData.Msg == null ? "操作失败" : clientData.Msg)); } return Ok(JsonView(clientData.Data, clientData.Data.Count)); } /// /// 根据Id获取签证客户信息 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task CustomerInfo(CustomerDto dto) { try { Crm_DeleClient crm_Dele = await _clientRepository.GetAsync(x => x.Id == dto.Id); if (crm_Dele == null) { return Ok(JsonView(false, "查询失败!")); } EncryptionProcessor.DecryptProperties(crm_Dele); List _VisaCustomerCompany = _clientRepository.Query(x => x.DcId == crm_Dele.Id && x.IsDel == 0).ToList();//客户工作经历表 List _VisaCustomerSchool = _clientRepository.Query(x => x.DcId == crm_Dele.Id && x.IsDel == 0).ToList();//客户学历表 List _VisaCustomerFamily = _clientRepository.Query(x => x.DcId == crm_Dele.Id && x.IsDel == 0).ToList();//客户学历表 List _CustomerCerts = _clientRepository.Query(x => x.DcId == crm_Dele.Id && x.IsDel == 0).ToList();//客户证件表 Crm_CustomerCompany _CustomerCompany = await _clientCompanyRepository.GetAsync(x => x.Id == crm_Dele.CrmCompanyId);//客户公司信息 var data = new { DeleClient = crm_Dele, WorkExperience = _VisaCustomerCompany, CustomerSchool = _VisaCustomerSchool, CustomerFamily = _VisaCustomerFamily, CustomerCompany = _CustomerCompany, CustomerCerts = _CustomerCerts }; return Ok(JsonView(true, "查询成功!", data)); } catch (Exception) { return Ok(JsonView(false, "程序错误!")); throw; } } /// /// 客户资料操作(Status:1.新增,2.修改) /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task EditCustomer(DeleClientOpDto dto) { try { Domain.Result result = await _clientRepository.OpCustomer(dto); if (result.Code != 0) { return Ok(JsonView(false, result.Msg)); } return Ok(JsonView(true, result.Msg)); } catch (Exception) { return Ok(JsonView(false, "程序错误!")); throw; } } /// /// 客户资料操作删除 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task DelCustomer(DeleClientDelDto dto) { Result result = await _clientRepository.DelCustomer(dto); if (result.Code != 0) { return Ok(JsonView(false, result.Msg)); } return Ok(JsonView(true, result.Msg)); } /// /// 证件表数据删除 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task DelCustomerCerts(DelBaseDto dto) { var result = await _customerCertRep.SoftDeleteByIdAsync(dto.Id.ToString(), dto.DeleteUserId); if (!result) { return Ok(JsonView(false, "删除失败")); } return Ok(JsonView(true, "删除成功!")); } /// /// 家庭成员表数据删除 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task DelCustomerFamily(DelBaseDto dto) { var result = await _customerFamilyRep.SoftDeleteByIdAsync(dto.Id.ToString(), dto.DeleteUserId); if (!result) { return Ok(JsonView(false, "删除失败")); } return Ok(JsonView(true, "删除成功!")); } /// /// 客户学历表数据删除 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task DelCustomerSchool(DelBaseDto dto) { var result = await _customerSchoolRep.SoftDeleteByIdAsync(dto.Id.ToString(), dto.DeleteUserId); if (!result) { return Ok(JsonView(false, "删除失败")); } return Ok(JsonView(true, "删除成功!")); } /// /// 客户工作经历表数据删除 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task DelVisaCustomerCompany(DelBaseDto dto) { var result = await _customerCompanyRep.SoftDeleteByIdAsync(dto.Id.ToString(), dto.DeleteUserId); if (!result) { return Ok(JsonView(false, "删除失败")); } return Ok(JsonView(true, "删除成功!")); } /// /// 客户资料导入 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task PostClient(DelBaseDto dto) { var result = await _customerCompanyRep.SoftDeleteByIdAsync(dto.Id.ToString(), dto.DeleteUserId); if (!result) { return Ok(JsonView(false, "删除失败")); } return Ok(JsonView(true, "删除成功!")); } /// /// 客户资料 地址经纬度查询 /// /// 省份 /// 城市 /// 区域 /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task ClientCompanyNautica(string province,string city,string area) { if (string.IsNullOrEmpty(province) && string.IsNullOrEmpty(city) && string.IsNullOrEmpty(area)) { return Ok(JsonView(false, "省份、城市、区域,其中一个必须有值!", Array.Empty())); } var datas = await _customerCertRep._sqlSugar.Queryable() .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.Address)) .Select(x => new Crm_NewClientData() { Id = x.Id, Address = x.Address }) .ToListAsync(); foreach (var item in datas) EncryptionProcessor.DecryptProperties(item); var seledtIds = datas .WhereIF(!string.IsNullOrEmpty(province), x => x.Address.Contains(province)) .WhereIF(!string.IsNullOrEmpty(city), x => x.Address.Contains(city)) .WhereIF(!string.IsNullOrEmpty(area), x => x.Address.Contains(area)) .Select(x => x.Id) .ToList(); if (!seledtIds.Any()) return Ok(JsonView(false, "暂无相关地址信息!", Array.Empty())); var clients = await _customerCertRep._sqlSugar.Queryable() .Where(x => seledtIds.Contains(x.Id)) .Select(x => new Crm_NewClientData() { Id = x.Id, Client = x.Client, Address = x.Address }) .ToListAsync(); foreach (var item in clients) EncryptionProcessor.DecryptProperties(item); var requestData = clients.Select(x => x.Address).ToList(); var aMapResults = await _geocodeService.GetGeocodesAsync(requestData); var res = new List(); foreach (var item in aMapResults) { var client = clients.Find(x => x.Address.Equals(item.Address))?.Client ?? "-"; if (item.Status.Equals("Success")) { res.Add(new { client = client, address = item.Address, Longitude =item.Longitude, Latitude = item.Latitude, }); } else { res.Add(new { client = client, address = item.Address, Longitude = 0d, Latitude = 0d, }); } } return Ok(JsonView(res)); } } }