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; /** *

* 算法平台 服务实现类 *

* * @author hechunping * @since 2023-01-12 */ @Service @AllArgsConstructor @Api(tags = "算法平台") public class AlgorithmServiceImpl extends ServiceImpl implements AlgorithmService { @ApiOperation("集合查询") public R> list(@RequestBody AlgorithmDto.SelectList selectList) { LambdaQueryWrapper lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(selectList, Algorithm.class).build(); List 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 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(); } }