FileInnerServiceSMOImpl.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package com.java110.common.smo.impl;
  2. import com.java110.common.dao.IFileServiceDao;
  3. import com.java110.config.properties.code.Java110Properties;
  4. import com.java110.core.base.smo.BaseServiceSMO;
  5. import com.java110.core.client.FtpUploadTemplate;
  6. import com.java110.core.client.JSchFtpUploadTemplate;
  7. import com.java110.core.client.OssUploadTemplate;
  8. import com.java110.dto.file.FileDto;
  9. import com.java110.intf.common.IFileInnerServiceSMO;
  10. import com.java110.utils.cache.MappingCache;
  11. import com.java110.utils.util.OSSUtil;
  12. import com.java110.utils.util.StringUtil;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.web.bind.annotation.RequestBody;
  15. import org.springframework.web.bind.annotation.RestController;
  16. import java.util.ArrayList;
  17. import java.util.List;
  18. @RestController
  19. public class FileInnerServiceSMOImpl extends BaseServiceSMO implements IFileInnerServiceSMO {
  20. @Autowired
  21. private IFileServiceDao fileServiceDaoImpl;
  22. @Autowired
  23. private Java110Properties java110Properties;
  24. @Autowired
  25. private FtpUploadTemplate ftpUploadTemplate;
  26. @Autowired
  27. private JSchFtpUploadTemplate jSchFtpUploadTemplate;
  28. @Autowired
  29. private OssUploadTemplate ossUploadTemplate;
  30. @Override
  31. public String saveFile(@RequestBody FileDto fileDto) {
  32. //int saveFileFlag = fileServiceDaoImpl.saveFile(BeanConvertUtil.beanCovertMap(fileDto));
  33. String fileName = "";
  34. String ossSwitch = MappingCache.getValue(OSSUtil.DOMAIN, OSSUtil.OSS_SWITCH);
  35. if (StringUtil.isEmpty(ossSwitch) || !OSSUtil.OSS_SWITCH_OSS.equals(ossSwitch)) {
  36. String ftpServer = MappingCache.getValue( FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_SERVER);
  37. int ftpPort = Integer.parseInt(MappingCache.getValue( FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_PORT));
  38. String ftpUserName = MappingCache.getValue( FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_USERNAME);
  39. String ftpUserPassword = MappingCache.getValue( FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_USERPASSWORD);
  40. String ftpPath = MappingCache.getValue( FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_PATH);
  41. fileName = ftpUploadTemplate.upload(fileDto.getContext(), ftpServer,
  42. ftpPort, ftpUserName,
  43. ftpUserPassword, ftpPath);
  44. } else {
  45. fileName = ossUploadTemplate.upload(fileDto.getContext(), java110Properties.getFtpServer(),
  46. java110Properties.getFtpPort(), java110Properties.getFtpUserName(),
  47. java110Properties.getFtpUserPassword(), java110Properties.getFtpPath());
  48. }
  49. return fileName;
  50. }
  51. @Override
  52. public List<FileDto> queryFiles(@RequestBody FileDto fileDto) {
  53. //return BeanConvertUtil.covertBeanList(fileServiceDaoImpl.getFiles(BeanConvertUtil.beanCovertMap(fileDto)), FileDto.class);
  54. List<FileDto> fileDtos = new ArrayList<>();
  55. String fileName = fileDto.getFileSaveName();
  56. String ftpPath = java110Properties.getFtpPath();
  57. String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
  58. if (fileName.contains("/")) {
  59. ftpPath += fileName.substring(0, fileName.lastIndexOf("/") + 1);
  60. fileName = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length());
  61. }
  62. String context = "";
  63. String ossSwitch = MappingCache.getValue(OSSUtil.DOMAIN, OSSUtil.OSS_SWITCH);
  64. if (StringUtil.isEmpty(ossSwitch) || !OSSUtil.OSS_SWITCH_OSS.equals(ossSwitch)) {
  65. context = ftpUploadTemplate.download(ftpPath, fileName, java110Properties.getFtpServer(),
  66. java110Properties.getFtpPort(), java110Properties.getFtpUserName(),
  67. java110Properties.getFtpUserPassword());
  68. }else{
  69. context = ossUploadTemplate.download(ftpPath, fileName, java110Properties.getFtpServer(),
  70. java110Properties.getFtpPort(), java110Properties.getFtpUserName(),
  71. java110Properties.getFtpUserPassword());
  72. }
  73. fileDto.setContext(context);
  74. fileDto.setSuffix(suffix);
  75. fileDtos.add(fileDto);
  76. return fileDtos;
  77. }
  78. public IFileServiceDao getFileServiceDaoImpl() {
  79. return fileServiceDaoImpl;
  80. }
  81. public void setFileServiceDaoImpl(IFileServiceDao fileServiceDaoImpl) {
  82. this.fileServiceDaoImpl = fileServiceDaoImpl;
  83. }
  84. }