收入支出类别

pull/451/head
starrysky 2019-08-15 00:00:59 +08:00
parent b37d944d72
commit acb99f3e3a
11 changed files with 199 additions and 11 deletions

View File

@ -1,13 +1,52 @@
package me.zhengjie.modules.wms.bd.repository;
import me.zhengjie.modules.wms.bd.domain.IncomeCategory;
import me.zhengjie.modules.wms.bd.domain.MaterialCategory;
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;
/**
* @author
* @date 2019-07-26
*/
public interface IncomeCategoryRepository extends JpaRepository<IncomeCategory, Long>, JpaSpecificationExecutor {
/**
*
* @param id
* @return
*/
IncomeCategory findByIdAndStatusTrue(long id);
/**
* name
* @param name
* @return
*/
IncomeCategory findByNameAndStatusTrue(String name);
/**
* name
* @param name
* @return
*/
IncomeCategory findByNameAndStatusFalse(String name);
/**
* true
* @param id
*/
@Modifying
@Query(value = "update bd_income_category set status = 1 where id = ?1",nativeQuery = true)
void updateStatusToTrue(long id);
/**
* ()
* @param id
*/
@Modifying
@Query(value = "update bd_income_category set status = 0 where id = ?1",nativeQuery = true)
void deleteSupplierCategory(long id);
}

View File

@ -41,4 +41,12 @@ public interface MaterialCategoryRepository extends JpaRepository<MaterialCatego
@Modifying
@Query(value = "update bd_product_category set status = 1 where id = ?1",nativeQuery = true)
void updateStatusToTrue(long id);
/**
* ()
* @param id
*/
@Modifying
@Query(value = "update bd_product_category set status = 0 where id = ?1",nativeQuery = true)
void deleteMaterialCategory(long id);
}

View File

@ -1,8 +1,11 @@
package me.zhengjie.modules.wms.bd.repository;
import me.zhengjie.modules.wms.bd.domain.IncomeCategory;
import me.zhengjie.modules.wms.bd.domain.SpendCategory;
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;
/**
* @author
@ -10,4 +13,40 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
*/
public interface SpendCategoryRepository extends JpaRepository<SpendCategory, Long >, JpaSpecificationExecutor {
/**
*
* @param id
* @return
*/
SpendCategory findByIdAndStatusTrue(long id);
/**
* name
* @param name
* @return
*/
SpendCategory findByNameAndStatusTrue(String name);
/**
* name
* @param name
* @return
*/
SpendCategory findByNameAndStatusFalse(String name);
/**
* true
* @param id
*/
@Modifying
@Query(value = "update bd_spend_category set status = 1 where id = ?1",nativeQuery = true)
void updateStatusToTrue(long id);
/**
* ()
* @param id
*/
@Modifying
@Query(value = "update bd_spend_category set status = 0 where id = ?1",nativeQuery = true)
void deleteSpendCategory(long id);
}

View File

@ -48,9 +48,9 @@ public class IncomeCategoryController {
return new ResponseEntity(HttpStatus.OK);
}
@Log("查询收入分类")
@GetMapping(value = "/incomeCategory")
public ResponseEntity getIncomeCategorys(IncomeCategoryDTO resources, Pageable pageable){
@Log("分页查询收入分类")
@GetMapping(value = "/queryIncomeCategoryPage")
public ResponseEntity queryIncomeCategoryPage(IncomeCategoryDTO resources, Pageable pageable){
return new ResponseEntity(incomeCategoryService.queryAll(resources,pageable),HttpStatus.OK);
}
}

View File

@ -49,8 +49,8 @@ public class SpendCategoryController {
}
@Log("查询支出类别")
@GetMapping(value = "/spendCategory")
public ResponseEntity getDicts(SpendCategoryDTO resources, Pageable pageable){
@GetMapping(value = "/querySpendCategoryPage")
public ResponseEntity querySpendCategoryPage(SpendCategoryDTO resources, Pageable pageable){
return new ResponseEntity(spendCategoryService.queryAll(resources,pageable),HttpStatus.OK);
}
}

View File

@ -53,4 +53,10 @@ public class SupplierCategoryController {
public ResponseEntity querySupplierCategoryPage(SupplierCategoryDTO resources, Pageable pageable){
return new ResponseEntity(supplierCategoryService.queryAll(resources,pageable),HttpStatus.OK);
}
@Log("查询所有供应商类别")
@GetMapping(value = "/queryAllCategoryList")
public ResponseEntity queryAllCategoryList(SupplierCategoryDTO resources){
return new ResponseEntity(supplierCategoryService.queryAll(resources),HttpStatus.OK);
}
}

View File

@ -17,4 +17,6 @@ public interface SupplierCategoryService {
void delete(Long id);
Object queryAll(SupplierCategoryDTO supplierCategory, Pageable pageable);
Object queryAll(SupplierCategoryDTO supplierCategory);
}

View File

