双碳管理系统 开发者手册

1. 适用对象与前置知识

本手册面向需要在本系统上做二次开发、功能扩展、缺陷修复的开发人员。阅读前应具备:Java 8 与 Spring Boot 基础、MyBatis 使用经验、Vue 3 与 Element Plus 基础、Maven 与 npm 构建流程。

2. 代码结构

模块二完整项目/
├── 服务端/carbon/                 Maven 多模块后端
│   ├── neu-admin/                 启动模块(含 application.yml)
│   ├── neu-framework/             安全、拦截器、日志、权限
│   ├── neu-system/                用户/角色/菜单/字典
│   ├── neu-quartz/                定时任务
│   ├── neu-generator/             代码生成
│   ├── neu-common/                公共工具与基础类
│   ├── neu-carbon-mapper/         所有 Mapper 接口与 XML、实体
│   ├── neu-carbon-scm/            供应链:采购、销售
│   ├── neu-carbon-mes/            生产执行:建模、计划、作业、质量
│   ├── neu-carbon-wms/            仓储:物料、仓库、出入库、运输
│   ├── neu-carbon-bid/            招投标:招标、企业、投诉、法规
│   ├── neu-carbon-footprint/      双碳:检测点、排放因子、核算
│   └── neu-carbon-report/         报表统计
├── 管理端/管理前端项目vue3/        Vue3 + Vite5 管理后台
├── 招投标网/用户前端项目vue3/      Vue3 用户门户
└── 数据大屏/                       DataV + ECharts 可视化

3. 分层约定

后端严格分层,调用方向单向:

Controller  →  IService  ←  ServiceImpl  →  Mapper  →  数据库
(接口层)    (服务接口)  (业务实现)     (持久层)

4. 新增一个业务功能

以「设备保养记录」为例,完整步骤如下。

4.1 建表

CREATE TABLE mes_equipment_maintain (
  id            BIGINT       NOT NULL AUTO_INCREMENT COMMENT '主键',
  equipment_id  BIGINT       COMMENT '设备ID',
  maintain_date DATE         COMMENT '保养日期',
  maintainer    VARCHAR(64)  COMMENT '保养人',
  content       VARCHAR(500) COMMENT '保养内容',
  status        VARCHAR(2)   DEFAULT '0' COMMENT '状态',
  create_by     VARCHAR(64), create_time DATETIME, update_by VARCHAR(64), update_time DATETIME, remark VARCHAR(500),
  PRIMARY KEY (id)
) COMMENT='设备保养记录';

4.2 生成代码

启动后台 → 系统工具 → 代码生成 → 导入表 → 编辑字段(配置查询/列表/表单)→ 生成。生成包结构:

com.neu.carbon.mes.domain.MesEquipmentMaintain
com.neu.carbon.mes.mapper.MesEquipmentMaintainMapper
com.neu.carbon.mes.service.IMesEquipmentMaintainService
com.neu.carbon.mes.service.impl.MesEquipmentMaintainServiceImpl
com.neu.carbon.mes.controller.MesEquipmentMaintainController

生成后把文件放入对应模块(domain/mapper 放 neu-carbon-mapper,其余放 neu-carbon-mes)。

4.3 补业务

在 ServiceImpl 中补充业务规则,例如保存时校验同一设备同日不可重复:

@Override
public int insertMesEquipmentMaintain(MesEquipmentMaintain entity) {
    if (entity.getEquipmentId() == null || entity.getMaintainDate() == null) {
        throw new CustomException("设备与保养日期不能为空");
    }
    MesEquipmentMaintain q = new MesEquipmentMaintain();
    q.setEquipmentId(entity.getEquipmentId());
    q.setMaintainDate(entity.getMaintainDate());
    if (!mapper.selectMesEquipmentMaintainList(q).isEmpty()) {
        throw new CustomException("该设备当日已存在保养记录");
    }
    return mapper.insertMesEquipmentMaintain(entity);
}

