EnterExitCostRepository.cs 23 KB

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