12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- package com.xy.service;
- 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.AuthorizeUtils;
- 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.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 {
- @Override
- @ApiOperation("所有字段列表")
- public R<List<AlgorithmDto.ListAllColumn>> listAllColumn(@RequestBody AlgorithmDto.ListAllColumn listAllColumn) {
- LambdaQueryWrapper<Algorithm> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(listAllColumn, Algorithm.class).build();
- List<Algorithm> list = list(lambdaQueryWrapper);
- return R.ok(copy(AlgorithmDto.ListAllColumn.class, list));
- }
- @Override
- @ApiOperation("ID和Name列表")
- public R<List<AlgorithmDto.ListNameId>> ListNameId() {
- LambdaQueryWrapper<Algorithm> lambdaQueryWrapper = Wrappers.<Algorithm>lambdaQuery().eq(Algorithm::getStatus,1).select(Algorithm::getId,Algorithm::getName);
- List<Algorithm> list = baseMapper.selectList(lambdaQueryWrapper);
- return R.ok(copy(AlgorithmDto.ListNameId.class, list));
- }
- @Override
- @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::getId);
- Algorithm exists = getOne(lambdaQueryWrapper);
- if (exists != null) {
- if (isAdd) {
- return R.fail("平台已存在");
- } else {
- if (exists.getId().longValue() != saveDto.getId().longValue()) {
- return R.fail("平台已存在");
- }
- }
- }
- Algorithm algorithm = copy(Algorithm.class, saveDto);
- if (isAdd) {
- algorithm.createUserTime(AuthorizeUtils.getLoginId(Long.class));
- baseMapper.insert(algorithm);
- } else {
- algorithm.updateUserTime(AuthorizeUtils.getLoginId(Long.class));
- baseMapper.updateById(algorithm);
- }
- return R.ok();
- }
- }
|