From 19c8409164eb0a2171f3d6ef09ac66373aaf8253 Mon Sep 17 00:00:00 2001 From: xiaoCJ <406612557@qq.com> Date: Fri, 19 Jul 2024 10:57:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=89=E6=96=B9=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=8C=E4=BF=AE=E6=94=B9bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/api/ObjectiveApi.java | 51 +++- .../new_module/admin/AdminCaseController.java | 269 +++++++++++++----- 2 files changed, 239 insertions(+), 81 deletions(-) diff --git a/src/main/java/com/sztzjy/resource_center/controller/api/ObjectiveApi.java b/src/main/java/com/sztzjy/resource_center/controller/api/ObjectiveApi.java index e216880..759042c 100644 --- a/src/main/java/com/sztzjy/resource_center/controller/api/ObjectiveApi.java +++ b/src/main/java/com/sztzjy/resource_center/controller/api/ObjectiveApi.java @@ -1,7 +1,6 @@ package com.sztzjy.resource_center.controller.api; import cn.hutool.core.util.IdUtil; -import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.sztzjy.resource_center.annotation.AnonymousAccess; import com.sztzjy.resource_center.entity.*; @@ -17,6 +16,7 @@ import io.swagger.annotations.ApiParam; import org.apache.commons.lang3.StringUtils; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.ss.usermodel.*; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; @@ -89,12 +89,6 @@ public class ObjectiveApi { SysOneCatalog sysOneCatalogs = getSysOneCatalogs(objectiveQuestion.getObjectiveId()); String oneId = sysOneCatalogs.getOneId(); - SysObjectiveQuestionsExample example = new SysObjectiveQuestionsExample(); - example.createCriteria().andContentEqualTo(objectiveQuestion.getContent()); - List sysObjectiveQuestions = sysObjectiveQuestionMapper.selectByExample(example); - if (!sysObjectiveQuestions.isEmpty()) { - return false; - } //新增题库表 String uuid = IdUtil.randomUUID(); objectiveQuestion.setObjectiveId(uuid); @@ -123,6 +117,26 @@ public class ObjectiveApi { } + @AnonymousAccess + @ApiOperation("客观题编辑") + @PostMapping("updateObjective") + private Boolean updateObjective(@RequestBody SysObjectiveQuestionsDto dto, + @RequestParam String systemOwner, + @RequestParam String schoolId) { + //ID不为空,修改绑定信息 + if (StringUtils.isNotBlank(dto.getTopicAndCourseId())) { + SysTopicAndCourse sysTopicAndCourse = new SysTopicAndCourse(); + BeanUtils.copyProperties(dto, sysTopicAndCourse); + sysTopicAndCourseMapper.updateByPrimaryKeySelective(sysTopicAndCourse); + } + //修改题库基础信息 + SysObjectiveQuestions newData = new SysObjectiveQuestions(); + BeanUtils.copyProperties(dto, newData); + sysObjectiveQuestionMapper.updateByPrimaryKeySelective(newData); + return true; + } + + /** * 客观题批量删除 * 方法名:batchDeleteObjective @@ -187,9 +201,28 @@ public class ObjectiveApi { @AnonymousAccess @ApiOperation("客观题单个详情查看") @PostMapping("selectObjectiveDetails") - private SysObjectiveQuestions selectObjectiveDetails(@RequestParam String objectiveId) { + private SysObjectiveQuestionsDto selectObjectiveDetails(@RequestParam String objectiveId, + @RequestParam String systemOwner, + @RequestParam String schoolId) { + SysOneCatalog sysOneCatalogs = getSysOneCatalogs(systemOwner); + + SysTopicAndCourseExample example = new SysTopicAndCourseExample(); + example.createCriteria().andTopicIdEqualTo(objectiveId).andOneIdEqualTo(sysOneCatalogs.getOneId()); + List sysTopicAndCourses = sysTopicAndCourseMapper.selectByExample(example); + SysObjectiveQuestionsDto dto = new SysObjectiveQuestionsDto(); + + if (sysTopicAndCourses != null && !sysTopicAndCourses.isEmpty()) { + SysTopicAndCourse sysTopicAndCourse = sysTopicAndCourses.get(0); + dto.setOneID(sysTopicAndCourse.getOneId()); + dto.setOneName(sysTopicAndCourse.getOneName()); + dto.setTwoID(sysTopicAndCourse.getTwoId()); + dto.setTwoName(sysTopicAndCourse.getTwoName()); + dto.setThreeName(sysTopicAndCourse.getThreeName()); + dto.setThreeID(sysTopicAndCourse.getThreeId()); + } SysObjectiveQuestions sysObjectiveQuestions = sysObjectiveQuestionMapper.selectByPrimaryKey(objectiveId); - return sysObjectiveQuestions; + BeanUtils.copyProperties(sysObjectiveQuestions, dto); + return dto; } /** diff --git a/src/main/java/com/sztzjy/resource_center/controller/new_module/admin/AdminCaseController.java b/src/main/java/com/sztzjy/resource_center/controller/new_module/admin/AdminCaseController.java index 387cbb9..cced201 100644 --- a/src/main/java/com/sztzjy/resource_center/controller/new_module/admin/AdminCaseController.java +++ b/src/main/java/com/sztzjy/resource_center/controller/new_module/admin/AdminCaseController.java @@ -3,6 +3,9 @@ package com.sztzjy.resource_center.controller.new_module.admin; import cn.hutool.core.util.IdUtil; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import com.google.common.reflect.TypeToken; +import com.nimbusds.jose.shaded.gson.Gson; +import com.nimbusds.jose.shaded.gson.JsonSyntaxException; import com.sztzjy.resource_center.annotation.AnonymousAccess; import com.sztzjy.resource_center.entity.admin.*; import com.sztzjy.resource_center.mapper.admin.AdminCaseMapper; @@ -14,12 +17,14 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.apache.commons.lang3.StringUtils; -import org.apache.ibatis.annotations.Param; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import java.util.ArrayList; @@ -46,93 +51,174 @@ public class AdminCaseController { private String filePath; - /* @PostMapping("add") +// /* @PostMapping("add") +// @ApiOperation("新增") //todo 案例目录和案例正文通过前端传路径过来 ,这里只存url +// @Transactional*/ +// ResultEntity add(@ModelAttribute AdminCaseDto adminCaseDto, +// @RequestParam String adminCaseDtoJson, +// @RequestParam MultipartFile pictureFile, +// @RequestParam List dataFile) { +// if (StringUtils.isBlank(adminCaseDto.getName())) { +// return new ResultEntity<>(HttpStatus.OK, "请输入名称!"); +// } +// if (adminCaseDto.getAdminLabelList() == null || adminCaseDto.getAdminLabelList().isEmpty()) { +// return new ResultEntity<>(HttpStatus.OK, "至少选择一个标签!"); +// } +// List adminLabelList = adminCaseDto.getAdminLabelList(); +// for (AdminLabel adminLabel : adminLabelList) { +// if (StringUtils.isBlank(adminLabel.getLabelId()) || StringUtils.isBlank(adminLabel.getName()) || StringUtils.isBlank(adminLabel.getType())) { +// return new ResultEntity<>(HttpStatus.OK, "标签数据不完整!"); +// } +// } +// if (StringUtils.isBlank(adminCaseDto.getCaseContent()) && adminCaseDto.getCaseContentFile() == null) { +// return new ResultEntity<>(HttpStatus.OK, "请输入内容或者上传文件!"); +// } +// +// //开始新增 +// AdminCaseWithBLOBs adminCase = new AdminCaseWithBLOBs(); +// String caseId = IdUtil.randomUUID(); +// adminCase.setId(caseId); +// adminCase.setName(adminCaseDto.getName()); +// adminCase.setStatus(0); //新增默认下架,发布后上架 +// adminCase.setSource(adminCaseDto.getSource()); +// adminCase.setCreateTime(new Date()); +// +// if (adminCaseDto.getPictureFile() != null) { +// String pictureUrl = fileUtil.upload(adminCaseDto.getPictureFile()); +// adminCase.setPictureUrl(pictureUrl); +// } +// +// //设置内容 +// if (adminCaseDto.getCaseContentFile() != null) { +// String contentUrl = fileUtil.upload(adminCaseDto.getCaseContentFile()); +// adminCase.setContent(contentUrl); //传的文件就存地址 +// } +// if (StringUtils.isNotBlank(adminCaseDto.getCaseContent())) { +// adminCase.setContent(adminCaseDto.getCaseContent()); +// } +// +// //设置目录 +// if (adminCaseDto.getCaseCatalogFile() != null) { +// String caseCatalogUrl = fileUtil.upload(adminCaseDto.getCaseCatalogFile()); +// adminCase.setCatalog(caseCatalogUrl); //传的文件就存地址 +// } +// if (StringUtils.isNotBlank(adminCaseDto.getCaseCatalog())) { +// adminCase.setCatalog(adminCaseDto.getCaseCatalog()); +// } +// +// //设置数据文件 +// if (adminCaseDto.getDataFile() != null && !adminCaseDto.getDataFile().isEmpty()) { +// List dataFileList = adminCaseDto.getDataFile(); +// List list = new ArrayList<>(); +// for (MultipartFile file : dataFileList) { +// AdminFile adminFile = new AdminFile(); +// adminFile.setFileId(IdUtil.randomUUID()); +// String pictureUrl = fileUtil.upload(file); +// String name = file.getName(); +// adminFile.setFileUrl(pictureUrl); +// adminFile.setName(name); +// adminFile.setSource("案例表"); +// adminFile.setDataCaseId(caseId); +// list.add(adminFile); +// } +// //批量新增数据文件 +// adminFileMapper.insertBatch(list); +// } +// +// List list = new ArrayList<>(); +// for (AdminLabel adminLabel : adminLabelList) { +// AdminDataLabel label = new AdminDataLabel(); +// label.setId(IdUtil.randomUUID()); +// label.setLabelId(adminLabel.getLabelId()); +// label.setName(adminLabel.getName()); +// label.setDataCaseId(adminCaseDto.getCaseId()); +// list.add(label); +// } +// //批量新增标签 +// adminDataLabelMapper.insertBatch(list); +// //新增案例 +// adminCaseMapper.insert(adminCase); +// return new ResultEntity<>(HttpStatus.OK, "新增成功!"); +// } + + @PostMapping("add") @ApiOperation("新增") //todo 案例目录和案例正文通过前端传路径过来 ,这里只存url - @Transactional*/ - ResultEntity add(@ModelAttribute AdminCaseDto adminCaseDto, - @RequestParam String adminCaseDtoJson, + @Transactional + ResultEntity add(@RequestParam String name, + @RequestParam String source, @RequestParam MultipartFile pictureFile, - @RequestParam List dataFile) { - if (StringUtils.isBlank(adminCaseDto.getName())) { + @RequestParam String adminLabelJson, + @RequestParam(required = false) List dataFile) { + Gson gson = new Gson(); + List adminLabelList = null; + try { + adminLabelList = gson.fromJson(adminLabelJson, new TypeToken>() { + }.getType()); + } catch (JsonSyntaxException e) { + e.printStackTrace(); + return new ResultEntity<>(HttpStatus.INTERNAL_SERVER_ERROR, "服务器错误,请联系管理员"); + } + if (StringUtils.isBlank(name)) { return new ResultEntity<>(HttpStatus.OK, "请输入名称!"); } - if (adminCaseDto.getAdminLabelList() == null || adminCaseDto.getAdminLabelList().isEmpty()) { + if (adminLabelList == null || adminLabelList.isEmpty()) { return new ResultEntity<>(HttpStatus.OK, "至少选择一个标签!"); } - List adminLabelList = adminCaseDto.getAdminLabelList(); for (AdminLabel adminLabel : adminLabelList) { if (StringUtils.isBlank(adminLabel.getLabelId()) || StringUtils.isBlank(adminLabel.getName()) || StringUtils.isBlank(adminLabel.getType())) { return new ResultEntity<>(HttpStatus.OK, "标签数据不完整!"); } } - if (StringUtils.isBlank(adminCaseDto.getCaseContent()) && adminCaseDto.getCaseContentFile() == null) { - return new ResultEntity<>(HttpStatus.OK, "请输入内容或者上传文件!"); - } - - //开始新增 - AdminCaseWithBLOBs adminCase = new AdminCaseWithBLOBs(); - String caseId = IdUtil.randomUUID(); - adminCase.setId(caseId); - adminCase.setName(adminCaseDto.getName()); - adminCase.setStatus(0); //新增默认下架,发布后上架 - adminCase.setSource(adminCaseDto.getSource()); - adminCase.setCreateTime(new Date()); - - if (adminCaseDto.getPictureFile() != null) { - String pictureUrl = fileUtil.upload(adminCaseDto.getPictureFile()); - adminCase.setPictureUrl(pictureUrl); - } - //设置内容 - if (adminCaseDto.getCaseContentFile() != null) { - String contentUrl = fileUtil.upload(adminCaseDto.getCaseContentFile()); - adminCase.setContent(contentUrl); //传的文件就存地址 - } - if (StringUtils.isNotBlank(adminCaseDto.getCaseContent())) { - adminCase.setContent(adminCaseDto.getCaseContent()); - } - - //设置目录 - if (adminCaseDto.getCaseCatalogFile() != null) { - String caseCatalogUrl = fileUtil.upload(adminCaseDto.getCaseCatalogFile()); - adminCase.setCatalog(caseCatalogUrl); //传的文件就存地址 - } - if (StringUtils.isNotBlank(adminCaseDto.getCaseCatalog())) { - adminCase.setCatalog(adminCaseDto.getCaseCatalog()); + AdminCaseWithBLOBs adminCaseWithBLOB = new AdminCaseWithBLOBs(); + String uuid = IdUtil.randomUUID(); + adminCaseWithBLOB.setId(uuid); + adminCaseWithBLOB.setSource(source); + adminCaseWithBLOB.setCreateTime(new Date()); + adminCaseWithBLOB.setStatus(0); //新增默认下架,发布后上架 + adminCaseWithBLOB.setName(name); + //设置图片 + if (pictureFile != null) { + String pictureUrl = fileUtil.upload(pictureFile); + adminCaseWithBLOB.setPictureUrl(pictureUrl); } //设置数据文件 - if (adminCaseDto.getDataFile() != null && !adminCaseDto.getDataFile().isEmpty()) { - List dataFileList = adminCaseDto.getDataFile(); + if (dataFile != null && !dataFile.isEmpty()) { List list = new ArrayList<>(); - for (MultipartFile file : dataFileList) { + for (MultipartFile file : dataFile) { AdminFile adminFile = new AdminFile(); adminFile.setFileId(IdUtil.randomUUID()); - String pictureUrl = fileUtil.upload(file); - String name = file.getName(); - adminFile.setFileUrl(pictureUrl); - adminFile.setName(name); - adminFile.setSource("案例表"); - adminFile.setDataCaseId(caseId); + String dataUrl = fileUtil.upload(file); + String fullFileName = file.getOriginalFilename(); + adminFile.setFileUrl(dataUrl); + adminFile.setName(fullFileName); + adminFile.setSource("数据表"); + adminFile.setDataCaseId(uuid); list.add(adminFile); } //批量新增数据文件 adminFileMapper.insertBatch(list); } + //批量新增标签 List list = new ArrayList<>(); for (AdminLabel adminLabel : adminLabelList) { AdminDataLabel label = new AdminDataLabel(); label.setId(IdUtil.randomUUID()); label.setLabelId(adminLabel.getLabelId()); label.setName(adminLabel.getName()); - label.setDataCaseId(adminCaseDto.getCaseId()); + label.setDataCaseId(uuid); + label.setType(adminLabel.getType()); list.add(label); } - //批量新增标签 - adminDataLabelMapper.insertBatch(list); - //新增案例 - adminCaseMapper.insert(adminCase); + try { + adminDataLabelMapper.insertBatch(list); + adminCaseMapper.insert(adminCaseWithBLOB); + } catch (Exception e) { + e.printStackTrace(); + return new ResultEntity<>(HttpStatus.INTERNAL_SERVER_ERROR, "新增失败!请联系管理员"); + } return new ResultEntity<>(HttpStatus.OK, "新增成功!"); } @@ -152,24 +238,63 @@ public class AdminCaseController { } - /* @PostMapping("updateAdminCase") - @ApiOperation("案例编辑")*/ - private ResultEntity updateAdminCase(@ModelAttribute AdminCaseDto adminCaseDto) { - List adminLabelList = adminCaseDto.getAdminLabelList(); - List dataFile = adminCaseDto.getDataFile(); - AdminCaseWithBLOBs adminCaseWithBLOBs = adminCaseMapper.selectByPrimaryKey(adminCaseDto.getCaseId()); + @PostMapping("updateAdminCase") + @ApiOperation("案例编辑/没改的参数别传") + @Transactional + ResultEntity updateAdminCase(@RequestParam String caseId, + @RequestParam(required = false) String name, + @RequestParam(required = false) MultipartFile pictureFile, + @RequestParam(required = false) String adminLabelJson) { + if (StringUtils.isBlank(name) + && pictureFile == null + && StringUtils.isBlank(adminLabelJson)) { + return null; + } - if (adminCaseDto.getPictureFile() != null) { - MultipartFile pictureFile = adminCaseDto.getPictureFile(); - String pictureUrl = fileUtil.upload(pictureFile); - adminCaseWithBLOBs.setPictureUrl(pictureUrl); + Gson gson = new Gson(); + List adminLabelList = null; + try { + if (StringUtils.isNotBlank(adminLabelJson)) { + adminLabelList = gson.fromJson(adminLabelJson, new TypeToken>() { + }.getType()); + } + } catch (JsonSyntaxException e) { + e.printStackTrace(); + return new ResultEntity<>(HttpStatus.INTERNAL_SERVER_ERROR, "服务器错误,请联系管理员"); } - if (adminCaseDto.getCaseCatalogFile() != null) { - MultipartFile pictureFile = adminCaseDto.getPictureFile(); - String pictureUrl = fileUtil.upload(pictureFile); - adminCaseWithBLOBs.setPictureUrl(pictureUrl); + + AdminCaseWithBLOBs adminCaseWithBLOBs = adminCaseMapper.selectByPrimaryKey(caseId); + if (pictureFile != null) { + String fileUrl = fileUtil.upload(pictureFile); + adminCaseWithBLOBs.setPictureUrl(fileUrl); } - return null; + if (StringUtils.isNotBlank(name)) { + adminCaseWithBLOBs.setName(name); + adminCaseMapper.updateByPrimaryKeySelective(adminCaseWithBLOBs); + } + if (adminLabelList != null && !adminLabelList.isEmpty()) { + List list = new ArrayList<>(); + for (AdminLabel adminLabel : adminLabelList) { + + if (StringUtils.isBlank(adminLabel.getLabelId()) || StringUtils.isBlank(adminLabel.getName()) || StringUtils.isBlank(adminLabel.getType())) { + return new ResultEntity<>(HttpStatus.OK, "标签数据不完整!"); + } else { + AdminDataLabelExample example = new AdminDataLabelExample(); + example.createCriteria().andDataCaseIdEqualTo(caseId); + adminDataLabelMapper.deleteByExample(example); + //批量新增标签 + AdminDataLabel label = new AdminDataLabel(); + label.setId(IdUtil.randomUUID()); + label.setLabelId(adminLabel.getLabelId()); + label.setName(adminLabel.getName()); + label.setDataCaseId(caseId); + label.setType(adminLabel.getType()); + list.add(label); + } + } + adminDataLabelMapper.insertBatch(list); + } + return new ResultEntity<>(HttpStatus.OK, "编辑成功!"); }