| @@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature; | |||
| import com.fasterxml.jackson.databind.ObjectMapper; | |||
| import com.fasterxml.jackson.databind.module.SimpleModule; | |||
| import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; | |||
| import com.iformall.file.aliyun.AliyunOSS; | |||
| import com.iformall.interceptor.CurrentTenantInterceptor; | |||
| import com.iformall.interceptor.HttpServletRequestWrapperFilter; | |||
| import com.iformall.interceptor.RequestInterceptor; | |||
| @@ -52,10 +53,13 @@ public class WebConfig implements WebMvcConfigurer { | |||
| @Autowired | |||
| private MallResourceService mallResourceService; | |||
| @Autowired | |||
| private AliyunOSS aliyunOSS; | |||
| @Bean | |||
| @ConditionalOnMissingBean(ActionEnter.class) | |||
| public ActionEnter actionEnter() { | |||
| ActionEnter actionEnter = new ActionEnter(ConfigManager.getInstance(uEditorConfig, awsProperty, mallResourceService)); | |||
| ActionEnter actionEnter = new ActionEnter(ConfigManager.getInstance(uEditorConfig, awsProperty, mallResourceService, aliyunOSS)); | |||
| return actionEnter; | |||
| } | |||
| @@ -41,7 +41,7 @@ public class WxMallController extends BaseController { | |||
| @SystemControllerLog(description = "商城-当前查询") | |||
| public ResultData mallinfo() { | |||
| logger.debug("[" + getIpAddr() + "] WxMallController::mallinfo"); | |||
| return new ResultData(wxMallService.getByTenantInfo(getTenantInfo())); | |||
| return new ResultData(wxMallService.getByTenantInfo(ifParentUpdateTenantInfo())); | |||
| } | |||
| @@ -168,6 +168,7 @@ public class HomeController extends BaseController { | |||
| // 集团用户获取子商场 | |||
| List<WxMall> mallList = mallService.getSubByParentTenantId(info.getTenantId()); | |||
| map.put("mall", JSON.toJSONString(mall)); | |||
| map.put("subMalls", JSON.toJSONString(mallList)); | |||
| map.put("group", EnumGroupSupport.SUPPORT.getCode()); | |||
| } | |||
| @@ -69,7 +69,7 @@ public class ActionEnter { | |||
| case ActionMap.UPLOAD_VIDEO: | |||
| case ActionMap.UPLOAD_FILE: | |||
| conf = this.configManager.getConfig(actionCode); | |||
| state = new Uploader(request, conf, configManager.getMallResourceService()).doExec(); | |||
| state = new Uploader(request, conf, configManager.getMallResourceService(),configManager.getAliyunOSS()).doExec(); | |||
| break; | |||
| case ActionMap.CATCH_IMAGE: | |||
| @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray; | |||
| import com.alibaba.fastjson.JSONException; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.iformall.config.AwsProperty; | |||
| import com.iformall.file.aliyun.AliyunOSS; | |||
| import com.iformall.service.MallResourceService; | |||
| import com.iformall.ueditor.define.ActionMap; | |||
| @@ -30,14 +31,16 @@ public final class ConfigManager { | |||
| private UEditorConfig uEditorConfig; | |||
| private AwsProperty awsProperty; | |||
| private MallResourceService mallResourceService; | |||
| private AliyunOSS aliyunOSS; | |||
| /* | |||
| * 通过一个给定的路径构建一个配置管理器, 该管理器要求地址路径所在目录下必须存在config.properties文件 | |||
| */ | |||
| private ConfigManager(UEditorConfig uEditorConfig, AwsProperty awsProperty, MallResourceService mallResourceService) throws IOException { | |||
| private ConfigManager(UEditorConfig uEditorConfig, AwsProperty awsProperty, MallResourceService mallResourceService, AliyunOSS aliyunOSS) throws IOException { | |||
| this.uEditorConfig = uEditorConfig; | |||
| this.awsProperty = awsProperty; | |||
| this.mallResourceService = mallResourceService; | |||
| this.aliyunOSS = aliyunOSS; | |||
| String configPath = uEditorConfig.getConfig(); | |||
| configPath = configPath == null || configPath.isEmpty() ? configFileName : configPath; | |||
| this.initEnv(configPath); | |||
| @@ -49,10 +52,10 @@ public final class ConfigManager { | |||
| * @param uEditorConfig 配置文件 | |||
| * @return 配置管理器实例或者null | |||
| */ | |||
| public static ConfigManager getInstance(UEditorConfig uEditorConfig, AwsProperty awsProperty, MallResourceService mallResourceService) { | |||
| public static ConfigManager getInstance(UEditorConfig uEditorConfig, AwsProperty awsProperty, MallResourceService mallResourceService, AliyunOSS aliyunOSS) { | |||
| try { | |||
| return new ConfigManager(uEditorConfig, awsProperty, mallResourceService); | |||
| return new ConfigManager(uEditorConfig, awsProperty, mallResourceService, aliyunOSS); | |||
| } catch (Exception e) { | |||
| System.err.println("UEditor ConfigManager load error~"); | |||
| return null; | |||
| @@ -60,6 +63,14 @@ public final class ConfigManager { | |||
| } | |||
| public AliyunOSS getAliyunOSS() { | |||
| return aliyunOSS; | |||
| } | |||
| public void setAliyunOSS(AliyunOSS aliyunOSS) { | |||
| this.aliyunOSS = aliyunOSS; | |||
| } | |||
| public MallResourceService getMallResourceService() { | |||
| return mallResourceService; | |||
| } | |||
| @@ -12,8 +12,10 @@ import com.amazonaws.services.s3.AmazonS3ClientBuilder; | |||
| import com.amazonaws.services.s3.model.CannedAccessControlList; | |||
| import com.amazonaws.services.s3.model.ObjectMetadata; | |||
| import com.amazonaws.services.s3.model.PutObjectRequest; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.MallResource; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.file.aliyun.AliyunOSS; | |||
| import com.iformall.service.MallResourceService; | |||
| import com.iformall.shiro.UserSession; | |||
| import com.iformall.ueditor.define.BaseState; | |||
| @@ -23,6 +25,7 @@ import org.apache.shiro.SecurityUtils; | |||
| import org.apache.shiro.session.Session; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.multipart.MultipartFile; | |||
| import org.springframework.web.multipart.MultipartHttpServletRequest; | |||
| @@ -41,6 +44,8 @@ public class Uploader { | |||
| private MallResourceService mallResourceService = null; | |||
| private AmazonS3 s3 = null; | |||
| private AliyunOSS aliyunOSS; | |||
| private String getFileName(TenantEntity tenantEntity, String fileName) { | |||
| if (StringUtils.isBlank(tenantEntity.getParentTenantId())) { | |||
| fileName = tenantEntity.getTenantId() + "/" + fileName; | |||
| @@ -50,24 +55,25 @@ public class Uploader { | |||
| return fileName; | |||
| } | |||
| public Uploader(HttpServletRequest request, Map<String, Object> conf, MallResourceService mallResourceService) { | |||
| public Uploader(HttpServletRequest request, Map<String, Object> conf, MallResourceService mallResourceService, AliyunOSS aliyunOSS) { | |||
| this.request = request; | |||
| this.conf = conf; | |||
| this.mallResourceService = mallResourceService; | |||
| this.s3 = AmazonS3ClientBuilder.standard() | |||
| .withRegion(conf.get("clientRegion").toString()) | |||
| .withCredentials(new AWSCredentialsProvider() { | |||
| @Override | |||
| public AWSCredentials getCredentials() { | |||
| return new BasicAWSCredentials(conf.get("access").toString(), conf.get("secret").toString()); | |||
| } | |||
| @Override | |||
| public void refresh() { | |||
| } | |||
| }) | |||
| .build(); | |||
| this.aliyunOSS = aliyunOSS; | |||
| // this.s3 = AmazonS3ClientBuilder.standard() | |||
| // .withRegion(conf.get("clientRegion").toString()) | |||
| // .withCredentials(new AWSCredentialsProvider() { | |||
| // @Override | |||
| // public AWSCredentials getCredentials() { | |||
| // return new BasicAWSCredentials(conf.get("access").toString(), conf.get("secret").toString()); | |||
| // } | |||
| // | |||
| // @Override | |||
| // public void refresh() { | |||
| // | |||
| // } | |||
| // }) | |||
| // .build(); | |||
| } | |||
| public final State doExec() { | |||
| @@ -82,18 +88,22 @@ public class Uploader { | |||
| Session session = SecurityUtils.getSubject().getSession(); | |||
| String tenantId = (String)session.getAttribute(UserSession.tenantId); | |||
| String parentTenantId = (String)session.getAttribute(UserSession.parentTenantId); | |||
| TenantEntity tenantEntity = new TenantEntity(){{ | |||
| setTenantId(tenantId); | |||
| setParentTenantId(parentTenantId); | |||
| }}; | |||
| if(StringUtils.isBlank(tenantId)){ | |||
| tenantId = parentTenantId; | |||
| parentTenantId = ""; | |||
| } | |||
| TenantEntity tenantEntity = new TenantEntity(); | |||
| tenantEntity.setTenantId(tenantId); | |||
| tenantEntity.setParentTenantId(parentTenantId); | |||
| if (StringUtils.isBlank(tenantId)) { | |||
| logger.error("TENANT is null"); | |||
| } | |||
| String fileName = UUID.randomUUID().toString(); | |||
| int dot = multiReq.getOriginalFilename().lastIndexOf('.'); | |||
| String fileFormat = ""; | |||
| if (dot >= 0) { | |||
| String fileFormat = multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length()); | |||
| fileFormat = multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length()); | |||
| fileName = getFileName(tenantEntity, fileName + fileFormat); | |||
| } else { | |||
| fileName = getFileName(tenantEntity, fileName); | |||
| @@ -110,19 +120,29 @@ public class Uploader { | |||
| metadata.setContentLength(multiReq.getSize()); | |||
| try { | |||
| s3.putObject( | |||
| new PutObjectRequest(conf.get("bucketName").toString(), fileName, multiReq.getInputStream(), metadata) | |||
| .withCannedAcl(CannedAccessControlList.PublicRead)); | |||
| URL url = s3.getUrl(conf.get("bucketName").toString(), fileName); | |||
| // s3.putObject( | |||
| // new PutObjectRequest(conf.get("bucketName").toString(), fileName, multiReq.getInputStream(), metadata) | |||
| // .withCannedAcl(CannedAccessControlList.PublicRead)); | |||
| // URL url = s3.getUrl(conf.get("bucketName").toString(), fileName); | |||
| //logger.info(url.toString()); | |||
| state.putInfo("url", url.toString()); | |||
| ResultData data = aliyunOSS.uploadFile(tenantEntity.getTenantId(), fileFormat, multiReq.getInputStream()); | |||
| Map<String, String> map = (Map<String, String>) data.data; | |||
| state.putInfo("url",map.get("url")); | |||
| MallResource mr = new MallResource(); | |||
| mr.updateTenantInfo(tenantEntity); | |||
| mr.setBucket(conf.get("bucketName").toString()); | |||
| mr.setS3Key(fileName); | |||
| mr.setUrl(url.toString()); | |||
| mr.setBucket(map.get("bucketName")); | |||
| //mr.setS3Key(fileName); | |||
| mr.setUrl(map.get("url")); | |||
| // state.putInfo("url", url.toString()); | |||
| // | |||
| // MallResource mr = new MallResource(); | |||
| // mr.updateTenantInfo(tenantEntity); | |||
| // mr.setBucket(conf.get("bucketName").toString()); | |||
| // mr.setS3Key(fileName); | |||
| // mr.setUrl(url.toString()); | |||
| mallResourceService.saveOrUpdate(mr); | |||
| } catch (AmazonServiceException ase) { | |||
| /* | |||
| @@ -35,6 +35,7 @@ public class AliyunOSS { | |||
| data = new ResultData(); | |||
| Map<String, String> map = new HashMap<>(); | |||
| map.put("url", upload); | |||
| map.put("bucketName", aliyunOSSConfig.getBucketname()); | |||
| data.data = map; | |||
| }else{ | |||
| data = new ResultData(ResultData.ERROR,"上传失败"); | |||
| @@ -42,6 +43,7 @@ public class AliyunOSS { | |||
| return data; | |||
| } | |||
| /** | |||
| * 上传 | |||
| * @param inputStream | |||
| @@ -49,11 +51,11 @@ public class AliyunOSS { | |||
| */ | |||
| public String upload(String folder, String suffix,InputStream inputStream){ | |||
| log.info("=========>OSS文件上传开始:"); | |||
| String endpoint= aliyunOSSConfig.getEndpoint(); | |||
| String accessKeyId= aliyunOSSConfig.getKeyid(); | |||
| String accessKeySecret=aliyunOSSConfig.getKeysecret(); | |||
| String bucketName=aliyunOSSConfig.getBucketname(); | |||
| String fileHost=aliyunOSSConfig.getFilehost(); | |||
| String endpoint = aliyunOSSConfig.getEndpoint(); | |||
| String accessKeyId = aliyunOSSConfig.getKeyid(); | |||
| String accessKeySecret = aliyunOSSConfig.getKeysecret(); | |||
| String bucketName = aliyunOSSConfig.getBucketname(); | |||
| String fileHost = aliyunOSSConfig.getFilehost(); | |||
| SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); | |||
| String dateStr = format.format(new Date()); | |||
| @@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature; | |||
| import com.fasterxml.jackson.databind.ObjectMapper; | |||
| import com.fasterxml.jackson.databind.module.SimpleModule; | |||
| import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; | |||
| import com.iformall.file.aliyun.AliyunOSS; | |||
| import com.iformall.interceptor.HttpServletRequestWrapperFilter; | |||
| import com.iformall.interceptor.RequestInterceptor; | |||
| import com.iformall.service.MallResourceService; | |||
| @@ -48,10 +49,13 @@ public class WebConfig implements WebMvcConfigurer { | |||
| @Autowired | |||
| private MallResourceService mallResourceService; | |||
| @Autowired | |||
| private AliyunOSS aliyunOSS; | |||
| @Bean | |||
| @ConditionalOnMissingBean(ActionEnter.class) | |||
| public ActionEnter actionEnter() { | |||
| ActionEnter actionEnter = new ActionEnter(ConfigManager.getInstance(uEditorConfig, awsProperty, mallResourceService)); | |||
| ActionEnter actionEnter = new ActionEnter(ConfigManager.getInstance(uEditorConfig, awsProperty, mallResourceService, aliyunOSS)); | |||
| return actionEnter; | |||
| } | |||
| @@ -69,7 +69,7 @@ public class ActionEnter { | |||
| case ActionMap.UPLOAD_VIDEO: | |||
| case ActionMap.UPLOAD_FILE: | |||
| conf = this.configManager.getConfig(actionCode); | |||
| state = new Uploader(request, conf, configManager.getMallResourceService()).doExec(); | |||
| state = new Uploader(request, conf, configManager.getMallResourceService(),configManager.getAliyunOSS()).doExec(); | |||
| break; | |||
| case ActionMap.CATCH_IMAGE: | |||
| @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray; | |||
| import com.alibaba.fastjson.JSONException; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.iformall.config.AwsProperty; | |||
| import com.iformall.file.aliyun.AliyunOSS; | |||
| import com.iformall.service.MallResourceService; | |||
| import com.iformall.ueditor.define.ActionMap; | |||
| @@ -30,14 +31,16 @@ public final class ConfigManager { | |||
| private UEditorConfig uEditorConfig; | |||
| private AwsProperty awsProperty; | |||
| private MallResourceService mallResourceService; | |||
| private AliyunOSS aliyunOSS; | |||
| /* | |||
| * 通过一个给定的路径构建一个配置管理器, 该管理器要求地址路径所在目录下必须存在config.properties文件 | |||
| */ | |||
| private ConfigManager(UEditorConfig uEditorConfig, AwsProperty awsProperty, MallResourceService mallResourceService) throws IOException { | |||
| private ConfigManager(UEditorConfig uEditorConfig, AwsProperty awsProperty, MallResourceService mallResourceService, AliyunOSS aliyunOSS) throws IOException { | |||
| this.uEditorConfig = uEditorConfig; | |||
| this.awsProperty = awsProperty; | |||
| this.mallResourceService = mallResourceService; | |||
| this.aliyunOSS = aliyunOSS; | |||
| String configPath = uEditorConfig.getConfig(); | |||
| configPath = configPath == null || configPath.isEmpty() ? configFileName : configPath; | |||
| this.initEnv(configPath); | |||
| @@ -49,10 +52,10 @@ public final class ConfigManager { | |||
| * @param uEditorConfig 配置文件 | |||
| * @return 配置管理器实例或者null | |||
| */ | |||
| public static ConfigManager getInstance(UEditorConfig uEditorConfig, AwsProperty awsProperty, MallResourceService mallResourceService) { | |||
| public static ConfigManager getInstance(UEditorConfig uEditorConfig, AwsProperty awsProperty, MallResourceService mallResourceService, AliyunOSS aliyunOSS) { | |||
| try { | |||
| return new ConfigManager(uEditorConfig, awsProperty, mallResourceService); | |||
| return new ConfigManager(uEditorConfig, awsProperty, mallResourceService, aliyunOSS); | |||
| } catch (Exception e) { | |||
| System.err.println("UEditor ConfigManager load error~"); | |||
| return null; | |||
| @@ -60,6 +63,14 @@ public final class ConfigManager { | |||
| } | |||
| public AliyunOSS getAliyunOSS() { | |||
| return aliyunOSS; | |||
| } | |||
| public void setAliyunOSS(AliyunOSS aliyunOSS) { | |||
| this.aliyunOSS = aliyunOSS; | |||
| } | |||
| public MallResourceService getMallResourceService() { | |||
| return mallResourceService; | |||
| } | |||
| @@ -12,8 +12,10 @@ import com.amazonaws.services.s3.AmazonS3ClientBuilder; | |||
| import com.amazonaws.services.s3.model.CannedAccessControlList; | |||
| import com.amazonaws.services.s3.model.ObjectMetadata; | |||
| import com.amazonaws.services.s3.model.PutObjectRequest; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.MallResource; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.file.aliyun.AliyunOSS; | |||
| import com.iformall.service.MallResourceService; | |||
| import com.iformall.shiro.UserSession; | |||
| import com.iformall.ueditor.define.BaseState; | |||
| @@ -41,29 +43,32 @@ public class Uploader { | |||
| private MallResourceService mallResourceService = null; | |||
| private AmazonS3 s3 = null; | |||
| private AliyunOSS aliyunOSS; | |||
| private String getFileName(TenantEntity tenantEntity, String fileName) { | |||
| fileName = tenantEntity.getTenantId() + "/" + fileName; | |||
| return fileName; | |||
| } | |||
| public Uploader(HttpServletRequest request, Map<String, Object> conf, MallResourceService mallResourceService) { | |||
| public Uploader(HttpServletRequest request, Map<String, Object> conf, MallResourceService mallResourceService, AliyunOSS aliyunOSS) { | |||
| this.request = request; | |||
| this.conf = conf; | |||
| this.mallResourceService = mallResourceService; | |||
| this.s3 = AmazonS3ClientBuilder.standard() | |||
| .withRegion(conf.get("clientRegion").toString()) | |||
| .withCredentials(new AWSCredentialsProvider() { | |||
| @Override | |||
| public AWSCredentials getCredentials() { | |||
| return new BasicAWSCredentials(conf.get("access").toString(), conf.get("secret").toString()); | |||
| } | |||
| @Override | |||
| public void refresh() { | |||
| } | |||
| }) | |||
| .build(); | |||
| this.aliyunOSS = aliyunOSS; | |||
| // this.s3 = AmazonS3ClientBuilder.standard() | |||
| // .withRegion(conf.get("clientRegion").toString()) | |||
| // .withCredentials(new AWSCredentialsProvider() { | |||
| // @Override | |||
| // public AWSCredentials getCredentials() { | |||
| // return new BasicAWSCredentials(conf.get("access").toString(), conf.get("secret").toString()); | |||
| // } | |||
| // | |||
| // @Override | |||
| // public void refresh() { | |||
| // | |||
| // } | |||
| // }) | |||
| // .build(); | |||
| } | |||
| public final State doExec() { | |||
| @@ -86,8 +91,9 @@ public class Uploader { | |||
| String fileName = UUID.randomUUID().toString(); | |||
| int dot = multiReq.getOriginalFilename().lastIndexOf('.'); | |||
| String fileFormat = ""; | |||
| if (dot >= 0) { | |||
| String fileFormat = multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length()); | |||
| fileFormat = multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length()); | |||
| fileName = getFileName(tenantEntity, fileName + fileFormat); | |||
| } else { | |||
| fileName = getFileName(tenantEntity, fileName); | |||
| @@ -104,19 +110,28 @@ public class Uploader { | |||
| metadata.setContentLength(multiReq.getSize()); | |||
| try { | |||
| s3.putObject( | |||
| new PutObjectRequest(conf.get("bucketName").toString(), fileName, multiReq.getInputStream(), metadata) | |||
| .withCannedAcl(CannedAccessControlList.PublicRead)); | |||
| URL url = s3.getUrl(conf.get("bucketName").toString(), fileName); | |||
| // s3.putObject( | |||
| // new PutObjectRequest(conf.get("bucketName").toString(), fileName, multiReq.getInputStream(), metadata) | |||
| // .withCannedAcl(CannedAccessControlList.PublicRead)); | |||
| // URL url = s3.getUrl(conf.get("bucketName").toString(), fileName); | |||
| //logger.info(url.toString()); | |||
| state.putInfo("url", url.toString()); | |||
| ResultData data = aliyunOSS.uploadFile(tenantEntity.getTenantId(), fileFormat, multiReq.getInputStream()); | |||
| Map<String, String> map = (Map<String, String>) data.data; | |||
| state.putInfo("url",map.get("url")); | |||
| MallResource mr = new MallResource(); | |||
| mr.updateTenantInfo(tenantEntity); | |||
| mr.setBucket(conf.get("bucketName").toString()); | |||
| mr.setS3Key(fileName); | |||
| mr.setUrl(url.toString()); | |||
| mr.setBucket(map.get("bucketName")); | |||
| //mr.setS3Key(fileName); | |||
| mr.setUrl(map.get("url")); | |||
| // state.putInfo("url", url.toString()); | |||
| // | |||
| // MallResource mr = new MallResource(); | |||
| // mr.updateTenantInfo(tenantEntity); | |||
| // mr.setBucket(conf.get("bucketName").toString()); | |||
| // mr.setS3Key(fileName); | |||
| // mr.setUrl(url.toString()); | |||
| mallResourceService.saveOrUpdate(mr); | |||
| } catch (AmazonServiceException ase) { | |||
| /* | |||