news 2026/4/15 13:09:03

easychat项目复盘---管理端

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
easychat项目复盘---管理端

1.保存更新

controller层:

思路如上述图所示:需要版本号,二选一形式(fileType) 若选择外键则outerLink进行接受 然后需要更新内容(因为每次更新必须有所不同,所以更新内容解释不能为空)

@RequestMapping("/saveUpdate") @GlobalInterceptor(checkAdmin = true) public ResponseVO saveUpdate(Integer id, @NotEmpty String version, @NotEmpty String updateDesc, @NotNull Integer fileType, String outerLink, MultipartFile file) throws IOException { AppUpdate appUpdate = new AppUpdate(); appUpdate.setId(id); appUpdate.setVersion(version); appUpdate.setUpdateDesc(updateDesc); appUpdate.setFileType(fileType); appUpdate.setOuterLink(outerLink); appUpdateService.saveUpdate(appUpdate, file); return getSuccessResponseVO(null); }

实现层比较复杂分段讲解:

AppUpdateFileTypeEnum fileTypeEnum = AppUpdateFileTypeEnum.getByType(appUpdate.getFileType()); if (null == fileTypeEnum) { throw new BusinessException(ResponseCodeEnum.CODE_600); } if (appUpdate.getId() != null) { AppUpdate dbInfo = this.getAppUpdateById(appUpdate.getId()); if (!AppUpdateSatusEnum.INIT.getStatus().equals(dbInfo.getStatus())) { throw new BusinessException(ResponseCodeEnum.CODE_600); } }

saveUpdate函数负责两种功能第一负责保存更新内容,第二可以修改未发布的版本信息,常规判断避免接口被攻击,第二个if则意思是只允许修改未发布(INIT状态)的版本,已发布的版本无法修改

思路:获取最新版本,保存新版本的版本号一定要高于往期的所有版本,将所有版本倒序搜索集合成list,再取开头第一个即为最新版本,如何判断大小呢,如图,一般的版本号都是1.0.0 1.0.1 只要把.去掉那就是100 101 那么101大于100 则1.0.1大于1.0.0 下述有两个if 是分别为更新(有id)与创建(无id)的版本判断

AppUpdateQuery updateQuery = new AppUpdateQuery(); updateQuery.setOrderBy("id desc"); updateQuery.setSimplePage(new SimplePage(0, 1)); List<AppUpdate> appUpdateList = appUpdateMapper.selectList(updateQuery); if (!appUpdateList.isEmpty()) { AppUpdate lastest = appUpdateList.get(0); Long dbVersion = Long.parseLong(lastest.getVersion().replace(".", "")); Long currentVersion = Long.parseLong(appUpdate.getVersion().replace(".", "")); if (appUpdate.getId() == null && currentVersion <= dbVersion) { throw new BusinessException("当前版本必须大于历史版本"); } if (appUpdate.getId() != null && currentVersion >= dbVersion && !appUpdate.getId().equals(lastest.getId())) { throw new BusinessException("当前版本必须大于历史版本"); } AppUpdate versionDb = appUpdateMapper.selectByVersion(appUpdate.getVersion()); if (appUpdate.getId() != null && versionDb != null && !versionDb.getId().equals(appUpdate.getId())) { throw new BusinessException("版本号已存在"); } }

随后创建插入,id为自增长主键,若有文件则处理文件路径,保存文件

if (appUpdate.getId() == null) { appUpdate.setCreateTime(new Date()); appUpdate.setStatus(AppUpdateSatusEnum.INIT.getStatus()); appUpdateMapper.insert(appUpdate); } else { appUpdateMapper.updateById(appUpdate, appUpdate.getId()); } if (file != null) { File folder = new File(appConfig.getProjectFolder() + Constants.APP_UPDATE_FOLDER); if (!folder.exists()) { folder.mkdirs(); } file.transferTo(new File(folder.getAbsolutePath() + "/" + appUpdate.getId() + Constants.APP_EXE_SUFFIX)); }

2.删除更新

十分简单不再赘述

@RequestMapping("/delUpdate") @GlobalInterceptor(checkAdmin = true) public ResponseVO delUpdate(@NotNull Integer id) { appUpdateService.deleteAppUpdateById(id); return getSuccessResponseVO(null); }
@Override public Integer deleteAppUpdateById(Integer id) { AppUpdate dbInfo = this.getAppUpdateById(id); if (!AppUpdateSatusEnum.INIT.getStatus().equals(dbInfo.getStatus())) { throw new BusinessException(ResponseCodeEnum.CODE_600); } return this.appUpdateMapper.deleteById(id); }

