refactor: 重构供应商文件类型枚举及相关服务

feat: 为多个服务添加缓存支持
fix: 修复WebSocket任务管理和远程调用异常处理
refactor: 重命名CompanyVendorFileType为VendorFileType
refactor: 优化项目成本导入任务实现
fix: 修复ContractTabSkinBase中的空指针问题
refactor: 统一WebSocket客户端任务调用接口
This commit is contained in:
2025-09-17 22:28:17 +08:00
parent 7560250036
commit c0e4916474
43 changed files with 624 additions and 260 deletions

View File

@@ -12,10 +12,10 @@ import com.ecep.contract.MyDateTimeUtils;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import com.ecep.contract.CompanyVendorFileType;
import com.ecep.contract.VendorFileType;
import com.ecep.contract.model.CompanyVendor;
import com.ecep.contract.model.CompanyVendorFile;
import com.ecep.contract.model.CompanyVendorFileTypeLocal;
import com.ecep.contract.model.VendorFileTypeLocal;
import com.ecep.contract.vm.CompanyVendorFileViewModel;
@Service
@@ -30,14 +30,14 @@ public class CompanyVendorFileService extends QueryService<CompanyVendorFile, Co
throw new UnsupportedOperationException("Unimplemented method 'saveAll'");
}
public Map<CompanyVendorFileType, CompanyVendorFileTypeLocal> getFileTypeLocalMap(Locale locale) {
public Map<VendorFileType, VendorFileTypeLocal> getFileTypeLocalMap(Locale locale) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getFileTypeLocalMap'");
}
public void verify(CompanyVendor companyVendor, LocalDate verifyDate, MessageHolder holder) {
// 查询所有评价表
List<CompanyVendorFile> files = findAllByVendorAndType(companyVendor, CompanyVendorFileType.EvaluationForm);
List<CompanyVendorFile> files = findAllByVendorAndType(companyVendor, VendorFileType.EvaluationForm);
if (files == null || files.isEmpty()) {
holder.error("未见供应商评价");
return;
@@ -65,7 +65,7 @@ public class CompanyVendorFileService extends QueryService<CompanyVendorFile, Co
}
}
public List<CompanyVendorFile> findAllByVendorAndType(CompanyVendor vendor, CompanyVendorFileType type) {
public List<CompanyVendorFile> findAllByVendorAndType(CompanyVendor vendor, VendorFileType type) {
return findAll(Map.of("vendor", vendor.getId(), "type", type.name()), Pageable.unpaged()).getContent();
}
}

View File

@@ -1,15 +1,60 @@
package com.ecep.contract.service;
import com.ecep.contract.model.ContractKind;
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.stereotype.Service;
import com.ecep.contract.model.ContractGroup;
import com.ecep.contract.vm.ContractGroupViewModel;
import java.util.List;
@Service
@CacheConfig(cacheNames = "contract-group")
public class ContractGroupService extends QueryService<ContractGroup, ContractGroupViewModel> {
public ContractGroup findByCode(String groupCode) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'findByCode'");
@Override
@Cacheable(key = "#p0")
public ContractGroup findById(Integer id) {
return super.findById(id);
}
public ContractGroup findByCode(String code) {
try {
return async("findByCode", code, String.class).handle((response, ex) -> {
if (ex != null) {
throw new RuntimeException("远程方法+findByCode+调用失败", ex);
}
ContractGroup newEntity = createNewEntity();
return updateValue(newEntity, response);
}).get();
} catch (Exception e) {
throw new RuntimeException("查询实体失败" + code, e);
}
}
@Cacheable(key = "'groups'")
@Override
public List<ContractGroup> findAll() {
return super.findAll();
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"), @CacheEvict(key = "'groups'")
})
@Override
public ContractGroup save(ContractGroup entity) {
return super.save(entity);
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"), @CacheEvict(key = "'groups'")
})
@Override
public void delete(ContractGroup entity) {
super.delete(entity);
}
}

View File

