EnterExitCostRepository.cs 28 KB

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