EnterExitCostRepository.cs 26 KB

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