@@ -1,19 +1,73 @@
package com.ecep.contract.service;
import com.ecep.contract.model.ContractType;
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.stereotype.Service;
import com.ecep.contract.model.ContractKind;
import com.ecep.contract.vm.ContractKindViewModel;
import java.util.List;
@Service
@CacheConfig(cacheNames = "contract-kind")
public class ContractKindService extends QueryService<ContractKind, ContractKindViewModel> {
@Cacheable(key = "#p0")
@Override
public ContractKind findById(Integer id) {
return super.findById(id);
}
public ContractKind findByName(String name) {
throw new UnsupportedOperationException("Unimplemented method 'findByName'");
try {
return async("findByName", name, String.class).handle((response, ex) -> {
ContractKind newEntity = createNewEntity();
return updateValue(newEntity, response);
}).get();
} catch (Exception e) {
throw new RuntimeException("查询实体失败" + name, e);
}
}
public ContractKind findByCode(String code) {
throw new UnsupportedOperationException("Unimplemented method 'findByCode'");
try {
return async("findByCode", code, String.class).handle((response, ex) -> {
if (ex != null) {
throw new RuntimeException("远程方法+findByCode+调用失败", ex);
}
ContractKind newEntity = createNewEntity();
return updateValue(newEntity, response);
}).get();
} catch (Exception e) {
throw new RuntimeException("查询实体失败" + code, e);
}
}
@Cacheable(key = "'kinds'")
@Override
public List<ContractKind> findAll() {
return super.findAll();
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"), @CacheEvict(key = "'kinds'"),
})
@Override
public ContractKind save(ContractKind entity) {
return super.save(entity);
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"), @CacheEvict(key = "'kinds'"),
})
@Override
public void delete(ContractKind entity) {
super.delete(entity);
}
}

View File

