index.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. import PageContent from '@/components/PageContent';
  2. import PageTitle from '@/components/PageTitle';
  3. import TabsContent from '@/components/TabsContent';
  4. import {
  5. getHistoryRecord,
  6. queryProjectConfig,
  7. querySimulationProfit,
  8. } from '@/services/SmartOps';
  9. import { getPatrolPerception } from '@/services/dumu';
  10. import { GetTokenFromUrl, UnityAction } from '@/utils/utils';
  11. import {
  12. connect,
  13. useNavigate,
  14. useParams,
  15. useRequest,
  16. useSearchParams,
  17. } from '@umijs/max';
  18. import { Tabs } from 'antd';
  19. import dayjs from 'dayjs';
  20. import { useEffect, useMemo, useRef, useState } from 'react';
  21. import Analysis from './Analysis';
  22. import DeviceAnalysis from './components/DeviceAnalysis';
  23. import VideoAnalysis from './components/VideoAnalysis';
  24. import WorkAnalysis from './components/WorkAnalysis';
  25. import styles from './index.less';
  26. const { TabPane } = Tabs;
  27. const icon06 = require('@/assets/smartOps/icon06.png');
  28. const icon07 = require('@/assets/smartOps/icon07.png');
  29. let timer = '';
  30. function SmartOps(props) {
  31. const { list, dispatch, loading, loadingDev, autoReport } = props;
  32. const navigate = useNavigate();
  33. const { projectId } = useParams();
  34. const [searchParams, setSearchParams] = useSearchParams();
  35. const time = searchParams.get('time');
  36. const idList = searchParams.get('idList');
  37. const patrolId = searchParams.get('patrolId');
  38. const [videoNum, setVideoNum] = useState(0);
  39. const signalRef = useRef();
  40. const {
  41. data: reportData,
  42. loading: reportLoading,
  43. run: getReportData,
  44. } = useRequest(
  45. () =>
  46. getHistoryRecord(
  47. convertObject2FormData({ project_id: Number(projectId) }),
  48. ),
  49. {
  50. manual: true,
  51. formatResult: (res) => {
  52. let data = res.data.list[0];
  53. data.Num2Length = data.Num2.split(',').length;
  54. return data;
  55. },
  56. },
  57. );
  58. const [sTime, eTime] = useMemo(() => {
  59. let sTime = null,
  60. eTime = null;
  61. if (time) {
  62. eTime = time;
  63. sTime = dayjs(eTime).subtract(10, 'minute').format('YYYY-MM-DD HH:mm:ss');
  64. } else if (reportData) {
  65. eTime = reportData.CTime;
  66. sTime = dayjs(eTime).subtract(10, 'minute').format('YYYY-MM-DD HH:mm:ss');
  67. }
  68. return [sTime, eTime];
  69. }, [reportData]);
  70. const initDate = () => {
  71. //工艺分析
  72. dispatch({
  73. type: 'smartOps/queryList',
  74. payload: {
  75. project_id: projectId * 1,
  76. projectId: projectId * 1,
  77. ids: idList || reportData.Num2,
  78. page_size: 999,
  79. isNewRole: [46, 65, 92, 94].includes(projectId * 1),
  80. },
  81. callback: (data) => {
  82. UnityAction.sendMsg('ProcessAnalysis', JSON.stringify(data?.list));
  83. },
  84. });
  85. dispatch({
  86. type: 'eqSelfInspection/getPatrolDataById',
  87. payload: {
  88. routeId: patrolId || reportData.PatrolId,
  89. },
  90. callback: (data) => {
  91. // console.log(data);
  92. const message = data?.extendWarningAllData?.map((item) => {
  93. return {
  94. DeviceCode: item.DeviceCode,
  95. grade_alarm: item.Status === 2 || item.Status === 1 ? 1 : 2,
  96. };
  97. });
  98. UnityAction.sendMsg('DevAnalysis', JSON.stringify(message));
  99. },
  100. });
  101. };
  102. const handlerHistoryClick = () => {
  103. navigate(
  104. `/smart-ops/history-record/${projectId}?JWT-TOKEN=${GetTokenFromUrl()}`,
  105. );
  106. };
  107. const handlerRecordClick = () => {
  108. navigate(
  109. `/smart-ops/operation-record/${projectId}?JWT-TOKEN=${GetTokenFromUrl()}`,
  110. );
  111. };
  112. // 工况分析
  113. const {
  114. data: workAnalysisRequest,
  115. run: runWork,
  116. loading: loadingWork,
  117. } = useRequest(
  118. () =>
  119. queryProjectConfig({
  120. project_id: projectId,
  121. s_time: sTime,
  122. e_time: eTime,
  123. }),
  124. {
  125. manual: true,
  126. onSuccess(res) {
  127. if (!res) return;
  128. UnityAction.sendMsg(
  129. 'WorkAnalysis',
  130. JSON.stringify(res.project_categorys),
  131. );
  132. },
  133. },
  134. );
  135. const optimizationNumber = workAnalysisRequest?.optimizationNumber || 0;
  136. //感知分析
  137. const {
  138. data: videoData,
  139. loading: loadingVideo,
  140. run: runVideo,
  141. } = useRequest(
  142. () =>
  143. getPatrolPerception({
  144. project_id: projectId * 1,
  145. patrol_id: patrolId || reportData?.PatrolId,
  146. }),
  147. {
  148. onSuccess: (data) => {
  149. const count1 = data.dumu_list?.length || 0;
  150. const count2 =
  151. data.environment_list?.filter((item) => item.status)?.length || 0;
  152. const count3 =
  153. data.fluid_level_list?.filter((item) => item.status)?.length || 0;
  154. setVideoNum(count1 + count2 + count3);
  155. const Cam = data.dumu_list?.map((item) => item.device_name) || [];
  156. const Dev1 =
  157. data.environment_list?.map((item) => {
  158. return { DeviceCode: item.device_code, grade_alarm: item.status };
  159. }) || [];
  160. const Dev2 =
  161. data.fluid_level_list?.map((item) => {
  162. return { DeviceCode: item.device_code, grade_alarm: item.status };
  163. }) || [];
  164. const params = { Cam, Dev: [...Dev1, ...Dev2] };
  165. },
  166. },
  167. );
  168. const AnalysisNumber = list?.pagenation?.total || 0;
  169. // 利润
  170. const { data: profitData, run: getProfit } = useRequest(
  171. () =>
  172. querySimulationProfit({
  173. project_id: projectId,
  174. s_time: dayjs(eTime).subtract(1, 'day').format('YYYY-MM-DD HH:mm:ss'),
  175. e_time: eTime,
  176. }),
  177. {
  178. formatResult(data) {
  179. if (!data?.info) return '-';
  180. return Object.values(data.info).reduce(
  181. (total, currentValue) => total + currentValue,
  182. 0,
  183. );
  184. },
  185. manual: true,
  186. },
  187. );
  188. const showTime = useMemo(() => {
  189. if (!eTime) return '';
  190. return dayjs(eTime).format('MM-DD HH:mm');
  191. }, [eTime]);
  192. const onChangeTab = (type) => {
  193. UnityAction.sendMsg('SmartAnalysisTab', type);
  194. };
  195. useEffect(() => {
  196. if (!eTime) return;
  197. initDate();
  198. runWork();
  199. runVideo();
  200. getProfit();
  201. }, [eTime]);
  202. useEffect(() => {
  203. if (!time) {
  204. getReportData();
  205. console.log('--------10分钟刷新数据--------', eTime);
  206. timer = setInterval(() => {
  207. getReportData();
  208. }, 60000);
  209. }
  210. dispatch({
  211. type: 'smartOps/queryProcessSection',
  212. payload: projectId,
  213. });
  214. // 通知unity当前处于工况分析
  215. UnityAction.sendMsg('SmartAnalysisTab', 1);
  216. const controller = new AbortController();
  217. signalRef.current = controller;
  218. return () => {
  219. signalRef.current.abort();
  220. clearInterval(timer);
  221. };
  222. }, []);
  223. return (
  224. <PageContent>
  225. <PageTitle returnable={time}>智慧分析</PageTitle>
  226. <div className={`card-box ${styles.topContent}`}>
  227. <div className={styles.titleContent}>
  228. <span className={styles.time}>{showTime}</span>
  229. {!time && (
  230. <div style={{ display: 'flex' }}>
  231. <div className={styles.iconLeft} onClick={handlerHistoryClick} />
  232. <div className={styles.iconRight} onClick={handlerRecordClick} />
  233. </div>
  234. )}
  235. </div>
  236. <div className={styles.middle}>
  237. <div className={styles.left}>
  238. <div className={styles.in} />
  239. <div className={styles.out} />
  240. </div>
  241. <div className={styles.right}>
  242. <div className={styles.item1}>
  243. 工况分析:
  244. {optimizationNumber > 0
  245. ? `${optimizationNumber}项可优化`
  246. : '暂无优化'}
  247. </div>
  248. <div className={styles.item2}>
  249. 工艺分析:
  250. {list?.pagenation?.total > 0
  251. ? `${list?.pagenation?.total}项可优化`
  252. : '暂无优化'}
  253. </div>
  254. <div className={styles.item3}>
  255. 感知分析:
  256. {videoNum > 0 ? `${videoNum}项可优化` : '暂无优化'}
  257. </div>
  258. </div>
  259. </div>
  260. <div className={styles.text}>通过智慧分析预计可省{profitData}元</div>
  261. </div>
  262. <div className={styles.tabContent}>
  263. <TabsContent
  264. defaultActiveKey="1"
  265. items={[
  266. {
  267. label: `工况分析(${loadingWork ? '-' : optimizationNumber})`,
  268. key: '1',
  269. children: (
  270. <WorkAnalysis
  271. workAnalysisRequest={workAnalysisRequest}
  272. projectId={projectId}
  273. loading={loadingWork}
  274. eTime={eTime}
  275. />
  276. ),
  277. },
  278. {
  279. label: `设备分析(${
  280. loadingDev ? '-' : autoReport?.extendWarningData?.length
  281. })`,
  282. key: '4',
  283. children: <DeviceAnalysis />,
  284. },
  285. {
  286. label: `工艺分析(${loading ? '-' : AnalysisNumber})`,
  287. key: '2',
  288. children: <Analysis />,
  289. },
  290. {
  291. label: `感知分析(${loadingVideo ? '-' : videoNum})`,
  292. key: '3',
  293. children: (
  294. <VideoAnalysis
  295. videoNum={videoNum}
  296. videoData={videoData}
  297. loading={loadingVideo}
  298. />
  299. ),
  300. },
  301. ]}
  302. onChange={onChangeTab}
  303. />
  304. </div>
  305. </PageContent>
  306. );
  307. }
  308. const convertObject2FormData = (params) => {
  309. const formData = new FormData();
  310. Object.entries(params).forEach(([key, value]) => {
  311. if (value !== null && value !== undefined && value !== NaN) {
  312. formData.append(key, value);
  313. }
  314. });
  315. return formData;
  316. };
  317. export default connect(({ smartOps, eqSelfInspection, loading }) => ({
  318. list: smartOps.list,
  319. loading: loading.models.smartOps,
  320. processList: smartOps.processList,
  321. autoReport: eqSelfInspection.autoReport,
  322. loadingDev: loading.effects['eqSelfInspection/getPatrolDataById'],
  323. }))(SmartOps);