4.4 前端页面与接口

4.5 权限标识

前端按钮用 v-hasPermi="['mes:equipmentMaintain:add']",后端方法用 @PreAuthorize("@ss.hasPermi('mes:equipmentMaintain:add')"),两处必须一致。

5. 编码规范

项 约定
包名 com.neu.carbon.<域>.<层>,域为 scm/mes/wms/bid/footprint/report
类名 实体 域+业务,如 MesEquipment;Controller 加 Controller 后缀
方法名 查询 selectXxxList / selectXxxById,写 insertXxx / updateXxx / deleteXxxByIds
注释 类与公开方法必须有 Javadoc,说明业务含义、参数、返回
异常 业务异常抛 CustomException,由全局处理器转 AjaxResult
事务 只读不加,写操作且跨表时加 @Transactional
日志 写操作加 @Log(title="…", businessType=BusinessType.INSERT)
返回 统一 AjaxResult(单对象)/ TableDataInfo(列表)

6. 构建与运行

6.1 后端

export JAVA_HOME=/path/to/jdk1.8
mvn clean package -DskipTests
java -jar neu-admin/target/carbon.jar
# 端口 9090;数据库密码可在启动时覆盖:
java -jar carbon.jar --spring.datasource.druid.master.password=123456

6.2 前端

cd 管理端/管理前端项目vue3
npm install
npm run dev          # 8081
npm run build:prod   # 产物 dist/

用户端 8082、大屏 8083 同理。

6.3 Nginx

server {
    listen 9025;
    client_max_body_size 2500m;
    root /usr/share/nginx/html/dist-client;
    location / { try_files $uri $uri/ /index.html; }
    location /prod-api/ { proxy_pass http://127.0.0.1:9090/; }
    location = /index.html {
        add_header Cache-Control "no-cache, no-store, must-revalidate";
    }
}

7. 调试与排错

现象 排查方向
登录页验证码不显示 Redis 未启动,或 captcha_codes:* 键过期
列表有数据但页面空白 前端取值字段错误(response.rows 与 response.data 混用)
按钮点击无反应 事件方法名拼写错误,或未定义
接口 403 缺少 Authorization 头,或 @PreAuthorize 权限标识与角色不匹配
导出得到空文件 导出实现只写表头,或查询条件过滤掉了全部数据
提交后状态不流转 前端调用了 updateXxx 而非 submitXxx
页面 404 菜单 path 与前端路由不一致,或组件路径大小写错误

8. 常见二次开发场景

8.1 增加审核节点

  1. 表增加 audit_status、audit_user、audit_time、audit_comment 字段。
  2. ServiceImpl 增加 audit(entity),校验当前状态为「待审核」再更新。
  3. Controller 增加 PUT /xxx/audit。
  4. 前端「我的任务」下新建审核页,列表只查 audit_status=待审核。
  5. 列表页状态列改用字典渲染,未提交行才显示「提交」按钮。

8.2 增加报表

  1. 新建视图(v_xxx)或在 *ReportMapper.xml 写聚合 SQL。
  2. Controller 放在 neu-carbon-report,返回 TableDataInfo。
  3. 导出使用 ExcelUtil.exportExcel,注意大数据量分批。
  4. 前端报表页「查询 + 导出」两按钮,导出走两次请求(先 export 拿文件名,再 download)。

8.3 增加大屏图表

  1. 在 数据大屏/src/views/indexs/ 新建组件,用 echarts.init 挂载。
  2. 接口返回 { categories, series } 结构,前端直接喂给 ECharts。
  3. 定时刷新用 setInterval,组件销毁时 clearInterval。

9. 交付与环境

环境 地址 说明
管理端 http://localhost:8081 开发
用户端 http://localhost:8082 招投标门户
数据大屏 http://localhost:8080 可视化
后端 http://localhost:9090 REST
平台 https://learn.codexm.cn 课程与任务

默认账号 admin / admin123,测试账号 test001 / test001。