CRMController.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Mvc;
  3. using OASystem.Domain.Dtos.CRM;
  4. using OASystem.Domain.Entities.Customer;
  5. using OASystem.Infrastructure.Repositories.CRM;
  6. using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
  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. /// <summary>
  23. /// 初始化
  24. /// </summary>
  25. /// <param name="clientCompanyRepository"></param>
  26. /// <param name="clientRepository"></param>
  27. public CRMController(VisaDeleClientCompanyRepository clientCompanyRepository, VisaDeleClientRepository clientRepository,
  28. CustomerCertRepository customerCertRep, CustomerFamilyRepository customerFamilyRep,CustomerSchoolRepository customerSchoolRep, CustomerCompanyRepository customerCompanyRep)
  29. {
  30. this._clientCompanyRepository = clientCompanyRepository;
  31. this._clientRepository = clientRepository;
  32. this._customerCertRep = customerCertRep;
  33. this._customerFamilyRep = customerFamilyRep;
  34. this._customerSchoolRep = customerSchoolRep;
  35. _customerCompanyRep = customerCompanyRep;
  36. }
  37. /// <summary>
  38. /// 获取签证客户公司列表
  39. /// </summary>
  40. /// <param name="dto"></param>
  41. /// <returns></returns>
  42. [HttpPost]
  43. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  44. public async Task<IActionResult> GetClientCompanyList(DtoBase dto)
  45. {
  46. var clientCompanyData = await _clientCompanyRepository.GetCrm_ClientCompanyList(dto);
  47. if (clientCompanyData.Code != 0)
  48. {
  49. return Ok(JsonView(false, clientCompanyData.Msg == null ? "操作失败" : clientCompanyData.Msg));
  50. }
  51. return Ok(JsonView(clientCompanyData.Data, clientCompanyData.Data.Count));
  52. }
  53. /// <summary>
  54. /// 签证客户公司列表操作(Status:1.新增,2.修改)
  55. /// </summary>
  56. /// <param name="dto"></param>
  57. /// <returns></returns>
  58. [HttpPost]
  59. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  60. public async Task<IActionResult> OperationClientCompany(OperationClientCompanyDto dto)
  61. {
  62. try
  63. {
  64. if (dto.CompanyName == "")
  65. {
  66. return Ok(JsonView(false, "请检查客户单位名称是否填写!"));
  67. }
  68. if (dto.Address == "")
  69. {
  70. return Ok(JsonView(false, "请检查客户单位地址是否填写!"));
  71. }
  72. if (dto.PostCodes == "")
  73. {
  74. return Ok(JsonView(false, "请检查客户单位邮编是否填写!"));
  75. }
  76. Result clientCompanyData = await _clientCompanyRepository.OperationClientCompany(dto);
  77. if (clientCompanyData.Code != 0)
  78. {
  79. return Ok(JsonView(false, clientCompanyData.Msg));
  80. }
  81. return Ok(JsonView(true, clientCompanyData.Msg));
  82. }
  83. catch (Exception)
  84. {
  85. return Ok(JsonView(false, "程序错误!"));
  86. throw;
  87. }
  88. }
  89. /// <summary>
  90. /// 签证客户公司列表操作(删除)
  91. /// </summary>
  92. /// <returns></returns>
  93. [HttpPost]
  94. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  95. public async Task<IActionResult> DelClientCompany(DelBaseDto dto)
  96. {
  97. try
  98. {
  99. var res = await _clientCompanyRepository.SoftDeleteByIdAsync<Crm_CustomerCompany>(dto.Id.ToString(), dto.DeleteUserId);
  100. if (!res)
  101. {
  102. return Ok(JsonView(false, "删除失败"));
  103. }
  104. return Ok(JsonView(true, "删除成功!"));
  105. }
  106. catch (Exception ex)
  107. {
  108. return Ok(JsonView(false, "程序错误!"));
  109. throw;
  110. }
  111. }
  112. /// <summary>
  113. /// 获取签证客户列表
  114. /// </summary>
  115. /// <param name="dto"></param>
  116. /// <returns></returns>
  117. [HttpPost]
  118. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  119. public async Task<IActionResult> GetClientList(DtoBase dto)
  120. {
  121. var clientData = await _clientRepository.GetCrmList(dto);
  122. if (clientData.Code != 0)
  123. {
  124. return Ok(JsonView(false, clientData.Msg == null ? "操作失败" : clientData.Msg));
  125. }
  126. return Ok(JsonView(clientData.Data, clientData.Data.Count));
  127. }
  128. /// <summary>
  129. /// 根据Id获取签证客户信息
  130. /// </summary>
  131. /// <param name="dto"></param>
  132. /// <returns></returns>
  133. [HttpPost]
  134. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  135. public async Task<IActionResult> CustomerInfo(CustomerDto dto)
  136. {
  137. try
  138. {
  139. Crm_DeleClient crm_Dele = await _clientRepository.GetAsync<Crm_DeleClient>(x => x.Id == dto.Id);
  140. if (crm_Dele == null)
  141. {
  142. return Ok(JsonView(false, "查询失败!"));
  143. }
  144. List<Crm_VisaCustomerCompany> _VisaCustomerCompany = _clientRepository.Query<Crm_VisaCustomerCompany>(x => x.DcId == crm_Dele.Id && x.IsDel == 0).ToList();//客户工作经历表
  145. List<Crm_VisaCustomerSchool> _VisaCustomerSchool = _clientRepository.Query<Crm_VisaCustomerSchool>(x => x.DcId == crm_Dele.Id && x.IsDel == 0).ToList();//客户学历表
  146. List<Crm_VisaCustomerFamily> _VisaCustomerFamily = _clientRepository.Query<Crm_VisaCustomerFamily>(x => x.DcId == crm_Dele.Id && x.IsDel == 0).ToList();//客户学历表
  147. List<Crm_CustomerCert> _CustomerCerts= _clientRepository.Query<Crm_CustomerCert>(x => x.DcId == crm_Dele.Id && x.IsDel == 0).ToList();//客户证件表
  148. Crm_CustomerCompany _CustomerCompany =await _clientCompanyRepository.GetAsync<Crm_CustomerCompany>(x => x.Id == crm_Dele.CrmCompanyId);//客户公司信息
  149. var data = new
  150. {
  151. DeleClient = crm_Dele,
  152. WorkExperience = _VisaCustomerCompany,
  153. CustomerSchool = _VisaCustomerSchool,
  154. CustomerFamily = _VisaCustomerFamily,
  155. CustomerCompany= _CustomerCompany,
  156. CustomerCerts= _CustomerCerts
  157. };
  158. return Ok(JsonView(true, "查询成功!", data));
  159. }
  160. catch (Exception)
  161. {
  162. return Ok(JsonView(false, "程序错误!"));
  163. throw;
  164. }
  165. }
  166. /// <summary>
  167. /// 客户资料操作(Status:1.新增,2.修改)
  168. /// </summary>
  169. /// <param name="dto"></param>
  170. /// <returns></returns>
  171. [HttpPost]
  172. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  173. public async Task<IActionResult> EditCustomer(DeleClientOpDto dto)
  174. {
  175. try
  176. {
  177. Domain.Result result =await _clientRepository.OpCustomer(dto);
  178. if (result.Code != 0)
  179. {
  180. return Ok(JsonView(false, result.Msg));
  181. }
  182. return Ok(JsonView(true, result.Msg));
  183. }
  184. catch (Exception)
  185. {
  186. return Ok(JsonView(false, "程序错误!"));
  187. throw;
  188. }
  189. }
  190. /// <summary>
  191. /// 客户资料操作删除
  192. /// </summary>
  193. /// <param name="dto"></param>
  194. /// <returns></returns>
  195. [HttpPost]
  196. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  197. public async Task<IActionResult>DelCustomer(DeleClientDelDto dto)
  198. {
  199. try
  200. {
  201. Result result = await _clientRepository.DelCustomer(dto);
  202. if (result.Code != 0)
  203. {
  204. return Ok(JsonView(false, result.Msg));
  205. }
  206. return Ok(JsonView(true, result.Msg));
  207. }
  208. catch (Exception)
  209. {
  210. return Ok(JsonView(false, "程序错误!"));
  211. throw;
  212. }
  213. return Ok(JsonView(false, "程序错误!"));
  214. }
  215. /// <summary>
  216. /// 证件表数据删除
  217. /// </summary>
  218. /// <param name="dto"></param>
  219. /// <returns></returns>
  220. [HttpPost]
  221. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  222. public async Task<IActionResult> DelCustomerCerts(DelBaseDto dto)
  223. {
  224. try
  225. {
  226. var result = await _customerCertRep.SoftDeleteByIdAsync<Crm_CustomerCert>(dto.Id.ToString(),dto.DeleteUserId);
  227. if (!result)
  228. {
  229. return Ok(JsonView(false, "删除失败"));
  230. }
  231. return Ok(JsonView(true, "删除成功!"));
  232. }
  233. catch (Exception ex)
  234. {
  235. return Ok(JsonView(false, "程序错误!"));
  236. throw;
  237. }
  238. }
  239. /// <summary>
  240. /// 家庭成员表数据删除
  241. /// </summary>
  242. /// <param name="dto"></param>
  243. /// <returns></returns>
  244. [HttpPost]
  245. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  246. public async Task<IActionResult> DelCustomerFamily(DelBaseDto dto)
  247. {
  248. try
  249. {
  250. var result = await _customerFamilyRep.SoftDeleteByIdAsync<Crm_VisaCustomerFamily>(dto.Id.ToString(), dto.DeleteUserId);
  251. if (!result)
  252. {
  253. return Ok(JsonView(false, "删除失败"));
  254. }
  255. return Ok(JsonView(true, "删除成功!"));
  256. }
  257. catch (Exception ex)
  258. {
  259. return Ok(JsonView(false, "程序错误!"));
  260. throw;
  261. }
  262. }
  263. /// <summary>
  264. /// 客户学历表数据删除
  265. /// </summary>
  266. /// <param name="dto"></param>
  267. /// <returns></returns>
  268. [HttpPost]
  269. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  270. public async Task<IActionResult> DelCustomerSchool(DelBaseDto dto)
  271. {
  272. try
  273. {
  274. var result = await _customerSchoolRep.SoftDeleteByIdAsync<Crm_VisaCustomerSchool>(dto.Id.ToString(), dto.DeleteUserId);
  275. if (!result)
  276. {
  277. return Ok(JsonView(false, "删除失败"));
  278. }
  279. return Ok(JsonView(true, "删除成功!"));
  280. }
  281. catch (Exception ex)
  282. {
  283. return Ok(JsonView(false, "程序错误!"));
  284. throw;
  285. }
  286. }
  287. /// <summary>
  288. /// 客户工作经历表数据删除
  289. /// </summary>
  290. /// <param name="dto"></param>
  291. /// <returns></returns>
  292. [HttpPost]
  293. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  294. public async Task<IActionResult> DelVisaCustomerCompany(DelBaseDto dto)
  295. {
  296. try
  297. {
  298. var result = await _customerCompanyRep.SoftDeleteByIdAsync<Crm_VisaCustomerCompany>(dto.Id.ToString(), dto.DeleteUserId);
  299. if (!result)
  300. {
  301. return Ok(JsonView(false, "删除失败"));
  302. }
  303. return Ok(JsonView(true, "删除成功!"));
  304. }
  305. catch (Exception ex)
  306. {
  307. return Ok(JsonView(false, "程序错误!"));
  308. throw;
  309. }
  310. }
  311. }
  312. }