HotelDataRepository.cs 3.8 KB

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