CountryFeeRepository.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. using AutoMapper;
  2. using OASystem.Domain.Dtos.Resource;
  3. using OASystem.Domain.Entities.Resource;
  4. using OASystem.Domain.ViewModels.Resource;
  5. namespace OASystem.Infrastructure.Repositories.Resource
  6. {
  7. public class CountryFeeRepository : BaseRepository<Res_CountryFeeCost, CountryFeeCostView>
  8. {
  9. private readonly IMapper _mapper;
  10. public CountryFeeRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
  11. {
  12. _mapper = mapper;
  13. }
  14. public async Task<Res_CountryFeeCost> InfoByCountryName(string countryName)
  15. {
  16. if (string.IsNullOrEmpty(countryName)) return null;
  17. return await _sqlSugar.Queryable<Res_CountryFeeCost>()
  18. .FirstAsync(it => it.VisaCountry == countryName);
  19. }
  20. public async Task<JsonView> OperationCountryFeeCost(OperationCountryFeeCostDto dto)
  21. {
  22. var result = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "未知错误" };
  23. var countryFeeCost = _mapper.Map<Res_CountryFeeCost>(dto);
  24. countryFeeCost.LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  25. if (dto.Status == 1)//添加
  26. {
  27. var exists = await _sqlSugar.Queryable<Res_CountryFeeCost>()
  28. .AnyAsync(x => x.IsDel == 0 &&
  29. x.VisaFeeType == dto.VisaFeeType &&
  30. x.VisaContinent == dto.VisaContinent &&
  31. x.VisaCountry == dto.VisaCountry);
  32. if (exists)
  33. {
  34. result.Msg = "该国家已存在,请勿重复添加!";
  35. return result;
  36. }
  37. else//不存在,可添加
  38. {
  39. int id = await AddAsyncReturnId(countryFeeCost);
  40. if (id == 0)
  41. {
  42. result.Msg = "添加失败!";
  43. return result;
  44. }
  45. result.Code = StatusCodes.Status200OK;
  46. result.Msg = "添加成功!";
  47. }
  48. }
  49. else if (dto.Status == 2)//修改
  50. {
  51. var update = await _sqlSugar
  52. .Updateable(countryFeeCost)
  53. .IgnoreColumns(it => new { it.Id, it.DeleteUserId, it.DeleteTime, it.CreateUserId, it.CreateTime, it.IsDel })
  54. .Where(it => it.Id == countryFeeCost.Id)
  55. .ExecuteCommandAsync();
  56. //bool res = await UpdateAsync(a => a.Id == dto.Id, a => _CountryFeeCost);
  57. if (update < 1)
  58. {
  59. result.Msg = "修改失败!";
  60. return result;
  61. }
  62. result.Code = StatusCodes.Status200OK;
  63. result.Msg = "修改成功!";
  64. }
  65. else
  66. {
  67. result.Msg = "请传入Status参数,1添加 2修改!";
  68. }
  69. return result;
  70. }
  71. #region New
  72. /// <summary>
  73. /// Page List Async
  74. /// </summary>
  75. /// <param name="dto"></param>
  76. /// <returns></returns>
  77. public async Task<JsonView> PageListAsync(VisaFeeStandardListDto dto)
  78. {
  79. int pageIndex = dto.PageIndex <= 0 ? 1 : dto.PageIndex;
  80. int pageSize = dto.PageSize <= 0 ? 10 : dto.PageSize;
  81. int feeType = dto.VisaFeeType < 0 ? -1 : dto.VisaFeeType; // -1:全部 0:因公 1:因私
  82. string countryName = dto.CountryName?.Trim() ?? string.Empty;
  83. var query = _sqlSugar.Queryable<Res_VisaFeeStandard>()
  84. .LeftJoin<Sys_Users>((x, y) => x.LastUpdateUserId == y.Id)
  85. .Where((x, y) => x.IsDel == 0 && x.FeeType == feeType)
  86. .WhereIF(!string.IsNullOrEmpty(countryName), x => x.Country.Contains(countryName) || countryName.Contains(x.Country))
  87. .OrderByDescending((x, y) => x.LastUpdateTime)
  88. .Select((x, y) => new VisaFeeStandardListView
  89. {
  90. Id = x.Id,
  91. Continent = x.Continent,
  92. Country = x.Country,
  93. FeeType = x.FeeType,
  94. LastUpdateUserName = y.CnName,
  95. LastUpdateTime = x.LastUpdateTime
  96. });
  97. RefAsync<int> total = 0;
  98. var pageList = await query.ToPageListAsync(pageIndex, pageSize, total);
  99. if (!pageList.Any())
  100. {
  101. return new JsonView
  102. {
  103. Code = StatusCodes.Status200OK,
  104. Data = pageList,
  105. Count = total,
  106. Msg = "暂无数据!"
  107. };
  108. }
  109. var ids = pageList.Select(x => x.Id).ToList();
  110. var detailsList = await _sqlSugar.Queryable<Res_VisaFeeStandardDetails>()
  111. .LeftJoin<Sys_Cities>((x, y) => x.ProvinceId == y.Id && (y.Level == 1 || y.Level == 4))
  112. .Where((x, y) => ids.Contains(x.ParentId) && x.IsDel == 0)
  113. .Select((x, y) => new VisaFeeStandardDetails
  114. {
  115. Id = x.Id,
  116. ParentId = x.ParentId,
  117. ProvinceId = x.ProvinceId,
  118. ProvinceName = y.Name_CN,
  119. VisaAddress = x.VisaAddress,
  120. IsVisaOnArrival = x.IsVisaOnArrival,
  121. IsElectronicSign = x.IsElectronicSign,
  122. VisaTime = x.VisaTime,
  123. IsVisaExemptionLarge = x.IsVisaExemptionLarge,
  124. LargeVisaPrice = x.LargeVisaPrice,
  125. LargeAgencyFee = x.LargeAgencyFee,
  126. IsVisaExemptionSmall = x.IsVisaExemptionSmall,
  127. SmallVisaPrice = x.SmallVisaPrice,
  128. SmallAgencyFee = x.SmallAgencyFee,
  129. NormExtFee = x.NormExtFee,
  130. UrgExtFee = x.UrgExtFee,
  131. IsUrgent = x.IsUrgent,
  132. UrgentTime = x.UrgentTime,
  133. UrgentPrice = x.UrgentPrice,
  134. UrgentPriceDesc = x.UrgentPriceDesc,
  135. Remark = x.Remark,
  136. })
  137. .ToListAsync();
  138. var specifiedOrder = new List<string> { "四川", "重庆", "贵州", "云南" };
  139. foreach (var item in pageList)
  140. {
  141. var provinceDetails = detailsList.Where(x => x.ParentId == item.Id).ToList();
  142. if (provinceDetails.Any())
  143. provinceDetails = VisaFeeStandardDetails.SortByProvinces(provinceDetails, specifiedOrder);
  144. item.VisaFees = provinceDetails;
  145. }
  146. return new JsonView
  147. {
  148. Code = StatusCodes.Status200OK,
  149. Data = pageList,
  150. Count = total,
  151. Msg = "操作成功!"
  152. };
  153. }
  154. /// <summary>
  155. /// info Async
  156. /// </summary>
  157. /// <param name="id"></param>
  158. /// <returns></returns>
  159. public async Task<JsonView> InfoAsync(int id)
  160. {
  161. var view = await Query<Res_VisaFeeStandard>(x => x.Id == id)
  162. .Select(x => new VisaFeeStandardInfoView()
  163. {
  164. Id = x.Id,
  165. Continent = x.Continent,
  166. Country = x.Country,
  167. FeeType = x.FeeType,
  168. })
  169. .FirstAsync();
  170. if (view == null)
  171. {
  172. return new JsonView
  173. {
  174. Code = StatusCodes.Status200OK,
  175. Msg = "暂无数据!",
  176. Data = view
  177. };
  178. }
  179. var detailsList = await _sqlSugar.Queryable<Res_VisaFeeStandardDetails>()
  180. .LeftJoin<Sys_Cities>((x, y) => x.ProvinceId == y.Id && (y.Level == 1 || y.Level == 4))
  181. .Where((x, y) => x.ParentId == view.Id && x.IsDel == 0)
  182. .Select((x, y) => new VisaFeeStandardDetails
  183. {
  184. Id = x.Id,
  185. ParentId = x.ParentId,
  186. ProvinceId = x.ProvinceId,
  187. ProvinceName = y.Name_CN,
  188. VisaAddress = x.VisaAddress,
  189. IsVisaOnArrival = x.IsVisaOnArrival,
  190. IsElectronicSign = x.IsElectronicSign,
  191. VisaTime = x.VisaTime,
  192. IsVisaExemptionLarge = x.IsVisaExemptionLarge,
  193. LargeVisaPrice = x.LargeVisaPrice,
  194. LargeAgencyFee = x.LargeAgencyFee,
  195. IsVisaExemptionSmall = x.IsVisaExemptionSmall,
  196. SmallVisaPrice = x.SmallVisaPrice,
  197. SmallAgencyFee = x.SmallAgencyFee,
  198. NormExtFee = x.NormExtFee,
  199. UrgExtFee = x.UrgExtFee,
  200. IsUrgent = x.IsUrgent,
  201. UrgentTime = x.UrgentTime,
  202. UrgentPrice = x.UrgentPrice,
  203. UrgentPriceDesc = x.UrgentPriceDesc,
  204. Remark = x.Remark,
  205. })
  206. .ToListAsync();
  207. // 指定的省份顺序
  208. var specifiedOrder = new List<string> { "四川", "重庆", "贵州", "云南" };
  209. if (detailsList.Any())
  210. detailsList = VisaFeeStandardDetails.SortByProvinces(detailsList, specifiedOrder);
  211. view.VisaFees = detailsList;
  212. return new JsonView
  213. {
  214. Code = StatusCodes.Status200OK,
  215. Msg = "操作成功!",
  216. Data = view
  217. };
  218. }
  219. /// <summary>
  220. /// Save Async
  221. /// </summary>
  222. /// <param name="id"></param>
  223. /// <returns></returns>
  224. public async Task<JsonView> SaveAsync(VisaFeeStandardSaveDto dto)
  225. {
  226. var now = DateTime.Now;
  227. var standardInfo = _mapper.Map<Res_VisaFeeStandard>(dto);
  228. standardInfo.LastUpdateTime = now;
  229. standardInfo.LastUpdateUserId = dto.CurrUserId;
  230. standardInfo.CreateTime = now;
  231. standardInfo.CreateUserId = dto.CurrUserId;
  232. // 指定的省份顺序
  233. var specifiedOrder = new List<string> { "四川", "重庆", "贵州", "云南" };
  234. if (dto.VisaFees.Any())
  235. dto.VisaFees = VisaFeeStandardDetails.SortByProvinces(dto.VisaFees, specifiedOrder);
  236. var standardDetails = _mapper.Map<List<Res_VisaFeeStandardDetails>>(dto.VisaFees);
  237. standardDetails.ForEach(x =>
  238. {
  239. x.CreateUserId = dto.CurrUserId;
  240. x.CreateTime = now;
  241. });
  242. _sqlSugar.BeginTran();
  243. try
  244. {
  245. if (standardInfo.Id < 1) // 添加
  246. {
  247. var insertId = await _sqlSugar.Insertable(standardInfo).ExecuteReturnIdentityAsync();
  248. if (insertId < 1)
  249. {
  250. _sqlSugar.RollbackTran();
  251. return new JsonView { Code = StatusCodes.Status400BadRequest, Msg = "添加失败!" };
  252. }
  253. standardDetails.ForEach(x => x.ParentId = insertId);
  254. var detailsResult = await _sqlSugar.Insertable(standardDetails).ExecuteCommandAsync();
  255. if (detailsResult < 1)
  256. {
  257. _sqlSugar.RollbackTran();
  258. return new JsonView { Code = StatusCodes.Status400BadRequest, Msg = "添加失败!" };
  259. }
  260. }
  261. else // 修改
  262. {
  263. var updStatus = await _sqlSugar.Updateable(standardInfo)
  264. .IgnoreColumns(x => new { x.IsDel, x.CreateUserId, x.CreateTime, x.DeleteUserId, x.DeleteTime })
  265. .ExecuteCommandAsync();
  266. if (updStatus < 1)
  267. {
  268. _sqlSugar.RollbackTran();
  269. return new JsonView { Code = StatusCodes.Status400BadRequest, Msg = "修改失败!" };
  270. }
  271. await _sqlSugar.Deleteable<Res_VisaFeeStandardDetails>()
  272. .Where(x => x.ParentId == standardInfo.Id)
  273. .ExecuteCommandAsync();
  274. standardDetails.ForEach(x => x.ParentId = standardInfo.Id);
  275. var detailsResult = await _sqlSugar.Insertable(standardDetails).ExecuteCommandAsync();
  276. if (detailsResult < 1)
  277. {
  278. _sqlSugar.RollbackTran();
  279. return new JsonView { Code = StatusCodes.Status400BadRequest, Msg = "修改失败!" };
  280. }
  281. }
  282. _sqlSugar.CommitTran();
  283. return new JsonView { Code = StatusCodes.Status200OK, Msg = "操作成功!" };
  284. }
  285. catch (Exception ex)
  286. {
  287. _sqlSugar.RollbackTran();
  288. return new JsonView { Code = StatusCodes.Status400BadRequest, Msg = ex.Message };
  289. }
  290. }
  291. /// <summary>
  292. /// SoftDel Async
  293. /// </summary>
  294. /// <param name="userId"></param>
  295. /// <param name="id"></param>
  296. /// <returns></returns>
  297. public async Task<JsonView> SoftDelAsync(int userId, int id)
  298. {
  299. _sqlSugar.BeginTran();
  300. try
  301. {
  302. var nowString = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  303. // 主表软删除
  304. var delStatus = await _sqlSugar.Updateable<Res_VisaFeeStandard>()
  305. .SetColumns(x => x.DeleteUserId == userId)
  306. .SetColumns(x => x.DeleteTime == nowString)
  307. .SetColumns(x => x.IsDel == 1)
  308. .Where(x => x.Id == id)
  309. .ExecuteCommandAsync();
  310. if (delStatus < 1)
  311. {
  312. _sqlSugar.RollbackTran();
  313. return new JsonView { Code = StatusCodes.Status400BadRequest, Msg = "删除失败!" };
  314. }
  315. // 子表软删除
  316. await _sqlSugar.Updateable<Res_VisaFeeStandardDetails>()
  317. .SetColumns(x => x.DeleteUserId == userId)
  318. .SetColumns(x => x.DeleteTime == nowString)
  319. .SetColumns(x => x.IsDel == 1)
  320. .Where(x => x.ParentId == id)
  321. .ExecuteCommandAsync();
  322. _sqlSugar.CommitTran();
  323. return new JsonView { Code = StatusCodes.Status200OK, Msg = "操作成功!" };
  324. }
  325. catch (Exception ex)
  326. {
  327. _sqlSugar.RollbackTran();
  328. return new JsonView { Code = StatusCodes.Status400BadRequest, Msg = ex.Message };
  329. }
  330. }
  331. /// <summary>
  332. /// 签证费用报价计算 Async
  333. /// </summary>
  334. /// <param name="provinceId"></param>
  335. /// <param name="countryName"></param>
  336. /// <returns></returns>
  337. public async Task<JsonView> VisaFeeQuoteAsync(int provinceId, string countryName)
  338. {
  339. var info = await _sqlSugar.Queryable<Res_VisaFeeStandard>()
  340. .FirstAsync(x => x.IsDel == 0 && x.Country.Contains(countryName));
  341. if (info == null)
  342. return new JsonView { Code = StatusCodes.Status400BadRequest, Msg = $"{countryName} 该国家签证费用信息不存在" };
  343. var details = await _sqlSugar.Queryable<Res_VisaFeeStandardDetails>()
  344. .FirstAsync(x => x.IsDel == 0 && x.ParentId == info.Id && x.ProvinceId == provinceId);
  345. if (details == null)
  346. return new JsonView { Code = StatusCodes.Status400BadRequest, Msg = $"{countryName} 该国家签证费用信息不存在" };
  347. decimal largeVisaQuote = 0.00M, // 公务签证报价
  348. smallVisaQuote = 0.00M, // 公务普通签证报价
  349. quotePrice1 = 0.00M; // 报价费用1
  350. var visaFeeLabel = new StringBuilder(); //签证费用描述
  351. // 103 重庆
  352. // 108 贵州
  353. // 122 四川
  354. // 132 云南
  355. if (provinceId == 103) //重庆
  356. {
  357. }
  358. else if (provinceId == 108) //贵州
  359. {
  360. }
  361. else if (provinceId == 122) //四川
  362. {
  363. }
  364. else if (provinceId == 132) //云南
  365. {
  366. }
  367. return new JsonView { Code = StatusCodes.Status400BadRequest, Msg = "-" };
  368. }
  369. #endregion
  370. }
  371. }