| @@ -1,13 +1,11 @@ | |||
| package com.iformall.controller.sys; | |||
| import com.amazonaws.services.s3.model.*; | |||
| import com.iformall.annotation.SystemControllerLog; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.controller.base.BaseController; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.file.aliyun.AliyunOSS; | |||
| import com.iformall.service.QrCodeService; | |||
| import com.iformall.utils.ImgUtil; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiOperation; | |||
| @@ -37,18 +35,6 @@ public class UploadController extends BaseController { | |||
| @Autowired | |||
| private AliyunOSS aliyunOSS; | |||
| @Autowired | |||
| private QrCodeService qrCodeService; | |||
| private String getFileName(TenantEntity tenantEntity, String fileName) { | |||
| if (StringUtils.isBlank(tenantEntity.getParentTenantId())) { | |||
| fileName = tenantEntity.getTenantId() + "/" + fileName; | |||
| } else { | |||
| fileName = tenantEntity.getTenantId() + "/" + tenantEntity.getParentTenantId() + "/" +fileName; | |||
| } | |||
| return fileName; | |||
| } | |||
| /** | |||
| * 上传文件 | |||
| * | |||
| @@ -64,21 +50,12 @@ public class UploadController extends BaseController { | |||
| TenantEntity tenantEntity = getTenantInfo(); | |||
| ObjectMetadata metadata = new ObjectMetadata(); | |||
| metadata.setContentType(multiReq.getContentType()); | |||
| metadata.setContentLength(multiReq.getSize()); | |||
| String fileName = UUID.randomUUID().toString(); | |||
| int dot = multiReq.getOriginalFilename().lastIndexOf('.'); | |||
| String fileFormat = ""; | |||
| if (dot >= 0) { | |||
| fileFormat = multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length()); | |||
| fileName = getFileName(tenantEntity, fileName + fileFormat); | |||
| } else { | |||
| fileName = getFileName(tenantEntity, fileName); | |||
| } | |||
| // ResultData data = qrCodeService.awsUpload(multiReq.getInputStream(), metadata, fileName, tenantEntity); | |||
| ResultData data = aliyunOSS.uploadFile(tenantEntity.getTenantId(), fileFormat, multiReq.getInputStream()); | |||
| return data; | |||
| } | |||
| @@ -103,16 +80,13 @@ public class UploadController extends BaseController { | |||
| if (size > length) { | |||
| return new ResultData(ErrorCode.PICTURE_SIZE_EXCEED); | |||
| } | |||
| String fileName = UUID.randomUUID().toString(); | |||
| String tempFileName = fileName; | |||
| String tempFileName = UUID.randomUUID().toString(); | |||
| String fileFormat = ""; | |||
| int dot = multiReq.getOriginalFilename().lastIndexOf('.'); | |||
| if (dot >= 0) { | |||
| fileFormat = multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length()); | |||
| fileName = getFileName(tenantEntity, fileName + fileFormat); | |||
| } else { | |||
| fileName = getFileName(tenantEntity, fileName); | |||
| } | |||
| @@ -138,19 +112,11 @@ public class UploadController extends BaseController { | |||
| logger.info("local new file: " + localNewImgFileName); | |||
| // 删除本地缓存 | |||
| localFile.delete(); | |||
| ObjectMetadata metadata = new ObjectMetadata(); | |||
| metadata.setContentType(multiReq.getContentType()); | |||
| metadata.setContentLength(newFile.length()); | |||
| // ResultData data = qrCodeService.awsUpload(new FileInputStream(newFile), metadata, fileName, tenantEntity); | |||
| ResultData data = aliyunOSS.uploadFile(tenantEntity.getTenantId(), fileFormat, new FileInputStream(newFile)); | |||
| // 删除本地缓存 | |||
| newFile.delete(); | |||
| return data; | |||
| } else { | |||
| ObjectMetadata metadata = new ObjectMetadata(); | |||
| metadata.setContentType(multiReq.getContentType()); | |||
| metadata.setContentLength(size); | |||
| // ResultData data = qrCodeService.awsUpload(multiReq.getInputStream(), metadata, fileName, tenantEntity); | |||
| ResultData data = aliyunOSS.uploadFile(tenantEntity.getTenantId(), fileFormat, multiReq.getInputStream()); | |||
| return data; | |||
| } | |||
| @@ -180,26 +146,14 @@ public class UploadController extends BaseController { | |||
| for(MultipartFile multipartFile: files) { | |||
| Map<String, String> map = new HashMap<>(); | |||
| ObjectMetadata metadata = new ObjectMetadata(); | |||
| metadata.setContentType(multipartFile.getContentType()); | |||
| metadata.setContentLength(multipartFile.getSize()); | |||
| FileOutputStream fos = null; | |||
| BufferedInputStream fs = null; | |||
| map.put("key", multipartFile.getOriginalFilename()); | |||
| String fileName = UUID.randomUUID().toString(); | |||
| int dot = multipartFile.getOriginalFilename().lastIndexOf('.'); | |||
| String fileFormat = ""; | |||
| if (dot >= 0) { | |||
| fileFormat = multipartFile.getOriginalFilename().substring(dot, multipartFile.getOriginalFilename().length());; | |||
| fileName = getFileName(tenantEntity, fileName + fileFormat); | |||
| } else { | |||
| fileName = getFileName(tenantEntity, fileName); | |||
| } | |||
| // ResultData data1 = qrCodeService.awsUpload(multipartFile.getInputStream(), metadata, fileName, getTenantInfo()); | |||
| ResultData data1 = aliyunOSS.uploadFile(tenantEntity.getTenantId(), fileFormat, multipartFile.getInputStream()); | |||
| if(data1.code == ResultData.SUCCESS) { | |||
| @@ -233,21 +187,12 @@ public class UploadController extends BaseController { | |||
| public ResultData cimgUpload(@RequestParam("file") MultipartFile multiReq) throws Exception{ | |||
| logger.info("[" + getIpAddr() + "] UploadController::cimgUpload"); | |||
| ObjectMetadata metadata = new ObjectMetadata(); | |||
| metadata.setContentType(multiReq.getContentType()); | |||
| metadata.setContentLength(multiReq.getSize()); | |||
| String fileName = multiReq.getOriginalFilename(); | |||
| int dot = multiReq.getOriginalFilename().lastIndexOf('.'); | |||
| String fileFormat = ""; | |||
| if (dot >= 0) { | |||
| fileFormat = multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length()); | |||
| } | |||
| fileName = "cimg/" + fileName; | |||
| // ResultData data = qrCodeService.awsUpload(multiReq.getInputStream(), metadata, fileName, new TenantEntity() {{ | |||
| // setTenantId("cimg"); | |||
| // }}); | |||
| ResultData data = aliyunOSS.uploadFile("cimg", fileFormat, multiReq.getInputStream()); | |||
| return data; | |||
| } | |||
| @@ -1,17 +1,5 @@ | |||
| package com.iformall.ueditor.upload; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.amazonaws.AmazonClientException; | |||
| import com.amazonaws.AmazonServiceException; | |||
| import com.amazonaws.auth.AWSCredentials; | |||
| import com.amazonaws.auth.AWSCredentialsProvider; | |||
| import com.amazonaws.auth.BasicAWSCredentials; | |||
| import com.amazonaws.services.s3.AmazonS3; | |||
| 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; | |||
| @@ -25,15 +13,12 @@ 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; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import java.io.IOException; | |||
| import java.net.URL; | |||
| import java.util.Map; | |||
| import java.util.UUID; | |||
| public class Uploader { | |||
| @@ -42,38 +27,14 @@ public class Uploader { | |||
| private HttpServletRequest request = null; | |||
| private Map<String, Object> conf = null; | |||
| 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; | |||
| } else { | |||
| fileName = tenantEntity.getTenantId() + "/" + tenantEntity.getParentTenantId() + "/" + fileName; | |||
| } | |||
| return fileName; | |||
| } | |||
| public Uploader(HttpServletRequest request, Map<String, Object> conf, MallResourceService mallResourceService, AliyunOSS aliyunOSS) { | |||
| this.request = request; | |||
| this.conf = conf; | |||
| this.mallResourceService = mallResourceService; | |||
| 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() { | |||
| @@ -99,32 +60,17 @@ public class Uploader { | |||
| logger.error("TENANT is null"); | |||
| } | |||
| String fileName = UUID.randomUUID().toString(); | |||
| int dot = multiReq.getOriginalFilename().lastIndexOf('.'); | |||
| String fileFormat = ""; | |||
| if (dot >= 0) { | |||
| fileFormat = multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length()); | |||
| fileName = getFileName(tenantEntity, fileName + fileFormat); | |||
| } else { | |||
| fileName = getFileName(tenantEntity, fileName); | |||
| } | |||
| state = state = new BaseState(true); | |||
| state = new BaseState(true); | |||
| state.putInfo("size", multiReq.getSize()); | |||
| state.putInfo("title", filedName); | |||
| JSONObject stateJson = JSON.parseObject(state.toJSONString()); | |||
| ObjectMetadata metadata = new ObjectMetadata(); | |||
| metadata.setContentType(multiReq.getContentType()); | |||
| 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); | |||
| //logger.info(url.toString()); | |||
| ResultData data = aliyunOSS.uploadFile(tenantEntity.getTenantId(), fileFormat, multiReq.getInputStream()); | |||
| Map<String, String> map = (Map<String, String>) data.data; | |||
| @@ -133,38 +79,10 @@ public class Uploader { | |||
| MallResource mr = new MallResource(); | |||
| mr.updateTenantInfo(tenantEntity); | |||
| 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) { | |||
| /* | |||
| logger.warn("Caught an AmazonServiceException, which " + | |||
| "means your request made it " + | |||
| "to Amazon S3, but was rejected with an error response" + | |||
| " for some reason."); | |||
| logger.warn(ase.getMessage()); | |||
| */ | |||
| ase.printStackTrace(); | |||
| } catch (AmazonClientException ace) { | |||
| /* | |||
| logger.warn("Caught an AmazonClientException, which " + | |||
| "means the client encountered " + | |||
| "an internal error while trying to " + | |||
| "communicate with S3, " + | |||
| "such as not being able to access the network."); | |||
| logger.warn("Error Message: " + ace.getMessage()); | |||
| */ | |||
| ace.printStackTrace(); | |||
| } catch (IOException ioe) { | |||
| //logger.warn("Caught an IOException: " + ioe.getMessage()); | |||
| ioe.printStackTrace(); | |||
| } | |||
| } | |||
| @@ -1,22 +1,9 @@ | |||
| package com.iformall.controller; | |||
| import com.amazonaws.AmazonClientException; | |||
| import com.amazonaws.AmazonServiceException; | |||
| import com.amazonaws.auth.AWSCredentials; | |||
| import com.amazonaws.auth.AWSCredentialsProvider; | |||
| import com.amazonaws.auth.BasicAWSCredentials; | |||
| import com.amazonaws.services.s3.AmazonS3; | |||
| 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.config.AwsProperty; | |||
| 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.utils.ImgUtil; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiOperation; | |||
| @@ -31,7 +18,6 @@ import org.springframework.web.bind.annotation.RestController; | |||
| import org.springframework.web.multipart.MultipartFile; | |||
| import java.io.*; | |||
| import java.net.URL; | |||
| import java.util.*; | |||
| import java.util.List; | |||
| @@ -42,94 +28,12 @@ public class UploadController extends BaseController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private AwsProperty awsProperty; | |||
| @Autowired | |||
| private MallResourceService mallResourceService; | |||
| @Autowired | |||
| private String fmUploadDir; | |||
| @Autowired | |||
| private AliyunOSS aliyunOSS; | |||
| private AmazonS3 s3 = null; | |||
| private String getFileName(TenantEntity tenantEntity, String fileName) { | |||
| if (StringUtils.isBlank(tenantEntity.getParentTenantId())) { | |||
| fileName = tenantEntity.getTenantId() + "/" + fileName; | |||
| } else { | |||
| fileName = tenantEntity.getTenantId() + "/" + tenantEntity.getParentTenantId() + "/" + fileName; | |||
| } | |||
| return fileName; | |||
| } | |||
| private ResultData awsUpload(InputStream inputStream, ObjectMetadata metadata, String fileName, TenantEntity tenantEntity) { | |||
| ResultData data = new ResultData(); | |||
| try { | |||
| if (s3 == null) { | |||
| s3 = AmazonS3ClientBuilder.standard() | |||
| .withRegion(awsProperty.getClientRegion()) | |||
| .withCredentials(new AWSCredentialsProvider() { | |||
| @Override | |||
| public AWSCredentials getCredentials() { | |||
| return new BasicAWSCredentials(awsProperty.getAccess(), awsProperty.getSecret()); | |||
| } | |||
| @Override | |||
| public void refresh() { | |||
| } | |||
| }) | |||
| .build(); | |||
| } | |||
| s3.putObject( | |||
| new PutObjectRequest(awsProperty.getBucketName(), fileName, inputStream, metadata) | |||
| .withCannedAcl(CannedAccessControlList.PublicRead)); | |||
| URL url = s3.getUrl(awsProperty.getBucketName(), fileName); | |||
| logger.info(url.toString()); | |||
| MallResource mr = new MallResource(); | |||
| mr.updateTenantInfo(tenantEntity); | |||
| mr.setBucket(awsProperty.getBucketName()); | |||
| mr.setS3Key(fileName); | |||
| mr.setUrl(url.toString()); | |||
| mallResourceService.saveOrUpdate(mr); | |||
| data.code = ResultData.SUCCESS; | |||
| Map<String, String> map = new HashMap<>(); | |||
| map.put("url", url.toString()); | |||
| data.data = map; | |||
| } catch (AmazonServiceException ase) { | |||
| data.code = ResultData.ERROR; | |||
| logger.warn("Caught an AmazonServiceException, which " + | |||
| "means your request made it " + | |||
| "to Amazon S3, but was rejected with an error response" + | |||
| " for some reason."); | |||
| logger.warn(ase.getMessage()); | |||
| data.code = ResultData.ERROR; | |||
| data.message = "上传失败"; | |||
| } catch (AmazonClientException ace) { | |||
| data.code = ResultData.ERROR; | |||
| logger.warn("Caught an AmazonClientException, which " + | |||
| "means the client encountered " + | |||
| "an internal error while trying to " + | |||
| "communicate with S3, " + | |||
| "such as not being able to access the network."); | |||
| logger.warn("Error Message: " + ace.getMessage()); | |||
| data.code = ResultData.ERROR; | |||
| data.message = "上传失败"; | |||
| } catch (Exception ioe) { | |||
| data.code = ResultData.ERROR; | |||
| logger.warn("Caught an IOException: " + ioe.getMessage()); | |||
| data.code = ResultData.ERROR; | |||
| data.message = "上传失败"; | |||
| } | |||
| return data; | |||
| } | |||
| /** | |||
| * 上传文件 | |||
| * | |||
| @@ -144,24 +48,12 @@ public class UploadController extends BaseController { | |||
| TenantEntity tenantEntity = getTenantInfo(); | |||
| ObjectMetadata metadata = new ObjectMetadata(); | |||
| metadata.setContentType(multiReq.getContentType()); | |||
| metadata.setContentLength(multiReq.getSize()); | |||
| FileOutputStream fos = null; | |||
| BufferedInputStream fs = null; | |||
| String fileName = UUID.randomUUID().toString(); | |||
| int dot = multiReq.getOriginalFilename().lastIndexOf('.'); | |||
| String fileFormat = ""; | |||
| if (dot >= 0) { | |||
| fileFormat = multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length()); | |||
| fileName = getFileName(tenantEntity, fileName + fileFormat); | |||
| } else { | |||
| fileName = getFileName(tenantEntity, fileName); | |||
| } | |||
| // ResultData data = awsUpload(multiReq.getInputStream(), metadata, fileName, tenantEntity); | |||
| ResultData data = aliyunOSS.uploadFile(tenantEntity.getTenantId(), fileFormat, multiReq.getInputStream()); | |||
| return data; | |||
| } | |||
| @@ -180,20 +72,14 @@ public class UploadController extends BaseController { | |||
| TenantEntity tenantEntity = getTenantInfo(); | |||
| String fileName = UUID.randomUUID().toString(); | |||
| String tempFileName = fileName; | |||
| String tempFileName = UUID.randomUUID().toString(); | |||
| String fileFormat = ""; | |||
| int dot = multiReq.getOriginalFilename().lastIndexOf('.'); | |||
| if (dot >= 0) { | |||
| fileFormat = multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length()); | |||
| fileName = getFileName(tenantEntity, fileName + fileFormat); | |||
| } else { | |||
| fileName = getFileName(tenantEntity, fileName); | |||
| } | |||
| System.out.println(fileName); | |||
| FileOutputStream fos = null; | |||
| String imgFormat = ImgUtil.getImgFormat(fileFormat); | |||
| @@ -215,19 +101,11 @@ public class UploadController extends BaseController { | |||
| File newFile = ImgUtil.thinImage(localImgFileName, localNewImgFileName, imgFormat); | |||
| // 删除本地缓存 | |||
| localFile.delete(); | |||
| ObjectMetadata metadata = new ObjectMetadata(); | |||
| metadata.setContentType(multiReq.getContentType()); | |||
| metadata.setContentLength(newFile.length()); | |||
| // ResultData data = awsUpload(new FileInputStream(newFile), metadata, fileName, tenantEntity); | |||
| ResultData data = aliyunOSS.uploadFile(tenantEntity.getTenantId(), fileFormat, new FileInputStream(newFile)); | |||
| // 删除本地缓存 | |||
| newFile.delete(); | |||
| return data; | |||
| } else { | |||
| ObjectMetadata metadata = new ObjectMetadata(); | |||
| metadata.setContentType(multiReq.getContentType()); | |||
| metadata.setContentLength(multiReq.getSize()); | |||
| // ResultData data = awsUpload(multiReq.getInputStream(), metadata, fileName, tenantEntity); | |||
| ResultData data = aliyunOSS.uploadFile(tenantEntity.getTenantId(), fileFormat, multiReq.getInputStream()); | |||
| return data; | |||
| } | |||
| @@ -253,26 +131,14 @@ public class UploadController extends BaseController { | |||
| for (MultipartFile multipartFile : files) { | |||
| Map<String, String> map = new HashMap<>(); | |||
| ObjectMetadata metadata = new ObjectMetadata(); | |||
| metadata.setContentType(multipartFile.getContentType()); | |||
| metadata.setContentLength(multipartFile.getSize()); | |||
| FileOutputStream fos = null; | |||
| BufferedInputStream fs = null; | |||
| map.put("key", multipartFile.getOriginalFilename()); | |||
| String fileName = UUID.randomUUID().toString(); | |||
| int dot = multipartFile.getOriginalFilename().lastIndexOf('.'); | |||
| String fileFormat = ""; | |||
| if (dot >= 0) { | |||
| fileFormat = multipartFile.getOriginalFilename().substring(dot, multipartFile.getOriginalFilename().length()); | |||
| getFileName(tenantEntity, fileName + fileFormat); | |||
| } else { | |||
| getFileName(tenantEntity, fileName); | |||
| } | |||
| // ResultData data1 = awsUpload(multipartFile.getInputStream(), metadata, fileName, tenantEntity); | |||
| ResultData data1 = aliyunOSS.uploadFile(tenantEntity.getTenantId(), fileFormat, multipartFile.getInputStream()); | |||
| if (data1.code == ResultData.SUCCESS) { | |||
| Map _data = (Map) data1.data; | |||
| @@ -1,24 +1,11 @@ | |||
| package com.iformall.controller; | |||
| import com.amazonaws.AmazonClientException; | |||
| import com.amazonaws.AmazonServiceException; | |||
| import com.amazonaws.auth.AWSCredentials; | |||
| import com.amazonaws.auth.AWSCredentialsProvider; | |||
| import com.amazonaws.auth.BasicAWSCredentials; | |||
| import com.amazonaws.services.s3.AmazonS3; | |||
| 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.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.config.AwsProperty; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.file.aliyun.AliyunOSS; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| @@ -28,10 +15,7 @@ import org.springframework.web.bind.annotation.RequestParam; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| import org.springframework.web.multipart.MultipartFile; | |||
| import java.io.BufferedInputStream; | |||
| import java.io.FileOutputStream; | |||
| import java.io.IOException; | |||
| import java.net.URL; | |||
| import java.util.*; | |||
| @RestController | |||
| @@ -41,80 +25,9 @@ public class UploadController extends BaseController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private AwsProperty awsProperty; | |||
| @Autowired | |||
| private AliyunOSS aliyunOSS; | |||
| private AmazonS3 s3 = null; | |||
| private ResultData awsUpload(MultipartFile multiReq, ObjectMetadata metadata, String fileName) { | |||
| ResultData data = new ResultData(); | |||
| try { | |||
| if (s3 == null) { | |||
| s3 = AmazonS3ClientBuilder.standard() | |||
| .withRegion(awsProperty.getClientRegion()) | |||
| .withCredentials(new AWSCredentialsProvider() { | |||
| @Override | |||
| public AWSCredentials getCredentials() { | |||
| return new BasicAWSCredentials(awsProperty.getAccess(), awsProperty.getSecret()); | |||
| } | |||
| @Override | |||
| public void refresh() { | |||
| } | |||
| }) | |||
| .build(); | |||
| } | |||
| s3.putObject( | |||
| new PutObjectRequest(awsProperty.getBucketName(), fileName, multiReq.getInputStream(), metadata) | |||
| .withCannedAcl(CannedAccessControlList.PublicRead)); | |||
| URL url = s3.getUrl(awsProperty.getBucketName(), fileName); | |||
| logger.info(url.toString()); | |||
| data.code = ResultData.SUCCESS; | |||
| Map<String, String> map = new HashMap<>(); | |||
| map.put("url", url.toString()); | |||
| data.data = map; | |||
| } catch (AmazonServiceException ase) { | |||
| data.code = ResultData.ERROR; | |||
| logger.warn("Caught an AmazonServiceException, which " + | |||
| "means your request made it " + | |||
| "to Amazon S3, but was rejected with an error response" + | |||
| " for some reason."); | |||
| logger.warn(ase.getMessage()); | |||
| data.code = ResultData.ERROR; | |||
| data.message = "上传失败"; | |||
| } catch (AmazonClientException ace) { | |||
| data.code = ResultData.ERROR; | |||
| logger.warn("Caught an AmazonClientException, which " + | |||
| "means the client encountered " + | |||
| "an internal error while trying to " + | |||
| "communicate with S3, " + | |||
| "such as not being able to access the network."); | |||
| logger.warn("Error Message: " + ace.getMessage()); | |||
| data.code = ResultData.ERROR; | |||
| data.message = "上传失败"; | |||
| } catch (IOException ioe) { | |||
| data.code = ResultData.ERROR; | |||
| logger.warn("Caught an IOException: " + ioe.getMessage()); | |||
| data.code = ResultData.ERROR; | |||
| data.message = "上传失败"; | |||
| } | |||
| return data; | |||
| } | |||
| private String getFileName(TenantEntity tenantEntity, String fileName) { | |||
| if (StringUtils.isBlank(tenantEntity.getParentTenantId())) { | |||
| fileName = tenantEntity.getTenantId() + "/" + fileName; | |||
| } else { | |||
| fileName = tenantEntity.getTenantId() + "/" + tenantEntity.getParentTenantId() + "/" + fileName; | |||
| } | |||
| return fileName; | |||
| } | |||
| /** | |||
| * 上传文件 | |||
| @@ -130,29 +43,16 @@ public class UploadController extends BaseController { | |||
| TenantEntity tenantEntity = getTenantInfo(); | |||
| ObjectMetadata metadata = new ObjectMetadata(); | |||
| metadata.setContentType(multiReq.getContentType()); | |||
| metadata.setContentLength(multiReq.getSize()); | |||
| FileOutputStream fos = null; | |||
| BufferedInputStream fs = null; | |||
| String fileName = UUID.randomUUID().toString(); | |||
| int dot = multiReq.getOriginalFilename().lastIndexOf('.'); | |||
| String fileFormat = ""; | |||
| if (dot >= 0) { | |||
| fileFormat = multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length()); | |||
| fileName = getFileName(tenantEntity, fileName + fileFormat); | |||
| } else { | |||
| fileName = getFileName(tenantEntity, fileName); | |||
| } | |||
| // ResultData data = awsUpload(multiReq, metadata, fileName); | |||
| try { | |||
| ResultData data = aliyunOSS.uploadFile(tenantEntity.getTenantId(), fileFormat, multiReq.getInputStream()); | |||
| return data; | |||
| } catch (IOException e) { | |||
| //e.printStackTrace(); | |||
| logger.error(e.getMessage()); | |||
| return new ResultData(ErrorCode.PICTURE_ANALYZING_ERROR); | |||
| } | |||
| @@ -179,26 +79,14 @@ public class UploadController extends BaseController { | |||
| for (MultipartFile multipartFile : files) { | |||
| Map<String, String> map = new HashMap<>(); | |||
| ObjectMetadata metadata = new ObjectMetadata(); | |||
| metadata.setContentType(multipartFile.getContentType()); | |||
| metadata.setContentLength(multipartFile.getSize()); | |||
| FileOutputStream fos = null; | |||
| BufferedInputStream fs = null; | |||
| map.put("key", multipartFile.getOriginalFilename()); | |||
| String fileName = UUID.randomUUID().toString(); | |||
| int dot = multipartFile.getOriginalFilename().lastIndexOf('.'); | |||
| String fileFormat = ""; | |||
| if (dot >= 0) { | |||
| fileFormat = multipartFile.getOriginalFilename().substring(dot, multipartFile.getOriginalFilename().length()); | |||
| fileName = getFileName(tenantEntity, fileName + fileFormat); | |||
| } else { | |||
| fileName = getFileName(tenantEntity, fileName); | |||
| } | |||
| // ResultData data1 = awsUpload(multipartFile, metadata, fileName); | |||
| try { | |||
| ResultData data1 = aliyunOSS.uploadFile(tenantEntity.getTenantId(), fileFormat, multipartFile.getInputStream()); | |||
| if (data1.code == ResultData.SUCCESS) { | |||
| @@ -212,7 +100,6 @@ public class UploadController extends BaseController { | |||
| return data; | |||
| } | |||
| } catch (IOException e) { | |||
| //e.printStackTrace(); | |||
| logger.error(e.getMessage()); | |||
| return new ResultData(ErrorCode.PICTURE_ANALYZING_ERROR); | |||
| } | |||
| @@ -46,9 +46,9 @@ public class PosController extends BaseController { | |||
| "\"return_code\":\"SUCCESS\",\"return_msg\":\"\",\"result_code\":\"SUCCESS\"," + | |||
| "\"tenant_id\":\"456\",\"mall_name\":\"富茂中心\"," + | |||
| "\"merchant_id\":\"320833942159982592\",\"merchant_name\":\"东软合作\"," + | |||
| "\"merchant_img\":\"https://s3.cn-northwest-1.amazonaws.com.cn/iformall-net/234/WechatIMG5071.png\"," + | |||
| "\"merchant_img\":\"https://formall.oss-accelerate.aliyuncs.com/234/WechatIMG5071.png\"," + | |||
| "\"order_operation_id\":\"320834180694245376\"," + | |||
| "\"qrcode_url\":\"https://s3.cn-northwest-1.amazonaws.com.cn/iformall-net/456/formall_c.png\"," + | |||
| "\"qrcode_url\":\" https://formall.oss-accelerate.aliyuncs.com/456/formall_c.png\"," + | |||
| "\"pos_qrcode_rule\":\"https://ctest.malls.iformall.com/order/(二维码规则: url + POS订单ID)\"," + | |||
| "\"discount\":\"false(是否支持会员折扣,false:禁用,true:可用)\"," + | |||
| "\"coupon\":\"0(会员优惠券是否开启,0-禁用,1-单选可用,2-多选可用)\",\"coupon_desc\":\"禁用(会员优惠券是否开启描述)\"," + | |||
| @@ -34,9 +34,9 @@ public class ContractSchedule { | |||
| /** | |||
| * 2小时执行一次 | |||
| * 凌晨5分 | |||
| */ | |||
| @Scheduled(cron = "0 */1 * * * ?") | |||
| @Scheduled(cron = "0 5 0 * * ?") | |||
| public void sendMsg() { | |||
| logger.info("合同状态更新开始"); | |||
| @@ -108,7 +108,7 @@ public class WxCUserBasicInfo extends BaseEntity { | |||
| private Integer status; | |||
| @TableField(exist = false) | |||
| @Excel(name="标签",width = 50,orderNum = "10") | |||
| //@Excel(name="标签",width = 50,orderNum = "10") | |||
| private String tagNames; | |||
| @@ -129,6 +129,12 @@ public class WxCUserBasicInfo extends BaseEntity { | |||
| @TableField(exist = false) | |||
| private Date endTime; | |||
| @TableField(exist = false) | |||
| private Integer begin; | |||
| @TableField(exist = false) | |||
| private Integer limit; | |||
| @TableField(exist = false) | |||
| @io.swagger.annotations.ApiModelProperty(value="操作人类型 枚举:EnumUserType",name="operatorType") | |||
| @@ -7,6 +7,8 @@ import cn.afterturn.easypoi.excel.ExcelImportUtil; | |||
| import cn.afterturn.easypoi.excel.entity.ExportParams; | |||
| import cn.afterturn.easypoi.excel.entity.ImportParams; | |||
| import cn.afterturn.easypoi.excel.entity.enmus.ExcelType; | |||
| import cn.afterturn.easypoi.handler.inter.IExcelExportServer; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.exception.MallinkException; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| @@ -37,6 +39,28 @@ public class ExcelService { | |||
| defaultExport(list, pojoClass, fileName, response, exportParams, false); | |||
| } | |||
| public void exportBigExcel(IExcelExportServer server,Object queryParams, String title, String sheetName, Class<?> pojoClass, String fileName, HttpServletResponse response, boolean template) { | |||
| exportBig(server,queryParams, pojoClass, fileName, response, new ExportParams(title, sheetName, ExcelType.XSSF), template); | |||
| } | |||
| private void exportBig(IExcelExportServer server,Object queryParams,Class<?> pojoClass, String fileName, HttpServletResponse response, ExportParams exportParams, boolean template) { | |||
| Workbook workbook = ExcelExportUtil.exportBigExcel(exportParams, pojoClass, server, queryParams); | |||
| if (workbook != null) { | |||
| if (template) { | |||
| Sheet sheetAt = workbook.getSheetAt(0); | |||
| CellStyle cellStyle = workbook.createCellStyle(); | |||
| Font font = workbook.createFont(); | |||
| font.setColor(IndexedColors.RED.getIndex()); | |||
| cellStyle.setFont(font); | |||
| Row row = sheetAt.createRow(sheetAt.getLastRowNum() + 2); | |||
| Cell cell = row.createCell(0); | |||
| cell.setCellValue("*为必填字段(导入数据时此行文字请删除)"); | |||
| cell.setCellStyle(cellStyle); | |||
| } | |||
| } | |||
| downLoadExcel(fileName, response, workbook); | |||
| } | |||
| public void exportExcel(List<?> list, String title, String sheetName, Class<?> pojoClass, String fileName, HttpServletResponse response, boolean template) { | |||
| defaultExport(list, pojoClass, fileName, response, new ExportParams(title, sheetName, ExcelType.XSSF), template); | |||
| } | |||
| @@ -1,6 +1,5 @@ | |||
| package com.iformall.service; | |||
| import com.amazonaws.services.s3.model.ObjectMetadata; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.enums.EnumPayWay; | |||
| @@ -9,7 +8,6 @@ import org.springframework.stereotype.Service; | |||
| import org.springframework.web.bind.annotation.RequestBody; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| import java.io.InputStream; | |||
| import java.util.Map; | |||
| @Service | |||
| @@ -24,5 +22,5 @@ public interface QrCodeService { | |||
| ResultData uploadQrcode(TenantEntity tenantEntity, int type, String pageUrl, String sceneParam, | |||
| int withText, String text1, String text2, | |||
| String name,EnumPayWay payWay); | |||
| ResultData awsUpload(InputStream inputStream, ObjectMetadata metadata, String fileName, TenantEntity tenantEntity); | |||
| } | |||
| @@ -1,33 +1,16 @@ | |||
| package com.iformall.service.impl; | |||
| import cn.binarywang.wx.miniapp.api.WxMaService; | |||
| import cn.binarywang.wx.miniapp.bean.WxMaCodeLineColor; | |||
| import com.amazonaws.AmazonClientException; | |||
| import com.amazonaws.AmazonServiceException; | |||
| import com.amazonaws.auth.AWSCredentials; | |||
| import com.amazonaws.auth.AWSCredentialsProvider; | |||
| import com.amazonaws.auth.BasicAWSCredentials; | |||
| import com.amazonaws.services.s3.AmazonS3; | |||
| 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.ErrorCode; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.config.AwsProperty; | |||
| import com.iformall.domain.po.MallResource; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.file.aliyun.AliyunOSS; | |||
| import com.iformall.service.MallResourceService; | |||
| import com.iformall.service.QrCodeService; | |||
| import com.iformall.service.WxAppinfoService; | |||
| import com.iformall.service.pay.PayServiceFactory; | |||
| import com.iformall.service.wechat.FmOpenService; | |||
| import com.iformall.utils.MaUtil; | |||
| import com.iformall.utils.QRCodeUtils; | |||
| import me.chanjar.weixin.common.error.WxErrorException; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| @@ -38,7 +21,6 @@ import org.springframework.stereotype.Service; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| import java.io.*; | |||
| import java.net.URL; | |||
| import java.util.*; | |||
| /** | |||
| @@ -52,83 +34,12 @@ public class QrCodeServiceImpl implements QrCodeService { | |||
| @Autowired | |||
| private boolean isFmOpen; | |||
| @Autowired | |||
| private AwsProperty awsProperty; | |||
| @Autowired | |||
| private MallResourceService mallResourceService; | |||
| @Autowired | |||
| private String fmUploadDir; | |||
| @Autowired | |||
| private PayServiceFactory payServiceFactory; | |||
| @Autowired | |||
| private AliyunOSS aliyunOSS; | |||
| private AmazonS3 s3 = null; | |||
| @Override | |||
| public ResultData awsUpload(InputStream inputStream, ObjectMetadata metadata, String fileName, TenantEntity tenantEntity) { | |||
| ResultData data = new ResultData(); | |||
| try { | |||
| if(s3 == null) { | |||
| s3 = AmazonS3ClientBuilder.standard() | |||
| .withRegion(awsProperty.getClientRegion()) | |||
| .withCredentials(new AWSCredentialsProvider() { | |||
| @Override | |||
| public AWSCredentials getCredentials() { | |||
| return new BasicAWSCredentials(awsProperty.getAccess(), awsProperty.getSecret()); | |||
| } | |||
| @Override | |||
| public void refresh() { | |||
| } | |||
| }) | |||
| .build(); | |||
| } | |||
| s3.putObject( | |||
| new PutObjectRequest(awsProperty.getBucketName(), fileName, inputStream, metadata) | |||
| .withCannedAcl(CannedAccessControlList.PublicRead)); | |||
| URL url = s3.getUrl(awsProperty.getBucketName(), fileName); | |||
| logger.info(url.toString()); | |||
| MallResource mr = new MallResource(); | |||
| mr.updateTenantInfo(tenantEntity); | |||
| mr.setBucket(awsProperty.getBucketName()); | |||
| mr.setS3Key(fileName); | |||
| mr.setUrl(url.toString()); | |||
| mallResourceService.saveOrUpdate(mr); | |||
| data.code = ResultData.SUCCESS; | |||
| Map<String, String> map = new HashMap<>(); | |||
| map.put("url", url.toString()); | |||
| data.data = map; | |||
| } catch (AmazonServiceException ase) { | |||
| data.code = ResultData.ERROR; | |||
| logger.warn("Caught an AmazonServiceException, which " + | |||
| "means your request made it " + | |||
| "to Amazon S3, but was rejected with an error response" + | |||
| " for some reason."); | |||
| logger.warn(ase.getMessage()); | |||
| data.code = ResultData.ERROR; | |||
| data.message = "上传失败"; | |||
| } catch (AmazonClientException ace) { | |||
| data.code = ResultData.ERROR; | |||
| logger.warn("Caught an AmazonClientException, which " + | |||
| "means the client encountered " + | |||
| "an internal error while trying to " + | |||
| "communicate with S3, " + | |||
| "such as not being able to access the network."); | |||
| logger.warn("Error Message: " + ace.getMessage()); | |||
| data.code = ResultData.ERROR; | |||
| data.message = "上传失败"; | |||
| } catch (Exception ioe) { | |||
| data.code = ResultData.ERROR; | |||
| logger.warn("Caught an IOException: " + ioe.getMessage()); | |||
| data.code = ResultData.ERROR; | |||
| data.message = "上传失败"; | |||
| } | |||
| return data; | |||
| } | |||
| @Override | |||
| public void downQrCode(TenantEntity tenantEntity, HttpServletRequest request, HttpServletResponse response, Map<String, Object> params,EnumPayWay payWay) throws MallinkException { | |||
| @@ -232,24 +143,12 @@ public class QrCodeServiceImpl implements QrCodeService { | |||
| try { | |||
| //上传 | |||
| ObjectMetadata metadata = new ObjectMetadata(); | |||
| metadata.setContentType("image/jpeg"); | |||
| metadata.setContentLength(dest.length()); | |||
| FileOutputStream fos = null; | |||
| BufferedInputStream fs = null; | |||
| String fn = UUID.randomUUID().toString(); | |||
| int dot = fileName.lastIndexOf('.'); | |||
| String fileFormat = ""; | |||
| if (dot >= 0) { | |||
| fileFormat = dest.getName().substring(dot, dest.getName().length()); | |||
| fn = getFileName(tenantEntity, fn + fileFormat); | |||
| } else { | |||
| fn = getFileName(tenantEntity, fn); | |||
| } | |||
| // ResultData data = awsUpload(new FileInputStream(dest), metadata, fn, tenantEntity); | |||
| ResultData data = aliyunOSS.uploadFile(tenantEntity.getTenantId(), fileFormat, new FileInputStream(dest)); | |||
| org.apache.commons.io.FileUtils.forceDelete(dest); | |||
| return data; | |||
| @@ -259,15 +158,6 @@ public class QrCodeServiceImpl implements QrCodeService { | |||
| return new ResultData(); | |||
| } | |||
| private String getFileName(TenantEntity tenantEntity, String fn) { | |||
| if (StringUtils.isBlank(tenantEntity.getParentTenantId())) { | |||
| fn = tenantEntity.getTenantId() + "/" + fn; | |||
| } else { | |||
| fn = tenantEntity.getTenantId() + "/" + tenantEntity.getParentTenantId() + "/" + fn; | |||
| } | |||
| return fn; | |||
| } | |||
| private void copyFileToDest(int withText, String text1, String text2, String destPath1, File dest, File codeFile) throws IOException { | |||
| if (withText == 1) { | |||
| File dest1 = new File(destPath1); | |||
| @@ -16,6 +16,9 @@ import com.iformall.domain.vo.*; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.service.*; | |||
| import cn.afterturn.easypoi.handler.inter.IExcelExportServer; | |||
| import org.apache.commons.compress.utils.Lists; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| @@ -38,7 +41,7 @@ import java.util.concurrent.TimeUnit; | |||
| import java.util.stream.Collectors; | |||
| @Service | |||
| public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { | |||
| public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService,IExcelExportServer { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| @@ -731,36 +734,40 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { | |||
| @Override | |||
| public void exportData(WxCUserBasicInfo basicInfo, HttpServletRequest request, HttpServletResponse response) { | |||
| List<WxCUserBasicInfoVo> list = wxCUserBasicInfoMapper.findVoList(basicInfo); | |||
| List<WxTags> tagList = wxTagsMapper.findListAll(); | |||
| Map<Long, String> tagMap = tagList.stream().collect(Collectors.toMap(WxTags::getId, WxTags::getName)); | |||
| list.stream().filter(u->u.getTags()!=null).forEach(u->{ | |||
| List<Long> ids = JSONObject.parseArray(u.getTags(), Long.class); | |||
| String tagNames = StringUtils.join(ids.stream().map(id->tagMap.get(id)).collect(Collectors.toList()),"/"); | |||
| u.setTagNames(tagNames); | |||
| }); | |||
| excelService.exportExcel(list, null, "会员信息", WxCUserBasicInfoVo.class, "会员信息数据.xlsx", response, false); | |||
| // List<WxCUserBasicInfoVo> list = wxCUserBasicInfoMapper.findVoList(basicInfo); | |||
| // List<WxTags> tagList = wxTagsMapper.findListAll(); | |||
| // Map<Long, String> tagMap = tagList.stream().collect(Collectors.toMap(WxTags::getId, WxTags::getName)); | |||
| // list.stream().filter(u->u.getTags()!=null).forEach(u->{ | |||
| // List<Long> ids = JSONObject.parseArray(u.getTags(), Long.class); | |||
| // String tagNames = StringUtils.join(ids.stream().map(id->tagMap.get(id)).collect(Collectors.toList()),"/"); | |||
| // u.setTagNames(tagNames); | |||
| // }); | |||
| excelService.exportBigExcel(this,basicInfo, null, "会员信息", WxCUserBasicInfoVo.class, "会员信息数据.xlsx", response, false); | |||
| } | |||
| @Override | |||
| public void exportData(TenantEntity tenantInfo, WxCUserBasicInfo basicInfo, HttpServletRequest request, HttpServletResponse response) { | |||
| List<WxCUserBasicInfoVo> list = new ArrayList<WxCUserBasicInfoVo>(); | |||
| if(StringUtils.isNotBlank(tenantInfo.getParentTenantId())){ | |||
| //关联微信表查询 | |||
| list = wxCUserBasicInfoMapper.findVoList1(tenantInfo,basicInfo); | |||
| }else{ | |||
| //直接查询本表 | |||
| basicInfo.undateFinalTenantId(tenantInfo); | |||
| list = wxCUserBasicInfoMapper.findVoList(basicInfo); | |||
| } | |||
| List<WxTags> tagList = wxTagsMapper.findListAll(); | |||
| Map<Long, String> tagMap = tagList.stream().collect(Collectors.toMap(WxTags::getId, WxTags::getName)); | |||
| list.stream().filter(u->u.getTags()!=null).forEach(u->{ | |||
| List<Long> ids = JSONObject.parseArray(u.getTags(), Long.class); | |||
| String tagNames = StringUtils.join(ids.stream().map(id->tagMap.get(id)).collect(Collectors.toList()),"/"); | |||
| u.setTagNames(tagNames); | |||
| }); | |||
| excelService.exportExcel(list, null, "会员信息", WxCUserBasicInfoVo.class, "会员信息数据.xlsx", response, false); | |||
| // List<WxCUserBasicInfoVo> list = new ArrayList<WxCUserBasicInfoVo>(); | |||
| // if(StringUtils.isNotBlank(tenantInfo.getParentTenantId())){ | |||
| // //关联微信表查询 | |||
| // list = wxCUserBasicInfoMapper.findVoList1(tenantInfo,basicInfo); | |||
| // }else{ | |||
| // //直接查询本表 | |||
| // basicInfo.undateFinalTenantId(tenantInfo); | |||
| // list = wxCUserBasicInfoMapper.findVoList(basicInfo); | |||
| // } | |||
| // List<WxTags> tagList = wxTagsMapper.findListAll(); | |||
| // Map<Long, String> tagMap = tagList.stream().collect(Collectors.toMap(WxTags::getId, WxTags::getName)); | |||
| // list.stream().filter(u->u.getTags()!=null).forEach(u->{ | |||
| // List<Long> ids = JSONObject.parseArray(u.getTags(), Long.class); | |||
| // String tagNames = StringUtils.join(ids.stream().map(id->tagMap.get(id)).collect(Collectors.toList()),"/"); | |||
| // u.setTagNames(tagNames); | |||
| // }); | |||
| // excelService.exportExcel(list, null, "会员信息", WxCUserBasicInfoVo.class, "会员信息数据.xlsx", response, false); | |||
| Map params = new HashMap(); | |||
| params.put("tenantInfo", tenantInfo); | |||
| params.put("basicInfo", basicInfo); | |||
| excelService.exportBigExcel(this,params, null, "会员信息", WxCUserBasicInfoVo.class, "会员信息数据.xlsx", response, false); | |||
| } | |||
| public void exportTemplate(HttpServletRequest request, HttpServletResponse response) { | |||
| @@ -1200,5 +1207,23 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { | |||
| return wxCUserBasicInfoMapper.findBirthdayList(finalTenantId,format,format1); | |||
| } | |||
| } | |||
| @Override | |||
| public List<Object> selectListForExcelExport(Object queryParams, int page) { | |||
| Map params = (Map) queryParams; | |||
| WxCUserBasicInfo basicInfo = (WxCUserBasicInfo) params.get("basicInfo"); | |||
| TenantEntity tenantInfo = (TenantEntity) params.get("tenantInfo"); | |||
| List list = new ArrayList<WxCUserBasicInfoVo>(); | |||
| basicInfo.setBegin((page-1)*10000); | |||
| basicInfo.setLimit(10000); | |||
| if(StringUtils.isNotBlank(tenantInfo.getParentTenantId())){ | |||
| //关联微信表查询 | |||
| list = wxCUserBasicInfoMapper.findVoList1(tenantInfo,basicInfo); | |||
| }else{ | |||
| //直接查询本表 | |||
| basicInfo.undateFinalTenantId(tenantInfo); | |||
| list = wxCUserBasicInfoMapper.findVoList(basicInfo); | |||
| } | |||
| return list; | |||
| } | |||
| } | |||
| @@ -545,7 +545,7 @@ public class WxFlowServiceImpl implements WxFlowService { | |||
| if (record.getStatus().equals(EnumFlowRecordStatus.NEW.getCode())) { | |||
| taskListHtml += "<div style=\"overflow: hidden;\">"; | |||
| taskListHtml += "<div style=\"overflow: hidden;\">"; | |||
| taskListHtml += "<div style=\"float: left; width: 40px;height: 30px;\"><img src=\"https://s3.cn-northwest-1.amazonaws.com.cn/iformall-net/cimg/emailduihao.png\" style=\"display: block; width: 20px;height: 20px;margin-top: 10px;\"></div>"; | |||
| taskListHtml += "<div style=\"float: left; width: 40px;height: 30px;\"><img src=\"https://formall.oss-accelerate.aliyuncs.com/cimg/emailduihao.png\" style=\"display: block; width: 20px;height: 20px;margin-top: 10px;\"></div>"; | |||
| taskListHtml += "<div style=\"float: left; width: auto;margin-right:10px;height: 30px;line-height: 18px;font-size:18px;font-family:MicrosoftYaHei;font-weight:400;color:rgba(51,51,51,1);margin-top: 11px;\">发起申请</div>"; | |||
| taskListHtml += "<div style=\"float: left; width: auto;margin-right:10px;height: 30px;margin-top:15px;line-height: 14px;font-size:14px;font-family:MicrosoftYaHei;font-weight:400;color:rgba(51,51,51,1);\">"+record.getUserName()+"</div>"; | |||
| taskListHtml += "</div>"; | |||
| @@ -558,7 +558,7 @@ public class WxFlowServiceImpl implements WxFlowService { | |||
| } else if (record.getStatus().equals(EnumFlowRecordStatus.ASSIGNEE.getCode())) { | |||
| taskListHtml += "<div style=\"overflow: hidden;\">"; | |||
| taskListHtml += "<div style=\"overflow: hidden;\">"; | |||
| taskListHtml += "<div style=\"float: left; width: 40px;height: 30px;\"><img src=\"https://s3.cn-northwest-1.amazonaws.com.cn/iformall-net/cimg/emailhong.png\" style=\"display: block; width: 20px;height: 20px;margin-top: 10px;\"></div>"; | |||
| taskListHtml += "<div style=\"float: left; width: 40px;height: 30px;\"><img src=\"https://formall.oss-accelerate.aliyuncs.com/cimg/emailhong.png\" style=\"display: block; width: 20px;height: 20px;margin-top: 10px;\"></div>"; | |||
| taskListHtml += "<div style=\"float: left; width: auto;margin-right:10px;height: 30px;line-height: 18px;font-size:18px;font-family:MicrosoftYaHei;font-weight:400;color:rgba(200,89,98,1);margin-top: 11px;\">待审批</div>"; | |||
| taskListHtml += "<div style=\"float: left; width: auto;margin-right:10px;height: 30px;margin-top:15px;line-height: 14px;font-size:14px;font-family:MicrosoftYaHei;font-weight:400;color:rgba(200,89,98,1);\">"+record.getUserName()+"</div>"; | |||
| taskListHtml += "</div>"; | |||
| @@ -571,7 +571,7 @@ public class WxFlowServiceImpl implements WxFlowService { | |||
| } else { | |||
| taskListHtml += "<div style=\"overflow: hidden;\">"; | |||
| taskListHtml += "<div style=\"overflow: hidden;\">"; | |||
| taskListHtml += "<div style=\"float: left; width: 40px;height: 30px;\"><img src=\"https://s3.cn-northwest-1.amazonaws.com.cn/iformall-net/cimg/emailhui.png\" style=\"display: block; width: 20px;height: 20px;margin-top: 10px;\"></div>"; | |||
| taskListHtml += "<div style=\"float: left; width: 40px;height: 30px;\"><img src=\"https://formall.oss-accelerate.aliyuncs.com/cimg/emailhui.png\" style=\"display: block; width: 20px;height: 20px;margin-top: 10px;\"></div>"; | |||
| taskListHtml += "<div style=\"float: left; width: auto;margin-right:10px;height: 30px;line-height: 18px;font-size:18px;font-family:MicrosoftYaHei;font-weight:400;color:rgba(153,153,153,1);margin-top: 11px;\">审批通过</div>"; | |||
| taskListHtml += "<div style=\"float: left; width: auto;margin-right:10px;height: 30px;margin-top:15px;line-height: 14px;font-size:14px;font-family:MicrosoftYaHei;font-weight:400;color:rgba(153,153,153,1);\">"+record.getUserName()+"</div>"; | |||
| taskListHtml += "</div>"; | |||
| @@ -64,7 +64,7 @@ public class WxMallBuildingServiceImpl implements WxMallBuildingService { | |||
| wxMallFloor.setBuildingId(wxMallBuilding.getId()); | |||
| wxMallFloor.setFloorName(cha); | |||
| //默认图片---------------------------------------------------- | |||
| wxMallFloor.setBackgroundImg("https://s3.cn-northwest-1.amazonaws.com.cn/iformall-net/789/9eea8e0e-15ea-4be0-a43d-31e2e9d8db8c.jpg"); | |||
| wxMallFloor.setBackgroundImg("https://formall.oss-accelerate.aliyuncs.com/789/9eea8e0e-15ea-4be0-a43d-31e2e9d8db8c.jpg"); | |||
| wxMallFloor.setCreateDate(new Date()); | |||
| wxMallFloor.setUpdateDate(new Date()); | |||
| wxMallFloorMapper.insert(wxMallFloor); | |||
| @@ -247,13 +247,10 @@ public class WxMerchantServiceImpl implements WxMerchantService { | |||
| return; | |||
| } | |||
| if(!wxMerchant.getCarVendorType().equals(EnumCarVendor.CAR_NOTFOUND.getCode())){ | |||
| if (!wxMerchant.getCarVendorType().equals(EnumCarVendor.CAR_NOTFOUND.getCode())) { | |||
| logger.info("不能停用停车商户"); | |||
| return; | |||
| } | |||
| wxMerchant.setStatus(EnumMerchantStatus.NOT_VALID.getCode()); | |||
| wxMerchantMapper.updateById(wxMerchant); | |||
| //是否有租赁合同 | |||
| WxRentContract wxRentContract = new WxRentContract(); | |||
| wxRentContract.setMerchantId(id); | |||
| @@ -274,6 +271,8 @@ public class WxMerchantServiceImpl implements WxMerchantService { | |||
| c.getStatus().equals(EnumRentContractStatus.PAING.getCode())).count(); | |||
| //解绑商铺-没有租赁合同或物业合同才可以 | |||
| if (countRentContract == 0 || countPropertyContract == 0) { | |||
| wxMerchant.setStatus(EnumMerchantStatus.NOT_VALID.getCode()); | |||
| wxMerchantMapper.updateById(wxMerchant); | |||
| WxMerchantShop wxMerchantShopQuery = new WxMerchantShop(); | |||
| wxMerchantShopQuery.updateTenantInfo(wxMerchant); | |||
| wxMerchantShopQuery.setMerchantId(wxMerchant.getId()); | |||
| @@ -289,30 +288,30 @@ public class WxMerchantServiceImpl implements WxMerchantService { | |||
| wxShop.setStatus(EnumShopStatus.NOT_RENT.getCode()); | |||
| wxShopMapper.updateById(wxShop); | |||
| } | |||
| //解绑用户 | |||
| WxMerchantBUser bUser = new WxMerchantBUser(); | |||
| bUser.setMerchantId(wxMerchant.getId()); | |||
| List<WxMerchantBUser> wxMerchantBUserMapperList = wxMerchantBUserMapper.findList(bUser); | |||
| for (WxMerchantBUser wxMerchantBUser : wxMerchantBUserMapperList) { | |||
| wxMerchantBUser.setStatus(EnumMerchantBUserStatus.INVALID.getCode()); | |||
| wxMerchantBUserMapper.updateById(wxMerchantBUser); | |||
| } | |||
| //作废卡券 | |||
| WxCouponMerchant wxCouponMerchant = new WxCouponMerchant(); | |||
| wxCouponMerchant.updateTenantInfo(wxMerchant); | |||
| wxCouponMerchant.setMerchantId(wxMerchant.getId()); | |||
| wxCouponMerchant.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); | |||
| List<WxCouponMerchant> wxCouponMerchantList = wxCouponMerchantMapper.findList(wxCouponMerchant); | |||
| List<Long> couponIds = wxCouponMerchantList.stream().map(cm -> cm.getProductId()).collect(Collectors.toList()); | |||
| couponIds.stream().filter(cid -> !isCouponMerchantValid(cid)).forEach(cid -> { | |||
| WxCoupon wxCoupon = new WxCoupon(); | |||
| wxCoupon.setId(cid); | |||
| wxCoupon.updateTenantInfo(wxMerchant); | |||
| wxCoupon.setStatus(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode()); | |||
| wxCouponService.saveOrUpdate(wxCoupon); | |||
| }); | |||
| } | |||
| //解绑用户 | |||
| WxMerchantBUser bUser = new WxMerchantBUser(); | |||
| bUser.setMerchantId(wxMerchant.getId()); | |||
| List<WxMerchantBUser> wxMerchantBUserMapperList = wxMerchantBUserMapper.findList(bUser); | |||
| for (WxMerchantBUser wxMerchantBUser : wxMerchantBUserMapperList) { | |||
| wxMerchantBUser.setStatus(EnumMerchantBUserStatus.INVALID.getCode()); | |||
| wxMerchantBUserMapper.updateById(wxMerchantBUser); | |||
| } | |||
| //作废卡券 | |||
| WxCouponMerchant wxCouponMerchant = new WxCouponMerchant(); | |||
| wxCouponMerchant.updateTenantInfo(wxMerchant); | |||
| wxCouponMerchant.setMerchantId(wxMerchant.getId()); | |||
| wxCouponMerchant.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); | |||
| List<WxCouponMerchant> wxCouponMerchantList = wxCouponMerchantMapper.findList(wxCouponMerchant); | |||
| List<Long> couponIds = wxCouponMerchantList.stream().map(cm->cm.getProductId()).collect(Collectors.toList()); | |||
| couponIds.stream().filter(cid->!isCouponMerchantValid(cid)).forEach(cid->{ | |||
| WxCoupon wxCoupon = new WxCoupon(); | |||
| wxCoupon.setId(cid); | |||
| wxCoupon.updateTenantInfo(wxMerchant); | |||
| wxCoupon.setStatus(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode()); | |||
| wxCouponService.saveOrUpdate(wxCoupon); | |||
| }); | |||
| } | |||
| @Transactional(rollbackFor = {Exception.class}) | |||
| @@ -57,7 +57,7 @@ public class WxMsgValidationcodeModelServiceImpl implements WxMsgValidationcodeM | |||
| " ( '" + idWorker.nextId() + "', '" + tenantId + "', '16', '商户分账账户删除提醒', '" + signature + "', '{merchant}商户的收款账户[{account}]于{time}取消绑定,营销活动与销售分成将无法正常进行,请尽快绑定新收款账户', '" + nowTimestr + "', '1', '0', null, null);" + | |||
| "insert into `mallink`.`wx_msg_validationcode_model` ( `id`, `tenant_id`, `type`, `name`, `signature`, `content`, `createtime`, `status`, `minutes`, `model_id`, `email_bg_img`)" + | |||
| "values ( '" + idWorker.nextId() + "', '" + tenantId + "', '10', '审批通过通知', '富茂', " + | |||
| " '<!DOCTYPE html>\\n<html>\\n\\n<head>\\n <meta charset=\\\"utf-8\\\">\\n <meta name=\\\"viewport\\\" content=\\\"width=device-width,initial-scale=1.0\\\">\\n <meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html; charset=utf-8\\\" />\\n <meta name=\\\"viewport\\\" content=\\\"initial-scale=1.0, user-scalable=no\\\" />\\n <meta name=\\\"renderer\\\" content=\\\"webkit\\\">\\n <meta http-equiv=\\\"X-UA-Compatible\\\" content=\\\"IE=edge,chrome=1\\\">\\n <title>富茂审批邮件</title>\\n <title></title>\\n <script> document.documentElement.style.fontSize = document.documentElement.clientWidth / 7.5 + \\'px\\';</script>\\n</head>\\n\\n<body>\\n <div id=\\\"box\\\" style=\\\"padding:80px 20%;background:#E9E7E7;min-height:100vh;\\\">\\n <header style=\\\"height:140px;width:100%;display:flex;background:rgba(31,47,62,1);border-radius:15px 15px 0px 0px;\\\">\\n <img style=\\\"height:auto;width:292px;display:flex;align-self: center;justify-content: center;padding:0 40px;\\\" src=\\\"https://s3.cn-northwest-1.amazonaws.com.cn/iformall-net/cimg/changrong-logo.png\\\"/>\\n </header>\\n <div style=\\\"background:#fff;\\\">\\n <div style=\\\"font-size:26px;font-family:MicrosoftYaHei-Bold;font-weight:bold;color:rgba(85,85,85,1);line-height: 32px;padding:56px 55px 0;\\\">审批通过通知</div>\\n <div style=\\\"font-size:18px;font-family:MicrosoftYaHei;font-weight:400;color:rgba(85,85,85,1);padding: 36px 55px;\\\">编号<span>{contract}</span>的{bustype}已经审批通过,请登录<a href=\\\"{page}\\\">{page}</a>跟进后续工作</div>\\n </div>\\n </div>\\n</body>\\n\\n</html>', " + | |||
| " '<!DOCTYPE html>\\n<html>\\n\\n<head>\\n <meta charset=\\\"utf-8\\\">\\n <meta name=\\\"viewport\\\" content=\\\"width=device-width,initial-scale=1.0\\\">\\n <meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html; charset=utf-8\\\" />\\n <meta name=\\\"viewport\\\" content=\\\"initial-scale=1.0, user-scalable=no\\\" />\\n <meta name=\\\"renderer\\\" content=\\\"webkit\\\">\\n <meta http-equiv=\\\"X-UA-Compatible\\\" content=\\\"IE=edge,chrome=1\\\">\\n <title>富茂审批邮件</title>\\n <title></title>\\n <script> document.documentElement.style.fontSize = document.documentElement.clientWidth / 7.5 + \\'px\\';</script>\\n</head>\\n\\n<body>\\n <div id=\\\"box\\\" style=\\\"padding:80px 20%;background:#E9E7E7;min-height:100vh;\\\">\\n <header style=\\\"height:140px;width:100%;display:flex;background:rgba(31,47,62,1);border-radius:15px 15px 0px 0px;\\\">\\n <img style=\\\"height:auto;width:292px;display:flex;align-self: center;justify-content: center;padding:0 40px;\\\" src=\\\"https://formall.oss-accelerate.aliyuncs.com/cimg/changrong-logo.png\\\"/>\\n </header>\\n <div style=\\\"background:#fff;\\\">\\n <div style=\\\"font-size:26px;font-family:MicrosoftYaHei-Bold;font-weight:bold;color:rgba(85,85,85,1);line-height: 32px;padding:56px 55px 0;\\\">审批通过通知</div>\\n <div style=\\\"font-size:18px;font-family:MicrosoftYaHei;font-weight:400;color:rgba(85,85,85,1);padding: 36px 55px;\\\">编号<span>{contract}</span>的{bustype}已经审批通过,请登录<a href=\\\"{page}\\\">{page}</a>跟进后续工作</div>\\n </div>\\n </div>\\n</body>\\n\\n</html>', " + | |||
| " '" + nowTimestr + "', '1', null, '500', '" + emailBgImg + "');" + | |||
| "insert into `mallink`.`wx_msg_validationcode_model` ( `id`, `tenant_id`, `type`, `name`, `signature`, `content`, `createtime`, `status`, `minutes`, `model_id`, `email_bg_img`)" + | |||
| "values ( '" + idWorker.nextId() + "', '" + tenantId + "', '11', '待缴账单通知', '富茂', " + | |||
| @@ -1593,7 +1593,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { | |||
| WxMerchant merchant = wxMerchantMapper.selectById((Long) merchantId); | |||
| Integer status = merchant.getStatus(); | |||
| if (status.equals(EnumMerchantStatus.VALID.getCode())) { | |||
| wxMerchantService.disable((Long) merchantId); | |||
| //wxMerchantService.disable((Long) merchantId); | |||
| } | |||
| } | |||
| } | |||
| @@ -35,7 +35,7 @@ public class Constant { | |||
| public static final String adminPage = "https://admin.malls.iformall.com"; | |||
| public static final String floor_back_img = "https://s3.cn-northwest-1.amazonaws.com.cn/iformall-net/789/9eea8e0e-15ea-4be0-a43d-31e2e9d8db8c.jpg"; | |||
| public static final String floor_back_img = " https://formall.oss-accelerate.aliyuncs.com/789/9eea8e0e-15ea-4be0-a43d-31e2e9d8db8c.jpg"; | |||
| /// REDIS key Prev | |||
| @@ -38,6 +38,11 @@ | |||
| where poins >= points and tenant_id=wcubi.final_tenant_id | |||
| order by points desc limit 1 ) level,wcubi.status | |||
| </sql> | |||
| <sql id="allSimpleColumns"> | |||
| `id`,`phone`,`birthdate`,`education`,`sex`,`email`,`address`,`poins`,`tag_id`, | |||
| `create_date`,`update_date`,`tenant_id`,`parent_tenant_id`,`name`,`nick_name`,`credit`,`active_time`,`act_record` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| where 1 = 1 | |||
| @@ -792,10 +797,12 @@ | |||
| <select id="findVoList" parameterType="com.iformall.domain.po.WxCUserBasicInfo" resultMap="VoBaseResultMap"> | |||
| select | |||
| <include refid="allVoColumns"/> | |||
| <include refid="allSimpleColumns"/> | |||
| from wx_c_user_basic_info cu | |||
| left join wx_c_user_tags cut on cut.`id` = cu.`tag_id` | |||
| <include refid="dynamicVoWhereConditions"/> | |||
| <if test=" null != begin "> | |||
| limit #{begin}, #{limit} | |||
| </if> | |||
| order by cu.`active_time` DESC | |||
| </select> | |||
| @@ -806,6 +813,9 @@ | |||
| left join wx_c_user c on c.user_id = cu.id | |||
| left join wx_c_user_tags cut on cut.`id` = cu.`tag_id` | |||
| <include refid="dynamicVoWhereConditions1"/> | |||
| <if test=" null != begin "> | |||
| limit #{begin}, #{limit} | |||
| </if> | |||
| order by cu.`active_time` DESC | |||
| </select> | |||
| @@ -813,7 +823,6 @@ | |||
| select | |||
| count(distinct cu.id) | |||
| from wx_c_user_basic_info cu | |||
| left join wx_c_user_tags cut on cut.`id` = cu.`tag_id` | |||
| <include refid="dynamicVoWhereConditions"/> | |||
| </select> | |||
| @@ -588,5 +588,15 @@ | |||
| </select> | |||
| <select id="getMerchantList" parameterType="com.iformall.domain.po.WxMerchant" resultMap="BaseResultMap"> | |||
| select * from wx_merchant where 1=1 and is_del=0 and status=1 | |||
| <if test=" null != tenantId and '' != tenantId"> | |||
| and `tenant_id` = #{tenantId} | |||
| </if> | |||
| <if test=" null != parentTenantId and '' != parentTenantId"> | |||
| and `parent_tenant_id` = #{parentTenantId} | |||
| </if> | |||
| order by create_date desc | |||
| </select> | |||
| </mapper> | |||
| @@ -1,21 +1,10 @@ | |||
| package com.iformall.controller.sys; | |||
| import com.amazonaws.AmazonClientException; | |||
| import com.amazonaws.AmazonServiceException; | |||
| import com.amazonaws.auth.AWSCredentials; | |||
| import com.amazonaws.auth.AWSCredentialsProvider; | |||
| import com.amazonaws.auth.BasicAWSCredentials; | |||
| import com.amazonaws.services.s3.AmazonS3; | |||
| import com.amazonaws.services.s3.AmazonS3ClientBuilder; | |||
| import com.amazonaws.services.s3.model.*; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.config.AwsProperty; | |||
| import com.iformall.controller.base.BaseController; | |||
| 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.utils.ImgUtil; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiOperation; | |||
| @@ -27,7 +16,6 @@ import org.springframework.web.bind.annotation.*; | |||
| import org.springframework.web.multipart.MultipartFile; | |||
| import java.io.*; | |||
| import java.net.URL; | |||
| import java.util.*; | |||
| import java.util.List; | |||
| @@ -38,93 +26,12 @@ public class UploadController extends BaseController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private AwsProperty awsProperty; | |||
| @Autowired | |||
| private String fmUploadDir; | |||
| @Autowired | |||
| private AliyunOSS aliyunOSS; | |||
| @Autowired | |||
| private MallResourceService mallResourceService; | |||
| private String getFileName(TenantEntity tenantEntity, String fileName) { | |||
| if (StringUtils.isBlank(tenantEntity.getParentTenantId())) { | |||
| fileName = tenantEntity.getTenantId() + "/" + fileName; | |||
| } else { | |||
| fileName = tenantEntity.getTenantId() + "/" + tenantEntity.getParentTenantId() + "/" +fileName; | |||
| } | |||
| return fileName; | |||
| } | |||
| private AmazonS3 s3 = null; | |||
| private ResultData awsUpload(InputStream inputStream, ObjectMetadata metadata, String fileName, TenantEntity tenantVEntity) { | |||
| ResultData data = new ResultData(); | |||
| try { | |||
| if(s3 == null) { | |||
| s3 = AmazonS3ClientBuilder.standard() | |||
| .withRegion(awsProperty.getClientRegion()) | |||
| .withCredentials(new AWSCredentialsProvider() { | |||
| @Override | |||
| public AWSCredentials getCredentials() { | |||
| return new BasicAWSCredentials(awsProperty.getAccess(), awsProperty.getSecret()); | |||
| } | |||
| @Override | |||
| public void refresh() { | |||
| } | |||
| }) | |||
| .build(); | |||
| } | |||
| s3.putObject( | |||
| new PutObjectRequest(awsProperty.getBucketName(), fileName, inputStream, metadata) | |||
| .withCannedAcl(CannedAccessControlList.PublicRead)); | |||
| URL url = s3.getUrl(awsProperty.getBucketName(), fileName); | |||
| logger.info(url.toString()); | |||
| MallResource mr = new MallResource(); | |||
| mr.updateTenantInfo(tenantVEntity); | |||
| mr.setBucket(awsProperty.getBucketName()); | |||
| mr.setS3Key(fileName); | |||
| mr.setUrl(url.toString()); | |||
| mallResourceService.saveOrUpdate(mr); | |||
| data.code = ResultData.SUCCESS; | |||
| Map<String, String> map = new HashMap<>(); | |||
| map.put("url", url.toString()); | |||
| data.data = map; | |||
| } catch (AmazonServiceException ase) { | |||
| data.code = ResultData.ERROR; | |||
| logger.warn("Caught an AmazonServiceException, which " + | |||
| "means your request made it " + | |||
| "to Amazon S3, but was rejected with an error response" + | |||
| " for some reason."); | |||
| logger.warn(ase.getMessage()); | |||
| data.code = ResultData.ERROR; | |||
| data.message = "上传失败"; | |||
| } catch (AmazonClientException ace) { | |||
| data.code = ResultData.ERROR; | |||
| logger.warn("Caught an AmazonClientException, which " + | |||
| "means the client encountered " + | |||
| "an internal error while trying to " + | |||
| "communicate with S3, " + | |||
| "such as not being able to access the network."); | |||
| logger.warn("Error Message: " + ace.getMessage()); | |||
| data.code = ResultData.ERROR; | |||
| data.message = "上传失败"; | |||
| } catch (Exception ioe) { | |||
| data.code = ResultData.ERROR; | |||
| logger.warn("Caught an IOException: " + ioe.getMessage()); | |||
| data.code = ResultData.ERROR; | |||
| data.message = "上传失败"; | |||
| } | |||
| return data; | |||
| } | |||
| /** | |||
| * 上传文件 | |||
| @@ -140,24 +47,12 @@ public class UploadController extends BaseController { | |||
| TenantEntity tenantEntity = getTenantInfo(); | |||
| ObjectMetadata metadata = new ObjectMetadata(); | |||
| metadata.setContentType(multiReq.getContentType()); | |||
| metadata.setContentLength(multiReq.getSize()); | |||
| FileOutputStream fos = null; | |||
| BufferedInputStream fs = null; | |||
| String fileName = UUID.randomUUID().toString(); | |||
| int dot = multiReq.getOriginalFilename().lastIndexOf('.'); | |||
| String fileFormat = ""; | |||
| if (dot >= 0) { | |||
| fileFormat = multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length()); | |||
| fileName = getFileName(tenantEntity, fileName + fileFormat); | |||
| } else { | |||
| fileName = getFileName(tenantEntity, fileName); | |||
| } | |||
| // ResultData data = awsUpload(multiReq.getInputStream(), metadata, fileName, tenantEntity); | |||
| ResultData data = aliyunOSS.uploadFile(tenantEntity.getTenantId(), fileFormat, multiReq.getInputStream()); | |||
| return data; | |||
| } | |||
| @@ -176,20 +71,13 @@ public class UploadController extends BaseController { | |||
| TenantEntity tenantEntity = getTenantInfo(); | |||
| String fileName = UUID.randomUUID().toString(); | |||
| String tempFileName = fileName; | |||
| String tempFileName = UUID.randomUUID().toString(); | |||
| String fileFormat = ""; | |||
| int dot = multiReq.getOriginalFilename().lastIndexOf('.'); | |||
| if (dot >= 0) { | |||
| fileFormat = multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length()); | |||
| fileName = getFileName(tenantEntity, fileName + fileFormat); | |||
| } else { | |||
| fileName = getFileName(tenantEntity, fileName); | |||
| } | |||
| System.out.println(fileName); | |||
| FileOutputStream fos = null; | |||
| String imgFormat = ImgUtil.getImgFormat(fileFormat); | |||
| if(StringUtils.isNotBlank(imgFormat)) { | |||
| @@ -210,19 +98,12 @@ public class UploadController extends BaseController { | |||
| File newFile = ImgUtil.thinImage(localImgFileName, localNewImgFileName, imgFormat); | |||
| // 删除本地缓存 | |||
| localFile.delete(); | |||
| ObjectMetadata metadata = new ObjectMetadata(); | |||
| metadata.setContentType(multiReq.getContentType()); | |||
| metadata.setContentLength(newFile.length()); | |||
| // ResultData data = awsUpload(new FileInputStream(newFile), metadata, fileName, tenantEntity); | |||
| ResultData data = aliyunOSS.uploadFile(tenantEntity.getTenantId(), fileFormat, new FileInputStream(newFile)); | |||
| // 删除本地缓存 | |||
| newFile.delete(); | |||
| return data; | |||
| } else { | |||
| ObjectMetadata metadata = new ObjectMetadata(); | |||
| metadata.setContentType(multiReq.getContentType()); | |||
| metadata.setContentLength(multiReq.getSize()); | |||
| // ResultData data = awsUpload(multiReq.getInputStream(), metadata, fileName, tenantEntity); | |||
| ResultData data = aliyunOSS.uploadFile(tenantEntity.getTenantId(), fileFormat, multiReq.getInputStream()); | |||
| return data; | |||
| } | |||
| @@ -248,26 +129,14 @@ public class UploadController extends BaseController { | |||
| for(MultipartFile multipartFile: files) { | |||
| Map<String, String> map = new HashMap<>(); | |||
| ObjectMetadata metadata = new ObjectMetadata(); | |||
| metadata.setContentType(multipartFile.getContentType()); | |||
| metadata.setContentLength(multipartFile.getSize()); | |||
| FileOutputStream fos = null; | |||
| BufferedInputStream fs = null; | |||
| map.put("key", multipartFile.getOriginalFilename()); | |||
| String fileName = UUID.randomUUID().toString(); | |||
| int dot = multipartFile.getOriginalFilename().lastIndexOf('.'); | |||
| String fileFormat = ""; | |||
| if (dot >= 0) { | |||
| fileFormat = multipartFile.getOriginalFilename().substring(dot, multipartFile.getOriginalFilename().length()); | |||
| fileName = getFileName(tenantEntity, fileName + fileFormat); | |||
| } else { | |||
| fileName = getFileName(tenantEntity, fileName); | |||
| } | |||
| // ResultData data1 = awsUpload(multipartFile.getInputStream(), metadata, fileName, tenantEntity); | |||
| ResultData data1 = aliyunOSS.uploadFile(tenantEntity.getTenantId(), fileFormat, multipartFile.getInputStream()); | |||
| if(data1.code == ResultData.SUCCESS) { | |||
| Map _data = (Map)data1.data; | |||
| @@ -300,46 +169,15 @@ public class UploadController extends BaseController { | |||
| public ResultData cimgUpload(@RequestParam("file") MultipartFile multiReq) throws Exception { | |||
| logger.info("[" + getIpAddr() + "] UploadController::cimgUpload"); | |||
| ObjectMetadata metadata = new ObjectMetadata(); | |||
| metadata.setContentType(multiReq.getContentType()); | |||
| metadata.setContentLength(multiReq.getSize()); | |||
| String fileName = multiReq.getOriginalFilename(); | |||
| fileName = "cimg/" + fileName; | |||
| int dot = multiReq.getOriginalFilename().lastIndexOf('.'); | |||
| String fileFormat = ""; | |||
| if (dot >= 0) { | |||
| fileFormat = multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length()); | |||
| } | |||
| // ResultData data = awsUpload(multiReq.getInputStream(), metadata, fileName, new TenantEntity() {{ | |||
| // setTenantId("cimg"); | |||
| // }}); | |||
| ResultData data = aliyunOSS.uploadFile("cimg", fileFormat, multiReq.getInputStream()); | |||
| return data; | |||
| } | |||
| // /** | |||
| // * AWS | |||
| // * @return | |||
| // * @throws Exception | |||
| // */ | |||
| // @GetMapping(value = "/lists") | |||
| // @ApiOperation("aws列举文件") | |||
| // public ResultData awsList() throws Exception { | |||
| // logger.info("[" + getIpAddr() + "] UploadController::cimgUpload"); | |||
| // | |||
| // try{ | |||
| // ObjectListing ol = s3.listObjects(awsProperty.getBucketName()); | |||
| // List<S3ObjectSummary> objects = ol.getObjectSummaries(); | |||
| // for (S3ObjectSummary os: objects) { | |||
| // logger.info(os.toString()); | |||
| // break; | |||
| // } | |||
| // }catch (Exception e){ | |||
| // e.printStackTrace(); | |||
| // } | |||
| // | |||
| // return new ResultData(); | |||
| // } | |||
| } | |||
| @@ -1,17 +1,5 @@ | |||
| package com.iformall.ueditor.upload; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.amazonaws.AmazonClientException; | |||
| import com.amazonaws.AmazonServiceException; | |||
| import com.amazonaws.auth.AWSCredentials; | |||
| import com.amazonaws.auth.AWSCredentialsProvider; | |||
| import com.amazonaws.auth.BasicAWSCredentials; | |||
| import com.amazonaws.services.s3.AmazonS3; | |||
| 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; | |||
| @@ -30,9 +18,7 @@ import org.springframework.web.multipart.MultipartHttpServletRequest; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import java.io.IOException; | |||
| import java.net.URL; | |||
| import java.util.Map; | |||
| import java.util.UUID; | |||
| public class Uploader { | |||
| @@ -41,34 +27,14 @@ public class Uploader { | |||
| private HttpServletRequest request = null; | |||
| private Map<String, Object> conf = null; | |||
| 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, AliyunOSS aliyunOSS) { | |||
| this.request = request; | |||
| this.conf = conf; | |||
| this.mallResourceService = mallResourceService; | |||
| 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() { | |||
| @@ -89,32 +55,17 @@ public class Uploader { | |||
| logger.error("TENANT is null"); | |||
| } | |||
| String fileName = UUID.randomUUID().toString(); | |||
| int dot = multiReq.getOriginalFilename().lastIndexOf('.'); | |||
| String fileFormat = ""; | |||
| if (dot >= 0) { | |||
| fileFormat = multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length()); | |||
| fileName = getFileName(tenantEntity, fileName + fileFormat); | |||
| } else { | |||
| fileName = getFileName(tenantEntity, fileName); | |||
| } | |||
| state = state = new BaseState(true); | |||
| state = new BaseState(true); | |||
| state.putInfo("size", multiReq.getSize()); | |||
| state.putInfo("title", filedName); | |||
| JSONObject stateJson = JSON.parseObject(state.toJSONString()); | |||
| ObjectMetadata metadata = new ObjectMetadata(); | |||
| metadata.setContentType(multiReq.getContentType()); | |||
| 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); | |||
| //logger.info(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")); | |||
| @@ -122,38 +73,10 @@ public class Uploader { | |||
| MallResource mr = new MallResource(); | |||
| mr.updateTenantInfo(tenantEntity); | |||
| 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) { | |||
| /* | |||
| logger.warn("Caught an AmazonServiceException, which " + | |||
| "means your request made it " + | |||
| "to Amazon S3, but was rejected with an error response" + | |||
| " for some reason."); | |||
| logger.warn(ase.getMessage()); | |||
| */ | |||
| ase.printStackTrace(); | |||
| } catch (AmazonClientException ace) { | |||
| /* | |||
| logger.warn("Caught an AmazonClientException, which " + | |||
| "means the client encountered " + | |||
| "an internal error while trying to " + | |||
| "communicate with S3, " + | |||
| "such as not being able to access the network."); | |||
| logger.warn("Error Message: " + ace.getMessage()); | |||
| */ | |||
| ace.printStackTrace(); | |||
| } catch (IOException ioe) { | |||
| //logger.warn("Caught an IOException: " + ioe.getMessage()); | |||
| ioe.printStackTrace(); | |||
| } | |||
| } | |||
| @@ -362,12 +362,6 @@ | |||
| <version>2.1.0</version> | |||
| </dependency> | |||
| <dependency> | |||
| <groupId>com.amazonaws</groupId> | |||
| <artifactId>aws-java-sdk-s3</artifactId> | |||
| <version>1.11.423</version> | |||
| </dependency> | |||
| <!-- https://mvnrepository.com/artifact/com.belerweb/pinyin4j --> | |||
| <dependency> | |||
| <groupId>com.belerweb</groupId> | |||