GroupsController.cs 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488
  1. using Aspose.Cells;
  2. using Aspose.Cells.Drawing.Texts;
  3. using Aspose.Words;
  4. using Aspose.Words.Tables;
  5. using NPOI.Util;
  6. using OASystem.API.OAMethodLib;
  7. using OASystem.API.OAMethodLib.File;
  8. using OASystem.Domain.Dtos.Groups;
  9. using OASystem.Domain.Entities.Groups;
  10. using OASystem.Domain.ViewModels.Groups;
  11. using OASystem.Infrastructure.Repositories.Groups;
  12. using System.Data;
  13. using static OASystem.Infrastructure.Repositories.Resource.AirTicketResRepository;
  14. using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
  15. using Cell = Aspose.Words.Tables.Cell;
  16. using Row = Aspose.Words.Tables.Row;
  17. namespace OASystem.API.Controllers
  18. {
  19. /// <summary>
  20. /// 团组相关
  21. /// </summary>
  22. //[Authorize]
  23. [Route("api/[controller]/[action]")]
  24. public class GroupsController : ControllerBase
  25. {
  26. private readonly GrpScheduleRepository _grpScheduleRep;
  27. private readonly IMapper _mapper;
  28. private readonly DelegationInfoRepository _groupRepository;
  29. private readonly TaskAssignmentRepository _taskAssignmentRep;
  30. private readonly AirTicketResRepository _airTicketResRep;
  31. private readonly SqlSugarClient _sqlSugar;
  32. private string url;
  33. private string path;
  34. public GroupsController(IMapper mapper,SqlSugarClient sqlSugar, GrpScheduleRepository grpScheduleRep, DelegationInfoRepository groupRepository, TaskAssignmentRepository taskAssignmentRep, AirTicketResRepository airTicketResRep)
  35. {
  36. _mapper = mapper;
  37. _grpScheduleRep = grpScheduleRep;
  38. _groupRepository = groupRepository;
  39. _taskAssignmentRep = taskAssignmentRep;
  40. _airTicketResRep = airTicketResRep;
  41. _sqlSugar = sqlSugar;
  42. url = AppSettingsHelper.Get("ExcelBaseUrl");
  43. path = AppSettingsHelper.Get("ExcelBasePath");
  44. if (!System.IO.Directory.Exists(path))
  45. {
  46. System.IO.Directory.CreateDirectory(path);//不存在就创建文件夹
  47. }
  48. }
  49. #region 流程管控
  50. /// <summary>
  51. /// 获取团组流程管控信息
  52. /// </summary>
  53. /// <param name="paras">参数Json字符串</param>
  54. /// <returns></returns>
  55. [HttpPost]
  56. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  57. public async Task<IActionResult> PostSearchGrpSchedule(JsonDtoBase _jsonDto)
  58. {
  59. if (string.IsNullOrEmpty(_jsonDto.Paras))
  60. {
  61. return Ok(JsonView(false, "参数为空"));
  62. }
  63. Grp_ScheduleDto _ScheduleDto = JsonConvert.DeserializeObject<Grp_ScheduleDto>(_jsonDto.Paras);
  64. if (_ScheduleDto != null)
  65. {
  66. if (_ScheduleDto.SearchType == 2)//获取列表
  67. {
  68. List<Grp_ScheduleView> _grpScheduleViewList = await _grpScheduleRep.GetViewList_GrpSchedule(_ScheduleDto);
  69. return Ok(JsonView(_grpScheduleViewList));
  70. }
  71. else//获取对象
  72. {
  73. Grp_ScheduleCombinView _grpScheduleView = await _grpScheduleRep.GetView_GrpSchedule(_ScheduleDto);
  74. if (_grpScheduleView != null)
  75. {
  76. return Ok(JsonView(_grpScheduleView));
  77. }
  78. }
  79. }
  80. else
  81. {
  82. return Ok(JsonView(false, "参数反序列化失败"));
  83. }
  84. return Ok(JsonView(false, "暂无数据!"));
  85. }
  86. /// <summary>
  87. /// 修改团组流程管控详细表数据
  88. /// </summary>
  89. /// <param name="paras"></param>
  90. /// <returns></returns>
  91. [HttpPost]
  92. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  93. public async Task<IActionResult> PostUpdateGrpScheduleDetail(Grp_ScheduleDetailUpdDto dto)
  94. {
  95. Grp_ScheduleDetailInfo _detail = _mapper.Map<Grp_ScheduleDetailInfo>(dto);
  96. var result = await _grpScheduleRep._sqlSugar.Updateable<Grp_ScheduleDetailInfo>()
  97. .SetColumns(it => it.Duty == _detail.Duty)
  98. .SetColumns(it => it.ExpectBeginDt == _detail.ExpectBeginDt)
  99. .SetColumns(it => it.ExpectEndDt == _detail.ExpectEndDt)
  100. .SetColumns(it => it.JobContent == _detail.JobContent)
  101. .SetColumns(it => it.Remark == _detail.Remark)
  102. .SetColumns(it => it.StepStatus == _detail.StepStatus)
  103. .Where(s => s.Id == dto.Id)
  104. //.UpdateColumns(s => new { s.Duty, s.ExpectBeginDt, s.ExpectEndDt, s.JobContent, s.Remark, s.StepStatus })
  105. .ExecuteCommandAsync();
  106. if (result > 0)
  107. {
  108. return Ok(JsonView(true, "保存成功!"));
  109. }
  110. return Ok(JsonView(false, "保存失败!"));
  111. }
  112. /// <summary>
  113. /// 删除团组流程管控详细表数据,删除人Id请放在Duty
  114. /// </summary>
  115. /// <param name="dto"></param>
  116. /// <returns></returns>
  117. [HttpPost]
  118. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  119. public async Task<ActionResult> PostDeleteGrpScheduleDetail(Grp_ScheduleDetailUpdDto dto)
  120. {
  121. Grp_ScheduleDetailInfo _detail = _mapper.Map<Grp_ScheduleDetailInfo>(dto);
  122. _detail.IsDel = 1;
  123. _detail.DeleteUserId = dto.Duty;
  124. _detail.DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  125. var result = await _grpScheduleRep._sqlSugar.Updateable<Grp_ScheduleDetailInfo>()
  126. .SetColumns(it => it.IsDel == _detail.IsDel)
  127. .SetColumns(it => it.DeleteUserId == _detail.DeleteUserId)
  128. .SetColumns(it => it.DeleteTime == _detail.DeleteTime)
  129. .Where(it => it.Id == dto.Id)
  130. //.UpdateColumns(s => new { s.IsDel, s.DeleteUserId, s.DeleteTime })
  131. //.WhereColumns(s => s.Id == dto.Id)
  132. .ExecuteCommandAsync();
  133. if (result > 0)
  134. {
  135. return Ok(JsonView(true, "删除成功!"));
  136. }
  137. return Ok(JsonView(false, "删除失败!"));
  138. }
  139. /// <summary>
  140. /// 增加团组流程管控详细表数据
  141. /// </summary>
  142. /// <param name="dto"></param>
  143. /// <returns></returns>
  144. [HttpPost]
  145. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  146. public async Task<ActionResult> PostInsertGrpScheduleDetail(Grp_ScheduleDetailInsertDto dto)
  147. {
  148. Grp_ScheduleDetailInfo _detail = _mapper.Map<Grp_ScheduleDetailInfo>(dto);
  149. if (DateTime.Now < _detail.ExpectBeginDt)
  150. {
  151. _detail.StepStatus = 0;
  152. }
  153. else
  154. {//若大于设置时间,不考虑设置的预计结束日期,统一视为进行中
  155. _detail.StepStatus = 1;
  156. }
  157. var result = await _grpScheduleRep._sqlSugar.Insertable(_detail).ExecuteReturnIdentityAsync();
  158. if (result > 0)
  159. {
  160. Grp_ScheduleDetailView _result = await _grpScheduleRep.GetInsertBackData(result);
  161. return Ok(JsonView(true, "添加成功!", _result));
  162. }
  163. return Ok(JsonView(false, "添加失败!"));
  164. }
  165. #endregion
  166. #region 团组基本信息
  167. /// <summary>
  168. /// 接团信息列表
  169. /// </summary>
  170. /// <param name="dto">团组列表请求dto</param>
  171. /// <returns></returns>
  172. [HttpPost]
  173. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  174. public async Task<IActionResult> GetGroupList(GroupListDto dto)
  175. {
  176. var groupData = await _groupRepository.GetGroupList(dto);
  177. if (groupData.Code != 0)
  178. {
  179. return Ok(JsonView(false, groupData.Msg));
  180. }
  181. return Ok(JsonView(groupData.Data));
  182. }
  183. /// <summary>
  184. /// 接团信息详情
  185. /// </summary>
  186. /// <param name="dto">团组info请求dto</param>
  187. /// <returns></returns>
  188. [HttpPost]
  189. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  190. public async Task<IActionResult> GetGroupInfo(GroupInfoDto dto)
  191. {
  192. var groupData = await _groupRepository.GetGroupInfo(dto);
  193. if (groupData.Code != 0)
  194. {
  195. return Ok(JsonView(false, groupData.Msg));
  196. }
  197. return Ok(JsonView(groupData.Data));
  198. }
  199. /// <summary>
  200. /// 接团信息 编辑添加
  201. /// 基础信息数据源
  202. /// </summary>
  203. /// <param name="dto"></param>
  204. /// <returns></returns>
  205. [HttpPost]
  206. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  207. public async Task<IActionResult> GroupEditBasicSource(GroupListDto dto)
  208. {
  209. var groupData = await _groupRepository.GroupEditBasicSource(dto);
  210. if (groupData.Code != 0)
  211. {
  212. return Ok(JsonView(false, groupData.Msg));
  213. }
  214. return Ok(JsonView(groupData.Data));
  215. }
  216. /// <summary>
  217. /// 接团信息 操作(增改)
  218. /// </summary>
  219. /// <param name="dto"></param>
  220. /// <returns></returns>
  221. [HttpPost]
  222. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  223. public async Task<IActionResult> GroupOperation(GroupOperationDto dto)
  224. {
  225. try
  226. {
  227. var groupData = await _groupRepository.GroupOperation(dto);
  228. if (groupData.Code != 0)
  229. {
  230. return Ok(JsonView(false, groupData.Msg));
  231. }
  232. return Ok(JsonView(true));
  233. }
  234. catch (Exception ex)
  235. {
  236. Logs("[response]" + JsonConvert.SerializeObject(dto));
  237. Logs(ex.Message);
  238. return Ok(JsonView(false, ex.Message));
  239. }
  240. }
  241. /// <summary>
  242. /// 接团信息 操作(删除)
  243. /// </summary>
  244. /// <param name="dto"></param>
  245. /// <returns></returns>
  246. [HttpPost]
  247. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  248. public async Task<IActionResult> GroupDel(GroupDelDto dto)
  249. {
  250. try
  251. {
  252. var groupData = await _groupRepository.GroupDel(dto);
  253. if (groupData.Code != 0)
  254. {
  255. return Ok(JsonView(false, groupData.Msg));
  256. }
  257. return Ok(JsonView(true));
  258. }
  259. catch (Exception ex)
  260. {
  261. Logs("[response]" + JsonConvert.SerializeObject(dto));
  262. Logs(ex.Message);
  263. return Ok(JsonView(false, ex.Message));
  264. }
  265. }
  266. /// <summary>
  267. /// 获取团组销售报价号
  268. /// 团组添加时 使用
  269. /// </summary>
  270. /// <returns></returns>
  271. [HttpPost]
  272. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  273. public async Task<IActionResult> GetGroupSalesQuoteNo()
  274. {
  275. var groupData = await _groupRepository.GetGroupSalesQuoteNo();
  276. if (groupData.Code != 0)
  277. {
  278. return Ok(JsonView(false, groupData.Msg));
  279. }
  280. object salesQuoteNo = new
  281. {
  282. SalesQuoteNo = groupData.Data
  283. };
  284. return Ok(JsonView(salesQuoteNo));
  285. }
  286. /// <summary>
  287. /// 设置确认出团
  288. /// </summary>
  289. /// <param name="dto"></param>
  290. /// <returns></returns>
  291. [HttpPost]
  292. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  293. public async Task<IActionResult> SetConfirmationGroup(ConfirmationGroupDto dto)
  294. {
  295. var groupData = await _groupRepository.ConfirmationGroup(dto);
  296. if (groupData.Code != 0)
  297. {
  298. return Ok(JsonView(false, groupData.Msg));
  299. }
  300. GroupStepForDelegation.CreateWorkStep(dto.GroupId); //创建管控流程
  301. return Ok(JsonView(groupData.Data));
  302. }
  303. /// <summary>
  304. /// 获取团组名称 List
  305. /// </summary>
  306. /// <param name="dto"></param>
  307. /// <returns></returns>
  308. [HttpPost]
  309. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  310. public async Task<IActionResult> GetGroupNameList(GroupNameDto dto)
  311. {
  312. var groupData = await _groupRepository.GetGroupNameList(dto);
  313. if (groupData.Code != 0)
  314. {
  315. return Ok(JsonView(false, groupData.Msg));
  316. }
  317. return Ok(JsonView(groupData.Data, groupData.Data.Count));
  318. }
  319. /// <summary>
  320. /// 获取团组名称data And 签证国别Data
  321. /// </summary>
  322. /// <param name="dto"></param>
  323. /// <returns></returns>
  324. [HttpPost]
  325. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  326. public async Task<IActionResult> GetGroupNameAndVisaNationality(GroupNameDto dto)
  327. {
  328. var groupData = await _groupRepository.GetGroupNameAndVisaNationality(dto);
  329. if (groupData.Code != 0)
  330. {
  331. return Ok(JsonView(false, groupData.Msg));
  332. }
  333. return Ok(JsonView(groupData.Data));
  334. }
  335. #endregion
  336. #region 团组&签证
  337. /// <summary>
  338. /// 根据团组Id获取签证客户信息List
  339. /// </summary>
  340. /// <param name="dto">请求dto</param>
  341. /// <returns></returns>
  342. [HttpPost]
  343. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  344. public async Task<IActionResult> GetCrmByGroupId(ClientByGroupIdDto dto)
  345. {
  346. var groupData = await _groupRepository.GetCrmByGroupId(dto);
  347. if (groupData.Code != 0)
  348. {
  349. return Ok(JsonView(false, groupData.Msg));
  350. }
  351. return Ok(JsonView(groupData.Data));
  352. }
  353. #endregion
  354. #region 团组任务分配
  355. /// <summary>
  356. /// 团组任务分配初始化
  357. /// </summary>
  358. /// <param name="dto"></param>
  359. /// <returns></returns>
  360. [HttpPost]
  361. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  362. public async Task<IActionResult> GetTaskAssignmen()
  363. {
  364. var groupData = await _taskAssignmentRep.GetTaskAssignmen();
  365. if (groupData.Code != 0)
  366. {
  367. return Ok(JsonView(false, groupData.Msg));
  368. }
  369. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  370. }
  371. /// <summary>
  372. /// 团组任务分配查询
  373. /// </summary>
  374. /// <param name="dto"></param>
  375. /// <returns></returns>
  376. [HttpPost]
  377. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  378. public async Task<IActionResult> TaskAssignmenQuery(TaskAssignmenQueryDto dto)
  379. {
  380. var groupData = await _taskAssignmentRep.TaskAssignmenQuery(dto);
  381. if (groupData.Code != 0)
  382. {
  383. return Ok(JsonView(false, groupData.Msg));
  384. }
  385. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  386. }
  387. /// <summary>
  388. /// 团组任务分配操作
  389. /// </summary>
  390. /// <param name="dto"></param>
  391. /// <returns></returns>
  392. [HttpPost]
  393. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  394. public async Task<IActionResult> GetTaskAssignmenOp(TaskAssignmenDto dto)
  395. {
  396. Result groupData = await _taskAssignmentRep.GetTaskAssignmenOp(dto);
  397. if (groupData.Code != 0)
  398. {
  399. return Ok(JsonView(false, groupData.Msg));
  400. }
  401. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  402. }
  403. #endregion
  404. #region 团组费用审核
  405. /// <summary>
  406. /// 获取团组费用审核
  407. /// </summary>
  408. /// <param name="paras">参数Json字符串</param>
  409. /// <returns></returns>
  410. [HttpPost]
  411. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  412. public async Task<IActionResult> PostSearchGrpCreditCardPayment(Search_GrpCreditCardPaymentDto _dto)
  413. {
  414. if (_dto.DiId < 1)
  415. {
  416. return Ok(JsonView(false, "团组Id为空"));
  417. }
  418. Grp_CreditCardPaymentView _view = new Grp_CreditCardPaymentView();
  419. #region 团组基本信息
  420. Grp_DelegationInfo _delegation = _groupRepository.Query<Grp_DelegationInfo>(s => s.Id == _dto.DiId).First();
  421. if (_delegation != null)
  422. {
  423. _view.ClientName = _delegation.ClientName;
  424. _view.DiId = _dto.DiId;
  425. _view.TeamName = _delegation.TeamName;
  426. _view.VisitCountry = _delegation.VisitCountry;
  427. _view.VisitDate = _delegation.VisitStartDate.ToString("yyyy-MM-dd") + " ~ " + _delegation.VisitEndDate.ToString("yyyy-MM-dd");
  428. _view.VisitDays = _delegation.VisitDays;
  429. _view.VisitPNumber = _delegation.VisitPNumber;
  430. }
  431. else
  432. {
  433. return Ok(JsonView(false, "团组信息为空"));
  434. }
  435. #endregion
  436. #region 费用清单
  437. var exp = Expressionable.Create<Grp_CreditCardPayment>();
  438. exp.AndIF(_dto.AuditStatus != -1, it => it.IsAuditGM == _dto.AuditStatus);
  439. exp.AndIF(_dto.Label != -1, it => it.CTable == _dto.Label);
  440. //缺少IF的语法糖 CTable
  441. List<Grp_CreditCardPayment> entityList = _groupRepository
  442. .Query<Grp_CreditCardPayment>(s => s.DIId == _dto.DiId && s.IsDel == 0 && s.CreateUserId > 0)
  443. .Where(exp.ToExpression())
  444. .ToList();
  445. List<Grp_CreditCardPaymentDetailView> detailList = new List<Grp_CreditCardPaymentDetailView>();
  446. decimal CNY = 0;
  447. decimal PayCNY = 0;
  448. decimal BalanceCNY = 0;
  449. decimal YSFYCNY = 0;
  450. decimal USD = 0;
  451. decimal PayUSD = 0;
  452. decimal BalanceUSD = 0;
  453. decimal YSFYUSD = 0;
  454. decimal EUR = 0;
  455. decimal PayEUR = 0;
  456. decimal BalanceEUR = 0;
  457. decimal YSFYEUR = 0;
  458. foreach (var entity in entityList)
  459. {
  460. Grp_CreditCardPaymentDetailView _detail = new Grp_CreditCardPaymentDetailView();
  461. _detail.Id = entity.Id;
  462. /*
  463. * Bus名称
  464. */
  465. _detail.BusName = "";
  466. /*
  467. *费用所属
  468. */
  469. switch (entity.CTable)
  470. {
  471. case 85:
  472. Grp_AirTicketReservations jpRes = _groupRepository.Query<Grp_AirTicketReservations>(s => s.Id == entity.CId).First();
  473. if (jpRes != null)
  474. {
  475. string FlightsDescription = jpRes.FlightsDescription;
  476. string PriceDescription = jpRes.PriceDescription;
  477. _detail.PriceMsgContent = "航班号:" + jpRes.FlightsCode + "<br/>城市A-B:" + jpRes.FlightsCity + "<br/>航班描述:" + FlightsDescription.Replace("\r\n", "<br />") + "<br/>" + "价格描述:" + PriceDescription;
  478. _detail.PriceNameContent = "(" + jpRes.FlightsCode + ")";
  479. }
  480. break;
  481. case 79:
  482. _detail.BusName = "待增加";
  483. break;
  484. default:
  485. break;
  486. }
  487. /*
  488. * 费用模块
  489. */
  490. Sys_SetData sdPriceName = _groupRepository.Query<Sys_SetData>(s => s.Id == entity.CTable).First();
  491. if (sdPriceName != null)
  492. {
  493. _detail.PriceName = sdPriceName.Name;
  494. }
  495. /*
  496. * 应付款金额
  497. */
  498. Sys_SetData sdPaymentCurrency_WaitPay = _groupRepository.Query<Sys_SetData>(s => s.Id == entity.PaymentCurrency).First();
  499. string PaymentCurrency_WaitPay = "Unknown";
  500. if (sdPaymentCurrency_WaitPay != null)
  501. {
  502. PaymentCurrency_WaitPay = sdPaymentCurrency_WaitPay.Name;
  503. }
  504. _detail.WaitPay = entity.PayMoney.ToString("#0.00") + " " + PaymentCurrency_WaitPay;
  505. /*
  506. * 此次付款金额
  507. */
  508. decimal CurrPayStr = 0;
  509. if (entity.PayPercentage == 0)
  510. {
  511. if (entity.PayThenMoney != 0)
  512. CurrPayStr = entity.PayThenMoney * decimal.Parse(entity.DayRate);
  513. }
  514. else
  515. {
  516. CurrPayStr = entity.PayMoney * (decimal.Parse(entity.PayPercentage.ToString("#0.00")) / 100 * decimal.Parse(entity.DayRate));
  517. }
  518. _detail.CurrPay = CurrPayStr.ToString("#0.00") + " CNY";
  519. /*
  520. * 剩余尾款
  521. */
  522. decimal BalanceStr = 0;
  523. if (entity.PayMoney - (CurrPayStr / decimal.Parse(entity.DayRate)) < 0.01M)
  524. BalanceStr = 0;
  525. else
  526. BalanceStr = (entity.PayMoney - CurrPayStr / decimal.Parse(entity.DayRate));
  527. _detail.Balance = BalanceStr.ToString("#0.00") + " " + PaymentCurrency_WaitPay;
  528. /*
  529. * 申请人
  530. */
  531. string operatorName = "无";
  532. Sys_Users _opUser = _groupRepository.Query<Sys_Users>(s => s.Id == entity.CreateUserId).First();
  533. if (_opUser != null)
  534. {
  535. operatorName = _opUser.CnName;
  536. }
  537. _detail.OperatorName = operatorName;
  538. /*
  539. * 审核人
  540. */
  541. string auditOperatorName = "Unknown";
  542. if (entity.AuditGMOperate == 0)
  543. auditOperatorName = "无";
  544. else if (entity.AuditGMOperate == 4)
  545. auditOperatorName = "自动审核";
  546. else
  547. {
  548. Sys_Users _adUser = _groupRepository.Query<Sys_Users>(s => s.Id == entity.AuditGMOperate).First();
  549. if (_adUser != null)
  550. {
  551. auditOperatorName = _adUser.CnName;
  552. }
  553. }
  554. _detail.AuditOperatorName = auditOperatorName;
  555. /*
  556. *
  557. * *超预算比例
  558. */
  559. string overBudgetStr = "";
  560. if (entity.ExceedBudget == -1)
  561. overBudgetStr = sdPriceName.Name + "尚无预算";
  562. else if (entity.ExceedBudget == 0)
  563. overBudgetStr = "未超预算";
  564. else
  565. overBudgetStr = entity.ExceedBudget.ToString("P");
  566. _detail.OverBudget = overBudgetStr;
  567. /*
  568. * 费用总计
  569. */
  570. if (entity.PaymentCurrency == 48)
  571. {
  572. CNY += entity.PayMoney;
  573. PayCNY += CurrPayStr;
  574. BalanceCNY += BalanceStr;
  575. YSFYCNY += CurrPayStr;
  576. }
  577. if (entity.PaymentCurrency == 49)
  578. {
  579. USD += entity.PayMoney;
  580. PayUSD += CurrPayStr;
  581. BalanceUSD += BalanceStr;
  582. YSFYUSD += CurrPayStr;
  583. }
  584. if (entity.PaymentCurrency == 51)
  585. {
  586. EUR += entity.PayMoney;
  587. PayEUR += CurrPayStr;
  588. BalanceEUR += BalanceStr;
  589. YSFYEUR += CurrPayStr;
  590. }
  591. _detail.TotalStr1 = string.Format(@"应付款总金额:{0}CNY&nbsp;|&nbsp;{1}USD&nbsp;|&nbsp;{2}EUR", CNY, USD, EUR);
  592. _detail.TotalStr2 = string.Format(@"此次付款总金额:{0}CNY&nbsp;|&nbsp;{1}USD&nbsp;|&nbsp;{2}EUR", PayCNY, PayUSD, PayEUR);
  593. _detail.TotalStr3 = string.Format(@"目前剩余尾款总金额:{0}CNY&nbsp;|&nbsp;{1}USD&nbsp;|&nbsp;{2}EUR", BalanceCNY, BalanceUSD, BalanceEUR);
  594. _detail.TotalStr4 = string.Format(@"已审费用总额:{0}CNY&nbsp;|&nbsp;{1}USD&nbsp;|&nbsp;{2}EUR", YSFYCNY, YSFYUSD, YSFYEUR);
  595. detailList.Add(_detail);
  596. }
  597. #endregion
  598. _view.DetailList = new List<Grp_CreditCardPaymentDetailView>(detailList);
  599. return Ok(JsonView(_view));
  600. }
  601. /// <summary>
  602. /// 修改团组费用审核状态
  603. /// </summary>
  604. /// <param name="paras">参数Json字符串</param>
  605. /// <returns></returns>
  606. [HttpPost]
  607. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  608. public async Task<IActionResult> PostAuditGrpCreditCardPayment(Edit_GrpCreditCardPaymentDto _dto)
  609. {
  610. List<string> idList = _dto.CreditIdStr.Split(',').ToList();
  611. Grp_CreditCardPayment _detail = _mapper.Map<Grp_CreditCardPayment>(_dto);
  612. DateTime dtNow = DateTime.Now;
  613. _groupRepository.BeginTran();
  614. int rst = 0;
  615. foreach (var item in idList)
  616. {
  617. int CreditId = int.Parse(item);
  618. var result = await _grpScheduleRep._sqlSugar.Updateable<Grp_CreditCardPayment>()
  619. .SetColumns(it => it.IsAuditGM == _dto.AuditCode)
  620. .SetColumns(it => it.AuditGMOperate == _dto.User)
  621. .SetColumns(it => it.AuditGMDate == dtNow)
  622. .Where(s => s.Id == CreditId)
  623. .ExecuteCommandAsync();
  624. if (result < 1)
  625. {
  626. rst = -1;
  627. }
  628. else
  629. {
  630. _groupRepository.RollbackTran();
  631. return Ok(JsonView(false, "保存失败并回滚!"));
  632. }
  633. }
  634. _groupRepository.CommitTran();
  635. if (rst == 0)
  636. {
  637. return Ok(JsonView(true, "保存成功!"));
  638. }
  639. return Ok(JsonView(false, "保存失败!"));
  640. }
  641. #endregion
  642. #region 机票费用录入
  643. /// <summary>
  644. /// 机票录入当前登录人可操作团组
  645. /// </summary>
  646. /// <param name="dto"></param>
  647. /// <returns></returns>
  648. [HttpPost]
  649. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  650. public async Task<IActionResult> AirTicketResSelect(AirTicketResDto dto)
  651. {
  652. try
  653. {
  654. Result groupData = await _airTicketResRep.AirTicketResSelect(dto);
  655. if (groupData.Code != 0)
  656. {
  657. return Ok(JsonView(false, groupData.Msg));
  658. }
  659. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  660. }
  661. catch (Exception ex)
  662. {
  663. return Ok(JsonView(false, "程序错误!"));
  664. throw;
  665. }
  666. }
  667. /// <summary>
  668. /// 机票费用录入列表
  669. /// </summary>
  670. /// <param name="dto"></param>
  671. /// <returns></returns>
  672. [HttpPost]
  673. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  674. public async Task<IActionResult> AirTicketResList(AirTicketResDto dto)
  675. {
  676. try
  677. {
  678. Result groupData = await _airTicketResRep.AirTicketResList(dto);
  679. if (groupData.Code != 0)
  680. {
  681. return Ok(JsonView(false, groupData.Msg));
  682. }
  683. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  684. }
  685. catch (Exception ex)
  686. {
  687. return Ok(JsonView(false, "程序错误!"));
  688. throw;
  689. }
  690. }
  691. /// <summary>
  692. /// 根据id查询费用录入信息
  693. /// </summary>
  694. /// <param name="dto"></param>
  695. /// <returns></returns>
  696. [HttpPost]
  697. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  698. public async Task<IActionResult> AirTicketResById(AirTicketResByIdDto dto)
  699. {
  700. try
  701. {
  702. Result groupData = await _airTicketResRep.AirTicketResById(dto);
  703. if (groupData.Code != 0)
  704. {
  705. return Ok(JsonView(false, groupData.Msg));
  706. }
  707. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  708. }
  709. catch (Exception ex)
  710. {
  711. return Ok(JsonView(false, "程序错误!"));
  712. throw;
  713. }
  714. }
  715. /// <summary>
  716. /// 机票费用录入操作(Status:1.新增,2.修改)
  717. /// </summary>
  718. /// <param name="dto"></param>
  719. /// <returns></returns>
  720. [HttpPost]
  721. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  722. public async Task<IActionResult> OpAirTicketRes(AirTicketResOpDto dto)
  723. {
  724. try
  725. {
  726. Result groupData = await _airTicketResRep.OpAirTicketRes(dto);
  727. if (groupData.Code != 0)
  728. {
  729. return Ok(JsonView(false, groupData.Msg));
  730. }
  731. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  732. }
  733. catch (Exception ex)
  734. {
  735. return Ok(JsonView(false, "程序错误!"));
  736. throw;
  737. }
  738. }
  739. /// <summary>
  740. /// 机票费用录入,删除
  741. /// </summary>
  742. /// <param name="dto"></param>
  743. /// <returns></returns>
  744. [HttpPost]
  745. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  746. public async Task<IActionResult> DelAirTicketRes(DelBaseDto dto)
  747. {
  748. try
  749. {
  750. var res = await _airTicketResRep.SoftDeleteByIdAsync<Grp_AirTicketReservations>(dto.Id.ToString(), dto.DeleteUserId);
  751. if (!res)
  752. {
  753. return Ok(JsonView(false, "删除失败"));
  754. }
  755. return Ok(JsonView(true, "删除成功!"));
  756. }
  757. catch (Exception ex)
  758. {
  759. return Ok(JsonView(false, "程序错误!"));
  760. throw;
  761. }
  762. }
  763. /// <summary>
  764. /// 导出机票录入报表
  765. /// </summary>
  766. /// <param name="dto"></param>
  767. /// <returns></returns>
  768. [HttpPost]
  769. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  770. public async Task<IActionResult> DeriveAirTicketRes(AirTicketResDto dto)
  771. {
  772. try
  773. {
  774. Result groupData = await _airTicketResRep.DeriveAirTicketRes(dto);
  775. if (groupData.Code != 0)
  776. {
  777. return Ok(JsonView(false, groupData.Msg));
  778. }
  779. else
  780. {
  781. List<AirTicketReservationsPayView> AirTicketReservations = groupData.Data.GetType().GetProperty("AirTicketRes").GetValue(groupData.Data);
  782. if (AirTicketReservations.Count != 0)
  783. {
  784. Grp_DelegationInfo DelegationInfo = groupData.Data.GetType().GetProperty("Delegation").GetValue(groupData.Data);
  785. Sys_Users _Users = groupData.Data.GetType().GetProperty("Users").GetValue(groupData.Data);
  786. string diCode = DelegationInfo != null ? DelegationInfo.TourCode : "XXX";
  787. string diName = DelegationInfo != null ? DelegationInfo.TeamName : "XXX";
  788. WorkbookDesigner designer = new WorkbookDesigner();
  789. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/机票预订费用报表模板.xlsx");
  790. decimal countCost = 0;
  791. foreach (var item in AirTicketReservations)
  792. {
  793. if (item.BankType == "其他")
  794. {
  795. item.BankNo = "--";
  796. }
  797. else
  798. {
  799. item.BankNo = item.BankType + ":" + item.BankNo.Substring(0, 3);
  800. }
  801. item.PrePrice = System.Decimal.Round(item.PrePrice, 2);
  802. item.Price = System.Decimal.Round(item.Price, 2);
  803. countCost += Convert.ToDecimal(item.Price);
  804. }
  805. designer.SetDataSource("Export", AirTicketReservations);
  806. designer.SetDataSource("ExportDiCode", diCode);
  807. designer.SetDataSource("ExportDiName", diName);
  808. designer.SetDataSource("ExportOpUserName", _Users.CnName);
  809. designer.SetDataSource("ExportCountCost", countCost + "(" + AirTicketReservations[0].CurrencyStr);
  810. designer.Process();
  811. string fileName = "AirfareStatement/" + diName + "机票费用报表" + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";
  812. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  813. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  814. return Ok(JsonView(true, "成功", url = rst));
  815. }
  816. else
  817. {
  818. return Ok(JsonView(false, "暂无数据!"));
  819. }
  820. }
  821. }
  822. catch (Exception ex)
  823. {
  824. return Ok(JsonView(false, "程序错误!"));
  825. throw;
  826. }
  827. }
  828. Dictionary<string, string> transDic = new Dictionary<string, string>();
  829. /// <summary>
  830. /// 行程单导出
  831. /// </summary>
  832. /// <param name="dto"></param>
  833. /// <returns></returns>
  834. [HttpPost]
  835. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  836. public async Task<IActionResult> ItineraryAirTicketRes(ItineraryAirTicketResDto dto)
  837. {
  838. try
  839. {
  840. Result groupData = await _airTicketResRep.ItineraryAirTicketRes(dto);
  841. if (groupData.Code != 0)
  842. {
  843. return Ok(JsonView(false, groupData.Msg));
  844. }
  845. else
  846. {
  847. List<AirTicketReservationsView> _AirTicketReservations = groupData.Data;
  848. if (dto.Language=="CN")
  849. {
  850. Document doc = new Document(AppSettingsHelper.Get("WordBasePath") + "Template/电子客票行程单模板_CN.docx");
  851. DocumentBuilder builder = new DocumentBuilder(doc);
  852. int tableIndex = 0;//表格索引
  853. //得到文档中的第一个表格
  854. Table table = (Table)doc.GetChild(NodeType.Table, tableIndex, true);
  855. foreach (var item in _AirTicketReservations)
  856. {
  857. #region 处理固定数据
  858. string[] FlightsCode = item.FlightsCode.Split('/');
  859. if (FlightsCode.Length != 0)
  860. {
  861. Res_AirCompany _AirCompany = _sqlSugar.Queryable<Res_AirCompany>().First(a => a.ShortCode == FlightsCode[0].Substring(0, 2));
  862. if (_AirCompany != null)
  863. {
  864. table.Range.Bookmarks["AirlineCompany"].Text = _AirCompany.CnName;
  865. }
  866. else
  867. {
  868. table.Range.Bookmarks["AirlineCompany"].Text = "--";
  869. }
  870. }
  871. table.Range.Bookmarks["AirlineRecordCode"].Text = "--";
  872. table.Range.Bookmarks["ReservationRecordCode"].Text = "--";
  873. string[] nameArray = Regex.Split(item.ClientName, "\\d+\\.", RegexOptions.IgnoreCase);
  874. nameArray = nameArray.Where(str => str != "" && str != " " && !string.IsNullOrEmpty(str)).ToArray();
  875. string name = "";
  876. foreach (string clientName in nameArray)
  877. {
  878. if (!name.Contains(clientName))
  879. {
  880. name += clientName + ",";
  881. }
  882. }
  883. if (!string.IsNullOrWhiteSpace(name))
  884. {
  885. table.Range.Bookmarks["ClientName"].Text = name.Substring(0, name.Length - 1);
  886. }
  887. else
  888. {
  889. table.Range.Bookmarks["ClientName"].Text = "--";
  890. }
  891. table.Range.Bookmarks["TicketNumber"].Text = "--";
  892. table.Range.Bookmarks["IdentificationCode"].Text = "--";
  893. table.Range.Bookmarks["JointTicket"].Text = "--";
  894. table.Range.Bookmarks["TimeIssue"].Text = "--";
  895. table.Range.Bookmarks["DrawingAgent"].Text = "--";
  896. table.Range.Bookmarks["NavigationCode"].Text = "--";
  897. table.Range.Bookmarks["AgentsAddress"].Text = "--";
  898. table.Range.Bookmarks["AgentPhone"].Text = "--";
  899. table.Range.Bookmarks["AgentFacsimile"].Text = "--";
  900. #endregion
  901. #region 循环数据处理
  902. List<AirInfo> airs = new List<AirInfo>();
  903. string[] DayArray = Regex.Split(item.FlightsDescription, "\\d+\\.", RegexOptions.IgnoreCase);
  904. DayArray = DayArray.Where(s => s != " " && s != "" && !string.IsNullOrEmpty(s)).ToArray();
  905. for (int i = 0; i < FlightsCode.Length; i++)
  906. {
  907. AirInfo air = new AirInfo();
  908. string[] tempstr = DayArray[i]
  909. .Replace("\r\n", string.Empty)
  910. .Replace("\\r\\n", string.Empty)
  911. .TrimStart().TrimEnd()
  912. .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  913. Res_ThreeCode star_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(0, 3));
  914. string starCity = "";
  915. if (star_Three != null)
  916. {
  917. starCity = star_Three.AirPort;
  918. }
  919. Res_ThreeCode End_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(3, 3));
  920. string EndCity = "";
  921. if (End_Three != null)
  922. {
  923. EndCity = End_Three.AirPort;
  924. }
  925. air.Destination = starCity + "/" + EndCity;
  926. air.Flight = FlightsCode[i];
  927. air.SeatingClass = item.CTypeName;
  928. string dateTime = tempstr[2];
  929. string DateTemp = dateTime.Substring(2, 5).ToUpper();
  930. air.FlightDate = DateTemp;
  931. air.DepartureTime = tempstr[5];
  932. air.LandingTime = tempstr[6];
  933. air.ValidityPeriod = DateTemp + "/" + DateTemp;
  934. air.TicketStatus = "--";
  935. air.Luggage = "--";
  936. air.DepartureTerminal = "--";
  937. air.LandingTerminal = "--";
  938. airs.Add(air);
  939. }
  940. int row = 13;
  941. for (int i = 0; i < airs.Count; i++)
  942. {
  943. if (airs.Count > 2)
  944. {
  945. for (int j = 0; j < airs.Count - 2; j++)
  946. {
  947. var CopyRow = table.Rows[12].Clone(true);
  948. table.Rows.Add(CopyRow);
  949. }
  950. }
  951. PropertyInfo[] properties = airs[i].GetType().GetProperties();
  952. int index = 0;
  953. foreach (PropertyInfo property in properties)
  954. {
  955. string value = property.GetValue(airs[i]).ToString();
  956. Cell ishcel0 = table.Rows[row].Cells[index];
  957. Paragraph p = new Paragraph(doc);
  958. string s = value;
  959. p.AppendChild(new Run(doc, s));
  960. ishcel0.AppendChild(p);
  961. index++;
  962. }
  963. row++;
  964. }
  965. #endregion
  966. Paragraph lastParagraph = new Paragraph(doc);
  967. //第一个表格末尾加段落
  968. table.ParentNode.InsertAfter(lastParagraph, table);
  969. //复制第一个表格
  970. Table cloneTable = (Table)table.Clone(true);
  971. //在文档末尾段落后面加入复制的表格
  972. table.ParentNode.InsertAfter(cloneTable, lastParagraph);
  973. if (item != _AirTicketReservations[_AirTicketReservations.Count - 1])
  974. {
  975. int rownewsIndex = 13;
  976. for (int i = 0; i < 2; i++)
  977. {
  978. var CopyRow = table.Rows[12].Clone(true);
  979. table.Rows.RemoveAt(13);
  980. table.Rows.Add(CopyRow);
  981. rownewsIndex++;
  982. }
  983. }
  984. else
  985. {
  986. table.Rows.RemoveAt(12);
  987. }
  988. cloneTable.Rows.RemoveAt(12);
  989. }
  990. if (_AirTicketReservations.Count != 0)
  991. {
  992. string[] FlightsCode = _AirTicketReservations[0].FlightsCode.Split('/');
  993. if (FlightsCode.Length != 0)
  994. {
  995. Res_AirCompany _AirCompany = _sqlSugar.Queryable<Res_AirCompany>().First(a => a.ShortCode == FlightsCode[0].Substring(0, 2));
  996. if (_AirCompany != null)
  997. {
  998. table.Range.Bookmarks["AirlineCompany"].Text = _AirCompany.CnName;
  999. }
  1000. else
  1001. {
  1002. table.Range.Bookmarks["AirlineCompany"].Text = "--";
  1003. }
  1004. }
  1005. table.Range.Bookmarks["AirlineRecordCode"].Text = "--";
  1006. table.Range.Bookmarks["ReservationRecordCode"].Text = "--";
  1007. string[] nameArray = Regex.Split(_AirTicketReservations[0].ClientName, "\\d+\\.", RegexOptions.IgnoreCase);
  1008. nameArray = nameArray.Where(str => str != "" && str != " " && !string.IsNullOrEmpty(str)).ToArray();
  1009. string name = "";
  1010. foreach (string clientName in nameArray)
  1011. {
  1012. if (!name.Contains(clientName))
  1013. {
  1014. name = name + "," + clientName;
  1015. }
  1016. }
  1017. if (!string.IsNullOrWhiteSpace(name))
  1018. {
  1019. table.Range.Bookmarks["ClientName"].Text = name;
  1020. }
  1021. else
  1022. {
  1023. table.Range.Bookmarks["ClientName"].Text = "--";
  1024. }
  1025. table.Range.Bookmarks["TicketNumber"].Text = "--";
  1026. table.Range.Bookmarks["IdentificationCode"].Text = "--";
  1027. table.Range.Bookmarks["JointTicket"].Text = "--";
  1028. table.Range.Bookmarks["TimeIssue"].Text = "--";
  1029. table.Range.Bookmarks["DrawingAgent"].Text = "--";
  1030. table.Range.Bookmarks["NavigationCode"].Text = "--";
  1031. table.Range.Bookmarks["AgentsAddress"].Text = "--";
  1032. table.Range.Bookmarks["AgentPhone"].Text = "--";
  1033. table.Range.Bookmarks["AgentFacsimile"].Text = "--";
  1034. }
  1035. doc.MailMerge.Execute(new[] { "PageCount" }, new object[] { doc.PageCount });
  1036. //保存合并后的文档
  1037. string fileName = "AirItinerary/电子客票中文行程单_CN.docx";
  1038. string rst = AppSettingsHelper.Get("WordBaseUrl") + AppSettingsHelper.Get("WordFtpPath") + fileName;
  1039. doc.Save(AppSettingsHelper.Get("WordBasePath") + fileName);
  1040. return Ok(JsonView(true, "成功!", rst));
  1041. }
  1042. else
  1043. {
  1044. Document doc = new Document(AppSettingsHelper.Get("WordBasePath") + "Template/电子客票行程单模板_EN.docx");
  1045. DocumentBuilder builder = new DocumentBuilder(doc);
  1046. int tableIndex = 0;//表格索引
  1047. //得到文档中的第一个表格
  1048. Table table = (Table)doc.GetChild(NodeType.Table, tableIndex, true);
  1049. List<string> texts = new List<string>();
  1050. foreach (var item in _AirTicketReservations)
  1051. {
  1052. string[] FlightsCode = item.FlightsCode.Split('/');
  1053. if (FlightsCode.Length != 0)
  1054. {
  1055. Res_AirCompany _AirCompany = _sqlSugar.Queryable<Res_AirCompany>().First(a => a.ShortCode == FlightsCode[0].Substring(0, 2));
  1056. if (_AirCompany != null)
  1057. {
  1058. if (!transDic.ContainsKey(_AirCompany.CnName))
  1059. {
  1060. transDic.Add(_AirCompany.CnName, _AirCompany.EnName);
  1061. }
  1062. }
  1063. else
  1064. {
  1065. if (!transDic.ContainsKey("--"))
  1066. {
  1067. transDic.Add("--", "--");
  1068. }
  1069. }
  1070. }
  1071. string[] nameArray = Regex.Split(item.ClientName, "\\d+\\.", RegexOptions.IgnoreCase);
  1072. nameArray = nameArray.Where(str => str != "" && str != " " && !string.IsNullOrEmpty(str)).ToArray();
  1073. string name = "";
  1074. foreach (string clientName in nameArray)
  1075. {
  1076. name += clientName+",";
  1077. }
  1078. if (!texts.Contains(name))
  1079. {
  1080. texts.Add(name);
  1081. }
  1082. List<AirInfo> airs = new List<AirInfo>();
  1083. string[] DayArray = Regex.Split(item.FlightsDescription, "\\d+\\.", RegexOptions.IgnoreCase);
  1084. DayArray = DayArray.Where(s => s != " " && s != "" && !string.IsNullOrEmpty(s)).ToArray();
  1085. for (int i = 0; i < FlightsCode.Length; i++)
  1086. {
  1087. AirInfo air = new AirInfo();
  1088. string[] tempstr = DayArray[i]
  1089. .Replace("\r\n", string.Empty)
  1090. .Replace("\\r\\n", string.Empty)
  1091. .TrimStart().TrimEnd()
  1092. .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  1093. Res_ThreeCode star_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(0, 3));
  1094. if (star_Three != null)
  1095. {
  1096. if (!transDic.ContainsKey(star_Three.AirPort))
  1097. {
  1098. transDic.Add(star_Three.AirPort, star_Three.AirPort_En);
  1099. }
  1100. }
  1101. Res_ThreeCode End_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(3, 3));
  1102. if (End_Three != null)
  1103. {
  1104. if (!transDic.ContainsKey(End_Three.AirPort))
  1105. {
  1106. transDic.Add(End_Three.AirPort, End_Three.AirPort_En);
  1107. }
  1108. }
  1109. if (!texts.Contains(item.CTypeName))
  1110. {
  1111. texts.Add(item.CTypeName);
  1112. }
  1113. }
  1114. }
  1115. List<TranslateResult> transData = _airTicketResRep.ReTransBatch(texts, "en");
  1116. if (transData.Count > 0)
  1117. {
  1118. foreach (TranslateResult item in transData)
  1119. {
  1120. if (!transDic.ContainsKey(item.Query))
  1121. {
  1122. transDic.Add(item.Query, item.Translation);
  1123. }
  1124. }
  1125. }
  1126. foreach (var item in _AirTicketReservations)
  1127. {
  1128. #region 处理固定数据
  1129. string[] FlightsCode = item.FlightsCode.Split('/');
  1130. if (FlightsCode.Length != 0)
  1131. {
  1132. Res_AirCompany _AirCompany = _sqlSugar.Queryable<Res_AirCompany>().First(a => a.ShortCode == FlightsCode[0].Substring(0, 2));
  1133. if (_AirCompany != null)
  1134. {
  1135. string str = "--";
  1136. string translateResult = transDic.Where(s => s.Key == _AirCompany.CnName).FirstOrDefault().Value;
  1137. if (!string.IsNullOrEmpty(translateResult))
  1138. {
  1139. str = translateResult;
  1140. str =_airTicketResRep.Processing(str);
  1141. }
  1142. table.Range.Bookmarks["AirlineCompany"].Text = str;
  1143. }
  1144. else
  1145. {
  1146. table.Range.Bookmarks["AirlineCompany"].Text = "--";
  1147. }
  1148. }
  1149. table.Range.Bookmarks["AirlineRecordCode"].Text = "--";
  1150. table.Range.Bookmarks["ReservationRecordCode"].Text = "--";
  1151. string[] nameArray = Regex.Split(item.ClientName, "\\d+\\.", RegexOptions.IgnoreCase);
  1152. nameArray = nameArray.Where(str => str != "" && str != " " && !string.IsNullOrEmpty(str)).ToArray();
  1153. string names = "";
  1154. foreach (string clientName in nameArray)
  1155. {
  1156. names += clientName + ",";
  1157. }
  1158. if (!string.IsNullOrWhiteSpace(names))
  1159. {
  1160. string str = "--";
  1161. string translateResult = transDic.Where(s => s.Key == names).FirstOrDefault().Value;
  1162. if (!string.IsNullOrEmpty(translateResult))
  1163. {
  1164. str = translateResult;
  1165. str = _airTicketResRep.Processing(str);
  1166. }
  1167. table.Range.Bookmarks["ClientName"].Text = str;
  1168. }
  1169. else
  1170. {
  1171. table.Range.Bookmarks["ClientName"].Text = "--";
  1172. }
  1173. table.Range.Bookmarks["TicketNumber"].Text = "--";
  1174. table.Range.Bookmarks["IdentificationCode"].Text = "--";
  1175. table.Range.Bookmarks["JointTicket"].Text = "--";
  1176. table.Range.Bookmarks["TimeIssue"].Text = "--";
  1177. table.Range.Bookmarks["DrawingAgent"].Text = "--";
  1178. table.Range.Bookmarks["NavigationCode"].Text = "--";
  1179. table.Range.Bookmarks["AgentsAddress"].Text = "--";
  1180. table.Range.Bookmarks["AgentPhone"].Text = "--";
  1181. table.Range.Bookmarks["AgentFacsimile"].Text = "--";
  1182. #endregion
  1183. #region 循环数据处理
  1184. List<AirInfo> airs = new List<AirInfo>();
  1185. string[] DayArray = Regex.Split(item.FlightsDescription, "\\d+\\.", RegexOptions.IgnoreCase);
  1186. DayArray = DayArray.Where(s => s != " " && s != "" && !string.IsNullOrEmpty(s)).ToArray();
  1187. for (int i = 0; i < FlightsCode.Length; i++)
  1188. {
  1189. AirInfo air = new AirInfo();
  1190. string[] tempstr = DayArray[i]
  1191. .Replace("\r\n", string.Empty)
  1192. .Replace("\\r\\n", string.Empty)
  1193. .TrimStart().TrimEnd()
  1194. .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  1195. Res_ThreeCode star_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(0, 3));
  1196. string starCity = "";
  1197. if (star_Three != null)
  1198. {
  1199. string str2 = "--";
  1200. string translateResult2 = transDic.Where(s => s.Key == star_Three.AirPort).FirstOrDefault().Value;
  1201. if (!string.IsNullOrEmpty(translateResult2))
  1202. {
  1203. str2 = translateResult2;
  1204. str2 = _airTicketResRep.Processing(str2);
  1205. }
  1206. starCity = str2;
  1207. }
  1208. Res_ThreeCode End_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(3, 3));
  1209. string EndCity = "";
  1210. if (End_Three != null)
  1211. {
  1212. string str1 = "--";
  1213. string translateResult1 = transDic.Where(s => s.Key == End_Three.AirPort).FirstOrDefault().Value;
  1214. if (!string.IsNullOrEmpty(translateResult1))
  1215. {
  1216. str1 = translateResult1;
  1217. str1= _airTicketResRep.Processing(str1);
  1218. }
  1219. EndCity = str1;
  1220. }
  1221. air.Destination = starCity + "/" + EndCity;
  1222. air.Flight = FlightsCode[i];
  1223. string str = "--";
  1224. string translateResult = transDic.Where(s => s.Key == item.CTypeName).FirstOrDefault().Value;
  1225. if (!string.IsNullOrEmpty(translateResult))
  1226. {
  1227. str = translateResult;
  1228. str = _airTicketResRep.Processing(str);
  1229. }
  1230. air.SeatingClass = str;
  1231. string dateTime = tempstr[2];
  1232. string DateTemp = dateTime.Substring(2, 5).ToUpper();
  1233. air.FlightDate = DateTemp;
  1234. air.DepartureTime = tempstr[5];
  1235. air.LandingTime = tempstr[6];
  1236. air.ValidityPeriod = DateTemp + "/" + DateTemp;
  1237. air.TicketStatus = "--";
  1238. air.Luggage = "--";
  1239. air.DepartureTerminal = "--";
  1240. air.LandingTerminal = "--";
  1241. airs.Add(air);
  1242. }
  1243. int row = 13;
  1244. for (int i = 0; i < airs.Count; i++)
  1245. {
  1246. if (airs.Count > 2)
  1247. {
  1248. for (int j = 0; j < airs.Count - 2; j++)
  1249. {
  1250. var CopyRow = table.Rows[12].Clone(true);
  1251. table.Rows.Add(CopyRow);
  1252. }
  1253. }
  1254. PropertyInfo[] properties = airs[i].GetType().GetProperties();
  1255. int index = 0;
  1256. foreach (PropertyInfo property in properties)
  1257. {
  1258. string value = property.GetValue(airs[i]).ToString();
  1259. Cell ishcel0 = table.Rows[row].Cells[index];
  1260. Paragraph p = new Paragraph(doc);
  1261. string s = value;
  1262. p.AppendChild(new Run(doc, s));
  1263. ishcel0.AppendChild(p);
  1264. index++;
  1265. }
  1266. row++;
  1267. }
  1268. #endregion
  1269. Paragraph lastParagraph = new Paragraph(doc);
  1270. //第一个表格末尾加段落
  1271. table.ParentNode.InsertAfter(lastParagraph, table);
  1272. //复制第一个表格
  1273. Table cloneTable = (Table)table.Clone(true);
  1274. //在文档末尾段落后面加入复制的表格
  1275. table.ParentNode.InsertAfter(cloneTable, lastParagraph);
  1276. if (item != _AirTicketReservations[_AirTicketReservations.Count - 1])
  1277. {
  1278. int rownewsIndex = 13;
  1279. for (int i = 0; i < 2; i++)
  1280. {
  1281. var CopyRow = table.Rows[12].Clone(true);
  1282. table.Rows.RemoveAt(13);
  1283. table.Rows.Add(CopyRow);
  1284. rownewsIndex++;
  1285. }
  1286. }
  1287. else
  1288. {
  1289. table.Rows.RemoveAt(12);
  1290. }
  1291. cloneTable.Rows.RemoveAt(12);
  1292. }
  1293. if (_AirTicketReservations.Count != 0)
  1294. {
  1295. string[] FlightsCode = _AirTicketReservations[0].FlightsCode.Split('/');
  1296. if (FlightsCode.Length != 0)
  1297. {
  1298. Res_AirCompany _AirCompany = _sqlSugar.Queryable<Res_AirCompany>().First(a => a.ShortCode == FlightsCode[0].Substring(0, 2));
  1299. if (_AirCompany != null)
  1300. {
  1301. string str = "--";
  1302. string translateResult = transDic.Where(s => s.Key == _AirCompany.CnName).FirstOrDefault().Value;
  1303. if (!string.IsNullOrEmpty(translateResult))
  1304. {
  1305. str = translateResult;
  1306. str = _airTicketResRep.Processing(str);
  1307. }
  1308. table.Range.Bookmarks["AirlineCompany"].Text = str;
  1309. }
  1310. else
  1311. {
  1312. table.Range.Bookmarks["AirlineCompany"].Text = "--";
  1313. }
  1314. }
  1315. table.Range.Bookmarks["AirlineRecordCode"].Text = "--";
  1316. table.Range.Bookmarks["ReservationRecordCode"].Text = "--";
  1317. string[] nameArray = Regex.Split(_AirTicketReservations[0].ClientName, "\\d+\\.", RegexOptions.IgnoreCase);
  1318. nameArray = nameArray.Where(str => str != "" && str != " " && !string.IsNullOrEmpty(str)).ToArray();
  1319. string names = "";
  1320. foreach (string clientName in nameArray)
  1321. {
  1322. names += clientName + ",";
  1323. }
  1324. if (!string.IsNullOrWhiteSpace(names))
  1325. {
  1326. string str = "--";
  1327. string translateResult = transDic.Where(s => s.Key == names).FirstOrDefault().Value;
  1328. if (!string.IsNullOrEmpty(translateResult))
  1329. {
  1330. str = translateResult;
  1331. str = _airTicketResRep.Processing(str);
  1332. }
  1333. table.Range.Bookmarks["ClientName"].Text = str;
  1334. }
  1335. else
  1336. {
  1337. table.Range.Bookmarks["ClientName"].Text = "--";
  1338. }
  1339. table.Range.Bookmarks["TicketNumber"].Text = "--";
  1340. table.Range.Bookmarks["IdentificationCode"].Text = "--";
  1341. table.Range.Bookmarks["JointTicket"].Text = "--";
  1342. table.Range.Bookmarks["TimeIssue"].Text = "--";
  1343. table.Range.Bookmarks["DrawingAgent"].Text = "--";
  1344. table.Range.Bookmarks["NavigationCode"].Text = "--";
  1345. table.Range.Bookmarks["AgentsAddress"].Text = "--";
  1346. table.Range.Bookmarks["AgentPhone"].Text = "--";
  1347. table.Range.Bookmarks["AgentFacsimile"].Text = "--";
  1348. }
  1349. doc.MailMerge.Execute(new[] { "PageCount" }, new object[] { doc.PageCount });
  1350. //保存合并后的文档
  1351. string fileName = "AirItinerary/电子客票英文行程单_EN.docx";
  1352. string rst = AppSettingsHelper.Get("WordBaseUrl") + AppSettingsHelper.Get("WordFtpPath") + fileName;
  1353. doc.Save(AppSettingsHelper.Get("WordBasePath") + fileName);
  1354. return Ok(JsonView(true, "成功!", rst));
  1355. }
  1356. }
  1357. }
  1358. catch (Exception ex)
  1359. {
  1360. return Ok(JsonView(false, "程序错误!"));
  1361. throw;
  1362. }
  1363. }
  1364. #endregion
  1365. }
  1366. }