|
@@ -0,0 +1,361 @@
|
|
|
+using OASystem.Domain.Dtos.Groups;
|
|
|
+using OASystem.Domain.Entities.Groups;
|
|
|
+using OASystem.Domain.ViewModels.Groups;
|
|
|
+using OASystem.Domain;
|
|
|
+using OASystem.Infrastructure.Repositories.System;
|
|
|
+using OASystem.Infrastructure.Tools;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using AutoMapper;
|
|
|
+
|
|
|
+namespace OASystem.Infrastructure.Repositories.Groups
|
|
|
+{
|
|
|
+ /// <summary>
|
|
|
+ /// 出入境费用-草稿 仓库
|
|
|
+ /// </summary>
|
|
|
+ public class EnterExitCostDraftRepository : BaseRepository<Grp_EnterExitCostDraft, EnterExitCostDraftView>
|
|
|
+ {
|
|
|
+ private readonly IMapper _mapper;
|
|
|
+ private readonly SetDataRepository _setDataRep;
|
|
|
+
|
|
|
+
|
|
|
+ public EnterExitCostDraftRepository(SqlSugarClient sqlSugar, IMapper mapper, SetDataRepository setDataRep)
|
|
|
+ : base(sqlSugar)
|
|
|
+ {
|
|
|
+ _setDataRep = setDataRep;
|
|
|
+ _mapper = mapper;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 查询 根据 Id 查询
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<JsonView> EnterExitCostDraftInfoById(EnterExitCostDraftInfoByIdDto dto)
|
|
|
+ {
|
|
|
+ var result = new JsonView() { Code = 400, Msg = "暂无数据" };
|
|
|
+
|
|
|
+ var id = dto.Id;
|
|
|
+ var enterExitCostDraftData = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().OrderByDescending(x => x.CreateTime).FirstAsync(it => it.Id == id && it.IsDel == 0);
|
|
|
+
|
|
|
+ var enterExitCostInfoView = new EnterExitCostDraftInfoView();
|
|
|
+
|
|
|
+ if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3)
|
|
|
+ {
|
|
|
+ if (enterExitCostDraftData != null)
|
|
|
+ {
|
|
|
+ enterExitCostInfoView = _mapper.Map<EnterExitCostDraftInfoView>(enterExitCostDraftData);
|
|
|
+
|
|
|
+ var dayAndCostDraftSql = string.Format(@"Select ntf.Country,ntf.City,ssd.Name CurremcyCode,ssd.Remark CurrencyName,gdac.* From Grp_DayAndCostDraft gdac
|
|
|
+ Left Join Grp_NationalTravelFee ntf On ntf.Id = gdac.NationalTravelFeeId
|
|
|
+ Left Join Sys_SetData ssd On ssd.STid = 66 And gdac.Currency = ssd.Id
|
|
|
+ Where gdac.Isdel = 0 And ntf.IsDel = 0 And gdac.ParentId = {0} Order By [Type] ASC,[Days] ASC", id);
|
|
|
+ var dayAndCostDraftData = await _sqlSugar.SqlQueryable<DayAndCostDraftInfoView>(dayAndCostDraftSql).ToListAsync();
|
|
|
+
|
|
|
+
|
|
|
+ enterExitCostInfoView.QuarterageData = dayAndCostDraftData.Where(it => it.Type == 1).ToList(); //住宿费 1
|
|
|
+ enterExitCostInfoView.BoardWagesData = dayAndCostDraftData.Where(it => it.Type == 2).ToList(); //伙食费 2
|
|
|
+ enterExitCostInfoView.MiscellaneousFeeData = dayAndCostDraftData.Where(it => it.Type == 3).ToList(); //公杂费 3
|
|
|
+ enterExitCostInfoView.TrainingExpenseData = dayAndCostDraftData.Where(it => it.Type == 4).ToList(); //培训费 4
|
|
|
+
|
|
|
+ enterExitCostInfoView.DayOtherPriceData = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>()
|
|
|
+ .Where(x => x.IsDel == 0 && x.ParentId == id)
|
|
|
+ .Select(x => new DayOtherPriceDraftView
|
|
|
+ {
|
|
|
+ ParentId = x.ParentId,
|
|
|
+ Id = x.Id,
|
|
|
+ Cost = x.Cost,
|
|
|
+ Currency = x.Currency,
|
|
|
+ Index = x.Index,
|
|
|
+ SetDataId = x.SetDataId,
|
|
|
+ SubTotal = x.SubTotal,
|
|
|
+ Remark = x.Remark,
|
|
|
+ })
|
|
|
+ .OrderBy(x => x.Index)
|
|
|
+ .ToList();
|
|
|
+
|
|
|
+ enterExitCostInfoView.Currencys = (List<CurrencyInfo>?)CommonFun.GetCurrencyChinaToList(enterExitCostDraftData.CurrencyRemark);
|
|
|
+
|
|
|
+ result.Msg = "操作成功";
|
|
|
+ result.Code = 200;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // List<DayAndCostInfoView> views = new List<DayAndCostInfoView>()
|
|
|
+ // {
|
|
|
+ // new DayAndCostInfoView {Days=1},
|
|
|
+ // new DayAndCostInfoView {Days=2},
|
|
|
+ // new DayAndCostInfoView {Days=3},
|
|
|
+ // new DayAndCostInfoView {Days=4},
|
|
|
+ // new DayAndCostInfoView {Days=5},
|
|
|
+ // new DayAndCostInfoView {Days=6},
|
|
|
+ // new DayAndCostInfoView {Days=7},
|
|
|
+ // new DayAndCostInfoView {Days=8},
|
|
|
+ // };
|
|
|
+ // enterExitCostInfoView.QuarterageData = views;
|
|
|
+ // enterExitCostInfoView.BoardWagesData = views;
|
|
|
+ // enterExitCostInfoView.MiscellaneousFeeData = views;
|
|
|
+ // enterExitCostInfoView.TrainingExpenseData = views;
|
|
|
+ // result.Code = 0;
|
|
|
+ result.Msg = "未查询出数据!!!";
|
|
|
+ }
|
|
|
+
|
|
|
+ result.Data = enterExitCostInfoView;
|
|
|
+ }
|
|
|
+ else result.Msg = MsgTips.Port;
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Add Or Update
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<Result> EnterExitCostDraftOp(EnterExitCostDraftOpDto dto)
|
|
|
+ {
|
|
|
+ Result result = new Result() { Code = -1, Msg = "操作失败!" };
|
|
|
+
|
|
|
+ if (dto.SumJJC == 0) dto.OutsideJJPay = 0;
|
|
|
+ if (dto.SumGWC == 0) dto.OutsideGWPay = 0;
|
|
|
+ if (dto.SumTDC == 0) dto.OutsideTDPay = 0;
|
|
|
+
|
|
|
+ var enterExitCost = _mapper.Map<Grp_EnterExitCostDraft>(dto);
|
|
|
+ enterExitCost.Remark = dto.FirstItemRemark;
|
|
|
+ //enterExitCost.InsidePay = enterExitCost.Visa + enterExitCost.YiMiao + enterExitCost.HeSuan + enterExitCost.Service + enterExitCost.Safe + enterExitCost.Ticket;
|
|
|
+
|
|
|
+ var subData = new List<Grp_DayAndCostDraft>();
|
|
|
+ var quarterageData = _mapper.Map<List<Grp_DayAndCostDraft>>(dto.QuarterageData); //住宿费 1
|
|
|
+ quarterageData = quarterageData.Select(it => { it.CreateUserId = dto.UserId; return it; }).ToList();
|
|
|
+ if (quarterageData.Any()) subData.AddRange(quarterageData);
|
|
|
+
|
|
|
+ var boardWagesData = _mapper.Map<List<Grp_DayAndCostDraft>>(dto.BoardWagesData); //伙食费 2
|
|
|
+ boardWagesData = boardWagesData.Select(it => { it.CreateUserId = dto.UserId; return it; }).ToList();
|
|
|
+ if (boardWagesData.Any()) subData.AddRange(boardWagesData);
|
|
|
+
|
|
|
+ var miscellaneousFeeData = _mapper.Map<List<Grp_DayAndCostDraft>>(dto.MiscellaneousFeeData); //公杂费 3
|
|
|
+ miscellaneousFeeData = miscellaneousFeeData.Select(it => { it.CreateUserId = dto.UserId; return it; }).ToList();
|
|
|
+ if (miscellaneousFeeData.Any()) subData.AddRange(miscellaneousFeeData);
|
|
|
+
|
|
|
+ var trainingExpenseData = _mapper.Map<List<Grp_DayAndCostDraft>>(dto.TrainingExpenseData); //培训费 4
|
|
|
+ trainingExpenseData = trainingExpenseData.Select(it => { it.CreateUserId = dto.UserId; return it; }).ToList();
|
|
|
+ if (trainingExpenseData.Any()) subData.AddRange(trainingExpenseData);
|
|
|
+
|
|
|
+ //处理币种string
|
|
|
+ enterExitCost.CurrencyRemark = CommonFun.GetCurrencyChinaToString(dto.Currencys);
|
|
|
+ enterExitCost.CreateUserId = dto.UserId;
|
|
|
+
|
|
|
+ _sqlSugar.BeginTran();
|
|
|
+
|
|
|
+ if (dto.PortType == 1)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ int enterExitId = 0;
|
|
|
+
|
|
|
+ var isNull = _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(it => it.IsDel == 0 && it.DraftName.Equals(dto.DraftName)).First();
|
|
|
+ if (isNull != null) //修改
|
|
|
+ {
|
|
|
+ var updateId = _sqlSugar.Updateable(enterExitCost)
|
|
|
+ .IgnoreColumns(it => new { it.DeleteUserId, it.DeleteTime, it.CreateUserId, it.CreateTime, it.IsDel })
|
|
|
+ .WhereColumns(it => it.DraftName)
|
|
|
+ .ExecuteCommand();
|
|
|
+ if (updateId > 0)
|
|
|
+ {
|
|
|
+ enterExitId = isNull.Id;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ result.Msg = "修改操作失败!";
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else //添加
|
|
|
+ {
|
|
|
+ //添加
|
|
|
+ enterExitId = _sqlSugar.Insertable(enterExitCost).ExecuteReturnIdentity();
|
|
|
+ if (enterExitId < 1)
|
|
|
+ {
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ result.Msg = "添加操作失败!";
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ subData.Select(x => { x.Id = 0; return x; }).ToList();
|
|
|
+ dto.DayOtherPriceData.Select(x => { x.Id = 0; return x; }).ToList();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (enterExitId > 0)
|
|
|
+ {
|
|
|
+ subData = subData.Select(x => { x.ParentId = enterExitId; return x; }).ToList();
|
|
|
+
|
|
|
+ var addList = subData.Where(x => x.Id == 0).ToList();
|
|
|
+ var updateList = subData.Where(x => x.Id > 0).ToList();
|
|
|
+
|
|
|
+ if (addList.Any())
|
|
|
+ {
|
|
|
+ var rowCount = _sqlSugar.Insertable(addList).ExecuteCommand();
|
|
|
+ }
|
|
|
+ if (updateList.Any())
|
|
|
+ {
|
|
|
+ var rowCount = _sqlSugar.Updateable(updateList).ExecuteCommand();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (dto.DayOtherPriceData.Any())
|
|
|
+ {
|
|
|
+ var inserList = dto.DayOtherPriceData
|
|
|
+ .Where(x => x.Id == 0)
|
|
|
+ .Select(x => new Grp_DayOtherPriceDraft
|
|
|
+ {
|
|
|
+ Cost = x.Cost,
|
|
|
+ Id = x.Id,
|
|
|
+ CreateTime = DateTime.Now,
|
|
|
+ CreateUserId = dto.UserId,
|
|
|
+ Currency = x.Currency,
|
|
|
+ ParentId = enterExitId,
|
|
|
+ Index = x.Index,
|
|
|
+ IsDel = 0,
|
|
|
+ SetDataId = x.SetDataId,
|
|
|
+ SubTotal = x.SubTotal,
|
|
|
+ Remark = x.Remark,
|
|
|
+
|
|
|
+ })
|
|
|
+ .ToList();
|
|
|
+ var updateList1 = dto.DayOtherPriceData
|
|
|
+ .Where(x => x.Id != 0)
|
|
|
+ .Select(x => new Grp_DayOtherPriceDraft
|
|
|
+ {
|
|
|
+ Cost = x.Cost,
|
|
|
+ Id = x.Id,
|
|
|
+ CreateTime = DateTime.Now,
|
|
|
+ CreateUserId = dto.UserId,
|
|
|
+ Currency = x.Currency,
|
|
|
+ ParentId = enterExitId,
|
|
|
+ Index = x.Index,
|
|
|
+ IsDel = 0,
|
|
|
+ SetDataId = x.SetDataId,
|
|
|
+ SubTotal = x.SubTotal,
|
|
|
+ Remark = x.Remark
|
|
|
+ })
|
|
|
+ .ToList();
|
|
|
+
|
|
|
+ if (inserList.Any())
|
|
|
+ {
|
|
|
+ var rowCount = _sqlSugar.Insertable(inserList).ExecuteCommand();
|
|
|
+ }
|
|
|
+ if (updateList1.Any())
|
|
|
+ {
|
|
|
+ var rowCount = _sqlSugar.Updateable(updateList1).ExecuteCommand();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ _sqlSugar.CommitTran();
|
|
|
+ result.Code = 0;
|
|
|
+ result.Msg = "操作成功!";
|
|
|
+ result.Data = new { sign = enterExitId, draftName = enterExitCost.DraftName };
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ result.Msg = ex.Message;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else result.Msg = MsgTips.Port;
|
|
|
+
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Del
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<Result> EnterExitCostDraftSubItemDel(EnterExitCostDraftSubItemDelDto dto)
|
|
|
+ {
|
|
|
+ Result result = new Result();
|
|
|
+
|
|
|
+ var data = new Grp_DayAndCostDraft()
|
|
|
+ {
|
|
|
+ Id = dto.Id,
|
|
|
+ IsDel = 1,
|
|
|
+ DeleteUserId = dto.DeleteUserId,
|
|
|
+ DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
|
|
|
+ };
|
|
|
+
|
|
|
+ var del = _sqlSugar.Updateable(data).UpdateColumns(it => new { it.IsDel, it.DeleteUserId, it.DeleteTime }).ExecuteCommand();
|
|
|
+
|
|
|
+ if (del > 0) result.Code = 0;
|
|
|
+ else result.Msg = string.Format("删除失败!");
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 一键清空
|
|
|
+ /// 删除主表数据 Update
|
|
|
+ /// 删除子表数据 delete
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id"></param>
|
|
|
+ /// <param name="userId"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<Result> OneClickEmpty(int id, int userId)
|
|
|
+ {
|
|
|
+ Result result = new Result() { Code = -1, Msg = "操作成功!" };
|
|
|
+
|
|
|
+ if (id < 1) return result = new Result() { Code = -1, Msg = "请传入有效的Id参数!" };
|
|
|
+ if (userId < 1) return result = new Result() { Code = -1, Msg = "请传入有效的UserId参数!" };
|
|
|
+
|
|
|
+ BeginTran();
|
|
|
+
|
|
|
+ int update = await _sqlSugar.Updateable<Grp_EnterExitCostDraft>()
|
|
|
+ .SetColumns(it => new Grp_EnterExitCostDraft()
|
|
|
+ {
|
|
|
+ IsDel = 1,
|
|
|
+ DeleteUserId = userId,
|
|
|
+ DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
|
|
+ })
|
|
|
+ .Where(it => it.Id == id)
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+
|
|
|
+ if (update > 0)
|
|
|
+ {
|
|
|
+ await _sqlSugar.Updateable<Grp_DayAndCostDraft>()
|
|
|
+ .SetColumns(it => new Grp_DayAndCostDraft()
|
|
|
+ {
|
|
|
+ IsDel = 1,
|
|
|
+ DeleteUserId = userId,
|
|
|
+ DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
|
|
+ })
|
|
|
+ .Where(it => it.ParentId == id)
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+
|
|
|
+ await _sqlSugar.Updateable<Grp_DayOtherPriceDraft>()
|
|
|
+ .SetColumns(it => new Grp_DayOtherPriceDraft()
|
|
|
+ {
|
|
|
+ IsDel = 1,
|
|
|
+ DeleteUserId = userId,
|
|
|
+ DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
|
|
+ })
|
|
|
+ .Where(it => it.ParentId == id)
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+
|
|
|
+ result.Code = 0;
|
|
|
+ result.Msg = "操作成功!";
|
|
|
+ CommitTran();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ result.Msg = "操作失败";
|
|
|
+ RollbackTran();
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|