添加敏感词下载模板
This commit is contained in:
@@ -3,6 +3,7 @@ package com.ruoyi.cms.controller.cms;
|
|||||||
import com.ruoyi.cms.domain.SensitiveWordData;
|
import com.ruoyi.cms.domain.SensitiveWordData;
|
||||||
import com.ruoyi.cms.service.SensitiveWordDataService;
|
import com.ruoyi.cms.service.SensitiveWordDataService;
|
||||||
import com.ruoyi.cms.util.EasyExcelUtils;
|
import com.ruoyi.cms.util.EasyExcelUtils;
|
||||||
|
import com.ruoyi.common.annotation.Anonymous;
|
||||||
import com.ruoyi.common.annotation.Log;
|
import com.ruoyi.common.annotation.Log;
|
||||||
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
@@ -11,11 +12,12 @@ import com.ruoyi.common.enums.BusinessType;
|
|||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@@ -29,6 +31,7 @@ import java.util.List;
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/cms/sensitiveworddata")
|
@RequestMapping("/cms/sensitiveworddata")
|
||||||
@Api(tags = "后台:敏感词库")
|
@Api(tags = "后台:敏感词库")
|
||||||
|
@Anonymous
|
||||||
public class SensitiveWordDataController extends BaseController {
|
public class SensitiveWordDataController extends BaseController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private SensitiveWordDataService sensitiveWordDataService;
|
private SensitiveWordDataService sensitiveWordDataService;
|
||||||
@@ -95,6 +98,20 @@ public class SensitiveWordDataController extends BaseController {
|
|||||||
@PostMapping("/exoprt")
|
@PostMapping("/exoprt")
|
||||||
public AjaxResult uploadFile(@RequestParam("file") MultipartFile file) throws Exception
|
public AjaxResult uploadFile(@RequestParam("file") MultipartFile file) throws Exception
|
||||||
{
|
{
|
||||||
|
// 参数校验
|
||||||
|
if (file.isEmpty()) {
|
||||||
|
return AjaxResult.error("上传文件不能为空");
|
||||||
|
}
|
||||||
|
String fileName = file.getOriginalFilename();
|
||||||
|
//类型验证
|
||||||
|
if (fileName == null || !fileName.endsWith(".xlsx") && !fileName.endsWith(".xls")) {
|
||||||
|
return AjaxResult.error("请上传Excel格式的文件");
|
||||||
|
}
|
||||||
|
//名称验证
|
||||||
|
if (fileName == null || !"mgc.xlsx".equals(fileName)) {
|
||||||
|
return AjaxResult.error("请上传正确的模板文件:mgc.xlsx");
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
InputStream inputStream = file.getInputStream();
|
InputStream inputStream = file.getInputStream();
|
||||||
@@ -109,4 +126,46 @@ public class SensitiveWordDataController extends BaseController {
|
|||||||
}
|
}
|
||||||
return AjaxResult.success();
|
return AjaxResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/downloadModel")
|
||||||
|
public void downloadModel(HttpServletRequest request, HttpServletResponse response)throws Exception{
|
||||||
|
String name = "mgc.xlsx";
|
||||||
|
String pathFile="/data/downloadmodel/"+name;
|
||||||
|
File url = new File(pathFile);
|
||||||
|
|
||||||
|
String resMsg = "";
|
||||||
|
try {
|
||||||
|
request.setCharacterEncoding("utf-8");
|
||||||
|
} catch (UnsupportedEncodingException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
name = new String(name.getBytes("gb2312"), "ISO8859-1");
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
response.reset();
|
||||||
|
|
||||||
|
response.setContentType("application/octet-stream");
|
||||||
|
response.setHeader("Content-Disposition", "attachment; filename="+ name);
|
||||||
|
response.setHeader("Pragma", "public");
|
||||||
|
response.setHeader("Cache-Control", "max-age=0");
|
||||||
|
InputStream in = null;
|
||||||
|
try {
|
||||||
|
in = new FileInputStream(url);
|
||||||
|
} catch (FileNotFoundException e1) {
|
||||||
|
resMsg = "文件未找到";
|
||||||
|
e1.printStackTrace();
|
||||||
|
response.getWriter().write(resMsg + ":" + name);
|
||||||
|
}
|
||||||
|
OutputStream ou = response.getOutputStream();
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int i = -1;
|
||||||
|
while ((i = in.read(buffer)) != -1) {
|
||||||
|
ou.write(buffer, 0, i);
|
||||||
|
}
|
||||||
|
ou.flush();
|
||||||
|
ou.close();
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user