@ -1,6 +1,8 @@
package me.zhengjie.modules.wms.bd.service.impl;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.wms.bd.domain.IncomeCategory;
import me.zhengjie.modules.wms.bd.domain.MaterialCategory;
import me.zhengjie.modules.wms.bd.domain.ProductCategory;
import me.zhengjie.modules.wms.bd.repository.IncomeCategoryRepository;
import me.zhengjie.modules.wms.bd.service.IncomeCategoryService;
@ -43,7 +45,28 @@ public class IncomeCategoryServiceImpl implements IncomeCategoryService {
@Override
@Transactional(rollbackFor = Exception.class)
public IncomeCategoryDTO create(IncomeCategory resources) {
return incomeCategoryMapper.toDto(incomeCategoryRepository.save(resources));
/**
*
*
*
*/
IncomeCategory byNameAndStatusTrue = incomeCategoryRepository.findByNameAndStatusTrue(resources.getName());
if(null != byNameAndStatusTrue){
throw new BadRequestException("该物料类别已经存在");
}
IncomeCategory byNameAndStatusFalse = incomeCategoryRepository.findByNameAndStatusFalse(resources.getName());
if(null != byNameAndStatusFalse){
resources.setStatus(true);
incomeCategoryRepository.updateStatusToTrue(byNameAndStatusFalse.getId());
Optional<IncomeCategory> incomeCategoryOptional = incomeCategoryRepository.findById(byNameAndStatusFalse.getId());
IncomeCategory incomeCategory = incomeCategoryOptional.get();
return incomeCategoryMapper.toDto(incomeCategory);
}else{
resources.getName();
resources.setStatus(true);
IncomeCategory materialCategory = incomeCategoryRepository.save(resources);
return incomeCategoryMapper.toDto(materialCategory);
}
}
@Override
@ -57,7 +80,7 @@ public class IncomeCategoryServiceImpl implements IncomeCategoryService {
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
incomeCategoryRepository.deleteById(id);
incomeCategoryRepository.deleteSupplierCategory(id);
}
@Override

View File

@ -80,7 +80,7 @@ public class MaterialCategoryServiceImpl implements MaterialCategoryService {
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
materialCategoryRepository.deleteById(id);
materialCategoryRepository.deleteMaterialCategory(id);
}
@Override

View File

@ -1,5 +1,7 @@
package me.zhengjie.modules.wms.bd.service.impl;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.wms.bd.domain.IncomeCategory;
import me.zhengjie.modules.wms.bd.domain.SpendCategory;
import me.zhengjie.modules.wms.bd.repository.SpendCategoryRepository;
import me.zhengjie.modules.wms.bd.service.SpendCategoryService;
@ -11,10 +13,18 @@ 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;
/**
@ -34,7 +44,28 @@ public class SpendCategoryServiceImpl implements SpendCategoryService {
@Override
@Transactional(rollbackFor = Exception.class)
public SpendCategoryDTO create(SpendCategory resources) {
return spendCategoryMapper.toDto(spendCategoryRepository.save(resources));
/**
*
*
*
*/
SpendCategory byNameAndStatusTrue = spendCategoryRepository.findByNameAndStatusTrue(resources.getName());
if(null != byNameAndStatusTrue){
throw new BadRequestException("该物料类别已经存在");
}
SpendCategory byNameAndStatusFalse = spendCategoryRepository.findByNameAndStatusFalse(resources.getName());
if(null != byNameAndStatusFalse){
resources.setStatus(true);
spendCategoryRepository.updateStatusToTrue(byNameAndStatusFalse.getId());
Optional<SpendCategory> incomeCategoryOptional = spendCategoryRepository.findById(byNameAndStatusFalse.getId());
SpendCategory spendCategory = incomeCategoryOptional.get();
return spendCategoryMapper.toDto(spendCategory);
}else{
resources.getName();
resources.setStatus(true);
SpendCategory spendCategory = spendCategoryRepository.save(resources);
return spendCategoryMapper.toDto(spendCategory);
}
}
@Override
@ -48,12 +79,29 @@ public class SpendCategoryServiceImpl implements SpendCategoryService {
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
spendCategoryRepository.deleteById(id);
spendCategoryRepository.deleteSpendCategory(id);
}
@Override
public Object queryAll(SpendCategoryDTO spendCategory, Pageable pageable) {
Page<SpendCategory> page = spendCategoryRepository.findAll((root, query, cb) -> QueryHelp.getPredicate(root, spendCategory, cb), pageable);
Specification<SpendCategoryDTO> specification = new Specification<SpendCategoryDTO>() {
@Override
public Predicate toPredicate(Root<SpendCategoryDTO> 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<SpendCategory> page = spendCategoryRepository.findAll(specification, pageable);
return PageUtil.toPage(page.map(spendCategoryMapper::toDto));
}

View File

@ -106,4 +106,27 @@ public class SupplierCategoryServiceImpl implements SupplierCategoryService {
return PageUtil.toPage(page.map(supplierCategoryMapper::toDto));
}
@Override
public Object queryAll(SupplierCategoryDTO supplierCategory) {
Specification<SupplierCategory> specification = new Specification<SupplierCategory>() {
@Override
public Predicate toPredicate(Root<SupplierCategory> 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<SupplierCategory> supplierCategoryRepositoryList = supplierCategoryRepository.findAll(specification);
return supplierCategoryRepositoryList;
}
}