当前位置: 首页 > news >正文

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); }
http://www.zskr.cn/news/184134.html

相关文章:

  • arm版win10下载更新机制:初始设置完整示例
  • 亲测降至5%以下!2025年10款降ai工具实测!免费降ai率真的靠谱吗?百万字降红总结,论文降aigc必看!
  • Miniconda-Python3.10镜像中配置Jupyter密码保护机制
  • 肯·汤普森:数字世界的奠基者与他的“为了游戏”的Unix革命
  • Miniconda-Python3.10镜像助力初创企业降低AI开发成本
  • Miniconda-Python3.10镜像中使用conda-forge频道安装最新PyTorch
  • ESP32引脚电气特性解析:系统学习指南
  • Miniconda-Python3.10镜像支持区块链数据分析脚本运行
  • STM32双I2C接口资源管理策略通俗解释
  • [特殊字符] 中国战斗机检测数据集介绍-3427张图片 军事装备识别 航空安全监控 军工制造质检 航空博物馆智能导览 军事训练仿真 国防科研分析
  • Miniconda-Python3.10镜像中使用netstat检查网络连接
  • 解决‘conda init’错误提示:Miniconda-Python3.10镜像初始化设置
  • Miniconda-Python3.10镜像结合Supervisor实现进程守护
  • Miniconda-Python3.10镜像结合Docker实现跨平台环境迁移
  • 高效复现实验结果:Miniconda-Python3.10镜像助力科研项目落地
  • 系统学习STLink引脚图与ARM Cortex调试接口
  • 清华镜像robots.txt限制爬虫抓取说明
  • 智谱启动招股:获北京核心国资等30亿港元认购 估值超500亿 1月8日上市
  • 零基础掌握jflash下载程序步骤方法
  • Miniconda环境备份策略:定期导出yml文件
  • 手把手教你用Miniconda-Python3.10镜像搭建Jupyter+PyTorch开发环境
  • 基于gerber文件转成pcb文件的BOM重建方法探讨
  • Miniconda-Python3.10镜像中升级Python版本的安全方法
  • 前后端分离线上学习资源智能推荐系统系统|SpringBoot+Vue+MyBatis+MySQL完整源码+部署教程
  • Miniconda-Python3.10镜像支持多用户共享GPU集群的权限管理
  • freemodbus与RS485结合应用:操作指南(项目实践)
  • java-转义字符 - T
  • PyTorch随机种子设置确保实验可复现性
  • PyTorch自动求导机制验证环境稳定性
  • SpringBoot+Vue 项目申报管理系统平台完整项目源码+SQL脚本+接口文档【Java Web毕设】