mirror of https://github.com/elunez/eladmin
收入支出类别
parent
b37d944d72
commit
acb99f3e3a
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,4 +17,6 @@ public interface SupplierCategoryService {
|
|||
void delete(Long id);
|
||||
|
||||
Object queryAll(SupplierCategoryDTO supplierCategory, Pageable pageable);
|
||||
|
||||
Object queryAll(SupplierCategoryDTO supplierCategory);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue