EnterExitCostRepository.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. 
  2. using AutoMapper;
  3. using OASystem.Domain;
  4. using OASystem.Domain.Dtos.Groups;
  5. using OASystem.Domain.Entities.Groups;
  6. using OASystem.Domain.ViewModels.Groups;
  7. using OASystem.Infrastructure.Repositories.System;
  8. using OASystem.Infrastructure.Tools;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace OASystem.Infrastructure.Repositories.Groups
  15. {
  16. /// <summary>
  17. /// 出入境费用 仓库
  18. /// </summary>
  19. public class EnterExitCostRepository:BaseRepository<Grp_EnterExitCost, EnterExitCostView>
  20. {
  21. private readonly IMapper _mapper;
  22. private readonly SetDataRepository _setDataRep;
  23. public EnterExitCostRepository(SqlSugarClient sqlSugar, IMapper mapper, SetDataRepository setDataRep)
  24. :base(sqlSugar)
  25. {
  26. _setDataRep = setDataRep;
  27. _mapper = mapper;
  28. }
  29. /// <summary>
  30. /// 更新出入境费用汇率信息
  31. /// </summary>
  32. /// <returns></returns>
  33. public async Task<Result> SetEnterExitCostCurrencyChange()
  34. {
  35. Result result = new Result { Code = -1, Msg = "未知错误" };
  36. var enterExitList = await _sqlSugar.Queryable<Grp_EnterExitCost>().ToListAsync();
  37. foreach (var item in enterExitList)
  38. {
  39. string rateStr = string.Format(@"美元(USD):{0}|日元(JPY):{1}|欧元(EUR):{2}|英镑(GBP):{3}|港币(HKD):{4}", item.RateUSD,item.RateJPY,item.RateEUR,item.RateGBP,item.RateHKD);
  40. item.CurrencyRemark = rateStr;
  41. }
  42. var res = await _sqlSugar.Updateable(enterExitList)
  43. .WhereColumns(it => new { it.Id })
  44. .UpdateColumns(it => new { it.CurrencyRemark })
  45. .ExecuteCommandAsync();
  46. if (res > 0)
  47. {
  48. result.Code = 0;
  49. result.Msg = res.ToString();
  50. return result;
  51. }
  52. return result;
  53. }
  54. /// <summary>
  55. /// 查询 根据 Diid 查询
  56. /// </summary>
  57. /// <returns></returns>
  58. public async Task<Result> GetEnterExitCostInfoByDiId(EnterExitCostInfobyDiIdDto dto)
  59. {
  60. Result result = new Result();
  61. var enterExitCostData = await _sqlSugar.Queryable<Grp_EnterExitCost>().FirstAsync(it => it.DiId == dto.DiId && it.IsDel == 0);
  62. //Sys_PageFunctionPermission Function = _mapper.Map<Sys_PageFunctionPermission>(dto);
  63. EnterExitCostInfoView enterExitCostInfoView = new EnterExitCostInfoView();
  64. if (dto.PortType == 1) // Web
  65. {
  66. if (enterExitCostData != null)
  67. {
  68. enterExitCostInfoView = _mapper.Map<EnterExitCostInfoView>(enterExitCostData);
  69. var dayAndCostSql = string.Format(@"Select ntf.Country,ntf.City,ssd.Name CurremcyCode,ssd.Remark CurrencyName,gdac.* From Grp_DayAndCost gdac
  70. Left Join Grp_NationalTravelFee ntf On ntf.Id = gdac.NationalTravelFeeId
  71. Left Join Sys_SetData ssd On ssd.STid = 66 And gdac.Currency = ssd.Id
  72. Where gdac.Isdel = 0 And gdac.DiId = {0} Order By [Type] ASC,[Days] ASC", dto.DiId);
  73. var dayAndCostData = await _sqlSugar.SqlQueryable<DayAndCostInfoView>(dayAndCostSql).ToListAsync();
  74. enterExitCostInfoView.QuarterageData = dayAndCostData.Where(it => it.Type == 1).ToList(); //住宿费 1
  75. enterExitCostInfoView.BoardWagesData = dayAndCostData.Where(it => it.Type == 2).ToList(); //伙食费 2
  76. enterExitCostInfoView.MiscellaneousFeeData = dayAndCostData.Where(it => it.Type == 3).ToList(); //公杂费 3
  77. enterExitCostInfoView.TrainingExpenseData = dayAndCostData.Where(it => it.Type == 4).ToList(); //培训费 4
  78. enterExitCostInfoView.Currencys = (List<CurrencyInfo>?)CommonFun.GetCurrencyChinaToList(enterExitCostData.CurrencyRemark);
  79. result.Msg = "查询成功";
  80. result.Code = 0;
  81. }
  82. else
  83. {
  84. result.Msg = "未查询出数据!!!";
  85. }
  86. result.Data = enterExitCostInfoView;
  87. }
  88. else result.Msg = ErrorMsg.Error_Port_Msg;
  89. return result;
  90. }
  91. /// <summary>
  92. /// Add Or Update
  93. /// </summary>
  94. /// <param name="dto"></param>
  95. /// <returns></returns>
  96. public async Task<Result> PostEnterExitCostOperate(EnterExitCostOperateDto dto)
  97. {
  98. Result result = new Result() { Code =-1,Msg="操作失败!" };
  99. var enterExitCost = _mapper.Map<Grp_EnterExitCost>(dto);
  100. var quarterageData = _mapper.Map<List<Grp_DayAndCost>>(dto.QuarterageData); //住宿费 1
  101. quarterageData = quarterageData.Select(it => { it.CreateUserId = dto.UserId; return it; }).ToList();
  102. var boardWagesData = _mapper.Map<List<Grp_DayAndCost>>(dto.BoardWagesData); //伙食费 2
  103. boardWagesData = boardWagesData.Select(it => { it.CreateUserId = dto.UserId; return it; }).ToList();
  104. var miscellaneousFeeData = _mapper.Map<List<Grp_DayAndCost>>(dto.MiscellaneousFeeData); //公杂费 3
  105. miscellaneousFeeData = miscellaneousFeeData.Select(it => { it.CreateUserId = dto.UserId; return it; }).ToList();
  106. var trainingExpenseData = _mapper.Map<List<Grp_DayAndCost>>(dto.TrainingExpenseData); //培训费 4
  107. trainingExpenseData = trainingExpenseData.Select(it => { it.CreateUserId = dto.UserId; return it; }).ToList();
  108. //处理币种string
  109. enterExitCost.CurrencyRemark = CommonFun.GetCurrencyChinaToString(dto.Currencys);
  110. enterExitCost.CreateUserId = dto.UserId;
  111. _sqlSugar.BeginTran();
  112. if (dto.PortType == 1)
  113. {
  114. try
  115. {
  116. var enterExit = _sqlSugar.Storageable<Grp_EnterExitCost>(enterExitCost).ToStorage();
  117. enterExit.AsInsertable.ExecuteCommand(); //不存在插入
  118. enterExit.AsUpdateable.IgnoreColumns(it => new { it.DiId, it.CreateUserId, it.CreateTime, it.IsDel }).ExecuteCommand(); //存在更新
  119. var quarterage = _sqlSugar.Storageable<Grp_DayAndCost>(quarterageData).ToStorage(); //住宿费 1
  120. quarterage.AsInsertable.ExecuteCommand(); //不存在插入
  121. quarterage.AsUpdateable.IgnoreColumns(it => new { it.DiId, it.Type, it.CreateUserId, it.CreateTime, it.IsDel }).ExecuteCommand(); //存在更新
  122. var boardWages = _sqlSugar.Storageable<Grp_DayAndCost>(boardWagesData).ToStorage(); //伙食费 2
  123. boardWages.AsInsertable.ExecuteCommand(); //不存在插入
  124. boardWages.AsUpdateable.IgnoreColumns(it => new { it.DiId, it.Type, it.CreateUserId, it.CreateTime, it.IsDel }).ExecuteCommand(); //存在更新
  125. var miscellaneousFee = _sqlSugar.Storageable<Grp_DayAndCost>(miscellaneousFeeData).ToStorage(); //公杂费 3
  126. miscellaneousFee.AsInsertable.ExecuteCommand(); //不存在插入
  127. miscellaneousFee.AsUpdateable.IgnoreColumns(it => new { it.DiId, it.Type, it.CreateUserId, it.CreateTime, it.IsDel }).ExecuteCommand(); //存在更新
  128. var trainingExpense = _sqlSugar.Storageable<Grp_DayAndCost>(trainingExpenseData).ToStorage(); //培训费 4
  129. trainingExpense.AsInsertable.ExecuteCommand(); //不存在插入
  130. trainingExpense.AsUpdateable.IgnoreColumns(it => new { it.DiId, it.Type, it.CreateUserId, it.CreateTime, it.IsDel }).ExecuteCommand(); //存在更新
  131. _sqlSugar.CommitTran();
  132. result.Code = 0;
  133. result.Msg = "操作成功!";
  134. }
  135. catch (Exception ex)
  136. {
  137. _sqlSugar.RollbackTran();
  138. result.Msg = ex.Message;
  139. }
  140. }
  141. else result.Msg = ErrorMsg.Error_Port_Msg;
  142. return result;
  143. }
  144. /// <summary>
  145. /// Del
  146. /// </summary>
  147. /// <param name="dto"></param>
  148. /// <returns></returns>
  149. public async Task<Result> PostEnterExitCostSubItemDel(EnterExitCostSubItemDelDto dto)
  150. {
  151. Result result = new Result();
  152. var del = await _sqlSugar.Updateable<Grp_DayAndCost>()
  153. .SetColumns(it => new Grp_DayAndCost()
  154. {
  155. IsDel = 1,
  156. DeleteUserId = dto.DeleteUserId,
  157. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  158. })
  159. .Where(it => it.Id == dto.Id)
  160. .ExecuteCommandAsync();
  161. if (del > 0) result.Code = 0;
  162. else result.Msg = string.Format("删除失败!");
  163. return result;
  164. }
  165. /// <summary>
  166. /// 团组模块 - 出入境国家费用标准 - Add Or Update
  167. /// </summary>
  168. /// <param name="dto"></param>
  169. /// <returns></returns>
  170. public async Task<Result> PostNationalTravelFeeOperate(NationalTravelFeeOperateDto dto)
  171. {
  172. Result result = new Result();
  173. Grp_NationalTravelFee nationalTravelFee = _mapper.Map<Grp_NationalTravelFee>(dto);
  174. nationalTravelFee.LastUpdateUserId = dto.UserId;
  175. nationalTravelFee.CreateUserId = dto.UserId;
  176. if (dto.PortType == 1) //web
  177. {
  178. var _nationalTravelFee = _sqlSugar.Storageable<Grp_NationalTravelFee>(nationalTravelFee).ToStorage();
  179. if (dto.Id == 0) //新增
  180. {
  181. string selectSql = string.Format(@"Select * From Grp_NationalTravelFee
  182. Where IsDel = 0
  183. And Continent = '{0}'
  184. And Country = '{1}'
  185. And City = '{2}'", dto.Continent, dto.Country, dto.City);
  186. Grp_NationalTravelFee nationalTravelFee1 = new Grp_NationalTravelFee();
  187. nationalTravelFee1 = await _sqlSugar.SqlQueryable<Grp_NationalTravelFee>(selectSql).FirstAsync();
  188. if (nationalTravelFee1 != null)
  189. {
  190. result.Msg = "该国家 城市已存在,请勿重复添加!";
  191. return result;
  192. }
  193. _nationalTravelFee.AsInsertable.ExecuteCommand(); //不存在插入
  194. }
  195. else
  196. {
  197. _nationalTravelFee.AsUpdateable
  198. .IgnoreColumns(it => new { it.CreateUserId, it.CreateTime, it.IsDel })
  199. .WhereColumns(it => it.Id)
  200. .ExecuteCommand(); //存在更新
  201. }
  202. result.Code = 0;
  203. }
  204. else if (dto.PortType == 2) //Android
  205. {
  206. }
  207. else if (dto.PortType == 3) //Ios
  208. {
  209. }
  210. else result.Msg = ErrorMsg.Error_Port_Msg;
  211. return result;
  212. }
  213. }
  214. }