仓库业务删除

pull/451/head
starrysky 2019-07-27 12:01:22 +08:00
parent 070dbf3a02
commit d471b797c2
3 changed files with 48 additions and 5 deletions

View File

@ -3,6 +3,8 @@ package me.zhengjie.modules.wms.bd.repository;
import me.zhengjie.modules.wms.bd.domain.WareHouse;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
@ -12,5 +14,33 @@ import java.util.List;
*/
public interface WareHouseRepository extends JpaRepository<WareHouse, Long >, JpaSpecificationExecutor {
List<WareHouse> findByNameOrWareHouseCode(String name, String wareHouseCode);
/**
*
* @param name
* @param wareHouseCode
* @return
*/
@Query(value ="select * from bd_ware_house where (name = ?1 or ware_house_code = ?2) and status = 1", nativeQuery = true)
List<WareHouse> findByNameOrWareHouseCodeAndStatusTrue(String name, String wareHouseCode);
/**
*
* @param name
* @param wareHouseCode
* @return
*/
WareHouse findByNameAndWareHouseCodeAndStatusFalse(String name, String wareHouseCode);
/**
*
* @param id
*/
@Modifying
@Query(value = "update bd_ware_house set status = 0 where id = ?1",nativeQuery = true)
void deleteWareHouse(long id);
@Modifying
@Query(value = "update bd_ware_house set status = 1 where id = ?1",nativeQuery = true)
void updateStatusTrue(long id);
}

View File

@ -4,6 +4,7 @@ import me.zhengjie.modules.wms.bd.domain.WareHouse;
import me.zhengjie.modules.wms.bd.service.dto.WareHouseDTO;
import org.springframework.data.domain.Pageable;
/**
* @author
* @date 2019-07-27
@ -14,7 +15,8 @@ public interface WareHouseService {
WareHouseDTO findById(long id);
void delete(Long id);
void delete(long id);
Object queryAll(WareHouseDTO wareHouse, Pageable pageable);
}

View File

@ -38,10 +38,18 @@ public class WareHouseServiceImpl implements WareHouseService {
@Transactional(rollbackFor = Exception.class)
public WareHouseDTO create(WareHouse resources) {
//验证仓库编码或者仓库名字是否存在
List<WareHouse> wareHouseList = wareHouseRepository.findByNameOrWareHouseCode(resources.getName(), resources.getWareHouseCode());
List<WareHouse> wareHouseList = wareHouseRepository.findByNameOrWareHouseCodeAndStatusTrue(resources.getName(), resources.getWareHouseCode());
if(!CollectionUtils.isEmpty(wareHouseList)) {
throw new BadRequestException("仓库编码或编号已经存在");
}
WareHouse wareHouseDelete = wareHouseRepository.findByNameAndWareHouseCodeAndStatusFalse(resources.getName(), resources.getWareHouseCode());
if(null != wareHouseDelete){
wareHouseDelete.setStatus(true);
wareHouseRepository.updateStatusTrue(wareHouseDelete.getId());
return wareHouseMapper.toDto(wareHouseDelete);
}
return wareHouseMapper.toDto(wareHouseRepository.save(resources));
}
@ -55,8 +63,11 @@ public class WareHouseServiceImpl implements WareHouseService {
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
wareHouseRepository.deleteById(id);
public void delete(long id) {
Optional<WareHouse> wareHouseOptional = wareHouseRepository.findById(id);
WareHouse wareHouse = wareHouseOptional.get();
wareHouse.setStatus(false);
wareHouseRepository.deleteWareHouse(id);
}
@Override