VisaDeleClientCompanyRepository.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using AutoMapper;
  2. using OASystem.Domain;
  3. using OASystem.Domain.Dtos;
  4. using OASystem.Domain.Dtos.CRM;
  5. using OASystem.Domain.Dtos.UserDto;
  6. using OASystem.Domain.Entities.Customer;
  7. using OASystem.Domain.Entities.Resource;
  8. using OASystem.Domain.ViewModels.CRM;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace OASystem.Infrastructure.Repositories.CRM
  15. {
  16. /// <summary>
  17. /// 签证客户公司
  18. /// 仓库
  19. /// </summary>
  20. public class VisaDeleClientCompanyRepository : BaseRepository<Crm_CustomerCompany, CustomerCompanyView>
  21. {
  22. private readonly IMapper _mapper;
  23. public VisaDeleClientCompanyRepository(SqlSugarClient sqlSugar, IMapper mapper) :
  24. base(sqlSugar)
  25. {
  26. _mapper= mapper;
  27. }
  28. /// <summary>
  29. /// 签证客户公司 List
  30. /// </summary>
  31. /// <param name="dto"></param>
  32. /// <returns></returns>
  33. public async Task<Result> GetCrm_ClientCompanyList(DtoBase dto)
  34. {
  35. Result result = new Result() { Code = -2 };
  36. try
  37. {
  38. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3)
  39. {
  40. string sql = string.Format(@"Select ccc.Id,ccc.CompanyFullName,ccc.CompanyAbbreviation,ccc.Address,ccc.PostCodes,su.CnName UserName,ccc.CreateTime,ccc.Remark
  41. From Crm_CustomerCompany ccc Inner Join Sys_Users su On ccc.CreateUserId = su.Id where ccc.IsDel=0 order by CreateTime Desc");
  42. var _clientCompanyList = await _sqlSugar.SqlQueryable<CustomerCompanyListView>(sql).ToListAsync();
  43. if (_clientCompanyList.Count > 0)
  44. {
  45. result.Code = 0;
  46. result.Msg = "成功!";
  47. result.Data = _clientCompanyList;
  48. }
  49. else
  50. {
  51. result.Msg = "查询失败!";
  52. }
  53. }
  54. }
  55. catch (Exception ex)
  56. {
  57. result.Msg = ex.Message;
  58. }
  59. return result;
  60. }
  61. public async Task<Result> OperationClientCompany(OperationClientCompanyDto dto)
  62. {
  63. Result result = new Result() { Code = -2, Msg = "未知错误" };
  64. try
  65. {
  66. if (dto.Status == 1)//添加
  67. {
  68. string selectSql = string.Format(@"select * from Crm_CustomerCompany WHERE CompanyName='{0}' and IsDel='{1}'"
  69. , dto.CompanyName, 0);
  70. var CustomerCompany = await _sqlSugar.SqlQueryable<Crm_CustomerCompany>(selectSql).FirstAsync();//查询是否存在
  71. if (CustomerCompany != null)
  72. {
  73. return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
  74. }
  75. else//不存在,可添加
  76. {
  77. Crm_CustomerCompany _CustomerCompany = _mapper.Map<Crm_CustomerCompany>(dto);
  78. int id = await AddAsyncReturnId(_CustomerCompany);
  79. if (id == 0)
  80. {
  81. return result = new Result() { Code = -1, Msg = "添加失败!" };
  82. }
  83. result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
  84. }
  85. }
  86. else if (dto.Status == 2)//修改
  87. {
  88. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Crm_CustomerCompany
  89. {
  90. CompanyFullName = dto.CompanyName,
  91. Address = dto.Address,
  92. PostCodes = dto.PostCodes,
  93. LastedOpUserId = dto.LastedOpUserId,
  94. LastedOpDt = dto.LastedOpDt,
  95. Remark = dto.Remark,
  96. });
  97. if (!res)
  98. {
  99. return result = new Result() { Code = -1, Msg = "修改失败!" };
  100. }
  101. result = new Result() { Code = 0, Msg = "修改成功!" };
  102. }
  103. else
  104. {
  105. return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  106. }
  107. }
  108. catch (Exception ex)
  109. {
  110. return result = new Result() { Code = -2, Msg = "程序错误!" };
  111. }
  112. return result;
  113. }
  114. }
  115. }