FileInnerServiceSMOImpl.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. private static final String ROOT_PATH = "hc/";
  23. @Autowired
  24. private IFileServiceDao fileServiceDaoImpl;
  25. @Autowired
  26. private Java110Properties java110Properties;
  27. @Autowired
  28. private FtpUploadTemplate ftpUploadTemplate;
  29. @Autowired
  30. private JSchFtpUploadTemplate jSchFtpUploadTemplate;
  31. @Autowired
  32. private OssUploadTemplate ossUploadTemplate;
  33. @Autowired
  34. private CosUploadTemplate cosUploadTemplate;
  35. @Override
  36. public String saveFile(@RequestBody FileDto fileDto) {
  37. //int saveFileFlag = fileServiceDaoImpl.saveFile(BeanConvertUtil.beanCovertMap(fileDto));
  38. String fileName = "";
  39. String ossSwitch = MappingCache.getValue(OSSUtil.DOMAIN, OSSUtil.OSS_SWITCH);
  40. if (OSSUtil.OSS_SWITCH_OSS.equals(ossSwitch)) {
  41. fileName = ossUploadTemplate.upload(fileDto.getContext(), java110Properties.getFtpServer(),
  42. java110Properties.getFtpPort(), java110Properties.getFtpUserName(),
  43. java110Properties.getFtpUserPassword(), ROOT_PATH);
  44. } else if (COSUtil.COS_SWITCH_COS.equals(ossSwitch)) {
  45. fileName = cosUploadTemplate.upload(fileDto.getContext(), java110Properties.getFtpServer(),
  46. java110Properties.getFtpPort(), java110Properties.getFtpUserName(),
  47. java110Properties.getFtpUserPassword(), ROOT_PATH);
  48. } else {
  49. String ftpServer = MappingCache.getValue(FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_SERVER);
  50. int ftpPort = Integer.parseInt(MappingCache.getValue(FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_PORT));
  51. String ftpUserName = MappingCache.getValue(FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_USERNAME);
  52. String ftpUserPassword = MappingCache.getValue(FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_USERPASSWORD);
  53. //String ftpPath = "hc/";
  54. fileName = ftpUploadTemplate.upload(fileDto.getContext(), ftpServer,
  55. ftpPort, ftpUserName,
  56. ftpUserPassword, ROOT_PATH);
  57. }
  58. return fileName;
  59. }
  60. @Override
  61. public List<FileDto> queryFiles(@RequestBody FileDto fileDto) {
  62. //return BeanConvertUtil.covertBeanList(fileServiceDaoImpl.getFiles(BeanConvertUtil.beanCovertMap(fileDto)), FileDto.class);
  63. List<FileDto> fileDtos = new ArrayList<>();
  64. String fileName = fileDto.getFileSaveName();
  65. String ftpPath = "hc/";
  66. String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
  67. if (fileName.contains("/")) {
  68. ftpPath += fileName.substring(0, fileName.lastIndexOf("/") + 1);
  69. fileName = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length());
  70. }
  71. String context = "";
  72. String ossSwitch = MappingCache.getValue(OSSUtil.DOMAIN, OSSUtil.OSS_SWITCH);
  73. if (OSSUtil.OSS_SWITCH_OSS.equals(ossSwitch)) {
  74. context = ossUploadTemplate.download(ftpPath, fileName, java110Properties.getFtpServer(),
  75. java110Properties.getFtpPort(), java110Properties.getFtpUserName(),
  76. java110Properties.getFtpUserPassword());
  77. } else if (COSUtil.COS_SWITCH_COS.equals(ossSwitch)) {
  78. context = cosUploadTemplate.download(ftpPath, fileName, java110Properties.getFtpServer(),
  79. java110Properties.getFtpPort(), java110Properties.getFtpUserName(),
  80. java110Properties.getFtpUserPassword());
  81. } else {
  82. String ftpServer = MappingCache.getValue(FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_SERVER);
  83. int ftpPort = Integer.parseInt(MappingCache.getValue(FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_PORT));
  84. String ftpUserName = MappingCache.getValue(FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_USERNAME);
  85. String ftpUserPassword = MappingCache.getValue(FtpUploadTemplate.FTP_DOMAIN, FtpUploadTemplate.FTP_USERPASSWORD);
  86. context = ftpUploadTemplate.download(ftpPath, fileName, ftpServer,
  87. ftpPort, ftpUserName,
  88. ftpUserPassword);
  89. }
  90. fileDto.setContext(context);
  91. fileDto.setSuffix(suffix);
  92. fileDtos.add(fileDto);
  93. return fileDtos;
  94. }
  95. public IFileServiceDao getFileServiceDaoImpl() {
  96. return fileServiceDaoImpl;
  97. }
  98. public void setFileServiceDaoImpl(IFileServiceDao fileServiceDaoImpl) {
  99. this.fileServiceDaoImpl = fileServiceDaoImpl;
  100. }
  101. }