|
|
@@ -13,6 +13,7 @@ import com.fs.common.utils.poi.ExcelUtil;
|
|
|
import com.fs.course.config.CourseConfig;
|
|
|
import com.fs.course.domain.FsCourseQuestionBank;
|
|
|
import com.fs.course.dto.FsCourseQuestionBankImportDTO;
|
|
|
+import com.fs.course.dto.ImportResultDTO;
|
|
|
import com.fs.course.service.IFsCourseQuestionBankService;
|
|
|
import com.fs.framework.web.service.TokenService;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
@@ -21,7 +22,9 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 题库Controller
|
|
|
@@ -80,6 +83,15 @@ public class FsCourseQuestionBankController extends BaseController
|
|
|
return util.exportExcel(list, "题库数据");
|
|
|
}
|
|
|
|
|
|
+ @PreAuthorize("@ss.hasPermi('course:courseQuestionBank:exportFail')")
|
|
|
+ @Log(title = "题库", businessType = BusinessType.EXPORT)
|
|
|
+ @PostMapping("/exportFail")
|
|
|
+ public AjaxResult export( @RequestBody List<FsCourseQuestionBankImportDTO> list)
|
|
|
+ {
|
|
|
+ ExcelUtil<FsCourseQuestionBankImportDTO> util = new ExcelUtil<>(FsCourseQuestionBankImportDTO.class);
|
|
|
+ return util.exportExcel(list, "题库错误数据");
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取题库详细信息
|
|
|
*/
|
|
|
@@ -144,19 +156,34 @@ public class FsCourseQuestionBankController extends BaseController
|
|
|
@PreAuthorize("@ss.hasPermi('course:courseQuestionBank:importData')")
|
|
|
@PostMapping("/importData")
|
|
|
public AjaxResult importData(MultipartFile file) throws Exception {
|
|
|
- ExcelUtil<FsCourseQuestionBankImportDTO> util = new ExcelUtil<>(FsCourseQuestionBankImportDTO.class);
|
|
|
- List<FsCourseQuestionBankImportDTO> list = util.importExcel(file.getInputStream());
|
|
|
+
|
|
|
+ ExcelUtil<FsCourseQuestionBankImportDTO> util =
|
|
|
+ new ExcelUtil<>(FsCourseQuestionBankImportDTO.class);
|
|
|
+ List<FsCourseQuestionBankImportDTO> list =
|
|
|
+ util.importExcel(file.getInputStream());
|
|
|
|
|
|
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
|
|
Long userId = loginUser.getUser().getUserId();
|
|
|
+
|
|
|
+ // 读取配置
|
|
|
String json = configService.selectConfigByKey("course.config");
|
|
|
CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
|
|
|
- if (ObjectUtil.isNotEmpty(config.getIsBound())&&config.getIsBound()){
|
|
|
- String message = fsCourseQuestionBankService.importData(list, loginUser.getUser().getNickName(),userId);
|
|
|
- return AjaxResult.success(message);
|
|
|
- }
|
|
|
- String message = fsCourseQuestionBankService.importData(list, loginUser.getUser().getNickName(),null);
|
|
|
- return AjaxResult.success(message);
|
|
|
+
|
|
|
+ // 绑定状态控制 userId
|
|
|
+ Long finalUserId = (ObjectUtil.isNotEmpty(config.getIsBound()) && config.getIsBound())
|
|
|
+ ? userId
|
|
|
+ : null;
|
|
|
+
|
|
|
+ // 调用 service
|
|
|
+ ImportResultDTO result =
|
|
|
+ fsCourseQuestionBankService.importData(list, loginUser.getUser().getNickName(), finalUserId);
|
|
|
+
|
|
|
+ // 返回 message + failList
|
|
|
+ Map<String, Object> resp = new HashMap<>();
|
|
|
+ resp.put("message", result.buildResultMessage());
|
|
|
+ resp.put("failList", result.getFailureList());
|
|
|
+
|
|
|
+ return AjaxResult.success(resp);
|
|
|
}
|
|
|
|
|
|
@GetMapping(value = "/getByIds")
|