refactor: 重构WebSocket服务及相关实体类
重构WebSocket服务名称从WebSocketService改为WebSocketClientService,并实现Serializable接口 添加WebSocket常量定义和消息处理实现 优化实体类equals和hashCode方法 修复控制器路径和日志配置 添加查询服务和任务接口方法
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user