AlgorithmServiceImpl.java 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package com.xy.service;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  4. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  5. import com.xy.dto.AlgorithmDto;
  6. import com.xy.entity.Algorithm;
  7. import com.xy.mapper.AlgorithmMapper;
  8. import com.xy.utils.AuthorizeUtils;
  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.RequestBody;
  17. import java.util.List;
  18. import static com.xy.utils.Beans.copy;
  19. /**
  20. * <p>
  21. * 算法平台 服务实现类
  22. * </p>
  23. *
  24. * @author hechunping
  25. * @since 2023-01-12
  26. */
  27. @Service
  28. @AllArgsConstructor
  29. @Api(tags = "算法平台")
  30. public class AlgorithmServiceImpl extends ServiceImpl<AlgorithmMapper, Algorithm> implements AlgorithmService {
  31. @Override
  32. @ApiOperation("所有字段列表")
  33. public R<List<AlgorithmDto.ListAllColumn>> listAllColumn(@RequestBody AlgorithmDto.ListAllColumn listAllColumn) {
  34. LambdaQueryWrapper<Algorithm> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(listAllColumn, Algorithm.class).build();
  35. List<Algorithm> list = list(lambdaQueryWrapper);
  36. return R.ok(copy(AlgorithmDto.ListAllColumn.class, list));
  37. }
  38. @Override
  39. @ApiOperation("ID和Name列表")
  40. public R<List<AlgorithmDto.ListNameId>> ListNameId() {
  41. LambdaQueryWrapper<Algorithm> lambdaQueryWrapper = Wrappers.<Algorithm>lambdaQuery().eq(Algorithm::getStatus,1).select(Algorithm::getId,Algorithm::getName);
  42. List<Algorithm> list = baseMapper.selectList(lambdaQueryWrapper);
  43. return R.ok(copy(AlgorithmDto.ListNameId.class, list));
  44. }
  45. @Override
  46. @ApiOperation(value = "新增、更新算法平台", notes = "不传id为新增,传id为修改")
  47. public R saveOrUpdate(@Validated @RequestBody AlgorithmDto.Save saveDto) {
  48. Long id = saveDto.getId();
  49. boolean isAdd = id == null || id == 0;
  50. //判断品牌是否存在
  51. LambdaQueryWrapper<Algorithm> lambdaQueryWrapper = Wrappers.lambdaQuery();
  52. lambdaQueryWrapper.eq(Algorithm::getName, saveDto.getName()).last("limit 1").select(Algorithm::getId);
  53. Algorithm exists = getOne(lambdaQueryWrapper);
  54. if (exists != null) {
  55. if (isAdd) {
  56. return R.fail("平台已存在");
  57. } else {
  58. if (exists.getId().longValue() != saveDto.getId().longValue()) {
  59. return R.fail("平台已存在");
  60. }
  61. }
  62. }
  63. Algorithm algorithm = copy(Algorithm.class, saveDto);
  64. if (isAdd) {
  65. algorithm.createUserTime(AuthorizeUtils.getLoginId(Long.class));
  66. baseMapper.insert(algorithm);
  67. } else {
  68. algorithm.updateUserTime(AuthorizeUtils.getLoginId(Long.class));
  69. baseMapper.updateById(algorithm);
  70. }
  71. return R.ok();
  72. }
  73. }