仓库编码

pull/451/head
starrysky 2019-07-27 11:22:11 +08:00
parent 658d2348b5
commit 070dbf3a02
2 changed files with 11 additions and 0 deletions

View File

@ -4,10 +4,13 @@ import me.zhengjie.modules.wms.bd.domain.WareHouse;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.util.List;
/** /**
* @author * @author
* @date 2019-07-26 * @date 2019-07-26
*/ */
public interface WareHouseRepository extends JpaRepository<WareHouse, Long >, JpaSpecificationExecutor { public interface WareHouseRepository extends JpaRepository<WareHouse, Long >, JpaSpecificationExecutor {
List<WareHouse> findByNameOrWareHouseCode(String name, String wareHouseCode);
} }

View File

@ -1,5 +1,6 @@
package me.zhengjie.modules.wms.bd.service.impl; package me.zhengjie.modules.wms.bd.service.impl;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.wms.bd.domain.WareHouse; import me.zhengjie.modules.wms.bd.domain.WareHouse;
import me.zhengjie.modules.wms.bd.repository.WareHouseRepository; import me.zhengjie.modules.wms.bd.repository.WareHouseRepository;
import me.zhengjie.modules.wms.bd.service.WareHouseService; import me.zhengjie.modules.wms.bd.service.WareHouseService;
@ -14,7 +15,9 @@ import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.Optional; import java.util.Optional;
/** /**
@ -34,6 +37,11 @@ public class WareHouseServiceImpl implements WareHouseService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public WareHouseDTO create(WareHouse resources) { public WareHouseDTO create(WareHouse resources) {
//验证仓库编码或者仓库名字是否存在
List<WareHouse> wareHouseList = wareHouseRepository.findByNameOrWareHouseCode(resources.getName(), resources.getWareHouseCode());
if(!CollectionUtils.isEmpty(wareHouseList)) {
throw new BadRequestException("仓库编码或编号已经存在");
}
return wareHouseMapper.toDto(wareHouseRepository.save(resources)); return wareHouseMapper.toDto(wareHouseRepository.save(resources));
} }