@@ -75,6 +75,9 @@ public class ContractService extends QueryService<Contract, ContractViewModel> {
public Contract findByCode(String code) {
try {
return async("findByCode", code, String.class).handle((response, ex) -> {
if (ex != null) {
throw new RuntimeException("远程方法+findByCode+调用失败", ex);
}
if (response != null) {
return updateValue(new Contract(), response);
}

View File

@@ -1,20 +1,69 @@
package com.ecep.contract.service;
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.stereotype.Service;
import com.ecep.contract.model.ContractType;
import com.ecep.contract.vm.ContractTypeViewModel;
import java.util.List;
@Service
@CacheConfig(cacheNames = "contract-type")
public class ContractTypeService extends QueryService<ContractType, ContractTypeViewModel> {
@Cacheable(key = "#p0")
@Override
public ContractType findById(Integer id) {
return super.findById(id);
}
public ContractType findByName(String name) {
throw new UnsupportedOperationException("Unimplemented method 'findByName'");
try {
return async("findByName", name, String.class).handle((response, ex) -> {
ContractType newEntity = createNewEntity();
return updateValue(newEntity, response);
}).get();
} catch (Exception e) {
throw new RuntimeException("查询实体失败" + name, e);
}
}
public ContractType findByCode(String typeCode) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'findByCode'");
public ContractType findByCode(String code) {
try {
return async("findByCode", code, String.class).handle((response, ex) -> {
if (ex != null) {
throw new RuntimeException("远程方法+findByCode+调用失败", ex);
}
ContractType newEntity = createNewEntity();
return updateValue(newEntity, response);
}).get();
} catch (Exception e) {
throw new RuntimeException("查询实体失败" + code, e);
}
}
@Cacheable(key = "'types'")
@Override
public List<ContractType> findAll() {
return super.findAll();
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"), @CacheEvict(key = "'types'"),
})
@Override
public void delete(ContractType entity) {
super.delete(entity);
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"), @CacheEvict(key = "'types'"),
})
@Override
public ContractType save(ContractType entity) {
return super.save(entity);
}
}

View File

@@ -5,6 +5,10 @@ import com.ecep.contract.model.Employee;
import com.ecep.contract.model.EmployeeRole;
import com.ecep.contract.vm.EmployeeViewModel;
import com.fasterxml.jackson.databind.JsonNode;
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.stereotype.Service;
import java.util.ArrayList;
@@ -12,15 +16,43 @@ import java.util.List;
import java.util.concurrent.ExecutionException;
@Service
@CacheConfig(cacheNames = "employee")
public class EmployeeService extends QueryService<Employee, EmployeeViewModel> {
public static final int DEFAULT_SYSTEM_EMPLOYEE_ID = 26;
public Employee findByName(String name) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'findByName'");
@Cacheable(key = "#p0")
@Override
public Employee findById(Integer id) {
return super.findById(id);
}
public Employee findByName(String name) {
try {
return async("findByName", name, String.class).handle((response, ex) -> {
Employee newEntity = createNewEntity();
return updateValue(newEntity, response);
}).get();
} catch (Exception e) {
throw new RuntimeException("查询实体失败:" + name, e);
}
}
public Employee findByCode(String code) {
try {
return async("findByCode", code, String.class).handle((response, ex) -> {
if (ex != null) {
throw new RuntimeException("远程方法+findByCode+调用失败", ex);
}
Employee newEntity = createNewEntity();
return updateValue(newEntity, response);
}).get();
} catch (Exception e) {
throw new RuntimeException("查询实体失败:" + code, e);
}
}
public List<EmployeeRole> getRolesByEmployeeId(Integer id) {
try {
return async("getRolesByEmployeeId", List.of(id), List.of(Integer.class)).handle((response, ex) -> {
@@ -44,15 +76,20 @@ public class EmployeeService extends QueryService<Employee, EmployeeViewModel> {
}
}
public void updateActive(int sessionId) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'updateActive'");
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
})
@Override
public Employee save(Employee entity) {
return super.save(entity);
}
public Employee findByCode(String personCode) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'findByCode'");
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
})
@Override
public void delete(Employee entity) {
super.delete(entity);
}
}

View File

@@ -1,16 +1,56 @@
package com.ecep.contract.service;
import com.ecep.contract.model.ContractType;
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.stereotype.Service;
import com.ecep.contract.model.ProductType;
import com.ecep.contract.vm.ProductTypeViewModel;
@Service
public class ProductTypeService extends QueryService<ProductType, ProductTypeViewModel> {
import java.util.List;
public ProductType findByName(String name) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'findByName'");
@Service
@CacheConfig(cacheNames = "product-type")
public class ProductTypeService extends QueryService<ProductType, ProductTypeViewModel> {
@Cacheable(key = "#p0")
@Override
public ProductType findById(Integer id) {
return super.findById(id);
}
public ProductType findByName(String name) {
try {
return async("findByName", name, String.class).handle((response, ex) -> {
ProductType newEntity = createNewEntity();
return updateValue(newEntity, response);
}).get();
} catch (Exception e) {
throw new RuntimeException("查询实体失败" + name, e);
}
}
@Cacheable(key = "'types'")
@Override
public List<ProductType> findAll() {
return super.findAll();
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"), @CacheEvict(key = "'types'"),
})
@Override
public ProductType save(ProductType entity) {
return super.save(entity);
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"), @CacheEvict(key = "'types'"),
})
@Override
public void delete(ProductType entity) {
super.delete(entity);
}
}

View File

@@ -2,6 +2,8 @@ package com.ecep.contract.service;
import java.util.List;
import com.ecep.contract.util.ParamUtils;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.Project;
@@ -12,8 +14,7 @@ import com.ecep.contract.vm.ProjectBidViewModel;
public class ProjectBidService extends QueryService<ProjectBid, ProjectBidViewModel> {
public List<ProjectBid> findAllByProject(Project project) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'findAllByProject'");
return findAll(ParamUtils.builder().equals("project", project.getId()).build(), Pageable.unpaged()).getContent();
}
}

View File

@@ -43,11 +43,6 @@ public class ProjectCostService extends QueryService<ProjectCost, ProjectCostVie
return page.getContent().getFirst();
}
public void updateAutoCost(Project project, MessageHolder holder) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'updateAutoCost'");
}
public List<ProjectCost> findAllByProject(Project project) {
return findAll(ParamUtils.builder().equals("project", project.getId()).build(), Pageable.unpaged()).getContent();
}

View File

