HotelDataRepository.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using AutoMapper;
  2. using MathNet.Numerics.Statistics.Mcmc;
  3. using MySqlX.XDevAPI.Common;
  4. using NPOI.SS.Formula.Functions;
  5. using OASystem.Domain;
  6. using OASystem.Domain.AesEncryption;
  7. using OASystem.Domain.Dtos.Groups;
  8. using OASystem.Domain.Dtos.Resource;
  9. using OASystem.Domain.Entities.Resource;
  10. using OASystem.Domain.ViewModels.Resource;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using Result = OASystem.Domain.Result;
  17. namespace OASystem.Infrastructure.Repositories.Resource
  18. {
  19. public class HotelDataRepository:BaseRepository<Res_HotelData,HotelDataView>
  20. {
  21. private readonly IMapper _mapper;
  22. public HotelDataRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
  23. {
  24. _mapper= mapper;
  25. }
  26. public async Task<Result> _Info(int portType, int id)
  27. {
  28. if (id< 1) return new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  29. string sql = string.Format(@"SELECT
  30. Id,
  31. City,
  32. [Name],
  33. [Level],
  34. [Address],
  35. Tel,
  36. Fax,
  37. Contact,
  38. ContactPhone,
  39. OtherInformation,
  40. Remark
  41. FROM
  42. Res_HotelData
  43. WHERE
  44. IsDel = 0
  45. AND Id = {0}", id);
  46. if (portType == 1 || portType == 2 || portType == 3)
  47. {
  48. var info = await _sqlSugar.SqlQueryable<HotelDataInfoView>(sql).FirstAsync();
  49. EncryptionProcessor.DecryptProperties(info);// 解密属性
  50. if (info != null) return new Result() { Code = 0, Msg = "操作成功!",Data = info };
  51. return new Result() { Code = -1, Msg = "暂无数据!" };
  52. }
  53. return new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  54. }
  55. public async Task<Result> OperationHotelData(OperationHotelDto dto)
  56. {
  57. Result result = new Result() { Code = -2, Msg = "未知错误" };
  58. var hotelDataDto = _mapper.Map<Res_HotelData>(dto);
  59. EncryptionProcessor.EncryptProperties(hotelDataDto);// 加密属性
  60. if (dto.Status == 1)//添加
  61. {
  62. string selectSql = string.Format(@"select * from Res_HotelData where Name='{0}' and IsDel='{1}'"
  63. , dto.Name, 0);
  64. var HotelData = await _sqlSugar.Queryable<Res_HotelData>().Where(x => x.IsDel == 0 && x.Name.Contains(AesEncryptionHelper.Encrypt(dto.Name))).FirstAsync();//查询是否存在
  65. if (HotelData != null)
  66. {
  67. return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
  68. }
  69. else//不存在,可添加
  70. {
  71. int id = await AddAsyncReturnId(hotelDataDto);
  72. if (id == 0)
  73. {
  74. return result = new Result() { Code = -1, Msg = "添加失败!" };
  75. }
  76. return result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
  77. }
  78. }
  79. else if (dto.Status == 2)//修改
  80. {
  81. var res = await _sqlSugar.Updateable(hotelDataDto)
  82. .IgnoreColumns(x => new { x.CreateTime, x.CreateUserId, x.DeleteTime, x.DeleteUserId, x.IsDel })
  83. .ExecuteCommandAsync();
  84. if (res < 1)
  85. {
  86. return result = new Result() { Code = -1, Msg = "修改失败!" };
  87. }
  88. return result = new Result() { Code = 0, Msg = "修改成功!" };
  89. }
  90. else
  91. {
  92. return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  93. }
  94. }
  95. }
  96. }