SmartMeterController.java 2.7 KB

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