GroupsController.cs 67 KB

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