前端不传被删记录的id怎么删除记录,或子表如何删除记录

2024-02-24 18:04

本文主要是介绍前端不传被删记录的id怎么删除记录,或子表如何删除记录,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1.删除主表相关子表所有记录

2.再保存一次前端传来的记录

3.如果子表是通过先生成空记录,再put修改模式,可以在执行1和2两步后再拿模板集合和当前现有子表集合套两个for循环对比判断,count记录模板记录和子表记录每次循环重合次数,当发送现有子表中没有模板的情况,也就是count==0,就在一层循环再创建一个模板对象,达到效果:原有空记录不会因为进来时全删除的操作而抹去,因为空记录是页面动态效果的一部分

    /*** 更新** @param documentEntities* @return*/@PutMapping("/reference/{projectStageId}/{typeListCode}")@Transactional@Operation(summary = "更新")public ActionResult referenceUpdate(@PathVariable String projectStageId,@RequestBody @Valid List<DocumentListVO> documentEntities ) throws DataException {UserInfo userInfo = userProvider.get();//删除原有所有记录LambdaQueryWrapper<ListDocumentFileEntity> wrapper = new LambdaQueryWrapper<>();wrapper.eq(ListDocumentFileEntity::getProjectStageId,projectStageId);List<ListDocumentFileEntity> list = listDocumentFileService.list(wrapper);listDocumentFileService.removeBatchByIds(list);//新增此次传来的记录for (DocumentListVO drawingListVO : documentEntities) {for (DocumentVO documentVO : drawingListVO.getChildren()) {ListDocumentFileEntity documentFile = new ListDocumentFileEntity(RandomUtil.uuId(),drawingListVO.getProjectStageId(),drawingListVO.getTypeListCode(),drawingListVO.getFSort(),drawingListVO.getFileType(),null,documentVO.getDocumentNumber(), documentVO.getIssuanceDate(),"0",userInfo.getUserName(), DateTime.now(),null,null,null,documentVO.getFileId(),documentVO.getSequence(),documentVO.getFileName());if (listDocumentFileService.getInfo(documentVO.getId())==null){listDocumentFileService.save(documentFile);}else {documentFile.setId(documentVO.getId());listDocumentFileService.updateById(documentFile);}}}//获取空记录的模板与现在的子表记录对比,如果缺了空记录就补充空记录List<ListTemplate1Entity> listByTypeCode = listTemplate1Service.getListByTypeCode(typeListCode);List<ListDocumentFileEntity> list2 = listDocumentFileService.list(wrapper);for (ListTemplate1Entity listTemplate1Entity : listByTypeCode) {int integer = 0;for (ListDocumentFileEntity documentFile : list2) {if (documentFile.getFileType().equals(listTemplate1Entity.getFileType())){integer++;}}if (integer==0){ListDocumentFileEntity listDocumentFileEntity = new ListDocumentFileEntity();listDocumentFileEntity.setId(RandomUtil.uuId());listDocumentFileEntity.setProjectStageId(projectStageId);listDocumentFileEntity.setFileType(listTemplate1Entity.getFileType());listDocumentFileEntity.setTypeListCode(listTemplate1Entity.getListTypeCode());listDocumentFileEntity.setFSort(listTemplate1Entity.getFSort());listDocumentFileEntity.setRemark(listTemplate1Entity.getRemark());listDocumentFileEntity.setRequired(listTemplate1Entity.getRequired());listDocumentFileService.save(listDocumentFileEntity);}}return ActionResult.success("更新成功");}

方法二:

后来想了下直接在第一次的时候判断有没有生成模板的记录,如果没生成就生一个,这样就避免了第二次遍历

    /*** 编辑** @param documentEntities* @return*/@PutMapping("/reference/{projectStageId}")@Transactional@Operation(summary = "更新")public ActionResult referenceUpdate(@PathVariable String projectStageId,@RequestBody @Valid List<DocumentListVO> documentEntities ) throws DataException {UserInfo userInfo = userProvider.get();//删除原有所有记录LambdaQueryWrapper<ListDocumentFileEntity> wrapper = new LambdaQueryWrapper<>();wrapper.eq(ListDocumentFileEntity::getProjectStageId,projectStageId);List<ListDocumentFileEntity> list = listDocumentFileService.list(wrapper);listDocumentFileService.removeBatchByIds(list);//新增此次传来的记录for (DocumentListVO drawingListVO : documentEntities) {int integer = 0;for (DocumentVO documentVO : drawingListVO.getChildren()) {ListDocumentFileEntity documentFile = new ListDocumentFileEntity(RandomUtil.uuId(),drawingListVO.getProjectStageId(),drawingListVO.getTypeListCode(),drawingListVO.getFSort(),drawingListVO.getFileType(),null,documentVO.getDocumentNumber(), documentVO.getIssuanceDate(),"0",userInfo.getUserName(), DateTime.now(),null,null,null,documentVO.getFileId(),documentVO.getSequence(),documentVO.getFileName());if (listDocumentFileService.getInfo(documentVO.getId())==null){listDocumentFileService.save(documentFile);integer++;}}//没有就生一个if (integer==0){ListDocumentFileEntity listDocumentFileEntity = new ListDocumentFileEntity();listDocumentFileEntity.setId(RandomUtil.uuId());listDocumentFileEntity.setProjectStageId(projectStageId);listDocumentFileEntity.setFileType(drawingListVO.getFileType());listDocumentFileEntity.setTypeListCode(drawingListVO.getTypeListCode());listDocumentFileEntity.setFSort(drawingListVO.getFSort());listDocumentFileEntity.setRemark(null);listDocumentFileEntity.setRequired(null);listDocumentFileService.save(listDocumentFileEntity);}}return ActionResult.success("更新成功");}

摸鱼的同志可以看看,代码很粗糙,应该只是思维符合很多人但实际情况几乎不符

这篇关于前端不传被删记录的id怎么删除记录,或子表如何删除记录的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/742906

相关文章

Mysql实现范围分区表(新增、删除、重组、查看)

《Mysql实现范围分区表(新增、删除、重组、查看)》MySQL分区表的四种类型(范围、哈希、列表、键值),主要介绍了范围分区的创建、查询、添加、删除及重组织操作,具有一定的参考价值,感兴趣的可以了解... 目录一、mysql分区表分类二、范围分区(Range Partitioning1、新建分区表:2、分

MySQL 删除数据详解(最新整理)

《MySQL删除数据详解(最新整理)》:本文主要介绍MySQL删除数据的相关知识,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录一、前言二、mysql 中的三种删除方式1.DELETE语句✅ 基本语法: 示例:2.TRUNCATE语句✅ 基本语

一文详解Git中分支本地和远程删除的方法

《一文详解Git中分支本地和远程删除的方法》在使用Git进行版本控制的过程中,我们会创建多个分支来进行不同功能的开发,这就容易涉及到如何正确地删除本地分支和远程分支,下面我们就来看看相关的实现方法吧... 目录技术背景实现步骤删除本地分支删除远程www.chinasem.cn分支同步删除信息到其他机器示例步骤

python删除xml中的w:ascii属性的步骤

《python删除xml中的w:ascii属性的步骤》使用xml.etree.ElementTree删除WordXML中w:ascii属性,需注册命名空间并定位rFonts元素,通过del操作删除属... 可以使用python的XML.etree.ElementTree模块通过以下步骤删除XML中的w:as

在Spring Boot中集成RabbitMQ的实战记录

《在SpringBoot中集成RabbitMQ的实战记录》本文介绍SpringBoot集成RabbitMQ的步骤,涵盖配置连接、消息发送与接收,并对比两种定义Exchange与队列的方式:手动声明(... 目录前言准备工作1. 安装 RabbitMQ2. 消息发送者(Producer)配置1. 创建 Spr

Navicat数据表的数据添加,删除及使用sql完成数据的添加过程

《Navicat数据表的数据添加,删除及使用sql完成数据的添加过程》:本文主要介绍Navicat数据表的数据添加,删除及使用sql完成数据的添加过程,具有很好的参考价值,希望对大家有所帮助,如有... 目录Navicat数据表数据添加,删除及使用sql完成数据添加选中操作的表则出现如下界面,查看左下角从左

前端如何通过nginx访问本地端口

《前端如何通过nginx访问本地端口》:本文主要介绍前端如何通过nginx访问本地端口的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、nginx安装1、下载(1)下载地址(2)系统选择(3)版本选择2、安装部署(1)解压(2)配置文件修改(3)启动(4)

怎么用idea创建一个SpringBoot项目

《怎么用idea创建一个SpringBoot项目》本文介绍了在IDEA中创建SpringBoot项目的步骤,包括环境准备(JDK1.8+、Maven3.2.5+)、使用SpringInitializr... 目录如何在idea中创建一个SpringBoot项目环境准备1.1打开IDEA,点击New新建一个项

HTML中meta标签的常见使用案例(示例详解)

《HTML中meta标签的常见使用案例(示例详解)》HTMLmeta标签用于提供文档元数据,涵盖字符编码、SEO优化、社交媒体集成、移动设备适配、浏览器控制及安全隐私设置,优化页面显示与搜索引擎索引... 目录html中meta标签的常见使用案例一、基础功能二、搜索引擎优化(seo)三、社交媒体集成四、移动

HTML input 标签示例详解

《HTMLinput标签示例详解》input标签主要用于接收用户的输入,随type属性值的不同,变换其具体功能,本文通过实例图文并茂的形式给大家介绍HTMLinput标签,感兴趣的朋友一... 目录通用属性输入框单行文本输入框 text密码输入框 password数字输入框 number电子邮件输入编程框