BusinessController.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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 查询页面操作权限
  230. /// <summary>
  231. /// 查询页面操作权限 根据 用户Id 及 页面ID
  232. /// </summary>
  233. /// <param name="userId">用户Id</param>
  234. /// <param name="pageId">页面Id</param>
  235. /// <param name="portType">端口类型</param>
  236. /// <returns></returns>
  237. [HttpGet, HttpPost]
  238. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  239. public async Task<IActionResult> PostPageOperationPermission(int userId,int pageId,int portType)
  240. {
  241. try
  242. {
  243. Result setData = await _setDataRep.GetSetDataBySTId(_setDataRep, 66); //币种类型
  244. if (setData.Code == 0)
  245. {
  246. return Ok(JsonView(true, "查询成功", setData.Data));
  247. }
  248. else
  249. {
  250. return Ok(JsonView(false, setData.Msg));
  251. }
  252. }
  253. catch (Exception)
  254. {
  255. return Ok(JsonView(false, "程序错误!"));
  256. }
  257. }
  258. #endregion
  259. #region 会务物料单
  260. /// <summary>
  261. /// 获取会务活动列表
  262. /// </summary>
  263. /// <param name="paras"></param>
  264. /// <returns></returns>
  265. [HttpPost]
  266. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  267. public async Task<IActionResult> PostConferenceList()
  268. {
  269. List<Grp_DelegationInfo> listSource = _busRep.Query<Grp_DelegationInfo>(s => s.TeamDid == 691 && s.IsDel == 0).ToList();
  270. List<GroupNameView> viewList = new List<GroupNameView>();
  271. foreach (var group in listSource)
  272. {
  273. GroupNameView _view = new GroupNameView();
  274. _view.Id = group.Id;
  275. _view.GroupName = group.TeamName;
  276. }
  277. return Ok(JsonView(viewList));
  278. }
  279. /// <summary>
  280. /// 获取会务的采购物品计划清单
  281. /// </summary>
  282. /// <param name="ConfId">会务活动Id</param>
  283. /// <returns></returns>
  284. [HttpPost]
  285. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  286. public async Task<IActionResult> PostConfItemList(int ConfId)
  287. {
  288. Bus_ConfItemListView view = new Bus_ConfItemListView();
  289. Bus_ConfItemListInfo _confListInfo = await _busRep.Query<Bus_ConfItemListInfo>(s => s.Diid == ConfId).FirstAsync();
  290. if (_confListInfo != null)
  291. {
  292. view.TotalCost = _confListInfo.TotalCost;
  293. string sqlItem = string.Format(@" Select c.Id,c.ItemId,d.ItemName,c.[Count],c.CurrCost,c.OpRemark
  294. From Bus_ConfItem as c With(Nolock)
  295. Inner Join Res_ItemDetail as d with(Nolock) On c.ItemId=d.Id
  296. Where c.ConfListId = {0}", ConfId);
  297. List<Bus_ConfItemView> confItemList = await _busRep._sqlSugar.SqlQueryable<Bus_ConfItemView>(sqlItem).ToListAsync();
  298. view.ItemList = new List<Bus_ConfItemView>(confItemList);
  299. }
  300. else
  301. {
  302. view.ItemList = new List<Bus_ConfItemView>();
  303. view.TotalCost = 0;
  304. }
  305. return Ok(JsonView(view));
  306. }
  307. /// <summary>
  308. /// 获取会务可采购的物料集合
  309. /// </summary>
  310. /// <returns></returns>
  311. [HttpPost]
  312. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  313. public async Task<IActionResult> PostOptionalItemList()
  314. {
  315. List<OptionalBusRangeView> result = await _busRep.GetViewList_OptionalItem();
  316. return Ok(JsonView(result));
  317. }
  318. /// <summary>
  319. /// 编辑物料采购清单
  320. /// </summary>
  321. /// <returns></returns>
  322. [HttpPost]
  323. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  324. public async Task<IActionResult> PostEditOptionalItemList(JsonDtoBase jsonDto)
  325. {
  326. if (string.IsNullOrEmpty(jsonDto.Paras))
  327. {
  328. return Ok(JsonView(false, "参数为空"));
  329. }
  330. Edit_OptionalItemListDto _dto = JsonConvert.DeserializeObject<Edit_OptionalItemListDto>(jsonDto.Paras);
  331. //Edit_OptionalItemListDto _dto = System.Text.Json.JsonSerializer.Deserialize<Edit_OptionalItemListDto>(jsonDto.Paras);
  332. if (_dto.DiId < 1)
  333. {
  334. return Ok(JsonView(false, "团组Id为空"));
  335. }
  336. if (_dto.ConfItemListId < 1)
  337. {
  338. //新增
  339. int rstInsert = await _busRep.Insert_ConfItemList(_dto);
  340. return Ok(JsonView(rstInsert == 0));
  341. }
  342. else
  343. {
  344. //修改
  345. int rstUpdate = await _busRep.Edit_ConfItemList(_dto);
  346. return Ok(JsonView(rstUpdate == 0));
  347. }
  348. return Ok(JsonView(false));
  349. }
  350. /// <summary>
  351. /// 获取会务采购物料清单Excel
  352. /// </summary>
  353. /// <returns></returns>
  354. [HttpPost]
  355. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  356. public async Task<IActionResult> Excel_ConfItemList(JsonDtoBase jsonDto)
  357. {
  358. if (string.IsNullOrEmpty(jsonDto.Paras))
  359. {
  360. return Ok(JsonView(false, "参数为空"));
  361. }
  362. dynamic confList = JsonConvert.DeserializeObject<dynamic>(jsonDto.Paras);
  363. int confListId = confList.ConfListId;
  364. Bus_ConfItemListInfo _entityConfList = await _busRep.Query<Bus_ConfItemListInfo>(s => s.Id == confListId).FirstAsync();
  365. if (_entityConfList != null)
  366. {
  367. string result = new Excel_BusConfItemList().Excel(_entityConfList);
  368. }
  369. else
  370. {
  371. return Ok(JsonView(false, "请先保存数据"));
  372. }
  373. return Ok(JsonView(false));
  374. }
  375. #endregion
  376. #region 阿里云短信测试
  377. /// <summary>
  378. /// 编辑物料采购清单
  379. /// </summary>
  380. /// <returns></returns>
  381. [HttpPost]
  382. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  383. public async Task<IActionResult> AliMessageTest(string mobile)
  384. {
  385. string add2dayZH = DateTime.Now.AddDays(2).ToString("yyyy年MM月dd日");
  386. string templateParam = JsonConvert.SerializeObject(new { teams = "测试团组", date = add2dayZH });
  387. AliMessagePost.PostMessage(mobile, "泛美国际团组", "SMS_461575447", templateParam);
  388. return Ok(JsonView(true));
  389. }
  390. #endregion
  391. }
  392. }