123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package com.xy.service;
- import cn.hutool.core.lang.Console;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.toolkit.Wrappers;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.xy.dto.AlgorithmDto;
- import com.xy.entity.Algorithm;
- import com.xy.mapper.AlgorithmMapper;
- import com.xy.utils.MybatisPlusQuery;
- import com.xy.utils.R;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import lombok.AllArgsConstructor;
- import org.springframework.stereotype.Service;
- import org.springframework.validation.annotation.Validated;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestBody;
- import java.util.List;
- import static com.xy.utils.Beans.copy;
- /**
- * <p>
- * 算法平台 服务实现类
- * </p>
- *
- * @author hechunping
- * @since 2023-01-12
- */
- @Service
- @AllArgsConstructor
- @Api(tags = "算法平台")
- public class AlgorithmServiceImpl extends ServiceImpl<AlgorithmMapper, Algorithm> implements AlgorithmService {
- @ApiOperation("集合查询")
- public R<List<AlgorithmDto.Vo>> list(@RequestBody AlgorithmDto.SelectList selectList) {
- LambdaQueryWrapper<Algorithm> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(selectList, Algorithm.class).build();
- List<Algorithm> list = list(lambdaQueryWrapper);
- return R.ok(copy(AlgorithmDto.Vo.class, list));
- }
- @ApiOperation(value = "新增、更新算法平台", notes = "不传id为新增,传id为修改")
- public R saveOrUpdate(@Validated @RequestBody AlgorithmDto.Save saveDto) {
- Long id = saveDto.getId();
- boolean isAdd = id == null || id == 0;
- //判断品牌是否存在
- LambdaQueryWrapper<Algorithm> lambdaQueryWrapper = Wrappers.lambdaQuery();
- lambdaQueryWrapper.eq(Algorithm::getName, saveDto.getName()).last("limit 1").select(Algorithm::getName);
- Algorithm exists = getOne(lambdaQueryWrapper);
- if (exists != null) {
- if (isAdd) {
- return R.fail("平台已存在");
- } else {
- if (exists.getId().intValue() != saveDto.getId().intValue()) {
- return R.fail("平台已存在");
- }
- }
- }
- Algorithm algorithm = copy(Algorithm.class, saveDto);
- if (isAdd) {
- algorithm.createUserTime(1L).createId();
- baseMapper.insert(algorithm);
- } else {
- algorithm.updateUserTime(1L);
- baseMapper.updateById(algorithm);
- }
- return R.ok();
- }
- }
|