OptimizationTasks.js 5.6 KB

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