|
|
@@ -0,0 +1,324 @@
|
|
|
+using Aspose.Words.Lists;
|
|
|
+using AutoMapper;
|
|
|
+using OASystem.Domain;
|
|
|
+using OASystem.Domain.AesEncryption;
|
|
|
+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
|
|
|
+{
|
|
|
+ /// <summary>
|
|
|
+ /// 境外用车信息 仓储
|
|
|
+ /// </summary>
|
|
|
+ public class OverseaVehicleRepository : BaseRepository<Res_OverseaVehicle, Res_OverseaVehicle>
|
|
|
+ {
|
|
|
+ private readonly IMapper _mapper;
|
|
|
+ public OverseaVehicleRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
|
|
|
+ {
|
|
|
+ _mapper = mapper;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Init
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<JsonView> InitAsync()
|
|
|
+ {
|
|
|
+ var currencyDatas = await _sqlSugar.Queryable<Sys_SetData>()
|
|
|
+ .Where(x => x.STid == 66 && x.IsDel == 0)
|
|
|
+ .Select(x =>
|
|
|
+ new
|
|
|
+ {
|
|
|
+ x.Id,
|
|
|
+ x.Name
|
|
|
+ })
|
|
|
+ .ToListAsync();
|
|
|
+
|
|
|
+ var serviceTypeDatas = EnumHelper.ToSelectList<VehicleServiceTypeEnum>(false);
|
|
|
+
|
|
|
+ var init = new {
|
|
|
+ currencyDatas,
|
|
|
+ serviceTypeDatas
|
|
|
+ };
|
|
|
+
|
|
|
+ return new JsonView(init, 1, "操作成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// List
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<JsonView> ListAsync(OverseaVehicleListDto dto)
|
|
|
+ {
|
|
|
+ var search = dto.Search.Trim();
|
|
|
+ RefAsync<int> total = 0;
|
|
|
+ var infos = await _sqlSugar.Queryable<Res_OverseaVehicle>()
|
|
|
+ .Where(x => x.IsDel == 0)
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(search), x => x.ContinentName.Contains(search) || x.CountryName.Contains(search) || x.CityName.Contains(search))
|
|
|
+ .OrderByDescending(x => x.CreateTime)
|
|
|
+ .Select(x => new OverseaVehicleListView() {
|
|
|
+ Id = x.Id,
|
|
|
+ ContinentName = x.ContinentName,
|
|
|
+ CountryName = x.CountryName,
|
|
|
+ CityName = x.CityName,
|
|
|
+ GuidePrice = x.GuidePrice,
|
|
|
+ OtherPrice1 = x.OtherPrice1,
|
|
|
+ OtherPrice2 = x.OtherPrice2,
|
|
|
+ Currency = x.Currency.ToString(),
|
|
|
+ LastUpdateUserName = x.LastUpdateUserId.ToString(),
|
|
|
+ LastUpdateTime = x.LastUpdateTime.ToString("yyyy-MM-dd HH:mm:ss"),
|
|
|
+ Remark = x.Remark
|
|
|
+ })
|
|
|
+ .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
|
|
|
+
|
|
|
+ if (total == 0)
|
|
|
+ {
|
|
|
+ return new JsonView(infos, total, "暂无数据!");
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach (var item in infos)
|
|
|
+ {
|
|
|
+ if (int.TryParse(item.Currency,out int currencyId))
|
|
|
+ {
|
|
|
+ item.Currency = _sqlSugar.Queryable<Sys_SetData>().Where(y => y.Id == currencyId).First()?.Name ?? "-";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (int.TryParse(item.LastUpdateUserName, out int lastUpdateUserId))
|
|
|
+ {
|
|
|
+ item.LastUpdateUserName = _sqlSugar.Queryable<Sys_Users>().Where(y => y.Id == lastUpdateUserId).First()?.CnName ?? "-";
|
|
|
+ }
|
|
|
+
|
|
|
+ item.CarInfos = _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
|
|
|
+ .Where(x => x.IsDel == 0 && x.OvId == item.Id)
|
|
|
+ .Select(x => new OverseaVehicleTypeListView() {
|
|
|
+ Id = x.Id,
|
|
|
+ CarTypeName = x.CarTypeName,
|
|
|
+ ServiceType = x.ServiceType,
|
|
|
+ Price = x.Price,
|
|
|
+ Remark = x.Remark
|
|
|
+ })
|
|
|
+ .ToList();
|
|
|
+ }
|
|
|
+
|
|
|
+ return new JsonView(infos, total, "操作成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 详细信息
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<JsonView> InfoAsync(int id)
|
|
|
+ {
|
|
|
+ if (id < 1) return new JsonView(false, "请传入有效的ID!");
|
|
|
+
|
|
|
+ var info = await _sqlSugar.Queryable<Res_OverseaVehicle>()
|
|
|
+ .Where(it => it.Id == id && it.IsDel == 0)
|
|
|
+ .FirstAsync();
|
|
|
+ if (info == null) return new JsonView(false, "暂无数据!");
|
|
|
+
|
|
|
+ var subInfos = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
|
|
|
+ .Where(it => it.OvId == id && it.IsDel == 0)
|
|
|
+ .ToListAsync();
|
|
|
+
|
|
|
+ var view = _mapper.Map<OverseaVehicleInfoView>(info);
|
|
|
+ view.CarInfos = _mapper.Map<List<OverseaVehicleTypeInfoView>>(subInfos);
|
|
|
+
|
|
|
+ return new JsonView(view, 1, "操作成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 添加
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<JsonView> AddAsync(OverseaVehicleAddOrEditDto dto)
|
|
|
+ {
|
|
|
+ //参数处理
|
|
|
+ var now = DateTime.Now;
|
|
|
+ var info = _mapper.Map<Res_OverseaVehicle>(dto);
|
|
|
+ info.CreateUserId = dto.CurrUserId;
|
|
|
+ info.LastUpdateUserId = dto.CurrUserId;
|
|
|
+ info.LastUpdateTime = now;
|
|
|
+ var subInfos = _mapper.Map<List<Res_OverseaVehicleTypePrice>>(dto.CarInfos);
|
|
|
+ if (subInfos == null && subInfos.Count < 1)
|
|
|
+ {
|
|
|
+ return new JsonView(false, $"请填写车型信息!");
|
|
|
+ }
|
|
|
+
|
|
|
+ _sqlSugar.BeginTran();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var infoIsNul = await _sqlSugar.Queryable<Res_OverseaVehicle>()
|
|
|
+ .Where(x => x.IsDel == 0)
|
|
|
+ .Where(x => x.ContinentName.Equals(dto.ContinentName.Trim()))
|
|
|
+ .Where(x => x.CountryName.Equals(dto.CountryName.Trim()))
|
|
|
+ .Where(x => x.CityName.Equals(dto.CityName.Trim()))
|
|
|
+ .AnyAsync();
|
|
|
+ if (infoIsNul)
|
|
|
+ {
|
|
|
+ return new JsonView(false, $"该城市已存在,不可重复添加!");
|
|
|
+ }
|
|
|
+
|
|
|
+ var infoId = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
|
|
|
+ if (infoId < 1)
|
|
|
+ {
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return new JsonView(false, $"车信息,操作失败!");
|
|
|
+ }
|
|
|
+ foreach (var subInfo in subInfos) {
|
|
|
+ subInfo.OvId = infoId;
|
|
|
+ subInfo.CreateUserId = dto.CurrUserId;
|
|
|
+ subInfo.LastUpdateUserId = dto.CurrUserId;
|
|
|
+ subInfo.LastUpdateTime = DateTime.Now;
|
|
|
+ }
|
|
|
+ var subCount = await _sqlSugar.Insertable(subInfos).ExecuteCommandAsync();
|
|
|
+ if (subCount < 1)
|
|
|
+ {
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return new JsonView(false, $"车型信息,操作失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return new JsonView(false, $"操作失败!ex:{ex.Message}");
|
|
|
+ }
|
|
|
+ _sqlSugar.CommitTran();
|
|
|
+
|
|
|
+ return new JsonView(true, "操作成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 编辑
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<JsonView> EditAsync(OverseaVehicleAddOrEditDto dto)
|
|
|
+ {
|
|
|
+ //参数处理
|
|
|
+ var now = DateTime.Now;
|
|
|
+ var info = _mapper.Map<Res_OverseaVehicle>(dto);
|
|
|
+ info.LastUpdateUserId = dto.CurrUserId;
|
|
|
+ info.LastUpdateTime = now;
|
|
|
+ var subInfos = _mapper.Map<List<Res_OverseaVehicleTypePrice>>(dto.CarInfos);
|
|
|
+ if (subInfos == null && subInfos.Count < 1)
|
|
|
+ {
|
|
|
+ return new JsonView(false, $"请填写车型信息!");
|
|
|
+ }
|
|
|
+
|
|
|
+ _sqlSugar.BeginTran();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var infoId = await _sqlSugar.Updateable(info)
|
|
|
+ .UpdateColumns(it => new
|
|
|
+ {
|
|
|
+ it.ContinentName,
|
|
|
+ it.CountryName,
|
|
|
+ it.CityName,
|
|
|
+ it.GuidePrice,
|
|
|
+ it.OtherPrice1,
|
|
|
+ it.OtherPrice2,
|
|
|
+ it.Currency,
|
|
|
+ it.LastUpdateUserId,
|
|
|
+ it.LastUpdateTime,
|
|
|
+ it.Remark
|
|
|
+ })
|
|
|
+ .Where(it => it.Id == info.Id)
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+ if (infoId < 1)
|
|
|
+ {
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return new JsonView(false, $"车信息,操作失败!");
|
|
|
+ }
|
|
|
+ foreach (var subInfo in subInfos)
|
|
|
+ {
|
|
|
+ subInfo.LastUpdateUserId = dto.CurrUserId;
|
|
|
+ subInfo.LastUpdateTime = DateTime.Now;
|
|
|
+ }
|
|
|
+ var subCount = await _sqlSugar.Updateable(subInfos)
|
|
|
+ .UpdateColumns(it => new
|
|
|
+ {
|
|
|
+ it.CarTypeName,
|
|
|
+ it.ServiceType,
|
|
|
+ it.Price,
|
|
|
+ it.LastUpdateUserId,
|
|
|
+ it.LastUpdateTime,
|
|
|
+ it.Remark
|
|
|
+ })
|
|
|
+ .WhereColumns (it => new { it.Id })
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+ if (subCount < 1)
|
|
|
+ {
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return new JsonView(false, $"车型信息,操作失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return new JsonView(false, $"操作失败!ex:{ex.Message}");
|
|
|
+ }
|
|
|
+ _sqlSugar.CommitTran();
|
|
|
+
|
|
|
+ return new JsonView(true, "操作成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 删除
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<JsonView> DelAsync(OverseaVehicleDelDto dto)
|
|
|
+ {
|
|
|
+ //参数处理
|
|
|
+ var now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
+ _sqlSugar.BeginTran();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var infoId = await _sqlSugar.Updateable<Res_OverseaVehicle>()
|
|
|
+ .SetColumns(x => x.IsDel == 1)
|
|
|
+ .SetColumns(x => x.DeleteUserId == dto.CurrUserId)
|
|
|
+ .SetColumns(x => x.DeleteTime == now)
|
|
|
+ .Where(it => it.Id == dto.Id)
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+ if (infoId < 1)
|
|
|
+ {
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return new JsonView(false, $"车信息,操作失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ var subCount = await _sqlSugar.Updateable<Res_OverseaVehicleTypePrice>()
|
|
|
+ .SetColumns(x => x.IsDel == 1)
|
|
|
+ .SetColumns(x => x.DeleteUserId == dto.CurrUserId)
|
|
|
+ .SetColumns(x => x.DeleteTime == now)
|
|
|
+ .Where(it => it.OvId == dto.Id)
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+ if (subCount < 1)
|
|
|
+ {
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return new JsonView(false, $"车型信息,操作失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return new JsonView(false, $"操作失败!ex:{ex.Message}");
|
|
|
+ }
|
|
|
+ _sqlSugar.CommitTran();
|
|
|
+
|
|
|
+ return new JsonView(true, "操作成功!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|