diff --git a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/zyInfoStudent/controller/ZyInfoStudentController.java b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/zyInfoStudent/controller/ZyInfoStudentController.java index e7ad55f8..5834c8ef 100644 --- a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/zyInfoStudent/controller/ZyInfoStudentController.java +++ b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/zyInfoStudent/controller/ZyInfoStudentController.java @@ -484,31 +484,44 @@ public class ZyInfoStudentController extends JeecgController map = zykService.saveToZykJxdg(zykInfo); - String fileName = map.get("data"); - String pdfName = map.get("pdfData"); - zyInfoStudent.setFilePath(fileName); - zyInfoStudent.setPdfPath(pdfName); - } + //目前作业都需要上传到文件服务器 + ZykInfo zykInfo = new ZykInfo(); + zykInfo.setBizId(zyInfoStudent.getId()); + zykInfo.setBizTable("zy_jxdg"); + zykInfo.setWjlx(WjlxEnum.JXDG.getType()); + zykInfo.setRwbh(zyInfo.getRwbh()); + zykInfo.setFileName(zyInfoStudent.getFilePath()); + Map map = zykService.saveToStufile(zykInfo); + String fileName = map.get("data"); + String pdfName = map.get("pdfData"); + zyInfoStudent.setFilePath(fileName); + zyInfoStudent.setPdfPath(pdfName); + +// if(StringUtils.equals("local",uploadType)){ +// Global global = SpringContextHolder.getBean(Global.class); +// FileUtil.mkdir(global.getContractDickPath()); +// String dd = DateUtils.formatDate(new Date(),"yyyyMMddHHmmss"); +// String docPath = upLoadPath+ File.separator+ zyInfoStudent.getFilePath(); +// String namePath = dd + ".pdf"; +// String pdfPath = global.getContractDickPath() + namePath; +// System.out.println("filPath:"+zyInfoStudent.getFilePath()); +// System.out.println("docPath:"+docPath); +// System.out.println("pdfPath:"+pdfPath); +// PDFUtil.office2PDF(docPath,pdfPath); +// zyInfoStudent.setPdfPath("contract/"+namePath); +// }else{ +// ZykInfo zykInfo = new ZykInfo(); +// zykInfo.setBizId(zyInfoStudent.getId()); +// zykInfo.setBizTable("zy_jxdg"); +// zykInfo.setWjlx(WjlxEnum.JXDG.getType()); +// zykInfo.setRwbh(zyInfo.getRwbh()); +// zykInfo.setFileName(zyInfoStudent.getFilePath()); +// Map map = zykService.saveToZykJxdg(zykInfo); +// String fileName = map.get("data"); +// String pdfName = map.get("pdfData"); +// zyInfoStudent.setFilePath(fileName); +// zyInfoStudent.setPdfPath(pdfName); +// } } zyInfoStudent.setPublishTime(new Date()); boolean bol = zyInfoStudentService.updateById(zyInfoStudent, response); diff --git a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/zyInfoStudent/service/impl/ZyInfoStudentServiceImpl.java b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/zyInfoStudent/service/impl/ZyInfoStudentServiceImpl.java index 26a30f30..6f66f661 100644 --- a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/zyInfoStudent/service/impl/ZyInfoStudentServiceImpl.java +++ b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/zyInfoStudent/service/impl/ZyInfoStudentServiceImpl.java @@ -230,13 +230,11 @@ public class ZyInfoStudentServiceImpl extends ServiceImpl"); - } +// String fileName = downloadpath+"/"+ zyInfoStudent.getFilePath(); +// if(CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)) { +// fileName = uploadpath+"/"+ zyInfoStudent.getFilePath(); +// } + String fileName = uploadpath+"/"+ zyInfoStudent.getFilePath(); Map textMap = new HashMap(); //可以设置多个input的name,value String sign = getSign(); @@ -312,13 +310,11 @@ public class ZyInfoStudentServiceImpl extends ServiceImpl"); - } +// String fileName = downloadpath+"/"+ zyInfoStudent.getFilePath(); +// if(CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)) { +// fileName = uploadpath+"/"+ zyInfoStudent.getFilePath(); +// } + String fileName = uploadpath+"/"+ zyInfoStudent.getFilePath(); Map textMap = new HashMap(); String titlePar =fileName.substring(fileName.lastIndexOf("/")+1,fileName.length()); String title = titlePar.split("_")[0]; @@ -370,13 +366,11 @@ public class ZyInfoStudentServiceImpl extends ServiceImpl textMap = new HashMap(); String titlePar =fileName.substring(fileName.lastIndexOf("/")+1,fileName.length()); String title = titlePar.split("_")[0]; @@ -456,11 +450,11 @@ public class ZyInfoStudentServiceImpl extends ServiceImpl textMap = new HashMap(); //可以设置多个input的name,value String sign = getSign(); diff --git a/jeecg-module-main/src/main/java/org/jeecg/modules/zyk/service/IZykService.java b/jeecg-module-main/src/main/java/org/jeecg/modules/zyk/service/IZykService.java index b1a10db2..85b6a6d0 100644 --- a/jeecg-module-main/src/main/java/org/jeecg/modules/zyk/service/IZykService.java +++ b/jeecg-module-main/src/main/java/org/jeecg/modules/zyk/service/IZykService.java @@ -59,4 +59,6 @@ public interface IZykService extends IService { void disConnect(); void saveLocal(ZykInfo zykInfo); + + Map saveToStufile(ZykInfo zykInfo); } diff --git a/jeecg-module-main/src/main/java/org/jeecg/modules/zyk/service/impl/ZykServiceImpl.java b/jeecg-module-main/src/main/java/org/jeecg/modules/zyk/service/impl/ZykServiceImpl.java index f24ccd4d..9ef25a4d 100644 --- a/jeecg-module-main/src/main/java/org/jeecg/modules/zyk/service/impl/ZykServiceImpl.java +++ b/jeecg-module-main/src/main/java/org/jeecg/modules/zyk/service/impl/ZykServiceImpl.java @@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.shiro.SecurityUtils; import org.jeecg.common.system.vo.LoginUser; import org.jeecg.common.util.DateUtils; +import org.jeecg.common.util.SFTPUtil; +import org.jeecg.common.util.SftpConfig; import org.jeecg.common.util.SpringContextHolder; import org.jeecg.common.util.text.StringUtils; import org.jeecg.modules.kc.ktgl.entity.KcKechengbiao; @@ -18,14 +20,16 @@ import org.jeecg.modules.zyk.service.IZykService; import org.jeecg.modules.zyk.utils.FileHandleUtil; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.mock.web.MockMultipartFile; import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.io.File; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.*; /** * @Description: 资源库信息 @@ -45,6 +49,15 @@ public class ZykServiceImpl extends ServiceImpl implements I @Autowired private ZykMapper zykMapper; + @Autowired + SftpConfig sftpConfig; + + private static String uploadpath; + + @Value("${jeecg.path.upload}") + public void setUploadPath(String uploadPath) { + this.uploadpath = uploadPath; + } @Override @@ -355,4 +368,71 @@ public class ZykServiceImpl extends ServiceImpl implements I zykInfo.setId(id.toString()); zykMapper.addInfo(zykInfo); } + + @Override + public Map saveToStufile(ZykInfo zykInfo) { + + String bizPath = ""; + MultipartFile file = null; + try { + file = this.convert(uploadpath+"/"+zykInfo.getFileName()); + } catch (IOException e) { + throw new RuntimeException(e); + } + this.uploadSftp(file,bizPath); +// Map downloadMap = downloadRemoteFile(zykInfo.getFileName()); +// if(!downloadMap.get("code").equals("0")){ +// return downloadMap; +// } + + + Map map = new HashMap<>(); + String fileType = zykInfo.getFileName().substring(zykInfo.getFileName().lastIndexOf(".") + 1); + if(StringUtils.equals(fileType,"doc")||StringUtils.equals(fileType,"docx")){ + Global global = SpringContextHolder.getBean(Global.class); + String dd = DateUtils.formatDate(new Date(),"yyyyMMddHHmmss"); + String namePath = dd + ".pdf"; + String pdfPath = global.getContractDickPath() + namePath; + + PDFUtil.office2PDF(zykInfo.getFileName(),pdfPath); + Map uploadMap = uploadFileToSftp("contract/"+namePath); + if(!uploadMap.get("code").equals("0")){ + return uploadMap; + } + zykInfo.setPdfName(uploadMap.get("data")); + if(StringUtils.isNotNull(uploadMap.get("data"))){ + String pdfName = uploadMap.get("data"); + zykInfo.setPdfName(pdfName); + map.put("pdfData",uploadMap.get("data")); + }else{ + map.put("pdfData",""); + } + } + return map; + } + + public static MultipartFile convert(String path) throws IOException { + File file = new File(path); + FileInputStream input = new FileInputStream(file); + MultipartFile multipartFile = new MockMultipartFile("file",file.getName(), "text/plain", input); + + return multipartFile; + } + + private String uploadSftp(MultipartFile mf, String bizPath){ + try { + Map uploadMap = SFTPUtil.upload(sftpConfig,mf,bizPath); + SFTPUtil.disChannel(); + SFTPUtil.disSession(); + if(uploadMap.get("code").equals("0")){ + return uploadMap.get("data"); + } + } catch (Exception e) { + log.error(e.getMessage(), e); + }finally { + SFTPUtil.disChannel(); + SFTPUtil.disSession(); + } + return ""; + } } diff --git a/jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml b/jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml index 8d42cf21..18f64364 100644 --- a/jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml +++ b/jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml @@ -348,4 +348,4 @@ sftp: password: sftp timeout: 1000 uploadpath: kczx - fullpath: /home/sftp \ No newline at end of file + fullpath: /data \ No newline at end of file diff --git a/jeecg-module-system/jeecg-system-start/src/main/resources/application-prod.yml b/jeecg-module-system/jeecg-system-start/src/main/resources/application-prod.yml index b2810a47..0cc67926 100644 --- a/jeecg-module-system/jeecg-system-start/src/main/resources/application-prod.yml +++ b/jeecg-module-system/jeecg-system-start/src/main/resources/application-prod.yml @@ -354,4 +354,4 @@ sftp: password: Nenujwc@99 timeout: 1000 uploadpath: kczx - fullpath: /home/sftp \ No newline at end of file + fullpath: /data \ No newline at end of file