CRMController.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. using OASystem.Domain.AesEncryption;
  2. using OASystem.Domain.Dtos.CRM;
  3. using OASystem.Domain.Entities.Customer;
  4. using OASystem.Infrastructure.Repositories.CRM;
  5. namespace OASystem.API.Controllers
  6. {
  7. /// <summary>
  8. /// 签证客户资料相关
  9. /// </summary>
  10. [Route("api/[controller]/[action]")]
  11. //[ApiController]
  12. public class CRMController : ControllerBase
  13. {
  14. private readonly VisaDeleClientCompanyRepository _clientCompanyRepository;
  15. private readonly VisaDeleClientRepository _clientRepository;
  16. private readonly CustomerCertRepository _customerCertRep;
  17. private readonly CustomerFamilyRepository _customerFamilyRep;
  18. private readonly CustomerSchoolRepository _customerSchoolRep;
  19. private readonly CustomerCompanyRepository _customerCompanyRep;
  20. /// <summary>
  21. /// 初始化
  22. /// </summary>
  23. /// <param name="clientCompanyRepository"></param>
  24. /// <param name="clientRepository"></param>
  25. public CRMController(VisaDeleClientCompanyRepository clientCompanyRepository, VisaDeleClientRepository clientRepository,
  26. CustomerCertRepository customerCertRep, CustomerFamilyRepository customerFamilyRep, CustomerSchoolRepository customerSchoolRep, CustomerCompanyRepository customerCompanyRep)
  27. {
  28. this._clientCompanyRepository = clientCompanyRepository;
  29. this._clientRepository = clientRepository;
  30. this._customerCertRep = customerCertRep;
  31. this._customerFamilyRep = customerFamilyRep;
  32. this._customerSchoolRep = customerSchoolRep;
  33. _customerCompanyRep = customerCompanyRep;
  34. }
  35. /// <summary>
  36. /// 获取签证客户公司列表
  37. /// </summary>
  38. /// <param name="dto"></param>
  39. /// <returns></returns>
  40. [HttpPost]
  41. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  42. public async Task<IActionResult> GetClientCompanyList(DtoBase dto)
  43. {
  44. var clientCompanyData = await _clientCompanyRepository.GetCrm_ClientCompanyList(dto);
  45. if (clientCompanyData.Code != 0)
  46. {
  47. return Ok(JsonView(false, clientCompanyData.Msg == null ? "操作失败" : clientCompanyData.Msg));
  48. }
  49. return Ok(JsonView(clientCompanyData.Data, clientCompanyData.Data.Count));
  50. }
  51. /// <summary>
  52. /// 签证客户公司列表操作(Status:1.新增,2.修改)
  53. /// </summary>
  54. /// <param name="dto"></param>
  55. /// <returns></returns>
  56. [HttpPost]
  57. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  58. public async Task<IActionResult> OperationClientCompany(OperationClientCompanyDto dto)
  59. {
  60. try
  61. {
  62. if (dto.CompanyName == "")
  63. {
  64. return Ok(JsonView(false, "请检查客户单位名称是否填写!"));
  65. }
  66. if (dto.Address == "")
  67. {
  68. return Ok(JsonView(false, "请检查客户单位地址是否填写!"));
  69. }
  70. if (dto.PostCodes == "")
  71. {
  72. return Ok(JsonView(false, "请检查客户单位邮编是否填写!"));
  73. }
  74. Result clientCompanyData = await _clientCompanyRepository.OperationClientCompany(dto);
  75. if (clientCompanyData.Code != 0)
  76. {
  77. return Ok(JsonView(false, clientCompanyData.Msg));
  78. }
  79. return Ok(JsonView(true, clientCompanyData.Msg));
  80. }
  81. catch (Exception)
  82. {
  83. return Ok(JsonView(false, "程序错误!"));
  84. throw;
  85. }
  86. }
  87. /// <summary>
  88. /// 签证客户公司列表操作(删除)
  89. /// </summary>
  90. /// <returns></returns>
  91. [HttpPost]
  92. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  93. public async Task<IActionResult> DelClientCompany(DelBaseDto dto)
  94. {
  95. try
  96. {
  97. var res = await _clientCompanyRepository.SoftDeleteByIdAsync<Crm_CustomerCompany>(dto.Id.ToString(), dto.DeleteUserId);
  98. if (!res)
  99. {
  100. return Ok(JsonView(false, "删除失败"));
  101. }
  102. return Ok(JsonView(true, "删除成功!"));
  103. }
  104. catch (Exception ex)
  105. {
  106. return Ok(JsonView(false, "程序错误!"));
  107. throw;
  108. }
  109. }
  110. /// <summary>
  111. /// 获取签证客户列表
  112. /// </summary>
  113. /// <param name="dto"></param>
  114. /// <returns></returns>
  115. [HttpPost]
  116. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  117. public async Task<IActionResult> GetClientList(DtoBase dto)
  118. {
  119. var clientData = await _clientRepository.GetCrmList(dto);
  120. if (clientData.Code != 0)
  121. {
  122. return Ok(JsonView(false, clientData.Msg == null ? "操作失败" : clientData.Msg));
  123. }
  124. return Ok(JsonView(clientData.Data, clientData.Data.Count));
  125. }
  126. /// <summary>
  127. /// 根据Id获取签证客户信息
  128. /// </summary>
  129. /// <param name="dto"></param>
  130. /// <returns></returns>
  131. [HttpPost]
  132. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  133. public async Task<IActionResult> CustomerInfo(CustomerDto dto)
  134. {
  135. try
  136. {
  137. Crm_DeleClient crm_Dele = await _clientRepository.GetAsync<Crm_DeleClient>(x => x.Id == dto.Id);
  138. if (crm_Dele == null)
  139. {
  140. return Ok(JsonView(false, "查询失败!"));
  141. }
  142. EncryptionProcessor.DecryptProperties(crm_Dele);
  143. List<Crm_VisaCustomerCompany> _VisaCustomerCompany = _clientRepository.Query<Crm_VisaCustomerCompany>(x => x.DcId == crm_Dele.Id && x.IsDel == 0).ToList();//客户工作经历表
  144. List<Crm_VisaCustomerSchool> _VisaCustomerSchool = _clientRepository.Query<Crm_VisaCustomerSchool>(x => x.DcId == crm_Dele.Id && x.IsDel == 0).ToList();//客户学历表
  145. List<Crm_VisaCustomerFamily> _VisaCustomerFamily = _clientRepository.Query<Crm_VisaCustomerFamily>(x => x.DcId == crm_Dele.Id && x.IsDel == 0).ToList();//客户学历表
  146. List<Crm_CustomerCert> _CustomerCerts = _clientRepository.Query<Crm_CustomerCert>(x => x.DcId == crm_Dele.Id && x.IsDel == 0).ToList();//客户证件表
  147. Crm_CustomerCompany _CustomerCompany = await _clientCompanyRepository.GetAsync<Crm_CustomerCompany>(x => x.Id == crm_Dele.CrmCompanyId);//客户公司信息
  148. var data = new
  149. {
  150. DeleClient = crm_Dele,
  151. WorkExperience = _VisaCustomerCompany,
  152. CustomerSchool = _VisaCustomerSchool,
  153. CustomerFamily = _VisaCustomerFamily,
  154. CustomerCompany = _CustomerCompany,
  155. CustomerCerts = _CustomerCerts
  156. };
  157. return Ok(JsonView(true, "查询成功!", data));
  158. }
  159. catch (Exception)
  160. {
  161. return Ok(JsonView(false, "程序错误!"));
  162. throw;
  163. }
  164. }
  165. /// <summary>
  166. /// 客户资料操作(Status:1.新增,2.修改)
  167. /// </summary>
  168. /// <param name="dto"></param>
  169. /// <returns></returns>
  170. [HttpPost]
  171. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  172. public async Task<IActionResult> EditCustomer(DeleClientOpDto dto)
  173. {
  174. try
  175. {
  176. Domain.Result result = await _clientRepository.OpCustomer(dto);
  177. if (result.Code != 0)
  178. {
  179. return Ok(JsonView(false, result.Msg));
  180. }
  181. return Ok(JsonView(true, result.Msg));
  182. }
  183. catch (Exception)
  184. {
  185. return Ok(JsonView(false, "程序错误!"));
  186. throw;
  187. }
  188. }
  189. /// <summary>
  190. /// 客户资料操作删除
  191. /// </summary>
  192. /// <param name="dto"></param>
  193. /// <returns></returns>
  194. [HttpPost]
  195. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  196. public async Task<IActionResult> DelCustomer(DeleClientDelDto dto)
  197. {
  198. Result result = await _clientRepository.DelCustomer(dto);
  199. if (result.Code != 0)
  200. {
  201. return Ok(JsonView(false, result.Msg));
  202. }
  203. return Ok(JsonView(true, result.Msg));
  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> DelCustomerCerts(DelBaseDto dto)
  213. {
  214. var result = await _customerCertRep.SoftDeleteByIdAsync<Crm_CustomerCert>(dto.Id.ToString(), dto.DeleteUserId);
  215. if (!result)
  216. {
  217. return Ok(JsonView(false, "删除失败"));
  218. }
  219. return Ok(JsonView(true, "删除成功!"));
  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> DelCustomerFamily(DelBaseDto dto)
  229. {
  230. var result = await _customerFamilyRep.SoftDeleteByIdAsync<Crm_VisaCustomerFamily>(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> DelCustomerSchool(DelBaseDto dto)
  245. {
  246. var result = await _customerSchoolRep.SoftDeleteByIdAsync<Crm_VisaCustomerSchool>(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> DelVisaCustomerCompany(DelBaseDto dto)
  261. {
  262. var result = await _customerCompanyRep.SoftDeleteByIdAsync<Crm_VisaCustomerCompany>(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> PostClient(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. }
  286. }