前端不传被删记录的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("更新成功");}

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/700231.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C# winfroms使用socket客户端服务端代码详解

文章目录 1️⃣ 通信相关说明1.1服务端与客户端1.2 信息发送原理1.3 信息接收原理 2️⃣ socket代码2.1 客户端代码2.2 服务端代码 3️⃣ 定时任务处理报文3.1 Timers定时任务 优质资源分享 作者&#xff1a;xcLeigh 文章地址&#xff1a;https://blog.csdn.net/weixin_4315141…

滚雪球学Java(71):深入剖析Java中的ArrayBlockingQueue底层实现与源码分析

咦咦咦&#xff0c;各位小可爱&#xff0c;我是你们的好伙伴——bug菌&#xff0c;今天又来给大家普及Java SE相关知识点了&#xff0c;别躲起来啊&#xff0c;听我讲干货还不快点赞&#xff0c;赞多了我就有动力讲得更嗨啦&#xff01;所以呀&#xff0c;养成先点赞后阅读的好…

每日leetcode--全排列II

问题描述 题目链接&#xff1a;力扣&#xff08;LeetCode&#xff09;官网 - 全球极客挚爱的技术成长平台 给定一个可能包含重复元素的整数数组 nums&#xff0c;编写一个函数来返回所有不重复的全排列 示例 1&#xff1a; 输入&#xff1a;nums [1,1,2] 输出&#xff1a;…

vue3 globalData 的使用方法

直接上教程 .新创建一个data.js它可以和main.js平级也可以在store文件夹下面都行&#xff0c;无非就是引用的时候前缀多一个单词少一个单词这样 data.js: 从vue上面引入reactive &#xff0c;然后它可以创建一个也可以创建两个可以任意名称 A或B或C都可以 //data.js import…

SpringMVC 学习(一)之 SpringMVC 介绍

目录 1 MVC 介绍 2 SpringMVC 介绍 2.1 SpringMVC 特点 2.2 SpringMVC 的核心组件 2.3 SpringMVC 执行流程 3 参考文档 1 MVC 介绍 MVC (Model View Controller) 是一种设计思想&#xff0c;它将应用程序分为三大组件&#xff1a;模型 (Model)、视图 (View)、控制器 (Con…

用TensorRT-LLM跑通chatGLM_6B模型

零、参考资料 NVIDIA官网 THUDM的Github NVIDIA的Github 一、构建 TensorRT-LLM的docker镜像 git lfs install git clone https://github.com/NVIDIA/TensorRT-LLM.git cd TensorRT-LLM git submodule update --init --recursive sudo make -C docker release_build sudo m…

在openEuler中通过KVM可视化安装华为FusionCompute的VRM节点

一、说明 本文是华为FusionCompute云平台配置的延续&#xff0c;是在CNA&#xff08;ComputingNode Agent&#xff0c;计算节点代理&#xff09;主机安装配置完成后&#xff0c;详细安装VRM&#xff08;Virtual Resource Manager&#xff0c;虚拟资源管理器&#xff09;节点的…

「JavaSE」String类3:字符串常量池

&#x1f387;个人主页&#xff1a;Ice_Sugar_7 &#x1f387;所属专栏&#xff1a;快来卷Java啦 &#x1f387;欢迎点赞收藏加关注哦&#xff01; 字符串常量池 &#x1f349;常量池&#x1f349;字符串常量池&#x1f349;intern 方法 &#x1f349;常量池 在Java程序中&…

微服务-Alibaba微服务nacos实战

1. Nacos配置中心 1.1 微服务为什么需要配置中心 在微服务架构中&#xff0c;当系统从一个单体应用&#xff0c;被拆分成分布式系统上一个个服务节点后&#xff0c;配置文件也必须跟着迁移&#xff08;分割&#xff09;&#xff0c;这样配置就分散了&#xff0c;不仅如此&…

*MYSQL--索引--内部原理

MYSQL的索引根据功能,主要有三大类型: 1.HASH索引 2.二叉树 3.BTREE索引 一:HASH索引 1.内部原理: 在设置了某列为索引列之后,并且开始或者将要在相应索引列创建数据的时候,系统通过某种算法 F(X) 自动计算出来一个十六进制的哈希值,这个哈希值能够对应相应的字段值 所以…

