123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- using AutoMapper;
- using OASystem.Domain;
- using OASystem.Domain.Dtos.Financial;
- using OASystem.Domain.Entities.Financial;
- using OASystem.Domain.ViewModels.Financial;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace OASystem.Infrastructure.Repositories.Financial
- {
- /// <summary>
- /// 财务 - 团组已收款项
- /// 雷怡 2023.08.16 15:24
- /// </summary>
- public class ProceedsReceivedRepository:BaseRepository<Fin_ProceedsReceived,Fin_ProceedsReceivedView>
- {
- private readonly IMapper _mapper;
- /// <summary>
- ///
- /// </summary>
- /// <param name="sqlSugar"></param>
- /// <param name="mapper"></param>
- public ProceedsReceivedRepository(SqlSugarClient sqlSugar, IMapper mapper)
- : base(sqlSugar)
- {
- _mapper = mapper;
- }
- /// <summary>
- /// 根据diid查询团组已收款项
- /// </summary>
- /// <param name="diid"></param>
- /// <returns></returns>
- public async Task<Result> GetGroupReceivedByDiid(int diid)
- {
- Result result = new() { Code = -2 };
- string sql = string.Format(@"Select * From ProceedsReceived Where IsDel=0 And Diid={0}", diid);
- var groupReceivablesList = await _sqlSugar.SqlQueryable<Fin_ProceedsReceivedView>(sql).ToListAsync();
- result.Code = 0;
- result.Msg = "查询成功!";
- result.Data = groupReceivablesList;
- return result;
- }
- /// <summary>
- /// 根据diid 数组 查询团组已收款项
- /// </summary>
- /// <param name="diid"></param>
- /// <returns></returns>
- public async Task<Result> GetGroupReceivedByDiids(int[] diids)
- {
- Result result = new() { Code = -2 };
- var groupReceivablesList = await _sqlSugar.Queryable<Fin_ProceedsReceived>()
- .Where(fr => fr.IsDel == 0 && diids.Contains(fr.Diid)) .ToListAsync();
- result.Code = 0;
- result.Msg = "查询成功!";
- result.Data = groupReceivablesList;
- return result;
- }
- /// <summary>
- /// 应收款项 删除
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- public async Task<Result> _Del(ProceedsReceivedDelDto dto)
- {
- Result result = new Result() { Code = -1, Msg = "程序错误!" };
- var res = await _sqlSugar.Updateable<Fin_ProceedsReceived>()
- .Where(it => it.Id == dto.Id)
- .SetColumns(it => new Fin_ProceedsReceived()
- {
- IsDel = 1,
- DeleteUserId = dto.UserId,
- DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
- }
- ).ExecuteCommandAsync();
- if (res > 0)
- {
- result.Msg = "删除成功!";
- result.Code = 0;
- }
- else
- {
- result.Msg = "删除失败!";
- }
- return result;
- }
- /// <summary>
- /// 已收款项
- /// Add And Update
- /// </summary>
- /// <param name="diid"></param>
- /// <returns></returns>
- public async Task<Result> PostAmountReceivedOperate(ProceedsReceivedDto dto)
- {
- Result result = new() { Code = -2 };
- if (dto._ProceedsReceivedInfos.Count <= 0)
- {
- result.Msg = "已收款项没有信息,不能进行,添加或修改操作!!!";
- return result;
- }
- int addCount = 0, updateCount = 0;
- if (dto.PortType == 1)
- {
- List<Fin_ProceedsReceived> _ProceedsReceived = new List<Fin_ProceedsReceived>();
- foreach (var item in dto._ProceedsReceivedInfos)
- {
- _ProceedsReceived.Add(new Fin_ProceedsReceived()
- {
- Diid = dto.DiId,
- Id = item.Id,
- SectionTime = item.SectionTime,
- Price = item.Price,
- Currency = item.Currency,
- ReceivablesType = item.ReceivablesType,
- Client = item.Client,
- CustomerName = item.CustomerName,
- CustomerTel = item.CustomerTel,
- FID = item.FID,
- CreateUserId = dto.UserId,
- CreateTime = DateTime.Now,
- Remark = item.Remark
- });
- }
- if (_ProceedsReceived.Count > 0)
- {
- var x = _sqlSugar.Storageable(_ProceedsReceived).ToStorage();
- addCount = x.AsInsertable.ExecuteCommand(); //不存在插入
- updateCount = x.AsUpdateable.ExecuteCommand(); //存在更新
- }
- result.Code = 0;
- result.Msg = string.Format(@"操作成功!添加:{0}条;更新:{1};", addCount, updateCount);
- }
- return result;
- }
- /// <summary>
- /// 已收款项
- /// 分配已收款项至 应收项下
- /// </summary>
- /// <param name="diid"></param>
- /// <returns></returns>
- public async Task<Result> PostAllocateAmountReceived(AllocateAmountReceivedDto dto)
- {
- Result result = new() { Code = -2 };
- if (dto.SubIds.Count <= 0)
- {
- result.Msg = "请选择要添加的已收款项!";
- return result;
- }
- if (dto.PortType == 1)
- {
- List<Fin_ProceedsReceived> _proceedsReceived = new List<Fin_ProceedsReceived>();
- foreach (var id in dto.SubIds)
- {
- _proceedsReceived.Add(new Fin_ProceedsReceived() { Id = id, FID = dto.ParentId });
- }
- var res = await _sqlSugar.Updateable(_proceedsReceived).
- WhereColumns(it => new { it.Id })
- .UpdateColumns(it => new { it.FID })
- .ExecuteCommandAsync();
- result.Code = 0;
- }
- return result;
- }
- }
- }
|