BusinessController.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. using Microsoft.AspNetCore.Mvc;
  2. using NPOI.SS.Formula.Functions;
  3. using OASystem.API.OAMethodLib.ALiYun;
  4. using OASystem.API.OAMethodLib.ExcelOutput;
  5. using OASystem.Domain.Common;
  6. using OASystem.Domain.Dtos.Business;
  7. using OASystem.Domain.Dtos.Financial;
  8. using OASystem.Domain.Dtos.Groups;
  9. using OASystem.Domain.Entities.Business;
  10. using OASystem.Domain.Entities.Financial;
  11. using OASystem.Domain.Entities.Groups;
  12. using OASystem.Domain.Entities.Resource;
  13. using OASystem.Domain.ViewModels.Business;
  14. using OASystem.Domain.ViewModels.Financial;
  15. using OASystem.Domain.ViewModels.Groups;
  16. using OASystem.Infrastructure.Repositories.Business;
  17. using OASystem.Infrastructure.Repositories.Groups;
  18. using OASystem.Infrastructure.Repositories.System;
  19. using Org.BouncyCastle.Asn1.Mozilla;
  20. namespace OASystem.API.Controllers
  21. {
  22. /// <summary>
  23. /// 通用业务操作
  24. /// </summary>
  25. [Route("api/[controller]/[action]")]
  26. public class BusinessController : ControllerBase
  27. {
  28. private readonly IMapper _mapper;
  29. private readonly CommonBusRepository _busRep;
  30. private readonly SetDataRepository _setDataRep;
  31. private readonly DelegationInfoRepository _groupRep;
  32. private readonly TeamRateRepository _teamRateRep;
  33. public BusinessController( IMapper mapper, CommonBusRepository busRep, SetDataRepository setDataRep, DelegationInfoRepository groupRep, TeamRateRepository teamRateRep)
  34. {
  35. _mapper = mapper;
  36. _busRep = busRep;
  37. _setDataRep = setDataRep;
  38. _groupRep = groupRep;
  39. _teamRateRep = teamRateRep;
  40. }
  41. #region 团组信息
  42. /// <summary>
  43. /// 团组信息
  44. /// 团组简略详情
  45. /// </summary>
  46. /// <param name="dto">团组info请求dto</param>
  47. /// <returns></returns>
  48. [HttpPost]
  49. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  50. public async Task<IActionResult> PostShareGroupInfo(ShareGroupInfoDto dto)
  51. {
  52. try
  53. {
  54. var groupData = await _groupRep.PostShareGroupInfo(dto);
  55. if (groupData.Code != 0)
  56. {
  57. return Ok(JsonView(false, groupData.Msg));
  58. }
  59. return Ok(JsonView(groupData.Data));
  60. }
  61. catch (Exception ex)
  62. {
  63. return Ok(JsonView(false, ex.Message));
  64. }
  65. }
  66. /// <summary>
  67. /// 团组信息 团组名称 List
  68. /// </summary>
  69. /// <param name="dto"></param>
  70. /// <returns></returns>
  71. [HttpPost]
  72. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  73. public async Task<IActionResult> GetGroupNameList(GroupNameDto dto)
  74. {
  75. var groupData = await _groupRep.GetGroupNameList(dto);
  76. if (groupData.Code != 0)
  77. {
  78. return Ok(JsonView(false, groupData.Msg));
  79. }
  80. return Ok(JsonView(groupData.Data, groupData.Data.Count));
  81. }
  82. /// <summary>
  83. /// 获取团组指向分类
  84. /// </summary>
  85. /// <param name="_dto">参数Json字符串</param>
  86. /// <returns></returns>
  87. [HttpPost]
  88. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  89. public async Task<IActionResult> PostGroupDirectionalClassificationInit()
  90. {
  91. Result result = new Result();
  92. result = await _setDataRep.GetSetDataBySTId(_setDataRep, 16); //团组指向分类
  93. if (result.Code != 0)
  94. {
  95. return Ok(JsonView(false, "获取失败!"));
  96. }
  97. List<SetDataInfoView> _view1 = JsonConvert.DeserializeObject<List<SetDataInfoView>>(JsonConvert.SerializeObject(result.Data));
  98. SetDataInfoView xc_view = new SetDataInfoView();//77 行程 //移除行程
  99. xc_view = _view1.Where(it => it.Id == 77).FirstOrDefault();
  100. if (xc_view != null) { _view1.Remove(xc_view); };
  101. List<SetDataInfoView> _view = new List<SetDataInfoView>();
  102. //_view.Insert(0, new SetDataInfoView { Id = -1, Name = "所有模块" });
  103. SetDataInfoView qz_view = new SetDataInfoView();//80 签证
  104. qz_view = _view1.Where(it => it.Id == 80).FirstOrDefault();
  105. if (qz_view != null) { _view.Insert(0, qz_view); _view1.Remove(qz_view); };
  106. SetDataInfoView jpyd_view = new SetDataInfoView();//85 机票预订
  107. jpyd_view = _view1.Where(it => it.Id == 85).FirstOrDefault();
  108. if (jpyd_view != null) { _view.Insert(1, jpyd_view); _view1.Remove(jpyd_view); };
  109. SetDataInfoView jdyd_view = new SetDataInfoView();//76 酒店预订
  110. jdyd_view = _view1.Where(it => it.Id == 76).FirstOrDefault();
  111. if (jdyd_view != null) { _view.Insert(2, jdyd_view); _view1.Remove(jdyd_view); };
  112. SetDataInfoView jdzc_view = new SetDataInfoView();//751 酒店早餐
  113. jdzc_view = _view1.Where(it => it.Id == 751).FirstOrDefault();
  114. if (jdzc_view != null) { _view.Insert(3, jdzc_view); _view1.Remove(jdzc_view); };
  115. SetDataInfoView cdy_view = new SetDataInfoView();//79 车/导游地接
  116. cdy_view = _view1.Where(it => it.Id == 79).FirstOrDefault();
  117. if (cdy_view != null) { _view.Insert(4, cdy_view); _view1.Remove(cdy_view); };
  118. SetDataInfoView yqgw_view = new SetDataInfoView();//81 邀请/公务活动
  119. yqgw_view = _view1.Where(it => it.Id == 81).FirstOrDefault();
  120. if (yqgw_view != null) { _view.Insert(5, yqgw_view); _view1.Remove(yqgw_view); };
  121. SetDataInfoView bx_view = new SetDataInfoView();//82 团组客户保险
  122. bx_view = _view1.Where(it => it.Id == 82).FirstOrDefault();
  123. if (bx_view != null) { _view.Insert(6, bx_view); _view1.Remove(bx_view); };
  124. SetDataInfoView qtkx_view = new SetDataInfoView();//98 其他款项
  125. qtkx_view = _view1.Where(it => it.Id == 98).FirstOrDefault();
  126. if (qtkx_view != null) { _view.Insert(7, qtkx_view); _view1.Remove(qtkx_view); };
  127. SetDataInfoView skth_view = new SetDataInfoView();//285 收款退还与其他款项
  128. skth_view = _view1.Where(it => it.Id == 285).FirstOrDefault();
  129. if (skth_view != null) { _view.Insert(8, skth_view); _view1.Remove(skth_view); };
  130. if (_view1.Count > 0)
  131. {
  132. _view.AddRange(_view1);
  133. }
  134. return Ok(JsonView(_view));
  135. }
  136. #endregion
  137. #region 币种 List
  138. /// <summary>
  139. /// 币种 List
  140. /// </summary>
  141. /// <returns></returns>
  142. [HttpGet,HttpPost]
  143. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  144. public async Task<IActionResult> PostCurrencyList()
  145. {
  146. try
  147. {
  148. Result setData = await _setDataRep.GetSetDataBySTId(_setDataRep, 66); //币种类型
  149. if (setData.Code == 0)
  150. {
  151. return Ok(JsonView(true, "查询成功", setData.Data));
  152. }
  153. else
  154. {
  155. return Ok(JsonView(false, setData.Msg));
  156. }
  157. }
  158. catch (Exception)
  159. {
  160. return Ok(JsonView(false, "程序错误!"));
  161. throw;
  162. }
  163. }
  164. /// <summary>
  165. /// 团组汇率 币种 Item (来源:团组汇率)
  166. /// 根据 团组Id And 业务类型(CTable)Id
  167. /// api处理CTable = 285,默认返回CNY
  168. /// </summary>
  169. /// <param name="dto"> 请求参数Dto </param>
  170. /// <returns></returns>
  171. [HttpPost]
  172. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  173. public async Task<IActionResult> PostGroupTeamRateByDiIdAndCTableId(GeneralTeamRateInfoDto dto)
  174. {
  175. try
  176. {
  177. if (dto == null)
  178. {
  179. return Ok(JsonView(false, "请输入参数!"));
  180. }
  181. if (dto.DiId == 0)
  182. {
  183. return Ok(JsonView(false, "请输入正确的团组Id!"));
  184. }
  185. if (dto.CTable == 0)
  186. {
  187. return Ok(JsonView(false, "请输入正确的业务类型(CTable)Id!"));
  188. }
  189. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3 )
  190. {
  191. string teamRateInfoSql = string.Format(@"Select sd.Name,tr.* From Grp_TeamRate tr
  192. Left Join Sys_SetData sd On sd.IsDel=0 And sd.STid=16 And tr.CTable = sd.Id
  193. Where tr.IsDel = 0 And tr.DiId = {0} And tr.CTable = {1}", dto.DiId,dto.CTable);
  194. var teamRateInfo = await _teamRateRep._sqlSugar.SqlQueryable<TeamRateInfoView>(teamRateInfoSql).ToListAsync();
  195. #region 团组汇率
  196. TeamRateModelGeneralView teamRateModels = new TeamRateModelGeneralView();
  197. #region 单独处理Ctable 币种汇率 默认 为CNY
  198. if (dto.CTable == 285)
  199. {
  200. teamRateModels = new TeamRateModelGeneralView()
  201. {
  202. Id = 0,
  203. CTableId = 285,
  204. CTableName = "其他款项与收款退还",
  205. TeamRates = new List<TeamRateDescAddCurrencyIdView>() {
  206. new TeamRateDescAddCurrencyIdView()
  207. {
  208. CurrencyId = 836,
  209. CurrencyCode = "CNY",
  210. CurrencyName = "人民币",
  211. Rate = 1.0000M,
  212. }
  213. }
  214. };
  215. return Ok(JsonView(true, "操作成功!", teamRateModels));
  216. }
  217. #endregion
  218. List<SetDataInfoView> currencyDatas = new List<SetDataInfoView>();
  219. #region 获取所有币种
  220. string sql = string.Format(@"select * from Sys_SetData where STid = {0} and isdel = 0", 66);
  221. var DBdata = await _setDataRep.GetListBySqlWithNolockAsync(sql);
  222. if (DBdata == null || DBdata.Count == 0)
  223. {
  224. return Ok(JsonView(false, "所有币种获取失败!"));
  225. }
  226. currencyDatas = DBdata.Select(x => new SetDataInfoView
  227. {
  228. Name = x.Name,
  229. Id = x.Id,
  230. Remark = x.Remark,
  231. }).ToList();
  232. #endregion
  233. foreach (TeamRateInfoView item in teamRateInfo)
  234. {
  235. TeamRateModelGeneralView teamRateModelInfo = new TeamRateModelGeneralView();
  236. teamRateModelInfo.Id = item.Id;
  237. teamRateModelInfo.CTableId = item.CTable;
  238. teamRateModelInfo.CTableName = item.Name;
  239. List<TeamRateDescAddCurrencyIdView> teamRateDescViews = new List<TeamRateDescAddCurrencyIdView>();
  240. #region 拆分remark里的汇率
  241. if (item.Remark.Contains("|"))
  242. {
  243. string[] currencyArr = item.Remark.Split("|");
  244. foreach (string currency in currencyArr)
  245. {
  246. string[] currency1 = currency.Split(":");
  247. string[] currency2 = currency1[0].Split("(");
  248. string currencyCode = currency2[1].Replace(")", "").TrimEnd();
  249. SetDataInfoView dataInfoView = new SetDataInfoView();
  250. dataInfoView = currencyDatas.Where(it => it.Name == currencyCode).FirstOrDefault();
  251. int currencyId = currencyDatas.Where(it => it.Name == currencyCode).FirstOrDefault().Id;
  252. TeamRateDescAddCurrencyIdView rateDescView = new TeamRateDescAddCurrencyIdView()
  253. {
  254. CurrencyId = dataInfoView.Id,
  255. CurrencyCode = currencyCode,
  256. CurrencyName = currency2[0],
  257. Rate = decimal.Parse(currency1[1]),
  258. };
  259. teamRateDescViews.Add(rateDescView);
  260. }
  261. }
  262. #endregion
  263. if (teamRateDescViews.Count > 0)
  264. {
  265. teamRateDescViews = teamRateDescViews.OrderBy(it => it.CurrencyId).ToList();
  266. }
  267. teamRateModelInfo.TeamRates = teamRateDescViews;
  268. teamRateModels = teamRateModelInfo;
  269. }
  270. #endregion
  271. return Ok(JsonView(true, "操作成功!", teamRateModels));
  272. }
  273. else
  274. {
  275. return Ok(JsonView(false, "请输入正确的端口号! 1 Web 2 Android 3 Ios;"));
  276. }
  277. }
  278. catch (Exception ex)
  279. {
  280. return Ok(JsonView(false, ex.Message));
  281. }
  282. }
  283. /// <summary>
  284. /// 根据团组Id币种Id及类型Id查询团组汇率
  285. /// </summary>
  286. /// <param name="dto"></param>
  287. /// <returns></returns>
  288. [HttpGet, HttpPost]
  289. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  290. public async Task<IActionResult> PostCurrencyByDiid(int DiId,int CId,int CurrencyId)
  291. {
  292. try
  293. {
  294. Result setData = await _setDataRep.PostCurrencyByDiid( DiId, CId, CurrencyId); //币种类型
  295. if (setData.Code == 0)
  296. {
  297. return Ok(JsonView(true, "查询成功", setData.Data));
  298. }
  299. else
  300. {
  301. return Ok(JsonView(false, setData.Msg));
  302. }
  303. }
  304. catch (Exception)
  305. {
  306. return Ok(JsonView(false, "程序错误!"));
  307. throw;
  308. }
  309. }
  310. #endregion
  311. #region 查询页面关联Ctable
  312. /// <summary>
  313. /// 页面关联Ctable
  314. /// 根据PageId 返回 CTable Id
  315. /// </summary>
  316. /// <param name="dto"></param>
  317. /// <returns></returns>
  318. [HttpPost]
  319. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  320. public async Task<IActionResult> PostPageLinkCTable(PageLinkCTableDto dto)
  321. {
  322. try
  323. {
  324. if (dto == null)
  325. {
  326. return Ok(JsonView(false, "请求参数不能为空!"));
  327. }
  328. if (dto.PageId == 0)
  329. {
  330. return Ok(JsonView(false, "页面Id不能为0!"));
  331. }
  332. List<CTableCorrelationPageDatas> data = AppSettingsHelper.Get<CTableCorrelationPageDatas>("CTableCorrelationPageDatas");
  333. CTableCorrelationPageDatas correlationPageDatas = new CTableCorrelationPageDatas();
  334. foreach (var item in data)
  335. {
  336. if (item.PageIdDatas != null)
  337. {
  338. var pageId = item.PageIdDatas.Where(it => it == dto.PageId).FirstOrDefault();
  339. if (pageId != 0)
  340. {
  341. correlationPageDatas = item;
  342. break;
  343. }
  344. }
  345. }
  346. if (correlationPageDatas.CTableId == 0)
  347. {
  348. return Ok(JsonView(false, "您查询的页面Id,未配置AppSettings,请前往配置!"));
  349. }
  350. return Ok(JsonView(true, "操作成功",new { CTable = correlationPageDatas.CTableId }));
  351. }
  352. catch (Exception ex)
  353. {
  354. return Ok(JsonView(false, ex.Message));
  355. }
  356. }
  357. #endregion
  358. #region 会务物料单
  359. /// <summary>
  360. /// 获取会务活动列表
  361. /// </summary>
  362. /// <param name="paras"></param>
  363. /// <returns></returns>
  364. [HttpPost]
  365. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  366. public async Task<IActionResult> PostConferenceList()
  367. {
  368. List<Grp_DelegationInfo> listSource = _busRep.Query<Grp_DelegationInfo>(s => s.TeamDid == 691 && s.IsDel == 0).ToList();
  369. List<GroupNameView> viewList = new List<GroupNameView>();
  370. foreach (var group in listSource)
  371. {
  372. GroupNameView _view = new GroupNameView();
  373. _view.Id = group.Id;
  374. _view.GroupName = group.TeamName;
  375. }
  376. return Ok(JsonView(viewList));
  377. }
  378. /// <summary>
  379. /// 获取会务的采购物品计划清单
  380. /// </summary>
  381. /// <param name="ConfId">会务活动Id</param>
  382. /// <returns></returns>
  383. [HttpPost]
  384. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  385. public async Task<IActionResult> PostConfItemList(int ConfId)
  386. {
  387. Bus_ConfItemListView view = new Bus_ConfItemListView();
  388. Bus_ConfItemListInfo _confListInfo = await _busRep.Query<Bus_ConfItemListInfo>(s => s.Diid == ConfId).FirstAsync();
  389. if (_confListInfo != null)
  390. {
  391. view.TotalCost = _confListInfo.TotalCost;
  392. string sqlItem = string.Format(@" Select c.Id,c.ItemId,d.ItemName,c.[Count],c.CurrCost,c.OpRemark
  393. From Bus_ConfItem as c With(Nolock)
  394. Inner Join Res_ItemDetail as d with(Nolock) On c.ItemId=d.Id
  395. Where c.ConfListId = {0}", ConfId);
  396. List<Bus_ConfItemView> confItemList = await _busRep._sqlSugar.SqlQueryable<Bus_ConfItemView>(sqlItem).ToListAsync();
  397. view.ItemList = new List<Bus_ConfItemView>(confItemList);
  398. }
  399. else
  400. {
  401. view.ItemList = new List<Bus_ConfItemView>();
  402. view.TotalCost = 0;
  403. }
  404. return Ok(JsonView(view));
  405. }
  406. /// <summary>
  407. /// 获取会务可采购的物料集合
  408. /// </summary>
  409. /// <returns></returns>
  410. [HttpPost]
  411. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  412. public async Task<IActionResult> PostOptionalItemList()
  413. {
  414. List<OptionalBusRangeView> result = await _busRep.GetViewList_OptionalItem();
  415. return Ok(JsonView(result));
  416. }
  417. /// <summary>
  418. /// 编辑物料采购清单
  419. /// </summary>
  420. /// <returns></returns>
  421. [HttpPost]
  422. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  423. public async Task<IActionResult> PostEditOptionalItemList(JsonDtoBase jsonDto)
  424. {
  425. if (string.IsNullOrEmpty(jsonDto.Paras))
  426. {
  427. return Ok(JsonView(false, "参数为空"));
  428. }
  429. Edit_OptionalItemListDto _dto = JsonConvert.DeserializeObject<Edit_OptionalItemListDto>(jsonDto.Paras);
  430. //Edit_OptionalItemListDto _dto = System.Text.Json.JsonSerializer.Deserialize<Edit_OptionalItemListDto>(jsonDto.Paras);
  431. if (_dto.DiId < 1)
  432. {
  433. return Ok(JsonView(false, "团组Id为空"));
  434. }
  435. if (_dto.ConfItemListId < 1)
  436. {
  437. //新增
  438. int rstInsert = await _busRep.Insert_ConfItemList(_dto);
  439. return Ok(JsonView(rstInsert == 0));
  440. }
  441. else
  442. {
  443. //修改
  444. int rstUpdate = await _busRep.Edit_ConfItemList(_dto);
  445. return Ok(JsonView(rstUpdate == 0));
  446. }
  447. return Ok(JsonView(false));
  448. }
  449. /// <summary>
  450. /// 获取会务采购物料清单Excel
  451. /// </summary>
  452. /// <returns></returns>
  453. [HttpPost]
  454. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  455. public async Task<IActionResult> Excel_ConfItemList(JsonDtoBase jsonDto)
  456. {
  457. if (string.IsNullOrEmpty(jsonDto.Paras))
  458. {
  459. return Ok(JsonView(false, "参数为空"));
  460. }
  461. dynamic confList = JsonConvert.DeserializeObject<dynamic>(jsonDto.Paras);
  462. int confListId = confList.ConfListId;
  463. Bus_ConfItemListInfo _entityConfList = await _busRep.Query<Bus_ConfItemListInfo>(s => s.Id == confListId).FirstAsync();
  464. if (_entityConfList != null)
  465. {
  466. string result = new Excel_BusConfItemList().Excel(_entityConfList);
  467. }
  468. else
  469. {
  470. return Ok(JsonView(false, "请先保存数据"));
  471. }
  472. return Ok(JsonView(false));
  473. }
  474. #endregion
  475. #region 阿里云短信测试
  476. /// <summary>
  477. /// 编辑物料采购清单
  478. /// </summary>
  479. /// <returns></returns>
  480. [HttpPost]
  481. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  482. public async Task<IActionResult> AliMessageTest(string mobile)
  483. {
  484. string add2dayZH = DateTime.Now.AddDays(2).ToString("yyyy年MM月dd日");
  485. string templateParam = JsonConvert.SerializeObject(new { teams = "测试团组", date = add2dayZH });
  486. AliMessagePost.PostMessage(mobile, "泛美国际团组", "SMS_461575447", templateParam);
  487. return Ok(JsonView(true));
  488. }
  489. #endregion
  490. }
  491. }