news 2026/4/16 19:33:43

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/16 12:22:01

Miniconda-Python3.10镜像结合Kubernetes部署容器化AI服务

Miniconda-Python3.10镜像结合Kubernetes部署容器化AI服务 在当今AI研发节奏日益加快的背景下&#xff0c;一个常见的痛点始终困扰着工程师和科研人员&#xff1a;为什么模型在本地运行完美&#xff0c;却在生产环境频频报错&#xff1f;归根结底&#xff0c;问题往往出在“环境…

作者头像 李华
网站建设 2026/4/16 17:12:55

Miniconda-Python3.10镜像提升GPU资源利用率的配置建议

Miniconda-Python3.10镜像提升GPU资源利用率的配置建议 在现代AI研发场景中&#xff0c;一个看似简单的环境问题常常成为压垮GPU集群效率的“最后一根稻草”&#xff1a;某位研究员刚跑通的模型&#xff0c;在另一位同事的机器上却因cudatoolkit版本不兼容而报错&#xff1b;一…

作者头像 李华
网站建设 2026/4/16 13:00:49

Miniconda-Python3.10镜像与Anaconda下载对比:谁更适合AI开发者?

Miniconda-Python3.10镜像与Anaconda下载对比&#xff1a;谁更适合AI开发者&#xff1f; 在人工智能项目日益复杂、团队协作频繁的今天&#xff0c;一个常见的问题反复出现&#xff1a;“为什么我的代码在同事机器上跑不通&#xff1f;” 更有甚者&#xff0c;在论文复现时&…

作者头像 李华
网站建设 2026/4/16 15:36:06

Miniconda-Python3.10镜像详解:打造高效稳定的深度学习开发平台

Miniconda-Python3.10镜像详解&#xff1a;打造高效稳定的深度学习开发平台 在人工智能项目日益复杂的今天&#xff0c;一个常见的场景是&#xff1a;你刚接手同事的代码仓库&#xff0c;满怀信心地运行 pip install -r requirements.txt&#xff0c;结果却因为 NumPy 版本冲突…

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

Proteus与Keil联调环境搭建操作指南

手把手教你搭建Proteus与Keil联合调试环境&#xff1a;从零开始的嵌入式仿真实战你有没有遇到过这样的场景&#xff1f;写完一段51单片机代码&#xff0c;烧进芯片却发现LED不亮、按键无响应&#xff0c;反复插拔下载器&#xff0c;怀疑是程序问题又怕是电路设计出错。更头疼的…

作者头像 李华
网站建设 2026/4/16 12:45:21

Miniconda-Python3.10镜像支持图像识别项目的快速原型开发

Miniconda-Python3.10镜像支持图像识别项目的快速原型开发 在图像识别项目中&#xff0c;开发者最怕的不是模型不收敛&#xff0c;而是代码“在我机器上能跑”——到了同事或服务器环境却频频报错。这类问题往往源于依赖版本混乱、系统库缺失&#xff0c;甚至是Python解释器本身…

作者头像 李华