dsStop.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="分析天数" prop="remark">
  5. <el-select
  6. v-model="queryParams.remark"
  7. placeholder="请选择分析天数"
  8. clearable
  9. style="width: 150px;"
  10. @change="handleDaysChange"
  11. >
  12. <el-option label="月(30天)" value="30"></el-option>
  13. <el-option label="季度(90天)" value="90"></el-option>
  14. <el-option label="半年(180天)" value="180"></el-option>
  15. <el-option label="年(365天)" value="365"></el-option>
  16. </el-select>
  17. </el-form-item>
  18. <el-form-item label="机台号" prop="deviceId">
  19. <el-input
  20. v-model="queryParams.deviceId"
  21. placeholder="请输入机台号"
  22. clearable
  23. @input="handleDeviceIdChange"
  24. />
  25. </el-form-item>
  26. <el-form-item label="分析结果" prop="result">
  27. <el-select
  28. v-model="queryParams.result"
  29. placeholder="请选择分析结果"
  30. clearable
  31. style="width: 150px;"
  32. @change="handleResultChange"
  33. >
  34. <el-option label="平稳" value="平稳"></el-option>
  35. <el-option label="上升" value="上升"></el-option>
  36. <el-option label="明显上升" value="明显上升"></el-option>
  37. <el-option label="下降" value="下降"></el-option>
  38. <el-option label="明显下降" value="明显下降"></el-option>
  39. </el-select>
  40. </el-form-item>
  41. <el-form-item>
  42. <el-button type="primary" icon="Search" @click="handleFilter">搜索</el-button>
  43. <el-button icon="Refresh" @click="resetFilter">重置</el-button>
  44. </el-form-item>
  45. </el-form>
  46. <!-- 总体统计数据展示 -->
  47. <el-card class="statistic-card" v-if="statistics">
  48. <div class="statistic-container">
  49. <div class="statistic-item">
  50. <div class="statistic-label">设备总数:</div>
  51. <div class="statistic-value">{{ statistics.totalDevices }}</div>
  52. </div>
  53. <div class="statistic-divider"></div>
  54. <div class="statistic-item" v-for="(count, key) in statistics.trendCounts" :key="key">
  55. <div class="statistic-label">{{ key }}:</div>
  56. <div class="statistic-value">{{ count }}</div>
  57. </div>
  58. </div>
  59. <!-- 群体分析结果展示 -->
  60. <div class="group-analysis" v-if="groupAnalysisResult">
  61. <el-alert
  62. :title="groupAnalysisResult.message"
  63. :type="groupAnalysisResult.type"
  64. show-icon
  65. :closable="false"
  66. />
  67. </div>
  68. </el-card>
  69. <el-table v-loading="loading" :data="filteredData" @selection-change="handleSelectionChange">
  70. <el-table-column type="selection" width="55" align="center"/>
  71. <!-- <el-table-column label="ID" align="center" prop="id" />-->
  72. <el-table-column label="机台号" align="center" prop="deviceId"/>
  73. <el-table-column label="数据量" align="center" prop="dataNum"/>
  74. <el-table-column label="斜率" align="center" prop="slope">
  75. <template #default="scope">
  76. {{ (scope.row.slope).toFixed(2) }}
  77. </template>
  78. </el-table-column>
  79. <el-table-column label="标准差" align="center" prop="stdDev">
  80. <template #default="scope">
  81. {{ (scope.row.stdDev).toFixed(2) }}
  82. </template>
  83. </el-table-column>
  84. <el-table-column label="趋势分析" align="center" prop="result">
  85. <template #default="scope">
  86. <el-link type="primary" @click="handleResultClick(scope.row)">{{ scope.row.result }}</el-link>
  87. </template>
  88. </el-table-column>
  89. </el-table>
  90. <!-- 图表弹窗 -->
  91. <el-dialog :title="'设备[' + currentRow.deviceId + ']分析结果详情'" v-model="chartOpen" width="800px" append-to-body>
  92. <div style="text-align: center; margin: 20px 0;">
  93. <p>设备名称: {{ currentRow.deviceName }}</p>
  94. <p>分析结果: {{ currentRow.result }}</p>
  95. </div>
  96. <div v-if="currentRow.list && currentRow.list.length > 0">
  97. <!-- 使用ECharts展示折线图 -->
  98. <div ref="chartRef" style="width: 100%; height: 400px;"></div>
  99. </div>
  100. <div v-else>
  101. <p style="text-align: center;">暂无详细数据</p>
  102. </div>
  103. <template #footer>
  104. <div class="dialog-footer">
  105. <el-button @click="closeChart">关 闭</el-button>
  106. </div>
  107. </template>
  108. </el-dialog>
  109. </div>
  110. </template>
  111. <script setup name="CalcStop">
  112. import {dsStop} from "@/api/calc/calcStop";
  113. import {getCurrentInstance, reactive, ref, toRefs, watch} from 'vue';
  114. import * as echarts from 'echarts';
  115. const {proxy} = getCurrentInstance();
  116. const calcStopList = ref([]);
  117. const filteredData = ref([]);
  118. const open = ref(false);
  119. const chartOpen = ref(false); // 添加图表弹窗状态
  120. const loading = ref(true);
  121. const showSearch = ref(true);
  122. const ids = ref([]);
  123. const single = ref(true);
  124. const multiple = ref(true);
  125. const total = ref(0);
  126. const title = ref("");
  127. const currentRow = ref({}); // 添加当前行数据
  128. const chartRef = ref(null);
  129. const statistics = ref(null); // 添加统计数据
  130. const groupAnalysisResult = ref(null); // 群体分析结果
  131. let chartInstance = null;
  132. const data = reactive({
  133. form: {},
  134. queryParams: {
  135. pageNum: 1,
  136. pageSize: 1000,
  137. deviceId: null,
  138. dataDate: null,
  139. hour: null,
  140. startTime: null,
  141. endTime: null,
  142. stopType: 2,
  143. result: "", // 设置默认选中值
  144. remark: "90" // 默认选中90天(季度)
  145. },
  146. rules: {}
  147. });
  148. const {queryParams, form, rules} = toRefs(data);
  149. // 分析天数变化处理
  150. function handleDaysChange() {
  151. getList(); // 分析天数变化时重新从后端获取数据
  152. }
  153. /** 查询停机数据统计列表 */
  154. function getList() {
  155. loading.value = true;
  156. // 将分析天数作为参数传递给后端
  157. dsStop(queryParams.value).then(response => {
  158. calcStopList.value = response.data;
  159. filteredData.value = response.data; // 初始化过滤数据
  160. statistics.value = response.statistics; // 保存统计数据
  161. // 在数据加载完成后触发一次过滤,确保默认选中项生效
  162. filterData();
  163. loading.value = false;
  164. });
  165. }
  166. // 计算统计数据
  167. function calculateStatistics(data) {
  168. if (!data || !Array.isArray(data)) {
  169. return;
  170. }
  171. // 计算设备总数
  172. const totalDevices = data.length;
  173. // 统计各趋势的数量
  174. const trendCounts = {
  175. "明显上升": 0,
  176. "上升": 0,
  177. "平稳": 0,
  178. "下降": 0,
  179. "明显下降": 0
  180. };
  181. data.forEach(item => {
  182. if (trendCounts.hasOwnProperty(item.result)) {
  183. trendCounts[item.result]++;
  184. }
  185. });
  186. // 只有在没有从后端获取到统计数据时才使用计算的统计数据
  187. if (!statistics.value) {
  188. statistics.value = {
  189. totalDevices,
  190. trendCounts
  191. };
  192. }
  193. }
  194. // 机台号变化处理
  195. function handleDeviceIdChange() {
  196. filterData();
  197. }
  198. // 分析结果变化处理
  199. function handleResultChange() {
  200. filterData();
  201. }
  202. // 过滤数据
  203. function filterData() {
  204. if (!calcStopList.value || !Array.isArray(calcStopList.value)) {
  205. filteredData.value = [];
  206. return;
  207. }
  208. // 如果没有过滤条件,返回所有数据
  209. if (!queryParams.value.deviceId && !queryParams.value.result) {
  210. filteredData.value = calcStopList.value;
  211. // 重新设置原始统计数据
  212. getList();
  213. return;
  214. }
  215. filteredData.value = calcStopList.value.filter(item => {
  216. // 根据机台号过滤(数字模糊匹配)
  217. if (queryParams.value.deviceId &&
  218. item.deviceId &&
  219. item.deviceId.toString().indexOf(queryParams.value.deviceId) === -1) {
  220. return false;
  221. }
  222. // 根据分析结果过滤
  223. if (queryParams.value.result &&
  224. item.result !== queryParams.value.result) {
  225. return false;
  226. }
  227. return true;
  228. });
  229. // 根据过滤后的数据重新计算统计数据
  230. calculateStatistics(filteredData.value);
  231. }
  232. /** 过滤操作 */
  233. function handleFilter() {
  234. getList(); // 点击搜索按钮时重新从后端获取数据
  235. }
  236. /** 重置过滤操作 */
  237. function resetFilter() {
  238. proxy.resetForm("queryRef");
  239. queryParams.value.deviceId = null;
  240. queryParams.value.remark = null; // 重置分析天数
  241. getList(); // 重置时重新从后端获取数据
  242. }
  243. /** 处理分析结果点击事件 */
  244. function handleResultClick(row) {
  245. currentRow.value = row;
  246. chartOpen.value = true;
  247. // 在弹窗打开后初始化图表
  248. setTimeout(() => {
  249. initChart();
  250. }, 100);
  251. }
  252. // 初始化图表
  253. function initChart() {
  254. if (chartRef.value) {
  255. // 销毁之前的实例
  256. if (chartInstance) {
  257. chartInstance.dispose();
  258. }
  259. // 初始化新的实例
  260. chartInstance = echarts.init(chartRef.value);
  261. // 准备数据
  262. const dates = currentRow.value.list.map(item => item.date);
  263. const times = currentRow.value.list.map(item => item.times);
  264. // 配置图表选项
  265. const option = {
  266. title: {
  267. text: '停机次数趋势图',
  268. left: 'center'
  269. },
  270. tooltip: {
  271. trigger: 'axis'
  272. },
  273. xAxis: {
  274. type: 'category',
  275. data: dates,
  276. name: '日期'
  277. },
  278. yAxis: {
  279. type: 'value',
  280. name: '次数(次)'
  281. },
  282. series: [{
  283. data: times,
  284. type: 'line',
  285. smooth: true,
  286. markPoint: {
  287. data: [
  288. { type: 'max', name: '最大值' },
  289. { type: 'min', name: '最小值' }
  290. ]
  291. },
  292. markLine: {
  293. data: [
  294. { type: 'average', name: '平均值' }
  295. ]
  296. }
  297. }]
  298. };
  299. // 设置配置项
  300. chartInstance.setOption(option);
  301. }
  302. }
  303. /** 关闭图表弹窗 */
  304. function closeChart() {
  305. chartOpen.value = false;
  306. // 销毁图表实例
  307. if (chartInstance) {
  308. chartInstance.dispose();
  309. chartInstance = null;
  310. }
  311. }
  312. // 群体分析算法
  313. function analyzeGroupPattern() {
  314. if (!statistics.value || !statistics.value.trendCounts) {
  315. groupAnalysisResult.value = null;
  316. return;
  317. }
  318. const { trendCounts } = statistics.value;
  319. // 计算上升趋势的设备数量(包括"上升"和"明显上升")
  320. const risingCount = (trendCounts["上升"] || 0) + (trendCounts["明显上升"] || 0);
  321. // 计算总设备数
  322. const totalCount = Object.values(trendCounts).reduce((sum, count) => sum + count, 0);
  323. // 如果没有设备数据,则不显示分析结果
  324. if (totalCount === 0) {
  325. groupAnalysisResult.value = null;
  326. return;
  327. }
  328. // 计算上升趋势设备占比
  329. const risingPercentage = (risingCount / totalCount) * 100;
  330. // 判断标准:如果超过60%的设备呈现上升趋势,则判断为群体上升现象
  331. if (risingPercentage > 60) {
  332. groupAnalysisResult.value = {
  333. type: "warning",
  334. message: `群体分析:${risingPercentage.toFixed(1)}%的设备断纱频次呈上升趋势,判断纱线或环境(温湿度)可能存在质量问题,请重点关注!`
  335. };
  336. } else {
  337. groupAnalysisResult.value = {
  338. type: "success",
  339. message: `群体分析:当前设备断纱频次趋势正常,无明显群体性质量问题。`
  340. };
  341. }
  342. }
  343. // 监听统计数据变化,触发群体分析
  344. watch(statistics, () => {
  345. analyzeGroupPattern();
  346. }, { deep: true });
  347. getList();
  348. </script>
  349. <style scoped>
  350. .statistic-card {
  351. margin-bottom: 20px;
  352. background-color: #f5f7fa;
  353. border: 1px solid #ebeef5;
  354. border-radius: 4px;
  355. }
  356. .statistic-container {
  357. display: flex;
  358. align-items: center;
  359. flex-wrap: wrap;
  360. }
  361. .statistic-item {
  362. display: flex;
  363. align-items: center;
  364. margin-right: 20px;
  365. margin-bottom: 10px;
  366. }
  367. .statistic-label {
  368. font-weight: bold;
  369. margin-right: 5px;
  370. color: #606266;
  371. }
  372. .statistic-value {
  373. font-size: 16px;
  374. font-weight: bold;
  375. color: #409eff;
  376. }
  377. .statistic-divider {
  378. width: 1px;
  379. height: 20px;
  380. background-color: #dcdfe6;
  381. margin-right: 20px;
  382. margin-bottom: 10px;
  383. }
  384. .group-analysis {
  385. margin-top: 15px;
  386. padding-top: 15px;
  387. border-top: 1px solid #ebeef5;
  388. }
  389. </style>