HotIconController.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package com.fdkankan.fusion.controller;
  2. import com.fdkankan.fusion.common.FilePath;
  3. import com.fdkankan.fusion.common.ResultCode;
  4. import com.fdkankan.fusion.exception.BusinessException;
  5. import com.fdkankan.fusion.common.ResultData;
  6. import com.fdkankan.fusion.entity.HotIcon;
  7. import com.fdkankan.fusion.service.ICaseTagService;
  8. import com.fdkankan.fusion.service.IHotIconService;
  9. import com.fdkankan.fusion.service.impl.UploadService;
  10. import org.apache.commons.lang3.StringUtils;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.beans.factory.annotation.Value;
  13. import org.springframework.web.bind.annotation.*;
  14. import org.springframework.web.multipart.MultipartFile;
  15. import java.io.IOException;
  16. import java.util.List;
  17. /**
  18. * <p>
  19. * 前端控制器
  20. * </p>
  21. *
  22. * @author
  23. * @since 2022-08-02
  24. */
  25. @RestController
  26. @RequestMapping("/edit/hotIcon")
  27. public class HotIconController extends BaseController{
  28. @Autowired
  29. IHotIconService hotIconService;
  30. @Autowired
  31. ICaseTagService caseTagService;
  32. @Autowired
  33. UploadService uploadService;
  34. @Value("${spring.profiles.active}")
  35. private String environment;
  36. @GetMapping("/list")
  37. public ResultData list(@RequestParam(required = false) Integer fusionId){
  38. if(fusionId!=null){
  39. return ResultData.ok(hotIconService.getListByFusionId(fusionId));
  40. }
  41. return ResultData.ok(hotIconService.getListByUserName(getUserName()));
  42. }
  43. @GetMapping("/treeList")
  44. public ResultData listTree(@RequestParam(required = false) Integer fusionId){
  45. List<HotIcon> iconList ;
  46. if(fusionId!=null){
  47. iconList = hotIconService.getListByFusionId(fusionId);
  48. }else {
  49. iconList = hotIconService.getListByUserName(getUserName());
  50. }
  51. List<HotIcon> treeList = hotIconService.treeList(iconList);
  52. return ResultData.ok(treeList);
  53. }
  54. @PostMapping("/add")
  55. public ResultData add(@RequestParam(required = false) MultipartFile file,
  56. @RequestParam(required = false) String iconTitle,
  57. @RequestParam(required = false) Integer fusionId,
  58. @RequestParam(required = false,defaultValue = "279") Integer parentId) throws IOException {
  59. if(file==null || StringUtils.isEmpty(iconTitle) || fusionId == null){
  60. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  61. }
  62. String iconUrl = uploadService.uploadFile(file, true, String.format(FilePath.ICON_OSS_PATH,environment,""));
  63. HotIcon hotIcon = new HotIcon();
  64. hotIcon.setIconTitle(iconTitle);
  65. hotIcon.setIconUrl(iconUrl);
  66. hotIcon.setFusionId(fusionId);
  67. hotIcon.setParentId(parentId);
  68. if(StringUtils.isEmpty(hotIcon.getIconUrl())){
  69. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  70. }
  71. //取消用户之前新增标记
  72. //hotIconService.cancelIsNew(username);
  73. if(StringUtils.isEmpty(hotIcon.getIconTitle())){
  74. String fileName = file.getOriginalFilename();
  75. assert fileName != null;
  76. hotIcon.setIconTitle(fileName.substring(0,fileName.lastIndexOf(".")));
  77. }
  78. hotIconService.save(hotIcon);
  79. return ResultData.ok(hotIcon);
  80. }
  81. @PostMapping("/delete")
  82. public ResultData delete(@RequestBody HotIcon hotIcon){
  83. if(hotIcon.getIconId() == null){
  84. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  85. }
  86. if(hotIcon.getIconId() == 1){
  87. return ResultData.ok();
  88. }
  89. HotIcon byId = hotIconService.getById(hotIcon.getIconId());
  90. if(byId == null){
  91. return ResultData.ok();
  92. }
  93. if(byId .getIsSystem() == 1){
  94. throw new BusinessException(ResultCode.SYSTEM_HOT_ICON_NOT_DELETE);
  95. }
  96. caseTagService.updateDFHotIcon(hotIcon.getIconId());
  97. hotIconService.removeById(hotIcon.getIconId());
  98. return ResultData.ok();
  99. }
  100. }