批量修改时间段信息:弹窗提醒或直接修改
<p>@PostMapping('/updateOneUpdateTimeByIDByNotice')
public Result<Object> updateOneUpdateTimeByIDByNotice(@RequestBody Map<String, Object> params, HttpServletRequest request) {</p>
<pre><code>//权限验证
String token = (String) request.getAttribute('claims_coach');
if (token == null || ''.equals(token)) {
throw new RuntimeException('权限不足!');
}
log.info('updateOneUpdateTimeByID报文:' + params);
Map<String, Object> map = new HashMap<>();
//前端传递参数
//修改时间段id:updateTimeId、要修改的时间段字符串:time、要修改的科目:projectType、要修改的人数:maxReservation
JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(params));
JSONArray jsonArray = jsonObject.getJSONArray('updateTime');
//集合(前端传递的要修改的对象集合)
List<UpdateTimeDtox> updateTimes = JSONObject.parseArray(jsonArray.toJSONString(), UpdateTimeDtox.class);
if (updateTimes.isEmpty()) {
log.error('前端传递集合为空!');
return new Result<>(ResultCode.FAIL);
}
List<UpdateTime> updateTimeMyList = new ArrayList<>();//存放修改的对象
List<CourseDto> courseDtoListByAll = new ArrayList<>();
//遍历前端发来的要修改信息的对象集合
for (UpdateTimeDtox updateTime : updateTimes) {
//在数据库找到对应的对象
UpdateTime updateTimeMy = updateTimeService.getById(updateTime.getUpdateTimeId());
if (updateTimeMy != null) {
//1.修改科目
//判断前端传递与自身信息是否相等
if (!updateTime.getProjectType().equals(updateTimeMy.getProjectType())) {
log.info('修改科目');
//通过修改时间段id和当前时间(08:00)查询(待训练)课程信息
List<CourseDto> courseInfos = courseInfoService.queryCourseByUpdateTimeIdByStatus0(updateTime.getUpdateTimeId());
//存放待训练的课程
for (CourseDto courseDto0 : courseInfos) {
if (courseDto0.getCourseDate().equals(RcqtUtils.getDay())) {
if (LocalTime.now().isBefore(courseDto0.getStartReservationTime().toLocalTime())) {
courseDtoListByAll.add(courseDto0);
}
} else if (courseDto0.getCourseDate().after(RcqtUtils.getDay())) {
courseDtoListByAll.add(courseDto0);
}
}
boolean shouldUpdateProjectType = true;
for (CourseDto courseDto : courseDtoListByAll) {
if (courseDto.getDrivingProjectType().equals('科二/科三')) {
break;
} else if (updateTime.getProjectType().equals('科二/科三')) {
break;
} else if (!courseDto.getDrivingProjectType().equals(updateTime.getProjectType())) {
shouldUpdateProjectType = false;
break;
}
}
if (shouldUpdateProjectType) {
log.info('当前无预约学员,直接修改');
//当前没有预约的学员
updateTimeMy.setProjectType(updateTime.getProjectType());
}
}
}
updateTimeMyList.add(updateTimeMy);
}
if (!courseDtoListByAll.isEmpty()) {
//处理通知逻辑
Map<Long, List<CourseDto>> fieldMap = courseDtoListByAll.stream()
.collect(Collectors.groupingBy(CourseDto::getUpdateTimeId));
List<NoticeDto> newObjects = fieldMap.entrySet().stream()
.map(entry -> {
Long field = entry.getKey();
List<CourseDto> values = entry.getValue();;
CourseDto courseDto = values.get(0);
return new NoticeDto(field, courseDto,values);
})
.collect(Collectors.toList());
log.info('通知');
map.put('courseInfos', newObjects);
return new Result<>(ResultCode.NOTICE_COACH, map);
} else {
boolean b = updateTimeService.updateBatchById(updateTimeMyList);
if (b) {
log.info('修改时间段信息成功!');
return new Result<>(ResultCode.SUCCESS);
} else {
log.error('修改时间段信息失败!');
return new Result<>(ResultCode.FAIL);
}
}
</code></pre>
<p>}</p>
原文地址: https://www.cveoy.top/t/topic/qojj 著作权归作者所有。请勿转载和采集!