拆分模块
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
package com.ecep.contract.manager;
|
||||
|
||||
import javafx.application.Application;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2017/4/16.
|
||||
*/
|
||||
public class AppV2 {
|
||||
private static final Logger logger = LoggerFactory.getLogger(AppV2.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
Application.launch(Desktop.class, args);
|
||||
done();
|
||||
}
|
||||
|
||||
private static void done() {
|
||||
logger.info("done");
|
||||
try {
|
||||
Desktop.shutdown();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
System.out.println("AppV2.done");
|
||||
}
|
||||
|
||||
public static final String DEFAULT_DB_HOST = "10.84.209.154"; // "db-server1.ecctrl.com"
|
||||
public static final String DEFAULT_DB_PORT = "3306";
|
||||
public static final String DEFAULT_DB_USERNAME = "supplier_ms";
|
||||
public static final String DEFAULT_DB_PASSWORD = "[TPdseO!JKMmlrpf";
|
||||
public static final String DEFAULT_DB_DATABASE = "supplier_ms";
|
||||
}
|
||||
@@ -1,187 +0,0 @@
|
||||
package com.ecep.contract.manager;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.manager.ds.other.model.Employee;
|
||||
import com.ecep.contract.manager.ds.other.model.EmployeeRole;
|
||||
import com.ecep.contract.manager.ds.other.service.EmployeeService;
|
||||
import com.ecep.contract.manager.ds.other.vo.EmployeeViewModel;
|
||||
import com.ecep.contract.manager.util.MyDateTimeUtils;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.SimpleListProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.util.converter.CurrencyStringConverter;
|
||||
import javafx.util.converter.LocalDateStringConverter;
|
||||
import javafx.util.converter.LocalDateTimeStringConverter;
|
||||
import javafx.util.converter.NumberStringConverter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* 当前登录用户
|
||||
*/
|
||||
@ToString(callSuper = false, exclude = "roles")
|
||||
public class CurrentEmployee extends EmployeeViewModel {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CurrentEmployee.class);
|
||||
/**
|
||||
* 语言环境
|
||||
*/
|
||||
private SimpleObjectProperty<Locale> locale = new SimpleObjectProperty<>(Locale.getDefault());
|
||||
/**
|
||||
* 角色
|
||||
*/
|
||||
private SimpleListProperty<EmployeeRole> roles = new SimpleListProperty<>(FXCollections.observableArrayList());
|
||||
|
||||
private DateTimeFormatter dateFormatter = DateTimeFormatter
|
||||
.ofPattern(MyDateTimeUtils.DEFAULT_DATE_FORMAT_PATTERN);
|
||||
private DateTimeFormatter dateTimeFormatter = DateTimeFormatter
|
||||
.ofPattern(MyDateTimeUtils.DEFAULT_DATETIME_FORMAT_PATTERN);
|
||||
private DateTimeFormatter timeFormatter = DateTimeFormatter
|
||||
.ofPattern(MyDateTimeUtils.DEFAULT_TIME_FORMAT_PATTERN);
|
||||
|
||||
private LocalDateStringConverter localDateStringConverter = new LocalDateStringConverter(
|
||||
dateFormatter, null);
|
||||
private LocalDateTimeStringConverter localDateTimeStringConverter = new LocalDateTimeStringConverter(
|
||||
dateTimeFormatter, null);
|
||||
|
||||
private NumberStringConverter numberStringConverter = new NumberStringConverter("#,##0.00");
|
||||
private CurrencyStringConverter currencyStringConverter = new CurrencyStringConverter("#,##0.00");
|
||||
|
||||
/**
|
||||
* 是否系统管理员
|
||||
*/
|
||||
public boolean isSystemAdministrator() {
|
||||
return roles.stream().anyMatch(EmployeeRole::isSystemAdministrator);
|
||||
}
|
||||
|
||||
/**
|
||||
* 语言环境属性
|
||||
*/
|
||||
public SimpleObjectProperty<Locale> localeProperty() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色属性
|
||||
*/
|
||||
public SimpleListProperty<EmployeeRole> rolesProperty() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateFrom(Employee v) {
|
||||
super.updateFrom(v);
|
||||
|
||||
// 根据用户的个人配置修改
|
||||
if (StringUtils.hasText(v.getLocale())) {
|
||||
try {
|
||||
localeProperty().set(Locale.forLanguageTag(v.getLocale()));
|
||||
} catch (Exception e) {
|
||||
handleException("解析设置用户区域设置失败," + v.getLocale(), e);
|
||||
}
|
||||
}
|
||||
if (StringUtils.hasText(v.getDateFormatter())) {
|
||||
try {
|
||||
dateFormatter = DateTimeFormatter.ofPattern(v.getDateFormatter());
|
||||
localDateStringConverter = new LocalDateStringConverter(dateFormatter, null);
|
||||
} catch (Exception e) {
|
||||
handleException("解析设置用户日期格式失败," + v.getDateFormatter(), e);
|
||||
}
|
||||
}
|
||||
if (StringUtils.hasText(v.getDateTimeFormatter())) {
|
||||
try {
|
||||
dateTimeFormatter = DateTimeFormatter.ofPattern(v.getDateTimeFormatter());
|
||||
localDateTimeStringConverter = new LocalDateTimeStringConverter(dateTimeFormatter, null);
|
||||
} catch (Exception e) {
|
||||
handleException("解析设置用户日期时间格式失败," + v.getDateTimeFormatter(), e);
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(v.getNumberFormatter())) {
|
||||
try {
|
||||
numberStringConverter = new NumberStringConverter(localeProperty().get(), v.getNumberFormatter());
|
||||
} catch (Exception e) {
|
||||
handleException("解析设置用户数字格式失败," + v.getNumberFormatter(), e);
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(v.getCurrencyFormatter())) {
|
||||
try {
|
||||
currencyStringConverter = new CurrencyStringConverter(localeProperty().get(), v.getCurrencyFormatter());
|
||||
} catch (Exception e) {
|
||||
handleException("解析设置用户货币格式失败," + v.getCurrencyFormatter(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
public CompletableFuture<Void> initialize() {
|
||||
CompletableFuture<Void> future = new CompletableFuture<>();
|
||||
ScheduledExecutorService executorService = Desktop.instance.getExecutorService();
|
||||
/**
|
||||
* 异步初始化当前用户
|
||||
* 1. 从数据库中查询当前用户
|
||||
* 2. 从数据库中查询当前用户的角色
|
||||
* 3. 更新当前用户的信息
|
||||
* 4. 更新当前用户的角色
|
||||
*/
|
||||
executorService.submit(() -> {
|
||||
// issue #1 sss 2020-07-05
|
||||
EmployeeService employeeService = SpringApp.getBean(EmployeeService.class);
|
||||
Employee employee = employeeService.findById(Desktop.instance.getActiveEmployeeId());
|
||||
List<EmployeeRole> roles = employeeService.getRolesByEmployeeId(employee.getId());
|
||||
Platform.runLater(() -> {
|
||||
update(employee);
|
||||
rolesProperty().setAll(roles);
|
||||
// 发布事件
|
||||
SpringApp.context.publishEvent(new CurrentEmployeeInitialedEvent(this));
|
||||
future.complete(null);
|
||||
});
|
||||
});
|
||||
/**
|
||||
* 定时更新用户活动状态
|
||||
*/
|
||||
executorService.scheduleWithFixedDelay(() -> {
|
||||
try {
|
||||
SpringApp.getBean(EmployeeService.class).updateActive(Desktop.instance.getSessionId());
|
||||
} catch (Exception e) {
|
||||
if (logger.isErrorEnabled()) {
|
||||
logger.error("updateActive:{}", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}, 10, 10, TimeUnit.SECONDS);
|
||||
return future;
|
||||
}
|
||||
|
||||
private void handleException(String msg, Exception e) {
|
||||
logger.warn(msg, e);
|
||||
}
|
||||
|
||||
public LocalDateStringConverter getLocalDateStringConverter() {
|
||||
return localDateStringConverter;
|
||||
}
|
||||
|
||||
public LocalDateTimeStringConverter getLocalDateTimeStringConverter() {
|
||||
return localDateTimeStringConverter;
|
||||
}
|
||||
|
||||
public NumberStringConverter getNumberStringConverter() {
|
||||
return numberStringConverter;
|
||||
}
|
||||
|
||||
public CurrencyStringConverter getCurrencyStringConverter() {
|
||||
return currencyStringConverter;
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.ecep.contract.manager;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
@Getter
|
||||
public class CurrentEmployeeInitialedEvent extends ApplicationEvent {
|
||||
private final CurrentEmployee employee;
|
||||
|
||||
public CurrentEmployeeInitialedEvent(CurrentEmployee employee) {
|
||||
super(employee);
|
||||
this.employee = employee;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CurrentEmployee getSource() {
|
||||
return employee;
|
||||
}
|
||||
}
|
||||
@@ -1,267 +0,0 @@
|
||||
package com.ecep.contract.manager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.FutureTask;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
|
||||
import com.ecep.contract.manager.ds.other.controller.LoginWidowController;
|
||||
import com.ecep.contract.manager.ui.BaseController;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import com.ecep.contract.manager.ui.task.TaskMonitorCenter;
|
||||
import com.ecep.contract.manager.util.UITools;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.StageStyle;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* JavaFx 应用程序
|
||||
*
|
||||
* @author ecep
|
||||
* Created by ecep on 2017/05/08.
|
||||
*/
|
||||
public class Desktop extends Application {
|
||||
public static final Logger logger = LoggerFactory.getLogger(Desktop.class);
|
||||
public static Desktop instance;
|
||||
|
||||
public static void shutdown() {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("shutdown");
|
||||
}
|
||||
if (instance != null) {
|
||||
try {
|
||||
instance.stop();
|
||||
} catch (Throwable e) {
|
||||
logger.error("shutdown error", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ScheduledExecutorService scheduledExecutorService = null;
|
||||
private final TaskMonitorCenter taskMonitorCenter = new TaskMonitorCenter();
|
||||
|
||||
private final SimpleIntegerProperty sessionId = new SimpleIntegerProperty(0);
|
||||
@Getter
|
||||
private final CurrentEmployee activeEmployee = new CurrentEmployee();
|
||||
|
||||
public void setActiveEmployeeId(int activeEmployeeId) {
|
||||
activeEmployee.getId().set(activeEmployeeId);
|
||||
}
|
||||
|
||||
public int getActiveEmployeeId() {
|
||||
return activeEmployee.getId().get();
|
||||
}
|
||||
|
||||
public int getSessionId() {
|
||||
return sessionId.get();
|
||||
}
|
||||
|
||||
public void setSessionId(int sessionId) {
|
||||
this.sessionId.set(sessionId);
|
||||
}
|
||||
|
||||
public ScheduledExecutorService getExecutorService() {
|
||||
if (scheduledExecutorService == null) {
|
||||
scheduledExecutorService = Executors.newScheduledThreadPool(3);
|
||||
}
|
||||
return scheduledExecutorService;
|
||||
}
|
||||
|
||||
public TaskMonitorCenter getTaskMonitorCenter() {
|
||||
return taskMonitorCenter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("start");
|
||||
}
|
||||
if (instance != null) {
|
||||
logger.error("Desktop already started");
|
||||
}
|
||||
instance = this;
|
||||
|
||||
URL resource = getClass().getResource("/ui/start_lamp.fxml");
|
||||
FXMLLoader loader = new FXMLLoader(resource);
|
||||
primaryStage.setTitle("CMS");
|
||||
primaryStage.initStyle(StageStyle.TRANSPARENT);
|
||||
|
||||
Parent root = loader.load();
|
||||
Scene scene = new Scene(root);
|
||||
scene.getStylesheets().add("/ui/start_lamp.css");
|
||||
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.setOnShown(e -> {
|
||||
System.out.println("primaryStage#OnShown");
|
||||
});
|
||||
primaryStage.show();
|
||||
System.out.println("Desktop.start -> primaryStage.show()");
|
||||
|
||||
try {
|
||||
startSpringApp(primaryStage, root, loader);
|
||||
} catch (Exception e) {
|
||||
UITools.showExceptionAndWait("启动失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
public CompletableFuture<Void> runAsync(Runnable runnable) {
|
||||
return CompletableFuture.runAsync(runnable, getExecutorService());
|
||||
}
|
||||
|
||||
private void startSpringApp(Stage primaryStage, Parent root, FXMLLoader loader) {
|
||||
System.out.println("Desktop.startSpringApp");
|
||||
// 更新窗口标题
|
||||
Node titleNode = root.lookup("#title");
|
||||
if (titleNode != null) {
|
||||
primaryStage.setTitle(((Text) titleNode).getText());
|
||||
}
|
||||
|
||||
Node lookup = root.lookup("#logBox");
|
||||
if (!(lookup instanceof VBox logBox)) {
|
||||
throw new RuntimeException("启动界面加载失败, #logger 类型错误");
|
||||
}
|
||||
|
||||
ScrollPane logPane = (ScrollPane) root.lookup("#logPane");
|
||||
|
||||
logBox.getChildren().clear();
|
||||
MessageHolder holder = (level, message) -> {
|
||||
Text text = new Text(message);
|
||||
if (Level.WARNING == level) { // warning
|
||||
text.setFill(Color.YELLOW);
|
||||
} else if (Level.SEVERE == level) {// error
|
||||
text.setFill(Color.RED);
|
||||
} else if (Level.FINE == level) { // debug
|
||||
text.setFill(Color.GRAY);
|
||||
} else {
|
||||
text.setFill(Color.WHITE);
|
||||
}
|
||||
Platform.runLater(() -> {
|
||||
logBox.getChildren().add(text);
|
||||
logPane.layout();
|
||||
logPane.setVvalue(1.0);
|
||||
});
|
||||
};
|
||||
|
||||
holder.info("启动中,请稍后...");
|
||||
|
||||
runAsync(() -> {
|
||||
try {
|
||||
//
|
||||
holder.info("读取配置文件...");
|
||||
Properties properties = new Properties();
|
||||
File configFile = new File("config.properties");
|
||||
if (configFile.exists()) {
|
||||
holder.debug("读取配置文件 " + configFile.getName() + "...");
|
||||
try (FileInputStream input = new FileInputStream(configFile)) {
|
||||
properties.load(input);
|
||||
holder.info("配置文件读取成功.");
|
||||
} catch (IOException e) {
|
||||
holder.error("读取失败:" + e.getMessage());
|
||||
logger.error(e.getMessage(), e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
runAsync(() -> {
|
||||
SpringApp.launch(properties, holder);
|
||||
ConfigurableListableBeanFactory beanFactory = SpringApp.context.getBeanFactory();
|
||||
|
||||
beanFactory.registerSingleton("scheduledExecutorService", getExecutorService());
|
||||
beanFactory.registerSingleton("taskMonitorCenter", taskMonitorCenter);
|
||||
});
|
||||
|
||||
try {
|
||||
LoginWidowController controller = new LoginWidowController();
|
||||
controller.setHolder(holder);
|
||||
controller.setPrimaryStage(primaryStage);
|
||||
controller.setProperties(properties);
|
||||
while (true) {
|
||||
controller.tryLogin();
|
||||
break;
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("login in");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
holder.error("登录失败:" + e.getMessage());
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
holder.error(e.getMessage());
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
});
|
||||
System.out.println("Desktop.startSpringApp.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() throws Exception {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("stop");
|
||||
}
|
||||
CompletableFuture<Void> future = BaseController.shutdown();
|
||||
future.orTimeout(5, TimeUnit.SECONDS);
|
||||
future.exceptionally(e -> {
|
||||
logger.error(e.getMessage(), e);
|
||||
return null;
|
||||
});
|
||||
future.thenRun(() -> {
|
||||
SpringApp.shutdown();
|
||||
try {
|
||||
shutdownExecutorService();
|
||||
super.stop();
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("stopped");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void shutdownExecutorService() {
|
||||
List<Runnable> runnableList = scheduledExecutorService.shutdownNow();
|
||||
for (Runnable runnable : runnableList) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("shutdown runnable = {}", runnable);
|
||||
}
|
||||
if (runnable instanceof FutureTask<?> future) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("runnable as future, isCancelled() = {}, isDone() = {}", future.isCancelled(),
|
||||
future.isDone());
|
||||
}
|
||||
if (future.cancel(true)) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("runnable as future canceled");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
scheduledExecutorService.close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,214 +0,0 @@
|
||||
package com.ecep.contract.manager;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.net.CookieStore;
|
||||
import java.net.HttpCookie;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
public class MyPersistentCookieStore implements CookieStore {
|
||||
|
||||
|
||||
private final File file;
|
||||
private final ObjectMapper objectMapper;
|
||||
private Map<URI, List<HttpCookie>> cookiesMap = new HashMap<>();
|
||||
|
||||
public MyPersistentCookieStore(File file, ObjectMapper objectMapper) {
|
||||
this.file = file;
|
||||
this.objectMapper = objectMapper;
|
||||
if (file != null && file.exists()) {
|
||||
loadFromFile2();
|
||||
}
|
||||
}
|
||||
|
||||
private void loadFromFile2() {
|
||||
try {
|
||||
ObjectNode root = (ObjectNode) objectMapper.readTree(file);
|
||||
for (Iterator<Map.Entry<String, JsonNode>> it = root.fields(); it.hasNext(); ) {
|
||||
Map.Entry<String, JsonNode> entry = it.next();
|
||||
String key = entry.getKey();
|
||||
ArrayNode value = (ArrayNode) entry.getValue();
|
||||
|
||||
List<HttpCookie> cookies = new ArrayList<>();
|
||||
for (JsonNode node1 : value) {
|
||||
HttpCookie cookie = new HttpCookie(node1.get("name").asText(), node1.get("value").asText());
|
||||
objectMapper.updateValue(node1, cookie);
|
||||
cookies.add(cookie);
|
||||
}
|
||||
URI uri = URI.create(key);
|
||||
System.out.println(key + " -> " + uri);
|
||||
cookiesMap.put(uri, cookies);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveToFile2() {
|
||||
try {
|
||||
objectMapper.writeValue(file, cookiesMap);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadFromFile(File file) {
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
// 假设格式为: name=value;domain=domain;path=path;expires=expires;
|
||||
String[] parts = line.split(";");
|
||||
String nameValue = parts[0];
|
||||
String[] nameValueParts = nameValue.split("=");
|
||||
String name = nameValueParts[0];
|
||||
String value = nameValueParts.length > 1 ? nameValueParts[1] : "";
|
||||
HttpCookie cookie = new HttpCookie(name, value);
|
||||
for (int i = 1; i < parts.length; i++) {
|
||||
String[] attribute = parts[i].split("=");
|
||||
if (attribute[0].equals("domain")) {
|
||||
cookie.setDomain(attribute[1]);
|
||||
} else if (attribute[0].equals("path")) {
|
||||
cookie.setPath(attribute[1]);
|
||||
} else if (attribute[0].equals("expires")) {
|
||||
// 解析日期格式并设置过期时间
|
||||
// 这里只是示例,实际需要正确解析日期格式
|
||||
Date expiresDate = new Date(Long.parseLong(attribute[1]));
|
||||
cookie.setMaxAge(expiresDate.getTime() - System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
URI uri = URI.create(cookie.getDomain());
|
||||
List<HttpCookie> cookies = cookiesMap.getOrDefault(uri, new ArrayList<>());
|
||||
cookies.add(cookie);
|
||||
cookiesMap.put(uri, cookies);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// 处理文件读取错误
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void saveToFile() {
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
|
||||
for (Map.Entry<URI, List<HttpCookie>> entry : cookiesMap.entrySet()) {
|
||||
for (HttpCookie cookie : entry.getValue()) {
|
||||
String line = cookie.getName() + "=" + cookie.getValue() + ";domain=" + cookie.getDomain() + ";path=" + cookie.getPath();
|
||||
if (cookie.getMaxAge() > 0) {
|
||||
line += ";expires=" + (System.currentTimeMillis() + cookie.getMaxAge());
|
||||
}
|
||||
writer.write(line);
|
||||
writer.newLine();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// 处理文件写入错误
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(URI uri, HttpCookie cookie) {
|
||||
if (cookie == null) {
|
||||
throw new NullPointerException("cookie is null");
|
||||
}
|
||||
|
||||
if (cookie.getDomain() != null) {
|
||||
URI key = getEffectiveURI(cookie);
|
||||
List<HttpCookie> cookies = cookiesMap.getOrDefault(key, new ArrayList<>());
|
||||
cookies.remove(cookie);
|
||||
cookies.add(cookie);
|
||||
cookiesMap.put(key, cookies);
|
||||
}
|
||||
|
||||
if (uri != null) {
|
||||
URI key = getEffectiveURI(uri);
|
||||
List<HttpCookie> cookies = cookiesMap.getOrDefault(key, new ArrayList<>());
|
||||
cookies.remove(cookie);
|
||||
cookies.add(cookie);
|
||||
cookiesMap.put(key, cookies);
|
||||
}
|
||||
saveToFile2();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HttpCookie> get(URI uri) {
|
||||
URI effectiveURI = getEffectiveURI(uri);
|
||||
System.out.println("effectiveURI = " + effectiveURI);
|
||||
return cookiesMap.getOrDefault(effectiveURI, new ArrayList<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HttpCookie> getCookies() {
|
||||
return cookiesMap.values().stream().flatMap(List::stream).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<URI> getURIs() {
|
||||
return cookiesMap.keySet().stream().toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(URI uri, HttpCookie cookie) {
|
||||
URI key = getEffectiveURI(uri);
|
||||
List<HttpCookie> httpCookies = cookiesMap.get(key);
|
||||
if (httpCookies == null) {
|
||||
return false;
|
||||
}
|
||||
return httpCookies.remove(cookie);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll() {
|
||||
cookiesMap.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
private URI getEffectiveURI(URI uri) {
|
||||
URI effectiveURI = null;
|
||||
try {
|
||||
effectiveURI = new URI("http",
|
||||
uri.getHost(),
|
||||
null, // path component
|
||||
null, // query component
|
||||
null // fragment component
|
||||
);
|
||||
} catch (URISyntaxException ignored) {
|
||||
ignored.printStackTrace();
|
||||
effectiveURI = uri;
|
||||
}
|
||||
|
||||
return effectiveURI;
|
||||
}
|
||||
|
||||
private URI getEffectiveURI(HttpCookie cookie) {
|
||||
URI effectiveURI = null;
|
||||
try {
|
||||
effectiveURI = new URI("http",
|
||||
cookie.getDomain(),
|
||||
null, // path component
|
||||
null, // query component
|
||||
null // fragment component
|
||||
);
|
||||
} catch (URISyntaxException ignored) {
|
||||
|
||||
}
|
||||
|
||||
return effectiveURI;
|
||||
}
|
||||
}
|
||||
@@ -1,436 +0,0 @@
|
||||
package com.ecep.contract.manager;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.CookieStore;
|
||||
import java.net.HttpCookie;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
public class MyPersistentCookieStore2 implements CookieStore {
|
||||
|
||||
|
||||
private final File file;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
private List<HttpCookie> cookieJar = null;
|
||||
|
||||
// the cookies are indexed by its domain and associated uri (if present)
|
||||
// CAUTION: when a cookie removed from main data structure (i.e. cookieJar),
|
||||
// it won't be cleared in domainIndex & uriIndex. Double-check the
|
||||
// presence of cookie when retrieve one form index store.
|
||||
private Map<String, List<HttpCookie>> domainIndex = null;
|
||||
private Map<URI, List<HttpCookie>> uriIndex = null;
|
||||
|
||||
// use ReentrantLock instead of synchronized for scalability
|
||||
private ReentrantLock lock = null;
|
||||
|
||||
|
||||
public MyPersistentCookieStore2(File file, ObjectMapper objectMapper) {
|
||||
this.file = file;
|
||||
this.objectMapper = objectMapper;
|
||||
cookieJar = new ArrayList<>();
|
||||
domainIndex = new HashMap<>();
|
||||
uriIndex = new HashMap<>();
|
||||
|
||||
lock = new ReentrantLock(false);
|
||||
|
||||
if (file != null && file.exists()) {
|
||||
loadFromFile2();
|
||||
}
|
||||
}
|
||||
|
||||
private void loadFromFile2() {
|
||||
try {
|
||||
ObjectNode root = (ObjectNode) objectMapper.readTree(file);
|
||||
|
||||
ArrayNode cookieJarNode = (ArrayNode) root.get("cookieJar");
|
||||
for (JsonNode node1 : cookieJarNode) {
|
||||
HttpCookie cookie = new HttpCookie(node1.get("name").asText(), node1.get("value").asText());
|
||||
objectMapper.updateValue(node1, cookie);
|
||||
cookieJar.add(cookie);
|
||||
}
|
||||
|
||||
|
||||
ObjectNode domainIndexNode = (ObjectNode) root.get("domainIndex");
|
||||
for (Iterator<Map.Entry<String, JsonNode>> it = domainIndexNode.fields(); it.hasNext(); ) {
|
||||
Map.Entry<String, JsonNode> entry = it.next();
|
||||
String key = entry.getKey();
|
||||
ArrayNode value = (ArrayNode) entry.getValue();
|
||||
|
||||
List<HttpCookie> cookies = new ArrayList<>();
|
||||
for (JsonNode node1 : value) {
|
||||
HttpCookie cookie = new HttpCookie(node1.get("name").asText(), node1.get("value").asText());
|
||||
objectMapper.updateValue(node1, cookie);
|
||||
cookies.add(cookie);
|
||||
}
|
||||
domainIndex.put(key, cookies);
|
||||
}
|
||||
|
||||
ObjectNode uriIndexNode = (ObjectNode) root.get("uriIndex");
|
||||
for (Iterator<Map.Entry<String, JsonNode>> it = uriIndexNode.fields(); it.hasNext(); ) {
|
||||
Map.Entry<String, JsonNode> entry = it.next();
|
||||
String key = entry.getKey();
|
||||
ArrayNode value = (ArrayNode) entry.getValue();
|
||||
|
||||
List<HttpCookie> cookies = new ArrayList<>();
|
||||
for (JsonNode node1 : value) {
|
||||
HttpCookie cookie = new HttpCookie(node1.get("name").asText(), node1.get("value").asText());
|
||||
objectMapper.updateValue(node1, cookie);
|
||||
cookies.add(cookie);
|
||||
}
|
||||
URI uri = URI.create(key);
|
||||
System.out.println(key + " -> " + uri);
|
||||
uriIndex.put(uri, cookies);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveToFile2() {
|
||||
try {
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("cookieJar", cookieJar);
|
||||
map.put("domainIndex", domainIndex);
|
||||
map.put("uriIndex", uriIndex);
|
||||
objectMapper.writeValue(file, map);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add one cookie into cookie store.
|
||||
*/
|
||||
public void add(URI uri, HttpCookie cookie) {
|
||||
// pre-condition : argument can't be null
|
||||
if (cookie == null) {
|
||||
throw new NullPointerException("cookie is null");
|
||||
}
|
||||
|
||||
|
||||
lock.lock();
|
||||
try {
|
||||
// remove the ole cookie if there has had one
|
||||
cookieJar.remove(cookie);
|
||||
|
||||
// add new cookie if it has a non-zero max-age
|
||||
if (cookie.getMaxAge() != 0) {
|
||||
cookieJar.add(cookie);
|
||||
// and add it to domain index
|
||||
if (cookie.getDomain() != null) {
|
||||
addIndex(domainIndex, cookie.getDomain(), cookie);
|
||||
}
|
||||
if (uri != null) {
|
||||
// add it to uri index, too
|
||||
addIndex(uriIndex, getEffectiveURI(uri), cookie);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
saveToFile2();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all cookies, which:
|
||||
* 1) given uri domain-matches with, or, associated with
|
||||
* given uri when added to the cookie store.
|
||||
* 3) not expired.
|
||||
* See RFC 2965 sec. 3.3.4 for more detail.
|
||||
*/
|
||||
public List<HttpCookie> get(URI uri) {
|
||||
// argument can't be null
|
||||
if (uri == null) {
|
||||
throw new NullPointerException("uri is null");
|
||||
}
|
||||
|
||||
List<HttpCookie> cookies = new ArrayList<>();
|
||||
boolean secureLink = "https".equalsIgnoreCase(uri.getScheme());
|
||||
lock.lock();
|
||||
try {
|
||||
// check domainIndex first
|
||||
getInternal1(cookies, domainIndex, uri.getHost(), secureLink);
|
||||
// check uriIndex then
|
||||
getInternal2(cookies, uriIndex, getEffectiveURI(uri), secureLink);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
return cookies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all cookies in cookie store, except those have expired
|
||||
*/
|
||||
public List<HttpCookie> getCookies() {
|
||||
List<HttpCookie> rt;
|
||||
|
||||
lock.lock();
|
||||
try {
|
||||
Iterator<HttpCookie> it = cookieJar.iterator();
|
||||
while (it.hasNext()) {
|
||||
if (it.next().hasExpired()) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
rt = Collections.unmodifiableList(cookieJar);
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
return rt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all URIs, which are associated with at least one cookie
|
||||
* of this cookie store.
|
||||
*/
|
||||
public List<URI> getURIs() {
|
||||
List<URI> uris = new ArrayList<>();
|
||||
|
||||
lock.lock();
|
||||
try {
|
||||
Iterator<URI> it = uriIndex.keySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
URI uri = it.next();
|
||||
List<HttpCookie> cookies = uriIndex.get(uri);
|
||||
if (cookies == null || cookies.size() == 0) {
|
||||
// no cookies list or an empty list associated with
|
||||
// this uri entry, delete it
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
uris.addAll(uriIndex.keySet());
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
return uris;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove a cookie from store
|
||||
*/
|
||||
public boolean remove(URI uri, HttpCookie ck) {
|
||||
// argument can't be null
|
||||
if (ck == null) {
|
||||
throw new NullPointerException("cookie is null");
|
||||
}
|
||||
|
||||
boolean modified = false;
|
||||
lock.lock();
|
||||
try {
|
||||
modified = cookieJar.remove(ck);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
return modified;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove all cookies in this cookie store.
|
||||
*/
|
||||
public boolean removeAll() {
|
||||
lock.lock();
|
||||
try {
|
||||
if (cookieJar.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
cookieJar.clear();
|
||||
domainIndex.clear();
|
||||
uriIndex.clear();
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* ---------------- Private operations -------------- */
|
||||
|
||||
|
||||
/*
|
||||
* This is almost the same as HttpCookie.domainMatches except for
|
||||
* one difference: It won't reject cookies when the 'H' part of the
|
||||
* domain contains a dot ('.').
|
||||
* I.E.: RFC 2965 section 3.3.2 says that if host is x.y.domain.com
|
||||
* and the cookie domain is .domain.com, then it should be rejected.
|
||||
* However that's not how the real world works. Browsers don't reject and
|
||||
* some sites, like yahoo.com do actually expect these cookies to be
|
||||
* passed along.
|
||||
* And should be used for 'old' style cookies (aka Netscape type of cookies)
|
||||
*/
|
||||
private boolean netscapeDomainMatches(String domain, String host) {
|
||||
if (domain == null || host == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// if there's no embedded dot in domain and domain is not .local
|
||||
boolean isLocalDomain = ".local".equalsIgnoreCase(domain);
|
||||
int embeddedDotInDomain = domain.indexOf('.');
|
||||
if (embeddedDotInDomain == 0) {
|
||||
embeddedDotInDomain = domain.indexOf('.', 1);
|
||||
}
|
||||
if (!isLocalDomain && (embeddedDotInDomain == -1 || embeddedDotInDomain == domain.length() - 1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// if the host name contains no dot and the domain name is .local
|
||||
int firstDotInHost = host.indexOf('.');
|
||||
if (firstDotInHost == -1 && isLocalDomain) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int domainLength = domain.length();
|
||||
int lengthDiff = host.length() - domainLength;
|
||||
if (lengthDiff == 0) {
|
||||
// if the host name and the domain name are just string-compare equal
|
||||
return host.equalsIgnoreCase(domain);
|
||||
} else if (lengthDiff > 0) {
|
||||
// need to check H & D component
|
||||
String H = host.substring(0, lengthDiff);
|
||||
String D = host.substring(lengthDiff);
|
||||
|
||||
return (D.equalsIgnoreCase(domain));
|
||||
} else if (lengthDiff == -1) {
|
||||
// if domain is actually .host
|
||||
return (domain.charAt(0) == '.' &&
|
||||
host.equalsIgnoreCase(domain.substring(1)));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void getInternal1(List<HttpCookie> cookies, Map<String, List<HttpCookie>> cookieIndex,
|
||||
String host, boolean secureLink) {
|
||||
// Use a separate list to handle cookies that need to be removed so
|
||||
// that there is no conflict with iterators.
|
||||
ArrayList<HttpCookie> toRemove = new ArrayList<>();
|
||||
for (Map.Entry<String, List<HttpCookie>> entry : cookieIndex.entrySet()) {
|
||||
String domain = entry.getKey();
|
||||
List<HttpCookie> lst = entry.getValue();
|
||||
for (HttpCookie c : lst) {
|
||||
if ((c.getVersion() == 0 && netscapeDomainMatches(domain, host)) ||
|
||||
(c.getVersion() == 1 && HttpCookie.domainMatches(domain, host))) {
|
||||
if ((cookieJar.indexOf(c) != -1)) {
|
||||
// the cookie still in main cookie store
|
||||
if (!c.hasExpired()) {
|
||||
// don't add twice and make sure it's the proper
|
||||
// security level
|
||||
if ((secureLink || !c.getSecure()) &&
|
||||
!cookies.contains(c)) {
|
||||
cookies.add(c);
|
||||
}
|
||||
} else {
|
||||
toRemove.add(c);
|
||||
}
|
||||
} else {
|
||||
// the cookie has been removed from main store,
|
||||
// so also remove it from domain indexed store
|
||||
toRemove.add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Clear up the cookies that need to be removed
|
||||
for (HttpCookie c : toRemove) {
|
||||
lst.remove(c);
|
||||
cookieJar.remove(c);
|
||||
|
||||
}
|
||||
toRemove.clear();
|
||||
}
|
||||
}
|
||||
|
||||
// @param cookies [OUT] contains the found cookies
|
||||
// @param cookieIndex the index
|
||||
// @param comparator the prediction to decide whether or not
|
||||
// a cookie in index should be returned
|
||||
private <T> void getInternal2(List<HttpCookie> cookies,
|
||||
Map<T, List<HttpCookie>> cookieIndex,
|
||||
Comparable<T> comparator, boolean secureLink) {
|
||||
for (T index : cookieIndex.keySet()) {
|
||||
if (comparator.compareTo(index) == 0) {
|
||||
List<HttpCookie> indexedCookies = cookieIndex.get(index);
|
||||
// check the list of cookies associated with this domain
|
||||
if (indexedCookies != null) {
|
||||
Iterator<HttpCookie> it = indexedCookies.iterator();
|
||||
while (it.hasNext()) {
|
||||
HttpCookie ck = it.next();
|
||||
if (cookieJar.indexOf(ck) != -1) {
|
||||
// the cookie still in main cookie store
|
||||
if (!ck.hasExpired()) {
|
||||
// don't add twice
|
||||
if ((secureLink || !ck.getSecure()) &&
|
||||
!cookies.contains(ck))
|
||||
cookies.add(ck);
|
||||
} else {
|
||||
it.remove();
|
||||
cookieJar.remove(ck);
|
||||
}
|
||||
} else {
|
||||
// the cookie has been removed from main store,
|
||||
// so also remove it from domain indexed store
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
} // end of indexedCookies != null
|
||||
} // end of comparator.compareTo(index) == 0
|
||||
} // end of cookieIndex iteration
|
||||
}
|
||||
|
||||
// add 'cookie' indexed by 'index' into 'indexStore'
|
||||
private <T> void addIndex(Map<T, List<HttpCookie>> indexStore,
|
||||
T index,
|
||||
HttpCookie cookie) {
|
||||
if (index != null) {
|
||||
List<HttpCookie> cookies = indexStore.get(index);
|
||||
if (cookies != null) {
|
||||
// there may already have the same cookie, so remove it first
|
||||
cookies.remove(cookie);
|
||||
|
||||
cookies.add(cookie);
|
||||
} else {
|
||||
cookies = new ArrayList<>();
|
||||
cookies.add(cookie);
|
||||
indexStore.put(index, cookies);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// for cookie purpose, the effective uri should only be http://host
|
||||
// the path will be taken into account when path-match algorithm applied
|
||||
//
|
||||
private URI getEffectiveURI(URI uri) {
|
||||
URI effectiveURI = null;
|
||||
try {
|
||||
effectiveURI = new URI("http",
|
||||
uri.getHost(),
|
||||
null, // path component
|
||||
null, // query component
|
||||
null // fragment component
|
||||
);
|
||||
} catch (URISyntaxException ignored) {
|
||||
effectiveURI = uri;
|
||||
}
|
||||
|
||||
return effectiveURI;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.ecep.contract.manager;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "my")
|
||||
public class MyProperties {
|
||||
@Getter
|
||||
@Setter
|
||||
private String downloadsPath;
|
||||
|
||||
|
||||
/**
|
||||
* 尝试返回当前用户的下载文件夹
|
||||
*/
|
||||
public File getDownloadDirectory() {
|
||||
String downloadsPath = getDownloadsPath();
|
||||
if (StringUtils.hasText(downloadsPath)) {
|
||||
return new File(downloadsPath);
|
||||
}
|
||||
|
||||
// 没有配置下载目录时,尝试使用默认设置
|
||||
String home = System.getProperty("user.home");
|
||||
Path path = Paths.get(home, "Downloads");
|
||||
return path.toFile();
|
||||
}
|
||||
}
|
||||
@@ -1,262 +0,0 @@
|
||||
package com.ecep.contract.manager;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.boot.ConfigurableBootstrapContext;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.SpringApplicationHook;
|
||||
import org.springframework.boot.SpringApplicationRunListener;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
|
||||
import org.springframework.boot.context.metrics.buffering.StartupTimeline;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cache.caffeine.CaffeineCacheManager;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.event.ContextClosedEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.PropertiesPropertySource;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.core.metrics.StartupStep;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
import com.ecep.contract.manager.cloud.CloudRepositoriesConfig;
|
||||
import com.ecep.contract.manager.ds.DsRepositoriesConfig;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import com.ecep.contract.manager.util.MyDateTimeUtils;
|
||||
import com.ecep.contract.manager.util.UITools;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
|
||||
|
||||
@SpringBootApplication(exclude = { org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration.class })
|
||||
@EnableScheduling
|
||||
@EnableAsync
|
||||
@EnableCaching
|
||||
public class SpringApp {
|
||||
private static final Logger logger = LoggerFactory.getLogger(SpringApp.class);
|
||||
|
||||
static SpringApplication application;
|
||||
static ConfigurableApplicationContext context;
|
||||
|
||||
public static <T> T getBean(Class<T> requiredType) throws BeansException {
|
||||
return context.getBean(requiredType);
|
||||
}
|
||||
|
||||
public static void launch(Properties properties, MessageHolder holder) {
|
||||
application = new SpringApplication(SpringApp.class);
|
||||
BufferingApplicationStartup startup = new BufferingApplicationStartup(2000);
|
||||
application.setApplicationStartup(startup);
|
||||
//
|
||||
holder.debug("应用程序环境准备中...");
|
||||
SpringApplication.withHook(new Hook(holder), () -> {
|
||||
// 动态地注册或修改这些组件和配置
|
||||
application.addBootstrapRegistryInitializer(registry -> {
|
||||
//
|
||||
System.out.println("registry = " + registry);
|
||||
|
||||
});
|
||||
application.addListeners(event -> {
|
||||
logger.debug("SpringApp.launch ApplicationListener, event:{}", event);
|
||||
});
|
||||
|
||||
application.addInitializers(app -> {
|
||||
logger.debug("SpringApp.launch ApplicationContextInitializer");
|
||||
ConfigurableEnvironment environment = app.getEnvironment();
|
||||
logger.debug("environment = {}", environment);
|
||||
PropertySource<?> dynamicProperties = environment.getPropertySources().get("dynamicProperties");
|
||||
if (dynamicProperties != null) {
|
||||
logger.debug("dynamicProperties = {}", dynamicProperties);
|
||||
}
|
||||
environment.getPropertySources().addLast(new PropertiesPropertySource("dynamicProperties", properties));
|
||||
// app.getBeanFactory().registerSingleton("dataSource", dataSource());
|
||||
logger.debug("app = {}", app);
|
||||
|
||||
if (app instanceof AnnotationConfigApplicationContext ctx) {
|
||||
ctx.register(DsRepositoriesConfig.class);
|
||||
ctx.register(CloudRepositoriesConfig.class);
|
||||
}
|
||||
});
|
||||
|
||||
startup.start("");
|
||||
context = application.run();
|
||||
logger.debug("SpringApp.launch application.run().");
|
||||
Duration between = Duration.between(startup.getBufferedTimeline().getStartTime(), Instant.now());
|
||||
holder.info("应用程序环境加载完成... " + between);
|
||||
});
|
||||
CompletableFuture.runAsync(() -> {
|
||||
// 在这里调用 startup 性能分析
|
||||
analyzeStartupPerformance(startup);
|
||||
}, Desktop.instance.getExecutorService());
|
||||
}
|
||||
|
||||
/**
|
||||
* 分析启动性能数据并输出到日志
|
||||
*/
|
||||
private static void analyzeStartupPerformance(BufferingApplicationStartup startup) {
|
||||
// 获取所有记录的事件
|
||||
StartupTimeline timeline = startup.getBufferedTimeline();
|
||||
if (timeline == null || timeline.getEvents().isEmpty()) {
|
||||
logger.warn("StartupTimeline 为空或没有事件!");
|
||||
return;
|
||||
}
|
||||
logger.info("总共有 {} 个事件", timeline.getEvents().size());
|
||||
|
||||
// 找出与 Bean 初始化相关的步骤
|
||||
timeline.getEvents().stream()
|
||||
.filter(event -> event.getStartupStep().getName().startsWith("spring.beans."))
|
||||
.sorted((a, b) -> Long.compare(b.getDuration().toMillis(), a.getDuration().toMillis()))
|
||||
.limit(30)
|
||||
.forEach(event -> {
|
||||
String name = event.getStartupStep().getName();
|
||||
long duration = event.getDuration().toMillis();
|
||||
logger.info("Bean 初始化阶段: {} - 耗时: {} ms", name, duration);
|
||||
|
||||
for (StartupStep.Tag tag : event.getStartupStep().getTags()) {
|
||||
if ("beanName".equals(tag.getKey())) {
|
||||
logger.info(" └── Bean 名称: {}", tag.getValue());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static String getMessage(String code, Object[] args, Locale locale) {
|
||||
return context.getMessage(code, args, locale);
|
||||
}
|
||||
|
||||
public static void shutdown() {
|
||||
System.out.println("SpringApp.shutdown");
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("shutdown");
|
||||
}
|
||||
if (context != null) {
|
||||
if (context.isRunning()) {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isRunning() {
|
||||
return context != null && context.isRunning();
|
||||
}
|
||||
|
||||
static class Hook implements SpringApplicationHook, SpringApplicationRunListener {
|
||||
MessageHolder holder;
|
||||
|
||||
Hook(MessageHolder holder) {
|
||||
this.holder = holder;
|
||||
}
|
||||
|
||||
public void debug(String msg) {
|
||||
holder.debug(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void starting(ConfigurableBootstrapContext bootstrapContext) {
|
||||
logger.debug("Desktop.starting");
|
||||
debug("Spring Application 启动中...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void environmentPrepared(ConfigurableBootstrapContext bootstrapContext,
|
||||
ConfigurableEnvironment environment) {
|
||||
logger.debug("Desktop.environmentPrepared");
|
||||
debug("初始化 Environment 中,请稍后...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextPrepared(ConfigurableApplicationContext context) {
|
||||
logger.debug("Desktop.contextPrepared");
|
||||
debug("Spring Application Context 预处理中,请稍后...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextLoaded(ConfigurableApplicationContext context) {
|
||||
logger.debug("Desktop.contextLoaded");
|
||||
debug("Spring Application Context 初始化完毕,请稍后...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void started(ConfigurableApplicationContext context, Duration timeTaken) {
|
||||
logger.debug("Desktop.started");
|
||||
debug("Spring Application 启动完毕.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ready(ConfigurableApplicationContext context, Duration timeTaken) {
|
||||
logger.debug("Desktop.ready");
|
||||
debug("Spring Application ready.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(ConfigurableApplicationContext context, Throwable exception) {
|
||||
logger.error("Desktop.failed", exception);
|
||||
holder.error("Spring Application 启动失败(" + exception.getMessage() + ").");
|
||||
UITools.showExceptionAndWait("启动失败", exception);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpringApplicationRunListener getRunListener(SpringApplication springApplication) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@EventListener
|
||||
public void handleClosedEvent(ContextClosedEvent event) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("handleClosedEvent={}", event);
|
||||
}
|
||||
Desktop.shutdown();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CacheManager cacheManager() {
|
||||
// return new ConcurrentMapCacheManager("myCache");
|
||||
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
|
||||
cacheManager.setAsyncCacheMode(true);
|
||||
return cacheManager;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ObjectMapper objectMapper() {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
JavaTimeModule javaTimeModule = new JavaTimeModule();
|
||||
javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ISO_LOCAL_DATE));
|
||||
javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(
|
||||
DateTimeFormatter.ofPattern(MyDateTimeUtils.DEFAULT_DATETIME_FORMAT_PATTERN)));
|
||||
javaTimeModule.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern("HH:mm:ss")));
|
||||
javaTimeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ISO_LOCAL_DATE));
|
||||
javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(
|
||||
DateTimeFormatter.ofPattern(MyDateTimeUtils.DEFAULT_DATETIME_FORMAT_PATTERN)));
|
||||
javaTimeModule.addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ISO_LOCAL_TIME));
|
||||
objectMapper.registerModule(javaTimeModule);
|
||||
return objectMapper;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ScheduledExecutorService scheduledExecutorService() {
|
||||
return Desktop.instance.getExecutorService();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,173 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud;
|
||||
|
||||
import com.ecep.contract.manager.ds.other.service.SysConfService;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import com.ecep.contract.manager.util.MyStringUtils;
|
||||
import com.ecep.contract.manager.util.NumberUtils;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static com.ecep.contract.manager.SpringApp.getBean;
|
||||
|
||||
public class AbstractCtx {
|
||||
@Setter
|
||||
SysConfService confService;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
Locale locale = Locale.getDefault();
|
||||
|
||||
public SysConfService getConfService() {
|
||||
if (confService == null) {
|
||||
confService = getBean(SysConfService.class);
|
||||
}
|
||||
return confService;
|
||||
}
|
||||
|
||||
|
||||
public boolean updateText(Supplier<String> getter, Consumer<String> setter, String text, MessageHolder holder, String topic) {
|
||||
if (!Objects.equals(getter.get(), text)) {
|
||||
setter.accept(text);
|
||||
holder.info(topic + "修改为: " + text);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateAppendText(Supplier<String> getter, Consumer<String> setter, String text, MessageHolder holder, String topic) {
|
||||
if (StringUtils.hasText(text)) {
|
||||
String str = MyStringUtils.appendIfAbsent(getter.get(), text);
|
||||
if (!Objects.equals(getter.get(), str)) {
|
||||
setter.accept(text);
|
||||
holder.info(topic + "修改为: " + text);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean updateLocalDate(Supplier<LocalDate> getter, Consumer<LocalDate> setter, java.sql.Date date, MessageHolder holder, String topic) {
|
||||
if (date != null) {
|
||||
return updateLocalDate(getter, setter, date.toLocalDate(), holder, topic);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateLocalDate(Supplier<LocalDate> getter, Consumer<LocalDate> setter, LocalDate date, MessageHolder holder, String topic) {
|
||||
return updateLocalDate(getter, setter, date, holder, topic, false);
|
||||
}
|
||||
|
||||
public boolean updateLocalDate(Supplier<LocalDate> getter, Consumer<LocalDate> setter, LocalDate date, MessageHolder holder, String topic, boolean allowNull) {
|
||||
if (date == null && !allowNull) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(getter.get(), date)) {
|
||||
setter.accept(date);
|
||||
holder.info(topic + "更新为 " + date);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateLocalDate(Supplier<LocalDate> getter, Consumer<LocalDate> setter, String strDate, MessageHolder holder, String topic) {
|
||||
LocalDate date = null;
|
||||
if (StringUtils.hasText(strDate)) {
|
||||
try {
|
||||
date = LocalDate.parse(strDate);
|
||||
} catch (DateTimeParseException e) {
|
||||
holder.warn("无法解析的日期:" + strDate);
|
||||
}
|
||||
}
|
||||
return updateLocalDate(getter, setter, date, holder, topic);
|
||||
}
|
||||
|
||||
public boolean updateLocalDate(Supplier<LocalDate> getter, Consumer<LocalDate> setter, Timestamp timestamp, MessageHolder holder, String topic) {
|
||||
LocalDate date = null;
|
||||
|
||||
if (timestamp != null) {
|
||||
try {
|
||||
date = timestamp.toLocalDateTime().toLocalDate();
|
||||
} catch (DateTimeParseException e) {
|
||||
holder.warn("解析日期" + timestamp + " 异常:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
return updateLocalDate(getter, setter, date, holder, topic);
|
||||
}
|
||||
|
||||
public boolean updateLocalDateTime(Supplier<LocalDateTime> getter, Consumer<LocalDateTime> setter, Timestamp timestamp, MessageHolder holder, String topic) {
|
||||
LocalDateTime dateTime = null;
|
||||
|
||||
if (timestamp != null) {
|
||||
try {
|
||||
// fixed nanos
|
||||
timestamp.setNanos(0);
|
||||
dateTime = timestamp.toLocalDateTime();
|
||||
} catch (DateTimeParseException e) {
|
||||
holder.warn("解析日期" + timestamp + " 异常:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if (!Objects.equals(getter.get(), dateTime)) {
|
||||
setter.accept(dateTime);
|
||||
holder.info(topic + "修改为: " + dateTime);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateInstant(Supplier<Instant> getter, Consumer<Instant> setter, Instant instant, MessageHolder holder, String topic) {
|
||||
if (!Objects.equals(getter.get(), instant)) {
|
||||
setter.accept(instant);
|
||||
holder.info(topic + "修改为: " + instant);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean updateNumber(Supplier<Double> getter, Consumer<Double> setter, BigDecimal value, MessageHolder holder, String topic) {
|
||||
double val = value.doubleValue();
|
||||
return updateNumber(getter, setter, val, holder, topic);
|
||||
}
|
||||
|
||||
public boolean updateNumber(Supplier<Double> getter, Consumer<Double> setter, double value, MessageHolder holder, String topic) {
|
||||
if (getter.get() == null || !NumberUtils.equals(getter.get(), value)) {
|
||||
setter.accept(value);
|
||||
holder.info(topic + "修改为: " + value);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateNumber(Supplier<Float> getter, Consumer<Float> setter, float value, MessageHolder holder, String topic) {
|
||||
if (getter.get() == null || !NumberUtils.equals(getter.get(), value)) {
|
||||
setter.accept(value);
|
||||
holder.info(topic + "修改为: " + value);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean updateNumber(Supplier<Integer> getter, Consumer<Integer> setter, Integer value, MessageHolder holder, String topic) {
|
||||
if (getter.get() == null || !NumberUtils.equals(getter.get(), value)) {
|
||||
setter.accept(value);
|
||||
holder.info(topic + "修改为: " + value);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud;
|
||||
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.other.model.IdentityEntity;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 记录同步来源
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
// @Entity
|
||||
// @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
|
||||
@ToString
|
||||
@MappedSuperclass
|
||||
public abstract class CloudBaseInfo implements IdentityEntity {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "ID", nullable = false)
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 平台编号
|
||||
*/
|
||||
@Column(name = "CLOUD_ID")
|
||||
private String cloudId;
|
||||
|
||||
/**
|
||||
* 本地更新时间戳,控制更新频率和重复更新
|
||||
*/
|
||||
@Column(name = "LATEST_UPDATE")
|
||||
private Instant latestUpdate;
|
||||
|
||||
/**
|
||||
* 关联的公司
|
||||
*/
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "COMPANY_ID")
|
||||
@ToString.Exclude
|
||||
private Company company;
|
||||
|
||||
@Version
|
||||
@ColumnDefault("0")
|
||||
@Column(name = "VERSION", nullable = false)
|
||||
private int version;
|
||||
|
||||
@Override
|
||||
public final boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null) return false;
|
||||
Class<?> oEffectiveClass = o instanceof HibernateProxy ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() : o.getClass();
|
||||
Class<?> thisEffectiveClass = this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() : this.getClass();
|
||||
if (thisEffectiveClass != oEffectiveClass) return false;
|
||||
CloudBaseInfo cloudInfo = (CloudBaseInfo) o;
|
||||
return getId() != null && Objects.equals(getId(), cloudInfo.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode();
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud;
|
||||
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 记录同步来源
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
//@org.springframework.data.relational.core.mapping.Table(name = "CLOUD_INFO")
|
||||
@Table(name = "CLOUD_INFO", schema = "supplier_ms")
|
||||
@ToString
|
||||
public class CloudInfo {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "ID", nullable = false)
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 记录源类型
|
||||
*/
|
||||
@Column(name = "CLOUD_TYPE", length = 50)
|
||||
private CloudType type;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Column(name = "CLOUD_ID")
|
||||
private String cloudId;
|
||||
|
||||
/**
|
||||
* 本地更新时间戳,控制更新频率和重复更新
|
||||
*/
|
||||
@Column(name = "LATEST_UPDATE")
|
||||
private Instant latestUpdate;
|
||||
|
||||
/**
|
||||
* 关联的公司
|
||||
*/
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "COMPANY_ID")
|
||||
@ToString.Exclude
|
||||
private Company company;
|
||||
|
||||
@Version
|
||||
@ColumnDefault("0")
|
||||
@Column(name = "VERSION", nullable = false)
|
||||
private int version;
|
||||
|
||||
@Override
|
||||
public final boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null) return false;
|
||||
Class<?> oEffectiveClass = o instanceof HibernateProxy ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() : o.getClass();
|
||||
Class<?> thisEffectiveClass = this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() : this.getClass();
|
||||
if (thisEffectiveClass != oEffectiveClass) return false;
|
||||
CloudInfo cloudInfo = (CloudInfo) o;
|
||||
return getId() != null && Objects.equals(getId(), cloudInfo.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode();
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud;
|
||||
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Lazy
|
||||
@Repository
|
||||
public interface CloudInfoRepository
|
||||
// curd
|
||||
extends CrudRepository<CloudInfo, Integer>, PagingAndSortingRepository<CloudInfo, Integer> {
|
||||
|
||||
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud;
|
||||
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.other.vo.IdentityViewModel;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.*;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 云信息
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Data
|
||||
public class CloudInfoViewModel<V extends CloudBaseInfo> extends IdentityViewModel<V> {
|
||||
|
||||
/**
|
||||
* 云端Id
|
||||
*/
|
||||
private SimpleStringProperty cloudId = new SimpleStringProperty();
|
||||
/**
|
||||
* 公司
|
||||
*/
|
||||
private SimpleObjectProperty<Company> company = new SimpleObjectProperty<>();
|
||||
/**
|
||||
* 最后更新日期
|
||||
*/
|
||||
private SimpleObjectProperty<LocalDateTime> latest = new SimpleObjectProperty<>();
|
||||
/**
|
||||
* Version
|
||||
*/
|
||||
private SimpleIntegerProperty version = new SimpleIntegerProperty();
|
||||
|
||||
@Override
|
||||
protected void updateFrom(V info) {
|
||||
super.updateFrom(info);
|
||||
cloudId.set(info.getCloudId());
|
||||
company.set(info.getCompany());
|
||||
|
||||
if (info.getLatestUpdate() != null) {
|
||||
ZoneId zone = ZoneId.systemDefault();
|
||||
ZonedDateTime zonedDateTime = info.getLatestUpdate().atZone(zone);
|
||||
LocalDateTime localDateTime = zonedDateTime.toLocalDateTime();
|
||||
latest.set(localDateTime);
|
||||
} else {
|
||||
latest.set(null);
|
||||
}
|
||||
version.set(info.getVersion());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean copyTo(V info) {
|
||||
boolean changed = super.copyTo(info);
|
||||
|
||||
if (!Objects.equals(cloudId.get(), info.getCloudId())) {
|
||||
info.setCloudId(cloudId.get());
|
||||
changed = true;
|
||||
}
|
||||
|
||||
Instant latestUpdate = null;
|
||||
LocalDateTime latestUpdateDateTime = latest.get();
|
||||
if (latestUpdateDateTime != null) {
|
||||
latestUpdate = latestUpdateDateTime.toInstant(ZoneOffset.ofHours(8));
|
||||
}
|
||||
if (!Objects.equals(latestUpdate, info.getLatestUpdate())) {
|
||||
info.setLatestUpdate(latestUpdate);
|
||||
changed = true;
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.data.repository.config.BootstrapMode;
|
||||
|
||||
@Configuration
|
||||
@EnableJpaRepositories(bootstrapMode = BootstrapMode.LAZY)
|
||||
public class CloudRepositoriesConfig {
|
||||
// @Bean
|
||||
// @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
// public BeanDefinition cloudInfoRepositoryDefinition() {
|
||||
// BeanDefinition definition = new org.springframework.beans.factory.support.GenericBeanDefinition();
|
||||
// definition.setBeanClassName("com.ecep.contract.manager.cloud.CloudInfoRepository");
|
||||
// definition.setLazyInit(true);
|
||||
// return definition;
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
// public BeanDefinition cloudRkRepositoryDefinition() {
|
||||
// BeanDefinition definition = new org.springframework.beans.factory.support.GenericBeanDefinition();
|
||||
// definition.setBeanClassName("com.ecep.contract.manager.cloud.u8.CloudRkRepository");
|
||||
// definition.setLazyInit(true);
|
||||
// return definition;
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
// public BeanDefinition cloudTycRepositoryDefinition() {
|
||||
// BeanDefinition definition = new org.springframework.beans.factory.support.GenericBeanDefinition();
|
||||
// definition.setBeanClassName("com.ecep.contract.manager.cloud.u8.CloudTycRepository");
|
||||
// definition.setLazyInit(true);
|
||||
// return definition;
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
// public BeanDefinition cloudYuRepositoryDefinition() {
|
||||
// BeanDefinition definition = new org.springframework.beans.factory.support.GenericBeanDefinition();
|
||||
// definition.setBeanClassName("com.ecep.contract.manager.cloud.u8.CloudYuRepository");
|
||||
// definition.setLazyInit(true);
|
||||
// return definition;
|
||||
// }
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud;
|
||||
|
||||
/**
|
||||
* 记录源类型
|
||||
*/
|
||||
public enum CloudType {
|
||||
/**
|
||||
* 上海电气集团相关方平台
|
||||
*/
|
||||
RK,
|
||||
/**
|
||||
* 天眼查
|
||||
*/
|
||||
TYC,
|
||||
/**
|
||||
* 用友U8
|
||||
*/
|
||||
U8,
|
||||
/**
|
||||
* 老版本APP
|
||||
*/
|
||||
OLD;
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.old;
|
||||
|
||||
import com.ecep.contract.manager.ds.company.model.CompanyContact;
|
||||
import com.ecep.contract.manager.ds.company.model.CompanyContract;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class CompanyContactUtils {
|
||||
/**
|
||||
* 使用 map 应用到 contact, 如有更新, 则返回 true
|
||||
*/
|
||||
public static boolean applyContactByMap(CompanyContact contact, Map<String, Object> map) {
|
||||
boolean modified = false;
|
||||
String name = (String) map.get("NAME");
|
||||
String phone = (String) map.get("PHONE");
|
||||
String email = (String) map.get("EMAIL");
|
||||
String address = (String) map.get("ADDRESS");
|
||||
if (name != null) {
|
||||
// 更新备注
|
||||
if (!Objects.equals(contact.getName(), name)) {
|
||||
contact.setName(name);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
if (phone != null) {
|
||||
// 更新备注
|
||||
if (!Objects.equals(contact.getPhone(), phone)) {
|
||||
contact.setPhone(phone);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
if (email != null) {
|
||||
// 更新备注
|
||||
if (!Objects.equals(contact.getEmail(), email)) {
|
||||
contact.setEmail(email);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
if (address != null) {
|
||||
// 更新备注
|
||||
if (!Objects.equals(contact.getAddress(), address)) {
|
||||
contact.setAddress(address);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
/**
|
||||
* 要和{@link CompanyContract#getContactKey(CompanyContact)}一致
|
||||
*/
|
||||
public static String getContactKey(Map<String, Object> map) {
|
||||
if (map == null) {
|
||||
return null;
|
||||
}
|
||||
String name = (String) map.get("NAME");
|
||||
String phone = (String) map.get("PHONE");
|
||||
String email = (String) map.get("EMAIL");
|
||||
return name + phone + email;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.old;
|
||||
|
||||
import com.ecep.contract.manager.ds.customer.model.CompanyCustomerFile;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CompanyCustomerFileUtils {
|
||||
public static boolean applyCustomerFileByMap(CompanyCustomerFile customerFile, Map<String, Object> m) {
|
||||
boolean modified = false;
|
||||
|
||||
String filePath = (String) m.get("FILE_PATH");
|
||||
String editFilePath = (String) m.get("EDIT_FILE_PATH");
|
||||
java.sql.Date signDate = (java.sql.Date) m.get("SIGN_DATE");
|
||||
Boolean valid = (Boolean) m.get("VALID");
|
||||
|
||||
if (filePath != null) {
|
||||
// file path
|
||||
if (!Objects.equals(customerFile.getFilePath(), filePath)) {
|
||||
customerFile.setFilePath(filePath);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
if (editFilePath != null) {
|
||||
// edit file path
|
||||
if (!Objects.equals(customerFile.getEditFilePath(), editFilePath)) {
|
||||
customerFile.setEditFilePath(editFilePath);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
if (signDate != null) {
|
||||
// date
|
||||
LocalDate localDate = signDate.toLocalDate();
|
||||
if (!Objects.equals(customerFile.getSignDate(), localDate)) {
|
||||
customerFile.setSignDate(localDate);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
if (valid != null) {
|
||||
// valid
|
||||
if (!Objects.equals(customerFile.isValid(), valid)) {
|
||||
customerFile.setValid(valid);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
public static String getCustomerFileKey(Map<String, Object> m) {
|
||||
return m.get("FILE_PATH").toString();
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.old;
|
||||
|
||||
import com.ecep.contract.manager.ds.vendor.model.CompanyVendorFile;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CompanyVendorFileUtils {
|
||||
public static boolean applyVendorFileByMap(CompanyVendorFile vendorFile, Map<String, Object> m) {
|
||||
boolean modified = false;
|
||||
|
||||
String filePath = (String) m.get("FILE_PATH");
|
||||
String editFilePath = (String) m.get("EDIT_FILE_PATH");
|
||||
java.sql.Date signDate = (java.sql.Date) m.get("SIGN_DATE");
|
||||
Boolean valid = (Boolean) m.get("VALID");
|
||||
|
||||
if (filePath != null) {
|
||||
// file path
|
||||
if (!Objects.equals(vendorFile.getFilePath(), filePath)) {
|
||||
vendorFile.setFilePath(filePath);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
if (editFilePath != null) {
|
||||
// edit file path
|
||||
if (!Objects.equals(vendorFile.getEditFilePath(), editFilePath)) {
|
||||
vendorFile.setEditFilePath(editFilePath);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
if (signDate != null) {
|
||||
// date
|
||||
LocalDate localDate = signDate.toLocalDate();
|
||||
if (!Objects.equals(vendorFile.getSignDate(), localDate)) {
|
||||
vendorFile.setSignDate(localDate);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
if (valid != null) {
|
||||
// valid
|
||||
if (!Objects.equals(vendorFile.isValid(), valid)) {
|
||||
vendorFile.setValid(valid);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
public static String getVendorFileKey(Map<String, Object> m) {
|
||||
return m.get("FILE_PATH").toString();
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,128 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.old;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.manager.ds.contract.model.Contract;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import com.ecep.contract.manager.ui.Tasker;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class OldVersionSyncCustomerTask extends Tasker<Object> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(OldVersionSyncCustomerTask.class);
|
||||
|
||||
private final OldVersionService service = SpringApp.getBean(OldVersionService.class);
|
||||
private final CompanyService companyService = SpringApp.getBean(CompanyService.class);
|
||||
|
||||
private Map<Object, List<Map<String, Object>>> oldNameGroupedMap;
|
||||
private Map<Object, List<Map<String, Object>>> contactGroupedMap;
|
||||
private File basePath;
|
||||
private String titlePrefix = "";
|
||||
|
||||
public OldVersionSyncCustomerTask() {
|
||||
updateTitle("老版本-同步客户数据");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateTitle(String title) {
|
||||
super.updateTitle(titlePrefix + title);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object execute(MessageHolder holder) throws Exception {
|
||||
updateTitle("老版本-同步客户数据");
|
||||
basePath = companyService.getCustomerBasePath();
|
||||
List<Runnable> runnable = Arrays.asList(this::loadOldNames, this::loadContacts, this::syncCustomers, this::syncContracts);
|
||||
|
||||
for (int i = 0; i < runnable.size(); i++) {
|
||||
titlePrefix = "老版本-同步客户数据-" + (i + 1) + "/" + runnable.size() + "-";
|
||||
try {
|
||||
runnable.get(i).run();
|
||||
} catch (Exception e) {
|
||||
logger.error("运行至 {} 时,发生错误中断", titlePrefix, e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private void loadOldNames() {
|
||||
try (Stream<Map<String, Object>> stream = service.queryAllCustomerOldNameForStream()) {
|
||||
updateTitle("载入曾用名");
|
||||
oldNameGroupedMap = stream.takeWhile(v -> !isCancelled()).parallel()
|
||||
.collect(Collectors.groupingBy(m -> m.get("GID")));
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("import Customer oldNames = {} from old version app", oldNameGroupedMap.size());
|
||||
}
|
||||
updateProgress(0.1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadContacts() {
|
||||
try (Stream<Map<String, Object>> stream = service.queryAllCustomerContactForStream()) {
|
||||
updateTitle("载入联系人");
|
||||
contactGroupedMap = stream.takeWhile(v -> !isCancelled()).parallel()
|
||||
.collect(Collectors.groupingBy(m -> m.get("GID")));
|
||||
logger.debug("import Customer contacts = {} from old version app", contactGroupedMap.size());
|
||||
updateProgress(0.2, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void syncCustomers() {
|
||||
try (Stream<Map<String, Object>> stream = service.queryAllCustomerForStream()) {
|
||||
updateTitle("客户信息");
|
||||
long size = service.countOfCustomer();
|
||||
AtomicInteger counter = new AtomicInteger(0);
|
||||
stream.takeWhile(v -> !isCancelled()).forEach(map -> {
|
||||
if (isCancelled()) {
|
||||
updateMessage("Cancelled");
|
||||
return;
|
||||
}
|
||||
Company updated = service.syncCustomer(map, basePath, oldNameGroupedMap, contactGroupedMap);
|
||||
if (updated != null) {
|
||||
updateMessage(counter.get() + " / " + size + ">" + updated.getName());
|
||||
} else {
|
||||
updateMessage(counter.get() + " / " + size + ">" + map.get("NAME"));
|
||||
}
|
||||
updateProgress(counter.incrementAndGet(), size);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void syncContracts() {
|
||||
try (Stream<Map<String, Object>> stream = service.queryAllCustomerContractForStream()) {
|
||||
updateTitle("合同信息");
|
||||
long size = service.countOfCustomerContract();
|
||||
AtomicInteger counter = new AtomicInteger(0);
|
||||
stream.takeWhile(v -> !isCancelled()).forEach(map -> {
|
||||
if (isCancelled()) {
|
||||
updateMessage("Cancelled");
|
||||
return;
|
||||
}
|
||||
Contract updated = service.syncCustomerContract(map);
|
||||
if (updated != null) {
|
||||
updateMessage(counter.get() + " / " + size + ">" + updated.getName());
|
||||
} else {
|
||||
updateMessage(counter.get() + " / " + size + ">" + map.get("NO"));
|
||||
}
|
||||
updateProgress(counter.incrementAndGet(), size);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.old;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.manager.ds.contract.model.Contract;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import com.ecep.contract.manager.ui.Tasker;
|
||||
|
||||
public class OldVersionSyncVendorTask extends Tasker<Object> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(OldVersionSyncVendorTask.class);
|
||||
|
||||
private final OldVersionService service = SpringApp.getBean(OldVersionService.class);
|
||||
private final CompanyService companyService = SpringApp.getBean(CompanyService.class);
|
||||
private Map<Object, List<Map<String, Object>>> oldNameGroupedMap;
|
||||
private Map<Object, List<Map<String, Object>>> contactGroupedMap;
|
||||
private File basePath;
|
||||
private String titlePrefix = "";
|
||||
|
||||
public OldVersionSyncVendorTask() {
|
||||
updateTitle("老版本-同步供应商数据");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateTitle(String title) {
|
||||
super.updateTitle(titlePrefix + title);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object execute(MessageHolder holder) throws Exception {
|
||||
basePath = companyService.getVendorBasePath();
|
||||
List<Runnable> runnable = Arrays.asList(this::loadOldNames, this::loadContacts, this::syncVendors,
|
||||
this::syncContracts);
|
||||
for (int i = 0; i < runnable.size(); i++) {
|
||||
titlePrefix = "老版本-同步供应商数据-" + (i + 1) + "/" + runnable.size() + "-";
|
||||
try {
|
||||
runnable.get(i).run();
|
||||
} catch (Exception e) {
|
||||
logger.error("运行至 {} 时,发生错误中断", titlePrefix, e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void loadOldNames() {
|
||||
try (Stream<Map<String, Object>> stream = service.queryAllVendorOldNameForStream()) {
|
||||
updateTitle("载入曾用名");
|
||||
oldNameGroupedMap = stream.takeWhile(v -> !isCancelled()).parallel()
|
||||
.collect(Collectors.groupingBy(m -> m.get("GID")));
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("import vendor oldNames = {} from old version app", oldNameGroupedMap.size());
|
||||
}
|
||||
updateProgress(0.1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadContacts() {
|
||||
try (Stream<Map<String, Object>> stream = service.queryAllVendorContactForStream()) {
|
||||
updateTitle("载入联系人");
|
||||
contactGroupedMap = stream.takeWhile(v -> !isCancelled()).parallel()
|
||||
.collect(Collectors.groupingBy(m -> m.get("GID")));
|
||||
logger.debug("import vendor contacts = {} from old version app", contactGroupedMap.size());
|
||||
updateProgress(0.2, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void syncVendors() {
|
||||
try (Stream<Map<String, Object>> stream = service.queryAllVendorForStream()) {
|
||||
updateTitle("客户信息");
|
||||
long size = service.countOfVendor();
|
||||
AtomicInteger counter = new AtomicInteger(0);
|
||||
stream.takeWhile(v -> !isCancelled()).forEach(map -> {
|
||||
if (isCancelled()) {
|
||||
updateMessage("Cancelled");
|
||||
return;
|
||||
}
|
||||
Company updated = service.syncVendor(map, basePath, oldNameGroupedMap, contactGroupedMap);
|
||||
if (updated != null) {
|
||||
updateMessage(counter.get() + " / " + size + ">" + updated.getName());
|
||||
} else {
|
||||
updateMessage(counter.get() + " / " + size + ">" + map.get("NAME"));
|
||||
}
|
||||
updateProgress(counter.incrementAndGet(), size);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void syncContracts() {
|
||||
try (Stream<Map<String, Object>> stream = service.queryAllVendorContractForStream()) {
|
||||
updateTitle("合同信息");
|
||||
long size = service.countOfVendorContract();
|
||||
AtomicInteger counter = new AtomicInteger(0);
|
||||
stream.takeWhile(v -> !isCancelled()).forEach(map -> {
|
||||
if (isCancelled()) {
|
||||
updateMessage("Cancelled");
|
||||
return;
|
||||
}
|
||||
Contract updated = service.syncVendorContract(map);
|
||||
if (updated != null) {
|
||||
updateMessage(counter.get() + " / " + size + ">" + updated.getName());
|
||||
} else {
|
||||
updateMessage(counter.get() + " / " + size + ">" + map.get("NO"));
|
||||
}
|
||||
updateProgress(counter.incrementAndGet(), size);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.rk;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.net.URI;
|
||||
|
||||
public class BlackListUpdateContext {
|
||||
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
private ObjectMapper objectMapper;
|
||||
private Proxy.Type proxyType;
|
||||
@Getter
|
||||
private Proxy socksProxy;
|
||||
@Setter
|
||||
@Getter
|
||||
private String url;
|
||||
@Getter
|
||||
private long elapse = 1440;
|
||||
|
||||
|
||||
public void setProxy(String proxy) {
|
||||
if (proxy != null) {
|
||||
URI proxyUri = URI.create(proxy);
|
||||
proxyType = Proxy.Type.valueOf(proxyUri.getScheme().toUpperCase());
|
||||
socksProxy = new Proxy(
|
||||
proxyType,
|
||||
new InetSocketAddress(proxyUri.getHost(), proxyUri.getPort())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public void setElapse(String value) {
|
||||
elapse = Long.parseLong(value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.rk;
|
||||
|
||||
import com.ecep.contract.manager.cloud.CloudBaseInfo;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "CLOUD_RK", schema = "supplier_ms")
|
||||
public class CloudRk extends CloudBaseInfo {
|
||||
/**
|
||||
* 是否自动更新
|
||||
*/
|
||||
@Column(name = "AUTO_UPDATE", nullable = false, columnDefinition = "boolean default true")
|
||||
private boolean autoUpdate = false;
|
||||
|
||||
/**
|
||||
* 更新间隔天数
|
||||
*/
|
||||
@Column(name = "UPDATE_DAYS", nullable = false, columnDefinition = "int default 30")
|
||||
private int updateDays;
|
||||
|
||||
/**
|
||||
* 客户信用评级
|
||||
*/
|
||||
@ColumnDefault("''")
|
||||
@Column(name = "CUSTOMER_GRADE", nullable = false)
|
||||
private String customerGrade;
|
||||
/**
|
||||
* 客户信用总分
|
||||
*/
|
||||
@ColumnDefault("0")
|
||||
@Column(name = "CUSTOMER_SCORE", nullable = false)
|
||||
private Integer customerScore;
|
||||
|
||||
@Column(name = "CUSTOMER_DESCRIPTION")
|
||||
private String customerDescription;
|
||||
|
||||
/**
|
||||
* 供应商信用评级
|
||||
*/
|
||||
@ColumnDefault("''")
|
||||
@Column(name = "VENDOR_GRADE", nullable = false)
|
||||
private String vendorGrade;
|
||||
/**
|
||||
* 供应商信用总分
|
||||
*/
|
||||
@ColumnDefault("0")
|
||||
@Column(name = "VENDOR_SCORE", nullable = false)
|
||||
private Integer vendorScore;
|
||||
|
||||
@Column(name = "VENDOR_DESCRIPTION")
|
||||
private String vendorDescription;
|
||||
|
||||
/**
|
||||
* 相关方资信评价等级
|
||||
*/
|
||||
@ColumnDefault("''")
|
||||
@Column(name = "CREDIT_RANK", nullable = false)
|
||||
private String rank;
|
||||
|
||||
@Column(name = "CREDIT_RANK_DESCRIPTION")
|
||||
private String rankDescription;
|
||||
|
||||
|
||||
@Column(name = "CLOUD_LATEST")
|
||||
private Instant cloudLatest;
|
||||
|
||||
@Column(name = "BLACK_LIST_UPDATED")
|
||||
private Instant cloudBlackListUpdated;
|
||||
|
||||
@Column(name = "ENT_UPDATED")
|
||||
private Instant cloudEntUpdate;
|
||||
|
||||
@Column(name = "DESCRIPTION")
|
||||
private String description;
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.rk;
|
||||
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import com.ecep.contract.manager.ui.Tasker;
|
||||
import lombok.Setter;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
/**
|
||||
* 数据修复任务
|
||||
*/
|
||||
public class CloudRkDataRepairTask extends Tasker<Object> {
|
||||
@Setter
|
||||
private int batchSize = 50;
|
||||
|
||||
@Override
|
||||
protected Object execute(MessageHolder holder) {
|
||||
CompanyService companyService = getBean(CompanyService.class);
|
||||
CloudRkService cloudRkService = getBean(CloudRkService.class);
|
||||
|
||||
Pageable pageRequest = PageRequest.ofSize(batchSize);
|
||||
while (!isCancelled()) {
|
||||
Page<Company> page = companyService.findAll(null, pageRequest);
|
||||
int index = page.getNumber() * page.getSize();
|
||||
|
||||
int i = 1;
|
||||
for (Company company : page) {
|
||||
if (isCancelled()) {
|
||||
break;
|
||||
}
|
||||
|
||||
String prefix = (index + i) + "/" + page.getTotalElements() + ", " + company.getName() + "> ";
|
||||
|
||||
cloudRkService.getOrCreateCloudRk(company);
|
||||
holder.info(prefix + " 完成");
|
||||
|
||||
updateProgress(index + i, page.getTotalElements());
|
||||
i++;
|
||||
}
|
||||
if (!page.hasNext()) {
|
||||
break;
|
||||
}
|
||||
pageRequest = page.nextPageable();
|
||||
|
||||
}
|
||||
if (isCancelled()) {
|
||||
updateMessage("Cancelled");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,172 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.rk;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.ecep.contract.manager.cloud.CloudInfoViewModel;
|
||||
import com.ecep.contract.manager.ui.util.MyDateTimePropertyUtils;
|
||||
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class CloudRkInfoViewModel extends CloudInfoViewModel<CloudRk> {
|
||||
private SimpleBooleanProperty autoUpdate = new SimpleBooleanProperty();
|
||||
|
||||
private SimpleStringProperty rank = new SimpleStringProperty();
|
||||
private SimpleStringProperty rankDescription = new SimpleStringProperty();
|
||||
|
||||
|
||||
private SimpleStringProperty customerGrade = new SimpleStringProperty();
|
||||
private SimpleIntegerProperty customerScore = new SimpleIntegerProperty();
|
||||
private SimpleStringProperty customerDescription = new SimpleStringProperty();
|
||||
|
||||
private SimpleStringProperty vendorGrade = new SimpleStringProperty();
|
||||
private SimpleIntegerProperty vendorScore = new SimpleIntegerProperty();
|
||||
private SimpleStringProperty vendorDescription = new SimpleStringProperty();
|
||||
|
||||
private SimpleObjectProperty<LocalDateTime> cloudLatest = new SimpleObjectProperty<>();
|
||||
private SimpleObjectProperty<LocalDateTime> cloudBlackListUpdated = new SimpleObjectProperty<>();
|
||||
private SimpleObjectProperty<LocalDateTime> cloudEntUpdate = new SimpleObjectProperty<>();
|
||||
|
||||
private SimpleStringProperty description = new SimpleStringProperty();
|
||||
|
||||
@Override
|
||||
protected void updateFrom(CloudRk info) {
|
||||
super.updateFrom(info);
|
||||
update_((CloudRk) info);
|
||||
}
|
||||
|
||||
private void update_(CloudRk info) {
|
||||
autoUpdate.set(info.isAutoUpdate());
|
||||
rank.set(info.getRank());
|
||||
rankDescription.set(info.getRankDescription());
|
||||
|
||||
customerGrade.set(info.getCustomerGrade());
|
||||
customerScore.set(info.getCustomerScore());
|
||||
customerDescription.set(info.getCustomerDescription());
|
||||
|
||||
vendorGrade.set(info.getVendorGrade());
|
||||
vendorScore.set(info.getVendorScore());
|
||||
vendorDescription.set(info.getVendorDescription());
|
||||
|
||||
description.set(info.getDescription());
|
||||
|
||||
if (info.getCloudLatest() != null) {
|
||||
ZoneId zone = ZoneId.systemDefault();
|
||||
ZonedDateTime zonedDateTime = info.getCloudLatest().atZone(zone);
|
||||
LocalDateTime localDateTime = zonedDateTime.toLocalDateTime();
|
||||
cloudLatest.set(localDateTime);
|
||||
} else {
|
||||
cloudLatest.set(null);
|
||||
}
|
||||
|
||||
if (info.getCloudBlackListUpdated() != null) {
|
||||
ZoneId zone = ZoneId.systemDefault();
|
||||
ZonedDateTime zonedDateTime = info.getCloudBlackListUpdated().atZone(zone);
|
||||
LocalDateTime localDateTime = zonedDateTime.toLocalDateTime();
|
||||
cloudBlackListUpdated.set(localDateTime);
|
||||
} else {
|
||||
cloudBlackListUpdated.set(null);
|
||||
}
|
||||
|
||||
if (info.getCloudEntUpdate() != null) {
|
||||
ZoneId zone = ZoneId.systemDefault();
|
||||
ZonedDateTime zonedDateTime = info.getCloudEntUpdate().atZone(zone);
|
||||
LocalDateTime localDateTime = zonedDateTime.toLocalDateTime();
|
||||
cloudEntUpdate.set(localDateTime);
|
||||
} else {
|
||||
cloudEntUpdate.set(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean copyTo(CloudRk info) {
|
||||
boolean modified = super.copyTo(info);
|
||||
if (copyTo_((CloudRk) info)) {
|
||||
modified = true;
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
private boolean copyTo_(CloudRk info) {
|
||||
boolean modified = false;
|
||||
if (info.isAutoUpdate() != autoUpdate.get()) {
|
||||
info.setAutoUpdate(autoUpdate.get());
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!Objects.equals(info.getRank(), rank.get())) {
|
||||
info.setRank(rank.get());
|
||||
modified = true;
|
||||
}
|
||||
if (!Objects.equals(info.getRankDescription(), rankDescription.get())) {
|
||||
info.setRankDescription(rankDescription.get());
|
||||
modified = true;
|
||||
}
|
||||
if (!Objects.equals(info.getCustomerGrade(), customerGrade.get())) {
|
||||
info.setCustomerGrade(customerGrade.get());
|
||||
modified = true;
|
||||
}
|
||||
if (!Objects.equals(info.getCustomerScore(), customerScore.get())) {
|
||||
info.setCustomerScore(customerScore.get());
|
||||
modified = true;
|
||||
}
|
||||
if (!Objects.equals(info.getCustomerDescription(), customerDescription.get())) {
|
||||
info.setCustomerDescription(customerDescription.get());
|
||||
modified = true;
|
||||
}
|
||||
if (!Objects.equals(info.getVendorGrade(), vendorGrade.get())) {
|
||||
info.setVendorGrade(vendorGrade.get());
|
||||
modified = true;
|
||||
}
|
||||
if (!Objects.equals(info.getVendorScore(), vendorScore.get())) {
|
||||
info.setVendorScore(vendorScore.get());
|
||||
modified = true;
|
||||
}
|
||||
if (!Objects.equals(info.getVendorDescription(), vendorDescription.get())) {
|
||||
info.setVendorDescription(vendorDescription.get());
|
||||
modified = true;
|
||||
}
|
||||
|
||||
Instant latest = MyDateTimePropertyUtils.localDateTimeToInstant(cloudLatest);
|
||||
if (!Objects.equals(info.getCloudLatest(), latest)) {
|
||||
info.setCloudLatest(latest);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
Instant blackListUpdated = MyDateTimePropertyUtils.localDateTimeToInstant(cloudBlackListUpdated);
|
||||
if (!Objects.equals(info.getCloudBlackListUpdated(), blackListUpdated)) {
|
||||
info.setCloudBlackListUpdated(blackListUpdated);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!Objects.equals(info.getDescription(), description.get())) {
|
||||
info.setDescription(description.get());
|
||||
modified = true;
|
||||
}
|
||||
|
||||
Instant entUpdated = MyDateTimePropertyUtils.localDateTimeToInstant(cloudEntUpdate);
|
||||
if (!Objects.equals(info.getCloudEntUpdate(), entUpdated)) {
|
||||
info.setCloudEntUpdate(entUpdated);
|
||||
modified = true;
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
public static CloudRkInfoViewModel from(CloudRk info) {
|
||||
CloudRkInfoViewModel viewModel = new CloudRkInfoViewModel();
|
||||
viewModel.updateFrom(info);
|
||||
return viewModel;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.rk;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.ui.table.cell.CompanyTableCell;
|
||||
import com.ecep.contract.manager.ds.company.controller.CompanyWindowController;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.manager.ui.AbstEntityManagerSkin;
|
||||
import com.ecep.contract.manager.ui.table.cell.LocalDateTimeTableCell;
|
||||
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.control.ContextMenu;
|
||||
import javafx.scene.control.MenuItem;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.cell.CheckBoxTableCell;
|
||||
import lombok.Setter;
|
||||
|
||||
public class CloudRkManagerSkin
|
||||
extends AbstEntityManagerSkin<CloudRk, CloudRkInfoViewModel, CloudRkManagerSkin, CloudRkManagerWindowController> {
|
||||
@Setter
|
||||
private CompanyService companyService;
|
||||
|
||||
public CloudRkManagerSkin(CloudRkManagerWindowController controller) {
|
||||
super(controller);
|
||||
}
|
||||
|
||||
CloudRkService getCloudRkService() {
|
||||
return controller.getViewModelService();
|
||||
}
|
||||
|
||||
CompanyService getCompanyService() {
|
||||
if (companyService == null) {
|
||||
companyService = SpringApp.getBean(CompanyService.class);
|
||||
}
|
||||
return companyService;
|
||||
}
|
||||
|
||||
@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.cloudBlackListUpdatedColumn.setCellValueFactory(param -> param.getValue().getCloudBlackListUpdated());
|
||||
controller.cloudBlackListUpdatedColumn.setCellFactory(param -> new LocalDateTimeTableCell<>());
|
||||
|
||||
controller.cloudEntUpdateColumn.setCellValueFactory(param -> param.getValue().getCloudEntUpdate());
|
||||
controller.cloudEntUpdateColumn.setCellFactory(param -> new LocalDateTimeTableCell<>());
|
||||
|
||||
controller.autoUpdateColumn.setCellValueFactory(param -> param.getValue().getAutoUpdate());
|
||||
controller.autoUpdateColumn.setCellFactory(CheckBoxTableCell.forTableColumn(controller.autoUpdateColumn));
|
||||
|
||||
controller.descriptionColumn.setCellValueFactory(param -> param.getValue().getDescription());
|
||||
}
|
||||
|
||||
private void onAutoUpdateColumnEditCommit(TableColumn.CellEditEvent<CloudRkInfoViewModel, Boolean> event) {
|
||||
CloudRkInfoViewModel row = event.getRowValue();
|
||||
row.getAutoUpdate().set(event.getNewValue());
|
||||
saveRowData(row);
|
||||
}
|
||||
|
||||
|
||||
@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<CloudRkInfoViewModel> selectedItems = getTableView().getSelectionModel().getSelectedItems();
|
||||
if (selectedItems.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
CloudRkService service = getCloudRkService();
|
||||
for (CloudRkInfoViewModel selectedItem : selectedItems) {
|
||||
selectedItem.getDescription().set("");
|
||||
selectedItem.saveInFxApplicationThread(service);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTableRowDoubleClickedAction(CloudRkInfoViewModel item) {
|
||||
Company company = item.getCompany().get();
|
||||
if (!Hibernate.isInitialized(item)) {
|
||||
company = getCompanyService().findById(company.getId());
|
||||
}
|
||||
CompanyWindowController.show(company, getTableView().getScene().getWindow());
|
||||
}
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.rk;
|
||||
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.cloud.CloudBaseInfo;
|
||||
import com.ecep.contract.manager.cloud.CloudInfo;
|
||||
import com.ecep.contract.manager.cloud.tyc.CloudTyc;
|
||||
import com.ecep.contract.manager.cloud.tyc.CloudTycService;
|
||||
import com.ecep.contract.manager.cloud.u8.CloudYu;
|
||||
import com.ecep.contract.manager.cloud.u8.YongYouU8Service;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ui.AbstManagerWindowController;
|
||||
import com.ecep.contract.manager.ui.FxmlPath;
|
||||
import com.ecep.contract.manager.ui.Message;
|
||||
import com.ecep.contract.manager.ui.ViewModelService;
|
||||
import com.ecep.contract.manager.util.UITools;
|
||||
import javafx.concurrent.Task;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.stage.WindowEvent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Lazy
|
||||
@Scope("prototype")
|
||||
@Component
|
||||
@FxmlPath("/ui/cloud/rk_manager.fxml")
|
||||
public class CloudRkManagerWindowController
|
||||
extends AbstManagerWindowController<CloudRk, CloudRkInfoViewModel, CloudRkManagerSkin> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CloudRkManagerWindowController.class);
|
||||
|
||||
public static void show() {
|
||||
show(CloudRkManagerWindowController.class, null);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private CloudRkService cloudRkService;
|
||||
|
||||
public TableColumn<CloudRkInfoViewModel, Number> idColumn;
|
||||
public TableColumn<CloudRkInfoViewModel, LocalDateTime> latestUpdateColumn;
|
||||
|
||||
public TableColumn<CloudRkInfoViewModel, Company> companyColumn;
|
||||
public TableColumn<CloudRkInfoViewModel, String> cloudIdColumn;
|
||||
public TableColumn<CloudRkInfoViewModel, LocalDateTime> cloudLatestColumn;
|
||||
public TableColumn<CloudRkInfoViewModel, LocalDateTime> cloudBlackListUpdatedColumn;
|
||||
public TableColumn<CloudRkInfoViewModel, LocalDateTime> cloudEntUpdateColumn;
|
||||
public TableColumn<CloudRkInfoViewModel, Boolean> autoUpdateColumn;
|
||||
public TableColumn<CloudRkInfoViewModel, String> descriptionColumn;
|
||||
|
||||
|
||||
@Override
|
||||
protected CloudRkManagerSkin createDefaultSkin() {
|
||||
return new CloudRkManagerSkin(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShown(WindowEvent windowEvent) {
|
||||
super.onShown(windowEvent);
|
||||
getTitle().set("数据源:集团相关方");
|
||||
}
|
||||
|
||||
boolean copyTo(CloudInfo v, CloudBaseInfo cloudRk) {
|
||||
boolean modified = false;
|
||||
if (!Objects.equals(cloudRk.getLatestUpdate(), v.getLatestUpdate())) {
|
||||
cloudRk.setLatestUpdate(v.getLatestUpdate());
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!Objects.equals(cloudRk.getCloudId(), v.getCloudId())) {
|
||||
cloudRk.setCloudId(v.getCloudId());
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!Objects.equals(cloudRk.getCompany(), v.getCompany())) {
|
||||
cloudRk.setCompany(v.getCompany());
|
||||
modified = true;
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据迁移,从 CloudInfo 迁移到 CloudRk
|
||||
*/
|
||||
public void onDateTransferAction(ActionEvent event) {
|
||||
|
||||
CompletableFuture.runAsync(() -> {
|
||||
com.ecep.contract.manager.cloud.CloudInfoRepository cloudInfoRepository = SpringApp.getBean(com.ecep.contract.manager.cloud.CloudInfoRepository.class);
|
||||
CloudTycService tycService = SpringApp.getBean(CloudTycService.class);
|
||||
YongYouU8Service u8Service = SpringApp.getBean(YongYouU8Service.class);
|
||||
|
||||
cloudInfoRepository.findAll().forEach(v -> {
|
||||
try {
|
||||
CloudRk cloudRk = cloudRkService.getOrCreateCloudRk(v);
|
||||
if (copyTo(v, cloudRk)) {
|
||||
cloudRkService.save(cloudRk);
|
||||
}
|
||||
|
||||
CloudTyc cloudTyc = tycService.getOrCreateCloudTyc(v);
|
||||
if (copyTo(v, cloudTyc)) {
|
||||
tycService.save(cloudTyc);
|
||||
}
|
||||
|
||||
CloudYu cloudYu = u8Service.getOrCreateCloudYu(v);
|
||||
if (copyTo(v, cloudYu)) {
|
||||
u8Service.save(cloudYu);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void initializeTask(Task<Object> task, String prefix, Consumer<String> consumer) {
|
||||
task.setOnScheduled(e -> {
|
||||
consumer.accept("正在从相关方平台同步" + prefix + ",请稍后...");
|
||||
});
|
||||
task.setOnRunning(e -> {
|
||||
consumer.accept("开始" + prefix + "...");
|
||||
});
|
||||
task.setOnSucceeded(e -> {
|
||||
consumer.accept(prefix + "完成...");
|
||||
});
|
||||
task.exceptionProperty().addListener((observable, oldValue, newValue) -> {
|
||||
consumer.accept(newValue.getMessage());
|
||||
logger.error("{} 发生异常", prefix, newValue);
|
||||
});
|
||||
SpringApp.getBean(ScheduledExecutorService.class).submit(task);
|
||||
consumer.accept("任务已创建...");
|
||||
}
|
||||
|
||||
public void onDataRepairAction(ActionEvent event) {
|
||||
CloudRkDataRepairTask task = new CloudRkDataRepairTask();
|
||||
task.titleProperty().get();
|
||||
UITools.showTaskDialogAndWait("修复数据", task, null);
|
||||
}
|
||||
|
||||
public void onSyncAction(ActionEvent event) {
|
||||
CloudRkSyncTask task = new CloudRkSyncTask();
|
||||
UITools.showTaskDialogAndWait("同步数据", task, consumer -> {
|
||||
initializeTask(task, "同步数据", msg -> consumer.accept(Message.info(msg)));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public CloudRkService getViewModelService() {
|
||||
return cloudRkService;
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.rk;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.ecep.contract.manager.ds.MyRepository;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
|
||||
@Repository
|
||||
public interface CloudRkRepository extends MyRepository<CloudRk, Integer> {
|
||||
|
||||
Stream<CloudRk> findByCloudLatestAfter(Instant timestamp);
|
||||
|
||||
Stream<CloudRk> findByCloudEntUpdateAfter(Instant timestamp);
|
||||
|
||||
/**
|
||||
* 按公司查找 Cloud RK
|
||||
*
|
||||
* @param company 公司对象
|
||||
* @return Cloud RK
|
||||
*/
|
||||
Optional<CloudRk> findByCompany(Company company);
|
||||
|
||||
/**
|
||||
* 按公司查找 Cloud RK
|
||||
*
|
||||
* @param companyId 公司对象编号
|
||||
* @return Cloud RK
|
||||
*/
|
||||
Optional<CloudRk> findByCompanyId(int companyId);
|
||||
|
||||
List<CloudRk> findAllByCompanyId(int companyId);
|
||||
|
||||
long countByLatestUpdateBefore(Instant instant);
|
||||
|
||||
long countByAutoUpdateIsTrueAndLatestUpdateBefore(Instant instant);
|
||||
|
||||
List<CloudRk> findTop100ByLatestUpdateBeforeOrderByLatestUpdateDesc(Instant instant);
|
||||
|
||||
List<CloudRk> findTop100ByAutoUpdateIsTrueAndLatestUpdateBeforeOrderByLatestUpdateDesc(Instant instant);
|
||||
|
||||
@Modifying
|
||||
@Transactional
|
||||
int deleteAllByCompany(Company company);
|
||||
}
|
||||
@@ -1,400 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.rk;
|
||||
|
||||
import com.ecep.contract.manager.Desktop;
|
||||
import com.ecep.contract.manager.cloud.CloudInfo;
|
||||
import com.ecep.contract.manager.ds.company.BlackReasonType;
|
||||
import com.ecep.contract.manager.ds.company.CompanyFileUtils;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.model.CompanyBlackReason;
|
||||
import com.ecep.contract.manager.ds.company.repository.CompanyBlackReasonRepository;
|
||||
import com.ecep.contract.manager.ds.company.repository.CompanyOldNameRepository;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.manager.ds.other.service.SysConfService;
|
||||
import com.ecep.contract.manager.ui.ViewModelService;
|
||||
import com.ecep.contract.manager.util.HttpJsonUtils;
|
||||
import com.ecep.contract.manager.util.MyStringUtils;
|
||||
import com.fasterxml.jackson.annotation.JsonAlias;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import jakarta.persistence.criteria.Path;
|
||||
import javafx.application.Platform;
|
||||
import javafx.concurrent.Task;
|
||||
import lombok.Data;
|
||||
import org.controlsfx.control.TaskProgressView;
|
||||
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 java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "cloud-rk")
|
||||
public class CloudRkService implements ViewModelService<CloudRk, CloudRkInfoViewModel> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CloudRkService.class);
|
||||
|
||||
public static final String NAME = "集团相关方平台";
|
||||
public static final String VENDOR_NAME = "元素征信";
|
||||
public final static String ENTERPRISE_CREDIT_REPORT = "企业征信报告";
|
||||
|
||||
public static final String KEY_PROXY = "cloud.rk.proxy";
|
||||
public static final String KEY_SYNC_ELAPSE = "cloud.rk.sync.elapse";
|
||||
public static final long DEFAULT_SYNC_ELAPSE = 36000L;
|
||||
public static final String KEY_VENDOR_REPORT_URL = "cloud.rk.vendor.report.url";
|
||||
public static final String KEY_CUSTOMER_REPORT_URL = "cloud.rk.customer.report.url";
|
||||
public static final String KEY_ENT_SCORE_URL = "cloud.rk.ent_score.url";
|
||||
public static final String KEY_ENT_REPORT_URL = "cloud.rk.ent_report.url";
|
||||
public static final String KEY_ENT_FUZZY_URL = "cloud.rk.ent_fuzzy.url";
|
||||
public static final String KEY_BLACK_LIST_URL = "cloud.rk.black_list.url";
|
||||
public static final String KEY_BLACK_LIST_ELAPSE = "cloud.rk.black_list.elapse";
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
/**
|
||||
* 同步超时, 单位 毫秒
|
||||
*
|
||||
* @return 毫秒
|
||||
*/
|
||||
public long getSyncElapse() {
|
||||
String string = confService.getString(KEY_SYNC_ELAPSE);
|
||||
if (!StringUtils.hasText(string)) {
|
||||
return DEFAULT_SYNC_ELAPSE;
|
||||
}
|
||||
return MyStringUtils.toLong(string, DEFAULT_SYNC_ELAPSE);
|
||||
}
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class EntInfo {
|
||||
@JsonAlias("entid")
|
||||
private String id;
|
||||
@JsonAlias("entname")
|
||||
private String name;
|
||||
private boolean nowName;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private SysConfService confService;
|
||||
@Autowired
|
||||
private CloudRkRepository cloudRKRepository;
|
||||
@Lazy
|
||||
@Autowired
|
||||
private CompanyService companyService;
|
||||
@Autowired
|
||||
private CompanyOldNameRepository companyOldNameRepository;
|
||||
@Autowired
|
||||
private CompanyBlackReasonRepository companyBlackReasonRepository;
|
||||
|
||||
@Cacheable(key = "#p0")
|
||||
public CloudRk findById(Integer id) {
|
||||
return cloudRKRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
public Page<CloudRk> findAll(Specification<CloudRk> spec, Pageable pageable) {
|
||||
return cloudRKRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<CloudRk> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
return null;
|
||||
}
|
||||
return (root, query, builder) -> {
|
||||
Path<Object> company = root.get("company");
|
||||
return builder.or(
|
||||
builder.like(company.get("name"), "%" + searchText + "%"),
|
||||
builder.like(company.get("shortName"), "%" + searchText + "%"),
|
||||
builder.like(root.get("cloudId"), "%" + searchText + "%"),
|
||||
builder.like(root.get("description"), "%" + searchText + "%"));
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新黑名单列表
|
||||
*/
|
||||
public void updateBlackList(
|
||||
Company company, CloudRk cloudRk, BlackListUpdateContext context) throws IOException {
|
||||
List<String> companyNames = new ArrayList<>();
|
||||
companyNames.add(company.getName());
|
||||
// fixed 平台API使用企业名称,可能记录的是曾用名
|
||||
companyOldNameRepository.findAllByCompanyId(company.getId()).forEach(oldName -> {
|
||||
// 歧义的曾用名不采用
|
||||
if (oldName.getAmbiguity()) {
|
||||
return;
|
||||
}
|
||||
companyNames.add(oldName.getName());
|
||||
});
|
||||
|
||||
List<CompanyBlackReason> reasonList = new ArrayList<>();
|
||||
List<CompanyBlackReason> dbReasons = companyBlackReasonRepository.findAllByCompany(company);
|
||||
|
||||
companyNames.forEach(name -> {
|
||||
String url = context.getUrl() + URLEncoder.encode(name, StandardCharsets.UTF_8);
|
||||
try {
|
||||
HttpJsonUtils.get(url, json -> {
|
||||
if (!json.has("success") || !json.get("success").asBoolean()) {
|
||||
System.out.println("json = " + json.toPrettyString());
|
||||
return;
|
||||
}
|
||||
|
||||
if (json.has("data")) {
|
||||
JsonNode data = json.get("data");
|
||||
try {
|
||||
if (data.has("blackReason")) {
|
||||
for (JsonNode reason : data.get("blackReason")) {
|
||||
toCompanyBlackReasonList(company, BlackReasonType.BLACK, reason, dbReasons,
|
||||
reasonList, context.getObjectMapper());
|
||||
}
|
||||
}
|
||||
if (data.has("greyReason")) {
|
||||
for (JsonNode reason : data.get("greyReason")) {
|
||||
toCompanyBlackReasonList(company, BlackReasonType.GRAY, reason, dbReasons,
|
||||
reasonList, context.getObjectMapper());
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("{} {},json = {}", company.getName(), ex.getMessage(), json, ex);
|
||||
throw new RuntimeException(json.toString(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
// 保存JSON数据到公司目录
|
||||
String companyPath = company.getPath();
|
||||
if (StringUtils.hasText(companyPath)) {
|
||||
File dir = new File(companyPath);
|
||||
if (dir.exists()) {
|
||||
File file = new File(dir, CompanyFileUtils.FILE_BLACK_LIST_JSON);
|
||||
try {
|
||||
objectMapper.writeValue(file, json);
|
||||
} catch (IOException e) {
|
||||
logger.warn("Unable Save BlackList to {}, company:{}", file, company.getName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, context.getObjectMapper(), context.getSocksProxy());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
|
||||
if (!reasonList.isEmpty()) {
|
||||
companyBlackReasonRepository.saveAll(reasonList);
|
||||
}
|
||||
cloudRk.setCloudBlackListUpdated(Instant.now());
|
||||
}
|
||||
|
||||
private void toCompanyBlackReasonList(
|
||||
Company company, BlackReasonType type,
|
||||
JsonNode reason, List<CompanyBlackReason> dbReasons,
|
||||
List<CompanyBlackReason> reasonList, ObjectMapper objectMapper) throws JsonMappingException {
|
||||
ObjectNode object = (ObjectNode) reason;
|
||||
String key = "rk-" + object.remove("id").asText();
|
||||
CompanyBlackReason cbr = dbReasons.stream().filter(r -> r.getKey().equals(key)).findAny()
|
||||
.orElseGet(CompanyBlackReason::new);
|
||||
objectMapper.updateValue(cbr, reason);
|
||||
cbr.setCompany(company);
|
||||
cbr.setType(type);
|
||||
cbr.setKey(key);
|
||||
reasonList.add(cbr);
|
||||
}
|
||||
|
||||
public CompletableFuture<BlackListUpdateContext> createBlackListUpdateContext() {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
BlackListUpdateContext context = new BlackListUpdateContext();
|
||||
context.setObjectMapper(objectMapper);
|
||||
context.setProxy(confService.getString(KEY_PROXY));
|
||||
context.setUrl(confService.getString(KEY_BLACK_LIST_URL));
|
||||
// context.setElapse(confService.getLong(KEY_BLACK_LIST_ELAPSE));
|
||||
return context;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true
|
||||
*/
|
||||
public boolean checkBlackListUpdateElapse(
|
||||
Company company, CloudRk cloudRk, BlackListUpdateContext context) {
|
||||
Instant start = cloudRk.getCloudBlackListUpdated();
|
||||
if (start == null) {
|
||||
return true;
|
||||
}
|
||||
Instant elapse = start.plusSeconds(context.getElapse());
|
||||
return elapse.isBefore(Instant.now());
|
||||
}
|
||||
|
||||
public CloudRk getOrCreateCloudRk(CloudInfo info) {
|
||||
Optional<CloudRk> optional = cloudRKRepository.findById(info.getId());
|
||||
return optional.orElseGet(() -> getOrCreateCloudRk(info.getCompany()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回或者创建 Cloud RK
|
||||
*
|
||||
* @param company 公司对象
|
||||
* @return Cloud RK
|
||||
*/
|
||||
public CloudRk getOrCreateCloudRk(Company company) {
|
||||
Integer companyId = company.getId();
|
||||
List<CloudRk> list = cloudRKRepository.findAllByCompanyId(companyId);
|
||||
if (list.isEmpty()) {
|
||||
CloudRk rk = new CloudRk();
|
||||
rk.setCompany(company);
|
||||
rk.setCustomerGrade("");
|
||||
rk.setCustomerScore(-1);
|
||||
rk.setVendorGrade("");
|
||||
rk.setVendorScore(-1);
|
||||
rk.setRank("");
|
||||
return cloudRKRepository.save(rk);
|
||||
}
|
||||
if (list.size() == 1) {
|
||||
return list.getFirst();
|
||||
}
|
||||
|
||||
// 查询有 CloudId 的记录
|
||||
List<CloudRk> hasCouldIdList = list.stream().filter(v -> StringUtils.hasText(v.getCloudId()))
|
||||
.collect(Collectors.toList());
|
||||
// 没有匹配到一条时
|
||||
if (hasCouldIdList.isEmpty()) {
|
||||
// 保留第一条,其他删除
|
||||
CloudRk rk = list.removeFirst();
|
||||
cloudRKRepository.deleteAll(list);
|
||||
return rk;
|
||||
}
|
||||
|
||||
// 只有匹配到一条有 CloudId 的记录
|
||||
if (hasCouldIdList.size() == 1) {
|
||||
// 保留匹配的记录,其他删除
|
||||
CloudRk rk = hasCouldIdList.removeFirst();
|
||||
list.remove(rk);
|
||||
cloudRKRepository.deleteAll(list);
|
||||
return rk;
|
||||
}
|
||||
|
||||
// 查询有 CloudLatest 的记录
|
||||
List<CloudRk> hasLatestList = hasCouldIdList.stream().filter(v -> v.getCloudLatest() != null)
|
||||
.collect(Collectors.toList());
|
||||
// 没有匹配到一条时
|
||||
if (hasLatestList.isEmpty()) {
|
||||
// 保留第一条,其他删除
|
||||
CloudRk rk = hasCouldIdList.removeFirst();
|
||||
list.remove(rk);
|
||||
cloudRKRepository.deleteAll(list);
|
||||
return rk;
|
||||
}
|
||||
|
||||
// 只有匹配到一条有 CloudId 的记录
|
||||
if (hasLatestList.size() == 1) {
|
||||
// 保留匹配的记录,其他删除
|
||||
CloudRk rk = hasLatestList.removeFirst();
|
||||
list.remove(rk);
|
||||
cloudRKRepository.deleteAll(list);
|
||||
return rk;
|
||||
}
|
||||
|
||||
return hasLatestList.getFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存 Cloud Rk
|
||||
*
|
||||
* @param cloudRk Cloud Rk 对象
|
||||
* @return 更新的 Cloud Rk
|
||||
*/
|
||||
@CacheEvict(key = "#p0.id")
|
||||
public CloudRk save(CloudRk cloudRk) {
|
||||
return cloudRKRepository.save(cloudRk);
|
||||
}
|
||||
|
||||
@CacheEvict(key = "#p0.id")
|
||||
@Override
|
||||
public void delete(CloudRk entity) {
|
||||
cloudRKRepository.delete(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回 在 {@link #getSyncElapse()} 毫秒前,更新的
|
||||
*
|
||||
* @return 记录条数
|
||||
*/
|
||||
public long countNeedUpdate() {
|
||||
Instant now = Instant.now();
|
||||
long elapse = getSyncElapse();
|
||||
Instant instant = now.minusSeconds(elapse);
|
||||
return cloudRKRepository.countByAutoUpdateIsTrueAndLatestUpdateBefore(instant);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回距离上次更新超过 SysConfig:cloud.rk.black_list.elapse 秒的公司
|
||||
*/
|
||||
// @Transactional
|
||||
public List<CloudRk> findNeedUpdate() {
|
||||
Instant now = Instant.now();
|
||||
long elapse = getSyncElapse();
|
||||
Instant instant = now.minusSeconds(elapse);
|
||||
return cloudRKRepository.findTop100ByAutoUpdateIsTrueAndLatestUpdateBeforeOrderByLatestUpdateDesc(instant);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成定时同步任务
|
||||
*
|
||||
* @param taskProgressView 任务视图
|
||||
*/
|
||||
public void scheduledTasks(TaskProgressView<Task<?>> taskProgressView) {
|
||||
ScheduledExecutorService executorService = Desktop.instance.getExecutorService();
|
||||
// 第一次延时1分钟启动
|
||||
executorService.schedule(() -> {
|
||||
// 定时 30分钟 运行一次
|
||||
executorService.scheduleAtFixedRate(() -> {
|
||||
Desktop.instance.getTaskMonitorCenter().registerAndStartTask(new CloudRkSyncTask());
|
||||
}, 0, 30, TimeUnit.MINUTES);
|
||||
}, 1, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
@CacheEvict
|
||||
public void deleteByCompany(Company company) {
|
||||
int deleted = cloudRKRepository.deleteAllByCompany(company);
|
||||
if (deleted > 0) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Delete {} records by company:#{}", deleted, company.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO 这个可以无法更新缓存
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "#p0.id"),
|
||||
@CacheEvict(key = "#p1.id"),
|
||||
})
|
||||
public void resetTo(Company from, Company to) {
|
||||
List<CloudRk> list = cloudRKRepository.findAllByCompanyId(from.getId());
|
||||
for (CloudRk item : list) {
|
||||
item.setCompany(to);
|
||||
}
|
||||
cloudRKRepository.saveAll(list);
|
||||
}
|
||||
}
|
||||
@@ -1,143 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.rk;
|
||||
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.cloud.rk.ctx.CloudRkCtx;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.contract.service.ContractService;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import com.ecep.contract.manager.ui.Tasker;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* 集团相关方平台同步任务
|
||||
*/
|
||||
public class CloudRkSyncTask extends Tasker<Object> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CloudRkSyncTask.class);
|
||||
|
||||
private ContractService contractService;
|
||||
|
||||
@Override
|
||||
protected Object execute(MessageHolder holder) throws Exception {
|
||||
updateTitle("集团相关方平台");
|
||||
|
||||
CloudRkCtx cloudRkCtx = null;
|
||||
CloudRkService service = null;
|
||||
try {
|
||||
cloudRkCtx = new CloudRkCtx();
|
||||
service = SpringApp.getBean(CloudRkService.class);
|
||||
cloudRkCtx.setCloudRkService(service);
|
||||
} catch (BeansException e) {
|
||||
holder.error("没有找到 " + CloudRkService.NAME + " 服务");
|
||||
return null;
|
||||
}
|
||||
|
||||
long total = service.countNeedUpdate();
|
||||
if (total == 0) {
|
||||
holder.info("没有需要更新");
|
||||
return null;
|
||||
}
|
||||
|
||||
AtomicInteger counter = new AtomicInteger(0);
|
||||
holder.info("统计需要更新的 " + total + " 条");
|
||||
|
||||
try {
|
||||
// 每次获取100条记录
|
||||
while (!isCancelled()) {
|
||||
List<CloudRk> needUpdate = service.findNeedUpdate();
|
||||
if (needUpdate.isEmpty()) {
|
||||
holder.info("处理完成");
|
||||
break;
|
||||
}
|
||||
for (CloudRk cloudRk : needUpdate) {
|
||||
if (isCancelled()) {
|
||||
break;
|
||||
}
|
||||
MessageHolder subHolder = holder.sub(counter.get() + " / " + total + ">");
|
||||
// fixed lazy
|
||||
Company company = cloudRk.getCompany();
|
||||
if (company == null) {
|
||||
subHolder.error("数据不完整,没有关联公司");
|
||||
break;
|
||||
}
|
||||
if (!Hibernate.isInitialized(company)) {
|
||||
company = getCompanyService().findById(company.getId());
|
||||
cloudRk.setCompany(company);
|
||||
}
|
||||
if (cloudRk.isAutoUpdate()) {
|
||||
LocalDate date = LocalDate.now().minusYears(3);
|
||||
long count = getContractService().findAllByCompany(company).stream()
|
||||
.filter(c -> c.getSetupDate() != null)
|
||||
.filter(c -> c.getSetupDate().isAfter(date))
|
||||
.count();
|
||||
if (count == 0) {
|
||||
holder.info("公司:" + company.getName() + " 没有3年以上的合同, 取消自动更新");
|
||||
cloudRk.setAutoUpdate(false);
|
||||
}
|
||||
}
|
||||
try {
|
||||
cloudRk.setDescription("");
|
||||
if (cloudRkCtx.syncCompany(company, cloudRk, subHolder)) {
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
cloudRk.setLatestUpdate(Instant.now());
|
||||
service.save(cloudRk);
|
||||
}
|
||||
updateProgress(counter.incrementAndGet(), total);
|
||||
}
|
||||
}
|
||||
|
||||
if (isCancelled()) {
|
||||
updateMessage("Cancelled");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("运行至 {}/{} 时,发生错误中断", counter.get(), total, e);
|
||||
}
|
||||
updateProgress(1, 1);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public CompletableFuture<Void> delay(int second, Executor executor) {
|
||||
CompletableFuture<Void> future = new CompletableFuture<>();
|
||||
|
||||
long until = System.currentTimeMillis() + second * 1000L;
|
||||
String title = getTitle();
|
||||
AtomicReference<Runnable> reference = new AtomicReference<>();
|
||||
Runnable runnable = () -> {
|
||||
long let = until - System.currentTimeMillis();
|
||||
if (let < 0) {
|
||||
System.out.println("complete @" + Thread.currentThread().getName());
|
||||
future.complete(null);
|
||||
} else {
|
||||
// 再次调度
|
||||
executor.execute(reference.get());
|
||||
updateTitle(title + " 延时 " + ((int) let / 1000) + "秒");
|
||||
}
|
||||
};
|
||||
reference.set(runnable);
|
||||
// 第一次调度
|
||||
executor.execute(runnable);
|
||||
return future;
|
||||
}
|
||||
|
||||
ContractService getContractService() {
|
||||
if (contractService == null) {
|
||||
contractService = getBean(ContractService.class);
|
||||
}
|
||||
return contractService;
|
||||
}
|
||||
}
|
||||
@@ -1,270 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.rk;
|
||||
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.ds.company.CompanyFileUtils;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.model.CompanyContact;
|
||||
import com.ecep.contract.manager.ds.company.model.CompanyOldName;
|
||||
import com.ecep.contract.manager.ds.company.repository.CompanyContactRepository;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyOldNameService;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.Data;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@Data
|
||||
public class EntReportParser {
|
||||
private static final Logger logger = LoggerFactory.getLogger(EntReportParser.class);
|
||||
private ObjectMapper objectMapper;
|
||||
private Company company;
|
||||
private CloudRk cloudRk;
|
||||
private boolean modified = false;
|
||||
|
||||
|
||||
public void parse(JsonNode json) {
|
||||
if (!json.has("B1001")) {
|
||||
// 没有数据
|
||||
throw new RuntimeException("B1001 can't be null, json:" + json);
|
||||
}
|
||||
JsonNode b1001 = json.get("B1001");
|
||||
if (!b1001.has("count") || b1001.get("count").asInt() < 1 || !b1001.has("data")) {
|
||||
// 没有数据
|
||||
return;
|
||||
}
|
||||
JsonNode data = b1001.get("data");
|
||||
|
||||
updateCompanyProperty("entType", data.get("enttype"));
|
||||
updateCompanyProperty("entStatus", data.get("entstatus"));
|
||||
updateCompanyProperty("setupDate", data.get("esdate"));
|
||||
|
||||
updateCompanyUniscid(data);
|
||||
updateCompanyNameHistory(data);
|
||||
|
||||
updateCompanyProperty("regAddr", data.get("dom"));
|
||||
updateCompanyProperty("registeredCapital", data.get("regcap"));
|
||||
updateCompanyProperty("registeredCapitalCurrency", data.get("regcapcur"));
|
||||
updateCompanyProperty("legalRepresentative", data.get("frname"));
|
||||
updateCompanyProperty("district", data.get("regorgprovince"));
|
||||
updateCompanyProperty("telephone", data.get("tel"));
|
||||
updateCompanyProperty("address", data.get("oploc"));
|
||||
updateCompanyProperty("operationPeriodBegin", data.get("opfrom"));
|
||||
updateCompanyProperty("operationPeriodEnd", data.get("opto"), "-");
|
||||
updateCompanyProperty("industry", data.get("nicfulltitle"));
|
||||
|
||||
//
|
||||
updateCloudRkEntUpdateDate(data);
|
||||
|
||||
// 更新法人联系人
|
||||
updateLegalRepresentativeContact(data);
|
||||
|
||||
// 保存JSON数据到公司目录
|
||||
saveJsonToFile(json);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void updateLegalRepresentativeContact(JsonNode data) {
|
||||
String legalRepresentative = company.getLegalRepresentative();
|
||||
if (!StringUtils.hasText(legalRepresentative)) {
|
||||
return;
|
||||
}
|
||||
CompanyContact contact = null;
|
||||
boolean modified = false;
|
||||
CompanyContactRepository contactRepository = SpringApp.getBean(CompanyContactRepository.class);
|
||||
List<CompanyContact> contactList = contactRepository.findAllByCompanyAndName(company, legalRepresentative);
|
||||
if (contactList == null) {
|
||||
// db error
|
||||
return;
|
||||
}
|
||||
if (contactList.isEmpty()) {
|
||||
//没有,创建法人联系人
|
||||
contact = new CompanyContact();
|
||||
contact.setCompany(company);
|
||||
contact.setName(legalRepresentative);
|
||||
contact.setPosition("法定代表人");
|
||||
contact.setCreated(LocalDate.now());
|
||||
modified = true;
|
||||
} else {
|
||||
Optional<CompanyContact> any = contactList.stream().filter(c -> "法定代表人".equals(c.getPosition())).findAny();
|
||||
if (any.isEmpty()) {
|
||||
any = contactList.stream().findAny();
|
||||
}
|
||||
contact = any.get();
|
||||
// if (contact.getPostion() == null || !contact.setPostion().contains("法定代表人")) {
|
||||
// contact.setMemo("法定代表人");
|
||||
// modified = true;
|
||||
// }
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(contact.getEmail())) {
|
||||
String text = data.get("email").asText();
|
||||
contact.setEmail(text);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(contact.getAddress())) {
|
||||
String text = company.getAddress();
|
||||
contact.setAddress(text);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(contact.getPhone())) {
|
||||
String text = company.getTelephone();
|
||||
contact.setPhone(text);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(contact.getPosition())) {
|
||||
contact.setPosition("法定代表人");
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (modified) {
|
||||
contactRepository.save(contact);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void updateCompanyNameHistory(JsonNode data) {
|
||||
JsonNode node = data.get("nameHistory");
|
||||
if (node == null) {
|
||||
return;
|
||||
}
|
||||
// 历史曾用名
|
||||
String nameHistory = node.asText();
|
||||
if (!StringUtils.hasText(nameHistory)) {
|
||||
return;
|
||||
}
|
||||
List<String> historyNames = new ArrayList<>();
|
||||
for (String str : nameHistory.split(",")) {
|
||||
String trimmed = str.trim();
|
||||
if (StringUtils.hasText(trimmed)) {
|
||||
historyNames.add(trimmed);
|
||||
}
|
||||
}
|
||||
CompanyOldNameService service = SpringApp.getBean(CompanyOldNameService.class);
|
||||
List<CompanyOldName> oldNames = service.findAllByCompany(company);
|
||||
for (CompanyOldName oldName : oldNames) {
|
||||
historyNames.remove(oldName.getName());
|
||||
}
|
||||
for (String historyName : historyNames) {
|
||||
CompanyOldName oldName = new CompanyOldName();
|
||||
oldName.setName(historyName);
|
||||
oldName.setCompanyId(company.getId());
|
||||
oldName.setMemo("从相关方平台导入");
|
||||
oldName.setAmbiguity(false);
|
||||
service.save(oldName);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCompanyUniscid(JsonNode data) {
|
||||
JsonNode node = data.get("uniscid");
|
||||
if (node == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String uid = node.asText();
|
||||
if (StringUtils.hasText(uid)) {
|
||||
if (!uid.equals(company.getUniscid())) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("更新 {} 的 UNISCID {} -> {}", company.getName(), company.getUniscid(), uid);
|
||||
}
|
||||
company.setUniscid(uid);
|
||||
modified = true;
|
||||
}
|
||||
} else {
|
||||
//fixed 当平台返回的 社会统一信用代码为空时,如果原来已经有的,则不做更新
|
||||
if (StringUtils.hasText(company.getUniscid())) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("来自平台的 UNISCID 为空,但本地{}已经记录{},不做更改", company.getName(), company.getUniscid());
|
||||
}
|
||||
} else {
|
||||
company.setUniscid("");
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新 平台的数据更新时间戳
|
||||
*/
|
||||
private void updateCloudRkEntUpdateDate(JsonNode data) {
|
||||
JsonNode node = data.get("updated");
|
||||
if (node == null) {
|
||||
return;
|
||||
}
|
||||
LocalDateTime updated = objectMapper.convertValue(node, LocalDateTime.class);
|
||||
cloudRk.setCloudEntUpdate(updated.toInstant(ZoneOffset.ofHours(8)));
|
||||
}
|
||||
|
||||
private void updateCompanyProperty(String field, JsonNode node, String... excludeValues) {
|
||||
if (node == null || node.isNull()) {
|
||||
return;
|
||||
}
|
||||
String text = node.asText();
|
||||
for (String excludeValue : excludeValues) {
|
||||
if (Objects.equals(text, excludeValue)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
updateCompanyProperty(field, node);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新属性通用方法, 数据的类型转换由 objectMapper 提供
|
||||
*
|
||||
* @param field 类属性名称
|
||||
* @param node 数据来源 json node
|
||||
*/
|
||||
private void updateCompanyProperty(String field, JsonNode node) {
|
||||
if (node == null || node.isNull()) {
|
||||
return;
|
||||
}
|
||||
PropertyDescriptor descriptor = BeanUtils.getPropertyDescriptor(Company.class, field);
|
||||
if (descriptor == null) {
|
||||
logger.error("Company 的字段 {} 不存在,请确认.", field);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Object oldValue = descriptor.getReadMethod().invoke(company);
|
||||
Object newValue = objectMapper.convertValue(node, descriptor.getReadMethod().getReturnType());
|
||||
if (!Objects.equals(oldValue, newValue)) {
|
||||
descriptor.getWriteMethod().invoke(company, newValue);
|
||||
modified = true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void saveJsonToFile(JsonNode json) {
|
||||
String companyPath = company.getPath();
|
||||
if (StringUtils.hasText(companyPath)) {
|
||||
File dir = new File(companyPath);
|
||||
if (dir.exists()) {
|
||||
File file = new File(dir, CompanyFileUtils.FILE_B1001_JSON);
|
||||
try {
|
||||
objectMapper.writeValue(file, json);
|
||||
} catch (IOException e) {
|
||||
logger.warn("Unable Save BlackList to {}, company:{}", file, company.getName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,823 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.rk.ctx;
|
||||
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.cloud.AbstractCtx;
|
||||
import com.ecep.contract.manager.cloud.rk.CloudRk;
|
||||
import com.ecep.contract.manager.cloud.rk.CloudRkService;
|
||||
import com.ecep.contract.manager.ds.company.BlackReasonType;
|
||||
import com.ecep.contract.manager.ds.company.CompanyFileUtils;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.model.CompanyBlackReason;
|
||||
import com.ecep.contract.manager.ds.company.model.CompanyContact;
|
||||
import com.ecep.contract.manager.ds.company.model.CompanyOldName;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyBlackReasonService;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyContactService;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyOldNameService;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import com.ecep.contract.manager.util.HttpJsonUtils;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import lombok.Setter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.net.ssl.SSLException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.ecep.contract.manager.SpringApp.getBean;
|
||||
|
||||
public class CloudRkCtx extends AbstractCtx {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CloudRkCtx.class);
|
||||
@Setter
|
||||
private CloudRkService cloudRkService;
|
||||
@Setter
|
||||
private CompanyService companyService;
|
||||
@Setter
|
||||
private CompanyBlackReasonService companyBlackReasonService;
|
||||
@Setter
|
||||
private ObjectMapper objectMapper;
|
||||
private Proxy socksProxy;
|
||||
|
||||
public CloudRkService getCloudRkService() {
|
||||
if (cloudRkService == null) {
|
||||
cloudRkService = getBean(CloudRkService.class);
|
||||
}
|
||||
return cloudRkService;
|
||||
}
|
||||
|
||||
public CompanyService getCompanyService() {
|
||||
if (companyService == null) {
|
||||
companyService = getBean(CompanyService.class);
|
||||
}
|
||||
return companyService;
|
||||
}
|
||||
|
||||
CompanyBlackReasonService getCompanyBlackReasonService() {
|
||||
if (companyBlackReasonService == null) {
|
||||
companyBlackReasonService = getBean(CompanyBlackReasonService.class);
|
||||
}
|
||||
return companyBlackReasonService;
|
||||
}
|
||||
|
||||
ObjectMapper getObjectMapper() {
|
||||
if (objectMapper == null) {
|
||||
objectMapper = getBean(ObjectMapper.class);
|
||||
}
|
||||
return objectMapper;
|
||||
}
|
||||
|
||||
Proxy getSocksProxy() {
|
||||
if (socksProxy == null) {
|
||||
String proxy = getConfService().getString(CloudRkService.KEY_PROXY);
|
||||
URI proxyUri = URI.create(proxy);
|
||||
Proxy.Type proxyType = Proxy.Type.valueOf(proxyUri.getScheme().toUpperCase());
|
||||
socksProxy = new Proxy(
|
||||
proxyType,
|
||||
new InetSocketAddress(proxyUri.getHost(), proxyUri.getPort())
|
||||
);
|
||||
}
|
||||
return socksProxy;
|
||||
}
|
||||
|
||||
public void post(String url, Consumer<Map<String, Object>> data, Consumer<JsonNode> consumer) throws IOException {
|
||||
HttpJsonUtils.post(url, data, consumer, getObjectMapper(), getSocksProxy());
|
||||
}
|
||||
|
||||
|
||||
public boolean syncCompany(Company company, CloudRk cloudRk, MessageHolder holder) {
|
||||
if (!StringUtils.hasText(cloudRk.getCloudId())) {
|
||||
holder.warn("未定义平台编号, 尝试从平台上自动获取");
|
||||
// 当未定义平台编号时,尝试自动获取
|
||||
if (!queryCloudIdAndSelectOne(company, cloudRk, holder)) {
|
||||
// 自动获取到平台编号失败,立即返回
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(cloudRk.getCloudId()) || cloudRk.getCloudId().equals("-")) {
|
||||
// 平台编号为 空 或 - 时,跳过同步
|
||||
holder.debug("平台编号为 空 或 - 时,跳过同步");
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean updated = false;
|
||||
try {
|
||||
if (updateEnterpriseInfo(company, cloudRk, holder)) {
|
||||
company = getCompanyService().save(company);
|
||||
updated = true;
|
||||
}
|
||||
|
||||
if (updateBlackList(company, cloudRk, holder)) {
|
||||
updated = true;
|
||||
}
|
||||
|
||||
if (updateEnterpriseCredit(company, cloudRk, holder)) {
|
||||
// cloudRk modified
|
||||
updated = true;
|
||||
}
|
||||
if (updateCustomerScore(company, cloudRk, holder)) {
|
||||
// cloudRk modified
|
||||
updated = true;
|
||||
}
|
||||
if (updateVendorScore(company, cloudRk, holder)) {
|
||||
// cloudRk modified
|
||||
updated = true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 异常
|
||||
logger.error("使用评分接口更新企业资信评价等级时发生错误", e);
|
||||
cloudRk.setDescription("评分接口错误:" + e.getMessage());
|
||||
}
|
||||
return updated;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新黑名单列表
|
||||
*/
|
||||
public boolean updateBlackList(
|
||||
Company company, CloudRk cloudRk, MessageHolder holder
|
||||
) throws IOException {
|
||||
Instant start = cloudRk.getCloudBlackListUpdated();
|
||||
if (start != null) {
|
||||
long elapse = getConfService().getLong(CloudRkService.KEY_BLACK_LIST_ELAPSE);
|
||||
if (elapse > 0) {
|
||||
Instant next = start.plusSeconds(elapse);
|
||||
if (next.isAfter(Instant.now())) {
|
||||
holder.debug("更新时间未到, 上次更新时间 = " + start);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String api = getConfService().getString(CloudRkService.KEY_BLACK_LIST_URL);
|
||||
List<String> companyNames = getCompanyService().getAllNames(company);
|
||||
|
||||
|
||||
List<CompanyBlackReason> reasonList = new ArrayList<>();
|
||||
List<CompanyBlackReason> dbReasons = getCompanyBlackReasonService().findAllByCompany(company);
|
||||
for (String name : companyNames) {
|
||||
String url = api + URLEncoder.encode(name, StandardCharsets.UTF_8);
|
||||
try {
|
||||
HttpJsonUtils.get(url, json -> {
|
||||
applyBlackReason(json, company, cloudRk, reasonList, dbReasons, holder);
|
||||
saveJsonToFile(company, json, "black-" + name + ".json", holder);
|
||||
}, getObjectMapper(), getSocksProxy());
|
||||
} catch (IOException e) {
|
||||
catchException(e, holder);
|
||||
}
|
||||
}
|
||||
|
||||
if (reasonList.isEmpty()) {
|
||||
cloudRk.setCloudBlackListUpdated(Instant.now());
|
||||
return false;
|
||||
|
||||
}
|
||||
for (CompanyBlackReason companyBlackReason : reasonList) {
|
||||
getCompanyBlackReasonService().save(companyBlackReason);
|
||||
}
|
||||
cloudRk.setCloudBlackListUpdated(Instant.now());
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean applyBlackReason(
|
||||
JsonNode json, Company company, CloudRk cloudRk,
|
||||
List<CompanyBlackReason> reasonList, List<CompanyBlackReason> dbReasons,
|
||||
MessageHolder holder
|
||||
) {
|
||||
if (isUnSuccess(json, holder)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!json.has("data")) {
|
||||
holder.error("数据异常,返回的json中没有 data 字段");
|
||||
return false;
|
||||
}
|
||||
JsonNode data = json.get("data");
|
||||
|
||||
if (data.has("blackReason")) {
|
||||
for (JsonNode reason : data.get("blackReason")) {
|
||||
try {
|
||||
toCompanyBlackReasonList(company, BlackReasonType.BLACK, reason, dbReasons, reasonList);
|
||||
} catch (JsonMappingException e) {
|
||||
holder.error("blackReason " + e.getMessage() + ", " + reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (data.has("greyReason")) {
|
||||
for (JsonNode reason : data.get("greyReason")) {
|
||||
try {
|
||||
toCompanyBlackReasonList(company, BlackReasonType.GRAY, reason, dbReasons, reasonList);
|
||||
} catch (JsonMappingException e) {
|
||||
holder.error("greyReason " + e.getMessage() + ", " + reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void toCompanyBlackReasonList(
|
||||
Company company, BlackReasonType type,
|
||||
JsonNode reason, List<CompanyBlackReason> dbReasons,
|
||||
List<CompanyBlackReason> reasonList
|
||||
) throws JsonMappingException {
|
||||
ObjectNode object = (ObjectNode) reason;
|
||||
String key = "rk-" + object.remove("id").asText();
|
||||
CompanyBlackReason cbr = dbReasons.stream().filter(r -> r.getKey().equals(key)).findAny().orElseGet(CompanyBlackReason::new);
|
||||
getObjectMapper().updateValue(cbr, reason);
|
||||
cbr.setCompany(company);
|
||||
cbr.setType(type);
|
||||
cbr.setKey(key);
|
||||
reasonList.add(cbr);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新评分
|
||||
*/
|
||||
public boolean updateEnterpriseCredit(
|
||||
Company company, CloudRk cloudRk, MessageHolder holder
|
||||
) throws IOException {
|
||||
String api = getConfService().getString(CloudRkService.KEY_ENT_SCORE_URL);
|
||||
AtomicBoolean modified = new AtomicBoolean(false);
|
||||
try {
|
||||
post(api, data -> {
|
||||
data.put("entname", company.getName());
|
||||
// data.put("entid", cloudInfo.getCloudId());
|
||||
data.put("get", true);
|
||||
}, json -> {
|
||||
modified.set(applyEnterpriseCredit(json, cloudRk, holder));
|
||||
saveJsonToFile(company, json, "credit.json", holder);
|
||||
});
|
||||
} catch (IOException e) {
|
||||
catchException(e, holder);
|
||||
}
|
||||
return modified.get();
|
||||
}
|
||||
|
||||
private boolean applyEnterpriseCredit(JsonNode json, CloudRk cloudRk, MessageHolder holder) {
|
||||
if (isUnSuccess(json, holder)) {
|
||||
return false;
|
||||
}
|
||||
if (isUnHasField(json, "data", holder)) {
|
||||
return false;
|
||||
}
|
||||
JsonNode data = json.get("data");
|
||||
boolean modified = false;
|
||||
String level = "";
|
||||
String description = "";
|
||||
if (data.isNull()) {
|
||||
level = "-";
|
||||
} else {
|
||||
level = data.get("level").asText();
|
||||
description = data.get("levelDescription").asText();
|
||||
}
|
||||
|
||||
if (updateText(cloudRk::getRank, cloudRk::setRank, level, holder, "企业资信评价等级")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateText(cloudRk::getRankDescription, cloudRk::setRankDescription, description, holder, "企业资信评价等级说明")) {
|
||||
modified = true;
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
private boolean isUnHasField(JsonNode json, String field, MessageHolder holder) {
|
||||
if (!json.has("data")) {
|
||||
holder.error("数据异常,返回的json中没有 data 字段");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isUnSuccess(JsonNode json, MessageHolder holder) {
|
||||
if (isUnHasField(json, "success", holder)) {
|
||||
return true;
|
||||
}
|
||||
if (!json.get("success").asBoolean()) {
|
||||
holder.error("数据异常,返回 success = false, " + json);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户信用
|
||||
*/
|
||||
public boolean updateCustomerScore(
|
||||
Company company, CloudRk cloudRk, MessageHolder holder
|
||||
) throws IOException {
|
||||
String url = getConfService().getString(CloudRkService.KEY_CUSTOMER_REPORT_URL);
|
||||
AtomicBoolean modified = new AtomicBoolean(false);
|
||||
try {
|
||||
post(url, data -> {
|
||||
// data.put("entName", company.getName());
|
||||
data.put("entId", cloudRk.getCloudId());
|
||||
data.put("get", true);
|
||||
}, json -> {
|
||||
modified.set(applyCustomerScore(json, company, cloudRk, holder));
|
||||
saveJsonToFile(company, json, "customer-score.json", holder);
|
||||
});
|
||||
} catch (IOException e) {
|
||||
catchException(e, holder);
|
||||
}
|
||||
return modified.get();
|
||||
}
|
||||
|
||||
private boolean applyCustomerScore(JsonNode json, Company company, CloudRk cloudRk, MessageHolder holder) {
|
||||
if (isUnSuccess(json, holder)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean modified = false;
|
||||
String grade = "";
|
||||
int score = 0;
|
||||
String description = "";
|
||||
if (isUnHasField(json, "data", holder)) {
|
||||
grade = "-";
|
||||
score = -1;
|
||||
} else {
|
||||
JsonNode data = json.get("data");
|
||||
if (data.isNull()) {
|
||||
grade = "无";
|
||||
score = -1;
|
||||
} else {
|
||||
grade = data.get("grade").asText();
|
||||
score = data.get("totalScore").asInt();
|
||||
description = data.get("description").asText();
|
||||
}
|
||||
}
|
||||
|
||||
if (updateText(cloudRk::getCustomerGrade, cloudRk::setCustomerGrade, grade, holder, "客户信用评级")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateNumber(cloudRk::getCustomerScore, cloudRk::setCustomerScore, score, holder, "客户信用总分")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateText(cloudRk::getCustomerDescription, cloudRk::setCustomerDescription, description, holder, "客户信用评级说明")) {
|
||||
modified = true;
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
|
||||
public boolean updateVendorScore(
|
||||
Company company, CloudRk cloudRk, MessageHolder holder
|
||||
) throws IOException {
|
||||
String url = getConfService().getString(CloudRkService.KEY_VENDOR_REPORT_URL);
|
||||
AtomicBoolean modified = new AtomicBoolean(false);
|
||||
try {
|
||||
post(url, data -> {
|
||||
// data.put("entName", company.getName());
|
||||
data.put("entId", cloudRk.getCloudId());
|
||||
data.put("get", true);
|
||||
}, json -> {
|
||||
modified.set(applyVendorScore(json, cloudRk, holder));
|
||||
saveJsonToFile(company, json, "vendor-score.json", holder);
|
||||
});
|
||||
} catch (IOException e) {
|
||||
catchException(e, holder);
|
||||
}
|
||||
return modified.get();
|
||||
}
|
||||
|
||||
private boolean applyVendorScore(JsonNode json, CloudRk cloudRk, MessageHolder holder) {
|
||||
if (isUnSuccess(json, holder)) {
|
||||
return false;
|
||||
}
|
||||
boolean modified = false;
|
||||
String grade = "";
|
||||
int score = 0;
|
||||
String description = "";
|
||||
if (isUnHasField(json, "data", holder)) {
|
||||
grade = "-";
|
||||
score = -1;
|
||||
} else {
|
||||
JsonNode data = json.get("data");
|
||||
if (data.isNull()) {
|
||||
grade = "无";
|
||||
score = -1;
|
||||
} else {
|
||||
grade = data.get("scoreLevel").asText();
|
||||
score = data.get("score").asInt();
|
||||
description = data.get("scoreDes").asText();
|
||||
}
|
||||
}
|
||||
|
||||
if (updateText(cloudRk::getVendorGrade, cloudRk::setVendorGrade, grade, holder, "供应商信用得分")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateNumber(cloudRk::getVendorScore, cloudRk::setVendorScore, score, holder, "供应商信用总分")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateText(cloudRk::getVendorDescription, cloudRk::setVendorDescription, description, holder, "供应商信用评级说明")) {
|
||||
modified = true;
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动获取到平台编号
|
||||
*
|
||||
* @param company 公司对象
|
||||
* @param cloudRk Cloud Rk
|
||||
* @return true 更新了 cloudId,否则false
|
||||
*/
|
||||
private boolean queryCloudIdAndSelectOne(
|
||||
Company company, CloudRk cloudRk, MessageHolder holder
|
||||
) {
|
||||
try {
|
||||
List<CloudRkService.EntInfo> entInfos = queryEnterpriseWithFuzzy(company, cloudRk, holder);
|
||||
// 返回的查询结果为空时
|
||||
if (entInfos.isEmpty()) {
|
||||
// 设置为 -, 不在重复查找
|
||||
cloudRk.setCloudId("-");
|
||||
holder.warn("在平台中没有匹配到 " + company.getName());
|
||||
return false;
|
||||
}
|
||||
|
||||
// 在返回的结果中,找到与公司名字一致的一个
|
||||
Optional<CloudRkService.EntInfo> optional = entInfos.stream().filter(n -> n.getName().equals(company.getName())).findAny();
|
||||
if (optional.isPresent()) {
|
||||
cloudRk.setCloudId(optional.get().getId());
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
holder.error("在平台中查询到多个匹配 (" + entInfos.stream().map(CloudRkService.EntInfo::getName).collect(Collectors.joining(", ")) + "),请手工同步选择匹配");
|
||||
return false;
|
||||
|
||||
} catch (Exception e) {
|
||||
// 异常
|
||||
holder.error("查询接口获取企业平台编号发生错误 = " + e.getMessage());
|
||||
if (logger.isErrorEnabled()) {
|
||||
logger.error("使用模糊查询接口获取 {} 企业平台编号发生错误", company.getName(), e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 使用模糊查询接口查询相关企业信息
|
||||
*/
|
||||
public List<CloudRkService.EntInfo> queryEnterpriseWithFuzzy(
|
||||
Company company, CloudRk cloudRk, MessageHolder holder
|
||||
) throws IOException {
|
||||
String url = getConfService().getString(CloudRkService.KEY_ENT_FUZZY_URL);
|
||||
List<CloudRkService.EntInfo> results = new ArrayList<>();
|
||||
ObjectMapper objectMapper = getObjectMapper();
|
||||
try {
|
||||
HttpJsonUtils.post(url, data -> {
|
||||
data.put("theKey", company.getName());
|
||||
data.put("get", true);
|
||||
}, json -> {
|
||||
applyEnterpriseQuery(json, company, cloudRk, results, holder);
|
||||
saveJsonToFile(company, json, "fuzzy.json", holder);
|
||||
}, objectMapper, getSocksProxy());
|
||||
} catch (IOException ex) {
|
||||
catchException(ex, holder);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private boolean applyEnterpriseQuery(JsonNode json, Company company, CloudRk cloudRk, List<CloudRkService.EntInfo> results, MessageHolder holder) {
|
||||
if (!json.has("data")) {
|
||||
// 没有数据
|
||||
holder.error("数据异常,返回的json中没有 data 字段");
|
||||
return false;
|
||||
}
|
||||
JsonNode dataNode = json.get("data");
|
||||
if (!dataNode.isArray()) {
|
||||
holder.error("数据异常,返回的json中 data 字段不是数组");
|
||||
return false;
|
||||
}
|
||||
ObjectMapper objectMapper = getObjectMapper();
|
||||
|
||||
for (JsonNode node : dataNode) {
|
||||
try {
|
||||
CloudRkService.EntInfo entInfo = new CloudRkService.EntInfo();
|
||||
objectMapper.updateValue(entInfo, node);
|
||||
if (node.has("isNowName")) {
|
||||
String s = node.get("isNowName").asText();
|
||||
entInfo.setNowName(s.equals("1") || s.equals("true"));
|
||||
}
|
||||
results.add(entInfo);
|
||||
} catch (Exception e) {
|
||||
holder.error("更新企业信息失败:" + e.getMessage() + ", json=" + node.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新企业工商注册信息
|
||||
*/
|
||||
public boolean updateEnterpriseInfo(
|
||||
Company company, CloudRk cloudRk, MessageHolder holder
|
||||
) throws IOException {
|
||||
String api = getConfService().getString(CloudRkService.KEY_ENT_REPORT_URL);
|
||||
Proxy socksProxy = getSocksProxy();
|
||||
holder.debug("更新企业工商注册信息: " + company.getName() + " @ " + api + ", proxy=" + socksProxy);
|
||||
AtomicBoolean modified = new AtomicBoolean(false);
|
||||
try {
|
||||
post(api, data -> {
|
||||
data.put("entName", company.getName());
|
||||
data.put("entid", cloudRk.getCloudId());
|
||||
data.put("get", true);
|
||||
data.put("method", "data");
|
||||
data.put("nodetype", "B1001");
|
||||
}, jsonNode -> {
|
||||
modified.set(applyEnterpriseInfo(jsonNode, company, cloudRk, holder));
|
||||
saveJsonToFile(company, jsonNode, CompanyFileUtils.FILE_B1001_JSON, holder);
|
||||
});
|
||||
} catch (IOException e) {
|
||||
catchException(e, holder);
|
||||
}
|
||||
return modified.get();
|
||||
}
|
||||
|
||||
private void catchException(IOException e, MessageHolder holder) throws IOException {
|
||||
if (e instanceof SSLException) {
|
||||
holder.error("网络错误:" + e.getMessage());
|
||||
// 网络错误时,抛出异常,中断后续网络请求
|
||||
throw e;
|
||||
}
|
||||
if (e instanceof SocketException) {
|
||||
holder.error("网络错误:" + e.getMessage());
|
||||
// 网络错误时,抛出异常,中断后续网络请求
|
||||
throw e;
|
||||
}
|
||||
holder.error(e.getMessage());
|
||||
}
|
||||
|
||||
private boolean applyEnterpriseInfo(JsonNode json, Company company, CloudRk cloudRk, MessageHolder holder) {
|
||||
if (!json.has("B1001")) {
|
||||
holder.error("数据异常,返回的json中没有 B1001 字段");
|
||||
return false;
|
||||
}
|
||||
JsonNode b1001 = json.get("B1001");
|
||||
if (!b1001.has("count") || b1001.get("count").asInt() < 1 || !b1001.has("data")) {
|
||||
holder.error("数据异常,B1001 字段没有数据");
|
||||
return false;
|
||||
}
|
||||
boolean modified = false;
|
||||
JsonNode data = b1001.get("data");
|
||||
if (updateText(company::getEntType, company::setEntType, data, "enttype", holder, "企业类型")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateText(company::getEntStatus, company::setEntStatus, data, "entstatus", holder, "企业状态")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateLocalDate(company::getSetupDate, company::setSetupDate, data, "esdate", holder, "成立日期")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateText(company::getUniscid, company::setUniscid, data, "uniscid", holder, "企业状态")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateText(company::getRegAddr, company::setRegAddr, data, "dom", holder, "注册地址")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateText(company::getRegisteredCapital, company::setRegisteredCapital, data, "regcap", holder, "注册资金")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateText(company::getRegisteredCapitalCurrency, company::setRegisteredCapitalCurrency, data, "regcapcur", holder, "资本金币种")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateText(company::getLegalRepresentative, company::setLegalRepresentative, data, "frname", holder, "法人")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateText(company::getDistrict, company::setDistrict, data, "regorgprovince", holder, "注册区域")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateText(company::getTelephone, company::setTelephone, data, "tel", holder, "注册电话")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateText(company::getAddress, company::setAddress, data, "oploc", holder, "通讯地址")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateOperationPeriodBegin(company, data, holder)) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateOperationPeriodEnd(company, data, holder)) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateText(company::getIndustry, company::setIndustry, data, "nicfulltitle", holder, "行业")) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
updateCompanyNameHistory(company, data, holder.sub("曾用名"));
|
||||
updateLegalRepresentativeContact(company, data, holder.sub("法人联系方式"));
|
||||
updateInstant(cloudRk::getCloudEntUpdate, cloudRk::setCloudEntUpdate, data, "updated", holder, "更新时间", false);
|
||||
return modified;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新法人联系人联系方式
|
||||
*/
|
||||
private void updateLegalRepresentativeContact(Company company, JsonNode data, MessageHolder holder) {
|
||||
String legalRepresentative = company.getLegalRepresentative();
|
||||
if (!StringUtils.hasText(legalRepresentative)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
CompanyContactService contactService = SpringApp.getBean(CompanyContactService.class);
|
||||
List<CompanyContact> contactList = contactService.findAllByCompanyAndName(company, legalRepresentative);
|
||||
if (contactList == null) {
|
||||
// db error
|
||||
return;
|
||||
}
|
||||
CompanyContact contact = null;
|
||||
boolean modified = false;
|
||||
if (contactList.isEmpty()) {
|
||||
//没有,创建法人联系人
|
||||
contact = new CompanyContact();
|
||||
contact.setCompany(company);
|
||||
contact.setName(legalRepresentative);
|
||||
contact.setPosition("法定代表人");
|
||||
contact.setCreated(LocalDate.now());
|
||||
modified = true;
|
||||
} else {
|
||||
// 先尝试查找法人
|
||||
Optional<CompanyContact> any = contactList.stream().filter(c -> "法定代表人".equals(c.getPosition())).findAny();
|
||||
// 如果没有找到,列表中第一个联系人
|
||||
if (any.isEmpty()) {
|
||||
any = contactList.stream().findFirst();
|
||||
}
|
||||
contact = any.get();
|
||||
if (updateText(contact::getPosition, contact::setPosition, "法定代表人", holder, "职位")) {
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(contact.getEmail())) {
|
||||
if (updateText(contact::getEmail, contact::setEmail, data, "email", holder, "邮箱")) {
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(contact.getAddress())) {
|
||||
if (updateText(contact::getAddress, contact::setAddress, data, "oploc", holder, "地址")) {
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(contact.getPhone())) {
|
||||
if (updateText(contact::getPhone, contact::setPhone, data, "tel", holder, "电话")) {
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (modified) {
|
||||
contactService.save(contact);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean updateOperationPeriodBegin(Company company, JsonNode data, MessageHolder holder) {
|
||||
return updateLocalDate(company::getOperationPeriodBegin, company::setOperationPeriodBegin, data, "opfrom", holder, "营业期限起始日期", true);
|
||||
}
|
||||
|
||||
private boolean updateOperationPeriodEnd(Company company, JsonNode data, MessageHolder holder) {
|
||||
JsonNode node = data.get("opto");
|
||||
if (node == null) {
|
||||
return false;
|
||||
}
|
||||
String text = node.asText();
|
||||
if (StringUtils.hasText(text)) {
|
||||
if (text.equals("-")) {
|
||||
return updateLocalDate(company::getOperationPeriodEnd, company::setOperationPeriodEnd, (LocalDate) null, holder, "营业期限截至日期", true);
|
||||
}
|
||||
return updateLocalDate(company::getOperationPeriodEnd, company::setOperationPeriodEnd, data, "opto", holder, "营业期限截至日期", true);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private void updateCompanyNameHistory(Company company, JsonNode data, MessageHolder holder) {
|
||||
JsonNode node = data.get("nameHistory");
|
||||
if (node == null) {
|
||||
return;
|
||||
}
|
||||
// 历史曾用名
|
||||
String nameHistory = node.asText();
|
||||
if (!StringUtils.hasText(nameHistory)) {
|
||||
return;
|
||||
}
|
||||
List<String> historyNames = new ArrayList<>();
|
||||
for (String str : nameHistory.split(",")) {
|
||||
String trimmed = str.trim();
|
||||
if (StringUtils.hasText(trimmed)) {
|
||||
historyNames.add(trimmed);
|
||||
}
|
||||
}
|
||||
CompanyOldNameService service = SpringApp.getBean(CompanyOldNameService.class);
|
||||
List<CompanyOldName> oldNames = service.findAllByCompany(company);
|
||||
for (CompanyOldName oldName : oldNames) {
|
||||
// 已经存在的移除
|
||||
historyNames.remove(oldName.getName());
|
||||
}
|
||||
for (String historyName : historyNames) {
|
||||
CompanyOldName oldName = service.createNew(company, historyName, false);
|
||||
oldName.setMemo("从相关方平台导入");
|
||||
service.save(oldName);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean updateLocalDate(Supplier<LocalDate> getter, Consumer<LocalDate> setter, JsonNode data, String field, MessageHolder holder, String topic, boolean allowNull) {
|
||||
JsonNode node = data.get(field);
|
||||
if (node == null || node.isNull()) {
|
||||
return false;
|
||||
}
|
||||
LocalDate localDate = getObjectMapper().convertValue(node, LocalDate.class);
|
||||
if (localDate == null && !allowNull) {
|
||||
return false;
|
||||
}
|
||||
return updateLocalDate(getter, setter, localDate, holder, topic, allowNull);
|
||||
}
|
||||
|
||||
private boolean updateLocalDate(Supplier<LocalDate> getter, Consumer<LocalDate> setter, JsonNode data, String field, MessageHolder holder, String topic) {
|
||||
return updateLocalDate(getter, setter, data, field, holder, topic, false);
|
||||
}
|
||||
|
||||
private void updateInstant(Supplier<Instant> getter, Consumer<Instant> setter, JsonNode data, String field, MessageHolder holder, String topic, boolean allowNull) {
|
||||
JsonNode node = data.get("updated");
|
||||
if (node == null) {
|
||||
return;
|
||||
}
|
||||
LocalDateTime updated = getObjectMapper().convertValue(node, LocalDateTime.class);
|
||||
if (updated == null) {
|
||||
if (!allowNull) {
|
||||
return;
|
||||
}
|
||||
updateInstant(getter, setter, null, holder, topic);
|
||||
return;
|
||||
}
|
||||
Instant instant = updated.toInstant(ZoneOffset.ofHours(8));
|
||||
updateInstant(getter, setter, instant, holder, topic);
|
||||
}
|
||||
|
||||
private boolean updateText(Supplier<String> getter, Consumer<String> setter, JsonNode data, String field, MessageHolder holder, String topic) {
|
||||
JsonNode node = data.get(field);
|
||||
if (node == null || node.isNull()) {
|
||||
return false;
|
||||
}
|
||||
String text = node.asText();
|
||||
if (!StringUtils.hasText(text)) {
|
||||
return false;
|
||||
}
|
||||
return updateText(getter, setter, text, holder, topic);
|
||||
}
|
||||
|
||||
private void saveJsonToFile(Company company, JsonNode json, String fileName, MessageHolder holder) {
|
||||
String companyPath = company.getPath();
|
||||
if (!StringUtils.hasText(companyPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
File dir = new File(companyPath);
|
||||
if (!dir.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
File file = new File(dir, fileName);
|
||||
try {
|
||||
getObjectMapper().writeValue(file, json);
|
||||
holder.debug("保存文件 " + file.getName());
|
||||
} catch (IOException e) {
|
||||
holder.error("保存文件 " + file.getName() + " 发生错误:" + e.getMessage());
|
||||
logger.error("Save {}", file.getAbsolutePath(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public CloudRk getOrCreateCloudRk(Company company) {
|
||||
return getCloudRkService().getOrCreateCloudRk(company);
|
||||
}
|
||||
|
||||
public CloudRk save(CloudRk cloudRk) {
|
||||
return getCloudRkService().save(cloudRk);
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.tyc;
|
||||
|
||||
import com.ecep.contract.manager.cloud.CloudBaseInfo;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "CLOUD_TYC", schema = "supplier_ms")
|
||||
public class CloudTyc extends CloudBaseInfo {
|
||||
|
||||
@ColumnDefault("0")
|
||||
@Column(name = "SCORE", nullable = false)
|
||||
private Integer score;
|
||||
|
||||
@Column(name = "CLOUD_LATEST")
|
||||
private Instant cloudLatest;
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.tyc;
|
||||
|
||||
import com.ecep.contract.manager.cloud.CloudInfoViewModel;
|
||||
import com.ecep.contract.manager.ui.util.MyDateTimePropertyUtils;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Objects;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class CloudTycInfoViewModel extends CloudInfoViewModel<CloudTyc> {
|
||||
|
||||
private SimpleIntegerProperty score = new SimpleIntegerProperty();
|
||||
private SimpleObjectProperty<LocalDateTime> cloudLatest = new SimpleObjectProperty<>();
|
||||
|
||||
@Override
|
||||
protected void updateFrom(CloudTyc info) {
|
||||
super.updateFrom(info);
|
||||
update_((CloudTyc) info);
|
||||
}
|
||||
|
||||
private void update_(CloudTyc info) {
|
||||
score.set(info.getScore());
|
||||
|
||||
if (info.getCloudLatest() != null) {
|
||||
ZoneId zone = ZoneId.systemDefault();
|
||||
ZonedDateTime zonedDateTime = info.getCloudLatest().atZone(zone);
|
||||
LocalDateTime localDateTime = zonedDateTime.toLocalDateTime();
|
||||
cloudLatest.set(localDateTime);
|
||||
} else {
|
||||
cloudLatest.set(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean copyTo(CloudTyc info) {
|
||||
boolean modified = super.copyTo(info);
|
||||
if (copyTo_((CloudTyc) info)) {
|
||||
modified = true;
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
private boolean copyTo_(CloudTyc info) {
|
||||
boolean modified = super.copyTo(info);
|
||||
if (!Objects.equals(info.getId(), getId().get())) {
|
||||
info.setId(getId().get());
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!Objects.equals(info.getScore(), getScore().get())) {
|
||||
info.setScore(getScore().get());
|
||||
modified = true;
|
||||
}
|
||||
|
||||
Instant latest = MyDateTimePropertyUtils.localDateTimeToInstant(cloudLatest);
|
||||
if (!Objects.equals(info.getCloudLatest(), latest)) {
|
||||
info.setCloudLatest(latest);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
return modified;
|
||||
}
|
||||
|
||||
public static CloudTycInfoViewModel from(CloudTyc cc) {
|
||||
CloudTycInfoViewModel model = new CloudTycInfoViewModel();
|
||||
model.update(cc);
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.tyc;
|
||||
|
||||
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.manager.SpringApp;
|
||||
import com.ecep.contract.manager.ui.table.cell.CompanyTableCell;
|
||||
import com.ecep.contract.manager.ds.company.controller.CompanyWindowController;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.manager.ui.AbstEntityManagerSkin;
|
||||
import com.ecep.contract.manager.ui.table.cell.LocalDateTimeTableCell;
|
||||
|
||||
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 CloudTycManagerSkin
|
||||
extends
|
||||
AbstEntityManagerSkin<CloudTyc, CloudTycInfoViewModel, CloudTycManagerSkin, CloudTycManagerWindowController> {
|
||||
@Setter
|
||||
private CloudTycService cloudTycService;
|
||||
|
||||
@Setter
|
||||
private CompanyService companyService;
|
||||
|
||||
public CloudTycManagerSkin(CloudTycManagerWindowController controller) {
|
||||
super(controller);
|
||||
}
|
||||
|
||||
CloudTycService getCloudTycService() {
|
||||
if (cloudTycService == null) {
|
||||
cloudTycService = getBean(CloudTycService.class);
|
||||
}
|
||||
return cloudTycService;
|
||||
}
|
||||
|
||||
CompanyService getCompanyService() {
|
||||
if (companyService == null) {
|
||||
companyService = SpringApp.getBean(CompanyService.class);
|
||||
}
|
||||
return companyService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CloudTycInfoViewModel> loadTableData() {
|
||||
String searchText = controller.searchKeyField.getText();
|
||||
Specification<CloudTyc> spec = null;
|
||||
if (StringUtils.hasText(searchText)) {
|
||||
|
||||
Specification<CloudTyc> 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<CloudTyc> cloudIdSpec = (root, query, builder) -> {
|
||||
return builder.like(root.get("cloudId"), "%" + searchText + "%");
|
||||
};
|
||||
|
||||
spec = Specification.anyOf(companySpec, cloudIdSpec);
|
||||
}
|
||||
|
||||
Page<CloudTyc> page = getCloudTycService().findAll(spec, getPageable());
|
||||
updateFooter(page);
|
||||
return page.map(CloudTycInfoViewModel::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.scoreColumn.setCellValueFactory(param -> param.getValue().getScore());
|
||||
|
||||
}
|
||||
|
||||
@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<CloudTycInfoViewModel> selectedItems = getTableView().getSelectionModel().getSelectedItems();
|
||||
if (selectedItems.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (CloudTycInfoViewModel selectedItem : selectedItems) {
|
||||
CloudTyc cloudTyc = getCloudTycService().findById(selectedItem.getId().get());
|
||||
// selectedItem.getDescription().set("");
|
||||
if (selectedItem.copyTo(cloudTyc)) {
|
||||
CloudTyc saved = getCloudTycService().save(cloudTyc);
|
||||
selectedItem.update(saved);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTableRowDoubleClickedAction(CloudTycInfoViewModel item) {
|
||||
Company company = item.getCompany().get();
|
||||
if (!Hibernate.isInitialized(item)) {
|
||||
company = getCompanyService().findById(company.getId());
|
||||
}
|
||||
CompanyWindowController.show(company, getTableView().getScene().getWindow());
|
||||
}
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.tyc;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.cloud.CloudBaseInfo;
|
||||
import com.ecep.contract.manager.cloud.CloudInfo;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.manager.ui.AbstManagerWindowController;
|
||||
import com.ecep.contract.manager.ui.FxmlPath;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
* 天眼查信息管理窗口控制器
|
||||
*/
|
||||
@Lazy
|
||||
@Scope("prototype")
|
||||
@Component
|
||||
@FxmlPath("/ui/cloud/tyc_manager.fxml")
|
||||
public class CloudTycManagerWindowController
|
||||
extends AbstManagerWindowController<CloudTyc, CloudTycInfoViewModel, CloudTycManagerSkin> {
|
||||
|
||||
public static void show() {
|
||||
show(CloudTycManagerWindowController.class, null);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private CloudTycService cloudTycService;
|
||||
|
||||
@Autowired
|
||||
private CompanyService companyService;
|
||||
|
||||
@FXML
|
||||
public TableColumn<CloudTycInfoViewModel, Number> idColumn;
|
||||
@FXML
|
||||
public TableColumn<CloudTycInfoViewModel, LocalDateTime> latestUpdateColumn;
|
||||
|
||||
@FXML
|
||||
public TableColumn<CloudTycInfoViewModel, Company> companyColumn;
|
||||
@FXML
|
||||
public TableColumn<CloudTycInfoViewModel, String> cloudIdColumn;
|
||||
@FXML
|
||||
public TableColumn<CloudTycInfoViewModel, LocalDateTime> cloudLatestColumn;
|
||||
@FXML
|
||||
public TableColumn<CloudTycInfoViewModel, Number> scoreColumn;
|
||||
|
||||
@FXML
|
||||
public TableColumn<CloudTycInfoViewModel, String> descriptionColumn;
|
||||
|
||||
@Override
|
||||
public CloudTycService getViewModelService() {
|
||||
return cloudTycService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CloudTycManagerSkin createDefaultSkin() {
|
||||
return new CloudTycManagerSkin(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show(Stage stage) {
|
||||
super.show(stage);
|
||||
getTitle().set("数据源:天眼查");
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据迁移,从 CloudInfo 迁移到 CloudRk
|
||||
*/
|
||||
public void onDateTransferAction(ActionEvent event) {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
com.ecep.contract.manager.cloud.CloudInfoRepository cloudInfoRepository = SpringApp
|
||||
.getBean(com.ecep.contract.manager.cloud.CloudInfoRepository.class);
|
||||
cloudInfoRepository.findAll().forEach(v -> {
|
||||
try {
|
||||
CloudTyc cloudTyc = cloudTycService.getOrCreateCloudTyc(v);
|
||||
if (copyTo(v, cloudTyc)) {
|
||||
cloudTycService.save(cloudTyc);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
boolean copyTo(CloudInfo v, CloudBaseInfo cloudRk) {
|
||||
boolean modified = false;
|
||||
if (!Objects.equals(cloudRk.getLatestUpdate(), v.getLatestUpdate())) {
|
||||
cloudRk.setLatestUpdate(v.getLatestUpdate());
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!Objects.equals(cloudRk.getCloudId(), v.getCloudId())) {
|
||||
cloudRk.setCloudId(v.getCloudId());
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!Objects.equals(cloudRk.getCompany(), v.getCompany())) {
|
||||
cloudRk.setCompany(v.getCompany());
|
||||
modified = true;
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.tyc;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.ecep.contract.manager.ds.MyRepository;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
|
||||
@Repository
|
||||
public interface CloudTycRepository extends MyRepository<CloudTyc, Integer> {
|
||||
|
||||
List<CloudTyc> findAllByCompanyId(Integer companyId);
|
||||
|
||||
Optional<CloudTyc> findByCompanyId(Integer companyId);
|
||||
|
||||
@Modifying
|
||||
@Transactional
|
||||
int deleteAllByCompany(Company company);
|
||||
|
||||
}
|
||||
@@ -1,208 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.tyc;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
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.manager.SpringApp;
|
||||
import com.ecep.contract.manager.cloud.CloudInfo;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.other.service.SysConfService;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import com.ecep.contract.manager.ui.ViewModelService;
|
||||
import com.ecep.contract.manager.util.MyStringUtils;
|
||||
import com.ecep.contract.manager.util.UITools;
|
||||
|
||||
import javafx.application.Platform;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
public class CloudTycService implements ViewModelService<CloudTyc, CloudTycInfoViewModel> {
|
||||
public static final String NAME = "天眼查";
|
||||
|
||||
public final static String TYC_ENTERPRISE_ANALYSIS_REPORT = "企业分析报告";
|
||||
public final static String TYC_ENTERPRISE_BASIC_REPORT = "基础版企业信用报告";
|
||||
public final static String TYC_ENTERPRISE_MAJOR_REPORT = "专业版企业信用报告";
|
||||
public final static String TYC_ENTERPRISE_CREDIT_REPORT = "企业信用信息公示报告";
|
||||
public static final String URL_COMPANY = "https://www.tianyancha.com/company/%s";
|
||||
public static final String URL_COMPANY_SEARCH = "https://www.tianyancha.com/search?key=%s";
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CloudTycService.class);
|
||||
|
||||
/**
|
||||
* 天眼查报告,文件名中必须包含 天眼查 字样
|
||||
*
|
||||
* @param fileName 文件名
|
||||
* @return 是否是天眼查报告
|
||||
*/
|
||||
public static boolean isTycReport(String fileName) {
|
||||
// 文件名中包含 天眼查 字样
|
||||
return fileName.contains(CloudTycService.NAME);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private CloudTycRepository cloudTycRepository;
|
||||
|
||||
public CloudTyc getOrCreateCloudTyc(CloudInfo info) {
|
||||
Optional<CloudTyc> optional = cloudTycRepository.findById(info.getId());
|
||||
return optional.orElseGet(() -> getOrCreateCloudTyc(info.getCompany()));
|
||||
}
|
||||
|
||||
public CloudTyc getOrCreateCloudTyc(Company company) {
|
||||
Integer companyId = company.getId();
|
||||
List<CloudTyc> list = cloudTycRepository.findAllByCompanyId(companyId);
|
||||
if (list.isEmpty()) {
|
||||
CloudTyc tyc = new CloudTyc();
|
||||
tyc.setCompany(company);
|
||||
tyc.setScore(-1);
|
||||
tyc.setCloudLatest(null);
|
||||
return cloudTycRepository.save(tyc);
|
||||
}
|
||||
if (list.size() == 1) {
|
||||
return list.getFirst();
|
||||
}
|
||||
|
||||
// 查询有 CloudId 的记录
|
||||
List<CloudTyc> hasCouldIdList = list.stream()
|
||||
.filter(v -> {
|
||||
return StringUtils.hasText(v.getCloudId())
|
||||
&& MyStringUtils.isAllDigit(v.getCloudId());
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 没有匹配到一条时
|
||||
if (hasCouldIdList.isEmpty()) {
|
||||
// 保留第一条,其他删除
|
||||
CloudTyc rk = list.removeFirst();
|
||||
cloudTycRepository.deleteAll(list);
|
||||
return rk;
|
||||
}
|
||||
|
||||
// 只有匹配到一条有 CloudId 的记录
|
||||
if (hasCouldIdList.size() == 1) {
|
||||
// 保留匹配的记录,其他删除
|
||||
CloudTyc rk = hasCouldIdList.removeFirst();
|
||||
list.remove(rk);
|
||||
cloudTycRepository.deleteAll(list);
|
||||
return rk;
|
||||
}
|
||||
|
||||
// 查询有 Score 的记录
|
||||
List<CloudTyc> hasLatestList = hasCouldIdList.stream().filter(v -> {
|
||||
return v.getScore() != null && v.getScore() > 0;
|
||||
}).collect(Collectors.toList());
|
||||
// 没有匹配到一条时
|
||||
if (hasLatestList.isEmpty()) {
|
||||
// 保留第一条,其他删除
|
||||
CloudTyc rk = hasCouldIdList.removeFirst();
|
||||
list.remove(rk);
|
||||
cloudTycRepository.deleteAll(list);
|
||||
return rk;
|
||||
}
|
||||
|
||||
// 只有匹配到一条有 CloudId 的记录
|
||||
if (hasLatestList.size() == 1) {
|
||||
// 保留匹配的记录,其他删除
|
||||
CloudTyc rk = hasLatestList.removeFirst();
|
||||
list.remove(rk);
|
||||
cloudTycRepository.deleteAll(list);
|
||||
return rk;
|
||||
}
|
||||
|
||||
return hasLatestList.getFirst();
|
||||
|
||||
}
|
||||
|
||||
public CloudTyc save(CloudTyc cloudTyc) {
|
||||
return cloudTycRepository.save(cloudTyc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(CloudTyc entity) {
|
||||
cloudTycRepository.delete(entity);
|
||||
}
|
||||
|
||||
public void save(CloudTycInfoViewModel viewModel) {
|
||||
int infoId = viewModel.getId().get();
|
||||
CloudTyc cloudTyc = cloudTycRepository.findById(infoId).orElse(null);
|
||||
if (cloudTyc == null) {
|
||||
return;
|
||||
}
|
||||
if (viewModel.copyTo(cloudTyc)) {
|
||||
cloudTyc.setLatestUpdate(Instant.now());
|
||||
CloudTyc saved = cloudTycRepository.save(cloudTyc);
|
||||
Platform.runLater(() -> viewModel.update(saved));
|
||||
}
|
||||
}
|
||||
|
||||
public void showInBrowse(String cloudId) {
|
||||
String baseUrl = SpringApp.getBean(SysConfService.class).getString("cloud.tyc.company");
|
||||
if (!StringUtils.hasText(baseUrl)) {
|
||||
UITools.showAlertAndWait("系统参数 cloud.tyc.company 未配置");
|
||||
return;
|
||||
}
|
||||
|
||||
String url = baseUrl + cloudId;
|
||||
|
||||
com.ecep.contract.manager.util.DesktopUtils.showInBrowse(url);
|
||||
|
||||
// UITools.showExceptionAndWait("使用浏览器打开网址出现异常", e);
|
||||
|
||||
}
|
||||
|
||||
public void deleteByCompany(Company company) {
|
||||
int deleted = cloudTycRepository.deleteAllByCompany(company);
|
||||
if (deleted > 0) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Delete {} records by company:#{}", deleted, company.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void resetTo(Company from, Company to) {
|
||||
List<CloudTyc> list = cloudTycRepository.findAllByCompanyId(from.getId());
|
||||
for (CloudTyc item : list) {
|
||||
item.setCompany(to);
|
||||
}
|
||||
cloudTycRepository.saveAll(list);
|
||||
}
|
||||
|
||||
public CloudTyc findById(Integer id) {
|
||||
return cloudTycRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
public Page<CloudTyc> findAll(Specification<CloudTyc> spec, PageRequest pageable) {
|
||||
return cloudTycRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
public Page<CloudTyc> findAll(Specification<CloudTyc> spec, Pageable pageable) {
|
||||
return cloudTycRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<CloudTyc> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
return null;
|
||||
}
|
||||
return (root, query, builder) -> {
|
||||
return builder.like(root.get("cloudId"), "%" + searchText + "%");
|
||||
};
|
||||
}
|
||||
|
||||
// TODO
|
||||
public void syncCompany(Company company, MessageHolder holder) {
|
||||
holder.warn("TODO 未实现");
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8;
|
||||
|
||||
import com.ecep.contract.manager.cloud.CloudBaseInfo;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "CLOUD_YU", schema = "supplier_ms")
|
||||
@ToString
|
||||
public class CloudYu extends CloudBaseInfo {
|
||||
@ColumnDefault("''")
|
||||
@Column(name = "EX_MSG")
|
||||
private String exceptionMessage;
|
||||
|
||||
/**
|
||||
* 供应商信息更新日期
|
||||
*/
|
||||
@Column(name = "VEN_UP_DATE")
|
||||
private LocalDate vendorUpdateDate;
|
||||
|
||||
/**
|
||||
* 客户信息更新日期
|
||||
*/
|
||||
@Column(name = "CUS_UP_DATE")
|
||||
private LocalDate customerUpdateDate;
|
||||
|
||||
/**
|
||||
* 数据更新日期
|
||||
*/
|
||||
@Column(name = "CLOUD_LATEST")
|
||||
private Instant cloudLatest;
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8;
|
||||
|
||||
import com.ecep.contract.manager.cloud.CloudInfoViewModel;
|
||||
import com.ecep.contract.manager.ui.util.MyDateTimePropertyUtils;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.*;
|
||||
import java.util.Objects;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class CloudYuInfoViewModel extends CloudInfoViewModel<CloudYu> {
|
||||
private SimpleStringProperty vendorCode = new SimpleStringProperty();
|
||||
private SimpleStringProperty vendorClassCode = new SimpleStringProperty();
|
||||
private SimpleObjectProperty<LocalDate> vendorDevelopDate = new SimpleObjectProperty<>();
|
||||
|
||||
private SimpleStringProperty customerCode = new SimpleStringProperty();
|
||||
private SimpleStringProperty customerClassCode = new SimpleStringProperty();
|
||||
private SimpleObjectProperty<LocalDate> customerDevelopDate = new SimpleObjectProperty<>();
|
||||
|
||||
private SimpleObjectProperty<LocalDateTime> cloudLatest = new SimpleObjectProperty<>();
|
||||
|
||||
@Override
|
||||
protected void updateFrom(CloudYu info) {
|
||||
super.updateFrom(info);
|
||||
update_((CloudYu) info);
|
||||
}
|
||||
|
||||
private void update_(CloudYu info) {
|
||||
vendorCode.set(info.getExceptionMessage());
|
||||
vendorDevelopDate.set(info.getVendorUpdateDate());
|
||||
customerDevelopDate.set(info.getCustomerUpdateDate());
|
||||
if (info.getCloudLatest() != null) {
|
||||
ZoneId zone = ZoneId.systemDefault();
|
||||
ZonedDateTime zonedDateTime = info.getCloudLatest().atZone(zone);
|
||||
LocalDateTime localDateTime = zonedDateTime.toLocalDateTime();
|
||||
cloudLatest.set(localDateTime);
|
||||
} else {
|
||||
cloudLatest.set(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean copyTo(CloudYu info) {
|
||||
boolean modified = super.copyTo(info);
|
||||
if (copyTo_((CloudYu) info)) {
|
||||
modified = true;
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
private boolean copyTo_(CloudYu info) {
|
||||
boolean modified = false;
|
||||
if (!Objects.equals(info.getExceptionMessage(), vendorCode.get())) {
|
||||
info.setExceptionMessage(vendorCode.get());
|
||||
modified = true;
|
||||
}
|
||||
if (!Objects.equals(info.getVendorUpdateDate(), vendorDevelopDate.get())) {
|
||||
info.setVendorUpdateDate(vendorDevelopDate.get());
|
||||
modified = true;
|
||||
}
|
||||
if (!Objects.equals(info.getCustomerUpdateDate(), customerDevelopDate.get())) {
|
||||
info.setCustomerUpdateDate(customerDevelopDate.get());
|
||||
modified = true;
|
||||
}
|
||||
|
||||
Instant latest = MyDateTimePropertyUtils.localDateTimeToInstant(cloudLatest);
|
||||
if (!Objects.equals(info.getCloudLatest(), latest)) {
|
||||
info.setCloudLatest(latest);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
return modified;
|
||||
}
|
||||
|
||||
public static CloudYuInfoViewModel from(CloudYu cc) {
|
||||
CloudYuInfoViewModel model = new CloudYuInfoViewModel();
|
||||
model.update(cc);
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8;
|
||||
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface CloudYuRepository
|
||||
// curd
|
||||
extends CrudRepository<CloudYu, Integer>, PagingAndSortingRepository<CloudYu, Integer>,
|
||||
// JPA interfaces
|
||||
JpaRepository<CloudYu, Integer>, JpaSpecificationExecutor<CloudYu> {
|
||||
|
||||
List<CloudYu> findAllByCompanyId(Integer companyId);
|
||||
|
||||
Optional<CloudYu> findByCompanyId(Integer companyId);
|
||||
|
||||
@Modifying
|
||||
@Transactional
|
||||
int deleteAllByCompany(Company company);
|
||||
|
||||
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.ds.contract.model.ContractGroup;
|
||||
import com.ecep.contract.manager.ds.contract.service.ContractGroupService;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import com.ecep.contract.manager.ui.Tasker;
|
||||
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* 同步合同分组
|
||||
*/
|
||||
public class ContractGroupSyncTask extends Tasker<Object> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ContractGroupSyncTask.class);
|
||||
@Setter
|
||||
private ContractGroupService contractGroupService;
|
||||
|
||||
public ContractGroupSyncTask() {
|
||||
updateTitle("用友U8系统-同步合同分组信息");
|
||||
}
|
||||
|
||||
ContractGroupService getContractGroupService() {
|
||||
if (contractGroupService == null) {
|
||||
contractGroupService = SpringApp.getBean(ContractGroupService.class);
|
||||
}
|
||||
return contractGroupService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object execute(MessageHolder holder) throws Exception {
|
||||
YongYouU8Service service = null;
|
||||
try {
|
||||
service = SpringApp.getBean(YongYouU8Service.class);
|
||||
} catch (BeansException e) {
|
||||
logger.error("can't get bean of YongYouU8Service", e);
|
||||
holder.error("can't get bean of YongYouU8Service");
|
||||
return null;
|
||||
}
|
||||
|
||||
AtomicInteger counter = new AtomicInteger(0);
|
||||
logger.info("读取 U8 系统 CM_Group 数据表...");
|
||||
List<Map<String, Object>> list = service.queryAllContractGroup();
|
||||
int size = list.size();
|
||||
holder.debug("总共读取 CM_Group 数据 " + size + " 条");
|
||||
|
||||
for (Map<String, Object> map : list) {
|
||||
if (isCancelled()) {
|
||||
holder.info("Cancelled");
|
||||
return null;
|
||||
}
|
||||
MessageHolder sub = holder.sub(counter.get() + "/" + size + ">" );
|
||||
sync(map, sub);
|
||||
// 更新进度
|
||||
updateProgress(counter.incrementAndGet(), size);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void sync(Map<String, Object> map, MessageHolder holder) {
|
||||
boolean modified = false;
|
||||
|
||||
String groupCode = (String) map.get("cGroupID");
|
||||
String groupName = (String) map.get("cGroupName");
|
||||
String groupTitle = (String) map.get("cRemark");
|
||||
|
||||
ContractGroupService service = getContractGroupService();
|
||||
ContractGroup contractGroup = service.findByCode(groupCode);
|
||||
if (contractGroup == null) {
|
||||
contractGroup = service.newContractGroup();
|
||||
holder.info("新建合同分组:" + groupCode);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!Objects.equals(contractGroup.getCode(), groupCode)) {
|
||||
contractGroup.setCode(groupCode);
|
||||
holder.info("合同分组代码:" + contractGroup.getCode() + " -> " + groupCode);
|
||||
modified = true;
|
||||
}
|
||||
if (!Objects.equals(contractGroup.getName(), groupName)) {
|
||||
contractGroup.setName(groupName);
|
||||
holder.info("合同分组名称:" + contractGroup.getName() + " -> " + groupName);
|
||||
modified = true;
|
||||
}
|
||||
if (!Objects.equals(contractGroup.getTitle(), groupTitle)) {
|
||||
contractGroup.setTitle(groupTitle);
|
||||
holder.info("合同分组标题:" + contractGroup.getTitle() + " -> " + groupTitle);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (modified) {
|
||||
service.save(contractGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.ds.contract.model.ContractKind;
|
||||
import com.ecep.contract.manager.ds.contract.service.ContractKindService;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import com.ecep.contract.manager.ui.Tasker;
|
||||
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* 同步合同分类
|
||||
*/
|
||||
public class ContractKindSyncTask extends Tasker<Object> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ContractKindSyncTask.class);
|
||||
@Setter
|
||||
private ContractKindService contractKindService;
|
||||
|
||||
public ContractKindSyncTask() {
|
||||
updateTitle("用友U8系统-同步合同分类信息");
|
||||
}
|
||||
|
||||
ContractKindService getContractKindService() {
|
||||
if (contractKindService == null) {
|
||||
contractKindService = SpringApp.getBean(ContractKindService.class);
|
||||
}
|
||||
return contractKindService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object execute(MessageHolder holder) throws Exception {
|
||||
YongYouU8Repository repository = null;
|
||||
try {
|
||||
repository = SpringApp.getBean(YongYouU8Repository.class);
|
||||
} catch (BeansException e) {
|
||||
logger.error("can't get bean of YongYouU8Repository", e);
|
||||
holder.error("can't get bean of YongYouU8Repository");
|
||||
return null;
|
||||
}
|
||||
|
||||
AtomicInteger counter = new AtomicInteger(0);
|
||||
logger.info("读取 U8 系统 CM_Kind 数据表...");
|
||||
List<Map<String, Object>> list = repository.queryAllContractKind();
|
||||
int size = list.size();
|
||||
holder.debug("总共读取 CM_Kind 数据 " + size + " 条");
|
||||
|
||||
for (Map<String, Object> map : list) {
|
||||
if (isCancelled()) {
|
||||
holder.info("Cancelled");
|
||||
return null;
|
||||
}
|
||||
MessageHolder sub = holder.sub(counter.get() + "/" + size + ">");
|
||||
sync(map, sub);
|
||||
// 更新进度
|
||||
updateProgress(counter.incrementAndGet(), size);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void sync(Map<String, Object> map, MessageHolder holder) {
|
||||
boolean modified = false;
|
||||
|
||||
String typeCode = (String) map.get("KindID");
|
||||
String typeName = (String) map.get("KindName");
|
||||
String typeTitle = (String) map.get("Description");
|
||||
|
||||
ContractKindService kindService = getContractKindService();
|
||||
ContractKind contractKind = kindService.findByCode(typeCode);
|
||||
if (contractKind == null) {
|
||||
contractKind = new ContractKind();
|
||||
holder.info("新建合同分类:" + typeCode);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!Objects.equals(contractKind.getCode(), typeCode)) {
|
||||
contractKind.setCode(typeCode);
|
||||
holder.info("合同分类代码:" + contractKind.getCode() + " -> " + typeCode);
|
||||
modified = true;
|
||||
}
|
||||
if (!Objects.equals(contractKind.getName(), typeName)) {
|
||||
contractKind.setName(typeName);
|
||||
holder.info("合同分类名称:" + contractKind.getName() + " -> " + typeName);
|
||||
modified = true;
|
||||
}
|
||||
if (!Objects.equals(contractKind.getTitle(), typeTitle)) {
|
||||
contractKind.setTitle(typeTitle);
|
||||
holder.info("合同分类描述:" + contractKind.getTitle() + " -> " + typeTitle);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (modified) {
|
||||
kindService.save(contractKind);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.ecep.contract.manager.ds.contract.tasker.AbstContractRepairTasker;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
|
||||
/**
|
||||
* 用友U8系统-同步全量合同
|
||||
*/
|
||||
public class ContractSyncAllTask extends AbstContractRepairTasker {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ContractSyncAllTask.class);
|
||||
|
||||
|
||||
@Override
|
||||
protected void repair(MessageHolder holder) {
|
||||
updateTitle("用友U8系统-同步全量合同");
|
||||
YongYouU8Repository repository = getBean(YongYouU8Repository.class);
|
||||
|
||||
long total = repository.countAllContracts();
|
||||
AtomicInteger counter = new AtomicInteger(0);
|
||||
|
||||
try (Stream<Map<String, Object>> stream = repository.queryAllContractForStream()) {
|
||||
stream.forEach(rs -> {
|
||||
if (isCancelled()) {
|
||||
holder.debug("Cancelled");
|
||||
return;
|
||||
}
|
||||
MessageHolder subHolder = holder.sub(counter.get() + " / " + total + "> ");
|
||||
try {
|
||||
repairFromCMList(rs, subHolder);
|
||||
} catch (Exception e) {
|
||||
updateMessage(e.getMessage());
|
||||
logger.error("data = {}", rs, e);
|
||||
|
||||
}
|
||||
updateProgress(counter.incrementAndGet(), total);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8;
|
||||
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.ds.contract.model.ContractGroup;
|
||||
import com.ecep.contract.manager.ds.contract.model.ContractKind;
|
||||
import com.ecep.contract.manager.ds.contract.model.ContractType;
|
||||
import com.ecep.contract.manager.ds.contract.service.ContractGroupService;
|
||||
import com.ecep.contract.manager.ds.contract.service.ContractKindService;
|
||||
import com.ecep.contract.manager.ds.contract.service.ContractTypeService;
|
||||
import com.ecep.contract.manager.ds.other.model.Employee;
|
||||
import com.ecep.contract.manager.ds.other.service.EmployeeService;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.beans.BeansException;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ContractSyncContext {
|
||||
<T> T getBean(Class<T> requiredType) throws BeansException {
|
||||
return SpringApp.getBean(requiredType);
|
||||
}
|
||||
|
||||
private ContractTypeService contractTypeService;
|
||||
private ContractGroupService contractGroupService;
|
||||
private ContractKindService contractKindService;
|
||||
private EmployeeService employeeService;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
Consumer<String> consumer;
|
||||
|
||||
public ContractSyncContext() {
|
||||
}
|
||||
|
||||
private ContractTypeService getContractTypeService() {
|
||||
if (contractTypeService == null) {
|
||||
contractTypeService = getBean(ContractTypeService.class);
|
||||
}
|
||||
return contractTypeService;
|
||||
}
|
||||
|
||||
private ContractGroupService getContractGroupService() {
|
||||
if (contractGroupService == null) {
|
||||
contractGroupService = getBean(ContractGroupService.class);
|
||||
}
|
||||
return contractGroupService;
|
||||
}
|
||||
|
||||
private ContractKindService getContractKindService() {
|
||||
if (contractKindService == null) {
|
||||
contractKindService = getBean(ContractKindService.class);
|
||||
}
|
||||
return contractKindService;
|
||||
}
|
||||
|
||||
private EmployeeService getEmployeeService() {
|
||||
if (employeeService == null) {
|
||||
employeeService = getBean(EmployeeService.class);
|
||||
}
|
||||
return employeeService;
|
||||
}
|
||||
|
||||
public ContractType getTypeByCode(String typeCode) {
|
||||
return getContractTypeService().findByCode(typeCode);
|
||||
}
|
||||
|
||||
public ContractGroup getGroupByCode(String groupCode) {
|
||||
return getContractGroupService().findByCode(groupCode);
|
||||
}
|
||||
|
||||
public ContractKind getKindByName(String kindName) {
|
||||
return getContractKindService().findByName(kindName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void updateMessage(String message) {
|
||||
Consumer<String> consumer = getConsumer();
|
||||
if (consumer != null) {
|
||||
consumer.accept(message);
|
||||
}
|
||||
}
|
||||
public Employee findEmployeeByCode(String personCode) {
|
||||
return getEmployeeService().findByCode(personCode);
|
||||
}
|
||||
public Employee findEmployeeByName(String personName) {
|
||||
if (personName == null) {
|
||||
return null;
|
||||
}
|
||||
return getEmployeeService().findByName(personName);
|
||||
}
|
||||
}
|
||||
@@ -1,141 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.cloud.u8.ctx.ContractCtx;
|
||||
import com.ecep.contract.manager.ds.contract.tasker.AbstContractRepairTasker;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
|
||||
/**
|
||||
* 合同同步任务
|
||||
*/
|
||||
public class ContractSyncTask extends AbstContractRepairTasker {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ContractSyncTask.class);
|
||||
private YongYouU8Repository repository;
|
||||
|
||||
public ContractSyncTask() {
|
||||
updateTitle("用友U8系统-同步合同");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void repair(MessageHolder holder) {
|
||||
updateTitle("用友U8系统-同步合同");
|
||||
try {
|
||||
repository = SpringApp.getBean(YongYouU8Repository.class);
|
||||
} catch (BeansException e) {
|
||||
holder.error("无法获取 YongYouU8Repository " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
if (getConfService().getBoolean(ContractCtx.KEY_SYNC_USE_LATEST_ID)) {
|
||||
syncByLatestId(holder);
|
||||
} else {
|
||||
syncByLatestDate(holder);
|
||||
}
|
||||
}
|
||||
|
||||
private void syncByLatestId(MessageHolder holder) {
|
||||
int latestId = getConfService().getInt(ContractCtx.KEY_SYNC_BY_LATEST_ID);
|
||||
updateTitle("用友U8系统-同步合同,从 " + latestId + " 开始");
|
||||
|
||||
Long total = repository.countAllContracts(latestId);
|
||||
updateTitle("用友U8系统-同步合同,从 " + latestId + " 开始,合计 " + total + " 条");
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("sync latest Id from {}, have {} record.", latestId, total);
|
||||
}
|
||||
|
||||
AtomicInteger counter = new AtomicInteger(0);
|
||||
AtomicReference<Integer> reference = new AtomicReference<>(latestId);
|
||||
try (Stream<Map<String, Object>> stream = repository.queryAllContractForStream(latestId)) {
|
||||
stream.forEach(rs -> {
|
||||
if (isCancelled()) {
|
||||
updateMessage("Cancelled");
|
||||
return;
|
||||
}
|
||||
MessageHolder subHolder = holder.sub(counter.get() + " / " + total + "> ");
|
||||
try {
|
||||
Integer ID = (Integer) rs.get("ID");
|
||||
repairFromCMList(rs, subHolder);
|
||||
if (ID != null) {
|
||||
Integer latest = reference.get();
|
||||
if (latest == null || ID.compareTo(latest) > 0) {
|
||||
reference.set(ID);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Contract sync failure {}, data = {}", e.getMessage(), rs, e);
|
||||
updateMessage(e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
updateProgress(counter.incrementAndGet(), total);
|
||||
});
|
||||
}
|
||||
getConfService().set(ContractCtx.KEY_SYNC_BY_LATEST_ID, String.valueOf(reference.get()));
|
||||
}
|
||||
|
||||
private void syncByLatestDate(MessageHolder holder) {
|
||||
String strDateTime = getConfService().getString(ContractCtx.KEY_SYNC_BY_LATEST_DATE);
|
||||
LocalDateTime latestDateTime = null;
|
||||
if (StringUtils.hasText(strDateTime)) {
|
||||
try {
|
||||
latestDateTime = LocalDateTime.parse(strDateTime);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
if (latestDateTime == null) {
|
||||
latestDateTime = LocalDateTime.of(2025, 1, 1, 0, 0, 0);
|
||||
}
|
||||
updateTitle("用友U8系统-同步合同,从 " + latestDateTime + " 开始");
|
||||
|
||||
Long total = repository.countAllContracts(latestDateTime);
|
||||
updateTitle("用友U8系统-同步合同,从 " + latestDateTime + " 开始,合计 " + total + " 条");
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("from latest date {}, have {} record.", latestDateTime, total);
|
||||
}
|
||||
|
||||
AtomicInteger counter = new AtomicInteger(0);
|
||||
AtomicReference<LocalDateTime> reference = new AtomicReference<>(latestDateTime);
|
||||
|
||||
try (Stream<Map<String, Object>> stream = repository.queryAllContractForStream(latestDateTime)) {
|
||||
stream.forEach(rs -> {
|
||||
if (isCancelled()) {
|
||||
updateMessage("Cancelled");
|
||||
return;
|
||||
}
|
||||
|
||||
MessageHolder subHolder = holder.sub(counter.get() + " / " + total + "> ");
|
||||
try {
|
||||
Timestamp dtDate = (Timestamp) rs.get("dtDate");
|
||||
|
||||
repairFromCMList(rs, subHolder);
|
||||
|
||||
if (dtDate != null) {
|
||||
LocalDateTime latest = reference.get();
|
||||
LocalDateTime localDate = dtDate.toLocalDateTime();
|
||||
if (latest == null || localDate.isAfter(latest)) {
|
||||
reference.set(localDate);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("Contract sync failure {}, data = {}", e.getMessage(), rs, e);
|
||||
updateMessage(e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
updateProgress(counter.incrementAndGet(), total);
|
||||
});
|
||||
}
|
||||
getConfService().set(ContractCtx.KEY_SYNC_BY_LATEST_DATE, String.valueOf(reference.get()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.ds.contract.model.ContractType;
|
||||
import com.ecep.contract.manager.ds.contract.service.ContractTypeService;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import com.ecep.contract.manager.ui.Tasker;
|
||||
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* 同步合同类型
|
||||
*/
|
||||
public class ContractTypeSyncTask extends Tasker<Object> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ContractTypeSyncTask.class);
|
||||
@Setter
|
||||
private ContractTypeService contractTypeService;
|
||||
|
||||
public ContractTypeSyncTask() {
|
||||
updateTitle("用友U8系统-同步合同类型信息");
|
||||
}
|
||||
|
||||
ContractTypeService getContractTypeService() {
|
||||
if (contractTypeService == null) {
|
||||
contractTypeService = SpringApp.getBean(ContractTypeService.class);
|
||||
}
|
||||
return contractTypeService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object execute(MessageHolder holder) throws Exception {
|
||||
YongYouU8Repository repository = null;
|
||||
try {
|
||||
repository = SpringApp.getBean(YongYouU8Repository.class);
|
||||
} catch (BeansException e) {
|
||||
logger.error("can't get bean of YongYouU8Service", e);
|
||||
holder.error("can't get bean of YongYouU8Service");
|
||||
return null;
|
||||
}
|
||||
|
||||
AtomicInteger counter = new AtomicInteger(0);
|
||||
logger.info("读取 U8 系统 CM_Type,CM_TypeClass 数据表...");
|
||||
List<Map<String, Object>> list = repository.queryAllContractType();
|
||||
int size = list.size();
|
||||
holder.debug("总共读取 CM_Type,CM_TypeClass 数据 " + size + " 条");
|
||||
|
||||
for (Map<String, Object> map : list) {
|
||||
if (isCancelled()) {
|
||||
holder.info("Cancelled");
|
||||
return null;
|
||||
}
|
||||
MessageHolder sub = holder.sub(counter.get() + "/" + size + ">" );
|
||||
sync(map, sub);
|
||||
// 更新进度
|
||||
updateProgress(counter.incrementAndGet(), size);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void sync(Map<String, Object> map, MessageHolder holder) {
|
||||
boolean modified = false;
|
||||
|
||||
String typeCode = (String) map.get("cTypeCode");
|
||||
String typeName = (String) map.get("cTypeName");
|
||||
String typeTitle = (String) map.get("cCharacter");
|
||||
String typeCatalog = (String) map.get("cClassName");
|
||||
String typeDirection = (String) map.get("cDirection");
|
||||
|
||||
ContractTypeService typeService = getContractTypeService();
|
||||
ContractType contractType = typeService.findByCode(typeCode);
|
||||
if (contractType == null) {
|
||||
contractType = new ContractType();
|
||||
holder.info("新建合同类型:" + typeCode);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!Objects.equals(contractType.getCode(), typeCode)) {
|
||||
contractType.setCode(typeCode);
|
||||
holder.info("合同类型代码:" + contractType.getCode() + " -> " + typeCode);
|
||||
modified = true;
|
||||
}
|
||||
if (!Objects.equals(contractType.getName(), typeName)) {
|
||||
contractType.setName(typeName);
|
||||
holder.info("合同类型名称:" + contractType.getName() + " -> " + typeName);
|
||||
modified = true;
|
||||
}
|
||||
if (!Objects.equals(contractType.getTitle(), typeTitle)) {
|
||||
contractType.setTitle(typeTitle);
|
||||
holder.info("合同类型标题:" + contractType.getTitle() + " -> " + typeTitle);
|
||||
modified = true;
|
||||
}
|
||||
if (!Objects.equals(contractType.getCatalog(), typeCatalog)) {
|
||||
contractType.setCatalog(typeCatalog);
|
||||
holder.info("合同类型分类:" + contractType.getCatalog() + " -> " + typeCatalog);
|
||||
modified = true;
|
||||
}
|
||||
if (!Objects.equals(contractType.getDirection(), typeDirection)) {
|
||||
contractType.setDirection(typeDirection);
|
||||
holder.info("合同类型方向:" + contractType.getDirection() + " -> " + typeDirection);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (modified) {
|
||||
typeService.save(contractType);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.ds.customer.model.CustomerCatalog;
|
||||
import com.ecep.contract.manager.ds.customer.service.CompanyCustomerService;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import com.ecep.contract.manager.ui.Tasker;
|
||||
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* 同步客户分类
|
||||
*/
|
||||
public class CustomerClassSyncTask extends Tasker<Object> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CustomerClassSyncTask.class);
|
||||
@Setter
|
||||
private CompanyCustomerService companyCustomerService;
|
||||
|
||||
public CustomerClassSyncTask() {
|
||||
updateTitle("用友U8系统-同步客户分类信息");
|
||||
}
|
||||
|
||||
CompanyCustomerService getCompanyCustomerService() {
|
||||
if (companyCustomerService == null) {
|
||||
companyCustomerService = SpringApp.getBean(CompanyCustomerService.class);
|
||||
}
|
||||
return companyCustomerService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object execute(MessageHolder holder) throws Exception {
|
||||
YongYouU8Repository repository = null;
|
||||
try {
|
||||
repository = SpringApp.getBean(YongYouU8Repository.class);
|
||||
} catch (BeansException e) {
|
||||
logger.error("can't get bean of YongYouU8Repository", e);
|
||||
holder.error("can't get bean of YongYouU8Repository");
|
||||
return null;
|
||||
}
|
||||
|
||||
AtomicInteger counter = new AtomicInteger(0);
|
||||
logger.info("读取 U8 系统 CustomerClass 数据表...");
|
||||
List<Map<String, Object>> list = repository.queryAllCustomerClass();
|
||||
int size = list.size();
|
||||
holder.debug("总共读取 CustomerClass 数据 " + size + " 条");
|
||||
|
||||
for (Map<String, Object> map : list) {
|
||||
if (isCancelled()) {
|
||||
holder.info("Cancelled");
|
||||
return null;
|
||||
}
|
||||
MessageHolder sub = holder.sub(counter.get() + "/" + size + ">" );
|
||||
sync(map, sub);
|
||||
// 更新进度
|
||||
updateProgress(counter.incrementAndGet(), size);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void sync(Map<String, Object> map, MessageHolder holder) {
|
||||
boolean modified = false;
|
||||
|
||||
String code = (String) map.get("cCCCode");
|
||||
String name = (String) map.get("cCCName");
|
||||
|
||||
CompanyCustomerService customerService = getCompanyCustomerService();
|
||||
CustomerCatalog customerCatalog = customerService.findCatalogByCode(code);
|
||||
if (customerCatalog == null) {
|
||||
customerCatalog = new CustomerCatalog();
|
||||
holder.info("新建客户分类:" + code);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!Objects.equals(customerCatalog.getCode(), code)) {
|
||||
customerCatalog.setCode(code);
|
||||
holder.info("客户分类代码:" + customerCatalog.getCode() + " -> " + code);
|
||||
modified = true;
|
||||
}
|
||||
if (!Objects.equals(customerCatalog.getName(), name)) {
|
||||
customerCatalog.setName(name);
|
||||
holder.info("客户分类名称:" + customerCatalog.getName() + " -> " + name);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (modified) {
|
||||
customerService.save(customerCatalog);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,144 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8;
|
||||
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.cloud.u8.ctx.CompanyCtx;
|
||||
import com.ecep.contract.manager.cloud.u8.ctx.CustomerCtx;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.manager.ds.contract.tasker.AbstContractRepairTasker;
|
||||
import com.ecep.contract.manager.ds.customer.model.CompanyCustomer;
|
||||
import com.ecep.contract.manager.ds.customer.model.CompanyCustomerEntity;
|
||||
import com.ecep.contract.manager.ds.customer.service.CompanyCustomerService;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* 同步客户任务
|
||||
*/
|
||||
public class CustomerSyncTask extends AbstContractRepairTasker {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CustomerSyncTask.class);
|
||||
private YongYouU8Repository repository;
|
||||
private final CustomerCtx customerCtx = new CustomerCtx();
|
||||
@Setter
|
||||
private YongYouU8Service yongYouU8Service;
|
||||
|
||||
public CustomerSyncTask() {
|
||||
updateTitle("用友U8系统-同步客户");
|
||||
}
|
||||
|
||||
|
||||
private CompanyCustomerService getCompanyCustomerService() {
|
||||
return customerCtx.getCompanyCustomerService();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void repair(MessageHolder holder) {
|
||||
try {
|
||||
yongYouU8Service = getBean(YongYouU8Service.class);
|
||||
} catch (BeansException e) {
|
||||
holder.warn("未启用 " + YongYouU8Service.NAME + " 服务");
|
||||
return;
|
||||
}
|
||||
repository = SpringApp.getBean(YongYouU8Repository.class);
|
||||
yongYouU8Service.initialize(customerCtx);
|
||||
|
||||
AtomicInteger counter = new AtomicInteger(0);
|
||||
Long total = repository.countAllCustomers();
|
||||
updateTitle("用友U8系统-同步客户,合计 " + total + " 条");
|
||||
try (Stream<Map<String, Object>> stream = repository.queryAllCustomerForStream()) {
|
||||
stream.forEach(rs -> {
|
||||
if (isCancelled()) {
|
||||
updateMessage("Cancelled");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String cusCode = (String) rs.get("cCusCode");
|
||||
MessageHolder subHolder = holder.sub(counter.get() + " / " + total + "> " + cusCode + " ");
|
||||
boolean modified = false;
|
||||
CompanyCustomerEntity entity = customerCtx.findOrCreateByCode(rs, cusCode, subHolder);
|
||||
Map<String, Object> map = repository.findCustomerByCusCode(entity.getCode());
|
||||
if (map == null) {
|
||||
subHolder.error("客户项不存在:" + cusCode);
|
||||
return;
|
||||
}
|
||||
if (customerCtx.applyEntityDetail(entity, map, subHolder)) {
|
||||
modified = true;
|
||||
}
|
||||
if (modified) {
|
||||
entity = customerCtx.getCompanyCustomerEntityService().save(entity);
|
||||
}
|
||||
updateCompanyNameAndAbbName(entity, subHolder);
|
||||
updateCloudYu(entity);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Customer sync failure {}, data = {}", e.getMessage(), rs, e);
|
||||
updateMessage(e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
updateProgress(counter.incrementAndGet(), total);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCloudYu(CompanyCustomerEntity entity) {
|
||||
CompanyCustomer customer = entity.getCustomer();
|
||||
if (customer == null) {
|
||||
return;
|
||||
}
|
||||
if (!Hibernate.isInitialized(customer)) {
|
||||
customer = getCompanyCustomerService().findById(customer.getId());
|
||||
}
|
||||
Company company = customer.getCompany();
|
||||
if (company == null) {
|
||||
return;
|
||||
}
|
||||
CloudYu cloudYu = yongYouU8Service.getOrCreateCloudYu(company);
|
||||
if (cloudYu == null) {
|
||||
return;
|
||||
}
|
||||
cloudYu.setCustomerUpdateDate(LocalDate.now());
|
||||
cloudYu.setCloudLatest(Instant.now());
|
||||
cloudYu.setExceptionMessage("");
|
||||
yongYouU8Service.save(cloudYu);
|
||||
|
||||
}
|
||||
|
||||
private void updateCompanyNameAndAbbName(CompanyCustomerEntity entity, MessageHolder holder) {
|
||||
CompanyService companyService = customerCtx.getCompanyService();
|
||||
CompanyCustomer customer = entity.getCustomer();
|
||||
if (customer == null) {
|
||||
return;
|
||||
}
|
||||
if (!Hibernate.isInitialized(customer)) {
|
||||
customer = getCompanyCustomerService().findById(customer.getId());
|
||||
}
|
||||
Company company = customer.getCompany();
|
||||
if (company == null) {
|
||||
return;
|
||||
}
|
||||
if (!Hibernate.isInitialized(company)) {
|
||||
company = companyService.findById(company.getId());
|
||||
}
|
||||
boolean modified = false;
|
||||
CompanyCtx companyCtx = customerCtx.getCompanyCtx();
|
||||
if (companyCtx.updateCompanyNameIfAbsent(company, entity.getName(), holder)) {
|
||||
modified = true;
|
||||
}
|
||||
if (companyCtx.updateCompanyAbbNameIfAbsent(company, entity.getAbbName(), holder)) {
|
||||
modified = true;
|
||||
}
|
||||
if (modified) {
|
||||
companyService.save(company);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.cloud.CloudBaseInfo;
|
||||
import com.ecep.contract.manager.cloud.CloudInfo;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import com.ecep.contract.manager.ui.Tasker;
|
||||
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* 数据迁移任务,从CloudInfo迁移到CloudYu
|
||||
*/
|
||||
public class DateTransferTask extends Tasker<Object> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DateTransferTask.class);
|
||||
@Setter
|
||||
private YongYouU8Service yongYouU8Service;
|
||||
|
||||
public DateTransferTask() {
|
||||
updateTitle("用友U8系统-数据迁移任务");
|
||||
}
|
||||
|
||||
YongYouU8Service getYongYouU8Service() {
|
||||
if (yongYouU8Service == null) {
|
||||
yongYouU8Service = SpringApp.getBean(YongYouU8Service.class);
|
||||
}
|
||||
return yongYouU8Service;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object execute(MessageHolder holder) throws Exception {
|
||||
YongYouU8Service u8Service = null;
|
||||
try {
|
||||
u8Service = getYongYouU8Service();
|
||||
} catch (BeansException e) {
|
||||
logger.error("获取用友U8服务失败", e);
|
||||
holder.error("获取用友U8服务失败");
|
||||
return null;
|
||||
}
|
||||
|
||||
AtomicInteger counter = new AtomicInteger(0);
|
||||
logger.info("开始数据迁移任务...");
|
||||
Iterable<CloudInfo> cloudInfos = u8Service.findAllCloudYu();
|
||||
|
||||
// 计算总数
|
||||
int total = 0;
|
||||
for (@SuppressWarnings("unused")
|
||||
CloudInfo info : cloudInfos) {
|
||||
total++;
|
||||
}
|
||||
holder.debug("总共需要迁移的数据量: " + total + " 条");
|
||||
|
||||
// 重新获取Iterable以进行遍历
|
||||
cloudInfos = u8Service.findAllCloudYu();
|
||||
|
||||
for (CloudInfo v : cloudInfos) {
|
||||
if (isCancelled()) {
|
||||
holder.info("迁移任务已取消");
|
||||
return null;
|
||||
}
|
||||
|
||||
MessageHolder sub = holder.sub(counter.get() + "/" + total + ">");
|
||||
try {
|
||||
sync(v, sub);
|
||||
} catch (Exception e) {
|
||||
sub.error("迁移失败: " + e.getMessage());
|
||||
logger.error("迁移数据失败", e);
|
||||
}
|
||||
|
||||
// 更新进度
|
||||
updateProgress(counter.incrementAndGet(), total);
|
||||
}
|
||||
|
||||
holder.info("数据迁移任务完成");
|
||||
return null;
|
||||
}
|
||||
|
||||
private void sync(CloudInfo v, MessageHolder holder) {
|
||||
YongYouU8Service u8Service = getYongYouU8Service();
|
||||
CloudYu cloudYu = u8Service.getOrCreateCloudYu(v);
|
||||
|
||||
if (copyTo(v, cloudYu)) {
|
||||
u8Service.save(cloudYu);
|
||||
holder.info("成功迁移数据: " + v.getCloudId());
|
||||
} else {
|
||||
holder.debug("数据未变更,无需迁移: " + v.getCloudId());
|
||||
}
|
||||
}
|
||||
|
||||
boolean copyTo(CloudInfo v, CloudBaseInfo cloudRk) {
|
||||
boolean modified = false;
|
||||
if (!Objects.equals(cloudRk.getLatestUpdate(), v.getLatestUpdate())) {
|
||||
cloudRk.setLatestUpdate(v.getLatestUpdate());
|
||||
modified = true;
|
||||
}
|
||||
if (!Objects.equals(cloudRk.getCloudId(), v.getCloudId())) {
|
||||
cloudRk.setCloudId(v.getCloudId());
|
||||
modified = true;
|
||||
}
|
||||
if (!Objects.equals(cloudRk.getCompany(), v.getCompany())) {
|
||||
cloudRk.setCompany(v.getCompany());
|
||||
modified = true;
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8;
|
||||
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.ds.other.model.Department;
|
||||
import com.ecep.contract.manager.ds.other.model.Employee;
|
||||
import com.ecep.contract.manager.ds.other.service.DepartmentService;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import com.ecep.contract.manager.ui.Tasker;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* 用友U8系统-同步员工信息
|
||||
*/
|
||||
public class EmployeesSyncTask extends Tasker<Object> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(EmployeesSyncTask.class);
|
||||
private final AtomicInteger counter = new AtomicInteger(0);
|
||||
|
||||
DepartmentService departmentService;
|
||||
|
||||
public EmployeesSyncTask() {
|
||||
updateTitle("用友U8系统-同步员工信息");
|
||||
}
|
||||
|
||||
DepartmentService getDepartmentService() {
|
||||
if (departmentService == null) {
|
||||
departmentService = SpringApp.getBean(DepartmentService.class);
|
||||
}
|
||||
return departmentService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object execute(MessageHolder holder) throws Exception {
|
||||
YongYouU8Service service = SpringApp.getBean(YongYouU8Service.class);
|
||||
|
||||
holder.debug("读取 U8 系统 Person 数据表...");
|
||||
List<Map<String, Object>> list = service.queryAllPerson();
|
||||
int size = list.size();
|
||||
holder.debug("总共读取 Person 数据 " + size + " 条");
|
||||
|
||||
for (Map<String, Object> rs : list) {
|
||||
if (isCancelled()) {
|
||||
holder.debug("Cancelled");
|
||||
return null;
|
||||
}
|
||||
|
||||
MessageHolder sub = holder.sub(counter.get() + "/" + size + ">");
|
||||
sync(rs, sub);
|
||||
|
||||
// 更新进度
|
||||
updateProgress(counter.incrementAndGet(), size);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void sync(Map<String, Object> rs, MessageHolder holder) {
|
||||
String personCode = (String) rs.get("cPersonCode");
|
||||
String personName = (String) rs.get("cPersonName");
|
||||
String departmentCode = (String) rs.get("cDepCode");
|
||||
String personEmail = (String) rs.get("cPersonEmail");
|
||||
String personPhone = (String) rs.get("cPersonPhone");
|
||||
java.sql.Timestamp personValidDate = (java.sql.Timestamp) rs.get("dPValidDate");
|
||||
java.sql.Timestamp personInValidDate = (java.sql.Timestamp) rs.get("dPInValidDate");
|
||||
boolean modified = false;
|
||||
|
||||
|
||||
Employee employee = getEmployeeService().findByCode(personCode);
|
||||
// 按员工代码未匹配时,尝试使用名字去匹配
|
||||
if (employee == null) {
|
||||
employee = getEmployeeService().findByName(personName);
|
||||
if (employee == null) {
|
||||
employee = new Employee();
|
||||
employee.setCode(personCode);
|
||||
employee.setName(personName);
|
||||
employee.setActive(false);
|
||||
employee.setCreated(LocalDate.now());
|
||||
holder.info("创建员工:" + personCode + ", 姓名:" + personName + ".");
|
||||
|
||||
// consumer.accept("员工编号:" + personCode + ", 姓名:" + personName + ", 本地未创建");
|
||||
// return;
|
||||
}
|
||||
employee.setCode(personCode);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
MessageHolder subHolder = holder.sub(personName + ": ");
|
||||
|
||||
|
||||
if (!StringUtils.hasText(employee.getName())) {
|
||||
employee.setName(personName);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(departmentCode)) {
|
||||
Department departmentByCode = getDepartmentService().findByCode(departmentCode);
|
||||
if (departmentByCode == null) {
|
||||
subHolder.warn("部门代码:" + departmentCode + "未匹配到部门");
|
||||
} else {
|
||||
if (!Objects.equals(employee.getDepartment(), departmentByCode)) {
|
||||
employee.setDepartment(departmentByCode);
|
||||
subHolder.info("更新部门:" + departmentByCode.getName());
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(personPhone)) {
|
||||
if (!Objects.equals(personPhone, employee.getPhone())) {
|
||||
employee.setPhone(personPhone);
|
||||
subHolder.info("更新电话:" + personPhone);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(personEmail)) {
|
||||
if (!Objects.equals(personEmail, employee.getEmail())) {
|
||||
employee.setEmail(personEmail);
|
||||
subHolder.info("更新Email:" + personEmail);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (personValidDate != null) {
|
||||
LocalDate localDate = personValidDate.toLocalDateTime().toLocalDate();
|
||||
if (!Objects.equals(localDate, employee.getEntryDate())) {
|
||||
employee.setEntryDate(localDate);
|
||||
subHolder.info("更新入职日期:" + localDate);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (personInValidDate != null) {
|
||||
LocalDate localDate = personInValidDate.toLocalDateTime().toLocalDate();
|
||||
if (!Objects.equals(localDate, employee.getLeaveDate())) {
|
||||
employee.setLeaveDate(localDate);
|
||||
subHolder.info("更新离职日期:" + localDate);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (modified) {
|
||||
getEmployeeService().save(employee);
|
||||
subHolder.info("更新保存");
|
||||
} else {
|
||||
subHolder.debug("无更新");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8;
|
||||
|
||||
|
||||
import com.ecep.contract.manager.ds.other.service.SysConfService;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@Lazy
|
||||
@Component
|
||||
@ConditionalOnBean(YongYouU8Service.class)
|
||||
public class U8DataSourceFactory {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private SysConfService service;
|
||||
|
||||
public U8DataSourceFactory() {
|
||||
System.out.println("U8DataSourceFactory.U8DataSourceFactory");
|
||||
}
|
||||
|
||||
@Lazy
|
||||
@Bean
|
||||
// @ConfigurationProperties(prefix = "u8.datasource")
|
||||
public DataSource MSSQL_Server() {
|
||||
System.out.println("U8DataSourceFactory.MSSQL_Server");
|
||||
|
||||
String host = service.get("u8.db.server.ip", "192.168.1.1");
|
||||
String database = service.get("u8.db.database", "UF_DATA");
|
||||
String username = service.get("u8.db.server.name", "sa");
|
||||
String password = service.get("u8.db.server.password", "");
|
||||
boolean encrypt = service.get("u8.db.server.encrypt", false);
|
||||
boolean trustServerCertificate = service.get("u8.db.server.trustServerCertificate", true);
|
||||
|
||||
String url = "jdbc:sqlserver://" +
|
||||
host +
|
||||
";databaseName=" +
|
||||
database +
|
||||
";encrypt=" +
|
||||
encrypt +
|
||||
";trustServerCertificate=" +
|
||||
trustServerCertificate
|
||||
// + ";sslProtocol=TLSv1"
|
||||
;
|
||||
|
||||
HikariDataSource source = DataSourceBuilder.create()
|
||||
.type(HikariDataSource.class)
|
||||
.url(url)
|
||||
.username(username)
|
||||
.password(password)
|
||||
.driverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver")
|
||||
.build();
|
||||
source.setMinimumIdle(0);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.ds.vendor.model.VendorCatalog;
|
||||
import com.ecep.contract.manager.ds.vendor.repository.VendorClassRepository;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import com.ecep.contract.manager.ui.Tasker;
|
||||
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* 同步供应商分类
|
||||
*/
|
||||
public class VendorClassSyncTask extends Tasker<Object> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(VendorClassSyncTask.class);
|
||||
@Setter
|
||||
private VendorClassRepository vendorClassRepository;
|
||||
|
||||
public VendorClassSyncTask() {
|
||||
updateTitle("用友U8系统-同步供应商分类信息");
|
||||
}
|
||||
|
||||
VendorClassRepository getVendorClassRepository() {
|
||||
if (vendorClassRepository == null) {
|
||||
vendorClassRepository = SpringApp.getBean(VendorClassRepository.class);
|
||||
}
|
||||
return vendorClassRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object execute(MessageHolder holder) throws Exception {
|
||||
YongYouU8Service service = null;
|
||||
try {
|
||||
service = SpringApp.getBean(YongYouU8Service.class);
|
||||
} catch (BeansException e) {
|
||||
logger.error("can't get bean of YongYouU8Service", e);
|
||||
holder.error("can't get bean of YongYouU8Service");
|
||||
return null;
|
||||
}
|
||||
|
||||
AtomicInteger counter = new AtomicInteger(0);
|
||||
logger.info("读取 U8 系统 VendorClass 数据表...");
|
||||
List<Map<String, Object>> list = service.queryAllVendorClass();
|
||||
int size = list.size();
|
||||
holder.debug("总共读取 VendorClass 数据 " + size + " 条");
|
||||
|
||||
for (Map<String, Object> map : list) {
|
||||
if (isCancelled()) {
|
||||
holder.info("Cancelled");
|
||||
return null;
|
||||
}
|
||||
MessageHolder sub = holder.sub(counter.get() + "/" + size + ">" );
|
||||
sync(map, sub);
|
||||
// 更新进度
|
||||
updateProgress(counter.incrementAndGet(), size);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void sync(Map<String, Object> map, MessageHolder holder) {
|
||||
boolean modified = false;
|
||||
|
||||
String code = (String) map.get("cVCCode");
|
||||
String name = (String) map.get("cVCName");
|
||||
|
||||
VendorClassRepository repository = getVendorClassRepository();
|
||||
VendorCatalog vendorCatalog = repository.findByCode(code).orElse(null);
|
||||
if (vendorCatalog == null) {
|
||||
vendorCatalog = new VendorCatalog();
|
||||
holder.info("新建供应商分类:" + code);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!Objects.equals(vendorCatalog.getCode(), code)) {
|
||||
vendorCatalog.setCode(code);
|
||||
holder.info("供应商分类代码:" + vendorCatalog.getCode() + " -> " + code);
|
||||
modified = true;
|
||||
}
|
||||
if (!Objects.equals(vendorCatalog.getName(), name)) {
|
||||
vendorCatalog.setName(name);
|
||||
holder.info("供应商分类名称:" + vendorCatalog.getName() + " -> " + name);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (modified) {
|
||||
repository.save(vendorCatalog);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,157 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8;
|
||||
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.cloud.u8.ctx.CompanyCtx;
|
||||
import com.ecep.contract.manager.cloud.u8.ctx.VendorCtx;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.manager.ds.contract.tasker.AbstContractRepairTasker;
|
||||
import com.ecep.contract.manager.ds.vendor.model.CompanyVendor;
|
||||
import com.ecep.contract.manager.ds.vendor.model.CompanyVendorEntity;
|
||||
import com.ecep.contract.manager.ds.vendor.service.CompanyVendorEntityService;
|
||||
import com.ecep.contract.manager.ds.vendor.service.CompanyVendorService;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* 供应商同步任务
|
||||
*/
|
||||
public class VendorSyncTask extends AbstContractRepairTasker {
|
||||
private static final Logger logger = LoggerFactory.getLogger(VendorSyncTask.class);
|
||||
private final VendorCtx vendorCtx = new VendorCtx();
|
||||
private CompanyVendorService companyVendorService;
|
||||
private CompanyVendorEntityService vendorEntityService;
|
||||
private YongYouU8Repository repository;
|
||||
@Setter
|
||||
private YongYouU8Service yongYouU8Service;
|
||||
|
||||
public VendorSyncTask() {
|
||||
updateTitle("用友U8系统-同步供应商");
|
||||
}
|
||||
|
||||
private CompanyVendorService getCompanyVendorService() {
|
||||
if (companyVendorService == null) {
|
||||
companyVendorService = SpringApp.getBean(CompanyVendorService.class);
|
||||
}
|
||||
return companyVendorService;
|
||||
}
|
||||
|
||||
private CompanyVendorEntityService getVendorEntityService() {
|
||||
if (vendorEntityService == null) {
|
||||
vendorEntityService = SpringApp.getBean(CompanyVendorEntityService.class);
|
||||
}
|
||||
return vendorEntityService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void repair(MessageHolder holder) {
|
||||
try {
|
||||
yongYouU8Service = getBean(YongYouU8Service.class);
|
||||
} catch (BeansException e) {
|
||||
holder.warn("未启用 " + YongYouU8Service.NAME + " 服务");
|
||||
return;
|
||||
}
|
||||
repository = SpringApp.getBean(YongYouU8Repository.class);
|
||||
yongYouU8Service.initialize(vendorCtx);
|
||||
|
||||
AtomicInteger counter = new AtomicInteger(0);
|
||||
Long total = repository.countAllVendors();
|
||||
updateTitle("用友U8系统-同步供应商,合计 " + total + " 条");
|
||||
|
||||
try (Stream<Map<String, Object>> stream = repository.queryAllVendorForStream()) {
|
||||
stream.forEach(rs -> {
|
||||
if (isCancelled()) {
|
||||
updateMessage("Cancelled");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String venCode = (String) rs.get("cVenCode");
|
||||
MessageHolder subHolder = holder.sub(counter.get() + " / " + total + "> " + venCode + " ");
|
||||
boolean modified = false;
|
||||
CompanyVendorEntity entity = vendorCtx.findOrCreateByCode(venCode, subHolder);
|
||||
Map<String, Object> map = repository.findVendorByVendCode(entity.getCode());
|
||||
if (map == null) {
|
||||
subHolder.error("供应商项不存在:" + venCode);
|
||||
return;
|
||||
}
|
||||
if (vendorCtx.applyEntityDetail(entity, map, subHolder)) {
|
||||
modified = true;
|
||||
}
|
||||
if (modified) {
|
||||
entity = getVendorEntityService().save(entity);
|
||||
}
|
||||
updateCompanyNameAndAbbName(entity, subHolder);
|
||||
updateCloudYu(entity);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Vendor sync failure {}, data = {}", e.getMessage(), rs, e);
|
||||
updateMessage(e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
updateProgress(counter.incrementAndGet(), total);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCloudYu(CompanyVendorEntity entity) {
|
||||
CompanyVendor vendor = entity.getVendor();
|
||||
if (vendor == null) {
|
||||
return;
|
||||
}
|
||||
if (!Hibernate.isInitialized(vendor)) {
|
||||
vendor = getCompanyVendorService().findById(vendor.getId());
|
||||
}
|
||||
Company company = vendor.getCompany();
|
||||
if (company == null) {
|
||||
return;
|
||||
}
|
||||
CloudYu cloudYu = yongYouU8Service.getOrCreateCloudYu(company);
|
||||
if (cloudYu == null) {
|
||||
return;
|
||||
}
|
||||
cloudYu.setVendorUpdateDate(LocalDate.now());
|
||||
cloudYu.setCloudLatest(Instant.now());
|
||||
cloudYu.setExceptionMessage("");
|
||||
yongYouU8Service.save(cloudYu);
|
||||
}
|
||||
|
||||
private void updateCompanyNameAndAbbName(CompanyVendorEntity entity, MessageHolder holder) {
|
||||
CompanyService companyService = vendorCtx.getCompanyService();
|
||||
CompanyVendor vendor = entity.getVendor();
|
||||
if (vendor == null) {
|
||||
return;
|
||||
}
|
||||
if (!Hibernate.isInitialized(vendor)) {
|
||||
vendor = getCompanyVendorService().findById(vendor.getId());
|
||||
}
|
||||
Company company = vendor.getCompany();
|
||||
if (company == null) {
|
||||
return;
|
||||
}
|
||||
if (!Hibernate.isInitialized(company)) {
|
||||
company = companyService.findById(company.getId());
|
||||
}
|
||||
boolean modified = false;
|
||||
CompanyCtx companyCtx = vendorCtx.getCompanyCtx();
|
||||
if (companyCtx.updateCompanyNameIfAbsent(company, entity.getName(), holder)) {
|
||||
modified = true;
|
||||
}
|
||||
if (companyCtx.updateCompanyAbbNameIfAbsent(company, entity.getAbbName(), holder)) {
|
||||
modified = true;
|
||||
}
|
||||
if (modified) {
|
||||
companyService.save(company);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8;
|
||||
|
||||
import org.controlsfx.control.ToggleSwitch;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.ecep.contract.manager.cloud.u8.ctx.CompanyCtx;
|
||||
import com.ecep.contract.manager.cloud.u8.ctx.ContractCtx;
|
||||
import com.ecep.contract.manager.ds.other.BooleanConfig;
|
||||
import com.ecep.contract.manager.ds.other.LocalDateConfig;
|
||||
import com.ecep.contract.manager.ds.other.LocalDateTimeConfig;
|
||||
import com.ecep.contract.manager.ds.other.StringConfig;
|
||||
import com.ecep.contract.manager.ui.BaseController;
|
||||
import com.ecep.contract.manager.ui.FxmlPath;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.DatePicker;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.stage.WindowEvent;
|
||||
|
||||
@Lazy
|
||||
@Scope("prototype")
|
||||
@Component
|
||||
@FxmlPath("/ui/cloud/u8_config.fxml")
|
||||
public class YongYouU8ConfigWindowController extends BaseController {
|
||||
@FXML
|
||||
private DatePicker auto_create_company_after;
|
||||
|
||||
@FXML
|
||||
private TextField contract_latest_date;
|
||||
|
||||
@FXML
|
||||
private TextField contract_latest_id;
|
||||
|
||||
@FXML
|
||||
private TextField sync_elapse;
|
||||
@FXML
|
||||
private ToggleSwitch use_latest_id;
|
||||
|
||||
LocalDateConfig config1 = new LocalDateConfig(CompanyCtx.AUTO_CREATE_COMPANY_AFTER);
|
||||
LocalDateTimeConfig config2 = new LocalDateTimeConfig(ContractCtx.KEY_SYNC_BY_LATEST_DATE);
|
||||
StringConfig config3 = new StringConfig(ContractCtx.KEY_SYNC_BY_LATEST_ID);
|
||||
StringConfig config4 = new StringConfig(ContractCtx.KEY_SYNC_ELAPSE);
|
||||
BooleanConfig config5 = new BooleanConfig(ContractCtx.KEY_SYNC_USE_LATEST_ID);
|
||||
|
||||
@Override
|
||||
public void onShown(WindowEvent windowEvent) {
|
||||
super.onShown(windowEvent);
|
||||
getTitle().set("用友U8配置");
|
||||
|
||||
auto_create_company_after.setConverter(getCurrentEmployee().getLocalDateStringConverter());
|
||||
config1.setControl(auto_create_company_after);
|
||||
config1.initialize();
|
||||
|
||||
config2.setControl(contract_latest_date);
|
||||
config2.setControlConverter(getCurrentEmployee().getLocalDateTimeStringConverter());
|
||||
config2.initialize();
|
||||
|
||||
config3.setControl(contract_latest_id);
|
||||
config3.initialize();
|
||||
|
||||
config4.setControl(sync_elapse);
|
||||
config4.initialize();
|
||||
|
||||
config5.setControl(use_latest_id);
|
||||
config5.initialize();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,135 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8;
|
||||
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.ui.table.cell.CompanyTableCell;
|
||||
import com.ecep.contract.manager.ds.company.controller.CompanyWindowController;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.manager.ui.AbstEntityManagerSkin;
|
||||
import com.ecep.contract.manager.ui.ManagerSkin;
|
||||
import com.ecep.contract.manager.ui.table.cell.LocalDateTimeTableCell;
|
||||
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;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.ecep.contract.manager.Desktop;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ui.AbstManagerWindowController;
|
||||
import com.ecep.contract.manager.ui.BaseController;
|
||||
import com.ecep.contract.manager.ui.FxmlPath;
|
||||
import com.ecep.contract.manager.util.UITools;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
@Lazy
|
||||
@Scope("prototype")
|
||||
@Component
|
||||
@FxmlPath("/ui/cloud/u8_manager.fxml")
|
||||
public class YongYouU8ManagerWindowController
|
||||
extends AbstManagerWindowController<CloudYu, CloudYuInfoViewModel, YongYouU8ManagerSkin> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(YongYouU8ManagerWindowController.class);
|
||||
|
||||
public static void show() {
|
||||
show(YongYouU8ManagerWindowController.class, null);
|
||||
}
|
||||
|
||||
public TableColumn<CloudYuInfoViewModel, Number> idColumn;
|
||||
public TableColumn<CloudYuInfoViewModel, LocalDateTime> latestUpdateColumn;
|
||||
public TableColumn<CloudYuInfoViewModel, Company> companyColumn;
|
||||
public TableColumn<CloudYuInfoViewModel, String> cloudIdColumn;
|
||||
public TableColumn<CloudYuInfoViewModel, LocalDateTime> cloudLatestColumn;
|
||||
public TableColumn<CloudYuInfoViewModel, String> descriptionColumn;
|
||||
|
||||
@Override
|
||||
public YongYouU8Service getViewModelService() {
|
||||
return getSkin().getU8Service();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected YongYouU8ManagerSkin createDefaultSkin() {
|
||||
return new YongYouU8ManagerSkin(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show(Stage stage) {
|
||||
super.show(stage);
|
||||
getTitle().set("用友U8");
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开配置窗口
|
||||
*/
|
||||
public void onConfigAction(ActionEvent event) {
|
||||
BaseController.show(YongYouU8ConfigWindowController.class, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据迁移,从 CloudInfo 迁移到 CloudRk
|
||||
*/
|
||||
public void onDateTransferAction(ActionEvent event) {
|
||||
DateTransferTask task = new DateTransferTask();
|
||||
Desktop.instance.getTaskMonitorCenter().registerAndStartTask(task);
|
||||
}
|
||||
|
||||
public void onPersonSyncAction(ActionEvent event) {
|
||||
EmployeesSyncTask task = new EmployeesSyncTask();
|
||||
UITools.showTaskDialogAndWait("员工数据同步", task, null);
|
||||
}
|
||||
|
||||
public void onContractSyncAction(ActionEvent event) {
|
||||
ContractSyncTask task = new ContractSyncTask();
|
||||
UITools.showTaskDialogAndWait("合同数据增量同步", task, null);
|
||||
}
|
||||
|
||||
public void onContractAllSyncAction(ActionEvent event) {
|
||||
ContractSyncAllTask task = new ContractSyncAllTask();
|
||||
UITools.showTaskDialogAndWait("合同数据全量同步", task, null);
|
||||
}
|
||||
|
||||
public void onVendorSyncAction(ActionEvent event) {
|
||||
VendorSyncTask task = new VendorSyncTask();
|
||||
UITools.showTaskDialogAndWait("供应商数据同步", task, null);
|
||||
}
|
||||
|
||||
public void onCustomerSyncAction(ActionEvent event) {
|
||||
CustomerSyncTask task = new CustomerSyncTask();
|
||||
UITools.showTaskDialogAndWait("客户数据同步", task, null);
|
||||
}
|
||||
|
||||
public void onContractGroupSyncAction(ActionEvent event) {
|
||||
ContractGroupSyncTask task = new ContractGroupSyncTask();
|
||||
Desktop.instance.getTaskMonitorCenter().registerAndStartTask(task);
|
||||
}
|
||||
|
||||
public void onContractTypeSyncAction(ActionEvent event) {
|
||||
ContractTypeSyncTask task = new ContractTypeSyncTask();
|
||||
Desktop.instance.getTaskMonitorCenter().registerAndStartTask(task);
|
||||
}
|
||||
|
||||
public void onContractKindSyncAction(ActionEvent event) {
|
||||
ContractKindSyncTask task = new ContractKindSyncTask();
|
||||
Desktop.instance.getTaskMonitorCenter().registerAndStartTask(task);
|
||||
}
|
||||
|
||||
public void onVendorClassSyncAction(ActionEvent event) {
|
||||
VendorClassSyncTask task = new VendorClassSyncTask();
|
||||
Desktop.instance.getTaskMonitorCenter().registerAndStartTask(task);
|
||||
}
|
||||
|
||||
public void onCustomerClassSyncAction(ActionEvent event) {
|
||||
CustomerClassSyncTask task = new CustomerClassSyncTask();
|
||||
Desktop.instance.getTaskMonitorCenter().registerAndStartTask(task);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,377 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8;
|
||||
|
||||
import com.ecep.contract.manager.ds.contract.ContractPayWay;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.jdbc.core.ColumnMapRowMapper;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Lazy
|
||||
@Repository
|
||||
@ConditionalOnBean(YongYouU8Service.class)
|
||||
public class YongYouU8Repository {
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
@Lazy
|
||||
@Autowired
|
||||
@Qualifier("MSSQL_Server")
|
||||
private DataSource dataSource;
|
||||
|
||||
private JdbcTemplate getJdbcTemplate() {
|
||||
if (jdbcTemplate == null) {
|
||||
jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
return jdbcTemplate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 返回 U8 系统中 供应商总数
|
||||
*
|
||||
* @return 供应商总数
|
||||
*/
|
||||
public Long countAllVendors() {
|
||||
return getJdbcTemplate().queryForObject("select count(*) from Vendor", Long.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 以流式返回所有供应商数据
|
||||
*
|
||||
* @return Stream 数据流
|
||||
*/
|
||||
public Stream<Map<String, Object>> queryAllVendorForStream() {
|
||||
return getJdbcTemplate().queryForStream(
|
||||
"select cVenCode,cVenName,cVenAbbName," +
|
||||
"cVCCode,cVenAddress,cast(dVenDevDate as DATE) as venDevDate," +
|
||||
"cVenBank, cVenAccount, cCreatePerson,cModifyPerson,dModifyDate " +
|
||||
"from Vendor",
|
||||
new ColumnMapRowMapper()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 以 U8 供应商 的代码查询 供应商
|
||||
*
|
||||
* @param vendCode U8 供应商 的代码,vendCode 唯一
|
||||
* @return 字段和值的Map集合, 没找到匹配的记录时,返回null
|
||||
*/
|
||||
public Map<String, Object> findVendorByVendCode(String vendCode) {
|
||||
try {
|
||||
return getJdbcTemplate().queryForObject("select cVenCode,cVenName,cVenAbbName," +
|
||||
"cVCCode,cVenAddress," +
|
||||
"cast(dVenDevDate as DATE) as devDate,dModifyDate," +
|
||||
"cVenBank,cVenAccount,cCreatePerson, cModifyPerson " +
|
||||
"from Vendor where cVenCode=?", new ColumnMapRowMapper(), vendCode);
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(vendCode, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回 U8 系统中 客户总数
|
||||
*
|
||||
* @return 客户总数
|
||||
*/
|
||||
public Long countAllCustomers() {
|
||||
return getJdbcTemplate().queryForObject("select count(*) from Customer", Long.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 以流式返回所有客户数据
|
||||
*
|
||||
* @return Stream 数据流
|
||||
*/
|
||||
public Stream<Map<String, Object>> queryAllCustomerForStream() {
|
||||
return getJdbcTemplate().queryForStream(
|
||||
"select cCusCode,cCusName,cCusAbbName," +
|
||||
"cCCCode,cCusAddress,cast(dCusDevDate as DATE) as cusDevDate," +
|
||||
"cCusBank,cCusAccount, cCreatePerson,cModifyPerson,dModifyDate " +
|
||||
"from Customer",
|
||||
new ColumnMapRowMapper()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 以 U8 客户 的代码查询 客户
|
||||
*
|
||||
* @param cusCode U8 客户 的代码,cusCode 唯一
|
||||
* @return 字段和值的Map集合
|
||||
*/
|
||||
public Map<String, Object> findCustomerByCusCode(String cusCode) {
|
||||
return getJdbcTemplate().queryForObject("select cCusCode,cCusName,cCusAbbName," +
|
||||
"cCCCode,cCusAddress," +
|
||||
"cast(dCusDevDate as DATE) as devDate,dModifyDate," +
|
||||
"cCusBank,cCusAccount,cCreatePerson,cModifyPerson " +
|
||||
"from Customer where cCusCode=?", new ColumnMapRowMapper(), cusCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回 U8 系统中 合同总数
|
||||
* 在U8中合同在多个地方存在,CM_List, CM_Contract_A,CM_Contract_B,CM_Contract_C
|
||||
*
|
||||
* @return 合同总数
|
||||
*/
|
||||
public Long countAllContracts(int latestId) {
|
||||
return getJdbcTemplate().queryForObject("select count(*) from CM_List where ID>?", Long.class, latestId);
|
||||
}
|
||||
|
||||
public Long countAllContracts(LocalDateTime dateTime) {
|
||||
return getJdbcTemplate().queryForObject("select count(*) from CM_List where dtDate>?", Long.class, dateTime);
|
||||
}
|
||||
|
||||
public Long countAllContracts() {
|
||||
return getJdbcTemplate().queryForObject("select count(*) from CM_List", Long.class);
|
||||
}
|
||||
|
||||
public Long countAllContractB() {
|
||||
return getJdbcTemplate().queryForObject("select count(*) from CM_Contract_B", Long.class);
|
||||
}
|
||||
|
||||
public Long countAllContractB(LocalDate latestDate) {
|
||||
return getJdbcTemplate().queryForObject(
|
||||
"select count(*) " +
|
||||
"from CM_Contract_B " +
|
||||
"where strSetupDate>=? or (dtVaryDate is not null and dtVaryDate>=?)"
|
||||
, Long.class, latestDate, latestDate);
|
||||
}
|
||||
|
||||
public Stream<Map<String, Object>> queryAllContractForStream() {
|
||||
return getJdbcTemplate().queryForStream(
|
||||
"select * from CM_List", new ColumnMapRowMapper()
|
||||
);
|
||||
}
|
||||
|
||||
public Stream<Map<String, Object>> queryAllContractForStream(int latestId) {
|
||||
return getJdbcTemplate().queryForStream(
|
||||
"select * from CM_List where ID > ?",
|
||||
new ColumnMapRowMapper(),
|
||||
latestId
|
||||
);
|
||||
}
|
||||
|
||||
public Stream<Map<String, Object>> queryAllContractForStream(LocalDateTime dateTime) {
|
||||
return getJdbcTemplate().queryForStream(
|
||||
"select * from CM_List where dtDate > ?",
|
||||
new ColumnMapRowMapper(),
|
||||
dateTime
|
||||
);
|
||||
}
|
||||
|
||||
public Stream<Map<String, Object>> queryAllContractBForStream() {
|
||||
return getJdbcTemplate().queryForStream(
|
||||
"select GUID,strContractID,strContractName,strContractType,strParentID,strContractKind,strWay," +
|
||||
"strContractGrp,strContractDesc,strBisectionUnit," +
|
||||
// 时间
|
||||
"strContractOrderDate,strContractStartDate,strContractEndDate," +
|
||||
// 创建人和时间
|
||||
"strSetupPerson,strSetupDate," +
|
||||
// 生效人和时间
|
||||
"strInurePerson,strInureDate," +
|
||||
// 修改人和时间
|
||||
"strVaryPerson,dtVaryDate," +
|
||||
// 业务员
|
||||
"strPersonID, " +
|
||||
"dblTotalCurrency,dblExecCurrency,dblTotalQuantity,dblExecQuqantity " +
|
||||
"from CM_Contract_B ",
|
||||
new ColumnMapRowMapper()
|
||||
);
|
||||
}
|
||||
|
||||
public Stream<Map<String, Object>> queryAllContractBForStream(LocalDate latestDate) {
|
||||
return getJdbcTemplate().queryForStream(
|
||||
"select GUID,strContractID,strContractName,strContractType,strParentID,strContractKind,strWay," +
|
||||
"strContractGrp,strContractDesc,strBisectionUnit," +
|
||||
// 时间
|
||||
"strContractOrderDate,strContractStartDate,strContractEndDate," +
|
||||
// 创建人和时间
|
||||
"strSetupPerson,strSetupDate," +
|
||||
// 生效人和时间
|
||||
"strInurePerson,strInureDate," +
|
||||
// 修改人和时间
|
||||
"strVaryPerson,dtVaryDate," +
|
||||
// 业务员
|
||||
"strPersonID, " +
|
||||
"dblTotalCurrency,dblExecCurrency,dblTotalQuantity,dblExecQuqantity " +
|
||||
"from CM_Contract_B where strSetupDate>=? or (dtVaryDate is not null and dtVaryDate>=?)",
|
||||
new ColumnMapRowMapper(), latestDate, latestDate
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 CM_Contract_B 表中,检索 strBisectionUnit 是 unit 的记录
|
||||
*
|
||||
* @param unit 单位编码
|
||||
* @param payWay 付款方向,付 或 收
|
||||
*/
|
||||
public Stream<Map<String, Object>> queryAllContractByUnitForStream(String unit, ContractPayWay payWay) {
|
||||
return getJdbcTemplate().queryForStream(
|
||||
"select GUID,strContractID,strContractName,strContractType,strParentID,strContractKind,strWay," +
|
||||
"strContractGrp, strContractDesc,strBisectionUnit," +
|
||||
// 时间
|
||||
"strContractOrderDate,strContractStartDate,strContractEndDate," +
|
||||
// 创建人和时间
|
||||
"strSetupPerson,strSetupDate," +
|
||||
// 生效人和时间
|
||||
"strInurePerson,strInureDate," +
|
||||
// 修改人和时间
|
||||
"strVaryPerson,dtVaryDate," +
|
||||
// 业务员
|
||||
"strPersonID, " +
|
||||
"dblTotalCurrency,dblExecCurrency,dblTotalQuantity,dblExecQuqantity " +
|
||||
"from CM_Contract_B where strBisectionUnit=? and strWay=?",
|
||||
new ColumnMapRowMapper(), unit, payWay.getText()
|
||||
);
|
||||
}
|
||||
|
||||
public Map<String, Object> queryContractDetail(String guid) {
|
||||
return getJdbcTemplate().queryForObject("select GUID,strContractID,strContractName,strContractType,strParentID,strContractKind,strWay," +
|
||||
"strContractGrp, strContractDesc,strBisectionUnit," +
|
||||
// 时间
|
||||
"strContractOrderDate,strContractStartDate,strContractEndDate," +
|
||||
// 创建人和时间
|
||||
"strSetupPerson,strSetupDate," +
|
||||
// 生效人和时间
|
||||
"strInurePerson,strInureDate," +
|
||||
// 修改人和时间
|
||||
"strVaryPerson,dtVaryDate," +
|
||||
// 业务员
|
||||
"strPersonID, " +
|
||||
"dblTotalCurrency,dblExecCurrency,dblTotalQuantity,dblExecQuqantity " +
|
||||
" from CM_Contract_B where GUID = ?", new ColumnMapRowMapper(), guid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 合计合同的执行数量、金额、 不含税金额
|
||||
*
|
||||
* @param code 合同号
|
||||
* @return Map<String, Object>
|
||||
*/
|
||||
public Map<String, Object> sumContractExec(String code) {
|
||||
return getJdbcTemplate().queryForObject("select sum(decCount) as execQuantity, sum(decRateMoney) as execAmount, sum(decNoRateMoney) as execUnTaxAmount " +
|
||||
"from CM_ExecInterface " +
|
||||
"where cContractID = ?;", new ColumnMapRowMapper(), code);
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> findAllContractExecByContractCode(String code) {
|
||||
return getJdbcTemplate().queryForList("select * from CM_ExecInterface where cContractID=?", code);
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> findAllContractItemByContractCode(String code) {
|
||||
return getJdbcTemplate().queryForList("select * from CM_Contract_Item_B where strContractID=?", code);
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> findAllContractPayPlanByContractCode(String code) {
|
||||
return getJdbcTemplate().queryForList("select * from CM_Contract_Pay where strContractID=?", code);
|
||||
}
|
||||
|
||||
public Map<String, Object> querySalesOrderDetail(String code) {
|
||||
return getJdbcTemplate().queryForObject("select * " +
|
||||
" from SO_SOMain where cSOCode = ?", new ColumnMapRowMapper(), code);
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> findAllSalesOrderItemByContractCode(String code) {
|
||||
return getJdbcTemplate().queryForList("select * from SO_SODetails where cContractID=?", code);
|
||||
}
|
||||
|
||||
public Map<String, Object> queryPurchaseOrderDetail(Integer code) {
|
||||
return getJdbcTemplate().queryForObject("select * " +
|
||||
" from PO_Pomain where POID = ?", new ColumnMapRowMapper(), code);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 采购合同项
|
||||
*
|
||||
* @param code 采购合同号
|
||||
* @return List<Map < String, Object>>
|
||||
*/
|
||||
public List<Map<String, Object>> findAllPurchaseOrderItemByContractCode(String code) {
|
||||
return getJdbcTemplate().queryForList("select * from PO_Podetails where ContractCode=?", code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询存货档案数据
|
||||
*
|
||||
* @param code 存货编码
|
||||
* @return Map<String, Object>
|
||||
*/
|
||||
public Map<String, Object> queryInventoryDetail(String code) {
|
||||
return getJdbcTemplate().queryForObject("select I.*, U.cComUnitName from Inventory as I left join ComputationUnit as U on I.cComUnitCode=U.cComunitCode where cInvCode = ?", new ColumnMapRowMapper(), code);
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> queryAllPerson() {
|
||||
return getJdbcTemplate().queryForList("select * from Person;");
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> queryAllContractGroup() {
|
||||
return getJdbcTemplate().queryForList("select cGroupID, cGroupName,cRemark from CM_Group;");
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> queryAllContractType() {
|
||||
return getJdbcTemplate().queryForList(
|
||||
"select cTypeCode, cTypeName, CM_TypeClass.cClassName, cCharacter, cDirection " +
|
||||
"from CM_Type left join CM_TypeClass on CM_Type.cClassCode = CM_TypeClass.cClassCode;");
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> queryAllContractKind() {
|
||||
return getJdbcTemplate().queryForList("select KindID,KindName,Description from CM_Kind;");
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> queryAllVendorClass() {
|
||||
return getJdbcTemplate().queryForList("select cVCCode, cVCName, iVCGrade from VendorClass;");
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> queryAllCustomerClass() {
|
||||
return getJdbcTemplate().queryForList("select cCCCode, cCCName, iCCGrade from CustomerClass;");
|
||||
}
|
||||
|
||||
|
||||
public List<Map<String, Object>> findAllPurchaseBillVoucherByVendorCode(String code) {
|
||||
return getJdbcTemplate().queryForList("select * from PurBillVouch where cVenCode=?", code);
|
||||
}
|
||||
|
||||
public Map<String, Object> findPurchaseBillVoucherById(Integer pbvId) {
|
||||
return getJdbcTemplate().queryForObject("select * from PurBillVouch where PBVID = ?", new ColumnMapRowMapper(), pbvId);
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> findAllPurchaseBillVoucherItemByPbvId(int pbvId) {
|
||||
return getJdbcTemplate().queryForList("select * from PurBillVouchs where PBVID=?", pbvId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过合同编号查询采购
|
||||
*
|
||||
* @param contractCode 合同编号
|
||||
*/
|
||||
public List<Map<String, Object>> findAllPurchaseBillVoucherItemByContractCode(String contractCode) {
|
||||
return getJdbcTemplate().queryForList("select * from PurBillVouchs where ContractCode=?", contractCode);
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> findAllSalesBillVoucherByCustomerCode(String code) {
|
||||
return getJdbcTemplate().queryForList("select * from SaleBillVouch where cCusCode=?", code);
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> findAllSalesBillVoucherBySalesOrderCode(String code) {
|
||||
return getJdbcTemplate().queryForList("select * from SaleBillVouch where cSOCode=?", code);
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> findAllSalesBillVoucherItemBySBVID(int sbvid) {
|
||||
return getJdbcTemplate().queryForList("select * from SaleBillVouchs where SBVID=?", sbvid);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,246 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.controlsfx.control.TaskProgressView;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
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.manager.Desktop;
|
||||
import com.ecep.contract.manager.cloud.CloudInfo;
|
||||
import com.ecep.contract.manager.cloud.CloudInfoRepository;
|
||||
import com.ecep.contract.manager.cloud.u8.ctx.AbstractYongYouU8Ctx;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.manager.ds.customer.service.CompanyCustomerService;
|
||||
import com.ecep.contract.manager.ds.other.service.EmployeeService;
|
||||
import com.ecep.contract.manager.ds.vendor.service.CompanyVendorService;
|
||||
import com.ecep.contract.manager.ui.ViewModelService;
|
||||
import com.ecep.contract.manager.ui.task.MonitoredTask;
|
||||
|
||||
import javafx.concurrent.Task;
|
||||
|
||||
@Lazy
|
||||
@Service
|
||||
@ConditionalOnProperty(name = "cloud.u8.enabled", havingValue = "true")
|
||||
public class YongYouU8Service implements ViewModelService<CloudYu, CloudYuInfoViewModel> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(YongYouU8Service.class);
|
||||
public static final String NAME = "用友U8";
|
||||
|
||||
public static final String KEY_HOST_IP = "u8.db.server.ip";
|
||||
public static final String KEY_DATABASE = "u8.db.database";
|
||||
public static final String KEY_USER_NAME = "u8.db.server.name";
|
||||
public static final String KEY_PASSWORD = "u8.db.server.password";
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
private YongYouU8Repository repository;
|
||||
@Lazy
|
||||
@Autowired
|
||||
private CloudInfoRepository cloudInfoRepository;
|
||||
@Lazy
|
||||
@Autowired
|
||||
private CompanyService companyService;
|
||||
@Lazy
|
||||
@Autowired
|
||||
private CompanyVendorService companyVendorService;
|
||||
@Lazy
|
||||
@Autowired
|
||||
private CloudYuRepository cloudYuRepository;
|
||||
@Lazy
|
||||
@Autowired
|
||||
private EmployeeService employeeService;
|
||||
@Lazy
|
||||
@Autowired
|
||||
private CompanyCustomerService companyCustomerService;
|
||||
|
||||
public YongYouU8Service() {
|
||||
|
||||
}
|
||||
|
||||
public CloudYu findById(Integer id) {
|
||||
return cloudYuRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建
|
||||
*
|
||||
* @param info 供应商信息
|
||||
* @return 供应商对象
|
||||
*/
|
||||
public CloudYu getOrCreateCloudYu(CloudInfo info) {
|
||||
Optional<CloudYu> optional = cloudYuRepository.findById(info.getId());
|
||||
return optional.orElseGet(() -> getOrCreateCloudYu(info.getCompany()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建或获取供应商云信息
|
||||
*
|
||||
* @param company 公司
|
||||
* @return 供应商云信息
|
||||
*/
|
||||
public CloudYu getOrCreateCloudYu(Company company) {
|
||||
Integer companyId = company.getId();
|
||||
List<CloudYu> list = cloudYuRepository.findAllByCompanyId(companyId);
|
||||
if (list.isEmpty()) {
|
||||
CloudYu cloudYu = new CloudYu();
|
||||
cloudYu.setCompany(company);
|
||||
cloudYu.setExceptionMessage("");
|
||||
cloudYu.setVendorUpdateDate(null);
|
||||
cloudYu.setCustomerUpdateDate(null);
|
||||
cloudYu.setCloudLatest(null);
|
||||
return cloudYuRepository.save(cloudYu);
|
||||
}
|
||||
|
||||
// 只有匹配到一条有 CloudId 的记录
|
||||
if (list.size() == 1) {
|
||||
// 保留匹配的记录,其他删除
|
||||
CloudYu rk = list.removeFirst();
|
||||
list.remove(rk);
|
||||
cloudYuRepository.deleteAll(list);
|
||||
return rk;
|
||||
}
|
||||
|
||||
return list.getFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成定时同步任务
|
||||
*
|
||||
* @param taskProgressView 任务视图
|
||||
*/
|
||||
public void scheduledTasks(TaskProgressView<Task<?>> taskProgressView) {
|
||||
ScheduledExecutorService executorService = Desktop.instance.getExecutorService();
|
||||
executorService.scheduleAtFixedRate(() -> {
|
||||
ContractSyncTask task = new ContractSyncTask();
|
||||
MonitoredTask<Object> registerTask = Desktop.instance.getTaskMonitorCenter().registerTask(task);
|
||||
registerTask.schedule(5, TimeUnit.SECONDS);
|
||||
}, 3, TimeUnit.MINUTES.toSeconds(15), TimeUnit.SECONDS);
|
||||
|
||||
executorService.scheduleAtFixedRate(() -> {
|
||||
// 1小时运行一次同步供应商任务
|
||||
VendorSyncTask vendorTask = new VendorSyncTask();
|
||||
MonitoredTask<Object> registerVendorTask = Desktop.instance.getTaskMonitorCenter().registerTask(vendorTask);
|
||||
registerVendorTask.schedule(60, TimeUnit.SECONDS);
|
||||
|
||||
// 1小时运行一次同步客户任务
|
||||
CustomerSyncTask customerTask = new CustomerSyncTask();
|
||||
MonitoredTask<Object> registerCustomerTask = Desktop.instance.getTaskMonitorCenter()
|
||||
.registerTask(customerTask);
|
||||
registerCustomerTask.schedule(60, TimeUnit.SECONDS);
|
||||
|
||||
}, 3, TimeUnit.HOURS.toSeconds(1), TimeUnit.SECONDS);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存 Cloud Yu
|
||||
*
|
||||
* @param cloudYu Cloud Yu 对象
|
||||
* @return 更新的 Cloud Yu
|
||||
*/
|
||||
public CloudYu save(CloudYu cloudYu) {
|
||||
return cloudYuRepository.save(cloudYu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(CloudYu entity) {
|
||||
cloudYuRepository.delete(entity);
|
||||
}
|
||||
|
||||
public void deleteByCompany(Company company) {
|
||||
int deleted = cloudYuRepository.deleteAllByCompany(company);
|
||||
if (deleted > 0) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Delete {} records by company:#{}", deleted, company.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void resetTo(Company from, Company to) {
|
||||
List<CloudYu> list = cloudYuRepository.findAllByCompanyId(from.getId());
|
||||
for (CloudYu item : list) {
|
||||
item.setCompany(to);
|
||||
}
|
||||
cloudYuRepository.saveAll(list);
|
||||
}
|
||||
|
||||
public Page<CloudYu> findAll(Specification<CloudYu> spec, Pageable pageable) {
|
||||
return cloudYuRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<CloudYu> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
return null;
|
||||
}
|
||||
return (root, query, builder) -> {
|
||||
return builder.like(root.get("cloudId"), "%" + searchText + "%");
|
||||
};
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> queryAllContractKind() {
|
||||
return repository.queryAllContractKind();
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> queryAllVendorClass() {
|
||||
return repository.queryAllVendorClass();
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> queryAllCustomerClass() {
|
||||
return repository.queryAllCustomerClass();
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> queryAllContractType() {
|
||||
return repository.queryAllContractType();
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> queryAllContractGroup() {
|
||||
return repository.queryAllContractGroup();
|
||||
}
|
||||
|
||||
public Long countAllCustomers() {
|
||||
return repository.countAllCustomers();
|
||||
}
|
||||
|
||||
public Stream<Map<String, Object>> queryAllCustomerForStream() {
|
||||
return repository.queryAllCustomerForStream();
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> queryAllPerson() {
|
||||
return repository.queryAllPerson();
|
||||
}
|
||||
|
||||
public Map<String, Object> findVendorByVendCode(String unit) {
|
||||
return repository.findVendorByVendCode(unit);
|
||||
}
|
||||
|
||||
public Map<String, Object> findCustomerByCusCode(String unit) {
|
||||
return repository.findCustomerByCusCode(unit);
|
||||
}
|
||||
|
||||
public void initialize(AbstractYongYouU8Ctx ctx) {
|
||||
ctx.setRepository(repository);
|
||||
ctx.setCompanyService(companyService);
|
||||
ctx.setEmployeeService(employeeService);
|
||||
ctx.setCompanyVendorService(companyVendorService);
|
||||
ctx.setCompanyCustomerService(companyCustomerService);
|
||||
}
|
||||
|
||||
public Iterable<CloudInfo> findAllCloudYu() {
|
||||
return cloudInfoRepository.findAll();
|
||||
}
|
||||
}
|
||||
@@ -1,216 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8.ctx;
|
||||
|
||||
import com.ecep.contract.manager.cloud.AbstractCtx;
|
||||
import com.ecep.contract.manager.cloud.u8.YongYouU8Repository;
|
||||
import com.ecep.contract.manager.cloud.u8.YongYouU8Service;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.manager.ds.customer.model.CompanyCustomer;
|
||||
import com.ecep.contract.manager.ds.customer.model.CompanyCustomerEntity;
|
||||
import com.ecep.contract.manager.ds.customer.service.CompanyCustomerEntityService;
|
||||
import com.ecep.contract.manager.ds.customer.service.CompanyCustomerService;
|
||||
import com.ecep.contract.manager.ds.other.model.Employee;
|
||||
import com.ecep.contract.manager.ds.other.service.EmployeeService;
|
||||
import com.ecep.contract.manager.ds.vendor.model.CompanyVendor;
|
||||
import com.ecep.contract.manager.ds.vendor.model.CompanyVendorEntity;
|
||||
import com.ecep.contract.manager.ds.vendor.service.CompanyVendorEntityService;
|
||||
import com.ecep.contract.manager.ds.vendor.service.CompanyVendorService;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static com.ecep.contract.manager.SpringApp.getBean;
|
||||
|
||||
public class AbstractYongYouU8Ctx extends AbstractCtx {
|
||||
@Getter
|
||||
@Setter
|
||||
YongYouU8Repository repository;
|
||||
@Setter
|
||||
CompanyService companyService;
|
||||
@Setter
|
||||
EmployeeService employeeService;
|
||||
@Setter
|
||||
CompanyCustomerService companyCustomerService;
|
||||
@Setter
|
||||
CompanyCustomerEntityService companyCustomerEntityService;
|
||||
@Setter
|
||||
CompanyVendorService companyVendorService;
|
||||
@Setter
|
||||
CompanyVendorEntityService companyVendorEntityService;
|
||||
|
||||
|
||||
public void from(AbstractYongYouU8Ctx parent) {
|
||||
repository = parent.repository;
|
||||
companyService = parent.companyService;
|
||||
employeeService = parent.employeeService;
|
||||
companyCustomerService = parent.companyCustomerService;
|
||||
companyVendorService = parent.companyVendorService;
|
||||
}
|
||||
|
||||
public void initializeRepository(MessageHolder holder) {
|
||||
if (repository != null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
repository = getBean(YongYouU8Repository.class);
|
||||
} catch (BeansException e) {
|
||||
holder.warn("未启用 " + YongYouU8Service.NAME + " 服务");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public CompanyService getCompanyService() {
|
||||
if (companyService == null) {
|
||||
companyService = getBean(CompanyService.class);
|
||||
}
|
||||
return companyService;
|
||||
}
|
||||
|
||||
EmployeeService getEmployeeService() {
|
||||
if (employeeService == null) {
|
||||
employeeService = getBean(EmployeeService.class);
|
||||
}
|
||||
return employeeService;
|
||||
}
|
||||
|
||||
public CompanyCustomerService getCompanyCustomerService() {
|
||||
if (companyCustomerService == null) {
|
||||
companyCustomerService = getBean(CompanyCustomerService.class);
|
||||
}
|
||||
return companyCustomerService;
|
||||
}
|
||||
|
||||
public CompanyCustomerEntityService getCompanyCustomerEntityService() {
|
||||
if (companyCustomerEntityService == null) {
|
||||
companyCustomerEntityService = getBean(CompanyCustomerEntityService.class);
|
||||
}
|
||||
return companyCustomerEntityService;
|
||||
}
|
||||
|
||||
public CompanyVendorService getCompanyVendorService() {
|
||||
if (companyVendorService == null) {
|
||||
companyVendorService = getBean(CompanyVendorService.class);
|
||||
}
|
||||
return companyVendorService;
|
||||
}
|
||||
|
||||
public CompanyVendorEntityService getCompanyVendorEntityService() {
|
||||
if (companyVendorEntityService == null) {
|
||||
companyVendorEntityService = getBean(CompanyVendorEntityService.class);
|
||||
}
|
||||
return companyVendorEntityService;
|
||||
}
|
||||
|
||||
boolean updateEmployeeByCode(Supplier<Employee> getter, Consumer<Employee> setter, String code, MessageHolder holder, String topic) {
|
||||
if (StringUtils.hasText(code)) {
|
||||
Employee employee = getEmployeeService().findByCode(code);
|
||||
if (employee != null) {
|
||||
if (!Objects.equals(getter.get(), employee)) {
|
||||
setter.accept(employee);
|
||||
holder.info(topic + "更新为 " + employee.getName());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
boolean updateEmployeeByName(Supplier<Employee> getter, Consumer<Employee> setter, String name, MessageHolder holder, String topic) {
|
||||
if (StringUtils.hasText(name)) {
|
||||
Employee employee = getEmployeeService().findByName(name);
|
||||
if (employee != null) {
|
||||
if (!Objects.equals(getter.get(), employee)) {
|
||||
setter.accept(employee);
|
||||
holder.info(topic + "更新为 " + employee.getName());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean updateCompanyByCustomerCode(Supplier<Company> getter, Consumer<Company> setter, String customerCode, MessageHolder holder, String topic) {
|
||||
Company company = null;
|
||||
if (StringUtils.hasText(customerCode)) {
|
||||
CompanyCustomerEntityService customerEntityService = getCompanyCustomerEntityService();
|
||||
CompanyCustomerService customerService = getCompanyCustomerService();
|
||||
CompanyCustomerEntity entity = customerEntityService.findByCustomerCode(customerCode);
|
||||
if (entity == null) {
|
||||
holder.warn("无效" + topic + ":" + customerCode);
|
||||
} else {
|
||||
CompanyCustomer customer = entity.getCustomer();
|
||||
if (customer == null) {
|
||||
holder.warn("无效" + topic + ":" + customerCode);
|
||||
} else {
|
||||
if (!Hibernate.isInitialized(customer)) {
|
||||
customer = customerService.findById(customer.getId());
|
||||
}
|
||||
company = customer.getCompany();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (company == null) {
|
||||
setter.accept(null);
|
||||
holder.warn("无效" + topic + ":" + customerCode);
|
||||
return true;
|
||||
} else {
|
||||
if (!Objects.equals(getter.get(), company)) {
|
||||
setter.accept(company);
|
||||
if (!Hibernate.isInitialized(company)) {
|
||||
company = getCompanyService().findById(company.getId());
|
||||
}
|
||||
holder.info(topic + "修改为: " + company.getName());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
boolean updateCompanyByVendorCode(Supplier<Company> getter, Consumer<Company> setter, String vendorCode, MessageHolder holder, String topic) {
|
||||
Company company = null;
|
||||
if (StringUtils.hasText(vendorCode)) {
|
||||
CompanyVendorEntityService vendorEntityService = getCompanyVendorEntityService();
|
||||
CompanyVendorService customerService = getCompanyVendorService();
|
||||
CompanyVendorEntity entity = vendorEntityService.findByCode(vendorCode);
|
||||
if (entity == null) {
|
||||
holder.warn("无效" + topic + ":" + vendorCode);
|
||||
} else {
|
||||
CompanyVendor customer = entity.getVendor();
|
||||
if (customer == null) {
|
||||
holder.warn("无效" + topic + ":" + vendorCode);
|
||||
} else {
|
||||
if (!Hibernate.isInitialized(customer)) {
|
||||
customer = customerService.findById(customer.getId());
|
||||
}
|
||||
company = customer.getCompany();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (company == null) {
|
||||
setter.accept(null);
|
||||
holder.warn("无效" + topic + ":" + vendorCode);
|
||||
return true;
|
||||
} else {
|
||||
if (!Objects.equals(getter.get(), company)) {
|
||||
setter.accept(company);
|
||||
if (!Hibernate.isInitialized(company)) {
|
||||
company = getCompanyService().findById(company.getId());
|
||||
}
|
||||
holder.info(topic + "修改为: " + company.getName());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8.ctx;
|
||||
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyBankAccountService;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import lombok.Setter;
|
||||
|
||||
import static com.ecep.contract.manager.SpringApp.getBean;
|
||||
|
||||
public class CompanyBankAccountCtx extends AbstractYongYouU8Ctx {
|
||||
@Setter
|
||||
private CompanyBankAccountService companyBankAccountService;
|
||||
|
||||
CompanyBankAccountService getCompanyBankAccountService() {
|
||||
if (companyBankAccountService == null) {
|
||||
companyBankAccountService = getBean(CompanyBankAccountService.class);
|
||||
}
|
||||
return companyBankAccountService;
|
||||
}
|
||||
|
||||
public void updateBankAccount(Company company, String bank, String bankAccount, MessageHolder holder) {
|
||||
getCompanyBankAccountService().updateBankAccount(company, bank, bankAccount, holder);
|
||||
}
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8.ctx;
|
||||
|
||||
import static com.ecep.contract.manager.SpringApp.getBean;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.manager.cloud.u8.YongYouU8Service;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.model.CompanyOldName;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyOldNameService;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
|
||||
import lombok.Setter;
|
||||
|
||||
public class CompanyCtx extends AbstractYongYouU8Ctx {
|
||||
/**
|
||||
* 自动创建公司的时间
|
||||
*/
|
||||
public static final String AUTO_CREATE_COMPANY_AFTER = "cloud.u8.auto-create-company-after";
|
||||
|
||||
@Setter
|
||||
private CompanyOldNameService companyOldNameService;
|
||||
|
||||
CompanyOldNameService getCompanyOldNameService() {
|
||||
if (companyOldNameService == null) {
|
||||
companyOldNameService = getBean(CompanyOldNameService.class);
|
||||
}
|
||||
return companyOldNameService;
|
||||
}
|
||||
|
||||
public boolean updateCompanyNameIfAbsent(Company company, String name, MessageHolder holder) {
|
||||
if (!StringUtils.hasText(name)) {
|
||||
return false;
|
||||
}
|
||||
if (StringUtils.hasText(company.getName())) {
|
||||
if (Objects.equals(company.getName(), name)) {
|
||||
return false;
|
||||
}
|
||||
appendOldNameIfAbsent(company, name, false, holder);
|
||||
return false;
|
||||
} else {
|
||||
return updateText(company::getName, company::setName, name, holder, "公司名称");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean updateCompanyAbbNameIfAbsent(Company company, String abbName, MessageHolder holder) {
|
||||
if (!StringUtils.hasText(abbName)) {
|
||||
return false;
|
||||
}
|
||||
// 简称与公司名相同,跳过
|
||||
if (Objects.equals(company.getName(), abbName)) {
|
||||
return false;
|
||||
}
|
||||
if (StringUtils.hasText(company.getShortName())) {
|
||||
if (Objects.equals(company.getShortName(), abbName)) {
|
||||
return false;
|
||||
}
|
||||
appendOldNameIfAbsent(company, abbName, true, holder);
|
||||
return false;
|
||||
} else {
|
||||
return updateText(company::getShortName, company::setShortName, abbName, holder, "公司简称");
|
||||
}
|
||||
}
|
||||
|
||||
private void appendOldNameIfAbsent(Company company, String name, boolean ambiguity, MessageHolder holder) {
|
||||
List<CompanyOldName> oldNames = getCompanyOldNameService().findAllByCompanyAndName(company, name);
|
||||
if (oldNames.isEmpty()) {
|
||||
CompanyOldName companyOldName = getCompanyOldNameService().createNew(company, name, ambiguity);
|
||||
companyOldName.setMemo("来自" + YongYouU8Service.NAME);
|
||||
getCompanyOldNameService().save(companyOldName);
|
||||
holder.info("新增曾用名:" + name);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean syncCompany(Company company, MessageHolder holder) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Company findOrCreateByNameOrAbbName(String name, String abbName, LocalDate developDate, MessageHolder holder) {
|
||||
Company company = getCompanyService().findAndRemoveDuplicateCompanyByNameOrAbbName(name, abbName);
|
||||
if (company != null) {
|
||||
return company;
|
||||
}
|
||||
|
||||
// 判断是否是个人
|
||||
holder.warn("企业库中找不到" + name + " 或 " + abbName + " 的企业");
|
||||
// 推测个人用户,归入散户
|
||||
if (name.length() < 4 && !name.contains("公司")) {
|
||||
company = getCompanyService().findByName("散户");
|
||||
if (company == null) {
|
||||
return null;
|
||||
}
|
||||
holder.info(name + " 个人用户归集到散户");
|
||||
return company;
|
||||
}
|
||||
|
||||
// 尝试创建公司
|
||||
company = autoCreateNewCompanyAfter(developDate, name, abbName, holder);
|
||||
if (company != null) {
|
||||
holder.info("自动创建公司:" + company.getName());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Company autoCreateNewCompanyAfter(LocalDate devDate, String name, String abbName, MessageHolder holder) {
|
||||
if (devDate == null) {
|
||||
holder.warn("开发时间未知,不创建公司");
|
||||
return null;
|
||||
}
|
||||
CompanyService companyService = getCompanyService();
|
||||
String autoCreateAfter = getConfService().getString(AUTO_CREATE_COMPANY_AFTER);
|
||||
// 当配置存在,且开发时间小于指定时间,不创建
|
||||
if (StringUtils.hasText(autoCreateAfter)) {
|
||||
LocalDate miniDate = LocalDate.parse(autoCreateAfter);
|
||||
if (devDate.isBefore(miniDate)) {
|
||||
// 创建时间小于指定时间,不创建
|
||||
holder.warn(name + " 的开发时间 " + devDate + " 是 " + miniDate + " 之前的, 按规定不创建, 如有需要请手动创建");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Company com = companyService.createNewCompany(name);
|
||||
com.setShortName(abbName);
|
||||
return companyService.save(com);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,301 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8.ctx;
|
||||
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.cloud.old.OldVersionService;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.customer.model.CompanyCustomer;
|
||||
import com.ecep.contract.manager.ds.customer.model.CompanyCustomerEntity;
|
||||
import com.ecep.contract.manager.ds.customer.model.CustomerCatalog;
|
||||
import com.ecep.contract.manager.ds.customer.service.CompanyCustomerEntityService;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class CustomerCtx extends AbstractYongYouU8Ctx {
|
||||
private static final String AUTO_CREATE_CUSTOMER_AFTER = "cloud.u8.auto-create-customer-after";
|
||||
@Setter
|
||||
private CompanyCtx companyCtx;
|
||||
@Setter
|
||||
private ContractCtx contractCtx;
|
||||
@Setter
|
||||
private CompanyBankAccountCtx companyBankAccountCtx;
|
||||
@Setter
|
||||
private CompanyCustomerEntityService customerEntityService;
|
||||
|
||||
public CompanyCtx getCompanyCtx() {
|
||||
if (companyCtx == null) {
|
||||
companyCtx = new CompanyCtx();
|
||||
companyCtx.from(this);
|
||||
}
|
||||
return companyCtx;
|
||||
}
|
||||
|
||||
ContractCtx getContractCtx() {
|
||||
if (contractCtx == null) {
|
||||
contractCtx = new ContractCtx();
|
||||
contractCtx.from(this);
|
||||
}
|
||||
return contractCtx;
|
||||
}
|
||||
|
||||
CompanyBankAccountCtx getCompanyBankAccountCtx() {
|
||||
if (companyBankAccountCtx == null) {
|
||||
companyBankAccountCtx = new CompanyBankAccountCtx();
|
||||
companyBankAccountCtx.from(this);
|
||||
}
|
||||
return companyBankAccountCtx;
|
||||
}
|
||||
|
||||
CompanyCustomerEntityService getCustomerEntityService() {
|
||||
if (customerEntityService == null) {
|
||||
customerEntityService = SpringApp.getBean(CompanyCustomerEntityService.class);
|
||||
}
|
||||
return customerEntityService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新客户相关项
|
||||
*
|
||||
* @param item
|
||||
* @param unitCode
|
||||
* @param holder
|
||||
*/
|
||||
public CompanyCustomerEntity updateCustomerEntityDetailByCode(CompanyCustomerEntity item, String unitCode, MessageHolder holder) {
|
||||
if (applyEntityDetail(item, repository.findCustomerByCusCode(unitCode), holder)) {
|
||||
item = save(item);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public boolean applyEntityDetail(CompanyCustomerEntity item, Map<String, Object> map, MessageHolder holder) {
|
||||
|
||||
String name = (String) map.get("cCusName");
|
||||
String abbName = (String) map.get("cCusAbbName");
|
||||
String cusCode = (String) map.get("cCusCode");
|
||||
String classCode = (String) map.get("cCCCode");
|
||||
|
||||
String createPerson = (String) map.get("cCreatePerson");
|
||||
String modifyPerson = (String) map.get("cModifyPerson");
|
||||
java.sql.Date devDate = (java.sql.Date) map.get("devDate");
|
||||
java.sql.Timestamp modifyDate = (java.sql.Timestamp) map.get("dModifyDate");
|
||||
|
||||
String bank = (String) map.get("cCusBank");
|
||||
String bankAccount = (String) map.get("cCusAccount");
|
||||
|
||||
|
||||
boolean modified = false;
|
||||
if (updateText(item::getName, item::setName, name, holder, "名称")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateText(item::getAbbName, item::setAbbName, abbName, holder, "简称")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateText(item::getCode, item::setCode, cusCode, holder, "客户编号")) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (updateCustomerCatalog(item::getCatalog, item::setCatalog, classCode, holder, "分类")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateEmployeeByName(item::getCreator, item::setCreator, createPerson, holder, "创建人")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateEmployeeByName(item::getModifier, item::setModifier, modifyPerson, holder, "修改人")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateLocalDate(item::getDevelopDate, item::setDevelopDate, devDate, holder, "发展日期")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateLocalDate(item::getModifyDate, item::setModifyDate, modifyDate, holder, "修改日期")) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (modified) {
|
||||
LocalDate today = LocalDate.now();
|
||||
if (item.getUpdatedDate() == null || item.getUpdatedDate().isBefore(today)) {
|
||||
item.setUpdatedDate(today);
|
||||
holder.info("更新日期更新为 " + today);
|
||||
}
|
||||
}
|
||||
|
||||
CompanyCustomer customer = item.getCustomer();
|
||||
if (customer == null) {
|
||||
// 如果没有关联客户,则根据供应商名称或别名查找公司
|
||||
Company company = findOrCreateCompanyByCustomerEntity(item, holder);
|
||||
if (company != null) {
|
||||
// 找到客户
|
||||
|
||||
customer = getCompanyCustomerService().findByCompany(company);
|
||||
if (customer == null) {
|
||||
customer = createCustomerByCustomerEntity(item, holder);
|
||||
if (customer != null) {
|
||||
customer.setCompany(company);
|
||||
customer = getCompanyCustomerService().save(customer);
|
||||
}
|
||||
}
|
||||
|
||||
if (customer != null) {
|
||||
item.setCustomer(customer);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (customer != null) {
|
||||
if (!Hibernate.isInitialized(customer)) {
|
||||
customer = getCompanyCustomerService().findById(customer.getId());
|
||||
}
|
||||
Company company = customer.getCompany();
|
||||
if (company != null) {
|
||||
getCompanyBankAccountCtx().updateBankAccount(company, bank, bankAccount, holder);
|
||||
}
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
private boolean updateCustomerCatalog(Supplier<CustomerCatalog> getter, Consumer<CustomerCatalog> setter, String catalogCode, MessageHolder holder, String topic) {
|
||||
CustomerCatalog catalog = null;
|
||||
if (StringUtils.hasText(catalogCode)) {
|
||||
catalog = getCompanyCustomerService().findCatalogByCode(catalogCode);
|
||||
}
|
||||
if (catalog == null) {
|
||||
setter.accept(null);
|
||||
holder.warn("无效" + topic + ":" + catalogCode);
|
||||
return true;
|
||||
} else {
|
||||
if (!Objects.equals(getter.get(), catalog)) {
|
||||
if (!Hibernate.isInitialized(catalog)) {
|
||||
catalog = getCompanyCustomerService().findCatalogByCode(catalogCode);
|
||||
}
|
||||
setter.accept(catalog);
|
||||
holder.info(topic + "修改为: " + catalog.getName());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean syncCustomer(Company company, MessageHolder holder) {
|
||||
CompanyCustomer companyCustomer = getCompanyCustomerService().findByCompany(company);
|
||||
if (companyCustomer == null) {
|
||||
holder.error("客户未创建, 如需要请手动创建.");
|
||||
return false;
|
||||
}
|
||||
// 检索相关项
|
||||
List<CompanyCustomerEntity> entities = getCustomerEntityService().findAllByCustomer(companyCustomer);
|
||||
if (entities.isEmpty()) {
|
||||
holder.error("客户未关联任何相关项");
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean updated = false;
|
||||
boolean companyModified = false;
|
||||
|
||||
// 更新相关项
|
||||
for (CompanyCustomerEntity entity : entities) {
|
||||
if (!StringUtils.hasText(entity.getCode())) {
|
||||
holder.warn("相关项:" + entity.getCode() + " 无效,跳过");
|
||||
continue;
|
||||
}
|
||||
if (applyEntityDetail(entity, repository.findCustomerByCusCode(entity.getCode()), holder)) {
|
||||
entity = getCustomerEntityService().save(entity);
|
||||
}
|
||||
|
||||
if (getCompanyCtx().updateCompanyNameIfAbsent(company, entity.getName(), holder)) {
|
||||
companyModified = true;
|
||||
}
|
||||
if (getCompanyCtx().updateCompanyAbbNameIfAbsent(company, entity.getAbbName(), holder)) {
|
||||
companyModified = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (companyModified) {
|
||||
company = getCompanyService().save(company);
|
||||
updated = true;
|
||||
}
|
||||
|
||||
// 更新客户的开发日期
|
||||
if (updateCustomerDevelopDate(companyCustomer, entities, holder)) {
|
||||
companyCustomer = getCompanyCustomerService().save(companyCustomer);
|
||||
updated = true;
|
||||
}
|
||||
|
||||
for (CompanyCustomerEntity entity : entities) {
|
||||
if (getContractCtx().syncByCustomerEntity(companyCustomer, entity, holder)) {
|
||||
updated = true;
|
||||
}
|
||||
}
|
||||
return updated;
|
||||
}
|
||||
|
||||
private boolean updateCustomerDevelopDate(CompanyCustomer companyCustomer, List<CompanyCustomerEntity> entities, MessageHolder holder) {
|
||||
LocalDate developDate = null;
|
||||
for (CompanyCustomerEntity entity : entities) {
|
||||
// 取最早的开发日期
|
||||
if (developDate == null || entity.getDevelopDate().isBefore(developDate)) {
|
||||
developDate = entity.getDevelopDate();
|
||||
}
|
||||
}
|
||||
return updateLocalDate(companyCustomer::getDevelopDate, companyCustomer::setDevelopDate, developDate, holder, "开发日期");
|
||||
}
|
||||
|
||||
public CompanyCustomerEntity findOrCreateByCode(Map<String, Object> rs, String cusCode, MessageHolder subHolder) {
|
||||
CompanyCustomerEntityService customerEntityService = getCompanyCustomerEntityService();
|
||||
CompanyCustomerEntity entity = customerEntityService.findByCustomerCode(cusCode);
|
||||
if (entity == null) {
|
||||
entity = new CompanyCustomerEntity();
|
||||
entity.setCode(cusCode);
|
||||
entity = customerEntityService.save(entity);
|
||||
subHolder.info("创建客户相关项:" + cusCode);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
private CompanyCustomer createCustomerByCustomerEntity(CompanyCustomerEntity entity, MessageHolder holder) {
|
||||
LocalDate developDate = entity.getDevelopDate();
|
||||
if (developDate == null) {
|
||||
holder.warn(entity.getName() + " 没有设置开发日期,跳过");
|
||||
return null;
|
||||
}
|
||||
// 创建发展日期从2023年1月1日后的
|
||||
LocalDate start = LocalDate.of(2023, 1, 1);
|
||||
String autoCreateAfter = getConfService().getString(AUTO_CREATE_CUSTOMER_AFTER);
|
||||
if (StringUtils.hasText(autoCreateAfter)) {
|
||||
start = LocalDate.parse(autoCreateAfter);
|
||||
}
|
||||
if (developDate.isBefore(start)) {
|
||||
// start 之前的不自动创建
|
||||
holder.warn(entity.getName() + " 的发展日期 " + developDate + " 是 " + start + " 之前的, 按规定不自动创建客户, 如有需要请手动创建");
|
||||
return null;
|
||||
}
|
||||
|
||||
CompanyCustomer companyCustomer = new CompanyCustomer();
|
||||
int nextId = SpringApp.getBean(OldVersionService.class).newCompanyCustomer(entity.getName());
|
||||
companyCustomer.setId(nextId);
|
||||
companyCustomer.setDevelopDate(developDate);
|
||||
holder.info("新客户:" + entity.getName() + "分配编号:" + nextId);
|
||||
companyCustomer.setCreated(Instant.now());
|
||||
return companyCustomer;
|
||||
}
|
||||
|
||||
private Company findOrCreateCompanyByCustomerEntity(CompanyCustomerEntity entity, MessageHolder holder) {
|
||||
String name = entity.getName();
|
||||
String abbName = entity.getAbbName();
|
||||
return getCompanyCtx().findOrCreateByNameOrAbbName(name, abbName, entity.getDevelopDate(), holder);
|
||||
}
|
||||
|
||||
public CompanyCustomerEntity save(CompanyCustomerEntity entity) {
|
||||
return getCustomerEntityService().save(entity);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,227 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8.ctx;
|
||||
|
||||
import com.ecep.contract.manager.cloud.u8.YongYouU8Service;
|
||||
import com.ecep.contract.manager.ds.other.model.Inventory;
|
||||
import com.ecep.contract.manager.ds.other.model.InventoryCatalog;
|
||||
import com.ecep.contract.manager.ds.other.model.Price;
|
||||
import com.ecep.contract.manager.ds.other.service.InventoryCatalogService;
|
||||
import com.ecep.contract.manager.ds.other.service.InventoryService;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static com.ecep.contract.manager.SpringApp.getBean;
|
||||
|
||||
public class InventoryCtx extends AbstractYongYouU8Ctx {
|
||||
@Setter
|
||||
private InventoryService inventoryService;
|
||||
@Setter
|
||||
private InventoryCatalogService inventoryCatalogService;
|
||||
|
||||
public InventoryService getInventoryService() {
|
||||
if (inventoryService == null) {
|
||||
inventoryService = getBean(InventoryService.class);
|
||||
}
|
||||
return inventoryService;
|
||||
}
|
||||
|
||||
public InventoryCatalogService getInventoryCatalogService() {
|
||||
if (inventoryCatalogService == null) {
|
||||
inventoryCatalogService = getBean(InventoryCatalogService.class);
|
||||
}
|
||||
return inventoryCatalogService;
|
||||
}
|
||||
|
||||
private boolean applyInventoryDetail(Inventory item, Map<String, Object> map, MessageHolder holder) {
|
||||
String catalogCode = (String) map.get("cInvCCode");
|
||||
String name = (String) map.get("cInvName");
|
||||
String spec = (String) map.get("cInvStd");
|
||||
String unitCode = (String) map.get("cComUnitCode");
|
||||
String unitName = (String) map.get("cComUnitName");
|
||||
String createPerson = (String) map.get("cCreatePerson");
|
||||
String modifyPerson = (String) map.get("cModifyPerson");
|
||||
Timestamp createDate = (Timestamp) map.get("dSDate");
|
||||
Timestamp modifyDate = (Timestamp) map.get("dModifyDate");
|
||||
|
||||
boolean modified = false;
|
||||
|
||||
Double outTaxRate = (Double) map.get("iTaxRate");
|
||||
Double inTaxRate = (Double) map.get("iImpTaxRate");
|
||||
// 参考成本
|
||||
Double baseCostPrice = (Double) map.get("iInvSPrice");
|
||||
// 最新成本
|
||||
Double latestCostPrice = (Double) map.get("iInvNCost");
|
||||
// 计划价/售价
|
||||
Double plannedPrice = (Double) map.get("iInvRCost");
|
||||
// 最低售价
|
||||
Double lowestSalePrice = (Double) map.get("iInvLSCost");
|
||||
// 参考售价
|
||||
Double suggestedSalePrice = (Double) map.get("iInvSCost");
|
||||
|
||||
|
||||
if (!item.isNameLock()) {
|
||||
if (updateText(item::getName, item::setName, name, holder, "名称")) {
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!item.isSpecificationLock()) {
|
||||
if (updateText(item::getSpecification, item::setSpecification, spec, holder, "规格")) {
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (updateText(item::getUnit, item::setUnit, unitName, holder, "单位")) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (updatePrice(item.getPurchasePrice(), inTaxRate, latestCostPrice, holder, "采购")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updatePrice(item.getSalePrice(), outTaxRate, suggestedSalePrice, holder, "销售")) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (updateInventoryCatalog(item::getCatalog, item::setCatalog, catalogCode, holder, "类别")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateEmployeeByName(item::getCreator, item::setCreator, createPerson, holder, "创建人")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateLocalDate(item::getCreateTime, item::setCreateTime, createDate, holder, "创建时间")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateEmployeeByName(item::getUpdater, item::setUpdater, modifyPerson, holder, "修改人")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateLocalDateTime(item::getUpdateDate, item::setUpdateDate, modifyDate, holder, "修改时间")) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
return modified;
|
||||
}
|
||||
|
||||
private boolean updatePrice(Price price, Double taxRate, Double preTaxPrice, MessageHolder holder, String title) {
|
||||
boolean modified = false;
|
||||
if (taxRate != null) {
|
||||
if (updateNumber(price::getTaxRate, price::setTaxRate, taxRate.floatValue(), holder, title + "税率")) {
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
if (preTaxPrice != null) {
|
||||
if (updateNumber(price::getPreTaxPrice, price::setPreTaxPrice, preTaxPrice, holder, title + "未税单价")) {
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
|
||||
public boolean syncInventoryDetailByCode(Inventory inventory, String inventoryCode, MessageHolder holder) {
|
||||
if (repository == null) {
|
||||
return false;
|
||||
}
|
||||
Map<String, Object> map = null;
|
||||
try {
|
||||
map = repository.queryInventoryDetail(inventoryCode);
|
||||
} catch (NoSuchBeanDefinitionException e) {
|
||||
holder.warn("未启用 " + YongYouU8Service.NAME + " 服务");
|
||||
return false;
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
holder.error("无此存货:" + inventoryCode);
|
||||
return false;
|
||||
}
|
||||
if (applyInventoryDetail(inventory, map, holder)) {
|
||||
inventory.setUpdateDate(LocalDateTime.now());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 依据存货分类编号更新存货分类
|
||||
*
|
||||
* @param getter 获取的函数
|
||||
* @param setter 设置的函数
|
||||
* @param catalogCode 存货分类编号
|
||||
* @param holder 消息处理对象
|
||||
* @param topic 主题
|
||||
* @return 是否更新
|
||||
*/
|
||||
private boolean updateInventoryCatalog(Supplier<InventoryCatalog> getter, Consumer<InventoryCatalog> setter, String catalogCode, MessageHolder holder, String topic) {
|
||||
InventoryCatalog catalog = null;
|
||||
if (StringUtils.hasText(catalogCode)) {
|
||||
catalog = getInventoryCatalogService().findByCode(catalogCode);
|
||||
}
|
||||
if (catalog == null) {
|
||||
setter.accept(null);
|
||||
holder.warn("无效" + topic + ":" + catalogCode);
|
||||
return true;
|
||||
} else {
|
||||
if (!Objects.equals(getter.get(), catalog)) {
|
||||
if (!Hibernate.isInitialized(catalog)) {
|
||||
catalog = getInventoryCatalogService().findByCode(catalogCode);
|
||||
}
|
||||
setter.accept(catalog);
|
||||
holder.info(topic + "修改为: " + catalog.getName());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 依据存货编号更新存货
|
||||
*
|
||||
* @param getter 获取的函数
|
||||
* @param setter 设置的函数
|
||||
* @param inventoryCode 存货编号
|
||||
* @param holder 消息持有者
|
||||
* @param topic 主题
|
||||
* @return 是否更新
|
||||
*/
|
||||
public boolean syncInventoryDetailByCode(Supplier<Inventory> getter, Consumer<Inventory> setter, String inventoryCode, MessageHolder holder, String topic) {
|
||||
if (!StringUtils.hasText(inventoryCode)) {
|
||||
return false;
|
||||
}
|
||||
Inventory inventory = null;
|
||||
InventoryService service = getInventoryService();
|
||||
if (StringUtils.hasText(inventoryCode)) {
|
||||
inventory = service.findByCode(inventoryCode);
|
||||
if (inventory == null) {
|
||||
inventory = service.createNewInstance();
|
||||
inventory.setCode(inventoryCode);
|
||||
if (syncInventoryDetailByCode(inventory, inventoryCode, holder)) {
|
||||
inventory = getInventoryService().save(inventory);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (inventory == null) {
|
||||
setter.accept(null);
|
||||
holder.warn("无效" + topic + ":" + inventoryCode);
|
||||
return true;
|
||||
} else {
|
||||
if (!Objects.equals(getter.get(), inventory)) {
|
||||
if (!Hibernate.isInitialized(inventory)) {
|
||||
inventory = service.findByCode(inventoryCode);
|
||||
}
|
||||
setter.accept(inventory);
|
||||
holder.info(topic + "修改为: " + inventory.getName());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8.ctx;
|
||||
|
||||
import com.ecep.contract.manager.ds.company.model.Invoice;
|
||||
import com.ecep.contract.manager.ds.company.service.InvoiceService;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import lombok.Setter;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static com.ecep.contract.manager.SpringApp.getBean;
|
||||
|
||||
public class InvoiceCtx extends AbstractYongYouU8Ctx {
|
||||
@Setter
|
||||
private InvoiceService invoiceService;
|
||||
|
||||
InvoiceService getInvoiceService() {
|
||||
if (invoiceService == null) {
|
||||
invoiceService = getBean(InvoiceService.class);
|
||||
}
|
||||
return invoiceService;
|
||||
}
|
||||
|
||||
public boolean updateInvoiceByNumber(Supplier<Invoice> getter, Consumer<Invoice> setter, String invoiceNumber, MessageHolder holder, String topic) {
|
||||
// TODO 从U8系统中获取数据
|
||||
Invoice invoice = null;
|
||||
if (StringUtils.hasText(invoiceNumber)) {
|
||||
invoice = getInvoiceService().findByCode(invoiceNumber);
|
||||
if (invoice == null) {
|
||||
invoice = new Invoice();
|
||||
invoice.setCode(invoiceNumber);
|
||||
invoice = getInvoiceService().save(invoice);
|
||||
}
|
||||
}
|
||||
if (invoice == null) {
|
||||
setter.accept(null);
|
||||
holder.warn("无效" + topic + ":" + invoiceNumber);
|
||||
return true;
|
||||
} else {
|
||||
if (!Objects.equals(getter.get(), invoice)) {
|
||||
setter.accept(invoice);
|
||||
holder.info(topic + "修改为: " + invoice.getCode());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,419 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8.ctx;
|
||||
|
||||
import com.ecep.contract.manager.cloud.u8.YongYouU8Service;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.model.Invoice;
|
||||
import com.ecep.contract.manager.ds.contract.model.*;
|
||||
import com.ecep.contract.manager.ds.contract.service.PurchaseBillVoucherItemService;
|
||||
import com.ecep.contract.manager.ds.contract.service.PurchaseBillVoucherService;
|
||||
import com.ecep.contract.manager.ds.contract.service.PurchaseOrderItemService;
|
||||
import com.ecep.contract.manager.ds.contract.service.PurchaseOrdersService;
|
||||
import com.ecep.contract.manager.ds.other.model.Inventory;
|
||||
import com.ecep.contract.manager.ds.vendor.model.CompanyVendor;
|
||||
import com.ecep.contract.manager.ds.vendor.model.CompanyVendorEntity;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import lombok.Setter;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.ecep.contract.manager.SpringApp.getBean;
|
||||
|
||||
public class PurchaseBillVoucherCtx extends AbstractYongYouU8Ctx {
|
||||
@Setter
|
||||
private PurchaseOrdersService purchaseOrdersService;
|
||||
@Setter
|
||||
private PurchaseOrderItemService purchaseOrderItemService;
|
||||
@Setter
|
||||
private PurchaseBillVoucherService purchaseBillVoucherService;
|
||||
@Setter
|
||||
private PurchaseBillVoucherItemService purchaseBillVoucherItemService;
|
||||
|
||||
|
||||
InventoryCtx inventoryCtx;
|
||||
InvoiceCtx invoiceCtx;
|
||||
ContractCtx contractCtx;
|
||||
|
||||
PurchaseOrdersService getPurchaseOrdersService() {
|
||||
if (purchaseOrdersService == null) {
|
||||
purchaseOrdersService = getBean(PurchaseOrdersService.class);
|
||||
}
|
||||
return purchaseOrdersService;
|
||||
}
|
||||
|
||||
PurchaseBillVoucherService getPurchaseBillVoucherService() {
|
||||
if (purchaseBillVoucherService == null) {
|
||||
purchaseBillVoucherService = getBean(PurchaseBillVoucherService.class);
|
||||
}
|
||||
return purchaseBillVoucherService;
|
||||
}
|
||||
|
||||
private PurchaseOrderItemService getPurchaseOrderItemService() {
|
||||
if (purchaseOrderItemService == null) {
|
||||
purchaseOrderItemService = getBean(PurchaseOrderItemService.class);
|
||||
}
|
||||
return purchaseOrderItemService;
|
||||
}
|
||||
|
||||
PurchaseBillVoucherItemService getPurchaseBillVoucherItemService() {
|
||||
if (purchaseBillVoucherItemService == null) {
|
||||
purchaseBillVoucherItemService = getBean(PurchaseBillVoucherItemService.class);
|
||||
}
|
||||
return purchaseBillVoucherItemService;
|
||||
}
|
||||
|
||||
InventoryCtx getInventoryCtx() {
|
||||
if (inventoryCtx == null) {
|
||||
inventoryCtx = new InventoryCtx();
|
||||
inventoryCtx.from(this);
|
||||
}
|
||||
return inventoryCtx;
|
||||
}
|
||||
|
||||
InvoiceCtx getInvoiceCtx() {
|
||||
if (invoiceCtx == null) {
|
||||
invoiceCtx = new InvoiceCtx();
|
||||
invoiceCtx.from(this);
|
||||
}
|
||||
return invoiceCtx;
|
||||
}
|
||||
|
||||
ContractCtx getContractCtx() {
|
||||
if (contractCtx == null) {
|
||||
contractCtx = new ContractCtx();
|
||||
contractCtx.from(this);
|
||||
}
|
||||
return contractCtx;
|
||||
}
|
||||
|
||||
public void syncByCompany(Company company, MessageHolder holder) {
|
||||
PurchaseBillVoucherService voucherService = getPurchaseBillVoucherService();
|
||||
PurchaseBillVoucherItemService voucherItemService = getPurchaseBillVoucherItemService();
|
||||
List<PurchaseBillVoucher> vouchers = voucherService.findAll((root, q, cb) -> {
|
||||
return cb.equal(root.get("company"), company);
|
||||
}, Sort.unsorted());
|
||||
holder.debug("查找到 " + vouchers.size() + " 条专用发票记录在数据库中");
|
||||
Map<Integer, PurchaseBillVoucher> voucherMap = vouchers.stream().collect(Collectors.toMap(PurchaseBillVoucher::getRefId, item -> item));
|
||||
|
||||
CompanyVendor vendor = getCompanyVendorService().findByCompany(company);
|
||||
if (vendor != null) {
|
||||
List<CompanyVendorEntity> entities = getCompanyVendorEntityService().findAllByVendor(vendor);
|
||||
holder.debug(company.getName() + " 有 " + entities.stream().map(CompanyVendorEntity::getCode).collect(Collectors.joining(", ")) + " 关联项");
|
||||
for (CompanyVendorEntity entity : entities) {
|
||||
// 查询 U8 数据库
|
||||
List<Map<String, Object>> ds = repository.findAllPurchaseBillVoucherByVendorCode(entity.getCode());
|
||||
holder.debug("供应商关联项: " + entity.getCode() + " 查找到 " + ds.size() + " 条专用发票记录在 " + YongYouU8Service.NAME);
|
||||
|
||||
for (Map<String, Object> map : ds) {
|
||||
Integer pbvid = (Integer) map.get("PBVID");
|
||||
if (pbvid == 0) {
|
||||
holder.warn("跳过无效专用发票记录:缺少 PBVID");
|
||||
continue;
|
||||
}
|
||||
holder.debug("发票 #" + pbvid);
|
||||
PurchaseBillVoucher voucher = voucherMap.get(pbvid);
|
||||
boolean voucherModified = false;
|
||||
if (voucher == null) {
|
||||
voucher = new PurchaseBillVoucher();
|
||||
voucher.setCompany(company);
|
||||
voucher.setRefId(pbvid);
|
||||
voucherMap.put(pbvid, voucher);
|
||||
voucherModified = true;
|
||||
|
||||
holder.info("新增发票记录");
|
||||
}
|
||||
|
||||
if (applyPurchaseBillVoucherDetail(voucher, map, holder.sub("-- | "))) {
|
||||
voucherModified = true;
|
||||
}
|
||||
|
||||
if (voucherModified) {
|
||||
voucher = voucherService.save(voucher);
|
||||
voucherMap.put(pbvid, voucher);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<PurchaseBillVoucherItem> items = voucherItemService.findAll((root, q, cb) -> {
|
||||
return cb.equal(root.get("voucher").get("company"), company);
|
||||
}, Sort.unsorted());
|
||||
|
||||
// 按 order 分组
|
||||
Map<PurchaseBillVoucher, Map<Integer, PurchaseBillVoucherItem>> itemMap = items.stream().collect(Collectors.groupingBy(PurchaseBillVoucherItem::getVoucher,
|
||||
Collectors.toMap(PurchaseBillVoucherItem::getRefId, item -> item)));
|
||||
for (PurchaseBillVoucher voucher : voucherMap.values()) {
|
||||
|
||||
// 查询 U8 数据库
|
||||
List<Map<String, Object>> ds = repository.findAllPurchaseBillVoucherItemByPbvId(voucher.getRefId());
|
||||
holder.debug("专用发票#" + voucher.getRefId() + "查找到 " + ds.size() + "条条目记录在 " + YongYouU8Service.NAME);
|
||||
Map<Integer, PurchaseBillVoucherItem> subItemMap = itemMap.computeIfAbsent(voucher, k -> new HashMap<>());
|
||||
for (Map<String, Object> map : ds) {
|
||||
Integer refId = (Integer) map.get("ID");
|
||||
if (refId == 0) {
|
||||
holder.warn("跳过无效专用发票记录:缺少 ID");
|
||||
continue;
|
||||
}
|
||||
PurchaseBillVoucherItem item = subItemMap.remove(refId);
|
||||
boolean itemModified = false;
|
||||
if (item == null) {
|
||||
item = new PurchaseBillVoucherItem();
|
||||
item.setVoucher(voucher);
|
||||
item.setRefId(refId);
|
||||
itemModified = true;
|
||||
|
||||
holder.info("新增专用发票条目 #" + refId);
|
||||
}
|
||||
MessageHolder subHolder = holder.sub("-- | ");
|
||||
if (applyPurchaseBillVoucherItemDetail(item, map, subHolder)) {
|
||||
itemModified = true;
|
||||
}
|
||||
if (itemModified) {
|
||||
item = voucherItemService.save(item);
|
||||
}
|
||||
}
|
||||
for (PurchaseBillVoucherItem item : subItemMap.values()) {
|
||||
holder.info("删除专用发票条目");
|
||||
voucherItemService.delete(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void syncByContract(Contract contract, MessageHolder holder) {
|
||||
PurchaseBillVoucherService voucherService = getPurchaseBillVoucherService();
|
||||
PurchaseBillVoucherItemService voucherItemService = getPurchaseBillVoucherItemService();
|
||||
List<PurchaseBillVoucherItem> items = voucherItemService.findAll((root, q, cb) -> {
|
||||
return cb.equal(root.get("contract"), contract);
|
||||
}, Sort.unsorted());
|
||||
|
||||
Map<Integer, PurchaseBillVoucherItem> itemMap = items.stream().collect(Collectors.toMap(PurchaseBillVoucherItem::getRefId, item -> item));
|
||||
// 查询 U8 数据库
|
||||
List<Map<String, Object>> ds = repository.findAllPurchaseBillVoucherItemByContractCode(contract.getCode());
|
||||
holder.debug("合同编号#" + contract.getCode() + "查找到 " + ds.size() + "条发票条目记录在 " + YongYouU8Service.NAME);
|
||||
|
||||
for (Map<String, Object> map : ds) {
|
||||
Integer refId = (Integer) map.get("ID");
|
||||
if (refId == 0) {
|
||||
holder.warn("跳过无效专用发票记录:缺少 ID");
|
||||
continue;
|
||||
}
|
||||
PurchaseBillVoucherItem item = itemMap.remove(refId);
|
||||
boolean itemModified = false;
|
||||
if (item == null) {
|
||||
item = new PurchaseBillVoucherItem();
|
||||
PurchaseBillVoucher voucher = this.updateVoucherByPBVID((Integer) map.get("PBVID"), holder);
|
||||
item.setVoucher(voucher);
|
||||
item.setRefId(refId);
|
||||
itemModified = true;
|
||||
|
||||
holder.info("新增专用发票条目 #" + refId);
|
||||
}
|
||||
MessageHolder subHolder = holder.sub("-- | ");
|
||||
if (applyPurchaseBillVoucherItemDetail(item, map, subHolder)) {
|
||||
itemModified = true;
|
||||
}
|
||||
if (itemModified) {
|
||||
item = voucherItemService.save(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PurchaseBillVoucher updateVoucherByPBVID(Integer pbvId, MessageHolder holder) {
|
||||
PurchaseBillVoucherService voucherService = getPurchaseBillVoucherService();
|
||||
PurchaseBillVoucher voucher = voucherService.findByRefId(pbvId);
|
||||
if (voucher != null) {
|
||||
return voucher;
|
||||
}
|
||||
voucher = new PurchaseBillVoucher();
|
||||
// 查询 U8 数据库
|
||||
Map<String, Object> map = repository.findPurchaseBillVoucherById(pbvId);
|
||||
applyPurchaseBillVoucherDetail(voucher, map, holder.sub("-- | "));
|
||||
voucher = voucherService.save(voucher);
|
||||
return voucher;
|
||||
}
|
||||
|
||||
|
||||
private boolean applyPurchaseBillVoucherDetail(PurchaseBillVoucher voucher, Map<String, Object> map, MessageHolder holder) {
|
||||
String code = String.valueOf(map.get("PBVID"));
|
||||
String vendorCode = (String) map.get("cVenCode");
|
||||
String invoiceNumber = (String) map.get("cPBVCode");
|
||||
String personCode = (String) map.get("cPersonCode");
|
||||
String inCode = (String) map.get("cInCode");
|
||||
|
||||
|
||||
Timestamp invoiceDate = (Timestamp) map.get("dPBVDate");
|
||||
Timestamp voucherDate = (Timestamp) map.get("dVouDate");
|
||||
|
||||
BigDecimal amount = (BigDecimal) map.get("iSum");
|
||||
|
||||
String maker = (String) map.get("cPBVMaker");
|
||||
String verifier = (String) map.get("cPBVVerifier");
|
||||
Timestamp makeTime = (Timestamp) map.get("cmaketime");
|
||||
Timestamp auditTime = (Timestamp) map.get("dverifysystime");
|
||||
|
||||
String description = (String) map.get("cPBVMemo");
|
||||
|
||||
|
||||
boolean modified = false;
|
||||
|
||||
holder.debug("发票号码:" + invoiceNumber);
|
||||
|
||||
if (updateCompanyByVendorCode(voucher::getCompany, voucher::setCompany, vendorCode, holder, "供应商")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateInvoice(voucher::getInvoice, voucher::setInvoice, invoiceNumber, holder, "发票")) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (voucher.getInvoice() != null) {
|
||||
Invoice invoice = voucher.getInvoice();
|
||||
if (updateLocalDate(invoice::getInvoiceDate, invoice::setInvoiceDate, voucherDate, holder, "开票日期")) {
|
||||
invoice = getInvoiceCtx().getInvoiceService().save(invoice);
|
||||
voucher.setInvoice(invoice);
|
||||
}
|
||||
}
|
||||
|
||||
if (updateEmployeeByCode(voucher::getEmployee, voucher::setEmployee, personCode, holder, "业务员")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateEmployeeByName(voucher::getMaker, voucher::setMaker, maker, holder, "制单人")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateEmployeeByName(voucher::getVerifier, voucher::setVerifier, verifier, holder, "审核人")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateLocalDateTime(voucher::getMakerDate, voucher::setMakerDate, makeTime, holder, "制单时间")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateLocalDateTime(voucher::getVerifierDate, voucher::setVerifierDate, auditTime, holder, "审核时间")) {
|
||||
modified = true;
|
||||
}
|
||||
if (!Objects.equals(voucher.getDescription(), description)) {
|
||||
voucher.setDescription(description);
|
||||
holder.info("描述修改为: " + description);
|
||||
modified = true;
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
|
||||
private boolean applyPurchaseBillVoucherItemDetail(PurchaseBillVoucherItem item, Map<String, Object> map, MessageHolder holder) {
|
||||
String code = String.valueOf(map.get("ID"));
|
||||
String inventoryCode = (String) map.get("cInvCode");
|
||||
String contractCode = (String) map.get("ContractCode");
|
||||
|
||||
|
||||
String title = (String) map.get("cInvCode");
|
||||
double quantity = (double) map.get("iPBVQuantity");
|
||||
BigDecimal taxRate = (BigDecimal) map.get("iOriTaxPrice");
|
||||
BigDecimal taxPrice = (BigDecimal) map.get("iTaxPrice");
|
||||
BigDecimal amount = (BigDecimal) map.get("iSum");
|
||||
|
||||
// RdsId
|
||||
|
||||
// 采购订单条目refId
|
||||
Integer purchaseOrderItemId = (Integer) map.get("iPOsID");
|
||||
|
||||
String description = (String) map.get("cdescription");
|
||||
Timestamp signDate = (Timestamp) map.get("dSignDate");
|
||||
|
||||
boolean modified = false;
|
||||
|
||||
holder.debug("条目:" + title + " x " + amount);
|
||||
if (updateInventory(item::getInventory, item::setInventory, inventoryCode, holder, "商品")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updatePurchaseOrderItem(item::getOrderItem, item::setOrderItem, purchaseOrderItemId, holder, "采购订单条目")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateContractByContractCode(item::getContract, item::setContract, contractCode, holder, "合同")) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (updateNumber(item::getPrice, item::setPrice, taxPrice, holder, "含税单价")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateNumber(item::getQuantity, item::setQuantity, quantity, holder, "数量")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateAppendText(item::getDescription, item::setDescription, description, holder, "描述")) {
|
||||
modified = true;
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
boolean updatePurchaseOrderItem(Supplier<PurchaseOrderItem> getter, Consumer<PurchaseOrderItem> setter, Integer orderItemRefId, MessageHolder holder, String topic) {
|
||||
PurchaseOrderItem item = null;
|
||||
if (orderItemRefId != null) {
|
||||
item = getPurchaseOrderItemService().findByRefId(orderItemRefId);
|
||||
}
|
||||
if (item == null) {
|
||||
setter.accept(null);
|
||||
holder.warn("无效" + topic + ":" + orderItemRefId);
|
||||
return true;
|
||||
} else {
|
||||
if (!Objects.equals(getter.get(), item)) {
|
||||
setter.accept(item);
|
||||
holder.info(topic + "修改为: " + item.getRefId());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean updatePurchaseOrder(Supplier<PurchaseOrder> getter, Consumer<PurchaseOrder> setter, Integer orderRefId, MessageHolder holder, String topic) {
|
||||
PurchaseOrder order = null;
|
||||
if (orderRefId != null) {
|
||||
order = getPurchaseOrdersService().findByRefId(orderRefId);
|
||||
}
|
||||
if (order == null) {
|
||||
setter.accept(null);
|
||||
holder.warn("无效" + topic + ":" + orderRefId);
|
||||
return true;
|
||||
} else {
|
||||
if (!Objects.equals(getter.get(), order)) {
|
||||
setter.accept(order);
|
||||
holder.info(topic + "修改为: " + order.getCode());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean updateContractByContractCode(Supplier<Contract> getter, Consumer<Contract> setter, String contractCode, MessageHolder holder, String topic) {
|
||||
Contract contract = null;
|
||||
if (contractCode != null) {
|
||||
contract = getContractCtx().findContractByCode(contractCode);
|
||||
}
|
||||
if (contract == null) {
|
||||
setter.accept(null);
|
||||
holder.warn("无效" + topic + ":" + contractCode);
|
||||
return true;
|
||||
} else {
|
||||
if (!Objects.equals(getter.get(), contract)) {
|
||||
setter.accept(contract);
|
||||
holder.info(topic + "修改为: " + contract.getCode());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean updateInventory(Supplier<Inventory> getter, Consumer<Inventory> setter, String inventoryCode, MessageHolder holder, String topic) {
|
||||
return getInventoryCtx().syncInventoryDetailByCode(getter, setter, inventoryCode, holder, topic);
|
||||
}
|
||||
|
||||
private boolean updateInvoice(Supplier<Invoice> getter, Consumer<Invoice> setter, String invoiceNumber, MessageHolder holder, String topic) {
|
||||
return getInvoiceCtx().updateInvoiceByNumber(getter, setter, invoiceNumber, holder, topic);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,318 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8.ctx;
|
||||
|
||||
import com.ecep.contract.manager.cloud.u8.YongYouU8Service;
|
||||
import com.ecep.contract.manager.ds.contract.model.Contract;
|
||||
import com.ecep.contract.manager.ds.contract.model.PurchaseOrder;
|
||||
import com.ecep.contract.manager.ds.contract.model.PurchaseOrderItem;
|
||||
import com.ecep.contract.manager.ds.contract.service.ContractService;
|
||||
import com.ecep.contract.manager.ds.contract.service.PurchaseOrderItemService;
|
||||
import com.ecep.contract.manager.ds.contract.service.PurchaseOrdersService;
|
||||
import com.ecep.contract.manager.ds.other.model.Inventory;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import com.ecep.contract.manager.util.NumberUtils;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.ecep.contract.manager.SpringApp.getBean;
|
||||
|
||||
public class PurchaseOrderCtx extends AbstractYongYouU8Ctx {
|
||||
@Setter
|
||||
private ContractService contractService;
|
||||
@Setter
|
||||
private PurchaseOrdersService purchaseOrdersService;
|
||||
@Setter
|
||||
private PurchaseOrderItemService purchaseOrderItemService;
|
||||
|
||||
InventoryCtx inventoryCtx;
|
||||
CompanyBankAccountCtx companyBankAccountCtx;
|
||||
|
||||
InventoryCtx getInventoryCtx() {
|
||||
if (inventoryCtx == null) {
|
||||
inventoryCtx = new InventoryCtx();
|
||||
inventoryCtx.from(this);
|
||||
}
|
||||
return inventoryCtx;
|
||||
}
|
||||
|
||||
CompanyBankAccountCtx getCompanyBankAccountCtx() {
|
||||
if (companyBankAccountCtx == null) {
|
||||
companyBankAccountCtx = new CompanyBankAccountCtx();
|
||||
companyBankAccountCtx.from(this);
|
||||
}
|
||||
return companyBankAccountCtx;
|
||||
}
|
||||
|
||||
ContractService getContractService() {
|
||||
if (contractService == null) {
|
||||
contractService = getBean(ContractService.class);
|
||||
}
|
||||
return contractService;
|
||||
}
|
||||
|
||||
PurchaseOrdersService getPurchaseOrdersService() {
|
||||
if (purchaseOrdersService == null) {
|
||||
purchaseOrdersService = getBean(PurchaseOrdersService.class);
|
||||
}
|
||||
return purchaseOrdersService;
|
||||
}
|
||||
|
||||
PurchaseOrderItemService getPurchaseOrderItemService() {
|
||||
if (purchaseOrderItemService == null) {
|
||||
purchaseOrderItemService = getBean(PurchaseOrderItemService.class);
|
||||
}
|
||||
return purchaseOrderItemService;
|
||||
}
|
||||
|
||||
|
||||
public List<PurchaseOrder> syncByContract(Contract contract, MessageHolder holder) {
|
||||
PurchaseOrdersService ordersService = getPurchaseOrdersService();
|
||||
PurchaseOrderItemService itemService = getPurchaseOrderItemService();
|
||||
|
||||
List<PurchaseOrder> orders = ordersService.findAll((root, q, cb) -> {
|
||||
return cb.equal(root.get("contract"), contract);
|
||||
}, Sort.unsorted());
|
||||
holder.debug("查找到 " + orders.size() + " 条采购订单记录在数据库中");
|
||||
Map<Integer, PurchaseOrder> ordersMap = orders.stream().collect(Collectors.toMap(PurchaseOrder::getRefId, item -> item));
|
||||
|
||||
List<PurchaseOrderItem> items = itemService.findAll((root, q, cb) -> {
|
||||
return cb.equal(root.get("order").get("contract"), contract);
|
||||
}, Sort.unsorted());
|
||||
|
||||
// 按 order 分组
|
||||
Map<PurchaseOrder, Map<Integer, PurchaseOrderItem>> itemMap = items.stream().collect(Collectors.groupingBy(PurchaseOrderItem::getOrder,
|
||||
Collectors.toMap(PurchaseOrderItem::getRefId, item -> item)));
|
||||
|
||||
// 查询 U8 数据库
|
||||
List<Map<String, Object>> ds = repository.findAllPurchaseOrderItemByContractCode(contract.getCode());
|
||||
holder.debug("查找到 " + ds.size() + " 条采购订单条目记录在 " + YongYouU8Service.NAME);
|
||||
|
||||
Map<PurchaseOrder, List<PurchaseOrderItem>> updateMap = new HashMap<>();
|
||||
for (Map<String, Object> map : ds) {
|
||||
Integer poId = (Integer) map.get("POID");
|
||||
if (poId == 0) {
|
||||
holder.warn("跳过无效采购订单记录:缺少 POID");
|
||||
continue;
|
||||
}
|
||||
PurchaseOrder order = ordersMap.get(poId);
|
||||
if (order == null) {
|
||||
order = new PurchaseOrder();
|
||||
order.setContract(contract);
|
||||
order.setRefId(poId);
|
||||
|
||||
order = ordersService.save(order);
|
||||
ordersMap.put(poId, order);
|
||||
holder.info("新增采购订单 #" + poId);
|
||||
}
|
||||
}
|
||||
for (Map<String, Object> map : ds) {
|
||||
// holder.debug("条目:" + map.toString());
|
||||
Integer poId = (Integer) map.get("POID");
|
||||
if (poId == 0) {
|
||||
holder.warn("跳过无效采购订单记录:缺少 POID");
|
||||
continue;
|
||||
}
|
||||
PurchaseOrder order = ordersMap.get(poId);
|
||||
|
||||
boolean itemModified = false;
|
||||
List<PurchaseOrderItem> updates = updateMap.computeIfAbsent(order, k -> new ArrayList<>());
|
||||
|
||||
// 获取条目标识并处理 null
|
||||
Integer refId = (Integer) map.get("ID");
|
||||
if (poId == null) {
|
||||
holder.warn("跳过条目:订单 " + poId + " 缺少 ID");
|
||||
continue;
|
||||
}
|
||||
Map<Integer, PurchaseOrderItem> subItemMap = itemMap.get(order);
|
||||
PurchaseOrderItem item = null;
|
||||
if (subItemMap != null) {
|
||||
item = subItemMap.remove(refId);
|
||||
}
|
||||
|
||||
if (item == null) {
|
||||
item = new PurchaseOrderItem();
|
||||
item.setOrder(order);
|
||||
item.setRefId(refId);
|
||||
itemModified = true;
|
||||
|
||||
holder.info("新增采购订单条目 #" + refId);
|
||||
}
|
||||
MessageHolder subHolder = holder.sub("---| ");
|
||||
if (applyPurchaseOrderItemDetail(item, map, subHolder)) {
|
||||
itemModified = true;
|
||||
}
|
||||
if (itemModified) {
|
||||
item = itemService.save(item);
|
||||
}
|
||||
updates.add(item);
|
||||
}
|
||||
|
||||
for (PurchaseOrder order : updateMap.keySet()) {
|
||||
if (applyPurchaseOrderDetail(order, repository.queryPurchaseOrderDetail(order.getRefId()), holder)) {
|
||||
ordersService.save(order);
|
||||
}
|
||||
}
|
||||
|
||||
if (!itemMap.isEmpty()) {
|
||||
for (Map<Integer, PurchaseOrderItem> subMap : itemMap.values()) {
|
||||
if (!subMap.isEmpty()) {
|
||||
for (PurchaseOrderItem item : subMap.values()) {
|
||||
holder.info("删除采购订单条目");
|
||||
itemService.delete(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (PurchaseOrder order : updateMap.keySet()) {
|
||||
itemMap.remove(order);
|
||||
}
|
||||
if (!itemMap.isEmpty()) {
|
||||
holder.info("剩余 " + itemMap.size() + " 个采购订单条目");
|
||||
}
|
||||
}
|
||||
|
||||
return new ArrayList<>(updateMap.keySet());
|
||||
}
|
||||
|
||||
private boolean applyPurchaseOrderDetail(PurchaseOrder order, Map<String, Object> map, MessageHolder holder) {
|
||||
String code = (String) map.get("cPOID");
|
||||
|
||||
String venBank = (String) map.get("cVenBank");
|
||||
String venBankAccount = (String) map.get("cVenAccount");
|
||||
|
||||
String venCode = (String) map.get("cVenCode");
|
||||
String memo = (String) map.get("cMemo");
|
||||
|
||||
boolean modified = false;
|
||||
|
||||
if (!Objects.equals(order.getCode(), code)) {
|
||||
order.setCode(code);
|
||||
holder.info("订单编号更新为 " + code);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (updateEmployeeByCode(order::getEmployee, order::setEmployee, (String) map.get("cPersonCode"), holder, "业务员")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateEmployeeByName(order::getMaker, order::setMaker, (String) map.get("cMaker"), holder, "制单人")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateEmployeeByName(order::getVerifier, order::setVerifier, (String) map.get("cVerifier"), holder, "审核人")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateEmployeeByName(order::getCloser, order::setCloser, (String) map.get("cCloser"), holder, "订单关闭人")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateLocalDateTime(order::getMakerDate, order::setMakerDate, (Timestamp) map.get("cmaketime"), holder, "制单日期")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateLocalDateTime(order::getModifyDate, order::setModifyDate, (Timestamp) map.get("cModifyTime"), holder, "修改日期")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateLocalDateTime(order::getVerifierDate, order::setVerifierDate, (Timestamp) map.get("cAuditTime"), holder, "审核日期")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateLocalDateTime(order::getCloserDate, order::setCloserDate, (Timestamp) map.get("dCloseTime"), holder, "关闭日期")) {
|
||||
modified = true;
|
||||
}
|
||||
if (!Objects.equals(order.getVendorCode(), venCode)) {
|
||||
order.setVendorCode(venCode);
|
||||
holder.info("供方代码修改为: " + venCode);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!Objects.equals(order.getDescription(), memo)) {
|
||||
order.setDescription(memo);
|
||||
holder.info("描述修改为: " + memo);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
updateCompanyBankAccount(order.getContract(), venBank, venBankAccount, holder);
|
||||
|
||||
return modified;
|
||||
}
|
||||
|
||||
private void updateCompanyBankAccount(Contract contract, String bank, String bankAccount, MessageHolder holder) {
|
||||
if (contract == null) {
|
||||
return;
|
||||
}
|
||||
if (!Hibernate.isInitialized(contract)) {
|
||||
contract = getContractService().findById(contract.getId());
|
||||
}
|
||||
getCompanyBankAccountCtx().updateBankAccount(contract.getCompany(), bank, bankAccount, holder);
|
||||
}
|
||||
|
||||
|
||||
private boolean applyPurchaseOrderItemDetail(PurchaseOrderItem item, Map<String, Object> map, MessageHolder holder) {
|
||||
Integer refId = (Integer) map.get("ID");
|
||||
String inventoryCode = (String) map.get("cInvCode");
|
||||
String contractCode = (String) map.get("ContractCode");
|
||||
|
||||
String title = (String) map.get("cInvCode");
|
||||
double quantity = (double) map.get("iQuantity");
|
||||
BigDecimal taxRate = (BigDecimal) map.get("iPerTaxRate");
|
||||
BigDecimal taxPrice = (BigDecimal) map.get("iTaxPrice");
|
||||
double exclusiveTaxPrice = (double) map.get("iUnitPrice");
|
||||
BigDecimal amount = (BigDecimal) map.get("iSum");
|
||||
|
||||
|
||||
Timestamp arriveDate = (Timestamp) map.get("dArriveDate");
|
||||
|
||||
boolean modified = false;
|
||||
|
||||
holder.debug("条目:" + title + " x " + amount);
|
||||
if (updateInventory(item::getInventory, item::setInventory, inventoryCode, holder, "商品")) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!Objects.equals(item.getRefId(), refId)) {
|
||||
item.setRefId(refId);
|
||||
holder.info("RefId修改为: " + refId);
|
||||
modified = true;
|
||||
}
|
||||
if (!NumberUtils.equals(item.getExclusiveTaxPrice(), exclusiveTaxPrice)) {
|
||||
item.setExclusiveTaxPrice(exclusiveTaxPrice);
|
||||
holder.info("不含税单价修改为: " + exclusiveTaxPrice);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!NumberUtils.equals(item.getPrice(), taxPrice.doubleValue())) {
|
||||
item.setPrice(taxPrice.doubleValue());
|
||||
holder.info("含税单价修改为: " + taxPrice.doubleValue());
|
||||
modified = true;
|
||||
}
|
||||
if (!NumberUtils.equals(item.getTaxRate(), taxRate.doubleValue())) {
|
||||
item.setTaxRate(taxRate.doubleValue());
|
||||
holder.info("税率修改为: " + taxRate);
|
||||
modified = true;
|
||||
}
|
||||
if (!NumberUtils.equals(item.getQuantity(), quantity)) {
|
||||
item.setQuantity(quantity);
|
||||
holder.info("数量修改为: " + quantity);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (updateLocalDate(item::getArriveDate, item::setArriveDate, (Timestamp) map.get("dArriveDate"), holder, "开始日期")) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!Objects.equals(item.getDescription(), contractCode)) {
|
||||
item.setDescription(contractCode);
|
||||
holder.info("描述修改为: " + contractCode);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
return modified;
|
||||
}
|
||||
|
||||
boolean updateInventory(Supplier<Inventory> getter, Consumer<Inventory> setter, String inventoryCode, MessageHolder holder, String topic) {
|
||||
return getInventoryCtx().syncInventoryDetailByCode(getter, setter, inventoryCode, holder, topic);
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8.ctx;
|
||||
|
||||
import com.ecep.contract.manager.ds.contract.model.PurchaseSettlementVoucher;
|
||||
import com.ecep.contract.manager.ds.contract.model.PurchaseSettlementVoucherItem;
|
||||
import com.ecep.contract.manager.ds.other.model.Inventory;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class PurchaseSettlementVoucherCtx extends AbstractYongYouU8Ctx {
|
||||
InventoryCtx inventoryCtx;
|
||||
|
||||
InventoryCtx getInventoryCtx() {
|
||||
if (inventoryCtx == null) {
|
||||
inventoryCtx = new InventoryCtx();
|
||||
inventoryCtx.from(this);
|
||||
}
|
||||
return inventoryCtx;
|
||||
}
|
||||
|
||||
|
||||
private boolean applyPurchaseSettlementVoucherDetail(PurchaseSettlementVoucher voucher, Map<String, Object> map, MessageHolder holder) {
|
||||
String code = (String) map.get("cSVCode");
|
||||
String vendorCode = (String) map.get("cVenCode");
|
||||
String personCode = (String) map.get("cPersonCode");
|
||||
double taxRate = (double) map.get("iTaxRate");
|
||||
String maker = (String) map.get("cMaker");
|
||||
Timestamp date = (Timestamp) map.get("dSVDate");
|
||||
|
||||
String description = (String) map.get("cSVMemo");
|
||||
boolean modified = false;
|
||||
if (updateText(voucher::getCode, voucher::setCode, code, holder, "编号:")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateCompanyByVendorCode(voucher::getCompany, voucher::setCompany, vendorCode, holder, "供应商")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateEmployeeByCode(voucher::getEmployee, voucher::setEmployee, personCode, holder, "业务员")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateEmployeeByName(voucher::getMaker, voucher::setMaker, maker, holder, "制单人")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateLocalDate(voucher::getDate, voucher::setDate, date, holder, "日期:")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateAppendText(voucher::getDescription, voucher::setDescription, description, holder, "描述")) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
return modified;
|
||||
}
|
||||
|
||||
|
||||
private boolean applyPurchaseSettlementVoucherItemDetail(PurchaseSettlementVoucherItem item, Map<String, Object> map, MessageHolder holder) {
|
||||
String inventoryCode = (String) map.get("cInvCode");
|
||||
String pivCode = (String) map.get("cPIVCode");
|
||||
String accountant = (String) map.get("cbAccounter");
|
||||
Integer rdsID = (Integer) map.get("iRdsID");
|
||||
double quantity = (double) map.get("iPBVQuantity");
|
||||
String description = (String) map.get("cbMemo");
|
||||
boolean modified = false;
|
||||
if (updateInventory(item::getInventory, item::setInventory, inventoryCode, holder, "商品")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateEmployeeByName(item::getAccountant, item::setAccountant, accountant, holder, "会计师")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateNumber(item::getQuantity, item::setQuantity, quantity, holder, "数量")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateAppendText(item::getDescription, item::setDescription, description, holder, "描述")) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
return modified;
|
||||
}
|
||||
|
||||
boolean updateInventory(Supplier<Inventory> getter, Consumer<Inventory> setter, String inventoryCode, MessageHolder holder, String topic) {
|
||||
return getInventoryCtx().syncInventoryDetailByCode(getter, setter, inventoryCode, holder, topic);
|
||||
}
|
||||
}
|
||||
@@ -1,363 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8.ctx;
|
||||
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.cloud.u8.YongYouU8Service;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.contract.model.Contract;
|
||||
import com.ecep.contract.manager.ds.contract.model.SalesBillVoucher;
|
||||
import com.ecep.contract.manager.ds.contract.model.SalesBillVoucherItem;
|
||||
import com.ecep.contract.manager.ds.contract.model.SalesOrder;
|
||||
import com.ecep.contract.manager.ds.contract.service.ContractService;
|
||||
import com.ecep.contract.manager.ds.contract.service.SaleOrdersService;
|
||||
import com.ecep.contract.manager.ds.contract.service.SalesBillVoucherService;
|
||||
import com.ecep.contract.manager.ds.customer.model.CompanyCustomer;
|
||||
import com.ecep.contract.manager.ds.customer.model.CompanyCustomerEntity;
|
||||
import com.ecep.contract.manager.ds.other.model.Inventory;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import com.ecep.contract.manager.util.NumberUtils;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.ecep.contract.manager.SpringApp.getBean;
|
||||
|
||||
public class SalesBillVoucherCtx extends AbstractYongYouU8Ctx {
|
||||
@Setter
|
||||
private ContractService contractService;
|
||||
@Setter
|
||||
private SaleOrdersService saleOrdersService;
|
||||
@Setter
|
||||
private SalesBillVoucherService salesBillVoucherService;
|
||||
|
||||
InventoryCtx inventoryCtx;
|
||||
|
||||
ContractService getContractService() {
|
||||
if (contractService == null) {
|
||||
contractService = getBean(ContractService.class);
|
||||
}
|
||||
return contractService;
|
||||
}
|
||||
|
||||
SaleOrdersService getSaleOrdersService() {
|
||||
if (saleOrdersService == null) {
|
||||
saleOrdersService = getBean(SaleOrdersService.class);
|
||||
}
|
||||
return saleOrdersService;
|
||||
}
|
||||
|
||||
SalesBillVoucherService getSalesBillVoucherService() {
|
||||
if (salesBillVoucherService == null) {
|
||||
salesBillVoucherService = SpringApp.getBean(SalesBillVoucherService.class);
|
||||
}
|
||||
return salesBillVoucherService;
|
||||
}
|
||||
|
||||
InventoryCtx getInventoryCtx() {
|
||||
if (inventoryCtx == null) {
|
||||
inventoryCtx = new InventoryCtx();
|
||||
inventoryCtx.from(this);
|
||||
}
|
||||
return inventoryCtx;
|
||||
}
|
||||
|
||||
public void syncByCompany(Company company, MessageHolder holder) {
|
||||
|
||||
List<SalesBillVoucher> vouchers = salesBillVoucherService.findAll((root, q, cb) -> {
|
||||
return cb.equal(root.get("company"), company);
|
||||
}, Sort.unsorted());
|
||||
holder.debug("查找到 " + vouchers.size() + " 条专用发票记录在数据库中");
|
||||
Map<Integer, SalesBillVoucher> voucherMap = vouchers.stream().collect(Collectors.toMap(SalesBillVoucher::getRefId, item -> item));
|
||||
|
||||
CompanyCustomer customer = getCompanyCustomerService().findByCompany(company);
|
||||
if (customer != null) {
|
||||
List<CompanyCustomerEntity> entities = getCompanyCustomerEntityService().findAllByCustomer(customer);
|
||||
for (CompanyCustomerEntity entity : entities) {
|
||||
// 查询 U8 数据库
|
||||
List<Map<String, Object>> ds = repository.findAllSalesBillVoucherByCustomerCode(entity.getCode());
|
||||
holder.debug("查找" + entity.getCode() + "到 " + ds.size() + " 条专用发票记录在 " + YongYouU8Service.NAME);
|
||||
|
||||
for (Map<String, Object> map : ds) {
|
||||
Integer sbvid = (Integer) map.get("SBVID");
|
||||
if (sbvid == 0) {
|
||||
holder.warn("跳过无效专用发票记录:缺少 SBVID");
|
||||
continue;
|
||||
}
|
||||
SalesBillVoucher voucher = voucherMap.get(sbvid);
|
||||
boolean voucherModified = false;
|
||||
if (voucher == null) {
|
||||
voucher = new SalesBillVoucher();
|
||||
voucher.setCompany(company);
|
||||
voucher.setRefId(sbvid);
|
||||
voucherMap.put(sbvid, voucher);
|
||||
voucherModified = true;
|
||||
|
||||
holder.info("新增专用发票记录 #" + sbvid);
|
||||
}
|
||||
if (applySalesBillVoucherDetail(voucher, map, holder)) {
|
||||
voucherModified = true;
|
||||
}
|
||||
|
||||
if (voucherModified) {
|
||||
voucher = salesBillVoucherService.save(voucher);
|
||||
voucherMap.put(sbvid, voucher);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<SalesBillVoucherItem> items = salesBillVoucherService.findAllItems((root, q, cb) -> {
|
||||
return cb.equal(root.get("voucher").get("company"), company);
|
||||
}, Sort.unsorted());
|
||||
|
||||
// 按 order 分组
|
||||
Map<SalesBillVoucher, Map<Integer, SalesBillVoucherItem>> itemMap = items.stream().collect(Collectors.groupingBy(SalesBillVoucherItem::getVoucher,
|
||||
Collectors.toMap(SalesBillVoucherItem::getRefId, item -> item)));
|
||||
for (SalesBillVoucher voucher : voucherMap.values()) {
|
||||
|
||||
// 查询 U8 数据库
|
||||
List<Map<String, Object>> ds = repository.findAllSalesBillVoucherItemBySBVID(voucher.getRefId());
|
||||
holder.debug("专用发票#" + voucher.getRefId() + "查找到 " + ds.size() + "条条目记录在 " + YongYouU8Service.NAME);
|
||||
Map<Integer, SalesBillVoucherItem> subItemMap = itemMap.computeIfAbsent(voucher, k -> new HashMap<>());
|
||||
for (Map<String, Object> map : ds) {
|
||||
Integer refId = (Integer) map.get("ID");
|
||||
if (refId == 0) {
|
||||
holder.warn("跳过无效专用发票记录:缺少 ID");
|
||||
continue;
|
||||
}
|
||||
SalesBillVoucherItem item = subItemMap.remove(refId);
|
||||
boolean itemModified = false;
|
||||
if (item == null) {
|
||||
item = new SalesBillVoucherItem();
|
||||
item.setVoucher(voucher);
|
||||
item.setRefId(refId);
|
||||
itemModified = true;
|
||||
|
||||
holder.info("新增专用发票条目 #" + refId);
|
||||
}
|
||||
MessageHolder subHolder = holder.sub("---| ");
|
||||
if (applySalesBillVoucherItemDetail(item, map, subHolder)) {
|
||||
itemModified = true;
|
||||
}
|
||||
if (itemModified) {
|
||||
item = salesBillVoucherService.save(item);
|
||||
}
|
||||
}
|
||||
for (SalesBillVoucherItem item : subItemMap.values()) {
|
||||
holder.info("删除无效专用发票条目");
|
||||
salesBillVoucherService.delete(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void syncBySalesOrder(SalesOrder order, MessageHolder holder) {
|
||||
SalesBillVoucherService voucherService = getSalesBillVoucherService();
|
||||
List<SalesBillVoucher> vouchers = voucherService.findAll((root, q, cb) -> {
|
||||
return cb.equal(root.get("order"), order);
|
||||
}, Sort.unsorted());
|
||||
holder.debug("查找到 " + vouchers.size() + " 条专用发票记录在数据库中");
|
||||
Map<Integer, SalesBillVoucher> voucherMap = vouchers.stream().collect(Collectors.toMap(SalesBillVoucher::getRefId, item -> item));
|
||||
{
|
||||
// 查询 U8 数据库
|
||||
List<Map<String, Object>> ds = repository.findAllSalesBillVoucherBySalesOrderCode(order.getCode());
|
||||
holder.debug("查找" + order.getCode() + "到 " + ds.size() + " 条专用发票记录在 " + YongYouU8Service.NAME);
|
||||
|
||||
for (Map<String, Object> map : ds) {
|
||||
Integer sbvid = (Integer) map.get("SBVID");
|
||||
if (sbvid == 0) {
|
||||
holder.warn("跳过无效专用发票记录:缺少 SBVID");
|
||||
continue;
|
||||
}
|
||||
SalesBillVoucher voucher = voucherMap.get(sbvid);
|
||||
boolean voucherModified = false;
|
||||
if (voucher == null) {
|
||||
voucher = new SalesBillVoucher();
|
||||
|
||||
Contract contract = order.getContract();
|
||||
if (!Hibernate.isInitialized(contract)) {
|
||||
contract = getContractService().findById(contract.getId());
|
||||
}
|
||||
voucher.setCompany(contract.getCompany());
|
||||
voucher.setRefId(sbvid);
|
||||
voucherMap.put(sbvid, voucher);
|
||||
voucherModified = true;
|
||||
|
||||
holder.info("新增专用发票记录 #" + sbvid);
|
||||
}
|
||||
if (applySalesBillVoucherDetail(voucher, map, holder)) {
|
||||
voucherModified = true;
|
||||
}
|
||||
|
||||
if (voucherModified) {
|
||||
voucher = voucherService.save(voucher);
|
||||
voucherMap.put(sbvid, voucher);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<SalesBillVoucherItem> items = voucherService.findAllItems((root, q, cb) -> {
|
||||
return cb.equal(root.get("voucher").get("order"), order);
|
||||
}, Sort.unsorted());
|
||||
|
||||
// 按 order 分组
|
||||
Map<SalesBillVoucher, Map<Integer, SalesBillVoucherItem>> itemMap = items.stream().collect(Collectors.groupingBy(SalesBillVoucherItem::getVoucher,
|
||||
Collectors.toMap(SalesBillVoucherItem::getRefId, item -> item)));
|
||||
for (SalesBillVoucher voucher : voucherMap.values()) {
|
||||
|
||||
// 查询 U8 数据库
|
||||
List<Map<String, Object>> ds = repository.findAllSalesBillVoucherItemBySBVID(voucher.getRefId());
|
||||
holder.debug("专用发票#" + voucher.getRefId() + "查找到 " + ds.size() + "条条目记录在 " + YongYouU8Service.NAME);
|
||||
Map<Integer, SalesBillVoucherItem> subItemMap = itemMap.computeIfAbsent(voucher, k -> new HashMap<>());
|
||||
for (Map<String, Object> map : ds) {
|
||||
Integer refId = (Integer) map.get("AutoID");
|
||||
if (refId == 0) {
|
||||
holder.warn("跳过无效专用发票记录:缺少 AutoID");
|
||||
continue;
|
||||
}
|
||||
SalesBillVoucherItem item = subItemMap.remove(refId);
|
||||
boolean itemModified = false;
|
||||
if (item == null) {
|
||||
item = new SalesBillVoucherItem();
|
||||
item.setVoucher(voucher);
|
||||
item.setRefId(refId);
|
||||
itemModified = true;
|
||||
|
||||
holder.info("新增专用发票条目 #" + refId);
|
||||
}
|
||||
MessageHolder subHolder = holder.sub("---| ");
|
||||
if (applySalesBillVoucherItemDetail(item, map, subHolder)) {
|
||||
itemModified = true;
|
||||
}
|
||||
if (itemModified) {
|
||||
item = voucherService.save(item);
|
||||
}
|
||||
}
|
||||
for (SalesBillVoucherItem item : subItemMap.values()) {
|
||||
holder.info("删除无效专用发票条目");
|
||||
voucherService.delete(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean applySalesBillVoucherDetail(SalesBillVoucher voucher, Map<String, Object> map, MessageHolder holder) {
|
||||
String code = String.valueOf(map.get("SBVID"));
|
||||
String customerCode = (String) map.get("cCusCode");
|
||||
String salesOrderCode = (String) map.get("cSOCode");
|
||||
String personCode = (String) map.get("cPersonCode");
|
||||
String inCode = (String) map.get("cDLCode");
|
||||
Timestamp billDate = (Timestamp) map.get("dDate");
|
||||
|
||||
String maker = (String) map.get("cMaker");
|
||||
String checker = (String) map.get("cChecker");
|
||||
String modifier = (String) map.get("cmodifier");
|
||||
String verifier = (String) map.get("cVerifier");
|
||||
Timestamp makeTime = (Timestamp) map.get("cmaketime");
|
||||
Timestamp verifyTime = (Timestamp) map.get("dverifysystime");
|
||||
Timestamp modifyTime = (Timestamp) map.get("dmodifysystime");
|
||||
|
||||
String description = (String) map.get("cMemo");
|
||||
|
||||
|
||||
boolean modified = false;
|
||||
|
||||
holder.debug("条目:" + code + " x " + salesOrderCode);
|
||||
if (updateCompanyByCustomerCode(voucher::getCompany, voucher::setCompany, customerCode, holder, "客户")) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
SalesOrder salesOrder = null;
|
||||
if (StringUtils.hasText(salesOrderCode)) {
|
||||
salesOrder = getSaleOrdersService().findByCode(salesOrderCode);
|
||||
}
|
||||
if (salesOrder == null) {
|
||||
voucher.setOrder(null);
|
||||
holder.warn("无效销售订单:" + salesOrderCode);
|
||||
modified = true;
|
||||
} else {
|
||||
if (!Objects.equals(voucher.getOrder(), salesOrder)) {
|
||||
voucher.setOrder(salesOrder);
|
||||
holder.info("销售订单修改为: " + salesOrder.getCode());
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
if (updateEmployeeByCode(voucher::getEmployee, voucher::setEmployee, personCode, holder, "业务员")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateEmployeeByName(voucher::getMaker, voucher::setMaker, maker, holder, "制单人")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateEmployeeByName(voucher::getVerifier, voucher::setVerifier, verifier, holder, "审核人")) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (updateLocalDateTime(voucher::getMakerDate, voucher::setMakerDate, makeTime, holder, "制单时间")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateLocalDateTime(voucher::getVerifierDate, voucher::setVerifierDate, verifyTime, holder, "审核时间")) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!Objects.equals(voucher.getDescription(), description)) {
|
||||
voucher.setDescription(description);
|
||||
holder.info("描述修改为: " + description);
|
||||
modified = true;
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
|
||||
private boolean applySalesBillVoucherItemDetail(SalesBillVoucherItem item, Map<String, Object> map, MessageHolder holder) {
|
||||
String code = String.valueOf(map.get("ID"));
|
||||
String inventoryCode = (String) map.get("cInvCode");
|
||||
String contractCode = (String) map.get("ContractCode");
|
||||
|
||||
String title = (String) map.get("cInvCode");
|
||||
double quantity = (double) map.get("iQuantity");
|
||||
double taxRate = (double) map.get("iTaxRate");
|
||||
double taxPrice = (double) map.get("iTaxUnitPrice");
|
||||
BigDecimal amount = (BigDecimal) map.get("iSum");
|
||||
|
||||
|
||||
Timestamp signDate = (Timestamp) map.get("dSignDate");
|
||||
|
||||
boolean modified = false;
|
||||
|
||||
holder.debug("条目:" + title + " x " + amount);
|
||||
|
||||
if (updateInventory(item::getInventory, item::setInventory, inventoryCode, holder, "商品")) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!NumberUtils.equals(item.getPrice(), taxPrice)) {
|
||||
item.setPrice(taxPrice);
|
||||
holder.info("含税单价修改为: " + taxPrice);
|
||||
modified = true;
|
||||
}
|
||||
if (!NumberUtils.equals(item.getQuantity(), quantity)) {
|
||||
item.setQuantity(quantity);
|
||||
holder.info("数量修改为: " + quantity);
|
||||
modified = true;
|
||||
}
|
||||
if (!Objects.equals(item.getDescription(), contractCode)) {
|
||||
item.setDescription(contractCode);
|
||||
holder.info("描述修改为: " + contractCode);
|
||||
modified = true;
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
boolean updateInventory(Supplier<Inventory> getter, Consumer<Inventory> setter, String inventoryCode, MessageHolder holder, String topic) {
|
||||
return getInventoryCtx().syncInventoryDetailByCode(getter, setter, inventoryCode, holder, topic);
|
||||
}
|
||||
}
|
||||
@@ -1,257 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8.ctx;
|
||||
|
||||
import com.ecep.contract.manager.cloud.u8.YongYouU8Service;
|
||||
import com.ecep.contract.manager.ds.contract.model.Contract;
|
||||
import com.ecep.contract.manager.ds.contract.model.SalesOrder;
|
||||
import com.ecep.contract.manager.ds.contract.model.SalesOrderItem;
|
||||
import com.ecep.contract.manager.ds.contract.service.SaleOrdersService;
|
||||
import com.ecep.contract.manager.ds.contract.service.SalesOrderItemService;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import com.ecep.contract.manager.util.NumberUtils;
|
||||
import lombok.Setter;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.ecep.contract.manager.SpringApp.getBean;
|
||||
|
||||
public class SalesOrderCtx extends AbstractYongYouU8Ctx {
|
||||
|
||||
@Setter
|
||||
private SaleOrdersService saleOrdersService;
|
||||
@Setter
|
||||
private SalesOrderItemService orderItemService;
|
||||
|
||||
SaleOrdersService getSaleOrdersService() {
|
||||
if (saleOrdersService == null) {
|
||||
saleOrdersService = getBean(SaleOrdersService.class);
|
||||
}
|
||||
return saleOrdersService;
|
||||
}
|
||||
|
||||
SalesOrderItemService getOrderItemService() {
|
||||
if (orderItemService == null) {
|
||||
orderItemService = getBean(SalesOrderItemService.class);
|
||||
}
|
||||
return orderItemService;
|
||||
}
|
||||
|
||||
|
||||
public List<SalesOrder> syncByContract(Contract contract, MessageHolder holder) {
|
||||
SaleOrdersService saleOrdersService = getSaleOrdersService();
|
||||
SalesOrderItemService orderItemService = getOrderItemService();
|
||||
|
||||
List<SalesOrder> orders = saleOrdersService.findAll((root, q, cb) -> {
|
||||
return cb.equal(root.get("contract"), contract);
|
||||
}, Sort.unsorted());
|
||||
holder.debug("查找到 " + orders.size() + " 条销售订单记录在数据库中");
|
||||
Map<String, SalesOrder> ordersMap = orders.stream().collect(Collectors.toMap(SalesOrder::getCode, item -> item));
|
||||
|
||||
List<SalesOrderItem> items = orderItemService.findAll((root, q, cb) -> {
|
||||
return cb.equal(root.get("order").get("contract"), contract);
|
||||
}, Sort.unsorted());
|
||||
|
||||
// 按 order 分组
|
||||
Map<SalesOrder, Map<String, SalesOrderItem>> itemMap = items.stream().collect(Collectors.groupingBy(SalesOrderItem::getOrder,
|
||||
Collectors.toMap(SalesOrderItem::getCode, item -> item)));
|
||||
|
||||
// 查询 U8 数据库
|
||||
List<Map<String, Object>> ds = repository.findAllSalesOrderItemByContractCode(contract.getCode());
|
||||
holder.debug("查找到 " + ds.size() + " 条销售订单条目记录在 " + YongYouU8Service.NAME);
|
||||
|
||||
Map<SalesOrder, List<SalesOrderItem>> updateMap = new HashMap<>();
|
||||
for (Map<String, Object> map : ds) {
|
||||
String orderCode = Optional.ofNullable(map.get("cSOCode")).map(Object::toString).orElse("");
|
||||
if (orderCode.isEmpty()) {
|
||||
holder.warn("跳过无效销售订单记录:缺少 cSOCode");
|
||||
continue;
|
||||
}
|
||||
SalesOrder order = ordersMap.get(orderCode);
|
||||
if (order == null) {
|
||||
order = new SalesOrder();
|
||||
order.setContract(contract);
|
||||
order.setCode(orderCode);
|
||||
|
||||
order = saleOrdersService.save(order);
|
||||
ordersMap.put(orderCode, order);
|
||||
holder.info("新增销售订单 #" + orderCode);
|
||||
}
|
||||
}
|
||||
for (Map<String, Object> map : ds) {
|
||||
// holder.debug("条目:" + map.toString());
|
||||
String orderCode = Optional.ofNullable(map.get("cSOCode")).map(Object::toString).orElse("");
|
||||
if (orderCode.isEmpty()) {
|
||||
holder.warn("跳过无效销售订单记录:缺少 cSOCode");
|
||||
continue;
|
||||
}
|
||||
SalesOrder order = ordersMap.get(orderCode);
|
||||
|
||||
boolean itemModified = false;
|
||||
List<SalesOrderItem> updates = updateMap.computeIfAbsent(order, k -> new ArrayList<>());
|
||||
|
||||
// 获取条目标识并处理 null
|
||||
String refId = Optional.ofNullable(map.get("iSOsID")).map(Object::toString).orElse("");
|
||||
if (refId.isEmpty()) {
|
||||
holder.warn("跳过条目:订单 " + orderCode + " 缺少 iSOsID");
|
||||
continue;
|
||||
}
|
||||
Map<String, SalesOrderItem> subItemMap = itemMap.get(order);
|
||||
SalesOrderItem item = null;
|
||||
if (subItemMap != null) {
|
||||
item = subItemMap.remove(refId);
|
||||
}
|
||||
|
||||
if (item == null) {
|
||||
item = new SalesOrderItem();
|
||||
item.setOrder(order);
|
||||
item.setCode(refId);
|
||||
itemModified = true;
|
||||
|
||||
holder.info("新增销售订单条目 #" + refId);
|
||||
}
|
||||
MessageHolder subHolder = holder.sub("---| ");
|
||||
if (applySaleOrderItemDetail(item, map, subHolder)) {
|
||||
itemModified = true;
|
||||
}
|
||||
if (itemModified) {
|
||||
item = orderItemService.save(item);
|
||||
}
|
||||
updates.add(item);
|
||||
}
|
||||
|
||||
for (SalesOrder order : updateMap.keySet()) {
|
||||
holder.debug("销售订单 #" + order.getCode());
|
||||
if (applySalesOrderDetail(order, repository.querySalesOrderDetail(order.getCode()), holder)) {
|
||||
saleOrdersService.save(order);
|
||||
}
|
||||
}
|
||||
|
||||
if (!itemMap.isEmpty()) {
|
||||
for (Map<String, SalesOrderItem> subMap : itemMap.values()) {
|
||||
if (!subMap.isEmpty()) {
|
||||
for (SalesOrderItem item : subMap.values()) {
|
||||
holder.info("删除销售订单条目");
|
||||
orderItemService.delete(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (SalesOrder order : updateMap.keySet()) {
|
||||
itemMap.remove(order);
|
||||
}
|
||||
if (!itemMap.isEmpty()) {
|
||||
holder.info("剩余 " + itemMap.size() + " 个销售订单条目");
|
||||
}
|
||||
}
|
||||
|
||||
return new ArrayList<>(updateMap.keySet());
|
||||
|
||||
}
|
||||
|
||||
private boolean applySalesOrderDetail(SalesOrder order, Map<String, Object> map, MessageHolder holder) {
|
||||
String code = (String) map.get("cSOCode");
|
||||
|
||||
String cCloser = (String) map.get("cCloser");
|
||||
|
||||
String memo = (String) map.get("cMemo");
|
||||
|
||||
boolean modified = false;
|
||||
|
||||
if (!Objects.equals(order.getCode(), code)) {
|
||||
order.setCode(code);
|
||||
holder.info("订单编号更新为 " + code);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (updateEmployeeByCode(order::getEmployee, order::setEmployee, (String) map.get("cPersonCode"), holder, "业务员")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateEmployeeByName(order::getMaker, order::setMaker, (String) map.get("cMaker"), holder, "制单人")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateEmployeeByName(order::getVerifier, order::setVerifier, (String) map.get("cVerifier"), holder, "审核人")) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (updateLocalDate(order::getMakerDate, order::setMakerDate, (Timestamp) map.get("dcreatesystime"), holder, "制单日期")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateLocalDate(order::getVerifierDate, order::setVerifierDate, (Timestamp) map.get("dverifysystime"), holder, "审核日期")) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!Objects.equals(order.getDescription(), memo)) {
|
||||
order.setDescription(memo);
|
||||
holder.info("描述修改为: " + memo);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
return modified;
|
||||
}
|
||||
|
||||
|
||||
private boolean applySaleOrderItemDetail(SalesOrderItem item, Map<String, Object> map, MessageHolder holder) {
|
||||
String code = String.valueOf(map.get("iSOsID"));
|
||||
String spec = (String) map.get("cInvName");
|
||||
String title = (String) map.get("cInvName");
|
||||
double quantity = (double) map.get("iQuantity");
|
||||
double taxRate = (double) map.get("iTaxRate");
|
||||
double taxPrice = (double) map.get("iTaxUnitPrice");
|
||||
double exclusiveTaxPrice = (double) map.get("iUnitPrice");
|
||||
BigDecimal amount = (BigDecimal) map.get("iSum");
|
||||
|
||||
String memo = (String) map.get("cMemo");
|
||||
|
||||
boolean modified = false;
|
||||
|
||||
holder.debug("条目:" + title + " x " + amount);
|
||||
|
||||
|
||||
if (!Objects.equals(item.getCode(), code)) {
|
||||
item.setCode(code);
|
||||
holder.info("代码修改为: " + code);
|
||||
modified = true;
|
||||
}
|
||||
if (!Objects.equals(item.getName(), title)) {
|
||||
item.setName(title);
|
||||
holder.info("名称修改为: " + title);
|
||||
modified = true;
|
||||
}
|
||||
if (!NumberUtils.equals(item.getExclusiveTaxPrice(), exclusiveTaxPrice)) {
|
||||
item.setExclusiveTaxPrice(exclusiveTaxPrice);
|
||||
holder.info("不含税单价修改为: " + exclusiveTaxPrice);
|
||||
modified = true;
|
||||
}
|
||||
if (!NumberUtils.equals(item.getPrice(), taxPrice)) {
|
||||
item.setPrice(taxPrice);
|
||||
holder.info("含税单价修改为: " + taxPrice);
|
||||
modified = true;
|
||||
}
|
||||
if (!NumberUtils.equals(item.getTaxRate(), taxRate)) {
|
||||
item.setTaxRate(taxRate);
|
||||
holder.info("税率修改为: " + taxRate);
|
||||
modified = true;
|
||||
}
|
||||
if (!NumberUtils.equals(item.getQuantity(), quantity)) {
|
||||
item.setQuantity(quantity);
|
||||
holder.info("数量修改为: " + quantity);
|
||||
modified = true;
|
||||
}
|
||||
if (updateLocalDate(item::getStartDate, item::setStartDate, (Timestamp) map.get("dPreDate"), holder, "开始日期")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateLocalDate(item::getEndDate, item::setEndDate, (Timestamp) map.get("dPreMoDate"), holder, "结束日期")) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (!Objects.equals(item.getDescription(), memo)) {
|
||||
item.setDescription(memo);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
return modified;
|
||||
}
|
||||
}
|
||||
@@ -1,325 +0,0 @@
|
||||
package com.ecep.contract.manager.cloud.u8.ctx;
|
||||
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.cloud.old.OldVersionService;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.manager.ds.vendor.model.CompanyVendor;
|
||||
import com.ecep.contract.manager.ds.vendor.model.CompanyVendorEntity;
|
||||
import com.ecep.contract.manager.ds.vendor.model.VendorCatalog;
|
||||
import com.ecep.contract.manager.ds.vendor.service.CompanyVendorEntityService;
|
||||
import com.ecep.contract.manager.ds.vendor.service.CompanyVendorService;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class VendorCtx extends AbstractYongYouU8Ctx {
|
||||
private static final String AUTO_CREATE_VENDOR_AFTER = "cloud.u8.auto-create-vendor-after";
|
||||
@Setter
|
||||
private CompanyVendorService companyVendorService;
|
||||
@Setter
|
||||
private CompanyCtx companyCtx;
|
||||
@Setter
|
||||
private ContractCtx contractCtx;
|
||||
@Setter
|
||||
private CompanyBankAccountCtx companyBankAccountCtx;
|
||||
|
||||
public CompanyCtx getCompanyCtx() {
|
||||
if (companyCtx == null) {
|
||||
companyCtx = new CompanyCtx();
|
||||
companyCtx.from(this);
|
||||
}
|
||||
return companyCtx;
|
||||
}
|
||||
|
||||
ContractCtx getContractCtx() {
|
||||
if (contractCtx == null) {
|
||||
contractCtx = new ContractCtx();
|
||||
contractCtx.from(this);
|
||||
}
|
||||
return contractCtx;
|
||||
}
|
||||
|
||||
CompanyBankAccountCtx getCompanyBankAccountCtx() {
|
||||
if (companyBankAccountCtx == null) {
|
||||
companyBankAccountCtx = new CompanyBankAccountCtx();
|
||||
companyBankAccountCtx.from(this);
|
||||
}
|
||||
return companyBankAccountCtx;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新供应商相关项(相关项是 U8 系统中的 Vendor 表数据,因为同一个公司有多个相关项,因此需要一个一对多的关系来处理)详情
|
||||
*
|
||||
* @param item 供应商相关项
|
||||
* @param unitCode 供应商相关项编码
|
||||
* @param holder 消息
|
||||
*/
|
||||
public CompanyVendorEntity updateVendorEntityDetailByCode(CompanyVendorEntity item, String unitCode, MessageHolder holder) {
|
||||
if (applyEntityDetail(item, repository.findVendorByVendCode(unitCode), holder)) {
|
||||
item = save(item);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public boolean applyEntityDetail(CompanyVendorEntity item, Map<String, Object> map, MessageHolder holder) {
|
||||
if (map == null || map.isEmpty()) {
|
||||
holder.warn("Vendor 中未检索到供应商数据");
|
||||
return false;
|
||||
}
|
||||
String name = (String) map.get("cVenName");
|
||||
String abbName = (String) map.get("cVenAbbName");
|
||||
String venCode = (String) map.get("cVenCode");
|
||||
String classCode = (String) map.get("cVCCode");
|
||||
|
||||
String createPerson = (String) map.get("cCreatePerson");
|
||||
String modifyPerson = (String) map.get("cModifyPerson");
|
||||
java.sql.Date devDate = (java.sql.Date) map.get("devDate");
|
||||
java.sql.Timestamp modifyDate = (java.sql.Timestamp) map.get("dModifyDate");
|
||||
java.sql.Timestamp createDatetime = (java.sql.Timestamp) map.get("dVenCreateDatetime");
|
||||
|
||||
String bank = (String) map.get("cVenBank");
|
||||
String bankAccount = (String) map.get("cVenAccount");
|
||||
String address = (String) map.get("cVenAddress");
|
||||
String phone = (String) map.get("cVenPhone");
|
||||
String person = (String) map.get("cVenPerson");
|
||||
|
||||
|
||||
boolean modified = false;
|
||||
if (updateText(item::getName, item::setName, name, holder, "名称")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateText(item::getAbbName, item::setAbbName, abbName, holder, "简称")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateText(item::getCode, item::setCode, venCode, holder, "供应商编号")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateVendorCatalog(item::getCatalog, item::setCatalog, classCode, holder, "分类")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateEmployeeByName(item::getCreator, item::setCreator, createPerson, holder, "创建人")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateEmployeeByName(item::getModifier, item::setModifier, modifyPerson, holder, "修改人")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateLocalDate(item::getDevelopDate, item::setDevelopDate, devDate, holder, "开发日期")) {
|
||||
modified = true;
|
||||
}
|
||||
if (updateLocalDate(item::getModifyDate, item::setModifyDate, modifyDate, holder, "修改日期")) {
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (modified) {
|
||||
LocalDate today = LocalDate.now();
|
||||
if (item.getUpdatedDate() == null || item.getUpdatedDate().isBefore(today)) {
|
||||
item.setUpdatedDate(today);
|
||||
holder.info("更新日期更新为 " + today);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CompanyVendor vendor = item.getVendor();
|
||||
if (vendor == null) {
|
||||
// 如果没有关联供应商,则根据供应商名称或别名查找公司
|
||||
Company company = findOrCreateCompanyByVendorEntity(item, holder);
|
||||
if (company != null) {
|
||||
vendor = getCompanyVendorService().findByCompany(company);
|
||||
if (vendor == null) {
|
||||
vendor = createVendorByVendorEntity(item, holder);
|
||||
if (vendor != null) {
|
||||
vendor.setCompany(company);
|
||||
vendor = getCompanyVendorService().save(vendor);
|
||||
}
|
||||
}
|
||||
if (vendor != null) {
|
||||
item.setVendor(vendor);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (vendor != null) {
|
||||
if (!Hibernate.isInitialized(vendor)) {
|
||||
vendor = getCompanyVendorService().findById(vendor.getId());
|
||||
}
|
||||
Company company = vendor.getCompany();
|
||||
if (company != null) {
|
||||
getCompanyBankAccountCtx().updateBankAccount(company, bank, bankAccount, holder.sub(item.getName()));
|
||||
}
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
private boolean updateVendorCatalog(Supplier<VendorCatalog> getter, Consumer<VendorCatalog> setter, String catalogCode, MessageHolder holder, String topic) {
|
||||
VendorCatalog catalog = null;
|
||||
if (StringUtils.hasText(catalogCode)) {
|
||||
catalog = getCompanyVendorService().findCatalogByCode(catalogCode);
|
||||
}
|
||||
if (catalog == null) {
|
||||
setter.accept(null);
|
||||
holder.warn("无效" + topic + ":" + catalogCode);
|
||||
return true;
|
||||
} else {
|
||||
if (!Objects.equals(getter.get(), catalog)) {
|
||||
if (!Hibernate.isInitialized(catalog)) {
|
||||
catalog = getCompanyVendorService().findCatalogByCode(catalogCode);
|
||||
}
|
||||
setter.accept(catalog);
|
||||
holder.info(topic + "修改为: " + catalog.getName());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步供应商
|
||||
*
|
||||
* @param company 要同步的供应商企业
|
||||
* @param holder 状态输出
|
||||
* @return 是否更新了供应商信息
|
||||
*/
|
||||
public boolean syncVendor(Company company, MessageHolder holder) {
|
||||
CompanyVendor companyVendor = getCompanyVendorService().findByCompany(company);
|
||||
if (companyVendor == null) {
|
||||
holder.warn("供应商未创建, 如需要请手动创建.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检索相关项
|
||||
List<CompanyVendorEntity> entities = getCompanyVendorEntityService().findAllByVendor(companyVendor);
|
||||
if (entities.isEmpty()) {
|
||||
holder.error("供应商关联任何相关项");
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean updated = false;
|
||||
boolean companyModified = false;
|
||||
|
||||
// 更新相关项
|
||||
for (CompanyVendorEntity entity : entities) {
|
||||
if (!StringUtils.hasText(entity.getCode())) {
|
||||
holder.warn("相关项:" + entity.getCode() + " 无效,跳过");
|
||||
continue;
|
||||
}
|
||||
if (applyEntityDetail(entity, repository.findVendorByVendCode(entity.getCode()), holder)) {
|
||||
entity = getCompanyVendorEntityService().save(entity);
|
||||
}
|
||||
if (updateCompanyNameAndAbbNameByVendorEntity(company, entity, holder)) {
|
||||
companyModified = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (companyModified) {
|
||||
company = getCompanyService().save(company);
|
||||
updated = true;
|
||||
}
|
||||
|
||||
// 更新供应商的开发日期
|
||||
if (updateVendorDevelopDate(companyVendor, entities, holder)) {
|
||||
companyVendor = getCompanyVendorService().save(companyVendor);
|
||||
updated = true;
|
||||
}
|
||||
|
||||
// 同步供应商关联的合同
|
||||
for (CompanyVendorEntity entity : entities) {
|
||||
if (getContractCtx().syncByVendorEntity(companyVendor, entity, holder)) {
|
||||
updated = true;
|
||||
}
|
||||
}
|
||||
return updated;
|
||||
}
|
||||
|
||||
private boolean updateCompanyNameAndAbbNameByVendorEntity(Company company, CompanyVendorEntity entity, MessageHolder holder) {
|
||||
CompanyService companyService = getCompanyService();
|
||||
if (company == null) {
|
||||
return false;
|
||||
}
|
||||
if (!Hibernate.isInitialized(company)) {
|
||||
company = companyService.findById(company.getId());
|
||||
}
|
||||
boolean modified = false;
|
||||
CompanyCtx companyCtx = getCompanyCtx();
|
||||
if (companyCtx.updateCompanyNameIfAbsent(company, entity.getName(), holder)) {
|
||||
modified = true;
|
||||
}
|
||||
if (companyCtx.updateCompanyAbbNameIfAbsent(company, entity.getAbbName(), holder)) {
|
||||
modified = true;
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
private boolean updateVendorDevelopDate(CompanyVendor companyVendor, List<CompanyVendorEntity> entities, MessageHolder holder) {
|
||||
LocalDate developDate = null;
|
||||
for (CompanyVendorEntity entity : entities) {
|
||||
// 取最早的开发日期
|
||||
if (developDate == null || entity.getDevelopDate().isBefore(developDate)) {
|
||||
developDate = entity.getDevelopDate();
|
||||
}
|
||||
}
|
||||
return updateLocalDate(companyVendor::getDevelopDate, companyVendor::setDevelopDate, developDate, holder, "开发日期");
|
||||
}
|
||||
|
||||
public CompanyVendorEntity findOrCreateByCode(String venCode, MessageHolder subHolder) {
|
||||
CompanyVendorEntityService service = getCompanyVendorEntityService();
|
||||
CompanyVendorEntity entity = service.findByCode(venCode);
|
||||
if (entity == null) {
|
||||
entity = new CompanyVendorEntity();
|
||||
entity.setCode(venCode);
|
||||
entity = service.save(entity);
|
||||
subHolder.info("创建供应商相关项: " + venCode);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
private CompanyVendor createVendorByVendorEntity(CompanyVendorEntity entity, MessageHolder holder) {
|
||||
LocalDate developDate = entity.getDevelopDate();
|
||||
if (developDate == null) {
|
||||
holder.warn(entity.getName() + " 没有设置开发日期,跳过");
|
||||
return null;
|
||||
}
|
||||
// 创建发展日期从2023年1月1日后的
|
||||
LocalDate start = LocalDate.of(2023, 1, 1);
|
||||
String autoCreateAfter = getConfService().getString(AUTO_CREATE_VENDOR_AFTER);
|
||||
if (StringUtils.hasText(autoCreateAfter)) {
|
||||
start = LocalDate.parse(autoCreateAfter);
|
||||
}
|
||||
if (developDate.isBefore(start)) {
|
||||
// start 之前的不自动创建
|
||||
holder.warn(entity.getName() + " 的发展日期 " + developDate + " 是 " + start + " 之前的, 按规定不自动创建供应商, 如有需要请手动创建");
|
||||
return null;
|
||||
}
|
||||
|
||||
CompanyVendor companyVendor = new CompanyVendor();
|
||||
int nextId = SpringApp.getBean(OldVersionService.class).newCompanyVendor(entity.getName());
|
||||
companyVendor.setId(nextId);
|
||||
companyVendor.setCatalog(entity.getCatalog());
|
||||
companyVendor.setDevelopDate(developDate);
|
||||
holder.info("新供应商:" + entity.getName() + "分配编号:" + nextId);
|
||||
companyVendor.setCreated(Instant.now());
|
||||
return companyVendor;
|
||||
}
|
||||
|
||||
|
||||
private Company findOrCreateCompanyByVendorEntity(CompanyVendorEntity entity, MessageHolder holder) {
|
||||
String name = entity.getName();
|
||||
String abbName = entity.getAbbName();
|
||||
return getCompanyCtx().findOrCreateByNameOrAbbName(name, abbName, entity.getDevelopDate(), holder);
|
||||
}
|
||||
|
||||
public CompanyVendorEntity save(CompanyVendorEntity entity) {
|
||||
return getCompanyVendorEntityService().save(entity);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package com.ecep.contract.manager.ds;
|
||||
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.data.repository.config.BootstrapMode;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import static com.ecep.contract.manager.AppV2.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Configuration
|
||||
@EnableJpaRepositories(bootstrapMode = BootstrapMode.LAZY)
|
||||
public class DsRepositoriesConfig {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DsRepositoriesConfig.class);
|
||||
|
||||
@Bean
|
||||
// @ConfigurationProperties(prefix = "spring.datasource")
|
||||
@Primary
|
||||
public DataSource dataSource(Environment env) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("SpringApp.dataSource, env:{}", env);
|
||||
}
|
||||
|
||||
String host = env.getProperty("db.server.host", DEFAULT_DB_HOST);
|
||||
String port = env.getProperty("db.server.port", DEFAULT_DB_PORT);
|
||||
String database = env.getProperty("db.server.database", DEFAULT_DB_DATABASE);
|
||||
String username = env.getProperty("db.server.username", DEFAULT_DB_USERNAME);
|
||||
String password = env.getProperty("db.server.password", DEFAULT_DB_PASSWORD);
|
||||
|
||||
String url = "jdbc:mysql://" + host + ":" + port + "/" + database;
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("db server url:{},user:{}", url, username);
|
||||
}
|
||||
|
||||
return DataSourceBuilder.create()
|
||||
.type(HikariDataSource.class)
|
||||
.url(url)
|
||||
.username(username)
|
||||
.password(password)
|
||||
.driverClassName("com.mysql.cj.jdbc.Driver")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Primary
|
||||
@Bean
|
||||
public JdbcTemplate jdbcTemplate(@Qualifier("dataSource") DataSource dataSource) {
|
||||
return new JdbcTemplate(dataSource);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.ecep.contract.manager.ds;
|
||||
|
||||
import jakarta.persistence.AttributeConverter;
|
||||
import jakarta.persistence.Converter;
|
||||
|
||||
import java.time.MonthDay;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
@Converter(autoApply = true)
|
||||
public class MonthDayConverter implements AttributeConverter<MonthDay, String> {
|
||||
|
||||
// 定义日期格式(月-日,两位数)
|
||||
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("MM-dd");
|
||||
|
||||
@Override
|
||||
public String convertToDatabaseColumn(MonthDay attribute) {
|
||||
// 将 MonthDay 转换为数据库存储的字符串(MM-dd)
|
||||
return attribute != null ? attribute.format(FORMATTER) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MonthDay convertToEntityAttribute(String dbData) {
|
||||
// 将数据库字符串(MM-dd)转换为 MonthDay
|
||||
return dbData != null ? MonthDay.parse(dbData, FORMATTER) : null;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package com.ecep.contract.manager.ds;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.repository.ListCrudRepository;
|
||||
|
||||
public interface MyRepository<T, ID> extends ListCrudRepository<T, ID>, JpaSpecificationExecutor<T> {
|
||||
|
||||
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.ecep.contract.manager.ds.company;
|
||||
|
||||
/**
|
||||
* Date : 2024/2/3
|
||||
*/
|
||||
public enum BlackReasonType {
|
||||
/**
|
||||
* 黑名单
|
||||
*/
|
||||
BLACK,
|
||||
/**
|
||||
* 警示名单
|
||||
*/
|
||||
GRAY
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.ecep.contract.manager.ds.company;
|
||||
|
||||
import com.ecep.contract.manager.ds.company.model.CompanyContact;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyContactService;
|
||||
import com.ecep.contract.manager.ds.other.EntityStringConverter;
|
||||
|
||||
public class CompanyContactStringConverter extends EntityStringConverter<CompanyContact> {
|
||||
|
||||
public CompanyContactStringConverter() {
|
||||
|
||||
}
|
||||
|
||||
public CompanyContactStringConverter(CompanyContactService service) {
|
||||
setInitialized(employee -> service.findById(employee.getId()));
|
||||
// setFromString(service::findByName);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.ecep.contract.manager.ds.company;
|
||||
|
||||
/**
|
||||
* 公司文件类型(资质文件)
|
||||
*/
|
||||
public enum CompanyFileType {
|
||||
/**
|
||||
* 普通文件,一般文件
|
||||
*/
|
||||
General,
|
||||
/**
|
||||
* 资信评估
|
||||
*/
|
||||
CreditReport,
|
||||
/**
|
||||
* 营业执照
|
||||
*/
|
||||
BusinessLicense,
|
||||
/**
|
||||
* 资质证书
|
||||
*/
|
||||
QualificationCertificate,
|
||||
/**
|
||||
* 企业信用信息公示报告
|
||||
*/
|
||||
CreditInfoPublicityReport,
|
||||
/**
|
||||
* 操作证
|
||||
*/
|
||||
OperationCertificate,
|
||||
/**
|
||||
* 框架协议
|
||||
*/
|
||||
FrameworkAgreement;
|
||||
}
|
||||
@@ -1,212 +0,0 @@
|
||||
package com.ecep.contract.manager.ds.company;
|
||||
|
||||
import com.ecep.contract.manager.cloud.tyc.CloudTycService;
|
||||
import com.ecep.contract.manager.ds.company.model.CompanyFile;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyFileService;
|
||||
import com.ecep.contract.manager.util.MyDateTimeUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.ecep.contract.manager.ds.company.CompanyFileType.CreditReport;
|
||||
|
||||
public class CompanyFileUtils {
|
||||
|
||||
public final static String PDF = ".pdf";
|
||||
public final static String DOC = ".doc";
|
||||
public final static String DOCX = ".docx";
|
||||
public final static String XLS = ".xls";
|
||||
public final static String XLSX = ".xlsx";
|
||||
public final static String PNG = ".png";
|
||||
public final static String JPG = ".jpg";
|
||||
public final static String JPEG = ".jpeg";
|
||||
|
||||
public final static String JSON = ".json";
|
||||
public final static String FILE_DB_THUMBS = "Thumbs.db";
|
||||
public final static String FILE_DB_JSON = "db.json";
|
||||
public final static String FILE_BLACK_LIST_JSON = "black_list.json";
|
||||
public final static String FILE_B1001_JSON = "b1001.json";
|
||||
|
||||
|
||||
public static CompanyFile fillType(String fileName, String companyName, File destDir) {
|
||||
CompanyFile companyFile = new CompanyFile();
|
||||
if (isTycReport(fileName, companyName)) {
|
||||
File dest = new File(destDir, fileName);
|
||||
companyFile.setType(CreditReport);
|
||||
companyFile.setFilePath(dest.getAbsolutePath());
|
||||
return companyFile;
|
||||
}
|
||||
|
||||
|
||||
// 包含公司名称 和 天眼查 的文件
|
||||
if (fileName.contains(companyName) && fileName.contains(CloudTycService.NAME)) {
|
||||
LocalDateTime dateTime = LocalDateTime.now();
|
||||
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm");
|
||||
int idx = fileName.indexOf("报告");
|
||||
String destName = (idx > 0 ? fileName.substring(0, fileName.indexOf("报告") + 2) + "_" : "") +
|
||||
companyName + "_天眼查_" + dateTime.format(fmt) + "." + StringUtils.getFilenameExtension(fileName);
|
||||
}
|
||||
|
||||
|
||||
for (CompanyFileType value : CompanyFileType.values()) {
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查文件是否符合后缀要求
|
||||
*
|
||||
* @param name 文件名
|
||||
* @param fileExtensions 后缀
|
||||
*/
|
||||
public static boolean withExtensions(String name, String... fileExtensions) {
|
||||
for (String fn : fileExtensions) {
|
||||
if (name.endsWith(fn)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从文件名判断是否是天眼查的报告文件
|
||||
*/
|
||||
public static boolean isTycReport(String fileName, String companyName) {
|
||||
// 文件名中必须包含 天眼查 字样
|
||||
if (!fileName.contains(CloudTycService.NAME)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 文件名中必须包含 公司名称
|
||||
if (!fileName.contains(companyName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 文件名后缀需符合要求
|
||||
return withExtensions(fileName, PDF, DOC, DOCX);
|
||||
}
|
||||
|
||||
public static boolean isCompanyFile(File file) {
|
||||
String fileName = file.getName();
|
||||
if (fileName.equals(FILE_DB_JSON)) {
|
||||
return true;
|
||||
}
|
||||
if (fileName.equals(FILE_B1001_JSON)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (fileName.equals(FILE_BLACK_LIST_JSON)) {
|
||||
return true;
|
||||
}
|
||||
if (fileName.equals("合同列表.json")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//营业执照
|
||||
if (fileName.contains(CompanyFileService.BUSINESS_LICENSE)) {
|
||||
return true;
|
||||
}
|
||||
// 操作证
|
||||
if (fileName.contains(CompanyFileService.OPERATION_CERTIFICATE)) {
|
||||
return true;
|
||||
}
|
||||
// 许可证
|
||||
if (fileName.contains(CompanyFileService.PERMIT_CERTIFICATE)) {
|
||||
return true;
|
||||
}
|
||||
// 登记证
|
||||
if (fileName.contains(CompanyFileService.REGISTRATION_CERTIFICATE)) {
|
||||
return true;
|
||||
}
|
||||
// 组织机构代码证
|
||||
if (fileName.contains(CompanyFileService.ORGANIZATION_CODE_CERTIFICATE)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文件名中提取的日期信息更新对象的日期,如果文件名称中没有可识别的日期,则不进行任何更新
|
||||
* 日期提取方法参考 {@link MyDateTimeUtils#pickLocalDate(String)}
|
||||
*
|
||||
* @param file 日期来源文件对象
|
||||
* @param vendorFile 要更新的对象
|
||||
* @param getter 对象的日期获取方法
|
||||
* @param setter 对象的日期设置方法
|
||||
* @param <T> 对象泛型
|
||||
* @return 是否更新了日期
|
||||
*/
|
||||
public static <T> boolean fillApplyDateAbsent(File file, T vendorFile, Function<T, LocalDate> getter, BiConsumer<T, LocalDate> setter) {
|
||||
LocalDate applyDate = getter.apply(vendorFile);
|
||||
if (applyDate != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean modified = false;
|
||||
String fileName = file.getName();
|
||||
// 从文件的名称中提取日期
|
||||
LocalDate picked = MyDateTimeUtils.pickLocalDate(fileName);
|
||||
if (picked != null) {
|
||||
// 如果提取出的日期不为空,则通过setter函数将这个日期设置到vendorFile中,并将modified标志设置为true。
|
||||
setter.accept(vendorFile, picked);
|
||||
modified = true;
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
public static boolean isHiddenFile(File file) {
|
||||
String fileName = file.getName();
|
||||
if (fileName.equals(FILE_DB_THUMBS)) {
|
||||
return true;
|
||||
}
|
||||
return fileName.startsWith("~$");
|
||||
}
|
||||
|
||||
public static String escapeFileName(String fileName) {
|
||||
String patternStr = "[\\\\/:*?\"<>|]";
|
||||
Pattern pattern = Pattern.compile(patternStr);
|
||||
Matcher matcher = pattern.matcher(fileName);
|
||||
return matcher.replaceAll("_");
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回 district 中关于省份的部门zi
|
||||
*
|
||||
* @param district 地区
|
||||
* @return 省份名称
|
||||
*/
|
||||
public static String getParentPrefixByDistrict(String district) {
|
||||
int indexOf = district.indexOf("省");
|
||||
if (indexOf != -1) {
|
||||
return district.substring(0, indexOf);
|
||||
}
|
||||
|
||||
indexOf = district.indexOf("自治区");
|
||||
if (indexOf != -1) {
|
||||
return district.substring(0, 2);
|
||||
}
|
||||
|
||||
indexOf = district.indexOf("市");
|
||||
if (indexOf != -1) {
|
||||
return district.substring(0, indexOf);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean exists(String path) {
|
||||
if (!StringUtils.hasText(path)) {
|
||||
return false;
|
||||
}
|
||||
File file = new File(path);
|
||||
return file.exists();
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.ecep.contract.manager.ds.company;
|
||||
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.manager.ds.other.EntityStringConverter;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Lazy
|
||||
@Component
|
||||
public class CompanyStringConverter extends EntityStringConverter<Company> {
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
CompanyService service;
|
||||
public CompanyStringConverter() {
|
||||
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
setInitialized(project -> service.findById(project.getId()));
|
||||
setSuggestion(service::search);
|
||||
setFromString(service::findByName);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.ecep.contract.manager.ds.company.controller;
|
||||
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.manager.ds.company.vo.CompanyViewModel;
|
||||
import com.ecep.contract.manager.ui.tab.AbstEntityBasedTabSkin;
|
||||
import com.ecep.contract.manager.ui.tab.TabSkin;
|
||||
|
||||
public abstract class AbstCompanyBasedTabSkin
|
||||
extends AbstEntityBasedTabSkin<CompanyWindowController, Company, CompanyViewModel>
|
||||
implements TabSkin {
|
||||
|
||||
public AbstCompanyBasedTabSkin(CompanyWindowController controller) {
|
||||
super(controller);
|
||||
}
|
||||
|
||||
protected CompanyService getCompanyService() {
|
||||
return controller.getViewModelService();
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package com.ecep.contract.manager.ds.company.controller;
|
||||
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.manager.ds.company.vo.CompanyBasedViewModel;
|
||||
import com.ecep.contract.manager.ds.company.vo.CompanyViewModel;
|
||||
import com.ecep.contract.manager.ds.other.model.IdentityEntity;
|
||||
import com.ecep.contract.manager.ds.other.vo.IdentityViewModel;
|
||||
import com.ecep.contract.manager.ui.table.AbstEntityTableTabSkin;
|
||||
import com.ecep.contract.manager.ui.tab.TabSkin;
|
||||
import com.ecep.contract.manager.ui.table.TableOfTabSkin;
|
||||
import com.ecep.contract.manager.util.SpecificationUtils;
|
||||
import lombok.Setter;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
|
||||
public abstract class AbstCompanyTableTabSkin<T extends IdentityEntity, TV extends IdentityViewModel<T>>
|
||||
extends AbstEntityTableTabSkin<CompanyWindowController, Company, CompanyViewModel, T, TV>
|
||||
implements TabSkin, TableOfTabSkin<Company, T, TV> {
|
||||
|
||||
@Setter
|
||||
private CompanyService companyService;
|
||||
|
||||
public AbstCompanyTableTabSkin(CompanyWindowController controller) {
|
||||
super(controller);
|
||||
viewModel = controller.getViewModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TV createNewViewModel() {
|
||||
TV model = super.createNewViewModel();
|
||||
if (model instanceof CompanyBasedViewModel m) {
|
||||
m.getCompany().set(getEntity());
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
protected CompanyService getCompanyService(){
|
||||
return getParentService();
|
||||
}
|
||||
|
||||
protected CompanyService getParentService() {
|
||||
if (companyService == null) {
|
||||
companyService = getBean(CompanyService.class);
|
||||
}
|
||||
return companyService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<T> getSpecification(Company parent) {
|
||||
return SpecificationUtils.and(getSpecification(), (root, query, builder) -> {
|
||||
return builder.equal(root.get("company"), parent);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
package com.ecep.contract.manager.ds.company.controller;
|
||||
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyOldNameService;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.manager.ds.company.vo.CompanyViewModel;
|
||||
import com.ecep.contract.manager.ui.AbstEntityManagerSkin;
|
||||
import com.ecep.contract.manager.ui.ManagerSkin;
|
||||
import javafx.application.Platform;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.TextInputDialog;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class CompanyManagerSkin
|
||||
extends AbstEntityManagerSkin<Company, CompanyViewModel, CompanyManagerSkin, CompanyManagerWindowController> {
|
||||
|
||||
@Setter
|
||||
private CompanyOldNameService companyOldNameService;
|
||||
|
||||
public CompanyManagerSkin(CompanyManagerWindowController controller) {
|
||||
super(controller);
|
||||
}
|
||||
|
||||
public CompanyService getCompanyService() {
|
||||
return controller.getViewModelService();
|
||||
}
|
||||
|
||||
public CompanyOldNameService getCompanyOldNameService() {
|
||||
if (companyOldNameService == null) {
|
||||
companyOldNameService = getBean(CompanyOldNameService.class);
|
||||
}
|
||||
return companyOldNameService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeTable() {
|
||||
controller.idColumn.setCellValueFactory(param -> param.getValue().getId());
|
||||
controller.nameColumn.setCellValueFactory(param -> param.getValue().getName());
|
||||
controller.uniscidColumn.setCellValueFactory(param -> param.getValue().getUid());
|
||||
controller.entStatusColumn.setCellValueFactory(param -> param.getValue().getEntStatus());
|
||||
controller.createdColumn.setCellValueFactory(param -> param.getValue().getCreated());
|
||||
controller.memoColumn.setCellValueFactory(param -> param.getValue().getMemo());
|
||||
|
||||
Platform.runLater(() -> {
|
||||
getTableView().getSortOrder().add(controller.createdColumn);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTableRowDoubleClickedAction(CompanyViewModel item) {
|
||||
showInOwner(CompanyWindowController.class, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTableCreateNewAction(ActionEvent event) {
|
||||
Platform.runLater(() -> {
|
||||
TextInputDialog dialog = new TextInputDialog();
|
||||
dialog.setTitle("新建公司");
|
||||
dialog.setHeaderText("请输入新建的公司名称,请输入公司名字全称");
|
||||
Optional<String> optional = dialog.showAndWait();
|
||||
if (optional.isPresent()) {
|
||||
CompanyService companyService = getCompanyService();
|
||||
String newCompanyName = optional.get();
|
||||
List<Company> list = companyService.findAllByName(newCompanyName);
|
||||
if (list == null || list.isEmpty()) {
|
||||
// 未登记过
|
||||
Company company = companyService.createNewCompany(newCompanyName);
|
||||
Company saved = companyService.save(company);
|
||||
CompanyWindowController.show(saved, getTableView().getScene().getWindow());
|
||||
} else {
|
||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||
alert.setTitle("新建公司");
|
||||
alert.setHeaderText("公司名称 " + newCompanyName + " 已经存在,是否打开公司页面");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
package com.ecep.contract.manager.ds.company.controller;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.manager.ds.company.tasker.CompanyFilesRebuildTasker;
|
||||
import com.ecep.contract.manager.ds.company.vo.CompanyViewModel;
|
||||
import com.ecep.contract.manager.ui.AbstManagerWindowController;
|
||||
import com.ecep.contract.manager.ui.FxmlPath;
|
||||
import com.ecep.contract.manager.util.UITools;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
@Lazy
|
||||
@Scope("prototype")
|
||||
@Component
|
||||
@FxmlPath("/ui/company/company-manager.fxml")
|
||||
public class CompanyManagerWindowController
|
||||
extends AbstManagerWindowController<Company, CompanyViewModel, CompanyManagerSkin> {
|
||||
|
||||
// columns
|
||||
@FXML
|
||||
public TableColumn<CompanyViewModel, Number> idColumn;
|
||||
@FXML
|
||||
public TableColumn<CompanyViewModel, String> nameColumn;
|
||||
@FXML
|
||||
public TableColumn<CompanyViewModel, String> uniscidColumn;
|
||||
@FXML
|
||||
public TableColumn<CompanyViewModel, String> entStatusColumn;
|
||||
@FXML
|
||||
public TableColumn<CompanyViewModel, LocalDate> createdColumn;
|
||||
@FXML
|
||||
public TableColumn<CompanyViewModel, String> memoColumn;
|
||||
|
||||
@Autowired
|
||||
private CompanyService companyService;
|
||||
|
||||
@Override
|
||||
public CompanyService getViewModelService() {
|
||||
return companyService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show(Stage stage) {
|
||||
super.show(stage);
|
||||
getTitle().set("公司管理");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CompanyManagerSkin createDefaultSkin() {
|
||||
return new CompanyManagerSkin(this);
|
||||
}
|
||||
|
||||
public void onCompanyCreateNewAction(ActionEvent event) {
|
||||
getSkin().onTableCreateNewAction(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对所有公司的文件进行重置
|
||||
* <p>
|
||||
* 弹出对话框模式,对话框中有进度条和重置的消息
|
||||
*
|
||||
* @param event 事件
|
||||
*/
|
||||
public void onReBuildFilesAction(ActionEvent event) {
|
||||
CompanyFilesRebuildTasker task = new CompanyFilesRebuildTasker();
|
||||
UITools.showTaskDialogAndWait("公司文件重置", task, null);
|
||||
}
|
||||
|
||||
public void onVerifyAction(ActionEvent event) {
|
||||
show(CompanyVerifyWindowController.class, null);
|
||||
}
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
package com.ecep.contract.manager.ds.company.controller;
|
||||
|
||||
import com.ecep.contract.manager.ds.company.controller.bank_account.BankAccountWindowController;
|
||||
import com.ecep.contract.manager.ds.company.model.CompanyBankAccount;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyBankAccountService;
|
||||
import com.ecep.contract.manager.ds.company.vo.CompanyBankAccountViewModel;
|
||||
import com.ecep.contract.manager.ds.other.model.Bank;
|
||||
import com.ecep.contract.manager.ds.other.service.BankService;
|
||||
import com.ecep.contract.manager.ui.table.EditableEntityTableTabSkin;
|
||||
import com.ecep.contract.manager.ui.FxmlPath;
|
||||
import com.ecep.contract.manager.ui.tab.TabSkin;
|
||||
import com.ecep.contract.manager.ui.table.cell.BankTableCell;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.Hibernate;
|
||||
|
||||
/**
|
||||
* 子合同
|
||||
*/
|
||||
@FxmlPath("/ui/company/company-tab-bank-account.fxml")
|
||||
public class CompanyTabSkinBankAccount
|
||||
extends AbstCompanyTableTabSkin<CompanyBankAccount, CompanyBankAccountViewModel>
|
||||
implements TabSkin, EditableEntityTableTabSkin<CompanyBankAccount, CompanyBankAccountViewModel> {
|
||||
/**
|
||||
* 银行账户
|
||||
*/
|
||||
public TableColumn<CompanyBankAccountViewModel, Number> bankAccountTable_idColumn;
|
||||
public TableColumn<CompanyBankAccountViewModel, Bank> bankAccountTable_bankColumn;
|
||||
public TableColumn<CompanyBankAccountViewModel, String> bankAccountTable_openingBankColumn;
|
||||
public TableColumn<CompanyBankAccountViewModel, String> bankAccountTable_accountColumn;
|
||||
public TextField bankAccountSearchKeyField;
|
||||
public Button bankAccountSearchBtn;
|
||||
public MenuItem bankAccountTable_menu_refresh;
|
||||
public MenuItem bankAccountTable_menu_add;
|
||||
public MenuItem bankAccountTable_menu_del;
|
||||
|
||||
@Setter
|
||||
private CompanyBankAccountService bankAccountService;
|
||||
@Setter
|
||||
private BankService bankService;
|
||||
|
||||
public CompanyTabSkinBankAccount(CompanyWindowController controller) {
|
||||
super(controller);
|
||||
}
|
||||
@Override
|
||||
public Tab getTab() {
|
||||
return controller.bankAccountTab;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeTab() {
|
||||
bankAccountSearchKeyField.setOnKeyReleased(event -> {
|
||||
if (event.getCode() == KeyCode.ENTER) {
|
||||
bankAccountSearchBtn.fire();
|
||||
}
|
||||
});
|
||||
bankAccountSearchBtn.setOnAction(this::onTableRefreshAction);
|
||||
|
||||
bankAccountTable_idColumn.setCellValueFactory(param -> param.getValue().getId());
|
||||
bankAccountTable_bankColumn.setCellValueFactory(param -> param.getValue().getBank());
|
||||
bankAccountTable_bankColumn.setCellFactory(param -> new BankTableCell<>(getBankService()));
|
||||
|
||||
bankAccountTable_openingBankColumn.setCellValueFactory(param -> param.getValue().getOpeningBank());
|
||||
bankAccountTable_accountColumn.setCellValueFactory(param -> param.getValue().getAccount());
|
||||
|
||||
|
||||
bankAccountTable_menu_refresh.setOnAction(this::onTableRefreshAction);
|
||||
bankAccountTable_menu_add.setOnAction(this::onTableAddAction);
|
||||
bankAccountTable_menu_del.setOnAction(this::onTableDeleteAction);
|
||||
|
||||
super.initializeTab();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTableRowDoubleClickedAction(CompanyBankAccountViewModel item) {
|
||||
BankAccountWindowController.show(item, controller.root.getScene().getWindow());
|
||||
}
|
||||
|
||||
|
||||
public CompanyBankAccountService getViewModelService() {
|
||||
if (bankAccountService == null) {
|
||||
bankAccountService = getBean(CompanyBankAccountService.class);
|
||||
}
|
||||
return bankAccountService;
|
||||
}
|
||||
|
||||
public BankService getBankService() {
|
||||
if (bankService == null) {
|
||||
bankService = getBean(BankService.class);
|
||||
}
|
||||
return bankService;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,204 +0,0 @@
|
||||
package com.ecep.contract.manager.ds.company.controller;
|
||||
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.model.CompanyOldName;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyOldNameService;
|
||||
import com.ecep.contract.manager.ui.tab.TabSkin;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.util.converter.LocalDateStringConverter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public class CompanyTabSkinBase
|
||||
extends AbstCompanyBasedTabSkin
|
||||
implements TabSkin {
|
||||
@Setter
|
||||
private CompanyOldNameService companyOldNameService;
|
||||
|
||||
public CompanyTabSkinBase(CompanyWindowController controller) {
|
||||
super(controller);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tab getTab() {
|
||||
return controller.baseInfoTab;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeTab() {
|
||||
|
||||
LocalDateStringConverter localDateStringConverter = new LocalDateStringConverter(DateTimeFormatter.ISO_LOCAL_DATE, null);
|
||||
|
||||
controller.nameField.textProperty().bind(viewModel.getName());
|
||||
controller.shortNameField.textProperty().bindBidirectional(viewModel.getShortName());
|
||||
controller.entStatusField.textProperty().bindBidirectional(viewModel.getEntStatus());
|
||||
|
||||
controller.uidField.textProperty().bindBidirectional(viewModel.getUid());
|
||||
controller.setupDateField.setConverter(localDateStringConverter);
|
||||
controller.setupDateField.valueProperty().bindBidirectional(viewModel.getSetupDate());
|
||||
controller.entTypeField.textProperty().bindBidirectional(viewModel.getEntType());
|
||||
controller.industryField.textProperty().bindBidirectional(viewModel.getIndustry());
|
||||
controller.districtField.textProperty().bindBidirectional(viewModel.getDistrict());
|
||||
controller.pathExistField.selectedProperty().bind(viewModel.getPathExist());
|
||||
controller.pathField.textProperty().bind(viewModel.getPath());
|
||||
controller.createdDateField.setConverter(localDateStringConverter);
|
||||
controller.createdDateField.valueProperty().bindBidirectional(viewModel.getCreated());
|
||||
|
||||
controller.telephoneField.textProperty().bindBidirectional(viewModel.getTelephone());
|
||||
controller.regAddressField.textProperty().bindBidirectional(viewModel.getRegAddress());
|
||||
controller.addressField.textProperty().bindBidirectional(viewModel.getAddress());
|
||||
controller.registeredCapitalField.textProperty().bindBidirectional(viewModel.getRegisteredCapital());
|
||||
controller.registeredCapitalCurrencyField.textProperty().bindBidirectional(viewModel.getRegisteredCapitalCurrency());
|
||||
controller.legalRepresentativeField.textProperty().bindBidirectional(viewModel.getLegalRepresentative());
|
||||
|
||||
controller.operationPeriodBeginField.setConverter(localDateStringConverter);
|
||||
controller.operationPeriodBeginField.valueProperty().bindBidirectional(viewModel.getOperationPeriodBegin());
|
||||
controller.operationPeriodEndField.setConverter(localDateStringConverter);
|
||||
controller.operationPeriodEndField.valueProperty().bindBidirectional(viewModel.getOperationPeriodEnd());
|
||||
|
||||
controller.memoField.textProperty().bindBidirectional(viewModel.getMemo());
|
||||
controller.versionLabel.textProperty().bind(viewModel.getVersion().asString());
|
||||
|
||||
controller.companyRenameBtn.setOnAction(this::onCompanyRenameAction);
|
||||
controller.companyPathCreateBtn.setOnAction(this::onCompanyPathCreatePathAction);
|
||||
controller.companyPathChangeBtn.setOnAction(this::onCompanyPathChangePathAction);
|
||||
controller.companyPathSameAsNameBtn.setOnAction(this::onCompanyPathSameAsNameAction);
|
||||
}
|
||||
|
||||
private void onCompanyPathCreatePathAction(ActionEvent event) {
|
||||
Company company = getEntity();
|
||||
if (getCompanyService().makePathAbsent(company)) {
|
||||
save(company);
|
||||
} else {
|
||||
setStatus("目录存在或创建失败");
|
||||
}
|
||||
}
|
||||
|
||||
private void onCompanyPathChangePathAction(ActionEvent event) {
|
||||
}
|
||||
|
||||
private void onCompanyPathSameAsNameAction(ActionEvent event) {
|
||||
Company company = getEntity();
|
||||
String path = company.getPath();
|
||||
if (!StringUtils.hasText(path)) {
|
||||
return;
|
||||
}
|
||||
File file = new File(path);
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (file.getName().equals(company.getName())) {
|
||||
return;
|
||||
}
|
||||
File dest = new File(file.getParent(), company.getName());
|
||||
if (file.renameTo(dest)) {
|
||||
company.setPath(dest.getAbsolutePath());
|
||||
save(company);
|
||||
setStatus("目录变更为" + dest.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private void onCompanyRenameAction(ActionEvent event) {
|
||||
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
|
||||
alert.initOwner(controller.root.getScene().getWindow());
|
||||
alert.initModality(Modality.WINDOW_MODAL);
|
||||
VBox layout = new VBox();
|
||||
|
||||
TextField nameField = new TextField();
|
||||
Label nameLabel = new Label("");
|
||||
|
||||
CheckBox saveAsOldName = new CheckBox();
|
||||
CheckBox ambiguity = new CheckBox();
|
||||
Label ambiguityLabel = new Label("当曾用名不是工商注册过的名字时,请勾选 歧义 标记");
|
||||
layout.setPadding(new Insets(12));
|
||||
layout.setSpacing(8);
|
||||
|
||||
nameField.setPromptText("新的公司名称");
|
||||
nameField.setText(viewModel.getName().get());
|
||||
nameField.setEditable(true);
|
||||
nameLabel.setTextFill(Color.GRAY);
|
||||
|
||||
saveAsOldName.setText("旧名称是否设置为曾用名");
|
||||
ambiguity.setText("是否标记为歧义");
|
||||
ambiguity.visibleProperty().bind(saveAsOldName.selectedProperty());
|
||||
ambiguityLabel.setTextFill(Color.GRAY);
|
||||
ambiguityLabel.visibleProperty().bind(saveAsOldName.selectedProperty());
|
||||
|
||||
layout.getChildren().addAll(nameField, nameLabel, saveAsOldName, ambiguity, ambiguityLabel);
|
||||
|
||||
|
||||
alert.setContentText("context");
|
||||
alert.setHeaderText(null);
|
||||
alert.setTitle("企业更名");
|
||||
|
||||
alert.getDialogPane().setContent(layout);
|
||||
|
||||
// alert.setResultConverter(param -> {
|
||||
//
|
||||
// return null;
|
||||
// });
|
||||
|
||||
|
||||
alert.setOnCloseRequest(dialogEvent -> {
|
||||
ButtonType buttonType = alert.getResult();
|
||||
if (buttonType != ButtonType.OK) {
|
||||
return;
|
||||
}
|
||||
String newName = nameField.getText();
|
||||
String oldName = viewModel.getName().get();
|
||||
if (oldName.equals(newName)) {
|
||||
nameLabel.setText("名称没有修改");
|
||||
nameLabel.setTextFill(Color.PERU);
|
||||
dialogEvent.consume();
|
||||
return;
|
||||
}
|
||||
|
||||
viewModel.getName().set(newName);
|
||||
save();
|
||||
|
||||
// TODO 修改文件夹
|
||||
if (!saveAsOldName.isSelected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Company company = getEntity();
|
||||
List<CompanyOldName> oldNames = getCompanyOldNameService().findAllByCompanyAndName(company, oldName);
|
||||
if (oldNames.isEmpty()) {
|
||||
CompanyOldName companyOldName = new CompanyOldName();
|
||||
companyOldName.setCompanyId(company.getId());
|
||||
companyOldName.setName(oldName);
|
||||
companyOldName.setAmbiguity(ambiguity.isSelected());
|
||||
companyOldName.setMemo("名称更名 " + oldName + " -> " + newName);
|
||||
getCompanyOldNameService().save(companyOldName);
|
||||
|
||||
CompanyTabSkinOldName tabSkin = controller.getTabSkin(CompanyTabSkinOldName.class);
|
||||
if (tabSkin != null) {
|
||||
tabSkin.loadTableDataSet();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
alert.showAndWait();
|
||||
}
|
||||
|
||||
private CompanyOldNameService getCompanyOldNameService() {
|
||||
if (companyOldNameService == null) {
|
||||
companyOldNameService = getBean(CompanyOldNameService.class);
|
||||
}
|
||||
return companyOldNameService;
|
||||
}
|
||||
}
|
||||
@@ -1,142 +0,0 @@
|
||||
package com.ecep.contract.manager.ds.company.controller;
|
||||
|
||||
import com.ecep.contract.manager.cloud.rk.BlackListUpdateContext;
|
||||
import com.ecep.contract.manager.cloud.rk.CloudRk;
|
||||
import com.ecep.contract.manager.cloud.rk.CloudRkService;
|
||||
import com.ecep.contract.manager.ds.company.BlackReasonType;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.model.CompanyBlackReason;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyBlackReasonService;
|
||||
import com.ecep.contract.manager.ds.company.vo.CompanyBlackReasonViewModel;
|
||||
import com.ecep.contract.manager.ui.table.EditableEntityTableTabSkin;
|
||||
import com.ecep.contract.manager.ui.FxmlPath;
|
||||
import com.ecep.contract.manager.ui.tab.TabSkin;
|
||||
import com.ecep.contract.manager.util.UITools;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* 子合同
|
||||
*/
|
||||
@FxmlPath("/ui/company/company-tab-black-list.fxml")
|
||||
public class CompanyTabSkinBlackReason
|
||||
extends AbstCompanyTableTabSkin<CompanyBlackReason, CompanyBlackReasonViewModel>
|
||||
implements TabSkin, EditableEntityTableTabSkin<CompanyBlackReason, CompanyBlackReasonViewModel> {
|
||||
/**
|
||||
* 以下是黑名单列定义
|
||||
*/
|
||||
public TableColumn<CompanyBlackReasonViewModel, Number> blackReasonTable_idColumn;
|
||||
public TableColumn<CompanyBlackReasonViewModel, BlackReasonType> blackReasonTable_typeColumn;
|
||||
public TableColumn<CompanyBlackReasonViewModel, String> blackReasonTable_applyNameColumn;
|
||||
public TableColumn<CompanyBlackReasonViewModel, String> blackReasonTable_blackReasonColumn;
|
||||
public TableColumn<CompanyBlackReasonViewModel, String> blackReasonTable_descriptionColumn;
|
||||
public TableColumn<CompanyBlackReasonViewModel, LocalDate> blackReasonTable_applyDateColumn;
|
||||
public TableColumn<CompanyBlackReasonViewModel, LocalDate> blackReasonTable_updateTimeColumn;
|
||||
public TableColumn<CompanyBlackReasonViewModel, LocalDate> blackReasonTable_createTimeColumn;
|
||||
public TableColumn<CompanyBlackReasonViewModel, LocalDate> blackReasonTable_includeDateColumn;
|
||||
public TableColumn<CompanyBlackReasonViewModel, String> blackReasonTable_keyColumn;
|
||||
|
||||
public TextField blackListSearchKeyField;
|
||||
public Button blackListSearchBtn;
|
||||
public MenuItem blackReasonTable_menu_refresh;
|
||||
public MenuItem blackReasonTable_menu_update;
|
||||
|
||||
@Setter
|
||||
private CompanyBlackReasonService companyBlackReasonService;
|
||||
@Setter
|
||||
private CloudRkService cloudRkService;
|
||||
|
||||
public CompanyTabSkinBlackReason(CompanyWindowController controller) {
|
||||
super(controller);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tab getTab() {
|
||||
return controller.blackReasonTab;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeTab() {
|
||||
|
||||
blackListSearchKeyField.setOnKeyReleased(event -> {
|
||||
if (event.getCode() == KeyCode.ENTER) {
|
||||
blackListSearchBtn.fire();
|
||||
}
|
||||
});
|
||||
|
||||
blackListSearchBtn.setOnAction(this::onTableRefreshAction);
|
||||
|
||||
blackReasonTable_idColumn.setCellValueFactory(param -> param.getValue().getId());
|
||||
blackReasonTable_typeColumn.setCellValueFactory(param -> param.getValue().getType());
|
||||
blackReasonTable_applyNameColumn.setCellValueFactory(param -> param.getValue().getApplyName());
|
||||
blackReasonTable_blackReasonColumn.setCellValueFactory(param -> param.getValue().getBlackReason());
|
||||
blackReasonTable_descriptionColumn.setCellValueFactory(param -> param.getValue().getDescription());
|
||||
|
||||
blackReasonTable_applyDateColumn.setCellValueFactory(param -> param.getValue().getApplyDate());
|
||||
blackReasonTable_updateTimeColumn.setCellValueFactory(param -> param.getValue().getUpdateTime());
|
||||
blackReasonTable_createTimeColumn.setCellValueFactory(param -> param.getValue().getUpdateTime());
|
||||
blackReasonTable_includeDateColumn.setCellValueFactory(param -> param.getValue().getCreateTime());
|
||||
|
||||
blackReasonTable_keyColumn.setCellValueFactory(param -> param.getValue().getKey());
|
||||
|
||||
blackReasonTable_menu_refresh.setOnAction(this::onTableRefreshAction);
|
||||
blackReasonTable_menu_update.setOnAction(this::onTableUpdateAction);
|
||||
|
||||
|
||||
super.initializeTab();
|
||||
}
|
||||
|
||||
|
||||
private void onTableUpdateAction(ActionEvent event) {
|
||||
Company company = getParent();
|
||||
|
||||
CloudRkService cloudRkService = getCloudRkService();
|
||||
CloudRk cloudRk = cloudRkService.getOrCreateCloudRk(company);
|
||||
BlackListUpdateContext context = cloudRkService.createBlackListUpdateContext().join();
|
||||
if (cloudRkService.checkBlackListUpdateElapse(company, cloudRk, context)) {
|
||||
try {
|
||||
cloudRkService.updateBlackList(company, cloudRk, context);
|
||||
} catch (Exception e) {
|
||||
UITools.showExceptionAndWait("更新黑名单时发生错误", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTableRowDoubleClickedAction(CompanyBlackReasonViewModel item) {
|
||||
// ContractWindowController.show(item, controller.root.getScene().getWindow());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompanyBlackReason loadRowData(CompanyBlackReasonViewModel row) {
|
||||
return getViewModelService().findById(row.getId().get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompanyBlackReason saveRowData(CompanyBlackReason entity) {
|
||||
return getViewModelService().save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteRowData(CompanyBlackReason entity) {
|
||||
getViewModelService().delete(entity);
|
||||
}
|
||||
|
||||
protected CompanyBlackReasonService getViewModelService() {
|
||||
if (companyBlackReasonService == null) {
|
||||
companyBlackReasonService = getBean(CompanyBlackReasonService.class);
|
||||
}
|
||||
return companyBlackReasonService;
|
||||
}
|
||||
|
||||
public CloudRkService getCloudRkService() {
|
||||
if (cloudRkService == null) {
|
||||
cloudRkService = getBean(CloudRkService.class);
|
||||
}
|
||||
return cloudRkService;
|
||||
}
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
package com.ecep.contract.manager.ds.company.controller;
|
||||
|
||||
import com.ecep.contract.manager.ds.company.controller.contact.CompanyContactWindowController;
|
||||
import com.ecep.contract.manager.ds.company.model.CompanyContact;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyContactService;
|
||||
import com.ecep.contract.manager.ds.company.vo.CompanyContactViewModel;
|
||||
import com.ecep.contract.manager.ui.table.EditableEntityTableTabSkin;
|
||||
import com.ecep.contract.manager.ui.FxmlPath;
|
||||
import com.ecep.contract.manager.ui.tab.TabSkin;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* 子合同
|
||||
*/
|
||||
@FxmlPath("/ui/company/company-tab-contact.fxml")
|
||||
public class CompanyTabSkinContact
|
||||
extends AbstCompanyTableTabSkin<CompanyContact, CompanyContactViewModel>
|
||||
implements TabSkin, EditableEntityTableTabSkin<CompanyContact, CompanyContactViewModel> {
|
||||
|
||||
/**
|
||||
* 以下是联系人列定义
|
||||
*/
|
||||
public TableColumn<CompanyContactViewModel, Number> contactTable_idColumn;
|
||||
public TableColumn<CompanyContactViewModel, String> contactTable_nameColumn;
|
||||
public TableColumn<CompanyContactViewModel, String> contactTable_positionColumn;
|
||||
public TableColumn<CompanyContactViewModel, String> contactTable_phoneColumn;
|
||||
public TableColumn<CompanyContactViewModel, String> contactTable_emailColumn;
|
||||
public TableColumn<CompanyContactViewModel, String> contactTable_addressColumn;
|
||||
public TableColumn<CompanyContactViewModel, String> contactTable_u8CodeColumn;
|
||||
public TableColumn<CompanyContactViewModel, LocalDate> contactTable_createdColumn;
|
||||
|
||||
public TextField contactSearchKeyField;
|
||||
public Button contactSearchBtn;
|
||||
public MenuItem contactTable_menu_refresh;
|
||||
public MenuItem contactTable_menu_add;
|
||||
public MenuItem contactTable_menu_del;
|
||||
@Setter
|
||||
private CompanyContactService contactService;
|
||||
|
||||
public CompanyTabSkinContact(CompanyWindowController controller) {
|
||||
super(controller);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tab getTab() {
|
||||
return controller.contactTab;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initializeTab() {
|
||||
contactSearchKeyField.setOnKeyReleased(event -> {
|
||||
if (event.getCode() == KeyCode.ENTER) {
|
||||
contactSearchBtn.fire();
|
||||
}
|
||||
});
|
||||
contactSearchBtn.setOnAction(this::onTableRefreshAction);
|
||||
|
||||
contactTable_idColumn.setCellValueFactory(param -> param.getValue().getId());
|
||||
contactTable_nameColumn.setCellValueFactory(param -> param.getValue().getName());
|
||||
contactTable_positionColumn.setCellValueFactory(param -> param.getValue().getPosition());
|
||||
contactTable_phoneColumn.setCellValueFactory(param -> param.getValue().getPhone());
|
||||
contactTable_emailColumn.setCellValueFactory(param -> param.getValue().getEmail());
|
||||
contactTable_addressColumn.setCellValueFactory(param -> param.getValue().getAddress());
|
||||
contactTable_u8CodeColumn.setCellValueFactory(param -> param.getValue().getU8Code());
|
||||
contactTable_createdColumn.setCellValueFactory(param -> param.getValue().getCreated());
|
||||
|
||||
contactTable_menu_refresh.setOnAction(this::onTableRefreshAction);
|
||||
contactTable_menu_add.setOnAction(this::onTableAddAction);
|
||||
contactTable_menu_del.setOnAction(this::onTableDeleteAction);
|
||||
|
||||
|
||||
super.initializeTab();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTableAddAction(ActionEvent event) {
|
||||
CompanyContact contact = new CompanyContact();
|
||||
contact.setCompany(getParent());
|
||||
contact.setCreated(LocalDate.now());
|
||||
getViewModelService().save(contact);
|
||||
loadTableDataSet();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTableRowDoubleClickedAction(CompanyContactViewModel item) {
|
||||
CompanyContactWindowController.show(item, controller.root.getScene().getWindow());
|
||||
}
|
||||
|
||||
public CompanyContactService getViewModelService() {
|
||||
if (contactService == null) {
|
||||
contactService = getBean(CompanyContactService.class);
|
||||
}
|
||||
return contactService;
|
||||
}
|
||||
}
|
||||
@@ -1,293 +0,0 @@
|
||||
package com.ecep.contract.manager.ds.company.controller;
|
||||
|
||||
import com.ecep.contract.manager.cloud.u8.YongYouU8Service;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.contract.controller.ContractWindowController;
|
||||
import com.ecep.contract.manager.ds.contract.model.Contract;
|
||||
import com.ecep.contract.manager.ds.contract.model.ContractGroup;
|
||||
import com.ecep.contract.manager.ds.contract.model.ContractKind;
|
||||
import com.ecep.contract.manager.ds.contract.model.ContractType;
|
||||
import com.ecep.contract.manager.ds.contract.service.ContractGroupService;
|
||||
import com.ecep.contract.manager.ds.contract.service.ContractKindService;
|
||||
import com.ecep.contract.manager.ds.contract.service.ContractService;
|
||||
import com.ecep.contract.manager.ds.contract.service.ContractTypeService;
|
||||
import com.ecep.contract.manager.ds.contract.tasker.ContractRepairByCompanyTask;
|
||||
import com.ecep.contract.manager.ds.contract.vo.ContractViewModel;
|
||||
import com.ecep.contract.manager.ds.other.EmployeeStringConverter;
|
||||
import com.ecep.contract.manager.ds.other.model.Employee;
|
||||
import com.ecep.contract.manager.ui.FxmlPath;
|
||||
import com.ecep.contract.manager.ui.tab.TabSkin;
|
||||
import com.ecep.contract.manager.ui.table.EditableEntityTableTabSkin;
|
||||
import com.ecep.contract.manager.ui.table.cell.*;
|
||||
import com.ecep.contract.manager.ui.util.ContractGroupStringConverter;
|
||||
import com.ecep.contract.manager.util.DesktopUtils;
|
||||
import com.ecep.contract.manager.util.SpecificationUtils;
|
||||
import com.ecep.contract.manager.util.UITools;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.control.cell.TextFieldTableCell;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import lombok.Setter;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* 子合同
|
||||
*/
|
||||
@FxmlPath("/ui/company/company-tab-contract.fxml")
|
||||
public class CompanyTabSkinContract
|
||||
extends AbstCompanyTableTabSkin<Contract, ContractViewModel>
|
||||
implements TabSkin, EditableEntityTableTabSkin<Contract, ContractViewModel> {
|
||||
|
||||
public TableColumn<ContractViewModel, Number> contractTable_idColumn;
|
||||
public TableColumn<ContractViewModel, String> contractTable_codeColumn;
|
||||
public TableColumn<ContractViewModel, String> contractTable_nameColumn;
|
||||
public TableColumn<ContractViewModel, String> contractTable_stateColumn;
|
||||
public TableColumn<ContractViewModel, ContractGroup> contractTable_groupColumn;
|
||||
public TableColumn<ContractViewModel, ContractType> contractTable_typeColumn;
|
||||
public TableColumn<ContractViewModel, ContractKind> contractTable_kindColumn;
|
||||
public TableColumn<ContractViewModel, String> contractTable_parentCodeColumn;
|
||||
public TableColumn<ContractViewModel, LocalDate> contractTable_orderDateColumn;
|
||||
public TableColumn<ContractViewModel, LocalDate> contractTable_startDateColumn;
|
||||
public TableColumn<ContractViewModel, LocalDate> contractTable_endDateColumn;
|
||||
public TableColumn<ContractViewModel, Employee> contractTable_setupPersonColumn;
|
||||
public TableColumn<ContractViewModel, LocalDate> contractTable_setupDateColumn;
|
||||
public TableColumn<ContractViewModel, Employee> contractTable_inurePersonColumn;
|
||||
public TableColumn<ContractViewModel, LocalDate> contractTable_inureDateColumn;
|
||||
public TableColumn<ContractViewModel, Employee> contractTable_varyPersonColumn;
|
||||
public TableColumn<ContractViewModel, LocalDate> contractTable_varyDateColumn;
|
||||
public TableColumn<ContractViewModel, LocalDateTime> contractTable_createdColumn;
|
||||
|
||||
public ComboBox<ContractGroup> contractGroupSelector;
|
||||
public TextField contractSearchKeyField;
|
||||
public Button contractSearchBtn;
|
||||
public Button contractTabToolBtn1;
|
||||
public MenuItem contractTable_menu_refresh;
|
||||
public MenuItem contractTable_menu_add;
|
||||
public MenuItem contractTable_menu_open_in_explorer;
|
||||
public MenuItem contractTable_menu_update;
|
||||
public MenuItem contractTable_menu_del;
|
||||
|
||||
@Setter
|
||||
private ContractService contractService;
|
||||
@Setter
|
||||
private ContractGroupService contractGroupService;
|
||||
@Setter
|
||||
private ContractKindService contractKindService;
|
||||
@Setter
|
||||
private ContractTypeService contractTypeService;
|
||||
@Setter
|
||||
private YongYouU8Service u8Service;
|
||||
@Setter
|
||||
private EmployeeStringConverter employeeStringConverter;
|
||||
|
||||
public CompanyTabSkinContract(CompanyWindowController controller) {
|
||||
super(controller);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tab getTab() {
|
||||
return controller.contractTab;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<Contract> getSpecification(Company parent) {
|
||||
Specification<Contract> spec = super.getSpecification(parent);
|
||||
ContractGroup selectedGroup = contractGroupSelector.getValue();
|
||||
if (selectedGroup != null) {
|
||||
spec = SpecificationUtils.and(spec, (root, query, builder) -> {
|
||||
return builder.equal(root.get("group"), selectedGroup);
|
||||
});
|
||||
}
|
||||
return spec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeTab() {
|
||||
|
||||
if (u8Service == null) {
|
||||
try {
|
||||
u8Service = getBean(YongYouU8Service.class);
|
||||
} catch (BeansException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
contractSearchKeyField.setOnKeyReleased(event -> {
|
||||
if (event.getCode() == KeyCode.ENTER) {
|
||||
contractSearchBtn.fire();
|
||||
}
|
||||
});
|
||||
|
||||
contractSearchBtn.setOnAction(this::onTableRefreshAction);
|
||||
|
||||
|
||||
ObservableList<ContractGroup> contractGroups = FXCollections.observableArrayList();
|
||||
contractGroups.add(null);
|
||||
contractGroups.addAll(getViewModelService().findAllGroups());
|
||||
contractGroupSelector.setItems(contractGroups);
|
||||
contractGroupSelector.setConverter(new ContractGroupStringConverter(contractGroups));
|
||||
contractSearchKeyField.setOnKeyReleased(event -> {
|
||||
if (event.getCode() == KeyCode.ENTER) {
|
||||
contractSearchBtn.fire();
|
||||
}
|
||||
});
|
||||
|
||||
contractTabToolBtn1.setOnAction(event -> {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
// 计算主合同编号
|
||||
for (ContractViewModel model : dataSet) {
|
||||
Contract contract = getViewModelService().findById(model.getId().get());
|
||||
if (contract == null) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
if (getViewModelService().updateParentCode(contract)) {
|
||||
Contract updated = getViewModelService().save(contract);
|
||||
model.update(updated);
|
||||
}
|
||||
} catch (NoSuchElementException e) {
|
||||
model.getParentCode().set(e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
contractTable_idColumn.setCellValueFactory(param -> param.getValue().getId());
|
||||
contractTable_codeColumn.setCellValueFactory(param -> param.getValue().getCode());
|
||||
contractTable_nameColumn.setCellValueFactory(param -> param.getValue().getName());
|
||||
contractTable_stateColumn.setCellValueFactory(param -> param.getValue().getState());
|
||||
contractTable_groupColumn.setCellValueFactory(param -> param.getValue().getGroup());
|
||||
contractTable_groupColumn.setCellFactory(param -> new ContractGroupTableCell<>(getContractGroupService()));
|
||||
|
||||
contractTable_typeColumn.setCellValueFactory(param -> param.getValue().getType());
|
||||
contractTable_typeColumn.setCellFactory(param -> new ContractTypeTableCell<>(getContractTypeService()));
|
||||
|
||||
contractTable_kindColumn.setCellValueFactory(param -> param.getValue().getKind());
|
||||
contractTable_kindColumn.setCellFactory(param -> new ContractKindTableCell<>(getContractKindService()));
|
||||
|
||||
|
||||
contractTable_parentCodeColumn.setCellValueFactory(param -> param.getValue().getParentCode());
|
||||
contractTable_orderDateColumn.setCellValueFactory(param -> param.getValue().getOrderDate());
|
||||
contractTable_startDateColumn.setCellValueFactory(param -> param.getValue().getStartDate());
|
||||
contractTable_endDateColumn.setCellValueFactory(param -> param.getValue().getEndDate());
|
||||
contractTable_setupPersonColumn.setCellValueFactory(param -> param.getValue().getSetupPerson());
|
||||
contractTable_setupPersonColumn.setCellFactory(param -> new EmployeeTableCell<>(getEmployeeService()));
|
||||
|
||||
contractTable_setupDateColumn.setCellValueFactory(param -> param.getValue().getSetupDate());
|
||||
// contractTable_setupDateColumn.setSortable(true);
|
||||
// contractTable_setupDateColumn.setSortType(TableColumn.SortType.DESCENDING);
|
||||
contractTable_inurePersonColumn.setCellValueFactory(param -> param.getValue().getInurePerson());
|
||||
contractTable_inurePersonColumn.setCellFactory(param -> new EmployeeTableCell<>(getEmployeeService()));
|
||||
|
||||
contractTable_inureDateColumn.setCellValueFactory(param -> param.getValue().getInureDate());
|
||||
|
||||
contractTable_varyPersonColumn.setCellValueFactory(param -> param.getValue().getVaryPerson());
|
||||
contractTable_varyPersonColumn.setCellFactory(param->new EmployeeTableCell<>(getEmployeeService()));
|
||||
|
||||
contractTable_varyDateColumn.setCellValueFactory(param -> param.getValue().getVaryDate());
|
||||
contractTable_createdColumn.setCellValueFactory(param -> param.getValue().getCreated());
|
||||
contractTable_createdColumn.setCellFactory(param -> new LocalDateTimeTableCell<>());
|
||||
|
||||
|
||||
contractTable_menu_refresh.setOnAction(this::onTableRefreshAction);
|
||||
// contractTable_menu_add.setOnAction(this::onTableAddAction);
|
||||
contractTable_menu_del.setOnAction(this::onTableDeleteAction);
|
||||
contractTable_menu_open_in_explorer.setOnAction(this::onTableOpenInExplorerAction);
|
||||
contractTable_menu_update.setOnAction(this::onTableUpdateAction);
|
||||
|
||||
|
||||
super.initializeTab();
|
||||
}
|
||||
|
||||
|
||||
private void onTableUpdateAction(ActionEvent event) {
|
||||
ContractRepairByCompanyTask task = new ContractRepairByCompanyTask();
|
||||
task.setContractService(getViewModelService());
|
||||
task.setCompany(getParent());
|
||||
UITools.showTaskDialogAndWait("同步合同", task, null);
|
||||
if (task.isRepaired()) {
|
||||
loadTableDataSet();
|
||||
}
|
||||
}
|
||||
|
||||
private void onTableOpenInExplorerAction(ActionEvent event) {
|
||||
ContractViewModel selectedItem = getSelectedItem();
|
||||
if (selectedItem != null) {
|
||||
showInExplorer(selectedItem.getPath().get());
|
||||
}
|
||||
}
|
||||
|
||||
private void showInExplorer(String path) {
|
||||
if (!StringUtils.hasText(path)) {
|
||||
setStatus("文件/目录为空,无法打开");
|
||||
return;
|
||||
}
|
||||
File file = new File(path);
|
||||
if (!file.exists()) {
|
||||
if (file.isFile()) {
|
||||
setStatus("文件 " + file.getAbsolutePath() + " 不存在,请确认");
|
||||
} else {
|
||||
setStatus("目录 " + file.getAbsolutePath() + " 不存在,请确认");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
DesktopUtils.showInExplorer(file);
|
||||
setStatus("打开文件/目录 " + path);
|
||||
} catch (Exception e) {
|
||||
setStatus("打开文件错误:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTableRowDoubleClickedAction(ContractViewModel item) {
|
||||
ContractWindowController.show(item, controller.root.getScene().getWindow());
|
||||
}
|
||||
|
||||
protected ContractService getViewModelService() {
|
||||
if (contractService == null) {
|
||||
contractService = getBean(ContractService.class);
|
||||
}
|
||||
return contractService;
|
||||
}
|
||||
|
||||
private ContractTypeService getContractTypeService() {
|
||||
if (contractTypeService == null) {
|
||||
contractTypeService = getBean(ContractTypeService.class);
|
||||
}
|
||||
return contractTypeService;
|
||||
}
|
||||
|
||||
private ContractKindService getContractKindService() {
|
||||
if (contractKindService == null) {
|
||||
contractKindService = getBean(ContractKindService.class);
|
||||
}
|
||||
return contractKindService;
|
||||
}
|
||||
|
||||
private ContractGroupService getContractGroupService() {
|
||||
if (contractGroupService == null) {
|
||||
contractGroupService = getBean(ContractGroupService.class);
|
||||
}
|
||||
return contractGroupService;
|
||||
}
|
||||
|
||||
private EmployeeStringConverter getEmployeeStringConverter() {
|
||||
if (employeeStringConverter == null) {
|
||||
employeeStringConverter = getBean(EmployeeStringConverter.class);
|
||||
}
|
||||
return employeeStringConverter;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,378 +0,0 @@
|
||||
package com.ecep.contract.manager.ds.company.controller;
|
||||
|
||||
import com.ecep.contract.manager.MyProperties;
|
||||
import com.ecep.contract.manager.cloud.tyc.CloudTycService;
|
||||
import com.ecep.contract.manager.ds.company.CompanyFileType;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.model.CompanyFile;
|
||||
import com.ecep.contract.manager.ds.company.model.CompanyFileTypeLocal;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyFileService;
|
||||
import com.ecep.contract.manager.ds.company.vo.CompanyFileViewModel;
|
||||
import com.ecep.contract.manager.ui.table.EditableEntityTableTabSkin;
|
||||
import com.ecep.contract.manager.ui.FxmlPath;
|
||||
import com.ecep.contract.manager.ui.tab.TabSkin;
|
||||
import com.ecep.contract.manager.util.DesktopUtils;
|
||||
import com.ecep.contract.manager.util.MyDateTimeUtils;
|
||||
import com.ecep.contract.manager.util.UITools;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableMap;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.Event;
|
||||
import javafx.scene.control.*;
|
||||
import lombok.Setter;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@FxmlPath("/ui/company/company-tab-file.fxml")
|
||||
public class CompanyTabSkinFile
|
||||
extends AbstCompanyTableTabSkin<CompanyFile, CompanyFileViewModel>
|
||||
implements TabSkin, EditableEntityTableTabSkin<CompanyFile, CompanyFileViewModel> {
|
||||
|
||||
public TableColumn<CompanyFileViewModel, Number> idColumn;
|
||||
public TableColumn<CompanyFileViewModel, String> typeColumn;
|
||||
public TableColumn<CompanyFileViewModel, String> filePathColumn;
|
||||
public TableColumn<CompanyFileViewModel, LocalDate> applyDateColumn;
|
||||
public TableColumn<CompanyFileViewModel, LocalDate> expiringDateColumn;
|
||||
|
||||
public Button fileTable_file_move_btn;
|
||||
public Button fileTable_file_retrieve_from_download_dir_btn;
|
||||
public Button fileTable_file_reset_btn;
|
||||
public MenuItem fileTable_menu_refresh;
|
||||
public MenuItem fileTable_menu_del;
|
||||
public MenuItem fileTable_menu_copy_as_matched_by_contract;
|
||||
|
||||
@Setter
|
||||
private CompanyFileService companyFileService;
|
||||
@Setter
|
||||
private MyProperties myProperties;
|
||||
private final ObservableMap<CompanyFileType, CompanyFileTypeLocal> fileTypeLocalMap = FXCollections.observableHashMap();
|
||||
|
||||
public CompanyTabSkinFile(CompanyWindowController controller) {
|
||||
super(controller);
|
||||
setDragAndDrop(true);
|
||||
setDragAndDropFileHandler(this::moveFileToCompany);
|
||||
}
|
||||
|
||||
CompanyFileService getCompanyFileService() {
|
||||
if (companyFileService == null) {
|
||||
companyFileService = getBean(CompanyFileService.class);
|
||||
}
|
||||
return companyFileService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tab getTab() {
|
||||
return controller.fileTab;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeTable() {
|
||||
super.initializeTable();
|
||||
fileTable_file_move_btn.setOnAction(this::onTableMoveFileAction);
|
||||
fileTable_file_retrieve_from_download_dir_btn.setOnAction(this::onTableRetrieveFromDownloadDirAction);
|
||||
fileTable_file_reset_btn.setOnAction(this::onTableResetAction);
|
||||
|
||||
|
||||
idColumn.setCellValueFactory(param -> param.getValue().getId());
|
||||
|
||||
typeColumn.setCellValueFactory(param -> Bindings.valueAt(fileTypeLocalMap, param.getValue().getType()).map(CompanyFileTypeLocal::getValue));
|
||||
filePathColumn.setCellValueFactory(param -> param.getValue().getFilePath());
|
||||
filePathColumn.setCellFactory(param -> new FileTableFilePathTableCell());
|
||||
applyDateColumn.setCellValueFactory(param -> param.getValue().getApplyDate());
|
||||
expiringDateColumn.setCellValueFactory(param -> param.getValue().getExpiringDate());
|
||||
|
||||
|
||||
fileTable_menu_refresh.setOnAction(this::onTableRefreshAction);
|
||||
fileTable_menu_del.setOnAction(this::onTableDeleteAction);
|
||||
fileTable_menu_copy_as_matched_by_contract.setOnAction(this::onTableCopyAsMatchedByContractAction);
|
||||
fileTable_menu_copy_as_matched_by_contract.setOnMenuValidation(this::onTableCopyAsMatchedMenuValidation);
|
||||
|
||||
fileTypeLocalMap.putAll(getCompanyFileService().findAllFileTypes(getLocale().toLanguageTag()));
|
||||
}
|
||||
|
||||
private void onTableResetAction(ActionEvent event) {
|
||||
runAsync(() -> {
|
||||
if (getViewModelService().reBuildingFiles(getParent(), this::setStatus)) {
|
||||
loadTableDataSet();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 下载目录 中查找相关的资质文件
|
||||
*/
|
||||
private void onTableRetrieveFromDownloadDirAction(ActionEvent event) {
|
||||
Company company = getParent();
|
||||
MyProperties myProperties = getMyProperties();
|
||||
File dir = myProperties.getDownloadDirectory();
|
||||
if (!dir.exists()) {
|
||||
setStatus("下载目录 " + dir.getAbsolutePath() + " 不存在,请检查");
|
||||
return;
|
||||
}
|
||||
|
||||
setStatus("开始检索 下载 文件夹:" + dir.getAbsolutePath() + "...");
|
||||
File[] files = dir.listFiles(File::isFile);
|
||||
if (files == null) {
|
||||
setStatus("检索 下载 文件夹失败");
|
||||
return;
|
||||
}
|
||||
if (files.length == 0) {
|
||||
setStatus("下载 文件夹没有文件");
|
||||
return;
|
||||
}
|
||||
setStatus("下载 文件夹中共有文件 " + files.length + " 个文件");
|
||||
|
||||
if (getParentService().retrieveFromDownloadFiles(company, files, this::setStatus)) {
|
||||
// fixed if update
|
||||
viewModel.update(company);
|
||||
loadTableDataSet();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 把文件从 老系统中移到 \\10.84.209.8\项目信息\相关方信息 目录中
|
||||
*/
|
||||
private void onTableMoveFileAction(ActionEvent event) {
|
||||
CompanyFileService companyFileService = getViewModelService();
|
||||
Company company = getParent();
|
||||
List<CompanyFile> list = companyFileService.findByCompany(company);
|
||||
if (list.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (getParentService().makePathAbsent(company)) {
|
||||
save(company);
|
||||
}
|
||||
|
||||
String path = company.getPath();
|
||||
if (!StringUtils.hasText(path)) {
|
||||
setStatus("异常, 企业目录未设置");
|
||||
return;
|
||||
}
|
||||
File companyPath = new File(path);
|
||||
for (CompanyFile companyFile : list) {
|
||||
String filePath = companyFile.getFilePath();
|
||||
if (StringUtils.hasText(filePath)) {
|
||||
File file = new File(filePath);
|
||||
if (file.exists()) {
|
||||
if (file.getParentFile().equals(companyPath)) {
|
||||
continue;
|
||||
}
|
||||
File dest = new File(companyPath, file.getName());
|
||||
if (file.renameTo(dest)) {
|
||||
companyFile.setFilePath(dest.getAbsolutePath());
|
||||
companyFileService.save(companyFile);
|
||||
setStatus(file.getName() + " 移动到 " + companyPath.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void onTableCopyAsMatchedByContractAction(ActionEvent event) {
|
||||
UITools.showDialogAndWait("复制资信评估报告", "按当前评估报告复制一个合同中最匹配的", list -> {
|
||||
onTableCopyAsMatchedAction_(msg -> {
|
||||
Platform.runLater(() -> {
|
||||
list.add(msg);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private void onTableCopyAsMatchedAction_(Consumer<String> state) {
|
||||
Company company = getParent();
|
||||
|
||||
CompanyFileViewModel selectedItem = getSelectedItem();
|
||||
if (selectedItem == null) {
|
||||
state.accept("未选择行");
|
||||
return;
|
||||
}
|
||||
if (selectedItem.getApplyDate().get() == null) {
|
||||
state.accept("有效日期不能未空");
|
||||
return;
|
||||
}
|
||||
|
||||
LocalDate nextCreditReportDate = null;
|
||||
try {
|
||||
nextCreditReportDate = getViewModelService().getNextCreditReportDate(company, state);
|
||||
if (nextCreditReportDate == null) {
|
||||
state.accept("没有找到下一个咨询评估日期");
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
state.accept("获取下一个咨询评估日期失败:" + e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
state.accept("下一个咨询评估日期:" + nextCreditReportDate);
|
||||
|
||||
if (!nextCreditReportDate.isBefore(selectedItem.getApplyDate().get())) {
|
||||
state.accept("咨询评估日期晚于下一个咨询评估日期");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
File src = new File(selectedItem.getFilePath().get());
|
||||
if (!src.exists()) {
|
||||
state.accept("当前选择行的文件不存在");
|
||||
return;
|
||||
}
|
||||
|
||||
String srcDate = MyDateTimeUtils.format(selectedItem.getApplyDate().get());
|
||||
String destDate = MyDateTimeUtils.format(nextCreditReportDate);
|
||||
String srcFileName = src.getName();
|
||||
String destFileName;
|
||||
|
||||
// 天眼查的报告
|
||||
if (CloudTycService.isTycReport(srcFileName)) {
|
||||
state.accept("天眼查的报告按标准格式命名");
|
||||
String name = company.getName() + "_" + CloudTycService.NAME;
|
||||
if (srcFileName.contains(CloudTycService.TYC_ENTERPRISE_BASIC_REPORT)) {
|
||||
name = name + "_" + CloudTycService.TYC_ENTERPRISE_BASIC_REPORT;
|
||||
} else if (srcFileName.contains(CloudTycService.TYC_ENTERPRISE_MAJOR_REPORT)) {
|
||||
name = name + "_" + CloudTycService.TYC_ENTERPRISE_MAJOR_REPORT;
|
||||
} else if (srcFileName.contains(CloudTycService.TYC_ENTERPRISE_ANALYSIS_REPORT)) {
|
||||
name = name + "_" + CloudTycService.TYC_ENTERPRISE_ANALYSIS_REPORT;
|
||||
}
|
||||
destFileName = name + "_" + destDate + "_cp." + StringUtils.getFilenameExtension(srcFileName);
|
||||
} else {
|
||||
if (srcFileName.contains(srcDate)) {
|
||||
// 如果文件名中包含日期,则替换为新日期
|
||||
destFileName = srcFileName.replace(srcDate, destDate + "_cp");
|
||||
} else {
|
||||
// 如果文件名中不包含日期,则添加日期
|
||||
destFileName = company.getName() + "_" + destDate + "_cp." + StringUtils.getFilenameExtension(srcFileName);
|
||||
}
|
||||
}
|
||||
|
||||
state.accept("新文件名:" + destFileName);
|
||||
|
||||
File dest = new File(src.getParent(), destFileName);
|
||||
try {
|
||||
FileSystemUtils.copyRecursively(src, dest);
|
||||
state.accept("新文件复制成功");
|
||||
} catch (IOException e) {
|
||||
state.accept("新文件复制失败:" + e.getMessage());
|
||||
}
|
||||
|
||||
CompanyFile companyFile = new CompanyFile();
|
||||
companyFile.setFilePath(dest.getAbsolutePath());
|
||||
companyFile.setApplyDate(nextCreditReportDate);
|
||||
companyFile.setExpiringDate(nextCreditReportDate.plusYears(1));
|
||||
companyFile.setType(CompanyFileType.CreditReport);
|
||||
companyFile.setCompany(company);
|
||||
saveRowData(companyFile);
|
||||
|
||||
state.accept("新文件已记录");
|
||||
|
||||
loadTableDataSet();
|
||||
state.accept("文件表已刷新");
|
||||
}
|
||||
|
||||
/**
|
||||
* 当fileTable选中的行是咨询评估时,可用
|
||||
*
|
||||
* @param event event
|
||||
*/
|
||||
public void onTableCopyAsMatchedMenuValidation(Event event) {
|
||||
//当fileTable选中的行是咨询评估时,可用
|
||||
CompanyFileViewModel selectedItem = getSelectedItem();
|
||||
if (selectedItem == null) {
|
||||
event.consume();
|
||||
return;
|
||||
}
|
||||
CompanyFileType type = selectedItem.getType().get();
|
||||
if (type != CompanyFileType.CreditReport) {
|
||||
event.consume();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean deleteRow(CompanyFileViewModel row) {
|
||||
String path = row.getFilePath().get();
|
||||
if (super.deleteRow(row)) {
|
||||
File file = new File(path);
|
||||
if (file.exists()) {
|
||||
UITools.showConfirmation("数据记录已经删除,请确认是否删除物理文件", path).thenAccept(buttonType -> {
|
||||
if (buttonType == ButtonType.OK) {
|
||||
if (file.delete()) {
|
||||
setStatus("删除文件 " + path);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private void moveFileToCompany(List<File> files) {
|
||||
String path = viewModel.getPath().get();
|
||||
if (!StringUtils.hasText(path)) {
|
||||
setStatus("未设置目录");
|
||||
return;
|
||||
}
|
||||
File dir = new File(path);
|
||||
if (!dir.exists()) {
|
||||
setStatus("目录错误,不存在");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTableRowDoubleClickedAction(CompanyFileViewModel item) {
|
||||
String path = item.getFilePath().get();
|
||||
if (StringUtils.hasText(path)) {
|
||||
File file = new File(path);
|
||||
if (!file.exists()) {
|
||||
setStatus("文件不存在 " + file.getName());
|
||||
return;
|
||||
}
|
||||
DesktopUtils.showInExplorer(file);
|
||||
}
|
||||
}
|
||||
|
||||
class FileTableFilePathTableCell extends TableCell<CompanyFileViewModel, String> {
|
||||
@Override
|
||||
protected void updateItem(String item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (empty || item == null) {
|
||||
setText("");
|
||||
return;
|
||||
}
|
||||
String path = viewModel.getPath().get();
|
||||
if (StringUtils.hasText(path)) {
|
||||
if (item.startsWith(path)) {
|
||||
item = "~" + item.substring(path.length());
|
||||
}
|
||||
}
|
||||
setText(item);
|
||||
}
|
||||
}
|
||||
|
||||
public MyProperties getMyProperties() {
|
||||
if (myProperties == null) {
|
||||
myProperties = getBean(MyProperties.class);
|
||||
}
|
||||
return myProperties;
|
||||
}
|
||||
|
||||
protected CompanyFileService getViewModelService() {
|
||||
return getCompanyFileService();
|
||||
}
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
package com.ecep.contract.manager.ds.company.controller;
|
||||
|
||||
import com.ecep.contract.manager.cloud.u8.YongYouU8Service;
|
||||
import com.ecep.contract.manager.ds.company.model.Invoice;
|
||||
import com.ecep.contract.manager.ds.company.service.InvoiceService;
|
||||
import com.ecep.contract.manager.ds.company.vo.InvoiceViewModel;
|
||||
import com.ecep.contract.manager.ds.contract.service.PurchaseBillVoucherService;
|
||||
import com.ecep.contract.manager.ds.other.EmployeeStringConverter;
|
||||
import com.ecep.contract.manager.ui.table.EditableEntityTableTabSkin;
|
||||
import com.ecep.contract.manager.ui.FxmlPath;
|
||||
import com.ecep.contract.manager.ui.tab.TabSkin;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Tab;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import lombok.Setter;
|
||||
import org.springframework.beans.BeansException;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* 子合同
|
||||
*/
|
||||
@FxmlPath("/ui/company/company-tab-invoice.fxml")
|
||||
public class CompanyTabSkinInvoice
|
||||
extends AbstCompanyTableTabSkin<Invoice, InvoiceViewModel>
|
||||
implements TabSkin, EditableEntityTableTabSkin<Invoice, InvoiceViewModel> {
|
||||
|
||||
public TableColumn<InvoiceViewModel, Number> idColumn;
|
||||
public TableColumn<InvoiceViewModel, String> codeColumn;
|
||||
public TableColumn<InvoiceViewModel, LocalDate> dateColumn;
|
||||
public TableColumn<InvoiceViewModel, String> descriptionColumn;
|
||||
|
||||
public TextField searchKeyField;
|
||||
public Button searchBtn;
|
||||
|
||||
@Setter
|
||||
private PurchaseBillVoucherService purchaseBillVoucherService;
|
||||
@Setter
|
||||
private InvoiceService invoiceService;
|
||||
@Setter
|
||||
private YongYouU8Service u8Service;
|
||||
@Setter
|
||||
private EmployeeStringConverter employeeStringConverter;
|
||||
|
||||
public CompanyTabSkinInvoice(CompanyWindowController controller) {
|
||||
super(controller);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tab getTab() {
|
||||
return controller.invoiceTab;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InvoiceService getViewModelService() {
|
||||
return getInvoiceService();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeTab() {
|
||||
|
||||
if (u8Service == null) {
|
||||
try {
|
||||
u8Service = getBean(YongYouU8Service.class);
|
||||
} catch (BeansException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
searchKeyField.setOnKeyReleased(event -> {
|
||||
if (event.getCode() == KeyCode.ENTER) {
|
||||
searchBtn.fire();
|
||||
}
|
||||
});
|
||||
|
||||
searchBtn.setOnAction(this::onTableRefreshAction);
|
||||
searchKeyField.setOnKeyReleased(event -> {
|
||||
if (event.getCode() == KeyCode.ENTER) {
|
||||
searchBtn.fire();
|
||||
}
|
||||
});
|
||||
|
||||
idColumn.setCellValueFactory(param -> param.getValue().getId());
|
||||
codeColumn.setCellValueFactory(param -> param.getValue().getCode());
|
||||
dateColumn.setCellValueFactory(param -> param.getValue().getInvoiceDate());
|
||||
descriptionColumn.setCellValueFactory(param -> param.getValue().getDescription());
|
||||
super.initializeTab();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTableRowDoubleClickedAction(InvoiceViewModel item) {
|
||||
// ContractWindowController.show(item, controller.root.getScene().getWindow());
|
||||
}
|
||||
|
||||
private PurchaseBillVoucherService getPurchaseBillVoucherService() {
|
||||
if (purchaseBillVoucherService == null) {
|
||||
purchaseBillVoucherService = getBean(PurchaseBillVoucherService.class);
|
||||
}
|
||||
return purchaseBillVoucherService;
|
||||
}
|
||||
|
||||
private EmployeeStringConverter getEmployeeStringConverter() {
|
||||
if (employeeStringConverter == null) {
|
||||
employeeStringConverter = getBean(EmployeeStringConverter.class);
|
||||
}
|
||||
return employeeStringConverter;
|
||||
}
|
||||
|
||||
private InvoiceService getInvoiceService() {
|
||||
if (invoiceService == null) {
|
||||
invoiceService = getBean(InvoiceService.class);
|
||||
}
|
||||
return invoiceService;
|
||||
}
|
||||
}
|
||||
@@ -1,208 +0,0 @@
|
||||
package com.ecep.contract.manager.ds.company.controller;
|
||||
|
||||
import com.ecep.contract.manager.ds.company.controller.old_name.CompanyOldNameWindowController;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.model.CompanyOldName;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyOldNameService;
|
||||
import com.ecep.contract.manager.ds.company.vo.CompanyOldNameViewModel;
|
||||
import com.ecep.contract.manager.ui.FxmlPath;
|
||||
import com.ecep.contract.manager.ui.tab.TabSkin;
|
||||
import com.ecep.contract.manager.util.SpecificationUtils;
|
||||
import javafx.application.Platform;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.control.cell.CheckBoxTableCell;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import lombok.Setter;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*曾用名
|
||||
*/
|
||||
@FxmlPath("/ui/company/company-tab-oldname.fxml")
|
||||
public class CompanyTabSkinOldName
|
||||
extends AbstCompanyTableTabSkin<CompanyOldName, CompanyOldNameViewModel>
|
||||
implements TabSkin {
|
||||
|
||||
/**
|
||||
* 以下是曾用名列定义
|
||||
*/
|
||||
public TableColumn<CompanyOldNameViewModel, Number> oldNameTable_idColumn;
|
||||
public TableColumn<CompanyOldNameViewModel, String> oldNameTable_nameColumn;
|
||||
public TableColumn<CompanyOldNameViewModel, LocalDate> oldNameTable_beginDateColumn;
|
||||
public TableColumn<CompanyOldNameViewModel, LocalDate> oldNameTable_endDateColumn;
|
||||
public TableColumn<CompanyOldNameViewModel, Boolean> oldNameTable_ambiguityColumn;
|
||||
public TableColumn<CompanyOldNameViewModel, String> oldNameTable_pathColumn;
|
||||
public TableColumn<CompanyOldNameViewModel, String> oldNameTable_memoColumn;
|
||||
|
||||
public TextField oldNameSearchKeyField;
|
||||
public Button oldNameSearchBtn;
|
||||
public Button oldNameTable_create_btn;
|
||||
public Button oldNameTable_merge_btn;
|
||||
public MenuItem oldNameTable_menu_refresh;
|
||||
public MenuItem oldNameTable_menu_del;
|
||||
|
||||
@Setter
|
||||
private CompanyOldNameService companyOldNameService;
|
||||
|
||||
public CompanyTabSkinOldName(CompanyWindowController controller) {
|
||||
super(controller);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tab getTab() {
|
||||
return controller.oldNameTab;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Specification<CompanyOldName> getSpecification(Company parent) {
|
||||
return SpecificationUtils.and(getSpecification(), (root, query, builder) -> {
|
||||
return builder.equal(root.get("companyId"), parent.getId());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeTab() {
|
||||
|
||||
oldNameSearchKeyField.setOnKeyReleased(event -> {
|
||||
if (event.getCode() == KeyCode.ENTER) {
|
||||
oldNameSearchBtn.fire();
|
||||
}
|
||||
});
|
||||
|
||||
oldNameSearchBtn.setOnAction(this::onTableRefreshAction);
|
||||
|
||||
oldNameTable_create_btn.setOnAction(this::onTableAddAction);
|
||||
oldNameTable_merge_btn.setOnAction(this::onTableMergeAction);
|
||||
|
||||
oldNameTable_idColumn.setCellValueFactory(param -> param.getValue().getId());
|
||||
oldNameTable_nameColumn.setCellValueFactory(param -> param.getValue().getName());
|
||||
|
||||
oldNameTable_pathColumn.setCellFactory(param -> new FileTableFilePathTableCell());
|
||||
|
||||
oldNameTable_ambiguityColumn.setCellValueFactory(param -> param.getValue().getAmbiguity());
|
||||
oldNameTable_ambiguityColumn.setCellFactory(c -> new CheckBoxTableCell<>());
|
||||
|
||||
oldNameTable_beginDateColumn.setCellValueFactory(param -> param.getValue().getBeginDate());
|
||||
oldNameTable_endDateColumn.setCellValueFactory(param -> param.getValue().getEndDate());
|
||||
|
||||
oldNameTable_memoColumn.setCellValueFactory(param -> param.getValue().getMemo());
|
||||
|
||||
oldNameTable_menu_refresh.setOnAction(this::onTableRefreshAction);
|
||||
oldNameTable_menu_del.setOnAction(this::onTableDeleteAction);
|
||||
|
||||
super.initializeTab();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onTableAddAction(ActionEvent event) {
|
||||
//
|
||||
TextInputDialog dialog = new TextInputDialog();
|
||||
dialog.setHeaderText("请输入曾用名");
|
||||
dialog.setTitle("新建曾用名");
|
||||
Optional<String> optional = dialog.showAndWait();
|
||||
if (optional.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
CompanyOldName oldName = new CompanyOldName();
|
||||
oldName.setName(optional.get());
|
||||
oldName.setCompanyId(viewModel.getId().get());
|
||||
oldName.setAmbiguity(true);
|
||||
getViewModelService().save(oldName);
|
||||
loadTableDataSet();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean deleteRow(CompanyOldNameViewModel row) {
|
||||
CompanyOldName entity = getViewModelService().findById(row.getId().get());
|
||||
if (entity != null) {
|
||||
getViewModelService().delete(entity);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void onTableMergeAction(ActionEvent event) {
|
||||
Company updater = getParent();
|
||||
HashSet<String> nameSet = new HashSet<>();
|
||||
nameSet.add(updater.getName());
|
||||
|
||||
List<CompanyOldNameViewModel> removes = new ArrayList<>();
|
||||
for (CompanyOldNameViewModel viewModel : dataSet) {
|
||||
if (!nameSet.add(viewModel.getName().get())) {
|
||||
// fixed 曾用名中有重复时,删除重复的
|
||||
getViewModelService().delete(viewModel);
|
||||
removes.add(viewModel);
|
||||
}
|
||||
}
|
||||
if (!removes.isEmpty()) {
|
||||
Platform.runLater(() -> {
|
||||
dataSet.removeAll(removes);
|
||||
});
|
||||
setStatus("移除重复的曾用名" + removes.size());
|
||||
}
|
||||
|
||||
int size = nameSet.size();
|
||||
int count = 1;
|
||||
int merge = 0;
|
||||
for (String name : nameSet) {
|
||||
controller.setRightStatus(count + "/" + size);
|
||||
if (StringUtils.hasText(name)) {
|
||||
List<Company> list = getParentService().findAllByName(name);
|
||||
for (Company company : list) {
|
||||
// fixed 曾用名中有可能有 updater 的名字,会导致自己删除自己
|
||||
if (Objects.equals(company.getId(), updater.getId())) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
getCompanyService().merge(company, updater);
|
||||
setStatus("并户 " + company.getName() + "[" + company.getId() + "] 到当前公司");
|
||||
merge++;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("合并 " + company.getName() + " -> " + updater.getName() + " 失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
count++;
|
||||
}
|
||||
if (merge == 0) {
|
||||
setStatus("没有需要并户的公司");
|
||||
}
|
||||
controller.setRightStatus("");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTableRowDoubleClickedAction(CompanyOldNameViewModel item) {
|
||||
CompanyOldNameWindowController.show(item, controller.root.getScene().getWindow());
|
||||
}
|
||||
|
||||
class FileTableFilePathTableCell extends TableCell<CompanyOldNameViewModel, String> {
|
||||
@Override
|
||||
protected void updateItem(String item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (empty || item == null) {
|
||||
setText("");
|
||||
return;
|
||||
}
|
||||
String path = viewModel.getPath().get();
|
||||
if (StringUtils.hasText(path)) {
|
||||
if (item.startsWith(path)) {
|
||||
item = "~" + item.substring(path.length());
|
||||
}
|
||||
}
|
||||
setText(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected CompanyOldNameService getViewModelService() {
|
||||
if (companyOldNameService == null) {
|
||||
companyOldNameService = getBean(CompanyOldNameService.class);
|
||||
}
|
||||
return companyOldNameService;
|
||||
}
|
||||
}
|
||||
@@ -1,647 +0,0 @@
|
||||
package com.ecep.contract.manager.ds.company.controller;
|
||||
|
||||
import com.ecep.contract.manager.cloud.rk.CloudRk;
|
||||
import com.ecep.contract.manager.cloud.rk.CloudRkInfoViewModel;
|
||||
import com.ecep.contract.manager.cloud.rk.CloudRkService;
|
||||
import com.ecep.contract.manager.cloud.rk.ctx.CloudRkCtx;
|
||||
import com.ecep.contract.manager.cloud.tyc.CloudTyc;
|
||||
import com.ecep.contract.manager.cloud.tyc.CloudTycInfoViewModel;
|
||||
import com.ecep.contract.manager.cloud.tyc.CloudTycService;
|
||||
import com.ecep.contract.manager.cloud.u8.CloudYu;
|
||||
import com.ecep.contract.manager.cloud.u8.CloudYuInfoViewModel;
|
||||
import com.ecep.contract.manager.cloud.u8.YongYouU8Service;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.model.CompanyExtendInfo;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyExtendInfoService;
|
||||
import com.ecep.contract.manager.ds.company.vo.CompanyExtendInfoViewModel;
|
||||
import com.ecep.contract.manager.ui.FxmlPath;
|
||||
import com.ecep.contract.manager.ui.MessageHolder;
|
||||
import com.ecep.contract.manager.ui.tab.TabSkin;
|
||||
import com.ecep.contract.manager.ui.util.DelayOnceExecutor;
|
||||
import com.ecep.contract.manager.util.DesktopUtils;
|
||||
import com.ecep.contract.manager.util.MyDateTimeUtils;
|
||||
import com.ecep.contract.manager.util.UITools;
|
||||
import javafx.application.Platform;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.Border;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.web.WebView;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.util.converter.NumberStringConverter;
|
||||
import lombok.Setter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.w3c.dom.html.HTMLDocument;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@FxmlPath("/ui/company/company-tab-other.fxml")
|
||||
public class CompanyTabSkinOther
|
||||
extends AbstCompanyBasedTabSkin
|
||||
implements TabSkin {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CompanyTabSkinOther.class);
|
||||
/**
|
||||
* 以下是云平台数据
|
||||
*/
|
||||
public TitledPane rkCloudPane;
|
||||
public TextField cloudRkIdField;
|
||||
public TextField cloudRkCloudIdField;
|
||||
public TextField cloudRkLatestField;
|
||||
public TextField cloudRkCustomerGradeField;
|
||||
public TextField cloudRkCustomerScoreField;
|
||||
public TextField cloudRkCustomerDescriptionField;
|
||||
|
||||
public TextField cloudRkVendorGradeField;
|
||||
public TextField cloudRkVendorScoreField;
|
||||
public TextField cloudRkVendorDescriptionField;
|
||||
|
||||
public TextField cloudRkBlackListUpdatedField;
|
||||
public TextField cloudRkCloudLatestField;
|
||||
public TextField cloudRkEntUpdateField;
|
||||
public TextField cloudRkCreditRankField;
|
||||
public TextField cloudRkCreditRankDescriptionField;
|
||||
public Label cloudRkVersionLabel;
|
||||
public CheckBox cloudRkAutoUpdateField;
|
||||
|
||||
|
||||
// Tyc //
|
||||
public TitledPane tycCloudPane;
|
||||
public TextField cloudTycIdField;
|
||||
public TextField cloudTycCloudIdField;
|
||||
public TextField cloudTycLatestField;
|
||||
public Label cloudTycVersionLabel;
|
||||
public TextField tycCloudPaneCloudScore;
|
||||
// public Hyperlink tycCloudPaneHyperLink;
|
||||
public Button tycCloudPaneSaveButton;
|
||||
|
||||
|
||||
// Yu //
|
||||
public TitledPane yuCloudPane;
|
||||
public TextField cloudYuIdField;
|
||||
public TextField cloudYuCloudIdField;
|
||||
public TextField cloudYuLatestField;
|
||||
public Label cloudYuVersionLabel;
|
||||
public Button yuCloudPaneSaveButton;
|
||||
|
||||
// Extend Info //
|
||||
public TitledPane extendInfoPane;
|
||||
public TextField extendInfoIdField;
|
||||
public TextField extendInfoLatestField;
|
||||
public Label extendInfoVersionLabel;
|
||||
public CheckBox extendInfoDisableVerifyField;
|
||||
public Button extendInfoPaneSaveButton;
|
||||
|
||||
private final CloudRkInfoViewModel rkCloudInfoViewModel = new CloudRkInfoViewModel();
|
||||
private final CloudTycInfoViewModel tycCloudInfoViewModel = new CloudTycInfoViewModel();
|
||||
private final CloudYuInfoViewModel yuCloudInfoViewModel = new CloudYuInfoViewModel();
|
||||
private final CompanyExtendInfoViewModel extendInfoViewModel = new CompanyExtendInfoViewModel();
|
||||
|
||||
|
||||
|
||||
@Setter
|
||||
private CloudRkService cloudRkService;
|
||||
@Setter
|
||||
private CloudTycService cloudTycService;
|
||||
@Setter
|
||||
private YongYouU8Service yongYouU8Service;
|
||||
@Setter
|
||||
private CompanyExtendInfoService extendInfoService;
|
||||
|
||||
public CompanyTabSkinOther(CompanyWindowController controller) {
|
||||
super(controller);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tab getTab() {
|
||||
return controller.otherTab;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeTab() {
|
||||
initializeCloudRkPane();
|
||||
initializeCloudTycPane();
|
||||
initializeCloudYuPane();
|
||||
initializeExtendInfoPane();
|
||||
listenTabSelectionChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabShown() {
|
||||
Company parent = getEntity();
|
||||
updateRKCloudPane(parent, rkCloudPane);
|
||||
updateTYCCloudPane(parent, tycCloudPane);
|
||||
updateYuCloudPane(parent, yuCloudPane);
|
||||
updateExtendInfoPane(parent, extendInfoPane);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化 相关方平台信息 Titled Pane
|
||||
*/
|
||||
private void initializeCloudRkPane() {
|
||||
// 记录编号
|
||||
cloudRkIdField.textProperty().bind(rkCloudInfoViewModel.getId().asString());
|
||||
// 平台编号
|
||||
cloudRkCloudIdField.textProperty().bindBidirectional(rkCloudInfoViewModel.getCloudId());
|
||||
cloudRkLatestField.textProperty().bind(rkCloudInfoViewModel.getLatest().map(MyDateTimeUtils::format));
|
||||
cloudRkVersionLabel.textProperty().bind(rkCloudInfoViewModel.getVersion().asString("Ver:%s"));
|
||||
|
||||
cloudRkAutoUpdateField.selectedProperty().bindBidirectional(rkCloudInfoViewModel.getAutoUpdate());
|
||||
|
||||
cloudRkCustomerGradeField.textProperty().bind(rkCloudInfoViewModel.getCustomerGrade());
|
||||
cloudRkCustomerScoreField.textProperty().bind(rkCloudInfoViewModel.getCustomerScore().asString());
|
||||
cloudRkCustomerDescriptionField.textProperty().bind(rkCloudInfoViewModel.getCustomerDescription());
|
||||
|
||||
cloudRkVendorGradeField.textProperty().bind(rkCloudInfoViewModel.getVendorGrade());
|
||||
cloudRkVendorScoreField.textProperty().bind(rkCloudInfoViewModel.getVendorScore().asString());
|
||||
cloudRkVendorDescriptionField.textProperty().bind(rkCloudInfoViewModel.getVendorDescription());
|
||||
|
||||
cloudRkCreditRankField.textProperty().bind(rkCloudInfoViewModel.getRank());
|
||||
cloudRkCreditRankDescriptionField.textProperty().bind(rkCloudInfoViewModel.getRankDescription());
|
||||
cloudRkCloudLatestField.textProperty().bind(rkCloudInfoViewModel.getCloudLatest().map(MyDateTimeUtils::format));
|
||||
cloudRkEntUpdateField.textProperty().bind(rkCloudInfoViewModel.getCloudEntUpdate().map(MyDateTimeUtils::format));
|
||||
cloudRkBlackListUpdatedField.textProperty().bind(rkCloudInfoViewModel.getCloudBlackListUpdated().map(MyDateTimeUtils::format));
|
||||
|
||||
DelayOnceExecutor saveExecutor = new DelayOnceExecutor(() -> {
|
||||
save(rkCloudInfoViewModel);
|
||||
cloudRkAutoUpdateField.setBorder(null);
|
||||
}, 2, TimeUnit.SECONDS).exception(e -> logger.error(e.getMessage(), e));
|
||||
cloudRkAutoUpdateField.setOnMouseClicked(event -> {
|
||||
cloudRkAutoUpdateField.setBorder(Border.stroke(Color.RED));
|
||||
saveExecutor.tick();
|
||||
});
|
||||
}
|
||||
|
||||
public void save(CloudRkInfoViewModel viewModel) {
|
||||
int infoId = viewModel.getId().get();
|
||||
CloudRkService service = getCloudRkService();
|
||||
CloudRk cloudRk = service.findById(infoId);
|
||||
if (cloudRk == null) {
|
||||
throw new RuntimeException("CloudRk not found");
|
||||
}
|
||||
if (viewModel.copyTo(cloudRk)) {
|
||||
CloudRk saved = service.save(cloudRk);
|
||||
if (Platform.isFxApplicationThread()) {
|
||||
viewModel.update(saved);
|
||||
} else {
|
||||
Platform.runLater(() -> {
|
||||
viewModel.update(saved);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 杂项页中,集团相关方panel中更新action
|
||||
*/
|
||||
public void onCloudRkUpdateButtonClickedAction(ActionEvent event) {
|
||||
Button button = (Button) event.getSource();
|
||||
button.setDisable(true);
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
onCloudRkUpdateButtonClicked(event);
|
||||
} catch (Exception e) {
|
||||
UITools.showExceptionAndWait("", e);
|
||||
}
|
||||
}).whenComplete((v, e) -> {
|
||||
button.setDisable(false);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 从集团相关方平台中更新公司信息
|
||||
*
|
||||
* @see #onCloudRkUpdateButtonClickedAction(ActionEvent)
|
||||
*/
|
||||
private void onCloudRkUpdateButtonClicked(ActionEvent actionEvent) throws IOException {
|
||||
Button button = (Button) actionEvent.getSource();
|
||||
|
||||
Company company = getEntity();
|
||||
|
||||
CloudRkCtx cloudRkCtx = new CloudRkCtx();
|
||||
cloudRkCtx.setCloudRkService(getCloudRkService());
|
||||
CloudRk cloudRk = cloudRkCtx.getOrCreateCloudRk(company);
|
||||
|
||||
MessageHolder holder = (level, message) -> {
|
||||
setStatus(message);
|
||||
if (level == Level.WARNING) {
|
||||
logger.warn("{} {}", getEntity().getName(), message);
|
||||
}
|
||||
if (level == Level.SEVERE) {
|
||||
logger.error("{} {}", getEntity().getName(), message);
|
||||
}
|
||||
};
|
||||
|
||||
if (!StringUtils.hasText(rkCloudInfoViewModel.getCloudId().get())) {
|
||||
holder.info("没有 " + CloudRkService.NAME + " 编号,准备使用模糊查询接口获取编号...");
|
||||
// use fuzzy to find cloud id
|
||||
try {
|
||||
//
|
||||
List<CloudRkService.EntInfo> entInfos = cloudRkCtx.queryEnterpriseWithFuzzy(company, cloudRk, holder);
|
||||
if (entInfos.isEmpty()) {
|
||||
cloudRk.setCloudId("-");
|
||||
cloudRkCtx.save(cloudRk);
|
||||
holder.error("没有查询到相关企业信息");
|
||||
return;
|
||||
}
|
||||
String companyName = company.getName();
|
||||
Optional<CloudRkService.EntInfo> optional = entInfos.stream()
|
||||
.filter(n -> n.getName().equals(companyName)).findAny();
|
||||
if (optional.isPresent()) {
|
||||
// 查询接口中返回的结果中有跟公司名称相同的,则直接使用
|
||||
cloudRk.setCloudId(optional.get().getId());
|
||||
} else {
|
||||
// 手动选择
|
||||
CloudRkService.EntInfo selectedItem = showEnterpriseChooser(entInfos);
|
||||
if (selectedItem != null) {
|
||||
cloudRk.setCloudId(selectedItem.getId());
|
||||
rkCloudInfoViewModel.update(cloudRkCtx.save(cloudRk));
|
||||
// 重新发起
|
||||
button.getOnAction().handle(actionEvent);
|
||||
}
|
||||
|
||||
Platform.runLater(() -> {
|
||||
|
||||
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
// 异常
|
||||
UITools.showExceptionAndWait(CloudRkService.NAME + " 中使用模糊查询接口获取企业平台编号发生错误", e);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(cloudRk.getCloudId())) {
|
||||
setStatus("没有平台编号, 无法更新");
|
||||
return;
|
||||
}
|
||||
if (cloudRk.getCloudId().equals("-")) {
|
||||
setStatus("更新已经屏蔽");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
rkCloudInfoViewModel.getLatest().set(null);
|
||||
setStatus("尝试从 " + CloudRkService.NAME + " 中更新企业信息...");
|
||||
if (cloudRkCtx.updateEnterpriseInfo(company, cloudRk, holder)) {
|
||||
company = save(company);
|
||||
}
|
||||
|
||||
setStatus("尝试从 " + CloudRkService.NAME + " 中更新黑名单...");
|
||||
if (cloudRkCtx.updateBlackList(company, cloudRk, holder)) {
|
||||
CompanyTabSkinOldName tabSkin = controller.getTabSkin(CompanyTabSkinOldName.class);
|
||||
if (tabSkin != null) {
|
||||
tabSkin.loadTableDataSet();
|
||||
}
|
||||
}
|
||||
|
||||
setStatus("尝试从 " + CloudRkService.NAME + " 中更新企业评分...");
|
||||
if (cloudRkCtx.updateEnterpriseCredit(company, cloudRk, holder)) {
|
||||
// cloudRk modified
|
||||
}
|
||||
setStatus("尝试从 " + CloudRkService.NAME + " 中更新客户评级...");
|
||||
if (cloudRkCtx.updateCustomerScore(company, cloudRk, holder)) {
|
||||
// cloudRk modified
|
||||
}
|
||||
setStatus("尝试从 " + CloudRkService.NAME + " 中更新供应商评分...");
|
||||
if (cloudRkCtx.updateVendorScore(company, cloudRk, holder)) {
|
||||
// cloudRk modified
|
||||
}
|
||||
setStatus("");
|
||||
} catch (Exception e) {
|
||||
// 异常
|
||||
logger.error("更新 {} 时发生错误", company.getName(), e);
|
||||
UITools.showExceptionAndWait(CloudRkService.NAME + " 中使用报表接口更新企业基本注册信息时发生错误", e);
|
||||
return;
|
||||
} finally {
|
||||
cloudRk.setLatestUpdate(Instant.now());
|
||||
CloudRk cloudRk1 = cloudRkCtx.save(cloudRk);
|
||||
Platform.runLater(() -> {
|
||||
rkCloudInfoViewModel.update(cloudRk1);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private CloudRkService.EntInfo showEnterpriseChooser(List<CloudRkService.EntInfo> entInfos) {
|
||||
// TODO 转换为 独立窗口类,通过 getResult() 返回操作
|
||||
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
|
||||
alert.setWidth(350);
|
||||
alert.setHeaderText(CloudRkService.NAME + " 返回多个结果, 请选择确认");
|
||||
ListView<CloudRkService.EntInfo> listView = new ListView<>();
|
||||
listView.setCellFactory(param -> new ListCell<>() {
|
||||
@Override
|
||||
protected void updateItem(CloudRkService.EntInfo item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (item == null || empty) {
|
||||
setText(null);
|
||||
// setBackground(Background.EMPTY);
|
||||
} else {
|
||||
setText((item.isNowName() ? "☑" : "☐") + " " + item.getName());
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
listView.getItems().addAll(entInfos);
|
||||
alert.getDialogPane().setContent(listView);
|
||||
if (alert.showAndWait().get() != ButtonType.OK) {
|
||||
return null;
|
||||
}
|
||||
return listView.getSelectionModel().getSelectedItem();
|
||||
}
|
||||
|
||||
|
||||
public void onTycCloudPaneHyperLinkClickedAction(ActionEvent event) {
|
||||
String cloudId = tycCloudInfoViewModel.getCloudId().get();
|
||||
String url = null;
|
||||
if (StringUtils.hasText(cloudId)) {
|
||||
url = String.format(CloudTycService.URL_COMPANY, cloudId);
|
||||
} else {
|
||||
Company company = getEntity();
|
||||
url = String.format(CloudTycService.URL_COMPANY_SEARCH, company.getName());
|
||||
}
|
||||
DesktopUtils.showInBrowse(url);
|
||||
}
|
||||
|
||||
public void onTycCloudPaneHyperLinkInnerViewClickedAction(ActionEvent event) {
|
||||
Company company = getEntity();
|
||||
String cloudId = tycCloudInfoViewModel.getCloudId().get();
|
||||
String url = "https://www.tianyancha.com/search?key=" + company.getName();
|
||||
Stage stage = new Stage();
|
||||
WebView webView = new WebView();
|
||||
webView.getEngine().locationProperty().addListener((ob, old, n) -> {
|
||||
System.out.println("location " + old + " -> " + n);
|
||||
});
|
||||
webView.getEngine().getLoadWorker().exceptionProperty().addListener((ob, old, n) -> {
|
||||
System.out.println("LoadWorker exception:" + n);
|
||||
});
|
||||
webView.getEngine().setCreatePopupHandler(p -> {
|
||||
System.out.println("Popup = " + p);
|
||||
return webView.getEngine();
|
||||
});
|
||||
|
||||
webView.getEngine().setPromptHandler(p -> {
|
||||
System.out.println("Prompt = " + p);
|
||||
return null;
|
||||
});
|
||||
|
||||
webView.getEngine().setConfirmHandler(p -> {
|
||||
System.out.println("Confirm = " + p);
|
||||
return null;
|
||||
});
|
||||
webView.getEngine().getLoadWorker().stateProperty().addListener((ob, old, n) -> {
|
||||
System.out.println("LoadWorker state:" + n);
|
||||
});
|
||||
webView.getEngine().getLoadWorker().progressProperty().addListener((ob, old, n) -> {
|
||||
System.out.println("LoadWorker progress:" + n);
|
||||
});
|
||||
|
||||
File directory = new File(".");
|
||||
System.out.println(". = " + directory.getAbsolutePath());
|
||||
webView.getEngine().setUserDataDirectory(directory);
|
||||
|
||||
webView.getEngine().load(url);
|
||||
webView.getEngine().documentProperty().addListener(((observable, oldValue, newValue) -> {
|
||||
if (newValue == null) {
|
||||
return;
|
||||
}
|
||||
HTMLDocument doc = (HTMLDocument) newValue;
|
||||
setStatus("Open Url : " + doc.getURL());
|
||||
stage.setTitle(doc.getTitle());
|
||||
// updateByTycSearch(company, doc);
|
||||
}));
|
||||
StackPane root = new StackPane();
|
||||
root.getChildren().add(webView);
|
||||
Scene scene = new Scene(root);
|
||||
stage.setScene(scene);
|
||||
stage.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* 杂项 天眼查页,更新按钮 action
|
||||
*/
|
||||
public void onCloudTycUpdateButtonClickedAction(ActionEvent event) {
|
||||
Button button = (Button) event.getSource();
|
||||
button.setDisable(true);
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
onCloudTycUpdateButtonClicked(event);
|
||||
} catch (Exception e) {
|
||||
UITools.showExceptionAndWait("", e);
|
||||
}
|
||||
}).whenComplete((v, e) -> {
|
||||
button.setDisable(false);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新 天眼查 资讯资信
|
||||
*
|
||||
* @see #onCloudTycUpdateButtonClickedAction(ActionEvent)
|
||||
*/
|
||||
private void onCloudTycUpdateButtonClicked(ActionEvent event) {
|
||||
// TODO 待实现
|
||||
setStatus("待实现");
|
||||
// CompletableFuture.delayedExecutor(2, TimeUnit.SECONDS).execute(() -> {
|
||||
// button.setDisable(false);
|
||||
// });
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化 天眼查平台 Titled Pane
|
||||
*/
|
||||
private void initializeCloudTycPane() {
|
||||
// 记录编号
|
||||
cloudTycIdField.textProperty().bind(tycCloudInfoViewModel.getId().asString());
|
||||
// 平台编号
|
||||
cloudTycCloudIdField.textProperty().bindBidirectional(tycCloudInfoViewModel.getCloudId());
|
||||
cloudTycLatestField.textProperty().bind(tycCloudInfoViewModel.getLatest().map(MyDateTimeUtils::format));
|
||||
cloudTycVersionLabel.textProperty().bind(tycCloudInfoViewModel.getVersion().asString("Ver:%s"));
|
||||
|
||||
|
||||
TextField cloudIdField = cloudTycCloudIdField;
|
||||
TextField cloudScoreField = tycCloudPaneCloudScore;
|
||||
|
||||
DelayOnceExecutor saveExecutor = new DelayOnceExecutor(() -> {
|
||||
cloudTycService.save(tycCloudInfoViewModel);
|
||||
cloudIdField.setBorder(null);
|
||||
cloudScoreField.setBorder(null);
|
||||
tycCloudPaneSaveButton.setDisable(true);
|
||||
setStatus("保存成功");
|
||||
}, 2, TimeUnit.SECONDS).exception(e -> logger.error(e.getMessage(), e));
|
||||
|
||||
cloudIdField.setOnKeyPressed(event -> {
|
||||
cloudIdField.setBorder(Border.stroke(Color.RED));
|
||||
tycCloudPaneSaveButton.setDisable(false);
|
||||
saveExecutor.tick();
|
||||
});
|
||||
cloudScoreField.setOnKeyPressed(event -> {
|
||||
cloudScoreField.setBorder(Border.stroke(Color.RED));
|
||||
tycCloudPaneSaveButton.setDisable(false);
|
||||
saveExecutor.tick();
|
||||
});
|
||||
|
||||
|
||||
cloudScoreField.textProperty().bindBidirectional(tycCloudInfoViewModel.getScore(), new NumberStringConverter());
|
||||
tycCloudPaneSaveButton.setOnAction(event -> {
|
||||
saveExecutor.tickNow();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void initializeCloudYuPane() {
|
||||
try {
|
||||
yongYouU8Service = getBean(YongYouU8Service.class);
|
||||
} catch (BeansException e) {
|
||||
yuCloudPane.setDisable(true);
|
||||
}
|
||||
|
||||
cloudYuIdField.textProperty().bind(yuCloudInfoViewModel.getId().asString());
|
||||
cloudYuCloudIdField.textProperty().bindBidirectional(yuCloudInfoViewModel.getCloudId());
|
||||
cloudYuLatestField.textProperty().bind(yuCloudInfoViewModel.getLatest().map(MyDateTimeUtils::format));
|
||||
cloudYuVersionLabel.textProperty().bind(yuCloudInfoViewModel.getVersion().asString("Ver:%s"));
|
||||
|
||||
|
||||
Button button = yuCloudPaneSaveButton;
|
||||
|
||||
// 更新
|
||||
button.setOnAction(event -> {
|
||||
button.setDisable(true);
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
onCloudYuUpdateButtonClicked(event);
|
||||
} catch (Exception e) {
|
||||
UITools.showExceptionAndWait("", e);
|
||||
}
|
||||
}).whenComplete((v, e) -> {
|
||||
button.setDisable(false);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void onCloudYuUpdateButtonClicked(ActionEvent event) {
|
||||
Company company = getEntity();
|
||||
// service.syncVendor(company);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void initializeExtendInfoPane() {
|
||||
// 记录编号
|
||||
extendInfoIdField.textProperty().bind(extendInfoViewModel.getId().asString());
|
||||
extendInfoDisableVerifyField.selectedProperty().bindBidirectional(extendInfoViewModel.getDisableVerify());
|
||||
extendInfoVersionLabel.textProperty().bind(extendInfoViewModel.getVersion().asString("Ver:%s"));
|
||||
|
||||
DelayOnceExecutor saveExecutor = new DelayOnceExecutor(() -> {
|
||||
save(extendInfoViewModel);
|
||||
extendInfoDisableVerifyField.setBorder(null);
|
||||
}, 2, TimeUnit.SECONDS).exception(e -> logger.error(e.getMessage(), e));
|
||||
extendInfoDisableVerifyField.setOnMouseClicked(event -> {
|
||||
extendInfoDisableVerifyField.setBorder(Border.stroke(Color.RED));
|
||||
saveExecutor.tick();
|
||||
});
|
||||
|
||||
extendInfoPaneSaveButton.setOnAction(event -> {
|
||||
saveExecutor.tickNow();
|
||||
});
|
||||
}
|
||||
|
||||
public void save(CompanyExtendInfoViewModel viewModel) {
|
||||
int infoId = viewModel.getId().get();
|
||||
CompanyExtendInfoService service = getExtendInfoService();
|
||||
CompanyExtendInfo cloudRk = service.findById(infoId);
|
||||
if (cloudRk == null) {
|
||||
throw new RuntimeException("CloudRk not found");
|
||||
}
|
||||
if (viewModel.copyTo(cloudRk)) {
|
||||
CompanyExtendInfo saved = service.save(cloudRk);
|
||||
if (Platform.isFxApplicationThread()) {
|
||||
viewModel.update(saved);
|
||||
} else {
|
||||
Platform.runLater(() -> {
|
||||
viewModel.update(saved);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateRKCloudPane(Company company, TitledPane pane) {
|
||||
CloudRkInfoViewModel viewModel = rkCloudInfoViewModel;
|
||||
CloudRk cloudRk = getCloudRkService().getOrCreateCloudRk(company);
|
||||
Platform.runLater(() -> {
|
||||
viewModel.update(cloudRk);
|
||||
});
|
||||
}
|
||||
|
||||
private void updateTYCCloudPane(Company company, TitledPane pane) {
|
||||
CloudTycInfoViewModel viewModel = tycCloudInfoViewModel;
|
||||
CloudTyc cloudTyc = getCloudTycService().getOrCreateCloudTyc(company);
|
||||
Platform.runLater(() -> {
|
||||
viewModel.update(cloudTyc);
|
||||
});
|
||||
}
|
||||
|
||||
private void updateYuCloudPane(Company company, TitledPane pane) {
|
||||
CloudYuInfoViewModel viewModel = yuCloudInfoViewModel;
|
||||
if (yongYouU8Service == null) {
|
||||
setStatus("未启用 " + YongYouU8Service.NAME + " 服务");
|
||||
return;
|
||||
}
|
||||
CloudYu cloudYu = yongYouU8Service.getOrCreateCloudYu(company);
|
||||
Platform.runLater(() -> {
|
||||
viewModel.update(cloudYu);
|
||||
});
|
||||
}
|
||||
|
||||
private void updateExtendInfoPane(Company company, TitledPane pane) {
|
||||
CompanyExtendInfoViewModel viewModel = extendInfoViewModel;
|
||||
CompanyExtendInfoService service = getExtendInfoService();
|
||||
CompanyExtendInfo extendInfo = service.findByCompany(company);
|
||||
Platform.runLater(() -> {
|
||||
viewModel.update(extendInfo);
|
||||
});
|
||||
}
|
||||
|
||||
CloudRkService getCloudRkService() {
|
||||
if (cloudRkService == null) {
|
||||
cloudRkService = getBean(CloudRkService.class);
|
||||
}
|
||||
return cloudRkService;
|
||||
}
|
||||
|
||||
CloudTycService getCloudTycService() {
|
||||
if (cloudTycService == null) {
|
||||
cloudTycService = getBean(CloudTycService.class);
|
||||
}
|
||||
return cloudTycService;
|
||||
}
|
||||
|
||||
CompanyExtendInfoService getExtendInfoService() {
|
||||
if (extendInfoService == null) {
|
||||
extendInfoService = getBean(CompanyExtendInfoService.class);
|
||||
}
|
||||
return extendInfoService;
|
||||
}
|
||||
|
||||
YongYouU8Service getYongYouU8Service() {
|
||||
return yongYouU8Service;
|
||||
}
|
||||
}
|
||||
@@ -1,153 +0,0 @@
|
||||
package com.ecep.contract.manager.ds.company.controller;
|
||||
|
||||
import com.ecep.contract.manager.cloud.u8.YongYouU8Service;
|
||||
import com.ecep.contract.manager.ds.company.model.Invoice;
|
||||
import com.ecep.contract.manager.ds.company.service.InvoiceService;
|
||||
import com.ecep.contract.manager.ds.contract.model.PurchaseBillVoucher;
|
||||
import com.ecep.contract.manager.ds.contract.service.PurchaseBillVoucherService;
|
||||
import com.ecep.contract.manager.ds.contract.vo.PurchaseBillVoucherViewModel;
|
||||
import com.ecep.contract.manager.ds.other.EmployeeStringConverter;
|
||||
import com.ecep.contract.manager.ds.other.model.Employee;
|
||||
import com.ecep.contract.manager.ui.FxmlPath;
|
||||
import com.ecep.contract.manager.ui.tab.TabSkin;
|
||||
import com.ecep.contract.manager.ui.table.cell.InvoiceTableCell;
|
||||
import com.ecep.contract.manager.ui.table.cell.LocalDateTimeTableCell;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.control.cell.TextFieldTableCell;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import lombok.Setter;
|
||||
import org.springframework.beans.BeansException;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 子合同
|
||||
*/
|
||||
@FxmlPath("/ui/company/company-tab-purchase-bill-voucher.fxml")
|
||||
public class CompanyTabSkinPurchaseBillVoucher
|
||||
extends AbstCompanyTableTabSkin<PurchaseBillVoucher, PurchaseBillVoucherViewModel>
|
||||
implements TabSkin {
|
||||
|
||||
public TableColumn<PurchaseBillVoucherViewModel, Number> contractTable_idColumn;
|
||||
public TableColumn<PurchaseBillVoucherViewModel, Number> contractTable_refIdColumn;
|
||||
public TableColumn<PurchaseBillVoucherViewModel, Invoice> invoiceColumn;
|
||||
public TableColumn<PurchaseBillVoucherViewModel, String> contractTable_codeColumn;
|
||||
public TableColumn<PurchaseBillVoucherViewModel, Employee> employeeColumn;
|
||||
public TableColumn<PurchaseBillVoucherViewModel, Employee> makerColumn;
|
||||
public TableColumn<PurchaseBillVoucherViewModel, LocalDateTime> makerDateColumn;
|
||||
public TableColumn<PurchaseBillVoucherViewModel, LocalDateTime> modifyDateColumn;
|
||||
public TableColumn<PurchaseBillVoucherViewModel, Employee> verifierColumn;
|
||||
public TableColumn<PurchaseBillVoucherViewModel, LocalDateTime> verifierDateColumn;
|
||||
public TableColumn<PurchaseBillVoucherViewModel, String> descriptionColumn;
|
||||
|
||||
public TextField searchKeyField;
|
||||
public Button searchBtn;
|
||||
public MenuItem contractTable_menu_refresh;
|
||||
public MenuItem contractTable_menu_add;
|
||||
public MenuItem contractTable_menu_del;
|
||||
|
||||
|
||||
@Setter
|
||||
private PurchaseBillVoucherService purchaseBillVoucherService;
|
||||
@Setter
|
||||
private InvoiceService invoiceService;
|
||||
@Setter
|
||||
private YongYouU8Service u8Service;
|
||||
@Setter
|
||||
private EmployeeStringConverter employeeStringConverter;
|
||||
|
||||
public CompanyTabSkinPurchaseBillVoucher(CompanyWindowController controller) {
|
||||
super(controller);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tab getTab() {
|
||||
return controller.purchaseBillVoucherTab;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeTab() {
|
||||
|
||||
if (u8Service == null) {
|
||||
try {
|
||||
u8Service = getBean(YongYouU8Service.class);
|
||||
} catch (BeansException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
searchKeyField.setOnKeyReleased(event -> {
|
||||
if (event.getCode() == KeyCode.ENTER) {
|
||||
searchBtn.fire();
|
||||
}
|
||||
});
|
||||
|
||||
searchBtn.setOnAction(this::onTableRefreshAction);
|
||||
searchKeyField.setOnKeyReleased(event -> {
|
||||
if (event.getCode() == KeyCode.ENTER) {
|
||||
searchBtn.fire();
|
||||
}
|
||||
});
|
||||
|
||||
contractTable_idColumn.setCellValueFactory(param -> param.getValue().getId());
|
||||
contractTable_refIdColumn.setCellValueFactory(param -> param.getValue().getRefId());
|
||||
contractTable_codeColumn.setCellValueFactory(param -> param.getValue().getCode());
|
||||
|
||||
employeeColumn.setCellValueFactory(param -> param.getValue().getEmployee());
|
||||
employeeColumn.setCellFactory(TextFieldTableCell.forTableColumn(getEmployeeStringConverter()));
|
||||
|
||||
invoiceColumn.setCellValueFactory(param -> param.getValue().getInvoice());
|
||||
invoiceColumn.setCellFactory(param -> new InvoiceTableCell<>(getInvoiceService()));
|
||||
|
||||
|
||||
makerColumn.setCellValueFactory(param -> param.getValue().getMaker());
|
||||
makerColumn.setCellFactory(TextFieldTableCell.forTableColumn(getEmployeeStringConverter()));
|
||||
makerDateColumn.setCellValueFactory(param -> param.getValue().getMakerDate());
|
||||
makerDateColumn.setCellFactory(param -> new LocalDateTimeTableCell<>());
|
||||
modifyDateColumn.setCellValueFactory(param -> param.getValue().getModifyDate());
|
||||
modifyDateColumn.setCellFactory(param -> new LocalDateTimeTableCell<>());
|
||||
|
||||
verifierColumn.setCellValueFactory(param -> param.getValue().getVerifier());
|
||||
verifierColumn.setCellFactory(TextFieldTableCell.forTableColumn(getEmployeeStringConverter()));
|
||||
verifierDateColumn.setCellValueFactory(param -> param.getValue().getVerifierDate());
|
||||
verifierDateColumn.setCellFactory(param -> new LocalDateTimeTableCell<>());
|
||||
|
||||
descriptionColumn.setCellValueFactory(param -> param.getValue().getDescription());
|
||||
|
||||
contractTable_menu_refresh.setOnAction(this::onTableRefreshAction);
|
||||
contractTable_menu_del.setOnAction(this::onTableDeleteAction);
|
||||
|
||||
super.initializeTab();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTableRowDoubleClickedAction(PurchaseBillVoucherViewModel item) {
|
||||
// ContractWindowController.show(item, controller.root.getScene().getWindow());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PurchaseBillVoucherService getViewModelService() {
|
||||
return getPurchaseBillVoucherService();
|
||||
}
|
||||
|
||||
private PurchaseBillVoucherService getPurchaseBillVoucherService() {
|
||||
if (purchaseBillVoucherService == null) {
|
||||
purchaseBillVoucherService = getBean(PurchaseBillVoucherService.class);
|
||||
}
|
||||
return purchaseBillVoucherService;
|
||||
}
|
||||
|
||||
private EmployeeStringConverter getEmployeeStringConverter() {
|
||||
if (employeeStringConverter == null) {
|
||||
employeeStringConverter = getBean(EmployeeStringConverter.class);
|
||||
}
|
||||
return employeeStringConverter;
|
||||
}
|
||||
|
||||
private InvoiceService getInvoiceService() {
|
||||
if (invoiceService == null) {
|
||||
invoiceService = getBean(InvoiceService.class);
|
||||
}
|
||||
return invoiceService;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.ecep.contract.manager.ds.company.controller;
|
||||
|
||||
import com.ecep.contract.manager.ui.BaseController;
|
||||
import com.ecep.contract.manager.ui.FxmlPath;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Lazy
|
||||
@Scope("prototype")
|
||||
@Component
|
||||
@FxmlPath("/ui/company/company-verify.fxml")
|
||||
public class CompanyVerifyWindowController extends BaseController {
|
||||
|
||||
}
|
||||
@@ -1,314 +0,0 @@
|
||||
package com.ecep.contract.manager.ds.company.controller;
|
||||
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyFileService;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.manager.ds.company.tasker.CompanyCompositeUpdateTasker;
|
||||
import com.ecep.contract.manager.ds.company.tasker.CompanyVerifyTasker;
|
||||
import com.ecep.contract.manager.ds.company.vo.CompanyViewModel;
|
||||
import com.ecep.contract.manager.ds.contract.service.ContractService;
|
||||
import com.ecep.contract.manager.ds.customer.controller.CompanyCustomerWindowController;
|
||||
import com.ecep.contract.manager.ds.customer.model.CompanyCustomer;
|
||||
import com.ecep.contract.manager.ds.customer.service.CompanyCustomerService;
|
||||
import com.ecep.contract.manager.ds.vendor.controller.CompanyVendorWindowController;
|
||||
import com.ecep.contract.manager.ds.vendor.model.CompanyVendor;
|
||||
import com.ecep.contract.manager.ds.vendor.service.CompanyVendorService;
|
||||
import com.ecep.contract.manager.ui.tab.AbstEntityBasedTabSkin;
|
||||
import com.ecep.contract.manager.ui.AbstEntityController;
|
||||
import com.ecep.contract.manager.ui.FxmlPath;
|
||||
import com.ecep.contract.manager.util.DesktopUtils;
|
||||
import com.ecep.contract.manager.util.UITools;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.Window;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Lazy
|
||||
@Scope("prototype")
|
||||
@Component
|
||||
@FxmlPath("/ui/company/company.fxml")
|
||||
public class CompanyWindowController
|
||||
extends AbstEntityController<Company, CompanyViewModel> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CompanyWindowController.class);
|
||||
|
||||
|
||||
public static void show(Company company, Window window) {
|
||||
CompanyViewModel viewModel = new CompanyViewModel();
|
||||
if (!Hibernate.isInitialized(company)) {
|
||||
company = SpringApp.getBean(CompanyService.class).findById(company.getId());
|
||||
}
|
||||
viewModel.update(company);
|
||||
show(viewModel, window);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示界面
|
||||
*/
|
||||
public static void show(CompanyViewModel viewModel, Window window) {
|
||||
show(CompanyWindowController.class, viewModel, window);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private CompanyService companyService;
|
||||
@Autowired
|
||||
private CompanyFileService companyFileService;
|
||||
@Autowired
|
||||
private ContractService contractService;
|
||||
@Autowired
|
||||
private CompanyCustomerService companyCustomerService;
|
||||
@Autowired
|
||||
private CompanyVendorService companyVendorService;
|
||||
|
||||
public BorderPane root;
|
||||
public TabPane tabPane;
|
||||
public Tab baseInfoTab;
|
||||
public Tab oldNameTab;
|
||||
public Tab contactTab;
|
||||
public Tab blackReasonTab;
|
||||
public Tab customerTab;
|
||||
public Tab vendorTab;
|
||||
public Tab bankAccountTab;
|
||||
public Tab contractTab;
|
||||
public Tab fileTab;
|
||||
public Tab invoiceTab;
|
||||
public Tab purchaseBillVoucherTab;
|
||||
public Tab otherTab;
|
||||
/*
|
||||
|
||||
*/
|
||||
public TextField nameField;
|
||||
public TextField shortNameField;
|
||||
public TextField uidField;
|
||||
public TextField entStatusField;
|
||||
public DatePicker setupDateField;
|
||||
public TextField entTypeField;
|
||||
public TextField industryField;
|
||||
public TextField districtField;
|
||||
public CheckBox pathExistField;
|
||||
public TextField pathField;
|
||||
public DatePicker createdDateField;
|
||||
public TextField telephoneField;
|
||||
public TextField regAddressField;
|
||||
public TextField addressField;
|
||||
public TextField registeredCapitalField;
|
||||
public TextField registeredCapitalCurrencyField;
|
||||
public TextField legalRepresentativeField;
|
||||
public DatePicker operationPeriodBeginField;
|
||||
public DatePicker operationPeriodEndField;
|
||||
public TextArea memoField;
|
||||
public Label versionLabel;
|
||||
public Button companyRenameBtn;
|
||||
public Button companyPathCreateBtn;
|
||||
public Button companyPathChangeBtn;
|
||||
public Button companyPathSameAsNameBtn;
|
||||
|
||||
|
||||
// private final CompanyCustomerViewModel companyCustomerViewModel = new CompanyCustomerViewModel();
|
||||
// private final CompanyVendorViewModel companyVendorViewModel = new CompanyVendorViewModel();
|
||||
|
||||
private final SimpleObjectProperty<CompanyCustomer> companyCustomerProperty = new SimpleObjectProperty<>();
|
||||
private final SimpleObjectProperty<CompanyVendor> companyVendorProperty = new SimpleObjectProperty<>();
|
||||
|
||||
public Pane customerTab_pane1;
|
||||
public Button customerTab_openBtn;
|
||||
public Pane customerTab_pane2;
|
||||
public Button customerTab_createBtn;
|
||||
|
||||
public Pane vendorTab_pane1;
|
||||
public Button vendorTab_openBtn;
|
||||
public Pane vendorTab_pane2;
|
||||
public Button vendorTab_createBtn;
|
||||
|
||||
|
||||
@Override
|
||||
public void show(Stage stage) {
|
||||
super.show(stage);
|
||||
stage.minWidthProperty().set(600);
|
||||
stage.minHeightProperty().set(450);
|
||||
getTitle().set("[" + viewModel.getId().get() + "] " + viewModel.getName().getValue() + " 公司详情");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Company loadEntity() {
|
||||
return companyService.findById(viewModel.getId().get());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Company saveEntity(Company entity) {
|
||||
return companyService.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerTabSkins() {
|
||||
registerTabSkin(baseInfoTab, tab1 -> new CompanyTabSkinBase(this));
|
||||
registerTabSkin(oldNameTab, tab1 -> new CompanyTabSkinOldName(this));
|
||||
registerTabSkin(contactTab, tab1 -> new CompanyTabSkinContact(this));
|
||||
registerTabSkin(blackReasonTab, tab1 -> new CompanyTabSkinBlackReason(this));
|
||||
registerTabSkin(bankAccountTab, tab1 -> new CompanyTabSkinBankAccount(this));
|
||||
registerTabSkin(contractTab, this::createContractTabSkin);
|
||||
registerTabSkin(fileTab, this::createFileTabSkin);
|
||||
registerTabSkin(invoiceTab, tab -> new CompanyTabSkinInvoice(this));
|
||||
registerTabSkin(purchaseBillVoucherTab, tab -> new CompanyTabSkinPurchaseBillVoucher(this));
|
||||
registerTabSkin(otherTab, tab -> new CompanyTabSkinOther(this));
|
||||
|
||||
|
||||
initializeVendorTab();
|
||||
initializeCustomerTab();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected <K extends AbstEntityBasedTabSkin<?, ?, ?>> K registerTabSkin(Tab tab, Function<Tab, K> func) {
|
||||
K skin = super.registerTabSkin(tab, func);
|
||||
if (skin instanceof AbstCompanyBasedTabSkin b) {
|
||||
b.setViewModel(viewModel);
|
||||
}
|
||||
return skin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompanyService getViewModelService() {
|
||||
return companyService;
|
||||
}
|
||||
|
||||
|
||||
private CompanyTabSkinContract createContractTabSkin(Tab tab) {
|
||||
CompanyTabSkinContract skin = new CompanyTabSkinContract(this);
|
||||
skin.setContractService(contractService);
|
||||
return skin;
|
||||
}
|
||||
|
||||
private CompanyTabSkinFile createFileTabSkin(Tab tab) {
|
||||
CompanyTabSkinFile skin = new CompanyTabSkinFile(this);
|
||||
skin.setCompanyFileService(companyFileService);
|
||||
return skin;
|
||||
}
|
||||
|
||||
private void initializeCustomerTab() {
|
||||
customerTab.setOnSelectionChanged(event -> {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("customerTab OnSelectionChanged");
|
||||
}
|
||||
if (customerTab.isSelected()) {
|
||||
onCustomerTabShown();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
customerTab_pane1.visibleProperty().bind(customerTab_pane2.visibleProperty().not());
|
||||
customerTab_pane2.visibleProperty().bind(companyCustomerProperty.isNull());
|
||||
customerTab_createBtn.setOnAction(event -> {
|
||||
// TODO 创建
|
||||
});
|
||||
|
||||
customerTab_openBtn.setOnAction(event -> {
|
||||
CompanyCustomerWindowController.show(companyCustomerProperty.get(), root.getScene().getWindow());
|
||||
});
|
||||
}
|
||||
|
||||
private void onCustomerTabShown() {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("onCustomerTabShown");
|
||||
}
|
||||
getLoadedFuture().thenAcceptAsync(company -> {
|
||||
companyCustomerProperty.set(companyCustomerService.findByCompany(company));
|
||||
}).exceptionally(ex -> {
|
||||
UITools.showExceptionAndWait(ex.getMessage(), ex);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private void initializeVendorTab() {
|
||||
vendorTab.setOnSelectionChanged(event -> {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("vendorTab OnSelectionChanged");
|
||||
}
|
||||
if (vendorTab.isSelected()) {
|
||||
onVendorTabShown();
|
||||
}
|
||||
});
|
||||
|
||||
vendorTab_pane1.visibleProperty().bind(vendorTab_pane2.visibleProperty().not());
|
||||
vendorTab_pane2.visibleProperty().bind(companyVendorProperty.isNull());
|
||||
vendorTab_createBtn.setOnAction(event -> {
|
||||
// TODO 创建
|
||||
});
|
||||
|
||||
vendorTab_openBtn.setOnAction(event -> {
|
||||
CompanyVendorWindowController.show(companyVendorProperty.get(), root.getScene().getWindow());
|
||||
});
|
||||
}
|
||||
|
||||
private void onVendorTabShown() {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("onVendorTabShown");
|
||||
}
|
||||
getLoadedFuture().thenAcceptAsync(company -> {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("onVendorTabShown company {}", company.getName());
|
||||
}
|
||||
companyVendorProperty.set(companyVendorService.findByCompany(company));
|
||||
}).exceptionally(ex -> {
|
||||
UITools.showExceptionAndWait(ex.getMessage(), ex);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并更新企业信息
|
||||
*/
|
||||
public void onCompanyCompositeUpdateAction(ActionEvent event) {
|
||||
CompanyCompositeUpdateTasker task = new CompanyCompositeUpdateTasker();
|
||||
task.setCompany(getEntity());
|
||||
UITools.showTaskDialogAndWait("更新企业信息", task, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 企业合规检查
|
||||
*/
|
||||
public void onCompanyVerifyAction(ActionEvent event) {
|
||||
Company company = getEntity();
|
||||
|
||||
CompanyVerifyTasker task = new CompanyVerifyTasker();
|
||||
task.setCompanyService(companyService);
|
||||
task.setCompany(company);
|
||||
UITools.showTaskDialogAndWait("企业合规性验证", task, null);
|
||||
}
|
||||
|
||||
public void onCompanyOpenInExplorerAction(ActionEvent event) {
|
||||
Company company = getEntity();
|
||||
String path = company.getPath();
|
||||
|
||||
CompletableFuture.runAsync(() -> {
|
||||
if (!StringUtils.hasText(path)) {
|
||||
ButtonType buttonType = UITools.showConfirmation("目录未设置", "是否创建目录").join();
|
||||
if (buttonType == ButtonType.OK) {
|
||||
if (companyService.makePathAbsent(company)) {
|
||||
save(company);
|
||||
}
|
||||
} else {
|
||||
setStatus("未设置目录");
|
||||
return;
|
||||
}
|
||||
}
|
||||
DesktopUtils.checkAndShowInExplorer(company.getPath(), this::setStatus);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
package com.ecep.contract.manager.ds.company.controller.bank_account;
|
||||
|
||||
import com.ecep.contract.manager.SpringApp;
|
||||
import com.ecep.contract.manager.ds.company.CompanyStringConverter;
|
||||
import com.ecep.contract.manager.ds.company.controller.CompanyWindowController;
|
||||
import com.ecep.contract.manager.ds.company.model.Company;
|
||||
import com.ecep.contract.manager.ds.company.model.CompanyBankAccount;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.manager.ds.company.vo.CompanyBankAccountViewModel;
|
||||
import com.ecep.contract.manager.ds.other.BankStringConverter;
|
||||
import com.ecep.contract.manager.ds.other.service.BankService;
|
||||
import com.ecep.contract.manager.ui.tab.AbstEntityBasedTabSkin;
|
||||
import com.ecep.contract.manager.ui.tab.TabSkin;
|
||||
import com.ecep.contract.manager.util.UITools;
|
||||
import javafx.scene.control.Tab;
|
||||
import javafx.scene.control.TextField;
|
||||
import lombok.Setter;
|
||||
|
||||
public class BankAccountBaseTabSkin extends AbstEntityBasedTabSkin<BankAccountWindowController, CompanyBankAccount, CompanyBankAccountViewModel> implements TabSkin {
|
||||
@Setter
|
||||
private CompanyService companyService;
|
||||
@Setter
|
||||
private BankService bankService;
|
||||
|
||||
public BankAccountBaseTabSkin(BankAccountWindowController controller) {
|
||||
super(controller);
|
||||
viewModel = controller.getViewModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tab getTab() {
|
||||
return controller.baseInfoTab;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeTab() {
|
||||
initializeBaseTabCompanyFieldAutoCompletion(controller.companyField);
|
||||
initializeBaseTabBankFieldAutoCompletion(controller.bankField);
|
||||
|
||||
controller.openingBankField.textProperty().bindBidirectional(viewModel.getOpeningBank());
|
||||
controller.bankAccountField.textProperty().bindBidirectional(viewModel.getAccount());
|
||||
|
||||
|
||||
// controller.descriptionField.textProperty().bindBidirectional(viewModel.getDescription());
|
||||
controller.createdField.textProperty().bind(viewModel.getCreated().asString());
|
||||
controller.versionLabel.textProperty().bind(viewModel.getVersion().asString());
|
||||
|
||||
controller.relativeCompanyBtn.disableProperty().bind(viewModel.getCompany().isNull());
|
||||
controller.relativeCompanyBtn.setOnAction(event -> {
|
||||
Company company = viewModel.getCompany().get();
|
||||
if (company != null) {
|
||||
CompanyWindowController.show(company, controller.root.getScene().getWindow());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initializeBaseTabCompanyFieldAutoCompletion(TextField textField) {
|
||||
CompanyStringConverter converter = SpringApp.getBean(CompanyStringConverter.class);
|
||||
UITools.autoCompletion(textField, viewModel.getCompany(), converter::suggest, converter);
|
||||
}
|
||||
|
||||
|
||||
private void initializeBaseTabBankFieldAutoCompletion(TextField textField) {
|
||||
BankStringConverter converter = SpringApp.getBean(BankStringConverter.class);
|
||||
UITools.autoCompletion(textField, viewModel.getBank(), converter::suggest, converter);
|
||||
}
|
||||
|
||||
|
||||
public BankService getBankService() {
|
||||
if (bankService == null) {
|
||||
bankService = getBean(BankService.class);
|
||||
}
|
||||
return bankService;
|
||||
}
|
||||
|
||||
public CompanyService getCompanyService() {
|
||||
if (companyService == null) {
|
||||
companyService = getBean(CompanyService.class);
|
||||
}
|
||||
return companyService;
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package com.ecep.contract.manager.ds.company.controller.bank_account;
|
||||
|
||||
import com.ecep.contract.manager.ds.company.model.CompanyBankAccount;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyBankAccountService;
|
||||
import com.ecep.contract.manager.ds.company.vo.CompanyBankAccountViewModel;
|
||||
import com.ecep.contract.manager.ui.AbstEntityController;
|
||||
import com.ecep.contract.manager.ui.FxmlPath;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.stage.Window;
|
||||
import javafx.stage.WindowEvent;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Lazy
|
||||
@Scope("prototype")
|
||||
@Component
|
||||
@FxmlPath("/ui/company/bank-account.fxml")
|
||||
public class BankAccountWindowController extends AbstEntityController<CompanyBankAccount, CompanyBankAccountViewModel> {
|
||||
public BorderPane root;
|
||||
public TabPane tabPane;
|
||||
|
||||
public Tab baseInfoTab;
|
||||
public TextField companyField;
|
||||
public Button relativeCompanyBtn;
|
||||
public TextField bankField;
|
||||
public TextField openingBankField;
|
||||
public TextField bankAccountField;
|
||||
public TextField createdField;
|
||||
public TextArea descriptionField;
|
||||
public Label versionLabel;
|
||||
|
||||
public Tab entityTab;
|
||||
|
||||
|
||||
public static void show(CompanyBankAccountViewModel viewModel, Window window) {
|
||||
show(BankAccountWindowController.class, viewModel, window);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private CompanyBankAccountService bankAccountService;
|
||||
|
||||
@Override
|
||||
public void onShown(WindowEvent event) {
|
||||
super.onShown(event);
|
||||
getTitle().set("[" + viewModel.getId().get() + "] 银行账户详情");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerTabSkins() {
|
||||
registerTabSkin(baseInfoTab, tab -> new BankAccountBaseTabSkin(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompanyBankAccountService getViewModelService() {
|
||||
return bankAccountService;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,179 +0,0 @@
|
||||
package com.ecep.contract.manager.ds.company.controller.contact;
|
||||
|
||||
import com.ecep.contract.manager.ds.company.model.CompanyContact;
|
||||
import com.ecep.contract.manager.ds.company.repository.CompanyContactRepository;
|
||||
import com.ecep.contract.manager.ui.BaseController;
|
||||
import com.ecep.contract.manager.ds.company.vo.CompanyContactViewModel;
|
||||
import com.ecep.contract.manager.util.FxmlUtils;
|
||||
import com.ecep.contract.manager.util.UITools;
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.Window;
|
||||
import javafx.stage.WindowEvent;
|
||||
import javafx.util.converter.LocalDateStringConverter;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@Lazy
|
||||
@Scope("prototype")
|
||||
@Component
|
||||
public class CompanyContactWindowController extends BaseController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CompanyContactWindowController.class);
|
||||
/**
|
||||
* 显示界面
|
||||
*/
|
||||
public static void show(CompanyContactViewModel viewModel, Window window) {
|
||||
String key = toKey(viewModel);
|
||||
// 一个合同一个界面
|
||||
if (toFront(key)) {
|
||||
return;
|
||||
}
|
||||
FxmlUtils.newLoaderAsyncWithRunLater("/ui/contact.fxml", null, loader -> {
|
||||
CompanyContactWindowController controller = loader.getController();
|
||||
controller.setViewModel(viewModel);
|
||||
controller.show(loader, window, Modality.NONE, key);
|
||||
});
|
||||
}
|
||||
|
||||
private static String toKey(CompanyContactViewModel viewModel) {
|
||||
return viewModel.getClass().getName() + "-" + viewModel.getId().get();
|
||||
}
|
||||
|
||||
public Tab baseInfoTab;
|
||||
public BorderPane root;
|
||||
public TabPane tabPane;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private CompanyContactViewModel viewModel;
|
||||
@Autowired
|
||||
private CompanyContactRepository companyContactRepository;
|
||||
|
||||
public TextField nameField;
|
||||
public TextField positionField;
|
||||
public TextField phoneField;
|
||||
public DatePicker createdField;
|
||||
public TextField u8CodeField;
|
||||
public TextField emailField;
|
||||
public TextField addressField;
|
||||
public TextArea descriptionField;
|
||||
public Label versionLabel;
|
||||
public Button saveBtn;
|
||||
|
||||
private CompletableFuture<CompanyContact> companyContactLoadedFuture;
|
||||
|
||||
@Override
|
||||
public void show(Stage stage) {
|
||||
super.show(stage);
|
||||
getTitle().bind(viewModel.getName().map(v -> "[" + viewModel.getId().get() + "] " + viewModel.getName().getValue() + " 曾用名详情"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShown(WindowEvent windowEvent) {
|
||||
super.onShown(windowEvent);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("onShown");
|
||||
}
|
||||
|
||||
initializeBaseTab();
|
||||
|
||||
companyContactLoadedFuture = CompletableFuture.supplyAsync(() -> {
|
||||
Optional<CompanyContact> optional = companyContactRepository.findById(viewModel.getId().get());
|
||||
if (optional.isPresent()) {
|
||||
CompanyContact oldName = optional.get();
|
||||
Platform.runLater(() -> {
|
||||
viewModel.update(oldName);
|
||||
viewModel.bindListener();
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("bind ViewModel({}) Listener", viewModel.getName().get());
|
||||
}
|
||||
tabPane.getSelectionModel().getSelectedItem().getOnSelectionChanged().handle(null);
|
||||
});
|
||||
return oldName;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void initializeBaseTab() {
|
||||
baseInfoTab.setOnSelectionChanged(event -> {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("baseInfoTab OnSelectionChanged");
|
||||
}
|
||||
if (baseInfoTab.isSelected()) {
|
||||
onBaseTabShown();
|
||||
}
|
||||
});
|
||||
saveBtn.disableProperty().bind(viewModel.getChanged().not());
|
||||
saveBtn.setOnAction(event -> {
|
||||
try {
|
||||
CompanyContact contact = companyContactLoadedFuture.join();
|
||||
viewModel.copyTo(contact);
|
||||
CompanyContact saved = companyContactRepository.save(contact);
|
||||
viewModel.update(saved);
|
||||
companyContactLoadedFuture = CompletableFuture.completedFuture(saved);
|
||||
} catch (Exception e) {
|
||||
UITools.showExceptionAndWait("保存失败,请检查", e);
|
||||
}
|
||||
});
|
||||
|
||||
nameField.textProperty().bindBidirectional(viewModel.getName());
|
||||
positionField.textProperty().bindBidirectional(viewModel.getPosition());
|
||||
phoneField.textProperty().bindBidirectional(viewModel.getPhone());
|
||||
emailField.textProperty().bindBidirectional(viewModel.getEmail());
|
||||
addressField.textProperty().bindBidirectional(viewModel.getAddress());
|
||||
LocalDateStringConverter converter = new LocalDateStringConverter(DateTimeFormatter.ISO_LOCAL_DATE, null);
|
||||
createdField.setConverter(converter);
|
||||
createdField.valueProperty().bindBidirectional(viewModel.getCreated());
|
||||
u8CodeField.textProperty().bind(viewModel.getU8Code());
|
||||
descriptionField.textProperty().bindBidirectional(viewModel.getMemo());
|
||||
versionLabel.textProperty().bind(viewModel.getVersion().asString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 基础页显示时回调函数
|
||||
*/
|
||||
private void onBaseTabShown() {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("onBaseTabShown");
|
||||
}
|
||||
companyContactLoadedFuture.thenAcceptAsync(contact -> {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("onBaseTabShown company contact {}", contact.getName());
|
||||
}
|
||||
// viewModel.update(contact);
|
||||
}).exceptionally(ex -> {
|
||||
UITools.showExceptionAndWait(ex.getMessage(), ex);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
public void onHidden(WindowEvent windowEvent) {
|
||||
if (viewModel != null) {
|
||||
try {
|
||||
viewModel.unBindListener();
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("unbind ViewModel({}) Listener", viewModel.getName().get());
|
||||
}
|
||||
} catch (InvocationTargetException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
super.onHidden(windowEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
package com.ecep.contract.manager.ds.company.controller.old_name;
|
||||
|
||||
import com.ecep.contract.manager.ds.company.model.CompanyOldName;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyOldNameService;
|
||||
import com.ecep.contract.manager.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.manager.ds.company.vo.CompanyOldNameViewModel;
|
||||
import com.ecep.contract.manager.ui.tab.AbstEntityBasedTabSkin;
|
||||
import com.ecep.contract.manager.ui.tab.TabSkin;
|
||||
import javafx.scene.control.Tab;
|
||||
import javafx.util.converter.LocalDateStringConverter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
|
||||
public class CompanyOldNameTabSkinBase
|
||||
extends AbstEntityBasedTabSkin<CompanyOldNameWindowController, CompanyOldName, CompanyOldNameViewModel>
|
||||
implements TabSkin {
|
||||
@Setter
|
||||
private CompanyService companyService;
|
||||
@Setter
|
||||
private CompanyOldNameService companyOldNameService;
|
||||
|
||||
public CompanyOldNameTabSkinBase(CompanyOldNameWindowController controller) {
|
||||
super(controller);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tab getTab() {
|
||||
return controller.baseInfoTab;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeTab() {
|
||||
|
||||
controller.nameField.textProperty().bind(viewModel.getName());
|
||||
controller.ambiguityField.selectedProperty().bindBidirectional(viewModel.getAmbiguity());
|
||||
LocalDateStringConverter converter = new LocalDateStringConverter(DateTimeFormatter.ISO_LOCAL_DATE, null);
|
||||
controller.startDateField.setConverter(converter);
|
||||
controller.startDateField.valueProperty().bindBidirectional(viewModel.getBeginDate());
|
||||
controller.endDateField.setConverter(converter);
|
||||
controller.endDateField.valueProperty().bindBidirectional(viewModel.getEndDate());
|
||||
|
||||
controller.pathField.textProperty().bind(viewModel.getPath());
|
||||
controller.descriptionField.textProperty().bindBidirectional(viewModel.getMemo());
|
||||
controller.versionLabel.textProperty().bind(viewModel.getVersion().asString());
|
||||
|
||||
controller.saveBtn.disableProperty().bind(viewModel.getChanged().not());
|
||||
controller.saveBtn.setOnAction(this::onSaveAction);
|
||||
}
|
||||
|
||||
public CompanyService getCompanyService() {
|
||||
if (companyService == null) {
|
||||
companyService = getBean(CompanyService.class);
|
||||
}
|
||||
return companyService;
|
||||
}
|
||||
|
||||
public CompanyOldNameService getCompanyOldNameService() {
|
||||
if (companyOldNameService == null) {
|
||||
companyOldNameService = getBean(CompanyOldNameService.class);
|
||||
}
|
||||
return companyOldNameService;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user