实现waiTeacher和Student批量分组接口
This commit is contained in:
parent
1df6d0f7dd
commit
2bcc2b3858
|
@ -17,6 +17,7 @@ import org.springframework.web.servlet.ModelAndView;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 外校老师管理
|
* @Description: 外校老师管理
|
||||||
|
@ -85,6 +86,17 @@ public class CeesWaiTeacherController extends JeecgController<CeesWaiTeacher, IC
|
||||||
return Result.OK(ceesWaiTeacherService.queryPageList(ceesWaiTeacher,pageNo,pageSize,req));
|
return Result.OK(ceesWaiTeacherService.queryPageList(ceesWaiTeacher,pageNo,pageSize,req));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量分组
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/batchGroup")
|
||||||
|
public Result<?> batchGroup(@RequestBody Map<String, Object> webData){
|
||||||
|
log.info(webData.toString());
|
||||||
|
return ceesWaiTeacherService.batchGroup(webData);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加
|
* 添加
|
||||||
*
|
*
|
||||||
|
|
|
@ -21,6 +21,7 @@ import org.springframework.web.servlet.ModelAndView;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 研究生表
|
* @Description: 研究生表
|
||||||
|
@ -114,6 +115,16 @@ public class StudentController extends JeecgController<Student, IStudentService>
|
||||||
this.studentService.removeByIds(Arrays.asList(ids.split(",")));
|
this.studentService.removeByIds(Arrays.asList(ids.split(",")));
|
||||||
return Result.OK("批量删除成功!");
|
return Result.OK("批量删除成功!");
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 批量分组
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/batchGroup")
|
||||||
|
public Result<?> batchGroup(@RequestBody Map<String, Object> webData){
|
||||||
|
log.info(webData.toString());
|
||||||
|
return studentService.batchGroup(webData);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过id查询
|
* 通过id查询
|
||||||
|
|
|
@ -8,6 +8,7 @@ import org.jeecg.modules.entity.CeesWaiTeacher;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 外校老师管理
|
* @Description: 外校老师管理
|
||||||
|
@ -31,4 +32,6 @@ public interface ICeesWaiTeacherService extends IService<CeesWaiTeacher> {
|
||||||
Result<?> h5Save(CeesWaiTeacher ceesWaiTeacher);
|
Result<?> h5Save(CeesWaiTeacher ceesWaiTeacher);
|
||||||
|
|
||||||
Result<?> getDormitoryName(String dormitoryId);
|
Result<?> getDormitoryName(String dormitoryId);
|
||||||
|
|
||||||
|
Result<?> batchGroup(Map<String, Object> webData);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.api.vo.Result;
|
||||||
import org.jeecg.modules.entity.Student;
|
import org.jeecg.modules.entity.Student;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 研究生表
|
* @Description: 研究生表
|
||||||
* @Author: jeecg-boot
|
* @Author: jeecg-boot
|
||||||
|
@ -13,4 +15,6 @@ import org.jeecg.modules.entity.Student;
|
||||||
public interface IStudentService extends IService<Student> {
|
public interface IStudentService extends IService<Student> {
|
||||||
|
|
||||||
Result<?> h5Save(Student student);
|
Result<?> h5Save(Student student);
|
||||||
|
|
||||||
|
Result<?> batchGroup(Map<String, Object> webData);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ package org.jeecg.modules.service.impl;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
@ -12,6 +13,7 @@ import lombok.RequiredArgsConstructor;
|
||||||
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.api.vo.Result;
|
||||||
import org.jeecg.common.system.query.QueryGenerator;
|
import org.jeecg.common.system.query.QueryGenerator;
|
||||||
import org.jeecg.modules.entity.CeesDormitoryInfo;
|
import org.jeecg.modules.entity.CeesDormitoryInfo;
|
||||||
|
import org.jeecg.modules.entity.CeesLocalTeacher;
|
||||||
import org.jeecg.modules.entity.CeesUser;
|
import org.jeecg.modules.entity.CeesUser;
|
||||||
import org.jeecg.modules.entity.CeesWaiTeacher;
|
import org.jeecg.modules.entity.CeesWaiTeacher;
|
||||||
import org.jeecg.modules.enums.MajorEnum;
|
import org.jeecg.modules.enums.MajorEnum;
|
||||||
|
@ -23,7 +25,9 @@ import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -159,4 +163,78 @@ public class CeesWaiTeacherServiceImpl extends ServiceImpl<CeesWaiTeacherMapper,
|
||||||
public Result<?> getDormitoryName(String dormitoryId) {
|
public Result<?> getDormitoryName(String dormitoryId) {
|
||||||
return Result.ok(ceesDormitoryInfoMapper.selectById(dormitoryId).getDormitory());
|
return Result.ok(ceesDormitoryInfoMapper.selectById(dormitoryId).getDormitory());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<?> batchGroup(Map<String, Object> webData) {
|
||||||
|
String groupId = webData.get("groupId").toString();
|
||||||
|
Object idsObj = webData.get("ids");
|
||||||
|
List<String> ids = JSONObject.parseArray(idsObj.toString(), String.class);
|
||||||
|
|
||||||
|
// 记录更新结果
|
||||||
|
int totalUpdatedLocal = 0;
|
||||||
|
List<String> failedIdsLocal = new ArrayList<>();
|
||||||
|
//更新具体的用户数据
|
||||||
|
for (String id : ids) {
|
||||||
|
try {
|
||||||
|
LambdaUpdateWrapper<CeesWaiTeacher> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
updateWrapper.eq(CeesWaiTeacher::getId, id)
|
||||||
|
.set(CeesWaiTeacher::getGroupId, groupId);
|
||||||
|
|
||||||
|
// 执行更新并检查受影响行数
|
||||||
|
int affectedRows = ceesWaiTeacherMapper.update(null, updateWrapper);
|
||||||
|
|
||||||
|
if (affectedRows > 0) {
|
||||||
|
totalUpdatedLocal++;
|
||||||
|
} else {
|
||||||
|
failedIdsLocal.add(id); // 记录未更新的ID(可能用户不存在或groupId未变)
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
failedIdsLocal.add(id); // 记录更新失败的ID
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 记录更新结果
|
||||||
|
int totalUpdated = 0;
|
||||||
|
List<String> failedIds = new ArrayList<>();
|
||||||
|
//更新所以表中的用户数据
|
||||||
|
for (String id : ids) {
|
||||||
|
try {
|
||||||
|
LambdaQueryWrapper<CeesWaiTeacher> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(CeesWaiTeacher::getId, id);
|
||||||
|
CeesWaiTeacher ceesLocalTeacher = ceesWaiTeacherMapper.selectOne(queryWrapper);
|
||||||
|
String user_id = ceesLocalTeacher.getUserId();
|
||||||
|
LambdaUpdateWrapper<CeesUser> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
updateWrapper.eq(CeesUser::getUserId, user_id)
|
||||||
|
.set(CeesUser::getGroupId, groupId);
|
||||||
|
// 执行更新并检查受影响行数
|
||||||
|
int affectedRows = ceesUserMapper.update(null, updateWrapper);
|
||||||
|
|
||||||
|
if (affectedRows > 0) {
|
||||||
|
totalUpdated++;
|
||||||
|
} else {
|
||||||
|
failedIds.add(id); // 记录未更新的ID(可能用户不存在或groupId未变)
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
failedIds.add(id); // 记录更新失败的ID
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建返回结果
|
||||||
|
JSONObject resultJson = new JSONObject();
|
||||||
|
//update-localTeacher
|
||||||
|
JSONObject localTeacherJson = new JSONObject();
|
||||||
|
localTeacherJson.put("totalUpdated", totalUpdatedLocal);
|
||||||
|
localTeacherJson.put("failedIds", failedIdsLocal);
|
||||||
|
localTeacherJson.put("success", failedIdsLocal.isEmpty()); // 是否全部成功
|
||||||
|
//update-User
|
||||||
|
JSONObject userJson = new JSONObject();
|
||||||
|
userJson.put("totalUpdated", totalUpdated);
|
||||||
|
userJson.put("failedIds", failedIds);
|
||||||
|
userJson.put("success", failedIds.isEmpty()); // 是否全部成功
|
||||||
|
|
||||||
|
resultJson.put("localTeacher", localTeacherJson);
|
||||||
|
resultJson.put("user", userJson);
|
||||||
|
return Result.ok(resultJson);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,11 @@ package org.jeecg.modules.service.impl;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.api.vo.Result;
|
||||||
import org.jeecg.modules.entity.CeesUser;
|
import org.jeecg.modules.entity.CeesUser;
|
||||||
|
import org.jeecg.modules.entity.CeesWaiTeacher;
|
||||||
import org.jeecg.modules.entity.Student;
|
import org.jeecg.modules.entity.Student;
|
||||||
import org.jeecg.modules.mapper.CeesUserMapper;
|
import org.jeecg.modules.mapper.CeesUserMapper;
|
||||||
import org.jeecg.modules.mapper.StudentMapper;
|
import org.jeecg.modules.mapper.StudentMapper;
|
||||||
|
@ -14,6 +16,9 @@ import org.jeecg.modules.service.IStudentService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 研究生表
|
* @Description: 研究生表
|
||||||
|
@ -27,6 +32,8 @@ public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> impl
|
||||||
CeesUserMapper ceesUserMapper;
|
CeesUserMapper ceesUserMapper;
|
||||||
@Resource
|
@Resource
|
||||||
ICeesUserService ceesUserService;
|
ICeesUserService ceesUserService;
|
||||||
|
@Resource
|
||||||
|
StudentMapper studentMapper;
|
||||||
/**
|
/**
|
||||||
* @param student
|
* @param student
|
||||||
* @return
|
* @return
|
||||||
|
@ -48,4 +55,78 @@ public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> impl
|
||||||
jsonObject.put("router", "/mainPage");
|
jsonObject.put("router", "/mainPage");
|
||||||
return Result.ok(jsonObject);
|
return Result.ok(jsonObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<?> batchGroup(Map<String, Object> webData) {
|
||||||
|
String groupId = webData.get("groupId").toString();
|
||||||
|
Object idsObj = webData.get("ids");
|
||||||
|
List<String> ids = JSONObject.parseArray(idsObj.toString(), String.class);
|
||||||
|
|
||||||
|
// 记录更新结果
|
||||||
|
int totalUpdatedLocal = 0;
|
||||||
|
List<String> failedIdsLocal = new ArrayList<>();
|
||||||
|
//更新具体的用户数据
|
||||||
|
for (String id : ids) {
|
||||||
|
try {
|
||||||
|
LambdaUpdateWrapper<Student> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
updateWrapper.eq(Student::getId, id)
|
||||||
|
.set(Student::getGroupId, groupId);
|
||||||
|
|
||||||
|
// 执行更新并检查受影响行数
|
||||||
|
int affectedRows = studentMapper.update(null, updateWrapper);
|
||||||
|
|
||||||
|
if (affectedRows > 0) {
|
||||||
|
totalUpdatedLocal++;
|
||||||
|
} else {
|
||||||
|
failedIdsLocal.add(id); // 记录未更新的ID(可能用户不存在或groupId未变)
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
failedIdsLocal.add(id); // 记录更新失败的ID
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 记录更新结果
|
||||||
|
int totalUpdated = 0;
|
||||||
|
List<String> failedIds = new ArrayList<>();
|
||||||
|
//更新所以表中的用户数据
|
||||||
|
for (String id : ids) {
|
||||||
|
try {
|
||||||
|
LambdaQueryWrapper<Student> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(Student::getId, id);
|
||||||
|
Student Student = studentMapper.selectOne(queryWrapper);
|
||||||
|
String user_id = Student.getUserId();
|
||||||
|
LambdaUpdateWrapper<CeesUser> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
updateWrapper.eq(CeesUser::getUserId, user_id)
|
||||||
|
.set(CeesUser::getGroupId, groupId);
|
||||||
|
// 执行更新并检查受影响行数
|
||||||
|
int affectedRows = ceesUserMapper.update(null, updateWrapper);
|
||||||
|
|
||||||
|
if (affectedRows > 0) {
|
||||||
|
totalUpdated++;
|
||||||
|
} else {
|
||||||
|
failedIds.add(id); // 记录未更新的ID(可能用户不存在或groupId未变)
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
failedIds.add(id); // 记录更新失败的ID
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建返回结果
|
||||||
|
JSONObject resultJson = new JSONObject();
|
||||||
|
//update-localTeacher
|
||||||
|
JSONObject localTeacherJson = new JSONObject();
|
||||||
|
localTeacherJson.put("totalUpdated", totalUpdatedLocal);
|
||||||
|
localTeacherJson.put("failedIds", failedIdsLocal);
|
||||||
|
localTeacherJson.put("success", failedIdsLocal.isEmpty()); // 是否全部成功
|
||||||
|
//update-User
|
||||||
|
JSONObject userJson = new JSONObject();
|
||||||
|
userJson.put("totalUpdated", totalUpdated);
|
||||||
|
userJson.put("failedIds", failedIds);
|
||||||
|
userJson.put("success", failedIds.isEmpty()); // 是否全部成功
|
||||||
|
|
||||||
|
resultJson.put("localTeacher", localTeacherJson);
|
||||||
|
resultJson.put("user", userJson);
|
||||||
|
return Result.ok(resultJson);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue