123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- package com.example.demo.controller;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.toolkit.Wrappers;
- import com.example.demo.constant.CodeConstant;
- import com.example.demo.entity.ModelExistEntity;
- import com.example.demo.entity.ModelUploadEntity;
- import com.example.demo.service.IModelExistService;
- import com.example.demo.service.IModelUploadService;
- import com.example.demo.util.Result;
- import com.example.demo.vo.request.RequestModelExist;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiImplicitParam;
- import io.swagger.annotations.ApiImplicitParams;
- import io.swagger.annotations.ApiOperation;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.util.StringUtils;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RestController;
- import java.util.*;
- /**
- * Created by Hb_zzZ on 2021/1/20.
- */
- @Slf4j
- @RestController
- @RequestMapping("/change/modelExist")
- @Api(tags = "现有模型模块")
- public class ModelExistController extends BaseController {
- @Autowired
- private IModelExistService modelExistService;
- @Autowired
- private IModelUploadService modelUploadService;
- /**
- * 根据模型名称判断是否存在
- * @return
- */
- @ApiOperation("根据模型名称判断是否存在")
- @RequestMapping(value = "/findModelByNames", method = RequestMethod.POST)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "names", value = "名称(多个以逗号分割)", dataType = "MultipartFile")})
- public Result findModelByNames(@RequestBody RequestModelExist param){
- if(StringUtils.isEmpty(param.getNames())){
- return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
- }
- String[] nameArr = param.getNames().split(",");
- LambdaQueryWrapper<ModelExistEntity> wrapper = Wrappers.lambdaQuery();
- wrapper.in(ModelExistEntity::getName,Arrays.asList(nameArr));
- List<ModelExistEntity> list = modelExistService.list(wrapper);
- List<String> nameList = new ArrayList<>();
- for (ModelExistEntity modelExistEntity : list) {
- nameList.add(modelExistEntity.getName());
- }
- List<String> result = new ArrayList<>();
- List<Map<String, Object>> resultMap = new ArrayList<>();
- Map<String, Object> map = null;
- ModelUploadEntity modelUploadEntity = null;
- for (String name : nameArr) {
- if(!nameList.contains(name)){
- modelUploadEntity = modelUploadService.findByFileId(name);
- if(modelUploadEntity == null){
- return Result.failure(CodeConstant.FAILURE_CODE_4009, CodeConstant.FAILURE_MSG_4009);
- }
- result.add(name);
- map = new HashMap<>();
- map.put("name", name);
- map.put("userid", modelUploadEntity.getUserId());
- resultMap.add(map);
- }
- }
- ModelExistEntity modelExistEntity = new ModelExistEntity();
- for (String name : result) {
- modelExistEntity = new ModelExistEntity();
- modelExistEntity.setName(name);
- modelExistService.save(modelExistEntity);
- }
- return Result.success(resultMap);
- }
- /**
- * 根据模型名称删除
- * @return
- */
- @ApiOperation("根据模型名称删除")
- @RequestMapping(value = "/deleteModelByNames", method = RequestMethod.POST)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "names", value = "名称(多个以逗号分割)", dataType = "MultipartFile")})
- public Result deleteModelByNames(@RequestBody RequestModelExist param){
- if(StringUtils.isEmpty(param.getNames())){
- return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
- }
- String[] nameArr = param.getNames().split(",");
- for (String name : nameArr) {
- modelExistService.deleteByName(name);
- }
- return Result.success();
- }
- }
|