123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516 |
- using AutoMapper;
- using MathNet.Numerics.Distributions;
- using MathNet.Numerics.Statistics.Mcmc;
- using Newtonsoft.Json;
- using NPOI.SS.Formula.Functions;
- using OASystem.Domain;
- using OASystem.Domain.AesEncryption;
- using OASystem.Domain.Dtos.Resource;
- using OASystem.Domain.Entities.Groups;
- using OASystem.Domain.Entities.Resource;
- using OASystem.Domain.ViewModels.Resource;
- using OASystem.Infrastructure.Tools;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace OASystem.Infrastructure.Repositories.Resource
- {
- public class OfficialActivitiesRepository : BaseRepository<Res_OfficialActivities, OfficialActivitiesView>
- {
- private readonly IMapper _mapper;
- public OfficialActivitiesRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
- {
- _mapper = mapper;
- }
- /// <summary>
- /// 根据Diid查询公务出访数据List
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- public async Task<JsonView> QueryOfficialActivitiesByDiId(OfficialActivitiesByDiIdDto dto)
- {
- JsonView result = new JsonView() { Code = StatusCodes.Status200OK, Msg = "暂无数据" };
- string sqlWhere = string.Empty;
- sqlWhere += string.Format(@"AND o.Isdel={0} AND o.DiId={1} ", 0, dto.DiId);
- if (!string.IsNullOrEmpty(sqlWhere.Trim()))
- {
- Regex r = new Regex("AND");
- sqlWhere = r.Replace(sqlWhere, "WHERE", 1);
- }
- string sql = string.Format(@"
- SELECT
- *,
- u.CnName AS CreateUserName,
- sd.Name AS OfficialFormName
- FROM
- Res_OfficialActivities o
- LEFT JOIN Sys_SetData sd ON o.OfficialForm = sd.Id
- LEFT JOIN Sys_Users u ON o.CreateUserId = u.Id
- {0}
- ORDER BY
- o.CreateTime desc
- ", sqlWhere);
- var OfficialActivities = await _sqlSugar.SqlQueryable<OfficialActivitiesView>(sql).ToListAsync();
- if (OfficialActivities.Count != 0)
- {
- if (dto.PageSize == 0 && dto.PageIndex == 0)
- {
- OfficialActivities.ForEach(x =>
- {
- //2024年4月1日 11:55:44 -蒋金辰 -日期处理
- DateTime dt;
- bool b_dt = DateTime.TryParse(x.Date, out dt);
- if (b_dt)
- {
- if (!string.IsNullOrEmpty(x.Time)) x.Date = dt.ToString("yyyy-MM-dd") + " " + x.Time;
- else x.Date = dt.ToString("yyyy-MM-dd HH:mm:ss");
- }
- });
- result = new JsonView() { Code = 200, Msg = "查询成功!", Data = OfficialActivities };
- }
- else
- {
- int count = OfficialActivities.Count;
- float totalPage = (float)count / dto.PageSize;//总页数
- if (totalPage == 0) totalPage = 1;
- else totalPage = (int)Math.Ceiling((double)totalPage);
- List<OfficialActivitiesView> _OfficialActivities = new List<OfficialActivitiesView>();
- for (int i = 0; i < dto.PageSize; i++)
- {
- var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
- if (RowIndex < OfficialActivities.Count)
- {
- //2024年4月1日 11:55:44 -蒋金辰 -日期处理
- DateTime dt;
- bool b_dt = DateTime.TryParse(OfficialActivities[RowIndex].Date, out dt);
- if (b_dt)
- {
- OfficialActivities[RowIndex].Date = dt.ToString("yyyy-MM-dd HH:mm");
- }
- _OfficialActivities.Add(OfficialActivities[RowIndex]);
- }
- else
- {
- break;
- }
- }
- ListViewBase<OfficialActivitiesView> rst = new ListViewBase<OfficialActivitiesView>();
- rst.DataList = _OfficialActivities;
- rst.DataCount = count;
- rst.CurrPageIndex = dto.PageIndex;
- rst.CurrPageSize = dto.PageSize;
- result = new JsonView() { Code = 200, Msg = "查询成功!", Data = rst };
- }
- }
- else
- {
- result = new JsonView() { Code = StatusCodes.Status200OK, Msg = "暂无数据!" };
- if (dto.PageSize == 0 && dto.PageIndex == 0) { result.Data = OfficialActivities; }
- else {
- ListViewBase<OfficialActivitiesView> rst = new ListViewBase<OfficialActivitiesView>();
- rst.DataList = OfficialActivities;
- rst.DataCount = 0;
- rst.CurrPageIndex = dto.PageIndex;
- rst.CurrPageSize = dto.PageSize;
- result.Data = rst;
- }
- }
- return result;
- }
- /// <summary>
- /// 根据公务出访Id查询单个数据
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- /// <exception cref="NotImplementedException"></exception>
- public async Task<Result> QueryOfficialActivitiesById(OfficialActivitiesDiIdDto dto)
- {
- Result result = new Result() { Code = -2, Msg = "未知错误" };
- try
- {
- string sqlWhere = string.Empty;
- sqlWhere += string.Format(@"AND oa.Isdel={0} AND oa.DiId={1} AND oa.Id={2}", 0, dto.DiId, dto.Id);
- if (!string.IsNullOrEmpty(sqlWhere.Trim()))
- {
- Regex r = new Regex("AND");
- sqlWhere = r.Replace(sqlWhere, "WHERE", 1);
- }
- string sql = string.Format(@"
- SELECT
- oa.*,
- u.CnName AS CreateUserName,
- sd.Name AS OfficialFormName
- FROM
- Res_OfficialActivities oa
- LEFT JOIN Sys_Users u ON oa.CreateUserId = u.Id
- LEFT JOIN Sys_SetData sd ON oa.OfficialForm = sd.Id
- {0}", sqlWhere);
- var oa = await _sqlSugar.SqlQueryable<OfficialActivitiesView>(sql).FirstAsync();
- var array1 = _sqlSugar.Queryable<Grp_OfficialDutyLinkTranslator>()
- .Where(x => x.IsDel == 0 && x.OfficialDutyId == dto.Id)
- .Select(x => x.TranslatorId)
- .ToArray();
- if (array1.Any())
- {
- oa.TranslatorIdItem = array1;
- int translatorId = array1[0];
- var translatorInfo = await _sqlSugar.Queryable<Res_TranslatorLibrary>()
- .Where(x => x.IsDel == 0 && x.Id == translatorId)
- .FirstAsync();
- EncryptionProcessor.DecryptProperties(translatorInfo);
- oa.TranslatorInfo = _mapper.Map<TranslatorView>(translatorInfo);
- oa.TranslatorInfo.CurrencyName = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.Id == oa.TranslatorInfo.Currency).First()?.Name ?? "";
- }
- result = new Result() { Code = 0, Msg = "查询成功!", Data = oa };
- }
- catch (Exception ex)
- {
- result = new Result() { Code = -2, Msg = "未知错误" };
- }
- return result;
- }
- public async Task<Result> OpOfficialActivities(OpOfficialActivitiesDto dto)
- {
- var result = new Result() { Code = -2, Msg = "未知错误" };
- var language = dto?.TranslatorInfo?.Language;
- #region 特殊字符转码 037 - 4.28 15:17
- if (!string.IsNullOrEmpty(dto.Contact))
- {
- byte[] utf8Bytes = Encoding.UTF8.GetBytes(dto.Contact);
- byte[] utf16Bytes = Encoding.Convert(Encoding.UTF8, Encoding.Unicode, utf8Bytes);
- dto.Contact = Encoding.Unicode.GetString(utf16Bytes);
- }
- #endregion
- _sqlSugar.BeginTran();
- //添加到资料库
- var res_InvitationData = new Res_InvitationOfficialActivityData();
- res_InvitationData.Country = dto.Country;
- res_InvitationData.City = dto.Area;
- res_InvitationData.UnitName = dto.Client;
- res_InvitationData.Delegation = dto.DiId.ToString();
- res_InvitationData.Address = dto.Address;
- res_InvitationData.CreateUserId = dto.CreateUserId;
- res_InvitationData.Contact = dto.Contact;
- res_InvitationData.Job = dto.Job;
- res_InvitationData.Tel = dto.Tel;
- res_InvitationData.Field = dto.Field;
- EncryptionProcessor.EncryptProperties(res_InvitationData);
- var isInserTranslator = false;
- var translatorInfo = new Res_TranslatorLibrary();
- if (true)
- {
- //翻译人员资料
- translatorInfo = _mapper.Map<Res_TranslatorLibrary>(dto.TranslatorInfo);
- translatorInfo.CreateUserId = dto.CreateUserId;
- if (dto.TranslatorIdItem.Any()) translatorInfo.Id = dto.TranslatorIdItem[0];
- EncryptionProcessor.EncryptProperties(translatorInfo);
- isInserTranslator = true;
- }
- int DataID = 0;
- if (dto.Status == 1)//添加
- {
- //添加资料
- DataID = await _sqlSugar.Insertable(res_InvitationData).ExecuteReturnIdentityAsync();
- var _InvitationOfficialActivityData = _mapper.Map<Res_OfficialActivities>(dto);
- _InvitationOfficialActivityData.DataId = DataID;
- _InvitationOfficialActivityData.Language = language;
- int id = await _sqlSugar.Insertable(_InvitationOfficialActivityData).ExecuteReturnIdentityAsync();
- if (id == 0)
- {
- _sqlSugar.RollbackTran();
- result = new Result() { Code = -1, Msg = "添加失败!" };
- }
- else
- {
- var translatorId = translatorInfo.Id;
- if (isInserTranslator)
- {
- if (translatorId > 0) // 翻译人员资料更新
- {
- var tiStatus = await _sqlSugar.Updateable<Res_TranslatorLibrary>(translatorInfo)
- .UpdateColumns(x => new
- {
- x.Area,
- x.Name,
- x.Sex,
- x.Tel,
- x.Email,
- x.WechatNo,
- x.OtherSocialAccounts,
- x.Language,
- x.Price,
- x.Currency,
- })
- .ExecuteCommandAsync();
- if (tiStatus < 1)
- {
- _sqlSugar.RollbackTran();
- return new Result() { Code = -1, Msg = "翻译人员资料更新失败!", Data = new { Id = id } };
- }
- }
- else //添加翻译人员资料
- {
- translatorId = await _sqlSugar.Insertable(translatorInfo).ExecuteReturnIdentityAsync();
- if (translatorId == 0)
- {
- _sqlSugar.RollbackTran();
- return new Result() { Code = -1, Msg = "翻译人员资料添加失败!", Data = new { Id = id } };
- }
- }
- #region 新增(公务信息关联翻译人员) 关联信息
- var linkStatus = await _sqlSugar
- .Insertable(new Grp_OfficialDutyLinkTranslator()
- {
- TranslatorId = translatorId,
- OfficialDutyId = id,
- CreateUserId = dto.CreateUserId,
- Remark = $"公务出访客户资料-->添加"
- }).ExecuteCommandAsync();
- if (linkStatus < 1)
- {
- _sqlSugar.RollbackTran();
- return new Result() { Code = -1, Msg = "公务出访关联翻译人员资料添加失败!", Data = new { Id = id } };
- }
- #endregion
- }
- _sqlSugar.CommitTran();
- result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
- }
- }
- else if (dto.Status == 2)//修改
- {
- var officialActivities = _sqlSugar.Queryable<Res_OfficialActivities>().First(x => x.Id == dto.Id);
- if (officialActivities.DataId > 0)
- {
- res_InvitationData.Id = officialActivities.DataId;
- }
- else
- {
- var ifNullUp = await _sqlSugar.Queryable<Res_InvitationOfficialActivityData>()
- .FirstAsync(a => a.Country == res_InvitationData.Country
- && a.City == res_InvitationData.City
- && a.UnitName == res_InvitationData.UnitName
- && a.IsDel == 0
- && a.Address == res_InvitationData.Address);
- if (ifNullUp != null)
- {
- res_InvitationData.Id = ifNullUp.Id;
- }
- }
- if (res_InvitationData.Id == 0 )
- {
- DataID = await _sqlSugar.Insertable(res_InvitationData).ExecuteReturnIdentityAsync();
- }
- else
- {
- DataID = res_InvitationData.Id;
- //商邀资料
- await _sqlSugar.Updateable<Res_InvitationOfficialActivityData>(res_InvitationData)
- .UpdateColumns(x => new
- {
- x.Country,
- x.City,
- x.UnitName,
- x.Delegation,
- x.Address,
- x.CreateUserId,
- x.Contact,
- x.Job,
- x.Tel,
- x.Field,
- })
- .ExecuteCommandAsync();
- }
-
- //公务出访
- bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Res_OfficialActivities
- {
- DataSource = dto.DataSource,
- Country = dto.Country,
- Area = dto.Area,
- Type = dto.Type,
- Client = dto.Client,
- Date = dto.Date,
- Time = dto.Time,
- Address = dto.Address,
- Contact = dto.Contact,
- Job = dto.Job,
- Tel = dto.Tel,
- OfficialForm = dto.OfficialForm,
- Field = dto.Field,
- ReqSample = dto.ReqSample,
- Setting = dto.Setting,
- Dresscode = dto.Dresscode,
- Attendees = dto.Attendees,
- IsNeedTrans = dto.IsNeedTrans,
- //Translators = dto.Translators,
- Language = language,
- Trip = dto.Trip,
- CreateUserId = dto.CreateUserId,
- Remark = dto.Remark,
- IsPay = dto.IsPay,
- IsSubmitApproval = dto.IsSubmitApproval,
- EmailOrWeChat = dto.EmailOrWeChat,
- Website = dto.Website,
- Nature = dto.Nature,
- DataId = DataID,
- });
- if (res)
- {
- if (isInserTranslator)
- {
- #region 更新(公务信息关联翻译人员) 关联信息
- if (translatorInfo.Id > 0) //资料更新
- {
- var tiStatus = await _sqlSugar.Updateable<Res_TranslatorLibrary>(translatorInfo)
- .UpdateColumns(x => new
- {
- x.Area,
- x.Name,
- x.Sex,
- x.Tel,
- x.Email,
- x.WechatNo,
- x.OtherSocialAccounts,
- x.Language,
- x.Price,
- x.Currency,
- })
- .ExecuteCommandAsync();
- if (tiStatus < 1)
- {
- _sqlSugar.RollbackTran();
- return new Result() { Code = -1, Msg = "翻译人员资料更新失败!", Data = new { Id = dto.Id } };
- }
- var dutyLink_select = await _sqlSugar.Queryable<Grp_OfficialDutyLinkTranslator>()
- .Where(x => x.IsDel == 0 && x.OfficialDutyId == dto.Id && x.TranslatorId == translatorInfo.Id)
- .FirstAsync();
- if (dutyLink_select == null)
- {
- var odltStatus = await _sqlSugar.Insertable(new Grp_OfficialDutyLinkTranslator()
- {
- TranslatorId = translatorInfo.Id,
- OfficialDutyId = dto.Id,
- CreateUserId = dto.CreateUserId,
- Remark = $"公务出访客户资料-->添加"
- }).ExecuteCommandAsync();
- if (odltStatus < 1)
- {
- _sqlSugar.RollbackTran();
- result = new Result() { Code = -1, Msg = "公务出访关联翻译人员资料添加失败!" };
- }
- }
- }
- else // 添加
- {
- translatorInfo.Id = await _sqlSugar.Insertable(translatorInfo).ExecuteReturnIdentityAsync();
- if (translatorInfo.Id == 0)
- {
- _sqlSugar.RollbackTran();
- return new Result() { Code = -1, Msg = "翻译人员资料添加失败!", Data = new { Id = dto.Id } };
- }
- var odltStatus = await _sqlSugar.Insertable(new Grp_OfficialDutyLinkTranslator()
- {
- TranslatorId = translatorInfo.Id,
- OfficialDutyId = dto.Id,
- CreateUserId = dto.CreateUserId,
- Remark = $"公务出访客户资料-->添加"
- }).ExecuteCommandAsync();
- if (odltStatus < 1)
- {
- _sqlSugar.RollbackTran();
- result = new Result() { Code = -1, Msg = "公务出访关联翻译人员资料添加失败!" };
- }
- }
- #endregion
- }
- _sqlSugar.CommitTran();
- result = new Result() { Code = 0, Msg = "修改成功!", Data = new { Id = dto.Id } };
- }
- else
- {
- _sqlSugar.RollbackTran();
- result = new Result() { Code = -1, Msg = "公务出访修改失败!" };
- }
- }
- else
- {
- _sqlSugar.RollbackTran();
- result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
- }
- return result;
- }
- public async Task<Result> PostReqReqSampleTips(string country, string Area,string client)
- {
- if (string.IsNullOrEmpty(country)) return new Result() { Code = -1, Msg = "国家为空!" };
- string sqlWhere = string.Empty;
- if (!string.IsNullOrEmpty(Area)) sqlWhere = string.Format(@$" And oa.Area Like '%{Area}%'");
- if (!string.IsNullOrEmpty(client)) sqlWhere = string.Format(@$" And oa.Client Like '%{client}%'");
- string sql = string.Format(@$"Select di.TeamName,oa.Id,oa.Country,oa.Area,oa.Client,oa.ReqSample
- From Res_OfficialActivities oa With(NoLock)
- Left Join Grp_DelegationInfo di On oa.DiId = di.Id
- Where oa.IsDel = 0 And oa.Country='{country}' {sqlWhere}");
- //ReqReqSampleTipsView
- var _views = await _sqlSugar.SqlQueryable<ReqReqSampleTipsView>(sql).ToListAsync();
- if (_views.Count > 0 )
- {
- return new Result() { Code = 0, Msg = "操作成功!", Data = _views };
- }
- return new Result() { Code = -1, Msg = "暂无相关数据!" };
- }
- }
- }
|