123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- using AutoMapper;
- using OASystem.Domain;
- using OASystem.Domain.AesEncryption;
- using OASystem.Domain.Dtos.Resource;
- using OASystem.Domain.Entities.Resource;
- using OASystem.Domain.ViewModels.Resource;
- using XAct;
- namespace OASystem.Infrastructure.Repositories.Resource
- {
- public class CarDataRepository: BaseRepository<Res_CarData, CarDataView>
- {
- private readonly IMapper _mapper;
- public CarDataRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
- {
- _mapper = mapper;
- }
- /// <summary>
- /// 查询用车资料
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- public async Task<Result> QueryCarData(QueryCarDataDto dto)
- {
- string sqlWhere = string.Empty;
- if (!string.IsNullOrWhiteSpace(dto.UnitName)) sqlWhere += string.Format(@" And UnitName like '%{0}%'", AesEncryptionHelper.Encrypt(dto.UnitName));
- if (!string.IsNullOrWhiteSpace(dto.UnitArea) && dto.UnitArea != "全部") sqlWhere += string.Format(@" And UnitArea like '%{0}%'", AesEncryptionHelper.Encrypt(dto.UnitArea));
- if (!string.IsNullOrWhiteSpace(dto.Contact)) sqlWhere += string.Format(@" And Contact like '%{0}%'", AesEncryptionHelper.Encrypt(dto.Contact));
- if (!string.IsNullOrWhiteSpace(dto.ContactTel)) sqlWhere += string.Format(@" And ContactTel like '%{0}%'", AesEncryptionHelper.Encrypt(dto.ContactTel));
- sqlWhere += string.Format(@" And IsDel={0}", 0);
- if (!string.IsNullOrEmpty(sqlWhere.Trim()))
- {
- Regex r = new Regex("And");
- sqlWhere = r.Replace(sqlWhere, "Where", 1);
- }
- if (dto.PortType == 1)
- {
- string sql = string.Format(@"select * from Res_CarData {0}", sqlWhere);
- var carDatas = await _sqlSugar.SqlQueryable<Res_CarData>(sql).ToListAsync();
- if (carDatas.Count == 0) return new Result() { Code = -1, Msg = "暂无数据" };
- carDatas = carDatas.OrderByDescending(x => x.CreateTime).ToList();
- if (dto.PageSize == 0 && dto.PageIndex == 0)
- {
- foreach (var item in carDatas) EncryptionProcessor.DecryptProperties(item);
- return new Result()
- {
- Code = 0,
- Msg = "查询成功",
- Data = carDatas,
- };
- }
- else
- {
- int count = carDatas.Count;
- float totalPage = (float)count / dto.PageSize;//总页数
- if (totalPage == 0) totalPage = 1;
- else totalPage = (int)Math.Ceiling((double)totalPage);
- var ListData = new List<Res_CarData>();
- for (int i = 0; i < dto.PageSize; i++)
- {
- var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
- if (RowIndex < carDatas.Count) {
- EncryptionProcessor.DecryptProperties(carDatas[RowIndex]);
- ListData.Add(carDatas[RowIndex]);
- }
- else break;
- }
- return new Result()
- {
- Code = 0,
- Msg = "查询成功",
- Data = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = ListData },
- };
- }
- }
- else if (dto.PortType == 2 || dto.PortType == 3)
- {
- string sql = string.Format(@"select * from Res_CarData {0}", sqlWhere);
- var carDatas = await _sqlSugar.SqlQueryable<Res_CarData>(sql).ToListAsync();
- if (carDatas.Count == 0) return new Result() { Code = -1, Msg = "暂无数据" };
- carDatas = carDatas.OrderByDescending(x => x.CreateTime).ToList();
- if (dto.PageSize == 0 || dto.PageIndex == 0)
- {
- foreach (var item in carDatas) EncryptionProcessor.DecryptProperties(item);
- return new Result()
- {
- Code = 0,
- Msg = "查询成功",
- Data = carDatas,
- };
- }
- else
- {
- int count = carDatas.Count;
- float totalPage = (float)count / dto.PageSize;//总页数
- if (totalPage == 0) totalPage = 1;
- else totalPage = (int)Math.Ceiling((double)totalPage);
- var ListData = new List<Res_CarData>();
- for (int i = 0; i < dto.PageSize; i++)
- {
- var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
- if (RowIndex < carDatas.Count)
- {
- EncryptionProcessor.DecryptProperties(carDatas[RowIndex]);
- ListData.Add(carDatas[RowIndex]);
- }
- else break;
- }
- return new Result()
- {
- Code = 0,
- Msg = "查询成功",
- Data = new { pageCount = count, totalPage = ((int)totalPage).ToString(), pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = ListData },
- };
- }
- }
- else return new Result() { Code = -2, Msg = MsgTips.Port };
- }
- }
- }
|