OptimizationTasks.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. // 优化任务
  2. import PageContent from '@/components/PageContent';
  3. import PageTitle from '@/components/PageTitle';
  4. import {
  5. queryMandate,
  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. const OptimizationTasks = (props) => {
  16. const { projectId } = useParams();
  17. const { data, run } = useRequest(queryMandate, {
  18. manual: true,
  19. });
  20. return (
  21. <PageContent closeable={false}>
  22. <PageTitle returnable>
  23. <div className={styles.navigateTitle}>
  24. <div>优化任务</div>
  25. </div>
  26. </PageTitle>
  27. <div className={styles.titleTime}>{dayjs().format('MM月DD日 HH:mm')}</div>
  28. <div className="content-title">
  29. <div>
  30. <Produce projectId={projectId} />
  31. <Cost projectId={projectId} />
  32. </div>
  33. </div>
  34. </PageContent>
  35. );
  36. };
  37. const Produce = ({ projectId }) => {
  38. const columns = [
  39. {
  40. title: '参数',
  41. dataIndex: 'Title',
  42. },
  43. {
  44. title: '调整内容',
  45. dataIndex: 'Content',
  46. },
  47. ];
  48. const [mandateID, setMandateID] = useState();
  49. const { data } = useRequest(queryMandateChildList, {
  50. defaultParams: [
  51. {
  52. projectId,
  53. mandateClass: 1,
  54. },
  55. ],
  56. onSuccess: (data) => {
  57. setMandateID(data[0].MandateId);
  58. },
  59. });
  60. const openDetail = () => {
  61. // send message to unity with mandate_id
  62. if (!mandateID) {
  63. return;
  64. }
  65. UnityAction.sendMsg('OpenTaskModal', `mandate_id=${mandateID}`);
  66. };
  67. return (
  68. <div className={styles.pageCard}>
  69. <h3 className={styles.title} style={{ justifyContent: 'space-between' }}>
  70. <div>
  71. <i />
  72. 生产调度类
  73. </div>
  74. {mandateID && (
  75. <div className={styles.btnBlue} onClick={openDetail}>
  76. 查看任务
  77. </div>
  78. )}
  79. </h3>
  80. {data?.length > 0 && (
  81. <>
  82. <div
  83. className={styles.content}
  84. style={{ backgroundColor: '#B1D2F3' }}
  85. >
  86. <h3 className={styles.left}>任务总结</h3>
  87. <div className={styles.desc}>
  88. 根据水质相关数据.建议您调节以下参数,水厂运行可达较优状态
  89. </div>
  90. </div>
  91. <div
  92. className={styles.content}
  93. style={{ backgroundColor: '#EDF5FC' }}
  94. >
  95. <h3 className={styles.left}>任务内容</h3>
  96. <Table
  97. className={styles.taskTable}
  98. style={{ width: '100%' }}
  99. columns={columns}
  100. dataSource={data}
  101. pagination={false}
  102. />
  103. </div>
  104. </>
  105. )}
  106. {!data?.length && (
  107. <div className={styles.content} style={{ backgroundColor: '#B1D2F3' }}>
  108. <div className={styles.desc}>
  109. 当前进水数据稳定,产水数据稳定,暂无调节任务,继续保持哦~
  110. </div>
  111. </div>
  112. )}
  113. </div>
  114. );
  115. };
  116. const Cost = ({ projectId }) => {
  117. const columns = [
  118. {
  119. title: '设备',
  120. dataIndex: 'Title',
  121. },
  122. {
  123. title: '调整内容',
  124. dataIndex: 'Content',
  125. },
  126. ];
  127. const [mandateID, setMandateID] = useState();
  128. const { data: profit } = useRequest(querySimulationProfit, {
  129. defaultParams: [
  130. {
  131. project_id: projectId,
  132. s_time: dayjs().subtract(1, 'day').format('YYYY-MM-DD'),
  133. e_time: dayjs().format('YYYY-MM-DD'),
  134. },
  135. ],
  136. formatResult(data) {
  137. if (!data?.info) return '-';
  138. return Object.values(data.info).reduce(
  139. (total, currentValue) => total + currentValue,
  140. 0,
  141. );
  142. },
  143. });
  144. const { data } = useRequest(queryMandateChildList, {
  145. defaultParams: [
  146. {
  147. projectId,
  148. mandateClass: 2,
  149. },
  150. ],
  151. onSuccess: (data) => {
  152. setMandateID(data[0].MandateId);
  153. },
  154. });
  155. const openDetail = () => {
  156. // send message to unity
  157. if (!mandateID) {
  158. return;
  159. }
  160. UnityAction.sendMsg('OpenTaskModal', `mandate_id=${mandateID}`);
  161. };
  162. return (
  163. <div className={styles.pageCard}>
  164. <h3 className={styles.title} style={{ justifyContent: 'space-between' }}>
  165. <div>
  166. <i style={{ background: '#F5A623' }} />
  167. 成本节约类
  168. </div>
  169. {mandateID && (
  170. <div className={styles.btnOrange} onClick={openDetail}>
  171. 查看任务
  172. </div>
  173. )}
  174. </h3>
  175. {data?.length > 0 && (
  176. <>
  177. <div
  178. className={styles.content}
  179. style={{ backgroundColor: '#FBDEAE' }}
  180. >
  181. <h3 className={styles.left}>任务总结</h3>
  182. <div className={styles.desc}>
  183. 通过能耗/药耗数据模拟仿真预计未来一日可节省
  184. <span>{profit || '-'}</span>元
  185. </div>
  186. </div>
  187. <div
  188. className={styles.content}
  189. style={{ backgroundColor: 'rgba(245,166,35,0.04);' }}
  190. >
  191. <h3 className={styles.left}>任务内容</h3>
  192. <Table
  193. className={styles.taskTable}
  194. columns={columns}
  195. dataSource={data}
  196. pagination={false}
  197. />
  198. </div>
  199. </>
  200. )}
  201. {!data?.length && (
  202. <div className={styles.content} style={{ backgroundColor: '#FBDEAE' }}>
  203. <h3 className={styles.left}>任务总结</h3>
  204. <div className={styles.desc}>暂无可降低成本,继续保持哦~</div>
  205. </div>
  206. )}
  207. </div>
  208. );
  209. };
  210. export default OptimizationTasks;