mirror of https://github.com/elunez/eladmin
仓库业务删除
parent
070dbf3a02
commit
d471b797c2
|
@ -3,6 +3,8 @@ package me.zhengjie.modules.wms.bd.repository;
|
||||||
import me.zhengjie.modules.wms.bd.domain.WareHouse;
|
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 org.springframework.data.jpa.repository.Modifying;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -12,5 +14,33 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public interface WareHouseRepository extends JpaRepository<WareHouse, Long >, JpaSpecificationExecutor {
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import me.zhengjie.modules.wms.bd.domain.WareHouse;
|
||||||
import me.zhengjie.modules.wms.bd.service.dto.WareHouseDTO;
|
import me.zhengjie.modules.wms.bd.service.dto.WareHouseDTO;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 黄星星
|
* @author 黄星星
|
||||||
* @date 2019-07-27
|
* @date 2019-07-27
|
||||||
|
@ -14,7 +15,8 @@ public interface WareHouseService {
|
||||||
|
|
||||||
WareHouseDTO findById(long id);
|
WareHouseDTO findById(long id);
|
||||||
|
|
||||||
void delete(Long id);
|
void delete(long id);
|
||||||
|
|
||||||
Object queryAll(WareHouseDTO wareHouse, Pageable pageable);
|
Object queryAll(WareHouseDTO wareHouse, Pageable pageable);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,10 +38,18 @@ public class WareHouseServiceImpl implements WareHouseService {
|
||||||
@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());
|
List<WareHouse> wareHouseList = wareHouseRepository.findByNameOrWareHouseCodeAndStatusTrue(resources.getName(), resources.getWareHouseCode());
|
||||||
if(!CollectionUtils.isEmpty(wareHouseList)) {
|
if(!CollectionUtils.isEmpty(wareHouseList)) {
|
||||||
throw new BadRequestException("仓库编码或编号已经存在");
|
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));
|
return wareHouseMapper.toDto(wareHouseRepository.save(resources));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,8 +63,11 @@ public class WareHouseServiceImpl implements WareHouseService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void delete(Long id) {
|
public void delete(long id) {
|
||||||
wareHouseRepository.deleteById(id);
|
Optional<WareHouse> wareHouseOptional = wareHouseRepository.findById(id);
|
||||||
|
WareHouse wareHouse = wareHouseOptional.get();
|
||||||
|
wareHouse.setStatus(false);
|
||||||
|
wareHouseRepository.deleteWareHouse(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue