CountryFeeRepository.cs 17 KB

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