DelegationEnDataRepository.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using AutoMapper;
  2. using OASystem.Domain;
  3. using OASystem.Domain.Dtos.Groups;
  4. using OASystem.Domain.Entities.Groups;
  5. using OASystem.Domain.Entities.Resource;
  6. using OASystem.Domain.ViewModels.Groups;
  7. using OASystem.Infrastructure.Repositories.System;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace OASystem.Infrastructure.Repositories.Groups
  14. {
  15. public class DelegationEnDataRepository : BaseRepository<Grp_DelegationEnData, Grp_DelegationEnData>
  16. {
  17. private readonly IMapper _mapper;
  18. public DelegationEnDataRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
  19. {
  20. _mapper = mapper;
  21. }
  22. /// <summary>
  23. /// 团组英文资料操作(Status:1.新增,2.修改)
  24. /// </summary>
  25. /// <param name="dto"></param>
  26. /// <returns></returns>
  27. /// <exception cref="NotImplementedException"></exception>
  28. public async Task<Result> OpDelegationEnData(OpDelegationEnDataDto dto)
  29. {
  30. Result result = new Result() { Code = -2, Msg = "未知错误" };
  31. try
  32. {
  33. if (dto.Status == 1)//添加
  34. {
  35. string selectSql = string.Format(@"select * from Grp_DelegationEnData where Area='{0}' and Job='{1}' and IsDel='{2}'", dto.Area, dto.Job, 0);
  36. var grp_DelegationEnData = await _sqlSugar.SqlQueryable<Grp_DelegationEnData>(selectSql).FirstAsync();//查询是否存在
  37. if (grp_DelegationEnData != null)
  38. {
  39. return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
  40. }
  41. else//不存在,可添加
  42. {
  43. Grp_DelegationEnData _DelegationEnData = _mapper.Map<Grp_DelegationEnData>(dto);
  44. int id = await _sqlSugar.Insertable(_DelegationEnData).ExecuteReturnIdentityAsync();
  45. if (id == 0)
  46. {
  47. return result = new Result() { Code = -1, Msg = "添加失败!" };
  48. }
  49. return result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
  50. }
  51. }
  52. else if (dto.Status == 2)//修改
  53. {
  54. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationEnData
  55. {
  56. Area = dto.Area,
  57. Job = dto.Job,
  58. JobEn = dto.JobEn,
  59. DelegationSetting = dto.DelegationSetting,
  60. DelegationSettingEn = dto.DelegationSettingEn,
  61. CreateUserId = dto.CreateUserId,
  62. Remark = dto.Remark,
  63. });
  64. if (!res)
  65. {
  66. return result = new Result() { Code = -1, Msg = "修改失败!" };
  67. }
  68. return result = new Result() { Code = 0, Msg = "修改成功!", Data = new { Id = dto.Id } };
  69. }
  70. else
  71. {
  72. return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  73. }
  74. }
  75. catch (Exception ex)
  76. {
  77. return result = new Result() { Code = -2, Msg = "程序错误!" };
  78. }
  79. }
  80. public async Task<Result> QueryDelegationEnData(QueryDelegationEnDataDto dto)
  81. {
  82. Result result = new Result() { Code = -2, Msg = "未知错误" };
  83. try
  84. {
  85. string sqlWhere = string.Empty;
  86. if (!string.IsNullOrWhiteSpace(dto.Area))
  87. {
  88. sqlWhere += string.Format(@"And Area like '%{0}%'", dto.Area);
  89. }
  90. if (!string.IsNullOrWhiteSpace(dto.Job))
  91. {
  92. sqlWhere += string.Format(@"And Job like '%{0}%'", dto.Job);
  93. }
  94. sqlWhere += string.Format(@"And IsDel={0}", 0);
  95. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  96. {
  97. Regex r = new Regex("And");
  98. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  99. }
  100. string sql = string.Format(@"select * from Grp_DelegationEnData {0} order by CreateTime desc", sqlWhere);
  101. List<Grp_DelegationEnData> askDatd = await _sqlSugar.SqlQueryable<Grp_DelegationEnData>(sql).ToListAsync();
  102. if (askDatd.Count != 0 && askDatd.Count!=0)
  103. {
  104. result = new Result() { Code = 0, Msg = "查询成功!", Data =askDatd };
  105. }
  106. else
  107. {
  108. result = new Result() { Code = 0, Msg = "暂无数据!", Data =askDatd };
  109. }
  110. }
  111. catch (Exception ex)
  112. {
  113. result = new Result() { Code = -2, Msg = "未知错误" };
  114. }
  115. return result;
  116. }
  117. }
  118. }