EnterExitCostRepository.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  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<List<PermissionViewUserview>> PermissionViewUsersAsync()
  37. {
  38. var gj_jobPostIds = new List<int>() { 22, 32 };
  39. var viewPermissionData = await _sqlSugar.Queryable<Sys_Users>()
  40. .Where(x => x.IsDel == 0 && ((x.DepId == 7 && gj_jobPostIds.Contains(x.JobPostId)) || x.DepId == 6))
  41. .Select(x => new PermissionViewUserview { Id = x.Id, Name = x.CnName })
  42. .ToListAsync();
  43. return viewPermissionData;
  44. }
  45. /// <summary>
  46. /// 出入境费用正式 --> 权限验证
  47. /// </summary>
  48. /// <param name="groupId">团组Id</param>
  49. /// <param name="permission">操作权限 1:查看;2:新增;3:编辑;4:删除;5:下载; </param>
  50. /// <returns></returns>
  51. public async Task<bool> PermissionValidationAsync(int groupId, int userId, int permission = 1)
  52. {
  53. //参数验证
  54. if (groupId < 1) return false;
  55. if (userId < 1) return false;
  56. var permissionIds = new List<int>() { 1, 2, 3, 4, 5 };
  57. if (!permissionIds.Contains(permission)) return false;
  58. var info = await _sqlSugar.Queryable<Grp_EnterExitCostPermission>()
  59. .Where(it => it.GroupId == groupId && it.UserId == userId && it.Permission == permission)
  60. .FirstAsync();
  61. if (info != null) return true;
  62. return false;
  63. }
  64. /// <summary>
  65. /// 更新出入境费用汇率信息
  66. /// </summary>
  67. /// <returns></returns>
  68. public async Task<Result> SetEnterExitCostCurrencyChange()
  69. {
  70. Result result = new Result { Code = -1, Msg = "未知错误" };
  71. var enterExitList = await _sqlSugar.Queryable<Grp_EnterExitCost>().ToListAsync();
  72. foreach (var item in enterExitList)
  73. {
  74. string rateStr = string.Format(@"美元(USD):{0}|日元(JPY):{1}|欧元(EUR):{2}|英镑(GBP):{3}|港币(HKD):{4}", item.RateUSD, item.RateJPY, item.RateEUR, item.RateGBP, item.RateHKD);
  75. item.CurrencyRemark = rateStr;
  76. }
  77. var res = await _sqlSugar.Updateable(enterExitList)
  78. .WhereColumns(it => new { it.Id })
  79. .UpdateColumns(it => new { it.CurrencyRemark })
  80. .ExecuteCommandAsync();
  81. if (res > 0)
  82. {
  83. result.Code = 0;
  84. result.Msg = res.ToString();
  85. return result;
  86. }
  87. return result;
  88. }
  89. /// <summary>
  90. ///
  91. /// </summary>
  92. /// <param name="groupId"></param>
  93. /// <param name="currUserId"></param>
  94. /// <param name="permissionType">1 查看 2 编辑</param>
  95. /// <returns></returns>
  96. public async Task<(bool, string)> MobilePermissionsValidationAsync(int groupId,int currUserId,int permissionType = 1)
  97. {
  98. bool status = false;
  99. string msg = string.Empty;
  100. var enterExitCostData = await _sqlSugar.Queryable<Grp_EnterExitCost>().OrderByDescending(x => x.CreateTime).FirstAsync(it => it.DiId == groupId && it.IsDel == 0);
  101. if (permissionType == 1)
  102. {
  103. status = await PermissionValidationAsync(groupId, currUserId);//查看权限
  104. if (enterExitCostData.CreateUserId == currUserId) status = true; //查看权限
  105. if (!status)
  106. {
  107. var setUserName = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.Id == enterExitCostData.CreateUserId).Select(x => x.CnName).FirstAsync();
  108. msg = $"{setUserName}设置了你不能查看当前团组的出入境费用明细数据,如要查看,请联系{setUserName}!";
  109. }
  110. return (status, msg);
  111. }
  112. else if (permissionType == 2)
  113. {
  114. if (enterExitCostData.CreateUserId == currUserId) status = true; //编辑权限
  115. if (!status)
  116. {
  117. var setUserName = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.Id == enterExitCostData.CreateUserId).Select(x => x.CnName).FirstAsync();
  118. msg = $"您没有编辑权限,“{setUserName}”才可编辑!";
  119. }
  120. return (status, msg);
  121. }
  122. else msg = $"请传入正确的权限验证类型!";
  123. return (status, msg);
  124. }
  125. /// <summary>
  126. /// 查询 根据 Diid 查询
  127. /// </summary>
  128. /// <returns></returns>
  129. public async Task<JsonView> GetEnterExitCostInfoByDiId(EnterExitCostInfobyDiIdDto dto)
  130. {
  131. var result = new JsonView() { Code = 400 , Msg = "暂无数据" };
  132. var enterExitCostData = await _sqlSugar.Queryable<Grp_EnterExitCost>().OrderByDescending(x => x.CreateTime).FirstAsync(it => it.DiId == dto.DiId && it.IsDel == 0);
  133. //Sys_PageFunctionPermission Function = _mapper.Map<Sys_PageFunctionPermission>(dto);
  134. var enterExitCostInfoView = new EnterExitCostInfoView();
  135. if (dto.PortType == 1) // Web
  136. {
  137. if (enterExitCostData != null)
  138. {
  139. enterExitCostInfoView = _mapper.Map<EnterExitCostInfoView>(enterExitCostData);
  140. var isView = await PermissionValidationAsync(dto.DiId, dto.CurrUserId);
  141. if (isView) enterExitCostInfoView.IsView = true; //查看权限
  142. if (enterExitCostData.CreateUserId == dto.CurrUserId) {
  143. enterExitCostInfoView.IsSave = true; //操作权限
  144. enterExitCostInfoView.IsView = true; //查看权限
  145. }
  146. if (!enterExitCostInfoView.IsView)
  147. {
  148. var setUserName = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.Id == enterExitCostData.CreateUserId).Select(x => x.CnName).FirstAsync();
  149. result.Msg = $"{setUserName}设置了你不能查看当前团组的出入境费用明细数据,如要查看,请联系{setUserName}!";
  150. return result;
  151. }
  152. enterExitCostInfoView.ViewUsers = await _sqlSugar
  153. .Queryable<Grp_EnterExitCostPermission>()
  154. .Where(x => x.IsDel == 0 && x.GroupId == dto.DiId)
  155. .Select(x => x.UserId)
  156. .ToArrayAsync();
  157. //enterExitCostInfoView.FirstItemRemark = enterExitCostData.Remark;
  158. var dayAndCostSql = string.Format(@"Select ntf.Country,ntf.City,ssd.Name CurremcyCode,ssd.Remark CurrencyName,gdac.* From Grp_DayAndCost gdac
  159. Left Join Grp_NationalTravelFee ntf On ntf.Id = gdac.NationalTravelFeeId
  160. Left Join Sys_SetData ssd On ssd.STid = 66 And gdac.Currency = ssd.Id
  161. Where gdac.Isdel = 0 And ntf.IsDel = 0 And gdac.DiId = {0} Order By [Type] ASC,[Days] ASC", dto.DiId);
  162. var dayAndCostData = await _sqlSugar.SqlQueryable<DayAndCostInfoView>(dayAndCostSql).ToListAsync();
  163. enterExitCostInfoView.QuarterageData = dayAndCostData.Where(it => it.Type == 1).ToList(); //住宿费 1
  164. enterExitCostInfoView.BoardWagesData = dayAndCostData.Where(it => it.Type == 2).ToList(); //伙食费 2
  165. enterExitCostInfoView.MiscellaneousFeeData = dayAndCostData.Where(it => it.Type == 3).ToList(); //公杂费 3
  166. enterExitCostInfoView.TrainingExpenseData = dayAndCostData.Where(it => it.Type == 4).ToList(); //培训费 4
  167. enterExitCostInfoView.DayOtherPriceData = _sqlSugar.Queryable<Grp_DayOtherPrice>()
  168. .Where(x => x.IsDel == 0 && x.Diid == dto.DiId)
  169. .OrderBy(x => x.Index)
  170. .Select(x => new DayOtherPriceView
  171. {
  172. DiId = x.Diid,
  173. Id = x.Id,
  174. Cost = x.Cost,
  175. Currency = x.Currency,
  176. Index = x.Index,
  177. SetDataId = x.SetDataId,
  178. SubTotal = x.SubTotal,
  179. Remark = x.Remark,
  180. })
  181. .ToList();
  182. enterExitCostInfoView.Currencys = (List<CurrencyInfo>?)CommonFun.GetCurrencyChinaToList(enterExitCostData.CurrencyRemark);
  183. result.Msg = "操作成功";
  184. result.Code = 200;
  185. }
  186. else
  187. {
  188. // List<DayAndCostInfoView> views = new List<DayAndCostInfoView>()
  189. // {
  190. // new DayAndCostInfoView {Days=1},
  191. // new DayAndCostInfoView {Days=2},
  192. // new DayAndCostInfoView {Days=3},
  193. // new DayAndCostInfoView {Days=4},
  194. // new DayAndCostInfoView {Days=5},
  195. // new DayAndCostInfoView {Days=6},
  196. // new DayAndCostInfoView {Days=7},
  197. // new DayAndCostInfoView {Days=8},
  198. // };
  199. // enterExitCostInfoView.QuarterageData = views;
  200. // enterExitCostInfoView.BoardWagesData = views;
  201. // enterExitCostInfoView.MiscellaneousFeeData = views;
  202. // enterExitCostInfoView.TrainingExpenseData = views;
  203. // result.Code = 0;
  204. enterExitCostInfoView.IsView = true;
  205. enterExitCostInfoView.IsSave = true;
  206. result.Msg = "未查询出数据!可操作该条数据!";
  207. }
  208. result.Data = enterExitCostInfoView;
  209. }
  210. else if (dto.PortType == 2 || dto.PortType == 3)
  211. {
  212. var mobileInfo = new EnterExitCostMobileInfoView();
  213. if (enterExitCostData != null)
  214. {
  215. mobileInfo = _mapper.Map<EnterExitCostMobileInfoView>(enterExitCostData);
  216. var dayAndCostData = _sqlSugar.Queryable<Grp_DayAndCost>()
  217. .LeftJoin<Grp_NationalTravelFee>((dac,ntf) => dac.NationalTravelFeeId == ntf.Id)
  218. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  219. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.DiId == dto.DiId)
  220. .Select((dac, ntf, sd) => new DayAndCostMobileInfoView
  221. {
  222. SubId = dac.Id,
  223. DiId = dac.DiId,
  224. Type = dac.Type,
  225. Days = dac.Days,
  226. NationalTravelFeeId = dac.NationalTravelFeeId,
  227. Arae = $"{ntf.Country}-{ntf.City}",
  228. Cost = dac.Cost,
  229. Currency = dac.Currency,
  230. CurrencyName = sd.Name,
  231. SubTotal = dac.SubTotal,
  232. })
  233. .ToList();
  234. mobileInfo.ChoiceOneTotalCost = enterExitCostData.InsidePay;
  235. mobileInfo.ChoiceOneDetails = new ChoiceOneMobileInfoView() {
  236. Visa = enterExitCostData.Visa,
  237. VisaRemark = enterExitCostData.VisaRemark,
  238. YiMiao = enterExitCostData.YiMiao,
  239. HeSuan = enterExitCostData.HeSuan,
  240. Service = enterExitCostData.Service,
  241. Ticket = enterExitCostData.Ticket,
  242. Safe = enterExitCostData.Safe,
  243. };
  244. mobileInfo.ChoiceTwoDetails = new ChoiceTwoMobileInfoView()
  245. {
  246. AirJJ = enterExitCostData.AirJJ,
  247. AirGW = enterExitCostData.AirGW,
  248. AirTD = enterExitCostData.AirTD,
  249. CityTranffic = enterExitCostData.CityTranffic
  250. };
  251. mobileInfo.ChoiceThreeDetails = dayAndCostData.Where(it => it.Type == 1).OrderBy(it => it.Days).ToArray(); //住宿费 1
  252. mobileInfo.ChoiceFourDetails = dayAndCostData.Where(it => it.Type == 2).OrderBy(it => it.Days).ToArray(); //伙食费 2
  253. mobileInfo.ChoiceFiveDetails = dayAndCostData.Where(it => it.Type == 3).OrderBy(it => it.Days).ToArray(); //公杂费 3
  254. mobileInfo.ChoiceSixDetails = dayAndCostData.Where(it => it.Type == 4).OrderBy(it => it.Days).ToArray(); //培训费 4
  255. //其他款项
  256. mobileInfo.OtherExpensesDetails = _sqlSugar.Queryable<Grp_DayOtherPrice>()
  257. .LeftJoin<Sys_SetData>((dop,sd1) => dop.SetDataId == sd1.Id)
  258. .LeftJoin<Sys_SetData>((dop, sd1,sd2) => dop.Currency == sd2.Id)
  259. .Where((dop, sd1, sd2) => dop.IsDel == 0 && dop.Diid == dto.DiId)
  260. .OrderBy((dop, sd1, sd2) => dop.Index)
  261. .Select((dop, sd1, sd2) => new DayOtherPriceMobileInfoView
  262. {
  263. SubId = dop.Id,
  264. DiId = dop.Diid,
  265. Index = dop.Index,
  266. SetDataId = dop.SetDataId,
  267. SetDataName = sd1.Name,
  268. Cost = dop.Cost,
  269. Currency = dop.Currency,
  270. CurrencyName = sd2.Remark,
  271. SubTotal = dop.SubTotal,
  272. Remark = dop.Remark,
  273. })
  274. .ToArray();
  275. mobileInfo.Currencys = (List<CurrencyInfo>?)CommonFun.GetCurrencyChinaToList(enterExitCostData.CurrencyRemark);
  276. result.Msg = "查询成功";
  277. result.Code = 200;
  278. }
  279. result.Data = mobileInfo;
  280. }
  281. else result.Msg = MsgTips.Port;
  282. return result;
  283. }
  284. /// <summary>
  285. /// Add Or Update
  286. /// </summary>
  287. /// <param name="dto"></param>
  288. /// <returns></returns>
  289. public async Task<Result> PostEnterExitCostOperate(EnterExitCostOperateDto dto)
  290. {
  291. Result result = new Result() { Code = -1, Msg = "操作失败!" };
  292. if (dto.SumJJC == 0) dto.OutsideJJPay = 0;
  293. if (dto.SumGWC == 0) dto.OutsideGWPay = 0;
  294. if (dto.SumTDC == 0) dto.OutsideTDPay = 0;
  295. var enterExitCost = _mapper.Map<Grp_EnterExitCost>(dto);
  296. //enterExitCost.Remark = dto.FirstItemRemark;
  297. //enterExitCost.InsidePay = enterExitCost.Visa + enterExitCost.YiMiao + enterExitCost.HeSuan + enterExitCost.Service + enterExitCost.Safe + enterExitCost.Ticket;
  298. List<Grp_DayAndCost> subData = new List<Grp_DayAndCost>();
  299. var quarterageData = _mapper.Map<List<Grp_DayAndCost>>(dto.QuarterageData); //住宿费 1
  300. quarterageData = quarterageData.Select(it => { it.CreateUserId = dto.UserId; return it; }).ToList();
  301. if (quarterageData.Count > 0) subData.AddRange(quarterageData);
  302. var boardWagesData = _mapper.Map<List<Grp_DayAndCost>>(dto.BoardWagesData); //伙食费 2
  303. boardWagesData = boardWagesData.Select(it => { it.CreateUserId = dto.UserId; return it; }).ToList();
  304. if (boardWagesData.Count > 0) subData.AddRange(boardWagesData);
  305. var miscellaneousFeeData = _mapper.Map<List<Grp_DayAndCost>>(dto.MiscellaneousFeeData); //公杂费 3
  306. miscellaneousFeeData = miscellaneousFeeData.Select(it => { it.CreateUserId = dto.UserId; return it; }).ToList();
  307. if (miscellaneousFeeData.Count > 0) subData.AddRange(miscellaneousFeeData);
  308. var trainingExpenseData = _mapper.Map<List<Grp_DayAndCost>>(dto.TrainingExpenseData); //培训费 4
  309. trainingExpenseData = trainingExpenseData.Select(it => { it.CreateUserId = dto.UserId; return it; }).ToList();
  310. if (trainingExpenseData.Count > 0) subData.AddRange(trainingExpenseData);
  311. //处理币种string
  312. enterExitCost.CurrencyRemark = CommonFun.GetCurrencyChinaToString(dto.Currencys);
  313. enterExitCost.CreateUserId = dto.UserId;
  314. _sqlSugar.BeginTran();
  315. if (dto.PortType == 1)
  316. {
  317. try
  318. {
  319. int enterExitId = 0;
  320. if (enterExitCost.Id > 0) //修改
  321. {
  322. //操作权限验证 只有创建人可修改
  323. var info = await _sqlSugar.Queryable<Grp_EnterExitCost,Sys_Users>((eec,u) => new JoinQueryInfos(JoinType.Left,eec.CreateUserId == u.Id))
  324. .Where((eec, u) => eec.IsDel == 0 && eec.Id == enterExitCost.Id)
  325. .Select((eec, u) => new { eec.CreateUserId,u.CnName })
  326. .FirstAsync();
  327. if (info.CreateUserId != dto.UserId)
  328. {
  329. _sqlSugar.RollbackTran();
  330. result.Msg = $"该条信息只有操作人“{info.CnName}”可修改!";
  331. return result;
  332. }
  333. //修改验证
  334. //IsConfirm == 2 不可修改
  335. //var info = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(it => it.IsDel == 0 && it.Id == enterExitCost.Id).First();
  336. //if (info.IsConfirm == 2)
  337. //{
  338. // result.Msg = "该团出入境费用已确认!不可更改!!";
  339. // return result;
  340. //}
  341. var updateId = _sqlSugar.Updateable<Grp_EnterExitCost>(enterExitCost)
  342. .IgnoreColumns(it => new { it.DeleteUserId, it.DeleteTime, it.CreateUserId, it.CreateTime, it.IsDel })
  343. .ExecuteCommand();
  344. if (updateId > 0)
  345. {
  346. enterExitId = enterExitCost.Id;
  347. }
  348. else
  349. {
  350. _sqlSugar.RollbackTran();
  351. result.Msg = "修改操作失败!";
  352. return result;
  353. }
  354. }
  355. else
  356. {
  357. //效重 根据团组Id
  358. var info = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).First();
  359. if (info != null )
  360. {
  361. _sqlSugar.RollbackTran();
  362. result.Msg = "该团组相关数据已存在,请勿重新添加!";
  363. return result;
  364. }
  365. //添加
  366. enterExitId = _sqlSugar.Insertable<Grp_EnterExitCost>(enterExitCost).ExecuteReturnIdentity();
  367. if (enterExitId < 1)
  368. {
  369. _sqlSugar.RollbackTran();
  370. result.Msg = "添加操作失败!";
  371. return result;
  372. }
  373. //默认添加查看权限
  374. var users = await PermissionViewUsersAsync();
  375. var userIds = users.Select(x => x.Id).ToList();
  376. if (userIds.Any())
  377. {
  378. var permissions = new List<Grp_EnterExitCostPermission>();
  379. foreach (var userId in userIds)
  380. {
  381. permissions.Add(new Grp_EnterExitCostPermission()
  382. {
  383. GroupId = enterExitId,
  384. UserId = userId,
  385. Permission = 1,
  386. CreateUserId = dto.UserId,
  387. });
  388. }
  389. if (permissions.Any())
  390. {
  391. _sqlSugar.Insertable(permissions).ExecuteReturnIdentity();
  392. }
  393. }
  394. }
  395. if (enterExitId > 0)
  396. {
  397. string sqlDelete = string.Format(@" Delete From Grp_DayAndCost Where Diid = {0} ", dto.DiId);
  398. await ExecuteCommandAsync(sqlDelete);
  399. foreach (var item in subData)
  400. {
  401. var updateId = _sqlSugar.Insertable<Grp_DayAndCost>(item).ExecuteCommand();
  402. if (updateId < 1)
  403. {
  404. _sqlSugar.RollbackTran();
  405. result.Msg = "添加操作失败!";
  406. return result;
  407. }
  408. }
  409. }
  410. _sqlSugar.CommitTran();
  411. result.Code = 0;
  412. result.Msg = "操作成功!";
  413. result.Data = new { sign = enterExitId };
  414. }
  415. catch (Exception ex)
  416. {
  417. _sqlSugar.RollbackTran();
  418. result.Msg = ex.Message;
  419. }
  420. }
  421. else result.Msg = MsgTips.Port;
  422. return result;
  423. }
  424. /// <summary>
  425. /// 确认费用
  426. /// </summary>
  427. /// <param name="id"></param>
  428. /// <returns></returns>
  429. public async Task<JsonView> ConfirmCost(ConfirmCostDto dto)
  430. {
  431. var _view = new JsonView() { Code = 20001, Msg = "操作失败!" };
  432. if (dto.Id < 1)
  433. {
  434. _view.Msg = MsgTips.Id;
  435. return _view;
  436. }
  437. int confirm = 1;
  438. if (dto.Type == 1) confirm = 2; // 确认
  439. else if (dto.Type == 2) { confirm = 1; } // 撤回
  440. else
  441. {
  442. _view.Msg = "请传入正确的type;1:确认 2:撤回";
  443. return _view;
  444. }
  445. var update = await _sqlSugar.Updateable<Grp_EnterExitCost>()
  446. .SetColumns(x => new Grp_EnterExitCost() { IsConfirm = confirm })
  447. .Where(x => x.Id == dto.Id)
  448. .ExecuteCommandAsync();
  449. if (update>0)
  450. {
  451. _view.Code = 200;
  452. _view.Msg = "操作成功!";
  453. return _view;
  454. }
  455. return _view;
  456. }
  457. /// <summary>
  458. /// Del
  459. /// </summary>
  460. /// <param name="dto"></param>
  461. /// <returns></returns>
  462. public async Task<Result> PostEnterExitCostSubItemDel(EnterExitCostSubItemDelDto dto)
  463. {
  464. Result result = new Result();
  465. var data = new Grp_DayAndCost()
  466. {
  467. Id = dto.Id,
  468. IsDel = 1,
  469. DeleteUserId = dto.DeleteUserId,
  470. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  471. };
  472. var del = _sqlSugar.Updateable(data).UpdateColumns(it => new { it.IsDel, it.DeleteUserId, it.DeleteTime }).ExecuteCommand();
  473. if (del > 0) result.Code = 0;
  474. else result.Msg = string.Format("删除失败!");
  475. return result;
  476. }
  477. /// <summary>
  478. /// 团组模块 - 出入境国家费用标准 - Add Or Update
  479. /// </summary>
  480. /// <param name="dto"></param>
  481. /// <returns></returns>
  482. public async Task<Result> PostNationalTravelFeeOperate(NationalTravelFeeOperateDto dto)
  483. {
  484. Result result = new Result();
  485. Grp_NationalTravelFee nationalTravelFee = _mapper.Map<Grp_NationalTravelFee>(dto);
  486. nationalTravelFee.LastUpdateUserId = dto.UserId;
  487. nationalTravelFee.CreateUserId = dto.UserId;
  488. if (dto.PortType == 1) //web
  489. {
  490. var _nationalTravelFee = _sqlSugar.Storageable<Grp_NationalTravelFee>(nationalTravelFee).ToStorage();
  491. if (dto.Id == 0) //新增
  492. {
  493. string selectSql = string.Format(@"Select * From Grp_NationalTravelFee
  494. Where IsDel = 0
  495. And Continent = '{0}'
  496. And Country = '{1}'
  497. And City = '{2}'", dto.Continent, dto.Country, dto.City);
  498. Grp_NationalTravelFee nationalTravelFee1 = new Grp_NationalTravelFee();
  499. nationalTravelFee1 = await _sqlSugar.SqlQueryable<Grp_NationalTravelFee>(selectSql).FirstAsync();
  500. if (nationalTravelFee1 != null)
  501. {
  502. result.Msg = "该国家 城市已存在,请勿重复添加!";
  503. return result;
  504. }
  505. _nationalTravelFee.AsInsertable.ExecuteCommand(); //不存在插入
  506. }
  507. else
  508. {
  509. _nationalTravelFee.AsUpdateable
  510. .IgnoreColumns(it => new { it.CreateUserId, it.CreateTime, it.IsDel })
  511. .WhereColumns(it => it.Id)
  512. .ExecuteCommand(); //存在更新
  513. }
  514. result.Code = 0;
  515. }
  516. else if (dto.PortType == 2) //Android
  517. {
  518. }
  519. else if (dto.PortType == 3) //Ios
  520. {
  521. }
  522. else result.Msg = MsgTips.Port;
  523. return result;
  524. }
  525. /// <summary>
  526. /// 一键清空
  527. /// 删除主表数据 Update
  528. /// 删除子表数据 delete
  529. /// </summary>
  530. /// <param name="id"></param>
  531. /// <param name="diid"></param>
  532. /// <returns></returns>
  533. public async Task<Result> _OneClickClear(int id, int diId, int userId)
  534. {
  535. Result result = new Result() { Code = -1, Msg = "操作成功!" };
  536. if (id < 1) return result = new Result() { Code = -1, Msg = "请传入有效的Id参数!" };
  537. if (diId < 1) return result = new Result() { Code = -1, Msg = "请传入有效的Id参数!" };
  538. if (userId < 1) return result = new Result() { Code = -1, Msg = "请传入有效的UserId参数!" };
  539. BeginTran();
  540. Grp_EnterExitCost _EnterExitCost = new Grp_EnterExitCost() {
  541. Id = id,
  542. IsDel = 1,
  543. DeleteUserId = userId,
  544. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  545. };
  546. //int update = await _sqlSugar.Updateable<Grp_EnterExitCost>(_EnterExitCost).Where(it => it.Id == id).ExecuteCommandAsync();
  547. int update = await _sqlSugar.Updateable<Grp_EnterExitCost>(_EnterExitCost)
  548. .UpdateColumns(it => new {
  549. it.IsDel,
  550. it.DeleteUserId ,
  551. it.DeleteTime
  552. })
  553. .Where(it => it.Id == id).ExecuteCommandAsync();
  554. if (update > 0) {
  555. string sqlDelete = string.Format(@"Delete From Grp_DayAndCost Where Diid = {0} ", diId);
  556. await ExecuteCommandAsync(sqlDelete);
  557. result.Code = 0;
  558. result.Msg = "操作成功!";
  559. CommitTran();
  560. }
  561. else
  562. {
  563. result.Msg = "操作失败";
  564. RollbackTran();
  565. }
  566. return result;
  567. }
  568. }
  569. }