using AutoMapper; using OASystem.Domain; using OASystem.Domain.Dtos.Resource; using OASystem.Domain.Entities.Groups; using OASystem.Domain.Entities.Resource; using OASystem.Domain.ViewModels.Resource; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace OASystem.Infrastructure.Repositories.Resource { public class AskDataRepository : BaseRepository { private readonly IMapper _mapper; public AskDataRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar) { _mapper = mapper; } public async Task QueryAskData(QueryAskDataDto dto) { Result result = new Result() { Code = -2, Msg = "未知错误" }; try { string sqlWhere = string.Empty; if (!string.IsNullOrWhiteSpace(dto.Country)) { sqlWhere += string.Format(@"And Country like '%{0}%'", dto.Country); } if (!string.IsNullOrWhiteSpace(dto.Area)) { sqlWhere += string.Format(@"And Area like '%{0}%'", dto.Area); } if (!string.IsNullOrWhiteSpace(dto.Field)) { sqlWhere += string.Format(@"And Field like '%{0}%'", dto.Field); } sqlWhere += string.Format(@"And IsDel={0}", 0); if (!string.IsNullOrEmpty(sqlWhere.Trim())) { Regex r = new Regex("And"); sqlWhere = r.Replace(sqlWhere, "Where", 1); } string sql = string.Format(@"select * from Res_AskData {0}", sqlWhere); List askDatd = await _sqlSugar.SqlQueryable(sql).ToListAsync(); List delegationInfo=await _sqlSugar.Queryable().Where(a=>a.IsDel==0).ToListAsync(); if (askDatd.Count != 0 && delegationInfo.Count!=0) { result = new Result() { Code = 0, Msg = "查询成功!", Data = new { askDatd= askDatd, delegationInfo= delegationInfo } }; } else { result = new Result() { Code = 0, Msg = "暂无数据!", Data = new { askDatd = askDatd, delegationInfo = delegationInfo } }; } } catch (Exception ex) { result = new Result() { Code = -2, Msg = "未知错误" }; } return result; } } }