ModelExistController.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package com.example.demo.controller;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  4. import com.example.demo.constant.CodeConstant;
  5. import com.example.demo.entity.ModelExistEntity;
  6. import com.example.demo.entity.ModelUploadEntity;
  7. import com.example.demo.service.IModelExistService;
  8. import com.example.demo.service.IModelUploadService;
  9. import com.example.demo.util.Result;
  10. import com.example.demo.vo.request.RequestModelExist;
  11. import io.swagger.annotations.Api;
  12. import io.swagger.annotations.ApiImplicitParam;
  13. import io.swagger.annotations.ApiImplicitParams;
  14. import io.swagger.annotations.ApiOperation;
  15. import lombok.extern.slf4j.Slf4j;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.util.StringUtils;
  18. import org.springframework.web.bind.annotation.RequestBody;
  19. import org.springframework.web.bind.annotation.RequestMapping;
  20. import org.springframework.web.bind.annotation.RequestMethod;
  21. import org.springframework.web.bind.annotation.RestController;
  22. import java.util.*;
  23. /**
  24. * Created by Hb_zzZ on 2021/1/20.
  25. */
  26. @Slf4j
  27. @RestController
  28. @RequestMapping("/change/modelExist")
  29. @Api(tags = "现有模型模块")
  30. public class ModelExistController extends BaseController {
  31. @Autowired
  32. private IModelExistService modelExistService;
  33. @Autowired
  34. private IModelUploadService modelUploadService;
  35. /**
  36. * 根据模型名称判断是否存在
  37. * @return
  38. */
  39. @ApiOperation("根据模型名称判断是否存在")
  40. @RequestMapping(value = "/findModelByNames", method = RequestMethod.POST)
  41. @ApiImplicitParams({
  42. @ApiImplicitParam(name = "names", value = "名称(多个以逗号分割)", dataType = "MultipartFile")})
  43. public Result findModelByNames(@RequestBody RequestModelExist param){
  44. if(StringUtils.isEmpty(param.getNames())){
  45. return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
  46. }
  47. String[] nameArr = param.getNames().split(",");
  48. LambdaQueryWrapper<ModelExistEntity> wrapper = Wrappers.lambdaQuery();
  49. wrapper.in(ModelExistEntity::getName,Arrays.asList(nameArr));
  50. List<ModelExistEntity> list = modelExistService.list(wrapper);
  51. List<String> nameList = new ArrayList<>();
  52. for (ModelExistEntity modelExistEntity : list) {
  53. nameList.add(modelExistEntity.getName());
  54. }
  55. List<String> result = new ArrayList<>();
  56. List<Map<String, Object>> resultMap = new ArrayList<>();
  57. Map<String, Object> map = null;
  58. ModelUploadEntity modelUploadEntity = null;
  59. for (String name : nameArr) {
  60. if(!nameList.contains(name)){
  61. modelUploadEntity = modelUploadService.findByFileId(name);
  62. if(modelUploadEntity == null){
  63. return Result.failure(CodeConstant.FAILURE_CODE_4009, CodeConstant.FAILURE_MSG_4009);
  64. }
  65. result.add(name);
  66. map = new HashMap<>();
  67. map.put("name", name);
  68. map.put("userid", modelUploadEntity.getUserId());
  69. resultMap.add(map);
  70. }
  71. }
  72. ModelExistEntity modelExistEntity = new ModelExistEntity();
  73. for (String name : result) {
  74. modelExistEntity = new ModelExistEntity();
  75. modelExistEntity.setName(name);
  76. modelExistService.save(modelExistEntity);
  77. }
  78. return Result.success(resultMap);
  79. }
  80. /**
  81. * 根据模型名称删除
  82. * @return
  83. */
  84. @ApiOperation("根据模型名称删除")
  85. @RequestMapping(value = "/deleteModelByNames", method = RequestMethod.POST)
  86. @ApiImplicitParams({
  87. @ApiImplicitParam(name = "names", value = "名称(多个以逗号分割)", dataType = "MultipartFile")})
  88. public Result deleteModelByNames(@RequestBody RequestModelExist param){
  89. if(StringUtils.isEmpty(param.getNames())){
  90. return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
  91. }
  92. String[] nameArr = param.getNames().split(",");
  93. for (String name : nameArr) {
  94. modelExistService.deleteByName(name);
  95. }
  96. return Result.success();
  97. }
  98. }