EnterExitCostRepository.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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.Security.Policy;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. namespace OASystem.Infrastructure.Repositories.Groups
  16. {
  17. /// <summary>
  18. /// 出入境费用 仓库
  19. /// </summary>
  20. public class EnterExitCostRepository : BaseRepository<Grp_EnterExitCost, EnterExitCostView>
  21. {
  22. private readonly IMapper _mapper;
  23. private readonly SetDataRepository _setDataRep;
  24. public EnterExitCostRepository(SqlSugarClient sqlSugar, IMapper mapper, SetDataRepository setDataRep)
  25. : base(sqlSugar)
  26. {
  27. _setDataRep = setDataRep;
  28. _mapper = mapper;
  29. }
  30. /// <summary>
  31. /// 更新出入境费用汇率信息
  32. /// </summary>
  33. /// <returns></returns>
  34. public async Task<Result> SetEnterExitCostCurrencyChange()
  35. {
  36. Result result = new Result { Code = -1, Msg = "未知错误" };
  37. var enterExitList = await _sqlSugar.Queryable<Grp_EnterExitCost>().ToListAsync();
  38. foreach (var item in enterExitList)
  39. {
  40. string rateStr = string.Format(@"美元(USD):{0}|日元(JPY):{1}|欧元(EUR):{2}|英镑(GBP):{3}|港币(HKD):{4}", item.RateUSD, item.RateJPY, item.RateEUR, item.RateGBP, item.RateHKD);
  41. item.CurrencyRemark = rateStr;
  42. }
  43. var res = await _sqlSugar.Updateable(enterExitList)
  44. .WhereColumns(it => new { it.Id })
  45. .UpdateColumns(it => new { it.CurrencyRemark })
  46. .ExecuteCommandAsync();
  47. if (res > 0)
  48. {
  49. result.Code = 0;
  50. result.Msg = res.ToString();
  51. return result;
  52. }
  53. return result;
  54. }
  55. /// <summary>
  56. /// 查询 根据 Diid 查询
  57. /// </summary>
  58. /// <returns></returns>
  59. public async Task<Result> GetEnterExitCostInfoByDiId(EnterExitCostInfobyDiIdDto dto)
  60. {
  61. Result result = new Result();
  62. var enterExitCostData = await _sqlSugar.Queryable<Grp_EnterExitCost>().FirstAsync(it => it.DiId == dto.DiId && it.IsDel == 0);
  63. //Sys_PageFunctionPermission Function = _mapper.Map<Sys_PageFunctionPermission>(dto);
  64. EnterExitCostInfoView enterExitCostInfoView = new EnterExitCostInfoView();
  65. if (dto.PortType == 1) // Web
  66. {
  67. if (enterExitCostData != null)
  68. {
  69. enterExitCostInfoView = _mapper.Map<EnterExitCostInfoView>(enterExitCostData);
  70. var dayAndCostSql = string.Format(@"Select ntf.Country,ntf.City,ssd.Name CurremcyCode,ssd.Remark CurrencyName,gdac.* From Grp_DayAndCost gdac
  71. Left Join Grp_NationalTravelFee ntf On ntf.Id = gdac.NationalTravelFeeId
  72. Left Join Sys_SetData ssd On ssd.STid = 66 And gdac.Currency = ssd.Id
  73. Where gdac.Isdel = 0 And ntf.IsDel = 0 And gdac.DiId = {0} Order By [Type] ASC,[Days] ASC", dto.DiId);
  74. var dayAndCostData = await _sqlSugar.SqlQueryable<DayAndCostInfoView>(dayAndCostSql).ToListAsync();
  75. enterExitCostInfoView.QuarterageData = dayAndCostData.Where(it => it.Type == 1).ToList(); //住宿费 1
  76. enterExitCostInfoView.BoardWagesData = dayAndCostData.Where(it => it.Type == 2).ToList(); //伙食费 2
  77. enterExitCostInfoView.MiscellaneousFeeData = dayAndCostData.Where(it => it.Type == 3).ToList(); //公杂费 3
  78. enterExitCostInfoView.TrainingExpenseData = dayAndCostData.Where(it => it.Type == 4).ToList(); //培训费 4
  79. enterExitCostInfoView.Currencys = (List<CurrencyInfo>?)CommonFun.GetCurrencyChinaToList(enterExitCostData.CurrencyRemark);
  80. result.Msg = "查询成功";
  81. result.Code = 0;
  82. }
  83. else
  84. {
  85. // List<DayAndCostInfoView> views = new List<DayAndCostInfoView>()
  86. // {
  87. // new DayAndCostInfoView {Days=1},
  88. // new DayAndCostInfoView {Days=2},
  89. // new DayAndCostInfoView {Days=3},
  90. // new DayAndCostInfoView {Days=4},
  91. // new DayAndCostInfoView {Days=5},
  92. // new DayAndCostInfoView {Days=6},
  93. // new DayAndCostInfoView {Days=7},
  94. // new DayAndCostInfoView {Days=8},
  95. // };
  96. // enterExitCostInfoView.QuarterageData = views;
  97. // enterExitCostInfoView.BoardWagesData = views;
  98. // enterExitCostInfoView.MiscellaneousFeeData = views;
  99. // enterExitCostInfoView.TrainingExpenseData = views;
  100. // result.Code = 0;
  101. result.Msg = "未查询出数据!!!";
  102. }
  103. result.Data = enterExitCostInfoView;
  104. }
  105. else result.Msg = MsgTips.Port;
  106. return result;
  107. }
  108. /// <summary>
  109. /// Add Or Update
  110. /// </summary>
  111. /// <param name="dto"></param>
  112. /// <returns></returns>
  113. public async Task<Result> PostEnterExitCostOperate(EnterExitCostOperateDto dto)
  114. {
  115. Result result = new Result() { Code = -1, Msg = "操作失败!" };
  116. if (dto.SumJJC == 0) dto.OutsideJJPay = 0;
  117. if (dto.SumGWC == 0) dto.OutsideGWPay = 0;
  118. if (dto.SumTDC == 0) dto.OutsideTDPay = 0;
  119. var enterExitCost = _mapper.Map<Grp_EnterExitCost>(dto);
  120. //enterExitCost.InsidePay = enterExitCost.Visa + enterExitCost.YiMiao + enterExitCost.HeSuan + enterExitCost.Service + enterExitCost.Safe + enterExitCost.Ticket;
  121. List<Grp_DayAndCost> subData = new List<Grp_DayAndCost>();
  122. var quarterageData = _mapper.Map<List<Grp_DayAndCost>>(dto.QuarterageData); //住宿费 1
  123. quarterageData = quarterageData.Select(it => { it.CreateUserId = dto.UserId; return it; }).ToList();
  124. if (quarterageData.Count > 0) subData.AddRange(quarterageData);
  125. var boardWagesData = _mapper.Map<List<Grp_DayAndCost>>(dto.BoardWagesData); //伙食费 2
  126. boardWagesData = boardWagesData.Select(it => { it.CreateUserId = dto.UserId; return it; }).ToList();
  127. if (boardWagesData.Count > 0) subData.AddRange(boardWagesData);
  128. var miscellaneousFeeData = _mapper.Map<List<Grp_DayAndCost>>(dto.MiscellaneousFeeData); //公杂费 3
  129. miscellaneousFeeData = miscellaneousFeeData.Select(it => { it.CreateUserId = dto.UserId; return it; }).ToList();
  130. if (miscellaneousFeeData.Count > 0) subData.AddRange(miscellaneousFeeData);
  131. var trainingExpenseData = _mapper.Map<List<Grp_DayAndCost>>(dto.TrainingExpenseData); //培训费 4
  132. trainingExpenseData = trainingExpenseData.Select(it => { it.CreateUserId = dto.UserId; return it; }).ToList();
  133. if (trainingExpenseData.Count > 0) subData.AddRange(trainingExpenseData);
  134. //处理币种string
  135. enterExitCost.CurrencyRemark = CommonFun.GetCurrencyChinaToString(dto.Currencys);
  136. enterExitCost.CreateUserId = dto.UserId;
  137. _sqlSugar.BeginTran();
  138. if (dto.PortType == 1)
  139. {
  140. try
  141. {
  142. int enterExitId = 0;
  143. if (enterExitCost.Id > 0) //修改
  144. {
  145. //修改验证
  146. //IsConfirm == 2 不可修改
  147. //var info = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(it => it.IsDel == 0 && it.Id == enterExitCost.Id).First();
  148. //if (info.IsConfirm == 2)
  149. //{
  150. // result.Msg = "该团出入境费用已确认!不可更改!!";
  151. // return result;
  152. //}
  153. var updateId = _sqlSugar.Updateable<Grp_EnterExitCost>(enterExitCost)
  154. .IgnoreColumns(it => new { it.DeleteUserId, it.DeleteTime, it.CreateUserId, it.CreateTime, it.IsDel })
  155. .ExecuteCommand();
  156. if (updateId > 0)
  157. {
  158. enterExitId = enterExitCost.Id;
  159. }
  160. else
  161. {
  162. _sqlSugar.RollbackTran();
  163. result.Msg = "修改操作失败!";
  164. return result;
  165. }
  166. }
  167. else
  168. {
  169. //效重 根据团组Id
  170. var info = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).First();
  171. if (info != null )
  172. {
  173. _sqlSugar.RollbackTran();
  174. result.Msg = "该团组相关数据已存在,请勿重新添加!";
  175. return result;
  176. }
  177. //添加
  178. enterExitId = _sqlSugar.Insertable<Grp_EnterExitCost>(enterExitCost).ExecuteReturnIdentity();
  179. if (enterExitId < 1)
  180. {
  181. _sqlSugar.RollbackTran();
  182. result.Msg = "添加操作失败!";
  183. return result;
  184. }
  185. }
  186. if (enterExitId > 0)
  187. {
  188. string sqlDelete = string.Format(@" Delete From Grp_DayAndCost Where Diid = {0} ", dto.DiId);
  189. await ExecuteCommandAsync(sqlDelete);
  190. foreach (var item in subData)
  191. {
  192. var updateId = _sqlSugar.Insertable<Grp_DayAndCost>(item).ExecuteCommand();
  193. if (updateId < 1)
  194. {
  195. _sqlSugar.RollbackTran();
  196. result.Msg = "添加操作失败!";
  197. return result;
  198. }
  199. }
  200. }
  201. _sqlSugar.CommitTran();
  202. result.Code = 0;
  203. result.Msg = "操作成功!";
  204. result.Data = new { sign = enterExitId };
  205. }
  206. catch (Exception ex)
  207. {
  208. _sqlSugar.RollbackTran();
  209. result.Msg = ex.Message;
  210. }
  211. }
  212. else result.Msg = MsgTips.Port;
  213. return result;
  214. }
  215. /// <summary>
  216. /// 确认费用
  217. /// </summary>
  218. /// <param name="id"></param>
  219. /// <returns></returns>
  220. public async Task<JsonView> ConfirmCost(ConfirmCostDto dto)
  221. {
  222. var _view = new JsonView() { Code = 20001, Msg = "操作失败!" };
  223. if (dto.Id < 1)
  224. {
  225. _view.Msg = MsgTips.Id;
  226. return _view;
  227. }
  228. int confirm = 1;
  229. if (dto.Type == 1) confirm = 2; // 确认
  230. else if (dto.Type == 2) { confirm = 1; } // 撤回
  231. else
  232. {
  233. _view.Msg = "请传入正确的type;1:确认 2:撤回";
  234. return _view;
  235. }
  236. var update = await _sqlSugar.Updateable<Grp_EnterExitCost>()
  237. .SetColumns(x => new Grp_EnterExitCost() { IsConfirm = confirm })
  238. .Where(x => x.Id == dto.Id)
  239. .ExecuteCommandAsync();
  240. if (update>0)
  241. {
  242. _view.Code = 200;
  243. _view.Msg = "操作成功!";
  244. return _view;
  245. }
  246. return _view;
  247. }
  248. /// <summary>
  249. /// Del
  250. /// </summary>
  251. /// <param name="dto"></param>
  252. /// <returns></returns>
  253. public async Task<Result> PostEnterExitCostSubItemDel(EnterExitCostSubItemDelDto dto)
  254. {
  255. Result result = new Result();
  256. var data = new Grp_DayAndCost()
  257. {
  258. Id = dto.Id,
  259. IsDel = 1,
  260. DeleteUserId = dto.DeleteUserId,
  261. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  262. };
  263. var del = _sqlSugar.Updateable(data).UpdateColumns(it => new { it.IsDel, it.DeleteUserId, it.DeleteTime }).ExecuteCommand();
  264. if (del > 0) result.Code = 0;
  265. else result.Msg = string.Format("删除失败!");
  266. return result;
  267. }
  268. /// <summary>
  269. /// 团组模块 - 出入境国家费用标准 - Add Or Update
  270. /// </summary>
  271. /// <param name="dto"></param>
  272. /// <returns></returns>
  273. public async Task<Result> PostNationalTravelFeeOperate(NationalTravelFeeOperateDto dto)
  274. {
  275. Result result = new Result();
  276. Grp_NationalTravelFee nationalTravelFee = _mapper.Map<Grp_NationalTravelFee>(dto);
  277. nationalTravelFee.LastUpdateUserId = dto.UserId;
  278. nationalTravelFee.CreateUserId = dto.UserId;
  279. if (dto.PortType == 1) //web
  280. {
  281. var _nationalTravelFee = _sqlSugar.Storageable<Grp_NationalTravelFee>(nationalTravelFee).ToStorage();
  282. if (dto.Id == 0) //新增
  283. {
  284. string selectSql = string.Format(@"Select * From Grp_NationalTravelFee
  285. Where IsDel = 0
  286. And Continent = '{0}'
  287. And Country = '{1}'
  288. And City = '{2}'", dto.Continent, dto.Country, dto.City);
  289. Grp_NationalTravelFee nationalTravelFee1 = new Grp_NationalTravelFee();
  290. nationalTravelFee1 = await _sqlSugar.SqlQueryable<Grp_NationalTravelFee>(selectSql).FirstAsync();
  291. if (nationalTravelFee1 != null)
  292. {
  293. result.Msg = "该国家 城市已存在,请勿重复添加!";
  294. return result;
  295. }
  296. _nationalTravelFee.AsInsertable.ExecuteCommand(); //不存在插入
  297. }
  298. else
  299. {
  300. _nationalTravelFee.AsUpdateable
  301. .IgnoreColumns(it => new { it.CreateUserId, it.CreateTime, it.IsDel })
  302. .WhereColumns(it => it.Id)
  303. .ExecuteCommand(); //存在更新
  304. }
  305. result.Code = 0;
  306. }
  307. else if (dto.PortType == 2) //Android
  308. {
  309. }
  310. else if (dto.PortType == 3) //Ios
  311. {
  312. }
  313. else result.Msg = MsgTips.Port;
  314. return result;
  315. }
  316. /// <summary>
  317. /// 一键清空
  318. /// 删除主表数据 Update
  319. /// 删除子表数据 delete
  320. /// </summary>
  321. /// <param name="id"></param>
  322. /// <param name="diid"></param>
  323. /// <returns></returns>
  324. public async Task<Result> _OneClickClear(int id, int diId, int userId)
  325. {
  326. Result result = new Result() { Code = -1, Msg = "操作成功!" };
  327. if (id < 1) return result = new Result() { Code = -1, Msg = "请传入有效的Id参数!" };
  328. if (diId < 1) return result = new Result() { Code = -1, Msg = "请传入有效的Id参数!" };
  329. if (userId < 1) return result = new Result() { Code = -1, Msg = "请传入有效的UserId参数!" };
  330. BeginTran();
  331. Grp_EnterExitCost _EnterExitCost = new Grp_EnterExitCost() {
  332. Id = id,
  333. IsDel = 1,
  334. DeleteUserId = userId,
  335. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  336. };
  337. //int update = await _sqlSugar.Updateable<Grp_EnterExitCost>(_EnterExitCost).Where(it => it.Id == id).ExecuteCommandAsync();
  338. int update = await _sqlSugar.Updateable<Grp_EnterExitCost>(_EnterExitCost)
  339. .UpdateColumns(it => new {
  340. it.IsDel,
  341. it.DeleteUserId ,
  342. it.DeleteTime
  343. })
  344. .Where(it => it.Id == id).ExecuteCommandAsync();
  345. if (update > 0) {
  346. string sqlDelete = string.Format(@"Delete From Grp_DayAndCost Where Diid = {0} ", diId);
  347. await ExecuteCommandAsync(sqlDelete);
  348. result.Code = 0;
  349. result.Msg = "操作成功!";
  350. CommitTran();
  351. }
  352. else
  353. {
  354. result.Msg = "操作失败";
  355. RollbackTran();
  356. }
  357. return result;
  358. }
  359. }
  360. }