OptimizationTasks.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. // 优化任务
  2. import PageContent from '@/components/PageContent';
  3. import PageTitle from '@/components/PageTitle';
  4. import {
  5. queryHistory,
  6. queryMandateChildList,
  7. querySimulationProfit,
  8. } from '@/services/SmartOps';
  9. import { UnityAction } from '@/utils/utils';
  10. import { useParams, useRequest } from '@umijs/max';
  11. import { Table } from 'antd';
  12. import dayjs from 'dayjs';
  13. import { useState } from 'react';
  14. import styles from './OptimizationTasks.less';
  15. import EvaluationReport from './components/EvaluationReport';
  16. import ScrollLoading from './components/ScrollLoading';
  17. const OptimizationTasks = (props) => {
  18. const { projectId } = useParams();
  19. return (
  20. <PageContent closeable={false}>
  21. <PageTitle returnable>
  22. <div className={styles.navigateTitle}>
  23. <div>优化任务</div>
  24. </div>
  25. </PageTitle>
  26. <div className={styles.titleTime}>{dayjs().format('MM月DD日 HH:mm')}</div>
  27. <div className="content-title">
  28. <div>
  29. <Produce projectId={projectId} />
  30. <Cost projectId={projectId} />
  31. <div className={styles.pageCard}>
  32. <h3
  33. className={styles.title}
  34. style={{ justifyContent: 'space-between' }}
  35. >
  36. <div>
  37. <i />
  38. 评估报告
  39. </div>
  40. </h3>
  41. <EvaluationReport dataKey="allProject" />
  42. </div>
  43. </div>
  44. </div>
  45. </PageContent>
  46. );
  47. };
  48. const Produce = ({ projectId }) => {
  49. const columns = [
  50. {
  51. title: '参数',
  52. dataIndex: 'Title',
  53. },
  54. {
  55. title: '调整内容',
  56. dataIndex: 'Content',
  57. },
  58. ];
  59. const historyColumns = [
  60. {
  61. title: '时间',
  62. dataIndex: 'CreateTime',
  63. render: (time) => dayjs(time).format('YYYY-MM-DD HH:mm:ss'),
  64. },
  65. {
  66. title: '参数',
  67. dataIndex: 'Title',
  68. },
  69. {
  70. title: '任务内容',
  71. dataIndex: 'Content',
  72. },
  73. ];
  74. const [mandateID, setMandateID] = useState();
  75. const [active, setActive] = useState(false);
  76. const [list, setList] = useState([]);
  77. const [curPagination, setCurPagination] = useState({});
  78. // 当前记录
  79. const { data } = useRequest(queryMandateChildList, {
  80. defaultParams: [
  81. {
  82. projectId,
  83. mandateClass: 1,
  84. },
  85. ],
  86. onSuccess: (data) => {
  87. setMandateID(data[0]?.MandateId);
  88. },
  89. });
  90. // 历史记录
  91. const {
  92. run,
  93. loading,
  94. data: historyData,
  95. } = useRequest(queryHistory, {
  96. defaultParams: [{ project_id: projectId, class: 1, currentPage: 1 }],
  97. onSuccess: (data) => {
  98. setList([...list, ...data.list]);
  99. setCurPagination(data.pagination);
  100. },
  101. });
  102. const openDetail = () => {
  103. // send message to unity with mandate_id
  104. if (!mandateID) {
  105. return;
  106. }
  107. UnityAction.sendMsg('OpenTaskModal', `mandate_id=${mandateID}`);
  108. };
  109. return (
  110. <>
  111. <div className={styles.pageCard}>
  112. <h3
  113. className={styles.title}
  114. style={{ justifyContent: 'space-between' }}
  115. >
  116. <div>
  117. <i />
  118. 生产调度类
  119. </div>
  120. {mandateID && (
  121. <div className={styles.btnBlue} onClick={openDetail}>
  122. 查看任务
  123. </div>
  124. )}
  125. </h3>
  126. {data?.length > 0 && (
  127. <>
  128. <div
  129. className={styles.content}
  130. style={{ backgroundColor: '#B1D2F3' }}
  131. >
  132. <h3 className={styles.left}>任务总结</h3>
  133. <div className={styles.desc}>
  134. 根据水质相关数据.建议您调节以下参数,水厂运行可达较优状态
  135. </div>
  136. </div>
  137. <div
  138. className={styles.content}
  139. style={{ backgroundColor: '#EDF5FC' }}
  140. >
  141. <h3 className={styles.left}>任务内容</h3>
  142. <Table
  143. className={styles.taskTable}
  144. style={{ width: '100%' }}
  145. columns={columns}
  146. dataSource={data}
  147. pagination={false}
  148. />
  149. </div>
  150. </>
  151. )}
  152. {!data?.length && (
  153. <div
  154. className={styles.content}
  155. style={{ backgroundColor: '#B1D2F3' }}
  156. >
  157. <div className={styles.desc}>
  158. 当前进水数据稳定,产水数据稳定,暂无调节任务,继续保持哦~
  159. </div>
  160. </div>
  161. )}
  162. <div
  163. className={`${styles.bottomBtn} ${active ? styles.active : ''}`}
  164. onClick={() => setActive(!active)}
  165. >
  166. 历史优化记录
  167. <i></i>
  168. </div>
  169. <div style={{ display: active ? 'block' : 'none' }}>
  170. <ScrollLoading
  171. loading={loading}
  172. pagination={curPagination}
  173. handleLoadData={(current) =>
  174. run({ project_id: projectId, currentPage: current, class: 1 })
  175. }
  176. height="3rem"
  177. >
  178. <Table
  179. rowKey={'id'}
  180. loading={loading}
  181. dataSource={list}
  182. columns={historyColumns}
  183. pagination={false}
  184. className={styles.table1}
  185. />
  186. </ScrollLoading>
  187. </div>
  188. </div>
  189. </>
  190. );
  191. };
  192. const Cost = ({ projectId }) => {
  193. const columns = [
  194. {
  195. title: '设备',
  196. dataIndex: 'Title',
  197. },
  198. {
  199. title: '调整内容',
  200. dataIndex: 'Content',
  201. },
  202. ];
  203. const historyColumns = [
  204. {
  205. title: '时间',
  206. dataIndex: 'CreateTime',
  207. render: (time) => dayjs(time).format('YYYY-MM-DD HH:mm:ss'),
  208. },
  209. {
  210. title: '参数',
  211. dataIndex: 'Title',
  212. },
  213. {
  214. title: '任务内容',
  215. dataIndex: 'Content',
  216. },
  217. ];
  218. const [mandateID, setMandateID] = useState();
  219. const [active, setActive] = useState(false);
  220. const [list, setList] = useState([]);
  221. const [curPagination, setCurPagination] = useState({});
  222. const { data: profit } = useRequest(querySimulationProfit, {
  223. defaultParams: [
  224. {
  225. project_id: projectId,
  226. s_time: dayjs().subtract(1, 'day').format('YYYY-MM-DD'),
  227. e_time: dayjs().format('YYYY-MM-DD'),
  228. },
  229. ],
  230. formatResult(data) {
  231. if (!data?.info) return '-';
  232. return Object.values(data.info).reduce(
  233. (total, currentValue) => total + currentValue,
  234. 0,
  235. );
  236. },
  237. });
  238. const { data } = useRequest(queryMandateChildList, {
  239. defaultParams: [
  240. {
  241. projectId,
  242. mandateClass: 2,
  243. },
  244. ],
  245. onSuccess: (data) => {
  246. setMandateID(data[0]?.MandateId);
  247. },
  248. });
  249. // 历史记录
  250. const { run, loading } = useRequest(queryHistory, {
  251. defaultParams: [{ project_id: projectId, class: 2, currentPage: 1 }],
  252. onSuccess: (data) => {
  253. setList([...list, ...data.list]);
  254. setCurPagination(data.pagination);
  255. },
  256. });
  257. const openDetail = () => {
  258. // send message to unity
  259. if (!mandateID) {
  260. return;
  261. }
  262. UnityAction.sendMsg('OpenTaskModal', `mandate_id=${mandateID}`);
  263. };
  264. return (
  265. <div className={styles.pageCard}>
  266. <h3 className={styles.title} style={{ justifyContent: 'space-between' }}>
  267. <div>
  268. <i style={{ background: '#F5A623' }} />
  269. 成本节约类
  270. </div>
  271. {mandateID && (
  272. <div className={styles.btnOrange} onClick={openDetail}>
  273. 查看任务
  274. </div>
  275. )}
  276. </h3>
  277. {data?.length > 0 && (
  278. <>
  279. <div
  280. className={styles.content}
  281. style={{ backgroundColor: '#FBDEAE' }}
  282. >
  283. <h3 className={styles.left}>任务总结</h3>
  284. <div className={styles.desc}>
  285. 通过能耗/药耗数据模拟仿真预计未来一日可节省
  286. <span>{profit || '-'}</span>元
  287. </div>
  288. </div>
  289. <div
  290. className={styles.content}
  291. style={{ backgroundColor: 'rgba(245,166,35,0.04);' }}
  292. >
  293. <h3 className={styles.left}>任务内容</h3>
  294. <Table
  295. className={styles.taskTable}
  296. columns={columns}
  297. dataSource={data}
  298. pagination={false}
  299. />
  300. </div>
  301. </>
  302. )}
  303. {!data?.length && (
  304. <div className={styles.content} style={{ backgroundColor: '#FBDEAE' }}>
  305. <h3 className={styles.left}>任务总结</h3>
  306. <div className={styles.desc}>暂无可降低成本,继续保持哦~</div>
  307. </div>
  308. )}
  309. <div
  310. className={`${styles.bottomBtn2} ${active ? styles.active : ''}`}
  311. onClick={() => setActive(!active)}
  312. >
  313. 历史优化记录
  314. <i></i>
  315. </div>
  316. <div style={{ display: active ? 'block' : 'none' }}>
  317. <ScrollLoading
  318. loading={loading}
  319. pagination={curPagination}
  320. handleLoadData={(current) =>
  321. run({ project_id: projectId, currentPage: current, class: 2 })
  322. }
  323. height="3rem"
  324. >
  325. <Table
  326. rowKey={'id'}
  327. loading={loading}
  328. dataSource={list}
  329. columns={historyColumns}
  330. pagination={false}
  331. className={styles.table2}
  332. />
  333. </ScrollLoading>
  334. </div>
  335. </div>
  336. );
  337. };
  338. export default OptimizationTasks;