ConfigController.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package cn.seecoder.paas.web.controller.api;
  2. import cn.seecoder.paas.service.ConfigService;
  3. import cn.seecoder.paas.service.EnvironmentService;
  4. import cn.seecoder.paas.service.model.vo.ConfigVO;
  5. import cn.seecoder.paas.util.ServiceException;
  6. import cn.seecoder.paas.util.enums.ConfigBelongsToType;
  7. import cn.seecoder.paas.web.model.Response;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.web.bind.annotation.*;
  10. @RestController
  11. @RequestMapping("/api/config")
  12. public class ConfigController {
  13. private final ConfigService configService;
  14. private final EnvironmentService environmentService;
  15. @Autowired
  16. public ConfigController(ConfigService configService, EnvironmentService environmentService) {
  17. this.configService = configService;
  18. this.environmentService = environmentService;
  19. }
  20. @PutMapping("")
  21. public Response update(@RequestBody ConfigVO configVO,
  22. @RequestParam(required = false, defaultValue = "false") Boolean hotUpdate) throws ServiceException {
  23. ConfigVO result = configService.createOrUpdate(configVO);
  24. // 如果是环境配置且需要热更新
  25. if (hotUpdate && result.getConfigBelongs() == ConfigBelongsToType.ENVIRONMENT) {
  26. environmentService.hotUpdateConfig(result.getEntityId());
  27. }
  28. return Response.buildSuccess(result);
  29. }
  30. }