ExecSqlController.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using Bowin.Common.DES;
  2. using Bowin.Common.WebModels;
  3. using Microsoft.AspNetCore.Authorization;
  4. using Microsoft.AspNetCore.Mvc;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Threading.Tasks;
  9. using YLShipBuildLandMap.Entity.ViewModel;
  10. using YLShipBuildLandMap.Services.SystemSetting;
  11. namespace YLShipBuildLandMap.Web.Controllers.SystemSetting
  12. {
  13. [Route("api/systemsetting/[controller]/[action]")]
  14. [ApiController]
  15. [Authorize]
  16. public class ExecSqlController : ControllerBase
  17. {
  18. private IExecSqlService ExecSqlService { get; set; }
  19. private readonly IDesAccessor DesAccessor;
  20. private Guid adminUserId = Guid.Parse("0905539A-29AC-4A28-B3AB-A4D8EDBC2535");
  21. private string md5verCode = "DB6FF5AEF4426CA805674506B4248294";
  22. public ExecSqlController(IExecSqlService execSqlService, IUserService userService, IDesAccessor desAccessor)
  23. {
  24. ExecSqlService = execSqlService;
  25. this.DesAccessor = desAccessor;
  26. }
  27. [HttpPost]
  28. public ResultMessage select([FromBody] DesModel inputObject)
  29. {
  30. return ResultMessage.Success(ExecSqlService.select(getSql(inputObject)));
  31. }
  32. [HttpPost]
  33. public ResultMessage insert([FromBody] DesModel inputObject)
  34. {
  35. return ResultMessage.Success(ExecSqlService.insert(getSql(inputObject)));
  36. }
  37. [HttpPost]
  38. public ResultMessage update([FromBody] DesModel inputObject)
  39. {
  40. return ResultMessage.Success(ExecSqlService.update(getSql(inputObject)));
  41. }
  42. [HttpPost]
  43. public ResultMessage delete([FromBody] DesModel inputObject)
  44. {
  45. return ResultMessage.Success(ExecSqlService.delete(getSql(inputObject)));
  46. }
  47. private string getSql(DesModel inputObject)
  48. {
  49. var data = this.DesAccessor.DeDesToken(inputObject).Split('|');
  50. string sql = data[0];
  51. string verCode = data[1];
  52. if(!LoginUser.Current.UserID.Equals(adminUserId) || !verCode.ToUpper().Equals(md5verCode))
  53. throw new Exception("无权限操作");
  54. return sql;
  55. }
  56. }
  57. }