当前位置: 首页 > 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.jsqmd.com/news/168414/

相关文章:

  • 51单片机驱动LCD1602:Keil C51环境配置完整指南
  • 高德纳:算法与编程艺术的永恒巨匠
  • 251230人生有几个支持自己的人就会充满无限动力
  • Miniconda-Python3.11镜像助力GPU算力销售:开发者友好型环境预装
  • 上位机软件与STM32串口通信完整示例
  • Miniconda-Python3.10镜像中配置Jupyter密码保护机制
  • 丹尼斯·里奇:无声的巨人,数字世界的奠基者
  • 亲测降至5%以下!2025年10款降ai工具实测!免费降ai率真的靠谱吗?百万字降红总结,论文降aigc必看!
  • USB转串口驱动安装:WDF框架应用实例
  • Miniconda-Python3.10镜像支持AIGC内容生成的前置条件
  • Miniconda-Python3.10镜像中Jupyter Lab的高级使用技巧
  • Miniconda-Python3.10镜像中使用wget/curl下载大型数据集
  • 肯·汤普森:数字世界的奠基者与他的“为了游戏”的Unix革命
  • 通过Keil编译51单片机流水灯代码的系统学习
  • Miniconda-Python3.10镜像中使用conda-forge频道安装最新PyTorch
  • Miniconda-Python3.10镜像助力初创企业降低AI开发成本
  • ESP32引脚电气特性解析:系统学习指南
  • Miniconda-Python3.10镜像结合FastAPI构建高性能API接口
  • Miniconda-Python3.10镜像中限制GPU显存使用的技巧
  • 工业控制电路板热管理与PCB Layout综合方案
  • Miniconda-Python3.10镜像配合CUDA安装实现端到端AI训练流程
  • Miniconda-Python3.10镜像支持自动化测试脚本执行
  • Miniconda-Python3.10镜像中如何清理缓存节省磁盘空间
  • Miniconda安装后bash不识别命令解决办法
  • 战斗机检测数据集介绍-10000张图片 军事防空系统 航空交通管制 情报侦察分析 航空博物馆导览 军事训练模拟 边境监控预警
  • Miniconda-Python3.10镜像与Pyenv协同管理Python版本的方法
  • STM32双I2C接口资源管理策略通俗解释
  • 一文说清Proteus元件库对照表中的封装映射关系
  • [特殊字符] 中国战斗机检测数据集介绍-3427张图片 军事装备识别 航空安全监控 军工制造质检 航空博物馆智能导览 军事训练仿真 国防科研分析
  • 从寄存器配置看STM32 CANFD和CAN的区别:实践型解析