news 2026/5/1 2:02:28

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/26 23:28:40

vivado2018.3与SDK联合调试硬件系统:操作指南

Vivado 2018.3 与 SDK 联合调试实战指南&#xff1a;从零搭建 Zynq 硬件系统你有没有遇到过这样的场景&#xff1f;FPGA 工程综合通过了&#xff0c;比特流也下载进去了&#xff0c;可一到软件端运行程序就“卡死”、外设无响应&#xff0c;串口输出乱码……最后翻遍文档才发现…

作者头像 李华
网站建设 2026/4/28 18:52:03

Proteus元件库对照表初识指南(图文结合)

从“找不到元件”到高效仿真&#xff1a;Proteus 元件库实战指南&#xff08;图文结合&#xff09; 你有没有遇到过这样的场景&#xff1f; 想在 Proteus 里搭一个基于 STM32 的最小系统&#xff0c;结果输入 “STM32F103C8T6” 死活搜不到&#xff1b; 打算用个普通的三极…

作者头像 李华
网站建设 2026/4/20 23:53:59

通过Keil编译51单片机流水灯代码的系统学习

从零开始&#xff1a;用Keil点亮51单片机的流水灯你有没有试过&#xff0c;第一次在单片机上跑通一个程序时那种兴奋感&#xff1f;不是复杂的操作系统&#xff0c;也不是炫酷的图形界面——而是一个简单的LED&#xff0c;从左到右&#xff0c;一盏接一盏地亮起来。就像电流顺着…

作者头像 李华
网站建设 2026/4/29 1:26:08

解决‘conda init’错误提示:Miniconda-Python3.10镜像初始化设置

解决“conda init”错误提示&#xff1a;Miniconda-Python3.10镜像初始化设置 在现代数据科学和人工智能项目中&#xff0c;环境管理早已不再是“能跑就行”的附属环节&#xff0c;而是决定研发效率、实验可复现性和团队协作质量的关键一环。你有没有遇到过这样的场景&#xff…

作者头像 李华
网站建设 2026/4/30 17:14:45

STLink连接STM32实现在线调试:项目应用级接线策略

STLink连接STM32实现在线调试&#xff1a;从原理到实战的接线艺术你有没有遇到过这样的场景&#xff1f;代码写得一丝不苟&#xff0c;编译通过&#xff0c;信心满满点击“Debug”&#xff0c;结果 IDE 弹出一行冷冰冰的提示&#xff1a;“No target connected”。反复插拔、换…

作者头像 李华
网站建设 2026/4/20 21:59:40

Miniconda安装后bash不识别命令解决办法

Miniconda安装后bash不识别命令解决办法 在搭建Python开发环境时&#xff0c;尤其是从事数据科学、机器学习或AI项目的过程中&#xff0c;Miniconda 已成为许多工程师和研究人员的首选工具。它轻量、灵活&#xff0c;支持多版本Python共存与依赖隔离&#xff0c;极大提升了项目…

作者头像 李华