123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- using AutoMapper;
- using OASystem.Domain.AesEncryption;
- using OASystem.Domain.Dtos.Groups;
- using OASystem.Domain.Entities.Groups;
- using OASystem.Domain.ViewModels.Groups;
- using OASystem.Infrastructure.Tools;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime;
- using System.Text;
- using System.Threading.Tasks;
- namespace OASystem.Infrastructure.Repositories.Groups
- {
- /// <summary>
- /// 签证提成录入
- /// 仓储
- /// </summary>
- public class VisaCommissionRepository : BaseRepository<Grp_VisaCommission, VisaCommissionViewModel>
- {
- private readonly IMapper _mapper;
- private readonly DelegationInfoRepository _groupRep;
- public VisaCommissionRepository(SqlSugarClient sqlSugar, IMapper mapper, DelegationInfoRepository groupRep)
- : base(sqlSugar)
- {
- _mapper = mapper;
- _groupRep = groupRep;
- }
- /// <summary>
- /// Init
- /// </summary>
- /// <returns></returns>
- public async Task<JsonView> Init()
- {
- var groupInfo = await _groupRep.GetGroupNameList(new Domain.Dtos.Groups.GroupNameDto() { PortType = 1 });
- return new JsonView() { Code = StatusCodes.Status200OK, Msg = "操作成功!", Data = new { GroupData = groupInfo.Data } };
- }
- /// <summary>
- /// Item
- /// </summary>
- /// <returns></returns>
- public async Task<JsonView> Item(VisaCommissionItemDto _dto)
- {
- var data = await _sqlSugar.Queryable<Grp_VisaCommission>()
- .Where(x => x.IsDel == 0 && x.DiId == _dto.DiId && x.UId == _dto.CurrUserId)
- .Select(x => new
- {
- x.Id,
- x.Country,
- x.Quantity,
- x.Remark
- })
- .ToListAsync();
- var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.IsDel == 0 && x.Id == _dto.DiId).FirstAsync();
- if (groupInfo != null)
- {
- string[] countryArray = _groupRep.GroupSplitCountry(groupInfo.VisitCountry).ToArray();
- foreach (string country in countryArray)
- {
- if (data.Find(x => country.Equals(x.Country)) == null)
- {
- data.Add(new
- {
- Id = 0,
- Country = country,
- Quantity = 0,
- Remark = ""
- });
- }
- }
- }
- return new JsonView() { Code = StatusCodes.Status200OK, Msg = "操作成功!", Data = data };
- }
- /// <summary>
- /// Save
- /// </summary>
- /// <returns></returns>
- public async Task<JsonView> Save(VisaCommissionSaveDto _dto)
- {
- var data = _mapper.Map<List<Grp_VisaCommission>>(_dto.Items);
- for (int i = 0; i < data.Count; i++)
- {
- data[i].CreateUserId = _dto.Items.FirstOrDefault()?.CurrUserId ?? 0;
- data[i].UId = _dto.Items.FirstOrDefault()?.CurrUserId ?? 0;
- }
- //添加数据
- var addData = data.Where(x => x.Id < 1).ToList();
- //修改数据
- var updData = data.Where(x => x.Id > 0).ToList();
- _sqlSugar.BeginTran();
- bool status = false;
- if (addData.Count > 0) {
-
- var addCount = await _sqlSugar.Insertable<Grp_VisaCommission>(addData).ExecuteCommandAsync();
- if (addCount > 0) status=true;
- }
- if (updData.Count > 0)
- {
- var updCount = await _sqlSugar.Updateable<Grp_VisaCommission>(updData)
- .UpdateColumns(x => new
- {
- x.Country,
- x.Quantity,
- x.Remark
- })
- .WhereColumns(x => x.Id)
- .ExecuteCommandAsync();
- if (updCount > 0) status = true;
- }
- var jv = new JsonView() { Code = StatusCodes.Status200OK, Msg = "操作成功!" };
- if (status) _sqlSugar.CommitTran();
- else
- {
- _sqlSugar.RollbackTran();
- jv.Code = StatusCodes.Status400BadRequest;
- jv.Msg = "操作失败";
- }
- return jv;
- }
- /// <summary>
- /// Create
- /// </summary>
- /// <returns></returns>
- public async Task<JsonView> Create(VisaCommissionCreateDto _dto)
- {
- var _view = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "操作失败!" };
- //添加查重
- var info = await _sqlSugar.Queryable<Grp_VisaCommission>()
- .Where(x => x.IsDel == 0 && x.DiId == _dto.DiId && x.Country.Equals(_dto.Country))
- .FirstAsync();
- //if (info != null)
- //{
- // _view.Code = StatusCodes.Status400BadRequest;
- // _view.Msg = "该数据已存在请勿重新添加!";
- // return _view;
- //}
- var createInfo = _mapper.Map<Grp_VisaCommission>(_dto);
- createInfo.CreateUserId = _dto.CurrUserId;
- createInfo.UId = _dto.CurrUserId;
- var createStatus = await _sqlSugar.Insertable<Grp_VisaCommission>(createInfo)
- .ExecuteCommandAsync();
- if (createStatus > 0)
- {
- _view.Code = StatusCodes.Status200OK;
- _view.Msg = "操作成功!";
- return _view;
- }
- return _view;
- }
- /// <summary>
- /// Edit
- /// </summary>
- /// <param name="id"></param>
- /// <param name="_dto"></param>
- /// <returns></returns>
- public async Task<JsonView> Edit(int id,VisaCommissionCreateDto _dto)
- {
- var _view = new JsonView() { Code = StatusCodes.Status204NoContent, Msg = "操作失败!" };
- var editInfo = _mapper.Map<Grp_VisaCommission>(_dto);
- editInfo.CreateUserId = _dto.CurrUserId;
- editInfo.UId = _dto.CurrUserId;
- var editStatus = await _sqlSugar.Updateable<Grp_VisaCommission>(editInfo)
- .UpdateColumns(x => new
- {
- x.Country,
- x.Quantity,
- x.Remark
- })
- .Where(x => x.Id == id)
- .ExecuteCommandAsync();
- if (editStatus > 0)
- {
- _view.Code = StatusCodes.Status200OK;
- _view.Msg = "操作成功!";
- return _view;
- }
- return _view;
- }
- /// <summary>
- /// Del
- /// </summary>
- /// <param name="id"></param>
- /// <param name="currUserId"></param>
- /// <returns></returns>
- public async Task<JsonView> Del(int id,int currUserId)
- {
- var _view = new JsonView() { Code = StatusCodes.Status204NoContent, Msg = "操作失败!" };
- var editStatus = await _sqlSugar.Updateable<Grp_VisaCommission>()
- .SetColumns(x => new Grp_VisaCommission
- {
- DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
- DeleteUserId = currUserId,
- })
- .Where(x => x.Id == id)
- .ExecuteCommandAsync();
- if (editStatus > 0)
- {
- _view.Code = StatusCodes.Status200OK;
- _view.Msg = "操作成功!";
- return _view;
- }
- return _view;
- }
- }
- }
|