| @@ -0,0 +1,61 @@ | |||
| package com.iformall.config; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.context.annotation.Bean; | |||
| import org.springframework.context.annotation.Configuration; | |||
| import springfox.documentation.builders.ApiInfoBuilder; | |||
| import springfox.documentation.builders.ParameterBuilder; | |||
| import springfox.documentation.builders.PathSelectors; | |||
| import springfox.documentation.builders.RequestHandlerSelectors; | |||
| import springfox.documentation.schema.ModelRef; | |||
| import springfox.documentation.service.ApiInfo; | |||
| import springfox.documentation.service.Parameter; | |||
| import springfox.documentation.spi.DocumentationType; | |||
| import springfox.documentation.spring.web.paths.RelativePathProvider; | |||
| import springfox.documentation.spring.web.plugins.Docket; | |||
| import springfox.documentation.swagger2.annotations.EnableSwagger2; | |||
| import javax.servlet.ServletContext; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| //参考:http://blog.csdn.net/catoop/article/details/50668896 | |||
| @Configuration | |||
| @EnableSwagger2 | |||
| public class Swagger2Config { | |||
| @Autowired | |||
| private ServletContext servletContext; | |||
| @Bean | |||
| public Docket createRestApi() { | |||
| ParameterBuilder tokenPar = new ParameterBuilder(); | |||
| List<Parameter> pars = new ArrayList<Parameter>(); | |||
| //增加一个request的header参数 | |||
| tokenPar.name("token").description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build(); | |||
| pars.add(tokenPar.build()); | |||
| return new Docket(DocumentationType.SWAGGER_2) | |||
| .apiInfo(apiInfo()) | |||
| .select() | |||
| .apis(RequestHandlerSelectors.basePackage("com.iformall.controller")) | |||
| .paths(PathSelectors.any()) | |||
| .build() | |||
| .globalOperationParameters(pars) | |||
| .pathProvider(new RelativePathProvider(servletContext) { | |||
| @Override | |||
| public String getApplicationBasePath() { | |||
| return "/api"; | |||
| } | |||
| }); | |||
| } | |||
| private ApiInfo apiInfo() { | |||
| return new ApiInfoBuilder() | |||
| .title("a端 api") | |||
| .description("a api") | |||
| .termsOfServiceUrl("http://localhost:7000") | |||
| .version("2.0") | |||
| .build(); | |||
| } | |||
| } | |||
| @@ -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) { | |||
| /* | |||
| @@ -58,7 +58,7 @@ spring: | |||
| keysecret: VfWqGb83qIQrS9us45utskl8itd7ry | |||
| bucketname: formall | |||
| filehost: malinkadmin | |||
| filedomain: http://formall.oss-accelerate.aliyuncs.com | |||
| filedomain: https://formall.oss-accelerate.aliyuncs.com | |||
| mail: | |||
| @@ -54,7 +54,7 @@ spring: | |||
| keysecret: VfWqGb83qIQrS9us45utskl8itd7ry | |||
| bucketname: formall | |||
| filehost: malinkadmin | |||
| filedomain: http://formall.oss-accelerate.aliyuncs.com | |||
| filedomain: https://formall.oss-accelerate.aliyuncs.com | |||
| mail: | |||
| host: smtp.exmail.qq.com | |||
| @@ -57,7 +57,7 @@ spring: | |||
| keysecret: VfWqGb83qIQrS9us45utskl8itd7ry | |||
| bucketname: formall | |||
| filehost: malinkbapi | |||
| filedomain: http://formall.oss-accelerate.aliyuncs.com | |||
| filedomain: https://formall.oss-accelerate.aliyuncs.com | |||
| mail: | |||
| @@ -53,7 +53,7 @@ spring: | |||
| keysecret: VfWqGb83qIQrS9us45utskl8itd7ry | |||
| bucketname: formall | |||
| filehost: malinkadmin | |||
| filedomain: http://formall.oss-accelerate.aliyuncs.com | |||
| filedomain: https://formall.oss-accelerate.aliyuncs.com | |||
| mail: | |||
| host: smtp.exmail.qq.com | |||
| @@ -1,5 +1,6 @@ | |||
| package com.iformall.config; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.context.annotation.Bean; | |||
| import org.springframework.context.annotation.Configuration; | |||
| import springfox.documentation.builders.ApiInfoBuilder; | |||
| @@ -10,9 +11,11 @@ import springfox.documentation.schema.ModelRef; | |||
| import springfox.documentation.service.ApiInfo; | |||
| import springfox.documentation.service.Parameter; | |||
| import springfox.documentation.spi.DocumentationType; | |||
| import springfox.documentation.spring.web.paths.RelativePathProvider; | |||
| import springfox.documentation.spring.web.plugins.Docket; | |||
| import springfox.documentation.swagger2.annotations.EnableSwagger2; | |||
| import javax.servlet.ServletContext; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| @@ -21,6 +24,9 @@ import java.util.List; | |||
| @EnableSwagger2 | |||
| public class Swagger2Config { | |||
| @Autowired | |||
| private ServletContext servletContext; | |||
| @Bean | |||
| public Docket createRestApi() { | |||
| ParameterBuilder tokenPar = new ParameterBuilder(); | |||
| @@ -34,7 +40,13 @@ public class Swagger2Config { | |||
| .apis(RequestHandlerSelectors.basePackage("com.iformall.controller")) | |||
| .paths(PathSelectors.any()) | |||
| .build() | |||
| .globalOperationParameters(pars); | |||
| .globalOperationParameters(pars) | |||
| .pathProvider(new RelativePathProvider(servletContext) { | |||
| @Override | |||
| public String getApplicationBasePath() { | |||
| return "/api"; | |||
| } | |||
| }); | |||
| } | |||
| private ApiInfo apiInfo() { | |||
| @@ -57,7 +57,7 @@ spring: | |||
| keysecret: VfWqGb83qIQrS9us45utskl8itd7ry | |||
| bucketname: formall | |||
| filehost: malinkcapi | |||
| filedomain: http://formall.oss-accelerate.aliyuncs.com | |||
| filedomain: https://formall.oss-accelerate.aliyuncs.com | |||
| mail: | |||
| @@ -52,7 +52,7 @@ spring: | |||
| keysecret: VfWqGb83qIQrS9us45utskl8itd7ry | |||
| bucketname: formall | |||
| filehost: malinkadmin | |||
| filedomain: http://formall.oss-accelerate.aliyuncs.com | |||
| filedomain: https://formall.oss-accelerate.aliyuncs.com | |||
| mail: | |||
| @@ -58,7 +58,7 @@ spring: | |||
| keysecret: VfWqGb83qIQrS9us45utskl8itd7ry | |||
| bucketname: formall | |||
| filehost: malinkcallback | |||
| filedomain: http://formall.oss-accelerate.aliyuncs.com | |||
| filedomain: https://formall.oss-accelerate.aliyuncs.com | |||
| mail: | |||
| @@ -53,7 +53,7 @@ spring: | |||
| keysecret: VfWqGb83qIQrS9us45utskl8itd7ry | |||
| bucketname: formall | |||
| filehost: malinkadmin | |||
| filedomain: http://formall.oss-accelerate.aliyuncs.com | |||
| filedomain: https://formall.oss-accelerate.aliyuncs.com | |||
| mail: | |||
| @@ -59,7 +59,7 @@ spring: | |||
| keysecret: VfWqGb83qIQrS9us45utskl8itd7ry | |||
| bucketname: formall | |||
| filehost: malinkmqconsumer | |||
| filedomain: http://formall.oss-accelerate.aliyuncs.com | |||
| filedomain: https://formall.oss-accelerate.aliyuncs.com | |||
| mail: | |||
| @@ -53,7 +53,7 @@ spring: | |||
| keysecret: VfWqGb83qIQrS9us45utskl8itd7ry | |||
| bucketname: formall | |||
| filehost: malinkadmin | |||
| filedomain: http://formall.oss-accelerate.aliyuncs.com | |||
| filedomain: https://formall.oss-accelerate.aliyuncs.com | |||
| mail: | |||
| host: smtp.exmail.qq.com | |||
| @@ -57,7 +57,7 @@ spring: | |||
| keysecret: VfWqGb83qIQrS9us45utskl8itd7ry | |||
| bucketname: formall | |||
| filehost: malinkposapi | |||
| filedomain: http://formall.oss-accelerate.aliyuncs.com | |||
| filedomain: https://formall.oss-accelerate.aliyuncs.com | |||
| mail: | |||
| @@ -52,7 +52,7 @@ spring: | |||
| keysecret: VfWqGb83qIQrS9us45utskl8itd7ry | |||
| bucketname: formall | |||
| filehost: malinkadmin | |||
| filedomain: http://formall.oss-accelerate.aliyuncs.com | |||
| filedomain: https://formall.oss-accelerate.aliyuncs.com | |||
| mail: | |||
| host: smtp.exmail.qq.com | |||
| @@ -59,7 +59,7 @@ spring: | |||
| keysecret: VfWqGb83qIQrS9us45utskl8itd7ry | |||
| bucketname: formall | |||
| filehost: malinkschedule | |||
| filedomain: http://formall.oss-accelerate.aliyuncs.com | |||
| filedomain: https://formall.oss-accelerate.aliyuncs.com | |||
| mail: | |||
| @@ -53,7 +53,7 @@ spring: | |||
| keysecret: VfWqGb83qIQrS9us45utskl8itd7ry | |||
| bucketname: formall | |||
| filehost: malinkadmin | |||
| filedomain: http://formall.oss-accelerate.aliyuncs.com | |||
| filedomain: https://formall.oss-accelerate.aliyuncs.com | |||
| mail: | |||
| host: smtp.exmail.qq.com | |||
| @@ -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()); | |||
| @@ -760,7 +760,7 @@ | |||
| </select> | |||
| <select id="findPressData" parameterType="com.iformall.domain.po.WxCoupon" resultMap="statisMap"> | |||
| select c.id, c.`cover_img`,c.`title`,c.`sale_price`,c.`price`, | |||
| select c.id,c.tenant_id, c.`cover_img`,c.`title`,c.`sale_price`,c.`price`, | |||
| ifnull(op.press_count,0) as press_count, | |||
| ifnull(o.press_succ_count,0) as press_succ_count, | |||
| ifnull(op2.join_count,0) as join_count, | |||
| @@ -521,11 +521,11 @@ | |||
| </select> | |||
| <select id="searchMerchantByname" resultType="hashmap" parameterType="com.iformall.domain.po.WxRentContract"> | |||
| select merchant_id,merchant_name from wx_rent_contract where tenant_id = #{tenantId} and merchant_name like concat('%',#{merchantName},'%') | |||
| select merchant_id,merchant_name from wx_rent_contract where tenant_id = #{tenantId} and merchant_name like concat('%',#{merchantName},'%') and rent_shop_type = 1 | |||
| </select> | |||
| <select id="getByMerchantId" resultType="com.iformall.domain.po.WxRentContract" parameterType="com.iformall.domain.po.WxRentContract"> | |||
| select * from wx_rent_contract where merchant_id = #{merchantId} and in (3,5) ORDER BY rental_end_date DESC limit 1 | |||
| select * from wx_rent_contract where merchant_id = #{merchantId} and status in (3,5) ORDER BY rental_end_date DESC limit 1 | |||
| </select> | |||
| <select id="getAllContractBymerchantId" resultType="com.iformall.domain.po.WxRentContract" parameterType="com.iformall.domain.po.WxRentContract"> | |||
| @@ -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) { | |||
| /* | |||
| @@ -57,7 +57,7 @@ spring: | |||
| keysecret: VfWqGb83qIQrS9us45utskl8itd7ry | |||
| bucketname: formall | |||
| filehost: malinksysadmin | |||
| filedomain: http://formall.oss-accelerate.aliyuncs.com | |||
| filedomain: https://formall.oss-accelerate.aliyuncs.com | |||
| mail: | |||
| @@ -53,7 +53,7 @@ spring: | |||
| keysecret: VfWqGb83qIQrS9us45utskl8itd7ry | |||
| bucketname: formall | |||
| filehost: malinkadmin | |||
| filedomain: http://formall.oss-accelerate.aliyuncs.com | |||
| filedomain: https://formall.oss-accelerate.aliyuncs.com | |||
| mail: | |||
| host: smtp.exmail.qq.com | |||
| @@ -59,7 +59,7 @@ spring: | |||
| keysecret: VfWqGb83qIQrS9us45utskl8itd7ry | |||
| bucketname: formall | |||
| filehost: malinkwebsocketserver | |||
| filedomain: http://formall.oss-accelerate.aliyuncs.com | |||
| filedomain: https://formall.oss-accelerate.aliyuncs.com | |||
| mail: | |||
| @@ -53,7 +53,7 @@ spring: | |||
| keysecret: VfWqGb83qIQrS9us45utskl8itd7ry | |||
| bucketname: formall | |||
| filehost: malinkadmin | |||
| filedomain: http://formall.oss-accelerate.aliyuncs.com | |||
| filedomain: https://formall.oss-accelerate.aliyuncs.com | |||
| mail: | |||
| host: smtp.exmail.qq.com | |||