SmartSchoolController.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package com.template.controller;
  2. import com.template.annotation.DESRespondSecret;
  3. import com.template.api.SmartSchoolControllerAPI;
  4. import com.template.common.utils.paramUtils;
  5. import com.template.model.pojo.SmartSchool;
  6. import com.template.model.request.UpdateSmartSchoolRequest;
  7. import com.template.model.result.CommonResult;
  8. import com.template.model.result.PageUtils;
  9. import com.template.services.SmartSchoolService;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.validation.BindingResult;
  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. //返回参数加密注解
  23. @DESRespondSecret
  24. public class SmartSchoolController implements SmartSchoolControllerAPI {
  25. @Autowired
  26. private SmartSchoolService smartSchoolService;
  27. /**
  28. * 新增学校基本信息
  29. *
  30. * @param smartApply 学校基本信息数据
  31. * @param bindingResult
  32. * @return
  33. */
  34. @Override
  35. @DESRespondSecret(validated = true)
  36. public CommonResult insertSmartSchool(SmartSchool smartApply, BindingResult bindingResult) {
  37. if (bindingResult.hasErrors()) {
  38. String st = paramUtils.getParamError(bindingResult);
  39. return CommonResult.fail(st);
  40. }
  41. if (smartApply.getOriginalId() == null) {
  42. smartApply.setOriginalId(smartApply.getAppid());
  43. }
  44. int result = smartSchoolService.insertSmartSchool(smartApply);
  45. return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
  46. }
  47. /**
  48. * 更新学校基本信息
  49. *
  50. * @param sa 学校基本信息数据
  51. * @param bindingResult
  52. * @return
  53. */
  54. @Override
  55. @DESRespondSecret(validated = true)
  56. public CommonResult updateSmartSchoolById(UpdateSmartSchoolRequest sa, BindingResult bindingResult) {
  57. if (bindingResult.hasErrors()) {
  58. String st = paramUtils.getParamError(bindingResult);
  59. return CommonResult.fail(st);
  60. }
  61. if (sa.getId() == null) {
  62. return CommonResult.fail("数据ID不能为空");
  63. }
  64. SmartSchool oldData = smartSchoolService.getSmartById(sa.getId());
  65. if (oldData == null) {
  66. return CommonResult.fail("学校基本信息无效,修改失败");
  67. }
  68. oldData.setSchoolCode(sa.getSchoolCode() == null ? oldData.getSchoolCode() : sa.getSchoolCode());
  69. oldData.setName(sa.getName() == null ? oldData.getName() : sa.getName());
  70. oldData.setSchoolBadge(sa.getSchoolBadge() == null ? oldData.getSchoolBadge() : sa.getSchoolBadge());
  71. oldData.setLogoImage(sa.getSchoolBadge() == null ? oldData.getLogoImage() : sa.getLogoImage());
  72. oldData.setOfficialName(sa.getOfficialName() == null ? oldData.getOfficialName() : sa.getOfficialName());
  73. oldData.setOriginalId(sa.getAppid() == null ? oldData.getOriginalId() : (oldData.getAppid().equals(sa.getAppid()) ? oldData.getOriginalId() : oldData.getAppid()));
  74. oldData.setAppid(sa.getAppid() == null ? oldData.getAppid() : sa.getAppid());
  75. int result = smartSchoolService.updateSmartSchool(oldData);
  76. return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
  77. }
  78. @Override
  79. @DESRespondSecret(validated = true)
  80. public CommonResult querySmartSchool() {
  81. SmartSchool result = smartSchoolService.getSmartSchool();
  82. return CommonResult.ok(result);
  83. }
  84. /**
  85. * 学校基本信息分页数据查询
  86. *
  87. * @param currentPage 当前页数
  88. * @param pageCount 一页数据条数
  89. * @param name 查询名称
  90. * @return
  91. */
  92. @Override
  93. @DESRespondSecret(validated = true)
  94. public CommonResult queryPageSmartSchools(int currentPage, int pageCount, String name) {
  95. PageUtils<SmartSchool> result = smartSchoolService.queryPageSmartSchools(currentPage, pageCount, name);
  96. return CommonResult.ok(result);
  97. }
  98. @Override
  99. @DESRespondSecret(validated = true)
  100. public CommonResult deleteSmartSchoolById(int id) {
  101. SmartSchool data = smartSchoolService.getSmartById(id);
  102. if (data == null) {
  103. return CommonResult.fail("当前数据不存在,删除失败!");
  104. }
  105. int result = smartSchoolService.deleteSmartSchoolById(id);
  106. return result > 0 ? CommonResult.ok("删除成功") : CommonResult.fail("删除失败");
  107. }
  108. }