学生作业上传增加SFTP上传下载

This commit is contained in:
曹磊 2024-05-29 16:18:26 +08:00
parent fcc7a963c8
commit 5702d3f521
3 changed files with 112 additions and 21 deletions

View File

@ -275,7 +275,7 @@ public class ZyInfoStudentController extends JeecgController<ZyInfoStudent, IZyI
@AutoLog(value = "学生作业上传") @AutoLog(value = "学生作业上传")
@ApiOperation(value="学生作业上传", notes="学生作业上传") @ApiOperation(value="学生作业上传", notes="学生作业上传")
@RequestMapping(value = "/zyscStu", method = {RequestMethod.PUT,RequestMethod.POST}) @RequestMapping(value = "/zyscStu", method = {RequestMethod.PUT,RequestMethod.POST})
public Result<String> zyscStu(@RequestBody ZyInfoStudent zyInfoStudent) { public Result<String> zyscStu(@RequestBody ZyInfoStudent zyInfoStudent, HttpServletResponse response) {
ZyInfoStudent stuPar = zyInfoStudentService.getById(zyInfoStudent.getId()); ZyInfoStudent stuPar = zyInfoStudentService.getById(zyInfoStudent.getId());
ZyInfo zyInfo = zyInfoService.getById(stuPar.getMainId()); ZyInfo zyInfo = zyInfoService.getById(stuPar.getMainId());
@ -310,7 +310,7 @@ public class ZyInfoStudentController extends JeecgController<ZyInfoStudent, IZyI
zyInfoStudent.setPdfPath(pdfName); zyInfoStudent.setPdfPath(pdfName);
} }
} }
zyInfoStudentService.updateById(zyInfoStudent); zyInfoStudentService.updateById(zyInfoStudent, response);
//作业代办提醒 //作业代办提醒
ZyDbtx zyDbtx = new ZyDbtx(); ZyDbtx zyDbtx = new ZyDbtx();

View File

