<p>//3.修改信息(批量修改)-是否有预约的学员(有:弹窗提醒-修改时间段已约学员,确定需要调整,调整后会短信通知学员、无:直接修改)\n@PostMapping(&quot;/updateOneUpdateTimeByIDByNotice&quot;)\npublic Result<Object> updateOneUpdateTimeByIDByNotice(@RequestBody Map&lt;String, Object&gt; params, HttpServletRequest request) {\n\n    //权限验证\n    String token = (String) request.getAttribute(&quot;claims_coach&quot;);\n    if (token == null || &quot;&quot;.equals(token)) {\n        throw new RuntimeException(&quot;权限不足!&quot;);\n    }\n\n    log.info(&quot;updateOneUpdateTimeByID报文:&quot; + params);\n    Map&lt;String, Object&gt; map = new HashMap&lt;&gt;();\n\n    //前端传递参数\n    //修改时间段id:updateTimeId、要修改的时间段字符串:time、要修改的科目:projectType、要修改的人数:maxReservation\n    JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(params));\n    JSONArray jsonArray = jsonObject.getJSONArray(&quot;updateTime&quot;);\n\n    //集合(前端传递的要修改的对象集合)\n    List<UpdateTimeDtox> updateTimes = JSONObject.parseArray(jsonArray.toJSONString(), UpdateTimeDtox.class);\n\n    if (updateTimes.isEmpty()) {\n        log.error(&quot;前端传递集合为空!&quot;);\n        return new Result&lt;&gt;(ResultCode.FAIL);\n    }\n\n    List<UpdateTime> updateTimeMyList = new ArrayList&lt;&gt;();//存放修改的对象\n    List<CourseDto> courseDtoListByNow = new ArrayList&lt;&gt;();\n    List<CourseDto> courseDtoListByAll = new ArrayList&lt;&gt;();\n\n    //遍历前端发来的要修改信息的对象集合\n    for (UpdateTimeDtox updateTime : updateTimes) {\n        //在数据库找到对应的对象\n        UpdateTime updateTimeMy = updateTimeService.getById(updateTime.getUpdateTimeId());\n\n        if (updateTimeMy != null) {\n\n            //1.修改科目\n            //判断前端传递与自身信息是否相等\n            if (!updateTime.getProjectType().equals(updateTimeMy.getProjectType())) {\n                log.info(&quot;修改科目&quot;);\n                //通过修改时间段id和当前时间(08:00)查询(待训练)课程信息\n                List<CourseDto> courseInfos = courseInfoService.queryCourseByUpdateTimeIdByStatus0(updateTime.getUpdateTimeId());\n                //存放待训练的课程\n                for (CourseDto courseDto0 : courseInfos) {\n                    if (courseDto0.getCourseDate().equals(RcqtUtils.getDay())) {\n                        if (LocalTime.now().isBefore(courseDto0.getStartReservationTime().toLocalTime())) {\n                            courseDtoListByNow.add(courseDto0);\n                        }\n                    } else if (courseDto0.getCourseDate().after(RcqtUtils.getDay())) {\n                        courseDtoListByNow.add(courseDto0);\n                    }\n                }\n\n                boolean shouldUpdateProjectType = true;\n                for (CourseDto courseDto : courseDtoListByNow) {\n                    CarUser carUser = carUserService.queryOneCarUserById(courseDto.getUserId());\n                    courseDto.setCarUser(carUser);\n                    if (carUser.getDrivingProjectType().equals(&quot;科二/科三&quot;)) {\n                        shouldUpdateProjectType = false;\n                        break;\n                    } else if (updateTime.getProjectType().equals(&quot;科二/科三&quot;)) {\n                        shouldUpdateProjectType = false;\n                        break;\n                    } else if (!carUser.getDrivingProjectType().equals(updateTime.getProjectType())) {\n                        if (Objects.equals(carUser.getUserId(), courseDto.getUserId())){\n                            courseDtoListByAll.add(courseDto);\n                        }\n                    }\n                }\n\n                if (shouldUpdateProjectType) {\n                    log.info(&quot;当前无预约学员,直接修改&quot;);\n                    //当前没有预约的学员\n                    updateTimeMy.setProjectType(updateTime.getProjectType());\n                }\n            }\n        }\n        updateTimeMyList.add(updateTimeMy);\n    }\n\n    if (!courseDtoListByAll.isEmpty()) {\n        Map&lt;Long, List<CourseDto>&gt; fieldMap = new HashMap&lt;&gt;();\n        courseDtoListByAll.forEach(obj -&gt; {\n            Long field = obj.getUpdateTimeId();\n            fieldMap.computeIfAbsent(field, k -&gt; new ArrayList&lt;&gt;()).add(obj);\n        });\n\n        List<NoticeDto> newObjects = new ArrayList&lt;&gt;();\n        fieldMap.entrySet().forEach(entry -&gt; {\n            Long field = entry.getKey();\n            List<CourseDto> values = entry.getValue();\n            List<CarUser> carUserList = values.stream().map(CourseDto::getCarUser).collect(Collectors.toList());\n\n            CourseDto courseDto = values.get(0);\n            NoticeDto newObject = new NoticeDto(field, courseDto, carUserList, values);\n            newObjects.add(newObject);\n        });\n\n        log.info(&quot;通知&quot;);\n        map.put(&quot;courseInfos&quot;, newObjects);\n        return new Result&lt;&gt;(ResultCode.NOTICE_COACH, map);\n    }\n\n    boolean b = updateTimeService.updateBatchById(updateTimeMyList);\n\n    if (b) {\n        log.info(&quot;修改时间段信息成功!&quot;);\n        return new Result&lt;&gt;(ResultCode.SUCCESS);\n    } else {\n        log.error(&quot;修改时间段信息失败!&quot;);\n        return new Result&lt;&gt;(ResultCode.FAIL);\n    }\n\n</p>
批量修改时间段信息-预约学员弹窗提醒

原文地址: https://www.cveoy.top/t/topic/qohW 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录