refactor: 移除冗余方法并优化查询逻辑
移除多个服务类中重复的findAll方法实现,统一使用父类方法 优化QueryService的findOneByProperty实现,提高可读性 为EntityService添加aliasFor方法支持字段别名 修复ContractVerifyWindowController的消息处理逻辑 添加查看验证状态的功能菜单项
This commit is contained in:
@@ -12,6 +12,9 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.logging.Level;
|
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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -50,13 +53,6 @@ import javafx.collections.ObservableList;
|
|||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.FXMLLoader;
|
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.scene.layout.HBox;
|
||||||
import javafx.stage.FileChooser;
|
import javafx.stage.FileChooser;
|
||||||
import javafx.stage.Modality;
|
import javafx.stage.Modality;
|
||||||
@@ -79,6 +75,7 @@ public class ContractVerifyWindowController extends BaseController {
|
|||||||
return super.show(loader, owner, modality);
|
return super.show(loader, owner, modality);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
@Getter
|
@Getter
|
||||||
public static class MessageExt extends Message {
|
public static class MessageExt extends Message {
|
||||||
@@ -90,12 +87,16 @@ public class ContractVerifyWindowController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public static class Model implements MessageHolder {
|
public static class Model {
|
||||||
private SimpleStringProperty code = new SimpleStringProperty();
|
private SimpleStringProperty code = new SimpleStringProperty();
|
||||||
private SimpleStringProperty name = new SimpleStringProperty();
|
private SimpleStringProperty name = new SimpleStringProperty();
|
||||||
private SimpleObjectProperty<Integer> employee = new SimpleObjectProperty<>();
|
private SimpleObjectProperty<Integer> employee = new SimpleObjectProperty<>();
|
||||||
private SimpleObjectProperty<LocalDate> setupDate = new SimpleObjectProperty<>();
|
private SimpleObjectProperty<LocalDate> setupDate = new SimpleObjectProperty<>();
|
||||||
private SimpleListProperty<MessageExt> messages = new SimpleListProperty<>(FXCollections.observableArrayList());
|
private SimpleListProperty<MessageExt> messages = new SimpleListProperty<>(FXCollections.observableArrayList());
|
||||||
|
}
|
||||||
|
|
||||||
|
static class MessageHolderImpl implements MessageHolder {
|
||||||
|
List<MessageExt> messages = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addMessage(Level level, String message) {
|
public void addMessage(Level level, String message) {
|
||||||
@@ -261,6 +262,8 @@ public class ContractVerifyWindowController extends BaseController {
|
|||||||
long total = contractService.count(params);
|
long total = contractService.count(params);
|
||||||
setStatus("合同:" + total + " 条");
|
setStatus("合同:" + total + " 条");
|
||||||
|
|
||||||
|
MessageHolderImpl messageHolder = new MessageHolderImpl();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (isCloseRequested()) {
|
if (isCloseRequested()) {
|
||||||
break;
|
break;
|
||||||
@@ -268,6 +271,7 @@ public class ContractVerifyWindowController extends BaseController {
|
|||||||
|
|
||||||
Page<ContractVo> page = contractService.findAll(params, pageRequest);
|
Page<ContractVo> page = contractService.findAll(params, pageRequest);
|
||||||
for (ContractVo contract : page) {
|
for (ContractVo contract : page) {
|
||||||
|
messageHolder.messages.clear();
|
||||||
if (isCloseRequested()) {
|
if (isCloseRequested()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -285,11 +289,11 @@ public class ContractVerifyWindowController extends BaseController {
|
|||||||
model.getName().set(contract.getName());
|
model.getName().set(contract.getName());
|
||||||
model.getSetupDate().set(contract.getSetupDate());
|
model.getSetupDate().set(contract.getSetupDate());
|
||||||
|
|
||||||
comm.verify(contract, model);
|
comm.verify(contract, messageHolder);
|
||||||
setStatus("合同验证进度:" + counter.get() + " / " + total);
|
setStatus("合同验证进度:" + counter.get() + " / " + total);
|
||||||
// 移除中间消息
|
// 移除中间消息
|
||||||
if (!model.getMessages().isEmpty()) {
|
if (!messageHolder.messages.isEmpty()) {
|
||||||
model.getMessages().removeIf(msg -> msg.getLevel().intValue() <= Level.INFO.intValue());
|
model.getMessages().setAll(messageHolder.messages.stream().filter(msg -> msg.getLevel().intValue() > Level.INFO.intValue()).limit(50).toList());
|
||||||
}
|
}
|
||||||
if (model.getMessages().isEmpty()) {
|
if (model.getMessages().isEmpty()) {
|
||||||
if (onlyShowVerifiedChecker.isSelected()) {
|
if (onlyShowVerifiedChecker.isSelected()) {
|
||||||
@@ -325,6 +329,7 @@ public class ContractVerifyWindowController extends BaseController {
|
|||||||
}
|
}
|
||||||
runAsync(() -> {
|
runAsync(() -> {
|
||||||
ContractVo contract = null;
|
ContractVo contract = null;
|
||||||
|
MessageHolderImpl messageHolder = new MessageHolderImpl();
|
||||||
try {
|
try {
|
||||||
contract = contractService.findByCode(contractCode);
|
contract = contractService.findByCode(contractCode);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -336,17 +341,18 @@ public class ContractVerifyWindowController extends BaseController {
|
|||||||
}
|
}
|
||||||
model.getMessages().clear();
|
model.getMessages().clear();
|
||||||
try {
|
try {
|
||||||
comm.verify(contract, model);
|
comm.verify(contract, messageHolder);
|
||||||
// 移除中间消息
|
|
||||||
if (!model.getMessages().isEmpty()) {
|
|
||||||
model.getMessages().removeIf(msg -> msg.getLevel().intValue() <= Level.INFO.intValue());
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error(model.getCode().get(), 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(() -> {
|
Platform.runLater(() -> {
|
||||||
viewTableDataSet.remove(model);
|
viewTableDataSet.remove(model);
|
||||||
});
|
});
|
||||||
@@ -380,6 +386,38 @@ public class ContractVerifyWindowController extends BaseController {
|
|||||||
ContractWindowController.show(contract, viewTable.getScene().getWindow());
|
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) {
|
public void onExportVerifyResultAsFileAction(ActionEvent e) {
|
||||||
FileChooser chooser = new FileChooser();
|
FileChooser chooser = new FileChooser();
|
||||||
chooser.setTitle("导出核验结果");
|
chooser.setTitle("导出核验结果");
|
||||||
|
|||||||
@@ -13,6 +13,12 @@ import com.ecep.contract.vo.ContractVo;
|
|||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ContractFileService extends QueryService<ContractFileVo, ContractFileViewModel> {
|
public class ContractFileService extends QueryService<ContractFileVo, ContractFileViewModel> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ContractFileVo findById(Integer id) {
|
||||||
|
return super.findById(id);
|
||||||
|
}
|
||||||
|
|
||||||
public List<ContractFileVo> findAllByContract(ContractVo contract) {
|
public List<ContractFileVo> findAllByContract(ContractVo contract) {
|
||||||
return findAll(ParamUtils.equal("contract", contract.getId()), Pageable.unpaged()).getContent();
|
return findAll(ParamUtils.equal("contract", contract.getId()), Pageable.unpaged()).getContent();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,11 +26,11 @@ public class ProjectSaleTypeService extends QueryService<ProjectSaleTypeVo, Proj
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ProjectSaleTypeVo findByCode(String code) {
|
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) {
|
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")})
|
@Caching(evict = {@CacheEvict(key = "#p0.id")})
|
||||||
|
|||||||
@@ -188,8 +188,9 @@ public class QueryService<T extends IdentityEntity, TV extends IdentityViewModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
public T findOneByProperty(String propertyName, Object propertyValue) {
|
public T findOneByProperty(String propertyName, Object propertyValue) {
|
||||||
return findAll(ParamUtils.builder().equals(propertyName, propertyValue).build(), Pageable.ofSize(1)).stream()
|
ParamUtils.Builder paramBuilder = ParamUtils.builder().equals(propertyName, propertyValue);
|
||||||
.findFirst().orElse(null);
|
Page<T> page = findAll(paramBuilder.build(), Pageable.ofSize(1));
|
||||||
|
return page.stream().findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -373,7 +373,10 @@ public class ContractVerifyComm implements BeanContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CompanyVo company = getCompanyService().findById(bidVendor.getCompanyId());
|
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 (contractFile == null) {
|
||||||
if (requireQuotation && bidVendor.getCompanyId().equals(contract.getCompanyId())) {
|
if (requireQuotation && bidVendor.getCompanyId().equals(contract.getCompanyId())) {
|
||||||
|
|||||||
@@ -105,9 +105,9 @@
|
|||||||
<contextMenu>
|
<contextMenu>
|
||||||
<ContextMenu>
|
<ContextMenu>
|
||||||
<items>
|
<items>
|
||||||
<MenuItem mnemonicParsing="false" onAction="#onShowContractDetailAction"
|
<MenuItem mnemonicParsing="false" onAction="#onShowContractDetailAction" text="合同详情"/>
|
||||||
text="合同详情"/>
|
|
||||||
<MenuItem mnemonicParsing="false" onAction="#onContractReVerifyAction" text="重新验证"/>
|
<MenuItem mnemonicParsing="false" onAction="#onContractReVerifyAction" text="重新验证"/>
|
||||||
|
<MenuItem mnemonicParsing="false" onAction="#onShowVerifyStatusAction" text="查看状态"/>
|
||||||
</items>
|
</items>
|
||||||
</ContextMenu>
|
</ContextMenu>
|
||||||
</contextMenu>
|
</contextMenu>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.ecep.contract;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.ecep.contract.constant.ParamConstant;
|
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.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
@@ -226,6 +227,8 @@ public abstract class EntityService<T extends Voable<VO>, VO, ID> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
field = aliasFor(field, filterNode);
|
||||||
|
|
||||||
if (ParamConstant.KEY_equal.equals(operatorStr)) {
|
if (ParamConstant.KEY_equal.equals(operatorStr)) {
|
||||||
return buildEqualSpecification(field, filterNode);
|
return buildEqualSpecification(field, filterNode);
|
||||||
}
|
}
|
||||||
@@ -251,6 +254,17 @@ public abstract class EntityService<T extends Voable<VO>, VO, ID> {
|
|||||||
return null;
|
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,
|
private <X extends Comparable<? super X>> Specification<T> buildLessThanSpecification(String field,
|
||||||
JsonNode filterNode) {
|
JsonNode filterNode) {
|
||||||
JsonNode valueNode = filterNode.get(ParamConstant.KEY_VALUE);
|
JsonNode valueNode = filterNode.get(ParamConstant.KEY_VALUE);
|
||||||
@@ -343,11 +357,29 @@ public abstract class EntityService<T extends Voable<VO>, VO, ID> {
|
|||||||
path = path.get(segment);
|
path = path.get(segment);
|
||||||
}
|
}
|
||||||
Class<?> clz = path.getJavaType();
|
Class<?> clz = path.getJavaType();
|
||||||
if (IdentityEntity.class.isAssignableFrom(clz) && valueNode.isNumber()) {
|
if (IdentityEntity.class.isAssignableFrom(clz)) {
|
||||||
return cb.equal(path.get("id"), valueNode.asInt());
|
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);
|
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()
|
// Object value = valueNode.isTextual() ? valueNode.asText()
|
||||||
// : valueNode.isNumber() ? valueNode.numberValue()
|
// : valueNode.isNumber() ? valueNode.numberValue()
|
||||||
// : valueNode.isBoolean() ? valueNode.asBoolean() : valueNode;
|
// : valueNode.isBoolean() ? valueNode.asBoolean() : valueNode;
|
||||||
@@ -366,16 +398,35 @@ public abstract class EntityService<T extends Voable<VO>, VO, ID> {
|
|||||||
JsonNode filterNode) {
|
JsonNode filterNode) {
|
||||||
// BETWEEN 操作符:要求 value 为数组,且长度=2
|
// BETWEEN 操作符:要求 value 为数组,且长度=2
|
||||||
JsonNode valueNode = filterNode.get(ParamConstant.KEY_VALUE);
|
JsonNode valueNode = filterNode.get(ParamConstant.KEY_VALUE);
|
||||||
if (valueNode == null || !valueNode.isArray() || valueNode.size() != 2) {
|
JsonNode lowNode, highNode;
|
||||||
log.debug("BETWEEN 操作符需要 value 为包含两个元素的数组");
|
boolean includeBegin = false, includeEnd = false;
|
||||||
return null;
|
if (valueNode == null || valueNode.isNull()) {
|
||||||
|
throw new IllegalArgumentException(field + " 的 BETWEEN 操作符需要参数");
|
||||||
}
|
}
|
||||||
JsonNode lowNode = valueNode.get(0);
|
if (valueNode.isArray()) {
|
||||||
JsonNode highNode = valueNode.get(1);
|
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()) {
|
if (lowNode == null || highNode == null || lowNode.isNull() || highNode.isNull()) {
|
||||||
log.debug("BETWEEN 操作符的 value 数组元素不能为空");
|
throw new IllegalArgumentException(field + " 的 BETWEEN 操作符的 value 数组元素不能为空");
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (root, query, cb) -> {
|
return (root, query, cb) -> {
|
||||||
// 支持嵌套属性路径,如 company.id
|
// 支持嵌套属性路径,如 company.id
|
||||||
String[] fieldPath = field.split("\\.");
|
String[] fieldPath = field.split("\\.");
|
||||||
|
|||||||
@@ -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) {
|
protected Specification<CompanyFile> buildSearchSpecification(String searchText) {
|
||||||
return (root, query, builder) -> {
|
return (root, query, builder) -> {
|
||||||
|
|||||||
@@ -137,10 +137,6 @@ public class CompanyOldNameService extends EntityService<CompanyOldName, Company
|
|||||||
return companyOldNameRepository.findAllByName(name);
|
return companyOldNameRepository.findAllByName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<CompanyOldName> findAll(Specification<CompanyOldName> spec, Sort sort) {
|
|
||||||
return companyOldNameRepository.findAll(spec, sort);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<CompanyOldName> findAllByCompany(Company company) {
|
public List<CompanyOldName> findAllByCompany(Company company) {
|
||||||
return companyOldNameRepository.findAllByCompanyId(company.getId());
|
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
|
@Override
|
||||||
public Page<CompanyOldName> findAll(Specification<CompanyOldName> spec, Pageable pageable) {
|
protected String aliasFor(String field, JsonNode filterNode) {
|
||||||
return companyOldNameRepository.findAll(spec, pageable);
|
if ("company".equals(field)) {
|
||||||
}
|
return "company.id";
|
||||||
|
|
||||||
@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());
|
|
||||||
}
|
}
|
||||||
if (paramsNode.has("company")) {
|
return super.aliasFor(field, filterNode);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompanyOldName createNew(Company company, String name, boolean ambiguity) {
|
public CompanyOldName createNew(Company company, String name, boolean ambiguity) {
|
||||||
|
|||||||
@@ -232,12 +232,6 @@ public class HolidayService extends EntityService<HolidayTable, HolidayTableVo,
|
|||||||
return entityPage.map(HolidayTable::toVo);
|
return entityPage.map(HolidayTable::toVo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long count(JsonNode paramsNode) {
|
|
||||||
// 简单实现,返回所有节假日数量
|
|
||||||
return holidayTableRepository.count();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateByVo(HolidayTable model, HolidayTableVo vo) {
|
public void updateByVo(HolidayTable model, HolidayTableVo vo) {
|
||||||
if (model == null || vo == null) {
|
if (model == null || vo == null) {
|
||||||
|
|||||||
@@ -110,17 +110,6 @@ public class ContractBidVendorService extends EntityService<ContractBidVendor, C
|
|||||||
return new ContractBidVendor();
|
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
|
@Override
|
||||||
public void updateByVo(ContractBidVendor model, ContractBidVendorVo vo) {
|
public void updateByVo(ContractBidVendor model, ContractBidVendorVo vo) {
|
||||||
// 处理关联对象
|
// 处理关联对象
|
||||||
|
|||||||
@@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建参数规范
|
* 构建参数规范
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -45,11 +45,6 @@ public class ContractKindService extends EntityService<ContractKind, ContractKin
|
|||||||
return repository.findById(id).map(ContractKind::toVo).orElse(null);
|
return repository.findById(id).map(ContractKind::toVo).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Page<ContractKindVo> findAll(JsonNode paramsNode, Pageable pageable) {
|
|
||||||
return super.findAll(paramsNode, pageable);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Specification<ContractKind> buildParameterSpecification(JsonNode paramsNode) {
|
protected Specification<ContractKind> buildParameterSpecification(JsonNode paramsNode) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -98,11 +98,6 @@ public class ExtendVendorInfoService extends EntityService<ExtendVendorInfo, Ext
|
|||||||
repository.delete(bidVendor);
|
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) {
|
public List<ExtendVendorInfo> findAll(Specification<ExtendVendorInfo> spec, Sort sort) {
|
||||||
return repository.findAll(spec, sort);
|
return repository.findAll(spec, sort);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,11 +55,6 @@ public class PurchaseOrderItemService extends EntityService<PurchaseOrderItem, P
|
|||||||
return list.getFirst().toVo();
|
return list.getFirst().toVo();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Page<PurchaseOrderItemVo> findAll(JsonNode paramsNode, Pageable pageable) {
|
|
||||||
return super.findAll(paramsNode, pageable);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Caching(evict = {
|
@Caching(evict = {
|
||||||
@CacheEvict(key = "#p0.id"),
|
@CacheEvict(key = "#p0.id"),
|
||||||
@CacheEvict(key = "'refId-'+#p0.refId")
|
@CacheEvict(key = "'refId-'+#p0.refId")
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.cache.annotation.CacheConfig;
|
import org.springframework.cache.annotation.CacheConfig;
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
import org.springframework.context.annotation.Lazy;
|
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.data.jpa.domain.Specification;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -64,17 +62,6 @@ public class EmployeeLoginHistoryService extends EntityService<EmployeeLoginHist
|
|||||||
return repository.findById(id).map(EmployeeLoginHistory::toVo).orElse(null);
|
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
|
@Override
|
||||||
@CacheEvict(key = "#p0.id")
|
@CacheEvict(key = "#p0.id")
|
||||||
|
|||||||
@@ -67,7 +67,16 @@ public class EmployeeService extends EntityService<Employee, EmployeeVo, Integer
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected org.springframework.data.jpa.domain.Specification<Employee> buildSearchSpecification(String searchText) {
|
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);
|
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 + "%"));
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据搜索文本查询员工列表
|
* 根据搜索文本查询员工列表
|
||||||
|
|||||||
@@ -48,17 +48,6 @@ public class ProjectFundPlanService extends EntityService<ProjectFundPlan, Proje
|
|||||||
return null;
|
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 = {
|
@Caching(evict = {
|
||||||
@CacheEvict(key = "#p0.id"),
|
@CacheEvict(key = "#p0.id"),
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user