@@ -1,13 +1,19 @@
package com.ecep.contract.service;
import com.ecep.contract.SpringApp;
import com.ecep.contract.model.Employee;
import com.ecep.contract.util.ProxyUtils;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.Contract;
import com.ecep.contract.model.Project;
import com.ecep.contract.model.ProjectSaleType;
import com.ecep.contract.vm.ProjectViewModel;
import org.springframework.util.StringUtils;
import java.io.File;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
@Service
@@ -15,11 +21,25 @@ public class ProjectService extends QueryService<Project, ProjectViewModel> {
public Project findByName(String name) {
throw new UnsupportedOperationException();
try {
return async("findByName", name, String.class).handle((response, ex) -> {
Project newEntity = createNewEntity();
return updateValue(newEntity, response);
}).get();
} catch (Exception e) {
throw new RuntimeException("查询实体失败:" + name, e);
}
}
public Project findByCode(String code) {
throw new UnsupportedOperationException();
try {
return async("findByCode", code, String.class).handle((response, ex) -> {
Project newEntity = createNewEntity();
return updateValue(newEntity, response);
}).get();
} catch (Exception e) {
throw new RuntimeException("查询实体失败:" + code, e);
}
}
public void applyCode(Project project, String code) {
@@ -27,13 +47,63 @@ public class ProjectService extends QueryService<Project, ProjectViewModel> {
}
public Project newInstanceByContract(Contract contract) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'newInstanceByContract'");
Project project = new Project();
project.setName(contract.getName());
applyCode(project, contract.getCode());
contract.setCreated(LocalDateTime.now());
LocalDateTime created = contract.getCreated();
if (created != null) {
project.setCreated(created.toLocalDate());
} else {
project.setCreated(LocalDate.now());
}
project.setCustomer(contract.getCompany());
project.setApplicant(contract.getEmployee());
return project;
}
public File searchPath(Project project) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'searchPath'");
ProjectSaleType saleType = project.getSaleType();
if (saleType == null) {
return null;
}
if (!ProxyUtils.isInitialized(saleType)) {
saleType = SpringApp.getBean(ProjectSaleTypeService.class).findById(saleType.getId());
project.setSaleType(saleType);
}
if (!StringUtils.hasText(saleType.getPath())) {
return null;
}
File path = new File(saleType.getPath());
if (saleType.isStoreByYear()) {
path = new File(path, "20" + project.getCodeYear());
if (!path.exists()) {
path.mkdir();// 创建目录
}
}
String projectCode = makeProjectCode(project);
// 检索目录
File[] files = path.listFiles(f -> f.isDirectory() && f.getName().contains(projectCode));
if (files != null && files.length > 0) {
path = files[0];
}
return path;
}
public String makeProjectCode(Project project) {
StringBuilder sb = new StringBuilder();
sb.append(project.getSaleType().getCode());
sb.append(project.getCodeYear());
if (project.getCodeSequenceNumber() < 10) {
sb.append("0");
}
if (project.getCodeSequenceNumber() < 100) {
sb.append("0");
}
sb.append(project.getCodeSequenceNumber());
return sb.toString();
}
public int getNextCodeSequenceNumber(ProjectSaleType newValue, int i) {
@@ -42,7 +112,7 @@ public class ProjectService extends QueryService<Project, ProjectViewModel> {
}
public Project findBySaleTypeAndCodeYearAndCodeSequenceNumber(ProjectSaleType saleType, int codeYear,
int codeSequenceNumber) {
int codeSequenceNumber) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'findBySaleTypeAndCodeYearAndCodeSequenceNumber'");
}

View File

