CRMController.cs 12 KB

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