BusinessController.cs 18 KB

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