SmartMeterController.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package com.template.controller;
  2. import com.template.annotation.DESRespondSecret;
  3. import com.template.api.SmartMeterControllerAPI;
  4. import com.template.common.utils.paramUtils;
  5. import com.template.model.pojo.SmartMeter;
  6. import com.template.model.pojo.SmartMeter;
  7. import com.template.model.result.CommonResult;
  8. import com.template.model.result.PageUtils;
  9. import com.template.services.SmartMeterService;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.validation.BindingResult;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.RestController;
  14. /**
  15. * <p>
  16. * 前端控制器
  17. * </p>
  18. *
  19. * @author ceshi
  20. * @since 2023-12-04
  21. */
  22. @RestController
  23. //返回参数加密注解
  24. @DESRespondSecret
  25. public class SmartMeterController implements SmartMeterControllerAPI {
  26. @Autowired
  27. private SmartMeterService smartMeterService;
  28. /**
  29. * 新增水电表
  30. *
  31. * @param smartApply 水电表数据
  32. * @param bindingResult
  33. * @return
  34. */
  35. @Override
  36. @DESRespondSecret(validated = true)
  37. public CommonResult insertSmartMeter(SmartMeter smartApply, BindingResult bindingResult) {
  38. if (bindingResult.hasErrors()) {
  39. String st = paramUtils.getParamError(bindingResult);
  40. return CommonResult.fail(st);
  41. }
  42. int result = smartMeterService.insertSmartMeter(smartApply);
  43. return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
  44. }
  45. /**
  46. * 更新水电表
  47. *
  48. * @param sa 水电表数据
  49. * @param bindingResult
  50. * @return
  51. */
  52. @Override
  53. @DESRespondSecret(validated = true)
  54. public CommonResult updateSmartMeterById(SmartMeter sa, BindingResult bindingResult) {
  55. if (bindingResult.hasErrors()) {
  56. String st = paramUtils.getParamError(bindingResult);
  57. return CommonResult.fail(st);
  58. }
  59. int result = smartMeterService.updateSmartMeter(sa);
  60. return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
  61. }
  62. /**
  63. * 水电表分页数据查询
  64. *
  65. * @param currentPage 当前页数
  66. * @param pageCount 一页数据条数
  67. * @param name 查询名称
  68. * @return
  69. */
  70. @Override
  71. @DESRespondSecret(validated = true)
  72. public CommonResult queryPageSmartMeters(int currentPage, int pageCount, String name) {
  73. PageUtils<SmartMeter> result = smartMeterService.queryPageSmartMeters(currentPage, pageCount, name);
  74. return CommonResult.ok(result);
  75. }
  76. @Override
  77. @DESRespondSecret(validated = true)
  78. public CommonResult deleteSmartMeterById(int id) {
  79. SmartMeter data = smartMeterService.getSmartById(id);
  80. if (data == null) {
  81. return CommonResult.fail("当前数据不存在,删除失败!");
  82. }
  83. int result = smartMeterService.deleteSmartMeterById(id);
  84. return result > 0 ? CommonResult.ok("删除成功") : CommonResult.fail("删除失败");
  85. }
  86. }