BusinessController.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  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. #endregion
  75. #region 币种 List
  76. /// <summary>
  77. /// 币种 List
  78. /// </summary>
  79. /// <returns></returns>
  80. [HttpGet,HttpPost]
  81. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  82. public async Task<IActionResult> PostCurrencyList()
  83. {
  84. try
  85. {
  86. Result setData = await _setDataRep.GetSetDataBySTId(_setDataRep, 66); //币种类型
  87. if (setData.Code == 0)
  88. {
  89. return Ok(JsonView(true, "查询成功", setData.Data));
  90. }
  91. else
  92. {
  93. return Ok(JsonView(false, setData.Msg));
  94. }
  95. }
  96. catch (Exception)
  97. {
  98. return Ok(JsonView(false, "程序错误!"));
  99. throw;
  100. }
  101. }
  102. /// <summary>
  103. /// 团组汇率 币种 Item (来源:团组汇率)
  104. /// 根据 团组Id And 业务类型(CTable)Id
  105. /// </summary>
  106. /// <param name="portType"> 1 Web 2 Android 3 Ios; </param>
  107. /// <param name="diId"> 团组Id </param>
  108. /// <param name="CTbale"> CTableType Id </param>
  109. /// <returns></returns>
  110. [HttpPost]
  111. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  112. public async Task<IActionResult> PostGroupTeamRateByDiIdAndCTableId(GeneralTeamRateInfoDto dto)
  113. {
  114. try
  115. {
  116. if (dto == null)
  117. {
  118. return Ok(JsonView(false, "请输入参数!"));
  119. }
  120. if (dto.DiId == 0)
  121. {
  122. return Ok(JsonView(false, "请输入正确的团组Id!"));
  123. }
  124. if (dto.CTbale == 0)
  125. {
  126. return Ok(JsonView(false, "请输入正确的业务类型(CTable)Id!"));
  127. }
  128. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3 )
  129. {
  130. string teamRateInfoSql = string.Format(@"Select sd.Name,tr.* From Grp_TeamRate tr
  131. Left Join Sys_SetData sd On sd.IsDel=0 And sd.STid=16 And tr.CTable = sd.Id
  132. Where tr.IsDel = 0 And tr.DiId = {0} And tr.CTable = {1}", dto.DiId,dto.CTbale);
  133. var teamRateInfo = await _teamRateRep._sqlSugar.SqlQueryable<TeamRateInfoView>(teamRateInfoSql).ToListAsync();
  134. #region 团组汇率
  135. TeamRateModelGeneralView teamRateModels = new TeamRateModelGeneralView();
  136. List<SetDataInfoView> currencyDatas = new List<SetDataInfoView>();
  137. #region 获取所有币种
  138. string sql = string.Format(@"select * from Sys_SetData where STid = {0} and isdel = 0", 66);
  139. var DBdata = await _setDataRep.GetListBySqlWithNolockAsync(sql);
  140. if (DBdata == null || DBdata.Count == 0)
  141. {
  142. return Ok(JsonView(false, "所有币种获取失败!"));
  143. }
  144. currencyDatas = DBdata.Select(x => new SetDataInfoView
  145. {
  146. Name = x.Name,
  147. Id = x.Id,
  148. Remark = x.Remark,
  149. }).ToList();
  150. #endregion
  151. foreach (TeamRateInfoView item in teamRateInfo)
  152. {
  153. TeamRateModelGeneralView teamRateModelInfo = new TeamRateModelGeneralView();
  154. teamRateModelInfo.Id = item.Id;
  155. teamRateModelInfo.CTableId = item.CTable;
  156. teamRateModelInfo.CTableName = item.Name;
  157. List<TeamRateDescAddCurrencyIdView> teamRateDescViews = new List<TeamRateDescAddCurrencyIdView>();
  158. #region 拆分remark里的汇率
  159. if (item.Remark.Contains("|"))
  160. {
  161. string[] currencyArr = item.Remark.Split("|");
  162. foreach (string currency in currencyArr)
  163. {
  164. string[] currency1 = currency.Split(":");
  165. string[] currency2 = currency1[0].Split("(");
  166. string currencyCode = currency2[1].Replace(")", "").TrimEnd();
  167. SetDataInfoView dataInfoView = new SetDataInfoView();
  168. dataInfoView = currencyDatas.Where(it => it.Name == currencyCode).FirstOrDefault();
  169. int currencyId = currencyDatas.Where(it => it.Name == currencyCode).FirstOrDefault().Id;
  170. TeamRateDescAddCurrencyIdView rateDescView = new TeamRateDescAddCurrencyIdView()
  171. {
  172. CurrencyId = dataInfoView.Id,
  173. CurrencyCode = currencyCode,
  174. CurrencyName = currency2[0],
  175. Rate = decimal.Parse(currency1[1]),
  176. };
  177. teamRateDescViews.Add(rateDescView);
  178. }
  179. }
  180. #endregion
  181. if (teamRateDescViews.Count > 0)
  182. {
  183. teamRateDescViews = teamRateDescViews.OrderBy(it => it.CurrencyId).ToList();
  184. }
  185. teamRateModelInfo.TeamRates = teamRateDescViews;
  186. teamRateModels = teamRateModelInfo;
  187. }
  188. #endregion
  189. return Ok(JsonView(true, "操作成功!", teamRateModels));
  190. }
  191. else
  192. {
  193. return Ok(JsonView(false, "请输入正确的端口号! 1 Web 2 Android 3 Ios;"));
  194. }
  195. }
  196. catch (Exception ex)
  197. {
  198. return Ok(JsonView(false, ex.Message));
  199. }
  200. }
  201. /// <summary>
  202. /// 根据团组Id币种Id及类型Id查询团组汇率
  203. /// </summary>
  204. /// <param name="dto"></param>
  205. /// <returns></returns>
  206. [HttpGet, HttpPost]
  207. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  208. public async Task<IActionResult> PostCurrencyByDiid(int DiId,int CId,int CurrencyId)
  209. {
  210. try
  211. {
  212. Result setData = await _setDataRep.PostCurrencyByDiid( DiId, CId, CurrencyId); //币种类型
  213. if (setData.Code == 0)
  214. {
  215. return Ok(JsonView(true, "查询成功", setData.Data));
  216. }
  217. else
  218. {
  219. return Ok(JsonView(false, setData.Msg));
  220. }
  221. }
  222. catch (Exception)
  223. {
  224. return Ok(JsonView(false, "程序错误!"));
  225. throw;
  226. }
  227. }
  228. #endregion
  229. #region 查询页面关联Ctable
  230. /// <summary>
  231. /// 页面关联Ctable
  232. /// 根据PageId 返回 CTable Id
  233. /// </summary>
  234. /// <param name="dto"></param>
  235. /// <returns></returns>
  236. [HttpPost]
  237. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  238. public async Task<IActionResult> PostPageLinkCTable(PageLinkCTableDto dto)
  239. {
  240. try
  241. {
  242. if (dto == null)
  243. {
  244. return Ok(JsonView(false, "请求参数不能为空!"));
  245. }
  246. if (dto.PageId == 0)
  247. {
  248. return Ok(JsonView(false, "页面Id不能为0!"));
  249. }
  250. List<CTableCorrelationPageDatas> data = AppSettingsHelper.Get<CTableCorrelationPageDatas>("CTableCorrelationPageDatas");
  251. CTableCorrelationPageDatas correlationPageDatas = new CTableCorrelationPageDatas();
  252. foreach (var item in data)
  253. {
  254. if (item.PageIdDatas != null)
  255. {
  256. var pageId = item.PageIdDatas.Where(it => it == dto.PageId).FirstOrDefault();
  257. if (pageId != 0)
  258. {
  259. correlationPageDatas = item;
  260. break;
  261. }
  262. }
  263. }
  264. if (correlationPageDatas.CTableId == 0)
  265. {
  266. return Ok(JsonView(false, "您查询的页面Id,未配置AppSettings,请前往配置!"));
  267. }
  268. return Ok(JsonView(true, "操作成功",new { CTable = correlationPageDatas.CTableId }));
  269. }
  270. catch (Exception ex)
  271. {
  272. return Ok(JsonView(false, ex.Message));
  273. }
  274. }
  275. #endregion
  276. #region 会务物料单
  277. /// <summary>
  278. /// 获取会务活动列表
  279. /// </summary>
  280. /// <param name="paras"></param>
  281. /// <returns></returns>
  282. [HttpPost]
  283. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  284. public async Task<IActionResult> PostConferenceList()
  285. {
  286. List<Grp_DelegationInfo> listSource = _busRep.Query<Grp_DelegationInfo>(s => s.TeamDid == 691 && s.IsDel == 0).ToList();
  287. List<GroupNameView> viewList = new List<GroupNameView>();
  288. foreach (var group in listSource)
  289. {
  290. GroupNameView _view = new GroupNameView();
  291. _view.Id = group.Id;
  292. _view.GroupName = group.TeamName;
  293. }
  294. return Ok(JsonView(viewList));
  295. }
  296. /// <summary>
  297. /// 获取会务的采购物品计划清单
  298. /// </summary>
  299. /// <param name="ConfId">会务活动Id</param>
  300. /// <returns></returns>
  301. [HttpPost]
  302. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  303. public async Task<IActionResult> PostConfItemList(int ConfId)
  304. {
  305. Bus_ConfItemListView view = new Bus_ConfItemListView();
  306. Bus_ConfItemListInfo _confListInfo = await _busRep.Query<Bus_ConfItemListInfo>(s => s.Diid == ConfId).FirstAsync();
  307. if (_confListInfo != null)
  308. {
  309. view.TotalCost = _confListInfo.TotalCost;
  310. string sqlItem = string.Format(@" Select c.Id,c.ItemId,d.ItemName,c.[Count],c.CurrCost,c.OpRemark
  311. From Bus_ConfItem as c With(Nolock)
  312. Inner Join Res_ItemDetail as d with(Nolock) On c.ItemId=d.Id
  313. Where c.ConfListId = {0}", ConfId);
  314. List<Bus_ConfItemView> confItemList = await _busRep._sqlSugar.SqlQueryable<Bus_ConfItemView>(sqlItem).ToListAsync();
  315. view.ItemList = new List<Bus_ConfItemView>(confItemList);
  316. }
  317. else
  318. {
  319. view.ItemList = new List<Bus_ConfItemView>();
  320. view.TotalCost = 0;
  321. }
  322. return Ok(JsonView(view));
  323. }
  324. /// <summary>
  325. /// 获取会务可采购的物料集合
  326. /// </summary>
  327. /// <returns></returns>
  328. [HttpPost]
  329. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  330. public async Task<IActionResult> PostOptionalItemList()
  331. {
  332. List<OptionalBusRangeView> result = await _busRep.GetViewList_OptionalItem();
  333. return Ok(JsonView(result));
  334. }
  335. /// <summary>
  336. /// 编辑物料采购清单
  337. /// </summary>
  338. /// <returns></returns>
  339. [HttpPost]
  340. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  341. public async Task<IActionResult> PostEditOptionalItemList(JsonDtoBase jsonDto)
  342. {
  343. if (string.IsNullOrEmpty(jsonDto.Paras))
  344. {
  345. return Ok(JsonView(false, "参数为空"));
  346. }
  347. Edit_OptionalItemListDto _dto = JsonConvert.DeserializeObject<Edit_OptionalItemListDto>(jsonDto.Paras);
  348. //Edit_OptionalItemListDto _dto = System.Text.Json.JsonSerializer.Deserialize<Edit_OptionalItemListDto>(jsonDto.Paras);
  349. if (_dto.DiId < 1)
  350. {
  351. return Ok(JsonView(false, "团组Id为空"));
  352. }
  353. if (_dto.ConfItemListId < 1)
  354. {
  355. //新增
  356. int rstInsert = await _busRep.Insert_ConfItemList(_dto);
  357. return Ok(JsonView(rstInsert == 0));
  358. }
  359. else
  360. {
  361. //修改
  362. int rstUpdate = await _busRep.Edit_ConfItemList(_dto);
  363. return Ok(JsonView(rstUpdate == 0));
  364. }
  365. return Ok(JsonView(false));
  366. }
  367. /// <summary>
  368. /// 获取会务采购物料清单Excel
  369. /// </summary>
  370. /// <returns></returns>
  371. [HttpPost]
  372. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  373. public async Task<IActionResult> Excel_ConfItemList(JsonDtoBase jsonDto)
  374. {
  375. if (string.IsNullOrEmpty(jsonDto.Paras))
  376. {
  377. return Ok(JsonView(false, "参数为空"));
  378. }
  379. dynamic confList = JsonConvert.DeserializeObject<dynamic>(jsonDto.Paras);
  380. int confListId = confList.ConfListId;
  381. Bus_ConfItemListInfo _entityConfList = await _busRep.Query<Bus_ConfItemListInfo>(s => s.Id == confListId).FirstAsync();
  382. if (_entityConfList != null)
  383. {
  384. string result = new Excel_BusConfItemList().Excel(_entityConfList);
  385. }
  386. else
  387. {
  388. return Ok(JsonView(false, "请先保存数据"));
  389. }
  390. return Ok(JsonView(false));
  391. }
  392. #endregion
  393. #region 阿里云短信测试
  394. /// <summary>
  395. /// 编辑物料采购清单
  396. /// </summary>
  397. /// <returns></returns>
  398. [HttpPost]
  399. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  400. public async Task<IActionResult> AliMessageTest(string mobile)
  401. {
  402. string add2dayZH = DateTime.Now.AddDays(2).ToString("yyyy年MM月dd日");
  403. string templateParam = JsonConvert.SerializeObject(new { teams = "测试团组", date = add2dayZH });
  404. AliMessagePost.PostMessage(mobile, "泛美国际团组", "SMS_461575447", templateParam);
  405. return Ok(JsonView(true));
  406. }
  407. #endregion
  408. }
  409. }