refactor: 移除冗余方法并优化查询逻辑

移除多个服务类中重复的findAll方法实现,统一使用父类方法
优化QueryService的findOneByProperty实现,提高可读性
为EntityService添加aliasFor方法支持字段别名
修复ContractVerifyWindowController的消息处理逻辑
添加查看验证状态的功能菜单项
This commit is contained in:
2025-12-15 00:04:32 +08:00
parent 3cf3a717be
commit 4e738bea3c
18 changed files with 166 additions and 207 deletions

View File

@@ -12,6 +12,9 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import javafx.scene.Node;
import javafx.scene.control.*;
import org.controlsfx.control.PopOver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -50,13 +53,6 @@ import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Button;
import javafx.scene.control.CheckMenuItem;
import javafx.scene.control.DatePicker;
import javafx.scene.control.Label;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.HBox;
import javafx.stage.FileChooser;
import javafx.stage.Modality;
@@ -79,6 +75,7 @@ public class ContractVerifyWindowController extends BaseController {
return super.show(loader, owner, modality);
}
@Setter
@Getter
public static class MessageExt extends Message {
@@ -90,12 +87,16 @@ public class ContractVerifyWindowController extends BaseController {
}
@Data
public static class Model implements MessageHolder {
public static class Model {
private SimpleStringProperty code = new SimpleStringProperty();
private SimpleStringProperty name = new SimpleStringProperty();
private SimpleObjectProperty<Integer> employee = new SimpleObjectProperty<>();
private SimpleObjectProperty<LocalDate> setupDate = new SimpleObjectProperty<>();
private SimpleListProperty<MessageExt> messages = new SimpleListProperty<>(FXCollections.observableArrayList());
}
static class MessageHolderImpl implements MessageHolder {
List<MessageExt> messages = new ArrayList<>();
@Override
public void addMessage(Level level, String message) {
@@ -261,6 +262,8 @@ public class ContractVerifyWindowController extends BaseController {
long total = contractService.count(params);
setStatus("合同:" + total + "");
MessageHolderImpl messageHolder = new MessageHolderImpl();
while (true) {
if (isCloseRequested()) {
break;
@@ -268,6 +271,7 @@ public class ContractVerifyWindowController extends BaseController {
Page<ContractVo> page = contractService.findAll(params, pageRequest);
for (ContractVo contract : page) {
messageHolder.messages.clear();
if (isCloseRequested()) {
break;
}
@@ -285,11 +289,11 @@ public class ContractVerifyWindowController extends BaseController {
model.getName().set(contract.getName());
model.getSetupDate().set(contract.getSetupDate());
comm.verify(contract, model);
comm.verify(contract, messageHolder);
setStatus("合同验证进度:" + counter.get() + " / " + total);
// 移除中间消息
if (!model.getMessages().isEmpty()) {
model.getMessages().removeIf(msg -> msg.getLevel().intValue() <= Level.INFO.intValue());
if (!messageHolder.messages.isEmpty()) {
model.getMessages().setAll(messageHolder.messages.stream().filter(msg -> msg.getLevel().intValue() > Level.INFO.intValue()).limit(50).toList());
}
if (model.getMessages().isEmpty()) {
if (onlyShowVerifiedChecker.isSelected()) {
@@ -325,6 +329,7 @@ public class ContractVerifyWindowController extends BaseController {
}
runAsync(() -> {
ContractVo contract = null;
MessageHolderImpl messageHolder = new MessageHolderImpl();
try {
contract = contractService.findByCode(contractCode);
} catch (Exception e) {
@@ -336,17 +341,18 @@ public class ContractVerifyWindowController extends BaseController {
}
model.getMessages().clear();
try {
comm.verify(contract, model);
// 移除中间消息
if (!model.getMessages().isEmpty()) {
model.getMessages().removeIf(msg -> msg.getLevel().intValue() <= Level.INFO.intValue());
}
comm.verify(contract, messageHolder);
} catch (Exception e) {
logger.error(model.getCode().get(), e);
model.error(e.getMessage());
messageHolder.error(e.getMessage());
}
if (model.getMessages().isEmpty()) {
// 移除中间消息
if (!messageHolder.messages.isEmpty()) {
model.getMessages().setAll(messageHolder.messages.stream().filter(msg -> msg.getLevel().intValue() > Level.INFO.intValue()).limit(50).toList());
}
if (messageHolder.messages.isEmpty()) {
Platform.runLater(() -> {
viewTableDataSet.remove(model);
});
@@ -380,6 +386,38 @@ public class ContractVerifyWindowController extends BaseController {
ContractWindowController.show(contract, viewTable.getScene().getWindow());
}
public void onShowVerifyStatusAction(ActionEvent event) {
// 在新新窗口中显示 状态消息 Model# messages
Model selectedItem = viewTable.getSelectionModel().getSelectedItem();
if (selectedItem == null) {
return;
}
ListView<MessageExt> listView = new ListView<>();
listView.setItems(selectedItem.messages);
listView.setCellFactory(v -> new ListCell<>() {
@Override
protected void updateItem(MessageExt item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setText(null);
setGraphic(null);
} else {
setText(item.getMessage());
setGraphic(new Label(item.getPrefix()));
}
}
});
PopOver popOver = new PopOver(listView);
popOver.setArrowLocation(PopOver.ArrowLocation.TOP_LEFT);
MenuItem menuItem = (MenuItem) event.getSource();
Node node = viewTable.lookup(".table-row-cell:selected");
popOver.show(node);
}
public void onExportVerifyResultAsFileAction(ActionEvent e) {
FileChooser chooser = new FileChooser();
chooser.setTitle("导出核验结果");

View File

@@ -13,6 +13,12 @@ import com.ecep.contract.vo.ContractVo;
@Service
public class ContractFileService extends QueryService<ContractFileVo, ContractFileViewModel> {
@Override
public ContractFileVo findById(Integer id) {
return super.findById(id);
}
public List<ContractFileVo> findAllByContract(ContractVo contract) {
return findAll(ParamUtils.equal("contract", contract.getId()), Pageable.unpaged()).getContent();
}

View File

@@ -26,11 +26,11 @@ public class ProjectSaleTypeService extends QueryService<ProjectSaleTypeVo, Proj
}
public ProjectSaleTypeVo findByCode(String code) {
return findAll(ParamUtils.builder().equals("code", code).build(), Pageable.ofSize(1)).getContent().getFirst();
return findOneByProperty("code", code);
}
public ProjectSaleTypeVo findByName(String name) {
return findAll(ParamUtils.builder().equals("name", name).build(), Pageable.ofSize(1)).getContent().getFirst();
return findOneByProperty("name", name);
}
@Caching(evict = {@CacheEvict(key = "#p0.id")})

View File

@@ -188,8 +188,9 @@ public class QueryService<T extends IdentityEntity, TV extends IdentityViewModel
}
public T findOneByProperty(String propertyName, Object propertyValue) {
return findAll(ParamUtils.builder().equals(propertyName, propertyValue).build(), Pageable.ofSize(1)).stream()
.findFirst().orElse(null);
ParamUtils.Builder paramBuilder = ParamUtils.builder().equals(propertyName, propertyValue);
Page<T> page = findAll(paramBuilder.build(), Pageable.ofSize(1));
return page.stream().findFirst().orElse(null);
}
/**

View File

@@ -373,7 +373,10 @@ public class ContractVerifyComm implements BeanContext {
}
CompanyVo company = getCompanyService().findById(bidVendor.getCompanyId());
ContractFileVo contractFile = fileService.findById(bidVendor.getQuotationSheetFileId());
ContractFileVo contractFile = null;
if (bidVendor.getQuotationSheetFileId() != null) {
contractFile = fileService.findById(bidVendor.getQuotationSheetFileId());
}
// 报价表文件不存在
if (contractFile == null) {
if (requireQuotation && bidVendor.getCompanyId().equals(contract.getCompanyId())) {

View File

@@ -105,9 +105,9 @@
<contextMenu>
<ContextMenu>
<items>
<MenuItem mnemonicParsing="false" onAction="#onShowContractDetailAction"
text="合同详情"/>
<MenuItem mnemonicParsing="false" onAction="#onShowContractDetailAction" text="合同详情"/>
<MenuItem mnemonicParsing="false" onAction="#onContractReVerifyAction" text="重新验证"/>
<MenuItem mnemonicParsing="false" onAction="#onShowVerifyStatusAction" text="查看状态"/>
</items>
</ContextMenu>
</contextMenu>

View File

@@ -3,6 +3,7 @@ package com.ecep.contract;
import java.util.List;
import com.ecep.contract.constant.ParamConstant;
import org.hibernate.query.sqm.tree.domain.SqmBasicValuedSimplePath;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
@@ -22,7 +23,7 @@ import lombok.extern.slf4j.Slf4j;
/**
* 实体服务基类
* 提供基础的CRUD操作和查询方法
*
*
* @param <T> 实体类型
* @param <VO> VO类型
* @param <ID> 主键类型
@@ -32,7 +33,7 @@ public abstract class EntityService<T extends Voable<VO>, VO, ID> {
/**
* 获取实体数据访问层接口
* 子类必须实现此方法,提供具体的实体数据访问层实例
*
*
* @return 实体数据访问层接口
*/
protected abstract MyRepository<T, ID> getRepository();
@@ -45,14 +46,14 @@ public abstract class EntityService<T extends Voable<VO>, VO, ID> {
* 创建新实体实例
* 设置默认值或必要的属性
* 实例是游离态的,未存储到数据库
*
*
* @return 新实体实例
*/
public abstract T createNewEntity();
/**
* 统计所有实体数量
*
*
* @return 实体数量
*/
public long count() {
@@ -61,7 +62,7 @@ public abstract class EntityService<T extends Voable<VO>, VO, ID> {
/**
* 根据查询规范统计实体数量
*
*
* @param spec 查询规范
* @return 符合规范的实体数量
*/
@@ -71,7 +72,7 @@ public abstract class EntityService<T extends Voable<VO>, VO, ID> {
/**
* 根据JSON参数节点统计实体数量
*
*
* @param paramsNode JSON参数节点
* @return 符合参数节点规范的实体数量
*/
@@ -81,7 +82,7 @@ public abstract class EntityService<T extends Voable<VO>, VO, ID> {
/**
* 保存实体到数据库
*
*
* @param entity 要保存的实体
* @return 保存后的实体
*/
@@ -91,7 +92,7 @@ public abstract class EntityService<T extends Voable<VO>, VO, ID> {
/**
* 删除实体
*
*
* @param entity 要删除的实体
*/
public void delete(T entity) {
@@ -103,7 +104,7 @@ public abstract class EntityService<T extends Voable<VO>, VO, ID> {
/**
* 应用JSON参数节点到查询规范
*
*
* @param node JSON参数节点
* @return 应用参数节点后的查询规范
*/
@@ -121,7 +122,7 @@ public abstract class EntityService<T extends Voable<VO>, VO, ID> {
/**
* 根据JSON参数节点查询所有实体
*
*
* @param paramsNode JSON参数节点
* @param pageable 分页信息
* @return 符合参数节点规范的实体分页结果
@@ -132,7 +133,7 @@ public abstract class EntityService<T extends Voable<VO>, VO, ID> {
/**
* 根据查询规范查询所有实体
*
*
* @param spec 查询规范
* @param pageable 分页信息
* @return 符合规范的实体分页结果
@@ -143,7 +144,7 @@ public abstract class EntityService<T extends Voable<VO>, VO, ID> {
/**
* 根据查询规范查询所有实体
*
*
* @param spec 查询规范
* @param sort 排序信息
* @return 符合规范的实体列表
@@ -154,7 +155,7 @@ public abstract class EntityService<T extends Voable<VO>, VO, ID> {
/**
* 根据搜索文本查询所有实体
*
*
* @param searchText 搜索文本
* @return 符合搜索文本规范的实体列表
*/
@@ -165,7 +166,7 @@ public abstract class EntityService<T extends Voable<VO>, VO, ID> {
/**
* 根据搜索文本构建查询规范
*
*
* @param searchText 搜索文本
* @return 符合搜索文本规范的查询规范
*/
@@ -178,7 +179,7 @@ public abstract class EntityService<T extends Voable<VO>, VO, ID> {
/**
* 构建搜索规范
*
*
* @param searchText 搜索文本,非空
* @return 符合搜索文本规范的查询规范
*/
@@ -186,7 +187,7 @@ public abstract class EntityService<T extends Voable<VO>, VO, ID> {
/**
* 构建过滤条件规范
*
*
* @param filterNode 过滤条件节点
* @return 过滤条件规范
*/
@@ -226,6 +227,8 @@ public abstract class EntityService<T extends Voable<VO>, VO, ID> {
return null;
}
field = aliasFor(field, filterNode);
if (ParamConstant.KEY_equal.equals(operatorStr)) {
return buildEqualSpecification(field, filterNode);
}
@@ -251,6 +254,17 @@ public abstract class EntityService<T extends Voable<VO>, VO, ID> {
return null;
}
/**
* 为查询字段添加别名
*
* @param field
* @param filterNode
* @return
*/
protected String aliasFor(String field, JsonNode filterNode) {
return field;
}
private <X extends Comparable<? super X>> Specification<T> buildLessThanSpecification(String field,
JsonNode filterNode) {
JsonNode valueNode = filterNode.get(ParamConstant.KEY_VALUE);
@@ -324,7 +338,7 @@ public abstract class EntityService<T extends Voable<VO>, VO, ID> {
/**
* 等于操作符的逻辑
*
*
* @param field
* @param filterNode
* @return
@@ -343,11 +357,29 @@ public abstract class EntityService<T extends Voable<VO>, VO, ID> {
path = path.get(segment);
}
Class<?> clz = path.getJavaType();
if (IdentityEntity.class.isAssignableFrom(clz) && valueNode.isNumber()) {
return cb.equal(path.get("id"), valueNode.asInt());
if (IdentityEntity.class.isAssignableFrom(clz)) {
if (valueNode.isNumber()) {
return cb.equal(path.get("id"), valueNode.asInt());
}
if (valueNode.isObject() && valueNode.has("id")) {
JsonNode identity = valueNode.get("id");
if (identity.isNumber()) {
return cb.equal(path.get("id"), identity.asInt());
}
}
}
if (clz == java.lang.Enum.class) {
// 将字符串转换为对应的枚举值
clz = ((SqmBasicValuedSimplePath) path).getExpressibleJavaType().getJavaTypeClass();
}
ObjectMapper objectMapper = SpringApp.getBean(ObjectMapper.class);
Object value = objectMapper.convertValue(valueNode, clz);
Object value = null;
try {
value = objectMapper.convertValue(valueNode, clz);
} catch (Exception e) {
throw new RuntimeException("field=" + field + ", clz=" + clz.getName() + ", value=" + valueNode, e);
}
// Object value = valueNode.isTextual() ? valueNode.asText()
// : valueNode.isNumber() ? valueNode.numberValue()
// : valueNode.isBoolean() ? valueNode.asBoolean() : valueNode;
@@ -357,7 +389,7 @@ public abstract class EntityService<T extends Voable<VO>, VO, ID> {
/**
* BETWEEN 操作符的逻辑
*
*
* @param field
* @param filterNode
* @return
@@ -366,16 +398,35 @@ public abstract class EntityService<T extends Voable<VO>, VO, ID> {
JsonNode filterNode) {
// BETWEEN 操作符:要求 value 为数组,且长度=2
JsonNode valueNode = filterNode.get(ParamConstant.KEY_VALUE);
if (valueNode == null || !valueNode.isArray() || valueNode.size() != 2) {
log.debug("BETWEEN 操作符需要 value 为包含两个元素的数组");
return null;
JsonNode lowNode, highNode;
boolean includeBegin = false, includeEnd = false;
if (valueNode == null || valueNode.isNull()) {
throw new IllegalArgumentException(field + " 的 BETWEEN 操作符需要参数");
}
JsonNode lowNode = valueNode.get(0);
JsonNode highNode = valueNode.get(1);
if (valueNode.isArray()) {
if (valueNode.size() != 2) {
throw new IllegalArgumentException(field + " 的 BETWEEN 操作符的 value 数组长度必须为 2");
}
lowNode = valueNode.get(0);
highNode = valueNode.get(1);
} else if (valueNode.isObject()) {
lowNode = valueNode.get(ParamConstant.KEY_between_begin);
highNode = valueNode.get(ParamConstant.KEY_between_end);
if (valueNode.has(ParamConstant.KEY_INCLUDE_BEGIN)) {
includeBegin = valueNode.get(ParamConstant.KEY_INCLUDE_BEGIN).asBoolean();
}
if (valueNode.has(ParamConstant.KEY_INCLUDE_END)) {
includeEnd = valueNode.get(ParamConstant.KEY_INCLUDE_END).asBoolean();
}
} else {
throw new IllegalArgumentException(field + " 的 BETWEEN 操作符的 value 必须为数组或对象");
}
if (lowNode == null || highNode == null || lowNode.isNull() || highNode.isNull()) {
log.debug("BETWEEN 操作符的 value 数组元素不能为空");
return null;
throw new IllegalArgumentException(field + "BETWEEN 操作符的 value 数组元素不能为空");
}
return (root, query, cb) -> {
// 支持嵌套属性路径,如 company.id
String[] fieldPath = field.split("\\.");

View File

@@ -442,27 +442,6 @@ public class CompanyFileService extends EntityService<CompanyFile, CompanyFileVo
}
@Override
public Page<CompanyFileVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<CompanyFile> spec = null;
if (paramsNode.has(ParamConstant.KEY_SEARCH_TEXT)) {
spec = getSearchSpecification(paramsNode.get(ParamConstant.KEY_SEARCH_TEXT).asText());
}
spec = SpecificationUtils.and(spec, buildParameterSpecification(paramsNode));
return findAll(spec, pageable).map(CompanyFile::toVo);
}
public Page<CompanyFile> findAll(Specification<CompanyFile> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
}
@Override
public Specification<CompanyFile> getSearchSpecification(String searchText) {
if (!StringUtils.hasText(searchText)) {
return null;
}
return SpecificationUtils.andWith(searchText, this::buildSearchSpecification);
}
protected Specification<CompanyFile> buildSearchSpecification(String searchText) {
return (root, query, builder) -> {

View File

@@ -137,10 +137,6 @@ public class CompanyOldNameService extends EntityService<CompanyOldName, Company
return companyOldNameRepository.findAllByName(name);
}
public List<CompanyOldName> findAll(Specification<CompanyOldName> spec, Sort sort) {
return companyOldNameRepository.findAll(spec, sort);
}
public List<CompanyOldName> findAllByCompany(Company company) {
return companyOldNameRepository.findAllByCompanyId(company.getId());
}
@@ -211,47 +207,12 @@ public class CompanyOldNameService extends EntityService<CompanyOldName, Company
}
}
/**
* 根据提供的搜索文本查询公司旧名称列表。
* <p>
* 该函数使用JPA的Specification接口构建查询条件查找公司旧名称中包含指定文本的记录。
* 查询结果最多返回10条记录。
*
* @param searchText 用于搜索的文本,将匹配公司旧名称中包含该文本的记录。
* @return 包含匹配的公司旧名称的列表列表中的每个元素都是一个CompanyOldName对象。
*/
public List<CompanyOldName> search(String searchText) {
return companyOldNameRepository.findAll(getSearchSpecification(searchText), Pageable.ofSize(10)).getContent();
}
@Override
public Page<CompanyOldName> findAll(Specification<CompanyOldName> spec, Pageable pageable) {
return companyOldNameRepository.findAll(spec, pageable);
}
@Override
public Page<CompanyOldNameVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<CompanyOldName> spec = null;
if (paramsNode.has(ParamConstant.KEY_SEARCH_TEXT)) {
spec = getSearchSpecification(paramsNode.get(ParamConstant.KEY_SEARCH_TEXT).asText());
protected String aliasFor(String field, JsonNode filterNode) {
if ("company".equals(field)) {
return "company.id";
}
if (paramsNode.has("company")) {
JsonNode param = paramsNode.get("company");
Integer companyId = null;
if (param.isInt()) {
companyId = param.asInt();
} else if (param.isObject()) {
companyId = param.get("id").asInt();
}
if (companyId != null) {
final int id = companyId;
spec = SpecificationUtils.and(spec, (root, query, builder) -> {
return builder.equal(root.get("companyId"), id);
});
}
}
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "name", "ambiguity", "beginDate", "endDate");
return findAll(spec, pageable).map(CompanyOldName::toVo);
return super.aliasFor(field, filterNode);
}
public CompanyOldName createNew(Company company, String name, boolean ambiguity) {

View File

@@ -232,12 +232,6 @@ public class HolidayService extends EntityService<HolidayTable, HolidayTableVo,
return entityPage.map(HolidayTable::toVo);
}
@Override
public long count(JsonNode paramsNode) {
// 简单实现,返回所有节假日数量
return holidayTableRepository.count();
}
@Override
public void updateByVo(HolidayTable model, HolidayTableVo vo) {
if (model == null || vo == null) {

View File

@@ -110,17 +110,6 @@ public class ContractBidVendorService extends EntityService<ContractBidVendor, C
return new ContractBidVendor();
}
@Override
public Page<ContractBidVendorVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ContractBidVendor> spec = null;
if (paramsNode.has("searchText")) {
spec = buildSearchSpecification(paramsNode.get("searchText").asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "contract", "company");
return findAll(spec, pageable).map(ContractBidVendor::toVo);
}
@Override
public void updateByVo(ContractBidVendor model, ContractBidVendorVo vo) {
// 处理关联对象

View File

@@ -144,11 +144,6 @@ public class ContractInvoiceService extends EntityService<ContractInvoice, Contr
}
@Override
public Page<ContractInvoiceVo> findAll(JsonNode paramsNode, Pageable pageable) {
return super.findAll(paramsNode, pageable);
}
/**
* 构建参数规范
*

View File

@@ -45,11 +45,6 @@ public class ContractKindService extends EntityService<ContractKind, ContractKin
return repository.findById(id).map(ContractKind::toVo).orElse(null);
}
@Override
public Page<ContractKindVo> findAll(JsonNode paramsNode, Pageable pageable) {
return super.findAll(paramsNode, pageable);
}
@Override
protected Specification<ContractKind> buildParameterSpecification(JsonNode paramsNode) {
return null;

View File

@@ -98,11 +98,6 @@ public class ExtendVendorInfoService extends EntityService<ExtendVendorInfo, Ext
repository.delete(bidVendor);
}
@Override
public Page<ExtendVendorInfoVo> findAll(JsonNode paramsNode, Pageable pageable) {
return super.findAll(paramsNode, pageable);
}
public List<ExtendVendorInfo> findAll(Specification<ExtendVendorInfo> spec, Sort sort) {
return repository.findAll(spec, sort);
}

View File

@@ -55,11 +55,6 @@ public class PurchaseOrderItemService extends EntityService<PurchaseOrderItem, P
return list.getFirst().toVo();
}
@Override
public Page<PurchaseOrderItemVo> findAll(JsonNode paramsNode, Pageable pageable) {
return super.findAll(paramsNode, pageable);
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'refId-'+#p0.refId")

View File

@@ -4,8 +4,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
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;
@@ -64,17 +62,6 @@ public class EmployeeLoginHistoryService extends EntityService<EmployeeLoginHist
return repository.findById(id).map(EmployeeLoginHistory::toVo).orElse(null);
}
@Override
public Page<EmployeeLoginHistoryVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<EmployeeLoginHistory> spec = null;
if (paramsNode.has("searchText")) {
spec = getSearchSpecification(paramsNode.get("searchText").asText());
}
// 可以根据需要添加更多参数处理
spec = SpecificationUtils.andParam(spec, paramsNode, "employee");
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "ip", "mac");
return findAll(spec, pageable).map(EmployeeLoginHistory::toVo);
}
@Override
@CacheEvict(key = "#p0.id")

View File

@@ -67,7 +67,16 @@ public class EmployeeService extends EntityService<Employee, EmployeeVo, Integer
@Override
protected org.springframework.data.jpa.domain.Specification<Employee> buildSearchSpecification(String searchText) {
return getSearchSpecification(searchText);
return (root, query, builder) -> {
// 使用或条件组合查询,以实现对员工代码或名称的模糊搜索
return builder.or(
builder.like(root.get("account"), "%" + searchText + "%"),
builder.like(root.get("name"), "%" + searchText + "%"),
builder.like(root.get("alias"), "%" + searchText + "%"),
builder.like(root.get("code"), "%" + searchText + "%"),
builder.like(root.get("email"), "%" + searchText + "%"),
builder.like(root.get("phone"), "%" + searchText + "%"));
};
}
/**
@@ -138,34 +147,6 @@ public class EmployeeService extends EntityService<Employee, EmployeeVo, Integer
employeeRepository.delete(employee);
}
@Override
public Page<EmployeeVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<Employee> spec = null;
if (paramsNode.has("searchText")) {
spec = getSearchSpecification(paramsNode.get("searchText").asText());
}
// 可以根据需要添加更多参数处理
spec = SpecificationUtils.andParam(spec, paramsNode, "department");
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "isActive");
return findAll(spec, pageable).map(Employee::toVo);
}
@Override
public Specification<Employee> getSearchSpecification(String searchText) {
if (!StringUtils.hasText(searchText)) {
return null;
}
return (root, query, builder) -> {
// 使用或条件组合查询,以实现对员工代码或名称的模糊搜索
return builder.or(
builder.like(root.get("account"), "%" + searchText + "%"),
builder.like(root.get("name"), "%" + searchText + "%"),
builder.like(root.get("alias"), "%" + searchText + "%"),
builder.like(root.get("code"), "%" + searchText + "%"),
builder.like(root.get("email"), "%" + searchText + "%"),
builder.like(root.get("phone"), "%" + searchText + "%"));
};
}
/**
* 根据搜索文本查询员工列表

View File

@@ -48,17 +48,6 @@ public class ProjectFundPlanService extends EntityService<ProjectFundPlan, Proje
return null;
}
@Override
public Page<ProjectFundPlanVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ProjectFundPlan> spec = null;
if (paramsNode.has("searchText")) {
spec = buildSearchSpecification(paramsNode.get("searchText").asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "project");
return findAll(spec, pageable).map(ProjectFundPlan::toVo);
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
})