1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129 |
- using AutoMapper;
- using Newtonsoft.Json;
- using NPOI.OpenXmlFormats.Wordprocessing;
- using NPOI.SS.Formula.Functions;
- using OASystem.Domain;
- using OASystem.Domain.AesEncryption;
- using OASystem.Domain.Dtos;
- using OASystem.Domain.Dtos.Financial;
- using OASystem.Domain.Dtos.Groups;
- using OASystem.Domain.Dtos.UserDto;
- using OASystem.Domain.Entities.Customer;
- using OASystem.Domain.Entities.Groups;
- using OASystem.Domain.ViewModels.CRM;
- using OASystem.Domain.ViewModels.Financial;
- using OASystem.Domain.ViewModels.Groups;
- using OASystem.Infrastructure.Repositories.System;
- using Org.BouncyCastle.Asn1.Cms;
- using Org.BouncyCastle.Utilities.Collections;
- using Serilog;
- using SqlSugar;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace OASystem.Infrastructure.Repositories.Groups
- {
- /// <summary>
- /// 接团信息
- /// </summary>
- public class DelegationInfoRepository : BaseRepository<Grp_DelegationInfo, DelegationInfoView>
- {
- private readonly SetDataRepository _setDataRepository;
- private readonly UsersRepository _usersRepository;
- private readonly TaskAssignmentRepository _taskAssignmentRep;
- private readonly IMapper _mapper;
- //private readonly TeamRateRepository _teamRateRep;
- //public readonly Logs _logs;
- public DelegationInfoRepository(SqlSugarClient sqlSugar, SetDataRepository setDataRepository, UsersRepository usersRepository,
- TaskAssignmentRepository taskAssignmentRep, IMapper mapper)
- : base(sqlSugar)
- {
- _setDataRepository = setDataRepository;
- _usersRepository = usersRepository;
- _taskAssignmentRep = taskAssignmentRep;
- _mapper = mapper;
- //_teamRateRep = teamRateRep;
- }
- #region 团组信息 团组详情共享Api
- /// <summary>
- /// 团组信息 团组预览详情共享Api
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- public async Task<Result> PostShareGroupInfo(ShareGroupInfoDto dto)
- {
- Result result = new Result() { Code = -2, Msg = "未知错误" };
- string sql = string.Format(@"Select Id,TeamName,TourCode,ClientName,VisitCountry,VisitStartDate,VisitEndDate,VisitDays,VisitPNumber
- From Grp_DelegationInfo Where Id = {0} And IsDel = 0", dto.Id);
- if (dto.PortType == 1) //Web
- {
- var _DelegationInfo = await _sqlSugar.SqlQueryable<Web_ShareGroupInfoView>(sql).FirstAsync();
- if (_DelegationInfo != null)
- {
- _DelegationInfo.VisitCountry = FormartTeamName(_DelegationInfo.VisitCountry);
- }
- else result.Msg = "暂无该团组信息";
- result.Data = _DelegationInfo;
- }
- else if (dto.PortType == 2 || dto.PortType == 3) //IOS Or Android
- {
- var _DelegationInfo = await _sqlSugar.SqlQueryable<IOSOrAndroid_ShareGroupInfoView>(sql).FirstAsync();
- if (_DelegationInfo != null)
- {
- _DelegationInfo.VisitCountry = FormartTeamName(_DelegationInfo.VisitCountry);
- result.Data = _DelegationInfo;
- }
- else result.Msg = "暂无该团组信息";
- result.Data = _DelegationInfo;
- }
- else result.Msg = "请输入正确的端口号。1 Web 2 Android 3 IOS";
- result.Code = 0;
- result.Msg = "成功!";
- return result;
- }
- /// <summary>
- /// 团组信息List 团组预览详情共享Api
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- public async Task<Result> PostShareGroupInfos(int portType)
- {
- Result result = new Result() { Code = -2, Msg = "未知错误", Data = new List<object>() { } };
- string sql = string.Format(@"Select Id,TeamName,TourCode,ClientName,VisitCountry,VisitStartDate,VisitEndDate,VisitDays,VisitPNumber
- From Grp_DelegationInfo With(NoLock) Where IsDel = 0 Order By Id Desc");
- var _DelegationInfo = await _sqlSugar.SqlQueryable<Web_ShareGroupInfoView>(sql).ToListAsync();
- if (_DelegationInfo.Count > 0)
- {
- foreach (var item in _DelegationInfo)
- {
- item.VisitCountry = FormartTeamName(item.VisitCountry);
- }
- }
- else { result.Msg = "暂无该团组信息"; return result; }
- if (portType == 1) //Web
- {
- result.Data = _DelegationInfo;
- }
- else if (portType == 2 || portType == 3) //IOS Or Android
- {
- result.Data = _DelegationInfo;
- }
- else { result.Msg = "请输入正确的端口号。1 Web 2 Android 3 IOS"; return result; }
- result.Code = 0;
- result.Msg = "成功!";
- return result;
- }
- #endregion
- /// <summary>
- /// 获取接团信息Info
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- public async Task<Result> PostGroupInfo(GroupInfoDto dto)
- {
- Result result = new Result() { Code = -2, Msg = "未知错误" };
- if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //Web Or Android
- {
- string sql = string.Format(@"Select Id,SalesQuoteNo,TourCode,JietuanOperator,TeamLevSId,TeamDid,TeamName,ClientName,
- ClientUnit,VisitCountry,VisitDate,VisitDays,VisitPNumber,TontractTime,
- PayDay,PaymentMoney,VisitPurpose,SpecialNeeds,OtherNeeds,CGRWSPBMMC,CGRWSPWH,
- ZZSCBMMC,ZZSCSPWH,Remark,TellPhone,Officialneeds
- From Grp_DelegationInfo Where Id = {0} And IsDel = 0", dto.Id);
- var _DelegationInfo = await _sqlSugar.SqlQueryable<DelegationInfoWebView>(sql).FirstAsync();
- if (_DelegationInfo != null)
- {
- _DelegationInfo.TeamName = FormartTeamName(_DelegationInfo.TeamName);
- result.Code = 0;
- result.Msg = "成功!";
- result.Data = _DelegationInfo;
- }
- else result.Msg = "暂无该团组信息";
- }
- return result;
- }
- #region 团组
- /// <summary>
- /// 统一团组国家分割字符
- /// </summary>
- /// <param name="teamName"></param>
- /// <returns></returns>
- public string FormartTeamName(string teamName)
- {
- string str = "";
- if (!string.IsNullOrEmpty(teamName))
- {
- str = teamName;
- List<string> searchreplaces = new List<string>() { "|", " ", "/", ",", "," };
- foreach (var item in searchreplaces)
- {
- if (str.Contains(item))
- {
- str = str.Replace(item, "、");
- break;
- }
- }
- }
- return str.Trim();
- }
- /// <summary>
- /// 团组国家分割字符
- /// 返回 国家数组
- /// </summary>
- /// <param name="teamName"></param>
- /// <returns></returns>
- public List<string> GroupSplitCountry (string visitCountry)
- {
- List<string> countrys = new List<string>();
- if (!string.IsNullOrEmpty(visitCountry))
- {
- if (visitCountry.Contains("、")) countrys = visitCountry.Split("、").ToList();
- else if (visitCountry.Contains("|")) countrys = visitCountry.Split("|").ToList();
- else countrys.Add(visitCountry);
- }
- return countrys;
- }
- /// <summary>
- /// 获取接团信息 Page List
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- public async Task<Result> GetGroupPageList(GroupCommissionDto dto)
- {
- Result result = new Result() { Code = -2, Msg = "未知错误" };
- ListViewBase<DelegationPageListView> groupsInfoPageList = new ListViewBase<DelegationPageListView>()
- {
- ReceiveDt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
- };
- if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
- {
- int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
- int endIndex = startIndex + dto.PageSize - 1;
- int taskUserId = -1;
- string taskGroupIds = string.Empty;
- #region 处理用户团组操作权限
- if (dto.UserId != -1)
- {
- }
- #endregion
- string sql = string.Format(@"Select * From(Select row_number() over (order by gdi.Id Desc) as RowNumber,
- gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,ssd1.Id TeamLevId,
- ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,VisitDate,VisitDays,VisitPNumber,
- su.CnName JietuanOperator,IsSure
- From Grp_DelegationInfo gdi
- Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
- Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
- Left Join Sys_Users su On gdi.CreateUserId = su.Id
- Where gdi.IsDel = 0
- )temp Where RowNumber Between {0} and {1}", startIndex, endIndex);
- string sqlCount = string.Format(@"Select Count(1) as Count From Grp_DelegationInfo gdi
- Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
- Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
- Left Join Sys_Users su On gdi.CreateUserId = su.Id
- Where gdi.IsDel = 0 ");
- List<DelegationPageListView> _DeleInfoList = await _sqlSugar.SqlQueryable<DelegationPageListView>(sql).ToListAsync();
- DelegationPageCountView _DeleCount = await _sqlSugar.SqlQueryable<DelegationPageCountView>(sqlCount).FirstAsync();
- int count = _DeleCount.Count;
- groupsInfoPageList = new ListViewBase<DelegationPageListView>
- {
- CurrPageIndex = dto.PageIndex,
- CurrPageSize = dto.PageSize,
- DataCount = count,
- DataList = _DeleInfoList
- };
- result.Code = 0;
- result.Msg = "成功!";
- result.Data = groupsInfoPageList;
- }
- return result;
- }
- /// <summary>
- /// 获取接团信息List
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- public async Task<Result> GetGroupList(GroupListDto dto)
- {
- Result result = new Result() { Code = -2, Msg = "未知错误" };
- if (dto.PortType == 1) {
- string sql = string.Format(@"Select gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,VisitDate,VisitDays,VisitPNumber,su.CnName JietuanOperator,IsSure
- ,gs.Id as GrpScheduleId
- From Grp_DelegationInfo gdi
- Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
- Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
- Left Join Sys_Users su On gdi.CreateUserId = su.Id
- left Join Grp_Schedule gs On gdi.Id = gs.DiId
- Where gdi.IsDel = 0
- Order By gdi.CreateTime Desc");
- var _DelegationList = await _sqlSugar.SqlQueryable<DelegationListView>(sql).ToListAsync();
- if (_DelegationList.Count > 0)
- {
- result.Code = 0;
- result.Msg = "成功!";
- result.Data = _DelegationList;
- }
- else
- {
- result.Msg = "暂无该团组信息";
- }
- }
- else if (dto.PortType == 2 || dto.PortType == 3) //web
- {
- string sql = string.Format(@"Select gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,VisitDate,VisitDays,VisitPNumber,su.CnName JietuanOperator,IsSure
- From Grp_DelegationInfo gdi
- Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
- Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
- Left Join Sys_Users su On gdi.CreateUserId = su.Id
- Where gdi.IsDel = 0
- Order By gdi.CreateTime Desc");
- var _DelegationList = await _sqlSugar.SqlQueryable<DelegationListView>(sql).ToListAsync();
- if (_DelegationList.Count > 0)
- {
- result.Code = 0;
- result.Msg = "成功!";
- result.Data = _DelegationList;
- }
- else
- {
- result.Msg = "暂无该团组信息";
- }
- }
- return result;
- }
- /// <summary>
- /// 获取接团信息Info
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- public async Task<Result> GetGroupInfo(GroupInfoDto dto)
- {
- Result result = new Result() { Code = -2, Msg = "未知错误" };
- if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //Web Or Android
- {
- string sql = string.Format(@"Select Id,SalesQuoteNo,TourCode,JietuanOperator,TeamLevSId,TeamDid,TeamName,ClientName,
- ClientUnit,VisitCountry,VisitDate,VisitDays,VisitPNumber,TontractTime,IsBid,
- PayDay,PaymentMoney,VisitPurpose,SpecialNeeds,OtherNeeds,CGRWSPBMMC,CGRWSPWH,
- ZZSCBMMC,ZZSCSPWH,Remark,TellPhone,WeChatNo,OpRoyaltyLv,OpRoyaltyRemark,Officialneeds
- From Grp_DelegationInfo Where Id = {0} And IsDel = 0", dto.Id);
- var _DelegationInfo = await _sqlSugar.SqlQueryable<DelegationInfoWebView>(sql).FirstAsync();
- if (_DelegationInfo != null)
- {
- _DelegationInfo.TeamName = FormartTeamName(_DelegationInfo.TeamName);
- _DelegationInfo.VisitCountry = FormartTeamName(_DelegationInfo.VisitCountry);
- //if (_DelegationInfo.TontractTime)
- //{
- //}
- result.Code = 0;
- result.Msg = "成功!";
- result.Data = _DelegationInfo;
- if (dto.PortType == 2)
- {
- var GroupProcessOperationDtoParam = new GroupProcessOperationDto();
- GroupProcessOperationDtoParam = _mapper.Map<DelegationInfoWebView, GroupProcessOperationDto>(_DelegationInfo);
- List<Crm_DeleClient> DeleClientArr = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToListAsync(); //客户信息
- List<Grp_TourClientList> _DeleClients = await _sqlSugar.Queryable<Grp_TourClientList>().Where(it => it.IsDel == 0 && it.DiId == dto.Id).ToListAsync(); // 接团客户名单
- List<Crm_CustomerCert> _CustomerCerts = await _sqlSugar.Queryable<Crm_CustomerCert>().Where(it => it.IsDel == 0 && it.SdId == 773).ToListAsync(); // 身份证类型证件信息
- List<Crm_CustomerCompany> CompanyArr = await _sqlSugar.Queryable<Crm_CustomerCompany>().Where(it => it.IsDel == 0).ToListAsync();
- var TourClientListInfoArr = new List<TourClientListProcessInfo>();
- var timeParam = new DateTime();
- foreach (var item in _DeleClients)
- {
- var param = new TourClientListProcessInfo();
- var clientInfo = DeleClientArr.FirstOrDefault(x => x.Id == item.ClientId);
- if (clientInfo == null) clientInfo = new Crm_DeleClient();
- var clientIDInfo = _CustomerCerts.FirstOrDefault(x=>x.DcId == item.ClientId); //身份证信息
- if (clientIDInfo == null) clientIDInfo = new Crm_CustomerCert();
- var Company = CompanyArr.FirstOrDefault(x => x.Id == clientInfo.CrmCompanyId);
- if(Company == null) Company = new Crm_CustomerCompany();
- param.IDCardNo = clientIDInfo.CertNo;
- param.Remark = item.Remark;
- param.BirthDay = clientInfo.BirthDay == null ? "" : DateTime.TryParse(Convert.ToDateTime( clientInfo.BirthDay).ToString("yyyy-MM-dd"), out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
- param.FirstName = clientInfo.FirstName;
- param.LastName = clientInfo.LastName;
- param.CompanyFullName = Company.CompanyFullName;
- param.Job = clientInfo.Job;
- param.Sex = clientInfo.Sex;
- param.Phone = clientInfo.Phone;
- param.Pinyin = clientInfo.Pinyin;
- param.HotelSpecialNeeds = item.HotelSpecialNeeds;
- param.MealSpecialNeeds = item.MealSpecialNeeds;
- param.ShippingSpaceSpecialNeeds = item.ShippingSpaceSpecialNeeds;
- param.ShippingSpaceTypeId = item.ShippingSpaceTypeId;
- param.Id = clientInfo.Id;
- EncryptionProcessor.DecryptProperties(param);
- TourClientListInfoArr.Add(param);
- }
- GroupProcessOperationDtoParam.PortType = dto.PortType;
- GroupProcessOperationDtoParam.TourClientListInfos = TourClientListInfoArr;
- GroupProcessOperationDtoParam.VisitDate = DateTime.TryParse(GroupProcessOperationDtoParam.VisitDate, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
- GroupProcessOperationDtoParam.VisitDate = DateTime.TryParse(GroupProcessOperationDtoParam.VisitDate, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
- GroupProcessOperationDtoParam.TontractTime = DateTime.TryParse(GroupProcessOperationDtoParam.TontractTime, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
- result.Data = GroupProcessOperationDtoParam;
- }
- else if (dto.PortType == 3)
- {
- var GroupProcessOperationDtoParam = new GroupProcessOperationDto();
- GroupProcessOperationDtoParam = _mapper.Map<DelegationInfoWebView, GroupProcessOperationDto>(_DelegationInfo);
- List<Crm_DeleClient> DeleClientArr = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToListAsync(); //客户信息
- List<Grp_TourClientList> _DeleClients = await _sqlSugar.Queryable<Grp_TourClientList>().Where(it => it.IsDel == 0 && it.DiId == dto.Id).ToListAsync(); // 接团客户名单
- List<Crm_CustomerCert> _CustomerCerts = await _sqlSugar.Queryable<Crm_CustomerCert>().Where(it => it.IsDel == 0 && it.SdId == 773).ToListAsync(); // 身份证类型证件信息
- List<Crm_CustomerCompany> CompanyArr = await _sqlSugar.Queryable<Crm_CustomerCompany>().Where(it => it.IsDel == 0).ToListAsync();
- var TourClientListInfoArr = new List<TourClientListProcessInfo>();
- var timeParam = new DateTime();
- foreach (var item in _DeleClients)
- {
- var param = new TourClientListProcessInfo();
- var clientInfo = DeleClientArr.FirstOrDefault(x => x.Id == item.ClientId);
- if (clientInfo == null) clientInfo = new Crm_DeleClient();
- var clientIDInfo = _CustomerCerts.FirstOrDefault(x => x.DcId == item.ClientId); //身份证信息
- if (clientIDInfo == null) clientIDInfo = new Crm_CustomerCert();
- var Company = CompanyArr.FirstOrDefault(x => x.Id == clientInfo.CrmCompanyId);
- if (Company == null) Company = new Crm_CustomerCompany();
- param.IDCardNo = clientIDInfo.CertNo;
- param.Remark = item.Remark;
- param.BirthDay = clientInfo.BirthDay == null ? "" : DateTime.TryParse(Convert.ToDateTime(clientInfo.BirthDay).ToString("yyyy-MM-dd"), out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
- param.FirstName = clientInfo.FirstName;
- param.LastName = clientInfo.LastName;
- param.CompanyFullName = Company.CompanyFullName;
- param.Job = clientInfo.Job;
- param.Sex = clientInfo.Sex;
- param.Phone = clientInfo.Phone;
- param.Pinyin = clientInfo.Pinyin;
- param.HotelSpecialNeeds = item.HotelSpecialNeeds;
- param.MealSpecialNeeds = item.MealSpecialNeeds;
- param.ShippingSpaceSpecialNeeds = item.ShippingSpaceSpecialNeeds;
- param.ShippingSpaceTypeId = item.ShippingSpaceTypeId;
- param.Id = item.Id;
- EncryptionProcessor.DecryptProperties(param);
- TourClientListInfoArr.Add(param);
- }
- GroupProcessOperationDtoParam.PortType = dto.PortType;
- GroupProcessOperationDtoParam.TourClientListInfos = TourClientListInfoArr;
- GroupProcessOperationDtoParam.VisitDate = DateTime.TryParse(GroupProcessOperationDtoParam.VisitDate, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
- GroupProcessOperationDtoParam.TontractTime = DateTime.TryParse(GroupProcessOperationDtoParam.TontractTime, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
- result.Data = GroupProcessOperationDtoParam;
- }
- }
- else result.Msg = "暂无该团组信息";
- }
- return result;
- }
- /// <summary>
- /// 获取接团信息 编辑
- /// 基础 数据源
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- public async Task<Result> GroupEditBasicSource(GroupListDto dto)
- {
- Result result = new Result() { Code = -2, Msg = "未知错误" };
- if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
- {
- dynamic? teamTypeData1 = null;
- string teamTypeSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = {0} And IsDel = {1}", 10, 0);
- var teamTypeData = await _sqlSugar.SqlQueryable<SetDataInfoView>(teamTypeSql).ToListAsync(); ; //团组分类 10
- if (teamTypeData.Any())
- {
- teamTypeData1 = teamTypeData;
- }
- dynamic? teamLevData1 = null;
- string teamLevSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = {0} And IsDel = {1}", 56, 0);
- var teamLevData = await _sqlSugar.SqlQueryable<SetDataInfoView>(teamLevSql).ToListAsync(); ; //团组等级 56
- if (teamLevData.Any())
- {
- teamLevData1 = teamLevData;
- }
- dynamic? userData1 = null;
- string userSql = string.Format(@"Select Id,CnName From Sys_Users Where IsDel = {0}", 0);
- var userData = await _sqlSugar.SqlQueryable<UserNameView>(userSql).ToListAsync();
- if (userData.Any())
- {
- userData1 = userData;
- }
- //客户单位数据源 来源市场客户资料
- dynamic? clientData1 = null;
- string clientSql = $@"Select Client,Contact,Telephone,WeChat From Crm_NewClientData Where IsDel = 0";
- var clientData = await _sqlSugar.SqlQueryable<Crm_NewClientData>(clientSql).ToListAsync();
- if (clientData.Any())
- {
- clientData1 = clientData.Select(it => new
- {
- Client = AesEncryptionHelper.Decrypt(it.Client),
- Contact = AesEncryptionHelper.Decrypt(it.Contact),
- Telephone = AesEncryptionHelper.Decrypt(it.Telephone),
- Wechat = AesEncryptionHelper.Decrypt(it.Wechat)
- }).ToList();
- }
- result.Code = 0;
- result.Msg = "成功!";
- result.Data = new
- {
- teamTypeData = teamTypeData1,
- teamLevData = teamLevData1,
- userData = userData1,
- clientData = clientData1
- };
- }
- return result;
- }
- /// <summary>
- /// 团组信息操作
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- public async Task<Result>GroupOperation(GroupOperationDto dto)
- {
- Result result = new Result() { Code = -2, Msg = "未知错误" };
- if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
- {
- #region 添加出访起止时间
- var startTime = new DateTime();
- var endTime = new DateTime();
- if (DateTime.TryParse(dto.VisitDate, out startTime))
- {
- endTime = startTime.AddDays(dto.VisitDays - 1);//含当天
- }
- #endregion
- if (dto.Status == 1) //添加
- {
- string selectSql = string.Format(@"Select * From Grp_DelegationInfo
- Where IsDel = 0
- And TeamName = '{0}'
- And ClientName = '{1}'
- And ClientUnit ='{2}'
- And VisitDate ='{3}'",dto.TeamName, dto.ClientName, dto.ClientUnit, dto.VisitDate);
- var selectGroupInfo = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(selectSql).First();
- if (selectGroupInfo != null)
- {
- result.Msg = "数据已存在,请勿重复添加!";
- return result;
- }
- //string teamCodeSql = string.Format("Select SalesQuoteNo From Grp_DelegationInfo");
- //var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
- //string SalesQuoteNo = "";
- //while (true)
- //{
- // SalesQuoteNo = Tools.CommonFun.GetRandomStr(6);
- // if (!teamCodeItem.Equals(SalesQuoteNo))
- // {
- // break;
- // }
- //}
- string countrys = string.Empty;
- string countryReq = dto.VisitCountry;
- if (!string.IsNullOrEmpty(countryReq))
- {
- if (countryReq.Contains(",")) countrys = countryReq.Replace(',','|');
- else if (countryReq.Contains(",")) countrys = countryReq.Replace(',', '|');
- else if (countryReq.Contains(" ")) countrys = countryReq.Replace(' ', '|');
- else if (countryReq.Contains("、")) countrys = countryReq.Replace('、', '|');
- else if (countryReq.Contains(".")) countrys = countryReq.Replace('.', '|');
- else countrys = countryReq;
- }
- //建团时 默认出团 设置 团组code
- string teamCode="";
- string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
- var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
- while (true)
- {
- teamCode = Tools.CommonFun.GetRandomAllStr(6);
- if (!teamCodeItem.Equals(teamCode))
- {
- break;
- }
- }
- Grp_DelegationInfo delegationInfo = new Grp_DelegationInfo()
- {
- SalesQuoteNo = dto.SalesQuoteNo,
- TeamLevSId = dto.TeamLevSId,
- ClientName = dto.ClientName,
- ClientUnit = dto.ClientUnit,
- TeamName = dto.TeamName,
- TeamDid = dto.TeamDid,
- VisitDate = Convert.ToDateTime(dto.VisitDate),
- VisitCountry = countrys,
- VisitPurpose = dto.VisitPurpose,
- VisitDays = dto.VisitDays,
- VisitPNumber = dto.VisitPNumber,
- SpecialNeeds = dto.SpecialNeeds,
- OtherNeeds = dto.OtherNeeds,
- Remark = dto.Remark,
- JietuanOperator = dto.JietuanOperator,
- TellPhone = dto.TellPhone,
- WeChatNo = dto.WeChatNo,
- CGRWSPBMMC = dto.CGRWSPBMMC,
- CGRWSPWH = dto.CGRWSPWH,
- ZZSCBMMC = dto.ZZSCBMMC,
- ZZSCSPWH = dto.ZZSCSPWH,
- TontractTime = string.IsNullOrEmpty(dto.TontractTime) ? null : Convert.ToDateTime(dto.TontractTime),
- IsBid = dto.IsBid,
- PaymentMoney = dto.PaymentMoney,
- PayDay = dto.PayDay,
- TourCode = teamCode,
- GroupsOperator = dto.UserId,
- GroupsTime = DateTime.Now,
- SalesDate = DateTime.Now,
- IsState = 0, //默认团组未完成 0
- JietuanTime = DateTime.Now,
- IsDel = 0,
- BudgetCost = 0.00M,
- HotelComplain = 0,
- OPComplain = 0,
- OAComplain = 0,
- AirComplain = 0,
- VisaComplain = 0,
- CreateUserId = dto.UserId,
- CreateTime = DateTime.Now,
- DeleteUserId = null,
- DeleteTime = new DateTime(1990, 1, 1).ToString("yyyy-MM-dd HH:mm:ss"),
- OpRoyaltyLv = dto.OpRoyaltyLv,
- OpRoyaltyRemark=dto.opRoyaltyRemark,
- Officialneeds = dto.Officialneeds,
- VisitStartDate = startTime,
- VisitEndDate = endTime,
- };
- var addId = _sqlSugar.Insertable(delegationInfo).ExecuteReturnIdentity();
- if (addId > 0)
- {
- result.Code = 0;
- result.Msg = "添加成功!";
- result.Data = addId;
- }
- else
- {
- result.Msg = "添加失败!";
- }
- }
- else if (dto.Status == 2) //修改
- {
- var updateStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
- {
- SalesQuoteNo = dto.SalesQuoteNo,
- TeamLevSId = dto.TeamLevSId,
- ClientName = dto.ClientName,
- ClientUnit = dto.ClientUnit,
- TeamName = dto.TeamName,
- TeamDid = dto.TeamDid,
- VisitDate = Convert.ToDateTime(dto.VisitDate),
- VisitCountry = dto.VisitCountry,
- VisitPurpose = dto.VisitPurpose,
- VisitDays = dto.VisitDays,
- VisitPNumber = dto.VisitPNumber,
- SpecialNeeds = dto.SpecialNeeds,
- OtherNeeds = dto.OtherNeeds,
- Remark = dto.Remark,
- JietuanOperator = dto.JietuanOperator,
- TellPhone = dto.TellPhone,
- WeChatNo = dto.WeChatNo,
- CGRWSPBMMC = dto.CGRWSPBMMC,
- CGRWSPWH = dto.CGRWSPWH,
- ZZSCBMMC = dto.ZZSCBMMC,
- ZZSCSPWH = dto.ZZSCSPWH,
- TontractTime = string.IsNullOrEmpty(dto.TontractTime) ? null : Convert.ToDateTime(dto.TontractTime),
- IsBid = dto.IsBid,
- PaymentMoney = dto.PaymentMoney,
- PayDay = dto.PayDay,
- OpRoyaltyLv = dto.OpRoyaltyLv,
- OpRoyaltyRemark = dto.opRoyaltyRemark,
- Officialneeds = dto.Officialneeds,
- VisitStartDate = startTime,
- VisitEndDate = endTime,
- });
- if (updateStatus)
- {
- result.Code = 0;
- result.Msg = "修改成功!";
- }
- else
- {
- result.Msg = "修改失败!";
- }
- }
- else if (dto.Status == 3) //删除
- {
- var deleteStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
- {
- DeleteUserId = dto.UserId,
- DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
- IsDel = 1
- });
- if (deleteStatus)
- {
- result.Code = 0;
- result.Msg = "删除成功!";
- }
- else
- {
- result.Msg = "删除失败!";
- }
- }
- }
- return result;
- }
- /// <summary>
- /// 团组信息操作 - 删除
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- public async Task<Result> GroupDel(GroupDelDto dto)
- {
- Result result = new Result() { Code = -2, Msg = "未知错误" };
- if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
- {
- var deleteStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
- {
- DeleteUserId = dto.UserId,
- DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
- IsDel = 1
- });
- if (deleteStatus)
- {
- result.Code = 0;
- result.Msg = "删除成功!";
- }
- else
- {
- result.Msg = "删除失败!";
- }
- }
- return result;
- }
- /// <summary>
- /// 获取销售报价号
- /// </summary>
- /// <returns></returns>
- public async Task<Result> GetGroupSalesQuoteNo()
- {
- Result result = new Result() { Code = -2, Msg = "未知错误" };
- string teamCodeSql = string.Format("Select SalesQuoteNo From Grp_DelegationInfo");
- var teamCodeItem = await _sqlSugar.SqlQueryable<SalesQuoteNoView>(teamCodeSql).ToListAsync();
- string teamCode = "";
- while (true)
- {
- teamCode = Tools.CommonFun.GetRandomAllStr(6);
- if (!teamCodeItem.Equals(teamCode))
- {
- break;
- }
- }
- result.Code = 0;
- result.Msg = "成功!";
- result.Data = teamCode;
- return result;
- }
- /// <summary>
- /// 团组删除
- /// </summary>
- /// <returns></returns>
- public async Task<Result> GroupDeleteById()
- {
- Result result = new Result() { Code = -2, Msg = "未知错误" };
- string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
- var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
- string teamCode = "";
- while (true)
- {
- teamCode = Tools.CommonFun.GetRandomAllStr(6);
- if (!teamCodeItem.Equals(teamCode))
- {
- break;
- }
- }
- result.Code = 0;
- result.Msg = "成功!";
- result.Data = teamCode;
- return result;
- }
- /// <summary>
- /// 团组确认出团
- /// </summary>
- /// <returns></returns>
- public async Task<Result> ConfirmationGroup(ConfirmationGroupDto dto)
- {
- Result result = new Result() { Code = -2, Msg = "未知错误" };
- string teamCode = "";
- if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
- {
- string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
- var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
- while (true)
- {
- teamCode = Tools.CommonFun.GetRandomAllStr(6);
- if (!teamCodeItem.Equals(teamCode))
- {
- break;
- }
- }
- var deleteStatus = await UpdateAsync(a => a.Id == dto.GroupId, a => new Grp_DelegationInfo
- {
- TourCode = teamCode,
- GroupsOperator = dto.GroupsOperator,
- GroupsTime = DateTime.Now
- });
- if (deleteStatus)
- {
- result.Code = 0;
- result.Msg = "确认出团设置成功!";
- }
- else
- {
- result.Msg = "确认出团设置失败!";
- }
- }
- result.Code = 0;
- result.Msg = "成功!";
- result.Data = teamCode;
- return result;
- }
- /// <summary>
- /// 获取接团名称List
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- public async Task<Result> GetGroupNameList(GroupNameDto dto)
- {
- Result result = new Result() { Code = -2, Msg = "未知错误" };
- if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
- {
- string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
- Where TeamName != '' And IsDel = 0
- Order By Id Desc");
- var _groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
- if (_groupNameList.Count > 0)
- {
- for (int i = 0; i < _groupNameList.Count; i++)
- {
- var info = _groupNameList[i];
- _groupNameList[i].GroupName = FormartTeamName(info.GroupName);
- }
- result.Code = 0;
- result.Msg = "成功!";
- result.Data = _groupNameList;
- }
- else
- {
- result.Msg = "暂无团组信息";
- }
- }
- return result;
- }
- //PostGroupNameScreen
- /// <summary>
- /// 获取接团名称 Page List
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- public async Task<JsonView> GetGroupNameList(int portType,int pageIndex,int pageSize, string groupName,int userId)
- {
- var _res = new JsonView() { Code = 400 , Msg = MsgTips.Fail };
- string sql = "";
- string sqlWhere = "";
- string mobileSqlWhere = "";
- if (!string.IsNullOrEmpty(groupName))
- {
- sqlWhere += string.Format($@"And TeamName Like '%{groupName}%'");
- mobileSqlWhere += string.Format($@"GroupName Like '%{groupName}%'");
- }
- List<int> userIds = new List<int>() { -1, 21 };
- if (!userIds.Contains(userId))
- {
- sqlWhere += string.Format($@"And JietuanOperator = {userId}");
- }
- sql = string.Format($@"Select ROW_NUMBER()Over(Order By Id Desc) as RowNumber,Id,TeamName GroupName From Grp_DelegationInfo
- Where IsDel = 0 {sqlWhere}");
- if (portType == 1) //web
- { }
- else if (portType == 2 || portType == 3)
- {
- //国交部 7 (主管 22,经理 32)团操操作权限 市场部 6 接团人
- var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == userId && it.IsDel == 0).FirstAsync();
- if (userInfo != null)
- {
- if (userInfo.DepId == 7)
- {
- if (userInfo.JobPostId != 22 || userInfo.JobPostId != 32)
- {
- if (!string.IsNullOrEmpty(mobileSqlWhere)) mobileSqlWhere = $" Where {mobileSqlWhere}";
- sql = string.Format($@"Select
- ROW_NUMBER()Over(Order By Id Desc) as RowNumber,
- Id,
- GroupName
- From (
- Select
- distinct
- di.Id,
- di.TeamName GroupName
- From Grp_GroupsTaskAssignment gta With(NoLock)
- Inner Join Grp_DelegationInfo di With(NoLock) On gta.DIId = di.Id
- Where gta.IsDel = 0 And di.IsDel = 0 And gta.UId = {userId}
- ) Temp {mobileSqlWhere}");
- }
- }
- }
- }
- RefAsync<int> total = 0;
- var groupNamePageData = await _sqlSugar.SqlQueryable<GroupNamePageView>(sql).ToPageListAsync(pageIndex, pageSize, total);
- _res.Code = 200;
- _res.Data = groupNamePageData;
- _res.Msg = MsgTips.Succeed;
- _res.Count = total;
- return _res;
- }
- /// <summary>
- /// 获取接团名称List And 签证国别
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- public async Task<Result> GetGroupNameAndVisaNationality(GroupNameDto dto)
- {
- Result result = new Result() { Code = -2, Msg = "未知错误" };
- if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
- {
- string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
- Where TeamName != '' And IsDel = 0
- Order By Id Desc");
- var _groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
-
- string visaSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = 41 And IsDel = 0");
- var _setDataList = await _sqlSugar.SqlQueryable<SetDataInfoView>(visaSql).ToListAsync();
- var data = new {
- groupNameData = _groupNameList,
- visaNationalityData = _setDataList
- };
- result.Data = data;
- result.Code = 0;
- }
- return result;
- }
- #endregion
- #region 团组&签证
- /// <summary>
- /// 根据团组Id查询客户
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- public async Task<Result> GetCrmByGroupId(ClientByGroupIdDto dto)
- {
- Result result = new Result() { Code = -2 };
- if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3)
- {
- string sql = string.Format(@"Select gdjc.GrpDCId grpId,cdc.Id,cdc.LastName+cdc.FirstName clientName,cdc.Tel,ccc.CertNo CerdNo
- From Grp_DelegationJoinCustomer gdjc
- Inner join Crm_DeleClient cdc On gdjc.CrmDCId = cdc.Id
- Left Join Crm_CustomerCert ccc On ccc.SdId = 773 And cdc.Id = ccc.DcId
- Where gdjc.GrpDCId = {0}", dto.GroupId);
- var clientList = await _sqlSugar.SqlQueryable<CrmByGroupIdView>(sql).ToListAsync();
- if (clientList.Count > 0)
- {
- result.Code = 0;
- result.Msg = "成功!";
- result.Data = clientList;
- }
- else
- {
- result.Msg = "暂无数据!";
- }
- }
- return result;
- }
- #endregion
- #region 团组&出入境费用
- /// <summary>
- /// 获取单组名称并验证出入境费用明细是否填写
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- public async Task<Result> EnterExitCostGroupNameAsync()
- {
- var result = new Result() { Code = -2, Msg = "未知错误" };
- var groupSql = string.Format(@$"SELECT
- Id,
- TeamName GroupName,
- CASE
- WHEN (
- SELECT
- COUNT(*)
- FROM
- Grp_EnterExitCost
- WHERE
- IsDel = 0
- AND DiId = di.Id
- ) > 0 THEN 'false'
- ELSE 'true'
- END AS [IsNull]
- FROM
- Grp_DelegationInfo di
- WHERE
- di.Isdel = 0
- ORDER BY
- CreateTime Desc");
- result.Data = await _sqlSugar.SqlQueryable<EnterExitCostGroupNameView>(groupSql).ToListAsync();
- result.Code = 0;
- return result;
- }
- #endregion
- }
- }
|