@@ -66,6 +66,9 @@ public class QueryService<T extends IdentityEntity, TV extends IdentityViewModel
public T save(T entity) {
try {
return async("save", entity, entity.getClass().getName()).handle((response, ex) -> {
if (ex != null) {
throw new RuntimeException("保存实体失败", ex);
}
if (response != null) {
try {
objectMapper.updateValue(entity, response);
@@ -84,6 +87,9 @@ public class QueryService<T extends IdentityEntity, TV extends IdentityViewModel
public void delete(T entity) {
try {
async("delete", entity, entity.getClass().getName()).handle((response, ex) -> {
if (ex != null) {
throw new RuntimeException("删除实体失败", ex);
}
if (response != null) {
return updateValue(entity, response);
}
@@ -116,6 +122,9 @@ public class QueryService<T extends IdentityEntity, TV extends IdentityViewModel
public CompletableFuture<T> asyncFindById(Integer id) {
return async("findById", id, Integer.class).handle((response, ex) -> {
if (ex != null) {
throw new RuntimeException("查询实体失败", ex);
}
T newEntity = createNewEntity();
return updateValue(newEntity, response);
});
@@ -145,6 +154,9 @@ public class QueryService<T extends IdentityEntity, TV extends IdentityViewModel
public CompletableFuture<Page<T>> asyncFindAll(Map<String, Object> params, Pageable pageable) {
// 调用async方法发送WebSocket请求获取异步响应结果
return async("findAll", params, PageArgument.of(pageable)).handle((response, ex) -> {
if (ex != null) {
throw new RuntimeException("远程方法+findAll+调用失败", ex);
}
try {
// 将响应结果转换为PageContent对象使用当前类的createNewEntity方法创建实体实例
PageContent<T> pageContent = of(response, objectMapper, this::createNewEntity);
@@ -186,6 +198,9 @@ public class QueryService<T extends IdentityEntity, TV extends IdentityViewModel
// 调用async方法执行名为"count"的异步操作传入参数params
// 使用handle方法处理异步操作的结果或异常
return async("count", params).handle((response, ex) -> {
if (ex != null) {
throw new RuntimeException("远程方法+count+调用失败", ex);
}
// 将响应结果转换为Long类型并返回
return response.asLong();
});

View File

@@ -1,7 +1,7 @@
package com.ecep.contract.service;
import com.ecep.contract.model.CompanyVendorFileTypeLocal;
import com.ecep.contract.vm.CompanyVendorFileTypeLocalViewModel;
import com.ecep.contract.model.VendorFileTypeLocal;
import com.ecep.contract.vm.VendorFileTypeLocalViewModel;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
@@ -12,28 +12,28 @@ import java.util.List;
@Service
@CacheConfig(cacheNames = "vendor-file-type")
public class CompanyVendorFileTypeService extends QueryService<CompanyVendorFileTypeLocal, CompanyVendorFileTypeLocalViewModel> {
public class VendorFileTypeService extends QueryService<VendorFileTypeLocal, VendorFileTypeLocalViewModel> {
@Cacheable(key = "#p0")
@Override
public CompanyVendorFileTypeLocal findById(Integer id) {
public VendorFileTypeLocal findById(Integer id) {
return super.findById(id);
}
@Cacheable(key = "'all'")
@Override
public List<CompanyVendorFileTypeLocal> findAll() {
public List<VendorFileTypeLocal> findAll() {
return super.findAll();
}
@Caching(put = {@CachePut(key = "#p0.id"), @CachePut(key = "'all'")})
@Override
public CompanyVendorFileTypeLocal save(CompanyVendorFileTypeLocal entity) {
public VendorFileTypeLocal save(VendorFileTypeLocal entity) {
return super.save(entity);
}
@Caching(put = {@CachePut(key = "#p0.id"), @CachePut(key = "'all'")})
@Override
public void delete(CompanyVendorFileTypeLocal entity) {
public void delete(VendorFileTypeLocal entity) {
super.delete(entity);
}
}

View File

@@ -23,6 +23,9 @@ public class VendorGroupService extends QueryService<VendorGroup, VendorGroupVie
public VendorGroup findByCode(String code) {
try {
return async("findByCode", code, String.class).handle((response, ex) -> {
if (ex != null) {
throw new RuntimeException("远程方法+findByCode+调用失败", ex);
}
VendorGroup newEntity = newInstance();
return updateValue(newEntity, response);
}).get();

View File

@@ -1,12 +1,39 @@
package com.ecep.contract.service;
import com.ecep.contract.model.CompanyVendorFileTypeLocal;
import com.ecep.contract.vm.CompanyVendorFileTypeLocalViewModel;
import com.ecep.contract.model.VendorTypeLocal;
import com.ecep.contract.vm.VendorTypeLocalViewModel;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.stereotype.Service;
@Service
@CacheConfig(cacheNames = "vendor-file-type")
public class CompanyVendorFileTypeService extends QueryService<CompanyVendorFileTypeLocal, CompanyVendorFileTypeLocalViewModel> {
import java.util.List;
@Service
@CacheConfig(cacheNames = "vendor-type")
public class VendorTypeService extends QueryService<VendorTypeLocal, VendorTypeLocalViewModel> {
@Cacheable(key = "#p0")
@Override
public VendorTypeLocal findById(Integer id) {
return super.findById(id);
}
@Cacheable(key = "'all'")
@Override
public List<VendorTypeLocal> findAll() {
return super.findAll();
}
@Caching(put = {@CachePut(key = "#p0.id"), @CachePut(key = "'all'")})
@Override
public VendorTypeLocal save(VendorTypeLocal entity) {
return super.save(entity);
}
@Caching(put = {@CachePut(key = "#p0.id"), @CachePut(key = "'all'")})
@Override
public void delete(VendorTypeLocal entity) {
super.delete(entity);
}
}