BusinessController.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. using OASystem.API.OAMethodLib;
  2. using OASystem.API.OAMethodLib.ALiYun;
  3. using OASystem.API.OAMethodLib.ExcelOutput;
  4. using OASystem.Domain.Dtos.Business;
  5. using OASystem.Domain.Dtos.CRM;
  6. using OASystem.Domain.Dtos.FileDto;
  7. using OASystem.Domain.Dtos.Financial;
  8. using OASystem.Domain.Dtos.Groups;
  9. using OASystem.Domain.Entities.Business;
  10. using OASystem.Domain.Entities.Customer;
  11. using OASystem.Domain.Entities.Groups;
  12. using OASystem.Domain.ViewModels.Business;
  13. using OASystem.Domain.ViewModels.CRM;
  14. using OASystem.Domain.ViewModels.Groups;
  15. using OASystem.Infrastructure.Repositories.Business;
  16. using OASystem.Infrastructure.Repositories.CRM;
  17. using OASystem.Infrastructure.Repositories.Groups;
  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. private readonly TableOperationRecordRepository _TableOperationRecordRep;
  32. public BusinessController(IMapper mapper, CommonBusRepository busRep, SetDataRepository setDataRep, DelegationInfoRepository groupRep, TeamRateRepository teamRateRep,
  33. TableOperationRecordRepository tableOperationRecordRep)
  34. {
  35. _mapper = mapper;
  36. _busRep = busRep;
  37. _setDataRep = setDataRep;
  38. _groupRep = groupRep;
  39. _teamRateRep = teamRateRep;
  40. _TableOperationRecordRep = tableOperationRecordRep;
  41. }
  42. #region 团组信息
  43. /// <summary>
  44. /// 团组信息
  45. /// 团组简略详情
  46. /// </summary>
  47. /// <param name="dto">团组info请求dto</param>
  48. /// <returns></returns>
  49. [HttpPost]
  50. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  51. public async Task<IActionResult> PostShareGroupInfo(ShareGroupInfoDto dto)
  52. {
  53. try
  54. {
  55. var groupData = await _groupRep.PostShareGroupInfo(dto);
  56. if (groupData.Code != 0)
  57. {
  58. return Ok(JsonView(false, groupData.Msg));
  59. }
  60. return Ok(JsonView(groupData.Data));
  61. }
  62. catch (Exception ex)
  63. {
  64. return Ok(JsonView(false, ex.Message));
  65. }
  66. }
  67. /// <summary>
  68. /// 团组信息 团组名称 List
  69. /// </summary>
  70. /// <param name="dto"></param>
  71. /// <returns></returns>
  72. [HttpPost]
  73. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  74. public async Task<IActionResult> GetGroupNameList(GroupNameDto dto)
  75. {
  76. var groupData = await _groupRep.GetGroupNameList(dto);
  77. if (groupData.Code != 0)
  78. {
  79. return Ok(JsonView(false, groupData.Msg));
  80. }
  81. return Ok(JsonView(groupData.Data, groupData.Data.Count));
  82. }
  83. /// <summary>
  84. /// 团组信息 团组名称 Page List
  85. /// </summary>
  86. /// <param name="dto"></param>
  87. /// <returns></returns>
  88. [HttpPost]
  89. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  90. public async Task<IActionResult> PostGroupNameScreen(GroupNameScreenDto dto)
  91. {
  92. //验证
  93. var validator = new GroupNameScreenDtoFoaValidator();
  94. var validatorRes = await validator.ValidateAsync(dto);
  95. if (!validatorRes.IsValid)
  96. {
  97. var errors = new StringBuilder();
  98. foreach (var error in validatorRes.Errors) errors.AppendLine(error.ErrorMessage);
  99. return Ok(JsonView(false, errors.ToString()));
  100. }
  101. //获取数据
  102. var res = await _groupRep.GetGroupNameList(dto.PortType, dto.PageIndex, dto.PageSize, dto.groupName, dto.userId);
  103. return Ok(res);
  104. }
  105. /// <summary>
  106. /// 获取团组指向分类
  107. /// </summary>
  108. /// <param name="_dto">参数Json字符串</param>
  109. /// <returns></returns>
  110. [HttpPost]
  111. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  112. public async Task<IActionResult> PostGroupDirectionalClassificationInit()
  113. {
  114. Result result = new Result();
  115. result = await _setDataRep.GetSetDataBySTId(_setDataRep, 16); //团组指向分类
  116. if (result.Code != 0)
  117. {
  118. return Ok(JsonView(false, "获取失败!"));
  119. }
  120. List<SetDataInfoView> _view1 = JsonConvert.DeserializeObject<List<SetDataInfoView>>(JsonConvert.SerializeObject(result.Data));
  121. SetDataInfoView xc_view = new SetDataInfoView();//77 行程 //移除行程
  122. xc_view = _view1.Where(it => it.Id == 77).FirstOrDefault();
  123. if (xc_view != null) { _view1.Remove(xc_view); };
  124. List<SetDataInfoView> _view = new List<SetDataInfoView>();
  125. //_view.Insert(0, new SetDataInfoView { Id = -1, Name = "所有模块" });
  126. SetDataInfoView qz_view = new SetDataInfoView();//80 签证
  127. qz_view = _view1.Where(it => it.Id == 80).FirstOrDefault();
  128. if (qz_view != null) { _view.Insert(0, qz_view); _view1.Remove(qz_view); };
  129. SetDataInfoView jpyd_view = new SetDataInfoView();//85 机票预订
  130. jpyd_view = _view1.Where(it => it.Id == 85).FirstOrDefault();
  131. if (jpyd_view != null) { _view.Insert(1, jpyd_view); _view1.Remove(jpyd_view); };
  132. SetDataInfoView jdyd_view = new SetDataInfoView();//76 酒店预订
  133. jdyd_view = _view1.Where(it => it.Id == 76).FirstOrDefault();
  134. if (jdyd_view != null) { _view.Insert(2, jdyd_view); _view1.Remove(jdyd_view); };
  135. SetDataInfoView jdzc_view = new SetDataInfoView();//751 酒店早餐
  136. jdzc_view = _view1.Where(it => it.Id == 751).FirstOrDefault();
  137. if (jdzc_view != null)
  138. {
  139. _view1.Remove(jdzc_view);
  140. //_view.Insert(3, jdzc_view); _view1.Remove(jdzc_view);
  141. };
  142. SetDataInfoView cdy_view = new SetDataInfoView();//79 车/导游地接
  143. cdy_view = _view1.Where(it => it.Id == 79).FirstOrDefault();
  144. if (cdy_view != null) { _view.Insert(3, cdy_view); _view1.Remove(cdy_view); };
  145. SetDataInfoView yqgw_view = new SetDataInfoView();//81 邀请/公务活动
  146. yqgw_view = _view1.Where(it => it.Id == 81).FirstOrDefault();
  147. if (yqgw_view != null) { _view.Insert(4, yqgw_view); _view1.Remove(yqgw_view); };
  148. SetDataInfoView bx_view = new SetDataInfoView();//82 团组客户保险
  149. bx_view = _view1.Where(it => it.Id == 82).FirstOrDefault();
  150. if (bx_view != null) { _view.Insert(5, bx_view); _view1.Remove(bx_view); };
  151. SetDataInfoView qtkx_view = new SetDataInfoView();//98 其他款项
  152. qtkx_view = _view1.Where(it => it.Id == 98).FirstOrDefault();
  153. if (qtkx_view != null) { _view.Insert(6, qtkx_view); _view1.Remove(qtkx_view); };
  154. SetDataInfoView skth_view = new SetDataInfoView();//285 收款退还与其他款项
  155. skth_view = _view1.Where(it => it.Id == 285).FirstOrDefault();
  156. if (skth_view != null) { _view.Insert(7, skth_view); _view1.Remove(skth_view); };
  157. if (_view1.Count > 0)
  158. {
  159. _view.AddRange(_view1);
  160. }
  161. return Ok(JsonView(_view));
  162. }
  163. /// <summary>
  164. /// 查询团组简略详情列表
  165. /// Page 根据Ctable And User 返回可操作的团
  166. /// </summary>
  167. /// <param name="dto"></param>
  168. /// <returns></returns>
  169. [HttpPost]
  170. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  171. public async Task<IActionResult> PostGroupListByCTableAndUserId(GroupListByCTableAndUserIdDto dto)
  172. {
  173. if (dto.CTable < 1) Ok(JsonView(false, @"请输入正确的员工给Id!"));
  174. if (dto.CTable < 1)
  175. return Ok(JsonView(false, @"请输入正确的CTable Id !76 酒店预订 77 行程 79 车/导游地接<br/>80 签证 81 邀请/公务活动 82 团组客户保险<br\>85 机票预订 98 其他款项 751 酒店早餐"));
  176. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3)
  177. {
  178. string sql = string.Format(@"Select row_number() over(order by di.CreateTime Desc) as Row_Number,
  179. di.Id,di.TeamName,di.TourCode,di.ClientName,di.VisitCountry,di.VisitStartDate,
  180. di.VisitEndDate,di.VisitDays,di.VisitPNumber,di.CreateTime
  181. From Grp_GroupsTaskAssignment gta
  182. Inner Join Grp_DelegationInfo di On gta.DIId = di.Id
  183. Where gta.IsDel = 0 And di.IsDel = 0 And gta.IsEnable = 1
  184. And gta.CTId = {0} And gta.UId = {1}", dto.CTable, dto.UserId);
  185. if (!string.IsNullOrEmpty(dto.TeamName))
  186. {
  187. sql = string.Format($"{sql} And di.TeamName Like '%{dto.TeamName}%'");
  188. }
  189. //去重
  190. sql = $"{sql} GROUP BY di.Id,di.TeamName,di.TourCode,di.ClientName,di.VisitCountry,di.VisitStartDate,di.VisitEndDate,di.VisitDays,di.VisitPNumber,di.CreateTime";
  191. RefAsync<int> total = 0;//REF和OUT不支持异步,想要真的异步这是最优解
  192. var data = await _groupRep._sqlSugar.SqlQueryable<GroupListByCTableAndUserIdView>(sql).ToPageListAsync(dto.PageIndex, dto.PageSize, total); //ToPageAsync
  193. foreach (var item in data)
  194. {
  195. item.VisitStartDate = item.VisitStartDate == "" ? "" : Convert.ToDateTime(item.VisitStartDate).ToString("yyyy-MM-dd");
  196. item.VisitEndDate = item.VisitEndDate == "" ? "" : Convert.ToDateTime(item.VisitEndDate).ToString("yyyy-MM-dd");
  197. }
  198. return Ok(JsonView(true, "操作成功!", data, total));
  199. }
  200. else
  201. {
  202. return Ok(JsonView(false, @"请输入正确的PortType 1 Web 2 Android 3 IOS "));
  203. }
  204. }
  205. #endregion
  206. #region 币种 List
  207. /// <summary>
  208. /// 币种 List
  209. /// </summary>
  210. /// <returns></returns>
  211. [HttpGet, HttpPost]
  212. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  213. public async Task<IActionResult> PostCurrencyList()
  214. {
  215. try
  216. {
  217. Result setData = await _setDataRep.GetSetDataBySTId(_setDataRep, 66); //币种类型
  218. if (setData.Code == 0)
  219. {
  220. return Ok(JsonView(true, "查询成功", setData.Data));
  221. }
  222. else
  223. {
  224. return Ok(JsonView(false, setData.Msg));
  225. }
  226. }
  227. catch (Exception)
  228. {
  229. return Ok(JsonView(false, "程序错误!"));
  230. throw;
  231. }
  232. }
  233. /// <summary>
  234. /// 团组汇率 币种 Item (来源:团组汇率)
  235. /// 根据 团组Id And 业务类型(CTable)Id
  236. /// api处理CTable = 285,默认返回CNY
  237. /// </summary>
  238. /// <param name="dto"> 请求参数Dto </param>
  239. /// <returns></returns>
  240. [HttpPost]
  241. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  242. public async Task<IActionResult> PostGroupTeamRateByDiIdAndCTableId(GeneralTeamRateInfoDto dto)
  243. {
  244. try
  245. {
  246. if (dto == null)
  247. {
  248. return Ok(JsonView(false, "请输入参数!"));
  249. }
  250. if (dto.DiId == 0)
  251. {
  252. return Ok(JsonView(false, "请输入正确的团组Id!"));
  253. }
  254. if (dto.CTable == 0)
  255. {
  256. return Ok(JsonView(false, "请输入正确的业务类型(CTable)Id!"));
  257. }
  258. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3)
  259. {
  260. var _vew = await GeneralMethod.PostGroupTeamRateByDiIdAndCTableId(dto.PortType, dto.DiId, dto.CTable);
  261. return Ok(JsonView(true, "操作成功!", _vew));
  262. }
  263. else
  264. {
  265. return Ok(JsonView(false, "请输入正确的端口号! 1 Web 2 Android 3 Ios;"));
  266. }
  267. }
  268. catch (Exception ex)
  269. {
  270. return Ok(JsonView(false, ex.Message));
  271. }
  272. }
  273. /// <summary>
  274. /// 根据团组Id币种Id及类型Id查询团组汇率
  275. /// </summary>
  276. /// <param name="dto"></param>
  277. /// <returns></returns>
  278. [HttpGet, HttpPost]
  279. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  280. public async Task<IActionResult> PostCurrencyByDiid(int DiId, int CId, int CurrencyId)
  281. {
  282. try
  283. {
  284. Result setData = await _setDataRep.PostCurrencyByDiid(DiId, CId, CurrencyId); //币种类型
  285. if (setData.Code == 0)
  286. {
  287. return Ok(JsonView(true, "查询成功", setData.Data));
  288. }
  289. else
  290. {
  291. return Ok(JsonView(false, setData.Msg));
  292. }
  293. }
  294. catch (Exception)
  295. {
  296. return Ok(JsonView(false, "程序错误!"));
  297. throw;
  298. }
  299. }
  300. #endregion
  301. #region 查询页面关联Ctable
  302. /// <summary>
  303. /// 页面关联Ctable
  304. /// 根据PageId 返回 CTable Id
  305. /// </summary>
  306. /// <param name="dto"></param>
  307. /// <returns></returns>
  308. [HttpPost]
  309. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  310. public async Task<IActionResult> PostPageLinkCTable(PageLinkCTableDto dto)
  311. {
  312. try
  313. {
  314. if (dto == null)
  315. {
  316. return Ok(JsonView(false, "请求参数不能为空!"));
  317. }
  318. if (dto.PageId == 0)
  319. {
  320. return Ok(JsonView(false, "页面Id不能为0!"));
  321. }
  322. List<CTableCorrelationPageDatas> data = AppSettingsHelper.Get<CTableCorrelationPageDatas>("CTableCorrelationPageDatas");
  323. CTableCorrelationPageDatas correlationPageDatas = new CTableCorrelationPageDatas();
  324. foreach (var item in data)
  325. {
  326. if (item.PageIdDatas != null)
  327. {
  328. var pageId = item.PageIdDatas.Where(it => it == dto.PageId).FirstOrDefault();
  329. if (pageId != 0)
  330. {
  331. correlationPageDatas = item;
  332. break;
  333. }
  334. }
  335. }
  336. if (correlationPageDatas.CTableId == 0)
  337. {
  338. return Ok(JsonView(false, "您查询的页面Id,未配置AppSettings,请前往配置!"));
  339. }
  340. return Ok(JsonView(true, "操作成功", new { CTable = correlationPageDatas.CTableId }));
  341. }
  342. catch (Exception ex)
  343. {
  344. return Ok(JsonView(false, ex.Message));
  345. }
  346. }
  347. #endregion
  348. #region 会务物料单
  349. /// <summary>
  350. /// 获取会务活动列表
  351. /// </summary>
  352. /// <param name="paras"></param>
  353. /// <returns></returns>
  354. [HttpPost]
  355. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  356. public async Task<IActionResult> PostConferenceList()
  357. {
  358. List<Grp_DelegationInfo> listSource = _busRep.Query<Grp_DelegationInfo>(s => s.TeamDid == 691 && s.IsDel == 0).ToList();
  359. List<GroupNameView> viewList = new List<GroupNameView>();
  360. foreach (var group in listSource)
  361. {
  362. GroupNameView _view = new GroupNameView();
  363. _view.Id = group.Id;
  364. _view.GroupName = group.TeamName;
  365. }
  366. return Ok(JsonView(viewList));
  367. }
  368. /// <summary>
  369. /// 获取会务的采购物品计划清单
  370. /// </summary>
  371. /// <param name="ConfId">会务活动Id</param>
  372. /// <returns></returns>
  373. [HttpPost]
  374. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  375. public async Task<IActionResult> PostConfItemList(int ConfId)
  376. {
  377. Bus_ConfItemListView view = new Bus_ConfItemListView();
  378. Bus_ConfItemListInfo _confListInfo = await _busRep.Query<Bus_ConfItemListInfo>(s => s.Diid == ConfId).FirstAsync();
  379. if (_confListInfo != null)
  380. {
  381. view.TotalCost = _confListInfo.TotalCost;
  382. string sqlItem = string.Format(@" Select c.Id,c.ItemId,d.ItemName,c.[Count],c.CurrCost,c.OpRemark
  383. From Bus_ConfItem as c With(Nolock)
  384. Inner Join Res_ItemDetail as d with(Nolock) On c.ItemId=d.Id
  385. Where c.ConfListId = {0}", ConfId);
  386. List<Bus_ConfItemView> confItemList = await _busRep._sqlSugar.SqlQueryable<Bus_ConfItemView>(sqlItem).ToListAsync();
  387. view.ItemList = new List<Bus_ConfItemView>(confItemList);
  388. }
  389. else
  390. {
  391. view.ItemList = new List<Bus_ConfItemView>();
  392. view.TotalCost = 0;
  393. }
  394. return Ok(JsonView(view));
  395. }
  396. /// <summary>
  397. /// 获取会务可采购的物料集合
  398. /// </summary>
  399. /// <returns></returns>
  400. [HttpPost]
  401. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  402. public async Task<IActionResult> PostOptionalItemList()
  403. {
  404. List<OptionalBusRangeView> result = await _busRep.GetViewList_OptionalItem();
  405. return Ok(JsonView(result));
  406. }
  407. /// <summary>
  408. /// 编辑物料采购清单
  409. /// </summary>
  410. /// <returns></returns>
  411. [HttpPost]
  412. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  413. public async Task<IActionResult> PostEditOptionalItemList(JsonDtoBase jsonDto)
  414. {
  415. if (string.IsNullOrEmpty(jsonDto.Paras))
  416. {
  417. return Ok(JsonView(false, "参数为空"));
  418. }
  419. Edit_OptionalItemListDto _dto = JsonConvert.DeserializeObject<Edit_OptionalItemListDto>(jsonDto.Paras);
  420. //Edit_OptionalItemListDto _dto = System.Text.Json.JsonSerializer.Deserialize<Edit_OptionalItemListDto>(jsonDto.Paras);
  421. if (_dto.DiId < 1)
  422. {
  423. return Ok(JsonView(false, "团组Id为空"));
  424. }
  425. if (_dto.ConfItemListId < 1)
  426. {
  427. //新增
  428. int rstInsert = await _busRep.Insert_ConfItemList(_dto);
  429. return Ok(JsonView(rstInsert == 0));
  430. }
  431. else
  432. {
  433. //修改
  434. int rstUpdate = await _busRep.Edit_ConfItemList(_dto);
  435. return Ok(JsonView(rstUpdate == 0));
  436. }
  437. return Ok(JsonView(false));
  438. }
  439. /// <summary>
  440. /// 获取会务采购物料清单Excel
  441. /// </summary>
  442. /// <returns></returns>
  443. [HttpPost]
  444. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  445. public async Task<IActionResult> Excel_ConfItemList(JsonDtoBase jsonDto)
  446. {
  447. if (string.IsNullOrEmpty(jsonDto.Paras))
  448. {
  449. return Ok(JsonView(false, "参数为空"));
  450. }
  451. dynamic confList = JsonConvert.DeserializeObject<dynamic>(jsonDto.Paras);
  452. int confListId = confList.ConfListId;
  453. Bus_ConfItemListInfo _entityConfList = await _busRep.Query<Bus_ConfItemListInfo>(s => s.Id == confListId).FirstAsync();
  454. if (_entityConfList != null)
  455. {
  456. string result = new Excel_BusConfItemList().Excel(_entityConfList);
  457. }
  458. else
  459. {
  460. return Ok(JsonView(false, "请先保存数据"));
  461. }
  462. return Ok(JsonView(false));
  463. }
  464. #endregion
  465. #region 阿里云短信测试
  466. /// <summary>
  467. /// 编辑物料采购清单
  468. /// </summary>
  469. /// <returns></returns>
  470. [HttpPost]
  471. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  472. public async Task<IActionResult> AliMessageTest(string mobile)
  473. {
  474. string add2dayZH = DateTime.Now.AddDays(2).ToString("yyyy年MM月dd日");
  475. string templateParam = JsonConvert.SerializeObject(new { teams = "测试团组", date = add2dayZH });
  476. AliMessagePost.PostMessage(mobile, "泛美国际团组", "SMS_461575447", templateParam);
  477. return Ok(JsonView(true));
  478. }
  479. #endregion
  480. #region 文件删除
  481. /// <summary>
  482. /// 文件操作
  483. /// 删除指定文件
  484. /// </summary>
  485. /// <param name="dto">Dto</param>
  486. /// <returns></returns>
  487. [HttpPost]
  488. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  489. public async Task<IActionResult> PostFileDel(FileDelDto dto)
  490. {
  491. try
  492. {
  493. string pathUrl = dto.PathUrl;
  494. if (string.IsNullOrEmpty(pathUrl))
  495. return Ok(JsonView(false, "路径为空或者不是有效路径!"));
  496. if (System.IO.File.Exists(pathUrl))
  497. {
  498. System.IO.File.Delete(pathUrl);
  499. return Ok(JsonView(false, "操作成功!"));
  500. }
  501. else
  502. {
  503. return Ok(JsonView(false, "该文件不存在!"));
  504. }
  505. }
  506. catch (Exception ex)
  507. {
  508. return Ok(JsonView(false, ex.Message));
  509. }
  510. }
  511. #endregion
  512. #region 表操作记录
  513. /// <summary>
  514. /// 表操作记录
  515. /// 添加
  516. /// </summary>
  517. /// <returns></returns>
  518. [HttpPost]
  519. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  520. public async Task<IActionResult> PostTableOperationRecordAdd(TableOperationRecordAddDto _dto)
  521. {
  522. try
  523. {
  524. Crm_TableOperationRecord _TableOperationRecord = new Crm_TableOperationRecord()
  525. {
  526. TableName = _dto.TableName,
  527. PortType = _dto.PortType,
  528. OperationItem = _dto.OperationItem,
  529. DataId = _dto.DataId,
  530. CreateUserId = _dto.UserId,
  531. CreateTime = DateTime.Now,
  532. Remark = "",
  533. IsDel = 0
  534. };
  535. bool _view = await _TableOperationRecordRep._Add(_TableOperationRecord);
  536. if (_view)
  537. {
  538. return Ok(JsonView(true, "操作成功!"));
  539. }
  540. else
  541. {
  542. return Ok(JsonView(false, "操作失败!"));
  543. }
  544. }
  545. catch (Exception)
  546. {
  547. return Ok(JsonView(false, "程序错误!"));
  548. }
  549. }
  550. /// <summary>
  551. /// 表操作记录
  552. /// 分页
  553. /// </summary>
  554. /// <returns></returns>
  555. [HttpPost]
  556. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  557. public async Task<IActionResult> PostTableOperationRecordPageList(TableOperationRecordPageDto _dto)
  558. {
  559. try
  560. {
  561. string whereSql = "";
  562. if (!string.IsNullOrEmpty(_dto.TableName))
  563. {
  564. whereSql = string.Format(" And tor.TableName = '{0}'", _dto.TableName);
  565. }
  566. string sql = string.Format(@"Select row_number() over(order by tor.CreateTime Desc) As Row_Number,
  567. tor.TableName,tor.PortType,tor.OperationItem,tor.DataId,u.CnName As OperationUserName,
  568. tor.CreateTime,tor.Remark
  569. From Crm_TableOperationRecord tor
  570. Left Join Sys_Users u On tor.CreateUserId = u.Id
  571. Where tor.Isdel = 0 {0}", whereSql);
  572. RefAsync<int> total = 0;//REF和OUT不支持异步,想要真的异步这是最优解
  573. var _view = await _TableOperationRecordRep._sqlSugar.SqlQueryable<TableOperationRecordPageView>(sql).ToPageListAsync(_dto.PageIndex, _dto.PageSize, total);//ToPageAsync
  574. return Ok(JsonView(true, "查询成功!", _view, total));
  575. }
  576. catch (Exception ex)
  577. {
  578. return Ok(JsonView(false, "程序错误!Msg:" + ex.Message));
  579. }
  580. }
  581. #endregion
  582. /// <summary>
  583. /// 汉字转拼音
  584. /// </summary>
  585. /// <param name="dto"></param>
  586. /// <returns></returns>
  587. [HttpPost]
  588. public IActionResult ChineseToEnFn(ChineseToEn dto)
  589. {
  590. var jw = JsonView(false, "请输入中文!");
  591. if (dto.originalText.Count == 0)
  592. {
  593. return Ok(jw);
  594. }
  595. List<string> values = new List<string>();
  596. foreach (var item in dto.originalText)
  597. {
  598. var val = item.GetTotalPingYin();
  599. if (dto.isUp)
  600. {
  601. val = val.Select(x => x.ToUpper()).ToList();
  602. }
  603. values.Add(val.Count > 0 ? val[0] : "暂无该拼音!");
  604. }
  605. jw = JsonView(true, "转换成功!", values);
  606. return Ok(jw);
  607. }
  608. [HttpGet]
  609. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  610. public IActionResult CodeTest()
  611. {
  612. return Ok(JsonView(true, "测试成功!"));
  613. }
  614. }
  615. }