GroupsController.cs 69 KB

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