仓库设置

pull/451/head
starrysky 2019-08-16 00:32:43 +08:00
parent b5d26b09f8
commit f8b809cea6
3 changed files with 47 additions and 6 deletions

View File

@ -20,7 +20,7 @@ public interface WareHouseRepository extends JpaRepository<WareHouse, Long >, Jp
* @param wareHouseCode
* @return
*/
@Query(value ="select * from bd_ware_house where (name = ?1 or ware_house_code = ?2) and status = 1", nativeQuery = true)
@Query(value ="select * from bd_ware_house where name = ?1 and ware_house_code = ?2 and status = 1", nativeQuery = true)
List<WareHouse> findByNameOrWareHouseCodeAndStatusTrue(String name, String wareHouseCode);
@ -30,6 +30,7 @@ public interface WareHouseRepository extends JpaRepository<WareHouse, Long >, Jp
* @param wareHouseCode
* @return
*/
@Query(value ="select * from bd_ware_house where name = ?1 and ware_house_code = ?2 and status = 0", nativeQuery = true)
WareHouse findByNameAndWareHouseCodeAndStatusFalse(String name, String wareHouseCode);
/**

View File

@ -32,7 +32,7 @@ public class WareHouseController {
@Log("新增仓库")
@PostMapping(value = "/wareHouse")
public ResponseEntity create(@Validated @RequestBody WareHouse resources){
public ResponseEntity create(@RequestBody WareHouse resources){
if (resources.getId() != null) {
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
}
@ -62,8 +62,8 @@ public class WareHouseController {
}
@Log("分页查询仓库")
@GetMapping(value = "/wareHouses")
public ResponseEntity getWareHouses(WareHouseQueryCriteria wareHouseQueryCriteria, Pageable pageable){
@GetMapping(value = "/queryWareHousePage")
public ResponseEntity queryWareHousePage(WareHouseQueryCriteria wareHouseQueryCriteria, Pageable pageable){
return new ResponseEntity(wareHouseService.queryAll(wareHouseQueryCriteria,pageable),HttpStatus.OK);
}

View File

@ -1,6 +1,7 @@
package me.zhengjie.modules.wms.bd.service.impl;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.wms.bd.domain.SupplierInfo;
import me.zhengjie.modules.wms.bd.domain.WareHouse;
import me.zhengjie.modules.wms.bd.repository.WareHouseRepository;
import me.zhengjie.modules.wms.bd.service.WareHouseService;
@ -13,11 +14,17 @@ import me.zhengjie.utils.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@ -51,6 +58,7 @@ public class WareHouseServiceImpl implements WareHouseService {
return wareHouseMapper.toDto(wareHouseDelete);
}
resources.setStatus(true);
return wareHouseMapper.toDto(wareHouseRepository.save(resources));
}
@ -73,13 +81,45 @@ public class WareHouseServiceImpl implements WareHouseService {
@Override
public Object queryAll(WareHouseQueryCriteria wareHouseQueryCriteria, Pageable pageable) {
Page<WareHouse> page = wareHouseRepository.findAll((root, query, cb) -> QueryHelp.getPredicate(root, wareHouseQueryCriteria, cb), pageable);
Specification<WareHouse> specification = new Specification<WareHouse>() {
@Override
public Predicate toPredicate(Root<WareHouse> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
List<Predicate> targetPredicateList = new ArrayList<>();
Predicate statusPredicate = criteriaBuilder.equal(root.get("status"), 1);
targetPredicateList.add(statusPredicate);
if(CollectionUtils.isEmpty(targetPredicateList)){
return null;
}else{
return criteriaBuilder.and(targetPredicateList.toArray(new Predicate[targetPredicateList.size()]));
}
}
};
Page<WareHouse> page = wareHouseRepository.findAll(specification, pageable);
return PageUtil.toPage(page.map(wareHouseMapper::toDto));
}
@Override
public Object queryAll(WareHouseQueryCriteria wareHouseQueryCriteria) {
List<WareHouse> wareHouseList = wareHouseRepository.findAll((root, query, cb) -> QueryHelp.getPredicate(root, wareHouseQueryCriteria, cb));
Specification<WareHouse> specification = new Specification<WareHouse>() {
@Override
public Predicate toPredicate(Root<WareHouse> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
List<Predicate> targetPredicateList = new ArrayList<>();
Predicate statusPredicate = criteriaBuilder.equal(root.get("status"), 1);
targetPredicateList.add(statusPredicate);
if(CollectionUtils.isEmpty(targetPredicateList)){
return null;
}else{
return criteriaBuilder.and(targetPredicateList.toArray(new Predicate[targetPredicateList.size()]));
}
}
};
List<WareHouse> wareHouseList = wareHouseRepository.findAll(specification);
return wareHouseList;
}