InvertedListRepository.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. string visaSql = string.Format(@$"Select * From Grp_InvertedListVisaCountry Where Isdel={0} And ILId = {ilId}");
  129. var visaCountryInfo = await _sqlSugar.SqlQueryable<VisaCountryInfo>(visaSql).ToListAsync();
  130. info.VisaCountryData = visaCountryInfo;
  131. _result.Data = info;
  132. _result.Code = 0;
  133. return _result;
  134. }
  135. /// <summary>
  136. /// Create
  137. /// </summary>
  138. /// <param name="diId"></param>
  139. /// <returns></returns>
  140. public async Task<Result> _Create(int userId,int diId)
  141. {
  142. #region 参数验证
  143. if (diId < 1)
  144. {
  145. _result.Msg = $@"请输入有效的DiId参数值!";
  146. return _result;
  147. }
  148. if (userId < 1)
  149. {
  150. _result.Msg = $@"请输入有效的UserId参数值!";
  151. return _result;
  152. }
  153. #endregion
  154. var selectInfo = await _sqlSugar.Queryable<Grp_InvertedList>().Where(it => it.IsDel == 0 && it.DiId == diId).FirstAsync();
  155. if (selectInfo != null)
  156. {
  157. _result.Msg = @$"该数据已存在,不可重复创建!";
  158. return _result;
  159. }
  160. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == diId).FirstAsync();
  161. if (groupInfo == null)
  162. {
  163. _result.Msg = @$"团组数据不存在,不可创建!";
  164. return _result;
  165. }
  166. if (string.IsNullOrEmpty( groupInfo.VisitDate.ToString()))
  167. {
  168. _result.Msg = @$"团组出访时间未填写,不可创建!";
  169. return _result;
  170. }
  171. DateTime visitDt = groupInfo.VisitDate;
  172. List<string> visitCountry = new List<string>();
  173. string grpVisitCountry = groupInfo.VisitCountry;
  174. if (!string.IsNullOrEmpty(grpVisitCountry))
  175. {
  176. grpVisitCountry = _delegationInfoRep.FormartTeamName(grpVisitCountry);
  177. visitCountry = grpVisitCountry.Split("、").ToList();
  178. }
  179. //签证费用标准
  180. var visaFeeDatas = await _sqlSugar.Queryable<Res_CountryFeeCost>().Where(it => it.IsDel == 0).ToListAsync();
  181. string sqqzRemark = "";
  182. List<VisaCountryInfo> visaCountryInfos = new List<VisaCountryInfo>();
  183. string countryStr = "";
  184. string countryDesc = "";
  185. foreach (var item in visitCountry)
  186. {
  187. int visaDays = Convert.ToInt32(visaFeeDatas.Find(it => it.VisaCountry.Equals(item.Trim()))?.VisaTime ?? "0");
  188. visaCountryInfos.Add(new VisaCountryInfo()
  189. {
  190. Country = item,
  191. OfficialTypeId = -1,
  192. VisaTypeId = -1,
  193. VisaDay = visaDays
  194. });
  195. countryStr += $"{item}、";
  196. countryDesc += $"{item}签证{visaDays}个工作日,";
  197. }
  198. if (countryStr.Length > 0)
  199. {
  200. countryStr = countryStr.Substring(0, countryStr.Length - 1);
  201. }
  202. if (countryDesc.Length > 0)
  203. {
  204. countryDesc = countryDesc.Substring(0, countryDesc.Length - 1);
  205. }
  206. sqqzRemark = $"申请{countryStr}签证;{countryDesc}\r\n(签证周期仅供参考)";
  207. /*
  208. * 默认步骤所需提前天数
  209. * A 自然日 B 工作日
  210. */
  211. int approvalData_advanceDays = -60, //报批资料准备
  212. approval_advanceDays = -45, //报批
  213. IssueApproval_advanceDays = -33, //出批件、办护照
  214. //ApplyPassport_advanceDays = -30, //办护照
  215. VisaInformation_advanceDays = -16, //签证资料准备
  216. sendVisa_advanceDays = -12, //送签
  217. issueVisa_advanceDays = -5, //出签
  218. preTripMeeting_advanceDays = -3, //行前会
  219. airportdDropOff_advanceDays = 0; //送机
  220. var info = new Grp_InvertedList() {
  221. DiId = diId,
  222. ApprovalDataDt = visitDt.AddDays(approvalData_advanceDays).ToString("yyyy-MM-dd"),
  223. ApprovalDt = visitDt.AddDays(approval_advanceDays).ToString("yyyy-MM-dd"),
  224. ApprovalType = -1,
  225. IssueApprovalDt = visitDt.AddDays(IssueApproval_advanceDays).ToString("yyyy-MM-dd"),
  226. //ApplyPassportDt = visitDt.AddDays(ApplyPassport_advanceDays).ToString("yyyy-MM-dd"),
  227. VisaInformationDt = visitDt.AddDays(VisaInformation_advanceDays).ToString("yyyy-MM-dd"),
  228. SendVisaDt = visitDt.AddDays(sendVisa_advanceDays).ToString("yyyy-MM-dd"),
  229. IssueVisaDt = visitDt.AddDays(issueVisa_advanceDays).ToString("yyyy-MM-dd"),
  230. PreTripMeetingDt = visitDt.AddDays(preTripMeeting_advanceDays).ToString("yyyy-MM-dd"),
  231. AirportdDropOffDt = visitDt.AddDays(airportdDropOff_advanceDays).ToString("yyyy-MM-dd"),
  232. CreateUserId = userId,
  233. };
  234. if (!string.IsNullOrEmpty(sqqzRemark)) info.SendVisaRemark = sqqzRemark;
  235. _sqlSugar.BeginTran();
  236. int add1 = await _sqlSugar.Insertable<Grp_InvertedList>(info).ExecuteReturnIdentityAsync();
  237. if (add1<1)
  238. {
  239. _result.Msg = $@"倒推表添加失败!";
  240. _sqlSugar.RollbackTran();
  241. return _result;
  242. }
  243. List<Grp_InvertedListVisaCountry> _InvertedListVisaCountries = new List<Grp_InvertedListVisaCountry>();
  244. foreach (var item in visitCountry)
  245. {
  246. int days = Convert.ToInt32(visaFeeDatas.Find(x => x.VisaCountry.Equals(item.Trim()))?.VisaTime ?? "0");
  247. _InvertedListVisaCountries.Add(new Grp_InvertedListVisaCountry()
  248. {
  249. ILId = add1,
  250. Country = item,
  251. OfficialTypeId = -1,
  252. VisaTypeId = -1,
  253. VisaDay = days,
  254. });
  255. }
  256. int add2 = await _sqlSugar.Insertable<Grp_InvertedListVisaCountry>(_InvertedListVisaCountries).ExecuteReturnIdentityAsync();
  257. _sqlSugar.CommitTran();
  258. _result.Code = 0;
  259. _result.Msg = @$"操作成功!";
  260. return _result;
  261. }
  262. /// <summary>
  263. /// Update
  264. /// </summary>
  265. /// <param name="diId"></param>
  266. /// <returns></returns>
  267. public async Task<Result> _Update(InvertedListUpdateDto dto)
  268. {
  269. #region 参数验证
  270. if (dto.DiId < 1)
  271. {
  272. _result.Msg = $@"请输入有效的DiId参数值!";
  273. return _result;
  274. }
  275. if (dto.Id < 1)
  276. {
  277. _result.Msg = $@"请输入有效的Id参数值!";
  278. return _result;
  279. }
  280. #endregion
  281. Grp_InvertedList _InvertedList = _mapper.Map<Grp_InvertedList>(dto);
  282. List<Grp_InvertedListVisaCountry> _InvertedListVisaCountries = new List<Grp_InvertedListVisaCountry>();
  283. if (dto.VisaCountryData.Count > 0)
  284. {
  285. _InvertedListVisaCountries = _mapper.Map<List<Grp_InvertedListVisaCountry>>(dto.VisaCountryData);
  286. }
  287. _sqlSugar.BeginTran();
  288. int update1 = await _sqlSugar.Updateable(_InvertedList)
  289. .IgnoreColumns(it => new { it.CreateTime,it.IsDel })
  290. .ExecuteCommandAsync();
  291. if (update1 < 1)
  292. {
  293. _sqlSugar.RollbackTran();
  294. _result.Msg = @$"修改失败!";
  295. return _result;
  296. }
  297. if (_InvertedListVisaCountries.Count > 0)
  298. {
  299. int update2 = await _sqlSugar.Updateable(_InvertedListVisaCountries)
  300. .IgnoreColumns(it => new { it.CreateTime, it.IsDel })
  301. .ExecuteCommandAsync();
  302. if (update2 < 1)
  303. {
  304. _sqlSugar.RollbackTran();
  305. _result.Msg = @$"修改失败!";
  306. return _result;
  307. }
  308. }
  309. _sqlSugar.CommitTran();
  310. _result.Code = 0;
  311. _result.Msg = @$"操作成功!";
  312. return _result;
  313. }
  314. }
  315. }