news 2026/10/2 11:26:12

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/9/30 14:55:52

Miniconda-Python3.10镜像结合Vault管理敏感凭证

Miniconda-Python3.10镜像结合Vault管理敏感凭证 在当今AI与数据科学项目快速迭代的背景下&#xff0c;一个常见的痛点浮出水面&#xff1a;为什么代码在开发者本地运行良好&#xff0c;一旦部署到服务器或分享给同事就频频报错&#xff1f;更令人担忧的是&#xff0c;那些写在…

作者头像 李华
网站建设 2026/10/1 12:49:48

Miniconda-Python3.10镜像用于构建可复用的大模型训练模板

Miniconda-Python3.10镜像用于构建可复用的大模型训练模板 在大模型研发日益成为主流的今天&#xff0c;一个令人头疼却无法回避的问题反复出现&#xff1a;为什么同样的代码&#xff0c;在我的机器上能跑通&#xff0c;换到同事或服务器上就报错&#xff1f;更糟糕的是&#x…

作者头像 李华
网站建设 2026/9/30 9:44:26

could not find driver故障排查:从零实现完整示例

深入排查“could not find driver”错误&#xff1a;从原理到实战的完整指南你有没有遇到过这样的场景&#xff1f;本地开发一切正常&#xff0c;一部署到服务器或容器环境&#xff0c;程序刚启动就抛出一条刺眼的错误&#xff1a;PDOException: could not find driver没有堆栈…

作者头像 李华
网站建设 2026/9/30 9:44:26

Miniconda-Python3.10镜像结合Supervisor实现进程守护

Miniconda-Python3.10镜像结合Supervisor实现进程守护 在现代AI服务与自动化系统的部署实践中&#xff0c;一个看似简单却频繁引发故障的场景是&#xff1a;某次模型推理接口突然无响应&#xff0c;日志显示Python脚本因内存溢出崩溃后未重启&#xff1b;与此同时&#xff0c;团…

作者头像 李华
网站建设 2026/10/1 19:26:26

Miniconda-Python3.10镜像中Jupyter Lab的高级使用技巧

Miniconda-Python3.10镜像中Jupyter Lab的高级使用技巧 在数据科学和人工智能项目日益复杂的今天&#xff0c;一个稳定、可复现且高效的开发环境已成为团队协作与个人研究的核心基础。你是否曾遇到这样的场景&#xff1a;本地跑通的模型在同事机器上因包版本冲突而报错&#xf…

作者头像 李华
网站建设 2026/9/30 9:44:26

hid单片机入门项目:制作简易键盘实战案例

从零开始造键盘&#xff1a;用HID单片机实现一个能插电脑的“硬核玩具”你有没有想过&#xff0c;手边那个普普通通的机械键盘&#xff0c;其实自己也能做出来&#xff1f;不是拆开换轴、改灯效那种“改装”&#xff0c;而是从一块裸片开始&#xff0c;亲手写代码、接电路&…

作者头像 李华