refactor(vo): 重构VO对象结构,统一字段命名和接口实现
重构所有VO对象,统一字段命名规范,移除冗余字段,优化接口实现 新增Voable接口用于VO对象转换 调整BaseViewModel和ProjectBasedViewModel接口定义 更新相关服务和控制器以适应VO对象变更
This commit is contained in:
@@ -4,6 +4,7 @@ import java.beans.PropertyDescriptor;
|
||||
import java.io.File;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -514,7 +515,7 @@ public class OldVersionService {
|
||||
CompanyVendor vendor = new CompanyVendor();
|
||||
vendor.setId(id);
|
||||
vendor.setCompany(updater);
|
||||
vendor.setCreated(Instant.now());
|
||||
vendor.setCreated(LocalDateTime.now());
|
||||
return vendor;
|
||||
});
|
||||
|
||||
@@ -602,7 +603,7 @@ public class OldVersionService {
|
||||
CompanyCustomer customer = new CompanyCustomer();
|
||||
customer.setId(id);
|
||||
customer.setCompany(updater);
|
||||
customer.setCreated(Instant.now());
|
||||
customer.setCreated(LocalDateTime.now());
|
||||
return customer;
|
||||
});
|
||||
if (companyCustomer.getCompany() == null) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ecep.contract.cloud.u8.ctx;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -285,7 +286,7 @@ public class CustomerCtx extends AbstractYongYouU8Ctx {
|
||||
companyCustomer.setId(nextId);
|
||||
companyCustomer.setDevelopDate(developDate);
|
||||
holder.info("新客户:" + entity.getName() + "分配编号:" + nextId);
|
||||
companyCustomer.setCreated(Instant.now());
|
||||
companyCustomer.setCreated(LocalDateTime.now());
|
||||
return companyCustomer;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ecep.contract.cloud.u8.ctx;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -308,7 +309,7 @@ public class VendorCtx extends AbstractYongYouU8Ctx {
|
||||
companyVendor.setCatalog(entity.getCatalog());
|
||||
companyVendor.setDevelopDate(developDate);
|
||||
holder.info("新供应商:" + entity.getName() + "分配编号:" + nextId);
|
||||
companyVendor.setCreated(Instant.now());
|
||||
companyVendor.setCreated(LocalDateTime.now());
|
||||
return companyVendor;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@ import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -25,6 +28,7 @@ public class BankService implements IEntityService<Bank>, QueryService<Bank> {
|
||||
@Autowired
|
||||
private BankRepository bankRepository;
|
||||
|
||||
@Cacheable(key = "#id")
|
||||
public Bank findById(Integer id) {
|
||||
return bankRepository.findById(id).orElse(null);
|
||||
}
|
||||
@@ -71,10 +75,12 @@ public class BankService implements IEntityService<Bank>, QueryService<Bank> {
|
||||
return bankRepository.findFirstByName(name).orElse(null);
|
||||
}
|
||||
|
||||
@Caching(evict = { @CacheEvict(key = "#entity.id") })
|
||||
public Bank save(Bank entity) {
|
||||
return bankRepository.save(entity);
|
||||
}
|
||||
|
||||
@Caching(evict = { @CacheEvict(key = "#entity.id") })
|
||||
public void delete(Bank entity) {
|
||||
bankRepository.delete(entity);
|
||||
}
|
||||
|
||||
@@ -8,11 +8,6 @@ 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;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -27,9 +22,20 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.constant.ProjectConstant;
|
||||
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;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
/**
|
||||
* 项目服务
|
||||
|
||||
@@ -38,7 +38,8 @@ import java.util.stream.Collectors;
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = CompanyVendorConstant.CACHE_NAME)
|
||||
public class CompanyVendorService extends CompanyBasicService implements IEntityService<CompanyVendor>, QueryService<CompanyVendor> {
|
||||
public class CompanyVendorService extends CompanyBasicService
|
||||
implements IEntityService<CompanyVendor>, QueryService<CompanyVendor> {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CompanyVendorService.class);
|
||||
|
||||
@@ -84,26 +85,21 @@ public class CompanyVendorService extends CompanyBasicService implements IEntity
|
||||
return companyVendorRepository.findByCompany(company).orElse(null);
|
||||
}
|
||||
|
||||
@Caching(
|
||||
evict = {
|
||||
@CacheEvict(key = "#p0.id")
|
||||
}
|
||||
)
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "#p0.id")
|
||||
})
|
||||
public CompanyVendor save(CompanyVendor companyVendor) {
|
||||
return companyVendorRepository.save(companyVendor);
|
||||
}
|
||||
|
||||
@Caching(
|
||||
evict = {
|
||||
@CacheEvict(key = "#p0.id")
|
||||
}
|
||||
)
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "#p0.id")
|
||||
})
|
||||
@Override
|
||||
public void delete(CompanyVendor entity) {
|
||||
companyVendorRepository.delete(entity);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Specification<CompanyVendor> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
@@ -169,7 +165,7 @@ public class CompanyVendorService extends CompanyBasicService implements IEntity
|
||||
// 有修改和新导入的文件
|
||||
List<CompanyVendorFile> retrieveFiles = new ArrayList<>();
|
||||
|
||||
//TODO 供应商有曾用名,可能存在多个目录
|
||||
// TODO 供应商有曾用名,可能存在多个目录
|
||||
fetchFiles(companyVendor.getPath(), needMoveToCompanyPath, retrieveFiles, map, status);
|
||||
|
||||
// 移动文件到公司目录下 to company path
|
||||
@@ -177,19 +173,18 @@ public class CompanyVendorService extends CompanyBasicService implements IEntity
|
||||
|
||||
status.accept("导入 " + retrieveFiles.size() + " 个文件");
|
||||
if (!retrieveFiles.isEmpty()) {
|
||||
//update db
|
||||
// update db
|
||||
retrieveFiles.forEach(v -> v.setVendor(companyVendor));
|
||||
companyVendorFileService.saveAll(retrieveFiles);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
|
||||
return modified;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected <T, F extends CompanyBasicFile<T>> boolean fillFileAsDefaultType(F dbFile, File file, Consumer<String> status) {
|
||||
protected <T, F extends CompanyBasicFile<T>> boolean fillFileAsDefaultType(F dbFile, File file,
|
||||
Consumer<String> status) {
|
||||
dbFile.setType((T) VendorFileType.General);
|
||||
fillFile(dbFile, file, null, status);
|
||||
companyVendorFileService.save((CompanyVendorFile) dbFile);
|
||||
@@ -197,7 +192,8 @@ public class CompanyVendorService extends CompanyBasicService implements IEntity
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T, F extends CompanyBasicFile<T>> F fillFileType(File file, List<File> fileList, Consumer<String> status) {
|
||||
protected <T, F extends CompanyBasicFile<T>> F fillFileType(File file, List<File> fileList,
|
||||
Consumer<String> status) {
|
||||
CompanyVendorFile vendorFile = new CompanyVendorFile();
|
||||
vendorFile.setType(VendorFileType.General);
|
||||
vendorFile.setFilePath(file.getAbsolutePath());
|
||||
@@ -216,7 +212,8 @@ public class CompanyVendorService extends CompanyBasicService implements IEntity
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T, F extends CompanyBasicFile<T>> boolean fillFileAsEvaluationFile(F customerFile, File file, List<File> fileList, Consumer<String> status) {
|
||||
protected <T, F extends CompanyBasicFile<T>> boolean fillFileAsEvaluationFile(F customerFile, File file,
|
||||
List<File> fileList, Consumer<String> status) {
|
||||
boolean modified = super.fillFileAsEvaluationFile(customerFile, file, fileList, status);
|
||||
// 当评价表有日期,并且未设审核时
|
||||
boolean valid = isArchiveFile(customerFile.getFilePath()) && customerFile.getSignDate() != null;
|
||||
@@ -233,7 +230,6 @@ public class CompanyVendorService extends CompanyBasicService implements IEntity
|
||||
|| fileName.contains(CompanyVendorConstant.EVALUATION_FORM_NAME3);
|
||||
}
|
||||
|
||||
|
||||
public void verify(CompanyVendor companyVendor, MessageHolder holder) {
|
||||
if (companyVendor.getType() == null) {
|
||||
holder.warn("数据异常,未设置供应商类型");
|
||||
@@ -259,7 +255,8 @@ public class CompanyVendorService extends CompanyBasicService implements IEntity
|
||||
if (entStatus.contains("注销")) {
|
||||
holder.error("营业状态异常:" + entStatus + ", 自动设置为不合格");
|
||||
companyVendor.setType(VendorType.UNQUALIFIED);
|
||||
companyVendor.setDescription(MyStringUtils.appendIfAbsent(companyVendor.getDescription(), "自动检测到营业状态为" + entStatus + ",设置为不合格供应商."));
|
||||
companyVendor.setDescription(MyStringUtils.appendIfAbsent(companyVendor.getDescription(),
|
||||
"自动检测到营业状态为" + entStatus + ",设置为不合格供应商."));
|
||||
modified = true;
|
||||
}
|
||||
} else {
|
||||
@@ -355,7 +352,6 @@ public class CompanyVendorService extends CompanyBasicService implements IEntity
|
||||
return new File(path);
|
||||
}
|
||||
|
||||
|
||||
public boolean makePathAbsent(CompanyVendor companyVendor) {
|
||||
String path = companyVendor.getPath();
|
||||
if (StringUtils.hasText(path)) {
|
||||
@@ -384,7 +380,8 @@ public class CompanyVendorService extends CompanyBasicService implements IEntity
|
||||
}
|
||||
|
||||
String companyName = company.getName();
|
||||
String fileName = CompanyUtils.formatCompanyVendorId(companyVendor.getId()) + "-" + FileUtils.escapeFileName(companyName);
|
||||
String fileName = CompanyUtils.formatCompanyVendorId(companyVendor.getId()) + "-"
|
||||
+ FileUtils.escapeFileName(companyName);
|
||||
|
||||
File dir = new File(basePath, fileName);
|
||||
if (!dir.exists()) {
|
||||
@@ -398,13 +395,13 @@ public class CompanyVendorService extends CompanyBasicService implements IEntity
|
||||
public void resetTo(Company from, Company to) {
|
||||
Optional<CompanyVendor> optional = companyVendorRepository.findByCompany(from);
|
||||
optional.ifPresent(companyVendor -> {
|
||||
companyVendor.setDescription(MyStringUtils.appendIfAbsent(companyVendor.getDescription(), "转自 " + from.getId()));
|
||||
companyVendor
|
||||
.setDescription(MyStringUtils.appendIfAbsent(companyVendor.getDescription(), "转自 " + from.getId()));
|
||||
companyVendor.setCompany(to);
|
||||
companyVendorRepository.save(companyVendor);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void deleteByCompany(Company company) {
|
||||
int deleted = companyVendorRepository.deleteAllByCompany(company);
|
||||
if (deleted > 0) {
|
||||
@@ -428,12 +425,10 @@ public class CompanyVendorService extends CompanyBasicService implements IEntity
|
||||
return vendorClassRepository.findByCode(code).orElse(null);
|
||||
}
|
||||
|
||||
@Caching(
|
||||
evict = {
|
||||
@CacheEvict(key = "'catalog-'+#p0.id"),
|
||||
@CacheEvict(key = "'catalog-code-'+#p0.code")
|
||||
}
|
||||
)
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "'catalog-'+#p0.id"),
|
||||
@CacheEvict(key = "'catalog-code-'+#p0.code")
|
||||
})
|
||||
public VendorCatalog save(VendorCatalog catalog) {
|
||||
return vendorClassRepository.save(catalog);
|
||||
}
|
||||
@@ -446,11 +441,9 @@ public class CompanyVendorService extends CompanyBasicService implements IEntity
|
||||
return list;
|
||||
}
|
||||
|
||||
@Caching(
|
||||
evict = {
|
||||
@CacheEvict(key = "'type-'+#p0.lang"),
|
||||
}
|
||||
)
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "'type-'+#p0.lang"),
|
||||
})
|
||||
public VendorTypeLocal save(VendorTypeLocal type) {
|
||||
return vendorTypeLocalRepository.save(type);
|
||||
}
|
||||
@@ -459,5 +452,4 @@ public class CompanyVendorService extends CompanyBasicService implements IEntity
|
||||
return companyVendorRepository.count(spec);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.ecep.contract.ds.other.service.EmployeeLoginHistoryService;
|
||||
import com.ecep.contract.ds.other.service.EmployeeService;
|
||||
import com.ecep.contract.model.Employee;
|
||||
import com.ecep.contract.model.EmployeeLoginHistory;
|
||||
import com.ecep.contract.model.Voable;
|
||||
import com.ecep.contract.service.WebSocketServerTaskManager;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
@@ -112,7 +113,6 @@ public class WebSocketServerHandler extends TextWebSocketHandler {
|
||||
sessionInfo.setPingPongScheduledFuture(schedule);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 接收文本消息时调用
|
||||
*/
|
||||
@@ -157,7 +157,6 @@ public class WebSocketServerHandler extends TextWebSocketHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (jsonNode.has(WebSocketConstant.MESSAGE_ID_FIELD_NAME)) {
|
||||
// 处理 messageId 的消息
|
||||
String messageId = jsonNode.get(WebSocketConstant.MESSAGE_ID_FIELD_NAME).asText();
|
||||
@@ -176,8 +175,8 @@ public class WebSocketServerHandler extends TextWebSocketHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private void handleAsMessageCallback(WebSocketSession session, String messageId, JsonNode jsonNode) throws Exception {
|
||||
private void handleAsMessageCallback(WebSocketSession session, String messageId, JsonNode jsonNode)
|
||||
throws Exception {
|
||||
if (!jsonNode.has(WebSocketConstant.SERVICE_FIELD_NAME)) {
|
||||
throw new IllegalArgumentException("缺失 service 参数");
|
||||
}
|
||||
@@ -213,7 +212,11 @@ public class WebSocketServerHandler extends TextWebSocketHandler {
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("data", result);
|
||||
if (result instanceof Voable<?>) {
|
||||
map.put("data", ((Voable<?>) result).toVo());
|
||||
} else {
|
||||
map.put("data", result);
|
||||
}
|
||||
map.put(WebSocketConstant.MESSAGE_ID_FIELD_NAME, messageId);
|
||||
map.put(WebSocketConstant.SUCCESS_FIELD_VALUE, true);
|
||||
|
||||
@@ -222,9 +225,9 @@ public class WebSocketServerHandler extends TextWebSocketHandler {
|
||||
|
||||
}
|
||||
|
||||
|
||||
private Object invokerOtherMethod(Object service, String methodName, JsonNode argumentsNode)
|
||||
throws NoSuchMethodException, SecurityException, InvocationTargetException, IllegalAccessException, ClassNotFoundException, JsonProcessingException {
|
||||
throws NoSuchMethodException, SecurityException, InvocationTargetException, IllegalAccessException,
|
||||
ClassNotFoundException, JsonProcessingException {
|
||||
int size = argumentsNode.size();
|
||||
Class<?> targetClass = getTargetClass(service.getClass());
|
||||
if (size == 0) {
|
||||
@@ -261,7 +264,6 @@ public class WebSocketServerHandler extends TextWebSocketHandler {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Object invokerDeleteMethod(Object service, JsonNode argumentsNode) {
|
||||
JsonNode paramsNode = argumentsNode.get(0);
|
||||
if (!paramsNode.has("id")) {
|
||||
@@ -472,7 +474,12 @@ public class WebSocketServerHandler extends TextWebSocketHandler {
|
||||
PageArgument pageArgument = objectMapper.treeToValue(pageableNode, PageArgument.class);
|
||||
QueryService<?> entityService = (QueryService<?>) service;
|
||||
Page<?> page = entityService.findAll(paramsNode, pageArgument.toPageable());
|
||||
return PageContent.of(page);
|
||||
return PageContent.of(page.map(entity -> {
|
||||
if (entity instanceof Voable<?>) {
|
||||
return ((Voable<?>) entity).toVo();
|
||||
}
|
||||
return entity;
|
||||
}));
|
||||
}
|
||||
|
||||
private Object invokerCountMethod(Object service, JsonNode argumentsNode) {
|
||||
@@ -487,7 +494,6 @@ public class WebSocketServerHandler extends TextWebSocketHandler {
|
||||
_sendError(session, WebSocketConstant.MESSAGE_ID_FIELD_NAME, messageId, message);
|
||||
}
|
||||
|
||||
|
||||
private void _sendError(WebSocketSession session, String fieldName, String messageId, String message) {
|
||||
if (session == null || !session.isOpen()) {
|
||||
logger.warn("尝试向已关闭的WebSocket会话发送错误消息: {}", message);
|
||||
@@ -498,8 +504,7 @@ public class WebSocketServerHandler extends TextWebSocketHandler {
|
||||
String errorMessage = objectMapper.writeValueAsString(Map.of(
|
||||
fieldName, messageId,
|
||||
WebSocketConstant.SUCCESS_FIELD_VALUE, false,
|
||||
WebSocketConstant.MESSAGE_FIELD_NAME, message
|
||||
));
|
||||
WebSocketConstant.MESSAGE_FIELD_NAME, message));
|
||||
|
||||
// 检查会话状态并尝试发送错误消息
|
||||
if (session.isOpen()) {
|
||||
|
||||
Reference in New Issue
Block a user