EnterExitCostRepository.cs 23 KB

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