index.js 12 KB

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