BusinessController.cs 19 KB

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