EnterExitCostRepository.cs 26 KB

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