AlgorithmServiceImpl.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package com.xy.service;
  2. import cn.hutool.core.lang.Console;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  5. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  6. import com.xy.dto.AlgorithmDto;
  7. import com.xy.entity.Algorithm;
  8. import com.xy.mapper.AlgorithmMapper;
  9. import com.xy.utils.MybatisPlusQuery;
  10. import com.xy.utils.R;
  11. import io.swagger.annotations.Api;
  12. import io.swagger.annotations.ApiOperation;
  13. import lombok.AllArgsConstructor;
  14. import org.springframework.stereotype.Service;
  15. import org.springframework.validation.annotation.Validated;
  16. import org.springframework.web.bind.annotation.PostMapping;
  17. import org.springframework.web.bind.annotation.RequestBody;
  18. import java.util.List;
  19. import static com.xy.utils.Beans.copy;
  20. /**
  21. * <p>
  22. * 算法平台 服务实现类
  23. * </p>
  24. *
  25. * @author hechunping
  26. * @since 2023-01-12
  27. */
  28. @Service
  29. @AllArgsConstructor
  30. @Api(tags = "算法平台")
  31. public class AlgorithmServiceImpl extends ServiceImpl<AlgorithmMapper, Algorithm> implements AlgorithmService {
  32. @ApiOperation("集合查询")
  33. public R<List<AlgorithmDto.Vo>> list(@RequestBody AlgorithmDto.SelectList selectList) {
  34. LambdaQueryWrapper<Algorithm> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(selectList, Algorithm.class).build();
  35. List<Algorithm> list = list(lambdaQueryWrapper);
  36. return R.ok(copy(AlgorithmDto.Vo.class, list));
  37. }
  38. @ApiOperation(value = "新增、更新算法平台", notes = "不传id为新增,传id为修改")
  39. public R saveOrUpdate(@Validated @RequestBody AlgorithmDto.Save saveDto) {
  40. Long id = saveDto.getId();
  41. boolean isAdd = id == null || id == 0;
  42. //判断品牌是否存在
  43. LambdaQueryWrapper<Algorithm> lambdaQueryWrapper = Wrappers.lambdaQuery();
  44. lambdaQueryWrapper.eq(Algorithm::getName, saveDto.getName()).last("limit 1").select(Algorithm::getName);
  45. Algorithm exists = getOne(lambdaQueryWrapper);
  46. if (exists != null) {
  47. if (isAdd) {
  48. return R.fail("平台已存在");
  49. } else {
  50. if (exists.getId().intValue() != saveDto.getId().intValue()) {
  51. return R.fail("平台已存在");
  52. }
  53. }
  54. }
  55. Algorithm algorithm = copy(Algorithm.class, saveDto);
  56. if (isAdd) {
  57. algorithm.createUserTime(1L).createId();
  58. baseMapper.insert(algorithm);
  59. } else {
  60. algorithm.updateUserTime(1L);
  61. baseMapper.updateById(algorithm);
  62. }
  63. return R.ok();
  64. }
  65. }