VisaDeleClientCompanyRepository.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. if (dto.PortType == 1 || dto.PortType == 2)
  37. {
  38. string sql = string.Format(@"Select ccc.Id,ccc.CompanyName,ccc.Address,ccc.PostCodes,su.CnName UserName,ccc.CreateTime,ccc.Remark
  39. From Crm_CustomerCompany ccc Inner Join Sys_Users su On ccc.CreateUserId = su.Id where ccc.IsDel=0 order by CreateTime Desc");
  40. var _clientCompanyList = await _sqlSugar.SqlQueryable<CustomerCompanyListView>(sql).ToListAsync();
  41. if (_clientCompanyList.Count > 0)
  42. {
  43. result.Code = 0;
  44. result.Msg = "成功!";
  45. result.Data = _clientCompanyList;
  46. }
  47. else
  48. {
  49. result.Msg = "查询失败!";
  50. }
  51. }
  52. return result;
  53. }
  54. public async Task<Result> OperationClientCompany(OperationClientCompanyDto dto)
  55. {
  56. Result result = new Result() { Code = -2, Msg = "未知错误" };
  57. try
  58. {
  59. if (dto.Status == 1)//添加
  60. {
  61. string selectSql = string.Format(@"select * from Crm_CustomerCompany WHERE CompanyName='{0}' and IsDel='{1}'"
  62. , dto.CompanyName, 0);
  63. var CustomerCompany = await _sqlSugar.SqlQueryable<Crm_CustomerCompany>(selectSql).FirstAsync();//查询是否存在
  64. if (CustomerCompany != null)
  65. {
  66. return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
  67. }
  68. else//不存在,可添加
  69. {
  70. Crm_CustomerCompany _CustomerCompany = _mapper.Map<Crm_CustomerCompany>(dto);
  71. int id = await AddAsyncReturnId(_CustomerCompany);
  72. if (id == 0)
  73. {
  74. return result = new Result() { Code = -1, Msg = "添加失败!" };
  75. }
  76. result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
  77. }
  78. }
  79. else if (dto.Status == 2)//修改
  80. {
  81. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Crm_CustomerCompany
  82. {
  83. CompanyName=dto.CompanyName,
  84. Address = dto.Address,
  85. PostCodes = dto.PostCodes,
  86. LastedOpUserId = dto.LastedOpUserId,
  87. LastedOpDt = dto.LastedOpDt,
  88. Remark = dto.Remark,
  89. });
  90. if (!res)
  91. {
  92. return result = new Result() { Code = -1, Msg = "修改失败!" };
  93. }
  94. result = new Result() { Code = 0, Msg = "修改成功!" };
  95. }
  96. else
  97. {
  98. return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  99. }
  100. }
  101. catch (Exception ex)
  102. {
  103. return result = new Result() { Code = -2, Msg = "程序错误!" };
  104. }
  105. return result;
  106. }
  107. }
  108. }