BusinessController.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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.Groups;
  8. using OASystem.Domain.Entities.Business;
  9. using OASystem.Domain.Entities.Groups;
  10. using OASystem.Domain.Entities.Resource;
  11. using OASystem.Domain.ViewModels.Business;
  12. using OASystem.Domain.ViewModels.Financial;
  13. using OASystem.Domain.ViewModels.Groups;
  14. using OASystem.Infrastructure.Repositories.Business;
  15. using OASystem.Infrastructure.Repositories.Groups;
  16. using OASystem.Infrastructure.Repositories.System;
  17. using Org.BouncyCastle.Asn1.Mozilla;
  18. namespace OASystem.API.Controllers
  19. {
  20. /// <summary>
  21. /// 通用业务操作
  22. /// </summary>
  23. [Route("api/[controller]/[action]")]
  24. public class BusinessController : ControllerBase
  25. {
  26. private readonly IMapper _mapper;
  27. private readonly CommonBusRepository _busRep;
  28. private readonly SetDataRepository _setDataRep;
  29. private readonly DelegationInfoRepository _groupRep;
  30. private readonly TeamRateRepository _teamRateRep;
  31. public BusinessController( IMapper mapper, CommonBusRepository busRep, SetDataRepository setDataRep, DelegationInfoRepository groupRep, TeamRateRepository teamRateRep)
  32. {
  33. _mapper = mapper;
  34. _busRep = busRep;
  35. _setDataRep = setDataRep;
  36. _groupRep = groupRep;
  37. _teamRateRep = teamRateRep;
  38. }
  39. #region 团组信息 团组详情
  40. /// <summary>
  41. /// 团组信息 团组详情
  42. /// </summary>
  43. /// <param name="dto">团组info请求dto</param>
  44. /// <returns></returns>
  45. [HttpPost]
  46. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  47. public async Task<IActionResult> PostShareGroupInfo(ShareGroupInfoDto dto)
  48. {
  49. var groupData = await _groupRep.PostShareGroupInfo(dto);
  50. if (groupData.Code != 0)
  51. {
  52. return Ok(JsonView(false, groupData.Msg));
  53. }
  54. return Ok(JsonView(groupData.Data));
  55. }
  56. /// <summary>
  57. /// 团组信息 团组名称 List
  58. /// </summary>
  59. /// <param name="dto"></param>
  60. /// <returns></returns>
  61. [HttpPost]
  62. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  63. public async Task<IActionResult> GetGroupNameList(GroupNameDto dto)
  64. {
  65. var groupData = await _groupRep.GetGroupNameList(dto);
  66. if (groupData.Code != 0)
  67. {
  68. return Ok(JsonView(false, groupData.Msg));
  69. }
  70. return Ok(JsonView(groupData.Data, groupData.Data.Count));
  71. }
  72. #endregion
  73. #region 币种 List
  74. /// <summary>
  75. /// 币种 List
  76. /// </summary>
  77. /// <param name="dto"></param>
  78. /// <returns></returns>
  79. [HttpGet,HttpPost]
  80. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  81. public async Task<IActionResult> PostCurrencyList()
  82. {
  83. try
  84. {
  85. Result setData = await _setDataRep.GetSetDataBySTId(_setDataRep, 66); //币种类型
  86. if (setData.Code == 0)
  87. {
  88. return Ok(JsonView(true, "查询成功", setData.Data));
  89. }
  90. else
  91. {
  92. return Ok(JsonView(false, setData.Msg));
  93. }
  94. }
  95. catch (Exception)
  96. {
  97. return Ok(JsonView(false, "程序错误!"));
  98. throw;
  99. }
  100. }
  101. /// <summary>
  102. /// 团组汇率 币种 Item (来源:团组汇率)
  103. /// 根据 团组Id And 业务类型(CTable)Id
  104. /// </summary>
  105. /// <param name="portType"> 1 Web 2 Android 3 Ios; </param>
  106. /// <param name="diId"> 团组Id </param>
  107. /// <param name="CTbale"> CTableType Id </param>
  108. /// <returns></returns>
  109. [HttpPost]
  110. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  111. public async Task<IActionResult> PostGroupTeamRateByDiIdAndCTableId(int portType, int diId,int CTbale)
  112. {
  113. try
  114. {
  115. if (diId == 0)
  116. {
  117. return Ok(JsonView(false, "请输入正确的团组Id!"));
  118. }
  119. if (CTbale == 0)
  120. {
  121. return Ok(JsonView(false, "请输入正确的业务类型(CTable)Id!"));
  122. }
  123. if (portType == 1 || portType == 2 || portType == 3 )
  124. {
  125. string teamRateInfoSql = string.Format(@"Select sd.Name,tr.* From Grp_TeamRate tr
  126. Left Join Sys_SetData sd On sd.IsDel=0 And sd.STid=16 And tr.CTable = sd.Id
  127. Where tr.IsDel = 0 And tr.DiId = {0} And tr.CTable = {1}", diId,CTbale);
  128. var teamRateInfo = await _teamRateRep._sqlSugar.SqlQueryable<TeamRateInfoView>(teamRateInfoSql).ToListAsync();
  129. #region 团组汇率
  130. TeamRateModelGeneralView teamRateModels = new TeamRateModelGeneralView();
  131. List<SetDataInfoView> currencyDatas = new List<SetDataInfoView>();
  132. #region 获取所有币种
  133. string sql = string.Format(@"select * from Sys_SetData where STid = {0} and isdel = 0", 66);
  134. var DBdata = await _setDataRep.GetListBySqlWithNolockAsync(sql);
  135. if (DBdata == null || DBdata.Count == 0)
  136. {
  137. return Ok(JsonView(false, "所有币种获取失败!"));
  138. }
  139. currencyDatas = DBdata.Select(x => new SetDataInfoView
  140. {
  141. Name = x.Name,
  142. Id = x.Id,
  143. Remark = x.Remark,
  144. }).ToList();
  145. #endregion
  146. foreach (TeamRateInfoView item in teamRateInfo)
  147. {
  148. TeamRateModelGeneralView teamRateModelInfo = new TeamRateModelGeneralView();
  149. teamRateModelInfo.Id = item.Id;
  150. teamRateModelInfo.CTableId = item.CTable;
  151. teamRateModelInfo.CTableName = item.Name;
  152. List<TeamRateDescAddCurrencyIdView> teamRateDescViews = new List<TeamRateDescAddCurrencyIdView>();
  153. #region 拆分remark里的汇率
  154. if (item.Remark.Contains("|"))
  155. {
  156. string[] currencyArr = item.Remark.Split("|");
  157. foreach (string currency in currencyArr)
  158. {
  159. string[] currency1 = currency.Split(":");
  160. string[] currency2 = currency1[0].Split("(");
  161. string currencyCode = currency2[1].Replace(")", "").TrimEnd();
  162. SetDataInfoView dataInfoView = new SetDataInfoView();
  163. dataInfoView = currencyDatas.Where(it => it.Name == currencyCode).FirstOrDefault();
  164. int currencyId = currencyDatas.Where(it => it.Name == currencyCode).FirstOrDefault().Id;
  165. TeamRateDescAddCurrencyIdView rateDescView = new TeamRateDescAddCurrencyIdView()
  166. {
  167. CurrencyId = dataInfoView.Id,
  168. CurrencyCode = currencyCode,
  169. CurrencyName = currency2[0],
  170. Rate = decimal.Parse(currency1[1]),
  171. };
  172. teamRateDescViews.Add(rateDescView);
  173. }
  174. }
  175. #endregion
  176. if (teamRateDescViews.Count > 0)
  177. {
  178. teamRateDescViews = teamRateDescViews.OrderBy(it => it.CurrencyId).ToList();
  179. }
  180. teamRateModelInfo.TeamRates = teamRateDescViews;
  181. teamRateModels = teamRateModelInfo;
  182. }
  183. #endregion
  184. return Ok(JsonView(true, "操作成功!", teamRateModels));
  185. }
  186. else
  187. {
  188. return Ok(JsonView(false, "请输入正确的端口号! 1 Web 2 Android 3 Ios;"));
  189. }
  190. }
  191. catch (Exception ex)
  192. {
  193. return Ok(JsonView(false, ex.Message));
  194. }
  195. }
  196. /// <summary>
  197. /// 根据团组Id币种Id及类型Id查询团组汇率
  198. /// </summary>
  199. /// <param name="dto"></param>
  200. /// <returns></returns>
  201. [HttpGet, HttpPost]
  202. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  203. public async Task<IActionResult> PostCurrencyByDiid(int DiId,int CId,int CurrencyId)
  204. {
  205. try
  206. {
  207. Result setData = await _setDataRep.PostCurrencyByDiid( DiId, CId, CurrencyId); //币种类型
  208. if (setData.Code == 0)
  209. {
  210. return Ok(JsonView(true, "查询成功", setData.Data));
  211. }
  212. else
  213. {
  214. return Ok(JsonView(false, setData.Msg));
  215. }
  216. }
  217. catch (Exception)
  218. {
  219. return Ok(JsonView(false, "程序错误!"));
  220. throw;
  221. }
  222. }
  223. #endregion
  224. #region 查询页面操作权限
  225. /// <summary>
  226. /// 查询页面操作权限 根据 用户Id 及 页面ID
  227. /// </summary>
  228. /// <param name="userId">用户Id</param>
  229. /// <param name="pageId">页面Id</param>
  230. /// <param name="portType">端口类型</param>
  231. /// <returns></returns>
  232. [HttpGet, HttpPost]
  233. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  234. public async Task<IActionResult> PostPageOperationPermission(int userId,int pageId,int portType)
  235. {
  236. try
  237. {
  238. Result setData = await _setDataRep.GetSetDataBySTId(_setDataRep, 66); //币种类型
  239. if (setData.Code == 0)
  240. {
  241. return Ok(JsonView(true, "查询成功", setData.Data));
  242. }
  243. else
  244. {
  245. return Ok(JsonView(false, setData.Msg));
  246. }
  247. }
  248. catch (Exception)
  249. {
  250. return Ok(JsonView(false, "程序错误!"));
  251. throw;
  252. }
  253. }
  254. #endregion
  255. #region 会务物料单
  256. /// <summary>
  257. /// 获取会务活动列表
  258. /// </summary>
  259. /// <param name="paras"></param>
  260. /// <returns></returns>
  261. [HttpPost]
  262. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  263. public async Task<IActionResult> PostConferenceList()
  264. {
  265. List<Grp_DelegationInfo> listSource = _busRep.Query<Grp_DelegationInfo>(s => s.TeamDid == 691 && s.IsDel == 0).ToList();
  266. List<GroupNameView> viewList = new List<GroupNameView>();
  267. foreach (var group in listSource)
  268. {
  269. GroupNameView _view = new GroupNameView();
  270. _view.Id = group.Id;
  271. _view.GroupName = group.TeamName;
  272. }
  273. return Ok(JsonView(viewList));
  274. }
  275. /// <summary>
  276. /// 获取会务的采购物品计划清单
  277. /// </summary>
  278. /// <param name="ConfId">会务活动Id</param>
  279. /// <returns></returns>
  280. [HttpPost]
  281. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  282. public async Task<IActionResult> PostConfItemList(int ConfId)
  283. {
  284. Bus_ConfItemListView view = new Bus_ConfItemListView();
  285. Bus_ConfItemListInfo _confListInfo = await _busRep.Query<Bus_ConfItemListInfo>(s => s.Diid == ConfId).FirstAsync();
  286. if (_confListInfo != null)
  287. {
  288. view.TotalCost = _confListInfo.TotalCost;
  289. string sqlItem = string.Format(@" Select c.Id,c.ItemId,d.ItemName,c.[Count],c.CurrCost,c.OpRemark
  290. From Bus_ConfItem as c With(Nolock)
  291. Inner Join Res_ItemDetail as d with(Nolock) On c.ItemId=d.Id
  292. Where c.ConfListId = {0}", ConfId);
  293. List<Bus_ConfItemView> confItemList = await _busRep._sqlSugar.SqlQueryable<Bus_ConfItemView>(sqlItem).ToListAsync();
  294. view.ItemList = new List<Bus_ConfItemView>(confItemList);
  295. }
  296. else
  297. {
  298. view.ItemList = new List<Bus_ConfItemView>();
  299. view.TotalCost = 0;
  300. }
  301. return Ok(JsonView(view));
  302. }
  303. /// <summary>
  304. /// 获取会务可采购的物料集合
  305. /// </summary>
  306. /// <returns></returns>
  307. [HttpPost]
  308. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  309. public async Task<IActionResult> PostOptionalItemList()
  310. {
  311. List<OptionalBusRangeView> result = await _busRep.GetViewList_OptionalItem();
  312. return Ok(JsonView(result));
  313. }
  314. /// <summary>
  315. /// 编辑物料采购清单
  316. /// </summary>
  317. /// <returns></returns>
  318. [HttpPost]
  319. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  320. public async Task<IActionResult> PostEditOptionalItemList(JsonDtoBase jsonDto)
  321. {
  322. if (string.IsNullOrEmpty(jsonDto.Paras))
  323. {
  324. return Ok(JsonView(false, "参数为空"));
  325. }
  326. Edit_OptionalItemListDto _dto = JsonConvert.DeserializeObject<Edit_OptionalItemListDto>(jsonDto.Paras);
  327. //Edit_OptionalItemListDto _dto = System.Text.Json.JsonSerializer.Deserialize<Edit_OptionalItemListDto>(jsonDto.Paras);
  328. if (_dto.DiId < 1)
  329. {
  330. return Ok(JsonView(false, "团组Id为空"));
  331. }
  332. if (_dto.ConfItemListId < 1)
  333. {
  334. //新增
  335. int rstInsert = await _busRep.Insert_ConfItemList(_dto);
  336. return Ok(JsonView(rstInsert == 0));
  337. }
  338. else
  339. {
  340. //修改
  341. int rstUpdate = await _busRep.Edit_ConfItemList(_dto);
  342. return Ok(JsonView(rstUpdate == 0));
  343. }
  344. return Ok(JsonView(false));
  345. }
  346. /// <summary>
  347. /// 获取会务采购物料清单Excel
  348. /// </summary>
  349. /// <returns></returns>
  350. [HttpPost]
  351. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  352. public async Task<IActionResult> Excel_ConfItemList(JsonDtoBase jsonDto)
  353. {
  354. if (string.IsNullOrEmpty(jsonDto.Paras))
  355. {
  356. return Ok(JsonView(false, "参数为空"));
  357. }
  358. dynamic confList = JsonConvert.DeserializeObject<dynamic>(jsonDto.Paras);
  359. int confListId = confList.ConfListId;
  360. Bus_ConfItemListInfo _entityConfList = await _busRep.Query<Bus_ConfItemListInfo>(s => s.Id == confListId).FirstAsync();
  361. if (_entityConfList != null)
  362. {
  363. string result = new Excel_BusConfItemList().Excel(_entityConfList);
  364. }
  365. else
  366. {
  367. return Ok(JsonView(false, "请先保存数据"));
  368. }
  369. return Ok(JsonView(false));
  370. }
  371. #endregion
  372. #region 阿里云短信测试
  373. /// <summary>
  374. /// 编辑物料采购清单
  375. /// </summary>
  376. /// <returns></returns>
  377. [HttpPost]
  378. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  379. public async Task<IActionResult> AliMessageTest(string mobile)
  380. {
  381. string add2dayZH = DateTime.Now.AddDays(2).ToString("yyyy年MM月dd日");
  382. string templateParam = JsonConvert.SerializeObject(new { teams = "测试团组", date = add2dayZH });
  383. AliMessagePost.PostMessage(mobile, "泛美国际团组", "SMS_461575447", templateParam);
  384. return Ok(JsonView(true));
  385. }
  386. #endregion
  387. }
  388. }