feat(mes): 新增计量器具与计量检测记录功能
- 添加计量器具类别、状态、检测结论字典类型和数据
- 新增计量器具实体类、Mapper、Service和控制器
- 新增计量检测记录实体类、Mapper、Service和控制器
- 添加计量器具到期提醒Redis键常量和定时任务
- 集成站内信模板实现到期提醒功能
- 创建计量器具和检测记录的数据表结构
- 配置相关菜单权限和前端路由集成方案
- 实现器具与检测记录的关联查询和状态同步逻辑
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | # MES 计éå¨å
·ä¸è®¡éæ£æµè®°å½ - å端èè°æ¹æ¡ |
| | | |
| | | ## æ¶åé¡µé¢ |
| | | |
| | | | é¡µé¢ | èåè·¯å¾ | è·¯ç±è·¯å¾ | component_name | |
| | | |------|----------|----------|----------------| |
| | | | 计éå¨å
· | 设å¤ç®¡ç -> 计éå¨å
· | `mes/dv/metering/index` | MesDvMetering | |
| | | | è®¡éæ£æµè®°å½ | 设å¤ç®¡ç -> è®¡éæ£æµè®°å½ | `mes/dv/meteringcheck/index` | MesDvMeteringCheck | |
| | | |
| | | > 两个页é¢ä¸ºå¹³çº§èåãæ£æµè®°å½é¡µå¯éè¿ã计éå¨å
·ã䏿çéï¼ä»
æ¥çæå°å¨å
·çæ£æµåå²ã |
| | | |
| | | ## ä¸å¡æµç¨ä¸æ°æ®å¸¦å
¥ |
| | | |
| | | 1. 计éå¨å
·å表 -> æ°å¢/ç¼è¾è¡¨åï¼å½å
¥å¨å
·ç¼ç ãåç§°ãç±»å«ãæ ¡å卿ã使ç¨é¨é¨ã责任人çã |
| | | 2. è®¡éæ£æµè®°å½ -> æ°å¢/ç¼è¾è¡¨åï¼éæ©ã计éå¨å
·ãï¼ä» `/mes/dv/metering/simple-list` 带å
¥ `meteringId`ã`code`ã`name`ï¼ã |
| | | 3. æ£æµè®°å½ä¿ååï¼å端èªå¨è®¡ç® `nextCheckDate` å¹¶**åå**å°è®¡éå¨å
·ç `lastCheckDate`ã`nextCheckDate`ï¼ |
| | | - `nextCheckDate` ä¼ ç©ºæ¶ = `checkDate + æ ¡å卿(æ)`ï¼èªå¨è®¡ç®ï¼ï¼ |
| | | - `nextCheckDate` ä¼ å¼æ¶ = ä»¥ä¼ å
¥å¼ä¸ºåï¼æå¨æå®ï¼ã |
| | | 4. 计éå¨å
·å表å±ç¤º `expireStatus` å°æç¶ææ è®°ï¼ç±å端æ `nextCheckDate` ä¸å
¨å±é
ç½®çæé天æ°è®¡ç®ã |
| | | |
| | | ## API |
| | | |
| | | ### 计éå¨å
· |
| | | |
| | | | æ¹æ³ | è·¯å¾ | 说æ | æé | |
| | | |------|------|------|------| |
| | | | POST | /mes/dv/metering/create | å建计éå¨å
· | mes:dv-metering:create | |
| | | | PUT | /mes/dv/metering/update | æ´æ°è®¡éå¨å
· | mes:dv-metering:update | |
| | | | DELETE | /mes/dv/metering/delete?id= | å é¤è®¡éå¨å
·ï¼æå
³èæ£æµè®°å½æ¶æç»ï¼ | mes:dv-metering:delete | |
| | | | GET | /mes/dv/metering/get?id= | è·å¾è®¡éå¨å
·è¯¦æ
| mes:dv-metering:query | |
| | | | GET | /mes/dv/metering/page | 计éå¨å
·å页 | mes:dv-metering:query | |
| | | | GET | /mes/dv/metering/export-excel | å¯¼åº Excel | mes:dv-metering:export | |
| | | | GET | /mes/dv/metering/simple-list | ç²¾ç®å表ï¼ä¸æéé¡¹ï¼ | mes:dv-metering:query | |
| | | |
| | | **å页çéåæ°ï¼page æ¥å£ï¼ï¼** |
| | | |
| | | | åæ° | ç±»å | å¿
å¡« | 说æ | |
| | | |------|------|------|------| |
| | | | code | String | å¦ | å¨å
·ç¼ç æ¨¡ç³ | |
| | | | name | String | å¦ | å¨å
·åç§°æ¨¡ç³ | |
| | | | brand | String | å¦ | åç/ç产åå®¶æ¨¡ç³ | |
| | | | category | Integer | å¦ | å¨å
·ç±»å«ï¼åå
¸ï¼ | |
| | | | deptId | Long | å¦ | 使ç¨é¨é¨ | |
| | | | chargeUserId | Long | å¦ | 责任人 | |
| | | | status | Integer | å¦ | ç¶æï¼åå
¸ï¼ | |
| | | | expireStatus | Integer | å¦ | å°æç¶æï¼1 å·²è¿æ / 2 å³å°å°æ / 3 æ£å¸¸ | |
| | | |
| | | ### è®¡éæ£æµè®°å½ |
| | | |
| | | | æ¹æ³ | è·¯å¾ | 说æ | æé | |
| | | |------|------|------|------| |
| | | | POST | /mes/dv/metering-check/create | åå»ºæ£æµè®°å½ | mes:dv-metering-check:create | |
| | | | PUT | /mes/dv/metering-check/update | æ´æ°æ£æµè®°å½ | mes:dv-metering-check:update | |
| | | | DELETE | /mes/dv/metering-check/delete?id= | å 餿£æµè®°å½ | mes:dv-metering-check:delete | |
| | | | GET | /mes/dv/metering-check/get?id= | è·å¾æ£æµè®°å½è¯¦æ
| mes:dv-metering-check:query | |
| | | | GET | /mes/dv/metering-check/page | æ£æµè®°å½å页 | mes:dv-metering-check:query | |
| | | | GET | /mes/dv/metering-check/export-excel | å¯¼åº Excel | mes:dv-metering-check:export | |
| | | |
| | | **å页çéåæ°ï¼page æ¥å£ï¼ï¼** |
| | | |
| | | | åæ° | ç±»å | å¿
å¡« | 说æ | |
| | | |------|------|------|------| |
| | | | meteringId | Long | å¦ | 计éå¨å
·ï¼ä»å¨å
·å表带å
¥ï¼ | |
| | | | checkCode | String | å¦ | æ£æµç¼å·æ¨¡ç³ | |
| | | | checkResult | Integer | å¦ | æ£æµç»è®ºï¼åå
¸ï¼ | |
| | | | checkDate | LocalDate[] | å¦ | æ£æµæ¥æåºé´ | |
| | | |
| | | ### ååºå段æ°å¢è¯´æ |
| | | |
| | | 计éå¨å
·å表/详æ
ååºé¢å¤è¿åï¼ |
| | | |
| | | | åæ®µ | ç±»å | 说æ | |
| | | |------|------|------| |
| | | | deptName | String | 使ç¨é¨é¨åç§° | |
| | | | chargeUserNickname | String | 责任人æµç§° | |
| | | | expireStatus | Integer | å°æç¶æï¼1 å·²è¿æ / 2 å³å°å°æ / 3 æ£å¸¸ | |
| | | | expireDays | Long | è·å°æå¤©æ°ï¼æ£æ°æªå°ãè´æ°å·²è¿æï¼ | |
| | | |
| | | è®¡éæ£æµè®°å½å表/详æ
ååºé¢å¤è¿åï¼ |
| | | |
| | | | åæ®µ | ç±»å | 说æ | |
| | | |------|------|------| |
| | | | meteringCode | String | 计éå¨å
·ç¼ç | |
| | | | meteringName | String | 计éå¨å
·åç§° | |
| | | | checkUserNickname | String | æ£æµäººæµç§° | |
| | | |
| | | ## åæ®µå±ç¤ºè§å |
| | | |
| | | | åæ®µ | å±ç¤ºä½ç½® | 说æ | |
| | | |------|----------|------| |
| | | | expireStatus | 计éå¨å
·å表 | 1 å·²è¿æ=å±é©(danger)ï¼2 å³å°å°æ=è¦å(warning)ï¼3 æ£å¸¸=æå(success) | |
| | | | status | 计éå¨å
·å表ã表å | åå
¸ mes_dv_metering_statusï¼å¨ç¨=success/åç¨=info/æ¥åº=dangerï¼ | |
| | | | category | 计éå¨å
·å表ã表å | åå
¸ mes_dv_metering_category | |
| | | | nextCheckDate | ä¸¤ä¸ªé¡µé¢ | 计éå¨å
·å±ç¤ºä¸ºã䏿¬¡æ£æµæ¥æãåï¼æ£æµè®°å½ä¿åæ¶åå | |
| | | | checkResult | æ£æµè®°å½å表ã表å | åå
¸ mes_dv_metering_check_resultï¼åæ ¼=success/ä¸åæ ¼=dangerï¼ | |
| | | | meteringCode/meteringName | æ£æµè®°å½å表 | ä»å¨å
·å¸¦å
¥å±ç¤º | |
| | | | deptName/chargeUserNickname | 计éå¨å
·å表 | é¨é¨ã责任人åç§° | |
| | | |
| | | ## ä¸å¡è§å说æ |
| | | |
| | | | åºæ¯ | è§å | |
| | | |------|------| |
| | | | æ£æµè®°å½æ°å¢ | æªå¡« nextCheckDate æ¶æ `checkDate + æ ¡å卿` èªå¨è®¡ç®å¹¶ä¿å | |
| | | | æ£æµè®°å½æ´æ° | éæ°è®¡ç® nextCheckDateï¼å¹¶ååå¨å
· | |
| | | | æ£æµè®°å½å é¤ | å¨å
·æå©ä½ãææ°ä¸æ¡è®°å½ãæ´ä½éç®ååï¼æ è®°å½å lastCheckDate/nextCheckDate ç½®ç©ºï¼ | |
| | | | 计éå¨å
·å é¤ | å·²å
³èæ£æµè®°å½æ¶æç»å é¤ï¼æç¤ºã计éå¨å
·å·²å
³èæ£æµè®°å½ï¼æ æ³å é¤ã | |
| | | | å°ææé | å°æå N 天ï¼å
¨å±é
ç½® `mes.dv-metering.remind-days`ï¼é»è®¤ 30ï¼åéç«å
ä¿¡ç»è´£ä»»äººï¼åä¸å¨å
·åä¸å°ææ¥ 60 天å
åªæé䏿¬¡ | |
| | | | ç¼ç /ç¼å·å¯ä¸ | å¨å
· codeãæ£æµ checkCode åå¯ä¸ï¼é夿¶å端æ¥é | |
| | | |
| | | ## 注æäºé¡¹ |
| | | |
| | | - expireStatus ç±å端计ç®å¹¶è¿åï¼å端åªéæä¸ææ¸²æ tag é¢è²ï¼æ éèªè¡è®¡ç®å¤©æ°ã |
| | | - å é¤å¨å
·åé确认æ å
³èæ£æµè®°å½ï¼å 餿£æµè®°å½åå¨å
·çå°ææ¥ä¼éä¹ååï¼å端åºå·æ°å¨å
·å表ã |
| | | - æ£æµè®°å½é¡µä¾èµè®¡éå¨å
·æ°æ®ï¼åºå
åå¨å¨å
·åç»è®°æ£æµè®°å½ã |
| | | - æé天æ°å¯å¨ãåºç¡è®¾æ½ -> é
置管çãä¸ä¿®æ¹ `mes.dv-metering.remind-days`ï¼æ¹åç«å³çæã |
| | | - ä¸ä¸ªæ°åå
¸å¯å¨ãç³»ç»ç®¡ç -> åå
¸ç®¡çãä¸ç»´æ¤ï¼mes_dv_metering_categoryãmes_dv_metering_statusãmes_dv_metering_check_resultã |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | -- ============================================ |
| | | -- MES 设å¤ç®¡ç-计éå¨å
· & è®¡éæ£æµè®°å½ 模ååå§åèæ¬ |
| | | -- 1. 建表 2. èå 3. åå
¸ 4. ç«å
ä¿¡æ¨¡æ¿ 5. å
¨å±é
ç½® |
| | | -- ============================================ |
| | | |
| | | -- 1. 建表 |
| | | DROP TABLE IF EXISTS `mes_dv_metering_check`; |
| | | DROP TABLE IF EXISTS `mes_dv_metering`; |
| | | CREATE TABLE `mes_dv_metering` ( |
| | | `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主é®ID', |
| | | `code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '计éå¨å
·ç¼ç ', |
| | | `name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '计éå¨å
·åç§°', |
| | | `specification` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT 'è§æ ¼åå·', |
| | | `brand` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT 'åç/ç产åå®¶', |
| | | `category` int NULL DEFAULT NULL COMMENT 'å¨å
·ç±»å«ï¼å¡å°º/ååå°º/åå表çï¼ï¼åå
¸ mes_dv_metering_category', |
| | | `precision` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '精度', |
| | | `range` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT 'éç¨', |
| | | `dept_id` bigint NULL DEFAULT NULL COMMENT '使ç¨é¨é¨ç¼å·', |
| | | `charge_user_id` bigint NULL DEFAULT NULL COMMENT '责任人ç¼å·ï¼ç«å
ä¿¡åé对象ï¼', |
| | | `check_cycle_count` int NOT NULL COMMENT 'æ ¡åå¨æï¼æï¼', |
| | | `use_date` date NULL DEFAULT NULL COMMENT 'æå
¥ä½¿ç¨æ¥æ', |
| | | `last_check_date` date NULL DEFAULT NULL COMMENT '䏿¬¡æ£æµæ¥æ', |
| | | `next_check_date` date NULL DEFAULT NULL COMMENT '䏿¬¡æ£æµæ¥æï¼å°ææ¥ï¼', |
| | | `status` int NOT NULL COMMENT 'ç¶æï¼å¨ç¨/åç¨/æ¥åºï¼ï¼åå
¸ mes_dv_metering_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, |
| | | UNIQUE INDEX `uk_code` (`code`), |
| | | INDEX `idx_dept_id` (`dept_id`), |
| | | INDEX `idx_charge_user_id` (`charge_user_id`), |
| | | INDEX `idx_next_check_date` (`next_check_date`) |
| | | ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = 'MES 计éå¨å
·' ROW_FORMAT = Dynamic; |
| | | |
| | | CREATE TABLE `mes_dv_metering_check` ( |
| | | `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主é®ID', |
| | | `metering_id` bigint NOT NULL COMMENT '计éå¨å
·ID', |
| | | `check_code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'æ£æµç¼å·', |
| | | `check_date` date NULL DEFAULT NULL COMMENT 'æ£æµæ¥æ', |
| | | `check_org` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT 'æ£æµæºæ', |
| | | `check_result` int NULL DEFAULT NULL COMMENT 'æ£æµç»è®ºï¼åæ ¼/ä¸åæ ¼ï¼ï¼åå
¸ mes_dv_metering_check_result', |
| | | `cert_no` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT 'è¯ä¹¦ç¼å·', |
| | | `check_user_id` bigint NULL DEFAULT NULL COMMENT 'æ£æµäººç¼å·', |
| | | `next_check_date` date NULL DEFAULT NULL COMMENT '䏿¬¡æ£æµæ¥æï¼èªå¨è®¡ç®ææå¨æå®ï¼', |
| | | `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, |
| | | UNIQUE INDEX `uk_check_code` (`check_code`), |
| | | INDEX `idx_metering_id` (`metering_id`), |
| | | INDEX `idx_check_date` (`check_date`) |
| | | ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = 'MES è®¡éæ£æµè®°å½' ROW_FORMAT = Dynamic; |
| | | |
| | | -- 2. èåï¼ç¶èå 5300 设å¤ç®¡çï¼ |
| | | 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 (5380, '计éå¨å
·', '', 2, 8, 5300, 'metering', 'ep:scale-to-original', 'mes/dv/metering/index', 'MesDvMetering', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'); |
| | | |
| | | 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 |
| | | (5381, '计éå¨å
·æ¥è¯¢', 'mes:dv-metering:query', 3, 1, 5380, '', '', '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | (5382, '计éå¨å
ጌȼ', 'mes:dv-metering:create', 3, 2, 5380, '', '', '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | (5383, '计éå¨å
·æ´æ°', 'mes:dv-metering:update', 3, 3, 5380, '', '', '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | (5384, '计éå¨å
·å é¤', 'mes:dv-metering:delete', 3, 4, 5380, '', '', '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | (5385, '计éå¨å
·å¯¼åº', 'mes:dv-metering:export', 3, 5, 5380, '', '', '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'); |
| | | |
| | | 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 (5386, 'è®¡éæ£æµè®°å½', '', 2, 9, 5300, 'metering-check', 'ep:checked', 'mes/dv/meteringcheck/index', 'MesDvMeteringCheck', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'); |
| | | |
| | | 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 |
| | | (5387, 'æ£æµè®°å½æ¥è¯¢', 'mes:dv-metering-check:query', 3, 1, 5386, '', '', '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | (5388, 'æ£æµè®°å½å建', 'mes:dv-metering-check:create', 3, 2, 5386, '', '', '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | (5389, 'æ£æµè®°å½æ´æ°', 'mes:dv-metering-check:update', 3, 3, 5386, '', '', '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | (5390, 'æ£æµè®°å½å é¤', 'mes:dv-metering-check:delete', 3, 4, 5386, '', '', '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'), |
| | | (5391, 'æ£æµè®°å½å¯¼åº', 'mes:dv-metering-check:export', 3, 5, 5386, '', '', '', '', 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'); |
| | | |
| | | -- 3. åå
¸ç±»å |
| | | INSERT INTO `system_dict_type` (`name`, `type`, `status`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) |
| | | VALUES |
| | | ('MES 计éå¨å
·ç±»å«', 'mes_dv_metering_category', 0, '计éå¨å
·ç±»å«', '1', NOW(), '1', NOW(), b'0'), |
| | | ('MES 计éå¨å
·ç¶æ', 'mes_dv_metering_status', 0, '计éå¨å
·ç¶æ', '1', NOW(), '1', NOW(), b'0'), |
| | | ('MES è®¡éæ£æµç»è®º', 'mes_dv_metering_check_result', 0, 'è®¡éæ£æµç»è®º', '1', NOW(), '1', NOW(), b'0'); |
| | | |
| | | -- 4. åå
¸æ°æ® |
| | | 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_dv_metering_category', 0, '', '', 'å¡å°º', '1', NOW(), '1', NOW(), b'0'), |
| | | (2, 'ååå°º', '2', 'mes_dv_metering_category', 0, '', '', 'ååå°º', '1', NOW(), '1', NOW(), b'0'), |
| | | (3, 'åå表', '3', 'mes_dv_metering_category', 0, '', '', 'åå表', '1', NOW(), '1', NOW(), b'0'), |
| | | (4, '温度计', '4', 'mes_dv_metering_category', 0, '', '', '温度计', '1', NOW(), '1', NOW(), b'0'), |
| | | (5, 'ä¸ç¨è¡¨', '5', 'mes_dv_metering_category', 0, '', '', 'ä¸ç¨è¡¨', '1', NOW(), '1', NOW(), b'0'), |
| | | (6, '天平ç ç ', '6', 'mes_dv_metering_category', 0, '', '', '天平ç ç ', '1', NOW(), '1', NOW(), b'0'), |
| | | (7, 'å
¶ä»', '7', 'mes_dv_metering_category', 0, '', '', 'å
¶ä»', '1', NOW(), '1', NOW(), b'0'), |
| | | -- å¨å
·ç¶æ |
| | | (1, 'å¨ç¨', '1', 'mes_dv_metering_status', 0, 'success', '', 'å¨ç¨', '1', NOW(), '1', NOW(), b'0'), |
| | | (2, 'åç¨', '2', 'mes_dv_metering_status', 0, 'info', '', 'åç¨', '1', NOW(), '1', NOW(), b'0'), |
| | | (3, 'æ¥åº', '3', 'mes_dv_metering_status', 0, 'danger', '', 'æ¥åº', '1', NOW(), '1', NOW(), b'0'), |
| | | -- æ£æµç»è®º |
| | | (1, 'åæ ¼', '1', 'mes_dv_metering_check_result', 0, 'success', '', 'åæ ¼', '1', NOW(), '1', NOW(), b'0'), |
| | | (2, 'ä¸åæ ¼', '2', 'mes_dv_metering_check_result', 0, 'danger', '', 'ä¸åæ ¼', '1', NOW(), '1', NOW(), b'0'); |
| | | |
| | | -- 5. ç«å
ä¿¡æ¨¡æ¿ |
| | | INSERT INTO `system_notify_template` (`name`, `code`, `nickname`, `content`, `type`, `params`, `status`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) |
| | | VALUES ('计éå¨å
·å°ææé', 'mes_metering_expire_remind', 'MES ç³»ç»', '计éå¨å
·ã{meteringCode}ã{meteringName} å°äº {nextCheckDate} å°æï¼è¯·åæ¶å®ææ ¡å/æ£å®ã', 2, '["meteringCode","meteringName","nextCheckDate"]', 0, '1', NOW(), '1', NOW(), b'0'); |
| | | |
| | | -- 6. å
¨å±é
ç½®ï¼æé天æ°ï¼é»è®¤ 30 å¤©ï¼ |
| | | INSERT INTO `infra_config` (`category`, `type`, `name`, `config_key`, `value`, `visible`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) |
| | | VALUES ('biz', 2, 'MES 计éå¨å
·å°ææé天æ°', 'mes.dv-metering.remind-days', '30', 0, '计éå¨å
·ä¸æ¬¡æ£æµæ¥æå°æå N 天æéï¼ç«å
ä¿¡åéç»è´£ä»»äººï¼', '1', NOW(), '1', NOW(), b'0'); |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.dv.metering; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; |
| | | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| | | 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.framework.excel.core.util.ExcelUtils; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.metering.vo.MesDvMeteringPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.metering.vo.MesDvMeteringRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.metering.vo.MesDvMeteringSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.dv.metering.MesDvMeteringDO; |
| | | import cn.iocoder.yudao.module.mes.enums.dv.MesDvMeteringExpireStatusEnum; |
| | | import cn.iocoder.yudao.module.mes.service.dv.metering.MesDvMeteringService; |
| | | import cn.iocoder.yudao.module.system.api.dept.DeptApi; |
| | | import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; |
| | | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| | | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; |
| | | 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.servlet.http.HttpServletResponse; |
| | | 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.io.IOException; |
| | | import java.time.LocalDate; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; |
| | | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| | | |
| | | @Tag(name = "管çåå° - MES 计éå¨å
·") |
| | | @RestController |
| | | @RequestMapping("/mes/dv/metering") |
| | | @Validated |
| | | public class MesDvMeteringController { |
| | | |
| | | @Resource |
| | | private MesDvMeteringService meteringService; |
| | | @Resource |
| | | private DeptApi deptApi; |
| | | @Resource |
| | | private AdminUserApi adminUserApi; |
| | | |
| | | @PostMapping("/create") |
| | | @Operation(summary = "å建计éå¨å
·") |
| | | @PreAuthorize("@ss.hasPermission('mes:dv-metering:create')") |
| | | public CommonResult<Long> createMetering(@Valid @RequestBody MesDvMeteringSaveReqVO createReqVO) { |
| | | return success(meteringService.createMetering(createReqVO)); |
| | | } |
| | | |
| | | @PutMapping("/update") |
| | | @Operation(summary = "æ´æ°è®¡éå¨å
·") |
| | | @PreAuthorize("@ss.hasPermission('mes:dv-metering:update')") |
| | | public CommonResult<Boolean> updateMetering(@Valid @RequestBody MesDvMeteringSaveReqVO updateReqVO) { |
| | | meteringService.updateMetering(updateReqVO); |
| | | return success(true); |
| | | } |
| | | |
| | | @DeleteMapping("/delete") |
| | | @Operation(summary = "å é¤è®¡éå¨å
·") |
| | | @Parameter(name = "id", description = "ç¼å·", required = true) |
| | | @PreAuthorize("@ss.hasPermission('mes:dv-metering:delete')") |
| | | public CommonResult<Boolean> deleteMetering(@RequestParam("id") Long id) { |
| | | meteringService.deleteMetering(id); |
| | | return success(true); |
| | | } |
| | | |
| | | @GetMapping("/get") |
| | | @Operation(summary = "è·å¾è®¡éå¨å
·") |
| | | @Parameter(name = "id", description = "ç¼å·", required = true, example = "1024") |
| | | @PreAuthorize("@ss.hasPermission('mes:dv-metering:query')") |
| | | public CommonResult<MesDvMeteringRespVO> getMetering(@RequestParam("id") Long id) { |
| | | MesDvMeteringDO metering = meteringService.getMetering(id); |
| | | if (metering == null) { |
| | | return success(null); |
| | | } |
| | | return success(buildMeteringRespVOList(Collections.singletonList(metering)).get(0)); |
| | | } |
| | | |
| | | @GetMapping("/page") |
| | | @Operation(summary = "è·å¾è®¡éå¨å
·å页") |
| | | @PreAuthorize("@ss.hasPermission('mes:dv-metering:query')") |
| | | public CommonResult<PageResult<MesDvMeteringRespVO>> getMeteringPage(@Valid MesDvMeteringPageReqVO pageReqVO) { |
| | | PageResult<MesDvMeteringDO> pageResult = meteringService.getMeteringPage(pageReqVO); |
| | | return success(new PageResult<>(buildMeteringRespVOList(pageResult.getList()), pageResult.getTotal())); |
| | | } |
| | | |
| | | @GetMapping("/export-excel") |
| | | @Operation(summary = "导åºè®¡éå¨å
· Excel") |
| | | @PreAuthorize("@ss.hasPermission('mes:dv-metering:export')") |
| | | @ApiAccessLog(operateType = EXPORT) |
| | | public void exportMeteringExcel(@Valid MesDvMeteringPageReqVO pageReqVO, |
| | | HttpServletResponse response) throws IOException { |
| | | pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); |
| | | List<MesDvMeteringDO> list = meteringService.getMeteringPage(pageReqVO).getList(); |
| | | ExcelUtils.write(response, "计éå¨å
·.xls", "æ°æ®", MesDvMeteringRespVO.class, |
| | | buildMeteringRespVOList(list)); |
| | | } |
| | | |
| | | @GetMapping("/simple-list") |
| | | @Operation(summary = "è·å¾è®¡éå¨å
·ç²¾ç®å表", description = "主è¦ç¨äºå端ç䏿é项") |
| | | @PreAuthorize("@ss.hasPermission('mes:dv-metering:query')") |
| | | public CommonResult<List<MesDvMeteringRespVO>> getMeteringSimpleList() { |
| | | List<MesDvMeteringDO> list = meteringService.getMeteringList(); |
| | | return success(buildMeteringRespVOList(list)); |
| | | } |
| | | |
| | | // ==================== æ¼æ¥ VO ==================== |
| | | |
| | | @SuppressWarnings("DuplicatedCode") |
| | | private List<MesDvMeteringRespVO> buildMeteringRespVOList(List<MesDvMeteringDO> list) { |
| | | if (CollUtil.isEmpty(list)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | // 1. æ¹éè·åå
³èæ°æ® |
| | | int remindDays = meteringService.getRemindDays(); |
| | | Map<Long, DeptRespDTO> deptMap = CollUtil.isNotEmpty(convertSet(list, MesDvMeteringDO::getDeptId)) |
| | | ? deptApi.getDeptMap(convertSet(list, MesDvMeteringDO::getDeptId)) : Collections.emptyMap(); |
| | | Map<Long, AdminUserRespDTO> userMap = CollUtil.isNotEmpty(convertSet(list, MesDvMeteringDO::getChargeUserId)) |
| | | ? adminUserApi.getUserMap(convertSet(list, MesDvMeteringDO::getChargeUserId)) : Collections.emptyMap(); |
| | | // 2. æ¼æ¥ VO |
| | | return BeanUtils.toBean(list, MesDvMeteringRespVO.class, vo -> { |
| | | // 计ç®å°æç¶æä¸å©ä½å¤©æ° |
| | | vo.setExpireStatus(MesDvMeteringExpireStatusEnum.compute(vo.getNextCheckDate(), remindDays)); |
| | | if (vo.getNextCheckDate() != null) { |
| | | vo.setExpireDays(ChronoUnit.DAYS.between(LocalDate.now(), vo.getNextCheckDate())); |
| | | } |
| | | MapUtils.findAndThen(deptMap, vo.getDeptId(), dept -> vo.setDeptName(dept.getName())); |
| | | MapUtils.findAndThen(userMap, vo.getChargeUserId(), |
| | | user -> vo.setChargeUserNickname(user.getNickname())); |
| | | }); |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.dv.metering.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 java.time.LocalDate; |
| | | |
| | | @Schema(description = "管çåå° - MES 计éå¨å
·å页 Request VO") |
| | | @Data |
| | | @EqualsAndHashCode(callSuper = true) |
| | | @ToString(callSuper = true) |
| | | public class MesDvMeteringPageReqVO extends PageParam { |
| | | |
| | | @Schema(description = "计éå¨å
·ç¼ç ", example = "MD-001") |
| | | private String code; |
| | | |
| | | @Schema(description = "计éå¨å
·åç§°", example = "æ°æ¾å¡å°º") |
| | | private String name; |
| | | |
| | | @Schema(description = "åç/ç产åå®¶", example = "ä¸ä¸°") |
| | | private String brand; |
| | | |
| | | @Schema(description = "å¨å
·ç±»å«", example = "1") |
| | | private Integer category; |
| | | |
| | | @Schema(description = "使ç¨é¨é¨ç¼å·", example = "100") |
| | | private Long deptId; |
| | | |
| | | @Schema(description = "责任人ç¼å·", example = "200") |
| | | private Long chargeUserId; |
| | | |
| | | @Schema(description = "ç¶æ", example = "1") |
| | | private Integer status; |
| | | |
| | | @Schema(description = "å°æç¶æï¼1 å·²è¿æ/2 å³å°å°æ/3 æ£å¸¸ï¼", example = "2") |
| | | private Integer expireStatus; |
| | | |
| | | @Schema(description = "䏿¬¡æ£æµæ¥æå¼å§ï¼ç±åç«¯æ ¹æ®å°æç¶æèªå¨å¡«å
ï¼", hidden = true) |
| | | private LocalDate nextCheckDateBegin; |
| | | |
| | | @Schema(description = "䏿¬¡æ£æµæ¥æç»æï¼ç±åç«¯æ ¹æ®å°æç¶æèªå¨å¡«å
ï¼", hidden = true) |
| | | private LocalDate nextCheckDateEnd; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.dv.metering.vo; |
| | | |
| | | import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; |
| | | import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; |
| | | import cn.iocoder.yudao.module.mes.enums.DictTypeConstants; |
| | | import cn.idev.excel.annotation.ExcelIgnoreUnannotated; |
| | | import cn.idev.excel.annotation.ExcelProperty; |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | |
| | | @Schema(description = "管çåå° - MES 计éå¨å
· Response VO") |
| | | @Data |
| | | @ExcelIgnoreUnannotated |
| | | public class MesDvMeteringRespVO { |
| | | |
| | | @Schema(description = "ç¼å·", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| | | @ExcelProperty("ç¼å·") |
| | | private Long id; |
| | | |
| | | @Schema(description = "计éå¨å
·ç¼ç ", requiredMode = Schema.RequiredMode.REQUIRED, example = "MD-001") |
| | | @ExcelProperty("计éå¨å
·ç¼ç ") |
| | | private String code; |
| | | |
| | | @Schema(description = "计éå¨å
·åç§°", requiredMode = Schema.RequiredMode.REQUIRED, example = "æ°æ¾å¡å°º") |
| | | @ExcelProperty("计éå¨å
·åç§°") |
| | | private String name; |
| | | |
| | | @Schema(description = "è§æ ¼åå·", example = "0-150mm") |
| | | @ExcelProperty("è§æ ¼åå·") |
| | | private String specification; |
| | | |
| | | @Schema(description = "åç/ç产åå®¶", example = "ä¸ä¸°") |
| | | @ExcelProperty("åç/ç产åå®¶") |
| | | private String brand; |
| | | |
| | | @Schema(description = "å¨å
·ç±»å«", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| | | @ExcelProperty(value = "å¨å
·ç±»å«", converter = DictConvert.class) |
| | | @DictFormat(DictTypeConstants.MES_DV_METERING_CATEGORY) |
| | | private Integer category; |
| | | |
| | | @Schema(description = "精度", example = "0.01mm") |
| | | @ExcelProperty("精度") |
| | | private String precision; |
| | | |
| | | @Schema(description = "éç¨", example = "0-150mm") |
| | | @ExcelProperty("éç¨") |
| | | private String range; |
| | | |
| | | @Schema(description = "使ç¨é¨é¨ç¼å·", example = "100") |
| | | private Long deptId; |
| | | |
| | | @Schema(description = "使ç¨é¨é¨åç§°", example = "è´¨æ£é¨") |
| | | @ExcelProperty("使ç¨é¨é¨") |
| | | private String deptName; |
| | | |
| | | @Schema(description = "责任人ç¼å·", example = "200") |
| | | private Long chargeUserId; |
| | | |
| | | @Schema(description = "责任人åç§°", example = "å¼ ä¸") |
| | | @ExcelProperty("责任人") |
| | | private String chargeUserNickname; |
| | | |
| | | @Schema(description = "æ ¡åå¨æï¼æï¼", requiredMode = Schema.RequiredMode.REQUIRED, example = "12") |
| | | @ExcelProperty("æ ¡å卿(æ)") |
| | | private Integer checkCycleCount; |
| | | |
| | | @Schema(description = "æå
¥ä½¿ç¨æ¥æ") |
| | | @ExcelProperty("æå
¥ä½¿ç¨æ¥æ") |
| | | private LocalDate useDate; |
| | | |
| | | @Schema(description = "䏿¬¡æ£æµæ¥æ") |
| | | @ExcelProperty("䏿¬¡æ£æµæ¥æ") |
| | | private LocalDate lastCheckDate; |
| | | |
| | | @Schema(description = "䏿¬¡æ£æµæ¥æï¼å°ææ¥ï¼") |
| | | @ExcelProperty("䏿¬¡æ£æµæ¥æ") |
| | | private LocalDate nextCheckDate; |
| | | |
| | | @Schema(description = "å°æç¶æï¼1 å·²è¿æ/2 å³å°å°æ/3 æ£å¸¸ï¼", example = "2") |
| | | @ExcelProperty("å°æç¶æ") |
| | | private Integer expireStatus; |
| | | |
| | | @Schema(description = "è·ç¦»å°æå¤©æ°ï¼æ£æ°æªå°ï¼è´æ°å·²è¿æï¼", example = "10") |
| | | @ExcelProperty("å©ä½å¤©æ°") |
| | | private Long expireDays; |
| | | |
| | | @Schema(description = "ç¶æ", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| | | @ExcelProperty(value = "ç¶æ", converter = DictConvert.class) |
| | | @DictFormat(DictTypeConstants.MES_DV_METERING_STATUS) |
| | | private Integer status; |
| | | |
| | | @Schema(description = "夿³¨", example = "夿³¨") |
| | | @ExcelProperty("夿³¨") |
| | | private String remark; |
| | | |
| | | @Schema(description = "å建æ¶é´", requiredMode = Schema.RequiredMode.REQUIRED) |
| | | @ExcelProperty("å建æ¶é´") |
| | | private LocalDateTime createTime; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.dv.metering.vo; |
| | | |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import jakarta.validation.constraints.NotEmpty; |
| | | import jakarta.validation.constraints.NotNull; |
| | | import lombok.Data; |
| | | |
| | | import java.time.LocalDate; |
| | | |
| | | @Schema(description = "管çåå° - MES 计éå¨å
·æ°å¢/ä¿®æ¹ Request VO") |
| | | @Data |
| | | public class MesDvMeteringSaveReqVO { |
| | | |
| | | @Schema(description = "ç¼å·", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| | | private Long id; |
| | | |
| | | @Schema(description = "计éå¨å
·ç¼ç ", requiredMode = Schema.RequiredMode.REQUIRED, example = "MD-001") |
| | | @NotEmpty(message = "计éå¨å
·ç¼ç ä¸è½ä¸ºç©º") |
| | | private String code; |
| | | |
| | | @Schema(description = "计éå¨å
·åç§°", requiredMode = Schema.RequiredMode.REQUIRED, example = "æ°æ¾å¡å°º") |
| | | @NotEmpty(message = "计éå¨å
·åç§°ä¸è½ä¸ºç©º") |
| | | private String name; |
| | | |
| | | @Schema(description = "è§æ ¼åå·", example = "0-150mm") |
| | | private String specification; |
| | | |
| | | @Schema(description = "åç/ç产åå®¶", example = "ä¸ä¸°") |
| | | private String brand; |
| | | |
| | | @Schema(description = "å¨å
·ç±»å«", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| | | @NotNull(message = "å¨å
·ç±»å«ä¸è½ä¸ºç©º") |
| | | private Integer category; |
| | | |
| | | @Schema(description = "精度", example = "0.01mm") |
| | | private String precision; |
| | | |
| | | @Schema(description = "éç¨", example = "0-150mm") |
| | | private String range; |
| | | |
| | | @Schema(description = "使ç¨é¨é¨ç¼å·", example = "100") |
| | | private Long deptId; |
| | | |
| | | @Schema(description = "责任人ç¼å·", example = "200") |
| | | private Long chargeUserId; |
| | | |
| | | @Schema(description = "æ ¡åå¨æï¼æï¼", requiredMode = Schema.RequiredMode.REQUIRED, example = "12") |
| | | @NotNull(message = "æ ¡å卿ä¸è½ä¸ºç©º") |
| | | private Integer checkCycleCount; |
| | | |
| | | @Schema(description = "æå
¥ä½¿ç¨æ¥æ") |
| | | private LocalDate useDate; |
| | | |
| | | @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.dv.meteringcheck; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; |
| | | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| | | 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.framework.excel.core.util.ExcelUtils; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.meteringcheck.vo.MesDvMeteringCheckPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.meteringcheck.vo.MesDvMeteringCheckRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.meteringcheck.vo.MesDvMeteringCheckSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.dv.metering.MesDvMeteringDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.dv.meteringcheck.MesDvMeteringCheckDO; |
| | | import cn.iocoder.yudao.module.mes.service.dv.metering.MesDvMeteringService; |
| | | import cn.iocoder.yudao.module.mes.service.dv.meteringcheck.MesDvMeteringCheckService; |
| | | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| | | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; |
| | | 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.servlet.http.HttpServletResponse; |
| | | 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.io.IOException; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; |
| | | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| | | |
| | | @Tag(name = "管çåå° - MES è®¡éæ£æµè®°å½") |
| | | @RestController |
| | | @RequestMapping("/mes/dv/metering-check") |
| | | @Validated |
| | | public class MesDvMeteringCheckController { |
| | | |
| | | @Resource |
| | | private MesDvMeteringCheckService meteringCheckService; |
| | | @Resource |
| | | private MesDvMeteringService meteringService; |
| | | @Resource |
| | | private AdminUserApi adminUserApi; |
| | | |
| | | @PostMapping("/create") |
| | | @Operation(summary = "åå»ºè®¡éæ£æµè®°å½") |
| | | @PreAuthorize("@ss.hasPermission('mes:dv-metering-check:create')") |
| | | public CommonResult<Long> createMeteringCheck(@Valid @RequestBody MesDvMeteringCheckSaveReqVO createReqVO) { |
| | | return success(meteringCheckService.createMeteringCheck(createReqVO)); |
| | | } |
| | | |
| | | @PutMapping("/update") |
| | | @Operation(summary = "æ´æ°è®¡éæ£æµè®°å½") |
| | | @PreAuthorize("@ss.hasPermission('mes:dv-metering-check:update')") |
| | | public CommonResult<Boolean> updateMeteringCheck(@Valid @RequestBody MesDvMeteringCheckSaveReqVO updateReqVO) { |
| | | meteringCheckService.updateMeteringCheck(updateReqVO); |
| | | return success(true); |
| | | } |
| | | |
| | | @DeleteMapping("/delete") |
| | | @Operation(summary = "å é¤è®¡éæ£æµè®°å½") |
| | | @Parameter(name = "id", description = "ç¼å·", required = true) |
| | | @PreAuthorize("@ss.hasPermission('mes:dv-metering-check:delete')") |
| | | public CommonResult<Boolean> deleteMeteringCheck(@RequestParam("id") Long id) { |
| | | meteringCheckService.deleteMeteringCheck(id); |
| | | return success(true); |
| | | } |
| | | |
| | | @GetMapping("/get") |
| | | @Operation(summary = "è·å¾è®¡éæ£æµè®°å½") |
| | | @Parameter(name = "id", description = "ç¼å·", required = true, example = "1024") |
| | | @PreAuthorize("@ss.hasPermission('mes:dv-metering-check:query')") |
| | | public CommonResult<MesDvMeteringCheckRespVO> getMeteringCheck(@RequestParam("id") Long id) { |
| | | MesDvMeteringCheckDO check = meteringCheckService.getMeteringCheck(id); |
| | | if (check == null) { |
| | | return success(null); |
| | | } |
| | | return success(buildMeteringCheckRespVOList(Collections.singletonList(check)).get(0)); |
| | | } |
| | | |
| | | @GetMapping("/page") |
| | | @Operation(summary = "è·å¾è®¡éæ£æµè®°å½å页") |
| | | @PreAuthorize("@ss.hasPermission('mes:dv-metering-check:query')") |
| | | public CommonResult<PageResult<MesDvMeteringCheckRespVO>> getMeteringCheckPage( |
| | | @Valid MesDvMeteringCheckPageReqVO pageReqVO) { |
| | | PageResult<MesDvMeteringCheckDO> pageResult = meteringCheckService.getMeteringCheckPage(pageReqVO); |
| | | return success(new PageResult<>(buildMeteringCheckRespVOList(pageResult.getList()), pageResult.getTotal())); |
| | | } |
| | | |
| | | @GetMapping("/export-excel") |
| | | @Operation(summary = "导åºè®¡éæ£æµè®°å½ Excel") |
| | | @PreAuthorize("@ss.hasPermission('mes:dv-metering-check:export')") |
| | | @ApiAccessLog(operateType = EXPORT) |
| | | public void exportMeteringCheckExcel(@Valid MesDvMeteringCheckPageReqVO pageReqVO, |
| | | HttpServletResponse response) throws IOException { |
| | | pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); |
| | | List<MesDvMeteringCheckDO> list = meteringCheckService.getMeteringCheckPage(pageReqVO).getList(); |
| | | ExcelUtils.write(response, "è®¡éæ£æµè®°å½.xls", "æ°æ®", MesDvMeteringCheckRespVO.class, |
| | | buildMeteringCheckRespVOList(list)); |
| | | } |
| | | |
| | | // ==================== æ¼æ¥ VO ==================== |
| | | |
| | | @SuppressWarnings("DuplicatedCode") |
| | | private List<MesDvMeteringCheckRespVO> buildMeteringCheckRespVOList(List<MesDvMeteringCheckDO> list) { |
| | | if (CollUtil.isEmpty(list)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | // 1. æ¹éè·åå
³èæ°æ® |
| | | Map<Long, MesDvMeteringDO> meteringMap = meteringService.getMeteringMap( |
| | | convertSet(list, MesDvMeteringCheckDO::getMeteringId)); |
| | | Map<Long, AdminUserRespDTO> userMap = CollUtil.isNotEmpty(convertSet(list, MesDvMeteringCheckDO::getCheckUserId)) |
| | | ? adminUserApi.getUserMap(convertSet(list, MesDvMeteringCheckDO::getCheckUserId)) : Collections.emptyMap(); |
| | | // 2. æ¼æ¥ VO |
| | | return BeanUtils.toBean(list, MesDvMeteringCheckRespVO.class, vo -> { |
| | | MapUtils.findAndThen(meteringMap, vo.getMeteringId(), |
| | | metering -> vo.setMeteringCode(metering.getCode()).setMeteringName(metering.getName())); |
| | | MapUtils.findAndThen(userMap, vo.getCheckUserId(), |
| | | user -> vo.setCheckUserNickname(user.getNickname())); |
| | | }); |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.dv.meteringcheck.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 java.time.LocalDate; |
| | | |
| | | @Schema(description = "管çåå° - MES è®¡éæ£æµè®°å½å页 Request VO") |
| | | @Data |
| | | @EqualsAndHashCode(callSuper = true) |
| | | @ToString(callSuper = true) |
| | | public class MesDvMeteringCheckPageReqVO extends PageParam { |
| | | |
| | | @Schema(description = "计éå¨å
·ç¼å·", example = "100") |
| | | private Long meteringId; |
| | | |
| | | @Schema(description = "æ£æµç¼å·", example = "CK-001") |
| | | private String checkCode; |
| | | |
| | | @Schema(description = "æ£æµç»è®º", example = "1") |
| | | private Integer checkResult; |
| | | |
| | | @Schema(description = "æ£æµæ¥æ") |
| | | private LocalDate[] checkDate; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.dv.meteringcheck.vo; |
| | | |
| | | import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; |
| | | import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; |
| | | import cn.iocoder.yudao.module.mes.enums.DictTypeConstants; |
| | | import cn.idev.excel.annotation.ExcelIgnoreUnannotated; |
| | | import cn.idev.excel.annotation.ExcelProperty; |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import lombok.Data; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | |
| | | @Schema(description = "管çåå° - MES è®¡éæ£æµè®°å½ Response VO") |
| | | @Data |
| | | @ExcelIgnoreUnannotated |
| | | public class MesDvMeteringCheckRespVO { |
| | | |
| | | @Schema(description = "ç¼å·", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| | | @ExcelProperty("ç¼å·") |
| | | private Long id; |
| | | |
| | | @Schema(description = "计éå¨å
·ç¼å·", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") |
| | | private Long meteringId; |
| | | |
| | | @Schema(description = "计éå¨å
·ç¼ç ", example = "MD-001") |
| | | @ExcelProperty("计éå¨å
·ç¼ç ") |
| | | private String meteringCode; |
| | | |
| | | @Schema(description = "计éå¨å
·åç§°", example = "æ°æ¾å¡å°º") |
| | | @ExcelProperty("计éå¨å
·åç§°") |
| | | private String meteringName; |
| | | |
| | | @Schema(description = "æ£æµç¼å·", requiredMode = Schema.RequiredMode.REQUIRED, example = "CK-001") |
| | | @ExcelProperty("æ£æµç¼å·") |
| | | private String checkCode; |
| | | |
| | | @Schema(description = "æ£æµæ¥æ", requiredMode = Schema.RequiredMode.REQUIRED) |
| | | @ExcelProperty("æ£æµæ¥æ") |
| | | private LocalDate checkDate; |
| | | |
| | | @Schema(description = "æ£æµæºæ", example = "å¸è®¡éé¢") |
| | | @ExcelProperty("æ£æµæºæ") |
| | | private String checkOrg; |
| | | |
| | | @Schema(description = "æ£æµç»è®º", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| | | @ExcelProperty(value = "æ£æµç»è®º", converter = DictConvert.class) |
| | | @DictFormat(DictTypeConstants.MES_DV_METERING_CHECK_RESULT) |
| | | private Integer checkResult; |
| | | |
| | | @Schema(description = "è¯ä¹¦ç¼å·", example = "CN-2026-001") |
| | | @ExcelProperty("è¯ä¹¦ç¼å·") |
| | | private String certNo; |
| | | |
| | | @Schema(description = "æ£æµäººç¼å·", example = "200") |
| | | private Long checkUserId; |
| | | |
| | | @Schema(description = "æ£æµäººåç§°", example = "æå") |
| | | @ExcelProperty("æ£æµäºº") |
| | | private String checkUserNickname; |
| | | |
| | | @Schema(description = "䏿¬¡æ£æµæ¥æ") |
| | | @ExcelProperty("䏿¬¡æ£æµæ¥æ") |
| | | private LocalDate nextCheckDate; |
| | | |
| | | @Schema(description = "夿³¨", example = "夿³¨") |
| | | @ExcelProperty("夿³¨") |
| | | private String remark; |
| | | |
| | | @Schema(description = "å建æ¶é´", requiredMode = Schema.RequiredMode.REQUIRED) |
| | | @ExcelProperty("å建æ¶é´") |
| | | private LocalDateTime createTime; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.dv.meteringcheck.vo; |
| | | |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | import jakarta.validation.constraints.NotEmpty; |
| | | import jakarta.validation.constraints.NotNull; |
| | | import lombok.Data; |
| | | |
| | | import java.time.LocalDate; |
| | | |
| | | @Schema(description = "管çåå° - MES è®¡éæ£æµè®°å½æ°å¢/ä¿®æ¹ Request VO") |
| | | @Data |
| | | public class MesDvMeteringCheckSaveReqVO { |
| | | |
| | | @Schema(description = "ç¼å·", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| | | private Long id; |
| | | |
| | | @Schema(description = "计éå¨å
·ç¼å·", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") |
| | | @NotNull(message = "计éå¨å
·ä¸è½ä¸ºç©º") |
| | | private Long meteringId; |
| | | |
| | | @Schema(description = "æ£æµç¼å·", requiredMode = Schema.RequiredMode.REQUIRED, example = "CK-001") |
| | | @NotEmpty(message = "æ£æµç¼å·ä¸è½ä¸ºç©º") |
| | | private String checkCode; |
| | | |
| | | @Schema(description = "æ£æµæ¥æ", requiredMode = Schema.RequiredMode.REQUIRED) |
| | | @NotNull(message = "æ£æµæ¥æä¸è½ä¸ºç©º") |
| | | private LocalDate checkDate; |
| | | |
| | | @Schema(description = "æ£æµæºæ", example = "å¸è®¡éé¢") |
| | | private String checkOrg; |
| | | |
| | | @Schema(description = "æ£æµç»è®º", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| | | @NotNull(message = "æ£æµç»è®ºä¸è½ä¸ºç©º") |
| | | private Integer checkResult; |
| | | |
| | | @Schema(description = "è¯ä¹¦ç¼å·", example = "CN-2026-001") |
| | | private String certNo; |
| | | |
| | | @Schema(description = "æ£æµäººç¼å·", example = "200") |
| | | private Long checkUserId; |
| | | |
| | | @Schema(description = "䏿¬¡æ£æµæ¥æï¼ä¸ºç©ºåæ æ£æµæ¥æ + æ ¡å卿 èªå¨è®¡ç®ï¼") |
| | | private LocalDate nextCheckDate; |
| | | |
| | | @Schema(description = "夿³¨", example = "夿³¨") |
| | | private String remark; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.dal.dataobject.dv.metering; |
| | | |
| | | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| | | import cn.iocoder.yudao.module.mes.enums.DictTypeConstants; |
| | | import com.baomidou.mybatisplus.annotation.KeySequence; |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.*; |
| | | |
| | | import java.time.LocalDate; |
| | | |
| | | /** |
| | | * MES 计éå¨å
· DO |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @TableName("mes_dv_metering") |
| | | @KeySequence("mes_dv_metering_seq") // ç¨äº OracleãPostgreSQLãKingbaseãDB2ãH2 æ°æ®åºç主é®èªå¢ãå¦ææ¯ MySQL çæ°æ®åºï¼å¯ä¸åã |
| | | @Data |
| | | @EqualsAndHashCode(callSuper = true) |
| | | @ToString(callSuper = true) |
| | | @Builder |
| | | @NoArgsConstructor |
| | | @AllArgsConstructor |
| | | public class MesDvMeteringDO extends BaseDO { |
| | | |
| | | /** |
| | | * ç¼å· |
| | | */ |
| | | @TableId |
| | | private Long id; |
| | | /** |
| | | * 计éå¨å
·ç¼ç |
| | | */ |
| | | private String code; |
| | | /** |
| | | * 计éå¨å
·åç§° |
| | | */ |
| | | private String name; |
| | | /** |
| | | * è§æ ¼åå· |
| | | */ |
| | | private String specification; |
| | | /** |
| | | * åç/ç产åå®¶ |
| | | */ |
| | | private String brand; |
| | | /** |
| | | * å¨å
·ç±»å« |
| | | * |
| | | * åå
¸ {@link DictTypeConstants#MES_DV_METERING_CATEGORY} |
| | | */ |
| | | private Integer category; |
| | | /** |
| | | * 精度 |
| | | */ |
| | | @TableField("`precision`") |
| | | private String precision; |
| | | /** |
| | | * éç¨ |
| | | */ |
| | | @TableField("`range`") |
| | | private String range; |
| | | /** |
| | | * 使ç¨é¨é¨ç¼å· |
| | | */ |
| | | private Long deptId; |
| | | /** |
| | | * 责任人ç¼å· |
| | | */ |
| | | private Long chargeUserId; |
| | | /** |
| | | * æ ¡åå¨æï¼æï¼ |
| | | */ |
| | | private Integer checkCycleCount; |
| | | /** |
| | | * æå
¥ä½¿ç¨æ¥æ |
| | | */ |
| | | private LocalDate useDate; |
| | | /** |
| | | * 䏿¬¡æ£æµæ¥æ |
| | | */ |
| | | private LocalDate lastCheckDate; |
| | | /** |
| | | * 䏿¬¡æ£æµæ¥æï¼å°ææ¥ï¼ |
| | | */ |
| | | private LocalDate nextCheckDate; |
| | | /** |
| | | * ç¶æ |
| | | * |
| | | * åå
¸ {@link DictTypeConstants#MES_DV_METERING_STATUS} |
| | | */ |
| | | private Integer status; |
| | | /** |
| | | * 夿³¨ |
| | | */ |
| | | private String remark; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.dal.dataobject.dv.meteringcheck; |
| | | |
| | | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| | | import cn.iocoder.yudao.module.mes.enums.DictTypeConstants; |
| | | import com.baomidou.mybatisplus.annotation.KeySequence; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.*; |
| | | |
| | | import java.time.LocalDate; |
| | | |
| | | /** |
| | | * MES è®¡éæ£æµè®°å½ DO |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @TableName("mes_dv_metering_check") |
| | | @KeySequence("mes_dv_metering_check_seq") // ç¨äº OracleãPostgreSQLãKingbaseãDB2ãH2 æ°æ®åºç主é®èªå¢ãå¦ææ¯ MySQL çæ°æ®åºï¼å¯ä¸åã |
| | | @Data |
| | | @EqualsAndHashCode(callSuper = true) |
| | | @ToString(callSuper = true) |
| | | @Builder |
| | | @NoArgsConstructor |
| | | @AllArgsConstructor |
| | | public class MesDvMeteringCheckDO extends BaseDO { |
| | | |
| | | /** |
| | | * ç¼å· |
| | | */ |
| | | @TableId |
| | | private Long id; |
| | | /** |
| | | * 计éå¨å
·ç¼å· |
| | | * |
| | | * å
³è {@link cn.iocoder.yudao.module.mes.dal.dataobject.dv.metering.MesDvMeteringDO#getId()} |
| | | */ |
| | | private Long meteringId; |
| | | /** |
| | | * æ£æµç¼å· |
| | | */ |
| | | private String checkCode; |
| | | /** |
| | | * æ£æµæ¥æ |
| | | */ |
| | | private LocalDate checkDate; |
| | | /** |
| | | * æ£æµæºæ |
| | | */ |
| | | private String checkOrg; |
| | | /** |
| | | * æ£æµç»è®º |
| | | * |
| | | * åå
¸ {@link DictTypeConstants#MES_DV_METERING_CHECK_RESULT} |
| | | */ |
| | | private Integer checkResult; |
| | | /** |
| | | * è¯ä¹¦ç¼å· |
| | | */ |
| | | private String certNo; |
| | | /** |
| | | * æ£æµäººç¼å· |
| | | */ |
| | | private Long checkUserId; |
| | | /** |
| | | * 䏿¬¡æ£æµæ¥æï¼èªå¨è®¡ç®ææå¨æå®ï¼ |
| | | */ |
| | | private LocalDate nextCheckDate; |
| | | /** |
| | | * 夿³¨ |
| | | */ |
| | | private String remark; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.dal.mysql.dv.metering; |
| | | |
| | | 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.dv.metering.vo.MesDvMeteringPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.dv.metering.MesDvMeteringDO; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * MES 计éå¨å
· Mapper |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @Mapper |
| | | public interface MesDvMeteringMapper extends BaseMapperX<MesDvMeteringDO> { |
| | | |
| | | default PageResult<MesDvMeteringDO> selectPage(MesDvMeteringPageReqVO reqVO) { |
| | | return selectPage(reqVO, new LambdaQueryWrapperX<MesDvMeteringDO>() |
| | | .likeIfPresent(MesDvMeteringDO::getCode, reqVO.getCode()) |
| | | .likeIfPresent(MesDvMeteringDO::getName, reqVO.getName()) |
| | | .likeIfPresent(MesDvMeteringDO::getBrand, reqVO.getBrand()) |
| | | .eqIfPresent(MesDvMeteringDO::getCategory, reqVO.getCategory()) |
| | | .eqIfPresent(MesDvMeteringDO::getDeptId, reqVO.getDeptId()) |
| | | .eqIfPresent(MesDvMeteringDO::getChargeUserId, reqVO.getChargeUserId()) |
| | | .eqIfPresent(MesDvMeteringDO::getStatus, reqVO.getStatus()) |
| | | .geIfPresent(MesDvMeteringDO::getNextCheckDate, reqVO.getNextCheckDateBegin()) |
| | | .leIfPresent(MesDvMeteringDO::getNextCheckDate, reqVO.getNextCheckDateEnd()) |
| | | .orderByDesc(MesDvMeteringDO::getId)); |
| | | } |
| | | |
| | | default MesDvMeteringDO selectByCode(String code) { |
| | | return selectOne(MesDvMeteringDO::getCode, code); |
| | | } |
| | | |
| | | default List<MesDvMeteringDO> selectListByNextCheckDateBetween(LocalDate begin, LocalDate end) { |
| | | return selectList(new LambdaQueryWrapperX<MesDvMeteringDO>() |
| | | .ge(MesDvMeteringDO::getNextCheckDate, begin) |
| | | .le(MesDvMeteringDO::getNextCheckDate, end)); |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.dal.mysql.dv.meteringcheck; |
| | | |
| | | 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.dv.meteringcheck.vo.MesDvMeteringCheckPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.dv.meteringcheck.MesDvMeteringCheckDO; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | /** |
| | | * MES è®¡éæ£æµè®°å½ Mapper |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @Mapper |
| | | public interface MesDvMeteringCheckMapper extends BaseMapperX<MesDvMeteringCheckDO> { |
| | | |
| | | default PageResult<MesDvMeteringCheckDO> selectPage(MesDvMeteringCheckPageReqVO reqVO) { |
| | | return selectPage(reqVO, new LambdaQueryWrapperX<MesDvMeteringCheckDO>() |
| | | .eqIfPresent(MesDvMeteringCheckDO::getMeteringId, reqVO.getMeteringId()) |
| | | .likeIfPresent(MesDvMeteringCheckDO::getCheckCode, reqVO.getCheckCode()) |
| | | .eqIfPresent(MesDvMeteringCheckDO::getCheckResult, reqVO.getCheckResult()) |
| | | .betweenIfPresent(MesDvMeteringCheckDO::getCheckDate, reqVO.getCheckDate()) |
| | | .orderByDesc(MesDvMeteringCheckDO::getId)); |
| | | } |
| | | |
| | | default MesDvMeteringCheckDO selectByCheckCode(String checkCode) { |
| | | return selectOne(MesDvMeteringCheckDO::getCheckCode, checkCode); |
| | | } |
| | | |
| | | default MesDvMeteringCheckDO selectLatestByMeteringId(Long meteringId) { |
| | | return selectOne(new LambdaQueryWrapperX<MesDvMeteringCheckDO>() |
| | | .eq(MesDvMeteringCheckDO::getMeteringId, meteringId) |
| | | .orderByDesc(MesDvMeteringCheckDO::getCheckDate) |
| | | .orderByDesc(MesDvMeteringCheckDO::getId) |
| | | .last("LIMIT 1")); |
| | | } |
| | | |
| | | default Long selectCountByMeteringId(Long meteringId) { |
| | | return selectCount(MesDvMeteringCheckDO::getMeteringId, meteringId); |
| | | } |
| | | |
| | | } |
| | |
| | | */ |
| | | String AUTO_CODE = "mes:md:auto_code:"; |
| | | |
| | | /** |
| | | * 计éå¨å
·å°ææéå»é |
| | | * |
| | | * KEY æ ¼å¼ï¼mes:dv:metering:remind:{meteringId}:{nextCheckDate} |
| | | * VALUE æ°æ®æ ¼å¼ï¼1 |
| | | */ |
| | | String METERING_EXPIRE_REMIND = "mes:dv:metering:remind:"; |
| | | |
| | | /** |
| | | * 计éå¨å
·å°ææéæ«æé¨é© |
| | | * |
| | | * KEY æ ¼å¼ï¼mes:dv:metering:remind:scan:{today} |
| | | * VALUE æ°æ®æ ¼å¼ï¼1 |
| | | */ |
| | | String METERING_EXPIRE_REMIND_SCAN = "mes:dv:metering:remind:scan:"; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.dal.redis.dv.metering; |
| | | |
| | | import cn.iocoder.yudao.module.mes.dal.redis.RedisKeyConstants; |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.data.redis.core.StringRedisTemplate; |
| | | import org.springframework.stereotype.Repository; |
| | | |
| | | import java.time.Duration; |
| | | import java.time.LocalDate; |
| | | |
| | | /** |
| | | * MES 计éå¨å
·å°ææé Redis DAO |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @Repository |
| | | public class MesDvMeteringRemindRedisDAO { |
| | | |
| | | /** |
| | | * æéå»é KEY çè¿ææ¶é´ï¼60 天ï¼ï¼åä¸å¨å
·åä¸å°ææ¥ 60 天å
åªæé䏿¬¡ |
| | | */ |
| | | private static final Duration REMIND_TIMEOUT = Duration.ofDays(60); |
| | | /** |
| | | * æ«æé¨é©çè¿ææ¶é´ï¼30 åéï¼ï¼é¿å
å¤å®ä¾/夿¬¡å¹¶åé夿«æ |
| | | */ |
| | | private static final Duration SCAN_LOCK_TIMEOUT = Duration.ofMinutes(30); |
| | | |
| | | @Resource |
| | | private StringRedisTemplate stringRedisTemplate; |
| | | |
| | | /** |
| | | * å°è¯æ è®°å·²æéï¼åä¸å¨å
·åä¸å°ææ¥ 60 天å
åªæé䏿¬¡ï¼ |
| | | * |
| | | * @param meteringId 计éå¨å
·ç¼å· |
| | | * @param nextCheckDate å°ææ¥ |
| | | * @return true è¡¨ç¤ºé¦æ¬¡æ è®°æåï¼éè¦åéæé |
| | | */ |
| | | public boolean tryMarkReminded(Long meteringId, LocalDate nextCheckDate) { |
| | | String key = RedisKeyConstants.METERING_EXPIRE_REMIND + meteringId + ":" + nextCheckDate; |
| | | return Boolean.TRUE.equals(stringRedisTemplate.opsForValue().setIfAbsent(key, "1", REMIND_TIMEOUT)); |
| | | } |
| | | |
| | | /** |
| | | * å°è¯è·åå½å¤©çæ«æé¨é©ï¼é¿å
å¤å®ä¾å¹¶åé夿«æ |
| | | * |
| | | * @param today å½å¤©æ¥æ |
| | | * @return true 表示è·åæåï¼å¯ä»¥æ§è¡æ«æï¼ |
| | | */ |
| | | public boolean tryAcquireScanLock(LocalDate today) { |
| | | String key = RedisKeyConstants.METERING_EXPIRE_REMIND_SCAN + today; |
| | | return Boolean.TRUE.equals(stringRedisTemplate.opsForValue().setIfAbsent(key, "1", SCAN_LOCK_TIMEOUT)); |
| | | } |
| | | |
| | | } |
| | |
| | | String MES_DV_CHECK_RESULT = "mes_dv_check_result"; // MES ç¹æ£ç»æ |
| | | String MES_DV_REPAIR_STATUS = "mes_dv_repair_status"; // MES 维修工åç¶æ |
| | | String MES_DV_REPAIR_RESULT = "mes_dv_repair_result"; // MES ç»´ä¿®ç»æ |
| | | String MES_DV_METERING_CATEGORY = "mes_dv_metering_category"; // MES 计éå¨å
·ç±»å« |
| | | String MES_DV_METERING_STATUS = "mes_dv_metering_status"; // MES 计éå¨å
·ç¶æ |
| | | String MES_DV_METERING_CHECK_RESULT = "mes_dv_metering_check_result"; // MES è®¡éæ£æµç»è®º |
| | | |
| | | // ========== æçæ¥å (CAL) ========== |
| | | String MES_CAL_HOLIDAY_TYPE = "mes_cal_holiday_type"; // MES åæç±»å |
| | |
| | | // ========== MES 设å¤ç®¡ç-ç¹æ£è®°å½æç»ï¼1-040-306-100ï¼ ========== |
| | | ErrorCode DV_CHECK_RECORD_LINE_NOT_EXISTS = new ErrorCode(1_040_306_100, "设å¤ç¹æ£è®°å½æç»ä¸åå¨"); |
| | | |
| | | // ========== MES 设å¤ç®¡ç-计éå¨å
·ï¼1-040-307-000ï¼ ========== |
| | | ErrorCode DV_METERING_NOT_EXISTS = new ErrorCode(1_040_307_000, "计éå¨å
·ä¸åå¨"); |
| | | ErrorCode DV_METERING_CODE_DUPLICATE = new ErrorCode(1_040_307_001, "计éå¨å
·ç¼ç å·²åå¨"); |
| | | ErrorCode DV_METERING_HAS_CHECK_RECORD = new ErrorCode(1_040_307_002, "计éå¨å
·å·²å
³èæ£æµè®°å½ï¼æ æ³å é¤"); |
| | | |
| | | // ========== MES 设å¤ç®¡ç-è®¡éæ£æµè®°å½ï¼1-040-307-100ï¼ ========== |
| | | ErrorCode DV_METERING_CHECK_NOT_EXISTS = new ErrorCode(1_040_307_100, "è®¡éæ£æµè®°å½ä¸åå¨"); |
| | | ErrorCode DV_METERING_CHECK_CODE_DUPLICATE = new ErrorCode(1_040_307_101, "è®¡éæ£æµç¼å·å·²åå¨"); |
| | | |
| | | // ========== MES å·¥å
·ç®¡ç-å·¥å
·ç±»åï¼1-040-400-000ï¼ ========== |
| | | ErrorCode TM_TOOL_TYPE_NOT_EXISTS = new ErrorCode(1_040_400_000, "å·¥å
·ç±»åä¸åå¨"); |
| | | ErrorCode TM_TOOL_TYPE_CODE_DUPLICATE = new ErrorCode(1_040_400_001, "å·¥å
·ç±»åç¼ç å·²åå¨"); |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.enums.dv; |
| | | |
| | | import cn.iocoder.yudao.framework.common.core.ArrayValuable; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Getter; |
| | | |
| | | import java.util.Arrays; |
| | | |
| | | /** |
| | | * MES è®¡éæ£æµç»è®ºæä¸¾ |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @Getter |
| | | @AllArgsConstructor |
| | | public enum MesDvMeteringCheckResultEnum implements ArrayValuable<Integer> { |
| | | |
| | | QUALIFIED(1, "åæ ¼"), |
| | | UNQUALIFIED(2, "ä¸åæ ¼"); |
| | | |
| | | public static final Integer[] ARRAYS = Arrays.stream(values()).map(MesDvMeteringCheckResultEnum::getResult).toArray(Integer[]::new); |
| | | |
| | | /** |
| | | * ç»è®ºå¼ |
| | | */ |
| | | private final Integer result; |
| | | /** |
| | | * ç»è®ºå |
| | | */ |
| | | private final String name; |
| | | |
| | | @Override |
| | | public Integer[] array() { |
| | | return ARRAYS; |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.enums.dv; |
| | | |
| | | import cn.iocoder.yudao.framework.common.core.ArrayValuable; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Getter; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.Arrays; |
| | | |
| | | /** |
| | | * MES 计éå¨å
·å°æç¶ææä¸¾ |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @Getter |
| | | @AllArgsConstructor |
| | | public enum MesDvMeteringExpireStatusEnum implements ArrayValuable<Integer> { |
| | | |
| | | OVERDUE(1, "å·²è¿æ"), |
| | | WITHIN(2, "å³å°å°æ"), |
| | | NORMAL(3, "æ£å¸¸"); |
| | | |
| | | public static final Integer[] ARRAYS = Arrays.stream(values()).map(MesDvMeteringExpireStatusEnum::getStatus).toArray(Integer[]::new); |
| | | |
| | | /** |
| | | * ç¶æå¼ |
| | | */ |
| | | private final Integer status; |
| | | /** |
| | | * ç¶æå |
| | | */ |
| | | private final String name; |
| | | |
| | | /** |
| | | * 计ç®å°æç¶æ |
| | | * |
| | | * @param nextCheckDate 䏿¬¡æ£æµæ¥æï¼å°ææ¥ï¼ |
| | | * @param remindDays æåæéå¤©æ° |
| | | * @return å°æç¶æ |
| | | */ |
| | | public static Integer compute(LocalDate nextCheckDate, int remindDays) { |
| | | if (nextCheckDate == null) { |
| | | return NORMAL.getStatus(); |
| | | } |
| | | long days = ChronoUnit.DAYS.between(LocalDate.now(), nextCheckDate); |
| | | if (days < 0) { |
| | | return OVERDUE.getStatus(); |
| | | } |
| | | if (days <= remindDays) { |
| | | return WITHIN.getStatus(); |
| | | } |
| | | return NORMAL.getStatus(); |
| | | } |
| | | |
| | | @Override |
| | | public Integer[] array() { |
| | | return ARRAYS; |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.enums.dv; |
| | | |
| | | import cn.iocoder.yudao.framework.common.core.ArrayValuable; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Getter; |
| | | |
| | | import java.util.Arrays; |
| | | |
| | | /** |
| | | * MES 计éå¨å
·ç¶ææä¸¾ |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @Getter |
| | | @AllArgsConstructor |
| | | public enum MesDvMeteringStatusEnum implements ArrayValuable<Integer> { |
| | | |
| | | IN_USE(1, "å¨ç¨"), |
| | | STOPPED(2, "åç¨"), |
| | | SCRAPPED(3, "æ¥åº"); |
| | | |
| | | public static final Integer[] ARRAYS = Arrays.stream(values()).map(MesDvMeteringStatusEnum::getStatus).toArray(Integer[]::new); |
| | | |
| | | /** |
| | | * ç¶æå¼ |
| | | */ |
| | | private final Integer status; |
| | | /** |
| | | * ç¶æå |
| | | */ |
| | | private final String name; |
| | | |
| | | @Override |
| | | public Integer[] array() { |
| | | return ARRAYS; |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.service.dv.metering; |
| | | |
| | | /** |
| | | * MES 计éå¨å
·å°ææé Service æ¥å£ |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | public interface MesDvMeteringRemindService { |
| | | |
| | | /** |
| | | * åéå°ææéç«å
ä¿¡ï¼æè§¦åï¼å¹çï¼ |
| | | * |
| | | * å¨è®¡éå¨å
·å页æ¥è¯¢æ¶è§¦åï¼å
æ¢å½å¤©æ«æé¨é©ï¼åæ¥å°æå¨å
·ï¼æå¨å
·+å°ææ¥å»éåéå°åç«å
ä¿¡ã |
| | | */ |
| | | void sendExpireRemind(); |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.service.dv.metering; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.iocoder.yudao.module.infra.api.config.ConfigApi; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.dv.metering.MesDvMeteringDO; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.dv.metering.MesDvMeteringMapper; |
| | | import cn.iocoder.yudao.module.mes.dal.redis.dv.metering.MesDvMeteringRemindRedisDAO; |
| | | import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi; |
| | | import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO; |
| | | import jakarta.annotation.Resource; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * MES 计éå¨å
·å°ææé Service å®ç°ç±» |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class MesDvMeteringRemindServiceImpl implements MesDvMeteringRemindService { |
| | | |
| | | /** |
| | | * æé天æ°é
ç½® KEYï¼infra_configï¼ |
| | | */ |
| | | private static final String REMIND_DAYS_CONFIG_KEY = "mes.dv-metering.remind-days"; |
| | | /** |
| | | * æé天æ°é»è®¤å¼ |
| | | */ |
| | | private static final int DEFAULT_REMIND_DAYS = 30; |
| | | /** |
| | | * å°ææéç«å
信模æ¿ç¼å· |
| | | */ |
| | | private static final String REMIND_TEMPLATE_CODE = "mes_metering_expire_remind"; |
| | | |
| | | @Resource |
| | | private MesDvMeteringMapper meteringMapper; |
| | | @Resource |
| | | private MesDvMeteringRemindRedisDAO meteringRemindRedisDAO; |
| | | @Resource |
| | | private ConfigApi configApi; |
| | | @Resource |
| | | private NotifyMessageSendApi notifyMessageSendApi; |
| | | |
| | | @Override |
| | | public void sendExpireRemind() { |
| | | try { |
| | | // 1. æ¢å½å¤©æ«æé¨é©ï¼é¿å
å¤å®ä¾/夿¬¡å¹¶åé夿«æ |
| | | LocalDate today = LocalDate.now(); |
| | | if (!meteringRemindRedisDAO.tryAcquireScanLock(today)) { |
| | | return; |
| | | } |
| | | // 2. 读åæé天æ°ï¼é»è®¤ 30ï¼ |
| | | int remindDays = getRemindDays(); |
| | | // 3. æ¥è¯¢ [today, today + remindDays] å°æçå¨å
· |
| | | List<MesDvMeteringDO> list = meteringMapper.selectListByNextCheckDateBetween( |
| | | today, today.plusDays(remindDays)); |
| | | // 4. éå°åéç«å
ä¿¡ï¼æå¨å
· + å°ææ¥å»éï¼ |
| | | for (MesDvMeteringDO metering : list) { |
| | | if (metering.getChargeUserId() == null || metering.getNextCheckDate() == null) { |
| | | continue; |
| | | } |
| | | if (!meteringRemindRedisDAO.tryMarkReminded(metering.getId(), metering.getNextCheckDate())) { |
| | | continue; |
| | | } |
| | | sendRemindMessage(metering); |
| | | } |
| | | } catch (Exception ex) { |
| | | // best-effortï¼æé失败ä¸å½±åå表æ¥è¯¢ |
| | | log.error("[sendExpireRemind][åé计éå¨å
·å°ææé失败]", ex); |
| | | } |
| | | } |
| | | |
| | | private int getRemindDays() { |
| | | String value = configApi.getConfigValueByKey(REMIND_DAYS_CONFIG_KEY); |
| | | if (StrUtil.isBlank(value)) { |
| | | return DEFAULT_REMIND_DAYS; |
| | | } |
| | | try { |
| | | return Integer.parseInt(value.trim()); |
| | | } catch (NumberFormatException ex) { |
| | | log.warn("[getRemindDays][é
ç½® {} çå¼ {} éæ³ï¼ä½¿ç¨é»è®¤å¼ {}]", REMIND_DAYS_CONFIG_KEY, value, DEFAULT_REMIND_DAYS); |
| | | return DEFAULT_REMIND_DAYS; |
| | | } |
| | | } |
| | | |
| | | private void sendRemindMessage(MesDvMeteringDO metering) { |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("meteringCode", metering.getCode()); |
| | | params.put("meteringName", metering.getName()); |
| | | params.put("nextCheckDate", metering.getNextCheckDate().toString()); |
| | | NotifySendSingleToUserReqDTO reqDTO = new NotifySendSingleToUserReqDTO() |
| | | .setUserId(metering.getChargeUserId()) |
| | | .setTemplateCode(REMIND_TEMPLATE_CODE) |
| | | .setTemplateParams(params); |
| | | notifyMessageSendApi.sendSingleMessageToAdmin(reqDTO); |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.service.dv.metering; |
| | | |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.metering.vo.MesDvMeteringPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.metering.vo.MesDvMeteringSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.dv.metering.MesDvMeteringDO; |
| | | import jakarta.validation.Valid; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.util.Collection; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; |
| | | |
| | | /** |
| | | * MES 计éå¨å
· Service æ¥å£ |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | public interface MesDvMeteringService { |
| | | |
| | | /** |
| | | * å建计éå¨å
· |
| | | * |
| | | * @param createReqVO åå»ºä¿¡æ¯ |
| | | * @return ç¼å· |
| | | */ |
| | | Long createMetering(@Valid MesDvMeteringSaveReqVO createReqVO); |
| | | |
| | | /** |
| | | * æ´æ°è®¡éå¨å
· |
| | | * |
| | | * @param updateReqVO æ´æ°ä¿¡æ¯ |
| | | */ |
| | | void updateMetering(@Valid MesDvMeteringSaveReqVO updateReqVO); |
| | | |
| | | /** |
| | | * å é¤è®¡éå¨å
· |
| | | * |
| | | * @param id ç¼å· |
| | | */ |
| | | void deleteMetering(Long id); |
| | | |
| | | /** |
| | | * è·å¾è®¡éå¨å
· |
| | | * |
| | | * @param id ç¼å· |
| | | * @return 计éå¨å
· |
| | | */ |
| | | MesDvMeteringDO getMetering(Long id); |
| | | |
| | | /** |
| | | * è·å¾è®¡éå¨å
·å页 |
| | | * |
| | | * @param pageReqVO å页æ¥è¯¢ |
| | | * @return 计éå¨å
·å页 |
| | | */ |
| | | PageResult<MesDvMeteringDO> getMeteringPage(MesDvMeteringPageReqVO pageReqVO); |
| | | |
| | | /** |
| | | * è·å¾è®¡éå¨å
·å表 |
| | | * |
| | | * @return 计éå¨å
·å表 |
| | | */ |
| | | List<MesDvMeteringDO> getMeteringList(); |
| | | |
| | | /** |
| | | * è·å¾è®¡éå¨å
·å表 |
| | | * |
| | | * @param ids ç¼å·æ°ç» |
| | | * @return 计éå¨å
·å表 |
| | | */ |
| | | List<MesDvMeteringDO> getMeteringList(Collection<Long> ids); |
| | | |
| | | /** |
| | | * è·å¾è®¡éå¨å
· Map |
| | | * |
| | | * @param ids ç¼å·æ°ç» |
| | | * @return 计éå¨å
· Map |
| | | */ |
| | | default Map<Long, MesDvMeteringDO> getMeteringMap(Collection<Long> ids) { |
| | | return convertMap(getMeteringList(ids), MesDvMeteringDO::getId); |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªè®¡éå¨å
·åå¨ |
| | | * |
| | | * @param id ç¼å· |
| | | */ |
| | | void validateMeteringExists(Long id); |
| | | |
| | | /** |
| | | * è·å¾å°ææé天æ°ï¼é»è®¤ 30ï¼ |
| | | * |
| | | * @return æéå¤©æ° |
| | | */ |
| | | int getRemindDays(); |
| | | |
| | | /** |
| | | * åå计éå¨å
·çæè¿æ£æµä¿¡æ¯ï¼æ£æµè®°å½æ°å¢/ä¿®æ¹/å é¤åè°ç¨ï¼ |
| | | * |
| | | * @param meteringId 计éå¨å
·ç¼å· |
| | | * @param lastCheckDate æè¿æ£æµæ¥æï¼æ åç½®ç©ºï¼ |
| | | * @param nextCheckDate 䏿¬¡æ£æµæ¥æï¼æ åç½®ç©ºï¼ |
| | | */ |
| | | void updateMeteringCheckInfo(Long meteringId, LocalDate lastCheckDate, LocalDate nextCheckDate); |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.service.dv.metering; |
| | | |
| | | 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.infra.api.config.ConfigApi; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.metering.vo.MesDvMeteringPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.metering.vo.MesDvMeteringSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.dv.metering.MesDvMeteringDO; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.dv.metering.MesDvMeteringMapper; |
| | | import cn.iocoder.yudao.module.mes.service.dv.meteringcheck.MesDvMeteringCheckService; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.util.Collection; |
| | | 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.DV_METERING_CODE_DUPLICATE; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.DV_METERING_HAS_CHECK_RECORD; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.DV_METERING_NOT_EXISTS; |
| | | |
| | | /** |
| | | * MES 计éå¨å
· Service å®ç°ç±» |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @Service |
| | | @Validated |
| | | public class MesDvMeteringServiceImpl implements MesDvMeteringService { |
| | | |
| | | /** |
| | | * æé天æ°é
ç½® KEYï¼infra_configï¼ |
| | | */ |
| | | private static final String REMIND_DAYS_CONFIG_KEY = "mes.dv-metering.remind-days"; |
| | | /** |
| | | * æé天æ°é»è®¤å¼ |
| | | */ |
| | | private static final int DEFAULT_REMIND_DAYS = 30; |
| | | |
| | | @Resource |
| | | private MesDvMeteringMapper meteringMapper; |
| | | @Resource |
| | | @Lazy // å»¶è¿å è½½ï¼é¿å
ä¸è®¡éæ£æµè®°å½ Service 循ç¯ä¾èµ |
| | | private MesDvMeteringCheckService meteringCheckService; |
| | | @Resource |
| | | private MesDvMeteringRemindService meteringRemindService; |
| | | @Resource |
| | | private ConfigApi configApi; |
| | | |
| | | @Override |
| | | public Long createMetering(MesDvMeteringSaveReqVO createReqVO) { |
| | | // æ ¡éªç¼ç å¯ä¸ |
| | | validateMeteringCodeUnique(null, createReqVO.getCode()); |
| | | |
| | | // æå
¥ |
| | | MesDvMeteringDO metering = BeanUtils.toBean(createReqVO, MesDvMeteringDO.class); |
| | | meteringMapper.insert(metering); |
| | | return metering.getId(); |
| | | } |
| | | |
| | | @Override |
| | | public void updateMetering(MesDvMeteringSaveReqVO updateReqVO) { |
| | | // æ ¡éªåå¨ |
| | | validateMeteringExists(updateReqVO.getId()); |
| | | // æ ¡éªç¼ç å¯ä¸ |
| | | validateMeteringCodeUnique(updateReqVO.getId(), updateReqVO.getCode()); |
| | | |
| | | // æ´æ° |
| | | MesDvMeteringDO updateObj = BeanUtils.toBean(updateReqVO, MesDvMeteringDO.class); |
| | | meteringMapper.updateById(updateObj); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteMetering(Long id) { |
| | | // æ ¡éªåå¨ |
| | | validateMeteringExists(id); |
| | | // æ ¡éªæ å
³èæ£æµè®°å½ |
| | | if (meteringCheckService.getMeteringCheckCountByMeteringId(id) > 0) { |
| | | throw exception(DV_METERING_HAS_CHECK_RECORD); |
| | | } |
| | | |
| | | // å é¤ |
| | | meteringMapper.deleteById(id); |
| | | } |
| | | |
| | | @Override |
| | | public void validateMeteringExists(Long id) { |
| | | if (meteringMapper.selectById(id) == null) { |
| | | throw exception(DV_METERING_NOT_EXISTS); |
| | | } |
| | | } |
| | | |
| | | private void validateMeteringCodeUnique(Long id, String code) { |
| | | if (StrUtil.isBlank(code)) { |
| | | return; |
| | | } |
| | | MesDvMeteringDO metering = meteringMapper.selectByCode(code); |
| | | if (metering == null) { |
| | | return; |
| | | } |
| | | if (ObjUtil.notEqual(metering.getId(), id)) { |
| | | throw exception(DV_METERING_CODE_DUPLICATE); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public MesDvMeteringDO getMetering(Long id) { |
| | | return meteringMapper.selectById(id); |
| | | } |
| | | |
| | | @Override |
| | | public PageResult<MesDvMeteringDO> getMeteringPage(MesDvMeteringPageReqVO pageReqVO) { |
| | | // 1. å°æç¶æè½¬æ¢ä¸ºæ¥æèå´ï¼èµ° DB è¿æ»¤ |
| | | Integer expireStatus = pageReqVO.getExpireStatus(); |
| | | if (expireStatus != null) { |
| | | LocalDate today = LocalDate.now(); |
| | | int remindDays = getRemindDays(); |
| | | switch (expireStatus) { |
| | | case 1 -> { // å·²è¿æï¼å°ææ¥ < ä»å¤© |
| | | pageReqVO.setNextCheckDateEnd(today.minusDays(1)); |
| | | } |
| | | case 2 -> { // å³å°å°æï¼å°ææ¥å¨ [ä»å¤©, ä»å¤©+æé天æ°] |
| | | pageReqVO.setNextCheckDateBegin(today); |
| | | pageReqVO.setNextCheckDateEnd(today.plusDays(remindDays)); |
| | | } |
| | | case 3 -> { // æ£å¸¸ï¼å°ææ¥ > ä»å¤©+æéå¤©æ° |
| | | pageReqVO.setNextCheckDateBegin(today.plusDays(remindDays + 1)); |
| | | } |
| | | default -> { |
| | | } |
| | | } |
| | | } |
| | | // 2. æ¥è¯¢ |
| | | PageResult<MesDvMeteringDO> pageResult = meteringMapper.selectPage(pageReqVO); |
| | | // 3. æè§¦åå°ææéç«å
ä¿¡ï¼best-effortï¼ä¸å½±åæ¥è¯¢ï¼ |
| | | meteringRemindService.sendExpireRemind(); |
| | | return pageResult; |
| | | } |
| | | |
| | | @Override |
| | | public int getRemindDays() { |
| | | String value = configApi.getConfigValueByKey(REMIND_DAYS_CONFIG_KEY); |
| | | if (StrUtil.isBlank(value)) { |
| | | return DEFAULT_REMIND_DAYS; |
| | | } |
| | | try { |
| | | return Integer.parseInt(value.trim()); |
| | | } catch (NumberFormatException ex) { |
| | | return DEFAULT_REMIND_DAYS; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void updateMeteringCheckInfo(Long meteringId, LocalDate lastCheckDate, LocalDate nextCheckDate) { |
| | | meteringMapper.updateById(new MesDvMeteringDO() |
| | | .setId(meteringId) |
| | | .setLastCheckDate(lastCheckDate) |
| | | .setNextCheckDate(nextCheckDate)); |
| | | } |
| | | |
| | | @Override |
| | | public List<MesDvMeteringDO> getMeteringList() { |
| | | return meteringMapper.selectList(); |
| | | } |
| | | |
| | | @Override |
| | | public List<MesDvMeteringDO> getMeteringList(Collection<Long> ids) { |
| | | if (CollUtil.isEmpty(ids)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | return meteringMapper.selectByIds(ids); |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.service.dv.meteringcheck; |
| | | |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.meteringcheck.vo.MesDvMeteringCheckPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.meteringcheck.vo.MesDvMeteringCheckSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.dv.meteringcheck.MesDvMeteringCheckDO; |
| | | import jakarta.validation.Valid; |
| | | |
| | | /** |
| | | * MES è®¡éæ£æµè®°å½ Service æ¥å£ |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | public interface MesDvMeteringCheckService { |
| | | |
| | | /** |
| | | * åå»ºè®¡éæ£æµè®°å½ |
| | | * |
| | | * @param createReqVO åå»ºä¿¡æ¯ |
| | | * @return ç¼å· |
| | | */ |
| | | Long createMeteringCheck(@Valid MesDvMeteringCheckSaveReqVO createReqVO); |
| | | |
| | | /** |
| | | * æ´æ°è®¡éæ£æµè®°å½ |
| | | * |
| | | * @param updateReqVO æ´æ°ä¿¡æ¯ |
| | | */ |
| | | void updateMeteringCheck(@Valid MesDvMeteringCheckSaveReqVO updateReqVO); |
| | | |
| | | /** |
| | | * å é¤è®¡éæ£æµè®°å½ |
| | | * |
| | | * @param id ç¼å· |
| | | */ |
| | | void deleteMeteringCheck(Long id); |
| | | |
| | | /** |
| | | * è·å¾è®¡éæ£æµè®°å½ |
| | | * |
| | | * @param id ç¼å· |
| | | * @return è®¡éæ£æµè®°å½ |
| | | */ |
| | | MesDvMeteringCheckDO getMeteringCheck(Long id); |
| | | |
| | | /** |
| | | * è·å¾è®¡éæ£æµè®°å½å页 |
| | | * |
| | | * @param pageReqVO å页æ¥è¯¢ |
| | | * @return è®¡éæ£æµè®°å½å页 |
| | | */ |
| | | PageResult<MesDvMeteringCheckDO> getMeteringCheckPage(MesDvMeteringCheckPageReqVO pageReqVO); |
| | | |
| | | /** |
| | | * è·å¾æå®è®¡éå¨å
·ä¸çæ£æµè®°å½æ°é |
| | | * |
| | | * @param meteringId 计éå¨å
·ç¼å· |
| | | * @return æ£æµè®°å½æ°é |
| | | */ |
| | | Long getMeteringCheckCountByMeteringId(Long meteringId); |
| | | |
| | | /** |
| | | * æ ¡éªè®¡éæ£æµè®°å½åå¨ |
| | | * |
| | | * @param id ç¼å· |
| | | */ |
| | | void validateMeteringCheckExists(Long id); |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package cn.iocoder.yudao.module.mes.service.dv.meteringcheck; |
| | | |
| | | 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.object.BeanUtils; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.meteringcheck.vo.MesDvMeteringCheckPageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.dv.meteringcheck.vo.MesDvMeteringCheckSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.dv.metering.MesDvMeteringDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.dv.meteringcheck.MesDvMeteringCheckDO; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.dv.meteringcheck.MesDvMeteringCheckMapper; |
| | | import cn.iocoder.yudao.module.mes.service.dv.metering.MesDvMeteringService; |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.time.LocalDate; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.DV_METERING_CHECK_CODE_DUPLICATE; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.DV_METERING_CHECK_NOT_EXISTS; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.DV_METERING_NOT_EXISTS; |
| | | |
| | | /** |
| | | * MES è®¡éæ£æµè®°å½ Service å®ç°ç±» |
| | | * |
| | | * @author è¶
级管çå |
| | | */ |
| | | @Service |
| | | @Validated |
| | | public class MesDvMeteringCheckServiceImpl implements MesDvMeteringCheckService { |
| | | |
| | | @Resource |
| | | private MesDvMeteringCheckMapper meteringCheckMapper; |
| | | @Resource |
| | | @Lazy // å»¶è¿å è½½ï¼é¿å
ä¸è®¡éå¨å
· Service 循ç¯ä¾èµ |
| | | private MesDvMeteringService meteringService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Long createMeteringCheck(MesDvMeteringCheckSaveReqVO createReqVO) { |
| | | // æ ¡éªè®¡éå¨å
·åå¨ |
| | | MesDvMeteringDO metering = validateMeteringExists(createReqVO.getMeteringId()); |
| | | // æ ¡éªæ£æµç¼å·å¯ä¸ |
| | | validateMeteringCheckCodeUnique(null, createReqVO.getCheckCode()); |
| | | |
| | | // 计ç®ä¸æ¬¡æ£æµæ¥æï¼ä¸ºç©ºåææ ¡å卿èªå¨è®¡ç®ï¼ |
| | | LocalDate nextCheckDate = computeNextCheckDate(createReqVO.getCheckDate(), |
| | | createReqVO.getNextCheckDate(), metering); |
| | | MesDvMeteringCheckDO check = BeanUtils.toBean(createReqVO, MesDvMeteringCheckDO.class); |
| | | check.setNextCheckDate(nextCheckDate); |
| | | meteringCheckMapper.insert(check); |
| | | |
| | | // åå计éå¨å
·çæè¿æ£æµä¿¡æ¯ |
| | | refreshMeteringCheckInfo(createReqVO.getMeteringId()); |
| | | return check.getId(); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateMeteringCheck(MesDvMeteringCheckSaveReqVO updateReqVO) { |
| | | // æ ¡éªåå¨ |
| | | validateMeteringCheckExists(updateReqVO.getId()); |
| | | // æ ¡éªè®¡éå¨å
·åå¨ |
| | | MesDvMeteringDO metering = validateMeteringExists(updateReqVO.getMeteringId()); |
| | | // æ ¡éªæ£æµç¼å·å¯ä¸ |
| | | validateMeteringCheckCodeUnique(updateReqVO.getId(), updateReqVO.getCheckCode()); |
| | | |
| | | // 计ç®ä¸æ¬¡æ£æµæ¥æï¼ä¸ºç©ºåææ ¡å卿èªå¨è®¡ç®ï¼ |
| | | LocalDate nextCheckDate = computeNextCheckDate(updateReqVO.getCheckDate(), |
| | | updateReqVO.getNextCheckDate(), metering); |
| | | MesDvMeteringCheckDO updateObj = BeanUtils.toBean(updateReqVO, MesDvMeteringCheckDO.class); |
| | | updateObj.setNextCheckDate(nextCheckDate); |
| | | meteringCheckMapper.updateById(updateObj); |
| | | |
| | | // åå计éå¨å
·çæè¿æ£æµä¿¡æ¯ |
| | | refreshMeteringCheckInfo(updateReqVO.getMeteringId()); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void deleteMeteringCheck(Long id) { |
| | | // æ ¡éªåå¨ |
| | | validateMeteringCheckExists(id); |
| | | MesDvMeteringCheckDO check = meteringCheckMapper.selectById(id); |
| | | |
| | | // å é¤ |
| | | meteringCheckMapper.deleteById(id); |
| | | |
| | | // åå计éå¨å
·çæè¿æ£æµä¿¡æ¯ |
| | | refreshMeteringCheckInfo(check.getMeteringId()); |
| | | } |
| | | |
| | | @Override |
| | | public MesDvMeteringCheckDO getMeteringCheck(Long id) { |
| | | return meteringCheckMapper.selectById(id); |
| | | } |
| | | |
| | | @Override |
| | | public PageResult<MesDvMeteringCheckDO> getMeteringCheckPage(MesDvMeteringCheckPageReqVO pageReqVO) { |
| | | return meteringCheckMapper.selectPage(pageReqVO); |
| | | } |
| | | |
| | | @Override |
| | | public Long getMeteringCheckCountByMeteringId(Long meteringId) { |
| | | return meteringCheckMapper.selectCountByMeteringId(meteringId); |
| | | } |
| | | |
| | | @Override |
| | | public void validateMeteringCheckExists(Long id) { |
| | | if (meteringCheckMapper.selectById(id) == null) { |
| | | throw exception(DV_METERING_CHECK_NOT_EXISTS); |
| | | } |
| | | } |
| | | |
| | | private MesDvMeteringDO validateMeteringExists(Long meteringId) { |
| | | MesDvMeteringDO metering = meteringService.getMetering(meteringId); |
| | | if (metering == null) { |
| | | throw exception(DV_METERING_NOT_EXISTS); |
| | | } |
| | | return metering; |
| | | } |
| | | |
| | | private void validateMeteringCheckCodeUnique(Long id, String checkCode) { |
| | | if (StrUtil.isBlank(checkCode)) { |
| | | return; |
| | | } |
| | | MesDvMeteringCheckDO check = meteringCheckMapper.selectByCheckCode(checkCode); |
| | | if (check == null) { |
| | | return; |
| | | } |
| | | if (ObjUtil.notEqual(check.getId(), id)) { |
| | | throw exception(DV_METERING_CHECK_CODE_DUPLICATE); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 计ç®ä¸æ¬¡æ£æµæ¥æï¼æå¨æå®ä¼å
ï¼å¦åæ æ£æµæ¥æ + æ ¡åå¨æï¼æï¼èªå¨è®¡ç® |
| | | */ |
| | | private LocalDate computeNextCheckDate(LocalDate checkDate, LocalDate nextCheckDate, MesDvMeteringDO metering) { |
| | | if (nextCheckDate != null) { |
| | | return nextCheckDate; |
| | | } |
| | | if (checkDate != null && metering.getCheckCycleCount() != null) { |
| | | return checkDate.plusMonths(metering.getCheckCycleCount()); |
| | | } |
| | | return nextCheckDate; |
| | | } |
| | | |
| | | /** |
| | | * æ"ææ°ä¸æ¡æ£æµè®°å½"æ´ä½éç®åå计éå¨å
·ï¼æ£ç¡®è¦çç¼è¾éææ°è®°å½/å é¤ä¸é´è®°å½çè¾¹ç |
| | | */ |
| | | private void refreshMeteringCheckInfo(Long meteringId) { |
| | | MesDvMeteringCheckDO latest = meteringCheckMapper.selectLatestByMeteringId(meteringId); |
| | | if (latest == null) { |
| | | meteringService.updateMeteringCheckInfo(meteringId, null, null); |
| | | } else { |
| | | meteringService.updateMeteringCheckInfo(meteringId, |
| | | latest.getCheckDate(), latest.getNextCheckDate()); |
| | | } |
| | | } |
| | | |
| | | } |