@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.kc.zyInfoStudent.entity.ZyInfoStudent; import org.jeecg.modules.kc.zyInfoStudent.entity.ZyInfoStudent;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List; import java.util.List;
/** /**
@ -20,7 +22,7 @@ public interface IZyInfoStudentService extends IService<ZyInfoStudent> {
void deleteMainId(String id); void deleteMainId(String id);
public boolean updateById(ZyInfoStudent zyInfoStudent); public boolean updateById(ZyInfoStudent zyInfoStudent, HttpServletResponse response);
void editFabu(ZyInfoStudent zyInfoStudent); void editFabu(ZyInfoStudent zyInfoStudent);

View File

@ -8,10 +8,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.vo.LoginUser; import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.kc.blZycc.entity.BlZycc; import org.jeecg.common.util.SFTPUtil;
import org.jeecg.modules.kc.kcSysConfig.entity.KcSysConfig; import org.jeecg.common.util.SftpConfig;
import org.jeecg.modules.kc.kcSysConfig.service.IKcSysConfigService;
import org.jeecg.modules.kc.ktgl.entity.KcKechengbiao; import org.jeecg.modules.kc.ktgl.entity.KcKechengbiao;
import org.jeecg.modules.kc.ktgl.service.IKcKechengbiaoService; import org.jeecg.modules.kc.ktgl.service.IKcKechengbiaoService;
import org.jeecg.modules.kc.zyCcjg.entity.ZyCcjg; import org.jeecg.modules.kc.zyCcjg.entity.ZyCcjg;
@ -28,6 +28,8 @@ import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import javax.activation.MimetypesFileTypeMap; import javax.activation.MimetypesFileTypeMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*; import java.io.*;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
@ -53,6 +55,9 @@ public class ZyInfoStudentServiceImpl extends ServiceImpl<ZyInfoStudentMapper, Z
@Autowired @Autowired
private IKcKechengbiaoService kcKechengbiaoService; private IKcKechengbiaoService kcKechengbiaoService;
@Autowired
SftpConfig sftpConfig;
private static String uploadpath; private static String uploadpath;
@Value("${jeecg.path.upload}") @Value("${jeecg.path.upload}")
@ -60,6 +65,9 @@ public class ZyInfoStudentServiceImpl extends ServiceImpl<ZyInfoStudentMapper, Z
this.uploadpath = uploadPath; this.uploadpath = uploadPath;
} }
@Value(value="${jeecg.uploadType}")
private String uploadType;
private static String weipuId; private static String weipuId;
@Value("${weipu.userId}") @Value("${weipu.userId}")
@ -74,6 +82,8 @@ public class ZyInfoStudentServiceImpl extends ServiceImpl<ZyInfoStudentMapper, Z
this.weipuKey = weipuKey; this.weipuKey = weipuKey;
} }
@Value(value = "${jeecg.path.webapp}")
private String downloadpath;
@Override @Override
public boolean save(ZyInfoStudent zyInfoStudent) { public boolean save(ZyInfoStudent zyInfoStudent) {
@ -88,7 +98,7 @@ public class ZyInfoStudentServiceImpl extends ServiceImpl<ZyInfoStudentMapper, Z
} }
@Override @Override
public boolean updateById(ZyInfoStudent zyInfoStudent) { public boolean updateById(ZyInfoStudent zyInfoStudent, HttpServletResponse response) {
baseMapper.updateById(zyInfoStudent); baseMapper.updateById(zyInfoStudent);
zyInfoStudent = baseMapper.selectById(zyInfoStudent.getId()); zyInfoStudent = baseMapper.selectById(zyInfoStudent.getId());
ZyInfo zyInfo = zyInfoService.getById(zyInfoStudent.getMainId()); ZyInfo zyInfo = zyInfoService.getById(zyInfoStudent.getMainId());
@ -105,21 +115,21 @@ public class ZyInfoStudentServiceImpl extends ServiceImpl<ZyInfoStudentMapper, Z
zyInfoStudent.setCatename(catename); zyInfoStudent.setCatename(catename);
//外网查重及提交检测 //外网查重及提交检测
if(StringUtils.equals(zyInfo.getWwcc(),"1")){ if(StringUtils.equals(zyInfo.getWwcc(),"1")){
wwccSave(zyInfoStudent); wwccSave(zyInfoStudent,response);
} }
//内网查重及提交检测 //内网查重及提交检测
if(StringUtils.equals(zyInfo.getNwcc(),"1")){ if(StringUtils.equals(zyInfo.getNwcc(),"1")){
nwccSave(zyInfoStudent); nwccSave(zyInfoStudent,response);
} }
//aigc查重及提交检测 //aigc查重及提交检测
if(StringUtils.equals(zyInfo.getAigccc(),"1")){ if(StringUtils.equals(zyInfo.getAigccc(),"1")){
aigcSave(zyInfoStudent); aigcSave(zyInfoStudent,response);
} }
//校内查重及提交检测 //校内查重及提交检测
if(StringUtils.equals(zyInfo.getXncc(),"1")){ if(StringUtils.equals(zyInfo.getXncc(),"1")){
zyInfoStudent.setCateid("DBSDQXZYBDK001"); zyInfoStudent.setCateid("DBSDQXZYBDK001");
zyInfoStudent.setCatename("东北师大全校作业比对库"); zyInfoStudent.setCatename("东北师大全校作业比对库");
xnccSave(zyInfoStudent,"0");//提交比对 xnccSave(zyInfoStudent,"0",response);//提交比对
}else{ }else{
// zyInfoStudent.setCateid("DBSDQXZYBDK001"); // zyInfoStudent.setCateid("DBSDQXZYBDK001");
// zyInfoStudent.setCatename("东北师大全校作业比对库"); // zyInfoStudent.setCatename("东北师大全校作业比对库");
@ -146,10 +156,11 @@ public class ZyInfoStudentServiceImpl extends ServiceImpl<ZyInfoStudentMapper, Z
} }
//aigc提交 //aigc提交
private void aigcSave(ZyInfoStudent zyInfoStudent) { private void aigcSave(ZyInfoStudent zyInfoStudent,HttpServletResponse response) {
String url = "https://vims.fanyu.com/tool/AIGCCheck/paperSubmit"; String url = "https://vims.fanyu.com/tool/AIGCCheck/paperSubmit";
//文件路径文件存在不存在的话需要先下载下来 //文件路径文件存在不存在的话需要先下载下来
String fileName = uploadpath+"/"+ zyInfoStudent.getFilePath(); // String fileName = uploadpath+"/"+ zyInfoStudent.getFilePath();
String fileName = getFileName(zyInfoStudent.getFilePath(),response);
Map<String, String> textMap = new HashMap<String, String>(); Map<String, String> textMap = new HashMap<String, String>();
//可以设置多个input的namevalue //可以设置多个input的namevalue
String sign = getSign(); String sign = getSign();
@ -214,10 +225,11 @@ public class ZyInfoStudentServiceImpl extends ServiceImpl<ZyInfoStudentMapper, Z
} }
//小范围提交校园内网提交 //小范围提交校园内网提交
private void nwccSave(ZyInfoStudent zyInfoStudent) { private void nwccSave(ZyInfoStudent zyInfoStudent,HttpServletResponse response) {
String url = "https://vims.fanyu.com/toole/smallcheck/submitData"; String url = "https://vims.fanyu.com/toole/smallcheck/submitData";
//文件路径文件存在不存在的话需要先下载下来 //文件路径文件存在不存在的话需要先下载下来
String fileName = uploadpath+"/"+ zyInfoStudent.getFilePath(); // String fileName = uploadpath+"/"+ zyInfoStudent.getFilePath();
String fileName = getFileName(zyInfoStudent.getFilePath(),response);
Map<String, String> textMap = new HashMap<String, String>(); Map<String, String> textMap = new HashMap<String, String>();
String titlePar =fileName.substring(fileName.lastIndexOf("/")+1,fileName.length()); String titlePar =fileName.substring(fileName.lastIndexOf("/")+1,fileName.length());
String title = titlePar.split("_")[0]; String title = titlePar.split("_")[0];
@ -259,10 +271,11 @@ public class ZyInfoStudentServiceImpl extends ServiceImpl<ZyInfoStudentMapper, Z
} }
//小范围提交校园内网提交 //小范围提交校园内网提交
private void xnccSave(ZyInfoStudent zyInfoStudent,String type) { private void xnccSave(ZyInfoStudent zyInfoStudent,String type,HttpServletResponse response) {
String url = "https://vims.fanyu.com/toole/smallcheck/submitData"; String url = "https://vims.fanyu.com/toole/smallcheck/submitData";
//文件路径文件存在不存在的话需要先下载下来 //文件路径文件存在不存在的话需要先下载下来
String fileName = uploadpath+"/"+ zyInfoStudent.getFilePath(); // String fileName = uploadpath+"/"+ zyInfoStudent.getFilePath();
String fileName = getFileName(zyInfoStudent.getFilePath(),response);
Map<String, String> textMap = new HashMap<String, String>(); Map<String, String> textMap = new HashMap<String, String>();
String titlePar =fileName.substring(fileName.lastIndexOf("/")+1,fileName.length()); String titlePar =fileName.substring(fileName.lastIndexOf("/")+1,fileName.length());
String title = titlePar.split("_")[0]; String title = titlePar.split("_")[0];
@ -327,11 +340,12 @@ public class ZyInfoStudentServiceImpl extends ServiceImpl<ZyInfoStudentMapper, Z
} }
//外网查重提交方法 //外网查重提交方法
private String wwccSave(ZyInfoStudent zyInfoStudent) { private String wwccSave(ZyInfoStudent zyInfoStudent,HttpServletResponse response) {
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
String url = "https://vims.fanyu.com/toole/jianceorgan/papersubmit.aspx"; String url = "https://vims.fanyu.com/toole/jianceorgan/papersubmit.aspx";
//文件路径文件存在不存在的话需要先下载下来 //文件路径文件存在不存在的话需要先下载下来
String fileName = uploadpath+"/"+ zyInfoStudent.getFilePath(); // String fileName = uploadpath+"/"+ zyInfoStudent.getFilePath();
String fileName = getFileName(zyInfoStudent.getFilePath(),response);
Map<String, String> textMap = new HashMap<String, String>(); Map<String, String> textMap = new HashMap<String, String>();
//可以设置多个input的namevalue //可以设置多个input的namevalue
String sign = getSign(); String sign = getSign();
@ -373,8 +387,6 @@ public class ZyInfoStudentServiceImpl extends ServiceImpl<ZyInfoStudentMapper, Z
} }
} }
//外网开始检测 //外网开始检测
public String wwKsjc(ZyCcjg zyCcjg) { public String wwKsjc(ZyCcjg zyCcjg) {
String url = "https://vims.fanyu.com/toole/jianceorgan/paperbegincheck.aspx"; String url = "https://vims.fanyu.com/toole/jianceorgan/paperbegincheck.aspx";
@ -394,8 +406,85 @@ public class ZyInfoStudentServiceImpl extends ServiceImpl<ZyInfoStudentMapper, Z
return message; return message;
} }
private String getFileName(String imgPath, HttpServletResponse response){
String fileName = "";
if(CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)) {
fileName = uploadpath+"/"+ imgPath;
}else if(CommonConstant.UPLOAD_TYPE_SFTP.equals(uploadType)){
InputStream inputStream = null;
OutputStream outputStream = null;
try{
int index = imgPath.lastIndexOf("/");
String path = "temp";
if(index != -1){
path = imgPath.substring(0,index);
}
Map<String,String> map = SFTPUtil.download(sftpConfig,imgPath,getDownloadPath(path));
if(!map.get("code").equals("0")){
response.setStatus(404);
throw new RuntimeException(map.get("msg"));
}
String localFilePath = map.get("fileName");
File file = new File(localFilePath);
if(!file.exists()){
response.setStatus(404);
throw new RuntimeException("文件["+imgPath+"]不存在..");
}
// 设置强制下载不打开
response.setContentType("application/force-download");
response.addHeader("Content-Disposition", "attachment;fileName=" + new String(file.getName().getBytes("UTF-8"),"iso-8859-1"));
inputStream = new BufferedInputStream(new FileInputStream(localFilePath));
outputStream = response.getOutputStream();
byte[] buf = new byte[1024];
int len;
while ((len = inputStream.read(buf)) > 0) {
outputStream.write(buf, 0, len);
}
response.flushBuffer();
fileName = localFilePath;
}catch (Exception e){
// e.printStackTrace();
}finally {
SFTPUtil.disChannel();
SFTPUtil.disSession();
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
}
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
// log.error(e.getMessage(), e);
}
}
}
}
return fileName;
}
/**
* 获取文件真实路径
* @param path
* @return
*/
private String getDownloadPath(String path){
String filePath = "";
if(org.jeecg.common.util.text.StringUtils.isEmpty(path)){
return "";
}
int idx = path.indexOf(downloadpath);
if(idx==-1){
filePath = downloadpath + File.separator + path;
}else{
filePath = path;
}
return filePath;
}
//生成sign //生成sign