新增三方接口,修改bug

master
xiaoCJ 8 months ago
parent ac777fd62e
commit 19c8409164

@ -1,7 +1,6 @@
package com.sztzjy.resource_center.controller.api; package com.sztzjy.resource_center.controller.api;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.sztzjy.resource_center.annotation.AnonymousAccess; import com.sztzjy.resource_center.annotation.AnonymousAccess;
import com.sztzjy.resource_center.entity.*; import com.sztzjy.resource_center.entity.*;
@ -17,6 +16,7 @@ import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -89,12 +89,6 @@ public class ObjectiveApi {
SysOneCatalog sysOneCatalogs = getSysOneCatalogs(objectiveQuestion.getObjectiveId()); SysOneCatalog sysOneCatalogs = getSysOneCatalogs(objectiveQuestion.getObjectiveId());
String oneId = sysOneCatalogs.getOneId(); String oneId = sysOneCatalogs.getOneId();
SysObjectiveQuestionsExample example = new SysObjectiveQuestionsExample();
example.createCriteria().andContentEqualTo(objectiveQuestion.getContent());
List<SysObjectiveQuestions> sysObjectiveQuestions = sysObjectiveQuestionMapper.selectByExample(example);
if (!sysObjectiveQuestions.isEmpty()) {
return false;
}
//新增题库表 //新增题库表
String uuid = IdUtil.randomUUID(); String uuid = IdUtil.randomUUID();
objectiveQuestion.setObjectiveId(uuid); 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 * batchDeleteObjective
@ -187,9 +201,28 @@ public class ObjectiveApi {
@AnonymousAccess @AnonymousAccess
@ApiOperation("客观题单个详情查看") @ApiOperation("客观题单个详情查看")
@PostMapping("selectObjectiveDetails") @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<SysTopicAndCourse> 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); SysObjectiveQuestions sysObjectiveQuestions = sysObjectiveQuestionMapper.selectByPrimaryKey(objectiveId);
return sysObjectiveQuestions; BeanUtils.copyProperties(sysObjectiveQuestions, dto);
return dto;
} }
/** /**

@ -3,6 +3,9 @@ package com.sztzjy.resource_center.controller.new_module.admin;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; 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.annotation.AnonymousAccess;
import com.sztzjy.resource_center.entity.admin.*; import com.sztzjy.resource_center.entity.admin.*;
import com.sztzjy.resource_center.mapper.admin.AdminCaseMapper; 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.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils; 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.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.transaction.annotation.Transactional; 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 org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList; import java.util.ArrayList;
@ -46,93 +51,174 @@ public class AdminCaseController {
private String filePath; private String filePath;
/* @PostMapping("add") // /* @PostMapping("add")
// @ApiOperation("新增") //todo 案例目录和案例正文通过前端传路径过来 这里只存url
// @Transactional*/
// ResultEntity<String> add(@ModelAttribute AdminCaseDto adminCaseDto,
// @RequestParam String adminCaseDtoJson,
// @RequestParam MultipartFile pictureFile,
// @RequestParam List<MultipartFile> dataFile) {
// if (StringUtils.isBlank(adminCaseDto.getName())) {
// return new ResultEntity<>(HttpStatus.OK, "请输入名称!");
// }
// if (adminCaseDto.getAdminLabelList() == null || adminCaseDto.getAdminLabelList().isEmpty()) {
// return new ResultEntity<>(HttpStatus.OK, "至少选择一个标签!");
// }
// List<AdminLabel> 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<MultipartFile> dataFileList = adminCaseDto.getDataFile();
// List<AdminFile> 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<AdminDataLabel> 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 @ApiOperation("新增") //todo 案例目录和案例正文通过前端传路径过来 这里只存url
@Transactional*/ @Transactional
ResultEntity<String> add(@ModelAttribute AdminCaseDto adminCaseDto, ResultEntity<String> add(@RequestParam String name,
@RequestParam String adminCaseDtoJson, @RequestParam String source,
@RequestParam MultipartFile pictureFile, @RequestParam MultipartFile pictureFile,
@RequestParam List<MultipartFile> dataFile) { @RequestParam String adminLabelJson,
if (StringUtils.isBlank(adminCaseDto.getName())) { @RequestParam(required = false) List<MultipartFile> dataFile) {
Gson gson = new Gson();
List<AdminLabel> adminLabelList = null;
try {
adminLabelList = gson.fromJson(adminLabelJson, new TypeToken<List<AdminLabel>>() {
}.getType());
} catch (JsonSyntaxException e) {
e.printStackTrace();
return new ResultEntity<>(HttpStatus.INTERNAL_SERVER_ERROR, "服务器错误,请联系管理员");
}
if (StringUtils.isBlank(name)) {
return new ResultEntity<>(HttpStatus.OK, "请输入名称!"); return new ResultEntity<>(HttpStatus.OK, "请输入名称!");
} }
if (adminCaseDto.getAdminLabelList() == null || adminCaseDto.getAdminLabelList().isEmpty()) { if (adminLabelList == null || adminLabelList.isEmpty()) {
return new ResultEntity<>(HttpStatus.OK, "至少选择一个标签!"); return new ResultEntity<>(HttpStatus.OK, "至少选择一个标签!");
} }
List<AdminLabel> adminLabelList = adminCaseDto.getAdminLabelList();
for (AdminLabel adminLabel : adminLabelList) { for (AdminLabel adminLabel : adminLabelList) {
if (StringUtils.isBlank(adminLabel.getLabelId()) || StringUtils.isBlank(adminLabel.getName()) || StringUtils.isBlank(adminLabel.getType())) { if (StringUtils.isBlank(adminLabel.getLabelId()) || StringUtils.isBlank(adminLabel.getName()) || StringUtils.isBlank(adminLabel.getType())) {
return new ResultEntity<>(HttpStatus.OK, "标签数据不完整!"); 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);
}
//设置内容 AdminCaseWithBLOBs adminCaseWithBLOB = new AdminCaseWithBLOBs();
if (adminCaseDto.getCaseContentFile() != null) { String uuid = IdUtil.randomUUID();
String contentUrl = fileUtil.upload(adminCaseDto.getCaseContentFile()); adminCaseWithBLOB.setId(uuid);
adminCase.setContent(contentUrl); //传的文件就存地址 adminCaseWithBLOB.setSource(source);
} adminCaseWithBLOB.setCreateTime(new Date());
if (StringUtils.isNotBlank(adminCaseDto.getCaseContent())) { adminCaseWithBLOB.setStatus(0); //新增默认下架,发布后上架
adminCase.setContent(adminCaseDto.getCaseContent()); adminCaseWithBLOB.setName(name);
} //设置图片
if (pictureFile != null) {
//设置目录 String pictureUrl = fileUtil.upload(pictureFile);
if (adminCaseDto.getCaseCatalogFile() != null) { adminCaseWithBLOB.setPictureUrl(pictureUrl);
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()) { if (dataFile != null && !dataFile.isEmpty()) {
List<MultipartFile> dataFileList = adminCaseDto.getDataFile();
List<AdminFile> list = new ArrayList<>(); List<AdminFile> list = new ArrayList<>();
for (MultipartFile file : dataFileList) { for (MultipartFile file : dataFile) {
AdminFile adminFile = new AdminFile(); AdminFile adminFile = new AdminFile();
adminFile.setFileId(IdUtil.randomUUID()); adminFile.setFileId(IdUtil.randomUUID());
String pictureUrl = fileUtil.upload(file); String dataUrl = fileUtil.upload(file);
String name = file.getName(); String fullFileName = file.getOriginalFilename();
adminFile.setFileUrl(pictureUrl); adminFile.setFileUrl(dataUrl);
adminFile.setName(name); adminFile.setName(fullFileName);
adminFile.setSource("案例表"); adminFile.setSource("数据表");
adminFile.setDataCaseId(caseId); adminFile.setDataCaseId(uuid);
list.add(adminFile); list.add(adminFile);
} }
//批量新增数据文件 //批量新增数据文件
adminFileMapper.insertBatch(list); adminFileMapper.insertBatch(list);
} }
//批量新增标签
List<AdminDataLabel> list = new ArrayList<>(); List<AdminDataLabel> list = new ArrayList<>();
for (AdminLabel adminLabel : adminLabelList) { for (AdminLabel adminLabel : adminLabelList) {
AdminDataLabel label = new AdminDataLabel(); AdminDataLabel label = new AdminDataLabel();
label.setId(IdUtil.randomUUID()); label.setId(IdUtil.randomUUID());
label.setLabelId(adminLabel.getLabelId()); label.setLabelId(adminLabel.getLabelId());
label.setName(adminLabel.getName()); label.setName(adminLabel.getName());
label.setDataCaseId(adminCaseDto.getCaseId()); label.setDataCaseId(uuid);
label.setType(adminLabel.getType());
list.add(label); list.add(label);
} }
//批量新增标签 try {
adminDataLabelMapper.insertBatch(list); adminDataLabelMapper.insertBatch(list);
//新增案例 adminCaseMapper.insert(adminCaseWithBLOB);
adminCaseMapper.insert(adminCase); } catch (Exception e) {
e.printStackTrace();
return new ResultEntity<>(HttpStatus.INTERNAL_SERVER_ERROR, "新增失败!请联系管理员");
}
return new ResultEntity<>(HttpStatus.OK, "新增成功!"); return new ResultEntity<>(HttpStatus.OK, "新增成功!");
} }
@ -152,24 +238,63 @@ public class AdminCaseController {
} }
/* @PostMapping("updateAdminCase") @PostMapping("updateAdminCase")
@ApiOperation("案例编辑")*/ @ApiOperation("案例编辑/没改的参数别传")
private ResultEntity<String> updateAdminCase(@ModelAttribute AdminCaseDto adminCaseDto) { @Transactional
List<AdminLabel> adminLabelList = adminCaseDto.getAdminLabelList(); ResultEntity<String> updateAdminCase(@RequestParam String caseId,
List<MultipartFile> dataFile = adminCaseDto.getDataFile(); @RequestParam(required = false) String name,
AdminCaseWithBLOBs adminCaseWithBLOBs = adminCaseMapper.selectByPrimaryKey(adminCaseDto.getCaseId()); @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) { Gson gson = new Gson();
MultipartFile pictureFile = adminCaseDto.getPictureFile(); List<AdminLabel> adminLabelList = null;
String pictureUrl = fileUtil.upload(pictureFile); try {
adminCaseWithBLOBs.setPictureUrl(pictureUrl); if (StringUtils.isNotBlank(adminLabelJson)) {
adminLabelList = gson.fromJson(adminLabelJson, new TypeToken<List<AdminLabel>>() {
}.getType());
}
} catch (JsonSyntaxException e) {
e.printStackTrace();
return new ResultEntity<>(HttpStatus.INTERNAL_SERVER_ERROR, "服务器错误,请联系管理员");
} }
if (adminCaseDto.getCaseCatalogFile() != null) {
MultipartFile pictureFile = adminCaseDto.getPictureFile(); AdminCaseWithBLOBs adminCaseWithBLOBs = adminCaseMapper.selectByPrimaryKey(caseId);
String pictureUrl = fileUtil.upload(pictureFile); if (pictureFile != null) {
adminCaseWithBLOBs.setPictureUrl(pictureUrl); 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<AdminDataLabel> 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, "编辑成功!");
} }

Loading…
Cancel
Save