拆分模块
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
package com.ecep.contract.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.SpringApp;
|
||||
import com.ecep.contract.cloud.u8.YongYouU8Service;
|
||||
import com.ecep.contract.controller.company.CompanyWindowController;
|
||||
import com.ecep.contract.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.model.CloudYu;
|
||||
import com.ecep.contract.model.Company;
|
||||
import com.ecep.contract.ui.table.cell.CompanyTableCell;
|
||||
import com.ecep.contract.ui.table.cell.LocalDateTimeTableCell;
|
||||
import com.ecep.contract.vm.CloudYuInfoViewModel;
|
||||
|
||||
import jakarta.persistence.criteria.Path;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.control.ContextMenu;
|
||||
import javafx.scene.control.MenuItem;
|
||||
import lombok.Setter;
|
||||
|
||||
public class YongYouU8ManagerSkin
|
||||
extends
|
||||
AbstEntityManagerSkin<CloudYu, CloudYuInfoViewModel, YongYouU8ManagerSkin, YongYouU8ManagerWindowController>
|
||||
implements ManagerSkin {
|
||||
@Setter
|
||||
private YongYouU8Service u8Service;
|
||||
@Setter
|
||||
private CompanyService companyService;
|
||||
|
||||
public YongYouU8ManagerSkin(YongYouU8ManagerWindowController controller) {
|
||||
super(controller);
|
||||
}
|
||||
|
||||
YongYouU8Service getU8Service() {
|
||||
if (u8Service == null) {
|
||||
u8Service = SpringApp.getBean(YongYouU8Service.class);
|
||||
}
|
||||
return u8Service;
|
||||
}
|
||||
|
||||
CompanyService getCompanyService() {
|
||||
if (companyService == null) {
|
||||
companyService = SpringApp.getBean(CompanyService.class);
|
||||
}
|
||||
return companyService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CloudYuInfoViewModel> loadTableData() {
|
||||
String searchText = controller.searchKeyField.getText();
|
||||
Specification<CloudYu> spec = null;
|
||||
if (StringUtils.hasText(searchText)) {
|
||||
|
||||
Specification<CloudYu> companySpec = (root, query, builder) -> {
|
||||
Path<Object> company = root.get("company");
|
||||
return builder.or(
|
||||
builder.like(company.get("name"), "%" + searchText + "%"),
|
||||
builder.like(company.get("shortName"), "%" + searchText + "%"));
|
||||
};
|
||||
|
||||
Specification<CloudYu> cloudIdSpec = (root, query, builder) -> {
|
||||
return builder.like(root.get("cloudId"), "%" + searchText + "%");
|
||||
};
|
||||
|
||||
Specification<CloudYu> exceptionSpec = (root, query, builder) -> {
|
||||
return builder.like(root.get("exceptionMessage"), "%" + searchText + "%");
|
||||
};
|
||||
spec = Specification.anyOf(companySpec, cloudIdSpec, exceptionSpec);
|
||||
}
|
||||
|
||||
Page<CloudYu> page = getU8Service().findAll(spec, getPageable());
|
||||
updateFooter(page);
|
||||
return page.map(CloudYuInfoViewModel::from).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeTable() {
|
||||
controller.idColumn.setCellValueFactory(param -> param.getValue().getId());
|
||||
controller.companyColumn.setCellValueFactory(param -> param.getValue().getCompany());
|
||||
controller.companyColumn.setCellFactory(param -> new CompanyTableCell<>(getCompanyService()));
|
||||
|
||||
controller.cloudIdColumn.setCellValueFactory(param -> param.getValue().getCloudId());
|
||||
|
||||
controller.latestUpdateColumn.setCellValueFactory(param -> param.getValue().getLatest());
|
||||
controller.latestUpdateColumn.setCellFactory(param -> new LocalDateTimeTableCell<>());
|
||||
|
||||
controller.cloudLatestColumn.setCellValueFactory(param -> param.getValue().getCloudLatest());
|
||||
controller.cloudLatestColumn.setCellFactory(param -> new LocalDateTimeTableCell<>());
|
||||
|
||||
controller.descriptionColumn.setCellValueFactory(param -> param.getValue().getVendorCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createContextMenu(ContextMenu contextMenu) {
|
||||
MenuItem item2 = new MenuItem("刷新");
|
||||
item2.setOnAction(this::onTableRefreshAction);
|
||||
|
||||
MenuItem item3 = new MenuItem("清空备注");
|
||||
item3.setOnAction(this::onTableClearDescriptionAction);
|
||||
|
||||
contextMenu.getItems().addAll(item2, item3);
|
||||
}
|
||||
|
||||
/**
|
||||
* 请空选择行的注释
|
||||
*
|
||||
* @param event event
|
||||
*/
|
||||
public void onTableClearDescriptionAction(ActionEvent event) {
|
||||
ObservableList<CloudYuInfoViewModel> selectedItems = getTableView().getSelectionModel().getSelectedItems();
|
||||
if (selectedItems.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (CloudYuInfoViewModel selectedItem : selectedItems) {
|
||||
CloudYu cloudYu = getU8Service().findById(selectedItem.getId().get());
|
||||
selectedItem.getCustomerCode().set("");
|
||||
if (selectedItem.copyTo(cloudYu)) {
|
||||
CloudYu saved = getU8Service().save(cloudYu);
|
||||
selectedItem.update(saved);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTableRowDoubleClickedAction(CloudYuInfoViewModel item) {
|
||||
Company company = item.getCompany().get();
|
||||
if (!Hibernate.isInitialized(item)) {
|
||||
company = getCompanyService().findById(company.getId());
|
||||
}
|
||||
CompanyWindowController.show(company, getTableView().getScene().getWindow());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user