beetlsql3-dev
Mlxa0324 2 years ago
parent 222d265cce
commit b6900aae0b

@ -9,7 +9,8 @@ public enum JsonReturnCode {
SUCCESS ("200","成功"), SUCCESS ("200","成功"),
FAIL ("500","内部失败"), FAIL ("500","内部失败"),
ACCESS_ERROR ("403","禁止访问"), ACCESS_ERROR ("403","禁止访问"),
NOT_FOUND ("404","页面未发现"); NOT_FOUND ("404","页面未发现"),
DIY_ERROR ("5000","自定义异常");
private String code; private String code;
private String desc; private String desc;

@ -46,6 +46,7 @@ import static cn.hutool.core.util.ObjectUtil.defaultIfNull;
import static cn.jlw.util.CacheUserUtil.getStudent; import static cn.jlw.util.CacheUserUtil.getStudent;
import static com.ibeetl.admin.console.service.OrgConsoleService.setObjectOrgId; import static com.ibeetl.admin.console.service.OrgConsoleService.setObjectOrgId;
import static com.ibeetl.admin.core.util.user.CacheUserUtil.getUser; import static com.ibeetl.admin.core.util.user.CacheUserUtil.getUser;
import static com.ibeetl.admin.core.web.JsonReturnCode.DIY_ERROR;
/** /**
* SchoolClass * SchoolClass
@ -303,43 +304,48 @@ public class SchoolClassController extends BaseController {
@ResponseBody @ResponseBody
public JsonResult importBatchTemplate(@NotNull(message = "导入的文件不能为空!") MultipartFile file, @SCoreUser CoreUser coreUser) { public JsonResult importBatchTemplate(@NotNull(message = "导入的文件不能为空!") MultipartFile file, @SCoreUser CoreUser coreUser) {
Assert.isNull(getStudent(), "学生无法访问该接口"); try {
Assert.isNull(getStudent(), "学生无法访问该接口");
// 输出 Excel // 输出 Excel
MyValidateExcelCellDataListener<SchoolClassBatchImportDTO> listener = new MyValidateExcelCellDataListener<>(); MyValidateExcelCellDataListener<SchoolClassBatchImportDTO> listener = new MyValidateExcelCellDataListener<>();
ExcelUtil.readExcelNotContainHeader(file, SchoolClassBatchImportDTO.class, listener); ExcelUtil.readExcelNotContainHeader(file, SchoolClassBatchImportDTO.class, listener);
// 判断错误的结果集 // 判断错误的结果集
Assert.isTrue(CollectionUtil.isEmpty(listener.getFailMessage()), JSONUtil.toJsonStr(listener.getFailMessage())); Assert.isTrue(CollectionUtil.isEmpty(listener.getFailMessage()), JSONUtil.toJsonStr(listener.getFailMessage()));
// 类型转换 // 类型转换
List<SchoolClass> classList = listener.getData().stream() List<SchoolClass> classList = listener.getData().stream()
// .map(item -> SchoolClassBatchImportDTO.pojo(item, (e) -> e)) // .map(item -> SchoolClassBatchImportDTO.pojo(item, (e) -> e))
.map(SchoolClassBatchImportDTO::pojo) .map(SchoolClassBatchImportDTO::pojo)
.collect(Collectors.toList()); .collect(Collectors.toList());
// 设置机构ID // 设置机构ID
setObjectOrgId(classList, (e) -> { setObjectOrgId(classList, (e) -> {
UniversitiesColleges universitiesColleges = new UniversitiesColleges(); UniversitiesColleges universitiesColleges = new UniversitiesColleges();
universitiesColleges.setUniversitiesCollegesId(e.getUniversitiesCollegesId()); universitiesColleges.setUniversitiesCollegesId(e.getUniversitiesCollegesId());
UniversitiesColleges uc = universitiesCollegesDao.templateOne(universitiesColleges); UniversitiesColleges uc = universitiesCollegesDao.templateOne(universitiesColleges);
if (uc != null) { if (uc != null) {
return uc.getOrgId(); return uc.getOrgId();
}
return null;
}, true);
try {
schoolClassService.validateClassSnListIsExistsThrow(classList);
}
catch (IllegalArgumentException e) {
listener.putFailMessage(e.getMessage());
}
finally {
// 再次判断错误的结果集
Assert.isTrue(CollectionUtil.isEmpty(listener.getFailMessage()), JSONUtil.toJsonStr(listener.getFailMessage()));
} }
return null;
}, true);
try { schoolClassService.insertBatch(classList);
schoolClassService.validateClassSnListIsExistsThrow(classList);
} }
catch (IllegalArgumentException e) { catch (IllegalArgumentException exception) {
listener.putFailMessage(e.getMessage()); return JsonResult.failMessage(exception.getMessage()).setCode(DIY_ERROR.getCode());
} }
finally {
// 再次判断错误的结果集
Assert.isTrue(CollectionUtil.isEmpty(listener.getFailMessage()), JSONUtil.toJsonStr(listener.getFailMessage()));
}
schoolClassService.insertBatch(classList);
return JsonResult.successMessage("导入成功!"); return JsonResult.successMessage("导入成功!");
} }

@ -66,6 +66,7 @@ import static com.ibeetl.admin.console.service.OrgConsoleService.setObjectOrgId;
import static com.ibeetl.admin.core.util.ExcelUtil.convertData; import static com.ibeetl.admin.core.util.ExcelUtil.convertData;
import static com.ibeetl.admin.core.util.ExcelUtil.write; import static com.ibeetl.admin.core.util.ExcelUtil.write;
import static com.ibeetl.admin.core.util.user.CacheUserUtil.getUser; import static com.ibeetl.admin.core.util.user.CacheUserUtil.getUser;
import static com.ibeetl.admin.core.web.JsonReturnCode.DIY_ERROR;
import static com.ibeetl.jlw.web.IpAddressController.ipAddressMap; import static com.ibeetl.jlw.web.IpAddressController.ipAddressMap;
@ -2802,43 +2803,47 @@ public class StudentController extends BaseController{
@ResponseBody @ResponseBody
public JsonResult importBatchTemplate(@NotNull(message = "导入的文件不能为空!") MultipartFile file, @SCoreUser CoreUser coreUser) { public JsonResult importBatchTemplate(@NotNull(message = "导入的文件不能为空!") MultipartFile file, @SCoreUser CoreUser coreUser) {
Assert.isNull(getStudent(), "学生无法访问该接口"); try {
Assert.isNull(getStudent(), "学生无法访问该接口");
// 输出 Excel // 输出 Excel
MyValidateExcelCellDataListener<StudentBatchImportDTO> listener = new MyValidateExcelCellDataListener<>(); MyValidateExcelCellDataListener<StudentBatchImportDTO> listener = new MyValidateExcelCellDataListener<>();
ExcelUtil.readExcelNotContainHeader(file, StudentBatchImportDTO.class, listener);
// 判断错误的结果集
Assert.isTrue(CollectionUtil.isEmpty(listener.getFailMessage()), JSONUtil.toJsonStr(listener.getFailMessage()));
// 类型转换
List<Student> list = listener.getData().stream().map(StudentBatchImportDTO::pojo)
.collect(Collectors.toList());
// 设置机构ID
setObjectOrgId(list, (e) -> {
SchoolClass params = new SchoolClass();
params.setClassId(e.getClassId());
params.setClassStatus(1);
SchoolClass sc = schoolClassDao.templateOne(params);
if (sc != null) {
return sc.getOrgId();
}
return null;
}, true);
try { ExcelUtil.readExcelNotContainHeader(file, StudentBatchImportDTO.class, listener);
studentService.validateStudentSnListIsExistsThrow(list); // 判断错误的结果集
}
catch (IllegalArgumentException e) {
listener.putFailMessage(e.getMessage());
}
finally {
// 再次判断错误的结果集
Assert.isTrue(CollectionUtil.isEmpty(listener.getFailMessage()), JSONUtil.toJsonStr(listener.getFailMessage())); Assert.isTrue(CollectionUtil.isEmpty(listener.getFailMessage()), JSONUtil.toJsonStr(listener.getFailMessage()));
} // 类型转换
List<Student> list = listener.getData().stream().map(StudentBatchImportDTO::pojo)
.collect(Collectors.toList());
// 设置机构ID
setObjectOrgId(list, (e) -> {
SchoolClass params = new SchoolClass();
params.setClassId(e.getClassId());
params.setClassStatus(1);
SchoolClass sc = schoolClassDao.templateOne(params);
if (sc != null) {
return sc.getOrgId();
}
return null;
}, true);
studentService.insertBatch(list); try {
studentService.validateStudentSnListIsExistsThrow(list);
}
catch (IllegalArgumentException e) {
listener.putFailMessage(e.getMessage());
}
finally {
// 再次判断错误的结果集
Assert.isTrue(CollectionUtil.isEmpty(listener.getFailMessage()), JSONUtil.toJsonStr(listener.getFailMessage()));
}
studentService.insertBatch(list);
}
catch (IllegalArgumentException exception) {
return JsonResult.failMessage(exception.getMessage()).setCode(DIY_ERROR.getCode());
}
return JsonResult.successMessage("导入成功!"); return JsonResult.successMessage("导入成功!");
} }
} }

@ -58,6 +58,7 @@ import java.util.stream.Collectors;
import static cn.jlw.util.CacheUserUtil.getStudent; import static cn.jlw.util.CacheUserUtil.getStudent;
import static com.ibeetl.admin.core.util.user.CacheUserUtil.getUser; import static com.ibeetl.admin.core.util.user.CacheUserUtil.getUser;
import static com.ibeetl.admin.core.web.JsonReturnCode.DIY_ERROR;
/** /**
* --线 * --线
@ -511,22 +512,27 @@ public class TeacherOpenCourseMergeResourcesQuestionController extends BaseContr
@PostMapping(API + "/importBatchTemplate.do") @PostMapping(API + "/importBatchTemplate.do")
public JsonResult importBatchTemplate(@NotNull(message = "导入的文件不能为空!") MultipartFile file, @SCoreUser CoreUser coreUser) { public JsonResult importBatchTemplate(@NotNull(message = "导入的文件不能为空!") MultipartFile file, @SCoreUser CoreUser coreUser) {
Assert.isNull(getStudent(), "学生无法访问该接口"); try {
Assert.isNull(getStudent(), "学生无法访问该接口");
// 输出 Excel // 输出 Excel
MyValidateExcelCellDataListener<TeacherOpenCourseMergeResourcesQuestionImport> listener = new MyValidateExcelCellDataListener<>(); MyValidateExcelCellDataListener<TeacherOpenCourseMergeResourcesQuestionImport> listener = new MyValidateExcelCellDataListener<>();
ExcelUtil.readExcelNotContainHeader(file, TeacherOpenCourseMergeResourcesQuestionImport.class, listener); ExcelUtil.readExcelNotContainHeader(file, TeacherOpenCourseMergeResourcesQuestionImport.class, listener);
// 判断错误的结果集 // 判断错误的结果集
Assert.isTrue(CollectionUtil.isEmpty(listener.getFailMessage()), JSONUtil.toJsonStr(listener.getFailMessage())); Assert.isTrue(CollectionUtil.isEmpty(listener.getFailMessage()), JSONUtil.toJsonStr(listener.getFailMessage()));
// 类型转换 // 类型转换
List<TeacherOpenCourseMergeResourcesQuestion> options = listener.getData().stream() List<TeacherOpenCourseMergeResourcesQuestion> options = listener.getData().stream()
.map(TeacherOpenCourseMergeResourcesQuestionImport::pojo).collect(Collectors.toList()); .map(TeacherOpenCourseMergeResourcesQuestionImport::pojo).collect(Collectors.toList());
// 只复制用户ID和组织ID // 只复制用户ID和组织ID
BeanUtil.beanPropertyCopyToList(coreUser, options, MapUtil.of("id", "userId"), "userId", "orgId"); BeanUtil.beanPropertyCopyToList(coreUser, options, MapUtil.of("id", "userId"), "userId", "orgId");
teacherOpenCourseMergeResourcesQuestionService.insertBatch(options); teacherOpenCourseMergeResourcesQuestionService.insertBatch(options);
}
catch (IllegalArgumentException exception) {
return JsonResult.failMessage(exception.getMessage()).setCode(DIY_ERROR.getCode());
}
return JsonResult.successMessage("导入成功!"); return JsonResult.successMessage("导入成功!");
} }

Loading…
Cancel
Save