<p>{&quot;@PostMapping&quot;:&quot;&quot;/updateOneUpdateTimeByIDByNotice&quot;&quot;,&quot;public&quot;:&quot; Result<Object> updateOneUpdateTimeByIDByNotice(@RequestBody Map&lt;String, Object&gt; params, HttpServletRequest request) {</p>
<pre><code>//权限验证
String token = (String) request.getAttribute(&quot;claims_coach&quot;);
if (token == null || \&quot;\&quot;.equals(token)) {
    throw new RuntimeException(&quot;权限不足!&quot;);
}

log.info(&quot;updateOneUpdateTimeByID报文:&quot; + params);
Map&lt;String, Object&gt; map = new HashMap&lt;&gt;();

//前端传递参数
//修改时间段id:updateTimeId、要修改的时间段字符串:time、要修改的科目:projectType、要修改的人数:maxReservation
JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(params));
JSONArray jsonArray = jsonObject.getJSONArray(&quot;updateTime&quot;);

//集合(前端传递的要修改的对象集合)
List&lt;UpdateTimeDtox&gt; updateTimes = JSONObject.parseArray(jsonArray.toJSONString(), UpdateTimeDtox.class);

if (updateTimes.isEmpty()) {
    log.error(&quot;前端传递集合为空!&quot;);
    return new Result&lt;&gt;(ResultCode.FAIL);
}

List&lt;UpdateTime&gt; updateTimeMyList = new ArrayList&lt;&gt;();//存放修改的对象
List&lt;CourseDto&gt; courseDtoListByNow = new ArrayList&lt;&gt;();
List&lt;CourseDto&gt; courseDtoListByAll = new ArrayList&lt;&gt;();

//遍历前端发来的要修改信息的对象集合
for (UpdateTimeDtox updateTime : updateTimes) {
    //在数据库找到对应的对象
    UpdateTime updateTimeMy = updateTimeService.getById(updateTime.getUpdateTimeId());

    if (updateTimeMy != null) {

        //1.修改科目
        //判断前端传递与自身信息是否相等
        if (!updateTime.getProjectType().equals(updateTimeMy.getProjectType())) {
            log.info(&quot;修改科目&quot;);
            //通过修改时间段id和当前时间(08:00)查询(待训练)课程信息
            List&lt;CourseDto&gt; courseInfos = courseInfoService.queryCourseByUpdateTimeIdByStatus0(updateTime.getUpdateTimeId());
            //存放待训练的课程
            for (CourseDto courseDto0 : courseInfos) {
                if (courseDto0.getCourseDate().equals(RcqtUtils.getDay())) {
                    if (LocalTime.now().isBefore(courseDto0.getStartReservationTime().toLocalTime())) {
                        courseDtoListByNow.add(courseDto0);
                    }
                } else if (courseDto0.getCourseDate().after(RcqtUtils.getDay())) {
                    courseDtoListByNow.add(courseDto0);
                }
            }
            
            if (!CollectionUtils.isEmpty(courseDtoListByNow)) {
                for (CourseDto courseDto : courseDtoListByNow) {
                    CarUser carUser = carUserService.queryOneCarUserById(courseDto.getUserId());
                    courseDto.setCarUser(carUser);
                    if (carUser.getDrivingProjectType().equals(&quot;科二/科三&quot;) || updateTime.getProjectType().equals(&quot;科二/科三&quot;)) {
                        updateTimeMy.setProjectType(updateTime.getProjectType());
                    } else if (!carUser.getDrivingProjectType().equals(updateTime.getProjectType())) {
                        if (Objects.equals(carUser.getUserId(), courseDto.getUserId())){
                            courseDtoListByAll.add(courseDto);
                        }
                    }
                }
            } else {
                log.info(&quot;当前无预约学员,直接修改&quot;);
                //当前没有预约的学员
                updateTimeMy.setProjectType(updateTime.getProjectType());
            }
        }
    }
    updateTimeMyList.add(updateTimeMy);
}

if (!courseDtoListByAll.isEmpty()) {
    Map&lt;Long, List&lt;CourseDto&gt;&gt; fieldMap = courseDtoListByAll.stream()
            .collect(Collectors.groupingBy(CourseDto::getUpdateTimeId));

    List&lt;NoticeDto&gt; newObjects = fieldMap.entrySet().stream()
            .map(entry -&gt; {
                Long field = entry.getKey();
                List&lt;CourseDto&gt; values = entry.getValue();
                List&lt;CarUser&gt; carUserList = values.stream().map(CourseDto::getCarUser).collect(Collectors.toList());

                CourseDto courseDto = values.get(0);
                return new NoticeDto(field, courseDto, carUserList, values);
            })
            .collect(Collectors.toList());

    log.info(&quot;通知&quot;);
    map.put(&quot;courseInfos&quot;, newObjects);
    return new Result&lt;&gt;(ResultCode.NOTICE_COACH, map);
}

boolean b = updateTimeService.updateBatchById(updateTimeMyList);

if (b) {
    log.info(&quot;修改时间段信息成功!&quot;);
    return new Result&lt;&gt;(ResultCode.SUCCESS);
} else {
    log.error(&quot;修改时间段信息失败!&quot;);
    return new Result&lt;&gt;(ResultCode.FAIL);
}
</code></pre>
<p>}</p>
批量修改时间段信息 - 有预约学员则弹窗提醒,无预约学员则直接修改

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

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