refactor: 重构WebSocket服务及相关实体类
重构WebSocket服务名称从WebSocketService改为WebSocketClientService,并实现Serializable接口 添加WebSocket常量定义和消息处理实现 优化实体类equals和hashCode方法 修复控制器路径和日志配置 添加查询服务和任务接口方法
This commit is contained in:
@@ -1,4 +1,68 @@
|
||||
package com.ecep.contract;
|
||||
|
||||
public class EntityService {
|
||||
import com.ecep.contract.ds.MyRepository;
|
||||
import com.ecep.contract.model.Contract;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
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.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class EntityService<T, ID> {
|
||||
|
||||
protected abstract MyRepository<T, ID> getRepository();
|
||||
|
||||
public abstract T createNewEntity();
|
||||
|
||||
|
||||
public long count() {
|
||||
return getRepository().count();
|
||||
}
|
||||
|
||||
public long count(Specification<T> spec) {
|
||||
return getRepository().count(spec);
|
||||
}
|
||||
|
||||
public long count(JsonNode paramsNode) {
|
||||
return getRepository().count(buildParameterSpecification(paramsNode));
|
||||
}
|
||||
|
||||
protected abstract Specification<T> buildParameterSpecification(JsonNode paramsNode);
|
||||
|
||||
public Page<T> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<T> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
spec = SpecificationUtils.and(spec, buildParameterSpecification(paramsNode));
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
|
||||
public Page<T> findAll(Specification<T> spec, Pageable pageable) {
|
||||
return getRepository().findAll(spec, pageable);
|
||||
}
|
||||
|
||||
public List<T> findAll(Specification<T> spec, Sort sort) {
|
||||
return getRepository().findAll(spec, sort);
|
||||
}
|
||||
|
||||
protected abstract Specification<T> buildSearchSpecification(String searchText);
|
||||
|
||||
public Specification<T> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
return null;
|
||||
}
|
||||
return SpecificationUtils.andWith(searchText, this::buildSearchSpecification);
|
||||
}
|
||||
|
||||
public List<T> search(String searchText) {
|
||||
Specification<T> spec = getSpecification(searchText);
|
||||
return getRepository().findAll(spec, Pageable.ofSize(10)).getContent();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,4 +23,8 @@ public interface QueryService<T> {
|
||||
Specification<T> getSpecification(String searchText);
|
||||
|
||||
Page<T> findAll(Specification<T> spec, Pageable pageable);
|
||||
|
||||
default long count(JsonNode paramsNode) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,15 @@
|
||||
package com.ecep.contract.cloud.old;
|
||||
|
||||
import com.ecep.contract.MessageHolder;
|
||||
import com.ecep.contract.SpringApp;
|
||||
import com.ecep.contract.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.ds.customer.service.CompanyCustomerService;
|
||||
import com.ecep.contract.model.Company;
|
||||
import com.ecep.contract.model.Contract;
|
||||
import com.ecep.contract.ui.Tasker;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -8,16 +18,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.ecep.contract.MessageHolder;
|
||||
import com.ecep.contract.SpringApp;
|
||||
import com.ecep.contract.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.model.Company;
|
||||
import com.ecep.contract.model.Contract;
|
||||
import com.ecep.contract.ui.Tasker;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -25,7 +25,6 @@ public class OldVersionSyncCustomerTask extends Tasker<Object> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(OldVersionSyncCustomerTask.class);
|
||||
|
||||
private final OldVersionService service = SpringApp.getBean(OldVersionService.class);
|
||||
private final CompanyService companyService = SpringApp.getBean(CompanyService.class);
|
||||
|
||||
private Map<Object, List<Map<String, Object>>> oldNameGroupedMap;
|
||||
private Map<Object, List<Map<String, Object>>> contactGroupedMap;
|
||||
@@ -39,7 +38,7 @@ public class OldVersionSyncCustomerTask extends Tasker<Object> {
|
||||
@Override
|
||||
protected Object execute(MessageHolder holder) throws Exception {
|
||||
updateTitle("老版本-同步客户数据");
|
||||
basePath = companyService.getCustomerBasePath();
|
||||
basePath = getCachedBean(CompanyCustomerService.class).getBasePath();
|
||||
List<Runnable> runnable = Arrays.asList(this::loadOldNames, this::loadContacts, this::syncCustomers,
|
||||
this::syncContracts);
|
||||
|
||||
@@ -67,7 +66,6 @@ public class OldVersionSyncCustomerTask extends Tasker<Object> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void loadContacts() {
|
||||
try (Stream<Map<String, Object>> stream = service.queryAllCustomerContactForStream()) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.ecep.contract.ds.vendor.service.CompanyVendorService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -34,7 +35,7 @@ public class OldVersionSyncVendorTask extends Tasker<Object> {
|
||||
|
||||
@Override
|
||||
protected Object execute(MessageHolder holder) throws Exception {
|
||||
basePath = companyService.getVendorBasePath();
|
||||
basePath = getCachedBean(CompanyVendorService.class).getBasePath();
|
||||
List<Runnable> runnable = Arrays.asList(this::loadOldNames, this::loadContacts, this::syncVendors,
|
||||
this::syncContracts);
|
||||
for (int i = 0; i < runnable.size(); i++) {
|
||||
|
||||
@@ -3,21 +3,17 @@ package com.ecep.contract.cloud.u8;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.logging.Level;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.ecep.contract.service.WebSocketServerTasker;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.MessageHolder;
|
||||
@@ -28,55 +24,19 @@ import com.ecep.contract.ds.contract.tasker.AbstContractRepairTasker;
|
||||
/**
|
||||
* 合同同步任务
|
||||
*/
|
||||
@Component
|
||||
public class ContractSyncTask extends AbstContractRepairTasker implements InitializingBean, DisposableBean {
|
||||
public class ContractSyncTask extends AbstContractRepairTasker implements WebSocketServerTasker {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ContractSyncTask.class);
|
||||
private YongYouU8Repository repository;
|
||||
private ScheduledExecutorService executorService;
|
||||
private ScheduledFuture<?> scheduleAtFixedRate;
|
||||
|
||||
@Autowired
|
||||
public ContractSyncTask(ScheduledExecutorService executorService) {
|
||||
this.executorService = executorService;
|
||||
updateTitle("用友U8系统-同步合同");
|
||||
System.out.println("合同同步任务启动");
|
||||
public ContractSyncTask() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
scheduleAtFixedRate = executorService.scheduleAtFixedRate(() -> {
|
||||
try {
|
||||
ContractSyncTask.this.call();
|
||||
} catch (Exception e) {
|
||||
logger.error("合同同步任务异常", e);
|
||||
}
|
||||
}, 1, 5, TimeUnit.MINUTES);
|
||||
;
|
||||
}
|
||||
public void init(JsonNode argsNode) {
|
||||
|
||||
public void destroy() throws Exception {
|
||||
if (scheduleAtFixedRate != null) {
|
||||
scheduleAtFixedRate.cancel(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateMessage(Level level, String message) {
|
||||
if (level == Level.SEVERE) {
|
||||
logger.error(message);
|
||||
}
|
||||
if (level == Level.WARNING) {
|
||||
logger.warn(message);
|
||||
}
|
||||
if (level == Level.INFO) {
|
||||
logger.info(message);
|
||||
}
|
||||
if (level == Level.FINE) {
|
||||
logger.debug(message);
|
||||
}
|
||||
if (level == Level.FINER) {
|
||||
logger.trace(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -189,4 +149,5 @@ public class ContractSyncTask extends AbstContractRepairTasker implements Initia
|
||||
getConfService().set(CloudYuConstant.KEY_SYNC_BY_LATEST_DATE, String.valueOf(reference.get()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -120,7 +120,8 @@ public class CompanyCtx extends AbstractYongYouU8Ctx {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Company com = companyService.createNewCompany(name);
|
||||
Company com = companyService.createNewEntity();
|
||||
com.setName(name);
|
||||
com.setShortName(abbName);
|
||||
return companyService.save(com);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.ecep.contract.ds.contract.service.*;
|
||||
import com.ecep.contract.util.FileUtils;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -27,15 +28,10 @@ import com.ecep.contract.MessageHolder;
|
||||
import com.ecep.contract.MyDateTimeUtils;
|
||||
import com.ecep.contract.constant.CloudServiceConstant;
|
||||
import com.ecep.contract.ds.company.CompanyFileUtils;
|
||||
import com.ecep.contract.ds.contract.service.ContractFileService;
|
||||
import com.ecep.contract.ds.contract.service.ContractFileTypeService;
|
||||
import com.ecep.contract.ds.contract.service.ContractItemService;
|
||||
import com.ecep.contract.ds.contract.service.ContractPayPlanService;
|
||||
import com.ecep.contract.ds.contract.service.ContractService;
|
||||
import com.ecep.contract.ds.customer.service.CompanyCustomerEntityService;
|
||||
import com.ecep.contract.ds.customer.service.CompanyCustomerService;
|
||||
import com.ecep.contract.ds.project.ProjectCtx;
|
||||
import com.ecep.contract.ds.project.service.SaleTypeService;
|
||||
import com.ecep.contract.ds.project.service.ProjectSaleTypeService;
|
||||
import com.ecep.contract.ds.vendor.service.CompanyVendorEntityService;
|
||||
import com.ecep.contract.ds.vendor.service.CompanyVendorService;
|
||||
import com.ecep.contract.model.Company;
|
||||
@@ -98,8 +94,8 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
return getCachedBean(ContractFileService.class);
|
||||
}
|
||||
|
||||
public SaleTypeService getSaleTypeService() {
|
||||
return getCachedBean(SaleTypeService.class);
|
||||
public ProjectSaleTypeService getSaleTypeService() {
|
||||
return getCachedBean(ProjectSaleTypeService.class);
|
||||
}
|
||||
|
||||
VendorCtx getVendorCtx() {
|
||||
@@ -301,7 +297,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
if (contract.getType() != null && contract.getPayWay() != null) {
|
||||
ContractType type = contract.getType();
|
||||
if (!Hibernate.isInitialized(type)) {
|
||||
type = getContractService().findTypeById(type.getId());
|
||||
type = getCachedBean(ContractTypeService.class).findById(type.getId());
|
||||
contract.setType(type);
|
||||
}
|
||||
if (!type.getDirection().equals(contract.getPayWay().getText())) {
|
||||
@@ -312,12 +308,12 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
if (contract.getKind() != null && contract.getType() != null) {
|
||||
ContractKind kind = contract.getKind();
|
||||
if (!Hibernate.isInitialized(kind)) {
|
||||
kind = getContractService().findKindById(kind.getId());
|
||||
kind = getCachedBean(ContractKindService.class).findById(kind.getId());
|
||||
contract.setKind(kind);
|
||||
}
|
||||
ContractType type = contract.getType();
|
||||
if (!Hibernate.isInitialized(type)) {
|
||||
type = getContractService().findTypeById(type.getId());
|
||||
type = getCachedBean(ContractTypeService.class).findById(type.getId());
|
||||
contract.setType(type);
|
||||
}
|
||||
if (!kind.getName().equals(type.getTitle())) {
|
||||
@@ -412,7 +408,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
}
|
||||
|
||||
private CompanyVendorEntity updateVendorEntityDetailByCode(CompanyVendorEntity entity, String unitCode,
|
||||
MessageHolder holder) {
|
||||
MessageHolder holder) {
|
||||
if (vendorEntityUpdateDelayDays > 0) {
|
||||
LocalDateTime today = LocalDateTime.now();
|
||||
if (entity.getFetchedTime() != null) {
|
||||
@@ -431,7 +427,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
}
|
||||
|
||||
private CompanyCustomerEntity updateCustomerEntityDetailByCode(CompanyCustomerEntity entity, String unitCode,
|
||||
MessageHolder holder) {
|
||||
MessageHolder holder) {
|
||||
if (customerEntityUpdateDelayDays > 0) {
|
||||
LocalDateTime today = LocalDateTime.now();
|
||||
if (entity.getFetchedTime() != null) {
|
||||
@@ -529,7 +525,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
}
|
||||
|
||||
private boolean updateTypeByCode(Contract contract, String typeCode, MessageHolder holder) {
|
||||
ContractType type = getContractService().findTypeByCode(typeCode);
|
||||
ContractType type = getCachedBean(ContractTypeService.class).findByCode(typeCode);
|
||||
if (!Objects.equals(contract.getType(), type)) {
|
||||
contract.setType(type);
|
||||
holder.info("合同类型修改为: " + type.getName());
|
||||
@@ -539,7 +535,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
}
|
||||
|
||||
private boolean updateGroupByCode(Contract contract, String groupCode, MessageHolder holder) {
|
||||
ContractGroup group = getContractService().findGroupByCode(groupCode);
|
||||
ContractGroup group = getCachedBean(ContractGroupService.class).findByCode(groupCode);
|
||||
if (!Objects.equals(contract.getGroup(), group)) {
|
||||
contract.setGroup(group);
|
||||
holder.info("合同分组修改为: " + group.getName());
|
||||
@@ -549,7 +545,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
}
|
||||
|
||||
private boolean updateKindByCode(Contract contract, String kindName, MessageHolder holder) {
|
||||
ContractKind kind = getContractService().findKindByName(kindName);
|
||||
ContractKind kind = getCachedBean(ContractKindService.class).findByName(kindName);
|
||||
if (!Objects.equals(contract.getKind(), kind)) {
|
||||
contract.setKind(kind);
|
||||
holder.info("合同分类修改为: " + kind.getName());
|
||||
@@ -605,7 +601,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
* 客户数据要通过 CompanyCustomerEntity 表关联来从用友数据库中读取
|
||||
*/
|
||||
public boolean syncByCustomerEntity(CompanyCustomer companyCustomer, CompanyCustomerEntity entity,
|
||||
MessageHolder holder) {
|
||||
MessageHolder holder) {
|
||||
String code = entity.getCode();
|
||||
holder.debug("同步客户相关项 " + code + "," + entity.getName() + " 的合同");
|
||||
if (!StringUtils.hasText(code)) {
|
||||
@@ -645,7 +641,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
|
||||
if (contract == null) {
|
||||
holder.debug("根据合同号未查找到合同, 合同号: " + contractId);
|
||||
|
||||
contract = service.createNew();
|
||||
contract = service.createNewEntity();
|
||||
contract.setGuid(guid);
|
||||
contract.setCode(contractId);
|
||||
contract = service.save(contract);
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
|
||||
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
|
||||
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;
|
||||
|
||||
import com.ecep.contract.handler.WebSocketHandler;
|
||||
import com.ecep.contract.handler.WebSocketServerHandler;
|
||||
|
||||
/**
|
||||
* WebSocket配置类
|
||||
@@ -19,10 +19,10 @@ import com.ecep.contract.handler.WebSocketHandler;
|
||||
@EnableWebSocket
|
||||
public class WebSocketConfig implements WebSocketConfigurer {
|
||||
|
||||
private final WebSocketHandler webSocketHandler;
|
||||
private final WebSocketServerHandler webSocketHandler;
|
||||
|
||||
@Autowired
|
||||
public WebSocketConfig(WebSocketHandler webSocketHandler) {
|
||||
public WebSocketConfig(WebSocketServerHandler webSocketHandler) {
|
||||
this.webSocketHandler = webSocketHandler;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.ecep.contract.ds.MyRepository;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
@@ -14,11 +15,7 @@ import org.springframework.stereotype.Repository;
|
||||
import com.ecep.contract.model.Company;
|
||||
|
||||
@Repository
|
||||
public interface CompanyRepository extends
|
||||
// JDBC interfaces
|
||||
CrudRepository<Company, Integer>, PagingAndSortingRepository<Company, Integer>,
|
||||
// JPA interfaces
|
||||
JpaRepository<Company, Integer>, JpaSpecificationExecutor<Company> {
|
||||
public interface CompanyRepository extends MyRepository<Company, Integer> {
|
||||
|
||||
List<Company> findAllByName(String name);
|
||||
|
||||
|
||||
@@ -11,13 +11,17 @@ import java.util.function.Consumer;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.ecep.contract.*;
|
||||
import com.ecep.contract.constant.CompanyConstant;
|
||||
import com.ecep.contract.ds.MyRepository;
|
||||
import com.ecep.contract.util.FileUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -26,11 +30,6 @@ import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.CompanyFileType;
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.MyDateTimeUtils;
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.SpringApp;
|
||||
import com.ecep.contract.constant.CloudServiceConstant;
|
||||
import com.ecep.contract.ds.company.repository.CompanyFileRepository;
|
||||
import com.ecep.contract.ds.company.repository.CompanyFileTypeLocalRepository;
|
||||
@@ -50,7 +49,7 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "company-file")
|
||||
public class CompanyFileService implements IEntityService<CompanyFile>, QueryService<CompanyFile> {
|
||||
public class CompanyFileService extends EntityService<CompanyFile, Integer> implements IEntityService<CompanyFile>, QueryService<CompanyFile> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CompanyFileService.class);
|
||||
@Lazy
|
||||
@Autowired
|
||||
@@ -62,53 +61,47 @@ public class CompanyFileService implements IEntityService<CompanyFile>, QuerySer
|
||||
@Autowired
|
||||
private CompanyFileTypeLocalRepository fileTypeLocalRepository;
|
||||
|
||||
@Override
|
||||
protected CompanyFileRepository getRepository() {
|
||||
return companyFileRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompanyFile createNewEntity() {
|
||||
return new CompanyFile();
|
||||
}
|
||||
|
||||
@Cacheable(key = "#p0")
|
||||
public CompanyFile findById(Integer id) {
|
||||
return companyFileRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<CompanyFile> findAll(Specification<CompanyFile> spec, Pageable pageable) {
|
||||
return companyFileRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
public List<CompanyFile> findFileByCompanyAndType(Company company, CompanyFileType type) {
|
||||
return companyFileRepository.findByCompanyAndType(company, type);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Specification<CompanyFile> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
return null;
|
||||
}
|
||||
protected Specification<CompanyFile> buildSearchSpecification(String searchText) {
|
||||
return (root, query, builder) -> {
|
||||
return builder.or(builder.like(root.get("filePath"), "%" + searchText + "%"));
|
||||
};
|
||||
}
|
||||
|
||||
@Cacheable(key = "'type-locals-'+#p0")
|
||||
public Map<CompanyFileType, CompanyFileTypeLocal> findAllFileTypes(String lang) {
|
||||
return fileTypeLocalRepository.getCompleteMapByLocal(lang);
|
||||
}
|
||||
// public List<CompanyFileTypeLocal> findAllFileTypes(String lang) {
|
||||
// Map<CompanyFileType, CompanyFileTypeLocal> map =
|
||||
// fileTypeLocalRepository.getCompleteMapByLocal(lang);
|
||||
// public List<CompanyFileTypeLocal> list = new ArrayList<>(map.values());
|
||||
// list.sort((o1, o2) -> Objects.compare(o1.getValue(), o2.getValue(),
|
||||
// String::compareTo));
|
||||
// return list;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public Page<CompanyFile> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
protected Specification<CompanyFile> buildParameterSpecification(JsonNode paramsNode) {
|
||||
Specification<CompanyFile> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
if (paramsNode.has("type")) {
|
||||
CompanyFileType type = CompanyFileType.valueOf(paramsNode.get("type").asText());
|
||||
spec = SpecificationUtils.and(spec, (root, query, builder) -> {
|
||||
return builder.equal(root.get("type"), type);
|
||||
});
|
||||
}
|
||||
// field
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "company");
|
||||
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "filePath");
|
||||
return findAll(spec, pageable);
|
||||
return spec;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -215,18 +208,23 @@ public class CompanyFileService implements IEntityService<CompanyFile>, QuerySer
|
||||
* @param companyFile 企业文件
|
||||
* @return 保存后的企业文件
|
||||
*/
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "#p0.id")
|
||||
})
|
||||
public CompanyFile save(CompanyFile companyFile) {
|
||||
return companyFileRepository.save(companyFile);
|
||||
}
|
||||
|
||||
public List<CompanyFile> findAll(Specification<CompanyFile> spec, Sort sort) {
|
||||
return companyFileRepository.findAll(spec, sort);
|
||||
}
|
||||
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "#p0")
|
||||
})
|
||||
public void deleteById(int id) {
|
||||
companyFileRepository.deleteById(id);
|
||||
}
|
||||
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "#p0.id")
|
||||
})
|
||||
public void delete(CompanyFile file) {
|
||||
companyFileRepository.delete(file);
|
||||
}
|
||||
|
||||
@@ -1,43 +1,13 @@
|
||||
package com.ecep.contract.ds.company.service;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.ecep.contract.constant.CompanyConstant;
|
||||
import com.ecep.contract.util.FileUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.EntityService;
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.MyDateTimeUtils;
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.cloud.rk.CloudRkService;
|
||||
import com.ecep.contract.cloud.tyc.CloudTycService;
|
||||
import com.ecep.contract.cloud.u8.YongYouU8Service;
|
||||
import com.ecep.contract.constant.CompanyCustomerConstant;
|
||||
import com.ecep.contract.constant.CompanyVendorConstant;
|
||||
import com.ecep.contract.constant.CompanyConstant;
|
||||
import com.ecep.contract.ds.company.repository.CompanyRepository;
|
||||
import com.ecep.contract.ds.contract.service.ContractService;
|
||||
import com.ecep.contract.ds.customer.service.CompanyCustomerService;
|
||||
@@ -47,15 +17,31 @@ import com.ecep.contract.model.Company;
|
||||
import com.ecep.contract.model.CompanyCustomer;
|
||||
import com.ecep.contract.model.CompanyOldName;
|
||||
import com.ecep.contract.model.CompanyVendor;
|
||||
import com.ecep.contract.util.FileUtils;
|
||||
import com.ecep.contract.util.MyStringUtils;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.CriteriaQuery;
|
||||
import jakarta.persistence.criteria.Path;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 公司服务
|
||||
@@ -63,7 +49,7 @@ import jakarta.transaction.Transactional;
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "company")
|
||||
public class CompanyService implements IEntityService<Company>, QueryService<Company> {
|
||||
public class CompanyService extends EntityService<Company, Integer> implements IEntityService<Company>, QueryService<Company> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CompanyService.class);
|
||||
|
||||
@Lazy
|
||||
@@ -74,9 +60,6 @@ public class CompanyService implements IEntityService<Company>, QueryService<Com
|
||||
private SysConfService confService;
|
||||
@Lazy
|
||||
@Autowired
|
||||
private CompanyFileService companyFileService;
|
||||
@Lazy
|
||||
@Autowired
|
||||
private ContractService contractService;
|
||||
@Lazy
|
||||
@Autowired
|
||||
@@ -100,6 +83,19 @@ public class CompanyService implements IEntityService<Company>, QueryService<Com
|
||||
@Autowired(required = false)
|
||||
private YongYouU8Service yongYouU8Service;
|
||||
|
||||
@Override
|
||||
protected CompanyRepository getRepository() {
|
||||
return companyRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Company createNewEntity() {
|
||||
Company company = new Company();
|
||||
company.setPathExist(false);
|
||||
company.setCreated(LocalDate.now());
|
||||
return company;
|
||||
}
|
||||
|
||||
@Cacheable(key = "#p0")
|
||||
public Company findById(Integer id) {
|
||||
return companyRepository.findById(id).orElse(null);
|
||||
@@ -120,17 +116,10 @@ public class CompanyService implements IEntityService<Company>, QueryService<Com
|
||||
return companyRepository.findAllByName(name);
|
||||
}
|
||||
|
||||
public Page<Company> findAll(Specification<Company> spec, Pageable pageable) {
|
||||
return companyRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Company> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<Company> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
return findAll(spec, pageable);
|
||||
protected Specification<Company> buildParameterSpecification(JsonNode paramsNode) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -342,16 +331,6 @@ public class CompanyService implements IEntityService<Company>, QueryService<Com
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存实体对象,异步方法
|
||||
*
|
||||
* @param company 要保存的实体对象
|
||||
* @return 返回异步调用
|
||||
*/
|
||||
public CompletableFuture<Company> asyncSave(Company company) {
|
||||
return CompletableFuture.completedFuture(companyRepository.save(company));
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存实体对象
|
||||
*
|
||||
@@ -366,28 +345,6 @@ public class CompanyService implements IEntityService<Company>, QueryService<Com
|
||||
return companyRepository.save(company);
|
||||
}
|
||||
|
||||
public long count() {
|
||||
return companyRepository.count();
|
||||
}
|
||||
|
||||
public long count(Specification<Company> spec) {
|
||||
return companyRepository.count(spec);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void findAllWithStream(Consumer<Stream<Company>> consumer) {
|
||||
try (Stream<Company> stream = companyRepository.findAllAsStream()) {
|
||||
consumer.accept(stream);
|
||||
}
|
||||
}
|
||||
|
||||
public File getVendorBasePath() {
|
||||
return new File(confService.getString(CompanyVendorConstant.KEY_BASE_PATH));
|
||||
}
|
||||
|
||||
public File getCustomerBasePath() {
|
||||
return new File(confService.getString(CompanyCustomerConstant.KEY_BASE_PATH));
|
||||
}
|
||||
|
||||
public File getBasePath() {
|
||||
return new File(confService.getString(CompanyConstant.COMPANY_BASE_PATH));
|
||||
@@ -483,6 +440,7 @@ public class CompanyService implements IEntityService<Company>, QueryService<Com
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Specification<Company> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
@@ -536,8 +494,8 @@ public class CompanyService implements IEntityService<Company>, QueryService<Com
|
||||
return (root, query, builder) -> buildSearchPredicate(searchText, root, query, builder);
|
||||
}
|
||||
|
||||
public Predicate buildSearchPredicate(String searchText, Path<Company> root, @Nullable CriteriaQuery<?> query,
|
||||
CriteriaBuilder builder) {
|
||||
public Predicate buildSearchPredicate(String searchText, Path<Company> root, CriteriaQuery<?> query,
|
||||
CriteriaBuilder builder) {
|
||||
return builder.or(
|
||||
builder.like(root.get("name"), "%" + searchText + "%"),
|
||||
builder.like(root.get("shortName"), "%" + searchText + "%"),
|
||||
@@ -548,25 +506,6 @@ public class CompanyService implements IEntityService<Company>, QueryService<Com
|
||||
builder.like(root.get("memo"), "%" + searchText + "%"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 检索企业
|
||||
* 企业名称中模糊搜索
|
||||
*
|
||||
* @param searchText 搜索文本
|
||||
* @return 企业列表,返回前10个企业
|
||||
*/
|
||||
public List<Company> search(String searchText) {
|
||||
Specification<Company> spec = getSpecification(searchText);
|
||||
return companyRepository.findAll(spec, Pageable.ofSize(10)).getContent();
|
||||
}
|
||||
|
||||
public Company createNewCompany(String name) {
|
||||
Company company = new Company();
|
||||
company.setName(name);
|
||||
company.setCreated(LocalDate.now());
|
||||
return company;
|
||||
}
|
||||
|
||||
public List<String> getAllNames(Company company) {
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add(company.getName());
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.ecep.contract.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.ds.contract.tasker.ContractVerifyComm;
|
||||
import com.ecep.contract.model.Company;
|
||||
import com.ecep.contract.model.Contract;
|
||||
import com.ecep.contract.ui.MessageHolderImpl;
|
||||
import com.ecep.contract.ui.Tasker;
|
||||
|
||||
import lombok.Getter;
|
||||
@@ -39,7 +40,7 @@ public class CompanyVerifyTasker extends Tasker<Object> {
|
||||
comm.setVerifyCompanyPath(false);
|
||||
comm.setVerifyCompanyStatus(false);
|
||||
comm.setVerifyCompanyCredit(false);
|
||||
return execute(new MessageHolderImpl() {
|
||||
return execute(new MessageHolderImpl(this) {
|
||||
@Override
|
||||
public void addMessage(Level level, String message) {
|
||||
super.addMessage(level, message);
|
||||
|
||||
@@ -12,6 +12,12 @@ import com.ecep.contract.model.Contract;
|
||||
@Repository
|
||||
public interface ContractRepository extends MyRepository<Contract, Integer> {
|
||||
|
||||
/**
|
||||
* 根据GUID查找合同的方法
|
||||
*
|
||||
* @param guid 合同的唯一标识符
|
||||
* @return 返回一个Optional<Contract>对象,可能包含找到的合同,也可能为空
|
||||
*/
|
||||
Optional<Contract> findByGuid(String guid);
|
||||
|
||||
Optional<Contract> findByProjectIdAndPayWay(int projectId, ContractPayWay payWay);
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ecep.contract.ds.contract.repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.ecep.contract.ds.MyRepository;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
@@ -11,11 +12,7 @@ import org.springframework.stereotype.Repository;
|
||||
import com.ecep.contract.model.SalesBillVoucher;
|
||||
|
||||
@Repository
|
||||
public interface SalesBillVoucherRepository extends
|
||||
// JDBC interfaces
|
||||
CrudRepository<SalesBillVoucher, Integer>, PagingAndSortingRepository<SalesBillVoucher, Integer>,
|
||||
// JPA interfaces
|
||||
JpaRepository<SalesBillVoucher, Integer>, JpaSpecificationExecutor<SalesBillVoucher> {
|
||||
public interface SalesBillVoucherRepository extends MyRepository<SalesBillVoucher, Integer> {
|
||||
|
||||
Optional<SalesBillVoucher> findByCode(String code);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.ecep.contract.ds.contract.repository;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.ecep.contract.ds.MyRepository;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
@@ -13,11 +14,7 @@ import com.ecep.contract.model.SalesOrder;
|
||||
import com.ecep.contract.model.SalesOrderItem;
|
||||
|
||||
@Repository
|
||||
public interface SalesOrderItemRepository extends
|
||||
// JDBC interfaces
|
||||
CrudRepository<SalesOrderItem, Integer>, PagingAndSortingRepository<SalesOrderItem, Integer>,
|
||||
// JPA interfaces
|
||||
JpaRepository<SalesOrderItem, Integer>, JpaSpecificationExecutor<SalesOrderItem> {
|
||||
public interface SalesOrderItemRepository extends MyRepository<SalesOrderItem, Integer> {
|
||||
|
||||
Optional<SalesOrderItem> findByCode(String code);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.ecep.contract.ds.contract.repository;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.ecep.contract.ds.MyRepository;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
@@ -13,11 +14,7 @@ import com.ecep.contract.model.Contract;
|
||||
import com.ecep.contract.model.SalesOrder;
|
||||
|
||||
@Repository
|
||||
public interface SalesOrderRepository extends
|
||||
// JDBC interfaces
|
||||
CrudRepository<SalesOrder, Integer>, PagingAndSortingRepository<SalesOrder, Integer>,
|
||||
// JPA interfaces
|
||||
JpaRepository<SalesOrder, Integer>, JpaSpecificationExecutor<SalesOrder> {
|
||||
public interface SalesOrderRepository extends MyRepository<SalesOrder, Integer> {
|
||||
|
||||
Optional<SalesOrder> findByCode(String code);
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ public class ContractBidVendorService implements IEntityService<ContractBidVendo
|
||||
}
|
||||
|
||||
// field
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "contract");
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "contract", "company");
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.ecep.contract.EntityService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -52,33 +53,26 @@ import jakarta.persistence.criteria.Predicate;
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "contract")
|
||||
public class ContractService implements IEntityService<Contract>, QueryService<Contract> {
|
||||
public class ContractService extends EntityService<Contract, Integer> implements IEntityService<Contract>, QueryService<Contract> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ContractService.class);
|
||||
@Lazy
|
||||
@Autowired
|
||||
private ContractCatalogService contractCatalogService;
|
||||
@Lazy
|
||||
@Autowired
|
||||
private ContractTypeService contractTypeService;
|
||||
@Lazy
|
||||
@Autowired
|
||||
private ContractGroupService contractGroupService;
|
||||
@Lazy
|
||||
@Autowired
|
||||
private ContractKindService contractKindService;
|
||||
@Lazy
|
||||
@Autowired
|
||||
private ContractFileService contractFileService;
|
||||
@Lazy
|
||||
@Autowired
|
||||
protected ContractRepository contractRepository;
|
||||
@Lazy
|
||||
@Autowired
|
||||
protected SysConfService confService;
|
||||
|
||||
@Override
|
||||
protected ContractRepository getRepository() {
|
||||
return contractRepository;
|
||||
}
|
||||
|
||||
@Cacheable(key = "#p0")
|
||||
public Contract findById(Integer id) {
|
||||
return contractRepository.findById(id).orElse(null);
|
||||
return getRepository().findById(id).orElse(null);
|
||||
}
|
||||
|
||||
public Contract findByName(String name) {
|
||||
@@ -113,43 +107,6 @@ public class ContractService implements IEntityService<Contract>, QueryService<C
|
||||
contractRepository.delete(contract);
|
||||
}
|
||||
|
||||
public long count() {
|
||||
return contractRepository.count();
|
||||
}
|
||||
|
||||
public long count(Specification<Contract> spec) {
|
||||
return contractRepository.count(spec);
|
||||
}
|
||||
|
||||
public Page<Contract> findAll(Specification<Contract> spec, Pageable pageable) {
|
||||
return contractRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
public List<Contract> findAll(Specification<Contract> spec, Sort sort) {
|
||||
return contractRepository.findAll(spec, sort);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Contract> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<Contract> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// field
|
||||
if (paramsNode.has("payWay")) {
|
||||
ContractPayWay payWay = ContractPayWay.valueOf(paramsNode.get("payWay").asText());
|
||||
spec = SpecificationUtils.and(spec, (root, query, cb) -> {
|
||||
return cb.equal(root.get("payWay"), payWay);
|
||||
});
|
||||
}
|
||||
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "parentCode");
|
||||
|
||||
// relation
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "group", "kind", "type", "group", "company", "project");
|
||||
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
public List<Contract> findAllByCompany(Company company) {
|
||||
return contractRepository.findAllByCompanyId(company.getId());
|
||||
}
|
||||
@@ -170,33 +127,6 @@ public class ContractService implements IEntityService<Contract>, QueryService<C
|
||||
return new File(confService.getString(ContractConstant.KEY_BASE_PATH));
|
||||
}
|
||||
|
||||
public ContractGroup findGroupById(Integer id) {
|
||||
return contractGroupService.findById(id);
|
||||
}
|
||||
|
||||
public ContractGroup findGroupByCode(String groupCode) {
|
||||
return contractGroupService.findByCode(groupCode);
|
||||
}
|
||||
|
||||
public List<ContractGroup> findAllGroups() {
|
||||
return contractGroupService.findAll();
|
||||
}
|
||||
|
||||
public ContractType findTypeById(Integer id) {
|
||||
return contractTypeService.findById(id);
|
||||
}
|
||||
|
||||
public ContractType findTypeByCode(String typeCode) {
|
||||
return contractTypeService.findByCode(typeCode);
|
||||
}
|
||||
|
||||
public ContractKind findKindById(Integer id) {
|
||||
return contractKindService.findById(id);
|
||||
}
|
||||
|
||||
public ContractKind findKindByName(String kindName) {
|
||||
return contractKindService.findByName(kindName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回合同的分类目录
|
||||
@@ -270,18 +200,28 @@ public class ContractService implements IEntityService<Contract>, QueryService<C
|
||||
return contractCatalogService.findByCode(catalogCode);
|
||||
}
|
||||
|
||||
public Contract createNew() {
|
||||
public Contract createNewEntity() {
|
||||
Contract contract = new Contract();
|
||||
contract.setCreated(LocalDateTime.now());
|
||||
return contract;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<Contract> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
return null;
|
||||
protected Specification<Contract> buildParameterSpecification(JsonNode paramsNode) {
|
||||
Specification<Contract> spec = null;
|
||||
// field
|
||||
if (paramsNode.has("payWay")) {
|
||||
ContractPayWay payWay = ContractPayWay.valueOf(paramsNode.get("payWay").asText());
|
||||
spec = SpecificationUtils.and(spec, (root, query, cb) -> {
|
||||
return cb.equal(root.get("payWay"), payWay);
|
||||
});
|
||||
}
|
||||
return SpecificationUtils.andWith(searchText, this::buildSearchSpecification);
|
||||
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "parentCode");
|
||||
spec = SpecificationUtils.andFieldBetweenParam(spec, paramsNode, "setupDate", LocalDate.class);
|
||||
|
||||
// relation
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "group", "kind", "type", "group", "company", "project");
|
||||
return spec;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -424,10 +364,6 @@ public class ContractService implements IEntityService<Contract>, QueryService<C
|
||||
return contractRepository.findAllByParentCode(contract.getCode());
|
||||
}
|
||||
|
||||
public List<Contract> search(String searchText) {
|
||||
Specification<Contract> spec = getSpecification(searchText);
|
||||
return contractRepository.findAll(spec, Pageable.ofSize(10)).getContent();
|
||||
}
|
||||
|
||||
public List<Contract> findByCodeStartsWith(ContractPayWay payWay, String parentCode) {
|
||||
return contractRepository.findByPayWayAndCodeStartsWith(payWay, parentCode);
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
package com.ecep.contract.ds.contract.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.EntityService;
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.ds.MyRepository;
|
||||
import com.ecep.contract.ds.contract.repository.SalesOrderRepository;
|
||||
import com.ecep.contract.model.Contract;
|
||||
import com.ecep.contract.model.PurchaseOrder;
|
||||
import com.ecep.contract.model.SalesOrder;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -17,10 +25,7 @@ import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.ds.contract.repository.SalesOrderRepository;
|
||||
import com.ecep.contract.model.Contract;
|
||||
import com.ecep.contract.model.SalesOrder;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 合同服务
|
||||
@@ -28,23 +33,39 @@ import com.ecep.contract.model.SalesOrder;
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "contract-sale-order")
|
||||
public class SaleOrdersService implements IEntityService<SalesOrder> {
|
||||
public class SaleOrdersService extends EntityService<SalesOrder, Integer> implements IEntityService<SalesOrder>, QueryService<SalesOrder> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(SaleOrdersService.class);
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
private SalesOrderRepository salesOrderRepository;
|
||||
|
||||
@Override
|
||||
protected SalesOrderRepository getRepository() {
|
||||
return salesOrderRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SalesOrder createNewEntity() {
|
||||
return new SalesOrder();
|
||||
}
|
||||
|
||||
@Cacheable(key = "#p0")
|
||||
public SalesOrder findById(Integer id) {
|
||||
return salesOrderRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Specification<SalesOrder> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
return null;
|
||||
}
|
||||
protected Specification<SalesOrder> buildParameterSpecification(JsonNode paramsNode) {
|
||||
Specification<SalesOrder> spec = null;
|
||||
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "code");
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "contract", "employee", "maker", "verifier");
|
||||
return spec;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Specification<SalesOrder> buildSearchSpecification(String searchText) {
|
||||
return (root, query, builder) -> {
|
||||
return builder.or(
|
||||
builder.like(root.get("name"), "%" + searchText + "%"),
|
||||
@@ -79,27 +100,8 @@ public class SaleOrdersService implements IEntityService<SalesOrder> {
|
||||
salesOrderRepository.delete(order);
|
||||
}
|
||||
|
||||
public long count() {
|
||||
return salesOrderRepository.count();
|
||||
}
|
||||
|
||||
public long count(Specification<SalesOrder> spec) {
|
||||
return salesOrderRepository.count(spec);
|
||||
}
|
||||
|
||||
public Page<SalesOrder> findAll(Specification<SalesOrder> spec, Pageable pageable) {
|
||||
return salesOrderRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
public List<SalesOrder> findAll(Specification<SalesOrder> spec, Sort sort) {
|
||||
return salesOrderRepository.findAll(spec, sort);
|
||||
}
|
||||
|
||||
public List<SalesOrder> findAllByContract(Contract contract) {
|
||||
return salesOrderRepository.findAllByContract(contract);
|
||||
}
|
||||
|
||||
public List<SalesOrder> search(String searchText) {
|
||||
return salesOrderRepository.findAll(getSpecification(searchText), Pageable.ofSize(10)).getContent();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,12 @@ package com.ecep.contract.ds.contract.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.EntityService;
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.ds.MyRepository;
|
||||
import com.ecep.contract.model.SalesOrder;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -29,7 +35,7 @@ import com.ecep.contract.model.SalesBillVoucherItem;
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "sales-bill-voucher")
|
||||
public class SalesBillVoucherService implements IEntityService<SalesBillVoucher> {
|
||||
public class SalesBillVoucherService extends EntityService<SalesBillVoucher, Integer> implements IEntityService<SalesBillVoucher>, QueryService<SalesBillVoucher> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(SalesBillVoucherService.class);
|
||||
|
||||
@Lazy
|
||||
@@ -39,6 +45,15 @@ public class SalesBillVoucherService implements IEntityService<SalesBillVoucher>
|
||||
@Autowired
|
||||
private SalesBillVoucherItemRepository salesBillVoucherItemRepository;
|
||||
|
||||
@Override
|
||||
protected SalesBillVoucherRepository getRepository() {
|
||||
return salesBillVoucherRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SalesBillVoucher createNewEntity() {
|
||||
return new SalesBillVoucher();
|
||||
}
|
||||
|
||||
@Cacheable(key = "#p0")
|
||||
public SalesBillVoucher findById(Integer id) {
|
||||
@@ -46,11 +61,7 @@ public class SalesBillVoucherService implements IEntityService<SalesBillVoucher>
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<SalesBillVoucher> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected Specification<SalesBillVoucher> buildSearchSpecification(String searchText) {
|
||||
return (root, query, builder) -> {
|
||||
return builder.or(
|
||||
builder.like(root.get("name"), "%" + searchText + "%"),
|
||||
@@ -90,33 +101,15 @@ public class SalesBillVoucherService implements IEntityService<SalesBillVoucher>
|
||||
salesBillVoucherRepository.delete(order);
|
||||
}
|
||||
|
||||
public long count() {
|
||||
return salesBillVoucherRepository.count();
|
||||
}
|
||||
|
||||
public long count(Specification<SalesBillVoucher> spec) {
|
||||
return salesBillVoucherRepository.count(spec);
|
||||
@Override
|
||||
protected Specification<SalesBillVoucher> buildParameterSpecification(JsonNode paramsNode) {
|
||||
Specification<SalesBillVoucher> spec = null;
|
||||
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "refId");
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "company", "order", "employee", "maker", "verifier");
|
||||
return spec;
|
||||
}
|
||||
|
||||
public Page<SalesBillVoucher> findAll(Specification<SalesBillVoucher> spec, Pageable pageable) {
|
||||
return salesBillVoucherRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
public List<SalesBillVoucher> findAll(Specification<SalesBillVoucher> spec, Sort sort) {
|
||||
return salesBillVoucherRepository.findAll(spec, sort);
|
||||
}
|
||||
|
||||
public List<SalesBillVoucher> search(String searchText) {
|
||||
Specification<SalesBillVoucher> spec = (root, query, builder) -> {
|
||||
return builder.or(
|
||||
builder.like(root.get("name"), "%" + searchText + "%"),
|
||||
builder.like(root.get("code"), "%" + searchText + "%")
|
||||
);
|
||||
};
|
||||
return salesBillVoucherRepository.findAll(spec, Pageable.ofSize(10)).getContent();
|
||||
}
|
||||
|
||||
|
||||
@Cacheable(key = "'item-'+#p0")
|
||||
public SalesBillVoucherItem findItemById(Integer id) {
|
||||
return salesBillVoucherItemRepository.findById(id).orElse(null);
|
||||
|
||||
@@ -2,6 +2,11 @@ package com.ecep.contract.ds.contract.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.EntityService;
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.model.SalesOrder;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
@@ -21,19 +26,30 @@ import com.ecep.contract.model.SalesOrderItem;
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "contract-sale-order-item")
|
||||
public class SalesOrderItemService implements IEntityService<SalesOrderItem> {
|
||||
public class SalesOrderItemService extends EntityService<SalesOrderItem, Integer> implements IEntityService<SalesOrderItem>, QueryService<SalesOrderItem> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private SalesOrderItemRepository repository;
|
||||
|
||||
@Override
|
||||
public SalesOrderItemRepository getRepository() {
|
||||
return repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SalesOrderItem createNewEntity() {
|
||||
return new SalesOrderItem();
|
||||
}
|
||||
|
||||
@Cacheable(key = "#p0")
|
||||
@Override
|
||||
public SalesOrderItem findById(Integer id) {
|
||||
return repository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Specification<SalesOrderItem> getSpecification(String searchText) {
|
||||
protected Specification<SalesOrderItem> buildSearchSpecification(String searchText) {
|
||||
return (root, query, builder) -> {
|
||||
return builder.or(
|
||||
builder.like(root.get("code"), "%" + searchText + "%"),
|
||||
@@ -44,8 +60,11 @@ public class SalesOrderItemService implements IEntityService<SalesOrderItem> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<SalesOrderItem> findAll(Specification<SalesOrderItem> spec, Pageable pageable) {
|
||||
return repository.findAll(spec, pageable);
|
||||
protected Specification<SalesOrderItem> buildParameterSpecification(JsonNode paramsNode) {
|
||||
Specification<SalesOrderItem> spec = null;
|
||||
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "code");
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "order");
|
||||
return spec;
|
||||
}
|
||||
|
||||
@Caching(
|
||||
@@ -67,8 +86,4 @@ public class SalesOrderItemService implements IEntityService<SalesOrderItem> {
|
||||
public SalesOrderItem save(SalesOrderItem entity) {
|
||||
return repository.save(entity);
|
||||
}
|
||||
|
||||
public List<SalesOrderItem> findAll(Specification<SalesOrderItem> spec, Sort sort) {
|
||||
return repository.findAll(spec, sort);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package com.ecep.contract.ds.contract.tasker;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import com.ecep.contract.ds.contract.service.ContractService;
|
||||
import com.ecep.contract.service.WebSocketServerTasker;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.ContractPayWay;
|
||||
@@ -14,19 +18,25 @@ import lombok.Setter;
|
||||
/**
|
||||
* 合同修复任务
|
||||
*/
|
||||
public class ContractRepairTask extends AbstContractRepairTasker {
|
||||
public class ContractRepairTask extends AbstContractRepairTasker implements WebSocketServerTasker {
|
||||
@Getter
|
||||
@Setter
|
||||
private Contract contract;
|
||||
@Getter
|
||||
boolean repaired = false;
|
||||
|
||||
|
||||
|
||||
private final ContractRepairComm comm = new ContractRepairComm();
|
||||
|
||||
public ContractRepairTask() {
|
||||
}
|
||||
|
||||
public void init(JsonNode argsNode) {
|
||||
int contractId = argsNode.get(1).asInt();
|
||||
contract = getCachedBean(ContractService.class).findById(contractId);
|
||||
String lang = argsNode.get(2).asText();
|
||||
setLocale(Locale.forLanguageTag(lang));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void repair(MessageHolder holder) {
|
||||
updateTitle("修复合同 " + contract.toPrettyString());
|
||||
@@ -41,6 +51,7 @@ public class ContractRepairTask extends AbstContractRepairTasker {
|
||||
AtomicReference<Contract> contractProperty = new AtomicReference<>(contract);
|
||||
if (repair(contractProperty, parent, holder, progress -> updateProgress(progress, 1))) {
|
||||
repaired = true;
|
||||
updateProperty("repaired", true);
|
||||
}
|
||||
|
||||
setContract(contractProperty.get());
|
||||
@@ -48,5 +59,9 @@ public class ContractRepairTask extends AbstContractRepairTasker {
|
||||
updateProgress(1, 1);
|
||||
}
|
||||
|
||||
public void setContract(Contract contract) {
|
||||
this.contract = contract;
|
||||
updateProperty("contract", contract);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ import com.ecep.contract.ds.project.service.ProjectCostService;
|
||||
import com.ecep.contract.ds.project.service.ProjectQuotationService;
|
||||
import com.ecep.contract.ds.project.service.ProjectSaleTypeRequireFileTypeService;
|
||||
import com.ecep.contract.ds.project.service.ProjectService;
|
||||
import com.ecep.contract.ds.project.service.SaleTypeService;
|
||||
import com.ecep.contract.ds.project.service.ProjectSaleTypeService;
|
||||
import com.ecep.contract.ds.vendor.service.CompanyVendorService;
|
||||
import com.ecep.contract.ds.vendor.service.VendorGroupRequireFileTypeService;
|
||||
import com.ecep.contract.ds.vendor.service.VendorGroupService;
|
||||
@@ -74,7 +74,7 @@ public class ContractVerifyComm {
|
||||
// Project
|
||||
private ProjectService projectService;
|
||||
private ProjectSaleTypeRequireFileTypeService saleTypeRequireFileTypeService;
|
||||
private SaleTypeService saleTypeService;
|
||||
private ProjectSaleTypeService projectSaleTypeService;
|
||||
private ProjectCostService projectCostService;
|
||||
private ProjectQuotationService projectQuotationService;
|
||||
private ProjectBidService projectBidService;
|
||||
@@ -106,11 +106,11 @@ public class ContractVerifyComm {
|
||||
return projectService;
|
||||
}
|
||||
|
||||
private SaleTypeService getSaleTypeService() {
|
||||
if (saleTypeService == null) {
|
||||
saleTypeService = SpringApp.getBean(SaleTypeService.class);
|
||||
private ProjectSaleTypeService getProjectSaleTypeService() {
|
||||
if (projectSaleTypeService == null) {
|
||||
projectSaleTypeService = SpringApp.getBean(ProjectSaleTypeService.class);
|
||||
}
|
||||
return saleTypeService;
|
||||
return projectSaleTypeService;
|
||||
}
|
||||
|
||||
ProjectCostService getProjectCostService() {
|
||||
@@ -574,7 +574,7 @@ public class ContractVerifyComm {
|
||||
if (saleType != null) {
|
||||
if (CompanyFileUtils.exists(contract.getPath())) {
|
||||
if (!Hibernate.isInitialized(saleType)) {
|
||||
saleType = getSaleTypeService().findById(saleType.getId());
|
||||
saleType = getProjectSaleTypeService().findById(saleType.getId());
|
||||
project.setSaleType(saleType);
|
||||
}
|
||||
if (!contract.getPath().startsWith(saleType.getPath())) {
|
||||
@@ -725,7 +725,7 @@ public class ContractVerifyComm {
|
||||
if (saleType == null) {
|
||||
String code = contract.getCode();
|
||||
if (code != null && code.length() > 5) {
|
||||
saleType = getSaleTypeService().findByCode(code.substring(0, 1));
|
||||
saleType = getProjectSaleTypeService().findByCode(code.substring(0, 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -865,7 +865,7 @@ public class ContractVerifyComm {
|
||||
}
|
||||
}
|
||||
if (!Hibernate.isInitialized(saleType)) {
|
||||
saleType = getSaleTypeService().findById(saleType.getId());
|
||||
saleType = getProjectSaleTypeService().findById(saleType.getId());
|
||||
}
|
||||
if (saleType.isCriticalProjectDecision()) {
|
||||
if (contract.getAmount() != null && contract.getAmount() >= saleType.getCriticalProjectLimit()) {
|
||||
|
||||
@@ -7,12 +7,15 @@ import java.util.logging.Level;
|
||||
import com.ecep.contract.MessageHolder;
|
||||
import com.ecep.contract.ds.contract.service.ContractService;
|
||||
import com.ecep.contract.model.Contract;
|
||||
import com.ecep.contract.service.WebSocketServerTasker;
|
||||
import com.ecep.contract.ui.MessageHolderImpl;
|
||||
import com.ecep.contract.ui.Tasker;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
public class ContractVerifyTasker extends Tasker<Object> {
|
||||
public class ContractVerifyTasker extends Tasker<Object> implements WebSocketServerTasker {
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -24,7 +27,7 @@ public class ContractVerifyTasker extends Tasker<Object> {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
updateTitle("验证合同 " + contract.getCode() + " 及其子合同是否符合合规要求");
|
||||
return execute(new MessageHolderImpl() {
|
||||
return execute(new MessageHolderImpl(this) {
|
||||
@Override
|
||||
public void addMessage(Level level, String message) {
|
||||
super.addMessage(level, message);
|
||||
@@ -58,4 +61,12 @@ public class ContractVerifyTasker extends Tasker<Object> {
|
||||
public void setLocale(Locale locale) {
|
||||
comm.setLocale(locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(JsonNode argsNode) {
|
||||
int contractId = argsNode.get(1).asInt();
|
||||
contract = getCachedBean(ContractService.class).findById(contractId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import com.ecep.contract.ds.project.service.ProjectCostService;
|
||||
import com.ecep.contract.ds.project.service.ProjectIndustryService;
|
||||
import com.ecep.contract.ds.project.service.ProjectService;
|
||||
import com.ecep.contract.ds.project.service.ProjectTypeService;
|
||||
import com.ecep.contract.ds.project.service.SaleTypeService;
|
||||
import com.ecep.contract.ds.project.service.ProjectSaleTypeService;
|
||||
import com.ecep.contract.model.Company;
|
||||
import com.ecep.contract.model.Contract;
|
||||
import com.ecep.contract.model.Employee;
|
||||
@@ -90,7 +90,7 @@ public class CustomerContractCostFormUpdateTask extends Tasker<Object> {
|
||||
@Setter
|
||||
private ProjectTypeService projectTypeService;
|
||||
@Setter
|
||||
private SaleTypeService saleTypeService;
|
||||
private ProjectSaleTypeService projectSaleTypeService;
|
||||
@Setter
|
||||
private ProjectIndustryService projectIndustryService;
|
||||
@Setter
|
||||
@@ -116,11 +116,11 @@ public class CustomerContractCostFormUpdateTask extends Tasker<Object> {
|
||||
return projectTypeService;
|
||||
}
|
||||
|
||||
private SaleTypeService getSaleTypeService() {
|
||||
if (saleTypeService == null) {
|
||||
saleTypeService = SpringApp.getBean(SaleTypeService.class);
|
||||
private ProjectSaleTypeService getProjectSaleTypeService() {
|
||||
if (projectSaleTypeService == null) {
|
||||
projectSaleTypeService = SpringApp.getBean(ProjectSaleTypeService.class);
|
||||
}
|
||||
return saleTypeService;
|
||||
return projectSaleTypeService;
|
||||
}
|
||||
|
||||
private ProjectIndustryService getProjectIndustryService() {
|
||||
@@ -262,7 +262,7 @@ public class CustomerContractCostFormUpdateTask extends Tasker<Object> {
|
||||
saleType = project.getSaleType();
|
||||
if (saleType != null) {
|
||||
if (!Hibernate.isInitialized(saleType)) {
|
||||
saleType = getSaleTypeService().findById(saleType.getId());
|
||||
saleType = getProjectSaleTypeService().findById(saleType.getId());
|
||||
project.setSaleType(saleType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,13 @@ public class BankService implements IEntityService<Bank>, QueryService<Bank> {
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public long count(JsonNode paramsNode) {
|
||||
return bankRepository.count();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<Bank> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ecep.contract.ds.other.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
@@ -57,6 +58,7 @@ public class EmployeeAuthBindService implements IEntityService<EmployeeAuthBind>
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// 可以根据需要添加更多参数处理
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "employee");
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
package com.ecep.contract.ds.other.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.ds.other.repository.EmployeeRepository;
|
||||
import com.ecep.contract.model.Employee;
|
||||
import com.ecep.contract.model.EmployeeRole;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -17,14 +22,8 @@ import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.ecep.contract.ds.other.repository.EmployeeRepository;
|
||||
import com.ecep.contract.model.Employee;
|
||||
import com.ecep.contract.model.EmployeeRole;
|
||||
|
||||
import jakarta.transaction.Transactional;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 员工服务类
|
||||
@@ -119,6 +118,8 @@ public class EmployeeService implements IEntityService<Employee>, QueryService<E
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// 可以根据需要添加更多参数处理
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "department");
|
||||
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "isActive");
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@@ -155,7 +156,7 @@ public class EmployeeService implements IEntityService<Employee>, QueryService<E
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<EmployeeRole> getRolesByEmployeeId(int employeeId) {
|
||||
public List<EmployeeRole> getRolesByEmployeeId(Integer employeeId) {
|
||||
Optional<Employee> optional = employeeRepository.findById(employeeId);
|
||||
if (optional.isPresent()) {
|
||||
Employee employee = optional.get();
|
||||
|
||||
@@ -2,6 +2,10 @@ package com.ecep.contract.ds.project.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.model.CompanyBankAccount;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -20,7 +24,7 @@ import com.ecep.contract.model.CustomerSatisfactionSurvey;
|
||||
@Lazy
|
||||
@Service
|
||||
public class CustomerSatisfactionSurveyService
|
||||
implements IEntityService<CustomerSatisfactionSurvey> {
|
||||
implements IEntityService<CustomerSatisfactionSurvey>, QueryService<CustomerSatisfactionSurvey> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private CustomerSatisfactionSurveyRepository repository;
|
||||
@@ -86,4 +90,15 @@ public class CustomerSatisfactionSurveyService
|
||||
public List<CustomerSatisfactionSurvey> findAll(Specification<CustomerSatisfactionSurvey> spec) {
|
||||
return repository.findAll(spec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<CustomerSatisfactionSurvey> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<CustomerSatisfactionSurvey> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// field
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "project", "applicant");
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@ package com.ecep.contract.ds.project.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.model.CompanyBankAccount;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
@@ -22,7 +26,7 @@ import com.ecep.contract.model.ProjectSaleType;
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "project-sign-method")
|
||||
public class DeliverySignMethodService implements IEntityService<DeliverySignMethod> {
|
||||
public class DeliverySignMethodService implements IEntityService<DeliverySignMethod>, QueryService<DeliverySignMethod> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private ProductDeliverySignMethodRepository deliverySignMethodRepository;
|
||||
@@ -37,6 +41,17 @@ public class DeliverySignMethodService implements IEntityService<DeliverySignMet
|
||||
return deliverySignMethodRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<DeliverySignMethod> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<DeliverySignMethod> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// field
|
||||
// spec = SpecificationUtils.andParam(spec, paramsNode, "company");
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
public DeliverySignMethod findBySaleTypeAndName(ProjectSaleType saleType, String name) {
|
||||
return deliverySignMethodRepository.findBySaleTypeAndName(saleType, name).orElse(null);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@ package com.ecep.contract.ds.project.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.model.CompanyBankAccount;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
@@ -21,7 +25,7 @@ import com.ecep.contract.model.ProductType;
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "product-type")
|
||||
public class ProductTypeService implements IEntityService<ProductType> {
|
||||
public class ProductTypeService implements IEntityService<ProductType>, QueryService<ProductType> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private ProductTypeRepository productTypeRepository;
|
||||
@@ -50,6 +54,18 @@ public class ProductTypeService implements IEntityService<ProductType> {
|
||||
return productTypeRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Page<ProductType> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<ProductType> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// field
|
||||
// spec = SpecificationUtils.andParam(spec, paramsNode, "company");
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<ProductType> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
|
||||
@@ -2,6 +2,10 @@ package com.ecep.contract.ds.project.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.model.CompanyBankAccount;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
@@ -21,7 +25,7 @@ import com.ecep.contract.model.ProductUsage;
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "product-usage")
|
||||
public class ProductUsageService implements IEntityService<ProductUsage> {
|
||||
public class ProductUsageService implements IEntityService<ProductUsage>, QueryService<ProductUsage> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private ProductUsageRepository productUsageRepository;
|
||||
@@ -36,6 +40,17 @@ public class ProductUsageService implements IEntityService<ProductUsage> {
|
||||
return productUsageRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ProductUsage> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<ProductUsage> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// field
|
||||
// spec = SpecificationUtils.andParam(spec, paramsNode, "company");
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<ProductUsage> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
|
||||
@@ -3,6 +3,10 @@ package com.ecep.contract.ds.project.service;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.model.CompanyBankAccount;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -20,7 +24,7 @@ import com.ecep.contract.model.ProjectBid;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
public class ProjectBidService implements IEntityService<ProjectBid> {
|
||||
public class ProjectBidService implements IEntityService<ProjectBid>, QueryService<ProjectBid> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProjectBidService.class);
|
||||
|
||||
@Lazy
|
||||
@@ -36,6 +40,17 @@ public class ProjectBidService implements IEntityService<ProjectBid> {
|
||||
return repository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ProjectBid> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<ProjectBid> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// field
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "project", "cost", "applicant", "authorizer");
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
public List<ProjectBid> findAllByProject(Project project) {
|
||||
return repository.findAllByProject(project);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@ package com.ecep.contract.ds.project.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.model.CompanyBankAccount;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -17,7 +21,7 @@ import com.ecep.contract.model.ProjectCostItem;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
public class ProjectCostItemService implements IEntityService<ProjectCostItem> {
|
||||
public class ProjectCostItemService implements IEntityService<ProjectCostItem>, QueryService<ProjectCostItem> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private ProjectCostItemRepository repository;
|
||||
@@ -48,6 +52,17 @@ public class ProjectCostItemService implements IEntityService<ProjectCostItem> {
|
||||
return repository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ProjectCostItem> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<ProjectCostItem> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// field
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "cost", "inventory", "creator", "updater");
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(ProjectCostItem entity) {
|
||||
repository.delete(entity);
|
||||
|
||||
@@ -3,6 +3,10 @@ package com.ecep.contract.ds.project.service;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.model.CompanyBankAccount;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -22,7 +26,7 @@ import com.ecep.contract.model.ProjectCost;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
public class ProjectCostService implements IEntityService<ProjectCost> {
|
||||
public class ProjectCostService implements IEntityService<ProjectCost>, QueryService<ProjectCost> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProjectCostService.class);
|
||||
|
||||
@Lazy
|
||||
@@ -39,6 +43,17 @@ public class ProjectCostService implements IEntityService<ProjectCost> {
|
||||
return repository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ProjectCost> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<ProjectCost> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// field
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "contract", "project", "applicant", "authorizer");
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
public ProjectCost findByContract(Contract contract) {
|
||||
return repository.findByContract(contract).orElse(null);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,10 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.model.CompanyBankAccount;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -24,7 +28,7 @@ import com.ecep.contract.model.ProjectFile;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
public class ProjectFileService implements IEntityService<ProjectFile> {
|
||||
public class ProjectFileService implements IEntityService<ProjectFile>, QueryService<ProjectFile> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProjectFileService.class);
|
||||
|
||||
@Autowired
|
||||
@@ -39,6 +43,17 @@ public class ProjectFileService implements IEntityService<ProjectFile> {
|
||||
return projectFileRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ProjectFile> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<ProjectFile> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// field
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "project");
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
public List<ProjectFile> findAllByProject(Project project) {
|
||||
return projectFileRepository.findByProject(project);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,10 @@ package com.ecep.contract.ds.project.service;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.model.CompanyBankAccount;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -20,7 +24,7 @@ import com.ecep.contract.model.ProjectFundPlan;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
public class ProjectFundPlanService implements IEntityService<ProjectFundPlan> {
|
||||
public class ProjectFundPlanService implements IEntityService<ProjectFundPlan>, QueryService<ProjectFundPlan> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProjectFundPlanService.class);
|
||||
|
||||
@Lazy
|
||||
@@ -36,6 +40,17 @@ public class ProjectFundPlanService implements IEntityService<ProjectFundPlan> {
|
||||
return repository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ProjectFundPlan> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<ProjectFundPlan> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// field
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "project", "contractPayPlan");
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
public List<ProjectFundPlan> findAllByProject(Project project) {
|
||||
return repository.findAllByProject(project);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@ package com.ecep.contract.ds.project.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.model.CompanyBankAccount;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
@@ -21,7 +25,7 @@ import com.ecep.contract.model.ProjectIndustry;
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "project-industry")
|
||||
public class ProjectIndustryService implements IEntityService<ProjectIndustry> {
|
||||
public class ProjectIndustryService implements IEntityService<ProjectIndustry>, QueryService<ProjectIndustry> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private ProjectIndustryRepository industryRepository;
|
||||
@@ -50,6 +54,17 @@ public class ProjectIndustryService implements IEntityService<ProjectIndustry> {
|
||||
return industryRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ProjectIndustry> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<ProjectIndustry> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// field
|
||||
// spec = SpecificationUtils.andParam(spec, paramsNode, "company");
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<ProjectIndustry> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
|
||||
@@ -3,6 +3,10 @@ package com.ecep.contract.ds.project.service;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.model.CompanyBankAccount;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -20,7 +24,7 @@ import com.ecep.contract.model.ProjectQuotation;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
public class ProjectQuotationService implements IEntityService<ProjectQuotation> {
|
||||
public class ProjectQuotationService implements IEntityService<ProjectQuotation>, QueryService<ProjectQuotation> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProjectQuotationService.class);
|
||||
|
||||
|
||||
@@ -38,6 +42,17 @@ public class ProjectQuotationService implements IEntityService<ProjectQuotation>
|
||||
return repository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ProjectQuotation> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<ProjectQuotation> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// field
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "project", "applicant","authorizer");
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
public List<ProjectQuotation> findAllByProject(Project project) {
|
||||
return repository.findAllByProject(project);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@ package com.ecep.contract.ds.project.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.model.CompanyBankAccount;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
@@ -20,7 +24,7 @@ import com.ecep.contract.model.ProjectSaleTypeRequireFileType;
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "project-sale-type-require-file-type")
|
||||
public class ProjectSaleTypeRequireFileTypeService implements IEntityService<ProjectSaleTypeRequireFileType> {
|
||||
public class ProjectSaleTypeRequireFileTypeService implements IEntityService<ProjectSaleTypeRequireFileType>, QueryService<ProjectSaleTypeRequireFileType> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private ProjectSaleTypeRequireFileTypeRepository repository;
|
||||
@@ -46,6 +50,17 @@ public class ProjectSaleTypeRequireFileTypeService implements IEntityService<Pro
|
||||
return repository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ProjectSaleTypeRequireFileType> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<ProjectSaleTypeRequireFileType> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// field
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "saleType");
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<ProjectSaleTypeRequireFileType> getSpecification(String searchText) {
|
||||
return null;
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.ecep.contract.ds.project.service;
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.model.CompanyBankAccount;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -24,8 +23,8 @@ import com.ecep.contract.model.ProjectSaleType;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "sale-type")
|
||||
public class SaleTypeService implements IEntityService<ProjectSaleType>, QueryService<ProjectSaleType> {
|
||||
@CacheConfig(cacheNames = "project-sale-type")
|
||||
public class ProjectSaleTypeService implements IEntityService<ProjectSaleType>, QueryService<ProjectSaleType> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private ProjectSaleTypeRepository saleTypeRepository;
|
||||
|
||||
@@ -8,6 +8,10 @@ import java.util.Optional;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.constant.ProjectConstant;
|
||||
import com.ecep.contract.model.*;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -25,14 +29,6 @@ import org.springframework.util.StringUtils;
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.ds.other.service.SysConfService;
|
||||
import com.ecep.contract.ds.project.repository.ProjectRepository;
|
||||
import com.ecep.contract.model.Contract;
|
||||
import com.ecep.contract.model.DeliverySignMethod;
|
||||
import com.ecep.contract.model.ProductType;
|
||||
import com.ecep.contract.model.ProductUsage;
|
||||
import com.ecep.contract.model.Project;
|
||||
import com.ecep.contract.model.ProjectIndustry;
|
||||
import com.ecep.contract.model.ProjectSaleType;
|
||||
import com.ecep.contract.model.ProjectType;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
|
||||
/**
|
||||
@@ -41,11 +37,9 @@ import com.ecep.contract.util.SpecificationUtils;
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "project")
|
||||
public class ProjectService implements IEntityService<Project> {
|
||||
public class ProjectService implements IEntityService<Project>, QueryService<Project> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProjectService.class);
|
||||
|
||||
public static final String KEY_BASE_PATH = "project.base.path";
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
private ProjectRepository projectRepository;
|
||||
@@ -66,7 +60,7 @@ public class ProjectService implements IEntityService<Project> {
|
||||
private ProjectIndustryService projectIndustryService;
|
||||
@Lazy
|
||||
@Autowired
|
||||
private SaleTypeService saleTypeService;
|
||||
private ProjectSaleTypeService projectSaleTypeService;
|
||||
@Lazy
|
||||
@Autowired
|
||||
private ProjectTypeService projectTypeService;
|
||||
@@ -90,7 +84,7 @@ public class ProjectService implements IEntityService<Project> {
|
||||
}
|
||||
|
||||
public File getBasePath() {
|
||||
return new File(confService.getString(KEY_BASE_PATH));
|
||||
return new File(confService.getString(ProjectConstant.KEY_BASE_PATH));
|
||||
}
|
||||
|
||||
public boolean makePathAbsent(Project project) {
|
||||
@@ -130,6 +124,23 @@ public class ProjectService implements IEntityService<Project> {
|
||||
return projectRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Project> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<Project> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// field
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "customer","industry","saleType", "projectType", "productType","deliverySignMethod", "productUsage");
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "applicant","authorizer");
|
||||
|
||||
//
|
||||
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "code");
|
||||
|
||||
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@CacheEvict(key = "#p0.id")
|
||||
public void delete(Project project) {
|
||||
projectRepository.delete(project);
|
||||
@@ -186,7 +197,7 @@ public class ProjectService implements IEntityService<Project> {
|
||||
|
||||
if (code.length() >= 6) {
|
||||
try {
|
||||
ProjectSaleType saleType = saleTypeService.findByCode(code.substring(0, 1));
|
||||
ProjectSaleType saleType = projectSaleTypeService.findByCode(code.substring(0, 1));
|
||||
if (saleType == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -228,7 +239,7 @@ public class ProjectService implements IEntityService<Project> {
|
||||
}
|
||||
}
|
||||
|
||||
ProjectSaleType saleType = saleTypeService.findByCode(saleTypeCode);
|
||||
ProjectSaleType saleType = projectSaleTypeService.findByCode(saleTypeCode);
|
||||
if (saleType != null) {
|
||||
project.setSaleType(saleType);
|
||||
}
|
||||
@@ -307,7 +318,7 @@ public class ProjectService implements IEntityService<Project> {
|
||||
return null;
|
||||
}
|
||||
if (!Hibernate.isInitialized(saleType)) {
|
||||
saleType = saleTypeService.findById(saleType.getId());
|
||||
saleType = projectSaleTypeService.findById(saleType.getId());
|
||||
project.setSaleType(saleType);
|
||||
}
|
||||
if (!StringUtils.hasText(saleType.getPath())) {
|
||||
|
||||
@@ -2,6 +2,10 @@ package com.ecep.contract.ds.project.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.model.CompanyBankAccount;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
@@ -21,7 +25,7 @@ import com.ecep.contract.model.ProjectType;
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "project-type")
|
||||
public class ProjectTypeService implements IEntityService<ProjectType> {
|
||||
public class ProjectTypeService implements IEntityService<ProjectType>, QueryService<ProjectType> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private ProjectTypeRepository projectTypeRepository;
|
||||
@@ -50,6 +54,17 @@ public class ProjectTypeService implements IEntityService<ProjectType> {
|
||||
return projectTypeRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ProjectType> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<ProjectType> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// field
|
||||
// spec = SpecificationUtils.andParam(spec, paramsNode, "company");
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<ProjectType> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
|
||||
@@ -64,6 +64,10 @@ public class CompanyVendorFileService implements IEntityService<CompanyVendorFil
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
// 添加额外的参数过滤
|
||||
if (paramsNode.has("type")) {
|
||||
CompanyVendorFileType type = CompanyVendorFileType.valueOf(paramsNode.get("type").asText());
|
||||
spec = SpecificationUtils.and(spec, (root, query, builder) -> builder.equal(root.get("type"), type));
|
||||
}
|
||||
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "valid");
|
||||
spec = SpecificationUtils.andParam(spec, paramsNode, "vendor");
|
||||
return findAll(spec, pageable);
|
||||
|
||||
@@ -313,8 +313,9 @@ public class CompanyVendorService extends CompanyBasicService implements IEntity
|
||||
* @param verifyDate 检测日期
|
||||
* @param holder 状态输出对象
|
||||
*/
|
||||
private void verify(CompanyVendor companyVendor, LocalDate verifyDate, MessageHolder holder) {
|
||||
public boolean verify(CompanyVendor companyVendor, LocalDate verifyDate, MessageHolder holder) {
|
||||
boolean modified = false;
|
||||
|
||||
if (verifyAsQualifiedVendor(companyVendor, verifyDate, holder)) {
|
||||
modified = true;
|
||||
}
|
||||
@@ -335,6 +336,7 @@ public class CompanyVendorService extends CompanyBasicService implements IEntity
|
||||
if (modified) {
|
||||
companyVendorRepository.save(companyVendor);
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
public File getEvaluationFormTemplate() {
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.ecep.contract.ui.MessageHolderImpl;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -51,7 +52,7 @@ public class VendorVerifyAllTasker extends Tasker<Object> {
|
||||
MessageHolder subHolder = holder.sub(counter.get() + " / " + total + "> #" + vendor.getId() + "> ");
|
||||
|
||||
List<String> meesages = new ArrayList<>();
|
||||
MessageHolderImpl messageHolder = new MessageHolderImpl() {
|
||||
MessageHolderImpl messageHolder = new MessageHolderImpl(this) {
|
||||
@Override
|
||||
public void addMessage(Level level, String message) {
|
||||
if (level.intValue() > Level.INFO.intValue()) {
|
||||
|
||||
@@ -42,14 +42,12 @@ import java.util.concurrent.TimeUnit;
|
||||
* 处理与客户端的WebSocket连接、消息传递和断开连接
|
||||
*/
|
||||
@Component
|
||||
public class WebSocketHandler extends TextWebSocketHandler {
|
||||
public class WebSocketServerHandler extends TextWebSocketHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(WebSocketServerHandler.class);
|
||||
|
||||
private final AuthenticationManager authenticationManager;
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(WebSocketHandler.class);
|
||||
|
||||
@Autowired
|
||||
private EmployeeLoginHistoryService employeeLoginHistoryService;
|
||||
@Autowired
|
||||
@@ -67,7 +65,7 @@ public class WebSocketHandler extends TextWebSocketHandler {
|
||||
private Integer employeeId;
|
||||
private Integer loginHistoryId;
|
||||
private WebSocketSession session;
|
||||
private ScheduledFuture<?> schedule;
|
||||
private ScheduledFuture<?> pingPongScheduledFuture;
|
||||
|
||||
void click() {
|
||||
try {
|
||||
@@ -78,7 +76,7 @@ public class WebSocketHandler extends TextWebSocketHandler {
|
||||
}
|
||||
}
|
||||
|
||||
WebSocketHandler(ObjectMapper objectMapper, AuthenticationManager authenticationManager) {
|
||||
WebSocketServerHandler(ObjectMapper objectMapper, AuthenticationManager authenticationManager) {
|
||||
this.objectMapper = objectMapper;
|
||||
this.authenticationManager = authenticationManager;
|
||||
}
|
||||
@@ -97,7 +95,7 @@ public class WebSocketHandler extends TextWebSocketHandler {
|
||||
if (sessionInfo.getEmployeeId() == null) {
|
||||
logger.error("会话未绑定用户: {}", session.getId());
|
||||
sendError(session, 401, "会话未绑定用户");
|
||||
session.close();
|
||||
session.close(CloseStatus.NOT_ACCEPTABLE);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -111,7 +109,7 @@ public class WebSocketHandler extends TextWebSocketHandler {
|
||||
}
|
||||
|
||||
ScheduledFuture<?> schedule = scheduledExecutorService.schedule(sessionInfo::click, 30, TimeUnit.SECONDS);
|
||||
sessionInfo.setSchedule(schedule);
|
||||
sessionInfo.setPingPongScheduledFuture(schedule);
|
||||
}
|
||||
|
||||
|
||||
@@ -158,6 +156,8 @@ public class WebSocketHandler extends TextWebSocketHandler {
|
||||
logger.warn("解析消息回调JSON失败: {}", payload, e);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (jsonNode.has(WebSocketConstant.MESSAGE_ID_FIELD_NAME)) {
|
||||
// 处理 messageId 的消息
|
||||
String messageId = jsonNode.get(WebSocketConstant.MESSAGE_ID_FIELD_NAME).asText();
|
||||
@@ -195,7 +195,7 @@ public class WebSocketHandler extends TextWebSocketHandler {
|
||||
}
|
||||
|
||||
String methodName = jsonNode.get(WebSocketConstant.METHOD_FIELD_NAME).asText();
|
||||
JsonNode argumentsNode = jsonNode.get("arguments");
|
||||
JsonNode argumentsNode = jsonNode.get(WebSocketConstant.ARGUMENTS_FIELD_NAME);
|
||||
|
||||
Object result = null;
|
||||
if (methodName.equals("findAll")) {
|
||||
@@ -206,27 +206,39 @@ public class WebSocketHandler extends TextWebSocketHandler {
|
||||
result = invokerSaveMethod(service, argumentsNode);
|
||||
} else if (methodName.equals("delete")) {
|
||||
result = invokerDeleteMethod(service, argumentsNode);
|
||||
} else if (methodName.equals("count")) {
|
||||
result = invokerCountMethod(service, argumentsNode);
|
||||
} else {
|
||||
result = invokerOtherMethod(service, methodName, argumentsNode);
|
||||
}
|
||||
|
||||
String response = objectMapper.writeValueAsString(Map.of(
|
||||
WebSocketConstant.MESSAGE_ID_FIELD_NAME, messageId,
|
||||
WebSocketConstant.SUCCESS_FIELD_VALUE, true,
|
||||
"data", result
|
||||
));
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("data", result);
|
||||
map.put(WebSocketConstant.MESSAGE_ID_FIELD_NAME, messageId);
|
||||
map.put(WebSocketConstant.SUCCESS_FIELD_VALUE, true);
|
||||
|
||||
String response = objectMapper.writeValueAsString(map);
|
||||
session.sendMessage(new TextMessage(response));
|
||||
|
||||
}
|
||||
|
||||
|
||||
private Object invokerOtherMethod(Object service, String methodName, JsonNode argumentsNode)
|
||||
throws NoSuchMethodException, SecurityException, InvocationTargetException, IllegalAccessException, ClassNotFoundException, JsonProcessingException {
|
||||
int size = argumentsNode.size();
|
||||
Class<?> targetClass = getTargetClass(service.getClass());
|
||||
if (size == 0) {
|
||||
Method method = service.getClass().getMethod(methodName);
|
||||
Method method = targetClass.getMethod(methodName);
|
||||
return method.invoke(service);
|
||||
}
|
||||
|
||||
if (!argumentsNode.get(0).isArray()) {
|
||||
Class<?> parameterType = Class.forName(argumentsNode.get(1).asText());
|
||||
Object arg = objectMapper.treeToValue(argumentsNode.get(0), parameterType);
|
||||
Method method = targetClass.getMethod(methodName, parameterType);
|
||||
return method.invoke(service, arg);
|
||||
}
|
||||
|
||||
// 参数值
|
||||
JsonNode paramsNode = argumentsNode.get(0);
|
||||
// 参数类型
|
||||
@@ -239,12 +251,12 @@ public class WebSocketHandler extends TextWebSocketHandler {
|
||||
parameterTypes[i] = Class.forName(type);
|
||||
args[i] = objectMapper.treeToValue(paramsNode.get(i), parameterTypes[i]);
|
||||
}
|
||||
Class<?> targetClass = getTargetClass(service.getClass());
|
||||
|
||||
try {
|
||||
Method method = targetClass.getMethod(methodName, parameterTypes);
|
||||
return method.invoke(service, args);
|
||||
} catch (NoSuchMethodException e) {
|
||||
logger.error("targetClass: {}, Methods:{}", targetClass, targetClass.getMethods());
|
||||
logger.error("NoSuchMethodException, targetClass: {}, Methods:{}", targetClass, targetClass.getMethods());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -463,6 +475,14 @@ public class WebSocketHandler extends TextWebSocketHandler {
|
||||
return PageContent.of(page);
|
||||
}
|
||||
|
||||
private Object invokerCountMethod(Object service, JsonNode argumentsNode) {
|
||||
JsonNode paramsNode = argumentsNode.get(0);
|
||||
if (service instanceof QueryService<?> entityService) {
|
||||
return entityService.count(paramsNode);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void sendError(WebSocketSession session, String messageId, String message) {
|
||||
_sendError(session, WebSocketConstant.MESSAGE_ID_FIELD_NAME, messageId, message);
|
||||
}
|
||||
@@ -533,10 +553,10 @@ public class WebSocketHandler extends TextWebSocketHandler {
|
||||
if (sessionInfo == null) {
|
||||
return;
|
||||
}
|
||||
ScheduledFuture<?> schedule = sessionInfo.getSchedule();
|
||||
ScheduledFuture<?> schedule = sessionInfo.getPingPongScheduledFuture();
|
||||
if (schedule != null) {
|
||||
schedule.cancel(true);
|
||||
sessionInfo.setSchedule(null);
|
||||
sessionInfo.setPingPongScheduledFuture(null);
|
||||
}
|
||||
|
||||
Integer loginHistoryId = sessionInfo.getLoginHistoryId();
|
||||
|
||||
@@ -17,8 +17,8 @@ import java.util.Map;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
@Service
|
||||
public class WebSocketTaskManager implements InitializingBean {
|
||||
private static final Logger logger = LoggerFactory.getLogger(WebSocketTaskManager.class);
|
||||
public class WebSocketServerTaskManager implements InitializingBean {
|
||||
private static final Logger logger = LoggerFactory.getLogger(WebSocketServerTaskManager.class);
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
@Autowired
|
||||
@@ -56,10 +56,12 @@ public class WebSocketTaskManager implements InitializingBean {
|
||||
}
|
||||
|
||||
private void createTask(WebSocketSession session, String sessionId, JsonNode jsonNode) {
|
||||
if (!jsonNode.has("taskName")) {
|
||||
throw new IllegalArgumentException("缺失 taskName 参数");
|
||||
if (!jsonNode.has(WebSocketConstant.ARGUMENTS_FIELD_NAME)) {
|
||||
throw new IllegalArgumentException("缺失 " + WebSocketConstant.ARGUMENTS_FIELD_NAME + " 参数");
|
||||
}
|
||||
String taskName = jsonNode.get("taskName").asText();
|
||||
JsonNode argsNode = jsonNode.get(WebSocketConstant.ARGUMENTS_FIELD_NAME);
|
||||
|
||||
String taskName = argsNode.get(0).asText();
|
||||
|
||||
String clzName = taskClzMap.get(taskName);
|
||||
if (clzName == null) {
|
||||
@@ -78,7 +80,10 @@ public class WebSocketTaskManager implements InitializingBean {
|
||||
if (tasker instanceof WebSocketServerTasker t) {
|
||||
t.setTitleHandler(title -> sendToSession(session, sessionId, "title", title));
|
||||
t.setMessageHandler(msg -> sendMessageToSession(session, sessionId, msg));
|
||||
t.init(jsonNode);
|
||||
t.setPropertyHandler((name, value) -> sendToSession(session, sessionId, "property", name, value));
|
||||
t.setProgressHandler((current, total) -> sendToSession(session, sessionId, "progress", current, total));
|
||||
t.init(argsNode);
|
||||
|
||||
scheduledExecutorService.submit(t);
|
||||
}
|
||||
}
|
||||
@@ -92,7 +97,7 @@ public class WebSocketTaskManager implements InitializingBean {
|
||||
String text = objectMapper.writeValueAsString(Map.of(
|
||||
WebSocketConstant.SESSION_ID_FIELD_NAME, sessionId,
|
||||
"type", type,
|
||||
"args", args
|
||||
WebSocketConstant.ARGUMENTS_FIELD_NAME, args
|
||||
));
|
||||
session.sendMessage(new TextMessage(text));
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -4,12 +4,20 @@ import com.ecep.contract.Message;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public interface WebSocketTasker extends Callable<Object> {
|
||||
public interface WebSocketServerTasker extends Callable<Object> {
|
||||
/**
|
||||
* 设置消息处理函数
|
||||
*/
|
||||
void setMessageHandler(Predicate<Message> messageHandler);
|
||||
|
||||
void setTitleHandler(Predicate<String> titleHandler);
|
||||
|
||||
void init(JsonNode jsonNode);
|
||||
void setPropertyHandler(BiConsumer<String, Object> propertyHandler);
|
||||
|
||||
void init(JsonNode argsNode);
|
||||
|
||||
void setProgressHandler(BiConsumer<Long, Long> progressHandler);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.springframework.web.socket.TextMessage;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
|
||||
import com.ecep.contract.handler.MessageNotitfication;
|
||||
import com.ecep.contract.handler.WebSocketHandler;
|
||||
import com.ecep.contract.handler.WebSocketServerHandler;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
/**
|
||||
@@ -21,11 +21,11 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
public class WebSocketService {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(WebSocketService.class.getName());
|
||||
private final WebSocketHandler webSocketHandler;
|
||||
private final WebSocketServerHandler webSocketHandler;
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
public WebSocketService(WebSocketHandler webSocketHandler) {
|
||||
public WebSocketService(WebSocketServerHandler webSocketHandler) {
|
||||
this.webSocketHandler = webSocketHandler;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,21 @@
|
||||
package com.ecep.contract.ui;
|
||||
|
||||
public class MessageHolderImpl {
|
||||
import com.ecep.contract.MessageHolder;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* 错误消息处理
|
||||
*/
|
||||
public class MessageHolderImpl implements MessageHolder {
|
||||
private final Tasker tasker;
|
||||
|
||||
public MessageHolderImpl(Tasker<?> tasker) {
|
||||
this.tasker = tasker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMessage(Level level, String message) {
|
||||
tasker.updateMessage(level, message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ecep.contract.ui;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@@ -26,6 +27,11 @@ public abstract class Tasker<T> implements java.util.concurrent.Callable<T> {
|
||||
@Setter
|
||||
private java.util.function.Predicate<String> titleHandler;
|
||||
@Setter
|
||||
private BiConsumer<String, Object> propertyHandler;
|
||||
@Setter
|
||||
private BiConsumer<Long, Long> progressHandler;
|
||||
@Getter
|
||||
@Setter
|
||||
private Locale locale = Locale.getDefault();
|
||||
private HashMap<Class<?>, Object> cachedMap = new HashMap<>();
|
||||
@Setter
|
||||
@@ -34,6 +40,7 @@ public abstract class Tasker<T> implements java.util.concurrent.Callable<T> {
|
||||
@Getter
|
||||
private boolean cancelled = false;
|
||||
|
||||
|
||||
public SysConfService getConfService() {
|
||||
return getCachedBean(SysConfService.class);
|
||||
}
|
||||
@@ -66,7 +73,7 @@ public abstract class Tasker<T> implements java.util.concurrent.Callable<T> {
|
||||
|
||||
@Override
|
||||
public T call() throws Exception {
|
||||
MessageHolderImpl holder = new MessageHolderImpl();
|
||||
MessageHolderImpl holder = new MessageHolderImpl(this);
|
||||
try {
|
||||
return execute(holder);
|
||||
} catch (Exception e) {
|
||||
@@ -99,23 +106,19 @@ public abstract class Tasker<T> implements java.util.concurrent.Callable<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 错误消息处理
|
||||
*/
|
||||
public class MessageHolderImpl implements MessageHolder {
|
||||
public MessageHolderImpl() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMessage(Level level, String message) {
|
||||
updateMessage(level, message);
|
||||
public void updateProgress(long current, long total) {
|
||||
if (progressHandler != null) {
|
||||
progressHandler.accept(current, total);
|
||||
}
|
||||
}
|
||||
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
public void updateProgress(double current, double total) {
|
||||
updateProgress((long) (current * 1000), (long) (total * 1000));
|
||||
}
|
||||
|
||||
public void updateProgress(double d, double total) {
|
||||
public void updateProperty(String property, Object value) {
|
||||
if (propertyHandler != null) {
|
||||
propertyHandler.accept(property, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.ecep.contract.util;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.ecep.contract.SpringApp;
|
||||
import com.ecep.contract.model.Contract;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class SpecificationUtils {
|
||||
public static <T> Specification<T> and(Specification<T> one, Specification<T> two) {
|
||||
@@ -40,7 +43,7 @@ public class SpecificationUtils {
|
||||
* @return 搜索条件为空时返回null,否则返回一个Specification对象
|
||||
*/
|
||||
public static <T> Specification<T> andWith(String searchText,
|
||||
Function<String, Specification<T>> buildSearchSpecification) {
|
||||
Function<String, Specification<T>> buildSearchSpecification) {
|
||||
Specification<T> spec = null;
|
||||
String[] split = null;
|
||||
do {
|
||||
@@ -60,6 +63,12 @@ public class SpecificationUtils {
|
||||
continue;
|
||||
}
|
||||
JsonNode param = paramsNode.get(field);
|
||||
if (param.isNull()) {
|
||||
spec = SpecificationUtils.and(spec, (root, query, builder) -> {
|
||||
return builder.isNull(root.get(field));
|
||||
});
|
||||
continue;
|
||||
}
|
||||
Integer value = null;
|
||||
if (param.isInt()) {
|
||||
value = param.asInt();
|
||||
@@ -103,4 +112,24 @@ public class SpecificationUtils {
|
||||
}
|
||||
return spec;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static <T, Y extends Comparable<? super Y>> Specification<T> andFieldBetweenParam(Specification<T> spec, JsonNode paramsNode, String field, Class<Y> valyeType) {
|
||||
if (paramsNode.has(field)) {
|
||||
JsonNode param = paramsNode.get(field);
|
||||
if (param.isObject()) {
|
||||
JsonNode beginNode = param.get("begin");
|
||||
JsonNode endNode = param.get("end");
|
||||
|
||||
ObjectMapper objectMapper = SpringApp.getBean(ObjectMapper.class);
|
||||
Y begin = objectMapper.convertValue(beginNode, valyeType);
|
||||
Y end = objectMapper.convertValue(endNode, valyeType);
|
||||
|
||||
spec = SpecificationUtils.and(spec, (root, query, builder) -> {
|
||||
return builder.between(root.get(field), begin, end);
|
||||
});
|
||||
}
|
||||
}
|
||||
return spec;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user