数据之巅:揭秘企业数据分析师如何成为企业的决策智囊

引言 在数字化浪潮中&#xff0c;企业数据分析师已成为企业决策的重要支撑。他们如同探险家&#xff0c;在数据的丛林中寻找着能够指引企业前行的宝贵信息。本文将深入剖析企业数据分析师的角色、挑战与成就&#xff0c;带你领略这个充满智慧与激情的职业风采。 一、从数字到智…

28-k8s集群中-StatefulSets控制器(进阶知识)

一、statefullsets控制器概述 1&#xff0c;举例 假如&#xff0c;我们有一个deployment资源&#xff0c;创建了3个nginx的副本&#xff0c;对于nginx来讲&#xff0c;它是不区分启动或者关闭的先后顺序的&#xff0c;也就是“没有特殊状态”的一个服务&#xff0c;也成“无状…

【Java】图形、图像与音频(实验十二)

一 、Component组件类中有一个public void paint( Graphics g)绘画方法&#xff0c;只要用户自定义的类继承了此组件类或其子类并重写了paint()方法&#xff0c;当用户自定义的类被实例化后&#xff0c;此时java运行环境就会开启一个新线程来自动调用并执行用户自定义类中的pai…

树莓派更新源,以及安装wiringPi库

1、更换树莓派&#xff08;Raspberry Pi 3B&#xff09;软件源 更换树莓派&#xff08;Raspberry Pi 3B&#xff09;软件源为国内镜像源_树莓派3b更换国内源-CSDN博客 2、安装wiringPi库 安装wiringPi库在树莓派上&#xff0c;可以按照以下步骤进行操作&#xff1a; a.首先&…

十四届蓝桥杯国赛考试计算思维 U10 组真题和答案

答案在底部 第一题 恐龙乐园的规划图中有 n 个小岛,m 座小桥,每座桥连接两个小岛。 下图是 n=5,m=8 的一个例子: 希希发现,如果拆除一些桥,仍然能使任何两个小岛都互通。最多可以拆除( )座 桥。 A. n-m B. m-n C. m-m-1 D. m-n+1 第二题

Python文件和异常(一)

目录 一、从文件中读取数据 &#xff08;一&#xff09;读取整个文件 &#xff08;二&#xff09;文件路径 &#xff08;三&#xff09;逐行读取 &#xff08;四&#xff09;创建一个包含文件各行内容的列表 &#xff08;五&#xff09;使用文件的内容 &#xff08;六&a…

私域运营的4个核心要素

第一&#xff0c;我们要首先理解私域现在的形势。 以前私域&#xff1a;崛起的微商。发朋友圈&#xff0c;成交率高。 因为主要来源是信息差。 当代&#xff1a;信息透明化。私域流量运营的本质是获取信任。通过建立起泛人脉亲密关系。信任才重要。 第二&#xff0c;塑造一对一…

探索设计模式的魅力:状态模式揭秘-如何优雅地处理复杂状态转换

​&#x1f308; 个人主页&#xff1a;danci_ &#x1f525; 系列专栏&#xff1a;《设计模式》 &#x1f4aa;&#x1f3fb; 制定明确可量化的目标&#xff0c;并且坚持默默的做事。 探索设计模式的魅力&#xff1a;状态模式揭秘-如何优雅地处理复杂状态转换 文章目录 一、案例…

VUE3使用three.js显示3D模型

使用3D模型作为自动化系统的界面已经成为潮流。尽管在AutomationML 中推荐COLLADA作为 3D 模型的标准。但是COLLADA的开发者khronos 集团却已经开发了COLLADA的后继者glTF 。glTF 2.0已经成为国际标准ISO/IEC 12113:2022。 Khronos声称-‘glTF是3D里的JPEG’。目前看来glTF 更加…

Java WEB面试系列-01

1. 什么是 Servlet? Servlet是用Java编写的服务器端程序, 其主要功能在于交互式地浏览和修改数据,生成动态Web内容。 狭义的Servlet是指Java语言实现的一个接口,广义的Servlet是指任何实现了这个Servlet接口的类,一般情况下,我们一般将Servlet理解为后者。 2. 为什么要使…