This commit is contained in:
2026-06-29 13:33:16 +08:00
89 changed files with 8024 additions and 943 deletions

View File

@@ -0,0 +1,282 @@
# QH-MES 部署与热部署方案
> 本文档记录 QH-MES(jeecg-boot 3.9.2)在 Windows Server 上的部署方案,包含后端、前端的一键发版流程、关键配置、踩过的坑,以及未来上线客户正式服务器的规划。
> 最后更新:2026-06-17
---
## 一、环境概况
### 测试服务器(当前)
- **系统**:Windows Server 2016 Standard
- **JDK**:17.0.11(`C:\Program Files\Java\jdk-17`,注意 `JAVA_HOME` 要指根目录,**不能带 `\bin`**)
- **Maven**:3.9.8(`D:\apache-maven-3.9.8`,从本地 Win11 拷过去的,因服务器网络受限无法在线下载)
- **Git**:已装在 `C:\Program Files\Git`,但不在 PATH(用完整路径 `"C:\Program Files\Git\cmd\git.exe"` 调用)
- **Gitea**:跑在**同一台机器**,裸仓库在 `D:\gitea\data\gitea-repositories\chenx\qhmes.git`,Web 地址 `http://27.223.88.102:33000/chenx/qhmes`
- **Nginx**:1.30.1,装在 `D:\qhmes\nginx-1.30.1\`,前端文件目录 `D:\qhmes\nginx-1.30.1\html\jeecg\`
- **Node/pnpm/npm**:**服务器上没装**(前端不在服务器构建)
### 关键路径
| 用途 | 路径 |
|------|------|
| 后端运行目录(jar + WinSW 服务) | `D:\qhmes\` |
| 后端运行 jar | `D:\qhmes\jeecg-system-start-3.9.2.jar` |
| 服务器源码工作副本 | `D:\qhmes-src\`(从本地裸仓库 clone,分支 `main`) |
| 前端 nginx 目录 | `D:\qhmes\nginx-1.30.1\html\jeecg\` |
| WinSW 服务程序/配置 | `D:\qhmes\qhmes-service.exe` / `qhmes-service.xml` |
| 后端发版脚本 | `D:\deploy-server.bat`(放源码目录外,避免 git pull 自我覆盖) |
### 本地开发机(Win11)
- 项目路径:`D:\XSL-PROJECT\QH-MES\qhmes`
- 后端模块:`jeecg-boot/`,前端:`jeecgboot-vue3/`(同一个 git 仓库)
- 传文件到服务器的方式:**向日葵远程传输**(只能手动,不能脚本化)
---
## 二、后端部署(已跑通 ✅)
### 2.1 后端做成 Windows 服务(WinSW)
后端不再手动 `java -jar`(关窗口/断 RDP 就掉),改用 **WinSW** 注册成 Windows 服务,开机自启、崩溃自动重启。
- 服务 id:`qhmes`,名称:`QH-MES Backend`
- 配置文件 `D:\qhmes\qhmes-service.xml` 关键内容:
```xml
<executable>java</executable>
<arguments>-Xms1g -Xmx2g -jar "D:\qhmes\jeecg-system-start-3.9.2.jar"</arguments>
<workingdirectory>D:\qhmes</workingdirectory>
<logpath>D:\qhmes\logs</logpath>
<onfailure action="restart" delay="10 sec"/>
```
- **注意**:`<arguments>` 里**不加** `--spring.profiles.active`,因为 profile 已在打包时烤进 jar(见第四节)。
- 常用命令(管理员):
```
D:\qhmes\qhmes-service.exe install # 安装服务(一次性)
D:\qhmes\qhmes-service.exe start # 启动
D:\qhmes\qhmes-service.exe stop # 停止
```
- 查日志:
```powershell
Get-Content D:\qhmes\logs\qhmes-service.out.log -Wait -Tail 60
```
启动成功标志:`Started JeecgSystemApplication in xx seconds`,Tomcat 监听 8888。
### 2.2 一键发版脚本 `D:\deploy-server.bat`
流程:`git pull → mvn 打包(prod) → 停服务 → 换 jar → 启服务`。脚本自带 `git pull`,**双击即自动拉最新代码**。
```bat
@echo off
setlocal
set SRC=D:\qhmes-src
set GIT="C:\Program Files\Git\cmd\git.exe"
set DEPLOY_DIR=D:\qhmes
set JAR_NAME=jeecg-system-start-3.9.2.jar
set SVC=D:\qhmes\qhmes-service.exe
set BUILT_JAR=%SRC%\jeecg-boot\jeecg-module-system\jeecg-system-start\target\%JAR_NAME%
echo [1/5] git pull ...
cd /d %SRC%
%GIT% pull
if errorlevel 1 ( echo [ERROR] git pull failed & pause & exit /b 1 )
echo [2/5] maven package with prod profile ...
cd /d %SRC%\jeecg-boot
call mvn clean package -pl jeecg-module-system/jeecg-system-start -am -DskipTests -P prod -T 1C
if errorlevel 1 ( echo [ERROR] build failed & pause & exit /b 1 )
if not exist "%BUILT_JAR%" ( echo [ERROR] built jar not found & pause & exit /b 1 )
echo [3/5] stop service ...
"%SVC%" stop
timeout /t 6 /nobreak >nul
echo [4/5] copy new jar ...
copy /Y "%BUILT_JAR%" "%DEPLOY_DIR%\%JAR_NAME%"
if errorlevel 1 ( echo [ERROR] copy failed, jar locked? & pause & exit /b 1 )
echo [5/5] start service ...
"%SVC%" start
echo ===== DEPLOY DONE =====
endlocal
pause
```
### 2.3 后端发版流程
1. 本地改代码 → `git push`(推到 `main`)
2. RDP/向日葵到服务器 → 双击 `D:\deploy-server.bat`
3. 看日志确认 `Started ... in xx seconds`
> 首次构建会下载几百 MB 依赖(约 8 分钟),缓存在 `D:\maven-repo`,之后每次只需 1~3 分钟。
---
## 三、前端部署(脚本已就绪)
前端 `jeecgboot-vue3` 用 **pnpm** 构建,产物 `dist/`,放到 nginx 的 `html\jeecg\`。
因服务器没 Node 且网络受限,**前端不在服务器构建**,而是:**本地构建 → dist 走 git → 服务器拉取替换**。
> `jeecgboot-vue3/dist` 被 `.gitignore` 忽略,所以构建后复制到根目录 **`web-dist`** 文件夹(未被忽略)再提交。
### 3.1 本地构建脚本 `build-frontend.bat`(本地 Win11 双击)
核心构建步骤与官网一致:`pnpm install` + `pnpm run build`,之后自动复制 dist 到 web-dist 并 git push。
```bat
@echo off
setlocal
set REPO=%~dp0
set WEBDIST=%REPO%web-dist
echo [1/4] build frontend (pnpm install + build) ...
cd /d %REPO%jeecgboot-vue3
call pnpm install
if errorlevel 1 ( echo [ERROR] pnpm install failed & pause & exit /b 1 )
call pnpm run build
if errorlevel 1 ( echo [ERROR] frontend build failed & pause & exit /b 1 )
if not exist "%REPO%jeecgboot-vue3\dist\index.html" ( echo [ERROR] dist/index.html not found & pause & exit /b 1 )
echo [2/4] refresh web-dist folder ...
if exist "%WEBDIST%" rmdir /S /Q "%WEBDIST%"
mkdir "%WEBDIST%"
xcopy "%REPO%jeecgboot-vue3\dist\*" "%WEBDIST%\" /E /Y /I >nul
echo [3/4] git add and commit web-dist ...
cd /d %REPO%
git add web-dist
git commit -m "frontend build dist update"
echo [4/4] git push ...
git push
if errorlevel 1 ( echo [ERROR] git push failed & pause & exit /b 1 )
echo ===== FRONTEND BUILT AND PUSHED =====
endlocal
pause
```
### 3.2 服务器部署脚本 `D:\deploy-frontend.bat`(服务器双击)
```bat
@echo off
setlocal
set SRC=D:\qhmes-src
set GIT="C:\Program Files\Git\cmd\git.exe"
set WEB=D:\qhmes\nginx-1.30.1\html\jeecg
set NGINX_DIR=D:\qhmes\nginx-1.30.1
echo [1/3] git pull ...
cd /d %SRC%
%GIT% pull
if errorlevel 1 ( echo [ERROR] git pull failed & pause & exit /b 1 )
if not exist "%SRC%\web-dist\index.html" ( echo [ERROR] web-dist not found, run build-frontend.bat first & pause & exit /b 1 )
echo [2/3] replace nginx frontend files ...
if exist "%WEB%" rmdir /S /Q "%WEB%"
mkdir "%WEB%"
xcopy "%SRC%\web-dist\*" "%WEB%\" /E /Y /I >nul
if errorlevel 1 ( echo [ERROR] copy failed & pause & exit /b 1 )
echo [3/3] reload nginx (ignore error if not running) ...
cd /d %NGINX_DIR%
nginx.exe -s reload
echo ===== FRONTEND DEPLOY DONE =====
endlocal
pause
```
> **nginx 不用重启**:静态文件替换后自动生效。`nginx -s reload` 是平滑重载,**不要直接跑 `nginx.exe`**(会报端口占用)。
### 3.3 前端发版流程(两步双击)
1. 本地双击 `build-frontend.bat`(构建 + 推送 web-dist)
2. 服务器双击 `D:\deploy-frontend.bat`(拉取 + 替换 + reload)
3. 刷新浏览器
---
## 四、配置(profile)说明 —— 重点
### 4.1 哪个配置生效,由打包时的 Maven `-P` 决定
`application.yml``spring.profiles.active: '@profile.name@'` 是 Maven 占位符,打包时填入:
| 打包命令 | 生效配置 |
|---------|---------|
| `mvn package`(不带 -P) | **dev**(默认,`<activeByDefault>` 在 dev 上) |
| `mvn package -P prod` | **prod** |
| `mvn package -P test` | test |
> 发版脚本用的是 **`-P prod`**,所以烤进 jar 的是 prod 配置,运行时无需再加 `--spring.profiles.active`。
### 4.2 判断一个 jar 用的哪个配置
- 看启动日志:`The following 1 profile is active: "prod"`
- 解压 jar 看 `BOOT-INF/classes/application.yml``active` 的实际值
- 运行时 `--spring.profiles.active=xxx` 可强制覆盖
### 4.3 dev vs prod 的区别(本项目)
| 项 | dev | prod(当前测试服务器用) |
|----|-----|------|
| 端口 | 8888 | 8888(已改成与现网一致) |
| MySQL | `xsl.qdxsl.top:50768`(公网绕一圈) | `127.0.0.1:3306`(本机直连) |
| MySQL 密码 | 123456 | 123456(已改,原为 root) |
> **重要事实**:`xsl.qdxsl.top:50768` 与本机 `127.0.0.1:3306` 是**同一个生产库**(公网域名+端口转发到本机)。prod 走本机直连更快更稳。
> prod 配置的修改在 `application-prod.yml`,已带 `update-begin/update-end` 痕迹注释。
---
## 五、踩过的坑(避免重复)
1. **bat 文件乱码/无法执行**:bat 里写中文 + 存成 UTF-8,cmd 按 GBK 读会乱码,连 `@echo off` 都坏。→ **bat 只用英文 ASCII,不带 BOM**
2. **WinSW 报 `Invalid character in encoding`**:xml 里中文存成了 ANSI/GBK。→ 用 UTF-8 保存,或描述改英文。
3. **服务用 prod 启动报 `Access denied for user 'root'`**:prod 密码原写的 `root`,实际应为 `123456`
4. **PowerShell 下载报 `未能创建 SSL/TLS 安全通道`**:Server 2016 默认 TLS 1.0。→ 先 `[Net.ServicePointManager]::SecurityProtocol = ... -bor 3072` 开启 TLS 1.2。
5. **服务器下载被 `127.0.0.1:10080` 的本机 Apache 拦截 404**:服务器网络有本机代理/DNS 劫持,外网下载不通。→ Maven/Node 等**在本地下好,向日葵拷过去**。
6. **`mvn``JAVA_HOME not defined correctly`**:`JAVA_HOME` 误设成了 `...\jdk-17\bin`。→ 应为根目录 `...\jdk-17`
7. **`git clone D:\gitea\...qhmes.git` 拿到的没有源码**:那是 Gitea 裸仓库(只有 git 底层数据)。→ `git clone` 它到 `D:\qhmes-src` 得到工作副本。
8. **cmd 里 `cd D:\xxx` 不切盘**:要用 `cd /d D:\xxx`;`&` 是 PowerShell 语法,cmd 里不能用。
9. **PowerShell 粘贴 here-string 卡在 `>>`**:终止符 `'@` 没识别。→ 大段内容改用**记事本**另存为(All Files + ANSI),或写进 git 拉取。
---
## 六、未来上线客户正式服务器的规划(待落地)
**核心原则:测试服务器可以 git 拉源码+构建;客户正式服务器只部署"已构建的成品",不放源码、不装构建工具、不依赖我方 gitea。**
### 6.1 目标流程
```
我方(测试服务器/开发机):打包出成品(jar + 前端dist)并测好
↓ 向日葵/U盘/网盘 传过去
客户正式服务器:双击 deploy.bat → 停服务 → 换jar → 换前端 → 启服务
```
### 6.2 必做改造:配置外置(同一 jar 走天下)
现在 prod 配置(数据库/IP/密码)烤死在 jar 里,是测试服务器的。客户的库不同,需把配置挪到 jar 外:
```
D:\qhmes\
├── jeecg-system-start-3.9.2.jar ← 所有环境通用,不用为每个客户重打
└── config\
└── application-prod.yml ← 本机专属:客户的数据库/IP/密码
```
Spring Boot 自动优先读 jar 同级 `config\` 目录的配置(外部 > jar 内 classpath)。
### 6.3 待办(上线时找 Claude 做)
1. 把 prod 配置从 jar 内挪到外部 `config\`,jar 变环境无关
2. 写"打 release 包"脚本:一键产出 `jar + 前端dist + deploy.bat` 发布包
3. 写客户服务器 `deploy.bat`:只"换文件+重启",不构建、不拉源码
4. (建议)测试服务器也提前切到外置配置,与客户环境保持一致,上线零改动
---
## 七、快速命令速查
```powershell
# 后端发版
D:\deploy-server.bat # 服务器双击
# 前端发版
build-frontend.bat # 本地 Win11 双击
D:\deploy-frontend.bat # 服务器双击
# 看后端日志
Get-Content D:\qhmes\logs\qhmes-service.out.log -Wait -Tail 60
# 后端服务控制(管理员)
D:\qhmes\qhmes-service.exe stop|start|status
# nginx 平滑重载(在 nginx 目录下)
cd /d D:\qhmes\nginx-1.30.1
nginx.exe -s reload
```

View File

@@ -1110,3 +1110,73 @@ jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/flyway/sql/
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/controller/MesXslDesktopAnonController.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/service/impl/MesXslRubberQuickTestStdServiceImpl.java
yy-admin-master/YY.Admin.Services/Service/RubberQuickTestStd/RubberQuickTestStdService.cs
-- author:GHT---date:20260617--for: 【MES上辅机】密炼动作秒级采集 + 通用中间表采集配置 ---
需求:密炼机动作维护数据从中间表 MCSToMES_MixAct 秒级采集(机台名称→设备名称、动作名称→动作名称、动作地址→动作代号),
在「密炼动作」页支持 启动/停止采集与设置时间间隔默认1秒采集配置落库为通用配置表(mes_xsl_mcs_sync_config)供后续功能复用。
设计:新增通用采集配置表 + McsSyncHandler 扩展点 + McsSyncScheduler(ThreadPoolTaskScheduler 动态重排+启动加载)
MixActSyncHandler 增量 Upsert(按机台编号+动作代号唯一),保留手动维护数据;密炼机动作维护补全 equip_id/equip_type 字段,
唯一性由全局唯一改为(设备+动作代号)同设备内唯一equipment_id 允许为空(采集未匹配台账时)。
jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/flyway/sql/mysql/V3.9.2_153__mes_xsl_mcs_sync_config.sql
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/entity/MesXslMcsSyncConfig.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/mapper/MesXslMcsSyncConfigMapper.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/service/IMesXslMcsSyncConfigService.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/service/impl/MesXslMcsSyncConfigServiceImpl.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/controller/MesXslMcsSyncConfigController.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/sync/McsSyncHandler.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/sync/McsSyncScheduler.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/sync/handler/MixActSyncHandler.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/entity/MesXslMixerAction.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/service/IMesXslMixerActionService.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/service/impl/MesXslMixerActionServiceImpl.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/controller/MesXslMixerActionController.java
jeecgboot-vue3/src/views/xslmesMcs/mcsToMesMixAct/index.vue
jeecgboot-vue3/src/views/xslmesMcs/mcsToMesMixAct/McsToMesMixAct.api.ts
jeecgboot-vue3/src/views/xslmes/mesXslMixerAction/MesXslMixerAction.data.ts
jeecgboot-vue3/src/views/xslmes/mesXslMixerAction/MesXslMixerAction.api.ts
-- author:GHT---date:20260617--for: 【MES上辅机】密炼动作秒级采集 + 通用中间表采集配置 ---
-- author:GHT---date:20260617--for: 【MES上辅机】采集配置通用表/字段绑定 + 配置驱动采集 ---
需求在「MES上辅机数据」下新增「采集配置」左选中间库表、右选MES表(mes_xsl_前缀)下方左带出中间库字段、右由用户选MES接收字段
采集操作改为弹窗(是否采集+采集间隔),密炼动作页同样改为弹窗。
设计:统一为配置驱动——删除硬编码 MixActSyncHandler/McsSyncHandler新增 GenericMcsSyncEngine(JdbcTemplate跨库读源表→按"匹配键"Upsert写MES表
自动填充 id/时间/租户/del_flag纯字段拷贝)McsSyncScheduler 改为按 configId 调度;新增字段映射表 mes_xsl_mcs_sync_field 与配置头扩展(target_table/config_name等)
密炼动作(MIX_ACT)改造为预置配置+字段映射;新增 McsMetaMapper 查询SQLServer/MySQL表与字段元数据采集配置CRUD/详情/采集操作接口。
jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/flyway/sql/mysql/V3.9.2_154__mes_xsl_mcs_sync_field.sql
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/entity/MesXslMcsSyncConfig.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/entity/MesXslMcsSyncField.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/mapper/MesXslMcsSyncFieldMapper.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/mapper/McsMetaMapper.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/sync/GenericMcsSyncEngine.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/sync/McsSyncScheduler.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/service/IMesXslMcsSyncConfigService.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/service/impl/MesXslMcsSyncConfigServiceImpl.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/controller/MesXslMcsSyncConfigController.java
删除jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/sync/McsSyncHandler.java
删除jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/sync/handler/MixActSyncHandler.java
jeecgboot-vue3/src/views/xslmesMcs/mcsSyncConfig/index.vue
jeecgboot-vue3/src/views/xslmesMcs/mcsSyncConfig/mcsSyncConfig.api.ts
jeecgboot-vue3/src/views/xslmesMcs/mcsSyncConfig/mcsSyncConfig.data.ts
jeecgboot-vue3/src/views/xslmesMcs/mcsSyncConfig/components/SyncConfigModal.vue
jeecgboot-vue3/src/views/xslmesMcs/mcsSyncConfig/components/CollectModal.vue
jeecgboot-vue3/src/views/xslmesMcs/mcsToMesMixAct/index.vue
jeecgboot-vue3/src/views/xslmesMcs/mcsToMesMixAct/McsToMesMixAct.api.ts
-- author:GHT---date:20260617--for: 【MES上辅机】采集配置通用表/字段绑定 + 配置驱动采集 ---
-- author:GHT---date:20260617--for: 【MES上辅机】采集模式全量/时间/增量 + 批量增量写入(应对大表) ---
背景:原通用引擎每周期全表读源+全表读目标逐行Upsertautocommit逐行往返大表(上万~数十万)采集慢。
优化GenericMcsSyncEngine 改为「一次读现有建索引+内存比对+变更检测+batchUpdate分批」并新增三种采集模式(采集操作弹窗可配)
FULL全量匹配(小表全量Upsert)、TIME时间匹配(按时间列取当天/最近七天再Upsert目标侧按窗口匹配键定向IN读取)、
INCR增量匹配(按增量列高水位>last_watermark、ORDER BY ASC取TOP N仅追加并推进水位)。调度器落库 last_watermark。
mes_xsl_mcs_sync_config 增加 sync_mode/incr_column/time_window/batch_limit/last_watermark。
jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/flyway/sql/mysql/V3.9.2_155__mes_xsl_mcs_sync_mode.sql
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/entity/MesXslMcsSyncConfig.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/sync/GenericMcsSyncEngine.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/sync/McsSyncScheduler.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/service/IMesXslMcsSyncConfigService.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/service/impl/MesXslMcsSyncConfigServiceImpl.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/controller/MesXslMcsSyncConfigController.java
jeecgboot-vue3/src/views/xslmesMcs/mcsSyncConfig/components/CollectModal.vue
jeecgboot-vue3/src/views/xslmesMcs/mcsSyncConfig/mcsSyncConfig.api.ts
jeecgboot-vue3/src/views/xslmesMcs/mcsSyncConfig/mcsSyncConfig.data.ts
-- author:GHT---date:20260617--for: 【MES上辅机】采集模式全量/时间/增量 + 批量增量写入(应对大表) ---

View File

@@ -35,6 +35,7 @@ import org.jeecg.modules.xslmes.entity.MesXslVehicle;
import org.jeecg.modules.xslmes.entity.MesXslWarehouse;
import org.jeecg.modules.xslmes.entity.MesXslWarehouseArea;
import org.jeecg.modules.xslmes.entity.MesXslMixingProductionPlan;
import org.jeecg.modules.xslmes.entity.MesXslRubberQuickTestMethod;
import org.jeecg.modules.xslmes.entity.MesXslRubberQuickTestRecord;
import org.jeecg.modules.xslmes.entity.MesXslRubberQuickTestRecordLine;
import org.jeecg.modules.xslmes.entity.MesXslRubberQuickTestStd;
@@ -50,11 +51,13 @@ import org.jeecg.modules.xslmes.service.IMesXslVehicleService;
import org.jeecg.modules.xslmes.service.IMesXslWarehouseAreaService;
import org.jeecg.modules.xslmes.service.IMesXslWarehouseService;
import org.jeecg.modules.xslmes.service.IMesXslMixingProductionPlanService;
import org.jeecg.modules.xslmes.service.IMesXslRubberQuickTestMethodService;
import org.jeecg.modules.xslmes.service.IMesXslRubberQuickTestRecordService;
import org.jeecg.modules.xslmes.service.IMesXslRubberQuickTestStdService;
import org.jeecg.modules.xslmes.service.IMesXslWeightRecordService;
import org.jeecg.modules.xslmes.service.MesXslStompNotifyService;
import org.jeecg.modules.xslmes.vo.MesXslRawMaterialCardBriefVO;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
@@ -100,6 +103,7 @@ public class MesXslDesktopAnonController {
private final IMesXslMixingProductionPlanService mixingProductionPlanService;
private final IMesXslRubberQuickTestStdService rubberQuickTestStdService;
private final IMesXslRubberQuickTestRecordService rubberQuickTestRecordService;
private final IMesXslRubberQuickTestMethodService rubberQuickTestMethodService;
// ═══════════════════════════ 车辆管理 ═══════════════════════════
@@ -965,6 +969,9 @@ public class MesXslDesktopAnonController {
QueryWrapper<MesXslRubberQuickTestStd> qw = QueryGenerator.initQueryWrapper(model, req.getParameterMap());
qw.orderByDesc("create_time");
IPage<MesXslRubberQuickTestStd> page = rubberQuickTestStdService.page(new Page<>(pageNo, pageSize), qw);
if (page.getRecords() != null) {
page.getRecords().forEach(this::fillStdQuickTestTypeFromMethod);
}
return Result.OK(page);
}
@@ -976,6 +983,7 @@ public class MesXslDesktopAnonController {
return Result.error("未找到对应数据");
}
entity.setLineList(rubberQuickTestStdService.selectLinesByStdId(id));
fillStdQuickTestTypeFromMethod(entity);
return Result.OK(entity);
}
//update-end---author:jiangxh ---date:2026-06-17 for【快检实验标准】桌面端只读列表与详情-----------
@@ -1001,6 +1009,7 @@ public class MesXslDesktopAnonController {
return Result.error("未找到胶料「" + name + "」对应的使用中且已批准的快检实验标准");
}
std.setLineList(rubberQuickTestStdService.selectLinesByStdId(std.getId()));
fillStdQuickTestTypeFromMethod(std);
return Result.OK(std);
}
@@ -1013,6 +1022,30 @@ public class MesXslDesktopAnonController {
//update-end---author:jiangxh ---date:2026-06-17 for【快检记录】桌面端胶料快检实验标准查询-----------
//update-begin---author:jiangxh ---date:2026-06-17 for【快检记录】桌面端胶料快检记录保存-----------
@Operation(summary = "胶料快检记录-免密分页列表")
@GetMapping("/xslmes/mesXslRubberQuickTestRecord/anon/list")
public Result<IPage<MesXslRubberQuickTestRecord>> rubberQuickTestRecordAnonList(
MesXslRubberQuickTestRecord model,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "20") Integer pageSize,
HttpServletRequest req) {
QueryWrapper<MesXslRubberQuickTestRecord> qw = QueryGenerator.initQueryWrapper(model, req.getParameterMap());
qw.orderByDesc("create_time");
IPage<MesXslRubberQuickTestRecord> page = rubberQuickTestRecordService.page(new Page<>(pageNo, pageSize), qw);
return Result.OK(page);
}
@Operation(summary = "胶料快检记录-免密通过id查询含明细")
@GetMapping("/xslmes/mesXslRubberQuickTestRecord/anon/queryById")
public Result<MesXslRubberQuickTestRecord> rubberQuickTestRecordAnonQueryById(@RequestParam(name = "id") String id) {
MesXslRubberQuickTestRecord entity = rubberQuickTestRecordService.getById(id);
if (entity == null) {
return Result.error("未找到对应数据");
}
fillRubberQuickTestRecordDetails(entity);
return Result.OK(entity);
}
@Operation(summary = "胶料快检记录-免密添加")
@PostMapping("/xslmes/mesXslRubberQuickTestRecord/anon/add")
public Result<String> rubberQuickTestRecordAnonAdd(@RequestBody MesXslRubberQuickTestRecord record) {
@@ -1022,21 +1055,57 @@ public class MesXslDesktopAnonController {
if (oConvertUtils.isEmpty(record.getRubberMaterialName())) {
return Result.error("胶料名称不能为空");
}
List<MesXslRubberQuickTestRecordLine> lineList = record.getLineList();
if (lineList == null || lineList.isEmpty()) {
return Result.error("请维护检验明细");
if (CollectionUtils.isEmpty(record.getStdLineList())) {
return Result.error("请维护数据标准明细");
}
if (CollectionUtils.isEmpty(record.getRawLineList())) {
return Result.error("请维护试验结果明细");
}
//update-begin---author:jiangxh ---date:20260617 for【快检记录】桌面端同步须含曲线图数据-----------
if (CollectionUtils.isEmpty(record.getChartPointList())) {
return Result.error("请维护曲线图数据");
}
//update-end---author:jiangxh ---date:20260617 for【快检记录】桌面端同步须含曲线图数据-----------
try {
rubberQuickTestRecordService.saveMain(record, lineList);
if (oConvertUtils.isEmpty(record.getRecordNo())) {
record.setRecordNo(rubberQuickTestRecordService.generateDesktopRecordNo(record));
}
rubberQuickTestRecordService.fillStdAndTypeForRecord(record);
rubberQuickTestRecordService.saveMain(record, record.getLineList());
stompNotify.publishRubberQuickTestRecordChanged("add", record.getId());
return Result.OK("添加成功!");
return Result.OK(record.getRecordNo());
} catch (Exception e) {
log.error(e.getMessage(), e);
return Result.error(e.getMessage());
}
}
private void fillRubberQuickTestRecordDetails(MesXslRubberQuickTestRecord entity) {
if (entity == null || oConvertUtils.isEmpty(entity.getId())) {
return;
}
String id = entity.getId();
entity.setStdLineList(rubberQuickTestRecordService.selectStdLinesByRecordId(id));
entity.setRawLineList(rubberQuickTestRecordService.selectRawLinesByRecordId(id));
entity.setChartPointList(rubberQuickTestRecordService.selectChartPointsByRecordId(id));
entity.setLineList(rubberQuickTestRecordService.selectLinesByRecordId(id));
}
//update-end---author:jiangxh ---date:2026-06-17 for【快检记录】桌面端胶料快检记录保存-----------
//update-begin---author:jiangxh ---date:20260618 for【快检实验标准】桌面端回填实验方法关联实验类型-----------
private void fillStdQuickTestTypeFromMethod(MesXslRubberQuickTestStd std) {
if (std == null || oConvertUtils.isEmpty(std.getTestMethodId())) {
return;
}
MesXslRubberQuickTestMethod method = rubberQuickTestMethodService.getById(std.getTestMethodId());
if (method == null) {
return;
}
std.setQuickTestTypeId(method.getQuickTestTypeId());
std.setQuickTestTypeName(method.getQuickTestTypeName());
}
//update-end---author:jiangxh ---date:20260618 for【快检实验标准】桌面端回填实验方法关联实验类型-----------
// ─────────────────────────── 车辆私有辅助 ────────────────────────────
private void applyWeightNetAndBillType(MesXslWeightRecord record) {

View File

@@ -112,13 +112,14 @@ public class MesXslMixerActionController extends JeecgController<MesXslMixerActi
@Operation(summary = "校验动作名称是否重复")
@GetMapping("/checkActionName")
public Result<String> checkActionName(
@RequestParam(name = "equipmentId", required = false) String equipmentId,
@RequestParam(name = "actionName", required = true) String actionName,
@RequestParam(name = "dataId", required = false) String dataId) {
if (oConvertUtils.isEmpty(actionName) || actionName.trim().isEmpty()) {
return Result.OK("该值可用!");
}
if (mesXslMixerActionService.isActionNameDuplicated(actionName, dataId)) {
return Result.error("动作名称不能重复");
if (mesXslMixerActionService.isActionNameDuplicated(equipmentId, actionName, dataId)) {
return Result.error("同一设备下动作名称不能重复");
}
return Result.OK("该值可用!");
}
@@ -126,13 +127,14 @@ public class MesXslMixerActionController extends JeecgController<MesXslMixerActi
@Operation(summary = "校验动作代号是否重复")
@GetMapping("/checkActionCode")
public Result<String> checkActionCode(
@RequestParam(name = "equipmentId", required = false) String equipmentId,
@RequestParam(name = "actionCode", required = true) String actionCode,
@RequestParam(name = "dataId", required = false) String dataId) {
if (oConvertUtils.isEmpty(actionCode) || actionCode.trim().isEmpty()) {
return Result.OK("该值可用!");
}
if (mesXslMixerActionService.isActionCodeDuplicated(actionCode, dataId)) {
return Result.error("动作代号不能重复");
if (mesXslMixerActionService.isActionCodeDuplicated(equipmentId, actionCode, dataId)) {
return Result.error("同一设备下动作代号不能重复");
}
return Result.OK("该值可用!");
}
@@ -152,15 +154,15 @@ public class MesXslMixerActionController extends JeecgController<MesXslMixerActi
return "动作名称不能为空";
}
model.setActionName(model.getActionName().trim());
if (mesXslMixerActionService.isActionNameDuplicated(model.getActionName(), excludeId)) {
return "动作名称不能重复";
if (mesXslMixerActionService.isActionNameDuplicated(model.getEquipmentId(), model.getActionName(), excludeId)) {
return "同一设备下动作名称不能重复";
}
if (oConvertUtils.isEmpty(model.getActionCode()) || StringUtils.isBlank(model.getActionCode())) {
return "动作代号不能为空";
}
model.setActionCode(model.getActionCode().trim());
if (mesXslMixerActionService.isActionCodeDuplicated(model.getActionCode(), excludeId)) {
return "动作代号不能重复";
if (mesXslMixerActionService.isActionCodeDuplicated(model.getEquipmentId(), model.getActionCode(), excludeId)) {
return "同一设备下动作代号不能重复";
}
return null;
}

View File

@@ -13,6 +13,7 @@ import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.xslmes.entity.MesXslMixingProductionPlan;
import org.jeecg.modules.xslmes.service.IMesXslMixingProductionPlanService;
import org.jeecg.modules.xslmes.service.MesXslStompNotifyService;
import org.jeecg.modules.xslmes.vo.MesXslMixingProductionPlanOrderOptionVO;
import org.jeecg.modules.xslmes.vo.MesXslMixingProductionPlanSaveAllVO;
import org.springframework.web.bind.annotation.GetMapping;
@@ -29,10 +30,13 @@ public class MesXslMixingProductionPlanController
extends JeecgController<MesXslMixingProductionPlan, IMesXslMixingProductionPlanService> {
private final IMesXslMixingProductionPlanService mixingProductionPlanService;
private final MesXslStompNotifyService stompNotify;
public MesXslMixingProductionPlanController(
IMesXslMixingProductionPlanService mixingProductionPlanService) {
IMesXslMixingProductionPlanService mixingProductionPlanService,
MesXslStompNotifyService stompNotify) {
this.mixingProductionPlanService = mixingProductionPlanService;
this.stompNotify = stompNotify;
}
@Operation(summary = "密炼生产计划维护-分页列表查询")
@@ -56,6 +60,9 @@ public class MesXslMixingProductionPlanController
@PostMapping("/saveAll")
public Result<String> saveAll(@RequestBody MesXslMixingProductionPlanSaveAllVO req) {
mixingProductionPlanService.saveAllRows(req == null ? null : req.getRows());
//update-begin---author:jiangxh ---date:20260617 for【密炼计划】整表保存后广播桌面端同步-----------
stompNotify.publishMixingProductionPlanChanged("saveAll", null);
//update-end---author:jiangxh ---date:20260617 for【密炼计划】整表保存后广播桌面端同步-----------
return Result.OK("保存成功");
}

View File

@@ -23,8 +23,10 @@ import org.jeecg.modules.mes.material.service.IMesMaterialService;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.service.ISysUserService;
import org.jeecg.modules.xslmes.entity.MesXslRubberQuickTestRecord;
import org.jeecg.modules.xslmes.entity.MesXslRubberQuickTestRecordChartPoint;
import org.jeecg.modules.xslmes.entity.MesXslRubberQuickTestRecordLine;
import org.jeecg.modules.xslmes.entity.MesXslRubberQuickTestRecordRawLine;
import org.jeecg.modules.xslmes.entity.MesXslRubberQuickTestRecordStdLine;
import org.jeecg.modules.xslmes.entity.MesXslRubberQuickTestType;
import org.jeecg.modules.xslmes.service.IMesXslRubberQuickTestRecordService;
import org.jeecg.modules.xslmes.service.IMesXslRubberQuickTestTypeService;
@@ -32,6 +34,7 @@ import org.jeecg.modules.xslmes.vo.MesXslRubberQuickTestRecordBatchFromMaterialV
import org.jeecg.modules.xslmes.vo.MesXslRubberQuickTestRecordPage;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
@@ -117,16 +120,9 @@ public class MesXslRubberQuickTestRecordController
@RequiresPermissions("mes:mes_material:rubberQuickTestInspect")
@PostMapping(value = "/batchFromMaterial")
public Result<List<String>> batchFromMaterial(@RequestBody MesXslRubberQuickTestRecordBatchFromMaterialVO vo) {
try {
//update-begin---author:jiangxh ---date:20260616 for【MES】胶料快检记录批量生成默认带出当前登录检验人-----------
fillInspectorIfEmpty(vo);
//update-end---author:jiangxh ---date:20260616 for【MES】胶料快检记录批量生成默认带出当前登录检验人-----------
List<String> ids = mesXslRubberQuickTestRecordService.batchFromMaterial(vo);
return Result.OK("成功生成 " + ids.size() + " 条快检记录", ids);
} catch (Exception e) {
log.error(e.getMessage(), e);
return Result.error(e.getMessage());
}
//update-begin---author:jiangxh ---date:2026-06-22 for【快检记录】取消胶料列表批量生成改由桌面端同步-----------
return Result.error("该功能已停用,请通过桌面端新增并同步胶料快检记录");
//update-end---author:jiangxh ---date:2026-06-22 for【快检记录】取消胶料列表批量生成改由桌面端同步-----------
}
@AutoLog(value = "MES胶料快检记录-删除")
@@ -154,6 +150,12 @@ public class MesXslRubberQuickTestRecordController
if (entity == null) {
return Result.error("未找到对应数据");
}
//update-begin---author:jiangxh ---date:2026-06-22 for【快检记录】查询含数据标准/试验结果/曲线图明细-----------
entity.setStdLineList(mesXslRubberQuickTestRecordService.selectStdLinesByRecordId(id));
entity.setRawLineList(mesXslRubberQuickTestRecordService.selectRawLinesByRecordId(id));
entity.setChartPointList(mesXslRubberQuickTestRecordService.selectChartPointsByRecordId(id));
entity.setLineList(mesXslRubberQuickTestRecordService.selectLinesByRecordId(id));
//update-end---author:jiangxh ---date:2026-06-22 for【快检记录】查询含数据标准/试验结果/曲线图明细-----------
return Result.OK(entity);
}
@@ -173,6 +175,22 @@ public class MesXslRubberQuickTestRecordController
}
//update-end---author:jiangxh ---date:2026-06-17 for【快检记录】查询原始数据明细-----------
//update-begin---author:jiangxh ---date:2026-06-22 for【快检记录】查询数据标准明细与曲线图-----------
@Operation(summary = "MES胶料快检记录-查询数据标准明细")
@GetMapping(value = "/queryStdLineListByRecordId")
public Result<List<MesXslRubberQuickTestRecordStdLine>> queryStdLineListByRecordId(
@RequestParam(name = "id", required = true) String id) {
return Result.OK(mesXslRubberQuickTestRecordService.selectStdLinesByRecordId(id));
}
@Operation(summary = "MES胶料快检记录-查询曲线图数据点")
@GetMapping(value = "/queryChartPointListByRecordId")
public Result<List<MesXslRubberQuickTestRecordChartPoint>> queryChartPointListByRecordId(
@RequestParam(name = "id", required = true) String id) {
return Result.OK(mesXslRubberQuickTestRecordService.selectChartPointsByRecordId(id));
}
//update-end---author:jiangxh ---date:2026-06-22 for【快检记录】查询数据标准明细与曲线图-----------
@RequiresPermissions("mes:mes_xsl_rubber_quick_test_record:exportXls")
@RequestMapping(value = "/exportXls")
public ModelAndView exportXls(HttpServletRequest request, MesXslRubberQuickTestRecord model) {
@@ -189,14 +207,22 @@ public class MesXslRubberQuickTestRecordController
if (main == null) {
return "参数不能为空";
}
if (oConvertUtils.isEmpty(main.getRubberMaterialId())) {
return "请选择胶料";
//update-begin---author:jiangxh ---date:2026-06-22 for【快检记录】Web保存校验支持桌面端三类明细-----------
if (oConvertUtils.isNotEmpty(main.getRubberMaterialId())) {
MesMaterial material = mesMaterialService.getById(main.getRubberMaterialId());
if (material == null) {
return "所选胶料不存在";
}
main.setRubberMaterialName(material.getMaterialName());
} else if (oConvertUtils.isEmpty(main.getRubberMaterialName())) {
return "胶料名称不能为空";
}
MesMaterial material = mesMaterialService.getById(main.getRubberMaterialId());
if (material == null) {
return "所选胶料不存在";
if (!CollectionUtils.isEmpty(main.getStdLineList()) && !CollectionUtils.isEmpty(main.getRawLineList())) {
resolveInspector(main);
return null;
}
main.setRubberMaterialName(material.getMaterialName());
//update-end---author:jiangxh ---date:2026-06-22 for【快检记录】Web保存校验支持桌面端三类明细-----------
if (oConvertUtils.isNotEmpty(main.getQuickTestTypeId())) {
MesXslRubberQuickTestType type = mesXslRubberQuickTestTypeService.getById(main.getQuickTestTypeId());

View File

@@ -38,6 +38,16 @@ public class MesXslMixerAction implements Serializable {
@Schema(description = "设备名称冗余")
private String equipmentName;
//update-begin---author:GHT ---date:20260617 for【MES上辅机】密炼动作秒级采集-补全机台字段-----------
@Excel(name = "机台编号", width = 15)
@Schema(description = "机台编号(采集自中间表 EquipID")
private String equipId;
@Excel(name = "机台类型", width = 15)
@Schema(description = "机台类型(采集自中间表 EquipType")
private String equipType;
//update-end---author:GHT ---date:20260617 for【MES上辅机】密炼动作秒级采集-补全机台字段-----------
@Excel(name = "动作名称", width = 20)
@Schema(description = "动作名称")
private String actionName;

View File

@@ -32,8 +32,8 @@ public class MesXslRubberQuickTestRecord implements Serializable {
@TableId(type = IdType.ASSIGN_ID)
private String id;
@Excel(name = "", width = 16)
@Schema(description = "单号JL+yyyyMMdd+4位流水")
@Excel(name = "快检记录", width = 16)
@Schema(description = "快检记录号(yyyyMMdd+4位流水+胶料名称")
private String recordNo;
@Schema(description = "胶料ID mes_material.id")
@@ -46,14 +46,25 @@ public class MesXslRubberQuickTestRecord implements Serializable {
@Schema(description = "引用的实验标准ID")
private String stdId;
@Schema(description = "生产机台ID")
@Excel(name = "实验标准", width = 20)
@Schema(description = "实验标准名称冗余")
private String stdName;
@Schema(description = "实验方法ID")
private String testMethodId;
@Excel(name = "实验方法", width = 20)
@Schema(description = "实验方法名称冗余")
private String testMethodName;
@Schema(description = "炼机台ID")
private String prodEquipmentLedgerId;
@Excel(name = "生产机台", width = 16)
@Schema(description = "生产机台名称冗余")
@Excel(name = "机台", width = 16)
@Schema(description = "机台名称冗余")
private String prodEquipmentName;
@Excel(name = "生产日期", width = 12, format = "yyyy-MM-dd")
@Excel(name = "密炼日期", width = 12, format = "yyyy-MM-dd")
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date productionDate;
@@ -69,7 +80,7 @@ public class MesXslRubberQuickTestRecord implements Serializable {
@Dict(dicCode = "xslmes_rubber_quick_test_work_team")
private String workTeam;
@Excel(name = "验次数", width = 10)
@Excel(name = "验次数", width = 10)
private Integer inspectTimes;
@Excel(name = "检验时间", width = 18, format = "yyyy-MM-dd HH:mm:ss")
@@ -86,17 +97,17 @@ public class MesXslRubberQuickTestRecord implements Serializable {
@Excel(name = "检验人", width = 12)
private String inspectorRealname;
@Schema(description = "验类型ID")
@Schema(description = "验类型ID")
private String quickTestTypeId;
@Excel(name = "验类型", width = 16)
@Excel(name = "验类型", width = 16)
private String quickTestTypeName;
@Excel(name = "检验结果", width = 10, dicCode = "xslmes_rubber_quick_test_record_result")
@Dict(dicCode = "xslmes_rubber_quick_test_record_result")
private String inspectResult;
@Excel(name = "生产计划", width = 16)
@Excel(name = "密炼计划", width = 16)
private String productionPlanNo;
@Schema(description = "检验机台ID")
@@ -134,4 +145,14 @@ public class MesXslRubberQuickTestRecord implements Serializable {
@TableField(exist = false)
@Schema(description = "原始数据明细(试验结果全部检测值)")
private List<MesXslRubberQuickTestRecordRawLine> rawLineList;
//update-begin---author:jiangxh ---date:2026-06-22 for【快检记录】数据标准明细与曲线图-----------
@TableField(exist = false)
@Schema(description = "数据标准明细(实验标准快照)")
private List<MesXslRubberQuickTestRecordStdLine> stdLineList;
@TableField(exist = false)
@Schema(description = "曲线图数据点")
private List<MesXslRubberQuickTestRecordChartPoint> chartPointList;
//update-end---author:jiangxh ---date:2026-06-22 for【快检记录】数据标准明细与曲线图-----------
}

View File

@@ -0,0 +1,59 @@
package org.jeecg.modules.xslmes.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
/**
* MES 胶料快检记录曲线图数据点
*/
@Data
@TableName("mes_xsl_rubber_quick_test_record_chart_point")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@Schema(description = "MES胶料快检记录曲线图数据点")
public class MesXslRubberQuickTestRecordChartPoint implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(type = IdType.ASSIGN_ID)
private String id;
@Schema(description = "主表ID mes_xsl_rubber_quick_test_record.id")
private String recordId;
@Excel(name = "时间(min)", width = 12, type = 10)
private BigDecimal timeMin;
@Excel(name = "上模温度", width = 12, type = 10)
private BigDecimal upperTemp;
@Excel(name = "下模温度", width = 12, type = 10)
private BigDecimal lowerTemp;
@Excel(name = "S'(dNm)", width = 12, type = 10)
private BigDecimal torqueS;
private Integer sortNo;
private String createBy;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
private String updateBy;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
}

View File

@@ -0,0 +1,68 @@
package org.jeecg.modules.xslmes.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
/**
* MES 胶料快检记录数据标准明细(实验标准快照)
*/
@Data
@TableName("mes_xsl_rubber_quick_test_record_std_line")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@Schema(description = "MES胶料快检记录数据标准明细")
public class MesXslRubberQuickTestRecordStdLine implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(type = IdType.ASSIGN_ID)
private String id;
@Schema(description = "主表ID mes_xsl_rubber_quick_test_record.id")
private String recordId;
@Schema(description = "数据点ID")
private String dataPointId;
@Excel(name = "数据点", width = 18)
private String pointName;
@Excel(name = "下限值", width = 12, type = 10)
private BigDecimal lowerLimit;
@Excel(name = "上限值", width = 12, type = 10)
private BigDecimal upperLimit;
@Excel(name = "下限预警", width = 12, type = 10)
private BigDecimal lowerWarn;
@Excel(name = "上限预警", width = 12, type = 10)
private BigDecimal upperWarn;
@Excel(name = "目标值", width = 12, type = 10)
private BigDecimal targetValue;
private Integer sortNo;
private String createBy;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
private String updateBy;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
}

View File

@@ -106,4 +106,12 @@ public class MesXslRubberQuickTestStd implements Serializable {
@TableField(exist = false)
@Schema(description = "标准明细")
private List<MesXslRubberQuickTestStdLine> lineList;
@TableField(exist = false)
@Schema(description = "实验类型ID来自实验方法桌面端展示")
private String quickTestTypeId;
@TableField(exist = false)
@Schema(description = "实验类型名称(来自实验方法,桌面端展示)")
private String quickTestTypeName;
}

View File

@@ -0,0 +1,6 @@
package org.jeecg.modules.xslmes.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.jeecg.modules.xslmes.entity.MesXslRubberQuickTestRecordChartPoint;
public interface MesXslRubberQuickTestRecordChartPointMapper extends BaseMapper<MesXslRubberQuickTestRecordChartPoint> {}

View File

@@ -0,0 +1,7 @@
package org.jeecg.modules.xslmes.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.jeecg.modules.xslmes.entity.MesXslRubberQuickTestRecordStdLine;
public interface MesXslRubberQuickTestRecordStdLineMapper extends BaseMapper<MesXslRubberQuickTestRecordStdLine> {
}

View File

@@ -0,0 +1,150 @@
package org.jeecg.modules.xslmes.mcs.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.xslmes.mcs.datasource.McsDataSourceManager;
import org.jeecg.modules.xslmes.mcs.entity.MesXslMcsSyncConfig;
import org.jeecg.modules.xslmes.mcs.mapper.McsMetaMapper;
import org.jeecg.modules.xslmes.mcs.service.IMesXslMcsSyncConfigService;
import org.jeecg.modules.xslmes.mcs.sync.McsSyncScheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
* MES上辅机 中间表采集配置(表/字段绑定 + 采集操作 + 元数据)
*
* @author GHT
* @date 2026-06-17 for【MES上辅机】采集配置-表与字段绑定
*/
@Tag(name = "MES上辅机采集配置")
@RestController
@RequestMapping("/xslmes/mcs/syncConfig")
public class MesXslMcsSyncConfigController {
@Autowired
private IMesXslMcsSyncConfigService syncConfigService;
@Autowired
private McsSyncScheduler syncScheduler;
@Autowired
private McsMetaMapper metaMapper;
@Autowired
private McsDataSourceManager mcsDataSourceManager;
@Operation(summary = "采集配置-分页列表")
@GetMapping("/list")
public Result<IPage<MesXslMcsSyncConfig>> list(MesXslMcsSyncConfig query,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
LambdaQueryWrapper<MesXslMcsSyncConfig> qw = new LambdaQueryWrapper<MesXslMcsSyncConfig>()
.eq(MesXslMcsSyncConfig::getDelFlag, 0)
.like(StringUtils.isNotBlank(query.getConfigName()), MesXslMcsSyncConfig::getConfigName, query.getConfigName())
.like(StringUtils.isNotBlank(query.getSourceTable()), MesXslMcsSyncConfig::getSourceTable, query.getSourceTable())
.orderByDesc(MesXslMcsSyncConfig::getUpdateTime);
IPage<MesXslMcsSyncConfig> page = syncConfigService.page(new Page<>(pageNo, pageSize), qw);
page.getRecords().forEach(c -> c.setRunning(syncScheduler.isRunning(c.getId())));
return Result.OK(page);
}
@Operation(summary = "采集配置-详情(含字段映射)")
@GetMapping("/queryById")
public Result<MesXslMcsSyncConfig> queryById(@RequestParam("id") String id) {
MesXslMcsSyncConfig cfg = syncConfigService.getDetail(id);
if (cfg == null) {
return Result.error("配置不存在");
}
cfg.setRunning(syncScheduler.isRunning(id));
return Result.OK(cfg);
}
@Operation(summary = "采集配置-按业务类型获取(密炼动作页用)")
@GetMapping("/getByBizType")
public Result<MesXslMcsSyncConfig> getByBizType(@RequestParam(name = "bizType", defaultValue = "MIX_ACT") String bizType) {
MesXslMcsSyncConfig cfg = syncConfigService.getByBizType(bizType);
if (cfg != null) {
cfg.setRunning(syncScheduler.isRunning(cfg.getId()));
}
return Result.OK(cfg);
}
@Operation(summary = "采集配置-新增")
@RequiresPermissions("xslmes:mcsSyncConfig:add")
@PostMapping("/add")
public Result<String> add(@RequestBody MesXslMcsSyncConfig config) {
config.setId(null);
return syncConfigService.saveConfig(config);
}
@Operation(summary = "采集配置-编辑")
@RequiresPermissions("xslmes:mcsSyncConfig:edit")
@PostMapping("/edit")
public Result<String> edit(@RequestBody MesXslMcsSyncConfig config) {
if (StringUtils.isBlank(config.getId())) {
return Result.error("缺少配置ID");
}
return syncConfigService.saveConfig(config);
}
@Operation(summary = "采集配置-删除")
@RequiresPermissions("xslmes:mcsSyncConfig:delete")
@DeleteMapping("/delete")
public Result<String> delete(@RequestParam("id") String id) {
return syncConfigService.deleteConfig(id);
}
@Operation(summary = "采集操作-是否采集+采集间隔")
@RequiresPermissions("xslmes:mcsSyncConfig:setting")
@PostMapping("/saveCollect")
public Result<String> saveCollect(@RequestBody MesXslMcsSyncConfig body) {
return syncConfigService.saveCollect(body);
}
// ===================== 元数据 =====================
@Operation(summary = "元数据-中间库表清单")
@GetMapping("/meta/sourceTables")
public Result<List<Map<String, Object>>> sourceTables() {
if (!mcsDataSourceManager.isDbConfigActive()) {
return Result.error("中间库未连接,请先在「中间库连接配置」中启用");
}
return Result.OK(metaMapper.listSourceTables());
}
@Operation(summary = "元数据-中间库表字段")
@GetMapping("/meta/sourceColumns")
public Result<List<Map<String, Object>>> sourceColumns(@RequestParam("table") String table) {
if (!mcsDataSourceManager.isDbConfigActive()) {
return Result.error("中间库未连接,请先在「中间库连接配置」中启用");
}
if (!table.matches("^[A-Za-z0-9_]+$")) {
return Result.error("非法表名");
}
return Result.OK(metaMapper.listSourceColumns(table));
}
@Operation(summary = "元数据-MES业务表清单(mes_xsl_前缀)")
@GetMapping("/meta/targetTables")
public Result<List<Map<String, Object>>> targetTables() {
return Result.OK(metaMapper.listTargetTables());
}
@Operation(summary = "元数据-MES表字段")
@GetMapping("/meta/targetColumns")
public Result<List<Map<String, Object>>> targetColumns(@RequestParam("table") String table) {
if (!table.matches("^[A-Za-z0-9_]+$")) {
return Result.error("非法表名");
}
return Result.OK(metaMapper.listTargetColumns(table));
}
}

View File

@@ -0,0 +1,126 @@
package org.jeecg.modules.xslmes.mcs.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* MES上辅机 中间表采集配置(通用)
* <p>按 bizType 区分不同业务(密炼动作/报警/配方等),供秒级定时采集统一复用</p>
*
* @author GHT
* @date 2026-06-17 for【MES上辅机】密炼动作秒级采集
*/
@Data
@TableName("mes_xsl_mcs_sync_config")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@Schema(description = "MES上辅机中间表采集配置")
public class MesXslMcsSyncConfig implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(type = IdType.ASSIGN_ID)
@Schema(description = "主键")
private String id;
@Schema(description = "业务类型(采集任务唯一标识,如 MIX_ACT 密炼动作;通用配置可为空)")
private String bizType;
@Schema(description = "配置名称")
private String configName;
@Schema(description = "业务名称")
private String bizName;
@Schema(description = "源中间表名")
private String sourceTable;
@Schema(description = "源中间表注释")
private String sourceTableComment;
@Schema(description = "MES目标表名")
private String targetTable;
@Schema(description = "MES目标表注释")
private String targetTableComment;
@Schema(description = "采集时间间隔(秒)默认1秒")
private Integer intervalSeconds;
@Schema(description = "采集状态(0停止,1运行)")
private String status;
@Schema(description = "采集模式(FULL全量匹配,TIME时间匹配,INCR增量匹配-标记位回写)")
private String syncMode;
@Schema(description = "时间列/标记列(源表列名)。TIME模式=时间列INCR模式=同步标记列(为空表示未采集,采集后回写'1')")
private String incrColumn;
@Schema(description = "时间范围(TODAY当天,LAST7最近七天)")
private String timeWindow;
@Schema(description = "每轮最大采集行数(INCR模式TOP N)")
private Integer batchLimit;
@Schema(description = "增量采集高水位(INCR模式自动维护)")
private String lastWatermark;
@Schema(description = "增量标记采集条件(IS_NULL为空,EQ_EMPTY等于匹配值,NE_EMPTY不等于匹配值)INCR模式用")
private String flagCondition;
//update-begin---author:GHT ---date:20260617 for【MES上辅机】增量采集条件等于/不等于支持自定义匹配值-----------
@Schema(description = "增量标记采集条件比较值(EQ_EMPTY/NE_EMPTY 用,留空表示空字符串)INCR模式用")
private String flagMatchValue;
//update-end---author:GHT ---date:20260617 for【MES上辅机】增量采集条件等于/不等于支持自定义匹配值-----------
@Schema(description = "增量标记采集完成后回写值(默认1)INCR模式用")
private String flagWriteValue;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Schema(description = "最近一次采集时间")
private Date lastSyncTime;
@Schema(description = "最近一次采集结果")
private String lastSyncResult;
@Schema(description = "备注")
private String remark;
@Schema(description = "租户ID")
private Integer tenantId;
private String createBy;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
private String updateBy;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
private Integer delFlag;
@TableField(exist = false)
@Schema(description = "字段映射明细(主子保存/详情用)")
private List<MesXslMcsSyncField> fieldList;
@TableField(exist = false)
@Schema(description = "采集任务是否运行中(运行态由调度器实时给出)")
private Boolean running;
}

View File

@@ -0,0 +1,75 @@
package org.jeecg.modules.xslmes.mcs.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
/**
* MES上辅机 采集字段映射(中间库源字段 → MES目标字段
*
* @author GHT
* @date 2026-06-17 for【MES上辅机】采集配置-表与字段绑定
*/
@Data
@TableName("mes_xsl_mcs_sync_field")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@Schema(description = "MES上辅机采集字段映射")
public class MesXslMcsSyncField implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(type = IdType.ASSIGN_ID)
@Schema(description = "主键")
private String id;
@Schema(description = "采集配置ID")
private String configId;
@Schema(description = "中间库源字段名")
private String sourceField;
@Schema(description = "源字段注释")
private String sourceFieldComment;
@Schema(description = "源字段类型")
private String sourceFieldType;
@Schema(description = "MES目标字段名(接收字段)")
private String targetField;
@Schema(description = "MES目标字段注释")
private String targetFieldComment;
@Schema(description = "是否匹配键(0否,1是)")
private String matchKey;
@Schema(description = "排序")
private Integer sortNo;
@Schema(description = "租户ID")
private Integer tenantId;
private String createBy;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
private String updateBy;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
private Integer delFlag;
}

View File

@@ -0,0 +1,58 @@
package org.jeecg.modules.xslmes.mcs.mapper;
import com.baomidou.dynamic.datasource.annotation.DS;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Map;
/**
* 中间库(SQL Server) / MES(MySQL) 表与字段元数据查询。
* <p>源表元数据走 sqlserver_mcs 数据源,目标表元数据走默认 MES 库。</p>
*
* @author GHT
* @date 2026-06-17 for【MES上辅机】采集配置-表与字段绑定
*/
public interface McsMetaMapper {
/**
* 中间库表清单(含表注释 MS_Description
*/
@DS("sqlserver_mcs")
@Select("SELECT t.name AS tableName, CAST(ep.value AS NVARCHAR(200)) AS tableComment "
+ "FROM sys.tables t "
+ "LEFT JOIN sys.extended_properties ep ON ep.major_id = t.object_id AND ep.minor_id = 0 AND ep.name = 'MS_Description' "
+ "ORDER BY t.name")
List<Map<String, Object>> listSourceTables();
/**
* 中间库表字段清单(含字段注释、类型)
*/
@DS("sqlserver_mcs")
@Select("SELECT c.name AS columnName, ty.name AS dataType, CAST(ep.value AS NVARCHAR(200)) AS columnComment "
+ "FROM sys.columns c "
+ "JOIN sys.types ty ON c.user_type_id = ty.user_type_id "
+ "LEFT JOIN sys.extended_properties ep ON ep.major_id = c.object_id AND ep.minor_id = c.column_id AND ep.name = 'MS_Description' "
+ "WHERE c.object_id = OBJECT_ID(#{table}) "
+ "ORDER BY c.column_id")
List<Map<String, Object>> listSourceColumns(@Param("table") String table);
/**
* MES 业务表清单(仅 mes_xsl_ 前缀)
*/
@Select("SELECT table_name AS tableName, table_comment AS tableComment "
+ "FROM information_schema.tables "
+ "WHERE table_schema = (SELECT DATABASE()) AND table_name LIKE 'mes\\_xsl\\_%' "
+ "ORDER BY table_name")
List<Map<String, Object>> listTargetTables();
/**
* MES 表字段清单(含字段注释、类型)
*/
@Select("SELECT column_name AS columnName, data_type AS dataType, column_comment AS columnComment "
+ "FROM information_schema.columns "
+ "WHERE table_schema = (SELECT DATABASE()) AND table_name = #{table} "
+ "ORDER BY ordinal_position")
List<Map<String, Object>> listTargetColumns(@Param("table") String table);
}

View File

@@ -0,0 +1,13 @@
package org.jeecg.modules.xslmes.mcs.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.jeecg.modules.xslmes.mcs.entity.MesXslMcsSyncConfig;
/**
* MES上辅机 中间表采集配置 Mapper
*
* @author GHT
* @date 2026-06-17 for【MES上辅机】密炼动作秒级采集
*/
public interface MesXslMcsSyncConfigMapper extends BaseMapper<MesXslMcsSyncConfig> {
}

View File

@@ -0,0 +1,13 @@
package org.jeecg.modules.xslmes.mcs.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.jeecg.modules.xslmes.mcs.entity.MesXslMcsSyncField;
/**
* MES上辅机 采集字段映射 Mapper
*
* @author GHT
* @date 2026-06-17 for【MES上辅机】采集配置-表与字段绑定
*/
public interface MesXslMcsSyncFieldMapper extends BaseMapper<MesXslMcsSyncField> {
}

View File

@@ -0,0 +1,40 @@
package org.jeecg.modules.xslmes.mcs.service;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.xslmes.mcs.entity.MesXslMcsSyncConfig;
/**
* MES上辅机 中间表采集配置 Service配置驱动表/字段绑定 + 采集操作)
*
* @author GHT
* @date 2026-06-17 for【MES上辅机】采集配置-表与字段绑定
*/
public interface IMesXslMcsSyncConfigService extends IService<MesXslMcsSyncConfig> {
/**
* 获取配置详情(含字段映射明细 fieldList
*/
MesXslMcsSyncConfig getDetail(String id);
/**
* 按业务类型获取最近配置密炼动作页用bizType=MIX_ACT
*/
MesXslMcsSyncConfig getByBizType(String bizType);
/**
* 保存配置(头 + 字段映射明细,主子整存)
*/
Result<String> saveConfig(MesXslMcsSyncConfig config);
/**
* 删除配置及其字段映射,并停止采集
*/
Result<String> deleteConfig(String id);
/**
* 采集操作:维护是否采集、采集间隔、采集模式(全量/时间/增量)及其参数。
* status='1' 启动并按间隔重排,'0' 停止。
*/
Result<String> saveCollect(MesXslMcsSyncConfig body);
}

View File

@@ -0,0 +1,223 @@
package org.jeecg.modules.xslmes.mcs.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.xslmes.mcs.entity.MesXslMcsSyncConfig;
import org.jeecg.modules.xslmes.mcs.entity.MesXslMcsSyncField;
import org.jeecg.modules.xslmes.mcs.mapper.MesXslMcsSyncConfigMapper;
import org.jeecg.modules.xslmes.mcs.mapper.MesXslMcsSyncFieldMapper;
import org.jeecg.modules.xslmes.mcs.service.IMesXslMcsSyncConfigService;
import org.jeecg.modules.xslmes.mcs.sync.McsSyncScheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* MES上辅机 中间表采集配置 Service 实现
*
* @author GHT
* @date 2026-06-17 for【MES上辅机】采集配置-表与字段绑定
*/
@Slf4j
@Service
public class MesXslMcsSyncConfigServiceImpl extends ServiceImpl<MesXslMcsSyncConfigMapper, MesXslMcsSyncConfig>
implements IMesXslMcsSyncConfigService {
@Autowired
private MesXslMcsSyncFieldMapper syncFieldMapper;
@Autowired
private McsSyncScheduler syncScheduler;
@Override
public MesXslMcsSyncConfig getDetail(String id) {
MesXslMcsSyncConfig cfg = getById(id);
if (cfg == null) {
return null;
}
cfg.setFieldList(listFields(id));
return cfg;
}
@Override
public MesXslMcsSyncConfig getByBizType(String bizType) {
return getOne(new LambdaQueryWrapper<MesXslMcsSyncConfig>()
.eq(MesXslMcsSyncConfig::getBizType, bizType)
.eq(MesXslMcsSyncConfig::getDelFlag, 0)
.orderByDesc(MesXslMcsSyncConfig::getUpdateTime)
.last("LIMIT 1"), false);
}
@Override
@Transactional(rollbackFor = Exception.class)
public Result<String> saveConfig(MesXslMcsSyncConfig config) {
if (config == null) {
return Result.error("配置不能为空");
}
if (StringUtils.isBlank(config.getSourceTable())) {
return Result.error("请选择中间库源表");
}
if (StringUtils.isBlank(config.getTargetTable())) {
return Result.error("请选择MES目标表");
}
List<MesXslMcsSyncField> fields = config.getFieldList() != null ? config.getFieldList() : new ArrayList<>();
// 至少一个有效映射
boolean hasValid = fields.stream().anyMatch(f -> StringUtils.isNotBlank(f.getSourceField())
&& StringUtils.isNotBlank(f.getTargetField()));
if (!hasValid) {
return Result.error("请至少配置一个字段映射(源字段+接收字段)");
}
String username = currentUsername();
Date now = new Date();
if (config.getIntervalSeconds() == null || config.getIntervalSeconds() < 1) {
config.setIntervalSeconds(1);
}
if (config.getTenantId() == null) {
config.setTenantId(0);
}
config.setDelFlag(0);
config.setUpdateBy(username);
config.setUpdateTime(now);
boolean isUpdate = StringUtils.isNotBlank(config.getId());
if (isUpdate) {
MesXslMcsSyncConfig old = getById(config.getId());
if (old == null) {
return Result.error("配置不存在");
}
// 状态由采集操作维护,保存配置不改变运行状态
config.setStatus(old.getStatus());
updateById(config);
} else {
if (StringUtils.isBlank(config.getStatus())) {
config.setStatus("0");
}
config.setCreateBy(username);
config.setCreateTime(now);
save(config);
}
// 整存字段映射:先物理删除旧映射再插入
syncFieldMapper.delete(new LambdaQueryWrapper<MesXslMcsSyncField>()
.eq(MesXslMcsSyncField::getConfigId, config.getId()));
int sort = 0;
for (MesXslMcsSyncField f : fields) {
if (StringUtils.isBlank(f.getSourceField())) {
continue;
}
f.setId(null);
f.setConfigId(config.getId());
f.setSortNo(sort++);
f.setTenantId(config.getTenantId());
f.setDelFlag(0);
f.setCreateBy(username);
f.setCreateTime(now);
f.setUpdateBy(username);
f.setUpdateTime(now);
syncFieldMapper.insert(f);
}
// 运行中则按新配置重排(间隔/映射即时生效)
if ("1".equals(config.getStatus())) {
syncScheduler.scheduleTask(getById(config.getId()));
}
return Result.OK(isUpdate ? "保存成功" : "新增成功");
}
@Override
@Transactional(rollbackFor = Exception.class)
public Result<String> deleteConfig(String id) {
MesXslMcsSyncConfig cfg = getById(id);
if (cfg == null) {
return Result.error("配置不存在");
}
syncScheduler.cancelTask(id);
syncFieldMapper.delete(new LambdaQueryWrapper<MesXslMcsSyncField>()
.eq(MesXslMcsSyncField::getConfigId, id));
removeById(id);
return Result.OK("删除成功");
}
@Override
public Result<String> saveCollect(MesXslMcsSyncConfig body) {
if (body == null || StringUtils.isBlank(body.getId())) {
return Result.error("缺少配置ID");
}
MesXslMcsSyncConfig cfg = getById(body.getId());
if (cfg == null) {
return Result.error("配置不存在");
}
if (body.getIntervalSeconds() != null) {
if (body.getIntervalSeconds() < 1) {
return Result.error("采集间隔不能小于1秒");
}
cfg.setIntervalSeconds(body.getIntervalSeconds());
}
// 采集模式及参数
String mode = StringUtils.isBlank(body.getSyncMode()) ? "FULL" : body.getSyncMode().trim().toUpperCase();
cfg.setSyncMode(mode);
cfg.setIncrColumn(StringUtils.trimToNull(body.getIncrColumn()));
cfg.setTimeWindow(StringUtils.isBlank(body.getTimeWindow()) ? "TODAY" : body.getTimeWindow());
if (body.getBatchLimit() != null && body.getBatchLimit() > 0) {
cfg.setBatchLimit(body.getBatchLimit());
}
// INCR(标记回写):采集条件 + 回写值(可视化配置,回写值默认"1"
cfg.setFlagCondition(StringUtils.isBlank(body.getFlagCondition()) ? "IS_NULL" : body.getFlagCondition().trim().toUpperCase());
//update-begin---author:GHT ---date:20260617 for【MES上辅机】增量采集条件等于/不等于支持自定义匹配值-----------
cfg.setFlagMatchValue(body.getFlagMatchValue());
//update-end---author:GHT ---date:20260617 for【MES上辅机】增量采集条件等于/不等于支持自定义匹配值-----------
cfg.setFlagWriteValue(StringUtils.isBlank(body.getFlagWriteValue()) ? "1" : body.getFlagWriteValue());
if (("TIME".equals(mode) || "INCR".equals(mode)) && StringUtils.isBlank(cfg.getIncrColumn())) {
return Result.error("时间匹配/增量匹配需选择" + ("TIME".equals(mode) ? "时间列" : "标记列"));
}
boolean on = "1".equals(body.getStatus());
cfg.setStatus(on ? "1" : "0");
cfg.setUpdateBy(currentUsername());
cfg.setUpdateTime(new Date());
updateById(cfg);
if (on) {
syncScheduler.scheduleTask(cfg);
return Result.OK("已启动采集(" + modeText(mode) + "),间隔 " + cfg.getIntervalSeconds() + "");
}
syncScheduler.cancelTask(cfg.getId());
return Result.OK("已停止采集");
}
private String modeText(String mode) {
switch (mode) {
case "TIME":
return "时间匹配";
case "INCR":
return "增量匹配";
default:
return "全量匹配";
}
}
private List<MesXslMcsSyncField> listFields(String configId) {
return syncFieldMapper.selectList(new LambdaQueryWrapper<MesXslMcsSyncField>()
.eq(MesXslMcsSyncField::getConfigId, configId)
.eq(MesXslMcsSyncField::getDelFlag, 0)
.orderByAsc(MesXslMcsSyncField::getSortNo));
}
private String currentUsername() {
try {
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
return user != null ? user.getUsername() : "system";
} catch (Exception e) {
return "system";
}
}
}

View File

@@ -0,0 +1,524 @@
package org.jeecg.modules.xslmes.mcs.sync;
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.modules.xslmes.mcs.datasource.McsDataSourceManager;
import org.jeecg.modules.xslmes.mcs.entity.MesXslMcsSyncConfig;
import org.jeecg.modules.xslmes.mcs.entity.MesXslMcsSyncField;
import org.jeecg.modules.xslmes.mcs.mapper.McsMetaMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* 通用中间表采集引擎(配置驱动,纯字段拷贝)。
* <p>支持三种采集模式,应对中间库不同规模的表:</p>
* <ul>
* <li><b>FULL 全量匹配</b>:全表读源+全表读目标→按匹配键 Upsert仅写新增/变化行。适合小状态表、以更新为主。</li>
* <li><b>TIME 时间匹配</b>:按时间列只取窗口内数据(当天/最近七天)→按匹配键 Upsert目标侧按窗口匹配键定向读取。避免全表扫描。</li>
* <li><b>INCR 增量匹配(标记位回写)</b>源表选一「同步标记列」仅采集该列为空NULL/''的行TOP N 限流),
* 按匹配键 Upsert 到 MES 后,回写源表该列为 {@code '1'},下轮不再重复采集。适合带 GUID 主键、无可靠递增列的流水表。</li>
* </ul>
*
* @author GHT
* @date 2026-06-17 for【MES上辅机】采集配置-表与字段绑定
*/
@Slf4j
@Component
public class GenericMcsSyncEngine {
public static final String MODE_FULL = "FULL";
public static final String MODE_TIME = "TIME";
public static final String MODE_INCR = "INCR";
/** 合法标识符(表名/列名),防止 SQL 注入 */
private static final Pattern IDENT = Pattern.compile("^[A-Za-z0-9_]+$");
/** 批量写入分批大小 */
private static final int BATCH_SIZE = 500;
/** IN 查询分块大小 */
private static final int IN_CHUNK = 1000;
/** INCR 默认每轮行数 */
private static final int DEFAULT_BATCH_LIMIT = 2000;
/** INCR 标记位回写后的已同步标识值 */
private static final String FLAG_SYNCED = "1";
@Autowired
private DataSource dataSource;
@Autowired
private McsMetaMapper metaMapper;
@Autowired
private org.jeecg.modules.xslmes.mcs.datasource.McsDataSourceManager mcsDataSourceManager;
//update-begin---author:GHT ---date:20260617 for【MES上辅机】采集模式 全量/时间/增量-----------
public String sync(MesXslMcsSyncConfig cfg, List<MesXslMcsSyncField> fields) {
String sourceTable = trim(cfg.getSourceTable());
String targetTable = trim(cfg.getTargetTable());
if (StringUtils.isBlank(sourceTable) || StringUtils.isBlank(targetTable)) {
return "未配置源表或目标表,跳过";
}
validateIdent(sourceTable);
validateIdent(targetTable);
List<MesXslMcsSyncField> maps = fields == null ? List.of() : fields.stream()
.filter(f -> StringUtils.isNotBlank(f.getSourceField()) && StringUtils.isNotBlank(f.getTargetField()))
.collect(Collectors.toList());
if (maps.isEmpty()) {
return "无有效字段映射,跳过";
}
for (MesXslMcsSyncField f : maps) {
validateIdent(f.getSourceField());
validateIdent(f.getTargetField());
}
String mode = StringUtils.isBlank(cfg.getSyncMode()) ? MODE_FULL : cfg.getSyncMode().trim().toUpperCase();
JdbcTemplate sourceJt = new JdbcTemplate(getSourceDataSource());
JdbcTemplate targetJt = new JdbcTemplate(dataSource);
// 目标表标准字段探测 + 自动填充列
Set<String> targetCols = metaMapper.listTargetColumns(targetTable).stream()
.map(m -> String.valueOf(m.get("columnName")).toLowerCase())
.collect(Collectors.toSet());
boolean hasDel = targetCols.contains("del_flag");
List<MesXslMcsSyncField> keyMaps = maps.stream().filter(f -> "1".equals(f.getMatchKey())).collect(Collectors.toList());
Set<String> keyTargetsLower = keyMaps.stream().map(k -> k.getTargetField().toLowerCase()).collect(Collectors.toSet());
List<MesXslMcsSyncField> nonKeyMaps = maps.stream()
.filter(f -> !keyTargetsLower.contains(f.getTargetField().toLowerCase()))
.collect(Collectors.toList());
int tenantId = cfg.getTenantId() != null ? cfg.getTenantId() : 0;
Timestamp now = new Timestamp(System.currentTimeMillis());
AutoCols auto = buildAutoCols(targetCols, maps, tenantId, now);
// 1. 按模式读源数据
LinkedHashSet<String> srcCols = maps.stream().map(MesXslMcsSyncField::getSourceField)
.collect(Collectors.toCollection(LinkedHashSet::new));
List<Map<String, Object>> rows;
//update-begin---author:GHT ---date:20260617 for【MES上辅机】增量匹配改为标记位回写-----------
// INCR(标记回写)模式:仅采集「标记列」为空的行,采完回写"1",下轮不再重复采集
String flagCol = null;
boolean flagMode = MODE_INCR.equals(mode);
if (flagMode) {
flagCol = requireIncrColumn(cfg);
if (keyMaps.isEmpty()) {
return "增量(标记)采集需在字段映射中勾选至少一个匹配键作为回写主键(如 GUID";
}
if (!mcsDataSourceManager.isWriteEnabled()) {
return "增量(标记)采集需开启中间库写入开关以回写同步标记,请在「中间库连接配置」开启写入";
}
srcCols.add(flagCol);
int limit = cfg.getBatchLimit() != null && cfg.getBatchLimit() > 0 ? cfg.getBatchLimit() : DEFAULT_BATCH_LIMIT;
String predicate = flagPredicate(flagCol, cfg.getFlagCondition(), cfg.getFlagMatchValue());
String sql = "SELECT TOP " + limit + " " + colList(srcCols) + " FROM [" + sourceTable + "]"
+ " WHERE (" + predicate + ")";
rows = sourceJt.queryForList(sql);
if (rows.isEmpty()) {
return "增量采集:无待采集数据";
}
} else if (MODE_TIME.equals(mode)) {
String incrCol = requireIncrColumn(cfg);
Timestamp[] window = timeWindow(cfg.getTimeWindow(), now);
StringBuilder sql = new StringBuilder("SELECT ").append(colList(srcCols))
.append(" FROM [").append(sourceTable).append("] WHERE [").append(incrCol).append("] >= ?");
List<Object> args = new ArrayList<>();
args.add(window[0]);
if (window[1] != null) {
sql.append(" AND [").append(incrCol).append("] < ?");
args.add(window[1]);
}
rows = sourceJt.queryForList(sql.toString(), args.toArray());
} else {
// FULL
rows = sourceJt.queryForList("SELECT " + colList(srcCols) + " FROM [" + sourceTable + "]");
}
if (rows.isEmpty()) {
return ("TIME".equals(mode) ? "时间匹配" : "全量匹配") + ":窗口/源表无数据,未更新";
}
// 无匹配键 → 整批追加
if (keyMaps.isEmpty()) {
int ins = appendInsert(targetJt, targetTable, maps, auto, rows);
return String.format("采集完成(无匹配键,追加):新增%d源%d条", ins, rows.size());
}
// 2. 加载现有目标数据FULL 全量TIME/INCR 仅按本批匹配键定向读取)
LinkedHashSet<String> existCols = new LinkedHashSet<>();
keyMaps.forEach(k -> existCols.add(k.getTargetField()));
maps.forEach(m -> existCols.add(m.getTargetField()));
Map<String, Map<String, Object>> existingByKey = (MODE_TIME.equals(mode) || flagMode)
? loadExistingByKeys(targetJt, targetTable, existCols, keyMaps, hasDel, rows)
: loadExistingAll(targetJt, targetTable, existCols, keyMaps, hasDel);
// 3. 比对 → 批量 Upsert
List<String> updateSetCols = nonKeyMaps.stream().map(MesXslMcsSyncField::getTargetField).collect(Collectors.toList());
boolean updTime = targetCols.contains("update_time") && !mappedContains(maps, "update_time");
boolean updBy = targetCols.contains("update_by") && !mappedContains(maps, "update_by");
String updateSql = buildUpdateSql(targetTable, updateSetCols, keyMaps, updTime, updBy, hasDel);
String insertSql = buildInsertSql(targetTable, maps, auto);
List<Object[]> insertArgs = new ArrayList<>();
List<Object[]> updateArgs = new ArrayList<>();
Set<String> handled = new HashSet<>();
int unchanged = 0;
for (Map<String, Object> row : rows) {
Map<String, Object> rci = ci(row);
String key = buildKeyFromSource(keyMaps, rci);
if (!handled.add(key)) {
continue;
}
Map<String, Object> existing = existingByKey.get(key);
if (existing == null) {
insertArgs.add(buildInsertArgs(maps, rci, auto));
} else if (updateSetCols.isEmpty()) {
unchanged++;
} else if (isChanged(nonKeyMaps, rci, existing)) {
updateArgs.add(buildUpdateArgs(nonKeyMaps, keyMaps, rci, updTime, updBy, now));
} else {
unchanged++;
}
}
int ins = batch(targetJt, insertSql, insertArgs);
int upd = updateSetCols.isEmpty() ? 0 : batch(targetJt, updateSql, updateArgs);
// INCR(标记回写):对本批所有源行回写标记值,下轮不再采集
if (flagMode) {
String writeValue = StringUtils.isBlank(cfg.getFlagWriteValue()) ? FLAG_SYNCED : cfg.getFlagWriteValue();
int marked = writeBackFlag(sourceJt, sourceTable, flagCol, cfg.getFlagCondition(), cfg.getFlagMatchValue(), writeValue, keyMaps, rows);
return String.format("增量采集:新增%d更新%d未变%d回写标记%d源%d条",
ins, upd, unchanged, marked, rows.size());
}
return String.format("%s新增%d更新%d未变%d源%d条",
"TIME".equals(mode) ? "时间匹配" : "全量匹配", ins, upd, unchanged, rows.size());
//update-end---author:GHT ---date:20260617 for【MES上辅机】增量匹配改为标记位回写-----------
}
//update-begin---author:GHT ---date:20260617 for【MES上辅机】增量匹配改为标记位回写-----------
/**
* INCR 标记采集条件根据配置构造源表标记列的判定谓词SELECT 取数 + 回写守卫共用)。
* <ul>
* <li>{@code IS_NULL} 为空:{@code [col] IS NULL}</li>
* <li>{@code EQ_EMPTY} 等于:{@code [col] = '<匹配值>'}(匹配值留空时退化为等于空串)</li>
* <li>{@code NE_EMPTY} 不等于:{@code [col] <> '<匹配值>'}(匹配值留空时退化为不等于空串)</li>
* </ul>
* @param matchValue EQ_EMPTY/NE_EMPTY 的比较值,由用户填写,留空表示空字符串
*/
private String flagPredicate(String flagCol, String condition, String matchValue) {
String c = StringUtils.isBlank(condition) ? "IS_NULL" : condition.trim().toUpperCase();
switch (c) {
case "EQ_EMPTY":
return "[" + flagCol + "] = '" + sqlLiteral(matchValue) + "'";
case "NE_EMPTY":
return "[" + flagCol + "] <> '" + sqlLiteral(matchValue) + "'";
case "IS_NULL":
default:
return "[" + flagCol + "] IS NULL";
}
}
/** 将用户填写的匹配值转义为 SQL 字符串字面量内容(单引号翻倍),防止注入。 */
private String sqlLiteral(String value) {
return value == null ? "" : value.replace("'", "''");
}
/**
* INCR 标记回写:把本批读到的源行该标记列回写为配置的回写值。
* <p>仅按匹配键精确定位本批读到的行(而非整列条件批量更新),
* 避免误标在本轮 SELECT 之后才进入中间库、尚未采集的新数据;
* 并以采集条件谓词做守卫,避开本轮已被其他进程改动的行。</p>
*/
private int writeBackFlag(JdbcTemplate sourceJt, String sourceTable, String flagCol, String condition,
String matchValue, String writeValue, List<MesXslMcsSyncField> keyMaps, List<Map<String, Object>> rows) {
validateIdent(flagCol);
StringBuilder sql = new StringBuilder("UPDATE [").append(sourceTable).append("] SET [")
.append(flagCol).append("] = ? WHERE ");
sql.append(keyMaps.stream().map(k -> "[" + k.getSourceField() + "] = ?").collect(Collectors.joining(" AND ")));
sql.append(" AND (").append(flagPredicate(flagCol, condition, matchValue)).append(")");
List<Object[]> argsList = new ArrayList<>();
Set<String> handled = new HashSet<>();
for (Map<String, Object> row : rows) {
Map<String, Object> rci = ci(row);
String key = buildKeyFromSource(keyMaps, rci);
if (!handled.add(key)) {
continue;
}
List<Object> args = new ArrayList<>(keyMaps.size() + 1);
args.add(writeValue);
for (MesXslMcsSyncField k : keyMaps) {
args.add(rci.get(k.getSourceField()));
}
argsList.add(args.toArray());
}
return batch(sourceJt, sql.toString(), argsList);
}
//update-end---author:GHT ---date:20260617 for【MES上辅机】增量匹配改为标记位回写-----------
// ---------------- 现有数据加载 ----------------
private Map<String, Map<String, Object>> loadExistingAll(JdbcTemplate jt, String table, LinkedHashSet<String> existCols,
List<MesXslMcsSyncField> keyMaps, boolean hasDel) {
String sql = "SELECT " + colListBt(existCols) + " FROM `" + table + "`" + (hasDel ? " WHERE `del_flag` = 0" : "");
Map<String, Map<String, Object>> map = new HashMap<>();
for (Map<String, Object> er : jt.queryForList(sql)) {
Map<String, Object> eci = ci(er);
map.put(buildKeyFromTarget(keyMaps, eci), eci);
}
return map;
}
private Map<String, Map<String, Object>> loadExistingByKeys(JdbcTemplate jt, String table, LinkedHashSet<String> existCols,
List<MesXslMcsSyncField> keyMaps, boolean hasDel,
List<Map<String, Object>> rows) {
Map<String, Map<String, Object>> map = new HashMap<>();
MesXslMcsSyncField firstKey = keyMaps.get(0);
// 收集窗口内首匹配键去重值
LinkedHashSet<Object> values = new LinkedHashSet<>();
for (Map<String, Object> row : rows) {
Object v = ci(row).get(firstKey.getSourceField());
if (v != null) {
values.add(v);
}
}
if (values.isEmpty()) {
return map;
}
List<Object> valueList = new ArrayList<>(values);
for (int i = 0; i < valueList.size(); i += IN_CHUNK) {
List<Object> part = valueList.subList(i, Math.min(i + IN_CHUNK, valueList.size()));
String ph = part.stream().map(x -> "?").collect(Collectors.joining(","));
String sql = "SELECT " + colListBt(existCols) + " FROM `" + table + "` WHERE `"
+ firstKey.getTargetField() + "` IN (" + ph + ")" + (hasDel ? " AND `del_flag` = 0" : "");
for (Map<String, Object> er : jt.queryForList(sql, part.toArray())) {
Map<String, Object> eci = ci(er);
map.put(buildKeyFromTarget(keyMaps, eci), eci);
}
}
return map;
}
// ---------------- 追加写入 ----------------
private int appendInsert(JdbcTemplate jt, String table, List<MesXslMcsSyncField> maps, AutoCols auto,
List<Map<String, Object>> rows) {
List<Object[]> insertArgs = new ArrayList<>();
for (Map<String, Object> row : rows) {
insertArgs.add(buildInsertArgs(maps, ci(row), auto));
}
return batch(jt, buildInsertSql(table, maps, auto), insertArgs);
}
// ---------------- SQL 构建 ----------------
private String buildInsertSql(String table, List<MesXslMcsSyncField> maps, AutoCols auto) {
List<String> cols = new ArrayList<>();
maps.forEach(m -> cols.add(m.getTargetField()));
if (auto.id) {
cols.add("id");
}
cols.addAll(auto.cols);
String colSql = cols.stream().map(c -> "`" + c + "`").collect(Collectors.joining(","));
String ph = cols.stream().map(c -> "?").collect(Collectors.joining(","));
return "INSERT INTO `" + table + "` (" + colSql + ") VALUES (" + ph + ")";
}
private Object[] buildInsertArgs(List<MesXslMcsSyncField> maps, Map<String, Object> ci, AutoCols auto) {
List<Object> args = new ArrayList<>(maps.size() + auto.vals.size() + 1);
for (MesXslMcsSyncField m : maps) {
args.add(ci.get(m.getSourceField()));
}
if (auto.id) {
args.add(IdWorker.getIdStr());
}
args.addAll(auto.vals);
return args.toArray();
}
private String buildUpdateSql(String table, List<String> setCols, List<MesXslMcsSyncField> keyMaps,
boolean updTime, boolean updBy, boolean hasDel) {
if (setCols.isEmpty()) {
return null;
}
StringBuilder sql = new StringBuilder("UPDATE `").append(table).append("` SET ");
sql.append(setCols.stream().map(c -> "`" + c + "` = ?").collect(Collectors.joining(",")));
if (updTime) {
sql.append(", `update_time` = ?");
}
if (updBy) {
sql.append(", `update_by` = ?");
}
sql.append(" WHERE ");
sql.append(keyMaps.stream().map(k -> "`" + k.getTargetField() + "` = ?").collect(Collectors.joining(" AND ")));
if (hasDel) {
sql.append(" AND `del_flag` = 0");
}
return sql.toString();
}
private Object[] buildUpdateArgs(List<MesXslMcsSyncField> nonKeyMaps, List<MesXslMcsSyncField> keyMaps,
Map<String, Object> ci, boolean updTime, boolean updBy, Timestamp now) {
List<Object> args = new ArrayList<>();
for (MesXslMcsSyncField m : nonKeyMaps) {
args.add(ci.get(m.getSourceField()));
}
if (updTime) {
args.add(now);
}
if (updBy) {
args.add("mcs-sync");
}
for (MesXslMcsSyncField k : keyMaps) {
args.add(ci.get(k.getSourceField()));
}
return args.toArray();
}
// ---------------- 工具 ----------------
/** 自动填充列汇总id 单独标记,因每行不同) */
private static class AutoCols {
boolean id;
final List<String> cols = new ArrayList<>();
final List<Object> vals = new ArrayList<>();
}
private AutoCols buildAutoCols(Set<String> targetCols, List<MesXslMcsSyncField> maps, int tenantId, Timestamp now) {
AutoCols a = new AutoCols();
a.id = targetCols.contains("id") && !mappedContains(maps, "id");
addAuto(a, targetCols, maps, "create_time", now);
addAuto(a, targetCols, maps, "update_time", now);
addAuto(a, targetCols, maps, "create_by", "mcs-sync");
addAuto(a, targetCols, maps, "update_by", "mcs-sync");
addAuto(a, targetCols, maps, "tenant_id", tenantId);
addAuto(a, targetCols, maps, "del_flag", 0);
return a;
}
private void addAuto(AutoCols a, Set<String> targetCols, List<MesXslMcsSyncField> maps, String col, Object val) {
if (targetCols.contains(col) && !mappedContains(maps, col)) {
a.cols.add(col);
a.vals.add(val);
}
}
/** 返回 [start, end]end 可为 null */
private Timestamp[] timeWindow(String window, Timestamp now) {
String w = StringUtils.isBlank(window) ? "TODAY" : window.trim().toUpperCase();
if ("LAST7".equals(w)) {
return new Timestamp[]{Timestamp.valueOf(LocalDateTime.now().minusDays(7)), null};
}
// 默认当天
Timestamp start = Timestamp.valueOf(LocalDate.now().atStartOfDay());
Timestamp end = Timestamp.valueOf(LocalDate.now().plusDays(1).atStartOfDay());
return new Timestamp[]{start, end};
}
private String requireIncrColumn(MesXslMcsSyncConfig cfg) {
String col = trim(cfg.getIncrColumn());
if (StringUtils.isBlank(col)) {
throw new IllegalArgumentException("当前采集模式需指定标记列/时间列,请在采集操作中配置");
}
validateIdent(col);
return col;
}
private int batch(JdbcTemplate jt, String sql, List<Object[]> argsList) {
if (sql == null || argsList.isEmpty()) {
return 0;
}
int total = 0;
for (int i = 0; i < argsList.size(); i += BATCH_SIZE) {
List<Object[]> part = argsList.subList(i, Math.min(i + BATCH_SIZE, argsList.size()));
jt.batchUpdate(sql, part);
total += part.size();
}
return total;
}
private boolean isChanged(List<MesXslMcsSyncField> nonKeyMaps, Map<String, Object> ci, Map<String, Object> existing) {
for (MesXslMcsSyncField m : nonKeyMaps) {
if (!normVal(ci.get(m.getSourceField())).equals(normVal(existing.get(m.getTargetField())))) {
return true;
}
}
return false;
}
private String buildKeyFromSource(List<MesXslMcsSyncField> keyMaps, Map<String, Object> ci) {
return keyMaps.stream().map(k -> normKey(ci.get(k.getSourceField()))).collect(Collectors.joining("||"));
}
private String buildKeyFromTarget(List<MesXslMcsSyncField> keyMaps, Map<String, Object> eci) {
return keyMaps.stream().map(k -> normKey(eci.get(k.getTargetField()))).collect(Collectors.joining("||"));
}
private Map<String, Object> ci(Map<String, Object> row) {
Map<String, Object> m = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
m.putAll(row);
return m;
}
private String colList(LinkedHashSet<String> cols) {
return cols.stream().map(c -> "[" + c + "]").collect(Collectors.joining(","));
}
private String colListBt(LinkedHashSet<String> cols) {
return cols.stream().map(c -> "`" + c + "`").collect(Collectors.joining(","));
}
private String normKey(Object v) {
return v == null ? "" : String.valueOf(v).trim();
}
private String normVal(Object v) {
return v == null ? " " : String.valueOf(v);
}
private boolean mappedContains(List<MesXslMcsSyncField> maps, String targetCol) {
return maps.stream().anyMatch(m -> m.getTargetField() != null && m.getTargetField().equalsIgnoreCase(targetCol));
}
private DataSource getSourceDataSource() {
DynamicRoutingDataSource routing = (DynamicRoutingDataSource) dataSource;
DataSource src = routing.getDataSources().get(McsDataSourceManager.DS_KEY);
if (src == null) {
throw new IllegalStateException("中间库数据源 " + McsDataSourceManager.DS_KEY + " 未注册");
}
return src;
}
private void validateIdent(String name) {
if (name == null || !IDENT.matcher(name).matches()) {
throw new IllegalArgumentException("非法的表名或字段名: " + name);
}
}
private String trim(String s) {
return s == null ? null : s.trim();
}
//update-end---author:GHT ---date:20260617 for【MES上辅机】采集模式 全量/时间/增量-----------
}

View File

@@ -0,0 +1,162 @@
package org.jeecg.modules.xslmes.mcs.sync;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.xslmes.mcs.datasource.McsDataSourceManager;
import org.jeecg.modules.xslmes.mcs.entity.MesXslMcsSyncConfig;
import org.jeecg.modules.xslmes.mcs.entity.MesXslMcsSyncField;
import org.jeecg.modules.xslmes.mcs.mapper.MesXslMcsSyncConfigMapper;
import org.jeecg.modules.xslmes.mcs.mapper.MesXslMcsSyncFieldMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.stereotype.Component;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import java.time.Duration;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
/**
* 中间表采集调度器(通用,配置驱动)。
* <p>基于 {@link ThreadPoolTaskScheduler} 为每个运行中的采集配置维护一个可重排的定时任务,
* 支持秒级间隔、运行时改间隔、启动/停止。每次触发调用 {@link GenericMcsSyncEngine} 执行采集。</p>
*
* @author GHT
* @date 2026-06-17 for【MES上辅机】采集配置-表与字段绑定
*/
@Slf4j
@Component
public class McsSyncScheduler {
private static final String LOG_TAG = "[MCS采集]";
@Autowired
private MesXslMcsSyncConfigMapper syncConfigMapper;
@Autowired
private MesXslMcsSyncFieldMapper syncFieldMapper;
@Autowired
private McsDataSourceManager mcsDataSourceManager;
@Autowired
private GenericMcsSyncEngine syncEngine;
/** 运行中的定时任务configId -> future */
private final Map<String, ScheduledFuture<?>> runningTasks = new ConcurrentHashMap<>();
private ThreadPoolTaskScheduler taskScheduler;
@PostConstruct
public void init() {
taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.setPoolSize(4);
taskScheduler.setThreadNamePrefix("mcs-sync-");
taskScheduler.setWaitForTasksToCompleteOnShutdown(true);
taskScheduler.setAwaitTerminationSeconds(10);
taskScheduler.initialize();
log.info("{} 采集调度器初始化完成", LOG_TAG);
}
@PreDestroy
public void destroy() {
runningTasks.values().forEach(f -> f.cancel(false));
runningTasks.clear();
if (taskScheduler != null) {
taskScheduler.shutdown();
}
}
/**
* 应用启动后,加载所有 status=1 的采集配置并启动定时任务
*/
@EventListener(ApplicationReadyEvent.class)
public void loadOnStartup() {
try {
List<MesXslMcsSyncConfig> configs = syncConfigMapper.selectList(
new LambdaQueryWrapper<MesXslMcsSyncConfig>()
.eq(MesXslMcsSyncConfig::getDelFlag, 0)
.eq(MesXslMcsSyncConfig::getStatus, "1"));
configs.forEach(this::scheduleTask);
log.info("{} 启动加载采集任务完成,已启动={}", LOG_TAG, configs.size());
} catch (Exception e) {
log.error("{} 启动加载采集任务失败: {}", LOG_TAG, e.getMessage(), e);
}
}
public boolean isRunning(String configId) {
ScheduledFuture<?> f = runningTasks.get(configId);
return f != null && !f.isCancelled();
}
/**
* (重新)按配置的间隔调度采集任务。已存在则先取消再重排,实现运行时改间隔。
*/
public synchronized void scheduleTask(MesXslMcsSyncConfig config) {
if (config == null || config.getId() == null) {
return;
}
cancelTask(config.getId());
long seconds = config.getIntervalSeconds() != null && config.getIntervalSeconds() > 0
? config.getIntervalSeconds() : 1L;
String configId = config.getId();
ScheduledFuture<?> future = taskScheduler.scheduleWithFixedDelay(
() -> runOnce(configId), Duration.ofSeconds(seconds));
runningTasks.put(configId, future);
log.info("{} 采集任务已启动 configId={} 间隔={}s", LOG_TAG, configId, seconds);
}
/**
* 取消采集任务(仅停内存定时,不改库)
*/
public synchronized void cancelTask(String configId) {
ScheduledFuture<?> old = runningTasks.remove(configId);
if (old != null) {
old.cancel(false);
log.info("{} 采集任务已停止 configId={}", LOG_TAG, configId);
}
}
/**
* 单次采集执行:连接/读取开关守卫 + 调用通用引擎 + 落库结果
*/
private void runOnce(String configId) {
MesXslMcsSyncConfig cfg = syncConfigMapper.selectById(configId);
if (cfg == null || cfg.getDelFlag() != null && cfg.getDelFlag() == 1 || !"1".equals(cfg.getStatus())) {
return;
}
// 中间库未启用或读取开关关闭时安静跳过
if (!mcsDataSourceManager.isDbConfigActive() || !mcsDataSourceManager.isReadEnabled()) {
log.debug("{} 中间库未就绪或读取关闭,跳过 configId={}", LOG_TAG, configId);
return;
}
try {
List<MesXslMcsSyncField> fields = syncFieldMapper.selectList(
new LambdaQueryWrapper<MesXslMcsSyncField>()
.eq(MesXslMcsSyncField::getConfigId, configId)
.eq(MesXslMcsSyncField::getDelFlag, 0)
.orderByAsc(MesXslMcsSyncField::getSortNo));
String result = syncEngine.sync(cfg, fields);
// INCR 改为标记位回写后不再维护高水位,仅落库采集结果
updateSyncResult(configId, result, null);
} catch (Exception e) {
log.error("{} 采集异常 configId={}: {}", LOG_TAG, configId, e.getMessage(), e);
updateSyncResult(configId, "采集失败:" + e.getMessage(), null);
}
}
private void updateSyncResult(String id, String result, String watermark) {
MesXslMcsSyncConfig update = new MesXslMcsSyncConfig();
update.setId(id);
update.setLastSyncTime(new Date());
update.setLastSyncResult(result != null && result.length() > 480 ? result.substring(0, 480) : result);
update.setLastWatermark(watermark);
syncConfigMapper.updateById(update);
}
}

View File

@@ -5,9 +5,9 @@ import org.jeecg.modules.xslmes.entity.MesXslMixerAction;
public interface IMesXslMixerActionService extends IService<MesXslMixerAction> {
boolean isActionNameDuplicated(String actionName, String excludeId);
boolean isActionNameDuplicated(String equipmentId, String actionName, String excludeId);
boolean isActionCodeDuplicated(String actionCode, String excludeId);
boolean isActionCodeDuplicated(String equipmentId, String actionCode, String excludeId);
void fillEquipmentName(MesXslMixerAction model);
}

View File

@@ -5,8 +5,10 @@ import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import org.jeecg.modules.xslmes.entity.MesXslRubberQuickTestRecord;
import org.jeecg.modules.xslmes.entity.MesXslRubberQuickTestRecordChartPoint;
import org.jeecg.modules.xslmes.entity.MesXslRubberQuickTestRecordLine;
import org.jeecg.modules.xslmes.entity.MesXslRubberQuickTestRecordRawLine;
import org.jeecg.modules.xslmes.entity.MesXslRubberQuickTestRecordStdLine;
import org.jeecg.modules.xslmes.vo.MesXslRubberQuickTestRecordBatchFromMaterialVO;
public interface IMesXslRubberQuickTestRecordService extends IService<MesXslRubberQuickTestRecord> {
@@ -23,7 +25,24 @@ public interface IMesXslRubberQuickTestRecordService extends IService<MesXslRubb
List<MesXslRubberQuickTestRecordRawLine> selectRawLinesByRecordId(String recordId);
//update-begin---author:jiangxh ---date:2026-06-22 for【快检记录】数据标准明细与曲线图查询-----------
List<MesXslRubberQuickTestRecordStdLine> selectStdLinesByRecordId(String recordId);
List<MesXslRubberQuickTestRecordChartPoint> selectChartPointsByRecordId(String recordId);
/** 桌面端保存前:按实验标准回填标准名、方法名、实验类型 */
void fillStdAndTypeForRecord(MesXslRubberQuickTestRecord record);
//update-end---author:jiangxh ---date:2026-06-22 for【快检记录】数据标准明细与曲线图查询-----------
String generateRecordNo(MesXslRubberQuickTestRecord context);
//update-begin---author:jiangxh ---date:20260618 for【快检记录】桌面端快检记录号生成-----------
/** 桌面端快检记录号yyyyMMdd + 4位流水 + 胶料名称,如 202606180001SA889 */
String generateDesktopRecordNo(MesXslRubberQuickTestRecord context);
/** 桌面端保存前:按实验标准关联实验方法回填检验类型 */
void fillQuickTestTypeForRecord(MesXslRubberQuickTestRecord record);
//update-end---author:jiangxh ---date:20260618 for【快检记录】桌面端快检记录号生成-----------
List<String> batchFromMaterial(MesXslRubberQuickTestRecordBatchFromMaterialVO vo);
}

View File

@@ -99,6 +99,14 @@ public class MesXslStompNotifyService {
}
//update-end---author:jiangxh ---date:20260617 for【快检实验标准】桌面端只读同步 STOMP-----------
//update-begin---author:jiangxh ---date:20260617 for【密炼计划】桌面端只读同步 STOMP-----------
/** 广播密炼生产计划变更事件到 /topic/sync/mes-mixing-production-plans */
public void publishMixingProductionPlanChanged(String action, String mixingProductionPlanId) {
publish("/topic/sync/mes-mixing-production-plans", "MIXING_PRODUCTION_PLAN_CHANGED",
"mixingProductionPlanId", mixingProductionPlanId, action);
}
//update-end---author:jiangxh ---date:20260617 for【密炼计划】桌面端只读同步 STOMP-----------
// ─────────────────────────── 私有辅助 ────────────────────────────
private void publish(String topic, String cmd, String idKey, String idValue, String action) {

View File

@@ -17,13 +17,16 @@ public class MesXslMixerActionServiceImpl extends ServiceImpl<MesXslMixerActionM
@Autowired private MesXslEquipmentLedgerMapper equipmentLedgerMapper;
//update-begin---author:GHT ---date:20260617 for【MES上辅机】密炼动作秒级采集-唯一性改为(设备+动作代号)同设备内唯一-----------
@Override
public boolean isActionNameDuplicated(String actionName, String excludeId) {
if (StringUtils.isBlank(actionName)) {
public boolean isActionNameDuplicated(String equipmentId, String actionName, String excludeId) {
if (StringUtils.isBlank(actionName) || StringUtils.isBlank(equipmentId)) {
return false;
}
LambdaQueryWrapper<MesXslMixerAction> wrapper =
new LambdaQueryWrapper<MesXslMixerAction>().eq(MesXslMixerAction::getActionName, actionName.trim());
new LambdaQueryWrapper<MesXslMixerAction>()
.eq(MesXslMixerAction::getEquipmentId, equipmentId.trim())
.eq(MesXslMixerAction::getActionName, actionName.trim());
if (StringUtils.isNotBlank(excludeId)) {
wrapper.ne(MesXslMixerAction::getId, excludeId.trim());
}
@@ -31,17 +34,20 @@ public class MesXslMixerActionServiceImpl extends ServiceImpl<MesXslMixerActionM
}
@Override
public boolean isActionCodeDuplicated(String actionCode, String excludeId) {
if (StringUtils.isBlank(actionCode)) {
public boolean isActionCodeDuplicated(String equipmentId, String actionCode, String excludeId) {
if (StringUtils.isBlank(actionCode) || StringUtils.isBlank(equipmentId)) {
return false;
}
LambdaQueryWrapper<MesXslMixerAction> wrapper =
new LambdaQueryWrapper<MesXslMixerAction>().eq(MesXslMixerAction::getActionCode, actionCode.trim());
new LambdaQueryWrapper<MesXslMixerAction>()
.eq(MesXslMixerAction::getEquipmentId, equipmentId.trim())
.eq(MesXslMixerAction::getActionCode, actionCode.trim());
if (StringUtils.isNotBlank(excludeId)) {
wrapper.ne(MesXslMixerAction::getId, excludeId.trim());
}
return this.count(wrapper) > 0;
}
//update-end---author:GHT ---date:20260617 for【MES上辅机】密炼动作秒级采集-唯一性改为(设备+动作代号)同设备内唯一-----------
@Override
public void fillEquipmentName(MesXslMixerAction model) {

View File

@@ -19,14 +19,18 @@ import org.jeecg.modules.mes.material.service.IMesMaterialService;
import org.jeecg.modules.xslmes.common.XslMesBizConstants;
import org.jeecg.modules.xslmes.entity.MesXslRubberQuickTestMethod;
import org.jeecg.modules.xslmes.entity.MesXslRubberQuickTestRecord;
import org.jeecg.modules.xslmes.entity.MesXslRubberQuickTestRecordChartPoint;
import org.jeecg.modules.xslmes.entity.MesXslRubberQuickTestRecordLine;
import org.jeecg.modules.xslmes.entity.MesXslRubberQuickTestRecordRawLine;
import org.jeecg.modules.xslmes.entity.MesXslRubberQuickTestRecordStdLine;
import org.jeecg.modules.xslmes.entity.MesXslRubberQuickTestStd;
import org.jeecg.modules.xslmes.entity.MesXslRubberQuickTestStdLine;
import org.jeecg.modules.xslmes.entity.MesXslRubberQuickTestType;
import org.jeecg.modules.xslmes.mapper.MesXslRubberQuickTestRecordChartPointMapper;
import org.jeecg.modules.xslmes.mapper.MesXslRubberQuickTestRecordLineMapper;
import org.jeecg.modules.xslmes.mapper.MesXslRubberQuickTestRecordMapper;
import org.jeecg.modules.xslmes.mapper.MesXslRubberQuickTestRecordRawLineMapper;
import org.jeecg.modules.xslmes.mapper.MesXslRubberQuickTestRecordStdLineMapper;
import org.jeecg.modules.xslmes.service.IMesXslRubberQuickTestMethodService;
import org.jeecg.modules.xslmes.service.IMesXslRubberQuickTestRecordService;
import org.jeecg.modules.xslmes.service.IMesXslRubberQuickTestStdService;
@@ -50,6 +54,12 @@ public class MesXslRubberQuickTestRecordServiceImpl
@Autowired
private MesXslRubberQuickTestRecordRawLineMapper mesXslRubberQuickTestRecordRawLineMapper;
@Autowired
private MesXslRubberQuickTestRecordStdLineMapper mesXslRubberQuickTestRecordStdLineMapper;
@Autowired
private MesXslRubberQuickTestRecordChartPointMapper mesXslRubberQuickTestRecordChartPointMapper;
@Autowired
private IMesXslRubberQuickTestStdService mesXslRubberQuickTestStdService;
@@ -73,6 +83,10 @@ public class MesXslRubberQuickTestRecordServiceImpl
//update-begin---author:jiangxh ---date:2026-06-17 for【快检记录】保存试验结果原始数据明细-----------
insertRawLines(main.getId(), main.getRawLineList());
//update-end---author:jiangxh ---date:2026-06-17 for【快检记录】保存试验结果原始数据明细-----------
//update-begin---author:jiangxh ---date:2026-06-22 for【快检记录】保存数据标准明细与曲线图-----------
insertStdLines(main.getId(), main.getStdLineList());
insertChartPoints(main.getId(), main.getChartPointList());
//update-end---author:jiangxh ---date:2026-06-22 for【快检记录】保存数据标准明细与曲线图-----------
}
@Override
@@ -95,6 +109,16 @@ public class MesXslRubberQuickTestRecordServiceImpl
.eq(MesXslRubberQuickTestRecordRawLine::getRecordId, main.getId()));
insertRawLines(main.getId(), main.getRawLineList());
//update-end---author:jiangxh ---date:2026-06-17 for【快检记录】更新时同步原始数据明细-----------
//update-begin---author:jiangxh ---date:2026-06-22 for【快检记录】更新时同步数据标准与曲线图-----------
mesXslRubberQuickTestRecordStdLineMapper.delete(
new LambdaQueryWrapper<MesXslRubberQuickTestRecordStdLine>()
.eq(MesXslRubberQuickTestRecordStdLine::getRecordId, main.getId()));
insertStdLines(main.getId(), main.getStdLineList());
mesXslRubberQuickTestRecordChartPointMapper.delete(
new LambdaQueryWrapper<MesXslRubberQuickTestRecordChartPoint>()
.eq(MesXslRubberQuickTestRecordChartPoint::getRecordId, main.getId()));
insertChartPoints(main.getId(), main.getChartPointList());
//update-end---author:jiangxh ---date:2026-06-22 for【快检记录】更新时同步数据标准与曲线图-----------
}
private void insertLines(String recordId, List<MesXslRubberQuickTestRecordLine> lineList) {
@@ -128,6 +152,40 @@ public class MesXslRubberQuickTestRecordServiceImpl
}
//update-end---author:jiangxh ---date:2026-06-17 for【快检记录】原始数据明细入库-----------
//update-begin---author:jiangxh ---date:2026-06-22 for【快检记录】数据标准明细与曲线图入库-----------
private void insertStdLines(String recordId, List<MesXslRubberQuickTestRecordStdLine> stdLineList) {
if (CollectionUtils.isEmpty(stdLineList)) {
return;
}
int sort = 0;
for (MesXslRubberQuickTestRecordStdLine line : stdLineList) {
if (line == null) {
continue;
}
line.setId(null);
line.setRecordId(recordId);
line.setSortNo(sort++);
mesXslRubberQuickTestRecordStdLineMapper.insert(line);
}
}
private void insertChartPoints(String recordId, List<MesXslRubberQuickTestRecordChartPoint> chartPointList) {
if (CollectionUtils.isEmpty(chartPointList)) {
return;
}
int sort = 0;
for (MesXslRubberQuickTestRecordChartPoint point : chartPointList) {
if (point == null) {
continue;
}
point.setId(null);
point.setRecordId(recordId);
point.setSortNo(sort++);
mesXslRubberQuickTestRecordChartPointMapper.insert(point);
}
}
//update-end---author:jiangxh ---date:2026-06-22 for【快检记录】数据标准明细与曲线图入库-----------
@Override
@Transactional(rollbackFor = Exception.class)
public void delMain(String id) {
@@ -135,6 +193,10 @@ public class MesXslRubberQuickTestRecordServiceImpl
new LambdaQueryWrapper<MesXslRubberQuickTestRecordLine>().eq(MesXslRubberQuickTestRecordLine::getRecordId, id));
mesXslRubberQuickTestRecordRawLineMapper.delete(
new LambdaQueryWrapper<MesXslRubberQuickTestRecordRawLine>().eq(MesXslRubberQuickTestRecordRawLine::getRecordId, id));
mesXslRubberQuickTestRecordStdLineMapper.delete(
new LambdaQueryWrapper<MesXslRubberQuickTestRecordStdLine>().eq(MesXslRubberQuickTestRecordStdLine::getRecordId, id));
mesXslRubberQuickTestRecordChartPointMapper.delete(
new LambdaQueryWrapper<MesXslRubberQuickTestRecordChartPoint>().eq(MesXslRubberQuickTestRecordChartPoint::getRecordId, id));
this.removeById(id);
}
@@ -162,6 +224,22 @@ public class MesXslRubberQuickTestRecordServiceImpl
.orderByAsc(MesXslRubberQuickTestRecordRawLine::getSortNo));
}
@Override
public List<MesXslRubberQuickTestRecordStdLine> selectStdLinesByRecordId(String recordId) {
return mesXslRubberQuickTestRecordStdLineMapper.selectList(
new LambdaQueryWrapper<MesXslRubberQuickTestRecordStdLine>()
.eq(MesXslRubberQuickTestRecordStdLine::getRecordId, recordId)
.orderByAsc(MesXslRubberQuickTestRecordStdLine::getSortNo));
}
@Override
public List<MesXslRubberQuickTestRecordChartPoint> selectChartPointsByRecordId(String recordId) {
return mesXslRubberQuickTestRecordChartPointMapper.selectList(
new LambdaQueryWrapper<MesXslRubberQuickTestRecordChartPoint>()
.eq(MesXslRubberQuickTestRecordChartPoint::getRecordId, recordId)
.orderByAsc(MesXslRubberQuickTestRecordChartPoint::getSortNo));
}
//update-begin---author:jiangxh ---date:20260528 for【MES】胶料快检记录单号JL+日期+4位流水自动生成-----------
@Override
public String generateRecordNo(MesXslRubberQuickTestRecord context) {
@@ -216,49 +294,92 @@ public class MesXslRubberQuickTestRecordServiceImpl
}
//update-end---author:jiangxh ---date:20260528 for【MES】胶料快检记录单号JL+日期+4位流水自动生成-----------
//update-begin---author:jiangxh ---date:20260618 for【快检记录】桌面端快检记录号 yyyyMMdd+流水+胶料号-----------
@Override
public String generateDesktopRecordNo(MesXslRubberQuickTestRecord context) {
String dateStr = new SimpleDateFormat("yyyyMMdd").format(new Date());
if (context == null || oConvertUtils.isEmpty(context.getRubberMaterialName())) {
throw new JeecgBootException("胶料名称不能为空,无法生成快检记录号");
}
String material = context.getRubberMaterialName().trim();
int expectedLen = dateStr.length() + 4 + material.length();
Integer tenantId = resolveTenantId(context);
LambdaQueryWrapper<MesXslRubberQuickTestRecord> qw = new LambdaQueryWrapper<>();
qw.likeRight(MesXslRubberQuickTestRecord::getRecordNo, dateStr);
qw.and(q -> q.eq(MesXslRubberQuickTestRecord::getDelFlag, CommonConstant.DEL_FLAG_0).or().isNull(MesXslRubberQuickTestRecord::getDelFlag));
if (tenantId != null) {
qw.eq(MesXslRubberQuickTestRecord::getTenantId, tenantId);
}
qw.select(MesXslRubberQuickTestRecord::getRecordNo);
int maxSeq = 0;
for (MesXslRubberQuickTestRecord row : this.list(qw)) {
String no = row.getRecordNo();
if (oConvertUtils.isEmpty(no) || no.length() != expectedLen) {
continue;
}
if (!no.startsWith(dateStr) || !no.endsWith(material)) {
continue;
}
String seqPart = no.substring(dateStr.length(), dateStr.length() + 4);
try {
maxSeq = Math.max(maxSeq, Integer.parseInt(seqPart));
} catch (NumberFormatException ignored) {
// ignore malformed historical numbers
}
}
return dateStr + String.format("%04d", maxSeq + 1) + material;
}
@Override
public void fillQuickTestTypeForRecord(MesXslRubberQuickTestRecord record) {
fillStdAndTypeForRecord(record);
}
//update-begin---author:jiangxh ---date:2026-06-22 for【快检记录】回填实验标准/方法/类型-----------
@Override
public void fillStdAndTypeForRecord(MesXslRubberQuickTestRecord record) {
if (record == null) {
return;
}
String testMethodId = record.getTestMethodId();
if (oConvertUtils.isNotEmpty(record.getStdId())) {
MesXslRubberQuickTestStd std = mesXslRubberQuickTestStdService.getById(record.getStdId());
if (std != null) {
if (oConvertUtils.isEmpty(record.getStdName())) {
record.setStdName(std.getStdName());
}
if (oConvertUtils.isEmpty(testMethodId)) {
testMethodId = std.getTestMethodId();
record.setTestMethodId(testMethodId);
}
}
}
if (oConvertUtils.isNotEmpty(testMethodId) && oConvertUtils.isEmpty(record.getTestMethodName())) {
MesXslRubberQuickTestMethod method = mesXslRubberQuickTestMethodService.getById(testMethodId);
if (method != null) {
record.setTestMethodName(method.getMethodName());
if (oConvertUtils.isEmpty(record.getQuickTestTypeId())
&& oConvertUtils.isNotEmpty(method.getQuickTestTypeId())) {
fillQuickTestType(record, method.getQuickTestTypeId());
}
}
}
if (oConvertUtils.isNotEmpty(record.getQuickTestTypeId()) && oConvertUtils.isEmpty(record.getQuickTestTypeName())) {
fillQuickTestType(record, record.getQuickTestTypeId());
}
}
//update-end---author:jiangxh ---date:2026-06-22 for【快检记录】回填实验标准/方法/类型-----------
//update-end---author:jiangxh ---date:20260618 for【快检记录】桌面端快检记录号 yyyyMMdd+流水+胶料号-----------
//update-begin---author:jiangxh ---date:20260525 for【MES】胶料信息多选按实验标准批量生成快检记录-----------
@Override
@Transactional(rollbackFor = Exception.class)
public List<String> batchFromMaterial(MesXslRubberQuickTestRecordBatchFromMaterialVO vo) {
if (vo == null || CollectionUtils.isEmpty(vo.getMaterialIds())) {
throw new JeecgBootException("请至少选择一条胶料信息");
}
List<String> createdIds = new ArrayList<>();
for (String materialId : vo.getMaterialIds()) {
if (oConvertUtils.isEmpty(materialId)) {
continue;
}
String mid = materialId.trim();
MesMaterial material = mesMaterialService.getById(mid);
if (material == null) {
throw new JeecgBootException("胶料不存在:" + mid);
}
MesXslRubberQuickTestStd std = findApprovedStdForMaterial(mid);
if (std == null) {
throw new JeecgBootException(
"胶料【" + material.getMaterialName() + "】未找到已启用且已批准的实验标准,请先在胶料快检实验标准中维护");
}
List<MesXslRubberQuickTestStdLine> stdLines = mesXslRubberQuickTestStdService.selectLinesByStdId(std.getId());
if (CollectionUtils.isEmpty(stdLines)) {
throw new JeecgBootException("胶料【" + material.getMaterialName() + "】关联的实验标准无明细数据");
}
MesXslRubberQuickTestRecord main = buildMainFromMaterial(material, std, vo);
List<MesXslRubberQuickTestRecordLine> recordLines = new ArrayList<>();
for (MesXslRubberQuickTestStdLine stdLine : stdLines) {
MesXslRubberQuickTestRecordLine rl = new MesXslRubberQuickTestRecordLine();
rl.setDataPointId(stdLine.getDataPointId());
rl.setInspectItem(stdLine.getPointName());
rl.setLowerLimit(stdLine.getLowerLimit());
rl.setUpperLimit(stdLine.getUpperLimit());
recordLines.add(rl);
}
saveMain(main, recordLines);
createdIds.add(main.getId());
}
if (createdIds.isEmpty()) {
throw new JeecgBootException("未生成任何快检记录");
}
return createdIds;
//update-begin---author:jiangxh ---date:2026-06-22 for【快检记录】取消胶料列表批量生成改由桌面端同步-----------
throw new JeecgBootException("胶料快检记录已改为由桌面端同步创建,请使用桌面端「胶料快检记录」功能");
//update-end---author:jiangxh ---date:2026-06-22 for【快检记录】取消胶料列表批量生成改由桌面端同步-----------
}
private MesXslRubberQuickTestStd findApprovedStdForMaterial(String materialId) {

View File

@@ -0,0 +1,73 @@
-- MES上辅机密炼动作秒级采集
-- 1. 通用中间表采集配置表可被密炼动作/报警/配方等多功能复用 biz_type 区分
-- 2. 密炼机动作维护表补全机台字段放开台账关联调整唯一键为(设备+动作代号)
-- 3. 密炼动作菜单下新增 启动采集/停止采集/采集设置 按钮权限
-- ===================== 1. 通用采集配置表 =====================
CREATE TABLE IF NOT EXISTS `mes_xsl_mcs_sync_config` (
`id` varchar(32) NOT NULL COMMENT '主键',
`biz_type` varchar(50) NOT NULL COMMENT '业务类型(采集任务唯一标识 MIX_ACT 密炼动作)',
`biz_name` varchar(100) DEFAULT NULL COMMENT '业务名称',
`source_table` varchar(100) DEFAULT NULL COMMENT '源中间表名',
`interval_seconds` int NOT NULL DEFAULT '1' COMMENT '采集时间间隔()默认1秒',
`status` varchar(1) NOT NULL DEFAULT '0' COMMENT '采集状态(0停止,1运行)',
`last_sync_time` datetime DEFAULT NULL COMMENT '最近一次采集时间',
`last_sync_result` varchar(500) DEFAULT NULL COMMENT '最近一次采集结果',
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
`tenant_id` int DEFAULT '0' COMMENT '租户',
`create_by` varchar(100) DEFAULT NULL COMMENT '创建人',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`update_by` varchar(100) DEFAULT NULL COMMENT '更新人',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
`del_flag` int DEFAULT '0' COMMENT '删除标记(0正常,1删除)',
PRIMARY KEY (`id`),
KEY `idx_mscfg_biz` (`biz_type`, `tenant_id`, `del_flag`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='MES上辅机中间表采集配置(通用)';
-- 初始化密炼动作采集配置默认间隔1秒默认停止
INSERT INTO `mes_xsl_mcs_sync_config`
(`id`, `biz_type`, `biz_name`, `source_table`, `interval_seconds`, `status`, `remark`, `tenant_id`, `create_by`, `create_time`, `update_by`, `update_time`, `del_flag`)
SELECT '1900000000000000860', 'MIX_ACT', '密炼机动作', 'MCSToMES_MixAct', 1, '0', '密炼机动作维护数据采集', 0, 'admin', NOW(), 'admin', NOW(), 0
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `mes_xsl_mcs_sync_config` WHERE `biz_type` = 'MIX_ACT' AND `tenant_id` = 0);
-- ===================== 2. 密炼机动作维护表补全字段 =====================
-- 机台编号机台类型采集自中间表 EquipID/EquipType
ALTER TABLE `mes_xsl_mixer_action`
ADD COLUMN `equip_id` varchar(50) DEFAULT NULL COMMENT '机台编号(采集自中间表 EquipID)' AFTER `equipment_name`,
ADD COLUMN `equip_type` varchar(50) DEFAULT NULL COMMENT '机台类型(采集自中间表 EquipType)' AFTER `equip_id`;
-- 采集未匹配到台账时 equipment_id 允许为空
ALTER TABLE `mes_xsl_mixer_action`
MODIFY COLUMN `equipment_id` varchar(32) DEFAULT NULL COMMENT '设备台账ID(mes_xsl_equipment_ledger.id)采集未匹配时为空';
-- 唯一性改为(设备+动作代号)按机台编号+动作代号建索引便于采集 upsert
ALTER TABLE `mes_xsl_mixer_action`
ADD KEY `idx_mxma_equip_code` (`tenant_id`, `equip_id`, `action_code`, `del_flag`);
-- ===================== 3. 密炼动作菜单按钮权限 =====================
-- 父菜单密炼动作 1900000000000000835
INSERT INTO `sys_permission` (`id`, `parent_id`, `name`, `url`, `component`, `is_route`, `component_name`, `redirect`, `menu_type`, `perms`, `perms_type`, `sort_no`, `always_show`, `icon`, `is_leaf`, `keep_alive`, `hidden`, `hide_tab`, `description`, `create_by`, `create_time`, `update_by`, `update_time`, `del_flag`, `rule_flag`, `status`, `internal_or_external`)
SELECT '1900000000000000861', '1900000000000000835', '启动采集', NULL, NULL, 0, NULL, NULL, 2, 'xslmes:mcsSyncConfig:start', '1', 1.00, 0, NULL, 1, 0, 0, 0, NULL, 'admin', NOW(), 'admin', NOW(), 0, 0, '1', 0
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = '1900000000000000861');
INSERT INTO `sys_permission` (`id`, `parent_id`, `name`, `url`, `component`, `is_route`, `component_name`, `redirect`, `menu_type`, `perms`, `perms_type`, `sort_no`, `always_show`, `icon`, `is_leaf`, `keep_alive`, `hidden`, `hide_tab`, `description`, `create_by`, `create_time`, `update_by`, `update_time`, `del_flag`, `rule_flag`, `status`, `internal_or_external`)
SELECT '1900000000000000862', '1900000000000000835', '停止采集', NULL, NULL, 0, NULL, NULL, 2, 'xslmes:mcsSyncConfig:stop', '1', 2.00, 0, NULL, 1, 0, 0, 0, NULL, 'admin', NOW(), 'admin', NOW(), 0, 0, '1', 0
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = '1900000000000000862');
INSERT INTO `sys_permission` (`id`, `parent_id`, `name`, `url`, `component`, `is_route`, `component_name`, `redirect`, `menu_type`, `perms`, `perms_type`, `sort_no`, `always_show`, `icon`, `is_leaf`, `keep_alive`, `hidden`, `hide_tab`, `description`, `create_by`, `create_time`, `update_by`, `update_time`, `del_flag`, `rule_flag`, `status`, `internal_or_external`)
SELECT '1900000000000000863', '1900000000000000835', '采集设置', NULL, NULL, 0, NULL, NULL, 2, 'xslmes:mcsSyncConfig:setting', '1', 3.00, 0, NULL, 1, 0, 0, 0, NULL, 'admin', NOW(), 'admin', NOW(), 0, 0, '1', 0
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = '1900000000000000863');
-- admin 角色授权
INSERT INTO `sys_role_permission` (`id`, `role_id`, `permission_id`, `data_rule_ids`, `operate_date`, `operate_ip`)
SELECT REPLACE(UUID(), '-', ''), r.id, p.id, NULL, NOW(), '127.0.0.1'
FROM `sys_role` r
JOIN (
SELECT id FROM `sys_permission`
WHERE id IN ('1900000000000000861','1900000000000000862','1900000000000000863')
) p ON 1 = 1
WHERE r.`role_code` = 'admin'
AND NOT EXISTS (
SELECT 1 FROM `sys_role_permission` rp
WHERE rp.`role_id` = r.id AND rp.`permission_id` = p.id
);

View File

@@ -0,0 +1,85 @@
-- MES上辅机采集配置通用表+字段映射中间库表 MES表配置驱动
-- 1. 扩展采集配置头目标表配置名称表注释
-- 2. 新建字段映射表 mes_xsl_mcs_sync_field
-- 3. 将密炼动作(MIX_ACT)改造为配置驱动补目标表+预置字段映射
-- 4. 新增"采集配置"菜单及按钮权限
-- ===================== 1. 采集配置头扩展 =====================
ALTER TABLE `mes_xsl_mcs_sync_config`
ADD COLUMN `config_name` varchar(100) DEFAULT NULL COMMENT '配置名称' AFTER `biz_type`,
ADD COLUMN `source_table_comment` varchar(200) DEFAULT NULL COMMENT '源中间表注释' AFTER `source_table`,
ADD COLUMN `target_table` varchar(100) DEFAULT NULL COMMENT 'MES目标表名' AFTER `source_table_comment`,
ADD COLUMN `target_table_comment` varchar(200) DEFAULT NULL COMMENT 'MES目标表注释' AFTER `target_table`;
-- 密炼动作改造为配置驱动
UPDATE `mes_xsl_mcs_sync_config`
SET `config_name` = '密炼机动作采集',
`source_table_comment` = '密炼机实时动作',
`target_table` = 'mes_xsl_mixer_action',
`target_table_comment` = 'MES密炼机动作维护'
WHERE `biz_type` = 'MIX_ACT';
-- ===================== 2. 字段映射表 =====================
CREATE TABLE IF NOT EXISTS `mes_xsl_mcs_sync_field` (
`id` varchar(32) NOT NULL COMMENT '主键',
`config_id` varchar(32) NOT NULL COMMENT '采集配置ID(mes_xsl_mcs_sync_config.id)',
`source_field` varchar(100) NOT NULL COMMENT '中间库源字段名',
`source_field_comment` varchar(200) DEFAULT NULL COMMENT '源字段注释',
`source_field_type` varchar(50) DEFAULT NULL COMMENT '源字段类型',
`target_field` varchar(100) DEFAULT NULL COMMENT 'MES目标字段名(接收字段)',
`target_field_comment` varchar(200) DEFAULT NULL COMMENT 'MES目标字段注释',
`match_key` varchar(1) DEFAULT '0' COMMENT '是否匹配键(0否,1是)作为Upsert唯一键',
`sort_no` int DEFAULT '0' COMMENT '排序',
`tenant_id` int DEFAULT '0' COMMENT '租户',
`create_by` varchar(100) DEFAULT NULL COMMENT '创建人',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`update_by` varchar(100) DEFAULT NULL COMMENT '更新人',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
`del_flag` int DEFAULT '0' COMMENT '删除标记(0正常,1删除)',
PRIMARY KEY (`id`),
KEY `idx_msf_config` (`config_id`, `del_flag`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='MES上辅机采集字段映射';
-- 预置密炼动作字段映射EquipNameequipment_name 匹配键=机台编号+动作代号
INSERT INTO `mes_xsl_mcs_sync_field`
(`id`, `config_id`, `source_field`, `source_field_comment`, `source_field_type`, `target_field`, `target_field_comment`, `match_key`, `sort_no`, `tenant_id`, `create_by`, `create_time`, `update_by`, `update_time`, `del_flag`)
SELECT * FROM (
SELECT '1900000000000000870' id, '1900000000000000860' config_id, 'EquipName' sf, '机台名称' sfc, 'nvarchar' sft, 'equipment_name' tf, '设备名称' tfc, '0' mk, 1 sn, 0 tid, 'admin' cb, NOW() ct, 'admin' ub, NOW() ut, 0 df
UNION ALL SELECT '1900000000000000871', '1900000000000000860', 'EquipID', '机台编号', 'varchar', 'equip_id', '机台编号', '1', 2, 0, 'admin', NOW(), 'admin', NOW(), 0
UNION ALL SELECT '1900000000000000872', '1900000000000000860', 'EquipType', '机台类型', 'nvarchar', 'equip_type', '机台类型', '0', 3, 0, 'admin', NOW(), 'admin', NOW(), 0
UNION ALL SELECT '1900000000000000873', '1900000000000000860', 'MixActName', '动作名称', 'nvarchar', 'action_name', '动作名称', '0', 4, 0, 'admin', NOW(), 'admin', NOW(), 0
UNION ALL SELECT '1900000000000000874', '1900000000000000860', 'MixActAddress', '动作地址', 'int', 'action_code', '动作代号', '1', 5, 0, 'admin', NOW(), 'admin', NOW(), 0
) t
WHERE NOT EXISTS (SELECT 1 FROM `mes_xsl_mcs_sync_field` WHERE `config_id` = '1900000000000000860');
-- ===================== 3. 采集配置菜单 + 按钮权限 =====================
-- 父菜单MES上辅机数据 1900000000000000830
INSERT INTO `sys_permission` (`id`, `parent_id`, `name`, `url`, `component`, `is_route`, `component_name`, `redirect`, `menu_type`, `perms`, `perms_type`, `sort_no`, `always_show`, `icon`, `is_leaf`, `keep_alive`, `hidden`, `hide_tab`, `description`, `create_by`, `create_time`, `update_by`, `update_time`, `del_flag`, `rule_flag`, `status`, `internal_or_external`)
SELECT '1900000000000000865', '1900000000000000830', '采集配置', '/xslmesMcs/mcsSyncConfig', 'xslmesMcs/mcsSyncConfig/index', 1, NULL, NULL, 0, NULL, '0', 0.50, 0, 'ant-design:sync-outlined', 1, 1, 0, 0, '中间表MES表 采集配置与字段映射', 'admin', NOW(), 'admin', NOW(), 0, 0, '1', 0
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = '1900000000000000865');
INSERT INTO `sys_permission` (`id`, `parent_id`, `name`, `url`, `component`, `is_route`, `component_name`, `redirect`, `menu_type`, `perms`, `perms_type`, `sort_no`, `always_show`, `icon`, `is_leaf`, `keep_alive`, `hidden`, `hide_tab`, `description`, `create_by`, `create_time`, `update_by`, `update_time`, `del_flag`, `rule_flag`, `status`, `internal_or_external`)
SELECT '1900000000000000866', '1900000000000000865', '新增', NULL, NULL, 0, NULL, NULL, 2, 'xslmes:mcsSyncConfig:add', '1', 1.00, 0, NULL, 1, 0, 0, 0, NULL, 'admin', NOW(), 'admin', NOW(), 0, 0, '1', 0
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = '1900000000000000866');
INSERT INTO `sys_permission` (`id`, `parent_id`, `name`, `url`, `component`, `is_route`, `component_name`, `redirect`, `menu_type`, `perms`, `perms_type`, `sort_no`, `always_show`, `icon`, `is_leaf`, `keep_alive`, `hidden`, `hide_tab`, `description`, `create_by`, `create_time`, `update_by`, `update_time`, `del_flag`, `rule_flag`, `status`, `internal_or_external`)
SELECT '1900000000000000867', '1900000000000000865', '编辑', NULL, NULL, 0, NULL, NULL, 2, 'xslmes:mcsSyncConfig:edit', '1', 2.00, 0, NULL, 1, 0, 0, 0, NULL, 'admin', NOW(), 'admin', NOW(), 0, 0, '1', 0
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = '1900000000000000867');
INSERT INTO `sys_permission` (`id`, `parent_id`, `name`, `url`, `component`, `is_route`, `component_name`, `redirect`, `menu_type`, `perms`, `perms_type`, `sort_no`, `always_show`, `icon`, `is_leaf`, `keep_alive`, `hidden`, `hide_tab`, `description`, `create_by`, `create_time`, `update_by`, `update_time`, `del_flag`, `rule_flag`, `status`, `internal_or_external`)
SELECT '1900000000000000868', '1900000000000000865', '删除', NULL, NULL, 0, NULL, NULL, 2, 'xslmes:mcsSyncConfig:delete', '1', 3.00, 0, NULL, 1, 0, 0, 0, NULL, 'admin', NOW(), 'admin', NOW(), 0, 0, '1', 0
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = '1900000000000000868');
-- admin 授权
INSERT INTO `sys_role_permission` (`id`, `role_id`, `permission_id`, `data_rule_ids`, `operate_date`, `operate_ip`)
SELECT REPLACE(UUID(), '-', ''), r.id, p.id, NULL, NOW(), '127.0.0.1'
FROM `sys_role` r
JOIN (
SELECT id FROM `sys_permission`
WHERE id IN ('1900000000000000865','1900000000000000866','1900000000000000867','1900000000000000868')
) p ON 1 = 1
WHERE r.`role_code` = 'admin'
AND NOT EXISTS (
SELECT 1 FROM `sys_role_permission` rp
WHERE rp.`role_id` = r.id AND rp.`permission_id` = p.id
);

View File

@@ -0,0 +1,10 @@
-- MES上辅机采集模式全量匹配/时间匹配/增量匹配应对中间库大表
ALTER TABLE `mes_xsl_mcs_sync_config`
ADD COLUMN `sync_mode` varchar(20) NOT NULL DEFAULT 'FULL' COMMENT '采集模式(FULL全量匹配,TIME时间匹配,INCR增量匹配)' AFTER `status`,
ADD COLUMN `incr_column` varchar(100) DEFAULT NULL COMMENT '增量/时间列(源表列名TIME/INCR模式用)' AFTER `sync_mode`,
ADD COLUMN `time_window` varchar(20) DEFAULT 'TODAY' COMMENT '时间范围(TODAY当天,LAST7最近七天)TIME模式用' AFTER `incr_column`,
ADD COLUMN `batch_limit` int DEFAULT '2000' COMMENT '每轮最大采集行数(INCR模式TOP N限流)' AFTER `time_window`,
ADD COLUMN `last_watermark` varchar(64) DEFAULT NULL COMMENT '增量采集已处理到的高水位(INCR模式自动维护)' AFTER `batch_limit`;
-- 密炼动作为小状态表保持全量匹配
UPDATE `mes_xsl_mcs_sync_config` SET `sync_mode` = 'FULL' WHERE `biz_type` = 'MIX_ACT';

View File

@@ -0,0 +1,4 @@
-- MES上辅机增量匹配改为标记位回写可视化采集条件 + 可配置回写值
ALTER TABLE `mes_xsl_mcs_sync_config`
ADD COLUMN `flag_condition` varchar(20) DEFAULT 'IS_NULL' COMMENT '增量标记采集条件(IS_NULL为空,EQ_EMPTY等于空串,NE_EMPTY不等于空串)' AFTER `last_watermark`,
ADD COLUMN `flag_write_value` varchar(64) DEFAULT '1' COMMENT '增量标记采集完成后回写值(默认1)' AFTER `flag_condition`;

View File

@@ -0,0 +1,3 @@
-- MES上辅机增量采集条件等于/不等于支持自定义匹配值留空时退化为空字符串
ALTER TABLE `mes_xsl_mcs_sync_config`
ADD COLUMN `flag_match_value` varchar(255) DEFAULT NULL COMMENT '增量标记采集条件比较值(EQ_EMPTY/NE_EMPTY用,留空表示空字符串)' AFTER `flag_condition`;

View File

@@ -0,0 +1,42 @@
-- MES 胶料快检记录主表扩展实验标准/方法字段新增数据标准明细与曲线图明细
SET NAMES utf8mb4;
ALTER TABLE `mes_xsl_rubber_quick_test_record`
ADD COLUMN `std_name` varchar(200) DEFAULT NULL COMMENT '实验标准名称冗余' AFTER `std_id`,
ADD COLUMN `test_method_id` varchar(32) DEFAULT NULL COMMENT '实验方法ID' AFTER `std_name`,
ADD COLUMN `test_method_name` varchar(200) DEFAULT NULL COMMENT '实验方法名称冗余' AFTER `test_method_id`;
CREATE TABLE IF NOT EXISTS `mes_xsl_rubber_quick_test_record_std_line` (
`id` varchar(32) NOT NULL COMMENT '主键',
`record_id` varchar(32) NOT NULL COMMENT '主表 mes_xsl_rubber_quick_test_record.id',
`data_point_id` varchar(32) DEFAULT NULL COMMENT '数据点ID',
`point_name` varchar(128) DEFAULT NULL COMMENT '数据点名称',
`lower_limit` decimal(18,6) DEFAULT NULL COMMENT '下限值',
`lower_warn` decimal(18,6) DEFAULT NULL COMMENT '下警告值',
`target_value` decimal(18,6) DEFAULT NULL COMMENT '目标值',
`upper_warn` decimal(18,6) DEFAULT NULL COMMENT '上警告值',
`upper_limit` decimal(18,6) DEFAULT NULL COMMENT '上限值',
`sort_no` int DEFAULT NULL COMMENT '排序号',
`create_by` varchar(32) DEFAULT NULL COMMENT '创建人',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`update_by` varchar(32) DEFAULT NULL COMMENT '更新人',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `idx_rubber_quick_test_record_std_record_id` (`record_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='MES胶料快检记录数据标准明细';
CREATE TABLE IF NOT EXISTS `mes_xsl_rubber_quick_test_record_chart_point` (
`id` varchar(32) NOT NULL COMMENT '主键',
`record_id` varchar(32) NOT NULL COMMENT '主表 mes_xsl_rubber_quick_test_record.id',
`time_min` decimal(10,4) DEFAULT NULL COMMENT '时间(min)',
`upper_temp` decimal(18,6) DEFAULT NULL COMMENT '上模温度',
`lower_temp` decimal(18,6) DEFAULT NULL COMMENT '下模温度',
`torque_s` decimal(18,6) DEFAULT NULL COMMENT 'S''(dNm)',
`sort_no` int DEFAULT NULL COMMENT '排序号',
`create_by` varchar(32) DEFAULT NULL COMMENT '创建人',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`update_by` varchar(32) DEFAULT NULL COMMENT '更新人',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `idx_rubber_quick_test_record_chart_record_id` (`record_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='MES胶料快检记录曲线图数据点';

View File

@@ -0,0 +1,374 @@
{
"scanKeyword": "MesXslMixingProductionPlan",
"entityClass": "MesXslMixingProductionPlan",
"tableName": "mes_xsl_mixing_production_plan",
"javaEntityFile": "jeecg-boot\\jeecg-boot-module\\jeecg-module-xslmes\\src\\main\\java\\org\\jeecg\\modules\\xslmes\\entity\\MesXslMixingProductionPlan.java",
"hasIzEnable": false,
"hasCodeUniqueness": false,
"uniquenessFields": [],
"backendArch": {
"unifiedAnonCtrl": "jeecg-boot\\jeecg-boot-module\\jeecg-module-xslmes\\src\\main\\java\\org\\jeecg\\modules\\xslmes\\controller\\MesXslDesktopAnonController.java",
"registeredInAnonCtrl": true,
"anonEndpoints": [
"list"
],
"stompNotifySvc": "jeecg-boot\\jeecg-boot-module\\jeecg-module-xslmes\\src\\main\\java\\org\\jeecg\\modules\\xslmes\\service\\MesXslStompNotifyService.java",
"registeredInStompSvc": false,
"bizCtrlFile": "jeecg-boot\\jeecg-boot-module\\jeecg-module-xslmes\\src\\main\\java\\org\\jeecg\\modules\\xslmes\\controller\\MesXslMixingProductionPlanController.java",
"bizCtrlUsesSharedNotify": false,
"bizCtrlHasPrivatePublish": false
},
"wpfRegistrationStatus": {
"syncModuleService": false,
"syncModuleCoordinator": false,
"navigationView": false,
"stompSubscribe": false,
"menuRegistered": false,
"tenantMenuRegistered": false,
"syncModuleFilePath": "yy-admin-master\\YY.Admin\\Module\\SyncModule.cs",
"navExtFilePath": "yy-admin-master\\YY.Admin\\Module\\NavigationExtensions.cs",
"stompWsFilePath": "yy-admin-master\\YY.Admin\\Infrastructure\\Hubs\\StompWebSocketService.cs",
"menuSeedFilePath": "yy-admin-master\\YY.Admin.Core\\SeedData\\SysMenuSeedData.cs",
"summary": "✗ 待完成: SyncModule服务注册, SyncModule协调器注册, NavigationExtensions视图注册, STOMP订阅, 菜单注册"
},
"menuSuggestion": {
"parentMenuId": 1300150000101,
"parentMenuTitle": "基础资料",
"nextMenuId": 1300150011401,
"nextOrderNo": 113,
"menuIdPattern": "130015001{N}01N 每次 +11→101,2→201...",
"alreadyExists": false,
"existingMenuId": null
},
"apiPrefix": "/xslmes/mesXslMixingProductionPlan",
"stompCmd": "MIXING_PRODUCTION_PLAN_CHANGED",
"stompTopic": "/topic/sync/mes-mixing-production-plans",
"stompSubscriptionId": "sub-mes-xsl-mixing-production-plan",
"syncMode": "B",
"syncModeReason": "有/anon/免密端点适合模式B",
"filterFields": [
"machineId",
"machineName",
"planNo",
"planType",
"materialName"
],
"fields": [
{
"javaName": "sortNo",
"csName": "SortNo",
"sqlName": "sort_no",
"javaType": "Integer",
"csType": "int?",
"comment": "",
"isPk": false,
"isAudit": false,
"isIzEnable": false,
"required": false,
"dictCode": null
},
{
"javaName": "machineId",
"csName": "MachineId",
"sqlName": "machine_id",
"javaType": "String",
"csType": "string?",
"comment": "",
"isPk": false,
"isAudit": false,
"isIzEnable": false,
"required": false,
"dictCode": "id"
},
{
"javaName": "machineName",
"csName": "MachineName",
"sqlName": "machine_name",
"javaType": "String",
"csType": "string?",
"comment": "",
"isPk": false,
"isAudit": false,
"isIzEnable": false,
"required": false,
"dictCode": null
},
{
"javaName": "shiftFlag",
"csName": "ShiftFlag",
"sqlName": "shift_flag",
"javaType": "Integer",
"csType": "int?",
"comment": "",
"isPk": false,
"isAudit": false,
"isIzEnable": false,
"required": false,
"dictCode": null
},
{
"javaName": "planDate",
"csName": "PlanDate",
"sqlName": "plan_date",
"javaType": "Date",
"csType": "DateTime?",
"comment": "",
"isPk": false,
"isAudit": false,
"isIzEnable": false,
"required": false,
"dictCode": null
},
{
"javaName": "planNo",
"csName": "PlanNo",
"sqlName": "plan_no",
"javaType": "String",
"csType": "string?",
"comment": "",
"isPk": false,
"isAudit": false,
"isIzEnable": false,
"required": false,
"dictCode": null
},
{
"javaName": "planId",
"csName": "PlanId",
"sqlName": "plan_id",
"javaType": "String",
"csType": "string?",
"comment": "",
"isPk": false,
"isAudit": false,
"isIzEnable": false,
"required": false,
"dictCode": null
},
{
"javaName": "planType",
"csName": "PlanType",
"sqlName": "plan_type",
"javaType": "String",
"csType": "string?",
"comment": "",
"isPk": false,
"isAudit": false,
"isIzEnable": false,
"required": false,
"dictCode": null
},
{
"javaName": "sourceOrderId",
"csName": "SourceOrderId",
"sqlName": "source_order_id",
"javaType": "String",
"csType": "string?",
"comment": "",
"isPk": false,
"isAudit": false,
"isIzEnable": false,
"required": false,
"dictCode": null
},
{
"javaName": "materialId",
"csName": "MaterialId",
"sqlName": "material_id",
"javaType": "String",
"csType": "string?",
"comment": "",
"isPk": false,
"isAudit": false,
"isIzEnable": false,
"required": false,
"dictCode": null
},
{
"javaName": "materialName",
"csName": "MaterialName",
"sqlName": "material_name",
"javaType": "String",
"csType": "string?",
"comment": "",
"isPk": false,
"isAudit": false,
"isIzEnable": false,
"required": false,
"dictCode": null
},
{
"javaName": "orderNo",
"csName": "OrderNo",
"sqlName": "order_no",
"javaType": "String",
"csType": "string?",
"comment": "",
"isPk": false,
"isAudit": false,
"isIzEnable": false,
"required": false,
"dictCode": null
},
{
"javaName": "orderDate",
"csName": "OrderDate",
"sqlName": "order_date",
"javaType": "Date",
"csType": "DateTime?",
"comment": "",
"isPk": false,
"isAudit": false,
"isIzEnable": false,
"required": false,
"dictCode": null
},
{
"javaName": "formulaName",
"csName": "FormulaName",
"sqlName": "formula_name",
"javaType": "String",
"csType": "string?",
"comment": "",
"isPk": false,
"isAudit": false,
"isIzEnable": false,
"required": false,
"dictCode": null
},
{
"javaName": "planWeight",
"csName": "PlanWeight",
"sqlName": "plan_weight",
"javaType": "BigDecimal",
"csType": "double?",
"comment": "",
"isPk": false,
"isAudit": false,
"isIzEnable": false,
"required": false,
"dictCode": null
},
{
"javaName": "plannedCarCount",
"csName": "PlannedCarCount",
"sqlName": "planned_car_count",
"javaType": "Integer",
"csType": "int?",
"comment": "",
"isPk": false,
"isAudit": false,
"isIzEnable": false,
"required": false,
"dictCode": null
},
{
"javaName": "scheduledCarCount",
"csName": "ScheduledCarCount",
"sqlName": "scheduled_car_count",
"javaType": "Integer",
"csType": "int?",
"comment": "",
"isPk": false,
"isAudit": false,
"isIzEnable": false,
"required": false,
"dictCode": null
},
{
"javaName": "finishedCarCount",
"csName": "FinishedCarCount",
"sqlName": "finished_car_count",
"javaType": "Integer",
"csType": "int?",
"comment": "",
"isPk": false,
"isAudit": false,
"isIzEnable": false,
"required": false,
"dictCode": null
},
{
"javaName": "planCount",
"csName": "PlanCount",
"sqlName": "plan_count",
"javaType": "Integer",
"csType": "int?",
"comment": "",
"isPk": false,
"isAudit": false,
"isIzEnable": false,
"required": false,
"dictCode": null
},
{
"javaName": "remark",
"csName": "Remark",
"sqlName": "remark",
"javaType": "String",
"csType": "string?",
"comment": "",
"isPk": false,
"isAudit": false,
"isIzEnable": false,
"required": false,
"dictCode": null
}
],
"pkField": {
"javaName": "id",
"csName": "Id",
"sqlName": "id",
"javaType": "String",
"csType": "string?",
"comment": "",
"isPk": true,
"isAudit": false,
"isIzEnable": false,
"required": false,
"dictCode": null
},
"auditFields": [
"TenantId",
"SysOrgCode",
"CreateBy",
"CreateTime",
"UpdateBy",
"UpdateTime",
"DelFlag"
],
"dbConfig": {
"url": "jdbc:mysql://localhost:3306/jeecg-boot-dev?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai",
"username": "root",
"configFile": "jeecg-boot\\jeecg-boot-module\\jeecg-boot-module-airag\\src\\main\\resources\\application.yml"
},
"dbColumns": [],
"csEntityStub": "public class MesXslMixingProductionPlan\n{\n public string? Id { get; set; }\n public int? SortNo { get; set; }\n public string? MachineId { get; set; } [Dict:id]\n public string? MachineName { get; set; }\n public int? ShiftFlag { get; set; }\n public DateTime? PlanDate { get; set; }\n public string? PlanNo { get; set; }\n public string? PlanId { get; set; }\n public string? PlanType { get; set; }\n public string? SourceOrderId { get; set; }\n public string? MaterialId { get; set; }\n public string? MaterialName { get; set; }\n public string? OrderNo { get; set; }\n public DateTime? OrderDate { get; set; }\n public string? FormulaName { get; set; }\n public double? PlanWeight { get; set; }\n public int? PlannedCarCount { get; set; }\n public int? ScheduledCarCount { get; set; }\n public int? FinishedCarCount { get; set; }\n public int? PlanCount { get; set; }\n public string? Remark { get; set; }\n public int? TenantId { get; set; }\n public string? SysOrgCode { get; set; }\n public string? CreateBy { get; set; }\n public DateTime? CreateTime { get; set; }\n public string? UpdateBy { get; set; }\n public DateTime? UpdateTime { get; set; }\n public int? DelFlag { get; set; }\n // 只读显示属性:\n // public string StatusText => Status == \"1\" ? \"停用\" : \"启用\";\n}",
"generationHints": {
"eventClassName": "MesXslMixingProductionPlanChangedEvent",
"serviceInterface": "IMixingProductionPlanService",
"serviceImpl": "MixingProductionPlanService",
"syncCoordinator": "MixingProductionPlanSyncCoordinator",
"listViewModel": "MixingProductionPlanListViewModel",
"editDialogViewModel": "MixingProductionPlanEditDialogViewModel",
"listView": "MixingProductionPlanListView",
"editDialogView": "MixingProductionPlanEditDialogView",
"pendingOpsFile": "mes-xsl-mixing-production-plan-pending-ops.json",
"cacheFile": "mes-xsl-mixing-production-plan-cache.json",
"nextMenuId": 1300150011401,
"nextMenuOrderNo": 113,
"backendFilesToModify": [
"jeecg-boot\\jeecg-boot-module\\jeecg-module-xslmes\\src\\main\\java\\org\\jeecg\\modules\\xslmes\\controller\\MesXslDesktopAnonController.java",
"jeecg-boot\\jeecg-boot-module\\jeecg-module-xslmes\\src\\main\\java\\org\\jeecg\\modules\\xslmes\\service\\MesXslStompNotifyService.java",
"jeecg-boot\\jeecg-boot-module\\jeecg-module-xslmes\\src\\main\\java\\org\\jeecg\\modules\\xslmes\\controller\\MesXslMixingProductionPlanController.java",
"jeecg-boot-base-core/.../ShiroConfig.java"
],
"wpfFilesToModify": [
"yy-admin-master\\YY.Admin\\Module\\SyncModule.cs",
"yy-admin-master\\YY.Admin\\Module\\NavigationExtensions.cs",
"yy-admin-master\\YY.Admin\\Infrastructure\\Hubs\\StompWebSocketService.cs",
"yy-admin-master\\YY.Admin.Core\\SeedData\\SysMenuSeedData.cs",
"YY.Admin.Core/SeedData/SysTenantMenuSeedData.cs"
]
}
}

View File

@@ -5,15 +5,6 @@
<a-button type="primary" v-auth="'mes:mes_material:add'" @click="handleAdd" preIcon="ant-design:plus-outlined">新增</a-button>
<a-button type="primary" v-auth="'mes:mes_material:exportXls'" preIcon="ant-design:export-outlined" @click="onExportXls">导出</a-button>
<j-upload-button type="primary" v-auth="'mes:mes_material:importExcel'" preIcon="ant-design:import-outlined" @click="onImportXls">导入</j-upload-button>
<a-button
type="primary"
v-auth="'mes:mes_material:rubberQuickTestInspect'"
preIcon="ant-design:experiment-outlined"
:disabled="selectedRowKeys.length === 0"
@click="handleRubberQuickTest"
>
检验
</a-button>
<a-dropdown v-if="selectedRowKeys.length > 0">
<template #overlay>
<a-menu>
@@ -38,10 +29,7 @@ import { useListPage } from '/@/hooks/system/useListPage';
import MesMaterialModal from './modules/MesMaterialModal.vue';
import { columns, searchFormSchema } from './MesMaterial.data';
import { batchDelete, deleteOne, getExportUrl, getImportUrl, list } from './MesMaterial.api';
import { batchFromMaterial } from '/@/views/xslmes/mesXslRubberQuickTestRecord/MesXslRubberQuickTestRecord.api';
import { useMessage } from '/@/hooks/web/useMessage';
const { createMessage } = useMessage();
const [registerModal, { openModal }] = useModal();
const { tableContext, onExportXls, onImportXls } = useListPage({
tableProps: {
@@ -75,18 +63,6 @@ async function batchHandleDelete() {
function handleSuccess() {
reload();
}
async function handleRubberQuickTest() {
if (!selectedRowKeys.value?.length) {
createMessage.warning('请至少选择一条胶料');
return;
}
try {
await batchFromMaterial({ materialIds: [...selectedRowKeys.value] });
createMessage.success('快检记录已生成,请到「胶料快检记录」中编辑');
} catch (e: any) {
createMessage.error(e?.message || '生成失败');
}
}
function getTableAction(record) {
return [{ label: '编辑', onClick: handleEdit.bind(null, record), auth: 'mes:mes_material:edit' }];
}

View File

@@ -14,10 +14,10 @@ enum Api {
export const list = (params) => defHttp.get({ url: Api.list, params });
export const checkActionName = (params: { actionName: string; dataId?: string }) =>
export const checkActionName = (params: { equipmentId?: string; actionName: string; dataId?: string }) =>
defHttp.get({ url: Api.checkActionName, params }, { successMessageMode: 'none', errorMessageMode: 'none' });
export const checkActionCode = (params: { actionCode: string; dataId?: string }) =>
export const checkActionCode = (params: { equipmentId?: string; actionCode: string; dataId?: string }) =>
defHttp.get({ url: Api.checkActionCode, params }, { successMessageMode: 'none', errorMessageMode: 'none' });
export const deleteOne = (params, handleSuccess) =>

View File

@@ -2,9 +2,11 @@ import { BasicColumn, FormSchema } from '/@/components/Table';
import { checkActionCode, checkActionName } from './MesXslMixerAction.api';
export const columns: BasicColumn[] = [
{ title: '设备名称', align: 'center', dataIndex: 'equipmentId_dictText', width: 180 },
{ title: '设备名称', align: 'center', dataIndex: 'equipmentName', width: 180 },
{ title: '机台编号', align: 'center', dataIndex: 'equipId', width: 110 },
{ title: '机台类型', align: 'center', dataIndex: 'equipType', width: 110 },
{ title: '动作名称', align: 'center', dataIndex: 'actionName', width: 180 },
{ title: '动作代号', align: 'center', dataIndex: 'actionCode', width: 160 },
{ title: '动作代号', align: 'center', dataIndex: 'actionCode', width: 120 },
{ title: '创建时间', align: 'center', dataIndex: 'createTime', width: 170 },
];
@@ -16,6 +18,7 @@ export const searchFormSchema: FormSchema[] = [
componentProps: { dictCode: 'mes_xsl_equipment_ledger,equipment_name,id' },
colProps: { span: 6 },
},
{ label: '机台编号', field: 'equipId', component: 'Input', colProps: { span: 6 } },
{ label: '动作名称', field: 'actionName', component: 'Input', colProps: { span: 6 } },
{ label: '动作代号', field: 'actionCode', component: 'Input', colProps: { span: 6 } },
];
@@ -29,6 +32,21 @@ export const formSchema: FormSchema[] = [
required: true,
componentProps: { dictCode: 'mes_xsl_equipment_ledger,equipment_name,id', placeholder: '请选择设备台账中的设备' },
},
// 采集冗余字段:仅采集数据有值,只读展示
{
label: '机台编号',
field: 'equipId',
component: 'Input',
componentProps: { disabled: true },
ifShow: ({ values }) => !!values.equipId,
},
{
label: '机台类型',
field: 'equipType',
component: 'Input',
componentProps: { disabled: true },
ifShow: ({ values }) => !!values.equipType,
},
{
label: '动作名称',
field: 'actionName',
@@ -41,10 +59,10 @@ export const formSchema: FormSchema[] = [
const v = value == null ? '' : String(value).trim();
if (!v) return Promise.resolve();
try {
await checkActionName({ actionName: v, dataId: model?.id });
await checkActionName({ equipmentId: model?.equipmentId, actionName: v, dataId: model?.id });
return Promise.resolve();
} catch (e: any) {
return Promise.reject(e?.response?.data?.message || e?.message || '动作名称不能重复');
return Promise.reject(e?.response?.data?.message || e?.message || '同一设备下动作名称不能重复');
}
},
trigger: 'blur',
@@ -63,10 +81,10 @@ export const formSchema: FormSchema[] = [
const v = value == null ? '' : String(value).trim();
if (!v) return Promise.resolve();
try {
await checkActionCode({ actionCode: v, dataId: model?.id });
await checkActionCode({ equipmentId: model?.equipmentId, actionCode: v, dataId: model?.id });
return Promise.resolve();
} catch (e: any) {
return Promise.reject(e?.response?.data?.message || e?.message || '动作代号不能重复');
return Promise.reject(e?.response?.data?.message || e?.message || '同一设备下动作代号不能重复');
}
},
trigger: 'blur',

View File

@@ -13,7 +13,9 @@ enum Api {
exportXls = '/xslmes/mesXslRubberQuickTestRecord/exportXls',
queryById = '/xslmes/mesXslRubberQuickTestRecord/queryById',
queryLineList = '/xslmes/mesXslRubberQuickTestRecord/queryLineListByRecordId',
batchFromMaterial = '/xslmes/mesXslRubberQuickTestRecord/batchFromMaterial',
queryStdLineList = '/xslmes/mesXslRubberQuickTestRecord/queryStdLineListByRecordId',
queryRawLineList = '/xslmes/mesXslRubberQuickTestRecord/queryRawLineListByRecordId',
queryChartPointList = '/xslmes/mesXslRubberQuickTestRecord/queryChartPointListByRecordId',
}
export const getExportUrl = Api.exportXls;
@@ -25,7 +27,11 @@ export const queryById = (params: { id: string }) => defHttp.get({ url: Api.quer
export const queryLineListByRecordId = (params: { id: string }) => defHttp.get({ url: Api.queryLineList, params });
export const batchFromMaterial = (params) => defHttp.post({ url: Api.batchFromMaterial, params });
export const queryStdLineListByRecordId = (params: { id: string }) => defHttp.get({ url: Api.queryStdLineList, params });
export const queryRawLineListByRecordId = (params: { id: string }) => defHttp.get({ url: Api.queryRawLineList, params });
export const queryChartPointListByRecordId = (params: { id: string }) => defHttp.get({ url: Api.queryChartPointList, params });
export const deleteOne = (params, handleSuccess) => {
return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {

View File

@@ -4,14 +4,13 @@ import { JVxeColumn, JVxeTypes } from '/@/components/jeecg/JVxeTable/types';
const numProps = { style: { width: '100%' }, precision: 6 };
export const columns: BasicColumn[] = [
{ title: '号', align: 'center', dataIndex: 'recordNo', width: 150 },
{ title: '快检记录号', align: 'center', dataIndex: 'recordNo', width: 150 },
{ title: '胶料名称', align: 'center', dataIndex: 'rubberMaterialName', width: 140 },
{ title: '生产机台', align: 'center', dataIndex: 'prodEquipmentName', width: 120 },
{ title: '生产日期', align: 'center', dataIndex: 'productionDate', width: 110 },
{ title: '机台', align: 'center', dataIndex: 'prodEquipmentName', width: 120 },
{ title: '密炼日期', align: 'center', dataIndex: 'productionDate', width: 110 },
{ title: '车次编号', align: 'center', dataIndex: 'trainNo', width: 100 },
{ title: '班次', align: 'center', dataIndex: 'workShift_dictText', width: 80 },
{ title: '班组', align: 'center', dataIndex: 'workTeam_dictText', width: 80 },
{ title: '检验次数', align: 'center', dataIndex: 'inspectTimes', width: 90 },
{ title: '试验次数', align: 'center', dataIndex: 'inspectTimes', width: 90 },
{ title: '检验时间', align: 'center', dataIndex: 'inspectTime', width: 165 },
{
title: '检验人',
@@ -20,22 +19,24 @@ export const columns: BasicColumn[] = [
width: 100,
customRender: ({ record }) => record?.inspectorRealname || record?.inspectorUserId_dictText || '',
},
{ title: '检验类型', align: 'center', dataIndex: 'quickTestTypeName', width: 120 },
{ title: '实验标准', align: 'center', dataIndex: 'stdName', width: 120 },
{ title: '实验方法', align: 'center', dataIndex: 'testMethodName', width: 120 },
{ title: '实验类型', align: 'center', dataIndex: 'quickTestTypeName', width: 120 },
{ title: '检验结果', align: 'center', dataIndex: 'inspectResult_dictText', width: 90 },
{ title: '生产计划', align: 'center', dataIndex: 'productionPlanNo', width: 120 },
{ title: '密炼计划', align: 'center', dataIndex: 'productionPlanNo', width: 120 },
{ title: '检验机台', align: 'center', dataIndex: 'inspectEquipmentName', width: 120 },
{ title: '胶料卡片号', align: 'center', dataIndex: 'rubberCardNo', width: 120 },
{ title: '胶料批次', align: 'center', dataIndex: 'rubberBatchNo', width: 120 },
];
export const searchFormSchema: FormSchema[] = [
{ label: '号', field: 'recordNo', component: 'Input', colProps: { span: 6 } },
{ label: '快检记录号', field: 'recordNo', component: 'Input', colProps: { span: 6 } },
{ label: '胶料名称', field: 'rubberMaterialName', component: 'Input', colProps: { span: 6 } },
{
label: '生产机台',
label: '机台',
field: 'prodEquipmentLedgerId',
component: 'JDictSelectTag',
componentProps: { dictCode: 'mes_xsl_equipment_ledger,equipment_name,id', placeholder: '请选择生产机台' },
componentProps: { dictCode: 'mes_xsl_equipment_ledger,equipment_name,id', placeholder: '请选择机台' },
colProps: { span: 6 },
},
{
@@ -53,20 +54,13 @@ export const searchFormSchema: FormSchema[] = [
colProps: { span: 6 },
},
{
label: '班组',
field: 'workTeam',
component: 'JDictSelectTag',
componentProps: { dictCode: 'xslmes_rubber_quick_test_work_team', placeholder: '请选择班组' },
colProps: { span: 6 },
},
{
label: '检验类型',
label: '实验类型',
field: 'quickTestTypeId',
component: 'JSearchSelect',
componentProps: {
dict: 'mes_xsl_rubber_quick_test_type,type_name,id',
async: true,
placeholder: '请选择验类型',
placeholder: '请选择验类型',
},
colProps: { span: 6 },
},
@@ -82,7 +76,7 @@ export const searchFormSchema: FormSchema[] = [
},
colProps: { span: 6 },
},
{ label: '生产计划', field: 'productionPlanNo', component: 'Input', colProps: { span: 6 } },
{ label: '密炼计划', field: 'productionPlanNo', component: 'Input', colProps: { span: 6 } },
{ label: '胶料批次', field: 'rubberBatchNo', component: 'Input', colProps: { span: 6 } },
{
label: '检验结果',
@@ -103,7 +97,7 @@ export const formSchema: FormSchema[] = [
{ label: '', field: 'inspectorUsername', component: 'Input', show: false },
{ label: '', field: 'quickTestTypeId', component: 'Input', show: false },
{
label: '号',
label: '快检记录号',
field: 'recordNo',
component: 'Input',
componentProps: { readonly: true, placeholder: '保存时自动生成' },
@@ -115,13 +109,31 @@ export const formSchema: FormSchema[] = [
componentProps: { readonly: true },
},
{
label: '生产机台',
label: '实验标准',
field: 'stdName',
component: 'Input',
componentProps: { readonly: true },
},
{
label: '实验方法',
field: 'testMethodName',
component: 'Input',
componentProps: { readonly: true },
},
{
label: '实验类型',
field: 'quickTestTypeName',
component: 'Input',
componentProps: { readonly: true },
},
{
label: '炼机台',
field: 'prodEquipmentName',
component: 'Input',
slot: 'prodEquipmentPicker',
},
{
label: '生产日期',
label: '密炼日期',
field: 'productionDate',
component: 'DatePicker',
componentProps: { valueFormat: 'YYYY-MM-DD', style: { width: '100%' } },
@@ -134,13 +146,7 @@ export const formSchema: FormSchema[] = [
componentProps: { dictCode: 'xslmes_rubber_quick_test_work_shift', placeholder: '请选择班次' },
},
{
label: '班组',
field: 'workTeam',
component: 'JDictSelectTag',
componentProps: { dictCode: 'xslmes_rubber_quick_test_work_team', placeholder: '请选择班组' },
},
{
label: '检验次数',
label: '试验次数',
field: 'inspectTimes',
component: 'InputNumber',
componentProps: { style: { width: '100%' }, min: 0, precision: 0 },
@@ -176,23 +182,13 @@ export const formSchema: FormSchema[] = [
}),
},
{ label: '', field: 'inspectorRealname', component: 'Input', show: false },
{
label: '检验类型',
field: 'quickTestTypeId',
component: 'JSearchSelect',
componentProps: {
dict: 'mes_xsl_rubber_quick_test_type,type_name,id',
async: true,
placeholder: '请选择检验类型',
},
},
{
label: '检验结果',
field: 'inspectResult',
component: 'JDictSelectTag',
componentProps: { dictCode: 'xslmes_rubber_quick_test_record_result', placeholder: '合格/不合格' },
},
{ label: '生产计划', field: 'productionPlanNo', component: 'Input' },
{ label: '密炼计划', field: 'productionPlanNo', component: 'Input' },
{
label: '检验机台',
field: 'inspectEquipmentName',
@@ -203,6 +199,40 @@ export const formSchema: FormSchema[] = [
{ label: '胶料批次', field: 'rubberBatchNo', component: 'Input' },
];
export const stdLineJVxeColumns: JVxeColumn[] = [
{ title: '', key: 'dataPointId', type: JVxeTypes.hidden },
{ title: '数据点', key: 'pointName', type: JVxeTypes.normal, width: 160, disabled: true },
{ title: '下限值', key: 'lowerLimit', type: JVxeTypes.normal, width: 100, disabled: true },
{ title: '下警告值', key: 'lowerWarn', type: JVxeTypes.normal, width: 100, disabled: true },
{ title: '目标值', key: 'targetValue', type: JVxeTypes.normal, width: 100, disabled: true },
{ title: '上警告值', key: 'upperWarn', type: JVxeTypes.normal, width: 100, disabled: true },
{ title: '上限值', key: 'upperLimit', type: JVxeTypes.normal, width: 100, disabled: true },
];
export const rawLineJVxeColumns: JVxeColumn[] = [
{ title: '', key: 'dataPointId', type: JVxeTypes.hidden },
{ title: '编号', key: 'rowNo', type: JVxeTypes.normal, width: 90, disabled: true },
{ title: '数据点', key: 'inspectItem', type: JVxeTypes.normal, width: 140, disabled: true },
{ title: '下限值', key: 'lowerLimit', type: JVxeTypes.normal, width: 90, disabled: true },
{ title: '上限值', key: 'upperLimit', type: JVxeTypes.normal, width: 90, disabled: true },
{
title: '检测值',
key: 'inspectValue',
type: JVxeTypes.inputNumber,
width: 100,
componentProps: numProps,
},
{
title: '行检验结果',
key: 'rowInspectResult',
type: JVxeTypes.select,
width: 110,
disabled: true,
dictCode: 'xslmes_rubber_quick_test_record_result',
},
];
/** @deprecated 历史汇总明细,仅兼容旧数据 */
export const lineJVxeColumns: JVxeColumn[] = [
{ title: '', key: 'dataPointId', type: JVxeTypes.hidden },
{ title: '检验项目', key: 'inspectItem', type: JVxeTypes.normal, width: 180, disabled: true },

View File

@@ -3,14 +3,14 @@
v-bind="$attrs"
destroyOnClose
:title="title"
width="1100px"
width="1200px"
@register="registerModal"
@ok="handleSubmit"
>
<BasicForm @register="registerForm">
<template #prodEquipmentPicker="{ model, field }">
<a-input-group compact style="display: flex; width: 100%">
<a-input v-model:value="model[field]" read-only placeholder="请选择生产机台" style="flex: 1" />
<a-input v-model:value="model[field]" read-only placeholder="请选择机台" style="flex: 1" />
<a-button type="primary" :disabled="isDetail" @click="openProdEquipmentSelect">选择</a-button>
<a-button v-if="model.prodEquipmentLedgerId && !isDetail" @click="clearProdEquipment(model)">清除</a-button>
</a-input-group>
@@ -23,34 +23,86 @@
</a-input-group>
</template>
</BasicForm>
<a-divider orientation="left">检验明细由实验标准带出不可增删</a-divider>
<JVxeTable
v-if="tableReady"
ref="lineTableRef"
row-number
keep-source
:toolbar="false"
:insert-row="false"
:remove-btn="false"
:max-height="380"
:loading="lineLoading"
:columns="lineJVxeColumns"
:dataSource="lineDataSource"
:disabled="isDetail"
/>
<template v-if="useNewDetail">
<a-divider orientation="left">数据标准明细</a-divider>
<JVxeTable
v-if="tableReady"
row-number
keep-source
:toolbar="false"
:insert-row="false"
:remove-btn="false"
:max-height="260"
:loading="detailLoading"
:columns="stdLineJVxeColumns"
:dataSource="stdLineDataSource"
disabled
/>
<a-divider orientation="left">试验结果明细</a-divider>
<JVxeTable
v-if="tableReady"
row-number
keep-source
:toolbar="false"
:insert-row="false"
:remove-btn="false"
:max-height="320"
:loading="detailLoading"
:columns="rawLineJVxeColumns"
:dataSource="rawLineDataSource"
:disabled="isDetail"
/>
<a-divider orientation="left">曲线图</a-divider>
<a-row :gutter="16">
<a-col :span="12">
<div class="chart-title">温度曲线上模/下模</div>
<div ref="tempChartRef" class="chart-box"></div>
</a-col>
<a-col :span="12">
<div class="chart-title">S'(dNm) 曲线</div>
<div ref="torqueChartRef" class="chart-box"></div>
</a-col>
</a-row>
</template>
<template v-else>
<a-divider orientation="left">检验明细(历史数据)</a-divider>
<JVxeTable
v-if="tableReady"
row-number
keep-source
:toolbar="false"
:insert-row="false"
:remove-btn="false"
:max-height="380"
:loading="detailLoading"
:columns="lineJVxeColumns"
:dataSource="lineDataSource"
:disabled="isDetail"
/>
</template>
<MesXslEquipmentLedgerSelectModal @register="registerLedgerModal" @select="onLedgerSelect" />
</BasicModal>
</template>
<script lang="ts" setup>
import { computed, ref, unref } from 'vue';
import { computed, nextTick, ref, unref, watch, type Ref } from 'vue';
import { BasicModal, useModalInner, useModal } from '/@/components/Modal';
import { BasicForm, useForm } from '/@/components/Form/index';
import type { JVxeTableInstance } from '/@/components/jeecg/JVxeTable/types';
import { useMessage } from '/@/hooks/web/useMessage';
import { useUserStore } from '/@/store/modules/user';
import { formSchema, lineJVxeColumns } from '../MesXslRubberQuickTestRecord.data';
import { saveOrUpdate, queryById, queryLineListByRecordId } from '../MesXslRubberQuickTestRecord.api';
import { useECharts } from '/@/hooks/web/useECharts';
import {
formSchema,
lineJVxeColumns,
stdLineJVxeColumns,
rawLineJVxeColumns,
} from '../MesXslRubberQuickTestRecord.data';
import { saveOrUpdate, queryById, queryChartPointListByRecordId } from '../MesXslRubberQuickTestRecord.api';
import MesXslEquipmentLedgerSelectModal from '/@/views/xslmes/mesXslEquipInspectConfig/components/MesXslEquipmentLedgerSelectModal.vue';
const emit = defineEmits(['register', 'success']);
@@ -59,9 +111,19 @@
const isDetail = ref(false);
const tableReady = ref(false);
const lineLoading = ref(false);
const detailLoading = ref(false);
const useNewDetail = ref(false);
const stdLineDataSource = ref<Recordable[]>([]);
const rawLineDataSource = ref<Recordable[]>([]);
const chartPointDataSource = ref<Recordable[]>([]);
const lineDataSource = ref<Recordable[]>([]);
const lineTableRef = ref<JVxeTableInstance>();
const tempChartRef = ref<HTMLDivElement | null>(null);
const torqueChartRef = ref<HTMLDivElement | null>(null);
const { setOptions: setTempChartOptions, resize: resizeTempChart } = useECharts(tempChartRef as Ref<HTMLDivElement>);
const { setOptions: setTorqueChartOptions, resize: resizeTorqueChart } = useECharts(torqueChartRef as Ref<HTMLDivElement>);
const ledgerPickTarget = ref<'prod' | 'inspect'>('prod');
const [registerForm, { resetFields, setFieldsValue, validate, setProps, getFieldsValue }] = useForm({
@@ -75,19 +137,21 @@
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
tableReady.value = false;
stdLineDataSource.value = [];
rawLineDataSource.value = [];
chartPointDataSource.value = [];
lineDataSource.value = [];
useNewDetail.value = false;
await resetFields();
setModalProps({ confirmLoading: false, showCancelBtn: data?.showFooter, showOkBtn: data?.showFooter });
isDetail.value = !data?.showFooter;
setProps({ disabled: !data?.showFooter });
if (data?.record?.id) {
lineLoading.value = true;
detailLoading.value = true;
try {
const mainRaw = await queryById({ id: data.record.id });
const m = (mainRaw as any)?.id != null ? mainRaw : (mainRaw as any)?.result ?? mainRaw;
const linesRaw = await queryLineListByRecordId({ id: data.record.id });
const list = Array.isArray(linesRaw) ? linesRaw : (linesRaw as any)?.result ?? [];
const patch: Recordable = { ...m };
if (data?.showFooter && !patch.inspectorRealname && !patch.inspectorUserId) {
const user = userStore.getUserInfo || {};
@@ -96,16 +160,95 @@
patch.inspectorRealname = user.realname;
}
await setFieldsValue(patch);
lineDataSource.value = list || [];
const stdLines = m?.stdLineList ?? [];
const rawLines = m?.rawLineList ?? [];
let chartPoints = m?.chartPointList ?? [];
const legacyLines = m?.lineList ?? [];
if (stdLines.length > 0 || rawLines.length > 0 || chartPoints.length > 0) {
useNewDetail.value = true;
stdLineDataSource.value = stdLines;
rawLineDataSource.value = rawLines;
if (!chartPoints.length && data?.record?.id) {
try {
const chartRes = await queryChartPointListByRecordId({ id: data.record.id });
chartPoints = Array.isArray(chartRes) ? chartRes : (chartRes as any)?.result ?? [];
} catch (_) {
chartPoints = [];
}
}
chartPointDataSource.value = chartPoints;
} else {
lineDataSource.value = legacyLines;
}
} finally {
lineLoading.value = false;
detailLoading.value = false;
}
}
tableReady.value = true;
if (useNewDetail.value) {
await scheduleRenderCharts(chartPointDataSource.value);
}
});
async function scheduleRenderCharts(points: Recordable[]) {
await nextTick();
await nextTick();
window.setTimeout(() => {
renderCharts(points);
resizeTempChart();
resizeTorqueChart();
}, 120);
}
watch(useNewDetail, async (visible) => {
if (visible && chartPointDataSource.value.length) {
await scheduleRenderCharts(chartPointDataSource.value);
}
});
const title = computed(() => (unref(isDetail) ? '快检记录详情' : '编辑胶料快检记录'));
function toChartNumber(value: unknown) {
if (value === null || value === undefined || value === '') return null;
const num = Number(value);
return Number.isFinite(num) ? num : null;
}
function renderCharts(points: Recordable[]) {
if (!points?.length) {
setTempChartOptions({ title: { text: '暂无曲线数据', left: 'center', top: 'center', textStyle: { fontSize: 14 } } });
setTorqueChartOptions({ title: { text: '暂无曲线数据', left: 'center', top: 'center', textStyle: { fontSize: 14 } } });
return;
}
const sorted = [...points].sort((a, b) => (a.sortNo ?? 0) - (b.sortNo ?? 0));
const times = sorted.map((p) => toChartNumber(p.timeMin) ?? 0);
setTempChartOptions({
title: undefined,
tooltip: { trigger: 'axis' },
legend: { data: ['上模温度', '下模温度'] },
grid: { left: 48, right: 24, top: 40, bottom: 32 },
xAxis: { type: 'category', name: '时间(min)', data: times },
yAxis: { type: 'value', name: '温度()', min: 189, max: 201, interval: 3 },
series: [
{ name: '上模温度', type: 'line', smooth: true, data: sorted.map((p) => toChartNumber(p.upperTemp)) },
{ name: '下模温度', type: 'line', smooth: true, data: sorted.map((p) => toChartNumber(p.lowerTemp)) },
],
});
setTorqueChartOptions({
title: undefined,
tooltip: { trigger: 'axis' },
legend: { data: ["S'(dNm)"] },
grid: { left: 48, right: 24, top: 40, bottom: 32 },
xAxis: { type: 'category', name: '时间(min)', data: times },
yAxis: { type: 'value', name: "S'(dNm)", min: 0, max: 14.8 },
series: [{ name: "S'(dNm)", type: 'line', smooth: true, data: sorted.map((p) => toChartNumber(p.torqueS)) }],
});
}
function openProdEquipmentSelect() {
ledgerPickTarget.value = 'prod';
const vals = getFieldsValue();
@@ -149,23 +292,36 @@
}
try {
const values = await validate();
const lineRef = lineTableRef.value as any;
const tableData = (lineRef?.getTableData?.() || lineDataSource.value || []) as Recordable[];
const lineList = tableData
.filter((r) => r && r.inspectItem)
.map((r) => ({
dataPointId: r.dataPointId,
inspectItem: r.inspectItem,
lowerLimit: r.lowerLimit,
inspectValue: r.inspectValue,
upperLimit: r.upperLimit,
}));
if (!lineList.length) {
createMessage.warning('检验明细不能为空');
return;
const payload: Recordable = { ...values };
if (unref(useNewDetail)) {
payload.stdLineList = stdLineDataSource.value || [];
payload.rawLineList = rawLineDataSource.value || [];
payload.chartPointList = chartPointDataSource.value || [];
if (!payload.stdLineList.length || !payload.rawLineList.length) {
createMessage.warning('数据标准明细与试验结果明细不能为空');
return;
}
} else {
const tableData = lineDataSource.value || [];
const lineList = tableData
.filter((r) => r && r.inspectItem)
.map((r) => ({
dataPointId: r.dataPointId,
inspectItem: r.inspectItem,
lowerLimit: r.lowerLimit,
inspectValue: r.inspectValue,
upperLimit: r.upperLimit,
}));
if (!lineList.length) {
createMessage.warning('检验明细不能为空');
return;
}
payload.lineList = lineList;
}
setModalProps({ confirmLoading: true });
await saveOrUpdate({ ...values, lineList }, true);
await saveOrUpdate(payload, true);
closeModal();
emit('success');
} finally {
@@ -173,3 +329,15 @@
}
}
</script>
<style scoped>
.chart-title {
font-size: 13px;
color: rgba(0, 0, 0, 0.65);
margin-bottom: 8px;
}
.chart-box {
width: 100%;
height: 220px;
}
</style>

View File

@@ -0,0 +1,201 @@
<template>
<BasicModal v-bind="$attrs" @register="registerModal" title="采集操作" :width="560" @ok="handleOk">
<a-spin :spinning="loading">
<a-form :labelCol="{ span: 7 }" :wrapperCol="{ span: 16 }">
<a-form-item label="采集配置">
<span>{{ configName || '-' }}</span>
<span v-if="sourceTable" style="color: #999"> 源表{{ sourceTable }}</span>
</a-form-item>
<a-form-item label="是否采集">
<a-switch v-model:checked="enabled" checkedChildren="采集中" unCheckedChildren="已停止" />
</a-form-item>
<a-form-item label="采集间隔">
<a-input-number v-model:value="intervalSeconds" :min="1" :precision="0" addonAfter="秒" style="width: 100%" />
</a-form-item>
<a-form-item label="采集模式">
<a-radio-group v-model:value="syncMode" button-style="solid">
<a-radio-button value="FULL">全量匹配</a-radio-button>
<a-radio-button value="TIME">时间匹配</a-radio-button>
<a-radio-button value="INCR">增量匹配</a-radio-button>
</a-radio-group>
<div style="color: #999; font-size: 12px; margin-top: 4px">{{ modeHint }}</div>
</a-form-item>
<template v-if="syncMode === 'TIME'">
<a-form-item label="时间列" required>
<a-select v-model:value="incrColumn" :options="sourceColumnOptions" showSearch allowClear placeholder="选择源表的时间列(如 WriteTime)" />
</a-form-item>
<a-form-item label="时间范围">
<a-radio-group v-model:value="timeWindow">
<a-radio value="TODAY">当天</a-radio>
<a-radio value="LAST7">最近七天</a-radio>
</a-radio-group>
</a-form-item>
</template>
<template v-else-if="syncMode === 'INCR'">
<a-form-item label="标记列" required>
<a-select v-model:value="incrColumn" :options="sourceColumnOptions" showSearch allowClear placeholder="选择源表用于标记是否已采集的列" />
<div style="color: #999; font-size: 12px">需在字段映射中勾选匹配键( GUID)作为回写主键并开启中间库写入开关</div>
</a-form-item>
<a-form-item label="采集条件" required>
<a-radio-group v-model:value="flagCondition" button-style="solid">
<a-radio-button value="IS_NULL">为空</a-radio-button>
<a-radio-button value="EQ_EMPTY">等于</a-radio-button>
<a-radio-button value="NE_EMPTY">不等于</a-radio-button>
</a-radio-group>
<!-- update-begin---author:GHT ---date:20260617 forMES上辅机等于/不等于支持自定义匹配值----------- -->
<a-input
v-if="flagCondition === 'EQ_EMPTY' || flagCondition === 'NE_EMPTY'"
v-model:value="flagMatchValue"
:placeholder="`填写要${flagCondition === 'EQ_EMPTY' ? '等于' : '不等于'}的值(留空表示空字符串“”)`"
allowClear
style="width: 100%; margin-top: 6px"
/>
<!-- update-end---author:GHT ---date:20260617 forMES上辅机等于/不等于支持自定义匹配值----------- -->
<div style="color: #999; font-size: 12px">仅采集标记列满足此条件的行</div>
</a-form-item>
<a-form-item label="回写值">
<a-input v-model:value="flagWriteValue" placeholder="采集完成后写回标记列的值,默认 1" allowClear style="width: 100%" />
<div style="color: #999; font-size: 12px">采集完成后把标记列回写成该值使这些行不再满足上面的采集条件默认1</div>
</a-form-item>
<a-form-item label="每轮最大行数">
<a-input-number v-model:value="batchLimit" :min="100" :step="500" :precision="0" addonAfter="行" style="width: 100%" />
<div style="color: #999; font-size: 12px">每个采集周期最多取这么多行分批吃完历史未采集数据</div>
</a-form-item>
</template>
<a-form-item v-if="lastSyncResult" label="最近采集">
<span style="color: #999">{{ lastSyncResult }}</span>
</a-form-item>
</a-form>
</a-spin>
</BasicModal>
</template>
<script lang="ts" setup>
import { computed, ref } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { useMessage } from '/@/hooks/web/useMessage';
import { queryById, getByBizType, saveCollect, getSourceColumns } from '../mcsSyncConfig.api';
const emit = defineEmits(['register', 'success']);
const { createMessage } = useMessage();
const loading = ref(false);
const configId = ref('');
const configName = ref('');
const sourceTable = ref('');
const enabled = ref(false);
const intervalSeconds = ref(1);
const syncMode = ref('FULL');
const incrColumn = ref<string | undefined>(undefined);
const timeWindow = ref('TODAY');
const batchLimit = ref(2000);
const flagCondition = ref('IS_NULL');
const flagMatchValue = ref('');
const flagWriteValue = ref('1');
const lastWatermark = ref('');
const lastSyncResult = ref('');
const sourceColumnOptions = ref<any[]>([]);
const modeHint = computed(() => {
if (syncMode.value === 'TIME') return '只采集时间列在所选范围内的数据,再按匹配键更新/新增。适合中大型表只关注近期数据。';
if (syncMode.value === 'INCR') return '标记位回写只采集“标记列”为空的行采完回写“1”下轮不再重复。适合带 GUID 主键、无可靠递增列的流水表。';
return '全表读取并按匹配键更新/新增。适合数据量小、以更新为主的表。';
});
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
setModalProps({ confirmLoading: false });
loading.value = true;
try {
reset();
const cfg: any = data?.id ? await queryById(data.id) : await getByBizType(data?.bizType || 'MIX_ACT');
if (!cfg || !cfg.id) {
createMessage.warning('未找到采集配置,请先在「采集配置」中新增');
return;
}
configId.value = cfg.id;
configName.value = cfg.configName || cfg.bizName || cfg.sourceTable;
sourceTable.value = cfg.sourceTable || '';
enabled.value = cfg.running === true || cfg.status === '1';
intervalSeconds.value = cfg.intervalSeconds || 1;
syncMode.value = cfg.syncMode || 'FULL';
incrColumn.value = cfg.incrColumn || undefined;
timeWindow.value = cfg.timeWindow || 'TODAY';
batchLimit.value = cfg.batchLimit || 2000;
flagCondition.value = cfg.flagCondition || 'IS_NULL';
flagMatchValue.value = cfg.flagMatchValue ?? '';
flagWriteValue.value = cfg.flagWriteValue ?? '1';
lastWatermark.value = cfg.lastWatermark || '';
lastSyncResult.value = cfg.lastSyncResult || '';
// 载入源表列供时间列/增量列选择(中间库未连接时静默忽略)
if (sourceTable.value) {
try {
const cols: any = await getSourceColumns(sourceTable.value);
sourceColumnOptions.value = (cols || []).map((c: any) => ({
label: c.columnName + (c.columnComment ? ` - ${c.columnComment}` : '') + (c.dataType ? ` (${c.dataType})` : ''),
value: c.columnName,
}));
} catch (e) {
sourceColumnOptions.value = [];
}
}
} finally {
loading.value = false;
}
});
function reset() {
configId.value = '';
configName.value = '';
sourceTable.value = '';
enabled.value = false;
intervalSeconds.value = 1;
syncMode.value = 'FULL';
incrColumn.value = undefined;
timeWindow.value = 'TODAY';
batchLimit.value = 2000;
flagCondition.value = 'IS_NULL';
flagMatchValue.value = '';
flagWriteValue.value = '1';
lastWatermark.value = '';
lastSyncResult.value = '';
sourceColumnOptions.value = [];
}
async function handleOk() {
if (!configId.value) {
closeModal();
return;
}
if (!intervalSeconds.value || intervalSeconds.value < 1) {
createMessage.warning('采集间隔不能小于1秒');
return;
}
if ((syncMode.value === 'TIME' || syncMode.value === 'INCR') && !incrColumn.value) {
createMessage.warning(syncMode.value === 'TIME' ? '请选择时间列' : '请选择标记列');
return;
}
setModalProps({ confirmLoading: true });
try {
await saveCollect({
id: configId.value,
status: enabled.value ? '1' : '0',
intervalSeconds: intervalSeconds.value,
syncMode: syncMode.value,
incrColumn: incrColumn.value,
timeWindow: timeWindow.value,
batchLimit: batchLimit.value,
flagCondition: flagCondition.value,
flagMatchValue: flagMatchValue.value,
flagWriteValue: flagWriteValue.value,
});
closeModal();
emit('success');
} finally {
setModalProps({ confirmLoading: false });
}
}
</script>

View File

@@ -0,0 +1,267 @@
<template>
<BasicModal v-bind="$attrs" @register="registerModal" :title="title" :width="960" @ok="handleSubmit" :confirmLoading="confirmLoading">
<a-spin :spinning="loading">
<a-form :model="form" :labelCol="{ span: 6 }" :wrapperCol="{ span: 16 }">
<a-row>
<a-col :span="12">
<a-form-item label="配置名称" required>
<a-input v-model:value="form.configName" placeholder="如:密炼机动作采集" />
</a-form-item>
</a-col>
<a-col :span="12">
<a-form-item label="采集间隔">
<a-input-number v-model:value="form.intervalSeconds" :min="1" :precision="0" addonAfter="秒" style="width: 100%" />
</a-form-item>
</a-col>
</a-row>
<a-row>
<a-col :span="12">
<a-form-item label="中间库源表" required>
<a-select
v-model:value="form.sourceTable"
:options="sourceTableOptions"
showSearch
placeholder="选择中间库的表"
style="width: 100%"
@change="onSourceTableChange"
/>
</a-form-item>
</a-col>
<a-col :span="12">
<a-form-item label="MES目标表" required>
<a-select
v-model:value="form.targetTable"
:options="targetTableOptions"
showSearch
placeholder="选择MES的表(mes_xsl_)"
style="width: 100%"
@change="onTargetTableChange"
/>
</a-form-item>
</a-col>
</a-row>
</a-form>
<a-divider style="margin: 8px 0">字段映射中间库字段 / MES接收字段勾选匹配键作为去重Upsert唯一键</a-divider>
<a-table
:columns="mappingColumns"
:dataSource="mappingRows"
:pagination="false"
size="small"
rowKey="sourceField"
:scroll="{ y: 360 }"
>
<template #bodyCell="{ column, record }">
<template v-if="column.dataIndex === 'sourceField'">
<div>{{ record.sourceField }}</div>
<div style="color: #999; font-size: 12px">{{ record.sourceFieldComment }}</div>
</template>
<template v-else-if="column.dataIndex === 'targetField'">
<a-select
v-model:value="record.targetField"
:options="targetColumnOptions"
allowClear
showSearch
placeholder="选择MES接收字段"
style="width: 100%"
:disabled="!form.targetTable"
@change="(v) => onTargetFieldChange(record, v)"
/>
</template>
<template v-else-if="column.dataIndex === 'matchKey'">
<a-checkbox v-model:checked="record.matchKey" />
</template>
</template>
</a-table>
<div v-if="mappingRows.length === 0" style="text-align: center; color: #999; padding: 16px">请选择中间库源表以载入字段</div>
</a-spin>
</BasicModal>
</template>
<script lang="ts" setup>
import { computed, reactive, ref } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { useMessage } from '/@/hooks/web/useMessage';
import { queryById, saveOrUpdate, getSourceTables, getSourceColumns, getTargetTables, getTargetColumns } from '../mcsSyncConfig.api';
const emit = defineEmits(['register', 'success']);
const { createMessage } = useMessage();
const isUpdate = ref(false);
const loading = ref(false);
const confirmLoading = ref(false);
const form = reactive<any>({
id: undefined,
configName: '',
bizType: '',
sourceTable: undefined,
sourceTableComment: '',
targetTable: undefined,
targetTableComment: '',
intervalSeconds: 1,
});
const sourceTableOptions = ref<any[]>([]);
const targetTableOptions = ref<any[]>([]);
const targetColumnOptions = ref<any[]>([]);
const mappingRows = ref<any[]>([]);
const title = computed(() => (isUpdate.value ? '编辑采集配置' : '新增采集配置'));
const mappingColumns = [
{ title: '中间库字段', dataIndex: 'sourceField', width: 240 },
{ title: '类型', dataIndex: 'sourceFieldType', width: 90 },
{ title: 'MES接收字段', dataIndex: 'targetField' },
{ title: '匹配键', dataIndex: 'matchKey', width: 70, align: 'center' },
];
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
setModalProps({ confirmLoading: false });
loading.value = true;
try {
resetForm();
isUpdate.value = !!data?.isUpdate;
// 表清单
const [srcTables, tgtTables] = await Promise.all([safeGet(getSourceTables), getTargetTables()]);
sourceTableOptions.value = (srcTables || []).map((t: any) => ({
label: t.tableName + (t.tableComment ? ` - ${t.tableComment}` : ''),
value: t.tableName,
comment: t.tableComment,
}));
targetTableOptions.value = (tgtTables || []).map((t: any) => ({
label: t.tableName + (t.tableComment ? ` - ${t.tableComment}` : ''),
value: t.tableName,
comment: t.tableComment,
}));
if (isUpdate.value && data?.record?.id) {
const cfg: any = await queryById(data.record.id);
Object.assign(form, {
id: cfg.id,
configName: cfg.configName,
bizType: cfg.bizType,
sourceTable: cfg.sourceTable,
sourceTableComment: cfg.sourceTableComment,
targetTable: cfg.targetTable,
targetTableComment: cfg.targetTableComment,
intervalSeconds: cfg.intervalSeconds || 1,
});
// 载入目标字段选项
if (cfg.targetTable) {
targetColumnOptions.value = buildColumnOptions(await getTargetColumns(cfg.targetTable));
}
// 字段映射来自已存配置
mappingRows.value = (cfg.fieldList || []).map((f: any) => ({
sourceField: f.sourceField,
sourceFieldComment: f.sourceFieldComment,
sourceFieldType: f.sourceFieldType,
targetField: f.targetField,
targetFieldComment: f.targetFieldComment,
matchKey: f.matchKey === '1',
}));
}
} finally {
loading.value = false;
}
});
function resetForm() {
Object.assign(form, {
id: undefined,
configName: '',
bizType: '',
sourceTable: undefined,
sourceTableComment: '',
targetTable: undefined,
targetTableComment: '',
intervalSeconds: 1,
});
targetColumnOptions.value = [];
mappingRows.value = [];
}
async function safeGet(fn: () => Promise<any>) {
try {
return await fn();
} catch (e) {
return [];
}
}
function buildColumnOptions(cols: any[]) {
return (cols || []).map((c: any) => ({
label: c.columnName + (c.columnComment ? ` - ${c.columnComment}` : ''),
value: c.columnName,
comment: c.columnComment,
}));
}
async function onSourceTableChange(val: string) {
const opt = sourceTableOptions.value.find((o) => o.value === val);
form.sourceTableComment = opt?.comment || '';
if (!val) {
mappingRows.value = [];
return;
}
const cols = await getSourceColumns(val);
mappingRows.value = (cols || []).map((c: any) => {
// 同名自动匹配 MES 字段
const guess = targetColumnOptions.value.find((o) => o.value.toLowerCase() === String(c.columnName).toLowerCase());
return {
sourceField: c.columnName,
sourceFieldComment: c.columnComment,
sourceFieldType: c.dataType,
targetField: guess ? guess.value : undefined,
targetFieldComment: guess ? guess.comment : '',
matchKey: false,
};
});
}
async function onTargetTableChange(val: string) {
const opt = targetTableOptions.value.find((o) => o.value === val);
form.targetTableComment = opt?.comment || '';
targetColumnOptions.value = val ? buildColumnOptions(await getTargetColumns(val)) : [];
}
function onTargetFieldChange(record: any, val: string) {
const opt = targetColumnOptions.value.find((o) => o.value === val);
record.targetFieldComment = opt?.comment || '';
}
async function handleSubmit() {
if (!form.configName) {
createMessage.warning('请填写配置名称');
return;
}
if (!form.sourceTable || !form.targetTable) {
createMessage.warning('请选择中间库源表与MES目标表');
return;
}
const fieldList = mappingRows.value
.filter((r) => r.targetField)
.map((r, idx) => ({
sourceField: r.sourceField,
sourceFieldComment: r.sourceFieldComment,
sourceFieldType: r.sourceFieldType,
targetField: r.targetField,
targetFieldComment: r.targetFieldComment,
matchKey: r.matchKey ? '1' : '0',
sortNo: idx,
}));
if (fieldList.length === 0) {
createMessage.warning('请至少为一个中间库字段选择 MES 接收字段');
return;
}
confirmLoading.value = true;
try {
await saveOrUpdate({ ...form, fieldList }, isUpdate.value);
closeModal();
emit('success');
} finally {
confirmLoading.value = false;
}
}
</script>

View File

@@ -0,0 +1,64 @@
<template>
<div>
<BasicTable @register="registerTable">
<template #tableTitle>
<a-button type="primary" v-auth="'xslmes:mcsSyncConfig:add'" preIcon="ant-design:plus-outlined" @click="handleAdd">新增采集配置</a-button>
</template>
<template #action="{ record }">
<TableAction :actions="getTableAction(record)" />
</template>
</BasicTable>
<SyncConfigModal @register="registerEditModal" @success="reload" />
<CollectModal @register="registerCollectModal" @success="reload" />
</div>
</template>
<script lang="ts" name="xslmes-mcs-mcsSyncConfig" setup>
import { BasicTable, TableAction } from '/@/components/Table';
import { useModal } from '/@/components/Modal';
import { useListPage } from '/@/hooks/system/useListPage';
import SyncConfigModal from './components/SyncConfigModal.vue';
import CollectModal from './components/CollectModal.vue';
import { columns, searchFormSchema } from './mcsSyncConfig.data';
import { list, deleteOne } from './mcsSyncConfig.api';
const [registerEditModal, { openModal: openEditModal }] = useModal();
const [registerCollectModal, { openModal: openCollectModal }] = useModal();
const { tableContext } = useListPage({
tableProps: {
title: '采集配置',
api: list,
columns,
canResize: true,
formConfig: { labelWidth: 100, schemas: searchFormSchema, autoSubmitOnEnter: true },
actionColumn: { width: 200, fixed: 'right' },
},
});
const [registerTable, { reload }] = tableContext;
function handleAdd() {
openEditModal(true, { isUpdate: false });
}
function handleEdit(record) {
openEditModal(true, { isUpdate: true, record });
}
function handleCollect(record) {
openCollectModal(true, { id: record.id });
}
async function handleDelete(record) {
await deleteOne(record.id, reload);
}
function getTableAction(record) {
return [
{ label: '编辑', onClick: handleEdit.bind(null, record), auth: 'xslmes:mcsSyncConfig:edit' },
{ label: '采集操作', onClick: handleCollect.bind(null, record), auth: 'xslmes:mcsSyncConfig:setting' },
{
label: '删除',
color: 'error',
popConfirm: { title: '确认删除该采集配置?', confirm: handleDelete.bind(null, record) },
auth: 'xslmes:mcsSyncConfig:delete',
},
];
}
</script>

View File

@@ -0,0 +1,44 @@
import { defHttp } from '/@/utils/http/axios';
enum Api {
list = '/xslmes/mcs/syncConfig/list',
queryById = '/xslmes/mcs/syncConfig/queryById',
getByBizType = '/xslmes/mcs/syncConfig/getByBizType',
add = '/xslmes/mcs/syncConfig/add',
edit = '/xslmes/mcs/syncConfig/edit',
deleteOne = '/xslmes/mcs/syncConfig/delete',
saveCollect = '/xslmes/mcs/syncConfig/saveCollect',
sourceTables = '/xslmes/mcs/syncConfig/meta/sourceTables',
sourceColumns = '/xslmes/mcs/syncConfig/meta/sourceColumns',
targetTables = '/xslmes/mcs/syncConfig/meta/targetTables',
targetColumns = '/xslmes/mcs/syncConfig/meta/targetColumns',
}
export const list = (params) => defHttp.get({ url: Api.list, params });
export const queryById = (id: string) => defHttp.get({ url: Api.queryById, params: { id } });
export const getByBizType = (bizType = 'MIX_ACT') => defHttp.get({ url: Api.getByBizType, params: { bizType } });
export const saveOrUpdate = (params, isUpdate: boolean) => defHttp.post({ url: isUpdate ? Api.edit : Api.add, params });
export const deleteOne = (id: string, handleSuccess) =>
defHttp.delete({ url: Api.deleteOne, params: { id } }, { joinParamsToUrl: true }).then(() => handleSuccess());
// 采集操作status '1'/'0' 表示是否采集syncMode FULL/TIME/INCR
export const saveCollect = (params: {
id: string;
status: string;
intervalSeconds: number;
syncMode?: string;
incrColumn?: string;
timeWindow?: string;
batchLimit?: number;
flagCondition?: string;
flagWriteValue?: string;
}) => defHttp.post({ url: Api.saveCollect, params });
export const getSourceTables = () => defHttp.get({ url: Api.sourceTables }, { errorMessageMode: 'message' });
export const getSourceColumns = (table: string) => defHttp.get({ url: Api.sourceColumns, params: { table } }, { errorMessageMode: 'message' });
export const getTargetTables = () => defHttp.get({ url: Api.targetTables });
export const getTargetColumns = (table: string) => defHttp.get({ url: Api.targetColumns, params: { table } });

View File

@@ -0,0 +1,41 @@
import { BasicColumn, FormSchema } from '/@/components/Table';
export const columns: BasicColumn[] = [
{ title: '配置名称', align: 'center', dataIndex: 'configName', width: 160 },
{
title: '中间库源表',
align: 'center',
dataIndex: 'sourceTable',
width: 200,
customRender: ({ record }) => (record.sourceTableComment ? `${record.sourceTable}${record.sourceTableComment}` : record.sourceTable),
},
{
title: 'MES目标表',
align: 'center',
dataIndex: 'targetTable',
width: 200,
customRender: ({ record }) => (record.targetTableComment ? `${record.targetTable}${record.targetTableComment}` : record.targetTable),
},
{
title: '采集模式',
align: 'center',
dataIndex: 'syncMode',
width: 100,
customRender: ({ record }) => ({ FULL: '全量匹配', TIME: '时间匹配', INCR: '增量匹配' }[record.syncMode] || '全量匹配'),
},
{ title: '采集间隔(秒)', align: 'center', dataIndex: 'intervalSeconds', width: 100 },
{
title: '状态',
align: 'center',
dataIndex: 'running',
width: 90,
customRender: ({ record }) => (record.running ? '采集中' : '已停止'),
},
{ title: '最近采集时间', align: 'center', dataIndex: 'lastSyncTime', width: 160 },
{ title: '最近采集结果', align: 'center', dataIndex: 'lastSyncResult', width: 200 },
];
export const searchFormSchema: FormSchema[] = [
{ label: '配置名称', field: 'configName', component: 'Input', colProps: { span: 6 } },
{ label: '中间库源表', field: 'sourceTable', component: 'Input', colProps: { span: 6 } },
];

View File

@@ -1,8 +1,9 @@
<template>
<template>
<div>
<BasicTable @register="registerTable">
<template #tableTitle>
<a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
<a-button type="primary" v-auth="'xslmes:mcsSyncConfig:setting'" preIcon="ant-design:sync-outlined" @click="openCollect"> 采集操作 </a-button>
<a-button type="link" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
<super-query :config="superQueryConfig" @search="handleSuperQuery" />
</template>
<template #action="{ record }">
@@ -10,6 +11,7 @@
</template>
</BasicTable>
<McsToMesMixActModal @register="registerModal" />
<CollectModal @register="registerCollectModal" @success="reload" />
</div>
</template>
@@ -19,11 +21,13 @@
import { useModal } from '/@/components/Modal';
import { useListPage } from '/@/hooks/system/useListPage';
import McsToMesMixActModal from './components/McsToMesMixActModal.vue';
import CollectModal from '../mcsSyncConfig/components/CollectModal.vue';
import { columns, searchFormSchema } from './McsToMesMixAct.data';
import { list, getExportUrl } from './McsToMesMixAct.api';
const queryParam = reactive<any>({});
const [registerModal, { openModal }] = useModal();
const [registerCollectModal, { openModal: openCollectModal }] = useModal();
const { tableContext, onExportXls } = useListPage({
tableProps: {
@@ -49,8 +53,15 @@
const [registerTable, { reload }] = tableContext;
const superQueryConfig = reactive({});
// 采集操作:弹窗维护是否采集 + 采集间隔(绑定密炼动作采集配置 MIX_ACT
function openCollect() {
openCollectModal(true, { bizType: 'MIX_ACT' });
}
function handleSuperQuery(params) {
Object.keys(params).map((k) => { queryParam[k] = params[k]; });
Object.keys(params).map((k) => {
queryParam[k] = params[k];
});
reload();
}

View File

@@ -0,0 +1,11 @@
using Prism.Events;
namespace YY.Admin.Core.Events;
public class MixingProductionPlanChangedPayload
{
public string Action { get; set; } = string.Empty;
public string? MixingProductionPlanId { get; set; }
}
public class MixingProductionPlanChangedEvent : PubSubEvent<MixingProductionPlanChangedPayload> { }

View File

@@ -0,0 +1,11 @@
using Prism.Events;
namespace YY.Admin.Core.Events;
public class RubberQuickTestRecordChangedPayload
{
public string Action { get; set; } = string.Empty;
public string? RecordId { get; set; }
}
public class RubberQuickTestRecordChangedEvent : PubSubEvent<RubberQuickTestRecordChangedPayload> { }

View File

@@ -0,0 +1,28 @@
using YY.Admin.Core.Entity;
namespace YY.Admin.Core.Services;
/// <summary>密炼生产计划MES 只读同步)</summary>
public interface IMixingProductionPlanService
{
Task<MixingProductionPlanPageResult> PageAsync(
int pageNo, int pageSize,
DateTime? planDateFrom = null,
DateTime? planDateTo = null,
string? machineName = null,
int? shiftFlag = null,
string? planNo = null,
string? materialName = null,
CancellationToken ct = default);
Task<List<MesXslMixingProductionPlan>> GetAllCachedAsync(CancellationToken ct = default);
/// <returns>本地缓存是否有变更(有差异才写入)</returns>
Task<bool> SyncFromRemoteAsync(CancellationToken ct = default);
}
public record MixingProductionPlanPageResult(
List<MesXslMixingProductionPlan> Records,
long Total,
int PageNo,
int PageSize);

View File

@@ -2,12 +2,8 @@ using YY.Admin.Core.Entity;
namespace YY.Admin.Core.Services;
/// <summary>胶料快检记录操作台:密炼计划筛选、实验标准匹配、记录保存</summary>
/// <summary>胶料快检记录操作台:保存至 MES</summary>
public interface IRubberQuickTestOperationService
{
Task<List<MesXslMixingProductionPlan>> GetMixingProductionPlansAsync(CancellationToken ct = default);
Task<MesXslRubberQuickTestStd?> GetStdByRubberMaterialNameAsync(string rubberMaterialName, CancellationToken ct = default);
Task<string?> SaveRecordAsync(MesXslRubberQuickTestRecord record, CancellationToken ct = default);
}

View File

@@ -0,0 +1,31 @@
using YY.Admin.Core.Entity;
namespace YY.Admin.Core.Services;
public interface IRubberQuickTestRecordService
{
Task<RubberQuickTestRecordPageResult> PageAsync(
int pageNo,
int pageSize,
string? filterRecordNo = null,
string? filterRubberMaterialName = null,
string? filterPlanNo = null,
CancellationToken ct = default);
Task<MesXslRubberQuickTestRecord?> GetByIdAsync(string id, CancellationToken ct = default);
RubberQuickTestRecordLocalItem? GetByLocalId(string localId);
Task<RubberQuickTestRecordSaveResult> SaveAsync(MesXslRubberQuickTestRecord entity, CancellationToken ct = default);
/// <summary>删除本地同步失败的快检记录(已同步或待同步不可删)</summary>
bool DeleteFailedLocal(string localId);
string GenerateRecordNo(string rubberMaterialName);
}
public record RubberQuickTestRecordPageResult(
List<RubberQuickTestRecordListRow> Records,
long Total,
int PageNo,
int PageSize);

View File

@@ -14,7 +14,15 @@ public interface IRubberQuickTestStdService
Task<MesXslRubberQuickTestStd?> GetByIdAsync(string id, CancellationToken ct = default);
Task SyncFromRemoteAsync(CancellationToken ct = default);
Task<List<MesXslRubberQuickTestStd>> GetAllCachedAsync(CancellationToken ct = default);
Task<MesXslRubberQuickTestStd?> GetCachedByIdAsync(string id, CancellationToken ct = default);
/// <summary>优先读本地缓存;无明细时联网拉取详情并回写缓存</summary>
Task<MesXslRubberQuickTestStd?> GetWithLinesAsync(string id, CancellationToken ct = default);
/// <returns>本地缓存是否有变更(有差异才写入)</returns>
Task<bool> SyncFromRemoteAsync(CancellationToken ct = default);
}
public record RubberQuickTestStdPageResult(

View File

@@ -1,6 +1,6 @@
namespace YY.Admin.Core.Entity;
/// <summary>密炼生产计划维护(桌面端快检记录筛选用</summary>
/// <summary>密炼生产计划维护(MES 数据源,桌面端只读同步</summary>
public class MesXslMixingProductionPlan
{
public string? Id { get; set; }
@@ -8,21 +8,57 @@ public class MesXslMixingProductionPlan
public string? MachineId { get; set; }
public string? MachineName { get; set; }
public string? MorningPlanId { get; set; }
public string? MorningPlanType { get; set; }
public string? MorningOrderNo { get; set; }
public DateTime? MorningOrderDate { get; set; }
public string? MorningFormulaName { get; set; }
/// <summary>班次标识1早班 2中班 3晚班</summary>
public int? ShiftFlag { get; set; }
public string? NoonPlanId { get; set; }
public string? NoonPlanType { get; set; }
public string? NoonOrderNo { get; set; }
public DateTime? NoonOrderDate { get; set; }
public string? NoonFormulaName { get; set; }
/// <summary>计划日期(密炼日期)</summary>
public DateTime? PlanDate { get; set; }
public string? NightPlanId { get; set; }
public string? NightPlanType { get; set; }
public string? NightOrderNo { get; set; }
public DateTime? NightOrderDate { get; set; }
public string? NightFormulaName { get; set; }
public string? PlanNo { get; set; }
public string? PlanId { get; set; }
public string? PlanType { get; set; }
public string? SourceOrderId { get; set; }
public string? MaterialId { get; set; }
public string? MaterialName { get; set; }
public string? OrderNo { get; set; }
public DateTime? OrderDate { get; set; }
public string? FormulaName { get; set; }
public double? PlanWeight { get; set; }
public int? PlannedCarCount { get; set; }
public int? ScheduledCarCount { get; set; }
public int? FinishedCarCount { get; set; }
/// <summary>计划数量MES plan_count</summary>
public int? PlanCount { get; set; }
public string? Remark { get; set; }
public int? TenantId { get; set; }
public string? SysOrgCode { get; set; }
public string? CreateBy { get; set; }
public DateTime? CreateTime { get; set; }
public string? UpdateBy { get; set; }
public DateTime? UpdateTime { get; set; }
public int? DelFlag { get; set; }
public string ShiftFlagText => ShiftFlag switch
{
1 => "早班",
2 => "中班",
3 => "晚班",
_ => ShiftFlag?.ToString() ?? string.Empty
};
public string PlanDateText => PlanDate?.ToString("yyyy-MM-dd") ?? string.Empty;
/// <summary>计划+胶料号计划号_胶料名称如 SA0001_HB10001</summary>
public string PlanMaterialNo
{
get
{
var planNo = PlanNo?.Trim();
var materialName = MaterialName?.Trim();
if (string.IsNullOrEmpty(planNo) && string.IsNullOrEmpty(materialName)) return string.Empty;
if (string.IsNullOrEmpty(planNo)) return materialName ?? string.Empty;
if (string.IsNullOrEmpty(materialName)) return planNo;
return $"{planNo}_{materialName}";
}
}
}

View File

@@ -7,6 +7,9 @@ public class MesXslRubberQuickTestRecord
public string? RubberMaterialId { get; set; }
public string? RubberMaterialName { get; set; }
public string? StdId { get; set; }
public string? StdName { get; set; }
public string? TestMethodId { get; set; }
public string? TestMethodName { get; set; }
public string? ProdEquipmentLedgerId { get; set; }
public string? ProdEquipmentName { get; set; }
public DateTime? ProductionDate { get; set; }
@@ -17,8 +20,18 @@ public class MesXslRubberQuickTestRecord
public string? InspectorUserId { get; set; }
public string? InspectorUsername { get; set; }
public string? InspectorRealname { get; set; }
public string? QuickTestTypeId { get; set; }
public string? QuickTestTypeName { get; set; }
public string? InspectResult { get; set; }
public string? ProductionPlanNo { get; set; }
public List<MesXslRubberQuickTestRecordLine>? LineList { get; set; }
public DateTime? CreateTime { get; set; }
public List<MesXslRubberQuickTestRecordStdLine>? StdLineList { get; set; }
public List<MesXslRubberQuickTestRecordRawLine>? RawLineList { get; set; }
public List<MesXslRubberQuickTestRecordChartPoint>? ChartPointList { get; set; }
/// <summary>列表展示:班次文本</summary>
public string? WorkShiftText { get; set; }
/// <summary>列表展示:是否合格</summary>
public string? InspectResultText { get; set; }
}

View File

@@ -0,0 +1,13 @@
namespace YY.Admin.Core.Entity;
/// <summary>胶料快检记录曲线图数据点</summary>
public class MesXslRubberQuickTestRecordChartPoint
{
public string? Id { get; set; }
public string? RecordId { get; set; }
public decimal? TimeMin { get; set; }
public decimal? UpperTemp { get; set; }
public decimal? LowerTemp { get; set; }
public decimal? TorqueS { get; set; }
public int? SortNo { get; set; }
}

View File

@@ -0,0 +1,16 @@
namespace YY.Admin.Core.Entity;
/// <summary>胶料快检记录数据标准明细(实验标准快照)</summary>
public class MesXslRubberQuickTestRecordStdLine
{
public string? Id { get; set; }
public string? RecordId { get; set; }
public string? DataPointId { get; set; }
public string? PointName { get; set; }
public decimal? LowerLimit { get; set; }
public decimal? UpperLimit { get; set; }
public decimal? LowerWarn { get; set; }
public decimal? UpperWarn { get; set; }
public decimal? TargetValue { get; set; }
public int? SortNo { get; set; }
}

View File

@@ -9,6 +9,9 @@ public class MesXslRubberQuickTestStd
public string? StdName { get; set; }
public string? TestMethodId { get; set; }
public string? TestMethodName { get; set; }
/// <summary>实验类型来自实验方法MES 回填)</summary>
public string? QuickTestTypeId { get; set; }
public string? QuickTestTypeName { get; set; }
public string? MixerType { get; set; }
public string? RubberMaterialId { get; set; }
public string? RubberMaterialName { get; set; }

View File

@@ -0,0 +1,32 @@
namespace YY.Admin.Core.Entity;
/// <summary>胶料快检记录列表行</summary>
public class RubberQuickTestRecordListRow
{
public string? LocalId { get; set; }
public string? MesId { get; set; }
public string? RecordNo { get; set; }
public DateTime? ProductionDate { get; set; }
public string? ProdEquipmentName { get; set; }
public string? WorkShiftDisplay { get; set; }
public string? ProductionPlanNo { get; set; }
public string? RubberMaterialName { get; set; }
public string? StdName { get; set; }
public string? TestMethodName { get; set; }
public string? QuickTestTypeName { get; set; }
public string? TrainNo { get; set; }
public int? InspectTimes { get; set; }
public string? InspectorRealname { get; set; }
public DateTime? InspectDate { get; set; }
public string? InspectResultDisplay { get; set; }
public string SyncStatus { get; set; } = "Pending";
public string SyncStatusDisplay => SyncStatus switch
{
"Synced" => "已同步",
"Failed" => "失败",
_ => "待同步"
};
/// <summary>仅本地同步失败记录可删除</summary>
public bool CanDelete => SyncStatus == "Failed" && !string.IsNullOrWhiteSpace(LocalId);
}

View File

@@ -0,0 +1,13 @@
namespace YY.Admin.Core.Entity;
/// <summary>桌面端本地胶料快检记录包装(含同步状态)</summary>
public class RubberQuickTestRecordLocalItem
{
public string LocalId { get; set; } = Guid.NewGuid().ToString("N");
public string? MesId { get; set; }
/// <summary>Pending / Synced / Failed</summary>
public string SyncStatus { get; set; } = "Pending";
public string? SyncError { get; set; }
public DateTime LocalCreateTime { get; set; } = DateTime.Now;
public MesXslRubberQuickTestRecord Record { get; set; } = new();
}

View File

@@ -0,0 +1,8 @@
namespace YY.Admin.Core.Entity;
public class RubberQuickTestRecordSaveResult
{
public MesXslRubberQuickTestRecord Record { get; set; } = new();
public string LocalId { get; set; } = string.Empty;
public string SyncStatus { get; set; } = "Pending";
}

View File

@@ -0,0 +1,66 @@
namespace YY.Admin.Core.Helper;
/// <summary>MES 只读数据:远端列表与本地缓存按 Id 对比合并</summary>
public static class MesReadOnlyCacheMergeHelper
{
public sealed record MergeResult(int Added, int Updated, int Removed)
{
public bool HasChanges => Added > 0 || Updated > 0 || Removed > 0;
}
/// <summary>
/// 对比远端与本地,返回合并后的列表及变更统计。
/// 内容相同则保留本地副本;<paramref name="mergeUpdated"/> 可定制变更行的合并策略(如保留本地子表)。
/// </summary>
public static (List<T> Merged, MergeResult Stats) Merge<T>(
IReadOnlyList<T> local,
IReadOnlyList<T> remote,
Func<T, string?> getId,
Func<T, T, bool> isContentEqual,
Func<T, T> clone,
Func<T, T, T>? mergeUpdated = null)
{
var localById = new Dictionary<string, T>(StringComparer.OrdinalIgnoreCase);
foreach (var item in local)
{
var id = getId(item);
if (!string.IsNullOrWhiteSpace(id))
localById[id] = item;
}
var remoteIds = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
var merged = new List<T>(remote.Count);
int added = 0, updated = 0;
foreach (var remoteItem in remote)
{
var id = getId(remoteItem);
if (string.IsNullOrWhiteSpace(id))
{
merged.Add(clone(remoteItem));
added++;
continue;
}
remoteIds.Add(id);
if (!localById.TryGetValue(id, out var localItem))
{
merged.Add(clone(remoteItem));
added++;
}
else if (!isContentEqual(localItem, remoteItem))
{
merged.Add(mergeUpdated != null ? mergeUpdated(localItem, remoteItem) : clone(remoteItem));
updated++;
}
else
{
merged.Add(clone(localItem));
}
}
int removed = localById.Keys.Count(id => !remoteIds.Contains(id));
return (merged, new MergeResult(added, updated, removed));
}
}

View File

@@ -48,10 +48,12 @@ public class SysMenuSeedData : ISqlSugarEntitySeedData<SysMenu>
new SysMenu{ Id=1300150011001, Pid=1300150000101, Title="库区管理", Path="/xslmes/mesXslWarehouseArea", Name="mesXslWarehouseArea", Component="WarehouseAreaListView", Icon="&#xe7ce;", Type=MenuTypeEnum.Menu, CreateTime=DateTime.Parse("2022-02-10 00:00:00"), OrderNo=109 },
// 密炼物料皮重策略
new SysMenu{ Id=1300150011101, Pid=1300150000101, Title="密炼物料皮重策略", Path="/xslmes/mesXslMixerMaterialTareStrategy", Name="mesXslMixerMaterialTareStrategy", Component="MixerMaterialTareStrategyListView", Icon="&#xe7ce;", Type=MenuTypeEnum.Menu, CreateTime=DateTime.Parse("2022-02-10 00:00:00"), OrderNo=110 },
// 快检记录
new SysMenu{ Id=1300150011201, Pid=1300150000101, Title="快检记录", Path="/xslmes/rubberQuickTestOperation", Name="rubberQuickTestOperation", Component="RubberQuickTestOperationView", Icon="&#xe7de;", Type=MenuTypeEnum.Menu, CreateTime=DateTime.Parse("2022-02-10 00:00:00"), OrderNo=111 },
// 胶料快检实验标准(桌面端只读)
new SysMenu{ Id=1300150011301, Pid=1300150000101, Title="胶料快检实验标准", Path="/xslmes/mesXslRubberQuickTestStd", Name="mesXslRubberQuickTestStd", Component="RubberQuickTestStdListView", Icon="&#xe7ce;", Type=MenuTypeEnum.Menu, CreateTime=DateTime.Parse("2022-02-10 00:00:00"), OrderNo=112 },
// 胶料快检记录(紧接实验标准之后)
new SysMenu{ Id=1300150011201, Pid=1300150000101, Title="胶料快检记录", Path="/xslmes/rubberQuickTestRecord", Name="rubberQuickTestRecord", Component="RubberQuickTestRecordListView", Icon="&#xe7de;", Type=MenuTypeEnum.Menu, CreateTime=DateTime.Parse("2022-02-10 00:00:00"), OrderNo=113 },
// 密炼计划
new SysMenu{ Id=1300150011401, Pid=1300150000101, Title="密炼计划", Path="/xslmes/mesXslMixingProductionPlan", Name="mesXslMixingProductionPlan", Component="MixingProductionPlanListView", Icon="&#xe7ce;", Type=MenuTypeEnum.Menu, CreateTime=DateTime.Parse("2022-02-10 00:00:00"), OrderNo=114 },
#endregion

View File

@@ -34,6 +34,7 @@ public class SysTenantMenuSeedData : ISqlSugarEntitySeedData<SysTenantMenu>
new SysTenantMenu(){ TenantId=1300000000001,MenuId=1300150011101},
new SysTenantMenu(){ TenantId=1300000000001,MenuId=1300150011201},
new SysTenantMenu(){ TenantId=1300000000001,MenuId=1300150011301},
new SysTenantMenu(){ TenantId=1300000000001,MenuId=1300150011401},
new SysTenantMenu(){ TenantId=1300000000001,MenuId=1300200012101},
new SysTenantMenu(){ TenantId=1300000000001,MenuId=1300200012111},
new SysTenantMenu(){ TenantId=1300000000001,MenuId=1300200012121},

View File

@@ -270,6 +270,8 @@ namespace YY.Admin.Core.SqlSugar
EnsureBaselineSysMenuSeed(db, config);
// 旧库升级:按种子补全缺失菜单及租户/角色授权(仅插入缺失项)
EnsureIncrementalDesktopMenuSeed(db, config);
// 旧库升级:胶料快检记录菜单名称与排序
EnsureRubberQuickTestRecordMenuPatch(db, config);
}
/// <summary>
@@ -494,6 +496,46 @@ namespace YY.Admin.Core.SqlSugar
}
}
/// <summary>
/// 旧库升级:胶料快检记录改名为「胶料快检记录」,排序置于胶料快检实验标准之后。
/// </summary>
private static void EnsureRubberQuickTestRecordMenuPatch(SqlSugarScope db, DbConnectionConfig config)
{
try
{
if (!string.Equals(config.ConfigId.ToString(), SqlSugarConst.MainConfigId, StringComparison.Ordinal))
return;
if (config.DbType != DbType.Sqlite)
return;
var dbProvider = db.GetConnectionScope(config.ConfigId);
var menuEntityInfo = dbProvider.EntityMaintenance.GetEntityInfo(typeof(SysMenu));
if (!dbProvider.DbMaintenance.IsAnyTable(menuEntityInfo.DbTableName, false))
return;
const long quickTestRecordMenuId = 1300150011201;
const long mixingPlanMenuId = 1300150011401;
dbProvider.Updateable<SysMenu>()
.SetColumns(m => m.Title == "胶料快检记录")
.SetColumns(m => m.Path == "/xslmes/rubberQuickTestRecord")
.SetColumns(m => m.Name == "rubberQuickTestRecord")
.SetColumns(m => m.Component == "RubberQuickTestRecordListView")
.SetColumns(m => m.OrderNo == 113)
.Where(m => m.Id == quickTestRecordMenuId)
.ExecuteCommand();
dbProvider.Updateable<SysMenu>()
.SetColumns(m => m.OrderNo == 114)
.Where(m => m.Id == mixingPlanMenuId)
.ExecuteCommand();
}
catch
{
// 启动阶段不因菜单补丁失败而阻断
}
}
/// <summary>
/// 兼容旧库:补齐桌面端「登录设置」所需的 sys_config 配置项(升级前库可能缺少这些 code
/// </summary>

View File

@@ -0,0 +1,326 @@
using Microsoft.Extensions.Configuration;
using Prism.Events;
using System.IO;
using System.Net.Http;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Web;
using YY.Admin.Core;
using YY.Admin.Core.Entity;
using YY.Admin.Core.Events;
using YY.Admin.Core.Helper;
using YY.Admin.Core.Services;
namespace YY.Admin.Services.Service.MixingProductionPlan;
/// <summary>密炼生产计划MES 只读拉取 + 本地缓存,断网读缓存,联网刷新</summary>
public class MixingProductionPlanService : IMixingProductionPlanService, ISingletonDependency
{
private readonly IHttpClientFactory _httpClientFactory;
private readonly IConfiguration _configuration;
private readonly INetworkMonitor _networkMonitor;
private readonly IEventAggregator _eventAggregator;
private readonly ILoggerService _logger;
private readonly SemaphoreSlim _syncLock = new(1, 1);
private readonly object _cacheLock = new();
private readonly string _cacheFilePath;
private List<MesXslMixingProductionPlan> _localCache = new();
private static readonly JsonSerializerOptions _jsonOpts = new()
{
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
Converters = { new NullableDateTimeJsonConverter() }
};
public MixingProductionPlanService(
IHttpClientFactory httpClientFactory,
IConfiguration configuration,
INetworkMonitor networkMonitor,
IEventAggregator eventAggregator,
ILoggerService logger)
{
_httpClientFactory = httpClientFactory;
_configuration = configuration;
_networkMonitor = networkMonitor;
_eventAggregator = eventAggregator;
_logger = logger;
var appDataDir = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"YY.Admin", "sync-cache");
Directory.CreateDirectory(appDataDir);
_cacheFilePath = Path.Combine(appDataDir, "mes-xsl-mixing-production-plan-cache.json");
LoadCacheFromDisk();
_logger.Information($"[密炼计划] 服务初始化,缓存={_localCache.Count},在线={_networkMonitor.IsOnline}");
_networkMonitor.StatusChanged += OnNetworkStatusChanged;
if (_networkMonitor.IsOnline)
_ = Task.Run(() => SyncFromRemoteAsync(CancellationToken.None));
}
private string BaseUrl => (_configuration.GetValue<string>("JeecgIntegration:BaseUrl") ?? "http://localhost:8080/jeecg-boot").TrimEnd('/');
private int DefaultTenantId => (int?)_configuration.GetValue<long?>("JeecgIntegration:DefaultTenantId") ?? 1002;
private HttpClient CreateClient() => _httpClientFactory.CreateClient("JeecgApi");
public async Task<MixingProductionPlanPageResult> PageAsync(
int pageNo, int pageSize,
DateTime? planDateFrom = null,
DateTime? planDateTo = null,
string? machineName = null,
int? shiftFlag = null,
string? planNo = null,
string? materialName = null,
CancellationToken ct = default)
{
if (_networkMonitor.IsOnline)
{
try
{
await SyncFromRemoteAsync(ct).ConfigureAwait(false);
}
catch (Exception ex)
{
_logger.Warning($"[密炼计划] 列表拉取失败,使用本地缓存:{ex.Message}");
}
}
List<MesXslMixingProductionPlan> source;
lock (_cacheLock)
source = _localCache.Select(Clone).ToList();
var filtered = ApplyFilters(source, planDateFrom, planDateTo, machineName, shiftFlag, planNo, materialName);
var total = filtered.Count;
var records = filtered
.Skip(Math.Max(0, (pageNo - 1) * pageSize))
.Take(pageSize)
.ToList();
return new MixingProductionPlanPageResult(records, total, pageNo, pageSize);
}
public async Task<List<MesXslMixingProductionPlan>> GetAllCachedAsync(CancellationToken ct = default)
{
if (_networkMonitor.IsOnline)
{
try
{
await SyncFromRemoteAsync(ct).ConfigureAwait(false);
}
catch (Exception ex)
{
_logger.Warning($"[密炼计划] 全量拉取失败,使用本地缓存:{ex.Message}");
}
}
lock (_cacheLock)
return _localCache.Select(Clone).ToList();
}
public async Task<bool> SyncFromRemoteAsync(CancellationToken ct = default)
{
await _syncLock.WaitAsync(ct).ConfigureAwait(false);
try
{
if (!_networkMonitor.IsOnline)
return false;
var all = new List<MesXslMixingProductionPlan>();
int pageNo = 1;
const int pageSize = 500;
while (true)
{
var query = HttpUtility.ParseQueryString(string.Empty);
query["pageNo"] = pageNo.ToString();
query["pageSize"] = pageSize.ToString();
query["tenantId"] = DefaultTenantId.ToString();
var url = $"{BaseUrl}/xslmes/mesXslMixingProductionPlan/anon/list?{query}";
using var client = CreateClient();
var resp = await client.GetAsync(url, ct).ConfigureAwait(false);
resp.EnsureSuccessStatusCode();
var json = await resp.Content.ReadAsStringAsync(ct).ConfigureAwait(false);
using var doc = JsonDocument.Parse(json);
if (!doc.RootElement.TryGetProperty("result", out var resultEl)) break;
var page = resultEl.GetProperty("records")
.Deserialize<List<MesXslMixingProductionPlan>>(_jsonOpts) ?? new();
all.AddRange(page);
long total = 0;
if (resultEl.TryGetProperty("total", out var totalEl)) total = totalEl.GetInt64();
if (all.Count >= total || page.Count < pageSize) break;
pageNo++;
}
List<MesXslMixingProductionPlan> localSnapshot;
lock (_cacheLock)
localSnapshot = _localCache.Select(Clone).ToList();
var (merged, stats) = MesReadOnlyCacheMergeHelper.Merge(
localSnapshot,
all,
x => x.Id,
IsPlanContentEqual,
Clone);
if (!stats.HasChanges)
{
_logger.Information($"[密炼计划] 与 MES 对比无差异,跳过更新 count={merged.Count}");
return false;
}
lock (_cacheLock)
{
_localCache = merged;
SaveCacheToDiskUnsafe();
}
_logger.Information(
$"[密炼计划] 差异同步完成 total={merged.Count} 新增={stats.Added} 变更={stats.Updated} 删除={stats.Removed}");
return true;
}
catch (Exception ex)
{
_logger.Warning($"[密炼计划] 远程同步失败:{ex.Message}");
throw;
}
finally
{
_syncLock.Release();
}
}
private void OnNetworkStatusChanged(bool isOnline)
{
if (!isOnline) return;
_ = Task.Run(async () =>
{
try
{
if (!await SyncFromRemoteAsync(CancellationToken.None).ConfigureAwait(false))
return;
_eventAggregator.GetEvent<MixingProductionPlanChangedEvent>()
.Publish(new MixingProductionPlanChangedPayload { Action = "reconnect" });
}
catch (Exception ex)
{
_logger.Warning($"[密炼计划] 重连同步失败:{ex.Message}");
}
});
}
private static bool IsPlanContentEqual(MesXslMixingProductionPlan a, MesXslMixingProductionPlan b) =>
string.Equals(GetPlanFingerprint(a), GetPlanFingerprint(b), StringComparison.Ordinal);
private static string GetPlanFingerprint(MesXslMixingProductionPlan x) =>
JsonSerializer.Serialize(Clone(x), _jsonOpts);
private static List<MesXslMixingProductionPlan> ApplyFilters(
List<MesXslMixingProductionPlan> source,
DateTime? planDateFrom,
DateTime? planDateTo,
string? machineName,
int? shiftFlag,
string? planNo,
string? materialName)
{
IEnumerable<MesXslMixingProductionPlan> q = source;
if (planDateFrom.HasValue)
q = q.Where(x => x.PlanDate?.Date >= planDateFrom.Value.Date);
if (planDateTo.HasValue)
q = q.Where(x => x.PlanDate?.Date <= planDateTo.Value.Date);
if (!string.IsNullOrWhiteSpace(machineName))
q = q.Where(x => (x.MachineName ?? "").Contains(machineName.Trim(), StringComparison.OrdinalIgnoreCase));
if (shiftFlag.HasValue && shiftFlag.Value > 0)
q = q.Where(x => x.ShiftFlag == shiftFlag.Value);
if (!string.IsNullOrWhiteSpace(planNo))
q = q.Where(x => (x.PlanNo ?? "").Contains(planNo.Trim(), StringComparison.OrdinalIgnoreCase));
if (!string.IsNullOrWhiteSpace(materialName))
q = q.Where(x => (x.MaterialName ?? "").Contains(materialName.Trim(), StringComparison.OrdinalIgnoreCase));
return q
.OrderByDescending(x => x.PlanDate ?? DateTime.MinValue)
.ThenBy(x => x.SortNo ?? int.MaxValue)
.ThenBy(x => x.MachineName)
.ToList();
}
private void LoadCacheFromDisk()
{
try
{
if (!File.Exists(_cacheFilePath)) return;
_localCache = JsonSerializer.Deserialize<List<MesXslMixingProductionPlan>>(
File.ReadAllText(_cacheFilePath), _jsonOpts) ?? new();
}
catch
{
_localCache = new();
}
}
private void SaveCacheToDiskUnsafe() =>
File.WriteAllText(_cacheFilePath, JsonSerializer.Serialize(_localCache, _jsonOpts));
private static MesXslMixingProductionPlan Clone(MesXslMixingProductionPlan x) => new()
{
Id = x.Id,
SortNo = x.SortNo,
MachineId = x.MachineId,
MachineName = x.MachineName,
ShiftFlag = x.ShiftFlag,
PlanDate = x.PlanDate,
PlanNo = x.PlanNo,
PlanId = x.PlanId,
PlanType = x.PlanType,
SourceOrderId = x.SourceOrderId,
MaterialId = x.MaterialId,
MaterialName = x.MaterialName,
OrderNo = x.OrderNo,
OrderDate = x.OrderDate,
FormulaName = x.FormulaName,
PlanWeight = x.PlanWeight,
PlannedCarCount = x.PlannedCarCount,
ScheduledCarCount = x.ScheduledCarCount,
FinishedCarCount = x.FinishedCarCount,
PlanCount = x.PlanCount,
Remark = x.Remark,
TenantId = x.TenantId,
SysOrgCode = x.SysOrgCode,
CreateBy = x.CreateBy,
CreateTime = x.CreateTime,
UpdateBy = x.UpdateBy,
UpdateTime = x.UpdateTime,
DelFlag = x.DelFlag
};
private sealed class NullableDateTimeJsonConverter : JsonConverter<DateTime?>
{
private static readonly string[] Formats =
[
"yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm:ss.fff",
"yyyy-MM-ddTHH:mm:ss", "yyyy-MM-ddTHH:mm:ss.fff",
"yyyy-MM-ddTHH:mm:ssZ", "yyyy-MM-ddTHH:mm:ss.fffZ",
"yyyy-MM-dd"
];
public override DateTime? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.Null) return null;
if (reader.TokenType == JsonTokenType.String)
{
var raw = reader.GetString();
if (string.IsNullOrWhiteSpace(raw)) return null;
if (DateTime.TryParseExact(raw, Formats, System.Globalization.CultureInfo.InvariantCulture,
System.Globalization.DateTimeStyles.AssumeLocal, out var dt)) return dt;
if (DateTime.TryParse(raw, out var fb)) return fb;
}
throw new JsonException($"无法转换为 DateTime?token={reader.TokenType}");
}
public override void Write(Utf8JsonWriter writer, DateTime? value, JsonSerializerOptions options)
{
if (value.HasValue) writer.WriteStringValue(value.Value.ToString("yyyy-MM-dd HH:mm:ss"));
else writer.WriteNullValue();
}
}
}

View File

@@ -0,0 +1,63 @@
using Prism.Events;
using System.Text.Json;
using YY.Admin.Core;
using YY.Admin.Core.Events;
using YY.Admin.Core.Services;
namespace YY.Admin.Services.Service.MixingProductionPlan;
public class MixingProductionPlanSyncCoordinator : ISingletonDependency
{
private readonly IEventAggregator _eventAggregator;
private readonly ILoggerService _logger;
public MixingProductionPlanSyncCoordinator(
IEventAggregator eventAggregator,
SyncPollManager pollManager,
ILoggerService logger)
{
_eventAggregator = eventAggregator;
_logger = logger;
_eventAggregator.GetEvent<RemoteCommandReceivedEvent>()
.Subscribe(OnRemoteCommand, ThreadOption.BackgroundThread);
pollManager.Register("密炼计划", () =>
{
_eventAggregator.GetEvent<MixingProductionPlanChangedEvent>()
.Publish(new MixingProductionPlanChangedPayload { Action = "poll" });
return Task.CompletedTask;
});
_logger.Information("[密炼计划] MixingProductionPlanSyncCoordinator 已启动");
}
private void OnRemoteCommand(RemoteCommandPayload payload)
{
try
{
var json = payload.CommandJson ?? string.Empty;
if (string.IsNullOrWhiteSpace(json)) return;
using var doc = JsonDocument.Parse(json);
if (!doc.RootElement.TryGetProperty("cmd", out var cmdEl)) return;
if (!cmdEl.GetString()?.Equals("MIXING_PRODUCTION_PLAN_CHANGED", StringComparison.OrdinalIgnoreCase) ?? true)
return;
doc.RootElement.TryGetProperty("action", out var actionEl);
doc.RootElement.TryGetProperty("mixingProductionPlanId", out var idEl);
var changed = new MixingProductionPlanChangedPayload
{
Action = actionEl.GetString() ?? string.Empty,
MixingProductionPlanId = idEl.ValueKind == JsonValueKind.String ? idEl.GetString() : null
};
_logger.Information($"[密炼计划] STOMP action={changed.Action}, id={changed.MixingProductionPlanId}");
_eventAggregator.GetEvent<MixingProductionPlanChangedEvent>().Publish(changed);
}
catch (Exception ex)
{
_logger.Warning($"[密炼计划] 处理 STOMP 命令失败:{ex.Message}");
}
}
}

View File

@@ -36,68 +36,11 @@ public class RubberQuickTestOperationService : IRubberQuickTestOperationService,
}
private string BaseUrl => (_configuration.GetValue<string>("JeecgIntegration:BaseUrl") ?? "http://localhost:8080/jeecg-boot").TrimEnd('/');
private int DefaultTenantId => (int?)_configuration.GetValue<long?>("JeecgIntegration:DefaultTenantId") ?? 1002;
public async Task<List<MesXslMixingProductionPlan>> GetMixingProductionPlansAsync(CancellationToken ct = default)
{
if (!_networkMonitor.IsOnline)
throw new InvalidOperationException("网络未连接,无法加载密炼生产计划");
var result = new List<MesXslMixingProductionPlan>();
int pageNo = 1;
const int pageSize = 500;
while (true)
{
var url = $"{BaseUrl}/xslmes/mesXslMixingProductionPlan/anon/list?pageNo={pageNo}&pageSize={pageSize}&tenantId={DefaultTenantId}";
using var client = _httpClientFactory.CreateClient("JeecgApi");
var resp = await client.GetAsync(url, ct).ConfigureAwait(false);
resp.EnsureSuccessStatusCode();
var json = await resp.Content.ReadAsStringAsync(ct).ConfigureAwait(false);
using var doc = JsonDocument.Parse(json);
if (!doc.RootElement.TryGetProperty("result", out var resultEl)) break;
if (resultEl.TryGetProperty("records", out var recordsEl))
{
var page = recordsEl.Deserialize<List<MesXslMixingProductionPlan>>(_jsonOpts);
if (page != null) result.AddRange(page);
}
long total = 0;
if (resultEl.TryGetProperty("total", out var totalEl)) total = totalEl.GetInt64();
if (result.Count >= total || (resultEl.TryGetProperty("records", out var r2) && r2.GetArrayLength() < pageSize)) break;
pageNo++;
}
_logger.Information($"[快检记录] 加载密炼生产计划 {result.Count} 条");
return result;
}
public async Task<MesXslRubberQuickTestStd?> GetStdByRubberMaterialNameAsync(string rubberMaterialName, CancellationToken ct = default)
{
if (string.IsNullOrWhiteSpace(rubberMaterialName))
return null;
if (!_networkMonitor.IsOnline)
throw new InvalidOperationException("网络未连接,无法加载实验标准");
var encoded = Uri.EscapeDataString(rubberMaterialName.Trim());
var url = $"{BaseUrl}/xslmes/mesXslRubberQuickTestStd/anon/queryByRubberMaterialName?rubberMaterialName={encoded}";
using var client = _httpClientFactory.CreateClient("JeecgApi");
var resp = await client.GetAsync(url, ct).ConfigureAwait(false);
var json = await resp.Content.ReadAsStringAsync(ct).ConfigureAwait(false);
using var doc = JsonDocument.Parse(json);
if (!doc.RootElement.TryGetProperty("success", out var successEl) || !successEl.GetBoolean())
{
var msg = doc.RootElement.TryGetProperty("message", out var msgEl) ? msgEl.GetString() : "查询实验标准失败";
_logger.Warning($"[快检记录] 实验标准查询失败: {msg}");
return null;
}
if (!doc.RootElement.TryGetProperty("result", out var resultEl) || resultEl.ValueKind == JsonValueKind.Null)
return null;
return resultEl.Deserialize<MesXslRubberQuickTestStd>(_jsonOpts);
}
public async Task<string?> SaveRecordAsync(MesXslRubberQuickTestRecord record, CancellationToken ct = default)
{
if (!_networkMonitor.IsOnline)
throw new InvalidOperationException("网络未连接,无法保存快检记录");
throw new InvalidOperationException("网络未连接,无法保存胶料快检记录");
var url = $"{BaseUrl}/xslmes/mesXslRubberQuickTestRecord/anon/add";
using var client = _httpClientFactory.CreateClient("JeecgApi");
@@ -111,7 +54,19 @@ public class RubberQuickTestOperationService : IRubberQuickTestOperationService,
var msg = doc.RootElement.TryGetProperty("message", out var msgEl) ? msgEl.GetString() : "保存失败";
throw new InvalidOperationException(msg ?? "保存失败");
}
_logger.Information($"[快检记录] 保存成功 recordNo={record.RecordNo}");
return doc.RootElement.TryGetProperty("message", out var m) ? m.GetString() : "保存成功";
string? recordNo = null;
if (doc.RootElement.TryGetProperty("result", out var resultEl))
{
if (resultEl.ValueKind == JsonValueKind.String)
recordNo = resultEl.GetString();
else if (resultEl.ValueKind == JsonValueKind.Object
&& resultEl.TryGetProperty("recordNo", out var noEl))
recordNo = noEl.GetString();
}
recordNo ??= record.RecordNo;
record.RecordNo = recordNo;
_logger.Information($"[胶料快检记录] 保存成功 recordNo={recordNo}");
return recordNo;
}
}

View File

@@ -0,0 +1,502 @@
using Microsoft.Extensions.Configuration;
using Prism.Events;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Web;
using YY.Admin.Core;
using YY.Admin.Core.Entity;
using YY.Admin.Core.Events;
using YY.Admin.Core.Services;
namespace YY.Admin.Services.Service.RubberQuickTest;
public class RubberQuickTestRecordService : IRubberQuickTestRecordService, ISingletonDependency
{
private readonly IHttpClientFactory _httpClientFactory;
private readonly IConfiguration _configuration;
private readonly INetworkMonitor _networkMonitor;
private readonly IEventAggregator _eventAggregator;
private readonly ILoggerService _logger;
private readonly SemaphoreSlim _syncLock = new(1, 1);
private readonly object _cacheLock = new();
private readonly string _cacheFilePath;
private List<RubberQuickTestRecordLocalItem> _localItems = new();
private static readonly JsonSerializerOptions _jsonOpts = new()
{
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
Converters = { new NullableDateTimeJsonConverter() }
};
public RubberQuickTestRecordService(
IHttpClientFactory httpClientFactory,
IConfiguration configuration,
INetworkMonitor networkMonitor,
IEventAggregator eventAggregator,
ILoggerService logger)
{
_httpClientFactory = httpClientFactory;
_configuration = configuration;
_networkMonitor = networkMonitor;
_eventAggregator = eventAggregator;
_logger = logger;
var appDataDir = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"YY.Admin", "sync-cache");
Directory.CreateDirectory(appDataDir);
_cacheFilePath = Path.Combine(appDataDir, "rubber-quick-test-record-items.json");
LoadCacheFromDisk();
_logger.Information($"[快检记录同步] 初始化完成,本地记录={_localItems.Count}");
_networkMonitor.StatusChanged += OnNetworkStatusChanged;
if (_networkMonitor.IsOnline)
_ = Task.Run(() => PushPendingAsync(CancellationToken.None));
}
private string BaseUrl => (_configuration.GetValue<string>("JeecgIntegration:BaseUrl") ?? "http://localhost:8080/jeecg-boot").TrimEnd('/');
private int DefaultTenantId => (int?)_configuration.GetValue<long?>("JeecgIntegration:DefaultTenantId") ?? 1002;
private HttpClient CreateClient() => _httpClientFactory.CreateClient("JeecgApi");
public async Task<RubberQuickTestRecordPageResult> PageAsync(
int pageNo, int pageSize,
string? filterRecordNo = null,
string? filterRubberMaterialName = null,
string? filterPlanNo = null,
CancellationToken ct = default)
{
var rows = await BuildAllRowsAsync(ct).ConfigureAwait(false);
var filtered = ApplyFilters(rows, filterRecordNo, filterRubberMaterialName, filterPlanNo);
var total = filtered.Count;
var records = filtered
.OrderByDescending(r => r.InspectDate ?? DateTime.MinValue)
.Skip(Math.Max(0, (pageNo - 1) * pageSize))
.Take(pageSize)
.ToList();
return new RubberQuickTestRecordPageResult(records, total, pageNo, pageSize);
}
public async Task<MesXslRubberQuickTestRecord?> GetByIdAsync(string id, CancellationToken ct = default)
{
RubberQuickTestRecordLocalItem? local = null;
lock (_cacheLock)
{
local = _localItems.FirstOrDefault(x =>
string.Equals(x.LocalId, id, StringComparison.OrdinalIgnoreCase)
|| string.Equals(x.MesId, id, StringComparison.OrdinalIgnoreCase)
|| string.Equals(x.Record.RecordNo, id, StringComparison.OrdinalIgnoreCase));
}
if (local != null)
return CloneRecord(local.Record);
if (_networkMonitor.IsOnline)
{
try
{
var url = $"{BaseUrl}/xslmes/mesXslRubberQuickTestRecord/anon/queryById?id={Uri.EscapeDataString(id)}&tenantId={DefaultTenantId}";
using var client = CreateClient();
var resp = await client.GetAsync(url, ct).ConfigureAwait(false);
if (resp.IsSuccessStatusCode)
{
var json = await resp.Content.ReadAsStringAsync(ct).ConfigureAwait(false);
using var doc = JsonDocument.Parse(json);
if (doc.RootElement.TryGetProperty("result", out var resultEl))
return resultEl.Deserialize<MesXslRubberQuickTestRecord>(_jsonOpts);
}
}
catch (Exception ex)
{
_logger.Warning($"[快检记录详情] 远端查询异常 id={id}: {ex.Message}");
}
}
return null;
}
public RubberQuickTestRecordLocalItem? GetByLocalId(string localId)
{
lock (_cacheLock)
{
var item = _localItems.FirstOrDefault(x => string.Equals(x.LocalId, localId, StringComparison.OrdinalIgnoreCase));
return item == null ? null : CloneLocalItem(item);
}
}
public async Task<RubberQuickTestRecordSaveResult> SaveAsync(MesXslRubberQuickTestRecord entity, CancellationToken ct = default)
{
var record = CloneRecord(entity);
record.CreateTime ??= DateTime.Now;
record.InspectTime ??= record.CreateTime;
var item = new RubberQuickTestRecordLocalItem
{
LocalId = Guid.NewGuid().ToString("N"),
LocalCreateTime = DateTime.Now,
SyncStatus = "Pending",
Record = record
};
if (_networkMonitor.IsOnline)
{
try
{
var recordNo = await RemoteAddAsync(record, ct).ConfigureAwait(false);
if (!string.IsNullOrWhiteSpace(recordNo))
{
item.Record.RecordNo = recordNo;
item.SyncStatus = "Synced";
}
}
catch (Exception ex)
{
item.SyncStatus = "Failed";
item.SyncError = ex.Message;
_logger.Warning($"[快检记录新增] 远端失败,保留本地:{ex.Message}");
}
}
lock (_cacheLock)
{
_localItems.Add(CloneLocalItem(item));
SaveCacheToDiskUnsafe();
}
_eventAggregator.GetEvent<RubberQuickTestRecordChangedEvent>()
.Publish(new RubberQuickTestRecordChangedPayload { Action = "add", RecordId = item.LocalId });
return new RubberQuickTestRecordSaveResult
{
LocalId = item.LocalId,
SyncStatus = item.SyncStatus,
Record = CloneRecord(item.Record)
};
}
public bool DeleteFailedLocal(string localId)
{
if (string.IsNullOrWhiteSpace(localId)) return false;
bool removed;
lock (_cacheLock)
{
var item = _localItems.FirstOrDefault(x =>
string.Equals(x.LocalId, localId.Trim(), StringComparison.OrdinalIgnoreCase));
if (item == null || !string.Equals(item.SyncStatus, "Failed", StringComparison.OrdinalIgnoreCase))
return false;
removed = _localItems.Remove(item);
if (removed)
SaveCacheToDiskUnsafe();
}
if (!removed) return false;
_eventAggregator.GetEvent<RubberQuickTestRecordChangedEvent>()
.Publish(new RubberQuickTestRecordChangedPayload { Action = "delete", RecordId = localId });
_logger.Information($"[快检记录删除] 已删除同步失败本地记录 localId={localId}");
return true;
}
public string GenerateRecordNo(string rubberMaterialName)
{
var dateStr = DateTime.Now.ToString("yyyyMMdd");
var material = rubberMaterialName.Trim();
int maxSeq = 0;
lock (_cacheLock)
{
foreach (var item in _localItems)
{
var no = item.Record.RecordNo;
if (string.IsNullOrWhiteSpace(no) || !no.StartsWith(dateStr, StringComparison.Ordinal) || !no.EndsWith(material, StringComparison.Ordinal))
continue;
var seqPart = no.Substring(dateStr.Length, Math.Min(4, no.Length - dateStr.Length - material.Length));
if (int.TryParse(seqPart, out var seq))
maxSeq = Math.Max(maxSeq, seq);
}
}
return dateStr + (maxSeq + 1).ToString("D4") + material;
}
private async Task<List<RubberQuickTestRecordListRow>> BuildAllRowsAsync(CancellationToken ct)
{
var rows = new List<RubberQuickTestRecordListRow>();
var seenRecordNos = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
lock (_cacheLock)
{
foreach (var item in _localItems)
{
rows.Add(ToListRow(item));
if (!string.IsNullOrWhiteSpace(item.Record.RecordNo))
seenRecordNos.Add(item.Record.RecordNo);
}
}
if (_networkMonitor.IsOnline)
{
try
{
foreach (var remote in await FetchRemoteListAsync(ct).ConfigureAwait(false))
{
if (!string.IsNullOrWhiteSpace(remote.RecordNo) && seenRecordNos.Contains(remote.RecordNo))
continue;
rows.Add(ToListRow(remote, "Synced", remote.Id));
}
}
catch (Exception ex)
{
_logger.Warning($"[快检记录列表] 远端拉取失败:{ex.Message}");
}
}
return rows;
}
private static RubberQuickTestRecordListRow ToListRow(RubberQuickTestRecordLocalItem item) =>
ToListRow(item.Record, item.SyncStatus, item.MesId, item.LocalId);
private static RubberQuickTestRecordListRow ToListRow(
MesXslRubberQuickTestRecord r,
string syncStatus,
string? mesId = null,
string? localId = null) => new()
{
LocalId = localId,
MesId = mesId ?? r.Id,
RecordNo = r.RecordNo,
ProductionDate = r.ProductionDate,
ProdEquipmentName = r.ProdEquipmentName,
WorkShiftDisplay = r.WorkShiftText ?? r.WorkShift,
ProductionPlanNo = r.ProductionPlanNo,
RubberMaterialName = r.RubberMaterialName,
StdName = r.StdName,
TestMethodName = r.TestMethodName,
QuickTestTypeName = r.QuickTestTypeName,
TrainNo = r.TrainNo,
InspectTimes = r.InspectTimes,
InspectorRealname = r.InspectorRealname,
InspectDate = r.CreateTime ?? r.InspectTime,
InspectResultDisplay = r.InspectResultText ?? (r.InspectResult == "1" ? "合格" : r.InspectResult == "0" ? "不合格" : ""),
SyncStatus = syncStatus
};
private async Task<string?> RemoteAddAsync(MesXslRubberQuickTestRecord entity, CancellationToken ct)
{
var url = $"{BaseUrl}/xslmes/mesXslRubberQuickTestRecord/anon/add?tenantId={DefaultTenantId}";
var payload = CloneRecord(entity);
payload.Id = null;
using var client = CreateClient();
var body = JsonSerializer.Serialize(payload, _jsonOpts);
using var content = new StringContent(body, Encoding.UTF8, "application/json");
var resp = await client.PostAsync(url, content, ct).ConfigureAwait(false);
var json = await resp.Content.ReadAsStringAsync(ct).ConfigureAwait(false);
using var doc = JsonDocument.Parse(json);
if (!doc.RootElement.TryGetProperty("success", out var successEl) || !successEl.GetBoolean())
{
var msg = doc.RootElement.TryGetProperty("message", out var msgEl) ? msgEl.GetString() : "保存失败";
throw new InvalidOperationException(msg ?? "保存失败");
}
if (doc.RootElement.TryGetProperty("result", out var resultEl) && resultEl.ValueKind == JsonValueKind.String)
return resultEl.GetString();
return entity.RecordNo;
}
private async Task<List<MesXslRubberQuickTestRecord>> FetchRemoteListAsync(CancellationToken ct)
{
var query = HttpUtility.ParseQueryString(string.Empty);
query["pageNo"] = "1";
query["pageSize"] = "10000";
query["tenantId"] = DefaultTenantId.ToString();
var url = $"{BaseUrl}/xslmes/mesXslRubberQuickTestRecord/anon/list?{query}";
using var client = CreateClient();
var resp = await client.GetAsync(url, ct).ConfigureAwait(false);
resp.EnsureSuccessStatusCode();
var json = await resp.Content.ReadAsStringAsync(ct).ConfigureAwait(false);
using var doc = JsonDocument.Parse(json);
var result = doc.RootElement.GetProperty("result");
return result.GetProperty("records").Deserialize<List<MesXslRubberQuickTestRecord>>(_jsonOpts) ?? new();
}
private void OnNetworkStatusChanged(bool isOnline)
{
if (!isOnline) return;
_ = Task.Run(() => PushPendingAsync(CancellationToken.None));
}
private async Task PushPendingAsync(CancellationToken ct)
{
if (!await _syncLock.WaitAsync(0, ct).ConfigureAwait(false)) return;
try
{
List<RubberQuickTestRecordLocalItem> pending;
lock (_cacheLock)
{
pending = _localItems.Where(x => x.SyncStatus != "Synced").Select(CloneLocalItem).ToList();
}
foreach (var item in pending)
{
if (!_networkMonitor.IsOnline) break;
try
{
var recordNo = await RemoteAddAsync(item.Record, ct).ConfigureAwait(false);
lock (_cacheLock)
{
var target = _localItems.FirstOrDefault(x => x.LocalId == item.LocalId);
if (target == null) continue;
if (!string.IsNullOrWhiteSpace(recordNo))
target.Record.RecordNo = recordNo;
target.SyncStatus = "Synced";
target.SyncError = null;
SaveCacheToDiskUnsafe();
}
}
catch (Exception ex)
{
lock (_cacheLock)
{
var target = _localItems.FirstOrDefault(x => x.LocalId == item.LocalId);
if (target != null)
{
target.SyncStatus = "Failed";
target.SyncError = ex.Message;
SaveCacheToDiskUnsafe();
}
}
}
}
}
finally
{
_syncLock.Release();
}
}
private static List<RubberQuickTestRecordListRow> ApplyFilters(
List<RubberQuickTestRecordListRow> source,
string? filterRecordNo,
string? filterRubberMaterialName,
string? filterPlanNo)
{
IEnumerable<RubberQuickTestRecordListRow> q = source;
if (!string.IsNullOrWhiteSpace(filterRecordNo))
q = q.Where(r => (r.RecordNo ?? "").Contains(filterRecordNo.Trim(), StringComparison.OrdinalIgnoreCase));
if (!string.IsNullOrWhiteSpace(filterRubberMaterialName))
q = q.Where(r => (r.RubberMaterialName ?? "").Contains(filterRubberMaterialName.Trim(), StringComparison.OrdinalIgnoreCase));
if (!string.IsNullOrWhiteSpace(filterPlanNo))
q = q.Where(r => (r.ProductionPlanNo ?? "").Contains(filterPlanNo.Trim(), StringComparison.OrdinalIgnoreCase));
return q.ToList();
}
private void LoadCacheFromDisk()
{
try
{
if (!File.Exists(_cacheFilePath)) return;
var data = JsonSerializer.Deserialize<List<RubberQuickTestRecordLocalItem>>(File.ReadAllText(_cacheFilePath), _jsonOpts);
_localItems = data ?? new();
}
catch { _localItems = new(); }
}
private void SaveCacheToDiskUnsafe() =>
File.WriteAllText(_cacheFilePath, JsonSerializer.Serialize(_localItems, _jsonOpts));
private static RubberQuickTestRecordLocalItem CloneLocalItem(RubberQuickTestRecordLocalItem src) => new()
{
LocalId = src.LocalId,
MesId = src.MesId,
SyncStatus = src.SyncStatus,
SyncError = src.SyncError,
LocalCreateTime = src.LocalCreateTime,
Record = CloneRecord(src.Record)
};
private static MesXslRubberQuickTestRecord CloneRecord(MesXslRubberQuickTestRecord src) => new()
{
Id = src.Id,
RecordNo = src.RecordNo,
RubberMaterialId = src.RubberMaterialId,
RubberMaterialName = src.RubberMaterialName,
StdId = src.StdId,
StdName = src.StdName,
TestMethodId = src.TestMethodId,
TestMethodName = src.TestMethodName,
ProdEquipmentLedgerId = src.ProdEquipmentLedgerId,
ProdEquipmentName = src.ProdEquipmentName,
ProductionDate = src.ProductionDate,
TrainNo = src.TrainNo,
WorkShift = src.WorkShift,
InspectTimes = src.InspectTimes,
InspectTime = src.InspectTime,
InspectorUserId = src.InspectorUserId,
InspectorUsername = src.InspectorUsername,
InspectorRealname = src.InspectorRealname,
QuickTestTypeId = src.QuickTestTypeId,
QuickTestTypeName = src.QuickTestTypeName,
InspectResult = src.InspectResult,
ProductionPlanNo = src.ProductionPlanNo,
CreateTime = src.CreateTime,
StdLineList = src.StdLineList?.Select(l => new MesXslRubberQuickTestRecordStdLine
{
Id = l.Id, RecordId = l.RecordId, DataPointId = l.DataPointId, PointName = l.PointName,
LowerLimit = l.LowerLimit, UpperLimit = l.UpperLimit, LowerWarn = l.LowerWarn,
UpperWarn = l.UpperWarn, TargetValue = l.TargetValue, SortNo = l.SortNo
}).ToList(),
RawLineList = src.RawLineList?.Select(l => new MesXslRubberQuickTestRecordRawLine
{
Id = l.Id, RecordId = l.RecordId, RowNo = l.RowNo, DataPointId = l.DataPointId,
InspectItem = l.InspectItem, LowerLimit = l.LowerLimit, UpperLimit = l.UpperLimit,
InspectValue = l.InspectValue, RowInspectResult = l.RowInspectResult, SortNo = l.SortNo
}).ToList(),
ChartPointList = src.ChartPointList?.Select(p => new MesXslRubberQuickTestRecordChartPoint
{
Id = p.Id, RecordId = p.RecordId, TimeMin = p.TimeMin, UpperTemp = p.UpperTemp,
LowerTemp = p.LowerTemp, TorqueS = p.TorqueS, SortNo = p.SortNo
}).ToList(),
WorkShiftText = src.WorkShiftText,
InspectResultText = src.InspectResultText
};
private sealed class NullableDateTimeJsonConverter : JsonConverter<DateTime?>
{
private static readonly string[] SupportedFormats =
[
"yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm:ss.fff",
"yyyy-MM-ddTHH:mm:ss", "yyyy-MM-ddTHH:mm:ss.fff",
"yyyy-MM-ddTHH:mm:ssZ", "yyyy-MM-ddTHH:mm:ss.fffZ",
"yyyy-MM-dd"
];
public override DateTime? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.Null) return null;
if (reader.TokenType == JsonTokenType.String)
{
var raw = reader.GetString();
if (string.IsNullOrWhiteSpace(raw)) return null;
if (DateTime.TryParseExact(raw, SupportedFormats,
System.Globalization.CultureInfo.InvariantCulture,
System.Globalization.DateTimeStyles.AssumeLocal, out var exact)) return exact;
if (DateTime.TryParse(raw, out var fallback)) return fallback;
}
throw new JsonException($"无法转换为 DateTime?token={reader.TokenType}");
}
public override void Write(Utf8JsonWriter writer, DateTime? value, JsonSerializerOptions options)
{
if (value == null) writer.WriteNullValue();
else writer.WriteStringValue(value.Value.ToString("yyyy-MM-dd HH:mm:ss"));
}
}
}

View File

@@ -8,6 +8,7 @@ using System.Web;
using YY.Admin.Core;
using YY.Admin.Core.Entity;
using YY.Admin.Core.Events;
using YY.Admin.Core.Helper;
using YY.Admin.Core.Services;
namespace YY.Admin.Services.Service.RubberQuickTestStd;
@@ -115,7 +116,7 @@ public class RubberQuickTestStdService : IRubberQuickTestStdService, ISingletonD
var entity = resultEl.Deserialize<MesXslRubberQuickTestStd>(_jsonOpts);
if (entity != null)
{
UpsertLocalCacheMain(entity);
UpsertIfChanged(entity);
return CloneMain(entity);
}
}
@@ -134,14 +135,50 @@ public class RubberQuickTestStdService : IRubberQuickTestStdService, ISingletonD
}
}
public async Task SyncFromRemoteAsync(CancellationToken ct = default)
public Task<List<MesXslRubberQuickTestStd>> GetAllCachedAsync(CancellationToken ct = default)
{
ct.ThrowIfCancellationRequested();
lock (_cacheLock)
return Task.FromResult(_localCache.Select(CloneMain).ToList());
}
public Task<MesXslRubberQuickTestStd?> GetCachedByIdAsync(string id, CancellationToken ct = default)
{
ct.ThrowIfCancellationRequested();
if (string.IsNullOrWhiteSpace(id)) return Task.FromResult<MesXslRubberQuickTestStd?>(null);
lock (_cacheLock)
{
var found = _localCache.FirstOrDefault(x => string.Equals(x.Id, id, StringComparison.OrdinalIgnoreCase));
return Task.FromResult(found != null ? CloneMain(found) : null);
}
}
public async Task<MesXslRubberQuickTestStd?> GetWithLinesAsync(string id, CancellationToken ct = default)
{
if (string.IsNullOrWhiteSpace(id)) return null;
var cached = await GetCachedByIdAsync(id, ct).ConfigureAwait(false);
if (cached?.LineList is { Count: > 0 })
return cached;
if (_networkMonitor.IsOnline)
{
var detail = await GetByIdAsync(id, ct).ConfigureAwait(false);
if (detail != null)
return detail;
}
return cached;
}
public async Task<bool> SyncFromRemoteAsync(CancellationToken ct = default)
{
await _syncLock.WaitAsync(ct).ConfigureAwait(false);
try
{
if (!_networkMonitor.IsOnline)
return;
return false;
var query = HttpUtility.ParseQueryString(string.Empty);
query["pageNo"] = "1";
@@ -158,16 +195,37 @@ public class RubberQuickTestStdService : IRubberQuickTestStdService, ISingletonD
var records = doc.RootElement.GetProperty("result").GetProperty("records")
.Deserialize<List<MesXslRubberQuickTestStd>>(_jsonOpts) ?? new();
List<MesXslRubberQuickTestStd> localSnapshot;
lock (_cacheLock)
localSnapshot = _localCache.Select(CloneMain).ToList();
var (merged, stats) = MesReadOnlyCacheMergeHelper.Merge(
localSnapshot,
records,
x => x.Id,
IsStdListContentEqual,
CloneMain,
MergeStdUpdated);
if (!stats.HasChanges)
{
_logger.Information($"[快检实验标准] 与 MES 对比无差异,跳过更新 count={merged.Count}");
return false;
}
lock (_cacheLock)
{
_localCache = records.Select(CloneMain).ToList();
_localCache = merged;
SaveCacheToDiskUnsafe();
}
_logger.Information($"[快检实验标准] 同步完成 count={records.Count}");
_logger.Information(
$"[快检实验标准] 差异同步完成 total={merged.Count} 新增={stats.Added} 变更={stats.Updated} 删除={stats.Removed}");
return true;
}
catch (Exception ex)
{
_logger.Warning($"[快检实验标准] 远程同步失败:{ex.Message}");
return false;
}
finally
{
@@ -180,7 +238,8 @@ public class RubberQuickTestStdService : IRubberQuickTestStdService, ISingletonD
if (!isOnline) return;
_ = Task.Run(async () =>
{
await SyncFromRemoteAsync(CancellationToken.None).ConfigureAwait(false);
if (!await SyncFromRemoteAsync(CancellationToken.None).ConfigureAwait(false))
return;
_eventAggregator.GetEvent<RubberQuickTestStdChangedEvent>()
.Publish(new RubberQuickTestStdChangedPayload { Action = "reconnect" });
});
@@ -202,19 +261,67 @@ public class RubberQuickTestStdService : IRubberQuickTestStdService, ISingletonD
return q.OrderByDescending(x => x.CreateTime ?? DateTime.MinValue).ToList();
}
private void UpsertLocalCacheMain(MesXslRubberQuickTestStd entity)
private bool UpsertIfChanged(MesXslRubberQuickTestStd entity)
{
if (string.IsNullOrWhiteSpace(entity.Id)) return;
if (string.IsNullOrWhiteSpace(entity.Id)) return false;
lock (_cacheLock)
{
var idx = _localCache.FindIndex(x => string.Equals(x.Id, entity.Id, StringComparison.OrdinalIgnoreCase));
var copy = CloneMain(entity);
if (idx >= 0) _localCache[idx] = copy;
else _localCache.Insert(0, copy);
if (idx >= 0)
{
if (IsStdDetailContentEqual(_localCache[idx], entity))
return false;
_localCache[idx] = CloneMain(entity);
}
else
{
_localCache.Insert(0, CloneMain(entity));
}
SaveCacheToDiskUnsafe();
return true;
}
}
private static bool IsStdListContentEqual(MesXslRubberQuickTestStd a, MesXslRubberQuickTestStd b) =>
string.Equals(GetStdListFingerprint(a), GetStdListFingerprint(b), StringComparison.Ordinal);
private static bool IsStdDetailContentEqual(MesXslRubberQuickTestStd a, MesXslRubberQuickTestStd b) =>
string.Equals(GetStdDetailFingerprint(a), GetStdDetailFingerprint(b), StringComparison.Ordinal);
private static string GetStdListFingerprint(MesXslRubberQuickTestStd x)
{
var snap = CloneMain(x);
snap.LineList = null;
return JsonSerializer.Serialize(snap, _jsonOpts);
}
private static string GetStdDetailFingerprint(MesXslRubberQuickTestStd x) =>
JsonSerializer.Serialize(CloneMain(x), _jsonOpts);
private static MesXslRubberQuickTestStd MergeStdUpdated(MesXslRubberQuickTestStd local, MesXslRubberQuickTestStd remote)
{
var copy = CloneMain(remote);
if ((copy.LineList == null || copy.LineList.Count == 0) && local.LineList is { Count: > 0 })
{
copy.LineList = local.LineList.Select(l => new MesXslRubberQuickTestStdLine
{
Id = l.Id,
StdId = l.StdId,
DataPointId = l.DataPointId,
PointName = l.PointName,
LowerLimit = l.LowerLimit,
UpperLimit = l.UpperLimit,
LowerWarn = l.LowerWarn,
UpperWarn = l.UpperWarn,
TargetValue = l.TargetValue,
SortNo = l.SortNo
}).ToList();
}
return copy;
}
private void UpsertLocalCacheMain(MesXslRubberQuickTestStd entity) => UpsertIfChanged(entity);
private void LoadCacheFromDisk()
{
try
@@ -238,6 +345,8 @@ public class RubberQuickTestStdService : IRubberQuickTestStdService, ISingletonD
StdName = x.StdName,
TestMethodId = x.TestMethodId,
TestMethodName = x.TestMethodName,
QuickTestTypeId = x.QuickTestTypeId,
QuickTestTypeName = x.QuickTestTypeName,
MixerType = x.MixerType,
RubberMaterialId = x.RubberMaterialId,
RubberMaterialName = x.RubberMaterialName,

View File

@@ -2,7 +2,6 @@ using Prism.Events;
using System.Text.Json;
using YY.Admin.Core;
using YY.Admin.Core.Events;
using YY.Admin.Core.Events;
namespace YY.Admin.Services.Service.RubberQuickTestStd;
@@ -21,8 +20,6 @@ public class RubberQuickTestStdSyncCoordinator : ISingletonDependency
_eventAggregator.GetEvent<RemoteCommandReceivedEvent>()
.Subscribe(OnRemoteCommand, ThreadOption.BackgroundThread);
_eventAggregator.GetEvent<NetworkStatusChangedEvent>()
.Subscribe(OnNetworkStatusChanged, ThreadOption.BackgroundThread);
pollManager.Register("胶料快检实验标准", () =>
{
@@ -34,14 +31,6 @@ public class RubberQuickTestStdSyncCoordinator : ISingletonDependency
_logger.Information("[快检实验标准] RubberQuickTestStdSyncCoordinator 已启动");
}
private void OnNetworkStatusChanged(NetworkStatusChangedPayload payload)
{
if (!payload.IsOnline) return;
_logger.Information("[快检实验标准] 网络恢复,触发补偿刷新");
_eventAggregator.GetEvent<RubberQuickTestStdChangedEvent>()
.Publish(new RubberQuickTestStdChangedPayload { Action = "reconnect" });
}
private void OnRemoteCommand(RemoteCommandPayload payload)
{
try

View File

@@ -178,6 +178,10 @@ public class StompWebSocketService : ISignalRService
await SendFrameAsync(
BuildSubscribeFrame("sub-mes-rubber-quick-test-stds", "/topic/sync/mes-rubber-quick-test-stds"),
cancellationToken).ConfigureAwait(false);
// 密炼生产计划变更:订阅 /topic/sync/mes-mixing-production-plans
await SendFrameAsync(
BuildSubscribeFrame("sub-mes-xsl-mixing-production-plan", "/topic/sync/mes-mixing-production-plans"),
cancellationToken).ConfigureAwait(false);
// 订阅服务端 PONG 回复(应用层假在线检测)
await SendFrameAsync(

View File

@@ -20,6 +20,7 @@ using YY.Admin.Views.Print;
using YY.Admin.Views.MixerMaterialTareStrategy;
using YY.Admin.Views.RubberQuickTest;
using YY.Admin.Views.RubberQuickTestStd;
using YY.Admin.Views.MixingProductionPlan;
namespace YY.Admin
{
@@ -97,10 +98,13 @@ namespace YY.Admin
containerRegistry.RegisterForNavigation<WarehouseAreaListView>();
// 密炼物料皮重策略
containerRegistry.RegisterForNavigation<MixerMaterialTareStrategyListView>();
// 快检记录操作台
// 胶料快检记录操作台
containerRegistry.RegisterForNavigation<RubberQuickTestRecordListView>();
containerRegistry.RegisterForNavigation<RubberQuickTestOperationView>();
// 胶料快检实验标准(只读)
containerRegistry.RegisterForNavigation<RubberQuickTestStdListView>();
// 密炼计划(只读)
containerRegistry.RegisterForNavigation<MixingProductionPlanListView>();
// 打印设置
containerRegistry.RegisterForNavigation<PrintSettingsView>();
// 打印模板列表

View File

@@ -29,6 +29,7 @@ using YY.Admin.Services.Service.WeightRecord;
using YY.Admin.Services.Service.Print;
using YY.Admin.Services.Service.RubberQuickTest;
using YY.Admin.Services.Service.RubberQuickTestStd;
using YY.Admin.Services.Service.MixingProductionPlan;
namespace YY.Admin.Module;
@@ -88,13 +89,18 @@ public class SyncModule : IModule
containerRegistry.RegisterSingleton<PrintTemplateSyncCoordinator>();
containerRegistry.RegisterSingleton<PrintBizTemplateBindSyncCoordinator>();
// 胶料快检记录操作台
// 胶料快检记录:本地存储 + MES 同步
containerRegistry.RegisterSingleton<IRubberQuickTestRecordService, RubberQuickTestRecordService>();
containerRegistry.RegisterSingleton<IRubberQuickTestOperationService, RubberQuickTestOperationService>();
// 胶料快检实验标准MES 只读同步)
containerRegistry.RegisterSingleton<IRubberQuickTestStdService, RubberQuickTestStdService>();
containerRegistry.RegisterSingleton<RubberQuickTestStdSyncCoordinator>();
// 密炼计划MES 只读同步)
containerRegistry.RegisterSingleton<IMixingProductionPlanService, MixingProductionPlanService>();
containerRegistry.RegisterSingleton<MixingProductionPlanSyncCoordinator>();
var serviceCollection = new ServiceCollection();
serviceCollection.AddTransient<DisconnectGuardHandler>();
serviceCollection.AddHttpClient("JeecgApi", (sp, client) =>
@@ -167,6 +173,8 @@ public class SyncModule : IModule
_ = containerProvider.Resolve<PrintBizTemplateBindSyncCoordinator>();
// 胶料快检实验标准只读同步协调器
_ = containerProvider.Resolve<RubberQuickTestStdSyncCoordinator>();
// 密炼计划只读同步协调器
_ = containerProvider.Resolve<MixingProductionPlanSyncCoordinator>();
}
private static IAsyncPolicy<HttpResponseMessage> GetRetryPolicy()

View File

@@ -152,7 +152,10 @@ namespace YY.Admin.ViewModels.Control
["/xslmes/mesXslMixerMaterialTareStrategy"] = "MixerMaterialTareStrategyListView",
["mesXslMixerMaterialTareStrategy"] = "MixerMaterialTareStrategyListView",
// 已实现页面:快检记录操作台
// 已实现页面:胶料快检记录操作台
["RubberQuickTestRecordListView"] = "RubberQuickTestRecordListView",
["/xslmes/rubberQuickTestRecord"] = "RubberQuickTestRecordListView",
["rubberQuickTestRecord"] = "RubberQuickTestRecordListView",
["RubberQuickTestOperationView"] = "RubberQuickTestOperationView",
["/xslmes/rubberQuickTestOperation"] = "RubberQuickTestOperationView",
["rubberQuickTestOperation"] = "RubberQuickTestOperationView",
@@ -162,6 +165,11 @@ namespace YY.Admin.ViewModels.Control
["/xslmes/mesXslRubberQuickTestStd"] = "RubberQuickTestStdListView",
["mesXslRubberQuickTestStd"] = "RubberQuickTestStdListView",
// 已实现页面:密炼计划(只读)
["MixingProductionPlanListView"] = "MixingProductionPlanListView",
["/xslmes/mesXslMixingProductionPlan"] = "MixingProductionPlanListView",
["mesXslMixingProductionPlan"] = "MixingProductionPlanListView",
// 已实现页面:打印设置
["PrintSettingsView"] = "PrintSettingsView",
["/system/printSettings"] = "PrintSettingsView",

View File

@@ -0,0 +1,139 @@
using HandyControl.Controls;
using Prism.Events;
using System.Collections.ObjectModel;
using System.Diagnostics;
using YY.Admin.Core;
using YY.Admin.Core.Entity;
using YY.Admin.Core.Events;
using YY.Admin.Core.Helper;
using YY.Admin.Core.Services;
using YY.Admin.Services.Service;
namespace YY.Admin.ViewModels.MixingProductionPlan;
public class MixingProductionPlanListViewModel : BaseViewModel
{
private readonly IMixingProductionPlanService _planService;
private SubscriptionToken? _changedToken;
private ObservableCollection<MesXslMixingProductionPlan> _items = new();
public ObservableCollection<MesXslMixingProductionPlan> Items
{
get => _items;
set => SetProperty(ref _items, value);
}
private long _total;
public long Total { get => _total; set => SetProperty(ref _total, value); }
private int _pageNo = 1;
public int PageNo { get => _pageNo; set => SetProperty(ref _pageNo, value); }
private int _pageSize = 20;
public int PageSize { get => _pageSize; set => SetProperty(ref _pageSize, value); }
private DateTime? _filterPlanDateFrom;
public DateTime? FilterPlanDateFrom { get => _filterPlanDateFrom; set => SetProperty(ref _filterPlanDateFrom, value); }
private DateTime? _filterPlanDateTo;
public DateTime? FilterPlanDateTo { get => _filterPlanDateTo; set => SetProperty(ref _filterPlanDateTo, value); }
private string? _filterMachineName;
public string? FilterMachineName { get => _filterMachineName; set => SetProperty(ref _filterMachineName, value); }
private int? _filterShiftFlag;
public int? FilterShiftFlag { get => _filterShiftFlag; set => SetProperty(ref _filterShiftFlag, value); }
private string? _filterPlanNo;
public string? FilterPlanNo { get => _filterPlanNo; set => SetProperty(ref _filterPlanNo, value); }
private string? _filterMaterialName;
public string? FilterMaterialName { get => _filterMaterialName; set => SetProperty(ref _filterMaterialName, value); }
public ObservableCollection<KeyValuePair<string, int?>> ShiftOptions { get; } = new()
{
new KeyValuePair<string, int?>("全部", null),
new KeyValuePair<string, int?>("早班", 1),
new KeyValuePair<string, int?>("中班", 2),
new KeyValuePair<string, int?>("晚班", 3)
};
public DelegateCommand SearchCommand { get; }
public DelegateCommand ResetCommand { get; }
public DelegateCommand PrevPageCommand { get; }
public DelegateCommand NextPageCommand { get; }
public MixingProductionPlanListViewModel(
IMixingProductionPlanService planService,
IContainerExtension container,
IRegionManager regionManager) : base(container, regionManager)
{
_planService = planService;
SearchCommand = new DelegateCommand(async () => { PageNo = 1; await LoadAsync(); });
ResetCommand = new DelegateCommand(async () =>
{
FilterPlanDateFrom = null;
FilterPlanDateTo = null;
FilterMachineName = null;
FilterShiftFlag = null;
FilterPlanNo = null;
FilterMaterialName = null;
PageNo = 1;
await LoadAsync();
});
PrevPageCommand = new DelegateCommand(async () => { if (PageNo > 1) { PageNo--; await LoadAsync(); } });
NextPageCommand = new DelegateCommand(async () => { if ((long)PageNo * PageSize < Total) { PageNo++; await LoadAsync(); } });
_changedToken = _eventAggregator.GetEvent<MixingProductionPlanChangedEvent>()
.Subscribe(async _ => await LoadAsync(), ThreadOption.UIThread);
_ = InitializeAsync();
}
private async Task InitializeAsync()
{
try
{
await UIHelper.WaitForRenderAsync();
await LoadAsync();
}
catch (Exception ex)
{
Debug.WriteLine($"密炼计划列表初始化失败: {ex.Message}");
}
}
public async Task LoadAsync()
{
try
{
IsLoading = true;
var result = await _planService.PageAsync(
PageNo, PageSize,
FilterPlanDateFrom, FilterPlanDateTo,
FilterMachineName, FilterShiftFlag,
FilterPlanNo, FilterMaterialName);
Items = new ObservableCollection<MesXslMixingProductionPlan>(result.Records);
Total = result.Total;
}
catch (Exception ex)
{
Growl.Error($"加载密炼计划失败:{ex.Message}");
}
finally
{
IsLoading = false;
}
}
protected override void CleanUp()
{
base.CleanUp();
if (_changedToken != null)
{
_eventAggregator.GetEvent<MixingProductionPlanChangedEvent>().Unsubscribe(_changedToken);
_changedToken = null;
}
}
}

View File

@@ -0,0 +1,104 @@
using LiveChartsCore;
using LiveChartsCore.Defaults;
using LiveChartsCore.SkiaSharpView;
using Prism.Mvvm;
using System.Collections.ObjectModel;
using YY.Admin.Core.Entity;
namespace YY.Admin.ViewModels.RubberQuickTest;
public class RubberQuickTestRecordDetailDialogViewModel : BindableBase
{
private MesXslRubberQuickTestRecord? _record;
public MesXslRubberQuickTestRecord? Record
{
get => _record;
private set => SetProperty(ref _record, value);
}
private string? _inspectResultDisplay;
public string? InspectResultDisplay
{
get => _inspectResultDisplay;
private set => SetProperty(ref _inspectResultDisplay, value);
}
public ObservableCollection<MesXslRubberQuickTestRecordStdLine> StdLines { get; } = new();
public ObservableCollection<MesXslRubberQuickTestRecordRawLine> RawLines { get; } = new();
public ObservableCollection<ISeries> TemperatureSeries { get; }
public ObservableCollection<ISeries> TorqueSeries { get; }
public ObservableCollection<ObservablePoint> UpperTempValues { get; } = new();
public ObservableCollection<ObservablePoint> LowerTempValues { get; } = new();
public ObservableCollection<ObservablePoint> TorqueValues { get; } = new();
public Axis[] TemperatureXAxes { get; } = BuildTimeAxis();
public Axis[] TemperatureYAxes { get; } = BuildTempYAxis();
public Axis[] TorqueXAxes { get; } = BuildTimeAxis();
public Axis[] TorqueYAxes { get; } = BuildTorqueYAxis();
public RubberQuickTestRecordDetailDialogViewModel()
{
TemperatureSeries = new ObservableCollection<ISeries>
{
new LineSeries<ObservablePoint> { Name = "上模温度", Values = UpperTempValues, GeometrySize = 4, LineSmoothness = 0.3 },
new LineSeries<ObservablePoint> { Name = "下模温度", Values = LowerTempValues, GeometrySize = 4, LineSmoothness = 0.3 }
};
TorqueSeries = new ObservableCollection<ISeries>
{
new LineSeries<ObservablePoint> { Name = "S'(dNm)", Values = TorqueValues, GeometrySize = 4, LineSmoothness = 0.3 }
};
}
public void Initialize(MesXslRubberQuickTestRecord record)
{
Record = record;
InspectResultDisplay = record.InspectResult switch
{
"1" => "合格",
"0" => "不合格",
_ => record.InspectResultText ?? record.InspectResult ?? ""
};
StdLines.Clear();
foreach (var line in record.StdLineList ?? [])
StdLines.Add(line);
RawLines.Clear();
foreach (var line in record.RawLineList ?? [])
RawLines.Add(line);
UpperTempValues.Clear();
LowerTempValues.Clear();
TorqueValues.Clear();
foreach (var p in (record.ChartPointList ?? []).OrderBy(x => x.SortNo ?? 0))
{
var time = (double)(p.TimeMin ?? 0);
UpperTempValues.Add(new ObservablePoint(time, (double)(p.UpperTemp ?? 0)));
LowerTempValues.Add(new ObservablePoint(time, (double)(p.LowerTemp ?? 0)));
TorqueValues.Add(new ObservablePoint(time, (double)(p.TorqueS ?? 0)));
}
}
private static Axis[] BuildTimeAxis() => new[]
{
new Axis { Name = "时间(min)", MinLimit = 0, MaxLimit = 2, Labeler = v => v.ToString("0.0#") }
};
private static Axis[] BuildTempYAxis() => new[]
{
new Axis { Name = "温度(℃)", MinLimit = 189, MaxLimit = 201 }
};
private static readonly double[] TorqueYTicks = { 0.0, 3.0, 5.9, 8.9, 11.8, 14.8 };
private static Axis[] BuildTorqueYAxis() => new[]
{
new Axis
{
Name = "S'(dNm)",
MinLimit = 0,
MaxLimit = 14.8,
CustomSeparators = TorqueYTicks
}
};
}

View File

@@ -0,0 +1,227 @@
using HandyControl.Controls;
using Prism.Events;
using Prism.Navigation;
using System.Collections.ObjectModel;
using System.Diagnostics;
using YY.Admin.Core;
using YY.Admin.Core.Entity;
using YY.Admin.Core.Events;
using YY.Admin.Core.Helper;
using YY.Admin.Core.Services;
using YY.Admin.Event;
using YY.Admin.Module;
using YY.Admin.Services.Service;
namespace YY.Admin.ViewModels.RubberQuickTest;
public class RubberQuickTestRecordListViewModel : BaseViewModel
{
private readonly IRubberQuickTestRecordService _recordService;
private readonly IJeecgDictSyncService _dictSyncService;
private SubscriptionToken? _changedToken;
private ObservableCollection<RubberQuickTestRecordListRow> _records = new();
public ObservableCollection<RubberQuickTestRecordListRow> Records
{
get => _records;
set => SetProperty(ref _records, value);
}
private long _total;
public long Total { get => _total; set => SetProperty(ref _total, value); }
private int _pageNo = 1;
public int PageNo { get => _pageNo; set => SetProperty(ref _pageNo, value); }
private int _pageSize = 20;
public int PageSize { get => _pageSize; set => SetProperty(ref _pageSize, value); }
private string? _filterRecordNo;
public string? FilterRecordNo { get => _filterRecordNo; set => SetProperty(ref _filterRecordNo, value); }
private string? _filterRubberMaterialName;
public string? FilterRubberMaterialName { get => _filterRubberMaterialName; set => SetProperty(ref _filterRubberMaterialName, value); }
private string? _filterPlanNo;
public string? FilterPlanNo { get => _filterPlanNo; set => SetProperty(ref _filterPlanNo, value); }
public DelegateCommand SearchCommand { get; }
public DelegateCommand ResetCommand { get; }
public DelegateCommand AddCommand { get; }
public DelegateCommand<RubberQuickTestRecordListRow> ViewDetailCommand { get; }
public DelegateCommand<RubberQuickTestRecordListRow> DeleteCommand { get; }
public DelegateCommand PrevPageCommand { get; }
public DelegateCommand NextPageCommand { get; }
public RubberQuickTestRecordListViewModel(
IRubberQuickTestRecordService recordService,
IJeecgDictSyncService dictSyncService,
IContainerExtension container,
IRegionManager regionManager) : base(container, regionManager)
{
_recordService = recordService;
_dictSyncService = dictSyncService;
SearchCommand = new DelegateCommand(async () => { PageNo = 1; await LoadAsync(); });
ResetCommand = new DelegateCommand(async () =>
{
FilterRecordNo = null;
FilterRubberMaterialName = null;
FilterPlanNo = null;
PageNo = 1;
await LoadAsync();
});
AddCommand = new DelegateCommand(OpenAddPage);
ViewDetailCommand = new DelegateCommand<RubberQuickTestRecordListRow>(async r => await ShowDetailAsync(r));
DeleteCommand = new DelegateCommand<RubberQuickTestRecordListRow>(
async r => await DeleteAsync(r),
r => r != null && r.CanDelete);
PrevPageCommand = new DelegateCommand(async () => { if (PageNo > 1) { PageNo--; await LoadAsync(); } });
NextPageCommand = new DelegateCommand(async () => { if ((long)PageNo * PageSize < Total) { PageNo++; await LoadAsync(); } });
_changedToken = _eventAggregator.GetEvent<RubberQuickTestRecordChangedEvent>()
.Subscribe(async _ => await LoadAsync(), ThreadOption.UIThread);
_ = InitializeAsync();
}
private async Task InitializeAsync()
{
try
{
await UIHelper.WaitForRenderAsync();
await LoadAsync();
}
catch (Exception ex)
{
Debug.WriteLine($"快检记录列表初始化失败: {ex.Message}");
}
}
public async Task LoadAsync()
{
try
{
IsLoading = true;
var result = await _recordService.PageAsync(
PageNo, PageSize, FilterRecordNo, FilterRubberMaterialName, FilterPlanNo);
var shiftMap = (await _dictSyncService.GetDictOptionsAsync("xslmes_rubber_quick_test_work_shift", includeAll: false))
.ToDictionary(x => x.Value, x => x.Key);
foreach (var r in result.Records)
{
if (!string.IsNullOrWhiteSpace(r.WorkShiftDisplay) && shiftMap.TryGetValue(r.WorkShiftDisplay, out var txt))
r.WorkShiftDisplay = txt;
}
Records = new ObservableCollection<RubberQuickTestRecordListRow>(result.Records);
Total = result.Total;
}
catch (Exception ex)
{
Growl.Error($"加载快检记录失败:{ex.Message}");
}
finally
{
IsLoading = false;
}
}
private void OpenAddPage()
{
_eventAggregator.GetEvent<TabSourceSelectedEvent>().Publish(new TabSource
{
Name = "新增胶料快检记录",
Icon = "\ue7de",
ViewName = "RubberQuickTestOperationView"
});
}
private async Task DeleteAsync(RubberQuickTestRecordListRow? row)
{
if (row == null || !row.CanDelete || string.IsNullOrWhiteSpace(row.LocalId))
return;
var label = row.RecordNo ?? row.LocalId;
var confirm = System.Windows.MessageBox.Show(
$"确定删除同步失败的快检记录「{label}」?\n此操作仅删除本地记录不可恢复。",
"确认删除",
System.Windows.MessageBoxButton.YesNo,
System.Windows.MessageBoxImage.Warning);
if (confirm != System.Windows.MessageBoxResult.Yes)
return;
try
{
if (_recordService.DeleteFailedLocal(row.LocalId))
{
Growl.Success("删除成功");
await LoadAsync();
}
else
{
Growl.Warning("仅同步失败的本地记录可删除");
}
}
catch (Exception ex)
{
Growl.Error($"删除失败:{ex.Message}");
}
}
private async Task ShowDetailAsync(RubberQuickTestRecordListRow? row)
{
if (row == null) return;
try
{
if (!string.IsNullOrWhiteSpace(row.LocalId))
{
if (_recordService.GetByLocalId(row.LocalId) == null)
{
Growl.Warning("未找到快检记录详情");
return;
}
}
else if (!string.IsNullOrWhiteSpace(row.MesId))
{
var remote = await _recordService.GetByIdAsync(row.MesId);
if (remote == null)
{
Growl.Warning("未找到快检记录详情");
return;
}
}
else
{
Growl.Warning("无法定位快检记录");
return;
}
var parameters = new NavigationParameters { { "readOnly", true } };
if (!string.IsNullOrWhiteSpace(row.LocalId))
parameters.Add("localId", row.LocalId);
else
parameters.Add("mesId", row.MesId!);
var title = row.RecordNo ?? row.LocalId ?? row.MesId ?? "详情";
_eventAggregator.GetEvent<TabSourceSelectedEvent>().Publish(new TabSource
{
Name = $"快检记录 {title}",
Icon = "\ue7de",
ViewName = "RubberQuickTestOperationView",
NavigationParameter = parameters
});
}
catch (Exception ex)
{
Growl.Error($"打开详情失败:{ex.Message}");
}
}
protected override void CleanUp()
{
base.CleanUp();
if (_changedToken != null)
_eventAggregator.GetEvent<RubberQuickTestRecordChangedEvent>().Unsubscribe(_changedToken);
}
}

View File

@@ -0,0 +1,135 @@
<UserControl x:Class="YY.Admin.Views.MixingProductionPlan.MixingProductionPlanListView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True"
mc:Ignorable="d">
<Grid Style="{StaticResource BaseViewStyle}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Border Grid.Row="0" CornerRadius="4" Margin="0 0 -10 0">
<hc:Row>
<hc:Col Layout="{hc:ColLayout Xs=12, Sm=8, Md=6, Lg=6, Xl=4}">
<hc:DatePicker SelectedDate="{Binding FilterPlanDateFrom}"
Margin="0 0 10 10"
hc:InfoElement.Title="密炼日期起"
hc:InfoElement.TitlePlacement="Left"
hc:InfoElement.TitleWidth="80"
hc:InfoElement.Placeholder="开始日期"/>
</hc:Col>
<hc:Col Layout="{hc:ColLayout Xs=12, Sm=8, Md=6, Lg=6, Xl=4}">
<hc:DatePicker SelectedDate="{Binding FilterPlanDateTo}"
Margin="0 0 10 10"
hc:InfoElement.Title="密炼日期止"
hc:InfoElement.TitlePlacement="Left"
hc:InfoElement.TitleWidth="80"
hc:InfoElement.Placeholder="结束日期"/>
</hc:Col>
<hc:Col Layout="{hc:ColLayout Xs=12, Sm=8, Md=6, Lg=6, Xl=4}">
<hc:TextBox Text="{Binding FilterMachineName, UpdateSourceTrigger=PropertyChanged}"
Margin="0 0 10 10"
hc:InfoElement.Title="机台名称"
hc:InfoElement.TitlePlacement="Left"
hc:InfoElement.TitleWidth="80"
hc:InfoElement.Placeholder="机台名称"
hc:InfoElement.ShowClearButton="True"/>
</hc:Col>
<hc:Col Layout="{hc:ColLayout Xs=12, Sm=8, Md=6, Lg=6, Xl=4}">
<hc:ComboBox SelectedValuePath="Value"
DisplayMemberPath="Key"
ItemsSource="{Binding ShiftOptions}"
SelectedValue="{Binding FilterShiftFlag}"
Margin="0 0 10 10"
hc:InfoElement.Title="班次"
hc:InfoElement.TitlePlacement="Left"
hc:InfoElement.TitleWidth="80"
hc:InfoElement.Placeholder="全部"/>
</hc:Col>
<hc:Col Layout="{hc:ColLayout Xs=12, Sm=8, Md=6, Lg=6, Xl=4}">
<hc:TextBox Text="{Binding FilterPlanNo, UpdateSourceTrigger=PropertyChanged}"
Margin="0 0 10 10"
hc:InfoElement.Title="计划号"
hc:InfoElement.TitlePlacement="Left"
hc:InfoElement.TitleWidth="80"
hc:InfoElement.Placeholder="计划号"
hc:InfoElement.ShowClearButton="True"/>
</hc:Col>
<hc:Col Layout="{hc:ColLayout Xs=12, Sm=8, Md=6, Lg=6, Xl=4}">
<hc:TextBox Text="{Binding FilterMaterialName, UpdateSourceTrigger=PropertyChanged}"
Margin="0 0 10 10"
hc:InfoElement.Title="胶料名称"
hc:InfoElement.TitlePlacement="Left"
hc:InfoElement.TitleWidth="80"
hc:InfoElement.Placeholder="胶料名称"
hc:InfoElement.ShowClearButton="True"/>
</hc:Col>
</hc:Row>
</Border>
<Border Grid.Row="1" Margin="0,10">
<hc:UniformSpacingPanel Spacing="10">
<Button Style="{StaticResource ButtonPrimary}" Command="{Binding SearchCommand}">
<StackPanel Orientation="Horizontal">
<md:PackIcon Kind="Search"/>
<TextBlock Text="搜索" Style="{StaticResource IconButtonStyle}"/>
</StackPanel>
</Button>
<Button Style="{StaticResource ButtonDefault}" Command="{Binding ResetCommand}">
<StackPanel Orientation="Horizontal">
<md:PackIcon Kind="Refresh"/>
<TextBlock Text="重置" Style="{StaticResource IconButtonStyle}"/>
</StackPanel>
</Button>
<TextBlock Text="数据来自 MES 密炼生产计划维护,桌面端只读;断网时显示本地缓存,联网后自动刷新"
VerticalAlignment="Center"
Foreground="{DynamicResource SecondaryTextBrush}"
FontSize="12"/>
</hc:UniformSpacingPanel>
</Border>
<DataGrid Grid.Row="2"
ItemsSource="{Binding Items}"
AutoGenerateColumns="False"
IsReadOnly="True"
CanUserAddRows="False"
SelectionMode="Single"
GridLinesVisibility="Horizontal"
HorizontalGridLinesBrush="#FFEDEDED"
VerticalGridLinesBrush="Transparent"
HeadersVisibility="All"
ColumnHeaderStyle="{StaticResource CusDataGridColumnHeaderStyle}"
Style="{StaticResource CusDataGridStyle}"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto">
<DataGrid.Columns>
<!-- 固定列宽合计约 920px宽屏右侧留白 -->
<DataGridTextColumn Header="密炼日期" Binding="{Binding PlanDateText}" CellStyle="{StaticResource CusDataGridCellStyle}" Width="100"/>
<DataGridTextColumn Header="机台名称" Binding="{Binding MachineName}" CellStyle="{StaticResource CusDataGridCellStyle}" Width="120"/>
<DataGridTextColumn Header="班次" Binding="{Binding ShiftFlagText}" CellStyle="{StaticResource CusDataGridCellStyle}" Width="68"/>
<DataGridTextColumn Header="计划号" Binding="{Binding PlanNo}" CellStyle="{StaticResource CusDataGridCellStyle}" Width="160"/>
<DataGridTextColumn Header="胶料名称" Binding="{Binding MaterialName}" CellStyle="{StaticResource CusDataGridCellStyle}" Width="120"/>
<DataGridTextColumn Header="计划+胶料号" Binding="{Binding PlanMaterialNo}" CellStyle="{StaticResource CusDataGridCellStyle}" Width="240"/>
<DataGridTextColumn Header="计划数量" Binding="{Binding PlanCount}" CellStyle="{StaticResource CusDataGridCellStyle}" Width="76"/>
</DataGrid.Columns>
</DataGrid>
<StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,10,0,0">
<TextBlock Text="{Binding Total, StringFormat=共 {0} 条}" VerticalAlignment="Center" Margin="0,0,16,0"
Foreground="{DynamicResource SecondaryTextBrush}"/>
<Button Content="上一页" Command="{Binding PrevPageCommand}" Style="{StaticResource ButtonDefault}" Margin="0,0,4,0" Width="80"/>
<TextBlock Text="{Binding PageNo, StringFormat=第 {0} 页}" VerticalAlignment="Center" Margin="8,0"
Foreground="{DynamicResource PrimaryTextBrush}"/>
<Button Content="下一页" Command="{Binding NextPageCommand}" Style="{StaticResource ButtonDefault}" Width="80"/>
</StackPanel>
</Grid>
</UserControl>

View File

@@ -0,0 +1,11 @@
using System.Windows.Controls;
namespace YY.Admin.Views.MixingProductionPlan;
public partial class MixingProductionPlanListView : UserControl
{
public MixingProductionPlanListView()
{
InitializeComponent();
}
}

View File

@@ -24,75 +24,110 @@
<Setter Property="Margin" Value="8,0,0,0"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
<Style x:Key="DataGridCellCenterTextStyle" TargetType="TextBlock">
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
<Style x:Key="DataGridCellCenterEditStyle" TargetType="TextBox">
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
</Style>
</UserControl.Resources>
<Grid Margin="12">
<Grid.RowDefinitions>
<RowDefinition Height="64"/>
<RowDefinition Height="52"/>
<RowDefinition Height="*"/>
<RowDefinition Height="56"/>
</Grid.RowDefinitions>
<!-- 标题 -->
<Border Grid.Row="0" Background="{DynamicResource RegionBrush}"
BorderBrush="{DynamicResource BorderBrush}" BorderThickness="0,0,0,1" Margin="-12,0,-12,8">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="20,0">
<Border Width="40" Height="40" CornerRadius="8" Background="{DynamicResource PrimaryBrush}" Margin="0,0,12,0">
<md:PackIcon Kind="Flask" Width="22" Height="22" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center"/>
BorderBrush="{DynamicResource BorderBrush}" BorderThickness="0,0,0,1" Margin="-12,0,-12,6">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="16,0">
<Border Width="32" Height="32" CornerRadius="6" Background="{DynamicResource PrimaryBrush}" Margin="0,0,10,0">
<md:PackIcon Kind="Flask" Width="18" Height="18" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<StackPanel>
<TextBlock Text="快检记录" FontSize="18" FontWeight="Bold"/>
<TextBlock Text="密炼快检试验操作台" FontSize="12" Foreground="{DynamicResource SecondaryTextBrush}"/>
<StackPanel VerticalAlignment="Center">
<TextBlock Text="无转子流变仪 MDR S3L" FontSize="18" FontWeight="Bold"/>
<TextBlock Text="胶料快检记录 · 密炼快检试验操作台" FontSize="11" Foreground="{DynamicResource SecondaryTextBrush}" Margin="0,2,0,0"/>
</StackPanel>
</StackPanel>
</Border>
<!-- 主体 2:1 -->
<!-- 主体 3:2 -->
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="12"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<!-- 左侧:曲线 + 试验结果 -->
<ScrollViewer Grid.Column="0" VerticalScrollBarVisibility="Auto">
<StackPanel>
<Border Style="{StaticResource SectionBorderStyle}">
<StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,0,0,8">
<Border Width="4" Height="18" CornerRadius="2" Background="#1890ff"/>
<TextBlock Text="温度(℃)曲线" Style="{StaticResource SectionTitleStyle}"/>
<Button Content="刷新演示" Command="{Binding RefreshChartDemoCommand}" Style="{StaticResource ButtonDefault}" Height="28" Padding="10,0" Margin="12,0,0,0"/>
<!-- 左侧:曲线图 : 试验结果 ≈ 3 : 2 -->
<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="3*"/>
<RowDefinition Height="2*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border Grid.Row="0" Style="{StaticResource SectionBorderStyle}" Padding="10,10,10,6" Margin="0,0,0,6">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal" Margin="0,0,0,4">
<Border Width="4" Height="16" CornerRadius="2" Background="#1890ff"/>
<TextBlock Text="温度(℃)曲线图" Style="{StaticResource SectionTitleStyle}"/>
<Button Content="刷新演示" Command="{Binding RefreshChartDemoCommand}" Style="{StaticResource ButtonDefault}" Height="26" Padding="8,0" Margin="10,0,0,0"/>
</StackPanel>
<TextBlock Text="{Binding ChartDemoHint}" FontSize="11" Foreground="{DynamicResource SecondaryTextBrush}" Margin="0,0,0,6"/>
<Border Height="220" CornerRadius="4">
<TextBlock Grid.Row="1" Text="{Binding ChartDemoHint}" FontSize="10" Foreground="{DynamicResource SecondaryTextBrush}" Margin="0,0,0,4"
TextTrimming="CharacterEllipsis"/>
<Border Grid.Row="2" CornerRadius="4">
<lvc:CartesianChart Series="{Binding TemperatureSeries}"
XAxes="{Binding TemperatureXAxes}"
YAxes="{Binding TemperatureYAxes}"
LegendPosition="Top"/>
</Border>
</StackPanel>
</Grid>
</Border>
<Border Style="{StaticResource SectionBorderStyle}">
<StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,0,0,8">
<Border Width="4" Height="18" CornerRadius="2" Background="#1890ff"/>
<TextBlock Text="S'(dNm)曲线" Style="{StaticResource SectionTitleStyle}"/>
<Border Grid.Row="1" Style="{StaticResource SectionBorderStyle}" Padding="10,10,10,6" Margin="0,0,0,0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal" Margin="0,0,0,4">
<Border Width="4" Height="16" CornerRadius="2" Background="#1890ff"/>
<TextBlock Text="S'(dNm)曲线图" Style="{StaticResource SectionTitleStyle}"/>
</StackPanel>
<Border Height="200" CornerRadius="4">
<Border Grid.Row="1" CornerRadius="4">
<lvc:CartesianChart Series="{Binding TorqueSeries}"
XAxes="{Binding TorqueXAxes}"
YAxes="{Binding TorqueYAxes}"
LegendPosition="Top"/>
</Border>
</StackPanel>
</Grid>
</Border>
</Grid>
<Border Style="{StaticResource SectionBorderStyle}">
<StackPanel>
<Grid Margin="0,0,0,8">
<Border Grid.Row="1" Style="{StaticResource SectionBorderStyle}" Margin="0" Padding="10,10,10,8">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Margin="0,0,0,8">
<StackPanel Orientation="Horizontal">
<Border Width="4" Height="18" CornerRadius="2" Background="#1890ff"/>
<TextBlock Text="试验结果" Style="{StaticResource SectionTitleStyle}"/>
@@ -102,66 +137,99 @@
<Button Content="删除选中行" Command="{Binding RemoveInspectRowCommand}" Style="{StaticResource ButtonDanger}" Height="28" Padding="10,0"/>
</StackPanel>
</Grid>
<DataGrid x:Name="InspectResultGrid"
<DataGrid Grid.Row="1"
x:Name="InspectResultGrid"
ItemsSource="{Binding InspectRows}"
AutoGenerateColumns="False"
CanUserAddRows="False"
CanUserDeleteRows="False"
HeadersVisibility="Column"
MinHeight="160"
SelectionMode="Single"
IsReadOnly="False"
SelectionChanged="InspectResultGrid_SelectionChanged">
RowHeight="30"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto"
SelectionChanged="InspectResultGrid_SelectionChanged"
Style="{StaticResource CusDataGridStyle}"
ColumnHeaderStyle="{StaticResource CusDataGridColumnHeaderStyle}">
</DataGrid>
<TextBlock Text="请手填各数据点检测值,系统将根据数据标准上下限自动判定合格/不合格" FontSize="11" Foreground="{DynamicResource SecondaryTextBrush}" Margin="0,6,0,0"/>
</StackPanel>
<TextBlock Grid.Row="2" Text="请手填各数据点检测值,系统将根据数据标准上下限自动判定合格/不合格" FontSize="11" Foreground="{DynamicResource SecondaryTextBrush}" Margin="0,6,0,0"/>
</Grid>
</Border>
</StackPanel>
</ScrollViewer>
</Grid>
<!-- 右侧 -->
<ScrollViewer Grid.Column="2" VerticalScrollBarVisibility="Auto">
<StackPanel>
<!-- 实时数据 -->
<Border Style="{StaticResource SectionBorderStyle}">
<StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,0,0,12">
<Border Width="4" Height="18" CornerRadius="2" Background="#52c41a"/>
<!-- 右侧:实时数据 + 试验信息(上)与 数据标准(下 2*,与左侧试验结果同高) -->
<Grid Grid.Column="2">
<Grid.RowDefinitions>
<RowDefinition Height="3*"/>
<RowDefinition Height="2*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!-- 实时数据(占用上部剩余空间) -->
<Border Grid.Row="0" Style="{StaticResource SectionBorderStyle}" Padding="10,8" Margin="0,0,0,8">
<Grid VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal" Margin="0,0,0,8">
<Border Width="4" Height="16" CornerRadius="2" Background="#52c41a"/>
<TextBlock Text="实时数据" Style="{StaticResource SectionTitleStyle}"/>
</StackPanel>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid Grid.Row="1" VerticalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="上模温度(℃)" Foreground="{DynamicResource SecondaryTextBrush}" Margin="0,0,0,4"/>
<TextBlock Grid.Row="1" Text="{Binding UpperMoldTemp, StringFormat={}{0:N2}}" FontSize="28" FontWeight="Bold" FontFamily="Consolas"/>
<TextBlock Grid.Column="1" Text="下模温度(℃)" Foreground="{DynamicResource SecondaryTextBrush}" Margin="0,0,0,4"/>
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding LowerMoldTemp, StringFormat={}{0:N2}}" FontSize="28" FontWeight="Bold" FontFamily="Consolas"/>
<TextBlock Grid.Row="2" Grid.Column="0" Text="S'(dNm)" Foreground="{DynamicResource SecondaryTextBrush}" Margin="0,12,0,4"/>
<TextBlock Grid.Row="2" Grid.Column="0" Margin="0,32,0,0" Text="{Binding TorqueS, StringFormat={}{0:N2}}" FontSize="28" FontWeight="Bold" FontFamily="Consolas"/>
<StackPanel Grid.Column="0" Margin="0,0,6,0" VerticalAlignment="Center">
<TextBlock Text="上模温度(℃)" FontSize="12" Foreground="{DynamicResource SecondaryTextBrush}" HorizontalAlignment="Center"/>
<TextBlock Text="{Binding UpperMoldTemp, StringFormat={}{0:N2}}" FontSize="28" FontWeight="Bold" FontFamily="Consolas" Margin="0,6,0,0" HorizontalAlignment="Center"/>
</StackPanel>
<StackPanel Grid.Column="1" Margin="0,0,6,0" VerticalAlignment="Center">
<TextBlock Text="下模温度(℃)" FontSize="12" Foreground="{DynamicResource SecondaryTextBrush}" HorizontalAlignment="Center"/>
<TextBlock Text="{Binding LowerMoldTemp, StringFormat={}{0:N2}}" FontSize="28" FontWeight="Bold" FontFamily="Consolas" Margin="0,6,0,0" HorizontalAlignment="Center"/>
</StackPanel>
<StackPanel Grid.Column="2" VerticalAlignment="Center">
<TextBlock Text="S'(dNm)" FontSize="12" Foreground="{DynamicResource SecondaryTextBrush}" HorizontalAlignment="Center"/>
<TextBlock Text="{Binding TorqueS, StringFormat={}{0:N2}}" FontSize="28" FontWeight="Bold" FontFamily="Consolas" Margin="0,6,0,0" HorizontalAlignment="Center"/>
</StackPanel>
</Grid>
</StackPanel>
</Grid>
</Border>
<!-- 试验信息 -->
<Border Style="{StaticResource SectionBorderStyle}">
<Border Grid.Row="1" Style="{StaticResource SectionBorderStyle}" Margin="0,0,0,0">
<StackPanel>
<Grid Margin="0,0,0,12">
<StackPanel Orientation="Horizontal">
<Border Width="4" Height="18" CornerRadius="2" Background="#1890ff"/>
<TextBlock Text="试验信息" Style="{StaticResource SectionTitleStyle}"/>
</StackPanel>
<Button Content="刷新计划" Command="{Binding RefreshPlansCommand}"
<Button Content="刷新本地数据" Command="{Binding RefreshPlansCommand}"
Style="{StaticResource ButtonDefault}" Height="26" Padding="8,0"
HorizontalAlignment="Right" VerticalAlignment="Center"/>
</Grid>
<hc:Row Gutter="10">
<!-- 快检记录号(保存后生成,单独一行) -->
<hc:Col Span="24">
<hc:TextBox Text="{Binding RecordNo, Mode=OneWay}"
IsReadOnly="True"
hc:InfoElement.Title="快检记录号"
hc:InfoElement.TitleWidth="90"
hc:InfoElement.TitlePlacement="Left"
hc:InfoElement.Placeholder="保存后自动生成"
Margin="0,0,0,8"/>
</hc:Col>
</hc:Row>
<hc:Row Gutter="10">
<!-- 密炼日期 -->
<hc:Col Span="12">
@@ -198,11 +266,11 @@
hc:InfoElement.Symbol="*"
Margin="0,0,0,8"/>
</hc:Col>
<!-- 密炼生产计划 -->
<!-- 密炼计划(计划+胶料号) -->
<hc:Col Span="24">
<hc:ComboBox ItemsSource="{Binding PlanOptions}"
SelectedItem="{Binding SelectedPlan}"
DisplayMemberPath="DisplayText"
DisplayMemberPath="PlanMaterialNo"
hc:InfoElement.Title="密炼计划"
hc:InfoElement.TitleWidth="90"
hc:InfoElement.TitlePlacement="Left"
@@ -211,18 +279,6 @@
hc:InfoElement.Symbol="*"
Margin="0,0,0,8"/>
</hc:Col>
<!-- 生产订单号 -->
<hc:Col Span="12">
<hc:TextBox Text="{Binding ProductionOrderNo, Mode=OneWay}"
IsReadOnly="True"
hc:InfoElement.Title="生产订单号"
hc:InfoElement.TitleWidth="90"
hc:InfoElement.TitlePlacement="Left"
hc:InfoElement.Placeholder="选择计划后自动带出"
hc:InfoElement.Necessary="True"
hc:InfoElement.Symbol="*"
Margin="0,0,0,8"/>
</hc:Col>
<!-- 胶料名称 -->
<hc:Col Span="12">
<hc:TextBox Text="{Binding RubberMaterialName, Mode=OneWay}"
@@ -233,6 +289,29 @@
hc:InfoElement.Placeholder="选择计划后自动带出"
Margin="0,0,0,8"/>
</hc:Col>
<!-- 实验标准 -->
<hc:Col Span="12">
<hc:ComboBox ItemsSource="{Binding StdOptions}"
SelectedItem="{Binding SelectedStd}"
DisplayMemberPath="StdName"
hc:InfoElement.Title="实验标准"
hc:InfoElement.TitleWidth="90"
hc:InfoElement.TitlePlacement="Left"
hc:InfoElement.Placeholder="按胶料名称筛选后选择"
hc:InfoElement.Necessary="True"
hc:InfoElement.Symbol="*"
Margin="0,0,0,8"/>
</hc:Col>
<!-- 实验方法 -->
<hc:Col Span="12">
<hc:TextBox Text="{Binding TestMethodName, Mode=OneWay}"
IsReadOnly="True"
hc:InfoElement.Title="实验方法"
hc:InfoElement.TitleWidth="90"
hc:InfoElement.TitlePlacement="Left"
hc:InfoElement.Placeholder="选择标准后自动带出"
Margin="0,0,0,8"/>
</hc:Col>
<!-- 车次 -->
<hc:Col Span="12">
<hc:TextBox Text="{Binding TrainNo, UpdateSourceTrigger=PropertyChanged}"
@@ -255,46 +334,81 @@
hc:InfoElement.Necessary="True"
hc:InfoElement.Symbol="*"
hc:InfoElement.ShowClearButton="True"
Margin="0,0,0,8"/>
</hc:Col>
<!-- 检验结果(由试验结果区域自动判定,只读) -->
<hc:Col Span="12">
<hc:TextBox Text="{Binding OverallInspectResultDisplay, Mode=OneWay}"
IsReadOnly="True"
hc:InfoElement.Title="检验结果"
hc:InfoElement.TitleWidth="90"
hc:InfoElement.TitlePlacement="Left"
hc:InfoElement.Placeholder="自动判定"
Margin="0,0,0,8"/>
</hc:Col>
<!-- 检验人(当前登录用户,只读) -->
<hc:Col Span="24">
<hc:TextBox Text="{Binding InspectorDisplay, Mode=OneWay}"
IsReadOnly="True"
hc:InfoElement.Title="检验人"
hc:InfoElement.TitleWidth="90"
hc:InfoElement.TitlePlacement="Left"
hc:InfoElement.Placeholder="当前登录用户"
Margin="0,0,0,0"/>
</hc:Col>
</hc:Row>
<TextBlock Text="按密炼日期 → 机台 → 班次筛选生产计划;胶料名称用于匹配快检实验标准"
<TextBlock Text="密炼计划、实验标准均来自桌面端本地缓存;按密炼日期筛选计划,再按胶料名称选择实验标准"
FontSize="11"
Foreground="{DynamicResource SecondaryTextBrush}"
Margin="0,8,0,0"
TextWrapping="Wrap"/>
</StackPanel>
</Border>
</Grid>
<!-- 数据标准 -->
<Border Style="{StaticResource SectionBorderStyle}">
<StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,0,0,8">
<!-- 数据标准(高度与左侧试验结果一致) -->
<Border Grid.Row="1" Style="{StaticResource SectionBorderStyle}" Margin="0" Padding="10,10,10,8">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal" Margin="0,0,0,8">
<Border Width="4" Height="18" CornerRadius="2" Background="#faad14"/>
<TextBlock Text="数据标准" Style="{StaticResource SectionTitleStyle}"/>
</StackPanel>
<DataGrid ItemsSource="{Binding DataPointColumns}"
<DataGrid Grid.Row="1"
ItemsSource="{Binding DataPointColumns}"
AutoGenerateColumns="False"
IsReadOnly="True"
HeadersVisibility="Column"
MaxHeight="240">
RowHeight="30"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto"
ColumnWidth="*"
Style="{StaticResource CusDataGridStyle}"
ColumnHeaderStyle="{StaticResource CusDataGridColumnHeaderStyle}">
<DataGrid.Columns>
<DataGridTextColumn Header="数据点" Binding="{Binding PointName}" Width="*"/>
<DataGridTextColumn Header="下限值" Binding="{Binding LowerLimit}" Width="70"/>
<DataGridTextColumn Header="限值" Binding="{Binding UpperLimit}" Width="70"/>
<DataGridTextColumn Header="数据点" Binding="{Binding PointName}" Width="5*"
ElementStyle="{StaticResource DataGridCellCenterTextStyle}"/>
<DataGridTextColumn Header="限值" Binding="{Binding LowerLimit, StringFormat={}{0:N2}}" Width="2.5*"
ElementStyle="{StaticResource DataGridCellCenterTextStyle}"/>
<DataGridTextColumn Header="上限值" Binding="{Binding UpperLimit, StringFormat={}{0:N2}}" Width="2.5*"
ElementStyle="{StaticResource DataGridCellCenterTextStyle}"/>
</DataGrid.Columns>
</DataGrid>
</StackPanel>
</Grid>
</Border>
</StackPanel>
</ScrollViewer>
</Grid>
</Grid>
<!-- 底部操作 -->
<Border Grid.Row="2" Background="{DynamicResource RegionBrush}" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="0,1,0,0" Margin="-12,8,-12,-12">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="20,0">
<Button Content="保存快检记录" Command="{Binding SaveCommand}" Style="{StaticResource ButtonPrimary}" Height="36" Width="140"/>
<Button Content="保存胶料快检记录" Command="{Binding SaveCommand}" Style="{StaticResource ButtonPrimary}" Height="36" Width="160"
IsEnabled="{Binding CanSave}"
Visibility="{Binding ShowSaveButton, Converter={StaticResource Boolean2VisibilityConverter}}"/>
</StackPanel>
</Border>
</Grid>

View File

@@ -1,72 +1,129 @@
using System.Collections.Specialized;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using YY.Admin.ViewModels.RubberQuickTest;
namespace YY.Admin.Views.RubberQuickTest;
public partial class RubberQuickTestOperationView : UserControl
{
private RubberQuickTestOperationViewModel? _vm;
private RubberQuickTestOperationViewModel? _vm;
public RubberQuickTestOperationView()
{
InitializeComponent();
DataContextChanged += OnDataContextChanged;
}
private void OnDataContextChanged(object sender, System.Windows.DependencyPropertyChangedEventArgs e)
{
if (_vm != null)
_vm.InspectColumnsChanged -= RebuildInspectColumns;
_vm = DataContext as RubberQuickTestOperationViewModel;
if (_vm != null)
public RubberQuickTestOperationView()
{
_vm.InspectColumnsChanged += RebuildInspectColumns;
RebuildInspectColumns();
}
}
private void RebuildInspectColumns()
{
if (_vm == null) return;
InspectResultGrid.Columns.Clear();
InspectResultGrid.Columns.Add(new DataGridTextColumn
{
Header = "编号",
Binding = new System.Windows.Data.Binding("RowNo"),
IsReadOnly = true,
Width = 80
});
for (int i = 0; i < _vm.DataPointColumns.Count; i++)
{
var col = _vm.DataPointColumns[i];
var binding = new System.Windows.Data.Binding($"Cells[{i}].Value")
{
UpdateSourceTrigger = System.Windows.Data.UpdateSourceTrigger.PropertyChanged,
Mode = System.Windows.Data.BindingMode.TwoWay
};
InspectResultGrid.Columns.Add(new DataGridTextColumn
{
Header = col.PointName ?? $"点{i + 1}",
Binding = binding,
Width = 90,
IsReadOnly = false
});
InitializeComponent();
Loaded += OnLoaded;
DataContextChanged += OnDataContextChanged;
Unloaded += (_, _) => DetachViewModel();
}
InspectResultGrid.Columns.Add(new DataGridTextColumn
private void OnLoaded(object sender, RoutedEventArgs e)
{
Header = "实验结果",
Binding = new System.Windows.Data.Binding("InspectResultText"),
IsReadOnly = true,
Width = 90
});
}
// 兜底AutoWireViewModel 可能在构造函数订阅 DataContextChanged 之前就设置了 DataContext
AttachViewModel(DataContext as RubberQuickTestOperationViewModel);
}
private void InspectResultGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (_vm == null) return;
_vm.SelectedInspectRow = InspectResultGrid.SelectedItem as QuickTestInspectRowViewModel;
}
private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
DetachViewModel();
AttachViewModel(DataContext as RubberQuickTestOperationViewModel);
}
private void AttachViewModel(RubberQuickTestOperationViewModel? vm)
{
if (vm == null || ReferenceEquals(_vm, vm)) return;
_vm = vm;
_vm.InspectColumnsChanged += RebuildInspectColumns;
_vm.DataPointColumns.CollectionChanged += OnDataPointColumnsChanged;
RebuildInspectColumns();
}
private void DetachViewModel()
{
if (_vm == null) return;
_vm.InspectColumnsChanged -= RebuildInspectColumns;
_vm.DataPointColumns.CollectionChanged -= OnDataPointColumnsChanged;
_vm = null;
}
private void OnDataPointColumnsChanged(object? sender, NotifyCollectionChangedEventArgs e)
=> RebuildInspectColumns();
private void RebuildInspectColumns()
{
if (!Dispatcher.CheckAccess())
{
Dispatcher.Invoke(RebuildInspectColumns);
return;
}
var vm = _vm ?? DataContext as RubberQuickTestOperationViewModel;
if (vm == null) return;
var centerTextStyle = (Style)FindResource("DataGridCellCenterTextStyle");
var centerEditStyle = (Style)FindResource("DataGridCellCenterEditStyle");
InspectResultGrid.Columns.Clear();
InspectResultGrid.Columns.Add(new DataGridTextColumn
{
Header = "编号",
Binding = new Binding(nameof(QuickTestInspectRowViewModel.RowNo))
{
Mode = BindingMode.OneWay
},
IsReadOnly = true,
Width = 80,
ElementStyle = centerTextStyle
});
for (int i = 0; i < vm.DataPointColumns.Count; i++)
{
var col = vm.DataPointColumns[i];
var columnIndex = i;
var header = string.IsNullOrWhiteSpace(col.PointName)
? $"数据点{columnIndex + 1}"
: col.PointName;
var valueBinding = new Binding($"Cells[{columnIndex}].Value")
{
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
Mode = vm.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay,
TargetNullValue = string.Empty
};
if (vm.IsReadOnly)
valueBinding.StringFormat = "N2";
InspectResultGrid.Columns.Add(new DataGridTextColumn
{
Header = header,
Binding = valueBinding,
Width = 100,
IsReadOnly = vm.IsReadOnly,
ElementStyle = centerTextStyle,
EditingElementStyle = centerEditStyle
});
}
InspectResultGrid.Columns.Add(new DataGridTextColumn
{
Header = "实验结果",
Binding = new Binding(nameof(QuickTestInspectRowViewModel.InspectResultText))
{
Mode = BindingMode.OneWay
},
IsReadOnly = true,
Width = 90,
ElementStyle = centerTextStyle
});
}
private void InspectResultGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var vm = _vm ?? DataContext as RubberQuickTestOperationViewModel;
if (vm == null) return;
vm.SelectedInspectRow = InspectResultGrid.SelectedItem as QuickTestInspectRowViewModel;
}
}

View File

@@ -0,0 +1,130 @@
<UserControl x:Class="YY.Admin.Views.RubberQuickTest.RubberQuickTestRecordDetailDialogView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:prism="http://prismlibrary.com/"
xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.WPF;assembly=LiveChartsCore.SkiaSharpView.WPF"
prism:ViewModelLocator.AutoWireViewModel="True"
mc:Ignorable="d"
Width="1100"
MinHeight="680">
<Grid Background="{DynamicResource ThirdlyRegionBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<hc:SimplePanel Margin="20">
<TextBlock FontSize="18" Foreground="{DynamicResource PrimaryTextBrush}"
Text="胶料快检记录详情" HorizontalAlignment="Left"/>
<Button Width="22" Height="22" Command="hc:ControlCommands.Close"
Style="{StaticResource ButtonIcon}" Foreground="{DynamicResource PrimaryBrush}"
hc:IconElement.Geometry="{StaticResource ErrorGeometry}"
Padding="0" HorizontalAlignment="Right" VerticalAlignment="Top"/>
</hc:SimplePanel>
<hc:ScrollViewer Grid.Row="1" IsInertiaEnabled="True">
<StackPanel Margin="20,0,20,0">
<hc:Row Gutter="10">
<hc:Col Span="8">
<hc:TextBox Text="{Binding Record.RecordNo, Mode=OneWay}" IsReadOnly="True"
hc:InfoElement.Title="快检记录号" hc:InfoElement.TitleWidth="90" Margin="0,0,0,8"/>
</hc:Col>
<hc:Col Span="8">
<hc:TextBox Text="{Binding Record.ProductionDate, Mode=OneWay, StringFormat={}{0:yyyy-MM-dd}}" IsReadOnly="True"
hc:InfoElement.Title="密炼日期" hc:InfoElement.TitleWidth="90" Margin="0,0,0,8"/>
</hc:Col>
<hc:Col Span="8">
<hc:TextBox Text="{Binding Record.ProdEquipmentName, Mode=OneWay}" IsReadOnly="True"
hc:InfoElement.Title="密炼机台" hc:InfoElement.TitleWidth="90" Margin="0,0,0,8"/>
</hc:Col>
<hc:Col Span="8">
<hc:TextBox Text="{Binding Record.ProductionPlanNo, Mode=OneWay}" IsReadOnly="True"
hc:InfoElement.Title="密炼计划" hc:InfoElement.TitleWidth="90" Margin="0,0,0,8"/>
</hc:Col>
<hc:Col Span="8">
<hc:TextBox Text="{Binding Record.RubberMaterialName, Mode=OneWay}" IsReadOnly="True"
hc:InfoElement.Title="胶料名称" hc:InfoElement.TitleWidth="90" Margin="0,0,0,8"/>
</hc:Col>
<hc:Col Span="8">
<hc:TextBox Text="{Binding Record.StdName, Mode=OneWay}" IsReadOnly="True"
hc:InfoElement.Title="实验标准" hc:InfoElement.TitleWidth="90" Margin="0,0,0,8"/>
</hc:Col>
<hc:Col Span="8">
<hc:TextBox Text="{Binding Record.TestMethodName, Mode=OneWay}" IsReadOnly="True"
hc:InfoElement.Title="实验方法" hc:InfoElement.TitleWidth="90" Margin="0,0,0,8"/>
</hc:Col>
<hc:Col Span="8">
<hc:TextBox Text="{Binding Record.QuickTestTypeName, Mode=OneWay}" IsReadOnly="True"
hc:InfoElement.Title="实验类型" hc:InfoElement.TitleWidth="90" Margin="0,0,0,8"/>
</hc:Col>
<hc:Col Span="8">
<hc:TextBox Text="{Binding Record.TrainNo, Mode=OneWay}" IsReadOnly="True"
hc:InfoElement.Title="车次" hc:InfoElement.TitleWidth="90" Margin="0,0,0,8"/>
</hc:Col>
<hc:Col Span="8">
<hc:TextBox Text="{Binding Record.InspectTimes, Mode=OneWay}" IsReadOnly="True"
hc:InfoElement.Title="试验次数" hc:InfoElement.TitleWidth="90" Margin="0,0,0,8"/>
</hc:Col>
<hc:Col Span="8">
<hc:TextBox Text="{Binding Record.InspectorRealname, Mode=OneWay}" IsReadOnly="True"
hc:InfoElement.Title="检验人" hc:InfoElement.TitleWidth="90" Margin="0,0,0,8"/>
</hc:Col>
<hc:Col Span="8">
<hc:TextBox Text="{Binding Record.CreateTime, Mode=OneWay, StringFormat={}{0:yyyy-MM-dd HH:mm}}" IsReadOnly="True"
hc:InfoElement.Title="检验日期" hc:InfoElement.TitleWidth="90" Margin="0,0,0,8"/>
</hc:Col>
<hc:Col Span="8">
<hc:TextBox Text="{Binding InspectResultDisplay, Mode=OneWay}" IsReadOnly="True"
hc:InfoElement.Title="是否合格" hc:InfoElement.TitleWidth="90" Margin="0,0,0,8"/>
</hc:Col>
</hc:Row>
<TextBlock Text="温度曲线" FontWeight="SemiBold" Margin="0,8,0,6"/>
<Border Height="200" Margin="0,0,0,12">
<lvc:CartesianChart Series="{Binding TemperatureSeries}"
XAxes="{Binding TemperatureXAxes}"
YAxes="{Binding TemperatureYAxes}"
LegendPosition="Top"/>
</Border>
<TextBlock Text="S'曲线" FontWeight="SemiBold" Margin="0,0,0,6"/>
<Border Height="200" Margin="0,0,0,12">
<lvc:CartesianChart Series="{Binding TorqueSeries}"
XAxes="{Binding TorqueXAxes}"
YAxes="{Binding TorqueYAxes}"
LegendPosition="Top"/>
</Border>
<TextBlock Text="数据标准" FontWeight="SemiBold" Margin="0,0,0,6"/>
<DataGrid ItemsSource="{Binding StdLines}" AutoGenerateColumns="False" IsReadOnly="True"
MaxHeight="180" Margin="0,0,0,12">
<DataGrid.Columns>
<DataGridTextColumn Header="数据点" Binding="{Binding PointName}" Width="*"/>
<DataGridTextColumn Header="下限值" Binding="{Binding LowerLimit}" Width="100"/>
<DataGridTextColumn Header="上限值" Binding="{Binding UpperLimit}" Width="100"/>
</DataGrid.Columns>
</DataGrid>
<TextBlock Text="试验结果" FontWeight="SemiBold" Margin="0,0,0,6"/>
<DataGrid ItemsSource="{Binding RawLines}" AutoGenerateColumns="False" IsReadOnly="True"
MaxHeight="220">
<DataGrid.Columns>
<DataGridTextColumn Header="编号" Binding="{Binding RowNo}" Width="80"/>
<DataGridTextColumn Header="数据点" Binding="{Binding InspectItem}" Width="*"/>
<DataGridTextColumn Header="检测值" Binding="{Binding InspectValue}" Width="100"/>
<DataGridTextColumn Header="行结果" Binding="{Binding RowInspectResult}" Width="80"/>
</DataGrid.Columns>
</DataGrid>
</StackPanel>
</hc:ScrollViewer>
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right" Margin="20">
<Button Content="关闭" Command="hc:ControlCommands.Close" Style="{StaticResource ButtonDefault}" Width="90"/>
</StackPanel>
</Grid>
</UserControl>

View File

@@ -0,0 +1,9 @@
namespace YY.Admin.Views.RubberQuickTest;
public partial class RubberQuickTestRecordDetailDialogView
{
public RubberQuickTestRecordDetailDialogView()
{
InitializeComponent();
}
}

View File

@@ -0,0 +1,109 @@
<UserControl x:Class="YY.Admin.Views.RubberQuickTest.RubberQuickTestRecordListView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True">
<Grid Style="{StaticResource BaseViewStyle}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Border Grid.Row="0" CornerRadius="4" Margin="0 0 -10 0">
<hc:Row>
<hc:Col Layout="{hc:ColLayout Xs=12, Sm=8, Md=6, Lg=4, Xl=4}">
<hc:TextBox Text="{Binding FilterRecordNo, UpdateSourceTrigger=PropertyChanged}"
Margin="0 0 10 10" hc:InfoElement.Title="快检记录号"
hc:InfoElement.TitlePlacement="Left" hc:InfoElement.TitleWidth="80"
hc:InfoElement.ShowClearButton="True">
<hc:TextBox.InputBindings>
<KeyBinding Key="Enter" Command="{Binding SearchCommand}"/>
</hc:TextBox.InputBindings>
</hc:TextBox>
</hc:Col>
<hc:Col Layout="{hc:ColLayout Xs=12, Sm=8, Md=6, Lg=4, Xl=4}">
<hc:TextBox Text="{Binding FilterRubberMaterialName, UpdateSourceTrigger=PropertyChanged}"
Margin="0 0 10 10" hc:InfoElement.Title="胶料名称"
hc:InfoElement.TitlePlacement="Left" hc:InfoElement.TitleWidth="80"
hc:InfoElement.ShowClearButton="True"/>
</hc:Col>
<hc:Col Layout="{hc:ColLayout Xs=12, Sm=8, Md=6, Lg=4, Xl=4}">
<hc:TextBox Text="{Binding FilterPlanNo, UpdateSourceTrigger=PropertyChanged}"
Margin="0 0 10 10" hc:InfoElement.Title="密炼计划"
hc:InfoElement.TitlePlacement="Left" hc:InfoElement.TitleWidth="80"
hc:InfoElement.ShowClearButton="True"/>
</hc:Col>
</hc:Row>
</Border>
<Border Grid.Row="1" Margin="0,10">
<hc:UniformSpacingPanel Spacing="10">
<Button Style="{StaticResource ButtonPrimary}" Command="{Binding SearchCommand}">
<StackPanel Orientation="Horizontal">
<md:PackIcon Kind="Search"/>
<TextBlock Text="搜索" Style="{StaticResource IconButtonStyle}"/>
</StackPanel>
</Button>
<Button Style="{StaticResource ButtonDefault}" Command="{Binding ResetCommand}">
<StackPanel Orientation="Horizontal">
<md:PackIcon Kind="Refresh"/>
<TextBlock Text="重置" Style="{StaticResource IconButtonStyle}"/>
</StackPanel>
</Button>
<Button Style="{StaticResource ButtonSuccess}" Command="{Binding AddCommand}">
<StackPanel Orientation="Horizontal">
<md:PackIcon Kind="Plus"/>
<TextBlock Text="新增" Style="{StaticResource IconButtonStyle}"/>
</StackPanel>
</Button>
</hc:UniformSpacingPanel>
</Border>
<DataGrid Grid.Row="2" ItemsSource="{Binding Records}" AutoGenerateColumns="False" IsReadOnly="True"
CanUserAddRows="False" SelectionMode="Single" HeadersVisibility="All"
Style="{StaticResource CusDataGridStyle}" ColumnHeaderStyle="{StaticResource CusDataGridColumnHeaderStyle}">
<DataGrid.Columns>
<DataGridTextColumn Header="快检记录号" Binding="{Binding RecordNo}" Width="160"/>
<DataGridTextColumn Header="密炼日期" Binding="{Binding ProductionDate, StringFormat='yyyy-MM-dd'}" Width="100"/>
<DataGridTextColumn Header="密炼机台" Binding="{Binding ProdEquipmentName}" Width="100"/>
<DataGridTextColumn Header="班次" Binding="{Binding WorkShiftDisplay}" Width="70"/>
<DataGridTextColumn Header="密炼计划" Binding="{Binding ProductionPlanNo}" Width="110"/>
<DataGridTextColumn Header="胶料名称" Binding="{Binding RubberMaterialName}" Width="120"/>
<DataGridTextColumn Header="实验标准" Binding="{Binding StdName}" Width="120"/>
<DataGridTextColumn Header="实验方法" Binding="{Binding TestMethodName}" Width="100"/>
<DataGridTextColumn Header="实验类型" Binding="{Binding QuickTestTypeName}" Width="100"/>
<DataGridTextColumn Header="车次" Binding="{Binding TrainNo}" Width="70"/>
<DataGridTextColumn Header="试验次数" Binding="{Binding InspectTimes}" Width="80"/>
<DataGridTextColumn Header="检验人" Binding="{Binding InspectorRealname}" Width="80"/>
<DataGridTextColumn Header="检验日期" Binding="{Binding InspectDate, StringFormat='yyyy-MM-dd HH:mm'}" Width="130"/>
<DataGridTextColumn Header="是否合格" Binding="{Binding InspectResultDisplay}" Width="80"/>
<DataGridTextColumn Header="同步状态" Binding="{Binding SyncStatusDisplay}" Width="80"/>
<DataGridTemplateColumn Header="操作" Width="150">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Button Content="详情" Command="{Binding DataContext.ViewDetailCommand, RelativeSource={RelativeSource AncestorType=DataGrid}}"
CommandParameter="{Binding}" Style="{StaticResource ButtonPrimary}" Height="26" Padding="8,0" Margin="0,0,6,0"/>
<Button Content="删除" Command="{Binding DataContext.DeleteCommand, RelativeSource={RelativeSource AncestorType=DataGrid}}"
CommandParameter="{Binding}" Style="{StaticResource ButtonDanger}" Height="26" Padding="8,0"
Visibility="{Binding CanDelete, Converter={StaticResource Boolean2VisibilityConverter}}"/>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
<StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,10,0,0">
<TextBlock Text="{Binding Total, StringFormat=共 {0} 条}" VerticalAlignment="Center" Margin="0,0,16,0"
Foreground="{DynamicResource SecondaryTextBrush}"/>
<Button Content="上一页" Command="{Binding PrevPageCommand}" Style="{StaticResource ButtonDefault}" Margin="0,0,4,0" Width="80"/>
<TextBlock Text="{Binding PageNo, StringFormat=第 {0} 页}" VerticalAlignment="Center" Margin="8,0"/>
<Button Content="下一页" Command="{Binding NextPageCommand}" Style="{StaticResource ButtonDefault}" Width="80"/>
</StackPanel>
</Grid>
</UserControl>

View File

@@ -0,0 +1,11 @@
using System.Windows.Controls;
namespace YY.Admin.Views.RubberQuickTest;
public partial class RubberQuickTestRecordListView : UserControl
{
public RubberQuickTestRecordListView()
{
InitializeComponent();
}
}

View File

@@ -39,6 +39,11 @@
hc:InfoElement.Title="实验方法" hc:InfoElement.TitleWidth="90" hc:InfoElement.TitlePlacement="Left"
Margin="0,0,0,12"/>
</hc:Col>
<hc:Col Span="12">
<hc:TextBox Text="{Binding Std.QuickTestTypeName, Mode=OneWay}" IsReadOnly="True"
hc:InfoElement.Title="实验类型" hc:InfoElement.TitleWidth="90" hc:InfoElement.TitlePlacement="Left"
Margin="0,0,0,12"/>
</hc:Col>
<hc:Col Span="12">
<hc:TextBox Text="{Binding Std.RubberMaterialName, Mode=OneWay}" IsReadOnly="True"
hc:InfoElement.Title="胶料名称" hc:InfoElement.TitleWidth="90" hc:InfoElement.TitlePlacement="Left"

View File

@@ -88,9 +88,10 @@
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto">
<DataGrid.Columns>
<DataGridTextColumn Header="实验标准名称" Binding="{Binding StdName}" CellStyle="{StaticResource CusDataGridCellStyle}" Width="180"/>
<DataGridTextColumn Header="实验方法" Binding="{Binding TestMethodName}" CellStyle="{StaticResource CusDataGridCellStyle}" Width="140"/>
<DataGridTextColumn Header="胶料名称" Binding="{Binding RubberMaterialName}" CellStyle="{StaticResource CusDataGridCellStyle}" Width="140"/>
<DataGridTextColumn Header="实验标准名称" Binding="{Binding StdName}" CellStyle="{StaticResource CusDataGridCellStyle}" Width="160"/>
<DataGridTextColumn Header="实验方法" Binding="{Binding TestMethodName}" CellStyle="{StaticResource CusDataGridCellStyle}" Width="120"/>
<DataGridTextColumn Header="实验类型" Binding="{Binding QuickTestTypeName}" CellStyle="{StaticResource CusDataGridCellStyle}" Width="100"/>
<DataGridTextColumn Header="胶料名称" Binding="{Binding RubberMaterialName}" CellStyle="{StaticResource CusDataGridCellStyle}" Width="120"/>
<DataGridTextColumn Header="发行编号" Binding="{Binding IssueNumber}" CellStyle="{StaticResource CusDataGridCellStyle}" Width="120"/>
<DataGridTextColumn Header="发行部门" Binding="{Binding IssueDeptName}" CellStyle="{StaticResource CusDataGridCellStyle}" Width="120"/>
<DataGridTextColumn Header="启用状态" Binding="{Binding EnableStatusText}" CellStyle="{StaticResource CusDataGridCellStyle}" Width="90"/>