|
|
|
@ -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<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
|
|
|
|
|
@Transactional*/
|
|
|
|
|
ResultEntity<String> add(@ModelAttribute AdminCaseDto adminCaseDto,
|
|
|
|
|
@RequestParam String adminCaseDtoJson,
|
|
|
|
|
@Transactional
|
|
|
|
|
ResultEntity<String> add(@RequestParam String name,
|
|
|
|
|
@RequestParam String source,
|
|
|
|
|
@RequestParam MultipartFile pictureFile,
|
|
|
|
|
@RequestParam List<MultipartFile> dataFile) {
|
|
|
|
|
if (StringUtils.isBlank(adminCaseDto.getName())) {
|
|
|
|
|
@RequestParam String adminLabelJson,
|
|
|
|
|
@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, "请输入名称!");
|
|
|
|
|
}
|
|
|
|
|
if (adminCaseDto.getAdminLabelList() == null || adminCaseDto.getAdminLabelList().isEmpty()) {
|
|
|
|
|
if (adminLabelList == null || adminLabelList.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());
|
|
|
|
|
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<MultipartFile> dataFileList = adminCaseDto.getDataFile();
|
|
|
|
|
if (dataFile != null && !dataFile.isEmpty()) {
|
|
|
|
|
List<AdminFile> 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<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());
|
|
|
|
|
label.setDataCaseId(uuid);
|
|
|
|
|
label.setType(adminLabel.getType());
|
|
|
|
|
list.add(label);
|
|
|
|
|
}
|
|
|
|
|
//批量新增标签
|
|
|
|
|
try {
|
|
|
|
|
adminDataLabelMapper.insertBatch(list);
|
|
|
|
|
//新增案例
|
|
|
|
|
adminCaseMapper.insert(adminCase);
|
|
|
|
|
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<String> updateAdminCase(@ModelAttribute AdminCaseDto adminCaseDto) {
|
|
|
|
|
List<AdminLabel> adminLabelList = adminCaseDto.getAdminLabelList();
|
|
|
|
|
List<MultipartFile> dataFile = adminCaseDto.getDataFile();
|
|
|
|
|
AdminCaseWithBLOBs adminCaseWithBLOBs = adminCaseMapper.selectByPrimaryKey(adminCaseDto.getCaseId());
|
|
|
|
|
@PostMapping("updateAdminCase")
|
|
|
|
|
@ApiOperation("案例编辑/没改的参数别传")
|
|
|
|
|
@Transactional
|
|
|
|
|
ResultEntity<String> 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<AdminLabel> adminLabelList = null;
|
|
|
|
|
try {
|
|
|
|
|
if (StringUtils.isNotBlank(adminLabelJson)) {
|
|
|
|
|
adminLabelList = gson.fromJson(adminLabelJson, new TypeToken<List<AdminLabel>>() {
|
|
|
|
|
}.getType());
|
|
|
|
|
}
|
|
|
|
|
if (adminCaseDto.getCaseCatalogFile() != null) {
|
|
|
|
|
MultipartFile pictureFile = adminCaseDto.getPictureFile();
|
|
|
|
|
String pictureUrl = fileUtil.upload(pictureFile);
|
|
|
|
|
adminCaseWithBLOBs.setPictureUrl(pictureUrl);
|
|
|
|
|
} catch (JsonSyntaxException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return new ResultEntity<>(HttpStatus.INTERNAL_SERVER_ERROR, "服务器错误,请联系管理员");
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
AdminCaseWithBLOBs adminCaseWithBLOBs = adminCaseMapper.selectByPrimaryKey(caseId);
|
|
|
|
|
if (pictureFile != null) {
|
|
|
|
|
String fileUrl = fileUtil.upload(pictureFile);
|
|
|
|
|
adminCaseWithBLOBs.setPictureUrl(fileUrl);
|
|
|
|
|
}
|
|
|
|
|
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, "编辑成功!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|