pert: 增加bdz名称校验

dev
huangfeng 1 year ago
parent 03e51f05af
commit c16a02bf87

@ -5,8 +5,13 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface BdzRepository extends JpaRepository<Bdz, Integer>, JpaSpecificationExecutor<Bdz> {
List<Bdz> findByMc(String mc);
List<Bdz> findByMcAndIdIsNot(String mc, Integer id);
}

@ -8,9 +8,9 @@ public interface BdzService {
List<Bdz> listAll();
Bdz add(Bdz item);
Bdz add(Bdz item) throws Exception;
void update(Bdz item);
void update(Bdz item) throws Exception;
void delete(Integer id) throws Exception;
}

@ -29,13 +29,21 @@ public class BdzServiceImpl implements BdzService {
}
@Override
public Bdz add(Bdz item) {
public Bdz add(Bdz item) throws Exception {
item.setId(null);
List<Bdz> list = repository.findByMc(item.getMc());
if (!CollectionUtils.isEmpty(list)) {
throw new Exception("该名称已被使用");
}
return repository.save(item);
}
@Override
public void update(Bdz item) {
public void update(Bdz item) throws Exception {
List<Bdz> list = repository.findByMcAndIdIsNot(item.getMc(), item.getId());
if (!CollectionUtils.isEmpty(list)) {
throw new Exception("该名称已被使用");
}
repository.save(item);
}

Loading…
Cancel
Save