CountryFeeRepository.cs 17 KB

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