InvertedListRepository.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. using AutoMapper;
  2. using MySqlX.XDevAPI.Common;
  3. using OASystem.Domain;
  4. using OASystem.Domain.Dtos.Groups;
  5. using OASystem.Domain.Entities.Groups;
  6. using OASystem.Domain.Entities.Resource;
  7. using OASystem.Domain.ViewModels.Groups;
  8. using SqlSugar;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using Result = OASystem.Domain.Result;
  15. namespace OASystem.Infrastructure.Repositories.Groups
  16. {
  17. /// <summary>
  18. /// 倒推表 仓储
  19. /// </summary>
  20. public class InvertedListRepository:BaseRepository<Grp_InvertedList,InvertedListView>
  21. {
  22. private readonly IMapper _mapper;
  23. private readonly Result _result;
  24. private readonly DelegationInfoRepository _delegationInfoRep;
  25. public InvertedListRepository(SqlSugarClient sqlSugar, IMapper mapper, DelegationInfoRepository delegationInfoRep)
  26. : base(sqlSugar)
  27. {
  28. _mapper = mapper;
  29. _result = new Result() { Code = -1, Msg = "系统错误!", Data = new List<object>() { } };
  30. _delegationInfoRep = delegationInfoRep;
  31. }
  32. /// <summary>
  33. /// 基础数据
  34. /// </summary>
  35. /// <returns></returns>
  36. public async Task<Result> Init()
  37. {
  38. dynamic groupData = null;
  39. var groupData1 = await _delegationInfoRep.PostShareGroupInfos(1);
  40. if (groupData1.Code == 0)
  41. {
  42. groupData = groupData1.Data;
  43. }
  44. var setData = await _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0).ToListAsync();
  45. var officialTypeData = setData.Where(it => it.STid == 81).Select(it => new { it.Id,it.Name }).ToList();
  46. var visaTypeData = setData.Where(it => it.STid == 82).Select(it => new { it.Id, it.Name }).ToList();
  47. _result.Code = 0;
  48. _result.Msg = "操作成功!";
  49. _result.Data = new {
  50. groupData = groupData,
  51. officialTypeData = officialTypeData,
  52. visaTypeData = visaTypeData
  53. };
  54. return _result;
  55. }
  56. /// <summary>
  57. /// Info
  58. /// </summary>
  59. /// <returns></returns>
  60. public async Task<Result> Info(int portTypeId,int diId)
  61. {
  62. #region 参数验证
  63. if (portTypeId < 1)
  64. {
  65. _result.Msg = "请输入有效的PortType参数值";
  66. return _result;
  67. }
  68. if (diId < 1)
  69. {
  70. _result.Msg = "请输入有效的DiId参数值";
  71. return _result;
  72. }
  73. #endregion
  74. string sql = string.Format(@$"Select * From Grp_InvertedList Where Isdel={0} And DiId = {diId}");
  75. var info = await _sqlSugar.SqlQueryable<InvertedListInfoView>(sql).FirstAsync();
  76. if (info == null) {
  77. info = new InvertedListInfoView();
  78. info.IsQuery = true;
  79. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == diId).FirstAsync();
  80. if (groupInfo == null)
  81. {
  82. _result.Msg = @$"团组数据不存在!";
  83. return _result;
  84. }
  85. List<string> visitCountry = new List<string>();
  86. string grpVisitCountry = groupInfo.VisitCountry;
  87. if (!string.IsNullOrEmpty(grpVisitCountry))
  88. {
  89. grpVisitCountry = _delegationInfoRep.FormartTeamName(grpVisitCountry);
  90. visitCountry = grpVisitCountry.Split("、").ToList();
  91. }
  92. string sqqzRemark = "";
  93. //签证费用标准
  94. var visaFeeDatas = await _sqlSugar.Queryable<Res_CountryFeeCost>().Where(it => it.IsDel == 0).ToListAsync();
  95. List<VisaCountryInfo> visaCountryInfos = new List<VisaCountryInfo>();
  96. string countryStr = "";
  97. string countryDesc = "";
  98. foreach (var item in visitCountry)
  99. {
  100. int visaDays = Convert.ToInt32(visaFeeDatas.Find(it => it.VisaCountry.Equals(item.Trim()))?.VisaTime ?? "0");
  101. visaCountryInfos.Add(new VisaCountryInfo()
  102. {
  103. Country = item,
  104. OfficialTypeId = -1,
  105. VisaTypeId = -1,
  106. VisaDay = visaDays
  107. });
  108. countryStr += $"{item}、";
  109. countryDesc += $"{item}签证{visaDays}个工作日,";
  110. }
  111. if (countryStr.Length > 0)
  112. {
  113. countryStr = countryStr.Substring(0, countryStr.Length - 1);
  114. }
  115. if (countryDesc.Length > 0)
  116. {
  117. countryDesc = countryDesc.Substring(0, countryDesc.Length - 1);
  118. }
  119. sqqzRemark = $"申请{countryStr}签证;{countryDesc}\r\n(签证周期仅供参考)";
  120. info.VisaCountryData = visaCountryInfos;
  121. info.SendVisaRemark = sqqzRemark;
  122. _result.Data = info;
  123. _result.Msg = "未查询到数据!";
  124. _result.Code = 0;
  125. return _result;
  126. }
  127. int ilId = info.Id;
  128. #region 新增客户时间字段值不存在使用默认值
  129. if (string.IsNullOrEmpty(info.Client_ApprovalDataDt)) info.Client_ApprovalDataDt = info.ApprovalDataDt;
  130. if (string.IsNullOrEmpty(info.Client_ApprovalDt)) info.Client_ApprovalDt = info.ApprovalDt;
  131. if (string.IsNullOrEmpty(info.Client_IssueApprovalDt)) info.Client_IssueApprovalDt = info.IssueApprovalDt;
  132. if (string.IsNullOrEmpty(info.Client_VisaInformationDt)) info.Client_VisaInformationDt = info.VisaInformationDt;
  133. if (string.IsNullOrEmpty(info.Client_SendVisaDt)) info.Client_SendVisaDt = info.SendVisaDt;
  134. if (string.IsNullOrEmpty(info.Client_IssueVisaDt)) info.Client_IssueVisaDt = info.IssueVisaDt;
  135. if (string.IsNullOrEmpty(info.Client_AirTicketDt)) info.Client_AirTicketDt = info.AirTicketDt;
  136. if (string.IsNullOrEmpty(info.Client_HotelDt)) info.Client_HotelDt = info.HotelDt;
  137. if (string.IsNullOrEmpty(info.Client_PreTripMeetingDt)) info.Client_PreTripMeetingDt = info.PreTripMeetingDt;
  138. if (string.IsNullOrEmpty(info.Client_AirportdDropOffDt)) info.Client_AirportdDropOffDt = info.AirportdDropOffDt;
  139. #endregion
  140. string visaSql = string.Format(@$"Select * From Grp_InvertedListVisaCountry Where Isdel={0} And ILId = {ilId}");
  141. var visaCountryInfo = await _sqlSugar.SqlQueryable<VisaCountryInfo>(visaSql).ToListAsync();
  142. info.VisaCountryData = visaCountryInfo;
  143. _result.Data = info;
  144. _result.Code = 0;
  145. return _result;
  146. }
  147. /// <summary>
  148. /// Create
  149. /// </summary>
  150. /// <param name="diId"></param>
  151. /// <returns></returns>
  152. public async Task<Result> Create(int userId,int diId,string remark = "")
  153. {
  154. #region 参数验证
  155. if (diId < 1)
  156. {
  157. _result.Msg = $@"请输入有效的DiId参数值!";
  158. return _result;
  159. }
  160. if (userId < 1)
  161. {
  162. _result.Msg = $@"请输入有效的UserId参数值!";
  163. return _result;
  164. }
  165. #endregion
  166. var selectInfo = await _sqlSugar.Queryable<Grp_InvertedList>().Where(it => it.IsDel == 0 && it.DiId == diId).FirstAsync();
  167. if (selectInfo != null)
  168. {
  169. _result.Msg = @$"该数据已存在,不可重复创建!";
  170. return _result;
  171. }
  172. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == diId).FirstAsync();
  173. if (groupInfo == null)
  174. {
  175. _result.Msg = @$"团组数据不存在,不可创建!";
  176. return _result;
  177. }
  178. if (string.IsNullOrEmpty(groupInfo.VisitDate.ToString()))
  179. {
  180. _result.Msg = @$"团组出访时间未填写,不可创建!";
  181. return _result;
  182. }
  183. DateTime visitDt = groupInfo.VisitDate;
  184. List<string> visitCountry = new List<string>();
  185. string grpVisitCountry = groupInfo.VisitCountry;
  186. if (!string.IsNullOrEmpty(grpVisitCountry))
  187. {
  188. grpVisitCountry = _delegationInfoRep.FormartTeamName(grpVisitCountry);
  189. visitCountry = grpVisitCountry.Split("、").ToList();
  190. }
  191. //签证费用标准
  192. var visaFeeDatas = await _sqlSugar.Queryable<Res_CountryFeeCost>().Where(it => it.IsDel == 0).ToListAsync();
  193. string sqqzRemark = "";
  194. List<VisaCountryInfo> visaCountryInfos = new List<VisaCountryInfo>();
  195. string countryStr = string.Empty,countryDesc = string.Empty;
  196. foreach (var item in visitCountry)
  197. {
  198. int visaDays = Convert.ToInt32(visaFeeDatas.Find(it => it.VisaCountry.Equals(item.Trim()))?.VisaTime ?? "0");
  199. visaCountryInfos.Add(new VisaCountryInfo()
  200. {
  201. Country = item,
  202. OfficialTypeId = -1,
  203. VisaTypeId = -1,
  204. VisaDay = visaDays
  205. });
  206. countryStr += $"{item}、";
  207. countryDesc += $"{item}签证{visaDays}个工作日,";
  208. }
  209. if (countryStr.Length > 0) countryStr = countryStr[..^1];
  210. if (countryDesc.Length > 0) countryDesc = countryDesc[..^1];
  211. sqqzRemark = $"申请{countryStr}签证;{countryDesc}\r\n(签证周期仅供参考)";
  212. /*
  213. * 默认步骤所需提前天数
  214. * A 自然日 B 工作日
  215. */
  216. int approvalData_advanceDays = -60, //报批资料准备
  217. approval_advanceDays = -45, //报批
  218. IssueApproval_advanceDays = -33, //出批件、办护照
  219. //ApplyPassport_advanceDays = -30, //办护照
  220. VisaInformation_advanceDays = -16, //签证资料准备
  221. sendVisa_advanceDays = -12, //送签
  222. issueVisa_advanceDays = -5, //出签
  223. preTripMeeting_advanceDays = -3, //行前会
  224. airportdDropOff_advanceDays = 0; //送机
  225. var info = new Grp_InvertedList() {
  226. DiId = diId,
  227. ApprovalDataDt = visitDt.AddDays(approvalData_advanceDays).ToString("yyyy-MM-dd"),
  228. Client_ApprovalDataDt = visitDt.AddDays(approvalData_advanceDays).ToString("yyyy-MM-dd"),
  229. ApprovalDt = visitDt.AddDays(approval_advanceDays).ToString("yyyy-MM-dd"),
  230. Client_ApprovalDt = visitDt.AddDays(approval_advanceDays).ToString("yyyy-MM-dd"),
  231. ApprovalType = -1,
  232. IssueApprovalDt = visitDt.AddDays(IssueApproval_advanceDays).ToString("yyyy-MM-dd"),
  233. Client_IssueApprovalDt = visitDt.AddDays(IssueApproval_advanceDays).ToString("yyyy-MM-dd"),
  234. //ApplyPassportDt = visitDt.AddDays(ApplyPassport_advanceDays).ToString("yyyy-MM-dd"),
  235. VisaInformationDt = visitDt.AddDays(VisaInformation_advanceDays).ToString("yyyy-MM-dd"),
  236. Client_VisaInformationDt = visitDt.AddDays(VisaInformation_advanceDays).ToString("yyyy-MM-dd"),
  237. SendVisaDt = visitDt.AddDays(sendVisa_advanceDays).ToString("yyyy-MM-dd"),
  238. Client_SendVisaDt = visitDt.AddDays(sendVisa_advanceDays).ToString("yyyy-MM-dd"),
  239. IssueVisaDt = visitDt.AddDays(issueVisa_advanceDays).ToString("yyyy-MM-dd"),
  240. Client_IssueVisaDt = visitDt.AddDays(issueVisa_advanceDays).ToString("yyyy-MM-dd"),
  241. AirTicketDt = visitDt.AddDays(issueVisa_advanceDays).ToString("yyyy-MM-dd"), //机票 应国交部要求默认使用出签时间
  242. Client_AirTicketDt = visitDt.AddDays(issueVisa_advanceDays).ToString("yyyy-MM-dd"), //机票 应国交部要求默认使用出签时间
  243. HotelDt = visitDt.AddDays(issueVisa_advanceDays).ToString("yyyy-MM-dd"), //酒店 应国交部要求默认使用出签时间
  244. Client_HotelDt = visitDt.AddDays(issueVisa_advanceDays).ToString("yyyy-MM-dd"), //酒店 应国交部要求默认使用出签时间
  245. PreTripMeetingDt = visitDt.AddDays(preTripMeeting_advanceDays).ToString("yyyy-MM-dd"),
  246. Client_PreTripMeetingDt = visitDt.AddDays(preTripMeeting_advanceDays).ToString("yyyy-MM-dd"),
  247. AirportdDropOffDt = visitDt.AddDays(airportdDropOff_advanceDays).ToString("yyyy-MM-dd"),
  248. Client_AirportdDropOffDt = visitDt.AddDays(airportdDropOff_advanceDays).ToString("yyyy-MM-dd"),
  249. CreateUserId = userId,
  250. Remark = remark
  251. };
  252. if (!string.IsNullOrEmpty(sqqzRemark)) info.SendVisaRemark = sqqzRemark;
  253. _sqlSugar.BeginTran();
  254. int add1 = await _sqlSugar.Insertable<Grp_InvertedList>(info).ExecuteReturnIdentityAsync();
  255. if (add1<1)
  256. {
  257. _result.Msg = $@"倒推表添加失败!";
  258. _sqlSugar.RollbackTran();
  259. return _result;
  260. }
  261. var invertedListVisaCountries = new List<Grp_InvertedListVisaCountry>();
  262. foreach (var item in visitCountry)
  263. {
  264. int days = Convert.ToInt32(visaFeeDatas.Find(x => x.VisaCountry.Equals(item.Trim()))?.VisaTime ?? "0");
  265. invertedListVisaCountries.Add(new Grp_InvertedListVisaCountry()
  266. {
  267. ILId = add1,
  268. Country = item,
  269. OfficialTypeId = -1,
  270. VisaTypeId = -1,
  271. VisaDay = days,
  272. });
  273. }
  274. int add2 = await _sqlSugar.Insertable<Grp_InvertedListVisaCountry>(invertedListVisaCountries).ExecuteReturnIdentityAsync();
  275. _sqlSugar.CommitTran();
  276. _result.Code = 0;
  277. _result.Msg = @$"操作成功!";
  278. return _result;
  279. }
  280. /// <summary>
  281. /// Update
  282. /// </summary>
  283. /// <param name="diId"></param>
  284. /// <returns></returns>
  285. public async Task<Result> Update(InvertedListUpdateDto dto)
  286. {
  287. #region 参数验证
  288. if (dto.DiId < 1)
  289. {
  290. _result.Msg = $@"请输入有效的DiId参数值!";
  291. return _result;
  292. }
  293. if (dto.Id < 1)
  294. {
  295. _result.Msg = $@"请输入有效的Id参数值!";
  296. return _result;
  297. }
  298. #endregion
  299. Grp_InvertedList _InvertedList = _mapper.Map<Grp_InvertedList>(dto);
  300. List<Grp_InvertedListVisaCountry> _InvertedListVisaCountries = new List<Grp_InvertedListVisaCountry>();
  301. if (dto.VisaCountryData.Count > 0)
  302. {
  303. _InvertedListVisaCountries = _mapper.Map<List<Grp_InvertedListVisaCountry>>(dto.VisaCountryData);
  304. }
  305. _sqlSugar.BeginTran();
  306. int update1 = await _sqlSugar.Updateable(_InvertedList)
  307. .IgnoreColumns(it => new { it.CreateTime,it.IsDel })
  308. .ExecuteCommandAsync();
  309. if (update1 < 1)
  310. {
  311. _sqlSugar.RollbackTran();
  312. _result.Msg = @$"修改失败!";
  313. return _result;
  314. }
  315. if (_InvertedListVisaCountries.Count > 0)
  316. {
  317. int update2 = await _sqlSugar.Updateable(_InvertedListVisaCountries)
  318. .IgnoreColumns(it => new { it.CreateTime, it.IsDel })
  319. .ExecuteCommandAsync();
  320. if (update2 < 1)
  321. {
  322. _sqlSugar.RollbackTran();
  323. _result.Msg = @$"修改失败!";
  324. return _result;
  325. }
  326. }
  327. _sqlSugar.CommitTran();
  328. _result.Code = 0;
  329. _result.Msg = @$"操作成功!";
  330. return _result;
  331. }
  332. }
  333. }