|
|
@ -6,6 +6,7 @@ import com.xydl.cac.service.ModevTypeService;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
@ -28,7 +29,7 @@ public class ModevTypeServiceImpl implements ModevTypeService {
|
|
|
|
public ModevType add(ModevType item) throws Exception {
|
|
|
|
public ModevType add(ModevType item) throws Exception {
|
|
|
|
item.setId(null);
|
|
|
|
item.setId(null);
|
|
|
|
List<ModevType> byMc = repository.findByMc(item.getMc());
|
|
|
|
List<ModevType> byMc = repository.findByMc(item.getMc());
|
|
|
|
if (!byMc.isEmpty()) {
|
|
|
|
if (!CollectionUtils.isEmpty(byMc)) {
|
|
|
|
throw new Exception("该监测装置类型已存在");
|
|
|
|
throw new Exception("该监测装置类型已存在");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return repository.save(item);
|
|
|
|
return repository.save(item);
|
|
|
@ -37,8 +38,12 @@ public class ModevTypeServiceImpl implements ModevTypeService {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void update(ModevType item) throws Exception {
|
|
|
|
public void update(ModevType item) throws Exception {
|
|
|
|
List<ModevType> byMc = repository.findByMc(item.getMc());
|
|
|
|
List<ModevType> byMc = repository.findByMc(item.getMc());
|
|
|
|
if (!byMc.isEmpty()) {
|
|
|
|
if (!CollectionUtils.isEmpty(byMc)) {
|
|
|
|
throw new Exception("该监测装置类型已存在");
|
|
|
|
for (ModevType it : byMc) {
|
|
|
|
|
|
|
|
if (it.getId() != item.getId()) {
|
|
|
|
|
|
|
|
throw new Exception("该监测装置类型已存在");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
repository.save(item);
|
|
|
|
repository.save(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|