SmartDataSourceLogController.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package com.template.controller;
  2. import com.template.api.SmartDataSourceLogControllerAPI;
  3. import com.template.common.utils.paramUtils;
  4. import com.template.model.pojo.SmartDataSourceLog;
  5. import com.template.model.result.CommonResult;
  6. import com.template.model.result.PageUtils;
  7. import com.template.services.SmartDataSourceLogService;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.validation.BindingResult;
  10. import org.springframework.web.bind.annotation.RestController;
  11. /**
  12. * <p>
  13. * 数据源操作日志 前端控制器
  14. * </p>
  15. *
  16. * @author ceshi
  17. * @since 2023-12-05
  18. */
  19. @RestController
  20. public class SmartDataSourceLogController implements SmartDataSourceLogControllerAPI {
  21. @Autowired
  22. private SmartDataSourceLogService smartDataSourceLogService;
  23. /**
  24. * 新增日志
  25. *
  26. * @param smartDataSourceLog 日志数据
  27. * @param bindingResult
  28. * @return
  29. */
  30. @Override
  31. public CommonResult insertSmartDataSourceLog(SmartDataSourceLog smartDataSourceLog, BindingResult bindingResult) {
  32. if (bindingResult.hasErrors()) {
  33. String st = paramUtils.getParamError(bindingResult);
  34. return CommonResult.fail(st);
  35. }
  36. if (smartDataSourceLog.getLogActionBusiness() == null) {
  37. return CommonResult.fail("【业务名称】不能为空!");
  38. }
  39. if (smartDataSourceLog.getLogActionHost() == null) {
  40. return CommonResult.fail("【操作主机ip】不能为空!");
  41. }
  42. if (smartDataSourceLog.getLogActionModule() == null) {
  43. return CommonResult.fail("【操作模块】不能为空!");
  44. }
  45. if (smartDataSourceLog.getLogActionClass() == null) {
  46. return CommonResult.fail("【操作类型】不能为空!");
  47. }
  48. if (smartDataSourceLog.getLogActionPeople() == null) {
  49. return CommonResult.fail("【操作人】不能为空!");
  50. }
  51. if (smartDataSourceLog.getLogActionRemote() == null) {
  52. return CommonResult.fail("【操作人ip】不能为空!");
  53. }
  54. if (smartDataSourceLog.getLogActionName() == null) {
  55. return CommonResult.fail("【操作名称】不能为空!");
  56. }
  57. int result = smartDataSourceLogService.insertSmartDataSourceLog(smartDataSourceLog);
  58. return result > 0 ? CommonResult.ok("操作日志添加成功") : CommonResult.fail("操作日志添加失败");
  59. }
  60. /**
  61. * 更新日志
  62. * @param smartDataSourceLog 日志数据
  63. * @param bindingResult
  64. * @return
  65. */
  66. // @Override
  67. // public CommonResult updateSmartDataSourceLogById(SmartDataSourceLog smartDataSourceLog, BindingResult bindingResult) {
  68. // if (bindingResult.hasErrors()) {
  69. // String st = paramUtils.getParamError(bindingResult);
  70. // return CommonResult.fail(st);
  71. // }
  72. //
  73. // int result = smartDataSourceLogService.updateSmartDataSourceLog(smartDataSourceLog);
  74. // return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
  75. // }
  76. /**
  77. * 日志分页数据查询
  78. *
  79. * @param currentPage 当前页数
  80. * @param pageCount 一页数据条数
  81. * @param smartDataSourceLog 查询名称
  82. * @return
  83. */
  84. @Override
  85. public CommonResult queryPageSmartDataSourceLogs(int currentPage, int pageCount, String startTime, String endTime,
  86. SmartDataSourceLog smartDataSourceLog) {
  87. if ((startTime != null && endTime == null) || (startTime == null && endTime != null)) {
  88. return CommonResult.fail("查询的【开始时间】和【结束时间】必须同时提供!");
  89. }
  90. PageUtils<SmartDataSourceLog> result = smartDataSourceLogService.queryPageSmartDataSourceLogs(currentPage, pageCount,
  91. startTime, endTime, smartDataSourceLog);
  92. return CommonResult.ok(result);
  93. }
  94. // @Override
  95. // public CommonResult deleteSmartDataSourceLogById(int id) {
  96. //
  97. // SmartDataSourceLog data = smartDataSourceLogService.getSmartById(id);
  98. //
  99. // if(data == null){
  100. // return CommonResult.fail("当前数据不存在,删除失败!");
  101. // }
  102. //
  103. // int result = smartDataSourceLogService.deleteSmartDataSourceLogById(id);
  104. //
  105. // return result > 0 ? CommonResult.ok("删除成功") : CommonResult.fail("删除失败");
  106. // }
  107. }