BusinessController.cs 22 KB

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