feat(mes): 新增能耗管理模块(计量点/抄表/定额/预警/统计)
- 新增能耗计量点、抄表记录、考核指标、预警的数据模型与 CRUD 接口
- 抄表自动带出期初读数并计算本期用量、费用,冗余车间/产线/设备快照
- 预警检测覆盖超定额、环比、同比、跑冒滴漏四类规则
- 新增能耗总览与月度报表统计接口,提供同比、环比分析
- 新增 8 个能耗字典类型与 16 个按钮权限
- 新增建表、字典、菜单及角色授权初始化脚本
Co-Authored-By: Claude Code <noreply@anthropic.com>
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | -- ============================================ |
| | | -- MES è½èç®¡ç æ¨¡ååå§åèæ¬ |
| | | -- 1. 建表 2. åå
¸ 3. èå䏿鮿é 4. è¶
级管çåèåææ |
| | | -- |
| | | -- 说æï¼ |
| | | -- * ä¸å¡è¡¨ç»ä¸é»è¾å é¤ï¼deleted ä½ï¼ï¼å æ¤ code / (meter_id, record_date) ç |
| | | -- ä¸å¡å¯ä¸æ§ç±æå¡å±æ ¡éªï¼æ°æ®åºä¾§åªå»ºæ®éç´¢å¼ï¼é¿å
é»è¾å é¤åæ æ³å¤ç¨ç¼ç ã |
| | | -- * èåæå¨å·²åå¨çãè½è管çãç®å½ä¸ï¼id = 1065864ï¼/energyManagementï¼ã |
| | | -- ============================================ |
| | | |
| | | -- 1. 建表 |
| | | |
| | | CREATE TABLE IF NOT EXISTS `mes_em_meter` ( |
| | | `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主é®ID', |
| | | `code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '计éç¹ç¼ç ', |
| | | `name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '计éç¹åç§°', |
| | | `energy_type` int NOT NULL COMMENT 'è½æºç±»åï¼åå
¸ mes_em_energy_type', |
| | | `unit` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '计éåä½', |
| | | `meter_no` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT 'ç°åºè¡¨è®¡ç¼å·', |
| | | `workshop_id` bigint NULL DEFAULT NULL COMMENT 'æå±è½¦é´ç¼å·', |
| | | `workshop_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT 'æå±è½¦é´åç§°', |
| | | `line_id` bigint NULL DEFAULT NULL COMMENT 'æå±äº§çº¿ç¼å·', |
| | | `line_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT 'æå±äº§çº¿åç§°', |
| | | `machinery_id` bigint NULL DEFAULT NULL COMMENT 'å
³è设å¤ç¼å·', |
| | | `machinery_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT 'å
³è设å¤åç§°', |
| | | `ratio` decimal(18, 4) NULL DEFAULT 1.0000 COMMENT 'åç', |
| | | `initial_reading` decimal(18, 2) NULL DEFAULT 0.00 COMMENT 'åå§è¯»æ°', |
| | | `coal_factor` decimal(18, 4) NULL DEFAULT NULL COMMENT 'ææ ç
¤ç³»æ°ï¼kgce/计éåä½ï¼', |
| | | `leak_threshold` decimal(18, 2) NULL DEFAULT NULL COMMENT 'æ¥ç¨éå¼å¸¸ä¸éï¼è¶
è¿è§¦åçä¼¼è·åæ»´æ¼ï¼', |
| | | `charge_user_id` bigint NULL DEFAULT NULL COMMENT '责任人ç¼å·', |
| | | `install_date` date NULL DEFAULT NULL COMMENT 'å®è£
æ¥æ', |
| | | `status` int NOT NULL DEFAULT 1 COMMENT 'ç¶æï¼åå
¸ mes_em_meter_status', |
| | | `remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '夿³¨', |
| | | |
| | | `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT 'å建è
', |
| | | `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'å建æ¶é´', |
| | | `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT 'æ´æ°è
', |
| | | `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'æ´æ°æ¶é´', |
| | | `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT 'æ¯å¦å é¤', |
| | | PRIMARY KEY (`id`) USING BTREE, |
| | | INDEX `idx_code` (`code`), |
| | | INDEX `idx_energy_type` (`energy_type`), |
| | | INDEX `idx_workshop_id` (`workshop_id`), |
| | | INDEX `idx_machinery_id` (`machinery_id`) |
| | | ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = 'MES è½è计éç¹' ROW_FORMAT = Dynamic; |
| | | |
| | | CREATE TABLE IF NOT EXISTS `mes_em_record` ( |
| | | `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主é®ID', |
| | | `meter_id` bigint NOT NULL COMMENT '计éç¹ç¼å·', |
| | | `meter_code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '计éç¹ç¼ç å¿«ç
§', |
| | | `meter_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '计éç¹åç§°å¿«ç
§', |
| | | `energy_type` int NULL DEFAULT NULL COMMENT 'è½æºç±»åå¿«ç
§ï¼åå
¸ mes_em_energy_type', |
| | | `unit` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '计éåä½å¿«ç
§', |
| | | `ratio` decimal(18, 4) NULL DEFAULT NULL COMMENT 'åçå¿«ç
§', |
| | | `coal_factor` decimal(18, 4) NULL DEFAULT NULL COMMENT 'ææ ç
¤ç³»æ°å¿«ç
§', |
| | | `workshop_id` bigint NULL DEFAULT NULL COMMENT 'æå±è½¦é´ç¼å·å¿«ç
§', |
| | | `workshop_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT 'æå±è½¦é´åç§°å¿«ç
§', |
| | | `line_id` bigint NULL DEFAULT NULL COMMENT 'æå±äº§çº¿ç¼å·å¿«ç
§', |
| | | `line_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT 'æå±äº§çº¿åç§°å¿«ç
§', |
| | | `machinery_id` bigint NULL DEFAULT NULL COMMENT 'å
³è设å¤ç¼å·å¿«ç
§', |
| | | `machinery_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT 'å
³è设å¤åç§°å¿«ç
§', |
| | | `record_date` date NOT NULL COMMENT 'æè¡¨æ¥æ', |
| | | `prev_reading` decimal(18, 2) NULL DEFAULT NULL COMMENT 'æå读æ°', |
| | | `reading` decimal(18, 2) NULL DEFAULT NULL COMMENT 'ææ«è¯»æ°', |
| | | `usage_amount` decimal(18, 4) NULL DEFAULT NULL COMMENT 'æ¬æç¨é', |
| | | `price` decimal(18, 4) NULL DEFAULT NULL COMMENT 'åä»·ï¼å
/计éåä½ï¼', |
| | | `cost` decimal(18, 2) NULL DEFAULT NULL COMMENT 'æ¬æè´¹ç¨ï¼å
ï¼', |
| | | `source` int NULL DEFAULT 1 COMMENT 'æ°æ®æ¥æºï¼åå
¸ mes_em_record_source', |
| | | `remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '夿³¨', |
| | | |
| | | `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT 'å建è
', |
| | | `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'å建æ¶é´', |
| | | `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT 'æ´æ°è
', |
| | | `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'æ´æ°æ¶é´', |
| | | `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT 'æ¯å¦å é¤', |
| | | PRIMARY KEY (`id`) USING BTREE, |
| | | INDEX `idx_meter_date` (`meter_id`, `record_date`), |
| | | INDEX `idx_record_date` (`record_date`), |
| | | INDEX `idx_energy_type` (`energy_type`), |
| | | INDEX `idx_workshop_id` (`workshop_id`) |
| | | ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = 'MES è½èæè¡¨è®°å½' ROW_FORMAT = Dynamic; |
| | | |
| | | CREATE TABLE IF NOT EXISTS `mes_em_quota` ( |
| | | `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主é®ID', |
| | | `name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'ææ åç§°', |
| | | `energy_type` int NOT NULL COMMENT 'è½æºç±»åï¼åå
¸ mes_em_energy_type', |
| | | `object_type` int NOT NULL COMMENT 'èæ ¸å¯¹è±¡ç±»åï¼åå
¸ mes_em_quota_object_type', |
| | | `object_id` bigint NOT NULL DEFAULT 0 COMMENT 'èæ ¸å¯¹è±¡ç¼å·ï¼å
¨å为 0ï¼', |
| | | `object_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT 'èæ ¸å¯¹è±¡åç§°', |
| | | `period_type` int NOT NULL COMMENT 'èæ ¸å¨æï¼åå
¸ mes_em_quota_period', |
| | | `quota_value` decimal(18, 4) NOT NULL COMMENT 'å®é¢å¼', |
| | | `unit` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '计éåä½', |
| | | `warn_ratio` decimal(8, 2) NULL DEFAULT 10.00 COMMENT 'é¢è¦æ¯ä¾ï¼%ï¼', |
| | | `alarm_ratio` decimal(8, 2) NULL DEFAULT 20.00 COMMENT '严éé¢è¦æ¯ä¾ï¼%ï¼', |
| | | `mom_warn_ratio` decimal(8, 2) NULL DEFAULT 30.00 COMMENT 'ç¯æ¯å¼å¸¸éå¼ï¼%ï¼', |
| | | `yoy_warn_ratio` decimal(8, 2) NULL DEFAULT 30.00 COMMENT '忝å¼å¸¸éå¼ï¼%ï¼', |
| | | `status` int NOT NULL DEFAULT 1 COMMENT 'ç¶æï¼åå
¸ mes_em_meter_status', |
| | | `remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '夿³¨', |
| | | |
| | | `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT 'å建è
', |
| | | `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'å建æ¶é´', |
| | | `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT 'æ´æ°è
', |
| | | `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'æ´æ°æ¶é´', |
| | | `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT 'æ¯å¦å é¤', |
| | | PRIMARY KEY (`id`) USING BTREE, |
| | | INDEX `idx_object` (`object_type`, `object_id`), |
| | | INDEX `idx_energy_type` (`energy_type`), |
| | | INDEX `idx_period_type` (`period_type`) |
| | | ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = 'MES è½èèæ ¸ææ ' ROW_FORMAT = Dynamic; |
| | | |
| | | CREATE TABLE IF NOT EXISTS `mes_em_alert` ( |
| | | `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主é®ID', |
| | | `alert_no` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT 'é¢è¦ç¼å·', |
| | | `meter_id` bigint NOT NULL DEFAULT 0 COMMENT '计éç¹ç¼å·ï¼å®é¢é¢è¦ä¸º 0ï¼', |
| | | `meter_code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '计éç¹ç¼ç å¿«ç
§', |
| | | `meter_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '计éç¹/èæ ¸å¯¹è±¡åç§°', |
| | | `energy_type` int NULL DEFAULT NULL COMMENT 'è½æºç±»åï¼åå
¸ mes_em_energy_type', |
| | | `alert_type` int NOT NULL COMMENT 'é¢è¦ç±»åï¼åå
¸ mes_em_alert_type', |
| | | `alert_level` int NOT NULL COMMENT 'é¢è¦çº§å«ï¼åå
¸ mes_em_alert_level', |
| | | `alert_date` date NOT NULL COMMENT 'é¢è¦æ¥æ', |
| | | `object_type` int NULL DEFAULT NULL COMMENT 'èæ ¸å¯¹è±¡ç±»åï¼åå
¸ mes_em_quota_object_type', |
| | | `object_id` bigint NOT NULL DEFAULT 0 COMMENT 'èæ ¸å¯¹è±¡ç¼å·ï¼è®¡éç¹çº§é¢è¦ä¸º 0ï¼', |
| | | `object_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT 'èæ ¸å¯¹è±¡åç§°', |
| | | `actual_value` decimal(18, 4) NULL DEFAULT NULL COMMENT 'å®é
å¼', |
| | | `threshold_value` decimal(18, 4) NULL DEFAULT NULL COMMENT 'éå¼', |
| | | `unit` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '计éåä½', |
| | | `content` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT 'é¢è¦å
容', |
| | | `status` int NOT NULL DEFAULT 0 COMMENT 'å¤çç¶æï¼åå
¸ mes_em_alert_status', |
| | | `handle_user_id` bigint NULL DEFAULT NULL COMMENT 'å¤ç人ç¼å·', |
| | | `handle_user_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT 'å¤ç人åç§°', |
| | | `handle_time` datetime NULL DEFAULT NULL COMMENT 'å¤çæ¶é´', |
| | | `handle_remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT 'å¤ç说æ', |
| | | |
| | | `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT 'å建è
', |
| | | `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'å建æ¶é´', |
| | | `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT 'æ´æ°è
', |
| | | `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'æ´æ°æ¶é´', |
| | | `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT 'æ¯å¦å é¤', |
| | | PRIMARY KEY (`id`) USING BTREE, |
| | | INDEX `idx_lookup` (`meter_id`, `alert_type`, `alert_date`, `object_id`), |
| | | INDEX `idx_alert_date` (`alert_date`), |
| | | INDEX `idx_status` (`status`) |
| | | ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = 'MES è½èé¢è¦' ROW_FORMAT = Dynamic; |
| | | |
| | | -- 2. åå
¸ç±»å |
| | | INSERT INTO `system_dict_type` (`name`, `type`, `status`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) |
| | | VALUES |
| | | ('MES è½æºç±»å', 'mes_em_energy_type', 0, 'çµãæ°´ãçæ²¹ãå¤©ç¶æ°', '1', NOW(), '1', NOW(), b'0'), |
| | | ('MES è½è计éç¹ç¶æ', 'mes_em_meter_status', 0, 'è½è计éç¹/èæ ¸ææ ç¶æ', '1', NOW(), '1', NOW(), b'0'), |
| | | ('MES è½èæ°æ®æ¥æº', 'mes_em_record_source', 0, 'æè¡¨è®°å½æ¥æº', '1', NOW(), '1', NOW(), b'0'), |
| | | ('MES è½èèæ ¸å¯¹è±¡ç±»å', 'mes_em_quota_object_type', 0, 'å
¨å/车é´/产线/设å¤', '1', NOW(), '1', NOW(), b'0'), |
| | | ('MES è½èèæ ¸å¨æ', 'mes_em_quota_period', 0, 'æ¥å®é¢/æå®é¢', '1', NOW(), '1', NOW(), b'0'), |
| | | ('MES è½èé¢è¦ç±»å', 'mes_em_alert_type', 0, 'è¶
å®é¢/ç¯æ¯å¼å¸¸/忝å¼å¸¸/è·åæ»´æ¼', '1', NOW(), '1', NOW(), b'0'), |
| | | ('MES è½èé¢è¦çº§å«', 'mes_em_alert_level', 0, 'æç¤º/è¦å/严é', '1', NOW(), '1', NOW(), b'0'), |
| | | ('MES è½èé¢è¦å¤çç¶æ', 'mes_em_alert_status', 0, 'æªå¤ç/å·²å¤ç', '1', NOW(), '1', NOW(), b'0'); |
| | | |
| | | -- 3. åå
¸æ°æ® |
| | | INSERT INTO `system_dict_data` (`sort`, `label`, `value`, `dict_type`, `status`, `color_type`, `css_class`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) |
| | | VALUES |
| | | -- è½æºç±»å |
| | | (1, 'çµ', '1', 'mes_em_energy_type', 0, 'primary', '', 'ç¨çµéï¼åä½ kWh', '1', NOW(), '1', NOW(), b'0'), |
| | | (2, 'æ°´', '2', 'mes_em_energy_type', 0, 'info', '', 'ç¨æ°´éï¼åä½ t', '1', NOW(), '1', NOW(), b'0'), |
| | | (3, 'çæ²¹', '3', 'mes_em_energy_type', 0, 'warning', '', 'çæ²¹ç¨éï¼åä½ L', '1', NOW(), '1', NOW(), b'0'), |
| | | (4, 'å¤©ç¶æ°', '4', 'mes_em_energy_type', 0, 'success', '', 'å¤©ç¶æ°ç¨éï¼åä½ m³', '1', NOW(), '1', NOW(), b'0'), |
| | | -- 计éç¹ç¶æ |
| | | (1, 'å¯ç¨', '1', 'mes_em_meter_status', 0, 'success', '', 'å¯ç¨', '1', NOW(), '1', NOW(), b'0'), |
| | | (2, 'åç¨', '0', 'mes_em_meter_status', 0, 'info', '', 'åç¨', '1', NOW(), '1', NOW(), b'0'), |
| | | -- æ°æ®æ¥æº |
| | | (1, 'æå·¥å½å
¥', '1', 'mes_em_record_source', 0, 'primary', '', '人工æè¡¨å½å
¥', '1', NOW(), '1', NOW(), b'0'), |
| | | (2, 'Excel 导å
¥', '2', 'mes_em_record_source', 0, 'warning', '', 'æ¹é导å
¥', '1', NOW(), '1', NOW(), b'0'), |
| | | (3, 'èªå¨éé', '3', 'mes_em_record_source', 0, 'success', '', 'éé设å¤èªå¨ä¸æ¥', '1', NOW(), '1', NOW(), b'0'), |
| | | -- èæ ¸å¯¹è±¡ç±»å |
| | | (1, 'å
¨å', '0', 'mes_em_quota_object_type', 0, 'info', '', 'å
¨åçº§èæ ¸', '1', NOW(), '1', NOW(), b'0'), |
| | | (2, '车é´', '1', 'mes_em_quota_object_type', 0, 'primary', '', '车é´çº§èæ ¸', '1', NOW(), '1', NOW(), b'0'), |
| | | (3, '产线', '2', 'mes_em_quota_object_type', 0, 'warning', '', 'äº§çº¿çº§èæ ¸', '1', NOW(), '1', NOW(), b'0'), |
| | | (4, '设å¤', '3', 'mes_em_quota_object_type', 0, 'danger', '', 'éç¹ç¨è½è®¾å¤èæ ¸', '1', NOW(), '1', NOW(), b'0'), |
| | | -- èæ ¸å¨æ |
| | | (1, 'æ¥', '1', 'mes_em_quota_period', 0, 'primary', '', 'ææ¥èæ ¸', '1', NOW(), '1', NOW(), b'0'), |
| | | (2, 'æ', '2', 'mes_em_quota_period', 0, 'success', '', 'ææç´¯è®¡èæ ¸', '1', NOW(), '1', NOW(), b'0'), |
| | | -- é¢è¦ç±»å |
| | | (1, 'è¶
å®é¢', '1', 'mes_em_alert_type', 0, 'danger', '', 'å®é
ç¨éè¶
è¿èæ ¸å®é¢', '1', NOW(), '1', NOW(), b'0'), |
| | | (2, 'ç¯æ¯å¼å¸¸', '2', 'mes_em_alert_type', 0, 'warning', '', 'è¾ä¸ä¸å¨æå¼å¸¸å¢é¿', '1', NOW(), '1', NOW(), b'0'), |
| | | (3, '忝å¼å¸¸', '3', 'mes_em_alert_type', 0, 'warning', '', 'è¾å»å¹´åæå¼å¸¸å¢é¿', '1', NOW(), '1', NOW(), b'0'), |
| | | (4, 'çä¼¼è·åæ»´æ¼', '4', 'mes_em_alert_type', 0, 'danger', '', '忥ç¨éè¶
è¿è®¡éç¹è®¾å®éå¼', '1', NOW(), '1', NOW(), b'0'), |
| | | -- é¢è¦çº§å« |
| | | (1, 'æç¤º', '1', 'mes_em_alert_level', 0, 'info', '', 'æç¤ºçº§', '1', NOW(), '1', NOW(), b'0'), |
| | | (2, 'è¦å', '2', 'mes_em_alert_level', 0, 'warning', '', 'è¦å级', '1', NOW(), '1', NOW(), b'0'), |
| | | (3, '严é', '3', 'mes_em_alert_level', 0, 'danger', '', '严é级', '1', NOW(), '1', NOW(), b'0'), |
| | | -- é¢è¦å¤çç¶æ |
| | | (1, 'æªå¤ç', '0', 'mes_em_alert_status', 0, 'danger', '', 'å¾
å¤ç', '1', NOW(), '1', NOW(), b'0'), |
| | | (2, 'å·²å¤ç', '1', 'mes_em_alert_status', 0, 'success', '', 'å·²å¤ç', '1', NOW(), '1', NOW(), b'0'); |
| | | |
| | | -- 4. èåï¼ç¶èå 1065864 è½è管çï¼ |
| | | INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) |
| | | VALUES |
| | | (1065865, 'è½èæ»è§', '', 2, 1, 1065864, 'overview', 'ep:data-analysis', 'energy/overview/index', 'EnergyOverview', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | (1065866, '计éç¹ç®¡ç', '', 2, 2, 1065864, 'meter', 'ep:odometer', 'energy/meter/index', 'EnergyMeter', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | (1065867, 'è½èæ°æ®éé', '', 2, 3, 1065864, 'record', 'ep:edit', 'energy/record/index', 'EnergyRecord', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | (1065868, 'èæ ¸ææ ', '', 2, 4, 1065864, 'quota', 'ep:aim', 'energy/quota/index', 'EnergyQuota', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | (1065869, 'è½èé¢è¦', '', 2, 5, 1065864, 'alert', 'ep:bell', 'energy/alert/index', 'EnergyAlert', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | (1065870, 'æ¥è¡¨åæ', '', 2, 6, 1065864, 'report', 'ep:document', 'energy/report/index', 'EnergyReport', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'); |
| | | |
| | | -- 5. æé®æé |
| | | INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) |
| | | VALUES |
| | | -- è½èæ»è§ |
| | | (1065871, 'è½èæ»è§æ¥è¯¢', 'mes:em-overview:query', 3, 1, 1065865, '', '', '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | -- 计éç¹ç®¡ç |
| | | (1065872, '计éç¹æ¥è¯¢', 'mes:em-meter:query', 3, 1, 1065866, '', '', '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | (1065873, '计éç¹å建', 'mes:em-meter:create', 3, 2, 1065866, '', '', '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | (1065874, '计éç¹æ´æ°', 'mes:em-meter:update', 3, 3, 1065866, '', '', '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | (1065875, '计éç¹å é¤', 'mes:em-meter:delete', 3, 4, 1065866, '', '', '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | -- è½èæ°æ®éé |
| | | (1065876, 'æè¡¨è®°å½æ¥è¯¢', 'mes:em-record:query', 3, 1, 1065867, '', '', '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | (1065877, 'æè¡¨è®°å½å建', 'mes:em-record:create', 3, 2, 1065867, '', '', '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | (1065878, 'æè¡¨è®°å½æ´æ°', 'mes:em-record:update', 3, 3, 1065867, '', '', '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | (1065879, 'æè¡¨è®°å½å é¤', 'mes:em-record:delete', 3, 4, 1065867, '', '', '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | -- èæ ¸ææ |
| | | (1065880, 'èæ ¸ææ æ¥è¯¢', 'mes:em-quota:query', 3, 1, 1065868, '', '', '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | (1065881, 'èæ ¸ææ å建', 'mes:em-quota:create', 3, 2, 1065868, '', '', '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | (1065882, 'èæ ¸ææ æ´æ°', 'mes:em-quota:update', 3, 3, 1065868, '', '', '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | (1065883, 'èæ ¸ææ å é¤', 'mes:em-quota:delete', 3, 4, 1065868, '', '', '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | -- è½èé¢è¦ |
| | | (1065884, 'è½èé¢è¦æ¥è¯¢', 'mes:em-alert:query', 3, 1, 1065869, '', '', '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | (1065885, 'è½èé¢è¦å¤ç', 'mes:em-alert:handle', 3, 2, 1065869, '', '', '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | -- æ¥è¡¨åæ |
| | | (1065886, 'æ¥è¡¨åææ¥è¯¢', 'mes:em-report:query', 3, 1, 1065870, '', '', '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'); |
| | | |
| | | -- 6. è¶
级管çåèåææï¼è§è² 1 ç»è¿æéæ ¡éªï¼è¿éè¡¥é½ææè®°å½ä¾¿äºè§è²èåæ å±ç¤ºï¼ |
| | | -- å
¶ä»è§è²å¦é使ç¨ï¼è¯·å¨ãç³»ç»ç®¡ç - è§è²ç®¡çãä¸å¾éãè½è管çãåä¿åã |
| | | INSERT INTO `system_role_menu` (`role_id`, `menu_id`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) |
| | | VALUES |
| | | (1, 1065864, '1', NOW(), '1', NOW(), b'0'), |
| | | (1, 1065865, '1', NOW(), '1', NOW(), b'0'), |
| | | (1, 1065866, '1', NOW(), '1', NOW(), b'0'), |
| | | (1, 1065867, '1', NOW(), '1', NOW(), b'0'), |
| | | (1, 1065868, '1', NOW(), '1', NOW(), b'0'), |
| | | (1, 1065869, '1', NOW(), '1', NOW(), b'0'), |
| | | (1, 1065870, '1', NOW(), '1', NOW(), b'0'), |
| | | (1, 1065871, '1', NOW(), '1', NOW(), b'0'), |
| | | (1, 1065872, '1', NOW(), '1', NOW(), b'0'), |
| | | (1, 1065873, '1', NOW(), '1', NOW(), b'0'), |
| | | (1, 1065874, '1', NOW(), '1', NOW(), b'0'), |
| | | (1, 1065875, '1', NOW(), '1', NOW(), b'0'), |
| | | (1, 1065876, '1', NOW(), '1', NOW(), b'0'), |
| | | (1, 1065877, '1', NOW(), '1', NOW(), b'0'), |
| | | (1, 1065878, '1', NOW(), '1', NOW(), b'0'), |
| | | (1, 1065879, '1', NOW(), '1', NOW(), b'0'), |
| | | (1, 1065880, '1', NOW(), '1', NOW(), b'0'), |
| | | (1, 1065881, '1', NOW(), '1', NOW(), b'0'), |
| | | (1, 1065882, '1', NOW(), '1', NOW(), b'0'), |
| | | (1, 1065883, '1', NOW(), '1', NOW(), b'0'), |
| | | (1, 1065884, '1', NOW(), '1', NOW(), b'0'), |
| | | (1, 1065885, '1', NOW(), '1', NOW(), b'0'), |
| | | (1, 1065886, '1', NOW(), '1', NOW(), b'0'); |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.em.alert; |
| | | |
| | | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.alert.vo.MesEmAlertHandleReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.alert.vo.MesEmAlertPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.alert.vo.MesEmAlertRespVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.em.alert.MesEmAlertDO; |
| | | import cn.iocoder.yudao.module.mes.service.em.alert.MesEmAlertService; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import jakarta.annotation.Resource; |
| | | import jakarta.validation.Valid; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.util.Collections; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| | | |
| | | @Tag(name = "管çåå° - MES è½èé¢è¦") |
| | | @RestController |
| | | @RequestMapping("/mes/em/alert") |
| | | @Validated |
| | | public class MesEmAlertController { |
| | | |
| | | @Resource |
| | | private MesEmAlertService alertService; |
| | | |
| | | @GetMapping("/page") |
| | | @Operation(summary = "è·å¾è½èé¢è¦å页") |
| | | @PreAuthorize("@ss.hasPermission('mes:em-alert:query')") |
| | | public CommonResult<PageResult<MesEmAlertRespVO>> getAlertPage(@Valid MesEmAlertPageReqVO pageReqVO) { |
| | | PageResult<MesEmAlertDO> pageResult = alertService.getAlertPage(pageReqVO); |
| | | return success(new PageResult<>(alertService.getAlertRespVOList(pageResult.getList()), |
| | | pageResult.getTotal())); |
| | | } |
| | | |
| | | @GetMapping("/get") |
| | | @Operation(summary = "è·å¾è½èé¢è¦") |
| | | @Parameter(name = "id", description = "ç¼å·", required = true) |
| | | @PreAuthorize("@ss.hasPermission('mes:em-alert:query')") |
| | | public CommonResult<MesEmAlertRespVO> getAlert(@RequestParam("id") Long id) { |
| | | MesEmAlertDO alert = alertService.getAlert(id); |
| | | if (alert == null) { |
| | | return success(null); |
| | | } |
| | | return success(alertService.getAlertRespVOList(Collections.singletonList(alert)).get(0)); |
| | | } |
| | | |
| | | @PutMapping("/handle") |
| | | @Operation(summary = "å¤çè½èé¢è¦") |
| | | @PreAuthorize("@ss.hasPermission('mes:em-alert:handle')") |
| | | public CommonResult<Boolean> handleAlert(@Valid @RequestBody MesEmAlertHandleReqVO handleReqVO) { |
| | | alertService.handleAlert(handleReqVO); |
| | | return success(true); |
| | | } |
| | | |
| | | @PostMapping("/check") |
| | | @Operation(summary = "éæ°æ£æµæå®æ¥æåºé´çè½èé¢è¦") |
| | | @PreAuthorize("@ss.hasPermission('mes:em-alert:handle')") |
| | | public CommonResult<Integer> checkAlerts( |
| | | @RequestParam("beginDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate beginDate, |
| | | @RequestParam("endDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate) { |
| | | return success(alertService.checkRange(beginDate, endDate)); |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.em.alert.vo; |
| | | |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import jakarta.validation.constraints.NotNull; |
| | | import lombok.Data; |
| | | |
| | | @Schema(description = "管çåå° - MES è½èé¢è¦å¤ç Request VO") |
| | | @Data |
| | | public class MesEmAlertHandleReqVO { |
| | | |
| | | @Schema(description = "é¢è¦ç¼å·", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| | | @NotNull(message = "é¢è¦ç¼å·ä¸è½ä¸ºç©º") |
| | | private Long id; |
| | | |
| | | @Schema(description = "å¤ç说æ", example = "已宿æ£ä¿®ï¼æ´æ¢å¯å°ä»¶") |
| | | private String handleRemark; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.em.alert.vo; |
| | | |
| | | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | import lombok.ToString; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | |
| | | import java.time.LocalDate; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY; |
| | | |
| | | @Schema(description = "管çåå° - MES è½èé¢è¦å页 Request VO") |
| | | @Data |
| | | @EqualsAndHashCode(callSuper = true) |
| | | @ToString(callSuper = true) |
| | | public class MesEmAlertPageReqVO extends PageParam { |
| | | |
| | | @Schema(description = "计éç¹åç§°", example = "ååå¨è½¦é´æ»çµè¡¨") |
| | | private String meterName; |
| | | |
| | | @Schema(description = "è½æºç±»å", example = "1") |
| | | private Integer energyType; |
| | | |
| | | @Schema(description = "é¢è¦ç±»å", example = "1") |
| | | private Integer alertType; |
| | | |
| | | @Schema(description = "é¢è¦çº§å«", example = "2") |
| | | private Integer alertLevel; |
| | | |
| | | @Schema(description = "å¤çç¶æ", example = "0") |
| | | private Integer status; |
| | | |
| | | @Schema(description = "é¢è¦æ¥æ") |
| | | @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY) |
| | | private LocalDate[] alertDate; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.em.alert.vo; |
| | | |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | |
| | | @Schema(description = "管çåå° - MES è½èé¢è¦ Response VO") |
| | | @Data |
| | | public class MesEmAlertRespVO { |
| | | |
| | | @Schema(description = "ç¼å·", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| | | private Long id; |
| | | |
| | | @Schema(description = "é¢è¦ç¼å·", example = "AL20261018-1024-1") |
| | | private String alertNo; |
| | | |
| | | @Schema(description = "计éç¹ç¼å·", example = "1024") |
| | | private Long meterId; |
| | | |
| | | @Schema(description = "计éç¹ç¼ç ", example = "EM-DL-001") |
| | | private String meterCode; |
| | | |
| | | @Schema(description = "计éç¹åç§°", example = "ååå¨è½¦é´æ»çµè¡¨") |
| | | private String meterName; |
| | | |
| | | @Schema(description = "è½æºç±»å", example = "1") |
| | | private Integer energyType; |
| | | |
| | | @Schema(description = "è½æºç±»ååç§°", example = "çµ") |
| | | private String energyTypeName; |
| | | |
| | | @Schema(description = "é¢è¦ç±»å", example = "1") |
| | | private Integer alertType; |
| | | |
| | | @Schema(description = "é¢è¦ç±»ååç§°", example = "è¶
å®é¢") |
| | | private String alertTypeName; |
| | | |
| | | @Schema(description = "é¢è¦çº§å«", example = "2") |
| | | private Integer alertLevel; |
| | | |
| | | @Schema(description = "é¢è¦çº§å«åç§°", example = "è¦å") |
| | | private String alertLevelName; |
| | | |
| | | @Schema(description = "é¢è¦æ¥æ") |
| | | private LocalDate alertDate; |
| | | |
| | | @Schema(description = "èæ ¸å¯¹è±¡ç±»å", example = "1") |
| | | private Integer objectType; |
| | | |
| | | @Schema(description = "èæ ¸å¯¹è±¡ç±»ååç§°", example = "车é´") |
| | | private String objectTypeName; |
| | | |
| | | @Schema(description = "èæ ¸å¯¹è±¡ç¼å·", example = "7") |
| | | private Long objectId; |
| | | |
| | | @Schema(description = "èæ ¸å¯¹è±¡åç§°", example = "ååå¨å¶é 车é´") |
| | | private String objectName; |
| | | |
| | | @Schema(description = "å®é
å¼", example = "1234") |
| | | private BigDecimal actualValue; |
| | | |
| | | @Schema(description = "éå¼", example = "1000") |
| | | private BigDecimal thresholdValue; |
| | | |
| | | @Schema(description = "计éåä½", example = "kWh") |
| | | private String unit; |
| | | |
| | | @Schema(description = "é¢è¦å
容") |
| | | private String content; |
| | | |
| | | @Schema(description = "å¤çç¶æ", example = "0") |
| | | private Integer status; |
| | | |
| | | @Schema(description = "å¤çç¶æåç§°", example = "æªå¤ç") |
| | | private String statusName; |
| | | |
| | | @Schema(description = "å¤ç人ç¼å·") |
| | | private Long handleUserId; |
| | | |
| | | @Schema(description = "å¤ç人åç§°") |
| | | private String handleUserName; |
| | | |
| | | @Schema(description = "å¤çæ¶é´") |
| | | private LocalDateTime handleTime; |
| | | |
| | | @Schema(description = "å¤ç说æ") |
| | | private String handleRemark; |
| | | |
| | | @Schema(description = "å建æ¶é´") |
| | | private LocalDateTime createTime; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.em.meter; |
| | | |
| | | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.meter.vo.MesEmMeterPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.meter.vo.MesEmMeterRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.meter.vo.MesEmMeterSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.meter.vo.MesEmOptionRespVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.em.meter.MesEmMeterDO; |
| | | import cn.iocoder.yudao.module.mes.service.em.meter.MesEmMeterService; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import jakarta.annotation.Resource; |
| | | import jakarta.validation.Valid; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| | | |
| | | @Tag(name = "管çåå° - MES è½è计éç¹") |
| | | @RestController |
| | | @RequestMapping("/mes/em/meter") |
| | | @Validated |
| | | public class MesEmMeterController { |
| | | |
| | | @Resource |
| | | private MesEmMeterService meterService; |
| | | |
| | | @PostMapping("/create") |
| | | @Operation(summary = "å建è½è计éç¹") |
| | | @PreAuthorize("@ss.hasPermission('mes:em-meter:create')") |
| | | public CommonResult<Long> createMeter(@Valid @RequestBody MesEmMeterSaveReqVO createReqVO) { |
| | | return success(meterService.createMeter(createReqVO)); |
| | | } |
| | | |
| | | @PutMapping("/update") |
| | | @Operation(summary = "æ´æ°è½è计éç¹") |
| | | @PreAuthorize("@ss.hasPermission('mes:em-meter:update')") |
| | | public CommonResult<Boolean> updateMeter(@Valid @RequestBody MesEmMeterSaveReqVO updateReqVO) { |
| | | meterService.updateMeter(updateReqVO); |
| | | return success(true); |
| | | } |
| | | |
| | | @DeleteMapping("/delete") |
| | | @Operation(summary = "å é¤è½è计éç¹") |
| | | @Parameter(name = "id", description = "ç¼å·", required = true) |
| | | @PreAuthorize("@ss.hasPermission('mes:em-meter:delete')") |
| | | public CommonResult<Boolean> deleteMeter(@RequestParam("id") Long id) { |
| | | meterService.deleteMeter(id); |
| | | return success(true); |
| | | } |
| | | |
| | | @GetMapping("/get") |
| | | @Operation(summary = "è·å¾è½è计éç¹") |
| | | @Parameter(name = "id", description = "ç¼å·", required = true) |
| | | @PreAuthorize("@ss.hasPermission('mes:em-meter:query')") |
| | | public CommonResult<MesEmMeterRespVO> getMeter(@RequestParam("id") Long id) { |
| | | MesEmMeterDO meter = meterService.getMeter(id); |
| | | if (meter == null) { |
| | | return success(null); |
| | | } |
| | | return success(meterService.getMeterRespVOList(Collections.singletonList(meter)).get(0)); |
| | | } |
| | | |
| | | @GetMapping("/page") |
| | | @Operation(summary = "è·å¾è½è计éç¹å页") |
| | | @PreAuthorize("@ss.hasPermission('mes:em-meter:query')") |
| | | public CommonResult<PageResult<MesEmMeterRespVO>> getMeterPage(@Valid MesEmMeterPageReqVO pageReqVO) { |
| | | PageResult<MesEmMeterDO> pageResult = meterService.getMeterPage(pageReqVO); |
| | | return success(new PageResult<>(meterService.getMeterRespVOList(pageResult.getList()), |
| | | pageResult.getTotal())); |
| | | } |
| | | |
| | | @GetMapping("/simple-list") |
| | | @Operation(summary = "è·å¾å¯ç¨ä¸çè½è计éç¹ç²¾ç®å表") |
| | | @PreAuthorize("@ss.hasPermission('mes:em-meter:query')") |
| | | public CommonResult<List<MesEmOptionRespVO>> getMeterSimpleList() { |
| | | return success(meterService.getMeterSimpleList()); |
| | | } |
| | | |
| | | @GetMapping("/workshop-options") |
| | | @Operation(summary = "è·å¾è½¦é´ä¸æé项") |
| | | @PreAuthorize("@ss.hasPermission('mes:em-meter:query')") |
| | | public CommonResult<List<MesEmOptionRespVO>> getWorkshopOptions() { |
| | | return success(meterService.getWorkshopOptions()); |
| | | } |
| | | |
| | | @GetMapping("/line-options") |
| | | @Operation(summary = "è·å¾äº§çº¿ä¸æé项") |
| | | @PreAuthorize("@ss.hasPermission('mes:em-meter:query')") |
| | | public CommonResult<List<MesEmOptionRespVO>> getLineOptions() { |
| | | return success(meterService.getLineOptions()); |
| | | } |
| | | |
| | | @GetMapping("/machinery-options") |
| | | @Operation(summary = "è·å¾è®¾å¤ä¸æé项") |
| | | @PreAuthorize("@ss.hasPermission('mes:em-meter:query')") |
| | | public CommonResult<List<MesEmOptionRespVO>> getMachineryOptions() { |
| | | return success(meterService.getMachineryOptions()); |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.em.meter.vo; |
| | | |
| | | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | import lombok.ToString; |
| | | |
| | | @Schema(description = "管çåå° - MES è½è计éç¹å页 Request VO") |
| | | @Data |
| | | @EqualsAndHashCode(callSuper = true) |
| | | @ToString(callSuper = true) |
| | | public class MesEmMeterPageReqVO extends PageParam { |
| | | |
| | | @Schema(description = "计éç¹ç¼ç ", example = "EM-DL-001") |
| | | private String code; |
| | | |
| | | @Schema(description = "计éç¹åç§°", example = "ååå¨è½¦é´æ»çµè¡¨") |
| | | private String name; |
| | | |
| | | @Schema(description = "è½æºç±»å", example = "1") |
| | | private Integer energyType; |
| | | |
| | | @Schema(description = "æå±è½¦é´ç¼å·", example = "7") |
| | | private Long workshopId; |
| | | |
| | | @Schema(description = "ç¶æ", example = "1") |
| | | private Integer status; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.em.meter.vo; |
| | | |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | |
| | | @Schema(description = "管çåå° - MES è½è计éç¹ Response VO") |
| | | @Data |
| | | public class MesEmMeterRespVO { |
| | | |
| | | @Schema(description = "ç¼å·", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| | | private Long id; |
| | | |
| | | @Schema(description = "计éç¹ç¼ç ", requiredMode = Schema.RequiredMode.REQUIRED, example = "EM-DL-001") |
| | | private String code; |
| | | |
| | | @Schema(description = "计éç¹åç§°", requiredMode = Schema.RequiredMode.REQUIRED, example = "ååå¨è½¦é´æ»çµè¡¨") |
| | | private String name; |
| | | |
| | | @Schema(description = "è½æºç±»å", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| | | private Integer energyType; |
| | | |
| | | @Schema(description = "è½æºç±»ååç§°", example = "çµ") |
| | | private String energyTypeName; |
| | | |
| | | @Schema(description = "计éåä½", example = "kWh") |
| | | private String unit; |
| | | |
| | | @Schema(description = "表å·", example = "DTSD341-001") |
| | | private String meterNo; |
| | | |
| | | @Schema(description = "æå±è½¦é´ç¼å·", example = "7") |
| | | private Long workshopId; |
| | | |
| | | @Schema(description = "æå±è½¦é´åç§°", example = "ååå¨å¶é 车é´") |
| | | private String workshopName; |
| | | |
| | | @Schema(description = "æå±äº§çº¿ç¼å·", example = "1") |
| | | private Long lineId; |
| | | |
| | | @Schema(description = "æå±äº§çº¿åç§°", example = "ååå¨ç产线") |
| | | private String lineName; |
| | | |
| | | @Schema(description = "å
³è设å¤ç¼å·", example = "1001") |
| | | private Long machineryId; |
| | | |
| | | @Schema(description = "å
³è设å¤åç§°", example = "çç©ºæµæ³¨ç½") |
| | | private String machineryName; |
| | | |
| | | @Schema(description = "åç", example = "1") |
| | | private BigDecimal ratio; |
| | | |
| | | @Schema(description = "åå§è¯»æ°", example = "0") |
| | | private BigDecimal initialReading; |
| | | |
| | | @Schema(description = "ææ ç
¤ç³»æ°ï¼kgce/计éåä½ï¼", example = "0.1229") |
| | | private BigDecimal coalFactor; |
| | | |
| | | @Schema(description = "æ¥ç¨éå¼å¸¸ä¸é", example = "500") |
| | | private BigDecimal leakThreshold; |
| | | |
| | | @Schema(description = "责任人ç¼å·", example = "1") |
| | | private Long chargeUserId; |
| | | |
| | | @Schema(description = "责任人åç§°", example = "å¼ ä¸") |
| | | private String chargeUserName; |
| | | |
| | | @Schema(description = "æç¨æ¥æ") |
| | | private LocalDate installDate; |
| | | |
| | | @Schema(description = "ç¶æ", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| | | private Integer status; |
| | | |
| | | @Schema(description = "ç¶æåç§°", example = "å¯ç¨") |
| | | private String statusName; |
| | | |
| | | @Schema(description = "夿³¨", example = "夿³¨") |
| | | private String remark; |
| | | |
| | | @Schema(description = "å建æ¶é´") |
| | | private LocalDateTime createTime; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.em.meter.vo; |
| | | |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import jakarta.validation.constraints.NotEmpty; |
| | | import jakarta.validation.constraints.NotNull; |
| | | import lombok.Data; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | |
| | | @Schema(description = "管çåå° - MES è½è计éç¹æ°å¢/ä¿®æ¹ Request VO") |
| | | @Data |
| | | public class MesEmMeterSaveReqVO { |
| | | |
| | | @Schema(description = "ç¼å·", example = "1024") |
| | | private Long id; |
| | | |
| | | @Schema(description = "计éç¹ç¼ç ", requiredMode = Schema.RequiredMode.REQUIRED, example = "EM-DL-001") |
| | | @NotEmpty(message = "计éç¹ç¼ç ä¸è½ä¸ºç©º") |
| | | private String code; |
| | | |
| | | @Schema(description = "计éç¹åç§°", requiredMode = Schema.RequiredMode.REQUIRED, example = "ååå¨è½¦é´æ»çµè¡¨") |
| | | @NotEmpty(message = "计éç¹åç§°ä¸è½ä¸ºç©º") |
| | | private String name; |
| | | |
| | | @Schema(description = "è½æºç±»å", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| | | @NotNull(message = "è½æºç±»åä¸è½ä¸ºç©º") |
| | | private Integer energyType; |
| | | |
| | | @Schema(description = "计éåä½", example = "kWh") |
| | | private String unit; |
| | | |
| | | @Schema(description = "表å·", example = "DTSD341-001") |
| | | private String meterNo; |
| | | |
| | | @Schema(description = "æå±è½¦é´ç¼å·", example = "7") |
| | | private Long workshopId; |
| | | |
| | | @Schema(description = "æå±äº§çº¿ç¼å·", example = "1") |
| | | private Long lineId; |
| | | |
| | | @Schema(description = "å
³è设å¤ç¼å·", example = "1001") |
| | | private Long machineryId; |
| | | |
| | | @Schema(description = "åç", example = "1") |
| | | private BigDecimal ratio; |
| | | |
| | | @Schema(description = "åå§è¯»æ°", example = "0") |
| | | private BigDecimal initialReading; |
| | | |
| | | @Schema(description = "ææ ç
¤ç³»æ°ï¼kgce/计éåä½ï¼", example = "0.1229") |
| | | private BigDecimal coalFactor; |
| | | |
| | | @Schema(description = "æ¥ç¨éå¼å¸¸ä¸éï¼è¶
è¿è§¦åçä¼¼è·åæ»´æ¼é¢è¦ï¼", example = "500") |
| | | private BigDecimal leakThreshold; |
| | | |
| | | @Schema(description = "责任人ç¼å·", example = "1") |
| | | private Long chargeUserId; |
| | | |
| | | @Schema(description = "æç¨æ¥æ") |
| | | private LocalDate installDate; |
| | | |
| | | @Schema(description = "ç¶æ", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| | | @NotNull(message = "ç¶æä¸è½ä¸ºç©º") |
| | | private Integer status; |
| | | |
| | | @Schema(description = "夿³¨", example = "夿³¨") |
| | | private String remark; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.em.meter.vo; |
| | | |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * è½è模å䏿é项 VO |
| | | * |
| | | * åæ¶ç¨äºè½¦é´ã产线ã设å¤ã计éç¹ç䏿鿩ã |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @Schema(description = "管çåå° - MES è½è䏿é项 Response VO") |
| | | @Data |
| | | public class MesEmOptionRespVO { |
| | | |
| | | @Schema(description = "ç¼å·") |
| | | private Long id; |
| | | |
| | | @Schema(description = "ç¼ç ") |
| | | private String code; |
| | | |
| | | @Schema(description = "åç§°") |
| | | private String name; |
| | | |
| | | @Schema(description = "è½æºç±»åï¼è®¡éç¹é项使ç¨ï¼") |
| | | private Integer energyType; |
| | | |
| | | @Schema(description = "计éåä½ï¼è®¡éç¹é项使ç¨ï¼") |
| | | private String unit; |
| | | |
| | | @Schema(description = "æå±è½¦é´ç¼å·") |
| | | private Long workshopId; |
| | | |
| | | @Schema(description = "æå±è½¦é´åç§°") |
| | | private String workshopName; |
| | | |
| | | @Schema(description = "æå±äº§çº¿ç¼å·") |
| | | private Long lineId; |
| | | |
| | | @Schema(description = "æå±äº§çº¿åç§°") |
| | | private String lineName; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.em.quota; |
| | | |
| | | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.quota.vo.MesEmQuotaPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.quota.vo.MesEmQuotaRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.quota.vo.MesEmQuotaSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.em.quota.MesEmQuotaDO; |
| | | import cn.iocoder.yudao.module.mes.service.em.quota.MesEmQuotaService; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import jakarta.annotation.Resource; |
| | | import jakarta.validation.Valid; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.Collections; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| | | |
| | | @Tag(name = "管çåå° - MES è½èèæ ¸ææ ") |
| | | @RestController |
| | | @RequestMapping("/mes/em/quota") |
| | | @Validated |
| | | public class MesEmQuotaController { |
| | | |
| | | @Resource |
| | | private MesEmQuotaService quotaService; |
| | | |
| | | @PostMapping("/create") |
| | | @Operation(summary = "å建è½èèæ ¸ææ ") |
| | | @PreAuthorize("@ss.hasPermission('mes:em-quota:create')") |
| | | public CommonResult<Long> createQuota(@Valid @RequestBody MesEmQuotaSaveReqVO createReqVO) { |
| | | return success(quotaService.createQuota(createReqVO)); |
| | | } |
| | | |
| | | @PutMapping("/update") |
| | | @Operation(summary = "æ´æ°è½èèæ ¸ææ ") |
| | | @PreAuthorize("@ss.hasPermission('mes:em-quota:update')") |
| | | public CommonResult<Boolean> updateQuota(@Valid @RequestBody MesEmQuotaSaveReqVO updateReqVO) { |
| | | quotaService.updateQuota(updateReqVO); |
| | | return success(true); |
| | | } |
| | | |
| | | @DeleteMapping("/delete") |
| | | @Operation(summary = "å é¤è½èèæ ¸ææ ") |
| | | @Parameter(name = "id", description = "ç¼å·", required = true) |
| | | @PreAuthorize("@ss.hasPermission('mes:em-quota:delete')") |
| | | public CommonResult<Boolean> deleteQuota(@RequestParam("id") Long id) { |
| | | quotaService.deleteQuota(id); |
| | | return success(true); |
| | | } |
| | | |
| | | @GetMapping("/get") |
| | | @Operation(summary = "è·å¾è½èèæ ¸ææ ") |
| | | @Parameter(name = "id", description = "ç¼å·", required = true) |
| | | @PreAuthorize("@ss.hasPermission('mes:em-quota:query')") |
| | | public CommonResult<MesEmQuotaRespVO> getQuota(@RequestParam("id") Long id) { |
| | | MesEmQuotaDO quota = quotaService.getQuota(id); |
| | | if (quota == null) { |
| | | return success(null); |
| | | } |
| | | return success(quotaService.getQuotaRespVOList(Collections.singletonList(quota)).get(0)); |
| | | } |
| | | |
| | | @GetMapping("/page") |
| | | @Operation(summary = "è·å¾è½èèæ ¸ææ å页") |
| | | @PreAuthorize("@ss.hasPermission('mes:em-quota:query')") |
| | | public CommonResult<PageResult<MesEmQuotaRespVO>> getQuotaPage(@Valid MesEmQuotaPageReqVO pageReqVO) { |
| | | PageResult<MesEmQuotaDO> pageResult = quotaService.getQuotaPage(pageReqVO); |
| | | return success(new PageResult<>(quotaService.getQuotaRespVOList(pageResult.getList()), |
| | | pageResult.getTotal())); |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.em.quota.vo; |
| | | |
| | | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | import lombok.ToString; |
| | | |
| | | @Schema(description = "管çåå° - MES è½èèæ ¸ææ å页 Request VO") |
| | | @Data |
| | | @EqualsAndHashCode(callSuper = true) |
| | | @ToString(callSuper = true) |
| | | public class MesEmQuotaPageReqVO extends PageParam { |
| | | |
| | | @Schema(description = "ææ åç§°", example = "ååå¨è½¦é´ç¨çµæ¥å®é¢") |
| | | private String name; |
| | | |
| | | @Schema(description = "è½æºç±»å", example = "1") |
| | | private Integer energyType; |
| | | |
| | | @Schema(description = "èæ ¸å¯¹è±¡ç±»å", example = "1") |
| | | private Integer objectType; |
| | | |
| | | @Schema(description = "èæ ¸å¨æ", example = "1") |
| | | private Integer periodType; |
| | | |
| | | @Schema(description = "ç¶æ", example = "1") |
| | | private Integer status; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.em.quota.vo; |
| | | |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | |
| | | @Schema(description = "管çåå° - MES è½èèæ ¸ææ Response VO") |
| | | @Data |
| | | public class MesEmQuotaRespVO { |
| | | |
| | | @Schema(description = "ç¼å·", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| | | private Long id; |
| | | |
| | | @Schema(description = "ææ åç§°", requiredMode = Schema.RequiredMode.REQUIRED, example = "ååå¨è½¦é´ç¨çµæ¥å®é¢") |
| | | private String name; |
| | | |
| | | @Schema(description = "è½æºç±»å", example = "1") |
| | | private Integer energyType; |
| | | |
| | | @Schema(description = "è½æºç±»ååç§°", example = "çµ") |
| | | private String energyTypeName; |
| | | |
| | | @Schema(description = "èæ ¸å¯¹è±¡ç±»å", example = "1") |
| | | private Integer objectType; |
| | | |
| | | @Schema(description = "èæ ¸å¯¹è±¡ç±»ååç§°", example = "车é´") |
| | | private String objectTypeName; |
| | | |
| | | @Schema(description = "èæ ¸å¯¹è±¡ç¼å·", example = "7") |
| | | private Long objectId; |
| | | |
| | | @Schema(description = "èæ ¸å¯¹è±¡åç§°", example = "ååå¨å¶é 车é´") |
| | | private String objectName; |
| | | |
| | | @Schema(description = "èæ ¸å¨æ", example = "1") |
| | | private Integer periodType; |
| | | |
| | | @Schema(description = "èæ ¸å¨æåç§°", example = "æ¥") |
| | | private String periodTypeName; |
| | | |
| | | @Schema(description = "å®é¢å¼", example = "1000") |
| | | private BigDecimal quotaValue; |
| | | |
| | | @Schema(description = "计éåä½", example = "kWh") |
| | | private String unit; |
| | | |
| | | @Schema(description = "é¢è¦æ¯ä¾ï¼%ï¼", example = "10") |
| | | private BigDecimal warnRatio; |
| | | |
| | | @Schema(description = "严éé¢è¦æ¯ä¾ï¼%ï¼", example = "20") |
| | | private BigDecimal alarmRatio; |
| | | |
| | | @Schema(description = "ç¯æ¯å¼å¸¸éå¼ï¼%ï¼", example = "30") |
| | | private BigDecimal momWarnRatio; |
| | | |
| | | @Schema(description = "忝å¼å¸¸éå¼ï¼%ï¼", example = "30") |
| | | private BigDecimal yoyWarnRatio; |
| | | |
| | | @Schema(description = "ç¶æ", example = "1") |
| | | private Integer status; |
| | | |
| | | @Schema(description = "ç¶æåç§°", example = "å¯ç¨") |
| | | private String statusName; |
| | | |
| | | @Schema(description = "夿³¨") |
| | | private String remark; |
| | | |
| | | @Schema(description = "å建æ¶é´") |
| | | private LocalDateTime createTime; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.em.quota.vo; |
| | | |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import jakarta.validation.constraints.DecimalMin; |
| | | import jakarta.validation.constraints.NotEmpty; |
| | | import jakarta.validation.constraints.NotNull; |
| | | import lombok.Data; |
| | | |
| | | import java.math.BigDecimal; |
| | | |
| | | @Schema(description = "管çåå° - MES è½èèæ ¸ææ æ°å¢/ä¿®æ¹ Request VO") |
| | | @Data |
| | | public class MesEmQuotaSaveReqVO { |
| | | |
| | | @Schema(description = "ç¼å·", example = "1024") |
| | | private Long id; |
| | | |
| | | @Schema(description = "ææ åç§°", requiredMode = Schema.RequiredMode.REQUIRED, example = "ååå¨è½¦é´ç¨çµæ¥å®é¢") |
| | | @NotEmpty(message = "ææ åç§°ä¸è½ä¸ºç©º") |
| | | private String name; |
| | | |
| | | @Schema(description = "è½æºç±»å", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| | | @NotNull(message = "è½æºç±»åä¸è½ä¸ºç©º") |
| | | private Integer energyType; |
| | | |
| | | @Schema(description = "èæ ¸å¯¹è±¡ç±»å", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| | | @NotNull(message = "èæ ¸å¯¹è±¡ç±»åä¸è½ä¸ºç©º") |
| | | private Integer objectType; |
| | | |
| | | @Schema(description = "èæ ¸å¯¹è±¡ç¼å·ï¼å
¨åæ¶ä¸ºç©ºï¼", example = "7") |
| | | private Long objectId; |
| | | |
| | | @Schema(description = "èæ ¸å¨æ", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| | | @NotNull(message = "èæ ¸å¨æä¸è½ä¸ºç©º") |
| | | private Integer periodType; |
| | | |
| | | @Schema(description = "å®é¢å¼", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") |
| | | @NotNull(message = "å®é¢å¼ä¸è½ä¸ºç©º") |
| | | @DecimalMin(value = "0", message = "å®é¢å¼ä¸è½å°äº 0") |
| | | private BigDecimal quotaValue; |
| | | |
| | | @Schema(description = "计éåä½", example = "kWh") |
| | | private String unit; |
| | | |
| | | @Schema(description = "é¢è¦æ¯ä¾ï¼%ï¼", example = "10") |
| | | private BigDecimal warnRatio; |
| | | |
| | | @Schema(description = "严éé¢è¦æ¯ä¾ï¼%ï¼", example = "20") |
| | | private BigDecimal alarmRatio; |
| | | |
| | | @Schema(description = "ç¯æ¯å¼å¸¸éå¼ï¼%ï¼", example = "30") |
| | | private BigDecimal momWarnRatio; |
| | | |
| | | @Schema(description = "忝å¼å¸¸éå¼ï¼%ï¼", example = "30") |
| | | private BigDecimal yoyWarnRatio; |
| | | |
| | | @Schema(description = "ç¶æ", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| | | @NotNull(message = "ç¶æä¸è½ä¸ºç©º") |
| | | private Integer status; |
| | | |
| | | @Schema(description = "夿³¨") |
| | | private String remark; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.em.record; |
| | | |
| | | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.record.vo.MesEmLastReadingRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.record.vo.MesEmRecordPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.record.vo.MesEmRecordRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.record.vo.MesEmRecordSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.em.record.MesEmRecordDO; |
| | | import cn.iocoder.yudao.module.mes.service.em.record.MesEmRecordService; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import jakarta.annotation.Resource; |
| | | import jakarta.validation.Valid; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.util.Collections; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| | | |
| | | @Tag(name = "管çåå° - MES è½èæè¡¨è®°å½") |
| | | @RestController |
| | | @RequestMapping("/mes/em/record") |
| | | @Validated |
| | | public class MesEmRecordController { |
| | | |
| | | @Resource |
| | | private MesEmRecordService recordService; |
| | | |
| | | @PostMapping("/create") |
| | | @Operation(summary = "å建è½èæè¡¨è®°å½") |
| | | @PreAuthorize("@ss.hasPermission('mes:em-record:create')") |
| | | public CommonResult<Long> createRecord(@Valid @RequestBody MesEmRecordSaveReqVO createReqVO) { |
| | | return success(recordService.createRecord(createReqVO)); |
| | | } |
| | | |
| | | @PutMapping("/update") |
| | | @Operation(summary = "æ´æ°è½èæè¡¨è®°å½") |
| | | @PreAuthorize("@ss.hasPermission('mes:em-record:update')") |
| | | public CommonResult<Boolean> updateRecord(@Valid @RequestBody MesEmRecordSaveReqVO updateReqVO) { |
| | | recordService.updateRecord(updateReqVO); |
| | | return success(true); |
| | | } |
| | | |
| | | @DeleteMapping("/delete") |
| | | @Operation(summary = "å é¤è½èæè¡¨è®°å½") |
| | | @Parameter(name = "id", description = "ç¼å·", required = true) |
| | | @PreAuthorize("@ss.hasPermission('mes:em-record:delete')") |
| | | public CommonResult<Boolean> deleteRecord(@RequestParam("id") Long id) { |
| | | recordService.deleteRecord(id); |
| | | return success(true); |
| | | } |
| | | |
| | | @GetMapping("/get") |
| | | @Operation(summary = "è·å¾è½èæè¡¨è®°å½") |
| | | @Parameter(name = "id", description = "ç¼å·", required = true) |
| | | @PreAuthorize("@ss.hasPermission('mes:em-record:query')") |
| | | public CommonResult<MesEmRecordRespVO> getRecord(@RequestParam("id") Long id) { |
| | | MesEmRecordDO record = recordService.getRecord(id); |
| | | if (record == null) { |
| | | return success(null); |
| | | } |
| | | return success(recordService.getRecordRespVOList(Collections.singletonList(record)).get(0)); |
| | | } |
| | | |
| | | @GetMapping("/page") |
| | | @Operation(summary = "è·å¾è½èæè¡¨è®°å½å页") |
| | | @PreAuthorize("@ss.hasPermission('mes:em-record:query')") |
| | | public CommonResult<PageResult<MesEmRecordRespVO>> getRecordPage(@Valid MesEmRecordPageReqVO pageReqVO) { |
| | | PageResult<MesEmRecordDO> pageResult = recordService.getRecordPage(pageReqVO); |
| | | return success(new PageResult<>(recordService.getRecordRespVOList(pageResult.getList()), |
| | | pageResult.getTotal())); |
| | | } |
| | | |
| | | @GetMapping("/last-reading") |
| | | @Operation(summary = "è·å¾è®¡éç¹ä¸æè¯»æ°", description = "ç¨äºæ°å¢æè¡¨è®°å½æ¶èªå¨å¸¦å
¥æå读æ°") |
| | | @PreAuthorize("@ss.hasPermission('mes:em-record:query')") |
| | | public CommonResult<MesEmLastReadingRespVO> getLastReading( |
| | | @RequestParam("meterId") Long meterId, |
| | | @RequestParam("recordDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate recordDate, |
| | | @RequestParam(value = "excludeId", required = false) Long excludeId) { |
| | | return success(recordService.getLastReading(meterId, recordDate, excludeId)); |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.em.record.vo; |
| | | |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Data; |
| | | import lombok.NoArgsConstructor; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | |
| | | @Schema(description = "管çåå° - MES è½èä¸æè¯»æ° Response VO") |
| | | @Data |
| | | @NoArgsConstructor |
| | | @AllArgsConstructor |
| | | public class MesEmLastReadingRespVO { |
| | | |
| | | @Schema(description = "ä¸æè¯»æ°", example = "1000") |
| | | private BigDecimal prevReading; |
| | | |
| | | @Schema(description = "䏿æè¡¨æ¥æ") |
| | | private LocalDate lastDate; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.em.record.vo; |
| | | |
| | | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | import lombok.ToString; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | |
| | | import java.time.LocalDate; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY; |
| | | |
| | | @Schema(description = "管çåå° - MES è½èæè¡¨è®°å½å页 Request VO") |
| | | @Data |
| | | @EqualsAndHashCode(callSuper = true) |
| | | @ToString(callSuper = true) |
| | | public class MesEmRecordPageReqVO extends PageParam { |
| | | |
| | | @Schema(description = "计éç¹ç¼å·", example = "1024") |
| | | private Long meterId; |
| | | |
| | | @Schema(description = "计éç¹åç§°", example = "ååå¨è½¦é´æ»çµè¡¨") |
| | | private String meterName; |
| | | |
| | | @Schema(description = "è½æºç±»å", example = "1") |
| | | private Integer energyType; |
| | | |
| | | @Schema(description = "æå±è½¦é´ç¼å·", example = "7") |
| | | private Long workshopId; |
| | | |
| | | @Schema(description = "æ°æ®æ¥æº", example = "1") |
| | | private Integer source; |
| | | |
| | | @Schema(description = "æè¡¨æ¥æ") |
| | | @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY) |
| | | private LocalDate[] recordDate; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.em.record.vo; |
| | | |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | |
| | | @Schema(description = "管çåå° - MES è½èæè¡¨è®°å½ Response VO") |
| | | @Data |
| | | public class MesEmRecordRespVO { |
| | | |
| | | @Schema(description = "ç¼å·", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| | | private Long id; |
| | | |
| | | @Schema(description = "计éç¹ç¼å·", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| | | private Long meterId; |
| | | |
| | | @Schema(description = "计éç¹ç¼ç ", example = "EM-DL-001") |
| | | private String meterCode; |
| | | |
| | | @Schema(description = "计éç¹åç§°", example = "ååå¨è½¦é´æ»çµè¡¨") |
| | | private String meterName; |
| | | |
| | | @Schema(description = "è½æºç±»å", example = "1") |
| | | private Integer energyType; |
| | | |
| | | @Schema(description = "è½æºç±»ååç§°", example = "çµ") |
| | | private String energyTypeName; |
| | | |
| | | @Schema(description = "计éåä½", example = "kWh") |
| | | private String unit; |
| | | |
| | | @Schema(description = "åç", example = "1") |
| | | private BigDecimal ratio; |
| | | |
| | | @Schema(description = "ææ ç
¤ç³»æ°", example = "0.1229") |
| | | private BigDecimal coalFactor; |
| | | |
| | | @Schema(description = "æå±è½¦é´ç¼å·", example = "7") |
| | | private Long workshopId; |
| | | |
| | | @Schema(description = "æå±è½¦é´åç§°", example = "ååå¨å¶é 车é´") |
| | | private String workshopName; |
| | | |
| | | @Schema(description = "æå±äº§çº¿ç¼å·", example = "1") |
| | | private Long lineId; |
| | | |
| | | @Schema(description = "æå±äº§çº¿åç§°", example = "ååå¨ç产线") |
| | | private String lineName; |
| | | |
| | | @Schema(description = "å
³è设å¤ç¼å·", example = "1001") |
| | | private Long machineryId; |
| | | |
| | | @Schema(description = "å
³è设å¤åç§°", example = "çç©ºæµæ³¨ç½") |
| | | private String machineryName; |
| | | |
| | | @Schema(description = "æè¡¨æ¥æ", requiredMode = Schema.RequiredMode.REQUIRED) |
| | | private LocalDate recordDate; |
| | | |
| | | @Schema(description = "æå读æ°", example = "1000") |
| | | private BigDecimal prevReading; |
| | | |
| | | @Schema(description = "ææ«è¯»æ°", example = "1200") |
| | | private BigDecimal reading; |
| | | |
| | | @Schema(description = "å®é
ç¨é", example = "200") |
| | | private BigDecimal usageAmount; |
| | | |
| | | @Schema(description = "åä»·", example = "0.68") |
| | | private BigDecimal price; |
| | | |
| | | @Schema(description = "è´¹ç¨", example = "136") |
| | | private BigDecimal cost; |
| | | |
| | | @Schema(description = "æ°æ®æ¥æº", example = "1") |
| | | private Integer source; |
| | | |
| | | @Schema(description = "æ°æ®æ¥æºåç§°", example = "æå·¥å½å
¥") |
| | | private String sourceName; |
| | | |
| | | @Schema(description = "夿³¨") |
| | | private String remark; |
| | | |
| | | @Schema(description = "å建æ¶é´") |
| | | private LocalDateTime createTime; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.em.record.vo; |
| | | |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import jakarta.validation.constraints.NotNull; |
| | | import lombok.Data; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | |
| | | @Schema(description = "管çåå° - MES è½èæè¡¨è®°å½æ°å¢/ä¿®æ¹ Request VO") |
| | | @Data |
| | | public class MesEmRecordSaveReqVO { |
| | | |
| | | @Schema(description = "ç¼å·", example = "1024") |
| | | private Long id; |
| | | |
| | | @Schema(description = "计éç¹ç¼å·", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| | | @NotNull(message = "计éç¹ä¸è½ä¸ºç©º") |
| | | private Long meterId; |
| | | |
| | | @Schema(description = "æè¡¨æ¥æ", requiredMode = Schema.RequiredMode.REQUIRED) |
| | | @NotNull(message = "æè¡¨æ¥æä¸è½ä¸ºç©º") |
| | | private LocalDate recordDate; |
| | | |
| | | @Schema(description = "æå读æ°ï¼ä¸ºç©ºæ¶åä¸ä¸æ¡è®°å½è¯»æ°æè®¡éç¹åå§è¯»æ°ï¼", example = "1000") |
| | | private BigDecimal prevReading; |
| | | |
| | | @Schema(description = "ææ«è¯»æ°", requiredMode = Schema.RequiredMode.REQUIRED, example = "1200") |
| | | @NotNull(message = "ææ«è¯»æ°ä¸è½ä¸ºç©º") |
| | | private BigDecimal reading; |
| | | |
| | | @Schema(description = "åä»·ï¼å
/计éåä½ï¼", example = "0.68") |
| | | private BigDecimal price; |
| | | |
| | | @Schema(description = "æ°æ®æ¥æº", example = "1") |
| | | private Integer source; |
| | | |
| | | @Schema(description = "夿³¨", example = "夿³¨") |
| | | private String remark; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.em.statistics; |
| | | |
| | | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.statistics.vo.MesEmOverviewRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.statistics.vo.MesEmReportRespVO; |
| | | import cn.iocoder.yudao.module.mes.service.em.statistics.MesEmStatisticsService; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.time.LocalDate; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| | | |
| | | @Tag(name = "管çåå° - MES è½èç»è®¡") |
| | | @RestController |
| | | @RequestMapping("/mes/em/statistics") |
| | | @Validated |
| | | public class MesEmStatisticsController { |
| | | |
| | | @Resource |
| | | private MesEmStatisticsService statisticsService; |
| | | |
| | | @GetMapping("/overview") |
| | | @Operation(summary = "è·å¾è½èæ»è§æ°æ®") |
| | | @PreAuthorize("@ss.hasPermission('mes:em-overview:query')") |
| | | public CommonResult<MesEmOverviewRespVO> getOverview( |
| | | @RequestParam(value = "beginDate", required = false) |
| | | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate beginDate, |
| | | @RequestParam(value = "endDate", required = false) |
| | | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate) { |
| | | return success(statisticsService.getOverview(beginDate, endDate)); |
| | | } |
| | | |
| | | @GetMapping("/report") |
| | | @Operation(summary = "è·å¾æåº¦è½èæ¥è¡¨ï¼å«åæ¯ãç¯æ¯ï¼") |
| | | @Parameter(name = "period", description = "æä»½ yyyy-MM", example = "2026-10") |
| | | @PreAuthorize("@ss.hasPermission('mes:em-report:query')") |
| | | public CommonResult<MesEmReportRespVO> getReport( |
| | | @RequestParam(value = "period", required = false) String period) { |
| | | return success(statisticsService.getReport(period)); |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.em.statistics.vo; |
| | | |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.List; |
| | | |
| | | @Schema(description = "管çåå° - MES è½èæ»è§ Response VO") |
| | | @Data |
| | | public class MesEmOverviewRespVO { |
| | | |
| | | @Schema(description = "综åè½èï¼å¨æ ç
¤ï¼", example = "12.34") |
| | | private BigDecimal totalTce; |
| | | |
| | | @Schema(description = "æ»è´¹ç¨ï¼å
ï¼", example = "123456.78") |
| | | private BigDecimal totalCost; |
| | | |
| | | @Schema(description = "计éç¹æ°é", example = "20") |
| | | private Integer meterCount; |
| | | |
| | | @Schema(description = "æªå¤çé¢è¦æ°é", example = "3") |
| | | private Integer pendingAlertCount; |
| | | |
| | | @Schema(description = "è½æºç±»åç»è®¡") |
| | | private List<TypeStat> typeStats; |
| | | |
| | | @Schema(description = "车é´è½èç»è®¡") |
| | | private List<WorkshopStat> workshopStats; |
| | | |
| | | @Schema(description = "è½èè¶å¿") |
| | | private List<TrendPoint> trend; |
| | | |
| | | @Schema(description = "éç¹ç¨è½è®¾å¤æè¡") |
| | | private List<MeterStat> topMeters; |
| | | |
| | | @Schema(description = "æè¿é¢è¦") |
| | | private List<RecentAlert> recentAlerts; |
| | | |
| | | @Data |
| | | public static class TypeStat { |
| | | |
| | | @Schema(description = "è½æºç±»å") |
| | | private Integer energyType; |
| | | |
| | | @Schema(description = "è½æºç±»ååç§°") |
| | | private String energyTypeName; |
| | | |
| | | @Schema(description = "ç¨é") |
| | | private BigDecimal usage; |
| | | |
| | | @Schema(description = "计éåä½") |
| | | private String unit; |
| | | |
| | | @Schema(description = "è´¹ç¨") |
| | | private BigDecimal cost; |
| | | |
| | | @Schema(description = "ææ ç
¤ï¼å¨ï¼") |
| | | private BigDecimal tce; |
| | | |
| | | } |
| | | |
| | | @Data |
| | | public static class WorkshopStat { |
| | | |
| | | @Schema(description = "车é´ç¼å·") |
| | | private Long workshopId; |
| | | |
| | | @Schema(description = "车é´åç§°") |
| | | private String workshopName; |
| | | |
| | | @Schema(description = "ææ ç
¤ï¼å¨ï¼") |
| | | private BigDecimal tce; |
| | | |
| | | @Schema(description = "è´¹ç¨") |
| | | private BigDecimal cost; |
| | | |
| | | } |
| | | |
| | | @Data |
| | | public static class TrendPoint { |
| | | |
| | | @Schema(description = "æ¥æ") |
| | | private String date; |
| | | |
| | | @Schema(description = "综åè½èï¼å¨æ ç
¤ï¼") |
| | | private BigDecimal tce; |
| | | |
| | | @Schema(description = "è´¹ç¨") |
| | | private BigDecimal cost; |
| | | |
| | | @Schema(description = "ç¨çµé") |
| | | private BigDecimal electricity; |
| | | |
| | | @Schema(description = "ç¨æ°´é") |
| | | private BigDecimal water; |
| | | |
| | | @Schema(description = "çæ²¹ç¨é") |
| | | private BigDecimal fuel; |
| | | |
| | | @Schema(description = "å¤©ç¶æ°ç¨é") |
| | | private BigDecimal gas; |
| | | |
| | | } |
| | | |
| | | @Data |
| | | public static class MeterStat { |
| | | |
| | | @Schema(description = "计éç¹ç¼å·") |
| | | private Long meterId; |
| | | |
| | | @Schema(description = "计éç¹åç§°") |
| | | private String meterName; |
| | | |
| | | @Schema(description = "è½æºç±»å") |
| | | private Integer energyType; |
| | | |
| | | @Schema(description = "è½æºç±»ååç§°") |
| | | private String energyTypeName; |
| | | |
| | | @Schema(description = "ç¨é") |
| | | private BigDecimal usage; |
| | | |
| | | @Schema(description = "计éåä½") |
| | | private String unit; |
| | | |
| | | @Schema(description = "è´¹ç¨") |
| | | private BigDecimal cost; |
| | | |
| | | @Schema(description = "ææ ç
¤ï¼å¨ï¼") |
| | | private BigDecimal tce; |
| | | |
| | | } |
| | | |
| | | @Data |
| | | public static class RecentAlert { |
| | | |
| | | @Schema(description = "é¢è¦ç¼å·") |
| | | private Long id; |
| | | |
| | | @Schema(description = "é¢è¦å
容") |
| | | private String content; |
| | | |
| | | @Schema(description = "é¢è¦çº§å«") |
| | | private Integer alertLevel; |
| | | |
| | | @Schema(description = "é¢è¦çº§å«åç§°") |
| | | private String alertLevelName; |
| | | |
| | | @Schema(description = "é¢è¦æ¥æ") |
| | | private String alertDate; |
| | | |
| | | @Schema(description = "å¤çç¶æ") |
| | | private Integer status; |
| | | |
| | | @Schema(description = "å¤çç¶æåç§°") |
| | | private String statusName; |
| | | |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.em.statistics.vo; |
| | | |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.util.List; |
| | | |
| | | @Schema(description = "管çåå° - MES è½èæ¥è¡¨ Response VO") |
| | | @Data |
| | | public class MesEmReportRespVO { |
| | | |
| | | @Schema(description = "æ¥è¡¨æä»½", example = "2026-10") |
| | | private String period; |
| | | |
| | | @Schema(description = "å¼å§æ¥æ") |
| | | private LocalDate beginDate; |
| | | |
| | | @Schema(description = "ç»ææ¥æ") |
| | | private LocalDate endDate; |
| | | |
| | | @Schema(description = "综åè½èï¼å¨æ ç
¤ï¼") |
| | | private BigDecimal totalTce; |
| | | |
| | | @Schema(description = "æ»è´¹ç¨") |
| | | private BigDecimal totalCost; |
| | | |
| | | @Schema(description = "ä¸æç»¼åè½è") |
| | | private BigDecimal lastMonthTce; |
| | | |
| | | @Schema(description = "ç¯æ¯ï¼%ï¼") |
| | | private BigDecimal momRate; |
| | | |
| | | @Schema(description = "å»å¹´åæç»¼åè½è") |
| | | private BigDecimal lastYearTce; |
| | | |
| | | @Schema(description = "忝ï¼%ï¼") |
| | | private BigDecimal yoyRate; |
| | | |
| | | @Schema(description = "æè½æºç±»åç»è®¡") |
| | | private List<TypeRow> typeRows; |
| | | |
| | | @Schema(description = "æè½¦é´ç»è®¡") |
| | | private List<WorkshopRow> workshopRows; |
| | | |
| | | @Data |
| | | public static class TypeRow { |
| | | |
| | | @Schema(description = "è½æºç±»å") |
| | | private Integer energyType; |
| | | |
| | | @Schema(description = "è½æºç±»ååç§°") |
| | | private String energyTypeName; |
| | | |
| | | @Schema(description = "æ¬æç¨é") |
| | | private BigDecimal usage; |
| | | |
| | | @Schema(description = "计éåä½") |
| | | private String unit; |
| | | |
| | | @Schema(description = "æ¬æè´¹ç¨") |
| | | private BigDecimal cost; |
| | | |
| | | @Schema(description = "æ¬æææ ç
¤ï¼å¨ï¼") |
| | | private BigDecimal tce; |
| | | |
| | | @Schema(description = "䏿ç¨é") |
| | | private BigDecimal lastMonthUsage; |
| | | |
| | | @Schema(description = "ç¯æ¯ï¼%ï¼") |
| | | private BigDecimal momRate; |
| | | |
| | | @Schema(description = "å»å¹´åæç¨é") |
| | | private BigDecimal lastYearUsage; |
| | | |
| | | @Schema(description = "忝ï¼%ï¼") |
| | | private BigDecimal yoyRate; |
| | | |
| | | } |
| | | |
| | | @Data |
| | | public static class WorkshopRow { |
| | | |
| | | @Schema(description = "车é´ç¼å·") |
| | | private Long workshopId; |
| | | |
| | | @Schema(description = "车é´åç§°") |
| | | private String workshopName; |
| | | |
| | | @Schema(description = "æ¬æè´¹ç¨") |
| | | private BigDecimal cost; |
| | | |
| | | @Schema(description = "æ¬æææ ç
¤ï¼å¨ï¼") |
| | | private BigDecimal tce; |
| | | |
| | | @Schema(description = "ä¸æææ ç
¤ï¼å¨ï¼") |
| | | private BigDecimal lastMonthTce; |
| | | |
| | | @Schema(description = "ç¯æ¯ï¼%ï¼") |
| | | private BigDecimal momRate; |
| | | |
| | | @Schema(description = "å»å¹´åæææ ç
¤ï¼å¨ï¼") |
| | | private BigDecimal lastYearTce; |
| | | |
| | | @Schema(description = "忝ï¼%ï¼") |
| | | private BigDecimal yoyRate; |
| | | |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.dal.dataobject.em.alert; |
| | | |
| | | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| | | import com.baomidou.mybatisplus.annotation.KeySequence; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.*; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | |
| | | /** |
| | | * MES è½èé¢è¦è®°å½ DO |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @TableName("mes_em_alert") |
| | | @KeySequence("mes_em_alert_seq") |
| | | @Data |
| | | @EqualsAndHashCode(callSuper = true) |
| | | @ToString(callSuper = true) |
| | | @Builder |
| | | @NoArgsConstructor |
| | | @AllArgsConstructor |
| | | public class MesEmAlertDO extends BaseDO { |
| | | |
| | | /** |
| | | * ç¼å· |
| | | */ |
| | | @TableId |
| | | private Long id; |
| | | /** |
| | | * é¢è¦ç¼å· |
| | | */ |
| | | private String alertNo; |
| | | /** |
| | | * 计éç¹ç¼å·ï¼å®é¢é¢è¦ä¸º 0ï¼ |
| | | */ |
| | | private Long meterId; |
| | | /** |
| | | * 计éç¹ç¼ç |
| | | */ |
| | | private String meterCode; |
| | | /** |
| | | * 计éç¹åç§° |
| | | */ |
| | | private String meterName; |
| | | /** |
| | | * è½æºç±»å |
| | | * |
| | | * æä¸¾ {@link cn.iocoder.yudao.module.mes.enums.em.MesEmEnergyTypeEnum} |
| | | */ |
| | | private Integer energyType; |
| | | /** |
| | | * é¢è¦ç±»å |
| | | * |
| | | * æä¸¾ {@link cn.iocoder.yudao.module.mes.enums.em.MesEmAlertTypeEnum} |
| | | */ |
| | | private Integer alertType; |
| | | /** |
| | | * é¢è¦çº§å« |
| | | * |
| | | * æä¸¾ {@link cn.iocoder.yudao.module.mes.enums.em.MesEmAlertLevelEnum} |
| | | */ |
| | | private Integer alertLevel; |
| | | /** |
| | | * é¢è¦æ¥æ |
| | | */ |
| | | private LocalDate alertDate; |
| | | /** |
| | | * èæ ¸å¯¹è±¡ç±»å |
| | | * |
| | | * æä¸¾ {@link cn.iocoder.yudao.module.mes.enums.em.MesEmQuotaObjectTypeEnum} |
| | | */ |
| | | private Integer objectType; |
| | | /** |
| | | * èæ ¸å¯¹è±¡ç¼å·ï¼éå®é¢é¢è¦ä¸º 0ï¼ |
| | | */ |
| | | private Long objectId; |
| | | /** |
| | | * èæ ¸å¯¹è±¡åç§° |
| | | */ |
| | | private String objectName; |
| | | /** |
| | | * å®é
å¼ |
| | | */ |
| | | private BigDecimal actualValue; |
| | | /** |
| | | * éå¼ |
| | | */ |
| | | private BigDecimal thresholdValue; |
| | | /** |
| | | * 计éåä½ |
| | | */ |
| | | private String unit; |
| | | /** |
| | | * é¢è¦å
容 |
| | | */ |
| | | private String content; |
| | | /** |
| | | * å¤çç¶æ |
| | | * |
| | | * æä¸¾ {@link cn.iocoder.yudao.module.mes.enums.em.MesEmAlertStatusEnum} |
| | | */ |
| | | private Integer status; |
| | | /** |
| | | * å¤ç人ç¼å· |
| | | */ |
| | | private Long handleUserId; |
| | | /** |
| | | * å¤ç人åç§° |
| | | */ |
| | | private String handleUserName; |
| | | /** |
| | | * å¤çæ¶é´ |
| | | */ |
| | | private LocalDateTime handleTime; |
| | | /** |
| | | * å¤ç说æ |
| | | */ |
| | | private String handleRemark; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.dal.dataobject.em.meter; |
| | | |
| | | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| | | import com.baomidou.mybatisplus.annotation.KeySequence; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.*; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | |
| | | /** |
| | | * MES è½è计éç¹ DO |
| | | * |
| | | * ä¸ä¸ªè®¡éç¹å¯ä»¥æå¨è½¦é´ã产线æéç¹é«èè½è®¾å¤ä¸ï¼ç¨äºééæä¸ç±»è½æºçç¨éã |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @TableName("mes_em_meter") |
| | | @KeySequence("mes_em_meter_seq") |
| | | @Data |
| | | @EqualsAndHashCode(callSuper = true) |
| | | @ToString(callSuper = true) |
| | | @Builder |
| | | @NoArgsConstructor |
| | | @AllArgsConstructor |
| | | public class MesEmMeterDO extends BaseDO { |
| | | |
| | | /** |
| | | * ç¼å· |
| | | */ |
| | | @TableId |
| | | private Long id; |
| | | /** |
| | | * 计éç¹ç¼ç |
| | | */ |
| | | private String code; |
| | | /** |
| | | * 计éç¹åç§° |
| | | */ |
| | | private String name; |
| | | /** |
| | | * è½æºç±»å |
| | | * |
| | | * æä¸¾ {@link cn.iocoder.yudao.module.mes.enums.em.MesEmEnergyTypeEnum} |
| | | */ |
| | | private Integer energyType; |
| | | /** |
| | | * 计éåä½ |
| | | */ |
| | | private String unit; |
| | | /** |
| | | * 表å·ï¼ç°åºè¡¨è®¡ç¼å·ï¼ |
| | | */ |
| | | private String meterNo; |
| | | /** |
| | | * æå±è½¦é´ç¼å· |
| | | */ |
| | | private Long workshopId; |
| | | /** |
| | | * æå±è½¦é´åç§° |
| | | */ |
| | | private String workshopName; |
| | | /** |
| | | * æå±äº§çº¿ç¼å· |
| | | */ |
| | | private Long lineId; |
| | | /** |
| | | * æå±äº§çº¿åç§° |
| | | */ |
| | | private String lineName; |
| | | /** |
| | | * å
³è设å¤ç¼å· |
| | | */ |
| | | private Long machineryId; |
| | | /** |
| | | * å
³è设å¤åç§° |
| | | */ |
| | | private String machineryName; |
| | | /** |
| | | * åçï¼è¯»æ° à åç = å®é
ç¨éï¼ |
| | | */ |
| | | private BigDecimal ratio; |
| | | /** |
| | | * åå§è¯»æ° |
| | | */ |
| | | private BigDecimal initialReading; |
| | | /** |
| | | * ææ ç
¤ç³»æ°ï¼kgce/计éåä½ï¼ |
| | | */ |
| | | private BigDecimal coalFactor; |
| | | /** |
| | | * æ¥ç¨éå¼å¸¸ä¸éï¼è¶
è¿å触åçä¼¼è·åæ»´æ¼é¢è¦ï¼ä¸ºç©ºè¡¨ç¤ºä¸æ£æµï¼ |
| | | */ |
| | | private BigDecimal leakThreshold; |
| | | /** |
| | | * 责任人ç¼å· |
| | | */ |
| | | private Long chargeUserId; |
| | | /** |
| | | * æç¨æ¥æ |
| | | */ |
| | | private LocalDate installDate; |
| | | /** |
| | | * ç¶æ |
| | | * |
| | | * æä¸¾ {@link cn.iocoder.yudao.module.mes.enums.em.MesEmMeterStatusEnum} |
| | | */ |
| | | private Integer status; |
| | | /** |
| | | * 夿³¨ |
| | | */ |
| | | private String remark; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.dal.dataobject.em.quota; |
| | | |
| | | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| | | import com.baomidou.mybatisplus.annotation.KeySequence; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.*; |
| | | |
| | | import java.math.BigDecimal; |
| | | |
| | | /** |
| | | * MES è½èèæ ¸ææ DO |
| | | * |
| | | * æå
¨å / è½¦é´ / 产线 / 设å¤é
ç½®æ¥ææçè½èå®é¢ï¼å¹¶è®¾ç½®è¶
éé¢è¦æ¯ä¾ã |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @TableName("mes_em_quota") |
| | | @KeySequence("mes_em_quota_seq") |
| | | @Data |
| | | @EqualsAndHashCode(callSuper = true) |
| | | @ToString(callSuper = true) |
| | | @Builder |
| | | @NoArgsConstructor |
| | | @AllArgsConstructor |
| | | public class MesEmQuotaDO extends BaseDO { |
| | | |
| | | /** |
| | | * ç¼å· |
| | | */ |
| | | @TableId |
| | | private Long id; |
| | | /** |
| | | * ææ åç§° |
| | | */ |
| | | private String name; |
| | | /** |
| | | * è½æºç±»å |
| | | * |
| | | * æä¸¾ {@link cn.iocoder.yudao.module.mes.enums.em.MesEmEnergyTypeEnum} |
| | | */ |
| | | private Integer energyType; |
| | | /** |
| | | * èæ ¸å¯¹è±¡ç±»å |
| | | * |
| | | * æä¸¾ {@link cn.iocoder.yudao.module.mes.enums.em.MesEmQuotaObjectTypeEnum} |
| | | */ |
| | | private Integer objectType; |
| | | /** |
| | | * èæ ¸å¯¹è±¡ç¼å·ï¼å
¨åæ¶ä¸ºç©ºï¼ |
| | | */ |
| | | private Long objectId; |
| | | /** |
| | | * èæ ¸å¯¹è±¡åç§°ï¼ä¿åæ¶åä½ï¼ |
| | | */ |
| | | private String objectName; |
| | | /** |
| | | * èæ ¸å¨æ |
| | | * |
| | | * æä¸¾ {@link cn.iocoder.yudao.module.mes.enums.em.MesEmQuotaPeriodEnum} |
| | | */ |
| | | private Integer periodType; |
| | | /** |
| | | * å®é¢å¼ |
| | | */ |
| | | private BigDecimal quotaValue; |
| | | /** |
| | | * 计éåä½ |
| | | */ |
| | | private String unit; |
| | | /** |
| | | * é¢è¦æ¯ä¾ï¼è¶
åºå®é¢å¤å°ç¾åæ¯è§¦åè¦åï¼ |
| | | */ |
| | | private BigDecimal warnRatio; |
| | | /** |
| | | * 严éé¢è¦æ¯ä¾ï¼è¶
åºå®é¢å¤å°ç¾åæ¯è§¦å严éé¢è¦ï¼ |
| | | */ |
| | | private BigDecimal alarmRatio; |
| | | /** |
| | | * ç¯æ¯å¼å¸¸éå¼ï¼%ï¼ |
| | | */ |
| | | private BigDecimal momWarnRatio; |
| | | /** |
| | | * 忝å¼å¸¸éå¼ï¼%ï¼ |
| | | */ |
| | | private BigDecimal yoyWarnRatio; |
| | | /** |
| | | * ç¶æ |
| | | * |
| | | * æä¸¾ {@link cn.iocoder.yudao.module.mes.enums.em.MesEmMeterStatusEnum} |
| | | */ |
| | | private Integer status; |
| | | /** |
| | | * 夿³¨ |
| | | */ |
| | | private String remark; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.dal.dataobject.em.record; |
| | | |
| | | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| | | import com.baomidou.mybatisplus.annotation.KeySequence; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.*; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | |
| | | /** |
| | | * MES è½èæè¡¨è®°å½ DO |
| | | * |
| | | * è®°å½ä¿åæ¶ä¼æè®¡éç¹çåç§°ã车é´/产线/设å¤ä¿¡æ¯åä½è¿æ¥ï¼ä½ä¸ºåå²å¿«ç
§ï¼ |
| | | * åç»ä¸»æ°æ®æ¹åä¸ä¼å½±åå岿¥è¡¨ã |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @TableName("mes_em_record") |
| | | @KeySequence("mes_em_record_seq") |
| | | @Data |
| | | @EqualsAndHashCode(callSuper = true) |
| | | @ToString(callSuper = true) |
| | | @Builder |
| | | @NoArgsConstructor |
| | | @AllArgsConstructor |
| | | public class MesEmRecordDO extends BaseDO { |
| | | |
| | | /** |
| | | * ç¼å· |
| | | */ |
| | | @TableId |
| | | private Long id; |
| | | /** |
| | | * 计éç¹ç¼å· |
| | | */ |
| | | private Long meterId; |
| | | /** |
| | | * 计éç¹ç¼ç |
| | | */ |
| | | private String meterCode; |
| | | /** |
| | | * 计éç¹åç§° |
| | | */ |
| | | private String meterName; |
| | | /** |
| | | * è½æºç±»å |
| | | * |
| | | * æä¸¾ {@link cn.iocoder.yudao.module.mes.enums.em.MesEmEnergyTypeEnum} |
| | | */ |
| | | private Integer energyType; |
| | | /** |
| | | * 计éåä½ |
| | | */ |
| | | private String unit; |
| | | /** |
| | | * åç |
| | | */ |
| | | private BigDecimal ratio; |
| | | /** |
| | | * ææ ç
¤ç³»æ°ï¼kgce/计éåä½ï¼ |
| | | */ |
| | | private BigDecimal coalFactor; |
| | | /** |
| | | * æå±è½¦é´ç¼å· |
| | | */ |
| | | private Long workshopId; |
| | | /** |
| | | * æå±è½¦é´åç§° |
| | | */ |
| | | private String workshopName; |
| | | /** |
| | | * æå±äº§çº¿ç¼å· |
| | | */ |
| | | private Long lineId; |
| | | /** |
| | | * æå±äº§çº¿åç§° |
| | | */ |
| | | private String lineName; |
| | | /** |
| | | * å
³è设å¤ç¼å· |
| | | */ |
| | | private Long machineryId; |
| | | /** |
| | | * å
³è设å¤åç§° |
| | | */ |
| | | private String machineryName; |
| | | /** |
| | | * æè¡¨æ¥æ |
| | | */ |
| | | private LocalDate recordDate; |
| | | /** |
| | | * æåè¯»æ° |
| | | */ |
| | | private BigDecimal prevReading; |
| | | /** |
| | | * ææ«è¯»æ° |
| | | */ |
| | | private BigDecimal reading; |
| | | /** |
| | | * å®é
ç¨éï¼(ææ«è¯»æ° - æå读æ°) à åçï¼ |
| | | */ |
| | | private BigDecimal usageAmount; |
| | | /** |
| | | * åä»·ï¼å
/计éåä½ï¼ |
| | | */ |
| | | private BigDecimal price; |
| | | /** |
| | | * è´¹ç¨ï¼å
ï¼ |
| | | */ |
| | | private BigDecimal cost; |
| | | /** |
| | | * æ°æ®æ¥æº |
| | | * |
| | | * æä¸¾ {@link cn.iocoder.yudao.module.mes.enums.em.MesEmRecordSourceEnum} |
| | | */ |
| | | private Integer source; |
| | | /** |
| | | * 夿³¨ |
| | | */ |
| | | private String remark; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.dal.mysql.em.alert; |
| | | |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| | | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.alert.vo.MesEmAlertPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.em.alert.MesEmAlertDO; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * MES è½èé¢è¦ Mapper |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @Mapper |
| | | public interface MesEmAlertMapper extends BaseMapperX<MesEmAlertDO> { |
| | | |
| | | default PageResult<MesEmAlertDO> selectPage(MesEmAlertPageReqVO reqVO) { |
| | | return selectPage(reqVO, new LambdaQueryWrapperX<MesEmAlertDO>() |
| | | .likeIfPresent(MesEmAlertDO::getMeterName, reqVO.getMeterName()) |
| | | .eqIfPresent(MesEmAlertDO::getEnergyType, reqVO.getEnergyType()) |
| | | .eqIfPresent(MesEmAlertDO::getAlertType, reqVO.getAlertType()) |
| | | .eqIfPresent(MesEmAlertDO::getAlertLevel, reqVO.getAlertLevel()) |
| | | .eqIfPresent(MesEmAlertDO::getStatus, reqVO.getStatus()) |
| | | .betweenIfPresent(MesEmAlertDO::getAlertDate, reqVO.getAlertDate()) |
| | | .orderByDesc(MesEmAlertDO::getAlertDate) |
| | | .orderByDesc(MesEmAlertDO::getId)); |
| | | } |
| | | |
| | | default MesEmAlertDO selectByUnique(Long meterId, Integer alertType, LocalDate alertDate, Long objectId) { |
| | | return selectOne(new LambdaQueryWrapperX<MesEmAlertDO>() |
| | | .eq(MesEmAlertDO::getMeterId, meterId) |
| | | .eq(MesEmAlertDO::getAlertType, alertType) |
| | | .eq(MesEmAlertDO::getAlertDate, alertDate) |
| | | .eq(MesEmAlertDO::getObjectId, objectId)); |
| | | } |
| | | |
| | | default List<MesEmAlertDO> selectRecent(LocalDate begin, LocalDate end, int limit) { |
| | | return selectList(new LambdaQueryWrapperX<MesEmAlertDO>() |
| | | .ge(MesEmAlertDO::getAlertDate, begin) |
| | | .le(MesEmAlertDO::getAlertDate, end) |
| | | .orderByDesc(MesEmAlertDO::getAlertDate) |
| | | .orderByDesc(MesEmAlertDO::getId) |
| | | .last("LIMIT " + limit)); |
| | | } |
| | | |
| | | default Long selectPendingCount() { |
| | | return selectCount(new LambdaQueryWrapperX<MesEmAlertDO>() |
| | | .eq(MesEmAlertDO::getStatus, 0)); |
| | | } |
| | | |
| | | default Long selectCountByDateRange(LocalDate begin, LocalDate end) { |
| | | return selectCount(new LambdaQueryWrapperX<MesEmAlertDO>() |
| | | .between(MesEmAlertDO::getAlertDate, begin, end)); |
| | | } |
| | | |
| | | default int deleteByMeterIdAndDate(Long meterId, LocalDate alertDate) { |
| | | return delete(new LambdaQueryWrapperX<MesEmAlertDO>() |
| | | .eq(MesEmAlertDO::getMeterId, meterId) |
| | | .eq(MesEmAlertDO::getAlertDate, alertDate)); |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.dal.mysql.em.meter; |
| | | |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| | | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.meter.vo.MesEmMeterPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.meter.vo.MesEmOptionRespVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.em.meter.MesEmMeterDO; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.apache.ibatis.annotations.Param; |
| | | import org.apache.ibatis.annotations.Select; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * MES è½è计éç¹ Mapper |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @Mapper |
| | | public interface MesEmMeterMapper extends BaseMapperX<MesEmMeterDO> { |
| | | |
| | | default PageResult<MesEmMeterDO> selectPage(MesEmMeterPageReqVO reqVO) { |
| | | return selectPage(reqVO, new LambdaQueryWrapperX<MesEmMeterDO>() |
| | | .likeIfPresent(MesEmMeterDO::getCode, reqVO.getCode()) |
| | | .likeIfPresent(MesEmMeterDO::getName, reqVO.getName()) |
| | | .eqIfPresent(MesEmMeterDO::getEnergyType, reqVO.getEnergyType()) |
| | | .eqIfPresent(MesEmMeterDO::getWorkshopId, reqVO.getWorkshopId()) |
| | | .eqIfPresent(MesEmMeterDO::getStatus, reqVO.getStatus()) |
| | | .orderByDesc(MesEmMeterDO::getId)); |
| | | } |
| | | |
| | | default MesEmMeterDO selectByCode(String code) { |
| | | return selectOne(MesEmMeterDO::getCode, code); |
| | | } |
| | | |
| | | default List<MesEmMeterDO> selectListByStatus(Integer status) { |
| | | return selectList(new LambdaQueryWrapperX<MesEmMeterDO>() |
| | | .eqIfPresent(MesEmMeterDO::getStatus, status) |
| | | .orderByAsc(MesEmMeterDO::getEnergyType) |
| | | .orderByAsc(MesEmMeterDO::getCode)); |
| | | } |
| | | |
| | | @Select("SELECT id, code, name FROM mes_md_workshop WHERE deleted = 0 ORDER BY id") |
| | | List<MesEmOptionRespVO> selectWorkshopOptions(); |
| | | |
| | | @Select("SELECT id, code, name FROM mes_pro_line WHERE deleted = 0 ORDER BY id") |
| | | List<MesEmOptionRespVO> selectLineOptions(); |
| | | |
| | | @Select("SELECT id, code, name FROM mes_pro_line WHERE id = #{id} AND deleted = 0") |
| | | MesEmOptionRespVO selectLineOptionById(@Param("id") Long id); |
| | | |
| | | @Select("SELECT id, code, name, workshop_id AS workshopId FROM mes_dv_machinery WHERE deleted = 0 ORDER BY id") |
| | | List<MesEmOptionRespVO> selectMachineryOptions(); |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.dal.mysql.em.quota; |
| | | |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| | | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.quota.vo.MesEmQuotaPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.em.quota.MesEmQuotaDO; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * MES è½èèæ ¸ææ Mapper |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @Mapper |
| | | public interface MesEmQuotaMapper extends BaseMapperX<MesEmQuotaDO> { |
| | | |
| | | default PageResult<MesEmQuotaDO> selectPage(MesEmQuotaPageReqVO reqVO) { |
| | | return selectPage(reqVO, new LambdaQueryWrapperX<MesEmQuotaDO>() |
| | | .likeIfPresent(MesEmQuotaDO::getName, reqVO.getName()) |
| | | .eqIfPresent(MesEmQuotaDO::getEnergyType, reqVO.getEnergyType()) |
| | | .eqIfPresent(MesEmQuotaDO::getObjectType, reqVO.getObjectType()) |
| | | .eqIfPresent(MesEmQuotaDO::getPeriodType, reqVO.getPeriodType()) |
| | | .eqIfPresent(MesEmQuotaDO::getStatus, reqVO.getStatus()) |
| | | .orderByDesc(MesEmQuotaDO::getId)); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢æç±»è½æºä¸ã䏿å®è½¦é´/产线/设å¤ç¸å
³çå¯ç¨ææ |
| | | */ |
| | | default List<MesEmQuotaDO> selectListByObject(Integer energyType, Integer periodType, |
| | | Long workshopId, Long lineId, Long machineryId) { |
| | | return selectList(new LambdaQueryWrapperX<MesEmQuotaDO>() |
| | | .eq(MesEmQuotaDO::getEnergyType, energyType) |
| | | .eqIfPresent(MesEmQuotaDO::getPeriodType, periodType) |
| | | .eq(MesEmQuotaDO::getStatus, 1) |
| | | .and(wrapper -> wrapper |
| | | .eq(MesEmQuotaDO::getObjectType, 0) |
| | | .or(workshopId != null, w -> w.eq(MesEmQuotaDO::getObjectType, 1) |
| | | .eq(MesEmQuotaDO::getObjectId, workshopId)) |
| | | .or(lineId != null, w -> w.eq(MesEmQuotaDO::getObjectType, 2) |
| | | .eq(MesEmQuotaDO::getObjectId, lineId)) |
| | | .or(machineryId != null, w -> w.eq(MesEmQuotaDO::getObjectType, 3) |
| | | .eq(MesEmQuotaDO::getObjectId, machineryId))) |
| | | .orderByAsc(MesEmQuotaDO::getId)); |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.dal.mysql.em.record; |
| | | |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.record.vo.MesEmRecordPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.em.record.MesEmRecordDO; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.apache.ibatis.annotations.Param; |
| | | import org.apache.ibatis.annotations.Select; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * MES è½èæè¡¨è®°å½ Mapper |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @Mapper |
| | | public interface MesEmRecordMapper extends BaseMapperX<MesEmRecordDO> { |
| | | |
| | | default PageResult<MesEmRecordDO> selectPage(MesEmRecordPageReqVO reqVO) { |
| | | return selectPage(reqVO, new LambdaQueryWrapperX<MesEmRecordDO>() |
| | | .eqIfPresent(MesEmRecordDO::getMeterId, reqVO.getMeterId()) |
| | | .likeIfPresent(MesEmRecordDO::getMeterName, reqVO.getMeterName()) |
| | | .eqIfPresent(MesEmRecordDO::getEnergyType, reqVO.getEnergyType()) |
| | | .eqIfPresent(MesEmRecordDO::getWorkshopId, reqVO.getWorkshopId()) |
| | | .eqIfPresent(MesEmRecordDO::getSource, reqVO.getSource()) |
| | | .betweenIfPresent(MesEmRecordDO::getRecordDate, reqVO.getRecordDate()) |
| | | .orderByDesc(MesEmRecordDO::getRecordDate) |
| | | .orderByDesc(MesEmRecordDO::getId)); |
| | | } |
| | | |
| | | default MesEmRecordDO selectByMeterIdAndDate(Long meterId, LocalDate recordDate) { |
| | | return selectOne(new LambdaQueryWrapperX<MesEmRecordDO>() |
| | | .eq(MesEmRecordDO::getMeterId, meterId) |
| | | .eq(MesEmRecordDO::getRecordDate, recordDate)); |
| | | } |
| | | |
| | | default MesEmRecordDO selectLastByMeterId(Long meterId, LocalDate beforeDate, Long excludeId) { |
| | | return selectOne(new LambdaQueryWrapperX<MesEmRecordDO>() |
| | | .eq(MesEmRecordDO::getMeterId, meterId) |
| | | .lt(MesEmRecordDO::getRecordDate, beforeDate) |
| | | .ne(excludeId != null, MesEmRecordDO::getId, excludeId) |
| | | .orderByDesc(MesEmRecordDO::getRecordDate) |
| | | .orderByDesc(MesEmRecordDO::getId) |
| | | .last("LIMIT 1")); |
| | | } |
| | | |
| | | default List<MesEmRecordDO> selectListByMeterIdAndDateRange(Long meterId, LocalDate begin, LocalDate end) { |
| | | return selectList(new LambdaQueryWrapperX<MesEmRecordDO>() |
| | | .eq(MesEmRecordDO::getMeterId, meterId) |
| | | .between(MesEmRecordDO::getRecordDate, begin, end)); |
| | | } |
| | | |
| | | /** |
| | | * ç»è®¡æä¸ªèæ ¸å¯¹è±¡å¨æå®åºé´å
çç¨é |
| | | * |
| | | * @param objectType 0 å
¨å / 1 è½¦é´ / 2 产线 / 3 è®¾å¤ |
| | | */ |
| | | @Select(""" |
| | | <script> |
| | | SELECT COALESCE(SUM(usage_amount), 0) |
| | | FROM mes_em_record |
| | | WHERE deleted = 0 |
| | | AND energy_type = #{energyType} |
| | | AND record_date BETWEEN #{begin} AND #{end} |
| | | <if test="objectType == 1">AND workshop_id = #{objectId}</if> |
| | | <if test="objectType == 2">AND line_id = #{objectId}</if> |
| | | <if test="objectType == 3">AND machinery_id = #{objectId}</if> |
| | | </script> |
| | | """) |
| | | BigDecimal sumUsage(@Param("energyType") Integer energyType, |
| | | @Param("objectType") Integer objectType, |
| | | @Param("objectId") Long objectId, |
| | | @Param("begin") LocalDate begin, |
| | | @Param("end") LocalDate end); |
| | | |
| | | @Select(""" |
| | | SELECT COALESCE(SUM(usage_amount), 0) |
| | | FROM mes_em_record |
| | | WHERE deleted = 0 AND meter_id = #{meterId} AND record_date BETWEEN #{begin} AND #{end} |
| | | """) |
| | | BigDecimal sumMeterUsage(@Param("meterId") Long meterId, |
| | | @Param("begin") LocalDate begin, |
| | | @Param("end") LocalDate end); |
| | | |
| | | @Select(""" |
| | | SELECT COALESCE(SUM(usage_amount), 0) |
| | | FROM mes_em_record |
| | | WHERE deleted = 0 AND energy_type = #{energyType} AND record_date BETWEEN #{begin} AND #{end} |
| | | """) |
| | | BigDecimal sumTypeUsage(@Param("energyType") Integer energyType, |
| | | @Param("begin") LocalDate begin, |
| | | @Param("end") LocalDate end); |
| | | |
| | | default List<MesEmRecordDO> selectListByDateRange(LocalDate begin, LocalDate end) { |
| | | return selectList(new LambdaQueryWrapperX<MesEmRecordDO>() |
| | | .between(MesEmRecordDO::getRecordDate, begin, end) |
| | | .orderByAsc(MesEmRecordDO::getRecordDate) |
| | | .orderByAsc(MesEmRecordDO::getId)); |
| | | } |
| | | |
| | | // ==================== ç»è®¡æ¥è¯¢ ==================== |
| | | |
| | | default List<Map<String, Object>> selectTypeStats(LocalDate begin, LocalDate end) { |
| | | return selectMaps(new QueryWrapper<MesEmRecordDO>() |
| | | .select("energy_type AS energyType", |
| | | "COALESCE(SUM(usage_amount), 0) AS usageAmount", |
| | | "COALESCE(SUM(cost), 0) AS costAmount", |
| | | "COALESCE(SUM(usage_amount * coal_factor) / 1000, 0) AS tce") |
| | | .between("record_date", begin, end) |
| | | .groupBy("energy_type") |
| | | .orderByAsc("energy_type")); |
| | | } |
| | | |
| | | default List<Map<String, Object>> selectWorkshopStats(LocalDate begin, LocalDate end) { |
| | | return selectMaps(new QueryWrapper<MesEmRecordDO>() |
| | | .select("workshop_id AS workshopId", |
| | | "workshop_name AS workshopName", |
| | | "COALESCE(SUM(usage_amount * coal_factor) / 1000, 0) AS tce", |
| | | "COALESCE(SUM(cost), 0) AS costAmount") |
| | | .between("record_date", begin, end) |
| | | .isNotNull("workshop_id") |
| | | .groupBy("workshop_id", "workshop_name") |
| | | .orderByDesc("tce")); |
| | | } |
| | | |
| | | default List<Map<String, Object>> selectTrendRows(LocalDate begin, LocalDate end) { |
| | | return selectMaps(new QueryWrapper<MesEmRecordDO>() |
| | | .select("record_date AS recordDate", |
| | | "energy_type AS energyType", |
| | | "COALESCE(SUM(usage_amount), 0) AS usageAmount", |
| | | "COALESCE(SUM(cost), 0) AS costAmount", |
| | | "COALESCE(SUM(usage_amount * coal_factor) / 1000, 0) AS tce") |
| | | .between("record_date", begin, end) |
| | | .groupBy("record_date", "energy_type") |
| | | .orderByAsc("record_date")); |
| | | } |
| | | |
| | | default List<Map<String, Object>> selectTopMeterStats(LocalDate begin, LocalDate end, int limit) { |
| | | return selectMaps(new QueryWrapper<MesEmRecordDO>() |
| | | .select("meter_id AS meterId", |
| | | "meter_name AS meterName", |
| | | "energy_type AS energyType", |
| | | "unit AS unit", |
| | | "COALESCE(SUM(usage_amount), 0) AS usageAmount", |
| | | "COALESCE(SUM(cost), 0) AS costAmount", |
| | | "COALESCE(SUM(usage_amount * coal_factor) / 1000, 0) AS tce") |
| | | .between("record_date", begin, end) |
| | | .groupBy("meter_id", "meter_name", "energy_type", "unit") |
| | | .orderByDesc("tce") |
| | | .last("LIMIT " + limit)); |
| | | } |
| | | |
| | | default Long selectCountByMeterId(Long meterId) { |
| | | return selectCount(new LambdaQueryWrapperX<MesEmRecordDO>() |
| | | .eq(MesEmRecordDO::getMeterId, meterId)); |
| | | } |
| | | |
| | | } |
| | |
| | | String MES_DV_METERING_CHECK_RESULT = "mes_dv_metering_check_result"; // MES è®¡éæ£æµç»è®º |
| | | String MES_DV_TELEMETRY_ANOMALY = "mes_dv_telemetry_anomaly"; // MES æ°éæ¯å¦å¼å¸¸ |
| | | |
| | | // ========== è½è管ç (EM) ========== |
| | | String MES_EM_ENERGY_TYPE = "mes_em_energy_type"; // MES è½æºç±»å |
| | | String MES_EM_METER_STATUS = "mes_em_meter_status"; // MES è½è计éç¹ç¶æ |
| | | String MES_EM_RECORD_SOURCE = "mes_em_record_source"; // MES è½èæ°æ®æ¥æº |
| | | String MES_EM_QUOTA_OBJECT_TYPE = "mes_em_quota_object_type"; // MES è½èèæ ¸å¯¹è±¡ç±»å |
| | | String MES_EM_QUOTA_PERIOD = "mes_em_quota_period"; // MES è½èèæ ¸å¨æ |
| | | String MES_EM_ALERT_TYPE = "mes_em_alert_type"; // MES è½èé¢è¦ç±»å |
| | | String MES_EM_ALERT_LEVEL = "mes_em_alert_level"; // MES è½èé¢è¦çº§å« |
| | | String MES_EM_ALERT_STATUS = "mes_em_alert_status"; // MES è½èé¢è¦å¤çç¶æ |
| | | |
| | | // ========== æçæ¥å (CAL) ========== |
| | | String MES_CAL_HOLIDAY_TYPE = "mes_cal_holiday_type"; // MES åæç±»å |
| | | String MES_CAL_SHIFT_TYPE = "mes_cal_shift_type"; // MES è½®çæ¹å¼ |
| | |
| | | ErrorCode WM_TRANSFER_IMPORT_LIST_IS_EMPTY = new ErrorCode(1_040_950_014, "导å
¥è½¬ç§»åæ°æ®ä¸è½ä¸ºç©ºï¼"); |
| | | ErrorCode WM_PACKAGE_IMPORT_LIST_IS_EMPTY = new ErrorCode(1_040_950_015, "导å
¥è£
ç®±åæ°æ®ä¸è½ä¸ºç©ºï¼"); |
| | | |
| | | // ========== MES è½è管çï¼1-040-902-000ï¼ ========== |
| | | ErrorCode EM_METER_NOT_EXISTS = new ErrorCode(1_040_902_000, "è½è计éç¹ä¸åå¨"); |
| | | ErrorCode EM_METER_CODE_DUPLICATE = new ErrorCode(1_040_902_001, "è½è计éç¹ç¼ç å·²åå¨"); |
| | | ErrorCode EM_METER_HAS_RECORD = new ErrorCode(1_040_902_002, "è½è计éç¹å·²åå¨æè¡¨è®°å½ï¼æ æ³å é¤"); |
| | | ErrorCode EM_METER_OBJECT_NOT_EXISTS = new ErrorCode(1_040_902_003, "计éç¹å
³èç车é´/产线/设å¤ä¸åå¨"); |
| | | ErrorCode EM_RECORD_NOT_EXISTS = new ErrorCode(1_040_902_010, "è½èæè¡¨è®°å½ä¸åå¨"); |
| | | ErrorCode EM_RECORD_DATE_DUPLICATE = new ErrorCode(1_040_902_011, "该计éç¹å¨å½æ¥å·²åå¨æè¡¨è®°å½"); |
| | | ErrorCode EM_RECORD_READING_INVALID = new ErrorCode(1_040_902_012, "ææ«è¯»æ°ä¸è½å°äºæå读æ°"); |
| | | ErrorCode EM_QUOTA_NOT_EXISTS = new ErrorCode(1_040_902_020, "è½èèæ ¸ææ ä¸åå¨"); |
| | | ErrorCode EM_QUOTA_OBJECT_NOT_EXISTS = new ErrorCode(1_040_902_021, "èæ ¸å¯¹è±¡ä¸åå¨"); |
| | | ErrorCode EM_ALERT_NOT_EXISTS = new ErrorCode(1_040_902_030, "è½èé¢è¦ä¸åå¨"); |
| | | ErrorCode EM_ALERT_ALREADY_HANDLED = new ErrorCode(1_040_902_031, "è½èé¢è¦å·²å¤çï¼è¯·å¿é夿ä½"); |
| | | |
| | | // ========== MES ç产模å-忮坼å
¥ï¼1-040-960-000ï¼ ========== |
| | | ErrorCode MES_PRO_WORK_ORDER_IMPORT_LIST_IS_EMPTY = new ErrorCode(1_040_960_000, "导å
¥çäº§å·¥åæ°æ®ä¸è½ä¸ºç©ºï¼"); |
| | | ErrorCode MES_PRO_FEEDBACK_IMPORT_LIST_IS_EMPTY = new ErrorCode(1_040_960_001, "导å
¥ç产æ¥å·¥æ°æ®ä¸è½ä¸ºç©ºï¼"); |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.enums.em; |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Getter; |
| | | |
| | | import java.util.Arrays; |
| | | |
| | | /** |
| | | * MES è½èé¢è¦çº§å«æä¸¾ |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @Getter |
| | | @AllArgsConstructor |
| | | public enum MesEmAlertLevelEnum { |
| | | |
| | | INFO(1, "æç¤º"), |
| | | WARN(2, "è¦å"), |
| | | SERIOUS(3, "严é"); |
| | | |
| | | /** |
| | | * çº§å« |
| | | */ |
| | | private final Integer level; |
| | | /** |
| | | * 级å«åç§° |
| | | */ |
| | | private final String name; |
| | | |
| | | public static MesEmAlertLevelEnum getByLevel(Integer level) { |
| | | return Arrays.stream(values()).filter(item -> item.getLevel().equals(level)).findFirst().orElse(null); |
| | | } |
| | | |
| | | public static String getName(Integer level) { |
| | | MesEmAlertLevelEnum item = getByLevel(level); |
| | | return item == null ? null : item.getName(); |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.enums.em; |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Getter; |
| | | |
| | | import java.util.Arrays; |
| | | |
| | | /** |
| | | * MES è½èé¢è¦å¤çç¶ææä¸¾ |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @Getter |
| | | @AllArgsConstructor |
| | | public enum MesEmAlertStatusEnum { |
| | | |
| | | PENDING(0, "æªå¤ç"), |
| | | HANDLED(1, "å·²å¤ç"); |
| | | |
| | | /** |
| | | * ç¶æ |
| | | */ |
| | | private final Integer status; |
| | | /** |
| | | * ç¶æåç§° |
| | | */ |
| | | private final String name; |
| | | |
| | | public static MesEmAlertStatusEnum getByStatus(Integer status) { |
| | | return Arrays.stream(values()).filter(item -> item.getStatus().equals(status)).findFirst().orElse(null); |
| | | } |
| | | |
| | | public static String getName(Integer status) { |
| | | MesEmAlertStatusEnum item = getByStatus(status); |
| | | return item == null ? null : item.getName(); |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.enums.em; |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Getter; |
| | | |
| | | import java.util.Arrays; |
| | | |
| | | /** |
| | | * MES è½èé¢è¦ç±»åæä¸¾ |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @Getter |
| | | @AllArgsConstructor |
| | | public enum MesEmAlertTypeEnum { |
| | | |
| | | QUOTA(1, "è¶
å®é¢"), |
| | | MOM(2, "ç¯æ¯å¼å¸¸"), |
| | | YOY(3, "忝å¼å¸¸"), |
| | | LEAK(4, "çä¼¼è·åæ»´æ¼"); |
| | | |
| | | /** |
| | | * ç±»å |
| | | */ |
| | | private final Integer type; |
| | | /** |
| | | * ç±»ååç§° |
| | | */ |
| | | private final String name; |
| | | |
| | | public static MesEmAlertTypeEnum getByType(Integer type) { |
| | | return Arrays.stream(values()).filter(item -> item.getType().equals(type)).findFirst().orElse(null); |
| | | } |
| | | |
| | | public static String getName(Integer type) { |
| | | MesEmAlertTypeEnum item = getByType(type); |
| | | return item == null ? null : item.getName(); |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.enums.em; |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Getter; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Arrays; |
| | | |
| | | /** |
| | | * MES è½æºç±»åæä¸¾ |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @Getter |
| | | @AllArgsConstructor |
| | | public enum MesEmEnergyTypeEnum { |
| | | |
| | | ELECTRICITY(1, "çµ", "kWh", new BigDecimal("0.1229")), |
| | | WATER(2, "æ°´", "t", new BigDecimal("0.2429")), |
| | | FUEL(3, "çæ²¹", "L", new BigDecimal("1.2000")), |
| | | GAS(4, "å¤©ç¶æ°", "m³", new BigDecimal("1.3300")); |
| | | |
| | | /** |
| | | * è½æºç±»å |
| | | */ |
| | | private final Integer type; |
| | | /** |
| | | * è½æºç±»ååç§° |
| | | */ |
| | | private final String name; |
| | | /** |
| | | * é»è®¤è®¡éåä½ |
| | | */ |
| | | private final String unit; |
| | | /** |
| | | * é»è®¤ææ ç
¤ç³»æ°ï¼kgce/计éåä½ï¼ |
| | | */ |
| | | private final BigDecimal coalFactor; |
| | | |
| | | public static MesEmEnergyTypeEnum getByType(Integer type) { |
| | | return Arrays.stream(values()).filter(item -> item.getType().equals(type)).findFirst().orElse(null); |
| | | } |
| | | |
| | | public static String getName(Integer type) { |
| | | MesEmEnergyTypeEnum energyType = getByType(type); |
| | | return energyType == null ? null : energyType.getName(); |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.enums.em; |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Getter; |
| | | |
| | | import java.util.Arrays; |
| | | |
| | | /** |
| | | * MES è½è计éç¹ç¶ææä¸¾ |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @Getter |
| | | @AllArgsConstructor |
| | | public enum MesEmMeterStatusEnum { |
| | | |
| | | ENABLE(1, "å¯ç¨"), |
| | | DISABLE(0, "åç¨"); |
| | | |
| | | /** |
| | | * ç¶æ |
| | | */ |
| | | private final Integer status; |
| | | /** |
| | | * ç¶æåç§° |
| | | */ |
| | | private final String name; |
| | | |
| | | public static MesEmMeterStatusEnum getByStatus(Integer status) { |
| | | return Arrays.stream(values()).filter(item -> item.getStatus().equals(status)).findFirst().orElse(null); |
| | | } |
| | | |
| | | public static String getName(Integer status) { |
| | | MesEmMeterStatusEnum item = getByStatus(status); |
| | | return item == null ? null : item.getName(); |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.enums.em; |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Getter; |
| | | |
| | | import java.util.Arrays; |
| | | |
| | | /** |
| | | * MES è½èèæ ¸å¯¹è±¡ç±»åæä¸¾ |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @Getter |
| | | @AllArgsConstructor |
| | | public enum MesEmQuotaObjectTypeEnum { |
| | | |
| | | FACTORY(0, "å
¨å"), |
| | | WORKSHOP(1, "车é´"), |
| | | LINE(2, "产线"), |
| | | MACHINERY(3, "设å¤"); |
| | | |
| | | /** |
| | | * 对象类å |
| | | */ |
| | | private final Integer type; |
| | | /** |
| | | * 对象类ååç§° |
| | | */ |
| | | private final String name; |
| | | |
| | | public static MesEmQuotaObjectTypeEnum getByType(Integer type) { |
| | | return Arrays.stream(values()).filter(item -> item.getType().equals(type)).findFirst().orElse(null); |
| | | } |
| | | |
| | | public static String getName(Integer type) { |
| | | MesEmQuotaObjectTypeEnum item = getByType(type); |
| | | return item == null ? null : item.getName(); |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.enums.em; |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Getter; |
| | | |
| | | import java.util.Arrays; |
| | | |
| | | /** |
| | | * MES è½èèæ ¸å¨ææä¸¾ |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @Getter |
| | | @AllArgsConstructor |
| | | public enum MesEmQuotaPeriodEnum { |
| | | |
| | | DAY(1, "æ¥"), |
| | | MONTH(2, "æ"); |
| | | |
| | | /** |
| | | * 卿 |
| | | */ |
| | | private final Integer period; |
| | | /** |
| | | * 卿åç§° |
| | | */ |
| | | private final String name; |
| | | |
| | | public static MesEmQuotaPeriodEnum getByPeriod(Integer period) { |
| | | return Arrays.stream(values()).filter(item -> item.getPeriod().equals(period)).findFirst().orElse(null); |
| | | } |
| | | |
| | | public static String getName(Integer period) { |
| | | MesEmQuotaPeriodEnum item = getByPeriod(period); |
| | | return item == null ? null : item.getName(); |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.enums.em; |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Getter; |
| | | |
| | | import java.util.Arrays; |
| | | |
| | | /** |
| | | * MES è½èæ°æ®æ¥æºæä¸¾ |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @Getter |
| | | @AllArgsConstructor |
| | | public enum MesEmRecordSourceEnum { |
| | | |
| | | MANUAL(1, "æå·¥å½å
¥"), |
| | | IMPORT(2, "Excel 导å
¥"), |
| | | AUTO(3, "èªå¨éé"); |
| | | |
| | | /** |
| | | * æ¥æº |
| | | */ |
| | | private final Integer source; |
| | | /** |
| | | * æ¥æºåç§° |
| | | */ |
| | | private final String name; |
| | | |
| | | public static MesEmRecordSourceEnum getBySource(Integer source) { |
| | | return Arrays.stream(values()).filter(item -> item.getSource().equals(source)).findFirst().orElse(null); |
| | | } |
| | | |
| | | public static String getName(Integer source) { |
| | | MesEmRecordSourceEnum item = getBySource(source); |
| | | return item == null ? null : item.getName(); |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.service.em.alert; |
| | | |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.alert.vo.MesEmAlertHandleReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.alert.vo.MesEmAlertPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.alert.vo.MesEmAlertRespVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.em.alert.MesEmAlertDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.em.record.MesEmRecordDO; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * MES è½èé¢è¦ Service |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | public interface MesEmAlertService { |
| | | |
| | | /** |
| | | * æ ¹æ®ä¸æ¡æè¡¨è®°å½æ£æµå¹¶çæé¢è¦ |
| | | */ |
| | | void checkRecord(MesEmRecordDO record); |
| | | |
| | | /** |
| | | * éæ°æ£æµæå®æ¥æåºé´çæè¡¨è®°å½ |
| | | * |
| | | * @return æ£æµçè®°å½æ° |
| | | */ |
| | | int checkRange(LocalDate begin, LocalDate end); |
| | | |
| | | /** |
| | | * å é¤æä¸ªè®¡éç¹æå¤©çç¯æ¯/忝/è·åæ»´æ¼é¢è¦ï¼æè¡¨è®°å½å 餿¶è°ç¨ï¼ |
| | | */ |
| | | void deleteMeterAlerts(Long meterId, LocalDate alertDate); |
| | | |
| | | MesEmAlertDO getAlert(Long id); |
| | | |
| | | PageResult<MesEmAlertDO> getAlertPage(MesEmAlertPageReqVO pageReqVO); |
| | | |
| | | List<MesEmAlertRespVO> getAlertRespVOList(List<MesEmAlertDO> list); |
| | | |
| | | void handleAlert(MesEmAlertHandleReqVO handleReqVO); |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.service.em.alert; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.alert.vo.MesEmAlertHandleReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.alert.vo.MesEmAlertPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.alert.vo.MesEmAlertRespVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.em.alert.MesEmAlertDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.em.meter.MesEmMeterDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.em.quota.MesEmQuotaDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.em.record.MesEmRecordDO; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.em.alert.MesEmAlertMapper; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.em.meter.MesEmMeterMapper; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.em.quota.MesEmQuotaMapper; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.em.record.MesEmRecordMapper; |
| | | import cn.iocoder.yudao.module.mes.enums.em.*; |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Collections; |
| | | import java.util.Comparator; |
| | | import java.util.List; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.EM_ALERT_ALREADY_HANDLED; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.EM_ALERT_NOT_EXISTS; |
| | | |
| | | /** |
| | | * MES è½èé¢è¦ Service å®ç°ç±» |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @Service |
| | | @Validated |
| | | public class MesEmAlertServiceImpl implements MesEmAlertService { |
| | | |
| | | private static final BigDecimal HUNDRED = new BigDecimal("100"); |
| | | private static final BigDecimal DEFAULT_MOM_RATIO = new BigDecimal("30"); |
| | | private static final BigDecimal DEFAULT_YOY_RATIO = new BigDecimal("30"); |
| | | private static final DateTimeFormatter DATE_NO_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd"); |
| | | |
| | | @Resource |
| | | private MesEmAlertMapper alertMapper; |
| | | @Resource |
| | | private MesEmRecordMapper recordMapper; |
| | | @Resource |
| | | private MesEmMeterMapper meterMapper; |
| | | @Resource |
| | | private MesEmQuotaMapper quotaMapper; |
| | | |
| | | @Override |
| | | public void checkRecord(MesEmRecordDO record) { |
| | | MesEmMeterDO meter = meterMapper.selectById(record.getMeterId()); |
| | | checkQuota(record, MesEmQuotaPeriodEnum.DAY); |
| | | checkQuota(record, MesEmQuotaPeriodEnum.MONTH); |
| | | checkMomentum(record); |
| | | checkLeak(record, meter); |
| | | } |
| | | |
| | | /** |
| | | * å®é¢é¢è¦ï¼æ¥å®é¢æ¯è¾å½æ¥ç¨éï¼æå®é¢æ¯è¾æåè³å½æ¥ç´¯è®¡ç¨é |
| | | */ |
| | | private void checkQuota(MesEmRecordDO record, MesEmQuotaPeriodEnum period) { |
| | | List<MesEmQuotaDO> quotas = quotaMapper.selectListByObject(record.getEnergyType(), period.getPeriod(), |
| | | record.getWorkshopId(), record.getLineId(), record.getMachineryId()); |
| | | MesEmQuotaDO quota = mostSpecificQuota(quotas); |
| | | if (quota == null) { |
| | | return; |
| | | } |
| | | LocalDate begin = MesEmQuotaPeriodEnum.MONTH.equals(period) |
| | | ? record.getRecordDate().withDayOfMonth(1) : record.getRecordDate(); |
| | | BigDecimal actual = recordMapper.sumUsage(record.getEnergyType(), quota.getObjectType(), |
| | | quota.getObjectId(), begin, record.getRecordDate()); |
| | | BigDecimal quotaValue = quota.getQuotaValue() == null ? BigDecimal.ZERO : quota.getQuotaValue(); |
| | | BigDecimal warnRatio = defaultIfNull(quota.getWarnRatio(), new BigDecimal("10")); |
| | | BigDecimal alarmRatio = defaultIfNull(quota.getAlarmRatio(), new BigDecimal("20")); |
| | | BigDecimal warnThreshold = quotaValue.multiply(BigDecimal.ONE.add( |
| | | warnRatio.divide(HUNDRED, 6, RoundingMode.HALF_UP))); |
| | | BigDecimal alarmThreshold = quotaValue.multiply(BigDecimal.ONE.add( |
| | | alarmRatio.divide(HUNDRED, 6, RoundingMode.HALF_UP))); |
| | | |
| | | Long objectId = quota.getObjectId() == null ? 0L : quota.getObjectId(); |
| | | if (actual.compareTo(warnThreshold) <= 0) { |
| | | // ç¨éåè½å°éå¼å
æ¶ï¼æ¤éå°æªå¤ççé¢è¦ |
| | | deleteIfPending(0L, MesEmAlertTypeEnum.QUOTA.getType(), record.getRecordDate(), objectId); |
| | | return; |
| | | } |
| | | BigDecimal exceedRate = rate(actual, quotaValue); |
| | | String unit = StrUtil.blankToDefault(record.getUnit(), StrUtil.blankToDefault(quota.getUnit(), "")); |
| | | String content = StrUtil.format("{}{} {} ç¨é {} {}ï¼å®é¢ {} {}ï¼è¶
åº {}%", period.getName(), |
| | | quota.getObjectName(), MesEmEnergyTypeEnum.getName(record.getEnergyType()), |
| | | stripZeros(actual), unit, stripZeros(quotaValue), unit, |
| | | exceedRate == null ? "-" : stripZeros(exceedRate)); |
| | | MesEmAlertDO alert = buildAlert(record, 0L, "", quota.getObjectName(), |
| | | MesEmAlertTypeEnum.QUOTA, actual.compareTo(alarmThreshold) > 0 |
| | | ? MesEmAlertLevelEnum.SERIOUS : MesEmAlertLevelEnum.WARN, |
| | | quota.getObjectType(), objectId, actual, quotaValue, unit, content); |
| | | upsertAlert(alert); |
| | | } |
| | | |
| | | /** |
| | | * ç¯æ¯ / 忝å¼å¸¸é¢è¦ï¼ä¸ä¸æ¥ãå»å¹´åæ¥æ¯è¾ |
| | | */ |
| | | private void checkMomentum(MesEmRecordDO record) { |
| | | List<MesEmQuotaDO> quotas = quotaMapper.selectListByObject(record.getEnergyType(), null, |
| | | record.getWorkshopId(), record.getLineId(), record.getMachineryId()); |
| | | MesEmQuotaDO quota = mostSpecificQuota(quotas); |
| | | BigDecimal momRatio = quota == null ? DEFAULT_MOM_RATIO : defaultIfNull(quota.getMomWarnRatio(), DEFAULT_MOM_RATIO); |
| | | BigDecimal yoyRatio = quota == null ? DEFAULT_YOY_RATIO : defaultIfNull(quota.getYoyWarnRatio(), DEFAULT_YOY_RATIO); |
| | | BigDecimal current = defaultIfNull(record.getUsageAmount(), BigDecimal.ZERO); |
| | | String unit = StrUtil.blankToDefault(record.getUnit(), ""); |
| | | |
| | | // ç¯æ¯ï¼æ¨æ¥ |
| | | LocalDate prevDate = record.getRecordDate().minusDays(1); |
| | | BigDecimal previous = recordMapper.sumMeterUsage(record.getMeterId(), prevDate, prevDate); |
| | | checkMomentumItem(record, current, previous, momRatio, unit, |
| | | MesEmAlertTypeEnum.MOM, "ç¯æ¯", prevDate); |
| | | |
| | | // 忝ï¼å»å¹´åæ¥ |
| | | LocalDate lastYearDate = record.getRecordDate().minusYears(1); |
| | | BigDecimal lastYear = recordMapper.sumMeterUsage(record.getMeterId(), lastYearDate, lastYearDate); |
| | | checkMomentumItem(record, current, lastYear, yoyRatio, unit, |
| | | MesEmAlertTypeEnum.YOY, "忝", lastYearDate); |
| | | } |
| | | |
| | | private void checkMomentumItem(MesEmRecordDO record, BigDecimal current, BigDecimal base, |
| | | BigDecimal thresholdRatio, String unit, MesEmAlertTypeEnum alertType, |
| | | String label, LocalDate baseDate) { |
| | | if (base == null || base.compareTo(BigDecimal.ZERO) <= 0) { |
| | | deleteIfPending(record.getMeterId(), alertType.getType(), record.getRecordDate(), 0L); |
| | | return; |
| | | } |
| | | BigDecimal changeRate = rate(current, base); |
| | | if (changeRate == null || changeRate.compareTo(thresholdRatio) <= 0) { |
| | | deleteIfPending(record.getMeterId(), alertType.getType(), record.getRecordDate(), 0L); |
| | | return; |
| | | } |
| | | MesEmAlertLevelEnum level = changeRate.compareTo(thresholdRatio.multiply(new BigDecimal("2"))) > 0 |
| | | ? MesEmAlertLevelEnum.SERIOUS : MesEmAlertLevelEnum.WARN; |
| | | String content = StrUtil.format("{} {} {} ç¨é {} {}ï¼è¾ {} ç {} {} ä¸å {}%ï¼è¶
è¿{}å¼å¸¸éå¼ {}%", |
| | | record.getMeterName(), MesEmEnergyTypeEnum.getName(record.getEnergyType()), label, |
| | | stripZeros(current), unit, baseDate, label, stripZeros(base), stripZeros(changeRate), |
| | | label, stripZeros(thresholdRatio)); |
| | | MesEmAlertDO alert = buildAlert(record, record.getMeterId(), record.getMeterCode(), record.getMeterName(), |
| | | alertType, level, resolveObjectType(record), resolveObjectId(record), |
| | | current, base, unit, content); |
| | | upsertAlert(alert); |
| | | } |
| | | |
| | | /** |
| | | * çä¼¼è·åæ»´æ¼é¢è¦ï¼å½æ¥ç¨éè¶
è¿è®¡éç¹é
ç½®çå¼å¸¸ä¸é |
| | | */ |
| | | private void checkLeak(MesEmRecordDO record, MesEmMeterDO meter) { |
| | | BigDecimal threshold = meter == null ? null : meter.getLeakThreshold(); |
| | | BigDecimal current = defaultIfNull(record.getUsageAmount(), BigDecimal.ZERO); |
| | | if (threshold == null || current.compareTo(threshold) <= 0) { |
| | | deleteIfPending(record.getMeterId(), MesEmAlertTypeEnum.LEAK.getType(), record.getRecordDate(), 0L); |
| | | return; |
| | | } |
| | | MesEmAlertLevelEnum level = current.compareTo(threshold.multiply(new BigDecimal("1.5"))) > 0 |
| | | ? MesEmAlertLevelEnum.SERIOUS : MesEmAlertLevelEnum.WARN; |
| | | String unit = StrUtil.blankToDefault(record.getUnit(), ""); |
| | | String content = StrUtil.format("{} 彿¥ç¨é {} {}ï¼è¶
è¿æ¥ç¨éå¼å¸¸ä¸é {} {}ï¼çä¼¼è·åæ»´æ¼", |
| | | record.getMeterName(), stripZeros(current), unit, stripZeros(threshold), unit); |
| | | MesEmAlertDO alert = buildAlert(record, record.getMeterId(), record.getMeterCode(), record.getMeterName(), |
| | | MesEmAlertTypeEnum.LEAK, level, resolveObjectType(record), resolveObjectId(record), |
| | | current, threshold, unit, content); |
| | | upsertAlert(alert); |
| | | } |
| | | |
| | | private MesEmAlertDO buildAlert(MesEmRecordDO record, Long meterId, String meterCode, String meterName, |
| | | MesEmAlertTypeEnum alertType, MesEmAlertLevelEnum alertLevel, |
| | | Integer objectType, Long objectId, |
| | | BigDecimal actualValue, BigDecimal thresholdValue, |
| | | String unit, String content) { |
| | | MesEmAlertDO alert = new MesEmAlertDO(); |
| | | alert.setAlertNo(buildAlertNo(record.getRecordDate(), meterId, alertType.getType(), objectId)); |
| | | alert.setMeterId(meterId); |
| | | alert.setMeterCode(meterCode); |
| | | alert.setMeterName(meterName); |
| | | alert.setEnergyType(record.getEnergyType()); |
| | | alert.setAlertType(alertType.getType()); |
| | | alert.setAlertLevel(alertLevel.getLevel()); |
| | | alert.setAlertDate(record.getRecordDate()); |
| | | alert.setObjectType(objectType); |
| | | alert.setObjectId(objectId); |
| | | alert.setObjectName(meterName); |
| | | alert.setActualValue(actualValue); |
| | | alert.setThresholdValue(thresholdValue); |
| | | alert.setUnit(unit); |
| | | alert.setContent(content); |
| | | alert.setStatus(MesEmAlertStatusEnum.PENDING.getStatus()); |
| | | return alert; |
| | | } |
| | | |
| | | private void upsertAlert(MesEmAlertDO alert) { |
| | | MesEmAlertDO existing = alertMapper.selectByUnique(alert.getMeterId(), alert.getAlertType(), |
| | | alert.getAlertDate(), alert.getObjectId()); |
| | | if (existing == null) { |
| | | alertMapper.insert(alert); |
| | | return; |
| | | } |
| | | alert.setId(existing.getId()); |
| | | alert.setAlertNo(existing.getAlertNo()); |
| | | alert.setStatus(existing.getStatus()); |
| | | alertMapper.updateById(alert); |
| | | } |
| | | |
| | | private void deleteIfPending(Long meterId, Integer alertType, LocalDate alertDate, Long objectId) { |
| | | MesEmAlertDO existing = alertMapper.selectByUnique(meterId, alertType, alertDate, objectId); |
| | | if (existing != null && MesEmAlertStatusEnum.PENDING.getStatus().equals(existing.getStatus())) { |
| | | alertMapper.deleteById(existing.getId()); |
| | | } |
| | | } |
| | | |
| | | private String buildAlertNo(LocalDate date, Long meterId, Integer alertType, Long objectId) { |
| | | return "AL" + date.format(DATE_NO_FORMATTER) + "-" + meterId + "-" + alertType + "-" + objectId; |
| | | } |
| | | |
| | | private MesEmQuotaDO mostSpecificQuota(List<MesEmQuotaDO> quotas) { |
| | | if (CollUtil.isEmpty(quotas)) { |
| | | return null; |
| | | } |
| | | return quotas.stream() |
| | | .max(Comparator.comparing(MesEmQuotaDO::getObjectType) |
| | | .thenComparing(MesEmQuotaDO::getId)) |
| | | .orElse(null); |
| | | } |
| | | |
| | | private Integer resolveObjectType(MesEmRecordDO record) { |
| | | if (record.getMachineryId() != null) { |
| | | return MesEmQuotaObjectTypeEnum.MACHINERY.getType(); |
| | | } |
| | | if (record.getLineId() != null) { |
| | | return MesEmQuotaObjectTypeEnum.LINE.getType(); |
| | | } |
| | | if (record.getWorkshopId() != null) { |
| | | return MesEmQuotaObjectTypeEnum.WORKSHOP.getType(); |
| | | } |
| | | return MesEmQuotaObjectTypeEnum.FACTORY.getType(); |
| | | } |
| | | |
| | | private Long resolveObjectId(MesEmRecordDO record) { |
| | | if (record.getMachineryId() != null) { |
| | | return record.getMachineryId(); |
| | | } |
| | | if (record.getLineId() != null) { |
| | | return record.getLineId(); |
| | | } |
| | | if (record.getWorkshopId() != null) { |
| | | return record.getWorkshopId(); |
| | | } |
| | | return 0L; |
| | | } |
| | | |
| | | private BigDecimal defaultIfNull(BigDecimal value, BigDecimal defaultValue) { |
| | | return value == null ? defaultValue : value; |
| | | } |
| | | |
| | | /** |
| | | * 计ç®ååçï¼%ï¼ï¼åºæ°ä¸º 0 æ¶è¿å null |
| | | */ |
| | | private BigDecimal rate(BigDecimal current, BigDecimal base) { |
| | | if (base == null || base.compareTo(BigDecimal.ZERO) == 0) { |
| | | return null; |
| | | } |
| | | return current.subtract(base).multiply(HUNDRED).divide(base, 2, RoundingMode.HALF_UP); |
| | | } |
| | | |
| | | private String stripZeros(BigDecimal value) { |
| | | if (value == null) { |
| | | return "0"; |
| | | } |
| | | return value.stripTrailingZeros().toPlainString(); |
| | | } |
| | | |
| | | @Override |
| | | public int checkRange(LocalDate begin, LocalDate end) { |
| | | List<MesEmRecordDO> records = recordMapper.selectListByDateRange(begin, end); |
| | | records.forEach(this::checkRecord); |
| | | return records.size(); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteMeterAlerts(Long meterId, LocalDate alertDate) { |
| | | alertMapper.deleteByMeterIdAndDate(meterId, alertDate); |
| | | } |
| | | |
| | | @Override |
| | | public MesEmAlertDO getAlert(Long id) { |
| | | return alertMapper.selectById(id); |
| | | } |
| | | |
| | | @Override |
| | | public PageResult<MesEmAlertDO> getAlertPage(MesEmAlertPageReqVO pageReqVO) { |
| | | return alertMapper.selectPage(pageReqVO); |
| | | } |
| | | |
| | | @Override |
| | | public List<MesEmAlertRespVO> getAlertRespVOList(List<MesEmAlertDO> list) { |
| | | if (CollUtil.isEmpty(list)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | return BeanUtils.toBean(list, MesEmAlertRespVO.class, vo -> { |
| | | vo.setEnergyTypeName(MesEmEnergyTypeEnum.getName(vo.getEnergyType())); |
| | | vo.setAlertTypeName(MesEmAlertTypeEnum.getName(vo.getAlertType())); |
| | | vo.setAlertLevelName(MesEmAlertLevelEnum.getName(vo.getAlertLevel())); |
| | | vo.setObjectTypeName(MesEmQuotaObjectTypeEnum.getName(vo.getObjectType())); |
| | | vo.setStatusName(MesEmAlertStatusEnum.getName(vo.getStatus())); |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void handleAlert(MesEmAlertHandleReqVO handleReqVO) { |
| | | MesEmAlertDO alert = alertMapper.selectById(handleReqVO.getId()); |
| | | if (alert == null) { |
| | | throw exception(EM_ALERT_NOT_EXISTS); |
| | | } |
| | | if (MesEmAlertStatusEnum.HANDLED.getStatus().equals(alert.getStatus())) { |
| | | throw exception(EM_ALERT_ALREADY_HANDLED); |
| | | } |
| | | alertMapper.updateById(new MesEmAlertDO().setId(alert.getId()) |
| | | .setStatus(MesEmAlertStatusEnum.HANDLED.getStatus()) |
| | | .setHandleUserId(SecurityFrameworkUtils.getLoginUserId()) |
| | | .setHandleUserName(SecurityFrameworkUtils.getLoginUserNickname()) |
| | | .setHandleTime(LocalDateTime.now()) |
| | | .setHandleRemark(handleReqVO.getHandleRemark())); |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.service.em.meter; |
| | | |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.meter.vo.MesEmMeterPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.meter.vo.MesEmMeterRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.meter.vo.MesEmMeterSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.meter.vo.MesEmOptionRespVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.em.meter.MesEmMeterDO; |
| | | |
| | | import java.util.Collection; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * MES è½è计éç¹ Service |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | public interface MesEmMeterService { |
| | | |
| | | Long createMeter(MesEmMeterSaveReqVO createReqVO); |
| | | |
| | | void updateMeter(MesEmMeterSaveReqVO updateReqVO); |
| | | |
| | | void deleteMeter(Long id); |
| | | |
| | | MesEmMeterDO getMeter(Long id); |
| | | |
| | | void validateMeterExists(Long id); |
| | | |
| | | PageResult<MesEmMeterDO> getMeterPage(MesEmMeterPageReqVO pageReqVO); |
| | | |
| | | List<MesEmMeterDO> getMeterList(); |
| | | |
| | | List<MesEmMeterDO> getMeterList(Collection<Long> ids); |
| | | |
| | | List<MesEmMeterRespVO> getMeterRespVOList(List<MesEmMeterDO> list); |
| | | |
| | | List<MesEmOptionRespVO> getMeterSimpleList(); |
| | | |
| | | List<MesEmOptionRespVO> getWorkshopOptions(); |
| | | |
| | | List<MesEmOptionRespVO> getLineOptions(); |
| | | |
| | | List<MesEmOptionRespVO> getMachineryOptions(); |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.service.em.meter; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.meter.vo.MesEmMeterPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.meter.vo.MesEmMeterRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.meter.vo.MesEmMeterSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.meter.vo.MesEmOptionRespVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.dv.machinery.MesDvMachineryDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.em.meter.MesEmMeterDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.md.workstation.MesMdWorkshopDO; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.dv.machinery.MesDvMachineryMapper; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.em.meter.MesEmMeterMapper; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.em.record.MesEmRecordMapper; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.md.workstation.MesMdWorkshopMapper; |
| | | import cn.iocoder.yudao.module.mes.enums.em.MesEmEnergyTypeEnum; |
| | | import cn.iocoder.yudao.module.mes.enums.em.MesEmMeterStatusEnum; |
| | | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| | | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; |
| | | |
| | | /** |
| | | * MES è½è计éç¹ Service å®ç°ç±» |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @Service |
| | | @Validated |
| | | public class MesEmMeterServiceImpl implements MesEmMeterService { |
| | | |
| | | @Resource |
| | | private MesEmMeterMapper meterMapper; |
| | | @Resource |
| | | private MesEmRecordMapper recordMapper; |
| | | @Resource |
| | | private MesMdWorkshopMapper workshopMapper; |
| | | @Resource |
| | | private MesDvMachineryMapper machineryMapper; |
| | | @Resource |
| | | private AdminUserApi adminUserApi; |
| | | |
| | | @Override |
| | | public Long createMeter(MesEmMeterSaveReqVO createReqVO) { |
| | | validateMeterCodeUnique(null, createReqVO.getCode()); |
| | | MesEmMeterDO meter = BeanUtils.toBean(createReqVO, MesEmMeterDO.class); |
| | | fillMeterDefaultsAndNames(meter); |
| | | meterMapper.insert(meter); |
| | | return meter.getId(); |
| | | } |
| | | |
| | | @Override |
| | | public void updateMeter(MesEmMeterSaveReqVO updateReqVO) { |
| | | validateMeterExists(updateReqVO.getId()); |
| | | validateMeterCodeUnique(updateReqVO.getId(), updateReqVO.getCode()); |
| | | MesEmMeterDO meter = BeanUtils.toBean(updateReqVO, MesEmMeterDO.class); |
| | | fillMeterDefaultsAndNames(meter); |
| | | meterMapper.updateById(meter); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteMeter(Long id) { |
| | | validateMeterExists(id); |
| | | if (recordMapper.selectCountByMeterId(id) > 0) { |
| | | throw exception(EM_METER_HAS_RECORD); |
| | | } |
| | | meterMapper.deleteById(id); |
| | | } |
| | | |
| | | @Override |
| | | public MesEmMeterDO getMeter(Long id) { |
| | | return meterMapper.selectById(id); |
| | | } |
| | | |
| | | @Override |
| | | public void validateMeterExists(Long id) { |
| | | if (meterMapper.selectById(id) == null) { |
| | | throw exception(EM_METER_NOT_EXISTS); |
| | | } |
| | | } |
| | | |
| | | private void validateMeterCodeUnique(Long id, String code) { |
| | | if (StrUtil.isBlank(code)) { |
| | | return; |
| | | } |
| | | MesEmMeterDO meter = meterMapper.selectByCode(code); |
| | | if (meter == null) { |
| | | return; |
| | | } |
| | | if (ObjUtil.notEqual(meter.getId(), id)) { |
| | | throw exception(EM_METER_CODE_DUPLICATE); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è¡¥å
¨åä½ãåçãææ ç
¤ç³»æ°ï¼å¹¶åä½è½¦é´/产线/设å¤åç§° |
| | | */ |
| | | private void fillMeterDefaultsAndNames(MesEmMeterDO meter) { |
| | | MesEmEnergyTypeEnum energyType = MesEmEnergyTypeEnum.getByType(meter.getEnergyType()); |
| | | if (StrUtil.isBlank(meter.getUnit()) && energyType != null) { |
| | | meter.setUnit(energyType.getUnit()); |
| | | } |
| | | if (meter.getRatio() == null) { |
| | | meter.setRatio(BigDecimal.ONE); |
| | | } |
| | | if (meter.getInitialReading() == null) { |
| | | meter.setInitialReading(BigDecimal.ZERO); |
| | | } |
| | | if (meter.getCoalFactor() == null && energyType != null) { |
| | | meter.setCoalFactor(energyType.getCoalFactor()); |
| | | } |
| | | if (meter.getStatus() == null) { |
| | | meter.setStatus(MesEmMeterStatusEnum.ENABLE.getStatus()); |
| | | } |
| | | // è½¦é´ |
| | | if (meter.getWorkshopId() != null) { |
| | | MesMdWorkshopDO workshop = workshopMapper.selectById(meter.getWorkshopId()); |
| | | if (workshop == null) { |
| | | throw exception(EM_METER_OBJECT_NOT_EXISTS); |
| | | } |
| | | meter.setWorkshopName(workshop.getName()); |
| | | } else { |
| | | meter.setWorkshopName(null); |
| | | } |
| | | // 产线 |
| | | if (meter.getLineId() != null) { |
| | | MesEmOptionRespVO line = meterMapper.selectLineOptionById(meter.getLineId()); |
| | | if (line == null) { |
| | | throw exception(EM_METER_OBJECT_NOT_EXISTS); |
| | | } |
| | | meter.setLineName(line.getName()); |
| | | } else { |
| | | meter.setLineName(null); |
| | | } |
| | | // 设å¤ï¼æªéæ©è½¦é´æ¶èªå¨å¸¦å
¥è®¾å¤æå±è½¦é´ |
| | | if (meter.getMachineryId() != null) { |
| | | MesDvMachineryDO machinery = machineryMapper.selectById(meter.getMachineryId()); |
| | | if (machinery == null) { |
| | | throw exception(EM_METER_OBJECT_NOT_EXISTS); |
| | | } |
| | | meter.setMachineryName(machinery.getName()); |
| | | if (meter.getWorkshopId() == null && machinery.getWorkshopId() != null) { |
| | | MesMdWorkshopDO workshop = workshopMapper.selectById(machinery.getWorkshopId()); |
| | | if (workshop != null) { |
| | | meter.setWorkshopId(workshop.getId()); |
| | | meter.setWorkshopName(workshop.getName()); |
| | | } |
| | | } |
| | | } else { |
| | | meter.setMachineryName(null); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public PageResult<MesEmMeterDO> getMeterPage(MesEmMeterPageReqVO pageReqVO) { |
| | | return meterMapper.selectPage(pageReqVO); |
| | | } |
| | | |
| | | @Override |
| | | public List<MesEmMeterDO> getMeterList() { |
| | | return meterMapper.selectList(); |
| | | } |
| | | |
| | | @Override |
| | | public List<MesEmMeterDO> getMeterList(Collection<Long> ids) { |
| | | if (CollUtil.isEmpty(ids)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | return meterMapper.selectByIds(ids); |
| | | } |
| | | |
| | | @Override |
| | | public List<MesEmMeterRespVO> getMeterRespVOList(List<MesEmMeterDO> list) { |
| | | if (CollUtil.isEmpty(list)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | Map<Long, AdminUserRespDTO> userMap = CollUtil.isNotEmpty(convertSet(list, MesEmMeterDO::getChargeUserId)) |
| | | ? adminUserApi.getUserMap(convertSet(list, MesEmMeterDO::getChargeUserId)) |
| | | : Collections.emptyMap(); |
| | | return BeanUtils.toBean(list, MesEmMeterRespVO.class, vo -> { |
| | | vo.setEnergyTypeName(MesEmEnergyTypeEnum.getName(vo.getEnergyType())); |
| | | vo.setStatusName(MesEmMeterStatusEnum.getName(vo.getStatus())); |
| | | MapUtils.findAndThen(userMap, vo.getChargeUserId(), user -> vo.setChargeUserName(user.getNickname())); |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public List<MesEmOptionRespVO> getMeterSimpleList() { |
| | | List<MesEmMeterDO> list = meterMapper.selectListByStatus(MesEmMeterStatusEnum.ENABLE.getStatus()); |
| | | return list.stream().map(meter -> { |
| | | MesEmOptionRespVO option = new MesEmOptionRespVO(); |
| | | option.setId(meter.getId()); |
| | | option.setCode(meter.getCode()); |
| | | option.setName(meter.getName()); |
| | | option.setEnergyType(meter.getEnergyType()); |
| | | option.setUnit(meter.getUnit()); |
| | | option.setWorkshopId(meter.getWorkshopId()); |
| | | option.setWorkshopName(meter.getWorkshopName()); |
| | | option.setLineId(meter.getLineId()); |
| | | option.setLineName(meter.getLineName()); |
| | | return option; |
| | | }).collect(Collectors.toList()); |
| | | } |
| | | |
| | | @Override |
| | | public List<MesEmOptionRespVO> getWorkshopOptions() { |
| | | return meterMapper.selectWorkshopOptions(); |
| | | } |
| | | |
| | | @Override |
| | | public List<MesEmOptionRespVO> getLineOptions() { |
| | | return meterMapper.selectLineOptions(); |
| | | } |
| | | |
| | | @Override |
| | | public List<MesEmOptionRespVO> getMachineryOptions() { |
| | | List<MesEmOptionRespVO> options = meterMapper.selectMachineryOptions(); |
| | | if (CollUtil.isEmpty(options)) { |
| | | return options; |
| | | } |
| | | Map<Long, MesMdWorkshopDO> workshopMap = workshopMapper.selectList().stream() |
| | | .collect(Collectors.toMap(MesMdWorkshopDO::getId, Function.identity(), (a, b) -> a)); |
| | | options.forEach(option -> { |
| | | MesMdWorkshopDO workshop = workshopMap.get(option.getWorkshopId()); |
| | | if (workshop != null) { |
| | | option.setWorkshopName(workshop.getName()); |
| | | } |
| | | }); |
| | | return options; |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.service.em.quota; |
| | | |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.quota.vo.MesEmQuotaPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.quota.vo.MesEmQuotaRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.quota.vo.MesEmQuotaSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.em.quota.MesEmQuotaDO; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * MES è½èèæ ¸ææ Service |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | public interface MesEmQuotaService { |
| | | |
| | | Long createQuota(MesEmQuotaSaveReqVO createReqVO); |
| | | |
| | | void updateQuota(MesEmQuotaSaveReqVO updateReqVO); |
| | | |
| | | void deleteQuota(Long id); |
| | | |
| | | MesEmQuotaDO getQuota(Long id); |
| | | |
| | | void validateQuotaExists(Long id); |
| | | |
| | | PageResult<MesEmQuotaDO> getQuotaPage(MesEmQuotaPageReqVO pageReqVO); |
| | | |
| | | List<MesEmQuotaRespVO> getQuotaRespVOList(List<MesEmQuotaDO> list); |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.service.em.quota; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.meter.vo.MesEmOptionRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.quota.vo.MesEmQuotaPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.quota.vo.MesEmQuotaRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.quota.vo.MesEmQuotaSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.dv.machinery.MesDvMachineryDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.em.quota.MesEmQuotaDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.md.workstation.MesMdWorkshopDO; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.dv.machinery.MesDvMachineryMapper; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.em.meter.MesEmMeterMapper; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.em.quota.MesEmQuotaMapper; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.md.workstation.MesMdWorkshopMapper; |
| | | import cn.iocoder.yudao.module.mes.enums.em.MesEmEnergyTypeEnum; |
| | | import cn.iocoder.yudao.module.mes.enums.em.MesEmMeterStatusEnum; |
| | | import cn.iocoder.yudao.module.mes.enums.em.MesEmQuotaObjectTypeEnum; |
| | | import cn.iocoder.yudao.module.mes.enums.em.MesEmQuotaPeriodEnum; |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.EM_QUOTA_NOT_EXISTS; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.EM_QUOTA_OBJECT_NOT_EXISTS; |
| | | |
| | | /** |
| | | * MES è½èèæ ¸ææ Service å®ç°ç±» |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @Service |
| | | @Validated |
| | | public class MesEmQuotaServiceImpl implements MesEmQuotaService { |
| | | |
| | | @Resource |
| | | private MesEmQuotaMapper quotaMapper; |
| | | @Resource |
| | | private MesEmMeterMapper meterMapper; |
| | | @Resource |
| | | private MesMdWorkshopMapper workshopMapper; |
| | | @Resource |
| | | private MesDvMachineryMapper machineryMapper; |
| | | |
| | | @Override |
| | | public Long createQuota(MesEmQuotaSaveReqVO createReqVO) { |
| | | MesEmQuotaDO quota = BeanUtils.toBean(createReqVO, MesEmQuotaDO.class); |
| | | fillQuotaDefaultsAndObjectName(quota); |
| | | quotaMapper.insert(quota); |
| | | return quota.getId(); |
| | | } |
| | | |
| | | @Override |
| | | public void updateQuota(MesEmQuotaSaveReqVO updateReqVO) { |
| | | validateQuotaExists(updateReqVO.getId()); |
| | | MesEmQuotaDO quota = BeanUtils.toBean(updateReqVO, MesEmQuotaDO.class); |
| | | fillQuotaDefaultsAndObjectName(quota); |
| | | quotaMapper.updateById(quota); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteQuota(Long id) { |
| | | validateQuotaExists(id); |
| | | quotaMapper.deleteById(id); |
| | | } |
| | | |
| | | @Override |
| | | public MesEmQuotaDO getQuota(Long id) { |
| | | return quotaMapper.selectById(id); |
| | | } |
| | | |
| | | @Override |
| | | public void validateQuotaExists(Long id) { |
| | | if (quotaMapper.selectById(id) == null) { |
| | | throw exception(EM_QUOTA_NOT_EXISTS); |
| | | } |
| | | } |
| | | |
| | | private void fillQuotaDefaultsAndObjectName(MesEmQuotaDO quota) { |
| | | MesEmEnergyTypeEnum energyType = MesEmEnergyTypeEnum.getByType(quota.getEnergyType()); |
| | | if (StrUtil.isBlank(quota.getUnit()) && energyType != null) { |
| | | quota.setUnit(energyType.getUnit()); |
| | | } |
| | | if (quota.getWarnRatio() == null) { |
| | | quota.setWarnRatio(new BigDecimal("10")); |
| | | } |
| | | if (quota.getAlarmRatio() == null) { |
| | | quota.setAlarmRatio(new BigDecimal("20")); |
| | | } |
| | | if (quota.getMomWarnRatio() == null) { |
| | | quota.setMomWarnRatio(new BigDecimal("30")); |
| | | } |
| | | if (quota.getYoyWarnRatio() == null) { |
| | | quota.setYoyWarnRatio(new BigDecimal("30")); |
| | | } |
| | | if (quota.getStatus() == null) { |
| | | quota.setStatus(MesEmMeterStatusEnum.ENABLE.getStatus()); |
| | | } |
| | | // èæ ¸å¯¹è±¡åç§° |
| | | Integer objectType = quota.getObjectType(); |
| | | if (MesEmQuotaObjectTypeEnum.FACTORY.getType().equals(objectType)) { |
| | | quota.setObjectId(0L); |
| | | quota.setObjectName("å
¨å"); |
| | | return; |
| | | } |
| | | if (quota.getObjectId() == null) { |
| | | throw exception(EM_QUOTA_OBJECT_NOT_EXISTS); |
| | | } |
| | | if (MesEmQuotaObjectTypeEnum.WORKSHOP.getType().equals(objectType)) { |
| | | MesMdWorkshopDO workshop = workshopMapper.selectById(quota.getObjectId()); |
| | | if (workshop == null) { |
| | | throw exception(EM_QUOTA_OBJECT_NOT_EXISTS); |
| | | } |
| | | quota.setObjectName(workshop.getName()); |
| | | } else if (MesEmQuotaObjectTypeEnum.LINE.getType().equals(objectType)) { |
| | | MesEmOptionRespVO line = meterMapper.selectLineOptionById(quota.getObjectId()); |
| | | if (line == null) { |
| | | throw exception(EM_QUOTA_OBJECT_NOT_EXISTS); |
| | | } |
| | | quota.setObjectName(line.getName()); |
| | | } else if (MesEmQuotaObjectTypeEnum.MACHINERY.getType().equals(objectType)) { |
| | | MesDvMachineryDO machinery = machineryMapper.selectById(quota.getObjectId()); |
| | | if (machinery == null) { |
| | | throw exception(EM_QUOTA_OBJECT_NOT_EXISTS); |
| | | } |
| | | quota.setObjectName(machinery.getName()); |
| | | } else { |
| | | throw exception(EM_QUOTA_OBJECT_NOT_EXISTS); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public PageResult<MesEmQuotaDO> getQuotaPage(MesEmQuotaPageReqVO pageReqVO) { |
| | | return quotaMapper.selectPage(pageReqVO); |
| | | } |
| | | |
| | | @Override |
| | | public List<MesEmQuotaRespVO> getQuotaRespVOList(List<MesEmQuotaDO> list) { |
| | | if (CollUtil.isEmpty(list)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | return BeanUtils.toBean(list, MesEmQuotaRespVO.class, vo -> { |
| | | vo.setEnergyTypeName(MesEmEnergyTypeEnum.getName(vo.getEnergyType())); |
| | | vo.setObjectTypeName(MesEmQuotaObjectTypeEnum.getName(vo.getObjectType())); |
| | | vo.setPeriodTypeName(MesEmQuotaPeriodEnum.getName(vo.getPeriodType())); |
| | | vo.setStatusName(MesEmMeterStatusEnum.getName(vo.getStatus())); |
| | | }); |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.service.em.record; |
| | | |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.record.vo.MesEmLastReadingRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.record.vo.MesEmRecordPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.record.vo.MesEmRecordRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.record.vo.MesEmRecordSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.em.record.MesEmRecordDO; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * MES è½èæè¡¨è®°å½ Service |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | public interface MesEmRecordService { |
| | | |
| | | Long createRecord(MesEmRecordSaveReqVO createReqVO); |
| | | |
| | | void updateRecord(MesEmRecordSaveReqVO updateReqVO); |
| | | |
| | | void deleteRecord(Long id); |
| | | |
| | | MesEmRecordDO getRecord(Long id); |
| | | |
| | | PageResult<MesEmRecordDO> getRecordPage(MesEmRecordPageReqVO pageReqVO); |
| | | |
| | | List<MesEmRecordRespVO> getRecordRespVOList(List<MesEmRecordDO> list); |
| | | |
| | | MesEmLastReadingRespVO getLastReading(Long meterId, LocalDate recordDate, Long excludeId); |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.service.em.record; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjUtil; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.record.vo.MesEmLastReadingRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.record.vo.MesEmRecordPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.record.vo.MesEmRecordRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.record.vo.MesEmRecordSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.em.meter.MesEmMeterDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.em.record.MesEmRecordDO; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.em.record.MesEmRecordMapper; |
| | | import cn.iocoder.yudao.module.mes.enums.em.MesEmEnergyTypeEnum; |
| | | import cn.iocoder.yudao.module.mes.enums.em.MesEmRecordSourceEnum; |
| | | import cn.iocoder.yudao.module.mes.service.em.alert.MesEmAlertService; |
| | | import cn.iocoder.yudao.module.mes.service.em.meter.MesEmMeterService; |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.LocalDate; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; |
| | | |
| | | /** |
| | | * MES è½èæè¡¨è®°å½ Service å®ç°ç±» |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @Service |
| | | @Validated |
| | | public class MesEmRecordServiceImpl implements MesEmRecordService { |
| | | |
| | | @Resource |
| | | private MesEmRecordMapper recordMapper; |
| | | @Resource |
| | | private MesEmMeterService meterService; |
| | | @Resource |
| | | private MesEmAlertService alertService; |
| | | |
| | | @Override |
| | | public Long createRecord(MesEmRecordSaveReqVO createReqVO) { |
| | | MesEmMeterDO meter = meterService.getMeter(createReqVO.getMeterId()); |
| | | if (meter == null) { |
| | | throw exception(EM_METER_NOT_EXISTS); |
| | | } |
| | | validateRecordDateUnique(null, createReqVO.getMeterId(), createReqVO.getRecordDate()); |
| | | |
| | | MesEmRecordDO record = buildRecord(createReqVO, meter, null); |
| | | recordMapper.insert(record); |
| | | // åå
¥åæå®é¢ãç¯æ¯ã忝ãè·åæ»´æ¼è§åæ£æµé¢è¦ |
| | | alertService.checkRecord(record); |
| | | return record.getId(); |
| | | } |
| | | |
| | | @Override |
| | | public void updateRecord(MesEmRecordSaveReqVO updateReqVO) { |
| | | validateRecordExists(updateReqVO.getId()); |
| | | MesEmMeterDO meter = meterService.getMeter(updateReqVO.getMeterId()); |
| | | if (meter == null) { |
| | | throw exception(EM_METER_NOT_EXISTS); |
| | | } |
| | | validateRecordDateUnique(updateReqVO.getId(), updateReqVO.getMeterId(), updateReqVO.getRecordDate()); |
| | | |
| | | MesEmRecordDO record = buildRecord(updateReqVO, meter, updateReqVO.getId()); |
| | | recordMapper.updateById(record); |
| | | alertService.checkRecord(record); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteRecord(Long id) { |
| | | MesEmRecordDO record = validateRecordExists(id); |
| | | recordMapper.deleteById(id); |
| | | // 忥æ¸
ç该记å½äº§ççç¯æ¯/忝/è·åæ»´æ¼é¢è¦ |
| | | alertService.deleteMeterAlerts(record.getMeterId(), record.getRecordDate()); |
| | | } |
| | | |
| | | @Override |
| | | public MesEmRecordDO getRecord(Long id) { |
| | | return recordMapper.selectById(id); |
| | | } |
| | | |
| | | private MesEmRecordDO validateRecordExists(Long id) { |
| | | MesEmRecordDO record = recordMapper.selectById(id); |
| | | if (record == null) { |
| | | throw exception(EM_RECORD_NOT_EXISTS); |
| | | } |
| | | return record; |
| | | } |
| | | |
| | | private void validateRecordDateUnique(Long id, Long meterId, LocalDate recordDate) { |
| | | MesEmRecordDO record = recordMapper.selectByMeterIdAndDate(meterId, recordDate); |
| | | if (record != null && ObjUtil.notEqual(record.getId(), id)) { |
| | | throw exception(EM_RECORD_DATE_DUPLICATE); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æå»ºæè¡¨è®°å½ï¼èªå¨è®¡ç®ç¨éä¸è´¹ç¨ï¼å¹¶åä½è®¡éç¹/车é´/产线/设å¤å¿«ç
§ |
| | | */ |
| | | private MesEmRecordDO buildRecord(MesEmRecordSaveReqVO reqVO, MesEmMeterDO meter, Long id) { |
| | | // æå读æ°ï¼æªå¡«åæ¶åä¸ä¸æ¡è®°å½è¯»æ°ï¼æ²¡æåå²è®°å½åå计éç¹åå§è¯»æ° |
| | | BigDecimal prevReading = reqVO.getPrevReading(); |
| | | if (prevReading == null) { |
| | | MesEmRecordDO lastRecord = recordMapper.selectLastByMeterId( |
| | | reqVO.getMeterId(), reqVO.getRecordDate(), id); |
| | | prevReading = lastRecord != null ? lastRecord.getReading() : meter.getInitialReading(); |
| | | } |
| | | if (prevReading == null) { |
| | | prevReading = BigDecimal.ZERO; |
| | | } |
| | | if (reqVO.getReading().compareTo(prevReading) < 0) { |
| | | throw exception(EM_RECORD_READING_INVALID); |
| | | } |
| | | BigDecimal ratio = meter.getRatio() == null ? BigDecimal.ONE : meter.getRatio(); |
| | | BigDecimal usage = reqVO.getReading().subtract(prevReading).multiply(ratio); |
| | | BigDecimal price = reqVO.getPrice() == null ? BigDecimal.ZERO : reqVO.getPrice(); |
| | | BigDecimal cost = usage.multiply(price).setScale(2, RoundingMode.HALF_UP); |
| | | |
| | | MesEmRecordDO record = BeanUtils.toBean(reqVO, MesEmRecordDO.class); |
| | | record.setId(id); |
| | | record.setMeterCode(meter.getCode()); |
| | | record.setMeterName(meter.getName()); |
| | | record.setEnergyType(meter.getEnergyType()); |
| | | record.setUnit(meter.getUnit()); |
| | | record.setRatio(ratio); |
| | | record.setCoalFactor(meter.getCoalFactor()); |
| | | record.setWorkshopId(meter.getWorkshopId()); |
| | | record.setWorkshopName(meter.getWorkshopName()); |
| | | record.setLineId(meter.getLineId()); |
| | | record.setLineName(meter.getLineName()); |
| | | record.setMachineryId(meter.getMachineryId()); |
| | | record.setMachineryName(meter.getMachineryName()); |
| | | record.setPrevReading(prevReading); |
| | | record.setUsageAmount(usage); |
| | | record.setPrice(price); |
| | | record.setCost(cost); |
| | | record.setSource(reqVO.getSource() == null ? MesEmRecordSourceEnum.MANUAL.getSource() : reqVO.getSource()); |
| | | return record; |
| | | } |
| | | |
| | | @Override |
| | | public PageResult<MesEmRecordDO> getRecordPage(MesEmRecordPageReqVO pageReqVO) { |
| | | return recordMapper.selectPage(pageReqVO); |
| | | } |
| | | |
| | | @Override |
| | | public List<MesEmRecordRespVO> getRecordRespVOList(List<MesEmRecordDO> list) { |
| | | if (CollUtil.isEmpty(list)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | return BeanUtils.toBean(list, MesEmRecordRespVO.class, vo -> { |
| | | vo.setEnergyTypeName(MesEmEnergyTypeEnum.getName(vo.getEnergyType())); |
| | | vo.setSourceName(MesEmRecordSourceEnum.getName(vo.getSource())); |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public MesEmLastReadingRespVO getLastReading(Long meterId, LocalDate recordDate, Long excludeId) { |
| | | MesEmRecordDO lastRecord = recordMapper.selectLastByMeterId(meterId, recordDate, excludeId); |
| | | if (lastRecord != null) { |
| | | return new MesEmLastReadingRespVO(lastRecord.getReading(), lastRecord.getRecordDate()); |
| | | } |
| | | MesEmMeterDO meter = meterService.getMeter(meterId); |
| | | if (meter == null) { |
| | | throw exception(EM_METER_NOT_EXISTS); |
| | | } |
| | | return new MesEmLastReadingRespVO( |
| | | meter.getInitialReading() == null ? BigDecimal.ZERO : meter.getInitialReading(), null); |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.service.em.statistics; |
| | | |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.statistics.vo.MesEmOverviewRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.statistics.vo.MesEmReportRespVO; |
| | | |
| | | import java.time.LocalDate; |
| | | |
| | | /** |
| | | * MES è½èç»è®¡ Service |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | public interface MesEmStatisticsService { |
| | | |
| | | MesEmOverviewRespVO getOverview(LocalDate beginDate, LocalDate endDate); |
| | | |
| | | MesEmReportRespVO getReport(String period); |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.service.em.statistics; |
| | | |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.statistics.vo.MesEmOverviewRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.em.statistics.vo.MesEmReportRespVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.em.alert.MesEmAlertDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.em.meter.MesEmMeterDO; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.em.alert.MesEmAlertMapper; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.em.meter.MesEmMeterMapper; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.em.record.MesEmRecordMapper; |
| | | import cn.iocoder.yudao.module.mes.enums.em.*; |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.LocalDate; |
| | | import java.time.YearMonth; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * MES è½èç»è®¡ Service å®ç°ç±» |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @Service |
| | | @Validated |
| | | public class MesEmStatisticsServiceImpl implements MesEmStatisticsService { |
| | | |
| | | private static final BigDecimal ZERO = BigDecimal.ZERO; |
| | | private static final BigDecimal HUNDRED = new BigDecimal("100"); |
| | | |
| | | @Resource |
| | | private MesEmRecordMapper recordMapper; |
| | | @Resource |
| | | private MesEmMeterMapper meterMapper; |
| | | @Resource |
| | | private MesEmAlertMapper alertMapper; |
| | | |
| | | @Override |
| | | public MesEmOverviewRespVO getOverview(LocalDate beginDate, LocalDate endDate) { |
| | | LocalDate begin = beginDate == null ? LocalDate.now().withDayOfMonth(1) : beginDate; |
| | | LocalDate end = endDate == null ? LocalDate.now() : endDate; |
| | | if (begin.isAfter(end)) { |
| | | LocalDate temp = begin; |
| | | begin = end; |
| | | end = temp; |
| | | } |
| | | |
| | | MesEmOverviewRespVO respVO = new MesEmOverviewRespVO(); |
| | | // 1. è½æºç±»åç»è®¡ |
| | | Map<Integer, Map<String, Object>> typeMap = toMapBy(recordMapper.selectTypeStats(begin, end), "energyType"); |
| | | List<MesEmOverviewRespVO.TypeStat> typeStats = new ArrayList<>(); |
| | | BigDecimal totalTce = ZERO; |
| | | BigDecimal totalCost = ZERO; |
| | | for (MesEmEnergyTypeEnum energyType : MesEmEnergyTypeEnum.values()) { |
| | | Map<String, Object> row = typeMap.getOrDefault(energyType.getType(), Collections.emptyMap()); |
| | | MesEmOverviewRespVO.TypeStat stat = new MesEmOverviewRespVO.TypeStat(); |
| | | stat.setEnergyType(energyType.getType()); |
| | | stat.setEnergyTypeName(energyType.getName()); |
| | | stat.setUnit(energyType.getUnit()); |
| | | stat.setUsage(toDecimal(row, "usageAmount")); |
| | | stat.setCost(toDecimal(row, "costAmount")); |
| | | stat.setTce(toDecimal(row, "tce")); |
| | | typeStats.add(stat); |
| | | totalTce = totalTce.add(stat.getTce()); |
| | | totalCost = totalCost.add(stat.getCost()); |
| | | } |
| | | respVO.setTypeStats(typeStats); |
| | | respVO.setTotalTce(scale(totalTce)); |
| | | respVO.setTotalCost(scale(totalCost)); |
| | | |
| | | // 2. 车é´ç»è®¡ |
| | | respVO.setWorkshopStats(parseWorkshopStats(recordMapper.selectWorkshopStats(begin, end))); |
| | | |
| | | // 3. è½èè¶å¿ |
| | | respVO.setTrend(parseTrend(recordMapper.selectTrendRows(begin, end))); |
| | | |
| | | // 4. éç¹ç¨è½è®¾å¤æè¡ |
| | | respVO.setTopMeters(parseTopMeters(recordMapper.selectTopMeterStats(begin, end, 10))); |
| | | |
| | | // 5. é¢è¦æ¦è§ |
| | | respVO.setMeterCount(Math.toIntExact(meterMapper.selectCount( |
| | | new LambdaQueryWrapperX<MesEmMeterDO>() |
| | | .eq(MesEmMeterDO::getStatus, MesEmMeterStatusEnum.ENABLE.getStatus())))); |
| | | respVO.setPendingAlertCount(Math.toIntExact(alertMapper.selectPendingCount())); |
| | | respVO.setRecentAlerts(parseRecentAlerts(alertMapper.selectRecent(begin, end, 5))); |
| | | return respVO; |
| | | } |
| | | |
| | | @Override |
| | | public MesEmReportRespVO getReport(String period) { |
| | | YearMonth yearMonth = StrUtil.isBlank(period) ? YearMonth.now() : YearMonth.parse(period); |
| | | LocalDate begin = yearMonth.atDay(1); |
| | | LocalDate end = yearMonth.atEndOfMonth(); |
| | | YearMonth lastMonth = yearMonth.minusMonths(1); |
| | | YearMonth lastYear = yearMonth.minusYears(1); |
| | | |
| | | Map<Integer, Map<String, Object>> currentTypeMap = toMapBy(recordMapper.selectTypeStats(begin, end), "energyType"); |
| | | Map<Integer, Map<String, Object>> lastMonthTypeMap = toMapBy( |
| | | recordMapper.selectTypeStats(lastMonth.atDay(1), lastMonth.atEndOfMonth()), "energyType"); |
| | | Map<Integer, Map<String, Object>> lastYearTypeMap = toMapBy( |
| | | recordMapper.selectTypeStats(lastYear.atDay(1), lastYear.atEndOfMonth()), "energyType"); |
| | | |
| | | MesEmReportRespVO respVO = new MesEmReportRespVO(); |
| | | respVO.setPeriod(yearMonth.toString()); |
| | | respVO.setBeginDate(begin); |
| | | respVO.setEndDate(end); |
| | | |
| | | // 1. æè½æºç±»å |
| | | List<MesEmReportRespVO.TypeRow> typeRows = new ArrayList<>(); |
| | | BigDecimal totalTce = ZERO; |
| | | BigDecimal totalCost = ZERO; |
| | | BigDecimal lastMonthTce = ZERO; |
| | | BigDecimal lastYearTce = ZERO; |
| | | for (MesEmEnergyTypeEnum energyType : MesEmEnergyTypeEnum.values()) { |
| | | Map<String, Object> current = currentTypeMap.getOrDefault(energyType.getType(), Collections.emptyMap()); |
| | | Map<String, Object> lastMonthRow = lastMonthTypeMap.getOrDefault(energyType.getType(), Collections.emptyMap()); |
| | | Map<String, Object> lastYearRow = lastYearTypeMap.getOrDefault(energyType.getType(), Collections.emptyMap()); |
| | | |
| | | MesEmReportRespVO.TypeRow row = new MesEmReportRespVO.TypeRow(); |
| | | row.setEnergyType(energyType.getType()); |
| | | row.setEnergyTypeName(energyType.getName()); |
| | | row.setUnit(energyType.getUnit()); |
| | | row.setUsage(toDecimal(current, "usageAmount")); |
| | | row.setCost(toDecimal(current, "costAmount")); |
| | | row.setTce(toDecimal(current, "tce")); |
| | | row.setLastMonthUsage(toDecimal(lastMonthRow, "usageAmount")); |
| | | row.setMomRate(rate(row.getUsage(), row.getLastMonthUsage())); |
| | | row.setLastYearUsage(toDecimal(lastYearRow, "usageAmount")); |
| | | row.setYoyRate(rate(row.getUsage(), row.getLastYearUsage())); |
| | | typeRows.add(row); |
| | | |
| | | totalTce = totalTce.add(row.getTce()); |
| | | totalCost = totalCost.add(row.getCost()); |
| | | lastMonthTce = lastMonthTce.add(toDecimal(lastMonthRow, "tce")); |
| | | lastYearTce = lastYearTce.add(toDecimal(lastYearRow, "tce")); |
| | | } |
| | | respVO.setTypeRows(typeRows); |
| | | |
| | | // 2. æè½¦é´ |
| | | respVO.setWorkshopRows(parseReportWorkshopRows( |
| | | recordMapper.selectWorkshopStats(begin, end), |
| | | recordMapper.selectWorkshopStats(lastMonth.atDay(1), lastMonth.atEndOfMonth()), |
| | | recordMapper.selectWorkshopStats(lastYear.atDay(1), lastYear.atEndOfMonth()))); |
| | | |
| | | // 3. å计 |
| | | respVO.setTotalTce(scale(totalTce)); |
| | | respVO.setTotalCost(scale(totalCost)); |
| | | respVO.setLastMonthTce(scale(lastMonthTce)); |
| | | respVO.setMomRate(rate(totalTce, lastMonthTce)); |
| | | respVO.setLastYearTce(scale(lastYearTce)); |
| | | respVO.setYoyRate(rate(totalTce, lastYearTce)); |
| | | return respVO; |
| | | } |
| | | |
| | | // ==================== æ°æ®è½¬æ¢ ==================== |
| | | |
| | | private Map<Integer, Map<String, Object>> toMapBy(List<Map<String, Object>> rows, String key) { |
| | | Map<Integer, Map<String, Object>> result = new HashMap<>(); |
| | | for (Map<String, Object> row : rows) { |
| | | Integer type = Convert.toInt(row.get(key)); |
| | | if (type != null) { |
| | | result.put(type, row); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private List<MesEmOverviewRespVO.WorkshopStat> parseWorkshopStats(List<Map<String, Object>> rows) { |
| | | List<MesEmOverviewRespVO.WorkshopStat> result = new ArrayList<>(); |
| | | for (Map<String, Object> row : rows) { |
| | | MesEmOverviewRespVO.WorkshopStat stat = new MesEmOverviewRespVO.WorkshopStat(); |
| | | stat.setWorkshopId(Convert.toLong(row.get("workshopId"))); |
| | | stat.setWorkshopName(Convert.toStr(row.get("workshopName"))); |
| | | stat.setTce(scale(Convert.toBigDecimal(row.get("tce"), ZERO))); |
| | | stat.setCost(scale(Convert.toBigDecimal(row.get("costAmount"), ZERO))); |
| | | result.add(stat); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private List<MesEmOverviewRespVO.TrendPoint> parseTrend(List<Map<String, Object>> rows) { |
| | | Map<String, MesEmOverviewRespVO.TrendPoint> pointMap = new TreeMap<>(); |
| | | for (Map<String, Object> row : rows) { |
| | | String date = toDateStr(row.get("recordDate")); |
| | | if (StrUtil.isBlank(date)) { |
| | | continue; |
| | | } |
| | | MesEmOverviewRespVO.TrendPoint point = pointMap.computeIfAbsent(date, key -> { |
| | | MesEmOverviewRespVO.TrendPoint item = new MesEmOverviewRespVO.TrendPoint(); |
| | | item.setDate(key); |
| | | item.setTce(ZERO); |
| | | item.setCost(ZERO); |
| | | item.setElectricity(ZERO); |
| | | item.setWater(ZERO); |
| | | item.setFuel(ZERO); |
| | | item.setGas(ZERO); |
| | | return item; |
| | | }); |
| | | Integer energyType = Convert.toInt(row.get("energyType")); |
| | | BigDecimal usage = Convert.toBigDecimal(row.get("usageAmount"), ZERO); |
| | | point.setTce(point.getTce().add(Convert.toBigDecimal(row.get("tce"), ZERO))); |
| | | point.setCost(point.getCost().add(Convert.toBigDecimal(row.get("costAmount"), ZERO))); |
| | | if (MesEmEnergyTypeEnum.ELECTRICITY.getType().equals(energyType)) { |
| | | point.setElectricity(usage); |
| | | } else if (MesEmEnergyTypeEnum.WATER.getType().equals(energyType)) { |
| | | point.setWater(usage); |
| | | } else if (MesEmEnergyTypeEnum.FUEL.getType().equals(energyType)) { |
| | | point.setFuel(usage); |
| | | } else if (MesEmEnergyTypeEnum.GAS.getType().equals(energyType)) { |
| | | point.setGas(usage); |
| | | } |
| | | } |
| | | pointMap.values().forEach(point -> { |
| | | point.setTce(scale(point.getTce())); |
| | | point.setCost(scale(point.getCost())); |
| | | }); |
| | | return new ArrayList<>(pointMap.values()); |
| | | } |
| | | |
| | | private List<MesEmOverviewRespVO.MeterStat> parseTopMeters(List<Map<String, Object>> rows) { |
| | | List<MesEmOverviewRespVO.MeterStat> result = new ArrayList<>(); |
| | | for (Map<String, Object> row : rows) { |
| | | MesEmOverviewRespVO.MeterStat stat = new MesEmOverviewRespVO.MeterStat(); |
| | | stat.setMeterId(Convert.toLong(row.get("meterId"))); |
| | | stat.setMeterName(Convert.toStr(row.get("meterName"))); |
| | | stat.setEnergyType(Convert.toInt(row.get("energyType"))); |
| | | stat.setEnergyTypeName(MesEmEnergyTypeEnum.getName(stat.getEnergyType())); |
| | | stat.setUnit(Convert.toStr(row.get("unit"))); |
| | | stat.setUsage(Convert.toBigDecimal(row.get("usageAmount"), ZERO)); |
| | | stat.setCost(scale(Convert.toBigDecimal(row.get("costAmount"), ZERO))); |
| | | stat.setTce(scale(Convert.toBigDecimal(row.get("tce"), ZERO))); |
| | | result.add(stat); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private List<MesEmOverviewRespVO.RecentAlert> parseRecentAlerts(List<MesEmAlertDO> alerts) { |
| | | List<MesEmOverviewRespVO.RecentAlert> result = new ArrayList<>(); |
| | | for (MesEmAlertDO alert : alerts) { |
| | | MesEmOverviewRespVO.RecentAlert item = new MesEmOverviewRespVO.RecentAlert(); |
| | | item.setId(alert.getId()); |
| | | item.setContent(alert.getContent()); |
| | | item.setAlertLevel(alert.getAlertLevel()); |
| | | item.setAlertLevelName(MesEmAlertLevelEnum.getName(alert.getAlertLevel())); |
| | | item.setAlertDate(alert.getAlertDate() == null ? null : alert.getAlertDate().toString()); |
| | | item.setStatus(alert.getStatus()); |
| | | item.setStatusName(MesEmAlertStatusEnum.getName(alert.getStatus())); |
| | | result.add(item); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private List<MesEmReportRespVO.WorkshopRow> parseReportWorkshopRows( |
| | | List<Map<String, Object>> currentRows, List<Map<String, Object>> lastMonthRows, |
| | | List<Map<String, Object>> lastYearRows) { |
| | | Map<Long, Map<String, Object>> currentMap = toMapByWorkshop(currentRows); |
| | | Map<Long, Map<String, Object>> lastMonthMap = toMapByWorkshop(lastMonthRows); |
| | | Map<Long, Map<String, Object>> lastYearMap = toMapByWorkshop(lastYearRows); |
| | | Set<Long> workshopIds = new LinkedHashSet<>(currentMap.keySet()); |
| | | workshopIds.addAll(lastMonthMap.keySet()); |
| | | workshopIds.addAll(lastYearMap.keySet()); |
| | | |
| | | List<MesEmReportRespVO.WorkshopRow> result = new ArrayList<>(); |
| | | for (Long workshopId : workshopIds) { |
| | | Map<String, Object> current = currentMap.getOrDefault(workshopId, Collections.emptyMap()); |
| | | Map<String, Object> lastMonth = lastMonthMap.getOrDefault(workshopId, Collections.emptyMap()); |
| | | Map<String, Object> lastYear = lastYearMap.getOrDefault(workshopId, Collections.emptyMap()); |
| | | MesEmReportRespVO.WorkshopRow row = new MesEmReportRespVO.WorkshopRow(); |
| | | row.setWorkshopId(workshopId); |
| | | row.setWorkshopName(Convert.toStr(current.getOrDefault("workshopName", |
| | | lastMonth.getOrDefault("workshopName", lastYear.get("workshopName"))))); |
| | | row.setCost(scale(Convert.toBigDecimal(current.get("costAmount"), ZERO))); |
| | | row.setTce(scale(Convert.toBigDecimal(current.get("tce"), ZERO))); |
| | | row.setLastMonthTce(scale(Convert.toBigDecimal(lastMonth.get("tce"), ZERO))); |
| | | row.setMomRate(rate(row.getTce(), row.getLastMonthTce())); |
| | | row.setLastYearTce(scale(Convert.toBigDecimal(lastYear.get("tce"), ZERO))); |
| | | row.setYoyRate(rate(row.getTce(), row.getLastYearTce())); |
| | | result.add(row); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private Map<Long, Map<String, Object>> toMapByWorkshop(List<Map<String, Object>> rows) { |
| | | Map<Long, Map<String, Object>> result = new HashMap<>(); |
| | | for (Map<String, Object> row : rows) { |
| | | Long workshopId = Convert.toLong(row.get("workshopId")); |
| | | if (workshopId != null) { |
| | | result.put(workshopId, row); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private BigDecimal toDecimal(Map<String, Object> row, String key) { |
| | | return scale(Convert.toBigDecimal(row.get(key), ZERO)); |
| | | } |
| | | |
| | | private String toDateStr(Object value) { |
| | | if (value == null) { |
| | | return null; |
| | | } |
| | | if (value instanceof LocalDate localDate) { |
| | | return localDate.toString(); |
| | | } |
| | | if (value instanceof java.sql.Date sqlDate) { |
| | | return sqlDate.toLocalDate().toString(); |
| | | } |
| | | String text = Convert.toStr(value); |
| | | return text != null && text.length() > 10 ? text.substring(0, 10) : text; |
| | | } |
| | | |
| | | /** |
| | | * 计ç®ç¯æ¯/忝ï¼%ï¼ï¼åºæ°ä¸º 0 æ¶è¿å nullï¼å端æ¾ç¤ºä¸º - |
| | | */ |
| | | private BigDecimal rate(BigDecimal current, BigDecimal base) { |
| | | if (base == null || base.compareTo(ZERO) == 0) { |
| | | return null; |
| | | } |
| | | return current.subtract(base).multiply(HUNDRED).divide(base, 2, RoundingMode.HALF_UP); |
| | | } |
| | | |
| | | private BigDecimal scale(BigDecimal value) { |
| | | return value == null ? ZERO : value.setScale(2, RoundingMode.HALF_UP); |
| | | } |
| | | |
| | | } |