FileInnerServiceSMOImpl.java 5.5 KB

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