refactor(服务层): 重构多个服务类继承EntityService基类
统一服务层实现,将PurchaseBillVoucherItemService、PurchaseOrdersService等服务类重构为继承EntityService基类 移除重复代码,实现通用CRUD操作 更新文档标记服务可用性 优化查询规范和缓存配置
This commit is contained in:
@@ -2,25 +2,22 @@ package com.ecep.contract.ds.contract.service;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.ecep.contract.util.SpecificationUtils;
|
|
||||||
import com.ecep.contract.vo.ContractVo;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cache.annotation.CacheConfig;
|
import org.springframework.cache.annotation.CacheConfig;
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.cache.annotation.Caching;
|
import org.springframework.cache.annotation.Caching;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.data.domain.Page;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import org.springframework.data.domain.Sort;
|
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.ecep.contract.EntityService;
|
||||||
import com.ecep.contract.IEntityService;
|
import com.ecep.contract.IEntityService;
|
||||||
import com.ecep.contract.QueryService;
|
import com.ecep.contract.QueryService;
|
||||||
import com.ecep.contract.ds.contract.repository.PurchaseBillVoucherItemRepository;
|
import com.ecep.contract.ds.contract.repository.PurchaseBillVoucherItemRepository;
|
||||||
import com.ecep.contract.ds.vendor.model.PurchaseBillVoucherItem;
|
import com.ecep.contract.ds.vendor.model.PurchaseBillVoucherItem;
|
||||||
import com.ecep.contract.service.VoableService;
|
import com.ecep.contract.service.VoableService;
|
||||||
|
import com.ecep.contract.vo.ContractVo;
|
||||||
import com.ecep.contract.vo.PurchaseBillVoucherItemVo;
|
import com.ecep.contract.vo.PurchaseBillVoucherItemVo;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
|
||||||
@@ -28,25 +25,31 @@ import com.fasterxml.jackson.databind.JsonNode;
|
|||||||
@Service
|
@Service
|
||||||
@CacheConfig(cacheNames = "purchase-bill-voucher-item")
|
@CacheConfig(cacheNames = "purchase-bill-voucher-item")
|
||||||
public class PurchaseBillVoucherItemService
|
public class PurchaseBillVoucherItemService
|
||||||
implements IEntityService<PurchaseBillVoucherItem>, QueryService<PurchaseBillVoucherItem>,
|
extends EntityService<PurchaseBillVoucherItem, PurchaseBillVoucherItemVo, Integer>
|
||||||
|
implements IEntityService<PurchaseBillVoucherItem>, QueryService<PurchaseBillVoucherItemVo>,
|
||||||
VoableService<PurchaseBillVoucherItem, PurchaseBillVoucherItemVo> {
|
VoableService<PurchaseBillVoucherItem, PurchaseBillVoucherItemVo> {
|
||||||
@Lazy
|
@Lazy
|
||||||
@Autowired
|
@Autowired
|
||||||
private PurchaseBillVoucherItemRepository repository;
|
private PurchaseBillVoucherItemRepository repository;
|
||||||
|
|
||||||
@Override
|
|
||||||
public PurchaseBillVoucherItem getById(Integer id) {
|
|
||||||
return repository.findById(id).orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Cacheable(key = "#p0")
|
@Cacheable(key = "#p0")
|
||||||
@Override
|
@Override
|
||||||
public PurchaseBillVoucherItem findById(Integer id) {
|
public PurchaseBillVoucherItemVo findById(Integer id) {
|
||||||
return repository.findById(id).orElse(null);
|
return repository.findById(id).map(PurchaseBillVoucherItem::toVo).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Specification<PurchaseBillVoucherItem> getSearchSpecification(String searchText) {
|
protected PurchaseBillVoucherItemRepository getRepository() {
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PurchaseBillVoucherItem createNewEntity() {
|
||||||
|
return new PurchaseBillVoucherItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Specification<PurchaseBillVoucherItem> buildSearchSpecification(String searchText) {
|
||||||
return (root, query, builder) -> {
|
return (root, query, builder) -> {
|
||||||
return builder.or(
|
return builder.or(
|
||||||
builder.like(root.get("description"), "%" + searchText + "%"));
|
builder.like(root.get("description"), "%" + searchText + "%"));
|
||||||
@@ -54,19 +57,8 @@ public class PurchaseBillVoucherItemService
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<PurchaseBillVoucherItem> findAll(Specification<PurchaseBillVoucherItem> spec, Pageable pageable) {
|
protected Specification<PurchaseBillVoucherItem> buildParameterSpecification(JsonNode paramsNode) {
|
||||||
return repository.findAll(spec, pageable);
|
return null;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Page<PurchaseBillVoucherItem> findAll(JsonNode paramsNode, Pageable pageable) {
|
|
||||||
Specification<PurchaseBillVoucherItem> spec = null;
|
|
||||||
if (paramsNode.has("searchText")) {
|
|
||||||
spec = getSearchSpecification(paramsNode.get("searchText").asText());
|
|
||||||
}
|
|
||||||
|
|
||||||
spec = SpecificationUtils.andParam(spec, paramsNode, "voucher");
|
|
||||||
return findAll(spec, pageable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Caching(evict = {
|
@Caching(evict = {
|
||||||
@@ -87,10 +79,6 @@ public class PurchaseBillVoucherItemService
|
|||||||
return repository.save(entity);
|
return repository.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PurchaseBillVoucherItem> findAll(Specification<PurchaseBillVoucherItem> spec, Sort sort) {
|
|
||||||
return repository.findAll(spec, sort);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateByVo(PurchaseBillVoucherItem model, PurchaseBillVoucherItemVo vo) {
|
public void updateByVo(PurchaseBillVoucherItem model, PurchaseBillVoucherItemVo vo) {
|
||||||
model.setId(vo.getId());
|
model.setId(vo.getId());
|
||||||
|
|||||||
@@ -1,12 +1,7 @@
|
|||||||
package com.ecep.contract.ds.contract.service;
|
package com.ecep.contract.ds.contract.service;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.ecep.contract.ds.vendor.model.PurchaseBillVoucherItem;
|
|
||||||
import com.ecep.contract.ds.vendor.model.PurchaseOrderItem;
|
|
||||||
import jakarta.persistence.criteria.Root;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cache.annotation.CacheConfig;
|
import org.springframework.cache.annotation.CacheConfig;
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
@@ -18,11 +13,12 @@ import org.springframework.data.domain.Pageable;
|
|||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
|
import com.ecep.contract.EntityService;
|
||||||
import com.ecep.contract.IEntityService;
|
import com.ecep.contract.IEntityService;
|
||||||
import com.ecep.contract.QueryService;
|
import com.ecep.contract.QueryService;
|
||||||
import com.ecep.contract.SpringApp;
|
import com.ecep.contract.SpringApp;
|
||||||
|
import com.ecep.contract.ds.MyRepository;
|
||||||
import com.ecep.contract.ds.company.service.CompanyService;
|
import com.ecep.contract.ds.company.service.CompanyService;
|
||||||
import com.ecep.contract.ds.company.service.InvoiceService;
|
import com.ecep.contract.ds.company.service.InvoiceService;
|
||||||
import com.ecep.contract.ds.contract.repository.PurchaseBillVoucherRepository;
|
import com.ecep.contract.ds.contract.repository.PurchaseBillVoucherRepository;
|
||||||
@@ -39,40 +35,21 @@ import com.fasterxml.jackson.databind.JsonNode;
|
|||||||
@Lazy
|
@Lazy
|
||||||
@Service
|
@Service
|
||||||
@CacheConfig(cacheNames = "purchase-bill-voucher")
|
@CacheConfig(cacheNames = "purchase-bill-voucher")
|
||||||
public class PurchaseBillVoucherService
|
public class PurchaseBillVoucherService extends EntityService<PurchaseBillVoucher, PurchaseBillVoucherVo, Integer>
|
||||||
implements IEntityService<PurchaseBillVoucher>, QueryService<PurchaseBillVoucherVo>,
|
implements IEntityService<PurchaseBillVoucher>, QueryService<PurchaseBillVoucherVo>,
|
||||||
VoableService<PurchaseBillVoucher, PurchaseBillVoucherVo> {
|
VoableService<PurchaseBillVoucher, PurchaseBillVoucherVo> {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(PurchaseBillVoucherService.class);
|
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
@Autowired
|
@Autowired
|
||||||
private PurchaseBillVoucherRepository repository;
|
private PurchaseBillVoucherRepository repository;
|
||||||
|
|
||||||
@Override
|
|
||||||
public PurchaseBillVoucher getById(Integer id) {
|
|
||||||
return repository.findById(id).orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Cacheable(key = "#p0")
|
@Cacheable(key = "#p0")
|
||||||
public PurchaseBillVoucherVo findById(Integer id) {
|
public PurchaseBillVoucherVo findById(Integer id) {
|
||||||
return repository.findById(id).map(PurchaseBillVoucher::toVo).orElse(null);
|
return repository.findById(id).map(PurchaseBillVoucher::toVo).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Specification<PurchaseBillVoucher> getSearchSpecification(String searchText) {
|
|
||||||
// if null
|
|
||||||
if (!StringUtils.hasText(searchText)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (root, query, builder) -> {
|
|
||||||
return builder.or(
|
|
||||||
builder.like(root.get("code"), "%" + searchText + "%"),
|
|
||||||
builder.like(root.get("description"), "%" + searchText + "%"));
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Cacheable(key = "'code-'+#p0")
|
@Cacheable(key = "'code-'+#p0")
|
||||||
public PurchaseBillVoucherVo findByCode(String code) {
|
public PurchaseBillVoucherVo findByCode(String code) {
|
||||||
return repository.findByCode(code).map(PurchaseBillVoucher::toVo).orElse(null);
|
return repository.findByCode(code).map(PurchaseBillVoucher::toVo).orElse(null);
|
||||||
@@ -88,16 +65,17 @@ public class PurchaseBillVoucherService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存实体对象,异步方法
|
* 保存实体对象
|
||||||
*
|
*
|
||||||
* @param voucher 要保存的实体对象
|
* @param voucher 要保存的实体对象
|
||||||
* @return 返回异步调用
|
* @return 返回保存后的实体
|
||||||
*/
|
*/
|
||||||
@Caching(evict = {
|
@Caching(evict = {
|
||||||
@CacheEvict(key = "#p0.id"),
|
@CacheEvict(key = "#p0.id"),
|
||||||
@CacheEvict(key = "'code-'+#p0.code"),
|
@CacheEvict(key = "'code-'+#p0.code"),
|
||||||
@CacheEvict(key = "'refId-'+#p0.refId")
|
@CacheEvict(key = "'refId-'+#p0.refId")
|
||||||
})
|
})
|
||||||
|
@Override
|
||||||
public PurchaseBillVoucher save(PurchaseBillVoucher voucher) {
|
public PurchaseBillVoucher save(PurchaseBillVoucher voucher) {
|
||||||
return repository.save(voucher);
|
return repository.save(voucher);
|
||||||
}
|
}
|
||||||
@@ -112,47 +90,30 @@ public class PurchaseBillVoucherService
|
|||||||
repository.delete(order);
|
repository.delete(order);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long count() {
|
|
||||||
return repository.count();
|
|
||||||
}
|
|
||||||
|
|
||||||
public long count(Specification<PurchaseBillVoucher> spec) {
|
@Override
|
||||||
return repository.count(spec);
|
protected Specification<PurchaseBillVoucher> buildParameterSpecification(JsonNode paramsNode) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'buildParameterSpecification'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<PurchaseBillVoucher> findAll(Specification<PurchaseBillVoucher> spec, Pageable pageable) {
|
protected PurchaseBillVoucherRepository getRepository() {
|
||||||
return repository.findAll(spec, pageable);
|
return repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<PurchaseBillVoucherVo> findAll(JsonNode paramsNode, Pageable pageable) {
|
public PurchaseBillVoucher createNewEntity() {
|
||||||
Specification<PurchaseBillVoucher> spec = null;
|
return new PurchaseBillVoucher();
|
||||||
if (paramsNode.has("searchText")) {
|
|
||||||
spec = getSearchSpecification(paramsNode.get("searchText").asText());
|
|
||||||
}
|
|
||||||
// field
|
|
||||||
spec = SpecificationUtils.andParam(spec, paramsNode, "company", "inventory");
|
|
||||||
if (paramsNode.has("purchaseOrder")) {
|
|
||||||
spec = SpecificationUtils.and(spec, (root, query, cb) -> {
|
|
||||||
Root<PurchaseBillVoucherItem> voucherItemRoot = query.from(PurchaseBillVoucherItem.class);
|
|
||||||
Root<PurchaseOrderItem> orderItemRoot = query.from(PurchaseOrderItem.class);
|
|
||||||
return cb.and(
|
|
||||||
cb.equal(voucherItemRoot.get("orderItem"), orderItemRoot),
|
|
||||||
cb.equal(orderItemRoot.get("order").get("id"), paramsNode.get("purchaseOrder").asInt()),
|
|
||||||
cb.equal(root, voucherItemRoot.get("voucher"))
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return findAll(spec, pageable).map(PurchaseBillVoucher::toVo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PurchaseBillVoucher> findAll(Specification<PurchaseBillVoucher> spec, Sort sort) {
|
@Override
|
||||||
return repository.findAll(spec, sort);
|
protected Specification<PurchaseBillVoucher> buildSearchSpecification(String searchText) {
|
||||||
}
|
return (root, query, builder) -> {
|
||||||
|
return builder.or(
|
||||||
public List<PurchaseBillVoucher> search(String searchText) {
|
builder.like(root.get("code"), "%" + searchText + "%"),
|
||||||
return repository.findAll(getSearchSpecification(searchText), Pageable.ofSize(10)).getContent();
|
builder.like(root.get("description"), "%" + searchText + "%"));
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -200,4 +161,5 @@ public class PurchaseBillVoucherService
|
|||||||
model.setVerifier(employeeService.getById(vo.getVerifierId()));
|
model.setVerifier(employeeService.getById(vo.getVerifierId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,6 @@ package com.ecep.contract.ds.contract.service;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import com.ecep.contract.ds.vendor.model.PurchaseOrder;
|
|
||||||
import com.ecep.contract.vo.ContractItemVo;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cache.annotation.CacheConfig;
|
import org.springframework.cache.annotation.CacheConfig;
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
@@ -15,38 +11,31 @@ import org.springframework.cache.annotation.Caching;
|
|||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
|
import com.ecep.contract.EntityService;
|
||||||
import com.ecep.contract.IEntityService;
|
import com.ecep.contract.IEntityService;
|
||||||
import com.ecep.contract.QueryService;
|
import com.ecep.contract.QueryService;
|
||||||
import com.ecep.contract.SpringApp;
|
import com.ecep.contract.SpringApp;
|
||||||
import com.ecep.contract.ds.contract.repository.PurchaseOrderItemRepository;
|
import com.ecep.contract.ds.contract.repository.PurchaseOrderItemRepository;
|
||||||
import com.ecep.contract.ds.other.service.InventoryService;
|
import com.ecep.contract.ds.other.service.InventoryService;
|
||||||
|
import com.ecep.contract.ds.vendor.model.PurchaseOrder;
|
||||||
import com.ecep.contract.ds.vendor.model.PurchaseOrderItem;
|
import com.ecep.contract.ds.vendor.model.PurchaseOrderItem;
|
||||||
import com.ecep.contract.service.ServiceException;
|
import com.ecep.contract.service.ServiceException;
|
||||||
import com.ecep.contract.service.VoableService;
|
import com.ecep.contract.service.VoableService;
|
||||||
import com.ecep.contract.util.SpecificationUtils;
|
|
||||||
import com.ecep.contract.vo.PurchaseOrderItemVo;
|
import com.ecep.contract.vo.PurchaseOrderItemVo;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
@Service
|
@Service
|
||||||
@CacheConfig(cacheNames = "contract-purchase-order-item")
|
@CacheConfig(cacheNames = "contract-purchase-order-item")
|
||||||
public class PurchaseOrderItemService implements IEntityService<PurchaseOrderItem>, QueryService<PurchaseOrderItemVo>,
|
public class PurchaseOrderItemService extends EntityService<PurchaseOrderItem, PurchaseOrderItemVo, Integer> implements IEntityService<PurchaseOrderItem>, QueryService<PurchaseOrderItemVo>,
|
||||||
VoableService<PurchaseOrderItem, PurchaseOrderItemVo> {
|
VoableService<PurchaseOrderItem, PurchaseOrderItemVo> {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(PurchaseOrderItemService.class);
|
|
||||||
@Lazy
|
@Lazy
|
||||||
@Autowired
|
@Autowired
|
||||||
private PurchaseOrderItemRepository repository;
|
private PurchaseOrderItemRepository repository;
|
||||||
|
|
||||||
@Override
|
|
||||||
public PurchaseOrderItem getById(Integer id) {
|
|
||||||
return repository.findById(id).orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Cacheable(key = "#p0")
|
@Cacheable(key = "#p0")
|
||||||
@Override
|
@Override
|
||||||
public PurchaseOrderItemVo findById(Integer id) {
|
public PurchaseOrderItemVo findById(Integer id) {
|
||||||
@@ -62,59 +51,13 @@ public class PurchaseOrderItemService implements IEntityService<PurchaseOrderIte
|
|||||||
while (list.size() > 1) {
|
while (list.size() > 1) {
|
||||||
PurchaseOrderItem item = list.removeLast();
|
PurchaseOrderItem item = list.removeLast();
|
||||||
repository.delete(item);
|
repository.delete(item);
|
||||||
if (logger.isInfoEnabled()) {
|
|
||||||
logger.info("Duplicate PurchaseOrderItem, Delete {}", item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return list.getFirst().toVo();
|
return list.getFirst().toVo();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Specification<PurchaseOrderItem> getSearchSpecification(String searchText) {
|
|
||||||
if (!StringUtils.hasText(searchText)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return (root, query, builder) -> {
|
|
||||||
return builder.or(builder.like(root.get("description"), "%" + searchText + "%"));
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Page<PurchaseOrderItem> findAll(Specification<PurchaseOrderItem> spec, Pageable pageable) {
|
|
||||||
return repository.findAll(spec, pageable);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<PurchaseOrderItemVo> findAll(JsonNode paramsNode, Pageable pageable) {
|
public Page<PurchaseOrderItemVo> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||||
Specification<PurchaseOrderItem> spec = null;
|
return super.findAll(paramsNode, pageable);
|
||||||
if (paramsNode.has("searchText")) {
|
|
||||||
spec = getSearchSpecification(paramsNode.get("searchText").asText());
|
|
||||||
}
|
|
||||||
// field
|
|
||||||
spec = SpecificationUtils.andParam(spec, paramsNode, "order", "inventory", "contractItem");
|
|
||||||
|
|
||||||
// if (paramsNode.has("contractItem")) {
|
|
||||||
// ContractItemService itemService = SpringApp.getBean(ContractItemService.class);
|
|
||||||
// var contractItem = itemService.findById(paramsNode.get("contractItem").asInt());
|
|
||||||
//
|
|
||||||
// if (contractItem.getInventoryId() == null) {
|
|
||||||
// spec = SpecificationUtils.and(spec, (root, query, builder) -> {
|
|
||||||
// return builder.and(
|
|
||||||
// builder.equal(root.get("order").get("contract").get("id"), contractItem.getContractId()),
|
|
||||||
// builder.equal(root.get("inventory").get("id"), null)
|
|
||||||
// );
|
|
||||||
// });
|
|
||||||
// } else {
|
|
||||||
// spec = SpecificationUtils.and(spec, (root, query, builder) -> {
|
|
||||||
// return builder.and(
|
|
||||||
// builder.equal(root.get("order").get("contract").get("id"), contractItem.getContractId()),
|
|
||||||
// builder.equal(root.get("inventory").get("id"), contractItem.getInventoryId())
|
|
||||||
// );
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
return findAll(spec, pageable).map(PurchaseOrderItem::toVo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Caching(evict = {
|
@Caching(evict = {
|
||||||
@@ -134,10 +77,6 @@ public class PurchaseOrderItemService implements IEntityService<PurchaseOrderIte
|
|||||||
return repository.save(entity);
|
return repository.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PurchaseOrderItem> findAll(Specification<PurchaseOrderItem> spec, Sort sort) {
|
|
||||||
return repository.findAll(spec, sort);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateByVo(PurchaseOrderItem model, PurchaseOrderItemVo vo) {
|
public void updateByVo(PurchaseOrderItem model, PurchaseOrderItemVo vo) {
|
||||||
if (model == null) {
|
if (model == null) {
|
||||||
@@ -183,4 +122,26 @@ public class PurchaseOrderItemService implements IEntityService<PurchaseOrderIte
|
|||||||
public List<PurchaseOrderItem> findAllByOrder(PurchaseOrder order) {
|
public List<PurchaseOrderItem> findAllByOrder(PurchaseOrder order) {
|
||||||
return repository.findAllByOrder(order);
|
return repository.findAllByOrder(order);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected PurchaseOrderItemRepository getRepository() {
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PurchaseOrderItem createNewEntity() {
|
||||||
|
return new PurchaseOrderItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Specification<PurchaseOrderItem> buildSearchSpecification(String searchText) {
|
||||||
|
return (root, query, builder) -> {
|
||||||
|
return builder.or(builder.like(root.get("description"), "%" + searchText + "%"));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Specification<PurchaseOrderItem> buildParameterSpecification(JsonNode paramsNode) {
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'buildParameterSpecification'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -3,8 +3,6 @@ package com.ecep.contract.ds.contract.service;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.ecep.contract.vo.ContractVo;
|
import com.ecep.contract.vo.ContractVo;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cache.annotation.CacheConfig;
|
import org.springframework.cache.annotation.CacheConfig;
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
@@ -13,10 +11,10 @@ import org.springframework.cache.annotation.Caching;
|
|||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.ecep.contract.EntityService;
|
||||||
import com.ecep.contract.IEntityService;
|
import com.ecep.contract.IEntityService;
|
||||||
import com.ecep.contract.QueryService;
|
import com.ecep.contract.QueryService;
|
||||||
import com.ecep.contract.SpringApp;
|
import com.ecep.contract.SpringApp;
|
||||||
@@ -26,7 +24,6 @@ import com.ecep.contract.ds.contract.model.Contract;
|
|||||||
import com.ecep.contract.ds.vendor.model.PurchaseOrder;
|
import com.ecep.contract.ds.vendor.model.PurchaseOrder;
|
||||||
import com.ecep.contract.service.ServiceException;
|
import com.ecep.contract.service.ServiceException;
|
||||||
import com.ecep.contract.service.VoableService;
|
import com.ecep.contract.service.VoableService;
|
||||||
import com.ecep.contract.util.SpecificationUtils;
|
|
||||||
import com.ecep.contract.vo.PurchaseOrderVo;
|
import com.ecep.contract.vo.PurchaseOrderVo;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
|
||||||
@@ -36,31 +33,32 @@ import com.fasterxml.jackson.databind.JsonNode;
|
|||||||
@Lazy
|
@Lazy
|
||||||
@Service
|
@Service
|
||||||
@CacheConfig(cacheNames = "contract-purchase-order")
|
@CacheConfig(cacheNames = "contract-purchase-order")
|
||||||
public class PurchaseOrdersService implements IEntityService<PurchaseOrder>, QueryService<PurchaseOrderVo>,
|
public class PurchaseOrdersService extends EntityService<PurchaseOrder, PurchaseOrderVo, Integer>
|
||||||
|
implements IEntityService<PurchaseOrder>, QueryService<PurchaseOrderVo>,
|
||||||
VoableService<PurchaseOrder, PurchaseOrderVo> {
|
VoableService<PurchaseOrder, PurchaseOrderVo> {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(PurchaseOrdersService.class);
|
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
@Autowired
|
@Autowired
|
||||||
private PurchaseOrderRepository repository;
|
private PurchaseOrderRepository repository;
|
||||||
|
|
||||||
@Lazy
|
|
||||||
@Autowired
|
|
||||||
private EmployeeService employeeService;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PurchaseOrder getById(Integer id) {
|
protected PurchaseOrderRepository getRepository() {
|
||||||
return repository.findById(id).orElse(null);
|
return repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Cacheable(key = "#p0")
|
@Cacheable(key = "#p0")
|
||||||
|
@Override
|
||||||
public PurchaseOrderVo findById(Integer id) {
|
public PurchaseOrderVo findById(Integer id) {
|
||||||
return repository.findById(id).map(PurchaseOrder::toVo).orElse(null);
|
return repository.findById(id).map(PurchaseOrder::toVo).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Specification<PurchaseOrder> getSearchSpecification(String searchText) {
|
public PurchaseOrder createNewEntity() {
|
||||||
|
return new PurchaseOrder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Specification<PurchaseOrder> buildSearchSpecification(String searchText) {
|
||||||
return (root, query, builder) -> {
|
return (root, query, builder) -> {
|
||||||
return builder.or(
|
return builder.or(
|
||||||
builder.like(root.get("code"), "%" + searchText + "%"),
|
builder.like(root.get("code"), "%" + searchText + "%"),
|
||||||
@@ -108,31 +106,9 @@ public class PurchaseOrdersService implements IEntityService<PurchaseOrder>, Que
|
|||||||
repository.delete(order);
|
repository.delete(order);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long count() {
|
|
||||||
return repository.count();
|
|
||||||
}
|
|
||||||
|
|
||||||
public long count(Specification<PurchaseOrder> spec) {
|
|
||||||
return repository.count(spec);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<PurchaseOrder> findAll(Specification<PurchaseOrder> spec, Pageable pageable) {
|
protected Specification<PurchaseOrder> buildParameterSpecification(JsonNode paramsNode) {
|
||||||
return repository.findAll(spec, pageable);
|
throw new UnsupportedOperationException("Unimplemented method 'buildParameterSpecification'");
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Page<PurchaseOrderVo> findAll(JsonNode paramsNode, Pageable pageable) {
|
|
||||||
Specification<PurchaseOrder> spec = null;
|
|
||||||
if (paramsNode.has("searchText")) {
|
|
||||||
spec = getSearchSpecification(paramsNode.get("searchText").asText());
|
|
||||||
}
|
|
||||||
spec = SpecificationUtils.andParam(spec, paramsNode, "contract");
|
|
||||||
return findAll(spec, pageable).map(PurchaseOrder::toVo);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<PurchaseOrder> findAll(Specification<PurchaseOrder> spec, Sort sort) {
|
|
||||||
return repository.findAll(spec, sort);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PurchaseOrder> findAllByContract(Contract contract) {
|
public List<PurchaseOrder> findAllByContract(Contract contract) {
|
||||||
@@ -143,15 +119,6 @@ public class PurchaseOrdersService implements IEntityService<PurchaseOrder>, Que
|
|||||||
return repository.findAllByContractId(contract.getId());
|
return repository.findAllByContractId(contract.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PurchaseOrder> search(String searchText) {
|
|
||||||
Specification<PurchaseOrder> spec = (root, query, builder) -> {
|
|
||||||
return builder.or(
|
|
||||||
builder.like(root.get("name"), "%" + searchText + "%"),
|
|
||||||
builder.like(root.get("code"), "%" + searchText + "%"));
|
|
||||||
};
|
|
||||||
return repository.findAll(spec, Pageable.ofSize(10)).getContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateByVo(PurchaseOrder model, PurchaseOrderVo vo) {
|
public void updateByVo(PurchaseOrder model, PurchaseOrderVo vo) {
|
||||||
if (model == null || vo == null) {
|
if (model == null || vo == null) {
|
||||||
|
|||||||
@@ -1,19 +1,15 @@
|
|||||||
package com.ecep.contract.ds.contract.service;
|
package com.ecep.contract.ds.contract.service;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cache.annotation.CacheConfig;
|
import org.springframework.cache.annotation.CacheConfig;
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.cache.annotation.Caching;
|
import org.springframework.cache.annotation.Caching;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.data.domain.Page;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import org.springframework.data.domain.Sort;
|
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.ecep.contract.EntityService;
|
||||||
import com.ecep.contract.IEntityService;
|
import com.ecep.contract.IEntityService;
|
||||||
import com.ecep.contract.QueryService;
|
import com.ecep.contract.QueryService;
|
||||||
import com.ecep.contract.ds.contract.repository.SalesBillVoucherItemRepository;
|
import com.ecep.contract.ds.contract.repository.SalesBillVoucherItemRepository;
|
||||||
@@ -25,50 +21,19 @@ import com.fasterxml.jackson.databind.JsonNode;
|
|||||||
@Lazy
|
@Lazy
|
||||||
@Service
|
@Service
|
||||||
@CacheConfig(cacheNames = "sales-bill-voucher-item")
|
@CacheConfig(cacheNames = "sales-bill-voucher-item")
|
||||||
public class SalesBillVoucherItemService
|
public class SalesBillVoucherItemService extends EntityService<SalesBillVoucherItem, SalesBillVoucherItemVo, Integer>
|
||||||
implements IEntityService<SalesBillVoucherItem>, QueryService<SalesBillVoucherItemVo>,
|
implements IEntityService<SalesBillVoucherItem>, QueryService<SalesBillVoucherItemVo>,
|
||||||
VoableService<SalesBillVoucherItem, SalesBillVoucherItemVo> {
|
VoableService<SalesBillVoucherItem, SalesBillVoucherItemVo> {
|
||||||
@Lazy
|
@Lazy
|
||||||
@Autowired
|
@Autowired
|
||||||
private SalesBillVoucherItemRepository repository;
|
private SalesBillVoucherItemRepository repository;
|
||||||
|
|
||||||
@Override
|
|
||||||
public SalesBillVoucherItem getById(Integer id) {
|
|
||||||
return repository.findById(id).orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Cacheable(key = "#p0")
|
@Cacheable(key = "#p0")
|
||||||
@Override
|
@Override
|
||||||
public SalesBillVoucherItemVo findById(Integer id) {
|
public SalesBillVoucherItemVo findById(Integer id) {
|
||||||
return repository.findById(id).map(SalesBillVoucherItem::toVo).orElse(null);
|
return repository.findById(id).map(SalesBillVoucherItem::toVo).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Specification<SalesBillVoucherItem> getSearchSpecification(String searchText) {
|
|
||||||
return (root, query, builder) -> {
|
|
||||||
return builder.or(
|
|
||||||
builder.like(root.get("description"), "%" + searchText + "%"));
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Page<SalesBillVoucherItem> findAll(Specification<SalesBillVoucherItem> spec, Pageable pageable) {
|
|
||||||
return repository.findAll(spec, pageable);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SalesBillVoucherItem> findAll(Specification<SalesBillVoucherItem> spec, Sort sort) {
|
|
||||||
return repository.findAll(spec, sort);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Page<SalesBillVoucherItemVo> findAll(JsonNode paramsNode, Pageable pageable) {
|
|
||||||
Specification<SalesBillVoucherItem> spec = null;
|
|
||||||
if (paramsNode.has("searchText")) {
|
|
||||||
spec = getSearchSpecification(paramsNode.get("searchText").asText());
|
|
||||||
}
|
|
||||||
return findAll(spec, pageable).map(SalesBillVoucherItem::toVo);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Caching(evict = {
|
@Caching(evict = {
|
||||||
@CacheEvict(key = "'item-'+#p0.id")
|
@CacheEvict(key = "'item-'+#p0.id")
|
||||||
})
|
})
|
||||||
@@ -85,12 +50,26 @@ public class SalesBillVoucherItemService
|
|||||||
return repository.save(entity);
|
return repository.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long countItems() {
|
@Override
|
||||||
return repository.count();
|
protected SalesBillVoucherItemRepository getRepository() {
|
||||||
|
return repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long countItems(Specification<SalesBillVoucherItem> spec) {
|
@Override
|
||||||
return repository.count(spec);
|
public SalesBillVoucherItem createNewEntity() {
|
||||||
|
return new SalesBillVoucherItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Specification<SalesBillVoucherItem> buildSearchSpecification(String searchText) {
|
||||||
|
return (root, query, builder) -> {
|
||||||
|
return builder.or(builder.like(root.get("description"), "%" + searchText + "%"));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Specification<SalesBillVoucherItem> buildParameterSpecification(JsonNode paramsNode) {
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'buildParameterSpecification'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -103,4 +82,5 @@ public class SalesBillVoucherItemService
|
|||||||
model.setPrice(vo.getPrice());
|
model.setPrice(vo.getPrice());
|
||||||
model.setDescription(vo.getDescription());
|
model.setDescription(vo.getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,24 +2,26 @@ package com.ecep.contract.ds.customer.repository;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import com.ecep.contract.ds.MyRepository;
|
||||||
import com.ecep.contract.ds.customer.model.CompanyCustomer;
|
import com.ecep.contract.ds.customer.model.CompanyCustomer;
|
||||||
import com.ecep.contract.ds.customer.model.CompanyCustomerEvaluationFormFile;
|
import com.ecep.contract.ds.customer.model.CompanyCustomerEvaluationFormFile;
|
||||||
import com.ecep.contract.ds.customer.model.CompanyCustomerFile;
|
import com.ecep.contract.ds.customer.model.CompanyCustomerFile;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface CompanyCustomerEvaluationFormFileRepository extends JpaRepository<CompanyCustomerEvaluationFormFile, Integer>, JpaSpecificationExecutor<CompanyCustomerEvaluationFormFile> {
|
public interface CompanyCustomerEvaluationFormFileRepository
|
||||||
|
extends MyRepository<CompanyCustomerEvaluationFormFile, Integer> {
|
||||||
|
|
||||||
List<CompanyCustomerEvaluationFormFile> findAllByCustomerFileCustomer(@Param("customer") CompanyCustomer customer);
|
List<CompanyCustomerEvaluationFormFile> findAllByCustomerFileCustomer(@Param("customer") CompanyCustomer customer);
|
||||||
|
|
||||||
@Query(value = "SELECT * FROM COMPANY_CUSTOMER_FILE ccf left join COMPANY_CUSTOMER_EVALUATION_FORM_FILE CCEFF on ccf.ID = CCEFF.ID " +
|
@Query(value = "SELECT * FROM COMPANY_CUSTOMER_FILE ccf left join COMPANY_CUSTOMER_EVALUATION_FORM_FILE CCEFF on ccf.ID = CCEFF.ID "
|
||||||
|
+
|
||||||
"where ccf.CUSTOMER_ID=:customer and ccf.TYPE=:fileType", nativeQuery = true)
|
"where ccf.CUSTOMER_ID=:customer and ccf.TYPE=:fileType", nativeQuery = true)
|
||||||
List<CompanyCustomerEvaluationFormFile> findAllByCustomerAndType(@Param("customer") int companyCustomerId, @Param("fileType") String type);
|
List<CompanyCustomerEvaluationFormFile> findAllByCustomerAndType(@Param("customer") int companyCustomerId,
|
||||||
|
@Param("fileType") String type);
|
||||||
|
|
||||||
CompanyCustomerEvaluationFormFile findByCustomerFile(CompanyCustomerFile customerFile);
|
CompanyCustomerEvaluationFormFile findByCustomerFile(CompanyCustomerFile customerFile);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,23 +12,25 @@ import org.springframework.data.domain.Page;
|
|||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
|
import com.ecep.contract.EntityService;
|
||||||
import com.ecep.contract.IEntityService;
|
import com.ecep.contract.IEntityService;
|
||||||
import com.ecep.contract.QueryService;
|
import com.ecep.contract.QueryService;
|
||||||
|
import com.ecep.contract.ds.MyRepository;
|
||||||
import com.ecep.contract.ds.customer.repository.CompanyCustomerEntityRepository;
|
import com.ecep.contract.ds.customer.repository.CompanyCustomerEntityRepository;
|
||||||
import com.ecep.contract.ds.other.service.EmployeeService;
|
import com.ecep.contract.ds.other.service.EmployeeService;
|
||||||
import com.ecep.contract.ds.customer.model.CompanyCustomer;
|
import com.ecep.contract.ds.customer.model.CompanyCustomer;
|
||||||
import com.ecep.contract.ds.customer.model.CompanyCustomerEntity;
|
import com.ecep.contract.ds.customer.model.CompanyCustomerEntity;
|
||||||
import com.ecep.contract.service.VoableService;
|
import com.ecep.contract.service.VoableService;
|
||||||
import com.ecep.contract.util.SpecificationUtils;
|
|
||||||
import com.ecep.contract.vo.CompanyCustomerEntityVo;
|
import com.ecep.contract.vo.CompanyCustomerEntityVo;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
@Service
|
@Service
|
||||||
@CacheConfig(cacheNames = "company-customer-entity")
|
@CacheConfig(cacheNames = "company-customer-entity")
|
||||||
public class CompanyCustomerEntityService implements IEntityService<CompanyCustomerEntity>, QueryService<CompanyCustomerEntityVo>, VoableService<CompanyCustomerEntity, CompanyCustomerEntityVo> {
|
public class CompanyCustomerEntityService extends EntityService<CompanyCustomerEntity, CompanyCustomerEntityVo, Integer>
|
||||||
|
implements IEntityService<CompanyCustomerEntity>, QueryService<CompanyCustomerEntityVo>,
|
||||||
|
VoableService<CompanyCustomerEntity, CompanyCustomerEntityVo> {
|
||||||
@Lazy
|
@Lazy
|
||||||
@Autowired
|
@Autowired
|
||||||
private CompanyCustomerEntityRepository repository;
|
private CompanyCustomerEntityRepository repository;
|
||||||
@@ -42,11 +44,6 @@ public class CompanyCustomerEntityService implements IEntityService<CompanyCusto
|
|||||||
@Autowired
|
@Autowired
|
||||||
private EmployeeService employeeService;
|
private EmployeeService employeeService;
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompanyCustomerEntity getById(Integer id) {
|
|
||||||
return repository.findById(id).orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Cacheable(key = "#p0")
|
@Cacheable(key = "#p0")
|
||||||
@Override
|
@Override
|
||||||
public CompanyCustomerEntityVo findById(Integer id) {
|
public CompanyCustomerEntityVo findById(Integer id) {
|
||||||
@@ -54,13 +51,6 @@ public class CompanyCustomerEntityService implements IEntityService<CompanyCusto
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Specification<CompanyCustomerEntity> getSearchSpecification(String searchText) {
|
|
||||||
if (!StringUtils.hasText(searchText)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return SpecificationUtils.andWith(searchText, this::buildSearchSpecification);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Specification<CompanyCustomerEntity> buildSearchSpecification(String searchText) {
|
protected Specification<CompanyCustomerEntity> buildSearchSpecification(String searchText) {
|
||||||
return (root, query, builder) -> {
|
return (root, query, builder) -> {
|
||||||
return builder.or(
|
return builder.or(
|
||||||
@@ -70,25 +60,9 @@ public class CompanyCustomerEntityService implements IEntityService<CompanyCusto
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<CompanyCustomerEntity> search(String searchText) {
|
|
||||||
Specification<CompanyCustomerEntity> spec = getSearchSpecification(searchText);
|
|
||||||
return repository.findAll(spec, Pageable.ofSize(10)).getContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<CompanyCustomerEntity> findAll(Specification<CompanyCustomerEntity> spec, Pageable pageable) {
|
protected Specification<CompanyCustomerEntity> buildParameterSpecification(JsonNode paramsNode) {
|
||||||
return repository.findAll(spec, pageable);
|
throw new UnsupportedOperationException("Unimplemented method 'buildParameterSpecification'");
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Page<CompanyCustomerEntityVo> findAll(JsonNode paramsNode, Pageable pageable) {
|
|
||||||
Specification<CompanyCustomerEntity> spec = null;
|
|
||||||
if (paramsNode.has("searchText")) {
|
|
||||||
spec = getSearchSpecification(paramsNode.get("searchText").asText());
|
|
||||||
}
|
|
||||||
// field
|
|
||||||
spec = SpecificationUtils.andParam(spec, paramsNode, "customer");
|
|
||||||
return findAll(spec, pageable).map(CompanyCustomerEntity::toVo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Caching(evict = {
|
@Caching(evict = {
|
||||||
@@ -126,6 +100,16 @@ public class CompanyCustomerEntityService implements IEntityService<CompanyCusto
|
|||||||
repository.saveAll(entities);
|
repository.saveAll(entities);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected MyRepository<CompanyCustomerEntity, Integer> getRepository() {
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompanyCustomerEntity createNewEntity() {
|
||||||
|
return new CompanyCustomerEntity();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateByVo(CompanyCustomerEntity entity, CompanyCustomerEntityVo vo) {
|
public void updateByVo(CompanyCustomerEntity entity, CompanyCustomerEntityVo vo) {
|
||||||
// 优化关联实体处理逻辑 - 客户关联
|
// 优化关联实体处理逻辑 - 客户关联
|
||||||
|
|||||||
@@ -3,12 +3,9 @@ package com.ecep.contract.ds.customer.service;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.ecep.contract.constant.ParamConstant;
|
import com.ecep.contract.constant.ParamConstant;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cache.annotation.CacheConfig;
|
import org.springframework.cache.annotation.CacheConfig;
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
|
||||||
import org.springframework.cache.annotation.Caching;
|
import org.springframework.cache.annotation.Caching;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
@@ -16,9 +13,11 @@ import org.springframework.data.domain.Pageable;
|
|||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.ecep.contract.EntityService;
|
||||||
import com.ecep.contract.IEntityService;
|
import com.ecep.contract.IEntityService;
|
||||||
import com.ecep.contract.QueryService;
|
import com.ecep.contract.QueryService;
|
||||||
import com.ecep.contract.SpringApp;
|
import com.ecep.contract.SpringApp;
|
||||||
|
import com.ecep.contract.ds.MyRepository;
|
||||||
import com.ecep.contract.ds.customer.repository.CompanyCustomerEvaluationFormFileRepository;
|
import com.ecep.contract.ds.customer.repository.CompanyCustomerEvaluationFormFileRepository;
|
||||||
import com.ecep.contract.ds.customer.model.CompanyCustomer;
|
import com.ecep.contract.ds.customer.model.CompanyCustomer;
|
||||||
import com.ecep.contract.ds.customer.model.CompanyCustomerEvaluationFormFile;
|
import com.ecep.contract.ds.customer.model.CompanyCustomerEvaluationFormFile;
|
||||||
@@ -33,30 +32,31 @@ import com.fasterxml.jackson.databind.JsonNode;
|
|||||||
@Service
|
@Service
|
||||||
@CacheConfig(cacheNames = "company-customer-evaluation-form-file")
|
@CacheConfig(cacheNames = "company-customer-evaluation-form-file")
|
||||||
public class CompanyCustomerEvaluationFormFileService
|
public class CompanyCustomerEvaluationFormFileService
|
||||||
implements IEntityService<CompanyCustomerEvaluationFormFile>, QueryService<CompanyCustomerEvaluationFormFile>,
|
extends EntityService<CompanyCustomerEvaluationFormFile, CompanyCustomerEvaluationFormFileVo, Integer>
|
||||||
|
implements IEntityService<CompanyCustomerEvaluationFormFile>, QueryService<CompanyCustomerEvaluationFormFileVo>,
|
||||||
VoableService<CompanyCustomerEvaluationFormFile, CompanyCustomerEvaluationFormFileVo> {
|
VoableService<CompanyCustomerEvaluationFormFile, CompanyCustomerEvaluationFormFileVo> {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(CompanyCustomerEvaluationFormFileService.class);
|
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
@Autowired
|
@Autowired
|
||||||
private CompanyCustomerEvaluationFormFileRepository repository;
|
private CompanyCustomerEvaluationFormFileRepository repository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompanyCustomerEvaluationFormFile getById(Integer id) {
|
protected CompanyCustomerEvaluationFormFileRepository getRepository() {
|
||||||
return repository.findById(id).orElse(null);
|
return repository;
|
||||||
}
|
|
||||||
|
|
||||||
@Cacheable(key = "#p0")
|
|
||||||
@Override
|
|
||||||
public CompanyCustomerEvaluationFormFile findById(Integer id) {
|
|
||||||
return getById(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Specification<CompanyCustomerEvaluationFormFile> getSearchSpecification(String searchText) {
|
public CompanyCustomerEvaluationFormFileVo findById(Integer id) {
|
||||||
if (!org.springframework.util.StringUtils.hasText(searchText)) {
|
return repository.findById(id).map(CompanyCustomerEvaluationFormFile::toVo).orElse(null);
|
||||||
return null;
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public CompanyCustomerEvaluationFormFile createNewEntity() {
|
||||||
|
return new CompanyCustomerEvaluationFormFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Specification<CompanyCustomerEvaluationFormFile> buildSearchSpecification(String searchText) {
|
||||||
return (root, query, builder) -> {
|
return (root, query, builder) -> {
|
||||||
var customerFile = root.get("customerFile");
|
var customerFile = root.get("customerFile");
|
||||||
return builder.or(
|
return builder.or(
|
||||||
@@ -64,8 +64,7 @@ public class CompanyCustomerEvaluationFormFileService
|
|||||||
builder.like(root.get("level"), "%" + searchText + "%"),
|
builder.like(root.get("level"), "%" + searchText + "%"),
|
||||||
builder.and(
|
builder.and(
|
||||||
customerFile.isNotNull(),
|
customerFile.isNotNull(),
|
||||||
builder.like(customerFile.get("filePath"), "%" + searchText + "%")
|
builder.like(customerFile.get("filePath"), "%" + searchText + "%")));
|
||||||
));
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,31 +85,23 @@ public class CompanyCustomerEvaluationFormFileService
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<CompanyCustomerEvaluationFormFile> findAll(Specification<CompanyCustomerEvaluationFormFile> spec,
|
protected Specification<CompanyCustomerEvaluationFormFile> buildParameterSpecification(JsonNode paramsNode) {
|
||||||
Pageable pageable) {
|
|
||||||
return repository.findAll(spec, pageable);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Page<CompanyCustomerEvaluationFormFile> findAll(JsonNode paramsNode, Pageable pageable) {
|
|
||||||
Specification<CompanyCustomerEvaluationFormFile> spec = null;
|
Specification<CompanyCustomerEvaluationFormFile> spec = null;
|
||||||
if (paramsNode.has(ParamConstant.KEY_SEARCH_TEXT)) {
|
|
||||||
spec = getSearchSpecification(paramsNode.get(ParamConstant.KEY_SEARCH_TEXT).asText());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (paramsNode.has("customer")) {
|
if (paramsNode.has("customer")) {
|
||||||
spec = SpecificationUtils.and(spec,
|
spec = SpecificationUtils.and(spec,
|
||||||
(root, query, builder) -> builder.equal(root.get("customerFile").get("customer").get("id"), paramsNode.get("customer").asInt()));
|
(root, query, builder) -> builder.equal(root.get("customerFile").get("customer").get("id"),
|
||||||
|
paramsNode.get("customer").asInt()));
|
||||||
}
|
}
|
||||||
if (paramsNode.has("company")) {
|
if (paramsNode.has("company")) {
|
||||||
spec = SpecificationUtils.and(spec,
|
spec = SpecificationUtils.and(spec,
|
||||||
(root, query, builder) -> builder.equal(root.get("customerFile").get("customer").get("company").get("id"), paramsNode.get("company").asInt()));
|
(root, query, builder) -> builder.equal(
|
||||||
|
root.get("customerFile").get("customer").get("company").get("id"),
|
||||||
|
paramsNode.get("company").asInt()));
|
||||||
}
|
}
|
||||||
|
|
||||||
spec = SpecificationUtils.andParam(spec, paramsNode, "customerFile");
|
spec = SpecificationUtils.andParam(spec, paramsNode, "customerFile");
|
||||||
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "catalog", "level");
|
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "catalog", "level");
|
||||||
|
return spec;
|
||||||
return findAll(spec, pageable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -178,4 +169,5 @@ public class CompanyCustomerEvaluationFormFileService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -29,16 +29,16 @@
|
|||||||
| ContractService | 是 |
|
| ContractService | 是 |
|
||||||
| ContractTypeService | 是 |
|
| ContractTypeService | 是 |
|
||||||
| ExtendVendorInfoService | 是 |
|
| ExtendVendorInfoService | 是 |
|
||||||
| PurchaseBillVoucherItemService | 否 |
|
| PurchaseBillVoucherItemService | 是 |
|
||||||
| PurchaseBillVoucherService | 否 |
|
| PurchaseBillVoucherService | 是 |
|
||||||
| PurchaseOrderItemService | 否 |
|
| PurchaseOrderItemService | 是 |
|
||||||
| PurchaseOrdersService | 否 |
|
| PurchaseOrdersService | 是 |
|
||||||
| SaleOrdersService | 是 |
|
| SaleOrdersService | 是 |
|
||||||
| SalesBillVoucherItemService | 否 |
|
| SalesBillVoucherItemService | 是 |
|
||||||
| SalesBillVoucherService | 是 |
|
| SalesBillVoucherService | 是 |
|
||||||
| SalesOrderItemService | 是 |
|
| SalesOrderItemService | 是 |
|
||||||
| CompanyCustomerEntityService | 否 |
|
| CompanyCustomerEntityService | 是 |
|
||||||
| CompanyCustomerEvaluationFormFileService | 否 |
|
| CompanyCustomerEvaluationFormFileService | 是 |
|
||||||
| CompanyCustomerFileService | 否 |
|
| CompanyCustomerFileService | 否 |
|
||||||
| CompanyCustomerFileTypeService | 否 |
|
| CompanyCustomerFileTypeService | 否 |
|
||||||
| CustomerCatalogService | 否 |
|
| CustomerCatalogService | 否 |
|
||||||
|
|||||||
Reference in New Issue
Block a user