3.发布更新

@RequestMapping("/postUpdate") @GlobalInterceptor(checkAdmin = true) public ResponseVO postUpdate(@NotNull Integer id, @NotNull Integer status, String grayscaleUid) { appUpdateService.postUpdate(id, status, grayscaleUid); return getSuccessResponseVO(null); }

就是改变数据库的状态,前端接受状态然后向客户端推送

@Override public void postUpdate(Integer id, Integer status, String grayscaleUid) { AppUpdateSatusEnum satusEnum = AppUpdateSatusEnum.getByStatus(status); if (status == null) { throw new BusinessException(ResponseCodeEnum.CODE_600); } if (AppUpdateSatusEnum.GRAYSCALE == satusEnum && StringTools.isEmpty(grayscaleUid)) { throw new BusinessException(ResponseCodeEnum.CODE_600); } if (AppUpdateSatusEnum.GRAYSCALE != satusEnum) { grayscaleUid = ""; } AppUpdate update = new AppUpdate(); update.setStatus(status); update.setGrayscaleUid(grayscaleUid); appUpdateMapper.updateById(update, id); }
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/13 23:19:07

Miniconda-Python3.10镜像中安装OpenCV进行图像处理

在 Miniconda-Python3.10 镜像中高效部署 OpenCV 实现图像处理 在当今计算机视觉技术迅猛发展的背景下&#xff0c;图像处理早已不再是实验室里的小众研究方向&#xff0c;而是深入到了自动驾驶、工业质检、医疗影像分析乃至消费级智能设备的方方面面。越来越多的开发者和研究…

作者头像 李华
网站建设 2026/4/14 23:44:44

arm版win10下载更新机制:初始设置完整示例

ARM版Win10下载更新机制&#xff1a;从零开始的完整实战解析 你有没有遇到过这样的情况&#xff1f;一台全新的ARM架构Windows设备&#xff0c;第一次开机后卡在“正在准备你的设备”界面&#xff0c;进度条缓慢爬行&#xff0c;Wi-Fi图标疯狂闪烁——背后正是 arm版win10下载…

作者头像 李华
网站建设 2026/4/14 5:51:55

Miniconda-Python3.10镜像中安装ONNX Runtime进行模型推理

在 Miniconda-Python3.10 环境中使用 ONNX Runtime 实现高效模型推理 如今&#xff0c;AI 模型早已走出实验室&#xff0c;广泛应用于工业质检、医疗影像分析、智能客服等实际场景。但一个训练好的模型要真正“跑起来”&#xff0c;却远非调用几行代码那么简单——环境依赖冲突…

作者头像 李华
网站建设 2026/4/15 12:31:54

Miniconda-Python3.10镜像结合FastAPI构建高性能API接口

Miniconda-Python3.10 镜像结合 FastAPI 构建高性能 API 接口 在人工智能与数据科学项目日益复杂的今天&#xff0c;一个常见的痛点浮出水面&#xff1a;为什么同样的代码&#xff0c;在开发机上运行良好&#xff0c;部署到服务器却频频报错&#xff1f; 答案往往藏在“环境不一…

作者头像 李华
网站建设 2026/4/15 12:31:53

CMSIS入门必看:ARM Cortex微控制器软件接口标准详解

CMSIS实战指南&#xff1a;为什么每个Cortex-M开发者都该懂这套标准你有没有遇到过这样的场景&#xff1f;刚在STM32上写完一套串口通信代码&#xff0c;领导一句话“这个项目要迁移到NXP的KL27”&#xff0c;瞬间让你陷入重写外设配置、反复查手册、调试中断向量表的噩梦。更糟…

作者头像 李华
网站建设 2026/4/15 12:33:42

电源管理与时钟调节协同实现深度睡眠模式

如何让MCU“睡得更沉”&#xff1f;电源与时钟协同下的深度睡眠实战解析你有没有遇到过这样的场景&#xff1a;一个电池供电的温湿度传感器&#xff0c;理论上能用一年&#xff0c;结果三个月就没电了&#xff1f;或者你的智能手环明明设置了省电模式&#xff0c;但待机几天就得…

作者头像 李华