BusinessController.cs 22 KB

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