pert: 增加lx名称校验

iec104
huangfeng 1 year ago
parent 6bd5592109
commit c2fc6c974b

@ -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 LxRepository extends JpaRepository<Lx, Integer>, JpaSpecificationExecutor<Lx> {
List<Lx> findByMc(String mc);
List<Lx> findByMcAndIdIsNot(String mc, Integer id);
}

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

@ -6,6 +6,7 @@ import com.xydl.cac.service.LxService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.List;
@ -24,13 +25,21 @@ public class LxServiceImpl implements LxService {
}
@Override
public Lx add(Lx item) {
public Lx add(Lx item) throws Exception {
item.setId(null);
List<Lx> list = repository.findByMc(item.getMc());
if (!CollectionUtils.isEmpty(list)) {
throw new Exception("该名称已被使用");
}
return repository.save(item);
}
@Override
public void update(Lx item) {
public void update(Lx item) throws Exception {
List<Lx> list = repository.findByMcAndIdIsNot(item.getMc(), item.getId());
if (!CollectionUtils.isEmpty(list)) {
throw new Exception("该名称已被使用");
}
repository.save(item);
}

Loading…
Cancel
Save