批量修改时间段信息 - 有预约学员则弹窗提醒,无预约学员则直接修改
<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> courseDtoListByNow = 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())) {
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("科二/科三") || updateTime.getProjectType().equals("科二/科三")) {
updateTimeMy.setProjectType(updateTime.getProjectType());
} else if (!carUser.getDrivingProjectType().equals(updateTime.getProjectType())) {
if (Objects.equals(carUser.getUserId(), courseDto.getUserId())){
courseDtoListByAll.add(courseDto);
}
}
}
} else {
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();
List<CarUser> 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("通知");
map.put("courseInfos", newObjects);
return new Result<>(ResultCode.NOTICE_COACH, map);
}
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/qohQ 著作权归作者所有。请勿转载和采集!