JyUserFileController.java 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package com.fdkankan.manage.controller;
  2. import com.fdkankan.manage.common.ResultCode;
  3. import com.fdkankan.manage.common.ResultData;
  4. import com.fdkankan.manage.entity.JyUserFile;
  5. import com.fdkankan.manage.exception.BusinessException;
  6. import com.fdkankan.manage.service.IJyUserFileService;
  7. import org.apache.commons.lang3.StringUtils;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.web.bind.annotation.*;
  10. import java.util.List;
  11. /**
  12. * <p>
  13. * 前端控制器
  14. * </p>
  15. *
  16. * @author
  17. * @since 2025-04-10
  18. */
  19. @RestController
  20. @RequestMapping("/service/manage/userFile")
  21. public class JyUserFileController {
  22. @Autowired
  23. IJyUserFileService jyUserFileService;
  24. @GetMapping("/info")
  25. public ResultData info(@RequestParam(required = false,defaultValue = "0")Integer imgType){
  26. return ResultData.ok(jyUserFileService.getByType(imgType));
  27. }
  28. @PostMapping("/addOrUpdate")
  29. public ResultData addOrUpdate(@RequestBody JyUserFile jyUserFile){
  30. if(StringUtils.isBlank(jyUserFile.getFileUrl()) || jyUserFile.getImgType() == null){
  31. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  32. }
  33. if(jyUserFile.getId() == null){
  34. List<JyUserFile> byType = jyUserFileService.getByType(jyUserFile.getImgType());
  35. if(byType != null && !byType.isEmpty()){
  36. jyUserFile.setId(byType.get(0).getId());
  37. }
  38. }
  39. return ResultData.ok(jyUserFileService.saveOrUpdate(jyUserFile));
  40. }
  41. }