refactor(service): 统一Service缓存为VO对象并优化关联实体处理

重构Service类实现,将QueryService泛型参数调整为VO类型,确保缓存VO对象而非实体。优化关联实体处理逻辑,减少重复代码。修改findById方法返回VO对象,新增getById方法获取实体。更新相关调用点以适配新接口。

调整WebSocket处理、控制器及Service实现,确保数据类型一致性。完善文档记录重构过程及发现的问题。为后续优化提供基础架构支持。
This commit is contained in:
2025-09-29 19:31:51 +08:00
parent 64471b46f8
commit 49413ad473
167 changed files with 6840 additions and 1811 deletions

View File

@@ -2,6 +2,7 @@ package com.ecep.contract;
import java.util.List;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
@@ -10,13 +11,25 @@ import org.springframework.util.StringUtils;
import com.ecep.contract.constant.ServiceConstant;
import com.ecep.contract.ds.MyRepository;
import com.ecep.contract.model.Voable;
import com.ecep.contract.util.SpecificationUtils;
import com.fasterxml.jackson.databind.JsonNode;
public abstract class EntityService<T, ID> {
/**
* 实体服务基类
*
* @param <T> 实体类型
* @param <VO> VO类型
* @param <ID> 主键类型
*/
public abstract class EntityService<T extends Voable<VO>, VO, ID> {
protected abstract MyRepository<T, ID> getRepository();
public T getById(ID id) {
return getRepository().findById(id).orElse(null);
}
public abstract T createNewEntity();
public long count() {
@@ -33,13 +46,13 @@ public abstract class EntityService<T, ID> {
protected abstract Specification<T> buildParameterSpecification(JsonNode paramsNode);
public Page<T> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<VO> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<T> spec = null;
if (paramsNode.has(ServiceConstant.KEY_SEARCH_TEXT)) {
spec = getSpecification(paramsNode.get(ServiceConstant.KEY_SEARCH_TEXT).asText());
}
spec = SpecificationUtils.and(spec, buildParameterSpecification(paramsNode));
return findAll(spec, pageable);
return findAll(spec, pageable).map(T::toVo);
}
public Page<T> findAll(Specification<T> spec, Pageable pageable) {

View File

@@ -7,7 +7,13 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
public interface IEntityService<T> {
T findById(Integer id);
/**
* 根据ID查询实体
* <b> 注意:如果实体类有关联实体此方法不能使用 @Cacheable 注解 </b>
* @param id 实体ID
* @return 实体对象
*/
T getById(Integer id);
Page<T> findAll(Specification<T> spec, Pageable pageable);

View File

@@ -7,9 +7,16 @@ import com.fasterxml.jackson.databind.JsonNode;
/**
* 查询服务接口,提供通用的分页查询能力
* 泛型T表示查询结果的数据类型
* 泛型Vo表示查询结果的数据类型, View Object 类,可序列化,可持久的类
*/
public interface QueryService<T> {
public interface QueryService<Vo> {
/**
* 根据ID查询单条数据
* @param id
* @return 符合ID的Vo对象若不存在则返回null
*/
Vo findById(Integer id);
/**
* 根据查询参数和分页条件获取数据列表
*
@@ -17,12 +24,13 @@ public interface QueryService<T> {
* @param pageable 分页参数,包含页码、每页条数、排序规则等信息
* @return 分页查询结果,包含符合条件的数据列表和分页元数据
*/
Page<T> findAll(JsonNode paramsNode, Pageable pageable);
// Specification<T> getSpecification(String searchText);
// Page<T> findAll(Specification<T> spec, Pageable pageable);
Page<Vo> findAll(JsonNode paramsNode, Pageable pageable);
/**
* 根据查询参数统计符合条件的数据总数
* @param paramsNode JSON格式的查询参数节点包含各种过滤条件
* @return 符合条件的数据总数
*/
default long count(JsonNode paramsNode) {
return 0;
}

View File

@@ -28,6 +28,7 @@ import com.ecep.contract.ds.other.service.EmployeeService;
import com.ecep.contract.model.Employee;
import com.ecep.contract.model.EmployeeAuthBind;
import com.ecep.contract.model.EmployeeLoginHistory;
import com.ecep.contract.vo.EmployeeVo;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
@@ -62,7 +63,7 @@ public class LoginApiController {
Map<String, Object> result = new HashMap<>();
try {
Employee employee = null;
EmployeeVo employee = null;
if ("client".equals(loginRequest.getType())) {
// 根据用户名查找Employee对象
employee = employeeService.findByAccount(loginRequest.getUsername());
@@ -133,12 +134,12 @@ public class LoginApiController {
// 登录成功后,发送系统通知
EmployeeLoginHistoryService employeeLoginHistoryService = getBean(EmployeeLoginHistoryService.class);
EmployeeLoginHistory employeeLoginHistory = new EmployeeLoginHistory();
employeeLoginHistory.setEmployee(employee);
String userId = (String) session.getAttribute("ip");
if (userId == null) {
userId = request.getRemoteAddr();
employeeLoginHistory.setEmployee(employeeService.getById(employee.getId()));
String userIp = (String) session.getAttribute("ip");
if (userIp == null) {
userIp = request.getRemoteAddr();
}
employeeLoginHistory.setIp(userId);
employeeLoginHistory.setIp(userIp);
employeeLoginHistory.setMac((String) session.getAttribute("mac"));
employeeLoginHistory.setLoginTime(LocalDateTime.now());
EmployeeLoginHistory saved = employeeLoginHistoryService.save(employeeLoginHistory);

View File

@@ -107,6 +107,11 @@ public class CloudRkService implements IEntityService<CloudRk>, VoableService<Cl
@Autowired
private CompanyBlackReasonRepository companyBlackReasonRepository;
@Override
public CloudRk getById(Integer id) {
return cloudRKRepository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
public CloudRk findById(Integer id) {
return cloudRKRepository.findById(id).orElse(null);
@@ -384,15 +389,15 @@ public class CloudRkService implements IEntityService<CloudRk>, VoableService<Cl
if (cloudRk == null || vo == null) {
throw new IllegalArgumentException("CloudRk and CloudRkVo cannot be null");
}
// 更新基本属性
if (vo.getCloudId() != null) {
cloudRk.setCloudId(vo.getCloudId());
}
cloudRk.setAutoUpdate(vo.isAutoUpdate());
cloudRk.setUpdateDays(vo.getUpdateDays());
if (vo.getCustomerGrade() != null) {
cloudRk.setCustomerGrade(vo.getCustomerGrade());
}
@@ -432,11 +437,11 @@ public class CloudRkService implements IEntityService<CloudRk>, VoableService<Cl
if (vo.getLatestUpdate() != null) {
cloudRk.setLatestUpdate(vo.getLatestUpdate());
}
// 更新关联的公司
if (vo.getCompanyId() != null) {
CompanyService companyService = SpringApp.getBean(CompanyService.class);
Company company = companyService.findById(vo.getCompanyId());
Company company = companyService.getById(vo.getCompanyId());
if (company != null) {
cloudRk.setCompany(company);
}

View File

@@ -53,6 +53,7 @@ public class CloudRkSyncTask extends Tasker<Object> {
AtomicInteger counter = new AtomicInteger(0);
holder.info("统计需要更新的 " + total + "");
var companyService = getCompanyService();
try {
// 每次获取100条记录
while (!isCancelled()) {
@@ -73,7 +74,7 @@ public class CloudRkSyncTask extends Tasker<Object> {
break;
}
if (!Hibernate.isInitialized(company)) {
company = getCompanyService().findById(company.getId());
company = companyService.getById(company.getId());
cloudRk.setCompany(company);
}
if (cloudRk.isAutoUpdate()) {

View File

@@ -46,6 +46,11 @@ public class CloudTycService implements IEntityService<CloudTyc>, VoableService<
@Autowired
private CloudTycRepository cloudTycRepository;
@Override
public CloudTyc getById(Integer id) {
return cloudTycRepository.findById(id).orElse(null);
}
public CloudTyc getOrCreateCloudTyc(CloudInfo info) {
Optional<CloudTyc> optional = cloudTycRepository.findById(info.getId());
return optional.orElseGet(() -> getOrCreateCloudTyc(info.getCompany()));
@@ -192,7 +197,7 @@ public class CloudTycService implements IEntityService<CloudTyc>, VoableService<
// 更新关联的公司
if (vo.getCompanyId() != null) {
CompanyService companyService = SpringApp.getBean(CompanyService.class);
Company company = companyService.findById(vo.getCompanyId());
Company company = companyService.getById(vo.getCompanyId());
if (company != null) {
cloudTyc.setCompany(company);
}

View File

@@ -12,7 +12,7 @@ import com.ecep.contract.ds.other.service.EmployeeService;
import com.ecep.contract.model.ContractGroup;
import com.ecep.contract.model.ContractKind;
import com.ecep.contract.model.ContractType;
import com.ecep.contract.model.Employee;
import com.ecep.contract.vo.EmployeeVo;
import lombok.Getter;
import lombok.Setter;
@@ -82,10 +82,10 @@ public class ContractSyncContext {
consumer.accept(message);
}
}
public Employee findEmployeeByCode(String personCode) {
public EmployeeVo findEmployeeByCode(String personCode) {
return getEmployeeService().findByCode(personCode);
}
public Employee findEmployeeByName(String personName) {
public EmployeeVo findEmployeeByName(String personName) {
if (personName == null) {
return null;
}

View File

@@ -1,6 +1,5 @@
package com.ecep.contract.cloud.u8;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Map;
@@ -100,7 +99,7 @@ public class CustomerSyncTask extends AbstContractRepairTasker {
return;
}
if (!Hibernate.isInitialized(customer)) {
customer = getCompanyCustomerService().findById(customer.getId());
customer = getCompanyCustomerService().getById(customer.getId());
}
Company company = customer.getCompany();
if (company == null) {
@@ -124,14 +123,14 @@ public class CustomerSyncTask extends AbstContractRepairTasker {
return;
}
if (!Hibernate.isInitialized(customer)) {
customer = getCompanyCustomerService().findById(customer.getId());
customer = getCompanyCustomerService().getById(customer.getId());
}
Company company = customer.getCompany();
if (company == null) {
return;
}
if (!Hibernate.isInitialized(company)) {
company = companyService.findById(company.getId());
company = companyService.getById(company.getId());
}
boolean modified = false;
CompanyCtx companyCtx = customerCtx.getCompanyCtx();

View File

@@ -13,9 +13,11 @@ import org.springframework.util.StringUtils;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.SpringApp;
import com.ecep.contract.ds.other.service.DepartmentService;
import com.ecep.contract.ds.other.service.EmployeeService;
import com.ecep.contract.model.Department;
import com.ecep.contract.model.Employee;
import com.ecep.contract.ui.Tasker;
import com.ecep.contract.vo.EmployeeVo;
/**
* 用友U8系统-同步员工信息
@@ -71,20 +73,21 @@ public class EmployeesSyncTask extends Tasker<Object> {
java.sql.Timestamp personInValidDate = (java.sql.Timestamp) rs.get("dPInValidDate");
boolean modified = false;
Employee employee = getEmployeeService().findByCode(personCode);
EmployeeService employeeService = getEmployeeService();
EmployeeVo employee = employeeService.findByCode(personCode);
// 按员工代码未匹配时,尝试使用名字去匹配
if (employee == null) {
employee = getEmployeeService().findByName(personName);
employee = employeeService.findByName(personName);
if (employee == null) {
employee = new Employee();
employee.setCode(personCode);
employee.setName(personName);
employee.setActive(false);
employee.setCreated(LocalDate.now());
Employee newInstance = new Employee();
newInstance.setCode(personCode);
newInstance.setName(personName);
newInstance.setActive(false);
newInstance.setCreated(LocalDate.now());
holder.info("创建员工:" + personCode + ", 姓名:" + personName + ".");
// consumer.accept("员工编号:" + personCode + ", 姓名:" + personName + ", 本地未创建");
// return;
getEmployeeService().save(newInstance);
employee = newInstance.toVo();
}
employee.setCode(personCode);
modified = true;
@@ -102,8 +105,8 @@ public class EmployeesSyncTask extends Tasker<Object> {
if (departmentByCode == null) {
subHolder.warn("部门代码:" + departmentCode + "未匹配到部门");
} else {
if (!Objects.equals(employee.getDepartment(), departmentByCode)) {
employee.setDepartment(departmentByCode);
if (!Objects.equals(employee.getDepartmentId(), departmentByCode.getId())) {
employee.setDepartmentId(departmentByCode.getId());
subHolder.info("更新部门:" + departmentByCode.getName());
modified = true;
}
@@ -145,7 +148,9 @@ public class EmployeesSyncTask extends Tasker<Object> {
}
if (modified) {
getEmployeeService().save(employee);
var v1 = employeeService.getById(employee.getId());
employeeService.updateByVo(v1, employee);
employeeService.save(v1);
subHolder.info("更新保存");
} else {
subHolder.debug("无更新");

View File

@@ -143,7 +143,7 @@ public class VendorSyncTask extends AbstContractRepairTasker {
return;
}
if (!Hibernate.isInitialized(company)) {
company = companyService.findById(company.getId());
company = companyService.getById(company.getId());
}
boolean modified = false;
CompanyCtx companyCtx = vendorCtx.getCompanyCtx();

View File

@@ -8,6 +8,10 @@ import java.util.stream.Stream;
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;
@@ -21,6 +25,7 @@ import com.ecep.contract.SpringApp;
import com.ecep.contract.cloud.CloudInfo;
import com.ecep.contract.cloud.CloudInfoRepository;
import com.ecep.contract.cloud.u8.ctx.AbstractYongYouU8Ctx;
import com.ecep.contract.constant.ServiceConstant;
import com.ecep.contract.ds.company.service.CompanyService;
import com.ecep.contract.model.CloudYu;
import com.ecep.contract.model.Company;
@@ -30,9 +35,9 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
// @ConditionalOnProperty(name = "cloud.u8.enabled", havingValue = "true")
@CacheConfig(cacheNames = "cloud-yu")
public class YongYouU8Service
implements IEntityService<CloudYu>, QueryService<CloudYu>, VoableService<CloudYu, CloudYuVo> {
implements IEntityService<CloudYu>, QueryService<CloudYuVo>, VoableService<CloudYu, CloudYuVo> {
private static final Logger logger = LoggerFactory.getLogger(YongYouU8Service.class);
public static final String KEY_HOST_IP = "u8.db.server.ip";
@@ -54,7 +59,14 @@ public class YongYouU8Service
}
public CloudYu findById(Integer id) {
@Cacheable(key = "#id")
public CloudYuVo findById(Integer id) {
Optional<CloudYu> optional = cloudYuRepository.findById(id);
return optional.map(CloudYu::toVo).orElse(null);
}
@Override
public CloudYu getById(Integer id) {
return cloudYuRepository.findById(id).orElse(null);
}
@@ -106,13 +118,19 @@ public class YongYouU8Service
* @param cloudYu Cloud Yu 对象
* @return 更新的 Cloud Yu
*/
@Caching(evict = { @CacheEvict(key = "#cloudYu.id") })
@Override
public CloudYu save(CloudYu cloudYu) {
return cloudYuRepository.save(cloudYu);
}
@Caching(evict = { @CacheEvict(key = "#cloudYu.id") })
@Override
public void delete(CloudYu entity) {
cloudYuRepository.delete(entity);
public void delete(CloudYu vo) {
CloudYu entity = cloudYuRepository.findById(vo.getId()).orElse(null);
if (entity != null) {
cloudYuRepository.delete(entity);
}
}
public void deleteByCompany(Company company) {
@@ -137,9 +155,13 @@ public class YongYouU8Service
}
@Override
public Page<CloudYu> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<CloudYuVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<CloudYu> spec = null;
return findAll(spec, pageable);
if (paramsNode.has(ServiceConstant.KEY_SEARCH_TEXT)) {
String searchText = paramsNode.get(ServiceConstant.KEY_SEARCH_TEXT).asText();
spec = getSpecification(searchText);
}
return findAll(spec, pageable).map(CloudYu::toVo);
}
@Override
@@ -225,11 +247,13 @@ public class YongYouU8Service
// 更新关联的公司
if (vo.getCompanyId() != null) {
CompanyService companyService = SpringApp.getBean(CompanyService.class);
Company company = companyService.findById(vo.getCompanyId());
if (company != null) {
if (cloudYu.getCompany() == null || !cloudYu.getCompany().getId().equals(vo.getCompanyId())) {
CompanyService companyService = SpringApp.getBean(CompanyService.class);
Company company = companyService.getById(vo.getCompanyId());
cloudYu.setCompany(company);
}
} else {
cloudYu.setCompany(null);
}
}
}

View File

@@ -12,17 +12,18 @@ import com.ecep.contract.MessageHolder;
import com.ecep.contract.cloud.AbstractCtx;
import com.ecep.contract.cloud.u8.YongYouU8Repository;
import com.ecep.contract.constant.CloudServiceConstant;
import com.ecep.contract.ds.company.service.CompanyService;
import com.ecep.contract.ds.customer.service.CompanyCustomerEntityService;
import com.ecep.contract.ds.customer.service.CompanyCustomerService;
import com.ecep.contract.ds.other.service.EmployeeService;
import com.ecep.contract.ds.vendor.service.VendorEntityService;
import com.ecep.contract.ds.vendor.service.VendorService;
import com.ecep.contract.model.Company;
import com.ecep.contract.model.CompanyCustomer;
import com.ecep.contract.model.CompanyCustomerEntity;
import com.ecep.contract.model.Employee;
import com.ecep.contract.model.Vendor;
import com.ecep.contract.model.VendorEntity;
import com.ecep.contract.model.Employee;
import com.ecep.contract.vo.EmployeeVo;
import lombok.Getter;
import lombok.Setter;
@@ -66,13 +67,23 @@ public class AbstractYongYouU8Ctx extends AbstractCtx {
boolean updateEmployeeByCode(Supplier<Employee> getter, Consumer<Employee> setter, String code,
MessageHolder holder, String topic) {
if (StringUtils.hasText(code)) {
Employee employee = getEmployeeService().findByCode(code);
var employee = getEmployeeService().findByCode(code);
if (employee != null) {
if (!Objects.equals(getter.get(), employee)) {
setter.accept(employee);
holder.info(topic + "更新为 " + employee.getName());
return true;
}
return updateEmployee(getter, setter, employee, holder, topic);
}
}
return false;
}
boolean updateEmployee(Supplier<Employee> getter, Consumer<Employee> setter, EmployeeVo employee,
MessageHolder holder, String topic) {
var service = getEmployeeService();
if (employee != null) {
var v1 = getter.get();
if (v1 == null || !Objects.equals(v1.getId(), employee.getId())) {
setter.accept(service.getById(employee.getId()));
holder.info(topic + "更新为 " + employee.getName());
return true;
}
}
return false;
@@ -81,13 +92,9 @@ public class AbstractYongYouU8Ctx extends AbstractCtx {
boolean updateEmployeeByName(Supplier<Employee> getter, Consumer<Employee> setter, String name,
MessageHolder holder, String topic) {
if (StringUtils.hasText(name)) {
Employee employee = getEmployeeService().findByName(name);
EmployeeVo employee = getEmployeeService().findByName(name);
if (employee != null) {
if (!Objects.equals(getter.get(), employee)) {
setter.accept(employee);
holder.info(topic + "更新为 " + employee.getName());
return true;
}
return updateEmployee(getter, setter, employee, holder, topic);
}
}
return false;
@@ -108,7 +115,7 @@ public class AbstractYongYouU8Ctx extends AbstractCtx {
holder.warn("无效" + topic + "" + customerCode);
} else {
if (!Hibernate.isInitialized(customer)) {
customer = customerService.findById(customer.getId());
customer = customerService.getById(customer.getId());
}
company = customer.getCompany();
}
@@ -122,7 +129,7 @@ public class AbstractYongYouU8Ctx extends AbstractCtx {
if (!Objects.equals(getter.get(), company)) {
setter.accept(company);
if (!Hibernate.isInitialized(company)) {
company = getCompanyService().findById(company.getId());
company = getCompanyService().getById(company.getId());
}
holder.info(topic + "修改为: " + company.getName());
return true;
@@ -160,7 +167,7 @@ public class AbstractYongYouU8Ctx extends AbstractCtx {
if (!Objects.equals(getter.get(), company)) {
setter.accept(company);
if (!Hibernate.isInitialized(company)) {
company = getCompanyService().findById(company.getId());
company = getCompanyService().getById(company.getId());
}
holder.info(topic + "修改为: " + company.getName());
return true;

View File

@@ -35,7 +35,6 @@ public class CompanyCtx extends AbstractYongYouU8Ctx implements CompanyContext {
}
}
public boolean updateCompanyAbbNameIfAbsent(Company company, String abbName, MessageHolder holder) {
if (!StringUtils.hasText(abbName)) {
return false;
@@ -69,7 +68,8 @@ public class CompanyCtx extends AbstractYongYouU8Ctx implements CompanyContext {
return false;
}
public Company findOrCreateByNameOrAbbName(String name, String abbName, LocalDate developDate, MessageHolder holder) {
public Company findOrCreateByNameOrAbbName(String name, String abbName, LocalDate developDate,
MessageHolder holder) {
Company company = getCompanyService().findAndRemoveDuplicateCompanyByNameOrAbbName(name, abbName);
if (company != null) {
return company;
@@ -79,12 +79,12 @@ public class CompanyCtx extends AbstractYongYouU8Ctx implements CompanyContext {
holder.warn("企业库中找不到" + name + "" + abbName + " 的企业");
// 推测个人用户,归入散户
if (name.length() < 4 && !name.contains("公司")) {
company = getCompanyService().findByName("散户");
if (company == null) {
var v1 = getCompanyService().findByName("散户");
if (v1 == null) {
return null;
}
holder.info(name + " 个人用户归集到散户");
return company;
return getCompanyService().getById(v1.getId());
}
// 尝试创建公司

View File

@@ -17,6 +17,8 @@ import com.ecep.contract.model.*;
import com.ecep.contract.util.FileUtils;
import com.ecep.contract.util.NumberUtils;
import com.ecep.contract.util.TaxRateUtils;
import com.ecep.contract.vo.ContractFileTypeLocalVo;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.Hibernate;
@@ -272,7 +274,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
if (contract.getType() != null && contract.getPayWay() != null) {
ContractType type = contract.getType();
if (!Hibernate.isInitialized(type)) {
type = getCachedBean(ContractTypeService.class).findById(type.getId());
type = getCachedBean(ContractTypeService.class).getById(type.getId());
contract.setType(type);
}
if (!type.getDirection().equals(contract.getPayWay().getText())) {
@@ -283,12 +285,12 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
if (contract.getKind() != null && contract.getType() != null) {
ContractKind kind = contract.getKind();
if (!Hibernate.isInitialized(kind)) {
kind = getCachedBean(ContractKindService.class).findById(kind.getId());
kind = getCachedBean(ContractKindService.class).getById(kind.getId());
contract.setKind(kind);
}
ContractType type = contract.getType();
if (!Hibernate.isInitialized(type)) {
type = getCachedBean(ContractTypeService.class).findById(type.getId());
type = getCachedBean(ContractTypeService.class).getById(type.getId());
contract.setType(type);
}
if (!kind.getName().equals(type.getTitle())) {
@@ -375,7 +377,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
return false;
}
if (!Hibernate.isInitialized(company)) {
company = getCompanyService().findById(company.getId());
company = getCompanyService().getById(company.getId());
}
contract.setCompany(company);
holder.info("关联至 " + company.getName());
@@ -440,7 +442,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
}
} else {
if (!Hibernate.isInitialized(customer)) {
customer = customerService.findById(customer.getId());
customer = customerService.getById(customer.getId());
}
if (customer.getCompany() == null) {
customer.setCompany(company);
@@ -536,7 +538,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
holder.warn("* 合同业务员:" + personId + " 未导入");
} else {
if (!Hibernate.isInitialized(employee)) {
employee = getEmployeeService().findById(employee.getId());
employee = getEmployeeService().getById(employee.getId());
}
if (!employee.isActive()) {
holder.warn("业务员 " + employee.getName() + " 已经不可用,其离职日期:" + employee.getLeaveDate());
@@ -783,7 +785,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
String memo = (String) map.get("strMemo");
if (!Hibernate.isInitialized(contract)) {
contract = getContractService().findById(contract.getId());
contract = getContractService().getById(contract.getId());
item.setContract(contract);
}
boolean modified = false;
@@ -943,7 +945,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
ProjectSaleType saleType = project.getSaleType();
if (saleType != null) {
if (!Hibernate.isInitialized(saleType)) {
saleType = getSaleTypeService().findById(saleType.getId());
saleType = getSaleTypeService().getById(saleType.getId());
}
File dir = new File(saleType.getPath());
if (saleType.isStoreByYear()) {
@@ -1170,7 +1172,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
MyDateTimeUtils.pickLocalDate(file.getName()), holder, "生效日期");
}
List<ContractFileTypeLocal> matched = getCachedBean(ContractFileTypeService.class)
List<ContractFileTypeLocalVo> matched = getCachedBean(ContractFileTypeService.class)
.findAll(getLocale()).values().stream()
.filter(local -> {
ContractFileType type = local.getType();
@@ -1209,7 +1211,7 @@ public class ContractCtx extends AbstractYongYouU8Ctx {
contractFile.setType(matched.stream().max((o1, o2) -> maxLength(o1) - maxLength(o2)).get().getType());
}
private int maxLength(ContractFileTypeLocal o1) {
private int maxLength(ContractFileTypeLocalVo o1) {
String suggestFileName = o1.getSuggestFileName();
String value = o1.getValue();
if (!StringUtils.hasText(suggestFileName)) {

View File

@@ -156,7 +156,7 @@ public class CustomerCtx extends AbstractYongYouU8Ctx {
}
if (customer != null) {
if (!Hibernate.isInitialized(customer)) {
customer = getCompanyCustomerService().findById(customer.getId());
customer = getCompanyCustomerService().getById(customer.getId());
}
Company company = customer.getCompany();
if (company != null) {

View File

@@ -257,7 +257,7 @@ public class PurchaseOrderCtx extends AbstractYongYouU8Ctx {
return;
}
if (!Hibernate.isInitialized(contract)) {
contract = getContractService().findById(contract.getId());
contract = getContractService().getById(contract.getId());
}
getCompanyBankAccountCtx().updateBankAccount(contract.getCompany(), bank, bankAccount, holder);
}

View File

@@ -187,7 +187,7 @@ public class SalesBillVoucherCtx extends AbstractYongYouU8Ctx {
Contract contract = order.getContract();
if (!Hibernate.isInitialized(contract)) {
contract = getContractService().findById(contract.getId());
contract = getContractService().getById(contract.getId());
}
voucher.setCompany(contract.getCompany());
voucher.setRefId(sbvid);

View File

@@ -248,7 +248,7 @@ public class VendorCtx extends AbstractYongYouU8Ctx {
return false;
}
if (!Hibernate.isInitialized(company)) {
company = companyService.findById(company.getId());
company = companyService.getById(company.getId());
}
boolean modified = false;
CompanyCtx companyCtx = getCompanyCtx();

View File

@@ -27,6 +27,7 @@ import org.springframework.security.web.SecurityFilterChain;
import com.ecep.contract.ds.other.service.EmployeeService;
import com.ecep.contract.model.Employee;
import com.ecep.contract.model.EmployeeRole;
import com.ecep.contract.vo.EmployeeVo;
/**
* Spring Security配置类
@@ -110,13 +111,16 @@ public class SecurityConfig {
public UserDetailsService userDetailsService() {
return username -> {
// 使用EmployeeService根据用户名查找员工
Employee employee = employeeService.findByAccount(username);
EmployeeVo employeeVo = employeeService.findByAccount(username);
// 如果找不到员工抛出UsernameNotFoundException异常
if (employee == null) {
if (employeeVo == null) {
throw new UsernameNotFoundException("用户不存在: " + username);
}
// 获取员工实体
Employee employee = employeeService.getById(employeeVo.getId());
// 检查员工是否活跃
if (!employee.isActive()) {
throw new UsernameNotFoundException("用户已禁用: " + username);

View File

@@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RestController;
import com.ecep.contract.SpringApp;
import com.ecep.contract.ds.other.service.EmployeeService;
import com.ecep.contract.model.Employee;
import com.ecep.contract.vo.EmployeeVo;
/**
* 基础控制器,处理根路径请求
@@ -31,8 +31,8 @@ public class IndexController {
System.out.println(userDetails.getUsername());
EmployeeService employeeService = SpringApp.getBean(EmployeeService.class);
try {
Employee employee = employeeService.findByAccount(userDetails.getUsername());
return ResponseEntity.ok(employee);
EmployeeVo employeeVo = employeeService.findByAccount(userDetails.getUsername());
return ResponseEntity.ok(employeeVo);
} catch (Exception e) {
e.printStackTrace();
}

View File

@@ -11,7 +11,7 @@ public class CompanyContactStringConverter extends EntityStringConverter<Company
}
public CompanyContactStringConverter(CompanyContactService service) {
setInitialized(employee -> service.findById(employee.getId()));
setInitialized(companyContact -> service.getById(companyContact.getId()));
// setFromString(service::findByName);
}

View File

@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RestController;
import com.ecep.contract.ds.company.service.CompanyService;
import com.ecep.contract.model.Company;
import com.ecep.contract.vo.CompanyVo;
@RestController
@RequestMapping("/company")
@@ -22,7 +23,7 @@ public class CompanyController {
private CompanyService companyService;
@RequestMapping("/findById")
public Company findById(Integer id) {
public CompanyVo findById(Integer id) {
return companyService.findById(id);
}
@@ -44,7 +45,7 @@ public class CompanyController {
@RequestMapping("/delete")
public void delete(Integer id) {
Company company = companyService.findById(id);
Company company = companyService.getById(id);
companyService.delete(company);
}
}

View File

@@ -7,6 +7,7 @@ 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.Cacheable;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
@@ -32,7 +33,7 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "company-bank-account")
public class CompanyBankAccountService implements IEntityService<CompanyBankAccount>, QueryService<CompanyBankAccount>,
public class CompanyBankAccountService implements IEntityService<CompanyBankAccount>, QueryService<CompanyBankAccountVo>,
VoableService<CompanyBankAccount, CompanyBankAccountVo> {
private static final Logger logger = LoggerFactory.getLogger(CompanyBankAccountService.class);
@Lazy
@@ -81,8 +82,14 @@ public class CompanyBankAccountService implements IEntityService<CompanyBankAcco
return repository.findAll(spec, sort);
}
@Cacheable(key = "#p0")
@Override
public CompanyBankAccount findById(Integer id) {
public CompanyBankAccountVo findById(Integer id) {
return repository.findById(id).map(CompanyBankAccount::toVo).orElse(null);
}
@Override
public CompanyBankAccount getById(Integer id) {
return repository.findById(id).orElse(null);
}
@@ -123,14 +130,14 @@ public class CompanyBankAccountService implements IEntityService<CompanyBankAcco
}
@Override
public Page<CompanyBankAccount> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<CompanyBankAccountVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<CompanyBankAccount> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "company");
return findAll(spec, pageable);
return findAll(spec, pageable).map(CompanyBankAccount::toVo);
}
@Override
@@ -149,14 +156,14 @@ public class CompanyBankAccountService implements IEntityService<CompanyBankAcco
// 处理关联关系 - 公司
if (vo.getCompanyId() != null) {
model.setCompany(SpringApp.getBean(CompanyService.class).findById(vo.getCompanyId()));
model.setCompany(SpringApp.getBean(CompanyService.class).getById(vo.getCompanyId()));
} else {
model.setCompany(null);
}
// 处理关联关系 - 银行
if (vo.getBankId() != null) {
model.setBank(SpringApp.getBean(BankService.class).findById(vo.getBankId()));
model.setBank(SpringApp.getBean(BankService.class).getById(vo.getBankId()));
} else {
model.setBank(null);
}

View File

@@ -174,7 +174,7 @@ public abstract class CompanyBasicService {
return;
}
if (!Hibernate.isInitialized(company)) {
company = companyService.findById(company.getId());
company = companyService.getById(company.getId());
}
String companyPath = company.getPath();
if (!StringUtils.hasText(companyPath)) {

View File

@@ -11,6 +11,8 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.util.StringUtils;
import com.ecep.contract.IEntityService;
@@ -26,15 +28,18 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
public class CompanyBlackReasonService implements IEntityService<CompanyBlackReason>, QueryService<CompanyBlackReason>,
@CacheConfig(cacheNames = "company-black-reason")
public class CompanyBlackReasonService
implements IEntityService<CompanyBlackReason>, QueryService<CompanyBlackReasonVo>,
VoableService<CompanyBlackReason, CompanyBlackReasonVo> {
private static final Logger logger = LoggerFactory.getLogger(CompanyContactService.class);
@Autowired
private CompanyBlackReasonRepository repository;
public CompanyBlackReason findById(Integer id) {
return repository.findById(id).orElse(null);
@Cacheable(key = "#p0")
public CompanyBlackReasonVo findById(Integer id) {
return repository.findById(id).map(CompanyBlackReason::toVo).orElse(null);
}
@Override
@@ -55,6 +60,11 @@ public class CompanyBlackReasonService implements IEntityService<CompanyBlackRea
return repository.findAll(spec, pageable);
}
@Override
public CompanyBlackReason getById(Integer id) {
return repository.findById(id).orElse(null);
}
public void delete(CompanyBlackReason entity) {
repository.delete(entity);
}
@@ -72,20 +82,27 @@ public class CompanyBlackReasonService implements IEntityService<CompanyBlackRea
}
@Override
public Page<CompanyBlackReason> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<CompanyBlackReasonVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<CompanyBlackReason> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "company");
return findAll(spec, pageable);
return findAll(spec, pageable).map(CompanyBlackReason::toVo);
}
@Override
public void updateByVo(CompanyBlackReason entity, CompanyBlackReasonVo vo) {
entity.setCompany(SpringApp.getBean(CompanyService.class).findById(vo.getCompanyId()));
if (vo.getCompanyId() == null) {
entity.setCompany(null);
} else {
CompanyService companyService = SpringApp.getBean(CompanyService.class);
if (entity.getCompany() == null || !entity.getCompany().getId().equals(vo.getCompanyId())) {
entity.setCompany(companyService.getById(vo.getCompanyId()));
}
}
// 更新基础字段
entity.setType(vo.getType());
entity.setApplyName(vo.getApplyName());

View File

@@ -18,7 +18,6 @@ import com.ecep.contract.IEntityService;
import com.ecep.contract.QueryService;
import com.ecep.contract.SpringApp;
import com.ecep.contract.ds.company.repository.CompanyContactRepository;
import com.ecep.contract.ds.company.service.CompanyService;
import com.ecep.contract.model.Company;
import com.ecep.contract.model.CompanyContact;
import com.ecep.contract.service.ServiceException;
@@ -34,20 +33,26 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "company-contact")
public class CompanyContactService implements IEntityService<CompanyContact>, QueryService<CompanyContact>,
public class CompanyContactService implements IEntityService<CompanyContact>, QueryService<CompanyContactVo>,
VoableService<CompanyContact, CompanyContactVo> {
private static final Logger logger = LoggerFactory.getLogger(CompanyContactService.class);
@Autowired
private CompanyContactRepository companyContactRepository;
private CompanyContactRepository repository;
@Override
public CompanyContact getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Override
public CompanyContact save(CompanyContact contact) {
return companyContactRepository.save(contact);
return repository.save(contact);
}
public void resetTo(Company from, Company to) {
// 曾用名 关联到 updater
List<CompanyContact> list = companyContactRepository.findAllByCompany(from);
List<CompanyContact> list = repository.findAllByCompany(from);
if (list.isEmpty()) {
return;
}
@@ -55,11 +60,11 @@ public class CompanyContactService implements IEntityService<CompanyContact>, Qu
oldName.setMemo(MyStringUtils.appendIfAbsent(oldName.getMemo(), "转自 " + from.getId()));
oldName.setCompany(to);
}
companyContactRepository.saveAll(list);
repository.saveAll(list);
}
public void deleteByCompany(Company company) {
int deleted = companyContactRepository.deleteAllByCompany(company);
int deleted = repository.deleteAllByCompany(company);
if (deleted > 0) {
if (logger.isInfoEnabled()) {
logger.info("Delete {} records by company:#{}", deleted, company.getId());
@@ -67,16 +72,18 @@ public class CompanyContactService implements IEntityService<CompanyContact>, Qu
}
}
@Override
public void delete(CompanyContact entity) {
companyContactRepository.delete(entity);
repository.delete(entity);
}
public CompanyContact findFirstByCompany(Company company) {
return companyContactRepository.findFirstByCompany(company).orElse(null);
return repository.findFirstByCompany(company).orElse(null);
}
public CompanyContact findById(Integer id) {
return companyContactRepository.findById(id).orElse(null);
@Override
public CompanyContactVo findById(Integer id) {
return repository.findById(id).map(CompanyContact::toVo).orElse(null);
}
@Override
@@ -96,33 +103,33 @@ public class CompanyContactService implements IEntityService<CompanyContact>, Qu
@Override
public Page<CompanyContact> findAll(Specification<CompanyContact> spec, Pageable pageable) {
return companyContactRepository.findAll(spec, pageable);
return repository.findAll(spec, pageable);
}
public List<CompanyContact> searchByCompany(Company company, String userText) {
Specification<CompanyContact> spec = SpecificationUtils.and((root, query, builder) -> {
return builder.equal(root.get("company"), company);
}, getSpecification(userText));
return companyContactRepository.findAll(spec);
return repository.findAll(spec);
}
public List<CompanyContact> findAll(Specification<CompanyContact> spec, Sort sort) {
return companyContactRepository.findAll(spec, sort);
return repository.findAll(spec, sort);
}
public List<CompanyContact> findAllByCompanyAndName(Company company, String contactName) {
return companyContactRepository.findAllByCompanyAndName(company, contactName);
return repository.findAllByCompanyAndName(company, contactName);
}
@Override
public Page<CompanyContact> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<CompanyContactVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<CompanyContact> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "company");
return findAll(spec, pageable);
return findAll(spec, pageable).map(CompanyContact::toVo);
}
@Override
@@ -133,7 +140,7 @@ public class CompanyContactService implements IEntityService<CompanyContact>, Qu
if (vo == null) {
throw new ServiceException("CompanyContactVo cannot be null");
}
// 基本属性映射
model.setName(vo.getName());
model.setPhone(vo.getPhone());
@@ -143,14 +150,14 @@ public class CompanyContactService implements IEntityService<CompanyContact>, Qu
model.setU8Code(vo.getU8Code());
model.setMemo(vo.getMemo());
model.setCreated(vo.getCreated());
// 处理关联关系 - 公司
if (vo.getCompanyId() != null) {
model.setCompany(SpringApp.getBean(CompanyService.class).findById(vo.getCompanyId()));
model.setCompany(SpringApp.getBean(CompanyService.class).getById(vo.getCompanyId()));
} else {
model.setCompany(null);
}
// 注意:
// 1. CompanyContact实体类中没有primary字段所以不需要设置
// 2. CompanyContact实体类中没有active字段所以不需要设置

View File

@@ -17,11 +17,16 @@ 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.ecep.contract.constant.ServiceConstant;
import com.ecep.contract.ds.company.repository.CompanyExtendInfoRepository;
import com.ecep.contract.model.Company;
import com.ecep.contract.model.CompanyExtendInfo;
import com.ecep.contract.service.ServiceException;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.util.SpecificationUtils;
import com.ecep.contract.vo.CompanyExtendInfoVo;
import com.fasterxml.jackson.databind.JsonNode;
/**
@@ -30,14 +35,15 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "company-extend-info")
public class CompanyExtendInfoService implements QueryService<CompanyExtendInfo> {
public class CompanyExtendInfoService implements IEntityService<CompanyExtendInfo>, QueryService<CompanyExtendInfoVo>, VoableService<CompanyExtendInfo, CompanyExtendInfoVo> {
private static final Logger logger = LoggerFactory.getLogger(CompanyExtendInfoService.class);
@Autowired
private CompanyExtendInfoRepository repository;
@Cacheable(key = "#p0")
public CompanyExtendInfo findById(int id) {
return repository.findById(id).orElse(null);
@Override
public CompanyExtendInfoVo findById(Integer id) {
return repository.findById(id).map(CompanyExtendInfo::toVo).orElse(null);
}
public List<CompanyExtendInfo> findAll(Specification<CompanyExtendInfo> spec, Sort sort) {
@@ -61,14 +67,14 @@ public class CompanyExtendInfoService implements QueryService<CompanyExtendInfo>
}
@Override
public Page<CompanyExtendInfo> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<CompanyExtendInfoVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<CompanyExtendInfo> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
if (paramsNode.has(ServiceConstant.KEY_SEARCH_TEXT)) {
spec = getSpecification(paramsNode.get(ServiceConstant.KEY_SEARCH_TEXT).asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "company");
return findAll(spec, pageable);
return findAll(spec, pageable).map(CompanyExtendInfo::toVo);
}
@Caching(evict = {
@@ -83,6 +89,7 @@ public class CompanyExtendInfoService implements QueryService<CompanyExtendInfo>
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'byCompany-'+#p0.company.id")
})
@Override
public CompanyExtendInfo save(CompanyExtendInfo extendInfo) {
return repository.save(extendInfo);
}
@@ -99,4 +106,18 @@ public class CompanyExtendInfoService implements QueryService<CompanyExtendInfo>
return list.getFirst();
}
@Override
public void updateByVo(CompanyExtendInfo model, CompanyExtendInfoVo vo) throws ServiceException {
if (model == null || vo == null) {
throw new ServiceException("Model or VO cannot be null");
}
// 只更新VO中已有的字段
model.setDisableVerify(vo.isDisableVerify());
}
@Override
public CompanyExtendInfo getById(Integer id) {
return repository.findById(id).orElse(null);
}
}

View File

@@ -54,25 +54,32 @@ import com.fasterxml.jackson.databind.JsonNode;
@Service
@CacheConfig(cacheNames = "company-file")
public class CompanyFileService
implements IEntityService<CompanyFile>, QueryService<CompanyFile>, VoableService<CompanyFile, CompanyFileVo> {
implements IEntityService<CompanyFile>, QueryService<CompanyFileVo>, VoableService<CompanyFile, CompanyFileVo> {
private final VendorGroupRepository vendorGroupRepository;
private static final Logger logger = LoggerFactory.getLogger(CompanyFileService.class);
@Lazy
@Autowired
private CompanyFileRepository companyFileRepository;
private CompanyFileRepository repository;
CompanyFileService(VendorGroupRepository vendorGroupRepository) {
this.vendorGroupRepository = vendorGroupRepository;
public CompanyFileService() {
}
public CompanyFile getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
public CompanyFile findById(Integer id) {
return companyFileRepository.findById(id).orElse(null);
@Override
public CompanyFileVo findById(Integer id) {
CompanyFile companyFile = getById(id);
if (companyFile != null) {
return companyFile.toVo();
}
return null;
}
public List<CompanyFile> findFileByCompanyAndType(Company company, CompanyFileType type) {
return companyFileRepository.findByCompanyAndType(company, type);
return repository.findByCompanyAndType(company, type);
}
protected Specification<CompanyFile> buildParameterSpecification(JsonNode paramsNode) {
@@ -201,25 +208,25 @@ public class CompanyFileService
@CacheEvict(key = "#p0.id")
})
public CompanyFile save(CompanyFile companyFile) {
return companyFileRepository.save(companyFile);
return repository.save(companyFile);
}
@Caching(evict = {
@CacheEvict(key = "#p0")
})
public void deleteById(int id) {
companyFileRepository.deleteById(id);
repository.deleteById(id);
}
@Caching(evict = {
@CacheEvict(key = "#p0.id")
})
public void delete(CompanyFile file) {
companyFileRepository.delete(file);
repository.delete(file);
}
public List<CompanyFile> findByCompany(Company company) {
return companyFileRepository.findByCompany(company);
return repository.findByCompany(company);
}
/**
@@ -229,7 +236,7 @@ public class CompanyFileService
* @param status 输出
*/
public boolean reBuildingFiles(Company company, Consumer<String> status) {
List<CompanyFile> dbFiles = companyFileRepository.findByCompany(company);
List<CompanyFile> dbFiles = repository.findByCompany(company);
List<CompanyFile> retrieveFiles = new ArrayList<>();
boolean modfied = false;
@@ -239,7 +246,7 @@ public class CompanyFileService
String filePath = dbFile.getFilePath();
// 没有文件信息,无效记录,删除
if (!StringUtils.hasText(filePath)) {
companyFileRepository.delete(dbFile);
repository.delete(dbFile);
modfied = true;
continue;
}
@@ -247,7 +254,7 @@ public class CompanyFileService
// 目录不存在,删除
File dir = new File(filePath);
if (!dir.exists()) {
companyFileRepository.delete(dbFile);
repository.delete(dbFile);
modfied = true;
continue;
}
@@ -255,7 +262,7 @@ public class CompanyFileService
CompanyFile old = map.put(filePath, dbFile);
// 目录有重复删除
if (old != null) {
companyFileRepository.delete(old);
repository.delete(old);
modfied = true;
}
}
@@ -313,7 +320,7 @@ public class CompanyFileService
// update db
retrieveFiles.forEach(v -> v.setCompany(company));
companyFileRepository.saveAll(retrieveFiles);
repository.saveAll(retrieveFiles);
return true;
}
@@ -429,18 +436,17 @@ public class CompanyFileService
}
@Override
public Page<CompanyFile> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<CompanyFileVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<CompanyFile> spec = null;
if (paramsNode.has(ServiceConstant.KEY_SEARCH_TEXT)) {
spec = getSpecification(paramsNode.get(ServiceConstant.KEY_SEARCH_TEXT).asText());
}
spec = SpecificationUtils.and(spec, buildParameterSpecification(paramsNode));
return findAll(spec, pageable);
return findAll(spec, pageable).map(CompanyFile::toVo);
}
@Override
public Page<CompanyFile> findAll(Specification<CompanyFile> spec, Pageable pageable) {
return companyFileRepository.findAll(spec, pageable);
return repository.findAll(spec, pageable);
}
@Override
@@ -479,7 +485,7 @@ public class CompanyFileService
model.setCompany(null);
} else {
CompanyService companyService = SpringApp.getBean(CompanyService.class);
Company company = companyService.findById(vo.getCompanyId());
Company company = companyService.getById(vo.getCompanyId());
model.setCompany(company);
}

View File

@@ -26,42 +26,53 @@ import org.springframework.util.StringUtils;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
@Lazy
@Service
@CacheConfig(cacheNames = "company-file-type")
public class CompanyFileTypeService
implements IEntityService<CompanyFileTypeLocal>, QueryService<CompanyFileTypeLocal>, VoableService<CompanyFileTypeLocal, CompanyFileTypeLocalVo> {
implements IEntityService<CompanyFileTypeLocal>, QueryService<CompanyFileTypeLocalVo>,
VoableService<CompanyFileTypeLocal, CompanyFileTypeLocalVo> {
@Resource
private CompanyFileTypeLocalRepository repository;
@Cacheable(key = "#p0")
@Override
public CompanyFileTypeLocal findById(Integer id) {
public CompanyFileTypeLocal getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Cacheable(key = "#id")
@Override
public Page<CompanyFileTypeLocal> findAll(JsonNode paramsNode, Pageable pageable) {
public CompanyFileTypeLocalVo findById(Integer id) {
Optional<CompanyFileTypeLocal> optional = repository.findById(id);
return optional.map(CompanyFileTypeLocal::toVo).orElse(null);
}
@Override
public Page<CompanyFileTypeLocalVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<CompanyFileTypeLocal> spec = null;
if (paramsNode.has(ServiceConstant.KEY_SEARCH_TEXT)) {
spec = getSpecification(paramsNode.get(ServiceConstant.KEY_SEARCH_TEXT).asText());
}
if (paramsNode.has("type")) {
spec = SpecificationUtils.and(spec, (root, query, builder) -> builder.equal(root.get("type"), CompanyFileType.valueOf(paramsNode.get("type").asText())));
spec = SpecificationUtils.and(spec, (root, query, builder) -> builder.equal(root.get("type"),
CompanyFileType.valueOf(paramsNode.get("type").asText())));
}
// field
return findAll(spec, pageable);
return findAll(spec, pageable).map(CompanyFileTypeLocal::toVo);
}
@Cacheable(key = "'all-'+#p0.toLanguageTag()")
public Map<CompanyFileType, CompanyFileTypeLocal> findAll(Locale locale) {
return repository.getCompleteMapByLocal(locale.toLanguageTag());
@Cacheable(key = "'all-'+#locale.toLanguageTag()")
public Map<CompanyFileType, CompanyFileTypeLocalVo> findAll(Locale locale) {
return repository.getCompleteMapByLocal(locale.toLanguageTag()).entrySet().stream()
.collect(java.util.stream.Collectors.toMap(
Map.Entry::getKey,
entry -> entry.getValue().toVo()));
}
@Override
public Page<CompanyFileTypeLocal> findAll(Specification<CompanyFileTypeLocal> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
@@ -74,16 +85,16 @@ public class CompanyFileTypeService
}
return (root, query, builder) -> {
return
// builder.or(
builder.like(root.get("type"), "%" + searchText + "%")
// )
;
// builder.or(
builder.like(root.get("type"), "%" + searchText + "%")
// )
;
};
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'all-'+#p0.getLang()")
@CacheEvict(key = "#entity.id"),
@CacheEvict(key = "'all-'+#entity.getLang()")
})
@Override
public void delete(CompanyFileTypeLocal entity) {
@@ -91,8 +102,8 @@ public class CompanyFileTypeService
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'all-'+#p0.getLang()")
@CacheEvict(key = "#entity.id"),
@CacheEvict(key = "'all-'+#entity.getLang()")
})
@Override
public CompanyFileTypeLocal save(CompanyFileTypeLocal entity) {

View File

@@ -6,7 +6,9 @@ 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;
@@ -14,11 +16,15 @@ 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.ecep.contract.ds.company.repository.CompanyInvoiceInfoRepository;
import com.ecep.contract.model.Company;
import com.ecep.contract.model.CompanyInvoiceInfo;
import com.ecep.contract.service.ServiceException;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.util.SpecificationUtils;
import com.ecep.contract.vo.CompanyInvoiceInfoVo;
import com.fasterxml.jackson.databind.JsonNode;
/**
@@ -27,15 +33,16 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "company-invoice-info")
public class CompanyInvoiceInfoService implements QueryService<CompanyInvoiceInfo> {
public class CompanyInvoiceInfoService implements IEntityService<CompanyInvoiceInfo>, QueryService<CompanyInvoiceInfoVo>, VoableService<CompanyInvoiceInfo, CompanyInvoiceInfoVo> {
private static final Logger logger = LoggerFactory.getLogger(CompanyInvoiceInfoService.class);
@Lazy
@Autowired
private CompanyInvoiceInfoRepository repository;
@Cacheable(key = "#p0")
public CompanyInvoiceInfo findById(int id) {
return repository.findById(id).orElse(null);
@Override
public CompanyInvoiceInfoVo findById(Integer id) {
return repository.findById(id).map(CompanyInvoiceInfo::toVo).orElse(null);
}
public List<CompanyInvoiceInfo> searchByCompany(Company company, String searchText) {
@@ -77,13 +84,50 @@ public class CompanyInvoiceInfoService implements QueryService<CompanyInvoiceInf
}
@Override
public Page<CompanyInvoiceInfo> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<CompanyInvoiceInfoVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<CompanyInvoiceInfo> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "company");
return findAll(spec, pageable);
return findAll(spec, pageable).map(CompanyInvoiceInfo::toVo);
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'byCompany-'+#p0.company.id")
})
@Override
public CompanyInvoiceInfo save(CompanyInvoiceInfo model) {
return repository.save(model);
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'byCompany-'+#p0.company.id")
})
public void delete(CompanyInvoiceInfo model) {
repository.delete(model);
}
@Override
public void updateByVo(CompanyInvoiceInfo model, CompanyInvoiceInfoVo vo) throws ServiceException {
if (model == null || vo == null) {
throw new ServiceException("Model or VO cannot be null");
}
// 更新VO中包含的字段
model.setName(vo.getName());
model.setTaxId(vo.getTaxId());
model.setAddress(vo.getAddress());
model.setPhone(vo.getPhone());
model.setBankName(vo.getBankName());
model.setBankAccount(vo.getBankAccount());
}
@Override
public CompanyInvoiceInfo getById(Integer id) {
return repository.findById(id).orElse(null);
}
}

View File

@@ -7,6 +7,8 @@ import java.util.List;
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.Cacheable;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
@@ -25,11 +27,13 @@ import com.ecep.contract.util.FileUtils;
import com.ecep.contract.util.MyStringUtils;
import com.ecep.contract.util.SpecificationUtils;
import com.ecep.contract.vo.CompanyOldNameVo;
import com.ecep.contract.vo.CompanyVo;
import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
public class CompanyOldNameService implements IEntityService<CompanyOldName>, QueryService<CompanyOldName>, VoableService<CompanyOldName, CompanyOldNameVo> {
@CacheConfig(cacheNames = "company-old-name")
public class CompanyOldNameService implements IEntityService<CompanyOldName>, QueryService<CompanyOldNameVo>, VoableService<CompanyOldName, CompanyOldNameVo> {
private static final Logger logger = LoggerFactory.getLogger(CompanyOldNameService.class);
@Lazy
@Autowired
@@ -38,8 +42,9 @@ public class CompanyOldNameService implements IEntityService<CompanyOldName>, Qu
@Autowired
private CompanyService companyService;
public CompanyOldName findById(Integer id) {
return companyOldNameRepository.findById(id).orElse(null);
@Cacheable(key = "#p0")
public CompanyOldNameVo findById(Integer id) {
return companyOldNameRepository.findById(id).map(CompanyOldName::toVo).orElse(null);
}
@Override
@@ -85,7 +90,7 @@ public class CompanyOldNameService implements IEntityService<CompanyOldName>, Qu
public File makePath(CompanyOldName companyOldName) {
String oldName = companyOldName.getName();
File basePath = companyService.getBasePath();
Company company = companyService.findById(companyOldName.getCompanyId());
CompanyVo company = companyService.findById(companyOldName.getCompanyId());
String district = company.getDistrict();
if (StringUtils.hasText(district)) {
String parentPrefix = FileUtils.getParentPrefixByDistrict(district);
@@ -199,7 +204,12 @@ public class CompanyOldNameService implements IEntityService<CompanyOldName>, Qu
}
@Override
public Page<CompanyOldName> findAll(JsonNode paramsNode, Pageable pageable) {
public CompanyOldName getById(Integer id) {
return companyOldNameRepository.findById(id).orElse(null);
}
@Override
public Page<CompanyOldNameVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<CompanyOldName> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
@@ -219,7 +229,7 @@ public class CompanyOldNameService implements IEntityService<CompanyOldName>, Qu
});
}
}
return findAll(spec, pageable);
return findAll(spec, pageable).map(CompanyOldName::toVo);
}
public CompanyOldName createNew(Company company, String name, boolean ambiguity) {

View File

@@ -1,6 +1,34 @@
package com.ecep.contract.ds.company.service;
import com.ecep.contract.*;
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.stream.Collectors;
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.stereotype.Service;
import org.springframework.util.StringUtils;
import com.ecep.contract.EntityService;
import com.ecep.contract.IEntityService;
import com.ecep.contract.MessageHolder;
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;
@@ -14,33 +42,17 @@ import com.ecep.contract.model.Company;
import com.ecep.contract.model.CompanyCustomer;
import com.ecep.contract.model.CompanyOldName;
import com.ecep.contract.model.Vendor;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.util.FileUtils;
import com.ecep.contract.util.MyStringUtils;
import com.ecep.contract.util.SpecificationUtils;
import com.ecep.contract.vo.CompanyVo;
import com.ecep.contract.service.VoableService;
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 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;
/**
* 公司服务
@@ -48,13 +60,13 @@ import java.util.stream.Collectors;
@Lazy
@Service
@CacheConfig(cacheNames = "company")
public class CompanyService extends EntityService<Company, Integer>
implements IEntityService<Company>, QueryService<Company>, VoableService<Company, CompanyVo> {
public class CompanyService extends EntityService<Company, CompanyVo, Integer>
implements IEntityService<Company>, QueryService<CompanyVo>, VoableService<Company, CompanyVo> {
private static final Logger logger = LoggerFactory.getLogger(CompanyService.class);
@Lazy
@Autowired
private CompanyRepository companyRepository;
private CompanyRepository repository;
@Lazy
@Autowired
private SysConfService confService;
@@ -85,7 +97,7 @@ public class CompanyService extends EntityService<Company, Integer>
@Override
protected CompanyRepository getRepository() {
return companyRepository;
return repository;
}
@Override
@@ -97,13 +109,13 @@ public class CompanyService extends EntityService<Company, Integer>
}
@Cacheable(key = "#p0")
public Company findById(Integer id) {
return companyRepository.findById(id).orElse(null);
public CompanyVo findById(Integer id) {
return repository.findById(id).map(Company::toVo).orElse(null);
}
@Cacheable(key = "'name-'+#p0")
public Company findByName(String name) {
return companyRepository.findFirstByName(name).orElse(null);
public CompanyVo findByName(String name) {
return repository.findFirstByName(name).map(Company::toVo).orElse(null);
}
/**
@@ -113,12 +125,15 @@ public class CompanyService extends EntityService<Company, Integer>
* @return 记录列表
*/
public List<Company> findAllByName(String name) {
return companyRepository.findAllByName(name);
return repository.findAllByName(name);
}
@Override
protected Specification<Company> buildParameterSpecification(JsonNode paramsNode) {
return null;
Specification<Company> spec = null;
// field
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "name","uniscid", "abbName");
return spec;
}
/**
@@ -130,7 +145,7 @@ public class CompanyService extends EntityService<Company, Integer>
*/
public Company findAndRemoveDuplicateCompanyByUniscid(String uniscid) {
// 根据统一社会信用代码去查询
List<Company> companies = companyRepository.findAllByUniscid(uniscid);
List<Company> companies = repository.findAllByUniscid(uniscid);
if (companies.isEmpty()) {
return null;
}
@@ -163,7 +178,7 @@ public class CompanyService extends EntityService<Company, Integer>
Company updater = null;
{
// 根据公司全名去查询
List<Company> companies = companyRepository.findAllByName(name);
List<Company> companies = repository.findAllByName(name);
if (companies.isEmpty()) {
if (logger.isDebugEnabled()) {
logger.debug("No record match by {}", name);
@@ -183,7 +198,7 @@ public class CompanyService extends EntityService<Company, Integer>
List<CompanyOldName> oldNames = companyOldNameService.findAllByName(name);
if (!oldNames.isEmpty()) {
CompanyOldName oldName = oldNames.getFirst();
Optional<Company> optional = companyRepository.findById(oldName.getCompanyId());
Optional<Company> optional = repository.findById(oldName.getCompanyId());
if (optional.isPresent()) {
updater = optional.get();
}
@@ -192,7 +207,7 @@ public class CompanyService extends EntityService<Company, Integer>
if (updater == null && StringUtils.hasText(abbName) && !Objects.equals(abbName, name)) {
// 根据公司全面去查询
List<Company> companies = companyRepository.findAllByShortName(abbName);
List<Company> companies = repository.findAllByShortName(abbName);
if (!companies.isEmpty()) {
updater = companies.removeFirst();
}
@@ -205,7 +220,7 @@ public class CompanyService extends EntityService<Company, Integer>
Optional<CompanyOldName> optional1 = oldNames.stream().filter(CompanyOldName::getAmbiguity)
.findFirst();
oldName = optional1.orElseGet(oldNames::getFirst);
Optional<Company> optional = companyRepository.findById(oldName.getCompanyId());
Optional<Company> optional = repository.findById(oldName.getCompanyId());
if (optional.isPresent()) {
updater = optional.get();
}
@@ -291,7 +306,7 @@ public class CompanyService extends EntityService<Company, Integer>
contractService.deleteByCompany(company);
companyContactService.deleteByCompany(company);
companyRepository.delete(company);
repository.delete(company);
if (logger.isInfoEnabled()) {
logger.info("Delete Company {}", company);
}
@@ -324,7 +339,7 @@ public class CompanyService extends EntityService<Company, Integer>
contractService.resetTo(from, to);
companyContactService.resetTo(from, to);
companyRepository.delete(from);
repository.delete(from);
if (logger.isInfoEnabled()) {
logger.info("Merge {} to {}", from, to);
}
@@ -341,7 +356,7 @@ public class CompanyService extends EntityService<Company, Integer>
@CacheEvict(key = "'name-'+#p0.name")
})
public Company save(Company company) {
return companyRepository.save(company);
return repository.save(company);
}
public File getBasePath() {
@@ -493,7 +508,7 @@ public class CompanyService extends EntityService<Company, Integer>
}
public Predicate buildSearchPredicate(String searchText, Path<Company> root, CriteriaQuery<?> query,
CriteriaBuilder builder) {
CriteriaBuilder builder) {
return builder.or(
builder.like(root.get("name"), "%" + searchText + "%"),
builder.like(root.get("shortName"), "%" + searchText + "%"),
@@ -545,4 +560,5 @@ public class CompanyService extends EntityService<Company, Integer>
company.getVersion(), vo.getVersion());
}
}
}

View File

@@ -20,9 +20,8 @@ import com.ecep.contract.IEntityService;
import com.ecep.contract.QueryService;
import com.ecep.contract.SpringApp;
import com.ecep.contract.ds.company.repository.InvoiceRepository;
import com.ecep.contract.ds.company.service.CompanyService;
import com.ecep.contract.model.Company;
import com.ecep.contract.model.Invoice;
import com.ecep.contract.service.ServiceException;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.util.SpecificationUtils;
import com.ecep.contract.vo.InvoiceVo;
@@ -31,18 +30,24 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "invoice")
public class InvoiceService implements IEntityService<Invoice>, QueryService<Invoice>,
public class InvoiceService implements IEntityService<Invoice>, QueryService<InvoiceVo>,
VoableService<Invoice, InvoiceVo> {
private static final Logger logger = LoggerFactory.getLogger(InvoiceService.class);
@Autowired
private InvoiceRepository repository;
@Cacheable(key = "#p0")
public Invoice findById(Integer id) {
@Override
public Invoice getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
@Override
public InvoiceVo findById(Integer id) {
return repository.findById(id).map(Invoice::toVo).orElse(null);
}
@Override
public Specification<Invoice> getSpecification(String searchText) {
if (!StringUtils.hasText(searchText)) {
@@ -63,6 +68,7 @@ public class InvoiceService implements IEntityService<Invoice>, QueryService<Inv
}
@CacheEvict(key = "#p0.id")
@Override
public void delete(Invoice entity) {
repository.delete(entity);
}
@@ -76,12 +82,13 @@ public class InvoiceService implements IEntityService<Invoice>, QueryService<Inv
}
@CacheEvict(key = "#p0.id")
@Override
public Invoice save(Invoice invoice) {
return repository.save(invoice);
}
@Override
public Page<Invoice> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<InvoiceVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<Invoice> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
@@ -89,12 +96,23 @@ public class InvoiceService implements IEntityService<Invoice>, QueryService<Inv
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "company");
return findAll(spec, pageable);
return findAll(spec, pageable).map(Invoice::toVo);
}
@Override
public void updateByVo(Invoice model, InvoiceVo vo) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'updateByVo'");
if (model == null || vo == null) {
throw new IllegalArgumentException("Model or VO cannot be null");
}
model.setCode(vo.getCode());
if (vo.getCompanyId() == null) {
model.setCompany(null);
} else {
Company company = SpringApp.getBean(CompanyService.class).getById(vo.getCompanyId());
model.setCompany(company);
}
model.setInvoiceDate(vo.getInvoiceDate());
model.setDescription(vo.getDescription());
}
}

View File

@@ -22,7 +22,7 @@ public class ContractStringConverter extends EntityStringConverter<Contract> {
@PostConstruct
private void init() {
setInitialized(project -> service.findById(project.getId()));
setInitialized(project -> service.getById(project.getId()));
setSuggestion(service::search);
// TODO 按名称找出,容易出问题
setFromString(service::findByName);

View File

@@ -32,17 +32,26 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "contract-ven-bid")
public class ContractBidVendorService implements IEntityService<ContractBidVendor>, QueryService<ContractBidVendor>, VoableService<ContractBidVendor, ContractBidVendorVo> {
public class ContractBidVendorService implements IEntityService<ContractBidVendor>, QueryService<ContractBidVendorVo>, VoableService<ContractBidVendor, ContractBidVendorVo> {
@Lazy
@Autowired
private ContractBidVendorRepository repository;
@Override
@Cacheable(key = "#p0")
public ContractBidVendor findById(Integer id) {
public ContractBidVendor getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
@Override
public ContractBidVendorVo findById(Integer id) {
ContractBidVendor entity = getById(id);
if (entity != null) {
return entity.toVo();
}
return null;
}
@Override
public Specification<ContractBidVendor> getSpecification(String searchText) {
if (!StringUtils.hasText(searchText)) {
@@ -99,14 +108,14 @@ public class ContractBidVendorService implements IEntityService<ContractBidVendo
}
@Override
public Page<ContractBidVendor> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<ContractBidVendorVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ContractBidVendor> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "contract", "company");
return findAll(spec, pageable);
return findAll(spec, pageable).map(ContractBidVendor::toVo);
}
@Override
@@ -115,19 +124,27 @@ public class ContractBidVendorService implements IEntityService<ContractBidVendo
if (vo.getContractId() == null) {
model.setContract(null);
} else {
model.setContract(SpringApp.getBean(ContractService.class).findById(vo.getContractId()));
ContractService contractService = SpringApp.getBean(ContractService.class);
if (model.getContract() == null || !model.getContract().getId().equals(vo.getContractId())) {
model.setContract(contractService.getById(vo.getContractId()));
}
}
if (vo.getCompanyId() == null) {
model.setCompany(null);
} else {
model.setCompany(SpringApp.getBean(CompanyService.class).findById(vo.getCompanyId()));
CompanyService companyService = SpringApp.getBean(CompanyService.class);
if (model.getCompany() == null || !model.getCompany().getId().equals(vo.getCompanyId())) {
model.setCompany(companyService.getById(vo.getCompanyId()));
}
}
if (vo.getQuotationSheetFileId() == null) {
model.setQuotationSheet(null);
} else {
model.setQuotationSheet(SpringApp.getBean(ContractFileRepository.class).findById(vo.getQuotationSheetFileId()).orElse(null));
if (model.getQuotationSheet() == null || !model.getQuotationSheet().getId().equals(vo.getQuotationSheetFileId())) {
model.setQuotationSheet(SpringApp.getBean(ContractFileRepository.class).findById(vo.getQuotationSheetFileId()).orElse(null));
}
}
}
}

View File

@@ -28,7 +28,7 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "contract-catalog")
public class ContractCatalogService implements IEntityService<ContractCatalog>, QueryService<ContractCatalog>,
public class ContractCatalogService implements IEntityService<ContractCatalog>, QueryService<ContractCatalogVo>,
VoableService<ContractCatalog, ContractCatalogVo> {
@Lazy
@Autowired
@@ -39,7 +39,11 @@ public class ContractCatalogService implements IEntityService<ContractCatalog>,
*/
@Cacheable(key = "#p0")
@Override
public ContractCatalog findById(Integer id) {
public ContractCatalogVo findById(Integer id) {
return repository.findById(id).map(ContractCatalog::toVo).orElse(null);
}
public ContractCatalog getById(Integer id) {
return repository.findById(id).orElse(null);
}
@@ -95,12 +99,12 @@ public class ContractCatalogService implements IEntityService<ContractCatalog>,
}
@Override
public Page<ContractCatalog> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<ContractCatalogVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ContractCatalog> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
}
return findAll(spec, pageable);
return findAll(spec, pageable).map(ContractCatalog::toVo);
}
@Override

View File

@@ -33,7 +33,7 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "contract-file")
public class ContractFileService implements IEntityService<ContractFile>, QueryService<ContractFile>,
public class ContractFileService implements IEntityService<ContractFile>, QueryService<ContractFileVo>,
VoableService<ContractFile, ContractFileVo> {
private static final Logger logger = LoggerFactory.getLogger(ContractFileService.class);
@Lazy
@@ -41,11 +41,16 @@ public class ContractFileService implements IEntityService<ContractFile>, QueryS
private ContractFileRepository contractFileRepository;
@Override
@Cacheable(key = "#p0")
public ContractFile findById(Integer id) {
public ContractFile getById(Integer id) {
return contractFileRepository.findById(id).orElse(null);
}
@Override
@Cacheable(key = "#p0")
public ContractFileVo findById(Integer id) {
return contractFileRepository.findById(id).map(ContractFile::toVo).orElse(null);
}
@Override
public Specification<ContractFile> getSpecification(String searchText) {
if (!StringUtils.hasText(searchText)) {
@@ -64,7 +69,7 @@ public class ContractFileService implements IEntityService<ContractFile>, QueryS
}
@Override
public Page<ContractFile> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<ContractFileVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ContractFile> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
@@ -73,7 +78,7 @@ public class ContractFileService implements IEntityService<ContractFile>, QueryS
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "contract", "type");
return findAll(spec, pageable);
return findAll(spec, pageable).map(ContractFile::toVo);
}
public List<ContractFile> findAll(Specification<ContractFile> spec, Sort by) {
@@ -147,6 +152,7 @@ public class ContractFileService implements IEntityService<ContractFile>, QueryS
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'allbycontract-'+#p0.contract.id")
})
@Override
public ContractFile save(ContractFile contractFile) {
return contractFileRepository.save(contractFile);
}
@@ -177,7 +183,10 @@ public class ContractFileService implements IEntityService<ContractFile>, QueryS
if (vo.getContractId() == null) {
model.setContract(null);
} else {
model.setContract(SpringApp.getBean(ContractService.class).findById(vo.getContractId()));
ContractService contractService = SpringApp.getBean(ContractService.class);
if (model.getContract() == null || !model.getContract().getId().equals(vo.getContractId())) {
model.setContract(contractService.getById(vo.getContractId()));
}
}
model.setType(vo.getType());

View File

@@ -2,6 +2,7 @@ package com.ecep.contract.ds.contract.service;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
@@ -31,14 +32,14 @@ import com.fasterxml.jackson.databind.JsonNode;
@Service
@CacheConfig(cacheNames = "contract-file-type")
public class ContractFileTypeService
implements IEntityService<ContractFileTypeLocal>, QueryService<ContractFileTypeLocal>,
implements IEntityService<ContractFileTypeLocal>, QueryService<ContractFileTypeLocalVo>,
VoableService<ContractFileTypeLocal, ContractFileTypeLocalVo> {
@Lazy
@Autowired
private ContractFileTypeLocalRepository repository;
@Override
public Page<ContractFileTypeLocal> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<ContractFileTypeLocalVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ContractFileTypeLocal> spec = null;
if (paramsNode.has(ServiceConstant.KEY_SEARCH_TEXT)) {
spec = getSpecification(paramsNode.get(ServiceConstant.KEY_SEARCH_TEXT).asText());
@@ -51,17 +52,24 @@ public class ContractFileTypeService
// field
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "lang", "value", "suggestFileName");
return findAll(spec, pageable);
return findAll(spec, pageable).map(ContractFileTypeLocal::toVo);
}
@Cacheable(key = "'all-'+#p0.toLanguageTag()")
public Map<ContractFileType, ContractFileTypeLocal> findAll(Locale locale) {
return repository.getCompleteMapByLocal(locale.toLanguageTag());
public Map<ContractFileType, ContractFileTypeLocalVo> findAll(Locale locale) {
return repository.getCompleteMapByLocal(locale.toLanguageTag()).entrySet().stream()
.collect(java.util.stream.Collectors.toMap(
Map.Entry::getKey,
entry -> entry.getValue().toVo()));
}
@Cacheable(key = "#p0")
@Override
public ContractFileTypeLocal findById(Integer id) {
public ContractFileTypeLocalVo findById(Integer id) {
return repository.findById(id).map(ContractFileTypeLocal::toVo).orElse(null);
}
public ContractFileTypeLocal getById(Integer id) {
return repository.findById(id).orElse(null);
}
@@ -119,7 +127,8 @@ public class ContractFileTypeService
}
@Cacheable(key = "'by-type-'+#p0.name()+'-'+#p1.toLanguageTag()")
public ContractFileTypeLocal findByTypeAndLang(ContractFileType type, Locale locale) {
return repository.findByTypeAndLang(type, locale.toLanguageTag());
public ContractFileTypeLocalVo findByTypeAndLang(ContractFileType type, Locale locale) {
return Optional.ofNullable(repository.findByTypeAndLang(type, locale.toLanguageTag()))
.map(ContractFileTypeLocal::toVo).orElse(null);
}
}

View File

@@ -17,6 +17,7 @@ import org.springframework.stereotype.Service;
import com.ecep.contract.IEntityService;
import com.ecep.contract.QueryService;
import com.ecep.contract.constant.ServiceConstant;
import com.ecep.contract.ds.contract.repository.ContractGroupRepository;
import com.ecep.contract.model.ContractGroup;
import com.ecep.contract.service.VoableService;
@@ -29,7 +30,7 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "contract-group")
public class ContractGroupService implements IEntityService<ContractGroup>, QueryService<ContractGroup>,
public class ContractGroupService implements IEntityService<ContractGroup>, QueryService<ContractGroupVo>,
VoableService<ContractGroup, ContractGroupVo> {
private static final Logger logger = LoggerFactory.getLogger(ContractGroupService.class);
@@ -38,23 +39,28 @@ public class ContractGroupService implements IEntityService<ContractGroup>, Quer
private ContractGroupRepository repository;
@Override
@Cacheable(key = "#p0")
public ContractGroup findById(Integer id) {
public ContractGroup getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Override
@Cacheable(key = "#p0")
public ContractGroupVo findById(Integer id) {
return repository.findById(id).map(ContractGroup::toVo).orElse(null);
}
@Override
public Page<ContractGroup> findAll(Specification<ContractGroup> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
}
@Override
public Page<ContractGroup> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<ContractGroupVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ContractGroup> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
if (paramsNode.has(ServiceConstant.KEY_SEARCH_TEXT)) {
spec = getSpecification(paramsNode.get(ServiceConstant.KEY_SEARCH_TEXT).asText());
}
return findAll(spec, pageable);
return findAll(spec, pageable).map(ContractGroup::toVo);
}
@Override
@@ -86,6 +92,7 @@ public class ContractGroupService implements IEntityService<ContractGroup>, Quer
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'code-'+#p0.code"),
})
@Override
public ContractGroup save(ContractGroup group) {
return repository.save(group);
}

View File

@@ -20,13 +20,13 @@ import org.springframework.util.StringUtils;
import com.ecep.contract.IEntityService;
import com.ecep.contract.QueryService;
import com.ecep.contract.SpringApp;
import com.ecep.contract.constant.ServiceConstant;
import com.ecep.contract.ds.contract.repository.ContractItemRepository;
import com.ecep.contract.ds.other.service.EmployeeService;
import com.ecep.contract.ds.other.service.InventoryService;
import com.ecep.contract.model.Contract;
import com.ecep.contract.model.ContractItem;
import com.ecep.contract.model.Inventory;
import com.ecep.contract.service.ServiceException;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.util.SpecificationUtils;
import com.ecep.contract.vo.ContractItemVo;
@@ -37,7 +37,8 @@ import jakarta.persistence.criteria.Path;
@Lazy
@Service
@CacheConfig(cacheNames = "contract-item")
public class ContractItemService implements IEntityService<ContractItem>, QueryService<ContractItem>, VoableService<ContractItem, ContractItemVo> {
public class ContractItemService implements IEntityService<ContractItem>, QueryService<ContractItemVo>,
VoableService<ContractItem, ContractItemVo> {
private static final Logger logger = LoggerFactory.getLogger(ContractItemService.class);
@Lazy
@@ -45,11 +46,16 @@ public class ContractItemService implements IEntityService<ContractItem>, QueryS
private ContractItemRepository itemRepository;
@Override
@Cacheable(key = "#p0")
public ContractItem findById(Integer id) {
public ContractItem getById(Integer id) {
return itemRepository.findById(id).orElse(null);
}
@Override
@Cacheable(key = "#p0")
public ContractItemVo findById(Integer id) {
return itemRepository.findById(id).map(ContractItem::toVo).orElse(null);
}
@Override
public Specification<ContractItem> getSpecification(String searchText) {
if (!StringUtils.hasText(searchText)) {
@@ -77,16 +83,15 @@ public class ContractItemService implements IEntityService<ContractItem>, QueryS
}
@Override
public Page<ContractItem> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<ContractItemVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ContractItem> spec = null;
// TODO 完成参数处理
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
if (paramsNode.has(ServiceConstant.KEY_SEARCH_TEXT)) {
spec = getSpecification(paramsNode.get(ServiceConstant.KEY_SEARCH_TEXT).asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "contract");
logger.warn("Unsupported paramsNode: {}", paramsNode);
return findAll(spec, pageable);
spec = SpecificationUtils.andParam(spec, paramsNode, "contract", "inventory", "creator", "updater");
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "itemCode", "refId", "title", "specification");
return findAll(spec, pageable).map(ContractItem::toVo);
}
public List<ContractItem> findAllByContract(Contract contract) {
@@ -120,35 +125,48 @@ public class ContractItemService implements IEntityService<ContractItem>, QueryS
model.setStartDate(vo.getStartDate());
model.setEndDate(vo.getEndDate());
model.setRemark(vo.getRemark());
// 处理关联对象
if (vo.getContractId() == null) {
model.setContract(null);
} else {
model.setContract(SpringApp.getBean(ContractService.class).findById(vo.getContractId()));
ContractService contractService = SpringApp.getBean(ContractService.class);
if (model.getContract() == null || !model.getContract().getId().equals(vo.getContractId())) {
model.setContract(contractService.getById(vo.getContractId()));
}
}
if (vo.getInventoryId() == null) {
model.setInventory(null);
} else {
model.setInventory(SpringApp.getBean(InventoryService.class).findById(vo.getInventoryId()));
InventoryService inventoryService = SpringApp.getBean(InventoryService.class);
if (model.getInventory() == null || !model.getInventory().getId().equals(vo.getInventoryId())) {
model.setInventory(inventoryService.getById(vo.getInventoryId()));
}
}
if (vo.getCreatorId() == null) {
model.setCreator(null);
} else {
model.setCreator(SpringApp.getBean(EmployeeService.class).findById(vo.getCreatorId()));
EmployeeService employeeService = SpringApp.getBean(EmployeeService.class);
if (model.getCreator() == null || !model.getCreator().getId().equals(vo.getCreatorId())) {
model.setCreator(employeeService.getById(vo.getCreatorId()));
}
}
if (vo.getUpdaterId() == null) {
model.setUpdater(null);
} else {
model.setUpdater(SpringApp.getBean(EmployeeService.class).findById(vo.getUpdaterId()));
EmployeeService employeeService = SpringApp.getBean(EmployeeService.class);
if (model.getUpdater() == null || !model.getUpdater().getId().equals(vo.getUpdaterId())) {
model.setUpdater(employeeService.getById(vo.getUpdaterId()));
}
}
// 创建日期和更新日期通常由系统自动维护,这里不设置
}
@Override
public ContractItem save(ContractItem item) {
return itemRepository.save(item);
}

View File

@@ -29,7 +29,7 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "contract-kind")
public class ContractKindService implements IEntityService<ContractKind>, QueryService<ContractKind>,
public class ContractKindService implements IEntityService<ContractKind>, QueryService<ContractKindVo>,
VoableService<ContractKind, ContractKindVo> {
private static final Logger logger = LoggerFactory.getLogger(ContractKindService.class);
@@ -39,7 +39,11 @@ public class ContractKindService implements IEntityService<ContractKind>, QueryS
@Override
@Cacheable(key = "'kind-'+#p0")
public ContractKind findById(Integer id) {
public ContractKindVo findById(Integer id) {
return repository.findById(id).map(ContractKind::toVo).orElse(null);
}
public ContractKind getById(Integer id) {
return repository.findById(id).orElse(null);
}
@@ -49,12 +53,12 @@ public class ContractKindService implements IEntityService<ContractKind>, QueryS
}
@Override
public Page<ContractKind> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<ContractKindVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ContractKind> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
}
return findAll(spec, pageable);
return findAll(spec, pageable).map(ContractKind::toVo);
}
@Override

View File

@@ -31,16 +31,21 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "contract-pay-plan")
public class ContractPayPlanService implements IEntityService<ContractPayPlan>, QueryService<ContractPayPlan>,
public class ContractPayPlanService implements IEntityService<ContractPayPlan>, QueryService<ContractPayPlanVo>,
VoableService<ContractPayPlan, ContractPayPlanVo> {
@Lazy
@Autowired
private ContractPayPlanRepository repository;
@Override
public ContractPayPlan getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
@Override
public ContractPayPlan findById(Integer id) {
return repository.findById(id).orElse(null);
public ContractPayPlanVo findById(Integer id) {
return repository.findById(id).map(ContractPayPlan::toVo).orElse(null);
}
@Override
@@ -59,14 +64,14 @@ public class ContractPayPlanService implements IEntityService<ContractPayPlan>,
}
@Override
public Page<ContractPayPlan> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<ContractPayPlanVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ContractPayPlan> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "contract");
return findAll(spec, pageable);
return findAll(spec, pageable).map(ContractPayPlan::toVo);
}
public List<ContractPayPlan> findAllByContract(Contract contract) {
@@ -104,7 +109,7 @@ public class ContractPayPlanService implements IEntityService<ContractPayPlan>,
if (vo.getContractId() == null) {
model.setContract(null);
} else {
model.setContract(SpringApp.getBean(ContractService.class).findById(vo.getContractId()));
model.setContract(SpringApp.getBean(ContractService.class).getById(vo.getContractId()));
}
if (vo.getUpdateDate() != null) {

View File

@@ -54,8 +54,8 @@ import jakarta.persistence.criteria.Predicate;
@Lazy
@Service
@CacheConfig(cacheNames = "contract")
public class ContractService extends EntityService<Contract, Integer>
implements IEntityService<Contract>, QueryService<Contract>, VoableService<Contract, ContractVo> {
public class ContractService extends EntityService<Contract, ContractVo, Integer>
implements IEntityService<Contract>, QueryService<ContractVo>, VoableService<Contract, ContractVo> {
private static final Logger logger = LoggerFactory.getLogger(ContractService.class);
@Lazy
@Autowired
@@ -73,8 +73,8 @@ public class ContractService extends EntityService<Contract, Integer>
}
@Cacheable(key = "#p0")
public Contract findById(Integer id) {
return getRepository().findById(id).orElse(null);
public ContractVo findById(Integer id) {
return getRepository().findById(id).map(Contract::toVo).orElse(null);
}
public Contract findByName(String name) {
@@ -395,30 +395,50 @@ public class ContractService extends EntityService<Contract, Integer>
contract.setExecUnTaxAmount(vo.getExecUnTaxAmount());
contract.setPayWay(vo.getPayWay());
// 处理关联实体 - 公司
if (vo.getCompanyId() == null) {
contract.setCompany(null);
} else {
contract.setCompany(SpringApp.getBean(CompanyService.class).findById(vo.getCompanyId()));
CompanyService companyService = SpringApp.getBean(CompanyService.class);
if (contract.getCompany() == null || !contract.getCompany().getId().equals(vo.getCompanyId())) {
contract.setCompany(companyService.getById(vo.getCompanyId()));
}
}
// 处理关联实体 - 合同组
if (vo.getGroupId() == null) {
contract.setGroup(null);
} else {
contract.setGroup(SpringApp.getBean(ContractGroupService.class).findById(vo.getGroupId()));
ContractGroupService contractGroupService = SpringApp.getBean(ContractGroupService.class);
if (contract.getGroup() == null || !contract.getGroup().getId().equals(vo.getGroupId())) {
contract.setGroup(contractGroupService.getById(vo.getGroupId()));
}
}
// 处理关联实体 - 合同类型
if (vo.getTypeId() == null) {
contract.setType(null);
} else {
contract.setType(SpringApp.getBean(ContractTypeService.class).findById(vo.getTypeId()));
ContractTypeService contractTypeService = SpringApp.getBean(ContractTypeService.class);
if (contract.getType() == null || !contract.getType().getId().equals(vo.getTypeId())) {
contract.setType(contractTypeService.getById(vo.getTypeId()));
}
}
// 处理关联实体 - 合同种类
if (vo.getKindId() == null) {
contract.setKind(null);
} else {
contract.setKind(SpringApp.getBean(ContractKindService.class).findById(vo.getKindId()));
ContractKindService contractKindService = SpringApp.getBean(ContractKindService.class);
if (contract.getKind() == null || !contract.getKind().getId().equals(vo.getKindId())) {
contract.setKind(contractKindService.getById(vo.getKindId()));
}
}
// 处理关联实体 - 项目
if (vo.getProject() == null) {
contract.setProject(null);
} else {
contract.setProject(SpringApp.getBean(ProjectService.class).findById(vo.getProject()));
ProjectService projectService = SpringApp.getBean(ProjectService.class);
if (contract.getProject() == null || !contract.getProject().getId().equals(vo.getProject())) {
contract.setProject(projectService.getById(vo.getProject()));
}
}
contract.setParentCode(vo.getParentCode());
contract.setOrderDate(vo.getOrderDate());
@@ -426,32 +446,47 @@ public class ContractService extends EntityService<Contract, Integer>
contract.setEndDate(vo.getEndDate());
EmployeeService employeeService = SpringApp.getBean(EmployeeService.class);
// 处理关联实体 - 员工
if (vo.getEmployeeId() == null) {
contract.setEmployee(null);
} else {
contract.setEmployee(employeeService.findById(vo.getEmployeeId()));
if (contract.getEmployee() == null || !contract.getEmployee().getId().equals(vo.getEmployeeId())) {
contract.setEmployee(employeeService.getById(vo.getEmployeeId()));
}
}
// 处理关联实体 - 处理人
if (vo.getHandlerId() == null) {
contract.setHandler(null);
} else {
contract.setHandler(employeeService.findById(vo.getHandlerId()));
if (contract.getHandler() == null || !contract.getHandler().getId().equals(vo.getHandlerId())) {
contract.setHandler(employeeService.getById(vo.getHandlerId()));
}
}
// 处理关联实体 - 订立人
if (vo.getSetupPersonId() == null) {
contract.setSetupPerson(null);
} else {
contract.setSetupPerson(employeeService.findById(vo.getSetupPersonId()));
if (contract.getSetupPerson() == null || !contract.getSetupPerson().getId().equals(vo.getSetupPersonId())) {
contract.setSetupPerson(employeeService.getById(vo.getSetupPersonId()));
}
}
contract.setSetupDate(vo.getSetupDate());
// 处理关联实体 - 生效人
if (vo.getInurePersonId() == null) {
contract.setInurePerson(null);
} else {
contract.setInurePerson(employeeService.findById(vo.getInurePersonId()));
if (contract.getInurePerson() == null || !contract.getInurePerson().getId().equals(vo.getInurePersonId())) {
contract.setInurePerson(employeeService.getById(vo.getInurePersonId()));
}
}
contract.setInureDate(vo.getInureDate());
// 处理关联实体 - 变更人
if (vo.getVaryPersonId() == null) {
contract.setVaryPerson(null);
} else {
contract.setVaryPerson(employeeService.findById(vo.getVaryPersonId()));
if (contract.getVaryPerson() == null || !contract.getVaryPerson().getId().equals(vo.getVaryPersonId())) {
contract.setVaryPerson(employeeService.getById(vo.getVaryPersonId()));
}
}
contract.setVaryDate(vo.getVaryDate());
}

View File

@@ -29,7 +29,7 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "contract-type")
public class ContractTypeService implements IEntityService<ContractType>, QueryService<ContractType>,
public class ContractTypeService implements IEntityService<ContractType>, QueryService<ContractTypeVo>,
VoableService<ContractType, ContractTypeVo> {
private static final Logger logger = LoggerFactory.getLogger(ContractTypeService.class);
@@ -38,7 +38,12 @@ public class ContractTypeService implements IEntityService<ContractType>, QueryS
private ContractTypeRepository repository;
@Cacheable(key = "#p0")
public ContractType findById(Integer id) {
@Override
public ContractTypeVo findById(Integer id) {
return repository.findById(id).map(ContractType::toVo).orElse(null);
}
public ContractType getById(Integer id) {
return repository.findById(id).orElse(null);
}
@@ -48,12 +53,12 @@ public class ContractTypeService implements IEntityService<ContractType>, QueryS
}
@Override
public Page<ContractType> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<ContractTypeVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ContractType> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
}
return findAll(spec, pageable);
return findAll(spec, pageable).map(ContractType::toVo);
}
public ContractType findByName(String name) {
@@ -70,6 +75,16 @@ public class ContractTypeService implements IEntityService<ContractType>, QueryS
return repository.findAll();
}
@Override
public Specification<ContractType> getSpecification(String searchText) {
return (root, query, builder) -> {
return builder.or(
builder.like(root.get("code"), "%" + searchText + "%"),
builder.like(root.get("name"), "%" + searchText + "%"),
builder.like(root.get("title"), "%" + searchText + "%"));
};
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'code-'+#p0.code"),
@@ -96,16 +111,6 @@ public class ContractTypeService implements IEntityService<ContractType>, QueryS
repository.delete(type);
}
@Override
public Specification<ContractType> getSpecification(String searchText) {
return (root, query, builder) -> {
return builder.or(
builder.like(root.get("code"), "%" + searchText + "%"),
builder.like(root.get("name"), "%" + searchText + "%"),
builder.like(root.get("title"), "%" + searchText + "%"));
};
}
@Override
public void updateByVo(ContractType model, ContractTypeVo vo) {
// 更新基本属性

View File

@@ -31,7 +31,7 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "contract-ext-ven-info")
public class ExtendVendorInfoService implements IEntityService<ExtendVendorInfo>, QueryService<ExtendVendorInfo>,
public class ExtendVendorInfoService implements IEntityService<ExtendVendorInfo>, QueryService<ExtendVendorInfoVo>,
VoableService<ExtendVendorInfo, ExtendVendorInfoVo> {
@Lazy
@Autowired
@@ -44,11 +44,20 @@ public class ExtendVendorInfoService implements IEntityService<ExtendVendorInfo>
private ContractService contractService;
@Override
@Cacheable(key = "#p0")
public ExtendVendorInfo findById(Integer id) {
public ExtendVendorInfo getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Override
@Cacheable(key = "#p0")
public ExtendVendorInfoVo findById(Integer id) {
ExtendVendorInfo entity = getById(id);
if (entity != null) {
return entity.toVo();
}
return null;
}
@Cacheable(key = "'bycontract-'+#p0.id")
public ExtendVendorInfo findByContract(Contract contract) {
return repository.findByContractId(contract.getId()).orElse(null);
@@ -90,14 +99,14 @@ public class ExtendVendorInfoService implements IEntityService<ExtendVendorInfo>
}
@Override
public Page<ExtendVendorInfo> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<ExtendVendorInfoVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ExtendVendorInfo> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "contract");
return findAll(spec, pageable);
return findAll(spec, pageable).map(ExtendVendorInfo::toVo);
}
public List<ExtendVendorInfo> findAll(Specification<ExtendVendorInfo> spec, Sort sort) {
@@ -138,16 +147,20 @@ public class ExtendVendorInfoService implements IEntityService<ExtendVendorInfo>
entity.setPrePurchase(vo.isPrePurchase());
// 处理关联对象
if (vo.getContractId() != null) {
entity.setContract(contractService.findById(vo.getContractId()));
} else {
if (vo.getContractId() == null) {
entity.setContract(null);
} else {
if (entity.getContract() == null || !entity.getContract().getId().equals(vo.getContractId())) {
entity.setContract(contractService.getById(vo.getContractId()));
}
}
if (vo.getGroupId() != null) {
entity.setGroup(vendorGroupService.findById(vo.getGroupId()));
} else {
if (vo.getGroupId() == null) {
entity.setGroup(null);
} else {
if (entity.getGroup() == null || !entity.getGroup().getId().equals(vo.getGroupId())) {
entity.setGroup(vendorGroupService.getById(vo.getGroupId()));
}
}
}
}

View File

@@ -26,12 +26,17 @@ import com.fasterxml.jackson.databind.JsonNode;
@Service
@CacheConfig(cacheNames = "purchase-bill-voucher-item")
public class PurchaseBillVoucherItemService
implements IEntityService<PurchaseBillVoucherItem>, QueryService<PurchaseBillVoucherItem>,
implements IEntityService<PurchaseBillVoucherItem>, QueryService<PurchaseBillVoucherItem>,
VoableService<PurchaseBillVoucherItem, PurchaseBillVoucherItemVo> {
@Lazy
@Autowired
private PurchaseBillVoucherItemRepository repository;
@Override
public PurchaseBillVoucherItem getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
@Override
public PurchaseBillVoucherItem findById(Integer id) {
@@ -86,11 +91,11 @@ public class PurchaseBillVoucherItemService
public void updateByVo(PurchaseBillVoucherItem model, PurchaseBillVoucherItemVo vo) {
model.setId(vo.getId());
model.setRefId(vo.getRefId());
// 关联实体ID设置
// voucher, orderItem, invoice, inventory, contract等实体需要在service层进行设置
// 这里只设置基本属性,关联实体的设置需要在调用此方法的地方处理
model.setQuantity(vo.getQuantity());
model.setPrice(vo.getPrice());
model.setDescription(vo.getDescription());

View File

@@ -45,6 +45,11 @@ public class PurchaseBillVoucherService
@Autowired
private PurchaseBillVoucherRepository repository;
@Override
public PurchaseBillVoucher getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Override
@Cacheable(key = "#p0")
public PurchaseBillVoucher findById(Integer id) {
@@ -149,32 +154,32 @@ public class PurchaseBillVoucherService
if (vo.getInvoiceId() == null) {
model.setInvoice(null);
} else {
model.setInvoice(SpringApp.getBean(InvoiceService.class).findById(vo.getInvoiceId()));
model.setInvoice(SpringApp.getBean(InvoiceService.class).getById(vo.getInvoiceId()));
}
if (vo.getCompanyId() == null) {
model.setCompany(null);
} else {
model.setCompany(SpringApp.getBean(CompanyService.class).findById(vo.getCompanyId()));
model.setCompany(SpringApp.getBean(CompanyService.class).getById(vo.getCompanyId()));
}
EmployeeService employeeService = SpringApp.getBean(EmployeeService.class);
if (vo.getEmployeeId() == null) {
model.setEmployee(null);
} else {
model.setEmployee(employeeService.findById(vo.getEmployeeId()));
model.setEmployee(employeeService.getById(vo.getEmployeeId()));
}
if (vo.getMakerId() == null) {
model.setMaker(null);
} else {
model.setMaker(employeeService.findById(vo.getMakerId()));
model.setMaker(employeeService.getById(vo.getMakerId()));
}
if (vo.getVerifierId() == null) {
model.setVerifier(null);
} else {
model.setVerifier(employeeService.findById(vo.getVerifierId()));
model.setVerifier(employeeService.getById(vo.getVerifierId()));
}
}
}

View File

@@ -32,17 +32,22 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "contract-purchase-order-item")
public class PurchaseOrderItemService implements IEntityService<PurchaseOrderItem>, QueryService<PurchaseOrderItem>,
public class PurchaseOrderItemService implements IEntityService<PurchaseOrderItem>, QueryService<PurchaseOrderItemVo>,
VoableService<PurchaseOrderItem, PurchaseOrderItemVo> {
private static final Logger logger = LoggerFactory.getLogger(PurchaseOrderItemService.class);
@Lazy
@Autowired
private PurchaseOrderItemRepository repository;
@Override
public PurchaseOrderItem getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
@Override
public PurchaseOrderItem findById(Integer id) {
return repository.findById(id).orElse(null);
public PurchaseOrderItemVo findById(Integer id) {
return repository.findById(id).map(PurchaseOrderItem::toVo).orElse(null);
}
@Cacheable(key = "'refId-'+#p0")
@@ -77,14 +82,14 @@ public class PurchaseOrderItemService implements IEntityService<PurchaseOrderIte
}
@Override
public Page<PurchaseOrderItem> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<PurchaseOrderItemVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<PurchaseOrderItem> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "order", "inventory");
return findAll(spec, pageable);
return findAll(spec, pageable).map(PurchaseOrderItem::toVo);
}
@Caching(evict = {
@@ -128,13 +133,13 @@ public class PurchaseOrderItemService implements IEntityService<PurchaseOrderIte
if (vo.getOrder() == null) {
model.setOrder(null);
} else {
model.setOrder(SpringApp.getBean(PurchaseOrdersService.class).findById(vo.getOrder()));
model.setOrder(SpringApp.getBean(PurchaseOrdersService.class).getById(vo.getOrder()));
}
if(vo.getInventoryId() == null) {
if (vo.getInventoryId() == null) {
model.setInventory(null);
} else {
model.setInventory(SpringApp.getBean(InventoryService.class).findById(vo.getInventoryId()));
model.setInventory(SpringApp.getBean(InventoryService.class).getById(vo.getInventoryId()));
}
}
}

View File

@@ -22,7 +22,6 @@ import com.ecep.contract.SpringApp;
import com.ecep.contract.ds.contract.repository.PurchaseOrderRepository;
import com.ecep.contract.ds.other.service.EmployeeService;
import com.ecep.contract.model.Contract;
import com.ecep.contract.model.Employee;
import com.ecep.contract.model.PurchaseOrder;
import com.ecep.contract.service.ServiceException;
import com.ecep.contract.service.VoableService;
@@ -36,22 +35,27 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "contract-purchase-order")
public class PurchaseOrdersService implements IEntityService<PurchaseOrder>, QueryService<PurchaseOrder>,
public class PurchaseOrdersService implements IEntityService<PurchaseOrder>, QueryService<PurchaseOrderVo>,
VoableService<PurchaseOrder, PurchaseOrderVo> {
private static final Logger logger = LoggerFactory.getLogger(PurchaseOrdersService.class);
@Lazy
@Autowired
private PurchaseOrderRepository purchaseOrderRepository;
private PurchaseOrderRepository repository;
@Lazy
@Autowired
private EmployeeService employeeService;
@Override
public PurchaseOrder getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Override
@Cacheable(key = "#p0")
public PurchaseOrder findById(Integer id) {
return purchaseOrderRepository.findById(id).orElse(null);
public PurchaseOrderVo findById(Integer id) {
return repository.findById(id).map(PurchaseOrder::toVo).orElse(null);
}
@Override
@@ -65,12 +69,12 @@ public class PurchaseOrdersService implements IEntityService<PurchaseOrder>, Que
@Cacheable(key = "'code-'+#p0")
public PurchaseOrder findByCode(String code) {
return purchaseOrderRepository.findByCode(code).orElse(null);
return repository.findByCode(code).orElse(null);
}
@Cacheable(key = "'refId-'+#p0")
public PurchaseOrder findByRefId(Integer refId) {
return purchaseOrderRepository.findByRefId(refId).orElse(null);
return repository.findByRefId(refId).orElse(null);
}
/**
@@ -84,8 +88,9 @@ public class PurchaseOrdersService implements IEntityService<PurchaseOrder>, Que
@CacheEvict(key = "'code-'+#p0.code"),
@CacheEvict(key = "'refId-'+#p0.refId")
})
@Override
public PurchaseOrder save(PurchaseOrder order) {
return purchaseOrderRepository.save(order);
return repository.save(order);
}
@Caching(evict = {
@@ -95,38 +100,38 @@ public class PurchaseOrdersService implements IEntityService<PurchaseOrder>, Que
})
@Override
public void delete(PurchaseOrder order) {
purchaseOrderRepository.delete(order);
repository.delete(order);
}
public long count() {
return purchaseOrderRepository.count();
return repository.count();
}
public long count(Specification<PurchaseOrder> spec) {
return purchaseOrderRepository.count(spec);
return repository.count(spec);
}
@Override
public Page<PurchaseOrder> findAll(Specification<PurchaseOrder> spec, Pageable pageable) {
return purchaseOrderRepository.findAll(spec, pageable);
return repository.findAll(spec, pageable);
}
@Override
public Page<PurchaseOrder> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<PurchaseOrderVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<PurchaseOrder> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
}
spec = SpecificationUtils.andParam(spec, paramsNode, "contract");
return findAll(spec, pageable);
return findAll(spec, pageable).map(PurchaseOrder::toVo);
}
public List<PurchaseOrder> findAll(Specification<PurchaseOrder> spec, Sort sort) {
return purchaseOrderRepository.findAll(spec, sort);
return repository.findAll(spec, sort);
}
public List<PurchaseOrder> findAllByContract(Contract contract) {
return purchaseOrderRepository.findAllByContract(contract);
return repository.findAllByContract(contract);
}
public List<PurchaseOrder> search(String searchText) {
@@ -135,7 +140,7 @@ public class PurchaseOrdersService implements IEntityService<PurchaseOrder>, Que
builder.like(root.get("name"), "%" + searchText + "%"),
builder.like(root.get("code"), "%" + searchText + "%"));
};
return purchaseOrderRepository.findAll(spec, Pageable.ofSize(10)).getContent();
return repository.findAll(spec, Pageable.ofSize(10)).getContent();
}
@Override
@@ -150,41 +155,52 @@ public class PurchaseOrdersService implements IEntityService<PurchaseOrder>, Que
model.setVendorCode(vo.getVendorCode());
model.setDescription(vo.getDescription());
// 更新负责人信息
// 处理关联实体 - 合同
if (vo.getContractId() == null) {
model.setContract(null);
} else {
model.setContract(SpringApp.getBean(ContractService.class).findById(vo.getContractId()));
ContractService contractService = SpringApp.getBean(ContractService.class);
if (model.getContract() == null || !model.getContract().getId().equals(vo.getContractId())) {
model.setContract(contractService.getById(vo.getContractId()));
}
}
EmployeeService employeeService = SpringApp.getBean(EmployeeService.class);
// 更新采购人信息
// 处理关联实体 - 采购人
if (vo.getEmployeeId() == null) {
model.setEmployee(null);
} else {
model.setEmployee(employeeService.findById(vo.getEmployeeId()));
if (model.getEmployee() == null || !model.getEmployee().getId().equals(vo.getEmployeeId())) {
model.setEmployee(employeeService.getById(vo.getEmployeeId()));
}
}
// 更新制单人信息
// 处理关联实体 - 制单人
if (vo.getMakerId() == null) {
model.setMaker(null);
} else {
model.setMaker(employeeService.findById(vo.getMakerId()));
if (model.getMaker() == null || !model.getMaker().getId().equals(vo.getMakerId())) {
model.setMaker(employeeService.getById(vo.getMakerId()));
}
}
model.setMakerDate(vo.getMakerDate());
model.setModifyDate(vo.getModifyDate());
// 更新审核人信息
// 处理关联实体 - 审核人
if (vo.getVerifierId() == null) {
model.setVerifier(null);
} else {
model.setVerifier(employeeService.findById(vo.getVerifierId()));
if (model.getVerifier() == null || !model.getVerifier().getId().equals(vo.getVerifierId())) {
model.setVerifier(employeeService.getById(vo.getVerifierId()));
}
}
model.setVerifierDate(vo.getVerifierDate());
// 更新关闭人信息
// 处理关联实体 - 关闭人
if (vo.getCloserId() == null) {
model.setCloser(null);
} else {
model.setCloser(employeeService.findById(vo.getCloserId()));
if (model.getCloser() == null || !model.getCloser().getId().equals(vo.getCloserId())) {
model.setCloser(employeeService.getById(vo.getCloserId()));
}
}
model.setCloserDate(vo.getCloserDate());
}

View File

@@ -32,17 +32,17 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "contract-sale-order")
public class SaleOrdersService extends EntityService<SalesOrder, Integer>
implements IEntityService<SalesOrder>, QueryService<SalesOrder>, VoableService<SalesOrder, SalesOrderVo> {
public class SaleOrdersService extends EntityService<SalesOrder, SalesOrderVo, Integer>
implements IEntityService<SalesOrder>, QueryService<SalesOrderVo>, VoableService<SalesOrder, SalesOrderVo> {
private static final Logger logger = LoggerFactory.getLogger(SaleOrdersService.class);
@Lazy
@Autowired
private SalesOrderRepository salesOrderRepository;
private SalesOrderRepository repository;
@Override
protected SalesOrderRepository getRepository() {
return salesOrderRepository;
return repository;
}
@Override
@@ -50,9 +50,14 @@ public class SaleOrdersService extends EntityService<SalesOrder, Integer>
return new SalesOrder();
}
@Override
public SalesOrder getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
public SalesOrder findById(Integer id) {
return salesOrderRepository.findById(id).orElse(null);
public SalesOrderVo findById(Integer id) {
return repository.findById(id).map(SalesOrder::toVo).orElse(null);
}
@Override
@@ -74,7 +79,7 @@ public class SaleOrdersService extends EntityService<SalesOrder, Integer>
@Cacheable(key = "'code-'+#p0")
public SalesOrder findByCode(String code) {
return salesOrderRepository.findByCode(code).orElse(null);
return repository.findByCode(code).orElse(null);
}
/**
@@ -88,7 +93,7 @@ public class SaleOrdersService extends EntityService<SalesOrder, Integer>
@CacheEvict(key = "'code-'+#p0.code")
})
public SalesOrder save(SalesOrder order) {
return salesOrderRepository.save(order);
return repository.save(order);
}
@Caching(evict = {
@@ -96,7 +101,7 @@ public class SaleOrdersService extends EntityService<SalesOrder, Integer>
@CacheEvict(key = "'code-'+#p0.code")
})
public void delete(SalesOrder order) {
salesOrderRepository.delete(order);
repository.delete(order);
}
@Override
@@ -111,31 +116,31 @@ public class SaleOrdersService extends EntityService<SalesOrder, Integer>
if (vo.getContractId() == null) {
model.setContract(null);
} else {
model.setContract(SpringApp.getBean(ContractService.class).findById(vo.getContractId()));
model.setContract(SpringApp.getBean(ContractService.class).getById(vo.getContractId()));
}
if (vo.getEmployeeId() == null) {
model.setEmployee(null);
} else {
model.setEmployee(SpringApp.getBean(EmployeeService.class).findById(vo.getEmployeeId()));
model.setEmployee(SpringApp.getBean(EmployeeService.class).getById(vo.getEmployeeId()));
}
if (vo.getMakerId() == null) {
model.setMaker(null);
} else {
model.setMaker(SpringApp.getBean(EmployeeService.class).findById(vo.getMakerId()));
model.setMaker(SpringApp.getBean(EmployeeService.class).getById(vo.getMakerId()));
}
if (vo.getVerifierId() == null) {
model.setVerifier(null);
} else {
model.setVerifier(SpringApp.getBean(EmployeeService.class).findById(vo.getVerifierId()));
model.setVerifier(SpringApp.getBean(EmployeeService.class).getById(vo.getVerifierId()));
}
// active字段在SalesOrder实体类中不存在不需要设置
}
public List<SalesOrder> findAllByContract(Contract contract) {
return salesOrderRepository.findAllByContract(contract);
return repository.findAllByContract(contract);
}
}

View File

@@ -37,8 +37,8 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "sales-bill-voucher")
public class SalesBillVoucherService extends EntityService<SalesBillVoucher, Integer>
implements IEntityService<SalesBillVoucher>, QueryService<SalesBillVoucher>,
public class SalesBillVoucherService extends EntityService<SalesBillVoucher, SalesBillVoucherVo, Integer>
implements IEntityService<SalesBillVoucher>, QueryService<SalesBillVoucherVo>,
VoableService<SalesBillVoucher, SalesBillVoucherVo> {
private static final Logger logger = LoggerFactory.getLogger(SalesBillVoucherService.class);
@@ -60,8 +60,9 @@ public class SalesBillVoucherService extends EntityService<SalesBillVoucher, Int
}
@Cacheable(key = "#p0")
public SalesBillVoucher findById(Integer id) {
return salesBillVoucherRepository.findById(id).orElse(null);
@Override
public SalesBillVoucherVo findById(Integer id) {
return salesBillVoucherRepository.findById(id).map(SalesBillVoucher::toVo).orElse(null);
}
@Override
@@ -163,32 +164,32 @@ public class SalesBillVoucherService extends EntityService<SalesBillVoucher, Int
if (vo.getCompanyId() == null) {
model.setCompany(null);
} else {
model.setCompany(SpringApp.getBean(CompanyService.class).findById(vo.getCompanyId()));
model.setCompany(SpringApp.getBean(CompanyService.class).getById(vo.getCompanyId()));
}
if (vo.getOrderId() == null) {
model.setOrder(null);
} else {
model.setOrder(SpringApp.getBean(SaleOrdersService.class).findById(vo.getOrderId()));
model.setOrder(SpringApp.getBean(SaleOrdersService.class).getById(vo.getOrderId()));
}
EmployeeService employeeService = SpringApp.getBean(EmployeeService.class);
if (vo.getEmployeeId() == null) {
model.setEmployee(null);
} else {
model.setEmployee(employeeService.findById(vo.getEmployeeId()));
model.setEmployee(employeeService.getById(vo.getEmployeeId()));
}
if (vo.getMakerId() == null) {
model.setMaker(null);
} else {
model.setMaker(employeeService.findById(vo.getMakerId()));
model.setMaker(employeeService.getById(vo.getMakerId()));
}
if (vo.getVerifierId() == null) {
model.setVerifier(null);
} else {
model.setVerifier(employeeService.findById(vo.getVerifierId()));
model.setVerifier(employeeService.getById(vo.getVerifierId()));
}
}
}

View File

@@ -24,8 +24,8 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "contract-sale-order-item")
public class SalesOrderItemService extends EntityService<SalesOrderItem, Integer>
implements IEntityService<SalesOrderItem>, QueryService<SalesOrderItem>,
public class SalesOrderItemService extends EntityService<SalesOrderItem, SalesOrderItemVo, Integer>
implements IEntityService<SalesOrderItem>, QueryService<SalesOrderItemVo>,
VoableService<SalesOrderItem, SalesOrderItemVo> {
@Lazy
@Autowired
@@ -43,8 +43,8 @@ public class SalesOrderItemService extends EntityService<SalesOrderItem, Integer
@Cacheable(key = "#p0")
@Override
public SalesOrderItem findById(Integer id) {
return repository.findById(id).orElse(null);
public SalesOrderItemVo findById(Integer id) {
return repository.findById(id).map(SalesOrderItem::toVo).orElse(null);
}
@Override
@@ -105,7 +105,7 @@ public class SalesOrderItemService extends EntityService<SalesOrderItem, Integer
if (vo.getOrderId() == null) {
model.setOrder(null);
} else {
model.setOrder(SpringApp.getBean(SaleOrdersService.class).findById(vo.getOrderId()));
model.setOrder(SpringApp.getBean(SaleOrdersService.class).getById(vo.getOrderId()));
}
}
}

View File

@@ -259,7 +259,7 @@ public abstract class AbstContractRepairTasker extends Tasker<Object> {
}
} catch (Exception e) {
if (!Hibernate.isInitialized(v)) {
v = contractService.findById(v.getId());
v = contractService.getById(v.getId());
}
throw new RuntimeException("同步子合同失败, contract=" + v.toPrettyString(), e);
}

View File

@@ -133,11 +133,11 @@ public class ContractRepairComm {
}
public Project findProjectById(Integer projectId) {
return getProjectService().findById(projectId);
return getProjectService().getById(projectId);
}
public Company findCompanyById(Integer companyId) {
return getCompanyService().findById(companyId);
return getCompanyService().getById(companyId);
}
public Contract findContractByGuid(String guid) {

View File

@@ -14,7 +14,6 @@ import java.util.Objects;
import java.util.stream.Collectors;
import org.hibernate.Hibernate;
import org.springframework.security.core.userdetails.User;
import org.springframework.util.StringUtils;
import com.ecep.contract.ContractFileType;
@@ -28,7 +27,6 @@ import com.ecep.contract.ds.company.service.CompanyExtendInfoService;
import com.ecep.contract.ds.contract.service.ExtendVendorInfoService;
import com.ecep.contract.ds.converter.NumberStringConverter;
import com.ecep.contract.ds.other.service.EmployeeService;
import com.ecep.contract.service.tasker.ProjectCostImportItemsFromContractsTasker;
import com.ecep.contract.ds.project.service.ProjectBidService;
import com.ecep.contract.ds.project.service.ProjectCostService;
import com.ecep.contract.ds.project.service.ProjectQuotationService;
@@ -53,8 +51,10 @@ import com.ecep.contract.model.ProjectSaleType;
import com.ecep.contract.model.ProjectSaleTypeRequireFileType;
import com.ecep.contract.model.VendorGroup;
import com.ecep.contract.model.VendorGroupRequireFileType;
import com.ecep.contract.util.SecurityUtils;
import com.ecep.contract.service.tasker.ProjectCostImportItemsFromContractsTasker;
import com.ecep.contract.util.VerifyContext;
import com.ecep.contract.vo.ContractFileTypeLocalVo;
import com.ecep.contract.vo.ProjectSaleTypeVo;
import lombok.Data;
@@ -95,7 +95,7 @@ public class ContractVerifyComm extends VerifyContext {
/**
*
*/
private Map<ContractFileType, ContractFileTypeLocal> fileTypeLocalMap = null;
private Map<ContractFileType, ContractFileTypeLocalVo> fileTypeLocalMap = null;
private Contract contract;
/**
@@ -151,7 +151,7 @@ public class ContractVerifyComm extends VerifyContext {
return false;
}
if (!Hibernate.isInitialized(company)) {
company = getCompanyService().findById(company.getId());
company = getCompanyService().getById(company.getId());
}
if (!verify(company, contract, holder)) {
passed = false;
@@ -297,7 +297,7 @@ public class ContractVerifyComm extends VerifyContext {
if (group != null) {
if (!Hibernate.isInitialized(group)) {
group = getVendorGroupService().findById(group.getId());
group = getVendorGroupService().getById(group.getId());
vendorInfo.setGroup(group);
}
}
@@ -372,7 +372,7 @@ public class ContractVerifyComm extends VerifyContext {
}
} else {
if (!Hibernate.isInitialized(contractFile)) {
contractFile = getContractFileService().findById(contractFile.getId());
contractFile = getContractFileService().getById(contractFile.getId());
}
ContractFileType type = contractFile.getType();
if (type != ContractFileType.QuotationSheet) {
@@ -393,7 +393,7 @@ public class ContractVerifyComm extends VerifyContext {
}
}
ContractFileTypeLocal getFileTypeLocal(ContractFileType type) {
ContractFileTypeLocalVo getFileTypeLocal(ContractFileType type) {
if (fileTypeLocalMap == null) {
fileTypeLocalMap = getContractFileTypeService().findAll(getLocale());
}
@@ -401,7 +401,7 @@ public class ContractVerifyComm extends VerifyContext {
}
String getFileTypeLocalValue(ContractFileType type) {
ContractFileTypeLocal fileTypeLocal = getContractFileTypeService().findByTypeAndLang(type, getLocale());
ContractFileTypeLocalVo fileTypeLocal = getContractFileTypeService().findByTypeAndLang(type, getLocale());
if (fileTypeLocal == null) {
return type.name();
}
@@ -451,7 +451,7 @@ public class ContractVerifyComm extends VerifyContext {
// fixed no hibernate session
if (project != null) {
if (!Hibernate.isInitialized(project)) {
project = getProjectService().findById(project.getId());
project = getProjectService().getById(project.getId());
// fixed
contract.setProject(project);
}
@@ -467,7 +467,7 @@ public class ContractVerifyComm extends VerifyContext {
if (saleType != null) {
if (CompanyFileUtils.exists(contract.getPath())) {
if (!Hibernate.isInitialized(saleType)) {
saleType = getProjectSaleTypeService().findById(saleType.getId());
saleType = getProjectSaleTypeService().getById(saleType.getId());
project.setSaleType(saleType);
}
if (!contract.getPath().startsWith(saleType.getPath())) {
@@ -624,7 +624,10 @@ public class ContractVerifyComm extends VerifyContext {
if (saleType == null) {
String code = contract.getCode();
if (code != null && code.length() > 5) {
saleType = getProjectSaleTypeService().findByCode(code.substring(0, 1));
ProjectSaleTypeVo saleTypeVo = getProjectSaleTypeService().findByCode(code.substring(0, 1));
if (saleTypeVo != null) {
saleType = getProjectSaleTypeService().getById(saleTypeVo.getId());
}
}
}
@@ -639,12 +642,23 @@ public class ContractVerifyComm extends VerifyContext {
//
boolean needImport = false;
ProjectCost autoCost = getProjectCostService().findAutoCostByProject(project);
List<ProjectCost> projectCosts = getProjectCostService().findByProject(project);
ProjectCost autoCost = null;
for (ProjectCost cost : projectCosts) {
if (cost.getVersion() == 0) {
autoCost = cost;
break;
}
}
if (autoCost == null) {
// 创建 V0 项目成本
ProjectCost cost = getProjectCostService().newInstanceByProject(project);
ProjectCost cost = new ProjectCost();
cost.setProject(project);
cost.setVersion(0);
cost.setApplicant(getEmployeeService().findById(EmployeeService.DEFAULT_SYSTEM_EMPLOYEE_ID));
cost.setStampTax(0.03f);
cost.setTaxAndSurcharges(11f);
cost.setApplicant(getEmployeeService().getById(EmployeeService.DEFAULT_SYSTEM_EMPLOYEE_ID));
cost.setApplyTime(LocalDateTime.now());
cost.setDescription("自动导入");
autoCost = getProjectCostService().save(cost);
@@ -667,15 +681,9 @@ public class ContractVerifyComm extends VerifyContext {
// 在类中添加以下依赖,假设使用 Spring Security 来获取当前登录用户
// 以下代码替换原有的获取当前用户逻辑,假设用户名即为员工 ID
// 需根据实际业务调整 UserDetails 中的信息获取方式
// 使用系统员工作为当前用户,实际项目中可能需要修改这里的逻辑
tasker.setCurrentUser(() -> {
User currentUser = SecurityUtils.getCurrentUser();
String username = currentUser.getUsername();
try {
return getEmployeeService().findByName(username);
} catch (NumberFormatException e) {
// 处理转换失败的情况,可根据实际需求调整
return null;
}
return getEmployeeService().getById(EmployeeService.DEFAULT_SYSTEM_EMPLOYEE_ID);
});
autoCost.setApplyTime(LocalDateTime.now());
@@ -684,10 +692,23 @@ public class ContractVerifyComm extends VerifyContext {
}
// 检查最新的项目成本,默认 V1
ProjectCost latestCost = getProjectCostService().findLatestByProject(project);
ProjectCost latestCost = null;
if (!projectCosts.isEmpty()) {
int maxVersion = -1;
for (ProjectCost cost : projectCosts) {
if (cost.getVersion() > maxVersion) {
maxVersion = cost.getVersion();
latestCost = cost;
}
}
}
if (latestCost == null) {
ProjectCost cost = getProjectCostService().newInstanceByProject(project);
ProjectCost cost = new ProjectCost();
cost.setProject(project);
cost.setVersion(1);
cost.setStampTax(0.03f);
cost.setTaxAndSurcharges(11f);
Employee applicant = project.getApplicant();
if (applicant == null) {
applicant = contract.getEmployee();
@@ -766,7 +787,7 @@ public class ContractVerifyComm extends VerifyContext {
}
}
if (!Hibernate.isInitialized(saleType)) {
saleType = getProjectSaleTypeService().findById(saleType.getId());
saleType = getProjectSaleTypeService().getById(saleType.getId());
}
if (saleType.isCriticalProjectDecision()) {
if (contract.getAmount() != null && contract.getAmount() >= saleType.getCriticalProjectLimit()) {

View File

@@ -30,6 +30,7 @@ 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.ProjectSaleTypeService;
import com.ecep.contract.ds.project.repository.ProjectCostRepository;
import com.ecep.contract.model.Company;
import com.ecep.contract.model.Contract;
import com.ecep.contract.model.Employee;
@@ -254,7 +255,7 @@ public class CustomerContractCostFormUpdateTask extends Tasker<Object> {
String address = null;
if (project != null) {
if (!Hibernate.isInitialized(project)) {
project = getProjectService().findById(project.getId());
project = getProjectService().getById(project.getId());
contract.setProject(project);
}
projectName = project.getName();
@@ -262,7 +263,7 @@ public class CustomerContractCostFormUpdateTask extends Tasker<Object> {
saleType = project.getSaleType();
if (saleType != null) {
if (!Hibernate.isInitialized(saleType)) {
saleType = getProjectSaleTypeService().findById(saleType.getId());
saleType = getProjectSaleTypeService().getById(saleType.getId());
project.setSaleType(saleType);
}
}
@@ -270,7 +271,7 @@ public class CustomerContractCostFormUpdateTask extends Tasker<Object> {
projectType = project.getProjectType();
if (projectType != null) {
if (!Hibernate.isInitialized(projectType)) {
projectType = getProjectTypeService().findById(projectType.getId());
projectType = getProjectTypeService().getById(projectType.getId());
project.setProjectType(projectType);
}
}
@@ -278,7 +279,7 @@ public class CustomerContractCostFormUpdateTask extends Tasker<Object> {
industry = project.getIndustry();
if (industry != null) {
if (!Hibernate.isInitialized(industry)) {
industry = getProjectIndustryService().findById(industry.getId());
industry = getProjectIndustryService().getById(industry.getId());
project.setIndustry(industry);
}
}
@@ -286,7 +287,7 @@ public class CustomerContractCostFormUpdateTask extends Tasker<Object> {
productType = project.getProductType();
if (productType != null) {
if (!Hibernate.isInitialized(productType)) {
productType = getProductTypeService().findById(productType.getId());
productType = getProductTypeService().getById(productType.getId());
project.setProductType(productType);
}
@@ -310,7 +311,7 @@ public class CustomerContractCostFormUpdateTask extends Tasker<Object> {
Company company = contract.getCompany();
if (company != null) {
if (!Hibernate.isInitialized(company)) {
company = getCompanyService().findById(company.getId());
company = getCompanyService().getById(company.getId());
contract.setCompany(company);
}
setCellValue(sheet, "C6", company.getName());
@@ -320,7 +321,7 @@ public class CustomerContractCostFormUpdateTask extends Tasker<Object> {
Employee employee = contract.getEmployee();
if (employee != null) {
if (!Hibernate.isInitialized(employee)) {
employee = getEmployeeService().findById(employee.getId());
employee = getEmployeeService().getById(employee.getId());
contract.setEmployee(employee);
}
setCellValue(sheet, "M7", employee.getName());
@@ -328,7 +329,8 @@ public class CustomerContractCostFormUpdateTask extends Tasker<Object> {
float taxAndSurcharges = 11;
ProjectCost cost = getCostService().findByContract(contract);
ProjectCostRepository costRepository = SpringApp.getBean(ProjectCostRepository.class);
ProjectCost cost = costRepository.findByContract(contract).orElse(null);
if (cost != null) {
taxAndSurcharges = cost.getTaxAndSurcharges();
if (cost.getApplyTime() != null) {
@@ -340,7 +342,10 @@ public class CustomerContractCostFormUpdateTask extends Tasker<Object> {
float stampTax = 0.03f;
setCellValue(sheet, "D39", stampTax + "%");
List<ProjectCostItem> items = getCostItemService().findByCost(cost);
List<ProjectCostItem> items = List.of();
if (cost != null) {
items = getCostItemService().findByCostId(cost.getId());
}
for (int i = 0; i < items.size(); i++) {
ProjectCostItem item = items.get(i);
int row = 10 + i;

View File

@@ -28,7 +28,7 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "company-customer-entity")
public class CompanyCustomerEntityService implements IEntityService<CompanyCustomerEntity>, QueryService<CompanyCustomerEntity>, VoableService<CompanyCustomerEntity, CompanyCustomerEntityVo> {
public class CompanyCustomerEntityService implements IEntityService<CompanyCustomerEntity>, QueryService<CompanyCustomerEntityVo>, VoableService<CompanyCustomerEntity, CompanyCustomerEntityVo> {
@Lazy
@Autowired
private CompanyCustomerEntityRepository repository;
@@ -42,10 +42,15 @@ public class CompanyCustomerEntityService implements IEntityService<CompanyCusto
@Autowired
private EmployeeService employeeService;
@Override
public CompanyCustomerEntity getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
@Override
public CompanyCustomerEntity findById(Integer id) {
return repository.findById(id).orElse(null);
public CompanyCustomerEntityVo findById(Integer id) {
return repository.findById(id).map(CompanyCustomerEntity::toVo).orElse(null);
}
@Override
@@ -76,14 +81,14 @@ public class CompanyCustomerEntityService implements IEntityService<CompanyCusto
}
@Override
public Page<CompanyCustomerEntity> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<CompanyCustomerEntityVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<CompanyCustomerEntity> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "customer");
return findAll(spec, pageable);
return findAll(spec, pageable).map(CompanyCustomerEntity::toVo);
}
@Caching(evict = {
@@ -123,26 +128,56 @@ public class CompanyCustomerEntityService implements IEntityService<CompanyCusto
@Override
public void updateByVo(CompanyCustomerEntity entity, CompanyCustomerEntityVo vo) {
if (vo.getCustomerId() != null) {
entity.setCustomer(companyCustomerService.findById(vo.getCustomerId()));
// 优化关联实体处理逻辑 - 客户关联
if (vo.getCustomerId() == null) {
entity.setCustomer(null);
} else {
// 添加实体匹配检查
if (entity.getCustomer() == null || !entity.getCustomer().getId().equals(vo.getCustomerId())) {
// 使用getById方法替代findById
entity.setCustomer(companyCustomerService.getById(vo.getCustomerId()));
}
}
// 映射基本属性
entity.setName(vo.getName());
entity.setAbbName(vo.getAbbName());
entity.setCode(vo.getCode());
if (vo.getCustomerCatalogId() != null) {
entity.setCatalog(customerCatalogService.findById(vo.getCustomerCatalogId()));
// 优化关联实体处理逻辑 - 客户分类关联
if (vo.getCustomerCatalogId() == null) {
entity.setCatalog(null);
} else {
// 添加实体匹配检查
if (entity.getCatalog() == null || !entity.getCatalog().getId().equals(vo.getCustomerCatalogId())) {
// 使用getById方法替代findById
entity.setCatalog(customerCatalogService.getById(vo.getCustomerCatalogId()));
}
}
if (vo.getCreatorId() != null) {
entity.setCreator(employeeService.findById(vo.getCreatorId()));
// 优化关联实体处理逻辑 - 创建者关联
if (vo.getCreatorId() == null) {
entity.setCreator(null);
} else {
// 添加实体匹配检查
if (entity.getCreator() == null || !entity.getCreator().getId().equals(vo.getCreatorId())) {
// 使用getById方法替代findById
entity.setCreator(employeeService.getById(vo.getCreatorId()));
}
}
if (vo.getModifierId() != null) {
entity.setModifier(employeeService.findById(vo.getModifierId()));
// 优化关联实体处理逻辑 - 修改者关联
if (vo.getModifierId() == null) {
entity.setModifier(null);
} else {
// 添加实体匹配检查
if (entity.getModifier() == null || !entity.getModifier().getId().equals(vo.getModifierId())) {
// 使用getById方法替代findById
entity.setModifier(employeeService.getById(vo.getModifierId()));
}
}
// 映射其他属性
entity.setModifyDate(vo.getModifyDate());
entity.setDevelopDate(vo.getDevelopDate());
entity.setUpdatedDate(vo.getUpdatedDate());

View File

@@ -41,10 +41,15 @@ public class CompanyCustomerEvaluationFormFileService
@Autowired
private CompanyCustomerEvaluationFormFileRepository repository;
@Override
public CompanyCustomerEvaluationFormFile getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
@Override
public CompanyCustomerEvaluationFormFile findById(Integer id) {
return repository.findById(id).orElse(null);
return getById(id);
}
@Override
@@ -154,11 +159,16 @@ public class CompanyCustomerEvaluationFormFileService
model.setScoreTemplateVersion(vo.getScoreTemplateVersion());
if (vo.getCustomerFile() != null) {
CompanyCustomerFileService service = SpringApp.getBean(CompanyCustomerFileService.class);
model.setCustomerFile(service.findById(vo.getCustomerFile()));
} else {
// 优化关联实体处理逻辑
if (vo.getCustomerFile() == null) {
model.setCustomerFile(null);
} else {
CompanyCustomerFileService service = SpringApp.getBean(CompanyCustomerFileService.class);
// 添加实体匹配检查
if (model.getCustomerFile() == null || !model.getCustomerFile().getId().equals(vo.getCustomerFile())) {
// 使用getById方法替代findById
model.setCustomerFile(service.getById(vo.getCustomerFile()));
}
}
}
}

View File

@@ -63,6 +63,11 @@ public class CompanyCustomerFileService
@Cacheable(key = "#p0")
public CompanyCustomerFile findById(Integer id) {
return getById(id);
}
@Override
public CompanyCustomerFile getById(Integer id) {
return companyCustomerFileRepository.findById(id).orElse(null);
}
@@ -276,19 +281,24 @@ public class CompanyCustomerFileService
model.setFilePath(vo.getFilePath());
model.setType(vo.getType());
model.setFilePath(vo.getFilePath());
model.setEditFilePath(vo.getEditFilePath());
model.setSignDate(vo.getSignDate());
model.setValid(vo.isValid());
if (vo.getCustomer() != null) {
CompanyCustomerService service = SpringApp.getBean(CompanyCustomerService.class);
model.setCustomer(service.findById(vo.getCustomer()));
} else {
// 优化关联实体处理逻辑
if (vo.getCustomer() == null) {
model.setCustomer(null);
} else {
CompanyCustomerService service = SpringApp.getBean(CompanyCustomerService.class);
// 添加实体匹配检查
if (model.getCustomer() == null || !model.getCustomer().getId().equals(vo.getCustomer())) {
// 使用getById方法替代findById
model.setCustomer(service.getById(vo.getCustomer()));
}
}
}
}

View File

@@ -2,6 +2,7 @@ package com.ecep.contract.ds.customer.service;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
@@ -31,19 +32,23 @@ import jakarta.annotation.Resource;
@Lazy
@Service
@CacheConfig(cacheNames = "customer-file-type")
public class CompanyCustomerFileTypeService implements IEntityService<CompanyCustomerFileTypeLocal>, QueryService<CompanyCustomerFileTypeLocal>,
public class CompanyCustomerFileTypeService implements IEntityService<CompanyCustomerFileTypeLocal>, QueryService<CompanyCustomerFileTypeLocalVo>,
VoableService<CompanyCustomerFileTypeLocal, CompanyCustomerFileTypeLocalVo> {
@Resource
private CompanyCustomerFileTypeLocalRepository repository;
@Cacheable(key = "#p0")
@Override
public CompanyCustomerFileTypeLocal findById(Integer id) {
public CompanyCustomerFileTypeLocalVo findById(Integer id) {
return repository.findById(id).map(CompanyCustomerFileTypeLocal::toVo).orElse(null);
}
public CompanyCustomerFileTypeLocal getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Override
public Page<CompanyCustomerFileTypeLocal> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<CompanyCustomerFileTypeLocalVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<CompanyCustomerFileTypeLocal> spec = null;
if (paramsNode.has(ServiceConstant.KEY_SEARCH_TEXT)) {
spec = getSpecification(paramsNode.get(ServiceConstant.KEY_SEARCH_TEXT).asText());
@@ -53,12 +58,16 @@ public class CompanyCustomerFileTypeService implements IEntityService<CompanyCus
spec = SpecificationUtils.and(spec, (root, query, builder) -> builder.equal(root.get("type"), CustomerFileType.valueOf(paramsNode.get("type").asText())));
}
// field
return findAll(spec, pageable);
return findAll(spec, pageable).map(CompanyCustomerFileTypeLocal::toVo);
}
@Cacheable(key = "'all-'+#p0.toLanguageTag()")
public Map<CustomerFileType, CompanyCustomerFileTypeLocal> findAll(Locale locale) {
return repository.getCompleteMapByLocal(locale.toLanguageTag());
public Map<CustomerFileType, CompanyCustomerFileTypeLocalVo> findAll(Locale locale) {
return repository.getCompleteMapByLocal(locale.toLanguageTag()).entrySet().stream()
.collect(java.util.stream.Collectors.toMap(
java.util.Map.Entry::getKey,
entry -> entry.getValue().toVo()
));
}
@Override

View File

@@ -59,13 +59,13 @@ import jakarta.persistence.criteria.Path;
@Service
@CacheConfig(cacheNames = "company-customer")
public class CompanyCustomerService extends CompanyBasicService
implements IEntityService<CompanyCustomer>, QueryService<CompanyCustomer>,
implements IEntityService<CompanyCustomer>, QueryService<CompanyCustomerVo>,
VoableService<CompanyCustomer, CompanyCustomerVo> {
private static final Logger logger = LoggerFactory.getLogger(CompanyCustomerService.class);
@Lazy
@Autowired
private CompanyCustomerRepository companyCustomerRepository;
private CompanyCustomerRepository repository;
@Lazy
@Autowired
private CompanyCustomerFileService companyCustomerFileService;
@@ -77,19 +77,24 @@ public class CompanyCustomerService extends CompanyBasicService
private CompanyCustomerEntityService companyCustomerEntityService;
public CompanyCustomer findByCompany(Company company) {
return companyCustomerRepository.findByCompany(company).orElse(null);
return repository.findByCompany(company).orElse(null);
}
@Override
public CompanyCustomer getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
public CompanyCustomer findById(Integer id) {
return companyCustomerRepository.findById(id).orElse(null);
public CompanyCustomerVo findById(Integer id) {
return repository.findById(id).map(CompanyCustomer::toVo).orElse(null);
}
@Caching(evict = {
@CacheEvict(key = "#p0.id")
})
public CompanyCustomer save(CompanyCustomer companyCustomer) {
return companyCustomerRepository.save(companyCustomer);
return repository.save(companyCustomer);
}
@Caching(evict = {
@@ -97,7 +102,7 @@ public class CompanyCustomerService extends CompanyBasicService
})
@Override
public void delete(CompanyCustomer entity) {
companyCustomerRepository.delete(entity);
repository.delete(entity);
}
@Override
@@ -138,7 +143,7 @@ public class CompanyCustomerService extends CompanyBasicService
@Override
public List<CompanyCustomer> search(String searchText) {
Specification<CompanyCustomer> spec = getSpecification(searchText);
return companyCustomerRepository.findAll(spec, Pageable.ofSize(10)).getContent();
return repository.findAll(spec, Pageable.ofSize(10)).getContent();
}
@Override
@@ -188,7 +193,7 @@ public class CompanyCustomerService extends CompanyBasicService
@SuppressWarnings("unchecked")
@Override
protected <T, F extends CompanyBasicFile<T>> boolean fillFileAsDefaultType(F dbFile, File file,
Consumer<String> status) {
Consumer<String> status) {
dbFile.setType((T) CustomerFileType.General);
fillFile(dbFile, file, null, status);
companyCustomerFileService.save((CompanyCustomerFile) dbFile);
@@ -197,7 +202,7 @@ public class CompanyCustomerService extends CompanyBasicService
@Override
protected <T, F extends CompanyBasicFile<T>> boolean fillFileAsEvaluationFile(F customerFile, File file,
List<File> fileList, Consumer<String> status) {
List<File> fileList, Consumer<String> status) {
boolean modified = super.fillFileAsEvaluationFile(customerFile, file, fileList, status);
if (fileList != null) {
@@ -231,7 +236,7 @@ public class CompanyCustomerService extends CompanyBasicService
}
private <T, F extends CompanyBasicFile<T>> void updateEvaluationFileByJsonFile(F customerFile, File jsonFile,
Consumer<String> status) throws IOException {
Consumer<String> status) throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode root = objectMapper.readTree(jsonFile);
if (!root.isObject()) {
@@ -257,7 +262,7 @@ public class CompanyCustomerService extends CompanyBasicService
@SuppressWarnings("unchecked")
@Override
protected <T, F extends CompanyBasicFile<T>> F fillFileType(File file, List<File> fileList,
Consumer<String> status) {
Consumer<String> status) {
CompanyCustomerFile customerFile = new CompanyCustomerFile();
customerFile.setType(CustomerFileType.General);
if (fillFile(customerFile, file, fileList, status)) {
@@ -281,7 +286,7 @@ public class CompanyCustomerService extends CompanyBasicService
return (fileName.contains(CompanyCustomerConstant.EVALUATION_FORM_NAME1)
|| fileName.contains(CompanyCustomerConstant.EVALUATION_FORM_NAME2))
&& (FileUtils.withExtensions(fileName, FileUtils.JPG, FileUtils.JPEG,
FileUtils.PDF));
FileUtils.PDF));
}
public boolean makePathAbsent(CompanyCustomer companyCustomer) {
@@ -308,7 +313,7 @@ public class CompanyCustomerService extends CompanyBasicService
File basePath = getBasePath();
Company company = companyCustomer.getCompany();
if (!Hibernate.isInitialized(company)) {
company = companyService.findById(company.getId());
company = companyService.getById(company.getId());
}
String companyName = company.getName();
@@ -325,18 +330,18 @@ public class CompanyCustomerService extends CompanyBasicService
}
public Page<CompanyCustomer> findAll(Specification<CompanyCustomer> spec, Pageable pageable) {
return companyCustomerRepository.findAll(spec, pageable);
return repository.findAll(spec, pageable);
}
@Override
public Page<CompanyCustomer> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<CompanyCustomerVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<CompanyCustomer> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "company");
return findAll(spec, pageable);
return findAll(spec, pageable).map(CompanyCustomer::toVo);
}
/**
@@ -347,17 +352,17 @@ public class CompanyCustomerService extends CompanyBasicService
*/
public void resetTo(Company from, Company to) {
// 这里使用Optional对象来处理可能为空的情况
Optional<CompanyCustomer> fromCustomer = companyCustomerRepository.findByCompany(from);
Optional<CompanyCustomer> fromCustomer = repository.findByCompany(from);
if (fromCustomer.isEmpty()) {
// 无效数据
return;
}
Optional<CompanyCustomer> toCustomer = companyCustomerRepository.findByCompany(to);
Optional<CompanyCustomer> toCustomer = repository.findByCompany(to);
if (toCustomer.isEmpty()) {
CompanyCustomer customer = fromCustomer.get();
customer.setCompany(to);
// 保存更新后的CompanyCustomer对象到数据库
companyCustomerRepository.save(customer);
repository.save(customer);
return;
}
@@ -378,14 +383,14 @@ public class CompanyCustomerService extends CompanyBasicService
// entity
companyCustomerEntityService.resetTo(from, to);
// 删除源客户对象
companyCustomerRepository.delete(from);
repository.delete(from);
}
/**
* 删除 company 的 客户
*/
public void deleteByCompany(Company company) {
int deleted = companyCustomerRepository.deleteAllByCompany(company);
int deleted = repository.deleteAllByCompany(company);
if (deleted > 0) {
if (logger.isInfoEnabled()) {
logger.info("Delete {} records by company:#{}", deleted, company.getId());
@@ -395,29 +400,47 @@ public class CompanyCustomerService extends CompanyBasicService
@Override
public void updateByVo(CompanyCustomer customer, CompanyCustomerVo vo) {
// 优化关联实体处理逻辑 - 公司关联
if (vo.getCompanyId() == null) {
customer.setCompany(null);
} else {
CompanyService service = SpringApp.getBean(CompanyService.class);
customer.setCompany(service.findById(vo.getCompanyId()));
// 添加实体匹配检查
if (customer.getCompany() == null || !customer.getCompany().getId().equals(vo.getCompanyId())) {
// 使用getById方法替代findById
customer.setCompany(service.getById(vo.getCompanyId()));
}
}
// 优化关联实体处理逻辑 - 客户分类关联
if (vo.getCatalogId() == null) {
customer.setCatalog(null);
} else {
CustomerCatalogService service = SpringApp.getBean(CustomerCatalogService.class);
customer.setCatalog(service.findById(vo.getCatalogId()));
// 添加实体匹配检查
if (customer.getCatalog() == null || !customer.getCatalog().getId().equals(vo.getCatalogId())) {
// 使用getById方法替代findById
customer.setCatalog(service.getById(vo.getCatalogId()));
}
}
// 映射基本属性
customer.setDevelopDate(vo.getDevelopDate());
customer.setPath(vo.getPath());
// 优化关联实体处理逻辑 - 联系人关联
if (vo.getContactId() == null) {
customer.setContact(null);
} else {
CompanyContactService service = SpringApp.getBean(CompanyContactService.class);
customer.setContact(service.findById(vo.getContactId()));
// 添加实体匹配检查
if (customer.getContact() == null || !customer.getContact().getId().equals(vo.getContactId())) {
// 使用getById方法替代findById
customer.setContact(service.getById(vo.getContactId()));
}
}
// 映射其他属性
customer.setDescription(vo.getDescription());
customer.setCreated(vo.getCreated());

View File

@@ -5,11 +5,11 @@ import com.ecep.contract.QueryService;
import com.ecep.contract.constant.ServiceConstant;
import com.ecep.contract.ds.customer.repository.CustomerCatalogRepository;
import com.ecep.contract.model.CustomerCatalog;
import com.ecep.contract.util.SpecificationUtils;
import com.fasterxml.jackson.databind.JsonNode;
import com.ecep.contract.service.ServiceException;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.util.SpecificationUtils;
import com.ecep.contract.vo.CustomerCatalogVo;
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;
@@ -30,7 +30,7 @@ import java.util.List;
@Lazy
@Service
@CacheConfig(cacheNames = "customer-catalog")
public class CustomerCatalogService implements IEntityService<CustomerCatalog>, QueryService<CustomerCatalog>,
public class CustomerCatalogService implements IEntityService<CustomerCatalog>, QueryService<CustomerCatalogVo>,
VoableService<CustomerCatalog, CustomerCatalogVo> {
@Lazy
@Autowired
@@ -39,10 +39,15 @@ public class CustomerCatalogService implements IEntityService<CustomerCatalog>,
/**
* 根据 id 查找 CustomerCatalog
*/
@Override
public CustomerCatalog getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
@Override
public CustomerCatalog findById(Integer id) {
return repository.findById(id).orElse(null);
public CustomerCatalogVo findById(Integer id) {
return repository.findById(id).map(CustomerCatalog::toVo).orElse(null);
}
@@ -112,7 +117,7 @@ public class CustomerCatalogService implements IEntityService<CustomerCatalog>,
* 分页查询 CustomerCatalog
*/
@Override
public Page<CustomerCatalog> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<CustomerCatalogVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<CustomerCatalog> spec = null;
if (paramsNode.has(ServiceConstant.KEY_SEARCH_TEXT)) {
spec = getSpecification(paramsNode.get(ServiceConstant.KEY_SEARCH_TEXT).asText());
@@ -120,7 +125,7 @@ public class CustomerCatalogService implements IEntityService<CustomerCatalog>,
// 字段等值查询
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "code", "name", "description");
return repository.findAll(spec, pageable);
return repository.findAll(spec, pageable).map(CustomerCatalog::toVo);
}
/**
@@ -154,6 +159,7 @@ public class CustomerCatalogService implements IEntityService<CustomerCatalog>,
@Override
public void updateByVo(CustomerCatalog model, CustomerCatalogVo vo) {
// 参数校验
if (model == null) {
throw new ServiceException("实体对象不能为空");
}

View File

@@ -2,6 +2,7 @@ package com.ecep.contract.ds.customer.service;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
@@ -31,14 +32,14 @@ import com.ecep.contract.vo.CustomerFileTypeLocalVo;
@Lazy
@Service
@CacheConfig(cacheNames = "customer-file-type")
public class CustomerFileTypeService implements IEntityService<CustomerFileTypeLocal>, QueryService<CustomerFileTypeLocal>,
public class CustomerFileTypeService implements IEntityService<CustomerFileTypeLocal>, QueryService<CustomerFileTypeLocalVo>,
VoableService<CustomerFileTypeLocal, CustomerFileTypeLocalVo> {
@Lazy
@Autowired
private CustomerFileTypeLocalRepository repository;
@Override
public Page<CustomerFileTypeLocal> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<CustomerFileTypeLocalVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<CustomerFileTypeLocal> spec = null;
if (paramsNode.has(ServiceConstant.KEY_SEARCH_TEXT)) {
spec = getSpecification(paramsNode.get(ServiceConstant.KEY_SEARCH_TEXT).asText());
@@ -50,12 +51,16 @@ public class CustomerFileTypeService implements IEntityService<CustomerFileTypeL
// field
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "lang", "value");
return findAll(spec, pageable);
return findAll(spec, pageable).map(CustomerFileTypeLocal::toVo);
}
@Cacheable(key = "#p0")
@Override
public CustomerFileTypeLocal findById(Integer id) {
public CustomerFileTypeLocalVo findById(Integer id) {
return repository.findById(id).map(CustomerFileTypeLocal::toVo).orElse(null);
}
public CustomerFileTypeLocal getById(Integer id) {
return repository.findById(id).orElse(null);
}
@@ -65,8 +70,12 @@ public class CustomerFileTypeService implements IEntityService<CustomerFileTypeL
}
@Cacheable(key = "'all-'+#p0.toLanguageTag()")
public Map<CustomerFileType, CustomerFileTypeLocal> findAll(Locale locale) {
return repository.getCompleteMapByLocal(locale.toLanguageTag());
public Map<CustomerFileType, CustomerFileTypeLocalVo> findAll(Locale locale) {
return repository.getCompleteMapByLocal(locale.toLanguageTag()).entrySet().stream()
.collect(java.util.stream.Collectors.toMap(
java.util.Map.Entry::getKey,
entry -> entry.getValue().toVo()
));
}
@Override

View File

@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RestController;
import com.ecep.contract.ds.other.service.BankService;
import com.ecep.contract.model.Bank;
import com.ecep.contract.vo.BankVo;
@RestController
@RequestMapping("/bank")
@@ -22,12 +23,12 @@ public class BankController {
private BankService bankService;
@RequestMapping("/findById")
public Bank findById(Integer id) {
public BankVo findById(Integer id) {
return bankService.findById(id);
}
@RequestMapping("/list")
public Page<Bank> list(
public Page<BankVo> list(
Map<String, Object> params,
@RequestParam(defaultValue = "0", name = "page") int pageNumber,
@RequestParam(defaultValue = "10", name = "size") int pageSize) {
@@ -35,17 +36,19 @@ public class BankController {
Sort sort = Sort.by(Sort.Order.desc("id"));
Pageable pageable = PageRequest.of(pageNumber, pageSize, sort);
// PagedModel<Bank> pagedModel = new PagedModel<>();
return bankService.findAll(spec, pageable);
return bankService.findAll(spec, pageable).map(Bank::toVo);
}
@RequestMapping("/save")
public Bank save(Bank bank) {
return bankService.save(bank);
public BankVo save(BankVo bank) {
var v1 = bankService.getById(bank.getId());
bankService.updateByVo(v1, bank);
return bankService.save(v1).toVo();
}
@RequestMapping("/delete")
public void delete(Integer id) {
Bank bank = bankService.findById(id);
Bank bank = bankService.getById(id);
bankService.delete(bank);
}
}

View File

@@ -8,43 +8,50 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ecep.contract.cloud.u8.YongYouU8Service;
import com.ecep.contract.model.CloudYu;
import com.ecep.contract.vo.CloudYuVo;
@RestController
@RequestMapping("/cloudYu")
@RequestMapping("/cloud/yu")
public class CloudYuController {
@Autowired
private YongYouU8Service yongYouU8Service;
@RequestMapping("/findById")
public CloudYu findById(Integer id) {
@RequestMapping("/{id:\\d+}")
public CloudYuVo findById(@PathVariable Integer id) {
return yongYouU8Service.findById(id);
}
@RequestMapping("/list")
public Page<CloudYu> list(
public Page<CloudYuVo> list(
Map<String, Object> params,
@RequestParam(defaultValue = "0", name = "page") int pageNumber,
@RequestParam(defaultValue = "10", name = "size") int pageSize) {
Specification<CloudYu> spec = null;
Sort sort = Sort.by(Sort.Order.desc("id"));
Pageable pageable = PageRequest.of(pageNumber, pageSize, sort);
return yongYouU8Service.findAll(spec, pageable);
return yongYouU8Service.findAll((Specification<CloudYu>) null, pageable).map(CloudYu::toVo);
}
@RequestMapping("/save")
public CloudYu save(CloudYu cloudYu) {
@PostMapping("/save")
public CloudYu save(CloudYuVo cloudYuVo) {
CloudYu cloudYu = yongYouU8Service.getById(cloudYuVo.getId());
yongYouU8Service.updateByVo(cloudYu, cloudYuVo);
return yongYouU8Service.save(cloudYu);
}
@RequestMapping("/delete")
public void delete(Integer id) {
CloudYu cloudYu = yongYouU8Service.findById(id);
@PostMapping("/delete/{id:\\d+}")
public void delete(@PathVariable Integer id) {
if (id == null) {
return;
}
CloudYu cloudYu = yongYouU8Service.getById(id);
yongYouU8Service.delete(cloudYu);
}
}

View File

@@ -1,9 +1,7 @@
package com.ecep.contract.ds.other.controller;
import java.util.Map;
import java.util.HashMap;
import jakarta.servlet.http.HttpSession;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
@@ -12,6 +10,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@@ -19,6 +18,9 @@ import org.springframework.web.bind.annotation.RestController;
import com.ecep.contract.ds.other.service.EmployeeService;
import com.ecep.contract.model.Employee;
import com.ecep.contract.util.SecurityUtils;
import com.ecep.contract.vo.EmployeeVo;
import jakarta.servlet.http.HttpSession;
@RestController
@RequestMapping("/employee")
@@ -27,12 +29,12 @@ public class EmployeeController {
private EmployeeService employeeService;
@RequestMapping("/findById")
public Employee findById(Integer id) {
public EmployeeVo findById(Integer id) {
return employeeService.findById(id);
}
@RequestMapping("/list")
public Page<Employee> list(
public Page<EmployeeVo> list(
Map<String, Object> params,
@RequestParam(defaultValue = "0", name = "page") int pageNumber,
@RequestParam(defaultValue = "10", name = "size") int pageSize) {
@@ -40,17 +42,19 @@ public class EmployeeController {
Sort sort = Sort.by(Sort.Order.desc("id"));
Pageable pageable = PageRequest.of(pageNumber, pageSize, sort);
return employeeService.findAll(spec, pageable);
return employeeService.findAll(spec, pageable).map(Employee::toVo);
}
@RequestMapping("/save")
public Employee save(Employee employee) {
return employeeService.save(employee);
@PostMapping("/save")
public EmployeeVo save(EmployeeVo employee) {
var v1 = employeeService.getById(employee.getId());
employeeService.updateByVo(v1, employee);
return employeeService.save(v1).toVo();
}
@RequestMapping("/delete")
public void delete(Integer id) {
Employee employee = employeeService.findById(id);
Employee employee = employeeService.getById(id);
employeeService.delete(employee);
}
@@ -61,13 +65,13 @@ public class EmployeeController {
@RequestMapping("/currentUser")
public Map<String, Object> getCurrentUser(HttpSession session) {
Map<String, Object> result = new HashMap<>();
try {
// 获取当前登录用户
User currentUser = SecurityUtils.getCurrentUser();
if (currentUser != null) {
// 根据用户名查找Employee对象
Employee employee = employeeService.findByName(currentUser.getUsername());
EmployeeVo employee = employeeService.findByName(currentUser.getUsername());
if (employee != null) {
result.put("employeeId", employee.getId());
result.put("sessionId", session.getId());
@@ -78,7 +82,7 @@ public class EmployeeController {
} catch (Exception e) {
// 处理异常
}
// 如果获取失败,返回错误信息
result.put("success", false);
result.put("error", "无法获取当前用户信息");

View File

@@ -17,20 +17,21 @@ import com.ecep.contract.ds.other.service.EmployeeRoleService;
import com.ecep.contract.model.EmployeeRole;
import com.ecep.contract.util.SecurityUtils;
import com.ecep.contract.util.SpecificationUtils;
import com.ecep.contract.vo.EmployeeRoleVo;
@RestController
@RequestMapping("/employeeRole")
@RequestMapping("/employee/role")
public class EmployeeRoleController {
@Autowired
private EmployeeRoleService employeeRoleService;
@RequestMapping("/findById")
public EmployeeRole findById(Integer id) {
return employeeRoleService.findById(id);
return employeeRoleService.getById(id);
}
@RequestMapping("/list")
public Page<EmployeeRole> list(
public Page<EmployeeRoleVo> list(
Map<String, Object> params,
@RequestParam(defaultValue = "0", name = "page") int pageNumber,
@RequestParam(defaultValue = "10", name = "size") int pageSize) {
@@ -41,14 +42,12 @@ public class EmployeeRoleController {
String searchText = (String) params.get("searchText");
if (StringUtils.hasText(searchText)) {
spec = SpecificationUtils.andWith(searchText, (text) -> (root, query, cb) -> {
return cb.like(root.get("name"), "%" + text + "%");
});
spec = SpecificationUtils.and(spec, employeeRoleService.getSpecification(searchText));
}
Sort sort = Sort.by(Sort.Order.desc("id"));
Pageable pageable = PageRequest.of(pageNumber, pageSize, sort);
return employeeRoleService.findAll(spec, pageable);
return employeeRoleService.findAll(spec, pageable).map(EmployeeRole::toVo);
}
@RequestMapping("/save")
@@ -66,7 +65,7 @@ public class EmployeeRoleController {
if (!SecurityUtils.currentUserHasRole("ROLE_ADMIN")) {
throw new SecurityException("无权限执行此操作");
}
EmployeeRole role = employeeRoleService.findById(id);
EmployeeRole role = employeeRoleService.getById(id);
if (role != null && role.isSystemAdministrator()) {
throw new SecurityException("不能删除系统管理员角色");
}

View File

@@ -7,11 +7,10 @@ import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Repository;
import com.ecep.contract.ds.MyRepository;
import com.ecep.contract.model.Employee;
import com.ecep.contract.model.EmployeeAuthBind;
@Lazy
@Repository
public interface EmployeeAuthBindRepository extends MyRepository<EmployeeAuthBind, Integer> {
List<EmployeeAuthBind> findAllByEmployee(Employee employee, Sort sort);
List<EmployeeAuthBind> findAllByEmployeeId(Integer employeeId, Sort sort);
}

View File

@@ -1,6 +1,7 @@
package com.ecep.contract.ds.other.service;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
@@ -25,13 +26,17 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "bank")
public class BankService implements IEntityService<Bank>, QueryService<Bank>, VoableService<Bank, BankVo> {
public class BankService implements IEntityService<Bank>, QueryService<BankVo>, VoableService<Bank, BankVo> {
@Lazy
@Autowired
private BankRepository bankRepository;
@Cacheable(key = "#id")
public Bank findById(Integer id) {
public BankVo findById(Integer id) {
return bankRepository.findById(id).map(Bank::toVo).orElse(null);
}
public Bank getById(Integer id) {
return bankRepository.findById(id).orElse(null);
}
@@ -40,13 +45,13 @@ public class BankService implements IEntityService<Bank>, QueryService<Bank>, Vo
}
@Override
public Page<Bank> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<BankVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<Bank> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
}
// 可以根据需要添加更多参数处理
return findAll(spec, pageable);
return findAll(spec, pageable).map(Bank::toVo);
}

View File

@@ -16,8 +16,10 @@ import org.springframework.util.StringUtils;
import com.ecep.contract.IEntityService;
import com.ecep.contract.QueryService;
import com.ecep.contract.SpringApp;
import com.ecep.contract.ds.other.repository.DepartmentRepository;
import com.ecep.contract.model.Department;
import com.ecep.contract.model.Employee;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.vo.DepartmentVo;
import com.fasterxml.jackson.databind.JsonNode;
@@ -28,14 +30,18 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "department")
public class DepartmentService implements IEntityService<Department>, QueryService<Department>, VoableService<Department, DepartmentVo> {
public class DepartmentService implements IEntityService<Department>, QueryService<DepartmentVo>, VoableService<Department, DepartmentVo> {
@Lazy
@Autowired
private DepartmentRepository repository;
@Cacheable(key = "#p0")
@Override
public Department findById(Integer id) {
public DepartmentVo findById(Integer id) {
return repository.findById(id).map(Department::toVo).orElse(null);
}
public Department getById(Integer id) {
return repository.findById(id).orElse(null);
}
@@ -50,13 +56,13 @@ public class DepartmentService implements IEntityService<Department>, QueryServi
}
@Override
public Page<Department> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<DepartmentVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<Department> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
}
// 可以根据需要添加更多参数处理
return findAll(spec, pageable);
return findAll(spec, pageable).map(Department::toVo);
}
@Override
@@ -100,7 +106,16 @@ public class DepartmentService implements IEntityService<Department>, QueryServi
department.setCode(vo.getCode());
department.setName(vo.getName());
department.setActive(vo.isActive());
// 处理leader字段需要将leaderId转换为Employee对象
// 这里暂时不实现因为需要依赖EmployeeService
// 处理leader字段
if (vo.getLeaderId() == null) {
department.setLeader(null);
} else {
EmployeeService employeeService = SpringApp.getBean(EmployeeService.class);
if (department.getLeader() == null || !department.getLeader().getId().equals(vo.getLeaderId())) {
Employee leader = employeeService.getById(vo.getLeaderId());
department.setLeader(leader);
}
}
}
}

View File

@@ -1,6 +1,7 @@
package com.ecep.contract.ds.other.service;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
@@ -21,19 +22,24 @@ import com.ecep.contract.model.EmployeeAuthBind;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.util.SpecificationUtils;
import com.ecep.contract.vo.EmployeeAuthBindVo;
import com.ecep.contract.vo.EmployeeVo;
import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "employee-auth-bind")
public class EmployeeAuthBindService implements IEntityService<EmployeeAuthBind>, QueryService<EmployeeAuthBind>,
public class EmployeeAuthBindService implements IEntityService<EmployeeAuthBind>, QueryService<EmployeeAuthBindVo>,
VoableService<EmployeeAuthBind, EmployeeAuthBindVo> {
@Lazy
@Autowired
private EmployeeAuthBindRepository repository;
@Override
public EmployeeAuthBind findById(Integer id) {
public EmployeeAuthBindVo findById(Integer id) {
return repository.findById(id).map(EmployeeAuthBind::toVo).orElse(null);
}
public EmployeeAuthBind getById(Integer id) {
return repository.findById(id).orElse(null);
}
@@ -56,14 +62,14 @@ public class EmployeeAuthBindService implements IEntityService<EmployeeAuthBind>
}
@Override
public Page<EmployeeAuthBind> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<EmployeeAuthBindVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<EmployeeAuthBind> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
}
// 可以根据需要添加更多参数处理
spec = SpecificationUtils.andParam(spec, paramsNode, "employee");
return findAll(spec, pageable);
return findAll(spec, pageable).map(EmployeeAuthBind::toVo);
}
@Override
@@ -77,7 +83,11 @@ public class EmployeeAuthBindService implements IEntityService<EmployeeAuthBind>
}
public List<EmployeeAuthBind> findAllByEmployee(Employee employee, Sort sort) {
return repository.findAllByEmployee(employee, sort);
return repository.findAllByEmployeeId(employee.getId(), sort);
}
public List<EmployeeAuthBind> findAllByEmployee(EmployeeVo employee, Sort sort) {
return repository.findAllByEmployeeId(employee.getId(), sort);
}
@Override
@@ -91,17 +101,22 @@ public class EmployeeAuthBindService implements IEntityService<EmployeeAuthBind>
// employee和updater属性需要通过ID查找对应的实体
EmployeeService employeeService = SpringApp.getBean(EmployeeService.class);
if (vo.getEmployeeId() != null) {
Employee employee = employeeService.findById(vo.getEmployeeId());
model.setEmployee(employee);
} else {
if (vo.getEmployeeId() == null) {
model.setEmployee(null);
}
if (vo.getUpdaterId() != null) {
Employee updater = employeeService.findById(vo.getUpdaterId());
model.setUpdater(updater);
} else {
if (model.getEmployee() == null || !model.getEmployee().getId().equals(vo.getEmployeeId())) {
Employee employee = employeeService.getById(vo.getEmployeeId());
model.setEmployee(employee);
}
}
if (vo.getUpdaterId() == null) {
model.setUpdater(null);
} else {
if (model.getUpdater() == null || !model.getUpdater().getId().equals(vo.getUpdaterId())) {
Employee updater = employeeService.getById(vo.getUpdaterId());
model.setUpdater(updater);
}
}
}
}

View File

@@ -1,5 +1,7 @@
package com.ecep.contract.ds.other.service;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.context.annotation.Lazy;
@@ -24,14 +26,18 @@ import com.fasterxml.jackson.databind.JsonNode;
@Service
@CacheConfig(cacheNames = "employee-login-history")
public class EmployeeLoginHistoryService
implements IEntityService<EmployeeLoginHistory>, QueryService<EmployeeLoginHistory>,
implements IEntityService<EmployeeLoginHistory>, QueryService<EmployeeLoginHistoryVo>,
VoableService<EmployeeLoginHistory, EmployeeLoginHistoryVo> {
@Lazy
@Autowired
private EmployeeLoginHistoryRepository repository;
@Override
public EmployeeLoginHistory findById(Integer id) {
public EmployeeLoginHistoryVo findById(Integer id) {
return repository.findById(id).map(EmployeeLoginHistory::toVo).orElse(null);
}
public EmployeeLoginHistory getById(Integer id) {
return repository.findById(id).orElse(null);
}
@@ -53,7 +59,7 @@ public class EmployeeLoginHistoryService
}
@Override
public Page<EmployeeLoginHistory> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<EmployeeLoginHistoryVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<EmployeeLoginHistory> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
@@ -61,7 +67,7 @@ public class EmployeeLoginHistoryService
// 可以根据需要添加更多参数处理
spec = SpecificationUtils.andParam(spec, paramsNode, "employee");
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "ip", "mac");
return findAll(spec, pageable);
return findAll(spec, pageable).map(EmployeeLoginHistory::toVo);
}
@Override
@@ -87,7 +93,10 @@ public class EmployeeLoginHistoryService
if (vo.getEmployeeId() == null) {
model.setEmployee(null);
} else {
model.setEmployee(SpringApp.getBean(EmployeeService.class).findById(vo.getEmployeeId()));
EmployeeService service = SpringApp.getBean(EmployeeService.class);
if (model.getEmployee() == null || !model.getEmployee().getId().equals(vo.getEmployeeId())) {
model.setEmployee(service.getById(vo.getEmployeeId()));
}
}
model.setIp(vo.getIp());
model.setMac(vo.getMac());

View File

@@ -31,14 +31,18 @@ import jakarta.transaction.Transactional;
*/
@Service
@CacheConfig(cacheNames = "employee-role")
public class EmployeeRoleService implements IEntityService<EmployeeRole>, QueryService<EmployeeRole>,
public class EmployeeRoleService implements IEntityService<EmployeeRole>, QueryService<EmployeeRoleVo>,
VoableService<EmployeeRole, EmployeeRoleVo> {
@Lazy
@Autowired
private EmployeeRoleRepository roleRepository;
@Cacheable(key = "#p0")
public EmployeeRole findById(Integer id) {
public EmployeeRoleVo findById(Integer id) {
return roleRepository.findById(id).map(EmployeeRole::toVo).orElse(null);
}
public EmployeeRole getById(Integer id) {
return roleRepository.findById(id).orElse(null);
}
@@ -81,13 +85,13 @@ public class EmployeeRoleService implements IEntityService<EmployeeRole>, QueryS
}
@Override
public Page<EmployeeRole> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<EmployeeRoleVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<EmployeeRole> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
}
// 可以根据需要添加更多参数处理
return findAll(spec, pageable);
return findAll(spec, pageable).map(EmployeeRole::toVo);
}
@Transactional

View File

@@ -1,16 +1,8 @@
package com.ecep.contract.ds.other.service;
import com.ecep.contract.IEntityService;
import com.ecep.contract.QueryService;
import com.ecep.contract.SpringApp;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.ds.other.repository.EmployeeRepository;
import com.ecep.contract.model.Employee;
import com.ecep.contract.model.EmployeeRole;
import com.ecep.contract.vo.EmployeeVo;
import com.ecep.contract.util.SpecificationUtils;
import com.fasterxml.jackson.databind.JsonNode;
import jakarta.transaction.Transactional;
import java.util.List;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -25,8 +17,19 @@ import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.List;
import java.util.Optional;
import com.ecep.contract.IEntityService;
import com.ecep.contract.QueryService;
import com.ecep.contract.SpringApp;
import com.ecep.contract.ds.other.repository.EmployeeRepository;
import com.ecep.contract.model.Department;
import com.ecep.contract.model.Employee;
import com.ecep.contract.model.EmployeeRole;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.util.SpecificationUtils;
import com.ecep.contract.vo.EmployeeVo;
import com.fasterxml.jackson.databind.JsonNode;
import jakarta.transaction.Transactional;
/**
* 员工服务类
@@ -35,7 +38,7 @@ import java.util.Optional;
@Service
@CacheConfig(cacheNames = "employee")
public class EmployeeService
implements IEntityService<Employee>, QueryService<Employee>, VoableService<Employee, EmployeeVo> {
implements IEntityService<Employee>, QueryService<EmployeeVo>, VoableService<Employee, EmployeeVo> {
private static final Logger logger = LoggerFactory.getLogger(EmployeeService.class);
public static final int DEFAULT_SYSTEM_EMPLOYEE_ID = 26;
@Lazy
@@ -49,17 +52,21 @@ public class EmployeeService
* 如果不存在则从数据库中查询,并将查询结果存入缓存中,以便下次查询时可以直接从缓存中获取。
*
* @param id 员工的唯一标识符类型为Integer。
* @return 返回与指定ID对应的Employee对象。如果数据库中不存在该ID对应的员工信息则返回null。
* @return 返回与指定ID对应的EmployeeVo对象。如果数据库中不存在该ID对应的员工信息则返回null。
*/
@Cacheable(key = "#p0")
public Employee findById(Integer id) {
public EmployeeVo findById(Integer id) {
// 从员工仓库中根据ID查找员工信息如果不存在则返回null
return employeeRepository.findById(id).map(Employee::toVo).orElse(null);
}
public Employee getById(Integer id) {
return employeeRepository.findById(id).orElse(null);
}
@Cacheable(key = "'ac-'+#p0")
public Employee findByAccount(String username) {
return employeeRepository.findByAccount(username).orElse(null);
public EmployeeVo findByAccount(String username) {
return employeeRepository.findByAccount(username).map(Employee::toVo).orElse(null);
}
/**
@@ -67,15 +74,15 @@ public class EmployeeService
* @return
*/
@Cacheable(key = "'name-'+#p0")
public Employee findByName(String name) {
return employeeRepository.findByName(name).orElseGet(() -> {
return employeeRepository.findByAlias(name).orElse(null);
public EmployeeVo findByName(String name) {
return employeeRepository.findByName(name).map(Employee::toVo).orElseGet(() -> {
return employeeRepository.findByAlias(name).map(Employee::toVo).orElse(null);
});
}
@Cacheable(key = "'code-'+#p0")
public Employee findByCode(String personCode) {
return employeeRepository.findByCode(personCode).orElse(null);
public EmployeeVo findByCode(String personCode) {
return employeeRepository.findByCode(personCode).map(Employee::toVo).orElse(null);
}
/**
@@ -116,7 +123,7 @@ public class EmployeeService
}
@Override
public Page<Employee> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<EmployeeVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<Employee> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
@@ -124,7 +131,7 @@ public class EmployeeService
// 可以根据需要添加更多参数处理
spec = SpecificationUtils.andParam(spec, paramsNode, "department");
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "isActive");
return findAll(spec, pageable);
return findAll(spec, pageable).map(Employee::toVo);
}
@Override
@@ -176,7 +183,14 @@ public class EmployeeService
entity.setAccount(vo.getAccount());
entity.setAlias(vo.getAlias());
entity.setCode(vo.getCode());
entity.setDepartment(SpringApp.getBean(DepartmentService.class).findById(vo.getDepartmentId()));
if (vo.getDepartmentId() != null) {
if(entity.getDepartment()==null || !entity.getDepartment().getId().equals(vo.getDepartmentId())){
Department department = SpringApp.getBean(DepartmentService.class).getById(vo.getDepartmentId());
entity.setDepartment(department);
}
} else {
entity.setDepartment(null);
}
entity.setPhone(vo.getPhone());
entity.setEmail(vo.getEmail());
entity.setCreated(vo.getCreated());

View File

@@ -1,5 +1,7 @@
package com.ecep.contract.ds.other.service;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
@@ -23,13 +25,17 @@ import com.ecep.contract.vo.FunctionVo;
@Lazy
@Service
@CacheConfig(cacheNames = "function")
public class FunctionService implements IEntityService<Function>, QueryService<Function>, VoableService<Function, FunctionVo> {
public class FunctionService implements IEntityService<Function>, QueryService<FunctionVo>, VoableService<Function, FunctionVo> {
@Lazy
@Autowired
private FunctionRepository repository;
@Cacheable(key = "#p0")
public Function findById(Integer id) {
public FunctionVo findById(Integer id) {
return repository.findById(id).map(Function::toVo).orElse(null);
}
public Function getById(Integer id) {
return repository.findById(id).orElse(null);
}
@@ -53,13 +59,13 @@ public class FunctionService implements IEntityService<Function>, QueryService<F
}
@Override
public Page<Function> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<FunctionVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<Function> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
}
// 可以根据需要添加更多参数处理
return findAll(spec, pageable);
return findAll(spec, pageable).map(Function::toVo);
}
@Override

View File

@@ -1,6 +1,7 @@
package com.ecep.contract.ds.other.service;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
@@ -18,18 +19,25 @@ import com.ecep.contract.IEntityService;
import com.ecep.contract.QueryService;
import com.ecep.contract.ds.other.repository.InventoryCatalogRepository;
import com.ecep.contract.model.InventoryCatalog;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.vo.InventoryCatalogVo;
import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "inventory-catalog")
public class InventoryCatalogService implements IEntityService<InventoryCatalog>, QueryService<InventoryCatalog> {
public class InventoryCatalogService implements IEntityService<InventoryCatalog>, QueryService<InventoryCatalogVo>,
VoableService<InventoryCatalog, InventoryCatalogVo> {
@Lazy
@Autowired
private InventoryCatalogRepository repository;
@Cacheable(key = "#p0")
public InventoryCatalog findById(Integer id) {
public InventoryCatalogVo findById(Integer id) {
return repository.findById(id).map(InventoryCatalog::toVo).orElse(null);
}
public InventoryCatalog getById(Integer id) {
return repository.findById(id).orElse(null);
}
@@ -49,13 +57,13 @@ public class InventoryCatalogService implements IEntityService<InventoryCatalog>
}
@Override
public Page<InventoryCatalog> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<InventoryCatalogVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<InventoryCatalog> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
}
// 可以根据需要添加更多参数处理
return findAll(spec, pageable);
return findAll(spec, pageable).map(InventoryCatalog::toVo);
}
@Override
@@ -96,4 +104,11 @@ public class InventoryCatalogService implements IEntityService<InventoryCatalog>
public void delete(InventoryCatalog entity) {
repository.delete(entity);
}
@Override
public void updateByVo(InventoryCatalog model, InventoryCatalogVo vo) {
model.setCode(vo.getCode());
model.setName(vo.getName());
// 其他属性根据实际需要添加
}
}

View File

@@ -1,6 +1,7 @@
package com.ecep.contract.ds.other.service;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
@@ -26,7 +27,7 @@ import jakarta.persistence.criteria.Path;
@Service
@CacheConfig(cacheNames = "inventory-history-price")
public class InventoryHistoryPriceService
implements IEntityService<InventoryHistoryPrice>, QueryService<InventoryHistoryPrice>,
implements IEntityService<InventoryHistoryPrice>, QueryService<InventoryHistoryPriceVo>,
VoableService<InventoryHistoryPrice, InventoryHistoryPriceVo> {
@Lazy
@Autowired
@@ -37,7 +38,11 @@ public class InventoryHistoryPriceService
InventoryService inventoryService;
@Override
public InventoryHistoryPrice findById(Integer id) {
public InventoryHistoryPriceVo findById(Integer id) {
return repository.findById(id).map(InventoryHistoryPrice::toVo).orElse(null);
}
public InventoryHistoryPrice getById(Integer id) {
return repository.findById(id).orElse(null);
}
@@ -60,13 +65,13 @@ public class InventoryHistoryPriceService
}
@Override
public Page<InventoryHistoryPrice> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<InventoryHistoryPriceVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<InventoryHistoryPrice> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
}
// 可以根据需要添加更多参数处理
return findAll(spec, pageable);
return findAll(spec, pageable).map(InventoryHistoryPrice::toVo);
}
public List<InventoryHistoryPrice> findAllByInventory(Inventory inventory) {
@@ -90,10 +95,14 @@ public class InventoryHistoryPriceService
}
// 映射基本属性
if (vo.getInventoryId() != null) {
Inventory inventory = inventoryService.findById(vo.getInventoryId());
if (inventory != null) {
entity.setInventory(inventory);
if (vo.getInventoryId() == null) {
entity.setInventory(null);
} else {
if (entity.getInventory() == null || !entity.getInventory().getId().equals(vo.getInventoryId())) {
Inventory inventory = inventoryService.getById(vo.getInventoryId());
if (inventory != null) {
entity.setInventory(inventory);
}
}
}
@@ -118,7 +127,6 @@ public class InventoryHistoryPriceService
entity.getMiniPurchasePrice().setTaxRate(vo.getMiniPurchasePrice().getTaxRate());
entity.getMiniPurchasePrice().setPreTaxPrice(vo.getMiniPurchasePrice().getPreTaxPrice());
entity.getMiniPurchasePrice().setPostTaxPrice(vo.getMiniPurchasePrice().getPostTaxPrice());
entity.getMiniPurchasePrice().setMonthDay(vo.getMiniPurchasePrice().getMonthDay());
}
if (vo.getMiniSalePrice() != null) {

View File

@@ -37,7 +37,7 @@ import lombok.Setter;
@Service
@CacheConfig(cacheNames = "inventory")
public class InventoryService
implements IEntityService<Inventory>, QueryService<Inventory>, VoableService<Inventory, InventoryVo> {
implements IEntityService<Inventory>, QueryService<InventoryVo>, VoableService<Inventory, InventoryVo> {
@Lazy
@Autowired
private InventoryRepository inventoryRepository;
@@ -46,7 +46,11 @@ public class InventoryService
private int searchPageSize = 10;
@Cacheable(key = "#p0")
public Inventory findById(Integer id) {
public InventoryVo findById(Integer id) {
return inventoryRepository.findById(id).map(Inventory::toVo).orElse(null);
}
public Inventory getById(Integer id) {
return inventoryRepository.findById(id).orElse(null);
}
@@ -56,13 +60,13 @@ public class InventoryService
}
@Override
public Page<Inventory> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<InventoryVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<Inventory> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
}
// 可以根据需要添加更多参数处理
return findAll(spec, pageable);
return findAll(spec, pageable).map(Inventory::toVo);
}
@Override
@@ -144,9 +148,14 @@ public class InventoryService
// 映射基本属性
if (vo.getCatalogId() != null) {
InventoryCatalog catalog = SpringApp.getBean(InventoryCatalogService.class).findById(vo.getCatalogId());
entity.setCatalog(catalog);
if (entity.getCatalog() == null || !entity.getCatalog().getId().equals(vo.getCatalogId())) {
InventoryCatalog catalog = SpringApp.getBean(InventoryCatalogService.class).getById(vo.getCatalogId());
entity.setCatalog(catalog);
}
} else {
entity.setCatalog(null);
}
entity.setCode(vo.getCode());
entity.setSpecification(vo.getSpecification());
@@ -197,14 +206,22 @@ public class InventoryService
EmployeeService employeeService = SpringApp.getBean(EmployeeService.class);
entity.setCreateTime(vo.getCreateTime());
if (vo.getCreatorId() != null) {
Employee creator = employeeService.findById(vo.getCreatorId());
entity.setCreator(creator);
if (vo.getCreatorId() == null) {
entity.setCreator(null);
} else {
if (entity.getCreator() == null || !entity.getCreator().getId().equals(vo.getCreatorId())) {
Employee creator = employeeService.getById(vo.getCreatorId());
entity.setCreator(creator);
}
}
entity.setUpdateDate(vo.getUpdateDate());
if (vo.getUpdaterId() != null) {
Employee updater = employeeService.findById(vo.getUpdaterId());
entity.setUpdater(updater);
if (vo.getUpdaterId() == null) {
entity.setUpdater(null);
} else {
if (entity.getUpdater() == null || !entity.getUpdater().getId().equals(vo.getUpdaterId())) {
Employee updater = employeeService.getById(vo.getUpdaterId());
entity.setUpdater(updater);
}
}
// 忽略active属性因为实体中没有这个属性

View File

@@ -28,7 +28,8 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "permission")
public class PermissionService implements IEntityService<Permission>, QueryService<Permission>, VoableService<Permission, PermissionVo> {
public class PermissionService
implements IEntityService<Permission>, QueryService<PermissionVo>, VoableService<Permission, PermissionVo> {
@Lazy
@Autowired
@@ -37,7 +38,11 @@ public class PermissionService implements IEntityService<Permission>, QueryServi
/*
*/
@Cacheable(key = "'permission-'+#p0")
public Permission findById(Integer id) {
public PermissionVo findById(Integer id) {
return permissionRepository.findById(id).map(Permission::toVo).orElse(null);
}
public Permission getById(Integer id) {
return permissionRepository.findById(id).orElse(null);
}
@@ -72,13 +77,13 @@ public class PermissionService implements IEntityService<Permission>, QueryServi
}
@Override
public Page<Permission> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<PermissionVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<Permission> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
}
// 可以根据需要添加更多参数处理
return findAll(spec, pageable);
return findAll(spec, pageable).map(Permission::toVo);
}
@Override
@@ -95,19 +100,23 @@ public class PermissionService implements IEntityService<Permission>, QueryServi
// 映射基本属性
permission.setName(vo.getName());
permission.setKey(vo.getKey());
// 处理关联对象 function
if (vo.getFunctionId() != null) {
if (vo.getFunctionId() == null) {
permission.setFunction(null);
} else {
try {
Function function = SpringApp.getBean(FunctionService.class).findById(vo.getFunctionId());
if (function != null) {
permission.setFunction(function);
if (permission.getFunction() == null || !permission.getFunction().getId().equals(vo.getFunctionId())) {
Function function = SpringApp.getBean(FunctionService.class).getById(vo.getFunctionId());
if (function != null) {
permission.setFunction(function);
}
}
} catch (Exception e) {
throw new ServiceException("Failed to find Function: " + e.getMessage(), e);
}
}
// PermissionVo中的description和active字段在Permission实体中不存在这里不做处理
// 如果需要处理,可以添加日志记录或者其他逻辑
}

View File

@@ -29,7 +29,7 @@ public class ProjectCtx extends AbstractCtx {
if (!Objects.equals(project.getCustomer(), customer)) {
project.setCustomer(customer);
if (!Hibernate.isInitialized(customer)) {
customer = getCompanyService().findById(customer.getId());
customer = getCompanyService().getById(customer.getId());
}
holder.info("同步合同所属项目客户为:" + customer.getName());
modified = true;
@@ -42,7 +42,7 @@ public class ProjectCtx extends AbstractCtx {
if (Hibernate.isInitialized(project)) {
return project;
}
return getProjectService().findById(project.getId());
return getProjectService().getById(project.getId());
}
public Project save(Project project) {

View File

@@ -10,13 +10,16 @@ import com.ecep.contract.model.DeliverySignMethod;
import com.ecep.contract.model.ProjectSaleType;
@Repository
public interface ProductDeliverySignMethodRepository extends MyRepository<DeliverySignMethod, Integer>{
public interface ProductDeliverySignMethodRepository extends MyRepository<DeliverySignMethod, Integer> {
Optional<DeliverySignMethod> findBySaleTypeAndName(ProjectSaleType saleType, String name);
Optional<DeliverySignMethod> findBySaleTypeAndCode(ProjectSaleType saleType, String code);
Optional<DeliverySignMethod> findBySaleTypeIdAndCode(Integer saleTypeId, String code);
Optional<DeliverySignMethod> findBySaleTypeAndId(ProjectSaleType saleType, Integer id);
List<DeliverySignMethod> findAllBySaleTypeId(Integer saleTypeId);
}

View File

@@ -12,18 +12,20 @@ import com.ecep.contract.model.ProjectSaleType;
public interface ProjectRepository extends
MyRepository<Project, Integer> {
Optional<Project> findFirstBySaleTypeAndCodeYearOrderByCodeSequenceNumberDesc(ProjectSaleType type, int year);
/**
* 根据销售类型、年、序号查询项目
*
* @param type 销售类型
* @param saleTypeId 销售类型ID
* @param year 年份
* @param sequenceNumber 序号
* @return 项目
*
* @see ProjectSaleType
*/
Optional<Project> findBySaleTypeAndCodeYearAndCodeSequenceNumber(ProjectSaleType type, int year, int sequenceNumber);
Optional<Project> findBySaleTypeIdAndCodeYearAndCodeSequenceNumber(Integer saleTypeId, int year,
int sequenceNumber);
Optional<Project> findByName(String name);

View File

@@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;
import com.ecep.contract.model.ProjectSaleType;
import com.ecep.contract.model.ProjectSaleTypeRequireFileType;
@Repository
@@ -14,4 +15,6 @@ public interface ProjectSaleTypeRequireFileTypeRepository extends
JpaSpecificationExecutor<ProjectSaleTypeRequireFileType> {
List<ProjectSaleTypeRequireFileType> findBySaleTypeId(int saleTypeId);
List<ProjectSaleTypeRequireFileType> findBySaleType(ProjectSaleType saleType);
}

View File

@@ -3,6 +3,8 @@ package com.ecep.contract.ds.project.service;
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.context.annotation.Lazy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
@@ -29,21 +31,33 @@ import com.fasterxml.jackson.databind.JsonNode;
*/
@Lazy
@Service
@CacheConfig(cacheNames = "customer-satisfaction-survey")
public class CustomerSatisfactionSurveyService
implements IEntityService<CustomerSatisfactionSurvey>, QueryService<CustomerSatisfactionSurvey>,
implements IEntityService<CustomerSatisfactionSurvey>, QueryService<CustomerSatisfactionSurveyVo>,
VoableService<CustomerSatisfactionSurvey, CustomerSatisfactionSurveyVo> {
@Lazy
@Autowired
private CustomerSatisfactionSurveyRepository repository;
@Override
public CustomerSatisfactionSurvey getById(Integer id) {
return repository.findById(id).orElse(null);
}
/**
* 根据ID查找客户满意度调查
*
* @param id ID
* @return 客户满意度调查实体
*/
public CustomerSatisfactionSurvey findById(Integer id) {
return repository.findById(id).orElse(null);
@Cacheable(key = "#p0")
@Override
public CustomerSatisfactionSurveyVo findById(Integer id) {
CustomerSatisfactionSurvey survey = getById(id);
if (survey != null) {
return survey.toVo();
}
return null;
}
@Override
@@ -94,12 +108,13 @@ public class CustomerSatisfactionSurveyService
* @param spec 查询条件
* @return 客户满意度调查列表
*/
public List<CustomerSatisfactionSurvey> findAll(Specification<CustomerSatisfactionSurvey> spec) {
return repository.findAll(spec);
public List<CustomerSatisfactionSurveyVo> findAll(Specification<CustomerSatisfactionSurvey> spec) {
List<CustomerSatisfactionSurvey> entities = repository.findAll(spec);
return entities.stream().map(CustomerSatisfactionSurvey::toVo).toList();
}
@Override
public Page<CustomerSatisfactionSurvey> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<CustomerSatisfactionSurveyVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<CustomerSatisfactionSurvey> spec = null;
if (paramsNode.has(ServiceConstant.KEY_SEARCH_TEXT)) {
spec = getSpecification(paramsNode.get(ServiceConstant.KEY_SEARCH_TEXT).asText());
@@ -113,7 +128,8 @@ public class CustomerSatisfactionSurveyService
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "project", "applicant");
return findAll(spec, pageable);
Page<CustomerSatisfactionSurvey> page = findAll(spec, pageable);
return page.map(CustomerSatisfactionSurvey::toVo);
}
@Override
@@ -127,12 +143,12 @@ public class CustomerSatisfactionSurveyService
// 处理关联对象
if (vo.getProject() != null) {
Project project = SpringApp.getBean(ProjectService.class).findById(vo.getProject());
Project project = SpringApp.getBean(ProjectService.class).getById(vo.getProject());
model.setProject(project);
}
if (vo.getApplicantId() != null) {
Employee employee = SpringApp.getBean(EmployeeService.class).findById(vo.getApplicantId());
Employee employee = SpringApp.getBean(EmployeeService.class).getById(vo.getApplicantId());
model.setApplicant(employee);
}

View File

@@ -23,36 +23,49 @@ import com.ecep.contract.model.ProjectSaleType;
import com.ecep.contract.service.ServiceException;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.vo.DeliverySignMethodVo;
import com.ecep.contract.vo.ProjectSaleTypeVo;
import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "project-sign-method")
public class DeliverySignMethodService implements IEntityService<DeliverySignMethod>, QueryService<DeliverySignMethod>,
public class DeliverySignMethodService
implements IEntityService<DeliverySignMethod>, QueryService<DeliverySignMethodVo>,
VoableService<DeliverySignMethod, DeliverySignMethodVo> {
@Lazy
@Autowired
private ProductDeliverySignMethodRepository deliverySignMethodRepository;
@Cacheable(key = "#p0")
public DeliverySignMethod findById(Integer id) {
@Override
public DeliverySignMethod getById(Integer id) {
return deliverySignMethodRepository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
@Override
public DeliverySignMethodVo findById(Integer id) {
DeliverySignMethod method = getById(id);
if (method != null) {
return method.toVo();
}
return null;
}
@Override
public Page<DeliverySignMethod> findAll(Specification<DeliverySignMethod> spec, Pageable pageable) {
return deliverySignMethodRepository.findAll(spec, pageable);
}
@Override
public Page<DeliverySignMethod> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<DeliverySignMethodVo> 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);
Page<DeliverySignMethod> page = findAll(spec, pageable);
return page.map(DeliverySignMethod::toVo);
}
public DeliverySignMethod findBySaleTypeAndName(ProjectSaleType saleType, String name) {
@@ -64,6 +77,10 @@ public class DeliverySignMethodService implements IEntityService<DeliverySignMet
return deliverySignMethodRepository.findBySaleTypeAndCode(saleType, code).orElse(null);
}
public DeliverySignMethod findBySaleTypeAndCode(ProjectSaleTypeVo saleType, String code) {
return deliverySignMethodRepository.findBySaleTypeIdAndCode(saleType.getId(), code).orElse(null);
}
public List<DeliverySignMethod> findAll(Specification<DeliverySignMethod> spec, Sort sort) {
return deliverySignMethodRepository.findAll(spec, sort);
}
@@ -117,7 +134,7 @@ public class DeliverySignMethodService implements IEntityService<DeliverySignMet
if (vo.getSaleTypeId() != null) {
ProjectSaleTypeService saleTypeService = SpringApp.getBean(ProjectSaleTypeService.class);
entity.setSaleType(saleTypeService.findById(vo.getSaleTypeId()));
entity.setSaleType(saleTypeService.getById(vo.getSaleTypeId()));
} else {
entity.setSaleType(null);
}

View File

@@ -2,9 +2,6 @@ package com.ecep.contract.ds.project.service;
import java.util.List;
import com.ecep.contract.QueryService;
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;
@@ -18,53 +15,62 @@ import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import com.ecep.contract.IEntityService;
import com.ecep.contract.QueryService;
import com.ecep.contract.ds.project.repository.ProductTypeRepository;
import com.ecep.contract.model.ProductType;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.vo.ProductTypeVo;
import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "product-type")
public class ProductTypeService implements IEntityService<ProductType>, QueryService<ProductType>, VoableService<ProductType, ProductTypeVo> {
public class ProductTypeService implements IEntityService<ProductType>, QueryService<ProductTypeVo>,
VoableService<ProductType, ProductTypeVo> {
@Lazy
@Autowired
private ProductTypeRepository productTypeRepository;
@Cacheable(key = "#p0")
public ProductType findById(Integer id) {
@Override
public ProductType getById(Integer id) {
return productTypeRepository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
@Override
public ProductTypeVo findById(Integer id) {
return productTypeRepository.findById(id).map(ProductType::toVo).orElse(null);
}
@Cacheable(key = "'name-'+#p0")
public ProductType findByName(String name) {
return productTypeRepository.findByName(name).orElse(null);
}
@Cacheable(key = "'code-'+#p0")
public ProductType findByCode(String code) {
return productTypeRepository.findByCode(code).orElse(null);
public ProductTypeVo findByCode(String code) {
return productTypeRepository.findByCode(code).map(ProductType::toVo).orElse(null);
}
@Cacheable(key = "'all'")
public List<ProductType> findAll() {
return productTypeRepository.findAll();
public List<ProductTypeVo> findAll() {
return productTypeRepository.findAll().stream().map(ProductType::toVo).toList();
}
@Override
public Page<ProductType> findAll(Specification<ProductType> spec, Pageable pageable) {
return productTypeRepository.findAll(spec, pageable);
}
@Override
public Page<ProductType> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<ProductTypeVo> 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);
// spec = SpecificationUtils.andParam(spec, paramsNode, "company");
return findAll(spec, pageable).map(ProductType::toVo);
}
@Override
@@ -85,6 +91,7 @@ public class ProductTypeService implements IEntityService<ProductType>, QuerySer
@CacheEvict(key = "'code-'+#p0.code"),
@CacheEvict(key = "'name-'+#p0.name"),
})
@Override
public ProductType save(ProductType type) {
return productTypeRepository.save(type);
}
@@ -95,18 +102,17 @@ public class ProductTypeService implements IEntityService<ProductType>, QuerySer
@CacheEvict(key = "'code-'+#p0.code"),
@CacheEvict(key = "'name-'+#p0.name"),
})
@Override
public void delete(ProductType type) {
productTypeRepository.delete(type);
}
@Override
public void updateByVo(ProductType productType, ProductTypeVo vo) {
// 映射基本属性
productType.setName(vo.getName());
productType.setCode(vo.getCode());
productType.setDescription(vo.getDescription());
// ProductTypeVo中的parentId、order和active字段在ProductType实体中不存在这里不做处理
// 如果需要处理,可以添加日志记录或者其他逻辑
public void updateByVo(ProductType model, ProductTypeVo vo) {
if (model == null || vo == null) {
throw new IllegalArgumentException("Model or VO cannot be null");
}
model.setName(vo.getName());
model.setCode(vo.getCode());
}
}

View File

@@ -2,11 +2,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.service.VoableService;
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,37 +15,75 @@ import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import com.ecep.contract.IEntityService;
import com.ecep.contract.QueryService;
import com.ecep.contract.ds.project.repository.ProductUsageRepository;
import com.ecep.contract.model.ProductUsage;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.vo.ProductUsageVo;
import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "product-usage")
public class ProductUsageService implements IEntityService<ProductUsage>, QueryService<ProductUsage>, VoableService<ProductUsage, ProductUsageVo> {
public class ProductUsageService implements IEntityService<ProductUsage>, QueryService<ProductUsageVo>,
VoableService<ProductUsage, ProductUsageVo> {
@Lazy
@Autowired
private ProductUsageRepository productUsageRepository;
@Cacheable(key = "#p0")
public ProductUsage findById(Integer id) {
@Override
public ProductUsage getById(Integer id) {
return productUsageRepository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
@Override
public ProductUsageVo findById(Integer id) {
ProductUsage usage = getById(id);
if (usage != null) {
return usage.toVo();
}
return null;
}
@Cacheable(key = "'name-'+#p0")
public ProductUsageVo findByName(String name) {
ProductUsage usage = productUsageRepository.findByName(name).orElse(null);
if (usage != null) {
return usage.toVo();
}
return null;
}
@Cacheable(key = "'code-'+#p0")
public ProductUsageVo findByCode(String substring) {
ProductUsage usage = productUsageRepository.findByCode(substring).orElse(null);
if (usage != null) {
return usage.toVo();
}
return null;
}
@Cacheable(key = "'all'")
public List<ProductUsage> findAll() {
return productUsageRepository.findAll();
}
@Override
public Page<ProductUsage> findAll(Specification<ProductUsage> spec, Pageable pageable) {
return productUsageRepository.findAll(spec, pageable);
}
@Override
public Page<ProductUsage> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<ProductUsageVo> 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);
// spec = SpecificationUtils.andParam(spec, paramsNode, "company");
Page<ProductUsage> page = findAll(spec, pageable);
return page.map(ProductUsage::toVo);
}
@Override
@@ -59,57 +92,36 @@ public class ProductUsageService implements IEntityService<ProductUsage>, QueryS
return null;
}
return (root, query, builder) -> {
return builder.or(
builder.like(root.get("name"), "%" + searchText + "%"),
builder.like(root.get("code"), "%" + searchText + "%"),
builder.like(root.get("description"), "%" + searchText + "%")
);
return builder.like(root.get("name"), "%" + searchText + "%");
};
}
public ProductUsage findByName(String name) {
return productUsageRepository.findByName(name).orElse(null);
}
@Cacheable(key = "'code-'+#p0")
public ProductUsage findByCode(String code) {
return productUsageRepository.findByCode(code).orElse(null);
}
@Cacheable(key = "'all'")
public List<ProductUsage> findAll() {
return productUsageRepository.findAll();
}
@Caching(
evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'code-'+#p0.name"),
@CacheEvict(key = "'all'"),
}
)
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'all'"),
@CacheEvict(key = "'name-'+#p0.name"),
@CacheEvict(key = "'code-'+#p0.code")
})
public ProductUsage save(ProductUsage usage) {
return productUsageRepository.save(usage);
}
@Caching(
evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'code-'+#p0.name"),
@CacheEvict(key = "'all'"),
}
)
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'all'"),
@CacheEvict(key = "'name-'+#p0.name"),
@CacheEvict(key = "'code-'+#p0.code")
})
public void delete(ProductUsage usage) {
productUsageRepository.delete(usage);
}
@Override
public void updateByVo(ProductUsage productUsage, ProductUsageVo vo) {
// 映射基本属性
productUsage.setName(vo.getName());
productUsage.setCode(vo.getCode());
productUsage.setDescription(vo.getDescription());
// ProductUsageVo中的active字段在ProductUsage实体中不存在这里不做处理
public void updateByVo(ProductUsage entity, ProductUsageVo vo) {
entity.setName(vo.getName());
entity.setCode(vo.getCode());
entity.setDescription(vo.getDescription());
}
}

View File

@@ -1,21 +1,23 @@
package com.ecep.contract.ds.project.service;
import java.time.LocalDateTime;
import java.util.List;
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.domain.Sort;
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.ecep.contract.SpringApp;
import com.ecep.contract.constant.ServiceConstant;
import com.ecep.contract.ds.customer.service.CompanyCustomerEvaluationFormFileService;
import com.ecep.contract.ds.other.service.EmployeeService;
import com.ecep.contract.ds.project.repository.ProjectBidRepository;
@@ -28,74 +30,89 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
public class ProjectBidService implements IEntityService<ProjectBid>, QueryService<ProjectBid>, VoableService<ProjectBid, ProjectBidVo> {
private static final Logger logger = LoggerFactory.getLogger(ProjectBidService.class);
@CacheConfig(cacheNames = "project-bid")
public class ProjectBidService implements IEntityService<ProjectBid>, QueryService<ProjectBidVo>,
VoableService<ProjectBid, ProjectBidVo> {
@Lazy
@Autowired
private ProjectBidRepository repository;
public ProjectBid findById(Integer id) {
@Override
public ProjectBid getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
@Override
public ProjectBidVo findById(Integer id) {
ProjectBid bid = getById(id);
if (bid != null) {
return bid.toVo();
}
return null;
}
@Override
public Page<ProjectBid> findAll(Specification<ProjectBid> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
}
@Override
public Page<ProjectBid> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<ProjectBidVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ProjectBid> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
if (paramsNode.has(ServiceConstant.KEY_SEARCH_TEXT)) {
spec = getSpecification(paramsNode.get(ServiceConstant.KEY_SEARCH_TEXT).asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "project", "cost", "applicant", "authorizer");
return findAll(spec, pageable);
}
spec = SpecificationUtils.andParam(spec, paramsNode, "project");
public List<ProjectBid> findAllByProject(Project project) {
return repository.findAllByProject(project);
}
public ProjectBid save(ProjectBid bid) {
return repository.save(bid);
if (paramsNode.has("project.customer")) {
Integer customerId = paramsNode.get("project.customer").asInt();
spec = SpecificationUtils.and(spec, (root, query, builder) -> {
return builder.equal(root.get("project").get("customer").get("id"), customerId);
});
}
Page<ProjectBid> page = findAll(spec, pageable);
return page.map(ProjectBid::toVo);
}
@Override
public Specification<ProjectBid> getSpecification(String searchText) {
if (!StringUtils.hasText(searchText)) {
return null;
}
return (root, query, builder) -> {
return builder.or(
builder.like(root.get("noStandardPayWayText"), "%" + searchText + "%"),
builder.like(root.get("noStandardContractText"), "%" + searchText + "%"),
builder.like(root.get("description"), "%" + searchText + "%"));
builder.like(root.get("code"), "%" + searchText + "%"),
builder.like(root.get("bidName"), "%" + searchText + "%"));
};
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
})
public ProjectBid save(ProjectBid bid) {
return repository.save(bid);
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
})
public void delete(ProjectBid bid) {
repository.delete(bid);
}
public ProjectBid newInstanceByProject(Project project) {
ProjectBid approval = new ProjectBid();
approval.setProject(project);
approval.setApplyTime(LocalDateTime.now());
return approval;
}
public List<ProjectBid> findAll(Specification<ProjectBid> spec, Sort sort) {
return repository.findAll(spec, sort);
public List<ProjectBid> findByProjectId(Integer projectId) {
Project project = SpringApp.getBean(ProjectService.class).getById(projectId);
if (project != null) {
return repository.findAllByProject(project);
}
return java.util.Collections.emptyList();
}
@Override
public void updateByVo(ProjectBid model, ProjectBidVo vo) {
if (model == null || vo == null) {
return;
}
// 设置基本属性
model.setLevel(vo.getLevel());
model.setAmount(vo.getAmount());
model.setStandardPayWay(vo.isStandardPayWay());
@@ -108,35 +125,43 @@ public class ProjectBidService implements IEntityService<ProjectBid>, QueryServi
model.setAuthorizationTime(vo.getAuthorizationTime());
model.setDescription(vo.getDescription());
// 处理关联实体
if (vo.getProject() == null) {
if (vo.getProject() != null) {
Project project = SpringApp.getBean(ProjectService.class).getById(vo.getProject());
model.setProject(project);
} else {
model.setProject(null);
} else {
model.setProject(SpringApp.getBean(ProjectService.class).findById(vo.getProject()));
}
if (vo.getEvaluationFileId() == null) {
if (vo.getEvaluationFileId() != null) {
CompanyCustomerEvaluationFormFileService evaluationFileService = SpringApp
.getBean(CompanyCustomerEvaluationFormFileService.class);
model.setEvaluationFile(evaluationFileService.findById(vo.getEvaluationFileId()));
} else {
model.setEvaluationFile(null);
} else {
model.setEvaluationFile(SpringApp.getBean(CompanyCustomerEvaluationFormFileService.class).findById(vo.getEvaluationFileId()));
}
if (vo.getCostId() == null) {
if (vo.getCostId() != null) {
ProjectCostService costService = SpringApp.getBean(ProjectCostService.class);
model.setCost(costService.getById(vo.getCostId()));
} else {
model.setCost(null);
} else {
model.setCost(SpringApp.getBean(ProjectCostService.class).findById(vo.getCostId()));
}
if (vo.getApplicantId() == null) {
EmployeeService employeeService = SpringApp.getBean(EmployeeService.class);
if (vo.getApplicantId() != null) {
model.setApplicant(employeeService.getById(vo.getApplicantId()));
} else {
model.setApplicant(null);
} else {
model.setApplicant(SpringApp.getBean(EmployeeService.class).findById(vo.getApplicantId()));
}
if (vo.getAuthorizerId() == null) {
model.setAuthorizer(null);
if (vo.getAuthorizerId() != null) {
model.setAuthorizer(employeeService.getById(vo.getAuthorizerId()));
} else {
model.setAuthorizer(SpringApp.getBean(EmployeeService.class).findById(vo.getAuthorizerId()));
model.setAuthorizer(null);
}
}
public List<ProjectBid> findAllByProject(Project project) {
return repository.findAllByProject(project);
}
}

View File

@@ -3,25 +3,25 @@ package com.ecep.contract.ds.project.service;
import java.util.List;
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.security.authentication.AuthenticationManager;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import com.ecep.contract.IEntityService;
import com.ecep.contract.QueryService;
import com.ecep.contract.SpringApp;
import com.ecep.contract.ds.other.service.EmployeeService;
import com.ecep.contract.constant.ServiceConstant;
import com.ecep.contract.ds.other.service.InventoryService;
import com.ecep.contract.ds.project.repository.ProjectCostItemRepository;
import com.ecep.contract.model.Employee;
import com.ecep.contract.model.Inventory;
import com.ecep.contract.model.ProjectCost;
import com.ecep.contract.model.ProjectCostItem;
import com.ecep.contract.service.ServiceException;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.util.SpecificationUtils;
import com.ecep.contract.vo.ProjectCostItemVo;
@@ -29,25 +29,45 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
public class ProjectCostItemService implements IEntityService<ProjectCostItem>, QueryService<ProjectCostItem>,
@CacheConfig(cacheNames = "project-cost-item")
public class ProjectCostItemService implements IEntityService<ProjectCostItem>, QueryService<ProjectCostItemVo>,
VoableService<ProjectCostItem, ProjectCostItemVo> {
private final AuthenticationManager authenticationManager;
@Lazy
@Autowired
private ProjectCostItemRepository repository;
ProjectCostItemService(AuthenticationManager authenticationManager) {
this.authenticationManager = authenticationManager;
}
@Override
public ProjectCostItem findById(Integer id) {
public ProjectCostItem getById(Integer id) {
return repository.findById(id).orElse(null);
}
public List<ProjectCostItem> findByCost(ProjectCost cost) {
return repository.findByCost(cost);
@Cacheable(key = "#p0")
@Override
public ProjectCostItemVo findById(Integer id) {
ProjectCostItem item = getById(id);
if (item != null) {
return item.toVo();
}
return null;
}
@Override
public Page<ProjectCostItem> findAll(Specification<ProjectCostItem> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
}
@Override
public Page<ProjectCostItemVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ProjectCostItem> spec = null;
if (paramsNode.has(ServiceConstant.KEY_SEARCH_TEXT)) {
spec = getSpecification(paramsNode.get(ServiceConstant.KEY_SEARCH_TEXT).asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "cost");
Page<ProjectCostItem> page = findAll(spec, pageable);
return page.map(ProjectCostItem::toVo);
}
@Override
@@ -57,91 +77,58 @@ public class ProjectCostItemService implements IEntityService<ProjectCostItem>,
}
return (root, query, builder) -> {
return builder.or(
builder.like(root.get("title"), "%" + searchText + "%"),
builder.like(root.get("specification"), "%" + searchText + "%"));
builder.like(root.get("code"), "%" + searchText + "%"),
builder.like(root.get("name"), "%" + searchText + "%")
);
};
}
@Override
public Page<ProjectCostItem> findAll(Specification<ProjectCostItem> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
})
public ProjectCostItem save(ProjectCostItem item) {
return repository.save(item);
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
})
public void delete(ProjectCostItem item) {
repository.delete(item);
}
public List<ProjectCostItem> findByCostId(Integer costId) {
if (costId == null) {
return List.of();
}
ProjectCost cost = new ProjectCost();
cost.setId(costId);
return repository.findByCost(cost);
}
@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);
}
public void updateByVo(ProjectCostItem model, ProjectCostItemVo vo) {
model.setTitle(vo.getTitle());
model.setSpecification(vo.getSpecification());
model.setUnit(vo.getUnit());
model.setInTaxRate(vo.getInTaxRate());
model.setInExclusiveTaxPrice(vo.getInExclusiveTaxPrice());
model.setInQuantity(vo.getInQuantity());
model.setOutTaxRate(vo.getOutTaxRate());
model.setOutExclusiveTaxPrice(vo.getOutExclusiveTaxPrice());
model.setOutQuantity(vo.getOutQuantity());
model.setRemark(vo.getRemark());
@Override
public void delete(ProjectCostItem entity) {
repository.delete(entity);
}
@Override
public ProjectCostItem save(ProjectCostItem entity) {
return repository.save(entity);
}
@Override
public void updateByVo(ProjectCostItem item, ProjectCostItemVo vo) {
if (item == null) {
throw new ServiceException("ProjectCostItem is null");
}
if (vo == null) {
throw new ServiceException("ProjectCostItemVo is null");
if (vo.getCostId() != null) {
ProjectCost cost = SpringApp.getBean(ProjectCostService.class).getById(vo.getCostId());
model.setCost(cost);
}
item.setTitle(vo.getTitle());
item.setSpecification(vo.getSpecification());
item.setUnit(vo.getUnit());
item.setInTaxRate(vo.getInTaxRate());
item.setInExclusiveTaxPrice(vo.getInExclusiveTaxPrice());
item.setInQuantity(vo.getInQuantity());
item.setOutTaxRate(vo.getOutTaxRate());
item.setOutExclusiveTaxPrice(vo.getOutExclusiveTaxPrice());
item.setOutQuantity(vo.getOutQuantity());
item.setCreateDate(vo.getCreateDate());
item.setUpdateDate(vo.getUpdateDate());
item.setRemark(vo.getRemark());
if (vo.getCostId() == null) {
item.setCost(null);
} else {
ProjectCostService costService = SpringApp.getBean(ProjectCostService.class);
ProjectCost cost = costService.findById(vo.getCostId());
item.setCost(cost);
}
if (vo.getInventoryId() == null) {
item.setInventory(null);
} else {
if (vo.getInventoryId() != null) {
InventoryService inventoryService = SpringApp.getBean(InventoryService.class);
Inventory inventory = inventoryService.findById(vo.getInventoryId());
item.setInventory(inventory);
}
EmployeeService employeeService = SpringApp.getBean(EmployeeService.class);
if (vo.getCreatorId() == null) {
item.setCreator(null);
model.setInventory(inventoryService.getById(vo.getInventoryId()));
} else {
Employee creator = employeeService.findById(vo.getCreatorId());
item.setCreator(creator);
}
if (vo.getUpdaterId() == null) {
item.setUpdater(null);
} else {
Employee updater = employeeService.findById(vo.getUpdaterId());
item.setUpdater(updater);
model.setInventory(null);
}
}
}

View File

@@ -1,15 +1,16 @@
package com.ecep.contract.ds.project.service;
import java.util.Comparator;
import java.math.BigDecimal;
import java.util.List;
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.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
@@ -17,14 +18,11 @@ import org.springframework.util.StringUtils;
import com.ecep.contract.IEntityService;
import com.ecep.contract.QueryService;
import com.ecep.contract.SpringApp;
import com.ecep.contract.ds.contract.service.ContractService;
import com.ecep.contract.ds.other.service.EmployeeService;
import com.ecep.contract.constant.ServiceConstant;
import com.ecep.contract.ds.project.repository.ProjectCostRepository;
import com.ecep.contract.model.Contract;
import com.ecep.contract.model.Employee;
import com.ecep.contract.model.Project;
import com.ecep.contract.model.ProjectCost;
import com.ecep.contract.service.ServiceException;
import com.ecep.contract.model.ProjectCostItem;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.util.SpecificationUtils;
import com.ecep.contract.vo.ProjectCostVo;
@@ -32,66 +30,51 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
public class ProjectCostService
implements IEntityService<ProjectCost>, QueryService<ProjectCost>, VoableService<ProjectCost, ProjectCostVo> {
private static final Logger logger = LoggerFactory.getLogger(ProjectCostService.class);
@CacheConfig(cacheNames = "project-cost")
public class ProjectCostService implements IEntityService<ProjectCost>, QueryService<ProjectCostVo>,
VoableService<ProjectCost, ProjectCostVo> {
@Lazy
@Autowired
private ProjectCostRepository repository;
public ProjectCost findById(Integer id) {
@Override
public ProjectCost getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
@Override
public ProjectCostVo findById(Integer id) {
ProjectCost cost = getById(id);
if (cost != null) {
return cost.toVo();
}
return null;
}
@Override
public Page<ProjectCost> findAll(Specification<ProjectCost> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
}
@Override
public Page<ProjectCost> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<ProjectCostVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ProjectCost> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
if (paramsNode.has(ServiceConstant.KEY_SEARCH_TEXT)) {
spec = getSpecification(paramsNode.get(ServiceConstant.KEY_SEARCH_TEXT).asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "contract", "project", "applicant", "authorizer");
return findAll(spec, pageable);
}
spec = SpecificationUtils.andParam(spec, paramsNode, "project");
public ProjectCost findByContract(Contract contract) {
return repository.findByContract(contract).orElse(null);
}
public ProjectCost findLatestVersionByProject(Project project) {
List<ProjectCost> list = repository.findAllByProject(project);
if (list.isEmpty()) {
return null;
if (paramsNode.has("project.customer")) {
Integer customerId = paramsNode.get("project.customer").asInt();
spec = SpecificationUtils.and(spec, (root, query, builder) -> {
return builder.equal(root.get("project").get("customer").get("id"), customerId);
});
}
return list.stream().max(Comparator.comparingInt(ProjectCost::getVersion)).orElse(null);
}
/**
* 在项目下查找最新的项目成本
*/
public ProjectCost findLatestByProject(Project project) {
return repository.findTopOneByProjectAndVersionGreaterThanOrderByVersionDesc(project, 0).orElse(null);
}
/**
* 在项目下查找V0版本的项目成本
*/
public ProjectCost findAutoCostByProject(Project project) {
return repository.findOneByProjectAndVersion(project, 0).orElse(null);
}
public List<ProjectCost> findAllByProject(Project project) {
return repository.findAllByProject(project);
}
public ProjectCost save(ProjectCost cost) {
return repository.save(cost);
Page<ProjectCost> page = findAll(spec, pageable);
return page.map(ProjectCost::toVo);
}
@Override
@@ -100,109 +83,73 @@ public class ProjectCostService
return null;
}
return (root, query, builder) -> {
return builder.like(root.get("description"), "%" + searchText + "%");
return builder.or(
builder.like(root.get("code"), "%" + searchText + "%"),
builder.like(root.get("name"), "%" + searchText + "%"));
};
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
})
public ProjectCost save(ProjectCost cost) {
return repository.save(cost);
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
})
public void delete(ProjectCost cost) {
repository.delete(cost);
}
public ProjectCost newInstanceByProject(Project project) {
ProjectCost cost = new ProjectCost();
cost.setProject(project);
// 0.3‰:购销合同、建筑安装工程承包合同、技术合同
cost.setStampTax(0.03f);
cost.setTaxAndSurcharges(11f);
return cost;
public List<ProjectCost> findByProject(Project project) {
return repository.findAllByProject(project);
}
public List<ProjectCost> findAll(Specification<ProjectCost> spec, Sort sort) {
return repository.findAll(spec, sort);
public void calculateTotalAmount(ProjectCost cost) {
List<ProjectCostItem> items = SpringApp.getBean(ProjectCostItemService.class).findByCostId(cost.getId());
double totalOutAmount = 0;
double totalInAmount = 0;
for (ProjectCostItem item : items) {
totalInAmount += item.getInExclusiveTaxPrice() != 0 ? item.getInQuantity() : 0;
totalOutAmount += item.getOutExclusiveTaxPrice() != 0 ? item.getOutQuantity() : 0;
}
// ProjectCost类中没有totalAmount属性使用现有属性存储计算结果
cost.setOutExclusiveTaxAmount(totalOutAmount);
cost.setInExclusiveTaxAmount(totalInAmount);
save(cost);
}
@Override
public void updateByVo(ProjectCost entity, ProjectCostVo vo) {
if (entity == null) {
throw new ServiceException("ProjectCost is null");
}
if (vo == null) {
throw new ServiceException("ProjectCostVo is null");
}
public void updateByVo(ProjectCost model, ProjectCostVo vo) {
// 根据ProjectCostVo的实际属性更新ProjectCost
model.setVersion(vo.getVersion());
model.setStandardPayWay(vo.isStandardPayWay());
model.setNoStandardPayWayText(vo.getNoStandardPayWayText());
model.setStandardContractText(vo.isStandardContractText());
model.setNoStandardContractText(vo.getNoStandardContractText());
model.setStampTax(vo.getStampTax());
model.setStampTaxFee(vo.getStampTaxFee());
model.setOnSiteServiceFee(vo.getOnSiteServiceFee());
model.setAssemblyServiceFee(vo.getAssemblyServiceFee());
model.setTechnicalServiceFee(vo.getTechnicalServiceFee());
model.setBidServiceFee(vo.getBidServiceFee());
model.setFreightCost(vo.getFreightCost());
model.setGuaranteeLetterFee(vo.getGuaranteeLetterFee());
model.setTaxAndSurcharges(vo.getTaxAndSurcharges());
model.setTaxAndSurchargesFee(vo.getTaxAndSurchargesFee());
model.setDescription(vo.getDescription());
model.setImportLock(vo.isImportLock());
// 基本字段映射
// 准付款方式 和 合同文本
entity.setStandardPayWay(vo.isStandardPayWay());
entity.setNoStandardPayWayText(vo.getNoStandardPayWayText());
entity.setStandardContractText(vo.isStandardContractText());
entity.setNoStandardContractText(vo.getNoStandardContractText());
// 印花税率和税费
entity.setStampTax(vo.getStampTax());
entity.setStampTaxFee(vo.getStampTaxFee());
// 其他服务费用和运费
entity.setOnSiteServiceFee(vo.getOnSiteServiceFee());
entity.setAssemblyServiceFee(vo.getAssemblyServiceFee());
entity.setTechnicalServiceFee(vo.getTechnicalServiceFee());
entity.setBidServiceFee(vo.getBidServiceFee());
entity.setFreightCost(vo.getFreightCost());
entity.setGuaranteeLetterFee(vo.getGuaranteeLetterFee());
// 营业税及附加费
entity.setTaxAndSurcharges(vo.getTaxAndSurcharges());
entity.setTaxAndSurchargesFee(vo.getTaxAndSurchargesFee());
// 数量和金额
entity.setInQuantities(vo.getInQuantities());
entity.setInTaxAmount(vo.getInTaxAmount());
entity.setInExclusiveTaxAmount(vo.getInExclusiveTaxAmount());
entity.setOutQuantities(vo.getOutQuantities());
entity.setOutTaxAmount(vo.getOutTaxAmount());
entity.setOutExclusiveTaxAmount(vo.getOutExclusiveTaxAmount());
// 毛利率
entity.setGrossProfitMargin(vo.getGrossProfitMargin());
//
entity.setApplyTime(vo.getApplyTime());
entity.setAuthorizationTime(vo.getAuthorizationTime());
entity.setAuthorizationFile(vo.getAuthorizationFile());
entity.setImportLock(vo.isImportLock());
entity.setDescription(vo.getDescription());
entity.setVersion(vo.getVersion());
// 处理关联实体
if (vo.getProject() != null) {
Project project = SpringApp.getBean(ProjectService.class).findById(vo.getProject());
entity.setProject(project);
Project project = SpringApp.getBean(ProjectService.class).getById(vo.getProject());
model.setProject(project);
} else {
entity.setProject(null);
model.setProject(null);
}
if (vo.getContractId() != null) {
Contract contract = SpringApp.getBean(ContractService.class).findById(vo.getContractId());
if (contract != null) {
entity.setContract(contract);
}
} else {
entity.setContract(null);
}
EmployeeService employeeService = SpringApp.getBean(EmployeeService.class);
if (vo.getApplicantId() != null) {
Employee applicant = employeeService.findById(vo.getApplicantId());
if (applicant != null) {
entity.setApplicant(applicant);
}
} else {
entity.setApplicant(null);
}
if (vo.getAuthorizerId() != null) {
Employee authorizer = employeeService.findById(vo.getAuthorizerId());
if (authorizer != null) {
entity.setAuthorizer(authorizer);
}
}
// 忽略的字段active, createTime, createUser, updateTime, updateUser
}
}

View File

@@ -1,17 +1,16 @@
package com.ecep.contract.ds.project.service;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.stream.Collectors;
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.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
@@ -19,7 +18,6 @@ import org.springframework.util.StringUtils;
import com.ecep.contract.IEntityService;
import com.ecep.contract.ProjectFileType;
import com.ecep.contract.QueryService;
import com.ecep.contract.SpringApp;
import com.ecep.contract.ds.project.repository.ProjectFileRepository;
import com.ecep.contract.model.Project;
import com.ecep.contract.model.ProjectFile;
@@ -30,52 +28,44 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
public class ProjectFileService
implements IEntityService<ProjectFile>, QueryService<ProjectFile>, VoableService<ProjectFile, ProjectFileVo> {
private static final Logger logger = LoggerFactory.getLogger(ProjectFileService.class);
@CacheConfig(cacheNames = "project-file")
public class ProjectFileService implements IEntityService<ProjectFile>, QueryService<ProjectFileVo>, VoableService<ProjectFile, ProjectFileVo> {
@Lazy
@Autowired
private ProjectFileRepository projectFileRepository;
private ProjectFileRepository repository;
@Lazy
@Autowired
private ProjectService projectService;
public ProjectFile findById(Integer id) {
return projectFileRepository.findById(id).orElse(null);
@Override
public ProjectFile getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
@Override
public ProjectFileVo findById(Integer id) {
ProjectFile file = getById(id);
if (file != null) {
return file.toVo();
}
return null;
}
@Override
public Page<ProjectFileVo> findAll(JsonNode paramsNode, Pageable pageable) {
// 构建查询规范
Specification<ProjectFile> spec = getSpecification(paramsNode);
// 查询实体列表
Page<ProjectFile> entityPage = findAll(spec, pageable);
// 转换为VO列表
return entityPage.map(ProjectFile::toVo);
}
@Override
public Page<ProjectFile> findAll(Specification<ProjectFile> spec, Pageable pageable) {
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);
}
public void verify(Project project, LocalDate verifyDate, Consumer<String> status) {
status.accept("待开发");
}
public void deleteById(int id) {
Optional<ProjectFile> optional = projectFileRepository.findById(id);
if (optional.isEmpty()) {
return;
}
ProjectFile customerFile = optional.get();
projectFileRepository.delete(customerFile);
}
public List<ProjectFile> findAll(Specification<ProjectFile> spec, Sort sort) {
return projectFileRepository.findAll(spec, sort);
return repository.findAll(spec, pageable);
}
@Override
@@ -88,39 +78,82 @@ public class ProjectFileService
};
}
public ProjectFile save(ProjectFile dbFile) {
return projectFileRepository.save(dbFile);
@Override
public List<ProjectFile> search(String searchText) {
Specification<ProjectFile> spec = getSpecification(searchText);
return repository.findAll(spec);
}
@Override
public void delete(ProjectFile entity) {
projectFileRepository.delete(entity);
}
public List<ProjectFile> saveAll(List<ProjectFile> files) {
return projectFileRepository.saveAll(files);
repository.delete(entity);
}
@Override
public ProjectFile save(ProjectFile entity) {
return repository.save(entity);
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
})
public ProjectFile saveFile(ProjectFile file) {
return repository.save(file);
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
})
public void deleteFile(ProjectFile file) {
repository.delete(file);
}
// 根据项目查询文件列表
public List<ProjectFileVo> findByProject(Project project) {
List<ProjectFile> files = repository.findByProject(project);
return files.stream().map(ProjectFile::toVo).collect(Collectors.toList());
}
// 根据项目和类型查询文件列表
public List<ProjectFileVo> findByProjectAndType(Project project, ProjectFileType type) {
List<ProjectFile> files = repository.findByProjectAndType(project, type);
return files.stream().map(ProjectFile::toVo).collect(Collectors.toList());
}
// 构建查询规范
private Specification<ProjectFile> getSpecification(JsonNode paramsNode) {
Specification<ProjectFile> spec = null;
// 根据参数构建查询条件
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "id");
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "projectId");
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "type");
return spec;
}
// 计数方法实现
@Override
public long count(JsonNode paramsNode) {
Specification<ProjectFile> spec = getSpecification(paramsNode);
if (spec != null) {
return repository.count(spec);
}
return repository.count();
}
@Override
public void updateByVo(ProjectFile model, ProjectFileVo vo) {
if (model == null || vo == null) {
return;
}
// 设置基本属性
// 更新文件类型
model.setType(vo.getType());
// 更新文件路径
model.setFilePath(vo.getFilePath());
// 处理关联实体
if (vo.getProjectId() == null) {
model.setProject(null);
// 更新项目关联
if (vo.getProjectId() != null) {
model.setProject(projectService.getById(vo.getProjectId()));
} else {
model.setProject(SpringApp.getBean(ProjectService.class).findById(vo.getProjectId()));
model.setProject(null);
}
}
public List<ProjectFile> findAllByProjectAndType(Project project, ProjectFileType type) {
return projectFileRepository.findByProjectAndType(project, type);
}
}

View File

@@ -1,13 +1,8 @@
package com.ecep.contract.ds.project.service;
import com.ecep.contract.IEntityService;
import com.ecep.contract.ProjectFileType;
import com.ecep.contract.QueryService;
import com.ecep.contract.constant.ServiceConstant;
import com.ecep.contract.ds.project.repository.ProjectFileTypeLocalRepository;
import com.ecep.contract.model.ProjectFileTypeLocal;
import com.ecep.contract.util.SpecificationUtils;
import com.fasterxml.jackson.databind.JsonNode;
import java.util.Locale;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
@@ -20,17 +15,23 @@ 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.ProjectFileType;
import com.ecep.contract.QueryService;
import com.ecep.contract.constant.ServiceConstant;
import com.ecep.contract.ds.project.repository.ProjectFileTypeLocalRepository;
import com.ecep.contract.model.ProjectFileTypeLocal;
import com.ecep.contract.service.ServiceException;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.util.SpecificationUtils;
import com.ecep.contract.vo.ProjectFileTypeLocalVo;
import java.util.Locale;
import java.util.Map;
import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "project-file-type")
public class ProjectFileTypeService implements IEntityService<ProjectFileTypeLocal>, QueryService<ProjectFileTypeLocal>,
public class ProjectFileTypeService
implements IEntityService<ProjectFileTypeLocal>, QueryService<ProjectFileTypeLocalVo>,
VoableService<ProjectFileTypeLocal, ProjectFileTypeLocalVo> {
@Lazy
@@ -38,7 +39,7 @@ public class ProjectFileTypeService implements IEntityService<ProjectFileTypeLoc
private ProjectFileTypeLocalRepository repository;
@Override
public Page<ProjectFileTypeLocal> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<ProjectFileTypeLocalVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ProjectFileTypeLocal> spec = null;
if (paramsNode.has(ServiceConstant.KEY_SEARCH_TEXT)) {
spec = getSpecification(paramsNode.get(ServiceConstant.KEY_SEARCH_TEXT).asText());
@@ -51,11 +52,15 @@ public class ProjectFileTypeService implements IEntityService<ProjectFileTypeLoc
// field
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "lang", "value");
return findAll(spec, pageable);
return findAll(spec, pageable).map(ProjectFileTypeLocal::toVo);
}
@Override
public ProjectFileTypeLocal findById(Integer id) {
public ProjectFileTypeLocalVo findById(Integer id) {
return repository.findById(id).map(ProjectFileTypeLocal::toVo).orElse(null);
}
public ProjectFileTypeLocal getById(Integer id) {
return repository.findById(id).orElse(null);
}
@@ -65,8 +70,11 @@ public class ProjectFileTypeService implements IEntityService<ProjectFileTypeLoc
}
@Cacheable(key = "'all-'+#p0.toLanguageTag()")
public Map<ProjectFileType, ProjectFileTypeLocal> findAll(Locale locale) {
return repository.getCompleteMapByLocal(locale.toLanguageTag());
public Map<ProjectFileType, ProjectFileTypeLocalVo> findAll(Locale locale) {
return repository.getCompleteMapByLocal(locale.toLanguageTag()).entrySet().stream()
.collect(java.util.stream.Collectors.toMap(
java.util.Map.Entry::getKey,
entry -> entry.getValue().toVo()));
}
@Override
@@ -94,7 +102,7 @@ public class ProjectFileTypeService implements IEntityService<ProjectFileTypeLoc
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'all-'+#p0.getLang")
@CacheEvict(key = "'all-'+#p0.getLang()")
})
@Override
public void delete(ProjectFileTypeLocal entity) {

View File

@@ -1,17 +1,19 @@
package com.ecep.contract.ds.project.service;
import java.time.LocalDateTime;
import java.math.BigDecimal;
import java.util.List;
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.domain.Sort;
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;
@@ -21,7 +23,6 @@ import com.ecep.contract.ds.project.repository.ProjectFundPlanRepository;
import com.ecep.contract.model.ContractPayPlan;
import com.ecep.contract.model.Project;
import com.ecep.contract.model.ProjectFundPlan;
import com.ecep.contract.service.ServiceException;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.util.SpecificationUtils;
import com.ecep.contract.vo.ProjectFundPlanVo;
@@ -29,99 +30,101 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
public class ProjectFundPlanService implements IEntityService<ProjectFundPlan>, QueryService<ProjectFundPlan>, VoableService<ProjectFundPlan, ProjectFundPlanVo> {
private static final Logger logger = LoggerFactory.getLogger(ProjectFundPlanService.class);
@CacheConfig(cacheNames = "project-fund-plan")
public class ProjectFundPlanService implements IEntityService<ProjectFundPlan>, QueryService<ProjectFundPlanVo>,
VoableService<ProjectFundPlan, ProjectFundPlanVo> {
@Lazy
@Autowired
private ProjectFundPlanRepository repository;
public ProjectFundPlan findById(Integer id) {
@Override
public ProjectFundPlan getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
@Override
public ProjectFundPlanVo findById(Integer id) {
ProjectFundPlan fundPlan = getById(id);
if (fundPlan != null) {
return fundPlan.toVo();
}
return null;
}
@Override
public Page<ProjectFundPlan> findAll(Specification<ProjectFundPlan> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
}
@Override
public Page<ProjectFundPlan> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<ProjectFundPlanVo> 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);
}
public ProjectFundPlan save(ProjectFundPlan fundPlan) {
return repository.save(fundPlan);
spec = SpecificationUtils.andParam(spec, paramsNode, "project");
Page<ProjectFundPlan> page = findAll(spec, pageable);
return page.map(ProjectFundPlan::toVo);
}
@Override
public Specification<ProjectFundPlan> getSpecification(String searchText) {
if (!StringUtils.hasText(searchText)) {
return null;
}
return (root, query, builder) -> {
return builder.or(
builder.like(root.get("payTerm"), "%" + searchText + "%"),
builder.like(builder.toString(root.get("payRatio")), "%" + searchText + "%"),
builder.like(builder.toString(root.get("payCurrency")), "%" + searchText + "%")
);
return builder.like(root.get("description"), "%" + searchText + "%");
};
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
})
public ProjectFundPlan save(ProjectFundPlan fundPlan) {
return repository.save(fundPlan);
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
})
public void delete(ProjectFundPlan fundPlan) {
repository.delete(fundPlan);
}
public ProjectFundPlan newInstanceByProject(Project project) {
ProjectFundPlan fundPlan = new ProjectFundPlan();
fundPlan.setProject(project);
fundPlan.setUpdateDate(LocalDateTime.now());
return fundPlan;
public List<ProjectFundPlan> findByProject(Project project) {
return repository.findAllByProject(project);
}
public List<ProjectFundPlan> findAll(Specification<ProjectFundPlan> spec, Sort sort) {
return repository.findAll(spec, sort);
public BigDecimal calculateAmountByProject(Project project) {
List<ProjectFundPlan> plans = findByProject(project);
if (plans.isEmpty()) {
return BigDecimal.ZERO;
}
// 转换为BigDecimal
return BigDecimal.valueOf(plans.stream().mapToDouble(ProjectFundPlan::getPayCurrency).sum());
// return plans.stream()
// .map(ProjectFundPlan::getAmount)
// .filter(Optional::isPresent)
// .map(Optional::get)
// .reduce(BigDecimal.ZERO, BigDecimal::add);
}
@Override
public void updateByVo(ProjectFundPlan fundPlan, ProjectFundPlanVo vo) {
// 映射基本属性
fundPlan.setPayDate(vo.getPayDate());
fundPlan.setPayWay(vo.getPayWay());
fundPlan.setPayRatio(vo.getPayRatio());
fundPlan.setPayCurrency(vo.getPayCurrency());
fundPlan.setPayTerm(vo.getPayTerm());
fundPlan.setUpdateDate(vo.getUpdateDate());
// 处理关联对象 project
if (vo.getProjectId() != null) {
try {
Project project = SpringApp.getBean(ProjectService.class).findById(vo.getProjectId());
if (project != null) {
fundPlan.setProject(project);
}
} catch (Exception e) {
throw new ServiceException("Failed to find Project: " + e.getMessage(), e);
}
}
// 处理关联对象 contractPayPlan
public void updateByVo(ProjectFundPlan model, ProjectFundPlanVo vo) {
// 基本字段映射
model.setPayRatio(vo.getPayRatio());
model.setPayCurrency(vo.getPayCurrency());
model.setPayTerm(vo.getPayTerm());
model.setUpdateDate(vo.getUpdateDate());
// 处理关联实体
if (vo.getContractPayPlanId() != null) {
try {
ContractPayPlan contractPayPlan = SpringApp.getBean(ContractPayPlanService.class).findById(vo.getContractPayPlanId());
if (contractPayPlan != null) {
fundPlan.setContractPayPlan(contractPayPlan);
}
} catch (Exception e) {
throw new ServiceException("Failed to find ContractPayPlan: " + e.getMessage(), e);
}
ContractPayPlan contractPayPlan = SpringApp.getBean(ContractPayPlanService.class).getById(vo.getContractPayPlanId());
model.setContractPayPlan(contractPayPlan);
}else{
model.setContractPayPlan(null);
}
}
}

View File

@@ -3,6 +3,7 @@ package com.ecep.contract.ds.project.service;
import java.util.List;
import com.ecep.contract.QueryService;
import com.ecep.contract.constant.ServiceConstant;
import com.ecep.contract.util.SpecificationUtils;
import com.fasterxml.jackson.databind.JsonNode;
import org.springframework.beans.factory.annotation.Autowired;
@@ -14,7 +15,7 @@ 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.stereotype.Service;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import com.ecep.contract.IEntityService;
@@ -26,44 +27,65 @@ import com.ecep.contract.vo.ProjectIndustryVo;
@Lazy
@Service
@CacheConfig(cacheNames = "project-industry")
public class ProjectIndustryService implements IEntityService<ProjectIndustry>, QueryService<ProjectIndustry>, VoableService<ProjectIndustry, ProjectIndustryVo> {
public class ProjectIndustryService implements IEntityService<ProjectIndustry>, QueryService<ProjectIndustryVo>,
VoableService<ProjectIndustry, ProjectIndustryVo> {
@Lazy
@Autowired
private ProjectIndustryRepository industryRepository;
private ProjectIndustryRepository repository;
@Override
public ProjectIndustry getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
public ProjectIndustry findById(Integer id) {
return industryRepository.findById(id).orElse(null);
@Override
public ProjectIndustryVo findById(Integer id) {
ProjectIndustry industry = getById(id);
if (industry != null) {
return industry.toVo();
}
return null;
}
@Cacheable(key = "'name-'+#p0")
public ProjectIndustry findByName(String name) {
return industryRepository.findByName(name).orElse(null);
public ProjectIndustryVo findByName(String name) {
ProjectIndustry industry = repository.findByName(name).orElse(null);
if (industry != null) {
return industry.toVo();
}
return null;
}
@Cacheable(key = "'code-'+#p0")
public ProjectIndustry findByCode(String code) {
return industryRepository.findByCode(code).orElse(null);
public ProjectIndustryVo findByCode(String code) {
ProjectIndustry industry = repository.findByCode(code).orElse(null);
if (industry != null) {
return industry.toVo();
}
return null;
}
@Cacheable(key = "'all'")
public List<ProjectIndustry> findAll() {
return industryRepository.findAll();
public List<ProjectIndustryVo> findAll() {
List<ProjectIndustry> industries = repository.findAll();
return industries.stream().map(ProjectIndustry::toVo).toList();
}
public Page<ProjectIndustry> findAll(Specification<ProjectIndustry> spec, Pageable pageable) {
return industryRepository.findAll(spec, pageable);
return repository.findAll(spec, pageable);
}
@Override
public Page<ProjectIndustry> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<ProjectIndustryVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ProjectIndustry> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
if (paramsNode.has(ServiceConstant.KEY_SEARCH_TEXT)) {
spec = getSpecification(paramsNode.get(ServiceConstant.KEY_SEARCH_TEXT).asText());
}
// field
// spec = SpecificationUtils.andParam(spec, paramsNode, "company");
return findAll(spec, pageable);
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "code", "name");
Page<ProjectIndustry> page = findAll(spec, pageable);
return page.map(ProjectIndustry::toVo);
}
@Override
@@ -74,43 +96,34 @@ public class ProjectIndustryService implements IEntityService<ProjectIndustry>,
return (root, query, builder) -> {
return builder.or(
builder.like(root.get("code"), "%" + searchText + "%"),
builder.like(root.get("name"), "%" + searchText + "%")
);
builder.like(root.get("name"), "%" + searchText + "%"));
};
}
@Caching(
evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'code-'+#p0.code"),
@CacheEvict(key = "'name-'+#p0.name"),
@CacheEvict(key = "'all'"),
}
)
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'code-'+#p0.code"),
@CacheEvict(key = "'name-'+#p0.name"),
@CacheEvict(key = "'all'"),
})
public ProjectIndustry save(ProjectIndustry industry) {
return industryRepository.save(industry);
return repository.save(industry);
}
@Caching(
evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'code-'+#p0.code"),
@CacheEvict(key = "'name-'+#p0.name"),
@CacheEvict(key = "'all'"),
}
)
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'code-'+#p0.code"),
@CacheEvict(key = "'name-'+#p0.name"),
@CacheEvict(key = "'all'"),
})
public void delete(ProjectIndustry industry) {
industryRepository.delete(industry);
repository.delete(industry);
}
@Override
public void updateByVo(ProjectIndustry industry, ProjectIndustryVo vo) {
// 映射基本属性
industry.setName(vo.getName());
industry.setCode(vo.getCode());
industry.setDescription(vo.getDescription());
// ProjectIndustryVo中的active字段在ProjectIndustry实体中不存在这里不做处理
// 如果需要处理,可以添加日志记录或者其他逻辑
public void updateByVo(ProjectIndustry model, ProjectIndustryVo vo) {
model.setName(vo.getName());
model.setCode(vo.getCode());
model.setDescription(vo.getDescription());
}
}

View File

@@ -6,6 +6,8 @@ import java.util.List;
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.Cacheable;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
@@ -16,9 +18,11 @@ import org.springframework.stereotype.Service;
import com.ecep.contract.IEntityService;
import com.ecep.contract.QueryService;
import com.ecep.contract.SpringApp;
import com.ecep.contract.constant.ServiceConstant;
import com.ecep.contract.ds.customer.service.CompanyCustomerEvaluationFormFileService;
import com.ecep.contract.ds.other.service.EmployeeService;
import com.ecep.contract.ds.project.repository.ProjectQuotationRepository;
import com.ecep.contract.model.Employee;
import com.ecep.contract.model.Project;
import com.ecep.contract.model.ProjectQuotation;
import com.ecep.contract.service.ServiceException;
@@ -29,7 +33,8 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
public class ProjectQuotationService implements IEntityService<ProjectQuotation>, QueryService<ProjectQuotation>,
@CacheConfig(cacheNames = "project-quotation")
public class ProjectQuotationService implements IEntityService<ProjectQuotation>, QueryService<ProjectQuotationVo>,
VoableService<ProjectQuotation, ProjectQuotationVo> {
private static final Logger logger = LoggerFactory.getLogger(ProjectQuotationService.class);
@@ -37,24 +42,36 @@ public class ProjectQuotationService implements IEntityService<ProjectQuotation>
@Autowired
private ProjectQuotationRepository repository;
public ProjectQuotation findById(Integer id) {
@Override
public ProjectQuotation getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Override
public Page<ProjectQuotation> findAll(Specification<ProjectQuotation> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
@Cacheable(key = "#p0")
public ProjectQuotationVo findById(Integer id) {
ProjectQuotation entity = getById(id);
if (entity != null) {
return entity.toVo();
}
return null;
}
// 实现QueryService接口的findAll方法
@Override
public Page<ProjectQuotation> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<ProjectQuotationVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ProjectQuotation> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
if (paramsNode.has(ServiceConstant.KEY_SEARCH_TEXT)) {
spec = getSpecification(paramsNode.get(ServiceConstant.KEY_SEARCH_TEXT).asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "project", "applicant", "authorizer");
return findAll(spec, pageable);
return findAll(spec, pageable).map(ProjectQuotation::toVo);
}
// 实现IEntityService接口的findAll方法
@Override
public Page<ProjectQuotation> findAll(Specification<ProjectQuotation> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
}
public List<ProjectQuotation> findAllByProject(Project project) {
@@ -106,28 +123,40 @@ public class ProjectQuotationService implements IEntityService<ProjectQuotation>
// 处理关联实体
if (vo.getProject() != null) {
ProjectService projectService = SpringApp.getBean(ProjectService.class);
entity.setProject(projectService.findById(vo.getProject()));
if (entity.getProject() == null || !entity.getProject().getId().equals(vo.getProject())) {
ProjectService projectService = SpringApp.getBean(ProjectService.class);
entity.setProject(projectService.getById(vo.getProject()));
}
} else {
entity.setProject(null);
}
EmployeeService employeeService = SpringApp.getBean(EmployeeService.class);
if (vo.getApplicantId() != null) {
entity.setApplicant(employeeService.findById(vo.getApplicantId()));
if (entity.getApplicant() == null || !entity.getApplicant().getId().equals(vo.getApplicantId())) {
Employee applicant = employeeService.getById(vo.getApplicantId());
entity.setApplicant(applicant);
}
} else {
entity.setApplicant(null);
}
if (vo.getAuthorizerId() != null) {
entity.setAuthorizer(employeeService.findById(vo.getAuthorizerId()));
if (entity.getAuthorizer() == null || !entity.getAuthorizer().getId().equals(vo.getAuthorizerId())) {
Employee authorizer = employeeService.getById(vo.getAuthorizerId());
entity.setAuthorizer(authorizer);
}
} else {
entity.setAuthorizer(null);
}
if(vo.getEvaluationFileId() != null){
CompanyCustomerEvaluationFormFileService evaluationFileService = SpringApp.getBean(CompanyCustomerEvaluationFormFileService.class);
entity.setEvaluationFile(evaluationFileService.findById(vo.getEvaluationFileId()));
}else{
if (vo.getEvaluationFileId() != null) {
if (entity.getEvaluationFile() == null
|| !entity.getEvaluationFile().getId().equals(vo.getEvaluationFileId())) {
CompanyCustomerEvaluationFormFileService evaluationFileService = SpringApp
.getBean(CompanyCustomerEvaluationFormFileService.class);
entity.setEvaluationFile(evaluationFileService.getById(vo.getEvaluationFileId()));
}
} else {
entity.setEvaluationFile(null);
}
}

View File

@@ -18,6 +18,8 @@ import com.ecep.contract.IEntityService;
import com.ecep.contract.QueryService;
import com.ecep.contract.SpringApp;
import com.ecep.contract.ds.project.repository.ProjectSaleTypeRequireFileTypeRepository;
import com.ecep.contract.ds.project.service.ProjectSaleTypeService;
import com.ecep.contract.model.ProjectSaleType;
import com.ecep.contract.model.ProjectSaleTypeRequireFileType;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.util.SpecificationUtils;
@@ -27,18 +29,26 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "project-sale-type-require-file-type")
public class ProjectSaleTypeRequireFileTypeService implements IEntityService<ProjectSaleTypeRequireFileType>, QueryService<ProjectSaleTypeRequireFileType>, VoableService<ProjectSaleTypeRequireFileType, ProjectSaleTypeRequireFileTypeVo> {
public class ProjectSaleTypeRequireFileTypeService
implements IEntityService<ProjectSaleTypeRequireFileType>, QueryService<ProjectSaleTypeRequireFileTypeVo>,
VoableService<ProjectSaleTypeRequireFileType, ProjectSaleTypeRequireFileTypeVo> {
@Lazy
@Autowired
private ProjectSaleTypeRequireFileTypeRepository repository;
@Cacheable(key = "#p0")
public ProjectSaleTypeRequireFileType findById(Integer id) {
@Override
public ProjectSaleTypeRequireFileType getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
public ProjectSaleTypeRequireFileTypeVo findById(Integer id) {
return repository.findById(id).map(ProjectSaleTypeRequireFileType::toVo).orElse(null);
}
@Override
public Page<ProjectSaleTypeRequireFileType> findAll(Specification<ProjectSaleTypeRequireFileType> spec, Pageable pageable) {
public Page<ProjectSaleTypeRequireFileType> findAll(Specification<ProjectSaleTypeRequireFileType> spec,
Pageable pageable) {
return repository.findAll(spec, pageable);
}
@@ -47,6 +57,18 @@ public class ProjectSaleTypeRequireFileTypeService implements IEntityService<Pro
return repository.findBySaleTypeId(saleTypeId);
}
@Cacheable(key = "'by-sale-type-'+#p0.id")
public List<ProjectSaleTypeRequireFileType> findBySaleType(ProjectSaleType saleType) {
return repository.findBySaleType(saleType);
}
public void deleteBySaleType(ProjectSaleType saleType) {
List<ProjectSaleTypeRequireFileType> list = findBySaleType(saleType);
for (ProjectSaleTypeRequireFileType fileType : list) {
delete(fileType);
}
}
// findAll
@Cacheable(key = "'all'")
public List<ProjectSaleTypeRequireFileType> findAll() {
@@ -54,14 +76,14 @@ public class ProjectSaleTypeRequireFileTypeService implements IEntityService<Pro
}
@Override
public Page<ProjectSaleTypeRequireFileType> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<ProjectSaleTypeRequireFileTypeVo> 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);
return findAll(spec, pageable).map(ProjectSaleTypeRequireFileType::toVo);
}
@Override
@@ -70,27 +92,23 @@ public class ProjectSaleTypeRequireFileTypeService implements IEntityService<Pro
}
// save
@Caching(
evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'bySaleType-'+#p0.saleType.id"),
@CacheEvict(key = "'all'")
}
)
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'bySaleType-'+#p0.saleType.id"),
@CacheEvict(key = "'by-sale-type-'+#p0.saleType.id"),
@CacheEvict(key = "'all'")
})
public ProjectSaleTypeRequireFileType save(ProjectSaleTypeRequireFileType type) {
return repository.save(type);
}
/**
* delete and evict cache
*/
@Caching(
evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'all'")
}
)
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'all'")
})
public void delete(ProjectSaleTypeRequireFileType type) {
repository.delete(type);
}
@@ -103,7 +121,7 @@ public class ProjectSaleTypeRequireFileTypeService implements IEntityService<Pro
// 设置基本属性
model.setFileType(vo.getFileType());
// 转换frequency从String到ContractFileType.Frequency枚举
if (vo.getFrequency() != null) {
try {
@@ -117,7 +135,10 @@ public class ProjectSaleTypeRequireFileTypeService implements IEntityService<Pro
if (vo.getSaleTypeId() == null) {
model.setSaleType(null);
} else {
model.setSaleType(SpringApp.getBean(ProjectSaleTypeService.class).findById(vo.getSaleTypeId()));
ProjectSaleTypeService projectSaleTypeService = SpringApp.getBean(ProjectSaleTypeService.class);
if (model.getSaleType() == null || !model.getSaleType().getId().equals(vo.getSaleTypeId())) {
model.setSaleType(projectSaleTypeService.getById(vo.getSaleTypeId()));
}
}
}
}

View File

@@ -26,29 +26,42 @@ import com.ecep.contract.vo.ProjectSaleTypeVo;
@Lazy
@Service
@CacheConfig(cacheNames = "project-sale-type")
public class ProjectSaleTypeService implements IEntityService<ProjectSaleType>, QueryService<ProjectSaleType>,
public class ProjectSaleTypeService implements IEntityService<ProjectSaleType>, QueryService<ProjectSaleTypeVo>,
VoableService<ProjectSaleType, ProjectSaleTypeVo> {
@Lazy
@Autowired
private ProjectSaleTypeRepository saleTypeRepository;
@Cacheable(key = "#p0")
public ProjectSaleType findById(Integer id) {
public ProjectSaleType getById(Integer id) {
return saleTypeRepository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
public ProjectSaleTypeVo findById(Integer id) {
ProjectSaleType entity = getById(id);
if (entity != null) {
return entity.toVo();
}
return null;
}
public ProjectSaleType findByName(String name) {
return saleTypeRepository.findByName(name).orElse(null);
}
@Cacheable(key = "'code-'+#p0")
public ProjectSaleType findByCode(String code) {
return saleTypeRepository.findByCode(code).orElse(null);
public ProjectSaleTypeVo findByCode(String code) {
ProjectSaleType entity = saleTypeRepository.findByCode(code).orElse(null);
if (entity != null) {
return entity.toVo();
}
return null;
}
@Cacheable(key = "'all'")
public List<ProjectSaleType> findAll() {
return saleTypeRepository.findAll();
public List<ProjectSaleTypeVo> findAll() {
List<ProjectSaleType> entities = saleTypeRepository.findAll();
return entities.stream().map(ProjectSaleType::toVo).toList();
}
public Page<ProjectSaleType> findAll(Specification<ProjectSaleType> spec, Pageable pageable) {
@@ -56,14 +69,14 @@ public class ProjectSaleTypeService implements IEntityService<ProjectSaleType>,
}
@Override
public Page<ProjectSaleType> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<ProjectSaleTypeVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ProjectSaleType> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
}
// field
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "active");
return findAll(spec, pageable);
return findAll(spec, pageable).map(ProjectSaleType::toVo);
}
@Override

View File

@@ -28,17 +28,19 @@ import com.ecep.contract.constant.ProjectConstant;
import com.ecep.contract.ds.company.service.CompanyService;
import com.ecep.contract.ds.other.service.EmployeeService;
import com.ecep.contract.ds.other.service.SysConfService;
import com.ecep.contract.ds.project.repository.ProductDeliverySignMethodRepository;
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.service.VoableService;
import com.ecep.contract.util.SpecificationUtils;
import com.ecep.contract.vo.ProductTypeVo;
import com.ecep.contract.vo.ProductUsageVo;
import com.ecep.contract.vo.ProjectIndustryVo;
import com.ecep.contract.vo.ProjectSaleTypeVo;
import com.ecep.contract.vo.ProjectTypeVo;
import com.ecep.contract.vo.ProjectVo;
import com.fasterxml.jackson.databind.JsonNode;
@@ -49,7 +51,9 @@ import com.fasterxml.jackson.databind.JsonNode;
@Service
@CacheConfig(cacheNames = "project")
public class ProjectService
implements IEntityService<Project>, QueryService<Project>, VoableService<Project, ProjectVo> {
implements IEntityService<Project>, QueryService<ProjectVo>, VoableService<Project, ProjectVo> {
private final ProductDeliverySignMethodRepository productDeliverySignMethodRepository;
private static final Logger logger = LoggerFactory.getLogger(ProjectService.class);
@Lazy
@@ -80,13 +84,25 @@ public class ProjectService
@Autowired
private SysConfService confService;
@Cacheable(key = "#p0")
public Project findById(Integer id) {
ProjectService(ProductDeliverySignMethodRepository productDeliverySignMethodRepository) {
this.productDeliverySignMethodRepository = productDeliverySignMethodRepository;
}
public Project getById(Integer id) {
return projectRepository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
public ProjectVo findById(Integer id) {
Project entity = getById(id);
if (entity != null) {
return entity.toVo();
}
return null;
}
public Project findBySaleTypeAndCodeYearAndCodeSequenceNumber(ProjectSaleType type, int year, int sequenceNumber) {
return projectRepository.findBySaleTypeAndCodeYearAndCodeSequenceNumber(type, year, sequenceNumber)
return projectRepository.findBySaleTypeIdAndCodeYearAndCodeSequenceNumber(type.getId(), year, sequenceNumber)
.orElse(null);
}
@@ -137,7 +153,7 @@ public class ProjectService
}
@Override
public Page<Project> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<ProjectVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<Project> spec = null;
if (paramsNode.has("searchText")) {
spec = getSpecification(paramsNode.get("searchText").asText());
@@ -150,7 +166,7 @@ public class ProjectService
//
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "code");
return findAll(spec, pageable);
return findAll(spec, pageable).map(Project::toVo);
}
@CacheEvict(key = "#p0.id")
@@ -209,13 +225,14 @@ public class ProjectService
if (code.length() >= 6) {
try {
ProjectSaleType saleType = projectSaleTypeService.findByCode(code.substring(0, 1));
ProjectSaleTypeVo saleType = projectSaleTypeService.findByCode(code.substring(0, 1));
if (saleType == null) {
return null;
}
int codeYear = Integer.parseInt(code.substring(1, 3));
int sequenceNumber = Integer.parseInt(code.substring(3, 6));
optional = projectRepository.findBySaleTypeAndCodeYearAndCodeSequenceNumber(saleType, codeYear,
optional = projectRepository.findBySaleTypeIdAndCodeYearAndCodeSequenceNumber(saleType.getId(),
codeYear,
sequenceNumber);
if (optional.isPresent()) {
return optional.get();
@@ -251,9 +268,12 @@ public class ProjectService
}
}
ProjectSaleType saleType = projectSaleTypeService.findByCode(saleTypeCode);
ProjectSaleTypeVo saleType = projectSaleTypeService.findByCode(saleTypeCode);
if (saleType != null) {
project.setSaleType(saleType);
if (project.getSaleType() == null || !project.getSaleType().getId().equals(saleType.getId())) {
var v1 = projectSaleTypeService.getById(saleType.getId());
project.setSaleType(v1);
}
}
if (seqCode != null) {
@@ -270,25 +290,26 @@ public class ProjectService
project.setDeliverySignMethod(signMethod);
}
ProductType productType = productTypeService.findByCode(extCode.substring(1, 2));
ProductTypeVo productType = productTypeService.findByCode(extCode.substring(1, 2));
if (productType != null) {
project.setProductType(productType);
}
ProjectType projectType = projectTypeService.findByCode(extCode.substring(2, 3));
if (projectType != null) {
project.setProjectType(projectType);
project.setProductType(productTypeService.getById(productType.getId()));
}
ProjectIndustry industry = projectIndustryService.findByCode(extCode.substring(3, 4));
ProjectTypeVo projectType = projectTypeService.findByCode(extCode.substring(2, 3));
if (projectType != null) {
project.setProjectType(projectTypeService.getById(projectType.getId()));
}
ProjectIndustryVo industry = projectIndustryService.findByCode(extCode.substring(3, 4));
if (industry != null) {
project.setIndustry(industry);
project.setIndustry(projectIndustryService.getById(industry.getId()));
}
}
// 扩展至 5个后缀编码
if (extCode.length() > 4) {
ProductUsage productUsage = productUsageService.findByCode(extCode.substring(4, 5));
ProductUsageVo productUsage = productUsageService.findByCode(extCode.substring(4, 5));
if (productUsage != null) {
project.setProductUsage(productUsage);
project.setProductUsage(productUsageService.getById(productUsage.getId()));
}
}
}
@@ -315,23 +336,72 @@ public class ProjectService
project.setName(vo.getName());
project.setCode(vo.getCode());
project.setCreated(vo.getCreated());
project.setProjectType(
vo.getProjectTypeId() != null ? projectTypeService.findById(vo.getProjectTypeId()) : null);
project.setSaleType(vo.getSaleTypeId() != null ? projectSaleTypeService.findById(vo.getSaleTypeId()) : null);
project.setIndustry(vo.getIndustryId() != null ? projectIndustryService.findById(vo.getIndustryId()) : null);
project.setProductType(
vo.getProductTypeId() != null ? productTypeService.findById(vo.getProductTypeId()) : null);
project.setProductUsage(
vo.getProductUsageId() != null ? productUsageService.findById(vo.getProductUsageId()) : null);
project.setDeliverySignMethod(
vo.getDeliverySignMethodId() != null ? deliverySignMethodService.findById(vo.getDeliverySignMethodId())
: null);
project.setCustomer(
vo.getCustomerId() != null ? SpringApp.getBean(CompanyService.class).findById(vo.getCustomerId())
: null);
project.setApplicant(
vo.getApplicantId() != null ? SpringApp.getBean(EmployeeService.class).findById(vo.getApplicantId())
: null);
if (vo.getProjectTypeId() == null) {
project.setProjectType(null);
} else {
if (project.getProjectType() == null || !project.getProjectType().getId().equals(vo.getProjectTypeId())) {
project.setProjectType(projectTypeService.getById(vo.getProjectTypeId()));
}
}
if (vo.getSaleTypeId() == null) {
project.setSaleType(null);
} else {
if (project.getSaleType() == null || !project.getSaleType().getId().equals(vo.getSaleTypeId())) {
project.setSaleType(projectSaleTypeService.getById(vo.getSaleTypeId()));
}
}
if (vo.getIndustryId() == null) {
project.setIndustry(null);
} else {
if (project.getIndustry() == null || !project.getIndustry().getId().equals(vo.getIndustryId())) {
project.setIndustry(projectIndustryService.getById(vo.getIndustryId()));
}
}
if (vo.getProductTypeId() == null) {
project.setProductType(null);
} else {
if (project.getProductType() == null || !project.getProductType().getId().equals(vo.getProductTypeId())) {
project.setProductType(productTypeService.getById(vo.getProductTypeId()));
}
}
if (vo.getProductUsageId() == null) {
project.setProductUsage(null);
} else {
if (project.getProductUsage() == null
|| !project.getProductUsage().getId().equals(vo.getProductUsageId())) {
project.setProductUsage(productUsageService.getById(vo.getProductUsageId()));
}
}
if (vo.getDeliverySignMethodId() == null) {
project.setDeliverySignMethod(null);
} else {
if (project.getDeliverySignMethod() == null
|| !project.getDeliverySignMethod().getId().equals(vo.getDeliverySignMethodId())) {
project.setDeliverySignMethod(deliverySignMethodService.getById(vo.getDeliverySignMethodId()));
}
}
if (vo.getCustomerId() == null) {
project.setCustomer(null);
} else {
if (project.getCustomer() == null || !project.getCustomer().getId().equals(vo.getCustomerId())) {
project.setCustomer(SpringApp.getBean(CompanyService.class).getById(vo.getCustomerId()));
}
}
if (vo.getApplicantId() == null) {
project.setApplicant(null);
} else {
if (project.getApplicant() == null || !project.getApplicant().getId().equals(vo.getApplicantId())) {
project.setApplicant(SpringApp.getBean(EmployeeService.class).getById(vo.getApplicantId()));
}
}
project.setDescription(vo.getDescription());
project.setAmount(vo.getAmount());
project.setCodeYear(vo.getCodeYear());

View File

@@ -23,7 +23,7 @@ public class ProjectStringConverter extends EntityStringConverter<Project> {
@PostConstruct
private void init() {
setInitialized(project -> service.findById(project.getId()));
setInitialized(project -> service.getById(project.getId()));
setSuggestion(service::search);
setFromString(service::findByName);
}

Some files were not shown because too many files have changed in this diff Show More