gaoluyang
2026-10-18 6e3d8e950e7dec3551bee3512673e1fc2d384d2b
fix(mes): 修复能耗抄表控制器启动时的 bean 名称冲突

- MesEmRecordController 的 MesEmRecordService 字段名为 recordService,
@Resource 会优先按名称注入到 mzt-log 的同名 bean,导致应用启动失败
- 字段重命名为 mesEmRecordService
- 能耗初始化脚本的父菜单改为 upsert,已存在时恢复 deleted=0

Co-Authored-By: Claude Code <noreply@anthropic.com>
已修改2个文件
29 ■■■■■ 文件已修改
sql/mysql/mes_em_energy_init.sql 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/em/record/MesEmRecordController.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
sql/mysql/mes_em_energy_init.sql
@@ -191,6 +191,13 @@
(2, '已处理', '1', 'mes_em_alert_status', 0, 'success', '', '已处理', '1', NOW(), '1', NOW(), b'0');
-- 4. 菜单(父菜单 1065864 能耗管理)
--    该目录可能已被逻辑删除(deleted = b'1'),此时子菜单会因父节点不可见而整棵树都不显示,
--    因此先按主键补插父目录;已存在时仅恢复删除标记,不改动原有名称和路径。
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
(1065864, '能耗管理', '', 1, 16, 0, '/energyManagement', 'monitor', NULL, NULL, 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0')
ON DUPLICATE KEY UPDATE `deleted` = b'0', `status` = 0, `visible` = b'1', `updater` = '1', `update_time` = NOW();
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'),
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/em/record/MesEmRecordController.java
@@ -29,21 +29,25 @@
@Validated
public class MesEmRecordController {
    /**
     * 注意:字段名不能叫 recordService,否则 @Resource 会优先按名称匹配到
     * mzt-log 的 recordService(DefaultLogRecordServiceImpl),导致启动失败。
     */
    @Resource
    private MesEmRecordService recordService;
    private MesEmRecordService mesEmRecordService;
    @PostMapping("/create")
    @Operation(summary = "创建能耗抄表记录")
    @PreAuthorize("@ss.hasPermission('mes:em-record:create')")
    public CommonResult<Long> createRecord(@Valid @RequestBody MesEmRecordSaveReqVO createReqVO) {
        return success(recordService.createRecord(createReqVO));
        return success(mesEmRecordService.createRecord(createReqVO));
    }
    @PutMapping("/update")
    @Operation(summary = "更新能耗抄表记录")
    @PreAuthorize("@ss.hasPermission('mes:em-record:update')")
    public CommonResult<Boolean> updateRecord(@Valid @RequestBody MesEmRecordSaveReqVO updateReqVO) {
        recordService.updateRecord(updateReqVO);
        mesEmRecordService.updateRecord(updateReqVO);
        return success(true);
    }
@@ -52,7 +56,7 @@
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('mes:em-record:delete')")
    public CommonResult<Boolean> deleteRecord(@RequestParam("id") Long id) {
        recordService.deleteRecord(id);
        mesEmRecordService.deleteRecord(id);
        return success(true);
    }
@@ -61,19 +65,19 @@
    @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);
        MesEmRecordDO record = mesEmRecordService.getRecord(id);
        if (record == null) {
            return success(null);
        }
        return success(recordService.getRecordRespVOList(Collections.singletonList(record)).get(0));
        return success(mesEmRecordService.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<MesEmRecordDO> pageResult = mesEmRecordService.getRecordPage(pageReqVO);
        return success(new PageResult<>(mesEmRecordService.getRecordRespVOList(pageResult.getList()),
                pageResult.getTotal()));
    }
@@ -84,7 +88,7 @@
            @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));
        return success(mesEmRecordService.getLastReading(meterId, recordDate, excludeId));
    }
}